Skip to content

Commit

Permalink
Merge pull request #36 from Jagepard/wip
Browse files Browse the repository at this point in the history
Wip
  • Loading branch information
Jagepard committed Feb 23, 2022
2 parents 670625d + 6dc590f commit 9208088
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 16 deletions.
3 changes: 2 additions & 1 deletion app/Ship/Commands/CreateMigrationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ public function up()
`id` INT NOT NULL AUTO_INCREMENT ,
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ,
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
, PRIMARY KEY (`id`)) ENGINE = InnoDB
PRIMARY KEY (`id`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci
");
\$query->execute();
Expand Down
57 changes: 45 additions & 12 deletions app/Ship/Commands/CreateSeedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ public function actionIndex()
Cli::printer("Enter container (empty for Ship): ", "magneta");
$container = ucfirst(str_replace(PHP_EOL, "", Cli::reader()));

Cli::printer("multiline Seed (yes): ", "magneta");
$multiline = ucfirst(str_replace(PHP_EOL, "", Cli::reader()));
$multiline = empty($multiline);

if (!empty($container)) {

$namespace = 'App\Containers\\' . $container . '\Seeds';

$this->writeFile(
[str_replace('/', DIRECTORY_SEPARATOR, Rudra::config()->get('app.path') . "/app/Containers/$container/Seeds/"), "{$className}_seed.php"],
$this->createClass($className, $table, $namespace)
$this->createClass($className, $table, $namespace, $multiline)
);


Expand All @@ -38,23 +42,51 @@ public function actionIndex()

$this->writeFile(
[str_replace('/', DIRECTORY_SEPARATOR, Rudra::config()->get('app.path') . "/app/Ship/Seeds/"), "{$className}_seed.php"],
$this->createClass($className, $table, $namespace)
$this->createClass($className, $table, $namespace, $multiline)
);
}
}

/**
* @param string $className
* @param string $table
* @return string
*
* Creates class data
* ------------------
* Создает данные класса
*/
private function createClass(string $className, string $table, string $namespace)
private function createClass(string $className, string $table, string $namespace, bool $multiline = false)
{
return <<<EOT
if ($multiline) {
return <<<EOT
<?php
namespace {$namespace};
use App\Ship\Seeds\AbstractSeed;
class {$className}_seed extends AbstractSeed
{
public function create()
{
\$table = "$table";
\$fieldsArray = [
[
"created_at" => date('Y-m-d H:i:s'),
"updated_at" => date('Y-m-d H:i:s'),
],
[
"created_at" => date('Y-m-d H:i:s'),
"updated_at" => date('Y-m-d H:i:s'),
],
];
foreach (\$fieldsArray as \$fields) {
\$this->execute(\$table, \$fields);
}
}
}
EOT;
} else {
return <<<EOT
<?php
namespace {$namespace};
Expand All @@ -67,19 +99,20 @@ public function create()
{
\$table = "$table";
\$fields = [
"created_at" => date('Y-m-d H:i:s'),
"updated_at" => date('Y-m-d H:i:s'),
];
\$this->execute(\$table, \$fields);
}
}
EOT;
}


}

/**
* @param $path
* @param $callable
*
* Writes data to a file
* ---------------------
* Записывает данные в файл
Expand Down
4 changes: 2 additions & 2 deletions app/Ship/Config/local.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
Route::class => Route::class,
Redirect::class => Redirect::class,
// "DSN" => new \PDO('pgsql:host=127.0.0.1;port=5432;dbname=rudra_postgres;', 'jagepard', 'password'),
// "DSN" => new \PDO('mysql:dbname=rudra_mysql;host=127.0.0.1', 'jagepard', 'password'),
"DSN" => new PDO('sqlite:/home/d/custom_projects/php/rudra/Rudra-Framework/app/Ship/Data/rudra.sqlite'),
"DSN" => new \PDO('mysql:dbname=rudra_mysql;host=127.0.0.1', 'jagepard', 'password'),
// "DSN" => new PDO('sqlite:/home/d/custom_projects/php/rudra/Rudra-Framework/app/Ship/Data/rudra.sqlite'),

"debugbar" => new StandardDebugBar()
]
Expand Down
2 changes: 1 addition & 1 deletion app/Ship/Seeds/AbstractSeed.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Db;
namespace App\Ship\Seeds;

use Rudra\Container\Facades\Request;
use Rudra\Container\Facades\Rudra;
Expand Down

0 comments on commit 9208088

Please sign in to comment.