Example #1
0
 public static function initialize(Config $config)
 {
     $config->addEventAfter(Event::CONSTRUCT, function ($model) {
         $class = get_class($model);
         $model->uniqueKey = $model->uniqueKey ?: $class::newRandomKeyUnique();
     });
 }
Example #2
0
 public static function initialize(Config $repo)
 {
     $repo->addEventBefore(Event::SAVE, function ($model) {
         $model->updatedAt = self::getCurrentDate();
     })->addEventBefore(Event::INSERT, function ($model) {
         $model->createdAt = self::getCurrentDate();
     });
 }
Example #3
0
 /**
  * Enables Repo "inheritance" allowing multiple repos to share one storage table
  * You will need to call setRootRepo on all the child repos.
  *
  * @param  boolean      $inherited
  * @return Config $this
  */
 public function setInherited($inherited)
 {
     $this->inherited = (bool) $inherited;
     if ($inherited) {
         if (!$this->reflectionModel->isRoot()) {
             $rootRepo = Container::get($this->reflectionModel->getRoot()->getName());
             $this->rootConfig = $rootRepo->getConfig();
         }
         $this->table = $this->rootConfig->getTable();
     }
     return $this;
 }
Example #4
0
 /**
  * Adds present and currency asserts to currency
  *
  * @param  Config $config
  */
 public static function initialize(Config $config)
 {
     $config->addAsserts([new Assert\Present('currency'), new AssertCurrency('currency')]);
 }
Example #5
0
 /**
  * @covers ::assertModel
  */
 public function testAssertModel()
 {
     $config = new Config(__NAMESPACE__ . '\\TestModel\\City');
     $model = new City();
     $other = new Post();
     $config->assertModel($model);
     $this->setExpectedException('InvalidArgumentException');
     $config->assertModel($other);
 }
Example #6
0
 /**
  * @covers ::hasManyThrough
  */
 public function testHasManyThrough()
 {
     $config = new Config('Harp\\Harp\\Test\\TestModel\\Country');
     $config->hasManyThrough('users', 'Harp\\Harp\\Test\\TestModel\\User', 'cities', ['foreignKey' => 'cityId']);
     $this->assertEquals(new HasManyThrough('users', $config, 'Harp\\Harp\\Test\\TestModel\\User', 'cities', ['foreignKey' => 'cityId']), $config->getRel('users'));
 }
Example #7
0
 public static function initialize(Config $config)
 {
     $config->addAsserts([new Assert\Present('value'), new Assert\Number('value')]);
 }
Example #8
0
 public static function initialize(Config $repo)
 {
     $repo->setInherited(true);
 }
Example #9
0
 public static function initialize(Config $repo)
 {
     $repo->setSoftDelete(true);
 }
Example #10
0
 public static function initialize(Config $config)
 {
     $config->addAsserts([new AssertRange('days')]);
 }
Example #11
0
 /**
  * Add 'parent' and 'children' rels
  *
  * @param  Config $config
  */
 public static function initialize(Config $config)
 {
     $class = $config->getModelClass();
     $config->addRel(new Rel\BelongsTo('parent', $config, $class::getRepo()))->addRel(new Rel\HasMany('children', $config, $class::getRepo(), ['foreignKey' => 'parentId']));
 }
Example #12
0
 public static function initialize(Config $config)
 {
     $config->addSerializers([new Json('responseData')]);
 }