Finds all constants defined in a particular file

@param  string $path The path to analyse
@param  array  $vars The existing variables to check against (so only new variables are returned)

@return array
775129
private function getConstantsFromFile($path, array $vars = [])
    {
        $out = [];

        if (file_exists($path)) {

            $appFile = file_get_contents($path);
            $pattern = '/define\([\'|"](.+?)[\'|"]\,(.*)\)/';
            preg_match_all($pattern, $appFile, $matches);

            if (!empty($matches[0])) {

                $numMatches = count($matches[0]);

                //  Remove quotes from stringy values
                for ($i = 0; $i < $numMatches; $i++) {

                    $matches[2][$i] = trim($matches[2][$i]);

                    if (substr($matches[2][$i], 0, 1) == '\'' || substr($matches[2][$i], 0, 1) == '"') {
                        //  Remove the first and last character; subtracting 2 to account for the removal of both chars
                        $matches[2][$i] = substr($matches[2][$i], 1, strlen($matches[2][$i]) - 2);
                    }
                }

                for ($i = 0; $i < $numMatches; $i++) {

                    //  Check to see if it's already been requested
                    $exists = false;
                    foreach ($vars as $existing) {
                        if (!is_string($existing) && $existing['key'] == $matches[1][$i]) {
                            $exists = true;
                        }
                    }

                    if (!$exists) {

                        $name = str_replace('_', ' ', $matches[1][$i]);
                        $name = strtolower($name);
                        $name = ucwords($name);

                        $out[] = [
                            'key'     => $matches[1][$i],
                            'label'   => $name,
                            'value'   => defined($matches[1][$i]) ? constant($matches[1][$i]) : '',
                            'options' => [],
                        ];
                    }
                }
            }
        }

        return $out;
    }
386437
public function findTranslationsFilesByPaths(string $path) : Finder
    {
        $finder = new Finder();
        $finder
            ->files()
            ->in($path)
            ->name('*.php');

        return $finder;
    }
336917
protected function getCachedFilepath(array $vars)
	{
		if (!isset($this->cacheDir))
		{
			return null;
		}

		$filepath = $this->cacheDir . '/http.' . $this->getCacheKey($vars);
		if (extension_loaded('zlib'))
		{
			$filepath = 'compress.zlib://' . $filepath . '.gz';
		}

		return $filepath;
	}
755323
private function getCompiledViewPaths(string $path) : array
    {
        if (!is_dir($path)) {
            return [];
        }

        $files = [];
        $iter = new RecursiveIteratorIterator(
            new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS),
            RecursiveIteratorIterator::SELF_FIRST,
            RecursiveIteratorIterator::CATCH_GET_CHILD
        );
        $iter->setMaxDepth(0);

        foreach ($iter as $path => $item) {
            if ($item->isFile()) {
                $files[] = $path;
            }
        }

        return $files;
    }
151826
private function matchVariableRouteChunk($path, $variableRoutes)
    {
        $numGroups = 0;

        /** @var Route[] $routes */
        $routes   = [];
        $pattern   = '';
        foreach ($variableRoutes as $route) {
            $numVariables = $route->getParameterCount();
            $pattern .= '|' . $route->getRegexp();
            if ($numVariables < $numGroups && !isset($routes[ $numVariables ])) {
                $routes[ $numVariables ] = $route;
            } else {
                $numGroups = max($numGroups, $numVariables);
                $pattern .= str_repeat('()', $numGroups - $numVariables);
                $routes[ $numGroups++ ] = $route;
            }
        }
        if (!preg_match('#^(?' . $pattern . ')$#', $path, $matched)) {
            return false;
        }
        //Remove the whole match
        array_shift($matched);
        $route = $routes[ count($matched) ];

        $parameterNames = $route->getParameterNames();
        //get the elements of $matched that are actually parameters
        $parameters = array_intersect_key($matched, $parameterNames);
        $matchedParams = array_combine($parameterNames, $parameters);

        return new Match($route, $matchedParams);
    }
378908
protected static function getFilesFromPath($path)
    {
        $files = [];
        $path = rtrim($path, '/') . DIRECTORY_SEPARATOR;

        if (false !== $items = scandir($path)) {
            foreach ($items as $item) {
                $file = $path . $item;
                if (is_file($file)) {
                    $extension = strtolower(pathinfo($file, PATHINFO_EXTENSION));
                    if (in_array($extension, [Packager::FILE_EXTENSION, Package::FILE_EXTENSION])) {
                        $files[] = $file;
                    }
                }
            }
        }

        return $files;
    }
