Skip to content

Instantly share code, notes, and snippets.

View texdc's full-sized avatar
🕶️

George Cooksey texdc

🕶️
  • Nashville, TN
View GitHub Profile
@texdc
texdc / 1-Notes.md
Last active December 19, 2015 08:59
Notes on refactoring ZF2's "InputFilter"

A few notes from my personal gripes about what InputFilter is and does.

  1. InputFilter is a terrible name as the class mixes sanitation and validation. Rename to something far more appropriate (e.g. InputManager?).
  2. Data should only be processed, not stored - remove setData()

SoC Article

For example, if both raw and sanitized data are required:

<?php
$files = array(
'node-v0.6.18.tar.gz' => 'http://nodejs.org/dist/v0.6.18/node-v0.6.18.tar.gz',
'php-5.4.3.tar.gz' => 'http://it.php.net/get/php-5.4.3.tar.gz/from/this/mirror',
);
function reader($loc) {
if ($f = fopen($loc, 'r')) {
stream_set_blocking($f, 0);
@texdc
texdc / 1-FilterOrSanitizer.md
Last active December 25, 2015 06:09
Filter or Sanitizer?
  • A filter removes unwanted data.
  • A sanitizer modifies data according to a standard or specification.

See FilterIterator

<?php
// generic helpers
interface NameProvider
{
public function getName();
}
trait NameProviderTrait
@texdc
texdc / 1-EventfulLocator.md
Last active August 8, 2017 15:20
A paper-napkin sketch exploring the use of SRP decorators for ZF's service locator.

A use-case for events on a service locator is rare. The most obvious would be logging, but there may be others, good or bad. Still, this should illustrate a more flexible, extensible, and maintainable architecture based around the SRP and decorators.

Pros

  • Locators don't need access to the cross-cutting concerns anymore, reducing the number of dependencies and increasing maintainability and testability.
  • Handles cross-cutting concerns, that can make the code very complex otherwise, in a clean way.
  • All the concerns are easily composable and the result is a SOLID approach towards them.
  • The decorator pattern also allows us to add or remove concerns later at one central location without having to change the business code.
  • The locator can be tailored to the application itself and end up being very small and easily understandable.
@texdc
texdc / error_handler.php
Last active January 4, 2016 12:59
Custom Error Handler
<?php
/**
* Custom error handler
*
* @see http://www.php.net/manual/en/class.errorexception.php#95415
*/
set_error_handler(function ($number, $string, $file, $line) {
// Determine if this error is enabled (php.ini, .htaccess, etc)
if (!(error_reporting() & $number)) {
@texdc
texdc / MailtrapTestCase.php
Last active August 29, 2015 13:56
Mailtrap, Zend Framework 2, and PhpUnit test case
<?php
use InvalidArgumentException;
use PHPUnit_Framework_TestCase as TestCase;
use Zend\Mail\Transport\Smtp as SmtpTransport;
use Zend\Mail\Transport\SmtpOptions;
/**
* A base testcase for mail transactions with Mailtrap.
*
<?php
namespace Barcode;
use Traversable;
use Barcode\Builder\ObjectBuilderInterface as ObjectBuilder;
use Barcode\Builder\RendererBuilderInterface as RendererBuilder;
use Barcode\Object\SpecificationInterface as ObjectSpecification;
use Barcode\Renderer\SpecificationInterface as RenderSpecification;
<?php
namespace Category\Command;
use Category\CategoryId;
use Message\AbstractMessage;
use Message\Message;
use Message\MessageId;
use Message\MessageTrait;
use Product\Command\ProductsCommandTrait;
@texdc
texdc / Role.php
Last active August 29, 2015 13:56
<?php
namespace My\Role;
use RoleId as BaseId;
class RoleId extends BaseId
{
const ADMIN = 'Admin';
const GUEST = 'Guest';