TYPO3 CMS  TYPO3_8-7
ClassSchema.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
18 
25 {
29  const MODELTYPE_ENTITY = 1;
31 
37  protected $className;
38 
44  protected $modelType = self::MODELTYPE_ENTITY;
45 
51  protected $aggregateRoot = false;
52 
58  protected $uuidPropertyName;
59 
65  protected $properties = [];
66 
72  protected $identityProperties = [];
73 
79  public function __construct($className)
80  {
81  $this->className = $className;
82  }
83 
89  public function getClassName()
90  {
91  return $this->className;
92  }
93 
102  public function addProperty($name, $type, $lazy = false, $cascade = '')
103  {
104  $type = TypeHandlingUtility::parseType($type);
105  $this->properties[$name] = [
106  'type' => $type['type'],
107  'elementType' => $type['elementType'],
108  'lazy' => $lazy,
109  'cascade' => $cascade
110  ];
111  }
112 
120  public function getProperty($propertyName)
121  {
122  return is_array($this->properties[$propertyName]) ? $this->properties[$propertyName] : [];
123  }
124 
130  public function getProperties()
131  {
132  return $this->properties;
133  }
134 
141  public function setModelType($modelType)
142  {
143  if ($modelType < self::MODELTYPE_ENTITY || $modelType > self::MODELTYPE_VALUEOBJECT) {
144  throw new \InvalidArgumentException('"' . $modelType . '" is an invalid model type.', 1212519195);
145  }
146  $this->modelType = $modelType;
147  }
148 
154  public function getModelType()
155  {
156  return $this->modelType;
157  }
158 
165  public function setAggregateRoot($isRoot)
166  {
167  $this->aggregateRoot = $isRoot;
168  }
169 
176  public function isAggregateRoot()
177  {
178  return $this->aggregateRoot;
179  }
180 
187  public function hasProperty($propertyName)
188  {
189  return array_key_exists($propertyName, $this->properties);
190  }
191 
198  public function setUuidPropertyName($propertyName)
199  {
200  if (!array_key_exists($propertyName, $this->properties)) {
201  throw new \InvalidArgumentException('Property "' . $propertyName . '" must be added to the class schema before it can be marked as UUID property.', 1233863842);
202  }
203  $this->uuidPropertyName = $propertyName;
204  }
205 
211  public function getUuidPropertyName()
212  {
214  }
215 
224  public function markAsIdentityProperty($propertyName)
225  {
226  if (!array_key_exists($propertyName, $this->properties)) {
227  throw new \InvalidArgumentException('Property "' . $propertyName . '" must be added to the class schema before it can be marked as identity property.', 1233775407);
228  }
229  if ($this->properties[$propertyName]['lazy'] === true) {
230  throw new \InvalidArgumentException('Property "' . $propertyName . '" must not be makred for lazy loading to be marked as identity property.', 1239896904);
231  }
232  $this->identityProperties[$propertyName] = $this->properties[$propertyName]['type'];
233  }
234 
241  public function getIdentityProperties()
242  {
244  }
245 }
addProperty($name, $type, $lazy=false, $cascade='')