Ejemplo n.º 1
0
 /**
  * CSS Minification
  *
  * @param string $file
  * @param array $arguments
  * @param array $cssOptions
  *
  * @return void
  */
 public function doFilter($file, $arguments, $cssOptions)
 {
     if (!$arguments['minify']) {
         return;
     }
     $content = file_get_contents($file);
     if (Utils::isSerialized($content, $content)) {
         $content['compiled'] = $this->minify($content['compiled']);
         $content = serialize($content);
     } else {
         $content = $this->minify($content);
     }
     file_put_contents($file, $content);
 }
Ejemplo n.º 2
0
 /**
  * Lets test all types of serialisation!
  */
 public function testIsSerialized()
 {
     $notSerializedString = 'nope';
     $this->assertFalse(Utils::isSerialized($notSerializedString));
     $notString = 42;
     $this->assertFalse(Utils::isSerialized($notString));
     $wrongQuotesSerial = "s:1:'foo';";
     $this->assertFalse(Utils::isSerialized($wrongQuotesSerial));
     $malformedStringSerial = 's:1:"foo";';
     $this->assertFalse(Utils::isSerialized($malformedStringSerial));
     $correctStringSerial = 's:3:"foo";';
     $this->assertTrue(Utils::isSerialized($correctStringSerial));
     $malformedArraySerial = 'a:1:{s:1:"foo";}';
     $this->assertFalse(Utils::isSerialized($malformedArraySerial));
     $correctArraySerial = 'a:1:{s:3:"foo";s:3:"bar";}';
     $this->assertTrue(Utils::isSerialized($correctArraySerial));
     $malformedObjectSerial = 'O8:"stdClass":0:{}';
     $this->assertFalse(Utils::isSerialized($malformedObjectSerial));
     $malformedObjectSerial = 'O:::"stdClass":0:{}';
     $this->assertFalse(Utils::isSerialized($malformedObjectSerial));
     $correctObjectSerial = 'O:8:"stdClass":0:{}';
     $this->assertTrue(Utils::isSerialized($correctObjectSerial));
     $malformedNullSerial = 'N:';
     $this->assertFalse(Utils::isSerialized($malformedNullSerial));
     $correctNullSerial = 'N;';
     $this->assertTrue(Utils::isSerialized($correctNullSerial));
     $isTrue = false;
     $serializedTrue = 'b:1;';
     $this->assertTrue(Utils::isSerialized($serializedTrue, $isTrue));
     $this->assertTrue($isTrue);
     $isFalse = false;
     $serializedFalse = 'b:0;';
     $this->assertTrue(Utils::isSerialized($serializedFalse, $isFalse));
     $this->assertFalse($isFalse);
     $checkArray = array('foo' => 'bar');
     $testArray = array();
     Utils::isSerialized('a:1:{s:3:"foo";s:3:"bar";}', $testArray);
     $this->assertSame($checkArray, $testArray);
 }
Ejemplo n.º 3
0
 /**
  * Tear Down
  *
  * Remove the tmp asset files
  */
 protected function tearDown()
 {
     Utils::removeDir(WEBROOT . DS . 'js');
 }
Ejemplo n.º 4
0
 /**
  * Callback method called after the content is collected and/or cached
  * Check if the content is serialized.  If it is, we have LESS cache
  * and we want to return whats in the `compiled` array key
  *
  * @param string $content
  *
  * @return string
  */
 protected function afterGetFileContent($content)
 {
     if (Utils::isSerialized($content, $content)) {
         $content = $content['compiled'];
     }
     return $content;
 }
Ejemplo n.º 5
0
 /**
  * Generate File Name Hash based on filename, request params and request options
  *
  * @param string $file
  *
  * @return string
  */
 protected function generateCacheFile($file)
 {
     $requestOptions = serialize($this->request->options);
     $params = serialize($this->request->params);
     $ext = pathinfo($file, PATHINFO_EXTENSION);
     $fileHash = md5($file);
     $optionsHash = md5($params . $requestOptions);
     $cacheDir = $this->cacheDir . DS . substr($fileHash, 0, 2);
     Utils::createDir($cacheDir);
     return $cacheDir . DS . substr($fileHash, 2) . '-' . $optionsHash . '.' . $ext;
 }
Ejemplo n.º 6
0
 /**
  * Generate File Name Hash based on filename, request params and request options
  *
  * @param string $file
  *
  * @return string
  */
 protected function generateCacheFile($file)
 {
     $cacheSalt = serialize(array($this->request->options, MUNEE_USING_URL_REWRITE, MUNEE_DISPATCHER_FILE));
     $params = serialize($this->request->params);
     $ext = pathinfo($file, PATHINFO_EXTENSION);
     $fileHash = md5($file);
     $optionsHash = md5($params . $cacheSalt);
     $cacheDir = $this->cacheDir . DS . substr($fileHash, 0, 2);
     Utils::createDir($cacheDir);
     return $cacheDir . DS . substr($fileHash, 2) . '-' . $optionsHash . '.' . $ext;
 }
Ejemplo n.º 7
0
 /**
  * Grabs an image by URL from another server
  *
  * @param string $url
  *
  * @return string
  */
 protected function getImageByUrl($url)
 {
     $cacheFolder = MUNEE_CACHE . DS . 'placeholders';
     Utils::createDir($cacheFolder);
     $requestOptions = serialize($this->request->options);
     $originalFile = array_shift($this->request->files);
     $fileName = $cacheFolder . DS . md5($url) . '-' . md5($requestOptions . $originalFile);
     if (!file_exists($fileName)) {
         file_put_contents($fileName, file_get_contents($url));
     }
     return $fileName;
 }