public function getProperty($name)
 {
     if (Attributes::isClassAttribute(get_called_class(), $name)) {
         return $this->getAttribute($name);
     } elseif ($type = AccessibleProperties::getProperty(get_called_class(), $name)) {
         if (isset($type['propName'])) {
             return $this->{$type['propName']};
         } elseif ($type[0]) {
             return $this->{$name}();
         }
     }
     throw new Exception\InvalidArgumentException(sprintf("Trying to get unknown property %s::%s", get_called_class(), $name));
 }
 protected function createRecord(array $options = [])
 {
     if (!$this->runCallbacks('validation', function () {
         return $this->isValid('create');
     })) {
         return false;
     }
     if ($this->runCallbacks('save', function () {
         return $this->runCallbacks('create', function () {
             if (!$this->fillTimeAttribute('created_at')) {
                 $this->fillTimeAttribute('created_on');
             }
             if (!$this->fillTimeAttribute('updated_at')) {
                 $this->fillTimeAttribute('updated_on');
             }
             $id = static::persistence()->insert($this);
             if ($id) {
                 if (true !== $id) {
                     if (Attributes::isClassAttribute(get_called_class(), static::primaryKey())) {
                         $this->setAttribute(static::primaryKey(), $id);
                     }
                     $this->isNewRecord = false;
                 }
                 return true;
             }
             return false;
         });
     })) {
         # TODO: after-commit callbacks.
         // $this->runCallbacks('commit');
         return true;
     }
     return false;
 }
Exemple #3
0
 protected function getPropertyGetter($modelClass, $propName)
 {
     if (Attributes::isClassAttribute($modelClass, $propName)) {
         return function ($model) use($propName) {
             return $model->getAttribute($propName);
         };
     } else {
         $property = AccessibleProperties::getProperty($modelClass, $propName);
         if ($property === true) {
             return function ($model) use($propName) {
                 $model->{$propName};
             };
         } elseif ($property[0]) {
             return function ($model) use($propName) {
                 $model->{$propName}();
             };
         }
     }
     throw new Exception\RuntimeException(sprintf("Unknown attribute or property %s::%s", $modelClass, $propName));
 }