/**
  * @return Filename
  */
 public function load()
 {
     if (!$this->filename->exists()) {
         $this->downloadFromSource();
     }
     return $this->filename;
 }
Example #2
0
 function __construct($name)
 {
     if (!Filename::isValid($name)) {
         throw new NameException($name);
     }
     $this->name = $name;
 }
Example #3
0
 function __construct($name, $content = '')
 {
     if (!Filename::isValid($name)) {
         throw new NameException($name);
     }
     $this->name = $name;
     $this->setContent($content);
 }
 function __construct($name, $rootDir)
 {
     if (!Filename::isValid($name)) {
         throw new NameException();
     }
     $this->name = $name;
     $rootDir = realpath($rootDir);
     if ($rootDir !== false && is_dir($rootDir)) {
         $this->rootDir = $rootDir;
     } else {
         throw new FolderNotFoundException($rootDir);
     }
 }
Example #5
0
 function __construct($name, $host, $username, $password)
 {
     if (!Filename::isValid($name) || $host === '') {
         throw new NameException();
     }
     if ($username === '') {
         $username = '******';
     }
     if ($password === '') {
         $password = '******';
     }
     $this->name = $name;
     $this->host = $host;
     $this->username = $username;
     $this->password = $password;
     $this->getConnection();
 }
Example #6
0
 function rename($path, $newName)
 {
     if (!Filename::isValid($newName)) {
         throw new NameException();
     }
     $splitPaths = Path::split($path);
     if (!$splitPaths) {
         throw new NameException();
     }
     $passedFolders = [];
     $parent = $this->rootFolder;
     if ($parent->isProxy) {
         $parent->rename(Path::join($splitPaths), $newName);
         return;
     }
     while (count($splitPaths) > 1) {
         $folderName = array_shift($splitPaths);
         $passedFolders[] = $folderName;
         $item = $parent->get($folderName);
         if (!$item) {
             throw new FolderNotFoundException(Path::join($passedFolders));
         } else {
             if ($item instanceof File) {
                 $passedFolders[] = array_shift($splitPaths);
                 throw new FolderNotFoundException(Path::join($passedFolders));
             } elseif ($item->isProxy) {
                 $item->rename(Path::join($splitPaths), $newName);
                 return;
             }
         }
         $parent = $item;
     }
     $item = $splitPaths[0];
     $parent->rename($item, $newName);
 }
Example #7
0
 /**
  * @param Filename $filename
  */
 public function saveAs(Filename $filename)
 {
     file_put_contents($filename->asString(), $this->getContent());
 }