Example #1
4
 private function recursiveScan(\RecursiveArrayIterator $iterator)
 {
     while ($iterator->valid()) {
         $this->checkIblockData($iterator);
         if ($iterator->hasChildren()) {
             $this->recursiveScan($iterator->getChildren());
         } else {
             $this->checkIblockData($iterator);
         }
         $iterator->next();
     }
 }
Example #2
0
 /**
  * Searches value inside a multidimensional array, returning its index
  *
  * Original function by "giulio provasi" (link below)
  *
  * @param mixed|array $haystack
  *   The haystack to search
  *
  * @param mixed $needle
  *   The needle we are looking for
  *
  * @param mixed|optional $index
  *   Allow to define a specific index where the data will be searched
  *
  * @return integer|string
  *   If given needle can be found in given haystack, its index will
  *   be returned. Otherwise, -1 will
  *
  * @see http://www.php.net/manual/en/function.array-search.php#97645
  */
 public static function search($haystack, $needle, $index = NULL)
 {
     if (is_null($haystack)) {
         return -1;
     }
     $arrayIterator = new \RecursiveArrayIterator($haystack);
     $iterator = new \RecursiveIteratorIterator($arrayIterator);
     while ($iterator->valid()) {
         if ((isset($index) and $iterator->key() == $index or !isset($index)) and $iterator->current() == $needle) {
             return $arrayIterator->key();
         }
         $iterator->next();
     }
     return -1;
 }
Example #3
0
 /**
  * Find a named route in a given array of routes.
  *
  * @param  string  $name
  * @param  array   $routes
  * @return array
  */
 public static function find($name, $routes)
 {
     if (array_key_exists($name, static::$names)) {
         return static::$names[$name];
     }
     $arrayIterator = new \RecursiveArrayIterator($routes);
     $recursiveIterator = new \RecursiveIteratorIterator($arrayIterator);
     // Since routes can be nested deep within sub-directories, we need to recursively
     // iterate through each directory and gather all of the routes.
     foreach ($recursiveIterator as $iterator) {
         $route = $recursiveIterator->getSubIterator();
         if (isset($route['name']) and $route['name'] == $name) {
             return static::$names[$name] = array($arrayIterator->key() => iterator_to_array($route));
         }
     }
 }
 /**
  * @param array $array
  */
 public function __construct($array)
 {
     if (is_object($array)) {
         $array = $array->toArray();
     }
     parent::__construct($array);
 }
 public function __construct(\ResourceBundle $bundle)
 {
     $storage = array();
     foreach ($bundle as $key => $value) {
         $storage[$key] = $value instanceof \ResourceBundle ? new self($value) : $value;
     }
     parent::__construct($storage);
 }
Example #6
0
 function valid()
 {
     if (!parent::valid()) {
         echo __METHOD__ . " = false\n";
         return false;
     } else {
         return true;
     }
 }
function traverse(RecursiveArrayIterator $iterator)
{
    while ($iterator->valid()) {
        if ($iterator->hasChildren()) {
            printf("HasChild: %s\n", $iterator->key());
            traverse($iterator->getChildren());
        } else {
            printf("%s => %s\n", $iterator->key(), $iterator->current());
        }
        $iterator->next();
    }
}
Example #8
0
 /**
  * Walks through array
  * @param $array
  * @param $callback callable function($path, $value)
  */
 public static function walkArray($array, $callback, $iterator = null, $prefix = '')
 {
     if (is_null($iterator)) {
         $iterator = new \RecursiveArrayIterator($array);
     }
     while ($iterator->valid()) {
         if ($iterator->hasChildren()) {
             self::walkArray(null, $callback, $iterator->getChildren(), $prefix . '.' . $iterator->key());
         } else {
             call_user_func($callback, ltrim($prefix . '.' . $iterator->key(), '.'), $iterator->current());
         }
         $iterator->next();
     }
 }
Example #9
0
 /** @return key() since that is the name we need
  */
 function current()
 {
     $result = parent::key();
     $parent = get_parent_class($result);
     if ($parent) {
         $interfaces = array_diff(class_implements($result), class_implements($parent));
         if ($interfaces) {
             $implements = array();
             foreach ($interfaces as $interface) {
                 $implements = array_merge($implements, class_implements($interface));
             }
             $interfaces = array_diff($interfaces, $implements);
             natcasesort($interfaces);
             $result .= ' (' . join(', ', $interfaces) . ')';
         }
     }
     return $result;
 }
Example #10
0
 /**
  * @param \RecursiveArrayIterator $iterator
  * @return mixed
  * @throws \Symfony\Component\HttpKernel\Exception\HttpException
  */
 protected function buildResources(\RecursiveArrayIterator $iterator)
 {
     if (count($this->mapping) == 0) {
         throw new HttpException(Codes::HTTP_BAD_REQUEST, 'Unable to generate CMMI Data, no mapping is known');
     }
     $this->resource = new Resource(new Link($this->request->getUri(), 'self'));
     if ($iterator->hasChildren()) {
         while ($iterator->valid()) {
             $childItem = $iterator->current();
             $this->addResource(new \RecursiveArrayIterator($childItem));
             $iterator->next();
         }
     } else {
         $this->addResource($iterator);
     }
     return $this->resource;
 }
