Example #1
0
 /**
  * Handle get$Model(), find$Model(), all$Models(), save$Model(), create$Model() and delete$Model() methods.
  *
  * @param string $method
  * @param array  $arguments
  *
  * @return mixed
  */
 public function __call($method, $arguments)
 {
     if (preg_match('/^(get|one|all|save|create|delete|reload)(.+)$/', $method, $matches)) {
         $method = $matches[1];
         array_unshift($arguments, $matches[2]);
         $usePlural = $method === 'all';
         if ($method === 'reload') {
             if (count($arguments) == 1) {
                 $usePlural = true;
                 $arguments[] = null;
                 $arguments[] = array('all' => true);
             } elseif (count($arguments) == 2 && is_array($arguments[1]) && isset($this->plurals[$arguments[0]]) && $this->plurals[$arguments[0]] != $matches[2]) {
                 // reloadPlural($options)
                 $arguments[0] = $this->plurals[$arguments[0]];
                 $arguments[2] = $arguments[1];
                 $arguments[1] = null;
                 $arguments[2]['all'] = true;
             }
         }
         if ($usePlural) {
             if (isset($this->plurals[$arguments[0]])) {
                 $arguments[0] = $this->plurals[$arguments[0]];
             } else {
                 if (isset($this->configs[$arguments[0]])) {
                     warning('Use plural form "' . array_search($arguments[0], $this->plurals) . '"');
                 }
             }
         }
         return call_user_func_array(array($this, $method), $arguments);
     }
     return parent::__call($method, $arguments);
 }
Example #2
0
 /**
  * Set a property or fields.
  *
  * @param string $property
  * @param mixed  $value
  */
 public function __set($property, $value)
 {
     if (property_exists($this->instance, $property)) {
         if (array_key_exists($property, $this->fields)) {
             notice('Property "' . $property . '" is ambiguous. It\'s available in both the instance as the junction fields.', "To modify the mapping of the junction field change the value of \$ModelConfig->hasMany[\$relation]['fields']['" . $property . "']");
         }
         $this->instance->{$property} = $value;
         return;
     }
     if (array_key_exists($property, $this->fields) || $this->dynamicFields) {
         $this->fields[$property] = $value;
         return;
     }
     parent::__set($property, $value);
 }
Example #3
0
 public function __get($property)
 {
     switch ($property) {
         case 'width':
         case 'height':
         case 'aspectRatio':
             $method = 'get' . ucfirst($property);
             return $this->{$method}();
     }
     return parent::__get($property);
 }
Example #4
0
 public function __set($property, $value)
 {
     if ($this->_state == 'deleted') {
         notice('A deleted Record has no properties');
     } else {
         return parent::__set($property, $value);
     }
 }