/**
  * Collects the filter value from request variables, session variables, or cookie variables, in that order.
  * Insures that the value is converted to a TRUE, FALSE or NULL value.
  * @param bool $read_cookies Flag indicating that the cookie collection should included in the search for a
  * filter value.
  */
 public function collectValue($read_cookies = true)
 {
     parent::collectValue($read_cookies);
     if ($this->value) {
         $this->value = Validation::parseBoolean($this->value);
     }
 }
Esempio n. 2
0
 public function testValidateDateString()
 {
     $d = Validation::validateDateString('2016-03-15');
     $this->assertEquals('2016-03-15', $d->format('Y-m-d'), "Y-m-d format");
     $d = Validation::validateDateString('3/15/2016');
     $this->assertEquals('2016-03-15', $d->format('Y-m-d'), "n/j/Y format");
     $d = Validation::validateDateString('03/15/2016');
     $this->assertEquals('2016-03-15', $d->format('Y-m-d'), "m/d/Y format");
     $d = Validation::validateDateString('3/2/2016');
     $this->assertEquals('2016-03-02', $d->format('Y-m-d'), "n/j/Y format");
     $d = Validation::validateDateString('02/08/1987');
     $this->assertEquals('1987-02-08', $d->format('Y-m-d'), "m/d/Y format");
     $d = Validation::validateDateString('2/8/87');
     $this->assertEquals('1987-02-08', $d->format('Y-m-d'), "n/j/y format");
     $d = Validation::validateDateString('02/08/87');
     $this->assertEquals('1987-02-08', $d->format('Y-m-d'), "m/d/y format");
     $d = Validation::validateDateString('February 08, 1987');
     $this->assertEquals('1987-02-08', $d->format('Y-m-d'), "F d, Y format");
     $d = Validation::validateDateString('February 8, 1987');
     $this->assertEquals('1987-02-08', $d->format('Y-m-d'), "F j, Y format");
     try {
         $d = Validation::validateDateString('February 08, 87');
     } catch (\Littled\Exception\ContentValidationException $ex) {
         $this->assertEquals("Unrecognized date value.", $ex->getMessage(), "F d, y format");
     }
 }
Esempio n. 3
0
 /**
  * collects filter value from request variables (GET or POST).
  */
 protected function collectRequestValue()
 {
     $value = Validation::collectRequestVar($this->key);
     if ($value) {
         $this->value = $value;
         return;
     }
 }
 public function collectValue($read_cookies = true)
 {
     parent::collectValue($read_cookies);
     if ($this->value) {
         try {
             $d = Validation::validateDateString($this->value);
             $this->value = $d->format("m/d/Y");
         } catch (ContentValidationException $ex) {
             $this->value = "[" . $ex->getMessage() . "]";
         }
     }
 }
 /**
  * Sets the id property value of the object's content from request variable values, e.g. GET, POST, etc.
  * First checks if a variable named "id" is present. 2nd, checks for a variable corresponding to the content
  * object's id's internal parameter name.
  * @return int|null Id value that was found, or null if no valid integer value was found for the content id.
  * @throws ConfigurationUndefinedException
  */
 public function collectContentId()
 {
     if (!defined('P_ID')) {
         throw new ConfigurationUndefinedException("P_ID not defined in app settings.");
     }
     $this->content->id->value = Validation::parseIntegerInput(P_ID);
     if ($this->content->id->value === null) {
         if ($this->content->id instanceof RequestInput) {
             $this->content->id->collectValue();
         } else {
             /* @todo remove this call after older version of IntegerInput class is fully removed from all apps */
             $this->content->id->fill_from_input();
         }
     }
     return $this->content->id->value;
 }
Esempio n. 6
0
 public function testParseNumeric()
 {
     $int_overflow = PHP_INT_MAX + 1;
     $this->assertEquals(Littled\Validation\Validation::parseNumeric("1"), 1, "\"1\" returns numeric value.");
     $this->assertEquals(Littled\Validation\Validation::parseNumeric("0"), 0, "\"0\" returns numeric value.");
     $this->assertEquals(Littled\Validation\Validation::parseNumeric("-1"), -1);
     $this->assertEquals(Littled\Validation\Validation::parseNumeric("5"), 5);
     $this->assertEquals(Littled\Validation\Validation::parseNumeric("" . PHP_INT_MAX), PHP_INT_MAX, "parseNumeric() with largest possible integer value");
     // $this->assertEquals(Littled\Validation\Validation::parseNumeric("".(PHP_INT_MAX+1)), $int_overflow, "parseNumeric() with value overflowing int max value");
     $this->assertEquals(Littled\Validation\Validation::parseNumeric("0.01"), 0.01);
     $this->assertEquals(Littled\Validation\Validation::parseNumeric("4.5"), 4.5);
     $this->assertNull(Littled\Validation\Validation::parseNumeric("zero"));
     $this->assertNull(Littled\Validation\Validation::parseNumeric("j01"));
     $this->assertNull(Littled\Validation\Validation::parseNumeric("01jx"));
     $this->assertNull(Littled\Validation\Validation::parseNumeric("true"));
     $this->assertNull(Littled\Validation\Validation::parseNumeric("false"));
     $this->assertNull(Littled\Validation\Validation::parseNumeric(true));
     $this->assertNull(Littled\Validation\Validation::parseNumeric(false));
 }
