1. Go to this page and download the library: Download spiral/marshaller library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
spiral / marshaller example snippets
namespace App\Entity;
use Ramsey\Uuid\UuidInterface;
use Spiral\Marshaller\Meta\Marshal;
use Spiral\Marshaller\Meta\MarshalArray;
use Spiral\Marshaller\Type\EnumType;
class User
{
public function __construct(
#[Marshal]
private UuidInterface $uuid,
#[Marshal(name: 'first_name')]
private string $firstName,
#[Marshal(name: 'last_name')]
private string $lastName,
#[Marshal(of: Status::class, type: EnumType::class)]
private Status $status,
#[Marshal(of: Address::class)]
private Address $address,
#[Marshal(name: 'registered_at', of: \DateTimeImmutable::class)]
private \DateTimeImmutable $registeredAt,
#[MarshalArray(name: 'delivery_addresses', of: Address::class)]
private array $deliveryAddresses
) {
}
}
namespace App\Entity;
use Spiral\Marshaller\Meta\Marshal;
final class Address
{
public function __construct(
#[Marshal]
private string $street,
#[Marshal]
private string $city,
#[Marshal]
private string $country
) {
}
}
namespace App\Entity;
enum Status: string
{
case Active = 'active';
case Inactive = 'inactive';
}