original_string: protected function _detachSubscriber(EventListenerInterface $subscriber, $eventKey = null)
      {
          $events = (array)$subscriber->implementedEvents();
          if (!empty($eventKey) && empty($events[$eventKey])) {
              return;
          }
          if (!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]);
          }
      }
code: protected function _detachSubscriber(EventListenerInterface $subscriber, $eventKey = null)
      {
          $events = (array)$subscriber->implementedEvents();
          if (!empty($eventKey) && empty($events[$eventKey])) {
              return;
          }
          if (!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]);
          }
      }
code_tokens: protected function _detachSubscriber ( EventListenerInterface $ subscriber , $ eventKey = null ) { $ events = ( array ) $ subscriber -> implementedEvents ( ) ; if ( ! empty ( $ eventKey ) && empty ( $ events [ $ eventKey ] ) ) { return ; } if ( ! 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 ] ) ; } }
docstring: 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
docstring_tokens: Auxiliary function to help detach all listeners provided by an object implementing EventListenerInterface