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
return [
'default' => [
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'blog',
'username' => 'blog',
'password' => 'fj6edWTinXimLpiT',
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_general_ci',
'prefix' => 'eb_',
]
'driver' => 'mysql',
'host' => '127.0.0.1',
'database' => 'saiadmin',
'username' => 'root',
'password' => '123456',
'port' => 3306,
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_general_ci',
'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__)));
$GLOBAL_CONFIGD= [
'db'=> require_once (__DIR__."/db.php"),
'redis'=>[]
$GLOBAL_CONFIGS = [
'db' => require_once(__DIR__ . "/db.php"),
'dbpool' => require_once(__DIR__ . '/dbpool.php'),
];

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -5,11 +5,20 @@ use Core\annotations\Bean;
use Core\annotations\Value;
return [
Bean::class => function ($instance, $container) {
$arr = explode("\\", get_class($instance));
$beanName = end($arr);
$container->set($beanName, $instance);
Bean::class => function ($instance, $container, $self) {
$vars = get_object_vars($self);
if (isset($vars['name']) && !empty($vars['name'])){
$beanName = $vars['name'];
}else{
$arrs = explode('\\',get_class($instance));
$beanName = end($arrs);
}
$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 [
DB::class => function (\ReflectionProperty $prop, $instance, $self) {
$mydbBean = BeanFactory::getBean(MyDB::class); //从新获取一个对象
$mydbBean->setDbSource($self->source);//新MyDB对象设置数据源
$prop->setAccessible(true); //
$prop->setValue($instance, $mydbBean);
DB::class => function (\ReflectionProperty $property, $instance, $self) {
if ($self->source != 'default') {
$bean_name = MyDB::class.'_'.$self->source;
$mydb_bean = BeanFactory::getBean($bean_name);//从新获取一个对象
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;
}
];

View File

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

View File

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

View File

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

View File

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

View File

@ -26,13 +26,17 @@ class Response
public function end()
{
$jsonConver = ['array'];
$res = $this->getBody();
if (in_array(gettype($res), $jsonConver)) {
$jsonConver = ['array', 'object'];
$body = $this->getBody();
if (in_array(gettype($body), $jsonConver)) {
$this->swooleResponse->header("Content-type","application/json;charset=utf-8");
$res = json_encode($res, 256);
$res = json_encode($body, 256);
$this->swooleResponse->write($res);
}else{
if ($body) {
$this->swooleResponse->write($body);
}
}
$this->swooleResponse->write($res);
$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
namespace Core\init;
use Core\annotations\Bean;
use Core\BeanFactory;
use Core\lib\PDOPool;
use Illuminate\Database\Capsule\Manager as lvDB;
/**
@ -13,30 +15,64 @@ class MyDB
private $lvDB;
private $dbSource='default';
private $transctionDB = false;
/**
* @var PDOPool
*/
public $pdopool;
public function __construct()
public function __construct($db_obj = false)
{
global $GLOBAL_CONFIGD;
if (isset($GLOBAL_CONFIGD['db'])) {
global $GLOBAL_CONFIGS;
if (isset($GLOBAL_CONFIGS['db'])) {
$this->lvDB = new LvDb();
$configs = $GLOBAL_CONFIGD['db'];
$configs = $GLOBAL_CONFIGS['db'];
foreach ($configs as $key => $config){
$this->lvDB->addConnection($config,$key);
}
$this->lvDB->addConnection($GLOBAL_CONFIGD['db']['default']);
$this->lvDB->addConnection(["driver"=>"mysql"], $key);
//设置全局静态访问
$this->lvDB->setAsGlobal();
//启动Eloquent
$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)
{
//用。。。解构数组
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)
{
$this->dbSource = $dbSource;
@ -45,4 +81,46 @@ class MyDB
{
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')
{
var_dump($str);
if ($str == 'dd') return;
$this->server = new Server("0.0.0.0",8085);
//配置参数 https://wiki.swoole.com/#/server/setting
@ -39,7 +40,7 @@ class HttpServer
public function onStart(Server $server)
{
$mid = $server->master_pid; //返回当前服务器主进程的 PID。
file_put_contents("./ttt.pid", $mid); //会覆盖
file_put_contents("./Buddha.pid", $mid); //会覆盖
}
public function onRequset($request, $response)
{
@ -69,14 +70,14 @@ class HttpServer
public function onShutDown(Server $server)
{
echo '关闭了' . PHP_EOL;
unlink("./ttt.pid");
unlink("./Buddha.pid");
}
public function run()
{
$p = new TestProcess();
//$this->server->addProcess($p->run());
echo '就要启动了';
echo '就要启动了喂......' . PHP_EOL;
$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