Skip to content

Commit a075940

Browse files
committed
Update
1 parent 98f7e04 commit a075940

35 files changed

+1243
-1
lines changed

.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
DB_HOST=
2+
DB_USER=
3+
DB_PASS=
4+
DB_DATABASE=

.idea/PHP8GIO.iml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/Attributes/Get.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace App\Attributes;
6+
7+
use Attribute;
8+
9+
#[Attribute(Attribute::TARGET_METHOD|Attribute::IS_REPEATABLE)]
10+
class Get extends Route
11+
{
12+
public function __construct(string $routePath)
13+
{
14+
parent::__construct($routePath);
15+
}
16+
}

app/Attributes/Post.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace App\Attributes;
6+
7+
use App\Enums\HttpMethod;
8+
use Attribute;
9+
10+
#[Attribute(Attribute::TARGET_METHOD|Attribute::IS_REPEATABLE)]
11+
class Post extends Route
12+
{
13+
public function __construct(string $routePath)
14+
{
15+
parent::__construct($routePath, HttpMethod::Post);
16+
}
17+
}

app/Attributes/Put.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace App\Attributes;
6+
7+
use App\Enums\HttpMethod;
8+
use Attribute;
9+
10+
#[Attribute(Attribute::TARGET_METHOD|Attribute::IS_REPEATABLE)]
11+
class Put extends Route
12+
{
13+
public function __construct(string $routePath)
14+
{
15+
parent::__construct($routePath, HttpMethod::Put);
16+
}
17+
}

app/Attributes/Route.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace App\Attributes;
6+
7+
use App\Contracts\RouteInterface;
8+
use App\Enums\HttpMethod;
9+
use Attribute;
10+
11+
#[Attribute(Attribute::TARGET_METHOD|Attribute::IS_REPEATABLE)]
12+
class Route implements RouteInterface
13+
{
14+
public function __construct(public string $routePath, public HttpMethod $method = HttpMethod::Get)
15+
{
16+
}
17+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace App\Contracts;
6+
7+
use App\DTO\EmailValidationResult;
8+
9+
interface EmailValidationInterface
10+
{
11+
public function verify(string $email): EmailValidationResult;
12+
}

app/Contracts/RouteInterface.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace App\Contracts;
6+
7+
interface RouteInterface
8+
{
9+
10+
}

app/Controllers/CurlController.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace App\Controllers;
6+
7+
use App\Attributes\Get;
8+
use App\Contracts\EmailValidationInterface;
9+
10+
class CurlController
11+
{
12+
public function __construct(private EmailValidationInterface $emailValidationService)
13+
{
14+
}
15+
16+
#[Get('/curl')]
17+
public function index()
18+
{
19+
$email = '[email protected]';
20+
$result = $this->emailValidationService->verify($email);
21+
22+
$score = $result->score;
23+
$isDeliverable = $result->isDeliverable;
24+
25+
var_dump($score, $isDeliverable);
26+
27+
echo '<pre>';
28+
print_r($result);
29+
echo '</pre>';
30+
}
31+
}

app/Controllers/InvoiceController.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
5+
namespace App\Controllers;
6+
7+
use App\Attributes\Get;
8+
use App\Enums\InvoiceStatus;
9+
use App\Models\Invoice;
10+
use App\View;
11+
use Carbon\Carbon;
12+
13+
class InvoiceController
14+
{
15+
#[Get('/invoices')]
16+
public function index(): View
17+
{
18+
$invoices = Invoice::query()->where('status', InvoiceStatus::Paid)->get();
19+
20+
return View::make('invoices/index', ['invoices' => $invoices]);
21+
}
22+
23+
#[Get('/invoices/new')]
24+
public function create()
25+
{
26+
$invoice = new Invoice();
27+
28+
$invoice->invoice_number = 5;
29+
$invoice->amount = 20;
30+
$invoice->status = InvoiceStatus::Pending;
31+
$invoice->due_date = (new Carbon())->addDay();
32+
33+
$invoice->save();
34+
35+
echo $invoice->id . ', ' . $invoice->due_date->format('m/d/Y');
36+
}
37+
}

0 commit comments

Comments
 (0)