<?php /** * Perforce Swarm * * @copyright 2013 Perforce Software. All rights reserved * @license Please see LICENSE.txt in top-level folder of this distribution. * @version 2013.1.MAIN-TEST_ONLY/597594 */ namespace DingoWorld; use Projects\Model\Project; use Zend\Mvc\MvcEvent; use Activity\Model\Activity; class Module { /** * New changes generate dingoes. * * This module shows how to generate new activity based on incoming activity. First we generate an * event and stick it on the queue. When it comes through the next time we flesh it out. * This module also shows you can attach to multiple events in one module. * * @param Event $event the bootstrap event * @return void */ public function onBootstrap(MvcEvent $event) { $application = $event->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__, ), ), ); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 8402 | Matt Attaway |
Add an sample extension to demonstrate event creation and capturing in Swarm This sample extension will show you how to both react to events that are published to the activity feed and how to add new events to the feed from inside of your module. |