Commit ba58ff06 authored by Erick Hitter's avatar Erick Hitter
Browse files

Trait for forthcoming singletons

parent c5eb7547
......@@ -12,4 +12,11 @@
* @package Camo_Image_Proxy
*/
// Your code starts here.
namespace Camo_Image_Proxy;
define( __NAMESPACE__ . '\PLUGIN_PATH', dirname( __FILE__ ) );
/**
* Trait for singletons
*/
require_once PLUGIN_PATH . '/inc/trait-singleton.php';
<?php
/**
* Trait file for Singletons.
*
* @package Camo_Image_Proxy
*/
namespace Camo_Image_Proxy;
/**
* Make a class into a singleton.
*/
trait Singleton {
/**
* Existing instance.
*
* @var object
*/
protected static $instance;
/**
* Get class instance.
*
* @return object
*/
public static function instance() {
if ( ! isset( static::$instance ) ) {
static::$instance = new static();
static::$instance->setup();
}
return static::$instance;
}
/**
* Setup the singleton.
*/
public function setup() {
// Silence.
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment