Skip to content

Commit

Permalink
Initial effort to replace Cilex with Symfony4
Browse files Browse the repository at this point in the history
  • Loading branch information
mvriel committed Jan 15, 2018
1 parent af08976 commit 014d7ba
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 556 deletions.
12 changes: 3 additions & 9 deletions config/packages/framework.yaml
@@ -1,15 +1,9 @@
framework:
secret: '%env(APP_SECRET)%'
#default_locale: en
#csrf_protection: ~
#http_method_override: true

# uncomment this entire section to enable sessions
#session:
# # With this config, PHP's native session handling is used
# handler_id: ~
# needs to be disabled because we currently use a different translator with the same service name
translator:
enabled: false

#esi: ~
#fragments: ~
php_errors:
log: true
20 changes: 0 additions & 20 deletions src/phpDocumentor/Application.php
Expand Up @@ -64,26 +64,6 @@ public function __construct(ContainerInterface $container)
$this->container = $container;
}

/**
* @param null|InputInterface $input
* @param null|OutputInterface $output
* @return mixed
*/
public function run(InputInterface $input = null, OutputInterface $output = null)
{
/** @var ConsoleApplication $app */
$app = $this['console'];
$app->setAutoExit(false);

if ($output === null) {
$output = new Console\Output\Output();
$output->setLogger($this['monolog']);
}

return parent::run(new ArgvInput(), $output);
}


/**
* Adjust php.ini settings.
*
Expand Down
Expand Up @@ -5,6 +5,10 @@
namespace phpDocumentor\Application\CilexCompatibilityLayer;

use phpDocumentor\Application;
use phpDocumentor\Command\Helper\ConfigurationHelper;
use phpDocumentor\Command\Helper\LoggerHelper;
use phpDocumentor\Configuration;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\HttpKernel\Bundle\Bundle;

final class CilexCompatibilityLayerBundle extends Bundle
Expand All @@ -18,6 +22,21 @@ public function boot()

public function registerCommands(\Symfony\Component\Console\Application $application)
{
$application->getHelperSet()->set(new LoggerHelper());
$application->getHelperSet()->set(new ConfigurationHelper(new Configuration()));

$application->getDefinition()->addOption(
new InputOption(
'config',
'c',
InputOption::VALUE_OPTIONAL,
'Location of a custom configuration file'
)
);
$application->getDefinition()->addOption(
new InputOption('log', null, InputOption::VALUE_OPTIONAL, 'Log file to write to')
);

if ($this->container->has('phpdocumentor.compatibility.extra_commands')) {
$commands = $this->container->get('phpdocumentor.compatibility.extra_commands');

Expand Down
19 changes: 19 additions & 0 deletions src/phpDocumentor/Command/Command.php
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Helper\ProgressHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Base command for phpDocumentor commands.
Expand All @@ -42,6 +43,24 @@ public function getService(string $name)
return $this->getContainer()->get($name);
}

/**
* Executes a callable piece of code and writes an entry to the log detailing how long it took.
*/
protected function writeTimedLog(OutputInterface $output, $message, $operation, array $arguments = array())
{
$output->write(sprintf('%-66.66s .. ', $message));
$timerStart = microtime(true);

call_user_func_array($operation, $arguments);

$output->writeln(sprintf('%8.3fs', microtime(true) - $timerStart));
}

public function getService(string $name)
{
return $this->getContainer()->get($name);
}

/**
* Returns the Progress bar helper.
*
Expand Down
2 changes: 1 addition & 1 deletion src/phpDocumentor/Configuration/Loader.php
Expand Up @@ -12,7 +12,7 @@
namespace phpDocumentor\Configuration;

use JMS\Serializer\Serializer;
use phpDocumentor\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\ArgvInput;

/**
* Loads the template and user-defined configuration file from disk and creates a Configuration object from it.
Expand Down
34 changes: 1 addition & 33 deletions src/phpDocumentor/Configuration/ServiceProvider.php
Expand Up @@ -53,47 +53,15 @@ class ServiceProvider implements ServiceProviderInterface
*/
public function register(Container $app)
{
$this->addMerger($app);

// $app->extend(
// 'console',
// function (ConsoleApplication $console) {
// $console->getDefinition()->addOption(
// new InputOption(
// 'config',
// 'c',
// InputOption::VALUE_OPTIONAL,
// 'Location of a custom configuration file'
// )
// );
//
// return $console;
// }
// );

$app['config.path.template'] = __DIR__ . '/Resources/phpdoc.tpl.xml';
$app['config.path.user'] = getcwd()
. ((file_exists(getcwd() . '/phpdoc.xml')) ? '/phpdoc.xml' : '/phpdoc.dist.xml');
$app['config.class'] = 'phpDocumentor\Configuration';

$app['config'] = function ($app) {
$loader = new Loader($app['serializer'], $app['config.merger']);
$loader = new Loader($app['serializer'], new Merger(new AnnotationReader()));

return $loader->load($app['config.path.template'], $app['config.path.user'], $app['config.class']);
};
}

/**
* Initializes and adds the configuration merger object as the 'config.merger' service to the container.
*
* @param Application $container
*
* @return void
*/
private function addMerger(Application $container)
{
$container['config.merger'] = function () {
return new Merger(new AnnotationReader());
};
}
}
53 changes: 0 additions & 53 deletions src/phpDocumentor/Console/Input/ArgvInput.php

This file was deleted.

85 changes: 0 additions & 85 deletions src/phpDocumentor/Console/Output/Output.php

This file was deleted.

Expand Up @@ -31,7 +31,6 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;
use Zend\Cache\Storage\StorageInterface;
use Zend\Stdlib\AbstractOptions;

/**
* Transforms the structure file into the specified output format
Expand Down Expand Up @@ -185,16 +184,18 @@ protected function execute(InputInterface $input, OutputInterface $output)

$projectDescriptor = $this->getBuilder()->getProjectDescriptor();
$mapper = new ProjectDescriptorMapper($this->getCache());
$output->writeTimedLog('Load cache', array($mapper, 'populate'), array($projectDescriptor));
$this->writeTimedLog($output,'Load cache', array($mapper, 'populate'), array($projectDescriptor));

foreach ($this->getTemplates($input) as $template) {
$output->writeTimedLog(
$this->writeTimedLog(
$output,
'Preparing template "'. $template .'"',
array($transformer->getTemplates(), 'load'),
array($template, $transformer)
);
}
$output->writeTimedLog(
$this->writeTimedLog(
$output,
'Preparing ' . count($transformer->getTemplates()->getTransformations()) . ' transformations',
array($this, 'loadTransformations'),
array($transformer)
Expand All @@ -206,7 +207,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

/** @var CompilerPassInterface $pass */
foreach ($this->compiler as $pass) {
$output->writeTimedLog($pass->getDescription(), array($pass, 'execute'), array($projectDescriptor));
$this->writeTimedLog($output, $pass->getDescription(), array($pass, 'execute'), array($projectDescriptor));
}

if ($progress) {
Expand All @@ -223,7 +224,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
*/
protected function getCache()
{
return $this->getContainer()->offsetGet('descriptor.cache');
return $this->getContainer()->get('descriptor.cache');
}

/**
Expand Down

0 comments on commit 014d7ba

Please sign in to comment.