diff --git a/.gitignore b/.gitignore index 7a79dae..56cb612 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ vendor/ build/ composer.lock .DS_Store +.php_cs.cache diff --git a/.php_cs b/.php_cs index 59aca3b..fb41ffa 100644 --- a/.php_cs +++ b/.php_cs @@ -7,126 +7,125 @@ This file is part of the Madapaja.TwigModule package. EOF; return \PhpCsFixer\Config::create() - ->setRiskyAllowed(true) - ->setRules(array( - '@PSR2' => true, - 'header_comment' => ['header' => $header, 'commentType' => 'PHPDoc', 'separate' => 'none'], - 'array_syntax' => ['syntax' => 'short'], - 'binary_operator_spaces' => ['align_equals' => false, 'align_double_arrow' => false], - 'blank_line_after_opening_tag' => true, - 'blank_line_after_namespace' => false, - 'blank_line_before_return' => true, - 'cast_spaces' => true, - // 'class_keyword_remove' => true, - 'combine_consecutive_unsets' => true, - 'concat_space' => ['spacing' => 'one'], - 'declare_equal_normalize' => true, - 'declare_strict_types' => false, - 'dir_constant' => true, - 'ereg_to_preg' => true, - 'function_typehint_space' => true, - 'general_phpdoc_annotation_remove' => true, - 'hash_to_slash_comment' => true, - 'heredoc_to_nowdoc' => true, - 'include' => true, - 'indentation_type' => true, - 'is_null' => ['use_yoda_style' => false], - 'linebreak_after_opening_tag' => true, - 'lowercase_cast' => true, - // 'mb_str_functions' => true, - 'method_separation' => true, - 'modernize_types_casting' => true, - 'native_function_casing' => true, - // 'native_function_invocation' => true, - 'new_with_braces' => false, // - 'no_alias_functions' => true, - 'no_blank_lines_after_class_opening' => true, - 'no_blank_lines_after_phpdoc' => true, - 'no_blank_lines_before_namespace' => true, - 'no_empty_comment' => true, - 'no_empty_phpdoc' => true, - 'no_empty_statement' => true, - 'no_extra_consecutive_blank_lines' => ['break', 'continue', 'curly_brace_block', 'extra', 'parenthesis_brace_block', 'return', 'square_brace_block', 'throw', 'use', 'useTrait'], - 'no_leading_import_slash' => true, - 'no_leading_namespace_whitespace' => true, - 'no_mixed_echo_print' => ['use' => 'echo'], - 'no_multiline_whitespace_around_double_arrow' => true, - 'no_multiline_whitespace_before_semicolons' => true, - 'no_php4_constructor' => false, - 'no_short_bool_cast' => true, - 'no_short_echo_tag' => false, - 'no_singleline_whitespace_before_semicolons' => true, - 'no_spaces_around_offset' => true, - 'no_trailing_comma_in_list_call' => true, - 'no_trailing_comma_in_singleline_array' => true, - 'no_trailing_whitespace' => true, - 'no_trailing_whitespace_in_comment' => true, - 'no_unneeded_control_parentheses' => true, - 'no_unreachable_default_argument_value' => true, - 'no_unused_imports' => true, - 'no_useless_else' => true, - 'no_useless_return' => true, - 'no_whitespace_before_comma_in_array' => true, - 'no_whitespace_in_blank_line' => true, - 'normalize_index_brace' => true, - 'not_operator_with_space' => false, - 'not_operator_with_successor_space' => true, - 'object_operator_without_whitespace' => true, - 'ordered_class_elements' => true, - 'ordered_imports' => true, - 'php_unit_construct' => true, - 'php_unit_dedicate_assert' => true, - 'php_unit_fqcn_annotation' => true, - 'php_unit_strict' => true, - // 'phpdoc_add_missing_param_annotation' => true, - 'phpdoc_align' => true, - 'phpdoc_annotation_without_dot' => true, - 'phpdoc_indent' => true, - 'phpdoc_inline_tag' => true, - 'phpdoc_no_access' => true, - 'phpdoc_no_alias_tag' => ['property-read' => 'property', 'property-write' => 'property', 'type' => 'var'], - 'phpdoc_no_empty_return' => true, - 'phpdoc_no_package' => true, - // 'phpdoc_no_useless_inheritdoc' => true, - 'phpdoc_order' => true, - 'phpdoc_return_self_reference' => true, - 'phpdoc_scalar' => true, - 'phpdoc_separation' => true, - 'phpdoc_single_line_var_spacing' => true, - // 'phpdoc_summary' => true, - 'phpdoc_to_comment' => true, - 'phpdoc_trim' => true, - 'phpdoc_types' => true, - 'phpdoc_var_without_name' => true, - 'pow_to_exponentiation' => true, - // 'pre_increment' => true, - 'protected_to_private' => true, - 'psr0' => true, - 'psr4' => true, - 'random_api_migration' => true, - 'return_type_declaration' => ['space_before' => 'one'], - 'self_accessor' => true, - 'short_scalar_cast' => true, - // 'silenced_deprecation_error' => true, - // 'simplified_null_return' => true, - // 'single_blank_line_before_namespace' => true, - 'single_quote' => true, - 'space_after_semicolon' => true, - 'standardize_not_equals' => true, - // 'strict_comparison' => true, - 'ternary_operator_spaces' => true, - 'strict_param' => true, - 'ternary_to_null_coalescing' => true, - // 'trailing_comma_in_multiline_array' => true, - 'trim_array_spaces' => true, - 'unary_operator_spaces' => true, - 'whitespace_after_comma_in_array' => true - )) - ->setFinder( - PhpCsFixer\Finder::create() - ->exclude('tests/Fake') - ->exclude('src-data') - ->exclude('src-deprecated') - ->in(__DIR__) - )->setLineEnding("\n") - ->setUsingCache(false); + ->setRiskyAllowed(true) + ->setRules(array( + '@PSR2' => true, + 'header_comment' => ['header' => $header, 'commentType' => 'PHPDoc', 'separate' => 'none'], + 'array_syntax' => ['syntax' => 'short'], + 'binary_operator_spaces' => ['align_equals' => false, 'align_double_arrow' => false], + 'blank_line_after_opening_tag' => true, + 'blank_line_after_namespace' => false, + 'blank_line_before_return' => true, + 'cast_spaces' => true, +// 'class_keyword_remove' => true, + 'combine_consecutive_unsets' => true, + 'concat_space' => ['spacing' => 'one'], + 'declare_equal_normalize' => true, + 'declare_strict_types' => false, + 'dir_constant' => true, + 'ereg_to_preg' => true, + 'function_typehint_space' => true, + 'general_phpdoc_annotation_remove' => true, + 'hash_to_slash_comment' => true, + 'heredoc_to_nowdoc' => true, + 'include' => true, + 'indentation_type' => true, + 'is_null' => ['use_yoda_style' => false], + 'linebreak_after_opening_tag' => true, + 'lowercase_cast' => true, +// 'mb_str_functions' => true, + 'method_separation' => true, + 'modernize_types_casting' => true, + 'native_function_casing' => true, + 'native_function_invocation' => true, + 'new_with_braces' => false, // + 'no_alias_functions' => true, + 'no_blank_lines_after_class_opening' => true, + 'no_blank_lines_after_phpdoc' => true, + 'no_blank_lines_before_namespace' => true, + 'no_empty_comment' => true, + 'no_empty_phpdoc' => true, + 'no_empty_statement' => true, + 'no_extra_consecutive_blank_lines' => ['break', 'continue', 'curly_brace_block', 'extra', 'parenthesis_brace_block', 'return', 'square_brace_block', 'throw', 'use', 'useTrait'], + 'no_leading_import_slash' => true, + 'no_leading_namespace_whitespace' => true, + 'no_mixed_echo_print' => ['use' => 'echo'], + 'no_multiline_whitespace_around_double_arrow' => true, + 'no_multiline_whitespace_before_semicolons' => true, + 'no_php4_constructor' => false, + 'no_short_bool_cast' => true, + 'no_short_echo_tag' => false, + 'no_singleline_whitespace_before_semicolons' => true, + 'no_spaces_around_offset' => true, + 'no_trailing_comma_in_list_call' => true, + 'no_trailing_comma_in_singleline_array' => true, + 'no_trailing_whitespace' => true, + 'no_trailing_whitespace_in_comment' => true, + 'no_unneeded_control_parentheses' => true, + 'no_unreachable_default_argument_value' => true, + 'no_unused_imports' => true, + 'no_useless_else' => true, + 'no_useless_return' => true, + 'no_whitespace_before_comma_in_array' => true, + 'no_whitespace_in_blank_line' => true, + 'normalize_index_brace' => true, + 'not_operator_with_space' => false, + 'not_operator_with_successor_space' => true, + 'object_operator_without_whitespace' => true, + 'ordered_class_elements' => true, + 'ordered_imports' => true, + 'php_unit_construct' => true, + 'php_unit_dedicate_assert' => true, + 'php_unit_fqcn_annotation' => true, + 'php_unit_strict' => true, + 'phpdoc_add_missing_param_annotation' => true, + 'phpdoc_align' => true, + 'phpdoc_annotation_without_dot' => true, + 'phpdoc_indent' => true, + 'phpdoc_inline_tag' => true, + 'phpdoc_no_access' => true, + 'phpdoc_no_alias_tag' => ['property-read' => 'property', 'property-write' => 'property', 'type' => 'var'], + 'phpdoc_no_empty_return' => true, + 'phpdoc_no_package' => true, + 'phpdoc_no_useless_inheritdoc' => true, + 'phpdoc_order' => true, + 'phpdoc_return_self_reference' => true, + 'phpdoc_scalar' => true, + 'phpdoc_separation' => true, + 'phpdoc_single_line_var_spacing' => true, +// 'phpdoc_summary' => true, + 'phpdoc_to_comment' => true, + 'phpdoc_trim' => true, + 'phpdoc_types' => true, + 'phpdoc_var_without_name' => true, + 'pow_to_exponentiation' => true, +// 'pre_increment' => true, + 'protected_to_private' => true, + 'psr0' => true, + 'psr4' => true, + 'random_api_migration' => true, + 'return_type_declaration' => ['space_before' => 'one'], + 'self_accessor' => true, + 'short_scalar_cast' => true, +// 'silenced_deprecation_error' => true, + 'simplified_null_return' => true, +// 'single_blank_line_before_namespace' => true, + 'single_quote' => true, + 'space_after_semicolon' => true, + 'standardize_not_equals' => true, +// 'strict_comparison' => true, + 'ternary_operator_spaces' => true, + 'strict_param' => true, + 'ternary_to_null_coalescing' => true, +// 'trailing_comma_in_multiline_array' => true, + 'trim_array_spaces' => true, + 'unary_operator_spaces' => true, + 'whitespace_after_comma_in_array' => true + )) + ->setFinder( + PhpCsFixer\Finder::create() + ->exclude('tests/Fake') + ->exclude('tests/tmp') + ->exclude('src-data') + ->in(__DIR__) + )->setLineEnding("\n"); diff --git a/.travis.yml b/.travis.yml index 47dc249..c34fdde 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,7 +17,6 @@ before_script: - composer self-update - composer update $DEPENDENCIES script: - - vendor/bin/phpmd src text phpmd.xml - ./vendor/bin/phpunit --coverage-clover=coverage.clover; - if [ "$TRAVIS_PHP_VERSION" = "7.1" ]; then wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.4.0/php-cs-fixer.phar -O php-cs-fixer && php php-cs-fixer fix --config=.php_cs -v --dry-run --using-cache=no --path-mode=intersection `git diff --name-only --diff-filter=ACMRTUXB $TRAVIS_COMMIT_RANGE`; fi diff --git a/composer.json b/composer.json index 3e21119..13a92ae 100644 --- a/composer.json +++ b/composer.json @@ -14,11 +14,12 @@ } ], "require": { - "ray/di": "^2.5.3", - "bear/sunday": "^1.1", + "php": ">=7.0.0", + "bear/sunday": "^1.2", "bear/app-meta": "^1.1", - "twig/twig": "^2.0", - "mobiledetect/mobiledetectlib": "^2.7" + "twig/twig": "^2.4.8", + "mobiledetect/mobiledetectlib": "^2.7", + "ray/di": "^2.7" }, "require-dev": { "phpunit/phpunit": "~5.7 < 6.0", @@ -36,11 +37,10 @@ } }, "scripts": { - "test": ["@cs", "php -n ./vendor/bin/phpunit"], - "cs": ["php -n ./vendor/bin/phpcs --standard=./phpcs.xml src"], - "cs-fix": ["php -n ./vendor/bin/phpcbf src"], + "test": ["@setup", "vendor/bin/phpunit"], + "tests": ["@cs", "phpstan analyse -l max src tests -c phpstan.neon --no-progress", "@test"], "coverage": ["php -dzend_extension=xdebug.so ./vendor/bin/phpunit --coverage-text --coverage-html=build/coverage"], - "md": ["phpmd src text phpmd.xml"], - "check-all": ["@cs", "@md", "@coverage"] + "cs": ["php-cs-fixer fix -v --dry-run", "phpcs --standard=phpcs.xml src;"], + "cs-fix": ["php-cs-fixer fix -v", "phpcbf src tests"] } } diff --git a/src/Annotation/TwigErrorPath.php b/src/Annotation/TwigErrorPath.php new file mode 100644 index 0000000..26617a2 --- /dev/null +++ b/src/Annotation/TwigErrorPath.php @@ -0,0 +1,19 @@ +twig = $twig; + $this->errorPage = $errorPage; + } + + /** + * @throws \Twig_Error_Loader + * @throws \Twig_Error_Runtime + * @throws \Twig_Error_Syntax + * + * @return string + */ + public function render(ResourceObject $ro) + { + $ro->view = $this->twig->render($this->errorPage, $ro->body); + + return $ro->view; + } +} diff --git a/src/MobileTemplateFinder.php b/src/MobileTemplateFinder.php index 33f1807..27fca44 100644 --- a/src/MobileTemplateFinder.php +++ b/src/MobileTemplateFinder.php @@ -27,6 +27,8 @@ class MobileTemplateFinder implements TemplateFinderInterface /** * @TwigPaths("paths") + * + * @param mixed $userAgent */ public function __construct($userAgent = '', array $paths = []) { @@ -44,10 +46,10 @@ public function __invoke(string $name) : string $detect = new \Mobile_Detect(null, $this->userAgent); $isMobile = $detect->isMobile() && ! $detect->isTablet(); if ($isMobile) { - $mobilePath = str_replace('.html.twig', '.mobile.twig', $templatePath); + $mobilePath = \str_replace('.html.twig', '.mobile.twig', $templatePath); foreach ($this->paths as $path) { - $mobileFile = sprintf('%s/%s', $path, $mobilePath); - if (file_exists($mobileFile)) { + $mobileFile = \sprintf('%s/%s', $path, $mobilePath); + if (\file_exists($mobileFile)) { return $mobilePath; } } diff --git a/src/OptionProvider.php b/src/OptionProvider.php index b558335..4a43c76 100644 --- a/src/OptionProvider.php +++ b/src/OptionProvider.php @@ -26,7 +26,7 @@ class OptionProvider implements ProviderInterface * @Named("isDebug=Madapaja\TwigModule\Annotation\TwigDebug") * @SuppressWarnings(PHPMD.BooleanArgumentFlag) */ - public function __construct(AbstractAppMeta $appMeta, $isDebug = false) + public function __construct(AbstractAppMeta $appMeta, bool $isDebug = false) { $this->appMeta = $appMeta; $this->isDebug = $isDebug; diff --git a/src/TemplateFinder.php b/src/TemplateFinder.php index 605c419..15e6dd7 100644 --- a/src/TemplateFinder.php +++ b/src/TemplateFinder.php @@ -13,9 +13,9 @@ class TemplateFinder implements TemplateFinderInterface */ public function __invoke(string $resourceFilePath) : string { - $pos = strpos($resourceFilePath, '/Resource/'); - $relativePath = substr($resourceFilePath, $pos + 10); - $templateFile = str_replace('.php', '.html.twig', $relativePath); + $pos = \strpos($resourceFilePath, '/Resource/'); + $relativePath = \substr($resourceFilePath, $pos + 10); + $templateFile = \str_replace('.php', '.html.twig', $relativePath); return $templateFile; } diff --git a/src/TwigErrorHandler.php b/src/TwigErrorHandler.php new file mode 100644 index 0000000..f236df7 --- /dev/null +++ b/src/TwigErrorHandler.php @@ -0,0 +1,86 @@ +transfer = $transfer; + $this->errorPage = $errorPage; + $this->logger = $logger; + } + + /** + * {@inheritdoc} + */ + public function handle(\Exception $e, Request $request) + { + unset($request); + $code = $this->getCode($e); + $eStr = (string) $e; + $logRef = \crc32($eStr); + if ($code >= 500) { + $this->logger->error(\sprintf('logref:%s %s', $logRef, $eStr)); + } + $this->errorPage->code = $code; + $this->errorPage->body = [ + 'status' => [ + 'code' => $code, + 'message' => (new Code)->statusText[$code] + ], + 'e' => [ + 'code' => $e->getCode(), + 'class' => \get_class($e), + 'message' => $e->getMessage() + ], + 'logref' => (string) $logRef + ]; + + return $this; + } + + /** + * {@inheritdoc} + */ + public function transfer() + { + ($this->transfer)($this->errorPage, []); + } + + private function getCode(\Exception $e) : int + { + if ($e instanceof NotFound || $e instanceof BadRequest) { + return $e->getCode(); + } + + return 503; + } +} diff --git a/src/TwigErrorPage.php b/src/TwigErrorPage.php new file mode 100644 index 0000000..b5a3816 --- /dev/null +++ b/src/TwigErrorPage.php @@ -0,0 +1,37 @@ + 'text/html; charset=utf-8' + ]; + protected $renderer; + + public function __sleep() + { + return ['renderer']; + } + + /** + * @Inject + * @Named("error_page") + */ + public function setRenderer(RenderInterface $renderer) + { + $this->renderer = $renderer; + } +} diff --git a/src/TwigErrorPageHandler.php b/src/TwigErrorPageHandler.php new file mode 100644 index 0000000..9d8906d --- /dev/null +++ b/src/TwigErrorPageHandler.php @@ -0,0 +1,83 @@ +transfer = $transfer; + $this->errorPage = $errorPage; + $this->logger = $logger; + } + + /** + * {@inheritdoc} + */ + public function handle(\Exception $e, Request $request) + { + unset($request); + $code = $this->isCodeExists($e) ? $e->getCode() : 503; + if ($code >= 500) { + $eStr = (string) $e; + $this->logger->error(\sprintf('logref:%s %s', \crc32($eStr), $eStr)); + } + $this->errorPage->code = $code; + $this->errorPage->body = [ + 'status' => [ + 'code' => $code, + 'message' => (new Code)->statusText[$code] + ], + 'e' => [ + 'code' => $e->getCode(), + 'message' => $e->getMessage() + ] + ]; + + return $this; + } + + /** + * {@inheritdoc} + */ + public function transfer() + { + ($this->transfer)($this->errorPage, []); + } + + private function isCodeExists(\Exception $e) : bool + { + if (! ($e instanceof NotFound) && ! ($e instanceof BadRequest) && ! ($e instanceof ServerError)) { + return false; + } + + return \array_key_exists($e->getCode(), (new Code)->statusText); + } +} diff --git a/src/TwigErrorPageModule.php b/src/TwigErrorPageModule.php new file mode 100644 index 0000000..45f495b --- /dev/null +++ b/src/TwigErrorPageModule.php @@ -0,0 +1,26 @@ +bind(RenderInterface::class)->annotatedWith('error_page')->to(ErrorPagerRenderer::class); + $this->bind(ErrorInterface::class)->to(TwigErrorHandler::class); + $this->bind()->annotatedWith(TwigErrorPath::class)->toInstance('/error/error.html.twig'); + $this->bind(TwigErrorPage::class); + } +} diff --git a/src/TwigModule.php b/src/TwigModule.php index bce317c..3bd0d48 100644 --- a/src/TwigModule.php +++ b/src/TwigModule.php @@ -7,6 +7,7 @@ namespace Madapaja\TwigModule; use BEAR\Resource\RenderInterface; +use BEAR\Sunday\Extension\Error\ErrorInterface; use Madapaja\TwigModule\Annotation\TwigLoader; use Madapaja\TwigModule\Annotation\TwigOptions; use Madapaja\TwigModule\Annotation\TwigPaths; @@ -34,12 +35,11 @@ class TwigModule extends AbstractModule * * @see http://twig.sensiolabs.org/api/master/Twig_Environment.html */ - public function __construct($paths = [], $options = []) + public function __construct($paths = [], $options = [], AbstractModule $module = null) { $this->paths = $paths; $this->options = $options; - - parent::__construct(); + parent::__construct($module); } /** @@ -52,6 +52,9 @@ protected function configure() $this->bindTwigEnvironment(); $this->bindTwigPaths(); $this->bindTwigOptions(); + $this->bind(RenderInterface::class)->annotatedWith('error_page')->to(ErrorPagerRenderer::class); + $this->bind(ErrorInterface::class)->to(TwigErrorHandler::class); + $this->bind(TwigErrorPage::class); } private function bindRender() @@ -100,6 +103,7 @@ private function bindTwigPaths() { if ($this->isNotEmpty($this->paths)) { $this->bind()->annotatedWith(TwigPaths::class)->toInstance($this->paths); + return; } $this->bind()->annotatedWith(TwigPaths::class)->toProvider(AppPathProvider::class); @@ -109,6 +113,7 @@ private function bindTwigOptions() { if ($this->isNotEmpty($this->options)) { $this->bind()->annotatedWith(TwigOptions::class)->toInstance($this->options); + return; } $this->bind()->annotatedWith(TwigOptions::class)->toProvider(OptionProvider::class); @@ -116,6 +121,6 @@ private function bindTwigOptions() private function isNotEmpty($var) { - return is_array($var) && ! empty($var); + return \is_array($var) && ! empty($var); } } diff --git a/src/TwigRenderer.php b/src/TwigRenderer.php index 0aec09f..ce718ae 100644 --- a/src/TwigRenderer.php +++ b/src/TwigRenderer.php @@ -71,7 +71,7 @@ private function load(ResourceObject $ro) return $this->loadTemplate($ro); } catch (\Twig_Error_Loader $e) { if ($ro->code !== 200) { - return null; + return; } } @@ -107,8 +107,8 @@ private function getReflection(ResourceObject $ro) : \ReflectionClass private function buildBody(ResourceObject $ro) : array { - $body = is_array($ro->body) ? $ro->body : []; - $body += ['_ro' => $ro,]; + $body = \is_array($ro->body) ? $ro->body : []; + $body += ['_ro' => $ro]; return $body; } diff --git a/tests/AppPathProviderTest.php b/tests/AppPathProviderTest.php index 9a14b97..d22bab0 100644 --- a/tests/AppPathProviderTest.php +++ b/tests/AppPathProviderTest.php @@ -20,8 +20,8 @@ public function testAppPathProvider() ]; foreach ($paths as $path) { - if (! is_dir($path)) { - mkdir($path, 0777, true); + if (! \is_dir($path)) { + \mkdir($path, 0777, true); } } diff --git a/tests/ExtensionTest.php b/tests/ExtensionTest.php index 6ffc72d..e125a06 100644 --- a/tests/ExtensionTest.php +++ b/tests/ExtensionTest.php @@ -25,6 +25,6 @@ public function setUp() public function testTwigFilter() { $ro = $this->injector->getInstance(TwigFilter::class); - $this->assertSame('Twig => "' . str_rot13('Twig') . '"', (string) trim($ro->onGet())); + $this->assertSame('Twig => "' . \str_rot13('Twig') . '"', (string) \trim($ro->onGet())); } } diff --git a/tests/Fake/src/FakeHttpResponder.php b/tests/Fake/src/FakeHttpResponder.php new file mode 100644 index 0000000..1318fb7 --- /dev/null +++ b/tests/Fake/src/FakeHttpResponder.php @@ -0,0 +1,32 @@ +toString(); + self::$content = $ro->view; + self::$code = $ro->code; + self::$headers = $ro->headers; + } +} diff --git a/tests/Fake/templates/error/error.html.twig b/tests/Fake/templates/error/error.html.twig new file mode 100644 index 0000000..206f07f --- /dev/null +++ b/tests/Fake/templates/error/error.html.twig @@ -0,0 +1 @@ +code:{{ status.code }} msg:{{ status.message }} \ No newline at end of file diff --git a/tests/FileLoaderTest.php b/tests/FileLoaderTest.php index 2472ff0..609275d 100644 --- a/tests/FileLoaderTest.php +++ b/tests/FileLoaderTest.php @@ -9,18 +9,12 @@ use BEAR\Resource\Code; use Madapaja\TwigModule\TwigAppMetaTestModule; use Madapaja\TwigModule\TwigFileLoaderTestModule; -use Madapaja\TwigModule\TwigModule; use Madapaja\TwigModule\TwigRenderer; use PHPUnit_Framework_TestCase; use Ray\Di\Injector; class FileLoaderTest extends PHPUnit_Framework_TestCase { - /** - * @var Injector - */ - private $injector; - public function getInjector() : Injector { return new Injector(new TwigFileLoaderTestModule([$_ENV['TEST_DIR'] . '/Fake/src/Resource'])); @@ -28,7 +22,7 @@ public function getInjector() : Injector public function testRenderer() { - $injector = $this->getInjector();; + $injector = $this->getInjector(); $ro = $injector->getInstance(Index::class); $prop = (new \ReflectionClass($ro))->getProperty('renderer'); $prop->setAccessible(true); @@ -49,26 +43,26 @@ public function testTwigOptions() public function testIndex() { - $injector = $this->getInjector();; + $injector = $this->getInjector(); $ro = $injector->getInstance(Index::class); - $this->assertSame('Hello, BEAR.Sunday!', trim((string) $ro->onGet())); + $this->assertSame('Hello, BEAR.Sunday!', \trim((string) $ro->onGet())); } public function testTemplatePath() { - $injector = $this->getInjector();; + $injector = $this->getInjector(); $ro = $injector->getInstance(Index::class); - $this->assertSame('Your Name is MyName!', trim((string) $ro->onPost('MyName'))); + $this->assertSame('Your Name is MyName!', \trim((string) $ro->onPost('MyName'))); } public function testIndexWithArg() { - $injector = $this->getInjector();; + $injector = $this->getInjector(); $ro = $injector->getInstance(Index::class); - $this->assertSame('Hello, Madapaja!', trim((string) $ro->onGet('Madapaja'))); + $this->assertSame('Hello, Madapaja!', \trim((string) $ro->onGet('Madapaja'))); } /** @@ -76,7 +70,7 @@ public function testIndexWithArg() */ public function testTemplateNotFoundException() { - $injector = $this->getInjector();; + $injector = $this->getInjector(); $ro = $injector->getInstance(NoTemplate::class); $prop = (new \ReflectionClass($ro))->getProperty('renderer'); $prop->setAccessible(true); @@ -85,7 +79,7 @@ public function testTemplateNotFoundException() public function testNoViewWhenCode301() { - $injector = $this->getInjector();; + $injector = $this->getInjector(); $ro = $injector->getInstance(NoTemplate::class); $ro->code = 303; $prop = (new \ReflectionClass($ro))->getProperty('renderer'); @@ -96,7 +90,7 @@ public function testNoViewWhenCode301() public function testNoContent() { - $injector = $this->getInjector();; + $injector = $this->getInjector(); $ro = $injector->getInstance(NoTemplate::class); $ro->code = Code::NO_CONTENT; $prop = (new \ReflectionClass($ro))->getProperty('renderer'); @@ -107,7 +101,7 @@ public function testNoContent() public function testPage() { - $injector = $this->getInjector();; + $injector = $this->getInjector(); $ro = $injector->getInstance(Page::class); $this->assertSame('
The requested URL was not found on this server.
+ {% elseif status.code == 500 %} +The server encountered an internal error.
+logref: {{ logref }}
+ {% elseif status.code == 503 %} +The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
+logref: {{ logref }}
+ {% endif %} +{% endblock %} diff --git a/var/templates/layout/base.html.twig b/var/templates/layout/base.html.twig new file mode 100644 index 0000000..c8f7720 --- /dev/null +++ b/var/templates/layout/base.html.twig @@ -0,0 +1,14 @@ + + + + + {% block head %} +