Compare commits

..

250 Commits

Author SHA1 Message Date
as2252258 24b69507b2 改名 2021-11-29 11:44:03 +08:00
as2252258 8b45c90a04 1 2021-11-28 19:37:07 +08:00
as2252258 95ae1fe999 1 2021-11-27 17:58:17 +08:00
as2252258 9668830ee2 1 2021-11-27 17:45:39 +08:00
as2252258 f26539c41f 1 2021-11-27 17:43:29 +08:00
as2252258 3ead688d5f Merge remote-tracking branch 'origin/master' 2021-11-26 11:28:37 +08:00
as2252258 157c233ed6 改名 2021-11-26 11:27:55 +08:00
as2252258 40b4c2a4c9 1 2021-11-24 23:46:26 +08:00
as2252258 a7db58d7e4 改名 2021-11-24 17:07:35 +08:00
as2252258 87e4bfdbec 改名 2021-11-24 17:07:13 +08:00
as2252258 ee761817bf 1 2021-11-21 01:30:49 +08:00
as2252258 4a4b7db651 1 2021-11-20 02:33:53 +08:00
as2252258 905427bccc 1 2021-11-20 02:30:13 +08:00
as2252258 68ee0244a2 1 2021-11-20 02:27:25 +08:00
as2252258 7e43775b04 改名 2021-11-19 18:27:17 +08:00
as2252258 dd4e9be06a 改名 2021-11-19 18:25:54 +08:00
as2252258 73b01c288b 改名 2021-11-19 18:23:06 +08:00
as2252258 f4f48ebad7 改名 2021-11-19 18:21:59 +08:00
as2252258 ef95f912cb 改名 2021-11-19 18:19:02 +08:00
as2252258 8bbb6adcc7 改名 2021-11-19 18:15:05 +08:00
as2252258 a855765365 改名 2021-11-19 18:13:48 +08:00
as2252258 3110e69350 改名 2021-11-19 17:11:17 +08:00
as2252258 4862e7e913 改名 2021-11-19 14:49:22 +08:00
as2252258 0a52bd502b 改名 2021-11-19 12:28:08 +08:00
as2252258 95492e2863 改名 2021-11-19 11:25:50 +08:00
as2252258 3cc0a9bef2 改名 2021-11-19 11:25:06 +08:00
as2252258 d743382868 改名 2021-11-19 11:24:08 +08:00
as2252258 47f1407118 改名 2021-11-19 11:21:02 +08:00
as2252258 04395f293d 改名 2021-11-19 11:20:25 +08:00
as2252258 a44b7a31ef 改名 2021-11-19 11:19:46 +08:00
as2252258 493ef65ce8 改名 2021-11-19 11:15:40 +08:00
as2252258 3943142b86 改名 2021-11-19 11:13:32 +08:00
as2252258 786f96363b 改名 2021-11-19 11:11:40 +08:00
as2252258 bcf73a8cad 改名 2021-11-19 11:05:08 +08:00
as2252258 2b152504ec 改名 2021-11-19 11:03:55 +08:00
as2252258 e554ad3642 改名 2021-11-19 11:03:38 +08:00
as2252258 c801aec334 改名 2021-11-19 11:03:18 +08:00
as2252258 2c2c16819a 改名 2021-11-19 11:02:49 +08:00
as2252258 a48aa9a20f 改名 2021-11-19 11:02:31 +08:00
as2252258 8dadcbed16 改名 2021-11-19 11:02:08 +08:00
as2252258 86dd776388 改名 2021-11-19 11:00:10 +08:00
as2252258 d83d0871f5 改名 2021-11-19 10:59:53 +08:00
as2252258 fc6baa83a7 改名 2021-11-19 10:59:32 +08:00
as2252258 35dd2803fc 改名 2021-11-19 10:55:52 +08:00
as2252258 e3527752a7 改名 2021-11-19 10:54:30 +08:00
as2252258 340e0f1686 改名 2021-11-19 10:54:06 +08:00
as2252258 2ad6153405 改名 2021-11-19 10:41:17 +08:00
as2252258 0f172ae62d 改名 2021-11-19 10:40:49 +08:00
as2252258 f4596bf02c 改名 2021-11-19 10:37:12 +08:00
as2252258 ef4f84f696 改名 2021-11-19 10:36:55 +08:00
as2252258 08d19c9c05 改名 2021-11-19 10:36:33 +08:00
as2252258 e0537f2ee4 改名 2021-11-19 10:36:07 +08:00
as2252258 0edcf8c83f 改名 2021-11-19 10:31:43 +08:00
as2252258 6ac2c73a8c 改名 2021-11-19 10:31:26 +08:00
as2252258 b1a5db0a6b 改名 2021-11-19 10:29:46 +08:00
as2252258 8ec1a81ecd 改名 2021-11-19 10:20:49 +08:00
as2252258 b98de03317 改名 2021-11-19 10:12:53 +08:00
as2252258 251bca3d64 Merge remote-tracking branch 'origin/master'
# Conflicts:
#	kiri-engine/FileListen/HotReload.php
2021-11-19 10:11:55 +08:00
as2252258 b2a79ef0ed 改名 2021-11-19 10:10:48 +08:00
as2252258 d9451f5087 1 2021-11-19 04:11:29 +08:00
as2252258 84d8dda8eb 1 2021-11-19 04:10:55 +08:00
as2252258 1d846a4903 1 2021-11-19 04:10:41 +08:00
as2252258 fe4f985315 1 2021-11-19 04:09:28 +08:00
as2252258 c5c1d991f2 1 2021-11-19 04:08:16 +08:00
as2252258 9ec6573ca4 1 2021-11-19 04:04:44 +08:00
as2252258 9800024d59 1 2021-11-19 04:04:36 +08:00
as2252258 57b2214433 1 2021-11-19 04:03:01 +08:00
as2252258 2f038e5637 1 2021-11-19 04:02:40 +08:00
as2252258 0f238f488d 1 2021-11-19 04:00:31 +08:00
as2252258 59243a6fed 1 2021-11-19 03:59:36 +08:00
as2252258 fbd7f874ac 1 2021-11-19 03:59:15 +08:00
as2252258 7aee3c8458 1 2021-11-19 03:59:04 +08:00
as2252258 f3446da34e 1 2021-11-19 03:57:24 +08:00
as2252258 755594b4bb 1 2021-11-19 03:54:31 +08:00
as2252258 abcf5e9feb 1 2021-11-19 03:53:57 +08:00
as2252258 f243e19b24 1 2021-11-19 03:52:44 +08:00
as2252258 5d91b61f83 1 2021-11-19 03:51:41 +08:00
as2252258 d3ed35e948 1 2021-11-19 03:50:47 +08:00
as2252258 c5bfe8110a 1 2021-11-19 03:48:54 +08:00
as2252258 1c18ee94ee 1 2021-11-19 03:48:16 +08:00
as2252258 f72c73766d 1 2021-11-19 03:46:29 +08:00
as2252258 092139c0b9 1 2021-11-19 03:46:10 +08:00
as2252258 43a1fad278 1 2021-11-19 03:45:18 +08:00
as2252258 dbc4cb15dd 1 2021-11-19 03:43:29 +08:00
as2252258 758bd650b5 1 2021-11-19 03:43:00 +08:00
as2252258 ba804c4d9c 1 2021-11-19 03:42:23 +08:00
as2252258 cac794ca20 1 2021-11-19 03:37:57 +08:00
as2252258 ea09d3e3ba 1 2021-11-19 03:36:35 +08:00
as2252258 f6552c45ae 1 2021-11-19 03:27:30 +08:00
as2252258 114f5d0279 1 2021-11-19 03:27:07 +08:00
as2252258 5638d171d0 1 2021-11-19 03:24:09 +08:00
as2252258 fa78d360b0 1 2021-11-19 03:21:21 +08:00
as2252258 ffc35090b9 1 2021-11-19 03:03:15 +08:00
as2252258 5156a606e0 1 2021-11-19 03:03:00 +08:00
as2252258 2393ef820f 1 2021-11-19 03:01:17 +08:00
as2252258 9986900b58 1 2021-11-19 02:56:34 +08:00
as2252258 07c52ef08f 1 2021-11-19 02:55:34 +08:00
as2252258 0a6fdda720 1 2021-11-19 02:54:05 +08:00
as2252258 841a6b4a19 1 2021-11-19 02:50:39 +08:00
as2252258 873da66a90 1 2021-11-19 02:20:04 +08:00
as2252258 be9f4281e6 改名 2021-11-18 19:01:11 +08:00
as2252258 57be085166 改名 2021-11-18 18:41:37 +08:00
as2252258 454c77f37a 改名 2021-11-18 17:59:46 +08:00
as2252258 323a4b8ff0 改名 2021-11-18 17:58:46 +08:00
as2252258 c66e5120e1 改名 2021-11-18 17:55:52 +08:00
as2252258 1fa7d3a3ba 改名 2021-11-18 17:50:05 +08:00
as2252258 a290108ddd 改名 2021-11-18 16:44:55 +08:00
as2252258 446fd740f2 改名 2021-11-18 16:42:24 +08:00
as2252258 a040099b99 改名 2021-11-18 16:38:55 +08:00
as2252258 78fdc7c1ca 改名 2021-11-18 16:38:43 +08:00
as2252258 dfc249b56c 改名 2021-11-18 16:31:41 +08:00
as2252258 577be309cc 改名 2021-11-18 16:30:34 +08:00
as2252258 9798be99e6 改名 2021-11-18 15:57:38 +08:00
as2252258 e3348a11c8 改名 2021-11-18 15:37:11 +08:00
as2252258 1643a839b3 改名 2021-11-18 11:37:13 +08:00
as2252258 d4a15d26ed 改名 2021-11-17 16:43:55 +08:00
as2252258 485d926dc0 改名 2021-11-17 16:39:12 +08:00
as2252258 6a5205e9a1 1 2021-11-11 02:22:14 +08:00
as2252258 471f7a92bb 1 2021-11-11 01:32:04 +08:00
as2252258 429ffe561c 改名 2021-11-08 11:12:53 +08:00
as2252258 27cdf5082f 改名 2021-11-08 11:10:58 +08:00
as2252258 4c3751ca4d 1 2021-11-07 03:18:27 +08:00
as2252258 5f1eaf8239 改名 2021-11-05 18:54:04 +08:00
as2252258 8b76ef8e41 改名 2021-11-05 14:45:24 +08:00
as2252258 981a800053 改名 2021-11-05 14:44:10 +08:00
as2252258 79544f1ad1 改名 2021-11-05 14:38:11 +08:00
as2252258 93bd3d3f69 改名 2021-11-05 14:35:16 +08:00
as2252258 975f6f85a2 改名 2021-11-05 14:27:13 +08:00
as2252258 5a99181eaf 改名 2021-11-05 14:25:32 +08:00
as2252258 da5d74f519 改名 2021-11-05 14:24:49 +08:00
as2252258 c878ed0ba4 改名 2021-11-05 14:22:57 +08:00
as2252258 e7e24a1488 改名 2021-11-05 11:30:32 +08:00
as2252258 3dba884f64 改名 2021-11-05 11:07:06 +08:00
as2252258 4b30a59f6a 改名 2021-11-05 11:04:45 +08:00
as2252258 704c0808ea 改名 2021-11-05 11:04:24 +08:00
as2252258 e738b084b4 改名 2021-11-05 11:03:00 +08:00
as2252258 77aa761e82 改名 2021-11-05 11:01:42 +08:00
as2252258 49ac53e751 改名 2021-11-05 10:58:34 +08:00
as2252258 2c0a431069 111 2021-11-05 01:24:08 +08:00
as2252258 61893335ae 111 2021-11-05 01:23:41 +08:00
as2252258 f87ddff585 111 2021-11-05 01:23:22 +08:00
as2252258 edcd873ff3 111 2021-11-05 01:22:16 +08:00
as2252258 3ac7720f5b 111 2021-11-05 01:21:47 +08:00
as2252258 a1fc45c3d7 111 2021-11-05 01:19:31 +08:00
as2252258 ac01000524 111 2021-11-05 01:16:22 +08:00
as2252258 0a313e2b99 111 2021-11-05 01:14:47 +08:00
as2252258 18b77760cd 111 2021-11-05 01:14:27 +08:00
as2252258 65a874c155 111 2021-11-05 01:14:01 +08:00
as2252258 1bf851ff6b 111 2021-11-05 01:13:02 +08:00
as2252258 3309b101b6 111 2021-11-05 01:12:45 +08:00
as2252258 27d8caec00 111 2021-11-05 01:12:36 +08:00
as2252258 0cb14bd24b 111 2021-11-05 01:11:50 +08:00
as2252258 133455a041 111 2021-11-05 01:11:32 +08:00
as2252258 9c5ba4b3e9 111 2021-11-05 01:10:58 +08:00
as2252258 6db849de8d 111 2021-11-05 01:10:42 +08:00
as2252258 5506b3e725 111 2021-11-05 01:09:59 +08:00
as2252258 d1ccbbb5e0 111 2021-11-05 01:09:20 +08:00
as2252258 c8c95d9dc9 111 2021-11-05 01:08:40 +08:00
as2252258 7d0ce48cd0 111 2021-11-05 01:07:43 +08:00
as2252258 c66b76d0be 111 2021-11-05 01:07:23 +08:00
as2252258 febc53147e 111 2021-11-05 01:05:26 +08:00
as2252258 c6279d6214 111 2021-11-05 01:05:01 +08:00
as2252258 8deea95fb8 111 2021-11-05 01:01:13 +08:00
as2252258 2512044bc5 111 2021-11-05 00:59:38 +08:00
as2252258 3a1a124db3 111 2021-11-05 00:58:03 +08:00
as2252258 d2df0cbc1a 111 2021-11-05 00:57:34 +08:00
as2252258 15b6ac1b79 111 2021-11-05 00:55:20 +08:00
as2252258 8fb60fcd76 111 2021-11-05 00:54:37 +08:00
as2252258 c8149e3754 111 2021-11-05 00:41:25 +08:00
as2252258 f49af928b6 111 2021-11-05 00:40:53 +08:00
as2252258 63aadcb31f 111 2021-11-05 00:39:53 +08:00
as2252258 5f1fd4d93c 111 2021-11-05 00:38:51 +08:00
as2252258 84e8d26371 111 2021-11-05 00:38:26 +08:00
as2252258 85fc29e76c 111 2021-11-05 00:36:55 +08:00
as2252258 ad568fa3a7 111 2021-11-05 00:36:34 +08:00
as2252258 ea8d4d9611 111 2021-11-05 00:34:12 +08:00
as2252258 d3e74965f9 111 2021-11-05 00:33:15 +08:00
as2252258 389c376c43 111 2021-11-05 00:32:52 +08:00
as2252258 81eeaa64e4 111 2021-11-05 00:25:47 +08:00
as2252258 fbad6d9938 111 2021-11-05 00:24:08 +08:00
as2252258 825539c792 111 2021-11-05 00:23:31 +08:00
as2252258 c73fe2d609 111 2021-11-05 00:21:42 +08:00
as2252258 ac66f768c3 111 2021-11-05 00:20:30 +08:00
as2252258 84e2998139 111 2021-11-05 00:14:54 +08:00
as2252258 19cab4f333 111 2021-11-05 00:13:52 +08:00
as2252258 7d8c50aed8 111 2021-11-05 00:12:13 +08:00
as2252258 8d98dc83be 111 2021-11-05 00:08:43 +08:00
as2252258 3adea33afe 111 2021-11-05 00:06:41 +08:00
as2252258 55250de396 111 2021-11-05 00:03:16 +08:00
as2252258 5fffe53022 111 2021-11-05 00:02:43 +08:00
as2252258 7a0ff2fbc5 111 2021-11-04 23:52:12 +08:00
as2252258 4f539f4e78 111 2021-11-04 23:50:26 +08:00
as2252258 9af827a11e 111 2021-11-04 23:49:35 +08:00
as2252258 3ddec68d7f 111 2021-11-04 23:48:53 +08:00
as2252258 a5519b927b 111 2021-11-04 23:46:44 +08:00
as2252258 8add22f589 111 2021-11-04 23:44:47 +08:00
as2252258 54f60e8765 111 2021-11-04 23:41:15 +08:00
as2252258 6a60b03678 111 2021-11-04 23:39:40 +08:00
as2252258 878e3b262b 111 2021-11-04 23:12:57 +08:00
as2252258 a3ad2a6f17 改名 2021-11-04 19:01:09 +08:00
as2252258 79b32df2d5 改名 2021-11-04 19:00:53 +08:00
as2252258 f40b79bb08 改名 2021-11-04 18:58:10 +08:00
as2252258 ee380aa520 改名 2021-11-04 18:57:49 +08:00
as2252258 dbf91656cb 改名 2021-11-04 18:57:13 +08:00
as2252258 52845dfdb8 改名 2021-11-04 18:56:54 +08:00
as2252258 78c187e49f 改名 2021-11-04 18:53:58 +08:00
as2252258 fe105bd7d2 改名 2021-11-04 18:53:31 +08:00
as2252258 021e9ea23a 改名 2021-11-04 18:47:32 +08:00
as2252258 794165fa67 改名 2021-11-04 18:47:23 +08:00
as2252258 6ef0f8b412 改名 2021-11-04 18:46:57 +08:00
as2252258 fcb8630095 改名 2021-11-04 18:43:19 +08:00
as2252258 ceafc139db 改名 2021-11-04 18:42:58 +08:00
as2252258 283c7c2371 改名 2021-11-04 18:42:26 +08:00
as2252258 0b170cafb2 改名 2021-11-04 18:42:05 +08:00
as2252258 d036f730ca 改名 2021-11-04 18:39:35 +08:00
as2252258 55727bb219 改名 2021-11-04 18:38:06 +08:00
as2252258 dc477978d3 改名 2021-11-04 18:37:31 +08:00
as2252258 7dda29a892 改名 2021-11-04 18:37:01 +08:00
as2252258 567cac606a 改名 2021-11-04 18:36:38 +08:00
as2252258 49d435e4a5 改名 2021-11-04 18:36:17 +08:00
as2252258 5303c05274 改名 2021-11-04 18:34:19 +08:00
as2252258 f6cb258259 改名 2021-11-04 18:33:57 +08:00
as2252258 affb161ddf 改名 2021-11-04 18:29:52 +08:00
as2252258 a80f671a22 改名 2021-11-04 18:29:29 +08:00
as2252258 497cd95731 改名 2021-11-04 18:27:41 +08:00
as2252258 3ae85beb16 改名 2021-11-04 18:25:03 +08:00
as2252258 0a76e991b9 改名 2021-11-04 18:24:42 +08:00
as2252258 bfc591b10a 改名 2021-11-04 18:23:58 +08:00
as2252258 b274140708 改名 2021-11-04 18:23:24 +08:00
as2252258 a4a9a5618d 改名 2021-11-04 18:22:42 +08:00
as2252258 0cf17a547e 改名 2021-11-04 18:21:29 +08:00
as2252258 35ea526420 改名 2021-11-04 18:16:34 +08:00
as2252258 8ba04b4ccc 改名 2021-11-04 18:15:56 +08:00
as2252258 b83a0c4c96 改名 2021-11-04 18:09:13 +08:00
as2252258 21d3738125 改名 2021-11-04 18:06:45 +08:00
as2252258 2bd18b014d 改名 2021-11-04 18:06:10 +08:00
as2252258 39be8f4b3b 改名 2021-11-04 18:03:24 +08:00
as2252258 043b62688b 改名 2021-11-04 18:02:33 +08:00
as2252258 38f5f57c4d 改名 2021-11-04 17:59:04 +08:00
as2252258 2c7a755663 改名 2021-11-04 17:58:56 +08:00
as2252258 187b4311eb 改名 2021-11-04 17:56:39 +08:00
as2252258 7d2c2cf7ff 改名 2021-11-04 17:48:27 +08:00
as2252258 3771a8fb22 改名 2021-11-04 17:47:50 +08:00
as2252258 7561bacda5 改名 2021-11-04 17:46:44 +08:00
as2252258 c7d6032010 改名 2021-11-04 17:45:53 +08:00
as2252258 48d9c5ce79 改名 2021-11-04 17:40:11 +08:00
as2252258 b9d2288ac7 改名 2021-11-04 17:38:37 +08:00
as2252258 13877c6d58 改名 2021-11-04 17:37:38 +08:00
as2252258 320a01d822 改名 2021-11-04 17:34:20 +08:00
as2252258 a435df8453 改名 2021-11-04 17:33:41 +08:00
34 changed files with 848 additions and 1347 deletions
+3
View File
@@ -4,8 +4,11 @@ namespace PHPSTORM_META {
// Reflect
use Kiri\Di\Container;
use Psr\Container\ContainerInterface;
override(ContainerInterface::get(0), map('@'));
override(Container::get(0), map('@'));
override(Container::make(0), map('@'));
override(Container::create(0), map('@'));
// override(\Hyperf\Utils\Context::get(0), map('@'));
// override(\make(0), map('@'));
+5 -4
View File
@@ -21,16 +21,17 @@
"ext-xml": "*",
"ext-curl": "*",
"ext-openssl": "*",
"symfony/console": "^v5.3",
"symfony/console": "v5.3.10",
"psr/log": "1.*",
"ext-sockets": "*",
"ext-pcntl": "*",
"ext-posix": "*",
"composer-runtime-api": "^2.0",
"swiftmailer/swiftmailer": "^6.0",
"swiftmailer/swiftmailer": "v6.3.*",
"psr/container": "^2.0",
"psr/http-server-middleware": "^1.0",
"game-worker/kiri-event": "v1.0"
"psr/http-server-middleware": "1.0.1",
"game-worker/kiri-event": "v1.0",
"ext-inotify": "*"
},
"autoload": {
"psr-4": {
+61 -14
View File
@@ -18,6 +18,7 @@ use Kiri\Exception\NotFindClassException;
use Kiri\Kiri;
use Psr\Log\LoggerInterface;
use Server\ServerManager;
use Swoole\Process;
use Swoole\WebSocket\Server;
if (!function_exists('make')) {
@@ -52,6 +53,38 @@ if (!function_exists('make')) {
}
if (!function_exists('checkPortIsAlready')) {
/**
* @param $port
* @return bool|string
* @throws Exception
*/
function checkPortIsAlready($port): bool|string
{
if (!Kiri::getPlatform()->isLinux()) {
exec("lsof -i :" . $port . " | grep -i 'LISTEN' | awk '{print $2}'", $output);
if (empty($output)) return false;
$output = explode(PHP_EOL, $output[0]);
return $output[0];
}
$serverPid = file_get_contents(storage('.swoole.pid'));
if (!empty($serverPid) && shell_exec('ps -ef | grep ' . $serverPid . ' | grep -v grep')) {
Process::kill($serverPid, 0) && Process::kill($serverPid, SIGTERM);
}
exec('netstat -lnp | grep ' . $port . ' | grep "LISTEN" | awk \'{print $7}\'', $output);
if (empty($output)) {
return false;
}
return explode('/', $output[0])[0];
}
}
if (!function_exists('done')) {
/**
@@ -59,12 +92,26 @@ if (!function_exists('done')) {
*/
function done()
{
ServerManager::setEnv('state', 'exit');
set_env('state', 'exit');
}
}
if (!function_exists('set_env')) {
/**
* @param $key
* @param $value
*/
function set_env($key, $value)
{
putenv(sprintf('%s=%s', $key, $value));
}
}
if (!function_exists('enable_file_modification_listening')) {
@@ -398,9 +445,7 @@ if (!function_exists('fire')) {
/**
* @param object $event
* @throws NotFindClassException
* @throws ReflectionException
*/
*/
function fire(object $event)
{
di(EventDispatch::class)->dispatch($event);
@@ -494,8 +539,8 @@ if (!function_exists('trim_blank')) {
if (!function_exists('get_file_extension')) {
function get_file_extension($filename)
{
function get_file_extension($filename): bool|int|string
{
$mime_types = [
'txt' => 'text/plain',
'htm' => 'text/html',
@@ -832,10 +877,11 @@ if (!function_exists('env')) {
if (!function_exists('di')) {
/**
* @param string $className
* @return mixed
*/
/**
* @param string $className
* @return mixed
* @throws ReflectionException
*/
function di(string $className): mixed
{
return Kiri::getDi()->get($className);
@@ -846,10 +892,11 @@ if (!function_exists('di')) {
if (!function_exists('duplicate')) {
/**
* @param string $className
* @return mixed
*/
/**
* @param string $className
* @return mixed
* @throws ReflectionException
*/
function duplicate(string $className): mixed
{
$class = di($className);
+5 -12
View File
@@ -14,6 +14,7 @@ use Annotation\Annotation as SAnnotation;
use Database\Connection;
use Exception;
use Http\Handler\Router;
use Kiri\Events\OnBeforeCommandExecute;
use Server\Server;
use Kafka\KafkaProvider;
use Kiri\Async;
@@ -24,11 +25,10 @@ use Kiri\Error\Logger;
use Kiri\Events\EventProvider;
use Kiri\Exception\InitException;
use Kiri\Exception\NotFindClassException;
use Kiri\Jwt\Jwt;
use Kiri\Kiri;
use ReflectionException;
use Server\ServerManager;
use Server\SInterface\OnTaskInterface;
use Server\Contract\OnTaskInterface;
use Swoole\Table;
/**
@@ -227,6 +227,8 @@ abstract class BaseApplication extends Component
$eventProvider->on($key, $value, 0);
return;
}
if (is_array($value)) {
if (is_object($value[0]) && !($value[0] instanceof \Closure)) {
$eventProvider->on($key, $value, 0);
@@ -239,6 +241,7 @@ abstract class BaseApplication extends Component
return;
}
foreach ($value as $item) {
if (!is_callable($item, true)) {
throw new InitException("Class does not hav callback.");
@@ -368,16 +371,6 @@ abstract class BaseApplication extends Component
}
/**
* @return Jwt
* @throws
*/
public function getJwt(): Jwt
{
return $this->get('jwt');
}
/**
* @return Server
* @throws
+191 -171
View File
@@ -21,203 +21,223 @@ use Swoole\Coroutine;
class BaseObject implements Configure
{
/**
* BaseAbstract constructor.
*
* @param array $config
* @throws Exception
*/
public function __construct(array $config = [])
{
if (!empty($config) && is_array($config)) {
Kiri::configure($this, $config);
}
}
/**
* BaseAbstract constructor.
*
* @param array $config
* @throws Exception
*/
public function __construct(array $config = [])
{
if (!empty($config) && is_array($config)) {
Kiri::configure($this, $config);
}
}
/**
* @throws Exception
*/
public function init()
{
}
/**
* @throws Exception
*/
public function init()
{
}
/**
* @param array|callable $callback
* @param object $scope
*/
public function async_create(array|callable $callback, object $scope)
{
Coroutine::create($callback, $scope);
}
/**
* @param array|callable $callback
* @param object $scope
*/
public function async_create(array|callable $callback, object $scope)
{
Coroutine::create($callback, $scope);
}
/**
* @return string
*/
#[Pure] public static function className(): string
{
return static::class;
}
/**
* @return string
*/
#[Pure] public static function className(): string
{
return static::class;
}
/**
* @param $name
* @param $value
*
* @throws Exception
*/
public function __set($name, $value)
{
$method = 'set' . ucfirst($name);
if (method_exists($this, $method)) {
$this->{$method}($value);
} else {
throw new Exception('The set name ' . $name . ' not find in class ' . static::class);
}
}
/**
* @param $name
* @param $value
*
* @throws Exception
*/
public function __set($name, $value)
{
$method = 'set' . ucfirst($name);
if (method_exists($this, $method)) {
$this->{$method}($value);
} else {
throw new Exception('The set name ' . $name . ' not find in class ' . static::class);
}
}
/**
* @param $name
*
* @return mixed
* @throws Exception
*/
public function __get($name): mixed
{
$method = 'get' . ucfirst($name);
if (method_exists($this, $method)) {
return $this->$method();
} else {
throw new Exception('The get name ' . $name . ' not find in class ' . static::class);
}
}
/**
* @param $name
*
* @return mixed
* @throws Exception
*/
public function __get($name): mixed
{
$method = 'get' . ucfirst($name);
if (method_exists($this, $method)) {
return $this->$method();
} else {
throw new Exception('The get name ' . $name . ' not find in class ' . static::class);
}
}
/**
* @param $message
* @param string $model
* @return bool
* @throws Exception
*/
public function addError($message, string $model = 'app'): bool
{
if ($message instanceof \Throwable) {
$this->error(jTraceEx($message));
} else {
if (!is_string($message)) {
$message = json_encode($message, JSON_UNESCAPED_UNICODE);
}
$this->error($message);
}
return FALSE;
}
/**
* @param $message
* @param string $model
* @return bool
* @throws Exception
*/
public function addError($message, string $model = 'app'): bool
{
if ($message instanceof \Throwable) {
$this->error(jTraceEx($message));
} else {
if (!is_string($message)) {
$message = json_encode($message, JSON_UNESCAPED_UNICODE);
}
$this->error($message);
}
return FALSE;
}
/**
* @return Logger
* @throws Exception
*/
private function logger(): Logger
{
return Kiri::getDi()->get(Logger::class);
}
/**
* @return Logger
* @throws Exception
*/
private function logger(): Logger
{
return Kiri::getDi()->get(Logger::class);
}
/**
* @param mixed $message
* @param string $method
* @param string $file
* @throws Exception
*/
public function debug(mixed $message, string $method = __METHOD__, string $file = __FILE__)
{
if (!is_string($message)) {
$message = print_r($message, true);
}
$message = "\033[35m[" . date('Y-m-d H:i:s') . '][DEBUG]: ' . $message . "\033[0m";
$message .= PHP_EOL;
$this->logger()->debug(Logger::DEBUG, [$message, $method, $file]);
}
/**
* @param mixed $message
* @param string $method
* @param string $file
* @throws Exception
*/
public function debug(mixed $message, string $method = '', string $file = '')
{
if (!is_string($message)) {
$message = print_r($message, true);
}
$message = "\033[35m" . $message . "\033[0m";
/**
* @param mixed $message
* @param string $method
* @param string $file
* @throws Exception
*/
public function info(mixed $message, string $method = __METHOD__, string $file = __FILE__)
{
if (!is_string($message)) {
$message = print_r($message, true);
}
$message = "\033[34m[" . date('Y-m-d H:i:s') . '][INFO]: ' . $message . "\033[0m";
$message .= PHP_EOL;
$context = [];
if (!empty($method)) $context['method'] = $method;
if (!empty($file)) $context['file'] = $file;
$this->logger()->info(Logger::NOTICE, [$message, $method, $file]);
}
$this->logger()->debug($message, $context);
}
/**
* @param mixed $message
* @param string $method
* @param string $file
* @throws Exception
*/
public function success(mixed $message, string $method = __METHOD__, string $file = __FILE__)
{
if (!is_string($message)) {
$message = print_r($message, true);
}
$message = "\033[36m[" . date('Y-m-d H:i:s') . '][SUCCESS]: ' . $message . "\033[0m";
$message .= PHP_EOL;
$this->logger()->notice(Logger::NOTICE, [$message, $method, $file]);
}
/**
* @param mixed $message
* @param string $method
* @param string $file
* @throws Exception
*/
public function info(mixed $message, string $method = '', string $file = '')
{
if (!is_string($message)) {
$message = print_r($message, true);
}
$message = "\033[34m" . $message . "\033[0m";
/**
* @param mixed $message
* @param string $method
* @param string $file
* @throws Exception
*/
public function warning(mixed $message, string $method = __METHOD__, string $file = __FILE__)
{
if (!is_string($message)) {
$message = print_r($message, true);
}
$context = [];
if (!empty($method)) $context['method'] = $method;
if (!empty($file)) $context['file'] = $file;
$message = "\033[33m[" . date('Y-m-d H:i:s') . '][WARNING]: ' . $message . "\033[0m";
$message .= PHP_EOL;
$this->logger()->critical(Logger::NOTICE, [$message, $method, $file]);
}
$this->logger()->info($message, $context);
}
/**
* @param mixed $message
* @param null $method
* @param null $file
* @throws Exception
*/
public function error(mixed $message, $method = null, $file = null)
{
if ($message instanceof \Throwable) {
$message = $message->getMessage() . " on line " . $message->getLine() . " at file " . $message->getFile();
}
$content = (empty($method) ? '' : $method . ': ') . $message;
/**
* @param mixed $message
* @param string $method
* @param string $file
* @throws Exception
*/
public function success(mixed $message, string $method = '', string $file = '')
{
if (!is_string($message)) {
$message = print_r($message, true);
}
$message = "\033[41;37m[" . date('Y-m-d H:i:s') . '][ERROR]: ' . $content . "\033[0m";
$message = "\033[36m" . $message . "\033[0m";
if (!empty($file)) {
$message .= PHP_EOL . "\033[41;37m[" . date('Y-m-d H:i:s') . '][ERROR]: ' . $file . "\033[0m";
}
$this->logger()->error(Logger::ERROR, [$message, $method, $file]);
}
$context = [];
if (!empty($method)) $context['method'] = $method;
if (!empty($file)) $context['file'] = $file;
$this->logger()->notice($message, $context);
}
/**
* @param mixed $message
* @param string $method
* @param string $file
* @throws Exception
*/
public function warning(mixed $message, string $method = '', string $file = '')
{
if (!is_string($message)) {
$message = print_r($message, true);
}
$message = "\033[33m" . $message . "\033[0m";
$context = [];
if (!empty($method)) $context['method'] = $method;
if (!empty($file)) $context['file'] = $file;
$this->logger()->critical($message, $context);
}
/**
* @param mixed $message
* @param null $method
* @param null $file
* @throws Exception
*/
public function error(mixed $message, $method = null, $file = null)
{
if ($message instanceof \Throwable) {
$message = $message->getMessage() . " on line " . $message->getLine() . " at file " . $message->getFile();
}
$content = (empty($method) ? '' : $method . ': ') . $message;
$message = "\033[41;37m" . $content . "\033[0m";
if (!empty($file)) {
$message .= PHP_EOL . "\03341;37m[" . $file . "\033[0m";
}
$context = [];
if (!empty($method)) $context['method'] = $method;
if (!empty($file)) $context['file'] = $file;
$this->logger()->error($message, $context);
}
}
+2 -2
View File
@@ -14,7 +14,7 @@ use Server\Server;
use Kiri\Crontab\Producer;
use Kiri\Async;
use Kiri\Error\Logger;
use Kiri\Jwt\Jwt;
use Kiri\Jwt\JWTAuth;
/**
* Trait TraitApplication
@@ -24,7 +24,7 @@ use Kiri\Jwt\Jwt;
* @property DatabasesProviders $db
* @property Async $async
* @property Logger $logger
* @property Jwt $jwt
* @property JWTAuth $jwt
* @property SAnnotation $annotation
* @property BaseGoto $goto
* @property Client $client
+10 -5
View File
@@ -20,9 +20,8 @@ use Kiri\Crontab\CrontabProviders;
use Kiri\Events\OnAfterCommandExecute;
use Kiri\Events\OnBeforeCommandExecute;
use Kiri\Exception\NotFindClassException;
use Kiri\FileListen\FileChangeCustomProcess;
use Kiri\FileListen\HotReload;
use ReflectionException;
use Server\ServerCommand;
use Server\ServerProviders;
use stdClass;
use Swoole\Process;
@@ -30,6 +29,7 @@ use Swoole\Timer;
use Symfony\Component\Console\Application as ConsoleApplication;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\ConsoleOutput;
/**
@@ -119,7 +119,7 @@ class Application extends BaseApplication
$container = Kiri::getDi();
$console = $container->get(ConsoleApplication::class);
$console->add($container->get(FileChangeCustomProcess::class));
$console->add($container->get(HotReload::class));
}
@@ -192,12 +192,13 @@ class Application extends BaseApplication
*/
public function execute(array $argv): void
{
/** @var InputInterface $input */
[$input, $output] = $this->argument($argv);
try {
$console = di(ConsoleApplication::class);
$command = $input->getFirstArgument();
if (empty($command)) {
$command = 'list';
$command = 'sw:server';
}
$command = $console->find($command);
if ($command instanceof Command) {
@@ -211,6 +212,7 @@ class Application extends BaseApplication
}
/**
* @param $argv
* @return array
@@ -221,6 +223,7 @@ class Application extends BaseApplication
}
/**
* @throws NotFindClassException
* @throws ReflectionException
@@ -229,7 +232,7 @@ class Application extends BaseApplication
private function enableFileChange(Command $class, $input, $output): void
{
fire(new OnBeforeCommandExecute());
if (!($class instanceof FileChangeCustomProcess)) {
if (!($class instanceof HotReload)) {
scan_directory(directory('app'), 'App');
}
$class->run($input, $output);
@@ -238,6 +241,8 @@ class Application extends BaseApplication
}
/**
* @param $className
* @param null $abstracts
+240 -234
View File
@@ -14,264 +14,270 @@ use Exception;
class Str
{
const STRING = 'abcdefghijklmnopqrstuvwxyz';
const STRING = 'abcdefghijklmnopqrstuvwxyz';
const NUMBER = '01234567890';
const NUMBER = '01234567890';
/**
* @param int $length
*
* @return string
* 获取随机字符串
*/
public static function rand(int $length = 20): string
{
$string = '';
if ($length < 1) $length = 20;
$default = self::STRING . strtoupper(self::STRING) . self::NUMBER;
$default = str_split($default);
$string .= str_repeat($default[array_rand($default)], $length);
return (string)$string;
}
/**
* @param int $length
*
* @return string
* 获取随机字符串
*/
public static function rand(int $length = 20): string
{
$string = '';
if ($length < 1) $length = 20;
$default = self::STRING . strtoupper(self::STRING) . self::NUMBER;
$default = str_split($default);
for ($i = 0; $i < $length; $i++) {
shuffle($default);
$string .= $default[array_rand($default)];
}
return $string;
}
/**
* @param int $length
*
* @return int|string 获取随机数字
* 获取随机数字
*/
public static function random(int $length = 20): int|string
{
$number = '';
$default = str_split(self::NUMBER);
if ($length < 1) $length = 1;
$number .= str_repeat($default[array_rand($default)], $length);
return $number;
}
/**
* @param int $length
*
* @return int|string 获取随机数字
* 获取随机数字
*/
public static function random(int $length = 20): int|string
{
$number = '';
$default = str_split(self::NUMBER);
if ($length < 1) $length = 1;
for ($i = 0; $i < $length; $i++) {
shuffle($default);
$number .= $default[array_rand($default)];
}
return $number;
}
/**
* @param $string
* @param $sullen
* @param bool $strip_tags
* @param string $append
*
* @return string
*/
public static function cut_str_utf8($string, $sullen, bool $strip_tags = true, string $append = '...'): string
{
if ($strip_tags) {
$string = strip_tags($string);
}//去掉签标
$pa = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/";
preg_match_all($pa, $string, $t_string);
$str = "";
for ($i = 0; $i < count($t_string[0]); $i++) {
$str .= $t_string[0][$i];
//转为gbk,一个汉字长度为2
if (strlen(@iconv('utf-8', 'gbk', $str)) >= $sullen) {
if ($i != count($t_string[0]) - 1) $str .= $append;
break;
}
}
return $str;
}
/**
* @param $string
* @param $sullen
* @param bool $strip_tags
* @param string $append
*
* @return string
*/
public static function cut_str_utf8($string, $sullen, bool $strip_tags = TRUE, string $append = '...'): string
{
if ($strip_tags) {
$string = strip_tags($string);
}//去掉签标
$pa = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/";
preg_match_all($pa, $string, $t_string);
$str = "";
for ($i = 0; $i < count($t_string[0]); $i++) {
$str .= $t_string[0][$i];
//转为gbk,一个汉字长度为2
if (strlen(@iconv('utf-8', 'gbk', $str)) >= $sullen) {
if ($i != count($t_string[0]) - 1) $str .= $append;
break;
}
}
return $str;
}
/**
* @param $data
*
* @param null $callback
* @return bool
* 判断是否为json字符串
*/
public static function isJson($data, $callback = null): bool
{
$json = !is_null(json_decode($data)) && !is_numeric($data);
if ($json && is_callable($callback, true)) {
return call_user_func($callback, $data);
}
return $json;
}
/**
* @param $data
*
* @param null $callback
* @return bool
* 判断是否为json字符串
*/
public static function isJson($data, $callback = NULL): bool
{
$json = !is_null(json_decode($data)) && !is_numeric($data);
if ($json && is_callable($callback, TRUE)) {
return call_user_func($callback, $data);
}
return $json;
}
/**
* @param $data
*
* @param null $callBack
* @return bool
* 判断是否序列化字符串
*/
public static function isSerialize($data, $callBack = null): bool
{
$false = !empty($data) && swoole_unserialize($data) !== false;
if ($false && is_callable($callBack, true)) {
return call_user_func($callBack, $data);
}
return $false;
}
/**
* @param $data
*
* @param null $callBack
* @return bool
* 判断是否序列化字符串
*/
public static function isSerialize($data, $callBack = NULL): bool
{
$false = !empty($data) && swoole_unserialize($data) !== FALSE;
if ($false && is_callable($callBack, TRUE)) {
return call_user_func($callBack, $data);
}
return $false;
}
/**
* @param $string
* @param int $length
*
* @param string $append
* @return string
*/
public static function cut($string, int $length = 20, string $append = '...'): string
{
if (empty($string)) {
return '';
}
if ($length < 1) {
$length = 1;
}
$array = str_split($string);
if (count($array) <= $length) {
return implode('', $array);
}
$string = implode('', array_slice($array, 0, $length));
if (!empty($append)) {
$string .= $append;
}
return $string;
}
/**
* @param $string
* @param int $length
*
* @param string $append
* @return string
*/
public static function cut($string, int $length = 20, string $append = '...'): string
{
if (empty($string)) {
return '';
}
if ($length < 1) {
$length = 1;
}
$array = str_split($string);
if (count($array) <= $length) {
return implode('', $array);
}
$string = implode('', array_slice($array, 0, $length));
if (!empty($append)) {
$string .= $append;
}
return $string;
}
/**
* @param $str
* @param int $number
* @param string $key
*
* @return string
*/
public static function encrypt($str, int $number = 10, string $key = 'xshucai.com'): string
{
$res = [];
$add = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$len = strlen($key) < 0 ? 1 : (strlen($key) + 5 > strlen($add) ? strlen($add) - 5 : strlen($key));
if ($number < 1) $number = 10;
$array = str_split($str);
asort($array);
$str = implode('', $array);
for ($i = 0; $i < $number; $i++) {
$_tmp = md5($key) . md5($str) . mb_substr($add, $len, $len + 5, 'utf-8');
$res[] = md5($_tmp);
}
sort($res, SORT_STRING);
return hash('sha384', implode('', $res));
}
/**
* @param $str
* @param int $number
* @param string $key
*
* @return string
*/
public static function encrypt($str, int $number = 10, string $key = 'xshucai.com'): string
{
$res = [];
$add = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$len = strlen($key) < 0 ? 1 : (strlen($key) + 5 > strlen($add) ? strlen($add) - 5 : strlen($key));
if ($number < 1) $number = 10;
$array = str_split($str);
asort($array);
$str = implode('', $array);
for ($i = 0; $i < $number; $i++) {
$_tmp = md5($key) . md5($str) . mb_substr($add, $len, $len + 5, 'utf-8');
$res[] = md5($_tmp);
}
sort($res, SORT_STRING);
return hash('sha384', implode('', $res));
}
/**
* @param $file
* @param $type
* @return string
*/
public static function filename($file, $type): string
{
switch ($type) {
case 'image/png':
return md5_file($file) . '.png';
case 'image/jpeg':
case 'image/jpg':
return md5_file($file) . '.jpg';
case 'image/gif':
return md5_file($file) . '.gif';
break;
}
return md5_file($file);
}
/**
* @param $file
* @param $type
* @return string
*/
public static function filename($file, $type): string
{
switch ($type) {
case 'image/png':
return md5_file($file) . '.png';
case 'image/jpeg':
case 'image/jpg':
return md5_file($file) . '.jpg';
case 'image/gif':
return md5_file($file) . '.gif';
break;
}
return md5_file($file);
}
/**
* @param $endTime
* @param int|null $startTime
* @return array
* 剩余天,带分秒
*/
public static function timeout($endTime, int $startTime = null): array
{
$endTime = $endTime - (!empty($startTime) ? $startTime : time());
/**
* @param $endTime
* @param int|null $startTime
* @return array
* 剩余天,带分秒
*/
public static function timeout($endTime, int $startTime = NULL): array
{
$endTime = $endTime - (!empty($startTime) ? $startTime : time());
$day = intval($endTime / (3600 * 24));
$day = intval($endTime / (3600 * 24));
$hours = intval(($endTime - ($day * (3600 * 24))) / 3600);
$hours = intval(($endTime - ($day * (3600 * 24))) / 3600);
$minute = intval(($endTime - ($day * (3600 * 24) + $hours * 3600)) / 60);
$minute = intval(($endTime - ($day * (3600 * 24) + $hours * 3600)) / 60);
$scrod = intval(($endTime - ($day * (3600 * 24) + $hours * 3600 + $minute * 60)));
$scrod = intval(($endTime - ($day * (3600 * 24) + $hours * 3600 + $minute * 60)));
return [$day, $hours, $minute, $scrod];
}
return [$day, $hours, $minute, $scrod];
}
/**
* @return false|int
*/
public static function get_sy_time(): bool|int
{
$time = strtotime('+1days', strtotime(date('Y-m-d')));
/**
* @return false|int
*/
public static function get_sy_time(): bool|int
{
$time = strtotime('+1days', strtotime(date('Y-m-d')));
return $time - time();
}
return $time - time();
}
/**
* @param string $string
* @return string
*/
public static function encode(string $string): string
{
return addslashes($string);
}
/**
* @param string $string
* @return string
*/
public static function encode(string $string): string
{
return addslashes($string);
}
/**
* @param string $string
* @return string|string[]|null
* 清除标点符号
*/
public static function clear(string $string): array|string|null
{
$char = '。、!?:;﹑•"…‘’“”〝〞∕¦‖— 〈〉﹞﹝「」‹›〖〗】【»«』『〕〔》《﹐¸﹕︰﹔!¡?¿﹖﹌﹏﹋'´ˊˋ―﹫︳︴¯_ ̄﹢﹦﹤‐­˜﹟﹩﹠﹪﹡﹨﹍﹉﹎﹊ˇ︵︶︷︸︹︿﹀︺︽︾ˉ﹁﹂﹃﹄︻︼()';
return preg_replace(array("/[[:punct:]]/i", '/[' . $char . ']/u', '/[ ]{2,}/'), '', $string);
}
/**
* @param string $string
* @return string|string[]|null
* 清除标点符号
*/
public static function clear(string $string): array|string|null
{
$char = '。、!?:;﹑•"…‘’“”〝〞∕¦‖— 〈〉﹞﹝「」‹›〖〗】【»«』『〕〔》《﹐¸﹕︰﹔!¡?¿﹖﹌﹏﹋'´ˊˋ―﹫︳︴¯_ ̄﹢﹦﹤‐­˜﹟﹩﹠﹪﹡﹨﹍﹉﹎﹊ˇ︵︶︷︸︹︿﹀︺︽︾ˉ﹁﹂﹃﹄︻︼()';
return preg_replace(["/[[:punct:]]/i", '/[' . $char . ']/u', '/[ ]{2,}/'], '', $string);
}
/**
* @param int $user
* @param array $param
* @param null $requestTime
*
* @return string
* @throws Exception
*/
public static function token(int $user, array $param = [], $requestTime = NULL): string
{
$str = '';
if (!$requestTime) {
$requestTime = microtime(true);
}
$_user = str_split(md5($user . md5((string)$user)));
ksort($_user);
foreach ($_user as $key => $val) {
$str .= md5(sha1($key . $val . 'www.xshucai.com'));
}
if (is_array($param)) {
foreach ($param as $key => $val) {
$str .= md5($str . sha1($key . md5($val)));
}
}
$str .= sha1(base64_encode((string)$requestTime));
/**
* @param int $user
* @param array $param
* @param null $requestTime
*
* @return string
* @throws Exception
*/
public static function token(int $user, array $param = [], $requestTime = NULL): string
{
$str = '';
if (!$requestTime) {
$requestTime = microtime(TRUE);
}
$_user = str_split(md5($user . md5((string)$user)));
ksort($_user);
foreach ($_user as $key => $val) {
$str .= md5(sha1($key . $val . 'www.xshucai.com'));
}
if (is_array($param)) {
foreach ($param as $key => $val) {
$str .= md5($str . sha1($key . md5($val)));
}
}
$str .= sha1(base64_encode((string)$requestTime));
$md5 = md5($str . $user);
$md5 = md5($str . $user);
return preg_replace('/(\w{10})(\w{3})(\w{4})(\w{9})(\w{6})/', '$1-$2-$3-$4-$5', $md5);
}
return preg_replace('/(\w{10})(\w{3})(\w{4})(\w{9})(\w{6})/', '$1-$2-$3-$4-$5', $md5);
}
/**
* @param string $str
* @param bool $unfairest
* @return string
*/
public static function convertUnderline(string $str, bool $unfairest = true): string
{
$str = ucwords(str_replace('_', ' ', $str));
$str = str_replace(' ', '', lcfirst($str));
return $unfairest ? ucfirst($str) : $str;
}
/**
* @param string $str
* @param bool $unfairest
* @return string
*/
public static function convertUnderline(string $str, bool $unfairest = TRUE): string
{
$str = ucwords(str_replace('_', ' ', $str));
$str = str_replace(' ', '', lcfirst($str));
return $unfairest ? ucfirst($str) : $str;
}
}
+39 -16
View File
@@ -21,6 +21,7 @@ use ReflectionException;
use ReflectionFunction;
use ReflectionMethod;
use ReflectionProperty;
use Psr\Container\ContainerInterface;
/**
* Class Container
@@ -61,26 +62,39 @@ class Container extends BaseObject implements ContainerInterface
];
/**
* @param $class
* @param array $constrict
* @param array $config
*
* @return mixed
* @throws
*/
public function get($class, array $constrict = [], array $config = []): mixed
/**
* @param string $id
* @return mixed
* @throws ReflectionException
*/
public function get(string $id): mixed
{
if ($this->isInterface($class)) {
$class = $this->_interfaces[$class];
}
if (!isset($this->_singletons[$class])) {
$this->_singletons[$class] = $this->resolve($class, $constrict, $config);
}
return $this->_singletons[$class];
return $this->make($id, [], []);
}
/**
* @param $class
* @param array $constrict
* @param array $config
* @return mixed
* @throws ReflectionException
* @throws Exception
*/
public function make($class, array $constrict = [], array $config = []): mixed
{
if ($this->isInterface($class)) {
$class = $this->_interfaces[$class];
}
if (!isset($this->_singletons[$class])) {
$this->_singletons[$class] = $this->resolve($class, $constrict, $config);
}
return $this->_singletons[$class];
}
/**
* @param string $interface
* @param string $class
@@ -435,4 +449,13 @@ class Container extends BaseObject implements ContainerInterface
}
return $old;
}
/**
* @param string $id
* @return bool
*/
public function has(string $id): bool
{
return isset($this->_singletons[$id]) || isset($this->_interfaces[$id]);
}
}
-12
View File
@@ -1,12 +0,0 @@
<?php
namespace Kiri\Di;
/**
* @mixin Container
*/
interface ContainerInterface
{
}
+57 -54
View File
@@ -13,73 +13,76 @@ class LocalService extends Component
{
private array $_components = [];
private array $_components = [];
private array $_definition = [];
private array $_definition = [];
/**
* @param $name
* @param $define
*/
public function set($name, $define)
{
unset($this->_components[$name]);
/**
* @param $name
* @param $define
*/
public function set($name, $define)
{
unset($this->_components[$name]);
$this->_definition[$name] = $define;
}
$this->_definition[$name] = $define;
if (is_object($define) || $define instanceof \Closure) {
$this->_components[$name] = $define;
}
}
/**
* @throws \Exception
*/
public function get(string $name, $throwException = true)
{
if (isset($this->_components[$name])) {
return $this->_components[$name];
}
if (isset($this->_definition[$name])) {
$definition = $this->_definition[$name];
if (is_object($definition) && !$definition instanceof \Closure) {
return $this->_components[$name] = $definition;
}
return $this->_components[$name] = Kiri::createObject($definition);
} else if ($throwException) {
throw new \Exception("Unknown component ID: $name");
}
return null;
}
/**
* @throws \Exception
*/
public function get(string $name, $throwException = true)
{
if (isset($this->_components[$name])) {
return $this->_components[$name];
}
if (isset($this->_definition[$name])) {
$definition = $this->_definition[$name];
if (is_object($definition) && !$definition instanceof \Closure) {
return $this->_components[$name] = $definition;
}
return $this->_components[$name] = Kiri::createObject($definition);
} else if ($throwException) {
throw new \Exception("Unknown component ID: $name");
}
return null;
}
/**
* @param array $components
*/
public function setComponents(array $components)
{
foreach ($components as $name => $component) {
$this->set($name, $component);
}
}
/**
* @param array $components
*/
public function setComponents(array $components)
{
foreach ($components as $name => $component) {
$this->set($name, $component);
}
}
/**
* @param $id
* @return bool
*/
public function has($id): bool
{
return isset($this->_components[$id]) || isset($this->_definition[$id]);
}
/**
* @param $id
* @return bool
*/
public function has($id): bool
{
return isset($this->_components[$id]) || isset($this->_definition[$id]);
}
/**
* @param $id
*/
public function remove($id): void
{
unset($this->_components[$id], $this->_definition[$id]);
}
/**
* @param $id
*/
public function remove($id): void
{
unset($this->_components[$id], $this->_definition[$id]);
}
}
+2
View File
@@ -118,6 +118,8 @@ class ErrorHandler extends Component implements ErrorInterface
{
$path = ['file' => $file, 'line' => $line];
var_dump(func_get_args());
$data = Json::to($code, $this->category . ': ' . $message, $path);
write($data, $this->category);
+13 -24
View File
@@ -5,8 +5,9 @@ namespace Kiri\Error;
use Exception;
use Http\Aspect\OnAspectInterface;
use Http\Aspect\OnJoinPointInterface;
use Http\Constrict\RequestInterface;
use Kiri\IAspect;
use Kiri\Kiri;
@@ -14,20 +15,24 @@ use Kiri\Kiri;
* Class LoggerAspect
* @package Kiri\Error
*/
class LoggerAspect implements IAspect
class LoggerAspect implements OnAspectInterface
{
private float $time;
/**
* @param mixed $handler
* @param array $params
* @param OnJoinPointInterface $joinPoint
* @return mixed
* @throws Exception
*/
public function invoke(mixed $handler, array $params = []): mixed
public function process(OnJoinPointInterface $joinPoint): mixed
{
return call_user_func($handler, ...$params);
$time = microtime(true);
$response = $joinPoint->process();
$this->print_runtime($time);
return $response;
}
@@ -44,20 +49,4 @@ class LoggerAspect implements IAspect
echo PHP_EOL;
}
public function before(): void
{
// TODO: Implement before() method.
$this->time = microtime(true);
}
/**
* @throws Exception
*/
public function after(mixed $response): void
{
// TODO: Implement after() method.
$this->print_runtime($this->time);
}
}
+4 -14
View File
@@ -20,22 +20,16 @@ use Server\Abstracts\BaseProcess;
class LoggerProcess extends BaseProcess
{
/**
* @param Process $process
* @return string
*/
#[Pure] public function getProcessName(Process $process): string
{
// TODO: Implement getProcessName() method.
return get_called_class();
}
public string $name = 'logger process';
/**
* @param Process $process
* @throws ComponentException
*/
public function onHandler(Process $process): void
public function process(Process $process): void
{
// TODO: Implement onHandler() method.
$this->message($process);
@@ -49,10 +43,6 @@ class LoggerProcess extends BaseProcess
*/
public function message(Process $process)
{
if ($this->checkProcessIsStop()) {
$this->exit();
return;
}
$message = Json::decode($process->read());
if (!empty($message)) {
Kiri::writeFile($this->getDirName($message), $message[0], FILE_APPEND);
@@ -1,106 +0,0 @@
<?php
namespace Kiri\FileListen;
use Exception;
use Kiri\Abstracts\Config;
use Kiri\Abstracts\Logger;
use Kiri\Exception\ConfigException;
use Kiri\Kiri;
use Swoole\Coroutine;
use Swoole\Coroutine\Barrier;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
*
*/
class FileChangeCustomProcess extends Command
{
public bool $isReloading = false;
public bool $isReloadingOut = false;
public ?array $dirs = [];
public int $events;
public int $int = -1;
/**
*
*/
protected function configure()
{
$this->setName('sw:wather')
->setDescription('server start')
->addArgument('action', InputArgument::REQUIRED);
}
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
* @throws ConfigException
* @throws \Swoole\Exception
* @throws Exception
*/
public function execute(InputInterface $input, OutputInterface $output): int
{
// TODO: Implement onHandler() method.
set_error_handler([$this, 'onErrorHandler']);
$this->dirs = Config::get('inotify', [APP_PATH . 'app']);
if (!extension_loaded('inotify')) {
$driver = Kiri::getDi()->get(Scaner::class, [$this->dirs, $this]);
} else {
$driver = Kiri::getDi()->get(Inotify::class, [$this->dirs, $this]);
}
$make = Barrier::make();
go(function () {
$this->trigger_reload();
});
go(function () {
$sign = Coroutine::waitSignal(SIGTERM, -1);
if ($sign) {
proc_open("php " . APP_PATH . "kiri.php sw:server stop", [], $pipes);
}
});
go(function () use ($driver) {
$driver->start();
});
Barrier::wait($make);
return 0;
}
/**
* @param $code
* @param $message
* @param $file
* @param $line
* @throws Exception
*/
public function onErrorHandler($code, $message, $file, $line)
{
if (str_contains($message, 'The file descriptor is not an inotify instance')) {
return;
}
debug('Error:' . $message . ' at ' . $file . ':' . $line);
}
/**
* 重启
* @throws Exception
*/
public function trigger_reload()
{
Kiri::getDi()->get(Logger::class)->warning('change reload');
proc_open("php " . APP_PATH . "kiri.php sw:server restart", [], $pipes);
}
}
+154
View File
@@ -0,0 +1,154 @@
<?php
namespace Kiri\FileListen;
use Annotation\Inject;
use Exception;
use Kiri\Abstracts\Config;
use Kiri\Error\Logger;
use Kiri\Exception\ConfigException;
use Kiri\Kiri;
use Swoole\Coroutine;
use Swoole\Process;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
*
*/
class HotReload extends Command
{
public bool $isReloading = false;
public bool $isReloadingOut = false;
public ?array $dirs = [];
public int $events;
public int $int = -1;
private ?Process $process = null;
public Inotify|Scaner $driver;
#[Inject(Logger::class)]
public Logger $logger;
protected mixed $source = null;
protected mixed $pipes = [];
protected ?Coroutine\Channel $channel = null;
/**
*
*/
protected function configure()
{
$this->setName('sw:wather')
->setDescription('server start');
}
/**
* @param InputInterface $input
* @param OutputInterface $output
* @return int
* @throws ConfigException
* @throws Exception
*/
public function execute(InputInterface $input, OutputInterface $output): int
{
// TODO: Implement onHandler() method.
set_error_handler([$this, 'onErrorHandler']);
$this->dirs = Config::get('inotify', [APP_PATH . 'app']);
swoole_async_set(['enable_coroutine' => false]);
if (!extension_loaded('inotify')) {
$this->driver = Kiri::getDi()->make(Scaner::class, [$this->dirs, $this]);
} else {
$this->driver = Kiri::getDi()->make(Inotify::class, [$this->dirs, $this]);
}
if (Kiri::getPlatform()->isLinux()) {
swoole_set_process_name('[' . Config::get('id', 'sw service.') . '].sw:wather');
}
$this->trigger_reload();
var_dump(getmypid());
Process::signal(SIGTERM, [$this, 'onSignal']);
Process::signal(SIGKILL, [$this, 'onSignal']);
$this->driver->start();
return 0;
}
/**
* @param $data
* @throws Exception
*/
public function onSignal($data)
{
if (!$data) {
return;
}
$this->driver->clear();
$pid = file_get_contents(storage('.swoole.pid'));
if (!empty($pid) && Process::kill($pid, 0)) {
Process::kill($pid, SIGTERM);
}
if ($this->process && Process::kill($this->process->pid, 0)) {
Process::kill($this->process->pid) && Process::wait(true);
}
while ($ret = Process::wait(true)) {
echo "PID={$ret['pid']}\n";
sleep(1);
}
}
/**
* @param $code
* @param $message
* @param $file
* @param $line
* @throws Exception
*/
public function onErrorHandler($code, $message, $file, $line)
{
if (str_contains($message, 'The file descriptor is not an inotify instance')) {
return;
}
debug('Error:' . $message . ' at ' . $file . ':' . $line);
}
/**
* 重启
*
* @throws Exception
*/
public function trigger_reload()
{
$this->logger->warning('change reload');
$pid = $this->process?->pid;
$process = new Process(function (Process $process) {
$process->exec(PHP_BINARY, [APP_PATH . "kiri.php", "sw:server", "restart"]);
});
$process->start();
if ($pid && Process::kill($pid, 0)) {
Process::kill($pid) && Process::wait(true);
}
$this->process = null;
$this->process = $process;
}
}
+20 -17
View File
@@ -4,6 +4,7 @@ namespace Kiri\FileListen;
use Exception;
use Swoole\Event;
use Swoole\Timer;
class Inotify
{
@@ -13,14 +14,20 @@ class Inotify
private array $watchFiles = [];
protected bool $isReloading = FALSE;
protected int $cid;
const IG_DIR = [APP_PATH . 'commands', APP_PATH . '.git', APP_PATH . '.gitee'];
/**
* @param array $dirs
* @param FileChangeCustomProcess $process
* @param HotReload $process
*/
public function __construct(protected array $dirs, public FileChangeCustomProcess $process)
public function __construct(protected array $dirs, public HotReload $process)
{
}
@@ -41,22 +48,26 @@ class Inotify
}
public function clear()
{
Event::del($this->inotify);
Event::exit();
}
/**
* 开始监听
* @throws Exception
*/
public function check()
{
if (!($events = inotify_read($this->inotify))) {
return;
}
if ($this->process->isReloading) {
if (!$this->process->isReloadingOut) {
$this->process->isReloadingOut = true;
}
if ($this->isReloading) {
return;
}
$LISTEN_TYPE = [IN_CREATE, IN_DELETE, IN_MODIFY, IN_MOVED_TO, IN_MOVED_FROM];
foreach ($events as $ev) {
if (!in_array($ev['mask'], $LISTEN_TYPE)) {
@@ -64,12 +75,8 @@ class Inotify
}
//非重启类型
if (str_ends_with($ev['name'], '.php')) {
if ($this->process->int !== -1) {
return;
}
$this->process->int = @swoole_timer_after(2000, [$this, 'reload']);
$this->process->isReloading = true;
Timer::after(3000, fn()=>$this->reload());
$this->isReloading = TRUE;
}
}
}
@@ -79,16 +86,13 @@ class Inotify
*/
public function reload()
{
$this->process->isReloading = true;
$this->process->trigger_reload();
$this->clearWatch();
foreach ($this->dirs as $root) {
$this->watch($root);
}
$this->process->int = -1;
$this->process->isReloading = FALSE;
$this->process->isReloadingOut = FALSE;
$this->isReloading = FALSE;
}
@@ -143,7 +147,6 @@ class Inotify
} else if (!str_ends_with($f, '.php')) {
continue;
}
//检测文件类型
if (strstr($f, '.') == '.php') {
$wd = @inotify_add_watch($this->inotify, $path, $this->events);
+14 -3
View File
@@ -11,9 +11,9 @@ class Scaner
/**
* @param array $dirs
* @param FileChangeCustomProcess $process
* @param HotReload $process
*/
public function __construct(protected array $dirs, public FileChangeCustomProcess $process)
public function __construct(protected array $dirs, public HotReload $process)
{
}
@@ -103,6 +103,9 @@ class Scaner
*/
public function timerReload()
{
if ($this->process->isReloading) {
return;
}
$this->process->isReloading = true;
$this->process->trigger_reload();
@@ -117,12 +120,20 @@ class Scaner
}
private bool $isStop = false;
public function clear()
{
$this->isStop = true;
}
/**
* @throws Exception
*/
public function tick()
{
if ($this->process->isReloading) {
if ($this->process->isReloading || $this->isStop) {
return;
}
-57
View File
@@ -1,57 +0,0 @@
<?php
declare(strict_types=1);
namespace Kiri\Jwt;
use Annotation\Inject;
use Exception;
use Http\Message\ServerRequest;
use Kiri\Kiri;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Server\Constrict\ResponseInterface;
/**
* Class CoreMiddleware
* @package Kiri\Kiri\Route
* 跨域中间件
*/
class JWTAuthMiddleware implements MiddlewareInterface
{
/** @var int */
public int $zOrder = 0;
#[Inject(ResponseInterface::class)]
public ResponseInterface $response;
/**
* @param ServerRequest $request
* @param RequestHandlerInterface $handler
* @return \Psr\Http\Message\ResponseInterface
* @throws Exception
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): \Psr\Http\Message\ResponseInterface
{
$authorization = $request->getHeaderLine('Authorization');
if (empty($authorization)) {
return $this->response->json(['code' => 401, 'JWT voucher cannot be empty.']);
}
if (!str_starts_with($authorization, 'Bearer ')) {
return $this->response->json(['code' => 401, 'JWT Voucher Format Error.']);
}
$authorization = str_replace('Bearer ', '', $authorization);
$jwt = Kiri::app()->getJwt();
if (!$jwt->validator($authorization)) {
return $this->response->json(['code' => 401, 'JWT Validator fail.']);
}
return $handler->handle($request);
}
}
-27
View File
@@ -1,27 +0,0 @@
<?php
namespace Kiri\Jwt;
use JetBrains\PhpStorm\Pure;
use Throwable;
/**
*
*/
class JWTAuthTokenException extends \Exception
{
/**
* @param string $message
* @param int $code
* @param Throwable|null $previous
*/
#[Pure] public function __construct($message = "", $code = 4001, Throwable $previous = null)
{
parent::__construct($message, 4001, $previous);
}
}
-201
View File
@@ -1,201 +0,0 @@
<?php
declare(strict_types=1);
namespace Kiri\Jwt;
use Annotation\Inject;
use Exception;
use Http\Constrict\RequestInterface;
use Kiri\Abstracts\Component;
use Kiri\Abstracts\Config;
use Kiri\Core\Json;
use Kiri\Exception\ConfigException;
/**
* Class Jwt
* @package Kiri\Jwt
*/
class Jwt extends Component
{
use JwtHelper;
#[Inject(RequestInterface::class)]
private RequestInterface $request;
/**
* @param RequestInterface $request
*/
public function setRequest(RequestInterface $request): void
{
$this->request = $request;
}
/**
* @throws ConfigException
* @throws Exception
* 'jwt' => [
* 'scene' => 'application',
* 'timeout' => 7200,
* 'encrypt' => '',
* 'iv' => '',
* 'key' => '',
* ]
*/
public function init()
{
$this->request = di(RequestInterface::class);
$this->public = Config::get('ssl.public', $this->public);
$this->private = Config::get('ssl.private', $this->private);
$this->timeout = Config::get('jwt.timeout', 7200);
$jwt = Config::get('jwt', []);
if ($jwt) {
$this->setScene($jwt['scene'] ?? 'application');
$this->setKey($jwt['key'] ?? get_called_class());
$length = openssl_cipher_iv_length($this->encrypt);
if ($length > 0) {
$defaultIv = openssl_random_pseudo_bytes($length);
$this->setIv($jwt['iv'] ?? $defaultIv);
}
}
}
/**
* @param int $unionId
*
* @return string
* @throws Exception
*/
public function create(int $unionId): string
{
$this->user = $unionId;
$this->config['time'] = time();
$this->data = $this->request->getHeaders();
if (!isset($this->data['source'])) {
$this->data['source'] = 'browser';
}
return $this->createEncrypt($unionId);
}
/**
* @return string
*/
private function jwtHeader(): string
{
$string = openssl_encrypt(
json_encode(['type' => 'openssl', 'encrypt' => $this->encrypt]),
$this->encrypt,
$this->key,
0,
$this->iv
);
return str_replace('=', '', $string);
}
/**
* @param $unionId
* @return string
* @throws Exception
*/
private function jwtBody($unionId): string
{
$json = json_encode(['unionId' => $unionId, 'createTime' => time(), 'expire_at' => time() + $this->timeout]);
openssl_private_encrypt($json, $encode, $this->private);
return base64_encode($encode);
}
/**
* @param $unionId
* @return string
* @throws Exception
*/
private function createEncrypt($unionId): string
{
$params[] = $this->jwtHeader();
$params[] = $this->jwtBody($unionId);
$params[] = hash('sha256', $params[0] . $params[1]);
return implode('.', $params);
}
/**
* @param $token
* @return string|int
* @throws JWTAuthTokenException
*/
public function getUnionId($token): string|int
{
$unpack = $this->unpack($token);
if (!$this->_validator($unpack)) {
throw new JWTAuthTokenException('JWT certificate has expired.');
}
return $unpack['unionId'];
}
/**
* @param $token
* @return bool
* @throws JWTAuthTokenException
*/
public function validator($token): bool
{
return $this->_validator($this->unpack($token));
}
/**
* @param $unpack
* @return bool
*/
private function _validator($unpack): bool
{
if ($unpack['expire_at'] < time()) {
return false;
}
return true;
}
/**
* @param $token
* @return string
* @throws JWTAuthTokenException
* @throws Exception
*/
public function refresh($token): string
{
return $this->create($this->unpack($token)['unionId']);
}
/**
* @param string $token
* @return mixed
* @throws JWTAuthTokenException
*/
private function unpack(string $token): array
{
if (count($explode = explode('.', $token)) != 3) {
throw new JWTAuthTokenException('JWT Voucher Format Error.');
}
if (hash('sha256', $explode[0] . $explode[1]) != $explode[2]) {
throw new JWTAuthTokenException('JWT Sign Validator Fail.');
}
if (!openssl_public_decrypt(base64_decode($explode[1]), $decode, $this->public)) {
throw new JWTAuthTokenException('JWT Voucher Unpack Error.');
}
return Json::decode($decode, true);
}
}
-134
View File
@@ -1,134 +0,0 @@
<?php
namespace Kiri\Jwt;
trait JwtHelper
{
/** @var int $user */
private int $user;
private array $data;
private array $source = ['browser', 'android', 'iphone', 'pc', 'mingame'];
private array $config = ['token' => ''];
private ?int $timeout = 7200;
private string $key = 'www.xshucai.com';
private string $secret = '';
private string $scene = 'default';
private string $encrypt = 'aes-128-ecb';
private string $iv = '';
private ?string $public = '-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6BuML3gtLGde7QKNuNST
UCB9gdHC7XIpOc7Wx2I64Esj3UxWHTgp3URj0ge8zpy7A3FfBdppR7d1nwoD6Xad
jqfjEWpTy4WwGYsOfH0tFl3wAmse0lebF4NFsS9pzrikQT6c9qsVm88pCjvg4i5t
WhTMEnpTFDYoDR0KXlLXltQMudBBUHFaVwP0wKJ/cGX7R1Mrv35K4MXwQFOuGZkP
hsp2rO9x5LjtSKIXbexy7WhUu6QMjD/XzgsXr9UF+ExYmBGXRVWgNFLMkiaCZ2Uz
WlQhpQrA5/wKd76dCzjvqw9M32OiZl2lCKT73cV8GUvt7BNsM1SiPhqfY7nhO6y3
cwIDAQAB
-----END PUBLIC KEY-----';
private ?string $private = '-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEA6BuML3gtLGde7QKNuNSTUCB9gdHC7XIpOc7Wx2I64Esj3UxW
HTgp3URj0ge8zpy7A3FfBdppR7d1nwoD6XadjqfjEWpTy4WwGYsOfH0tFl3wAmse
0lebF4NFsS9pzrikQT6c9qsVm88pCjvg4i5tWhTMEnpTFDYoDR0KXlLXltQMudBB
UHFaVwP0wKJ/cGX7R1Mrv35K4MXwQFOuGZkPhsp2rO9x5LjtSKIXbexy7WhUu6QM
jD/XzgsXr9UF+ExYmBGXRVWgNFLMkiaCZ2UzWlQhpQrA5/wKd76dCzjvqw9M32Oi
Zl2lCKT73cV8GUvt7BNsM1SiPhqfY7nhO6y3cwIDAQABAoIBADPihJHP8XktmmCs
43Vfv5Z3zNaKR2LA1Eph3E0xviuJYHkFqXJarbESqqW2qRQeoQeB/lXWnxYzAo4M
tRcpNss+6FlqRVUHi3gKR7C4Yq3PTemcfIVUpAy7gYa8LJDTYZRcJMZXNDtiMbBh
9kFZU4SBhaTTx2KLQKS9yyWOqzbBvyLXN+1+Wy477M9+MXXTKw79dO+pML6cR0yl
pNfVR5FX5L/GB5vOtQB/Aqg/CKT8NC5MzWPnKY+TPCCHZyoZuB9dLDuWOlqsN4QX
Y4B8fFca5yRwzHra5aGoqdaT/zGctt+I6V/f/KNQCo36f9LPxeXg1+FHvvtTj5WZ
N8CGPzECgYEA9R7lRMXzrHE4rK0DhxQXIFbIKKtxrimqZQdbwOUeYYD2R6CDSItK
z88RSYElmd6wiS7fYIaheXNqJ8Yu6SQFBF/yshBwjQVl9NJG94LJlgx1XnVZEju6
OZjMUOhHXBymtXnLo16pDRl8odc4MFLRH25/vLtwChUr+Qoyt54GzFUCgYEA8mjL
jdh94JAmcdnDXsKgjNOGyNWGDVvWoFmy8lEQsMXY1JJnEd3YfDM2prmv3vaoiXzi
YkSETl6ZUtJqh78MnHCBY1vI6EAcKQAF/kvP2TataRCXNcGNQwn2mtq+B+heTta6
Di8jjAdmdUAYHbmOQryBudiRYG7JEF038elzvKcCgYEAq81ByFguGBkrLev94vkz
1Fi+5bJ0dSuC4Fit+J8eEhz/gOiB26C1iL2LUkeQgS5R8XTG37K9DpDUQJhpXMMA
OTa+tgtLt6um8FdJokUq4V5ODSyWh28RcTklSzfifC8gsWVyU0kPl7zbW9uq6EPD
ixI5uaBuQMLiFSUOsx+xiBkCgYEAtqXHWeVZUy7KCNavomK7XeCzmfdovgAIw2FS
t8nk7YzlR6XYC1pAl7Ru5Ujb/v+TFaUHXkuJ9RLKK+Fna0jEU8thcl/iDTzg+vON
kIHG5j+Qga2CgXqI2Y5URXGz5XlsNbMNFUrnWcbpqEbW5O6/BgHLLSDEyQgwbygN
0zS3g9kCgYEAhssb7kOljdIul4lY5MXc67Zf1dp6S2bucLOxsG6cRW07b3pBz7QF
5aPE7ZwnkzTnA4HuGGauKj+qKGAR7ve55XClAq/XipiVFrjwV/t3LC6j5DoqTJYR
mlAZUEjsoaT9vjvjGTxl3uCm0TX5KTgtSJIt2kA1tYVjQef+/iZTHxY=
-----END RSA PRIVATE KEY-----';
/**
* @param string $publicKey
*/
public function setPublic(string $publicKey)
{
$this->public = $publicKey;
}
/**
* @param int $timeout
*/
public function setTimeout(int $timeout)
{
$this->timeout = $timeout;
}
public function setScene(string $scene)
{
$this->scene = $scene;
}
/**
* @param string $timeout
*/
public function setKey(string $timeout)
{
$this->key = $timeout;
}
/**
* @param string $privateKey
*/
public function setPrivate(string $privateKey)
{
$this->private = $privateKey;
}
/**
* @param string $privateKey
*/
public function setIv(string $privateKey)
{
$this->iv = $privateKey;
}
/**
* @param string $privateKey
*/
public function setEncrypt(string $privateKey)
{
$this->encrypt = $privateKey;
}
}
+11 -2
View File
@@ -13,7 +13,7 @@ use JetBrains\PhpStorm\Pure;
use Kiri\Abstracts\Config;
use Kiri\Core\Json;
use Kiri\Di\Container;
use Kiri\Di\ContainerInterface;
use Psr\Container\ContainerInterface;
use ReflectionException;
use Server\ServerManager;
use Swoole\Coroutine;
@@ -31,7 +31,7 @@ defined('TASK_PATH') or define('TASK_PATH', APP_PATH . 'app/Async/');
defined('LISTENER_PATH') or define('LISTENER_PATH', APP_PATH . 'app/Listener/');
defined('KAFKA_PATH') or define('KAFKA_PATH', APP_PATH . 'app/Kafka/');
defined('RPC_CLIENT_PATH') or define('RPC_CLIENT_PATH', APP_PATH . 'app/Client/Rpc/');
defined('MODEL_PATH') or define('MODEL_PATH', APP_PATH . 'app/Models/');
defined('MODEL_PATH') or define('MODEL_PATH', APP_PATH . 'app/Model/');
/**
@@ -229,6 +229,15 @@ class Kiri
}
/**
* @return Container
*/
public static function di(): Container
{
return static::$container;
}
/**
* @param $workerId
* @return mixed
+7
View File
@@ -220,6 +220,13 @@ class Pool extends Component
return;
}
while (static::$_connections[$name]->length() > 0) {
if (static::$_connections[$name] instanceof Channel)
{
if (!Context::inCoroutine())
{
break;
}
}
$client = static::$_connections[$name]->pop();
if ($client instanceof StopHeartbeatCheck) {
$client->stopHeartbeatCheck();
-8
View File
@@ -1,8 +0,0 @@
<?php
namespace Kiri\Proxy;
abstract class AProxy
{
}
-53
View File
@@ -1,53 +0,0 @@
<?php
namespace Kiri\Proxy;
use Annotation\Aspect;
use Http\Handler\Handler;
use Kiri\Di\NoteManager;
use Kiri\IAspect;
use Kiri\Kiri;
/**
*
*/
class AspectProxy extends AProxy implements ProxyInterface
{
/**
* @param Handler $executor
* @return mixed
*/
public function proxy(Handler $executor): mixed
{
if ($executor->callback instanceof \Closure) {
return call_user_func($executor->callback, ...$executor->params);
}
$controller = Kiri::getDi()->get($executor->callback[0]);
$aspect = $this->getAspect($executor->callback);
if (!is_null($aspect)) {
$aspect->before();
$result = $aspect->invoke([$controller, $executor->callback[1]], $executor->params);
$aspect->after($result);
} else {
$result = call_user_func([$controller, $executor->callback[1]]);
}
return $result;
}
/**
* @param array $executor
* @return ?IAspect
*/
protected function getAspect(array $executor): ?IAspect
{
$aspect = NoteManager::getSpecify_annotation(Aspect::class, $executor[0], $executor[1]);
if (!is_null($aspect)) {
$aspect = Kiri::getDi()->get($aspect->aspect);
}
return $aspect;
}
}
-17
View File
@@ -1,17 +0,0 @@
<?php
namespace Kiri\Proxy;
use Http\Handler\Handler;
interface ProxyInterface
{
/**
* @param Handler $executor
* @return mixed
*/
public function proxy(Handler $executor): mixed;
}
+4 -4
View File
@@ -30,11 +30,11 @@ class Gii
private InputInterface $input;
public string $modelPath = APP_PATH . 'app/Models/';
public string $modelNamespace = 'App\\Models\\';
public string $modelPath = APP_PATH . 'app/Model/';
public string $modelNamespace = 'App\\Model\\';
public string $controllerPath = APP_PATH . 'app/Http/Controllers/';
public string $controllerNamespace = 'App\\Controllers\\';
public string $controllerPath = APP_PATH . 'app/Http/Controller/';
public string $controllerNamespace = 'App\\Controller\\';
public static array $createSqls = [];
+4 -4
View File
@@ -24,11 +24,11 @@ abstract class GiiBase
protected InputInterface $input;
public string $modelPath = APP_PATH . 'app/Models/';
public string $modelNamespace = 'App\Models\\';
public string $modelPath = APP_PATH . 'app/Model/';
public string $modelNamespace = 'App\Model\\';
public string $controllerPath = APP_PATH . 'app/Http/Controllers/';
public string $controllerNamespace = 'App\\Controllers\\';
public string $controllerPath = APP_PATH . 'app/Http/Controller/';
public string $controllerNamespace = 'App\\Controller\\';
public ?string $module = null;
+1 -1
View File
@@ -92,7 +92,7 @@ use Kiri\Core\Json;
use Database\Connection;
use Database\Annotation\Get;
use Database\Annotation\Set;
use Annotation\Model\Relation;
use Database\Relation;
use Database\Model;
' . PHP_EOL;
}
+1 -1
View File
@@ -31,7 +31,7 @@ class GiiTask extends GiiBase
namespace App\Async;
use Server\SInterface\OnTaskInterface;
use Server\Contract\OnTaskInterface;
';
-10
View File
@@ -1,10 +0,0 @@
<?php
namespace Kiri\Process;
interface OnProcessInterface
{
public function handle();
}
-88
View File
@@ -1,88 +0,0 @@
<?php
namespace Kiri\Process;
abstract class Process implements OnProcessInterface
{
/**
* @var \Swoole\Process
*/
protected \Swoole\Process $process;
/**
* @var mixed
*/
protected mixed $redirect_stdin_and_stdout = null;
/**
* @var int
*/
protected int $pipe_type = SOCK_DGRAM;
/**
* @var bool
*/
protected bool $enable_coroutine = true;
/**
* @var string
*/
protected string $name = '';
/**
* @return \Swoole\Process
*/
public function getProcess(): \Swoole\Process
{
return $this->process;
}
/**
* @return mixed
*/
public function getRedirectStdinAndStdout(): mixed
{
return $this->redirect_stdin_and_stdout;
}
/**
* @return int
*/
public function getPipeType(): int
{
return $this->pipe_type;
}
/**
* @return bool
*/
public function isEnableCoroutine(): bool
{
return $this->enable_coroutine;
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @param \Swoole\Process $process
*/
public function start(\Swoole\Process $process)
{
$this->process = $process;
}
}
-52
View File
@@ -1,52 +0,0 @@
<?php
namespace Kiri\Process;
require_once 'OnProcessInterface.php';
require_once 'Process.php';
use function Co\run;
class TestProcess extends Process
{
protected string $name = 'test process';
/**
*/
public function onStart()
{
}
public function handle()
{
// TODO: Implement doWhile() method.
}
public function onShutdown()
{
// TODO: Implement onShutdown() method.
}
}
$array = [];
for ($i = 0; $i < 10; $i++) {
$class = new TestProcess();
$process = new \Swoole\Process([$class, 'start'], $class->getRedirectStdinAndStdout(),
$class->getPipeType(), $class->isEnableCoroutine());
$process->start();
array_push($array, $process);
}
run(function () use ($array) {
foreach ($array as $value) {
var_dump($value->getCallback());
}
});