/**
  * Loads from annotations from a directory.
  *
  * @param string $path A directory path
  * @param string $type The resource type
  *
  * @return EventsMap A event map
  *
  * @throws \InvalidArgumentException When annotations can't be parsed
  */
 public function load($path, $type = null)
 {
     $dir = $this->locator->locate($path);
     $map = new EventsMap();
     $map->addResource(new DirectoryResource($dir, '/Event\\.php$/'));
     $files = iterator_to_array(new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir), \RecursiveIteratorIterator::LEAVES_ONLY));
     usort($files, function (\SplFileInfo $a, \SplFileInfo $b) {
         return (string) $a > (string) $b ? 1 : -1;
     });
     foreach ($files as $file) {
         if (!$file->isFile() || 'Event.php' !== substr($file->getFilename(), -9)) {
             continue;
         }
         if ($class = $this->findClass($file)) {
             $refl = new \ReflectionClass($class);
             if ($refl->isAbstract()) {
                 continue;
             }
             if (!$refl->getParentClass() || $refl->getParentClass()->getName() != 'Symfony\\Component\\EventDispatcher\\Event') {
                 continue;
             }
             $map->merge($this->loader->load($class, $type));
         }
     }
     return $map;
 }
 /**
  * Loads from annotations from a file.
  *
  * @param string $file A PHP file path
  * @param string $type The resource type
  *
  * @return SecurityPolicyRules A Rules instance
  *
  * @throws \InvalidArgumentException When annotations can't be parsed
  */
 public function load($file, $type = null)
 {
     $path = $this->locator->locate($file);
     $map = new EventsMap();
     if ($class = $this->findClass($path)) {
         $map->addResource(new FileResource($path));
         $map->merge($this->loader->load($class, $type));
     }
     return $map;
 }
 private function loadMap()
 {
     if (null === $this->options['cache_dir'] || null === $this->options['cache_filename']) {
         throw new \RuntimeException('Options "cache_dir" and "cache_filename" must be defined.');
     }
     $cache = new ConfigCache($this->options['cache_dir'] . '/' . $this->options['cache_filename'] . '.php', $this->options['debug']);
     if (!$cache->isFresh()) {
         $map = new EventsMap();
         foreach ($this->options['bundles'] as $bundle) {
             $refl = new \ReflectionClass($bundle);
             $dir = dirname($refl->getFileName());
             if (file_exists($dir) && is_dir($dir)) {
                 $map->merge($this->loader->load($dir));
             }
         }
         $dumper = new $this->options['dumper_class']();
         $cache->write($dumper->dump($map), $map->getResources());
     }
     $this->map = (include $cache);
 }