Skip to content

Commit 2e091cd

Browse files
committed
Initial commit
0 parents  commit 2e091cd

12 files changed

Lines changed: 1971 additions & 0 deletions

File tree

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/app/**/*.php
2+
/pre.paths
3+
/pre.compilers
4+
/server.php
5+
/vendor

app/Component/AddTask.pre

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
}

app/Component/Page.pre

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
}

app/Component/Task.pre

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
}

app/Component/TaskList.pre

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
}

composer.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
}

0 commit comments

Comments
 (0)