Skip to content

Commit

Permalink
options enumeration
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas MURE committed Mar 20, 2015
1 parent 4c9ecec commit b32a5d2
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 35 deletions.
60 changes: 39 additions & 21 deletions Configuration/ElFinderConfigurationReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,50 @@ public function getConfiguration($instance)
$driver = $this->container->has($parameter['driver']) ? $this->container->get($parameter['driver']) : null;

$driverOptions = array(
'driver' => $parameter['driver'],
'service' => $driver,
'glideURL' => $parameter['glide_url'],
'glideKey' => $parameter['glide_key'],
'disabled' => $parameter['disabled_commands'],
'plugin' => $parameter['plugin'],
'alias' => $parameter['alias'],
'path' => $path . $homeFolder, //removed slash for Flysystem compatibility
'URL' => isset($parameter['url']) && $parameter['url']
'driver' => $parameter['driver'],
'service' => $driver,
'glideURL' => $parameter['glide_url'],
'glideKey' => $parameter['glide_key'],
'plugin' => $parameter['plugin'],
'path' => $path . $homeFolder, //removed slash for Flysystem compatibility
'startPath' => $parameter['start_path'],
'URL' => isset($parameter['url']) && $parameter['url']
? strpos($parameter['url'], 'http') === 0
? $parameter['url']
: sprintf('%s://%s%s/%s/%s', $request->getScheme(), $request->getHttpHost(), $request->getBasePath(), $parameter['url'], $homeFolder)
: sprintf('%s://%s%s/%s/%s', $request->getScheme(), $request->getHttpHost(), $request->getBasePath(), $path, $homeFolder),
'uploadAllow' => $parameter['upload_allow'],
'uploadDeny' => $parameter['upload_deny'],
'uploadMaxSize' => $parameter['upload_max_size']
'alias' => $parameter['alias'],
'mimeDetect' => $parameter['mime_detect'],
'mimefile' => $parameter['mimefile'],
'imgLib' => $parameter['img_lib'],
'tmbPath' => $parameter['tmb_path'],
'tmbPathMode' => $parameter['tmb_path_mode'],
'tmbUrl' => $parameter['tmb_url'],
'tmbSize' => $parameter['tmb_size'],
'tmbCrop' => $parameter['tmb_crop'],
'tmbBgColor' => $parameter['tmb_bg_color'],
'copyOverwrite' => $parameter['copy_overwrite'],
'copyJoin' => $parameter['copy_join'],
'copyFrom' => $parameter['copy_from'],
'copyTo' => $parameter['copy_to'],
'uploadOverwrite' => $parameter['upload_overwrite'],
'uploadAllow' => $parameter['upload_allow'],
'uploadDeny' => $parameter['upload_deny'],
'uploadMaxSize' => $parameter['upload_max_size'],
'defaults' => $parameter['defaults'],
'attributes' => $parameter['attributes'],
'acceptedName' => $parameter['accepted_name'],
'accessControl' => $parameter['access_control'],
'accessControlData' => $parameter['access_control_data'],
'disabled' => $parameter['disabled_commands'],
'treeDeep' => $parameter['tree_deep'],
'checkSubfolders' => $parameter['check_subfolders'],
'separator' => $parameter['separator'],
'timeFormat' => $parameter['time_format'],
'archiveMimes' => $parameter['archive_mimes'],
'archivers' => $parameter['archivers']
);

if(!$parameter['show_hidden']) {
$driverOptions['accessControl'] = array($this, 'access');
};
Expand All @@ -113,15 +140,6 @@ public function getConfiguration($instance)
$driverOptions['filesystem'] = $filesystem;
}

if (isset($parameter['options'])) {
foreach($parameter['options'] as $option => $value) {
// we do not override previously defined options from config.yml file
if (!isset($driverOptions[$option])) {
$driverOptions[$option] = $value;
}
}
}

$options['roots'][] = array_merge($driverOptions, $this->configureDriver($parameter));
}

