Skip to content

Commit fb558ef

Browse files
Add some Generics
1 parent d11057a commit fb558ef

29 files changed

+119
-1
lines changed

.ddev/example/Controller/Admin/BlogArticleCrudController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
1616
use EasyCorp\Bundle\EasyAdminBundle\Filter\EntityFilter;
1717

18+
/**
19+
* @extends AbstractCrudController<BlogArticle>
20+
*/
1821
#[AdminCrud(routePath: '/blog-article')]
1922
class BlogArticleCrudController extends AbstractCrudController
2023
{

.ddev/example/Controller/Admin/CategoryCrudController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
99
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
1010

11+
/**
12+
* @extends AbstractCrudController<Category>
13+
*/
1114
#[AdminCrud(routePath: '/category')]
1215
class CategoryCrudController extends AbstractCrudController
1316
{

src/Contracts/Controller/CrudControllerInterface.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@
2222

2323
/**
2424
* @author Javier Eguiluz <javier.eguiluz@gmail.com>
25+
*
26+
* @template TEntity of object
2527
*/
2628
interface CrudControllerInterface
2729
{
30+
/**
31+
* @return class-string<TEntity>
32+
*/
2833
public static function getEntityFqcn(): string;
2934

3035
public function configureCrud(Crud $crud): Crud;
@@ -65,10 +70,19 @@ public function createIndexQueryBuilder(SearchDto $searchDto, EntityDto $entityD
6570

6671
public function createEntity(string $entityFqcn);
6772

73+
/**
74+
* @param TEntity $entityInstance
75+
*/
6876
public function updateEntity(EntityManagerInterface $entityManager, $entityInstance): void;
6977

78+
/**
79+
* @param TEntity $entityInstance
80+
*/
7081
public function persistEntity(EntityManagerInterface $entityManager, $entityInstance): void;
7182

83+
/**
84+
* @param TEntity $entityInstance
85+
*/
7286
public function deleteEntity(EntityManagerInterface $entityManager, $entityInstance): void;
7387

7488
public function createEditFormBuilder(EntityDto $entityDto, KeyValueStore $formOptions, AdminContext $context): FormBuilderInterface;

src/Contracts/Event/EntityLifecycleEventInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44

55
/**
66
* @author: Benjamin Leibinger <mail@leibinger.io>
7+
*
8+
* @template TEntity of object
79
*/
810
interface EntityLifecycleEventInterface
911
{
12+
/**
13+
* @return TEntity
14+
*/
1015
public function getEntityInstance();
1116
}

src/Controller/AbstractCrudController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@
6565

6666
/**
6767
* @author Javier Eguiluz <javier.eguiluz@gmail.com>
68+
*
69+
* @template TEntity of object
70+
* @implements CrudControllerInterface<TEntity>
6871
*/
6972
abstract class AbstractCrudController extends AbstractController implements CrudControllerInterface
7073
{

src/Dto/EntityDto.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,29 @@
2121

2222
/**
2323
* @author Javier Eguiluz <javier.eguiluz@gmail.com>
24+
*
25+
* @template TEntity of object
2426
*/
2527
final class EntityDto
2628
{
2729
private bool $isAccessible = true;
30+
/** @var class-string<TEntity> */
2831
private string $fqcn;
32+
/** @var ClassMetadata<TEntity> */
2933
private ClassMetadata $metadata;
34+
/** @var TEntity|null */
3035
private $instance;
3136
private $primaryKeyName;
3237
private mixed $primaryKeyValue = null;
3338
private string|Expression|null $permission;
3439
private ?FieldCollection $fields = null;
3540
private ?ActionCollection $actions = null;
3641

42+
/**
43+
* @param class-string<TEntity> $entityFqcn
44+
* @param ClassMetadata<TEntity> $entityMetadata
45+
* @param TEntity|null $entityInstance
46+
*/
3747
public function __construct(string $entityFqcn, ClassMetadata $entityMetadata, string|Expression|null $entityPermission = null, /* ?object */ $entityInstance = null)
3848
{
3949
if (!\is_object($entityInstance)
@@ -61,6 +71,9 @@ public function __toString(): string
6171
return $this->toString();
6272
}
6373

74+
/**
75+
* @return class-string<TEntity>
76+
*/
6477
public function getFqcn(): string
6578
{
6679
return $this->fqcn;
@@ -84,6 +97,9 @@ public function toString(): string
8497
return sprintf('%s #%s', $this->getName(), substr($this->getPrimaryKeyValueAsString(), 0, 16));
8598
}
8699

100+
/**
101+
* @return TEntity|null
102+
*/
87103
public function getInstance()/* : ?object */
88104
{
89105
return $this->instance;
@@ -246,6 +262,9 @@ public function isEmbeddedClassProperty(string $propertyName): bool
246262
return \array_key_exists($propertyNameParts[0], $this->metadata->embeddedClasses);
247263
}
248264

265+
/**
266+
* @param TEntity|null $newEntityInstance
267+
*/
249268
public function setInstance(?object $newEntityInstance): void
250269
{
251270
if (null !== $this->instance && null !== $newEntityInstance && !$newEntityInstance instanceof $this->fqcn) {
@@ -256,6 +275,9 @@ public function setInstance(?object $newEntityInstance): void
256275
$this->primaryKeyValue = null;
257276
}
258277

278+
/**
279+
* @param TEntity $newEntityInstance
280+
*/
259281
public function newWithInstance(/* object */ $newEntityInstance): self
260282
{
261283
if (!\is_object($newEntityInstance)) {

src/Event/AbstractLifecycleEvent.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,20 @@
66

77
/**
88
* @author: Benjamin Leibinger <mail@leibinger.io>
9+
*
10+
* @template TEntity of object
11+
* @implements EntityLifecycleEventInterface<TEntity>
912
*/
1013
abstract class AbstractLifecycleEvent implements EntityLifecycleEventInterface
1114
{
15+
/**
16+
* @var TEntity
17+
*/
1218
protected $entityInstance;
1319

20+
/**
21+
* @param TEntity $entityInstance
22+
*/
1423
public function __construct(/* ?object */ $entityInstance)
1524
{
1625
if (!\is_object($entityInstance)

src/Security/SecurityVoter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
1313
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
1414

15-
/*
15+
/**
1616
* @author Javier Eguiluz <javier.eguiluz@gmail.com>
1717
*/
1818
final class SecurityVoter extends Voter

tests/PrettyUrlsTestApplication/src/Controller/BlogPostCrudController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
1010
use EasyCorp\Bundle\EasyAdminBundle\Tests\PrettyUrlsTestApplication\Entity\BlogPost;
1111

12+
/**
13+
* @extends AbstractCrudController<BlogPost>
14+
*/
1215
class BlogPostCrudController extends AbstractCrudController
1316
{
1417
public static function getEntityFqcn(): string

tests/PrettyUrlsTestApplication/src/Controller/CategoryCrudController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
use EasyCorp\Bundle\EasyAdminBundle\Tests\PrettyUrlsTestApplication\Entity\Category;
1717
use Symfony\Component\HttpFoundation\Response;
1818

19+
/**
20+
* @extends AbstractCrudController<Category>
21+
*/
1922
class CategoryCrudController extends AbstractCrudController
2023
{
2124
public static function getEntityFqcn(): string

0 commit comments

Comments
 (0)