diff --git a/composer.lock b/composer.lock index fb79cd21..b085b329 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "5f53c98916a1a98d47190e78c4bd4a7b", + "hash": "1cfa8fc4b867d0e6dd4a2884476316d1", "packages": [ { "name": "evandotpro/edp-github", @@ -163,16 +163,16 @@ }, { "name": "monolog/monolog", - "version": "1.12.0", + "version": "1.13.0", "source": { "type": "git", "url": "https://github.com/Seldaek/monolog.git", - "reference": "1fbe8c2641f2b163addf49cc5e18f144bec6b19f" + "reference": "c41c218e239b50446fd883acb1ecfd4b770caeae" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Seldaek/monolog/zipball/1fbe8c2641f2b163addf49cc5e18f144bec6b19f", - "reference": "1fbe8c2641f2b163addf49cc5e18f144bec6b19f", + "url": "https://api.github.com/repos/Seldaek/monolog/zipball/c41c218e239b50446fd883acb1ecfd4b770caeae", + "reference": "c41c218e239b50446fd883acb1ecfd4b770caeae", "shasum": "" }, "require": { @@ -189,6 +189,7 @@ "phpunit/phpunit": "~4.0", "raven/raven": "~0.5", "ruflin/elastica": "0.90.*", + "swiftmailer/swiftmailer": "~5.3", "videlalvaro/php-amqplib": "~2.4" }, "suggest": { @@ -205,7 +206,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.12.x-dev" + "dev-master": "1.13.x-dev" } }, "autoload": { @@ -231,7 +232,7 @@ "logging", "psr-3" ], - "time": "2014-12-29 21:29:35" + "time": "2015-03-05 01:12:12" }, { "name": "phing/phing", diff --git a/module/Application/config/module.config.php b/module/Application/config/module.config.php index bcd59b61..32fb9141 100644 --- a/module/Application/config/module.config.php +++ b/module/Application/config/module.config.php @@ -95,6 +95,9 @@ ], ], 'view_helpers' => [ + 'invokables' => [ + 'FlashMessenger' => View\Helper\FlashMessenger::class, + ], 'factories' => [ 'gitHubRepositoryUrl' => View\Helper\GitHubRepositoryUrlFactory::class, 'sanitizeHtml' => View\Helper\SanitizeHtmlFactory::class, diff --git a/module/Application/src/Application/Exception/ViewableUserException.php b/module/Application/src/Application/Exception/ViewableUserException.php new file mode 100644 index 00000000..b0aac34d --- /dev/null +++ b/module/Application/src/Application/Exception/ViewableUserException.php @@ -0,0 +1,26 @@ +publicMessage = (string) $publicMessage; + parent::__construct($message, $code, $previous); + } + + /** + * {@inheritdoc} + */ + public function getPublicMessage() + { + return $this->publicMessage; + } +} diff --git a/module/Application/src/Application/Exception/ViewableUserExceptionInterface.php b/module/Application/src/Application/Exception/ViewableUserExceptionInterface.php new file mode 100644 index 00000000..8b2ec7d5 --- /dev/null +++ b/module/Application/src/Application/Exception/ViewableUserExceptionInterface.php @@ -0,0 +1,20 @@ +classOptions = [ + PluginFlashMessenger::NAMESPACE_INFO => [ + 'name' => 'Information', + 'class' => 'alert alert-info', + ], + PluginFlashMessenger::NAMESPACE_ERROR => [ + 'name' => 'Error', + 'class' => 'alert alert-danger', + ], + PluginFlashMessenger::NAMESPACE_SUCCESS => [ + 'name' => 'Success', + 'class' => 'alert alert-success', + ], + PluginFlashMessenger::NAMESPACE_DEFAULT => [ + 'name' => 'Message', + 'class' => 'alert alert-info', + ], + PluginFlashMessenger::NAMESPACE_WARNING => [ + 'name' => 'Warning', + 'class' => 'alert alert-warning', + ], + ]; + + // if custom namespace handle as default message + if (!isset($this->classOptions[$namespace])) { + $this->classOptions = [ + $namespace => $this->classOptions[PluginFlashMessenger::NAMESPACE_DEFAULT], + ]; + } + + $messageOutput = ''; + $translator = $this->getTranslator(); + + foreach ($this->classOptions as $currentNamespace => $options) { + $this->classMessages[$currentNamespace] = $options['class']; + $openingString = sprintf('%s', $translator->translate($options['name'])); + + $this->setMessageOpenFormat($openingString); + $this->setMessageSeparatorString(sprintf('%s', $openingString)); + $this->setMessageCloseString(''); + + $messageOutput .= $renderer($currentNamespace, $classes); + } + + return $messageOutput; + } + + /** + * {@inheritdoc} + */ + public function render($namespace = PluginFlashMessenger::NAMESPACE_DEFAULT, array $classes = []) + { + $renderer = function ($namespace, $classes) { + return parent::render($namespace, $classes); + }; + + return $this->doRender($renderer, $namespace, $classes); + } + + /** + * {@inheritdoc} + */ + public function renderCurrent($namespace = PluginFlashMessenger::NAMESPACE_DEFAULT, array $classes = []) + { + $renderer = function ($namespace, $classes) { + return parent::renderCurrent($namespace, $classes); + }; + + return $this->doRender($renderer, $namespace, $classes); + } +} diff --git a/module/Application/test/ApplicationTest/Exception/ViewableUserExceptionTest.php b/module/Application/test/ApplicationTest/Exception/ViewableUserExceptionTest.php new file mode 100644 index 00000000..b938db22 --- /dev/null +++ b/module/Application/test/ApplicationTest/Exception/ViewableUserExceptionTest.php @@ -0,0 +1,26 @@ +getMock(\Exception::class); + + $exception = new Exception\ViewableUserException( + 'fooMessage', + 'fooPublicMessage', + 666, + $parentExceptionMock + ); + + $this->assertSame('fooMessage', $exception->getMessage()); + $this->assertSame('fooPublicMessage', $exception->getPublicMessage()); + $this->assertSame(666, $exception->getCode()); + $this->assertSame($parentExceptionMock, $exception->getPrevious()); + } +} diff --git a/module/Application/test/ApplicationTest/Integration/View/Helper/FlashMessengerTest.php b/module/Application/test/ApplicationTest/Integration/View/Helper/FlashMessengerTest.php new file mode 100644 index 00000000..d18a6c4e --- /dev/null +++ b/module/Application/test/ApplicationTest/Integration/View/Helper/FlashMessengerTest.php @@ -0,0 +1,57 @@ +get('ControllerPluginManager')->get('FlashMessenger'); + + $flashMessengerControllerPlugin->addMessage('FooMessage'); + $flashMessengerControllerPlugin->addSuccessMessage('FooSuccess'); + $flashMessengerControllerPlugin->addWarningMessage('FooWarning'); + $flashMessengerControllerPlugin->addErrorMessage('FooError'); + $flashMessengerControllerPlugin->addInfoMessage('FooInfo'); + + /* @var \Application\View\Helper\FlashMessenger $flashMessengerViewHelper */ + $flashMessengerViewHelper = $serviceManager->get('ViewHelperManager')->get('FlashMessenger'); + + $this->assertEquals( + '
InformationFooInfo
' . + '
ErrorFooError
' . + '
SuccessFooSuccess
' . + '
MessageFooMessage
' . + '
WarningFooWarning
', + $flashMessengerViewHelper->renderCurrent() + ); + } + + public function testCustomNamespaceMessageGetsRenderedAsInformationMessage() + { + $serviceManager = Bootstrap::getServiceManager(); + + /* @var $flashMessengerControllerPlugin \Zend\Mvc\Controller\Plugin\FlashMessenger */ + $flashMessengerControllerPlugin = $serviceManager->get('ControllerPluginManager')->get('FlashMessenger'); + $flashMessengerControllerPlugin->setNamespace('FooBar'); + + $flashMessengerControllerPlugin->addMessage('FooMessage'); + + /* @var \Application\View\Helper\FlashMessenger $flashMessengerViewHelper */ + $flashMessengerViewHelper = $serviceManager->get('ViewHelperManager')->get('FlashMessenger'); + + $this->assertEquals( + '
MessageFooMessage
', + $flashMessengerViewHelper->renderCurrent('FooBar') + ); + } +} diff --git a/module/Application/view/error/404.phtml b/module/Application/view/error/404.phtml index a0faa579..5180168e 100644 --- a/module/Application/view/error/404.phtml +++ b/module/Application/view/error/404.phtml @@ -1,6 +1,5 @@

A 404 error occurred

-

message ?>

- +
reason) && $this->reason): ?> -

+
+ message ?> +

+
controller) && $this->controller): ?> diff --git a/module/Application/view/error/index.phtml b/module/Application/view/error/index.phtml index f1c5ab76..cdcd879d 100644 --- a/module/Application/view/error/index.phtml +++ b/module/Application/view/error/index.phtml @@ -1,8 +1,21 @@ -

