本文整理汇总了PHP中Gaufrette\Filesystem::has方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::has方法的具体用法?PHP Filesystem::has怎么用?PHP Filesystem::has使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gaufrette\Filesystem
的用法示例。
在下文中一共展示了Filesystem::has方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: preUpload
/**
* Update attachment entity before upload
*
* @param File $entity
*/
public function preUpload(File $entity)
{
if ($entity->isEmptyFile()) {
if ($this->filesystem->has($entity->getFilename())) {
$this->filesystem->delete($entity->getFilename());
}
$entity->setFilename(null);
$entity->setExtension(null);
$entity->setOriginalFilename(null);
}
if ($entity->getFile() !== null && $entity->getFile()->isFile()) {
$entity->setOwner($this->securityFacadeLink->getService()->getLoggedUser());
$file = $entity->getFile();
if ($entity->getFilename() !== null && $this->filesystem->has($entity->getFilename())) {
$this->filesystem->delete($entity->getFilename());
}
$entity->setExtension($file->guessExtension());
if ($file instanceof UploadedFile) {
$entity->setOriginalFilename($file->getClientOriginalName());
$entity->setMimeType($file->getClientMimeType());
$entity->setFileSize($file->getClientSize());
} else {
$entity->setOriginalFilename($file->getFileName());
$entity->setMimeType($file->getMimeType());
$entity->setFileSize($file->getSize());
}
$entity->setFilename(uniqid() . '.' . $entity->getExtension());
if ($this->filesystem->getAdapter() instanceof MetadataSupporter) {
$this->filesystem->getAdapter()->setMetadata($entity->getFilename(), ['contentType' => $entity->getMimeType()]);
}
}
}
示例4: 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);
}
示例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: 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()));
}
示例7: 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);
}
示例8: shouldDeleteFile
/**
* @test
* @group functional
*/
public function shouldDeleteFile()
{
$this->filesystem->write('foo', 'Some content');
$this->assertTrue($this->filesystem->has('foo'));
$this->filesystem->delete('foo');
$this->assertFalse($this->filesystem->has('foo'));
}
示例9: fileExists
/**
* Predicate to know if file exists physically
*
* @param ProductMediaInterface $media
*
* @return bool
*/
protected function fileExists(ProductMediaInterface $media)
{
if (null === $media->getFilename()) {
return false;
}
return $this->filesystem->has($media->getFilename());
}
示例10: read
private function read(Filesystem $fs)
{
$profileFilename = Application::PROFILE_FILENAME;
if ($fs->has($profileFilename)) {
$this->processProfileContent($fs->read($profileFilename));
}
}
示例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: 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()));
}
}
示例13:
function it_uploads_without_removing(MediaInterface $media, Filesystem $filesystem, UploadedFile $file)
{
$media->hasMedia()->shouldBeCalled()->willReturn(true);
$media->getName()->shouldBeCalled()->willReturn(null);
$media->getMedia()->shouldBeCalled()->willReturn($file);
$file->guessExtension()->shouldBeCalled()->willReturn('md');
$filesystem->has(Argument::containingString('.md'))->shouldBeCalled()->willReturn(false);
$media->setName(Argument::any())->shouldBeCalled()->willReturn($media);
$media->getMedia()->shouldBeCalled()->willReturn($file);
$file->getPathname()->shouldBeCalled()->willReturn(__DIR__ . '/../../../../../README.md');
$filesystem->write(Argument::any(), file_get_contents(__DIR__ . '/../../../../../README.md'))->shouldBeCalled()->willReturn(Argument::type('int'));
$this->upload($media);
}
示例14: cleanup
public function cleanup(UserProfile $prop)
{
if ($prop->getProperty()->getFieldType() === ProfileProperty::TYPE_FILE) {
/*$fileName = str_replace($this->getBaseFileUrl() . '/', '', $prop->getPropertyValue());
if ( is_file($this->getBaseFilePath() . '/' . $fileName) ) {
echo 'maybe removing ' . $this->getBaseFilePath() . '/' . $fileName;
@unlink($this->getBaseFilePath() . '/' . $fileName);
}*/
$fileKey = AbstractUploader::extractKey($prop->getPropertyValue(), $this->awsBucket);
if ($fileKey && $this->filesystem->has($fileKey)) {
$this->filesystem->delete($fileKey);
}
}
}
示例15: has
public function has($id)
{
return $this->filesystem->has($id);
}