Creates a semi-random path based on a string.

Makes it possible to overload this functionality.

@param string $string Input string
@param int $level Depth of the path to generate.
@return string
556297
protected function _randomPathSha1($string, $level) {
		$result = sha1($string);
		$randomString = '';
		$counter = 0;
		for ($i = 1; $i <= $level; $i++) {
			$counter = $counter + 2;
			$randomString .= substr($result, $counter, 2) . DS;
		}

		return $randomString;
	}
228328
public static function get_random_string($length = 10, $chars)
	{
	    $random_string = '';
	    
	    for($i = 0; $i < $length; $i++)
	    {
	        $index = rand(0, strlen($chars) - 1);
	        $random_string .= $chars{$index};
	    }
	    
	    return $random_string;
	}
68284
public static function getLevelNumeric(string $level)
    {
        return isset(self::$LEVEL_NUMERIC[$level]) ? self::$LEVEL_NUMERIC[$level] : 0;
    }
127481
public static function makeValidUrl($string)
    {
        $protocols = ['http://', 'https://', 'ftp://'];

        if ($string != '') {
            foreach ($protocols as $p) {
                if (substr($string, 0, strlen($p)) == $p) {
                    return $string;
                }
            }
        }

        if ($string != '' && $string != 'http://') {
            $string = 'http://' . $string;
        }

        return $string;
    }
402539
public static function fromString(string $string): self
    {
        if (1 !== \preg_match('/^( *|\t+)$/', $string)) {
            throw Exception\InvalidIndentStringException::fromString($string);
        }

        return new self($string);
    }
946410
public static function generateSlug($string)
    {
        $string = strtolower($string);
        $string = preg_replace('/([^a-z0-9]+)/', '-', $string);
        $string = str_replace('--', '-', $string);

        if (substr($string, 0, 1) == '-') {
            $string = substr($string, 1);
        }

        if (substr($string, -1) == '-') {
            $string = substr($string, 0, -1);
        }

        return $string;
    }
3327
protected function buildMessage($level, $text) {
            $trace = Alo::ifnull($this->getBacktrace()[1], [], true);

            $file = isset($trace['file']) ? implode(DIRECTORY_SEPARATOR,
                                                    array_slice(explode(DIRECTORY_SEPARATOR,
                                                                        $trace['file']),
                                                                -2)) : '<<unknown file>>';
            $line = isset($trace['line']) ? implode(DIRECTORY_SEPARATOR,
                                                    array_slice(explode(DIRECTORY_SEPARATOR,
                                                                        $trace['line']),
                                                                -2)) : '<<unknown line>>';

            return $level . ' ' . self::SEPARATOR . ' ' . $this->time() . ' ' . self::SEPARATOR . ' ' .
                   $this->config->logLabel . ' ' . self::SEPARATOR . ' ' .
                   str_replace(self::SEPARATOR, '\\' . self::SEPARATOR, $text) . ' ' . self::SEPARATOR . ' ' . $file .
                   ' ' . self::SEPARATOR . ' ' . $line . PHP_EOL;
        }
314770
protected static function getArrayString($a, $level = 2)
    {
        $s = "[\n";
        $i = 0;

        $assoc = Arr::isAssociative($a);

        foreach ($a as $k => $v) {
            $s .= $i ? ",\n" : '';
            $s .= str_repeat('    ', $level);

            if ($assoc) {
                $s .= "'" . $k . "' => ";
            }

            if (is_array($v) || is_object($v)) {
                $s .= static::getArrayString((array) $v, $level + 1);
            } else {
                $s .= "'" . addslashes($v) . "'";
            }

            $i++;
        }

        $s .= "\n" . str_repeat('    ', $level - 1) . ']';

        return $s;
    }
398021
public function relativePath(string $path, string $from): string
    {
        $path = $this->normalizePath($path);
        $from = $this->normalizePath($from);

        $from = explode('/', $from);
        $path = explode('/', $path);
        $relative = $path;

        foreach ($from as $depth => $dir) {
            //Find first non-matching dir
            if ($dir === $path[$depth]) {
                //Ignore this directory
                array_shift($relative);
            } else {
                //Get number of remaining dirs to $from
                $remaining = count($from) - $depth;
                if ($remaining > 1) {
                    //Add traversals up to first matching directory
                    $padLength = (count($relative) + $remaining - 1) * -1;
                    $relative = array_pad($relative, $padLength, '..');
                    break;
                } else {
                    $relative[0] = './' . $relative[0];
                }
            }
        }

        return implode('/', $relative);
    }
