Ejemplo n.º 1
0
 public function execute($request)
 {
     $file = null;
     foreach ($this->getContext()->getRouting()->getRoutes() as $route) {
         $route_info = $route->getDefaults();
         if ($request->getParameter('namespace') == strtolower($route_info['module'] . $route_info['action'])) {
             $combiner = new combineFiles();
             $file = $combiner->getFileName($request->getParameter('type'), strtolower($route_info['module'] . $route_info['action']));
         }
     }
     $this->content = null;
     if (is_readable($file)) {
         $this->content = file_get_contents($file);
     } else {
         $this->content = sprintf('Couldn\'t read file %s', $file);
     }
     sfConfig::set('sf_web_debug', false);
     $this->getResponse()->setHttpHeader('Content-Type', $request->getParameter('type') === 'css' ? 'text/css' : 'text/javascript');
     $this->getResponse()->setHttpHeader('Cache-Control', 'max-age=86040000, public, must-revalidate');
     $this->setTemplate('output');
     $this->setLayout(false);
 }
Ejemplo n.º 2
0
<?php

include dirname(__FILE__) . '/../bootstrap/unit.php';
include dirname(__FILE__) . '/../../apps/client/lib/combineFiles.class.php';
include dirname(__FILE__) . '/../mock/sfWebResponseMock.class.php';
include dirname(__FILE__) . '/../../apps/client/lib/StreemeUtil.class.php';
// Initialize the test object
$t = new lime_test(6, new lime_output_color());
$combiner = new combineFiles();
$t->comment('->combine()');
// force the asset cache to regenerate
$_GET['clearassetcache'] = 1;
$t->comment('Javascripts');
$js_location = $combiner->combine('js', 'testnamespace', new sfWebResponseMock(new sfEventDispatcher()));
$t->is($js_location, '/service/combine/js/testnamespace', 'File stored correctly');
$t->comment('Stylesheets');
$css_location = $combiner->combine('css', 'testnamespace', new sfWebResponseMock(new sfEventDispatcher()));
$t->is($css_location, '/service/combine/css/testnamespace', 'File stored correctly');
$t->comment('->getFileName()');
$t->comment('Javascripts');
$js_filename = $combiner->getFileName('js', 'testnamespace');
$t->is($js_filename, sfConfig::get('sf_cache_dir') . '/combine/js/testnamespace.js', 'File retrieved correctly');
$js_content_expected = file_get_contents(sfConfig::get('sf_test_dir') . '/files/testnamespaceexample.js');
$js_content = file_get_contents($js_filename);
$t->is($js_content, $js_content_expected, 'File was minified as expected');
$t->comment('Stylesheets');
$css_filename = $combiner->getFileName('css', 'testnamespace');
$t->is($css_filename, sfConfig::get('sf_cache_dir') . '/combine/css/testnamespace.css', 'File retrieved correctly');
$css_content_expected = file_get_contents(sfConfig::get('sf_test_dir') . '/files/testnamespaceexample.css');
$css_content = file_get_contents($css_filename);
$t->is($css_content, $css_content_expected, 'File was minified as expected');