| 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 $map = array(); |
| 39 |
|
| 40 |
/** |
| 41 |
* put your comment there... |
| 42 |
* |
| 43 |
* @var mixed |
| 44 |
*/ |
| 45 |
protected $node = null; |
| 46 |
|
| 47 |
/** |
| 48 |
* put your comment there... |
| 49 |
* |
| 50 |
* @var mixed |
| 51 |
*/ |
| 52 |
protected $parent = null; |
| 53 |
|
| 54 |
/** |
| 55 |
* put your comment there... |
| 56 |
* |
| 57 |
* @var mixed |
| 58 |
*/ |
| 59 |
protected $register; |
| 60 |
|
| 61 |
/** |
| 62 |
* put your comment there... |
| 63 |
* |
| 64 |
* @var mixed |
| 65 |
*/ |
| 66 |
protected $rules = array(); |
| 67 |
|
| 68 |
/** |
| 69 |
* put your comment there... |
| 70 |
* |
| 71 |
* @param SimpleXMLElement $node |
| 72 |
* @param mixed $factory |
| 73 |
* @return CJT_Models_Package_Xml_Definition_Abstract |
| 74 |
*/ |
| 75 |
public function __construct(SimpleXMLElement $node, $parent, $factory) { |
| 76 |
// Initialize. |
| 77 |
$this->node = $node; |
| 78 |
$this->parent = $parent; |
| 79 |
$this->factory = $factory; |
| 80 |
$this->register = new ArrayObject(array()); |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* put your comment there... |
| 85 |
* |
| 86 |
*/ |
| 87 |
public function getChilds() { |
| 88 |
return $this->childs; |
| 89 |
} |
| 90 |
|
| 91 |
/** |
| 92 |
* put your comment there... |
| 93 |
* |
| 94 |
* @param mixed $child |
| 95 |
*/ |
| 96 |
protected function getDefaultMap($child) { |
| 97 |
// Initiaize. |
| 98 |
$path = ''; |
| 99 |
$factory = $this->getFactory(); |
| 100 |
// Get default object path. |
| 101 |
$path = $factory->obtainRelativePath(get_class($this), $child); |
| 102 |
return $path; |
| 103 |
} |
| 104 |
|
| 105 |
/** |
| 106 |
* put your comment there... |
| 107 |
* |
| 108 |
*/ |
| 109 |
protected function getDefaultRule() { |
| 110 |
return $this->defaultRule; |
| 111 |
} |
| 112 |
|
| 113 |
/** |
| 114 |
* put your comment there... |
| 115 |
* |
| 116 |
*/ |
| 117 |
public function getFactory() { |
| 118 |
return $this->factory; |
| 119 |
} |
| 120 |
|
| 121 |
/*** |
| 122 |
* put your comment there... |
| 123 |
* |
| 124 |
*/ |
| 125 |
protected function getNode() { |
| 126 |
return $this->node; |
| 127 |
} |
| 128 |
|
| 129 |
/** |
| 130 |
* put your comment there... |
| 131 |
* |
| 132 |
*/ |
| 133 |
public function getParent() { |
| 134 |
return $this->parent; |
| 135 |
} |
| 136 |
|
| 137 |
/** |
| 138 |
* put your comment there... |
| 139 |
* |
| 140 |
*/ |
| 141 |
public function processInners() { |
| 142 |
// Initialize. |
| 143 |
$factory = $this->getFactory(); |
| 144 |
$childs = $this->getNode()->children(); |
| 145 |
// For every child node that has childs create an object! |
| 146 |
foreach ($childs as $childNode) { |
| 147 |
// Process only childs with childs nexted! |
| 148 |
// Don't process scalars! |
| 149 |
if (count($childNode->children())) { |
| 150 |
// Get node name. |
| 151 |
$nodeName = $childNode->getName(); |
| 152 |
// Initialize object factory details. |
| 153 |
$objectInfo = array(); |
| 154 |
// Get rule. |
| 155 |
$objectInfo['rule'] = isset($this->rules[$nodeName]) ? $this->rules[$nodeName] : $this->getDefaultRule(); |
| 156 |
// Only process if rule is set to TRUE! |
| 157 |
if ($objectInfo['rule']) { |
| 158 |
// Get object class map. |
| 159 |
$objectInfo['map'] = isset($this->map[$nodeName]) ? $this->map[$nodeName] : $this->getDefaultMap($nodeName); |
| 160 |
// Instantiate object! |
| 161 |
$childObject = $factory->create($this, $objectInfo['map'], $childNode); |
| 162 |
// Share parameters. |
| 163 |
$childObject->register()->exchangeArray($this->register()->getArrayCopy()); |
| 164 |
// Transit. |
| 165 |
$childObject->transit() |
| 166 |
// Process inners. |
| 167 |
->processInners(); |
| 168 |
// Cache! |
| 169 |
$this->childs[] = $childObject; |
| 170 |
} |
| 171 |
} |
| 172 |
} |
| 173 |
return $this; |
| 174 |
} |
| 175 |
|
| 176 |
/** |
| 177 |
* put your comment there... |
| 178 |
* |
| 179 |
*/ |
| 180 |
public function register() { |
| 181 |
return $this->register; |
| 182 |
} |
| 183 |
|
| 184 |
/** |
| 185 |
* put your comment there... |
| 186 |
* |
| 187 |
*/ |
| 188 |
public function transit() { |
| 189 |
return $this; |
| 190 |
} |
| 191 |
|
| 192 |
} // End class. |
| 193 |
|