crypto_scythe/observ_r
最新稳定版本:1.0.0
Composer 安装命令:
composer require crypto_scythe/observ_r
包简介
Dynamic Observer Pattern via PHP Traits
README 文档
README
Dynamic Observer Pattern via PHP Traits with observers to react differently to specific subject update notices
Installing
File composer.json
{
"require": {
"crypto_scythe/observ_r": "*"
}
}
Then on command line:
composer install
Usage (simliar to examples/basic_example.php)
<?php
require( 'vendor/autoload.php' );
class testSubject {
use crypto_scythe\Observ_r\Subject;
public function testObservers() {
echo 'Notifying attached observers' . PHP_EOL;
$this->subjectNotify( array( 'code' => true, 'text' => 'Lorem Ipsum dolor...' ) );
}
}
class testObserverCode {
use crypto_scythe\Observ_r\Observer;
public function __construct( $subject ) {
$this->observerAttach( $subject, 'operate' );
}
public function operate( $data ) {
var_dump( $data['code'] );
}
}
class testObserverText {
use crypto_scythe\Observ_r\Observer;
public function __construct( $subject ) {
$this->observerAttach( $subject, 'operation' );
}
public function operation( $data ) {
var_dump( $data['text'] );
}
}
$subject = new testSubject();
$observerText = new testObserverText( $subject );
$observerCode = new testObserverCode( $subject );
$subject->testObservers();
// Each observer reacts to the update
// Detach the first observer (Text)
$observerText->observerDetach( $subject );
$subject->testObservers();
// Now only the remaining observer reacts (Code)
?>
统计信息
- 总下载量: 21
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-09-26