-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello-world.php
More file actions
34 lines (27 loc) 路 945 Bytes
/
Copy pathhello-world.php
File metadata and controls
34 lines (27 loc) 路 945 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
declare(strict_types=1);
// this is the default namespace; can be specified in build()
namespace App;
require_once dirname(__DIR__) . '/vendor/autoload.php';
use Elephox\Miniphox\Miniphox;
use Elephox\Web\Routing\Attribute\Http\Get;
#[Get] // defaults to '/'
function index(): string
{
return "Hello, World!";
}
#[Get('/greet/[name]')] // using route params
function greet(string $name): string
{
return "Hello, $name!";
}
// This creates a new Miniphox app.
Miniphox::build()
// index() and greet() are mounted at '/api'.
// This maps '/api' -> index() and '/api/greet/[name]' -> greet() according to their attributes above.
//
// You can pass first-class-callables or just the method name to the mount method.
->mount('/api', index(...), 'greet')
// This will start the HTTP server on http://0.0.0.0:8008.
// Pass a string uri to bind to a specific ip address or a different port.
->run();