public function serve(ConnectionInterface $conn, RequestInterface $request = null, array $parameters) { try { $path = $this->assets->get($parameters['asset'])->getFullPath(); if (!file_exists($path)) { throw new FileNotFoundException($path); } $response = new Response(200, array('Content-Type' => Mimetypes::getInstance()->fromFilename($path)), file_get_contents($path)); $conn->send((string) $response); $conn->close(); } catch (AssetNotFoundException $e) { $response = new Response(404, null, ''); $conn->send((string) $response); $conn->close(); } catch (FileNotFoundException $e) { $response = new Response(404, null, ''); $conn->send((string) $response); $conn->close(); } catch (\Exception $e) { $response = new Response(500, null, ''); $conn->send((string) $response); $conn->close(); } }
public function testRepository() { $repository = new AssetRepository(); $asset = new ExternalAsset('foo', 'bar.js'); $repository->add($asset); $this->assertSame($asset, $repository->get('global/bar.js')); $this->assertSame(array('global/bar.js' => $asset), $repository->getAll()); }