New: Aura.Dispatcher

32 views
Skip to first unread message

Paul M. Jones

unread,
Sep 23, 2013, 2:26:50 PM9/23/13
to aur...@googlegroups.com
Hi all,

As part of the work toward releasing v2 packages, I present the new Aura.Dispatcher package:

<https://github.com/auraphp/Aura.Dispatcher>

(As a side-note, it uses PSR-4 autoloading instead of PSR-0, which means the src/ and tests/ directories are shallower. The README has some different front-matter as well, and the tests directory is organized a bit differently.)

In putting together the v1 framework built from Aura packages, we embedded some things that turn out to be de-couple-able from the framework. For example, in the existing framework, we have a front controller that maps controller names to factories; it reads the routing information and then picks a controller to invoke.

Aura.Dispatcher is an extracted version of that front-controller/factory system, modified to allow for micro-framework closure controllers as well as for recursive dispatching. Instantiating a dispatcher is dead easy:

// the dispatcher instance
$dispatcher = new Dispatcher;

// look in this param for the object to dispatch to
$dispatcher->setObjectParam('controller');

// look in this param for the method to invoke, if needed
$dispatcher->setMethodParam('action');

Here's a micro-framework invocation style:

$params = [
'controller' => function ($id) {
return "Read blog entry $id";
},
'id' => 88,
];

$result = $dispatcher->__invoke($params);
echo $result; // Read blog entry 88

And here's a full-stack invocation style; note that the call to the dispatcher is the same as with the micro-framework style:

// the controller class
class Blog
{
public function browse()
{
// ...
}

public function read($id)
{
return "Read blog entry $id";
}

public function edit($id)
{
// ...
}

public function add()
{
// ...
}

public function delete($id)
{
// ...
}
}

// add to the dispatcher a factory closure that returns a Blog instance;
// could just as well be $di->lazyNew('Blog') or $di->newFactory('Blog')
$dispatcher->setObject('blog', function () {
return new Blog;
});

// $params taken from Aura\Router\Route->values
$params = [
'controller' => 'blog',
'action' => 'read',
'id' => 88,
];

$result = $dispatcher->__invoke($params);
echo $result; // "Read blog entry 88"


Take a look at the new Aura.Dispatcher stuff and let us know what you think.

<https://github.com/auraphp/Aura.Dispatcher>

Thanks!


--
Paul M. Jones
pmjo...@gmail.com
http://paul-m-jones.com


Jesse Burns

unread,
Sep 23, 2013, 2:44:15 PM9/23/13
to aur...@googlegroups.com
Beautiful stuff Paul, AuraPHP Team!

I'm very excited about this and am looking forward to putting some
time aside to work on integrating this into my project :-)

Keep up the good work folks!


Jesse Burns
jbWebWare.com - Bringing The Web To You!!!
AllianceCMS.com - Bringing Us Together!!!
> --
> You received this message because you are subscribed to the Google Groups "The Aura Project for PHP" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to auraphp+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Hari K T

unread,
Sep 23, 2013, 10:51:45 PM9/23/13
to aur...@googlegroups.com

I understood the use case much better.

Thank you for your great insight on v2 .

I am looking forward on your architecture of Aura.Web integration with Dispatcher .

jon.e...@gmail.com

unread,
Sep 24, 2013, 1:11:04 PM9/24/13
to aur...@googlegroups.com

I suppose you could just use:
$result = $dispatcher($params);
rather than explicitly calling __invoke()?
Or am I out-to-lunch there?

Paul M. Jones

unread,
Sep 24, 2013, 1:13:03 PM9/24/13
to aur...@googlegroups.com

On Sep 24, 2013, at 12:11 PM, "jon.e...@gmail.com" <jon.e...@gmail.com> wrote:

> I suppose you could just use:
> $result = $dispatcher($params);
> rather than explicitly calling __invoke()?

That's exactly right. I used __invoke() only to emphasize that a method call is happening.

jon.e...@gmail.com

unread,
Sep 24, 2013, 1:18:35 PM9/24/13
to aur...@googlegroups.com

Excellent. That's a pretty useful package to go along with Aura.Router. I can see myself playing with that today, just as soon as I get through these last TPS reports....

Reply all
Reply to author
Forward
0 new messages