Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/Attributes/Binary.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Crell\Serde\Attributes;

use Attribute;
use Crell\AttributeUtils\SupportsScopes;
use Crell\Serde\TypeField;

#[Attribute(Attribute::TARGET_PROPERTY)]
class Binary implements TypeField, SupportsScopes
{
/**
* @param array<string|null> $scopes
*/
public function __construct(protected readonly array $scopes = [null]) {}

public function scopes(): array
{
return $this->scopes;
}

public function acceptsType(string $type): bool
{
return $type === 'string';
}

public function validate(mixed $value): bool
{
return true;
}
}
3 changes: 3 additions & 0 deletions src/Attributes/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ class Field implements FromReflectionProperty, HasSubAttributes, Excludable, Sup
* the specified scopes. To also be included in the default "unscoped" case,
* include an array element of `null`, or include a non-scoped copy of the
* Field.
* @param int|null $fieldNum
* Some formatters (such as protobuf) allow specifying the serialized order of data.
*/
public function __construct(
?string $serializedName = null,
Expand All @@ -165,6 +167,7 @@ public function __construct(
?bool $requireValue = null,
?bool $omitIfNull = null,
protected readonly array $scopes = [null],
public readonly int|null $fieldNum = null,
) {
if ($default !== PropValue::None) {
$this->defaultValue = $default;
Expand Down
30 changes: 30 additions & 0 deletions src/Attributes/Fixed32.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Crell\Serde\Attributes;

use Crell\AttributeUtils\SupportsScopes;
use Crell\Serde\TypeField;

#[\Attribute(\Attribute::TARGET_PROPERTY)]
class Fixed32 implements TypeField, SupportsScopes
{
/**
* @param array<string|null> $scopes
*/
public function __construct(protected readonly array $scopes = [null]) {}

public function scopes(): array
{
return $this->scopes;
}

public function acceptsType(string $type): bool
{
return $type === 'string' || $type === 'int';
}

public function validate(mixed $value): bool
{
return is_numeric($value);
}
}
30 changes: 30 additions & 0 deletions src/Attributes/Fixed64.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Crell\Serde\Attributes;

use Crell\AttributeUtils\SupportsScopes;
use Crell\Serde\TypeField;

#[\Attribute(\Attribute::TARGET_PROPERTY)]
class Fixed64 implements TypeField, SupportsScopes
{
/**
* @param array<string|null> $scopes
*/
public function __construct(protected readonly array $scopes = [null]) {}

public function scopes(): array
{
return $this->scopes;
}

public function acceptsType(string $type): bool
{
return $type === 'string' || $type === 'int';
}

public function validate(mixed $value): bool
{
return is_numeric($value);
}
}
31 changes: 31 additions & 0 deletions src/Attributes/Float32.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Crell\Serde\Attributes;

use Crell\AttributeUtils\SupportsScopes;
use Crell\Serde\TypeField;

#[\Attribute(\Attribute::TARGET_PROPERTY)]
class Float32 implements TypeField, SupportsScopes
{

/**
* @param array<string|null> $scopes
*/
public function __construct(protected readonly array $scopes = [null]) {}

public function scopes(): array
{
return $this->scopes;
}

public function acceptsType(string $type): bool
{
return $type === 'float';
}

public function validate(mixed $value): bool
{
return is_numeric($value);
}
}
31 changes: 31 additions & 0 deletions src/Attributes/Float64.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Crell\Serde\Attributes;

use Crell\AttributeUtils\SupportsScopes;
use Crell\Serde\TypeField;

#[\Attribute(\Attribute::TARGET_PROPERTY)]
class Float64 implements TypeField, SupportsScopes
{

/**
* @param array<string|null> $scopes
*/
public function __construct(protected readonly array $scopes = [null]) {}

public function scopes(): array
{
return $this->scopes;
}

public function acceptsType(string $type): bool
{
return $type === 'float';
}

public function validate(mixed $value): bool
{
return is_numeric($value);
}
}
31 changes: 31 additions & 0 deletions src/Attributes/Int32.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Crell\Serde\Attributes;

use Crell\AttributeUtils\SupportsScopes;
use Crell\Serde\TypeField;

#[\Attribute(\Attribute::TARGET_PROPERTY)]
class Int32 implements TypeField, SupportsScopes
{

/**
* @param array<string|null> $scopes
*/
public function __construct(protected readonly array $scopes = [null]) {}

public function scopes(): array
{
return $this->scopes;
}

public function acceptsType(string $type): bool
{
return $type === 'int';
}

public function validate(mixed $value): bool
{
return is_numeric($value);
}
}
31 changes: 31 additions & 0 deletions src/Attributes/Int64.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Crell\Serde\Attributes;

use Crell\AttributeUtils\SupportsScopes;
use Crell\Serde\TypeField;

#[\Attribute(\Attribute::TARGET_PROPERTY)]
class Int64 implements TypeField, SupportsScopes
{

/**
* @param array<string|null> $scopes
*/
public function __construct(protected readonly array $scopes = [null]) {}

public function scopes(): array
{
return $this->scopes;
}

public function acceptsType(string $type): bool
{
return $type === 'string' || $type === 'int';
}

public function validate(mixed $value): bool
{
return is_numeric($value);
}
}
31 changes: 31 additions & 0 deletions src/Attributes/SFixed32.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Crell\Serde\Attributes;

use Attribute;
use Crell\AttributeUtils\SupportsScopes;
use Crell\Serde\TypeField;

#[Attribute(Attribute::TARGET_PROPERTY)]
class SFixed32 implements TypeField, SupportsScopes
{
/**
* @param array<string|null> $scopes
*/
public function __construct(protected readonly array $scopes = [null]) {}

public function scopes(): array
{
return $this->scopes;
}

public function acceptsType(string $type): bool
{
return $type === 'int';
}

public function validate(mixed $value): bool
{
return is_numeric($value);
}
}
31 changes: 31 additions & 0 deletions src/Attributes/SFixed64.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Crell\Serde\Attributes;

use Attribute;
use Crell\AttributeUtils\SupportsScopes;
use Crell\Serde\TypeField;

#[Attribute(Attribute::TARGET_PROPERTY)]
class SFixed64 implements TypeField, SupportsScopes
{
/**
* @param array<string|null> $scopes
*/
public function __construct(protected readonly array $scopes = [null]) {}

public function scopes(): array
{
return $this->scopes;
}

public function acceptsType(string $type): bool
{
return $type === 'int' || $type === 'string';
}

public function validate(mixed $value): bool
{
return is_numeric($value);
}
}
31 changes: 31 additions & 0 deletions src/Attributes/SInt32.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Crell\Serde\Attributes;

use Crell\AttributeUtils\SupportsScopes;
use Crell\Serde\TypeField;

#[\Attribute(\Attribute::TARGET_PROPERTY)]
class SInt32 implements TypeField, SupportsScopes
{

/**
* @param array<string|null> $scopes
*/
public function __construct(protected readonly array $scopes = [null]) {}

public function scopes(): array
{
return $this->scopes;
}

public function acceptsType(string $type): bool
{
return $type === 'int';
}

public function validate(mixed $value): bool
{
return is_numeric($value);
}
}
31 changes: 31 additions & 0 deletions src/Attributes/SInt64.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Crell\Serde\Attributes;

use Crell\AttributeUtils\SupportsScopes;
use Crell\Serde\TypeField;

#[\Attribute(\Attribute::TARGET_PROPERTY)]
class SInt64 implements TypeField, SupportsScopes
{

/**
* @param array<string|null> $scopes
*/
public function __construct(protected readonly array $scopes = [null]) {}

public function scopes(): array
{
return $this->scopes;
}

public function acceptsType(string $type): bool
{
return $type === 'int' || $type === 'string';
}

public function validate(mixed $value): bool
{
return is_numeric($value);
}
}
31 changes: 31 additions & 0 deletions src/Attributes/UInt32.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Crell\Serde\Attributes;

use Crell\AttributeUtils\SupportsScopes;
use Crell\Serde\TypeField;

#[\Attribute(\Attribute::TARGET_PROPERTY)]
class UInt32 implements TypeField, SupportsScopes
{

/**
* @param array<string|null> $scopes
*/
public function __construct(protected readonly array $scopes = [null]) {}

public function scopes(): array
{
return $this->scopes;
}

public function acceptsType(string $type): bool
{
return $type === 'int' || $type === 'string';
}

public function validate(mixed $value): bool
{
return is_numeric($value);
}
}
Loading