src/Command.php
/**
     * Create a new migration for a package
     *
     * ## OPTIONS
     *
     * <slug>
     * : The slug of the package to create a migration for
     *
     * <name>
     * : The name of the migration
     */
Create a new migration for a package
OPTIONS


: The slug of the package to create a migration for


: The name of the migration
Create a new migration for a package OPTIONS : The slug of the package to create a migration for : The name of the migration
public function create($args, $assoc_args)
    {
        list($slug, $name) = $args;
        if (!isset(self::$migrators[$slug])) {
            WP_CLI::error(sprintf('%s is not registered to migrate', $slug));
        }
        $migrator = self::$migrators[$slug];
        $migrations_path = sprintf('%s/migrations', $migrator->getRoot());
        if (!file_exists($migrations_path)) {
            mkdir($migrations_path);
        }
        $name = str_replace('-', '_', $name);
        $filename = sprintf('%s_%s.php', date('YmdHis'), $name);
        $classname = implode('', array_map('ucwords', explode('_', $name)));
        $template = file_get_contents(sprintf('%s/migration_template.txt', __DIR__));
        $template = str_replace('{{class}}', $classname, $template);
        $template = str_replace('{{namespace}}', $migrator->getNamespace(), $template);
        $template = str_replace('{{vendor}}', __NAMESPACE__, $template);
        file_put_contents(sprintf('%s/%s', $migrations_path, $filename), $template);
        WP_CLI::success('Migration file create successfully');
    }
public function create ( $ args , $ assoc_args ) { list ( $ slug , $ name ) = $ args ; if ( ! isset ( self :: $ migrators [ $ slug ] ) ) { WP_CLI :: error ( sprintf ( '%s is not registered to migrate' , $ slug ) ) ; } $ migrator = self :: $ migrators [ $ slug ] ; $ migrations_path = sprintf ( '%s/migrations' , $ migrator -> getRoot ( ) ) ; if ( ! file_exists ( $ migrations_path ) ) { mkdir ( $ migrations_path ) ; } $ name = str_replace ( '-' , '_' , $ name ) ; $ filename = sprintf ( '%s_%s.php' , date ( 'YmdHis' ) , $ name ) ; $ classname = implode ( '' , array_map ( 'ucwords' , explode ( '_' , $ name ) ) ) ; $ template = file_get_contents ( sprintf ( '%s/migration_template.txt' , __DIR__ ) ) ; $ template = str_replace ( '{{class}}' , $ classname , $ template ) ; $ template = str_replace ( '{{namespace}}' , $ migrator -> getNamespace ( ) , $ template ) ; $ template = str_replace ( '{{vendor}}' , __NAMESPACE__ , $ template ) ; file_put_contents ( sprintf ( '%s/%s' , $ migrations_path , $ filename ) , $ template ) ; WP_CLI :: success ( 'Migration file create successfully' ) ; }
Create a new migration for a package
 ## OPTIONS
Create a new migration for a package ## OPTIONS