Ejemplo n.º 1
0
 public function request($path)
 {
     $ext = strtolower(substr($path, strrpos($path, '.')));
     if (!isset($this->mime_types[$ext])) {
         return $this->notFound();
     }
     try {
         $asset = $this->manager->loader()->fromWebPath($path);
     } catch (Exceptions\FileNotFoundException $e) {
         // file not found => 404
         return $this->notfound();
     }
     if ($path !== $asset->getTargetPath()) {
         // file found but bad url => redirect
         return $this->redirectTo($asset->getTargetPath());
     }
     $this->send($this->mime_types[$ext], $asset->dump());
 }
Ejemplo n.º 2
0
 private function twigExtractAssetMethods($file)
 {
     $output = $this->output;
     preg_replace_callback('/aphet_[url|script|link]*\\((.*)\\)/', function ($match) use($output) {
         $match = str_replace("'", '"', $match[1]);
         $name = null;
         if (substr($match, 0, 1) === '[' && substr($match, -1) !== ']') {
             $split = explode(']', $match);
             $match = $split[0] . ']';
             $split = explode(',', $split[1]);
             $name = json_decode(str_replace("'", '"', $split[1]));
         }
         $urls = json_decode($match);
         $output->writeln("<info>compile: {$match} </info>");
         $start = microtime(true);
         $urls = $this->assetManager->computeAssetsUrl($urls, $name);
         $output->writeln((microtime(true) - $start) * 1000 . ' ms');
         $stringify = json_encode($urls);
         $output->writeln("  ===> {$stringify}");
     }, file_get_contents($file));
 }