public function __construct(AspectKernel $kernel) { $this->kernel = $kernel; $this->options = $kernel->getOptions(); $this->cacheDir = $this->options['cacheDir']; $this->appDir = $this->options['appDir']; if ($this->cacheDir && file_exists($this->cacheDir . self::CACHE_FILE_NAME)) { $this->cacheState = (include $this->cacheDir . self::CACHE_FILE_NAME); } }
/** * Static configurator for filter * * @param AspectKernel $kernel Kernel to use for configuration * @param string $filterName Name of the filter to inject * @param CachePathManager $cacheManager Cache manager */ protected static function configure(AspectKernel $kernel, $filterName, CachePathManager $cacheManager) { if (self::$kernel) { throw new \RuntimeException("Filter injector can be configured only once."); } self::$kernel = $kernel; self::$options = $kernel->getOptions(); self::$filterName = $filterName; self::$cachePathManager = $cacheManager; }
/** * Warms up the cache. * * @param string $cacheDir The cache directory */ public function warmUp($cacheDir) { $options = $this->aspectKernel->getOptions(); $oldCacheDir = $this->cachePathManager->getCacheDir(); $this->cachePathManager->setCacheDir($cacheDir . '/aspect'); $enumerator = new Enumerator($options['appDir'], $options['includePaths'], $options['excludePaths']); $iterator = $enumerator->enumerate(); set_error_handler(function ($errno, $errstr, $errfile, $errline) { throw new \ErrorException($errstr, $errno, 0, $errfile, $errline); }); $errors = array(); foreach ($iterator as $file) { $realPath = $file->getRealPath(); try { // This will trigger creation of cache file_get_contents(FilterInjectorTransformer::PHP_FILTER_READ . SourceTransformingLoader::FILTER_IDENTIFIER . "/resource=" . $realPath); } catch (\Exception $e) { $errors[$realPath] = $e; } } restore_error_handler(); $this->cachePathManager->flushCacheState(); $this->cachePathManager->setCacheDir($oldCacheDir); }
public function __construct(AspectKernel $kernel) { $this->kernel = $kernel; $this->options = $kernel->getOptions(); $this->cacheDir = $this->options['cacheDir']; $this->appDir = $this->options['appDir']; if ($this->cacheDir) { if (!is_dir($this->cacheDir)) { $cacheRootDir = dirname($this->cacheDir); if (!is_writable($cacheRootDir) || !is_dir($cacheRootDir)) { throw new \InvalidArgumentException("Can not create a directory {$this->cacheDir} for the cache.\n Parent directory {$cacheRootDir} is not writable or not exist."); } mkdir($this->cacheDir, 0770); } if (!$this->kernel->hasFeature(Features::PREBUILT_CACHE) && !is_writable($this->cacheDir)) { throw new \InvalidArgumentException("Cache directory {$this->cacheDir} is not writable"); } if (file_exists($this->cacheDir . self::CACHE_FILE_NAME)) { $this->cacheState = (include $this->cacheDir . self::CACHE_FILE_NAME); } } }
/** * Default constructor for transformer * * @param AspectKernel $kernel Instance of aspect kernel * @param array $options Custom options or kernel options */ public function __construct(AspectKernel $kernel, array $options = []) { $this->kernel = $kernel; $this->container = $kernel->getContainer(); $this->options = $options ?: $kernel->getOptions(); }