-
-
Notifications
You must be signed in to change notification settings - Fork 9
Remove extension, rename ViewRenderer.php
, update docs
#61
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
base: master
Are you sure you want to change the base?
Changes from all commits
ab4a767
86d82b5
4432759
83d0c31
858bb18
b9bcfaa
aba7407
6e023c9
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 |
---|---|---|
|
@@ -18,32 +18,29 @@ | |
use function str_replace; | ||
|
||
/** | ||
* `ViewRenderer` allows using Twig with a View service. | ||
* TwigTemplateRenderer allows using Twig with a View service. | ||
*/ | ||
final class ViewRenderer implements TemplateRendererInterface | ||
final class TwigTemplateRenderer implements TemplateRendererInterface | ||
{ | ||
public function __construct(private Environment $environment) | ||
public function __construct(private readonly Environment $environment) | ||
{ | ||
} | ||
|
||
public function render(ViewInterface $view, string $template, array $parameters): string | ||
{ | ||
$environment = $this->environment; | ||
$renderer = function () use ($view, $template, $parameters, $environment): void { | ||
$template = str_replace('\\', '/', $template); | ||
$basePath = str_replace('\\', '/', $view->getBasePath()); | ||
$file = str_replace($basePath, '', $template); | ||
|
||
echo $environment->render($file, array_merge($parameters, ['this' => $view])); | ||
}; | ||
$templateFile = str_replace( | ||
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. What if |
||
$view->getBasePath(), | ||
'', | ||
$template | ||
); | ||
|
||
$obInitialLevel = ob_get_level(); | ||
ob_start(); | ||
ob_implicit_flush(false); | ||
Check warning on line 39 in src/TwigTemplateRenderer.php
|
||
|
||
try { | ||
/** @psalm-suppress PossiblyInvalidFunctionCall,PossiblyNullFunctionCall */ | ||
$renderer->bindTo($view)(); | ||
$this->environment->display($templateFile, array_merge($parameters, ['this' => $view])); | ||
Check warning on line 42 in src/TwigTemplateRenderer.php
|
||
|
||
/** | ||
* @var string We assume that in this case active output buffer is always existed, so `ob_get_clean()` | ||
* returns a string. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\View\Twig\Extensions; | ||
namespace Yiisoft\View\Twig\Tests\Support; | ||
|
||
use Psr\Container\ContainerInterface; | ||
use Twig\Extension\AbstractExtension; | ||
|
@@ -11,7 +11,7 @@ | |
/** | ||
* YiiTwigExtension adds additional functionality to the Twig engine. | ||
*/ | ||
final class YiiTwigExtension extends AbstractExtension | ||
final class SimpleExtension extends AbstractExtension | ||
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.
|
||
{ | ||
public function __construct(private ContainerInterface $container) | ||
{ | ||
|
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.
Create
UPGRADE.md
also with instructions to upgrade. These changes breaks BC.