Module.php #1

  • //
  • guest/
  • matt_attaway/
  • Swarm_Demo_Extensions/
  • GoodbyeCruelWorld/
  • Module.php
  • View
  • Commits
  • Open Download .zip Download (3 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 GoodbyeCruelWorld;

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

class Module
{
    /**
     * Block all of alau's activity
     *
     * This module shows how to block events that you do not want in the feed.
     *
     * @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();

        // we attach to all events. see the other examples for how to attach to specific events
        $events->attach(
            '*',   // '*' here attaches us to all events
            function ($event) use ($services,$manager) { // we need both services and manager for this module

                // 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;
               }
                
                // calling stopPropagation prevents the event from getting to the end of the line and being published
                if ($model->get('user') == 'alau') {
                    $services->get('logger')->err("Lau smote");
                    $event->stopPropagation(true);
                    return;
                }

                //  note if we did nothing
                $services->get('logger')->err("No Lau to smite");
            },
            // set our priority, -90 puts us right before the end so Andrew can't sneak in easily
            -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.