Example #1
0
 /**
  * Sets the current cache key this class is managing, and creates a writable SplFileObject
  * for the cache file the key is referring to.
  *
  * @param string $key The key
  * @param boolean $createKey Whether the key should be created if it doesn't exists, or not
  * @return boolean true if the cache key could be set, false otherwise
  */
 protected function _setKey($key, $createKey = false)
 {
     $groups = null;
     if (!empty($this->_groupPrefix)) {
         $groups = vsprintf($this->_groupPrefix, $this->groups());
     }
     $dir = $this->settings['path'] . $groups;
     if (!is_dir($dir)) {
         mkdir($dir, 0775, true);
     }
     $path = new SplFileInfo($dir . $key);
     if (!$createKey && !$path->isFile()) {
         return false;
     }
     if (empty($this->_File) || $this->_File->getBaseName() !== $key) {
         $exists = file_exists($path->getPathname());
         try {
             $this->_File = $path->openFile('c+');
         } catch (Exception $e) {
             trigger_error($e->getMessage(), E_USER_WARNING);
             return false;
         }
         unset($path);
         if (!$exists && !chmod($this->_File->getPathname(), (int) $this->settings['mask'])) {
             trigger_error(__d('cake_dev', 'Could not apply permission mask "%s" on cache file "%s"', array($this->_File->getPathname(), $this->settings['mask'])), E_USER_WARNING);
         }
     }
     return true;
 }
Example #2
0
 /**
  * Tests File::getPathname
  */
 public function testGetPathname()
 {
     $spl = $this->getFileInfo();
     $file = new File($spl);
     $path = $file->getPathname();
     $this->assertEquals($spl->getPathname(), $path);
 }
Example #3
0
 /**
  * Finds test for $file by looping through all supported test directories.
  *
  * @param File $File File to get test for.
  * @return string Test file.
  */
 public function findTestFor($File)
 {
     $ds = DIRECTORY_SEPARATOR;
     $test = null;
     $path = explode($ds, $File->getPathname());
     $filename = array_pop($path);
     $extension = '.' . $File->getExtension();
     $checked = array();
     foreach ($this->testSuffixes as $suffix) {
         $test = implode($ds, $path) . $ds;
         $test .= substr($filename, 0, -strlen($extension)) . $suffix;
         if (!in_array($test, $checked) && file_exists($test)) {
             array_push($checked, $test);
             return $test;
         }
         array_push($checked, $test);
     }
     foreach ($this->testPaths($path) as $testPath) {
         foreach ($this->testSuffixes as $suffix) {
             $test = $testPath . substr($filename, 0, -strlen($extension)) . $suffix;
             if (!in_array($test, $checked) && file_exists($test)) {
                 array_push($checked, $test);
                 return $test;
             }
             array_push($checked, $test);
         }
     }
     if (!$test || !file_exists($test)) {
         return false;
     }
     return $test;
 }
Example #4
0
 /**
  * Adds a file to the collection.
  *
  * @param string $path File location, may be absolute, relative or even phar.
  *
  * @return void
  */
 public function addFile($path)
 {
     foreach (glob($path) as $path) {
         $file = new File($path);
         $path = $file->getRealPath() ? $file->getRealPath() : $file->getPathname();
         $this[$path] = $file;
     }
 }
Example #5
0
 /**
  * Adds a file to the collection.
  *
  * @param string $path File location, may be absolute, relative or even phar.
  *
  * @return void
  */
 public function addFile($path)
 {
     $paths = $this->getGlobbedPaths($path);
     foreach ($paths as $path) {
         $file = new File($path);
         $path = $file->getRealPath() ? $file->getRealPath() : $file->getPathname();
         $this[$path] = $file;
     }
 }