本文整理汇总了PHP中Cake\Event\Event::name方法的典型用法代码示例。如果您正苦于以下问题:PHP Event::name方法的具体用法?PHP Event::name怎么用?PHP Event::name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Event\Event
的用法示例。
在下文中一共展示了Event::name方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: authCheck
public function authCheck(Event $event)
{
if (isset($this->earlyAuthTest)) {
if ($this->_config['checkAuthIn'] !== $event->name()) {
return;
}
$this->authCheckCalledFrom = $event->name();
return;
}
return parent::authCheck($event);
}
示例2: afterRules
public function afterRules(Cake\Event\Event $event, Cat $entity, \ArrayObject $options, $result, $operation)
{
Log::write("debug", "afterRules");
Log::write("debug", $event->name());
Log::write("debug", "entity " . $entity);
Log::write("debug", $options);
Log::write("debug", "result " . $result);
Log::write("debug", "operation " . $operation);
}
示例3: handleEvent
/**
* There is only one event handler, it can be configured to be called for any event
*
* @param \Cake\Event\Event $event Event instance.
* @param \Cake\Datasource\EntityInterface $entity Entity instance.
* @throws \UnexpectedValueException if a field's when value is misdefined
* @return true (irrespective of the behavior logic, the save will not be prevented)
* @throws \UnexpectedValueException When the value for an event is not 'always', 'new' or 'existing'
*/
public function handleEvent(Event $event, EntityInterface $entity)
{
$eventName = $event->name();
$events = $this->_config['events'];
if ($events[$eventName] === true) {
$this->_purify($entity);
}
return true;
}
示例4: footprint
/**
* Try and attach footprint listener to models.
*
* It also passing the user record to footprint listener after user is
* identified by AuthComponent.
*
* @param \Cake\Event\Event $event Event.
* @return void
*/
public function footprint(Event $event)
{
if (!$this->_listener) {
$this->_listener = new FootprintListener($this->_getCurrentUser());
}
if ($event->name() === 'Auth.afterIdentify') {
$this->_listener->setUser($this->_getCurrentUser($event->data));
return;
}
$event->subject()->eventManager()->attach($this->_listener);
}
示例5: handleEvent
/**
* There is only one event handler, it can be configured to be called for any event
*
* @param \Cake\Event\Event $event Event instance.
* @param \Cake\ORM\Entity $entity Entity instance.
* @throws \UnexpectedValueException if a field's when value is misdefined
* @return true (irrespective of the behavior logic, the save will not be prevented)
* @throws \UnexpectedValueException When the value for an event is not 'always', 'new' or 'existing'
*/
public function handleEvent(Event $event, Entity $entity)
{
$eventName = $event->name();
$events = $this->config('events');
$new = $entity->isNew() !== false;
foreach ($events[$eventName] as $field => $when) {
if (!in_array($when, ['always', 'new', 'existing'])) {
throw new \UnexpectedValueException(sprintf('When should be one of "always", "new" or "existing". The passed value "%s" is invalid', $when));
}
if ($when === 'always' || $when === 'new' && $new || $when === 'existing' && !$new) {
$this->_updateField($entity, $field);
}
}
return true;
}
示例6: beforeSave
/**
* Injects configured field values into entity if those fields are not dirty.
*
* @param \Cake\Event\Event $event Event.
* @param \Cake\ORM\Entity $entity Entity.
* @param \ArrayObject $options Options.
* @return void
*/
public function beforeSave(Event $event, Entity $entity, ArrayObject $options)
{
$eventName = $event->name();
$events = $this->config('events');
$new = $entity->isNew() !== false;
foreach ($events[$eventName] as $field => $when) {
if (!in_array($when, ['always', 'new', 'existing'])) {
throw new UnexpectedValueException(sprintf('When should be one of "always", "new" or "existing". The passed value "%s" is invalid', $when));
}
if ($entity->dirty($field)) {
continue;
}
if ($when === 'always' || $when === 'new' && $new || $when === 'existing' && !$new) {
$entity->set($field, current(Hash::extract((array) $options, $this->config('propertiesMap.' . $field))));
}
}
}
示例7: onView
/**
* @param Event $event
* @return string
*/
public function onView(Event $event)
{
return $event->name();
}
示例8: authCheck
/**
* Main execution method, handles initial authentication check and redirection
* of invalid users.
*
* The auth check is done when event name is same as the one configured in
* `checkAuthIn` config.
*
* @param \Cake\Event\Event $event Event instance.
* @return \Cake\Network\Response|null
*/
public function authCheck(Event $event)
{
if ($this->_config['checkAuthIn'] !== $event->name()) {
return null;
}
$controller = $event->subject();
$action = strtolower($controller->request->params['action']);
if (!$controller->isAction($action)) {
return null;
}
$this->_setDefaults();
if ($this->_isAllowed($controller)) {
return null;
}
$isLoginAction = $this->_isLoginAction($controller);
if (!$this->_getUser()) {
if ($isLoginAction) {
return null;
}
$result = $this->_unauthenticated($controller);
if ($result instanceof Response) {
$event->stopPropagation();
}
return $result;
}
if ($isLoginAction || empty($this->_config['authorize']) || $this->isAuthorized($this->user())) {
return null;
}
$event->stopPropagation();
return $this->_unauthorized($controller);
}
示例9: dispatch
/**
* Dispatches a new event to all configured listeners
*
* @param string|\Cake\Event\Event $event the event key name or instance of Event
* @return \Cake\Event\Event
* @triggers $event
*/
public function dispatch($event)
{
if (is_string($event)) {
$event = new Event($event);
}
$listeners = $this->listeners($event->name());
if (empty($listeners)) {
return $event;
}
foreach ($listeners as $listener) {
if ($event->isStopped()) {
break;
}
$result = $this->_callListener($listener['callable'], $event);
if ($result === false) {
$event->stopPropagation();
}
if ($result !== null) {
$event->result = $result;
}
}
return $event;
}
示例10: handle
/**
* Handler method that applies conditions and resolves the correct method to call.
*
* @param \Cake\Event\Event $event The event instance.
* @return mixed
*/
public function handle(Event $event)
{
$name = $event->name();
list(, $method) = explode('.', $name);
if (empty($this->_config['for']) && empty($this->_config['when'])) {
return $this->{$method}($event);
}
if ($this->matches($event)) {
return $this->{$method}($event);
}
}
示例11: dispatch
/**
* Dispatches a new event to all configured listeners
*
* @param string|\Cake\Event\Event $event the event key name or instance of Event
* @return \Cake\Event\Event
* @triggers $event
*/
public function dispatch($event)
{
if (is_string($event)) {
$event = new Event($event);
}
$listeners = $this->listeners($event->name());
if ($this->_trackEvents) {
$this->addEventToList($event);
}
if (!$this->_isGlobal && static::instance()->isTrackingEvents()) {
static::instance()->addEventToList($event);
}
if (empty($listeners)) {
return $event;
}
foreach ($listeners as $listener) {
if ($event->isStopped()) {
break;
}
$result = $this->_callListener($listener['callable'], $event);
if ($result === false) {
$event->stopPropagation();
}
if ($result !== null) {
$event->result = $result;
}
}
return $event;
}
示例12: testName
/**
* Tests the name() method
*
* @return void
* @triggers fake.event
*/
public function testName()
{
$event = new Event('fake.event');
$this->assertEquals('fake.event', $event->name());
}
示例13: filterTest
/**
* Helper function to test single method attaching for dispatcher filters
*
* @param \Cake\Event\Event $event
* @return void
*/
public function filterTest($event)
{
$event->data['request']->params['eventName'] = $event->name();
}