public static function initialize(Config $config) { $config->addEventAfter(Event::CONSTRUCT, function ($model) { $class = get_class($model); $model->uniqueKey = $model->uniqueKey ?: $class::newRandomKeyUnique(); }); }
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(); }); }
/** * 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; }
/** * 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')]); }
/** * @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); }
/** * @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')); }
public static function initialize(Config $config) { $config->addAsserts([new Assert\Present('value'), new Assert\Number('value')]); }
public static function initialize(Config $repo) { $repo->setInherited(true); }
public static function initialize(Config $repo) { $repo->setSoftDelete(true); }
public static function initialize(Config $config) { $config->addAsserts([new AssertRange('days')]); }
/** * 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'])); }
public static function initialize(Config $config) { $config->addSerializers([new Json('responseData')]); }