getApplication(); $services = $application->getServiceManager(); $manager = $services->get('queue'); $events = $manager->getEventManager(); // in this method we generate newdingo events and add them to the global queue. they will be filled out later $events->attach( 'task.change', // 'task.change' here attaches us to only new checkins function ($event) use ($services) { // we need just services for this callback so that we can grab the queue // we grab a handle for the global queue and add our "task". the second argument to addTask is an id which we don't have in this case $queue = $services->get('queue'); $queue->addTask('newdingo', 'newdingo'); // note our event creation $services->get('logger')->err("created a newdingo event"); }, // set our priority, -95 puts us right before publishing at the end. -95 ); // this method fills out the newdingo task created earlier $events->attach( 'task.newdingo', // 'newdingo' here attaches us to the event we created on checkin function ($event) use ($services) { // we need just services to write to the log // create an activity object for the event filled with our data // see Activity/src/Activity/Model/Activity.php for the list of possible fields $activity = new Activity; $activity->set( array( 'type' => 'dingo', 'user' => 'Dingo', 'action' => 'snuggled', 'target' => 'a baby' ) ); $event->setParam('activity', $activity); // log our dingo creation $services->get('logger')->err("Added a dingo"); }, // set our priority, 100 makes this one of the first modules that is run 100 ); } // loads up our config file. all modules should have this method. public function getConfig() { return include __DIR__ . '/config/module.config.php'; } // makes sure our module is automatically loaded. otherwise the user would // explicitly install our module in the application public function getAutoloaderConfig() { return array( 'Zend\Loader\StandardAutoloader' => array( 'namespaces' => array( __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__, ), ), ); } }