mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
make timeline & paginator service private
This commit is contained in:
parent
930ab84a58
commit
e05031a743
@ -6,7 +6,7 @@ use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Chill\MainBundle\DependencyInjection\SearchableServicesCompilerPass;
|
||||
use Chill\MainBundle\DependencyInjection\ConfigConsistencyCompilerPass;
|
||||
use Chill\MainBundle\DependencyInjection\TimelineCompilerClass;
|
||||
use Chill\MainBundle\DependencyInjection\CompilerPass\TimelineCompilerClass;
|
||||
use Chill\MainBundle\DependencyInjection\RoleProvidersCompilerPass;
|
||||
use Chill\MainBundle\DependencyInjection\CompilerPass\ExportsCompilerPass;
|
||||
use Chill\MainBundle\DependencyInjection\CompilerPass\WidgetsCompilerPass;
|
||||
|
@ -120,6 +120,7 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
||||
$loader->load('services/phonenumber.yml');
|
||||
$loader->load('services/cache.yml');
|
||||
$loader->load('services/templating.yml');
|
||||
$loader->load('services/timeline.yml');
|
||||
|
||||
$this->configureCruds($container, $config['cruds'], $loader);
|
||||
}
|
||||
|
@ -17,28 +17,28 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\DependencyInjection;
|
||||
namespace Chill\MainBundle\DependencyInjection\CompilerPass;
|
||||
|
||||
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
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class TimelineCompilerClass implements CompilerPassInterface
|
||||
{
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->hasDefinition('chill.main.timeline_builder')) {
|
||||
throw new \LogicException('service chill.main.timeline_builder '
|
||||
if (!$container->hasDefinition('chill_main.timeline_builder')) {
|
||||
throw new \LogicException('service chill_main.timeline_builder '
|
||||
. 'is not defined.');
|
||||
}
|
||||
|
||||
$definition = $container->getDefinition(
|
||||
'chill.main.timeline_builder'
|
||||
'chill_main.timeline_builder'
|
||||
);
|
||||
|
||||
$taggedServices = $container->findTaggedServiceIds(
|
||||
@ -56,7 +56,7 @@ class TimelineCompilerClass implements CompilerPassInterface
|
||||
|
||||
$definition->addMethodCall(
|
||||
'addProvider',
|
||||
array($attributes["context"], $id)
|
||||
array($attributes["context"], $id, new Reference($id))
|
||||
);
|
||||
}
|
||||
}
|
@ -40,14 +40,6 @@ services:
|
||||
chill.main.search_provider:
|
||||
class: Chill\MainBundle\Search\SearchProvider
|
||||
public: true
|
||||
|
||||
chill.main.timeline_builder:
|
||||
class: Chill\MainBundle\Timeline\TimelineBuilder
|
||||
arguments:
|
||||
- "@doctrine.orm.entity_manager"
|
||||
public: true
|
||||
calls:
|
||||
- [ setContainer, ["@service_container"]]
|
||||
|
||||
chill.main.validator.role_scope_scope_presence:
|
||||
class: Chill\MainBundle\Validation\Validator\RoleScopeScopePresence
|
||||
|
@ -1,7 +1,6 @@
|
||||
services:
|
||||
chill_main.paginator_factory:
|
||||
class: Chill\MainBundle\Pagination\PaginatorFactory
|
||||
public: true # TODO sf4 check if service is public or if container is must be loaded via __constuct
|
||||
arguments:
|
||||
- "@request_stack"
|
||||
- "@router"
|
||||
|
7
Resources/config/services/timeline.yml
Normal file
7
Resources/config/services/timeline.yml
Normal file
@ -0,0 +1,7 @@
|
||||
services:
|
||||
chill_main.timeline_builder:
|
||||
class: Chill\MainBundle\Timeline\TimelineBuilder
|
||||
arguments:
|
||||
- "@doctrine.orm.entity_manager"
|
||||
calls:
|
||||
- [ setContainer, ["@service_container"]]
|
@ -40,17 +40,29 @@ class TimelineBuilder implements ContainerAwareInterface
|
||||
*/
|
||||
private $em;
|
||||
|
||||
/**
|
||||
* Record provider
|
||||
*
|
||||
* This array has the structure `[ 'service id' => $service ]`
|
||||
*
|
||||
* @var TimelineProviderInterface[]
|
||||
*/
|
||||
private $providers = [];
|
||||
|
||||
/**
|
||||
* Record provider and their context
|
||||
*
|
||||
* This array has the structure `[ 'context' => [ 'service id' ] ]`
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $providersByContext = [];
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string references to providers services
|
||||
*/
|
||||
private $providers = array();
|
||||
|
||||
/**
|
||||
* return an HTML string with timeline
|
||||
*
|
||||
@ -108,9 +120,10 @@ class TimelineBuilder implements ContainerAwareInterface
|
||||
* @param string $context the context of the service
|
||||
* @param string $id the
|
||||
*/
|
||||
public function addProvider($context, $id)
|
||||
public function addProvider($context, $id, TimelineProviderInterface $provider)
|
||||
{
|
||||
$this->providers[$context][] = $id;
|
||||
$this->providersByContext[$context][] = $id;
|
||||
$this->providers[$id] = $provider;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -121,10 +134,16 @@ class TimelineBuilder implements ContainerAwareInterface
|
||||
*/
|
||||
public function getProvidersByContext($context)
|
||||
{
|
||||
$providers = array();
|
||||
//throw an exception if no provider have been defined for this context
|
||||
if (!array_key_exists($context, $this->providersByContext)) {
|
||||
throw new \LogicException(sprintf('No builders have been defined for "%s"'
|
||||
. ' context', $context));
|
||||
}
|
||||
|
||||
$providers = [];
|
||||
|
||||
foreach($this->providers[$context] as $providerId) {
|
||||
$providers[] = $this->container->get($providerId);
|
||||
foreach($this->providersByContext[$context] as $providerId) {
|
||||
$providers[] = $this->providers[$providerId];
|
||||
}
|
||||
|
||||
return $providers;
|
||||
@ -144,12 +163,6 @@ class TimelineBuilder implements ContainerAwareInterface
|
||||
*/
|
||||
private function buildUnionQuery($context, array $args)
|
||||
{
|
||||
//throw an exception if no provider have been defined for this context
|
||||
if (!array_key_exists($context, $this->providers)) {
|
||||
throw new \LogicException(sprintf('No builders have been defined for "%s"'
|
||||
. ' context', $context));
|
||||
}
|
||||
|
||||
//append SELECT queries with UNION keyword between them
|
||||
$union = '';
|
||||
foreach($this->getProvidersByContext($context) as $provider) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user