コード例 #1
0
 public static function initialize(Config $config)
 {
     $config->addEventAfter(Event::CONSTRUCT, function ($model) {
         $class = get_class($model);
         $model->uniqueKey = $model->uniqueKey ?: $class::newRandomKeyUnique();
     });
 }
コード例 #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();
     });
 }
コード例 #3
0
ファイル: Config.php プロジェクト: harp-orm/harp
 /**
  * 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;
 }
コード例 #4
0
ファイル: CurrencyTrait.php プロジェクト: harp-orm/money
 /**
  * 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')]);
 }
コード例 #5
0
ファイル: ConfigTest.php プロジェクト: harp-orm/harp
 /**
  * @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);
 }
コード例 #6
0
ファイル: RelConfigTraitTest.php プロジェクト: harp-orm/harp
 /**
  * @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'));
 }
コード例 #7
0
ファイル: ValueTrait.php プロジェクト: harp-orm/money
 public static function initialize(Config $config)
 {
     $config->addAsserts([new Assert\Present('value'), new Assert\Number('value')]);
 }
コード例 #8
0
ファイル: InheritedTrait.php プロジェクト: harp-orm/harp
 public static function initialize(Config $repo)
 {
     $repo->setInherited(true);
 }
コード例 #9
0
ファイル: SoftDeleteTrait.php プロジェクト: harp-orm/harp
 public static function initialize(Config $repo)
 {
     $repo->setSoftDelete(true);
 }
コード例 #10
0
ファイル: DaysRangeTrait.php プロジェクト: harp-orm/range
 public static function initialize(Config $config)
 {
     $config->addAsserts([new AssertRange('days')]);
 }
コード例 #11
0
ファイル: NestedTrait.php プロジェクト: harp-orm/nested
 /**
  * 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']));
 }
コード例 #12
0
ファイル: TransferTrait.php プロジェクト: clippings/transfer
 public static function initialize(Config $config)
 {
     $config->addSerializers([new Json('responseData')]);
 }