Skip to content

Commit

Permalink
Added entity name overide
Browse files Browse the repository at this point in the history
Removed old unused code - hydrator & validator
  • Loading branch information
akadlec committed Mar 22, 2020
1 parent a60d979 commit 1d1d947
Show file tree
Hide file tree
Showing 15 changed files with 17 additions and 634 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
},

"require" : {
"php" : ">=7.3.0",
"php" : ">=7.2.0",

"doctrine/orm" : "~2.5",

Expand Down
18 changes: 15 additions & 3 deletions src/IPub/DoctrineCrud/Crud/Create/EntityCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,23 @@ public function __construct(
*
* @return Entities\IEntity
*/
public function create(Utils\ArrayHash $values, Entities\IEntity $entity = NULL) : Entities\IEntity
public function create(Utils\ArrayHash $values, Entities\IEntity $entity = null): Entities\IEntity
{
if (!$entity instanceof Entities\IEntity) {
try {
$rc = new ReflectionClass($this->entityName);
// Entity name is overriden
if ($values->offsetExists('entity') && class_exists($values->offsetGet('entity'))) {
$entityClass = $values->offsetGet('entity');

} else {
$entityClass = $this->entityName;
}

$rc = new ReflectionClass($entityClass);

if ($rc->isAbstract()) {
throw new Exceptions\InvalidArgumentException(sprintf('Abstract entity "%s" can not be used.', $entityClass));
}

if ($constructor = $rc->getConstructor()) {
$entity = $rc->newInstanceArgs(DoctrineCrud\Helpers::autowireArguments($constructor, (array) $values));
Expand All @@ -92,7 +104,7 @@ public function create(Utils\ArrayHash $values, Entities\IEntity $entity = NULL)

$this->processHooks($this->beforeAction, [$entity, $values]);

$this->entityMapper->fillEntity($values, $entity, TRUE);
$this->entityMapper->fillEntity($values, $entity, true);

$this->entityManager->persist($entity);

Expand Down
18 changes: 1 addition & 17 deletions src/IPub/DoctrineCrud/DI/DoctrineCrudExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@
*/
class DoctrineCrudExtension extends DI\CompilerExtension
{
// Define tag string for validator
const TAG_VALIDATOR = 'ipub.doctrine.validator';

/**
* @return void
*
Expand All @@ -62,14 +59,9 @@ public function loadConfiguration() : void
* Extensions helpers
*/

$builder->addDefinition($this->prefix('entity.validator'))
->setType(DoctrineCrud\Validation\ValidatorProxy::class)
->setArguments([$annotationReader])
->setAutowired(FALSE);

$builder->addDefinition($this->prefix('entity.mapper'))
->setType(Mapping\EntityMapper::class)
->setArguments(['@' . $this->prefix('entity.validator'), $annotationReader])
->setArguments([$annotationReader])
->setAutowired(FALSE);

/**
Expand Down Expand Up @@ -119,14 +111,6 @@ public function beforeCompile() : void
// Get container builder
$builder = $this->getContainerBuilder();

// Get validators service
$validator = $builder->getDefinition($this->prefix('entity.validator'));

foreach (array_keys($builder->findByTag(self::TAG_VALIDATOR)) as $serviceName) {
// Register validator to proxy validator
$validator->addSetup('registerValidator', ['@' . $serviceName, $serviceName]);
}

$builder->getDefinition($builder->getByType(Doctrine\ORM\EntityManagerInterface::class, TRUE))
->addSetup(
'?->getConfiguration()->addCustomStringFunction(?, ?)',
Expand Down
15 changes: 0 additions & 15 deletions src/IPub/DoctrineCrud/Entities/IEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,5 @@
*/
interface IEntity
{
/**
* @param int $maxLevel
*
* @return array
*/
public function toArray(int $maxLevel = 1) : array;

/**
* @return array
*/
public function toSimpleArray() : array;

/**
* @return string
*/
public function __toString();
}
101 changes: 0 additions & 101 deletions src/IPub/DoctrineCrud/Entities/TEntity.php

This file was deleted.

5 changes: 0 additions & 5 deletions src/IPub/DoctrineCrud/Mapping/Annotation/Crud.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ final class Crud extends Annotation
*/
public $is;

/**
* @var string|array
*/
public $validator;

/**
* @return bool
*/
Expand Down
Loading

0 comments on commit 1d1d947

Please sign in to comment.