Esempio n. 7
0
 /**
  * Handles redirects to other pages. If page argument "ref" has a value,
  * that will be used as the url for the redirect, overriding the $sURI argument passed to the script.
  * @param string $target_uri URI to redirect to.
  * @param string $msg (Optional) message to pass along to the next page.
  * @throws ConfigurationUndefinedException
  */
 public static function doRedirect($target_uri = '', $msg = null)
 {
     if (!defined('P_MESSAGE')) {
         throw new ConfigurationUndefinedException("P_MESSAGE not defined in app settings.");
     }
     if (!defined('P_REFERER')) {
         throw new ConfigurationUndefinedException("P_REFERER not defined in app settings.");
     }
     $_SESSION[P_MESSAGE] = $msg;
     $uri = Validation::collectStringInput(P_REFERER, FILTER_SANITIZE_URL);
     if (!$uri) {
         $uri = $target_uri;
     }
     $iPos = strpos($uri, "/");
     if (is_numeric($iPos) && $iPos == 0) {
         /* NB INPUT_SERVER is unreliable with filter_input() */
         $uri = 'http://' . $_SERVER['HTTP_HOST'] . $uri;
     }
     if (function_exists('cleanup')) {
         cleanup();
     }
     header("Location: {$uri}\n\n");
     exit;
 }
 /**
  * Specialized routine for collectin the "display listings" setting. 
  * - Don't check cookies for this filter's value. 
  * - If the input value is set to "filter", set the object's property value
  * to TRUE.
  */
 protected function collectDisplayListingsSetting()
 {
     /* don't get "display listings" value from cookies */
     $this->displayListings->collectValue(false);
     if ($this->displayListings->value === null) {
         $str_value = Validation::collectRequestVar($this->displayListings->key);
         if (strtolower($str_value) == "filter") {
             $this->displayListings->value = true;
         }
     }
 }
Esempio n. 9
0
 /**
  * Tests date string to see if it is in a recognized format.
  * @param string $date Date string to test.
  * @param array|null $formats Data formats to test.
  * @returns \DateTime
  * @throws ContentValidationException
  */
 public static function validateDateString($date, $formats = null)
 {
     if ($formats == null) {
         $formats = array('Y-m-d', 'm/d/y', 'm/d/Y', 'n/j/y', 'n/j/Y', 'F d, Y', 'F j, Y', 'M d, Y', 'M j, Y');
     } elseif (!is_array($formats)) {
         $formats = array($formats);
     }
     foreach ($formats as $format) {
         $d = Validation::_testDateFormat($date, $format);
         if ($d instanceof \DateTime) {
             return $d;
         }
     }
     throw new ContentValidationException("Unrecognized date value.");
 }
Esempio n. 10
0
 /**
  * Collects page status value as defined in request variables (e.g. GET, POST, session)
  * @throws ConfigurationUndefinedException
  */
 public static function collectPageStatus()
 {
     if (!defined('P_MESSAGE')) {
         throw new ConfigurationUndefinedException("P_MESSAGE not defined in app settings.");
     }
     self::$status = Validation::collectStringInput(P_MESSAGE);
     if (isset($_SESSION[P_MESSAGE])) {
         unset($_SESSION[P_MESSAGE]);
     }
 }
 /**
  * collects filter value from request variables (GET or POST).
  */
 protected function collectRequestValue()
 {
     $this->value = Validation::collectIntegerArrayRequestVar($this->key);
 }
Esempio n. 12
0
 /**
  * Collects the value of this form input and stores it in the object.
  * @param int $filters Filters for parsing request variables, e.g. FILTER_UNSAFE_RAW, FILTER_SANITIZE_STRING, etc.
  */
 public function collectValue($filters = null)
 {
     $this->value = Validation::parseBooleanInput($this->key, $this->index);
 }