diff options
7 files changed, 107 insertions, 9 deletions
diff --git a/app/config/config.yml b/app/config/config.yml index b5d82ed9..fbebfee7 100644 --- a/app/config/config.yml +++ b/app/config/config.yml | |||
@@ -64,6 +64,7 @@ twig: | |||
64 | strict_variables: "%kernel.debug%" | 64 | strict_variables: "%kernel.debug%" |
65 | form_themes: | 65 | form_themes: |
66 | - "LexikFormFilterBundle:Form:form_div_layout.html.twig" | 66 | - "LexikFormFilterBundle:Form:form_div_layout.html.twig" |
67 | exception_controller: wallabag_core.exception_controller:showAction | ||
67 | 68 | ||
68 | # Doctrine Configuration | 69 | # Doctrine Configuration |
69 | doctrine: | 70 | doctrine: |
diff --git a/src/Wallabag/CoreBundle/Controller/ExceptionController.php b/src/Wallabag/CoreBundle/Controller/ExceptionController.php new file mode 100644 index 00000000..abfa9c2f --- /dev/null +++ b/src/Wallabag/CoreBundle/Controller/ExceptionController.php | |||
@@ -0,0 +1,40 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Controller; | ||
4 | |||
5 | use Symfony\Bundle\TwigBundle\Controller\ExceptionController as BaseExceptionController; | ||
6 | use Symfony\Component\HttpFoundation\Request; | ||
7 | |||
8 | /** | ||
9 | * This controller allow us to customize the error template. | ||
10 | * The only modified line from the parent template is for "WallabagCoreBundle". | ||
11 | */ | ||
12 | class ExceptionController extends BaseExceptionController | ||
13 | { | ||
14 | protected function findTemplate(Request $request, $format, $code, $showException) | ||
15 | { | ||
16 | $name = $showException ? 'exception' : 'error'; | ||
17 | if ($showException && 'html' == $format) { | ||
18 | $name = 'exception_full'; | ||
19 | } | ||
20 | |||
21 | // For error pages, try to find a template for the specific HTTP status code and format | ||
22 | if (!$showException) { | ||
23 | $template = sprintf('WallabagCoreBundle:Exception:%s.%s.twig', $name, $format); | ||
24 | if ($this->templateExists($template)) { | ||
25 | return $template; | ||
26 | } | ||
27 | } | ||
28 | |||
29 | // try to find a template for the given format | ||
30 | $template = sprintf('@Twig/Exception/%s.%s.twig', $name, $format); | ||
31 | if ($this->templateExists($template)) { | ||
32 | return $template; | ||
33 | } | ||
34 | |||
35 | // default to a generic HTML exception | ||
36 | $request->setRequestFormat('html'); | ||
37 | |||
38 | return sprintf('@Twig/Exception/%s.html.twig', $showException ? 'exception_full' : $name); | ||
39 | } | ||
40 | } | ||
diff --git a/src/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverter.php b/src/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverter.php index 6ea2a4f3..40b5673d 100644 --- a/src/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverter.php +++ b/src/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverter.php | |||
@@ -49,7 +49,7 @@ class UsernameRssTokenConverter implements ParamConverterInterface | |||
49 | $em = $this->registry->getManagerForClass($configuration->getClass()); | 49 | $em = $this->registry->getManagerForClass($configuration->getClass()); |
50 | 50 | ||
51 | // Check, if class name is what we need | 51 | // Check, if class name is what we need |
52 | if ('Wallabag\UserBundle\Entity\User' !== $em->getClassMetadata($configuration->getClass())->getName()) { | 52 | if (null !== $em && 'Wallabag\UserBundle\Entity\User' !== $em->getClassMetadata($configuration->getClass())->getName()) { |
53 | return false; | 53 | return false; |
54 | } | 54 | } |
55 | 55 | ||
@@ -69,9 +69,8 @@ class UsernameRssTokenConverter implements ParamConverterInterface | |||
69 | $username = $request->attributes->get('username'); | 69 | $username = $request->attributes->get('username'); |
70 | $rssToken = $request->attributes->get('token'); | 70 | $rssToken = $request->attributes->get('token'); |
71 | 71 | ||
72 | // Check, if route attributes exists | 72 | if (!$request->attributes->has('username') || !$request->attributes->has('token')) { |
73 | if (null === $username || null === $rssToken) { | 73 | return false; |
74 | throw new \InvalidArgumentException('Route attribute is missing'); | ||
75 | } | 74 | } |
76 | 75 | ||
77 | // Get actual entity manager for class | 76 | // Get actual entity manager for class |
diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml index 5a727ec5..d1139846 100644 --- a/src/Wallabag/CoreBundle/Resources/config/services.yml +++ b/src/Wallabag/CoreBundle/Resources/config/services.yml | |||
@@ -122,3 +122,9 @@ services: | |||
122 | host: '%redis_host%' | 122 | host: '%redis_host%' |
123 | port: '%redis_port%' | 123 | port: '%redis_port%' |
124 | schema: tcp | 124 | schema: tcp |
125 | |||
126 | wallabag_core.exception_controller: | ||
127 | class: Wallabag\CoreBundle\Controller\ExceptionController | ||
128 | arguments: | ||
129 | - '@twig' | ||
130 | - '%kernel.debug%' | ||
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Exception/error.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Exception/error.html.twig new file mode 100644 index 00000000..b52634fd --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Exception/error.html.twig | |||
@@ -0,0 +1,24 @@ | |||
1 | {% extends "WallabagCoreBundle::layout.html.twig" %} | ||
2 | |||
3 | {% block title %}{{ 'error.page_title'|trans }}{% endblock %} | ||
4 | |||
5 | {% block body_class %}login{% endblock %} | ||
6 | |||
7 | {% block menu %}{% endblock %} | ||
8 | {% block messages %}{% endblock %} | ||
9 | {% block header %}{% endblock %} | ||
10 | |||
11 | {% block content %} | ||
12 | <main class="valign-wrapper"> | ||
13 | <div class="valign row"> | ||
14 | <div class="card sw"> | ||
15 | <div class="center"><img src="{{ asset('bundles/wallabagcore/themes/_global/img/logo-w.png') }}" alt="wallabag logo" /></div> | ||
16 | <h2>{{ status_code }}: {{ status_text }}</h2> | ||
17 | <p>{{ exception.message }}</p> | ||
18 | </div> | ||
19 | </div> | ||
20 | </main> | ||
21 | {% endblock %} | ||
22 | |||
23 | {% block footer %} | ||
24 | {% endblock %} | ||
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Exception/error.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Exception/error.html.twig new file mode 100644 index 00000000..6be78edb --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Exception/error.html.twig | |||
@@ -0,0 +1,30 @@ | |||
1 | {% extends "WallabagCoreBundle::layout.html.twig" %} | ||
2 | |||
3 | {% block title %}{{ 'error.page_title'|trans }}{% endblock %} | ||
4 | |||
5 | {% block body_class %}login{% endblock %} | ||
6 | |||
7 | {% block menu %}{% endblock %} | ||
8 | {% block messages %}{% endblock %} | ||
9 | |||
10 | {% block content %} | ||
11 | <main class="valign-wrapper"> | ||
12 | <div class="valign row"> | ||
13 | <div class="card sw"> | ||
14 | <div class="center"><img src="{{ asset('bundles/wallabagcore/themes/_global/img/logo-other_themes.png') }}" alt="wallabag logo" /></div> | ||
15 | <div class="card-content"> | ||
16 | <div class="row"> | ||
17 | <h5>{{ status_code }}: {{ status_text }}</h5> | ||
18 | <p>{{ exception.message }}</p> | ||
19 | {# {% for trace in exception.trace %} | ||
20 | <p>{{ trace.class }} - {{ trace.type }} - {{ trace.file }} - {{ trace.line }}</p> | ||
21 | {% endfor %} #} | ||
22 | </div> | ||
23 | </div> | ||
24 | </div> | ||
25 | </div> | ||
26 | </main> | ||
27 | {% endblock %} | ||
28 | |||
29 | {% block footer %} | ||
30 | {% endblock %} | ||
diff --git a/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php b/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php index e29b58b5..2e6fccfb 100644 --- a/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php +++ b/tests/Wallabag/CoreBundle/ParamConverter/UsernameRssTokenConverterTest.php | |||
@@ -125,16 +125,14 @@ class UsernameRssTokenConverterTest extends \PHPUnit_Framework_TestCase | |||
125 | $this->assertTrue($converter->supports($params)); | 125 | $this->assertTrue($converter->supports($params)); |
126 | } | 126 | } |
127 | 127 | ||
128 | /** | ||
129 | * @expectedException InvalidArgumentException | ||
130 | * @expectedExceptionMessage Route attribute is missing | ||
131 | */ | ||
132 | public function testApplyEmptyRequest() | 128 | public function testApplyEmptyRequest() |
133 | { | 129 | { |
134 | $params = new ParamConverter([]); | 130 | $params = new ParamConverter([]); |
135 | $converter = new UsernameRssTokenConverter(); | 131 | $converter = new UsernameRssTokenConverter(); |
136 | 132 | ||
137 | $converter->apply(new Request(), $params); | 133 | $res = $converter->apply(new Request(), $params); |
134 | |||
135 | $this->assertFalse($res); | ||
138 | } | 136 | } |
139 | 137 | ||
140 | /** | 138 | /** |