PHP code example of php-libs / value-states

1. Go to this page and download the library: Download php-libs/value-states 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/ */

    

php-libs / value-states example snippets


class MyClass
{
    private ?string $propertyA = null;

    private ?string $propertyB = null;

    public function setPropertyA(string $value)
    {
        $this->propertyA = $value;
    }

    public function setPropertyB(string $value)
    {
        $this->propertyB = $value;
    }
}


class MyClass implements \PhpLibs\Observable\BeforeValueChangeObservableInterface
{
    private const PROPERTY_A = 'propertyA';
    private const PROPERTY_B = 'propertyB';
    
    use PhpLibs\Observable\BeforeValueChangeObservableTrait;
    use PhpLibs\Observable\AfterValueChangeObservableTrait;

    private ?string $propertyA = null;

    private ?string $propertyB = null;

    public function setPropertyA(string $value)
    {
        $this->raiseBeforeValueChange(static::PROPERTY_A, $this->propertyA, $value);
        $this->propertyA = $value;
        $this->raiseAfterValueChange(static::PROPERTY_A, $this->propertyA);
    }

    public function setPropertyB(string $value)
    {
        $this->raiseBeforeValueChange(static::PROPERTY_B, $this->propertyB, $value);
        $this->propertyB = $value;
        $this->raiseAfterValueChange(static::PROPERTY_B, $this->propertyB);
    }
}