Module.php #1

  • //
  • guest/
  • matt_attaway/
  • Swarm_Demo_Extensions/
  • HelloWorld/
  • Module.php
  • View
  • Commits
  • Open Download .zip Download (2 KB)
<?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 HelloWorld;

use Projects\Model\Project;
use Zend\Mvc\MvcEvent;
use Activity\Model\Activity;

class Module
{
    /**
     * Mangle all incoming change events and "Hello World"-ify them
     *
     * This modules shows how to modify events as they go through the system
     *
     * @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();

        $events->attach(
            'task.change',   // this attaches us only to task.change events
            function ($event) use ($services) {

                // a lot of events come through. we need to make sure this is actually an activity event
                $model = $event->getParam('activity');
                if (!$model instanceof Activity) {
                    return;
                }

		// hello world a number of strings in the event
                // all available fields are described in the Activity model in /Activity/src/Activity/Model/Activity.php
                $model->set('description', 'Hello World');
                $model->set('action', 'helloed');
                $model->set('target', 'World');

                // you can write out to the log to help you debug your module. comment out the line below
                // $services->get('logger')->err("Writing to the log");
            },
            // set our priority, -90 puts us right before the end, but before the activity is published
            -90
        );
    }

    // 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 8302 Matt Attaway Adding a couple sample Swarm extensions.

HelloWorld shows how a module can intercept and modify events in the activity stream before
they are published.

GoodbyCruelWorld prevents events matching certain criteria from being published to the activity
stream.