Skip to content

Instantly share code, notes, and snippets.

View eimihar's full-sized avatar

Ahmad Rahimie eimihar

View GitHub Profile
<?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)
@eimihar
eimihar / gist:748ef0b0a89ef46f8ab9
Last active August 29, 2015 14:09
example logic behind multiple container binding
## original execution container
$original = function($result)
{
return "this is original execution";
}
## blocks of codes after multiple binding
## first (first-parent) container
$containers = function($result)
@eimihar
eimihar / gist:e0688887ca43f41b43f0
Created November 11, 2014 05:03
Re-routing/forwarding
## 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'));
}
@eimihar
eimihar / gist:52422bd9a145955b6c41
Last active August 29, 2015 14:13
Objectified route
<?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');
@eimihar
eimihar / gist:c4266dcb54a30af9a272
Created January 22, 2015 17:14
Some pseudo codes of simple mvc logic handling
<?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;
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]);
}
@eimihar
eimihar / gist:d5a2a8cb4a006e8952d4
Last active August 29, 2015 14:20
Cron handling example
<?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
@eimihar
eimihar / gist:12e2bb8826769676258837a1d5b7322f
Last active April 14, 2016 08:56
method invocation on property accessed through getter
// 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']);
@eimihar
eimihar / gist:e03a0ff71b4a148ca343a504596f39be
Last active April 14, 2016 11:14
extended eloquent model
<?php
namespace App\Entity;
abstract class Base extends \Illuminate\Database\Eloquent\Model
{
protected static function apiFields()
{
return array();
}
@eimihar
eimihar / index.php
Created June 19, 2016 22:02
A code sample for youtube v=LrfbmIYAGWI
<?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