本文整理汇总了PHP中Gaufrette\Filesystem类的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem类的具体用法?PHP Filesystem怎么用?PHP Filesystem使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Filesystem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testWriteThrowsAnExceptionIfTheFileAlreadyExistsAndIsNotAllowedToOverwrite
public function testWriteThrowsAnExceptionIfTheFileAlreadyExistsAndIsNotAllowedToOverwrite()
{
$adapter = new InMemory(array('myFile' => array()));
$fs = new Filesystem($adapter);
$this->setExpectedException('InvalidArgumentException');
$fs->write('myFile', 'some text');
}
示例2: let
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);
}
示例3:
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')]);
}
示例4: read
private function read(Filesystem $fs)
{
$profileFilename = Application::PROFILE_FILENAME;
if ($fs->has($profileFilename)) {
$this->processProfileContent($fs->read($profileFilename));
}
}
示例5: LocalAdapter
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');
}
示例6: __construct
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;
}
示例7:
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');
}
示例8: execute
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);
}
示例9: testCache
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());
}
示例10: execute
/**
* @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);
}
}
}
}
示例11: showAction
/**
* @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;
}
示例12: generateThumbnail
/**
* @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;
}
示例13: getArchive
/**
* {@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]);
}
示例14: upload
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));
}
}
示例15: deleteFile
/**
* 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);
}