Files
kiri-core/system/Application.php
T

87 lines
1.4 KiB
PHP
Raw Normal View History

2020-08-31 01:27:08 +08:00
<?php
/**
* Created by PhpStorm.
* User: whwyy
* Date: 2018/4/25 0025
* Time: 18:38
*/
namespace Snowflake;
2020-09-03 00:15:57 +08:00
use Console\ConsoleProviders;
2020-09-02 23:41:29 +08:00
use Database\DatabasesProviders;
2020-08-31 01:27:08 +08:00
use Exception;
2020-09-03 00:15:57 +08:00
use HttpServer\Server;
2020-09-02 23:41:29 +08:00
use HttpServer\ServerProviders;
2020-08-31 01:27:08 +08:00
use Snowflake\Abstracts\BaseApplication;
2020-09-02 18:15:22 +08:00
use Snowflake\Exception\NotFindClassException;
2020-08-31 01:27:08 +08:00
/**
* Class Init
*
2020-08-31 12:38:32 +08:00
* @package Snowflake
2020-08-31 01:27:08 +08:00
*
* @property-read Config $config
*/
class Application extends BaseApplication
{
/**
* @var string
*/
public $id = 'uniqueId';
2020-09-02 23:41:29 +08:00
/**
* @throws NotFindClassException
*/
public function init()
{
2020-09-03 00:15:57 +08:00
$this->import(ConsoleProviders::class);
2020-09-02 23:41:29 +08:00
$this->import(DatabasesProviders::class);
$this->import(ServerProviders::class);
}
2020-08-31 14:02:54 +08:00
/**
2020-09-02 18:15:22 +08:00
* @param string $service
* @return $this
2020-09-02 18:15:39 +08:00
* @throws
2020-08-31 14:02:54 +08:00
*/
2020-09-02 18:15:22 +08:00
public function import(string $service)
2020-08-31 14:02:54 +08:00
{
2020-09-02 18:15:22 +08:00
if (!class_exists($service)) {
throw new NotFindClassException($service);
}
2020-09-02 18:22:16 +08:00
$class = Snowflake::createObject($service);
2020-08-31 14:02:54 +08:00
if (method_exists($class, 'onImport')) {
$class->onImport($this);
}
return $this;
}
2020-08-31 01:27:08 +08:00
/**
2020-08-31 14:07:20 +08:00
* @throws
2020-08-31 01:27:08 +08:00
*/
public function start()
{
2020-09-03 00:15:57 +08:00
/** @var Server $manager */
$manager = Snowflake::get()->get('server');
$manager->start();
2020-08-31 01:27:08 +08:00
}
/**
* @param $className
* @param null $abstracts
* @return mixed
* @throws Exception
*/
public function make($className, $abstracts = null)
{
2020-08-31 12:38:32 +08:00
return make($className, $abstracts);
2020-08-31 01:27:08 +08:00
}
}