613586
function extractVars(path) {
    const declarators = [];

    if (path.isVariableDeclaration({ kind: "var" })) {
      for (const decl of path.node.declarations) {
        const bindingIds = Object.keys(t.getBindingIdentifiers(decl.id));

        declarators.push(
          ...bindingIds.map(name => t.variableDeclarator(t.identifier(name)))
        );
      }
    } else {
      path.traverse({
        VariableDeclaration(varPath) {
          if (!varPath.isVariableDeclaration({ kind: "var" })) return;

          if (!isSameFunctionScope(varPath, path)) return;

          for (const decl of varPath.node.declarations) {
            const bindingIds = Object.keys(t.getBindingIdentifiers(decl.id));
            declarators.push(
              ...bindingIds.map(name =>
                t.variableDeclarator(t.identifier(name))
              )
            );
          }
        }
      });
    }

    if (declarators.length <= 0) return [];

    return [t.variableDeclaration("var", declarators)];
  }
386224
public function parseThinkVar($vars)
    {
        $type  = strtoupper(trim(array_shift($vars)));
        $param = implode('.', $vars);

        if ($vars) {
            switch ($type) {
                case 'SERVER':
                    $parseStr = '$_SERVER[\'' . $param . '\']';
                    break;
                case 'GET':
                    $parseStr = '$_GET[\'' . $param . '\']';
                    break;
                case 'POST':
                    $parseStr = '$_POST[\'' . $param . '\']';
                    break;
                case 'COOKIE':
                    $parseStr = '$_COOKIE[\'' . $param . '\']';
                    break;
                case 'SESSION':
                    $parseStr = '$_SESSION[\'' . $param . '\']';
                    break;
                case 'ENV':
                    $parseStr = '$_ENV[\'' . $param . '\']';
                    break;
                case 'REQUEST':
                    $parseStr = '$_REQUEST[\'' . $param . '\']';
                    break;
                case 'CONST':
                    $parseStr = strtoupper($param);
                    break;
                default:
                    $parseStr = '\'\'';
                    break;
            }
        } else {
            switch ($type) {
                case 'NOW':
                    $parseStr = "date('Y-m-d g:i a',time())";
                    break;
                case 'LDELIM':
                    $parseStr = '\'' . ltrim($this->config['tpl_begin'], '\\') . '\'';
                    break;
                case 'RDELIM':
                    $parseStr = '\'' . ltrim($this->config['tpl_end'], '\\') . '\'';
                    break;
                default:
                    if (defined($type)) {
                        $parseStr = $type;
                    } else {
                        $parseStr = '';
                    }
            }
        }

        return $parseStr;
    }
352620
private function findFeatureFiles($path)
    {
        $absolutePath = $this->findAbsolutePath($path);

        if (!$absolutePath) {
            return array($path);
        }

        if (is_file($absolutePath)) {
            return array($absolutePath);
        }

        $iterator = new RegexIterator(
            new RecursiveIteratorIterator(
                new RecursiveDirectoryIterator(
                    $absolutePath,
                    RecursiveDirectoryIterator::FOLLOW_SYMLINKS | RecursiveDirectoryIterator::SKIP_DOTS
                )
            ),
            '/^.+\.feature$/i',
            RegexIterator::MATCH
        );

        $paths = array_map('strval', iterator_to_array($iterator));
        uasort($paths, 'strnatcasecmp');

        return $paths;
    }
315606
protected function getSourceFiles($path)
    {
        $files = [];
        foreach (glob($path.'/*.php') as $file) {
            $files[] = $file;
        }

        return $files;
    }
