Skip to content

Instantly share code, notes, and snippets.

@thepsion5
thepsion5 / controller.php
Last active August 29, 2015 13:56
In example illustration of how to use a base query function to generate a filtered and sorted query without repeating code for each function.
<?php
public function index()
{
if(Input::get('sort')) {
$this->offices->sort(Input::get('sort'), Input::get('direction'));
}
$offices = $this->offices->all();
return View::make('app.offices.list', compact('offices'));
}
@thepsion5
thepsion5 / Person Transformer
Last active August 29, 2015 14:00
Simple example of a transformer class
<?php
namespace Infrastructure\Database;
use DateTime,
Domain\Person\PersonEntity as Person,
Domain\Person\Name,
Domain\Person\Email;
class ExamplePersonDomainObjectTransformer extends AbstractTransformer
{
@thepsion5
thepsion5 / LaravelValidator.php
Last active November 10, 2016 07:25
Demonstration of a simple wrapper for Laravel's Validator that allows rules to be altered based on input before validating and exceptions as transports for validation errors
<?php
use Illuminate\Support\MessageBag,
Illuminate\Validation\Factory;
/**
* A simple wrapper for Laravel's native validator. Allows
* validation rules to be modified pre-validation based on
* input and can be used to throw an exception with the
* input and validation failures
@thepsion5
thepsion5 / EloquentFooRepository.php
Created May 2, 2014 15:09
Example implementation of a Eloquent-based repository that provides a fluent interface for sorting and pagination without exposing the underlying model API.
<?php
class EloquenFooRepository
{
/**
* The base eloquent model
* @var Eloquent
*/
protected $model;
@thepsion5
thepsion5 / ContactFormHandler.php
Created June 20, 2014 15:59
Simple contact form example
<?php
class ContactFormHandler
{
public function __construct(ContactFormTemplate $template, ContactFormValidator $validator, ContactFormMailer $mailer)
{
$this->template = $template;
$this->validator = $validator;
$this->mailer = $mailer;
}
@thepsion5
thepsion5 / BaseController.php
Last active February 29, 2020 15:27
Example of using A Laravel Controller to automatically handle validation exceptions and auth failures
<?php
class BaseController extends Controller
{
public function callAction($method, $params)
{
$ajax = Request::isAjax();
try {
return parent::callAction($method, $params);
@thepsion5
thepsion5 / .env.template.php
Created October 8, 2014 22:20
Example of a .env.php template, so developers using their own credentials know what's required
<?php
//Template for all required environment variables
return array(
'DB_USER' => '',
'DB_PASS' => '',
'DB_DATABASE' => '',
'BUGSNAG_KEY' => '',
'NEW_RELIC_APPNAME' => ''
);
@thepsion5
thepsion5 / ServiceContainer.php
Created December 9, 2014 01:17
Simple Service Container Example
<?php
class ServiceContainer
{
protected $services = [];
protected function setCallable($serviceKey, Callable $service)
{
$this->services[$serviceKey] = $service;
return $this;
@thepsion5
thepsion5 / gist:19ae573f6939ff40992f
Created January 30, 2015 18:49
Shell Script to run migrations and database seeders on a Laravel 4 application and dump the resulting DB contents to a SQL file
#!/bin/bash
#Retrieves an environment variable from the correct environment file
#Based on the specified environment
#Example: getEnvVariable local DB_USER VARIABLE
#Will attempt to retrieve the DB_USER array value from the file at .env.local.php
#And then store the result in VARIABLE
getEnvVariable(){
local RESULT=$3
local LOCAL_RESULT=$(php -r '
$file = getcwd() . "/.env." . trim($argv[1]) . ".php";
<?php
class FacebookUrlHelper
{
private $graphApiUrl;
private $fbHostname;
public function __construct($graphApiUrl = 'http://graph.facebook.com', $fbHostname = 'facebook.com')
{