Skip to content

Commit

Permalink
Merge pull request #221 from greg0ire/drop_old_versions
Browse files Browse the repository at this point in the history
Drop old versions
  • Loading branch information
core23 authored Dec 16, 2016
2 parents f66993a + a42885b commit 87d8ee1
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 168 deletions.
2 changes: 1 addition & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function getConfigTreeBuilder()

$rootNode
->children()
->scalarNode('default_formatter')->end() // NEXT_MAJOR: make this required
->scalarNode('default_formatter')->isRequired()->cannotBeEmpty()->end()
->arrayNode('formatters')
->useAttributeAsKey('name')
->prototype('array')
Expand Down
24 changes: 11 additions & 13 deletions DependencyInjection/SonataFormatterExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,12 @@ public function load(array $configs, ContainerBuilder $container)
$loader->load('ckeditor.xml');
}

// NEXT_MAJOR: remove this if block
if (!isset($config['default_formatter'])) {
@trigger_error(
'Not setting the default_formatter configuration node is deprecated since 3.x,'.
' and will no longer be supported in 4.0.',
E_USER_DEPRECATED
);
reset($config['formatters']);
$config['default_formatter'] = key($config['formatters']);
}

if (!array_key_exists($config['default_formatter'], $config['formatters'])) {
throw new \InvalidArgumentException(sprintf('SonataFormatterBundle - Invalid default formatter : %s, available : %s', $config['default_formatter'], json_encode(array_keys($config['formatters']))));
throw new \InvalidArgumentException(sprintf(
'SonataFormatterBundle - Invalid default formatter: %s, available: %s',
$config['default_formatter'],
json_encode(array_keys($config['formatters']))
));
}

$pool = $container->getDefinition('sonata.formatter.pool');
Expand All @@ -78,7 +71,12 @@ public function load(array $configs, ContainerBuilder $container)
if (count($configuration['extensions']) == 0) {
$env = null;
} else {
$env = new Reference($this->createEnvironment($container, $code, $container->getDefinition($configuration['service']), $configuration['extensions']));
$env = new Reference($this->createEnvironment(
$container,
$code,
$container->getDefinition($configuration['service']),
$configuration['extensions']
));
}

$pool->addMethodCall('add', array($code, new Reference($configuration['service']), $env));
Expand Down
14 changes: 1 addition & 13 deletions Form/Type/FormatterType.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Translation\TranslatorInterface;

class FormatterType extends AbstractType
Expand Down Expand Up @@ -174,16 +173,6 @@ public function buildView(FormView $view, FormInterface $form, array $options)
$view->vars['source_id'] = str_replace($view->vars['name'], $view->vars['source_field'], $view->vars['id']);
}

/**
* NEXT_MAJOR: Remove this method when dropping support for symfony 2.*.
*
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$this->configureOptions($resolver);
}

/**
* {@inheritdoc}
*/
Expand All @@ -201,8 +190,7 @@ public function configureOptions(OptionsResolver $resolver)
'choices' => $formatters,
);

// NEXT_MAJOR: Remove the method_exists hack when dropping support for symfony < 2.7
if (count($formatters) > 1 && method_exists('Symfony\Component\Form\AbstractType', 'configureOptions')) {
if (count($formatters) > 1) {
$formatFieldOptions['choice_translation_domain'] = false;
}

Expand Down
16 changes: 1 addition & 15 deletions Form/Type/SimpleFormatterType.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class SimpleFormatterType extends AbstractType
{
Expand Down Expand Up @@ -101,25 +100,12 @@ public function configureOptions(OptionsResolver $resolver)
));
}

/**
* For Symfony <= 2.8.
*
* @param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$this->configureOptions($resolver);
}

/**
* {@inheritdoc}
*/
public function getParent()
{
// NEXT_MAJOR: Remove ternary (when requirement of Symfony is >= 2.8)
return method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')
? 'Symfony\Component\Form\Extension\Core\Type\TextareaType'
: 'textarea';
return 'Symfony\Component\Form\Extension\Core\Type\TextareaType';
}

/**
Expand Down
67 changes: 7 additions & 60 deletions Formatter/Pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@
namespace Sonata\FormatterBundle\Formatter;

use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\NullLogger;
use Twig_Environment;
use Twig_Error_Syntax;
use Twig_Sandbox_SecurityError;

class Pool implements LoggerAwareInterface
{
use LoggerAwareTrait;

/**
* @var array
*/
Expand All @@ -31,60 +33,12 @@ class Pool implements LoggerAwareInterface
protected $defaultFormatter;

/**
* NEXT_MAJOR: use LoggerAwareTrait.
*
* @var LoggerInterface
*/
protected $logger;

