tobento / app-file-storage
App file storage support.
Requires
- php: >=8.0
- psr/http-factory: ^1.0
- tobento/app: ^1.0
- tobento/app-http: ^1.0 || ^1.1
- tobento/app-migration: ^1.0
- tobento/service-file-storage: ^1.0
Requires (Dev)
- nyholm/psr7: ^1.4
- phpunit/phpunit: ^9.5
- tobento/service-filesystem: ^1.0
- vimeo/psalm: ^4.0
README
File storage support for the app.
Table of Contents
Getting Started
Add the latest version of the app file storage project running this command.
composer require tobento/app-file-storage
Requirements
- PHP 8.0 or greater
Documentation
App
Check out the App Skeleton if you are using the skeleton.
You may also check out the App to learn more about the app in general.
File Storage Boot
The file storage boot does the following:
- installs and loads file storage config file
- creates file storages based on storage config file
use Tobento\App\AppFactory; // Create the app $app = (new AppFactory())->createApp(); // Add directories: $app->dirs() ->dir(realpath(__DIR__.'/../'), 'root') ->dir(realpath(__DIR__.'/../app/'), 'app') ->dir($app->dir('app').'config', 'config', group: 'config') ->dir($app->dir('root').'public', 'public') ->dir($app->dir('root').'vendor', 'vendor'); // Adding boots: $app->boot(\Tobento\App\FileStorage\Boot\FileStorage::class); // Run the app: $app->run();
You may check out the File Storage Service to learn more about it.
File Storage Config
The configuration for the file storage is located in the app/config/file_storage.php
file at the default App Skeleton config location where you can specify the pools and caches for your application.
File Storage Usage
You can access the file storage(s) in several ways:
Using the app
use Tobento\App\AppFactory; use Tobento\Service\FileStorage\StoragesInterface; use Tobento\Service\FileStorage\StorageInterface; $app = (new AppFactory())->createApp(); // Add directories: $app->dirs() ->dir(realpath(__DIR__.'/../'), 'root') ->dir(realpath(__DIR__.'/../app/'), 'app') ->dir($app->dir('app').'config', 'config', group: 'config') ->dir($app->dir('root').'public', 'public') ->dir($app->dir('root').'vendor', 'vendor'); // Adding boots: $app->boot(\Tobento\App\FileStorage\Boot\FileStorage::class); $app->booting(); $storages = $app->get(StoragesInterface::class); $defaultStorage = $app->get(StorageInterface::class); // Run the app: $app->run();
You may check out the File Storage Service to learn more about in general.
Check out the Storages Interface to learn more about storages.
Check out the Storage Interface to learn more about the storage.
Using autowiring
You can also request the interfaces in any class resolved by the app:
use Tobento\Service\FileStorage\StoragesInterface; use Tobento\Service\FileStorage\StorageInterface; class SomeService { public function __construct( protected StoragesInterface $storages, protected StorageInterface $storage, ) {} }