Esempio n. 1
0
 /**
  * Constructor.
  *
  * @param   string  $headerValue    Accept-Language value. If null, will be
  *                                  deduced from the current HTTP request.
  * @return  void
  */
 public function __construct($headerValue = null)
 {
     $value = $headerValue ?: HHttp\Runtime::getHeader('accept-language');
     // Remove CFWS.
     $this->_value = preg_replace('#\\([^\\)]+\\)|\\s#', '', $value);
     return;
 }
Esempio n. 2
0
 /**
  * Get last ID.
  *
  * @return  string
  */
 public function getLastId()
 {
     return Http\Runtime::getHeader('Last-Event-ID') ?: '';
 }
Esempio n. 3
0
 /**
  * Whether the form is valid or not.
  *
  * @param   bool  $revalid    Re-valid or not.
  * @return  bool
  */
 public function isValid($revalid = false)
 {
     if (false === $revalid && null !== $this->_validity) {
         return $this->_validity;
     }
     $novalidate = $this->abstract->readAttributeAsList('novalidate');
     // what about @formnovalidate on submitable element?
     if (true === in_array('all', $novalidate) || true === in_array('true', $novalidate)) {
         return $this->_validity = true;
     }
     $this->_validity = true;
     $data = Http\Runtime::getData();
     unset($data['__utf8']);
     $this->flat($data, $flat);
     if (false === is_array($data) || empty($data)) {
         return $this->_validity = false;
     }
     $elements = $this->getElements();
     $names = [];
     $validation = [];
     foreach ($elements as &$_element) {
         $_element = $this->getConcreteElement($_element);
         $name = $_element->readAttribute('name');
         if (!isset($names[$name])) {
             $names[$name] = [];
         }
         $names[$name][] = $_element;
     }
     foreach ($data as $index => $datum) {
         if (!is_array($datum)) {
             if (!isset($names[$index])) {
                 $validation[$index] = false;
                 continue;
             }
             if (1 < count($names[$index])) {
                 $validation[$index] = false;
                 foreach ($names[$index] as $element) {
                     $handle = $element->isValid($revalid, $datum);
                     if (true === $handle) {
                         $element->setValue($datum);
                     }
                     $validation[$index] = $validation[$index] || $handle;
                 }
                 unset($names[$index]);
                 unset($flat[$index]);
                 continue;
             }
             $element = $names[$index][0];
             $validation[$index] = $element->isValid($revalid, $datum);
             $element->setValue($datum);
             unset($names[$index]);
             unset($flat[$index]);
             continue;
         }
         $validation[$index] = false;
         /*
         print_r($flat);
         print_r($validation);
         
         $remainder = array();
         
         foreach($datum as $key => &$value) {
         
             $key = key($flat);
         
             if(!isset($names[$key])) {
         
                 $remainder[] = $key;
                 next($flat);
         
                 continue;
             }
         
             $validation[$key] = $names[$key][0]->isValid($revalid, $value);
             unset($flat[$key]);
             unset($names[$key]);
         }
         
         print_r($remainder);
         */
     }
     foreach ($names as $name => $element) {
         foreach ($element as $el) {
             if (($el instanceof Input || $el instanceof Textarea || $el instanceof Select) && true === $el->attributeExists('required')) {
                 $validation[$name] = false;
             }
         }
     }
     $handle =& $this->_validity;
     array_walk($validation, function ($verdict) use(&$handle) {
         $handle = $handle && $verdict;
     });
     self::postVerification($this->_validity, $this);
     if (true === $this->_validity) {
         $this->_formData = $data;
     }
     return $this->_validity;
 }