diff --git a/camo-image-proxy.php b/camo-image-proxy.php index 3d1cb47ae5e2ab099561d31b32c896a898119d33..d9f8865450d85a91b16b8655674e7a29209baef8 100755 --- a/camo-image-proxy.php +++ b/camo-image-proxy.php @@ -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'; diff --git a/inc/trait-singleton.php b/inc/trait-singleton.php new file mode 100644 index 0000000000000000000000000000000000000000..b890d8dea40792bc78dbf38c352bc4eaf030840d --- /dev/null +++ b/inc/trait-singleton.php @@ -0,0 +1,40 @@ +<?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. + } +}