[ZF2] The EventManager Reference Guide ( lack of code :( )

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[ZF2] The EventManager Reference Guide ( lack of code :( )

whisher
Hi,
so I'm trying to learn zf2 after Module Manager
I'm on EventManager but I find this


use Zend\Log\Factory as LogFactory;

$log = LogFactory($someConfig);
$foo = new Foo();
$foo->getEventManager()->attach('bar', function ($e) use ($log) {
    $event  = $e->getName();
    $target = get_class($e->getTarget());
    $params = json_encode($e->getParams());

    $log->info(sprintf(
        '%s called on %s, using params %s',
        $event,
        $target,
        $params
    ));
});

It's frustrating for a apprentice
I dont' see any LogFactory file
in Zend\Log\Factory
what's $someConfig ?
Could take me more info, please ?


Reply | Threaded
Open this post in threaded view
|

Re: [ZF2] The EventManager Reference Guide ( lack of code :( )

weierophinney
Administrator
-- whisher <[hidden email]> wrote
(on Monday, 05 November 2012, 01:49 PM -0800):

> so I'm trying to learn zf2 after Module Manager I'm on EventManager
> but I find this
>
> use Zend\Log\Factory as LogFactory;
>
> $log = LogFactory($someConfig);
> $foo = new Foo();
> $foo->getEventManager()->attach('bar', function ($e) use ($log) {
>     $event  = $e->getName();
>     $target = get_class($e->getTarget());
>     $params = json_encode($e->getParams());
>
>     $log->info(sprintf(
>         '%s called on %s, using params %s',
>         $event,
>         $target,
>         $params
>     ));
> });
>
> It's frustrating for a apprentice I dont' see any LogFactory file in
> Zend\Log\Factory what's $someConfig ?  Could take me more info, please?

Can you indicate where you're seeing this example, please? It's clearly
out-of-date with the current status of the Log component and should be
updated... but I need to know where.

However, regardless, the _theory_ behind its operation is still the
same. The idea behind the example is to show how you can create a
listener for an event, and the values available to the event; how the
log instance is retrieved is irrelevant.

Essentially:

 * Listeners are always passed an Event object ($e above)
 * The event object has accessors to get the event name ($e->getName(),
   the target object triggering the event ($e->getTarget()), and
   parameters provided to the event ($e->getParams()).

The above example shows retrieving the event manager from a fictional
"Foo" class, and attaching to its "bar" event.

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: [ZF2] The EventManager Reference Guide ( lack of code :( )

Mohammad ZeinEddin
Reply | Threaded
Open this post in threaded view
|

Re: [ZF2] The EventManager Reference Guide ( lack of code :( )

whisher
This post was updated on .
In reply to this post by weierophinney
weierophinney wrote
-- whisher <[hidden email]> wrote
(on Monday, 05 November 2012, 01:49 PM -0800):
> so I'm trying to learn zf2 after Module Manager I'm on EventManager
> but I find this
>
> use Zend\Log\Factory as LogFactory;
>
> $log = LogFactory($someConfig);
> $foo = new Foo();
> $foo->getEventManager()->attach('bar', function ($e) use ($log) {
>     $event  = $e->getName();
>     $target = get_class($e->getTarget());
>     $params = json_encode($e->getParams());
>
>     $log->info(sprintf(
>         '%s called on %s, using params %s',
>         $event,
>         $target,
>         $params
>     ));
> });
>
> It's frustrating for a apprentice I dont' see any LogFactory file in
> Zend\Log\Factory what's $someConfig ?  Could take me more info, please?

Can you indicate where you're seeing this example, please? It's clearly
out-of-date with the current status of the Log component and should be
updated... but I need to know where.

However, regardless, the _theory_ behind its operation is still the
same. The idea behind the example is to show how you can create a
listener for an event, and the values available to the event; how the
log instance is retrieved is irrelevant.

Essentially:

 * Listeners are always passed an Event object ($e above)
 * The event object has accessors to get the event name ($e->getName(),
   the target object triggering the event ($e->getTarget()), and
   parameters provided to the event ($e->getParams()).

The above example shows retrieving the event manager from a fictional
"Foo" class, and attaching to its "bar" event.

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]
Thanks a lot weierophinney for the explanation :)
@Mohammad has just pointed out the out-of-date link.
Bye