Reputation: 608
I'm lost with this problem...
I have a module Tables with a factory for my final class "Entreprise"
so in module/Tables/config/module.config.php
<?php
namespace \Tables\Service\Factory;
use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Tables\Service\Entreprise;
class EntrepriseFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
DIE('FACTORY ENTREPRISE NOT REACHED ... :-( ');
$entreprise = new Entreprise();
return $enteprise;
}
}
module/Tables/Modules.php
<?php
namespace Tables;
class Module
{
public function getServiceConfig()
{
return [
'factories' => [
'EntrepriseTableGateway' => function ($sm)
{
...
...
$e=$sm->get(\Service\Entreprise::class);
// Here is the problem
// \Service\Entreprise is resolved
// as Tables\Service\Factory\EntrepriseFactory as expected
// but Tables\Service\Factory\EntrepriseFactory is not found...
here is the factory flow
----module/Tables/src/Tables/Service
contains Entreprise.php (but the problem is not here at this time)
----/module/Tables/config/module.config.php
<?php
return array(
'service_manager' => [
// the resolution works...
// but the final class is not found...
'invokables' => [
Service\Entreprise::class => \Tables\Service\Factory\EntrepriseFactory::class,
]
]
);
module/Tables/src/Tables/Service/Factory.php
<?php
namespace \Tables\Service\Factory;
use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Tables\Service\Entreprise;
class EntrepriseFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
DIE('FACTORY ENTREPRISE NOT REACHED !!!');
$entreprise = new Entreprise();
return $entreprise;
}
}
in composer.json
(composer dump-autoload done)
...
"autoload": {
"psr-4": {
"Application\\": "module/Application/src/",
"Tfirst\\": "module/Tfirst/src/",
"Tables\\": "module/Tables/src/"
}
},
...
and in root config in SERVER/config/modules.config.php
...
return [
'Laminas\Db',
'Laminas\Di',
'Laminas\Mvc\Plugin\FilePrg',
'Laminas\Mvc\Plugin\FlashMessenger',
'Laminas\Mvc\Plugin\Identity',
'Laminas\Mvc\Plugin\Prg',
'Laminas\Session',
'Laminas\Mvc\I18n',
'Laminas\Mvc\Console',
'Laminas\Form',
'Laminas\Hydrator',
'Laminas\InputFilter',
'Laminas\Filter',
'Laminas\I18n',
'Laminas\Cache',
'Laminas\Router',
'Laminas\Validator',
'Application',
'Tables',
'Tfirst',
......
And the error dump
Error
File:
/home/vagrant/Code/yeting/SERVER/vendor/laminas/laminas-servicemanager/src/Factory/InvokableFactory.php:31
Message:
Class 'Tables\Service\Factory\EntrepriseFactory' not found
Stack trace:
#0 /home/vagrant/Code/yeting/SERVER/vendor/laminas/laminas-servicemanager/src/ServiceManager.php(765): Laminas\ServiceManager\Factory\InvokableFactory->__invoke()
#1 /home/vagrant/Code/yeting/SERVER/vendor/laminas/laminas-servicemanager/src/ServiceManager.php(201): Laminas\ServiceManager\ServiceManager->doCreate()
#2 /home/vagrant/Code/yeting/SERVER/module/Tables/src/Module.php(246): Laminas\ServiceManager\ServiceManager->get()
... any advice ?
Upvotes: 1
Views: 2264
Reputation: 608
ok... I found my mistake...
Actually, I mixed old school zend 2 directory structure with new Zend 3 tutorial (and now Laminas) , so the namespaces were wrong.
before correction : My structure directory was:
(ie for model : ) modules/Tables/src/Tables/Model
the new structure is
(ie for model : ) modules/Tables/src/Model
idem for Factory, etc...
There are always errors, but that's another problem ...
I close the question.
Upvotes: 1