Exemplo n.º 1
0
 /**
  *Gets a form element instance according to the context obtained from the within the Kernel::getSAPI method
  *
  *@param string $type									The *type* of the element, input, select, etc>
  *@param ElementConfigInterface						The configuration for said element.
  *@param string $ui										User Interface for the given element type, web, cli, etc
  */
 public static function getInstanceFromUIContext($type, $ui = NULL)
 {
     $type = trim($type);
     /**
      *An element type is mandatory. This "type" is the type of element one wishes to create
      *an input element, a select element, etc.
      */
     if (empty($type)) {
         throw new \InvalidArgumentException("Must specify element type!");
     }
     /**
      *	If no $ui is specified, autodetect the user interface through the Kernel::getSAPI object
      */
     if ($ui === NULL) {
         $ui = Kernel::getSAPI()->getName();
     }
     $class = self::getElementClassByTypeAndUI($type, $ui);
     /**
      *	Return a new element type instance, configured with a name, a value and a layout container.
      */
     return new $class();
 }
Exemplo n.º 2
0
 /**
  * Gets a form instance according to the context obtained from the within the Kernel::getSAPI method
  *
  * @return	\apf\ui\form\Cli			If the autodetected context is cli or if the $ui argument is equal to cli
  * @return	\apf\ui\form\Web			If the autodetected context is web or if the $ui argument is equal to web
  */
 public static function getInstanceFromUIContext($ui = NULL)
 {
     /**
      * If no $ui is specified, autodetect it through the Kernel::getSAPI object
      */
     if ($ui === NULL) {
         $ui = Kernel::getSAPI()->getName();
     }
     /**
      * Compose the class name
      */
     $class = sprintf('\\apf\\ui\\form\\%s', ucwords($ui));
     /**
      * Corroborate that the given form UI class does in fact exists
      */
     if (!class_exists($class)) {
         throw new \InvalidArgumentException("No Form UI named \"{$ui}\" was found, perhaps you'd like to help and create it?");
     }
     /**
      * Create a new form instance of the corresponding form considering the context 
      * where PHP is being called, i.e cli, web, etc
      */
     return new $class();
 }