Exemple #1
0
 /**
  * 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);
     }
 }
Exemple #2
0
 /**
  * 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;
 }
Exemple #3
0
 public static function initialize(AbstractRepo $repo)
 {
     $repo->setFile('Address.json')->addRels([new Rel\One('user', $repo, User::getRepo())]);
 }
Exemple #4
0
 public static function initialize(AbstractRepo $repo)
 {
     $repo->setInherited(true);
 }
Exemple #5
0
 public static function initialize(AbstractRepo $repo)
 {
     $repo->setSoftDelete(true);
 }
Exemple #6
0
 public static function initialize(AbstractRepo $repo)
 {
     $repo->addAsserts([new Present('name'), new Present('other')])->addEventAfter(Event::CONSTRUCT, function ($model) {
         $model->afterConstructCalled = true;
     });
 }
Exemple #7
0
 public static function initialize(AbstractRepo $repo)
 {
     $repo->addRels([new RelOne('one', $repo, Model::getRepo()), new RelMany('many', $repo, Model::getRepo())]);
 }