Skip to content

Commit f8a0824

Browse files
committed
Migrate to plaisio/kernel 3.0.
1 parent bc0891e commit f8a0824

20 files changed

+125
-116
lines changed

build.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
<exec command="composer update" checkreturn="true" passthru="true"/>
55
</target>
66

7+
<target name="kernel">
8+
<exec executable="bin/plaisio" checkreturn="true" passthru="true">
9+
<arg value="--ansi"/>
10+
<arg value="plaisio:kernel-properties"/>
11+
</exec>
12+
</target>
13+
714
<!-- Runs all unit tests -->
815
<target name="unit">
916
<exec command="bin/phpunit test" passthru="true" checkreturn="true"/>

composer.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@
1111
"ext-dom": "*",
1212
"ext-libxml": "*",
1313
"composer/composer": "^1.0",
14-
"plaisio/console": "^1.0",
14+
"plaisio/console": "^2.0.1",
15+
"plaisio/error-logger": "^1.2",
1516
"plaisio/exception": "^1.1",
16-
"plaisio/exception-handler": "^1.1",
17-
"plaisio/kernel": "^2.0",
18-
"plaisio/obfuscator": "^1.2",
17+
"plaisio/exception-handler": "^1.2",
18+
"plaisio/kernel": "^3.1.1",
19+
"plaisio/obfuscator": "^2.0",
20+
"plaisio/request": "^0.10.3",
21+
"plaisio/request-logger": "^1.2",
1922
"plaisio/response-core": "^1.1",
23+
"plaisio/session": "^3.0",
2024
"setbased/helper-code-store-php": "^2.4.1",
2125
"setbased/php-stratum-middle": "^5.2",
2226
"symfony/console": "^5.0"

plaisio-commands.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<commands>
2+
<command name="plaisio:generate-core-exception-handler">\Plaisio\ExceptionHandler\Command\GenerateExceptionHandlerCommand</command>
3+
</commands>

plaisio.xml

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

src/BadRequestExceptionAgent.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
namespace Plaisio\ExceptionHandler;
55

66
use Plaisio\Exception\BadRequestException;
7-
use Plaisio\Kernel\Nub;
7+
use Plaisio\PlaisioObject;
88
use Plaisio\Response\BadRequestResponse;
99

