| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
stubClassLoader::load('net::stubbles::ipo::interceptors::stubInterceptorInitializer', |
|---|
| 10 |
'net::stubbles::lang::exceptions::stubIllegalArgumentException', |
|---|
| 11 |
'net::stubbles::util::xjconf::xjconf' |
|---|
| 12 |
); |
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class stubInterceptorXJConfInitializer extends stubXJConfAbstractInitializer implements stubInterceptorInitializer |
|---|
| 20 |
{ |
|---|
| 21 |
|
|---|
| 22 |
* descriptor that identifies the initializer |
|---|
| 23 |
* |
|---|
| 24 |
* @var string |
|---|
| 25 |
*/ |
|---|
| 26 |
protected $descriptor = 'interceptors'; |
|---|
| 27 |
|
|---|
| 28 |
* list of pre interceptors |
|---|
| 29 |
* |
|---|
| 30 |
* @var array<stubPreInterceptor> |
|---|
| 31 |
*/ |
|---|
| 32 |
protected $preInterceptors = array(); |
|---|
| 33 |
|
|---|
| 34 |
* list of post interceptors |
|---|
| 35 |
* |
|---|
| 36 |
* @var array<stubPostInterceptor> |
|---|
| 37 |
*/ |
|---|
| 38 |
protected $postInterceptors = array(); |
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
* sets the descriptor that identifies this initializer |
|---|
| 42 |
* |
|---|
| 43 |
* @param string $descriptor |
|---|
| 44 |
*/ |
|---|
| 45 |
public function setDescriptor($descriptor) |
|---|
| 46 |
{ |
|---|
| 47 |
$this->descriptor = $descriptor; |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
* returns the descriptor that identifies the initializer |
|---|
| 52 |
* |
|---|
| 53 |
* @param string $type type of descriptor: config or definition |
|---|
| 54 |
* @return string |
|---|
| 55 |
* @throws stubIllegalArgumentException |
|---|
| 56 |
*/ |
|---|
| 57 |
public function getDescriptor($type) |
|---|
| 58 |
{ |
|---|
| 59 |
switch ($type) { |
|---|
| 60 |
case stubXJConfInitializer::DESCRIPTOR_CONFIG: |
|---|
| 61 |
return $this->descriptor; |
|---|
| 62 |
|
|---|
| 63 |
case stubXJConfInitializer::DESCRIPTOR_DEFINITION: |
|---|
| 64 |
return 'interceptors'; |
|---|
| 65 |
|
|---|
| 66 |
default: |
|---|
| 67 |
|
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
throw new stubIllegalArgumentException('Invalid descriptor type.'); |
|---|
| 71 |
} |
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
* returns the data to cache |
|---|
| 75 |
* |
|---|
| 76 |
* @return array |
|---|
| 77 |
*/ |
|---|
| 78 |
public function getCacheData() |
|---|
| 79 |
{ |
|---|
| 80 |
$cacheData = array('preInterceptors' => array(), 'postInterceptors' => array()); |
|---|
| 81 |
foreach ($this->preInterceptors as $preInterceptor) { |
|---|
| 82 |
if ($preInterceptor instanceof stubSerializable) { |
|---|
| 83 |
$cacheData['preInterceptors'][] = $preInterceptor->getSerialized(); |
|---|
| 84 |
} else { |
|---|
| 85 |
$cacheData['preInterceptors'][] = $preInterceptor->getClassName(); |
|---|
| 86 |
} |
|---|
| 87 |
} |
|---|
| 88 |
|
|---|
| 89 |
foreach ($this->postInterceptors as $postInterceptor) { |
|---|
| 90 |
if ($postInterceptor instanceof stubSerializable) { |
|---|
| 91 |
$cacheData['postInterceptors'][] = $postInterceptor->getSerialized(); |
|---|
| 92 |
} else { |
|---|
| 93 |
$cacheData['postInterceptors'][] = $postInterceptor->getClassName(); |
|---|
| 94 |
} |
|---|
| 95 |
} |
|---|
| 96 |
|
|---|
| 97 |
return $cacheData; |
|---|
| 98 |
} |
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
* sets the data from the cache |
|---|
| 102 |
* |
|---|
| 103 |
* @param array $cacheData |
|---|
| 104 |
*/ |
|---|
| 105 |
public function setCacheData(array $cacheData) |
|---|
| 106 |
{ |
|---|
| 107 |
foreach ($cacheData['preInterceptors'] as $preInterceptor) { |
|---|
| 108 |
if ($preInterceptor instanceof stubSerializedObject) { |
|---|
| 109 |
$this->preInterceptors[] = $preInterceptor->getUnserialized(); |
|---|
| 110 |
} else { |
|---|
| 111 |
$nqClassName = stubClassLoader::getNonQualifiedClassName($preInterceptor); |
|---|
| 112 |
if (null == $nqClassName) { |
|---|
| 113 |
$nqClassName = $preInterceptor; |
|---|
| 114 |
} |
|---|
| 115 |
if (class_exists($nqClassName, false) == false) { |
|---|
| 116 |
stubClassLoader::load($preInterceptor); |
|---|
| 117 |
} |
|---|
| 118 |
|
|---|
| 119 |
$this->preInterceptors[] = new $nqClassName(); |
|---|
| 120 |
} |
|---|
| 121 |
} |
|---|
| 122 |
|
|---|
| 123 |
foreach ($cacheData['postInterceptors'] as $postInterceptor) { |
|---|
| 124 |
if ($postInterceptor instanceof stubSerializedObject) { |
|---|
| 125 |
$this->postInterceptors[] = $postInterceptor->getUnserialized(); |
|---|
| 126 |
} else { |
|---|
| 127 |
$nqClassName = stubClassLoader::getNonQualifiedClassName($postInterceptor); |
|---|
| 128 |
if (null == $nqClassName) { |
|---|
| 129 |
$nqClassName = $postInterceptor; |
|---|
| 130 |
} |
|---|
| 131 |
if (class_exists($nqClassName, false) == false) { |
|---|
| 132 |
stubClassLoader::load($postInterceptor); |
|---|
| 133 |
} |
|---|
| 134 |
|
|---|
| 135 |
$this->postInterceptors[] = new $nqClassName(); |
|---|
| 136 |
} |
|---|
| 137 |
} |
|---|
| 138 |
} |
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 |
* will be called in case the stubXJConfProxy did not find the data in the |
|---|
| 142 |
* cache and the initializer has to load values from the facade |
|---|
| 143 |
* |
|---|
| 144 |
* @param stubXJConfFacade $xjconf |
|---|
| 145 |
*/ |
|---|
| 146 |
public function loadData(stubXJConfFacade $xjconf) |
|---|
| 147 |
{ |
|---|
| 148 |
$this->preInterceptors = $xjconf->getConfigValue('preInterceptors'); |
|---|
| 149 |
$this->postInterceptors = $xjconf->getConfigValue('postInterceptors'); |
|---|
| 150 |
} |
|---|
| 151 |
|
|---|
| 152 |
|
|---|
| 153 |
* sets the list of pre interceptors |
|---|
| 154 |
* |
|---|
| 155 |
* @param array<stubPreInterceptor> $preInterceptors |
|---|
| 156 |
*/ |
|---|
| 157 |
public function setPreInterceptors(array $preInterceptors) |
|---|
| 158 |
{ |
|---|
| 159 |
$this->preInterceptors = $preInterceptors; |
|---|
| 160 |
} |
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 |
* returns the list of pre interceptors |
|---|
| 164 |
* |
|---|
| 165 |
* @return array<stubPreInterceptor> |
|---|
| 166 |
*/ |
|---|
| 167 |
public function getPreInterceptors() |
|---|
| 168 |
{ |
|---|
| 169 |
return $this->preInterceptors; |
|---|
| 170 |
} |
|---|
| 171 |
|
|---|
| 172 |
|
|---|
| 173 |
* sets the list of pre interceptors |
|---|
| 174 |
* |
|---|
| 175 |
* @param array<stubPostInterceptor> $postInterceptors |
|---|
| 176 |
*/ |
|---|
| 177 |
public function setPostInterceptors(array $postInterceptors) |
|---|
| 178 |
{ |
|---|
| 179 |
$this->postInterceptors = $postInterceptors; |
|---|
| 180 |
} |
|---|
| 181 |
|
|---|
| 182 |
|
|---|
| 183 |
* returns the list of post interceptors |
|---|
| 184 |
* |
|---|
| 185 |
* @return array<stubPostInterceptor> |
|---|
| 186 |
*/ |
|---|
| 187 |
public function getPostInterceptors() |
|---|
| 188 |
{ |
|---|
| 189 |
return $this->postInterceptors; |
|---|
| 190 |
} |
|---|
| 191 |
} |
|---|
| 192 |
?> |
|---|