Resolve a migration instance from a file.

@param string $file

@throws Exception

@return MigrationInterface
518461
protected function getMigrationObjectByFileName($file)
    {
        $class = $this->getMigrationClassNameByFileName($file);

        $this->requireMigrationFile($file);

        $object = new $class();

        if (!$object instanceof MigrationInterface) {
            throw new Exception("Migration class {$class} must implement Arrilot\\BitrixMigrations\\Interfaces\\MigrationInterface");
        }

        return $object;
    }
807530
public static function fromFile(\SplFileObject $file)
    {
        $file->rewind();
        $object = static::fromJson($file->fread($file->getSize()));
        $object->file = $file;

        return $object;
    }
1300077
protected function requireFile($file)
    {
        switch ($this->type)
        {
            case PHP:
                return require $file;

            case YML:
                return \Symfony\Component\Yaml\Yaml::parse(file_get_contents($file));

            case JSON:
                return $this->helper->json()->decode(file_get_contents($file));
        }

        throw new Exceptions\TypeNotFound();
    }
579893
public function resolve($file)
    {
        $file = implode('_', array_slice(explode('_', $file), 4));

        $class = Str::studly($file);

        return new $class();
    }
1268495
public static function createFromFile($file)
    {
        // If the file is not readable
        if (!is_readable($file)) {
            throw new InvalidArgumentException(
                sprintf(InvalidArgumentException::INVALID_FILE_STR, $file),
                InvalidArgumentException::INVALID_FILE
            );
        }

        return self::createFromString(file_get_contents($file));
    }
903058
public function loadConfig(string $file): self
    {
        if (file_exists($file) === false) {
            throw new \RuntimeException('No such config file.');
        }
        $data = json_decode(file_get_contents($file), true);
        if ($data === null) {
            throw new \RuntimeException('Invalid config file.');
        }
        return $this->setConfigs($data);
    }
1047321
public static function loadClassFile($file) {
		$before = array_merge(get_declared_classes(), get_declared_interfaces());
		require_once $file;
		$after = array_merge(get_declared_classes(), get_declared_interfaces());

		$diff = array_diff($after, $before);

		#class was maybe already loaded
		if(!$diff) {
			foreach(array_merge(get_declared_classes(), get_declared_interfaces()) as $class) {
				$reflector = new \ReflectionClass($class);
				if($reflector->getFileName() == realpath($file)) {
					$result = $class;
					break;
				}
			}
			if(!isset($result))
				throw new \Exception('File '.$file.' does not contain any class.');
		}
		else
			$result = array_values($diff)[count($diff)-1];

		return $result;
	}
521485
public function instantiateMigration($name)
    {
        if (!$this->isMigrationExists($name)) {
            throw new Exception("Can't find file for migration with name {$name}");
        }

        if (!class_exists($name, false)) {
            require_once "{$this->folder}/{$name}.php";
            if (!class_exists($name, false)) {
                throw new Exception(
                    "File {$this->folder}/{$name}.php has no {$name} class"
                );
            }
        }

        return new $name;
    }
917836
public function up($file)
    {
        if (false === ($contents = file_get_contents($file->getPathName()))) {
            throw new RuntimeException($file->getPathName() . ' is not found.');
        }
        $queries = explode(';', $contents);
        try {
            $dbh = $this->pdo->connection(true);
            $dbh->beginTransaction();
            foreach($queries as $query) {
                $cleanedQuery = trim($query);
                if ('' === $cleanedQuery) {
                    continue;
                }
                $stmt = $dbh->prepare($cleanedQuery);
                $stmt->execute();
            }
            $dbh->commit();
        } catch(\PDOException $e) {
            $dbh->rollBack();
            throw new RuntimeException($e->getMessage() . PHP_EOL . $query);
        }

        $this->copyToAppliedDir($file);
    }
210444
protected function parseConfig($file)
    {
        $namespace = '';
        $directory = '';

        $config = file_get_contents($file);
        switch (pathinfo($file, PATHINFO_EXTENSION)) {
            case 'yml':
            case 'yaml':
                $config = Yaml::parse($config);
                if (isset($config['migrations_namespace'])) {
                    $namespace = $config['migrations_namespace'];
                }
                if (isset($config['migrations_directory'])) {
                    $directory = $config['migrations_directory'];
                }
                break;
            case 'xml':
                $doc = new \DOMDocument();
                $doc->loadXML($config);
                $list = $doc->getElementsByTagName('migrations-namespace');
                if ($list->length) {
                    $namespace = $list->item(0)->nodeValue;
                }
                $list = $doc->getElementsByTagName('migrations-directory');
                if ($list->length) {
                    $directory = $list->item(0)->nodeValue;
                }
                break;
        }

        return [
            'namespace' => $namespace && $namespace[0] == '\\' ? substr($namespace, 1) : $namespace,
            'directory' => $directory,
        ];
    }
581555
public static function createFromFile($file) {
    $jsonConfig = json_decode(file_get_contents($file), true);
    return self::createFromConfig($jsonConfig);
  }
680010
public static function removeFile($file)
    {
        if (!is_readable($file) || !is_file($file)) {
            throw new Exception('No such file: ' . $file);
        }
        $res = unlink($file);
        if (false === $res) {
            throw new Exception('File deleting failure: ' . $file);
        }
        return $res;
    }
73989
public function parse($file = null) {
        if ($file !== null) {
            $this->setFile($file);
        }
        if (empty($this->file)) {
            throw new LogicException("Need a file to parse.");
        }

        $simple_parsed = parse_ini_file($this->file, true);
        $inheritance_parsed = $this->parseSections($simple_parsed);
        return $this->parseKeys($inheritance_parsed);
    }
1169363
public function load($file)
	{
		$handle = strcasecmp(substr($file, -3), '.gz') ? fopen($file, 'rb') : gzopen($file, 'rb');
		if (!$handle) {
			throw new Exception("ERROR: Cannot open file '$file'.");
		}
		return $this->read($handle);
	}
88180
public static function for_file($file)
    {
        if (!$file || (is_string($file) && !file_exists($file))) {
            return null;
        }

        // Ensure we have a File instance to work with
        if (is_string($file)) {
            /** @var File $fileObject */
            $fileObject = File::create();
            $fileObject->setFromLocalFile($file);
            $file = $fileObject;
        }

        $extension = $file->getExtension();
        $mime = $file->getMimeType();

        foreach (self::get_extractor_classes() as $className) {
            $extractor = self::get_extractor($className);

            // Skip unavailable extractors
            if (!$extractor->isAvailable()) {
                continue;
            }

            // Check extension
            if ($extension && $extractor->supportsExtension($extension)) {
                return $extractor;
            }

            // Check mime
            if ($mime && $extractor->supportsMime($mime)) {
                return $extractor;
            }
        }
    }
852008
public static function get(String $file) : stdClass
    {
        $file = self::rpath($file);

        if( ! is_file($file) )
        {
            throw new Exception\FileNotFoundException(NULL, $file);
        }

        return (object)
        [
            'basename'   => self::pathInfo($file, 'basename'),
            'size'       => filesize($file),
            'date'       => filemtime($file),
            'readable'   => is_readable($file),
            'writable'   => is_writable($file),
            'executable' => is_executable($file),
            'permission' => fileperms($file)
        ];
    }
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;
      }
    };
  }