Пример #1
0
 /**
  * Performs the validation and returns the result
  *
  * @param Mixed $value The value to validate
  * @return \r8\Validator\Result
  */
 public function validate($value)
 {
     // Invoke the internal validator
     $result = $this->process($value);
     if ($result instanceof \Traversable) {
         $result = \iterator_to_array($result);
     }
     // Normalize the results if it is an array
     if (\is_array($result)) {
         $result = \r8\ary\flatten($result);
         $result = \r8\ary\stringize($result);
         $result = \r8\ary\compact($result);
     } elseif ($result instanceof \r8\Validator\Result) {
         $result = $result->getErrors();
     } elseif (is_null($result) || is_bool($result) || $result === 0 || $result === 0.0) {
         $result = null;
     } else {
         $result = (string) $result;
     }
     // Boot up the results of the validation process
     $output = new \r8\Validator\Result($value);
     // If the internal validator returned a non-empty value
     // (either an array with values or a non-blank string)
     if (!\r8\isEmpty($result)) {
         // If this validator is hooked up with a set of custom error messages,
         // use them instead of what the result returned
         if ($this->hasErrors()) {
             $output->addErrors($this->getErrors());
         } else {
             $output->addErrors($result);
         }
     }
     return $output;
 }
Пример #2
0
 public function testStringize()
 {
     $this->assertSame(array(), \r8\ary\stringize(array()));
     $obj = $this->getMock('stdClass', array("__toString"));
     $obj->expects($this->once())->method("__toString")->will($this->returnValue("obj"));
     $this->assertSame(array("one", "1", "1.2", "Array", "1", "", "", "obj"), \r8\ary\stringize(array("one", 1, 1.2, array(), TRUE, FALSE, NULL, $obj)));
 }
Пример #3
0
 /**
  * Constructor...
  *
  * @param Array $codes The list of strings the code can start with
  */
 public function __construct(array $codes)
 {
     $this->codes = \r8\ary\stringize($codes);
 }
Пример #4
0
 /**
  * Registers a set of quotes
  *
  * If the opening quote has already been registered, the closing quotes will
  * be replaced with the new set
  *
  * @param String $open The opening quote
  * @param Null|String|Array $close If left empty, this will assume the closing quote
  *      is the same as the opening quote. If an array is given, it will be
  *      flattened and compacted.
  * @return object Returns a self reference
  */
 public function setQuote($open, $close = FALSE)
 {
     $open = (string) $open;
     if (\r8\isEmpty($open, ALLOW_SPACES)) {
         throw new \r8\Exception\Argument(0, "Open Quote", "Must not be empty");
     }
     if (\r8\isVague($close, ALLOW_SPACES)) {
         $close = array($open);
     } else {
         $close = (array) $close;
         $close = \r8\ary\flatten($close);
         $close = \r8\ary\stringize($close);
         $close = \r8\ary\compact($close, \r8\ALLOW_SPACES);
         $close = \array_unique($close);
     }
     $this->quotes[$open] = $close;
     return $this;
 }
Пример #5
0
 /**
  * Returns an HTML representation of this Head object
  *
  * Note that this does NOT include the DocType. Only the values within
  * the actual Head tag.
  *
  * @return \r8\HTML\Tag
  */
 public function getTag()
 {
     $content = array();
     if (!empty($this->title)) {
         $content[] = "<title>" . htmlspecialchars($this->title) . "</title>";
     }
     $content = array_merge($content, \r8\ary\stringize(\r8\ary\invoke($this->metatags, "getTag")), \r8\ary\stringize(\r8\ary\invoke($this->css, "getTag")), \r8\ary\stringize(\r8\ary\invoke($this->javascript, "getTag")));
     return new \r8\HTML\Tag("head", implode("\n", $content));
 }
Пример #6
0
/**
 * Removes repetitions from a string
 *
 * @param String $string The string to strip of repeats
 * @param String|Array $repeated The repeated string to remove. If it is an array, it will remove multiple duplicates at once
 * @param Boolean $ignoreCase Whether the replace should be case sensitive
 * @return String Returns the string with the repeated values removed
 */
function stripRepeats($string, $repeated, $ignoreCase = TRUE)
{
    if (is_array($repeated)) {
        $repeated = \r8\ary\flatten($repeated);
        $repeated = \r8\ary\stringize($repeated);
        foreach ($repeated as $key => $value) {
            $repeated[$key] = preg_quote($value, "/");
        }
        $repeated = implode("|", $repeated);
    } else {
        $repeated = preg_quote((string) $repeated, '/');
    }
    if (\r8\isEmpty($repeated, \r8\ALLOW_SPACES)) {
        throw new \r8\Exception\Argument(1, 'Repeated', 'Must not be empty');
    }
    return preg_replace('/(' . $repeated . ')\\1+/' . ($ignoreCase ? 'i' : ''), '\\1', $string);
}