auraphp / aura.signal Goto Github PK
View Code? Open in Web Editor NEWSignalSlots / EventHandler Implementation
License: BSD 2-Clause "Simplified" License
SignalSlots / EventHandler Implementation
License: BSD 2-Clause "Simplified" License
Was playing with Aura.Signal
Error :
Fatal error: Call to a member function getLast() on a non-object
Fix : return results collection object for the send()
and process()
not returning anything .
Another Qn is :
In constructor itself we are cloning the result collection $this->results = clone $this->result_collection;
, then why we need it in send()
method again ?
// In Aura/Signal/Manager
public function send($origin, $signal)
{
// clone a new result collection
$this->results = clone $this->result_collection;
// get the arguments to be passed to the handler
$args = func_get_args();
array_shift($args);
array_shift($args);
// now process the signal through the handlers
$this->process($origin, $signal, $args);
//return the result collection .
return $this->results ;
}
Below is code that I was playing
<?php
use Aura\Signal\Manager as SignalManager;
class Example
{
protected $signal;
public function __construct(SignalManager $signal)
{
$this->signal = $signal;
}
public function doSomething($text)
{
echo __METHOD__ . "<br/>";
$results = $this->signal->send($this, 'example_signal', $text);
/*
$results = $this->signal->getResults();
// go through each result ...
foreach ($results as $result) {
// ... and echo the value returned by the Handler callback
//echo "<br /> The object that sent the signal. " . $result->origin;
echo "<br /> The sender expected by the Handler. " . $result->sender;
echo "<br /> The signal that was sent by the origin. " . $result->signal;
echo "<br /> The value returned by the Handler callback. " . $result->value;
}
*
*/
$result = $results->getLast();
echo "<br /> The signal that was sent by the origin. " . $result->signal;
echo "<br /> The value returned by the Handler callback. " . $result->value;
}
}
class ExampleOther
{
protected $signal;
public function __construct(SignalManager $signal)
{
$this->signal = $signal;
}
public function doSomethingElse($text)
{
echo __METHOD__ . "<br/>";
$this->signal->send($this, 'example_signal', $text);
}
}
$signal = require_once __DIR__ . '/Aura.Signal/scripts/instance.php';
$signal->handler(
'*',
'example_signal',
function ($arg ) {
echo " example_signal Called " . $arg;
}
);
$closure = function() {
echo "Before all others. <br />";
return " From Signal 1000";
};
$signal->handler('Example', 'example_signal', $closure, 1000);
// add a closure at position 9000, which means it will be processed
// after all handlers at the default position 5000.
$closure = function() {
echo "<br /> After all others. <br />";
return " From signal closure of value 6000";
};
$signal->handler('Example', 'example_signal', $closure, 6000);
$eg1 = new Example( $signal );
$eg1->doSomething('Hello World');
//$eg2 = new ExampleOther( $signal );
//$eg2->doSomethingElse('Hello World');
Hi Paul,
I have made the necessary changes to make Aura.Signal to 5.3 and v2
https://github.com/harikt/Aura.Signal/tree/develop-2
If you feel we can push to develop-2 for signals let me know.
Hi Paul,
I was wondering whether it is good to keep the results of all the events fired.
For eg : In a method there can be many events triggering. In that case the result of signal is not obtained, or is replaced. What do you suggest for things like that ?
I wonder whether getResults($signal_name)
should have a functionality to look and give back the results.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.