Example #1
0
 function setup()
 {
     $env = new Environment();
     $env->appendPath(__DIR__ . '/fixtures');
     $this->ctx = new Context($env);
     $this->ctx->path = __DIR__ . '/fixtures';
 }
Example #2
0
File: Server.php Project: chh/pipe
 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;
 }
Example #3
0
 /**
  * @dataProvider dataProvider
  */
 function test($file, $output)
 {
     $env = new Environment();
     $env->appendPath(__DIR__ . "/fixtures/import_processor");
     $p = new ImportProcessor(__DIR__ . "/fixtures/import_processor/{$file}");
     $ctx = new Context($env);
     $this->assertEquals($output, $p->render($ctx));
 }
Example #4
0
File: Config.php Project: chh/pipe
 function createEnvironment()
 {
     $env = new Environment();
     $loadPaths = $this->loadPaths ?: array();
     foreach ($loadPaths as $path) {
         $env->appendPath(dirname($this->filename) . "/" . $path);
     }
     if (!$this->debug) {
         if ($jsCompressor = $this->jsCompressor) {
             $env->setJsCompressor($jsCompressor);
         }
         if ($cssCompressor = $this->cssCompressor) {
             $env->setCssCompressor($cssCompressor);
         }
     }
     return $env;
 }
Example #5
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'));
 }
Example #6
0
 function setUp()
 {
     $env = new Environment();
     $env->appendPath(__DIR__ . "/fixtures");
     $this->environment = $env;
 }
Example #7
0
 function register(Application $app)
 {
     $app->register(new \Silex\Provider\UrlGeneratorServiceProvider());
     $app['pipe.use_precompiled_gzip'] = true;
     if (isset($app['caches'])) {
         $app['caches'] = $app->share($app->extend('caches', function ($caches) use($app) {
             $caches['pipe'] = $app->share($app['cache.namespace']('pipe', $caches['default']));
             return $caches;
         }));
     }
     $app['pipe.precompile'] = function () {
         return array('application.js', 'application.css');
     };
     $app['pipe.load_path'] = $app->share(function () use($app) {
         if (isset($app['pipe.root'])) {
             $root = $app['pipe.root'];
             return array("{$root}/images", "{$root}/javascripts", "{$root}/vendor/javascripts", "{$root}/stylesheets", "{$root}/vendor/stylesheets");
         }
         return array();
     });
     $app["pipe.manifest"] = $app->share(function () use($app) {
         if (isset($app['pipe.precompile_directory'])) {
             return $app['pipe.precompile_directory'] . "/manifest.json";
         }
         return "manifest.json";
     });
     $app["pipe"] = $app->share(function ($app) {
         return new PipeService($app);
     });
     $app['pipe.environment'] = $app->share(function () use($app) {
         $environment = new Environment();
         if (!$app['pipe.debug']) {
             if (isset($app['pipe.css_compressor'])) {
                 $environment->setCssCompressor($app['pipe.css_compressor']);
             }
             if (isset($app['pipe.js_compressor'])) {
                 $environment->setJsCompressor($app['pipe.js_compressor']);
             }
         }
         foreach ($app["pipe.load_path"] as $path) {
             $environment->appendPath($path);
         }
         return $environment;
     });
     if (isset($app["twig"])) {
         $app['twig'] = $app->share($app->extend('twig', function ($twig) {
             $twig->addExtension(new PipeTwigExtension());
             return $twig;
         }));
     }
     $app->get("/_pipe/asset/{logicalPath}", function ($logicalPath) use($app) {
         $asset = $app["pipe.environment"]->find($logicalPath, array('bundled' => true));
         if (!$asset) {
             return $app->abort(404, "Asset '{$logicalPath}' not found");
         }
         $lastModified = new \DateTime();
         $lastModified->setTimestamp($asset->getLastModified());
         $res = new Response();
         $res->setPublic();
         $res->setLastModified($lastModified);
         if ($res->isNotModified($app['request'])) {
             return $res;
         }
         $time = microtime(true);
         $res->headers->set("Content-Type", $asset->getContentType());
         $res->headers->set("Content-Length", strlen($asset->getBody()));
         $res->setContent($asset->getBody());
         if (isset($app["monolog"]) and $app["monolog"] !== null) {
             $d = microtime(true) - $time;
             $app["monolog"]->addInfo(sprintf('pipe: Generated "%s" in %f seconds', $logicalPath, $d), array('time' => $d, 'path' => $logicalPath, 'realpath' => $asset->path));
         }
         return $res;
     })->assert("logicalPath", ".+")->bind(self::ROUTE_ASSET);
 }
Example #8
0
 function setUp()
 {
     $env = new Environment();
     $env->appendPath(__DIR__ . "/fixtures/directive_processor");
     $this->server = new Server($env);
 }