Example #11
0
 /**
  * Find a value also in nested arrays/objects
  *
  * @param mixed $needle The value to search for
  *
  * @return string The key of that value
  *
  * @since 1.0.0
  */
 public function searchRecursive($needle)
 {
     $aIt = new RecursiveArrayIterator($this);
     $it = new RecursiveIteratorIterator($aIt);
     while ($it->valid()) {
         if ($it->current() == $needle) {
             return $aIt->key();
         }
         $it->next();
     }
     return false;
 }
 /**
  * @param Item[] $items
  */
 public function __construct(array $items)
 {
     parent::__construct($items);
 }
Example #13
0
    <div>
        <label for="y">Input int. for y axis</label>
        <input type="text" name="y">
    </div>
    <div>
        <label for="directions">Input string for directions</label>
        <input type="text" name="directions">
    </div>
    <input type="submit" name="submit" value="Go!">
</form>


<?php 
$move_data = str_split($directions);
//var_dump($move_data);
$recusive = new RecursiveArrayIterator($move_data);
$reverse = 0;
while ($recusive->valid()) {
    $direction = $recusive->current();
    if ($direction == '~') {
        $reverse++;
        $recusive->next();
    } else {
        if ($reverse % 2) {
            if ($direction == '>') {
                $_x++;
            } elseif ($direction == '<') {
                $_x--;
            } elseif ($direction == 'v') {
                $_y++;
            } elseif ($direction == '^') {
Example #14
0
 function getChildren()
 {
     return new SimpleXpathStructure(parent::current());
 }
 /**
  * @param RecursiveArrayIterator $iterator
  */
 public function fetchCategoriesWithProducts(RecursiveArrayIterator $iterator)
 {
     while ($iterator->valid()) {
         if ($iterator->hasChildren()) {
             $this->fetchCategoriesWithProducts($iterator->getChildren());
         } else {
             if ($iterator->key() == 'countProducts' && $iterator->current() != '0') {
                 $this->_categoryWithProducts[$iterator->offsetGet('id')] = array('name' => $iterator->offsetGet('name'), 'full_path' => $iterator->offsetGet('full_path'), 'countProduct' => $iterator->offsetGet('countProducts'));
             }
             /*$this->_categoryWithProducts[$iterator->offsetGet('id')] =
               $iterator->offsetGet('countProducts');*/
         }
         $iterator->next();
     }
 }
 /**
  * Find and return the bottom node in the given tree
  * @param \RecursiveArrayIterator $iterator
  * @param array $tree
  * @return mixed Array with 0: iterator, 1: value (reference)
  */
 protected function findNode(\RecursiveArrayIterator $iterator, $tree = [])
 {
     $find_key = array_shift($tree);
     foreach ($iterator as $key => &$value) {
         if ($key !== $find_key) {
             continue;
         }
         # $tree isn't null yet, meaning we still have to travel down
         # nodes in order to get to the last one... inception
         if (isset($tree[0])) {
             return $this->findNode($iterator->getChildren(), $tree);
         }
         # Return a reference to this current node - it's needed later. More details
         # are in the findValue() function. Yeah, it's kinda hackey
         return [$iterator, &$value];
     }
     return null;
 }
Example #17
0
 public function hasChildren()
 {
     echo 'MyArrIter::hasChildren = ', var_export(parent::hasChildren()), "\n";
     return parent::hasChildren();
 }
Example #18
0
 function getChildren()
 {
     echo __METHOD__ . "()\n";
     self::fail(2, __METHOD__);
     return parent::getChildren();
 }
Example #19
0
 function __construct($data)
 {
     parent::__construct($data, \RecursiveIteratorIterator::SELF_FIRST);
 }
Example #20
0
 public function __construct(HTML_QuickForm2_Container $container)
 {
     parent::__construct($container->getElements());
 }
Example #21
0
?>
" method="POST">
		
<input type="text" name="any_name">
<input type="submit" name="submit">
</form>	
		
		
		
		
		
	<?php 
if (isset($_POST['submit'])) {
    $var = $_POST['any_name'];
    $var = strtoupper($var);
    $str = file_get_contents('file.json');
    $json = json_decode($str, true);
    $iterator = new RecursiveArrayIterator($json);
    while ($iterator->valid()) {
        foreach ($iterator as $key => $value) {
            if (0 === strpos($key, $var)) {
                echo $key . ' : ' . $value . "<br/>";
            }
        }
        $iterator->next();
    }
}
?>
        </form>
    </body>
</html>
Example #22
0
 /**
  * performs a search in a nested array
  * @param array $haystack the array to be searched
  * @param string $needle the search string
  * @param string $index optional, only search this key name
  * @return mixed the key of the matching field, otherwise false
  *
  * performs a search in a nested array
  *
  * taken from http://www.php.net/manual/en/function.array-search.php#97645
  */
 public static function recursiveArraySearch($haystack, $needle, $index = null)
 {
     $aIt = new RecursiveArrayIterator($haystack);
     $it = new RecursiveIteratorIterator($aIt);
     while ($it->valid()) {
         if ((isset($index) and $it->key() == $index or !isset($index)) and $it->current() == $needle) {
             return $aIt->key();
         }
         $it->next();
     }
     return false;
 }
 public function getChildren()
 {
     $section = parent::current();
     return new self($section['topics'], 0, $this->path . '/' . $this->key());
 }
Example #24
0
 private function parseJson(\RecursiveArrayIterator $json, array $data, $level)
 {
     foreach ($json as $k => $j) {
         if (!isset($this->path[$level])) {
             return $data;
         }
         if ($k !== $this->path[$level] && $this->path[$level] !== '*') {
             continue;
         }
         if ($k === end($this->path)) {
             if (is_array($j)) {
                 $data = array_merge($data, $j);
             } else {
                 $data[] = $j;
             }
         }
         if ($json->hasChildren()) {
             $data = $this->parseJson($json->getChildren(), $data, $level + 1);
         }
     }
     return $data;
 }
Example #25
0
 /**
  * Parse the upload data out of $_FILES.
  *
  * @access protected
  * @return void
  */
 protected function _parseData()
 {
     $data = array();
     // Form uploading
     if ($_FILES) {
         // via CakePHP
         if (isset($_FILES['data'])) {
             foreach ($_FILES['data'] as $key => $file) {
                 $count = count($file);
                 // Add model index if it doesn't exist
                 $iterator = new RecursiveArrayIterator($file);
                 if ($iterator->hasChildren() === false) {
                     $file = array('Fake' => $file);
                 }
                 foreach ($file as $model => $fields) {
                     foreach ($fields as $field => $value) {
                         if ($count > 1) {
                             $data[$model . '.' . $field][$key] = $value;
                         } else {
                             $data[$field][$key] = $value;
                         }
                     }
                 }
             }
             // via normal form or AJAX iframe
         } else {
             $data = $_FILES;
         }
         // AJAX uploading
     } else {
         if (isset($_GET[$this->ajaxField])) {
             $name = $_GET[$this->ajaxField];
             $mime = self::mimeType($name);
             if ($mime) {
                 $input = fopen("php://input", "r");
                 $temp = tmpfile();
                 $data[$this->ajaxField] = array('name' => $name, 'type' => $mime, 'stream' => true, 'tmp_name' => $temp, 'error' => 0, 'size' => stream_copy_to_stream($input, $temp));
                 fclose($input);
             }
         }
     }
     $this->_data = $data;
 }
 function array_get($array, $searched, $index)
 {
     $aIt = new RecursiveArrayIterator($array);
     $it = new RecursiveIteratorIterator($aIt);
     while ($it->valid()) {
         if ((isset($index) and $it->key() == $index or !isset($index)) and $it->current() == $searched) {
             $c = $aIt->current();
             return $c;
             //				return $c[$key];
         }
         $it->next();
     }
     return FALSE;
 }
Example #27
0
 function getChildren()
 {
     echo __METHOD__ . "\n";
     return parent::getChildren();
 }
Example #28
0
 function current()
 {
     $x = parent::current();
     return new FileTag($x, $this->dir, $this->_packagefile);
 }
 protected static function encode_iterator(RecursiveArrayIterator $iterator, $options, $depth)
 {
     $json = array();
     while ($iterator->valid()) {
         $key = $iterator->key();
         $value = $iterator->current();
         if ($value instanceof JSExpression) {
             var_dump($value);
             $json[$key] = $value->json_encode($options);
         } else {
             if ($iterator->hasChildren()) {
                 if (!($depth > 0)) {
                     throw new Exception("Maximum depth reached");
                 }
                 $json[$key] = static::encode_iterator($iterator->getChildren(), $options, $depth - 1);
             } else {
                 $json[$key] = static::encode_value($iterator->current(), $options);
             }
         }
         $iterator->next();
     }
     var_dump($json);
     if (self::is_numeric_array($json)) {
         return '[' . implode(",", $json) . ']';
     } else {
         foreach (array_keys($json) as $key) {
             $json[$key] = static::encode_key($key, $options) . ':' . $json[$key];
         }
         return '{' . implode(",", $json) . '}';
     }
 }
/**
 * 
 * Search for needle in a recursive array
 * @author http://www.php.net/manual/en/function.array-search.php#97645
 * 
 * @param $haystack
 * @param $needle
 * @param $index
 */
function rarray_search($needle, $haystack, $index = null)
{
	$aIt	= new RecursiveArrayIterator($haystack);
	$it		= new RecursiveIteratorIterator($aIt);
	
	// Tar bort ".www" om det finns för bättre jämföring
	$needle = preg_replace('/\bwww./', '', $needle);
   
	while($it->valid())
    {
    	// Tar bort ".www" om det finns för bättre jämföring
    	$current = preg_replace('/\bwww./', '', $it->current());

		if (((isset($index) AND ($it->key() == $index)) OR (!isset($index))) AND ($current == $needle))
		{
			return $aIt->key();
		}
		$it->next();
	}

	return FALSE;
}