php-di / zf2-bridge Goto Github PK
View Code? Open in Web Editor NEWPHP-DI integration with Zend Framework 2
License: MIT License
PHP-DI integration with Zend Framework 2
License: MIT License
Is the quickstart up to date? Is it useful? Does it make sense to keep it or remove it?
Hi Matthieu,
Could you please give a hint why PHP-DI can be not working for me in integration with Zend2 (reproduced with Apache/2.4.9 (Win64) PHP/5.5.12 and Apache/2.2.22 (Win32) PHP/5.3.13).
composer.json
{
"require": {
"php": ">=5.3.3",
"zendframework/zendframework": "2.3.5",
"mnapoli/php-di": "4.4.6",
"mnapoli/php-di-zf2": "0.3.0",
...
},
"autoload": {
"classmap": [
...
],
"psr-0": {
"Morpho": "module/Morpho/src",
"phpMorphy": "vendor/makhov/phpmorphy/src/common.php"
}
}
}
module/Morpho/config.module.config.php:
<?php
return array(
'modules' => array(
'DI\ZendFramework2',
),
'router' => array(
...
),
),
'controllers' => array(
...
),
'view_manager' => array(
...
),
'service_manager' => array(
'factories' => array(
'DI\Container' => function() {
$builder = new DI\ContainerBuilder();
$builder->addDefinitionsFromFile("config/di.yml");
return $builder->build();
},
),
),
);
config/di.yml:
Morpho\Service\PartOfSpeechService:
class: Morpho\Service\PhpMorphyPartOfSpeechService
module/Morpho/src/Morpho/Controller/PartOfSpeechController:
class PartOfSpeechController extends AbstractRestfulController {
...
/**
* @Inject
*
* @var PartOfSpeechService
*/
public $partOfSpeechService;
public function processPostData(Request $request) {
$partsOfSpeech = $this->partOfSpeechService->getPartsOfSpeech("test", "en_EN");
return new JsonModel($partsOfSpeech);
}
When running this code under apache each time I get:
PHP Fatal error: Call to a member function getPartsOfSpeech() on a
non-object in \module\Morpho\src\Morpho\Controller\PartOfSpeechController.php on line 34
The injection is working normally if obtain the controller object using container but not under Zend2 MVC.
Any your thoughts would be really appreciated.
When i try to to use error occured:
Fatal error: Class DI\ZendFramework2\Service\PHPDIAbstractFactory contains 2 abstract methods and must therefore be declared abstract or implement the remaining methods (Zend\ServiceManager\Factory\AbstractFactoryInterface::canCreate, Zend\ServiceManager\Factory\FactoryInterface::__invoke) in /home/sohorev/workspace/multivpn-php/vendor/php-di/zf2-bridge/src/DI/ZendFramework2/Service/PHPDIAbstractFactory.php on line 23
In README
If you're using Memcached, you should have only one project per memcached instance.
But i can use namespace:
return [
'phpdi-zf2' => [
'cache' => [
'adapter' => 'memcached',
'host' => 'localhost', // default is localhost
'port' => 11211, // default is 11211
'namespace' => 'my_second_project_',
],
]
];
$builder->wrapContainer($serviceManager);
This means the service manager must implement DI\ContainerInterface, or we can wait for container-interop 1.0.
Hi
DI\ZendFramework2\Service\Cache\CacheFactory
in createService()
method can return null, but ZF2 ServiceLocator does not allow this behaviour - you'll get this :
\Zend\ServiceManager\ServiceManager @ 953
if ($instance === null) {
throw new Exception\ServiceNotCreatedException('The factory was called but did not return an instance.');
}
ZF2 version Im using is current stable ("zendframework/zendframework": "~2.5").
Proposed fixes :
Add some 'BlackholeCache' as default service returned via DiCache factory
Or simple, but a little nasty - catch and handle ServiceNotCreatedException
Current integration could be improved.
A way (suggested by Ocramius) is to use an abstract factory.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.