Skip to content

Instantly share code, notes, and snippets.

@alanpich
alanpich / de-database.php
Created October 30, 2013 23:51
Rough example of de-databasing MODX elements (as far as humanly possible)
<?php
/**
* Rough outline script of extracting MODX elements from the database to
* allow them to be version controlled.
*
* If this script is modified and also run for Snippets, Templates and Plugins
* then you can start to VCS their source
*
* All that would remain would be triggering a cache-refresh after each deployment
*/
<?php
/**
* The above 2 files (and additionals for all included modules) are merged to form a config cache array
*/
return array(
'factories' => array(
'my.foo.service' => 'Different\Library\Service\Factory\FooServiceFactory'
),
// Invokables are exactly that - invoke this class as-is
'invokables' => array(
@alanpich
alanpich / client.js
Created January 24, 2014 17:29
Node/Phantom one-way socket bridge
var PhantomBridgeClient,
net = require('net');
module.exports = PhantomBridgeClient = function(socketPath){
var socket;
@alanpich
alanpich / Controller.php
Created March 2, 2014 13:48
Proposed Slender\Module\Controllers\Controller abstract
<?php
namespace Slender\Module\Controllers;
/**
* Class Controller
*
* Provides a base controller setup for executing methods as actions.
*
* In this case, an action is simply a method on the controller. When the
* action is dispatched, $this->beforeAction() is called, passing it any arguments
@alanpich
alanpich / results.txt
Created March 11, 2014 21:13
Benchmarking dependency injection techniques in PHP
Test 1: Setting a public property directly
- 1000000 iterations in 0.49191880226135ms
Test 2: Setting a private property via setter method
- 1000000 iterations in 11.216212034225ms
Test 3: Setting a private property via Reflection
- 1000000 iterations in 11.286839008331ms
Test 4: Setting a protected property via Reflection
@alanpich
alanpich / 00_Example_Usage.php
Created June 4, 2014 16:19
Example of using PHP Interfaces
<?php
// Example usage
if($myMessage instanceof MessageInterface){
// Because $message implements MessageInterface, we
// can be absolutely sure that it has a send() method
// so don't have to care what it does when sending,
// just that it has the capability to send
$message->send();
}
<?php
use AlanPich\Configurator;
use AlanPich\Configurator\FileTypeAdapter;
$PROJECT_ROOT = dirname(__FILE__);
///////////////////////////////////////////////////////////////////////////////
// Create a configurator
@alanpich
alanpich / App.php
Created March 3, 2015 16:42
Concept for nestable routers in Slim
<?php
namespace Slim;
use FastRoute\Dispatcher;
use FastRoute\Dispatcher\GroupCountBased;
use \Slim\Router2 as Router;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;