| 1 |
<?php |
| 2 |
/** |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
/** |
| 7 |
* |
| 8 |
*/ |
| 9 |
|
| 10 |
class CJT_Models_Package_Xml_Factory { |
| 11 |
|
| 12 |
/** |
| 13 |
* put your comment there... |
| 14 |
* |
| 15 |
* @var mixed |
| 16 |
*/ |
| 17 |
protected $basePath = ''; |
| 18 |
|
| 19 |
/** |
| 20 |
* put your comment there... |
| 21 |
* |
| 22 |
* @var mixed |
| 23 |
*/ |
| 24 |
protected $yields = array(); |
| 25 |
|
| 26 |
/** |
| 27 |
* put your comment there... |
| 28 |
* |
| 29 |
* @param mixed $basePath |
| 30 |
* @return CJT_Models_Package_Xml_Factory |
| 31 |
*/ |
| 32 |
public function __construct($basePath) { |
| 33 |
$this->basePath = $basePath; |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* put your comment there... |
| 38 |
* |
| 39 |
* @param mixed $current |
| 40 |
* @param mixed $path |
| 41 |
* @param mixed $node |
| 42 |
*/ |
| 43 |
public function create($current, $path, $node) { |
| 44 |
// Get loader. |
| 45 |
$loader = CJT_Framework_Autoload_Loader::autoLoad('CJT'); |
| 46 |
// Get object element class name |
| 47 |
$classPath = "{$this->basePath}/{$path}"; |
| 48 |
$className = 'CJT_' . str_replace(' ', '_', ucwords(str_replace('/', ' ', $classPath))); |
| 49 |
// Instantiate class. |
| 50 |
$object = new $className($node, $current, $this); |
| 51 |
// Cache all instantiated objects so it can be accessed |
| 52 |
// anywhere inside! |
| 53 |
if (!isset($this->yields[$path])) { |
| 54 |
$this->yields[$path] = array(); |
| 55 |
} |
| 56 |
$this->yields[$path][] = $object; |
| 57 |
// Return new object. |
| 58 |
return $object; |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* put your comment there... |
| 63 |
* |
| 64 |
*/ |
| 65 |
public function getBasePath() { |
| 66 |
return $this->basePath; |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* put your comment there... |
| 71 |
* |
| 72 |
* @param mixed $path |
| 73 |
*/ |
| 74 |
public function getCreatedObjects($path) { |
| 75 |
// Initialize. |
| 76 |
$objects = array(); |
| 77 |
/// E_ALL complans |
| 78 |
if (isset($this->yields[$path])) { |
| 79 |
$objects = $this->yields[$path]; |
| 80 |
} |
| 81 |
// Return objects. |
| 82 |
return $objects; |
| 83 |
} |
| 84 |
/** |
| 85 |
* put your comment there... |
| 86 |
* |
| 87 |
* @param mixed $class |
| 88 |
* @param mixed $path |
| 89 |
*/ |
| 90 |
public function obtainRelativePath($class, $innerPath) { |
| 91 |
// Get class path. |
| 92 |
$classPath = strtolower(str_replace('_', '/', $class)); |
| 93 |
// Remove base path from the class path. |
| 94 |
$classRelativePath = str_replace("cjt/{$this->basePath}/", '', $classPath); |
| 95 |
// Build child relatoive path. |
| 96 |
$path = "{$classRelativePath}/{$innerPath}"; |
| 97 |
return $path; |
| 98 |
} |
| 99 |
|
| 100 |
} // End class. |