php Gaufrette-Filesystem类(方法)实例源码

下面列出了php Gaufrette-Filesystem 类(方法)源码代码实例,从而了解它的用法。

作者:ruud    项目:Gaufrett   
public function testWriteThrowsAnExceptionIfTheFileAlreadyExistsAndIsNotAllowedToOverwrite()
 {
     $adapter = new InMemory(array('myFile' => array()));
     $fs = new Filesystem($adapter);
     $this->setExpectedException('InvalidArgumentException');
     $fs->write('myFile', 'some text');
 }

作者:Silweret    项目:Syliu   
function let(Filesystem $filesystem, ImageInterface $image)
 {
     $filesystem->has(Argument::any())->willReturn(false);
     $file = new File(__FILE__, 'img.jpg');
     $image->getFile()->willReturn($file);
     $this->beConstructedWith($filesystem);
 }

作者:partiku    项目:FileArchiv   
function it_uploads_all_files_to_gaufrette(Filesystem $filesystem)
 {
     $filesystem->write('myArchive/aaa/a.txt', 'Test Cocoders content 123')->shouldBeCalled();
     $filesystem->write('myArchive/aaa/t.txt', 'Test Cocoders content!')->shouldBeCalled();
     $filesystem->write('myArchive/bbb', 'CDE !')->shouldBeCalled();
     $this->upload('myArchive', [vfsStream::url('tmp/23a/aaa/a.txt'), vfsStream::url('tmp/23a/aaa/t.txt'), vfsStream::url('tmp/23a/bbb')]);
 }

作者:lebri    项目:karm   
private function read(Filesystem $fs)
 {
     $profileFilename = Application::PROFILE_FILENAME;
     if ($fs->has($profileFilename)) {
         $this->processProfileContent($fs->read($profileFilename));
     }
 }

作者:jacko97    项目:pim-community-de   
function it_duplicates_product_media($filesystem, ProductMediaInterface $source, ProductMediaInterface $target, File $newFile)
 {
     $target->setFile(Argument::any())->shouldBeCalled();
     $source->getOriginalFilename()->willReturn('akeneo.jpg');
     $target->getOriginalFilename()->willReturn('akeneo.jpg');
     // upload
     $target->getFile()->willReturn($newFile);
     $newFile->getPathname()->willReturn('/tmp/tmp-phpspec');
     // write a fake file in tmp
     $adapter = new LocalAdapter('/tmp');
     $fs = new Filesystem($adapter);
     $fs->write('tmp-phpspec', '', true);
     $source->getFilename()->willReturn('akeneo.jpg');
     $newFile->getFilename()->willReturn('akeneo.jpg');
     $filesystem->write('prefix-akeneo.jpg', '', false)->shouldBeCalled();
     $target->setOriginalFilename('akeneo.jpg')->shouldBeCalled();
     $target->setFilename('prefix-akeneo.jpg')->shouldBeCalled();
     $filesystem->has('akeneo.jpg')->willReturn(true);
     $target->getFilename()->willReturn('akeneo.jpg');
     $newFile->getMimeType()->willReturn('jpg');
     $target->setMimeType('jpg')->shouldBeCalled();
     // update original file name
     $source->getOriginalFilename()->willReturn('akeneo.jpg');
     $target->setOriginalFilename('akeneo.jpg')->shouldBeCalled();
     $this->duplicate($source, $target, 'prefix');
 }

作者:ls    项目:OneupUploaderBundl   
public function __construct(Filesystem $filesystem, $bufferSize, $streamWrapperPrefix, $prefix)
 {
     if (!$filesystem->getAdapter() instanceof StreamFactory) {
         throw new \InvalidArgumentException('The filesystem used as chunk storage must implement StreamFactory');
     }
     $this->filesystem = $filesystem;
     $this->bufferSize = $bufferSize;
     $this->prefix = $prefix;
     $this->streamWrapperPrefix = $streamWrapperPrefix;
 }

作者:partiku    项目:FileArchiv   
function it_saves_content_of_files_from_gaufrette_at_local_disk(Filesystem $filesystem)
 {
     $filesystem->listKeys('test')->willReturn(['keys' => ['test/aaa/z.txt', 'test/aaa/test2.txt', 'test.txt'], 'dirs' => ['test/aaa']]);
     $filesystem->read('test/aaa/z.txt')->willReturn('Some content');
     $filesystem->read('test/aaa/test2.txt')->willReturn('Other text content');
     $files = $this->getFiles('test');
     $files[0]->shouldBeAnInstanceOf('Cocoders\\FileSource\\File');
     $files[0]->shouldHaveContent('Some content');
     $files[1]->shouldBeAnInstanceOf('Cocoders\\FileSource\\File');
     $files[1]->shouldHaveContent('Other text content');
 }

