https://github.com/rekalogika/doctrine-collections-decorator
Lets you easily create decorator classes to modify the behaviors of a Doctrine collection
https://github.com/rekalogika/doctrine-collections-decorator
abstract collection decorator doctrine entity php selectable trait wrapper
Last synced: 6 months ago
JSON representation
Lets you easily create decorator classes to modify the behaviors of a Doctrine collection
- Host: GitHub
- URL: https://github.com/rekalogika/doctrine-collections-decorator
- Owner: rekalogika
- License: mit
- Created: 2023-10-03T09:56:23.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-31T05:41:12.000Z (about 1 year ago)
- Last Synced: 2024-11-16T22:06:59.196Z (7 months ago)
- Topics: abstract, collection, decorator, doctrine, entity, php, selectable, trait, wrapper
- Language: PHP
- Homepage: https://rekalogika.dev/doctrine-collections-decorator
- Size: 71.3 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# rekalogika/doctrine-collections-decorator
Lets you easily create decorator classes to dynamically modify the behaviors of
Doctrine Collection objects, including the collection objects used by Doctrine
ORM in your entities.## Motivation
Custom collection classes won't come to Doctrine ORM anytime soon. Therefore,
the only way to modify the behavior of a Doctrine collection is to use
decorators. However, creating a Collection decorator by hand is a tedious
process.## Synopsis
The decorator class extending one of our abstract classes:
```php
use Doctrine\Common\Collections\Collection;
use Rekalogika\Collections\Decorator\AbstractCollectionDecorator;/**
* @extends AbstractCollectionDecorator
*/
class BookCollection extends AbstractCollectionDecorator
{
/**
* @param Collection $collection
*/
public function __construct(private Collection $collection)
{
}protected function getWrapped(): Collection
{
return $this->collection;
}// add and override methods here:
// ...
}
```The usage in an entity:
```php
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;#[ORM\Entity()]
class BookShelf
{
/**
* @var Collection
*/
#[ORM\OneToMany(targetEntity: Book::class)]
private Collection $books;public function __construct()
{
$this->books = new ArrayCollection();
}public function getBooks(): BookCollection
{
return new BookCollection($this->bookskkk);
}
}
```## Documentation
[rekalogika.dev/doctrine-collections-decorator](https://rekalogika.dev/doctrine-collections-decorator)
## License
MIT
## Contributing
Issues and pull requests should be filed in the GitHub repository
[rekalogika/doctrine-collections-decorator](https://github.com/rekalogika/doctrine-collections-decorator).