modify
This commit is contained in:
@@ -126,7 +126,7 @@ class ActiveRecord extends BaseActiveRecord
|
||||
if (empty($attributes)) {
|
||||
return $logger->addError(FIND_OR_CREATE_MESSAGE, 'mysql');
|
||||
}
|
||||
$select = self::getModelClass();
|
||||
$select = duplicate(static::class);
|
||||
$select->attributes = $attributes;
|
||||
if (!$select->save()) {
|
||||
return $logger->addError($select->getLastError(), 'mysql');
|
||||
@@ -150,7 +150,7 @@ class ActiveRecord extends BaseActiveRecord
|
||||
/** @var static $select */
|
||||
$select = static::find()->where($condition)->first();
|
||||
if (empty($select)) {
|
||||
$select = self::getModelClass();
|
||||
$select = duplicate(static::class);
|
||||
}
|
||||
$select->attributes = $attributes;
|
||||
if (!$select->save()) {
|
||||
@@ -160,20 +160,6 @@ class ActiveRecord extends BaseActiveRecord
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return static
|
||||
* @throws Exception
|
||||
*/
|
||||
private static function getModelClass(): static
|
||||
{
|
||||
/** @var Channel $channel */
|
||||
$channel = Snowflake::app()->get('channel');
|
||||
return $channel->pop(static::class, function () {
|
||||
return new static();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $action
|
||||
* @param $columns
|
||||
@@ -306,10 +292,6 @@ class ActiveRecord extends BaseActiveRecord
|
||||
$data[$key] = $this->{$item}($data[$key] ?? null);
|
||||
}
|
||||
$data = array_merge($data, $this->runRelate());
|
||||
|
||||
$class = Snowflake::app()->getChannel();
|
||||
$class->push($this, static::class);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat
|
||||
{
|
||||
$this->_item = $array;
|
||||
$this->query = $query;
|
||||
$this->model = $model;
|
||||
$this->model = duplicate($model);
|
||||
|
||||
parent::__construct([]);
|
||||
}
|
||||
@@ -110,10 +110,6 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat
|
||||
*/
|
||||
public function getModel(): ActiveRecord
|
||||
{
|
||||
if (!is_object($this->model)) {
|
||||
$this->model = duplicate($this->model);
|
||||
$this->model->setIsCreate(false);
|
||||
}
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
@@ -137,12 +133,10 @@ abstract class AbstractCollection extends Component implements \IteratorAggregat
|
||||
if (!$this->offsetExists($offset)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ($this->_item[$offset] instanceof ActiveRecord) {
|
||||
return $this->_item[$offset];
|
||||
if (!($this->_item[$offset] instanceof ActiveRecord)) {
|
||||
return $this->model->setAttributes($this->_item[$offset]);
|
||||
}
|
||||
|
||||
return $this->model::populate($this->_item[$offset]);
|
||||
return $this->_item[$offset];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -56,7 +56,7 @@ class CollectionIterator extends \ArrayIterator
|
||||
*/
|
||||
protected function newModel($current): ActiveRecord
|
||||
{
|
||||
return $this->model::populate($current);
|
||||
return $this->model->setAttributes($current);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace HttpServer\Http;
|
||||
use Annotation\Route\Socket;
|
||||
use Exception;
|
||||
use HttpServer\Abstracts\HttpService;
|
||||
use HttpServer\Http\Response as HResponse;
|
||||
use HttpServer\IInterface\AuthIdentity;
|
||||
use JetBrains\PhpStorm\Pure;
|
||||
use Snowflake\Abstracts\Config;
|
||||
@@ -451,7 +452,7 @@ class Request extends HttpService
|
||||
* @param \Swoole\Http\Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public static function create(\Swoole\Http\Request $request): Request
|
||||
public static function create(\Swoole\Http\Request $request, \Swoole\Http\Response $response): Request
|
||||
{
|
||||
/** @var Request $sRequest */
|
||||
$sRequest = Context::setContext('request', new Request());
|
||||
@@ -467,6 +468,8 @@ class Request extends HttpService
|
||||
$sRequest->uri = $sRequest->headers->get('request_uri');
|
||||
|
||||
$sRequest->parseUri();
|
||||
|
||||
HResponse::create($response);
|
||||
return $sRequest;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Server;
|
||||
|
||||
|
||||
use Swoole\Coroutine\Channel;
|
||||
|
||||
class ApplicationStore
|
||||
{
|
||||
|
||||
|
||||
private static ?ApplicationStore $applicationStore = null;
|
||||
|
||||
|
||||
private Channel $lock;
|
||||
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
$this->lock = new Channel(99999);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return \Server\ApplicationStore|null
|
||||
*/
|
||||
public static function getStore()
|
||||
{
|
||||
if (!(static::$applicationStore instanceof ApplicationStore)) {
|
||||
static::$applicationStore = new ApplicationStore();
|
||||
}
|
||||
return static::$applicationStore;
|
||||
}
|
||||
|
||||
|
||||
public function add()
|
||||
{
|
||||
$this->lock->push(1);
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
public function waite()
|
||||
{
|
||||
$this->lock->pop(-1);
|
||||
}
|
||||
|
||||
|
||||
public function done()
|
||||
{
|
||||
$this->lock->pop();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isBusy()
|
||||
{
|
||||
return !$this->lock->isEmpty();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getStatus(): string
|
||||
{
|
||||
return env('state');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -32,6 +32,8 @@ class HTTPServerListener extends Abstracts\Server
|
||||
|
||||
private Router $router;
|
||||
|
||||
private ApplicationStore $store;
|
||||
|
||||
|
||||
/**
|
||||
* HTTPServerListener constructor.
|
||||
@@ -40,6 +42,7 @@ class HTTPServerListener extends Abstracts\Server
|
||||
public function __construct()
|
||||
{
|
||||
$this->router = Snowflake::getApp('router');
|
||||
$this->store = ApplicationStore::getStore();
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
@@ -103,7 +106,7 @@ class HTTPServerListener extends Abstracts\Server
|
||||
public function onRequest(Request $request, Response $response)
|
||||
{
|
||||
try {
|
||||
[$request, $_] = [HRequest::create($request), HResponse::create($response)];
|
||||
$request = HRequest::create($request, $response);
|
||||
if ($request->is('favicon.ico')) {
|
||||
throw new Exception('Not found.', 404);
|
||||
}
|
||||
|
||||
@@ -69,7 +69,6 @@ class ServerWorker extends \Server\Abstracts\Server
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param $worker_id
|
||||
* @throws Exception
|
||||
@@ -98,8 +97,6 @@ class ServerWorker extends \Server\Abstracts\Server
|
||||
|
||||
Event::trigger(Event::SERVER_WORKER_STOP);
|
||||
|
||||
var_dump('worker stop .' . $workerId);
|
||||
|
||||
fire(Event::SYSTEM_RESOURCE_CLEAN);
|
||||
|
||||
Timer::clearAll();
|
||||
|
||||
Reference in New Issue
Block a user