Пример #1
0
 /**
  * @see Console\Command\Command
  */
 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 {
     $source = $input->getOption('source');
     $dest = $input->getOption('dest');
     $libs = (require $source . '/composer/autoload_namespaces.php');
     $count = 0;
     foreach ($libs as $ns => $dirs) {
         list($ns) = explode('\\', $ns);
         list($ns) = explode('_', $ns);
         foreach ($dirs as $dir) {
             $from = new Directory($dir . '/' . $ns);
             $from->copy($dest . '/' . $ns);
             $count++;
         }
     }
     $output->writeln('<info>Successfully copied ' . $count . ' libraries.</info>');
 }
Пример #2
0
 /**
  * Move node with contents.
  * 
  * @return self
  */
 public function move($to, $name = null)
 {
     if ($name === null) {
         $name = $this->getBasename();
     }
     $to .= '/' . $name;
     Directory::ensure(dirname($to));
     if (!@rename($this->getPathname(), $to)) {
         throw new Exception(sprintf('File "%s" cannot be moved to "%s" (%s).', $this->getPathname(), $to, error_get_last()['message']));
     }
     $c = get_class($this);
     return new $c($to);
 }
Пример #3
0
 /**
  * Move uploaded file to directory.
  * If no new name is speciefied, original file name will be used.
  * 
  * @param string
  * @param string
  * @return self
  */
 public function move($to, $name = null)
 {
     if ($this->isMoved) {
         return parent::move($to, $name);
     }
     $name = $name === null ? $this->getOriginalName() : $name;
     $path = rtrim($to . '/' . $name, '/');
     Directory::ensure(dirname($path));
     if (!@move_uploaded_file($this->tmp_name, $path)) {
         throw new Exception\Upload('upload error move', 'global');
     }
     $this->isMoved = true;
     parent::__construct($path);
     return $this;
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 public function save($id, array $data, $ttl)
 {
     $file = $this->dir . $id . '.session';
     \Vero\Filesystem\Directory::ensure($this->dir);
     file_put_contents($file, serialize($data), LOCK_EX);
 }
Пример #5
0
 /**
  * Install package.
  * 
  * Listener receives two arguments:
  *  - string $item: relative path to file/directory
  *  - int $status: 0 - ignored, 1 - installed, 2 - overwritten (when forced install)
  * 
  * @param string $package
  * @param boolean $force
  * @param callable $listener
  */
 public function install(Package $package, $force = false, callable $listener = null)
 {
     foreach ($package->getFiles() as $item) {
         $source = new Node($this->baseRepository . $item);
         $dest = new Node($this->baseInstance . $item);
         $exists = $dest->exists();
         if ($exists && $force) {
             $status = 2;
         } elseif (!$exists) {
             $status = 1;
         } else {
             $status = 0;
         }
         if ($status > 0) {
             if (!file_exists($dest->getPath())) {
                 Directory::ensure($dest->getPath());
             }
             $source->getSpecialized()->copy($dest);
         }
         if ($listener) {
             $listener($item, $status);
         }
     }
 }
Пример #6
0
 /**
  * Construct backend.
  * If specified directory not exists, backend will try to create it.
  * 
  * @param string
  * @param int
  */
 public function __construct($dir, $maxSize = self::K128)
 {
     $this->dir = $dir;
     $this->maxSize = $maxSize;
     \Vero\Filesystem\Directory::ensure($dir);
 }