TYPO3 CMS  TYPO3_7-6
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 
103  public function addProperty($name, $type, $lazy = false, $cascade = '')
104  {
105  $type = TypeHandlingUtility::parseType($type);
106  $this->properties[$name] = [
107  'type' => $type['type'],
108  'elementType' => $type['elementType'],
109  'lazy' => $lazy,
110  'cascade' => $cascade
111  ];
112  }
113 
121  public function getProperty($propertyName)
122  {
123  return is_array($this->properties[$propertyName]) ? $this->properties[$propertyName] : [];
124  }
125 
131  public function getProperties()
132  {
133  return $this->properties;
134  }
135 
143  public function setModelType($modelType)
144  {
145  if ($modelType < self::MODELTYPE_ENTITY || $modelType > self::MODELTYPE_VALUEOBJECT) {
146  throw new \InvalidArgumentException('"' . $modelType . '" is an invalid model type.', 1212519195);
147  }
148  $this->modelType = $modelType;
149  }
150 
156  public function getModelType()
157  {
158  return $this->modelType;
159  }
160 
168  public function setAggregateRoot($isRoot)
169  {
170  $this->aggregateRoot = $isRoot;
171  }
172 
179  public function isAggregateRoot()
180  {
181  return $this->aggregateRoot;
182  }
183 
190  public function hasProperty($propertyName)
191  {
192  return array_key_exists($propertyName, $this->properties);
193  }
194 
202  public function setUuidPropertyName($propertyName)
203  {
204  if (!array_key_exists($propertyName, $this->properties)) {
205  throw new \InvalidArgumentException('Property "' . $propertyName . '" must be added to the class schema before it can be marked as UUID property.', 1233863842);
206  }
207  $this->uuidPropertyName = $propertyName;
208  }
209 
215  public function getUuidPropertyName()
216  {
218  }
219 
229  public function markAsIdentityProperty($propertyName)
230  {
231  if (!array_key_exists($propertyName, $this->properties)) {
232  throw new \InvalidArgumentException('Property "' . $propertyName . '" must be added to the class schema before it can be marked as identity property.', 1233775407);
233  }
234  if ($this->properties[$propertyName]['lazy'] === true) {
235  throw new \InvalidArgumentException('Property "' . $propertyName . '" must not be makred for lazy loading to be marked as identity property.', 1239896904);
236  }
237  $this->identityProperties[$propertyName] = $this->properties[$propertyName]['type'];
238  }
239 
246  public function getIdentityProperties()
247  {
249  }
250 }
addProperty($name, $type, $lazy=false, $cascade='')