| 1 |
<?php |
| 2 |
/** |
| 3 |
* Manager trait. |
| 4 |
* |
| 5 |
* @package Tableberg |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Tableberg\includes\traits; |
| 9 |
|
| 10 |
require_once TABLEBERG_DIR_PATH . 'includes/traits/Singleton_Trait.php'; |
| 11 |
|
| 12 |
/** |
| 13 |
* Manager base trait. |
| 14 |
*/ |
| 15 |
trait Manager_Base_Trait { |
| 16 |
use Singleton_Trait; |
| 17 |
|
| 18 |
/** |
| 19 |
* Initialization status for manager base. |
| 20 |
* |
| 21 |
* @var bool |
| 22 |
*/ |
| 23 |
protected static $initialized = false; |
| 24 |
|
| 25 |
/** |
| 26 |
* Is manager initialized. |
| 27 |
* |
| 28 |
* @return bool initialization status |
| 29 |
*/ |
| 30 |
public static function is_initialized() { |
| 31 |
return static::$initialized; |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Set current manager base as initialized. |
| 36 |
* |
| 37 |
* @return void |
| 38 |
*/ |
| 39 |
protected static function set_as_initialized() { |
| 40 |
static::$initialized = true; |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* Main process that will be called during initialization of manager. |
| 45 |
* |
| 46 |
* @return void |
| 47 |
*/ |
| 48 |
abstract protected function init_process(); |
| 49 |
|
| 50 |
/** |
| 51 |
* Initialize manager. |
| 52 |
* |
| 53 |
* Since this base is using singleton trait and abstract class together, you should provide class name of extended manager in init function. |
| 54 |
* |
| 55 |
* @param array $const_args constructor arguments for singleton instance of manager. |
| 56 |
* @param string|null $class_name class name to create instance. |
| 57 |
* |
| 58 |
* @return void |
| 59 |
*/ |
| 60 |
final public static function init( $const_args = array(), $class_name = null ) { |
| 61 |
if ( ! static::is_initialized() ) { |
| 62 |
static::create_instance( $const_args, $class_name ); |
| 63 |
static::$instance->init_process(); |
| 64 |
static::set_as_initialized(); |
| 65 |
} |
| 66 |
} |
| 67 |
} |
| 68 |
|