Пример #1
0
 /** @inheritdoc */
 public function clean($validPackages)
 {
     foreach (Linq::from($this->filesystem->listContents($this->vendorDir))->where(function ($v) {
         return $v['type'] == 'dir';
     }) as $vendor) {
         if (!Linq::from($validPackages)->any(function ($v, $k) use($vendor) {
             return preg_match('/^' . $vendor['basename'] . '/i', $k);
         })) {
             $this->notify("DELETING: " . $vendor['path'] . "\n");
             $this->filesystem->deleteDir($vendor['path']);
             continue;
         }
         foreach (Linq::from($this->filesystem->listContents($vendor['path']))->where(function ($v) {
             return $v['type'] == 'dir';
         }) as $package) {
             if (!Linq::from($validPackages)->any(function ($v, $k) use($vendor, $package) {
                 return $k == $vendor['basename'] . '/' . $package['basename'];
             })) {
                 $this->notify("DELETING: " . $package['path'] . "\n");
                 $this->filesystem->deleteDir($package['path']);
                 continue;
             }
             foreach (Linq::from($this->filesystem->listContents($package['path']))->where(function ($v) {
                 return $v['type'] == 'dir';
             }) as $version) {
                 if (!Linq::from($validPackages[$vendor['basename'] . '/' . $package['basename']])->any(function ($v) use($version) {
                     return $v == $version['basename'];
                 })) {
                     $this->notify("DELETING: " . $version['path'] . "\n");
                     $this->filesystem->deleteDir($version['path']);
                 }
             }
         }
     }
 }
Пример #2
0
 public function handle($path)
 {
     $files = [];
     $folders = [];
     $list = $this->filesystem->listContents($path);
     $ignored = ['.', '..', '.DS_Store', '.gitignore', '.htaccess'];
     foreach ($list as $entry) {
         if (in_array($entry['basename'], $ignored)) {
             continue;
         }
         if (!$this->filesystem->authorized($entry['path'])) {
             continue;
         }
         if ($entry['type'] === 'file') {
             try {
                 $url = $this->filesystem->url($entry['path']);
             } catch (\Exception $e) {
                 $url = $entry['path'];
             }
             // Ugh, for some reason the foldername for the theme is included twice. Why?
             // For now we 'fix' this with an ugly hack, replacing it. :-/
             // TODO: dig into Filesystem and figure out why this happens.
             $pathsegments = explode('/', $entry['path']);
             if (!empty($pathsegments[0])) {
                 $url = str_replace('/' . $pathsegments[0] . '/' . $pathsegments[0] . '/', '/' . $pathsegments[0] . '/', $url);
             }
             $files[$entry['path']] = ['path' => $entry['dirname'], 'filename' => $entry['basename'], 'newpath' => $entry['path'], 'relativepath' => $entry['path'], 'writable' => true, 'readable' => false, 'type' => isset($entry['extension']) ? $entry['extension'] : '', 'filesize' => Lib::formatFilesize($entry['size']), 'modified' => date("Y/m/d H:i:s", $entry['timestamp']), 'permissions' => 'public', 'url' => $url];
             /* **** Extra checks for files that can be resolved via PHP urlopen functions **** */
             try {
                 $files[$entry['path']]['permissions'] = $this->filesystem->getVisibility($entry['path']);
             } catch (\Exception $e) {
                 // Computer says "No!"
             }
             $fullfilename = $this->filesystem->getAdapter()->applyPathPrefix($entry['path']);
             if (is_readable($fullfilename)) {
                 $files[$entry['path']]['readable'] = true;
                 if (!empty($entry['extension']) && in_array($entry['extension'], ['gif', 'jpg', 'png', 'jpeg'])) {
                     $size = getimagesize($fullfilename);
                     $files[$entry['path']]['imagesize'] = sprintf("%s × %s", $size[0], $size[1]);
                 }
                 $files[$entry['path']]['permissions'] = util::full_permissions($fullfilename);
             }
         }
         if ($entry['type'] == 'dir') {
             $folders[$entry['path']] = ['path' => $entry['dirname'], 'foldername' => $entry['basename'], 'newpath' => $entry['path'], 'modified' => date("Y/m/d H:i:s", $entry['timestamp']), 'writable' => true];
             $fullfilename = $this->filesystem->getAdapter()->applyPathPrefix($entry['path']);
             /* **** Extra checks for files that can be resolved via PHP urlopen functions **** */
             if (is_readable($fullfilename)) {
                 if (!is_writable($fullfilename)) {
                     $folders[$entry['path']]['writable'] = false;
                 }
             }
         }
     }
     ksort($files);
     ksort($folders);
     return [$files, $folders];
 }
Пример #3
0
 /**
  * @return array
  */
 private function getComposerFiles()
 {
     $files = [];
     $fileList = $this->fileSystem->listContents('./', true);
     foreach ($fileList as $file) {
         if ($file['basename'] === self::LOCATE_FILE) {
             $files[] = $file['path'];
         }
     }
     return $files;
 }
