-
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 #6 from fatkulnurk/dev
Dev
- Loading branch information
Showing
55 changed files
with
1,564 additions
and
95 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
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 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,35 +1,92 @@ | ||
<?php | ||
|
||
use Fatkulnurk\Microframework\Http\Message\Response; | ||
use Fatkulnurk\Microframework\Routing\RouteCollector; | ||
|
||
return function (RouteCollector $r) { | ||
|
||
/** | ||
* Example GET route | ||
* | ||
* @param array $args Route parameters | ||
* | ||
* @return \Psr\Http\Message\ResponseInterface | ||
*/ | ||
$r->addRoute('GET', '/', function ($args) { | ||
// echo "hello"; | ||
// echo "aaaaaaa"; | ||
|
||
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' => 'fatkulnurk@gmail.com', | ||
'hoby' => [ | ||
'memancing', | ||
'belajar hal baru' | ||
] | ||
] | ||
]; | ||
|
||
return Response::getInstance() | ||
->withJson($data); | ||
}); | ||
|
||
$r->addRoute('GET', '/tes-redirect', function ($args) { | ||
return Response::getInstance() | ||
->withRedirect('http://google.com'); | ||
}); | ||
|
||
$r->addRoute('GET', '/biodata', function ($args) { | ||
echo json_encode([ | ||
'a' => 'b' | ||
'biodata' => [ | ||
'nama' => 'fatkul nur koirudin', | ||
'ttl' => 'Lamongan, 18 Januari 1999', | ||
'alamat' => [ | ||
'desa' => 'Desa Ngambeg', | ||
'kecamatan' => 'Kecamatan Pucuk', | ||
'kabupaten' => 'Kabupaten Lamongan' | ||
], | ||
'email' => 'fatkulnurk@gmail.com', | ||
'hoby' => [ | ||
'memancing', | ||
'belajar hal baru' | ||
] | ||
] | ||
]); | ||
header('Content-Type: application/json'); | ||
}); | ||
|
||
$r->addRoute('GET', '/home', function ($args, $request, $response) { | ||
$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() { | ||
class Coba | ||
{ | ||
public function index() | ||
{ | ||
echo "Aaaa"; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Halaman Awal</title> | ||
</head> | ||
<body> | ||
<div> | ||
Halo {{ name }}! | ||
<br> | ||
Tanggal lahir kamu {{ birthday }} | ||
</div> | ||
</body> | ||
</html> |
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 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 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 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
namespace Fatkulnurk\Microframework\Http\Data\Document; | ||
|
||
abstract class BaseDocumentArray implements DocumentArray | ||
{ | ||
protected $data = []; | ||
protected $result = ''; | ||
|
||
public function __construct(array $data = []) | ||
{ | ||
$this->data = $data; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
namespace Fatkulnurk\Microframework\Http\Data\Document; | ||
|
||
class BaseDocumentObject | ||
{ | ||
protected $data; | ||
protected $dataArray = []; | ||
protected $result = ''; | ||
|
||
public function __construct(object $data) | ||
{ | ||
$this->data = $data; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
namespace Fatkulnurk\Microframework\Http\Data\Document; | ||
|
||
class Document | ||
{ | ||
protected $data; | ||
|
||
public function __construct($data) | ||
{ | ||
$this->data = $data; | ||
} | ||
|
||
public function result(DocumentFactory $documentFactory) | ||
{ | ||
if (is_object($this->data)) { | ||
$result = $documentFactory->createFromObject($this->data); | ||
} else { | ||
$result = $documentFactory->createFromArray($this->data); | ||
} | ||
|
||
return $result->result(); | ||
} | ||
} | ||
|
||
// CONTOH PENGGUNAAN | ||
//$data = [ | ||
// 'nama' => 'fatkul nur k' | ||
//]; | ||
// | ||
//$dataObj = new Std(); | ||
//$dataObj->name = 'fatkul nur k'; | ||
//$dataObj->birthday = '18 januari 1999'; | ||
// | ||
// | ||
//$document = new Document($data); | ||
//$result = $document->result(new JsonFactory()); | ||
// | ||
//$document = new Document($dataObj); | ||
//$result = $document->result(new JsonFactory()); |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
namespace Fatkulnurk\Microframework\Http\Data\Document; | ||
|
||
interface DocumentArray | ||
{ | ||
public function proses(); | ||
public function result(); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
namespace Fatkulnurk\Microframework\Http\Data\Document; | ||
|
||
interface DocumentFactory | ||
{ | ||
public function createFromArray(array $data); | ||
public function createFromObject(object $data); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
namespace Fatkulnurk\Microframework\Http\Data\Document; | ||
|
||
interface DocumentObject | ||
{ | ||
public function convert(); | ||
public function proses(); | ||
public function result(); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
namespace Fatkulnurk\Microframework\Http\Data\Document; | ||
|
||
class JsonDocumentArray extends BaseDocumentArray implements DocumentArray | ||
{ | ||
public function proses(): void | ||
{ | ||
if (is_array($this->data)) { | ||
$this->result = json_encode($this->data); | ||
} | ||
|
||
$this->result = json_encode((array) $this->data); | ||
} | ||
|
||
public function result() | ||
{ | ||
$this->proses(); | ||
|
||
return $this->result; | ||
} | ||
} |
Oops, something went wrong.