Substitute all paths in given array recursively with alias if applicable.
@param array $data
@param string $dir
@param string $alias
@return array
768467
public static function substitutePaths($data, $dir, $alias): array
    {
        foreach ($data as &$value) {
            if (is_string($value)) {
                $value = static::substitutePath($value, $dir, $alias);
            } elseif (is_array($value)) {
                $value = static::substitutePaths($value, $dir, $alias);
            }
        }

        return $data;
    }
198323
protected function evaluatePath($path, $data)
	{
		foreach ($data as $var => $val)
			$this->smarty->assign($var, $val);

		return $this->smarty->fetch($path);
	}
1343928
public function propertiesToArray(array $data, array $aliases = []): array
    {
        return ['articles' => array_map(function ($item) {
            if ($item instanceof NewsItem) {
                return $item->toJsonArray();
            }
        }, $this->get('items'))];
    }
924807
protected function findProvider($source, $alias)
    {
        if (!$alias) {
            $src = realpath($source);
            if (PATH_SEPARATOR == ';') {
                // on windows platform, remove the drive identifier
                $src = substr($src, 2);
            }

            if (is_dir($src)) {
                $provider = array('in' => $src);
            } elseif (is_file($src)) {
                $ext = pathinfo($src, PATHINFO_EXTENSION);

                if (in_array($ext, array('phar', 'zip', 'gz', 'tar', 'tgz', 'rar'))) {
                    // archive file
                    $provider = array('in' => 'phar://' . $src);
                } else {
                    $provider = array('in' => dirname($src), 'name' => basename($src));
                    $this->dataSourceId = $src;
                }
            }
        }

        if (!isset($provider)) {
            // when $source identify an entry of a json config file
            $filename = Environment::getJsonConfigFilename();

            if ($filename === false) {
                return false;
            }

            // try to validate syntax and content of this json config file
            $config = new Config();
            $var    = $config->validate($filename);

            foreach ($var['source-providers'] as $provider) {
                $in = trim($provider['in']);
                if (empty($in)) {
                    // this source provider is incomplete: empty "in" key
                    return false;
                }
                $src = explode(' as ', $in);
                $src = array_map('trim', $src);

                if (!empty($alias) && count($src) < 2) {
                    // searching on alias, which is not provided
                    continue;
                }
                $i = empty($alias) ? 0 : 1;
                // search on data source path ($i = 0) or alias ($i = 1)
                if ($src[$i] == $source) {
                    $provider['in'] = $src[0];
                    break;
                }
                unset($provider);
            }

            if (!isset($provider)) {
                // data source not found
                return false;
            }
        }

        if (substr($provider['in'], 0, 1) == '.') {
            // relative local file
            $provider['in'] = realpath($provider['in']);
        }
        if (PATH_SEPARATOR == ';') {
            // normalizes path to unix format
            $provider['in'] = str_replace(DIRECTORY_SEPARATOR, '/', $provider['in']);
        }
        if (!isset($provider['name'])) {
            // default file extensions to scan
            $provider['name'] = '/\\.(php|inc|phtml)$/';
        }
        if (!isset($this->dataSourceId)) {
            $this->dataSourceId = $provider['in'];
        }

        $finder = new Finder();
        $finder->files();

        $constraints = array(
            'in',                       // Location
            'exclude',                  // Exclude directories
            'name', 'notName',          // File name constraints
            'path', 'notPath',          // Path constraints
            'size',                     // File size constraints
            'date',                     // File date constraints
            'depth',                    // Directory depth constraints
            'contains', 'notContains',  // File contents constraints
        );
        foreach ($constraints as $constraint) {
            if (isset($provider[$constraint])) {
                if (is_array($provider[$constraint])) {
                    $args = $provider[$constraint];
                } else {
                    $args = array($provider[$constraint]);
                }
                foreach ($args as $arg) {
                    $finder->{$constraint}($arg);
                }
            }
        }
        $this->provider = $provider;
        return $finder;
    }
1079154
public static function sort($data, $path, $dir = 'asc') {
		$flatten = function($flatten, $results, $key = null) {
			$stack = [];
			foreach ((array) $results as $k => $r) {
				$id = $k;
				if ($key !== null) {
					$id = $key;
				}
				if (is_array($r)) {
					$stack = array_merge($stack, $flatten($flatten, $r, $id));
				} else {
					$stack[] = ['id' => $id, 'value' => $r];
				}
			}
			return $stack;
		};
		$extract = static::extract($data, $path);
		$result = $flatten($flatten, $extract);

		$keys = static::extract($result, '/id');
		$values = static::extract($result, '/value');

		$dir = ($dir === 'desc') ? SORT_DESC : SORT_ASC;
		array_multisort($values, $dir, $keys, $dir);
		$sorted = [];
		$keys = array_unique($keys);

		foreach ($keys as $k) {
			$sorted[] = $data[$k];
		}
		return $sorted;
	}
444463
private function filesWithFullPaths($dir, $include_hidden = true, $recursive = false)
    {
        $dir = $this->withSlash($dir);

        $result = [];

        if ($dirstream = opendir($dir)) {
            while (false !== ($filename = readdir($dirstream))) {
                $path = $dir . $filename;

                if ($filename != '.' && $filename != '..') {
                    if (is_dir($path)) {
                        if ($recursive) {
                            $files_from_subdir = $this->filesWithFullPaths($path, $recursive);

                            if (is_array($files_from_subdir)) {
                                $result = array_merge($result, $files_from_subdir);
                            }
                        }
                    } else {
                        if (is_file($path) || (is_link($path) && is_file(readlink($path)))) {
                            if (mb_substr($filename, 0, 1) == '.' && !$include_hidden) {
                                continue;
                            }

                            $result[] = $path;
                        }
                    }
                }
            }
        }

        closedir($dirstream);

        return $result;
    }
