Skip to content

Commit fc71aeb

Browse files
authored
Merge pull request #13 from niden-code/1.x
Catching up with the tests video #5
2 parents a978986 + 8a8e791 commit fc71aeb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+2026
-252
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ jobs:
127127
composer test-unit-coverage
128128
129129
- name: SonarCloud Scan
130-
uses: SonarSource/sonarqube-scan-action@v5
130+
uses: SonarSource/sonarqube-scan-action@v6.0.0
131131
env:
132132
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
133133
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

.gitignore

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
.bash_history
12
.cache
23
.config
3-
.local
4-
.composer
4+
.composer/
55
composer.lock
6-
vendor/
7-
.bash_history
8-
tests/_output
96
.env
7+
.local
8+
storage/logs/
9+
tests/_output
10+
vendor/

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"pds/skeleton": "^1.0",
3131
"phpstan/phpstan": "^2.1",
3232
"phpunit/phpunit": "^11.5",
33-
"squizlabs/php_codesniffer": "^3.13"
33+
"squizlabs/php_codesniffer": "^4.0"
3434
},
3535
"autoload": {
3636
"psr-4": {

public/index.php

Lines changed: 21 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,65 +2,41 @@
22

33
declare(strict_types=1);
44

5-
use Phalcon\Api\Domain\Interfaces\DomainInterface;
6-
use Phalcon\Api\Domain\Interfaces\ResponderInterface;
7-
use Phalcon\Api\Domain\Middleware\ResponseSender;
8-
use Phalcon\Api\Domain\Services\ActionHandler;
95
use Phalcon\Api\Domain\Services\Container;
6+
use Phalcon\Api\Domain\Services\Providers\ErrorHandlerProvider;
7+
use Phalcon\Api\Domain\Services\Providers\RouterProvider;
8+
use Phalcon\Di\ServiceProviderInterface;
109
use Phalcon\Mvc\Micro;
1110

1211
require_once dirname(__DIR__) . '/vendor/autoload.php';
1312

1413
$container = new Container();
1514
$application = new Micro($container);
15+
$container->set(Container::APPLICATION, $application, true);
16+
$now = hrtime(true);
17+
$container->set(
18+
Container::TIME,
19+
function () use ($now) {
20+
return $now;
21+
},
22+
true
23+
);
1624

1725
/**
18-
* Routes
26+
* Providers
1927
*/
20-
$routes = [
21-
[
22-
'method' => 'get',
23-
'pattern' => '/',
24-
'service' => Container::HELLO_SERVICE,
25-
'responder' => Container::HELLO_RESPONDER_JSON,
26-
],
28+
$providers = [
29+
ErrorHandlerProvider::class,
30+
RouterProvider::class,
2731
];
2832

29-
foreach ($routes as $route) {
30-
$method = $route['method'];
31-
$pattern = $route['pattern'];
32-
$serviceName = $route['service'];
33-
$responderName = $route['responder'];
34-
35-
$application->$method(
36-
$pattern,
37-
function () use ($container, $serviceName, $responderName) {
38-
/** @var DomainInterface $service */
39-
$service = $container->get($serviceName);
40-
/** @var ResponderInterface $responder */
41-
$responder = $container->get($responderName);
42-
43-
$action = new ActionHandler($service, $responder);
44-
$action->__invoke();
45-
}
46-
);
33+
/** @var class-string $provider */
34+
foreach ($providers as $provider) {
35+
/** @var ServiceProviderInterface $service */
36+
$service = new $provider();
37+
$container->register($service);
4738
}
4839

49-
$application->finish(
50-
function () use ($container) {
51-
$response = $container->getShared(Container::RESPONSE);
52-
$sender = new ResponseSender();
53-
54-
$sender->__invoke($response);
55-
}
56-
);
57-
58-
$application->notFound(
59-
function () {
60-
echo "404 - Not Found - " . date("Y-m-d H:i:s");
61-
}
62-
);
63-
6440

6541
/** @var string $uri */
6642
$uri = $_SERVER['REQUEST_URI'] ?? '';

src/Domain/Services/ActionHandler.php renamed to src/Domain/ADR/Action/ActionHandler.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111

1212
declare(strict_types=1);
1313

14-
namespace Phalcon\Api\Domain\Services;
14+
namespace Phalcon\Api\Domain\ADR\Action;
1515

16-
use Phalcon\Api\Domain\Interfaces\ActionInterface;
17-
use Phalcon\Api\Domain\Interfaces\DomainInterface;
18-
use Phalcon\Api\Domain\Interfaces\ResponderInterface;
16+
use Phalcon\Api\Domain\ADR\Domain\DomainInterface;
17+
use Phalcon\Api\Domain\ADR\Responder\ResponderInterface;
1918

2019
final readonly class ActionHandler implements ActionInterface
2120
{

src/Domain/Interfaces/ActionInterface.php renamed to src/Domain/ADR/Action/ActionInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
declare(strict_types=1);
1313

14-
namespace Phalcon\Api\Domain\Interfaces;
14+
namespace Phalcon\Api\Domain\ADR\Action;
1515

1616
interface ActionInterface
1717
{

src/Domain/Interfaces/DomainInterface.php renamed to src/Domain/ADR/Domain/DomainInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
declare(strict_types=1);
1313

14-
namespace Phalcon\Api\Domain\Interfaces;
14+
namespace Phalcon\Api\Domain\ADR\Domain;
1515

1616
use Phalcon\Domain\Payload;
1717

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Phalcon API.
5+
*
6+
* (c) Phalcon Team <[email protected]>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Phalcon\Api\Domain\ADR\Responder;
15+
16+
use Phalcon\Api\Domain\Services\Http\Response;
17+
use Phalcon\Domain\Payload;
18+
19+
final class JsonResponder implements ResponderInterface
20+
{
21+
public function __construct(
22+
private Response $response
23+
) {
24+
}
25+
26+
public function __invoke(Payload $payload): Response
27+
{
28+
$result = $payload->getResult();
29+
/** @var string $content */
30+
$content = $result['results'];
31+
32+
$this
33+
->response
34+
->withPayloadData([$content])
35+
->render()
36+
;
37+
38+
return $this->response;
39+
}
40+
}

src/Domain/Interfaces/ResponderInterface.php renamed to src/Domain/ADR/Responder/ResponderInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
declare(strict_types=1);
1313

14-
namespace Phalcon\Api\Domain\Interfaces;
14+
namespace Phalcon\Api\Domain\ADR\Responder;
1515

1616
use Phalcon\Domain\Payload;
1717
use Phalcon\Http\ResponseInterface;

src/Domain/Constants/Dates.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the Phalcon API.
5+
*
6+
* (c) Phalcon Team <[email protected]>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Phalcon\Api\Domain\Constants;
15+
16+
use DateTimeImmutable;
17+
use DateTimeZone;
18+
use Exception;
19+
20+
final class Dates
21+
{
22+
public const DATE_FORMAT = 'Y-m-d';
23+
public const DATE_NOW = 'NOW()';
24+
public const DATE_TIME_FORMAT = 'Y-m-d H:i:s';
25+
public const DATE_TIME_UTC_FORMAT = 'Y-m-d\\TH:i:sp';
26+
public const DATE_TIME_ZONE = 'UTC';
27+
28+
/**
29+
* @param string $date
30+
* @param string $format
31+
*
32+
* @return string
33+
* @throws Exception
34+
*/
35+
public static function toUTC(
36+
string $date = 'now',
37+
string $format = self::DATE_TIME_UTC_FORMAT
38+
): string {
39+
return (new DateTimeImmutable(
40+
$date,
41+
new DateTimeZone(self::DATE_TIME_ZONE)
42+
))->format($format);
43+
}
44+
}

0 commit comments

Comments
 (0)