Created
January 8, 2020 16:54
-
-
Save fatkulnurk/97a6d09aac29216fe719bc79e72f5bb3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Fatkulnurk\Microframework\Http\Message\Response; | |
use Fatkulnurk\Microframework\Routing\RouteCollector; | |
return function (RouteCollector $r) { | |
$r->addRoute('GET', '/', function ($args) { | |
return Response::getInstance() | |
->withView('index', [ | |
'name' => 'fatkul nur k', | |
'birthday' => '18 januari 1999' | |
]); | |
}); | |
$r->addRoute('GET', '/tes-json', function ($args) { | |
$data = [ | |
'biodata' => [ | |
'nama' => 'fatkul nur koirudin', | |
'ttl' => 'Lamongan, 18 Januari 1999', | |
'alamat' => [ | |
'desa' => 'Desa Ngambeg', | |
'kecamatan' => 'Kecamatan Pucuk', | |
'kabupaten' => 'Kabupaten Lamongan' | |
], | |
'email' => '[email protected]', | |
'hoby' => [ | |
'memancing', | |
'belajar hal baru' | |
] | |
] | |
]; | |
return Response::getInstance() | |
->withXml($data); | |
}); | |
$r->addRoute('GET', '/tes-redirect', function ($args) { | |
return Response::getInstance() | |
->withRedirect('http://google.com'); | |
}); | |
$r->addRoute('GET', '/biodata', function ($args) { | |
echo json_encode([ | |
'biodata' => [ | |
'nama' => 'fatkul nur koirudin', | |
'ttl' => 'Lamongan, 18 Januari 1999', | |
'alamat' => [ | |
'desa' => 'Desa Ngambeg', | |
'kecamatan' => 'Kecamatan Pucuk', | |
'kabupaten' => 'Kabupaten Lamongan' | |
], | |
'email' => '[email protected]', | |
'hoby' => [ | |
'memancing', | |
'belajar hal baru' | |
] | |
] | |
]); | |
header('Content-Type: application/json'); | |
}); | |
$r->addRoute('GET', '/home', function ($args) { | |
echo "aa"; | |
}); | |
$r->addRoute('GET', '/user/{id:\d+}[/{name}]', function ($args) { | |
var_dump($args); | |
}); | |
$r->addRoute('GET', '/download-tes', function ($args) { | |
return \Fatkulnurk\Microframework\Http\Message\Response::getInstance() | |
->withDownload('image.jpg', '12345.jpg'); | |
}); | |
$r->addRoute('GET', '/test/{name}', 'Coba::index'); | |
}; | |
// testing handler | |
class Coba | |
{ | |
public function index() | |
{ | |
echo "Aaaa"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment