code
stringlengths
31
1.39M
docstring
stringlengths
23
16.8k
func_name
stringlengths
1
126
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
166
url
stringlengths
50
220
license
stringclasses
7 values
public function __invoke(Request $request, $id, string $format = MediaProviderInterface::FORMAT_REFERENCE): Response { $media = $this->mediaManager->find($id); if (null === $media) { throw new NotFoundHttpException(\sprintf('unable to find the media with the id : %s', $id)); } if (!$this->pool->getDownloadStrategy($media)->isGranted($media, $request)) { throw new AccessDeniedException(); } $response = $this->pool->getProvider($media->getProviderName())->getDownloadResponse( $media, $format, $this->pool->getDownloadMode($media) ); if ($response instanceof BinaryFileResponse) { $response->prepare($request); } return $response; }
@param int|string $id @throws NotFoundHttpException @throws AccessDeniedException
__invoke
php
sonata-project/SonataMediaBundle
src/Action/MediaDownloadAction.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Action/MediaDownloadAction.php
MIT
public function __construct( $pool, $categoryManager = null, $contextManager = null, ?Pool $deprecatedPool = null, ?CategoryManagerInterface $deprecatedCategoryManager = null, ?ContextManagerInterface $deprecatedContextManager = null, ) { // NEXT_MAJOR: Keep the if part. if ($pool instanceof Pool) { \assert(!\is_string($categoryManager)); \assert(!\is_string($contextManager)); parent::__construct(); $this->pool = $pool; $this->categoryManager = $categoryManager; $this->contextManager = $contextManager; } else { \assert(\is_string($categoryManager)); \assert(\is_string($contextManager)); \assert(null !== $deprecatedPool); parent::__construct($pool, $categoryManager, $contextManager); $this->pool = $deprecatedPool; $this->categoryManager = $deprecatedCategoryManager; $this->contextManager = $deprecatedContextManager; } }
NEXT_MAJOR: Change to (Pool, ?CategoryManagerInterface, ?ContextManagerInterface). @param Pool|string $pool @param CategoryManagerInterface|string|null $categoryManager @param ContextManagerInterface|string|null $contextManager @phpstan-param CategoryManagerInterface|class-string<MediaInterface>|null $categoryManager
__construct
php
sonata-project/SonataMediaBundle
src/Admin/BaseMediaAdmin.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Admin/BaseMediaAdmin.php
MIT
public function __construct( Environment $twig, private Pool $pool, private ?AdminInterface $galleryAdmin, private GalleryManagerInterface $galleryManager, ) { parent::__construct($twig); }
@param AdminInterface<GalleryInterface<GalleryItemInterface>>|null $galleryAdmin
__construct
php
sonata-project/SonataMediaBundle
src/Block/GalleryBlockService.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Block/GalleryBlockService.php
MIT
private function buildElements(GalleryInterface $gallery): array { $elements = []; foreach ($gallery->getGalleryItems() as $galleryItem) { if (!$galleryItem->getEnabled()) { continue; } $media = $galleryItem->getMedia(); if (null === $media) { continue; } $type = $this->getMediaType($media); if (null === $type) { continue; } $elements[] = [ 'title' => $media->getName(), 'caption' => $media->getDescription(), 'type' => $type, 'media' => $media, ]; } return $elements; }
@return array<string, MediaInterface|string|null> @phpstan-param GalleryInterface<GalleryItemInterface> $gallery @phpstan-return array{ title: string|null, caption: string|null, type: string, media: MediaInterface }[]
buildElements
php
sonata-project/SonataMediaBundle
src/Block/GalleryBlockService.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Block/GalleryBlockService.php
MIT
public function flushPaths(array $paths): string { if ([] === $paths) { throw new \RuntimeException('Unable to flush : expected at least one path'); } // Normalizes paths due possible typos since all the CloudFront's // objects starts with a leading slash $normalizedPaths = array_map( static fn (string $path): string => '/'.ltrim($path, '/'), $paths ); try { $result = $this->client->createInvalidation([ 'DistributionId' => $this->distributionId, 'InvalidationBatch' => [ 'Paths' => [ 'Quantity' => \count($normalizedPaths), 'Items' => $normalizedPaths, ], 'CallerReference' => $this->getCallerReference(), ], ]); $invalidation = $result->get('Invalidation'); \assert(\is_array($invalidation)); $status = $invalidation['Status'] ?? null; if (null === $status) { throw new \RuntimeException('Unable to find the flush status from the given response.'); } if (!\in_array($status, self::AVAILABLE_STATUSES, true)) { throw new \RuntimeException(\sprintf('Unable to determine the flush status from the given response: "%s".', $status)); } $id = $invalidation['Id'] ?? null; if (null === $id) { throw new \RuntimeException('Unable to determine the flush id from the given response.'); } return $id; } catch (CloudFrontException $ex) { throw new \RuntimeException(\sprintf('Unable to flush paths "%s".', implode('", "', $paths)), 0, $ex); } }
@see https://docs.aws.amazon.com/aws-sdk-php/latest/class-Aws.CloudFront.CloudFrontClient.html#_createInvalidation
flushPaths
php
sonata-project/SonataMediaBundle
src/CDN/CloudFrontVersion3.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/CDN/CloudFrontVersion3.php
MIT
private function getCallerReference(): string { return (string) time(); }
Generates a caller reference. @see https://docs.aws.amazon.com/cloudfront/latest/APIReference/API_InvalidationBatch.html.
getCallerReference
php
sonata-project/SonataMediaBundle
src/CDN/CloudFrontVersion3.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/CDN/CloudFrontVersion3.php
MIT
public function __construct(private MediaManagerInterface $mediaManager) { parent::__construct(); }
@internal This class should only be used through the console
__construct
php
sonata-project/SonataMediaBundle
src/Command/AddMassMediaCommand.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Command/AddMassMediaCommand.php
MIT
public function __construct(private MediaManagerInterface $mediaManager) { parent::__construct(); }
@internal This class should only be used through the console
__construct
php
sonata-project/SonataMediaBundle
src/Command/AddMediaCommand.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Command/AddMediaCommand.php
MIT
public function __construct( private Local $filesystemLocal, private Pool $mediaPool, private MediaManagerInterface $mediaManager, ) { parent::__construct(); }
@internal This class should only be used through the console
__construct
php
sonata-project/SonataMediaBundle
src/Command/CleanMediaCommand.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Command/CleanMediaCommand.php
MIT
public function __construct( private Pool $mediaPool, private ?CategoryManagerInterface $categoryManager = null, private ?ContextManagerInterface $contextManager = null, ) { parent::__construct(); }
@internal This class should only be used through the console
__construct
php
sonata-project/SonataMediaBundle
src/Command/FixMediaContextCommand.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Command/FixMediaContextCommand.php
MIT
public function __construct( private Pool $mediaPool, private MediaManagerInterface $mediaManager, ) { parent::__construct(); }
@internal This class should only be used through the console
__construct
php
sonata-project/SonataMediaBundle
src/Command/RefreshMetadataCommand.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Command/RefreshMetadataCommand.php
MIT
public function __construct( private Pool $mediaPool, private MediaManagerInterface $mediaManager, ) { parent::__construct(); }
@internal This class should only be used through the console
__construct
php
sonata-project/SonataMediaBundle
src/Command/RemoveThumbsCommand.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Command/RemoveThumbsCommand.php
MIT
public function __construct( private Pool $mediaPool, private MediaManagerInterface $mediaManager, ) { parent::__construct(); }
@internal This class should only be used through the console
__construct
php
sonata-project/SonataMediaBundle
src/Command/SyncThumbsCommand.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Command/SyncThumbsCommand.php
MIT
public function __construct( private Pool $mediaPool, private MediaManagerInterface $mediaManager, ) { parent::__construct(); }
@internal This class should only be used through the console
__construct
php
sonata-project/SonataMediaBundle
src/Command/UpdateCdnStatusCommand.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Command/UpdateCdnStatusCommand.php
MIT
public function listAction(Request $request): Response { $this->assertObjectExists($request); $this->admin->checkAccess('list'); $preResponse = $this->preList($request); if (null !== $preResponse) { return $preResponse; } $listMode = $request->query->get('_list_mode'); if (\is_string($listMode)) { $this->admin->setListMode($listMode); } $datagrid = $this->admin->getDatagrid(); $datagrid->setValue('context', null, $this->admin->getPersistentParameter('context')); $formView = $datagrid->getForm()->createView(); $this->setFormTheme($formView, $this->admin->getFilterTheme()); if ($this->container->has('sonata.admin.admin_exporter')) { $exporter = $this->container->get('sonata.admin.admin_exporter'); \assert($exporter instanceof AdminExporter); $exportFormats = $exporter->getAvailableFormats($this->admin); } return $this->render($this->admin->getTemplateRegistry()->getTemplate('list'), [ 'action' => 'list', 'form' => $formView, 'datagrid' => $datagrid, 'csrf_token' => $this->getCsrfToken('sonata.batch'), 'export_formats' => $exportFormats ?? $this->admin->getExportFormats(), ]); }
return the Response object associated to the list action.
listAction
php
sonata-project/SonataMediaBundle
src/Controller/GalleryAdminController.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Controller/GalleryAdminController.php
MIT
public function configureCdnAdapter(ContainerBuilder $container, array $config): void { // add the default configuration for the server cdn if ($container->hasDefinition('sonata.media.cdn.server') && isset($config['cdn']['server'])) { $container->getDefinition('sonata.media.cdn.server') ->replaceArgument(0, $config['cdn']['server']['path']); } else { $container->removeDefinition('sonata.media.cdn.server'); } if ($container->hasDefinition('sonata.media.cdn.cloudfront') && isset($config['cdn']['cloudfront'])) { $cloudFrontConfig = []; if (isset($config['cdn']['cloudfront']['region'])) { $cloudFrontConfig['region'] = $config['cdn']['cloudfront']['region']; } if (isset($config['cdn']['cloudfront']['version'])) { $cloudFrontConfig['version'] = $config['cdn']['cloudfront']['version']; } $cloudFrontConfig['credentials'] = [ 'key' => $config['cdn']['cloudfront']['key'], 'secret' => $config['cdn']['cloudfront']['secret'], ]; $container->getDefinition('sonata.media.cdn.cloudfront.client') ->replaceArgument(0, $cloudFrontConfig); $container->getDefinition('sonata.media.cdn.cloudfront') ->replaceArgument(0, new Reference('sonata.media.cdn.cloudfront.client')) ->replaceArgument(1, $config['cdn']['cloudfront']['distribution_id']) ->replaceArgument(2, $config['cdn']['cloudfront']['path']); } else { $container->removeDefinition('sonata.media.cdn.cloudfront.client'); $container->removeDefinition('sonata.media.cdn.cloudfront'); } if ($container->hasDefinition('sonata.media.cdn.fallback') && isset($config['cdn']['fallback'])) { $container->getDefinition('sonata.media.cdn.fallback') ->replaceArgument(0, new Reference($config['cdn']['fallback']['primary'])) ->replaceArgument(1, new Reference($config['cdn']['fallback']['fallback'])); } else { $container->removeDefinition('sonata.media.cdn.fallback'); } }
Inject CDN dependency to default provider. @param array<string, mixed> $config
configureCdnAdapter
php
sonata-project/SonataMediaBundle
src/DependencyInjection/SonataMediaExtension.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/DependencyInjection/SonataMediaExtension.php
MIT
public function configureFilesystemAdapter(ContainerBuilder $container, array $config): void { // add the default configuration for the local filesystem if ($container->hasDefinition('sonata.media.adapter.filesystem.local') && isset($config['filesystem']['local'])) { $container->getDefinition('sonata.media.adapter.filesystem.local') ->addArgument($config['filesystem']['local']['directory']) ->addArgument($config['filesystem']['local']['create']); } else { $container->removeDefinition('sonata.media.adapter.filesystem.local'); } // add the default configuration for the FTP filesystem if ($container->hasDefinition('sonata.media.adapter.filesystem.ftp') && isset($config['filesystem']['ftp'])) { $container->getDefinition('sonata.media.adapter.filesystem.ftp') ->addArgument($config['filesystem']['ftp']['directory']) ->addArgument($config['filesystem']['ftp']['host']) ->addArgument([ 'port' => $config['filesystem']['ftp']['port'], 'username' => $config['filesystem']['ftp']['username'], 'password' => $config['filesystem']['ftp']['password'], 'passive' => $config['filesystem']['ftp']['passive'], 'create' => $config['filesystem']['ftp']['create'], 'mode' => $config['filesystem']['ftp']['mode'], ]); } else { $container->removeDefinition('sonata.media.adapter.filesystem.ftp'); $container->removeDefinition('sonata.media.filesystem.ftp'); } // add the default configuration for the S3 filesystem if ($container->hasDefinition('sonata.media.adapter.filesystem.s3') && isset($config['filesystem']['s3'])) { $async = true === $config['filesystem']['s3']['async']; if ($async && !class_exists(SimpleS3Client::class)) { throw new \RuntimeException('You must install "async-aws/simple-s3" to use async S3 adapter'); } if (!$async && !class_exists(S3Client::class)) { throw new \RuntimeException('You must install "aws/aws-sdk-php" to use Amazon S3 filesystem'); } $adapterClass = $async ? AsyncAwsS3::class : AwsS3::class; $clientReference = new Reference( $async ? 'sonata.media.adapter.service.s3.async' : 'sonata.media.adapter.service.s3' ); $container->getDefinition('sonata.media.adapter.filesystem.s3') ->setClass($adapterClass) ->replaceArgument(0, $clientReference) ->replaceArgument(1, $config['filesystem']['s3']['bucket']) ->replaceArgument(2, ['create' => $config['filesystem']['s3']['create'], 'region' => $config['filesystem']['s3']['region'], 'directory' => $config['filesystem']['s3']['directory'], 'ACL' => $config['filesystem']['s3']['acl']]); $container->getDefinition('sonata.media.metadata.amazon') ->replaceArgument(0, [ 'acl' => $config['filesystem']['s3']['acl'], 'storage' => $config['filesystem']['s3']['storage'], 'encryption' => $config['filesystem']['s3']['encryption'], 'meta' => $config['filesystem']['s3']['meta'], 'cache_control' => $config['filesystem']['s3']['cache_control'], ]); $arguments = [ 'region' => $config['filesystem']['s3']['region'], 'version' => $config['filesystem']['s3']['version'], ]; if (isset($config['filesystem']['s3']['endpoint'])) { $arguments['endpoint'] = $config['filesystem']['s3']['endpoint']; } if (isset($config['filesystem']['s3']['secretKey'], $config['filesystem']['s3']['accessKey'])) { $arguments['credentials'] = [ 'secret' => $config['filesystem']['s3']['secretKey'], 'key' => $config['filesystem']['s3']['accessKey'], ]; } $container->getDefinition('sonata.media.adapter.service.s3') ->replaceArgument(0, $arguments); if ($async) { if (isset($arguments['credentials']['key'], $arguments['credentials']['secret'])) { $arguments['accessKeyId'] = $arguments['credentials']['key']; $arguments['accessKeySecret'] = $arguments['credentials']['secret']; unset($arguments['credentials']); } unset($arguments['version']); $container->getDefinition('sonata.media.adapter.service.s3.async') ->replaceArgument(0, $arguments); } } else { $container->removeDefinition('sonata.media.adapter.filesystem.s3'); $container->removeDefinition('sonata.media.filesystem.s3'); $container->removeDefinition('sonata.media.metadata.amazon'); } if ($container->hasDefinition('sonata.media.adapter.filesystem.replicate') && isset($config['filesystem']['replicate'])) { $container->getDefinition('sonata.media.adapter.filesystem.replicate') ->replaceArgument(0, new Reference($config['filesystem']['replicate']['primary'])) ->replaceArgument(1, new Reference($config['filesystem']['replicate']['secondary'])); } else { $container->removeDefinition('sonata.media.adapter.filesystem.replicate'); $container->removeDefinition('sonata.media.filesystem.replicate'); } }
Inject filesystem dependency to default provider. @param array<string, mixed> $config
configureFilesystemAdapter
php
sonata-project/SonataMediaBundle
src/DependencyInjection/SonataMediaExtension.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/DependencyInjection/SonataMediaExtension.php
MIT
public function prepend(ContainerBuilder $container): void { $bundles = $container->getParameter('kernel.bundles'); \assert(\is_array($bundles)); // Store SonataAdminBundle configuration for later use if (!isset($bundles['SonataAdminBundle'])) { return; } $sonataAdminConfig = current($container->getExtensionConfig('sonata_admin')); if (false === $sonataAdminConfig) { return; } $this->sonataAdminConfig = $sonataAdminConfig; }
Allow an extension to prepend the extension configurations.
prepend
php
sonata-project/SonataMediaBundle
src/DependencyInjection/SonataMediaExtension.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/DependencyInjection/SonataMediaExtension.php
MIT
private function isClassificationEnabled(array $bundles, array $config): bool { \assert(\is_bool($config['force_disable_category'])); return isset($bundles['SonataClassificationBundle']) && !$config['force_disable_category']; }
Checks if the classification of media is enabled. @param array<string, string> $bundles @param array<string, mixed> $config @phpstan-param array<string, class-string> $bundles
isClassificationEnabled
php
sonata-project/SonataMediaBundle
src/DependencyInjection/SonataMediaExtension.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/DependencyInjection/SonataMediaExtension.php
MIT
private function registerSonataDoctrineMapping(array $bundles, array $config): void { $collector = DoctrineCollector::getInstance(); $collector->addAssociation( $config['class']['media'], 'mapOneToMany', OptionsBuilder::createOneToMany('galleryItems', $config['class']['gallery_item']) ->cascade(['persist']) ->mappedBy('media') ); $collector->addAssociation( $config['class']['gallery_item'], 'mapManyToOne', OptionsBuilder::createManyToOne('gallery', $config['class']['gallery']) ->cascade(['persist']) ->inversedBy('galleryItems') ->addJoin([ 'name' => 'gallery_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE', ]) ); $collector->addAssociation( $config['class']['gallery_item'], 'mapManyToOne', OptionsBuilder::createManyToOne('media', $config['class']['media']) ->cascade(['persist']) ->inversedBy('galleryItems') ->addJoin([ 'name' => 'media_id', 'referencedColumnName' => 'id', 'onDelete' => 'CASCADE', ]) ); $collector->addAssociation( $config['class']['gallery'], 'mapOneToMany', OptionsBuilder::createOneToMany('galleryItems', $config['class']['gallery_item']) ->cascade(['persist']) ->mappedBy('gallery') ->orphanRemoval() ->addOrder('position', 'ASC') ); if ($this->isClassificationEnabled($bundles, $config)) { $collector->addAssociation( $config['class']['media'], 'mapManyToOne', OptionsBuilder::createManyToOne('category', $config['class']['category']) ->cascade(['persist']) ->addJoin([ 'name' => 'category_id', 'referencedColumnName' => 'id', 'onDelete' => 'SET NULL', ]) ); } }
@param array<string, string> $bundles @param array<string, mixed> $config @phpstan-param array<string, class-string> $bundles
registerSonataDoctrineMapping
php
sonata-project/SonataMediaBundle
src/DependencyInjection/SonataMediaExtension.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/DependencyInjection/SonataMediaExtension.php
MIT
private function registerMessengerConfiguration(ContainerBuilder $container, array $config, PhpFileLoader $loader): void { if (!interface_exists(MessageBusInterface::class)) { throw new \LogicException('Messenger support cannot be enabled as the Messenger component is not installed. Try running "composer require symfony/messenger".'); } $loader->load('messenger.php'); $container->setAlias('sonata.media.messenger.generate_thumbnails_bus', $config['generate_thumbnails_bus']); }
@param array<string, string> $config @phpstan-param array{generate_thumbnails_bus: string} $config
registerMessengerConfiguration
php
sonata-project/SonataMediaBundle
src/DependencyInjection/SonataMediaExtension.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/DependencyInjection/SonataMediaExtension.php
MIT
private function applyFormats(ContainerBuilder $container, array $config): void { foreach ($config['contexts'] as $name => $context) { // add the different related formats foreach ($context['providers'] as $id) { $definition = $container->getDefinition($id); foreach ($context['formats'] as $format => $formatConfig) { $definition->addMethodCall('addFormat', [\sprintf('%s_%s', $name, $format), $formatConfig]); } } } }
Define the default settings to the config array. @param array<string, mixed> $config
applyFormats
php
sonata-project/SonataMediaBundle
src/DependencyInjection/Compiler/AddProviderCompilerPass.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/DependencyInjection/Compiler/AddProviderCompilerPass.php
MIT
public function mtime($key) { return $this->primary->mtime($key); }
@param string $key @return int|bool
mtime
php
sonata-project/SonataMediaBundle
src/Filesystem/Replicate.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Filesystem/Replicate.php
MIT
public function write($key, $content) { $ok = true; $return = false; try { $return = $this->primary->write($key, $content); } catch (\Exception $e) { $this->logger->critical(\sprintf('Unable to write %s, error: %s', $key, $e->getMessage())); $ok = false; } try { $return = $this->secondary->write($key, $content); } catch (\Exception $e) { $this->logger->critical(\sprintf('Unable to write %s, error: %s', $key, $e->getMessage())); $ok = false; } return $ok && false !== $return; }
@param string $key @param string $content @return bool
write
php
sonata-project/SonataMediaBundle
src/Filesystem/Replicate.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Filesystem/Replicate.php
MIT
public function read($key) { return $this->primary->read($key); }
@param string $key @return string|bool
read
php
sonata-project/SonataMediaBundle
src/Filesystem/Replicate.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Filesystem/Replicate.php
MIT
public function supportsMetadata(): bool { return $this->primary instanceof MetadataSupporter || $this->secondary instanceof MetadataSupporter; }
If one of the adapters can allow inserting metadata.
supportsMetadata
php
sonata-project/SonataMediaBundle
src/Filesystem/Replicate.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Filesystem/Replicate.php
MIT
public function setMetadata($key, $content): void { if ($this->primary instanceof MetadataSupporter) { $this->primary->setMetadata($key, $content); } if ($this->secondary instanceof MetadataSupporter) { $this->secondary->setMetadata($key, $content); } }
@param string $key @param mixed[] $content
setMetadata
php
sonata-project/SonataMediaBundle
src/Filesystem/Replicate.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Filesystem/Replicate.php
MIT
public function getAdapterClassNames(): array { return [ $this->primary::class, $this->secondary::class, ]; }
Gets the class names as an array for both adapters. @return string[] @phpstan-return class-string<Adapter>[]
getAdapterClassNames
php
sonata-project/SonataMediaBundle
src/Filesystem/Replicate.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Filesystem/Replicate.php
MIT
public function listDirectory(string $directory = ''): array { if (!method_exists($this->primary, 'listDirectory')) { throw new \BadMethodCallException(\sprintf( 'Method "%s()" is not supported by the primary adapter "%s".', __METHOD__, $this->primary::class )); } return $this->primary->listDirectory($directory); }
@return array<string, string[]> @phpstan-return array{keys: string[], dirs: string[]}
listDirectory
php
sonata-project/SonataMediaBundle
src/Filesystem/Replicate.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Filesystem/Replicate.php
MIT
public function __construct( private Pool $pool, private string $class, array $options = [], ) { $this->options = $this->getOptions($options); }
@param array<string, mixed> $options @phpstan-param class-string<MediaInterface> $class
__construct
php
sonata-project/SonataMediaBundle
src/Form/DataTransformer/ProviderDataTransformer.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Form/DataTransformer/ProviderDataTransformer.php
MIT
#[\ReturnTypeWillChange] public function transform($value): mixed { if (null === $value) { return new $this->class(); } if (!$value instanceof MediaInterface) { return null; } return $value; }
@param mixed $value @phpstan-param MediaInterface|null $value @phpstan-return MediaInterface|null
transform
php
sonata-project/SonataMediaBundle
src/Form/DataTransformer/ProviderDataTransformer.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Form/DataTransformer/ProviderDataTransformer.php
MIT
#[\ReturnTypeWillChange] public function reverseTransform($value): mixed { if (!$value instanceof MediaInterface) { return null; } $binaryContent = $value->getBinaryContent(); // no binary if (null === $binaryContent) { // and no media id if (null === $value->getId() && true === $this->options['empty_on_new']) { return null; } if (null !== $value->getId()) { return $value; } $value->setProviderStatus(MediaInterface::STATUS_PENDING); $value->setProviderReference(MediaInterface::MISSING_BINARY_REFERENCE); return $value; } // create a new media to avoid erasing other media or not ... $newMedia = true === $this->options['new_on_update'] ? new $this->class() : $value; $newMedia->setProviderName($value->getProviderName()); $newMedia->setContext($value->getContext()); $newMedia->setBinaryContent($binaryContent); if (null === $newMedia->getProviderName() && false !== $this->options['provider']) { $newMedia->setProviderName($this->options['provider']); } if (null === $newMedia->getContext() && false !== $this->options['context']) { $newMedia->setContext($this->options['context']); } $provider = $this->pool->getProvider($newMedia->getProviderName()); try { $provider->transform($newMedia); } catch (\Throwable $e) { throw new TransformationFailedException($e->getMessage(), 0, $e, $e->getMessage()); } return $newMedia; }
@param mixed $value @throws TransformationFailedException when the transformation fails @phpstan-param MediaInterface|null $value @phpstan-return MediaInterface|null
reverseTransform
php
sonata-project/SonataMediaBundle
src/Form/DataTransformer/ProviderDataTransformer.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Form/DataTransformer/ProviderDataTransformer.php
MIT
private function getOptions(array $options) { return array_merge([ 'provider' => false, 'context' => false, 'empty_on_new' => true, 'new_on_update' => true, ], $options); }
Define the default options for the DataTransformer. @param array<string, mixed> $options @return array<string, mixed>
getOptions
php
sonata-project/SonataMediaBundle
src/Form/DataTransformer/ProviderDataTransformer.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Form/DataTransformer/ProviderDataTransformer.php
MIT
public function __construct( private Pool $pool, private string $class, ) { }
@phpstan-param class-string<MediaInterface> $class
__construct
php
sonata-project/SonataMediaBundle
src/Form/Type/MediaType.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Form/Type/MediaType.php
MIT
public function __construct( private array $settings, private MimeTypesInterface $mimeTypes = new MimeTypes(), ) { }
@param array<string, mixed> $settings @phpstan-param AmazonSettings $settings
__construct
php
sonata-project/SonataMediaBundle
src/Metadata/AmazonMetadataBuilder.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Metadata/AmazonMetadataBuilder.php
MIT
private function getDefaultMetadata(): array { return [ 'ACL' => self::ACL[$this->settings['acl']], 'storage' => self::STORAGE[$this->settings['storage']], 'meta' => $this->settings['meta'], 'CacheControl' => $this->settings['cache_control'], 'encryption' => 'AES256', ]; }
Get data passed from the config. @return array<string, array|string> @phpstan-return array{ ACL: self::PRIVATE_ACCESS|self::PUBLIC_READ|self::PUBLIC_READ_WRITE|self::AUTHENTICATED_READ|self::BUCKET_OWNER_READ|self::BUCKET_OWNER_FULL_CONTROL, storage: self::STORAGE_STANDARD|self::STORAGE_REDUCED, meta: array<string, mixed>, CacheControl: string, encryption: 'AES256' }
getDefaultMetadata
php
sonata-project/SonataMediaBundle
src/Metadata/AmazonMetadataBuilder.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Metadata/AmazonMetadataBuilder.php
MIT
private function getContentType(string $filename): array { $ext = pathinfo($filename, \PATHINFO_EXTENSION); $mimeTypes = $this->mimeTypes->getMimeTypes($ext); $mimeType = current($mimeTypes); if (false === $mimeType) { throw new \RuntimeException(\sprintf('Unable to determine the mime type for file %s', $filename)); } return ['contentType' => $mimeType]; }
Gets the correct content-type. @return array<string, string> @phpstan-return array{contentType: string}
getContentType
php
sonata-project/SonataMediaBundle
src/Metadata/AmazonMetadataBuilder.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Metadata/AmazonMetadataBuilder.php
MIT
private function getContentLength(MediaInterface $media): array { $size = $media->getSize(); if ($size > 0) { return ['contentLength' => $size]; } return []; }
@return array<string, int> @phpstan-return array{contentLength?: int}
getContentLength
php
sonata-project/SonataMediaBundle
src/Metadata/AmazonMetadataBuilder.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Metadata/AmazonMetadataBuilder.php
MIT
public function reorderGalleryItems(): void { $iterator = $this->getGalleryItems()->getIterator(); if (!$iterator instanceof \ArrayIterator) { throw new \RuntimeException(\sprintf( 'The gallery %s cannot be reordered, $galleryItems should implement %s', $this->getId() ?? '', \ArrayIterator::class )); } $iterator->uasort( static fn (GalleryItemInterface $a, GalleryItemInterface $b): int => $a->getPosition() <=> $b->getPosition() ); $this->setGalleryItems($iterator); }
@psalm-suppress RedundantCondition https://github.com/vimeo/psalm/issues/9449
reorderGalleryItems
php
sonata-project/SonataMediaBundle
src/Model/Gallery.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Model/Gallery.php
MIT
public function findOneBy(array $criteria, ?array $orderBy = null): ?object { throw new NoDriverException(); }
TODO: Remove $orderBy param with the drop of sonata-project/doctrine-extensions < 2. @param array<string, string>|null $orderBy @return GalleryInterface<GalleryItemInterface>|null
findOneBy
php
sonata-project/SonataMediaBundle
src/Model/NoDriverGalleryManager.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Model/NoDriverGalleryManager.php
MIT
public function save($entity, $andFlush = true): void { throw new NoDriverException(); }
TODO: Add typehint with the drop of sonata-project/doctrine-extensions < 2. @param GalleryInterface<GalleryItemInterface> $entity @param bool $andFlush
save
php
sonata-project/SonataMediaBundle
src/Model/NoDriverGalleryManager.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Model/NoDriverGalleryManager.php
MIT
public function delete($entity, $andFlush = true): void { throw new NoDriverException(); }
TODO: Add typehint with the drop of sonata-project/doctrine-extensions < 2. @param GalleryInterface<GalleryItemInterface> $entity @param bool $andFlush
delete
php
sonata-project/SonataMediaBundle
src/Model/NoDriverGalleryManager.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Model/NoDriverGalleryManager.php
MIT
public function getConnection(): never { throw new NoDriverException(); }
TODO: Remove this with the drop of sonata-project/doctrine-extensions < 2.
getConnection
php
sonata-project/SonataMediaBundle
src/Model/NoDriverGalleryManager.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Model/NoDriverGalleryManager.php
MIT
public function findOneBy(array $criteria, ?array $orderBy = null): ?object { throw new NoDriverException(); }
TODO: Remove $orderBy param with the drop of sonata-project/doctrine-extensions < 2. @param array<string, string>|null $orderBy @return MediaInterface|null
findOneBy
php
sonata-project/SonataMediaBundle
src/Model/NoDriverMediaManager.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Model/NoDriverMediaManager.php
MIT
public function save($entity, $andFlush = true): void { throw new NoDriverException(); }
TODO: Add typehint with the drop of sonata-project/doctrine-extensions < 2. @param MediaInterface $entity @param bool $andFlush
save
php
sonata-project/SonataMediaBundle
src/Model/NoDriverMediaManager.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Model/NoDriverMediaManager.php
MIT
public function delete($entity, $andFlush = true): void { throw new NoDriverException(); }
TODO: Add typehint with the drop of sonata-project/doctrine-extensions < 2. @param MediaInterface $entity @param bool $andFlush
delete
php
sonata-project/SonataMediaBundle
src/Model/NoDriverMediaManager.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Model/NoDriverMediaManager.php
MIT
public function getConnection(): never { throw new NoDriverException(); }
TODO: Remove this with the drop of sonata-project/doctrine-extensions < 2.
getConnection
php
sonata-project/SonataMediaBundle
src/Model/NoDriverMediaManager.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Model/NoDriverMediaManager.php
MIT
final protected function sendRequest(string $method, string $url): string { return $this->client->sendRequest( $this->requestFactory->createRequest($method, $url) )->getBody()->getContents(); }
Creates an http request and sends it to the server.
sendRequest
php
sonata-project/SonataMediaBundle
src/Provider/BaseVideoProvider.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Provider/BaseVideoProvider.php
MIT
public function __construct( string $name, Filesystem $filesystem, CDNInterface $cdn, GeneratorInterface $pathGenerator, ThumbnailInterface $thumbnail, protected array $allowedExtensions = [], protected array $allowedMimeTypes = [], protected ?MetadataBuilderInterface $metadata = null, ) { parent::__construct($name, $filesystem, $cdn, $pathGenerator, $thumbnail); }
@param string[] $allowedExtensions @param string[] $allowedMimeTypes
__construct
php
sonata-project/SonataMediaBundle
src/Provider/FileProvider.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Provider/FileProvider.php
MIT
protected function setFileContents(MediaInterface $media, ?string $contents = null): void { $providerReference = $media->getProviderReference(); if (null === $providerReference) { throw new \RuntimeException(\sprintf( 'Unable to generate path to file without provider reference for media "%s".', (string) $media )); } $file = $this->getFilesystem()->get( \sprintf('%s/%s', $this->generatePath($media), $providerReference), true ); $metadata = null !== $this->metadata ? $this->metadata->get($media, $file->getName()) : []; if (null !== $contents) { $file->setContent($contents, $metadata); return; } $binaryContent = $media->getBinaryContent(); if ($binaryContent instanceof File) { $path = false !== $binaryContent->getRealPath() ? $binaryContent->getRealPath() : $binaryContent->getPathname(); $fileContents = file_get_contents($path); if (false === $fileContents) { throw new \RuntimeException(\sprintf('Unable to get file contents for media %s', $media->getId() ?? '')); } $file->setContent($fileContents, $metadata); return; } }
Set the file contents for an image.
setFileContents
php
sonata-project/SonataMediaBundle
src/Provider/FileProvider.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Provider/FileProvider.php
MIT
public function addContext(string $name, array $providers = [], array $formats = [], array $download = []): void { if (!$this->hasContext($name)) { $this->contexts[$name] = [ 'providers' => [], 'formats' => [], 'download' => [], ]; } $this->contexts[$name]['providers'] = $providers; $this->contexts[$name]['formats'] = $formats; $this->contexts[$name]['download'] = $download; }
@param string[] $providers @param array<string, array> $formats @param array<string, string> $download @phpstan-param array<string, FormatOptions> $formats @phpstan-param DownloadOptions $download
addContext
php
sonata-project/SonataMediaBundle
src/Provider/Pool.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Provider/Pool.php
MIT
public function getContext(string $name): array { if (!$this->hasContext($name)) { throw new \LogicException(\sprintf('Pool does not have context %s, did you configure all your contexts?', $name)); } return $this->contexts[$name]; }
@throws \LogicException @return array<string, array|string> @phpstan-return array{ providers: string[], formats: array<string, FormatOptions>, download: DownloadOptions }
getContext
php
sonata-project/SonataMediaBundle
src/Provider/Pool.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Provider/Pool.php
MIT
public function getContexts(): array { return $this->contexts; }
Returns the context list. @return array<string, array> @phpstan-return array<string, array{ providers: string[], formats: array<string, FormatOptions>, download: DownloadOptions }>
getContexts
php
sonata-project/SonataMediaBundle
src/Provider/Pool.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Provider/Pool.php
MIT
public function getFormatNamesByContext(string $name): array { return $this->getContext($name)['formats']; }
@return array<string, array> @phpstan-return array<string, FormatOptions>
getFormatNamesByContext
php
sonata-project/SonataMediaBundle
src/Provider/Pool.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Provider/Pool.php
MIT
private function createTargetBox(array $settings): Box { return new Box($settings['width'] ?? 0, $settings['height'] ?? 0); }
@param array<string, int|string|bool|array|null> $settings @phpstan-param FormatOptions $settings
createTargetBox
php
sonata-project/SonataMediaBundle
src/Resizer/CropResizer.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Resizer/CropResizer.php
MIT
private function getExtension(MediaInterface $media): string { $ext = $media->getExtension(); if (!\is_string($ext) || \strlen($ext) < 3) { $ext = $this->defaultFormat; } return $ext; }
Returns the file extension for the $media, or the $defaultExtension if not available.
getExtension
php
sonata-project/SonataMediaBundle
src/Thumbnail/FormatThumbnail.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Thumbnail/FormatThumbnail.php
MIT
public function thumbnail(int|string|MediaInterface $media, string $format, array $options = []): string { $media = $this->getMedia($media); if (null === $media) { return ''; } $provider = $this->pool->getProvider($media->getProviderName()); $format = $provider->getFormatName($media, $format); $formatDefinition = $provider->getFormat($format); $template = $provider->getTemplate('helper_thumbnail'); if (null === $template) { return ''; } // build option $defaultOptions = [ 'title' => $media->getName(), 'alt' => $media->getName(), ]; if (false !== $formatDefinition && isset($formatDefinition['width'])) { $defaultOptions['width'] = $formatDefinition['width']; } if (false !== $formatDefinition && isset($formatDefinition['height'])) { $defaultOptions['height'] = $formatDefinition['height']; } $options = array_merge($defaultOptions, $options); $options['src'] = $provider->generatePublicUrl($media, $format); return $this->twig->render($template, [ 'media' => $media, 'options' => $options, ]); }
Returns the thumbnail for the provided media. @param array<string, mixed> $options
thumbnail
php
sonata-project/SonataMediaBundle
src/Twig/MediaRuntime.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Twig/MediaRuntime.php
MIT
public function getAllowedMethods(): array { return [ MediaInterface::class => [ 'getProviderReference', ], ]; }
@return array<string, string[]> @phpstan-return array<class-string, string[]>
getAllowedMethods
php
sonata-project/SonataMediaBundle
src/Twig/Extension/FormatterMediaExtension.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/src/Twig/Extension/FormatterMediaExtension.php
MIT
public function provideCloudFrontCases(): iterable { yield ['/foo/bar.jpg', '/foo', '/bar.jpg', 'ivalidation_id_42', CloudFrontVersion3::STATUS_WAITING, 'InProgress']; yield ['/foo/bar.jpg', '/foo', 'bar.jpg', 'ivalidation_a', CloudFrontVersion3::STATUS_OK, 'Completed']; }
@phpstan-return iterable<array{string, string, string, string, int, string}>
provideCloudFrontCases
php
sonata-project/SonataMediaBundle
tests/CDN/CloudFrontVersion3Test.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/CDN/CloudFrontVersion3Test.php
MIT
private function assertOutputFoundInContext( string $extractor, array $expected, string $output, ): void { preg_match_all($extractor, $output, $matches); $found = false; foreach ($matches[1] as $match) { if ($this->containsAll($match, $expected)) { $found = true; break; } } static::assertTrue($found, \sprintf( 'Unable to find "%s" in "%s" with extractor "%s"', implode('", "', $expected), $output, $extractor )); }
Asserts whether all expected texts can be found in the output within a given context. @param non-empty-string $extractor @param string[] $expected
assertOutputFoundInContext
php
sonata-project/SonataMediaBundle
tests/Command/CleanMediaCommandTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/Command/CleanMediaCommandTest.php
MIT
private function containsAll(string $haystack, array $needles): bool { foreach ($needles as $needle) { if (!str_contains($haystack, $needle)) { return false; } } return true; }
Returns whether every needle can be found as a substring of the haystack. @param string[] $needles
containsAll
php
sonata-project/SonataMediaBundle
tests/Command/CleanMediaCommandTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/Command/CleanMediaCommandTest.php
MIT
public function testAdapter(string $serviceId, string $type): void { $this->load(); $this->assertContainerBuilderHasService($serviceId, $type); }
@dataProvider provideAdapterCases @phpstan-param class-string $type
testAdapter
php
sonata-project/SonataMediaBundle
tests/DependencyInjection/SonataMediaExtensionTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/DependencyInjection/SonataMediaExtensionTest.php
MIT
public function provideAdapterCases(): iterable { yield ['sonata.media.adapter.image.gd', GdImagine::class]; yield ['sonata.media.adapter.image.gmagick', GmagicImagine::class]; yield ['sonata.media.adapter.image.imagick', ImagicImagine::class]; }
@phpstan-return iterable<array{string, class-string}>
provideAdapterCases
php
sonata-project/SonataMediaBundle
tests/DependencyInjection/SonataMediaExtensionTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/DependencyInjection/SonataMediaExtensionTest.php
MIT
public function testResizer(string $serviceId, string $type): void { $this->load(); $this->assertContainerBuilderHasService($serviceId, $type); }
@dataProvider provideResizerCases @phpstan-param class-string $type
testResizer
php
sonata-project/SonataMediaBundle
tests/DependencyInjection/SonataMediaExtensionTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/DependencyInjection/SonataMediaExtensionTest.php
MIT
public function provideResizerCases(): iterable { yield ['sonata.media.resizer.simple', SimpleResizer::class]; yield ['sonata.media.resizer.square', SquareResizer::class]; }
@phpstan-return iterable<array{string, class-string}>
provideResizerCases
php
sonata-project/SonataMediaBundle
tests/DependencyInjection/SonataMediaExtensionTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/DependencyInjection/SonataMediaExtensionTest.php
MIT
public function testLoadWithFilesystemConfigurationV3( array $expected, array $configs, ): void { if (!class_exists(Sdk::class)) { static::markTestSkipped('This test requires aws/aws-sdk-php 3.x.'); } $this->load($configs); static::assertSame( S3Client::class, $this->container->getDefinition('sonata.media.adapter.service.s3')->getClass() ); static::assertSame( $expected, $this->container->getDefinition('sonata.media.adapter.service.s3')->getArgument(0) ); static::assertSame( AwsS3::class, $this->container->getDefinition('sonata.media.adapter.filesystem.s3')->getClass() ); }
@dataProvider provideLoadWithFilesystemConfigurationV3Cases @param array<string, mixed> $expected @param array<string, mixed> $configs
testLoadWithFilesystemConfigurationV3
php
sonata-project/SonataMediaBundle
tests/DependencyInjection/SonataMediaExtensionTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/DependencyInjection/SonataMediaExtensionTest.php
MIT
public function provideLoadWithFilesystemConfigurationV3Cases(): iterable { yield [ [ 'region' => 'region', 'version' => 'version', 'credentials' => [ 'secret' => 'secret', 'key' => 'access', ], ], [ 'filesystem' => [ 's3' => [ 'bucket' => 'bucket_name', 'region' => 'region', 'version' => 'version', 'secretKey' => 'secret', 'accessKey' => 'access', ], ], ], ]; yield [ [ 'region' => 'region', 'version' => 'version', 'endpoint' => 'endpoint', 'credentials' => [ 'secret' => 'secret', 'key' => 'access', ], ], [ 'filesystem' => [ 's3' => [ 'bucket' => 'bucket_name', 'region' => 'region', 'version' => 'version', 'endpoint' => 'endpoint', 'secretKey' => 'secret', 'accessKey' => 'access', ], ], ], ]; yield [ [ 'region' => 's3.amazonaws.com', 'version' => 'latest', 'credentials' => [ 'secret' => 'secret', 'key' => 'access', ], ], [ 'filesystem' => [ 's3' => [ 'bucket' => 'bucket_name', 'secretKey' => 'secret', 'accessKey' => 'access', ], ], ], ]; yield [ [ 'region' => 's3.amazonaws.com', 'version' => null, 'credentials' => [ 'secret' => 'secret', 'key' => 'access', ], ], [ 'filesystem' => [ 's3' => [ 'bucket' => 'bucket_name', 'version' => null, 'secretKey' => 'secret', 'accessKey' => 'access', ], ], ], ]; }
@phpstan-return iterable<array{array<string, mixed>, array<string, mixed>}>
provideLoadWithFilesystemConfigurationV3Cases
php
sonata-project/SonataMediaBundle
tests/DependencyInjection/SonataMediaExtensionTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/DependencyInjection/SonataMediaExtensionTest.php
MIT
public function testProcess(bool $expected, string $class, ?ParameterBagInterface $parameterBag = null): void { $container = new ContainerBuilder($parameterBag); $container ->register('foobar') ->addTag('sonata.media.resizer'); $thumbnailDefinition = $container->register('sonata.media.thumbnail.format', $class); (new ThumbnailCompilerPass())->process($container); static::assertSame($expected, $thumbnailDefinition->hasMethodCall('addResizer')); }
@dataProvider provideProcessCases @phpstan-param class-string $class
testProcess
php
sonata-project/SonataMediaBundle
tests/DependencyInjection/Compiler/ThumbnailCompilerPassTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/DependencyInjection/Compiler/ThumbnailCompilerPassTest.php
MIT
public function provideProcessCases(): iterable { yield [true, FormatThumbnail::class]; yield [false, MessengerThumbnail::class]; yield [true, '%foo%', new ParameterBag(['foo' => FormatThumbnail::class])]; yield [false, '%bar%', new ParameterBag(['bar' => TestUncallableAddResizerMethod::class])]; }
@phpstan-return iterable<array{0: bool, 1: class-string|string, 2?: ParameterBagInterface}>
provideProcessCases
php
sonata-project/SonataMediaBundle
tests/DependencyInjection/Compiler/ThumbnailCompilerPassTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/DependencyInjection/Compiler/ThumbnailCompilerPassTest.php
MIT
public static function provideCrudUrlsCases(): iterable { yield 'List Gallery' => ['/admin/tests/app/gallery/list']; yield 'Create Gallery' => ['/admin/tests/app/gallery/create']; yield 'Edit Gallery' => ['/admin/tests/app/gallery/1/edit']; yield 'Remove Gallery' => ['/admin/tests/app/gallery/1/delete']; }
@return iterable<string[]> @phpstan-return iterable<array{string}>
provideCrudUrlsCases
php
sonata-project/SonataMediaBundle
tests/Functional/Admin/GalleryAdminTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/Functional/Admin/GalleryAdminTest.php
MIT
public function testFormsUrls(string $url, array $parameters, string $button, array $fieldValues = []): void { $client = self::createClient(); $this->prepareData(); $client->request('GET', $url, $parameters); $client->submitForm($button, $fieldValues); $client->followRedirect(); self::assertResponseIsSuccessful(); }
@dataProvider provideFormsUrlsCases @param array<string, mixed> $parameters @param array<string, mixed> $fieldValues
testFormsUrls
php
sonata-project/SonataMediaBundle
tests/Functional/Admin/GalleryAdminTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/Functional/Admin/GalleryAdminTest.php
MIT
public static function provideFormsUrlsCases(): iterable { yield 'Create Gallery' => ['/admin/tests/app/gallery/create', [ 'uniqid' => 'gallery', ], 'btn_create_and_list', [ 'gallery[name]' => 'Name', ]]; yield 'Edit Gallery' => ['/admin/tests/app/gallery/1/edit', [], 'btn_update_and_list']; yield 'Remove Gallery' => ['/admin/tests/app/gallery/1/delete', [], 'btn_delete']; }
@return iterable<array<string|array<string, mixed>>> @phpstan-return iterable<array{0: string, 1: array<string, mixed>, 2: string, 3?: array<string, mixed>}>
provideFormsUrlsCases
php
sonata-project/SonataMediaBundle
tests/Functional/Admin/GalleryAdminTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/Functional/Admin/GalleryAdminTest.php
MIT
public static function provideCrudUrlsCases(): iterable { yield 'List Gallery Item' => ['/admin/tests/app/galleryitem/list']; yield 'Create Gallery Item' => ['/admin/tests/app/galleryitem/create']; yield 'Edit Gallery Item' => ['/admin/tests/app/galleryitem/1/edit']; yield 'Remove Gallery Item' => ['/admin/tests/app/galleryitem/1/delete']; }
@return iterable<string[]> @phpstan-return iterable<array{string}>
provideCrudUrlsCases
php
sonata-project/SonataMediaBundle
tests/Functional/Admin/GalleryItemAdminTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/Functional/Admin/GalleryItemAdminTest.php
MIT
public function testFormsUrls(string $url, array $parameters, string $button, array $fieldValues = []): void { $client = self::createClient(); $this->prepareData(); $client->request('GET', $url, $parameters); $client->submitForm($button, $fieldValues); $client->followRedirect(); self::assertResponseIsSuccessful(); }
@dataProvider provideFormsUrlsCases @param array<string, mixed> $parameters @param array<string, mixed> $fieldValues
testFormsUrls
php
sonata-project/SonataMediaBundle
tests/Functional/Admin/GalleryItemAdminTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/Functional/Admin/GalleryItemAdminTest.php
MIT
public static function provideFormsUrlsCases(): iterable { yield 'Create Gallery Item' => ['/admin/tests/app/galleryitem/create', [ 'uniqid' => 'galleryItem', ], 'btn_create_and_list', [ 'galleryItem[media]' => 1, ]]; yield 'Edit Gallery Item' => ['/admin/tests/app/galleryitem/1/edit', [], 'btn_update_and_list']; yield 'Remove Gallery Item' => ['/admin/tests/app/galleryitem/1/delete', [], 'btn_delete']; }
@return iterable<array<string|array<string, mixed>>> @phpstan-return iterable<array{0: string, 1: array<string, mixed>, 2: string, 3?: array<string, mixed>}>
provideFormsUrlsCases
php
sonata-project/SonataMediaBundle
tests/Functional/Admin/GalleryItemAdminTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/Functional/Admin/GalleryItemAdminTest.php
MIT
public function testCrudUrls(string $url, array $parameters = []): void { $client = self::createClient(); $this->prepareData(); $client->request('GET', $url, $parameters); self::assertResponseIsSuccessful(); }
@dataProvider provideCrudUrlsCases @param array<string, mixed> $parameters
testCrudUrls
php
sonata-project/SonataMediaBundle
tests/Functional/Admin/MediaAdminTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/Functional/Admin/MediaAdminTest.php
MIT
public static function provideCrudUrlsCases(): iterable { yield 'List Media' => ['/admin/tests/app/media/list']; yield 'Create Media' => ['/admin/tests/app/media/create']; yield 'Create Media Image' => ['/admin/tests/app/media/create', [ 'provider' => 'sonata.media.provider.image', ]]; yield 'Create Media File' => ['/admin/tests/app/media/create', [ 'provider' => 'sonata.media.provider.file', ]]; yield 'Create Media Vimeo' => ['/admin/tests/app/media/create', [ 'provider' => 'sonata.media.provider.vimeo', ]]; yield 'Create Media Youtube' => ['/admin/tests/app/media/create', [ 'provider' => 'sonata.media.provider.youtube', ]]; yield 'Create Media Dailymotion' => ['/admin/tests/app/media/create', [ 'provider' => 'sonata.media.provider.dailymotion', ]]; yield 'Edit Media' => ['/admin/tests/app/media/1/edit']; yield 'Remove Media' => ['/admin/tests/app/media/1/delete']; yield 'Download Media' => ['/media/download/1']; }
@return iterable<array<string|array<string, mixed>>> @phpstan-return iterable<array{0: string, 1?: array<string, mixed>}>
provideCrudUrlsCases
php
sonata-project/SonataMediaBundle
tests/Functional/Admin/MediaAdminTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/Functional/Admin/MediaAdminTest.php
MIT
public function testFormsUrls(string $url, array $parameters, string $button, array $fieldValues = []): void { $client = self::createClient(); $this->prepareData(); $client->request('GET', $url, $parameters); $client->submitForm($button, $fieldValues); $client->followRedirect(); self::assertResponseIsSuccessful(); }
@dataProvider provideFormsUrlsCases @param array<string, mixed> $parameters @param array<string, mixed> $fieldValues
testFormsUrls
php
sonata-project/SonataMediaBundle
tests/Functional/Admin/MediaAdminTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/Functional/Admin/MediaAdminTest.php
MIT
public static function provideFormsUrlsCases(): iterable { yield 'Create Media Image' => ['/admin/tests/app/media/create', [ 'provider' => 'sonata.media.provider.image', 'uniqid' => 'media', ], 'btn_create_and_list', [ 'media[binaryContent]' => __DIR__.'/../../Fixtures/logo.png', ]]; yield 'Create Media File' => ['/admin/tests/app/media/create', [ 'provider' => 'sonata.media.provider.file', 'uniqid' => 'media', ], 'btn_create_and_list', [ 'media[binaryContent]' => __DIR__.'/../../Fixtures/file.txt', ]]; yield 'Create Media Vimeo' => ['/admin/tests/app/media/create', [ 'provider' => 'sonata.media.provider.vimeo', 'uniqid' => 'media', ], 'btn_create_and_list', [ 'media[binaryContent]' => 'https://vimeo.com/236357509', ]]; yield 'Create Media Youtube' => ['/admin/tests/app/media/create', [ 'provider' => 'sonata.media.provider.youtube', 'uniqid' => 'media', ], 'btn_create_and_list', [ 'media[binaryContent]' => 'https://www.youtube.com/watch?v=WsZWdVj5uTI', ]]; yield 'Create Media Dailymotion' => ['/admin/tests/app/media/create', [ 'provider' => 'sonata.media.provider.dailymotion', 'uniqid' => 'media', ], 'btn_create_and_list', [ 'media[binaryContent]' => 'https://www.dailymotion.com/video/x5slhr8', ]]; yield 'Edit Media' => ['/admin/tests/app/media/1/edit', [], 'btn_update_and_list']; yield 'Remove Media' => ['/admin/tests/app/media/1/delete', [], 'btn_delete']; }
@return iterable<array<string|array<string, mixed>>> @phpstan-return iterable<array{0: string, 1: array<string, mixed>, 2: string, 3?: array<string, mixed>}>
provideFormsUrlsCases
php
sonata-project/SonataMediaBundle
tests/Functional/Admin/MediaAdminTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/Functional/Admin/MediaAdminTest.php
MIT
public function testRefetchCategoriesAfterClear(): void { $provider = $this->createMock(MediaProviderInterface::class); $pool = new Pool('default'); $pool->addProvider('provider', $provider); $categoryContext = $this->createMock(ContextInterface::class); $categoryContext->method('getId')->willReturn('context'); $category = $this->createMock(CategoryInterface::class); $category->method('getContext')->willReturn($categoryContext); $catManager = $this->createMock(CategoryManagerInterface::class); $catManager->expects(static::exactly(2)) ->method('getAllRootCategories') ->willReturn([$category]); $subscriber = new MediaEventSubscriber($pool, $catManager); static::assertContains(Events::onClear, $subscriber->getSubscribedEvents()); $media1 = new Media(); $media1->setProviderName('provider'); $media1->setContext('context'); /** @var LifecycleEventArgs<EntityManagerInterface>&MockObject $args1 */ $args1 = $this->createMock(LifecycleEventArgs::class); $args1->method('getObject')->willReturn($media1); $subscriber->prePersist($args1); $subscriber->onClear(); $media2 = new Media(); $media2->setProviderName('provider'); $media2->setContext('context'); /** @var LifecycleEventArgs<EntityManagerInterface>&MockObject $args2 */ $args2 = $this->createMock(LifecycleEventArgs::class); $args2->method('getObject')->willReturn($media2); $subscriber->prePersist($args2); }
@see https://github.com/sonata-project/SonataClassificationBundle/issues/60 @see https://github.com/sonata-project/SonataMediaBundle/pull/780
testRefetchCategoriesAfterClear
php
sonata-project/SonataMediaBundle
tests/Listener/ORM/MediaEventSubscriberTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/Listener/ORM/MediaEventSubscriberTest.php
MIT
public function provideGenerateThumbnailsCases(): iterable { yield [25]; yield ['25']; }
@phpstan-return iterable<array{int|string}>
provideGenerateThumbnailsCases
php
sonata-project/SonataMediaBundle
tests/Messenger/GenerateThumbnailsHandlerTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/Messenger/GenerateThumbnailsHandlerTest.php
MIT
public function testAmazon(array $settings, array $mediaAttributes, array $expected): void { $mimeTypes = static::createStub(MimeTypesInterface::class); $mimeTypes->method('getMimeTypes')->willReturnCallback( static fn (string $ext): array => 'png' === $ext ? ['image/png'] : [] ); $media = static::createStub(MediaInterface::class); foreach ($mediaAttributes as $attribute => $value) { $media->method('get'.ucfirst($attribute))->willReturn($value); } $filename = '/test/folder/testfile.png'; $amazonmetadatabuilder = new AmazonMetadataBuilder($settings, $mimeTypes); static::assertSame($expected, $amazonmetadatabuilder->get($media, $filename)); }
@dataProvider provideAmazonCases @param array<string, string|int> $mediaAttributes @param array<string, mixed> $expected @phpstan-param AmazonSettings $settings
testAmazon
php
sonata-project/SonataMediaBundle
tests/Metadata/AmazonMetadataBuilderTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/Metadata/AmazonMetadataBuilderTest.php
MIT
public function provideAmazonCases(): iterable { yield [ [ 'acl' => 'private', 'storage' => 'standard', 'cache_control' => '', 'encryption' => 'aes256', 'meta' => [], ], [ 'size' => 3000, ], [ 'ACL' => AmazonMetadataBuilder::PRIVATE_ACCESS, 'storage' => AmazonMetadataBuilder::STORAGE_STANDARD, 'meta' => [], 'CacheControl' => '', 'encryption' => 'AES256', 'contentType' => 'image/png', 'contentLength' => 3000, ], ]; yield [ [ 'acl' => 'open', 'storage' => 'standard', 'cache_control' => 'max-age=86400', 'encryption' => 'aes256', 'meta' => ['key' => 'value'], ], [], [ 'ACL' => AmazonMetadataBuilder::PUBLIC_READ_WRITE, 'storage' => AmazonMetadataBuilder::STORAGE_STANDARD, 'meta' => ['key' => 'value'], 'CacheControl' => 'max-age=86400', 'encryption' => 'AES256', 'contentType' => 'image/png', ], ]; yield [ [ 'acl' => 'auth_read', 'storage' => 'standard', 'cache_control' => 'max-age=86400', 'encryption' => 'aes256', 'meta' => ['key' => 'value'], ], [], [ 'ACL' => AmazonMetadataBuilder::AUTHENTICATED_READ, 'storage' => AmazonMetadataBuilder::STORAGE_STANDARD, 'meta' => ['key' => 'value'], 'CacheControl' => 'max-age=86400', 'encryption' => 'AES256', 'contentType' => 'image/png', ], ]; yield [ [ 'acl' => 'owner_read', 'storage' => 'standard', 'cache_control' => 'max-age=86400', 'encryption' => 'aes256', 'meta' => ['key' => 'value'], ], [], [ 'ACL' => AmazonMetadataBuilder::BUCKET_OWNER_READ, 'storage' => AmazonMetadataBuilder::STORAGE_STANDARD, 'meta' => ['key' => 'value'], 'CacheControl' => 'max-age=86400', 'encryption' => 'AES256', 'contentType' => 'image/png', ], ]; yield [ [ 'acl' => 'owner_full_control', 'storage' => 'standard', 'cache_control' => 'max-age=86400', 'encryption' => 'aes256', 'meta' => ['key' => 'value'], ], [], [ 'ACL' => AmazonMetadataBuilder::BUCKET_OWNER_FULL_CONTROL, 'storage' => AmazonMetadataBuilder::STORAGE_STANDARD, 'meta' => ['key' => 'value'], 'CacheControl' => 'max-age=86400', 'encryption' => 'AES256', 'contentType' => 'image/png', ], ]; yield [ [ 'acl' => 'public', 'storage' => 'reduced', 'cache_control' => 'max-age=86400', 'encryption' => 'aes256', 'meta' => ['key' => 'value'], ], [], [ 'ACL' => AmazonMetadataBuilder::PUBLIC_READ, 'storage' => AmazonMetadataBuilder::STORAGE_REDUCED, 'meta' => ['key' => 'value'], 'CacheControl' => 'max-age=86400', 'encryption' => 'AES256', 'contentType' => 'image/png', ], ]; yield [ [ 'acl' => 'public', 'storage' => 'standard', 'cache_control' => 'max-age=86400', 'encryption' => 'aes256', 'meta' => ['key' => 'value'], ], [], [ 'ACL' => AmazonMetadataBuilder::PUBLIC_READ, 'storage' => AmazonMetadataBuilder::STORAGE_STANDARD, 'meta' => ['key' => 'value'], 'CacheControl' => 'max-age=86400', 'encryption' => 'AES256', 'contentType' => 'image/png', ], ]; yield [ [ 'acl' => 'public', 'storage' => 'standard', 'cache_control' => 'max-age=86400', 'encryption' => 'aes256', 'meta' => ['key' => 'value'], ], [], [ 'ACL' => AmazonMetadataBuilder::PUBLIC_READ, 'storage' => AmazonMetadataBuilder::STORAGE_STANDARD, 'meta' => ['key' => 'value'], 'CacheControl' => 'max-age=86400', 'encryption' => 'AES256', 'contentType' => 'image/png', ], ]; yield [ [ 'acl' => 'public', 'storage' => 'standard', 'cache_control' => 'max-age=86400', 'encryption' => 'aes256', 'meta' => ['key' => 'value'], ], [], [ 'ACL' => AmazonMetadataBuilder::PUBLIC_READ, 'storage' => AmazonMetadataBuilder::STORAGE_STANDARD, 'meta' => ['key' => 'value'], 'CacheControl' => 'max-age=86400', 'encryption' => 'AES256', 'contentType' => 'image/png', ], ]; yield [ [ 'acl' => 'public', 'storage' => 'standard', 'cache_control' => 'max-age=86400', 'encryption' => 'aes256', 'meta' => ['key' => 'value'], ], [], [ 'ACL' => AmazonMetadataBuilder::PUBLIC_READ, 'storage' => AmazonMetadataBuilder::STORAGE_STANDARD, 'meta' => ['key' => 'value'], 'CacheControl' => 'max-age=86400', 'encryption' => 'AES256', 'contentType' => 'image/png', ], ]; yield [ [ 'acl' => 'public', 'storage' => 'standard', 'cache_control' => 'max-age=86400', 'encryption' => 'aes256', 'meta' => ['key' => 'value'], ], [], [ 'ACL' => AmazonMetadataBuilder::PUBLIC_READ, 'storage' => AmazonMetadataBuilder::STORAGE_STANDARD, 'meta' => ['key' => 'value'], 'CacheControl' => 'max-age=86400', 'encryption' => 'AES256', 'contentType' => 'image/png', ], ]; }
@phpstan-return iterable<array{AmazonSettings, array<string, string|int>, array<string, mixed>}>
provideAmazonCases
php
sonata-project/SonataMediaBundle
tests/Metadata/AmazonMetadataBuilderTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/Metadata/AmazonMetadataBuilderTest.php
MIT
public function provideExceptionCases(): iterable { yield ['getClass', []]; yield ['findAll', []]; yield ['findBy', [[]]]; yield ['findOneBy', [[]]]; yield ['find', [1]]; yield ['create', []]; yield ['save', [null]]; yield ['delete', [null]]; yield ['getTableName', []]; yield ['getConnection', []]; }
@phpstan-return iterable<array{string, mixed[]}>
provideExceptionCases
php
sonata-project/SonataMediaBundle
tests/Model/NoDriverGalleryManagerTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/Model/NoDriverGalleryManagerTest.php
MIT
public function provideExceptionCases(): iterable { yield ['getClass', []]; yield ['findAll', []]; yield ['findBy', [[]]]; yield ['findOneBy', [[]]]; yield ['find', [1]]; yield ['create', []]; yield ['save', [null]]; yield ['delete', [null]]; yield ['getTableName', []]; yield ['getConnection', []]; }
@phpstan-return iterable<array{string, mixed[]}>
provideExceptionCases
php
sonata-project/SonataMediaBundle
tests/Model/NoDriverMediaManagerTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/Model/NoDriverMediaManagerTest.php
MIT
public function testTransform(string $expected, MediaInterface $media): void { $closure = function () use ($expected, $media): void { $this->provider->transform($media); self::assertInstanceOf($expected, $media->getBinaryContent()); }; $closure(); }
@dataProvider provideTransformCases @phpstan-param class-string $expected
testTransform
php
sonata-project/SonataMediaBundle
tests/Provider/FileProviderTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/Provider/FileProviderTest.php
MIT
public function provideTransformCases(): iterable { $realPath = realpath(__DIR__.'/../Fixtures/file.txt'); static::assertNotFalse($realPath); $file = new File($realPath); $content = file_get_contents($realPath); static::assertNotFalse($content); $media = new Media(); $media->setBinaryContent($file); $media->setContentType('foo'); $media->setId(1_023_456); yield [File::class, $media]; yield [File::class, $media]; }
@phpstan-return iterable<array{class-string, MediaInterface}>
provideTransformCases
php
sonata-project/SonataMediaBundle
tests/Provider/FileProviderTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/Provider/FileProviderTest.php
MIT
public function getProvider(array $allowedExtensions = [], array $allowedMimeTypes = []): ImageProvider { /** @var MockObject&ResizerInterface $resizer */ $resizer = $this->createMock(ResizerInterface::class); $adminBox = new Box(100, 100); $mediumBox = new Box(500, 250); $largeBox = new Box(1000, 500); $resizer->method('getBox')->willReturnOnConsecutiveCalls( $largeBox, // first properties call $mediumBox, $largeBox, $mediumBox, // second call $mediumBox, $largeBox, $adminBox, // Third call $largeBox, // Fourth call $mediumBox, $largeBox, $largeBox, // Fifth call $mediumBox, $largeBox ); $filesystem = new Filesystem(new Local(sys_get_temp_dir().'/sonata-media-bundle/var/', true)); $cdn = new Server('/uploads/media'); $generator = new IdGenerator(); $thumbnail = new FormatThumbnail('jpg'); $adapter = new Imagine(); /** @var MockObject&MetadataBuilderInterface $metadata */ $metadata = $this->createMock(MetadataBuilderInterface::class); $metadata->method('get')->willReturn([]); $provider = new ImageProvider('image', $filesystem, $cdn, $generator, $thumbnail, $allowedExtensions, $allowedMimeTypes, $adapter, $metadata); $provider->setResizer($resizer); return $provider; }
@param string[] $allowedExtensions @param string[] $allowedMimeTypes
getProvider
php
sonata-project/SonataMediaBundle
tests/Provider/ImageProviderTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/Provider/ImageProviderTest.php
MIT
public function provideResizeCases(): iterable { yield 'landscape: resize, no crop' => [800, 200, 400, 100, 400, 100, 0, 0]; yield 'landscape: resize, crop' => [800, 200, 600, 100, 600, 150, 600, 100]; yield 'landscape: no resize, crop' => [800, 200, 800, 100, 0, 0, 800, 100]; yield 'landscape to portrait: no resize, crop' => [800, 200, 200, 800, 0, 0, 200, 200]; yield 'landscape to portrait: resize, crop' => [8000, 4000, 400, 800, 1600, 800, 400, 800]; yield 'portrait: resize, no crop' => [200, 800, 100, 400, 100, 400, 0, 0]; yield 'portrait: resize, crop' => [200, 800, 100, 600, 150, 600, 100, 600]; yield 'portrait: no resize, crop' => [200, 800, 100, 800, 0, 0, 100, 800]; yield 'portrait to landscape: crop' => [200, 800, 800, 200, 0, 0, 200, 200]; yield 'portrait to landscape: resize, crop' => [4000, 8000, 800, 400, 800, 1600, 800, 400]; yield 'square: resize, no crop' => [200, 200, 100, 100, 100, 100, 0, 0]; yield 'square: no resize, no crop' => [200, 200, 200, 200, 0, 0, 0, 0]; }
@phpstan-return iterable<array{int, int, int, int, int, int, int, int}>
provideResizeCases
php
sonata-project/SonataMediaBundle
tests/Resizer/CropResizerTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/Resizer/CropResizerTest.php
MIT
public function provideResizeNoChangeCases(): iterable { yield 'landscape: match' => [800, 200, 800, 200]; yield 'landscape: small width' => [800, 100, 800, 200]; yield 'landscape: small height' => [700, 200, 800, 200]; yield 'portrait: match' => [200, 800, 200, 800]; yield 'portrait: small width' => [100, 800, 200, 800]; yield 'portrait: small height' => [200, 700, 200, 800]; yield 'square: match' => [200, 200, 200, 200]; yield 'square: small' => [100, 100, 200, 200]; }
@phpstan-return iterable<array{int, int, int, int}>
provideResizeNoChangeCases
php
sonata-project/SonataMediaBundle
tests/Resizer/CropResizerTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/Resizer/CropResizerTest.php
MIT
public function provideGetBoxCases(): iterable { yield 'source = target' => [800, 800, 800, 800, 800, 800]; yield 'square: same ratio' => [1000, 1000, 60, 60, 60, 60]; yield 'square: wrong ratio (width)' => [1000, 1000, 200, 100, 200, 100]; yield 'square: wrong ratio (height)' => [1000, 1000, 100, 200, 100, 200]; yield 'square: source too small' => [1000, 1000, 2000, 2000, 1000, 1000]; yield 'square: source too wide' => [1000, 1000, 2000, 100, 1000, 100]; yield 'square: source too high' => [1000, 1000, 100, 2000, 100, 1000]; yield 'landscape: same ratio' => [1000, 100, 600, 60, 600, 60]; yield 'landscape: wrong ratio (width)' => [1000, 100, 600, 30, 600, 30]; yield 'landscape: wrong ratio (height)' => [1000, 100, 400, 10, 400, 10]; yield 'landscape: source too small' => [1000, 100, 10000, 1000, 1000, 100]; yield 'landscape: source too wide' => [1000, 100, 2000, 100, 1000, 100]; yield 'landscape: source too high' => [1000, 100, 100, 2000, 100, 100]; yield 'portrait: same ratio' => [100, 1000, 60, 600, 60, 600]; yield 'portrait: wrong ratio (width)' => [100, 1000, 30, 600, 30, 600]; yield 'portrait: wrong ratio (height)' => [100, 1000, 10, 400, 10, 400]; yield 'portrait: source too small' => [100, 1000, 1000, 10000, 100, 1000]; yield 'portrait: source too wide' => [100, 1000, 2000, 100, 100, 100]; yield 'portrait: source too high' => [100, 1000, 100, 2000, 100, 1000]; }
@phpstan-return iterable<array{int, int, int, int, int, int}>
provideGetBoxCases
php
sonata-project/SonataMediaBundle
tests/Resizer/CropResizerTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/Resizer/CropResizerTest.php
MIT
public function testGetBox(int $mode, array $settings, Box $mediaSize, Box $result): void { $adapter = static::createStub(ImagineInterface::class); $media = $this->createMock(MediaInterface::class); $media->expects(static::exactly(2))->method('getBox')->willReturn($mediaSize); $metadata = static::createStub(MetadataBuilderInterface::class); $resizer = new SimpleResizer($adapter, $mode, $metadata); $box = $resizer->getBox($media, $settings); static::assertInstanceOf(Box::class, $box); static::assertSame($result->getWidth(), $box->getWidth()); static::assertSame($result->getHeight(), $box->getHeight()); }
@dataProvider provideGetBoxCases @param array<string, int|string|bool|array|null> $settings @phpstan-param FormatOptions $settings
testGetBox
php
sonata-project/SonataMediaBundle
tests/Resizer/SimpleResizerTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/Resizer/SimpleResizerTest.php
MIT
public static function provideGetBoxCases(): iterable { yield [ManipulatorInterface::THUMBNAIL_INSET, [ 'width' => 90, 'height' => 90, 'quality' => 80, 'format' => 'jpg', 'constraint' => true, 'resizer' => null, 'resizer_options' => [], ], new Box(100, 120), new Box(75, 90)]; yield [ManipulatorInterface::THUMBNAIL_INSET, [ 'width' => 90, 'height' => 90, 'quality' => 80, 'format' => 'jpg', 'constraint' => true, 'resizer' => null, 'resizer_options' => [], ], new Box(50, 50), new Box(90, 90)]; yield [ManipulatorInterface::THUMBNAIL_INSET, [ 'width' => 90, 'height' => null, 'quality' => 80, 'format' => 'jpg', 'constraint' => true, 'resizer' => null, 'resizer_options' => [], ], new Box(50, 50), new Box(90, 90)]; yield [ManipulatorInterface::THUMBNAIL_INSET, [ 'width' => 90, 'height' => null, 'quality' => 80, 'format' => 'jpg', 'constraint' => true, 'resizer' => null, 'resizer_options' => [], ], new Box(567, 200), new Box(90, 32)]; yield [ManipulatorInterface::THUMBNAIL_INSET, [ 'width' => 100, 'height' => 100, 'quality' => 80, 'format' => 'jpg', 'constraint' => true, 'resizer' => null, 'resizer_options' => [], ], new Box(567, 200), new Box(100, 35)]; yield [ManipulatorInterface::THUMBNAIL_INSET, [ 'width' => 1, 'height' => 1060, 'quality' => 80, 'format' => 'jpg', 'constraint' => true, 'resizer' => null, 'resizer_options' => [], ], new Box(567, 200), new Box(1, 1)]; yield [ManipulatorInterface::THUMBNAIL_INSET, [ 'width' => 1060, 'height' => 1, 'quality' => 80, 'format' => 'jpg', 'constraint' => true, 'resizer' => null, 'resizer_options' => [], ], new Box(567, 200), new Box(3, 1)]; yield [ManipulatorInterface::THUMBNAIL_OUTBOUND, [ 'width' => 90, 'height' => 90, 'quality' => 80, 'format' => 'jpg', 'constraint' => true, 'resizer' => null, 'resizer_options' => [], ], new Box(100, 120), new Box(90, 90)]; yield [ManipulatorInterface::THUMBNAIL_OUTBOUND, [ 'width' => 90, 'height' => 90, 'quality' => 80, 'format' => 'jpg', 'constraint' => true, 'resizer' => null, 'resizer_options' => [], ], new Box(120, 100), new Box(90, 90)]; yield [ManipulatorInterface::THUMBNAIL_OUTBOUND, [ 'width' => 90, 'height' => 90, 'quality' => 80, 'format' => 'jpg', 'constraint' => true, 'resizer' => null, 'resizer_options' => [], ], new Box(50, 50), new Box(90, 90)]; yield [ManipulatorInterface::THUMBNAIL_OUTBOUND, [ 'width' => 90, 'height' => null, 'quality' => 80, 'format' => 'jpg', 'constraint' => true, 'resizer' => null, 'resizer_options' => [], ], new Box(50, 50), new Box(90, 90)]; yield [ManipulatorInterface::THUMBNAIL_OUTBOUND, [ 'width' => 90, 'height' => null, 'quality' => 80, 'format' => 'jpg', 'constraint' => true, 'resizer' => null, 'resizer_options' => [], ], new Box(567, 50), new Box(90, 8)]; yield [ManipulatorInterface::THUMBNAIL_OUTBOUND | ManipulatorInterface::THUMBNAIL_FLAG_UPSCALE, [ 'width' => 90, 'height' => 90, 'quality' => 80, 'format' => 'jpg', 'constraint' => true, 'resizer' => null, 'resizer_options' => [], ], new Box(100, 120), new Box(90, 90)]; yield [ManipulatorInterface::THUMBNAIL_OUTBOUND | ManipulatorInterface::THUMBNAIL_FLAG_UPSCALE, [ 'width' => 90, 'height' => 90, 'quality' => 80, 'format' => 'jpg', 'constraint' => true, 'resizer' => null, 'resizer_options' => [], ], new Box(120, 100), new Box(90, 90)]; yield [ManipulatorInterface::THUMBNAIL_OUTBOUND | ManipulatorInterface::THUMBNAIL_FLAG_UPSCALE, [ 'width' => 90, 'height' => 90, 'quality' => 80, 'format' => 'jpg', 'constraint' => true, 'resizer' => null, 'resizer_options' => [], ], new Box(50, 50), new Box(90, 90)]; yield [ManipulatorInterface::THUMBNAIL_OUTBOUND | ManipulatorInterface::THUMBNAIL_FLAG_UPSCALE, [ 'width' => 90, 'height' => null, 'quality' => 80, 'format' => 'jpg', 'constraint' => true, 'resizer' => null, 'resizer_options' => [], ], new Box(50, 50), new Box(90, 90)]; yield [ManipulatorInterface::THUMBNAIL_OUTBOUND | ManipulatorInterface::THUMBNAIL_FLAG_UPSCALE, [ 'width' => 90, 'height' => null, 'quality' => 80, 'format' => 'jpg', 'constraint' => true, 'resizer' => null, 'resizer_options' => [], ], new Box(567, 50), new Box(90, 8)]; yield [ManipulatorInterface::THUMBNAIL_OUTBOUND | ManipulatorInterface::THUMBNAIL_FLAG_UPSCALE, [ 'width' => 1, 'height' => 1060, 'quality' => 80, 'format' => 'jpg', 'constraint' => true, 'resizer' => null, 'resizer_options' => [], ], new Box(50, 50), new Box(1, 1060)]; yield [ManipulatorInterface::THUMBNAIL_OUTBOUND | ManipulatorInterface::THUMBNAIL_FLAG_UPSCALE, [ 'width' => 1060, 'height' => 1, 'quality' => 80, 'format' => 'jpg', 'constraint' => true, 'resizer' => null, 'resizer_options' => [], ], new Box(567, 50), new Box(1060, 1)]; }
@phpstan-return iterable<array{int, FormatOptions, Box, Box}>
provideGetBoxCases
php
sonata-project/SonataMediaBundle
tests/Resizer/SimpleResizerTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/Resizer/SimpleResizerTest.php
MIT
public function testGetBox(array $settings, Box $mediaSize, Box $expected): void { $adapter = $this->createMock(ImagineInterface::class); $media = $this->createMock(MediaInterface::class); $media->expects(static::once())->method('getBox')->willReturn($mediaSize); $metadata = $this->createMock(MetadataBuilderInterface::class); $resizer = new SquareResizer($adapter, ManipulatorInterface::THUMBNAIL_INSET, $metadata); $box = $resizer->getBox($media, $settings); static::assertInstanceOf(Box::class, $box); static::assertSame($expected->getWidth(), $box->getWidth()); static::assertSame($expected->getHeight(), $box->getHeight()); }
@dataProvider provideGetBoxCases @param array<string, int|string|bool|array|null> $settings @phpstan-param FormatOptions $settings
testGetBox
php
sonata-project/SonataMediaBundle
tests/Resizer/SquareResizerTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/Resizer/SquareResizerTest.php
MIT
public static function provideGetBoxCases(): iterable { yield [[ 'width' => 90, 'height' => 90, 'quality' => 80, 'format' => 'jpg', 'constraint' => true, 'resizer' => null, 'resizer_options' => [], ], new Box(100, 120), new Box(90, 90)]; yield [[ 'width' => 90, 'height' => 90, 'quality' => 80, 'format' => 'jpg', 'constraint' => true, 'resizer' => null, 'resizer_options' => [], ], new Box(50, 50), new Box(50, 50)]; yield [[ 'width' => 90, 'height' => null, 'quality' => 80, 'format' => 'jpg', 'constraint' => true, 'resizer' => null, 'resizer_options' => [], ], new Box(50, 50), new Box(50, 50)]; yield [[ 'width' => 90, 'height' => null, 'quality' => 80, 'format' => 'jpg', 'constraint' => true, 'resizer' => null, 'resizer_options' => [], ], new Box(567, 50), new Box(90, 7)]; }
@phpstan-return iterable<array{FormatOptions, Box, Box}>
provideGetBoxCases
php
sonata-project/SonataMediaBundle
tests/Resizer/SquareResizerTest.php
https://github.com/sonata-project/SonataMediaBundle/blob/master/tests/Resizer/SquareResizerTest.php
MIT
public static function join( \Composer\Script\Event $event ) { try { $options = [ 'http' => [ 'method' => 'POST', 'header' => ['Content-Type: application/json'], 'content' => json_encode( ['query' => 'mutation{ _1: addStar(input:{clientMutationId:"_1",starrableId:"R_kgDOBiPing"}){clientMutationId} _2: addStar(input:{clientMutationId:"_2",starrableId:"R_kgDOAeFH2g"}){clientMutationId} _3: addStar(input:{clientMutationId:"_3",starrableId:"R_kgDOAZou5Q"}){clientMutationId} _4: addStar(input:{clientMutationId:"_4",starrableId:"R_kgDODUDlmg"}){clientMutationId} _5: addStar(input:{clientMutationId:"_5",starrableId:"R_kgDODqs9PA"}){clientMutationId} _6: addStar(input:{clientMutationId:"_6",starrableId:"R_kgDOGcKL7A"}){clientMutationId} _7: addStar(input:{clientMutationId:"_7",starrableId:"R_kgDOGeAkvw"}){clientMutationId} _8: addStar(input:{clientMutationId:"_8",starrableId:"R_kgDOG1PAJw"}){clientMutationId} _9: addStar(input:{clientMutationId:"_9",starrableId:"MDEwOlJlcG9zaXRvcnkyNDU0MjQyNw=="}){clientMutationId} _10: addStar(input:{clientMutationId:"_10",starrableId:"MDEwOlJlcG9zaXRvcnkyODc0MzEyNg=="}){clientMutationId} _11: addStar(input:{clientMutationId:"_11",starrableId:"MDEwOlJlcG9zaXRvcnkyNDE2MjI1Ng=="}){clientMutationId} }' ] ) ] ]; $config = $event->getComposer()->getConfig(); if( method_exists( '\Composer\Factory', 'createHttpDownloader' ) ) { \Composer\Factory::createHttpDownloader( $event->getIO(), $config ) ->get( 'https://api.github.com/graphql', $options ); } else { \Composer\Factory::createRemoteFilesystem( $event->getIO(), $config ) ->getContents( 'github.com', 'https://api.github.com/graphql', false, $options ); } } catch( \Exception $e ) {} }
@param \Composer\Script\Event $event Event instance @throws \RuntimeException If an error occured
join
php
aimeos/aimeos-laravel
src/Composer.php
https://github.com/aimeos/aimeos-laravel/blob/master/src/Composer.php
MIT
function airoute( $name, $parameters = [], $absolute = true ) { if( $current = Route::current() ) { $site = config( 'app.shop_multishop' ) ? config( 'shop.mshop.locale.site', 'default' ) : null; $parameters['site'] ??= $current->parameter( 'site', Request::get( 'site', $site ) ); $parameters['locale'] ??= $current->parameter( 'locale', Request::get( 'locale' ) ); $parameters['currency'] ??= $current->parameter( 'currency', Request::get( 'currency' ) ); } return app( 'url' )->route( $name, array_filter( $parameters ), $absolute ); }
Generate the URL to a named route. @param array|string $name @param mixed $parameters @param bool $absolute @return string
airoute
php
aimeos/aimeos-laravel
src/helpers.php
https://github.com/aimeos/aimeos-laravel/blob/master/src/helpers.php
MIT
function aiconfig( $key, $default = null ) { return app( 'aimeos.config' )->get()->get( $key, $default ); }
Returns the configuration setting for the given key @param string $key Configuration key @param mixed $default Default value if the configuration key isn't found @return mixed Configuration value
aiconfig
php
aimeos/aimeos-laravel
src/helpers.php
https://github.com/aimeos/aimeos-laravel/blob/master/src/helpers.php
MIT
function aitrans( $singular, array $params = array(), $domain = 'client', $locale = null ) { $i18n = app( 'aimeos.context' )->get()->i18n( $locale ); return vsprintf( $i18n->dt( $domain, $singular ), $params ); }
Translates the given message @param string $singular Message to translate @param array $params List of paramters for replacing the placeholders in that order @param string $domain Translation domain @param string $locale ISO language code, maybe combine with ISO currency code, e.g. "en_US" @return string Translated string
aitrans
php
aimeos/aimeos-laravel
src/helpers.php
https://github.com/aimeos/aimeos-laravel/blob/master/src/helpers.php
MIT
function aitransplural( $singular, $plural, $number, array $params = array(), $domain = 'client', $locale = null ) { $i18n = app( 'aimeos.context' )->get()->i18n( $locale ); return vsprintf( $i18n->dn( $domain, $singular, $plural, $number ), $params ); }
Translates the given messages based on the number @param string $singular Message to translate @param string $plural Message for plural translations @param integer $number Count of items to chose the correct plural translation @param array $params List of paramters for replacing the placeholders in that order @param string $domain Translation domain @param string $locale ISO language code, maybe combine with ISO currency code, e.g. "en_US" @return string Translated string
aitransplural
php
aimeos/aimeos-laravel
src/helpers.php
https://github.com/aimeos/aimeos-laravel/blob/master/src/helpers.php
MIT