/**
* 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.
*
* @since 1.7.0
*/
protected static function loadType($entity, $type, $new = true)
{
// Reference to an array with current entity's type instances
$types =& self::$entities[$entity];
$key = md5($type);
// Return an entity object if it already exists and we don't need a new one.
if (isset($types[$key]) && $new === false) {
return $types[$key];
}
$class = self::loadClass($entity, $type);
if ($class === false) {
return false;
}
// Instantiate a new type object.
$types[$key] = new $class();
return $types[$key];
}