728264
function sassVars (filePath) {
    const declarations = collectDeclarations(filePath);
    let variables = {};

    if (!declarations.length) {
        message('Warning: Zero declarations found');
        return;
    }

    declarations.forEach(function (declaration) {
        const parsedDeclaration = parseDeclaration(declaration);
        const varName = parsedDeclaration.key;
        let varValue = parsedDeclaration.value;
        const valueType = getValueType(varValue);

        /*
         * $key: $value;
         */
        if (valueType === 'var') {
            const localVarName = varValue;
            varValue = getVarValue(localVarName, variables);

            if (!varValue) {
                message(`Warning: Null value for variable ${localVarName}`);
            }
        }

        /*
         * $key: ($value-1 + $value-2) * $value-3 ... ;
         */
        if (valueType === 'expression') {
            // todo
        }

        /*
         * $key: value;
         */
        variables[varName] = varValue;
    });

    return variables;
}
744899
public function match(string $path, array &$vars, string &$next_path) : bool
    {
        // parse query string: /path?foo=?bar&baz=qux
        $pos = strpos($path,'?');
        if ($pos !== false){
            $query = substr($path, $pos + 1);
            $path = substr($path, 0, $pos);
            parse_str($query, $auery_vars);
            $vars = array_replace($vars, $auery_vars);
        }
        // get first path section
        $pos = strpos(substr($path,1), '/');
        $first = $pos > 0 ? substr($path, 0, $pos + 1) : substr($path, 0);
        $next_path = $pos > 0 ? substr($path, $pos + 1) : '';
        // parse pattern
        $pattern = "@^/({$this->regex})$@";
        if (!preg_match($pattern, $first, $match) ){
            return false;
        }
        $varname = $this->varname;
        if (!empty($varname)){
            static $type_converters = [
                'string' => 'strval',
                'integer' => 'intval',
                'int' => 'intval',
                'float' => 'floatval',
                'double' => 'floatval',
                'boolean' => 'boolval',
                'bool' => 'boolval',
            ];
            $type_converter = $type_converters[$this->type] ?? null;
            $value = $type_converter ? ($type_converter)($match[1]) : $match[1];
            
            if (strpos($varname,'[]',strlen($varname)-3) !== false){
                $varname = substr($this->varname,0,-2);
                $vars[$varname][] = $value;
                $length = strlen($match[1]) + 1;
                $next = substr($path, $length);
                $pos = strpos(substr($next,1), '/');
                $next = substr($next, 0, $pos + 1);
                while(strlen($next)> 0 && preg_match($pattern, $next, $match))
                {
                    $value = $type_converter ? ($type_converter)($match[1]) : $match[1];
                    $vars[$varname][] = $value;
                    $length += strlen($match[1]) + 1;
                    $next = substr($path, $length);
                    $pos = strpos(substr($next,1), '/');
                    $next = $pos > 0 ? substr($next, 0, $pos + 1) : substr($next, 0);
                }
                $next_path = $next;
            }
            else{
                $vars[$this->varname] = $value;
            }
        }
        return true;
    }
294600
public function getParametersAsVars( $vars = array() )
	{
		foreach ( $this->parameters as $qname => $parameter )
		{
			$vars[ $qname ] = $parameter->result;
		}

		return $vars;
	}
625207
protected function templatePath($path, array $path_vars = []) {
    if (strpos($path, '{') !== false) {
      extract($path_vars);
      preg_match_all('@\{\$([A-Za-z0-9_]*)\}@i', $path, $matches);
      if (!empty($matches[1])) {
        foreach ($matches[1] as $var) {
          $path = str_replace('{$' . $var . '}', $$var, $path);
        }
      }
    }

    return $path;
  }
648395
protected function getConfigurationFiles($path)
    {
        $files = [];

        foreach (Finder::create()->files()->name('*.php')->in($path) as $file) {
            $directory = $this->getNestedDirectory($file, $path);
            $files[$directory.basename($file->getRealPath(), '.php')] = $file->getRealPath();
        }

        ksort($files, SORT_NATURAL);

        return $files;
    }
1031772
public function resolveBindings(array $vars)
    {
        // First check if the route $vars as a whole matches any registered composite binding
        if (count($vars) > 1 && !empty($this->compositeBindings)) {
            if ($r = $this->resolveCompositeBinding($vars)) {
                return $r;
            }
        }

        // If no composite binding found, check for explicit and implicit bindings
        if (!empty($this->implicitBindings) || !empty($this->bindings)) {
            foreach ($vars as $var => $value) {
                $vars[$var] = $this->resolveBinding($var, $value);
            }
        }

        return $vars;
    }
1025938
private function ensurePreviewVars(array $vars, array $uriVars)
    {
        if (! is_user_logged_in()) {
            return $vars;
        }

        foreach (['preview', 'preview_id', 'preview_nonce'] as $var) {
            if (! isset($vars[$var]) && isset($uriVars[$var])) {
                $vars[$var] = $uriVars[$var];
            }
        }

        return $vars;
    }