52 lines
2.1 KiB
PHP
52 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace Modules\Core\Providers;
|
|
|
|
use Illuminate\Support\Facades\Event;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use InvalidArgumentException;
|
|
use Modules\Core\Cart\Events\CartLineAdded;
|
|
use Modules\Core\Checkout\Events\OrderPlaced;
|
|
use Modules\Core\File\Adapters\LocalFileAdapter;
|
|
use Modules\Core\File\Commands\PruneUnownedFilesCommand;
|
|
use Modules\Core\File\Contracts\FileAdapterInterface;
|
|
use Modules\Core\File\Listeners\AttachCustomFieldFileToCartLine;
|
|
use Modules\Core\File\Listeners\TransferCustomFieldFileOwnership;
|
|
|
|
class FileServiceProvider extends ServiceProvider
|
|
{
|
|
public function register(): void
|
|
{
|
|
// Same pattern as ShippingServiceProvider's CarrierFulfillmentInterface
|
|
// binding — a plain param ('disk' here, 'carrier' there) picks which
|
|
// concrete adapter Modules\Core\File\Services\FileService actually
|
|
// talks to. Adding a real S3FileAdapter later is one class plus one
|
|
// more match arm here; nothing that already calls FileService changes.
|
|
$this->app->bind(FileAdapterInterface::class, function ($app, array $params) {
|
|
$disk = $params['disk'] ?? 'local';
|
|
|
|
return match ($disk) {
|
|
'local' => new LocalFileAdapter(Storage::disk($disk)),
|
|
default => throw new InvalidArgumentException("No FileAdapterInterface available for disk \"{$disk}\"."),
|
|
};
|
|
});
|
|
}
|
|
|
|
public function boot(): void
|
|
{
|
|
// Signed-URL auth only, same model as Shipping\Http\Controllers\
|
|
// DownloadShipmentLabelController — see that route's own docblock.
|
|
// Migrations live in the shared database/migrations directory
|
|
// CoreServiceProvider already loads; nothing more to register here.
|
|
$this->loadRoutesFrom(__DIR__.'/../File/routes/web.php');
|
|
|
|
Event::listen(CartLineAdded::class, AttachCustomFieldFileToCartLine::class);
|
|
Event::listen(OrderPlaced::class, TransferCustomFieldFileOwnership::class);
|
|
|
|
if ($this->app->runningInConsole()) {
|
|
$this->commands([PruneUnownedFilesCommand::class]);
|
|
}
|
|
}
|
|
}
|