Skip to content
Browse files

Rename BlockExecutionContext => BlockContext

  • Loading branch information...
1 parent 7e76232 commit 4c0038df80cc2acfcc809a3c4490f0d94053e3cb @rande rande committed Mar 28, 2013
View
18 Block/BaseBlockService.php
@@ -148,23 +148,21 @@ public function getStylesheets($media)
}
/**
- * @return array
- *
- * @deprecated
+ * {@inheritdoc}
*/
- public function getDefaultSettings()
+ public function setDefaultSettings(OptionsResolverInterface $resolver)
{
- return array();
+
}
/**
* {@inheritdoc}
*/
- public function setDefaultSetttings(OptionsResolverInterface $resolver)
+ public function execute(BlockContextInterface $blockContext, Response $response = null)
{
- // @bc code
- if (method_exists($this, 'getDefaultSettings')) {
- $resolver->setDefaults($this->getDefaultSettings());
- }
+ return $this->renderResponse($blockContext->getTemplate(), array(
+ 'block_context' => $blockContext,
+ 'block' => $blockContext->getBlock(),
+ ), $response);
}
}
View
4 Block/BlockExecutionContext.php → Block/BlockContext.php
@@ -13,7 +13,7 @@
use Sonata\BlockBundle\Model\BlockInterface;
-class BlockExecutionContext implements BlockExecutionContextInterface
+class BlockContext implements BlockContextInterface
{
/**
* @var BlockInterface
@@ -54,7 +54,7 @@ public function getSettings()
public function getSetting($name)
{
if (!isset($this->settings[$name])) {
- throw new \RuntimeException(sprintf('Unable to find the option %s - define the option in the related BlockServiceInterface', $name));
+ throw new \RuntimeException(sprintf('Unable to find the option `%s` (%s) - define the option in the related BlockServiceInterface', $name, $this->block->getType()));
}
return $this->settings[$name];
View
2 Block/BlockExecutionContextInterface.php → Block/BlockContextInterface.php
@@ -13,7 +13,7 @@
use Sonata\BlockBundle\Model\BlockInterface;
-interface BlockExecutionContextInterface
+interface BlockContextInterface
{
/**
* @return BlockInterface
View
6 Block/BlockContextManager.php
@@ -36,7 +36,7 @@ public function __construct(BlockLoaderInterface $blockLoader, BlockServiceManag
* @param mixed $meta
* @param array $settings
*
- * @return BlockExecutionContextInterface
+ * @return BlockContextInterface
*
* @thrown BlockOptionsException
*/
@@ -68,7 +68,7 @@ public function get($meta, array $settings = array())
));
$service = $this->blockService->get($block);
- $service->setDefaultSetttings($optionsResolver, $block);
+ $service->setDefaultSettings($optionsResolver, $block);
try {
// inline options overwrite model one
@@ -77,6 +77,6 @@ public function get($meta, array $settings = array())
throw new BlockOptionsException($e);
}
- return new BlockExecutionContext($block, $settings);
+ return new BlockContext($block, $settings);
}
}
View
2 Block/BlockContextManagerInterface.php
@@ -17,7 +17,7 @@
* @param $meta
* @param array $settings
*
- * @return BlockExecutionContextInterface
+ * @return BlockContextInterface
*/
public function get($meta, array $settings = array());
}
View
2 Block/BlockRenderer.php
@@ -60,7 +60,7 @@ public function __construct(BlockServiceManagerInterface $blockServiceManager, S
/**
* {@inheritdoc}
*/
- public function render(BlockExecutionContextInterface $blockContext, Response $response = null)
+ public function render(BlockContextInterface $blockContext, Response $response = null)
{
$block = $blockContext->getBlock();
View
6 Block/BlockRendererInterface.php
@@ -11,16 +11,16 @@
namespace Sonata\BlockBundle\Block;
-use Sonata\BlockBundle\Block\BlockExecutionContextInterface;
+use Sonata\BlockBundle\Block\BlockContextInterface;
use Symfony\Component\HttpFoundation\Response;
interface BlockRendererInterface
{
/**
- * @param BlockExecutionContextInterface $name
+ * @param BlockContextInterface $name
* @param null|Response $response
*
* @return Response
*/
- public function render(BlockExecutionContextInterface $name, Response $response = null);
+ public function render(BlockContextInterface $name, Response $response = null);
}
View
6 Block/BlockServiceInterface.php
@@ -37,12 +37,12 @@ public function buildEditForm(FormMapper $form, BlockInterface $block);
public function buildCreateForm(FormMapper $form, BlockInterface $block);
/**
- * @param BlockExecutionContextInterface $blockContext
+ * @param BlockContextInterface $blockContext
* @param null|Response $response
*
* @return Response
*/
- public function execute(BlockExecutionContextInterface $blockContext, Response $response = null);
+ public function execute(BlockContextInterface $blockContext, Response $response = null);
/**
* @param ErrorElement $errorElement
@@ -62,7 +62,7 @@ public function getName();
*
* @param OptionsResolverInterface $resolver
*/
- public function setDefaultSetttings(OptionsResolverInterface $resolver);
+ public function setDefaultSettings(OptionsResolverInterface $resolver);
/**
* @param BlockInterface $block
View
4 Block/Service/EmptyBlockService.php
@@ -11,7 +11,7 @@
namespace Sonata\BlockBundle\Block\Service;
-use Sonata\BlockBundle\Block\BlockExecutionContextInterface;
+use Sonata\BlockBundle\Block\BlockContextInterface;
use Symfony\Component\HttpFoundation\Response;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\BlockBundle\Model\BlockInterface;
@@ -39,7 +39,7 @@ public function validateBlock(ErrorElement $errorElement, BlockInterface $block)
/**
* {@inheritdoc}
*/
- public function execute(BlockExecutionContextInterface $blockContext, Response $response = null)
+ public function execute(BlockContextInterface $blockContext, Response $response = null)
{
return new Response();
}
View
6 Block/Service/RssBlockService.php
@@ -11,7 +11,7 @@
namespace Sonata\BlockBundle\Block\Service;
-use Sonata\BlockBundle\Block\BlockExecutionContextInterface;
+use Sonata\BlockBundle\Block\BlockContextInterface;
use Symfony\Component\HttpFoundation\Response;
use Sonata\AdminBundle\Form\FormMapper;
@@ -38,7 +38,7 @@ public function getName()
/**
* {@inheritdoc}
*/
- public function setDefaultSetttings(OptionsResolverInterface $resolver)
+ public function setDefaultSettings(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'url' => false,
@@ -80,7 +80,7 @@ public function validateBlock(ErrorElement $errorElement, BlockInterface $block)
/**
* {@inheritdoc}
*/
- public function execute(BlockExecutionContextInterface $blockContext, Response $response = null)
+ public function execute(BlockContextInterface $blockContext, Response $response = null)
{
// merge settings
$settings = $blockContext->getSettings();
View
8 Block/Service/TextBlockService.php
@@ -11,15 +11,15 @@
namespace Sonata\BlockBundle\Block\Service;
-use Sonata\BlockBundle\Block\BlockExecutionContextInterface;
+use Sonata\BlockBundle\Block\BlockContextInterface;
use Symfony\Component\HttpFoundation\Response;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Validator\ErrorElement;
use Sonata\BlockBundle\Model\BlockInterface;
use Sonata\BlockBundle\Block\BaseBlockService;
-use Symfony\Component\OptionsResolver\OptionsResolver;
+use Symfony\Component\OptionsResolver\OptionsResolverInterface;
/**
*
@@ -30,7 +30,7 @@ class TextBlockService extends BaseBlockService
/**
* {@inheritdoc}
*/
- public function execute(BlockExecutionContextInterface $blockContext, Response $response = null)
+ public function execute(BlockContextInterface $blockContext, Response $response = null)
{
return $this->renderResponse($blockContext->getTemplate(), array(
'block' => $blockContext->getBlock(),
@@ -69,7 +69,7 @@ public function getName()
/**
* {@inheritdoc}
*/
- public function setDefaultSettings(OptionsResolver $resolver)
+ public function setDefaultSettings(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'content' => 'Insert your custom content here',
View
2 Block/TraceableBlockRenderer.php
@@ -41,7 +41,7 @@ public function __construct(BlockRendererInterface $blockRender)
/**
* {@inheritdoc}
*/
- public function render(BlockExecutionContextInterface $blockContext, Response $response = null)
+ public function render(BlockContextInterface $blockContext, Response $response = null)
{
$this->startTracing($blockContext->getBlock());
View
2 CHANGELOG.md
@@ -9,4 +9,4 @@ A [BC BREAK] means the update will break the project for many reasons:
### 2013-03-28
-* [BC BREAK] Intoduction of an BlockExecutionContext to hold a BlockInterface instance and the related settings.
+* [BC BREAK] Intoduction of an BlockContext to hold a BlockInterface instance and the related settings.
View
7 Resources/config/core.xml
@@ -11,6 +11,11 @@
<argument type="service" id="logger" on-invalid="ignore" />
</service>
+ <service id="sonata.block.context_manager" class="Sonata\BlockBundle\Block\BlockContextManager">
+ <argument type="service" id="sonata.block.loader.service" />
+ <argument type="service" id="sonata.block.manager" />
+ </service>
+
<service id="sonata.block.renderer.default" class="Sonata\BlockBundle\Block\BlockRenderer">
<argument type="service" id="sonata.block.manager" />
<argument type="service" id="sonata.block.exception.strategy.manager" />
@@ -27,8 +32,8 @@
<argument type="service" id="sonata.block.manager" />
<argument />
- <argument type="service" id="sonata.block.loader.chain" />
<argument type="service" id="sonata.block.renderer" />
+ <argument type="service" id="sonata.block.context_manager" />
<argument type="service" id="sonata.cache.manager" on-invalid="ignore" />
</service>
View
8 Tests/Block/BlockContextManagerTest.php
@@ -18,7 +18,7 @@ class BlockContextManagerTest extends \PHPUnit_Framework_TestCase
public function testGetWithValidData()
{
$service = $this->getMock('Sonata\BlockBundle\Block\BlockServiceInterface');
- $service->expects($this->once())->method('setDefaultSetttings');
+ $service->expects($this->once())->method('setDefaultSettings');
$blockLoader = $this->getMock('Sonata\BlockBundle\Block\BlockLoaderInterface');
@@ -32,7 +32,7 @@ public function testGetWithValidData()
$blockContext = $manager->get($block);
- $this->assertInstanceOf('Sonata\BlockBundle\Block\BlockExecutionContextInterface', $blockContext);
+ $this->assertInstanceOf('Sonata\BlockBundle\Block\BlockContextInterface', $blockContext);
$this->assertEquals(array(
'use_cache' => true,
@@ -48,7 +48,7 @@ public function testGetWithValidData()
public function testGetWithException()
{
$service = $this->getMock('Sonata\BlockBundle\Block\BlockServiceInterface');
- $service->expects($this->once())->method('setDefaultSetttings');
+ $service->expects($this->once())->method('setDefaultSettings');
$blockLoader = $this->getMock('Sonata\BlockBundle\Block\BlockLoaderInterface');
@@ -64,6 +64,6 @@ public function testGetWithException()
$blockContext = $manager->get($block);
- $this->assertInstanceOf('Sonata\BlockBundle\Block\BlockExecutionContextInterface', $blockContext);
+ $this->assertInstanceOf('Sonata\BlockBundle\Block\BlockContextInterface', $blockContext);
}
}
View
8 Tests/Block/BlockExecutionContextTest.php
@@ -11,15 +11,15 @@
namespace Sonata\BlockBundle\Tests\Block;
-use Sonata\BlockBundle\Block\BlockExecutionContext;
+use Sonata\BlockBundle\Block\BlockContext;
-class BlockExecutionContextTest extends \PHPUnit_Framework_TestCase
+class BlockContextTest extends \PHPUnit_Framework_TestCase
{
public function testBasicFeature()
{
$block = $this->getMock('Sonata\BlockBundle\Model\BlockInterface');
- $blockContext = new BlockExecutionContext($block, array(
+ $blockContext = new BlockContext($block, array(
'hello' => 'world'
));
@@ -36,7 +36,7 @@ public function testInvalidParameter()
{
$block = $this->getMock('Sonata\BlockBundle\Model\BlockInterface');
- $blockContext = new BlockExecutionContext($block);
+ $blockContext = new BlockContext($block);
$blockContext->getSetting('fake');
}
View
8 Tests/Block/BlockRendererTest.php
@@ -11,7 +11,7 @@
namespace Sonata\BlockBundle\Tests\Block;
-use Sonata\BlockBundle\Block\BlockExecutionContext;
+use Sonata\BlockBundle\Block\BlockContext;
use Sonata\BlockBundle\Block\BlockRenderer;
/**
@@ -67,7 +67,7 @@ public function testRenderWithoutErrors()
// mock a block object
$block = $this->getMock('Sonata\BlockBundle\Model\BlockInterface');
- $blockContext = new BlockExecutionContext($block);
+ $blockContext = new BlockContext($block);
// WHEN
$result = $this->renderer->render($blockContext);
@@ -104,7 +104,7 @@ public function testRenderWithWrongResponse()
// mock a block object
$block = $this->getMock('Sonata\BlockBundle\Model\BlockInterface');
- $blockContext = new BlockExecutionContext($block);
+ $blockContext = new BlockContext($block);
// WHEN
$this->renderer->render($blockContext);
@@ -145,7 +145,7 @@ public function testRenderBlockWithException()
// mock a block object
$block = $this->getMock('Sonata\BlockBundle\Model\BlockInterface');
- $blockContext = new BlockExecutionContext($block);
+ $blockContext = new BlockContext($block);
// WHEN
$result = $this->renderer->render($blockContext);
View
6 Tests/Block/Service/RssBlockServiceTest.php
@@ -11,7 +11,7 @@
namespace Sonata\BlockBundle\Tests\Block\Service;
-use Sonata\BlockBundle\Block\BlockExecutionContext;
+use Sonata\BlockBundle\Block\BlockContext;
use Sonata\BlockBundle\Model\Block;
use Sonata\BlockBundle\Block\Service\RssBlockService;
@@ -34,9 +34,9 @@ public function testService()
));
$optionResolver = new OptionsResolver();
- $service->setDefaultSetttings($optionResolver);
+ $service->setDefaultSettings($optionResolver);
- $blockContext = new BlockExecutionContext($block, $optionResolver->resolve());
+ $blockContext = new BlockContext($block, $optionResolver->resolve());
$formMapper = $this->getMock('Sonata\\AdminBundle\\Form\\FormMapper', array(), array(), '', false);
$formMapper->expects($this->exactly(2))->method('add');
View
4 Tests/Block/Service/TextBlockServiceTest.php
@@ -14,7 +14,7 @@
use Sonata\BlockBundle\Model\Block;
use Sonata\BlockBundle\Block\Service\TextBlockService;
use Symfony\Component\OptionsResolver\OptionsResolver;
-use Sonata\BlockBundle\Block\BlockExecutionContext;
+use Sonata\BlockBundle\Block\BlockContext;
class TextBlockServiceTest extends BaseTestBlockService
{
@@ -33,7 +33,7 @@ public function testService()
$optionResolver = new OptionsResolver();
$service->setDefaultSettings($optionResolver);
- $blockContext = new BlockExecutionContext($block, $optionResolver->resolve($block->getSettings()));
+ $blockContext = new BlockContext($block, $optionResolver->resolve($block->getSettings()));
$formMapper = $this->getMock('Sonata\\AdminBundle\\Form\\FormMapper', array(), array(), '', false);
$formMapper->expects($this->exactly(2))->method('add');
View
4 Tests/Block/TraceableBlockRendererTest.php
@@ -13,7 +13,7 @@
use Sonata\BlockBundle\Block\TraceableBlockRenderer;
use Symfony\Component\HttpFoundation\Response;
-use Sonata\BlockBundle\Block\BlockExecutionContext;
+use Sonata\BlockBundle\Block\BlockContext;
class TraceableBlockRendererTest extends \PHPUnit_Framework_TestCase
{
@@ -28,7 +28,7 @@ public function testRender()
$block->expects($this->any())->method('getId')->will($this->returnValue(42));
$block->expects($this->any())->method('getType')->will($this->returnValue('mytype'));
- $blockContext = new BlockExecutionContext($block);
+ $blockContext = new BlockContext($block);
$traceable->render($blockContext);
View
12 UPGRADE-2.2.md
@@ -13,13 +13,13 @@ UPGRADE FROM 2.1 to 2.2
+ * @param OptionsResolverInterface $resolver
*/
- public function getDefaultSettings();
- + public function setDefaultSetttings(OptionsResolverInterface $resolver);
+ + public function setDefaultSettings(OptionsResolverInterface $resolver);
So to update, just use the ``OptionsResolverInterface`` API as the Form Component:
- public function getDefaultSettings()
- + public function setDefaultSetttings(OptionsResolverInterface $resolver)
+ + public function setDefaultSettings(OptionsResolverInterface $resolver)
{
- return array(
- 'url' => false,
@@ -35,7 +35,7 @@ UPGRADE FROM 2.1 to 2.2
The template is now a mandatory parameter (which can be set to false), so the ``execute`` method should like:
- public function execute(BlockInterface $block, Response $response = null)
- + public function execute(BlockExecutionContextInterface $blockContext, Response $response = null)
+ + public function execute(BlockContextInterface $blockContext, Response $response = null)
{
- $settings = array_merge($this->getDefaultSettings(), $block->getSettings());
-
@@ -49,3 +49,9 @@ UPGRADE FROM 2.1 to 2.2
}
+ The twig template helper sonata_block_render has been updated:
+
+ sonata_block_render(block, use_cache, extra_cache_key)
+
+ => sonata_block_render(block, {'use_cache': use_cache, 'extra_cache_key': extra_cache_key})
+
@dbu
dbu added a note Mar 29, 2013

and i can pass additional parameters now? or what was the purpose of this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

0 comments on commit 4c0038d

Please sign in to comment.
Something went wrong with that request. Please try again.