Nextras\Orm\Model\IModel::getRepository PHP Method

getRepository() public method

Returns repository by repository class.
public getRepository ( string $className ) : Nextras\Orm\Repository\IRepository
$className string
return Nextras\Orm\Repository\IRepository
    public function getRepository($className);

Usage Example

Esempio n. 1
0
 protected function random(PropertyMetadata $property)
 {
     if (in_array($property->relationshipType, [PropertyMetadata::RELATIONSHIP_MANY_HAS_ONE, PropertyMetadata::RELATIONSHIP_ONE_HAS_ONE, PropertyMetadata::RELATIONSHIP_ONE_HAS_ONE_DIRECTED])) {
         $entityClass = $this->model->getRepository($property->relationshipRepository)->getEntityClassNames()[0];
         return $this->create($entityClass);
     }
     $possibilities = [];
     if ($property->enum) {
         $possibilities = $property->enum;
     } else {
         foreach (array_keys($property->types) as $type) {
             switch ($type) {
                 case 'datetime':
                     $possibilities[] = new DateTime($this->randomInt(2010, 2020) . '-' . $this->randomInt(1, 12) . '-' . $this->randomInt(1, 31));
                     break;
                 case 'string':
                     $possibilities[] = $this->randomWords(20, 50);
                     break;
                 case 'int':
                     $possibilities[] = $this->randomInt(0, 100);
                     break;
                 case 'float':
                     $possibilities[] = $this->randomInt(0, 100) + $this->randomInt(0, 100) / 100;
                     break;
                 case 'bool':
                     $possibilities[] = (bool) $this->randomInt(0, 1);
                     break;
             }
         }
     }
     if (!$possibilities) {
         return NULL;
     }
     return $possibilities[array_rand($possibilities)];
 }
All Usage Examples Of Nextras\Orm\Model\IModel::getRepository