Parse ini file

@param string $file    Filename
@param array  $options
@return array|false
545395
protected function loadFile(string $file, array $options)
    {
        return parse_ini_file(
            $file,
            $options['process_sections'] ?? true,
            $options['mode'] ?? INI_SCANNER_NORMAL
        );
    }
784608
protected function _process(File $file, array $options) {
        if (!$file->isImage()) {
            throw new DomainException(sprintf('%s is not a valid image', $file->basename()));
        }

        $sourcePath = $file->path();
        $mimeType = $file->type();

        // Create an image to work with
        switch ($mimeType) {
            case 'image/gif':
                $sourceImage = @imagecreatefromgif($sourcePath);
            break;
            case 'image/png':
                $sourceImage = @imagecreatefrompng($sourcePath);
            break;
            case 'image/jpg':
            case 'image/jpeg':
            case 'image/pjpeg':
                $sourceImage = @imagecreatefromjpeg($sourcePath);
            break;
            default:
                $sourceImage = false;
            break;
        }

        if (!$sourceImage) {
            throw new DomainException(sprintf('%s can not be transformed', $mimeType));
        }

        // Gather options
        $options = $options + array(
            'width' => null,
            'height' => null,
            'dest_x' => 0,
            'dest_y' => 0,
            'dest_w' => null,
            'dest_h' => null,
            'source_x' => 0,
            'source_y' => 0,
            'source_w' => $file->width(),
            'source_h' => $file->height(),
            'quality' => 100,
            'overwrite' => false,
            'target' => '',
            'preCallback' => '',
            'postCallback' => ''
        );

        $options = array_map(function($value) {
            if (is_numeric($value)) {
                $value = round($value);
            }

            return $value;
        }, $options);

        $width = $options['width'] ?: $options['dest_w'];
        $height = $options['height'] ?: $options['dest_h'];
        $targetImage = imagecreatetruecolor($width, $height);

        // If gif/png allow transparencies
        if ($mimeType === 'image/gif' || $mimeType === 'image/png') {
            imagealphablending($targetImage, false);
            imagesavealpha($targetImage, true);
            imagefill($targetImage, 0, 0, imagecolorallocatealpha($targetImage, 255, 255, 255, 127));
        }

        // Trigger a callback to prepare the image
        if (is_callable($options['preCallback'])) {
            $targetImage = call_user_func_array($options['preCallback'], array($targetImage, $options));
        }

        // Lets take our source and apply it to the temporary file and resize
        imagecopyresampled($targetImage, $sourceImage, $options['dest_x'], $options['dest_y'], $options['source_x'], $options['source_y'], $options['dest_w'], $options['dest_h'], $options['source_w'], $options['source_h']);

        // Trigger a callback to modify the image
        if (is_callable($options['postCallback'])) {
            $targetImage = call_user_func_array($options['postCallback'], array($targetImage, $options));
        }

        // Now write the transformed image to the server
        if ($options['overwrite']) {
            $options['target'] = $file->name();

        } else if (!$options['target']) {
            $class = explode('\\', get_class($this));
            $class = str_replace('transformer', '', strtolower(end($class)));

            $options['target'] = sprintf('%s-%s-%sx%s-%s', $file->name(), $class, $width, $height, uniqid());
        }

        $targetPath = sprintf('%s%s.%s', $file->dir(), $options['target'], $file->ext());

        switch ($mimeType) {
            case 'image/gif':
                imagegif($targetImage, $targetPath);
            break;
            case 'image/png':
                imagepng($targetImage, $targetPath);
            break;
            case 'image/jpg':
            case 'image/jpeg':
            case 'image/pjpeg':
                imagejpeg($targetImage, $targetPath, $options['quality']);
            break;
        }

        // Clear memory
        imagedestroy($sourceImage);
        imagedestroy($targetImage);

        return new File($targetPath);
    }
383031
protected function load_file($file)
	{
		$contents = $this->parse_vars(file_get_contents($file));
		return parse_ini_string($contents, true);
	}
489671
public static function imageSize($file, $options)
    {
        if (!isset($options['height']) && !isset($options['width'])) {
            throw new InvalidArgumentException('Invalid image size validation parameters! Missing `width` and / or `height`.');
        }

        $filename = static::getFilename($file);

        list($width, $height) = getimagesize($filename);

        $validHeight = $validWidth = null;

        if (isset($options['height'])) {
            $validHeight = self::comparison($height, $options['height'][0], $options['height'][1]);
        }
        if (isset($options['width'])) {
            $validWidth = self::comparison($width, $options['width'][0], $options['width'][1]);
        }
        if ($validHeight !== null && $validWidth !== null) {
            return ($validHeight && $validWidth);
        }
        if ($validHeight !== null) {
            return $validHeight;
        }
        if ($validWidth !== null) {
            return $validWidth;
        }

        throw new InvalidArgumentException('The 2nd argument is missing the `width` and / or `height` options.');
    }
990425
private static function parse($file, $data)
    {
        $file = file_get_contents($file, FILE_USE_INCLUDE_PATH);

        // Go through each variable and replace the values
        foreach($data as $key => $value)
        {
            $pattern = '{{{' . $key . '}}}';
            $file = preg_replace($pattern, $value, $file);
        }

        if(!!$file)
        {
            return $file;
        }

        return false;
    }
