public dispatch ( $eventName, Symfony\Component\EventDispatcher\Event $event = null ) | ||
$event | Symfony\Component\EventDispatcher\Event |
/** * @param array $items */ public function write(array $items) { // file_put_contents('options.json', json_encode($items)); foreach ($items as $item) { try { $this->webservice->sendAttributeOption($item); } catch (\Exception $e) { $event = new InvalidItemEvent(__CLASS__, $e->getMessage(), array(), ['code' => key($item)]); // Logging file $this->eventDispatcher->dispatch(EventInterface::INVALID_ITEM, $event); // Loggin Interface $this->stepExecution->addWarning(__CLASS__, $e->getMessage(), array(), ['code' => key($item)]); /** @var ClientErrorResponseException $e */ if ($e->getResponse()->getStatusCode() <= 404) { $e = new \Exception($e->getResponse()->getReasonPhrase()); $this->stepExecution->addFailureException($e); $exitStatus = new ExitStatus(ExitStatus::FAILED); $this->stepExecution->setExitStatus($exitStatus); } // Handle next element. } $this->stepExecution->incrementWriteCount(); $this->stepExecution->incrementSummaryInfo('write'); } }
public function checkAndProxyEvent(CrawlerRequestEvent $event, $name) { $uri = $event->getRequest()->getUri(); if ($this->matcher->matches($uri)) { $this->dispatcher->dispatch($name, $event); } }
/** * {@inheritdoc} */ public function execute(EventDispatcher $dispatcher) { $this->ticksRemaining = $this->units; $dispatcher->dispatch(Events::STEP_BEFORE_EXECUTE, new StepEvent($this)); call_user_func($this->executer, $this); $dispatcher->dispatch(Events::STEP_AFTER_EXECUTE, new StepEvent($this)); }
/** * {@inheritdoc} */ public function commit() { while (!$this->messages->isEmpty()) { $message = $this->messages->dequeue(); $this->eventDispatcher->dispatch($message->getName(), new GenericEvent($message)); } }
/** * Create, configure and build datagrid * * @param DatagridConfiguration $config * * @return DatagridInterface */ public function build(DatagridConfiguration $config) { $class = $config->offsetGetByPath(self::BASE_DATAGRID_CLASS_PATH, $this->baseDatagridClass); $name = $config->getName(); /** @var Acceptor $acceptor */ $acceptor = new $this->acceptorClass($config); /** @var DatagridInterface $datagrid */ $datagrid = new $class($name, $acceptor); $event = new BuildBefore($datagrid, $config); $this->eventDispatcher->dispatch(BuildBefore::NAME, $event); // duplicate event dispatch with grid name $this->eventDispatcher->dispatch(BuildBefore::NAME . '.' . $name, $event); $this->buildDataSource($datagrid, $config); foreach ($this->extensions as $extension) { if ($extension->isApplicable($config)) { $acceptor->addExtension($extension); } } $acceptor->processConfiguration(); $event = new BuildAfter($datagrid); $this->eventDispatcher->dispatch(BuildAfter::NAME, $event); // duplicate event dispatch with grid name $this->eventDispatcher->dispatch(BuildAfter::NAME . '.' . $name, $event); return $datagrid; }
protected function fire($event, Event $eventType) { foreach ($this->scenario->getGroups() as $group) { $this->dispatcher->dispatch($event . '.' . $group, $eventType); } $this->dispatcher->dispatch($event, $eventType); }
/** * Dispatch event. * * @param string $name * @param Event $event */ private function dispatchEvent($name, Event $event) { if (null === $this->eventDispatcher) { return; } $this->eventDispatcher->dispatch($name, $event); }
/** * Navbar Menu * * @param array $options * @return ItemInterface */ public function createPrimaryMenu(array $options) { $menu = $this->factory->createItem('root'); $this->eventDispatcher->dispatch(WebsiteEvents::PRIMARY_MENU_INIT, new PrimaryMenuEvent($menu, $this->factory)); $this->reorderMenuItems($menu); return $menu; }
public function onCommitDone() { $this->eventDispatcher->dispatch('commitDone', new CommitDoneEvent()); foreach ($this->onCommitDoneCallbacks as $callback) { call_user_func($callback); } }
/** * @param string $method * @param string$uri * @param array $queryParams * @param array $requestParams * @param array $options * @param bool $secured * * @return array|stdClass * @throws GuzzleException * @throws Exception */ public function request($method, $uri, array $queryParams, array $requestParams, array $options, $secured) { $this->eventDispatcher->dispatch(BeforeClientRequestEvent::NAME, new BeforeClientRequestEvent($method, $uri, $queryParams, $requestParams, $options, $secured)); $originalRequest = ['method' => $method, 'uri' => $uri, 'queryParams' => $queryParams, 'requestParams' => $requestParams, 'option' => $options, 'secured' => $secured]; //Check for on behalf of in order to inject it if needed $isOnBehalfOfUsedInParams = false; foreach ([&$queryParams, &$requestParams] as &$paramsArray) { if (array_key_exists('on_behalf_of', $paramsArray)) { //isset is not used because id skips null-s if (null !== $paramsArray['on_behalf_of']) { $this->session->setOnBehalfOf($paramsArray['on_behalf_of']); $isOnBehalfOfUsedInParams = true; } else { $onBehalfOf = $this->session->getOnBehalfOf(); if (null !== $onBehalfOf) { $paramsArray['on_behalf_of'] = $onBehalfOf; } } } } try { //Wrap whole section if someone, for example, throws exceptions for PHP warnings etc. if ($secured) { //Perhaps check here if auth token set? $options['headers']['X-Auth-Token'] = $this->session->getAuthToken(); } $queryParams = array_filter($queryParams); $requestParams = array_filter($requestParams); if (count($requestParams) > 0) { if (!isset($options['form_params'])) { $options['form_params'] = []; } $options['form_params'] = array_merge($options['form_params'], $requestParams); } //Force no-exceptions in order to provide descriptive error messages $options['http_errors'] = false; $url = $this->applyApiBaseUrl($uri, $queryParams); $response = $this->client->request($method, $url, $options); switch ($response->getStatusCode()) { case 200: $data = json_decode($response->getBody()->getContents()); return $data; default: //Everything that's not 200 consider error and dispatch event $event = new ClientHttpErrorEvent($response, $requestParams, $method, $url, $originalRequest); $this->eventDispatcher->dispatch(ClientHttpErrorEvent::NAME, $event); $interceptedResponse = $event->getInterceptedResponse(); if (null !== $interceptedResponse) { return $interceptedResponse; } } } finally { //If on-behalf-of was injected through params, clear it now if ($isOnBehalfOfUsedInParams) { $this->session->clearOnBehalfOf(); } } throw new Exception($response->getBody()->getContents()); }
public function handleResponse(ApiResponse $response) { if (null != $this->eventDispatcher) { $event = new ApiResponseEvent($response); $this->eventDispatcher->dispatch(ApiEvent::API_RESPONSE, $event); } return $response; }
public function buildForm(FormBuilderInterface $builder, array $options) { $tags = $this->topicManager->getAvailableTags(); $builder->add('mainPost', "post")->add('tags', 'entity', array("choices" => $tags, 'class' => 'SymbbCoreForumBundle:Topic\\Tag', 'required' => false, "multiple" => true))->add('locked', 'checkbox', array('required' => false, 'label' => 'close topic'))->add('id', 'hidden')->add('forum', 'entity', array('class' => 'SymbbCoreForumBundle:Forum', 'disabled' => true)); // create Event to manipulate Post Form $event = new FormTopicEvent($builder, $this->translator, $this->topicManager, $this->userManager, $this->groupManager); $this->dispatcher->dispatch('symbb.core.forum.topic.form.create', $event); }
public function resolveCiActions(Request $request) { $event = new CiActionResolveEvent($request); if ($this->config['detect_controllers'] !== false) { $this->event_dispatcher->dispatch('nercury.ci_action_resolve', $event); } return $event->getResolvedActions(); }
/** * Verifies that permissions are changed. */ public function testChangePermissionsForCommittedSqon() { chmod($this->path, 0644); $this->dispatcher->addSubscriber(new ChmodSubscriber(0755)); $this->dispatcher->dispatch(AfterCommitEvent::NAME, new AfterCommitEvent($this->sqon)); clearstatcache(true, $this->path); self::assertEquals('755', substr(sprintf('%o', fileperms($this->path)), -3, 3), 'The file permissions were not set.'); }
/** * Set cache * * @param EntityLoadEvent $event * * @return void */ public function setCacheForEntity(EntityLoadEvent $event) { $entity = $event->getEntity(); if (!$entity->isLoaded()) { $this->cache->set($entity); $this->dispatcher->dispatch('cache.set', new CacheEvent($entity)); } }
/** * @group legacy */ public function testLegacyChildClassOnSubmitCallParent() { $form = $this->getBuilder('name')->setData($this->collection)->addEventSubscriber(new TestClassExtendingMergeDoctrineCollectionListener())->getForm(); $submittedData = array(); $event = new FormEvent($form, $submittedData); $this->dispatcher->dispatch(FormEvents::SUBMIT, $event); $this->assertTrue($this->collection->isEmpty()); $this->assertTrue(TestClassExtendingMergeDoctrineCollectionListener::$onBindCalled); }
/** * Call method, performs the call and sends the result to the dispatcher * * @param String $method * @param Array $params * @return Mixed */ public function __call($method, array $params = array()) { $before = new BeforeMethodEvent($this->alias, $method, $this->warden->getParams()); $this->dispatch->dispatch(WardenEvents::BEFORE_METHOD, $before); $returnValue = call_user_func_array([$this->service, $method], $params); $after = new AfterMethodEvent($this->alias, $method, $returnValue, $this->warden->getParams()); $this->dispatch->dispatch(WardenEvents::AFTER_METHOD, $after); return $returnValue; }
public function _proceed($job) { // I do what is required for new posts (Send mail to user and job board moderator) if ($job->getStatus() == 0) { $this->eventDispatcher->dispatch(JobEvents::JOB_CREATED, new JobEvent($job)); $msg = "Thanks, your job Post has been created and in moderation review"; return array('job' => $job, 'msg' => $msg, 'is_spam' => false); } }
/** * Execute steps * @param StepCollection $steps * @return Invoker */ public function execute(StepCollection $steps) { $this->dispatcher->dispatch(Events::INVOKER_START, new InvokerEvent($steps)); foreach ($steps->getIterator() as $step) { $step->execute($this->dispatcher); } $this->dispatcher->dispatch(Events::INVOKER_FINISH, new InvokerEvent($steps)); return $this; }
/** * @param $eventName * @param Event $event * * @return bool */ public function dispatchEvent($eventName, Event $event) { // Dispatch event if the event dispatcher is set if ($this->eventDispatcher instanceof EventDispatcherInterface) { $this->eventDispatcher->dispatch($eventName, $event); return true; } // Event not dispatched return false; }
protected function fire($event, \Codeception\Event\Test $eventType) { $test = $eventType->getTest(); if ($test instanceof TestCase) { foreach ($test->getScenario()->getGroups() as $group) { $this->dispatcher->dispatch($event . '.' . $group, $eventType); } } $this->dispatcher->dispatch($event, $eventType); }
public function it_should_dispatch_events(SubscriptionRepositoryInterface $repository, EventDispatcher $dispatcher, SubscriptionInterface $subscription) { $repository->findScheduled()->willReturn(array($subscription)); $dispatcher->dispatch(SubscriptionEvents::SUBSCRIPTION_PROCESS_BATCH_START, Argument::type('Symfony\\Component\\EventDispatcher\\GenericEvent'))->shouldBeCalled(); $dispatcher->dispatch(SubscriptionEvents::SUBSCRIPTION_PROCESS_BATCH_END, Argument::type('Symfony\\Component\\EventDispatcher\\GenericEvent'))->shouldBeCalled(); $dispatcher->dispatch(SubscriptionEvents::SUBSCRIPTION_PROCESS_INITIALIZE, Argument::type('Sylius\\Component\\Subscription\\Event\\SubscriptionEvent'))->shouldBeCalled(); $dispatcher->dispatch(SubscriptionEvents::SUBSCRIPTION_PROCESS_SUCCESS, Argument::type('Sylius\\Component\\Subscription\\Event\\SubscriptionEvent'))->shouldBeCalled(); $dispatcher->dispatch(SubscriptionEvents::SUBSCRIPTION_PROCESS_COMPLETED, Argument::type('Sylius\\Component\\Subscription\\Event\\SubscriptionEvent'))->shouldBeCalled(); $this->process(); }
/** * @test */ public function listensToPurge() { $self = $this; $message = $this->message; $this->output->expects($this->once())->method('writeln')->will($this->returnCallback(function ($output) use($self, $message) { $self->assertContains('purge', $output); })); $event = new Event(); $this->ed->dispatch(Events::PURGE, $event); }
/** * @param \FSi\Bundle\AdminBundle\Event\ListEvent $event * @param \Symfony\Component\HttpFoundation\Request $request * @param \Symfony\Component\EventDispatcher\EventDispatcher $eventDispatcher * @param \FSi\Component\DataSource\DataSource $dataSource * @throws \FSi\Component\DataSource\Exception\DataSourceException */ function it_return_response_from_post_datasource_bind_parameters_event($event, $request, $eventDispatcher, $dataSource) { $eventDispatcher->dispatch(ListEvents::LIST_DATASOURCE_REQUEST_PRE_BIND, $event)->shouldBeCalled(); $event->getDataSource()->willReturn($dataSource); $dataSource->bindParameters($request)->shouldBecalled(); $eventDispatcher->dispatch(ListEvents::LIST_DATASOURCE_REQUEST_POST_BIND, $event)->will(function () use($event) { $event->hasResponse()->willReturn(true); $event->getResponse()->willReturn(new Response()); }); $this->handleRequest($event, $request)->shouldReturnAnInstanceOf('Symfony\\Component\\HttpFoundation\\Response'); }
/** * Test that it actually collects data * * @return void */ public function test_it_collects_data() { $collector = new StopwatchCollector(); $collector->register($this->eventsDispatcher); // Fire the events $this->eventsDispatcher->dispatch(WardenEvents::WARDEN_START, $this->startEvent); usleep(600); $event = $this->eventsDispatcher->dispatch(WardenEvents::WARDEN_END, $this->stopEvent); $this->assertNotNull($event->params->getValue('request_time')); $this->assertNotNull($event->params->getValue('request_memory')); }
public function testExceptionListener() { $logger = $this->getMock('Psr\\Log\\LoggerInterface'); $logger->expects($this->at(0))->method('log')->with(LogLevel::CRITICAL, 'RuntimeException: Fatal error (uncaught exception) at ' . __FILE__ . ' line ' . (__LINE__ + 13)); $logger->expects($this->at(1))->method('log')->with(LogLevel::ERROR, 'Symfony\\Component\\HttpKernel\\Exception\\HttpException: Http error (uncaught exception) at ' . __FILE__ . ' line ' . (__LINE__ + 9)); $dispatcher = new EventDispatcher(); $dispatcher->addSubscriber(new LogListener($logger)); $kernel = $this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface'); $dispatcher->dispatch(KernelEvents::EXCEPTION, new GetResponseForExceptionEvent($kernel, Request::create('/foo'), HttpKernelInterface::SUB_REQUEST, new \RuntimeException('Fatal error'))); $dispatcher->dispatch(KernelEvents::EXCEPTION, new GetResponseForExceptionEvent($kernel, Request::create('/foo'), HttpKernelInterface::SUB_REQUEST, new HttpException(400, 'Http error'))); }
/** * Publish a message. * * @param Message\Message $message * @param string $exchangeName * @param string $routingkey */ public function publish(Message\Message $message, $exchangeName, $routingKey = null) { $this->eventDispatcher->dispatch(self::EVENT_PRE_PUBLISH, new PublishEvent($message)); $this->getExchange()->setName($exchangeName); if (!$routingKey) { $routingKey = $exchangeName; /* A convenient default */ } $this->exchange->messagePublish($message, $routingKey); $this->eventDispatcher->dispatch(self::EVENT_POST_PUBLISH, new PublishEvent($message)); }
public function test_working_dir_changes_with_command_and_terminate_events() { $oldCwd = getcwd(); $this->pathHelper->expects(static::once())->method('setProjectPath')->with($this->projectPath); $commandEvent = new ConsoleCommandEvent($this->command, $this->input, $this->output); $this->dispatcher->dispatch(ConsoleEvents::COMMAND, $commandEvent); static::assertEquals($this->projectPath, getcwd()); $terminateEvent = new ConsoleTerminateEvent($this->command, $this->input, $this->output, 0); $this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $terminateEvent); static::assertEquals($oldCwd, getcwd()); }
/** * @Route("/", name="homepage") */ public function indexAction() { // get class traits $productReflection = new \ReflectionClass(Product::class); dump($productReflection); dump($productReflection->getTraits()); $userEvent = new UserEvent(1234); $this->eventDispatcher->dispatch(AppEvents::ON_PAGE_SHOW, $userEvent); // replace this example code with whatever you need return $this->render('default/index.html.twig', ['base_dir' => realpath($this->getParameter('kernel.root_dir') . '/..')]); }
/** * @param \FSi\Bundle\AdminBundle\Event\FormEvent $event * @param \Symfony\Component\HttpFoundation\Request $request * @param \Symfony\Component\EventDispatcher\EventDispatcher $eventDispatcher * @param \Symfony\Component\Form\Form $form */ function it_return_response_from_request_post_submit_event($event, $request, $eventDispatcher, $form) { $request->isMethod('POST')->willReturn(true); $eventDispatcher->dispatch(BatchEvents::BATCH_REQUEST_PRE_SUBMIT, $event)->shouldBeCalled(); $event->getForm()->willReturn($form); $form->handleRequest($request)->shouldBeCalled(); $eventDispatcher->dispatch(BatchEvents::BATCH_REQUEST_POST_SUBMIT, $event)->will(function () use($event) { $event->hasResponse()->willReturn(true); $event->getResponse()->willReturn(new Response()); }); $this->handleRequest($event, $request)->shouldReturnAnInstanceOf('Symfony\\Component\\HttpFoundation\\Response'); }