Rollback a given migration.

@param string $file

@throws Exception

@return mixed
331419
public function rollbackMigration($file)
    {
        $migration = $this->getMigrationObjectByFileName($file);

        $this->checkTransactionAndRun($migration, function () use ($migration, $file) {
            if ($migration->down() === false) {
                throw new Exception("<error>Can't rollback migration:</error> {$file}.php");
            }
        });

        $this->removeSuccessfulMigrationFromLog($file);
    }
1089510
public static function setFile($file)
    {
        if (is_file($file)) {
            $options = Yaml::parse(file_get_contents($file));
            self::$instance = new self($options);
            self::$instance->validateOptions();
        } else {
            throw new Exception("Can't find config file at ".$file);
        }
    }
1002244
public static function fromIniFile($file) {
		if (!is_file($file)) {
			throw new Exception("Config file $file not found");
		}
		$conf = parse_ini_file($file, true);
		$all = [];
		$queue = new SplQueue;
		$environments = array_keys($conf);
		foreach ($environments as $one) {
			if (strpos($one, ':') === false) {
				$queue->push($one);
			}
		}
		while ($queue->count() > 0) {
			$it = $queue->pop();
			if (strpos($it, ':') === false) {
				$all[$it] = $conf[$it];
				$child = $it; 
			} else {
				list($child, $parent) = explode(':', $it, 2);
				$child = trim($child);
				$parent = trim($parent);
				$all[$child] = array_merge($all[$parent], $conf[$it]);
			}
			// Add childrens into queue
			foreach ($environments as $one) {
				if (!isset($all[$one]) && strpos($one, ':') !== false) {
					$one_parse = explode(':', $one, 2);
					if ($one_parse[1] === $child) {
						$queue->push($one);
					}
				}
			}
		}
		$result = [];
		//将“.”作为分隔符，分割为多维数组
		foreach ($all as $env => $it) {
			$result[$env] = [];
			foreach ($it as $k => $v) {
				if (strpos($k, '.') === false) {
					$result[$env][$k] = $v;
					continue;
				}
				$keys = explode('.', $k);
				$total = count($keys) - 1;
				$parent = &$result[$env];
				foreach ($keys as $kk => $vv) {
					if ($total === $kk) {
						$parent[$vv] = $v;
					} else {
						if (!isset($parent[$vv])) {
							$parent[$vv] = [];
						}
						$parent = &$parent[$vv];
					}
				}
			}
		}
		return new self($result);
	}
632028
private function findFile($file) {
        $filePath = MODULES_DIR . DS . self::$currentRoute['module'] . DS . 'Views' . DS . $file . '.php';
        if (!file_exists($filePath)) {
            $filePath = BASE_DIR . DS . 'base' . DS . 'views' . DS . $file . '.php';
            if (!file_exists($filePath)) {
                throw new \Exception(_message(ExceptionMessages::VIEW_FILE_NOT_FOUND, $file));
            }
        }

        return $filePath;
    }
650938
private function loadFile(string $file) : string
    {
        if (!file_exists($file)) {
            throw new \Exception($file . ' not found');
        }
        return (string)file_get_contents($file);
    }
11928
public function get($file)
    {
        $basepath = $this->config['basepath'];
        $suffix = $this->config['suffix'];
        $target = "$basepath/$file{$suffix}";

        if (!is_readable($target)) {
            throw new \Exception(t("No such file content: @FILENAME", ["@FILENAME" => $target]));
        }

        $filter  = $this->config['textfilter'];
        $content = file_get_contents($target);
        $content = $this->di->textFilter->doFilter($content, $filter);

        return $content;
    }
