summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2019-11-30 15:37:48 +0100
committerGitHub <noreply@github.com>2019-11-30 15:37:48 +0100
commita18c7d13fcae0af77cdaef1947f2160cbf1dc56a (patch)
tree98633eb27bc514e51643766c0c4c45fc5cecfdd3 /src
parent14f8d208b817d8d7dccebdb5f7a6ada2bcb9d5f4 (diff)
parente80fb54522c307afec3d8bb474a47dd9d2d5da64 (diff)
Merge pull request #682 from MyIgel/php7.4
PHP 7.4 compatibility, PHP min version 7.2, Twig 3
Diffstat (limited to 'src')
-rw-r--r--src/Config/ConfigServiceProvider.php5
-rw-r--r--src/Controllers/Metrics/MetricsEngine.php2
-rw-r--r--src/Helpers/Authenticator.php16
-rw-r--r--src/Middleware/ErrorHandler.php12
-rw-r--r--src/Renderer/Engine.php2
-rw-r--r--src/Renderer/EngineInterface.php2
-rw-r--r--src/Renderer/Renderer.php4
-rw-r--r--src/Renderer/Twig/Extensions/Assets.php10
-rw-r--r--src/Renderer/Twig/Extensions/Authentication.php10
-rw-r--r--src/Renderer/Twig/Extensions/Config.php6
-rw-r--r--src/Renderer/Twig/Extensions/Csrf.php10
-rw-r--r--src/Renderer/Twig/Extensions/Globals.php6
-rw-r--r--src/Renderer/Twig/Extensions/Legacy.php8
-rw-r--r--src/Renderer/Twig/Extensions/Markdown.php6
-rw-r--r--src/Renderer/Twig/Extensions/Session.php6
-rw-r--r--src/Renderer/Twig/Extensions/Translation.php29
-rw-r--r--src/Renderer/Twig/Extensions/Url.php10
-rw-r--r--src/Renderer/TwigEngine.php8
-rw-r--r--src/Renderer/TwigLoader.php10
-rw-r--r--src/Renderer/TwigServiceProvider.php8
20 files changed, 75 insertions, 95 deletions
diff --git a/src/Config/ConfigServiceProvider.php b/src/Config/ConfigServiceProvider.php
index 2c320fdd..aff7918d 100644
--- a/src/Config/ConfigServiceProvider.php
+++ b/src/Config/ConfigServiceProvider.php
@@ -40,10 +40,11 @@ class ConfigServiceProvider extends ServiceProvider
continue;
}
- $config->set(array_replace_recursive(
+ $configuration = array_replace_recursive(
$config->get(null),
require $file
- ));
+ );
+ $config->set($configuration);
}
if (empty($config->get(null))) {
diff --git a/src/Controllers/Metrics/MetricsEngine.php b/src/Controllers/Metrics/MetricsEngine.php
index 8301e388..375bb096 100644
--- a/src/Controllers/Metrics/MetricsEngine.php
+++ b/src/Controllers/Metrics/MetricsEngine.php
@@ -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
{
}
}
diff --git a/src/Helpers/Authenticator.php b/src/Helpers/Authenticator.php
index db33339b..28e48500 100644
--- a/src/Helpers/Authenticator.php
+++ b/src/Helpers/Authenticator.php
@@ -25,7 +25,7 @@ class Authenticator
/** @var string[] */
protected $permissions;
- /** @var int */
+ /** @var int|string|null */
protected $passwordAlgorithm = PASSWORD_DEFAULT;
/**
@@ -163,13 +163,11 @@ class Authenticator
*/
public function verifyPassword(User $user, string $password)
{
- $algorithm = $this->passwordAlgorithm;
-
if (!password_verify($password, $user->password)) {
return false;
}
- if (password_needs_rehash($user->password, $algorithm)) {
+ if (password_needs_rehash($user->password, $this->passwordAlgorithm)) {
$this->setPassword($user, $password);
}
@@ -182,14 +180,12 @@ class Authenticator
*/
public function setPassword(User $user, string $password)
{
- $algorithm = $this->passwordAlgorithm;
-
- $user->password = password_hash($password, $algorithm);
+ $user->password = password_hash($password, $this->passwordAlgorithm);
$user->save();
}
/**
- * @return int
+ * @return int|string|null
*/
public function getPasswordAlgorithm()
{
@@ -197,9 +193,9 @@ class Authenticator
}
/**
- * @param int $passwordAlgorithm
+ * @param int|string|null $passwordAlgorithm
*/
- public function setPasswordAlgorithm(int $passwordAlgorithm)
+ public function setPasswordAlgorithm($passwordAlgorithm)
{
$this->passwordAlgorithm = $passwordAlgorithm;
}
diff --git a/src/Middleware/ErrorHandler.php b/src/Middleware/ErrorHandler.php
index 65e2e609..46e6e5a8 100644
--- a/src/Middleware/ErrorHandler.php
+++ b/src/Middleware/ErrorHandler.php
@@ -11,7 +11,7 @@ use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
-use Twig_LoaderInterface as TwigLoader;
+use Twig\Loader\LoaderInterface as TwigLoader;
class ErrorHandler implements MiddlewareInterface
{
@@ -67,13 +67,11 @@ class ErrorHandler implements MiddlewareInterface
if ($request instanceof Request) {
$session = $request->getSession();
- $session->set(
- 'errors',
- array_merge_recursive(
- $session->get('errors', []),
- ['validation' => $e->getValidator()->getErrors()]
- )
+ $errors = array_merge_recursive(
+ $session->get('errors', []),
+ ['validation' => $e->getValidator()->getErrors()]
);
+ $session->set('errors', $errors);
$session->set('form-data', Arr::except($request->request->all(), $this->formIgnore));
}
diff --git a/src/Renderer/Engine.php b/src/Renderer/Engine.php
index 60f1d686..e2ff23f2 100644
--- a/src/Renderer/Engine.php
+++ b/src/Renderer/Engine.php
@@ -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];
diff --git a/src/Renderer/EngineInterface.php b/src/Renderer/EngineInterface.php
index 3bce9c02..dd713029 100644
--- a/src/Renderer/EngineInterface.php
+++ b/src/Renderer/EngineInterface.php
@@ -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;
}
diff --git a/src/Renderer/Renderer.php b/src/Renderer/Renderer.php
index de31ca74..ccda6881 100644
--- a/src/Renderer/Renderer.php
+++ b/src/Renderer/Renderer.php
@@ -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;
}
diff --git a/src/Renderer/Twig/Extensions/Assets.php b/src/Renderer/Twig/Extensions/Assets.php
index 2cdfb0fd..04d6c9c8 100644
--- a/src/Renderer/Twig/Extensions/Assets.php
+++ b/src/Renderer/Twig/Extensions/Assets.php
@@ -3,8 +3,8 @@
namespace Engelsystem\Renderer\Twig\Extensions;
use Engelsystem\Http\UrlGenerator;
-use Twig_Extension as TwigExtension;
-use Twig_Function as TwigFunction;
+use Twig\Extension\AbstractExtension as TwigExtension;
+use Twig\TwigFunction;
class Assets extends TwigExtension
{
@@ -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, '/');
diff --git a/src/Renderer/Twig/Extensions/Authentication.php b/src/Renderer/Twig/Extensions/Authentication.php
index 538526da..061a9018 100644
--- a/src/Renderer/Twig/Extensions/Authentication.php
+++ b/src/Renderer/Twig/Extensions/Authentication.php
@@ -3,8 +3,8 @@
namespace Engelsystem\Renderer\Twig\Extensions;
use Engelsystem\Helpers\Authenticator;
-use Twig_Extension as TwigExtension;
-use Twig_Function as TwigFunction;
+use Twig\Extension\AbstractExtension as TwigExtension;
+use Twig\TwigFunction;
class Authentication extends TwigExtension
{
@@ -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();
}
diff --git a/src/Renderer/Twig/Extensions/Config.php b/src/Renderer/Twig/Extensions/Config.php
index dbbe93e7..da106957 100644
--- a/src/Renderer/Twig/Extensions/Config.php
+++ b/src/Renderer/Twig/Extensions/Config.php
@@ -3,8 +3,8 @@
namespace Engelsystem\Renderer\Twig\Extensions;
use Engelsystem\Config\Config as EngelsystemConfig;
-use Twig_Extension as TwigExtension;
-use Twig_Function as TwigFunction;
+use Twig\Extension\AbstractExtension as TwigExtension;
+use Twig\TwigFunction;
class Config extends TwigExtension
{
@@ -22,7 +22,7 @@ class Config extends TwigExtension
/**
* @return TwigFunction[]
*/
- public function getFunctions()
+ public function getFunctions(): array
{
return [
new TwigFunction('config', [$this->config, 'get']),
diff --git a/src/Renderer/Twig/Extensions/Csrf.php b/src/Renderer/Twig/Extensions/Csrf.php
index 9f77df80..fee1c1f9 100644
--- a/src/Renderer/Twig/Extensions/Csrf.php
+++ b/src/Renderer/Twig/Extensions/Csrf.php
@@ -3,8 +3,8 @@
namespace Engelsystem\Renderer\Twig\Extensions;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
-use Twig_Extension as TwigExtension;
-use Twig_Function as TwigFunction;
+use Twig\Extension\AbstractExtension as TwigExtension;
+use Twig\TwigFunction;
class Csrf extends TwigExtension
{
@@ -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');
}
diff --git a/src/Renderer/Twig/Extensions/Globals.php b/src/Renderer/Twig/Extensions/Globals.php
index ef29a819..a809682c 100644
--- a/src/Renderer/Twig/Extensions/Globals.php
+++ b/src/Renderer/Twig/Extensions/Globals.php
@@ -3,8 +3,8 @@
namespace Engelsystem\Renderer\Twig\Extensions;
use Engelsystem\Helpers\Authenticator;
-use Twig_Extension as TwigExtension;
-use Twig_Extension_GlobalsInterface as GlobalsInterface;
+use Twig\Extension\AbstractExtension as TwigExtension;
+use Twig\Extension\GlobalsInterface as GlobalsInterface;
class Globals extends TwigExtension implements GlobalsInterface
{
@@ -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();
diff --git a/src/Renderer/Twig/Extensions/Legacy.php b/src/Renderer/Twig/Extensions/Legacy.php
index 55c095fc..dc0c4775 100644
--- a/src/Renderer/Twig/Extensions/Legacy.php
+++ b/src/Renderer/Twig/Extensions/Legacy.php
@@ -3,8 +3,8 @@
namespace Engelsystem\Renderer\Twig\Extensions;
use Engelsystem\Http\Request;
-use Twig_Extension as TwigExtension;
-use Twig_Function as TwigFunction;
+use Twig\Extension\AbstractExtension as TwigExtension;
+use Twig\TwigFunction;
class Legacy extends TwigExtension
{
@@ -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');
diff --git a/src/Renderer/Twig/Extensions/Markdown.php b/src/Renderer/Twig/Extensions/Markdown.php
index 293efe91..c23a0031 100644
--- a/src/Renderer/Twig/Extensions/Markdown.php
+++ b/src/Renderer/Twig/Extensions/Markdown.php
@@ -3,8 +3,8 @@
namespace Engelsystem\Renderer\Twig\Extensions;
use Parsedown;
-use Twig_Extension as TwigExtension;
-use Twig_Filter as TwigFilter;
+use Twig\Extension\AbstractExtension as TwigExtension;
+use Twig\TwigFilter;
class Markdown extends TwigExtension
{
@@ -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));
}
diff --git a/src/Renderer/Twig/Extensions/Session.php b/src/Renderer/Twig/Extensions/Session.php
index 4690f701..77b5b55a 100644
--- a/src/Renderer/Twig/Extensions/Session.php
+++ b/src/Renderer/Twig/Extensions/Session.php
@@ -3,8 +3,8 @@
namespace Engelsystem\Renderer\Twig\Extensions;
use Symfony\Component\HttpFoundation\Session\Session as SymfonySession;
-use Twig_Extension as TwigExtension;
-use Twig_Function as TwigFunction;
+use Twig\Extension\AbstractExtension as TwigExtension;
+use Twig\TwigFunction;
class Session extends TwigExtension
{
@@ -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']),
diff --git a/src/Renderer/Twig/Extensions/Translation.php b/src/Renderer/Twig/Extensions/Translation.php
index 3e6f30b4..fff3bfa9 100644
--- a/src/Renderer/Twig/Extensions/Translation.php
+++ b/src/Renderer/Twig/Extensions/Translation.php
@@ -3,34 +3,27 @@
namespace Engelsystem\Renderer\Twig\Extensions;
use Engelsystem\Helpers\Translation\Translator;
-use Twig_Extension as TwigExtension;
-use Twig_Extensions_TokenParser_Trans as TranslationTokenParser;
-use Twig_Filter as TwigFilter;
-use Twig_Function as TwigFunction;
-use Twig_TokenParserInterface as TwigTokenParser;
+use Twig\Extension\AbstractExtension as TwigExtension;
+use Twig\TwigFilter;
+use Twig\TwigFunction;
class Translation extends TwigExtension
{
/** @var Translator */
protected $translator;
- /** @var TranslationTokenParser */
- protected $tokenParser;
-
/**
- * @param Translator $translator
- * @param TranslationTokenParser $tokenParser
+ * @param Translator $translator
*/
- public function __construct(Translator $translator, TranslationTokenParser $tokenParser)
+ public function __construct(Translator $translator)
{
$this->translator = $translator;
- $this->tokenParser = $tokenParser;
}
/**
* @return array
*/
- public function getFilters()
+ public function getFilters(): array
{
return [
new TwigFilter('trans', [$this->translator, 'translate']),
@@ -40,19 +33,11 @@ class Translation extends TwigExtension
/**
* @return TwigFunction[]
*/
- public function getFunctions()
+ public function getFunctions(): array
{
return [
new TwigFunction('__', [$this->translator, 'translate']),
new TwigFunction('_e', [$this->translator, 'translatePlural']),
];
}
-
- /**
- * @return TwigTokenParser[]
- */
- public function getTokenParsers()
- {
- return [$this->tokenParser];
- }
}
diff --git a/src/Renderer/Twig/Extensions/Url.php b/src/Renderer/Twig/Extensions/Url.php
index 62e59782..17fd6ff0 100644
--- a/src/Renderer/Twig/Extensions/Url.php
+++ b/src/Renderer/Twig/Extensions/Url.php
@@ -3,8 +3,8 @@
namespace Engelsystem\Renderer\Twig\Extensions;
use Engelsystem\Http\UrlGenerator;
-use Twig_Extension as TwigExtension;
-use Twig_Function as TwigFunction;
+use Twig\Extension\AbstractExtension as TwigExtension;
+use Twig\TwigFunction;
class Url extends TwigExtension
{
@@ -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);
diff --git a/src/Renderer/TwigEngine.php b/src/Renderer/TwigEngine.php
index aa51a177..2c77e54f 100644
--- a/src/Renderer/TwigEngine.php
+++ b/src/Renderer/TwigEngine.php
@@ -2,10 +2,10 @@
namespace Engelsystem\Renderer;
-use Twig_Environment as Twig;
-use Twig_Error_Loader as LoaderError;
-use Twig_Error_Runtime as RuntimeError;
-use Twig_Error_Syntax as SyntaxError;
+use Twig\Environment as Twig;
+use Twig\Error\LoaderError as LoaderError;
+use Twig\Error\RuntimeError as RuntimeError;
+use Twig\Error\SyntaxError as SyntaxError;
class TwigEngine extends Engine
{
diff --git a/src/Renderer/TwigLoader.php b/src/Renderer/TwigLoader.php
index f20a8764..1bcbbd71 100644
--- a/src/Renderer/TwigLoader.php
+++ b/src/Renderer/TwigLoader.php
@@ -2,18 +2,18 @@
namespace Engelsystem\Renderer;
-use Twig_Error_Loader;
-use Twig_Loader_Filesystem as FilesystemLoader;
+use Twig\Error\LoaderError as ErrorLoader;
+use Twig\Loader\FilesystemLoader as FilesystemLoader;
class TwigLoader extends FilesystemLoader
{
/**
* @param string $name
* @param bool $throw
- * @return false|string
- * @throws Twig_Error_Loader
+ * @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);
diff --git a/src/Renderer/TwigServiceProvider.php b/src/Renderer/TwigServiceProvider.php
index 6cd885fd..d4e4a939 100644
--- a/src/Renderer/TwigServiceProvider.php
+++ b/src/Renderer/TwigServiceProvider.php
@@ -14,9 +14,9 @@ use Engelsystem\Renderer\Twig\Extensions\Markdown;
use Engelsystem\Renderer\Twig\Extensions\Session;
use Engelsystem\Renderer\Twig\Extensions\Translation;
use Engelsystem\Renderer\Twig\Extensions\Url;
-use Twig_Environment as Twig;
-use Twig_Extension_Core as TwigCore;
-use Twig_LoaderInterface as TwigLoaderInterface;
+use Twig\Environment as Twig;
+use Twig\Extension\CoreExtension as TwigCore;
+use Twig\Loader\LoaderInterface as TwigLoaderInterface;
class TwigServiceProvider extends ServiceProvider
{
@@ -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;