コード例 #1
0
 private static function get_writable_file($file_path)
 {
     $f = new File($file_path);
     //Ensure that all symlinks are followed to the end
     while ($f->is_link()) {
         $f = $f->readlink();
     }
     if (!$f->exists()) {
         //Just to make sure
         $real_path = $f->realPath();
         $real_file = new File($real_path);
         //Grab the path information
         $pinfo = $real_file->pathinfo();
         $directory = $pinfo->dirname;
         //Ensure the directory exists
         $dfile = new File($directory);
         if (!$dfile->exists()) {
             $dfile->mkdir(0777, true);
         }
         //Try to touch the file
         $real_file->touch();
     }
     if ($f->is_dir()) {
         return null;
     }
     if ($f->is_writable()) {
         return $f;
     }
     return null;
 }
コード例 #2
0
ファイル: JsonFile.php プロジェクト: lillockey/utilities
 public function __construct(File $path)
 {
     if ($path != null && $path->exists() && $path->is_file() && $path->is_readable()) {
         parent::__construct($path->get_contents());
     } else {
         parent::__construct(null);
     }
 }
コード例 #3
0
ファイル: INIFile.php プロジェクト: lillockey/utilities
 /**
  * Parse an INI path
  * @param File $path
  */
 public function __construct(File $path)
 {
     $ar = array();
     if ($path != null && $path->exists() && $path->is_file() && $path->is_readable()) {
         $ar = !parse_ini_file($path->getPath());
     }
     parent::__construct($ar);
 }
コード例 #4
0
 public function __construct(File $file, $first_row_headers = true)
 {
     if ($file == null) {
         throw new \Exception("The file may not be null");
     }
     $this->file = $file;
     if ($file == null || !$file->exists() || !$file->is_file() || !$file->is_readable()) {
         parent::__construct('', false);
         return;
     }
     parent::__construct($file->get_contents(), $first_row_headers);
 }
コード例 #5
0
ファイル: FIle.php プロジェクト: lillockey/utilities
 /**
  * @param File $target
  * @param bool|true $replace_current_symlink
  * @return bool
  */
 public function make_symlink(File $target, $replace_current_symlink = true)
 {
     if ($replace_current_symlink === true && $this->is_link()) {
         $this->delete();
     }
     return symlink($target->getPath(), $this->path);
 }