new files

This commit is contained in:
panchengyong
2026-03-07 22:29:07 +08:00
parent cd7e80b502
commit 7acbf45ff7
12516 changed files with 1808447 additions and 194 deletions

View File

@@ -0,0 +1,23 @@
<?php
namespace think\swoole\resetters;
use think\App;
use think\swoole\contract\ResetterInterface;
use think\swoole\Sandbox;
class ClearInstances implements ResetterInterface
{
public function handle(App $app, Sandbox $sandbox)
{
$instances = ['log', 'session', 'view', 'response', 'cookie'];
$instances = array_merge($instances, $sandbox->getConfig()->get('swoole.instances', []));
foreach ($instances as $instance) {
$app->delete($instance);
}
return $app;
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace think\swoole\resetters;
use think\App;
use think\swoole\contract\ResetterInterface;
use think\swoole\Sandbox;
class ResetConfig implements ResetterInterface
{
public function handle(App $app, Sandbox $sandbox)
{
$app->instance('config', clone $sandbox->getConfig());
return $app;
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace think\swoole\resetters;
use think\App;
use think\swoole\concerns\ModifyProperty;
use think\swoole\contract\ResetterInterface;
use think\swoole\Sandbox;
/**
* Class ResetEvent
* @package think\swoole\resetters
*/
class ResetEvent implements ResetterInterface
{
use ModifyProperty;
public function handle(App $app, Sandbox $sandbox)
{
$event = clone $sandbox->getEvent();
$this->modifyProperty($event, $app);
$app->instance('event', $event);
return $app;
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace think\swoole\resetters;
use think\App;
use think\Model;
use think\swoole\contract\ResetterInterface;
use think\swoole\Sandbox;
class ResetModel implements ResetterInterface
{
public function handle(App $app, Sandbox $sandbox)
{
if (class_exists(Model::class)) {
Model::setInvoker(function (...$args) use ($sandbox) {
return $sandbox->getApplication()->invoke(...$args);
});
}
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace think\swoole\resetters;
use think\App;
use think\Paginator;
use think\swoole\contract\ResetterInterface;
use think\swoole\Sandbox;
class ResetPaginator implements ResetterInterface
{
public function handle(App $app, Sandbox $sandbox)
{
Paginator::currentPathResolver(function () use ($sandbox) {
return $sandbox->getApplication()->request->baseUrl();
});
Paginator::currentPageResolver(function ($varPage = 'page') use ($sandbox) {
$page = $sandbox->getApplication()->request->param($varPage);
if (filter_var($page, FILTER_VALIDATE_INT) !== false && (int) $page >= 1) {
return (int) $page;
}
return 1;
});
}
}

View File

@@ -0,0 +1,37 @@
<?php
namespace think\swoole\resetters;
use think\App;
use think\swoole\concerns\ModifyProperty;
use think\swoole\contract\ResetterInterface;
use think\swoole\Sandbox;
/**
* Class ResetService
* @package think\swoole\resetters
*/
class ResetService implements ResetterInterface
{
use ModifyProperty;
/**
* "handle" function for resetting app.
*
* @param App $app
* @param Sandbox $sandbox
*/
public function handle(App $app, Sandbox $sandbox)
{
foreach ($sandbox->getServices() as $service) {
$this->modifyProperty($service, $app);
if (method_exists($service, 'register')) {
$service->register();
}
if (method_exists($service, 'boot')) {
$app->invoke([$service, 'boot']);
}
}
}
}