-
-
Notifications
You must be signed in to change notification settings - Fork 142
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
Remove dependency on symfony/templating #476
Conversation
E_USER_DEPRECATED | ||
); | ||
} elseif (!$templating instanceof Environment) { | ||
throw new \TypeError('Argument 2 passed to '.get_class($this).'::__construct() must be instance of Twig\Environment, instance of '.get_class($templating).' given'); |
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.
Please linebreak this, use sprintf
, __METHOD__
and Environment::class
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
*/ | ||
protected $templating; | ||
protected $twig; |
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.
Should be private
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, $twig
property is private in InlineRenderer
and InlineDebugRenderer
src/Templating/EngineInterface.php
Outdated
* | ||
* @return string The evaluated template as a string | ||
*/ | ||
public function render($name, array $parameters = []); |
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.
Please add return type hints
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.
Added type hints and updated classes, implementing this interface
@@ -63,7 +72,13 @@ public function __construct($name = null, EngineInterface $templating = null) | |||
*/ | |||
public function renderResponse($view, array $parameters = [], Response $response = null) | |||
{ | |||
return $this->getTemplating()->renderResponse($view, $parameters, $response); | |||
if (null === $response) { |
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.
this can probably be changed to $response = $response ?? new Response();
but I am not sure that makes it better 😄
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. But, i searched for ?? new
string in master branches of all sonata branches. This will be for a first time, where $obj = $obj ?? new className()
is used =)
de0842e
to
59eb208
Compare
{ | ||
if (null === $name || null === $templating) { | ||
if ($templating instanceof EngineInterface) { |
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.
Do we need to add deprecation messages on master? can't we just move to twig direclty? wdyt @sonata-project/contributors @covex-nn ?
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.
I think that is a better option.
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.
At the begining i thought, that if i will remove type hint from __construct
of AbstractBlockService, it will be easier to upgrade all other bundles, because they will be compatible with 3.x and with dev-master of BlockBundle.
I searched in src/Block
directory inside each bundle and found, that there are 12 bundles, containing Blocks
:
- 7 bundles contain at least one
Block
with extended__construct
(with more than 2 parameters): AdminBundle, DoctrineORMAdminBundle, MediaBundle, NewsBundle, PageBundle, SeoBundle, TimelineBundle. - 4 bundles have
Blocks
without__construct
: CommentBundle: DashboardBundle, FormatterBundle, TranslationBundle - DoctrinePhpcrAdminBundle contain
Block
, that extends deprecated BaseBlockService class
So, first 7 bundles will not be compatible with new AbstractBlockService::__construct =(( May be it is too much and a should just change EngineInterface $templating
to Environment $templating
? And there will be no deprecation message.
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.
@jordisala1991 @kunicmarko20 with type hint Environment
for second constructor's parameter of AbstractBlockService
there won't be Stage 3 =) and there won't be a message about deprecation, of course. I like it more, than current proposal.
But if we will leave second parameter without type hint, new Block classes, created after 3.11 and before 4.0 release could be compatible with new AbstractBlockService
, if they will be without own __construct
. And i guess, that all of new Blocks will use templating
service, not new sonata.templating
!
So, i think, that we will not reach BC. And if you do not mind, tomorrow i will add Environment
type hint to a second parameter.
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.
Well, 4.x does not have to be BC with 3.x? /cc @sonata-project/contributors
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.
If I understand correctly, the issue is that some bundle need to be compatible with 2 versions of some other bundles, right?
* @param MenuProviderInterface $menuProvider | ||
* @param MenuRegistryInterface|null $menuRegistry | ||
*/ | ||
public function __construct($name, EngineInterface $templating, MenuProviderInterface $menuProvider, $menuRegistry = null) | ||
public function __construct($name, $templating, MenuProviderInterface $menuProvider, $menuRegistry = null) |
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.
Can you replace parameters with typehint and remove the comment?
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.
@kunicmarko20 i am sorry, i did not understans what you mean =( you say, that i have to replace $templating
with Environment $templating
? But exception renderers contain this type hint and your comment is the same there.
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.
@covex-nn sorry, my bad, here you can skip it but on other places you can replace comment with typehint in constructor, right?
*/ | ||
public function __construct(EngineInterface $templating, $template, $debug, $forceStyle = true) | ||
public function __construct(Environment $twig, $template, $debug, $forceStyle = true) |
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.
Can you add typehint to parameters and remove the comment?
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.
But type hint is already exists here. Removing type hint for AbstractBlockService was made for compability with other bundles (for easier upgrade). Should i remove type hint from Environment $twig
or comment @param Environment $twig Templating engine
?
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.
My comment was badly explained, I updated it. So we can typehint all parameters and remove the phpdoc comment.
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. It is public function __construct(Environment $twig, string $template, bool $debug, bool $forceStyle = true)
now without phpdoc comment
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.
Great, thank you very much!
*/ | ||
public function __construct(EngineInterface $templating, $template) | ||
public function __construct(Environment $twig, $template) |
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.
Can you add typehint to parameters and remove the comment?
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. It is public function __construct(Environment $twig, string $template)
now without phpdoc comment
src/Test/FakeTemplating.php
Outdated
@@ -20,6 +20,8 @@ | |||
* Mocking class for template usage. | |||
* | |||
* @author Thomas Rabaix <[email protected]> | |||
* | |||
* @deprecated since 4.0, to be removed with 5.0. | |||
*/ | |||
class FakeTemplating implements EngineInterface |
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.
This class is not used any more. Can i remove it instead of deprecating?
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.
Yes
return $this->getTemplating()->renderResponse($view, $parameters, $response); | ||
$response = $response ?? new Response(); | ||
|
||
$response->setContent($this->getTemplating()->render($view, $parameters)); |
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.
setContent returns the response, so you can return directly if you want :P
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.
I do not like it =) with these two lines i can set breakpoint on a second line with return $response
after setContent; with one line it won't be convenient
src/Templating/EngineInterface.php
Outdated
|
||
interface EngineInterface extends TemplatingEngineInterface | ||
/** | ||
* @deprecated since 4.0, to be removed with 5.0. |
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.
If not used, you can remove it also
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.
It is not used =)
If so, in next PR i will remove templating helper too! All methods will be copied to twig extension
Could you please rebase your PR and fix merge conflicts? |
b7c0fdb
to
88fff71
Compare
E_USER_DEPRECATED | ||
); | ||
} | ||
|
||
$this->name = $name; | ||
$this->templating = $templating; |
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.
Can this be renamed to twig? And maybe the getTemplate method too? it will be a lof of changes maybe so I am not sure, but it seems wrong
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.
I was afraid, that you would ask =) It is not a lot of changes here, in BlockBundle
, but getTemplating
could be used in other bundles.
I will rename it everywhere. Also i will make AbstractBlockService::$templating
private.
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.
@jordisala1991 done
Travis failed, because 41 is not 42 again =) Please, restart travis job https://travis-ci.org/sonata-project/SonataBlockBundle/jobs/341291098
Could you please rebase your PR and fix merge conflicts? |
@@ -34,7 +34,6 @@ | |||
"symfony/http-foundation": "^2.8 || ^3.2 || ^4.0", | |||
"symfony/http-kernel": "^2.8 || ^3.2 || ^4.0", | |||
"symfony/options-resolver": "^2.8 || ^3.2 || ^4.0", | |||
"symfony/templating": "^2.8 || ^3.2 || ^4.0", |
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.
Can you check if we can get rid of framework-bundle also? AFAIK it was used for the EngineInterface, not sure if we need it for anything else
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.
symfony/framework-bundle
is used only in Sonata\BlockBundle\Command\BaseCommand
:
namespace Sonata\BlockBundle\Command;
use Sonata\BlockBundle\Block\BlockServiceManagerInterface;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
abstract class BaseCommand extends ContainerAwareCommand { /* ... */ }
To remove dependency extends ContainerAwareCommand
could be replaced with implements \Symfony\Component\DependencyInjection\ContainerAwareInterface
here
@@ -33,7 +33,7 @@ public function testRenderWithoutDebug(): void | |||
$debug = false; | |||
$exception = $this->createMock('\Exception'); | |||
$block = $this->createMock('Sonata\BlockBundle\Model\BlockInterface'); | |||
$templating = $this->createMock('Symfony\Bundle\FrameworkBundle\Templating\EngineInterface'); | |||
$templating = $this->createMock('Twig\Environment'); |
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.
Can you use ::class notation? Only on the lines you changed. No need to fix the whole file
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.
Done. Also i renamed all $templating
to $twig
in test classes
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.
Probably the docs could be updated, and an upgrade note to know what to do when migrating from 3.x to 4.x of this Bundle.
The changelog could be simplified.
Except for this minor comments, 👍
@jordisala1991 i've updated upgrading note and some docs. But this is the most difficult part of PR =) |
UPGRADE-4.0.md
Outdated
|
||
## Block constructor | ||
|
||
Blocks are using `twig` service to render templates, so if you already overridden a constructor of a custom `AbstractBlockService`, you must update it. |
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.
"overrode"
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
Could you please rebase your PR and fix merge conflicts? |
ping @sonata-project/contributors can you review this and maybe get it merged. |
IMO 3 approvals are enough 👍 |
Thank you very much @covex-nn 👍 |
I am targeting this branch, because this is BC break.
See #456
Changelog
Subject
Switch from Templating Component to Twig, Stage 2