Ejemplo n.º 1
0
 private function setAssociations()
 {
     require_once __DIR__ . '/Relations/InterfaceRelations.php';
     require_once __DIR__ . '/Relations/AbstractRelations.php';
     $namespace = $this->class->getNamespaceName();
     foreach ($this->class->getStaticProperties() as $name => $definitions) {
         if (!$definitions) {
             continue;
         }
         foreach (Utils::wrapStringsInArrays($definitions) as $definition) {
             $relationship = null;
             $definition += ['namespace' => $namespace];
             switch ($name) {
                 case 'has_many':
                     $relationship = new HasMany($definition);
                     break;
                 case 'has_one':
                     $relationship = new HasOne($definition);
                     break;
                 case 'belongs_to':
                     $relationship = new BelongsTo($definition);
                     break;
                 case 'has_and_belongs_to_many':
                     $relationship = new HasAndBelongsToMany($definition);
                     break;
             }
             if ($relationship) {
                 $this->addRelationship($relationship);
             }
         }
     }
 }
Ejemplo n.º 2
0
 public function testWrapStringsInArrays()
 {
     $utils = new Utils();
     $x = ['1', ['2']];
     $this->assertEquals([['1'], ['2']], $utils->wrapStringsInArrays($x));
     $x = '1';
     $this->assertEquals([['1']], $utils->wrapStringsInArrays($x));
 }