1) { $propertyName = array_shift($pathArr); $object = $object->$propertyName; } return [ $object, end($pathArr) ]; } public static function arrayGet(iterable $array, string $path, string $delimiter = '.') { $pathArr = explode($delimiter, $path); if (isset($array[$pathArr[0]])) { if ( isset($pathArr[1]) ) { $recurse = $array[array_shift($pathArr)]; if ( ! is_iterable($recurse) ) { if ( is_object($recurse) ) { list($object, $method) = static::objectFromPath($recurse, $pathArr); # @TODO An object caller would be a WAY better idea then this line of code # Calling $obj->varname return $object->$method ?? ""; } elseif (is_scalar($recurse)) { throw new \Exception("An error occured trying to fetch a value from a scalar value using path '$path'"); } } return static::arrayGet($recurse, implode($delimiter, $pathArr), $delimiter); } else { return $array[$pathArr[0]]; } } else { return null; } } public static function splitKeys(array &$array, string $delimiter = ".", string $enclosed = '{}') { if ( is_array($array) ) { $swap = []; foreach($array as $key => &$value) { $process = strstr($key, $delimiter); if ( $enclosed ) { if ( ( strlen($key) - 2 ) !== strlen( $tkey = trim($key, $enclosed) ) ) { $process = false; } else { $oldKey = $key; $key = $tkey; } } if ( $process ) { $tmp = []; $keylist = explode($delimiter, $key); $finalKey = array_shift($keylist); static::arrayKeysSet($keylist, $tmp, $value); $swap[$finalKey] = static::splitKeys($tmp, $delimiter, $enclosed); unset($array[isset($oldKey) ? $oldKey : $key]); } else if ( is_array($value) ) { $value = static::splitKeys($value, $delimiter, $enclosed); } } foreach($swap as $key => $item) { if ( $enclosed ) { if ( ( strlen($key) - 2 ) === ( $tkey = trim($key, $enclosed)) ) { $key = $tkey; } } $array[$key] = $item; } } return $array; } public static function files(string $path, string $fileExtension = "") : \Generator { if ( \file_exists($path) ) { $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD); foreach ($iterator as $file) { if ( $file->isFile() || $file->isDir() ) { if ($fileExtension && ( $file->getExtension() === $fileExtension )) { yield $file; } else { yield $file; } } } } } }