2017 © Pedro Peláez
 

library observ_r

Dynamic Observer Pattern via PHP Traits

image

crypto_scythe/observ_r

Dynamic Observer Pattern via PHP Traits

  • Saturday, September 26, 2015
  • by crypto_scythe
  • Repository
  • 1 Watchers
  • 0 Stars
  • 10 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Obsrv_r

Dynamic Observer Pattern via PHP Traits with observers to react differently to specific subject update notices, (*1)

Installing

File composer.json, (*2)

{
  "require": {
    "crypto_scythe/observ_r": "*"
  }
}

Then on command line:, (*3)

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)

?>

The Versions

26/09 2015

dev-master

9999999-dev https://github.com/crypto-scythe/observ_r

Dynamic Observer Pattern via PHP Traits

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Chris Fasel

php trait pattern subject observer

26/09 2015

1.0.0

1.0.0.0 https://github.com/crypto-scythe/observ_r

Dynamic Observer Pattern via PHP Traits

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Chris Fasel

php trait pattern subject observer