teknoo/states-bundle
最新稳定版本:3.0.2
Composer 安装命令:
composer require teknoo/states-bundle
包简介
Symfony bunde to create PHP classes following the State pattern in PHP. This can be a cleaner way for an object to change its behavior at runtime without resorting to large monolithic conditional statements and thus improve maintainability. (Build on the Teknoo Software States library)
README 文档
README
States allows you to create PHP classes following the State Pattern in PHP. This can be a cleaner way for an object to change its behavior at runtime without resorting to large monolithic conditional statements and this improve maintainability.
This package is bundle to adapt the library States to Symfony 2+.
Short Example
/**
* File States/English.php
*/
class English extends \Teknoo\States\State\AbstractState
{
public function sayHello(): string
{
return 'Good morning, '.$this->name;
}
public function displayDate(\DateTime $now): string
{
return $now->format('%m %d, %Y');
}
}
/**
* File States/French.php
*/
class French extends \Teknoo\States\State\AbstractState
{
public function sayHello(): string
{
return 'Bonjour, '.$this->name;
}
public function displayDate(\DateTime $now): string
{
return $now->format('%d %m %Y');
}
}
/**
* File MyClass.php
*/
class MyClass extends \Teknoo\Bundle\StatesBundle\Entity\IntegratedEntity
{
/**
* @ORM\Column(type="string", length=250)
* @var string
*/
private $name;
/**
* @param string $name
* @return self
*/
public function setName(string $name): MyClass
{
$this->name = $name;
return $this;
}
}
$frenchMan = new MyClass();
$frenchMan->switchState('French');
$frenchMan->setName('Roger');
$englishMan = new MyClass();
$englishMan->switchState('Enflish');
$englishMan->setName('Richard');
$now = new \DateTime('2016-07-01');
foreach ([$frenchMan, $englishMan] as $man) {
echo $man->sayHello().PHP_EOL;
echo 'Date: '.$man->displayDate($now);
}
//Display
Bonjour Roger
Date: 01 07 2016
Good morning Richard
Date: 07 01, 2016
Installation & Requirements
This library requires :
* PHP 7+
* Composer
* States 2+
* Symfony 2.7+
Instruction to install the States bundle with Symfony 2+ : Install.
This library support Doctrine, but Doctrine is not mandatory. (Stated classes can be use without Doctrine)
* Doctrine (Orm or Odm/Mongo)
Symfony Use
For main States's features, the bundle is transparent :
- States bundle's services are private and are not available. Only the loader is accessible via :
@teknoo.states.loader - Your Symfony's Doctrine entity (ORM) must use the trait
Teknoo\Bundle\StatesBundle\Entity\IntegratedTrait.- Alternative, you can inherits
Teknoo\Bundle\StatesBundle\Entity\IntegratedEntity.
- Alternative, you can inherits
- Your Symfony's Doctrine document (ODM) must use the trait
Teknoo\Bundle\StatesBundle\Document\IntegratedTrait.- Alternative, you can inherits
Teknoo\Bundle\StatesBundle\Entity\IntegratedDocument.
- Alternative, you can inherits
With the extension States Life cyclable :
- Observer instance to register a stated class and observe it :
@teknoo.states.lifecyclable.service.observer - Manager to register scenarii about stated class:
@teknoo.states.lifecyclable.service.manager - Prototype to create a new Yaml Scenario Builder
@teknoo.states.lifecyclable.prototype.scenario_yaml_builder - Prototype to create a new Scenario Builder
@teknoo.states.lifecyclable.prototype.scenario_builder - prototype to create a new Scenario :
@teknoo.states.lifecyclable.prototype.scenario
Documentation to use States with Symfony 2+ : Symfony.
Quick startup
Quick How-to to learn how use this library : Startup.
Example
An example of using this library is available in the folder : Demo.
API Documentation
Generated documentation from the library with PhpDocumentor : Open.
Behavior Documentation
Documentation to explain how this library works : Behavior.
Credits
Richard Déloge - richarddeloge@gmail.com - Lead developer. Teknoo Software - http://teknoo.software
About Teknoo Software
Teknoo Software is a PHP software editor, founded by Richard Déloge. Teknoo Software's DNA is simple : Provide to our partners and to the community a set of high quality services or software, sharing knowledge and skills.
License
States is licensed under the MIT and GPL3+ Licenses - see the licenses folder for details
Contribute :)
You are welcome to contribute to this project. Fork it on Github
teknoo/states-bundle 适用场景与选型建议
teknoo/states-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.77k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2015 年 10 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「pattern」 「bundle」 「class」 「states」 「state pattern」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 teknoo/states-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 teknoo/states-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 teknoo/states-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
2lenet/EasyAdminPlusBundle
The bundle for easy using json-rpc api on your project
Provide a way to secure accesses to all routes of an symfony application.
DMS Meetup API Bundle, enables Meetup API clients in services
A Laravel package for the Repository Design Pattern.
Inbox pattern process implementation for your Laravel Applications
统计信息
- 总下载量: 2.77k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-10-29