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
<?php | |
## within application building container. | |
## 1. initiate pm routes | |
$app->map->addRoute(Array( | |
'pm'=>Array( | |
'method'=>'any', | |
'uri'=>'pm', | |
'subroute'=>Array(), | |
'bind:execute'=>function($param,$execution) |
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 execution container | |
$original = function($result) | |
{ | |
return "this is original execution"; | |
} | |
## blocks of codes after multiple binding | |
## first (first-parent) container | |
$containers = 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
## routing part. | |
$app->addRoute(Array( | |
"route1"=>Array( | |
"method"=>"get", | |
"uri"=>"test", | |
"execute"=>function($result) | |
{ | |
## forward to other route. | |
return $app->execute('route2',Array('my-param'=>'this is value from route1')); | |
} |
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
<?php | |
// same api. example of adding routes. | |
$app->map->addRoute(array( | |
'r1'=> ['uri'=> 'first-level', 'subroute'=> array( | |
'sr2'=> ['uri'=> 'another-sub'] | |
)] | |
)); | |
// Get route 'r1'. \Exedra\Application\Map\Route | |
$route = $app->map->findByName('r1'); |
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
<?php | |
// Within controller | |
// example laravel eloquent ORM syntax | |
$user = user::find(1); // return \Model\User | |
$locations = location::findAll(); // return \Collection | |
$categories = category::findAll(); // return \Collection | |
$myform = new Form; |
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
var hortToVert = function(arrays) | |
{ | |
var result = []; | |
for(var i in arrays) | |
{ | |
for(var no in arrays[i]) | |
{ | |
if(!result[no]) result[no] = []; | |
result[no].push(arrays[i][no]); | |
} |
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
<?php | |
// filename : /var/www/thisfile.php | |
// cron handler | |
// let say this script is running every 1 minute, by crontab configure like : | |
// * * * * * /path/to/php /var/www/thisfile.php | |
$myTasks = array( | |
'01:20' => function() | |
{ | |
// do something |
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
// case on accessing the data by given fields | |
GET /api/person/10?fields=name,address,phone,delete | |
// api function | |
$person = Entity\Person::find($id); | |
if(!isset($_GET['fields'])) | |
return $person->toArray(); | |
$fields = explode(',', $_GET['fields']); |
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
<?php | |
namespace App\Entity; | |
abstract class Base extends \Illuminate\Database\Eloquent\Model | |
{ | |
protected static function apiFields() | |
{ | |
return array(); | |
} |
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
<?php | |
/* | |
GET /api/articles | |
POST /api/articles | |
GET /api/articles/:article-id | |
PUT /api/articles/:article-id | |
GET /api/articles/:article-id/author | |
GET /api/shops | |
GET /api/shops/:shop-id | |
GET /api/shops/:shop-id/products |
OlderNewer