Skip to content

Commit 5f2e599

Browse files
Merge pull request #2 from phphacks/OV-72
Removido Json Response Factory.
2 parents 3f6139b + d8dd6ec commit 5f2e599

13 files changed

+28
-273
lines changed

src/Common/Enums/Configuration.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
interface Configuration
66
{
77
const ERROR_LOGGING_ENABLE = 'enable';
8-
const ERROR_LOGGING = 'error-logging';
9-
const RESPONSE = 'response';
8+
const ERROR_LOGGING = 'error_logging';
109
const LOGGERS = 'loggers';
1110
const LOGGER = 'logger';
1211
const TYPEOF = 'typeof';

src/Common/ErrorLogging.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,6 @@ class ErrorLogging
1515
*/
1616
public $loggers = [];
1717

18-
/**
19-
* @return string
20-
*/
21-
public function getResponse(): string
22-
{
23-
return $this->response;
24-
}
25-
26-
/**
27-
* @param string $response
28-
*/
29-
public function setResponse(string $response)
30-
{
31-
$this->response = $response;
32-
}
33-
3418
/**
3519
* @return LoggerDefinition[]
3620
*/

src/Common/Parse/ConfigurationParser.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Zend\Mvc\ErrorLogger\Common\Enums\Configuration;
66
use Zend\Mvc\ErrorLogger\Common\ErrorLogging;
77

8-
use Zend\Mvc\ErrorLogger\Exceptions\Parse\NoJsonErrorResponseFactoryClassDefinedException;
98
use Zend\Mvc\ErrorLogger\Exceptions\Parse\LoggerClassDefinedAndIgnoredException;
109
use Zend\Mvc\ErrorLogger\Exceptions\Parse\LoggerClassException;
1110
use Zend\Mvc\ErrorLogger\Exceptions\Parse\NoExceptionClassDefined;
@@ -20,15 +19,13 @@ class ConfigurationParser
2019
* @throws LoggerClassDefinedAndIgnoredException
2120
* @throws LoggerClassException
2221
* @throws NoExceptionClassDefined
23-
* @throws NoJsonErrorResponseFactoryClassDefinedException
2422
* @throws NoLoggerDefinitionException
2523
*/
2624
public function parse($configuration)
2725
{
2826
if (isset($configuration[Configuration::ERROR_LOGGING])) {
2927

3028
$errorLogging = new ErrorLogging();
31-
$errorLogging->setResponse($this->parseResponse($configuration));
3229

3330
$this->hasLoggers($configuration[Configuration::ERROR_LOGGING]);
3431

@@ -105,22 +102,6 @@ private function hasLoggers(array $configuration)
105102
}
106103
}
107104

108-
/**
109-
* @param array $loggingConfiguration
110-
* @return string
111-
* @throws NoJsonErrorResponseFactoryClassDefinedException
112-
*/
113-
public function parseResponse(array $loggingConfiguration): string
114-
{
115-
if (!isset($loggingConfiguration[Configuration::ERROR_LOGGING][Configuration::RESPONSE])
116-
|| $loggingConfiguration[Configuration::ERROR_LOGGING][Configuration::RESPONSE] == null
117-
|| $loggingConfiguration[Configuration::ERROR_LOGGING][Configuration::RESPONSE] == '') {
118-
throw new NoJsonErrorResponseFactoryClassDefinedException('Invalid error response factory');
119-
} else {
120-
return $loggingConfiguration[Configuration::ERROR_LOGGING][Configuration::RESPONSE];
121-
}
122-
}
123-
124105
/**
125106
* @param array $loggerConfiguration
126107
* @param string $exceptionListIdentifier

src/Custom/JsonErrorResponseFactoryInterface.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/Exceptions/Logger/InvalidJsonErrorResponseFactoryClassException.php

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/Exceptions/Parse/NoJsonErrorResponseFactoryClassDefinedException.php

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/Listener/ErrorEventListener.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Exception;
77
use Zend\EventManager\EventManagerInterface;
88
use Zend\EventManager\AbstractListenerAggregate;
9-
use Zend\Mvc\ErrorLogger\Custom\JsonErrorResponseFactoryInterface;
109
use Zend\Mvc\ErrorLogger\Logger\Resolver;
1110
use Zend\Mvc\MvcEvent;
1211
use Zend\Log\Logger;
@@ -51,6 +50,12 @@ public function attach(EventManagerInterface $events, $priority = 1)
5150
* @throws \Interop\Container\Exception\ContainerException
5251
* @throws \ReflectionException
5352
* @throws \Zend\Mvc\Di\Exceptions\UnsolvableDependencyException
53+
* @throws \Zend\Mvc\ErrorLogger\Exceptions\Logger\InvalidFactoryException
54+
* @throws \Zend\Mvc\ErrorLogger\Exceptions\Logger\InvalidLoggerClassException
55+
* @throws \Zend\Mvc\ErrorLogger\Exceptions\Parse\LoggerClassDefinedAndIgnoredException
56+
* @throws \Zend\Mvc\ErrorLogger\Exceptions\Parse\LoggerClassException
57+
* @throws \Zend\Mvc\ErrorLogger\Exceptions\Parse\NoExceptionClassDefined
58+
* @throws \Zend\Mvc\ErrorLogger\Exceptions\Parse\NoLoggerDefinitionException
5459
*/
5560
public function handleExceptionError(MvcEvent $event)
5661
{
@@ -63,6 +68,12 @@ public function handleExceptionError(MvcEvent $event)
6368
* @throws \Interop\Container\Exception\ContainerException
6469
* @throws \ReflectionException
6570
* @throws \Zend\Mvc\Di\Exceptions\UnsolvableDependencyException
71+
* @throws \Zend\Mvc\ErrorLogger\Exceptions\Logger\InvalidFactoryException
72+
* @throws \Zend\Mvc\ErrorLogger\Exceptions\Logger\InvalidLoggerClassException
73+
* @throws \Zend\Mvc\ErrorLogger\Exceptions\Parse\LoggerClassDefinedAndIgnoredException
74+
* @throws \Zend\Mvc\ErrorLogger\Exceptions\Parse\LoggerClassException
75+
* @throws \Zend\Mvc\ErrorLogger\Exceptions\Parse\NoExceptionClassDefined
76+
* @throws \Zend\Mvc\ErrorLogger\Exceptions\Parse\NoLoggerDefinitionException
6677
*/
6778
private function handleError(MvcEvent $event): MvcEvent
6879
{
@@ -84,11 +95,6 @@ private function handleError(MvcEvent $event): MvcEvent
8495
$loggerInstance->info($exception->getMessage());
8596
}
8697
}
87-
88-
/** @var JsonErrorResponseFactoryInterface $jsonErrorResponseFactory */
89-
$jsonErrorResponseFactory = $serviceManager->get($errorLogging->getResponse());
90-
91-
$event->setViewModel($jsonErrorResponseFactory->createResponse($exception->getMessage()));
9298
}
9399
return $event;
94100
}
@@ -109,6 +115,12 @@ private function getServiceManagerFromMvcEvent(MvcEvent $event): ServiceLocatorI
109115
* @throws \Interop\Container\Exception\ContainerException
110116
* @throws \ReflectionException
111117
* @throws \Zend\Mvc\Di\Exceptions\UnsolvableDependencyException
118+
* @throws \Zend\Mvc\ErrorLogger\Exceptions\Logger\InvalidFactoryException
119+
* @throws \Zend\Mvc\ErrorLogger\Exceptions\Logger\InvalidLoggerClassException
120+
* @throws \Zend\Mvc\ErrorLogger\Exceptions\Parse\LoggerClassDefinedAndIgnoredException
121+
* @throws \Zend\Mvc\ErrorLogger\Exceptions\Parse\LoggerClassException
122+
* @throws \Zend\Mvc\ErrorLogger\Exceptions\Parse\NoExceptionClassDefined
123+
* @throws \Zend\Mvc\ErrorLogger\Exceptions\Parse\NoLoggerDefinitionException
112124
*/
113125
public function handlePhpError(MvcEvent $event)
114126
{

src/Logger/Resolver.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
use Zend\Mvc\ErrorLogger\Common\ErrorLogging;
99
use Zend\Mvc\ErrorLogger\Common\LoggerDefinition;
1010
use Zend\Mvc\ErrorLogger\Common\Parse\ConfigurationParser;
11-
use Zend\Mvc\ErrorLogger\Custom\JsonErrorResponseFactoryInterface;
1211
use Zend\Mvc\ErrorLogger\Exceptions\Logger\InvalidFactoryException;
13-
use Zend\Mvc\ErrorLogger\Exceptions\Logger\InvalidJsonErrorResponseFactoryClassException;
1412
use Zend\Mvc\ErrorLogger\Exceptions\Logger\InvalidLoggerClassException;
1513
use Zend\Mvc\MvcEvent;
1614
use Zend\ServiceManager\Factory\FactoryInterface;
@@ -39,27 +37,22 @@ public function __construct(array $configuration)
3937
* @param MvcEvent $event
4038
* @return ErrorLogging
4139
* @throws InvalidFactoryException
42-
* @throws InvalidJsonErrorResponseFactoryClassException
4340
* @throws InvalidLoggerClassException
4441
* @throws \Interop\Container\Exception\ContainerException
4542
* @throws \ReflectionException
4643
* @throws \Zend\Mvc\Di\Exceptions\UnsolvableDependencyException
4744
* @throws \Zend\Mvc\ErrorLogger\Exceptions\Parse\LoggerClassDefinedAndIgnoredException
4845
* @throws \Zend\Mvc\ErrorLogger\Exceptions\Parse\LoggerClassException
4946
* @throws \Zend\Mvc\ErrorLogger\Exceptions\Parse\NoExceptionClassDefined
50-
* @throws \Zend\Mvc\ErrorLogger\Exceptions\Parse\NoJsonErrorResponseFactoryClassDefinedException
5147
* @throws \Zend\Mvc\ErrorLogger\Exceptions\Parse\NoLoggerDefinitionException
5248
*/
5349
public function resolveConfiguration(MvcEvent $event): ErrorLogging
5450
{
5551
$errorLogging = $this->configurationParser->parse($this->configuration);
5652

57-
$this->validateResponseFactory($errorLogging);
58-
5953
$serviceManager = $this->getServiceManager($event);
6054

6155
$injector = new InjectableFactory();
62-
$injector->__invoke($serviceManager, $errorLogging->getResponse());
6356

6457
foreach ($errorLogging->getLoggers() as $logger) {
6558
$this->validateLoggerClassType($logger);
@@ -88,18 +81,6 @@ private function getServiceManager(MvcEvent $event): ServiceLocatorInterface
8881
return $application->getServiceManager();
8982
}
9083

91-
/**
92-
* @param ErrorLogging $errorLogging
93-
* @throws InvalidJsonErrorResponseFactoryClassException
94-
*/
95-
private function validateResponseFactory(ErrorLogging $errorLogging): void
96-
{
97-
if (!in_array(JsonErrorResponseFactoryInterface::class, class_implements($errorLogging->getResponse()))){
98-
throw new InvalidJsonErrorResponseFactoryClassException(sprintf('Json Error Response Factory "%s" must implements "Zend\Mvc\ErrorInterceptor\Custom\JsonErrorResponseFactoryInterface"',
99-
$errorLogging->getResponse()));
100-
}
101-
}
102-
10384
/**
10485
* @param LoggerDefinition $loggerDefinition
10586
* @throws InvalidFactoryException

tests/Common/Parse/ConfigurationParserTest.php

Lines changed: 4 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
use PHPUnit\Framework\TestCase;
77
use Tests\Utils\DatabaseErrorLogger;
88
use Tests\Utils\DatabaseErrorLoggerFactory;
9-
use Tests\Utils\JsonErrorResponseFactory;
10-
use Tests\Utils\SmsErrorLogger;
11-
use Tests\Utils\SmsErrorLoggerFactory;
129
use Tests\Utils\TransferenciaEntreContasException;
1310
use Zend\Mvc\ErrorLogger\Common\Parse\ConfigurationParser;
1411
use Zend\Mvc\ErrorLogger\Exceptions\Parse\LoggerClassDefinedAndIgnoredException;
@@ -18,47 +15,10 @@
1815

1916
class ConfigurationParserTest extends TestCase
2017
{
21-
22-
23-
private function createConfiguration()
24-
{
25-
return [
26-
'error-logging' => [
27-
'response' => JsonErrorResponseFactory::class,
28-
'loggers' => [
29-
[
30-
'logger' => DatabaseErrorLogger::class,
31-
'factory' => DatabaseErrorLoggerFactory::class,
32-
'typeof' => [TransferenciaEntreContasException::class],
33-
'ignored' => []
34-
],
35-
[
36-
'logger' => SmsErrorLogger::class,
37-
'factory' => SmsErrorLoggerFactory::class,
38-
'typeof' => [TransferenciaEntreContasException::class],
39-
'ignored' => []
40-
]
41-
]
42-
]
43-
];
44-
}
45-
46-
private function createConfigurationWithoutJsonErrorResponseFactory()
47-
{
48-
return [
49-
'error-logging' => [
50-
'loggers' => []
51-
]
52-
];
53-
}
54-
55-
56-
5718
private function createCongigurationWithoutLoggers()
5819
{
5920
return [
60-
'error-logging' => [
61-
'response' => JsonErrorResponseFactory::class,
21+
'error_logging' => [
6222
'loggers' => []
6323
]
6424
];
@@ -67,8 +27,7 @@ private function createCongigurationWithoutLoggers()
6727
private function createConfigurationWithNoLoggerClass()
6828
{
6929
return [
70-
'error-logging' => [
71-
'response' => JsonErrorResponseFactory::class,
30+
'error_logging' => [
7231
'loggers' => [
7332
[
7433
'logger' => '',
@@ -89,8 +48,7 @@ private function createParser()
8948
private function createConfigurationWithExceptionClassOnIgnoredList()
9049
{
9150
return [
92-
'error-logging' => [
93-
'response' => JsonErrorResponseFactory::class,
51+
'error_logging' => [
9452
'loggers' => [
9553
[
9654
'logger' => DatabaseErrorLogger::class,
@@ -108,8 +66,7 @@ private function createConfigurationWithExceptionClassOnIgnoredList()
10866
private function createConfigurationWithNoExceptionClassOnLogger()
10967
{
11068
return [
111-
'error-logging' => [
112-
'response' => JsonErrorResponseFactory::class,
69+
'error_logging' => [
11370
'loggers' => [
11471
[
11572
'logger' => DatabaseErrorLogger::class,
@@ -129,7 +86,6 @@ private function createConfigurationWithNoExceptionClassOnLogger()
12986
* @throws NoExceptionClassDefined
13087
* @throws NoLoggerDefinitionException
13188
* @throws \Zend\Mvc\ErrorLogger\Exceptions\Parse\LoggerClassException
132-
* @throws \Zend\Mvc\ErrorLogger\Exceptions\Parse\NoJsonErrorResponseFactoryClassDefinedException
13389
*/
13490
public function testIfNoExceptionClassDefinedForLogger()
13591
{
@@ -149,7 +105,6 @@ public function testIfNoExceptionClassDefinedForLogger()
149105
* @throws NoExceptionClassDefined
150106
* @throws NoLoggerDefinitionException
151107
* @throws \Zend\Mvc\ErrorLogger\Exceptions\Parse\LoggerClassException
152-
* @throws \Zend\Mvc\ErrorLogger\Exceptions\Parse\NoJsonErrorResponseFactoryClassDefinedException
153108
*/
154109
public function testIfExceptionClassExistsOnIgnoredList()
155110
{
@@ -169,7 +124,6 @@ public function testIfExceptionClassExistsOnIgnoredList()
169124
* @throws NoExceptionClassDefined
170125
* @throws NoLoggerDefinitionException
171126
* @throws \Zend\Mvc\ErrorLogger\Exceptions\Parse\LoggerClassException
172-
* @throws \Zend\Mvc\ErrorLogger\Exceptions\Parse\NoJsonErrorResponseFactoryClassDefinedException
173127
*/
174128
public function testIfConfigurationHasNoLoggers()
175129
{
@@ -188,7 +142,6 @@ public function testIfConfigurationHasNoLoggers()
188142
* @throws NoExceptionClassDefined
189143
* @throws NoLoggerDefinitionException
190144
* @throws \Zend\Mvc\ErrorLogger\Exceptions\Parse\LoggerClassException
191-
* @throws \Zend\Mvc\ErrorLogger\Exceptions\Parse\NoJsonErrorResponseFactoryClassDefinedException
192145
*/
193146
public function testIfLoggerConfigurationHasNoLoggerClass()
194147
{
@@ -202,24 +155,4 @@ public function testIfLoggerConfigurationHasNoLoggerClass()
202155
// assert
203156
}
204157

205-
/**
206-
* @expectedException \Zend\Mvc\ErrorLogger\Exceptions\Parse\NoJsonErrorResponseFactoryClassDefinedException
207-
* @throws LoggerClassDefinedAndIgnoredException
208-
* @throws NoExceptionClassDefined
209-
* @throws NoLoggerDefinitionException
210-
* @throws \Zend\Mvc\ErrorLogger\Exceptions\Parse\LoggerClassException
211-
* @throws \Zend\Mvc\ErrorLogger\Exceptions\Parse\NoJsonErrorResponseFactoryClassDefinedException
212-
*/
213-
public function testIfConfigurationHasJsonErrorResponseFactory()
214-
{
215-
// arrange
216-
$config = $this->createConfigurationWithoutJsonErrorResponseFactory();
217-
$parser = $this->createParser();
218-
219-
// act
220-
$parser->parse($config);
221-
222-
// assert
223-
}
224-
225158
}

tests/Listener/ErrorEventListenerTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use PHPUnit\Framework\TestCase;
66
use Tests\Utils\DatabaseErrorLogger;
77
use Tests\Utils\DatabaseErrorLoggerFactory;
8-
use Tests\Utils\JsonErrorResponseFactory;
98
use Tests\Utils\SmsErrorLogger;
109
use Tests\Utils\SmsErrorLoggerFactory;
1110
use Tests\Utils\TransferenciaEntreContasException;
@@ -30,8 +29,7 @@ public function testWhenAnRequestWithErrorIsMade()
3029
'Zend\Router',
3130
],
3231
'module_listener_options' => [],
33-
'error-logging' => [
34-
'response' => JsonErrorResponseFactory::class,
32+
'error_logging' => [
3533
'loggers' => [
3634
[
3735
'logger' => DatabaseErrorLogger::class,

0 commit comments

Comments
 (0)