/** * Pass-through to plugins, then Image\Info. This is for BC. * * @param string $method * @param array $arguments * * @return mixed */ public function __call($method, array $arguments) { try { return parent::__call($method, $arguments); } catch (BadMethodCallException $e) { } $info = $this->getInfo(); if (method_exists($info, 'get' . $method)) { return call_user_func([$info, 'get' . $method]); } elseif (method_exists($info, 'is' . $method)) { return call_user_func([$info, 'is' . $method]); } throw $e; }
/** * Sets the current handler and path. */ protected function setCurrent() { if (!isset($this->contents[$this->position])) { $this->current = null; $this->key = null; return; } $this->current = $this->contents[$this->position]; $path = $this->current->getFullPath(); if ($this->mode & static::KEY_FOR_GLOB) { // Glob code requires absolute paths, so prefix path // with leading slash, but not before mount point if (strpos($path, '://') > 0) { $path = str_replace('://', ':///', $path); } else { $path = '/' . ltrim($path, '/'); } } $this->key = $path; }
/** * 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; }
public function testDelete() { $file = new File($this->filesystem, 'fixtures/base.css'); $file->copy('temp/drop-the-base.css'); $newFile = new File($this->filesystem, 'temp/drop-the-base.css'); $this->assertSame($file->read(), $newFile->read()); $newFile->delete(); $this->assertFalse($newFile->exists()); $newNewFile = new File($this->filesystem, 'temp/drop-the-base.css'); $this->assertFalse($newNewFile->exists()); }
/** * Backup the YAML file. */ protected function backup() { $this->file->copy($this->file->getPath() . '.' . date('Ymd-His')); }
/** * Attempt to save the serialised exception if in debug mode. * * @param \Exception $exception */ protected function saveException(\Exception $exception) { if ($this->app['debug'] !== true) { return; } $environment = $this->app['environment']; $serialised = serialize(FlattenException::create($exception)); $sourceFile = Slugify::create()->slugify($exception->getFile()); $fileName = sprintf('%s-%s.exception', Carbon::now()->format('Ymd-Hmi'), substr($sourceFile, -102)); $fullPath = sprintf('%s/exception/%s', $environment, $fileName); $cacheFilesystem = $this->app['filesystem']->getFilesystem('cache'); $file = new File($cacheFilesystem, $fullPath); $file->write($serialised); }
/** * {@inheritdoc} */ public function listContents($directory = '', $recursive = false) { $directory = $this->normalizePath($directory); try { $contents = $this->getAdapter()->listContents($directory, $recursive); } catch (Exception $e) { throw $this->handleEx($e, $directory); } $formatter = new Flysystem\Util\ContentListingFormatter($directory, $recursive); $contents = $formatter->formatListing($contents); $contents = array_map(function ($entry) { $type = $this->getTypeFromMetadata($entry); $entry['type'] = $type; if ($type === 'dir') { $handler = new Handler\Directory($this, $entry['path']); } elseif ($type === 'image') { $handler = Handler\Image::createFromListingEntry($this, $entry); } else { $handler = Handler\File::createFromListingEntry($this, $entry); } $handler->setMountPoint($this->mountPoint); return $handler; }, $contents); return $contents; }
/** * @dataProvider getAcceptData */ public function testAccept($mode, array $expected) { $iterator = new \ArrayIterator([File::createFromListingEntry($this->filesystem, ['timestamp' => 1, 'path' => 'fixtures/js/script.js']), File::createFromListingEntry($this->filesystem, ['timestamp' => 9, 'path' => 'fixtures/css/reset.css']), File::createFromListingEntry($this->filesystem, ['timestamp' => 2, 'path' => 'fixtures']), File::createFromListingEntry($this->filesystem, ['timestamp' => 8, 'path' => 'fixtures/css/old/old_style.css']), File::createFromListingEntry($this->filesystem, ['timestamp' => 4, 'path' => 'fixtures/base.css']), File::createFromListingEntry($this->filesystem, ['timestamp' => 7, 'path' => 'fixtures/css/style.css']), File::createFromListingEntry($this->filesystem, ['timestamp' => 5, 'path' => 'fixtures/css/old']), File::createFromListingEntry($this->filesystem, ['timestamp' => 6, 'path' => 'fixtures/js']), File::createFromListingEntry($this->filesystem, ['timestamp' => 3, 'path' => 'fixtures/css'])]); $iterator = new SortableIterator($iterator, $mode); $this->assertOrderedIterator($expected, $iterator); }