-- whisher <[email protected]> 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 | [email protected] Zend Framework | http://framework.zend.com/ PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc -- List: [email protected] Info: http://framework.zend.com/archives Unsubscribe: [email protected]
