1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* Webino Examples |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
use WebinoAppLib\Event\DispatchEvent; |
7
|
|
|
use WebinoAppLib\Event\RouteEvent; |
8
|
|
|
use WebinoAppLib\Response\ViewResponse; |
9
|
|
|
use WebinoAppLib\Router\DefaultRoute; |
10
|
|
|
use WebinoAppLib\View\SourcePreviewComponent; |
11
|
|
|
use WebinoDomLib\Event\RenderEvent; |
12
|
|
|
use WebinoHtmlLib\Html; |
13
|
|
|
use WebinoViewLib\Component\AbstractViewComponent; |
14
|
|
|
use WebinoViewLib\Component\OnDispatchInterface; |
15
|
|
|
use WebinoViewLib\Component\Stylesheet; |
16
|
|
|
use WebinoViewLib\Feature\CommonView; |
17
|
|
|
use WebinoViewLib\Feature\NodeView; |
18
|
|
|
|
19
|
|
|
require __DIR__ . '/../vendor/autoload.php'; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Custom view component |
23
|
|
|
*/ |
24
|
|
|
class ExamplesComponent extends AbstractViewComponent implements OnDispatchInterface |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
private $api; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param NodeView $node |
33
|
|
|
*/ |
34
|
|
|
public function configure(NodeView $node) |
35
|
|
|
{ |
36
|
|
|
$node->setLocator('examples'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param DispatchEvent $event |
41
|
|
|
*/ |
42
|
|
|
public function onDispatch(DispatchEvent $event) |
43
|
|
|
{ |
44
|
|
|
$examples = []; |
45
|
|
|
foreach ($event->getApp()->file()->listContents() as $info) { |
46
|
|
|
if ('dir' !== $info['type']) { |
47
|
|
|
continue; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
list($section) = explode('-', $info['filename'], 2); |
51
|
|
|
$label = ucwords(str_replace('-', ' ', $info['filename'])); |
52
|
|
|
$examples[ucfirst($section)][] = new Html\Url($info['filename'], $label) . new Html\LineBreak; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$this->api = ''; |
56
|
|
|
foreach ($examples as $section => $items) { |
57
|
|
|
$this->api .= new Html\Title4($section); |
58
|
|
|
foreach ($items as $item) { |
59
|
|
|
$this->api .= $item; |
60
|
|
|
} |
61
|
|
|
$this->api .= new Html\LineBreak; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param RenderEvent $event |
67
|
|
|
*/ |
68
|
|
|
public function onRender(RenderEvent $event) |
69
|
|
|
{ |
70
|
|
|
$col = (new Html\Block)->setClass('col-md-4'); |
71
|
|
|
|
72
|
|
|
$event->getNode()->replace([ |
73
|
|
|
(new Html\Block([ |
74
|
|
|
new Html\Title('Webino Examples'), |
75
|
|
|
|
76
|
|
|
(new Html\Text('Showcase of :link prototype usage.')) |
77
|
|
|
->format([':link' => new Html\Url('https://github.com/webino/Webino', 'Webino™')]) |
78
|
|
|
]))->setClass('text-center'), |
79
|
|
|
|
80
|
|
|
new Html\HorizontalLine, |
81
|
|
|
(clone $col)->setValue(new Html\FieldSet(new Html\Title2('API'), new Html\Html($this->api))), |
82
|
|
|
(clone $col)->setValue(new Html\FieldSet(new Html\Title2('Cookbook'), 'TODO...')), |
83
|
|
|
(clone $col)->setValue(new Html\FieldSet(new Html\Title2('Applications'), 'TODO...')), |
84
|
|
|
]); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
$config = Webino::config([ |
89
|
|
|
new CommonView([ |
90
|
|
|
new Stylesheet\BootstrapV3, |
91
|
|
|
new SourcePreviewComponent(__FILE__), |
92
|
|
|
|
93
|
|
|
(new NodeView('content')) |
94
|
|
|
->setLocator('body') |
95
|
|
|
->setHtml('<div class="container jumbotron"><examples/></div><source-preview/>'), |
96
|
|
|
|
97
|
|
|
new ExamplesComponent, |
98
|
|
|
]), |
99
|
|
|
]); |
100
|
|
|
|
101
|
|
|
$app = Webino::application($config, Webino::debugger(Webino::debuggerOptions()->setBar()))->bootstrap(); |
102
|
|
|
|
103
|
|
|
$app->bind(DefaultRoute::class, function (RouteEvent $event) { |
104
|
|
|
$event->setResponse(new ViewResponse); |
105
|
|
|
}); |
106
|
|
|
|
107
|
|
|
$app->dispatch(); |
108
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.