File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /app /** /* .php
2+ /pre.paths
3+ /pre.compilers
4+ /server.php
5+ /vendor
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App\Component;
4+
5+ use InvalidArgumentException;
6+
7+ class AddTask
8+ {
9+ public function render($props)
10+ {
11+ assert($this->hasValid($props));
12+
13+ return (
14+ <form method={"post"} action={"/add"} className={"add-task"}>
15+ <input name={"text"} type={"text"} />
16+ <button type={"submit"}>add</button>
17+ </form>
18+ );
19+ }
20+
21+ private function hasValid($props)
22+ {
23+ return true;
24+ }
25+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App\Component;
4+
5+ use InvalidArgumentException;
6+
7+ class Page
8+ {
9+ public function render($props)
10+ {
11+ assert($this->hasValid($props));
12+
13+ { $children } = $props;
14+
15+ return (
16+ "<!doctype html>".
17+ <html lang="en">
18+ <body>
19+ {$children}
20+ </body>
21+ </html>
22+ );
23+ }
24+
25+ private function hasValid($props)
26+ {
27+ if (empty($props["children"])) {
28+ throw new InvalidArgumentException("page needs content (children)");
29+ }
30+
31+ return true;
32+ }
33+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App\Component;
4+
5+ use InvalidArgumentException;
6+
7+ class Task
8+ {
9+ public function render($props)
10+ {
11+ assert($this->hasValid($props));
12+
13+ { $children, $id } = $props;
14+
15+ return (
16+ <li className={"task"}>
17+ {$children}
18+ <a href={"/remove/{$id}"}>remove</a>
19+ </li>
20+ );
21+ }
22+
23+ private function hasValid($props)
24+ {
25+ if (!isset($props["id"])) {
26+ throw new InvalidArgumentException("task needs id (attribute)");
27+ }
28+
29+ if (empty($props["children"])) {
30+ throw new InvalidArgumentException("task needs text (children)");
31+ }
32+
33+ return true;
34+ }
35+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App\Component;
4+
5+ use InvalidArgumentException;
6+
7+ class TaskList
8+ {
9+ public function render($props)
10+ {
11+ assert($this->hasValid($props));
12+
13+ { $children } = $props;
14+
15+ return (
16+ <ul className={"task-list"}>
17+ {$this->children($children)}
18+ </ul>
19+ );
20+ }
21+
22+ private function hasValid($props)
23+ {
24+ return true;
25+ }
26+
27+ private function children($children)
28+ {
29+ if (count($children)) {
30+ return {$children}->map(($task) => {
31+ return (
32+ <Task id={$task["id"]}>{$task["text"]}</Task>
33+ );
34+ });
35+ }
36+
37+ return (
38+ <span>No tasks</span>
39+ );
40+ }
41+ }
Original file line number Diff line number Diff line change 1+ {
2+ "require" : {
3+ "silex/silex" : " ^2.0" ,
4+ "pre/collections" : " ^0.4.1" ,
5+ "pre/short-closures" : " ^0.5.2" ,
6+ "pre/phpx" : " ^0.2.0"
7+ },
8+ "autoload" : {
9+ "psr-4" : {
10+ "App\\ " : " app"
11+ }
12+ }
13+ }
You can’t perform that action at this time.
0 commit comments