mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-27 10:03:49 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,20 +1,10 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2014-2018 Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\DependencyInjection;
|
||||
@@ -23,60 +13,64 @@ use Chill\MainBundle\Controller\AddressApiController;
|
||||
use Chill\MainBundle\Controller\LocationController;
|
||||
use Chill\MainBundle\Controller\LocationTypeController;
|
||||
use Chill\MainBundle\Controller\UserController;
|
||||
use Chill\MainBundle\Doctrine\DQL\JsonbArrayLength;
|
||||
use Chill\MainBundle\Doctrine\DQL\STContains;
|
||||
use Chill\MainBundle\Doctrine\DQL\StrictWordSimilarityOPS;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Entity\UserJob;
|
||||
use Chill\MainBundle\Form\UserJobType;
|
||||
use Chill\MainBundle\Form\UserType;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||
use Symfony\Component\DependencyInjection\Loader;
|
||||
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
|
||||
use Chill\MainBundle\DependencyInjection\Widget\Factory\WidgetFactoryInterface;
|
||||
use Chill\MainBundle\DependencyInjection\Configuration;
|
||||
use Chill\MainBundle\Doctrine\DQL\GetJsonFieldByKey;
|
||||
use Chill\MainBundle\Doctrine\DQL\Unaccent;
|
||||
use Chill\MainBundle\Doctrine\DQL\JsonAggregate;
|
||||
use Chill\MainBundle\Doctrine\DQL\JsonbArrayLength;
|
||||
use Chill\MainBundle\Doctrine\DQL\JsonbExistsInArray;
|
||||
use Chill\MainBundle\Doctrine\DQL\Similarity;
|
||||
use Chill\MainBundle\Doctrine\DQL\OverlapsI;
|
||||
use Chill\MainBundle\Doctrine\DQL\Replace;
|
||||
use Chill\MainBundle\Doctrine\DQL\Similarity;
|
||||
use Chill\MainBundle\Doctrine\DQL\STContains;
|
||||
use Chill\MainBundle\Doctrine\DQL\StrictWordSimilarityOPS;
|
||||
use Chill\MainBundle\Doctrine\DQL\Unaccent;
|
||||
use Chill\MainBundle\Doctrine\ORM\Hydration\FlatHierarchyEntityHydrator;
|
||||
use Chill\MainBundle\Doctrine\Type\NativeDateIntervalType;
|
||||
use Chill\MainBundle\Doctrine\Type\PointType;
|
||||
use Chill\MainBundle\Entity\Location;
|
||||
use Chill\MainBundle\Entity\LocationType;
|
||||
use Chill\MainBundle\Form\LocationTypeType;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Entity\UserJob;
|
||||
use Chill\MainBundle\Form\LocationFormType;
|
||||
use Chill\MainBundle\Form\LocationTypeType;
|
||||
use Chill\MainBundle\Form\UserJobType;
|
||||
use Chill\MainBundle\Form\UserType;
|
||||
use Exception;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
|
||||
use Symfony\Component\DependencyInjection\Loader;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||
|
||||
/**
|
||||
* Class ChillMainExtension
|
||||
* This class load config for chillMainExtension.
|
||||
*
|
||||
* @package Chill\MainBundle\DependencyInjection
|
||||
*/
|
||||
class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
||||
class ChillMainExtension extends Extension implements
|
||||
PrependExtensionInterface,
|
||||
Widget\HasWidgetFactoriesExtensionInterface
|
||||
{
|
||||
/**
|
||||
* widget factory
|
||||
* widget factory.
|
||||
*
|
||||
* @var WidgetFactoryInterface[]
|
||||
*/
|
||||
protected $widgetFactories = array();
|
||||
protected $widgetFactories = [];
|
||||
|
||||
/**
|
||||
* @param WidgetFactoryInterface $factory
|
||||
*/
|
||||
public function addWidgetFactory(WidgetFactoryInterface $factory)
|
||||
{
|
||||
$this->widgetFactories[] = $factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Chill\MainBundle\DependencyInjection\Configuration|object|\Symfony\Component\Config\Definition\ConfigurationInterface|null
|
||||
*/
|
||||
public function getConfiguration(array $config, ContainerBuilder $container)
|
||||
{
|
||||
return new Configuration($this->widgetFactories, $container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return WidgetFactoryInterface[]
|
||||
*/
|
||||
@@ -86,10 +80,7 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* @param array $configs
|
||||
* @param ContainerBuilder $container
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
@@ -101,38 +92,55 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
||||
$container->setParameter('chill_main', $config);
|
||||
|
||||
// legacy config
|
||||
$container->setParameter('chill_main.installation_name',
|
||||
$config['installation_name']);
|
||||
$container->setParameter(
|
||||
'chill_main.installation_name',
|
||||
$config['installation_name']
|
||||
);
|
||||
|
||||
$container->setParameter('chill_main.available_languages',
|
||||
$config['available_languages']);
|
||||
$container->setParameter(
|
||||
'chill_main.available_languages',
|
||||
$config['available_languages']
|
||||
);
|
||||
|
||||
$container->setParameter('chill_main.available_countries',
|
||||
$config['available_countries']);
|
||||
$container->setParameter(
|
||||
'chill_main.available_countries',
|
||||
$config['available_countries']
|
||||
);
|
||||
|
||||
$container->setParameter('chill_main.routing.resources',
|
||||
$config['routing']['resources']);
|
||||
$container->setParameter(
|
||||
'chill_main.routing.resources',
|
||||
$config['routing']['resources']
|
||||
);
|
||||
|
||||
$container->setParameter('chill_main.pagination.item_per_page',
|
||||
$config['pagination']['item_per_page']);
|
||||
$container->setParameter(
|
||||
'chill_main.pagination.item_per_page',
|
||||
$config['pagination']['item_per_page']
|
||||
);
|
||||
|
||||
$container->setParameter('chill_main.notifications',
|
||||
$config['notifications']);
|
||||
$container->setParameter(
|
||||
'chill_main.notifications',
|
||||
$config['notifications']
|
||||
);
|
||||
|
||||
$container->setParameter('chill_main.redis',
|
||||
$config['redis']);
|
||||
$container->setParameter(
|
||||
'chill_main.redis',
|
||||
$config['redis']
|
||||
);
|
||||
|
||||
$container->setParameter('chill_main.phone_helper',
|
||||
$config['phone_helper'] ?? []);
|
||||
$container->setParameter(
|
||||
'chill_main.phone_helper',
|
||||
$config['phone_helper'] ?? []
|
||||
);
|
||||
|
||||
// add the key 'widget' without the key 'enable'
|
||||
$container->setParameter('chill_main.widgets',
|
||||
$container->setParameter(
|
||||
'chill_main.widgets',
|
||||
isset($config['widgets']['homepage']) ?
|
||||
array('homepage' => $config['widgets']['homepage']):
|
||||
array()
|
||||
);
|
||||
['homepage' => $config['widgets']['homepage']] :
|
||||
[]
|
||||
);
|
||||
|
||||
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../config'));
|
||||
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../config'));
|
||||
$loader->load('services.yaml');
|
||||
$loader->load('services/doctrine.yaml');
|
||||
$loader->load('services/logger.yaml');
|
||||
@@ -159,33 +167,20 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
||||
$this->configureCruds($container, $config['cruds'], $config['apis'], $loader);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $config
|
||||
* @param ContainerBuilder $container
|
||||
* @return \Chill\MainBundle\DependencyInjection\Configuration|null|object|\Symfony\Component\Config\Definition\ConfigurationInterface
|
||||
*/
|
||||
public function getConfiguration(array $config, ContainerBuilder $container)
|
||||
{
|
||||
return new Configuration($this->widgetFactories, $container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ContainerBuilder $container
|
||||
*/
|
||||
public function prepend(ContainerBuilder $container)
|
||||
{
|
||||
//add installation_name and date_format to globals
|
||||
$chillMainConfig = $container->getExtensionConfig($this->getAlias());
|
||||
$config = $this->processConfiguration($this
|
||||
->getConfiguration($chillMainConfig, $container), $chillMainConfig);
|
||||
$twigConfig = array(
|
||||
'globals' => array(
|
||||
'installation' => array(
|
||||
'name' => $config['installation_name']),
|
||||
'available_languages' => $config['available_languages']
|
||||
),
|
||||
'form_themes' => array('@ChillMain/Form/fields.html.twig')
|
||||
);
|
||||
->getConfiguration($chillMainConfig, $container), $chillMainConfig);
|
||||
$twigConfig = [
|
||||
'globals' => [
|
||||
'installation' => [
|
||||
'name' => $config['installation_name'], ],
|
||||
'available_languages' => $config['available_languages'],
|
||||
],
|
||||
'form_themes' => ['@ChillMain/Form/fields.html.twig'],
|
||||
];
|
||||
$container->prependExtensionConfig('twig', $twigConfig);
|
||||
|
||||
//add DQL function to ORM (default entity_manager)
|
||||
@@ -215,7 +210,7 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
||||
],
|
||||
],
|
||||
],
|
||||
);
|
||||
);
|
||||
|
||||
//add dbal types (default entity_manager)
|
||||
$container
|
||||
@@ -231,45 +226,43 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
||||
],
|
||||
'types' => [
|
||||
'dateinterval' => [
|
||||
'class' => NativeDateIntervalType::class
|
||||
'class' => NativeDateIntervalType::class,
|
||||
],
|
||||
'point' => [
|
||||
'class' => PointType::class
|
||||
]
|
||||
]
|
||||
]
|
||||
'class' => PointType::class,
|
||||
],
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
);
|
||||
|
||||
//add current route to chill main
|
||||
$container->prependExtensionConfig('chill_main', array(
|
||||
'routing' => array(
|
||||
'resources' => array(
|
||||
'@ChillMainBundle/config/routes.yaml'
|
||||
)
|
||||
|
||||
)
|
||||
));
|
||||
$container->prependExtensionConfig('chill_main', [
|
||||
'routing' => [
|
||||
'resources' => [
|
||||
'@ChillMainBundle/config/routes.yaml',
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
//add a channel to log app events
|
||||
$container->prependExtensionConfig('monolog', array(
|
||||
'channels' => array('chill')
|
||||
));
|
||||
$container->prependExtensionConfig('monolog', [
|
||||
'channels' => ['chill'],
|
||||
]);
|
||||
|
||||
//add crud api
|
||||
$this->prependCruds($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load parameter for configuration and set parameters for api
|
||||
* Load parameter for configuration and set parameters for api.
|
||||
*/
|
||||
protected function configureCruds(
|
||||
ContainerBuilder $container,
|
||||
array $crudConfig,
|
||||
array $apiConfig,
|
||||
Loader\YamlFileLoader $loader
|
||||
): void
|
||||
{
|
||||
): void {
|
||||
if (count($crudConfig) === 0) {
|
||||
return;
|
||||
}
|
||||
@@ -282,10 +275,6 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
||||
// Note: the controller are loaded inside compiler pass
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param ContainerBuilder $container
|
||||
*/
|
||||
protected function prependCruds(ContainerBuilder $container)
|
||||
{
|
||||
$container->prependExtensionConfig('chill_main', [
|
||||
@@ -302,11 +291,11 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
||||
'template' => '@ChillMain/UserJob/index.html.twig',
|
||||
],
|
||||
'new' => [
|
||||
'role' => 'ROLE_ADMIN'
|
||||
'role' => 'ROLE_ADMIN',
|
||||
],
|
||||
'edit' => [
|
||||
'role' => 'ROLE_ADMIN'
|
||||
]
|
||||
'role' => 'ROLE_ADMIN',
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
@@ -319,17 +308,17 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
||||
'actions' => [
|
||||
'index' => [
|
||||
'role' => 'ROLE_ADMIN',
|
||||
'template' => '@ChillMain/User/index.html.twig'
|
||||
'template' => '@ChillMain/User/index.html.twig',
|
||||
],
|
||||
'new' => [
|
||||
'role' => 'ROLE_ADMIN',
|
||||
'template' => '@ChillMain/User/new.html.twig'
|
||||
'template' => '@ChillMain/User/new.html.twig',
|
||||
],
|
||||
'edit' => [
|
||||
'role' => 'ROLE_ADMIN',
|
||||
'template' => '@ChillMain/User/edit.html.twig'
|
||||
]
|
||||
]
|
||||
'template' => '@ChillMain/User/edit.html.twig',
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'class' => Location::class,
|
||||
@@ -343,15 +332,15 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
||||
'role' => 'ROLE_ADMIN',
|
||||
'template' => '@ChillMain/Location/index.html.twig',
|
||||
],
|
||||
'new' => [
|
||||
'new' => [
|
||||
'role' => 'ROLE_ADMIN',
|
||||
'template' => '@ChillMain/Location/new.html.twig',
|
||||
],
|
||||
'edit' => [
|
||||
'edit' => [
|
||||
'role' => 'ROLE_ADMIN',
|
||||
'template' => '@ChillMain/Location/edit.html.twig',
|
||||
]
|
||||
]
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'class' => LocationType::class,
|
||||
@@ -365,15 +354,15 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
||||
'role' => 'ROLE_ADMIN',
|
||||
'template' => '@ChillMain/LocationType/index.html.twig',
|
||||
],
|
||||
'new' => [
|
||||
'new' => [
|
||||
'role' => 'ROLE_ADMIN',
|
||||
'template' => '@ChillMain/LocationType/new.html.twig',
|
||||
],
|
||||
'edit' => [
|
||||
'edit' => [
|
||||
'role' => 'ROLE_ADMIN',
|
||||
'template' => '@ChillMain/LocationType/edit.html.twig',
|
||||
]
|
||||
]
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'apis' => [
|
||||
@@ -387,7 +376,7 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
||||
'_index' => [
|
||||
'methods' => [
|
||||
Request::METHOD_GET => true,
|
||||
Request::METHOD_HEAD => true
|
||||
Request::METHOD_HEAD => true,
|
||||
],
|
||||
],
|
||||
'_entity' => [
|
||||
@@ -395,10 +384,10 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
||||
Request::METHOD_GET => true,
|
||||
Request::METHOD_POST => true,
|
||||
Request::METHOD_HEAD => true,
|
||||
Request::METHOD_PATCH => true
|
||||
]
|
||||
Request::METHOD_PATCH => true,
|
||||
],
|
||||
],
|
||||
]
|
||||
],
|
||||
],
|
||||
[
|
||||
'controller' => \Chill\MainBundle\Controller\AddressReferenceAPIController::class,
|
||||
@@ -410,16 +399,16 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
||||
'_index' => [
|
||||
'methods' => [
|
||||
Request::METHOD_GET => true,
|
||||
Request::METHOD_HEAD => true
|
||||
Request::METHOD_HEAD => true,
|
||||
],
|
||||
],
|
||||
'_entity' => [
|
||||
'methods' => [
|
||||
Request::METHOD_GET => true,
|
||||
Request::METHOD_HEAD => true
|
||||
]
|
||||
Request::METHOD_HEAD => true,
|
||||
],
|
||||
],
|
||||
]
|
||||
],
|
||||
],
|
||||
[
|
||||
'controller' => \Chill\MainBundle\Controller\PostalCodeAPIController::class,
|
||||
@@ -431,7 +420,7 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
||||
'_index' => [
|
||||
'methods' => [
|
||||
Request::METHOD_GET => true,
|
||||
Request::METHOD_HEAD => true
|
||||
Request::METHOD_HEAD => true,
|
||||
],
|
||||
],
|
||||
'_entity' => [
|
||||
@@ -439,9 +428,9 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
||||
Request::METHOD_GET => true,
|
||||
Request::METHOD_HEAD => true,
|
||||
Request::METHOD_POST => true,
|
||||
]
|
||||
],
|
||||
],
|
||||
]
|
||||
],
|
||||
],
|
||||
[
|
||||
'class' => \Chill\MainBundle\Entity\Country::class,
|
||||
@@ -452,16 +441,16 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
||||
'_index' => [
|
||||
'methods' => [
|
||||
Request::METHOD_GET => true,
|
||||
Request::METHOD_HEAD => true
|
||||
Request::METHOD_HEAD => true,
|
||||
],
|
||||
],
|
||||
'_entity' => [
|
||||
'methods' => [
|
||||
Request::METHOD_GET => true,
|
||||
Request::METHOD_HEAD => true
|
||||
]
|
||||
Request::METHOD_HEAD => true,
|
||||
],
|
||||
],
|
||||
]
|
||||
],
|
||||
],
|
||||
[
|
||||
'class' => \Chill\MainBundle\Entity\User::class,
|
||||
@@ -473,16 +462,16 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
||||
'_index' => [
|
||||
'methods' => [
|
||||
Request::METHOD_GET => true,
|
||||
Request::METHOD_HEAD => true
|
||||
Request::METHOD_HEAD => true,
|
||||
],
|
||||
],
|
||||
'_entity' => [
|
||||
'methods' => [
|
||||
Request::METHOD_GET => true,
|
||||
Request::METHOD_HEAD => true,
|
||||
]
|
||||
],
|
||||
],
|
||||
]
|
||||
],
|
||||
],
|
||||
[
|
||||
'class' => \Chill\MainBundle\Entity\Scope::class,
|
||||
@@ -493,16 +482,16 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
||||
'_index' => [
|
||||
'methods' => [
|
||||
Request::METHOD_GET => true,
|
||||
Request::METHOD_HEAD => true
|
||||
Request::METHOD_HEAD => true,
|
||||
],
|
||||
],
|
||||
'_entity' => [
|
||||
'methods' => [
|
||||
Request::METHOD_GET => true,
|
||||
Request::METHOD_HEAD => true,
|
||||
]
|
||||
],
|
||||
],
|
||||
]
|
||||
],
|
||||
],
|
||||
[
|
||||
'class' => \Chill\MainBundle\Entity\Location::class,
|
||||
@@ -514,7 +503,7 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
||||
'_index' => [
|
||||
'methods' => [
|
||||
Request::METHOD_GET => true,
|
||||
Request::METHOD_HEAD => true
|
||||
Request::METHOD_HEAD => true,
|
||||
],
|
||||
],
|
||||
'_entity' => [
|
||||
@@ -522,10 +511,9 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
||||
Request::METHOD_GET => true,
|
||||
Request::METHOD_HEAD => true,
|
||||
Request::METHOD_POST => true,
|
||||
]
|
||||
],
|
||||
],
|
||||
|
||||
]
|
||||
],
|
||||
],
|
||||
[
|
||||
'class' => \Chill\MainBundle\Entity\LocationType::class,
|
||||
@@ -537,19 +525,18 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
||||
'_index' => [
|
||||
'methods' => [
|
||||
Request::METHOD_GET => true,
|
||||
Request::METHOD_HEAD => true
|
||||
Request::METHOD_HEAD => true,
|
||||
],
|
||||
],
|
||||
'_entity' => [
|
||||
'methods' => [
|
||||
Request::METHOD_GET => true,
|
||||
Request::METHOD_HEAD => true,
|
||||
]
|
||||
],
|
||||
],
|
||||
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@@ -1,14 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\DependencyInjection\CompilerPass;
|
||||
|
||||
use Chill\MainBundle\Form\PermissionsGroupType;
|
||||
use LogicException;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Chill\MainBundle\Form\PermissionsGroupType;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use LogicException;
|
||||
|
||||
class ACLFlagsCompilerPass implements CompilerPassInterface
|
||||
{
|
||||
@@ -16,19 +23,24 @@ class ACLFlagsCompilerPass implements CompilerPassInterface
|
||||
{
|
||||
$permissionGroupType = $container->getDefinition(PermissionsGroupType::class);
|
||||
|
||||
foreach($container->findTaggedServiceIds('chill_main.flags') as $id => $tags) {
|
||||
foreach ($container->findTaggedServiceIds('chill_main.flags') as $id => $tags) {
|
||||
$reference = new Reference($id);
|
||||
|
||||
foreach ($tags as $tag) {
|
||||
switch($tag['scope']) {
|
||||
switch ($tag['scope']) {
|
||||
case PermissionsGroupType::FLAG_SCOPE:
|
||||
$permissionGroupType->addMethodCall('addFlagProvider', [$reference]);
|
||||
|
||||
$permissionGroupType->addMethodCall('addFlagProvider', [ $reference ]);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new LogicException(sprintf(
|
||||
"This tag 'scope' is not implemented: %s, on service with id %s", $tag['scope'], $id)
|
||||
);
|
||||
throw new LogicException(
|
||||
sprintf(
|
||||
"This tag 'scope' is not implemented: %s, on service with id %s",
|
||||
$tag['scope'],
|
||||
$id
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,51 +1,38 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2015 Champs-Libres <info@champs-libres.coop>
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\DependencyInjection\CompilerPass;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use LogicException;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* Compiles the services tagged with :
|
||||
*
|
||||
* Compiles the services tagged with :.
|
||||
*
|
||||
* - chill.export
|
||||
* - chill.export_formatter
|
||||
* - chill.export_aggregator
|
||||
* - chill.export_filter
|
||||
* - chill.export_elements_provider
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class ExportsCompilerPass implements CompilerPassInterface
|
||||
{
|
||||
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->has('Chill\MainBundle\Export\ExportManager')) {
|
||||
throw new \LogicException('service Chill\MainBundle\Export\ExportManager '
|
||||
throw new LogicException('service Chill\MainBundle\Export\ExportManager '
|
||||
. 'is not defined. It is required by ExportsCompilerPass');
|
||||
}
|
||||
|
||||
|
||||
$chillManagerDefinition = $container->findDefinition(
|
||||
'Chill\MainBundle\Export\ExportManager'
|
||||
);
|
||||
@@ -56,155 +43,164 @@ class ExportsCompilerPass implements CompilerPassInterface
|
||||
$this->compileFormatters($chillManagerDefinition, $container);
|
||||
$this->compileExportElementsProvider($chillManagerDefinition, $container);
|
||||
}
|
||||
|
||||
private function compileExports(Definition $chillManagerDefinition,
|
||||
ContainerBuilder $container)
|
||||
{
|
||||
$taggedServices = $container->findTaggedServiceIds(
|
||||
'chill.export'
|
||||
);
|
||||
|
||||
$knownAliases = array();
|
||||
|
||||
foreach ($taggedServices as $id => $tagAttributes) {
|
||||
foreach ($tagAttributes as $attributes) {
|
||||
if (!isset($attributes["alias"])) {
|
||||
throw new \LogicException("the 'alias' attribute is missing in your ".
|
||||
"service '$id' definition");
|
||||
}
|
||||
|
||||
if (array_search($attributes["alias"], $knownAliases)) {
|
||||
throw new \LogicException("There is already a chill.export service with alias "
|
||||
.$attributes["alias"].". Choose another alias.");
|
||||
}
|
||||
$knownAliases[] = $attributes["alias"];
|
||||
|
||||
$chillManagerDefinition->addMethodCall(
|
||||
'addExport',
|
||||
array(new Reference($id), $attributes["alias"])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function compileFilters(Definition $chillManagerDefinition,
|
||||
ContainerBuilder $container)
|
||||
{
|
||||
$taggedServices = $container->findTaggedServiceIds(
|
||||
'chill.export_filter'
|
||||
);
|
||||
|
||||
$knownAliases = array();
|
||||
|
||||
foreach ($taggedServices as $id => $tagAttributes) {
|
||||
foreach ($tagAttributes as $attributes) {
|
||||
if (!isset($attributes["alias"])) {
|
||||
throw new \LogicException("the 'alias' attribute is missing in your ".
|
||||
"service '$id' definition");
|
||||
}
|
||||
|
||||
if (array_search($attributes["alias"], $knownAliases)) {
|
||||
throw new \LogicException("There is already a chill.export_filter service with alias "
|
||||
.$attributes["alias"].". Choose another alias.");
|
||||
}
|
||||
$knownAliases[] = $attributes["alias"];
|
||||
|
||||
$chillManagerDefinition->addMethodCall(
|
||||
'addFilter',
|
||||
array(new Reference($id), $attributes["alias"])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function compileAggregators(Definition $chillManagerDefinition,
|
||||
ContainerBuilder $container)
|
||||
|
||||
private function compileAggregators(
|
||||
Definition $chillManagerDefinition,
|
||||
ContainerBuilder $container
|
||||
)
|
||||
{
|
||||
$taggedServices = $container->findTaggedServiceIds(
|
||||
'chill.export_aggregator'
|
||||
);
|
||||
|
||||
$knownAliases = array();
|
||||
|
||||
|
||||
$knownAliases = [];
|
||||
|
||||
foreach ($taggedServices as $id => $tagAttributes) {
|
||||
foreach ($tagAttributes as $attributes) {
|
||||
if (!isset($attributes["alias"])) {
|
||||
throw new \LogicException("the 'alias' attribute is missing in your ".
|
||||
"service '$id' definition");
|
||||
if (!isset($attributes['alias'])) {
|
||||
throw new LogicException("the 'alias' attribute is missing in your " .
|
||||
"service '{$id}' definition");
|
||||
}
|
||||
|
||||
if (array_search($attributes["alias"], $knownAliases)) {
|
||||
throw new \LogicException("There is already a chill.export_aggregator service with alias "
|
||||
.$attributes["alias"].". Choose another alias.");
|
||||
|
||||
if (array_search($attributes['alias'], $knownAliases)) {
|
||||
throw new LogicException('There is already a chill.export_aggregator service with alias '
|
||||
. $attributes['alias'] . '. Choose another alias.');
|
||||
}
|
||||
$knownAliases[] = $attributes["alias"];
|
||||
|
||||
$knownAliases[] = $attributes['alias'];
|
||||
|
||||
$chillManagerDefinition->addMethodCall(
|
||||
'addAggregator',
|
||||
array(new Reference($id), $attributes["alias"])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function compileFormatters(Definition $chillManagerDefinition,
|
||||
ContainerBuilder $container)
|
||||
{
|
||||
$taggedServices = $container->findTaggedServiceIds(
|
||||
'chill.export_formatter'
|
||||
);
|
||||
|
||||
$knownAliases = array();
|
||||
|
||||
foreach ($taggedServices as $id => $tagAttributes) {
|
||||
foreach ($tagAttributes as $attributes) {
|
||||
if (!isset($attributes["alias"])) {
|
||||
throw new \LogicException("the 'alias' attribute is missing in your ".
|
||||
"service '$id' definition");
|
||||
}
|
||||
|
||||
if (array_search($attributes["alias"], $knownAliases)) {
|
||||
throw new \LogicException("There is already a chill.export_formatter service with alias "
|
||||
.$attributes["alias"].". Choose another alias.");
|
||||
}
|
||||
$knownAliases[] = $attributes["alias"];
|
||||
|
||||
$chillManagerDefinition->addMethodCall(
|
||||
'addFormatter',
|
||||
array(new Reference($id), $attributes["alias"])
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function compileExportElementsProvider(Definition $chillManagerDefinition,
|
||||
ContainerBuilder $container)
|
||||
{
|
||||
$taggedServices = $container->findTaggedServiceIds(
|
||||
'chill.export_elements_provider'
|
||||
);
|
||||
|
||||
$knownAliases = array();
|
||||
|
||||
foreach ($taggedServices as $id => $tagAttributes) {
|
||||
foreach ($tagAttributes as $attributes) {
|
||||
if (!isset($attributes["prefix"])) {
|
||||
throw new \LogicException("the 'prefix' attribute is missing in your ".
|
||||
"service '$id' definition");
|
||||
}
|
||||
|
||||
if (array_search($attributes["prefix"], $knownAliases)) {
|
||||
throw new \LogicException("There is already a chill.export_elements_provider service with prefix "
|
||||
.$attributes["prefix"].". Choose another prefix.");
|
||||
}
|
||||
$knownAliases[] = $attributes["prefix"];
|
||||
|
||||
$chillManagerDefinition->addMethodCall(
|
||||
'addExportElementsProvider',
|
||||
array(new Reference($id), $attributes["prefix"])
|
||||
[new Reference($id), $attributes['alias']]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function compileExportElementsProvider(
|
||||
Definition $chillManagerDefinition,
|
||||
ContainerBuilder $container
|
||||
)
|
||||
{
|
||||
$taggedServices = $container->findTaggedServiceIds(
|
||||
'chill.export_elements_provider'
|
||||
);
|
||||
|
||||
$knownAliases = [];
|
||||
|
||||
foreach ($taggedServices as $id => $tagAttributes) {
|
||||
foreach ($tagAttributes as $attributes) {
|
||||
if (!isset($attributes['prefix'])) {
|
||||
throw new LogicException("the 'prefix' attribute is missing in your " .
|
||||
"service '{$id}' definition");
|
||||
}
|
||||
|
||||
if (array_search($attributes['prefix'], $knownAliases)) {
|
||||
throw new LogicException('There is already a chill.export_elements_provider service with prefix '
|
||||
. $attributes['prefix'] . '. Choose another prefix.');
|
||||
}
|
||||
$knownAliases[] = $attributes['prefix'];
|
||||
|
||||
$chillManagerDefinition->addMethodCall(
|
||||
'addExportElementsProvider',
|
||||
[new Reference($id), $attributes['prefix']]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function compileExports(
|
||||
Definition $chillManagerDefinition,
|
||||
ContainerBuilder $container
|
||||
)
|
||||
{
|
||||
$taggedServices = $container->findTaggedServiceIds(
|
||||
'chill.export'
|
||||
);
|
||||
|
||||
$knownAliases = [];
|
||||
|
||||
foreach ($taggedServices as $id => $tagAttributes) {
|
||||
foreach ($tagAttributes as $attributes) {
|
||||
if (!isset($attributes['alias'])) {
|
||||
throw new LogicException("the 'alias' attribute is missing in your " .
|
||||
"service '{$id}' definition");
|
||||
}
|
||||
|
||||
if (array_search($attributes['alias'], $knownAliases)) {
|
||||
throw new LogicException('There is already a chill.export service with alias '
|
||||
. $attributes['alias'] . '. Choose another alias.');
|
||||
}
|
||||
$knownAliases[] = $attributes['alias'];
|
||||
|
||||
$chillManagerDefinition->addMethodCall(
|
||||
'addExport',
|
||||
[new Reference($id), $attributes['alias']]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function compileFilters(
|
||||
Definition $chillManagerDefinition,
|
||||
ContainerBuilder $container
|
||||
)
|
||||
{
|
||||
$taggedServices = $container->findTaggedServiceIds(
|
||||
'chill.export_filter'
|
||||
);
|
||||
|
||||
$knownAliases = [];
|
||||
|
||||
foreach ($taggedServices as $id => $tagAttributes) {
|
||||
foreach ($tagAttributes as $attributes) {
|
||||
if (!isset($attributes['alias'])) {
|
||||
throw new LogicException("the 'alias' attribute is missing in your " .
|
||||
"service '{$id}' definition");
|
||||
}
|
||||
|
||||
if (array_search($attributes['alias'], $knownAliases)) {
|
||||
throw new LogicException('There is already a chill.export_filter service with alias '
|
||||
. $attributes['alias'] . '. Choose another alias.');
|
||||
}
|
||||
$knownAliases[] = $attributes['alias'];
|
||||
|
||||
$chillManagerDefinition->addMethodCall(
|
||||
'addFilter',
|
||||
[new Reference($id), $attributes['alias']]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function compileFormatters(
|
||||
Definition $chillManagerDefinition,
|
||||
ContainerBuilder $container
|
||||
)
|
||||
{
|
||||
$taggedServices = $container->findTaggedServiceIds(
|
||||
'chill.export_formatter'
|
||||
);
|
||||
|
||||
$knownAliases = [];
|
||||
|
||||
foreach ($taggedServices as $id => $tagAttributes) {
|
||||
foreach ($tagAttributes as $attributes) {
|
||||
if (!isset($attributes['alias'])) {
|
||||
throw new LogicException("the 'alias' attribute is missing in your " .
|
||||
"service '{$id}' definition");
|
||||
}
|
||||
|
||||
if (array_search($attributes['alias'], $knownAliases)) {
|
||||
throw new LogicException('There is already a chill.export_formatter service with alias '
|
||||
. $attributes['alias'] . '. Choose another alias.');
|
||||
}
|
||||
$knownAliases[] = $attributes['alias'];
|
||||
|
||||
$chillManagerDefinition->addMethodCall(
|
||||
'addFormatter',
|
||||
[new Reference($id), $attributes['alias']]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,46 +1,35 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2019 Champs-Libres <info@champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
namespace Chill\MainBundle\DependencyInjection\CompilerPass;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Chill\MainBundle\Form\Type\Export\PickCenterType;
|
||||
|
||||
/**
|
||||
*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\DependencyInjection\CompilerPass;
|
||||
|
||||
use LogicException;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
class GroupingCenterCompilerPass implements CompilerPassInterface
|
||||
{
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (FALSE === $container->hasDefinition('chill.main.form.pick_centers_type')) {
|
||||
throw new \LogicException("The service chill.main.form.pick_centers_type does "
|
||||
. "not exists in container");
|
||||
if (false === $container->hasDefinition('chill.main.form.pick_centers_type')) {
|
||||
throw new LogicException('The service chill.main.form.pick_centers_type does '
|
||||
. 'not exists in container');
|
||||
}
|
||||
|
||||
|
||||
$pickCenterType = $container->getDefinition('chill.main.form.pick_centers_type');
|
||||
|
||||
|
||||
foreach ($container->findTaggedServiceIds('chill.grouping_center') as $serviceId => $tagged) {
|
||||
$pickCenterType->addMethodCall('addGroupingCenter',
|
||||
[ new Reference($serviceId) ]);
|
||||
$pickCenterType->addMethodCall(
|
||||
'addGroupingCenter',
|
||||
[new Reference($serviceId)]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,44 +1,33 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2018 Champs Libres Cooperative <info@champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
namespace Chill\MainBundle\DependencyInjection\CompilerPass;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Chill\MainBundle\Routing\MenuComposer;
|
||||
|
||||
/**
|
||||
*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\DependencyInjection\CompilerPass;
|
||||
|
||||
use Chill\MainBundle\Routing\MenuComposer;
|
||||
use LogicException;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
class MenuCompilerPass implements CompilerPassInterface
|
||||
{
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->hasDefinition('chill.main.menu_composer')) {
|
||||
throw new \LogicException(sprintf("The service %s does not exists in "
|
||||
. "container.", MenuComposer::class));
|
||||
if (!$container->hasDefinition('chill.main.menu_composer')) {
|
||||
throw new LogicException(sprintf('The service %s does not exists in '
|
||||
. 'container.', MenuComposer::class));
|
||||
}
|
||||
|
||||
|
||||
$menuComposerDefinition = $container->getDefinition('chill.main.menu_composer');
|
||||
|
||||
$services = [];
|
||||
|
||||
foreach ($container->findTaggedServiceIds('chill.menu_builder') as $id => $tags) {
|
||||
$services[] = [
|
||||
'id' => $id,
|
||||
@@ -50,11 +39,13 @@ class MenuCompilerPass implements CompilerPassInterface
|
||||
if ($a['priority'] == $b['priority']) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ($a['priority'] < $b['priority']) ? -1 : 1;
|
||||
});
|
||||
|
||||
foreach ($services as $service) {
|
||||
$class = $container->getDefinition($service['id'])->getClass();
|
||||
|
||||
foreach ($class::getMenuIds() as $menuId) {
|
||||
$menuComposerDefinition
|
||||
->addMethodCall('addLocalMenuBuilder', [new Reference($service['id']), $menuId]);
|
||||
|
@@ -1,43 +1,31 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2018 Champs Libres Cooperative <info@champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
namespace Chill\MainBundle\DependencyInjection\CompilerPass;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Chill\MainBundle\Templating\UI\CountNotificationUser;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\DependencyInjection\CompilerPass;
|
||||
|
||||
use Chill\MainBundle\Templating\UI\CountNotificationUser;
|
||||
use LogicException;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
class NotificationCounterCompilerPass implements CompilerPassInterface
|
||||
{
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->hasDefinition(CountNotificationUser::class)) {
|
||||
throw new \LogicException("The service ".CountNotificationUser::class." "
|
||||
. "should be defined");
|
||||
throw new LogicException('The service ' . CountNotificationUser::class . ' '
|
||||
. 'should be defined');
|
||||
}
|
||||
|
||||
|
||||
$notificationCounterDefinition = $container->getDefinition(CountNotificationUser::class);
|
||||
|
||||
|
||||
foreach ($container->findTaggedServiceIds('chill.count_notification.user') as $id => $tags) {
|
||||
$notificationCounterDefinition
|
||||
->addMethodCall('addNotificationCounter', [new Reference($id)]);
|
||||
|
@@ -1,32 +1,21 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\DependencyInjection\CompilerPass;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use LogicException;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
class SearchableServicesCompilerPass implements CompilerPassInterface
|
||||
{
|
||||
|
||||
/*
|
||||
* (non-PHPdoc)
|
||||
* @see \Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface::process()
|
||||
@@ -34,10 +23,10 @@ class SearchableServicesCompilerPass implements CompilerPassInterface
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->hasDefinition('chill_main.search_provider')) {
|
||||
throw new \LogicException('service chill_main.search_provider '
|
||||
throw new LogicException('service chill_main.search_provider '
|
||||
. 'is not defined.');
|
||||
}
|
||||
|
||||
|
||||
$definition = $container->getDefinition(
|
||||
'chill_main.search_provider'
|
||||
);
|
||||
@@ -45,29 +34,27 @@ class SearchableServicesCompilerPass implements CompilerPassInterface
|
||||
$taggedServices = $container->findTaggedServiceIds(
|
||||
'chill.search'
|
||||
);
|
||||
|
||||
$knownAliases = array();
|
||||
|
||||
|
||||
$knownAliases = [];
|
||||
|
||||
foreach ($taggedServices as $id => $tagAttributes) {
|
||||
|
||||
foreach ($tagAttributes as $attributes) {
|
||||
|
||||
if (!isset($attributes["alias"])) {
|
||||
throw new \LogicException("the 'name' attribute is missing in your ".
|
||||
"service '$id' definition");
|
||||
if (!isset($attributes['alias'])) {
|
||||
throw new LogicException("the 'name' attribute is missing in your " .
|
||||
"service '{$id}' definition");
|
||||
}
|
||||
|
||||
if (array_search($attributes["alias"], $knownAliases)) {
|
||||
throw new \LogicException("There is already a chill.search service with alias "
|
||||
.$attributes["alias"].". Choose another alias.");
|
||||
|
||||
if (array_search($attributes['alias'], $knownAliases)) {
|
||||
throw new LogicException('There is already a chill.search service with alias '
|
||||
. $attributes['alias'] . '. Choose another alias.');
|
||||
}
|
||||
$knownAliases[] = $attributes["alias"];
|
||||
|
||||
$knownAliases[] = $attributes['alias'];
|
||||
|
||||
$definition->addMethodCall(
|
||||
'addSearchService',
|
||||
array(new Reference($id), $attributes["alias"])
|
||||
[new Reference($id), $attributes['alias']]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,42 +1,32 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2015 Champs-Libres Coopérative <info@champs-libres.coop>
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\DependencyInjection\CompilerPass;
|
||||
|
||||
use LogicException;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* Add services taggued with `name: chill.timeline` to
|
||||
* timeline_builder service definition
|
||||
*
|
||||
* Add services taggued with `name: chill.timeline` to
|
||||
* timeline_builder service definition.
|
||||
*/
|
||||
class TimelineCompilerClass implements CompilerPassInterface
|
||||
{
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->hasDefinition('chill_main.timeline_builder')) {
|
||||
throw new \LogicException('service chill_main.timeline_builder '
|
||||
throw new LogicException('service chill_main.timeline_builder '
|
||||
. 'is not defined.');
|
||||
}
|
||||
|
||||
|
||||
$definition = $container->getDefinition(
|
||||
'chill_main.timeline_builder'
|
||||
);
|
||||
@@ -44,22 +34,19 @@ class TimelineCompilerClass implements CompilerPassInterface
|
||||
$taggedServices = $container->findTaggedServiceIds(
|
||||
'chill.timeline'
|
||||
);
|
||||
|
||||
|
||||
foreach ($taggedServices as $id => $tagAttributes) {
|
||||
|
||||
foreach ($tagAttributes as $attributes) {
|
||||
|
||||
if (!isset($attributes["context"])) {
|
||||
throw new \LogicException("the 'context' attribute is missing in your ".
|
||||
"service '$id' definition");
|
||||
if (!isset($attributes['context'])) {
|
||||
throw new LogicException("the 'context' attribute is missing in your " .
|
||||
"service '{$id}' definition");
|
||||
}
|
||||
|
||||
$definition->addMethodCall(
|
||||
'addProvider',
|
||||
array($attributes["context"], $id, new Reference($id))
|
||||
[$attributes['context'], $id, new Reference($id)]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,34 +1,24 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2016 Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\DependencyInjection\CompilerPass;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Chill\MainBundle\DependencyInjection\Widget\AbstractWidgetsCompilerPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
/**
|
||||
* Compile the service definition to register widgets.
|
||||
*
|
||||
*/
|
||||
class WidgetsCompilerPass extends AbstractWidgetsCompilerPass {
|
||||
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
$this->doProcess($container, 'chill_main', 'chill_main.widgets');
|
||||
}
|
||||
class WidgetsCompilerPass extends AbstractWidgetsCompilerPass
|
||||
{
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
$this->doProcess($container, 'chill_main', 'chill_main.widgets');
|
||||
}
|
||||
}
|
||||
|
@@ -1,59 +1,52 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
* Copyright (C) 2015 Champs-Libres Coopérative <info@champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\DependencyInjection;
|
||||
|
||||
use LogicException;
|
||||
use RuntimeException;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
/**
|
||||
* Description of ConfigConsistencyCompilerPass
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* Description of ConfigConsistencyCompilerPass.
|
||||
*/
|
||||
class ConfigConsistencyCompilerPass implements CompilerPassInterface
|
||||
{
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
$availableLanguages = $container
|
||||
->getParameter('chill_main.available_languages');
|
||||
->getParameter('chill_main.available_languages');
|
||||
$methodCallsTranslator = $container
|
||||
->findDefinition('translator.default')
|
||||
->getMethodCalls();
|
||||
|
||||
$fallbackLocales = array();
|
||||
foreach($methodCallsTranslator as $call) {
|
||||
if ($call[0] === 'setFallbackLocales') {
|
||||
$fallbackLocales = array_merge($fallbackLocales,
|
||||
$call[1][0]);
|
||||
}
|
||||
->findDefinition('translator.default')
|
||||
->getMethodCalls();
|
||||
|
||||
$fallbackLocales = [];
|
||||
|
||||
foreach ($methodCallsTranslator as $call) {
|
||||
if ('setFallbackLocales' === $call[0]) {
|
||||
$fallbackLocales = array_merge(
|
||||
$fallbackLocales,
|
||||
$call[1][0]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (count($fallbackLocales) === 0) {
|
||||
throw new \LogicException('the fallback locale are not defined. '
|
||||
throw new LogicException('the fallback locale are not defined. '
|
||||
. 'The framework config should not allow this.');
|
||||
}
|
||||
|
||||
|
||||
$diff = array_diff($fallbackLocales, $availableLanguages);
|
||||
|
||||
if (count($diff) > 0) {
|
||||
throw new \RuntimeException(sprintf('The chill_main.available_languages'
|
||||
throw new RuntimeException(sprintf('The chill_main.available_languages'
|
||||
. ' parameter does not contains fallback locales. The languages %s'
|
||||
. ' are missing.', implode(', ', $diff)));
|
||||
}
|
||||
|
@@ -1,38 +1,38 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\DependencyInjection;
|
||||
|
||||
use Chill\MainBundle\DependencyInjection\Widget\AddWidgetConfigurationTrait;
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||
use Chill\MainBundle\DependencyInjection\Widget\Factory\WidgetFactoryInterface;
|
||||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
|
||||
use Chill\MainBundle\DependencyInjection\Widget\AddWidgetConfigurationTrait;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
|
||||
/**
|
||||
* Configure the main bundle
|
||||
* Configure the main bundle.
|
||||
*/
|
||||
class Configuration implements ConfigurationInterface
|
||||
{
|
||||
|
||||
use AddWidgetConfigurationTrait;
|
||||
|
||||
private ContainerBuilder $containerBuilder;
|
||||
|
||||
|
||||
public function __construct(
|
||||
array $widgetFactories,
|
||||
ContainerBuilder $containerBuilder)
|
||||
array $widgetFactories,
|
||||
ContainerBuilder $containerBuilder
|
||||
)
|
||||
{
|
||||
$this->setWidgetFactories($widgetFactories);
|
||||
$this->containerBuilder = $containerBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getConfigTreeBuilder()
|
||||
{
|
||||
$treeBuilder = new TreeBuilder('chill_main');
|
||||
@@ -40,225 +40,220 @@ class Configuration implements ConfigurationInterface
|
||||
|
||||
$rootNode
|
||||
->children()
|
||||
->scalarNode('installation_name')
|
||||
->cannotBeEmpty()
|
||||
->defaultValue('Chill')
|
||||
->end() // end of scalar 'installation_name'
|
||||
->arrayNode('available_languages')
|
||||
->defaultValue(array('fr'))
|
||||
->prototype('scalar')->end()
|
||||
->end() // end of array 'available_languages'
|
||||
->arrayNode('available_countries')
|
||||
->defaultValue(array('FR'))
|
||||
->prototype('scalar')->end()
|
||||
->end() // end of array 'available_countries'
|
||||
->arrayNode('routing')
|
||||
->children()
|
||||
->arrayNode('resources')
|
||||
->prototype('scalar')->end()
|
||||
->end() // end of array 'resources'
|
||||
->end() // end of children
|
||||
->end() // end of array node 'routing'
|
||||
->arrayNode('pagination')
|
||||
->canBeDisabled()
|
||||
->children()
|
||||
->integerNode('item_per_page')
|
||||
->info('The number of item to show in the page result, by default')
|
||||
->min(1)
|
||||
->defaultValue(50)
|
||||
->end() // end of integer 'item_per_page'
|
||||
->end() // end of children
|
||||
->end() // end of pagination
|
||||
->arrayNode('notifications')
|
||||
->children()
|
||||
->scalarNode('from_email')
|
||||
->cannotBeEmpty()
|
||||
->end()
|
||||
->scalarNode('from_name')
|
||||
->cannotBeEmpty()
|
||||
->end()
|
||||
->enumNode('scheme')
|
||||
->cannotBeEmpty()
|
||||
->values(['http', 'https'])
|
||||
->defaultValue('https')
|
||||
->end()
|
||||
->scalarNode('host')
|
||||
->cannotBeEmpty()
|
||||
->end()
|
||||
->end()
|
||||
->end() // end of notifications
|
||||
->arrayNode('phone_helper')
|
||||
->canBeUnset()
|
||||
->children()
|
||||
->scalarNode('twilio_sid')
|
||||
->defaultNull()
|
||||
->end()
|
||||
->scalarNode('twilio_secret')
|
||||
->defaultNull()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('acl')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->booleanNode('form_show_scopes')
|
||||
->defaultTrue()
|
||||
->end()
|
||||
->booleanNode('form_show_centers')
|
||||
->defaultTrue()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('redis')
|
||||
->children()
|
||||
->scalarNode('host')
|
||||
->cannotBeEmpty()
|
||||
->end()
|
||||
->scalarNode('port')
|
||||
->defaultValue(6379)
|
||||
->end()
|
||||
->scalarNode('timeout')
|
||||
->defaultValue(1)
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('widgets')
|
||||
->canBeEnabled()
|
||||
->canBeUnset()
|
||||
->children()
|
||||
->append($this->addWidgetsConfiguration('homepage', $this->containerBuilder))
|
||||
->end() // end of widgets/children
|
||||
->end() // end of widgets
|
||||
->arrayNode('cruds')
|
||||
->defaultValue([])
|
||||
->arrayPrototype()
|
||||
->children()
|
||||
->scalarNode('class')->cannotBeEmpty()->isRequired()->end()
|
||||
->scalarNode('controller')
|
||||
->cannotBeEmpty()
|
||||
->defaultValue(\Chill\MainBundle\CRUD\Controller\CRUDController::class)
|
||||
->end()
|
||||
->scalarNode('name')->cannotBeEmpty()->isRequired()->end()
|
||||
->scalarNode('base_path')->cannotBeEmpty()->isRequired()->end()
|
||||
->scalarNode('base_role')->defaultNull()->end()
|
||||
->scalarNode('form_class')->defaultNull()->end()
|
||||
->arrayNode('actions')
|
||||
->defaultValue([
|
||||
'edit' => [],
|
||||
'new' => []
|
||||
])
|
||||
->useAttributeAsKey('name')
|
||||
->arrayPrototype()
|
||||
->children()
|
||||
->scalarNode('controller_action')
|
||||
->defaultNull()
|
||||
->info('the method name to call in the route. Will be set to the action name if left empty.')
|
||||
->example("action")
|
||||
->end()
|
||||
->scalarNode('path')
|
||||
->defaultNull()
|
||||
->info('the path that will be **appended** after the base path. Do not forget to add '
|
||||
->scalarNode('installation_name')
|
||||
->cannotBeEmpty()
|
||||
->defaultValue('Chill')
|
||||
->end() // end of scalar 'installation_name'
|
||||
->arrayNode('available_languages')
|
||||
->defaultValue(['fr'])
|
||||
->prototype('scalar')->end()
|
||||
->end() // end of array 'available_languages'
|
||||
->arrayNode('available_countries')
|
||||
->defaultValue(['FR'])
|
||||
->prototype('scalar')->end()
|
||||
->end() // end of array 'available_countries'
|
||||
->arrayNode('routing')
|
||||
->children()
|
||||
->arrayNode('resources')
|
||||
->prototype('scalar')->end()
|
||||
->end() // end of array 'resources'
|
||||
->end() // end of children
|
||||
->end() // end of array node 'routing'
|
||||
->arrayNode('pagination')
|
||||
->canBeDisabled()
|
||||
->children()
|
||||
->integerNode('item_per_page')
|
||||
->info('The number of item to show in the page result, by default')
|
||||
->min(1)
|
||||
->defaultValue(50)
|
||||
->end() // end of integer 'item_per_page'
|
||||
->end() // end of children
|
||||
->end() // end of pagination
|
||||
->arrayNode('notifications')
|
||||
->children()
|
||||
->scalarNode('from_email')
|
||||
->cannotBeEmpty()
|
||||
->end()
|
||||
->scalarNode('from_name')
|
||||
->cannotBeEmpty()
|
||||
->end()
|
||||
->enumNode('scheme')
|
||||
->cannotBeEmpty()
|
||||
->values(['http', 'https'])
|
||||
->defaultValue('https')
|
||||
->end()
|
||||
->scalarNode('host')
|
||||
->cannotBeEmpty()
|
||||
->end()
|
||||
->end()
|
||||
->end() // end of notifications
|
||||
->arrayNode('phone_helper')
|
||||
->canBeUnset()
|
||||
->children()
|
||||
->scalarNode('twilio_sid')
|
||||
->defaultNull()
|
||||
->end()
|
||||
->scalarNode('twilio_secret')
|
||||
->defaultNull()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('acl')
|
||||
->addDefaultsIfNotSet()
|
||||
->children()
|
||||
->booleanNode('form_show_scopes')
|
||||
->defaultTrue()
|
||||
->end()
|
||||
->booleanNode('form_show_centers')
|
||||
->defaultTrue()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('redis')
|
||||
->children()
|
||||
->scalarNode('host')
|
||||
->cannotBeEmpty()
|
||||
->end()
|
||||
->scalarNode('port')
|
||||
->defaultValue(6379)
|
||||
->end()
|
||||
->scalarNode('timeout')
|
||||
->defaultValue(1)
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('widgets')
|
||||
->canBeEnabled()
|
||||
->canBeUnset()
|
||||
->children()
|
||||
->append($this->addWidgetsConfiguration('homepage', $this->containerBuilder))
|
||||
->end() // end of widgets/children
|
||||
->end() // end of widgets
|
||||
->arrayNode('cruds')
|
||||
->defaultValue([])
|
||||
->arrayPrototype()
|
||||
->children()
|
||||
->scalarNode('class')->cannotBeEmpty()->isRequired()->end()
|
||||
->scalarNode('controller')
|
||||
->cannotBeEmpty()
|
||||
->defaultValue(\Chill\MainBundle\CRUD\Controller\CRUDController::class)
|
||||
->end()
|
||||
->scalarNode('name')->cannotBeEmpty()->isRequired()->end()
|
||||
->scalarNode('base_path')->cannotBeEmpty()->isRequired()->end()
|
||||
->scalarNode('base_role')->defaultNull()->end()
|
||||
->scalarNode('form_class')->defaultNull()->end()
|
||||
->arrayNode('actions')
|
||||
->defaultValue([
|
||||
'edit' => [],
|
||||
'new' => [],
|
||||
])
|
||||
->useAttributeAsKey('name')
|
||||
->arrayPrototype()
|
||||
->children()
|
||||
->scalarNode('controller_action')
|
||||
->defaultNull()
|
||||
->info('the method name to call in the route. Will be set to the action name if left empty.')
|
||||
->example('action')
|
||||
->end()
|
||||
->scalarNode('path')
|
||||
->defaultNull()
|
||||
->info('the path that will be **appended** after the base path. Do not forget to add '
|
||||
. 'arguments for the method. Will be set to the action name, including an `{id}` '
|
||||
. 'parameter if left empty.')
|
||||
->example('/{id}/my-action')
|
||||
->end()
|
||||
->arrayNode('requirements')
|
||||
->ignoreExtraKeys(false)
|
||||
->info('the requirements for the route. Will be set to `[ \'id\' => \'\d+\' ]` if left empty.')
|
||||
->end()
|
||||
->scalarNode('role')
|
||||
->defaultNull()
|
||||
->info('the role that will be required for this action. Override option `base_role`')
|
||||
->end()
|
||||
->scalarNode('template')
|
||||
->defaultNull()
|
||||
->info('the template to render the view')
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
|
||||
->end()
|
||||
|
||||
|
||||
->arrayNode('apis')
|
||||
->defaultValue([])
|
||||
->arrayPrototype()
|
||||
->children()
|
||||
->scalarNode('class')->cannotBeEmpty()->isRequired()->end()
|
||||
->scalarNode('controller')
|
||||
->cannotBeEmpty()
|
||||
->defaultValue(\Chill\MainBundle\CRUD\Controller\ApiController::class)
|
||||
->end()
|
||||
->scalarNode('name')->cannotBeEmpty()->isRequired()->end()
|
||||
->scalarNode('base_path')->cannotBeEmpty()->isRequired()->end()
|
||||
->scalarNode('base_role')->defaultNull()->end()
|
||||
->arrayNode('actions')
|
||||
->useAttributeAsKey('name')
|
||||
->arrayPrototype()
|
||||
->children()
|
||||
->scalarNode('controller_action')
|
||||
->defaultNull()
|
||||
->info('the method name to call in the controller. Will be set to the concatenation '.
|
||||
->example('/{id}/my-action')
|
||||
->end()
|
||||
->arrayNode('requirements')
|
||||
->ignoreExtraKeys(false)
|
||||
->info('the requirements for the route. Will be set to `[ \'id\' => \'\d+\' ]` if left empty.')
|
||||
->end()
|
||||
->scalarNode('role')
|
||||
->defaultNull()
|
||||
->info('the role that will be required for this action. Override option `base_role`')
|
||||
->end()
|
||||
->scalarNode('template')
|
||||
->defaultNull()
|
||||
->info('the template to render the view')
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('apis')
|
||||
->defaultValue([])
|
||||
->arrayPrototype()
|
||||
->children()
|
||||
->scalarNode('class')->cannotBeEmpty()->isRequired()->end()
|
||||
->scalarNode('controller')
|
||||
->cannotBeEmpty()
|
||||
->defaultValue(\Chill\MainBundle\CRUD\Controller\ApiController::class)
|
||||
->end()
|
||||
->scalarNode('name')->cannotBeEmpty()->isRequired()->end()
|
||||
->scalarNode('base_path')->cannotBeEmpty()->isRequired()->end()
|
||||
->scalarNode('base_role')->defaultNull()->end()
|
||||
->arrayNode('actions')
|
||||
->useAttributeAsKey('name')
|
||||
->arrayPrototype()
|
||||
->children()
|
||||
->scalarNode('controller_action')
|
||||
->defaultNull()
|
||||
->info('the method name to call in the controller. Will be set to the concatenation ' .
|
||||
'of action name + \'Api\' if left empty.')
|
||||
->example("showApi")
|
||||
->end()
|
||||
->scalarNode('path')
|
||||
->defaultNull()
|
||||
->info('the path that will be **appended** after the base path. Do not forget to add ' .
|
||||
'arguments for the method. By default, will set to the action name, including an `{id}` '.
|
||||
'parameter. A suffix of action name will be appended, except if the action name '.
|
||||
->example('showApi')
|
||||
->end()
|
||||
->scalarNode('path')
|
||||
->defaultNull()
|
||||
->info('the path that will be **appended** after the base path. Do not forget to add ' .
|
||||
'arguments for the method. By default, will set to the action name, including an `{id}` ' .
|
||||
'parameter. A suffix of action name will be appended, except if the action name ' .
|
||||
'is "_entity".')
|
||||
->example('/{id}/my-action')
|
||||
->end()
|
||||
->arrayNode('requirements')
|
||||
->ignoreExtraKeys(false)
|
||||
->info('the requirements for the route. Will be set to `[ \'id\' => \'\d+\' ]` if left empty.')
|
||||
->end()
|
||||
->enumNode('single_collection')
|
||||
->values(['single', 'collection'])
|
||||
->defaultValue('single')
|
||||
->info('indicates if the returned object is a single element or a collection. '.
|
||||
'If the action name is `_index`, this value will always be considered as '.
|
||||
->example('/{id}/my-action')
|
||||
->end()
|
||||
->arrayNode('requirements')
|
||||
->ignoreExtraKeys(false)
|
||||
->info('the requirements for the route. Will be set to `[ \'id\' => \'\d+\' ]` if left empty.')
|
||||
->end()
|
||||
->enumNode('single_collection')
|
||||
->values(['single', 'collection'])
|
||||
->defaultValue('single')
|
||||
->info('indicates if the returned object is a single element or a collection. ' .
|
||||
'If the action name is `_index`, this value will always be considered as ' .
|
||||
'`collection`')
|
||||
->end()
|
||||
->arrayNode('methods')
|
||||
->addDefaultsIfNotSet()
|
||||
->info('the allowed methods')
|
||||
->children()
|
||||
->booleanNode(Request::METHOD_GET)->defaultTrue()->end()
|
||||
->booleanNode(Request::METHOD_HEAD)->defaultTrue()->end()
|
||||
->booleanNode(Request::METHOD_POST)->defaultFalse()->end()
|
||||
->booleanNode(Request::METHOD_DELETE)->defaultFalse()->end()
|
||||
->booleanNode(Request::METHOD_PUT)->defaultFalse()->end()
|
||||
->booleanNode(Request::METHOD_PATCH)->defaultFalse()->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('roles')
|
||||
->addDefaultsIfNotSet()
|
||||
->info("The role require for each http method")
|
||||
->children()
|
||||
->scalarNode(Request::METHOD_GET)->defaultNull()->end()
|
||||
->scalarNode(Request::METHOD_HEAD)->defaultNull()->end()
|
||||
->scalarNode(Request::METHOD_POST)->defaultNull()->end()
|
||||
->scalarNode(Request::METHOD_DELETE)->defaultNull()->end()
|
||||
->scalarNode(Request::METHOD_PUT)->defaultNull()->end()
|
||||
->scalarNode(Request::METHOD_PATCH)->defaultNull()->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
|
||||
->end()
|
||||
->end() // end of root/children
|
||||
->end()
|
||||
->arrayNode('methods')
|
||||
->addDefaultsIfNotSet()
|
||||
->info('the allowed methods')
|
||||
->children()
|
||||
->booleanNode(Request::METHOD_GET)->defaultTrue()->end()
|
||||
->booleanNode(Request::METHOD_HEAD)->defaultTrue()->end()
|
||||
->booleanNode(Request::METHOD_POST)->defaultFalse()->end()
|
||||
->booleanNode(Request::METHOD_DELETE)->defaultFalse()->end()
|
||||
->booleanNode(Request::METHOD_PUT)->defaultFalse()->end()
|
||||
->booleanNode(Request::METHOD_PATCH)->defaultFalse()->end()
|
||||
->end()
|
||||
->end()
|
||||
->arrayNode('roles')
|
||||
->addDefaultsIfNotSet()
|
||||
->info('The role require for each http method')
|
||||
->children()
|
||||
->scalarNode(Request::METHOD_GET)->defaultNull()->end()
|
||||
->scalarNode(Request::METHOD_HEAD)->defaultNull()->end()
|
||||
->scalarNode(Request::METHOD_POST)->defaultNull()->end()
|
||||
->scalarNode(Request::METHOD_DELETE)->defaultNull()->end()
|
||||
->scalarNode(Request::METHOD_PUT)->defaultNull()->end()
|
||||
->scalarNode(Request::METHOD_PATCH)->defaultNull()->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end() // end of root/children
|
||||
->end() // end of root
|
||||
;
|
||||
|
||||
;
|
||||
|
||||
return $treeBuilder;
|
||||
}
|
||||
|
@@ -1,20 +1,25 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\DependencyInjection;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Description of MissingBundleException
|
||||
*
|
||||
* @author julien
|
||||
* Description of MissingBundleException.
|
||||
*/
|
||||
class MissingBundleException extends Exception {
|
||||
|
||||
public function __construct($missingBundleName) {
|
||||
$message = "The bundle $missingBundleName is missing.";
|
||||
|
||||
class MissingBundleException extends Exception
|
||||
{
|
||||
public function __construct($missingBundleName)
|
||||
{
|
||||
$message = "The bundle {$missingBundleName} is missing.";
|
||||
|
||||
parent::__construct($message, 500);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,42 +1,28 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2015 Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use LogicException;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class RoleProvidersCompilerPass implements CompilerPassInterface
|
||||
{
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->hasDefinition('chill.main.role_provider')) {
|
||||
throw new \LogicException('service chill.main.role_provider '
|
||||
throw new LogicException('service chill.main.role_provider '
|
||||
. 'is not defined. It is required by RoleProviderCompilerPass');
|
||||
}
|
||||
|
||||
|
||||
$definition = $container->getDefinition(
|
||||
'chill.main.role_provider'
|
||||
);
|
||||
@@ -44,14 +30,12 @@ class RoleProvidersCompilerPass implements CompilerPassInterface
|
||||
$taggedServices = $container->findTaggedServiceIds(
|
||||
'chill.role'
|
||||
);
|
||||
|
||||
|
||||
foreach ($taggedServices as $id => $tagAttributes) {
|
||||
$definition->addMethodCall(
|
||||
'addProvider',
|
||||
array(new Reference($id))
|
||||
[new Reference($id)]
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,32 +1,24 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2016 Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\DependencyInjection\Widget;
|
||||
|
||||
use Chill\MainBundle\DependencyInjection\Widget\Factory\WidgetFactoryInterface;
|
||||
use Doctrine\Common\Proxy\Exception\InvalidArgumentException;
|
||||
use LengthException;
|
||||
use LogicException;
|
||||
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
|
||||
use Doctrine\Common\Proxy\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Chill\MainBundle\DependencyInjection\Widget\Factory\WidgetFactoryInterface;
|
||||
use Chill\MainBundle\DependencyInjection\Widget\HasWidgetFactoriesExtensionInterface;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use UnexpectedValueException;
|
||||
|
||||
/**
|
||||
* Compile the configurations and inject required service into container.
|
||||
@@ -57,37 +49,30 @@ use Chill\MainBundle\DependencyInjection\Widget\HasWidgetFactoriesExtensionInter
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
*
|
||||
*/
|
||||
abstract class AbstractWidgetsCompilerPass implements CompilerPassInterface
|
||||
{
|
||||
private $widgetServices = array();
|
||||
|
||||
/**
|
||||
*
|
||||
* @var WidgetFactoryInterface[]
|
||||
* the key to use to identify widget for a given place.
|
||||
*/
|
||||
private $widgetFactories;
|
||||
public const WIDGET_CONFIG_ALIAS = 'widget_alias';
|
||||
|
||||
/**
|
||||
* The service which will manage the widgets
|
||||
* the key to use to order widget for a given place.
|
||||
*/
|
||||
public const WIDGET_CONFIG_ORDER = 'order';
|
||||
|
||||
/**
|
||||
* The service which will manage the widgets.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const WIDGET_MANAGER = 'chill.main.twig.widget';
|
||||
public const WIDGET_MANAGER = 'chill.main.twig.widget';
|
||||
|
||||
/**
|
||||
* the method wich register the widget into give service.
|
||||
*/
|
||||
const WIDGET_MANAGER_METHOD_REGISTER = 'addWidget';
|
||||
|
||||
/**
|
||||
* the value of the `name` key in service definitions's tag
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const WIDGET_SERVICE_TAG_NAME = 'chill_widget';
|
||||
public const WIDGET_MANAGER_METHOD_REGISTER = 'addWidget';
|
||||
|
||||
/**
|
||||
* the key used to collect the alias in the service definition's tag.
|
||||
@@ -96,34 +81,46 @@ abstract class AbstractWidgetsCompilerPass implements CompilerPassInterface
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const WIDGET_SERVICE_TAG_ALIAS = 'alias';
|
||||
public const WIDGET_SERVICE_TAG_ALIAS = 'alias';
|
||||
|
||||
/**
|
||||
* the key used to collect the authorized place in the service definition's tag
|
||||
* the value of the `name` key in service definitions's tag.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const WIDGET_SERVICE_TAG_PLACES = 'place';
|
||||
public const WIDGET_SERVICE_TAG_NAME = 'chill_widget';
|
||||
|
||||
/**
|
||||
* the key to use to order widget for a given place
|
||||
*/
|
||||
const WIDGET_CONFIG_ORDER = 'order';
|
||||
|
||||
/**
|
||||
* the key to use to identify widget for a given place
|
||||
*/
|
||||
const WIDGET_CONFIG_ALIAS = 'widget_alias';
|
||||
|
||||
|
||||
/**
|
||||
* process the configuration and the container to add the widget available
|
||||
* the key used to collect the authorized place in the service definition's tag.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public const WIDGET_SERVICE_TAG_PLACES = 'place';
|
||||
|
||||
/**
|
||||
* cache of ordering by place.
|
||||
*
|
||||
* @internal used by function cacheAndGetOrdering
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $cacheOrdering = [];
|
||||
|
||||
/**
|
||||
* @var WidgetFactoryInterface[]
|
||||
*/
|
||||
private $widgetFactories;
|
||||
|
||||
private $widgetServices = [];
|
||||
|
||||
/**
|
||||
* process the configuration and the container to add the widget available.
|
||||
*
|
||||
* @param ContainerBuilder $container
|
||||
* @param string $extension the extension of your bundle
|
||||
* @param string $containerWidgetConfigParameterName the key under which we can use the widget configuration
|
||||
* @throws \LogicException
|
||||
* @throws \UnexpectedValueException if the given extension does not implement HasWidgetExtensionInterface
|
||||
*
|
||||
* @throws LogicException
|
||||
* @throws UnexpectedValueException if the given extension does not implement HasWidgetExtensionInterface
|
||||
*/
|
||||
public function doProcess(
|
||||
ContainerBuilder $container,
|
||||
@@ -131,8 +128,8 @@ abstract class AbstractWidgetsCompilerPass implements CompilerPassInterface
|
||||
$containerWidgetConfigParameterName
|
||||
) {
|
||||
if (!$container->hasDefinition(self::WIDGET_MANAGER)) {
|
||||
throw new \LogicException("the service ".self::WIDGET_MANAGER." should".
|
||||
" be present. It is required by ".self::class);
|
||||
throw new LogicException('the service ' . self::WIDGET_MANAGER . ' should' .
|
||||
' be present. It is required by ' . self::class);
|
||||
}
|
||||
|
||||
$managerDefinition = $container->getDefinition(self::WIDGET_MANAGER);
|
||||
@@ -142,15 +139,16 @@ abstract class AbstractWidgetsCompilerPass implements CompilerPassInterface
|
||||
$extensionClass = $container->getExtension($extension);
|
||||
// throw an error if extension does not implement HasWidgetFactoriesExtensionInterface
|
||||
if (!$extensionClass instanceof HasWidgetFactoriesExtensionInterface) {
|
||||
throw new \UnexpectedValueException(sprintf("The extension for %s "
|
||||
. "do not implements %s. You should implement %s on %s",
|
||||
$extension,
|
||||
HasWidgetFactoriesExtensionInterface::class,
|
||||
HasWidgetFactoriesExtensionInterface::class,
|
||||
get_class($extensionClass)));
|
||||
throw new UnexpectedValueException(sprintf(
|
||||
'The extension for %s '
|
||||
. 'do not implements %s. You should implement %s on %s',
|
||||
$extension,
|
||||
HasWidgetFactoriesExtensionInterface::class,
|
||||
HasWidgetFactoriesExtensionInterface::class,
|
||||
get_class($extensionClass)
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
$this->widgetFactories = $extensionClass->getWidgetFactories();
|
||||
|
||||
// collect the availabled tagged services
|
||||
@@ -160,23 +158,22 @@ abstract class AbstractWidgetsCompilerPass implements CompilerPassInterface
|
||||
$widgetParameters = $container->getParameter($containerWidgetConfigParameterName);
|
||||
|
||||
// and add them to the delegated_block
|
||||
foreach($widgetParameters as $place => $widgets) {
|
||||
|
||||
foreach ($widgetParameters as $place => $widgets) {
|
||||
foreach ($widgets as $param) {
|
||||
$alias = $param[self::WIDGET_CONFIG_ALIAS];
|
||||
// check that the service exists
|
||||
if (!array_key_exists($alias, $this->widgetServices)) {
|
||||
throw new InvalidConfigurationException(sprintf("The alias %s".
|
||||
" is not defined.", $alias));
|
||||
throw new InvalidConfigurationException(sprintf('The alias %s' .
|
||||
' is not defined.', $alias));
|
||||
}
|
||||
|
||||
// check that the widget is allowed at this place
|
||||
if (!$this->isPlaceAllowedForWidget($place, $alias, $container)) {
|
||||
throw new InvalidConfigurationException(sprintf(
|
||||
"The widget with alias %s is not allowed at place %s",
|
||||
'The widget with alias %s is not allowed at place %s',
|
||||
$alias,
|
||||
$place
|
||||
));
|
||||
));
|
||||
}
|
||||
|
||||
// get the order, eventually corrected
|
||||
@@ -189,64 +186,145 @@ abstract class AbstractWidgetsCompilerPass implements CompilerPassInterface
|
||||
$factory = $this->widgetServices[$alias];
|
||||
// get the config (under the key which equals to widget_alias
|
||||
$config = isset($param[$factory->getWidgetAlias()]) ?
|
||||
$param[$factory->getWidgetAlias()] : array();
|
||||
$param[$factory->getWidgetAlias()] : [];
|
||||
// register the service into the container
|
||||
$serviceId =$this->registerServiceIntoContainer($container,
|
||||
$factory, $place, $order, $config);
|
||||
$serviceId = $this->registerServiceIntoContainer(
|
||||
$container,
|
||||
$factory,
|
||||
$place,
|
||||
$order,
|
||||
$config
|
||||
);
|
||||
|
||||
$managerDefinition->addMethodCall(self::WIDGET_MANAGER_METHOD_REGISTER,
|
||||
array(
|
||||
$place,
|
||||
$order,
|
||||
new Reference($serviceId),
|
||||
$config
|
||||
));
|
||||
$managerDefinition->addMethodCall(
|
||||
self::WIDGET_MANAGER_METHOD_REGISTER,
|
||||
[
|
||||
$place,
|
||||
$order,
|
||||
new Reference($serviceId),
|
||||
$config,
|
||||
]
|
||||
);
|
||||
} else {
|
||||
$managerDefinition->addMethodCall(self::WIDGET_MANAGER_METHOD_REGISTER,
|
||||
array(
|
||||
$place,
|
||||
$order,
|
||||
new Reference($this->widgetServices[$alias]),
|
||||
array() // the config is alway an empty array
|
||||
));
|
||||
$managerDefinition->addMethodCall(
|
||||
self::WIDGET_MANAGER_METHOD_REGISTER,
|
||||
[
|
||||
$place,
|
||||
$order,
|
||||
new Reference($this->widgetServices[$alias]),
|
||||
[], // the config is alway an empty array
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method collect all service tagged with `self::WIDGET_SERVICE_TAG`, and
|
||||
* add also the widget defined by factories.
|
||||
*
|
||||
* This method also check that the service is correctly tagged with `alias` and
|
||||
* `places`, or the factory give a correct alias and more than one place.
|
||||
*
|
||||
* @throws InvalidConfigurationException
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
protected function collectTaggedServices(ContainerBuilder $container)
|
||||
{
|
||||
// first, check the service tagged in service definition
|
||||
foreach ($container->findTaggedServiceIds(self::WIDGET_SERVICE_TAG_NAME) as $id => $attrs) {
|
||||
foreach ($attrs as $attr) {
|
||||
// check the alias is set
|
||||
if (!isset($attr[self::WIDGET_SERVICE_TAG_ALIAS])) {
|
||||
throw new InvalidConfigurationException('you should add an ' . self::WIDGET_SERVICE_TAG_ALIAS .
|
||||
' key on the service ' . $id);
|
||||
}
|
||||
|
||||
// check the place is set
|
||||
if (!isset($attr[self::WIDGET_SERVICE_TAG_PLACES])) {
|
||||
throw new InvalidConfigurationException(sprintf(
|
||||
'You should add a %s key on the service %s',
|
||||
self::WIDGET_SERVICE_TAG_PLACES,
|
||||
$id
|
||||
));
|
||||
}
|
||||
|
||||
// check the alias does not exists yet
|
||||
if (array_key_exists($attr[self::WIDGET_SERVICE_TAG_ALIAS], $this->widgetServices)) {
|
||||
throw new InvalidArgumentException('a service has already be defined with the ' .
|
||||
self::WIDGET_SERVICE_TAG_ALIAS . ' ' . $attr[self::WIDGET_SERVICE_TAG_ALIAS]);
|
||||
}
|
||||
|
||||
// register the service as available
|
||||
$this->widgetServices[$attr[self::WIDGET_SERVICE_TAG_ALIAS]] = $id;
|
||||
}
|
||||
}
|
||||
|
||||
// add the services defined by factories
|
||||
foreach ($this->widgetFactories as $factory) {
|
||||
/* @var $factory WidgetFactoryInterface */
|
||||
$alias = $factory->getWidgetAlias();
|
||||
|
||||
// check the alias is not empty
|
||||
if (empty($alias)) {
|
||||
throw new LogicException(sprintf(
|
||||
'the widget factory %s returns an empty alias',
|
||||
get_class($factory)
|
||||
));
|
||||
}
|
||||
|
||||
// check the places are not empty
|
||||
if (!is_array($factory->getAllowedPlaces())) {
|
||||
throw new UnexpectedValueException("the method 'getAllowedPlaces' "
|
||||
. 'should return a non-empty array. Unexpected value on ' .
|
||||
get_class($factory));
|
||||
}
|
||||
|
||||
if (count($factory->getAllowedPlaces()) == 0) {
|
||||
throw new LengthException("The method 'getAllowedPlaces' should "
|
||||
. 'return a non-empty array, but returned 0 elements on ' .
|
||||
get_class($factory) . '::getAllowedPlaces()');
|
||||
}
|
||||
|
||||
// check the alias does not exists yet
|
||||
if (array_key_exists($alias, $this->widgetServices)) {
|
||||
throw new InvalidArgumentException('a service has already be defined with the ' .
|
||||
self::WIDGET_SERVICE_TAG_ALIAS . ' ' . $alias);
|
||||
}
|
||||
|
||||
// register the factory as available
|
||||
$this->widgetServices[$factory->getWidgetAlias()] = $factory;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* register the service into container.
|
||||
*
|
||||
* @param ContainerBuilder $container
|
||||
* @param WidgetFactoryInterface $factory
|
||||
* @param string $place
|
||||
* @param float $order
|
||||
* @param array $config
|
||||
*
|
||||
* @return string the id of the new service
|
||||
*/
|
||||
protected function registerServiceIntoContainer(
|
||||
ContainerBuilder $container,
|
||||
WidgetFactoryInterface $factory,
|
||||
ContainerBuilder $container,
|
||||
WidgetFactoryInterface $factory,
|
||||
$place,
|
||||
$order,
|
||||
array $config
|
||||
) {
|
||||
$serviceId = $factory->getServiceId($container, $place, $order, $config);
|
||||
$definition = $factory->createDefinition(
|
||||
$container,
|
||||
$place,
|
||||
$order,
|
||||
array $config
|
||||
) {
|
||||
$serviceId = $factory->getServiceId($container, $place, $order, $config);
|
||||
$definition = $factory->createDefinition($container, $place,
|
||||
$order, $config);
|
||||
$config
|
||||
);
|
||||
$container->setDefinition($serviceId, $definition);
|
||||
|
||||
return $serviceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* cache of ordering by place.
|
||||
*
|
||||
* @internal used by function cacheAndGetOrdering
|
||||
* @var array
|
||||
*/
|
||||
private $cacheOrdering = array();
|
||||
|
||||
/**
|
||||
* check if the ordering has already be used for the given $place and,
|
||||
* if yes, correct the ordering by incrementation of 1 until the ordering
|
||||
@@ -256,44 +334,46 @@ abstract class AbstractWidgetsCompilerPass implements CompilerPassInterface
|
||||
*
|
||||
* @param string $place
|
||||
* @param float $ordering
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
private function cacheAndGetOrdering($place, $ordering) {
|
||||
private function cacheAndGetOrdering($place, $ordering)
|
||||
{
|
||||
// create a key in the cache array if not exists
|
||||
if (!array_key_exists($place, $this->cacheOrdering)) {
|
||||
$this->cacheOrdering[$place] = array();
|
||||
$this->cacheOrdering[$place] = [];
|
||||
}
|
||||
|
||||
// check if the order exists
|
||||
if (array_search($ordering, $this->cacheOrdering[$place])) {
|
||||
// if the order exists, increment of 1 and try again
|
||||
return $this->cacheAndGetOrdering($place, $ordering + 1);
|
||||
} else {
|
||||
// cache the ordering
|
||||
$this->cacheOrdering[$place][] = $ordering;
|
||||
|
||||
return $ordering;
|
||||
}
|
||||
// cache the ordering
|
||||
$this->cacheOrdering[$place][] = $ordering;
|
||||
|
||||
return $ordering;
|
||||
}
|
||||
|
||||
/**
|
||||
* get the places where the service is allowed
|
||||
* get the places where the service is allowed.
|
||||
*
|
||||
* @param mixed $place
|
||||
* @param mixed $widgetAlias
|
||||
*
|
||||
* @param Definition $definition
|
||||
* @return unknown
|
||||
*/
|
||||
private function isPlaceAllowedForWidget($place, $widgetAlias, ContainerBuilder $container)
|
||||
{
|
||||
if ($this->widgetServices[$widgetAlias] instanceof WidgetFactoryInterface) {
|
||||
if (in_array($place, $this->widgetServices[$widgetAlias]
|
||||
->getAllowedPlaces())) {
|
||||
->getAllowedPlaces())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
} else {
|
||||
$definition = $container->findDefinition($this->widgetServices[$widgetAlias]);
|
||||
|
||||
foreach($definition->getTag(self::WIDGET_SERVICE_TAG_NAME) as $attrs) {
|
||||
foreach ($definition->getTag(self::WIDGET_SERVICE_TAG_NAME) as $attrs) {
|
||||
$placeValue = $attrs[self::WIDGET_SERVICE_TAG_PLACES];
|
||||
|
||||
if ($placeValue === $place) {
|
||||
@@ -304,86 +384,4 @@ abstract class AbstractWidgetsCompilerPass implements CompilerPassInterface
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method collect all service tagged with `self::WIDGET_SERVICE_TAG`, and
|
||||
* add also the widget defined by factories
|
||||
*
|
||||
* This method also check that the service is correctly tagged with `alias` and
|
||||
* `places`, or the factory give a correct alias and more than one place.
|
||||
*
|
||||
* @param ContainerBuilder $container
|
||||
* @throws InvalidConfigurationException
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
protected function collectTaggedServices(ContainerBuilder $container)
|
||||
{
|
||||
// first, check the service tagged in service definition
|
||||
foreach ($container->findTaggedServiceIds(self::WIDGET_SERVICE_TAG_NAME) as $id => $attrs) {
|
||||
foreach ($attrs as $attr) {
|
||||
|
||||
// check the alias is set
|
||||
if (!isset($attr[self::WIDGET_SERVICE_TAG_ALIAS])) {
|
||||
throw new InvalidConfigurationException("you should add an ".self::WIDGET_SERVICE_TAG_ALIAS.
|
||||
" key on the service ".$id);
|
||||
}
|
||||
|
||||
// check the place is set
|
||||
if (!isset($attr[self::WIDGET_SERVICE_TAG_PLACES])) {
|
||||
throw new InvalidConfigurationException(sprintf(
|
||||
"You should add a %s key on the service %s",
|
||||
self::WIDGET_SERVICE_TAG_PLACES,
|
||||
$id
|
||||
));
|
||||
}
|
||||
|
||||
// check the alias does not exists yet
|
||||
if (array_key_exists($attr[self::WIDGET_SERVICE_TAG_ALIAS], $this->widgetServices)) {
|
||||
throw new InvalidArgumentException("a service has already be defined with the ".
|
||||
self::WIDGET_SERVICE_TAG_ALIAS." ".$attr[self::WIDGET_SERVICE_TAG_ALIAS]);
|
||||
}
|
||||
|
||||
// register the service as available
|
||||
$this->widgetServices[$attr[self::WIDGET_SERVICE_TAG_ALIAS]] = $id;
|
||||
}
|
||||
}
|
||||
|
||||
// add the services defined by factories
|
||||
foreach($this->widgetFactories as $factory) {
|
||||
/* @var $factory WidgetFactoryInterface */
|
||||
$alias = $factory->getWidgetAlias();
|
||||
|
||||
// check the alias is not empty
|
||||
if (empty($alias)) {
|
||||
throw new \LogicException(sprintf(
|
||||
"the widget factory %s returns an empty alias",
|
||||
get_class($factory)));
|
||||
}
|
||||
|
||||
// check the places are not empty
|
||||
if (!is_array($factory->getAllowedPlaces())) {
|
||||
throw new \UnexpectedValueException("the method 'getAllowedPlaces' "
|
||||
. "should return a non-empty array. Unexpected value on ".
|
||||
get_class($factory));
|
||||
}
|
||||
|
||||
if (count($factory->getAllowedPlaces()) == 0) {
|
||||
throw new \LengthException("The method 'getAllowedPlaces' should "
|
||||
. "return a non-empty array, but returned 0 elements on ".
|
||||
get_class($factory).'::getAllowedPlaces()');
|
||||
}
|
||||
|
||||
// check the alias does not exists yet
|
||||
if (array_key_exists($alias, $this->widgetServices)) {
|
||||
throw new InvalidArgumentException("a service has already be defined with the ".
|
||||
self::WIDGET_SERVICE_TAG_ALIAS." ".$alias);
|
||||
}
|
||||
|
||||
// register the factory as available
|
||||
$this->widgetServices[$factory->getWidgetAlias()] = $factory;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -1,90 +1,81 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2016 Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\DependencyInjection\Widget;
|
||||
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Chill\MainBundle\DependencyInjection\Widget\AbstractWidgetsCompilerPass as WidgetsCompilerPass;
|
||||
use Generator;
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use function implode;
|
||||
|
||||
/**
|
||||
* This trait allow to add automatic configuration for widget inside your config.
|
||||
*
|
||||
* Usage
|
||||
*
|
||||
* Usage
|
||||
* ======
|
||||
*
|
||||
*
|
||||
* 1. Register widget factories
|
||||
* ----------------------------
|
||||
*
|
||||
*
|
||||
* Add widget factories, using `setWidgetFactories`
|
||||
*
|
||||
* Example :
|
||||
*
|
||||
*
|
||||
* Example :
|
||||
*
|
||||
* ```
|
||||
* use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
* use Chill\MainBundle\DependencyInjection\Widget\AddWidgetConfigurationTrait;
|
||||
*
|
||||
* class MyConfig
|
||||
*
|
||||
* class MyConfig
|
||||
* {
|
||||
*
|
||||
*
|
||||
* use addWidgetConfigurationTrait;
|
||||
*
|
||||
*
|
||||
* public function __construct(array $widgetFactories = array(), ContainerBuilder $container)
|
||||
* {
|
||||
* $this->setWidgetFactories($widgetFactories);
|
||||
* // will be used on next step
|
||||
* $this->container = $container;
|
||||
* }
|
||||
*
|
||||
*
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* 2. add widget config to your config
|
||||
* -----------------------------------
|
||||
*
|
||||
*
|
||||
* ```
|
||||
* use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
* use Chill\MainBundle\DependencyInjection\Widget\AddWidgetConfigurationTrait;
|
||||
* use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
*
|
||||
* class MyConfig
|
||||
*
|
||||
* class MyConfig
|
||||
* {
|
||||
*
|
||||
*
|
||||
* use addWidgetConfigurationTrait;
|
||||
*
|
||||
*
|
||||
* private $container;
|
||||
*
|
||||
*
|
||||
* public function __construct(array $widgetFactories = array(), ContainerBuilder $container)
|
||||
* {
|
||||
* $this->setWidgetFactories($widgetFactories);
|
||||
* $this->container;
|
||||
* }
|
||||
*
|
||||
*
|
||||
* public function getConfigTreeBuilder()
|
||||
* {
|
||||
* $treeBuilder = new TreeBuilder();
|
||||
* $root = $treeBuilder->root('my_root');
|
||||
*
|
||||
*
|
||||
* $root->children()
|
||||
* ->arrayNode('widgets')
|
||||
* ->canBeDisabled()
|
||||
@@ -93,15 +84,15 @@ use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
|
||||
* ->end()
|
||||
* ->end()
|
||||
* ;
|
||||
*
|
||||
*
|
||||
* return $treeBuilder;
|
||||
* }
|
||||
*
|
||||
*
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* the above code will add to the config :
|
||||
*
|
||||
*
|
||||
* the above code will add to the config :
|
||||
*
|
||||
* ```
|
||||
* widgets:
|
||||
* enabled: true
|
||||
@@ -113,8 +104,6 @@ use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
|
||||
* person_list:
|
||||
* # options for the person_list
|
||||
* ```
|
||||
*
|
||||
*
|
||||
*/
|
||||
trait AddWidgetConfigurationTrait
|
||||
{
|
||||
@@ -122,16 +111,7 @@ trait AddWidgetConfigurationTrait
|
||||
* @param WidgetFactoryInterface[]
|
||||
*/
|
||||
private $widgetFactories;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param WidgetFactoryInterface[] $widgetFactories
|
||||
*/
|
||||
public function setWidgetFactories(array $widgetFactories)
|
||||
{
|
||||
$this->widgetFactories = $widgetFactories;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return WidgetFactoryInterface[]
|
||||
*/
|
||||
@@ -139,12 +119,20 @@ trait AddWidgetConfigurationTrait
|
||||
{
|
||||
return $this->widgetFactories;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param WidgetFactoryInterface[] $widgetFactories
|
||||
*/
|
||||
public function setWidgetFactories(array $widgetFactories)
|
||||
{
|
||||
$this->widgetFactories = $widgetFactories;
|
||||
}
|
||||
|
||||
/**
|
||||
* add configuration nodes for the widget at the given place.
|
||||
*
|
||||
*
|
||||
* @param type $place
|
||||
* @param ContainerBuilder $containerBuilder
|
||||
*
|
||||
* @return type
|
||||
*/
|
||||
protected function addWidgetsConfiguration($place, ContainerBuilder $containerBuilder)
|
||||
@@ -152,101 +140,104 @@ trait AddWidgetConfigurationTrait
|
||||
$treeBuilder = new TreeBuilder($place);
|
||||
$root = $treeBuilder->getRootNode($place)
|
||||
->canBeUnset()
|
||||
->info('register widgets on place "'.$place.'"');
|
||||
|
||||
->info('register widgets on place "' . $place . '"');
|
||||
|
||||
// if no childen, return the root
|
||||
if (count(iterator_to_array($this->filterWidgetByPlace($place))) === 0) {
|
||||
return $root;
|
||||
}
|
||||
|
||||
|
||||
$prototypeChildren = $root->prototype('array')->children();
|
||||
|
||||
|
||||
$prototypeChildren
|
||||
->floatNode(WidgetsCompilerPass::WIDGET_CONFIG_ORDER)
|
||||
->isRequired()
|
||||
->info("the ordering of the widget. May be a number with decimal")
|
||||
->example("10.58")
|
||||
->end()
|
||||
->isRequired()
|
||||
->info('the ordering of the widget. May be a number with decimal')
|
||||
->example('10.58')
|
||||
->end()
|
||||
->scalarNode(WidgetsCompilerPass::WIDGET_CONFIG_ALIAS)
|
||||
// this node is scalar: when the configuration is build, the
|
||||
// tagged services are not available. But when the config reference
|
||||
// is build, the services are avaialble => we add the possible aliases
|
||||
// in the info.
|
||||
->info("the widget alias (see your installed bundles config). "
|
||||
. "Possible values are (maybe incomplete) : ".
|
||||
\implode(", ", $this->getWidgetAliasesbyPlace($place, $containerBuilder)))
|
||||
->isRequired()
|
||||
->end()
|
||||
;
|
||||
|
||||
->info('the widget alias (see your installed bundles config). '
|
||||
. 'Possible values are (maybe incomplete) : ' .
|
||||
implode(', ', $this->getWidgetAliasesbyPlace($place, $containerBuilder)))
|
||||
->isRequired()
|
||||
->end();
|
||||
|
||||
// adding the possible config on each widget under the widget_alias
|
||||
foreach ($this->filterWidgetByPlace($place) as $factory) {
|
||||
$builder = new TreeBuilder($factory->getWidgetAlias());
|
||||
$widgetOptionsRoot = $builder->getRootNode($factory->getWidgetAlias());
|
||||
$widgetOptionsRoot->canBeUnset()
|
||||
->info(sprintf('the configuration for the widget "%s" (only required if this widget is set in widget_alias)',
|
||||
$factory->getWidgetAlias()));
|
||||
->info(sprintf(
|
||||
'the configuration for the widget "%s" (only required if this widget is set in widget_alias)',
|
||||
$factory->getWidgetAlias()
|
||||
));
|
||||
$factory->configureOptions($place, $widgetOptionsRoot->children());
|
||||
$prototypeChildren->append($widgetOptionsRoot);
|
||||
}
|
||||
|
||||
|
||||
return $root;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get all widget factories for the given place.
|
||||
*
|
||||
* @param string $place
|
||||
* @return \Generator a generator containing a widget factory
|
||||
*
|
||||
* @return Generator a generator containing a widget factory
|
||||
*/
|
||||
protected function filterWidgetByPlace($place)
|
||||
{
|
||||
foreach($this->widgetFactories as $factory) {
|
||||
foreach ($this->widgetFactories as $factory) {
|
||||
if (in_array($place, $factory->getAllowedPlaces())) {
|
||||
yield $factory;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* get the all possible aliases for the given place. This method
|
||||
* search within service tags and widget factories
|
||||
*
|
||||
* **Note** that services are not available when the config is build: the whole
|
||||
* search within service tags and widget factories.
|
||||
*
|
||||
* **Note** that services are not available when the config is build: the whole
|
||||
* aliases will be checked in compiler pass, or when the command
|
||||
* `config:dump-reference` is runned.
|
||||
*
|
||||
*
|
||||
* @param type $place
|
||||
* @param ContainerBuilder $containerBuilder
|
||||
* @return type
|
||||
*
|
||||
* @throws InvalidConfigurationException if a service's tag does not have the "alias" key
|
||||
*
|
||||
* @return type
|
||||
*/
|
||||
protected function getWidgetAliasesbyPlace($place, ContainerBuilder $containerBuilder)
|
||||
{
|
||||
$result = array();
|
||||
|
||||
$result = [];
|
||||
|
||||
foreach ($this->filterWidgetByPlace($place) as $factory) {
|
||||
$result[] = $factory->getWidgetAlias();
|
||||
}
|
||||
|
||||
// append the aliases added without factory
|
||||
foreach ($containerBuilder
|
||||
->findTaggedServiceIds(WidgetsCompilerPass::WIDGET_SERVICE_TAG_NAME)
|
||||
->findTaggedServiceIds(WidgetsCompilerPass::WIDGET_SERVICE_TAG_NAME)
|
||||
as $serviceId => $tags) {
|
||||
foreach ($tags as $tag) {
|
||||
// throw an error if no alias in definition
|
||||
if (!array_key_exists(WidgetsCompilerPass::WIDGET_SERVICE_TAG_ALIAS, $tag)) {
|
||||
throw new InvalidConfigurationException(sprintf(
|
||||
"The service with id %s does not have any %d key",
|
||||
$serviceId,
|
||||
WidgetsCompilerPass::WIDGET_SERVICE_TAG_ALIAS
|
||||
));
|
||||
}
|
||||
// add the key to the possible results
|
||||
$result[] = $tag[WidgetsCompilerPass::WIDGET_SERVICE_TAG_ALIAS];
|
||||
foreach ($tags as $tag) {
|
||||
// throw an error if no alias in definition
|
||||
if (!array_key_exists(WidgetsCompilerPass::WIDGET_SERVICE_TAG_ALIAS, $tag)) {
|
||||
throw new InvalidConfigurationException(sprintf(
|
||||
'The service with id %s does not have any %d key',
|
||||
$serviceId,
|
||||
WidgetsCompilerPass::WIDGET_SERVICE_TAG_ALIAS
|
||||
));
|
||||
}
|
||||
// add the key to the possible results
|
||||
$result[] = $tag[WidgetsCompilerPass::WIDGET_SERVICE_TAG_ALIAS];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,47 +1,32 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2016 Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\DependencyInjection\Widget\Factory;
|
||||
|
||||
use Chill\MainBundle\DependencyInjection\Widget\Factory\WidgetFactoryInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
/**
|
||||
* Allow to easily create WidgetFactory.
|
||||
*
|
||||
* Allow to easily create WidgetFactory.
|
||||
*
|
||||
* Extending this factory, the widget will be created using the already defined
|
||||
* service created "as other services" in your configuration (the most frequent
|
||||
* way is using `services.yml` file.
|
||||
*
|
||||
* If you need to create different service based upon place, position or
|
||||
*
|
||||
* If you need to create different service based upon place, position or
|
||||
* definition, you should implements directly
|
||||
* `Chill\MainBundle\DependencyInjection\Widget\Factory\WidgetFactoryInterface`
|
||||
*
|
||||
*
|
||||
*/
|
||||
abstract class AbstractWidgetFactory implements WidgetFactoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* {@inheritdoc}
|
||||
*
|
||||
*
|
||||
* Will create the definition by returning the definition from the `services.yml`
|
||||
* file (or `services.xml` or `what-you-want.yml`).
|
||||
*
|
||||
@@ -49,9 +34,9 @@ abstract class AbstractWidgetFactory implements WidgetFactoryInterface
|
||||
*/
|
||||
public function createDefinition(ContainerBuilder $containerBuilder, $place, $order, array $config)
|
||||
{
|
||||
return $containerBuilder->getDefinition($this
|
||||
->getServiceId($containerBuilder, $place, $order, $config)
|
||||
);
|
||||
return $containerBuilder->getDefinition(
|
||||
$this
|
||||
->getServiceId($containerBuilder, $place, $order, $config)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1,52 +1,41 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2016 Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\DependencyInjection\Widget\Factory;
|
||||
|
||||
|
||||
use Symfony\Component\Config\Definition\Builder\NodeBuilder;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
/**
|
||||
* Factory for creating configuration of widgets.
|
||||
*
|
||||
*
|
||||
* When you need a widget with some configuration, you should implements this
|
||||
* interface on a factory. The factory will add configuration to the bundle
|
||||
* interface on a factory. The factory will add configuration to the bundle
|
||||
* giving the places for your widget.
|
||||
*
|
||||
* Using this interface, **you do not need** to define the service in your
|
||||
* container configuration (`services.yml` files).
|
||||
*
|
||||
*
|
||||
* Using this interface, **you do not need** to define the service in your
|
||||
* container configuration (`services.yml` files).
|
||||
*
|
||||
* Once the class is created, you should inject the factory inside the container
|
||||
* at compile time, in your `Bundle` class :
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* ```
|
||||
* namespace Chill\PersonBundle;
|
||||
*
|
||||
* use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
* use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
* use Chill\PersonBundle\Widget\PersonListWidgetFactory;
|
||||
*
|
||||
*
|
||||
* class ChillPersonBundle extends Bundle
|
||||
* {
|
||||
* public function build(ContainerBuilder $container)
|
||||
* public function build(ContainerBuilder $container)
|
||||
* {
|
||||
* parent::build($container);
|
||||
* // register a widget factory into chill_main :
|
||||
@@ -55,49 +44,40 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
interface WidgetFactoryInterface
|
||||
{
|
||||
/**
|
||||
* configure options for the widget. Those options will be added in
|
||||
* configure options for the widget. Those options will be added in
|
||||
* configuration in the bundle where the widget will be used.
|
||||
*
|
||||
*
|
||||
* @param type $place
|
||||
* @param NodeBuilder $node
|
||||
*/
|
||||
public function configureOptions($place, NodeBuilder $node);
|
||||
|
||||
/**
|
||||
* get the widget alias. This alias will be used in configuration (`config.yml`)
|
||||
*/
|
||||
public function getWidgetAlias();
|
||||
|
||||
|
||||
/**
|
||||
* Create a definition for the service which will render the widget.
|
||||
*
|
||||
* (Note: you can define the service by yourself, as other services,
|
||||
*
|
||||
* (Note: you can define the service by yourself, as other services,
|
||||
* using the `AbstractWidgetFactory`)
|
||||
*
|
||||
* @param ContainerBuilder $containerBuilder
|
||||
*
|
||||
* @param type $place
|
||||
* @param type $order
|
||||
* @param array $config
|
||||
*/
|
||||
public function createDefinition(ContainerBuilder $containerBuilder, $place, $order, array $config);
|
||||
|
||||
|
||||
/**
|
||||
* return the service id to build the widget.
|
||||
*
|
||||
* @param ContainerBuilder $containerBuilder
|
||||
*
|
||||
* @param string $place
|
||||
* @param float $order
|
||||
* @param array $config
|
||||
*
|
||||
*
|
||||
* @return string the service definition
|
||||
*
|
||||
*/
|
||||
public function getServiceId(ContainerBuilder $containerBuilder, $place, $order, array $config);
|
||||
|
||||
/**
|
||||
* get the widget alias. This alias will be used in configuration (`config.yml`).
|
||||
*/
|
||||
public function getWidgetAlias();
|
||||
}
|
||||
|
@@ -1,20 +1,10 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2016 Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\DependencyInjection\Widget;
|
||||
@@ -23,20 +13,19 @@ use Chill\MainBundle\DependencyInjection\Widget\Factory\WidgetFactoryInterface;
|
||||
|
||||
/**
|
||||
* Register widget factories to an extension.
|
||||
*
|
||||
*/
|
||||
interface HasWidgetFactoriesExtensionInterface {
|
||||
|
||||
interface HasWidgetFactoriesExtensionInterface
|
||||
{
|
||||
/**
|
||||
* register a widget factory
|
||||
*
|
||||
* register a widget factory.
|
||||
*
|
||||
* @param \Chill\MainBundle\DependencyInjection\Widget\WidgetFactoryInterface $factory
|
||||
*/
|
||||
public function addWidgetFactory(WidgetFactoryInterface $factory);
|
||||
|
||||
|
||||
/**
|
||||
* get all the widget factories registered for this extension
|
||||
*
|
||||
* get all the widget factories registered for this extension.
|
||||
*
|
||||
* @return WidgetFactoryInterface[]
|
||||
*/
|
||||
public function getWidgetFactories();
|
||||
|
Reference in New Issue
Block a user