/** * 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); $rules = new SecurityPolicyRules(); if ($class = $this->findClass($path)) { $rules->addResource(new FileResource($path)); $rules->merge($this->loader->load($class, $type)); } return $rules; }
public function getPolicyRules() { if ($this->rules) { return $this->rules; } 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()) { $rules = new SecurityPolicyRules(); foreach ($this->options['bundles'] as $bundle) { $refl = new \ReflectionClass($bundle); $dir = dirname($refl->getFileName()) . '/Entity'; if (file_exists($dir) && is_dir($dir)) { $rules->merge($this->loader->load($dir)); } } $dumper = new $this->options['dumper_class'](); $cache->write($dumper->dump($rules), $rules->getResources()); } $this->rules = (include $cache); return $this->rules; }