/**
* Constructor
*
* @param AbstractEntity $entity An entity
*/
public function __construct(AbstractEntity $entity)
{
$this->position = 0;
$this->entity = $entity;
$this->refl = $entity->_getReflectionClass();
$this->refProps = new ArrayObject(array());
$this->primaryKey = array();
$entityAnnotation = $entity->getEntityAnnotation();
$fieldsIterator = array();
$pos = 0;
$properties = $this->refl->getProperties(ReflectionProperty::IS_PROTECTED | ReflectionProperty::IS_PUBLIC);
$staticProperties = $this->refl->getProperties(ReflectionProperty::IS_STATIC);
foreach (array_diff($properties, $staticProperties) as $refProp) {
/* @var $refProp \ReflectionProperty */
/* @var $field \Scalr\Model\Loader\Field */
if (substr($refProp->name, 0, 1) != '_') {
if (!isset(self::$cache[$this->refl->name][$refProp->name])) {
//executes only once
$loader = \Scalr::getContainer()->get('model.loader');
$loader->load($refProp);
$field = $refProp->annotation;
$field->setEntityAnnotation($entityAnnotation);
$typeClass = __NAMESPACE__ . '\\Type\\' . ucfirst($field->column->type) . 'Type';
$refProp->annotation->setType(new $typeClass($field));
self::$cache[$refProp->class][$refProp->name] = $field;
unset($field);
}
$refProp->annotation = self::$cache[$refProp->class][$refProp->name];
$fieldsIterator[$refProp->annotation->name] = $refProp->annotation;
if (isset($refProp->annotation->id)) {
$this->primaryKey[] = $refProp->name;
}
if (isset($refProp->annotation->generatedValue->strategy) && $refProp->annotation->generatedValue->strategy == GeneratedValue::STRATEGY_AUTO) {
$this->autogenerated = $refProp->annotation;
}
$this->refProps->append($refProp);
$this->propertyPositions[$refProp->name] = $pos++;
}
}
$this->_fieldsIterator = new ArrayIterator($fieldsIterator);
}