Пример #1
0
 /**
  * Strategy creation
  *
  * @param AbstractModel $model
  * @param AbstractModel $relatedModel
  * @param Relation $relation
  * @return AbstractStrategy
  */
 public static function create(AbstractModel $model, AbstractModel $relatedModel, Relation $relation)
 {
     $modelKey = is_subclass_of($model, '\\NS\\Meta\\Model\\Model') ? 'Model' : 'Collection';
     $relatedModelKey = is_subclass_of($relatedModel, '\\NS\\Meta\\Model\\Model') ? 'Model' : 'Collection';
     $relationKey = $relation->getType() == Relation::TYPE_ONE ? 'One' : 'Many';
     $className = '\\NS\\Meta\\Model\\SetterStrategy\\' . $modelKey . $relatedModelKey . $relationKey . 'Strategy';
     $strategy = class_exists($className) ? $className : '\\NS\\Meta\\Model\\SetterStrategy\\DefaultStrategy';
     return $strategy::create()->setModel($model)->setRelatedModel($relatedModel)->setRelation($relation);
 }
Пример #2
0
 /**
  * Add relation
  *
  * @param Model|string $model
  * @param Relation $relation
  * @return Model
  */
 public function addRelation($model, Relation $relation)
 {
     $className = is_string($model) ? $model : get_class($model);
     if (!isset($this->_relations[$className])) {
         $this->_relations[$className] = array();
     }
     $this->_relations[$className][$relation->getProperty()] = $relation;
     return $this;
 }