PluginProbe
CSS & JavaScript Toolbox / 11.4
CSS & JavaScript Toolbox v11.4
trunk 0.3 0.8 10 10.1 11 11.2 11.3 11.4 11.5 11.6 11.7 11.8 11.9 11.9.1 12 12.0 12.0.1 12.0.3 12.0.4 12.0.5 12.0.6 12.0.7 6.0 6.0.11 All 60 releases
css-javascript-toolbox / models / package / xml / factory.php

factory.php in CSS & JavaScript Toolbox 11.4, at models/package/xml/factory.php

112 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 object element class name
45 $classPath = "{$this->basePath}/{$path}";
46 $className = 'CJT_' . str_replace(' ', '_', ucwords(str_replace('/', ' ', $classPath)));
47 // Instantiate class.
48 $object = new $className($node, $current, $this);
49 $objectPath = $object->virtualPath();
50 // Cache all instantiated objects so it can be accessed
51 // anywhere inside!
52 if (!isset($this->yields[$objectPath])) {
53 $this->yields[$objectPath] = array();
54 }
55 $this->yields[$objectPath][] = $object;
56 // Return new object.
57 return $object;
58 }
59
60 /**
61 * put your comment there...
62 *
63 */
64 public function getBasePath() {
65 return $this->basePath;
66 }
67
68 /**
69 * put your comment there...
70 *
71 * @param mixed $class
72 */
73 public function getClassRelativePath($class) {
74 // Get class path.
75 $classPath = strtolower(str_replace('_', '/', $class));
76 // Remove base path from the class path.
77 $classRelativePath = str_replace("cjt/{$this->basePath}/", '', $classPath);
78 // returns
79 return $classRelativePath;
80 }
81
82 /**
83 * put your comment there...
84 *
85 * @param mixed $path
86 */
87 public function & getCreatedObjects($path) {
88 // Initialize.
89 $objects = array();
90 /// E_ALL complans
91 if (isset($this->yields[$path])) {
92 $objects = $this->yields[$path];
93 }
94 // Return objects.
95 return $objects;
96 }
97
98 /**
99 * put your comment there...
100 *
101 * @param mixed $class
102 * @param mixed $path
103 */
104 public function obtainRelativePath($class, $innerPath) {
105 // Get class path relative to the package doc.
106 $classRelativePath = $this->getClassRelativePath($class);
107 // Build child relatoive path.
108 $path = "{$classRelativePath}/{$innerPath}";
109 return $path;
110 }
111
112 } // End class.