Beispiel #1
0
 /**
  * Set Up
  *
  * Create some tmp asset files
  */
 protected function setUp()
 {
     $jsDir = WEBROOT . DS . 'js';
     Utils::createDir($jsDir);
     file_put_contents($jsDir . DS . 'foo.js', '//Temp foo.js File');
     file_put_contents($jsDir . DS . 'bar.js', '//Temp bar.js File');
 }
Beispiel #2
0
 /**
  * Can Create/Remove Directories?
  */
 public function testCreateRemoveDirectories()
 {
     $testDir = WEBROOT . DS . 'test' . DS . 'sub_dir';
     $this->assertFalse(is_dir($testDir));
     Utils::createDir($testDir);
     $this->assertTrue(is_dir($testDir));
     Utils::removeDir(WEBROOT . DS . 'test');
 }
Beispiel #3
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;
 }
Beispiel #4
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;
 }
Beispiel #5
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;
 }