Example #1
0
 /**
  * Constructor.
  *
  * @param   EmbedMetadata   $metadata   The internal embed metadata that supports this Embed.
  * @param   Store           $store      The model store service for handling persistence operations.
  * @param   array|null      $properties The embed's properties from the db layer to init the embed with. New embeds will constructed with a null record.
  */
 public function __construct(EmbedMetadata $metadata, Store $store, array $properties = null)
 {
     parent::__construct($metadata, $store, $properties);
     $this->getState()->setLoaded();
 }
Example #2
0
 /**
  * Sets a model to a collection property (original, added, removed, models).
  *
  * @param   string          $property   The property key
  * @param   AbstractModel   $model      The model to set.
  * @return  self
  */
 protected function set($property, AbstractModel $model)
 {
     $key = $model->getCompositeKey();
     $this->{$property}[$key] = $model;
     if ('models' === $property) {
         $keys = array_flip($this->modelKeyMap);
         if (!isset($keys[$key])) {
             $this->modelKeyMap[] = $key;
             $this->totalCount++;
         }
     }
     return $this;
 }
Example #3
0
 /**
  * {@inheritdoc}
  *
  * Overloaded to support global model defaults.
  *
  */
 protected function applyDefaultAttrValues(array $attributes = [])
 {
     $attributes = parent::applyDefaultAttrValues($attributes);
     // Set defaults for the entire entity.
     foreach ($this->getMetadata()->defaultValues as $key => $value) {
         if (isset($attributes[$key])) {
             continue;
         }
         $attributes[$key] = $this->convertAttributeValue($key, $value);
     }
     return $attributes;
 }