0
votes

I'm trying to extend this IndexRepository to add my own method for a special search.

In the controller I inject my own IndexRepository with:

use Webian\Iancalendar\Domain\Repository\IndexRepository;

/**
 * Inject index repository.
 *
 * @param IndexRepository $indexRepository
 */
public function injectIndexRepository(IndexRepository $indexRepository)
{
    $this->indexRepository = $indexRepository;
}

What I did is working but I get this warning:

PHP Warning
Core: Error handler (BE): PHP Warning: Declaration of Webian\Iancalendar\Controller\
BackendController::injectIndexRepository(Webian\Iancalendar\Domain\Repository\IndexRepository $indexRepository)
should be compatible with HDNET\Calendarize\Controller\
AbstractController::injectIndexRepository(HDNET\Calendarize\Domain\Repository\IndexRepository $indexRepository)
in /typo3conf/ext/iancalendar/Classes/Controller/BackendController.php line 42

That's because I'm using my own Webian\Iancalendar\Domain\Repository\IndexRepository that extends HDNET\Calendarize\Domain\Repository\IndexRepository. If I use the original one the warning doesn't appear but obviously my own method is not called.

How can I avoid that warning?

1

1 Answers

1
votes

You should either not extend HDNET\Calendarize\Controller\AbstractController but the default AbstractController of Extbase, then you will need to implement all required logic yourself.

Or you just use a different name for your injection method:

use HDNET\Calendarize\Controller\AbstractController;
use MyNamespace\MyExtension\Domain\Repository\IndexRepository;

class MyController extends AbstractController
{

...

    /**
    * The index repository.
    *
    * @var IndexRepository
    */
    protected $myIndexRepository;

    /**
    * Inject index repository.
    *
    * @param IndexRepository $myIndexRepository
    */
    public function injectMyIndexRepository(IndexRepository $myIndexRepository)
    {
        $this->myIndexRepository = $myIndexRepository;
    }

...

class IndexRepository extends \HDNET\Calendarize\Domain\Repository\IndexRepository
{

...

    // My method that extends \HDNET\Calendarize\Domain\Repository\IndexRepository functionalities
    public function findByStartDate(DateTime $startDate = null, DateTime $endDate = null)
    {

...

The method name does not really matter, only that it starts with inject and has a type hint indicating the dependency to inject.