作者:umpirsk    项目:titlerato   
public function execute(InputInterface $input, OutputInterface $output)
 {
     $file = $input->getArgument('file');
     $filesystem = new Filesystem(new Local('/'));
     $titlerator = new Titlerator(new Transliterator(Settings::LANG_SR), $filesystem->read($file));
     $titlerator->fixEncoding();
     if ($input->getOption('transliterate')) {
         $titlerator->transliterate();
     }
     $filesystem->write($file, $titlerator->getText(), true);
 }

作者:niktu    项目:karm   
public function testCache()
 {
     $cacheAdapter = new InMemory(array());
     $this->app['finder.cache.adapter'] = $cacheAdapter;
     $cache = new Filesystem($cacheAdapter);
     $this->assertEmpty($cache->keys());
     // exec without cache
     $this->runCommand('rollback', array('sourcePath' => 'src/'));
     $this->assertEmpty($cache->keys());
     // exec with cache
     $this->runCommand('rollback', array('--cache' => true, 'sourcePath' => 'src/'));
     $this->assertNotEmpty($cache->keys());
 }

作者:kj18    项目:typo3-helpe   
/**
  * @param string $targetPath
  * @param array $replacePatterns
  * @return mixed|void
  */
 public function execute($targetPath = '', array $replacePatterns = array())
 {
     $adapter = new LocalAdapter($targetPath);
     $filesystem = new Filesystem($adapter);
     $listKeys = $filesystem->listKeys();
     if (count($replacePatterns) > 0) {
         foreach ($listKeys['keys'] as $file) {
             if (!@strstr(mime_content_type($targetPath . $file), 'image') && !@strstr($file, '.git') && !@strstr($file, '.svn')) {
                 $filesystem->write($file, $this->replaceContent($replacePatterns, $filesystem->read($file)), TRUE);
             }
         }
     }
 }

作者:javiersanto    项目:pim-community-de   
function it_archives_unvalid_items(InvalidItemsCollector $collector, CsvWriter $writer, JobExecution $jobExecution, JobInstance $jobInstance, Filesystem $filesystem)
 {
     $collector->getInvalidItems()->willReturn(['items']);
     $jobExecution->getId()->willReturn('id');
     $jobExecution->getJobInstance()->willReturn($jobInstance);
     $jobInstance->getType()->willReturn('type');
     $jobInstance->getAlias()->willReturn('alias');
     $filesystem->write('type/alias/id/invalid/invalid_items.csv', '', true)->shouldBeCalled();
     $writer->setFilePath('/root/type/alias/id/invalid/invalid_items.csv')->shouldBeCalled();
     $writer->initialize()->shouldBeCalled();
     $writer->write(['items'])->shouldBeCalled();
     $writer->flush()->shouldBeCalled();
     $this->archive($jobExecution);
 }

作者:thrace-projec    项目:media-bundl   
/**
  * {@inheritDoc}
  */
 public function clearCache($maxAge)
 {
     $delTime = time() - (int) $maxAge;
     $num = 0;
     foreach ($this->temporaryFilesystem->keys() as $key) {
         if (!$this->temporaryFilesystem->getAdapter()->isDirectory($key)) {
             if ($delTime > $this->temporaryFilesystem->mtime($key)) {
                 $this->temporaryFilesystem->delete($key);
                 $num++;
             }
         }
     }
     return $num;
 }

作者:jacko97    项目:pim-community-de   
function it_create_a_file_when_reader_is_valid(CsvReader $reader, JobExecution $jobExecution, JobInstance $jobInstance, Job $job, ItemStep $step, $filesystem)
 {
     $jobExecution->getJobInstance()->willReturn($jobInstance);
     $jobExecution->getId()->willReturn(12);
     $jobInstance->getJob()->willReturn($job);
     $jobInstance->getType()->willReturn('type');
     $jobInstance->getAlias()->willReturn('alias');
     $job->getSteps()->willReturn([$step]);
     $step->getReader()->willReturn($reader);
     $reader->getFilePath()->willReturn('/tmp/tmp');
     $adapter = new LocalAdapter('/tmp');
     $fs = new Filesystem($adapter);
     $fs->write('tmp', '', true);
     $filesystem->write("type/alias/12/input/tmp", "", true)->shouldBeCalled();
     $this->archive($jobExecution);
 }

