Skip to content

Instantly share code, notes, and snippets.

@AmyStephen
AmyStephen / Document.php
Created January 4, 2013 22:56
Implications of use statements on overrides - JDocument Relates to: https://github.com/joomla/joomla-platform/blob/staging/libraries/joomla/document/document.php Example 1: uses dependency injection to pass in the Namespace and the Alias. This enables overriding the location of the class file so that the class can be overridden. The core HTML cl…
namespace Joomla\Document;
class JDocument
{
public function __construct($options = array())
{
if (array_key_exists('lineend', $options))
{
$this->setLineEnd($options['lineend']);
@AmyStephen
AmyStephen / Example1.php
Last active December 11, 2015 00:59
JPlatform Namespace Examples
<?php
/**
* @package Joomla.Platform
* @subpackage Document
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
namespace Joomla\Example1;
@AmyStephen
AmyStephen / CacheInterface.php
Created January 16, 2013 04:43
Simple Cache Interface
<?php
interface Cache
{
/**
* Does cache exist for the key?
*
* @param string $key Key value used to store cache
*
* @return bool
*/
@AmyStephen
AmyStephen / StaticImplementation.php
Created January 24, 2013 11:21
PSR-3 Static Factory Approach
<?php
use Psr\Log\LoggerInterface;
class Foo
{
private $logger;
public function __construct()
{
@AmyStephen
AmyStephen / LocalWriteTest.php
Last active June 15, 2018 20:05
Delete all files and folders in a directory
<?php
$this->path = BASE_FOLDER . '/x/y/z';
if (file_exists($this->path)) {
$objects = new RecursiveIteratorIterator (
new RecursiveDirectoryIterator($this->path),
RecursiveIteratorIterator::SELF_FIRST);
$directories = array();
@AmyStephen
AmyStephen / Data.php
Last active December 12, 2015 01:08
Freaking dots.
<?php
/**
* Discovery retrieves folder and file names
*
* @param $path
*
* @return void
* @since 1.0
*/
public function discovery($path)
@AmyStephen
AmyStephen / Files.php
Last active July 5, 2017 17:47
General purpose folder and file processing for copy, move, delete, and size calculation
<?php
/**
* File class
*
* @package Molajo
* @copyright 2013 Amy Stephen. All rights reserved.
* @license MIT, GPL v2 or later
*/
namespace Molajo;
@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
@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 / 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?###