Example #1
0
 /**
  * Sets the source value to generate the seed from
  *
  * @param mixed $source The source value to generate the seed from. This will
  *      be converted to a string before it is used.
  * @return \r8\Encrypt\Seed Returns a self reference
  */
 public function setSource($source)
 {
     if (!\r8\isBasic($source)) {
         $source = serialize($source);
     }
     $this->source = (string) $source;
     return $this;
 }
Example #2
0
 /**
  * Formats an array as a key/value HTML pairing
  *
  * @param Array $data
  * @return String
  */
 private function formatArray(array $data)
 {
     $result = "";
     foreach ($data as $key => $value) {
         if (!\r8\isBasic($value)) {
             $value = \r8\getDump($value);
         }
         $result .= "    <tr>\n" . "        <th style='padding: 4px 8px; font-weight: normal; font-style: italic; text-align: right;'>" . $key . "</th>\n" . "        <td style='padding: 4px 8px;'>" . htmlspecialchars($value) . "</td>\n" . "    </tr>\n";
     }
     return $result;
 }
Example #3
0
 /**
  * Formats an array as a JSON object
  *
  * @param Array $data
  * @return String
  */
 private function formatArray(array $data)
 {
     $result = "";
     foreach ($data as $key => $value) {
         if (!\r8\isBasic($value)) {
             $value = \r8\getDump($value);
         }
         $result .= '"' . $key . '":' . json_encode($value) . ", ";
     }
     return rtrim($result, ", ");
 }
Example #4
0
 /**
  * Formats an error as a string
  *
  * @param \r8\iface\Error $error The error to format
  * @return String Returns the formatted error
  */
 public function format(\r8\iface\Error $error)
 {
     $formatter = new \r8\Backtrace\Formatter(new \r8\Backtrace\Formatter\Text());
     $result = "\n" . "PHP Error Encountered!\n";
     foreach ($this->toArray($error) as $key => $value) {
         $result .= $key . ": " . $value . "\n";
     }
     $details = $error->getDetails();
     if (!empty($details)) {
         $result .= "Details:\n";
         foreach ($details as $key => $value) {
             if (!\r8\isBasic($value)) {
                 $value = \r8\getDump($value);
             }
             $result .= "    " . $key . ": " . $value . "\n";
         }
     }
     $result .= "Backtrace:\n" . "    " . str_replace("\n", "\n    ", $formatter->format($error->getBacktrace())) . "\n\n";
     return $result;
 }
Example #5
0
 /**
  * Prepends a value to the end of an existing cached value.
  *
  * If the value doesn't exist, it will be set with the given value
  *
  * @param String $key The key for the value
  * @param mixed $value The value to prepend
  * @param Integer $expire The lifespan of this cache value, in seconds
  * @return \r8\Cache\Local Returns a self reference
  */
 public function prepend($key, $value, $expire = 0)
 {
     $key = \r8\indexVal($key);
     if (!isset($this->cache[$key]) || !\r8\isBasic($this->cache[$key]['val'])) {
         return $this->set($key, $value, $expire);
     }
     $this->cache[$key] = array("exp" => $expire == 0 ? 0 : time() + max(0, (int) $expire), "val" => $value . (string) $this->cache[$key]['val']);
     return $this;
 }
Example #6
0
 /**
  * Extracts the given key from a mixed value
  *
  * @param Mixed $haystack The mixed data collection to extract the key from
  * @return Mixed
  */
 private function extractKey($haystack)
 {
     if (is_array($haystack)) {
         $key = isset($haystack[$this->field]) ? $haystack[$this->field] : NULL;
     } else {
         if ($haystack instanceof \ArrayAccess) {
             $key = $haystack->offsetExists($this->field) ? $haystack->offsetGet($this->field) : NULL;
         } else {
             if (is_object($haystack)) {
                 $key = isset($haystack->{$this->field}) ? $haystack->{$this->field} : NULL;
             } else {
                 $key = NULL;
             }
         }
     }
     return \r8\isBasic($key) ? $key : NULL;
 }
Example #7
0
 /**
  * Validates a URL
  *
  * This will always fail for anything that isn't a basic value. That is, boolean,
  * null, integers, floats, or strings.
  *
  * @param mixed $value The value to validate
  * @return String|NULL Any errors encountered
  */
 protected function process($value)
 {
     if (!\r8\isBasic($value) || !array_key_exists($value, $this->field->getOptions())) {
         return "Value is not a valid selection";
     }
 }
Example #8
0
 /**
  * Recursively builds an XML tree
  *
  * @param \DOMDocument $doc The document being built
  * @param String $parent The tag name of the parent element
  * @param Mixed $data The data being pieced together
  * @param Boolean $root Whether the data being parsed is at the root level
  *      This is used during iteration, for example, to ensure lists are
  *      created properly
  * @return DOMNode Returns the built node
  */
 protected function build(\DOMDocument $doc, $parent, &$data, $root = FALSE)
 {
     if (\r8\isEmpty($data)) {
         return $this->createElement($doc, $parent);
     } else {
         if (\r8\isBasic($data) && $data !== NULL) {
             $node = $this->createElement($doc, $parent);
             $node->appendChild($doc->createTextNode((string) $data));
         } else {
             if (is_array($data) || $data instanceof \Traversable) {
                 $node = $this->iterate($doc, $parent, $data, $root);
             } else {
                 if ($data instanceof \r8\iface\XMLBuilder) {
                     $node = $this->createElement($doc, $parent);
                     $node->appendChild(\r8\XMLBuilder::buildNode($data, $doc));
                 } else {
                     if (is_object($data)) {
                         // If it is an object that supports "toString"
                         if (\r8\respondTo($data, "__toString")) {
                             $node = $this->createElement($doc, $parent);
                             $node->appendChild($doc->createTextNode($data->__toString()));
                         } else {
                             $props = get_object_vars($data);
                             $node = $this->iterate($doc, $parent, $props, $root);
                         }
                     }
                 }
             }
         }
     }
     return $node;
 }
Example #9
0
 public function testIsBasic()
 {
     $this->assertTrue(\r8\isBasic(FALSE));
     $this->assertTrue(\r8\isBasic(TRUE));
     $this->assertTrue(\r8\isBasic("some string"));
     $this->assertTrue(\r8\isBasic(500));
     $this->assertTrue(\r8\isBasic(2.78));
     $this->assertTrue(\r8\isBasic(NULL));
     $this->assertFalse(\r8\isBasic($this->getMock("object")));
     $this->assertFalse(\r8\isBasic(array()));
 }