├── .gitignore ├── .scrutinizer.yml ├── .sensiolabs.yml ├── .travis.yml ├── BundleDependency.php ├── BundleDependencyInterface.php ├── DependencyInjection └── Compiler │ └── ExtensionLoadPass.php ├── LICENSE ├── README.md ├── Tests ├── Bundle │ ├── FirstBundle │ │ └── FirstBundle.php │ ├── FourthBundle │ │ └── FourthBundle.php │ ├── SecondBundle │ │ └── SecondBundle.php │ └── ThirdBundle │ │ ├── DependencyInjection │ │ └── ThirdExtension.php │ │ └── ThirdBundle.php ├── BundleTest.php ├── Fixtures │ └── app │ │ ├── AppKernel.php │ │ └── config │ │ └── config_test.yml ├── Kernel.php ├── TestCase.php └── TraitTest.php ├── composer.json └── phpunit.xml.dist /.gitignore: -------------------------------------------------------------------------------- 1 | vendor/ 2 | composer.lock 3 | -------------------------------------------------------------------------------- /.scrutinizer.yml: -------------------------------------------------------------------------------- 1 | filter: 2 | excluded_paths: 3 | - vendor/* 4 | - Tests/* 5 | 6 | checks: 7 | php: 8 | code_rating: true 9 | duplication: true 10 | 11 | build: 12 | tests: 13 | override: 14 | - 15 | command: ./vendor/bin/phpunit --coverage-clover ./clover.xml 16 | coverage: 17 | file: clover.xml 18 | format: clover 19 | -------------------------------------------------------------------------------- /.sensiolabs.yml: -------------------------------------------------------------------------------- 1 | ignore_branches: 2 | - gh-pages 3 | 4 | global_exclude_dirs: 5 | - vendor 6 | - Tests 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | sudo: false 3 | 4 | php: 5 | - 5.6 6 | - 7.0 7 | - 7.1 8 | - 7.2 9 | - hhvm 10 | 11 | env: 12 | - SYMFONY_VERSION=2.7.* 13 | - SYMFONY_VERSION=2.8.* 14 | - SYMFONY_VERSION=3.0.* 15 | - SYMFONY_VERSION=3.1.* 16 | - SYMFONY_VERSION=3.2.* 17 | - SYMFONY_VERSION=3.3.* 18 | 19 | cache: 20 | directories: 21 | - $HOME/.composer/cache 22 | 23 | before_install: 24 | - if [ "$TRAVIS_PHP_VERSION" != "hhvm" ] && [ "$TRAVIS_PHP_VERSION" < "7.1" ]; then phpenv config-rm xdebug.ini; fi 25 | - if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then phpenv rehash; fi; 26 | - composer self-update 27 | - if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/symfony:${SYMFONY_VERSION}" --no-update; fi; 28 | 29 | install: 30 | - composer install 31 | 32 | script: 33 | - ./vendor/bin/phpunit 34 | -------------------------------------------------------------------------------- /BundleDependency.php: -------------------------------------------------------------------------------- 1 | registerBundleDependencies($container); 31 | } 32 | 33 | /** 34 | * Register the bundle dependencies. 35 | * 36 | * @param ContainerBuilder $container 37 | */ 38 | protected function registerBundleDependencies(ContainerBuilder $container) 39 | { 40 | if (true === $this->booted) { 41 | return; 42 | } 43 | 44 | $this->bundles = $container->getParameter('kernel.bundles'); 45 | 46 | if ($this->createBundles($this->getBundleDependencies())) { 47 | $container->setParameter('kernel.bundles', $this->bundles); 48 | 49 | $this->initializeBundles($container); 50 | 51 | $pass = new Compiler\ExtensionLoadPass($this->instances); 52 | 53 | $container->addCompilerPass($pass); 54 | } 55 | 56 | $this->booted = true; 57 | } 58 | 59 | /** 60 | * Creating the instances of bundle dependencies. 61 | * 62 | * @param array $dependencies 63 | * 64 | * @return bool Has new instances or not. 65 | */ 66 | protected function createBundles(array $dependencies) 67 | { 68 | foreach ($dependencies as $bundleClass) { 69 | $name = substr($bundleClass, strrpos($bundleClass, '\\') + 1); 70 | 71 | if (false === isset($this->bundles[$name])) { 72 | $bundle = new $bundleClass(); 73 | $this->bundles[$name] = $bundleClass; 74 | $this->instances[$name] = $bundle; 75 | 76 | if ($bundle instanceof BundleDependencyInterface) { 77 | $this->createBundles($bundle->getBundleDependencies()); 78 | } 79 | } 80 | } 81 | 82 | return count($this->instances) > 0; 83 | } 84 | 85 | /** 86 | * @param ContainerBuilder $container 87 | */ 88 | protected function initializeBundles(ContainerBuilder $container) 89 | { 90 | foreach ($this->instances as $bundle) { 91 | if ($extension = $bundle->getContainerExtension()) { 92 | $container->registerExtension($extension); 93 | } 94 | 95 | $bundle->build($container); 96 | } 97 | 98 | foreach ($this->instances as $bundle) { 99 | $bundle->setContainer($container); 100 | $bundle->boot(); 101 | } 102 | } 103 | 104 | /** 105 | * {@inheritdoc} 106 | */ 107 | abstract public function getBundleDependencies(); 108 | } 109 | -------------------------------------------------------------------------------- /BundleDependencyInterface.php: -------------------------------------------------------------------------------- 1 | bundles = $bundles; 22 | } 23 | 24 | /** 25 | * {@inheritdoc} 26 | */ 27 | public function process(ContainerBuilder $container) 28 | { 29 | foreach ($this->bundles as $bundle) { 30 | if ($extension = $bundle->getContainerExtension()) { 31 | $this->loadExtension($extension, $container); 32 | } 33 | } 34 | } 35 | 36 | /** 37 | * @param Extension $extension 38 | * @param ContainerBuilder $container 39 | */ 40 | private function loadExtension(Extension $extension, ContainerBuilder $container) 41 | { 42 | if (!$container->getExtensionConfig($extension->getAlias())) { 43 | $extension->load([], $container); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016-2017 Symfony Bundles (Dmitry Khaperets) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Symfony BundleDependency Component 2 | ================================== 3 | 4 | [![SensioLabsInsight][sensiolabs-insight-image]][sensiolabs-insight-link] 5 | 6 | [![Build Status][testing-image]][testing-link] 7 | [![Scrutinizer Code Quality][scrutinizer-code-quality-image]][scrutinizer-code-quality-link] 8 | [![Code Coverage][code-coverage-image]][code-coverage-link] 9 | [![Total Downloads][downloads-image]][package-link] 10 | [![Latest Stable Version][stable-image]][package-link] 11 | [![License][license-image]][license-link] 12 | 13 | Installation 14 | ------------ 15 | Pretty simple with Composer, run: 16 | 17 | ``` bash 18 | composer require symfony-bundles/bundle-dependency 19 | ``` 20 | 21 | How to use 22 | ---------- 23 | * Add to your composer.json the bundle dependencies 24 | * Update your composer dependencies with command `composer update` 25 | * Modify your Bundle Class. For example: 26 | 27 | ``` php 28 | use Symfony\Component\HttpKernel\Bundle\Bundle; 29 | use SymfonyBundles\BundleDependency\BundleDependency; 30 | use SymfonyBundles\BundleDependency\BundleDependencyInterface; 31 | 32 | class MyBundle extends Bundle implements BundleDependencyInterface 33 | { 34 | use BundleDependency; 35 | 36 | public function getBundleDependencies() 37 | { 38 | return [ 39 | 'FOS\RestBundle\FOSRestBundle', 40 | 'SymfonyBundles\ForkBundle\SymfonyBundlesForkBundle', 41 | 'SymfonyBundles\RedisBundle\SymfonyBundlesRedisBundle', 42 | ]; 43 | } 44 | } 45 | ``` 46 | 47 | If you want override a method `build`, call the method `registerBundleDependencies`. For example: 48 | 49 | ``` php 50 | public function build(ContainerBuilder $container) 51 | { 52 | parent::build($container); 53 | // ... 54 | 55 | $this->registerBundleDependencies($container); 56 | } 57 | ``` 58 | 59 | [package-link]: https://packagist.org/packages/symfony-bundles/bundle-dependency 60 | [license-link]: https://github.com/symfony-bundles/bundle-dependency/blob/master/LICENSE 61 | [license-image]: https://poser.pugx.org/symfony-bundles/bundle-dependency/license 62 | [testing-link]: https://travis-ci.org/symfony-bundles/bundle-dependency 63 | [testing-image]: https://travis-ci.org/symfony-bundles/bundle-dependency.svg?branch=master 64 | [stable-image]: https://poser.pugx.org/symfony-bundles/bundle-dependency/v/stable 65 | [downloads-image]: https://poser.pugx.org/symfony-bundles/bundle-dependency/downloads 66 | [sensiolabs-insight-link]: https://insight.sensiolabs.com/projects/f3d1e9cc-8a94-4d0c-97c4-a488490e4f72 67 | [sensiolabs-insight-image]: https://insight.sensiolabs.com/projects/f3d1e9cc-8a94-4d0c-97c4-a488490e4f72/big.png 68 | [code-coverage-link]: https://scrutinizer-ci.com/g/symfony-bundles/bundle-dependency/?branch=master 69 | [code-coverage-image]: https://scrutinizer-ci.com/g/symfony-bundles/bundle-dependency/badges/coverage.png?b=master 70 | [scrutinizer-code-quality-link]: https://scrutinizer-ci.com/g/symfony-bundles/bundle-dependency/?branch=master 71 | [scrutinizer-code-quality-image]: https://scrutinizer-ci.com/g/symfony-bundles/bundle-dependency/badges/quality-score.png?b=master 72 | -------------------------------------------------------------------------------- /Tests/Bundle/FirstBundle/FirstBundle.php: -------------------------------------------------------------------------------- 1 | registerBundleDependencies($container); 17 | $this->registerBundleDependencies($container); 18 | } 19 | 20 | public function getContainerExtension() 21 | { 22 | return new DependencyInjection\ThirdExtension(); 23 | } 24 | 25 | public function getBundleDependencies() 26 | { 27 | return [ 28 | \SymfonyBundles\BundleDependency\Tests\Bundle\FourthBundle\FourthBundle::class, 29 | ]; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Tests/BundleTest.php: -------------------------------------------------------------------------------- 1 | container->getParameter('kernel.bundles'); 10 | 11 | $this->assertArrayHasKey('FirstBundle', $bundles); 12 | $this->assertArrayHasKey('SecondBundle', $bundles); 13 | $this->assertArrayHasKey('ThirdBundle', $bundles); 14 | $this->assertArrayHasKey('FourthBundle', $bundles); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Tests/Fixtures/app/AppKernel.php: -------------------------------------------------------------------------------- 1 | remove($this->getCacheDir()); 16 | } 17 | 18 | public function registerBundles() 19 | { 20 | $bundles = [ 21 | new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(), 22 | new \SymfonyBundles\BundleDependency\Tests\Bundle\FirstBundle\FirstBundle(), 23 | ]; 24 | 25 | return $bundles; 26 | } 27 | 28 | public function getRootDir() 29 | { 30 | return __DIR__; 31 | } 32 | 33 | public function getCacheDir() 34 | { 35 | return '/tmp/symfony-cache'; 36 | } 37 | 38 | public function getLogDir() 39 | { 40 | return '/tmp/symfony-cache'; 41 | } 42 | 43 | public function registerContainerConfiguration(LoaderInterface $loader) 44 | { 45 | $loader->load($this->getRootDir() . '/config/config_test.yml'); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Tests/Fixtures/app/config/config_test.yml: -------------------------------------------------------------------------------- 1 | framework: 2 | test: ~ 3 | secret: test 4 | -------------------------------------------------------------------------------- /Tests/Kernel.php: -------------------------------------------------------------------------------- 1 | boot(); 21 | } 22 | 23 | return static::$instance; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Tests/TestCase.php: -------------------------------------------------------------------------------- 1 | container = Kernel::make()->getContainer(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Tests/TraitTest.php: -------------------------------------------------------------------------------- 1 | assertCount(1, $this->getBundleDependencies()); 14 | } 15 | 16 | public function getBundleDependencies() 17 | { 18 | return [ 19 | Bundle\FirstBundle\FirstBundle::class, 20 | ]; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "symfony-bundles/bundle-dependency", 3 | "type": "library", 4 | "description": "Symfony BundleDependency Component", 5 | "keywords": ["bundle", "dependency", "dependencies", "symfony"], 6 | "homepage": "https://github.com/symfony-bundles/bundle-dependency", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Dmitry Khaperets", 11 | "email": "khaperets@gmail.com" 12 | } 13 | ], 14 | "autoload": { 15 | "psr-4": { 16 | "SymfonyBundles\\BundleDependency\\": "" 17 | }, 18 | "exclude-from-classmap": [ 19 | "/Tests/" 20 | ] 21 | }, 22 | "require": { 23 | "php": ">=5.6" 24 | }, 25 | "require-dev": { 26 | "phpunit/phpunit": "^5.3", 27 | "phpunit/php-code-coverage": "^3.3.0|^4.0", 28 | "symfony/framework-bundle": "~2.7|~3.0", 29 | "doctrine/annotations": "~1.1" 30 | }, 31 | "extra": { 32 | "branch-alias": { 33 | "dev-master": "1.x-dev" 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | ./Tests 16 | 17 | 18 | 19 | 20 | 21 | ./ 22 | 23 | ./Tests 24 | ./vendor 25 | 26 | 27 | 28 | 29 | --------------------------------------------------------------------------------