Skip to content

Instantly share code, notes, and snippets.

@AmyStephen
AmyStephen / Translations with Anonymous Function.php
Last active December 17, 2015 02:49
Translations with Anonymous Function
<?php
namespace Molajo;
{
/** Translation Class */
class Language implements LanguageInterface
{
public function translate($key)
{
@AmyStephen
AmyStephen / PHP Unit Testing with $_FILES and move_uploaded_file.php
Last active December 16, 2015 23:59
I ran into a couple of challenges for how to unit test my FileUpload package.: mocking $_FILES and PHP function "move_uploaded_file." What I ended up doing was establishing a property named $file_array in my upload class. In the constructor, I set that property to the value contained in $_FILES. Then, I allowed it to be overridden by the value i…
<?php
/**
* $files_array contains $_FILE superglobal
*
* Helps with Unit Testing
*
* @var array
*/
protected $file_array = array();
<?php
/**
* Mimetype for your file - requires PHP 5.3, not enabled on default by Windows
*/
$php_mime = finfo_open(FILEINFO_MIME);
$this->mime_type = strtolower(finfo_file($php_mime, $this->your_file_path_and_name));
finfo_close($php_mime);
// Thanks for great discussion from Ben Ramsey, Anthony Ferrara, Dave Reid, Jarvis Badgley
/**
* Mime types - list by http://www.webmaster-toolkit.com/mime-types.shtml
*/
$mime_types = array(
'.3dm' => 'x-world/x-3dmf',
'.3dmf' => 'x-world/x-3dmf',
'.a' => 'application/octet-stream',
'.aab' => 'application/x-authorware-bin',
'.aam' => 'application/x-authorware-map',
@AmyStephen
AmyStephen / DatabaseInterface2.php
Last active December 16, 2015 18:09
Database Interface without SQL Object Interaction
<?php
/**
* Database Interface
*
* @package Molajo
* @copyright 2013 Amy Stephen. All rights reserved.
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
namespace Molajo\Database\Api;
@AmyStephen
AmyStephen / ThemeInterface.php
Created April 18, 2013 21:13
Theme Interface
<?php
/**
* Template Interface
*
* @package Molajo
* @copyright 2013 Amy Stephen. All rights reserved.
* @license http://www.opensource.org/licenses/mit-license.html MIT License
*/
namespace Molajo\Theme\Api;
@AmyStephen
AmyStephen / Women.md
Last active April 20, 2022 03:34
THIS JUST IN: @webandphp Embrace Women in an attempt to Enhance PHPness and Boost Subscriptions

THIS JUST IN: @WebandPHP Embrace Women in an attempt to Enhance PHPness and Boost Subscriptions

< sarcasm >

(PHP) -- A massive sexist storm spanning the globe dumped thousands of foreign messages on unsuspecting geeks as they watched as their tweet stream, normally depicting handy references to JS resources, object oriented design structures and REGEX utilities, turned into a thick sludge of sadness and despair, dividing the community.

Observers agreed, the divide also provided a distinct benefit by making easy work of identifying and arresting misogynist asshats who threaten the very fabric of a community, a community known for communicating using curly brackets, semi-colons and now, with PHP 5.3, namespaces.

Those detained now await no trail, but are able to exercise their right to a quick tagging and permanent display on the Geek Feminist Wiki.

@AmyStephen
AmyStephen / PSR-0 and Composer.md
Last active December 12, 2015 10:09
Documentation of how the environment and how utilizing Composer parameters and the package repository structure, itself, impact the installation path and provide options for how best to implement the PSR-0 for your package.

PSR-0 and Composer

It's helpful to understand how Composer works and how to best utilize the environment as you implement your PSR-0 Namespace. There are factors that you, where you, as a user of the environment, will not be able to change and you should be aware of those points. There are areas where your choices directly impact the folder path and the implementation of your namespace.

##1. Composer Name Parameter##

The first data relevant to the package install path is the name you provide to Composer.

###What is the purpose of the name parameter?###

@AmyStephen
AmyStephen / Builder.php
Last active December 12, 2015 08:08
Week 2: Introducing the "Builder Design Pattern", useful for hiding the complexity of the object construction while presenting a simple-to-use access interface. [ Week 1: Proxy https://gist.github.com/AmyStephen/4693855 ]
<?php
/**
* @package Design Patterns
* @copyright 2013 Amy Stephen. All rights reserved.
* @license MIT
*
* Week 2: Builder Design Pattern ... [ Week 1: Proxy https://gist.github.com/AmyStephen/4693855 ]
*
* Useful to hide the complexity of the object construction while presenting a simple-to-use
* access interface
@AmyStephen
AmyStephen / ProxyPattern.php
Last active December 13, 2018 15:26
Example Proxy Pattern implementation in PHP. The example implements an HTTP Proxy using cURL. Try it out on a local server by downloading and opening the page in your browser.
<?php
/**
* @package Design Patterns
* @copyright 2013 Amy Stephen. All rights reserved.
* @license MIT
*
* Proxy Pattern
*
* A proxy pattern creates an entry point which interacts behind the scenes with other objects.
* Can be useful for implementing access control, to implement lazy loading of resource intensive