/**
* @param string|null $defaultFormatter
*/
public function __construct($defaultFormatter = null)
{
if (func_num_args() == 2) {
list($logger, $defaultFormatter) = func_get_args();
$this->logger = $logger;
$this->defaultFormatter = $defaultFormatter;
} elseif (func_num_args() == 1) {
if ($defaultFormatter instanceof LoggerInterface) {
$this->logger = $defaultFormatter;
} else {
// NEXT_MAJOR: Only keep this block
$this->defaultFormatter = $defaultFormatter;
}
}

// NEXT_MAJOR: keep the else block only
if ($this->logger) {
@trigger_error(sprintf(
'Providing a logger to %s through the constructor is deprecated since 3.x'.
' and will no longer be possible in 4.0'.
' This argument should be provided through the setLogger() method.',
__CLASS__
), E_USER_DEPRECATED);
} else {
$this->logger = new NullLogger();
}

// NEXT_MAJOR: make defaultFormatter required
if (is_null($this->defaultFormatter)) {
@trigger_error(sprintf(
'Not providing the defaultFormatter argument to %s is deprecated since 3.x.'.
' This argument will become mandatory in 4.0.',
__METHOD__
), E_USER_DEPRECATED);
}
}

/**
* NEXT_MAJOR: use Psr\Log\LoggerAwareTrait.
*
* @param LoggerInterface will be used to report errors
* @param string $defaultFormatter
*/
public function setLogger(LoggerInterface $logger)
public function __construct($defaultFormatter)
{
$this->logger = $logger;
$this->defaultFormatter = $defaultFormatter;
$this->logger = new NullLogger();
}