Пример #4
0
 public function handle($term, $extensions = 'jpg,jpeg,gif,png')
 {
     $extensions = explode(",", $extensions);
     $allFiles = $this->filesystem->listContents('', true);
     $files = array();
     foreach ($allFiles as $file) {
         if ($file['type'] == 'file' && ($term == '*' || strpos($file['path'], $term) !== false) && in_array($file['extension'], $extensions)) {
             $files[] = $file['path'];
         }
     }
     return $files;
 }
Пример #5
0
 /**
  * {@inheritdoc}
  */
 public function handle($config, CertificateResponse $response)
 {
     $remoteAdapter = $this->createAdapter($config);
     $remote = new Filesystem($remoteAdapter);
     $files = $this->master->listContents('.', true);
     foreach ($files as $file) {
         if (0 === strpos($file['basename'], '.')) {
             continue;
         }
         $this->mirror($file['type'], $file['path'], $remote, $remoteAdapter);
     }
 }
Пример #6
0
 /**
  * @param string $containerName
  *
  * @return array
  */
 public function listFilesByContainerName($containerName)
 {
     $files = [];
     foreach ($this->filesystem->listContents($containerName, true) as $file) {
         $file['mapped_path'] = sprintf('%s/%s', $this->baseUrl, $file['path']);
         if (array_key_exists('size', $file)) {
             $file['size_human'] = FileSize::convertToHumanReadable($file['size']);
         }
         $files[] = $file;
     }
     return $files;
 }
Пример #7
0
 /**
  * Recursively yield files that meet the specification
  *
  * @param SpecificationInterface $specification
  * @param string $path
  * @return Generator
  */
 private function yieldFilesInPath(SpecificationInterface $specification, $path)
 {
     $listContents = $this->filesystem->listContents($path);
     foreach ($listContents as $location) {
         if ($specification->isSatisfiedBy($location)) {
             (yield $location);
         }
         if ($location['type'] == 'dir') {
             foreach ($this->yieldFilesInPath($specification, $location['path']) as $returnedLocation) {
                 (yield $returnedLocation);
             }
         }
     }
 }
 /**
  * Return files list in directory
  *
  * @param  string  $path  dir path
  * @return array
  **/
 protected function _scandir($path)
 {
     $paths = array();
     foreach ($this->fs->listContents($path, false) as $object) {
         $paths[] = $object['path'];
     }
     return $paths;
 }
 public function generate($query)
 {
     $files = $this->filesystem->listContents($this->config['directory']);
     array_filter($files, [$this, 'filterFiles']);
     if (empty($files)) {
         throw new RuntimeException('Cannot generate fractal image: template folder is empty');
     }
     mt_srand((double) microtime() * 1000000);
     mt_rand(0, 1);
     $random_file = mt_rand(0, count($files) - 1);
     $resource = imagecreatefromjpeg(DIRECTORY_SEPARATOR . $files[$random_file]['path']);
     if (!is_resource($resource)) {
         throw new RuntimeException('Cannot create image from the fractal template: ' . $files[$random_file]['basename']);
     }
     return $resource;
     // this variant will not work because of the different resource type
     // return $this->filesystem->readStream($files[$random_file]['path']);
 }
Пример #10
0
 /**
  * @inheritdoc
  */
 public function listFiles($directory = '')
 {
     $files = [];
     foreach ($this->filesystem->listContents($directory, true) as $file) {
         if ($file['type'] == 'dir' || strstr($file['path'], '/.') !== false) {
             continue;
         }
         $files[] = $file['path'];
     }
     return $files;
 }
Пример #11
0
 protected function getPaths(FilesystemInterface $filesystem, $skipDirs)
 {
     $paths = [];
     foreach ($filesystem->listContents($this->dir, true) as $path) {
         if ($skipDirs && $path['type'] === 'dir') {
             continue;
         }
         $paths[$path['path']] = $path;
     }
     ksort($paths);
     return $paths;
 }
Пример #12
0
 /** @inheritdoc */
 public function extract($zipBallPath, $to)
 {
     $absolutePathToZipBall = $this->filesystem->getAdapter()->applyPathPrefix($zipBallPath);
     if ($this->zip->open($absolutePathToZipBall) === true) {
         $absolutePathToExtract = $this->filesystem->getAdapter()->applyPathPrefix($to);
         $this->zip->extractTo($absolutePathToExtract);
         $this->zip->close();
         $zipCreatedFolder = Linq::from($this->filesystem->listContents($to))->single(function ($object) {
             return $object['type'] == 'dir';
         })['path'];
         foreach ($this->filesystem->listContents($zipCreatedFolder, true) as $object) {
             if ($object['type'] == "file") {
                 $segments = explode('/', $object['path']);
                 unset($segments[4]);
                 $this->filesystem->rename($object['path'], implode('/', $segments));
             }
         }
         $this->filesystem->deleteDir($zipCreatedFolder);
         return;
     }
     throw new ZipExtractionFailed($zipBall, $to);
 }
