<commit_before><?php
/*
 * This file is part of the ************************ package.
 * ##########################################################
 * #   ____                          ______  _   _ ______   #
 * #  /     \       ___  _ __  _   _ | ___ \| | | || ___ \  #
 * # |   (  ||(_)| / _ \| '__|| | | || |_/ /| |_| || |_/ /  #
 * #  \____/ |___||  __/| |   | |_| ||  __/ |  _  ||  __/   #
 * #       \__   | \___ |_|    \__  || |    | | | || |      #
 * #     Query Yet Simple      __/  |\_|    |_| |_|\_|      #
 * #                          |___ /  Since 2010.10.03      #
 * ##########################################################
 *
 * The PHP Framework For Code Poem As Free As Wind. <Query Yet Simple>
 * (c) 2010-2018 http://queryphp.com All rights reserved.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace Queryyetsimple\Database\Console;

use RuntimeException;
use InvalidArgumentException;
use Phinx\Console\Command\Init as PhinxInit;
use Symfony\Component\Console\{
    Input\InputInterface,
    Output\OutputInterface
};

/**
 * 数据库迁移初始化
 *
 * @author <NAME> <<EMAIL>>
 * @package $$
 * @since 2017.05.09
 * @version 1.0
 */
class Init extends PhinxInit
{

    /**
     * Configures the current command.
     *
     * @return void
     */
    protected function configure()
    {
        parent::configure();
        $this->setName('migrate:init');
    }

    /**
     * Initializes the application.
     * 重写读取配置文件，个性化配置，例外默认配置文件有一个解析 BUG
     *
     * @param InputInterface $input
     * @param OutputInterface $output
     * @throws RuntimeException
     * @throws InvalidArgumentException
     * @return void
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        // get the migration path from the config
        $path = $input->getArgument('path');

        if (null === $path) {
            $path = getcwd();
        }

        $path = realpath($path);

        if (! is_writable($path)) {
            throw new InvalidArgumentException(sprintf('The directory "%s" is not writable', $path));
        }

        // Compute the file path
        // TODO - maybe in the future we allow custom config names.
        $fileName = 'phinx.yml'; 
        $filePath = $path . DIRECTORY_SEPARATOR . $fileName;

        if (file_exists($filePath)) {
            throw new InvalidArgumentException(sprintf('The file "%s" already exists', $filePath));
        }

        // load the config template
        // 自定义 migrate.yml 文件
        $contents = file_get_contents(__DIR__ . '/yml/migrate.yml');

        if (false === file_put_contents($filePath, $contents)) {
            throw new RuntimeException(sprintf('The file "%s" could not be written to', $path));
        }

        chmod($filePath, 0777);

        $output->writeln('<info>created</info> .' . str_replace(getcwd(), '', $filePath));<commit_msg>the command line file generation tool and database migration initailization configuration do not need to set permissions to 0777<commit_after><?php
/*
 * This file is part of the ************************ package.
 * ##########################################################
 * #   ____                          ______  _   _ ______   #
 * #  /     \       ___  _ __  _   _ | ___ \| | | || ___ \  #
 * # |   (  ||(_)| / _ \| '__|| | | || |_/ /| |_| || |_/ /  #
 * #  \____/ |___||  __/| |   | |_| ||  __/ |  _  ||  __/   #
 * #       \__   | \___ |_|    \__  || |    | | | || |      #
 * #     Query Yet Simple      __/  |\_|    |_| |_|\_|      #
 * #                          |___ /  Since 2010.10.03      #
 * ##########################################################
 *
 * The PHP Framework For Code Poem As Free As Wind. <Query Yet Simple>
 * (c) 2010-2018 http://queryphp.com All rights reserved.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
namespace Queryyetsimple\Database\Console;

use RuntimeException;
use InvalidArgumentException;
use Phinx\Console\Command\Init as PhinxInit;
use Symfony\Component\Console\{
    Input\InputInterface,
    Output\OutputInterface
};

/**
 * 数据库迁移初始化
 *
 * @author <NAME> <<EMAIL>>
 * @package $$
 * @since 2017.05.09
 * @version 1.0
 */
class Init extends PhinxInit
{

    /**
     * Configures the current command.
     *
     * @return void
     */
    protected function configure()
    {
        parent::configure();
        $this->setName('migrate:init');
    }

    /**
     * Initializes the application.
     * 重写读取配置文件，个性化配置，例外默认配置文件有一个解析 BUG
     *
     * @param InputInterface $input
     * @param OutputInterface $output
     * @throws RuntimeException
     * @throws InvalidArgumentException
     * @return void
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        // get the migration path from the config
        $path = $input->getArgument('path');

        if (null === $path) {
            $path = getcwd();
        }

        $path = realpath($path);

        if (! is_writable($path)) {
            throw new InvalidArgumentException(sprintf('The directory "%s" is not writable', $path));
        }

        // Compute the file path
        // TODO - maybe in the future we allow custom config names.
        $fileName = 'phinx.yml'; 
        $filePath = $path . DIRECTORY_SEPARATOR . $fileName;

        if (file_exists($filePath)) {
            throw new InvalidArgumentException(sprintf('The file "%s" already exists', $filePath));
        }

        // load the config template
        // 自定义 migrate.yml 文件
        $contents = file_get_contents(__DIR__ . '/yml/migrate.yml');

        if (false === file_put_contents($filePath, $contents)) {
            throw new RuntimeException(sprintf('The file "%s" could not be written to', $path));
        }

        $output->writeln('<info>created</info> .' . str_replace(getcwd(), '', $filePath));
{'fraction_non_alphanumeric': 0.17820299500831946, 'fraction_numerical': 0.009983361064891847, 'mean_word_length': 2.2110042735042734, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2045862', 'n_tokens_mistral': 1870, 'n_tokens_neox': 1784, 'n_words': 413}