/**
Expand Down Expand Up @@ -175,13 +129,6 @@ public function getFormatters()
*/
public function getDefaultFormatter()
{
// NEXT_MAJOR: This should be removed
if (is_null($this->defaultFormatter)) {
reset($this->formatters);

$this->defaultFormatter = key($this->formatters);
}

return $this->defaultFormatter;
}
}
33 changes: 17 additions & 16 deletions Tests/Form/Type/FormatterTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class FormatterTypeTest extends \PHPUnit_Framework_TestCase
{
public function testBuildFormOneChoice()
{
$pool = $this->getMockBuilder('Sonata\FormatterBundle\Formatter\Pool')->disableOriginalConstructor()->getMock();
$pool = $this->getPool();

$translator = $this->getMock('Symfony\Component\Translation\TranslatorInterface');
$configManager = $this->getMock('Ivory\CKEditorBundle\Model\ConfigManagerInterface');
Expand Down Expand Up @@ -56,7 +56,7 @@ public function testBuildFormOneChoice()

public function testBuildFormSeveralChoices()
{
$pool = $this->getMockBuilder('Sonata\FormatterBundle\Formatter\Pool')->disableOriginalConstructor()->getMock();
$pool = $this->getPool();
$translator = $this->getMock('Symfony\Component\Translation\TranslatorInterface');
$configManager = $this->getMock('Ivory\CKEditorBundle\Model\ConfigManagerInterface');

Expand Down Expand Up @@ -86,9 +86,7 @@ public function testBuildFormSeveralChoices()

public function testBuildFormWithCustomFormatter()
{
$pool = $this->getMockBuilder('Sonata\FormatterBundle\Formatter\Pool')
->disableOriginalConstructor()
->getMock();
$pool = $this->getPool();
$translator = $this->getMock('Symfony\Component\Translation\TranslatorInterface');
$configManager = $this->getMock('Ivory\CKEditorBundle\Model\ConfigManagerInterface');

Expand Down Expand Up @@ -132,9 +130,7 @@ public function testBuildFormWithCustomFormatter()

public function testBuildFormWithDefaultFormatter()
{
$pool = $this->getMockBuilder('Sonata\FormatterBundle\Formatter\Pool')
->disableOriginalConstructor()
->getMock();
$pool = $this->getPool();
$translator = $this->getMock('Symfony\Component\Translation\TranslatorInterface');
$configManager = $this->getMock('Ivory\CKEditorBundle\Model\ConfigManagerInterface');

Expand Down Expand Up @@ -177,9 +173,7 @@ public function testBuildFormWithDefaultFormatter()

public function testBuildFormWithDefaultFormatterAndPluginManager()
{
$pool = $this->getMockBuilder('Sonata\FormatterBundle\Formatter\Pool')
->disableOriginalConstructor()
->getMock();
$pool = $this->getPool();
$translator = $this->getMock('Symfony\Component\Translation\TranslatorInterface');
$configManager = $this->getMock('Ivory\CKEditorBundle\Model\ConfigManagerInterface');
$pluginManager = $this->getMock('Ivory\CKEditorBundle\Model\PluginManagerInterface');
Expand Down Expand Up @@ -223,7 +217,7 @@ public function testBuildFormWithDefaultFormatterAndPluginManager()

public function testBuildViewWithDefaultConfig()
{
$pool = $this->getMockBuilder('Sonata\FormatterBundle\Formatter\Pool')->disableOriginalConstructor()->getMock();
$pool = $this->getPool();
$translator = $this->getMock('Symfony\Component\Translation\TranslatorInterface');
$configManager = $this->getMock('Ivory\CKEditorBundle\Model\ConfigManagerInterface');

Expand Down Expand Up @@ -255,7 +249,7 @@ public function testBuildViewWithDefaultConfig()

public function testBuildViewWithoutDefaultConfig()
{
$pool = $this->getMockBuilder('Sonata\FormatterBundle\Formatter\Pool')->disableOriginalConstructor()->getMock();
$pool = $this->getPool();
$translator = $this->getMock('Symfony\Component\Translation\TranslatorInterface');
$configManager = $this->getMock('Ivory\CKEditorBundle\Model\ConfigManagerInterface');

Expand Down Expand Up @@ -288,7 +282,7 @@ public function testBuildViewWithoutDefaultConfig()

public function testBuildViewWithDefaultConfigAndWithToolbarIcons()
{
$pool = $this->getMockBuilder('Sonata\FormatterBundle\Formatter\Pool')->disableOriginalConstructor()->getMock();
$pool = $this->getPool();
$translator = $this->getMock('Symfony\Component\Translation\TranslatorInterface');
$configManager = $this->getMock('Ivory\CKEditorBundle\Model\ConfigManagerInterface');

Expand Down Expand Up @@ -322,7 +316,7 @@ public function testBuildViewWithDefaultConfigAndWithToolbarIcons()

public function testBuildViewWithFormatter()
{
$pool = $this->getMockBuilder('Sonata\FormatterBundle\Formatter\Pool')->disableOriginalConstructor()->getMock();
$pool = $this->getPool();
$translator = $this->getMock('Symfony\Component\Translation\TranslatorInterface');
$configManager = $this->getMock('Ivory\CKEditorBundle\Model\ConfigManagerInterface');

Expand Down Expand Up @@ -359,7 +353,7 @@ public function testBuildViewWithFormatter()

public function testBuildViewWithDefaultConfigAndPluginManager()
{
$pool = $this->getMockBuilder('Sonata\FormatterBundle\Formatter\Pool')->disableOriginalConstructor()->getMock();
$pool = $this->getPool();
$translator = $this->getMock('Symfony\Component\Translation\TranslatorInterface');
$configManager = $this->getMock('Ivory\CKEditorBundle\Model\ConfigManagerInterface');
$pluginManager = $this->getMock('Ivory\CKEditorBundle\Model\PluginManagerInterface');
Expand Down Expand Up @@ -389,4 +383,11 @@ public function testBuildViewWithDefaultConfigAndPluginManager()

$this->assertSame($view->vars['ckeditor_configuration'], $defaultConfigValues);
}

private function getPool()
{
return $this->getMockBuilder('Sonata\FormatterBundle\Formatter\Pool')
->disableOriginalConstructor()
->getMock();
}
}
37 changes: 0 additions & 37 deletions Tests/Formatter/PoolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,43 +87,6 @@ public function testDefaultFormatter()
$this->assertSame('default', $pool->getDefaultFormatter());
}

/**
* NEXT_MAJOR: This should be removed.
*
* @group legacy
*/
public function testBcDefaultFormatter()
{
$formatter = new RawFormatter();
$env = $this->getMock('\Twig_Environment');

$pool = new Pool();

$pool->add('foo', $formatter, $env);

$this->assertSame('foo', $pool->getDefaultFormatter());
}

/**
* NEXT_MAJOR: This should be removed.
*
* @group legacy
*/
public function testLoggerProvidedThroughConstuctor()
{
$formatter = new RawFormatter();
$pool = new Pool($logger = $this->getMock('Psr\Log\LoggerInterface'));
$env = $this->getMock('\Twig_Environment');
$env->expects($this->once())->method('render')->will(
$this->throwException(new \Twig_Sandbox_SecurityError('Error'))
);

$pool->add('foo', $formatter, $env);
$logger->expects($this->once())->method('critical');

$pool->transform('foo', 'whatever');
}

private function getPool()
{
$pool = new Pool('whatever');
Expand Down
Loading

0 comments on commit 87d8ee1

Please sign in to comment.