This commit is contained in:
lq 2024-05-21 14:33:56 +08:00
parent 2f3467a38a
commit 0ffab55fa0
26 changed files with 631 additions and 318 deletions

View File

@ -1,13 +1,25 @@
<?php <?php
return [ return [
'default' => [ 'default' => [
'driver' => 'mysql', 'driver' => 'mysql',
'host' => 'localhost', 'host' => '127.0.0.1',
'database' => 'blog', 'database' => 'saiadmin',
'username' => 'blog', 'username' => 'root',
'password' => 'fj6edWTinXimLpiT', 'password' => '123456',
'port' => 3306,
'charset' => 'utf8mb4', 'charset' => 'utf8mb4',
'collation' => 'utf8mb4_general_ci', 'collation' => 'utf8mb4_general_ci',
'prefix' => 'eb_', 'prefix' => 'eb_',
] ],
'db2' => [
'driver' => 'mysql',
'host' => '127.0.0.1',
'database' => 'test',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
],
]; ];

8
app/config/dbpool.php Normal file
View File

@ -0,0 +1,8 @@
<?php
return [
"default" => [
"min" => 100,
"max" => 200,
"idleTime" => 30
]
];

View File

@ -2,7 +2,7 @@
define("ROOT_PATH", dirname(dirname(__DIR__))); define("ROOT_PATH", dirname(dirname(__DIR__)));
$GLOBAL_CONFIGD= [ $GLOBAL_CONFIGS = [
'db' => require_once(__DIR__ . "/db.php"), 'db' => require_once(__DIR__ . "/db.php"),
'redis'=>[] 'dbpool' => require_once(__DIR__ . '/dbpool.php'),
]; ];

View File

