| 1 |
<?php |
| 2 |
/** |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
/** |
| 7 |
* |
| 8 |
*/ |
| 9 |
abstract class CJT_Models_Package_Xml_Definition_Abstract |
| 10 |
implements CJT_Models_Package_Xml_Definition_Interface_Element { |
| 11 |
|
| 12 |
/** |
| 13 |
* put your comment there... |
| 14 |
* |
| 15 |
* @var mixed |
| 16 |
*/ |
| 17 |
protected $childs = array(); |
| 18 |
|
| 19 |
/** |
| 20 |
* put your comment there... |
| 21 |
* |
| 22 |
* @var mixed |
| 23 |
*/ |
| 24 |
protected $defaultRule = true; |
| 25 |
|
| 26 |
/** |
| 27 |
* put your comment there... |
| 28 |
* |
| 29 |
* @var mixed |
| 30 |
*/ |
| 31 |
protected $factory = null; |
| 32 |
|
| 33 |
/** |
| 34 |
* put your comment there... |
| 35 |
* |
| 36 |
* @var mixed |
| 37 |
*/ |
| 38 |
protected $forceProcess = array(); |
| 39 |
|
| 40 |
/** |
| 41 |
* put your comment there... |
| 42 |
* |
| 43 |
* @var mixed |
| 44 |
*/ |
| 45 |
protected $map = array(); |
| 46 |
|
| 47 |
/** |
| 48 |
* put your comment there... |
| 49 |
* |
| 50 |
* @var mixed |
| 51 |
*/ |
| 52 |
protected $node = null; |
| 53 |
|
| 54 |
/** |
| 55 |
* put your comment there... |
| 56 |
* |
| 57 |
* @var mixed |
| 58 |
*/ |
| 59 |
protected $parent = null; |
| 60 |
|
| 61 |
/** |
| 62 |
* put your comment there... |
| 63 |
* |
| 64 |
* @var mixed |
| 65 |
*/ |
| 66 |
protected $register; |
| 67 |
|
| 68 |
/** |
| 69 |
* put your comment there... |
| 70 |
* |
| 71 |
* @var mixed |
| 72 |
*/ |
| 73 |
protected $rules = array(); |
| 74 |
|
| 75 |
/** |
| 76 |
* put your comment there... |
| 77 |
* |
| 78 |
* @param SimpleXMLElement $node |
| 79 |
* @param mixed $factory |
| 80 |
* @return CJT_Models_Package_Xml_Definition_Abstract |
| 81 |
*/ |
| 82 |
public function __construct(SimpleXMLElement $node, $parent, $factory) { |
| 83 |
// Initialize. |
| 84 |
$this->node = $node; |
| 85 |
$this->parent = $parent; |
| 86 |
$this->factory = $factory; |
| 87 |
$this->register = new ArrayObject(array()); |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* put your comment there... |
| 92 |
* |
| 93 |
*/ |
| 94 |
public function getChilds() { |
| 95 |
return $this->childs; |
| 96 |
} |
| 97 |
|
| 98 |
/** |
| 99 |
* put your comment there... |
| 100 |
* |
| 101 |
* @param mixed $child |
| 102 |
*/ |
| 103 |
protected function getDefaultMap($child) { |
| 104 |
// Initiaize. |
| 105 |
$path = ''; |
| 106 |
$factory = $this->getFactory(); |
| 107 |
// Get default object path. |
| 108 |
$path = $factory->obtainRelativePath(get_class($this), $child); |
| 109 |
return $path; |
| 110 |
} |
| 111 |
|
| 112 |
/** |
| 113 |
* put your comment there... |
| 114 |
* |
| 115 |
*/ |
| 116 |
protected function getDefaultRule() { |
| 117 |
return $this->defaultRule; |
| 118 |
} |
| 119 |
|
| 120 |
/** |
| 121 |
* put your comment there... |
| 122 |
* |
| 123 |
*/ |
| 124 |
public function getFactory() { |
| 125 |
return $this->factory; |
| 126 |
} |
| 127 |
|
| 128 |
/*** |
| 129 |
* put your comment there... |
| 130 |
* |
| 131 |
*/ |
| 132 |
protected function getNode() { |
| 133 |
return $this->node; |
| 134 |
} |
| 135 |
|
| 136 |
/** |
| 137 |
* put your comment there... |
| 138 |
* |
| 139 |
*/ |
| 140 |
public function getParent() { |
| 141 |
return $this->parent; |
| 142 |
} |
| 143 |
|
| 144 |
/** |
| 145 |
* put your comment there... |
| 146 |
* |
| 147 |
*/ |
| 148 |
public function processInners() { |
| 149 |
// Initialize. |
| 150 |
$factory = $this->getFactory(); |
| 151 |
$childs = $this->getNode()->children(); |
| 152 |
// For every child node that has childs create an object! |
| 153 |
foreach ($childs as $childNode) { |
| 154 |
// Get node name. |
| 155 |
$nodeName = $childNode->getName(); |
| 156 |
// Process only childs with childs neested or what added to the force-process-map. |
| 157 |
// Don't process scalars until they're on the force-process-map! |
| 158 |
if (in_array($nodeName, $this->forceProcess) || count($childNode->children())) { |
| 159 |
// Initialize object factory details. |
| 160 |
$objectInfo = array(); |
| 161 |
// Get rule. |
| 162 |
$objectInfo['rule'] = isset($this->rules[$nodeName]) ? $this->rules[$nodeName] : $this->getDefaultRule(); |
| 163 |
// Only process if rule is set to TRUE! |
| 164 |
if ($objectInfo['rule']) { |
| 165 |
// Get object class map. |
| 166 |
$objectInfo['map'] = isset($this->map[$nodeName]) ? $this->map[$nodeName] : $this->getDefaultMap($nodeName); |
| 167 |
// Instantiate object! |
| 168 |
$childObject = $factory->create($this, $objectInfo['map'], $childNode); |
| 169 |
// Share parameters. |
| 170 |
$childObject->register()->exchangeArray($this->register()->getArrayCopy()); |
| 171 |
// Transit. |
| 172 |
$childObject->transit() |
| 173 |
// Process inners. |
| 174 |
->processInners(); |
| 175 |
// Cache! |
| 176 |
$this->childs[] = $childObject; |
| 177 |
} |
| 178 |
} |
| 179 |
} |
| 180 |
return $this; |
| 181 |
} |
| 182 |
|
| 183 |
/** |
| 184 |
* put your comment there... |
| 185 |
* |
| 186 |
*/ |
| 187 |
public function & register() { |
| 188 |
return $this->register; |
| 189 |
} |
| 190 |
|
| 191 |
/** |
| 192 |
* put your comment there... |
| 193 |
* |
| 194 |
*/ |
| 195 |
public function transit() { |
| 196 |
return $this; |
| 197 |
} |
| 198 |
|
| 199 |
/** |
| 200 |
* Default implementation to return physical path |
| 201 |
* relative to the current package document. |
| 202 |
* |
| 203 |
*/ |
| 204 |
public function virtualPath() { |
| 205 |
// Initialize. |
| 206 |
$factory =& $this->factory; |
| 207 |
// Return physical path relative to package document. |
| 208 |
return $factory->getClassRelativePath(get_class($this)); |
| 209 |
} |
| 210 |
|
| 211 |
} // End class. |
| 212 |
|