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 / 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 / .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;
<?php
class FacebookUrlHelper
{
private $graphApiUrl;
private $fbHostname;
public function __construct($graphApiUrl = 'http://graph.facebook.com', $fbHostname = 'facebook.com')
{
@thepsion5
thepsion5 / gist:f35d09ed9b5c8393671a
Last active August 29, 2015 14:24
Laravel Self-Validating Request Example
<?php
namespace MyAppName\Http\Requests\Members;
use Illuminate\Contracts\Validation\Validator;
use InternalPackage\Laravel\Traits\SessionFlashNotifierTrait;
use MyAppName\Http\Requests\Request;
class ImportMembersRequest extends Request
{
use SessionFlashNotifierTrait;
@thepsion5
thepsion5 / AclMiddleware.php
Last active September 16, 2015 20:29
Possible ACL Middleware Implementation for Laravel 5.1.11+
<?php
use AppName\Posts\Post;
use Illuminate\Http\Request;
class GenericAclMiddleware
{
private $entityClasses = [
'post' => Post::class
];
@thepsion5
thepsion5 / AbstractImporter.php
Last active September 22, 2015 18:10
Excerpts from proprietary code used to import items from a CSV
<?php
//namespaces and imports excluded for brevity
abstract class AbstractImporter implements Importer
{
/**
* @var ImportTransformer
*/
private $transformer;
/**
@thepsion5
thepsion5 / CountyElectionResult.php
Created February 24, 2016 00:09
An example of how to use PDO and a simple repository and POPO entity might work, in contrast with a large ORM
<?php
namespace MyApp\Domain;
class CountyElectionResult
{
/**
* @var string
*/
private $county;