Skip to content

Commit

Permalink
Intial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroTroller committed Feb 19, 2016
0 parents commit 53cb59a
Show file tree
Hide file tree
Showing 10 changed files with 375 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/vendor
/bin
composer.lock
21 changes: 21 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

$finder = Symfony\CS\Finder\DefaultFinder::create()
->in(__DIR__)
->exclude('vendor')
;

return Symfony\CS\Config\Config::create()
->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL)
->fixers([
'align_double_arrow',
'align_equals',
'concat_with_spaces',
'logical_not_operators_with_spaces',
'long_array_syntax',
'newline_after_open_tag',
'ordered_use',
'phpdoc_order',
])
->finder($finder)
;
18 changes: 18 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
language: php

php:
- 5.5
- 5.6
- 7

env:
- COMPOSER_PREFER=--prefer-lowest
- COMPOSER_PREFER=--prefer-stable

before_script:
- phpenv config-rm xdebug.ini
- composer update --dev $COMPOSER_PREFER

script:
- bin/symfony-integration-checker check -vvv
- bin/php-cs-fixer --diff --dry-run -v fix
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#SYMFONY Integration Checker


30 changes: 30 additions & 0 deletions bin/symfony-integration-checker
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env php
<?php

function includeIfExists($file)
{
return file_exists($file) ? include $file : null;
}

$autoloads = array(
sprintf('%s/../../../autoload.php', __DIR__),
sprintf('%s/../vendor/autoload.php', __DIR__),
sprintf('%s/../autoload.php', __DIR__),
);

$loaded = false;

foreach ($autoloads as $autoload) {
$loaded = null === includeIfExists($autoload) ? $loaded : true;

if (true === $loaded) {
break;
}
}

if (false === $loaded) {
throw new \Exception('Can\'t find autoload');
}

$application = new Pedrotroller\Symfony\IntegrationChecker\Application;
$application->run();
33 changes: 33 additions & 0 deletions checker_bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Pedrotroller\Symfony\IntegrationChecker\ConfigurableKernel;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Translation\TranslatorInterface;

$config = array(
'framework' => array(
'translator' => array(
'enabled' => true,
),
),
);

$test = function (KernelInterface $kernel) {
if (false === $kernel->getContainer()->get('translator') instanceof TranslatorInterface) {
throw new \Exception('Oups, there is a problem !');
}
};

return function (ConfigurableKernel $kernel) use ($config, $test) {
$container = new ContainerBuilder();
$container->setParameter('kernel.secret', md5(time()));

$kernel
->setContainerBuilder($container)
->setConfig($config)
->addBundle(new FrameworkBundle())
->afterBoot($test)
;
};
27 changes: 27 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "pedrotroller/symfony-integration-checker",
"authors": [
{
"name": "Pierre PLAZANET",
"email": "[email protected]"
}
],
"require": {
"symfony/config": "~2.3|~3.0",
"symfony/dependency-injection": "~2.3|~3.0",
"symfony/http-kernel": "~2.3|~3.0"
},
"require-dev": {
"fabpot/php-cs-fixer": "~1.11.0",
"symfony/framework-bundle": "~2.3|~3.0"
},
"autoload": {
"psr-0": { "Pedrotroller\\Symfony\\IntegrationChecker": "src/" }
},
"config": {
"bin-dir": "bin"
},
"bin": [
"bin/symfony-integration-checker"
]
}
37 changes: 37 additions & 0 deletions src/Pedrotroller/Symfony/IntegrationChecker/Application.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Pedrotroller\Symfony\IntegrationChecker;

use Pedrotroller\Symfony\IntegrationChecker\Command\CheckCommand;
use Symfony\Component\Console\Application as BaseApplication;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\OutputInterface;

