original_string: protected function _attachListeners($plugin, $path)
      {
          $path = normalizePath("{$path}/");
          $eventsPath = normalizePath("{$path}/src/Event/");
  
          if (is_readable($eventsPath) && is_dir($eventsPath)) {
              $EventManager = EventManager::instance();
              $eventsFolder = new Folder($eventsPath);
              Plugin::load($plugin, [
                  'autoload' => true,
                  'bootstrap' => false,
                  'routes' => false,
                  'path' => $path,
                  'classBase' => 'src',
                  'ignoreMissing' => true,
              ]);
  
              foreach ($eventsFolder->read(false, false, true)[1] as $classPath) {
                  $className = preg_replace('/\.php$/i', '', basename($classPath));
                  $fullClassName = implode('\\', [$plugin, 'Event', $className]);
  
                  if (class_exists($fullClassName)) {
                      $handler = new $fullClassName;
                      $this->_listeners[] = $handler;
                      $EventManager->on($handler);
                  }
              }
          }
      }
code: protected function _attachListeners($plugin, $path)
      {
          $path = normalizePath("{$path}/");
          $eventsPath = normalizePath("{$path}/src/Event/");
  
          if (is_readable($eventsPath) && is_dir($eventsPath)) {
              $EventManager = EventManager::instance();
              $eventsFolder = new Folder($eventsPath);
              Plugin::load($plugin, [
                  'autoload' => true,
                  'bootstrap' => false,
                  'routes' => false,
                  'path' => $path,
                  'classBase' => 'src',
                  'ignoreMissing' => true,
              ]);
  
              foreach ($eventsFolder->read(false, false, true)[1] as $classPath) {
                  $className = preg_replace('/\.php$/i', '', basename($classPath));
                  $fullClassName = implode('\\', [$plugin, 'Event', $className]);
  
                  if (class_exists($fullClassName)) {
                      $handler = new $fullClassName;
                      $this->_listeners[] = $handler;
                      $EventManager->on($handler);
                  }
              }
          }
      }
code_tokens: protected function _attachListeners ( $ plugin , $ path ) { $ path = normalizePath ( "{$path}/" ) ; $ eventsPath = normalizePath ( "{$path}/src/Event/" ) ; if ( is_readable ( $ eventsPath ) && is_dir ( $ eventsPath ) ) { $ EventManager = EventManager :: instance ( ) ; $ eventsFolder = new Folder ( $ eventsPath ) ; Plugin :: load ( $ plugin , [ 'autoload' => true , 'bootstrap' => false , 'routes' => false , 'path' => $ path , 'classBase' => 'src' , 'ignoreMissing' => true , ] ) ; foreach ( $ eventsFolder -> read ( false , false , true ) [ 1 ] as $ classPath ) { $ className = preg_replace ( '/\.php$/i' , '' , basename ( $ classPath ) ) ; $ fullClassName = implode ( '\\' , [ $ plugin , 'Event' , $ className ] ) ; if ( class_exists ( $ fullClassName ) ) { $ handler = new $ fullClassName ; $ this -> _listeners [ ] = $ handler ; $ EventManager -> on ( $ handler ) ; } } } }
docstring: Loads and registers plugin's namespace and loads its event listeners classes.
  
  This is used to allow plugins being installed to respond to events before
  they are integrated to the system. Events such as `beforeInstall`,
  `afterInstall`, etc.
  
  @param string $plugin Name of the plugin for which attach listeners
  @param string $path Path to plugin's root directory (which contains "src")
  @throws \Cake\Error\FatalErrorException On illegal usage of this method
docstring_tokens: Loads and registers plugin s namespace and loads its event listeners classes .