Exemplo n.º 1
0
 /**
  * Constructor
  *
  * @param string $iniFile
  * @throws IniException if unable to parse ini file
  * 
  */
 public function __construct($iniFile = null)
 {
     if (null === $iniFile && defined('CONFIG_FILE_PATH')) {
         $iniFile = CONFIG_FILE_PATH;
     }
     $this->iniFile = !empty($iniFile) ? $iniFile : LAMPCMS_PATH . DIRECTORY_SEPARATOR . '!config.ini';
     $aIni = \parse_ini_file($this->iniFile, true);
     if (empty($aIni)) {
         throw new IniException('Unable to parse ini file: ' . $this->iniFile . ' probably a syntax error in file');
     }
     parent::__construct($aIni);
 }
Exemplo n.º 2
0
 /**
  * Get filtered value of query string
  * param. Use $this->aFiltered as storage
  * for cached resolved values. This way multiple
  * requests for the same $name will only go
  * through filter once and then resolved filtered value
  * will be reused
  *
  * @param string $name name of query string param
  *
  * @return mixed string|bool|int depending on param type
  *
  */
 protected function getFiltered($name)
 {
     d('getting filtered for ' . $name);
     if (!\array_key_exists($name, $this->aFiltered)) {
         d('cp not yet in $this->aFiltered');
         $val = parent::offsetGet($name);
         if ('a' === $name && !empty($val)) {
             $expression = '/^[[:alpha:]\\-]{1,20}$/';
             if (!\filter_var($val, FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => $expression)))) {
                 throw new \InvalidArgumentException('Invalid value of "a" it can only contain letters and a hyphen and be limited to 20 characters in total was: ' . \htmlentities($val));
             }
             $ret = $val;
         } elseif ('i_' === \substr(\strtolower($name), 0, 2) || 'id' === \substr(\strtolower($name), -2, 2)) {
             /**
              * FILTER_VALIDATE_INT
              * does not seem to accept 0 as a valid int!
              * this sucks, so instead going to use is_numeric
              */
             if ('' !== $val && !\is_numeric($val) || $val < 0 || $val > 99999999999.0) {
                 throw new \InvalidArgumentException('Invalid value of "' . $name . '". It can only be a number between 0 and 99999999999 was: ' . \htmlentities($val));
             }
             $ret = (int) $val;
         } elseif ('_hex' === substr(\strtolower($name), -4, 4)) {
             $expression = '/^[0-9A-F]{6}$/';
             if (!filter_var($val, FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => $expression)))) {
                 throw new \InvalidArgumentException('Invalid value of ' . $name . ' it can only be a hex number. Was: ' . \htmlentities($val));
             }
             $ret = $val;
         } elseif ('flag' === \substr(\strtolower($name), -4, 4)) {
             /**
              * FILTER_VALIDATE_BOOLEAN will not work here
              * because it does not accept 0 as valid option,
              * only 1, true, on, yes
              * it just does not accept any values for 'false'
              */
             if ($val != 1) {
                 throw new \InvalidArgumentException('Invalid value of ' . $name . ' It can only be an integer and not greater than 1, it was: ' . gettype($val) . ' val: ' . \htmlentities($val));
             }
             $ret = (bool) $val;
         } elseif ('token' === $name) {
             $ret = filter_var($val, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH);
         } else {
             /**
              * Do NOT use FILTER_STRIP_LOW, it may look like a good idea but
              * it removes all line breaks in text!
              */
             $ret = $val;
             //filter_var($val, FILTER_SANITIZE_STRING); //, FILTER_FLAG_STRIP_LOW
         }
         $this->aFiltered[$name] = $ret;
     }
     return $this->aFiltered[$name];
 }
Exemplo n.º 3
0
 /**
  * Redefine offsetGet to return defaultValue
  * if index $name does not actually exists.
  * This way the $obj['blabla'] will return
  * the value of $this->defaultValue
  * instead of raising error
  *
  * @param string $name
  * @return unknown
  */
 public function offsetGet($name)
 {
     if (parent::offsetExists($name)) {
         return parent::offsetGet($name);
     }
     return $this->defaultValue;
 }