@ -1,5 +1,6 @@
<?php <?php
namespace App\controller; namespace App\controller;
use App\model\User;
use Core\annotations\Bean; use Core\annotations\Bean;
use Core\annotations\Value; use Core\annotations\Value;
use Core\annotations\DB; use Core\annotations\DB;
@ -7,7 +8,6 @@ use Core\annotations\RequestMapping;
use Core\http\Request; use Core\http\Request;
use Core\http\Response; use Core\http\Response;
use Core\init\MyDB; use Core\init\MyDB;
/** /**
* @Bean() * @Bean()
*/ */
@ -28,18 +28,18 @@ class UserController
*/ */
public function test() public function test()
{ {
return $this->db->table("user")->get(); //$this->db->select('select sleep(1)');
//return "route doc"; //User::query('select sleep(3)');
$user = User::first();
return ['uid'=>33,'username'=>$user];
} }
/** /**
* @RequestMapping(value="/user/{uid:\d+}") * @RequestMapping(value="/user/{uid:\d+}")
*/ */
public function user(int $uid,Request $request, Response $response) public function user(int $uid,Request $request, Response $response)
{ {
//var_dump($r->getQueryParams()); $user = $this->db->select('select * from eb_user where id = 1');
//$response->testWrite('abc'); return ['uid'=>$uid,'username'=>$user];
//return "bbb---".$uid;
return ['uid'=>$uid,'username'=>'ttt'];
} }
/** /**
* @RequestMapping(value="/redirect") * @RequestMapping(value="/redirect")

View File

@ -1,8 +1,11 @@
<?php <?php
namespace App\model; namespace App\model;
use \Illuminate\Database\Eloquent\Model; use Core\lib\Models;
class User extends Model
class User extends Models
{ {
protected $table = 'user'; protected $table = 'user';
protected $primaryKey = 'id'; protected $primaryKey = 'id';
protected $connection = 'default';
} }

View File

@ -1,27 +1,33 @@
<?php <?php
require_once __DIR__ . '/vendor/autoload.php'; require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . "/app/config/define.php"; require_once __DIR__ . "/app/config/define.php";
\Swoole\Runtime::enableCoroutine(true);
use Core\server\HttpServer;
use Swoole\Process; use Swoole\Process;
if ($argc == 2) { if ($argc == 2) {
$cmd = $argv[1]; $cmd = $argv[1];
if ($cmd == 'start') { if ($cmd == 'start') {
// $http = new Core\server\HttpServer('first');
//$http = \Core\BeanFactory::getBean('HttpServer');
$http = new HttpServer('first');
$http->run(); $http->run();
} else if ($cmd == 'stop') { } else if ($cmd == 'stop') {
$mid = intval(file_get_contents("./ttt.pid")); $getpid = intval(file_get_contents("./Buddha.pid")); //获取上一次程序运行的 master_id
if (trim($mid)){ if ($getpid && trim($getpid) != 0) {
Process::kill($mid); Process::kill($getpid);
echo "stop success" . PHP_EOL;
}
} else if ($cmd == 'restart') {
$getpid = intval(file_get_contents("./Buddha.pid")); //获取上一次程序运行的 master_id
if ($getpid && trim($getpid) != 0) {
Process::kill($getpid);
sleep(1);
$http = new Core\server\HttpServer('first');
echo "restart done" . PHP_EOL;
$http->run();
} else {
echo "restart the failure" . PHP_EOL;
} }
} else { } else {
echo '无效命令'; echo '无效命令';
} }
} else {
echo '无效命令';
} }

View File

@ -19,6 +19,6 @@
"nikic/fast-route": "^1.3", "nikic/fast-route": "^1.3",
"php-di/php-di": "^7.0", "php-di/php-di": "^7.0",
"doctrine/annotations": "^2.0.1", "doctrine/annotations": "^2.0.1",
"illuminate/database": "^11.7" "illuminate/database": "^10.48"
} }
} }

380
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "e265bde019301524339229e75bbcf759", "content-hash": "64d563c1b41fd9b1ca5e4e16c8d9d8d2",
"packages": [ "packages": [
{ {
"name": "brick/math", "name": "brick/math",
@ -68,26 +68,26 @@
}, },
{ {
"name": "carbonphp/carbon-doctrine-types", "name": "carbonphp/carbon-doctrine-types",
"version": "3.2.0", "version": "2.1.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/CarbonPHP/carbon-doctrine-types.git", "url": "https://github.com/CarbonPHP/carbon-doctrine-types.git",
"reference": "18ba5ddfec8976260ead6e866180bd5d2f71aa1d" "reference": "99f76ffa36cce3b70a4a6abce41dba15ca2e84cb"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/CarbonPHP/carbon-doctrine-types/zipball/18ba5ddfec8976260ead6e866180bd5d2f71aa1d", "url": "https://api.github.com/repos/CarbonPHP/carbon-doctrine-types/zipball/99f76ffa36cce3b70a4a6abce41dba15ca2e84cb",
"reference": "18ba5ddfec8976260ead6e866180bd5d2f71aa1d", "reference": "99f76ffa36cce3b70a4a6abce41dba15ca2e84cb",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": "^8.1" "php": "^7.4 || ^8.0"
}, },
"conflict": { "conflict": {
"doctrine/dbal": "<4.0.0 || >=5.0.0" "doctrine/dbal": "<3.7.0 || >=4.0.0"
}, },
"require-dev": { "require-dev": {
"doctrine/dbal": "^4.0.0", "doctrine/dbal": "^3.7.0",
"nesbot/carbon": "^2.71.0 || ^3.0.0", "nesbot/carbon": "^2.71.0 || ^3.0.0",
"phpunit/phpunit": "^10.3" "phpunit/phpunit": "^10.3"
}, },
@ -117,7 +117,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/CarbonPHP/carbon-doctrine-types/issues", "issues": "https://github.com/CarbonPHP/carbon-doctrine-types/issues",
"source": "https://github.com/CarbonPHP/carbon-doctrine-types/tree/3.2.0" "source": "https://github.com/CarbonPHP/carbon-doctrine-types/tree/2.1.0"
}, },
"funding": [ "funding": [
{ {
@ -133,7 +133,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2024-02-09T16:56:22+00:00" "time": "2023-12-11T17:09:12+00:00"
}, },
{ {
"name": "doctrine/annotations", "name": "doctrine/annotations",
@ -381,31 +381,31 @@
}, },
{ {
"name": "illuminate/collections", "name": "illuminate/collections",
"version": "v11.7.0", "version": "v10.48.10",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/collections.git", "url": "https://github.com/illuminate/collections.git",
"reference": "3859367b55d977bcf5da86680c787dffaaacdb86" "reference": "f9589f1063a449111dcaa1d68285b507d9483a95"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/illuminate/collections/zipball/3859367b55d977bcf5da86680c787dffaaacdb86", "url": "https://api.github.com/repos/illuminate/collections/zipball/f9589f1063a449111dcaa1d68285b507d9483a95",
"reference": "3859367b55d977bcf5da86680c787dffaaacdb86", "reference": "f9589f1063a449111dcaa1d68285b507d9483a95",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"illuminate/conditionable": "^11.0", "illuminate/conditionable": "^10.0",
"illuminate/contracts": "^11.0", "illuminate/contracts": "^10.0",
"illuminate/macroable": "^11.0", "illuminate/macroable": "^10.0",
"php": "^8.2" "php": "^8.1"
}, },
"suggest": { "suggest": {
"symfony/var-dumper": "Required to use the dump method (^7.0)." "symfony/var-dumper": "Required to use the dump method (^6.2)."
}, },
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "11.x-dev" "dev-master": "10.x-dev"
} }
}, },
"autoload": { "autoload": {
@ -432,20 +432,20 @@
"issues": "https://github.com/laravel/framework/issues", "issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework" "source": "https://github.com/laravel/framework"
}, },
"time": "2024-05-05T15:36:09+00:00" "time": "2024-03-20T20:09:13+00:00"
}, },
{ {
"name": "illuminate/conditionable", "name": "illuminate/conditionable",
"version": "v11.7.0", "version": "v10.48.10",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/conditionable.git", "url": "https://github.com/illuminate/conditionable.git",
"reference": "8a558fec063b6a63da1c3af1d219c0f998edffeb" "reference": "d0958e4741fc9d6f516a552060fd1b829a85e009"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/illuminate/conditionable/zipball/8a558fec063b6a63da1c3af1d219c0f998edffeb", "url": "https://api.github.com/repos/illuminate/conditionable/zipball/d0958e4741fc9d6f516a552060fd1b829a85e009",
"reference": "8a558fec063b6a63da1c3af1d219c0f998edffeb", "reference": "d0958e4741fc9d6f516a552060fd1b829a85e009",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -454,7 +454,7 @@
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "11.x-dev" "dev-master": "10.x-dev"
} }
}, },
"autoload": { "autoload": {
@ -478,25 +478,25 @@
"issues": "https://github.com/laravel/framework/issues", "issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework" "source": "https://github.com/laravel/framework"
}, },
"time": "2024-04-04T17:36:49+00:00" "time": "2023-02-03T08:06:17+00:00"
}, },
{ {
"name": "illuminate/container", "name": "illuminate/container",
"version": "v11.7.0", "version": "v10.48.10",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/container.git", "url": "https://github.com/illuminate/container.git",
"reference": "af979ecfd6dfa6583eae5dfe2e9a8840358f4ca7" "reference": "ddc26273085fad3c471b2602ad820e0097ff7939"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/illuminate/container/zipball/af979ecfd6dfa6583eae5dfe2e9a8840358f4ca7", "url": "https://api.github.com/repos/illuminate/container/zipball/ddc26273085fad3c471b2602ad820e0097ff7939",
"reference": "af979ecfd6dfa6583eae5dfe2e9a8840358f4ca7", "reference": "ddc26273085fad3c471b2602ad820e0097ff7939",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"illuminate/contracts": "^11.0", "illuminate/contracts": "^10.0",
"php": "^8.2", "php": "^8.1",
"psr/container": "^1.1.1|^2.0.1" "psr/container": "^1.1.1|^2.0.1"
}, },
"provide": { "provide": {
@ -505,7 +505,7 @@
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "11.x-dev" "dev-master": "10.x-dev"
} }
}, },
"autoload": { "autoload": {
@ -529,31 +529,31 @@
"issues": "https://github.com/laravel/framework/issues", "issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework" "source": "https://github.com/laravel/framework"
}, },
"time": "2024-04-04T17:36:49+00:00" "time": "2023-06-18T09:12:03+00:00"
}, },
{ {
"name": "illuminate/contracts", "name": "illuminate/contracts",
"version": "v11.7.0", "version": "v10.48.10",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/contracts.git", "url": "https://github.com/illuminate/contracts.git",
"reference": "8782f75e80ab3e6036842d24dbeead34a16f3a79" "reference": "8d7152c4a1f5d9cf7da3e8b71f23e4556f6138ac"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/illuminate/contracts/zipball/8782f75e80ab3e6036842d24dbeead34a16f3a79", "url": "https://api.github.com/repos/illuminate/contracts/zipball/8d7152c4a1f5d9cf7da3e8b71f23e4556f6138ac",
"reference": "8782f75e80ab3e6036842d24dbeead34a16f3a79", "reference": "8d7152c4a1f5d9cf7da3e8b71f23e4556f6138ac",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": "^8.2", "php": "^8.1",
"psr/container": "^1.1.1|^2.0.1", "psr/container": "^1.1.1|^2.0.1",
"psr/simple-cache": "^1.0|^2.0|^3.0" "psr/simple-cache": "^1.0|^2.0|^3.0"
}, },
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "11.x-dev" "dev-master": "10.x-dev"
} }
}, },
"autoload": { "autoload": {
@ -577,45 +577,50 @@
"issues": "https://github.com/laravel/framework/issues", "issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework" "source": "https://github.com/laravel/framework"
}, },
"time": "2024-04-17T14:09:55+00:00" "time": "2024-01-15T18:52:32+00:00"
}, },
{ {
"name": "illuminate/database", "name": "illuminate/database",
"version": "v11.7.0", "version": "v10.48.10",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/database.git", "url": "https://github.com/illuminate/database.git",
"reference": "49a2dd6fba0cfa0d3a11fd15433059f7f5fba45a" "reference": "eb8edf206d3a6eea8894bc6e21f53469e27dd5c9"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/illuminate/database/zipball/49a2dd6fba0cfa0d3a11fd15433059f7f5fba45a", "url": "https://api.github.com/repos/illuminate/database/zipball/eb8edf206d3a6eea8894bc6e21f53469e27dd5c9",
"reference": "49a2dd6fba0cfa0d3a11fd15433059f7f5fba45a", "reference": "eb8edf206d3a6eea8894bc6e21f53469e27dd5c9",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"brick/math": "^0.9.3|^0.10.2|^0.11|^0.12", "brick/math": "^0.9.3|^0.10.2|^0.11|^0.12",
"ext-pdo": "*", "ext-pdo": "*",
"illuminate/collections": "^11.0", "illuminate/collections": "^10.0",
"illuminate/container": "^11.0", "illuminate/container": "^10.0",
"illuminate/contracts": "^11.0", "illuminate/contracts": "^10.0",
"illuminate/macroable": "^11.0", "illuminate/macroable": "^10.0",
"illuminate/support": "^11.0", "illuminate/support": "^10.0",
"php": "^8.2" "php": "^8.1"
},
"conflict": {
"carbonphp/carbon-doctrine-types": ">=3.0",
"doctrine/dbal": ">=4.0"
}, },
"suggest": { "suggest": {
"doctrine/dbal": "Required to rename columns and drop SQLite columns (^3.5.1).",
"ext-filter": "Required to use the Postgres database driver.", "ext-filter": "Required to use the Postgres database driver.",
"fakerphp/faker": "Required to use the eloquent factory builder (^1.21).", "fakerphp/faker": "Required to use the eloquent factory builder (^1.21).",
"illuminate/console": "Required to use the database commands (^11.0).", "illuminate/console": "Required to use the database commands (^10.0).",
"illuminate/events": "Required to use the observers with Eloquent (^11.0).", "illuminate/events": "Required to use the observers with Eloquent (^10.0).",
"illuminate/filesystem": "Required to use the migrations (^11.0).", "illuminate/filesystem": "Required to use the migrations (^10.0).",
"illuminate/pagination": "Required to paginate the result set (^11.0).", "illuminate/pagination": "Required to paginate the result set (^10.0).",
"symfony/finder": "Required to use Eloquent model factories (^7.0)." "symfony/finder": "Required to use Eloquent model factories (^6.2)."
}, },
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "11.x-dev" "dev-master": "10.x-dev"
} }
}, },
"autoload": { "autoload": {
@ -645,29 +650,29 @@
"issues": "https://github.com/laravel/framework/issues", "issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework" "source": "https://github.com/laravel/framework"
}, },
"time": "2024-05-06T18:08:11+00:00" "time": "2024-04-29T13:23:17+00:00"
}, },
{ {
"name": "illuminate/macroable", "name": "illuminate/macroable",
"version": "v11.7.0", "version": "v10.48.10",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/macroable.git", "url": "https://github.com/illuminate/macroable.git",
"reference": "e1be58f9b2af73f242dc6a9add1f376b3ec89eef" "reference": "dff667a46ac37b634dcf68909d9d41e94dc97c27"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/illuminate/macroable/zipball/e1be58f9b2af73f242dc6a9add1f376b3ec89eef", "url": "https://api.github.com/repos/illuminate/macroable/zipball/dff667a46ac37b634dcf68909d9d41e94dc97c27",
"reference": "e1be58f9b2af73f242dc6a9add1f376b3ec89eef", "reference": "dff667a46ac37b634dcf68909d9d41e94dc97c27",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": "^8.2" "php": "^8.1"
}, },
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "11.x-dev" "dev-master": "10.x-dev"
} }
}, },
"autoload": { "autoload": {
@ -691,20 +696,20 @@
"issues": "https://github.com/laravel/framework/issues", "issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework" "source": "https://github.com/laravel/framework"
}, },
"time": "2023-06-08T14:08:27+00:00" "time": "2023-06-05T12:46:42+00:00"
}, },
{ {
"name": "illuminate/support", "name": "illuminate/support",
"version": "v11.7.0", "version": "v10.48.10",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/illuminate/support.git", "url": "https://github.com/illuminate/support.git",
"reference": "7d733a1dbeb96557ba287e778bbf7bc61e23c31d" "reference": "ee3a1aaed36d916654ce0ae09dfbd38644a4f582"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/illuminate/support/zipball/7d733a1dbeb96557ba287e778bbf7bc61e23c31d", "url": "https://api.github.com/repos/illuminate/support/zipball/ee3a1aaed36d916654ce0ae09dfbd38644a4f582",
"reference": "7d733a1dbeb96557ba287e778bbf7bc61e23c31d", "reference": "ee3a1aaed36d916654ce0ae09dfbd38644a4f582",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -712,33 +717,30 @@
"ext-ctype": "*", "ext-ctype": "*",
"ext-filter": "*", "ext-filter": "*",
"ext-mbstring": "*", "ext-mbstring": "*",
"illuminate/collections": "^11.0", "illuminate/collections": "^10.0",
"illuminate/conditionable": "^11.0", "illuminate/conditionable": "^10.0",
"illuminate/contracts": "^11.0", "illuminate/contracts": "^10.0",
"illuminate/macroable": "^11.0", "illuminate/macroable": "^10.0",
"nesbot/carbon": "^2.72.2|^3.0", "nesbot/carbon": "^2.67",
"php": "^8.2", "php": "^8.1",
"voku/portable-ascii": "^2.0" "voku/portable-ascii": "^2.0"
}, },
"conflict": { "conflict": {
"tightenco/collect": "<5.5.33" "tightenco/collect": "<5.5.33"
}, },
"replace": {
"spatie/once": "*"
},
"suggest": { "suggest": {
"illuminate/filesystem": "Required to use the composer class (^11.0).", "illuminate/filesystem": "Required to use the composer class (^10.0).",
"league/commonmark": "Required to use Str::markdown() and Stringable::markdown() (^2.0.2).", "league/commonmark": "Required to use Str::markdown() and Stringable::markdown() (^2.0.2).",
"ramsey/uuid": "Required to use Str::uuid() (^4.7).", "ramsey/uuid": "Required to use Str::uuid() (^4.7).",
"symfony/process": "Required to use the composer class (^7.0).", "symfony/process": "Required to use the composer class (^6.2).",
"symfony/uid": "Required to use Str::ulid() (^7.0).", "symfony/uid": "Required to use Str::ulid() (^6.2).",
"symfony/var-dumper": "Required to use the dd function (^7.0).", "symfony/var-dumper": "Required to use the dd function (^6.2).",
"vlucas/phpdotenv": "Required to use the Env class and env helper (^5.4.1)." "vlucas/phpdotenv": "Required to use the Env class and env helper (^5.4.1)."
}, },
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "11.x-dev" "dev-master": "10.x-dev"
} }
}, },
"autoload": { "autoload": {
@ -765,7 +767,7 @@
"issues": "https://github.com/laravel/framework/issues", "issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework" "source": "https://github.com/laravel/framework"
}, },
"time": "2024-05-06T18:30:15+00:00" "time": "2024-04-07T17:47:33+00:00"
}, },
{ {
"name": "laravel/serializable-closure", "name": "laravel/serializable-closure",
@ -829,41 +831,42 @@
}, },
{ {
"name": "nesbot/carbon", "name": "nesbot/carbon",
"version": "3.3.1", "version": "2.72.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/briannesbitt/Carbon.git", "url": "https://github.com/briannesbitt/Carbon.git",
"reference": "8ff64b92c1b1ec84fcde9f8bb9ff2ca34cb8a77a" "reference": "0c6fd108360c562f6e4fd1dedb8233b423e91c83"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/8ff64b92c1b1ec84fcde9f8bb9ff2ca34cb8a77a", "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/0c6fd108360c562f6e4fd1dedb8233b423e91c83",
"reference": "8ff64b92c1b1ec84fcde9f8bb9ff2ca34cb8a77a", "reference": "0c6fd108360c562f6e4fd1dedb8233b423e91c83",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"carbonphp/carbon-doctrine-types": "*", "carbonphp/carbon-doctrine-types": "*",
"ext-json": "*", "ext-json": "*",
"php": "^8.1", "php": "^7.1.8 || ^8.0",
"psr/clock": "^1.0", "psr/clock": "^1.0",
"symfony/clock": "^6.3 || ^7.0",
"symfony/polyfill-mbstring": "^1.0", "symfony/polyfill-mbstring": "^1.0",
"symfony/translation": "^4.4.18 || ^5.2.1|| ^6.0 || ^7.0" "symfony/polyfill-php80": "^1.16",
"symfony/translation": "^3.4 || ^4.0 || ^5.0 || ^6.0"
}, },
"provide": { "provide": {
"psr/clock-implementation": "1.0" "psr/clock-implementation": "1.0"
}, },
"require-dev": { "require-dev": {
"doctrine/dbal": "^3.6.3 || ^4.0", "doctrine/dbal": "^2.0 || ^3.1.4 || ^4.0",
"doctrine/orm": "^2.15.2 || ^3.0", "doctrine/orm": "^2.7 || ^3.0",
"friendsofphp/php-cs-fixer": "^3.52.1", "friendsofphp/php-cs-fixer": "^3.0",
"kylekatarnls/multi-tester": "^2.5.3", "kylekatarnls/multi-tester": "^2.0",
"ondrejmirtes/better-reflection": "^6.25.0.4", "ondrejmirtes/better-reflection": "*",
"phpmd/phpmd": "^2.15.0", "phpmd/phpmd": "^2.9",
"phpstan/extension-installer": "^1.3.1", "phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^1.10.65", "phpstan/phpstan": "^0.12.99 || ^1.7.14",
"phpunit/phpunit": "^10.5.15", "phpunit/php-file-iterator": "^2.0.5 || ^3.0.6",
"squizlabs/php_codesniffer": "^3.9.0" "phpunit/phpunit": "^7.5.20 || ^8.5.26 || ^9.5.20",
"squizlabs/php_codesniffer": "^3.4"
}, },
"bin": [ "bin": [
"bin/carbon" "bin/carbon"
@ -871,8 +874,8 @@
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "3.x-dev", "dev-3.x": "3.x-dev",
"dev-2.x": "2.x-dev" "dev-master": "2.x-dev"
}, },
"laravel": { "laravel": {
"providers": [ "providers": [
@ -931,7 +934,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2024-05-01T06:54:22+00:00" "time": "2024-01-25T10:35:09+00:00"
}, },
{ {
"name": "nikic/fast-route", "name": "nikic/fast-route",
@ -1313,37 +1316,35 @@
"time": "2021-10-29T13:26:27+00:00" "time": "2021-10-29T13:26:27+00:00"
}, },
{ {
"name": "symfony/clock", "name": "symfony/deprecation-contracts",
"version": "v7.0.7", "version": "v3.5.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/clock.git", "url": "https://github.com/symfony/deprecation-contracts.git",
"reference": "2008671acb4a30b01c453de193cf9c80549ebda6" "reference": "0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/clock/zipball/2008671acb4a30b01c453de193cf9c80549ebda6", "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1",
"reference": "2008671acb4a30b01c453de193cf9c80549ebda6", "reference": "0e0d29ce1f20deffb4ab1b016a7257c4f1e789a1",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=8.2", "php": ">=8.1"
"psr/clock": "^1.0",
"symfony/polyfill-php83": "^1.28"
},
"provide": {
"psr/clock-implementation": "1.0"
}, },
"type": "library", "type": "library",
"extra": {
"branch-alias": {
"dev-main": "3.5-dev"
},
"thanks": {
"name": "symfony/contracts",
"url": "https://github.com/symfony/contracts"
}
},
"autoload": { "autoload": {
"files": [ "files": [
"Resources/now.php" "function.php"
],
"psr-4": {
"Symfony\\Component\\Clock\\": ""
},
"exclude-from-classmap": [
"/Tests/"
] ]
}, },
"notification-url": "https://packagist.org/downloads/", "notification-url": "https://packagist.org/downloads/",
@ -1360,15 +1361,10 @@
"homepage": "https://symfony.com/contributors" "homepage": "https://symfony.com/contributors"
} }
], ],
"description": "Decouples applications from the system clock", "description": "A generic function and convention to trigger deprecation notices",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"keywords": [
"clock",
"psr20",
"time"
],
"support": { "support": {
"source": "https://github.com/symfony/clock/tree/v7.0.7" "source": "https://github.com/symfony/deprecation-contracts/tree/v3.5.0"
}, },
"funding": [ "funding": [
{ {
@ -1384,7 +1380,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2024-04-18T09:29:19+00:00" "time": "2024-04-18T09:32:20+00:00"
}, },
{ {
"name": "symfony/polyfill-mbstring", "name": "symfony/polyfill-mbstring",
@ -1546,111 +1542,35 @@
], ],
"time": "2024-01-29T20:11:03+00:00" "time": "2024-01-29T20:11:03+00:00"
}, },
{
"name": "symfony/polyfill-php83",
"version": "v1.29.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php83.git",
"reference": "86fcae159633351e5fd145d1c47de6c528f8caff"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-php83/zipball/86fcae159633351e5fd145d1c47de6c528f8caff",
"reference": "86fcae159633351e5fd145d1c47de6c528f8caff",
"shasum": ""
},
"require": {
"php": ">=7.1",
"symfony/polyfill-php80": "^1.14"
},
"type": "library",
"extra": {
"thanks": {
"name": "symfony/polyfill",
"url": "https://github.com/symfony/polyfill"
}
},
"autoload": {
"files": [
"bootstrap.php"
],
"psr-4": {
"Symfony\\Polyfill\\Php83\\": ""
},
"classmap": [
"Resources/stubs"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill backporting some PHP 8.3+ features to lower PHP versions",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"polyfill",
"portable",
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-php83/tree/v1.29.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2024-01-29T20:11:03+00:00"
},
{ {
"name": "symfony/translation", "name": "symfony/translation",
"version": "v7.0.7", "version": "v6.4.7",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/symfony/translation.git", "url": "https://github.com/symfony/translation.git",
"reference": "1515e03afaa93e6419aba5d5c9d209159317100b" "reference": "7495687c58bfd88b7883823747b0656d90679123"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/symfony/translation/zipball/1515e03afaa93e6419aba5d5c9d209159317100b", "url": "https://api.github.com/repos/symfony/translation/zipball/7495687c58bfd88b7883823747b0656d90679123",
"reference": "1515e03afaa93e6419aba5d5c9d209159317100b", "reference": "7495687c58bfd88b7883823747b0656d90679123",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=8.2", "php": ">=8.1",
"symfony/deprecation-contracts": "^2.5|^3",
"symfony/polyfill-mbstring": "~1.0", "symfony/polyfill-mbstring": "~1.0",
"symfony/translation-contracts": "^2.5|^3.0" "symfony/translation-contracts": "^2.5|^3.0"
}, },
"conflict": { "conflict": {
"symfony/config": "<6.4", "symfony/config": "<5.4",
"symfony/console": "<6.4", "symfony/console": "<5.4",
"symfony/dependency-injection": "<6.4", "symfony/dependency-injection": "<5.4",
"symfony/http-client-contracts": "<2.5", "symfony/http-client-contracts": "<2.5",
"symfony/http-kernel": "<6.4", "symfony/http-kernel": "<5.4",
"symfony/service-contracts": "<2.5", "symfony/service-contracts": "<2.5",
"symfony/twig-bundle": "<6.4", "symfony/twig-bundle": "<5.4",
"symfony/yaml": "<6.4" "symfony/yaml": "<5.4"
}, },
"provide": { "provide": {
"symfony/translation-implementation": "2.3|3.0" "symfony/translation-implementation": "2.3|3.0"
@ -1658,17 +1578,17 @@
"require-dev": { "require-dev": {
"nikic/php-parser": "^4.18|^5.0", "nikic/php-parser": "^4.18|^5.0",
"psr/log": "^1|^2|^3", "psr/log": "^1|^2|^3",
"symfony/config": "^6.4|^7.0", "symfony/config": "^5.4|^6.0|^7.0",
"symfony/console": "^6.4|^7.0", "symfony/console": "^5.4|^6.0|^7.0",
"symfony/dependency-injection": "^6.4|^7.0", "symfony/dependency-injection": "^5.4|^6.0|^7.0",
"symfony/finder": "^6.4|^7.0", "symfony/finder": "^5.4|^6.0|^7.0",
"symfony/http-client-contracts": "^2.5|^3.0", "symfony/http-client-contracts": "^2.5|^3.0",
"symfony/http-kernel": "^6.4|^7.0", "symfony/http-kernel": "^5.4|^6.0|^7.0",
"symfony/intl": "^6.4|^7.0", "symfony/intl": "^5.4|^6.0|^7.0",
"symfony/polyfill-intl-icu": "^1.21", "symfony/polyfill-intl-icu": "^1.21",
"symfony/routing": "^6.4|^7.0", "symfony/routing": "^5.4|^6.0|^7.0",
"symfony/service-contracts": "^2.5|^3", "symfony/service-contracts": "^2.5|^3",
"symfony/yaml": "^6.4|^7.0" "symfony/yaml": "^5.4|^6.0|^7.0"
}, },
"type": "library", "type": "library",
"autoload": { "autoload": {
@ -1699,7 +1619,7 @@
"description": "Provides tools to internationalize your application", "description": "Provides tools to internationalize your application",
"homepage": "https://symfony.com", "homepage": "https://symfony.com",
"support": { "support": {
"source": "https://github.com/symfony/translation/tree/v7.0.7" "source": "https://github.com/symfony/translation/tree/v6.4.7"
}, },
"funding": [ "funding": [
{ {
@ -1715,7 +1635,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2024-04-18T09:29:19+00:00" "time": "2024-04-18T09:22:46+00:00"
}, },
{ {
"name": "symfony/translation-contracts", "name": "symfony/translation-contracts",

View File

@ -4,7 +4,7 @@ namespace Core;
use DI\ContainerBuilder; use DI\ContainerBuilder;
use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;
class BeanFactory class BeanFactory
{ {
@ -29,6 +29,7 @@ class BeanFactory
foreach ($handlers as $handler) { foreach ($handlers as $handler) {
self::$handlers = array_merge(self::$handlers, require_once($handler)); self::$handlers = array_merge(self::$handlers, require_once($handler));
} }
//扫描(重点) //扫描(重点)
$scans = [ $scans = [
//必须扫描的文件夹 //必须扫描的文件夹
@ -82,6 +83,7 @@ class BeanFactory
foreach (get_declared_classes() as $class) { foreach (get_declared_classes() as $class) {
if (strstr($class, $scanRootNamespace)) { if (strstr($class, $scanRootNamespace)) {
$refClass = new \ReflectionClass($class); $refClass = new \ReflectionClass($class);
//AnnotationRegistry::loadAnnotationClass($class);
//获取所有类的注释 //获取所有类的注释
$classAnnos = $reader->getClassAnnotations($refClass); $classAnnos = $reader->getClassAnnotations($refClass);
$instance = self::$container->get($refClass->getName()); $instance = self::$container->get($refClass->getName());

View File

@ -5,11 +5,20 @@ use Core\annotations\Bean;
use Core\annotations\Value; use Core\annotations\Value;
return [ return [
Bean::class => function ($instance, $container) { Bean::class => function ($instance, $container, $self) {
$arr = explode("\\", get_class($instance)); $vars = get_object_vars($self);
$beanName = end($arr); if (isset($vars['name']) && !empty($vars['name'])){
$beanName = $vars['name'];
}else{
$arrs = explode('\\',get_class($instance));
$beanName = end($arrs);
}
$container->set($beanName,$instance); $container->set($beanName,$instance);
}, },
Value::class => function () { Value::class => function (\ReflectionProperty $property, $instance, $self) {
$env = parse_ini_file(ROOT_PATH.'/.env');
if (!isset($env[$self->name]) || empty($self->name)) return $instance;
$property->setValue($instance,$env[$self->name]);
return $instance;
} }
]; ];

View File

@ -8,12 +8,23 @@ use Core\init\MyDB;
return [ return [
DB::class => function (\ReflectionProperty $prop, $instance, $self) { DB::class => function (\ReflectionProperty $property, $instance, $self) {
$mydbBean = BeanFactory::getBean(MyDB::class); //从新获取一个对象 if ($self->source != 'default') {
$mydbBean->setDbSource($self->source);//新MyDB对象设置数据源 $bean_name = MyDB::class.'_'.$self->source;
$prop->setAccessible(true); // $mydb_bean = BeanFactory::getBean($bean_name);//从新获取一个对象
$prop->setValue($instance, $mydbBean); if (!$mydb_bean) {
$mydb_bean = clone BeanFactory::getBean(MyDB::class);
$mydb_bean->setDbSource($self->source);//新MyDB对象设置数据源
BeanFactory::setBean($bean_name, $mydb_bean);//把新的对象塞进容器里面
} else {
$mydb_bean = clone $mydb_bean;
}
} else {
$mydb_bean = clone BeanFactory::getBean(MyDB::class);
}
$property->setAccessible(true);
$property->setValue($instance,$mydb_bean);
return $instance; return $instance;
} }
]; ];

View File

@ -4,35 +4,41 @@ namespace Core\annotationhandlers;
use Core\annotations\RequestMapping; use Core\annotations\RequestMapping;
use Core\BeanFactory; use Core\BeanFactory;
use Core\init\DecoratorCollector;
return [ return [
//$methodAnnoSelf 注解本身 //$methodAnnoSelf 注解本身
RequestMapping::class => function (\ReflectionMethod $method, $instance, $methodAnnoSelf) { RequestMapping::class => function (\ReflectionMethod $method, $instance, $self) {
$path = $methodAnnoSelf->value;//uri; $path = $self->value;//uri;
$requestMethod = count($methodAnnoSelf->method) > 0 ? $methodAnnoSelf->method : ['GET']; $requestMethod = $self->method ?: ['GET'];
$RouterCollector = BeanFactory::getBean("RouterCollector"); $RouterCollector = BeanFactory::getBean("RouterCollector");
//var_dump($RouterCollector); //var_dump($RouterCollector);
$RouterCollector->addRouter($requestMethod, $path, function ($params,$extParams) use ($method, $instance) { $RouterCollector->addRouter($requestMethod, $path, function ($params,$extParams) use ($method, $instance) {
$inputParams=[]; $inputParams=[];
//得到方法的反射参数
$refParams=$method->getParameters(); $refParams=$method->getParameters();
foreach ($refParams as $refParam){ foreach ($refParams as $refParam){
if(isset($params[$refParam->getName()])){ if(isset($params[$refParam->getName()])){
$inputParams[] = $params[$refParam->getName()]; $inputParams[] = $params[$refParam->getName()];
}else{ }else{
foreach($extParams as $extParam){ foreach($extParams as $extParam){
//$refParam->getClass 获取参数Request $request的类型 $type = $refParam->getType();
if($refParam->getClass()->isInstance($extParam)){ if ($type instanceof \ReflectionNamedType && !$type->isBuiltin()) {
$className = $type->getName();
if(class_exists($className)){
$reflectionClass = new \ReflectionClass($className);
if($reflectionClass->isInstance($extParam)){
$inputParams[] = $extParam; $inputParams[] = $extParam;
//continue; goto end;
goto abc; }
}
} }
} }
$inputParams[] = false; $inputParams[] = false;
} }
abc: end:
} }
return $method->invokeArgs($instance,$inputParams); return BeanFactory::getBean(DecoratorCollector::class)->exec($method,$instance,$inputParams);
//return $method->invokeArgs($instance,$inputParams);
//return $method->invoke($instance);//执行反射方法 //return $method->invoke($instance);//执行反射方法
}); });

View File

@ -9,5 +9,5 @@ namespace Core\annotations;
*/ */
class Bean class Bean
{ {
public $name;
} }

