diff --git a/.travis.yml b/.travis.yml index 617ac22b..f9e19b89 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,6 @@ branches: - develop php: - - 5.6 - 7 - 7.1 - 7.2 diff --git a/composer.json b/composer.json index 226419e7..1f1d5303 100644 --- a/composer.json +++ b/composer.json @@ -13,39 +13,40 @@ ], "require": { "php": "^7.0", - "roave/security-advisories": "dev-master", - "zendframework/zend-expressive": "^2.0", - "zendframework/zend-expressive-fastroute": "^2.0", - "zendframework/zend-expressive-twigrenderer": "^1.4", - "zendframework/zend-stdlib": "^3.0", - "zendframework/zend-servicemanager": "^3.0", - "zendframework/zend-paginator": "^2.6", - "zendframework/zend-config": "^3.0", - "zendframework/zend-i18n": "^2.7", - "zendframework/zend-config-aggregator": "^0.1", "acelaya/ze-content-based-error-handler": "^2.0", - "doctrine/orm": "^2.5 <2.6", - "doctrine/dbal": "^2.5 <2.6", "doctrine/annotations": "^1.4 <1.5", + "doctrine/cache": "^1.6 <1.7", "doctrine/collections": "^1.4 <1.5", "doctrine/common": "^2.7 <2.8", - "doctrine/cache": "^1.6 <1.7", - "guzzlehttp/guzzle": "^6.2", - "symfony/console": "^3.0", - "symfony/process": "^3.0", - "symfony/filesystem": "^3.0", - "firebase/php-jwt": "^4.0", - "monolog/monolog": "^1.21", - "theorchard/monolog-cascade": "^0.4", - "endroid/qrcode": "^1.7", - "mikehaertl/phpwkhtmltopdf": "^2.2", + "doctrine/dbal": "^2.5 <2.6", "doctrine/migrations": "^1.4", - "http-interop/http-middleware": "^0.4.1" + "doctrine/orm": "^2.5 <2.6", + "endroid/qrcode": "^1.7", + "firebase/php-jwt": "^4.0", + "guzzlehttp/guzzle": "^6.2", + "http-interop/http-middleware": "^0.4.1", + "mikehaertl/phpwkhtmltopdf": "^2.2", + "monolog/monolog": "^1.21", + "roave/security-advisories": "dev-master", + "symfony/console": "^3.0", + "symfony/filesystem": "^3.0", + "symfony/process": "^3.0", + "theorchard/monolog-cascade": "^0.4", + "zendframework/zend-config": "^3.0", + "zendframework/zend-config-aggregator": "^0.1", + "zendframework/zend-expressive": "^2.0", + "zendframework/zend-expressive-fastroute": "^2.0", + "zendframework/zend-expressive-helpers": "^4.2", + "zendframework/zend-expressive-platesrenderer": "^1.3", + "zendframework/zend-i18n": "^2.7", + "zendframework/zend-paginator": "^2.6", + "zendframework/zend-servicemanager": "^3.0", + "zendframework/zend-stdlib": "^3.0" }, "require-dev": { - "phpunit/phpunit": "^5.7 || ^6.0", - "squizlabs/php_codesniffer": "^3.1", "filp/whoops": "^2.0", + "phpunit/phpunit": "^6.0", + "squizlabs/php_codesniffer": "^3.1", "symfony/var-dumper": "^3.0", "vlucas/phpdotenv": "^2.2", "zendframework/zend-expressive-tooling": "^0.4" @@ -81,6 +82,7 @@ "pretty-test": "phpunit --coverage-html build/coverage" }, "config": { - "process-timeout": 0 + "process-timeout": 0, + "sort-packages": true } } diff --git a/config/autoload/dependencies.global.php b/config/autoload/dependencies.global.php index 83a893dc..c918544d 100644 --- a/config/autoload/dependencies.global.php +++ b/config/autoload/dependencies.global.php @@ -1,11 +1,15 @@ [ 'factories' => [ Expressive\Application::class => Container\ApplicationFactory::class, - Template\TemplateRendererInterface::class => Twig\TwigRendererFactory::class, - \Twig_Environment::class => Twig\TwigEnvironmentFactory::class, + Template\TemplateRendererInterface::class => Plates\PlatesRendererFactory::class, Router\RouterInterface::class => Router\FastRouteRouterFactory::class, ErrorHandler::class => Container\ErrorHandlerFactory::class, Middleware\ImplicitOptionsMiddleware::class => EmptyResponseImplicitOptionsMiddlewareFactory::class, + + Helper\UrlHelper::class => Helper\UrlHelperFactory::class, + Helper\ServerUrlHelper::class => InvokableFactory::class, ], ], diff --git a/config/autoload/templates.global.php b/config/autoload/templates.global.php index f102baa0..cf8e404b 100644 --- a/config/autoload/templates.global.php +++ b/config/autoload/templates.global.php @@ -2,8 +2,8 @@ return [ - 'twig' => [ - 'cache_dir' => 'data/cache/twig', + 'templates' => [ + 'extension' => 'phtml', 'extensions' => [ // extension service names or instances ], diff --git a/module/Common/config/dependencies.config.php b/module/Common/config/dependencies.config.php index dd64b026..dd89b481 100644 --- a/module/Common/config/dependencies.config.php +++ b/module/Common/config/dependencies.config.php @@ -9,7 +9,7 @@ use Shlinkio\Shlink\Common\Image; use Shlinkio\Shlink\Common\Image\ImageBuilder; use Shlinkio\Shlink\Common\Middleware\LocaleMiddleware; use Shlinkio\Shlink\Common\Service; -use Shlinkio\Shlink\Common\Twig\Extension\TranslatorExtension; +use Shlinkio\Shlink\Common\Template\Extension\TranslatorExtension; use Symfony\Component\Filesystem\Filesystem; use Zend\I18n\Translator\Translator; use Zend\ServiceManager\AbstractFactory\ConfigAbstractFactory; diff --git a/module/Common/config/templates.config.php b/module/Common/config/templates.config.php index 903c1e8c..37a6714d 100644 --- a/module/Common/config/templates.config.php +++ b/module/Common/config/templates.config.php @@ -1,9 +1,11 @@ [ + 'templates' => [ 'extensions' => [ TranslatorExtension::class, ], diff --git a/module/Common/src/Template/Extension/TranslatorExtension.php b/module/Common/src/Template/Extension/TranslatorExtension.php new file mode 100644 index 00000000..01fbeeed --- /dev/null +++ b/module/Common/src/Template/Extension/TranslatorExtension.php @@ -0,0 +1,25 @@ +translator = $translator; + } + + public function register(Engine $engine) + { + $engine->registerFunction('translate', [$this->translator, 'translate']); + $engine->registerFunction('translate_plural', [$this->translator, 'translatePlural']); + } +} diff --git a/module/Common/src/Twig/Extension/TranslatorExtension.php b/module/Common/src/Twig/Extension/TranslatorExtension.php deleted file mode 100644 index 807c3099..00000000 --- a/module/Common/src/Twig/Extension/TranslatorExtension.php +++ /dev/null @@ -1,68 +0,0 @@ -translator = $translator; - } - - /** - * Returns the name of the extension. - * - * @return string The extension name - */ - public function getName() - { - return __CLASS__; - } - - public function getFunctions() - { - return [ - new \Twig_SimpleFunction('translate', [$this, 'translate']), - new \Twig_SimpleFunction('translate_plural', [$this, 'translatePlural']), - ]; - } - - /** - * Translate a message. - * - * @param string $message - * @param string $textDomain - * @param string $locale - * @return string - */ - public function translate($message, $textDomain = 'default', $locale = null) - { - return $this->translator->translate($message, $textDomain, $locale); - } - - /** - * Translate a plural message. - * - * @param string $singular - * @param string $plural - * @param int $number - * @param string $textDomain - * @param string|null $locale - * @return string - */ - public function translatePlural( - $singular, - $plural, - $number, - $textDomain = 'default', - $locale = null - ) { - $this->translator->translatePlural($singular, $plural, $number, $textDomain, $locale); - } -} diff --git a/module/Common/test/ConfigProviderTest.php b/module/Common/test/ConfigProviderTest.php index 05b5da49..65a62a01 100644 --- a/module/Common/test/ConfigProviderTest.php +++ b/module/Common/test/ConfigProviderTest.php @@ -24,6 +24,6 @@ class ConfigProviderTest extends TestCase $config = $this->configProvider->__invoke(); $this->assertArrayHasKey('dependencies', $config); - $this->assertArrayHasKey('twig', $config); + $this->assertArrayHasKey('templates', $config); } } diff --git a/module/Common/test/Template/Extension/TranslatorExtensionTest.php b/module/Common/test/Template/Extension/TranslatorExtensionTest.php new file mode 100644 index 00000000..e39e2b24 --- /dev/null +++ b/module/Common/test/Template/Extension/TranslatorExtensionTest.php @@ -0,0 +1,34 @@ +extension = new TranslatorExtension($this->prophesize(Translator::class)->reveal()); + } + + /** + * @test + */ + public function properFunctionsAreReturned() + { + $engine = $this->prophesize(Engine::class); + + $engine->registerFunction('translate', Argument::type('callable'))->shouldBeCalledTimes(1); + $engine->registerFunction('translate_plural', Argument::type('callable'))->shouldBeCalledTimes(1); + + $funcs = $this->extension->register($engine->reveal()); + } +} diff --git a/module/Common/test/Twig/Extension/TranslatorExtensionTest.php b/module/Common/test/Twig/Extension/TranslatorExtensionTest.php deleted file mode 100644 index 46dc2ec8..00000000 --- a/module/Common/test/Twig/Extension/TranslatorExtensionTest.php +++ /dev/null @@ -1,70 +0,0 @@ -translator = $this->prophesize(Translator::class); - $this->extension = new TranslatorExtension($this->translator->reveal()); - } - - /** - * @test - */ - public function extensionNameIsClassName() - { - $this->assertEquals(TranslatorExtension::class, $this->extension->getName()); - } - - /** - * @test - */ - public function properFunctionsAreReturned() - { - $funcs = $this->extension->getFunctions(); - $this->assertCount(2, $funcs); - foreach ($funcs as $func) { - $this->assertInstanceOf(\Twig_SimpleFunction::class, $func); - } - } - - /** - * @test - */ - public function translateFallbacksToTranslator() - { - $this->translator->translate('foo', 'default', null)->shouldBeCalledTimes(1); - $this->extension->translate('foo'); - - $this->translator->translate('bar', 'baz', 'en')->shouldBeCalledTimes(1); - $this->extension->translate('bar', 'baz', 'en'); - } - - /** - * @test - */ - public function translatePluralFallbacksToTranslator() - { - $this->translator->translatePlural('foo', 'bar', 'baz', 'default', null)->shouldBeCalledTimes(1); - $this->extension->translatePlural('foo', 'bar', 'baz'); - - $this->translator->translatePlural('foo', 'bar', 'baz', 'another', 'en')->shouldBeCalledTimes(1); - $this->extension->translatePlural('foo', 'bar', 'baz', 'another', 'en'); - } -} diff --git a/module/Core/config/templates.config.php b/module/Core/config/templates.config.php index da3623c1..d5e6677e 100644 --- a/module/Core/config/templates.config.php +++ b/module/Core/config/templates.config.php @@ -4,7 +4,7 @@ return [ 'templates' => [ 'paths' => [ - 'module/Core/templates', + 'ShlinkCore' => __DIR__ . '/../templates', ], ], diff --git a/module/Core/config/zend-expressive.config.php b/module/Core/config/zend-expressive.config.php index c5fefe8f..3dfd091f 100644 --- a/module/Core/config/zend-expressive.config.php +++ b/module/Core/config/zend-expressive.config.php @@ -4,8 +4,8 @@ return [ 'zend-expressive' => [ 'error_handler' => [ - 'template_404' => 'core/error/404.html.twig', - 'template_error' => 'core/error/error.html.twig', + 'template_404' => 'ShlinkCore::error/404', + 'template_error' => 'ShlinkCore::error/error', ], ], diff --git a/module/Core/templates/core/error/404.html.twig b/module/Core/templates/error/404.html.twig similarity index 100% rename from module/Core/templates/core/error/404.html.twig rename to module/Core/templates/error/404.html.twig diff --git a/module/Core/templates/core/error/error.html.twig b/module/Core/templates/error/error.html.twig similarity index 100% rename from module/Core/templates/core/error/error.html.twig rename to module/Core/templates/error/error.html.twig diff --git a/module/Core/templates/core/layout/default.html.twig b/module/Core/templates/layout/default.html.twig similarity index 100% rename from module/Core/templates/core/layout/default.html.twig rename to module/Core/templates/layout/default.html.twig