コード例 #1
0
ファイル: Form.php プロジェクト: zingular/forms
 /**
  * @param FormState $state
  * @param array $defaultValues
  */
 public function compile(FormState $state, array $defaultValues = array())
 {
     // TODO: make protected, and remove from all other components
     // TODO: loopt through all children and use fixed set of compilers to compile each child (recursively)
     // TODO: components are only models for data, no logic
     // prevent multiple compiles
     if ($this->compiled === false) {
         $this->compiled = true;
         // TODO: do CSRF check
         parent::compile($state, $defaultValues);
         // if form was submitted
         if ($this->hasSubmit()) {
             $this->dispatchEvent(new FormEvent(FormEvent::SUBMIT, $this));
         }
         // if form was successful
         if ($this->valid()) {
             // dispatch valid event
             $this->dispatchEvent(new FormEvent(FormEvent::VALID, $this));
         } else {
             // dispatch invalid event
             $this->dispatchEvent(new FormEvent(FormEvent::INVALID, $this));
         }
         // form was submitted and validated successfuly
         if ($this->success()) {
             // handle the orm model, if any
             if (!is_null($this->model)) {
                 $this->getOrmHandler()->setValues($this->getValues(), $this->model);
             }
             // dispatch success event
             $this->dispatchEvent(new FormEvent(FormEvent::SUCCESS, $this));
             // handle handlers
             // TODO: implement form handlers
         }
     }
 }
コード例 #2
0
ファイル: Aggregator.php プロジェクト: zingular/forms
 /**
  * @param FormState $state
  * @param array $defaultValues
  * @return string
  */
 public function compile(FormState $state, array $defaultValues = array())
 {
     // store the form context locally
     $this->state = $state;
     // default value
     $defaultValue = null;
     // extract the default value for this aggregator from the default values
     if (array_key_exists($this->getName(), $defaultValues)) {
         // set the default value from the set value
         $defaultValue = $defaultValues[$this->getName()];
         // overwrite the default values by de-aggregating the default value
         $defaultValues = $this->deaggregate($this->decodeValue($defaultValue));
         //$this->getAggregationStrategy()->deaggegate($this->decodeValue($defaultValue),$this);
         // TODO: apply native deaggregation here
         if (!is_array($defaultValues)) {
             $defaultValues = array();
         }
     } else {
         $defaultValues = array();
     }
     // compile the parent using the de-aggregated value as default values for child components
     parent::compile($state, $defaultValues);
     // make sure the value is collected, with the collected default value
     $this->retrieveValue($defaultValue);
 }