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; }
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; }
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); }
/** * 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']; }
/** * @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); } }
public function joinToQuery(Select $query, $leftAlias, $alias) { $query->leftJoin($leftAlias, $this->related->getTable(), $alias, (new Expression())->eq("{$leftAlias}.{$this->getForeignKey()}", "{$alias}.{$this->getTargetKey()}")); }