Skip to content

Commit

Permalink
rename config file
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Dec 11, 2023
1 parent 98d4609 commit 0e6e6e1
Show file tree
Hide file tree
Showing 48 changed files with 106 additions and 106 deletions.
2 changes: 1 addition & 1 deletion UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Because there are many breaking changes an upgrade is not that easy. There are m

## From v10 to v11

- Rename to config file from `media-library.php` to `medialibrary.php`.
- Image v3 is now used. Make sure to update your image conversions to the new syntax. See [the image docs](https://spatie.be/docs/image/v3) for more info.
- All event names have gained the `Event` suffix. For example `Spatie\MediaLibrary\MediaCollections\Events\MediaHasBeenAdded` is now `Spatie\MediaLibrary\MediaCollections\Events\MediaHasBeenAddedEvent`.


Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/Conversions/Actions/PerformManipulationsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function execute(
$conversion->format($media->extension);
}

$image = Image::useImageDriver(config('medialibrary.image_driver'))
$image = Image::useImageDriver(config('media-library.image_driver'))

Check failure on line 32 in src/Conversions/Actions/PerformManipulationsAction.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined method Spatie\Image\Drivers\ImageDriver::loadFile().
->loadFile($conversionTempFile)
->format('jpg');

Expand Down
8 changes: 4 additions & 4 deletions src/Conversions/Conversion.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ class Conversion
public function __construct(
protected string $name,
) {
$optimizerChain = OptimizerChainFactory::create(config('medialibrary.image_optimizers'));
$optimizerChain = OptimizerChainFactory::create(config('media-library.image_optimizers'));

$this->manipulations = (new Manipulations())

Check failure on line 39 in src/Conversions/Conversion.php

View workflow job for this annotation

GitHub Actions / phpstan

Property Spatie\MediaLibrary\Conversions\Conversion::$manipulations (Spatie\MediaLibrary\Conversions\Manipulations) does not accept Spatie\Image\Drivers\ImageDriver.
->optimize($optimizerChain)
->format('jpg');

$this->fileNamer = app(config('medialibrary.file_namer'));
$this->fileNamer = app(config('media-library.file_namer'));

$this->loadingAttributeValue = config('medialibrary.default_loading_attribute_value');
$this->loadingAttributeValue = config('media-library.default_loading_attribute_value');

$this->performOnQueue = config('medialibrary.queue_conversions_by_default', true);
$this->performOnQueue = config('media-library.queue_conversions_by_default', true);
}

public static function create(string $name): self
Expand Down
8 changes: 4 additions & 4 deletions src/Conversions/FileManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ protected function dispatchQueuedConversions(

/** @var PerformConversionsJob $job */
$job = (new $performConversionsJobClass($conversions, $media, $onlyMissing))
->onConnection(config('medialibrary.queue_connection_name'))
->onQueue(config('medialibrary.queue_name'));
->onConnection(config('media-library.queue_connection_name'))
->onQueue(config('media-library.queue_name'));

dispatch($job);

Expand All @@ -117,8 +117,8 @@ protected function generateResponsiveImages(Media $media, bool $withResponsiveIm

/** @var GenerateResponsiveImagesJob $job */
$job = (new $generateResponsiveImagesJobClass($media))
->onConnection(config('medialibrary.queue_connection_name'))
->onQueue(config('medialibrary.queue_name'));
->onConnection(config('media-library.queue_connection_name'))
->onQueue(config('media-library.queue_name'));

dispatch($job);

Expand Down
4 changes: 2 additions & 2 deletions src/Conversions/ImageGenerators/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function requirementsAreInstalled(): bool
public function supportedExtensions(): Collection
{
$extensions = ['png', 'jpg', 'jpeg', 'gif', 'webp', 'avif'];
if (config('medialibrary.image_driver') === 'imagick') {
if (config('media-library.image_driver') === 'imagick') {
$extensions[] = 'tiff';
$extensions[] = 'heic';
$extensions[] = 'heif';
Expand All @@ -32,7 +32,7 @@ public function supportedExtensions(): Collection
public function supportedMimeTypes(): Collection
{
$mimeTypes = ['image/jpeg', 'image/gif', 'image/png', 'image/webp', 'image/avif'];
if (config('medialibrary.image_driver') === 'imagick') {
if (config('media-library.image_driver') === 'imagick') {
$mimeTypes[] = 'image/tiff';
$mimeTypes[] = 'image/heic';
$mimeTypes[] = 'image/heif';
Expand Down
2 changes: 1 addition & 1 deletion src/Conversions/ImageGenerators/ImageGeneratorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ImageGeneratorFactory
{
public static function getImageGenerators(): Collection
{
return collect(config('medialibrary.image_generators'))
return collect(config('media-library.image_generators'))
->map(function ($imageGeneratorClassName, $key) {
$imageGeneratorConfig = [];

Expand Down
4 changes: 2 additions & 2 deletions src/Conversions/ImageGenerators/Video.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class Video extends ImageGenerator
public function convert(string $file, ?Conversion $conversion = null): ?string
{
$ffmpeg = FFMpeg::create([
'ffmpeg.binaries' => config('medialibrary.ffmpeg_path'),
'ffprobe.binaries' => config('medialibrary.ffprobe_path'),
'ffmpeg.binaries' => config('media-library.ffmpeg_path'),
'ffprobe.binaries' => config('media-library.ffprobe_path'),
]);

$video = $ffmpeg->open($file);
Expand Down
6 changes: 3 additions & 3 deletions src/InteractsWithMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static function bootInteractsWithMedia()

public function media(): MorphMany
{
return $this->morphMany(config('medialibrary.media_model'), 'model');
return $this->morphMany(config('media-library.media_model'), 'model');
}

/**
Expand Down Expand Up @@ -138,7 +138,7 @@ public function addMediaFromUrl(string $url, array|string ...$allowedMimeTypes):
throw InvalidUrl::doesNotStartWithProtocol($url);
}

$downloader = config('medialibrary.media_downloader', DefaultDownloader::class);
$downloader = config('media-library.media_downloader', DefaultDownloader::class);
$temporaryFile = (new $downloader())->getTempFile($url);
$this->guardAgainstInvalidMimeType($temporaryFile, $allowedMimeTypes);

Expand Down Expand Up @@ -378,7 +378,7 @@ public function updateMedia(array $newMediaArray, string $collectionName = 'defa
{
$this->removeMediaItemsNotPresentInArray($newMediaArray, $collectionName);

$mediaClass = config('medialibrary.media_model');
$mediaClass = config('media-library.media_model');
$mediaInstance = new $mediaClass();
$keyName = $mediaInstance->getKeyName();

Expand Down
4 changes: 2 additions & 2 deletions src/MediaCollections/Commands/CleanCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@ protected function deleteDeprecatedResponsiveImages(Media $media): void

protected function deleteOrphanedDirectories(): void
{
$diskName = $this->argument('disk') ?: config('medialibrary.disk_name');
$diskName = $this->argument('disk') ?: config('media-library.disk_name');

if (is_null(config("filesystems.disks.{$diskName}"))) {
throw DiskDoesNotExist::create($diskName);
}
$mediaClass = config('medialibrary.media_model');
$mediaClass = config('media-library.media_model');
$mediaInstance = new $mediaClass();
$keyName = $mediaInstance->getKeyName();

Expand Down
2 changes: 1 addition & 1 deletion src/MediaCollections/Exceptions/FileIsTooBig.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static function create(string $path, ?int $size = null): self
{
$fileSize = File::getHumanReadableSize($size ?: filesize($path));

$maxFileSize = File::getHumanReadableSize(config('medialibrary.max_file_size'));
$maxFileSize = File::getHumanReadableSize(config('media-library.max_file_size'));

return new static("File `{$path}` has a size of {$fileSize} which is greater than the maximum allowed {$maxFileSize}");
}
Expand Down
20 changes: 10 additions & 10 deletions src/MediaCollections/FileAdder.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,18 +240,18 @@ public function toMediaCollectionFromRemote(string $collectionName = 'default',

$this->fileSize ??= $storage->size($this->pathToFile);

if ($this->fileSize > config('medialibrary.max_file_size')) {
if ($this->fileSize > config('media-library.max_file_size')) {
throw FileIsTooBig::create($this->pathToFile, $storage->size($this->pathToFile));
}

$mediaClass = config('medialibrary.media_model');
$mediaClass = config('media-library.media_model');
/** @var Media $media */
$media = new $mediaClass();

$media->name = $this->mediaName;

$sanitizedFileName = ($this->fileNameSanitizer)($this->fileName);
$fileName = app(config('medialibrary.file_namer'))->originalFileName($sanitizedFileName);
$fileName = app(config('media-library.file_namer'))->originalFileName($sanitizedFileName);
$this->fileName = $this->appendExtension($fileName, pathinfo($sanitizedFileName, PATHINFO_EXTENSION));

$media->file_name = $this->fileName;
Expand Down Expand Up @@ -286,7 +286,7 @@ public function toMediaCollectionFromRemote(string $collectionName = 'default',
public function toMediaCollection(string $collectionName = 'default', string $diskName = ''): Media
{
$sanitizedFileName = ($this->fileNameSanitizer)($this->fileName);
$fileName = app(config('medialibrary.file_namer'))->originalFileName($sanitizedFileName);
$fileName = app(config('media-library.file_namer'))->originalFileName($sanitizedFileName);
$this->fileName = $this->appendExtension($fileName, pathinfo($sanitizedFileName, PATHINFO_EXTENSION));

if ($this->file instanceof RemoteFile) {
Expand All @@ -303,11 +303,11 @@ public function toMediaCollection(string $collectionName = 'default', string $di

$this->fileSize ??= filesize($this->pathToFile);

if ($this->fileSize > config('medialibrary.max_file_size')) {
if ($this->fileSize > config('media-library.max_file_size')) {
throw FileIsTooBig::create($this->pathToFile);
}

$mediaClass = config('medialibrary.media_model');
$mediaClass = config('media-library.media_model');
/** @var Media $media */
$media = new $mediaClass();

Expand Down Expand Up @@ -367,7 +367,7 @@ protected function determineDiskName(string $diskName, string $collectionName):
}
}

return config('medialibrary.disk_name');
return config('media-library.disk_name');
}

protected function determineConversionsDiskName(string $originalsDiskName, string $collectionName): string
Expand Down Expand Up @@ -460,15 +460,15 @@ protected function processMediaItem(HasMedia $model, Media $media, self $fileAdd
}

if ($this->generateResponsiveImages && (new ImageGenerator())->canConvert($media)) {
$generateResponsiveImagesJobClass = config('medialibrary.jobs.generate_responsive_images', GenerateResponsiveImagesJob::class);
$generateResponsiveImagesJobClass = config('media-library.jobs.generate_responsive_images', GenerateResponsiveImagesJob::class);

$job = new $generateResponsiveImagesJobClass($media);

if ($customConnection = config('medialibrary.queue_connection_name')) {
if ($customConnection = config('media-library.queue_connection_name')) {
$job->onConnection($customConnection);
}

if ($customQueue = config('medialibrary.queue_name')) {
if ($customQueue = config('media-library.queue_name')) {
$job->onQueue($customQueue);
}

Expand Down
6 changes: 3 additions & 3 deletions src/MediaCollections/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ protected function shouldCopyFileOnDisk(RemoteFile $file, Media $media, string $
return false;
}

if ((is_countable(config('medialibrary.remote.extra_headers')) ? count(config('medialibrary.remote.extra_headers')) : 0) > 0) {
if ((is_countable(config('media-library.remote.extra_headers')) ? count(config('media-library.remote.extra_headers')) : 0) > 0) {
return false;
}

Expand Down Expand Up @@ -189,7 +189,7 @@ public function getRemoteHeadersForFile(
): array {
$mimeTypeHeader = ['ContentType' => $mimeType ?: File::getMimeType($file)];

$extraHeaders = config('medialibrary.remote.extra_headers');
$extraHeaders = config('media-library.remote.extra_headers');

return array_merge(
$mimeTypeHeader,
Expand Down Expand Up @@ -277,7 +277,7 @@ protected function renameMediaFile(Media $media): void

protected function renameConversionFiles(Media $media): void
{
$mediaWithOldFileName = config('medialibrary.media_model')::find($media->id);
$mediaWithOldFileName = config('media-library.media_model')::find($media->id);
$mediaWithOldFileName->file_name = $mediaWithOldFileName->getOriginal('file_name');

$conversionDirectory = $this->getConversionDirectory($media);
Expand Down
6 changes: 3 additions & 3 deletions src/MediaCollections/HtmlableMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function toHtml()
$attributeString = ' '.$attributeString;
}

$loadingAttributeValue = config('medialibrary.default_loading_attribute_value');
$loadingAttributeValue = config('media-library.default_loading_attribute_value');

if ($this->conversionName !== '') {
$conversionObject = ConversionCollection::createForMedia($this->media)->getByName($this->conversionName);
Expand All @@ -74,7 +74,7 @@ public function toHtml()
$height = '';

if ($this->media->hasResponsiveImages($this->conversionName)) {
$viewName = config('medialibrary.responsive_images.use_tiny_placeholders')
$viewName = config('media-library.responsive_images.use_tiny_placeholders')
? 'responsiveImageWithPlaceholder'
: 'responsiveImage';

Expand All @@ -87,7 +87,7 @@ public function toHtml()
$media = $this->media;
$conversion = $this->conversionName;

return view("medialibrary::{$viewName}", compact(
return view("media-library::{$viewName}", compact(
'media',
'conversion',
'attributeString',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function toHtml()

public function jsonSerialize(): array
{
if (config('medialibrary.use_default_collection_serialization')) {
if (config('media-library.use_default_collection_serialization')) {
return parent::jsonSerialize();
}

Expand Down
2 changes: 1 addition & 1 deletion src/MediaCollections/Models/Observers/MediaObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function updating(Media $media)
/** @var Filesystem $filesystem */
$filesystem = app(Filesystem::class);

if (config('medialibrary.moves_media_on_update')) {
if (config('media-library.moves_media_on_update')) {
$filesystem->syncMediaPath($media);
}

Expand Down
12 changes: 6 additions & 6 deletions src/MediaLibraryServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public function configurePackage(Package $package): void
{
$package
->name('laravel-medialibrary')
->hasConfigFile()
->hasConfigFile('media-library')
->hasMigration('create_media_table')
->hasViews()
->hasViews('media-library')
->hasCommands([
RegenerateCommand::class,
ClearCommand::class,
Expand All @@ -31,18 +31,18 @@ public function configurePackage(Package $package): void

public function packageBooted()
{
$mediaClass = config('medialibrary.media_model', Media::class);
$mediaClass = config('media-library.media_model', Media::class);

$mediaClass::observe(new MediaObserver());
}

public function packageRegistered()
{
$this->app->bind(WidthCalculator::class, config('medialibrary.responsive_images.width_calculator'));
$this->app->bind(TinyPlaceholderGenerator::class, config('medialibrary.responsive_images.tiny_placeholder_generator'));
$this->app->bind(WidthCalculator::class, config('media-library.responsive_images.width_calculator'));
$this->app->bind(TinyPlaceholderGenerator::class, config('media-library.responsive_images.tiny_placeholder_generator'));

$this->app->scoped(MediaRepository::class, function () {
$mediaClass = config('medialibrary.media_model');
$mediaClass = config('media-library.media_model');

return new MediaRepository(new $mediaClass());
});
Expand Down
2 changes: 1 addition & 1 deletion src/ResponsiveImages/RegisteredResponsiveImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function getSrcset(): string
->map(fn (ResponsiveImage $responsiveImage) => "{$responsiveImage->url()} {$responsiveImage->width()}w")
->implode(', ');

$shouldAddPlaceholderSvg = config('medialibrary.responsive_images.use_tiny_placeholders')
$shouldAddPlaceholderSvg = config('media-library.responsive_images.use_tiny_placeholders')
&& $this->getPlaceholderSvg();

if ($shouldAddPlaceholderSvg) {
Expand Down
4 changes: 2 additions & 2 deletions src/ResponsiveImages/ResponsiveImageGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(
protected WidthCalculator $widthCalculator,
protected TinyPlaceholderGenerator $tinyPlaceholderGenerator
) {
$this->fileNamer = app(config('medialibrary.file_namer'));
$this->fileNamer = app(config('media-library.file_namer'));
}

public function generateResponsiveImages(Media $media): void
Expand Down Expand Up @@ -133,7 +133,7 @@ public function generateTinyJpg(

$originalImageHeight = $originalImage->getHeight();

$svg = view('medialibrary::placeholderSvg', compact(
$svg = view('media-library::placeholderSvg', compact(
'originalImageWidth',
'originalImageHeight',
'tinyImageBase64'
Expand Down
2 changes: 1 addition & 1 deletion src/Support/FileRemover/FileRemoverFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class FileRemoverFactory
{
public static function create(Media $media): FileRemover
{
$fileRemoverClass = config('medialibrary.file_remover_class');
$fileRemoverClass = config('media-library.file_remover_class');

static::guardAgainstInvalidFileRemover($fileRemoverClass);

Expand Down
2 changes: 1 addition & 1 deletion src/Support/ImageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ImageFactory
{
public static function load(string $path): ImageDriver
{
return Image::useImageDriver(config('medialibrary.image_driver'))
return Image::useImageDriver(config('media-library.image_driver'))

Check failure on line 12 in src/Support/ImageFactory.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined method Spatie\Image\Drivers\ImageDriver::loadFile().
->loadFile($path);
}
}
2 changes: 1 addition & 1 deletion src/Support/PathGenerator/DefaultPathGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function getPathForResponsiveImages(Media $media): string
*/
protected function getBasePath(Media $media): string
{
$prefix = config('medialibrary.prefix', '');
$prefix = config('media-library.prefix', '');

if ($prefix !== '') {
return $prefix.'/'.$media->getKey();
Expand Down
4 changes: 2 additions & 2 deletions src/Support/PathGenerator/PathGeneratorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public static function create(Media $media): PathGenerator

protected static function getPathGeneratorClass(Media $media)
{
$defaultPathGeneratorClass = config('medialibrary.path_generator');
$defaultPathGeneratorClass = config('media-library.path_generator');

foreach (config('medialibrary.custom_path_generators', []) as $modelClass => $customPathGeneratorClass) {
foreach (config('media-library.custom_path_generators', []) as $modelClass => $customPathGeneratorClass) {
if (static::mediaBelongToModelClass($media, $modelClass)) {
return $customPathGeneratorClass;
}
Expand Down
Loading

0 comments on commit 0e6e6e1

Please sign in to comment.