PHP code example of spaark / composite-utils

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

    

spaark / composite-utils example snippets


public function setProperty($value)
{
    $this->property = $value;
}

public function getProperty()
{
    return $this->property;
}

public function setProperty(RequiredPropertyType $value)
{
    $this->property = $value;
}

public function __construct($value1, $value2, $value3, $value4, $value5)
{
    // Set values
    $this->value1 = $value1;
    $this->value2 = $value2;
    $this->value3 = $value3;
    $this->value4 = $value4;
    $this->value5 = $value5;
    
    // Init Values
    $this->value6 = new Collection();
    $this->value7 = new HashMap();
}

class MyAwesomeComposite
{
    use AutoConstructTrait;
    use PropertyAccessTrait;

    /**
     * @var int
     */
    protected $property = 42;

    /**
     * @var string
     * @readable
     * @writable
     */
    protected $stringProperty = 'some value';

    /**
     * @var DataType
     * @readable
     * @construct 


$class = new MyAwesomeComposite(); // Fails, $iNeedThis is mposite(); // Fails, $iNeedThis should be a DataType

$iNeedThis = new DataType();
$class = new MyAwesomeComposite($iNeedThis); // All good!

var_dump($class->property); // Fails, not readable
var_dump($class->stringProperty); // string(10) "some value"

$class->stringProperty = 00000000123;
var_dump($class->stringProperty); // string(3) "123"

$class->iNeedThis = new DataType(); // Fails, not writable

var_dump($class->collection); // ArrayObject { }

var_dump($class->iNeedThis === $iNeedThis); // true