diff --git a/app/Commands/Foundation/Factories/FactoryMakeCommand.php b/app/Commands/Foundation/Factories/FactoryMakeCommand.php new file mode 100644 index 0000000..5d18a92 --- /dev/null +++ b/app/Commands/Foundation/Factories/FactoryMakeCommand.php @@ -0,0 +1,87 @@ +option('model') + ? $this->qualifyClass($this->option('model')) + : 'Model'; + + return str_replace( + 'DummyModel', + $model, + parent::buildClass($name) + ); + } + + /** + * Get the destination class path. + * + * @param string $name + * @return string + */ + protected function getPath($name) + { + $name = Str::replaceFirst($this->rootNamespace(), '', $name); + $path = getcwd() . $this->devPath() . '/src/'; + return $path . '/database/factories/' . str_replace('\\', '/', $name) . '.php'; + } + + /** + * Get the console command options. + * + * @return array + */ + protected function getOptions() + { + return [ + ['model', 'm', InputOption::VALUE_OPTIONAL, 'The name of the model'], + ]; + } +} diff --git a/app/Commands/Foundation/Factories/stubs/factory.stub b/app/Commands/Foundation/Factories/stubs/factory.stub new file mode 100644 index 0000000..9e3f90b --- /dev/null +++ b/app/Commands/Foundation/Factories/stubs/factory.stub @@ -0,0 +1,9 @@ +define(DummyModel::class, function (Faker $faker) { + return [ + // + ]; +}); diff --git a/app/Commands/Foundation/Migrations/MigrateMakeCommand.php b/app/Commands/Foundation/Migrations/MigrateMakeCommand.php new file mode 100644 index 0000000..797e52c --- /dev/null +++ b/app/Commands/Foundation/Migrations/MigrateMakeCommand.php @@ -0,0 +1,153 @@ +creator = $creator; + $this->composer = $composer; + } + + /** + * Execute the console command. + * + * @return void + */ + public function handle() + { + // It's possible for the developer to specify the tables to modify in this + // schema operation. The developer may also specify if this table needs + // to be freshly created so we can create the appropriate migrations. + $name = Str::snake(trim($this->input->getArgument('name'))); + + $table = $this->input->getOption('table'); + + $create = $this->input->getOption('create') ?: false; + + // If no table was given as an option but a create option is given then we + // will use the "create" option as the table name. This allows the devs + // to pass a table name into this option as a short-cut for creating. + if (!$table && is_string($create)) { + $table = $create; + + $create = true; + } + + // Next, we will attempt to guess the table name if this the migration has + // "create" in the name. This will allow us to provide a convenient way + // of creating migrations that create new tables for the application. + if (!$table) { + [$table, $create] = TableGuesser::guess($name); + } + + // Now we are ready to write the migration out to disk. Once we've written + // the migration out, we will dump-autoload for the entire framework to + // make sure that the migrations are registered by the class loaders. + $this->writeMigration($name, $table, $create); + + $this->composer->dumpAutoloads(); + } + + /** + * Write the migration file to disk. + * + * @param string $name + * @param string $table + * @param bool $create + * @return string + */ + protected function writeMigration($name, $table, $create) + { + $file = pathinfo($this->creator->create( + $name, + $this->getMigrationPath(), + $table, + $create + ), PATHINFO_FILENAME); + + $this->line("Created Migration: {$file}"); + } + + /** + * Get migration path (either specified by '--path' option or default location). + * + * @return string + */ + protected function getMigrationPath() + { + if (!is_null($targetPath = $this->input->getOption('path'))) { + return !$this->usingRealPath() + ? $this->laravel->basePath() . '/' . $targetPath + : $targetPath; + } + + return parent::getMigrationPath(); + } + + /** + * Determine if the given path(s) are pre-resolved "real" paths. + * + * @return bool + */ + protected function usingRealPath() + { + return $this->input->hasOption('realpath') && $this->option('realpath'); + } + + /** + * Get the path to the stubs. + * + * @return string + */ + public function stubPath() + { + return __DIR__ . '/stubs'; + } +} diff --git a/app/Commands/Foundation/Migrations/MigrationCreator.php b/app/Commands/Foundation/Migrations/MigrationCreator.php new file mode 100644 index 0000000..389a965 --- /dev/null +++ b/app/Commands/Foundation/Migrations/MigrationCreator.php @@ -0,0 +1,27 @@ +devPath() . '/src/database/migrations'; + if (!$this->files->isDirectory($path)) { + $this->files->makeDirectory($path); + } + return $path . '/' . $this->getDatePrefix() . '_' . $name . '.php'; + } +} diff --git a/app/Commands/Foundation/Migrations/TableGuesser.php b/app/Commands/Foundation/Migrations/TableGuesser.php new file mode 100644 index 0000000..7c14cbb --- /dev/null +++ b/app/Commands/Foundation/Migrations/TableGuesser.php @@ -0,0 +1,23 @@ +increments('id'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('DummyTable'); + } +} diff --git a/app/Commands/Foundation/Migrations/stubs/update.stub b/app/Commands/Foundation/Migrations/stubs/update.stub new file mode 100755 index 0000000..1fd4f6e --- /dev/null +++ b/app/Commands/Foundation/Migrations/stubs/update.stub @@ -0,0 +1,32 @@ +environment() == 'development' ? '/package/liker' : ''; + $dev_path = app()->environment() == 'development' ? '/package/tester' : ''; $path = getcwd() . $dev_path . '/composer.json'; return json_decode(file_get_contents($path)); } diff --git a/builds/packer b/builds/packer index 9151e0e..8a41f33 100755 Binary files a/builds/packer and b/builds/packer differ diff --git a/builds/packer.phar b/builds/packer.phar index 1bcefe3..9cbfcd2 100755 Binary files a/builds/packer.phar and b/builds/packer.phar differ diff --git a/composer.json b/composer.json index da0528e..342ac2a 100644 --- a/composer.json +++ b/composer.json @@ -14,6 +14,7 @@ }], "require": { "php": "^7.1.3", + "illuminate/database": "5.7.*", "laravel-zero/framework": "5.7.*" }, "require-dev": { @@ -32,9 +33,17 @@ }, "minimum-stability": "dev", "config": { - "preferred-install": { - "*": "dist" + "preferred-install": "dist", + "sort-packages": true, + "optimize-autoloader": true, + "platform": { + "ext-posix": "0" } }, + "scripts": { + "post-create-project-cmd": [ + "@php application app:rename" + ] + }, "bin": ["builds/packer"] } diff --git a/composer.lock b/composer.lock index 88c4256..3f4f46a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9c198fdfc20bd4960f3226fa92dfaf0a", + "content-hash": "46138b092196b9065da848e81af70c42", "packages": [ { "name": "beberlei/assert", @@ -470,6 +470,65 @@ "homepage": "https://laravel.com", "time": "2018-10-08T13:34:14+00:00" }, + { + "name": "illuminate/database", + "version": "5.7.x-dev", + "source": { + "type": "git", + "url": "https://github.com/illuminate/database.git", + "reference": "1f4a0881ca0012732ae7b73809cf50ef8d964547" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/illuminate/database/zipball/1f4a0881ca0012732ae7b73809cf50ef8d964547", + "reference": "1f4a0881ca0012732ae7b73809cf50ef8d964547", + "shasum": "" + }, + "require": { + "illuminate/container": "5.7.*", + "illuminate/contracts": "5.7.*", + "illuminate/support": "5.7.*", + "php": "^7.1.3" + }, + "suggest": { + "doctrine/dbal": "Required to rename columns and drop SQLite columns (^2.6).", + "fzaninotto/faker": "Required to use the eloquent factory builder (^1.4).", + "illuminate/console": "Required to use the database commands (5.7.*).", + "illuminate/events": "Required to use the observers with Eloquent (5.7.*).", + "illuminate/filesystem": "Required to use the migrations (5.7.*).", + "illuminate/pagination": "Required to paginate the result set (5.7.*)." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.7-dev" + } + }, + "autoload": { + "psr-4": { + "Illuminate\\Database\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "The Illuminate Database package.", + "homepage": "https://laravel.com", + "keywords": [ + "database", + "laravel", + "orm", + "sql" + ], + "time": "2018-10-06T18:48:42+00:00" + }, { "name": "illuminate/events", "version": "5.7.x-dev", @@ -2726,12 +2785,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "050bedf145a257b1ff02746c31894800e5122946" + "reference": "2da97ea973af95b5ccef2d5bae0f4a976f3923a0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/050bedf145a257b1ff02746c31894800e5122946", - "reference": "050bedf145a257b1ff02746c31894800e5122946", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/2da97ea973af95b5ccef2d5bae0f4a976f3923a0", + "reference": "2da97ea973af95b5ccef2d5bae0f4a976f3923a0", "shasum": "" }, "require": { @@ -2768,7 +2827,7 @@ "filesystem", "iterator" ], - "time": "2018-09-13T20:33:42+00:00" + "time": "2018-10-10T04:54:51+00:00" }, { "name": "phpunit/php-text-template", @@ -2915,12 +2974,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "abd6dba233d88b81e04291df41c99ae4e6cd9410" + "reference": "2e5304d8a5e54ef30da723de126d36992477c094" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/abd6dba233d88b81e04291df41c99ae4e6cd9410", - "reference": "abd6dba233d88b81e04291df41c99ae4e6cd9410", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/2e5304d8a5e54ef30da723de126d36992477c094", + "reference": "2e5304d8a5e54ef30da723de126d36992477c094", "shasum": "" }, "require": { @@ -2991,7 +3050,7 @@ "testing", "xunit" ], - "time": "2018-10-05T14:00:01+00:00" + "time": "2018-10-10T04:55:27+00:00" }, { "name": "sebastian/code-unit-reverse-lookup", @@ -3655,5 +3714,8 @@ "platform": { "php": "^7.1.3" }, - "platform-dev": [] + "platform-dev": [], + "platform-overrides": { + "ext-posix": "0" + } } diff --git a/config/commands.php b/config/commands.php index 1f7f081..6655e77 100644 --- a/config/commands.php +++ b/config/commands.php @@ -95,6 +95,11 @@ */ 'remove' => [ - // .. + Illuminate\Database\Console\Migrations\FreshCommand::class, + Illuminate\Database\Console\Migrations\RefreshCommand::class, + Illuminate\Database\Console\Migrations\InstallCommand::class, + Illuminate\Database\Console\Migrations\ResetCommand::class, + Illuminate\Database\Console\Migrations\RollbackCommand::class, + Illuminate\Database\Console\Migrations\StatusCommand::class, ], ]; diff --git a/config/database.php b/config/database.php new file mode 100644 index 0000000..37b227e --- /dev/null +++ b/config/database.php @@ -0,0 +1,127 @@ + env('DB_CONNECTION', 'sqlite'), + + /* + |-------------------------------------------------------------------------- + | Database Connections + |-------------------------------------------------------------------------- + | + | Here are each of the database connections setup for your application. + | Of course, examples of configuring each database platform that is + | supported by Laravel is shown below to make development simple. + | + | + | All database work in Laravel is done through the PHP PDO facilities + | so make sure you have the driver for your particular database of + | choice installed on your machine before you begin development. + | + */ + + 'connections' => [ + + 'sqlite' => [ + 'driver' => 'sqlite', + 'database' => env('DB_DATABASE', database_path('database.sqlite')), + 'prefix' => '', + ], + + 'mysql' => [ + 'driver' => 'mysql', + 'host' => env('DB_HOST', '127.0.0.1'), + 'port' => env('DB_PORT', '3306'), + 'database' => env('DB_DATABASE', 'forge'), + 'username' => env('DB_USERNAME', 'forge'), + 'password' => env('DB_PASSWORD', ''), + 'unix_socket' => env('DB_SOCKET', ''), + 'charset' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'prefix' => '', + 'strict' => true, + 'engine' => null, + ], + + 'pgsql' => [ + 'driver' => 'pgsql', + 'host' => env('DB_HOST', '127.0.0.1'), + 'port' => env('DB_PORT', '5432'), + 'database' => env('DB_DATABASE', 'forge'), + 'username' => env('DB_USERNAME', 'forge'), + 'password' => env('DB_PASSWORD', ''), + 'charset' => 'utf8', + 'prefix' => '', + 'schema' => 'public', + 'sslmode' => 'prefer', + ], + + 'sqlsrv' => [ + 'driver' => 'sqlsrv', + 'host' => env('DB_HOST', 'localhost'), + 'port' => env('DB_PORT', '1433'), + 'database' => env('DB_DATABASE', 'forge'), + 'username' => env('DB_USERNAME', 'forge'), + 'password' => env('DB_PASSWORD', ''), + 'charset' => 'utf8', + 'prefix' => '', + ], + + ], + + /* + |-------------------------------------------------------------------------- + | Migration Repository Table + |-------------------------------------------------------------------------- + | + | This table keeps track of all the migrations that have already run for + | your application. Using this information, we can determine which of + | the migrations on disk haven't actually been run in the database. + | + */ + + 'migrations' => 'migrations', + + /* + |-------------------------------------------------------------------------- + | Redis Databases + |-------------------------------------------------------------------------- + | + | Redis is an open source, fast, and advanced key-value store that also + | provides a richer set of commands than a typical key-value systems + | such as APC or Memcached. Laravel makes it easy to dig right in. + | + */ + + 'redis' => [ + + 'client' => 'predis', + + 'default' => [ + 'host' => env('REDIS_HOST', '127.0.0.1'), + 'password' => env('REDIS_PASSWORD', null), + 'port' => env('REDIS_PORT', 6379), + 'database' => env('REDIS_DB', 0), + ], + + 'cache' => [ + 'host' => env('REDIS_HOST', '127.0.0.1'), + 'password' => env('REDIS_PASSWORD', null), + 'port' => env('REDIS_PORT', 6379), + 'database' => env('REDIS_CACHE_DB', 1), + ], + + ], + +];