Source for file helper.php
Documentation is available at helper.php
* @package Joomla.Platform
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
* Provides a storage for filesystem's paths where JForm's entities reside and methods for creating those entities.
* Also stores objects with entities' prototypes for further reusing.
* @package Joomla.Platform
* Array with paths where entities(field, rule, form) can be found.
* Static array of JForm's entity objects for re-use.
* Prototypes for all fields and rules are here.
protected static $entities =
array();
* Method to load a form field object given a type.
* @param string $type The field type.
* @param boolean $new Flag to toggle whether we should get a new instance of the object.
* @return mixed JFormField object on success, false otherwise.
return self::loadType('field', $type, $new);
* Method to load a form rule object given a type.
* @param string $type The rule type.
* @param boolean $new Flag to toggle whether we should get a new instance of the object.
* @return mixed JFormRule object on success, false otherwise.
return self::loadType('rule', $type, $new);
* Method to load a form entity object given a type.
* Each type is loaded only once and then used as a prototype for other objects of same type.
* Please, use this method only with those entities which support types (forms don't support them).
* @param string $entity The entity.
* @param string $type The entity type.
* @param boolean $new Flag to toggle whether we should get a new instance of the object.
* @return mixed Entity object on success, false otherwise.
protected static function loadType($entity, $type, $new =
true)
// Reference to an array with current entity's type instances
$types =
&self::$entities[$entity];
// Return an entity object if it already exists and we don't need a new one.
if (isset
($types[$key]) &&
$new ===
false)
$class =
self::loadClass($entity, $type);
// Instantiate a new type object.
$types[$key] =
new $class;
* Attempt to import the JFormField class file if it isn't already imported.
* You can use this method outside of JForm for loading a field for inheritance or composition.
* @param string $type Type of a field whose class should be loaded.
* @return mixed Class name on success or false otherwise.
return self::loadClass('field', $type);
* Attempt to import the JFormRule class file if it isn't already imported.
* You can use this method outside of JForm for loading a rule for inheritance or composition.
* @param string $type Type of a rule whose class should be loaded.
* @return mixed Class name on success or false otherwise.
return self::loadClass('rule', $type);
* Load a class for one of the form's entities of a particular type.
* Currently, it makes sense to use this method for the "field" and "rule" entities
* (but you can support more entities in your subclass).
* @param string $entity One of the form entities (field or rule).
* @param string $type Type of an entity.
* @return mixed Class name on success or false otherwise.
protected static function loadClass($entity, $type)
list
($prefix, $type) =
explode('.', $type);
// Get the field search path array.
$paths =
self::addPath($entity);
// If the type is complex, add the base type to the paths.
if ($pos =
strpos($type, '_'))
// Add the complex type prefix to the paths.
for ($i =
0, $n =
count($paths); $i <
$n; $i++
)
// If the path does not exist, add it.
// Break off the end of the complex type.
$type =
substr($type, $pos +
1);
// Try to find the class file.
foreach ($paths as $path)
// Check for all if the class exists.
* Method to add a path to the list of field include paths.
* @param mixed $new A path or array of paths to add.
* @return array The list of paths that have been added.
return self::addPath('field', $new);
* Method to add a path to the list of form include paths.
* @param mixed $new A path or array of paths to add.
* @return array The list of paths that have been added.
return self::addPath('form', $new);
* Method to add a path to the list of rule include paths.
* @param mixed $new A path or array of paths to add.
* @return array The list of paths that have been added.
return self::addPath('rule', $new);
* Method to add a path to the list of include paths for one of the form's entities.
* Currently supported entities: field, rule and form. You are free to support your own in a subclass.
* @param string $entity Form's entity name for which paths will be added.
* @param mixed $new A path or array of paths to add.
* @return array The list of paths that have been added.
protected static function addPath($entity, $new =
null)
// Reference to an array with paths for current entity
$paths =
&self::$paths[$entity];
// Add the default entity's search path if not set.
// While we support limited number of entities (form, field and rule)
// we can do this simple pluralisation:
$entity_plural =
$entity .
's';
* But when someday we would want to support more entities, then we should consider adding
* an inflector class to "libraries/joomla/utilities" and use it here (or somebody can use a real inflector in his subclass).
* See also: pluralization snippet by Paul Osman in JControllerForm's constructor.
$paths[] = __DIR__ .
'/' .
$entity_plural;
// Force the new path(s) to an array.
// Add the new paths to the stack if not already there.
Documentation generated on Tue, 19 Nov 2013 15:04:29 +0100 by phpDocumentor 1.4.3