/** * Get Links object associated with this model. * If there is none, an empty Links object is created. * * @param AbstractModel $model * @return Links * @throws InvalidArgumentException If model does not belong to repo */ public function get(AbstractModel $model) { if (!$this->repo->isModel($model)) { throw new InvalidArgumentException(sprintf('Model must be %s, was %s', $this->repo->getModelClass(), get_class($model))); } if ($this->map->contains($model)) { return $this->map[$model]; } else { return $this->map[$model] = new Links($model); } }
/** * Used for inherited repos. All the child repos should call this, to set the parent repo object explicitly. * * @param AbstractRepo $rootRepo * @return AbstractRepo $this */ public function setRootRepo(AbstractRepo $rootRepo) { if (!$rootRepo->getInherited()) { throw new LogicException('The root repo must be set as inherited (->setInherited(true))'); } if (!$this->inherited) { throw new LogicException('You must call parent::initialize() for inherited repos'); } $this->rootRepo = $rootRepo; return $this; }
public static function initialize(AbstractRepo $repo) { $repo->setFile('Address.json')->addRels([new Rel\One('user', $repo, User::getRepo())]); }
public static function initialize(AbstractRepo $repo) { $repo->setInherited(true); }
public static function initialize(AbstractRepo $repo) { $repo->setSoftDelete(true); }
public static function initialize(AbstractRepo $repo) { $repo->addAsserts([new Present('name'), new Present('other')])->addEventAfter(Event::CONSTRUCT, function ($model) { $model->afterConstructCalled = true; }); }
public static function initialize(AbstractRepo $repo) { $repo->addRels([new RelOne('one', $repo, Model::getRepo()), new RelMany('many', $repo, Model::getRepo())]); }