# Migration from Zf2

**URL:** <https://discourse.laminas.dev/t/migration-from-zf2/2973>\
**Category:** Migration\
**Created:** [July 25, 2022, 8:06pm UTC](https://discourse.laminas.dev/t/migration-from-zf2/2973 "2022-07-25T20:06:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rajath](https://avatars.discourse-cdn.com/v4/letter/r/13edae/32.png) [@rajath](https://discourse.laminas.dev/u/rajath)\
**Post date:** [July 25, 2022, 8:06pm UTC](https://discourse.laminas.dev/t/migration-from-zf2/2973/1 "2022-07-25T20:06:49Z")

</div>

How to map factories written in the group of service manager in zf2 to laminas. Controller factories are working good

Not working showing path error - "Unable to resolve service “Application\Service\UserServiceInterface” to a factory; are you certain you provided it during configuration?

```auto
    'service_manager' => [
        'abstract_factories' => [
            'Laminas\Cache\Service\StorageCacheAbstractServiceFactory',
            'Laminas\Log\LoggerAbstractServiceFactory',
        ],
        'invokables' => [
        ],
        'aliases' => [
            'translator' => 'MvcTranslator',
        ],
        'factories' => [
            'Application\Service\UserServiceInterface' => 'Application\Factory\UserServiceFactory',
        ],
]

```

Thanks

---

<div class="post-metadata">

**Author:** ![ezkimo](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/ezkimo/32/781_2.png) [@ezkimo](https://discourse.laminas.dev/u/ezkimo)\
**Post date:** [July 26, 2022, 11:05am UTC](https://discourse.laminas.dev/t/migration-from-zf2/2973/2 "2022-07-26T11:05:17Z")

</div>

Are you sure the given factory exists under the given full qualified class name? I suggest using the `::class` keyword instead of strings. Strings tend to be errornous. Current IDEs like PHPStorm or VSCode support code completion when using the `::class` keyword.

```auto
<?php
declare(strict_types=1);
namespace Application;

return [
    'service_manager' => [
        'factories' => [
            // will resolve into fully qualified class names
            // Application\Service\UserServiceInterface and
            // Application\Service\Factory\UserServiceFactory
            Service\UserServiceInterface::class => Service\Factory\UserServiceFactory::class,
        ],
    ],
];

```

Since you 've noted a namespace at the beginning, everything will extend the namespace when not using a backslash at the first position. You can use the `::class` keyword even on classes, that actually don 't exist.

Please check, if the php file is available at `/modules/Application/src/Factory/UserServiceFactory.php`. If the file is available, you can check the class name. Is the class name really `UserServiceFactory`?

Did you check for PSR Service Container? Laminas has changed its behaviour regarding factories. To get lost of the dependency to the old Zend Framework 2 service container, just use the psr service container instead. The psr container should always be your first choice. Please avoid using old service container implementations.

```auto
<?php
declare(strict_types=1);
namespace Application\Factory;

use Application\Foo\SomethingFromTheServiceManager;
use Psr\Container\ContainerInterface;

class UserServiceFactory
{
    public function __invoke(ContainerInterface $container): UserServiceInterface
    {
        $somethingFromTheServiceManager = $container->get(SomethingFromTheServiceManager::class);
        return new UserService($somethingFromTheServiceManager);
    }
}

```

Optionally the `__invoke` method can have the good old `$requestedName` and `$options` parameters. I have simply omitted it for the sake of simplicity.

---

<div class="post-metadata">

**Author:** ![rajath](https://avatars.discourse-cdn.com/v4/letter/r/13edae/32.png) [@rajath](https://discourse.laminas.dev/u/rajath)\
**Post date:** [July 26, 2022, 4:18pm UTC](https://discourse.laminas.dev/t/migration-from-zf2/2973/3 "2022-07-26T16:18:51Z")

</div>

Thanks @ezkimo for the detailed explanations.

When i updated the paths as you suggested it started connecting to the Service and Factory. In Index factory i had made modification with \_\_invoke.