1010
/**
1111
* An agent that handles BadRequestException exceptions.
1212
*/
13-
class BadRequestExceptionAgent
13+
class BadRequestExceptionAgent extends PlaisioObject
1414
{
1515
//--------------------------------------------------------------------------------------------------------------------
1616
/**
@@ -62,20 +62,20 @@ public function handleResponseException(BadRequestException $exception): void
6262
*/
6363
private function handleException(BadRequestException $exception): void
6464
{
65-
Nub::$nub->DL->rollback();
65+
$this->nub->DL->rollback();
6666

6767
// Set the HTTP status to 400 (Bad Request).
6868
$response = new BadRequestResponse();
6969
$response->send();
7070

7171
// Log the bad request.
72-
Nub::$nub->requestLogger->logRequest($response->getStatus());
73-
Nub::$nub->DL->commit();
72+
$this->nub->requestLogger->logRequest($response->getStatus());
73+
$this->nub->DL->commit();
7474

7575
// Only on development environment log the error.
76-
if (Nub::$nub->request->isEnvDev())
76+
if ($this->nub->request->isEnvDev())
7777
{
78-
Nub::$nub->errorLogger->logError($exception);
78+
$this->nub->errorLogger->logError($exception);
7979
}
8080
}
8181

src/Command/GenerateExceptionHandlerCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace Plaisio\ExceptionHandler\Command;
55

66
use Plaisio\Console\Command\PlaisioCommand;
7+
use Plaisio\Console\Helper\PlaisioXmlUtility;
78
use Plaisio\Console\Helper\TwoPhaseWrite;
89
use Plaisio\ExceptionHandler\Helper\ExceptionHandlerCodeGenerator;
910
use Plaisio\ExceptionHandler\Helper\ExceptionHandlerMetadataExtractor;
@@ -37,7 +38,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
3738
$metadataExtractor = new ExceptionHandlerMetadataExtractor($this->io);
3839
$handlers = $metadataExtractor->extractExceptionAgents();
3940

40-
$xmlHelper = new PlaisioXmlHelper();
41+
$xmlHelper = new PlaisioXmlHelper(PlaisioXmlUtility::plaisioXmlPath('exception'));
4142
[$class, $path] = $xmlHelper->queryExceptionHandlerClass();
4243

4344
$generator = new ExceptionHandlerCodeGenerator();

src/DecodeExceptionAgent.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33

44
namespace Plaisio\ExceptionHandler;
55

6-
use Plaisio\Kernel\Nub;
76
use Plaisio\Obfuscator\Exception\DecodeException;
7+
use Plaisio\PlaisioObject;
88
use Plaisio\Response\BadRequestResponse;
99

1010
/**
1111
* An agent that handles DecodeException exceptions.
1212
*/
13-
class DecodeExceptionAgent
13+
class DecodeExceptionAgent extends PlaisioObject
1414
{
1515
//--------------------------------------------------------------------------------------------------------------------
1616
/**
@@ -62,20 +62,20 @@ public function handleResponseException(DecodeException $exception): void
6262
*/
6363
private function handleException(DecodeException $exception): void
6464
{
65-
Nub::$nub->DL->rollback();
65+
$this->nub->DL->rollback();
6666

6767
// Set the HTTP status to 400 (Bad Request).
6868
$response = new BadRequestResponse();
6969
$response->send();
7070

7171
// Log the bad request.
72-
Nub::$nub->requestLogger->logRequest($response->getStatus());
73-
Nub::$nub->DL->commit();
72+
$this->nub->requestLogger->logRequest($response->getStatus());
73+
$this->nub->DL->commit();
7474

7575
// Only on development environment log the error.
76-
if (Nub::$nub->request->isEnvDev())
76+
if ($this->nub->request->isEnvDev())
7777
{
78-
Nub::$nub->errorLogger->logError($exception);
78+
$this->nub->errorLogger->logError($exception);
7979
}
8080
}
8181

src/Helper/ExceptionHandlerCodeGenerator.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
namespace Plaisio\ExceptionHandler\Helper;
55

6+
use Plaisio\ExceptionHandler\ExceptionHandler;
7+
use Plaisio\PlaisioObject;
68
use SetBased\Helper\CodeStore\Importing;
79
use SetBased\Helper\CodeStore\PhpCodeStore;
810

@@ -12,13 +14,6 @@
1214
class ExceptionHandlerCodeGenerator
1315
{
1416
//--------------------------------------------------------------------------------------------------------------------
15-
/**
16-
* The parent class of the generated exception handler.
17-
*
18-
* @var string
19-
*/
20-
private static $parentClass = '\\Plaisio\\ExceptionHandler\\ExceptionHandler';
21-
2217
/**
2318
* The helper object for importing classes.
2419
*
@@ -58,13 +53,14 @@ public function generateCode(string $fullyQualifiedName, array $allAgents): stri
5853
$namespace = ltrim(implode('\\', $parts), '\\');
5954

6055
$this->importing = new Importing($namespace);
61-
$this->importing->addClass(self::$parentClass);
56+
$this->importing->addClass(ExceptionHandler::class);
57+
$this->importing->addClass(PlaisioObject::class);
6258
$this->importClasses($allAgents);
6359

6460
$this->importing->prepare();
6561

6662
$this->generateHeader($namespace);
67-
$this->generateClass($class, $allAgents);
63+
$this->generateClass($class, PlaisioObject::class, $allAgents);
6864
$this->generateTrailer();
6965

7066
return $this->store->getCode();
@@ -74,15 +70,18 @@ public function generateCode(string $fullyQualifiedName, array $allAgents): stri
7470
/**
7571
* Generates the PHP code of the class definition.
7672
*
77-
* @param string $class The class name.
78-
* @param array[] $allAgents The metadata of the exception agents.
73+
* @param string $handlerClass The class name of the exception handler.
74+
* @param string $kernelClass The class name of the kernel of PhpPlaisio.
75+
* @param array[] $allAgents The metadata of the exception agents.
7976
*/
80-
private function generateClass(string $class, array $allAgents): void
77+
private function generateClass(string $handlerClass, string $kernelClass, array $allAgents): void
8178
{
8279
$this->store->append('/**');
8380
$this->store->append(' * Concrete implementation of the exception handler.', false);
8481
$this->store->append(' */', false);
85-
$this->store->append(sprintf('class %s implements ExceptionHandler', $class));
82+
$this->store->append(sprintf('class %s extends %s implements ExceptionHandler',
83+
$handlerClass,
84+
$this->importing->simplyFullyQualifiedName($kernelClass)));
8685
$this->store->append('{');
8786
foreach ($allAgents as $name => $agents)
8887
{
@@ -137,7 +136,7 @@ private function generateMethod(string $method, array $agents)
137136
$this->importing->simplyFullyQualifiedName($agent['type'])));
138137
$this->store->append(sprintf('/** @var %s $exception */',
139138
$this->importing->simplyFullyQualifiedName($agent['type'])));
140-
$this->store->append(sprintf("\$handler = new %s();",
139+
$this->store->append(sprintf("\$handler = new %s(\$this);",
141140
$this->importing->simplyFullyQualifiedName($agent['class'])));
142141
$this->store->append(sprintf('$handler->%s($exception);', $agent['method']));
143142
$this->store->append('break;');

src/Helper/ExceptionHandlerMetadataExtractor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace Plaisio\ExceptionHandler\Helper;
55

6+
use Plaisio\Console\Helper\PlaisioXmlUtility;
67
use Plaisio\Console\Style\PlaisioStyle;
78

89
/**
@@ -207,7 +208,7 @@ private function extractExceptionHandlerBaseName(string $method): ?string
207208
*/
208209
private function readExceptionAgents(): array
209210
{
210-
$helper = new PlaisioXmlHelper();
211+
$helper = new PlaisioXmlHelper(PlaisioXmlUtility::plaisioXmlPath('exception'));
211212

212213
return $helper->extractExceptionAgents();
213214
}

src/Helper/PlaisioXmlHelper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function extractExceptionAgents(): array
2121
$classes = [];
2222

2323
$xpath = new \DOMXpath($this->xml);
24-
$list = $xpath->query('/plaisio/exception/agents/agent');
24+
$list = $xpath->query('/exception/agents/agent');
2525
foreach ($list as $item)
2626
{
2727
$classes[] = $item->nodeValue;
@@ -40,10 +40,10 @@ public function queryExceptionHandlerClass(): array
4040
{
4141
$xpath = new \DOMXpath($this->xml);
4242

43-
$list = $xpath->query('/plaisio/exception/class');
43+
$list = $xpath->query('/exception/class');
4444
$class = $list[0]->nodeValue;
4545

46-
$list = $xpath->query('/plaisio/exception/path');
46+
$list = $xpath->query('/exception/path');
4747
$path = $list[0]->nodeValue;
4848

4949
return [$class, $path];

0 commit comments

Comments
 (0)