Signals is a wireless cross component communication subsystem
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs
examples
src
tests
.gitattributes
.gitignore
.scrunitizer.yml
.travis.yml
CHANGELOG.md
CONTRIBUTORS.md
INSTALL.md
LICENSE-AGPL.mkd
LICENSE-PROPRIETARY.mkd
README.mkd
UPGRADE.md
codeception.yml
composer.json
composer.lock
debug-test.php
make-junctions.bat
make-junctions.sh
make-links
make-toc
make-unit
push-tests
run-test
run-tests
run-tests-coverage
run-tests-hhvm
run-tests.bat
run-travis
signals
signals-post-false-filter.yml
signals-pre-false-filter.yml
signals.yml

README.mkd

Maslosoft Signals

Wireless Cross-Component Communication

Latest Stable Version License [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Maslosoft/Signals/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Maslosoft/Signals/?branch=master) [![Code Coverage](https://scrutinizer-ci.com/g/Maslosoft/Signals/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/Maslosoft/Signals/?branch=master)

Quick Install

composer require maslosoft/signals

Wireless cross-component communication

This component allows for interaction of application components, without prior or explicit assignment.

Setup

Use composer to install

composer require maslosoft/signals:"*"

Or by hard way, download somewhere in your project and ensure autoloading works for Maslosoft\Signals\* and you include dep too;

Setup signals. After calling init any further instance will be configured same as below $signal.

$signal = new Maslosoft\Signals\Signal();
$signal->runtimePath = RUNTIME_PATH;
$signal->paths = [
	MODELS_PATH
];
$signal->init();

Generate signals definition, only once, hook it to your build script etc.

$signal = new Maslosoft\Signals\Signal();
(new Maslosoft\Signals\Utility($signal))->generate();

Usage

Emiting signal

Define signal:

namespace MyNamespace\Signals;

class AccountMenuItems extends AdminMenuItems
{
	public $item = [];
}

Define class with slot with @SlotFor annotation

namespace Maslosoft\Ilmatar\Modules;

class MyModule
{
	/**
	 * @SlotFor(MyNamespace\Signals\AccountMenuItems)
	 */
	public function reactOnAccountMenu(MyNamespace\Signals\AccountMenuItems $signal)
	{
		$signal->item = [
			'url' => '/content/myBlog',
			'label' => 'My blog'
		];
	}
}

Emit signal and get results of this call:

$signal = new Maslosoft\Signals\Signal();
$result = $signal->emit(new AdminMenuItems());

echo $result[0]->item[0]['label']; // My blog

Gathering signals