-
-
Notifications
You must be signed in to change notification settings - Fork 495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add default resizer and default resizer adapter #721
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
use Symfony\Component\Config\Definition\Processor; | ||
use Symfony\Component\Config\FileLocator; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
|
@@ -127,14 +128,57 @@ public function load(array $configs, ContainerBuilder $container) | |
$this->configureExtra($container, $config); | ||
$this->configureBuzz($container, $config); | ||
$this->configureProviders($container, $config); | ||
$this->configureAdapters($container, $config); | ||
$this->configureResizers($container, $config); | ||
$this->configureClassesToCompile(); | ||
} | ||
|
||
/** | ||
* @param ContainerBuilder $container | ||
* @param array $config | ||
*/ | ||
public function configureProviders(ContainerBuilder $container, $config) | ||
public function configureAdapters(ContainerBuilder $container, array $config) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why public? Can we make this at least protected? |
||
{ | ||
foreach (array('gd', 'imagick', 'gmagick') as $adapter) { | ||
if ($container->hasParameter('sonata.media.adapter.image.'.$adapter.'.class')) { | ||
$container->register('sonata.media.adapter.image.'.$adapter, $container->getParameter('sonata.media.adapter.image.'.$adapter.'.class')); | ||
} | ||
} | ||
$container->setAlias('sonata.media.adapter.image.default', $config['adapters']['default']); | ||
} | ||
|
||
/** | ||
* @param ContainerBuilder $container | ||
* @param array $config | ||
*/ | ||
public function configureResizers(ContainerBuilder $container, array $config) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. Why public? |
||
{ | ||
if ($container->hasParameter('sonata.media.resizer.simple.class')) { | ||
$class = $container->getParameter('sonata.media.resizer.simple.class'); | ||
$definition = new Definition($class, array( | ||
new Reference('sonata.media.adapter.image.default'), | ||
'%sonata.media.resizer.simple.adapter.mode%', | ||
new Reference('sonata.media.metadata.proxy'), | ||
)); | ||
$container->setDefinition('sonata.media.resizer.simple', $definition); | ||
} | ||
if ($container->hasParameter('sonata.media.resizer.square.class')) { | ||
$class = $container->getParameter('sonata.media.resizer.square.class'); | ||
$definition = new Definition($class, array( | ||
new Reference('sonata.media.adapter.image.default'), | ||
'%sonata.media.resizer.square.adapter.mode%', | ||
new Reference('sonata.media.metadata.proxy'), | ||
)); | ||
$container->setDefinition('sonata.media.resizer.square', $definition); | ||
} | ||
$container->setAlias('sonata.media.resizer.default', $config['resizers']['default']); | ||
} | ||
|
||
/** | ||
* @param ContainerBuilder $container | ||
* @param array $config | ||
*/ | ||
public function configureProviders(ContainerBuilder $container, array $config) | ||
{ | ||
$container->getDefinition('sonata.media.provider.image') | ||
->replaceArgument(5, array_map('strtolower', $config['providers']['image']['allowed_extensions'])) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
namespace Sonata\MediaBundle\Resizer; | ||
|
||
use Gaufrette\File; | ||
use Imagine\Image\ImagineInterface; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not related to this PR |
||
use Sonata\MediaBundle\Model\MediaInterface; | ||
|
||
interface ResizerInterface | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ | |
class SimpleResizer implements ResizerInterface | ||
{ | ||
/** | ||
* @var ImagineInterface | ||
* @var ImagineInterface. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove the |
||
*/ | ||
protected $adapter; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,12 +29,28 @@ | |
class SquareResizer implements ResizerInterface | ||
{ | ||
/** | ||
* ImagineInterface. | ||
* @var ImagineInterface. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove the |
||
*/ | ||
protected $adapter; | ||
|
||
/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need a new line separation. |
||
* string. | ||
* {@inheritdoc} | ||
*/ | ||
public function getAdapter() | ||
{ | ||
return $this->adapter; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function setAdapter(ImagineInterface $adapter) | ||
{ | ||
$this->adapter = $adapter; | ||
} | ||
|
||
/** | ||
* @var string. | ||
*/ | ||
protected $mode; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing Sonata headers. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
/* | ||
* This file is part of the Sonata project. | ||
* | ||
* (c) Sonata Project | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\MediaBundle\Tests\DependencyInjection; | ||
|
||
use PHPUnit_Framework_TestCase; | ||
use Sonata\MediaBundle\DependencyInjection\Configuration; | ||
use Symfony\Component\Config\Definition\Processor; | ||
|
||
class ConfigurationTest extends PHPUnit_Framework_TestCase | ||
{ | ||
protected $config; | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$configs = array( | ||
'sonata_media' => array( | ||
'db_driver' => 'doctrine_orm', | ||
'default_context' => 'default', | ||
), | ||
); | ||
$processor = new Processor(); | ||
$configuration = new Configuration(); | ||
$this->config = $processor->processConfiguration($configuration, $configs); | ||
} | ||
|
||
public function testResizers() | ||
{ | ||
$this->assertArrayHasKey('resizers', $this->config); | ||
$this->assertArrayHasKey('default', $this->config['resizers']); | ||
$this->assertEquals('sonata.media.resizer.simple', $this->config['resizers']['default']); | ||
} | ||
|
||
public function testAdapters() | ||
{ | ||
$this->assertArrayHasKey('adapters', $this->config); | ||
$this->assertArrayHasKey('default', $this->config['adapters']); | ||
$this->assertEquals('sonata.media.adapter.image.gd', $this->config['adapters']['default']); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing doc block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed