Exemple #1
0
 /**
  * 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)
 {
     $class = __NAMESPACE__ . '\\' . ucfirst($entity) . 's' . '\\' . ucfirst($type);
     if (class_exists($class)) {
         return $class;
     }
     // Get the field search path array.
     $paths = self::addPath($entity);
     // Try to find the class file.
     $type = strtolower($type) . '.php';
     foreach ($paths as $path) {
         if ($file = \Filesystem::find($path, $type)) {
             require_once $file;
             if (class_exists($class)) {
                 break;
             }
         }
     }
     // Check for all if the class exists.
     return class_exists($class) ? $class : false;
 }
Exemple #2
0
 /**
  * Method to load the form description from an XML file.
  *
  * The reset option works on a group basis. If the XML file references
  * groups that have already been created they will be replaced with the
  * fields in the new XML file unless the $reset parameter has been set
  * to false.
  *
  * @param   string   $file   The filesystem path of an XML file.
  * @param   string   $reset  Flag to toggle whether form fields should be replaced if a field
  *                           already exists with the same group/name.
  * @param   string   $xpath  An optional xpath to search for the fields.
  * @return  boolean  True on success, false otherwise.
  */
 public function loadFile($file, $reset = true, $xpath = false)
 {
     // Check to see if the path is an absolute path.
     if (!is_file($file)) {
         // Not an absolute path so let's attempt to find one using Filesystem.
         $file = Filesystem::find(self::addFormPath(), strtolower($file) . '.xml');
         // If unable to find the file return false.
         if (!$file) {
             return false;
         }
     }
     // Attempt to load the XML file.
     $xml = self::getXML($file, true);
     return $this->load($xml, $reset, $xpath);
 }
Exemple #3
0
 /**
  * Loads an element type.
  *
  * @param   string   The element type.
  * @param   boolean  False (default) to reuse parameter elements; true to load the parameter element type again.
  * @return  object
  */
 public function loadElement($type, $new = false)
 {
     if ($type == 'list') {
         $type = 'select';
     }
     $signature = md5($type);
     if (isset($this->_elements[$signature]) && !$this->_elements[$signature] instanceof __PHP_Incomplete_Class && $new === false) {
         return $this->_elements[$signature];
     }
     $elementClass = __NAMESPACE__ . '\\Element\\' . $type;
     if (!class_exists($elementClass)) {
         if (isset($this->_elementPath)) {
             $dirs = $this->_elementPath;
         } else {
             $dirs = array();
         }
         $source = str_replace('_', DS, $type) . '.php';
         preg_match('/^[A-Za-z0-9_-]+[A-Za-z0-9_\\.-]*([\\\\\\/][A-Za-z0-9_-]+[A-Za-z0-9_\\.-]*)*$/', (string) $source, $matches);
         $file = @(string) $matches[0];
         if ($elementFile = \Filesystem::find($dirs, $file)) {
             include_once $elementFile;
         } else {
             return false;
         }
     }
     if (!class_exists($elementClass)) {
         return false;
     }
     $this->_elements[$signature] = new $elementClass($this);
     return $this->_elements[$signature];
 }