mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-02 14:25:38 +08:00
rename Instant to ZM
This commit is contained in:
48
src/ZM/ZMApplication.php
Normal file
48
src/ZM/ZMApplication.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ZM;
|
||||
|
||||
use ZM\Command\Server\ServerStartCommand;
|
||||
use ZM\Exception\SingletonViolationException;
|
||||
use ZM\Plugin\ZMPlugin;
|
||||
|
||||
class ZMApplication extends ZMPlugin
|
||||
{
|
||||
/** @var null|ZMApplication 存储单例类的变量 */
|
||||
private static ?ZMApplication $obj;
|
||||
|
||||
/** @var array 存储要传入的args */
|
||||
private array $args = [];
|
||||
|
||||
public function __construct(mixed $dir = null)
|
||||
{
|
||||
if (self::$obj !== null) {
|
||||
throw new SingletonViolationException(self::class);
|
||||
}
|
||||
self::$obj = $this; // 用于标记已经初始化完成
|
||||
parent::__construct($dir ?? (__DIR__ . '/../..'));
|
||||
$this->args = ServerStartCommand::exportOptionArray();
|
||||
}
|
||||
|
||||
public function withConfig(array $config): ZMApplication
|
||||
{
|
||||
// TODO: 完成patch config
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withArgs(array $args): ZMApplication
|
||||
{
|
||||
$this->args = array_replace_recursive($this->args, $args);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
(new Framework($this->args))->init()->start();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user