Skip to content

Commit

Permalink
Merge 71c430d into d3904e5
Browse files Browse the repository at this point in the history
  • Loading branch information
big-dream committed Apr 16, 2024
2 parents d3904e5 + 71c430d commit 0165c2b
Show file tree
Hide file tree
Showing 90 changed files with 859 additions and 859 deletions.
250 changes: 125 additions & 125 deletions src/lang/zh-cn.php

Large diffs are not rendered by default.

56 changes: 28 additions & 28 deletions src/think/App.php
Expand Up @@ -134,28 +134,28 @@ class App extends Container
* @var array
*/
protected $bind = [
'app' => App::class,
'cache' => Cache::class,
'config' => Config::class,
'console' => Console::class,
'cookie' => Cookie::class,
'db' => Db::class,
'env' => Env::class,
'event' => Event::class,
'http' => Http::class,
'lang' => Lang::class,
'log' => Log::class,
'middleware' => Middleware::class,
'request' => Request::class,
'response' => Response::class,
'route' => Route::class,
'session' => Session::class,
'validate' => Validate::class,
'view' => View::class,
'filesystem' => Filesystem::class,
'think\DbManager' => Db::class,
'think\LogManager' => Log::class,
'think\CacheManager' => Cache::class,
'app' => App::class,
'cache' => Cache::class,
'config' => Config::class,
'console' => Console::class,
'cookie' => Cookie::class,
'db' => Db::class,
'env' => Env::class,
'event' => Event::class,
'http' => Http::class,
'lang' => Lang::class,
'log' => Log::class,
'middleware' => Middleware::class,
'request' => Request::class,
'response' => Response::class,
'route' => Route::class,
'session' => Session::class,
'validate' => Validate::class,
'view' => View::class,
'filesystem' => Filesystem::class,
'think\DbManager' => Db::class,
'think\LogManager' => Log::class,
'think\CacheManager' => Cache::class,

// 接口依赖注入
'Psr\Log\LoggerInterface' => Log::class,
Expand All @@ -168,9 +168,9 @@ class App extends Container
*/
public function __construct(string $rootPath = '')
{
$this->thinkPath = realpath(dirname(__DIR__)) . DIRECTORY_SEPARATOR;
$this->rootPath = $rootPath ? rtrim($rootPath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR : $this->getDefaultRootPath();
$this->appPath = $this->rootPath . 'app' . DIRECTORY_SEPARATOR;
$this->thinkPath = realpath(dirname(__DIR__)) . DIRECTORY_SEPARATOR;
$this->rootPath = $rootPath ? rtrim($rootPath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR : $this->getDefaultRootPath();
$this->appPath = $this->rootPath . 'app' . DIRECTORY_SEPARATOR;
$this->runtimePath = $this->rootPath . 'runtime' . DIRECTORY_SEPARATOR;

if (is_file($this->appPath . 'provider.php')) {
Expand Down Expand Up @@ -439,7 +439,7 @@ public function initialize()
$this->initialized = true;

$this->beginTime = microtime(true);
$this->beginMem = memory_get_usage();
$this->beginMem = memory_get_usage();

$this->loadEnv($this->envName);

Expand Down Expand Up @@ -592,10 +592,10 @@ public function loadEvent(array $event): void
*/
public function parseClass(string $layer, string $name): string
{
$name = str_replace(['/', '.'], '\\', $name);
$name = str_replace(['/', '.'], '\\', $name);
$array = explode('\\', $name);
$class = Str::studly(array_pop($array));
$path = $array ? implode('\\', $array) . '\\' : '';
$path = $array ? implode('\\', $array) . '\\' : '';

return $this->namespace . '\\' . $layer . '\\' . $path . $class;
}
Expand Down
10 changes: 5 additions & 5 deletions src/think/Config.php
Expand Up @@ -43,13 +43,13 @@ class Config
public function __construct(string $path = null, string $ext = '.php')
{
$this->path = $path ?: '';
$this->ext = $ext;
$this->ext = $ext;
}

public static function __make(App $app)
{
$path = $app->getConfigPath();
$ext = $app->getConfigExt();
$ext = $app->getConfigExt();

return new static($path, $ext);
}
Expand Down Expand Up @@ -85,7 +85,7 @@ public function load(string $file, string $name = ''): array
*/
protected function parse(string $file, string $name): array
{
$type = pathinfo($file, PATHINFO_EXTENSION);
$type = pathinfo($file, PATHINFO_EXTENSION);
$config = [];
switch ($type) {
case 'php':
Expand Down Expand Up @@ -154,9 +154,9 @@ public function get(string $name = null, $default = null)
return $this->pull($name);
}

$name = explode('.', $name);
$name = explode('.', $name);
$name[0] = strtolower($name[0]);
$config = $this->config;
$config = $this->config;

// 按.拆分成多维数组进行判断
foreach ($name as $val) {
Expand Down
64 changes: 32 additions & 32 deletions src/think/Console.php
Expand Up @@ -55,30 +55,30 @@ class Console
protected $wantHelps = false;

protected $catchExceptions = true;
protected $autoExit = true;
protected $autoExit = true;
protected $definition;
protected $defaultCommand = 'list';
protected $defaultCommand = 'list';

protected $defaultCommands = [
'help' => Help::class,
'list' => Lists::class,
'clear' => Clear::class,
'make:command' => MakeCommand::class,
'make:controller' => Controller::class,
'make:model' => Model::class,
'make:middleware' => Middleware::class,
'make:validate' => Validate::class,
'make:event' => Event::class,
'make:listener' => Listener::class,
'make:service' => Service::class,
'make:subscribe' => Subscribe::class,
'optimize:route' => Route::class,
'optimize:schema' => Schema::class,
'run' => RunServer::class,
'version' => Version::class,
'route:list' => RouteList::class,
'help' => Help::class,
'list' => Lists::class,
'clear' => Clear::class,
'make:command' => MakeCommand::class,
'make:controller' => Controller::class,
'make:model' => Model::class,
'make:middleware' => Middleware::class,
'make:validate' => Validate::class,
'make:event' => Event::class,
'make:listener' => Listener::class,
'make:service' => Service::class,
'make:subscribe' => Subscribe::class,
'optimize:route' => Route::class,
'optimize:schema' => Schema::class,
'run' => RunServer::class,
'version' => Version::class,
'route:list' => RouteList::class,
'service:discover' => ServiceDiscover::class,
'vendor:publish' => VendorPublish::class,
'vendor:publish' => VendorPublish::class,
];

/**
Expand Down Expand Up @@ -126,19 +126,19 @@ protected function makeRequest()
if (isset($components['path'])) {
$server = array_merge($server, [
'SCRIPT_FILENAME' => $components['path'],
'SCRIPT_NAME' => $components['path'],
'REQUEST_URI' => $components['path'],
'SCRIPT_NAME' => $components['path'],
'REQUEST_URI' => $components['path'],
]);
}

if (isset($components['host'])) {
$server['SERVER_NAME'] = $components['host'];
$server['HTTP_HOST'] = $components['host'];
$server['HTTP_HOST'] = $components['host'];
}

if (isset($components['scheme'])) {
if ('https' === $components['scheme']) {
$server['HTTPS'] = 'on';
$server['HTTPS'] = 'on';
$server['SERVER_PORT'] = 443;
} else {
unset($server['HTTPS']);
Expand Down Expand Up @@ -223,7 +223,7 @@ public function call(string $command, array $parameters = [], string $driver = '
{
array_unshift($parameters, $command);

$input = new Input($parameters);
$input = new Input($parameters);
$output = new Output($driver);

$this->setCatchExceptions(false);
Expand All @@ -241,7 +241,7 @@ public function call(string $command, array $parameters = [], string $driver = '
*/
public function run()
{
$input = new Input();
$input = new Input();
$output = new Output();

$this->configureIO($input, $output);
Expand Down Expand Up @@ -296,15 +296,15 @@ public function doRun(Input $input, Output $output)

if (true === $input->hasParameterOption(['--help', '-h'])) {
if (!$name) {
$name = 'help';
$name = 'help';
$input = new Input(['help']);
} else {
$this->wantHelps = true;
}
}

if (!$name) {
$name = $this->defaultCommand;
$name = $this->defaultCommand;
$input = new Input([$this->defaultCommand]);
}

Expand Down Expand Up @@ -513,10 +513,10 @@ public function getNamespaces(): array
public function findNamespace(string $namespace): string
{
$allNamespaces = $this->getNamespaces();
$expr = preg_replace_callback('{([^:]+|)}', function ($matches) {
$expr = preg_replace_callback('{([^:]+|)}', function ($matches) {
return preg_quote($matches[1]) . '[^:]*';
}, $namespace);
$namespaces = preg_grep('{^' . $expr . '}', $allNamespaces);
$namespaces = preg_grep('{^' . $expr . '}', $allNamespaces);

if (empty($namespaces)) {
$message = sprintf('There are no commands defined in the "%s" namespace.', $namespace);
Expand Down Expand Up @@ -719,7 +719,7 @@ public function extractNamespace(string $name, int $limit = 0): string
*/
private function findAlternatives(string $name, $collection): array
{
$threshold = 1e3;
$threshold = 1e3;
$alternatives = [];

$collectionParts = [];
Expand Down Expand Up @@ -769,7 +769,7 @@ private function findAlternatives(string $name, $collection): array
*/
private function extractAllNamespaces(string $name): array
{
$parts = explode(':', $name, -1);
$parts = explode(':', $name, -1);
$namespaces = [];

foreach ($parts as $part) {
Expand Down
10 changes: 5 additions & 5 deletions src/think/Container.php
Expand Up @@ -381,7 +381,7 @@ public function invokeClass(string $class, array $vars = [])
if ($reflect->hasMethod('__make')) {
$method = $reflect->getMethod('__make');
if ($method->isPublic() && $method->isStatic()) {
$args = $this->bindParams($method, $vars);
$args = $this->bindParams($method, $vars);
$object = $method->invokeArgs(null, $args);
$this->invokeAfter($class, $object);
return $object;
Expand Down Expand Up @@ -436,13 +436,13 @@ protected function bindParams(ReflectionFunctionAbstract $reflect, array $vars =

// 判断数组类型 数字数组时按顺序绑定参数
reset($vars);
$type = key($vars) === 0 ? 1 : 0;
$type = key($vars) === 0 ? 1 : 0;
$params = $reflect->getParameters();
$args = [];
$args = [];

foreach ($params as $param) {
$name = $param->getName();
$lowerName = Str::snake($name);
$name = $param->getName();
$lowerName = Str::snake($name);
$reflectionType = $param->getType();

if ($param->isVariadic()) {
Expand Down
18 changes: 9 additions & 9 deletions src/think/Cookie.php
Expand Up @@ -26,13 +26,13 @@ class Cookie
*/
protected $config = [
// cookie 保存时间
'expire' => 0,
'expire' => 0,
// cookie 保存路径
'path' => '/',
'path' => '/',
// cookie 有效域名
'domain' => '',
'domain' => '',
// cookie 启用安全传输
'secure' => false,
'secure' => false,
// httponly设置
'httponly' => false,
// samesite 设置,支持 'strict' 'lax'
Expand All @@ -58,7 +58,7 @@ class Cookie
public function __construct(Request $request, array $config = [])
{
$this->request = $request;
$this->config = array_merge($this->config, array_change_key_case($config));
$this->config = array_merge($this->config, array_change_key_case($config));
}

public static function __make(Request $request, Config $config)
Expand Down Expand Up @@ -217,10 +217,10 @@ protected function saveCookie(string $name, string $value, int $expire, string $
{
if (version_compare(PHP_VERSION, '7.3.0', '>=')) {
setcookie($name, $value, [
'expires' => $expire,
'path' => $path,
'domain' => $domain,
'secure' => $secure,
'expires' => $expire,
'path' => $path,
'domain' => $domain,
'secure' => $secure,
'httponly' => $httponly,
'samesite' => $samesite,
]);
Expand Down
6 changes: 3 additions & 3 deletions src/think/Env.php
Expand Up @@ -31,10 +31,10 @@ class Env implements ArrayAccess
* @var array
*/
protected $convert = [
'true' => true,
'true' => true,
'false' => false,
'off' => false,
'on' => true,
'off' => false,
'on' => true,
];

public function __construct()
Expand Down
16 changes: 8 additions & 8 deletions src/think/Event.php
Expand Up @@ -32,12 +32,12 @@ class Event
* @var array
*/
protected $bind = [
'AppInit' => event\AppInit::class,
'HttpRun' => event\HttpRun::class,
'HttpEnd' => event\HttpEnd::class,
'AppInit' => event\AppInit::class,
'HttpRun' => event\HttpRun::class,
'HttpEnd' => event\HttpEnd::class,
'RouteLoaded' => event\RouteLoaded::class,
'LogWrite' => event\LogWrite::class,
'LogRecord' => event\LogRecord::class,
'LogWrite' => event\LogWrite::class,
'LogRecord' => event\LogRecord::class,
];

/**
Expand Down Expand Up @@ -207,14 +207,14 @@ public function trigger($event, $params = null, bool $once = false)
{
if (is_object($event)) {
$params = $event;
$event = get_class($event);
$event = get_class($event);
}

if (isset($this->bind[$event])) {
$event = $this->bind[$event];
}

$result = [];
$result = [];
$listeners = $this->listener[$event] ?? [];

if (strpos($event, '.')) {
Expand Down Expand Up @@ -262,7 +262,7 @@ protected function dispatch($event, $params = null)
} elseif (strpos($event, '::')) {
$call = $event;
} else {
$obj = $this->app->make($event);
$obj = $this->app->make($event);
$call = [$obj, 'handle'];
}

Expand Down

0 comments on commit 0165c2b

Please sign in to comment.