Пример #1
0
 /**
  * Call
  *
  * @param string $name
  * @param array $arguments
  * @return mixed
  */
 public function __call($name, $arguments)
 {
     if (isset($arguments[0])) {
         $relModel = $arguments[0];
         if (substr($name, 0, 3) == 'set') {
             // Meta registry
             $registry = Registry::getInstance();
             // Formatting property
             $property = substr($name, 3);
             $property = strtolower($property[0]) . substr($property, 1);
             // Retrieving relation for property
             $rel = $registry->getRelation($this, $property);
             if ($rel) {
                 Factory::create($this, $relModel, $rel)->set();
                 return $this;
             }
         }
     }
     return parent::__call($name, $arguments);
 }
Пример #2
0
 /**
  * Add relations
  *
  * @param array $relations
  * @return Model
  */
 protected function _addRelations(array $relations)
 {
     $registry = Registry::getInstance();
     foreach ($relations as $relation) {
         if (is_array($relation)) {
             $relation = new Relation($relation);
         }
         $registry->addRelation($this, $relation);
     }
     return $this;
 }