Skip to content
This repository was archived by the owner on Oct 22, 2024. It is now read-only.

Commit 2b91b4f

Browse files
author
Vincent Chalnot
committed
Moving CleverAge\EAVManager\ProcessBundle to a dedicated CleverAge\EAVProcessBundle
0 parents  commit 2b91b4f

17 files changed

+1201
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/composer.lock
2+
/vendor

CleverAgeEAVProcessBundle.php

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/*
3+
* This file is part of the CleverAge/EAVProcessBundle package.
4+
*
5+
* Copyright (c) 2015-2019 Clever-Age
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace CleverAge\EAVProcessBundle;
12+
13+
use Symfony\Component\HttpKernel\Bundle\Bundle;
14+
15+
/**
16+
* Adds new features over the base process-bundle
17+
*
18+
* @author Vincent Chalnot <[email protected]>
19+
*/
20+
class CleverAgeEAVProcessBundle extends Bundle
21+
{
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/*
3+
* This file is part of the CleverAge/EAVProcessBundle package.
4+
*
5+
* Copyright (c) 2015-2019 Clever-Age
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace CleverAge\EAVProcessBundle\DependencyInjection;
12+
13+
use Sidus\BaseBundle\DependencyInjection\SidusBaseExtension;
14+
15+
/**
16+
* This is the class that loads and manages your bundle configuration.
17+
*
18+
* @link http://symfony.com/doc/current/cookbook/bundles/extension.html
19+
*
20+
* @author Vincent Chalnot <[email protected]>
21+
*/
22+
class CleverAgeEAVProcessExtension extends SidusBaseExtension
23+
{
24+
}

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2015-2019 Clever-Age
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CleverAge/EAVProcessBundle
2+
=======================

Resources/config/services/task.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
services:
2+
CleverAge\EAVProcessBundle\Task\:
3+
resource: '../../../Task/*'
4+
autowire: true
5+
public: true
6+
shared: false
7+
tags:
8+
- { name: monolog.logger, channel: cleverage_process_task }
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
services:
2+
CleverAge\EAVProcessBundle\Transformer\:
3+
resource: '../../../Transformer/*'
4+
autowire: true
5+
public: true # Set to false
6+
tags:
7+
- { name: cleverage.transformer }
8+
9+
CleverAge\EAVProcessBundle\Transformer\ResourceToAssetTransformer:
10+
autowire: true
11+
public: true
12+
calls:
13+
- [setFamilyMap, ['%eavmanager.asset.family_map%']]
14+
tags:
15+
- { name: cleverage.transformer }

Task/AbstractEAVQueryTask.php

+147
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
<?php
2+
/*
3+
* This file is part of the CleverAge/EAVProcessBundle package.
4+
*
5+
* Copyright (c) 2015-2019 Clever-Age
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace CleverAge\EAVProcessBundle\Task;
12+
13+
use CleverAge\EAVManager\EAVModelBundle\Entity\DataRepository;
14+
use CleverAge\ProcessBundle\Model\ProcessState;
15+
use Doctrine\ORM\EntityManagerInterface;
16+
use Doctrine\ORM\QueryBuilder;
17+
use Doctrine\ORM\Tools\Pagination\Paginator;
18+
use Sidus\EAVModelBundle\Doctrine\EAVFinder;
19+
use Sidus\EAVModelBundle\Exception\MissingAttributeException;
20+
use Sidus\EAVModelBundle\Model\FamilyInterface;
21+
use Sidus\EAVModelBundle\Registry\FamilyRegistry;
22+
use Symfony\Component\OptionsResolver\Exception\ExceptionInterface;
23+
use Symfony\Component\OptionsResolver\Options;
24+
use Symfony\Component\OptionsResolver\OptionsResolver;
25+
26+
/**
27+
* Handles EAV Data pagination
28+
*/
29+
abstract class AbstractEAVQueryTask extends AbstractEAVTask
30+
{
31+
/** @var EAVFinder */
32+
protected $eavFinder;
33+
34+
/**
35+
* @param EntityManagerInterface $entityManager
36+
* @param FamilyRegistry $familyRegistry
37+
* @param EAVFinder $eavFinder
38+
*/
39+
public function __construct(
40+
EntityManagerInterface $entityManager,
41+
FamilyRegistry $familyRegistry,
42+
EAVFinder $eavFinder
43+
) {
44+
parent::__construct($entityManager, $familyRegistry);
45+
$this->eavFinder = $eavFinder;
46+
}
47+
48+
/**
49+
* {@inheritDoc}
50+
*/
51+
protected function configureOptions(OptionsResolver $resolver): void
52+
{
53+
parent::configureOptions($resolver);
54+
55+
$resolver->setDefaults(
56+
[
57+
'criteria' => [],
58+
'extended_criteria' => [],
59+
'repository' => null,
60+
'order_by' => [],
61+
'limit' => null,
62+
'offset' => null,
63+
]
64+
);
65+
$resolver->setNormalizer(
66+
'repository',
67+
function (Options $options, $value) {
68+
if ($value instanceof DataRepository) {
69+
return $value;
70+
}
71+
/** @var FamilyInterface $family */
72+
$family = $options['family'];
73+
74+
return $this->entityManager->getRepository($family->getDataClass());
75+
}
76+
);
77+
78+
$resolver->setAllowedTypes('criteria', ['array']);
79+
$resolver->setAllowedTypes('extended_criteria', ['array']);
80+
$resolver->setAllowedTypes('repository', ['NULL', DataRepository::class]);
81+
$resolver->setAllowedTypes('order_by', ['array']);
82+
$resolver->setAllowedTypes('limit', ['NULL', 'integer']);
83+
$resolver->setAllowedTypes('offset', ['NULL', 'integer']);
84+
}
85+
86+
/**
87+
* @deprecated Use getPaginator instead because this method can't handle limit and offset properly
88+
*
89+
* @param ProcessState $state
90+
* @param string $alias
91+
*
92+
* @throws \InvalidArgumentException
93+
* @throws \UnexpectedValueException
94+
* @throws \LogicException
95+
* @throws MissingAttributeException
96+
* @throws ExceptionInterface
97+
*
98+
* @return QueryBuilder
99+
*/
100+
protected function getQueryBuilder(ProcessState $state, $alias = 'e'): QueryBuilder
101+
{
102+
$options = $this->getOptions($state);
103+
104+
$criteria = $options['extended_criteria'];
105+
foreach ($options['criteria'] as $key => $value) {
106+
$criteria[] = [
107+
$key,
108+
\is_array($value) ? 'in' : '=',
109+
$value,
110+
];
111+
}
112+
$qb = $this->eavFinder->getFilterByQb($options['family'], $criteria, $options['order_by'], $alias);
113+
114+
$qb->distinct();
115+
116+
return $qb;
117+
}
118+
119+
/**
120+
* If a limit or an offset is specified, we are forced to use a paginator to handle joins properly
121+
*
122+
* @param ProcessState $state
123+
* @param string $alias
124+
*
125+
* @throws \InvalidArgumentException
126+
* @throws \UnexpectedValueException
127+
* @throws MissingAttributeException
128+
* @throws \LogicException
129+
* @throws ExceptionInterface
130+
*
131+
* @return Paginator
132+
*/
133+
protected function getPaginator(ProcessState $state, $alias = 'e'): Paginator
134+
{
135+
$options = $this->getOptions($state);
136+
/** @noinspection PhpDeprecationInspection */
137+
$paginator = new Paginator($this->getQueryBuilder($state, $alias));
138+
if (null !== $options['limit']) {
139+
$paginator->getQuery()->setMaxResults($options['limit']);
140+
}
141+
if (null !== $options['offset']) {
142+
$paginator->getQuery()->setFirstResult($options['offset']);
143+
}
144+
145+
return $paginator;
146+
}
147+
}

Task/AbstractEAVTask.php

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/*
3+
* This file is part of the CleverAge/EAVProcessBundle package.
4+
*
5+
* Copyright (c) 2015-2019 Clever-Age
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace CleverAge\EAVProcessBundle\Task;
12+
13+
use CleverAge\ProcessBundle\Model\AbstractConfigurableTask;
14+
use Doctrine\ORM\EntityManagerInterface;
15+
use Sidus\EAVModelBundle\Exception\MissingFamilyException;
16+
use Sidus\EAVModelBundle\Model\FamilyInterface;
17+
use Sidus\EAVModelBundle\Registry\FamilyRegistry;
18+
use Symfony\Component\OptionsResolver\Options;
19+
use Symfony\Component\OptionsResolver\OptionsResolver;
20+
21+
/**
22+
* Handles EAV Data
23+
*/
24+
abstract class AbstractEAVTask extends AbstractConfigurableTask
25+
{
26+
/** @var EntityManagerInterface */
27+
protected $entityManager;
28+
29+
/** @var FamilyRegistry */
30+
protected $familyRegistry;
31+
32+
/**
33+
* @param EntityManagerInterface $entityManager
34+
* @param FamilyRegistry $familyRegistry
35+
*/
36+
public function __construct(
37+
EntityManagerInterface $entityManager,
38+
FamilyRegistry $familyRegistry
39+
) {
40+
$this->entityManager = $entityManager;
41+
$this->familyRegistry = $familyRegistry;
42+
}
43+
44+
/**
45+
* {@inheritDoc}
46+
* @throws MissingFamilyException
47+
*/
48+
protected function configureOptions(OptionsResolver $resolver): void
49+
{
50+
$resolver->setRequired(
51+
[
52+
'family',
53+
]
54+
);
55+
/** @noinspection PhpUnusedParameterInspection */
56+
$resolver->setNormalizer(
57+
'family',
58+
function (/** @noinspection PhpUnusedParameterInspection */
59+
Options $options,
60+
$value
61+
) {
62+
if ($value instanceof FamilyInterface) {
63+
return $value;
64+
}
65+
66+
return $this->familyRegistry->getFamily($value);
67+
}
68+
);
69+
$resolver->setAllowedTypes('family', ['string', FamilyInterface::class]);
70+
}
71+
}

Task/EAVCriteriaReaderTask.php

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
/*
3+
* This file is part of the CleverAge/EAVProcessBundle package.
4+
*
5+
* Copyright (c) 2015-2019 Clever-Age
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
namespace CleverAge\EAVProcessBundle\Task;
12+
13+
use CleverAge\ProcessBundle\Model\ProcessState;
14+
use Symfony\Component\OptionsResolver\Exception\ExceptionInterface;
15+
16+
/**
17+
* Use input as criteria to find EAV Data
18+
*/
19+
class EAVCriteriaReaderTask extends EAVReaderTask
20+
{
21+
/**
22+
* @param ProcessState $state
23+
*
24+
* @throws ExceptionInterface
25+
*
26+
* @return array
27+
*/
28+
protected function getOptions(ProcessState $state): array
29+
{
30+
$options = parent::getOptions($state);
31+
$options['criteria'] = $state->getInput();
32+
$options['allow_reset'] = true;
33+
34+
return $options;
35+
}
36+
}

0 commit comments

Comments
 (0)