Factory method - create a new CSPBuilder object from a JSON file

@param string $filename
@return self
@throws \Exception
175395
public static function fromFile(string $filename = ''): self
    {
        if (!\file_exists($filename)) {
            throw new \Exception($filename.' does not exist');
        }
        $contents = \file_get_contents($filename);
        if (!\is_string($contents)) {
            throw new \Exception('Could not read file contents');
        }
        return self::fromData($contents);
    }
439244
public function load($filename)
    {
        if (!file_exists($filename)) {
            throw new \Exception('Ini file "' . $filename . '" doesn\'t exist.');
            return false;
        }
        $this->filename = $filename;
        return $this;
    }
1287158
protected function openFile($filename)
    {
        $this->filename = $filename;

        if (!is_file($this->filename)) {
            throw new \Exception(
                sprintf(
                    'File %s does not exist',
                    $this->filename
                )
            );
        }

        $this->file = fopen($this->filename, 'rb');
        if (false === $this->file) {
            throw new \Exception(
                sprintf(
                    'Could not open file %s for reading',
                    $this->filename
                )
            );
        }
    }
154472
public static function fromFile(string $filename): PhpInterface {
		$interface = new PhpInterface();
		$parser = new FileParser($filename);
		$parser->addVisitor(new InterfaceParserVisitor($interface));
		$parser->addVisitor(new MethodParserVisitor($interface));
		$parser->addVisitor(new ConstantParserVisitor($interface));
		$parser->parse();

		return $interface;
	}
936352
static public function fromFile(string $filename)
    {
        $yaml = filter_var($filename, FILTER_VALIDATE_URL)
            ? yaml_parse_url($filename)
            : yaml_parse_file($filename);

        YamlException::importFromFile($yaml);
        return $yaml;
    }
555269
public static function load($filename)
    {
        if (static::$env != null) {
            return;
        }

        static::$env = json_decode(trim(file_get_contents($filename)), true);

        if (json_last_error() == JSON_ERROR_SYNTAX) {
            throw new \ErrorException('');
        }

        if (json_last_error() == JSON_ERROR_INVALID_PROPERTY_NAME) {
            throw new \ErrorException('Check environment file json syntax (.env.json)');
        }

        if (json_last_error() != JSON_ERROR_NONE) {
            throw new \ErrorException(json_last_error_msg());
        }
    }
383265
public function createFromFile($filename)
    {
        $img = imagecreatefromstring(file_get_contents($filename));
        list($width, $height) = getimagesize($filename);

        $ascii = null;
        $incY = $this->scale;
        $incX = $this->scale / 2;
        
        for ($y = 0; $y < $height - 1; $y += $incY) {
            for ($x = 0; $x < $width - 1; $x += $incX) {
                $toX = min($x + $this->scale / 2, $width - 1);
                $toY = min($y + $this->scale, $height - 1);
                $luminance = $this->luminanceAreaAverage($img, $x, $y, $toX, $toY);
                $ascii .= $this->luminance2character($luminance);
            }
            $ascii .= PHP_EOL;
        }

        return $ascii;
    }
178968
public static function fromFile(string $filename): PhpClass {
		$class = new PhpClass();
		$parser = new FileParser($filename);
		$parser->addVisitor(new ClassParserVisitor($class));
		$parser->addVisitor(new MethodParserVisitor($class));
		$parser->addVisitor(new ConstantParserVisitor($class));
		$parser->addVisitor(new PropertyParserVisitor($class));
		$parser->parse();

		return $class;
	}
189585
public static function fromFile($fileName) {
        if (!file_exists($fileName))
            throw new SettingsException("file $fileName does not exist");
        return static::fromString(file_get_contents($fileName), dirname($fileName));
    }
