| 1 |
<?php |
| 2 |
/** |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
/** |
| 7 |
* |
| 8 |
*/ |
| 9 |
abstract class CJTServicesPluginBase implements CJTServicesIPluginBase |
| 10 |
{ |
| 11 |
|
| 12 |
/** |
| 13 |
* put your comment there... |
| 14 |
* |
| 15 |
* @var mixed |
| 16 |
*/ |
| 17 |
private $config; |
| 18 |
|
| 19 |
/** |
| 20 |
* put your comment there... |
| 21 |
* |
| 22 |
* @var mixed |
| 23 |
*/ |
| 24 |
private $dir; |
| 25 |
|
| 26 |
/** |
| 27 |
* put your comment there... |
| 28 |
* |
| 29 |
* @var mixed |
| 30 |
*/ |
| 31 |
private $file; |
| 32 |
|
| 33 |
/** |
| 34 |
* put your comment there... |
| 35 |
* |
| 36 |
* @var mixed |
| 37 |
*/ |
| 38 |
private $services; |
| 39 |
|
| 40 |
/** |
| 41 |
* put your comment there... |
| 42 |
* |
| 43 |
* @var mixed |
| 44 |
*/ |
| 45 |
private $url; |
| 46 |
|
| 47 |
/** |
| 48 |
* put your comment there... |
| 49 |
* |
| 50 |
* @param mixed $file |
| 51 |
* @param mixed $config |
| 52 |
*/ |
| 53 |
protected function __construct( $file, $config ) |
| 54 |
{ |
| 55 |
|
| 56 |
$this->file = $file; |
| 57 |
$this->dir = dirname( $file ); |
| 58 |
$this->url = plugin_dir_url( $file ); |
| 59 |
$this->config = $config; |
| 60 |
|
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* put your comment there... |
| 65 |
* |
| 66 |
* @param mixed $item |
| 67 |
*/ |
| 68 |
public function getConfig( $configNames ) |
| 69 |
{ |
| 70 |
|
| 71 |
$configs = array(); |
| 72 |
|
| 73 |
# Each passed parameter is configuration to be merged to former one |
| 74 |
foreach ( func_get_args() as $configName ) |
| 75 |
{ |
| 76 |
# Generaly target config point to all configs |
| 77 |
# below loop is to point to the correct item |
| 78 |
$targetConfig =& $this->config; |
| 79 |
|
| 80 |
# Explode name and get array element recusively |
| 81 |
foreach ( explode( '.', $configName ) as $itemName ) |
| 82 |
{ |
| 83 |
|
| 84 |
if ( ! isset( $targetConfig[ $itemName ] ) ) |
| 85 |
{ |
| 86 |
throw new Exception( "Config: {$itemName} doesn't exists in {$configName}!!!" ); |
| 87 |
} |
| 88 |
|
| 89 |
# Go deeper as requested |
| 90 |
$targetConfig =& $targetConfig[ $itemName ]; |
| 91 |
} |
| 92 |
|
| 93 |
$configs = array_merge( $configs, $targetConfig ); |
| 94 |
} |
| 95 |
|
| 96 |
return $configs; |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* put your comment there... |
| 101 |
* |
| 102 |
* @param mixed $serviceConfig |
| 103 |
*/ |
| 104 |
public function & getController( $serviceConfig ) |
| 105 |
{ |
| 106 |
|
| 107 |
return CJTServicesMVCController::getInstance( $serviceConfig, $serviceConfig[ 'route' ] ); |
| 108 |
} |
| 109 |
|
| 110 |
/** |
| 111 |
* put your comment there... |
| 112 |
* |
| 113 |
*/ |
| 114 |
public function getDir() |
| 115 |
{ |
| 116 |
return $this->dir; |
| 117 |
} |
| 118 |
|
| 119 |
/** |
| 120 |
* put your comment there... |
| 121 |
* |
| 122 |
*/ |
| 123 |
public function getFile() |
| 124 |
{ |
| 125 |
return $this->file; |
| 126 |
} |
| 127 |
|
| 128 |
/** |
| 129 |
* put your comment there... |
| 130 |
* |
| 131 |
*/ |
| 132 |
public function getName() |
| 133 |
{ |
| 134 |
return basename( $this->dir ); |
| 135 |
} |
| 136 |
|
| 137 |
/** |
| 138 |
* put your comment there... |
| 139 |
* |
| 140 |
*/ |
| 141 |
public function getUrl() |
| 142 |
{ |
| 143 |
return $this->url; |
| 144 |
} |
| 145 |
|
| 146 |
/** |
| 147 |
* put your comment there... |
| 148 |
* |
| 149 |
* @param mixed $list |
| 150 |
*/ |
| 151 |
protected function & loadServices( $list ) |
| 152 |
{ |
| 153 |
|
| 154 |
foreach ( func_get_args() as $service ) |
| 155 |
{ |
| 156 |
|
| 157 |
$this->services[ get_class( $service ) ] =& $service; |
| 158 |
|
| 159 |
# Start |
| 160 |
$service->start(); |
| 161 |
} |
| 162 |
|
| 163 |
return $this; |
| 164 |
} |
| 165 |
|
| 166 |
} |