Exemplo n.º 1
0
 /**
  * Get the filesystem's disk.
  *
  * @return \Anomaly\FilesModule\Disk\Contract\DiskInterface|null
  */
 protected function getFilesystemDisk()
 {
     $filesystem = $this->file->getFilesystem();
     if ($filesystem instanceof AdapterFilesystem) {
         return $filesystem->getDisk();
     }
     return null;
 }
 /**
  * Sends the file.
  */
 public function sendContent()
 {
     if (!$this->isSuccessful()) {
         parent::sendContent();
         return;
     }
     $outStream = fopen('php://output', 'wb');
     $fileStream = $this->file->readStream();
     stream_copy_to_stream($fileStream, $outStream);
     fclose($outStream);
     fclose($fileStream);
 }
Exemplo n.º 3
0
 public static function index(File $file)
 {
     $lexer = new Lexer(array('usedAttributes' => array('comments', 'startLine', 'endLine', 'startFilePos', 'endFilePos')));
     $parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP5, $lexer);
     $traverser = new NodeTraverser();
     $traverser->addVisitor(new ScopeResolver());
     $stmts = $parser->parse($file->read());
     $stmts = new ScopeResolvedNodes($traverser->traverse($stmts));
     $functions = (new BasicFunctionIndexer($file, $stmts))->index();
     $variables = (new BasicVariableIndexer($file, $stmts))->index();
     return ["functions" => $functions, "variables" => $variables];
 }
Exemplo n.º 4
0
 /**
  * @param $event \trntv\filekit\events\StorageEvent
  */
 public function afterSave($event)
 {
     $file = new File($event->filesystem, $event->path);
     $model = new FileStorageItem();
     $model->component = $this->component;
     $model->path = $file->getPath();
     $model->base_url = $this->getStorage()->baseUrl;
     $model->size = $file->getSize();
     $model->type = $file->getMimeType();
     $model->name = pathinfo($file->getPath(), PATHINFO_FILENAME);
     if (Yii::$app->request->getIsConsoleRequest() === false) {
         $model->upload_ip = Yii::$app->request->getUserIP();
     }
     $model->save(false);
 }
Exemplo n.º 5
0
 /**
  * Sync the files folder.
  *
  * @param File          $resource
  * @param DiskInterface $disk
  * @return null|FolderInterface
  */
 protected function syncFolder(File $resource, DiskInterface $disk)
 {
     $path = dirname($resource->getPath());
     if ($path === '.') {
         return null;
     }
     /* @var FolderInterface|null $parent */
     $parent = null;
     $folder = null;
     foreach (explode('/', $path) as $name) {
         if (!($folder = $this->folders->findByName($name, $disk, $parent))) {
             $folder = $this->folders->create(['name' => $name, 'disk_id' => $disk->getId(), 'parent_id' => $parent ? $parent->getId() : null]);
         }
         $parent = $folder;
     }
     return $folder;
 }
 /**
  * Sends the file.
  */
 public function sendContent()
 {
     if (!$this->isSuccessful()) {
         parent::sendContent();
         return;
     }
     if (0 === $this->maxlen) {
         return;
     }
     $out = fopen('php://output', 'wb');
     $file = $this->filesystem->readStream($this->file->getPath());
     stream_copy_to_stream($file, $out, $this->maxlen, $this->offset);
     fclose($out);
     fclose($file);
 }
Exemplo n.º 7
0
 /**
  * Reads versions from the storage file.
  *
  * @return VersionInterface[]
  *
  * @throws StorageException
  */
 protected function doFetchAll()
 {
     $contents = $this->file->read();
     $lines = explode("\n", $contents);
     $collection = new Migrated();
     foreach ($lines as $line) {
         $line = trim($line);
         if (!empty($line)) {
             // skip empty lines
             $version = new Version($line);
             $version->setMigrated(true);
             // if its in storage its because it has been migrated
             $collection->add($version);
         }
     }
     return $collection;
 }
 public function __construct(File $file, Filesystem $filesystem, $streamWrapperPrefix = null)
 {
     parent::__construct($filesystem, $file->getPath());
     $this->streamWrapperPrefix = $streamWrapperPrefix;
 }
Exemplo n.º 9
0
 /**
  * Backup the YAML file.
  */
 protected function backup()
 {
     $this->file->copy($this->file->getPath() . '.' . date('Ymd-His'));
 }
Exemplo n.º 10
0
 protected function createResponseForFile(File $file)
 {
     return new Response($file->read(), Response::HTTP_OK, array('Content-Type' => $file->getMimetype()));
 }
Exemplo n.º 11
0
 protected function createResponseForFile(File $file)
 {
     return new StreamedResponse(function () use($file) {
         fpassthru($file->readStream());
     }, Response::HTTP_OK, array('Content-Type' => $file->getMimetype()));
 }
Exemplo n.º 12
0
 /**
  * Gather the 'similar' files, if present.
  *
  * i.e., if we're editing config.yml, we also want to check for
  * config.yml.dist and config_local.yml
  *
  * @param FilesystemInterface $filesystem
  * @param File                $file
  *
  * @return array
  */
 private function getFileGroup(FilesystemInterface $filesystem, File $file)
 {
     $basename = str_replace('.yml', '', str_replace('_local', '', $file->getPath()));
     $filegroup = [];
     if ($filesystem->has($basename . '.yml')) {
         $filegroup[] = basename($basename . '.yml');
     }
     if ($filesystem->has($basename . '_local.yml')) {
         $filegroup[] = basename($basename . '_local.yml');
     }
     return $filegroup;
 }
Exemplo n.º 13
0
 /**
  * Process an image using the provided template
  *
  * @param  File              $file         The file handler for the image
  * @param  ImageManager      $imageManager The image manipulation manager
  * @param  TemplateInterface $template     The template
  * @return Image                           The processed image
  */
 private function processImage(File $file, ImageManager $imageManager, TemplateInterface $template)
 {
     // Process the image using the template
     $image = new \Diarmuidie\ImageRack\Image\Process($file->readStream(), $imageManager);
     // Process the image
     return $image->process($template);
 }
Exemplo n.º 14
0
 /**
  * copies a file on cloud
  *
  * @param File $file file to be copied
  * @param string $newFileName new name of copied file
  *
  * @return bool false on error true on success
  */
 public function copyFile(File $file, $newFileName)
 {
     return $file->copy($newFileName) !== false;
 }
Exemplo n.º 15
0
 public function testFileGetPath()
 {
     $file = new File();
     $file->setPath('path.txt');
     $this->assertEquals('path.txt', $file->getPath());
 }
Exemplo n.º 16
0
 /**
  * @param FilesystemInterface $filesystem
  *
  * @return $this
  */
 public function setFilesystem(FilesystemInterface $filesystem)
 {
     $this->wrapper = new FilesystemWrapper($filesystem);
     return parent::setFilesystem($this->wrapper);
 }