I have just started using PHP-DI
and it is awesome, however I cannot manage to solve one issue.
Here is my services definitions
<?php
return [
'services.report'=> DI\autowire( '\CRM\Report\Service\ReportService' ),
'\CRM\Report\Service\ReportServiceContract' => DI\get ( 'services.report' )
];
And my class defined as follows
class ReportService implements ReportServiceContract {
private $repository;
/**
* ReportService constructor.
* @Inject("repositories.report_tasks")
*
* @param $repository
*/
public function __construct( $repository ) {
$this->repository = $repository;
var_dump( $this->repository->getReportTaskById( 1 )->getDateSubmitted() );
}
}
Having that configuration I am getting the following error
Entry "services.report" cannot be resolved: Parameter $repository of __construct() has no value defined or guessable Full definition: Object ( class = \CRM\Report\Service\ReportService lazy = false __construct( $repository = #UNDEFINED# ) )
I have tried to debug sources, and noticed that even an AnnotationReader
instance is not created.
But when using the following definition
<?php
return [
'services.report' => DI\autowire( '\CRM\Report\Service\ReportService' )->constructorParameter('repository',DI\get('repositories.report_tasks')),
'\CRM\Report\Service\ReportServiceContract' => DI\get ( 'services.report' )
];
Everything works fine.
What is wrong with my configuration ?