本文整理汇总了PHP中Gaufrette\Filesystem::write方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::write方法的具体用法?PHP Filesystem::write怎么用?PHP Filesystem::write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gaufrette\Filesystem
的用法示例。
在下文中一共展示了Filesystem::write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
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')]);
}
示例2: 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));
}
}
示例3: fileExistsWithContent
/**
* @Given file :name exists
* @Given dir :name exists
* @Given file :name exists with content:
* @Given I write :name with content:
*/
public function fileExistsWithContent($name, PyStringNode $string = null)
{
if (null === $string) {
$this->filesystem->createFile($name);
} else {
$this->filesystem->write($name, $string->__toString(), true);
}
}
示例4: saveImage
/**
* Saves an image.
*
* @param string $path
* @param string $image
*
* @return string
*/
public function saveImage($image, $path = null)
{
if ($path == null) {
$path = 'images/' . uniqid() . '.png';
}
$this->files->write($path, $image, true);
return $path;
}
示例5: write
/**
* @param mixed $data
* @param int $mode
* @return int
*/
public function write($data, $mode = 0)
{
if ($mode & FILE_APPEND) {
$data = $this->read() . $data;
}
if (!$this->gaufrette->has($this->filePath)) {
$this->gaufrette->createFile($this->filePath);
}
return $this->gaufrette->write($this->filePath, $data, true);
}
示例6: store
/**
* Store a file content.
*
* @param UploadContext $context
* @param $content
* @param array $metadataMap
* @return UploadedFile
*/
public function store(UploadContext $context, $content, array $metadataMap = array())
{
$name = $this->namingStrategy->getName($context);
$directory = $this->storageStrategy->getDirectory($context, $name);
$path = $directory . '/' . $name;
$adapter = $this->filesystem->getAdapter();
if ($adapter instanceof MetadataSupporter) {
$adapter->setMetadata($path, $this->resolveMetadataMap($context, $metadataMap));
}
$this->filesystem->write($path, $content);
$file = $this->filesystem->get($path);
return new UploadedFile($this, $file);
}
示例7: upload
/**
* {@inheritdoc}
*/
public function upload(ImageInterface $image)
{
if (!$image->hasFile()) {
return;
}
if (null !== $image->getPath()) {
$this->remove($image->getPath());
}
do {
$hash = md5(uniqid(mt_rand(), true));
$path = $this->expandPath($hash . '.' . $image->getFile()->guessExtension());
} while ($this->filesystem->has($path));
$image->setPath($path);
$this->filesystem->write($image->getPath(), file_get_contents($image->getFile()->getPathname()));
}
示例8: testWriteThrowsAnExceptionIfTheFileAlreadyExistsAndIsNotAllowedToOverwrite
public function testWriteThrowsAnExceptionIfTheFileAlreadyExistsAndIsNotAllowedToOverwrite()
{
$adapter = new InMemory(array('myFile' => array()));
$fs = new Filesystem($adapter);
$this->setExpectedException('InvalidArgumentException');
$fs->write('myFile', 'some text');
}
示例9: 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;
}
示例10: 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');
}
示例11: shouldWorkWithHiddenFiles
/**
* @test
* @group functional
*/
public function shouldWorkWithHiddenFiles()
{
$this->filesystem->write('.foo', 'hidden');
$this->assertTrue($this->filesystem->has('.foo'));
$this->assertContains('.foo', $this->filesystem->keys());
$this->filesystem->delete('.foo');
$this->assertFalse($this->filesystem->has('.foo'));
}
示例12: run
/**
* Retrieve information about artist (TopAlbum and track of album)
*/
public function run()
{
$result = $this->serviceArtistInfo->setArtist($this->artistName)->getResults();
if (!isset($result->error)) {
$artist = new Artist();
$artist->setName($this->artistName)->setInfo($result->artist->bio->summary);
if (!is_array($result->artist->tags->tag)) {
$tags = array($result->artist->tags->tag);
} else {
$tags = $result->artist->tags->tag;
}
foreach ($tags as $tagResult) {
$tag = new ArtistTagDocument();
$tag->setName($tagResult->name);
$artist->addTag($tag);
}
$albumResult = $this->serviceArtistAlbum->setArtist($this->artistName)->getResults();
if (!isset($albumResult->error)) {
if (!is_array($albumResult->topalbums->album)) {
$albums = array($albumResult->topalbums->album);
} else {
$albums = $albumResult->topalbums->album;
}
foreach ($albums as $albumResult) {
$album = new ArtistAlbumDocument();
$album->setName($albumResult->name)->setMbid($albumResult->mbid);
if (is_array($albumResult->image)) {
$image = $albumResult->image[count($albumResult->image) - 1];
$var = '#text';
if ('' !== $image->{$var}) {
$fileName = substr($image->{$var}, strrpos($image->{$var}, '/'));
$this->fileSystem->write($fileName, file_get_contents($image->{$var}));
$album->setImage($fileName);
}
}
if ($albumResult->mbid) {
$albumInfoResult = $this->serviceAlbumInfo->setArtist($this->artistName)->setMbid($albumResult->mbid)->getResults();
if (!isset($albumInfoResult->error)) {
if (!is_array($albumInfoResult->album->tracks->track)) {
$tracks = array($albumInfoResult->album->tracks->track);
} else {
$tracks = $albumInfoResult->album->tracks->track;
}
foreach ($tracks as $trackResult) {
$track = new ArtistTrackDocument();
$track->setName($trackResult->name)->setDuration($trackResult->duration);
$album->addTrack($track);
}
}
$artist->addAlbum($album);
}
}
}
$this->artistQuery->persist($artist);
}
}
示例13: upload
/**
* {@inheritdoc}
*/
public function upload(MediaInterface $media, $name = null, $test = false)
{
if (!$media->hasMedia()) {
return;
}
if (null !== $media->getName()) {
$this->remove($media->getName());
}
do {
$hash = md5(uniqid(mt_rand(), true));
if ($test === false) {
$name = $hash . '.' . $media->getMedia()->guessExtension();
}
} while ($this->filesystem->has($name));
$media->setName($name);
if ($test === false) {
$this->filesystem->write($media->getName(), file_get_contents($media->getMedia()->getPathname()));
}
}
示例14: 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);
}
示例15: shouldFetchKeys
/**
* @test
* @group functional
*/
public function shouldFetchKeys()
{
$this->assertEquals(array(), $this->filesystem->keys());
$this->filesystem->write('foo', 'Some content');
$this->filesystem->write('bar', 'Some content');
$this->filesystem->write('baz', 'Some content');
$actualKeys = $this->filesystem->keys();
$this->assertEquals(3, count($actualKeys));
foreach (array('foo', 'bar', 'baz') as $key) {
$this->assertContains($key, $actualKeys);
}
}