generic addition for some interfaces
ging-dev good idea, we should annotate the core types with generic type arguments as well
ging-dev pre-release 1.25.11728
adds the generic template annotations.
I'd appreciate it if you'll try it and let us know what else we can improve, and how to take more advantage of those annotations if there are some scenarios that don't work as expected.
Thank you!
Currently I have some problems related to doctrine/collections
, seems that generics are not working correctly, type of $item
should be User
:
https://github.com/doctrine/collections/blob/2.1.x/src/Collection.php
- Edited
ging-dev seems we don't handle it correctly in global code; working on a fix.
Workaround would be to move the code to a function/method.
- Edited
ging-dev so far, it seems working for Illuminate\Support\Collection
Doctrine\Common\Collections\Collection
is giving TValue
indeed - working on it
fixed! preparing pre-release (full release soon)
- Edited
JakubMisek Thank you, it worked!
There are a few slightly different behaviors on Hover:
ging-dev good point! will be fixed
JakubMisek I got some errors with generic:
my composer.json
{
"require": {
"doctrine/doctrine-bundle": "^2.8",
"doctrine/orm": "^2.14"
}
}
<?php
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
class Category {}
/**
* @extends ServiceEntityRepository<Category>
*
* @method Category|null find($id, $lockMode = null, $lockVersion = null)
* @method Category|null findOneBy(array $criteria, array $orderBy = null)
* @method Category[] findAll()
* @method Category[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class CategoryRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Category::class);
}
public function save(Category $entity, bool $flush = false): void
{
$this->getEntityManager()->persist($entity);
}
/**
* @return list<Category>
*/
public function findRootCategories(): array
{
return $this->createQueryBuilder('c')
->where('c.parent is NULL')
->getQuery()
->getResult();
}
}
i got an error Call to unknown method: CategoryRepository::getEntityManager()
when have @extends ServiceEntityRepository<Category>
in docblock
- Edited
ging-dev thank you, I'm getting it as well;
Would you have any hint, as to where the getEntityManager
is supposed to come from?
I see, if I remove the @extends
, the method is found alright
ok, it's caused by the ambiguity - there are two ServiceEntityRepository
;
we'll handle that
ging-dev fixed in pre-release 1.27.12005
thank!
We have also added a lot of generic type annotations. If you'd have more, please open a new topic here.