mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 22:53:49 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,35 +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\ThirdPartyBundle\DependencyInjection;
|
||||
|
||||
use Chill\ThirdPartyBundle\Controller\ThirdPartyController;
|
||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||
use Chill\ThirdPartyBundle\Form\ThirdPartyType;
|
||||
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\ThirdPartyBundle\Security\Voter\ThirdPartyVoter;
|
||||
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;
|
||||
|
||||
/**
|
||||
* This is the class that loads and manages your bundle configuration.
|
||||
*
|
||||
* @link http://symfony.com/doc/current/cookbook/bundles/extension.html
|
||||
* @see http://symfony.com/doc/current/cookbook/bundles/extension.html
|
||||
*/
|
||||
class ChillThirdPartyExtension extends Extension implements PrependExtensionInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
$configuration = new Configuration();
|
||||
$config = $this->processConfiguration($configuration, $configs);
|
||||
|
||||
$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/controller.yaml');
|
||||
$loader->load('services/form.yaml');
|
||||
@@ -49,15 +52,25 @@ class ChillThirdPartyExtension extends Extension implements PrependExtensionInte
|
||||
$this->prependRoleHierarchy($container);
|
||||
}
|
||||
|
||||
protected function prependRoleHierarchy(ContainerBuilder $container)
|
||||
{
|
||||
$container->prependExtensionConfig('security', [
|
||||
'role_hierarchy' => [
|
||||
ThirdPartyVoter::CREATE => [ThirdPartyVoter::SHOW],
|
||||
ThirdPartyVoter::UPDATE => [ThirdPartyVoter::SHOW],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
protected function preprendRoutes(ContainerBuilder $container)
|
||||
{
|
||||
//declare routes for 3party bundle
|
||||
$container->prependExtensionConfig('chill_main', array(
|
||||
'routing' => [
|
||||
'resources' => array(
|
||||
'@ChillThirdPartyBundle/config/routes.yaml'
|
||||
)
|
||||
],
|
||||
$container->prependExtensionConfig('chill_main', [
|
||||
'routing' => [
|
||||
'resources' => [
|
||||
'@ChillThirdPartyBundle/config/routes.yaml',
|
||||
],
|
||||
],
|
||||
'cruds' => [
|
||||
[
|
||||
'class' => ThirdParty::class,
|
||||
@@ -81,10 +94,9 @@ class ChillThirdPartyExtension extends Extension implements PrependExtensionInte
|
||||
'view' => [
|
||||
'template' => '@ChillThirdParty/ThirdParty/view.html.twig',
|
||||
'role' => ThirdPartyVoter::SHOW,
|
||||
]
|
||||
]
|
||||
|
||||
]
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
'apis' => [
|
||||
[
|
||||
@@ -100,29 +112,19 @@ class ChillThirdPartyExtension extends Extension implements PrependExtensionInte
|
||||
Request::METHOD_HEAD => true,
|
||||
Request::METHOD_POST => true,
|
||||
Request::METHOD_PUT => true,
|
||||
Request::METHOD_PATCH => true
|
||||
Request::METHOD_PATCH => true,
|
||||
],
|
||||
'roles' => [
|
||||
Request::METHOD_GET => \Chill\ThirdPartyBundle\Security\Voter\ThirdPartyVoter::SHOW,
|
||||
Request::METHOD_HEAD => \Chill\ThirdPartyBundle\Security\Voter\ThirdPartyVoter::SHOW,
|
||||
Request::METHOD_POST => \Chill\ThirdPartyBundle\Security\Voter\ThirdPartyVoter::CREATE,
|
||||
Request::METHOD_PUT => \Chill\ThirdPartyBundle\Security\Voter\ThirdPartyVoter::CREATE,
|
||||
Request::METHOD_PATCH => \Chill\ThirdPartyBundle\Security\Voter\ThirdPartyVoter::CREATE
|
||||
Request::METHOD_PATCH => \Chill\ThirdPartyBundle\Security\Voter\ThirdPartyVoter::CREATE,
|
||||
],
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
));
|
||||
}
|
||||
|
||||
protected function prependRoleHierarchy(ContainerBuilder $container)
|
||||
{
|
||||
$container->prependExtensionConfig('security', array(
|
||||
'role_hierarchy' => array(
|
||||
ThirdPartyVoter::CREATE => [ThirdPartyVoter::SHOW],
|
||||
ThirdPartyVoter::UPDATE => [ThirdPartyVoter::SHOW],
|
||||
)
|
||||
));
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@@ -1,38 +1,48 @@
|
||||
<?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\ThirdPartyBundle\DependencyInjection\CompilerPass;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Chill\ThirdPartyBundle\ThirdPartyType\ThirdPartyTypeManager;
|
||||
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
|
||||
use LogicException;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use function in_array;
|
||||
|
||||
/**
|
||||
* Load services tagged chill_3party.provider and add them to the service
|
||||
* definition of manager
|
||||
*
|
||||
* Load services tagged chill_3party.provider and add them to the service
|
||||
* definition of manager.
|
||||
*/
|
||||
class ThirdPartyTypeCompilerPass implements CompilerPassInterface
|
||||
{
|
||||
const TAG = 'chill_3party.provider';
|
||||
|
||||
public const TAG = 'chill_3party.provider';
|
||||
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
$definition = $container->getDefinition(ThirdPartyTypeManager::class);
|
||||
$usedKeys = [];
|
||||
|
||||
|
||||
foreach ($container->findTaggedServiceIds(self::TAG) as $id => $tags) {
|
||||
$taggedService = $container->getDefinition($id);
|
||||
// check forr keys already in use :
|
||||
$key = $taggedService->getClass()::getKey();
|
||||
if (\in_array($key, $usedKeys)) {
|
||||
throw new \LogicException(sprintf("Tag with key \"%s\" is already in used",
|
||||
$key));
|
||||
|
||||
if (in_array($key, $usedKeys)) {
|
||||
throw new LogicException(sprintf(
|
||||
'Tag with key "%s" is already in used',
|
||||
$key
|
||||
));
|
||||
}
|
||||
$usedKeys[] = $key;
|
||||
// alter the service definition of manager
|
||||
$definition->addMethodCall('addProvider', [ new Reference($id) ]);
|
||||
$definition->addMethodCall('addProvider', [new Reference($id)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,12 @@
|
||||
<?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\ThirdPartyBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
|
||||
@@ -12,9 +19,6 @@ use Symfony\Component\Config\Definition\ConfigurationInterface;
|
||||
*/
|
||||
class Configuration implements ConfigurationInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfigTreeBuilder()
|
||||
{
|
||||
$treeBuilder = new TreeBuilder('chill_third_party');
|
||||
|
Reference in New Issue
Block a user