class Application extends BaseApplication
{
/**
* {@inheritdoc}
*/
public function run(InputInterface $input = null, OutputInterface $output = null)
{
$input = null !== $input ? $input : new ArgvInput();
$output = null !== $output ? $output : new ConsoleOutput();

$this->add(new CheckCommand());

$this->configureIO($input, $output);

parent::run($input, $output);
}

/**
* {@inheritdoc}
*/
protected function getDefaultHelperSet()
{
return new HelperSet(array());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

namespace Pedrotroller\Symfony\IntegrationChecker\Command;

use Pedrotroller\Symfony\IntegrationChecker\ConfigurableKernel;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class CheckCommand extends Command
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('check')
->addArgument('bootstrap_file', InputArgument::OPTIONAL, 'The kernel initialisation file.', $this->getDefaultBootstrapFilename())
->addOption('env', 'e', InputOption::VALUE_REQUIRED, 'Symfony environement', 'prod')
;
}

/**
* {@inheritdoc}
*/
public function run(InputInterface $input, OutputInterface $output)
{
$file = $this->getDefaultBootstrapFilename();
$env = 'prod';

if (true === $input->hasOption('env')) {
$env = $input->getOption('env');
}

if (true === $input->hasArgument('bootstrap_file')) {
$file = $input->getArgument('bootstrap_file');
}

if (false === file_exists($file)) {
throw new \Exception(sprintf('Bootstrap file "%s" not found', $file));
}

$kernel = new ConfigurableKernel($env, true);
$callback = require $file;

$callback($kernel);

$output->writeln('<info>Kernel builded</info>');

$kernel->boot();

$output->writeln('<info>Kernel booted</info>');

foreach ($kernel->getAfterBootCallables() as $callable) {
$callable($kernel);
}

$output->writeln('<info>Symfony integration succeeded</info>');
}

/**
* @return string
*/
private function getDefaultBootstrapFilename()
{
return sprintf('%s/checker_bootstrap.php', getcwd());
}
}
132 changes: 132 additions & 0 deletions src/Pedrotroller/Symfony/IntegrationChecker/ConfigurableKernel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?php

namespace Pedrotroller\Symfony\IntegrationChecker;

use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
use Symfony\Component\HttpKernel\Kernel;

class ConfigurableKernel extends Kernel
{
/**
* @var ContainerBuilder
*/
private $containerBuilder;

/**
* @var array
*/
private $config;

/**
* @* @var callable[]
*/
private $afterBoot = array();

/**
* {@inheritdoc}
*/
public function getCacheDir()
{
return sys_get_temp_dir();
}

/**
* {@inheritdoc}
*/
public function getLogDir()
{
return sys_get_temp_dir();
}

/**
* @param BundleInterface $bundle
*
* @return ConfigurableKernel
*/
public function addBundle(BundleInterface $bundle)
{
$this->registeredBundles[] = $bundle;

return $this;
}

/**
* {@inheritdoc}
*/
public function registerBundles()
{
return $this->registeredBundles;
}

/**
* {@inheritdoc}
*/
public function registerContainerConfiguration(LoaderInterface $loader)
{
return $this->getContainerBuilder();
}

/**
* @param ContainerBuilder $containerBuilder
*
* @return ConfigurableKernel
*/
public function setContainerBuilder(ContainerBuilder $containerBuilder)
{
$this->containerBuilder = $containerBuilder;

return $this;
}

/**
* @param callable $callable
*
* @return ConfigurableKernel
*/
public function afterBoot(callable $callable)
{
$this->afterBoot[] = $callable;

return $this;
}

/**
* @return callable[]
*/
public function getAfterBootCallables()
{
return $this->afterBoot;
}

/**
* @param array $config
*
* @return ConfigurableKernel
*/
public function setConfig(array $config)
{
$this->config = $config;

return $this;
}

/**
* {@inheritdoc}
*/
protected function getContainerBuilder()
{
if (null === $this->containerBuilder) {
$this->containerBuilder = parent::getContainerBuilder();
} else {
$this->containerBuilder->merge(parent::getContainerBuilder());
}

foreach ($this->config as $extension => $config) {
$this->containerBuilder->prependExtensionConfig($extension, $config);
}

return $this->containerBuilder;
}
}

0 comments on commit 53cb59a

Please sign in to comment.