RainLab\Builder\Classes\MigrationModel::assignFileName PHP 메소드

assignFileName() 보호된 메소드

protected assignFileName ( )
    protected function assignFileName()
    {
        $code = trim($this->code);
        if (!strlen($code)) {
            $this->scriptFileName = null;
            return;
        }
        /*
         * The file name is based on the migration class name. 
         */
        $parser = new MigrationFileParser();
        $migrationInfo = $parser->extractMigrationInfoFromSource($code);
        if (!$migrationInfo || !array_key_exists('class', $migrationInfo)) {
            throw new ValidationException(['code' => Lang::get('rainlab.builder::lang.migration.error_file_must_define_class')]);
        }
        if (!array_key_exists('namespace', $migrationInfo)) {
            throw new ValidationException(['code' => Lang::get('rainlab.builder::lang.migration.error_file_must_define_namespace')]);
        }
        $pluginCodeObj = $this->getPluginCodeObj();
        $pluginNamespace = $pluginCodeObj->toUpdatesNamespace();
        if ($migrationInfo['namespace'] != $pluginNamespace) {
            throw new ValidationException(['code' => Lang::get('rainlab.builder::lang.migration.error_namespace_mismatch', ['namespace' => $pluginNamespace])]);
        }
        $this->scriptFileName = Str::snake($migrationInfo['class']);
        /*
         * Validate that a file with the generated name does not exist yet.
         */
        if ($this->scriptFileName != $this->originalScriptFileName) {
            $fileName = $this->scriptFileName . '.php';
            $filePath = $this->getPluginUpdatesPath($fileName);
            if (File::isFile($filePath)) {
                throw new ValidationException(['code' => Lang::get('rainlab.builder::lang.migration.error_migration_file_exists', ['file' => $fileName])]);
            }
        }
    }