Exemplo n.º 1
0
 public function __construct(Entity $entity, $method)
 {
     $class = $entity->getClassName();
     if (!is_callable([$class, $method])) {
         throw new \InvalidArgumentException("{$class}::{$method} is not callable");
     }
     $this->method = $method;
 }
Exemplo n.º 2
0
 public function __construct(Entity $entity, $property)
 {
     $class = $entity->getClassName();
     if (!property_exists($class, $property)) {
         throw new \InvalidArgumentException("{$class}::{$property} is not a property");
     }
     $this->property = $property;
 }
Exemplo n.º 3
0
 public function testCreate()
 {
     $entity = new Entity($this->entityManager, TestEntity::class);
     $entity->setTable('test');
     $entity->addField('key', new Field(new PropertySetter($entity, 'field'), new PropertyGetter($entity, 'field')));
     $entity->setPrimaryKey('key');
     $object = $entity->create(['key' => 'value']);
     $this->assertInstanceOf(TestEntity::class, $object);
     $this->assertEquals('value', $object->field);
 }
Exemplo n.º 4
0
 /**
  * Count selected records
  *
  * @param array $parameters
  *
  * @return mixed
  */
 public function count(array $parameters = [])
 {
     $this->manager->commit();
     $count = $this->applyFilters($this->queryBuilder->select('count(*) as count')->from($this->entity->getTable(), $this->alias))->query(array_merge($this->parameters, $parameters))->fetch();
     return $count['count'];
 }
Exemplo n.º 5
0
 /**
  * @param Entity $entity
  */
 private function readTableName(Entity $entity)
 {
     $className = $entity->getClassName();
     try {
         $classAnnotations = $this->annotationReader->readClass($className);
         $entity->setTable($classAnnotations->get('Table'));
     } catch (\OutOfBoundsException $e) {
         throw new EntityDefinitionException("Missing Table annotation of {$className}", 0, $e);
     }
 }
Exemplo n.º 6
0
 public function joinToQuery(Select $query, $leftAlias, $alias)
 {
     $query->leftJoin($leftAlias, $this->related->getTable(), $alias, (new Expression())->eq("{$leftAlias}.{$this->getForeignKey()}", "{$alias}.{$this->getTargetKey()}"));
 }