Skip to content

Instantly share code, notes, and snippets.

@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;
<?php
use AlanPich\Configurator;
use AlanPich\Configurator\FileTypeAdapter;
$PROJECT_ROOT = dirname(__FILE__);
///////////////////////////////////////////////////////////////////////////////
// Create a configurator
@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();
}
@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 / 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 / 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;
<?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 / 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
*/
@alanpich
alanpich / modx.package-install.php
Last active December 1, 2016 15:48
Rough outline of installing transport packages via the CLI
<?php
$path_to_modx = '/var/www/modx';
define('MODX_API_MODE',true);
require $path_to_modx."/index.php";
/** @var \modX $modx */
// Download Details
/** @var string $package_url - URL from the orange 'Download' button on the MODx Extras website */
$package_url = 'http://modx.com/extras/download/?id=512403a2f245547611000025'
$package_signature = 'getresources-1.6.0-pl'
@alanpich
alanpich / getchildlist.class.php
Last active December 18, 2015 00:49
Amending ModxCampaignMonitor extra to allow MCM.combo.resource to only show resources that are direct children on a parent resource
<?php
/** core/components/mcm/processors/mgr/resource/getchildlist.class.php */
/**
* Create this file to allow filtering of resources by a parent ID
*
* @param int $parentId
* @return array Array of modResource child elements
*
*/
if(!class_exists('modObjectGetListProcessor')){