-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new class Engineer/Factory/SettingUp
- Loading branch information
1 parent
eb7d0a1
commit 5c7f8aa
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |