Last active
January 29, 2018 13:53
-
-
Save bizmate/82b4694d53ac23eac315a032bf41e6a5 to your computer and use it in GitHub Desktop.
No extensions loading in re-usable bundle set up
This file contains hidden or 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 Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; | |
use Symfony\Component\Config\Loader\LoaderInterface; | |
use Symfony\Component\DependencyInjection\ContainerBuilder; | |
use Symfony\Component\HttpKernel\Kernel; | |
use Symfony\Component\Routing\RouteCollectionBuilder; | |
class AppKernel extends Kernel | |
{ | |
use MicroKernelTrait; | |
/** | |
* @return array | |
*/ | |
public function registerBundles() | |
{ | |
return array( | |
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), | |
//new Symfony\Bundle\MonologBundle\MonologBundle(), | |
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), | |
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), | |
new MyReviews\ReviewsBundle\MyReviewsReviewsBundle() | |
); | |
} | |
/** | |
* @return null | |
public function registerContainerConfiguration(LoaderInterface $loader) | |
{ | |
$loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml'); | |
} | |
*/ | |
/** | |
* @return string | |
*/ | |
public function getCacheDir() | |
{ | |
return sys_get_temp_dir().'/MyReviewsReviews/cache'; | |
} | |
/** | |
* @return string | |
*/ | |
public function getLogDir() | |
{ | |
return sys_get_temp_dir().'/MyReviewsReviews/logs'; | |
} | |
/** | |
* @param RouteCollectionBuilder $routes | |
*/ | |
protected function configureRoutes(RouteCollectionBuilder $routes) | |
{ | |
//$routes->import('@ZalasDemoBundle/Controller/', '/', 'annotation'); | |
} | |
/** | |
* @param ContainerBuilder $c | |
* @param LoaderInterface $loader | |
*/ | |
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader) | |
{ | |
//echo "Environment " . $this->environment ; die; | |
// load configurations in app kernel from yml files | |
$confDir = __DIR__ . '/../../Resources/config'; | |
if($this->environment == 'test'){ | |
$loader->load($confDir.'/services_test.yml', 'glob'); | |
} | |
else{ | |
$loader->load($confDir.'/services.yml', 'glob'); | |
} | |
//echo $this->getCacheDir();die; | |
$c->loadFromExtension('framework', [ | |
'secret' => 'my$ecret', | |
'test' => null, | |
//'templating' => ['engines' => ['twig']], | |
'profiler' => [ | |
'collect' => false, | |
], | |
]); | |
// $c->loadFromExtension('monolog', [ | |
// 'handlers' => [ | |
// 'main' => [ | |
// 'type' => 'stream', | |
// 'path' => '%kernel.logs_dir%/%kernel.environment%.log', | |
// 'level' => 'debug', | |
// ], | |
// ], | |
// ]); | |
$c->loadFromExtension('doctrine', [ | |
'dbal' => [ | |
'driver' => 'pdo_mysql', | |
'host' => 'db', | |
'dbname' => 'myreviews_test', | |
'user' => 'root', | |
'password' => 'example' | |
], | |
'orm' => [ | |
'naming_strategy' => 'doctrine.orm.naming_strategy.underscore', | |
'auto_mapping' => true, | |
'mappings' => [ | |
'MyReviewsReviewsBundle' => [ | |
'type' => 'yml', | |
//'dir' => 'Resources/config/doctrine-mapping', | |
'prefix' => 'MyReviews\ReviewsBundle\Service\Review\Entity' | |
] | |
] | |
] | |
]); | |
} | |
} |
This file contains hidden or 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 | |
//DependencyInjection/Configuration.php | |
namespace MyReviews\ReviewsBundle\DependencyInjection; | |
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | |
use Symfony\Component\Config\Definition\ConfigurationInterface; | |
/** | |
* This is the class that validates and merges configuration from your app/config files. | |
* | |
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/configuration.html} | |
*/ | |
class Configuration implements ConfigurationInterface | |
{ | |
/** | |
* {@inheritdoc} | |
*/ | |
public function getConfigTreeBuilder() | |
{ | |
$treeBuilder = new TreeBuilder(); | |
$rootNode = $treeBuilder->root('my_reviews_reviews'); | |
$rootNode | |
->children() | |
->arrayNode('google') | |
->children() | |
->variableNode('places_key')->end() | |
->end() | |
->end() | |
->arrayNode('yelp') | |
->children() | |
->variableNode('key')->end() | |
->end() | |
->end() | |
->arrayNode('cache') | |
->children() | |
->integerNode('expire')->end() | |
->booleanNode('enabled')->end() | |
->end() | |
->end() | |
->end() | |
; | |
// Here you should define the parameters that are allowed to | |
// configure your bundle. See the documentation linked above for | |
// more information on that topic. | |
return $treeBuilder; | |
} | |
} |
This file contains hidden or 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
docker-compose run --rm php bash -c "vendor/bin/behat" | |
WARNING: The UID variable is not set. Defaulting to a blank string. | |
Starting myreviewsreviews_db_1 ... done | |
In YamlFileLoader.php line 701: | |
There is no extension able to load the configuration for "my_reviews_reviews" (in /var/www/html/DependencyInjection/../Resources/config/services.yml). Looked for namespace "my_reviews_reviews", found none | |
Makefile:20: recipe for target 'integration_tests' failed | |
make: *** [integration_tests] Error 1 |
This file contains hidden or 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 | |
//DependencyInjection/MyReviewsReviewsExtension.php | |
namespace MyReviews\ReviewsBundle\DependencyInjection; | |
use Symfony\Component\DependencyInjection\ContainerBuilder; | |
use Symfony\Component\Config\FileLocator; | |
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | |
use Symfony\Component\DependencyInjection\Loader; | |
/** | |
* This is the class that loads and manages your bundle configuration. | |
* | |
* @link http://symfony.com/doc/current/cookbook/bundles/extension.html | |
*/ | |
class MyReviewsReviewsExtension extends Extension | |
{ | |
/** | |
* {@inheritdoc} | |
*/ | |
public function load(array $configs, ContainerBuilder $container) | |
{ | |
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); | |
$loader->load('services.yml'); | |
$configuration = new Configuration(); | |
$config = $this->processConfiguration($configuration, $configs); | |
if(empty($config['yelp']) || empty($config['google'])){ | |
// this is for debugging | |
var_dump($config); | |
$defs = $container->getExtensions(); | |
foreach($defs as $def) | |
{ | |
echo "\n Definition class " . $def->getAlias() . " namespace " . $def->getNamespace(); | |
} | |
// debugging finished | |
throw new \LogicException('MyReviews Reviews - Please provide at least Google and Yelp config/keys.' ); | |
} | |
// https://symfony.com/doc/3.4/bundles/configuration.html | |
$yelpAdapterDef = $container->getDefinition('yelp_adapter'); | |
$yelpAdapterDef->replaceArgument(2, $config['yelp']['key']); | |
$googleAdapterDef = $container->getDefinition('google_adapter'); | |
$googleAdapterDef->replaceArgument(0, $config['google']['places_key']); | |
} | |
} |
This file contains hidden or 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
parameters: | |
myreviews_reviews.google.places_key: '%env(GOOGLE_PLACES_KEY)%' | |
myreviews_reviews.yelp.key: '%env(YELP_FUSION_KEY)%' | |
myreviews_reviews.cache.expire: 604800 # 2 days | |
myreviews_reviews.cache.enabled: true | |
services: | |
_defaults: | |
public: false | |
file_cache: | |
class: Doctrine\Common\Cache\FilesystemCache | |
arguments: [ "%kernel.cache_dir%" ] | |
yelp_adapter: | |
class: MyReviews\ReviewsBundle\Adapter\RealYelpAdapter | |
arguments: | |
- "@file_cache" | |
- "@logger" | |
- "%myreviews_reviews.yelp.key%" | |
- "%myreviews_reviews.yelp.endpoint_url%" | |
- "%myreviews_reviews.yelp.business_path_prefix%" | |
- "%myreviews_reviews.yelp.business_path_suffix%" | |
- "%myreviews_reviews.yelp.search_path%" | |
yelp_transformer: | |
class: MyReviews\ReviewsBundle\Service\Review\Transformer\YelpTransformer | |
yelp_service: | |
class: MyReviews\ReviewsBundle\Service\YelpService | |
arguments: | |
- "@yelp_adapter" | |
- "@yelp_transformer" | |
# continues with other services ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment