Example #1
0
 public function testBranch_pushMidKey()
 {
     $ary = array();
     $this->assertNull(\r8\ary\branch($ary, "new", array("one", null, "two")));
     $this->assertSame(array('one' => array(array('two' => 'new'))), $ary);
     $this->assertNull(\r8\ary\branch($ary, "val", array("one", null, "two")));
     $this->assertSame(array('one' => array(array('two' => 'new'), array('two' => 'val'))), $ary);
     $this->assertNull(\r8\ary\branch($ary, 3, array("one", null, "three")));
     $this->assertSame(array('one' => array(array('two' => 'new'), array('two' => 'val'), array('three' => 3))), $ary);
 }
Example #2
0
 /**
  * Parses a query string into an array
  *
  * @param String $query The query string to parser
  * @return Array Returns the parsed string as an array
  */
 public function parse($query)
 {
     $query = (string) $query;
     // Grab everything after the starting delimiter
     if (\r8\str\contains($this->startDelim, $query)) {
         $query = substr($query, strpos($query, $this->startDelim) + 1);
     }
     // Cut off everything after the ending delimiter
     if (\r8\str\contains($this->endDelim, $query)) {
         $query = substr($query, 0, strpos($query, $this->endDelim));
     }
     // Split the query into its pairs
     $query = explode($this->outerDelim, $query);
     $result = array();
     // Loop through each pair
     foreach ($query as $pair) {
         // Skip over empty pairs
         if (\r8\isEmpty($pair)) {
             continue;
         }
         // split the pair up into its key and value
         if (\r8\str\contains($this->innerDelim, $pair)) {
             list($key, $value) = explode($this->innerDelim, $pair, 2);
         } else {
             list($key, $value) = array($pair, "");
         }
         // if the key is empty, do nothing with it
         if (\r8\isEmpty($key, \r8\ALLOW_SPACES)) {
             continue;
         }
         // Apply the filters to the key and value
         $key = $this->keyFilter->filter($key);
         $value = $this->valueFilter->filter($value);
         // parse the list of keys into an array
         $key = $this->parseKey($key);
         // Add the branch to the result array
         \r8\ary\branch($result, $value, $key);
     }
     return $result;
 }