-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from fatkulnurk/dev
Merge From Dev
- Loading branch information
Showing
21 changed files
with
542 additions
and
242 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,97 @@ PHP Microframework | |
|
||
Baca dokumentasi selengkapnya [link belum ada]. | ||
|
||
--- | ||
|
||
## Cara Install | ||
gunakan composer, lalu jalankan perintah dibawah ini (pastikan sudah install composer) | ||
|
||
```` | ||
composer create-project --prefer-dist fatkulnurk/microframework nama_aplikasi | ||
```` | ||
|
||
--- | ||
**Mendaftarkan Routing** | ||
|
||
Pendaftaran Routing | ||
|
||
contoh pendaftaran routing beserta implementasinya, contoh dibawah ini untuk return berupa xml. | ||
|
||
```` | ||
use Fatkulnurk\Microframework\Routing\RouteCollector; | ||
return function (RouteCollector $r) { | ||
$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); | ||
}); | ||
}; | ||
```` | ||
|
||
Routing Handler Berupa Callback | ||
|
||
dibawah ini contoh routing dengan callback. | ||
```` | ||
$r->addRoute('GET', '/', function ($args) { | ||
return Response::getInstance() | ||
->withView('index', [ | ||
'name' => 'fatkul nur k', | ||
'birthday' => '18 januari 1999' | ||
]); | ||
}); | ||
```` | ||
|
||
|
||
|
||
Routing Dengan handler berupa class | ||
|
||
dibawah ini contoh routing dengan handler berupa method dari suatu class. | ||
perlu di ingat, untuk pemanggilan adalah NamaClass::NamaMethod | ||
```` | ||
$r->addRoute('GET', '/test/{name}', 'Coba::index'); | ||
```` | ||
|
||
Buat class sebagai handlernya, contohnya dibawah ini. | ||
```` | ||
class Coba { | ||
public function index() | ||
{ | ||
echo "Hello World"; | ||
} | ||
} | ||
```` | ||
|
||
## Response | ||
method yang bisa digunakan untuk response sama dengan yang ada pada aturan PSR 7. | ||
|
||
untuk method tambahan adalah sebagai berikut: | ||
- withView() | ||
- withJson() | ||
- withXml() | ||
- withRedirect() | ||
- withDownload() | ||
|
||
## Request | ||
semua sama seperti PSR 7. Gunakan seperti di framework lain. | ||
|
||
--- | ||
**Cek CodeStyle** | ||
|
||
|
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,92 +1,9 @@ | ||
<?php | ||
|
||
use Fatkulnurk\Microframework\Http\Message\Response; | ||
use Fatkulnurk\Microframework\Routing\RouteCollector; | ||
|
||
return function (RouteCollector $r) { | ||
$r->addRoute('GET', '/', function ($args) { | ||
|
||
var_dump(\Fatkulnurk\Microframework\Http\Message\ServerRequest::getInstance() | ||
->make('GET', $_SERVER['REQUEST_URI'])->getUri()); | ||
|
||
die(); | ||
return Response::getInstance() | ||
->withView('index', [ | ||
'name' => 'fatkul nur koirudin', | ||
'birthday' => '18 januari 1999' | ||
], new \Fatkulnurk\Microframework\Http\Data\View\Page()); | ||
|
||
// /* Contoh return data view tanpa template factory */ | ||
// return Response::getInstance() | ||
// ->withView('index', [ | ||
// 'name' => 'fatkul nur k', | ||
// 'birthday' => '18 januari 1999' | ||
// , new \Fatkulnurk\Microframework\Http\Data\View\LexTemplateFactory()]); | ||
}); | ||
|
||
$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() | ||
->withJson($data); | ||
}); | ||
|
||
$r->addRoute('GET', '/tes-redirect', function ($args) { | ||
return Response::getInstance() | ||
->withRedirect('http://google.com'); | ||
echo "Hello World"; | ||
}); | ||
|
||
$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', '/test/{name}', 'Coba::index'); | ||
}; | ||
|
||
// testing handler | ||
class Coba | ||
{ | ||
public function index() | ||
{ | ||
echo "Aaaa"; | ||
} | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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
Oops, something went wrong.