Expand Down
56 changes: 46 additions & 10 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ public function getConfigTreeBuilder()
->requiresAtLeastOneElement()
->prototype('array')
->children()
->scalarNode('driver')
->isRequired()
->defaultValue('LocalFileSystem')->end()
->arrayNode('flysystem')
->canBeEnabled()
->children()
Expand All @@ -64,16 +61,28 @@ public function getConfigTreeBuilder()
->end()
->scalarNode('glide_url')->defaultValue('')->end()
->scalarNode('glide_key')->defaultValue('')->end()
->arrayNode('disabled_commands')
->prototype('scalar')->end()
->defaultValue(array())
->scalarNode('driver')
->isRequired()
->defaultValue('LocalFileSystem')
->end()
->scalarNode('path')->defaultValue('')->end()
->scalarNode('start_path')->defaultValue('')->end()
->scalarNode('url')->end()
->append($this->createPluginsNode())
->booleanNode('show_hidden')->defaultFalse()->end()
->scalarNode('alias')->defaultValue('')->end()
->integerNode('tree_deep')->defaultValue(0)->end()
->scalarNode('mime_detect')->defaultValue('auto')->end()
->scalarNode('mimefile')->defaultValue('')->end()
->scalarNode('img_lib')->defaultValue('auto')->end()
->scalarNode('tmb_path')->defaultValue('.tmb')->end()
->scalarNode('tmb_path_mode')->defaultValue(0777)->end()
->scalarNode('tmb_url')->defaultValue('')->end()
->integerNode('tmb_size')->defaultValue(48)->end()
->booleanNode('tmb_crop')->defaultTrue()->end()
->scalarNode('tmb_bg_color')->defaultValue('#ffffff')->end()
->booleanNode('copy_overwrite')->defaultTrue()->end()
->booleanNode('copy_join')->defaultTrue()->end()
->booleanNode('copy_from')->defaultTrue()->end()
->booleanNode('copy_to')->defaultTrue()->end()
->booleanNode('upload_overwrite')->defaultTrue()->end()
->arrayNode('upload_allow')
->prototype('scalar')->end()
->defaultValue(array('image'))
Expand All @@ -83,11 +92,38 @@ public function getConfigTreeBuilder()
->defaultValue(array('all'))
->end()
->scalarNode('upload_max_size')->defaultValue('2M')->end()
->arrayNode('options')
->arrayNode('defaults')
->useAttributeAsKey('defaults')
->normalizeKeys(false)
->prototype('boolean')->end()
->defaultValue(array('read' => true, 'write' => true))
->end()
->arrayNode('attributes')
->prototype('scalar')->end()
->defaultValue(array())
->end()
->scalarNode('accepted_name')->defaultValue('/^\w[\w\s\.\%\-]*$/u')->end()
->scalarNode('access_control')->defaultValue(null)->end()
->scalarNode('access_control_data')->defaultValue(null)->end()
->arrayNode('disabled_commands')
->prototype('scalar')->end()
->defaultValue(array())
->end()
->integerNode('tree_deep')->defaultValue(1)->end()
->booleanNode('check_subfolders')->defaultTrue()->end()
->scalarNode('separator')->defaultValue(DIRECTORY_SEPARATOR)->end()
->scalarNode('date_format')->defaultValue('j M Y H:i')->end()
->scalarNode('time_format')->defaultValue('H:i')->end()
->arrayNode('archive_mimes')
->prototype('scalar')->end()
->defaultValue(array())
->end()
->arrayNode('archivers')
->prototype('scalar')->end()
->defaultValue(array())
->end()
->append($this->createPluginsNode())
->booleanNode('show_hidden')->defaultFalse()->end()
->arrayNode('dropbox_settings')
->canBeEnabled()
->children()
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,7 @@ fm_elfinder:
upload_allow: ['image/png', 'image/jpg', 'image/jpeg']
upload_deny: ['all']
upload_max_size: 2M
options: # used to override connector's default options (optional)
'tmbSize': 64
# ...

```
* default - instance of elfinder, can be used to define multiple configurations of ElFinder, allows simultaneous configuration for different types of WYSIWYG editors in your project
* path - define root directory for the files inside web/ directory, default is "uploads". Make sure to set proper write/read permissions to this directory.
Expand All @@ -184,7 +182,9 @@ fm_elfinder:
* upload_allow: ['image/png', 'image/jpg', 'image/jpeg']
* upload_deny: ['all']
* upload_max_size: 2M
* options - Used to override connector's default options. Each key is a string corresponding to option name. You can go [here](https://github.com/Studio-42/elFinder/wiki/Connector-configuration-options "connector options list") to see all options list.
You can see the full list of roots options [here](https://github.com/Studio-42/elFinder/wiki/Connector-configuration-options#root-options "connector options list"). To use them,
convert camelCased option name to under_scored option name.
**Note:** `crypt_lib` option is not available as not implemented yet by elFinder PHP library.

### Use multiple upload folder by instance
You can set multiple upload root folder by instance configuration.
Expand Down

0 comments on commit b32a5d2

Please sign in to comment.