View File

@ -1,6 +1,9 @@
<?php <?php
namespace Core\annotations; namespace Core\annotations;
use Doctrine\Common\Annotations\Annotation\Target; use Doctrine\Common\Annotations\Annotation\Target;
/** /**
* @Annotation * @Annotation
* @Target({"METHOD"}) * @Target({"METHOD"})

View File

@ -6,13 +6,5 @@ namespace Core\annotations;
*/ */
class Value class Value
{ {
/*public $name; public $name;
public function do()
{
$env = parse_ini_file('./.env');
if (isset($env[$this->name])) {
return $env[$this->name];
}
return false;
}*/
} }

View File

@ -26,13 +26,17 @@ class Response
public function end() public function end()
{ {
$jsonConver = ['array']; $jsonConver = ['array', 'object'];
$res = $this->getBody(); $body = $this->getBody();
if (in_array(gettype($res), $jsonConver)) { if (in_array(gettype($body), $jsonConver)) {
$this->swooleResponse->header("Content-type","application/json;charset=utf-8"); $this->swooleResponse->header("Content-type","application/json;charset=utf-8");
$res = json_encode($res, 256); $res = json_encode($body, 256);
}
$this->swooleResponse->write($res); $this->swooleResponse->write($res);
}else{
if ($body) {
$this->swooleResponse->write($body);
}
}
$this->swooleResponse->end(); $this->swooleResponse->end();
} }

