本文整理汇总了PHP中Symfony\Component\EventDispatcher\EventDispatcher::dispatch方法的典型用法代码示例。如果您正苦于以下问题:PHP EventDispatcher::dispatch方法的具体用法?PHP EventDispatcher::dispatch怎么用?PHP EventDispatcher::dispatch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\EventDispatcher\EventDispatcher
的用法示例。
在下文中一共展示了EventDispatcher::dispatch方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: write
/**
* @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');
}
}
示例2: checkAndProxyEvent
public function checkAndProxyEvent(CrawlerRequestEvent $event, $name)
{
$uri = $event->getRequest()->getUri();
if ($this->matcher->matches($uri)) {
$this->dispatcher->dispatch($name, $event);
}
}
示例3: execute
/**
* {@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));
}
示例4: commit
/**
* {@inheritdoc}
*/
public function commit()
{
while (!$this->messages->isEmpty()) {
$message = $this->messages->dequeue();
$this->eventDispatcher->dispatch($message->getName(), new GenericEvent($message));
}
}
示例5: build
/**
* 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;
}
示例6: fire
protected function fire($event, Event $eventType)
{
foreach ($this->scenario->getGroups() as $group) {
$this->dispatcher->dispatch($event . '.' . $group, $eventType);
}
$this->dispatcher->dispatch($event, $eventType);
}
示例7: dispatchEvent
/**
* Dispatch event.
*
* @param string $name
* @param Event $event
*/
private function dispatchEvent($name, Event $event)
{
if (null === $this->eventDispatcher) {
return;
}
$this->eventDispatcher->dispatch($name, $event);
}
示例8: createPrimaryMenu
/**
* 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;
}
示例9: onCommitDone
public function onCommitDone()
{
$this->eventDispatcher->dispatch('commitDone', new CommitDoneEvent());
foreach ($this->onCommitDoneCallbacks as $callback) {
call_user_func($callback);
}
}
示例10: request
/**
* @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());
}
示例11: handleResponse
public function handleResponse(ApiResponse $response)
{
if (null != $this->eventDispatcher) {
$event = new ApiResponseEvent($response);
$this->eventDispatcher->dispatch(ApiEvent::API_RESPONSE, $event);
}
return $response;
}
示例12: buildForm
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);
}
示例13: resolveCiActions
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();
}
示例14: testChangePermissionsForCommittedSqon
/**
* 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.');
}
示例15: setCacheForEntity
/**
* 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));
}
}