Ejemplo n.º 1
0
 public function __construct($dir)
 {
     if (self::$useDirectories === NULL) {
         // checks whether directory is writable
         $uniq = uniqid('_', TRUE);
         umask(00);
         if (!@mkdir("{$dir}/{$uniq}", 0777)) {
             // intentionally @
             throw new \InvalidStateException("Unable to write to directory '{$dir}'. Make this directory writable.");
         }
         // tests subdirectory mode
         self::$useDirectories = !ini_get('safe_mode');
         if (!self::$useDirectories && @file_put_contents("{$dir}/{$uniq}/_", '') !== FALSE) {
             // intentionally @
             self::$useDirectories = TRUE;
             unlink("{$dir}/{$uniq}/_");
         }
         rmdir("{$dir}/{$uniq}");
     }
     $this->dir = $dir;
     $this->useDirs = (bool) self::$useDirectories;
     if (mt_rand() / mt_getrandmax() < self::$gcProbability) {
         $this->clean(array());
     }
 }
Ejemplo n.º 2
0
 public function __construct($dir, Nette\Context $context = NULL)
 {
     if (self::$useDirectories === NULL) {
         // checks whether directory is writable
         $uniq = uniqid('_', TRUE);
         umask(00);
         if (!@mkdir("{$dir}/{$uniq}", 0777)) {
             // @ - is escalated to exception
             throw new \InvalidStateException("Unable to write to directory '{$dir}'. Make this directory writable.");
         }
         // tests subdirectory mode
         self::$useDirectories = !ini_get('safe_mode');
         if (!self::$useDirectories && @file_put_contents("{$dir}/{$uniq}/_", '') !== FALSE) {
             // @ - error is expected
             self::$useDirectories = TRUE;
             unlink("{$dir}/{$uniq}/_");
         }
         @rmdir("{$dir}/{$uniq}");
         // @ - directory may not already exist
     }
     $this->dir = $dir;
     $this->useDirs = (bool) self::$useDirectories;
     $this->context = $context;
     if (mt_rand() / mt_getrandmax() < self::$gcProbability) {
         $this->clean(array());
     }
 }
Ejemplo n.º 3
0
	public function __construct($dir, ICacheJournal $journal = NULL)
	{
		$this->dir = realpath($dir);
		if ($this->dir === FALSE) {
			throw new \DirectoryNotFoundException("Directory '$dir' not found.");
		}

		if (self::$useDirectories === NULL) {
			// checks whether directory is writable
			$uniq = uniqid('_', TRUE);
			umask(0000);
			if (!@mkdir("$dir/$uniq", 0777)) { // @ - is escalated to exception
				throw new \InvalidStateException("Unable to write to directory '$dir'. Make this directory writable.");
			}

			// tests subdirectory mode
			self::$useDirectories = !ini_get('safe_mode');
			if (!self::$useDirectories && @file_put_contents("$dir/$uniq/_", '') !== FALSE) { // @ - error is expected
				self::$useDirectories = TRUE;
				unlink("$dir/$uniq/_");
			}
			@rmdir("$dir/$uniq"); // @ - directory may not already exist
		}

		$this->useDirs = (bool) self::$useDirectories;
		$this->journal = $journal;

		if (mt_rand() / mt_getrandmax() < self::$gcProbability) {
			$this->clean(array());
		}
	}