View File

@ -0,0 +1,20 @@
<?php
namespace Core\init;
use Core\annotations\Bean;
/**
* Class DecoratorCollector 装饰器收集类
* @Bean()
*/
class DecoratorCollector{
public $dSet=[];
public function exec(\ReflectionMethod $method,$instance,$inputParams){
$key=get_class($instance)."::".$method->getName();
if(isset($this->dSet[$key])){
$func=$this->dSet[$key];
return $func($method->getClosure($instance))($inputParams);//装饰执行
}
return $method->invokeArgs($instance,$inputParams);//原样执行
}
}

View File

@ -1,6 +1,8 @@
<?php <?php
namespace Core\init; namespace Core\init;
use Core\annotations\Bean; use Core\annotations\Bean;
use Core\BeanFactory;
use Core\lib\PDOPool;
use Illuminate\Database\Capsule\Manager as lvDB; use Illuminate\Database\Capsule\Manager as lvDB;
/** /**
@ -13,30 +15,64 @@ class MyDB
private $lvDB; private $lvDB;
private $dbSource='default'; private $dbSource='default';
private $transctionDB = false;
/**
* @var PDOPool
*/
public $pdopool;
public function __construct() public function __construct($db_obj = false)
{ {
global $GLOBAL_CONFIGD; global $GLOBAL_CONFIGS;
if (isset($GLOBAL_CONFIGD['db'])) { if (isset($GLOBAL_CONFIGS['db'])) {
$this->lvDB = new LvDb(); $this->lvDB = new LvDb();
$configs = $GLOBAL_CONFIGD['db']; $configs = $GLOBAL_CONFIGS['db'];
foreach ($configs as $key => $config){ foreach ($configs as $key => $config){
$this->lvDB->addConnection($config,$key); $this->lvDB->addConnection($config,$key);
} }
$this->lvDB->addConnection($GLOBAL_CONFIGD['db']['default']); $this->lvDB->addConnection(["driver"=>"mysql"], $key);
//设置全局静态访问 //设置全局静态访问
$this->lvDB->setAsGlobal(); $this->lvDB->setAsGlobal();
//启动Eloquent //启动Eloquent
$this->lvDB->bootEloquent(); $this->lvDB->bootEloquent();
} }
$this->transctionDB = $db_obj;
$this->pdopool = BeanFactory::getBean(PDOPool::class);
if ($db_obj) {
$this->lvDB->getConnection($this->dbSource)->setPdo($this->transctionDB->db);
$this->lvDB->getConnection($this->dbSource)->beginTransaction();
}
} }
public function __call($methodName, $arguments) public function __call($methodName, $arguments)
{ {
//用。。。解构数组
return $this->lvDB::$methodName(...$arguments); try{
if ($this->transctionDB) {//事务对象
$pdo_object = $this->transctionDB;
$isTranstion = true;
}else{
$isTranstion = false;
$pdo_object = $this->pdopool->getConnection();
$this->lvDB->getConnection($this->dbSource)->setPdo($pdo_object->db);//设置pdo对象
}
if ($methodName == 'model') {
return $arguments[0];
}
$ret = $this->lvDB::connection($this->dbSource)->$methodName(...$arguments);
return $ret;
}catch (\Exception $exception){
return null;
}finally{
if($pdo_object && ! $isTranstion){
$this->pdopool->close($pdo_object); //放回连接
}
} }
//return $ret;
//用。。。解构数组
//return $this->lvDB::$methodName(...$arguments);
}
public function setDbSource($dbSource) public function setDbSource($dbSource)
{ {
$this->dbSource = $dbSource; $this->dbSource = $dbSource;
@ -45,4 +81,46 @@ class MyDB
{ {
return $this->dbSource; return $this->dbSource;
} }
/**
* 开启事务
*/
public function Begin()
{
return new self($this->pdopool->getConnection());
}
/**
* 提交事务
*/
public function Commit()
{
try{
$this->lvDB->getConnection($this->dbSource)->commit();
}
finally{
if ($this->transctionDB) {
$this->pdopool->close($this->transctionDB);
$this->transctionDB = false;
}
}
}
/**
* 事务回滚
*/
public function RollBack()
{
try{
$this->lvDB->getConnection($this->dbSource)->rollBack();
}catch (\Exception $exception) {
return $exception->getMessage();
}
finally{
if ($this->transctionDB) {
$this->pdopool->close($this->transctionDB);
$this->transctionDB = false;
}
}
}
} }

