yohang/CalendR

Event repositories can't be properly added with Symfony2 & Doctrine2

nesk opened this issue · 4 comments

nesk commented

It's the second time I'm using Calendr for two different projects and I still get this error :

Capture d e cran 2013-04-01 a 17 26 08

The first time I used Calendr I had a PHP 5.4 server so I could use traits. My repository was declared as your first example code. To avoid the above error, I just added implements ProviderInterface to the EventRepository declaration and it was done.

Now my server is under PHP 5.3 so I'm using the second way provided on the doc. But, using this second way doesn't provides all the methods required by ProviderInterface and, at this point, I'm stuck…

dao commented

interfaces don't provide methods; they require them. you need to do something like:

use CalendR\Event\Provider\ProviderInterface;

class EventRepository extends DocumentRepository implements ProviderInterface

public function getEvents(\DateTime $begin, \DateTime $end, array $options = array())
{
    $events = $this->createQueryBuilder()->blahblah()->getQuery()->execute();
    return $events;
}

i use DocumentRepository because I use doctrine mongodb. It would be EntityRepository if you use ORM.

i'm on php 5.3.10 and symfony 2.2.x-dev.

this project makes me happy.

nesk commented

I'm agree with you, interfaces only exists to define what properties and methods your class should provide but it seems like the documentation forgot to mention the interface is a necessary or the app will never work. To solve my problem I've done something simple but really crappy: I've just copy all the methods inside the EventRepository trait and paste them inside my own event repository, it works now and that seems logical.

Honestly, I think Calendr is an awesome project but the documentation is a real pain in the ass. Sometimes I had to go inside Calendr's code to understand some of the behaviours, this should never happen with a good documentation.

I let this issue opened as a request for a better documentation.

Hi @nesk, I agree with you that CalendR suffers of its poor documentation. However, your case is described here : http://yohan.giarel.li/CalendR/events.html#create_your_event_provider

dao commented

i actually think the documentation is exceptionally good for a symfony bundle!