Sets properties of already existing objects.
Describes how to use any property setter.
use lukaszmakuch\PropertySetter\PropertySetter;
/* @var $propetySetter PropertySetter */
$propetySetter->setPropertiesOf($someObject);
Injects values obtained from a value source to objects described by a target specifier using some property setting strategy.
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")
);
It's a decorator that prevents the decorated setter from throwing the UnsupportedTarget exception if some object is not supported.
use lukaszmakuch\PropertySetter\SilentPropertySetter;
use lukaszmakuch\PropertySetter\PropertySetter;
/* @var $actualSetter PropertySetter */
$silentSetter = new SilentPropertySetter($actualSetter);
It tries to set properties of an object using all of its setters. It doesn't prevent any exceptions.
use lukaszmakuch\PropertySetter\SimpleChainOfPropertySetters;
use lukaszmakuch\PropertySetter\PropertySetter;
/* @var $firstSetter PropertySetter */
/* @var $anotherSetter PropertySetter */
$chain = (new SimpleChainOfPropertySetters())
->add($firstSetter)
->add($anotherSetter);
It's a decorator that ignores a situation when some setter doesn't support objects of some type. It prevents throwing the UnsupportedTarget exception. When one of its setter throws an exception, it keeps trying to use other setters.
use lukaszmakuch\PropertySetter\SilentChainOfPropertySetters;
use lukaszmakuch\PropertySetter\ChainOfPropertySetters;
/* @var $actualChain ChainOfPropertySetters */
$silentChain = new SilentChainOfPropertySetters($actualChain);
Calls a setter in order to set a property.
use lukaszmakuch\PropertySetter\SettingStrategy\CallSetterMethod;
$strategy = new CallSetterMethod("setParam"); //will call setParam
Calls a setter in order to set a property.
use lukaszmakuch\PropertySetter\SettingStrategy\CallOnlyMethodAsSetter;
interface ObjectThatHasOnlyOnePublicMethod
{
public function setParam($newValue);
}
$strategy = new CallOnlyMethodAsSetter(ObjectThatHasOnlyOnePublicMethod::class); //will call setParam
Selects targets by their classes.
use lukaszmakuch\PropertySetter\TargetSpecifier\PickByClass;
$specifier = new PickByClass(\DateTime::class); //will support \DateTime
Simply holds some value without modyfing it before it's returned.
use lukaszmakuch\PropertySetter\ValueSource\UseDirectly;
$valueSource = new UseDirectly(123); //will return 123
\lukaszmakuch\PropertySetter\Exception\UnableToSetProperty
It's the parent of any exception that may be thrown by the setPropertiesOf method. When the setter method throws an exception, it's wrapped in this one (and becomes available by calling the getPrevious method).
\lukaszmakuch\PropertySetter\Exception\UnableToGetValue
Thrown when it's impossible to get a value (from a value source). It inherits from the UnableToSetProperty exception.
\lukaszmakuch\PropertySetter\Exception\UnsupportedTarget
Thrown when trying to set properties of an object that is not supported. It inherits from the UnableToSetProperty exception.
Use composer to get the latest version:
$ composer require lukaszmakuch/property-setter