PHPackages                             lukaszmakuch/property-setter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. lukaszmakuch/property-setter

ActiveLibrary

lukaszmakuch/property-setter
============================

Sets properties of already existing objects.

v0.2(10y ago)0148—0%2MITPHP

Since Apr 17Pushed 10y ago1 watchersCompare

[ Source](https://github.com/lukaszmakuch/property-setter)[ Packagist](https://packagist.org/packages/lukaszmakuch/property-setter)[ RSS](/packages/lukaszmakuch-property-setter/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (1)Versions (3)Used By (2)

[![travis](https://camo.githubusercontent.com/c66cc795dbbec118f3d288d3c4eda16fce0212393b90dce52c7073b37130f1e4/68747470733a2f2f7472617669732d63692e6f72672f6c756b61737a6d616b7563682f70726f70657274792d7365747465722e737667)](https://travis-ci.org/lukaszmakuch/property-setter)

PropertySetter
==============

[](#propertysetter)

Sets properties of already existing objects.

Usage
-----

[](#usage)

### Different setters

[](#different-setters)

#### PropertySetter

[](#propertysetter-1)

Describes how to use any property setter.

```
use lukaszmakuch\PropertySetter\PropertySetter;

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

#### SimplePropertySetter

[](#simplepropertysetter)

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")
);
```

#### SilentPropertySetter

[](#silentpropertysetter)

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);
```

#### SimpleChainOfPropertySetters

[](#simplechainofpropertysetters)

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);
```

#### SilentChainOfPropertySetters

[](#silentchainofpropertysetters)

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);
```

### Setting strategies

[](#setting-strategies)

#### CallSetterMethod

[](#callsettermethod)

Calls a setter in order to set a property.

```
use lukaszmakuch\PropertySetter\SettingStrategy\CallSetterMethod;

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

#### CallOnlyMethodAsSetter

[](#callonlymethodassetter)

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
```

### Target specifiers

[](#target-specifiers)

#### PickByClass

[](#pickbyclass)

Selects targets by their classes.

```
use lukaszmakuch\PropertySetter\TargetSpecifier\PickByClass;

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

### Value Sources

[](#value-sources)

#### UseDirectly

[](#usedirectly)

Simply holds some value without modyfing it before it's returned.

```
use lukaszmakuch\PropertySetter\ValueSource\UseDirectly;

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

### Exceptions

[](#exceptions)

#### UnableToSetProperty

[](#unabletosetproperty)

*\\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).

#### UnableToGetValue

[](#unabletogetvalue)

*\\lukaszmakuch\\PropertySetter\\Exception\\UnableToGetValue*

Thrown when it's impossible to get a value (from a value source). It inherits from the *UnableToSetProperty* exception.

#### UnableToGetValue

[](#unabletogetvalue-1)

*\\lukaszmakuch\\PropertySetter\\Exception\\UnsupportedTarget*

Thrown when trying to set properties of an object that is not supported. It inherits from the *UnableToSetProperty* exception.

Installation
------------

[](#installation)

Use [composer](https://getcomposer.org) to get the latest version:

```
$ composer require lukaszmakuch/property-setter

```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

2

Last Release

3675d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5e08a5c26bd9824a0345f417660e2d1146f044c886266daf2dd0901720fbcf32?d=identicon)[lukaszmakuch](/maintainers/lukaszmakuch)

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lukaszmakuch-property-setter/health.svg)

```
[![Health](https://phpackages.com/badges/lukaszmakuch-property-setter/health.svg)](https://phpackages.com/packages/lukaszmakuch-property-setter)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