533705
protected function parseFile($file)
    {
        try {
            $dom = XmlUtils::loadFile($file, __DIR__ . static::SCHEME_PATH);
        } catch (\InvalidArgumentException $e) {
            throw new \InvalidArgumentException(sprintf('Unable to parse file "%s".', $file), $e->getCode(), $e);
        }

        return $dom;
    }
120936
public function readConfig($file = 'config.php')
    {
        $orig_file = $file;

        if (strpos($file, '.php') != strlen($file) - 4) {
            $file .= '.php';
        }

        if (strpos($file, '/') === false) {
            $file = getcwd().'/'.$this->config_location.'/'.$file;
        }

        if (file_exists($file)) {
            // some tricky thing to make config be read in some cases it could not in simple way
            unset($config);

            $config = &$this->config;
            $this->config_files_loaded[] = $file;
            include $file;

            unset($config);

            return true;
        }

        return false;
    }
402486
public static function parseFiles($paths, $file) {
		if ($paths === null) {
			$paths = ROOT . DS . 'config' . DS;
		}

		$list = [];
		foreach ((array)$paths as $path) {
			$list += static::parseFile($path . $file);
		}

		return $list;
	}
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];
    }
634308
private static function parse(File $file) {

		$lines 		= explode("\n", $file -> getContent());
		$languages 	= [];

		foreach($lines as $index => $line) {
			
			$line = trim($line);

			if('' === $line) {
				continue;
			}

			//Check for language format
			preg_match('#^\[([a-z_\-0-9]+)\]#i', $line, $language);

			if(count($language) === 2) {
				
				$lg = $language[1];
				$languages[$lg] = [];

				continue;
			}

			//If there is no language found
			if(false === isset($lg)) {
				return trigger_error(sprintf('Missing language title in translation file "%s" on line %s', $file -> entity() -> getBasepath(), ++$index), E_USER_ERROR);
			}
			
			//Match the format (key value) on a single translation line
			preg_match('#^(\'|")(.*)(\1)\s+(\'|")(.*)(\3)$#', $line, $match);

			if(count($match) !== 7) {
				return trigger_error(sprintf('Incorrect format in translation file "%s" on line %s', $file -> entity() -> getBasepath(), ++$index), E_USER_ERROR);
			}

			$languages[$lg][$match[2]] = $match[5];
		}

		return $languages;
	}
306035
protected function loadFile(string $file, array $options)
    {
        $yaml = file_get_contents($file);

        // Workaround for the bad practise of PHP extensions to trigger a warning and return false.
        error_clear_last();

        $unused = null;

        $data = @yaml_parse(
            $yaml,
            $options['pos'] ?? 0,
            $unused,
            $options['callbacks'] ?? []
        );

        return $data;
    }
542021
protected function parse_config($file) {

        $this->log("Loading configuration from $file");

        if (substr($file, -4) == ".php") {

            require $file;

        } elseif (substr($file, -4) == ".ini") {

            $gearman_config = parse_ini_file($file, true);

        }

        if (empty($gearman_config)) {
            $this->show_help("No configuration found in $file");
        }

        if (isset($gearman_config[self::DEFAULT_CONFIG])) {
            $this->config = $gearman_config[self::DEFAULT_CONFIG];
            $this->config['functions'] = array();
        }

        foreach ($gearman_config as $function=>$data) {

            if (strcasecmp($function, self::DEFAULT_CONFIG) != 0) {
                $this->config['functions'][$function] = $data;
            }

        }

    }
903227
protected function loadFile(string $file, array $options): ?Config
    {
        if (is_dir($file)) {
            return (bool)($options['recursive'] ?? false) ? $this->load($file, $options) : null;
        }

        return $this->getFileLoader()->load($file, $options);
    }
539352
private function parseConfigFile($file)
    {
        Assertion::file($file, 'Can\'t parse config file. File does not exist: ' . $file);

        $config = Yaml::parse(file_get_contents($file));

        if (is_null($config)) {
            $config = array();
        }

        return $config;
    }
184553
protected function lockFileName($file, array $options = array()) {
        $lockDir = $this->getOption('lock_dir', $options, $this->getCachePath() . 'locks' . DIRECTORY_SEPARATOR);
        return $lockDir . preg_replace('/\W/', '_', $file) . $this->getOption(xPDO::OPT_LOCKFILE_EXTENSION, $options, '.lock');
    }
427871
public static function file2array($file)
    {
        $aFile = [];
        if ($file instanceof UploadedFile) {
            $aFile = file($file->getRealPath());
        } elseif (is_array($file) && isset($file[0]) && is_string($file[0])) {
            $aFile = $file;
        } elseif (is_string($file) && is_file($file) && file_exists($file)) {
            $aFile = file($file);
        } elseif (is_string($file) && strstr($file, PHP_EOL) !== false) {
            $file_content = explode(PHP_EOL, $file);
            if (empty(end($file_content))) {
                array_pop($file_content);
            }
            reset($file_content);
            $aFile = $file_content;
        }

        return array_map('\ForceUTF8\Encoding::toUTF8', $aFile);
    }
968466
protected function parse_file($file = null) {
        if (is_null($file)) {
            $file = $this->file;
        }

        if (empty($this->file_data)) {
            $this->load_data($file);
        }

        return !empty($this->file_data) ? $this->parse_string() : false;
    }