An error occurred

-

message ?>

+ +

Oops. Something went wrong.

+
+ Error +

+ exception instanceof Exception\ViewableUserException && $this->exception->getPublicMessage()): ?> + escapeHtml($this->exception->getPublicMessage()); ?> + + Sorry, we got no more information + +

+
display_exceptions) && $this->display_exceptions): ?> - exception) && $this->exception instanceof Exception): ?> + exception) && $this->exception instanceof \Exception): ?>

Additional information:

exception); ?>

diff --git a/module/User/src/User/GitHub/LoginListener.php b/module/User/src/User/GitHub/LoginListener.php index 33ac330b..ea55c2c4 100644 --- a/module/User/src/User/GitHub/LoginListener.php +++ b/module/User/src/User/GitHub/LoginListener.php @@ -16,7 +16,7 @@ final class LoginListener implements SharedListenerAggregateInterface protected $listeners = []; /** - * @inheritdoc + * {@inheritdoc} */ public function attachShared(SharedEventManagerInterface $events) { @@ -28,7 +28,7 @@ public function attachShared(SharedEventManagerInterface $events) } /** - * @inheritdoc + * {@inheritdoc} */ public function detachShared(SharedEventManagerInterface $events) { diff --git a/module/User/view/zfc-user/user/index.phtml b/module/User/view/zfc-user/user/index.phtml index 0b8f73b7..8c4bd425 100644 --- a/module/User/view/zfc-user/user/index.phtml +++ b/module/User/view/zfc-user/user/index.phtml @@ -10,9 +10,7 @@ - flashMessenger()->getMessages() as $message): ?> -

escapeHtml($message); ?>

- + flashMessenger()->render(); ?>