39 private $properties = [];
40 private $valueProperties = [];
42 private $changedAttributes = [];
43 private $originalData = [];
44 private $mapper =
null;
46 private static $nullMapper =
null;
64 $this->type = $oid->getType();
66 if ($oid->containsDummyIds()) {
75 $attributeDescriptions =
$this->
getMapper()->getAttributes();
76 foreach($attributeDescriptions
as $curAttributeDesc) {
77 $data[$curAttributeDesc->getName()] = $curAttributeDesc->getDefaultValue();
81 if ($initialData !=
null) {
82 $data = array_merge($data, $initialData);
86 foreach ($data
as $name => $value) {
89 $this->originalData = $data;
98 private function initializeMapper() {
101 if ($persistenceFacade->isKnownType(
$this->type)) {
102 $this->mapper = $persistenceFacade->getMapper(
$this->type);
106 if (
self::$nullMapper ==
null) {
107 self::$nullMapper =
new NullMapper();
109 $this->mapper =
self::$nullMapper;
124 if (
$this->mapper ==
null) {
125 $this->initializeMapper();
127 return $this->mapper;
154 $ids = $oid->
getId();
155 $pkNames =
$this->
getMapper()->getPkNames();
156 for ($i=
0, $count=
sizeof($pkNames); $i<$count; $i++) {
157 if ($triggerListeners) {
158 $this->
setValue($pkNames[$i], $ids[$i],
true);
177 $oldState =
$this->state;
187 $this->state = $state;
197 $this->state = $state;
199 if ($oldState !=
$this->state) {
208 public function delete() {
210 $this->
setState(
self::STATE_DELETED);
217 $class = get_class(
$this);
219 $copy->oid =
$this->oid;
220 $copy->type =
$this->type;
221 $copy->data =
$this->data;
222 $copy->properties =
$this->properties;
223 $copy->valueProperties =
$this->valueProperties;
224 $copy->state =
$this->state;
225 $copy->changedAttributes =
$this->changedAttributes;
226 $copy->originalData =
$this->originalData;
235 $pkNames =
$this->
getMapper()->getPkNames();
237 foreach($iter
as $valueName => $value) {
238 if (strlen($value) >
0 && ($copyPkValues || !in_array($valueName, $pkNames))) {
239 $object->
setValue($valueName, $value,
true);
249 foreach($iter
as $valueName => $value) {
250 if (!
$this->
hasValue($valueName) && strlen($value) >
0) {
260 $pkNames =
$this->
getMapper()->getPkNames();
262 for($iter->rewind(); $iter->valid(); $iter->next()) {
263 $valueName = $iter->key();
264 if (!in_array($valueName, $pkNames)) {
265 $curNode = $iter->currentNode();
266 $curNode->setValue($valueName,
null,
true);
275 $this->data =
$this->originalData;
276 $this->changedAttributes = [];
282 private function updateOID() {
285 $pkNames =
$this->
getMapper()->getPkNames();
286 foreach ($pkNames
as $pkName) {
344 if (
isset(
$this->data[$name])) {
345 return $this->data[$name];
353 public function setValue($name, $value, $forceSet=false, $trackChange=true) {
358 if ($forceSet || $oldValue !== $value) {
360 if (in_array($name,
$this->
getMapper()->getPKNames())) {
365 $this->changedAttributes[$name] =
true;
381 $this->data[$name] = $value;
388 return array_key_exists($name,
$this->data);
396 unset(
$this->data[$name]);
406 for($iter->rewind(); $iter->valid(); $iter->next()) {
407 $curNode = $iter->currentNode();
409 $curNode->validateValue($iter->key(), $iter->current());
412 $errorMessage .= $ex->getMessage().
"\n";
415 if (strlen($errorMessage) >
0) {
437 if ($mapper->hasAttribute($name) && $mapper->getAttribute($name)
instanceof ReferenceDescription) {
442 [
'entity' =>
$this,
'value' => $name]))) {
447 $validateDescription =
$this->
getValueProperty($name,
'validate_description');
448 if (strlen($validateDescription) >
0) {
450 $errorMessage = $messageInstance->getText($validateDescription);
454 $errorMessage = $messageInstance->getText(
"The value of '%0%' (%1%) is invalid.", [$messageInstance->getText($name), $value]);
463 return array_keys(
$this->changedAttributes);
470 if (
isset(
$this->originalData[$name])) {
471 return $this->originalData[$name];
487 if (
isset(
$this->properties[$name])) {
488 return $this->properties[$name];
492 $properties =
$this->
getMapper()->getProperties();
493 if (
isset($properties[$name])) {
494 return $properties[$name];
505 $this->properties[$name] = $value;
514 $result = array_keys(
$this->
getMapper()->getProperties());
515 return array_merge($result, array_keys(
$this->properties));
522 if (!
isset(
$this->valueProperties[$name]) || !
isset(
$this->valueProperties[$name][$property])) {
525 if ($mapper->hasAttribute($name)) {
526 $attr = $mapper->getAttribute($name);
529 return $attr->$getter();
535 return $this->valueProperties[$name][$property];
544 if (!
isset(
$this->valueProperties[$name])) {
545 $this->valueProperties[$name] = [];
547 $this->valueProperties[$name][$property] = $value;
556 if ($mapper->hasAttribute($name)) {
557 $attr = $mapper->getAttribute($name);
559 $result = $attr->getPropertyNames();
562 return array_merge($result, array_keys(
$this->valueProperties[$name]));
569 if ($excludeTransient) {
572 $attributes =
$this->
getMapper()->getAttributes();
573 foreach ($attributes
as $attribute) {
574 $names[] = $attribute->getName();
578 $names = array_keys(
$this->data);
588 return $this->
getOID()->__toString();
595 $str =
$this->
getOID()->__toString().
"\n";
599 if (is_array($value)) {
600 $valueStr =
self::dumpArray($value).
"\n";
603 if (is_object($value)) {
604 $valueStr = $value->__toString().
"\n";
610 $str .=
" ".$valueName.
": ".$valueStr;
620 private static function dumpArray(array $array) {
622 foreach ($array
as $value) {
623 if (is_object($value)) {
624 $str .= $value->__toString().
", ";
630 $str = preg_replace(
"/, $/",
"", $str).
"]";
643 $this->mapper =
null;
644 return serialize(get_object_vars(
$this));
649 foreach ($values
as $key => $value) {
650 $this->$key = $value;
static NULL_OID()
Get the NULL instance.
getIndispensableObjects()
ValidationException signals an exception in validation.
NullMapper acts as there is no mapper.
static getDump($variable, $strlen=100, $width=25, $depth=10, $i=0, &$objects=[])
Get the dump of a variable as string.
DefaultPersistentObject is the base class of all persistent objects.
PropertyChangeEvent signals a change of a property of a PersistentObject instance.
__construct(ObjectId $oid=null, array $initialData=null)
Constructor.
mergeValues(PersistentObject $object)
NodeValueIterator is used to iterate over all persistent values of a Node (not including relations).
copyValues(PersistentObject $object, $copyPkValues=true)
Validator is is the single entry point for validation.
__toString()
Get a string representation of the PersistentObject.
static underScoreToCamelCase($string, $firstLowerCase=false)
Convert a string in underscore notation to camel case notation.
getValueProperty($name, $property)
StateChangeEvent signals a change of the state of a PersistentObject instance.
setValue($name, $value, $forceSet=false, $trackChange=true)
getValuePropertyNames($name)
StringUtil provides support for string manipulation.
setValue($name, $value, $forceSet=false, $trackChange=true)
Set the value of an attribute if it exists.
validateValue($name, $value)
ObjectId is the unique identifier of an object.
ValueChangeEvent signals a change of a value of a PersistentObject instance.
getValueNames($excludeTransient=false)
Instances of ReferenceDescription describe reference attributes of PersistentObjects.
getType()
Get the type (including namespace)
setValueInternal($name, $value)
Internal (fast) version to set a value without any validation, state change, listener notification et...
static getInstance($name, $dynamicConfiguration=[])
static validate($value, $validateDesc, $context=null)
Validate the given value against the given validateType description.
setValueProperty($name, $property, $value)
setProperty($name, $value)
PersistentObject defines the interface of all persistent objects.
static isValid($oid)
Check if a serialized ObjectId has a valid syntax, the type is known and if the number of primary key...
setOIDInternal(ObjectId $oid, $triggerListeners)
Set the object id of the PersistentObject.
validateValueAgainstValidateType($name, $value)
Check a value's value against the validation type set on it.
ObjectFactory implements the service locator pattern by wrapping a Factory instance and providing sta...