作者:novate    项目:SonataMediaBundl   
public function testResize()
 {
     $image = $this->getMock('Imagine\\Image\\ImageInterface');
     $image->expects($this->once())->method('thumbnail')->will($this->returnValue($image));
     $image->expects($this->once())->method('get')->will($this->returnValue(file_get_contents(__DIR__ . '/../fixtures/logo.png')));
     $adapter = $this->getMock('Imagine\\Image\\ImagineInterface');
     $adapter->expects($this->any())->method('load')->will($this->returnValue($image));
     $media = $this->getMock('Sonata\\MediaBundle\\Model\\MediaInterface');
     $media->expects($this->exactly(2))->method('getBox')->will($this->returnValue(new Box(535, 132)));
     $filesystem = new Filesystem(new InMemory());
     $in = $filesystem->get('in', true);
     $in->setContent(file_get_contents(__DIR__ . '/../fixtures/logo.png'));
     $out = $filesystem->get('out', true);
     $resizer = new SimpleResizer($adapter, 'outbound');
     $resizer->resize($media, $in, $out, 'bar', array('height' => null, 'width' => 90, 'quality' => 100));
 }

作者:jacko97    项目:pim-community-de   
/**
  * @param Request $request
  * @param string  $filename
  *
  * @throws NotFoundHttpException If media is not found
  *
  * @return Response
  */
 public function showAction(Request $request, $filename)
 {
     if (!$this->filesystem->has($filename)) {
         throw new NotFoundHttpException(sprintf('Media "%s" not found', $filename));
     }
     $response = new Response($content = $this->filesystem->read($filename));
     $mime = $this->filesystem->mimeType($filename);
     if (($filter = $request->query->get('filter')) && null !== $mime && 0 === strpos($mime, 'image')) {
         try {
             $cachePath = $this->cacheManager->resolve($request, $filename, $filter);
             if ($cachePath instanceof Response) {
                 $response = $cachePath;
             } else {
                 $image = $this->imagine->load($content);
                 $response = $this->filterManager->get($request, $filter, $image, $filename);
                 $response = $this->cacheManager->store($response, $cachePath, $filter);
             }
         } catch (\RuntimeException $e) {
             if (0 === strpos($e->getMessage(), 'Filter not defined')) {
                 throw new HttpException(404, sprintf('The filter "%s" cannot be found', $filter), $e);
             }
             throw $e;
         }
     }
     if ($mime) {
         $response->headers->set('Content-Type', $mime);
     }
     return $response;
 }

作者:fvilpoi    项目:php-commo   
/**
  * @param string $fileKey
  * @param string $fileKeyWithFormat
  * @param Format $format
  *
  * @return
  */
 protected function generateThumbnail($fileKey, $fileKeyWithFormat, Format $format)
 {
     // check if has original picture
     try {
         $has = $this->fileSystem->has($fileKey);
     } catch (\OutOfBoundsException $e) {
         $has = false;
     }
     if (!$has) {
         throw new Exception\ImageDoesNotExistException();
     }
     // create thumbnail
     try {
         $blobOriginal = $this->fileSystem->read($fileKey);
     } catch (FileNotFound $e) {
         throw new Exception\ImageDoesNotExistException();
     }
     $imagine = new Imagine();
     $image = $imagine->load($blobOriginal);
     $resizedImage = Manipulator::resize($image, $format);
     $extension = $this->getExtension($fileKey);
     $blobResizedImage = $resizedImage->get($extension, array('jpeg_quality' => 90, 'png_compression_level' => 9));
     $this->fileSystem->write($fileKeyWithFormat, $blobResizedImage, true);
     return $blobResizedImage;
 }

作者:javiersanto    项目:pim-community-de   
/**
  * {@inheritdoc}
  */
 public function getArchive(JobExecution $jobExecution, $key)
 {
     $archives = $this->getArchives($jobExecution);
     if (!isset($archives[$key])) {
         throw new \InvalidArgumentException(sprintf('Key "%s" does not exist', $key));
     }
     return $this->filesystem->createStream($archives[$key]);
 }

作者:partiku    项目:FileArchiv   
public function upload($name, $paths)
 {
     $rootParent = $this->fetchRootPath($paths);
     foreach ($paths as $path) {
         $key = $this->generateKey($name, $rootParent, $path);
         $this->filesystem->write($key, file_get_contents($path));
     }
 }

作者:CampaignChai    项目:cor   
/**
  * delete the given file
  *
  * @param string $file
  */
 public function deleteFile($file)
 {
     if (!$this->filesystem->has($file)) {
         return;
     }
     $this->filesystem->delete($file);
     $this->cacheManager->remove($file);
 }

作者:javiersanto    项目:pim-community-de   
/**
  * Test related method
  */
 public function testRemoveAFileIfMediaIsRemoved()
 {
     $this->filesystem->expects($this->any())->method('has')->will($this->returnValue(true));
     $this->filesystem->expects($this->once())->method('delete');
     $media = $this->getMediaMock();
     $media->expects($this->any())->method('isRemoved')->will($this->returnValue(true));
     $media->expects($this->any())->method('getFilename')->will($this->returnValue('foo.jpg'));
     $this->manager->handle($media, '');
 }


问题


面经


文章

微信
公众号

扫码关注公众号