Extract checks from a given manifest file.

@access public
@author Jerome Bogaerts <jerome@taotesting.com>
@param  $string $file The path to a manifest.php file.
@return common_configuration_ComponentCollection
547714
public static function extractChecks($file)
    {
        $returnValue = null;

        if (is_readable($file)){
        	$manifestPath = $file;
	    	$content = file_get_contents($manifestPath);
	    	$matches = array();
	    	preg_match_all("/(?:\"|')\s*checks\s*(?:\"|')\s*=>(\s*array\s*\((\s*array\((?:.*)\s*\)\)\s*,{0,1})*\s*\))/", $content, $matches);
	    	
	    	if (!empty($matches[1][0])){
	    		$returnValue = eval('return ' . $matches[1][0] . ';');
	    		
	    		foreach ($returnValue as &$component){
		    		if (strpos($component['type'], 'FileSystemComponent') !== false){
		    			$root = realpath(dirname(__FILE__) . '/../../../');
	        			$component['value']['location'] = $root . '/' . $component['value']['location'];
	        		}	
	    		}
	    	}
	    	else{
	    		$returnValue = array();	
	    	}
        }
        else{
        	$msg = "Extension Manifest file could not be found in '${file}'.";
        	throw new common_ext_ManifestNotFoundException($msg);
        }

        return $returnValue;
    }
987100
private function load(string $file): array
    {
        $file = basename($file);
        $fileName = realpath($this->configDirectory . '/' . $file);

        try {
            $json = @file_get_contents($fileName);

            if ($json !== false) {
                $configuration = json_decode($json, true);

                if (!empty($configuration)) {
                    if (!empty($configuration['@extends'])) {
                        $extends = $configuration['@extends'];
                        unset($configuration['@extends']);

                        $configuration = array_replace_recursive($this->load($extends), $configuration);
                    }
                } else {
                    throw new BerliozException(sprintf('Not a valid JSON configuration file "%s"', $file));
                }
            } else {
                throw new BerliozException(sprintf('Unable to load configuration file "%s"', $file));
            }
        } catch (BerliozException $e) {
            throw $e;
        } catch (\Exception $e) {
            throw new BerliozException(sprintf('Unable to load configuration file "%s"', $file));
        }

        return $configuration;
    }
230000
public function find(&$file)
    {
        list($package, $file) = StringHelper::explode($this->separator, $file, 2, 'array_unshift');

        if (!$package) {
            return false;
        }

        $package = $this->packageResolver->getPackage($package);

        if (!$package) {
            return false;
        }

        return $package->getDir() . '/Templates';
    }
612788
public function analyze_file(string $file): array
  {
    $res = [];
    $ext = bbn\str::file_ext($file);
    if ( \in_array($ext, self::$extensions, true) && is_file($file) ){
      switch ( $ext ){
        case 'html':
          $res = $this->analyze_php($file);
          break;
        case 'php':
          $res = $this->analyze_php($file);
          break;
        case 'js':
          $res = $this->analyze_js($file);
          break;
        /*case 'json':
          $res = $this->analyze_json($file);
          break;*/
      }
    }
    return $res;
  }
203613
protected function getExtensions($file)
    {
        $basename = strtolower(pathinfo($file, PATHINFO_BASENAME));

        // normalize
        foreach ($this->composedExtensions as $composedExtension => $canonicalExtension) {
            $basename = preg_replace('/\.'.preg_quote($composedExtension).'(\.|$)/', '.'.$canonicalExtension.'\\1', $basename);
        }

        $extensions = explode('.', $basename);
        $extensions = array_reverse(array_slice($extensions, 1));

        $recognizedExtensions = [];

        $i = 0;
        $extensionsNumber = count($extensions);

        while ($i < $extensionsNumber && array_key_exists($extensions[$i], $this->extensionMap)) {
            $recognizedExtensions[] = $extensions[$i];
            $i++;
        }

        return array_reverse($recognizedExtensions);
    }
558508
protected function getFileFinder($file) {
    return new class($file) implements ClassFinderInterface {

      protected $file;

      public function __construct($file) {
        $this->file = $file;
      }

      public function findFile($class) {
        return $this->file;
      }
    };
  }
803076
private static function parseRequestedFile(string $file): array
    {
        $file = ltrim($file, '/');

        $moduleConfig = Config::application('module');

        $parts    = explode('/', $file);
        $partsCnt = count($parts);

        if ($partsCnt > 0 && in_array($parts[0], Config::get('divisions'))) {
            $_division = $parts[0];
            $parts     = array_slice($parts, 1);
        } else {
            $_division = '';
        }

        $_module = empty($parts[0])
            ? $moduleConfig['default']
            : $parts[0];

        $_method = $partsCnt < 2 || empty($parts[1])
            ? $moduleConfig['defaultViewsControllerAction']
            : Str::camel($parts[1]);

        $_params = $partsCnt > 2
            ? array_slice($parts, 2)
            : [];

        return [$_division, $_module, $_method, $_params];
    }
282716
private static function checkType(string $file): string
    {
        $parts = explode('.', $file);
        $type = array_pop($parts);

        if (!in_array($type, array_keys(self::$types))) {
            throw new LoaderException("Loader::checkType(): Could not find parser for {$file}!");
        }

        return $type;
    }
494946
public function version($file)
    {
        try {
            $manifest = $this->readManifestFile();
        } catch (\Exception $e) {
            Craft::log(printf($e->getMessage()), LogLevel::Info, true);
            return $file;
        }

        // if no manifest, return the regular asset
        if (!$manifest) {
            return $file;
        }

        return '/' . $this->buildPath . '/' . $manifest[$file];
    }