9
core/lib/DBModel.php Normal file
View File

@ -0,0 +1,9 @@
<?php
namespace Core\lib;
use Illuminate\Database\Eloquent\Model;
class DBModel extends Model
{
}

93
core/lib/DBPool.php Normal file
View File

@ -0,0 +1,93 @@
<?php
namespace Core\lib;
abstract class DBPool
{
private $min;
private $max;
private $conns;
private $count;
private $idleTime = 40;
abstract protected function newDB();
function __construct($min = 5, $max = 10)
{
$this->min = $min;
$this->max = $max;
$this->conns = new \Swoole\Coroutine\Channel($this->max);
for ($i = 0; $i < $min; $i++) {
$this->addDBToPool();
}
}
public function initPool()
{
/*for ($i = 0; $i < $this->min; $i++) {
$db = $this->newDB();
$this->conns->push($db);
}
$this->count = $this->min;*/
}
public function getConnection()
{
if($this->conns->isEmpty()){
if ($this->count < $this->max) {
$this->addDBToPool();
$dbObject = $this->conns->pop();
}else{
$dbObject = $this->conns->pop(5);
}
}else{
$dbObject = $this->conns->pop();
}
if ($dbObject) {
$dbObject->usedTime = time();
}
return $dbObject;
}
public function close($conn)
{
if ($conn) {
$this->conns->push($conn);
}
}
public function addDBToPool()
{
try {
$this->count++;
$db = $this->newDB();
if (!$db) throw new \Exception('db创建错误');
$dbObject = new \stdClass();
$dbObject->usedTime = time();
$dbObject->db = $db;
$this->conns->push($dbObject);
}catch (\Exception $e) {
$this->count--;
}
}
public function cleanPool()
{
if ($this->conns->length() < $this->min && $this->conns->length()<intval($this->max*0.6)) {
return ;
}
$dbbak = [];
while (true) {
if($this->conns->isEmpty()) {
break;
}
$obj = $this->conns->pop(0.1);
if($this->count > $this->min && (time()-$obj->usedTime) > $this->idleTime){
$this->count--;
} else{
$dbbak[] = $obj;
}
}
foreach ($dbbak as $db){
$this->conns->push($db);
}
}
}