201783
public function migrate($version = null)
    {
        $migrations     = $this->getMigrations();
        $versions       = $this->getVersions();
        $currentVersion = $this->getCurrentVersion();

        if (!count($migrations)) {
            throw new \RuntimeException('No migrations found.');
        }

        if ($version === null) {
            $version = max(array_merge($versions, array_keys(iterator_to_array($migrations))));
        } else {
            if ($version != 0 && empty($migrations[$version])) {
                throw new \RuntimeException('Version is not valid.');
            }
        }

        // Prepare SQL logs
        if (is_file($this->getLogFile())) {
            File::delete($this->getLogFile());
        }

        Folder::create(dirname($this->getLogFile()));

        $queryLogStream = new Stream($this->getLogFile(), Stream::MODE_WRITE_ONLY_FROM_END);
        $logListener = function (Event $event) use ($queryLogStream) {
            $queryLogStream->write($event['query'] . ";\n\n");
        };
        Ioc::getDispatcher()->listen('onMigrationAfterQuery', $logListener);

        $direction = ($version > $currentVersion) ? AbstractMigration::UP : AbstractMigration::DOWN;

        $migrations = iterator_to_array($migrations);

        $count = 0;

        try {
            if ($direction === AbstractMigration::DOWN) {
                krsort($migrations);

                foreach ($migrations as $migration) {
                    if ($migration['version'] <= $version) {
                        break;
                    }

                    if (in_array($migration['version'], $versions)) {
                        $this->executeMigration($migration, AbstractMigration::DOWN);
                    }

                    $count++;
                }
            }

            ksort($migrations);

            foreach ($migrations as $migration) {
                if ($migration['version'] > $version) {
                    break;
                }

                if (!in_array($migration['version'], $versions, true)) {
                    $this->executeMigration($migration, AbstractMigration::UP);
                }

                $count++;
            }
        } catch (\PDOException $e) {
            $queryLogStream->write("-- ERROR: {$e->getMessage()}\n" . $this->db->getQuery());

            throw $e;
        }

        Ioc::getDispatcher()->removeListener($logListener);

        if (!$count) {
            $this->out('No change.');
        }
    }
279776
public static function rollback()
    {
        foreach (array_reverse(self::$migrationClasses) as $migrationClass) {
            /** @var Migration $instance */
            $instance = new $migrationClass;
            $instance->rollback();
        }
    }
764668
public function destroy($file)
    {
        $this->manager->resetPath($file);

        if (!$this->manager->blobExists()) {
            return $this->json('File not found.', 404);
        }

        $isRemoved = $this->manager->delete();

        return $this->json($isRemoved, $isRemoved ? 200 : 500);
    }
170240
public static function make($file)
    {
        if (!$file_content = Util::file2array($file)) {
            throw new \Exception("Arquivo: não existe");
        }

        if (!Util::isHeaderRetorno($file_content[0])) {
            throw new \Exception("Arquivo: $file, não é um arquivo de retorno");
        }

        $instancia = self::getBancoClass($file_content);
        return $instancia->processar();
    }
1147268
public function handleSingleFile($file)
    {
        if (!$file instanceof UploadedFile) {
            throw new \Exception("Dados inválidos para upload");
        }

        $document = $this->createDocument($file);

        $this->processBeforeSave($document);

        $disk = Storage::disk()->getDriver();
        $disk->put($document->filePath, fopen($file, 'r+'), [
            'visibility' => 'public',
            'ContentType' => $document->mimeType
        ]);

        $document->url = config('filesystems.default') == 'public' ? asset('images/' . $document->filePath) : Storage::url($document->filePath);
        $document->save();

        $this->addFileToList($document);

        return $document;
    }
154295
public function getAction($file)
    {
        if (!is_dir($this->source_directory) || !isset($this->file_extension, $this->response_type)) {
            throw new Exception("Controller is not configured!");
        }
        $source_file = $this->source_directory . "/" . $file . "." . $this->file_extension;
        if (!is_readable($source_file)) {
            throw new Error404Exception;
        }
        $this->response->setHeader("Content-Type", $this->response_type);
        return $this->view->display($source_file);
    }
178810
protected function runUp($file)
    {
        // First we will resolve a "real" instance of the migration class from this
        // migration file name. Once we have the instances we can run the actual
        // command such as "up" or "down", or we can just simulate the action.
        $migration = $this->resolve($name = $this->getMigrationName($file));

        $this->note("<comment>Migrating:</comment> {$name}");

        // Run migrayion up
        $migration->up();

        // Registrar na lista de executados
        $this->setExecuted($name);

        $this->note("<info>Migrated:</info>  {$name}");
    }
444666
private function openFile($file)
    {
        if (!(is_readable($file) && is_file($file))) {
            $this->throwException('FILE_EXISTS', $file);
        }
        $handle = fopen($file, 'rb');
        if (!$handle) {
            $this->throwException('FILE_OPEN', $file);
        }
        return $handle;
    }
680115
public function resolve($path, $file)
    {
        $migration = "$path/$file.php";

        if ($this->files->exists($migration)) {
            return $this->files->getRequire($migration);
        }
    }
453033
public function get($file)
    {
        $target = $this->path . $file;

        if (!is_readable($target)) {
            throw new \Exception("No such content " . $target);
        }

        return file_get_contents($target);
    }
1266924
public function rollback()
    {
        if ($this->_active && $this->_db->getActive()) {
            $this->_db->getPdoInstance()->rollBack();
            $this->_active = false;
        } else {
            throw new Exception('"Transaction"尚属未激活状态，不能执行"commit"和"rollback"操作', 101300602);
        }
    }