734158
protected function getFile($file)
    {
        $mapping = [
            '%environment%' => $this->runtime->getEnvironment(),
        ];

        if ($this->runtime->getHostName() !== null) {
            $mapping['%host%'] = $this->runtime->getHostName();
        }

        if ($this->runtime->getReleaseId() !== null) {
            $mapping['%release%'] = $this->runtime->getReleaseId();
        }

        $options = $this->getOptions();
        return str_replace(
            array_keys($mapping),
            array_values($mapping),
            $options[$file]
        );
    }
506659
protected function parseFile($file)
    {
        $stmts = $this->phpParser->parse(file_get_contents($file));

        $visitor = new RefVisitor($file);
        $this->traverser->addVisitor($visitor);
        $this->traverser->traverse($stmts);
        $this->traverser->removeVisitor($visitor);

        return $visitor->getClasses();
    }
775084
public static function parse($file)
    {
        $config_path = self::$config_path == '' ? APP_PATH . '/config/' : self::$config_path;
        if($file == null){
            $file = scandir($config_path);
            foreach ($file as $k => $v)
            {
                unset($file[0], $file[1]);
                if($v == 'routes.php' )
                {
                    unset($file[$k]);
                }
            }
            foreach ($file as $k => $v)
            {
                $name = str_replace('.php', '', $v);
                $file = $config_path . $v;
                $data[$name] = include $file;
            }
        }else{
            $type = $file;
            if(strpos($type, '.')){
                $type = explode('.', $type);
                $file = $config_path . $type[0] . '.php';
                if(!array_key_exists($type[1], self::load($file)))
                {
                    throw new Exception('This configuration [' . self::$config . '] is not supported!');
                }
                $data = self::load($file)[$type[1]];
            }else{
                $file = $config_path . $file . '.php';
                $data = self::load($file);
            }

        }
        return $data;
    }
607335
public static function parseFile($file)
    {
        if (!file_exists($file) || !is_readable($file)) {
            $message = "crontab config file is not exists or not readable";
            throw new \RuntimeException($message);
        }

        $tasks = array();
        $lines = file($file);
        foreach ($lines as $line) {
            $job = new JobParse($line);
            $tasks[] = $job->getTask();
        }

        return $tasks;
    }
1251984
protected function loadConfigFile($file)
    {
        $path = $this->getConfigPath() . '/' . $file;

        if (file_exists($path)) {
            $config = include $path;
            return is_array($config) ? $config : null;
        }

        return null;
    }
291207
protected function findUseStatements(File $file)
    {
        if (array_key_exists($file->getFilename(), static::$useCache)) {
            return static::$useCache[$file->getFilename()];
        }

        $tokens = $file->getTokens();
        $usePosition = $file->findNext(T_USE, 0);
        $useStatements = [];

        while ($usePosition !== false) {
            if ($this->shouldIgnoreUse($file, $usePosition)) {
                $usePosition = $file->findNext(T_USE, $usePosition + 1);
                continue;
            }

            $fullPath = '';
            $lastString = '';
            $alias = '';

            $useEnd = $file->findNext(
                [T_SEMICOLON, T_COMMA],
                $usePosition
            );
            $useFullPathEnd = $file->findNext(
                [T_SEMICOLON, T_COMMA, T_WHITESPACE],
                $usePosition + 2
            );

            $afterUse = $file->findNext(
                [T_STRING, T_NS_SEPARATOR],
                $usePosition
            );

            while ($afterUse !== false) {
                $fullPath .= $tokens[$afterUse]['content'];

                if ($tokens[$afterUse]['code'] == T_STRING) {
                    $lastString = $tokens[$afterUse]['content'];
                }

                $afterUse = $file->findNext(
                    [T_STRING, T_NS_SEPARATOR],
                    $afterUse + 1,
                    $useFullPathEnd
                );
            }

            if ($useFullPathEnd != $useEnd) {
                if ($tokens[$useFullPathEnd + 1]['code'] !== T_AS) {
                    continue;
                }

                if ($tokens[$useFullPathEnd + 3]['code'] === T_STRING) {
                    $alias = $tokens[$useFullPathEnd + 3]['content'];
                }
            } else {
                $alias = $lastString;
            }

            $useStatements[$fullPath] = $alias;

            $usePosition = $file->findNext(T_USE, $usePosition + 1);
        }

        static::$useCache[$file->getFilename()] = $useStatements;

        return $useStatements;
    }
951390
private function parseXml($file)
    {
        $formats = [];

        // load xml file
        $xmlDoc = $this->tryLoad($file);

        $this->xpath = new \DOMXPath($xmlDoc);
        $this->xpath->registerNamespace('x', static::XML_NAMESPACE_URI);

        foreach ($this->xpath->query('/x:formats/x:format') as $formatNode) {
            $this->addFormatFromFormatNode($formatNode, $formats);
        }

        return $formats;
    }
872393
public function analyze_php(string $file): array
  {
    $res = [];
    $php = file_get_contents($file);
    if ( $tmp = \Gettext\Translations::fromPhpCodeString($php, [
      'functions' => ['_' => 'gettext'],
      'file' => $file
      ]) ){
      foreach ( $tmp->getIterator() as $r => $tr ){
        $res[] = $tr->getOriginal();
      }
      $this->parser->mergeWith($tmp);
    }
    return array_unique($res);
  }