Пример #13
0
 /**
  * {@inheritdoc}
  */
 protected function removeEmptyDirectories($backupName)
 {
     /**
      * @var \SplFileInfo $dir
      */
     foreach ($this->flysystem->listContents($backupName) as $dir) {
         if ($dir['type'] != 'dir') {
             continue;
         }
         if (count($this->flysystem->listContents($dir['path'])) > 0) {
             $this->removeEmptyDirectories($dir['path']);
         } else {
             $this->flysystem->deleteDir($dir['path']);
         }
     }
 }
Пример #14
0
 /**
  * Erase a directory.
  *
  * @param string $dirname
  * @throws IoWriteException
  */
 public function eraseDir($dirname = '')
 {
     try {
         $listing = $this->fs->listContents($dirname, false);
         foreach ($listing as $item) {
             if ($item['type'] === 'dir') {
                 $this->fs->deleteDir($item['path']);
             } else {
                 $this->fs->delete($item['path']);
             }
         }
     } catch (Error $ex) {
         throw new IoWriteException("Directory {$dirname} could not be erased.", $ex);
     } catch (Exception $ex) {
         throw new IoWriteException("Directory {$dirname} could not be erased.", $ex);
     }
 }
Пример #15
0
 /**
  * Erase a directory.
  *
  * @param string $dirname
  * @throws WriteException
  */
 private function ensuredEraseDir($dirname)
 {
     try {
         $listing = $this->fs->listContents($dirname, false);
         foreach ($listing as $item) {
             if ($item['type'] === 'dir') {
                 $this->fs->deleteDir($item['path']);
             } else {
                 $this->fs->delete($item['path']);
             }
         }
         return;
     } catch (Error $ex) {
     } catch (Exception $ex) {
     }
     throw new WriteException("Directory {$dirname} could not be erased.", $ex);
 }
Пример #16
0
 /**
  * Given an array of mappings we will return a list of php src files.
  *
  * @param  array $mappings
  * @return array
  */
 private function getFilesFromMap($package, $version, $mappings)
 {
     $paths = [];
     $basePath = $this->vendorDir . '/' . $package . '/' . $version;
     foreach ($mappings as $ns => $mapping) {
         // Handle an exact file
         if (s($mapping)->endsWith('.php')) {
             $paths[] = $mapping;
             continue;
         }
         $files = $this->filesystem->listContents($basePath . '/' . $mapping, true);
         $query = Linq::from($files)->where(function ($v) {
             return $v['type'] == 'file';
         })->where(function ($v) {
             return isset($v['extension']);
         })->where(function ($v) {
             return $v['extension'] == 'php';
         })->select(function ($v) use($basePath) {
             return str_replace($basePath . '/', '', $v['path']);
         })->where(function ($v) {
             foreach ($this->excludes as $regex) {
                 if (preg_match($regex, $v)) {
                     return false;
                 }
             }
             return true;
         })->toArray();
         if (is_int($ns)) {
             // Handle a classmap
             $paths = array_merge($paths, $query);
         } else {
             // Handle a PSR-0/4 map
             // We save the namespace for later use.
             if (!isset($paths[$ns])) {
                 $paths[$ns] = [];
             }
             $paths[$ns] = array_merge($paths[$ns], $query);
         }
     }
     return $paths;
 }
Пример #17
0
 /**
  * @param string $trimmedSourcePath
  * @param string $trimmedTargetPath
  * @return bool
  */
 protected function copyFolderRecursively($trimmedSourcePath, $trimmedTargetPath)
 {
     try {
         $contents = $this->filesystem->listContents($trimmedSourcePath, true);
         foreach ($contents as $item) {
             if ('file' === $item['type']) {
                 try {
                     $relPath = substr_replace($trimmedSourcePath, '', 0, strlen($item['path']));
                     $targetPath = $trimmedTargetPath . $relPath . '/' . $item['basename'];
                     $this->filesystem->copy($item['path'], $targetPath);
                 } catch (FileExistsException $fee) {
                     continue;
                 } catch (FileNotFoundException $fnfe) {
                     return false;
                 }
             }
         }
     } catch (\Exception $e) {
         return false;
     }
     return true;
 }
Пример #18
0
 /**
  * Get all files in directory
  *
  * @param FilesystemInterface $filesystem
  * @param string $path
  * @return array
  */
 protected function allFiles(FilesystemInterface $filesystem, $path)
 {
     $files = [];
     foreach ($filesystem->listContents($path, true) as $file) {
         if ($file['type'] == 'file') {
             $files[] = $file['path'];
         }
     }
     return $files;
 }
 /**
  * Get all of the directories within a given directory.
  *
  * @param  string|null  $directory
  * @param  bool  $recursive
  * @return array
  */
 public function directories($directory = null, $recursive = false)
 {
     $contents = $this->driver->listContents($directory, $recursive);
     return $this->filterContentsByType($contents, 'dir');
 }
Пример #20
0
 /**
  * List contents of a directory.
  *
  * @param string $directory The directory to list.
  * @param bool   $recursive Whether to list recursively.
  *
  * @return array A list of file metadata.
  */
 public function listContents($directory = '', $recursive = false)
 {
     return $this->fileSystem->listContents($directory, $recursive);
 }