|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Routes. |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Zikula contributors (Zikula) |
|
6
|
|
|
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License |
|
7
|
|
|
* @author Zikula contributors <[email protected]>. |
|
8
|
|
|
* @link http://www.zikula.org |
|
9
|
|
|
* @link http://zikula.org |
|
10
|
|
|
* @version Generated by ModuleStudio 0.7.4 (http://modulestudio.de). |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Zikula\RoutesModule\Entity\Factory\Base; |
|
14
|
|
|
|
|
15
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
|
16
|
|
|
use Doctrine\ORM\EntityRepository; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Factory class used to create entities and receive entity repositories. |
|
20
|
|
|
* |
|
21
|
|
|
* This is the base factory class. |
|
22
|
|
|
*/ |
|
23
|
|
|
abstract class AbstractRoutesFactory |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var ObjectManager The object manager to be used for determining the repository |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $objectManager; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* RoutesFactory constructor. |
|
32
|
|
|
* |
|
33
|
|
|
* @param ObjectManager $objectManager The object manager to be used for determining the repositories |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct(ObjectManager $objectManager) |
|
36
|
|
|
{ |
|
37
|
|
|
$this->objectManager = $objectManager; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Returns a repository for a given object type. |
|
42
|
|
|
* |
|
43
|
|
|
* @param string $objectType Name of desired entity type |
|
44
|
|
|
* |
|
45
|
|
|
* @return EntityRepository The repository responsible for the given object type |
|
46
|
|
|
*/ |
|
47
|
|
|
public function getRepository($objectType) |
|
48
|
|
|
{ |
|
49
|
|
|
$entityClass = 'Zikula\\RoutesModule\\Entity\\' . ucfirst($objectType) . 'Entity'; |
|
50
|
|
|
|
|
51
|
|
|
return $this->objectManager->getRepository($entityClass); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Creates a new route instance. |
|
56
|
|
|
* |
|
57
|
|
|
* @return Zikula\RoutesModule\Entity\routeEntity The newly created entity instance |
|
58
|
|
|
*/ |
|
59
|
|
|
public function createRoute() |
|
60
|
|
|
{ |
|
61
|
|
|
$entityClass = 'Zikula\\RoutesModule\\Entity\\RouteEntity'; |
|
62
|
|
|
|
|
63
|
|
|
return new $entityClass(); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Gets the list of identifier fields for a given object type. |
|
68
|
|
|
* |
|
69
|
|
|
* @param string $objectType The object type to be treated |
|
70
|
|
|
* |
|
71
|
|
|
* @return array List of identifier field names |
|
72
|
|
|
*/ |
|
73
|
|
View Code Duplication |
public function getIdFields($objectType = '') |
|
|
|
|
|
|
74
|
|
|
{ |
|
75
|
|
|
if (empty($objectType)) { |
|
76
|
|
|
throw new InvalidArgumentException('Invalid object type received.'); |
|
77
|
|
|
} |
|
78
|
|
|
$entityClass = 'ZikulaRoutesModule:' . ucfirst($objectType) . 'Entity'; |
|
79
|
|
|
|
|
80
|
|
|
$meta = $this->entityFactory->getObjectManager()->getClassMetadata($entityClass); |
|
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
if ($this->hasCompositeKeys($objectType)) { |
|
83
|
|
|
$idFields = $meta->getIdentifierFieldNames(); |
|
84
|
|
|
} else { |
|
85
|
|
|
$idFields = [$meta->getSingleIdentifierFieldName()]; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
return $idFields; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Checks whether a certain entity type uses composite keys or not. |
|
93
|
|
|
* |
|
94
|
|
|
* @param string $objectType The object type to retrieve |
|
95
|
|
|
* |
|
96
|
|
|
* @return Boolean Whether composite keys are used or not |
|
97
|
|
|
*/ |
|
98
|
|
|
public function hasCompositeKeys($objectType) |
|
|
|
|
|
|
99
|
|
|
{ |
|
100
|
|
|
return false; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Returns the object manager. |
|
105
|
|
|
* |
|
106
|
|
|
* @return ObjectManager |
|
107
|
|
|
*/ |
|
108
|
|
|
public function getObjectManager() |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->objectManager; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Sets the object manager. |
|
115
|
|
|
* |
|
116
|
|
|
* @param ObjectManager $objectManager |
|
117
|
|
|
* |
|
118
|
|
|
* @return void |
|
119
|
|
|
*/ |
|
120
|
|
|
public function setObjectManager($objectManager) |
|
121
|
|
|
{ |
|
122
|
|
|
$this->objectManager = $objectManager; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
} |
|
126
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.