/** * Executes the pre-compile command. * * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output * * @return int|null */ protected function execute(InputInterface $input, OutputInterface $output) { $this->validateCommand($input); $output->writeln('> Loading configuration file'); $config = $input->getOption('config'); $files = (new ConfigResolver())->getFileList($config); $output->writeLn('- Found ' . count($files) . ' files'); $preloader = new ClassPreloader(new PrettyPrinter(), new Parser(new Lexer()), $this->getTraverser($input)); $outputFile = $input->getOption('output'); $handle = $preloader->prepareOutput($outputFile); $output->writeln('> Compiling classes'); $count = 0; $countSkipped = 0; $comments = !$input->getOption('strip_comments'); foreach ($files as $file) { $count++; try { $code = $preloader->getCode($file, $comments); $output->writeln('- Writing ' . $file); fwrite($handle, $code . "\n"); } catch (SkipFileException $ex) { $countSkipped++; $output->writeln('- Skipping ' . $file); } } fclose($handle); $output->writeln("> Compiled loader written to {$outputFile}"); $output->writeln('- Files: ' . ($count - $countSkipped) . '/' . $count . ' (skipped: ' . $countSkipped . ')'); $output->writeln('- Filesize: ' . round(filesize($outputFile) / 1024) . ' kb'); }
/** * Generate the compiled class file. * * @return void */ protected function compileClasses() { $preloader = new ClassPreloader(new PrettyPrinter(), new Parser(new Lexer()), $this->getTraverser()); $handle = $preloader->prepareOutput($this->laravel->getCachedCompilePath()); foreach ($this->getClassFiles() as $file) { try { fwrite($handle, $preloader->getCode($file, false) . "\n"); } catch (SkipFileException $ex) { // } } fclose($handle); }
private function optimizeClassLoader() { $compiledPath = $this->basePath . '/storages/apps/compiled.php'; $preloader = new ClassPreloader(new PrettyPrinter(), new Parser(new Lexer()), $this->getTraverser()); $handle = $preloader->prepareOutput($compiledPath); foreach ($this->getClassFiles() as $file) { try { fwrite($handle, $preloader->getCode($file, false) . "\n"); } catch (SkipFileException $ex) { // } } fclose($handle); }