function setup() { $this->application = new ApplicationWithTerminalWidth('TestApplication', '0.0.0'); $this->commandFactory = new AnnotatedCommandFactory(); // $factory->addListener(...); $alterOptionsEventManager = new AlterOptionsCommandEvent($this->application); $eventDispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $eventDispatcher->addSubscriber($this->commandFactory->commandProcessor()->hookManager()); $eventDispatcher->addSubscriber($alterOptionsEventManager); $this->application->setDispatcher($eventDispatcher); $this->application->setAutoExit(false); $discovery = new CommandFileDiscovery(); $discovery->setSearchPattern('*CommandFile.php')->setIncludeFilesAtBase(false)->setSearchLocations(['alpha']); chdir(__DIR__); $commandFiles = $discovery->discover('.', '\\Consolidation\\TestUtils'); $formatter = new FormatterManager(); $formatter->addDefaultFormatters(); $formatter->addDefaultSimplifiers(); $terminalWidthOption = new PrepareTerminalWidthOption(); $terminalWidthOption->setApplication($this->application); $this->commandFactory->commandProcessor()->setFormatterManager($formatter); $this->commandFactory->commandProcessor()->addPrepareFormatter($terminalWidthOption); $this->commandFactory->setIncludeAllPublicMethods(false); $this->addDiscoveredCommands($this->commandFactory, $commandFiles); $helpCommandfile = new HelpCommand($this->application); $commandList = $this->commandFactory->createCommandsFromClass($helpCommandfile); foreach ($commandList as $command) { $this->application->add($command); } }
public function registerServices($container) { // Me $container->set('kernel', $this); // Routes $container->set('routes', function ($c) { return new \Symfony\Component\Routing\RouteCollection(); }); // Request/Routes $container->set('request_stack', function ($c) { return new \Cerad\Component\HttpMessage\RequestStack(); }); /* ============================================= * $this->context->getHost() * $this->context->getMethod() * $this->context->getScheme() */ $container->set('request_context', function ($c) { $request = $c->get('request_stack')->getMasterRequest(); $context = []; $context['method'] = $request->getMethod(); return $context; }); $container->set('route_matcher', function ($c) { $routes = []; $tags = $c->getTags('routes'); foreach ($tags as $tag) { $serviceId = $tag['service_id']; $service = $c->get($serviceId); $routes[$serviceId] = $service; } return new \Cerad\Component\HttpRouting\UrlMatcher($routes, $c->get('request_context')); }); $container->set('route_generator', function ($c) { return new \Symfony\Component\Routing\Generator\UrlGenerator($c->get('routes'), $c->get('request_context')); }); $container->set('database_connection', function ($c) { $config = new \Doctrine\DBAL\Configuration(); $connectionParams = ['url' => $c->get('db_url'), 'driverOptions' => [\PDO::ATTR_EMULATE_PREPARES => false]]; $conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config); return $conn; }); $container->set('event_dispatcher', function ($c) { $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $tags = $c->getTags('event_listener'); foreach ($tags as $tag) { $listener = $c->get($tag['service_id']); $dispatcher->addSubscriber($listener); } return $dispatcher; }); $container->set('kernel_cors_listener', function () { return new \Cerad\Module\KernelModule\EventListener\CorsListener(); }, 'event_listener'); }
function setup() { $this->application = new ApplicationWithTerminalWidth('TestApplication', '0.0.0'); $this->commandFactory = new AnnotatedCommandFactory(); $alterOptionsEventManager = new AlterOptionsCommandEvent($this->application); $eventDispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $eventDispatcher->addSubscriber($this->commandFactory->commandProcessor()->hookManager()); $eventDispatcher->addSubscriber($alterOptionsEventManager); $this->application->setDispatcher($eventDispatcher); $this->application->setAutoExit(false); }
/** * Test default_configs * * @dataProvider default_configs_data */ public function test_default_configs($allow, $require, $registered, $is_bot, $expected) { $this->config['allow_birthdays'] = $allow; $this->config['birthday_require'] = $require; $this->set_listener(); $this->template->expects($this->exactly($expected))->method('assign_vars'); $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $dispatcher->addListener('core.user_setup', array($this->listener, 'default_configs')); $event_data = array('user_data' => array('is_bot' => $is_bot, 'is_registered' => $registered)); $event = new \phpbb\event\data(compact($event_data)); $dispatcher->dispatch('core.user_setup', $event); }
/** * */ private function ping() { try { $response = $this->dispatcher->dispatch('utility.ping', new Expressly\Event\ResponseEvent()); } catch (Exception $e) { } }
/** * Visits & tests StepNode. * * @param Behat\Gherkin\Node\AbstractNode $step * * @return integer */ public function visit(AbstractNode $step) { $step->setTokens($this->tokens); $this->dispatcher->dispatch('beforeStep', new StepEvent($step, $this->context)); $afterEvent = $this->executeStep($step); $this->dispatcher->dispatch('afterStep', $afterEvent); return $afterEvent->getResult(); }
public function createAction(Request $request) { $recipe = new Recipe(); $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $listener = $this->container->get('my_recipes.recipes_listener'); $dispatcher->addListener('recipe.create', array($listener, 'onRecipeCreate')); $em = $this->getDoctrine()->getManager(); $em->persist($recipe); $form = $this->createForm(new RecipeType(), $recipe); $form->handleRequest($request); if ($form->isValid()) { $em->flush(); $this->get('event_dispatcher')->dispatch('recipe.create', new RecipeEvent($recipe)); return $this->redirect($this->generateUrl('recipe_show', array('id' => $recipe->getId()))); } //# http://brentertainment.com/other/docs/cookbook/form/twig_form_customization.html#cookbook-form-twig-two-methods return $this->render("MyRecipesBundle:Recipe:form.html.twig", array("form" => $form->createView())); }
/** * @dataProvider post_auth_data */ public function test_post_auth($auth_data, $event_data, $expected_result_data) { // Modify auth $this->auth->expects($this->any())->method('acl_get')->with($this->stringContains('_'), $this->anything())->will($this->returnValueMap($auth_data)); // fetch listener $listener = $this->get_listener(); // Create Events $event = new \Symfony\Component\EventDispatcher\GenericEvent(null, $event_data); $expected_result = new \Symfony\Component\EventDispatcher\GenericEvent(null, $expected_result_data); // Dispatch $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $dispatcher->addListener('gn36.def_listen', array($listener, 'post_auth')); $dispatcher->dispatch('gn36.def_listen', $event); // Modify expected result event to mimic correct dispatch data $expected_result->setDispatcher($dispatcher); $expected_result->setName('gn36.def_listen'); // Check $this->assertEquals($expected_result, $event); }
/** * @return \Symfony\Component\EventDispatcher\EventDispatcher */ public function createEventDispatcher() { $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $dispatcher->addListener('hook_civicrm_post::Activity', array('\\Civi\\CCase\\Events', 'fireCaseChange')); $dispatcher->addListener('hook_civicrm_post::Case', array('\\Civi\\CCase\\Events', 'fireCaseChange')); $dispatcher->addListener('hook_civicrm_caseChange', array('\\Civi\\CCase\\Events', 'delegateToXmlListeners')); $dispatcher->addListener('hook_civicrm_caseChange', array('\\Civi\\CCase\\SequenceListener', 'onCaseChange_static')); return $dispatcher; }
public function testDispatchingEventsOnJob() { // Worker mock $worker = $this->getMockBuilder('\\GearmanWorker')->disableOriginalConstructor()->getMock(); $worker->method('addServer')->willReturn(true); // Wrapper mock $workers = array(0 => array('className' => "Mmoreram\\GearmanBundle\\Tests\\Service\\Mocks\\SingleCleanFile", 'fileName' => dirname(__FILE__) . '/Mocks/SingleCleanFile.php', 'callableName' => null, 'description' => "test", 'service' => false, 'servers' => array(), 'iterations' => 1, 'timeout' => null, 'minimumExecutionTime' => null, 'jobs' => array(0 => array('callableName' => "test", 'methodName' => "test", 'realCallableName' => "test", 'jobPrefix' => NULL, 'realCallableNameNoPrefix' => "test", 'description' => "test", 'iterations' => 1, 'servers' => array(), 'defaultMethod' => "doBackground", 'minimumExecutionTime' => null, 'timeout' => null)))); $wrapper = $this->getMockBuilder('Mmoreram\\GearmanBundle\\Service\\GearmanCacheWrapper')->disableOriginalConstructor()->getMock(); $wrapper->method('getWorkers')->willReturn($workers); // Prepare a dispatcher to listen to tested events $startingFlag = false; $executedFlag = false; $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $dispatcher->addListener(GearmanEvents::GEARMAN_WORK_STARTING, function () use(&$startingFlag) { $startingFlag = true; }); $dispatcher->addListener(GearmanEvents::GEARMAN_WORK_EXECUTED, function () use(&$executedFlag) { $executedFlag = true; }); // Create the service under test $service = new GearmanExecute($wrapper, array()); $service->setEventDispatcher($dispatcher); // We need a job object, this part could be improved $object = new \Mmoreram\GearmanBundle\Tests\Service\Mocks\SingleCleanFile(); // Finalize worker mock by making it call our job object // This is normally handled by Gearman, but for test purpose we must simulate it $worker->method('work')->will($this->returnCallback(function () use($service, $object) { $service->handleJob(new \GearmanJob(), array('job_object_instance' => $object, 'job_method' => 'myMethod', 'jobs' => array())); return true; })); // Execute a job :) $service->executeJob('test', array(), $worker); // Do we have the events ? $this->assertTrue($startingFlag); $this->assertTrue($executedFlag); }
/** * @return \Symfony\Component\EventDispatcher\EventDispatcher */ public function createEventDispatcher() { $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $dispatcher->addListener('hook_civicrm_post::Activity', array('\\Civi\\CCase\\Events', 'fireCaseChange')); $dispatcher->addListener('hook_civicrm_post::Case', array('\\Civi\\CCase\\Events', 'fireCaseChange')); $dispatcher->addListener('hook_civicrm_caseChange', array('\\Civi\\CCase\\Events', 'delegateToXmlListeners')); $dispatcher->addListener('hook_civicrm_caseChange', array('\\Civi\\CCase\\SequenceListener', 'onCaseChange_static')); $dispatcher->addListener('DAO::post-insert', array('\\CRM_Core_BAO_RecurringEntity', 'triggerInsert')); $dispatcher->addListener('DAO::post-update', array('\\CRM_Core_BAO_RecurringEntity', 'triggerUpdate')); $dispatcher->addListener('DAO::post-delete', array('\\CRM_Core_BAO_RecurringEntity', 'triggerDelete')); $dispatcher->addListener('hook_civicrm_unhandled_exception', array('CRM_Core_LegacyErrorHandler', 'handleException')); return $dispatcher; }
#!/usr/bin/php <?php $config = ['require_services' => ['sf_event_dispatcher', 'sf_http_foundation', 'sf_debug', 'psr_log', 'sf_routing'], 'git_urls' => ['https://github.com/symfony/HttpKernel.git' => 'sf_http_kernel/'], 'autoload_config' => ['sf_http_kernel/' => 'Symfony\\Component\\HttpKernel'], 'example' => function () { $old_level = error_reporting(); error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_USER_DEPRECATED & ~E_STRICT); $routes = new \Symfony\Component\Routing\RouteCollection(); $routes->add('hello', new \Symfony\Component\Routing\Route('/', ['_controller' => function (\Symfony\Component\HttpFoundation\Request $request) { return new \Symfony\Component\HttpFoundation\Response(sprintf("Hello %s", $request->get('name'))); }])); $request = \Symfony\Component\HttpFoundation\Request::createFromGlobals(); $context = new \Symfony\Component\Routing\RequestContext(); $context->fromRequest($request); $matcher = new \Symfony\Component\Routing\Matcher\UrlMatcher($routes, $context); $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $dispatcher->addSubscriber(new \Symfony\Component\HttpKernel\EventListener\RouterListener($matcher)); $resolver = new \Symfony\Component\HttpKernel\Controller\ControllerResolver(); $kernel = new \Symfony\Component\HttpKernel\HttpKernel($dispatcher, $resolver); $kernel->handle($request)->send(); echo PHP_EOL; error_reporting($old_level); }]; if ($return_config) { return $config; } require_once __DIR__ . '/_yf_autoloader.php'; new yf_autoloader($config);
/** * validate that we can interact with the visit process using an eventlistener * * @return void */ public function testThrowsEvent() { $query = 'eq(name,replaceme)&limit(10)'; $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $dispatcher->addListener('rql.visit.node', [new \Graviton\Rql\Listener\TestListener(), 'onVisitNode']); $visitor = new MongoOdm(); $visitor->setBuilder($this->builder); $visitor->setDispatcher($dispatcher); $results = $this->runTestQuery($query, $visitor); $this->assertCount(1, $results); $this->assertEquals('My First Sprocket', $results[0]->name); }
$fs->copy(Application::ROOT_DIR . '/app/resources/envmgr.db', $envMgrPath . '/envmgr.db'); // Try to connect to the database. $database = new Database($envMgrPath . '/envmgr.db'); } catch (DatabaseNotFoundException $e) { print sprintf('Error: %s' . "\n", $e->getMessage()); exit; } catch (Exception $e) { print 'An unknown exception occured while trying to load the database.' . "\n"; exit; } return $database; }); $c->addService('docker', function () { return new \commpress\Cli\Service\Docker\DockerManager(); }); $c->addService('filesystem', function () { return new \commpress\Cli\Service\Filesystem\Filesystem(); }); $c->addService('platform_config_parser', function () { return new \commpress\Cli\Service\Platform\PlatformConfigParser(); }); $c->addService('drupal.helper', function () { return new \commpress\Cli\Service\Drupal\DrupalHelper(); }); $c->addService('event_dispatcher', function () { $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $dispatcher->addSubscriber(new \commpress\Cli\Event\Subscriber\EnvironmentSubscriber()); $dispatcher->addSubscriber(new \commpress\Cli\Event\Subscriber\VirtualHostSubscriber()); return $dispatcher; }); return $c;
public function register(Application $app) { $config = $this->config; $app['devture_nagios.bundle_path'] = dirname(__FILE__); $app['devture_nagios.colors'] = array('#014de7', '#3a87ad', '#06cf99', '#8fcf06', '#dda808', '#e76d01', '#7801e7', '#353535', '#888888'); $app['devture_nagios.db'] = $app->share(function ($app) use($config) { return $app[$config['database_service_id']]; }); $app['devture_nagios.event_dispatcher'] = $app->share(function ($app) { $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); foreach ($app['devture_nagios.event_subscribers'] as $subscriber) { $dispatcher->addSubscriber($subscriber); } return $dispatcher; }); $app['devture_nagios.event_subscribers'] = function ($app) { return array($app['devture_nagios.time_period.event_subscriber'], $app['devture_nagios.command.event_subscriber'], $app['devture_nagios.host.event_subscriber'], $app['devture_nagios.contact.event_subscriber']); }; $app['devture_nagios.time_period.event_subscriber'] = $app->share(function ($app) { return new Event\Subscriber\TimePeriodEventsSubscriber($app); }); $app['devture_nagios.time_period.repository'] = $app->share(function ($app) { return new Repository\TimePeriodRepository($app['devture_nagios.event_dispatcher'], $app['devture_nagios.db']); }); $app['devture_nagios.time_period.validator'] = function ($app) { return new Validator\TimePeriodValidator($app['devture_nagios.time_period.repository']); }; $app['devture_nagios.time_period.form_binder'] = function ($app) { $binder = new Form\TimePeriodFormBinder($app['devture_nagios.time_period.validator']); $binder->setCsrfProtection($app['devture_framework.csrf_token_manager'], 'time_period'); return $binder; }; $app['devture_nagios.command.event_subscriber'] = $app->share(function ($app) { return new Event\Subscriber\CommandEventsSubscriber($app); }); $app['devture_nagios.command.repository'] = $app->share(function ($app) { return new Repository\CommandRepository($app['devture_nagios.event_dispatcher'], $app['devture_nagios.db']); }); $app['devture_nagios.command.validator'] = function ($app) { return new Validator\CommandValidator($app['devture_nagios.command.repository']); }; $app['devture_nagios.command.form_binder'] = function ($app) { $binder = new Form\CommandFormBinder($app['devture_nagios.command.validator']); $binder->setCsrfProtection($app['devture_framework.csrf_token_manager'], 'command'); return $binder; }; $app['devture_nagios.contact.event_subscriber'] = $app->share(function ($app) { return new Event\Subscriber\ContactEventsSubscriber($app); }); $app['devture_nagios.contact.repository'] = $app->share(function ($app) { return new Repository\ContactRepository($app['devture_nagios.event_dispatcher'], $app['devture_nagios.time_period.repository'], $app['devture_nagios.command.repository'], $app['devture_user.repository'], $app['devture_nagios.db']); }); $app['devture_nagios.contact.validator'] = function ($app) { return new Validator\ContactValidator($app['devture_nagios.contact.repository']); }; $app['devture_nagios.contact.form_binder'] = function ($app) { $binder = new Form\ContactFormBinder($app['devture_nagios.time_period.repository'], $app['devture_nagios.command.repository'], $app['devture_user.repository'], $app['devture_nagios.helper.access_checker'], $app['devture_user.access_control'], $app['devture_nagios.contact.validator']); $binder->setCsrfProtection($app['devture_framework.csrf_token_manager'], 'contact'); return $binder; }; $app['devture_nagios.host.event_subscriber'] = $app->share(function ($app) { return new Event\Subscriber\HostEventsSubscriber($app); }); $app['devture_nagios.host.repository'] = $app->share(function ($app) { return new Repository\HostRepository($app['devture_nagios.event_dispatcher'], $app['devture_nagios.db']); }); $app['devture_nagios.host.validator'] = function ($app) { return new Validator\HostValidator($app['devture_nagios.host.repository']); }; $app['devture_nagios.host.form_binder'] = function ($app) { $binder = new Form\HostFormBinder($app['devture_nagios.host.validator']); $binder->setCsrfProtection($app['devture_framework.csrf_token_manager'], 'host'); return $binder; }; $app['devture_nagios.service.defaults'] = new \ArrayObject($config['defaults']['service']); $app['devture_nagios.service.repository'] = $app->share(function ($app) { return new Repository\ServiceRepository($app['devture_nagios.host.repository'], $app['devture_nagios.command.repository'], $app['devture_nagios.contact.repository'], $app['devture_nagios.db']); }); $app['devture_nagios.service.validator'] = function ($app) { return new Validator\ServiceValidator($app['devture_nagios.service.repository']); }; $app['devture_nagios.service.form_binder'] = function ($app) { $binder = new Form\ServiceFormBinder($app['devture_nagios.contact.repository'], $app['devture_nagios.service.validator']); $binder->setCsrfProtection($app['devture_framework.csrf_token_manager'], 'service'); return $binder; }; $app['devture_nagios.resource.repository'] = $app->share(function ($app) { return new Repository\ResourceRepository($app['devture_nagios.db']); }); $app['devture_nagios.resource.validator'] = function ($app) { return new Validator\ResourceValidator(); }; $app['devture_nagios.resource.form_binder'] = function ($app) { $binder = new Form\ResourceFormBinder($app['devture_nagios.resource.validator']); $binder->setCsrfProtection($app['devture_framework.csrf_token_manager'], 'resource'); return $binder; }; $app['devture_nagios.helper.colorizer'] = $app->share(function ($app) { return new Helper\Colorizer($app['devture_nagios.colors']); }); $app['devture_nagios.helper.access_checker'] = $app->share(function ($app) { return new Helper\AccessChecker(); }); $app['devture_nagios.twig.extension'] = function ($app) { return new Twig\NagiosExtension($app); }; $this->overrideUserServices($app); $this->registerDeploymentServices($app); $this->registerEmailServices($app); $this->registerSmsServices($app); $this->registerInstallerServices($app); $this->registerInteractionServices($app); $this->registerApiModelBridgeServices($app); $this->registerConsoleServices($app); $this->registerControllers($app); }
/** * Triggers the listeners of an event. * * This method can be overridden to add functionality that is executed * for each listener. * * @param callable[] $listeners The event listeners. * @param string $eventName The name of the event to dispatch. * @param Event $event The event object to pass to the event handlers/listeners. */ protected static function doDispatch($listeners, $eventName, Symfony\Component\EventDispatcher\Event $event) { return static::$instance->doDispatch($listeners, $eventName, $event); }
/** * Test the setup * * @dataProvider setup_data */ public function test_setup($user_id, $is_reg, $is_bot, $pull_time, $expected, $last_n, $time_n) { $this->user->data['user_id'] = $user_id; $this->user->data['is_registered'] = $is_reg; $this->user->data['is_bot'] = $is_bot; $this->config['notification_pull_time'] = $pull_time; $this->config['enable_mod_rewrite'] = false; $this->config['cookie_domain'] = 'localhost'; $this->config['cookie_name'] = 'phpbb3_asd_obj'; $this->config['cookie_path'] = '/'; $this->set_listener(); if ($expected > 0) { $this->template->expects($this->exactly($expected))->method('assign_vars')->with(array('ACTIVE_NOTIFICATION_LAST' => $last_n, 'ACTIVE_NOTIFICATION_TIME' => $time_n, 'ACTIVE_NOTIFICATION_URL' => false, 'ACTIVE_NOTIFICATIONS_COOKIE_DOMAIN' => 'localhost', 'ACTIVE_NOTIFICATIONS_COOKIE_NAME' => 'phpbb3_asd_obj_an', 'ACTIVE_NOTIFICATIONS_COOKIE_PATH' => '/')); } else { $this->template->expects($this->exactly(0))->method('assign_vars'); } $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $dispatcher->addListener('core.page_header', array($this->listener, 'setup')); $dispatcher->dispatch('core.page_header'); }
function assertRunCommandViaApplicationEquals($command, $input, $expectedOutput, $expectedStatusCode = 0) { $output = new BufferedOutput(); if ($this->commandFileInstance && method_exists($this->commandFileInstance, 'setOutput')) { $this->commandFileInstance->setOutput($output); } $application = new Application('TestApplication', '0.0.0'); $alterOptionsEventManager = new AlterOptionsCommandEvent($application); $eventDispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $eventDispatcher->addSubscriber($this->commandFactory->commandProcessor()->hookManager()); $eventDispatcher->addSubscriber($alterOptionsEventManager); $application->setDispatcher($eventDispatcher); $application->setAutoExit(false); $application->add($command); $statusCode = $application->run($input, $output); $commandOutput = trim($output->fetch()); $this->assertEquals($expectedOutput, $commandOutput); $this->assertEquals($expectedStatusCode, $statusCode); }
/** * Doctrine DBAL Bridge * Copyright (C) 2013 Tristan Lins * * PHP version 5 * * @copyright bit3 UG 2013 * @author Tristan Lins <*****@*****.**> * @package doctrine-dbal * @license LGPL * @filesource */ /** @var Pimple $container */ $container['event-dispatcher'] = $container->share(function () { $eventDispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); if (isset($GLOBALS['TL_EVENTS']) && is_array($GLOBALS['TL_EVENTS'])) { foreach ($GLOBALS['TL_EVENTS'] as $eventName => $listeners) { foreach ($listeners as $listener) { if (is_array($listener) && count($listener) === 2 && is_int($listener[1])) { list($listener, $priority) = $listener; } else { $priority = 0; } $eventDispatcher->addListener($eventName, $listener, $priority); } } } if (isset($GLOBALS['TL_EVENT_SUBSCRIBERS']) && is_array($GLOBALS['TL_EVENT_SUBSCRIBERS'])) { foreach ($GLOBALS['TL_EVENT_SUBSCRIBERS'] as $eventSubscriber) { if (!is_object($eventSubscriber)) {
<?php $botCommands = array(); require __DIR__ . '/config.php'; require __DIR__ . '/vendor/autoload.php'; function exception_error_handler($errno, $errstr, $errfile, $errline) { throw new ErrorException($errstr, 0, $errno, $errfile, $errline); } set_error_handler("exception_error_handler"); $app = new Silex\Application(); $app->register(new Silex\Provider\ValidatorServiceProvider()); $eventDispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $ircConnection = new \Whisnet\IrcBotBundle\Connection\Socket($serverUrl, $serverPort, $app['validator'], $eventDispatcher); $listener['whisnet_irc_bot.command_PING'] = array(new \Whisnet\IrcBotBundle\EventListener\Irc\Messages\PingListener($ircConnection, $eventDispatcher), 'onData'); $listener['whisnet_irc_bot.irc_command_PRIVMSG'] = array(new \Whisnet\IrcBotBundle\EventListener\Irc\Messages\PrivMsgListener($ircConnection, $eventDispatcher, $commandPrefix), 'onData'); $listener['whisnet_irc_bot.data_from_server'] = array(new \Whisnet\IrcBotBundle\EventListener\Irc\ServerRequestListener($ircConnection, $eventDispatcher), 'onData'); foreach ($listener as $eventName => $eventHandler) { $eventDispatcher->addListener($eventName, $eventHandler, 10); } unset($listener); $loadUserCoreListener = new Whisnet\IrcBotBundle\EventListener\Plugins\Core\LoadUserCoreListener($ircConnection); $loadUserCoreListener->setConfig($user, $channels); $listener['whisnet_irc_bot.post_connection'] = array($loadUserCoreListener, 'onCore'); $helpList = new SplDoublyLinkedList(); foreach ($botCommands as $commandType => $commands) { foreach ($commands as $command => $commandData) { if (!$commandData['isActive']) { continue; } if (array_key_exists('classFile', $commandData)) {
/** * @param string $entity * @param string $action * @param array $params * @param bool $throws whether we should pass any exceptions for authorization failures * * @throws API_Exception * @throws Exception * @return bool TRUE or FALSE depending on the outcome of the authorization check */ function runPermissionCheck($entity, $action, $params, $throws = FALSE) { $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $dispatcher->addSubscriber(new \Civi\API\Subscriber\PermissionCheck()); $kernel = new \Civi\API\Kernel($dispatcher); $apiRequest = \Civi\API\Request::create($entity, $action, $params, NULL); try { $kernel->authorize(NULL, $apiRequest); return TRUE; } catch (\API_Exception $e) { $extra = $e->getExtraParams(); if (!$throws && $extra['error_code'] == API_Exception::UNAUTHORIZED) { return FALSE; } else { throw $e; } } }
/** * Test events * * @dataProvider gallery_link_in_profile_data * profile_fileds * get_user_ids */ public function test_gallery_link_events($option, $user_id, $expect) { $this->config['phpbb_gallery_profile_pega'] = $option; $user_ids = array($user_id); $event_data = array('user_ids'); $event_one = new \phpbb\event\data(compact($event_data)); $profile_row = array(); $event_two_data = array('profile_row'); $event_two = new \phpbb\event\data(compact($event_two_data)); $this->set_listener(); $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $dispatcher->addListener('core.grab_profile_fields_data', array($this->listener, 'get_user_ids')); $dispatcher->addListener('core.generate_profile_fields_template_data_before', array($this->listener, 'profile_fileds')); $dispatcher->dispatch('core.grab_profile_fields_data', $event_one); $dispatcher->dispatch('core.generate_profile_fields_template_data_before', $event_two); $ouput = $event_two->get_data_filtered($event_two_data); $expacted = array('phpbb_gallery' => array('value' => array('album_id' => 1), 'data' => array('field_id' => '', 'lang_id' => '', 'lang_name' => 'GALLERY', 'lang_explain' => '', 'lang_default_value' => '', 'field_name' => 'phpbb_gallery', 'field_type' => 'profilefields.type.url', 'field_ident' => 'phpbb_gallery', 'field_length' => '40', 'field_minlen' => '12', 'field_maxlen' => '255', 'field_novalue' => '', 'field_default_value' => '', 'field_validation' => '', 'field_required' => '0', 'field_show_on_reg' => '0', 'field_hide' => '0', 'field_no_view' => '0', 'field_active' => '1', 'field_order' => '', 'field_show_profile' => '1', 'field_show_on_vt' => '1', 'field_show_novalue' => '0', 'field_show_on_pm' => '1', 'field_show_on_ml' => '1', 'field_is_contact' => '1', 'field_contact_desc' => 'VISIT_GALLERY', 'field_contact_url' => '%s'))); if ($expect) { $this->assertEquals($expacted, $ouput['profile_row']); } else { $this->assertEmpty($ouput['profile_row']); } }
<?php include_once __DIR__ . '/../vendor/autoload.php'; ini_set('display_errors', 1); $adapter = new Itkg\Core\Cache\Adapter\Bridge\Doctrine(new \Doctrine\Common\Cache\FilesystemCache('/tmp')); $registry = new \Itkg\Core\Cache\Adapter\Registry(); $eventDispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $eventDispatcher->addSubscriber(new \Itkg\Consumer\Listener\CacheListener($eventDispatcher)); $eventDispatcher->addSubscriber(new \Itkg\Consumer\Listener\LoggerListener()); $eventDispatcher->addSubscriber(new \Itkg\Consumer\Listener\DeserializerListener(JMS\Serializer\SerializerBuilder::create()->build())); $eventDispatcher->addSubscriber(new \Itkg\Consumer\Listener\CacheControlListener(new \Itkg\Consumer\Cache\ServiceCacheQueueWriter($adapter))); $service = new \Itkg\Consumer\Service\Service($eventDispatcher, new Itkg\Consumer\Client\RestClient(array('timeout' => 10)), array('identifier' => 'my test', 'cache_adapter' => $adapter, 'cache_ttl' => 3600, 'cache_warmup' => true, 'cache_fresh_ttl' => 10)); $service->sendRequest(\Symfony\Component\HttpFoundation\Request::create('XXXX'))->getResponse(); $service = new \Itkg\Consumer\Service\Service($eventDispatcher, new Itkg\Consumer\Client\RestClient(array('timeout' => 10)), array('cache_ttl' => 20, 'cache_adapter' => $registry, 'identifier' => 'my test')); $service->sendRequest(\Symfony\Component\HttpFoundation\Request::create('XXXX'))->getResponse(); $service = new \Itkg\Consumer\Service\Service($eventDispatcher, new Itkg\Consumer\Client\RestClient(array('timeout' => 10)), array('identifier' => 'my test', 'logger' => new \Monolog\Logger('my_logger', array(new \Monolog\Handler\StreamHandler('/tmp/test'))))); $response = $service->sendRequest(\Symfony\Component\HttpFoundation\Request::create('XXXX'))->getResponse();
<?php require __DIR__ . '/vendor/autoload.php'; require __DIR__ . '/src/KarmaCommandListener.php'; function exception_error_handler($errno, $errstr, $errfile, $errline) { throw new ErrorException($errstr, 0, $errno, $errfile, $errline); } set_error_handler("exception_error_handler"); $app = new Silex\Application(); $app->register(new Silex\Provider\ValidatorServiceProvider()); $eventDispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $ircConnection = new \Whisnet\IrcBotBundle\Connection\Socket('irc.freenode.net', 6667, $app['validator'], $eventDispatcher); $commandPrefix = '!bot'; $user = array('username' => 'thebot|' . rand(55, 950), 'mode' => '8', 'realname' => 'mana-bot'); $channels = array('#magento-de', '#magento-offtopic-de', '#magento-dev'); $listener['whisnet_irc_bot.command_PING'] = array(new \Whisnet\IrcBotBundle\EventListener\Irc\Messages\PingListener($ircConnection, $eventDispatcher), 'onData'); $listener['whisnet_irc_bot.irc_command_PRIVMSG'] = array(new \Whisnet\IrcBotBundle\EventListener\Irc\Messages\PrivMsgListener($ircConnection, $eventDispatcher, $commandPrefix), 'onData'); $listener['whisnet_irc_bot.data_from_server'] = array(new \Whisnet\IrcBotBundle\EventListener\Irc\ServerRequestListener($ircConnection, $eventDispatcher), 'onData'); #= '\Whisnet\IrcBotBundle\EventListener\Irc\ServerRequestListener'; foreach ($listener as $eventName => $eventHandler) { $eventDispatcher->addListener($eventName, $eventHandler, 10); } unset($listener); $loadUserCoreListener = new Whisnet\IrcBotBundle\EventListener\Plugins\Core\LoadUserCoreListener($ircConnection); $loadUserCoreListener->setConfig($user, $channels); $listener['whisnet_irc_bot.post_connection'] = array($loadUserCoreListener, 'onCore'); $listener['whisnet_irc_bot.bot_command_join'] = array(new \Whisnet\IrcBotBundle\EventListener\Plugins\Commands\JoinCommandListener($ircConnection), 'onCommand'); $listener['whisnet_irc_bot.bot_command_part'] = array(new \Whisnet\IrcBotBundle\EventListener\Plugins\Commands\PartCommandListener($ircConnection), 'onCommand'); /* $listener['whisnet_irc_bot.bot_command_quit']