Ejemplo n.º 1
0
 /**
  * Client constructor.
  * @param string $dir
  */
 public function __construct($dir = false)
 {
     if (!$dir) {
         $dir = __DIR__ . '/../../../io-db';
     }
     $this->dir = new Directory($dir);
     $this->dir->create(true);
 }
Ejemplo n.º 2
0
 public static function create($path)
 {
     if (!file_exists($path)) {
         Directory::create(dirname($path));
         mkdir($path, 0777);
     }
 }
Ejemplo n.º 3
0
 public static function save($file, $contents, $code = false)
 {
     Directory::create(dirname($file));
     if ($code) {
         $file .= '.php';
         $contents = '<?php return ' . str_replace('stdClass::__set_state', '(object)', var_export($contents, true)) . ';';
     }
     return file_put_contents($file, $contents);
 }
Ejemplo n.º 4
0
 public function test_writeFile_should_create_file_in_dir()
 {
     $dir = new Directory("dir");
     $dir->create();
     $path = getcwd() . DS . 'dir';
     $dir->writeFile("test.txt", "hello world!");
     $file = $path . DS . 'test.txt';
     $this->assertTrue(file_exists($file));
     $this->assertEquals('hello world!', file_get_contents($file));
     unlink($file);
     rmdir('dir');
 }
Ejemplo n.º 5
0
 /**
  * Write a file to the disk.
  * It is using a temporary file and then rename the file. We guess the file system will
  * be smarter than us, avoiding a writing / reading while renaming the file.
  *
  * @author     Gérald Croes
  * @contributor Laurent Jouanneau
  *
  * @copyright  2001-2005 CopixTeam
  *
  * @link http://www.copix.org
  */
 public static function write($file, $data, $chmod = null)
 {
     $_dirname = dirname($file);
     //asking to create the directory structure if needed.
     Directory::create($_dirname);
     if (!@is_writable($_dirname)) {
         if (!@is_dir($_dirname)) {
             throw new \UnexpectedValueException('The directory ' . $_dirname . ' does not exists');
         }
         throw new \RuntimeException('The directory ' . $_dirname . ' is not writable');
     }
     // write to tmp file, then rename it to avoid
     // file locking race condition
     $_tmp_file = tempnam($_dirname, 'jelix_');
     if (!($fd = @fopen($_tmp_file, 'wb'))) {
         $_tmp_file = $_dirname . '/' . uniqid('jelix_');
         if (!($fd = @fopen($_tmp_file, 'wb'))) {
             throw new \RuntimeException('Cannot create temporary file ' . $_tmp_file);
         }
     }
     fwrite($fd, $data);
     fclose($fd);
     // Delete the file if it allready exists (this is needed on Windows,
     // because it cannot overwrite files with rename()
     if (file_exists($file)) {
         unlink($file);
     }
     rename($_tmp_file, $file);
     if ($chmod === null) {
         $chmod = self::$defaultChmod;
     }
     if ($chmod) {
         chmod($file, $chmod);
     }
     return true;
 }
Ejemplo n.º 6
0
 /**
  * Move a file.
  *
  * @access  public
  * @param   string  $name     New name.
  * @param   bool    $force    Force to move if the file $name already
  *                            exists.
  *                            Use the \Hoa\Stream\IStream\Touchable::*OVERWRITE
  *                            constants.
  * @param   bool    $mkdir    Force to make directory if does not exist.
  *                            Use the \Hoa\Stream\IStream\Touchable::*DIRECTORY
  *                            constants.
  * @return  bool
  */
 public function move($name, $force = \Hoa\Stream\IStream\Touchable::DO_NOT_OVERWRITE, $mkdir = \Hoa\Stream\IStream\Touchable::DO_NOT_MAKE_DIRECTORY)
 {
     $from = $this->getStreamName();
     if ($force === \Hoa\Stream\IStream\Touchable::DO_NOT_OVERWRITE && true === file_exists($name)) {
         return false;
     }
     if (\Hoa\Stream\IStream\Touchable::MAKE_DIRECTORY === $mkdir) {
         Directory::create(dirname($name), Directory::MODE_CREATE_RECURSIVE);
     }
     if (null === $this->getStreamContext()) {
         return @rename($from, $name);
     }
     return @rename($from, $name, $this->getStreamContext()->getContext());
 }
Ejemplo n.º 7
0
Archivo: Table.php Proyecto: xolf/io-db
 /**
  * Touches a table
  *
  * @throws Exception
  */
 public function touch()
 {
     $this->dir->create(true);
 }
Ejemplo n.º 8
0
 public static function write($file, $contents, $flag = null)
 {
     Directory::create(dirname($file));
     return file_put_contents($file, $contents, $flag);
 }
Ejemplo n.º 9
0
 public function createDirectory(string $path, int $permissions = 0770) : Directory
 {
     return Directory::create($path, $permissions);
 }