Esempio n. 1
0
 /**
  * System properties constructor
  *
  * @param array $data Property data
  * @param ObjectInterface $object Owner object
  */
 public function __construct(array $data, ObjectInterface $object)
 {
     parent::__construct($data, $object);
     // Initialize the object ID
     if (array_key_exists(self::PROPERTY_ID, $data)) {
         $this->uid = Id::unserialize($data[self::PROPERTY_ID]);
     }
     // Initialize the object type
     if (array_key_exists(self::PROPERTY_TYPE, $data)) {
         $this->type = Type::unserialize($data[self::PROPERTY_TYPE]);
     }
     // Initialize the object creation date
     if (array_key_exists(self::PROPERTY_CREATED, $data)) {
         $this->created = $data[self::PROPERTY_CREATED];
     }
     // Initialize the object modification date
     if (array_key_exists(self::PROPERTY_MODIFIED, $data)) {
         $this->modified = $data[self::PROPERTY_MODIFIED];
     }
     // Initialize the object publication date
     if (array_key_exists(self::PROPERTY_PUBLISHED, $data)) {
         $this->published = $data[self::PROPERTY_PUBLISHED];
     }
     // Initialize the object deletion date
     if (array_key_exists(self::PROPERTY_DELETED, $data)) {
         $this->deleted = $data[self::PROPERTY_DELETED];
     }
     // Initialize the object language
     if (array_key_exists(self::PROPERTY_LANGUAGE, $data)) {
         $this->language = trim($data[self::PROPERTY_LANGUAGE]);
     }
     // Initialize the location
     $this->location = Kernel::create(LocationProperties::class, [empty($data[self::PROPERTY_LOCATION]) ? [] : $data[self::PROPERTY_LOCATION], $this->object]);
     // Initialize the object revision
     if (array_key_exists(self::PROPERTY_REVISION, $data)) {
         $this->revision = Revision::unserialize($data[self::PROPERTY_REVISION])->setDraft($this->isDraft());
     }
     // Test if all mandatory properties are set
     if (!$this->uid instanceof Id || !$this->type instanceof Type || !$this->revision instanceof Revision || !$this->created instanceof \DateTimeInterface || !$this->modified instanceof \DateTimeInterface || !strlen($this->language)) {
         throw new InvalidArgumentException('Invalid system properties', InvalidArgumentException::INVALID_SYSTEM_PROPERTIES);
     }
 }