Twig update to 3.0.0 and Renderer type hinting
This commit is contained in:
parent
15e6740e12
commit
577c052aff
|
@ -40,7 +40,7 @@
|
|||
"swiftmailer/swiftmailer": "^6.2",
|
||||
"symfony/http-foundation": "^4.3",
|
||||
"symfony/psr-http-message-bridge": "^1.2",
|
||||
"twig/twig": "^2.11",
|
||||
"twig/twig": "^3.0",
|
||||
"vlucas/phpdotenv": "^3.3"
|
||||
},
|
||||
"require-dev": {
|
||||
|
|
|
@ -142,7 +142,7 @@ class MetricsEngine implements EngineInterface
|
|||
* @param string|mixed[] $key
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function share($key, $value = null)
|
||||
public function share($key, $value = null): void
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ abstract class Engine implements EngineInterface
|
|||
* @param mixed[]|string $key
|
||||
* @param null $value
|
||||
*/
|
||||
public function share($key, $value = null)
|
||||
public function share($key, $value = null): void
|
||||
{
|
||||
if (!is_array($key)) {
|
||||
$key = [$key => $value];
|
||||
|
|
|
@ -23,5 +23,5 @@ interface EngineInterface
|
|||
* @param string|mixed[] $key
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function share($key, $value = null);
|
||||
public function share($key, $value = null): void;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ class Renderer
|
|||
* @param mixed[] $data
|
||||
* @return string
|
||||
*/
|
||||
public function render($template, $data = [])
|
||||
public function render(string $template, array $data = []): string
|
||||
{
|
||||
foreach ($this->renderer as $renderer) {
|
||||
if (!$renderer->canRender($template)) {
|
||||
|
@ -40,7 +40,7 @@ class Renderer
|
|||
*
|
||||
* @param EngineInterface $renderer
|
||||
*/
|
||||
public function addRenderer(EngineInterface $renderer)
|
||||
public function addRenderer(EngineInterface $renderer): void
|
||||
{
|
||||
$this->renderer[] = $renderer;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ class Assets extends TwigExtension
|
|||
/**
|
||||
* @return TwigFunction[]
|
||||
*/
|
||||
public function getFunctions()
|
||||
public function getFunctions(): array
|
||||
{
|
||||
return [
|
||||
new TwigFunction('asset', [$this, 'getAsset']),
|
||||
|
@ -31,9 +31,9 @@ class Assets extends TwigExtension
|
|||
|
||||
/**
|
||||
* @param string $path
|
||||
* @return UrlGenerator|string
|
||||
* @return string
|
||||
*/
|
||||
public function getAsset($path)
|
||||
public function getAsset(string $path): string
|
||||
{
|
||||
$path = ltrim($path, '/');
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ class Authentication extends TwigExtension
|
|||
/**
|
||||
* @return TwigFunction[]
|
||||
*/
|
||||
public function getFunctions()
|
||||
public function getFunctions(): array
|
||||
{
|
||||
return [
|
||||
new TwigFunction('is_user', [$this, 'isAuthenticated']),
|
||||
|
@ -34,7 +34,7 @@ class Authentication extends TwigExtension
|
|||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isAuthenticated()
|
||||
public function isAuthenticated(): bool
|
||||
{
|
||||
return (bool)$this->auth->user();
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ class Authentication extends TwigExtension
|
|||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isGuest()
|
||||
public function isGuest(): bool
|
||||
{
|
||||
return !$this->isAuthenticated();
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ class Config extends TwigExtension
|
|||
/**
|
||||
* @return TwigFunction[]
|
||||
*/
|
||||
public function getFunctions()
|
||||
public function getFunctions(): array
|
||||
{
|
||||
return [
|
||||
new TwigFunction('config', [$this->config, 'get']),
|
||||
|
|
|
@ -22,7 +22,7 @@ class Csrf extends TwigExtension
|
|||
/**
|
||||
* @return TwigFunction[]
|
||||
*/
|
||||
public function getFunctions()
|
||||
public function getFunctions(): array
|
||||
{
|
||||
return [
|
||||
new TwigFunction('csrf', [$this, 'getCsrfField'], ['is_safe' => ['html']]),
|
||||
|
@ -33,7 +33,7 @@ class Csrf extends TwigExtension
|
|||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCsrfField()
|
||||
public function getCsrfField(): string
|
||||
{
|
||||
return sprintf('<input type="hidden" name="_token" value="%s">', $this->getCsrfToken());
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ class Csrf extends TwigExtension
|
|||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCsrfToken()
|
||||
public function getCsrfToken(): string
|
||||
{
|
||||
return $this->session->get('_token');
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ class Globals extends TwigExtension implements GlobalsInterface
|
|||
*
|
||||
* @return array An array of global variables
|
||||
*/
|
||||
public function getGlobals()
|
||||
public function getGlobals(): array
|
||||
{
|
||||
$user = $this->auth->user();
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ class Legacy extends TwigExtension
|
|||
/**
|
||||
* @return TwigFunction[]
|
||||
*/
|
||||
public function getFunctions()
|
||||
public function getFunctions(): array
|
||||
{
|
||||
$isSafeHtml = ['is_safe' => ['html']];
|
||||
return [
|
||||
|
@ -39,7 +39,7 @@ class Legacy extends TwigExtension
|
|||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getPage()
|
||||
public function getPage(): string
|
||||
{
|
||||
if ($this->request->has('p')) {
|
||||
return $this->request->get('p');
|
||||
|
|
|
@ -36,7 +36,7 @@ class Markdown extends TwigExtension
|
|||
* @param string $text
|
||||
* @return string
|
||||
*/
|
||||
public function render($text): string
|
||||
public function render(string $text): string
|
||||
{
|
||||
return $this->renderer->text(htmlspecialchars($text));
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ class Session extends TwigExtension
|
|||
/**
|
||||
* @return TwigFunction[]
|
||||
*/
|
||||
public function getFunctions()
|
||||
public function getFunctions(): array
|
||||
{
|
||||
return [
|
||||
new TwigFunction('session_get', [$this->session, 'get']),
|
||||
|
|
|
@ -23,7 +23,7 @@ class Translation extends TwigExtension
|
|||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getFilters()
|
||||
public function getFilters(): array
|
||||
{
|
||||
return [
|
||||
new TwigFilter('trans', [$this->translator, 'translate']),
|
||||
|
@ -33,7 +33,7 @@ class Translation extends TwigExtension
|
|||
/**
|
||||
* @return TwigFunction[]
|
||||
*/
|
||||
public function getFunctions()
|
||||
public function getFunctions(): array
|
||||
{
|
||||
return [
|
||||
new TwigFunction('__', [$this->translator, 'translate']),
|
||||
|
|
|
@ -22,7 +22,7 @@ class Url extends TwigExtension
|
|||
/**
|
||||
* @return TwigFunction[]
|
||||
*/
|
||||
public function getFunctions()
|
||||
public function getFunctions(): array
|
||||
{
|
||||
return [
|
||||
new TwigFunction('url', [$this, 'getUrl']),
|
||||
|
@ -32,9 +32,9 @@ class Url extends TwigExtension
|
|||
/**
|
||||
* @param string $path
|
||||
* @param array $parameters
|
||||
* @return UrlGenerator|string
|
||||
* @return string
|
||||
*/
|
||||
public function getUrl($path, $parameters = [])
|
||||
public function getUrl(string $path, array $parameters = []): string
|
||||
{
|
||||
$path = str_replace('_', '-', $path);
|
||||
|
||||
|
|
|
@ -10,10 +10,10 @@ class TwigLoader extends FilesystemLoader
|
|||
/**
|
||||
* @param string $name
|
||||
* @param bool $throw
|
||||
* @return string|false|null
|
||||
* @return string|null
|
||||
* @throws ErrorLoader
|
||||
*/
|
||||
public function findTemplate($name, $throw = true)
|
||||
public function findTemplate(string $name, bool $throw = true): ?string
|
||||
{
|
||||
$extension = '.twig';
|
||||
$extensionLength = mb_strlen($extension);
|
||||
|
|
|
@ -95,7 +95,7 @@ class TwigServiceProvider extends ServiceProvider
|
|||
* @param string $class
|
||||
* @param string $alias
|
||||
*/
|
||||
protected function registerTwigExtensions($class, $alias)
|
||||
protected function registerTwigExtensions(string $class, string $alias)
|
||||
{
|
||||
$alias = 'twig.extension.' . $alias;
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ use ReflectionClass as Reflection;
|
|||
use ReflectionException;
|
||||
use stdClass;
|
||||
use Twig\Environment as Twig;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\Extension\CoreExtension as TwigCore;
|
||||
use Twig\Extension\ExtensionInterface as ExtensionInterface;
|
||||
use Twig\Loader\LoaderInterface as TwigLoaderInterface;
|
||||
|
@ -103,9 +104,15 @@ class TwigServiceProviderTest extends ServiceProviderTest
|
|||
/** @var Config|MockObject $config */
|
||||
$config = $this->createMock(Config::class);
|
||||
/** @var TwigCore|MockObject $twigCore */
|
||||
$twigCore = $this->getMockBuilder(stdClass::class)
|
||||
->addMethods(['setTimezone'])
|
||||
->getMock();
|
||||
$twigCore = $this->getMockForAbstractClass(
|
||||
AbstractExtension::class,
|
||||
[],
|
||||
'',
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
['setTimezone']
|
||||
);
|
||||
|
||||
$app = $this->getApp(['make', 'instance', 'tag', 'get']);
|
||||
|
||||
|
|
Loading…
Reference in New Issue