10 defined(
'JPATH_PLATFORM') or die;
12 jimport('joomla.filesystem.path');
56 protected static $entities = array();
68 public static function loadFieldType($type, $new =
true)
70 return self::loadType(
'field', $type, $new);
83 public static function loadRuleType($type, $new =
true)
85 return self::loadType(
'rule', $type, $new);
101 protected static function loadType($entity, $type, $new =
true)
104 $types = &self::$entities[$entity];
109 if (isset($types[$key]) && $new ===
false)
114 $class = self::loadClass($entity, $type);
115 if ($class !==
false)
118 $types[$key] =
new $class;
137 public static function loadFieldClass($type)
139 return self::loadClass(
'field', $type);
152 public static function loadRuleClass($type)
154 return self::loadClass(
'rule', $type);
169 protected static function loadClass($entity, $type)
171 if (strpos($type,
'.'))
173 list($prefix, $type) = explode(
'.', $type);
182 if (class_exists($class))
188 $paths = self::addPath($entity);
191 if ($pos = strpos($type,
'_'))
195 for ($i = 0, $n = count($paths); $i < $n; $i++)
198 $path = $paths[$i] .
'/' . strtolower(substr($type, 0, $pos));
201 if (!in_array($path, $paths))
207 $type = substr($type, $pos + 1);
211 $type = strtolower($type) .
'.php';
212 foreach ($paths as $path)
217 if (class_exists($class))
225 return class_exists($class) ? $class :
false;
237 public static function addFieldPath($new = null)
239 return self::addPath(
'field', $new);
251 public static function addFormPath($new = null)
253 return self::addPath(
'form', $new);
265 public static function addRulePath($new = null)
267 return self::addPath(
'rule', $new);
281 protected static function addPath($entity, $new = null)
284 $paths = &self::$paths[$entity];
291 $entity_plural = $entity .
's';
298 $paths[] = __DIR__ .
'/' . $entity_plural;
302 settype($new,
'array');
305 foreach ($new as $path)
307 if (!in_array($path, $paths))
309 array_unshift($paths, trim($path));