Skip to content

Commit

Permalink
Merge branch '5.x' into merge
Browse files Browse the repository at this point in the history
  • Loading branch information
jordisala1991 authored Jun 3, 2023
2 parents 3e14ffd + e1be369 commit d4d18dd
Show file tree
Hide file tree
Showing 82 changed files with 197 additions and 2,122 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ jobs:
dependencies: highest
allowed-to-fail: false
variant: sonata-project/form-extensions:"2.0.0-alpha-1"
- php-version: '8.2'
dependencies: highest
allowed-to-fail: false
symfony-require: 4.4.*
variant: symfony/symfony:"4.4.*"
- php-version: '8.2'
dependencies: highest
allowed-to-fail: false
Expand Down
10 changes: 10 additions & 0 deletions UPGRADE-5.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
UPGRADE FROM 4.X to 5.0
=======================

## Deprecations

All the deprecated code introduced on 4.x is removed on 5.0.

Please read [4.x](https://github.com/sonata-project/SonataBlockBundle/blob/4.x/UPGRADE-4.x.md) upgrade guides for more information.

See also the [diff code](https://github.com/sonata-project/SonataBlockBundle/compare/4.x...5.0.0).
53 changes: 21 additions & 32 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,24 @@
"require": {
"php": "^8.0",
"doctrine/collections": "^1.8 || ^2.0",
"doctrine/common": "^2.7.1 || ^3.0",
"psr/cache": "^1.0 || ^2.0 || ^3.0",
"doctrine/common": "^3.0",
"psr/container": "^1.0 || ^2.0",
"psr/log": "^1.1 || ^2.0 || ^3.0",
"sonata-project/cache": "^2.0",
"psr/log": "^2.0 || ^3.0",
"sonata-project/form-extensions": "^1.4 || ^2.0",
"symfony/asset": "^4.4 || ^5.4 || ^6.2",
"symfony/config": "^4.4 || ^5.4 || ^6.2",
"symfony/console": "^4.4 || ^5.4 || ^6.2",
"symfony/dependency-injection": "^4.4 || ^5.4 || ^6.2",
"symfony/event-dispatcher": "^4.4 || ^5.4 || ^6.2",
"symfony/event-dispatcher-contracts": "^1.1 || ^2.0 || ^3.0",
"symfony/form": "^4.4 || ^5.4 || ^6.2",
"symfony/framework-bundle": "^4.4 || ^5.4 || ^6.2",
"symfony/http-foundation": "^4.4 || ^5.4 || ^6.2",
"symfony/http-kernel": "^4.4 || ^5.4 || ^6.2",
"symfony/options-resolver": "^4.4 || ^5.4 || ^6.2",
"symfony/twig-bundle": "^4.4 || ^5.4 || ^6.2",
"symfony/validator": "^4.4 || ^5.4 || ^6.2",
"twig/twig": "^2.12.1 || ^3.0"
"symfony/asset": "^5.4 || ^6.2",
"symfony/config": "^5.4 || ^6.2",
"symfony/console": "^5.4 || ^6.2",
"symfony/dependency-injection": "^5.4 || ^6.2",
"symfony/event-dispatcher": "^5.4 || ^6.2",
"symfony/event-dispatcher-contracts": "^2.0 || ^3.0",
"symfony/form": "^5.4 || ^6.2",
"symfony/framework-bundle": "^5.4 || ^6.2",
"symfony/http-foundation": "^5.4 || ^6.2",
"symfony/http-kernel": "^5.4 || ^6.2",
"symfony/options-resolver": "^5.4 || ^6.2",
"symfony/twig-bundle": "^5.4 || ^6.2",
"symfony/validator": "^5.4 || ^6.2",
"twig/twig": "^3.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.4",
Expand All @@ -56,19 +54,15 @@
"phpstan/phpstan-symfony": "^1.0",
"phpunit/phpunit": "^9.5.13",
"psalm/plugin-phpunit": "^0.18",
"psalm/plugin-symfony": "^4.0 || ^5.0",
"psalm/plugin-symfony": "^5.0",
"rector/rector": "^0.17",
"sonata-project/doctrine-extensions": "^1.10.1",
"symfony/browser-kit": "^4.4 || ^5.4 || ^6.2",
"symfony/debug": "^4.4 || ^5.4 || ^6.2",
"symfony/browser-kit": "^5.4 || ^6.2",
"symfony/error-handler": "^5.4 || ^6.2",
"symfony/phpunit-bridge": "^6.2",
"symfony/routing": "^4.4.12 || ^5.4 || ^6.2",
"symfony/stopwatch": "^4.4 || ^5.4 || ^6.2",
"symfony/yaml": "^4.4 || ^5.4 || ^6.2",
"vimeo/psalm": "^4.1 || ^5.8.0"
"symfony/stopwatch": "^5.4 || ^6.2",
"vimeo/psalm": "^5.8"
},
"conflict": {
"doctrine/annotations": "<1.7",
"knplabs/knp-menu-bundle": "<3.0"
},
"suggest": {
Expand All @@ -92,10 +86,5 @@
"phpstan/extension-installer": true
},
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-master": "4.x-dev"
}
}
}
1 change: 0 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Block Bundle
reference/profiler
reference/exceptions
reference/advanced_usage
reference/cache
reference/events
reference/testing

