承接 lukaszmakuch/property-setter 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

lukaszmakuch/property-setter

Composer 安装命令:

composer require lukaszmakuch/property-setter

包简介

Sets properties of already existing objects.

README 文档

README

travis

PropertySetter

Sets properties of already existing objects.

Usage

Different setters

PropertySetter

Describes how to use any property setter.

use lukaszmakuch\PropertySetter\PropertySetter;

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

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

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

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

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

CallSetterMethod

Calls a setter in order to set a property.

use lukaszmakuch\PropertySetter\SettingStrategy\CallSetterMethod;

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

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

PickByClass

Selects targets by their classes.

use lukaszmakuch\PropertySetter\TargetSpecifier\PickByClass;

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

Value Sources

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

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

\lukaszmakuch\PropertySetter\Exception\UnableToGetValue

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

UnableToGetValue

\lukaszmakuch\PropertySetter\Exception\UnsupportedTarget

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

Installation

Use composer to get the latest version:

$ composer require lukaszmakuch/property-setter

统计信息

  • 总下载量: 148
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-04-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固