Created
March 11, 2018 21:34
-
-
Save heiglandreas/dc9ed23f4ec3bbb997fd1bb4726080c1 to your computer and use it in GitHub Desktop.
Problems with extending Disco-Annotations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use \bitExpert\Disco\BeanFactoryConfiguration; | |
use \bitExpert\Disco\AnnotationBeanFactory; | |
use \bitExpert\Disco\BeanFactoryRegistry; | |
// Load configuration | |
$config = require __DIR__ . '/config.php'; | |
$config['di']['class'] = GlobalDependencies::class; | |
if (APPLICATION_ENVIRONMENT === 'development') { | |
$config['di']['class'] = DevelopmentDependencies::class; | |
} | |
$beanConfig = new BeanFactoryConfiguration($config['di']['cache']); | |
/** @var \Interop\Container\ContainerInterface $container */ | |
$beanFactory = new AnnotationBeanFactory( | |
$config['di']['class'], | |
['expressive' => $config], | |
$beanConfig); | |
BeanFactoryRegistry::register($beanFactory); | |
return $beanFactory; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Class DevelopmentDependencies | |
* | |
* @Configuration | |
*/ | |
class DevelopmentDependencies extends GlobalDependencies | |
{ | |
/** | |
* Middleware\ErrorResponseGenerator::class => Container\ErrorResponseGeneratorFactory::class, | |
* | |
* @Bean({"aliases" = {@Alias({"name" = "Zend\Expressive\Middleware\ErrorResponseGenerator"})}}) | |
*/ | |
public function getWhoopsErrorResponseGenerator() : WhoopsErrorResponseGenerator | |
{ | |
return (new WhoopsErrorResponseGeneratorFactory())($this->getBeanFactory()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @Configuration | |
*/ | |
class GlobalDependencies | |
{ | |
use ApiSlice; | |
/** | |
* Middleware\ErrorResponseGenerator::class => Container\ErrorResponseGeneratorFactory::class, | |
* | |
* @Bean({"aliases" = {@Alias({"name" = "Zend\Expressive\Middleware\ErrorResponseGenerator"})}}) | |
*/ | |
public function getZendExpressiveMiddlewareErrorResponseGenerator() : ErrorResponseGenerator | |
{ | |
return (new ErrorResponseGeneratorFactory())($this->getBeanFactory()); | |
} | |
/** | |
* @return ContainerInterface | |
*/ | |
protected function getBeanFactory() : ContainerInterface | |
{ | |
return BeanFactoryRegistry::getInstance(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment