/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln('Start up application with supplied config...'); $config = $input->getArgument('applicationConfig'); $path = stream_resolve_include_path($config); if (!is_readable($path)) { throw new \InvalidArgumentException("Invalid loader path: {$config}"); } // Init the application once using given config // This way the late static binding on the AspectKernel // will be on the goaop-zf2-module kernel \Zend\Mvc\Application::init(include $path); if (!class_exists(AspectKernel::class, false)) { $message = "Kernel was not initialized yet. Maybe missing module Go\\ZF2\\GoAopModule in config {$path}"; throw new \InvalidArgumentException($message); } $kernel = AspectKernel::getInstance(); $options = $kernel->getOptions(); if (empty($options['cacheDir'])) { throw new \InvalidArgumentException('Cache warmer require the `cacheDir` options to be configured'); } $enumerator = new Enumerator($options['appDir'], $options['includePaths'], $options['excludePaths']); $iterator = $enumerator->enumerate(); $totalFiles = iterator_count($iterator); $output->writeln("Total <info>{$totalFiles}</info> files to process."); $iterator->rewind(); set_error_handler(function ($errno, $errstr, $errfile, $errline) { throw new \ErrorException($errstr, $errno, 0, $errfile, $errline); }); $index = 0; $errors = []; foreach ($iterator as $file) { if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { $output->writeln("Processing file <info>{$file->getRealPath()}</info>"); } $isSuccess = null; try { // This will trigger creation of cache file_get_contents(FilterInjectorTransformer::PHP_FILTER_READ . SourceTransformingLoader::FILTER_IDENTIFIER . '/resource=' . $file->getRealPath()); $isSuccess = true; } catch (\Exception $e) { $isSuccess = false; $errors[$file->getRealPath()] = $e; } if ($output->getVerbosity() == OutputInterface::VERBOSITY_NORMAL) { $output->write($isSuccess ? '.' : '<error>E</error>'); if (++$index % 50 == 0) { $output->writeln("({$index}/{$totalFiles})"); } } } restore_error_handler(); if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) { foreach ($errors as $file => $error) { $message = "File {$file} is not processed correctly due to exception: {$error->getMessage()}"; $output->writeln($message); } } $output->writeln('<info>Done</info>'); }
private function showAdvisorInformation(SymfonyStyle $io, $advisorId) { $aspectContainer = $this->aspectKernel->getContainer(); /** @var AdviceMatcher $adviceMatcher */ $adviceMatcher = $aspectContainer->get('aspect.advice_matcher'); $this->loadAdvisorsList($aspectContainer); $advisor = $aspectContainer->getAdvisor($advisorId); $options = $this->aspectKernel->getOptions(); $enumerator = new Enumerator($options['appDir'], $options['includePaths'], $options['excludePaths']); $iterator = $enumerator->enumerate(); $totalFiles = iterator_count($iterator); $io->writeln("Total <info>{$totalFiles}</info> files to analyze."); $iterator->rewind(); foreach ($iterator as $file) { $reflectionFile = new ReflectionFile((string) $file); $reflectionNamespaces = $reflectionFile->getFileNamespaces(); foreach ($reflectionNamespaces as $reflectionNamespace) { foreach ($reflectionNamespace->getClasses() as $reflectionClass) { $advices = $adviceMatcher->getAdvicesForClass($reflectionClass, array($advisor)); if (!empty($advices)) { $this->writeInfoAboutAdvices($io, $reflectionClass, $advices); } } } } }
/** * {@inheritDoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln("Loading aspect kernel for warmup..."); $loader = $input->getArgument('loader'); $path = stream_resolve_include_path($loader); if (!is_readable($path)) { throw new \InvalidArgumentException("Invalid loader path: {$loader}"); } include_once $path; if (!class_exists('Go\\Core\\AspectKernel', false)) { $message = "Kernel was not initialized yet, please configure it in the {$path}"; throw new \InvalidArgumentException($message); } $kernel = AspectKernel::getInstance(); $options = $kernel->getOptions(); if (empty($options['cacheDir'])) { throw new \InvalidArgumentException("Cache warmer require the `cacheDir` options to be configured"); } $enumerator = new Enumerator($options['appDir'], $options['includePaths'], $options['excludePaths']); $iterator = $enumerator->enumerate(); $totalFiles = iterator_count($iterator); $output->writeln("Total <info>{$totalFiles}</info> files to process."); $iterator->rewind(); set_error_handler(function ($errno, $errstr, $errfile, $errline) { throw new \ErrorException($errstr, $errno, 0, $errfile, $errline); }); $index = 0; $errors = array(); foreach ($iterator as $file) { if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { $output->writeln("Processing file <info>{$file->getRealPath()}</info>"); } $isSuccess = null; try { // This will trigger creation of cache file_get_contents(FilterInjectorTransformer::PHP_FILTER_READ . SourceTransformingLoader::FILTER_IDENTIFIER . "/resource=" . $file->getRealPath()); $isSuccess = true; } catch (\Exception $e) { $isSuccess = false; $errors[$file->getRealPath()] = $e; } if ($output->getVerbosity() == OutputInterface::VERBOSITY_NORMAL) { $output->write($isSuccess ? '.' : '<error>E</error>'); if (++$index % 50 == 0) { $output->writeln("({$index}/{$totalFiles})"); } } } restore_error_handler(); if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) { foreach ($errors as $file => $error) { $message = "File {$file} is not processed correctly due to exception: {$error->getMessage()}"; $output->writeln($message); } } $output->writeln("<info>Done</info>"); }
/** * {@inheritDoc} */ protected function execute(InputInterface $input, OutputInterface $output) { parent::execute($input, $output); $options = $this->aspectKernel->getOptions(); if (empty($options['cacheDir'])) { throw new \InvalidArgumentException("Cache warmer require the `cacheDir` options to be configured"); } $enumerator = new Enumerator($options['appDir'], $options['includePaths'], $options['excludePaths']); $iterator = $enumerator->enumerate(); $totalFiles = iterator_count($iterator); $output->writeln("Total <info>{$totalFiles}</info> files to process."); $iterator->rewind(); set_error_handler(function ($errno, $errstr, $errfile, $errline) { throw new \ErrorException($errstr, $errno, 0, $errfile, $errline); }); $index = 0; $errors = []; foreach ($iterator as $file) { if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) { $output->writeln("Processing file <info>{$file->getRealPath()}</info>"); } $isSuccess = null; try { // This will trigger creation of cache file_get_contents(FilterInjectorTransformer::PHP_FILTER_READ . SourceTransformingLoader::FILTER_IDENTIFIER . "/resource=" . $file->getRealPath()); $isSuccess = true; } catch (\Exception $e) { $isSuccess = false; $errors[$file->getRealPath()] = $e; } if ($output->getVerbosity() == OutputInterface::VERBOSITY_NORMAL) { $output->write($isSuccess ? '.' : '<error>E</error>'); if (++$index % 50 == 0) { $output->writeln("({$index}/{$totalFiles})"); } } } restore_error_handler(); if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) { foreach ($errors as $file => $error) { $message = "File {$file} is not processed correctly due to exception: {$error->getMessage()}"; $output->writeln($message); } } $output->writeln("<info>Done</info>"); }
/** * 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); }
/** * {@inheritDoc} */ public function findFile($class) { static $isAllowedFilter = null, $isProduction = false; if (!$isAllowedFilter) { $isAllowedFilter = $this->fileEnumerator->getFilter(); $isProduction = !$this->options['debug']; } $file = $this->original->findFile($class); if ($file) { $cacheState = isset($this->cacheState[$file]) ? $this->cacheState[$file] : null; if ($cacheState && $isProduction) { $file = $cacheState['cacheUri'] ?: $file; } elseif ($isAllowedFilter(new \SplFileInfo($file))) { // can be optimized here with $cacheState even for debug mode, but no needed right now $file = FilterInjectorTransformer::rewrite($file); } } return $file; }