60
core/lib/Models.php Normal file
View File

@ -0,0 +1,60 @@
<?php
namespace Core\lib;
use Core\BeanFactory;
use Core\init\MyDB;
use Illuminate\Database\Eloquent\Model;
class Models extends Model
{
public function __call($method, $parameters)
{
return $this->invoke(function () use ($method, $parameters){
return parent::__call($method, $parameters);
});
}
public function save(array $options = [])
{
return $this->invoke(function () use ($options){
return parent::save($options);
});
}
public function update(array $attributes = [], array $options = [])
{
return $this->invoke(function () use ($attributes, $options){
return parent::update($attributes, $options);
});
}
public static function all($columns = ['*'])
{
return self::invokeStatic(function () use ($columns){
return parent::all($columns);
});
}
public function invoke(callable $func)
{
$mydb = clone BeanFactory::getBean(MyDB::class);
$obj = $mydb->model($func);
try{
return $obj();
}catch (\Exception $exception){
return $exception->getMessage();
}
}
public static function invokeStatic(callable $func)
{
$mydb = clone BeanFactory::getBean(MyDB::class);
$obj = $mydb->model($func);
try{
return $obj();
}catch (\Exception $exception){
return $exception->getMessage();
}
}
}

31
core/lib/PDOPool.php Normal file
View File