Expand Down
38 changes: 1 addition & 37 deletions docs/reference/advanced_usage.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.. index::
single: Advanced
single: Usage
single: Cache
single: Context

Advanced usage
Expand All @@ -10,45 +9,12 @@ Advanced usage
This happens when a block is rendered:

* A block is loaded based on the configuration passed to ``sonata_block_render``,
* If caching is configured, the cache is checked
* If cache exists and has content, the content is returned
* Each block model also has a block service, and its ``execute`` method is caled:
* Each block model also has a block service, and its ``execute`` method is called:

* You can logic into block service's ``execute`` method, like in a controller,
* It renders a template,
* It returns a `Response` object.

Cache
-----

The ``SonataBlockBundle`` is integrated with the SonataCacheBundle_, which provides several caching solutions.
Have a look at the available adapters in the SonataCacheBundle_ to see all options.

Block Context Manager - context cache
-------------------------------------

When using ``Varnish``, ``Ssi`` or ``Js`` cache, the settings passed here are lost:

.. code-block:: html+twig

{{ sonata_block_render({ 'type': 'sonata.block.service.rss' }, {
'title': 'Sonata Project\'s Feeds',
'url': 'https://sonata-project.org/blog/archive.rss'
}) }}

Taking ``Js`` as example, a URL is generated and added to some javascript. This javascript is injected into the page. When the page is loaded, the javascript calls the URL to retrieve the block content.

The default ``BlockContextManager`` automatically adds settings passed from the template to the ``extra_cache_keys`` with the key ``context``.
This allows cache adapters to rebuild a ``BlockContext`` if implemented.

Still in the ``Js`` example, the cache keys can be added to the URL as query parameters.
When the URL is called from the javascript, the cache adapter handles the request. It retrieves the settings from the ``context`` parameter and passes it to the ``BlockContextManager`` while creating a new ``BlockContext``.
This ensures the ``BlockContext`` is the same as when it was created from a template helper call without cache enabled.

.. note::

The settings are exposed because they are added to the URL as parameters, secure the URL if needed.

Block loading
-------------

Expand All @@ -59,5 +25,3 @@ Empty block

By default, the loader interface expects the exception ``Sonata\BlockBundle\Exception\BlockNotFoundException`` if a block is not found.
Return an empty block from your loader class if the default behavior for your blocks is to always return content.

.. _SonataCacheBundle: https://github.com/sonata-project/SonataCacheBundle
160 changes: 0 additions & 160 deletions docs/reference/cache.rst

This file was deleted.

2 changes: 0 additions & 2 deletions docs/reference/provided_blocks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ Defining a menu could be done by inserting the ``knp_menu.menu`` tag.
Upon configuration, you may set some rendering options (see KNP Doc for those).

Set ``cache_policy`` to private if this menu is dedicated to be in a user part.

A specific menu template is provided as well to render Bootstrap3's side menu, you may use it by setting the ``menu_template`` option to ``@SonataBlock/Block/block_side_menu_template.html.twig`` (see the implementation in SonataUserBundle or Sonata's e-commerce suite).

.. _KnpMenuBundle documentation: https://symfony.com/doc/current/bundles/KnpMenuBundle/index.html
8 changes: 4 additions & 4 deletions docs/reference/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Given the following block service::

class CustomBlockService extends AbstractBlockService
{
public function execute(BlockContextInterface $blockContext, Response $response = null)
public function execute(BlockContextInterface $blockContext, Response $response = null): Response
{
return $this->renderResponse($blockContext->getTemplate(), [
'context' => $blockContext,
Expand All @@ -20,7 +20,7 @@ Given the following block service::
], $response);
}

public function configureSettings(OptionsResolver $resolver)
public function configureSettings(OptionsResolver $resolver): array
{
$resolver->setDefaults([
'foo' => 'bar',
Expand All @@ -36,7 +36,7 @@ You can write unit tests for block services with the following code::

class CustomBlockServiceTest extends AbstractBlockServiceTestCase
{
public function testDefaultSettings()
public function testDefaultSettings(): void
{
$blockService = new CustomBlockService('foo', $this->twig);
$blockContext = $this->getBlockContext($blockService);
Expand All @@ -48,7 +48,7 @@ You can write unit tests for block services with the following code::
], $blockContext);
}

public function testExecute()
public function testExecute(): void
{
$blockService = new CustomBlockService('foo', $this->twig);
$blockContext = $this->getBlockContext($blockService);
Expand Down
9 changes: 0 additions & 9 deletions docs/reference/twig_helpers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ Render a block by providing the block's type and options:
'url': 'https://sonata-project.org/blog/archive.rss'
}) }}

Render a block by providing the block's cache options:

.. code-block:: html+twig

{{ sonata_block_render(block, {
'use_cache': use_cache,
'extra_cache_key': extra_cache_key
}) }}

Render a block by calling an event:

.. code-block:: html+twig
Expand Down
Loading

0 comments on commit d4d18dd

Please sign in to comment.