Skip to content

Commit 74bec60

Browse files
committed
[#.x] - added action/domain/responder classes
1 parent 26bfc05 commit 74bec60

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

src/Action/Hello/GetAction.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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\Action\Hello;
15+
16+
use Phalcon\Api\Domain\Hello\HelloService;
17+
use Phalcon\Api\Responder\Hello\HelloTextResponder;
18+
use Phalcon\Http\Response;
19+
20+
final class GetAction
21+
{
22+
public function __construct(
23+
private readonly HelloService $service,
24+
private readonly HelloTextResponder $responder
25+
) {
26+
}
27+
28+
public function __invoke(): void
29+
{
30+
$service = $this->service;
31+
$responder = $this->responder;
32+
33+
$serviceOutput = $service();
34+
$outputResponse = $responder($serviceOutput);
35+
36+
$outputResponse->send();
37+
}
38+
}

src/Domain/Hello/HelloService.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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\Hello;
15+
16+
use function date;
17+
18+
final class HelloService
19+
{
20+
public function __invoke(): string
21+
{
22+
return "Hello World!!! - " . date("Y-m-d H:i:s");
23+
}
24+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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\Responder\Hello;
15+
16+
use Phalcon\Http\Response;
17+
18+
final class HelloTextResponder
19+
{
20+
public function __construct(
21+
private Response $response
22+
) {
23+
}
24+
25+
public function __invoke(string $payload): Response
26+
{
27+
$this->response->setContent($payload);
28+
29+
return $this->response;
30+
}
31+
}

0 commit comments

Comments
 (0)