Skip to content

Zend Framework 2 - Lazy Factory - Kickstarter (for ZF 2.4)

No blabla, just how you do it with zend framework 2.4.

#add following line to your composer.json
"ocramius/proxy-manager": "1.0.*",

composer update

#add following lines to your module.config.php
'lazy_services' => [
    'class_map' => [
        \My\Class::class => \My\Class::class
    ]
],
'service_manager' => [
    'delegators' => [
        \My\Class::class => [
            \Zend\ServiceManager\Proxy\LazyServiceFactory::class
        ]
    ],
    'factories' => [
        \My\Class::class => \My\ClassFactory::class,
        \Zend\ServiceManager\Proxy\LazyServiceFactory::class => \Zend\ServiceManager\Proxy\LazyServiceFactoryFactory::class
    ]
]

Thats it.

Useful links are a gist from a closed issue and somehow an official howto (maybe working with zend framework greater 2.4).

zf-rest - error "title":"Not Found","status":404,"detail":"Entity not found."

I configured the routes as well as the other parts pretty well.
An important step to solving the issue was adding the following configuration section into my project "local.php".


    //this is possible overwritten by the zf-rest module
    'view-manager' => array(
        'display_exceptions' => true,
        'display_not_found_reason' => true
    )

After that, I got back an response with the following content:
{"type":"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html","title":"Not Found","status":404,"detail":"Entity not found."

After adding a lot of debugging statements in the "ZF\Rest\RestController" (search for "Entity not found." ;-)), started understanding the issue.
The answer is pretty clear after all. Whenever you listen on a GET HTTP Method with your listener, you have to return an array with the configured "route_identifier_name" (the entity identifier), otherwise the controller as well as the HAL post processor is not able to successful build the response.

zend framework 2.4 "Zend\ServiceManager\Exception\ServiceNotFoundException: Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for ApplicationConfig"

We had some controller tests in our test cases and the following error was thrown, after we updated to zend framework 2.4.


Zend\ServiceManager\Exception\ServiceNotFoundException: Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for ApplicationConfig

/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:555
/vendor/zendframework/zendframework/library/Zend/Mvc/Service/ModuleManagerFactory.php:41
/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:939
/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:1097
/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:638
/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:598
/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:530
/vendor/zendframework/zendframework/library/Zend/Mvc/Application.php:253
/vendor/zendframework/zendframework/library/Zend/Test/PHPUnit/Controller/AbstractControllerTestCase.php:164
/vendor/zendframework/zendframework/library/Zend/Test/PHPUnit/Controller/AbstractControllerTestCase.php:73
//MyControllerTest.php:124
"MyControllerTest" extends "Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase". What we did to solve the problem was adding the following lines of code in our "setUp" method.

$applicationConfigurationPath = __DIR__ . str_repeat('/..', ) . '/config/application.config.php';
if (!is_file($applicationConfigurationPath)) {
    $message = 'application configuration needed and not found in path "' . $applicationConfigurationPath . '"';

    $this->fail($message);
}
$applicationConfiguration = require $applicationConfigurationPath;
unset($applicationConfiguration['module_listener_options']['config_glob_paths']);
$applicationConfiguration['modules'] = array();

$this->setApplicationConfig($applicationConfiguration);

Thats it, hope it helps.

New versions of the zend framework 2 console helper family available now

I happy to announce the release of 1.1.0 of bazzlines zend framework 2 console helper (debian backport) module for php as well as the release of 1.1.0 of bazzlines zend framework 2 console helpermodule for php.
Important changes are:

  • added AbstractConsoleControllerFactory