Skip to content
Snippets Groups Projects
Commit ba58ff06 authored by Erick Hitter's avatar Erick Hitter
Browse files

Trait for forthcoming singletons

parent c5eb7547
Branches
No related tags found
3 merge requests!6add linting,!5WIP: Add JUnit reporting,!4WIP: Initial release
This commit is part of merge request !4. Comments created here will be created in the context of that merge request.
......@@ -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.
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment