PHP code example of lukaszmakuch / property-setter

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

    

lukaszmakuch / property-setter example snippets


use lukaszmakuch\PropertySetter\PropertySetter;

/* @var $propetySetter PropertySetter */
$propetySetter->setPropertiesOf($someObject);

use lukaszmakuch\PropertySetter\SimplePropertySetter;
use lukaszmakuch\PropertySetter\SettingStrategy\CallSetterMethod;
use lukaszmakuch\PropertySetter\TargetSpecifier\PickByClass;
use lukaszmakuch\PropertySetter\ValueSource\UseDirectly;

$setter = new SimplePropertySetter(
    new PickByClass(SomeClass::class),
    new CallSetterMethod("setParam"),
    new UseDirectly("param value")
);

use lukaszmakuch\PropertySetter\SilentPropertySetter;
use lukaszmakuch\PropertySetter\PropertySetter;

/* @var $actualSetter PropertySetter */
$silentSetter = new SilentPropertySetter($actualSetter);

use lukaszmakuch\PropertySetter\SimpleChainOfPropertySetters;
use lukaszmakuch\PropertySetter\PropertySetter;

/* @var $firstSetter PropertySetter */
/* @var $anotherSetter PropertySetter */
$chain = (new SimpleChainOfPropertySetters())
    ->add($firstSetter)
    ->add($anotherSetter);

use lukaszmakuch\PropertySetter\SilentChainOfPropertySetters;
use lukaszmakuch\PropertySetter\ChainOfPropertySetters;

/* @var $actualChain ChainOfPropertySetters */
$silentChain = new SilentChainOfPropertySetters($actualChain);

use lukaszmakuch\PropertySetter\SettingStrategy\CallSetterMethod;

$strategy = new CallSetterMethod("setParam"); //will call setParam

use lukaszmakuch\PropertySetter\SettingStrategy\CallOnlyMethodAsSetter;

interface ObjectThatHasOnlyOnePublicMethod
{
    public function setParam($newValue);
}

$strategy = new CallOnlyMethodAsSetter(ObjectThatHasOnlyOnePublicMethod::class); //will call setParam

use lukaszmakuch\PropertySetter\TargetSpecifier\PickByClass;

$specifier = new PickByClass(\DateTime::class); //will support \DateTime

use lukaszmakuch\PropertySetter\ValueSource\UseDirectly;

$valueSource = new UseDirectly(123); //will return 123