Skip to content

Commit

Permalink
add new class Engineer/Factory/SettingUp
Browse files Browse the repository at this point in the history
  • Loading branch information
amirfaramarzi committed Aug 21, 2021
1 parent eb7d0a1 commit 5c7f8aa
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/Engineer/Factory/SettingUp.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

namespace Tower\Engineer\Factory;

use Database\Factory;
use Dotenv\Dotenv;
use Illuminate\Database\Capsule\Manager as Capsule;
use Tower\Console\Color;
use Tower\Elastic;
use Workerman\Worker;

class SettingUp
{
public function run(array $arguments): void
{
$dotenv = Dotenv::createImmutable(basePath());
$dotenv->load();

$worker = new Worker();

$worker->name = 'factory';

$worker->onWorkerStart = function (){
Elastic::setInstance();

$this->setDatabase();

$time = microtime(true);

(new Factory())->run();

$time = microtime(true) - $time;

echo Color::LIGHT_WHITE . '--------------------------------------------------------------------------------------' . PHP_EOL;
echo Color::success("the operation done successfully ($time ms)");
echo Color::LIGHT_WHITE . 'please press CTRL+C to exit' . PHP_EOL;
};

Worker::runAll();
}

protected function setDatabase(): void
{
$config = include configPath() . "database.php";

$capsule = new Capsule();

$capsule->addConnection($config['mysql']);

$capsule->setAsGlobal();
}
}

0 comments on commit 5c7f8aa

Please sign in to comment.