Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/crypto-scythe/observ_r
PHP observer pattern implementation
https://github.com/crypto-scythe/observ_r
Last synced: 11 days ago
JSON representation
PHP observer pattern implementation
- Host: GitHub
- URL: https://github.com/crypto-scythe/observ_r
- Owner: crypto-scythe
- License: mit
- Created: 2015-09-26T17:06:18.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-09-26T17:28:26.000Z (over 9 years ago)
- Last Synced: 2024-12-06T17:27:37.390Z (21 days ago)
- Language: PHP
- Size: 137 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Obsrv_r
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)
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)?>