Exemplo n.º 1
0
 /**
  * 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);
 }
Exemplo n.º 2
0
 /**
  * Auxiliary function to help detach all listeners provided by an object implementing EventListenerInterface
  *
  * @param \Cake\Event\EventListenerInterface $subscriber the subscriber to be detached
  * @param string|null $eventKey optional event key name to unsubscribe the listener from
  * @return void
  */
 protected function _detachSubscriber(EventListenerInterface $subscriber, $eventKey = null)
 {
     $events = (array) $subscriber->implementedEvents();
     if (!empty($eventKey) && empty($events[$eventKey])) {
         return;
     } elseif (!empty($eventKey)) {
         $events = [$eventKey => $events[$eventKey]];
     }
     foreach ($events as $key => $function) {
         if (is_array($function)) {
             if (is_numeric(key($function))) {
                 foreach ($function as $handler) {
                     $handler = isset($handler['callable']) ? $handler['callable'] : $handler;
                     $this->off($key, [$subscriber, $handler]);
                 }
                 continue;
             }
             $function = $function['callable'];
         }
         $this->off($key, [$subscriber, $function]);
     }
 }