@ -0,0 +1,31 @@
<?php
namespace Core\lib;
class PDOPool extends DBPool
{
public function __construct($min = 5, $max = 10)
{
global $GLOBAL_CONFIGS;
$poolconfig = $GLOBAL_CONFIGS["dbpool"]["default"];
parent::__construct($poolconfig['min'], $poolconfig['max']);
//\Swoole\Runtime::enableCoroutine(true);
}
protected function newDB()
{
global $GLOBAL_CONFIGS;
$default = $GLOBAL_CONFIGS["db"]["default"];
{
$driver = $default["driver"];
$host = $default["host"];
$dbname = $default['database'];
$username = $default["username"];
$password = $default["password"];
$dsn = "$driver:host=$host;dbname=$dbname";
}
$pdo = new \PDO($dsn, $username, $password);
return $pdo;
}
}

View File

@ -11,6 +11,7 @@ class HttpServer
public function __construct($str = 'dd') public function __construct($str = 'dd')
{ {
var_dump($str);
if ($str == 'dd') return; if ($str == 'dd') return;
$this->server = new Server("0.0.0.0",8085); $this->server = new Server("0.0.0.0",8085);
//配置参数 https://wiki.swoole.com/#/server/setting //配置参数 https://wiki.swoole.com/#/server/setting
@ -39,7 +40,7 @@ class HttpServer
public function onStart(Server $server) public function onStart(Server $server)
{ {
$mid = $server->master_pid; //返回当前服务器主进程的 PID。 $mid = $server->master_pid; //返回当前服务器主进程的 PID。
file_put_contents("./ttt.pid", $mid); //会覆盖 file_put_contents("./Buddha.pid", $mid); //会覆盖
} }
public function onRequset($request, $response) public function onRequset($request, $response)
{ {
@ -69,14 +70,14 @@ class HttpServer
public function onShutDown(Server $server) public function onShutDown(Server $server)
{ {
echo '关闭了' . PHP_EOL; echo '关闭了' . PHP_EOL;
unlink("./ttt.pid"); unlink("./Buddha.pid");
} }
public function run() public function run()
{ {
$p = new TestProcess(); $p = new TestProcess();
//$this->server->addProcess($p->run()); //$this->server->addProcess($p->run());
echo '就要启动了'; echo '就要启动了喂......' . PHP_EOL;
$this->server->start(); $this->server->start();
} }
} }

24
pool.php Normal file
View File

@ -0,0 +1,24 @@
<?php
require __DIR__."/vendor/autoload.php";
go(function (){
$pool = new \baihand\pool\CoMySqlPool();
$pool->initPool();
for ($i = 0; $i < 5; $i++) {
go(function () use($pool,$i) {
$conn = $pool->getConnection();
defer(function () use ($pool,$conn){
//defer写在前 是怕后面的执行语句不一定成功
$pool->close($conn); // 放回链接
//channel对connection进行了引用
});
$state = $conn->query(" select $i");
var_dump($state);
});
}
while (true){
echo "链接了\n";
\Swoole\Coroutine::sleep(1);
}
});

22
pool/CoMySqlPool.php Normal file
View File

@ -0,0 +1,22 @@
<?php
namespace baihand\pool;
class CoMySqlPool extends DBPool
{
public function __construct($min = 5, $max = 10)
{
parent::__construct($min, $max);
}
protected function newDB()
{
$mysql = new \Swoole\Coroutine\MySQL();
$mysql ->connect([
'host'=>'127.0.0.1',
'user'=>'root',
'password'=>'123456',
'database'=>'saiadmin'
]);
return $mysql;
}
}

View File

@ -1 +0,0 @@
1023