find() публичный Метод

Example: find('application.js', ['bundled' => true]);
public find ( string $logicalPath, array $options = [] ) : Asset
$logicalPath string Path relative to the load path.
$options array
Результат Asset
Пример #1
0
 function handle(HttpFoundation\Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
 {
     $path = ltrim($request->getPathInfo(), '/');
     $asset = $this->environment->find($path, array("bundled" => true));
     $debug = $request->query->get("debug", false);
     $cache = !$request->query->get("nocache", false);
     if (!$asset or $path == '') {
         return $this->renderNotFound($request);
     }
     if ($debug) {
         $this->environment->bundleProcessors->clear();
     }
     $lastModified = new \DateTime();
     $lastModified->setTimestamp($asset->getLastModified());
     $response = new HttpFoundation\Response();
     $response->setPublic();
     $response->setLastModified($lastModified);
     if ($cache and $response->isNotModified($request)) {
         return $response;
     }
     $response->setContent($asset->getBody());
     $response->headers->set('Content-Type', $asset->getContentType());
     $response->prepare($request);
     return $response;
 }
Пример #2
0
 function testManifestDumpsAssets()
 {
     $dir = vfsStream::setup('assets');
     $env = new Environment();
     $env->appendPath(__DIR__ . '/fixtures');
     $asset = $env->find('asset1.js', array('bundled' => true));
     $digestName = $asset->getDigestName();
     $logger = new Logger('pipe');
     $logger->pushHandler(new TestHandler());
     $manifest = new Manifest($env, vfsStream::url('assets') . '/manifest.json');
     $manifest->setLogger($logger);
     $manifest->compress = true;
     $manifest->compile('asset1.js');
     $json = json_decode($manifest->toJSON(), true);
     $this->assertEquals($digestName, $json["assets"]["asset1.js"]);
     $fileInfo = $json['files'][$digestName];
     $this->assertArrayHasKey('size', $fileInfo);
     $this->assertArrayHasKey('logical_path', $fileInfo);
     $this->assertArrayHasKey('content_type', $fileInfo);
     $this->assertArrayHasKey('digest', $fileInfo);
     $this->assertTrue($dir->hasChild('manifest.json'));
     $this->assertTrue($dir->hasChild($digestName));
     $this->assertTrue($dir->hasChild($digestName . '.gz'));
 }