If basic configuration is not enough for you and you need more control, then use the following service configuration:
you only need one option:
Option | Type | Required |
---|---|---|
service |
String |
True |
Example:
artgris_file_manager:
conf:
perso:
service: "custom_service"
This service need to implement CustomConfServiceInterface
<?php
namespace AppBundle\Service;
use Artgris\Bundle\FileManagerBundle\Service\CustomConfServiceInterface;
class CustomService implements CustomConfServiceInterface
{
public function getConf($extra = []) {
...
}
}
getconf($extra)
must return an Array of the configuration:
public function getConf($extra = []) {
return [
'dir' => '%kernel.project_dir%/public'
...
];
}
Do not forget to configure your services.yml
services:
custom_service:
class: AppBundle\Service\CustomService
Browse the
/manager/?conf=perso
URL to get access to this File Manager
You can inject extra
parameters in your service via URL:
Example:
path('file_manager', {module:'tiny', type:'image', conf:'perso', extra: {'user':'miamolex', 'allow': true}})
Here, I add 2 extra parameters, which I recover in my Service:
public function getConf($extra = []) {
$user = $extra['user'] # miamolex
$allow = $extra['allow'] # true
...
With this service
configuration, you can define (for example) a folder for each user
<?php
namespace AppBundle\Service;
use Artgris\Bundle\FileManagerBundle\Service\CustomConfServiceInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
class CustomService implements CustomConfServiceInterface
{
/**
* @var TokenStorage
*/
private $tokenStorage;
/**
* CustomService constructor.
* @param TokenStorage $tokenStorage
*/
public function __construct(TokenStorage $tokenStorage)
{
$this->tokenStorage = $tokenStorage;
}
public function getConf($extra = [])
{
$folder = 'user/' . $this->tokenStorage->getToken()->getUser();
$fs = new Filesystem();
if (!$fs->exists($folder)) {
$fs->mkdir($folder);
}
return ['dir' => $folder];
}
}
with
custom_service:
public: true
class: AppBundle\Service\CustomService
arguments: ['@security.token_storage']
You can include all the options of jQuery File Upload
in return
(to make it easier than .yml):
Example
<?php
namespace AppBundle\Service;
use Artgris\Bundle\FileManagerBundle\Service\CustomConfServiceInterface;
class CustomService implements CustomConfServiceInterface
{
public function getConf($extra = [])
{
return [
'dir' => '%kernel.project_dir%/public/perso',
'upload' => [
'image_versions' => [
'medium' => [
'auto_orient' => true,
'max_width' => 10
]
],
]
];
}
}