655739
public function getByAlias($alias, array $data = [])
    {
        $pattern = null;
        foreach ($this->_patterns as $_pattern) {
            if ($_pattern[5] == $alias) {
                $pattern = $_pattern;
                break;
            }
        }
        if ($pattern == null) {
            return null;
        }

        /**
         * 没有指定数据则会直接返回原始路由信息
         */
        if (!$data) {
            return $pattern[3];
        }

        foreach ($data as $key => $val) {
            $data[':' . $key] = $val;
            unset($data[$key]);
        }
        $url = str_replace(array_keys($data), array_values($data), $pattern[3]);
        /**
         * 替换掉占位符格式限制字符串
         */
        $formatLimit = array_map(function ($item) {
            return '@' . $item;
        }, array_keys($this->regexps));
        $url = str_replace($formatLimit, '', $url);
        return $url;
    }
738626
public function unshiftResourceDir($dir)
    {
        File::resolveFilepath($dir);

        $resourcedir = $this->getResourceDir();
        array_unshift($resourcedir, $dir);

        $this->resourceDir = $resourcedir;

        return $this;
    }
826249
public function alias($alias, $name) {
		if (is_array($alias)) {
			foreach ($alias as $key) {
				$this->alias($key, $name);
			}

			return;
		}

		$this->aliases[$alias] = $name;
	}
993211
public static function setAlias(string $alias, string $path = null)
    {
        if ($alias[0] !== '@') {
            $alias = '@' . $alias;
        }

        // Delete alias
        if (!$path) {
            unset(self::$aliases[$alias]);

            return;
        }

        // $path 不是别名，直接设置
        if ($path[0] !== '@') {
            self::$aliases[$alias] = $path;

            return;
        }

        // $path是一个别名
        if (isset(self::$aliases[$path])) {
            self::$aliases[$alias] = self::$aliases[$path];

            return;
        }

        list($root) = explode('/', $path);
        if (!isset(self::$aliases[$root])) {
            throw new \InvalidArgumentException('The set root alias does not exist，alias=' . $root);
        }

        $rootPath  = self::$aliases[$root];
        $aliasPath = str_replace($root, '', $path);

        self::$aliases[$alias] = $rootPath . $aliasPath;
    }
428364
private function getPathsData($data, string $root): ?array
    {
        if ($data === null || !\is_array($data) || \count($data) === 0) {
            return null;
        }

        return $this->existingPaths($data, $root);
    }
111314
public function getTranslationsFromFiles($domain, $path, array $directories = [])
    {
        if (!$directories) {
            $directories = [
                $path . 'Resources' . DIRECTORY_SEPARATOR . 'translations',
                $this->kernelRoot . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . $domain . DIRECTORY_SEPARATOR . 'translations',
            ];
        }

        $finder = new Finder();
        $translations = [];

        foreach ($directories as $directory) {
            if (is_dir($directory)) {
                $finder->files()
                    ->name($this->getFileNamePattern())
                    ->in($directory);

                foreach ($finder as $file) {
                    $translations = array_replace_recursive($this->getFileTranslationMessages($file, $domain), $translations);
                }
            }
        }

        return $translations;
    }
840189
static function setAlias($name, $alias)
    {
        if (!is_array($alias))
            $alias = array($alias);

        foreach($alias as $a)
            self::$_aliases[(string) $a] = (string) $name;
    }
1094886
public function addFolder(string $directory, string $alias = '')
	{
		if ($alias === '')
		{
			throw new \InvalidArgumentException('Setting an alias is required in Plates');
		}

		$this->getRenderer()->addFolder($alias, $directory);

		return $this;
	}
1018995
protected static function replaceWildCards($route, &$data)
    {
        preg_match_all(chr(1) . '\(\*([a-z][a-zA-Z0-9_]*)\)' . chr(1), $route, $matches, PREG_SET_ORDER);

        if (!$matches) {
            return $route;
        }

        foreach ($matches as $match) {
            if (isset($data[$match[1]])) {
                $route = str_replace($match[0], implode('/', (array) $data[$match[1]]), $route);

                unset($data[$match[1]]);
            }
        }

        return $route;
    }
1333828
public function setAlias(array $data, $alias_model, $entity, $delete_existing = true)
    {
        if ((empty($data['form']) && empty($data['alias'])) || empty($data[$entity . '_id'])) {
            return null;
        }

        if ($delete_existing) {
            $alias_model->delete(array('entity' => $entity, 'entity_id' => $data[$entity . '_id']));
        }

        if (empty($data['alias'])) {
            $data['alias'] = $alias_model->generateEntity($entity, $data);
        }

        if (empty($data['alias'])) {
            return null;
        }

        $alias = array(
            'alias' => $data['alias'],
            'entity' => $entity,
            'entity_id' => $data[$entity . '_id']
        );

        return $alias_model->add($alias);
    }
567761
public static function createTools($directory, array $data)
    {
        $tools = [];

        foreach ($data as $name => $parameters) {
            $tools[$name] = self::createTool($name, $directory, $parameters);
        }

        return $tools;
    }