Ejemplo n.º 1
0
 /**
  * Set a Model's properties as fields on a Fieldset, which will be created with the Model's
  * classname if none is provided.
  *
  * @param   string
  * @param   Fieldset|null
  * @return  Fieldset
  */
 public static function set_fields($class, $fieldset = null)
 {
     $properties = $class::properties();
     if (is_null($fieldset)) {
         $fieldset = \Fieldset::instance($class);
         if (!$fieldset) {
             $fieldset = \Fieldset::factory($class);
         }
     }
     foreach ($properties as $p => $settings) {
         $field = $fieldset->add($p, !empty($settings['label']) ? $settings['label'] : $p);
         if (empty($settings['validation'])) {
             continue;
         } else {
             foreach ($settings['validation'] as $rule => $args) {
                 if (is_int($rule) and is_string($args)) {
                     $args = array($args);
                 } else {
                     array_unshift($args, $rule);
                 }
                 call_user_func_array(array($field, 'add_rule'), $args);
             }
         }
     }
     return $fieldset;
 }
Ejemplo n.º 2
0
 /**
  * Set a Model's properties as fields on a Fieldset, which will be created with the Model's
  * classname if none is provided.
  *
  * @param   string
  * @param   Fieldset|null
  * @return  Fieldset
  */
 public static function set_fields($obj, $fieldset = null)
 {
     static $_generated = array();
     $class = is_object($obj) ? get_class($obj) : $obj;
     if (is_null($fieldset)) {
         $fieldset = \Fieldset::instance($class);
         if (!$fieldset) {
             $fieldset = \Fieldset::factory($class);
         }
     }
     !array_key_exists($class, $_generated) and $_generated[$class] = array();
     if (in_array($fieldset, $_generated[$class], true)) {
         return $fieldset;
     }
     $_generated[$class][] = $fieldset;
     $fieldset->validation()->add_callable($obj);
     $properties = is_object($obj) ? $obj->properties() : $class::properties();
     foreach ($properties as $p => $settings) {
         $field = $fieldset->add($p, !empty($settings['label']) ? $settings['label'] : $p);
         if (empty($settings['validation'])) {
             continue;
         } else {
             foreach ($settings['validation'] as $rule => $args) {
                 if (is_int($rule) and is_string($args)) {
                     $args = array($args);
                 } else {
                     array_unshift($args, $rule);
                 }
                 call_user_func_array(array($field, 'add_rule'), $args);
             }
         }
     }
     return $fieldset;
 }
Ejemplo n.º 3
0
 protected function __construct($fieldset)
 {
     if (!$fieldset instanceof Fieldset) {
         $fieldset = Fieldset::factory($fieldset, array('validation_instance' => $this));
     }
     $this->fieldset = $fieldset;
     $this->callables = array($this);
 }
Ejemplo n.º 4
0
	public static function factory($fieldset)
	{
		if ( ! $fieldset instanceof Fieldset)
		{
			$fieldset = (string) $fieldset;
			if ( ! ($fieldset = \Fieldset::instance($fieldset)))
			{
				$fieldset = \Fieldset::factory($fieldset);
			}
		}
		return new Validation($fieldset);
	}
Ejemplo n.º 5
0
Archivo: form.php Proyecto: nasumi/fuel
	public static function factory($fieldset, $config)
	{
		if ( ! $fieldset instanceof Fieldset)
		{
			$fieldset = (string) $fieldset;
			if ( ! ($fieldset = \Fieldset::instance($fieldset)))
			{
				$fieldset = \Fieldset::factory($fieldset, $config);
			}
		}
		return new Form($fieldset);
	}
Ejemplo n.º 6
0
 protected function __construct($fieldset, array $config = array())
 {
     if ($fieldset instanceof Fieldset) {
         $fieldset->form($this);
         $this->fieldset = $fieldset;
     } else {
         $this->fieldset = \Fieldset::factory($fieldset, array('form_instance' => $this));
     }
     foreach ($config as $key => $val) {
         $this->set_config($key, $val);
     }
 }