Skip to content

Instantly share code, notes, and snippets.

View rizqidjamaluddin's full-sized avatar

Rizqi Djamaluddin rizqidjamaluddin

  • Jakarta, Indonesia
View GitHub Profile
@rizqidjamaluddin
rizqidjamaluddin / gist:a9a88fda81e96d65b4cb
Created May 8, 2014 07:32
Baseline vagrant bootstrap.sh file. PHP5, MySQL, composer, redis, server at 192.168.33.10.xip.io, based on a terrifying combination of other people's scripts
#!/usr/bin/env bash
echo ">>> Starting Install Script"
# Update
sudo apt-get update
# Install MySQL without prompt
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password password root'
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password root'
@rizqidjamaluddin
rizqidjamaluddin / gist:61cd7f61ca36cf5c2d5a
Last active February 19, 2020 22:01
Run a bunch of phpunit tests in sequence via Laravel 4's artisan CLI
<?php
use Illuminate\Console\Command;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class RunTests extends Command
{
@rizqidjamaluddin
rizqidjamaluddin / gist:72f5cc7fc22f336dac7a
Last active August 29, 2015 14:05
Experimental cross-package decoration
<?php
// part of "Users" package
/*
* The drawback here is that the User class must be moved into the userland space so the developers can attach
* decorating packages to it. Maybe this could be set up automatically via a (laravel-specific) config var?
*/
class User {
@rizqidjamaluddin
rizqidjamaluddin / Schema
Created October 16, 2014 11:31
An experimental idea of an endpoint schema with translation logic
class MessageSchema extends EndpointSchema
{
public function bridge () {
return [
'message' => new Parameter([
'get' => function($e) {
return $e->getMessage();
}
'set' => function($i, $e) {
return $e->setMessage($i);
@rizqidjamaluddin
rizqidjamaluddin / BlogCommentAuthorizer.php
Last active August 29, 2015 14:07
New Gatekeeper package setup, now with bonus policies and per-model authorizer classes
<?php
class BlogCommentAuthorizer extends GatekeeperAuthorizer {
public function register () {
// if you own it, you can read and edit it
$this->enforce([new OwnershipPolicy, new ActionPolicy(['read', 'edit'])]);
// members can read, admins can do anything
$this->enforce(new AclPolicy($this->getAcl()));
<?php
class BlogPostCommentAuthorizer {
public function can ($user, $blogPost, $comment) {
$judge = new Judge;
// blog post owner is obviously allowed to comment for sure
$policy = new EqualityPolicy();
$judge->consider($policy->enforce($user->id, $blogPost->getOwner()->id));
// ACL option. the list would generally be put in a separate file/config
<?php
class NewsAuthorizer {
public function canPublish(Actor $user, NewsPost $post) {
// using different classes to the Actor interface?
return $user instanceof Editor;
// got more complex rules, like the user can only post news within their area of expertise?
<?php
class CakeController {
public function createOrder() {
$cake = new Cake();
$cake->isFor(Input::get('customer'));
$cake->addFlavor(Input::get('flavor'));
$cake->bake();
$cake->save();
return $cake;
<?php
class CakeService {
public function makeOrder($customer, $flavor) {
$cake = new Cake();
$cake->isFor($customer);
$cake->addFlavor($flavor);
$cake->bake();
$cake->save();
return $cake;
<?php
class CakeController {
public function __construct (CakeService $cakeService) {
$this->cakeService = $cakeService;
}
public function createOrder() {
$customer = Input::get('customer');
$flavor = Input::get('flavor');
return $this->cakeService->makeOrder($customer, $flavor);