2lenet / file-bundle
File Bundle
Installs: 163
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 0
Type:symfony-bundle
Requires
- symfony/framework-bundle: ^6.0|^7.0
Requires (Dev)
- ergebnis/phpstan-rules: ^2.0
- phpstan/phpstan: ^1.9
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-doctrine: ^1.3
- phpstan/phpstan-mockery: ^1.1
- phpstan/phpstan-phpunit: ^1.3
- phpstan/phpstan-strict-rules: ^1.5
- phpstan/phpstan-symfony: ^1.2
- phpunit/phpunit: ^10.0
- slevomat/coding-standard: ^8.0
- squizlabs/php_codesniffer: ^3.5
README
Symfony bundle that standardize the way of handling data file associated with an entity
Installation
The bundle is not yet on packagist make sure to add the following to your composer.json
file:
{ "url": "https://github.com/2lenet/FileBundle", "type": "git" }
Install with composer:
composer require 2lenet/file-bundle
Usage
in your controller or service juste use the fileManager to get the db and absolute path to use to store your data.
$fileSpec = $this->fileManager->getLocalFilename( ENTITY::PDFSTORAGENAME, $object, "pdf" );
- This function take a first parameter which is the name of the store. Une one store for each field in each entity. It's a good practice to set a constant in the entitiy Class
- The second parameter is an object ( good to have a getId on it but not required ). Optionnally you can have a getDateForFilename to get the date to use for creating the folders.
- The third optionnal parameter is the extension to add to the file ( default .bin). Don't set the .
The function return a FileSpec object with two attribute
- dbPath is the path to use to store in your database ( relative from the projectDir )
- absPath is the filename to use to write your data ( open it with standard functions )
Path are build this way ( $projectDir / data / $storeName / Y / M / D / $objet->getId() . $ext ) if the folder does not exist it is created with the right right. Y/M/D is the year, month and day from the $object->getDateForFilename() if it exist, instead it use the today date.
file_put_contents($fileSpec->absPath,$youdata); $object->setLocalPdf($fileSpec->dbPath);