994997
public function loadExpectationFromFile($fileName)
    {
        $this->logger->debug("Loading expectation file $fileName");
        $content = file_get_contents($fileName);
        $data = @json_decode($content, true);
        if (JSON_ERROR_NONE !== json_last_error()) {
            throw new \Exception(json_last_error_msg());
        }
        /** @var Mcustiel\Phiremock\Domain\Expectation $expectation */
        $expectation = $this->requestBuilder->parseRequest(
            $data,
            Expectation::class,
            RequestBuilder::RETURN_ALL_ERRORS_IN_EXCEPTION
        );
        $this->validateExpectationOrThrowException($expectation, $this->logger);

        $this->logger->debug('Parsed expectation: ' . var_export($expectation, true));
        $this->storage->addExpectation($expectation);
        // As we have no API to modify expectation parsed the same object could be used for backup.
        // On futher changes when $expectation modifications are possible something like deep-copy
        // should be used to clone expectation.
        $this->backup->addExpectation($expectation);
    }
539411
public final function compose(string $fileName): LoaderInterface
    {
       if (is_file($fileName)){
           $config = json_decode(file_get_contents($fileName));
           if (is_object($config)
            && isset($config->{"autoload"})
            && isset($config->{"autoload"}->{"psr-4"})) {
               $includePath = dirname($fileName) . DIRECTORY_SEPARATOR;
               foreach ($config->{"autoload"}->{"psr-4"} as $key => $value) {
                   $this->addPrefix($key, $includePath . $value);
               }
           }
       }
       return $this;
    }
1159697
public function store(string $fileName): self
    {
        $this->driver->store($fileName, $this->handle);
        return $this;
    }
1251249
public static function fromClass($className)
    {
        return new self(
            \Pheasant::instance()->schema($className),
            \Pheasant::instance()->finderFor($className)
        );
    }
1266586
public function imageCreateJpegfromExif($filename)
    {
        $img = imagecreatefromjpeg($filename);

        if (!function_exists('exif_read_data') || !isset($this->source_info['APP1'])  || strpos($this->source_info['APP1'], 'Exif') !== 0) {
            return $img;
        }

        try {
            $exif = @exif_read_data($filename);
        } catch (Exception $e) {
            $exif = null;
        }

        if (!$exif || !isset($exif['Orientation'])) {
            return $img;
        }

        $orientation = $exif['Orientation'];

        if ($orientation === 6 || $orientation === 5) {
            $img = imagerotate($img, 270, null);
        } elseif ($orientation === 3 || $orientation === 4) {
            $img = imagerotate($img, 180, null);
        } elseif ($orientation === 8 || $orientation === 7) {
            $img = imagerotate($img, 90, null);
        }

        if ($orientation === 5 || $orientation === 4 || $orientation === 7) {
            if(function_exists('imageflip')) {
                imageflip($img, IMG_FLIP_HORIZONTAL);
            } else {
                $this->imageFlip($img, IMG_FLIP_HORIZONTAL);
            }
        }

        return $img;
    }
1269193
public function create($filename)
    {
        if ($this->exists($filename)) {
            $message = sprintf('Failed to create "%s" because its path is not accessible.', $filename);

            throw new IOException($filename, $message);
        }

        return $this->makeFile($filename, '');
    }
961320
public function open($filename)
    {
        if (!$this->exists($filename) || false === $content = file_get_contents($filename)) {
            throw new FileNotFoundException($filename);
        }

        return $this->makeFile($filename, $content);
    }
474894
public function import($filename)
    {
        // TODO: Wrap this in a transaction!
        if (!file_exists($filename)) {
            throw new Exception("File not found: $filename");
        }

        $sql_queries = file_get_contents($filename);
        $sql_queries = $this->_removeRemarks($sql_queries);
        $sql_queries = StringUtils::smartSplit($sql_queries, ";", "'", "\\'");

        foreach ($sql_queries as $sql) {
            $sql = trim($sql); // Trim newlines so we don't have blank queries
            if (empty($sql))
                continue;
            $this->write($sql);
        }
    }