本文整理汇总了PHP中Zend\EventManager\EventManager::trigger方法的典型用法代码示例。如果您正苦于以下问题:PHP EventManager::trigger方法的具体用法?PHP EventManager::trigger怎么用?PHP EventManager::trigger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\EventManager\EventManager
的用法示例。
在下文中一共展示了EventManager::trigger方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: trigger
protected function trigger(EntityInterface $entity)
{
if (!$this->eventManager) {
return;
}
$this->eventManager->trigger('create:post', $this, compact('entity'));
}
示例2: trigger
/**
* {@inheritDoc}
*/
public function trigger(EventInterface $event)
{
if ($event instanceof ZendEventInterface) {
$this->eventManager->trigger($event);
}
return $this;
}
示例3: trigger
protected function trigger($event, $values, $nameForReturnValue)
{
if (!$this->eventManager) {
return;
}
$this->eventManager->trigger($event, $this, array($nameForReturnValue => $values));
}
示例4: send
public function send($to, $templateName, array $data = [])
{
$template = $this->templateBuilder->get($templateName);
$message = $this->mailAssembler->assemble($to, $template, $data);
$this->mailTransport->send($message);
$event = new Event('mail-send:post', $this, ['to' => $to, 'template' => $template, 'message' => $message, 'data' => $data]);
$this->eventManager->trigger($event);
}
示例5: trigger
/**
* @param EventInterface $event
* @param null|callable $callback
* @throws \Exception
*/
public function trigger($event, $callback = null)
{
try {
$this->manager->trigger($event, null, null, $callback);
} catch (\Exception $ex) {
$this->logger->error($ex);
throw $ex;
}
}
示例6: parse
/**
*
* @param ClassScanner[] $classes
*/
public function parse($classes)
{
$config = array();
foreach ($classes as $class) {
$classAnnotationHolder = $this->parseClass($class);
$event = new ParseEvent(ParseEvent::EVENT_CLASS_PARSED, $classAnnotationHolder, array('config' => $this->config));
$this->eventManager->trigger($event);
$config = ArrayUtils::merge($config, $event->getResult());
}
return $config;
}
示例7: inAction
public function inAction()
{
if (!$this->getRequest()->isPost()) {
// just show the login form
return array();
}
$username = $this->params()->fromPost('username');
$password = $this->params()->fromPost('password');
$auth = $this->serviceLocator->get('auth');
$authAdapter = $auth->getAdapter();
// below we pass the username and the password to the authentication adapter for verification
$authAdapter->setIdentity($username);
$authAdapter->setCredential($password);
// here we do the actual verification
$result = $auth->authenticate();
$isValid = $result->isValid();
if ($isValid) {
// upon successful validation the getIdentity method returns
// the user entity for the provided credentials
$user = $result->getIdentity();
// @todo: upon successful validation store additional information about him in the auth storage
$this->flashmessenger()->addSuccessMessage(sprintf('Welcome %s. You are now logged in.', $user->getName()));
return $this->redirect()->toRoute('user/default', array('controller' => 'account', 'action' => 'me'));
} else {
$event = new EventManager('user');
$event->trigger('log-fail', $this, array('username' => $username));
return array('errors' => $result->getMessages());
}
}
示例8: addAction
public function addAction()
{
// The annotation builder help us create a form from the annotations in the user entity.
$builder = new AnnotationBuilder();
$entity = $this->serviceLocator->get('user-entity');
$form = $builder->createForm($entity);
$form->add(array('name' => 'password_verify', 'type' => 'Zend\\Form\\Element\\Password', 'attributes' => array('placeholder' => 'Verify Password Here...', 'required' => 'required'), 'options' => array('label' => 'Verify Password')), array('priority' => $form->get('password')->getOption('priority')));
// This is the special code that protects our form being submitted from automated scripts
$form->add(array('name' => 'csrf', 'type' => 'Zend\\Form\\Element\\Csrf'));
// This is the submit button
$form->add(array('name' => 'submit', 'type' => 'Zend\\Form\\Element\\Submit', 'attributes' => array('value' => 'Submit', 'required' => 'false')));
// We bind the entity to the user. If the form tries to read/write data from/to the entity
// it will use the hydrator specified in the entity to achieve this. In our case we use ClassMethods
// hydrator which means that reading will happen calling the getter methods and writing will happen by
// calling the setter methods.
$form->bind($entity);
if ($this->getRequest()->isPost()) {
$data = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray());
$form->setData($data);
if ($form->isValid()) {
// We use now the Doctrine 2 entity manager to save user data to the database
$entityManager = $this->serviceLocator->get('entity-manager');
$entityManager->persist($entity);
$entityManager->flush();
$this->flashmessenger()->addSuccessMessage('User was added successfully.');
$event = new EventManager('user');
$event->trigger('register', $this, array('user' => $entity));
// redirect the user to the view user action
return $this->redirect()->toRoute('user/default', array('controller' => 'account', 'action' => 'view', 'id' => $entity->getId()));
}
}
// pass the data to the view for visualization
return array('form1' => $form);
}
示例9: testOnFailure
/**
* 测试AuthLoggerListener::onFailure()
*/
public function testOnFailure()
{
$e = new Event();
$e->setFailure(new Failure('Test', array('result' => '123456')));
$this->events->trigger(Event::EVENT_FAILURE, $e);
$this->assertStringMatchesFormat('%s WARN (4): Test {"result":"123456"}%w', file_get_contents($this->destfile));
}
示例10: it_should_handle_valid_data
/**
* @param \Phpro\SmartCrud\Gateway\CrudGatewayInterface $gateway
* @param \Zend\EventManager\EventManager $eventManager
* @param \Zend\Form\Form $form
* @param \Phpro\SmartCrud\Service\SmartServiceResult $result
*/
public function it_should_handle_valid_data($gateway, $eventManager, $form, $result)
{
$entity = new \StdClass();
$postData = $this->getMockPostData();
$gateway->loadEntity('entityKey', null)->shouldBecalled()->willReturn($entity);
$gateway->delete($entity, $postData)->shouldBecalled()->willReturn(true);
$result->setSuccess(true)->shouldBeCalled();
$result->setEntity($entity)->shouldBeCalled();
$this->setEntityKey('entityKey');
$this->setGateway($gateway);
$this->setResult($result);
$this->setForm($form);
$this->run(null, $this->getMockPostData())->shouldReturn($result);
$eventManager->trigger(Argument::which('getName', CrudEvent::INVALID_DELETE))->shouldNotBeCalled();
$eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_DELETE))->shouldBeCalled();
$eventManager->trigger(Argument::which('getName', CrudEvent::AFTER_DELETE))->shouldBeCalled();
}
示例11: it_should_return_a_result
/**
* @param \Phpro\SmartCrud\Gateway\CrudGatewayInterface $gateway
* @param \Zend\EventManager\EventManager $eventManager
* @param \Phpro\SmartCrud\Service\SmartServiceResult $result
*/
public function it_should_return_a_result($gateway, $eventManager, $result)
{
$entity = new \StdClass();
$entity->id = 1;
$postData = null;
$gateway->loadEntity('entityKey', $entity->id)->shouldBecalled()->willReturn($entity);
$result->setSuccess(Argument::any())->shouldBeCalled();
$result->setForm(Argument::any())->shouldNotBeCalled();
$result->setEntity($entity)->shouldBeCalled();
$this->setEntityKey('entityKey');
$this->setGateway($gateway);
$this->setResult($result);
$this->run($entity->id, $postData)->shouldReturn($result);
$eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_DATA_VALIDATION))->shouldNotBeCalled();
$eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_READ))->shouldBeCalled();
$eventManager->trigger(Argument::which('getName', CrudEvent::AFTER_READ))->shouldBeCalled();
}
示例12: it_should_trigger_events_during_form_configuration
/**
* @param \Zend\EventManager\EventManager $eventManager
* @param \Zend\Form\FormInterface $form
* @param \ArrayAccess $spec
*/
public function it_should_trigger_events_during_form_configuration($eventManager, $form, $spec)
{
$this->configureForm($form, $spec);
$triggeredEvents = array(FormEvent::EVENT_CONFIGURE_ELEMENT_PRE, FormEvent::EVENT_CONFIGURE_ELEMENT_POST);
$eventManager->trigger(Argument::that(function ($event) use($form, $spec, $triggeredEvents) {
return $event instanceof FormEvent && in_array($event->getName(), $triggeredEvents) && $event->getTarget() == $form->getWrappedObject() && $event->getParam('spec') == $spec->getWrappedObject();
}))->shouldBeCalledTimes(count($triggeredEvents));
}
示例13: it_should_trigger_events_while_creating_form
/**
* @param \Zend\EventManager\EventManager $eventManager
*/
public function it_should_trigger_events_while_creating_form($eventManager)
{
$this->mockConfiguration();
$this->createForm('stdClass');
$eventManager->trigger(Argument::that(function ($event) {
$validEvents = array(FormEvent::EVENT_FORM_CREATE_PRE, FormEvent::EVENT_FORM_CREATE_POST);
return $event instanceof FormEvent && in_array($event->getName(), $validEvents);
}))->shouldBeCalledTimes(2);
}
示例14: testFirewallOn
/**
* Test if firewall is on
*/
public function testFirewallOn()
{
self::setUpFirewallOn();
$spyListener = new SpyingFirewallListener();
$spyListener->setServiceLocator($this->getServiceManager());
$eventManager = new EventManager();
$eventManager->attach($spyListener);
$eventManager->trigger(FirewallEvent::EVENT_FIREWALL_DISPATCH);
$this->assertTrue($spyListener->isFirewallEnabled());
}
示例15: triggerEvent
/**
* Trigger an event
*
* @param string $event Event name
* @param array|\ArrayAccess $argv Array of arguments; typically, should be associative
*/
protected function triggerEvent($event, $argv = [])
{
if (null === $this->events) {
if (class_exists('\\Zend\\EventManager\\EventManager')) {
$this->events = new EventManager(__CLASS__);
} else {
return;
}
}
$this->events->trigger($event, $this, $argv);
}