Skip to content

Commit

Permalink
First import
Browse files Browse the repository at this point in the history
  • Loading branch information
javiereguiluz committed Jan 16, 2015
1 parent 26237f3 commit f08250a
Show file tree
Hide file tree
Showing 27 changed files with 3,040 additions and 2 deletions.
474 changes: 474 additions & 0 deletions Controller/AdminController.php

Large diffs are not rendered by default.

57 changes: 57 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

/*
* This file is part of the EasyAdminBundle.
*
* (c) Javier Eguiluz <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace JavierEguiluz\Bundle\EasyAdminBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('easy_admin');

$rootNode
->children()
->scalarNode('site_name')
->defaultValue('Easy Admin')
->info('The name displayed as the title of the administration zone (e.g. comapny name, project name).')
->end()
->integerNode('list_max_results')
->defaultValue('15')

This comment has been minimized.

Copy link
@stof

stof Jan 16, 2015

the default value of an integer node should be an integer, not a string

->info('The maximum number of items to show on listing and search pages.')
->end()
->arrayNode('assets')
->performNoDeepMerging()
->addDefaultsIfNotSet()
->children()
->arrayNode('css')
->prototype('scalar')->end()
->end()
->arrayNode('js')
->prototype('scalar')->end()
->end()
->end()
->end()
->variableNode('list_actions')
->info('The actions to show for each item of listing and search pages. Only "edit" and "show" options are avaialable.')
->example(array('edit', 'show'))
->end()
->variableNode('entities')

This comment has been minimized.

Copy link
@stof

stof Jan 16, 2015

using a variable node means that configs cannot get merged together. It also means there is no validation of the configuration (and your DI extension does not validate it. It would trigger notices or errors for invalid configs)

It would be much better to define the supported configuration properly here (all the work you do in the DI extension to normalize the configuration could actually be moved here). I could contribute for this if you don't know how to handle it with the Config component.

->info('The list of entities to manage in the administration zone.')
->end()
->end();

return $treeBuilder;
}
}
86 changes: 86 additions & 0 deletions DependencyInjection/EasyAdminExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

/*
* This file is part of the EasyAdminBundle.
*
* (c) Javier Eguiluz <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace JavierEguiluz\Bundle\EasyAdminBundle\DependencyInjection;

use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class EasyAdminExtension extends Extension
{
private $defaultConfigOptions = array(
'site_name' => 'ACME',
'list_max_results' => 15,
'list_actions' => array('edit'),
'entities' => array(),
);

public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$options = array_replace($this->defaultConfigOptions, $config);

This comment has been minimized.

Copy link
@stof

stof Jan 16, 2015

why not handling this in the Configuration class ?

$options['entities'] = $this->processEntityConfiguration($options['entities']);

$container->setParameter('easy_admin.config', $options);
}

protected function processEntityConfiguration($entitiesConfiguration)
{
if (0 === count($entitiesConfiguration)) {
return $entitiesConfiguration;
}

$entitiesConfigurationKeys = array_keys($entitiesConfiguration);
if (is_integer($entitiesConfigurationKeys[0])) {
return $this->processEntityConfigurationFromSimpleParameters($entitiesConfiguration);
}

return $this->processEntityConfigurationFromComplexParameters($entitiesConfiguration);
}

private function processEntityConfigurationFromSimpleParameters($config)
{
$entities = array();
foreach ($config as $entityClass) {
$parts = explode('\\', $entityClass);
$entityName = array_pop($parts);

$entities[$entityName] = array(
'label' => $entityName,
'name' => $entityName,
'class' => $entityClass,
);
}

return $entities;
}

private function processEntityConfigurationFromComplexParameters($config)
{
$entities = array();
foreach ($config as $customEntityName => $entityConfiguration) {
$parts = explode('\\', $entityConfiguration['class']);
$realEntityName = array_pop($parts);

// copy the original entity to not loose any of its configuration
$entities[$realEntityName] = $config[$customEntityName];

// process the original configuration to use the format needed by the application
$entities[$realEntityName]['label'] = $customEntityName;
$entities[$realEntityName]['name'] = $realEntityName;
$entities[$realEntityName]['class'] = $entityConfiguration['class'];
}

return $entities;
}
}
18 changes: 18 additions & 0 deletions EasyAdminBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

/*
* This file is part of the EasyAdminBundle.
*
* (c) Javier Eguiluz <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace JavierEguiluz\Bundle\EasyAdminBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class EasyAdminBundle extends Bundle
{
}
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<img src="https://cloud.githubusercontent.com/assets/73419/5748433/476724ec-9c40-11e4-8f7a-5916c1212a22.png" alt="EasyAdmin" title="EasyAdmin" />

EasyAdmin
=========

Expand Down
Binary file added Resources/public/fonts/FontAwesome.otf
Binary file not shown.
Binary file added Resources/public/fonts/fontawesome-webfont.eot
Binary file not shown.
Loading

0 comments on commit f08250a

Please sign in to comment.