651914
public static function getRandomDir($path)
    {
        $DS = DIRECTORY_SEPARATOR;
        $max_scatter = 9; // Directory names max range 0..$max_scatter
        $levels = 3; // Nested level
        $dirs = [];
        for ($i = 1; $i <= $levels; $i++) {
            $dirs[] = (string)rand(0, $max_scatter);
        }
        $dir_path = implode($DS, $dirs);
        $full_path = rtrim($path, '/\\') . $DS . $dir_path;

        if (!is_dir($full_path)) {
            if (YII_DEBUG) {
                mkdir($full_path, 0777, true);
            } else {
                shell_exec('mkdir -m 0777 -p ' . $full_path);
            }
            if (!YII_DEBUG && isset($dirs[0])) {
                shell_exec('chmod -R 0777 ' . $path . $DS . $dirs[0] . $DS . '*');
            }
        }

        $dir_path = str_replace('\\', '/', $dir_path);

        return ltrim($dir_path, '/');
    }
305798
public static function getLevelByName($level)
    {
        $level = strtoupper($level);
        if (!isset(static::$levelNameToLevel[$level])) {
            return static::ALL;
        }

        return static::$levelNameToLevel[$level];
    }
304568
public function parent(string $path, int $levels = 1): string
    {
        [$scheme, $path] = $this->getSchemeAndHierarchy($path);

        if ($this->normalize !== false) {
            $path = $this->normalizePathPart($path);
        }

        if ($path === '' || $path === '.') {
            return '';
        }

        [$scheme, $parent] = $this->dirnameInternal($scheme, $path, $levels);

        return $parent !== $path ? $this->toString($scheme, $parent) : '';
    }
34035
public static function fromString($string)
    {
        list($lat, $long) = explode(',', $string);
        return new self($lat, $long);
    }
49654
protected function generateRelativePath($from, $to)
    {
        // some compatibility fixes for Windows paths
        $from = is_dir($from) ? rtrim($from, '\/').'/' : $from;
        $to = is_dir($to)   ? rtrim($to, '\/').'/'   : $to;
        $from = str_replace('\\', '/', $from);
        $to = str_replace('\\', '/', $to);

        $from = explode('/', $from);
        $to = explode('/', $to);
        $from2 = array();
        foreach ($from as $key => $value) {
            if ($value === '..') {
                unset($from2[$key - 1]);
            } else {
                $from2[] = $value;
            }
        }
        $from = $from2;
        $relPath = $to;

        foreach ($from as $depth => $dir) {
            // find first non-matching dir
            if ($dir === $to[$depth]) {
                // ignore this directory
                array_shift($relPath);
            } else {
                // get number of remaining dirs to $from
                $remaining = count($from) - $depth;

                if ($remaining > 1) {
                    // add traversals up to first matching dir
                    $padLength = (count($relPath) + $remaining) * -1;

                    $relPath = array_pad($relPath, $padLength, '..');
                    break;
                } else {
                    $relPath[0] = './'.$relPath[0];
                }
            }
        }

        return implode('/', $relPath);
    }
274566
protected function getNextFragment($string, $length = null, &$pos = null) {
			$state = self::STATE_DATA;
			$buffer = '';

			$length = $length ?: strlen($string);
			$pos = $pos ?: 0;
			$depth = 0;

			while ($pos < $length) {
				$char = $string[$pos++];

				if ($char === self::TOKEN_FIELD_SEPARATOR && $depth === 0 && $state === self::STATE_DATA)
					return $buffer;
				else if ($char === self::TOKEN_SUBFIELD_OPEN) {
					$state = self::STATE_SUBFIELD;

					++$depth;
				} else if ($char === self::TOKEN_SUBFIELD_CLOSE) {
					$state = self::STATE_DATA;

					--$depth;
				}

				$buffer .= $char;
			}

			if ($state !== self::STATE_DATA)
				throw new \Exception('Unexpected end of string');

			return $buffer;
		}
775026
private function text($text, $level)
    {
        $indentNextLine = (substr($text, -1) === "\n");
        $code = sprintf($this->prepare(self::TEXT, $level), $this->flushIndent(), var_export($text, true));
        $this->indentNextLine = $indentNextLine;

        return $code;
    }
519732
public static function randomString($length)
    {
        $key = '';
        $keys = array_merge(range('a', 'z'));

        for ($i = 0; $i < $length; ++$i) {
            $key .= $keys[array_rand($keys)];
        }

        return $key;
    }