add utils

This commit is contained in:
Simon Vieille 2022-05-07 13:47:17 +02:00
parent abd6d0056a
commit d580af9691
Signed by: deblan
GPG key ID: 579388D585F70417
7 changed files with 75 additions and 0 deletions

6
docs/utils/cache.md Normal file
View file

@ -0,0 +1,6 @@
# Cache Manager
* Service: `App\Core\Cache\SymfonyCacheManager`
* Methods:
* `cleanRouting()`: clear the cache of routes
* `cleanAll(OutputInterface $output = null)`: clean and warmup all cache

1
docs/utils/doctrine.md Normal file
View file

@ -0,0 +1 @@
# Doctrine

View file

@ -0,0 +1,21 @@
# File attribute
`App\Core\File\FileAttribute::handleFile` transforms a file path to an instance of `Symfony\Component\HttpFoundation\File\File`. You can specify another class if needed.
If the path is `null` or if the file does not exist, it returns `null`.
```
use App\Core\File\FileAttribute;
use App\Foo\Bar;
$path = 'path/to/file';
$file = FileAttribute::handleFile($path); // returns an instance of File
$path = 'path/to/removed_file';
$file = FileAttribute::handleFile($path); // returns null
$path = null;
$file = FileAttribute::handleFile($path); // returns null
$path = 'path/to/file';
$file = FileAttribute::handleFile($path, Bar::class); // returns an instance of Bar
```

View file

@ -0,0 +1,38 @@
# File upload handler
`App\Core\Form\FileUploadHandler` is a service and helps you to upload a file. See example below.
```
use App\Core\Form\FileUploadHandler;
use App\Entity\Foo;
use App\Form\FooType;
use Symfony\Component\HttpFoundation\Request;
public function upload(Request $request, FileUploadHandler $fileUpload)
{
$entity = new Foo();
$form = $this->createForm(FooType::class, $foo);
if ($request->isMethod('POST')) {
$form->handleRequest($request);
if ($form->isValid()) {
$fileDirectory = 'uploads/';
$keepOriginalFilename = false;
$fileUpload->handleForm(
$form->get('image')->getData(), // Symfony\Component\HttpFoundation\File\UploadedFile or null
$fileDirectory,
// optional
function ($filename) use ($entity, $fileDirectory) {
$entity->setImage($fileDirectory.$filename);
},
// optional
$keepOriginalFilename
);
// ...
}
}
}
```

1
docs/utils/mail.md Normal file
View file

@ -0,0 +1 @@
# Mail

1
docs/utils/slug.md Normal file
View file

@ -0,0 +1 @@
# Slug

View file

@ -32,6 +32,13 @@ nav:
- TinyMCE: utils/editors/tinymce.md
- GrapesJS: utils/editors/grapesjs.md
- Editor.js: utils/editors/editorjs.md
- Utils:
- Cache Manager: utils/cache.md
- Doctrine: utils/doctrine.md
- File upload handler: utils/file_handler.md
- File attribute: utils/file_attribute.md
- Mail notifier: utils/mail.md
- Slug: utils/slug.md
- Users:
- Users: users.md
- Tasks: