2017 © Pedro Peláez
 

library observatory

General Observation Pattern Component

image

subcosm/observatory

General Observation Pattern Component

  • Thursday, April 13, 2017
  • by nihylum
  • Repository
  • 2 Watchers
  • 1 Stars
  • 29 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

observatory

General Observation Pattern Component, (*1)

Build Status codecov SensioLabsInsight Code Climate Gittip, (*2)

What is observatory?

Observatory is a general interface orchestration for observable objects using a container for data transport. It's inspired by the SplObserver implementation of PHP., (*3)

What is the goal of observatory?

Providing an easy to use, easy to understand, lightweight event hub to specific implementations without provided methods for each event invoker registration., (*4)

How to use it?

Subcosm Observatory is available at Packagist:, (*5)

# composer require subcosm/observatory ~1.0

Creating the Observable Object

use Subcosm\Observable\{
    ObservableInterface,
    ObservableTrait,
    AbstractObservationContainer as Container
};

class Foo implements ObservableInterface {
    use ObservableTrait;

    public function firstAction()
    {
        $message = 'Hello from firstAction!';

        $container = new class($this, __METHOD__, $message) extends Container {

            protected $message;

            public function __construct($object, string $stage, string $message) 
            {
                $this->message = $message;

                parent::__construct($object, $stage);
            }

            public function getMessage()
            {
                $this->message;
            }
        };

        $this->notify($container);
    }

    public function secondAction()
    {
        $message = 'Another hello from secondAction!';

        $container = new class($this, __METHOD__, $message) extends Container {

            protected $message;

            public function __construct($object, string $stage, string $message) 
            {
                $this->message = $message;

                parent::__construct($object, $stage);
            }

            public function getMessage()
            {
                $this->message;
            }
        };

        $this->notify($container);
    }
}

Creating an Observer

use Subcosm\Observable\{
    ObserverInterface,
    ObservationContainerInterface as Container
};

class EchoMessageObserver implements ObserverInterface {

    public function update(Container $container)
    {
        echo $container->getMessage().PHP_EOL;
    }

}

Using the Observable and Observer

$observable = new Foo;

$observer = new EchoMessageObserver;

$observable->attach($observer);

$observable->firstAction();
$observable->secondAction();

Results in:, (*6)

Hello from firstAction!
Another hello from secondAction!

Package Stability and Maintainers

This package is considered stable. The maintainers of this package are:, (*7)

License

This package is licensed under the MIT-License., (*8)

The Versions

13/04 2017

dev-master

9999999-dev

General Observation Pattern Component

  Sources   Download

MIT

The Requires

  • php >=7.1

 

The Development Requires

by Matthias Kaschubowski

08/04 2017

v1.1

1.1.0.0

General Observation Pattern Component

  Sources   Download

MIT

The Requires

  • php >=7.1

 

The Development Requires

by Matthias Kaschubowski

05/04 2017

v1.0.1

1.0.1.0

General Observation Pattern Component

  Sources   Download

MIT

The Requires

  • php >=7.1

 

The Development Requires

by Matthias Kaschubowski

04/04 2017

v1.0

1.0.0.0

General Observation Pattern Component

  Sources   Download

MIT

The Development Requires

by Matthias Kaschubowski