1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Containers\Demo\Controller; |
4
|
|
|
|
5
|
|
|
use stdClass; |
6
|
|
|
use Rudra\Container\Facades\Rudra; |
7
|
|
|
use App\Containers\Demo\DemoController; |
8
|
|
|
use App\Containers\Demo\Factory\StdFactory; |
9
|
|
|
use Rudra\Container\Interfaces\RudraInterface; |
10
|
|
|
use App\Containers\Demo\Interface\TestInterface; |
11
|
|
|
use Rudra\EventDispatcher\EventDispatcherFacade as Dispatcher; |
12
|
|
|
|
13
|
|
|
class IndexController extends DemoController |
14
|
|
|
{ |
15
|
|
|
public function __construct(stdClass $std) |
16
|
|
|
{ |
17
|
|
|
$std->name = __METHOD__ . '::Dependency Injection'; |
18
|
|
|
dump($std); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
#[Routing(url: '')] |
22
|
|
|
#[Routing(url: 'name/name')] |
23
|
|
|
#[Routing(url: 'named3/:[\d]{1,3}')] |
24
|
|
|
#[Routing(url: 'namestr/:[a-z]{1,3}')] |
25
|
|
|
#[Routing(url: 'name/:name')] |
26
|
|
|
#[Middleware(name: 'App\Containers\Demo\Middleware\FirstMiddleware')] |
27
|
|
|
#[Middleware(name: 'App\Containers\Demo\Middleware\SecondMiddleware')] |
28
|
|
|
#[AfterMiddleware(name: 'App\Containers\Demo\Middleware\FirstMiddleware')] |
29
|
|
|
#[AfterMiddleware(name: 'App\Containers\Demo\Middleware\SecondMiddleware')] |
30
|
|
|
public function attributes(stdClass $std, stdClass $asd,stdClass $asw,string $name = 'John'): void |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
data([ |
33
|
|
|
"content" => cache(['mainpage']) ?? view(["index", 'mainpage']), |
34
|
|
|
]); |
35
|
|
|
|
36
|
|
|
Dispatcher::dispatch('message', __CLASS__); |
37
|
|
|
$this->info("Hello $name"); |
38
|
|
|
Dispatcher::notify('one'); |
39
|
|
|
|
40
|
|
|
// dump($std); |
41
|
|
|
// dump(Rudra::get('factory')); |
42
|
|
|
// dump(Rudra::get('callable')); |
43
|
|
|
|
44
|
|
|
Rudra::set(['one', [new StdFactory()]]); |
45
|
|
|
dump(Rudra::get('one')); |
46
|
|
|
|
47
|
|
|
Rudra::set(['two', [fn() => (new StdFactory())->create()]]); |
48
|
|
|
dump(Rudra::get('two')); |
49
|
|
|
|
50
|
|
|
Rudra::set(['three', [StdFactory::class]]); |
51
|
|
|
dump(Rudra::get('three')); |
52
|
|
|
|
53
|
|
|
render("layout", data()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
#[Routing(url: 'autowire')] |
57
|
|
|
public function autowire(RudraInterface $rudra, stdClass $std, TestInterface $test, StdFactory $factory): void |
58
|
|
|
{ |
59
|
|
|
dd($rudra, $std, $test, $factory); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @Routing(url = '') |
64
|
|
|
* @Routing(url = 'name/{name}') |
65
|
|
|
* |
66
|
|
|
* @Middleware(name = 'App\Containers\Demo\Middleware\FirstMiddleware') |
67
|
|
|
* @Middleware(name = 'App\Containers\Demo\Middleware\SecondMiddleware') |
68
|
|
|
* |
69
|
|
|
* @AfterMiddleware(name = 'App\Containers\Demo\Middleware\FirstMiddleware') |
70
|
|
|
* @AfterMiddleware(name = 'App\Containers\Demo\Middleware\SecondMiddleware') |
71
|
|
|
*/ |
72
|
|
|
public function annotations(string $name = 'John'): void |
73
|
|
|
{ |
74
|
|
|
data([ |
75
|
|
|
"content" => cache(['mainpage', 'now']) ?? view(["index", 'mainpage']), |
76
|
|
|
]); |
77
|
|
|
|
78
|
|
|
Dispatcher::dispatch('message', __CLASS__); |
79
|
|
|
$this->info("Hello $name"); |
80
|
|
|
|
81
|
|
|
Dispatcher::notify('one'); |
82
|
|
|
|
83
|
|
|
dump(__METHOD__); |
84
|
|
|
|
85
|
|
|
render("layout", data()); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.