PHP code example of cline / struct

1. Go to this page and download the library: Download cline/struct 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/ */

    

cline / struct example snippets


use Cline\Struct\Contracts\ContextualCastInterface;
use Cline\Struct\Metadata\PropertyMetadata;
use Cline\Struct\Support\PropertyHydrationContext;

final class SlugCast implements ContextualCastInterface
{
    public function get(PropertyMetadata $property, mixed $value): mixed
    {
        return $value;
    }

    public function getWithContext(
        PropertyMetadata $property,
        mixed $value,
        PropertyHydrationContext $context,
    ): mixed {
        return ($context->resolvedProperties['mode'] ?? null) === 'strict'
            ? mb_strtolower((string) $value)
            : (string) $value;
    }

    public function set(PropertyMetadata $property, mixed $value): mixed
    {
        return $value;
    }
}