-
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Particular use question :) #4
Comments
Can you post a code sample? I think what you want is doable. It is only a matter if it is possible to use a ready-made class from this project, or if you need to copy & paste relevant code. |
Of course!. This is my EntityCollection (aka BaseClass)
This is my custom collection
In this way, it works perfectly, but I don't have the feature of chaining matching methods. I haven't managed to make the matching work for me. I've tried copying the content of the LazyMatchingReadableCollection class to my EntityCollection and extending it from SelectableReadableCollectionDecorator, but it doesn't work; it gives me a copy error. For example:
Using this in this way:
Give me this error when InLastMonth() method is called
I have tried some more tests, but I don't see a way to get both of them to work together. Additionally, it would be ideal for me if the matching method does not remain public. |
I'm still investigating my error. )Doctrine\Common\Collections\Expr class in Doctrine has readonly properties in the constructor |
Just to provide more information, I have managed to make the method chaining work if I don't use deep_copy and only use clone methods. However, obviously now I cannot declare matching as protected due to the interfaces.
|
Thank you for your investigation. I didn't encounter the error because so far I only use it for straight |
2.1.4 should fix the Regarding your original question, can you just stack the decorators? class EntityCollection extends AbstractCollectionDecorator
{
private Collection $collection;
/**
* @param Collection&Selectable $collection
*/
public function __construct(Collection $collection)
{
if (!$collection instanceof Selectable) {
throw new \RuntimeException('The wrapped collection must implement the Selectable interface.');
}
$this->collection = new LazyMatchingCollection($collection);
}
protected function getWrapped(): Collection
{
return $this->collection;
}
} |
Hi!. thanks deep_copy bug is fixed for me in the last release!. Regarding the solution for my case that you propose, it doesn't work because if I make a return new LClassStudentCollection($this->getWrapped()->matching($criteria)); from any of the children of EntityCollection, That matching return type is of type ReadableCollection&Selectable and not of type Collection like the constructor. I think my case is very specific and I don't believe it happens to many people, so you can consider the issue closed. In the end, I've made EntityCollection implement Collection and I've written custom code to make my case work. Many thanks for your time and assistance! |
Hi!, congratulations on the work, I love the idea and the use of the package, it's something I've implemented by hand before.
I have some questions for a particular use case, let's see if you can help me.
I'm defining my own collections to ensure type safety.
I have something similar to this =>
StudentCollection extends EntityCollection and the latter lives in my Shared folder and this last is extending some classes from this package.
I would like to achieve the same functionality as with the LazyMatchingCollection, chaining the matchings but within my EntityCollection itself.
Something like this: StundetCollection()->enabled()->theLastMonth();
In addition to this, it would be ideal for me if the matching method itself is only accessible from within StundentCollection but not exposed as public.
I have done some tests and I can only protect the matching method by extending my EntityCollection from AbstractCollectionDecorator.
And similarly, I only achieve the chaining of matching if I don't use my own collection and in the entity I directly use LazyMatchingCollection.
In summary, I would like to achieve both behaviors in my base collection so that I can extend them to the rest of my collections.
Thank you very much in advance!
The text was updated successfully, but these errors were encountered: