diff --git a/.gitignore b/.gitignore index a36861b..67b90b8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ # Created by .ignore support plugin (hsz.mobi) .idea + +/vendor/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md index 05255e5..2353f5f 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ -# phpstorm-for-php-framework +# php-ide-helper php framework and php extension Auto Compelete for phpstorm Yaf、Yar、Yac、Yaconf、Redis、Swoole等框架或C扩展之PhpStrom代码自动补全(屏蔽IDE undefined,全命名空间,中文详细文档,比手册更详细) -这个想法fork自phpboy(https://github.com/xudianyang/yaf.auto.complete) +这个想法fork自phpboy(https://github.com/xudianyang/yaf.auto.complete) ## 原理 @@ -11,26 +11,45 @@ Yaf、Yar、Yac、Yaconf、Redis、Swoole等框架或C扩展之PhpStrom代码自 ## 目前支持的框架或扩展 -1、Yaf +1、Yaf(3.0.7) -2、Yac +2、Yac(2.0.3-dev) -3、Yaconf +3、Yaconf(1.0.8-dev) -4、Yar +4、Yar(2.0.4) -5、Redis(包括RedisCluster) +5、phpRedis(包括RedisCluster,支持phpredis 5.1.1) -6、swoole扩展 +6、swoole扩展(支持swoole 4.2.9) -7、SeasLog +7、SeasLog(1.8.5) 8、MsgPack(beta) 9、Xhprof +10、FastDFS(FastDFS 1.00) + ## 使用说明 +#### 一.支持composer的项目通过composer安装 + +##### 1.在项目的composer配置文件composer.json中的require-dev段添加以下内容 +``` +"require-dev": { + "shixinke/php-ide-helper":"dev-master" +} +``` + +##### 2.通过composer install安装包 + +``` +composer install +``` + +#### 二.不支持composer的项目安装 + 1、下载源文件并解压,将src文件夹下面的内容放到任意一个位置(我习惯将它放到我的phpstorm安装路径下的plugins\php\lib下面,然后建立一个vendor文件夹,如C:\Program Files (x86)\JetBrains\PhpStorm 9.0.2\plugins\php\lib\vendor) 2、打开phpstorm,选择File->Settings,打开setting控制面板 diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..e7276ce --- /dev/null +++ b/composer.json @@ -0,0 +1,21 @@ +{ + "name": "shixinke/php-ide-helper", + "description": "a tool that provides auto-completion for php frameworks and extensions", + "type": "library", + "keywords": [ + "php", + "ide-helper", + "phpstorm-helper", + "swoole-ide-helper" + ], + "license": "Apache-2.0", + "authors": [ + { + "name": "shixinke", + "email": "ishixinke@qq.com" + } + ], + "require": { + "php": ">=7.0" + } +} diff --git a/src/Fastdfs_client/FastDFS.php b/src/Fastdfs_client/FastDFS.php new file mode 100644 index 0000000..444fcc9 --- /dev/null +++ b/src/Fastdfs_client/FastDFS.php @@ -0,0 +1,1029 @@ +1024, 'height'=>768) + * @param string $group_name 分组名 + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return array | boolean + */ + public function storage_upload_by_filename($local_filename, $file_ext_name, Array $meta_list, $group_name, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *将本地文件上传到远程服务器(成功返回一个包括文件ID) + * @example + * @param string $local_filename 本地文件 + * @param string $file_ext_name 文件扩展名(不包括.) + * @param array $meta_list 文件相关数据,如:array('width'=>1024, 'height'=>768) + * @param string $group_name 分组名 + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return string | boolean + */ + public function storage_upload_by_filename1($local_filename, $file_ext_name, Array $meta_list, $group_name, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *通过文件内容将文件上传到远程服务器(成功返回一个包括group_name和filename信息的关联数组) + * @example + * @param string $file_buf 文件内容 + * @param string $file_ext_name 文件扩展名(不包括.) + * @param array $meta_list 文件相关数据,如:array('width'=>1024, 'height'=>768) + * @param string $group_name 分组名 + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return array | boolean + */ + public function storage_upload_by_filebuff($file_buf, $file_ext_name, Array $meta_list, $group_name, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *通过文件内容将文件上传到远程服务器(成功返回文件ID) + * @example + * @param string $file_buf 文件内容 + * @param string $file_ext_name 文件扩展名(不包括.) + * @param array $meta_list 文件相关数据,如:array('width'=>1024, 'height'=>768) + * @param string $group_name 分组名 + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return string | boolean + */ + public function storage_upload_by_filebuff1($file_buf, $file_ext_name, Array $meta_list, $group_name, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *通过回调函数上传文件到远程服务器(成功返回一个包括group_name和filename信息的关联数组) + * @example + * @param array $callback_array 回调函数(应包括callback, file_size和args三个元素) + * @param string $file_ext_name 文件扩展名(不包括.) + * @param array $meta_list 文件相关数据,如:array('width'=>1024, 'height'=>768) + * @param string $group_name 分组名 + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return array | boolean + */ + public function storage_upload_by_callback(Array $callback_array, $file_ext_name, Array $meta_list, $group_name, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *通过回调函数上传文件到远程服务器(成功返回文件ID) + * @example + * @param array $callback_array 回调函数(应包括callback, file_size和args三个元素) + * @param string $file_ext_name 文件扩展名(不包括.) + * @param array $meta_list 文件相关数据,如:array('width'=>1024, 'height'=>768) + * @param string $group_name 分组名 + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return string | boolean + */ + public function storage_upload_by_callback1(Array $callback_array, $file_ext_name, Array $meta_list, $group_name, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *将文件追加到存储服务器中的文件中(一般用于断点续传) + * @example + * @param string $local_filename 文件名 + * @param string $group_name 分组名 + * @param string $appender_filename 被追加的文件名 + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return boolean + */ + public function storage_append_by_filename($local_filename, $group_name, $appender_filename, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *将文件追加到存储服务器中的文件中(一般用于断点续传) + * @example + * @param string $local_filename 文件名 + * @param string $appender_file_id 被追加的文件ID + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return boolean + */ + public function storage_append_by_filename1($local_filename, $appender_file_id, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *将文件追加到存储服务器中的文件中(一般用于断点续传) + * @example + * @param string $file_buff 文件内容 + * @param string $group_name 分组名 + * @param string $appender_filename 被追加的文件名 + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return boolean + */ + public function storage_append_by_filebuff($file_buff, $group_name, $appender_filename, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *将文件追加到存储服务器中的文件中(一般用于断点续传) + * @example + * @param string $file_buff 文件内容 + * @param string $appender_file_id 被追加的文件ID + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return boolean + */ + public function storage_append_by_filebuff1($file_buff, $appender_file_id, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *通过回调函数将文件追加到存储服务器中的文件中(一般用于断点续传) + * @example + * @param array $callback_array 回调函数(应包括callback, file_size和args三个元素) + * @param string $group_name 分组名 + * @param string $appender_filename 被追加的文件名 + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return boolean + */ + public function storage_append_by_callback(Array $callback_array, $group_name, $appender_filename, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *将文件追加到存储服务器中的文件中(一般用于断点续传) + * @example + * @param array $callback_array 回调函数(应包括callback, file_size和args三个元素) + * @param string $appender_file_id 被追加的文件ID + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return boolean + */ + public function storage_append_by_callback1(Array $callback_array, $appender_file_id, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *通过本地文件修改追加的文件 + * @example + * @param string $local_filename 本地文件名 + * @param int $file_offset 文件位置 + * @param string $group_name 分组名 + * @param string $appender_filename 被追加的文件 + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return boolean + */ + public function storage_modify_by_filename($local_filename, $file_offset, $group_name, $appender_filename, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *通过本地文件修改追加的文件 + * @example + * @param string $local_filename 本地文件名 + * @param int $file_offset 文件位置 + * @param string $appender_file_id 被追加的文件ID + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return boolean + */ + public function storage_modify_by_filename1($local_filename, $file_offset, $appender_file_id, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *通过本地文件修改追加的文件 + * @example + * @param string $file_buff 本地文件内容 + * @param int $file_offset 文件位置 + * @param string $group_name 分组名 + * @param string $appender_filename 被追加的文件 + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return boolean + */ + public function storage_modify_by_filebuff($file_buff, $file_offset, $group_name, $appender_filename, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *通过本地文件修改追加的文件 + * @example + * @param string $local_filename 本地文件名 + * @param int $file_offset 文件位置 + * @param string $appender_file_id 被追加的文件ID + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return boolean + */ + public function storage_modify_by_filebuff1($local_filename, $file_offset, $appender_file_id, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *通过回调函数修改追加的文件 + * @example + * @param array $callback_array 回调函数(应包括callback, file_size和args三个元素) + * @param int $file_offset 文件位置 + * @param string $group_name 分组名 + * @param string $appender_filename 被追加的文件 + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return boolean + */ + public function storage_modify_by_callback(Array $callback_array, $file_offset, $group_name, $appender_filename, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *通过回调函数修改追加的文件 + * @example + * @param array $callback_array 回调函数(应包括callback, file_size和args三个元素) + * @param int $file_offset 文件位置 + * @param string $appender_file_id 被追加的文件ID + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return boolean + */ + public function storage_modify_by_callback1(Array $callback_array, $file_offset, $appender_file_id, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *将本地文件作为副加文件上传到远程服务器(成功返回一个包括group_name和filename信息的关联数组) + * @example + * @param string $local_filename 本地文件 + * @param string $file_ext_name 文件扩展名(不包括.) + * @param array $meta_list 文件相关数据,如:array('width'=>1024, 'height'=>768) + * @param string $group_name 分组名 + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return array | boolean + */ + public function storage_upload_appender_by_filename($local_filename, $file_ext_name, Array $meta_list, $group_name, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *将本地文件作为附加文件上传到远程服务器(成功返回文件ID) + * @example + * @param string $local_filename 本地文件 + * @param string $file_ext_name 文件扩展名(不包括.) + * @param array $meta_list 文件相关数据,如:array('width'=>1024, 'height'=>768) + * @param string $group_name 分组名 + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return string | boolean + */ + public function storage_upload_appender_by_filename1($local_filename, $file_ext_name, Array $meta_list, $group_name, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *通本地文件内容上传文件到远程服务器(成功返回一个包括group_name和filename信息的关联数组) + * @example + * @param string $file_buf 文件内容 + * @param string $file_ext_name 文件扩展名(不包括.) + * @param array $meta_list 文件相关数据,如:array('width'=>1024, 'height'=>768) + * @param string $group_name 分组名 + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return array | boolean + */ + public function storage_upload_appender_by_filebuff($file_buf, $file_ext_name, Array $meta_list, $group_name, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *通过文件内容将本地文件上传到远程服务器(成功返回一个包括group_name和filename信息的关联数组) + * @example + * @param string $file_buff 文件内容 + * @param string $file_ext_name 文件扩展名(不包括.) + * @param array $meta_list 文件相关数据,如:array('width'=>1024, 'height'=>768) + * @param string $group_name 分组名 + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return string | boolean + */ + public function storage_upload_appender_by_filebuff1($file_buff, $file_ext_name, Array $meta_list, $group_name, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *通过回调函数上传文件到远程服务器(成功返回一个包括group_name和filename信息的关联数组) + * @example + * @param array $callback_array 回调函数(应包括callback, file_size和args三个元素) + * @param string $file_ext_name 文件扩展名(不包括.) + * @param array $meta_list 文件相关数据,如:array('width'=>1024, 'height'=>768) + * @param string $group_name 分组名 + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return array | boolean + */ + public function storage_upload_appender_by_callback(Array $callback_array, $file_ext_name, Array $meta_list, $group_name, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *通过回调函数上传文件到远程服务器(成功返回文件ID) + * @example + * @param array $callback_array 回调函数(应包括callback, file_size和args三个元素) + * @param string $file_ext_name 文件扩展名(不包括.) + * @param array $meta_list 文件相关数据,如:array('width'=>1024, 'height'=>768) + * @param string $group_name 分组名 + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return string | boolean + */ + public function storage_upload_appender_by_callback1(Array $callback_array, $file_ext_name, Array $meta_list, $group_name, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *上传本地文件到存储服务器(从文件模式,成功返回一个包含 group_name和filename的关联数组) + * @example + * @param string $local_filename 本地文件名 + * @param string $group_name 分组名 + * @param string $master_filename 主文件名 + * @param string $prefix_name 前缀名 + * @param string $file_ext_name 文件扩展名(不包括.) + * @param array $meta_list 文件相关数据,如:array('width'=>1024, 'height'=>768) + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return array | boolean + */ + public function storage_upload_slave_by_filename($local_filename, $group_name, $master_filename, $prefix_name, $file_ext_name, Array $meta_list, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *上传本地文件到存储服务器(从文件模式,成功返回文件ID) + * @example + * @param string $local_filename 本地文件名 + * @param string $master_file_id 主文件ID + * @param string $prefix_name 前缀名 + * @param string $file_ext_name 文件扩展名(不包括.) + * @param array $meta_list 文件相关数据,如:array('width'=>1024, 'height'=>768) + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return array | boolean + */ + public function storage_upload_slave_by_filename1($local_filename, $master_file_id, $prefix_name, $file_ext_name, Array $meta_list, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *上传本地文件到存储服务器(从文件模式,成功返回一个包含 group_name和filename的关联数组) + * @example + * @param string $file_buff 本地文件内容 + * @param string $group_name 分组名 + * @param string $master_filename 主文件名 + * @param string $prefix_name 前缀名 + * @param string $file_ext_name 文件扩展名(不包括.) + * @param array $meta_list 文件相关数据,如:array('width'=>1024, 'height'=>768) + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return array | boolean + */ + public function storage_upload_slave_by_filebuff($file_buff, $group_name, $master_filename, $prefix_name, $file_ext_name, Array $meta_list, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *上传本地文件到存储服务器(从文件模式,成功返回文件ID) + * @example + * @param string $file_buff 本地文件内容 + * @param string $master_file_id 主文件ID + * @param string $prefix_name 前缀名 + * @param string $file_ext_name 文件扩展名(不包括.) + * @param array $meta_list 文件相关数据,如:array('width'=>1024, 'height'=>768) + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return array | boolean + */ + public function storage_upload_slave_by_filebuff1($file_buff, $master_file_id, $prefix_name, $file_ext_name, Array $meta_list, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *通过回调函数上传本地文件到存储服务器(从文件模式,成功返回一个包含 group_name和filename的关联数组) + * @example + * @param array $callback_array 回调函数(应包括callback, file_size和args三个元素) + * @param string $group_name 分组名 + * @param string $master_filename 主文件名 + * @param string $prefix_name 前缀名 + * @param string $file_ext_name 文件扩展名(不包括.) + * @param array $meta_list 文件相关数据,如:array('width'=>1024, 'height'=>768) + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return array | boolean + */ + public function storage_upload_slave_by_callback(Array $callback_array, $group_name, $master_filename, $prefix_name, $file_ext_name, Array $meta_list, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *通过回调函数上传本地文件到存储服务器(从文件模式,成功返回文件ID) + * @example + * @param array $callback_array 回调函数(应包括callback, file_size和args三个元素) + * @param string $master_file_id 主文件ID + * @param string $prefix_name 前缀名 + * @param string $file_ext_name 文件扩展名(不包括.) + * @param array $meta_list 文件相关数据,如:array('width'=>1024, 'height'=>768) + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return string | boolean + */ + public function storage_upload_slave_by_callback1(Array $callback_array, $master_file_id, $prefix_name, $file_ext_name, Array $meta_list, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *删除存储服务器上的文件 + * @example + * @param string $group_name 分组名 + * @param string $remote_filename 文件名 + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return boolean + */ + public function storage_delete_file($group_name, $remote_filename, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *删除存储服务器上的文件 + * @example + * @param string $remote_file_id 文件ID + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return boolean + */ + public function storage_delete_file1($remote_file_id, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *根据指定的大小截取文件 + * @example + * @param string $group_name 分组名 + * @param string $appender_filename 被截取的文件名 + * @param int $truncated_file_size 截取大小 + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return boolean + */ + public function storage_truncate_file($group_name, $appender_filename, $truncated_file_size, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *根据指定的大小截取文件 + * @example + * @param string $appender_file_id 被截取的文件ID + * @param int $truncated_file_size 截取大小 + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return boolean + */ + public function storage_truncate_file1($appender_file_id, $truncated_file_size, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *获取服务器上的文件内容 + * @example + * @param string $group_name 分组名 + * @param string $remote_filename 文件名 + * @param int $file_offset 文件位置 + * @param int $download_bytes 下载的字节数(默认为0,表示下载整个文件) + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return string | boolean + */ + public function storage_download_file_to_buff($group_name, $remote_filename, $file_offset, $download_bytes, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *获取服务器上的文件内容 + * @example + * @param string $remote_file_id 文件ID + * @param int $file_offset 文件位置 + * @param int $download_bytes 下载的字节数(默认为0,表示下载整个文件) + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return string | boolean + */ + public function storage_download_file_to_buff1($remote_file_id, $file_offset, $download_bytes, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *将服务器上的文件下载到本地,存储为本地文件 + * @example + * @param string $group_name 分组名 + * @param string $remote_filename 服务器上文件名 + * @param string $local_filename 本地文件名 + * @param int $file_offset 文件位置 + * @param int $download_bytes 下载的字节数(默认为0,表示下载整个文件) + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return boolean + */ + public function storage_download_file_to_file($group_name, $remote_filename, $local_filename, $file_offset, $download_bytes, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *将服务器上的文件下载到本地,存储为本地文件 + * @example + * @param string $remote_file_id 服务器上文件ID + * @param string $local_filename 本地文件名 + * @param int $file_offset 文件位置 + * @param int $download_bytes 下载的字节数(默认为0,表示下载整个文件) + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return boolean + */ + public function storage_download_file_to_file1($remote_file_id, $local_filename, $file_offset, $download_bytes, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *通过回调函数处理将服务器上的下载的文件 + * @example + * @param string $group_name 分组名 + * @param string $remote_filename 服务器上文件名 + * @param array $download_callback 回调函数(应包括callback和args两个元素) + * @param int $file_offset 文件位置 + * @param int $download_bytes 下载的字节数(默认为0,表示下载整个文件) + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return boolean + */ + public function storage_download_file_to_callback($group_name, $remote_filename, Array $download_callback, $file_offset, $download_bytes, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *通过回调函数处理将服务器上的下载的文件 + * @example + * @param string $remote_file_id 服务器上文件ID + * @param array $download_callback 回调函数(应包括callback和args两个元素) + * @param int $file_offset 文件位置 + * @param int $download_bytes 下载的字节数(默认为0,表示下载整个文件) + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return boolean + */ + public function storage_download_file_to_callback1($remote_file_id, Array $download_callback, $file_offset, $download_bytes, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *设置文件元数据 + * @example + * @param string $group_name 分组名 + * @param string $remote_filename 服务器上文件名 + * @param array $meta_list 文件相关数据,如:array('width'=>1024, 'height'=>768) + * @param string $op_type 操作标识(共有以下两个可选项: + FDFS_STORAGE_SET_METADATA_FLAG_MERGE: 与旧元数据合并 + FDFS_STORAGE_SET_METADATA_FLAG_OVERWRITE: 覆盖旧元数据) + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return boolean + */ + public function storage_set_metadata($group_name, $remote_filename, Array $meta_list, $op_type, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *设置文件元数据 + * @example + * @param string $remote_file_id 服务器上文件ID + * @param array $meta_list 文件相关数据,如:array('width'=>1024, 'height'=>768) + * @param string $op_type 操作标识(共有以下两个可选项: + FDFS_STORAGE_SET_METADATA_FLAG_MERGE: 与旧元数据合并 + FDFS_STORAGE_SET_METADATA_FLAG_OVERWRITE: 覆盖旧元数据) + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return boolean + */ + public function storage_set_metadata1($remote_file_id, Array $meta_list, $op_type, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *获取文件元数据(成功返回如:array('width' => 1024, 'height' => 768)) + * @example + * @param string $group_name 分组名 + * @param string $remote_filename 服务器上文件名 + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return array | boolean + */ + public function storage_get_metadata($group_name, $remote_filename, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *获取文件元数据(成功返回如:array('width' => 1024, 'height' => 768)) + * @example + * @param string $remote_file_id 服务器上文件ID + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return array | boolean + */ + public function storage_get_metadata1($remote_file_id, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *通过文件名等检查文件是否存在 + * @example + * @param string $group_name 分组名 + * @param string $remote_filename 文件名 + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return boolean + */ + public function storage_file_exist($group_name, $remote_filename, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *通过文件ID检查文件是否存在 + * @example + * @param string $file_id 文件ID + * @param array $track_servers 指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @param array $storage_servers 指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) + * @return boolean + */ + public function storage_file_exist1($file_id, Array $track_servers, Array $storage_servers) + { + } + + /** + * + *获取上次错误码 + * @example + * @return int + */ + public function get_last_error_no() + { + } + + /** + * + *获取上次错误信息 + * @example + * @return string + */ + public function get_last_error_info() + { + } + + /** + * + *生成针对http下载防止盗用链接的token + * @example + * @param string $remote_filename 下载的文件地址(不包含group的名称) + * @param int $timestamp 时间戳 + * @return string | boolean + */ + public function http_gen_token($remote_filename, $timestamp) + { + } + + /** + * + *获取文件信息(返回值包括3个信息: + * create_timestamp:文件创建时间; + * file_size: 文件大小 (字节) + * source_ip_addr: 文件存储原始的IP地址) + * @example + * @param string $group_name 分组名称 + * @param string $filename 文件名 + * @return array|boolean + */ + public function get_file_info($group_name, $filename) + { + } + + /** + * + *获取文件ID获取文件信息(返回值包括3个信息: + * create_timestamp:文件创建时间; + * file_size: 文件大小 (字节) + * source_ip_addr: 文件存储原始的IP地址) + * @example + * @param string $file_id 文件ID + * @return array|boolean + */ + public function get_file_info1($file_id) + { + } + + /** + * + *向指定的连接发送数据 + * @example + * @param int $sock 连接描述符 + * @param string $buff 发送的数据 + * @return boolean + */ + public function send_data($sock, $buff) + { + } + + /** + * + *通过主文件,文件前缀和文件扩展名生成从文件 + * @example + * @param string $master_filename 主文件 + * @param string $suffix 文件前缀 + * @param string $extension 文件扩展名 + * @return string | boolean + */ + public function gen_slave_filename($master_filename, $suffix, $extension) + { + } + + /** + * + *关闭与跟踪服务器的连接 + * @example + * @return + */ + public function close() + { + } + +} + diff --git a/src/Swoole/swoole_mysql_coro_exception.php b/src/Fastdfs_client/FastDFSException.php similarity index 62% rename from src/Swoole/swoole_mysql_coro_exception.php rename to src/Fastdfs_client/FastDFSException.php index 347d37c..1ab858c 100644 --- a/src/Swoole/swoole_mysql_coro_exception.php +++ b/src/Fastdfs_client/FastDFSException.php @@ -1,18 +1,18 @@ 1024, 'height'=>768) +* @param string $group_name:分组名 +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return array | boolean +*/ +function fastdfs_storage_upload_by_filename($local_filename, $file_ext_name, Array $meta_list, $group_name, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*将本地文件上传到远程服务器(成功返回一个包括文件ID) +* @example +* +* @param string $local_filename:本地文件 +* @param string $file_ext_name:文件扩展名(不包括.) +* @param array $meta_list:文件相关数据,如:array('width'=>1024, 'height'=>768) +* @param string $group_name:分组名 +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return string | boolean +*/ +function fastdfs_storage_upload_by_filename1($local_filename, $file_ext_name, Array $meta_list, $group_name, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*通过文件内容将文件上传到远程服务器(成功返回一个包括group_name和filename信息的关联数组) +* @example +* +* @param string $file_buf:文件内容 +* @param string $file_ext_name:文件扩展名(不包括.) +* @param array $meta_list:文件相关数据,如:array('width'=>1024, 'height'=>768) +* @param string $group_name:分组名 +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return array | boolean +*/ +function fastdfs_storage_upload_by_filebuff($file_buf, $file_ext_name, Array $meta_list, $group_name, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*通过文件内容将文件上传到远程服务器(成功返回文件ID) +* @example +* +* @param string $file_buf:文件内容 +* @param string $file_ext_name:文件扩展名(不包括.) +* @param array $meta_list:文件相关数据,如:array('width'=>1024, 'height'=>768) +* @param string $group_name:分组名 +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return string | boolean +*/ +function fastdfs_storage_upload_by_filebuff1($file_buf, $file_ext_name, Array $meta_list, $group_name, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*通过回调函数上传文件到远程服务器(成功返回一个包括group_name和filename信息的关联数组) +* @example +* +* @param array $callback_array:回调函数(应包括callback, file_size和args三个元素) +* @param string $file_ext_name:文件扩展名(不包括.) +* @param array $meta_list:文件相关数据,如:array('width'=>1024, 'height'=>768) +* @param string $group_name:分组名 +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return array | boolean +*/ +function fastdfs_storage_upload_by_callback(Array $callback_array, $file_ext_name, Array $meta_list, $group_name, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*通过回调函数上传文件到远程服务器(成功返回文件ID) +* @example +* +* @param array $callback_array:回调函数(应包括callback, file_size和args三个元素) +* @param string $file_ext_name:文件扩展名(不包括.) +* @param array $meta_list:文件相关数据,如:array('width'=>1024, 'height'=>768) +* @param string $group_name:分组名 +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return string | boolean +*/ +function fastdfs_storage_upload_by_callback1(Array $callback_array, $file_ext_name, Array $meta_list, $group_name, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*将文件追加到存储服务器中的文件中(一般用于断点续传) +* @example +* +* @param string $local_filename:文件名 +* @param string $group_name:分组名 +* @param string $appender_filename:被追加的文件名 +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return boolean +*/ +function fastdfs_storage_append_by_filename($local_filename, $group_name, $appender_filename, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*将文件追加到存储服务器中的文件中(一般用于断点续传) +* @example +* +* @param string $local_filename:文件名 +* @param string $appender_file_id:被追加的文件ID +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return boolean +*/ +function fastdfs_storage_append_by_filename1($local_filename, $appender_file_id, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*将文件追加到存储服务器中的文件中(一般用于断点续传) +* @example +* +* @param string $file_buff:文件内容 +* @param string $group_name:分组名 +* @param string $appender_filename:被追加的文件名 +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return boolean +*/ +function fastdfs_storage_append_by_filebuff($file_buff, $group_name, $appender_filename, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*将文件追加到存储服务器中的文件中(一般用于断点续传) +* @example +* +* @param string $file_buff:文件内容 +* @param string $appender_file_id:被追加的文件ID +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return boolean +*/ +function fastdfs_storage_append_by_filebuff1($file_buff, $appender_file_id, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*通过回调函数将文件追加到存储服务器中的文件中(一般用于断点续传) +* @example +* +* @param array $callback_array:回调函数(应包括callback, file_size和args三个元素) +* @param string $group_name:分组名 +* @param string $appender_filename:被追加的文件名 +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return boolean +*/ +function fastdfs_storage_append_by_callback(Array $callback_array, $group_name, $appender_filename, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*将文件追加到存储服务器中的文件中(一般用于断点续传) +* @example +* +* @param array $callback_array:回调函数(应包括callback, file_size和args三个元素) +* @param string $appender_file_id:被追加的文件ID +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return boolean +*/ +function fastdfs_storage_append_by_callback1(Array $callback_array, $appender_file_id, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*通过本地文件修改追加的文件 +* @example +* +* @param string $local_filename:本地文件名 +* @param int $file_offset:文件位置 +* @param string $group_name:分组名 +* @param string $appender_filename:被追加的文件 +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return boolean +*/ +function fastdfs_storage_modify_by_filename($local_filename, $file_offset, $group_name, $appender_filename, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*通过本地文件修改追加的文件 +* @example +* +* @param string $local_filename:本地文件名 +* @param int $file_offset:文件位置 +* @param string $appender_file_id:被追加的文件ID +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return boolean +*/ +function fastdfs_storage_modify_by_filename1($local_filename, $file_offset, $appender_file_id, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*通过本地文件修改追加的文件 +* @example +* +* @param string $file_buff:本地文件内容 +* @param int $file_offset:文件位置 +* @param string $group_name:分组名 +* @param string $appender_filename:被追加的文件 +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return boolean +*/ +function fastdfs_storage_modify_by_filebuff($file_buff, $file_offset, $group_name, $appender_filename, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*通过本地文件修改追加的文件 +* @example +* +* @param string $local_filename:本地文件名 +* @param int $file_offset:文件位置 +* @param string $appender_file_id:被追加的文件ID +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return boolean +*/ +function fastdfs_storage_modify_by_filebuff1($local_filename, $file_offset, $appender_file_id, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*通过回调函数修改追加的文件 +* @example +* +* @param array $callback_array:回调函数(应包括callback, file_size和args三个元素) +* @param int $file_offset:文件位置 +* @param string $group_name:分组名 +* @param string $appender_filename:被追加的文件 +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return boolean +*/ +function fastdfs_storage_modify_by_callback(Array $callback_array, $file_offset, $group_name, $appender_filename, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*通过回调函数修改追加的文件 +* @example +* +* @param array $callback_array:回调函数(应包括callback, file_size和args三个元素) +* @param int $file_offset:文件位置 +* @param string $appender_file_id:被追加的文件ID +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return boolean +*/ +function fastdfs_storage_modify_by_callback1(Array $callback_array, $file_offset, $appender_file_id, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*将本地文件作为副加文件上传到远程服务器(成功返回一个包括group_name和filename信息的关联数组) +* @example +* +* @param string $local_filename:本地文件 +* @param string $file_ext_name:文件扩展名(不包括.) +* @param array $meta_list:文件相关数据,如:array('width'=>1024, 'height'=>768) +* @param string $group_name:分组名 +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return array | boolean +*/ +function fastdfs_storage_upload_appender_by_filename($local_filename, $file_ext_name, Array $meta_list, $group_name, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*将本地文件作为附加文件上传到远程服务器(成功返回文件ID) +* @example +* +* @param string $local_filename:本地文件 +* @param string $file_ext_name:文件扩展名(不包括.) +* @param array $meta_list:文件相关数据,如:array('width'=>1024, 'height'=>768) +* @param string $group_name:分组名 +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return string | boolean +*/ +function fastdfs_storage_upload_appender_by_filename1($local_filename, $file_ext_name, Array $meta_list, $group_name, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*通本地文件内容上传文件到远程服务器(成功返回一个包括group_name和filename信息的关联数组) +* @example +* +* @param string $file_buf:文件内容 +* @param string $file_ext_name:文件扩展名(不包括.) +* @param array $meta_list:文件相关数据,如:array('width'=>1024, 'height'=>768) +* @param string $group_name:分组名 +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return array | boolean +*/ +function fastdfs_storage_upload_appender_by_filebuff($file_buf, $file_ext_name, Array $meta_list, $group_name, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*通过文件内容将本地文件上传到远程服务器(成功返回一个包括group_name和filename信息的关联数组) +* @example +* +* @param string $file_buff:文件内容 +* @param string $file_ext_name:文件扩展名(不包括.) +* @param array $meta_list:文件相关数据,如:array('width'=>1024, 'height'=>768) +* @param string $group_name:分组名 +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return string | boolean +*/ +function fastdfs_storage_upload_appender_by_filebuff1($file_buff, $file_ext_name, Array $meta_list, $group_name, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*通过回调函数上传文件到远程服务器(成功返回一个包括group_name和filename信息的关联数组) +* @example +* +* @param array $callback_array:回调函数(应包括callback, file_size和args三个元素) +* @param string $file_ext_name:文件扩展名(不包括.) +* @param array $meta_list:文件相关数据,如:array('width'=>1024, 'height'=>768) +* @param string $group_name:分组名 +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return array | boolean +*/ +function fastdfs_storage_upload_appender_by_callback(Array $callback_array, $file_ext_name, Array $meta_list, $group_name, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*通过回调函数上传文件到远程服务器(成功返回文件ID) +* @example +* +* @param array $callback_array:回调函数(应包括callback, file_size和args三个元素) +* @param string $file_ext_name:文件扩展名(不包括.) +* @param array $meta_list:文件相关数据,如:array('width'=>1024, 'height'=>768) +* @param string $group_name:分组名 +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return string | boolean +*/ +function fastdfs_storage_upload_appender_by_callback1(Array $callback_array, $file_ext_name, Array $meta_list, $group_name, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*上传本地文件到存储服务器(从文件模式,成功返回一个包含 group_name和filename的关联数组) +* @example +* +* @param string $local_filename:本地文件名 +* @param string $group_name:分组名 +* @param string $master_filename:主文件名 +* @param string $prefix_name:前缀名 +* @param string $file_ext_name:文件扩展名(不包括.) +* @param array $meta_list:文件相关数据,如:array('width'=>1024, 'height'=>768) +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return array | boolean +*/ +function fastdfs_storage_upload_slave_by_filename($local_filename, $group_name, $master_filename, $prefix_name, $file_ext_name, Array $meta_list, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*上传本地文件到存储服务器(从文件模式,成功返回文件ID) +* @example +* +* @param string $local_filename:本地文件名 +* @param string $master_file_id:主文件ID +* @param string $prefix_name:前缀名 +* @param string $file_ext_name:文件扩展名(不包括.) +* @param array $meta_list:文件相关数据,如:array('width'=>1024, 'height'=>768) +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return array | boolean +*/ +function fastdfs_storage_upload_slave_by_filename1($local_filename, $master_file_id, $prefix_name, $file_ext_name, Array $meta_list, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*上传本地文件到存储服务器(从文件模式,成功返回一个包含 group_name和filename的关联数组) +* @example +* +* @param string $file_buff:本地文件内容 +* @param string $group_name:分组名 +* @param string $master_filename:主文件名 +* @param string $prefix_name:前缀名 +* @param string $file_ext_name:文件扩展名(不包括.) +* @param array $meta_list:文件相关数据,如:array('width'=>1024, 'height'=>768) +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return array | boolean +*/ +function fastdfs_storage_upload_slave_by_filebuff($file_buff, $group_name, $master_filename, $prefix_name, $file_ext_name, Array $meta_list, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*上传本地文件到存储服务器(从文件模式,成功返回文件ID) +* @example +* +* @param string $file_buff:本地文件内容 +* @param string $master_file_id:主文件ID +* @param string $prefix_name:前缀名 +* @param string $file_ext_name:文件扩展名(不包括.) +* @param array $meta_list:文件相关数据,如:array('width'=>1024, 'height'=>768) +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return array | boolean +*/ +function fastdfs_storage_upload_slave_by_filebuff1($file_buff, $master_file_id, $prefix_name, $file_ext_name, Array $meta_list, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*通过回调函数上传本地文件到存储服务器(从文件模式,成功返回一个包含 group_name和filename的关联数组) +* @example +* +* @param array $callback_array:回调函数(应包括callback, file_size和args三个元素) +* @param string $group_name:分组名 +* @param string $master_filename:主文件名 +* @param string $prefix_name:前缀名 +* @param string $file_ext_name:文件扩展名(不包括.) +* @param array $meta_list:文件相关数据,如:array('width'=>1024, 'height'=>768) +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return array | boolean +*/ +function fastdfs_storage_upload_slave_by_callback(Array $callback_array, $group_name, $master_filename, $prefix_name, $file_ext_name, Array $meta_list, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*通过回调函数上传本地文件到存储服务器(从文件模式,成功返回文件ID) +* @example +* +* @param array $callback_array:回调函数(应包括callback, file_size和args三个元素) +* @param string $master_file_id:主文件ID +* @param string $prefix_name:前缀名 +* @param string $file_ext_name:文件扩展名(不包括.) +* @param array $meta_list:文件相关数据,如:array('width'=>1024, 'height'=>768) +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return string | boolean +*/ +function fastdfs_storage_upload_slave_by_callback1(Array $callback_array, $master_file_id, $prefix_name, $file_ext_name, Array $meta_list, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*删除存储服务器上的文件 +* @example +* +* @param string $group_name:分组名 +* @param string $remote_filename:文件名 +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return boolean +*/ +function fastdfs_storage_delete_file($group_name, $remote_filename, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*删除存储服务器上的文件 +* @example +* +* @param string $remote_file_id:文件ID +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return boolean +*/ +function fastdfs_storage_delete_file1($remote_file_id, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*根据指定的大小截取文件 +* @example +* +* @param string $group_name:分组名 +* @param string $appender_filename:被截取的文件名 +* @param int $truncated_file_size:截取大小 +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return boolean +*/ +function fastdfs_storage_truncate_file($group_name, $appender_filename, $truncated_file_size, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*根据指定的大小截取文件 +* @example +* +* @param string $appender_file_id:被截取的文件ID +* @param int $truncated_file_size:截取大小 +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return boolean +*/ +function fastdfs_storage_truncate_file1($appender_file_id, $truncated_file_size, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*获取服务器上的文件内容 +* @example +* +* @param string $group_name:分组名 +* @param string $remote_filename:文件名 +* @param int $file_offset:文件位置 +* @param int $download_bytes:下载的字节数(默认为0,表示下载整个文件) +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return string | boolean +*/ +function fastdfs_storage_download_file_to_buff($group_name, $remote_filename, $file_offset, $download_bytes, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*获取服务器上的文件内容 +* @example +* +* @param string $remote_file_id:文件ID +* @param int $file_offset:文件位置 +* @param int $download_bytes:下载的字节数(默认为0,表示下载整个文件) +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return string | boolean +*/ +function fastdfs_storage_download_file_to_buff1($remote_file_id, $file_offset, $download_bytes, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*将服务器上的文件下载到本地,存储为本地文件 +* @example +* +* @param string $group_name:分组名 +* @param string $remote_filename:服务器上文件名 +* @param string $local_filename:本地文件名 +* @param int $file_offset:文件位置 +* @param int $download_bytes:下载的字节数(默认为0,表示下载整个文件) +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return boolean +*/ +function fastdfs_storage_download_file_to_file($group_name, $remote_filename, $local_filename, $file_offset, $download_bytes, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*将服务器上的文件下载到本地,存储为本地文件 +* @example +* +* @param string $remote_file_id:服务器上文件ID +* @param string $local_filename:本地文件名 +* @param int $file_offset:文件位置 +* @param int $download_bytes:下载的字节数(默认为0,表示下载整个文件) +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return boolean +*/ +function fastdfs_storage_download_file_to_file1($remote_file_id, $local_filename, $file_offset, $download_bytes, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*通过回调函数处理将服务器上的下载的文件 +* @example +* +* @param string $group_name:分组名 +* @param string $remote_filename:服务器上文件名 +* @param array $download_callback:回调函数(应包括callback和args两个元素) +* @param int $file_offset:文件位置 +* @param int $download_bytes:下载的字节数(默认为0,表示下载整个文件) +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return boolean +*/ +function fastdfs_storage_download_file_to_callback($group_name, $remote_filename, Array $download_callback, $file_offset, $download_bytes, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*通过回调函数处理将服务器上的下载的文件 +* @example +* +* @param string $remote_file_id:服务器上文件ID +* @param array $download_callback:回调函数(应包括callback和args两个元素) +* @param int $file_offset:文件位置 +* @param int $download_bytes:下载的字节数(默认为0,表示下载整个文件) +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return boolean +*/ +function fastdfs_storage_download_file_to_callback1($remote_file_id, Array $download_callback, $file_offset, $download_bytes, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*设置文件元数据 +* @example +* +* @param string $group_name:分组名 +* @param string $remote_filename:服务器上文件名 +* @param array $meta_list:文件相关数据,如:array('width'=>1024, 'height'=>768) +* @param string $op_type:操作标识(共有以下两个可选项: + FDFS_STORAGE_SET_METADATA_FLAG_MERGE: 与旧元数据合并 + FDFS_STORAGE_SET_METADATA_FLAG_OVERWRITE: 覆盖旧元数据) +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return boolean +*/ +function fastdfs_storage_set_metadata($group_name, $remote_filename, Array $meta_list, $op_type, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*设置文件元数据 +* @example +* +* @param string $remote_file_id:服务器上文件ID +* @param array $meta_list:文件相关数据,如:array('width'=>1024, 'height'=>768) +* @param string $op_type:操作标识(共有以下两个可选项: + FDFS_STORAGE_SET_METADATA_FLAG_MERGE: 与旧元数据合并 + FDFS_STORAGE_SET_METADATA_FLAG_OVERWRITE: 覆盖旧元数据) +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return boolean +*/ +function fastdfs_storage_set_metadata1($remote_file_id, Array $meta_list, $op_type, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*获取文件元数据(成功返回如:array('width' => 1024, 'height' => 768)) +* @example +* +* @param string $group_name:分组名 +* @param string $remote_filename:服务器上文件名 +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return array | boolean +*/ +function fastdfs_storage_get_metadata($group_name, $remote_filename, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*获取文件元数据(成功返回如:array('width' => 1024, 'height' => 768)) +* @example +* +* @param string $remote_file_id:服务器上文件ID +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return array | boolean +*/ +function fastdfs_storage_get_metadata1($remote_file_id, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*生成针对http下载防止盗用链接的token +* @example +* +* @param string $remote_filename:下载的文件地址(不包含group的名称) +* @param int $timestamp:时间戳 +* @return string | boolean +*/ +function fastdfs_http_gen_token($remote_filename, $timestamp) +{ +} + +/** +* +*获取文件信息(返回值包括3个信息: +* create_timestamp:文件创建时间; +* file_size: 文件大小 (字节) +* source_ip_addr: 文件存储原始的IP地址) +* @example +* +* @param string $group_name:分组名称 +* @param string $filename:文件名 +* @return array|boolean +*/ +function fastdfs_get_file_info($group_name, $filename) +{ +} + +/** +* +*获取文件ID获取文件信息(返回值包括3个信息: +* create_timestamp:文件创建时间; +* file_size: 文件大小 (字节) +* source_ip_addr: 文件存储原始的IP地址) +* @example +* +* @param string $file_id:文件ID +* @return array|boolean +*/ +function fastdfs_get_file_info1($file_id) +{ +} + +/** +* +*通过文件名等检查文件是否存在 +* @example +* +* @param string $group_name:分组名 +* @param string $remote_filename:文件名 +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return boolean +*/ +function fastdfs_storage_file_exist($group_name, $remote_filename, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*通过文件ID检查文件是否存在 +* @example +* +* @param string $file_id:文件ID +* @param array $track_servers:指定跟踪的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @param array $storage_servers:指定存储的服务器(每个数组元素包括ip_addr, port 和 sock三个子元素) +* @return boolean +*/ +function fastdfs_storage_file_exist1($file_id, Array $track_servers, Array $storage_servers) +{ +} + +/** +* +*通过主文件,文件前缀和文件扩展名生成从文件 +* @example +* +* @param string $master_filename:主文件 +* @param string $suffix:文件前缀 +* @param string $extension:文件扩展名 +* @return string | boolean +*/ +function fastdfs_gen_slave_filename($master_filename, $suffix, $extension) +{ +} + +/** +* +*向指定的连接发送数据 +* @example +* +* @param int $sock:连接描述符 +* @param string $buff:发送的数据 +* @return boolean +*/ +function fastdfs_send_data($sock, $buff) +{ +} + diff --git a/src/Redis/Redis.php b/src/Redis/Redis.php index 32a417e..59190ef 100644 --- a/src/Redis/Redis.php +++ b/src/Redis/Redis.php @@ -1,133 +1,255 @@ * $redis->connect('127.0.0.1', 6379); @@ -135,171 +257,216 @@ public function __destruct() * $redis->connect('127.0.0.1', 6379, 2.5); // 2.5 sec timeout. * $redis->connect('/tmp/redis.sock'); // unix domain socket. * + * @param string $host 主机IP + * @param int $port 端口 + * @param float $timeout 连接超时时间(以秒为单位) + * @param mixed $reserved 当使用retry_interval时该值为NULL + * @param int $retry_interval 重试间隔 + * @param float $read_timeout 读操作超时时间 * @return bool */ - public function connect() + public function connect(string $host, int $port, float $timeout, $reserved, int $retry_interval, float $read_timeout): bool { + } /** * - *Connects to a Redis instance or reuse a connection already established with pconnect/popen. + *连接redis(长连接),与connect用法一致 * @example *
-     * $redis->connect('127.0.0.1', 6379);
-     * $redis->connect('127.0.0.1');            // port 6379 by default
+     * $redis->pconnect('127.0.0.1', 6379);
+     * $redis->pconnect('127.0.0.1');            // port 6379 by default
      * $redis->connect('127.0.0.1', 6379, 2.5); // 2.5 sec timeout.
      * $redis->connect('/tmp/redis.sock');      // unix domain socket.
      * 
+ * @param string $host 主机IP + * @param int $port 端口 + * @param float $timeout 连接超时时间(以秒为单位) + * @param mixed $reserved 当使用retry_interval时该值为NULL + * @param int $retry_interval 重试间隔 + * @param float $read_timeout 读操作超时时间 * @return bool */ - public function pconnect() + public function pconnect(string $host, int $port, float $timeout, $reserved, int $retry_interval, float $read_timeout): bool { + } /** * - *Disconnects from the Redis instance, except when pconnect is used. + *关闭redis连接(长连接除外) * @example * @return */ public function close() { + } /** * - *Check the current connection status + *检查当前redis连接状态(成功时返回PONG) * @example * @return string */ - public function ping() + public function ping(): string { + } /** * - * + *向redis发送一个字符串,而且redis服务器将返回一个相同的字符串 * @example - * @return + * @param string $str 发送的字符串 + * @return string */ - public function echo() + public function echo(string $str): string { + } /** * - *Get the value related to the specified key + *获取指定的key的值 * @example $redis->get('key'); - * @return string|bool: + * @return string|bool */ - public function get() + public function get(): ?string { + } /** * - *Set the string value in argument as value of the key. - * @example + *给指定的键设置值 + * @example 直接设置: + * $redis->set('key', 'value'); + * 带有效期的设置: + * $redis->set('key','value', 10); + * 当键不存在时,设置期有效期为10秒: + * $redis->set('key', 'value', Array('nx', 'ex'=>10)); + * 当键存在时,设置期有效期为1000毫秒: + * $redis->set('key', 'value', Array('xx', 'px'=>1000)); + * + * @param string $key 设置的缓存键 + * @param string $value 设置的缓存值 + * @param int|array $options 附加项,可以是超时时间或者一个选项数组 * @return bool */ - public function set() + public function set(string $key, string $value, int $options): bool { + } /** * - *Set the string value in argument as value of the key, with a time to live. - * @example $redis->setex('key', 3600, 'value'); // sets key → value, with 1h TTL. - * @return bool: + *设置键值并设置有效期 + * @example $redis->setex('key', 3600, 'value'); + * + * @param string $key 设置的缓存键 + * @param int $ttl 有效期 + * @param string $value 设置的缓存值 + * @return bool */ - public function setex() + public function setex(string $key, int $ttl, string $value): bool { + } /** * - * - * @example - * @return + *设置键值并设置有效期(毫秒为单位) + * @example $redis->pSetEx('key', 100, 'value') + * + * @param string $key 设置的缓存键 + * @param int $ttl 有效期(毫秒为单位) + * @param string $value 设置的缓存值 + * @return bool */ - public function psetex() + public function psetex(string $key, int $ttl, string $value): bool { + } /** * - *Set the string value in argument as value of the key if the key doesn't already exist in the database. + *当键不存在时设置其值 * @example - *
-     * $redis->setnx('key', 'value');   // return TRUE
-     * $redis->setnx('key', 'value');   // return FALSE
-     * 
- * @return bool: + * $redis->setnx('key', 'value'); + * + * @param string $key 设置的缓存键 + * @param string $value 设置的缓存值 + * @return bool */ - public function setnx() + public function setnx(string $key, string $value): bool { + } /** * - *Sets a value and returns the previous entry at that key. + *设置键的值,并返回它的旧的缓存值 * @example *
      * $redis->set('x', '42');
      * $exValue = $redis->getSet('x', 'lol');   // return '42', replaces x by 'lol'
      * $newValue = $redis->get('x')'            // return 'lol'
      * 
+ * @param string $key 设置的缓存键 + * @param string $value 设置的缓存值 * @return string */ - public function getSet() + public function getSet(string $key, string $value): string { + } /** * - *Returns a random key. + *返回一个随机的键 * @example *
      * $key = $redis->randomKey();
      * $surprise = $redis->get($key);  // who knows what's in there.
      * 
- * @return string: + * @return string */ - public function randomKey() + public function randomKey(): string { + } /** * - * + *给键重命名 * @example - * @return + * @param string $srcKey 旧键名 + * @param string $dstKey 新键名 + * @return bool */ - public function renameKey() + public function renameKey(string $srcKey, string $dstKey): bool { + } /** * - *Renames a key. + *当目标键名不存在时,给键重命名 * @example - *
-     * $redis->set('x', '42');
-     * $redis->rename('x', 'y');
-     * $redis->get('y');   // → 42
-     * $redis->get('x');   // → `FALSE`
-     * 
- * @return bool: + * @param string $srcKey 旧键名 + * @param string $dstKey 新键名 + * @return bool */ - public function renameNx() + public function renameNx(string $srcKey, string $dstKey): bool { + } /** * - *Get the values of all the specified keys. If one or more keys dont exist, the array will contain FALSE at the - *position of the key. + *批量获取键值 * @example *
      * $redis->set('key1', 'value1');
@@ -308,40 +475,47 @@ public function renameNx()
      * $redis->getMultiple(array('key1', 'key2', 'key3')); // array('value1', 'value2', 'value3');
      * $redis->getMultiple(array('key0', 'key1', 'key5')); // array(`FALSE`, 'value2', `FALSE`);
      * 
+ * @param array $keys 键名数组 * @return array */ - public function getMultiple() + public function getMultiple(Array $keys): array { + } /** * - *Verify if the specified key exists. + *判断键是否存在 * @example *
      * $redis->set('key', 'value');
      * $redis->exists('key');               //  TRUE
      * $redis->exists('NonExistingKey');    // FALSE
      * 
- * @return bool: + * @param string $key 键名 + * @return bool */ - public function exists() + public function exists(string $key): bool { + } /** * - * - * @example + *删除一个或多个键 + * @example $redis->delete('key1', 'key2'); + * $redis->delete(array('key3', 'key4')); + * @param array|string $keys 键名 * @return int */ - public function delete() + public function delete(array $keys): int { + } /** * - *Increment the number stored at key by one. + *键值自增 * @example *
      * $redis->incr('key1'); // key1 didn't exists, set to 0 before the increment and now has the value 1
@@ -349,16 +523,17 @@ public function delete()
      * $redis->incr('key1'); // 3
      * $redis->incr('key1'); // 4
      * 
+ * @param string $key 键名 * @return int */ - public function incr() + public function incr(string $key): int { + } /** * - *Increment the number stored at key by one. If the second argument is filled, it will be used as the integer - *value of the increment. + *按指定步长自增 * @example *
      * $redis->incr('key1');        // key1 didn't exists, set to 0 before the increment and now has the value 1
@@ -367,15 +542,18 @@ public function incr()
      * $redis->incr('key1');        // 4
      * $redis->incrBy('key1', 10);  // 14
      * 
+ * @param string $key 键名 + * @param int $step 自增步长 * @return int */ - public function incrBy() + public function incrBy(string $key, int $step): int { + } /** * - *Increment the float value of a key by the given amount + *按指定步长自增 * @example *
      * $redis = new Redis();
@@ -385,31 +563,35 @@ public function incrBy()
      * // ! SIC
      * var_dump( $redis->get('x') );                // string(3) "4.5"
      * 
- * @return + * @param string $key 键名 + * @param float $step 自增步长 + * @return float */ - public function incrByFloat() + public function incrByFloat(string $key, float $step): float { + } /** * - *Decrement the number stored at key by one. + *键值自减 * @example *
      * $redis->decr('key1'); // key1 didn't exists, set to 0 before the increment and now has the value -1
      * $redis->decr('key1'); // -2
      * $redis->decr('key1'); // -3
      * 
+ * @param string $key 键名 * @return int */ - public function decr() + public function decr(string $key): int { + } /** * - *Decrement the number stored at key by one. If the second argument is filled, it will be used as the integer - *value of the decrement. + *按指定步长自减 * @example *
      * $redis->decr('key1');        // key1 didn't exists, set to 0 before the increment and now has the value -1
@@ -417,85 +599,104 @@ public function decr()
      * $redis->decr('key1');        // -3
      * $redis->decrBy('key1', 10);  // -13
      * 
+ * @param string $key 键名 + * @param float $step 自减步长 * @return int */ - public function decrBy() + public function decrBy(string $key, float $step): int { + } /** * - *Returns the type of data pointed by a given key. + *获取指定键的数据类型(需要根据常量匹配) * @example $redis->type('key'); - * @return - + * @param string $key 键名 + * @return int */ - public function type() + public function type(string $key): int { + } /** * - *Append specified string to the string stored in specified key. + *将字符串追加到键值后(返回值的长度) * @example *
      * $redis->set('key', 'value1');
      * $redis->append('key', 'value2'); // 12
      * $redis->get('key');              // 'value1value2'
      * 
- * @return int: + * @param string $key 键名 + * @param string $value 追加的值 + * @return int */ - public function append() + public function append(string $key, string $value): int { + } /** * - *Return a substring of a larger string + *获取一个键值的子字符串 * @example *
      * $redis->set('key', 'string value');
      * $redis->getRange('key', 0, 5);   // 'string'
      * $redis->getRange('key', -5, -1); // 'value'
      * 
- * @return string: + * @param string $key 键名 + * @param int $start 开始位置 + * @param int $end 结束位置 + * @return string */ - public function getRange() + public function getRange(string $key, int $start, int $end): string { + } /** * - *Changes a substring of a larger string. + *修改某个键的某个位置的值 * @example *
      * $redis->set('key', 'Hello world');
      * $redis->setRange('key', 6, "redis"); // returns 11
      * $redis->get('key');                  // "Hello redis"
      * 
- * @return string: + * @param string $key 键名 + * @param int $offset 开始位置 + * @param string $value 被替换的子串的值 + * @return string */ - public function setRange() + public function setRange(string $key, int $offset, string $value): string { + } /** * - *Return a single bit out of a larger string + *获取某个键的某个位置的位值 * @example *
      * $redis->set('key', "\x7f");  // this is 0111 1111
      * $redis->getBit('key', 0);    // 0
      * $redis->getBit('key', 1);    // 1
      * 
- * @return int: + * @param string $key 键名 + * @param int $offset 所在位置 + * @return int */ - public function getBit() + public function getBit(string $key, int $offset): int { + } /** * - *Changes a single bit of a string. + *修改某个键的某个位置的位值 * @example *
      * $redis->set('key', "*");     // ord("*") = 42 = 0x2f = "0010 1010"
@@ -503,39 +704,49 @@ public function getBit()
      * $redis->setBit('key', 7, 1); // returns 0
      * $redis->get('key');          // chr(0x2f) = "/" = b("0010 1111")
      * 
- * @return int: + * @param string $key 键名 + * @param int $offset 开始位置 + * @param bool|int $value 新值 + * @return int */ - public function setBit() + public function setBit(string $key, int $offset, int $value): int { + } /** * - *Get the length of a string value. + *获取键值的长度 * @example *
      * $redis->set('key', 'value');
      * $redis->strlen('key'); // 5
      * 
- * @return + * @param string $key 键名 + * @return int */ - public function strlen() + public function strlen(string $key): int { + } /** * - * + *根据匹配模式获取键名(如*) * @example - * @return + * $allKeys = $redis->keys('*'); + * $keyWithUserPrefix = $redis->keys('user*'); + * @param string $pattern 匹配模式 + * @return array */ - public function getKeys() + public function getKeys(string $pattern): array { + } /** * - *Sort + *给列表、集合或有序集合的元素排序 * @example *
      * $redis->delete('s');
@@ -548,56 +759,66 @@ public function getKeys()
      * var_dump($redis->sort('s', array('sort' => 'desc'))); // 5,4,3,2,1
      * var_dump($redis->sort('s', array('sort' => 'desc', 'store' => 'out'))); // (int)5
      * 
+ * @param string $key 键名 + * @param array $options 排序参数,如:array('sort' => 'desc') * @return An */ - public function sort() + public function sort(string $key, Array $options): An { + } /** * - * + *给列表、集合或有序集合的元素排序(自小到大顺序) * @example + * @param string $key 键名 * @return */ - public function sortAsc() + public function sortAsc(string $key) { + } /** * - * + *给列表、集合或有序集合的元素排序(按字母顺序) * @example + * @param string $key 键名 * @return */ - public function sortAscAlpha() + public function sortAscAlpha(string $key) { + } /** * - * + *给列表、集合或有序集合的元素排序(自大到小顺序) * @example + * @param string $key 键名 * @return */ - public function sortDesc() + public function sortDesc(string $key) { + } /** * - * + *给列表、集合或有序集合的元素排序(按字母顺序倒序) * @example + * @param string $key 键名 * @return */ - public function sortDescAlpha() + public function sortDescAlpha(string $key) { + } /** * - *Adds the string values to the head (left) of the list. Creates the list if the key didn't exist. - *If the key exists and is not a list, FALSE is returned. + *从左侧(头部)向列表插入元素 * @example *
      * $redis->lPush('l', 'v1', 'v2', 'v3', 'v4')   // int(4)
@@ -610,16 +831,18 @@ public function sortDescAlpha()
      * //   [3]=> string(2) "v1"
      * // }
      * 
+ * @param string $key 键名 + * @param string $value 元素值 * @return int */ - public function lPush() + public function lPush(string $key, string $value): int { + } /** * - *Adds the string values to the tail (right) of the list. Creates the list if the key didn't exist. - *If the key exists and is not a list, FALSE is returned. + *从右侧(尾部)向列表插入元素 * @example *
      * $redis->rPush('l', 'v1', 'v2', 'v3', 'v4');    // int(4)
@@ -632,15 +855,18 @@ public function lPush()
      * //   [3]=> string(2) "v4"
      * // }
      * 
+ * @param string $key 键名 + * @param string $value 元素值 * @return int */ - public function rPush() + public function rPush(string $key, string $value): int { + } /** * - *Adds the string value to the head (left) of the list if the list exists. + *如果列表存在,从左侧(头部)向列表插入元素 * @example *
      * $redis->delete('key1');
@@ -650,15 +876,18 @@ public function rPush()
      * $redis->lPushx('key1', 'C');     // returns 3
      * // key1 now points to the following list: [ 'A', 'B', 'C' ]
      * 
+ * @param string $key 键名 + * @param string $value 元素值 * @return int */ - public function lPushx() + public function lPushx(string $key, string $value): int { + } /** * - *Adds the string value to the tail (right) of the list if the ist exists. FALSE in case of Failure. + *如果列表存在,从右侧(尾部)向列表插入元素 * @example *
      * $redis->delete('key1');
@@ -668,15 +897,18 @@ public function lPushx()
      * $redis->rPushx('key1', 'C'); // returns 3
      * // key1 now points to the following list: [ 'A', 'B', 'C' ]
      * 
+ * @param string $key 键名 + * @param string $value 元素值 * @return int */ - public function rPushx() + public function rPushx(string $key, string $value): int { + } /** * - *Returns and removes the first element of the list. + *从列表左侧删除一个元素 * @example *
      * $redis->rPush('key1', 'A');
@@ -684,15 +916,17 @@ public function rPushx()
      * $redis->rPush('key1', 'C');  // key1 => [ 'A', 'B', 'C' ]
      * $redis->lPop('key1');        // key1 => [ 'B', 'C' ]
      * 
+ * @param string $key 键名 * @return string */ - public function lPop() + public function lPop(string $key): string { + } /** * - *Returns and removes the last element of the list. + *从列表右侧删除一个元素 * @example *
      * $redis->rPush('key1', 'A');
@@ -700,18 +934,17 @@ public function lPop()
      * $redis->rPush('key1', 'C');  // key1 => [ 'A', 'B', 'C' ]
      * $redis->rPop('key1');        // key1 => [ 'A', 'B' ]
      * 
+ * @param string $key 键名 * @return string */ - public function rPop() + public function rPop(string $key): string { + } /** * - *Is a blocking lPop primitive. If at least one of the lists contains at least one element, - *the element will be popped from the head of the list and returned to the caller. - *Il all the list identified by the keys passed in arguments are empty, blPop will block - *during the specified timeout until an element is pushed to one of those lists. This element will be popped. + *是一个阻塞lPop原语。 如果至少有一个列表包含至少一个元素,则该元素将从列表头部弹出并返回给调用者。 如果所有通过参数传递的键标识的列表都是空的,blPop将在指定的超时期间阻塞,直到元素被推送到其中一个列表。 这个元素将被弹出。 * @example *
      * // Non blocking feature
@@ -733,19 +966,18 @@ public function rPop()
      * // process 1
      * // array('key1', 'A') is returned
      * 
+ * @param string|...|array $key 键名 + * @param int $timeout 超时时间 * @return array */ - public function blPop() + public function blPop(string $key, int $timeout): array { + } /** * - *Is a blocking rPop primitive. If at least one of the lists contains at least one element, - *the element will be popped from the head of the list and returned to the caller. - *Il all the list identified by the keys passed in arguments are empty, brPop will - *block during the specified timeout until an element is pushed to one of those lists. T - *his element will be popped. + *是一个阻塞rPop原语。 如果至少有一个列表包含至少一个元素,则该元素将从列表尾部弹出并返回给调用者。 如果所有通过参数传递的键标识的列表都是空的,brPop将在指定的超时期间阻塞,直到元素被推送到其中一个列表。 这个元素将被弹出。 * @example *
      * // Non blocking feature
@@ -767,65 +999,85 @@ public function blPop()
      * // process 1
      * // array('key1', 'A') is returned
      * 
+ * @param string|...|array $key 键名 + * @param int $timeout 超时时间 * @return array */ - public function brPop() + public function brPop(string $key, int $timeout): array { + } /** * - * + *返回列表的长度 * @example - * @return + * @param string|...|array $key 键名 + * @return int | bool */ - public function lSize() + public function lSize(string $key): ?int { + } /** * - * + *从列表中删除指定值的元素。 如果count为零,则删除所有匹配的元素。 如果计数是负数,则元素从尾部移到头部。 * @example - * @return + * @param string $key 键名 + * @param string $value 元素值 + * @param int $count 删除的个数 + * @return int | bool */ - public function lRemove() + public function lRemove(string $key, string $value, int $count): ?int { + } /** * - * + *删除指定范围外的其他元素 * @example - * @return + * @param string $key 键名 + * @param int $start 开始索引 + * @param int $end 结束索引 + * @return array | bool */ - public function listTrim() + public function listTrim(string $key, int $start, int $end): ?array { + } /** * - * + *获取列表中指定索引的值 * @example - * @return + * @param string $key 键名 + * @param int $index 索引值 + * @return string | bool */ - public function lGet() + public function lGet(string $key, int $index): ?string { + } /** * - * + *获取列表指定范围的值 * @example - * @return + * @param string $key 键名 + * @param int $start 索引开始值 + * @param int $end 索引结束值 + * @return array */ - public function lGetRange() + public function lGetRange(string $key, int $start, int $end): array { + } /** * - *Set the list at index with the new value. + *给列表指定位置设置新值 * @example *
      * $redis->rPush('key1', 'A');
@@ -835,17 +1087,19 @@ public function lGetRange()
      * $redis->lSet('key1', 0, 'X');
      * $redis->lGet('key1', 0);     // 'X'
      * 
- * @return is + * @param string $key 键名 + * @param int $index 索引值 + * @param string $value 新值 + * @return bool */ - public function lSet() + public function lSet(string $key, int $index, string $value): bool { + } /** * - *Insert value in the list before or after the pivot value. the parameter options - *specify the position of the insert (before or after). If the list didn't exists, - *or the pivot didn't exists, the value is not inserted. + *在列表中,在某个元素的前面或后面插入一个新值 * @example *
      * $redis->delete('key1');
@@ -859,60 +1113,75 @@ public function lSet()
      * $redis->lRange('key1', 0, -1);                       // array('A', 'B', 'X', 'C', 'Y')
      * $redis->lInsert('key1', Redis::AFTER, 'W', 'value'); // -1
      * 
+ * @param string $key 键名 + * @param string $position 位置(前面或后面,使用Redis::BEFORE | Redis::AFTER) + * @param string $element 元素 + * @param string $value 新值 * @return int */ - public function lInsert() + public function lInsert(string $key, string $position, string $element, string $value): int { + } /** * - *Adds a values to the set value stored at key. - *If this value is already in the set, FALSE is returned. + *给集合添加元素 * @example *
      * $redis->sAdd('k', 'v1');                // int(1)
      * $redis->sAdd('k', 'v1', 'v2', 'v3');    // int(2)
      * 
+ * @param string $key 键名 + * @param string $value 元素值 * @return int */ - public function sAdd() + public function sAdd(string $key, string $value): int { + } /** * - * + *给集合批量添加元素 * @example + * @param string $key 键名 + * @param array $value 元素值 * @return */ - public function sAddArray() + public function sAddArray(string $key, Array $value) { + } /** * - * + *返回集合的元素个数 * @example - * @return + * @param string $key 键名 + * @return int */ - public function sSize() + public function sSize(string $key): int { + } /** * - * + *删除集合元素 * @example - * @return + * @param string $key 键名 + * @param string|... $member 成员 + * @return int */ - public function sRemove() + public function sRemove(string $key, string $member): int { + } /** * - *Moves the specified member from the set at srcKey to the set at dstKey. + *将某个集合中的元素移动到另外一个集合中 * @example *
      * $redis->sAdd('key1' , 'set11');
@@ -923,15 +1192,19 @@ public function sRemove()
      * $redis->sMove('key1', 'key2', 'set13');  // 'key1' =>  {'set11', 'set12'}
      * // 'key2' =>  {'set21', 'set22', 'set13'}
      * 
- * @return If + * @param string $srcKey 原集合键名 + * @param string $dstKey 目标集合键名 + * @param string $member 成员 + * @return bool */ - public function sMove() + public function sMove(string $srcKey, string $dstKey, string $member): bool { + } /** * - *Removes and returns a random element from the set value at Key. + *随机删除元素的某个或某些成员,并返回这个删除的成员. * @example *
      * $redis->sAdd('key1' , 'set1');
@@ -940,15 +1213,18 @@ public function sMove()
      * $redis->sPop('key1');            // 'set1', 'key1' => {'set3', 'set2'}
      * $redis->sPop('key1');            // 'set3', 'key1' => {'set2'}
      * 
- * @return bool + * @param string $key 键名 + * @param int $count 删除个数 + * @return string | bool */ - public function sPop() + public function sPop(string $key, int $count): ?string { + } /** * - *Returns a random element(s) from the set value at Key, without removing it. + *随机返回一个集合的元素(不会删除它) * @example *
      * $redis->sAdd('key1' , 'one');
@@ -962,25 +1238,30 @@ public function sPop()
      * //   [1]=> string(2) "three"
      * // }
      * 
- * @return bool + * @param string $key 键名 + * @return string | bool */ - public function sRandMember() + public function sRandMember(string $key): ?string { + } /** * - * + *是否包含某个成员 * @example - * @return + * @param string $key 键名 + * @param string $member 成员值 + * @return bool */ - public function sContains() + public function sContains(string $key, string $member): bool { + } /** * - *Returns the contents of a set. + *返回集合的所有成员 * @example *
      * $redis->delete('s');
@@ -999,17 +1280,17 @@ public function sContains()
      * //}
      * // The order is random and corresponds to redis' own internal representation of the set structure.
      * 
+ * @param string $key 键名 * @return array */ - public function sMembers() + public function sMembers(string $key): array { + } /** * - *Returns the members of a set resulting from the intersection of all the sets - *held at the specified keys. If just a single key is specified, then this command - *produces the members of this set. If one of the keys is missing, FALSE is returned. + *获取两个集合的交集 * @example *
      * $redis->sAdd('key1', 'val1');
@@ -1028,15 +1309,18 @@ public function sMembers()
      * //  string(4) "val3"
      * //}
      * 
- * @return If + * @param string $key1 键名1 + * @param string $key2 键名2 + * @return array | bool */ - public function sInter() + public function sInter(string $key1, string $key2): ?array { + } /** * - *Performs a sInter command and stores the result in a new set. + *获取多个集合的交集,并将结果存入到另外一个集合中 * @example *
      * $redis->sAdd('key1', 'val1');
@@ -1058,15 +1342,20 @@ public function sInter()
      * //  string(4) "val3"
      * //}
      * 
- * @return int: + * @param string $dstKey 目标键,存放结果的键 + * @param string $key1 键名1 + * @param string $key2 键名2 + * @param string|... $keyN 键名n + * @return int */ - public function sInterStore() + public function sInterStore(string $dstKey, string $key1, string $key2, string $keyN): int { + } /** * - *Performs the union between N sets and returns it. + *获取集合的并集 * @example *
      * $redis->delete('s0', 's1', 's2');
@@ -1088,15 +1377,18 @@ public function sInterStore()
      * //  string(1) "2"
      * //}
      * 
+ * @param string $key1 键名1 + * @param string|... $key2 键名2 * @return array */ - public function sUnion() + public function sUnion(string $key1, string $key2): array { + } /** * - *Performs the same action as sUnion, but stores the result in the first key + *获取多个集合的并集,并将结果存入到另外一个集合中 * @example *
      * $redis->delete('s0', 's1', 's2');
@@ -1120,15 +1412,20 @@ public function sUnion()
      * //  string(1) "2"
      * //}
      * 
+ * @param string $dstKey 目标键,存放结果的键 + * @param string $key1 键名1 + * @param string $key2 键名2 + * @param string|... $keyN 键名n * @return int */ - public function sUnionStore() + public function sUnionStore(string $dstKey, string $key1, string $key2, string $keyN): int { + } /** * - *Performs the difference between N sets and returns it. + *获取多个集合的差集 * @example *
      * $redis->delete('s0', 's1', 's2');
@@ -1146,15 +1443,18 @@ public function sUnionStore()
      * //  string(1) "2"
      * //}
      * 
+ * @param string $key1 键名1 + * @param string|... $key2 键名2 * @return array */ - public function sDiff() + public function sDiff(string $key1, string $key2): array { + } /** * - *Performs the same action as sDiff, but stores the result in the first key + *获取多个集合的差集,并将结果存入到一个新的集合中 * @example *
      * $redis->delete('s0', 's1', 's2');
@@ -1174,130 +1474,151 @@ public function sDiff()
      * //  string(1) "2"
      * //}
      * 
- * @return int: + * @param string $dstKey 目标键,存放结果的键 + * @param string $key1 键名1 + * @param string $key2 键名2 + * @param string|... $keyN 键名n + * @return int */ - public function sDiffStore() + public function sDiffStore(string $dstKey, string $key1, string $key2, string $keyN): int { + } /** * - * + *设置键的有效期 * @example - * @return + * @param string $key 键名 + * @param int $ttl 有效期(秒数) + * @return bool */ - public function setTimeout() + public function setTimeout(string $key, int $ttl): bool { + } /** * - *Performs a synchronous save. + *将数据同步到硬盘上 * @example $redis->save(); - * @return If + * @return bool */ - public function save() + public function save(): bool { + } /** * - * + *将数据存入到硬盘上(异步操作) * @example * @return */ public function bgSave() { + } /** * - *Returns the timestamp of the last disk save. + *获取上次数据同步到硬盘的时间 * @example $redis->lastSave(); - * @return int: + * @return int */ - public function lastSave() + public function lastSave(): int { + } /** * - *Removes all entries from the current database. + *删除当前数据库的所有键 * @example $redis->flushDB(); - * @return bool: + * @return bool */ - public function flushDB() + public function flushDB(): bool { + } /** * - *Removes all entries from all databases. + *删除当前实例的所有键 * @example $redis->flushAll(); - * @return bool: + * @return bool */ - public function flushAll() + public function flushAll(): bool { + } /** * - *Returns the current database's size. + *获取当前数据库的键的个数 * @example *
      * $count = $redis->dbSize();
      * echo "Redis has $count keys\n";
      * 
- * @return int: + * @return int */ - public function dbSize() + public function dbSize(): int { + } /** * - *Authenticate the connection using a password. - *Warning: The password is sent in plain-text over the network. + *设置连接的认证密码 * @example $redis->auth('foobared'); - * @return bool: + * @param string $password 认证密码 + * @return bool */ - public function auth() + public function auth(string $password): bool { + } /** * - *Returns the time to live left for a given key, in seconds. If the key doesn't exist, FALSE is returned. + *返回指定键的有效时间(秒) * @example $redis->ttl('key'); - * @return int, + * @param string $key 键名 + * @return int */ - public function ttl() + public function ttl(string $key): int { + } /** * - *Returns a time to live left for a given key, in milliseconds. + *返回指定键的有效时间(毫秒) * @example $redis->pttl('key'); + * @param string $key 键名 * @return int */ - public function pttl() + public function pttl(string $key): int { + } /** * - *Remove the expiration timer from a key. + *移除指定键的有效期,让它永久有效 * @example $redis->persist('key'); - * @return bool: + * @param string $key 键名 + * @return bool */ - public function persist() + public function persist(string $key): bool { + } /** * - *Returns an associative array of strings and integers + *获取Redis服务器的信息和统计数据 * @example *
      * $redis->info();
@@ -1305,15 +1626,16 @@ public function persist()
      * $redis->info("COMMANDSTATS"); //Information on the commands that have been run (>=2.6 only)
      * $redis->info("CPU"); // just CPU information from Redis INFO
      * 
- * @return + * @return array */ - public function info() + public function info(): array { + } /** * - *Switches to a given database. + *切换数据库 * @example *
      * $redis->select(0);       // switch to DB 0
@@ -1322,15 +1644,17 @@ public function info()
      * $redis->select(1);       // switch to DB 1
      * $redis->get('x');        // will return 42
      * 
+ * @param int $dbIndex 数据库编号 * @return bool */ - public function select() + public function select(int $dbIndex): bool { + } /** * - *Moves a key to a different database. + *将某个键移动到其他数据库中 * @example *
      * $redis->select(0);       // switch to DB 0
@@ -1339,83 +1663,93 @@ public function select()
      * $redis->select(1);       // switch to DB 1
      * $redis->get('x');        // will return 42
      * 
- * @return bool: + * @param string $key 键名 + * @param int $dbIndex 数据库编号 + * @return bool */ - public function move() + public function move(string $key, int $dbIndex): bool { + } /** * - *Starts the background rewrite of AOF (Append-Only File) + *开启后台写AOF日志操作 * @example $redis->bgrewriteaof(); - * @return bool: + * @return bool */ - public function bgrewriteaof() + public function bgrewriteaof(): bool { + } /** * - *Changes the slave status - *Either host and port, or no parameter to stop being a slave. + *修改从服务状态(参数为空时,表示停止当前从属关系) * @example *
      * $redis->slaveof('10.0.1.7', 6379);
      * // ...
      * $redis->slaveof();
      * 
- * @return bool: + * @param string $host 服务器 + * @param int $port 端口号 + * @return bool */ - public function slaveof() + public function slaveof(string $host, int $port): bool { + } /** * - *Describes the object pointed to by a key. - *The information to retrieve (string) and the key (string). - *Info can be one of the following: - *- "encoding" - *- "refcount" - *- "idletime" + *获取某个键的对象信息 * @example *
      * $redis->object("encoding", "l"); // → ziplist
      * $redis->object("refcount", "l"); // → 1
      * $redis->object("idletime", "l"); // → 400 (in seconds, with a precision of 10 seconds).
      * 
+ * @param string $info 获取的信息指标名称(有 encoding、refcount 、idletime 3种可选择) + * @param string $key 键名 * @return string */ - public function object() + public function object(string $info, string $key): string { + } /** * - * + *多个键的位操作,并将结果存入到指定的键中 * @example - * @return + * @param string $operation 操作(有 AND, OR, NOT, XOR 4种可选择) + * @param string $dstKey 目标键 + * @param string $key1 键名1 + * @param string $key2 键名2 + * @param string|... $keyN 键名N + * @return int */ - public function bitop() + public function bitop(string $operation, string $dstKey, string $key1, string $key2, string $keyN): int { + } /** * - * + *统计字符串的位数 * @example - * @return + * @param string $key 键名 + * @return int */ - public function bitcount() + public function bitcount(string $key): int { + } /** * - *Return the position of the first bit set to 1 or 0 in a string. The position is returned, thinking of the - *string as an array of bits from left to right, where the first byte's most significant bit is at position 0, - *the second byte's most significant bit is at position 8, and so forth. + *获取指定位置的位值 * @example *
      * $redis->set('key', '\xff\xff');
@@ -1426,16 +1760,20 @@ public function bitcount()
      * $redis->bitpos('key', 0, 1); // int(16)
      * $redis->bitpos('key', 0, 1, 5); // int(-1)
      * 
- * @return function + * @param string $key 键名 + * @param int $bit 位值 + * @param int $start 开始位置 + * @param int $end 结束位置 + * @return callable */ - public function bitpos() + public function bitpos(string $key, int $bit, int $start, int $end): callable { + } /** * - *Sets multiple key-value pairs in one atomic command. - *MSETNX only returns TRUE if all the keys were set (see SETNX). + *批量设置值 * @example *
      * $redis->mset(array('key0' => 'value0', 'key1' => 'value1'));
@@ -1445,26 +1783,37 @@ public function bitpos()
      * // string(6) "value0"
      * // string(6) "value1"
      * 
+ * @param array $values 要设置的键值对 * @return bool */ - public function mset() + public function mset(Array $values): bool { + } /** * - * + *批量设置值(当不存在时设置) * @example - * @return int + *
+     * $redis->mset(array('key0' => 'value0', 'key1' => 'value1'));
+     * var_dump($redis->get('key0'));
+     * var_dump($redis->get('key1'));
+     * // Output:
+     * // string(6) "value0"
+     * // string(6) "value1"
+     * 
+ * @param array $values 要设置的键值对 + * @return bool */ - public function msetnx() + public function msetnx(Array $values): bool { + } /** * - *Pops a value from the tail of a list, and pushes it to the front of another list. - *Also return this value. + *从一个队列的队尾删除一个元素,并将该元素插入到另一个队列的头部 * @example *
      * $redis->delete('x', 'y');
@@ -1492,25 +1841,31 @@ public function msetnx()
      * //  string(3) "123"
      * //}
      * 
+ * @param string $srcKey 要删除元素的队列键名 + * @param string $dstKey 要插入元素的队列的键名 * @return string */ - public function rpoplpush() + public function rpoplpush(string $srcKey, string $dstKey): string { + } /** * - *A blocking version of rpoplpush, with an integral timeout in the third parameter. + *阻塞执行rpoplpush * @example + * @param string $srcKey 要删除元素的队列键名 + * @param string $dstKey 要插入元素的队列的键名 * @return string */ - public function brpoplpush() + public function brpoplpush(string $srcKey, string $dstKey): string { + } /** * - *Adds the specified member with a given score to the sorted set stored at key. + *向有序集合插入元素 * @example *
      * 
@@ -1524,30 +1879,32 @@ public function brpoplpush()
      * // }
      * 
*
+ * @param string $key 集合键名 + * @param double $score 排序值 + * @param string $value 元素值 * @return int */ - public function zAdd() + public function zAdd(string $key, double $score, string $value): int { + } /** * - * + *删除有序集合中的某个成员 * @example + * @param string $key 集合键名 + * @param string $member 成员值 * @return int */ - public function zDelete() + public function zDelete(string $key, string $member): int { + } /** * - *Returns a range of elements from the ordered set stored at the specified key, - *with values in the range [start, end]. start and stop are interpreted as zero-based indices: - *0 the first element, - *1 the second ... - *-1 the last element, - *-2 the penultimate ... + *获取有序集合中指定范围的成员 * @example *
      * $redis->zAdd('key1', 0, 'val0');
@@ -1557,20 +1914,20 @@ public function zDelete()
      * // with scores
      * $redis->zRange('key1', 0, -1, true); // array('val0' => 0, 'val2' => 2, 'val10' => 10)
      * 
+ * @param string $key 集合键名 + * @param int $start 索引开始值 + * @param int $end 索引结束值 + * @param bool $withScores 是否返回成员的排序值 * @return array */ - public function zRange() + public function zRange(string $key, int $start, int $end, bool $withScores): array { + } /** * - *Returns the elements of the sorted set stored at the specified key in the range [start, end] - *in reverse order. start and stop are interpretated as zero-based indices: - *0 the first element, - *1 the second ... - *-1 the last element, - *-2 the penultimate ... + *获取有序集合中指定范围的成员(倒序排列) * @example *
      * $redis->zAdd('key', 0, 'val0');
@@ -1580,17 +1937,20 @@ public function zRange()
      * // with scores
      * $redis->zRevRange('key', 0, -1, true); // array('val10' => 10, 'val2' => 2, 'val0' => 0)
      * 
+ * @param string $key 集合键名 + * @param int $start 索引开始值 + * @param int $end 索引结束值 + * @param bool $withScores 是否返回成员的排序值 * @return array */ - public function zRevRange() + public function zRevRange(string $key, int $start, int $end, bool $withScores): array { + } /** * - *Returns the elements of the sorted set stored at the specified key which have scores in the - *range [start,end]. Adding a parenthesis before start or end excludes it from the range. - *+inf and -inf are also valid limits. + *获取有序集合中指定范围的成员(按排序值排列) * @example *
      * $redis->zAdd('key', 0, 'val0');
@@ -1602,28 +1962,45 @@ public function zRevRange()
      * $redis->zRangeByScore('key', 0, 3, array('limit' => array(1, 1));                        // array('val2')
      * $redis->zRangeByScore('key', 0, 3, array('withscores' => TRUE, 'limit' => array(1, 1));  // array('val2' => 2)
      * 
+ * @param string $key 集合键名 + * @param int $start 索引开始值 + * @param int $end 索引结束值 + * @param array $options 附加选项(可以是:withscores => TRUE, and limit => array($offset, $count)) * @return array */ - public function zRangeByScore() + public function zRangeByScore(string $key, int $start, int $end, Array $options): array { + } /** * - * + *获取有序集合中指定范围的成员(按排序值倒序排列) * @example - * @return + *
+     * $redis->zAdd('key', 0, 'val0');
+     * $redis->zAdd('key', 2, 'val2');
+     * $redis->zAdd('key', 10, 'val10');
+     * $redis->zRangeByScore('key', 0, 3);                                          // array('val0', 'val2')
+     * $redis->zRangeByScore('key', 0, 3, array('withscores' => TRUE);              // array('val0' => 0, 'val2' => 2)
+     * $redis->zRangeByScore('key', 0, 3, array('limit' => array(1, 1));                        // array('val2' => 2)
+     * $redis->zRangeByScore('key', 0, 3, array('limit' => array(1, 1));                        // array('val2')
+     * $redis->zRangeByScore('key', 0, 3, array('withscores' => TRUE, 'limit' => array(1, 1));  // array('val2' => 2)
+     * 
+ * @param string $key 集合键名 + * @param int $start 索引开始值 + * @param int $end 索引结束值 + * @param array $options 附加选项(可以是:withscores => TRUE, and limit => array($offset, $count)) + * @return array */ - public function zRevRangeByScore() + public function zRevRangeByScore(string $key, int $start, int $end, Array $options): array { + } /** * - *Returns a lexigraphical range of members in a sorted set, assuming the members have the same score. The - *min and max values are required to start with '(' (exclusive), '[' (inclusive), or be exactly the values - *'-' (negative inf) or '+' (positive inf). The command must be called with either three *or* five - *arguments or will return FALSE. + *按字母字典的顺序返回成员 * @example *
      * foreach (array('a', 'b', 'c', 'd', 'e', 'f', 'g') as $char) {
@@ -1633,47 +2010,65 @@ public function zRevRangeByScore()
      * $redis->zRangeByLex('key', '-', '(c'); // array('a', 'b')
      * $redis->zRangeByLex('key', '-', '[c'); // array('b', 'c')
      * 
+ * @param string $key 集合键名 + * @param int $min 最小的字母 + * @param int $max 最大的字母 + * @param int $offset 索引开始值 + * @param int $limit 成员数 * @return array */ - public function zRangeByLex() + public function zRangeByLex(string $key, int $min, int $max, int $offset, int $limit): array { + } /** * - * + *按字母字典的顺序返回成员(倒序排序) * @example + * @param string $key 集合键名 + * @param int $min 最小的字母 + * @param int $max 最大的字母 + * @param int $offset 索引开始值 + * @param int $limit 成员数 * @return */ - public function zRevRangeByLex() + public function zRevRangeByLex(string $key, int $min, int $max, int $offset, int $limit) { + } /** * - * + *获取指定字母范围的成员数 * @example - * @return + * @param string $key 集合键名 + * @param int $min 最小的字母 + * @param int $max 最大的字母 + * @return int */ - public function zLexCount() + public function zLexCount(string $key, int $min, int $max): int { + } /** * - * + *删除指定字母范围的成员 * @example - * @return + * @param string $key 集合键名 + * @param int $min 最小的字母 + * @param int $max 最大的字母 + * @return int */ - public function zRemRangeByLex() + public function zRemRangeByLex(string $key, int $min, int $max): int { + } /** * - *Returns the number of elements of the sorted set stored at the specified key which have - *scores in the range [start,end]. Adding a parenthesis before start or end excludes it - *from the range. +inf and -inf are also valid limits. + *获取指定排序范围的成员数. * @example *
      * $redis->zAdd('key', 0, 'val0');
@@ -1681,35 +2076,54 @@ public function zRemRangeByLex()
      * $redis->zAdd('key', 10, 'val10');
      * $redis->zCount('key', 0, 3); // 2, corresponding to array('val0', 'val2')
      * 
+ * @param string $key 集合键名 + * @param double $start 开始排序值 + * @param double $end 结束排序值 * @return int */ - public function zCount() + public function zCount(string $key, double $start, double $end): int { + } /** * - * + *根据排序值范围来删除成员 * @example - * @return + * @param string $key 集合键名 + * @param double $start 开始排序值 + * @param double $end 结束排序值 + * @return int */ - public function zDeleteRangeByScore() + public function zDeleteRangeByScore(string $key, double $start, double $end): int { + } /** * - * + *根据排序范围删除成员 * @example - * @return + *
+     * $redis->zAdd('key', 1, 'one');
+     * $redis->zAdd('key', 2, 'two');
+     * $redis->zAdd('key', 3, 'three');
+     * $redis->zRemRangeByRank('key', 0, 1); // 2
+     * $redis->zRange('key', 0, -1, array('withscores' => TRUE)); // array('three' => 3)
+     * 
+ * @param string $key 集合键名 + * @param double $start 开始排序值 + * @param double $end 结束排序值 + * @return int */ - public function zDeleteRangeByRank() + public function zDeleteRangeByRank(string $key, double $start, double $end): int { + } /** * - *Returns the cardinality of an ordered set. + *获取有序集合的成员数 * @example *
      * $redis->zAdd('key', 0, 'val0');
@@ -1717,30 +2131,34 @@ public function zDeleteRangeByRank()
      * $redis->zAdd('key', 10, 'val10');
      * $redis->zCard('key');            // 3
      * 
+ * @param string $key 集合键名 * @return int */ - public function zCard() + public function zCard(string $key): int { + } /** * - *Returns the score of a given member in the specified sorted set. + *获取指定成员的排序值(分数) * @example *
      * $redis->zAdd('key', 2.5, 'val2');
      * $redis->zScore('key', 'val2'); // 2.5
      * 
- * @return + * @param string $key 集合键名 + * @param string $member 成员值 + * @return double */ - public function zScore() + public function zScore(string $key, string $member): double { + } /** * - *Returns the rank of a given member in the specified sorted set, starting at 0 for the item - *with the smallest score. zRevRank starts at 0 for the item with the largest score. + *获取成员的排序值 * @example *
      * $redis->delete('z');
@@ -1751,30 +2169,31 @@ public function zScore()
      * $redis->zRevRank('key', 'one');  // 1
      * $redis->zRevRank('key', 'two');  // 0
      * 
+ * @param string $key 集合键名 + * @param string $member 成员值 * @return int */ - public function zRank() + public function zRank(string $key, string $member): int { + } /** * - * + *获取成员的排位值(倒数) * @example + * @param string $key 集合键名 + * @param string $member 成员值 * @return int */ - public function zRevRank() + public function zRevRank(string $key, string $member): int { + } /** * - *Creates an intersection of sorted sets given in second argument. - *The result of the union will be stored in the sorted set defined by the first argument. - *The third optional argument defines weights to apply to the sorted sets in input. - *In this case, the weights will be multiplied by the score of each element in the sorted set - *before applying the aggregation. The forth argument defines the AGGREGATE option which - *specify how the results of the union are aggregated. + *将两个有序集合的交集存入到一个指定的键中 * @example *
      * $redis->delete('k1');
@@ -1795,20 +2214,20 @@ public function zRevRank()
      * $redis->zInter('ko3', array('k1', 'k2'), array(1, 5), 'min'); // 2, 'ko3' => array('val1', 'val3')
      * $redis->zInter('ko4', array('k1', 'k2'), array(1, 5), 'max'); // 2, 'ko4' => array('val3', 'val1')
      * 
+ * @param string $dstKey 目标集合键名 + * @param array $zsetKeys 集合键名 + * @param array $zsetKeysWeight 集合键对应的权重 + * @param string $aggregateFunction 合并使用的函数(SUM, MIN, 或 MAX) * @return int */ - public function zInter() + public function zInter(string $dstKey, Array $zsetKeys, Array $zsetKeysWeight, string $aggregateFunction): int { + } /** * - *Creates an union of sorted sets given in second argument. - *The result of the union will be stored in the sorted set defined by the first argument. - *The third optionnel argument defines weights to apply to the sorted sets in input. - *In this case, the weights will be multiplied by the score of each element in the sorted set - *before applying the aggregation. The forth argument defines the AGGREGATE option which - *specify how the results of the union are aggregated. + *将两个有序集合的并集存入到一个指定的键中 * @example *
      * $redis->delete('k1');
@@ -1826,15 +2245,20 @@ public function zInter()
      * $redis->zUnion('ko2', array('k1', 'k2'), array(1, 1)); // 4, 'ko2' => array('val0', 'val1', 'val2', 'val3')
      * $redis->zUnion('ko3', array('k1', 'k2'), array(5, 1)); // 4, 'ko3' => array('val0', 'val2', 'val3', 'val1')
      * 
+ * @param string $dstKey 目标集合键名 + * @param array $zsetKeys 集合键名 + * @param array $zsetKeysWeight 集合键对应的权重 + * @param string $aggregateFunction 合并使用的函数(SUM, MIN, 或 MAX) * @return int */ - public function zUnion() + public function zUnion(string $dstKey, Array $zsetKeys, Array $zsetKeysWeight, string $aggregateFunction): int { + } /** * - *Increments the score of a member from a sorted set by a given amount. + *给有序集合成员增加排序值 * @example *
      * $redis->delete('key');
@@ -1842,15 +2266,19 @@ public function zUnion()
      * // before the increment and now has the value 2.5
      * $redis->zIncrBy('key', 1, 'member1');    // 3.5
      * 
+ * @param string $key 目标集合键名 + * @param double $step 增加的步长 + * @param string $member 成员 * @return float */ - public function zIncrBy() + public function zIncrBy(string $key, double $step, string $member): float { + } /** * - *Sets an expiration date (a timestamp) on an item. + *为某个键设置有效期为某个时间点 * @example *
      * $redis->set('x', '42');
@@ -1859,46 +2287,64 @@ public function zIncrBy()
      * sleep(5);                        // wait 5 seconds
      * $redis->get('x');                // will return `FALSE`, as 'x' has expired.
      * 
- * @return bool: + * @param string $key 键名 + * @param int $expireTime 到期时间 + * @return bool */ - public function expireAt() + public function expireAt(string $key, int $expireTime): bool { + } /** * - * + *设置键的有效期(毫秒为单位) * @example - * @return + * @param string $key 键名 + * @param int $ttl 有效期(毫秒数) + * @return bool */ - public function pexpire() + public function pexpire(string $key, int $ttl): bool { + } /** * - * + *为某个键设置有效期为某个时间点(精确到毫秒) * @example - * @return + *
+     * $redis->set('x', '42');
+     * $now = time(NULL);               // current timestamp
+     * $redis->expireAt('x', $now + 3); // x will disappear in 3 seconds.
+     * sleep(5);                        // wait 5 seconds
+     * $redis->get('x');                // will return `FALSE`, as 'x' has expired.
+     * 
+ * @param string $key 键名 + * @param int $expireTime 到期时间 + * @return bool */ - public function pexpireAt() + public function pexpireAt(string $key, int $expireTime): bool { + } /** * - *Gets a value from the hash stored at key. - *If the hash table doesn't exist, or the key doesn't exist, FALSE is returned. + *获取字典的某个字段的值 * @example + * @param string $key 键名 + * @param string $field 字段名 * @return string */ - public function hGet() + public function hGet(string $key, string $field): string { + } /** * - *Adds a value to the hash stored at key. If this value is already in the hash, FALSE is returned. + *为字典的字段设置值 * @example *
      * $redis->delete('h')
@@ -1907,15 +2353,19 @@ public function hGet()
      * $redis->hSet('h', 'key1', 'plop');   // 0, value was replaced.
      * $redis->hGet('h', 'key1');           // returns "plop"
      * 
- * @return 0 + * @param string $key 键名 + * @param string $field 字段名 + * @param string $value 字段值 + * @return int */ - public function hSet() + public function hSet(string $key, string $field, string $value): int { + } /** * - *Adds a value to the hash stored at key only if this field isn't already in the hash. + *当字典的字段不存在时,为其设置值 * @example *
      * $redis->delete('h')
@@ -1923,16 +2373,19 @@ public function hSet()
      * $redis->hSetNx('h', 'key1', 'world'); // FALSE, 'key1' => 'hello' in the hash at "h". No change since the field
      * wasn't replaced.
      * 
+ * @param string $key 键名 + * @param string $field 字段名 + * @param string $value 字段值 * @return bool */ - public function hSetNx() + public function hSetNx(string $key, string $field, string $value): bool { + } /** * - *Removes a values from the hash stored at key. - *If the hash table doesn't exist, or the key doesn't exist, FALSE is returned. + *删除字典的某个或某些字段 * @example *
      * $redis->hMSet('h',
@@ -1951,15 +2404,18 @@ public function hSetNx()
      * //    ["f4"]=> string(2) "v4"
      * //  }
      * 
+ * @param string $key 键名 + * @param string|array $fields 字段名 * @return int */ - public function hDel() + public function hDel(string $key, string $fields): int { + } /** * - *Returns the length of a hash, in number of items + *获取字典的字段个数 * @example *
      * $redis->delete('h')
@@ -1967,15 +2423,17 @@ public function hDel()
      * $redis->hSet('h', 'key2', 'plop');
      * $redis->hLen('h'); // returns 2
      * 
+ * @param string $key 键名 * @return int */ - public function hLen() + public function hLen(string $key): int { + } /** * - *Returns the keys in a hash, as an array of strings. + *获取字典的字段名称列表. * @example *
      * $redis->delete('h');
@@ -1997,15 +2455,17 @@ public function hLen()
      * // }
      * // The order is random and corresponds to redis' own internal representation of the set structure.
      * 
+ * @param string $key 键名 * @return array */ - public function hKeys() + public function hKeys(string $key): array { + } /** * - *Returns the values in a hash, as an array of strings. + *获取字典的字段值列表 * @example *
      * $redis->delete('h');
@@ -2027,15 +2487,17 @@ public function hKeys()
      * // }
      * // The order is random and corresponds to redis' own internal representation of the set structure.
      * 
+ * @param string $key 键名 * @return array */ - public function hVals() + public function hVals(string $key): array { + } /** * - *Returns the whole hash, as an array of strings indexed by strings. + *获取字典所有字段键值对 * @example *
      * $redis->delete('h');
@@ -2057,45 +2519,54 @@ public function hVals()
      * // }
      * // The order is random and corresponds to redis' own internal representation of the set structure.
      * 
+ * @param string $key 键名 * @return array */ - public function hGetAll() + public function hGetAll(string $key): array { + } /** * - *Verify if the specified member exists in a key. + *判断字典的某个字段是否存在. * @example *
      * $redis->hSet('h', 'a', 'x');
      * $redis->hExists('h', 'a');               //  TRUE
      * $redis->hExists('h', 'NonExistingKey');  // FALSE
      * 
- * @return bool: + * @param string $key 键名 + * @param string $field 字段名 + * @return bool */ - public function hExists() + public function hExists(string $key, string $field): bool { + } /** * - *Increments the value of a member from a hash by a given amount. + *为指定字段增加指定的值. * @example *
      * $redis->delete('h');
      * $redis->hIncrBy('h', 'x', 2); // returns 2: h[x] = 2 now.
      * $redis->hIncrBy('h', 'x', 1); // h[x] ← 2 + 1. Returns 3
      * 
+ * @param string $key 键名 + * @param string $field 字段名 + * @param int $step 自增步长 * @return int */ - public function hIncrBy() + public function hIncrBy(string $key, string $field, int $step): int { + } /** * - *Increment the float value of a hash field by the given amount + *为指定字段增加指定的值 * @example *
      * $redis = new Redis();
@@ -2112,41 +2583,50 @@ public function hIncrBy()
      * string(1) "3"
      * }
      * 
+ * @param string $key 键名 + * @param string $field 字段名 + * @param double $step 自增步长 * @return */ - public function hIncrByFloat() + public function hIncrByFloat(string $key, string $field, double $step) { + } /** * - *Fills in a whole hash. Non-string values are converted to string, using the standard (string) cast. - *NULL values are stored as empty strings + *批量设置字典字段的值 * @example *
      * $redis->delete('user:1');
      * $redis->hMset('user:1', array('name' => 'Joe', 'salary' => 2000));
      * $redis->hIncrBy('user:1', 'salary', 100); // Joe earns 100 more now.
      * 
- * @return + * @param string $key 键名 + * @param array $fields 字段键值对 + * @return bool */ - public function hMset() + public function hMset(string $key, Array $fields): bool { + } /** * - * + *批量获取字典的字段值 * @example - * @return + * @param string $key 键名 + * @param array $fields 字段名列表 + * @return array */ - public function hMget() + public function hMget(string $key, Array $fields): array { + } /** * - *Enter and exit transactional mode. + *开始一个事务. * @example *
      * $ret = $redis->multi()
@@ -2161,84 +2641,94 @@ public function hMget()
      * //    2 => TRUE,
      * //    3 => 'val2');
      * 
- * @return Once + * @return */ public function multi() { + } /** * - * + *取消事务 * @example * @return */ public function discard() { + } /** * - * + *执行事务 * @example * @return */ public function exec() { + } /** * - * + *开启一个管道 * @example * @return */ public function pipeline() { + } /** * - *Watches a key for modifications by another client. If the key is modified between WATCH and EXEC, - *the MULTI/EXEC transaction will fail (return FALSE). unwatch cancels all the watching of all keys by this client. + *观察某个键在其他客户端的变化情况. * @example *
      * $redis->watch('x');
-     * // long code here during the execution of which other clients could well modify `x`
+     * // int code here during the execution of which other clients could well modify `x`
      * $ret = $redis->multi()
      * ->incr('x')
      * ->exec();
      * // $ret = FALSE if x has been modified between the call to WATCH and the call to EXEC.
      * 
+ * @param string|array $keys 键名 * @return */ - public function watch() + public function watch(string $keys) { + } /** * - * + *取消观察某个键在其他客户端的变化情况 * @example + * @param string|array $keys 键名 * @return */ - public function unwatch() + public function unwatch(string $keys) { + } /** * - *Publish messages to channels. Warning: this function will probably change in the future. + *将消息发布到消息通道(队列). * @example $redis->publish('chan-1', 'hello, world!'); // send message. + * @param string $channel 消息频道 + * @param string $message 消息 * @return int */ - public function publish() + public function publish(string $channel, string $message): int { + } /** * - *Subscribe to channels. Warning: this function will probably change in the future. + *订阅消息 * @example *
      * function f($redis, $chan, $msg) {
@@ -2256,15 +2746,19 @@ public function publish()
      * }
      * $redis->subscribe(array('chan-1', 'chan-2', 'chan-3'), 'f'); // subscribe to 3 chans
      * 
+ * @param array $channels 订阅的消息频道 + * @param string|array $callback 回调函数名称 + * @param mixed $value 返回值 * @return mixed */ - public function subscribe() + public function subscribe(Array $channels, string $callback, $value) { + } /** * - *Subscribe to channels by pattern + *通过匹配模式来订阅这些匹配的消息频道 * @example *
      * function psubscribe($redis, $pattern, $chan, $msg) {
@@ -2273,35 +2767,43 @@ public function subscribe()
      * echo "Payload: $msg\n";
      * }
      * 
+ * @param array $patterns 匹配模式 + * @param string|array $callback 回调函数名称 + * @param mixed $value 返回值 * @return */ - public function psubscribe() + public function psubscribe(Array $patterns, string $callback, $value) { + } /** * - * + *取消订阅 * @example + * @param array $channels 订阅的消息频道 * @return */ - public function unsubscribe() + public function unsubscribe(Array $channels) { + } /** * - * + *通过匹配模式来取消订阅这些匹配的消息频道 * @example + * @param array $patterns 匹配模式 * @return */ - public function punsubscribe() + public function punsubscribe(Array $patterns) { + } /** * - *Return the current Redis server time. + *返回当前redis服务器时间. * @example *
      * var_dump( $redis->time() );
@@ -2310,45 +2812,27 @@ public function punsubscribe()
      * //   [1] => string(6) "253002"
      * // }
      * 
- * @return unix - */ - public function time() - { - } - - /** - * - * - * @example - * @return - */ - public function role() - { - } - - /** - * - * - * @example - * @return + * @return int */ - public function eval() + public function time(): int { + } /** * - * + *返回当前连接的服务器的角色,如master、alone、slave、sentinel * @example - * @return + * @return string */ - public function evalsha() + public function role(): string { + } /** * - *Execute the Redis SCRIPT command to perform various operations on the scripting subsystem. + *在脚本子系统上执行redis命令 * @example *
      * $redis->script('load', $script);
@@ -2360,68 +2844,85 @@ public function evalsha()
      * SCRIPT FLUSH should always return TRUE
      * SCRIPT KILL will return true if a script was able to be killed and false if not
      * SCRIPT EXISTS will return an array with TRUE or FALSE for each passed script
+     * @param string $command redis命令
+     * @param string|... $script 脚本
      * @return 
      */
-    public function script()
+    public function script(string $command, string $script)
     {
+    
     }
 
     /**
      * 
-     *
+     *调试命令(不建议使用)
      * @example 
      * @return 
      */
     public function debug()
     {
+    
     }
 
     /**
      * 
-     *Dump a key out of a redis database, the value of which can later be passed into redis using the RESTORE command.
-     *The data that comes out of DUMP is a binary representation of the key as Redis stores it.
+     *将某个键导出为一个二进制数据.
      * @example 
      * 
      * $redis->set('foo', 'bar');
      * $val = $redis->dump('foo'); // $val will be the Redis encoded key value
      * 
+ * @param string $key 键名 * @return string */ - public function dump() + public function dump(string $key): string { + } /** * - *Restore a key from the result of a DUMP operation. + *将dump导出的二进制数据恢复到可读的字符串. * @example *
      * $redis->set('foo', 'bar');
      * $val = $redis->dump('foo');
      * $redis->restore('bar', 0, $val); // The key 'bar', will now be equal to the key 'foo'
      * 
+ * @param string $key 键名 + * @param int $ttl 有效期 + * @param string $value dump导出的二进制数据 * @return */ - public function restore() + public function restore(string $key, int $ttl, string $value) { + } /** * - *Migrates a key to a different Redis instance. + *将某个键迁移到其他的Redis实例中 * @example *
      * $redis->migrate('backup', 6379, 'foo', 0, 3600);
      * 
+ * @param string $host 目标主机 + * @param int $port 目标主机端口 + * @param string|array $keys 迁移的键 + * @param int $database 目标数据库 + * @param int $timeout 超时时间 + * @param bool $copy 是否复制 + * @param bool $replace 是否替换 * @return */ - public function migrate() + public function migrate(string $host, int $port, string $keys, int $database, int $timeout, bool $copy, bool $replace) { + } /** * - *The last error message (if any) + *获取上次错误信息 * @example *
      * $redis->eval('this-is-not-lua');
@@ -2430,13 +2931,14 @@ public function migrate()
      * 
* @return string */ - public function getLastError() + public function getLastError(): string { + } /** * - *Clear the last error message + *清除上次错误信息 * @example *
      * $redis->set('x', 'a');
@@ -2449,30 +2951,30 @@ public function getLastError()
      * 
* @return bool */ - public function clearLastError() + public function clearLastError(): bool { + } /** * - *A utility method to prefix the value with the prefix setting for phpredis. + *设置键前缀 * @example *
      * $redis->setOption(Redis::OPT_PREFIX, 'my-prefix:');
      * $redis->_prefix('my-value'); // Will return 'my-prefix:my-value'
      * 
+ * @param string $prefix 前缀 * @return string */ - public function _prefix() + public function _prefix(string $prefix): string { + } /** * - *A utility method to serialize values manually. This method allows you to serialize a value with whatever - *serializer is configured, manually. This can be useful for serialization/unserialization of data going in - *and out of EVAL commands as phpredis can't automatically do this itself. Note that if no serializer is - *set, phpredis will change Array values to 'Array', and Objects to 'Object'. + *用于手动序列化. * @example *
      * $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_NONE);
@@ -2482,52 +2984,61 @@ public function _prefix()
      * $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);
      * $redis->_serialize("foo"); // Returns 's:3:"foo";'
      * 
+ * @param string $value 被序列化的值 * @return */ - public function _serialize() + public function _serialize(string $value) { + } /** * - *A utility method to unserialize data with whatever serializer is set up. If there is no serializer set, the - *value will be returned unchanged. If there is a serializer set up, and the data passed in is malformed, an - *exception will be thrown. This can be useful if phpredis is serializing values, and you return something from - *redis in a LUA script that is serialized. + *反序列化方法. * @example *
      * $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);
      * $redis->_unserialize('a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}'); // Will return Array(1,2,3)
      * 
+ * @param string $value 被反序列化的值 * @return */ - public function _unserialize() + public function _unserialize(string $value) { + } /** * - * + *获取客户端相关参数或进行相关操作 * @example + * @param string $command 命令(CLIENT LIST +CLIENT GETNAME +CLIENT SETNAME [name] +CLIENT KILL [ip:port] +) + * @param string $args 参数 * @return */ - public function client() + public function client(string $command, string $args) { + } /** * - * + *获取所有命令列表 * @example - * @return + * @return array */ - public function command() + public function command(): array { + } /** * - *Scan the keyspace for keys. + *扫描键空间. * @example *
      * $iterator = null;
@@ -2537,102 +3048,116 @@ public function command()
      * }
      * }
      * 
- * @param mixed $i_iterator - * @param mixed $str_pattern - * @param mixed $i_count + * @param int|NULL $i_iterator 迭代器 + * @param string $str_pattern 匹配的模式 + * @param int $i_count 每次迭代的长度 * @return array */ - public function scan($i_iterator, $str_pattern, $i_count) + public function scan(int $i_iterator, string $str_pattern, int $i_count): array { + } /** * - * + *扫描hash的键 * @example - * @param mixed $str_key - * @param mixed $i_iterator - * @param mixed $str_pattern - * @param mixed $i_count + * @param string $str_key 键值 + * @param int|NULL $i_iterator 迭代器 + * @param string $str_pattern 匹配的模式 + * @param int $i_count 每次迭代的长度 * @return */ - public function hscan($str_key, $i_iterator, $str_pattern, $i_count) + public function hscan(string $str_key, int $i_iterator, string $str_pattern, int $i_count) { + } /** * - * + *扫描有序集合的键 * @example - * @param mixed $str_key - * @param mixed $i_iterator - * @param mixed $str_pattern - * @param mixed $i_count + * @param string $str_key 键值 + * @param int|NULL $i_iterator 迭代器 + * @param string $str_pattern 匹配的模式 + * @param int $i_count 每次迭代的长度 * @return */ - public function zscan($str_key, $i_iterator, $str_pattern, $i_count) + public function zscan(string $str_key, int $i_iterator, string $str_pattern, int $i_count) { + } /** * - * + *扫描集合的键 * @example - * @param mixed $str_key - * @param mixed $i_iterator - * @param mixed $str_pattern - * @param mixed $i_count + * @param string $str_key 键值 + * @param int|NULL $i_iterator 迭代器 + * @param string $str_pattern 匹配的模式 + * @param int $i_count 每次迭代的长度 * @return */ - public function sscan($str_key, $i_iterator, $str_pattern, $i_count) + public function sscan(string $str_key, int $i_iterator, string $str_pattern, int $i_count) { + } /** * - * + *将所有元素参数添加到 HyperLogLog 数据结构中 * @example + * @param string $key 键名 + * @param string|array|... $element 元素 * @return */ - public function pfadd() + public function pfadd(string $key, string $element) { + } /** * - * + *返回给定 HyperLogLog 的基数估算值 * @example + * @param string|array $keys 键名 * @return */ - public function pfcount() + public function pfcount(string $keys) { + } /** * - * + *将多个 HyperLogLog 合并为一个 HyperLogLog ,合并后的 HyperLogLog 的基数估算值是通过对所有 给定 HyperLogLog 进行并集计算得出的 * @example + * @param string|array $dstKey 目标键名 + * @param string|array $sourceKeys 源键名 * @return */ - public function pfmerge() + public function pfmerge(string $dstKey, string $sourceKeys) { + } /** * - *Get client option + *获取客户端选项 * @example * // return Redis::SERIALIZER_NONE, Redis::SERIALIZER_PHP, or Redis::SERIALIZER_IGBINARY. * $redis->getOption(Redis::OPT_SERIALIZER); + * @param string $optionName 选项名 * @return int */ - public function getOption() + public function getOption(string $optionName): int { + } /** * - *Set client option. + *设置客户端选项. * @example *
      * $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_NONE);        // don't serialize data
@@ -2640,150 +3165,174 @@ public function getOption()
      * $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_IGBINARY);    // use igBinary serialize/unserialize
      * $redis->setOption(Redis::OPT_PREFIX, 'myAppName:');                      // use custom prefix on all keys
      * 
- * @return bool: + * @param string $optionName 选项名 + * @param string $optionValue 选项值 + * @return bool */ - public function setOption() + public function setOption(string $optionName, string $optionValue): bool { + } /** * - *Get or Set the redis config keys. + *获取或设置配置项. * @example *
      * $redis->config("GET", "*max-*-entries*");
      * $redis->config("SET", "dir", "/var/run/redis/dumps/");
      * 
+ * @param string $operation 操作(SET或GET) + * @param string $key 配置项或配置项匹配模式 + * @param string $value 配置值 * @return array */ - public function config() + public function config(string $operation, string $key, string $value): array { + } /** * - * + *获取慢操作日志 * @example + * @param string $command 执行的命令 + * @param int $length 获取条目数 * @return */ - public function slowlog() + public function slowlog(string $command, int $length) { + } /** * - * + *在redis服务器上执行命令 * @example + * @param string $command 执行的命令 + * @param string|array $args 参数 * @return */ - public function rawcommand() + public function rawcommand(string $command, string $args) { + } /** * - * + *获取当前连接HOST * @example * @return */ public function getHost() { + } /** * - * + *获取当前连接的端口 * @example * @return */ public function getPort() { + } /** * - * + *获取数据库的数量 * @example * @return */ public function getDBNum() { + } /** * - * + *获取连接超时时间 * @example * @return */ public function getTimeout() { + } /** * - * + *获取读操作超时暗 * @example * @return */ public function getReadTimeout() { + } /** * - * + *获取当前正在使用的持久化操作的ID * @example * @return */ public function getPersistentID() { + } /** * - * + *获取验证的字符串 * @example - * @return + * @return string */ - public function getAuth() + public function getAuth(): string { + } /** * - *A method to determine if a phpredis object thinks it's connected to a server + *是否连接成功 * @example * @return bool */ - public function isConnected() + public function isConnected(): bool { + } /** * - *Detect whether we're in ATOMIC/MULTI/PIPELINE mode. + *获取运行模式,如 ATOMIC/MULTI/PIPELINE * @example $redis->getMode(); * @return int */ - public function getMode() + public function getMode(): int { + } /** * - *Blocks the current client until all the previous write commands are successfully transferred and - *acknowledged by at least the specified number of slaves. + *该命令将阻止当前客户端,直到所有先前的写入命令成功传输并至少由指定数量的从节点进行确认 * @example $redis->wait(2, 1000); + * @param int $count 从节点数量 + * @param int $timeout 超时时间 * @return context */ - public function wait() + public function wait(int $count, int $timeout): context { + } /** * - *A command allowing you to get information on the Redis pub/sub system. + *查看订阅与发布系统状态,它由数个不同格式的子命令组成. * @example *
      * $redis->pubsub('channels'); // All channels
@@ -2791,64 +3340,93 @@ public function wait()
      * $redis->pubsub('numsub', array('chan1', 'chan2')); // Get subscriber counts for 'chan1' and 'chan2'
      * $redis->pubsub('numpat'); // Get the number of pattern subscribers
      * 
- * @return - + * @param string $subcommand 子命令(可以是channels, numsub, numpat) + * @param string|array $args 参数 + * @return array|int */ - public function pubsub() + public function pubsub(string $subcommand, string $args): ?array { + } /** * - * + *连接redis服务器或打开一个已经连接的redis服务器 * @example + * @param string $host 主机IP + * @param int $port 端口 + * @param float $timeout 连接超时时间(以秒为单位) + * @param mixed $reserved 当使用retry_interval时该值为NULL + * @param int $retry_interval 重试间隔 + * @param float $read_timeout 读操作超时时间 * @return */ - public function open() + public function open(string $host, int $port, float $timeout, $reserved, int $retry_interval, float $read_timeout) { + } /** * - * + *连接redis服务器或打开一个已经连接的redis服务器(长连接) * @example + * @param string $host 主机IP + * @param int $port 端口 + * @param float $timeout 连接超时时间(以秒为单位) + * @param mixed $reserved 当使用retry_interval时该值为NULL + * @param int $retry_interval 重试间隔 + * @param float $read_timeout 读操作超时时间 * @return */ - public function popen() + public function popen(string $host, int $port, float $timeout, $reserved, int $retry_interval, float $read_timeout) { + } /** * - *Returns the size of a list identified by Key. If the list didn't exist or is empty, - *the command returns 0. If the data type identified by Key is not a list, the command return FALSE. + *返回列表的长度 * @example - *
-     * $redis->rPush('key1', 'A');
-     * $redis->rPush('key1', 'B');
-     * $redis->rPush('key1', 'C');  // key1 => [ 'A', 'B', 'C' ]
-     * $redis->lLen('key1');       // 3
-     * $redis->rPop('key1');
-     * $redis->lLen('key1');       // 2
-     * 
- * @return bool + * @param string|...|array $key 键名 + * @return int | bool */ - public function lLen() + public function lLen(string $key): ?int { + } /** * - * + *返回集合的所有成员 * @example + *
+     * $redis->delete('s');
+     * $redis->sAdd('s', 'a');
+     * $redis->sAdd('s', 'b');
+     * $redis->sAdd('s', 'a');
+     * $redis->sAdd('s', 'c');
+     * var_dump($redis->sMembers('s'));
+     * //array(3) {
+     * //  [0]=>
+     * //  string(1) "c"
+     * //  [1]=>
+     * //  string(1) "a"
+     * //  [2]=>
+     * //  string(1) "b"
+     * //}
+     * // The order is random and corresponds to redis' own internal representation of the set structure.
+     * 
+ * @param string $key 键名 * @return array */ - public function sGetMembers() + public function sGetMembers(string $key): array { + } /** * - *Returns the values of all specified keys. + *批量获取键名 * @example *
      * $redis->delete('x', 'y', 'z', 'h');	// remove x y z
@@ -2867,107 +3445,149 @@ public function sGetMembers()
      * // bool(false)
      * // }
      * 
+ * @param array $keys 键名数组 * @return */ - public function mget() + public function mget(Array $keys) { + } /** * - *Sets an expiration date (a timeout) on an item. + *设置键的有效期 * @example - *
-     * $redis->set('x', '42');
-     * $redis->setTimeout('x', 3);  // x will disappear in 3 seconds.
-     * sleep(5);                    // wait 5 seconds
-     * $redis->get('x');            // will return `FALSE`, as 'x' has expired.
-     * 
- * @return bool: + * @param string $key 键名 + * @param int $ttl 有效期(秒数) + * @return bool */ - public function expire() + public function expire(string $key, int $ttl): bool { + } /** * - * + *将两个有序集合的并集存入到一个指定的键中 * @example - * @return + *
+     * $redis->delete('k1');
+     * $redis->delete('k2');
+     * $redis->delete('k3');
+     * $redis->delete('ko1');
+     * $redis->delete('ko2');
+     * $redis->delete('ko3');
+     * $redis->zAdd('k1', 0, 'val0');
+     * $redis->zAdd('k1', 1, 'val1');
+     * $redis->zAdd('k2', 2, 'val2');
+     * $redis->zAdd('k2', 3, 'val3');
+     * $redis->zUnion('ko1', array('k1', 'k2')); // 4, 'ko1' => array('val0', 'val1', 'val2', 'val3')
+     * // Weighted zUnion
+     * $redis->zUnion('ko2', array('k1', 'k2'), array(1, 1)); // 4, 'ko2' => array('val0', 'val1', 'val2', 'val3')
+     * $redis->zUnion('ko3', array('k1', 'k2'), array(5, 1)); // 4, 'ko3' => array('val0', 'val2', 'val3', 'val1')
+     * 
+ * @param string $dstKey 目标集合键名 + * @param array $zsetKeys 集合键名 + * @param array $zsetKeysWeight 集合键对应的权重 + * @param string $aggregateFunction 合并使用的函数(SUM, MIN, 或 MAX) + * @return int */ - public function zunionstore() + public function zunionstore(string $dstKey, Array $zsetKeys, Array $zsetKeysWeight, string $aggregateFunction): int { + } /** * - * + *将两个有序集合的交集存入到一个指定的键中 * @example - * @return + *
+     * $redis->delete('k1');
+     * $redis->delete('k2');
+     * $redis->delete('k3');
+     * $redis->delete('ko1');
+     * $redis->delete('ko2');
+     * $redis->delete('ko3');
+     * $redis->delete('ko4');
+     * $redis->zAdd('k1', 0, 'val0');
+     * $redis->zAdd('k1', 1, 'val1');
+     * $redis->zAdd('k1', 3, 'val3');
+     * $redis->zAdd('k2', 2, 'val1');
+     * $redis->zAdd('k2', 3, 'val3');
+     * $redis->zInter('ko1', array('k1', 'k2'));               // 2, 'ko1' => array('val1', 'val3')
+     * $redis->zInter('ko2', array('k1', 'k2'), array(1, 1));  // 2, 'ko2' => array('val1', 'val3')
+     * // Weighted zInter
+     * $redis->zInter('ko3', array('k1', 'k2'), array(1, 5), 'min'); // 2, 'ko3' => array('val1', 'val3')
+     * $redis->zInter('ko4', array('k1', 'k2'), array(1, 5), 'max'); // 2, 'ko4' => array('val3', 'val1')
+     * 
+ * @param string $dstKey 目标集合键名 + * @param array $zsetKeys 集合键名 + * @param array $zsetKeysWeight 集合键对应的权重 + * @param string $aggregateFunction 合并使用的函数(SUM, MIN, 或 MAX) + * @return int */ - public function zinterstore() + public function zinterstore(string $dstKey, Array $zsetKeys, Array $zsetKeysWeight, string $aggregateFunction): int { + } /** * - * + *删除有序集合中的某个成员 * @example - * @return + * @param string $key 集合键名 + * @param string $member 成员值 + * @return int */ - public function zRemove() + public function zRemove(string $key, string $member): int { + } /** * - *Deletes a specified member from the ordered set. + *删除有序集合中的某个成员 * @example - *
-     * $redis->zAdd('z', 1, 'v2', 2, 'v2', 3, 'v3', 4, 'v4' );  // int(2)
-     * $redis->zRem('z', 'v2', 'v3');                           // int(2)
-     * var_dump( $redis->zRange('z', 0, -1) );
-     * //// Output:
-     * // array(2) {
-     * //   [0]=> string(2) "v1"
-     * //   [1]=> string(2) "v4"
-     * // }
-     * 
+ * @param string $key 集合键名 + * @param string $member 成员值 * @return int */ - public function zRem() + public function zRem(string $key, string $member): int { + } /** * - * + *根据排序值范围来删除成员 * @example - * @return + * @param string $key 集合键名 + * @param double $start 开始排序值 + * @param double $end 结束排序值 + * @return int */ - public function zRemoveRangeByScore() + public function zRemoveRangeByScore(string $key, double $start, double $end): int { + } /** * - *Deletes the elements of the sorted set stored at the specified key which have scores in the range [start,end]. + *根据排序值范围来删除成员 * @example - *
-     * $redis->zAdd('key', 0, 'val0');
-     * $redis->zAdd('key', 2, 'val2');
-     * $redis->zAdd('key', 10, 'val10');
-     * $redis->zRemRangeByScore('key', 0, 3); // 2
-     * 
+ * @param string $key 集合键名 + * @param double $start 开始排序值 + * @param double $end 结束排序值 * @return int */ - public function zRemRangeByScore() + public function zRemRangeByScore(string $key, double $start, double $end): int { + } /** * - *Deletes the elements of the sorted set stored at the specified key which have rank in the range [start,end]. + *根据排序范围删除成员 * @example *
      * $redis->zAdd('key', 1, 'one');
@@ -2976,188 +3596,279 @@ public function zRemRangeByScore()
      * $redis->zRemRangeByRank('key', 0, 1); // 2
      * $redis->zRange('key', 0, -1, array('withscores' => TRUE)); // array('three' => 3)
      * 
+ * @param string $key 集合键名 + * @param double $start 开始排序值 + * @param double $end 结束排序值 * @return int */ - public function zRemRangeByRank() + public function zRemRangeByRank(string $key, double $start, double $end): int { + } /** * - * + *获取有序集合的成员数 * @example - * @return + *
+     * $redis->zAdd('key', 0, 'val0');
+     * $redis->zAdd('key', 2, 'val2');
+     * $redis->zAdd('key', 10, 'val10');
+     * $redis->zCard('key');            // 3
+     * 
+ * @param string $key 集合键名 + * @return int */ - public function zSize() + public function zSize(string $key): int { + } /** * - *Return a substring of a larger string + *获取一个键值的子字符串 * @example - * @return + *
+     * $redis->set('key', 'string value');
+     * $redis->getRange('key', 0, 5);   // 'string'
+     * $redis->getRange('key', -5, -1); // 'value'
+     * 
+ * @param string $key 键名 + * @param int $start 开始位置 + * @param int $end 结束位置 + * @return string */ - public function substr() + public function substr(string $key, int $start, int $end): string { + } /** * - *Renames a key. + *给键重命名 * @example - *
-     * $redis->set('x', '42');
-     * $redis->rename('x', 'y');
-     * $redis->get('y');   // → 42
-     * $redis->get('x');   // → `FALSE`
-     * 
- * @return bool: + * @param string $srcKey 旧键名 + * @param string $dstKey 新键名 + * @return bool */ - public function rename() + public function rename(string $srcKey, string $dstKey): bool { + } /** * - *Remove specified keys. - * @example - *
-     * $redis->set('key1', 'val1');
-     * $redis->set('key2', 'val2');
-     * $redis->set('key3', 'val3');
-     * $redis->set('key4', 'val4');
-     * $redis->delete('key1', 'key2');          // return 2
-     * $redis->delete(array('key3', 'key4'));   // return 2
-     * 
+ *删除一个或多个键 + * @example $redis->delete('key1', 'key2'); + * $redis->delete(array('key3', 'key4')); + * @param array|string $keys 键名 * @return int */ - public function del() + public function del(array $keys): int { + } /** * - *Returns the keys that match a certain pattern. + *根据匹配模式获取键名(如*) * @example - *
-     * $allKeys = $redis->keys('*');   // all keys will match this.
+     * $allKeys = $redis->keys('*');
      * $keyWithUserPrefix = $redis->keys('user*');
-     * 
+ * @param string $pattern 匹配模式 * @return array */ - public function keys() + public function keys(string $pattern): array { + } /** * - * + *从列表中删除指定值的元素。 如果count为零,则删除所有匹配的元素。 如果计数是负数,则元素从尾部移到头部。 * @example - * @return + * @param string $key 键名 + * @param string $value 元素值 + * @param int $count 删除的个数 + * @return int | bool */ - public function lrem() + public function lrem(string $key, string $value, int $count): ?int { + } /** * - * + *删除指定范围外的其他元素 * @example - * @return + * @param string $key 键名 + * @param int $start 开始索引 + * @param int $end 结束索引 + * @return array | bool */ - public function ltrim() + public function ltrim(string $key, int $start, int $end): ?array { + } /** * - * + *获取列表中指定索引的值 * @example - * @return + * @param string $key 键名 + * @param int $index 索引值 + * @return string | bool */ - public function lindex() + public function lindex(string $key, int $index): ?string { + } /** * - * + *获取列表指定范围的值 * @example - * @return + * @param string $key 键名 + * @param int $start 索引开始值 + * @param int $end 索引结束值 + * @return array */ - public function lrange() + public function lrange(string $key, int $start, int $end): array { + } /** * - * + *返回集合的元素个数 * @example - * @return + * @param string $key 键名 + * @return int */ - public function scard() + public function scard(string $key): int { + } /** * - * + *删除集合元素 * @example - * @return + * @param string $key 键名 + * @param string|... $member 成员 + * @return int */ - public function srem() + public function srem(string $key, string $member): int { + } /** * - * + *是否包含某个成员 * @example - * @return + * @param string $key 键名 + * @param string $member 成员值 + * @return bool */ - public function sismember() + public function sismember(string $key, string $member): bool { + } /** * - * + *获取有序集合中指定范围的成员(倒序排列) * @example - * @return + *
+     * $redis->zAdd('key', 0, 'val0');
+     * $redis->zAdd('key', 2, 'val2');
+     * $redis->zAdd('key', 10, 'val10');
+     * $redis->zRevRange('key', 0, -1); // array('val10', 'val2', 'val0')
+     * // with scores
+     * $redis->zRevRange('key', 0, -1, true); // array('val10' => 10, 'val2' => 2, 'val0' => 0)
+     * 
+ * @param string $key 集合键名 + * @param int $start 索引开始值 + * @param int $end 索引结束值 + * @param bool $withScores 是否返回成员的排序值 + * @return array */ - public function zReverseRange() + public function zReverseRange(string $key, int $start, int $end, bool $withScores): array { + } /** * - * + *向redis发送一个字符串,而且redis服务器将返回一个相同的字符串 * @example - * @return + * @param string $str 发送的字符串 + * @return string */ - public function sendEcho() + public function sendEcho(string $str): string { + } /** * - * + *执行lua脚本 * @example + * @param string $script 脚本 + * @param array $args 脚本参数 + * @param int $num_keys 应该进入KEYS数组的参数个数 * @return mixed */ - public function evaluate() + public function evaluate(string $script, Array $args, int $num_keys) { + } /** * - * + *执行lua脚本 * @example + * @param string $script 脚本 + * @param array $args 脚本参数 + * @param int $num_keys 应该进入KEYS数组的参数个数 + * @return mixed + */ + public function eval(string $script, Array $args, int $num_keys) + { + + } + + /** + * + *从脚本的SHA1散列而不是脚本本身执行LUA脚本 + * @example $script = 'return 1'; + * $sha = $redis->script('load', $script); + * $redis->evalSha($sha); // Returns 1 + * @param string $script_sha 脚本的散列值 + * @param array $args 脚本参数 + * @param int $num_keys 应该进入KEYS数组的参数个数 + * @return + */ + public function evaluateSha(string $script_sha, Array $args, int $num_keys) + { + + } + + /** + * + *从脚本的SHA1散列而不是脚本本身执行LUA脚本 + * @example $script = 'return 1'; + * $sha = $redis->script('load', $script); + * $redis->evalSha($sha); // Returns 1 + * @param string $script_sha 脚本的散列值 + * @param array $args 脚本参数 + * @param int $num_keys 应该进入KEYS数组的参数个数 * @return */ - public function evaluateSha() + public function evalSha(string $script_sha, Array $args, int $num_keys) { + } } diff --git a/src/Redis/RedisArray.php b/src/Redis/RedisArray.php index a6480b5..f5826e9 100644 --- a/src/Redis/RedisArray.php +++ b/src/Redis/RedisArray.php @@ -1,285 +1,396 @@ + * $redis->select(0); // switch to DB 0 + * $redis->set('x', '42'); // write 42 to x + * $redis->move('x', 1); // move to DB 1 + * $redis->select(1); // switch to DB 1 + * $redis->get('x'); // will return 42 + *
+ * @param int $dbIndex 数据库编号 + * @return bool */ - public function select() + public function select(int $dbIndex): bool { + } /** * - * + *获取Redis服务器的信息和统计数据 * @example - * @return + *
+     * $redis->info();
+     * or
+     * $redis->info("COMMANDSTATS"); //Information on the commands that have been run (>=2.6 only)
+     * $redis->info("CPU"); // just CPU information from Redis INFO
+     * 
+ * @return array */ - public function info() + public function info(): array { + } /** * - * + *检查当前redis连接状态(成功时返回PONG) * @example - * @return + * @return string */ - public function ping() + public function ping(): string { + } /** * - * - * @example - * @return + *删除当前数据库的所有键 + * @example $redis->flushDB(); + * @return bool */ - public function flushdb() + public function flushDB(): bool { + } /** * - * - * @example - * @return + *删除当前实例的所有键 + * @example $redis->flushAll(); + * @return bool */ - public function flushall() + public function flushAll(): bool { + } /** * - * + *批量获取键名 * @example + *
+     * $redis->delete('x', 'y', 'z', 'h');	// remove x y z
+     * $redis->mset(array('x' => 'a', 'y' => 'b', 'z' => 'c'));
+     * $redis->hset('h', 'field', 'value');
+     * var_dump($redis->mget(array('x', 'y', 'z', 'h')));
+     * // Output:
+     * // array(3) {
+     * // [0]=>
+     * // string(1) "a"
+     * // [1]=>
+     * // string(1) "b"
+     * // [2]=>
+     * // string(1) "c"
+     * // [3]=>
+     * // bool(false)
+     * // }
+     * 
+ * @param array $keys 键名数组 * @return */ - public function mget() + public function mget(Array $keys) { + } /** * - * + *批量设置值 * @example - * @return + *
+     * $redis->mset(array('key0' => 'value0', 'key1' => 'value1'));
+     * var_dump($redis->get('key0'));
+     * var_dump($redis->get('key1'));
+     * // Output:
+     * // string(6) "value0"
+     * // string(6) "value1"
+     * 
+ * @param array $values 要设置的键值对 + * @return bool */ - public function mset() + public function mset(Array $values): bool { + } /** * - * - * @example - * @return + *删除一个或多个键 + * @example $redis->delete('key1', 'key2'); + * $redis->delete(array('key3', 'key4')); + * @param array|string $keys 键名 + * @return int */ - public function del() + public function del(array $keys): int { + } /** * - * + *获取客户端选项 * @example - * @return + * // return Redis::SERIALIZER_NONE, Redis::SERIALIZER_PHP, or Redis::SERIALIZER_IGBINARY. + * $redis->getOption(Redis::OPT_SERIALIZER); + * @param string $optionName 选项名 + * @return int */ - public function getOption() + public function getOption(string $optionName): int { + } /** * - * + *设置客户端选项. * @example - * @return + *
+     * $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_NONE);        // don't serialize data
+     * $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);         // use built-in serialize/unserialize
+     * $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_IGBINARY);    // use igBinary serialize/unserialize
+     * $redis->setOption(Redis::OPT_PREFIX, 'myAppName:');                      // use custom prefix on all keys
+     * 
+ * @param string $optionName 选项名 + * @param string $optionValue 选项值 + * @return bool */ - public function setOption() + public function setOption(string $optionName, string $optionValue): bool { + } /** * - * + *根据匹配模式获取键名(如*) * @example - * @return + * $allKeys = $redis->keys('*'); + * $keyWithUserPrefix = $redis->keys('user*'); + * @param string $pattern 匹配模式 + * @return array */ - public function keys() + public function keys(string $pattern): array { + } /** * - * - * @example - * @return + *将数据同步到硬盘上 + * @example $redis->save(); + * @return boolean */ - public function save() + public function save(): boolean { + } /** * - * + *将数据存入到硬盘上(异步操作) * @example * @return */ - public function bgsave() + public function bgSave() { + } /** * - * + *开始一个事务. * @example + *
+     * $ret = $redis->multi()
+     * ->set('key1', 'val1')
+     * ->get('key1')
+     * ->set('key2', 'val2')
+     * ->get('key2')
+     * ->exec();
+     * //$ret == array (
+     * //    0 => TRUE,
+     * //    1 => 'val1',
+     * //    2 => TRUE,
+     * //    3 => 'val2');
+     * 
* @return */ public function multi() { + } /** * - * + *取消事务 * @example * @return */ - public function exec() + public function discard() { + } /** * - * + *执行事务 * @example * @return */ - public function discard() + public function exec() { + } /** * - * + *取消观察某个键在其他客户端的变化情况 * @example + * @param string|array $keys 键名 * @return */ - public function unwatch() + public function unwatch(string $keys) { + } /** * - * - * @example - * @return + *删除一个或多个键 + * @example $redis->delete('key1', 'key2'); + * $redis->delete(array('key3', 'key4')); + * @param array|string $keys 键名 + * @return int */ - public function delete() + public function delete(array $keys): int { + } /** * - * + *批量获取键值 * @example - * @return + *
+     * $redis->set('key1', 'value1');
+     * $redis->set('key2', 'value2');
+     * $redis->set('key3', 'value3');
+     * $redis->getMultiple(array('key1', 'key2', 'key3')); // array('value1', 'value2', 'value3');
+     * $redis->getMultiple(array('key0', 'key1', 'key5')); // array(`FALSE`, 'value2', `FALSE`);
+     * 
+ * @param array $keys 键名数组 + * @return array */ - public function getMultiple() + public function getMultiple(Array $keys): array { + } } diff --git a/src/Redis/RedisCluster.php b/src/Redis/RedisCluster.php index a5ad7cd..39f196e 100644 --- a/src/Redis/RedisCluster.php +++ b/src/Redis/RedisCluster.php @@ -1,92 +1,127 @@ =1)个slave,当master挂掉以后,能选出一个slave晋升成Master继续提供服务。Failover由失败判定和Leader选举两部分组成,Redis Cluster采用去中心化(Gossip)的设计,每个节点通过发送Ping(包括Gossip信息)/Pong心跳的方式来探测对方节点的存活,如果心跳超时则标记对方节点的状态为PFail,这个意思是说该节点认为对方节点可能失败了,有可能是网络闪断或者分区等其他原因导致通讯失败) */ const FAILOVER_DISTRIBUTE = 2; /** * */ + const FAILOVER_DISTRIBUTE_SLAVES = 3; + + /** + *后面位置 + */ const AFTER = 'after'; /** - * + *前面位置 */ const BEFORE = 'before'; /** * - *Creates a RedisCluster client + *创建一个集群对象 * @example $redis = new RedisCluster(null, array('127.0.0.1:6379', '127.0.0.1:6380')); + * @param string $name 集群名称(在php.ini配置文件或redis.ini配置文件中配置,不配置则为NULL) + * @param array $config 连接的集群节点配置项,如array('127.0.0.1:6379', '127.0.0.1:6380') + * @param float $timeout 连接超时时间 + * @param float $read_timeout 读操作超时时间 + * @param boolean $persistent 与每个节点持久化连接 * @return */ - public function __construct() + public function __construct(string $name, Array $config, float $timeout, float $read_timeout, bool $persistent) { + } /** * - *Disconnects from the Redis instance, except when pconnect is used. + *关闭redis连接(长连接除外) * @example * @return */ public function close() { + } /** * - *Get the value related to the specified key + *获取指定的key的值 * @example $redis->get('key'); - * @return string|bool: + * @return string|bool */ - public function get() + public function get(): ?string { + } /** * - *Set the string value in argument as value of the key. - * @example $redis->set('key', 'value'); - * @return bool: + *给指定的键设置值 + * @example 直接设置: + * $redis->set('key', 'value'); + * 带有效期的设置: + * $redis->set('key','value', 10); + * 当键不存在时,设置期有效期为10秒: + * $redis->set('key', 'value', Array('nx', 'ex'=>10)); + * 当键存在时,设置期有效期为1000毫秒: + * $redis->set('key', 'value', Array('xx', 'px'=>1000)); + * + * @param string $key 设置的缓存键 + * @param string $value 设置的缓存值 + * @param int|array $options 附加项,可以是超时时间或者一个选项数组 + * @return bool */ - public function set() + public function set(string $key, string $value, int $options): bool { + } /** * - *Returns the values of all specified keys. + *批量获取键名 * @example *
      * $redis->delete('x', 'y', 'z', 'h');	// remove x y z
@@ -181,16 +241,17 @@ public function set()
      * // bool(false)
      * // }
      * 
+ * @param array $keys 键名数组 * @return */ - public function mget() + public function mget(Array $keys) { + } /** * - *Sets multiple key-value pairs in one atomic command. - *MSETNX only returns TRUE if all the keys were set (see SETNX). + *批量设置值 * @example *
      * $redis->mset(array('key0' => 'value0', 'key1' => 'value1'));
@@ -200,267 +261,442 @@ public function mget()
      * // string(6) "value0"
      * // string(6) "value1"
      * 
+ * @param array $values 要设置的键值对 * @return bool */ - public function mset() + public function mset(Array $values): bool { + } /** * - * + *批量设置值(当不存在时设置) * @example - * @return int + *
+     * $redis->mset(array('key0' => 'value0', 'key1' => 'value1'));
+     * var_dump($redis->get('key0'));
+     * var_dump($redis->get('key1'));
+     * // Output:
+     * // string(6) "value0"
+     * // string(6) "value1"
+     * 
+ * @param array $values 要设置的键值对 + * @return bool */ - public function msetnx() + public function msetnx(Array $values): bool { + } /** * - *Remove specified keys. - * @example - *
-     * $redis->set('key1', 'val1');
-     * $redis->set('key2', 'val2');
-     * $redis->set('key3', 'val3');
-     * $redis->set('key4', 'val4');
-     * $redis->delete('key1', 'key2');          // return 2
-     * $redis->delete(array('key3', 'key4'));   // return 2
-     * 
+ *删除一个或多个键 + * @example $redis->delete('key1', 'key2'); + * $redis->delete(array('key3', 'key4')); + * @param array|string $keys 键名 * @return int */ - public function del() + public function del(array $keys): int { + } /** * - *Set the string value in argument as value of the key, with a time to live. - * @example $redis->setex('key', 3600, 'value'); // sets key �� value, with 1h TTL. - * @return bool: + *设置键值并设置有效期 + * @example $redis->setex('key', 3600, 'value'); + * @param string $key 设置的缓存键 + * @param string $value 设置的缓存值 + * @param int $ttl 有效期 + * @return bool */ - public function setex() + public function setex(string $key, string $value, int $ttl): bool { + } /** * - *Set the string value in argument as value of the key, with a time to live. + *设置键值并设置有效期(毫秒为单位) * @example - * @return bool: + * @param string $key 设置的缓存键 + * @param string $value 设置的缓存值 + * @param int $ttl 有效期(毫秒为单位) + * @return */ - public function psetex() + public function psetex(string $key, string $value, int $ttl) { + } /** * - *Set the string value in argument as value of the key if the key doesn't already exist in the database. + *当键不存在时设置其值 * @example - *
-     * $redis->setnx('key', 'value');   // return TRUE
-     * $redis->setnx('key', 'value');   // return FALSE
-     * 
- * @return bool: + * $redis->setnx('key', 'value'); + * + * @param string $key 设置的缓存键 + * @param string $value 设置的缓存值 + * @return bool */ - public function setnx() + public function setnx(string $key, string $value): bool { + } /** * - * + *设置键的值,并返回它的旧的缓存值 * @example - * @return + *
+     * $redis->set('x', '42');
+     * $exValue = $redis->getSet('x', 'lol');   // return '42', replaces x by 'lol'
+     * $newValue = $redis->get('x')'            // return 'lol'
+     * 
+ * @param string $key 设置的缓存键 + * @param string $value 设置的缓存值 + * @return string */ - public function getset() + public function getset(string $key, string $value): string { + } /** * - *Verify if the specified key exists. + *判断键是否存在 * @example *
      * $redis->set('key', 'value');
      * $redis->exists('key');               //  TRUE
      * $redis->exists('NonExistingKey');    // FALSE
      * 
- * @return bool: + * @param string $key 键名 + * @return bool */ - public function exists() + public function exists(string $key): bool { + } /** * - *Returns the keys that match a certain pattern. + *根据匹配模式获取键名(如*) * @example - *
-     * $allKeys = $redis->keys('*');   // all keys will match this.
+     * $allKeys = $redis->keys('*');
      * $keyWithUserPrefix = $redis->keys('user*');
-     * 
+ * @param string $pattern 匹配模式 * @return array */ - public function keys() + public function keys(string $pattern): array { + } /** * - *Returns the type of data pointed by a given key. + *获取指定键的数据类型(需要根据常量匹配) * @example $redis->type('key'); - * @return - - */ - public function type() - { - } - - /** - * - * - * @example - * @return + * @param string $key 键名 + * @return int */ - public function lpop() + public function type(string $key): int { + } /** * - * + *从列表左侧删除一个元素 * @example - * @return + *
+     * $redis->rPush('key1', 'A');
+     * $redis->rPush('key1', 'B');
+     * $redis->rPush('key1', 'C');  // key1 => [ 'A', 'B', 'C' ]
+     * $redis->lPop('key1');        // key1 => [ 'B', 'C' ]
+     * 
+ * @param string $key 键名 + * @return string */ - public function rpop() + public function lPop(string $key): string { + } /** * - * + *从列表右侧删除一个元素 * @example - * @return + *
+     * $redis->rPush('key1', 'A');
+     * $redis->rPush('key1', 'B');
+     * $redis->rPush('key1', 'C');  // key1 => [ 'A', 'B', 'C' ]
+     * $redis->rPop('key1');        // key1 => [ 'A', 'B' ]
+     * 
+ * @param string $key 键名 + * @return string */ - public function lset() + public function rPop(string $key): string { + } /** * - * + *给列表指定位置设置新值 * @example - * @return + *
+     * $redis->rPush('key1', 'A');
+     * $redis->rPush('key1', 'B');
+     * $redis->rPush('key1', 'C');  // key1 => [ 'A', 'B', 'C' ]
+     * $redis->lGet('key1', 0);     // 'A'
+     * $redis->lSet('key1', 0, 'X');
+     * $redis->lGet('key1', 0);     // 'X'
+     * 
+ * @param string $key 键名 + * @param int $index 索引值 + * @param string $value 新值 + * @return boolean */ - public function spop() + public function lset(string $key, int $index, string $value): boolean { + } /** * - * + *随机删除元素的某个或某些成员,并返回这个删除的成员. * @example - * @return + *
+     * $redis->sAdd('key1' , 'set1');
+     * $redis->sAdd('key1' , 'set2');
+     * $redis->sAdd('key1' , 'set3');   // 'key1' => {'set3', 'set1', 'set2'}
+     * $redis->sPop('key1');            // 'set1', 'key1' => {'set3', 'set2'}
+     * $redis->sPop('key1');            // 'set3', 'key1' => {'set2'}
+     * 
+ * @param string $key 键名 + * @param int $count 删除个数 + * @return string | bool */ - public function lpush() + public function spop(string $key, int $count): ?string { + } /** * - * + *从左侧(头部)向列表插入元素 * @example - * @return + *
+     * $redis->lPush('l', 'v1', 'v2', 'v3', 'v4')   // int(4)
+     * var_dump( $redis->lRange('l', 0, -1) );
+     * //// Output:
+     * // array(4) {
+     * //   [0]=> string(2) "v4"
+     * //   [1]=> string(2) "v3"
+     * //   [2]=> string(2) "v2"
+     * //   [3]=> string(2) "v1"
+     * // }
+     * 
+ * @param string $key 键名 + * @param string $value 元素值 + * @return int */ - public function rpush() + public function lPush(string $key, string $value): int { + } /** * - * + *从右侧(尾部)向列表插入元素 * @example - * @return + *
+     * $redis->rPush('l', 'v1', 'v2', 'v3', 'v4');    // int(4)
+     * var_dump( $redis->lRange('l', 0, -1) );
+     * //// Output:
+     * // array(4) {
+     * //   [0]=> string(2) "v1"
+     * //   [1]=> string(2) "v2"
+     * //   [2]=> string(2) "v3"
+     * //   [3]=> string(2) "v4"
+     * // }
+     * 
+ * @param string $key 键名 + * @param string $value 元素值 + * @return int */ - public function blpop() + public function rPush(string $key, string $value): int { + } /** * - * + *是一个阻塞lPop原语。 如果至少有一个列表包含至少一个元素,则该元素将从列表头部弹出并返回给调用者。 如果所有通过参数传递的键标识的列表都是空的,blPop将在指定的超时期间阻塞,直到元素被推送到其中一个列表。 这个元素将被弹出。 * @example - * @return + *
+     * // Non blocking feature
+     * $redis->lPush('key1', 'A');
+     * $redis->delete('key2');
+     * $redis->blPop('key1', 'key2', 10); // array('key1', 'A')
+     * // OR
+     * $redis->blPop(array('key1', 'key2'), 10); // array('key1', 'A')
+     * $redis->brPop('key1', 'key2', 10); // array('key1', 'A')
+     * // OR
+     * $redis->brPop(array('key1', 'key2'), 10); // array('key1', 'A')
+     * // Blocking feature
+     * // process 1
+     * $redis->delete('key1');
+     * $redis->blPop('key1', 10);
+     * // blocking for 10 seconds
+     * // process 2
+     * $redis->lPush('key1', 'A');
+     * // process 1
+     * // array('key1', 'A') is returned
+     * 
+ * @param string|...|array $key 键名 + * @param int $timeout 超时时间 + * @return array */ - public function brpop() + public function blPop(string $key, int $timeout): array { + } /** * - * + *是一个阻塞rPop原语。 如果至少有一个列表包含至少一个元素,则该元素将从列表尾部弹出并返回给调用者。 如果所有通过参数传递的键标识的列表都是空的,brPop将在指定的超时期间阻塞,直到元素被推送到其中一个列表。 这个元素将被弹出。 * @example - * @return + *
+     * // Non blocking feature
+     * $redis->lPush('key1', 'A');
+     * $redis->delete('key2');
+     * $redis->blPop('key1', 'key2', 10); // array('key1', 'A')
+     * // OR
+     * $redis->blPop(array('key1', 'key2'), 10); // array('key1', 'A')
+     * $redis->brPop('key1', 'key2', 10); // array('key1', 'A')
+     * // OR
+     * $redis->brPop(array('key1', 'key2'), 10); // array('key1', 'A')
+     * // Blocking feature
+     * // process 1
+     * $redis->delete('key1');
+     * $redis->blPop('key1', 10);
+     * // blocking for 10 seconds
+     * // process 2
+     * $redis->lPush('key1', 'A');
+     * // process 1
+     * // array('key1', 'A') is returned
+     * 
+ * @param string|...|array $key 键名 + * @param int $timeout 超时时间 + * @return array */ - public function rpushx() + public function brPop(string $key, int $timeout): array { + } /** * - * + *如果列表存在,从左侧(头部)向列表插入元素 * @example - * @return + *
+     * $redis->delete('key1');
+     * $redis->lPushx('key1', 'A');     // returns 0
+     * $redis->lPush('key1', 'A');      // returns 1
+     * $redis->lPushx('key1', 'B');     // returns 2
+     * $redis->lPushx('key1', 'C');     // returns 3
+     * // key1 now points to the following list: [ 'A', 'B', 'C' ]
+     * 
+ * @param string $key 键名 + * @param string $value 元素值 + * @return int */ - public function lpushx() + public function lPushx(string $key, string $value): int { + } /** * - * + *如果列表存在,从右侧(尾部)向列表插入元素 * @example - * @return + *
+     * $redis->delete('key1');
+     * $redis->rPushx('key1', 'A'); // returns 0
+     * $redis->rPush('key1', 'A'); // returns 1
+     * $redis->rPushx('key1', 'B'); // returns 2
+     * $redis->rPushx('key1', 'C'); // returns 3
+     * // key1 now points to the following list: [ 'A', 'B', 'C' ]
+     * 
+ * @param string $key 键名 + * @param string $value 元素值 + * @return int */ - public function linsert() + public function rPushx(string $key, string $value): int { + } /** * - * + *在列表中,在某个元素的前面或后面插入一个新值 * @example - * @return + *
+     * $redis->delete('key1');
+     * $redis->lInsert('key1', Redis::AFTER, 'A', 'X');     // 0
+     * $redis->lPush('key1', 'A');
+     * $redis->lPush('key1', 'B');
+     * $redis->lPush('key1', 'C');
+     * $redis->lInsert('key1', Redis::BEFORE, 'C', 'X');    // 4
+     * $redis->lRange('key1', 0, -1);                       // array('A', 'B', 'X', 'C')
+     * $redis->lInsert('key1', Redis::AFTER, 'C', 'Y');     // 5
+     * $redis->lRange('key1', 0, -1);                       // array('A', 'B', 'X', 'C', 'Y')
+     * $redis->lInsert('key1', Redis::AFTER, 'W', 'value'); // -1
+     * 
+ * @param string $key 键名 + * @param string $position 位置(前面或后面,使用Redis::BEFORE | Redis::AFTER) + * @param string $element 元素 + * @param string $value 新值 + * @return int */ - public function lindex() + public function linsert(string $key, string $position, string $element, string $value): int { + } /** * - * + *获取列表中指定索引的值 * @example - * @return + * @param string $key 键名 + * @param int $index 索引值 + * @return string | boolean */ - public function lrem() + public function lindex(string $key, int $index): ?string { + } /** * - *A blocking version of rpoplpush, with an integral timeout in the third parameter. + *从列表中删除指定值的元素。 如果count为零,则删除所有匹配的元素。 如果计数是负数,则元素从尾部移到头部。 * @example - * @return string + * @param string $key 键名 + * @param string $value 元素值 + * @param int $count 删除的个数 + * @return long | bool */ - public function brpoplpush() + public function lrem(string $key, string $value, int $count): ?long { + } /** * - *Pops a value from the tail of a list, and pushes it to the front of another list. - *Also return this value. + *从一个队列的队尾删除一个元素,并将该元素插入到另一个队列的头部 * @example *
      * $redis->delete('x', 'y');
@@ -488,424 +724,874 @@ public function brpoplpush()
      * //  string(3) "123"
      * //}
      * 
+ * @param string $srcKey 要删除元素的队列键名 + * @param string $dstKey 要插入元素的队列的键名 * @return string */ - public function rpoplpush() + public function rpoplpush(string $srcKey, string $dstKey): string { + } /** * - * + *阻塞执行rpoplpush * @example - * @return + * @param string $srcKey 要删除元素的队列键名 + * @param string $dstKey 要插入元素的队列的键名 + * @return string */ - public function llen() + public function brpoplpush(string $srcKey, string $dstKey): string { + } /** * - * + *返回列表的长度 * @example - * @return + * @param string|...|array $key 键名 + * @return long | bool */ - public function scard() + public function llen(string $key): ?long { + } /** * - * + *返回集合的元素个数 * @example - * @return + * @param string $key 键名 + * @return long */ - public function smembers() + public function scard(string $key): long { + } /** * - * + *返回集合的所有成员 * @example - * @return + *
+     * $redis->delete('s');
+     * $redis->sAdd('s', 'a');
+     * $redis->sAdd('s', 'b');
+     * $redis->sAdd('s', 'a');
+     * $redis->sAdd('s', 'c');
+     * var_dump($redis->sMembers('s'));
+     * //array(3) {
+     * //  [0]=>
+     * //  string(1) "c"
+     * //  [1]=>
+     * //  string(1) "a"
+     * //  [2]=>
+     * //  string(1) "b"
+     * //}
+     * // The order is random and corresponds to redis' own internal representation of the set structure.
+     * 
+ * @param string $key 键名 + * @return array */ - public function sismember() + public function smembers(string $key): array { + } /** * - * + *是否包含某个成员 * @example - * @return + * @param string $key 键名 + * @param string $member 成员值 + * @return boolean */ - public function sadd() + public function sismember(string $key, string $member): boolean { + } /** * - * + *给集合添加元素 * @example - * @return + *
+     * $redis->sAdd('k', 'v1');                // int(1)
+     * $redis->sAdd('k', 'v1', 'v2', 'v3');    // int(2)
+     * 
+ * @param string $key 键名 + * @param string $value 元素值 + * @return int */ - public function saddarray() + public function sAdd(string $key, string $value): int { + } /** * - * + *给集合批量添加元素 * @example + * @param string $key 键名 + * @param array $value 元素值 * @return */ - public function srem() + public function sAddArray(string $key, Array $value) { + } /** * - * + *删除集合元素 * @example - * @return + * @param string $key 键名 + * @param string|... $member 成员 + * @return long */ - public function sunion() + public function srem(string $key, string $member): long { + } /** * - * + *获取集合的并集 * @example - * @return + *
+     * $redis->delete('s0', 's1', 's2');
+     * $redis->sAdd('s0', '1');
+     * $redis->sAdd('s0', '2');
+     * $redis->sAdd('s1', '3');
+     * $redis->sAdd('s1', '1');
+     * $redis->sAdd('s2', '3');
+     * $redis->sAdd('s2', '4');
+     * var_dump($redis->sUnion('s0', 's1', 's2'));
+     * array(4) {
+     * //  [0]=>
+     * //  string(1) "3"
+     * //  [1]=>
+     * //  string(1) "4"
+     * //  [2]=>
+     * //  string(1) "1"
+     * //  [3]=>
+     * //  string(1) "2"
+     * //}
+     * 
+ * @param string $key1 键名1 + * @param string|... $key2 键名2 + * @return array */ - public function sunionstore() + public function sUnion(string $key1, string $key2): array { + } /** * - * + *获取多个集合的并集,并将结果存入到另外一个集合中 * @example - * @return + *
+     * $redis->delete('s0', 's1', 's2');
+     * $redis->sAdd('s0', '1');
+     * $redis->sAdd('s0', '2');
+     * $redis->sAdd('s1', '3');
+     * $redis->sAdd('s1', '1');
+     * $redis->sAdd('s2', '3');
+     * $redis->sAdd('s2', '4');
+     * var_dump($redis->sUnionStore('dst', 's0', 's1', 's2'));
+     * var_dump($redis->sMembers('dst'));
+     * //int(4)
+     * //array(4) {
+     * //  [0]=>
+     * //  string(1) "3"
+     * //  [1]=>
+     * //  string(1) "4"
+     * //  [2]=>
+     * //  string(1) "1"
+     * //  [3]=>
+     * //  string(1) "2"
+     * //}
+     * 
+ * @param string $dstKey 目标键,存放结果的键 + * @param string $key1 键名1 + * @param string $key2 键名2 + * @param string|... $keyN 键名n + * @return int */ - public function sinter() + public function sUnionStore(string $dstKey, string $key1, string $key2, string $keyN): int { + } /** * - * + *获取两个集合的交集 * @example - * @return + *
+     * $redis->sAdd('key1', 'val1');
+     * $redis->sAdd('key1', 'val2');
+     * $redis->sAdd('key1', 'val3');
+     * $redis->sAdd('key1', 'val4');
+     * $redis->sAdd('key2', 'val3');
+     * $redis->sAdd('key2', 'val4');
+     * $redis->sAdd('key3', 'val3');
+     * $redis->sAdd('key3', 'val4');
+     * var_dump($redis->sInter('key1', 'key2', 'key3'));
+     * //array(2) {
+     * //  [0]=>
+     * //  string(4) "val4"
+     * //  [1]=>
+     * //  string(4) "val3"
+     * //}
+     * 
+ * @param string $key1 键名1 + * @param string $key2 键名2 + * @return array | boolean */ - public function sinterstore() + public function sInter(string $key1, string $key2): ?array { + } /** * - * + *获取多个集合的交集,并将结果存入到另外一个集合中 * @example - * @return + *
+     * $redis->sAdd('key1', 'val1');
+     * $redis->sAdd('key1', 'val2');
+     * $redis->sAdd('key1', 'val3');
+     * $redis->sAdd('key1', 'val4');
+     * $redis->sAdd('key2', 'val3');
+     * $redis->sAdd('key2', 'val4');
+     * $redis->sAdd('key3', 'val3');
+     * $redis->sAdd('key3', 'val4');
+     * var_dump($redis->sInterStore('output', 'key1', 'key2', 'key3'));
+     * var_dump($redis->sMembers('output'));
+     * //int(2)
+     * //
+     * //array(2) {
+     * //  [0]=>
+     * //  string(4) "val4"
+     * //  [1]=>
+     * //  string(4) "val3"
+     * //}
+     * 
+ * @param string $dstKey 目标键,存放结果的键 + * @param string $key1 键名1 + * @param string $key2 键名2 + * @param string|... $keyN 键名n + * @return int */ - public function sdiff() + public function sInterStore(string $dstKey, string $key1, string $key2, string $keyN): int { + } /** * - * + *获取多个集合的差集 * @example - * @return + *
+     * $redis->delete('s0', 's1', 's2');
+     * $redis->sAdd('s0', '1');
+     * $redis->sAdd('s0', '2');
+     * $redis->sAdd('s0', '3');
+     * $redis->sAdd('s0', '4');
+     * $redis->sAdd('s1', '1');
+     * $redis->sAdd('s2', '3');
+     * var_dump($redis->sDiff('s0', 's1', 's2'));
+     * //array(2) {
+     * //  [0]=>
+     * //  string(1) "4"
+     * //  [1]=>
+     * //  string(1) "2"
+     * //}
+     * 
+ * @param string $key1 键名1 + * @param string|... $key2 键名2 + * @return array */ - public function sdiffstore() + public function sDiff(string $key1, string $key2): array { + } /** * - * + *获取多个集合的差集,并将结果存入到一个新的集合中 * @example - * @return + *
+     * $redis->delete('s0', 's1', 's2');
+     * $redis->sAdd('s0', '1');
+     * $redis->sAdd('s0', '2');
+     * $redis->sAdd('s0', '3');
+     * $redis->sAdd('s0', '4');
+     * $redis->sAdd('s1', '1');
+     * $redis->sAdd('s2', '3');
+     * var_dump($redis->sDiffStore('dst', 's0', 's1', 's2'));
+     * var_dump($redis->sMembers('dst'));
+     * //int(2)
+     * //array(2) {
+     * //  [0]=>
+     * //  string(1) "4"
+     * //  [1]=>
+     * //  string(1) "2"
+     * //}
+     * 
+ * @param string $dstKey 目标键,存放结果的键 + * @param string $key1 键名1 + * @param string $key2 键名2 + * @param string|... $keyN 键名n + * @return int */ - public function srandmember() + public function sDiffStore(string $dstKey, string $key1, string $key2, string $keyN): int { + } /** * - *Get the length of a string value. + *随机返回一个集合的元素(不会删除它) + * @example + *
+     * $redis->sAdd('key1' , 'one');
+     * $redis->sAdd('key1' , 'two');
+     * $redis->sAdd('key1' , 'three');              // 'key1' => {'one', 'two', 'three'}
+     * var_dump( $redis->sRandMember('key1') );     // 'key1' => {'one', 'two', 'three'}
+     * // string(5) "three"
+     * var_dump( $redis->sRandMember('key1', 2) );  // 'key1' => {'one', 'two', 'three'}
+     * // array(2) {
+     * //   [0]=> string(2) "one"
+     * //   [1]=> string(2) "three"
+     * // }
+     * 
+ * @param string $key 键名 + * @return string | bool + */ + public function srandmember(string $key): ?string + { + + } + + /** + * + *获取键值的长度 * @example *
      * $redis->set('key', 'value');
      * $redis->strlen('key'); // 5
      * 
- * @return + * @param string $key 键名 + * @return int */ - public function strlen() + public function strlen(string $key): int { + } /** * - *Remove the expiration timer from a key. + *移除指定键的有效期,让它永久有效 * @example $redis->persist('key'); - * @return bool: + * @param string $key 键名 + * @return bool */ - public function persist() + public function persist(string $key): bool { + } /** * - *Returns the time to live left for a given key, in seconds. If the key doesn't exist, FALSE is returned. + *返回指定键的有效时间(秒) * @example $redis->ttl('key'); - * @return int, + * @param string $key 键名 + * @return long */ - public function ttl() + public function ttl(string $key): long { + } /** * - *Returns a time to live left for a given key, in milliseconds. + *返回指定键的有效时间(毫秒) * @example $redis->pttl('key'); - * @return int + * @param string $key 键名 + * @return long */ - public function pttl() + public function pttl(string $key): long { + } /** * - * + *获取有序集合的成员数 * @example - * @return + *
+     * $redis->zAdd('key', 0, 'val0');
+     * $redis->zAdd('key', 2, 'val2');
+     * $redis->zAdd('key', 10, 'val10');
+     * $redis->zCard('key');            // 3
+     * 
+ * @param string $key 集合键名 + * @return int */ - public function zcard() + public function zcard(string $key): int { + } /** * - * + *获取指定排序范围的成员数. * @example - * @return + *
+     * $redis->zAdd('key', 0, 'val0');
+     * $redis->zAdd('key', 2, 'val2');
+     * $redis->zAdd('key', 10, 'val10');
+     * $redis->zCount('key', 0, 3); // 2, corresponding to array('val0', 'val2')
+     * 
+ * @param string $key 集合键名 + * @param double $start 开始排序值 + * @param double $end 结束排序值 + * @return int */ - public function zcount() + public function zcount(string $key, double $start, double $end): int { + } /** * - * + *根据排序值范围来删除成员 * @example - * @return + * @param string $key 集合键名 + * @param double $start 开始排序值 + * @param double $end 结束排序值 + * @return long */ - public function zremrangebyscore() + public function zremrangebyscore(string $key, double $start, double $end): long { + } /** * - * + *获取指定成员的排序值(分数) * @example - * @return + *
+     * $redis->zAdd('key', 2.5, 'val2');
+     * $redis->zScore('key', 'val2'); // 2.5
+     * 
+ * @param string $key 集合键名 + * @param string $member 成员值 + * @return double */ - public function zscore() + public function zscore(string $key, string $member): double { + } /** * - * + *向有序集合插入元素 * @example - * @return + *
+     * 
+     * $redis->zAdd('z', 1, 'v2', 2, 'v2', 3, 'v3', 4, 'v4' );  // int(2)
+     * $redis->zRem('z', 'v2', 'v3');                           // int(2)
+     * var_dump( $redis->zRange('z', 0, -1) );
+     * //// Output:
+     * // array(2) {
+     * //   [0]=> string(2) "v1"
+     * //   [1]=> string(2) "v4"
+     * // }
+     * 
+ *
+ * @param string $key 集合键名 + * @param double $score 排序值 + * @param string $value 元素值 + * @return int */ - public function zadd() + public function zadd(string $key, double $score, string $value): int { + } /** * - * + *给有序集合成员增加排序值 * @example - * @return + *
+     * $redis->delete('key');
+     * $redis->zIncrBy('key', 2.5, 'member1');  // key or member1 didn't exist, so member1's score is to 0
+     * // before the increment and now has the value 2.5
+     * $redis->zIncrBy('key', 1, 'member1');    // 3.5
+     * 
+ * @param string $key 目标集合键名 + * @param double $step 增加的步长 + * @param string $member 成员 + * @return float */ - public function zincrby() + public function zincrby(string $key, double $step, string $member): float { + } /** * - * + *获取字典的某个字段的值 * @example - * @return + * @param string $key 键名 + * @param string $field 字段名 + * @return string */ - public function hlen() + public function hGet(string $key, string $field): string { + } /** * - * + *为字典的字段设置值 * @example - * @return + *
+     * $redis->delete('h')
+     * $redis->hSet('h', 'key1', 'hello');  // 1, 'key1' => 'hello' in the hash at "h"
+     * $redis->hGet('h', 'key1');           // returns "hello"
+     * $redis->hSet('h', 'key1', 'plop');   // 0, value was replaced.
+     * $redis->hGet('h', 'key1');           // returns "plop"
+     * 
+ * @param string $key 键名 + * @param string $field 字段名 + * @param string $value 字段值 + * @return long */ - public function hkeys() + public function hSet(string $key, string $field, string $value): long { + } /** * - * + *当字典的字段不存在时,为其设置值 * @example - * @return + *
+     * $redis->delete('h')
+     * $redis->hSetNx('h', 'key1', 'hello'); // TRUE, 'key1' => 'hello' in the hash at "h"
+     * $redis->hSetNx('h', 'key1', 'world'); // FALSE, 'key1' => 'hello' in the hash at "h". No change since the field
+     * wasn't replaced.
+     * 
+ * @param string $key 键名 + * @param string $field 字段名 + * @param string $value 字段值 + * @return bool */ - public function hvals() + public function hSetNx(string $key, string $field, string $value): bool { + } /** * - * + *删除字典的某个或某些字段 * @example - * @return + *
+     * $redis->hMSet('h',
+     * array(
+     * 'f1' => 'v1',
+     * 'f2' => 'v2',
+     * 'f3' => 'v3',
+     * 'f4' => 'v4',
+     * ));
+     * var_dump( $redis->hDel('h', 'f1') );        // int(1)
+     * var_dump( $redis->hDel('h', 'f2', 'f3') );  // int(2)
+     * s
+     * var_dump( $redis->hGetAll('h') );
+     * //// Output:
+     * //  array(1) {
+     * //    ["f4"]=> string(2) "v4"
+     * //  }
+     * 
+ * @param string $key 键名 + * @param string|array $fields 字段名 + * @return int */ - public function hget() + public function hDel(string $key, string $fields): int { + } /** * - * + *获取字典的字段个数 * @example - * @return + *
+     * $redis->delete('h')
+     * $redis->hSet('h', 'key1', 'hello');
+     * $redis->hSet('h', 'key2', 'plop');
+     * $redis->hLen('h'); // returns 2
+     * 
+ * @param string $key 键名 + * @return int */ - public function hgetall() + public function hLen(string $key): int { + } /** * - * + *获取字典的字段名称列表. * @example - * @return + *
+     * $redis->delete('h');
+     * $redis->hSet('h', 'a', 'x');
+     * $redis->hSet('h', 'b', 'y');
+     * $redis->hSet('h', 'c', 'z');
+     * $redis->hSet('h', 'd', 't');
+     * var_dump($redis->hKeys('h'));
+     * // Output:
+     * // array(4) {
+     * // [0]=>
+     * // string(1) "a"
+     * // [1]=>
+     * // string(1) "b"
+     * // [2]=>
+     * // string(1) "c"
+     * // [3]=>
+     * // string(1) "d"
+     * // }
+     * // The order is random and corresponds to redis' own internal representation of the set structure.
+     * 
+ * @param string $key 键名 + * @return array */ - public function hexists() + public function hKeys(string $key): array { + } /** * - * + *获取字典的字段值列表 * @example - * @return + *
+     * $redis->delete('h');
+     * $redis->hSet('h', 'a', 'x');
+     * $redis->hSet('h', 'b', 'y');
+     * $redis->hSet('h', 'c', 'z');
+     * $redis->hSet('h', 'd', 't');
+     * var_dump($redis->hVals('h'));
+     * // Output
+     * // array(4) {
+     * //   [0]=>
+     * //   string(1) "x"
+     * //   [1]=>
+     * //   string(1) "y"
+     * //   [2]=>
+     * //   string(1) "z"
+     * //   [3]=>
+     * //   string(1) "t"
+     * // }
+     * // The order is random and corresponds to redis' own internal representation of the set structure.
+     * 
+ * @param string $key 键名 + * @return array */ - public function hincrby() + public function hVals(string $key): array { + } /** * - * + *获取字典所有字段键值对 * @example - * @return + *
+     * $redis->delete('h');
+     * $redis->hSet('h', 'a', 'x');
+     * $redis->hSet('h', 'b', 'y');
+     * $redis->hSet('h', 'c', 'z');
+     * $redis->hSet('h', 'd', 't');
+     * var_dump($redis->hGetAll('h'));
+     * // Output:
+     * // array(4) {
+     * //   ["a"]=>
+     * //   string(1) "x"
+     * //   ["b"]=>
+     * //   string(1) "y"
+     * //   ["c"]=>
+     * //   string(1) "z"
+     * //   ["d"]=>
+     * //   string(1) "t"
+     * // }
+     * // The order is random and corresponds to redis' own internal representation of the set structure.
+     * 
+ * @param string $key 键名 + * @return array */ - public function hset() + public function hGetAll(string $key): array { + } /** * - * + *判断字典的某个字段是否存在. * @example - * @return + *
+     * $redis->hSet('h', 'a', 'x');
+     * $redis->hExists('h', 'a');               //  TRUE
+     * $redis->hExists('h', 'NonExistingKey');  // FALSE
+     * 
+ * @param string $key 键名 + * @param string $field 字段名 + * @return bool */ - public function hsetnx() + public function hExists(string $key, string $field): bool { + } /** * - * + *为指定字段增加指定的值. * @example - * @return + *
+     * $redis->delete('h');
+     * $redis->hIncrBy('h', 'x', 2); // returns 2: h[x] = 2 now.
+     * $redis->hIncrBy('h', 'x', 1); // h[x] ← 2 + 1. Returns 3
+     * 
+ * @param string $key 键名 + * @param string $field 字段名 + * @param int $step 自增步长 + * @return int */ - public function hmget() + public function hIncrBy(string $key, string $field, int $step): int { + } /** * - * + *为指定字段增加指定的值 * @example + *
+     * $redis = new Redis();
+     * $redis->connect('127.0.0.1');
+     * $redis->hset('h', 'float', 3);
+     * $redis->hset('h', 'int',   3);
+     * var_dump( $redis->hIncrByFloat('h', 'float', 1.5) ); // float(4.5)
+     * var_dump( $redis->hGetAll('h') );
+     * // Output
+     * array(2) {
+     * ["float"]=>
+     * string(3) "4.5"
+     * ["int"]=>
+     * string(1) "3"
+     * }
+     * 
+ * @param string $key 键名 + * @param string $field 字段名 + * @param double $step 自增步长 * @return */ - public function hmset() + public function hIncrByFloat(string $key, string $field, double $step) { + } /** * - * + *批量设置字典字段的值 * @example - * @return + *
+     * $redis->delete('user:1');
+     * $redis->hMset('user:1', array('name' => 'Joe', 'salary' => 2000));
+     * $redis->hIncrBy('user:1', 'salary', 100); // Joe earns 100 more now.
+     * 
+ * @param string $key 键名 + * @param array $fields 字段键值对 + * @return boolean */ - public function hdel() + public function hMset(string $key, Array $fields): boolean { + } /** * - * + *批量获取字典的字段值 * @example - * @return + * @param string $key 键名 + * @param array $fields 字段名列表 + * @return array */ - public function hincrbyfloat() + public function hMget(string $key, Array $fields): array { + } /** * - *Dump a key out of a redis database, the value of which can later be passed into redis using the RESTORE command. - *The data that comes out of DUMP is a binary representation of the key as Redis stores it. + *将某个键导出为一个二进制数据. * @example *
      * $redis->set('foo', 'bar');
      * $val = $redis->dump('foo'); // $val will be the Redis encoded key value
      * 
+ * @param string $key 键名 * @return string */ - public function dump() + public function dump(string $key): string { + } /** * - * + *获取成员的排序值 * @example - * @return + *
+     * $redis->delete('z');
+     * $redis->zAdd('key', 1, 'one');
+     * $redis->zAdd('key', 2, 'two');
+     * $redis->zRank('key', 'one');     // 0
+     * $redis->zRank('key', 'two');     // 1
+     * $redis->zRevRank('key', 'one');  // 1
+     * $redis->zRevRank('key', 'two');  // 0
+     * 
+ * @param string $key 集合键名 + * @param string $member 成员值 + * @return int */ - public function zrank() + public function zRank(string $key, string $member): int { + } /** * - * + *获取成员的排位值(倒数) * @example - * @return + * @param string $key 集合键名 + * @param string $member 成员值 + * @return int */ - public function zrevrank() + public function zRevRank(string $key, string $member): int { + } /** * - *Increment the number stored at key by one. + *键值自增 * @example *
      * $redis->incr('key1'); // key1 didn't exists, set to 0 before the increment and now has the value 1
@@ -913,432 +1599,729 @@ public function zrevrank()
      * $redis->incr('key1'); // 3
      * $redis->incr('key1'); // 4
      * 
+ * @param string $key 键名 * @return int */ - public function incr() + public function incr(string $key): int { + } /** * - *Decrement the number stored at key by one. + *按指定步长自增 * @example *
-     * $redis->decr('key1'); // key1 didn't exists, set to 0 before the increment and now has the value -1
-     * $redis->decr('key1'); // -2
-     * $redis->decr('key1'); // -3
+     * $redis->incr('key1');        // key1 didn't exists, set to 0 before the increment and now has the value 1
+     * $redis->incr('key1');        // 2
+     * $redis->incr('key1');        // 3
+     * $redis->incr('key1');        // 4
+     * $redis->incrBy('key1', 10);  // 14
      * 
+ * @param string $key 键名 + * @param int $step 自增步长 * @return int */ - public function decr() + public function incrBy(string $key, int $step): int { + } /** * - * + *按指定步长自增 * @example - * @return + *
+     * $redis = new Redis();
+     * $redis->connect('127.0.0.1');
+     * $redis->set('x', 3);
+     * var_dump( $redis->incrByFloat('x', 1.5) );   // float(4.5)
+     * // ! SIC
+     * var_dump( $redis->get('x') );                // string(3) "4.5"
+     * 
+ * @param string $key 键名 + * @param float $step 自增步长 + * @return float */ - public function incrby() + public function incrByFloat(string $key, float $step): float { + } /** * - * + *键值自减 * @example - * @return + *
+     * $redis->decr('key1'); // key1 didn't exists, set to 0 before the increment and now has the value -1
+     * $redis->decr('key1'); // -2
+     * $redis->decr('key1'); // -3
+     * 
+ * @param string $key 键名 + * @return int */ - public function decrby() + public function decr(string $key): int { + } /** * - * + *按指定步长自减 * @example - * @return + *
+     * $redis->decr('key1');        // key1 didn't exists, set to 0 before the increment and now has the value -1
+     * $redis->decr('key1');        // -2
+     * $redis->decr('key1');        // -3
+     * $redis->decrBy('key1', 10);  // -13
+     * 
+ * @param string $key 键名 + * @param float $step 自减步长 + * @return int */ - public function incrbyfloat() + public function decrBy(string $key, float $step): int { + } /** * - *Sets an expiration date (a timeout) on an item. + *设置键的有效期 * @example - *
-     * $redis->set('x', '42');
-     * $redis->setTimeout('x', 3);  // x will disappear in 3 seconds.
-     * sleep(5);                    // wait 5 seconds
-     * $redis->get('x');            // will return `FALSE`, as 'x' has expired.
-     * 
- * @return bool: + * @param string $key 键名 + * @param int $ttl 有效期(秒数) + * @return boolean */ - public function expire() + public function expire(string $key, int $ttl): boolean { + } /** * - * + *为某个键设置有效期为某个时间点 * @example - * @return + *
+     * $redis->set('x', '42');
+     * $now = time(NULL);               // current timestamp
+     * $redis->expireAt('x', $now + 3); // x will disappear in 3 seconds.
+     * sleep(5);                        // wait 5 seconds
+     * $redis->get('x');                // will return `FALSE`, as 'x' has expired.
+     * 
+ * @param string $key 键名 + * @param int $expireTime 到期时间 + * @return bool */ - public function pexpire() + public function expireAt(string $key, int $expireTime): bool { + } /** * - * + *设置键的有效期(毫秒为单位) * @example - * @return + * @param string $key 键名 + * @param int $ttl 有效期(毫秒数) + * @return boolean */ - public function expireat() + public function pexpire(string $key, int $ttl): boolean { + } /** * - * + *为某个键设置有效期为某个时间点(精确到毫秒) * @example - * @return + *
+     * $redis->set('x', '42');
+     * $now = time(NULL);               // current timestamp
+     * $redis->expireAt('x', $now + 3); // x will disappear in 3 seconds.
+     * sleep(5);                        // wait 5 seconds
+     * $redis->get('x');                // will return `FALSE`, as 'x' has expired.
+     * 
+ * @param string $key 键名 + * @param int $expireTime 到期时间 + * @return bool */ - public function pexpireat() + public function pexpireAt(string $key, int $expireTime): bool { + } /** * - *Append specified string to the string stored in specified key. + *将字符串追加到键值后(返回值的长度) * @example *
      * $redis->set('key', 'value1');
      * $redis->append('key', 'value2'); // 12
      * $redis->get('key');              // 'value1value2'
      * 
- * @return int: + * @param string $key 键名 + * @param string $value 追加的值 + * @return int */ - public function append() + public function append(string $key, string $value): int { + } /** * - * + *获取某个键的某个位置的位值 * @example - * @return + *
+     * $redis->set('key', "\x7f");  // this is 0111 1111
+     * $redis->getBit('key', 0);    // 0
+     * $redis->getBit('key', 1);    // 1
+     * 
+ * @param string $key 键名 + * @param int $offset 所在位置 + * @return int */ - public function getbit() + public function getBit(string $key, int $offset): int { + } /** * - * + *修改某个键的某个位置的位值 * @example - * @return + *
+     * $redis->set('key', "*");     // ord("*") = 42 = 0x2f = "0010 1010"
+     * $redis->setBit('key', 5, 1); // returns 0
+     * $redis->setBit('key', 7, 1); // returns 0
+     * $redis->get('key');          // chr(0x2f) = "/" = b("0010 1111")
+     * 
+ * @param string $key 键名 + * @param int $offset 开始位置 + * @param boolean|int $value 新值 + * @return int */ - public function setbit() + public function setBit(string $key, int $offset, int $value): int { + } /** * - * + *多个键的位操作,并将结果存入到指定的键中 * @example - * @return + * @param string $operation 操作(有 AND, OR, NOT, XOR 4种可选择) + * @param string $dstKey 目标键 + * @param string $key1 键名1 + * @param string $key2 键名2 + * @param string|... $keyN 键名N + * @return long */ - public function bitop() + public function bitop(string $operation, string $dstKey, string $key1, string $key2, string $keyN): long { + } /** * - * + *统计字符串的位数 * @example - * @return + * @param string $key 键名 + * @return long */ - public function bitpos() + public function bitcount(string $key): long { + } /** * - * + *获取指定位置的位值 * @example - * @return + *
+     * $redis->set('key', '\xff\xff');
+     * $redis->bitpos('key', 1); // int(0)
+     * $redis->bitpos('key', 1, 1); // int(8)
+     * $redis->bitpos('key', 1, 3); // int(-1)
+     * $redis->bitpos('key', 0); // int(16)
+     * $redis->bitpos('key', 0, 1); // int(16)
+     * $redis->bitpos('key', 0, 1, 5); // int(-1)
+     * 
+ * @param string $key 键名 + * @param int $bit 位值 + * @param int $start 开始位置 + * @param int $end 结束位置 + * @return callable */ - public function bitcount() + public function bitpos(string $key, int $bit, int $start, int $end): callable { + } /** * - * + *获取列表中指定索引的值 * @example - * @return + * @param string $key 键名 + * @param int $index 索引值 + * @return string | boolean */ - public function lget() + public function lget(string $key, int $index): ?string { + } /** * - * + *获取一个键值的子字符串 * @example - * @return + *
+     * $redis->set('key', 'string value');
+     * $redis->getRange('key', 0, 5);   // 'string'
+     * $redis->getRange('key', -5, -1); // 'value'
+     * 
+ * @param string $key 键名 + * @param int $start 开始位置 + * @param int $end 结束位置 + * @return string */ - public function getrange() + public function getrange(string $key, int $start, int $end): string { + } /** * - * + *删除指定范围外的其他元素 * @example - * @return + * @param string $key 键名 + * @param int $start 开始索引 + * @param int $end 结束索引 + * @return array | boolean */ - public function ltrim() + public function ltrim(string $key, int $start, int $end): ?array { + } /** * - * + *获取列表指定范围的值 * @example - * @return + * @param string $key 键名 + * @param int $start 索引开始值 + * @param int $end 索引结束值 + * @return array */ - public function lrange() + public function lrange(string $key, int $start, int $end): array { + } /** * - * + *根据排序范围删除成员 * @example - * @return + *
+     * $redis->zAdd('key', 1, 'one');
+     * $redis->zAdd('key', 2, 'two');
+     * $redis->zAdd('key', 3, 'three');
+     * $redis->zRemRangeByRank('key', 0, 1); // 2
+     * $redis->zRange('key', 0, -1, array('withscores' => TRUE)); // array('three' => 3)
+     * 
+ * @param string $key 集合键名 + * @param double $start 开始排序值 + * @param double $end 结束排序值 + * @return int */ - public function zremrangebyrank() + public function zremrangebyrank(string $key, double $start, double $end): int { + } /** * - *Publish messages to channels. Warning: this function will probably change in the future. + *将消息发布到消息通道(队列). * @example $redis->publish('chan-1', 'hello, world!'); // send message. + * @param string $channel 消息频道 + * @param string $message 消息 * @return int */ - public function publish() + public function publish(string $channel, string $message): int { + } /** * - *Renames a key. + *给键重命名 * @example - *
-     * $redis->set('x', '42');
-     * $redis->rename('x', 'y');
-     * $redis->get('y');   // �� 42
-     * $redis->get('x');   // �� `FALSE`
-     * 
- * @return bool: + * @param string $srcKey 旧键名 + * @param string $dstKey 新键名 + * @return boolean */ - public function rename() + public function rename(string $srcKey, string $dstKey): boolean { + } /** * - * + *当目标键名不存在时,给键重命名 * @example - * @return + * @param string $srcKey 旧键名 + * @param string $dstKey 新键名 + * @return boolean */ - public function renamenx() + public function renamenx(string $srcKey, string $dstKey): boolean { + } /** * - * + *将所有元素参数添加到 HyperLogLog 数据结构中 * @example + * @param string $key 键名 + * @param string|array|... $element 元素 * @return */ - public function pfcount() + public function pfadd(string $key, string $element) { + } /** * - * + *返回给定 HyperLogLog 的基数估算值 * @example + * @param string|array $keys 键名 * @return */ - public function pfadd() + public function pfcount(string $keys) { + } /** * - * + *将多个 HyperLogLog 合并为一个 HyperLogLog ,合并后的 HyperLogLog 的基数估算值是通过对所有 给定 HyperLogLog 进行并集计算得出的 * @example + * @param string|array $dstKey 目标键名 + * @param string|array $sourceKeys 源键名 * @return */ - public function pfmerge() + public function pfmerge(string $dstKey, string $sourceKeys) { + } /** * - * + *修改某个键的某个位置的值 * @example - * @return + *
+     * $redis->set('key', 'Hello world');
+     * $redis->setRange('key', 6, "redis"); // returns 11
+     * $redis->get('key');                  // "Hello redis"
+     * 
+ * @param string $key 键名 + * @param int $offset 开始位置 + * @param string $value 被替换的子串的值 + * @return string */ - public function setrange() + public function setrange(string $key, int $offset, string $value): string { + } /** * - *Restore a key from the result of a DUMP operation. + *将dump导出的二进制数据恢复到可读的字符串. * @example *
      * $redis->set('foo', 'bar');
      * $val = $redis->dump('foo');
      * $redis->restore('bar', 0, $val); // The key 'bar', will now be equal to the key 'foo'
      * 
+ * @param string $key 键名 + * @param int $ttl 有效期 + * @param string $value dump导出的二进制数据 * @return */ - public function restore() + public function restore(string $key, int $ttl, string $value) { + } /** * - * + *将某个集合中的元素移动到另外一个集合中 * @example - * @return + *
+     * $redis->sAdd('key1' , 'set11');
+     * $redis->sAdd('key1' , 'set12');
+     * $redis->sAdd('key1' , 'set13');          // 'key1' => {'set11', 'set12', 'set13'}
+     * $redis->sAdd('key2' , 'set21');
+     * $redis->sAdd('key2' , 'set22');          // 'key2' => {'set21', 'set22'}
+     * $redis->sMove('key1', 'key2', 'set13');  // 'key1' =>  {'set11', 'set12'}
+     * // 'key2' =>  {'set21', 'set22', 'set13'}
+     * 
+ * @param string $srcKey 原集合键名 + * @param string $dstKey 目标集合键名 + * @param string $member 成员 + * @return bool */ - public function smove() + public function smove(string $srcKey, string $dstKey, string $member): bool { + } /** * - * + *获取有序集合中指定范围的成员 * @example - * @return + *
+     * $redis->zAdd('key1', 0, 'val0');
+     * $redis->zAdd('key1', 2, 'val2');
+     * $redis->zAdd('key1', 10, 'val10');
+     * $redis->zRange('key1', 0, -1); // array('val0', 'val2', 'val10')
+     * // with scores
+     * $redis->zRange('key1', 0, -1, true); // array('val0' => 0, 'val2' => 2, 'val10' => 10)
+     * 
+ * @param string $key 集合键名 + * @param long $start 索引开始值 + * @param long $end 索引结束值 + * @param boolean $withScores 是否返回成员的排序值 + * @return array */ - public function zrange() + public function zRange(string $key, int $start, int $end, bool $withScores): array { + } /** * - * + *获取有序集合中指定范围的成员(倒序排列) * @example - * @return + *
+     * $redis->zAdd('key', 0, 'val0');
+     * $redis->zAdd('key', 2, 'val2');
+     * $redis->zAdd('key', 10, 'val10');
+     * $redis->zRevRange('key', 0, -1); // array('val10', 'val2', 'val0')
+     * // with scores
+     * $redis->zRevRange('key', 0, -1, true); // array('val10' => 10, 'val2' => 2, 'val0' => 0)
+     * 
+ * @param string $key 集合键名 + * @param long $start 索引开始值 + * @param long $end 索引结束值 + * @param boolean $withScores 是否返回成员的排序值 + * @return array */ - public function zrevrange() + public function zRevRange(string $key, int $start, int $end, bool $withScores): array { + } /** * - * + *获取有序集合中指定范围的成员(按排序值排列) * @example - * @return + *
+     * $redis->zAdd('key', 0, 'val0');
+     * $redis->zAdd('key', 2, 'val2');
+     * $redis->zAdd('key', 10, 'val10');
+     * $redis->zRangeByScore('key', 0, 3);                                          // array('val0', 'val2')
+     * $redis->zRangeByScore('key', 0, 3, array('withscores' => TRUE);              // array('val0' => 0, 'val2' => 2)
+     * $redis->zRangeByScore('key', 0, 3, array('limit' => array(1, 1));                        // array('val2' => 2)
+     * $redis->zRangeByScore('key', 0, 3, array('limit' => array(1, 1));                        // array('val2')
+     * $redis->zRangeByScore('key', 0, 3, array('withscores' => TRUE, 'limit' => array(1, 1));  // array('val2' => 2)
+     * 
+ * @param string $key 集合键名 + * @param long $start 索引开始值 + * @param long $end 索引结束值 + * @param array $options 附加选项(可以是:withscores => TRUE, and limit => array($offset, $count)) + * @return array */ - public function zrangebyscore() + public function zRangeByScore(string $key, int $start, int $end, Array $options): array { + } /** * - * + *获取有序集合中指定范围的成员(按排序值倒序排列) * @example - * @return + *
+     * $redis->zAdd('key', 0, 'val0');
+     * $redis->zAdd('key', 2, 'val2');
+     * $redis->zAdd('key', 10, 'val10');
+     * $redis->zRangeByScore('key', 0, 3);                                          // array('val0', 'val2')
+     * $redis->zRangeByScore('key', 0, 3, array('withscores' => TRUE);              // array('val0' => 0, 'val2' => 2)
+     * $redis->zRangeByScore('key', 0, 3, array('limit' => array(1, 1));                        // array('val2' => 2)
+     * $redis->zRangeByScore('key', 0, 3, array('limit' => array(1, 1));                        // array('val2')
+     * $redis->zRangeByScore('key', 0, 3, array('withscores' => TRUE, 'limit' => array(1, 1));  // array('val2' => 2)
+     * 
+ * @param string $key 集合键名 + * @param long $start 索引开始值 + * @param long $end 索引结束值 + * @param array $options 附加选项(可以是:withscores => TRUE, and limit => array($offset, $count)) + * @return array */ - public function zrevrangebyscore() + public function zRevRangeByScore(string $key, int $start, int $end, Array $options): array { + } /** * - * + *按字母字典的顺序返回成员 * @example - * @return + *
+     * foreach (array('a', 'b', 'c', 'd', 'e', 'f', 'g') as $char) {
+     * $redis->zAdd('key', $char);
+     * }
+     * $redis->zRangeByLex('key', '-', '[c'); // array('a', 'b', 'c')
+     * $redis->zRangeByLex('key', '-', '(c'); // array('a', 'b')
+     * $redis->zRangeByLex('key', '-', '[c'); // array('b', 'c')
+     * 
+ * @param string $key 集合键名 + * @param long $min 最小的字母 + * @param long $max 最大的字母 + * @param long $offset 索引开始值 + * @param long $limit 成员数 + * @return array */ - public function zrangebylex() + public function zRangeByLex(string $key, int $min, int $max, int $offset, int $limit): array { + } /** * - * + *按字母字典的顺序返回成员(倒序排序) * @example + * @param string $key 集合键名 + * @param long $min 最小的字母 + * @param long $max 最大的字母 + * @param long $offset 索引开始值 + * @param long $limit 成员数 * @return */ - public function zrevrangebylex() + public function zRevRangeByLex(string $key, int $min, int $max, int $offset, int $limit) { + } /** * - * + *获取指定字母范围的成员数 * @example - * @return + * @param string $key 集合键名 + * @param long $min 最小的字母 + * @param long $max 最大的字母 + * @return int */ - public function zlexcount() + public function zlexcount(string $key, int $min, int $max): int { + } /** * - * + *删除指定字母范围的成员 * @example - * @return + * @param string $key 集合键名 + * @param long $min 最小的字母 + * @param long $max 最大的字母 + * @return long */ - public function zremrangebylex() + public function zremrangebylex(string $key, int $min, int $max): long { + } /** * - * + *将两个有序集合的并集存入到一个指定的键中 * @example - * @return + *
+     * $redis->delete('k1');
+     * $redis->delete('k2');
+     * $redis->delete('k3');
+     * $redis->delete('ko1');
+     * $redis->delete('ko2');
+     * $redis->delete('ko3');
+     * $redis->zAdd('k1', 0, 'val0');
+     * $redis->zAdd('k1', 1, 'val1');
+     * $redis->zAdd('k2', 2, 'val2');
+     * $redis->zAdd('k2', 3, 'val3');
+     * $redis->zUnion('ko1', array('k1', 'k2')); // 4, 'ko1' => array('val0', 'val1', 'val2', 'val3')
+     * // Weighted zUnion
+     * $redis->zUnion('ko2', array('k1', 'k2'), array(1, 1)); // 4, 'ko2' => array('val0', 'val1', 'val2', 'val3')
+     * $redis->zUnion('ko3', array('k1', 'k2'), array(5, 1)); // 4, 'ko3' => array('val0', 'val2', 'val3', 'val1')
+     * 
+ * @param string $dstKey 目标集合键名 + * @param array $zsetKeys 集合键名 + * @param array $zsetKeysWeight 集合键对应的权重 + * @param string $aggregateFunction 合并使用的函数(SUM, MIN, 或 MAX) + * @return int */ - public function zunionstore() + public function zunionstore(string $dstKey, Array $zsetKeys, Array $zsetKeysWeight, string $aggregateFunction): int { + } /** * - * + *将两个有序集合的交集存入到一个指定的键中 * @example - * @return + *
+     * $redis->delete('k1');
+     * $redis->delete('k2');
+     * $redis->delete('k3');
+     * $redis->delete('ko1');
+     * $redis->delete('ko2');
+     * $redis->delete('ko3');
+     * $redis->delete('ko4');
+     * $redis->zAdd('k1', 0, 'val0');
+     * $redis->zAdd('k1', 1, 'val1');
+     * $redis->zAdd('k1', 3, 'val3');
+     * $redis->zAdd('k2', 2, 'val1');
+     * $redis->zAdd('k2', 3, 'val3');
+     * $redis->zInter('ko1', array('k1', 'k2'));               // 2, 'ko1' => array('val1', 'val3')
+     * $redis->zInter('ko2', array('k1', 'k2'), array(1, 1));  // 2, 'ko2' => array('val1', 'val3')
+     * // Weighted zInter
+     * $redis->zInter('ko3', array('k1', 'k2'), array(1, 5), 'min'); // 2, 'ko3' => array('val1', 'val3')
+     * $redis->zInter('ko4', array('k1', 'k2'), array(1, 5), 'max'); // 2, 'ko4' => array('val3', 'val1')
+     * 
+ * @param string $dstKey 目标集合键名 + * @param array $zsetKeys 集合键名 + * @param array $zsetKeysWeight 集合键对应的权重 + * @param string $aggregateFunction 合并使用的函数(SUM, MIN, 或 MAX) + * @return int */ - public function zinterstore() + public function zinterstore(string $dstKey, Array $zsetKeys, Array $zsetKeysWeight, string $aggregateFunction): int { + } /** * - * + *删除有序集合中的某个成员 * @example - * @return + * @param string $key 集合键名 + * @param string $member 成员值 + * @return int */ - public function zrem() + public function zrem(string $key, string $member): int { + } /** * - *Sort + *给列表、集合或有序集合的元素排序 * @example *
      * $redis->delete('s');
@@ -1351,35 +2334,36 @@ public function zrem()
      * var_dump($redis->sort('s', array('sort' => 'desc'))); // 5,4,3,2,1
      * var_dump($redis->sort('s', array('sort' => 'desc', 'store' => 'out'))); // (int)5
      * 
+ * @param string $key 键名 + * @param array $options 排序参数,如:array('sort' => 'desc') * @return An */ - public function sort() + public function sort(string $key, Array $options): An { + } /** * - *Describes the object pointed to by a key. - *The information to retrieve (string) and the key (string). - *Info can be one of the following: - *- "encoding" - *- "refcount" - *- "idletime" + *获取某个键的对象信息 * @example *
-     * $redis->object("encoding", "l"); // �� ziplist
-     * $redis->object("refcount", "l"); // �� 1
-     * $redis->object("idletime", "l"); // �� 400 (in seconds, with a precision of 10 seconds).
+     * $redis->object("encoding", "l"); // → ziplist
+     * $redis->object("refcount", "l"); // → 1
+     * $redis->object("idletime", "l"); // → 400 (in seconds, with a precision of 10 seconds).
      * 
+ * @param string $info 获取的信息指标名称(有 encoding、refcount 、idletime 3种可选择) + * @param string $key 键名 * @return string */ - public function object() + public function object(string $info, string $key): string { + } /** * - *Subscribe to channels. Warning: this function will probably change in the future. + *订阅消息 * @example *
      * function f($redis, $chan, $msg) {
@@ -1397,15 +2381,19 @@ public function object()
      * }
      * $redis->subscribe(array('chan-1', 'chan-2', 'chan-3'), 'f'); // subscribe to 3 chans
      * 
- * @return + * @param array $channels 订阅的消息频道 + * @param string|array $callback 回调函数名称 + * @param mixed $value 返回值 + * @return mixed */ - public function subscribe() + public function subscribe(Array $channels, string $callback, $value) { + } /** * - *Subscribe to channels by pattern + *通过匹配模式来订阅这些匹配的消息频道 * @example *
      * function psubscribe($redis, $pattern, $chan, $msg) {
@@ -1414,232 +2402,296 @@ public function subscribe()
      * echo "Payload: $msg\n";
      * }
      * 
+ * @param array $patterns 匹配模式 + * @param string|array $callback 回调函数名称 + * @param mixed $value 返回值 * @return */ - public function psubscribe() + public function psubscribe(Array $patterns, string $callback, $value) { + } /** * - * + *取消订阅 * @example + * @param array $channels 订阅的消息频道 * @return */ - public function unsubscribe() + public function unsubscribe(Array $channels) { + } /** * - * + *通过匹配模式来取消订阅这些匹配的消息频道 * @example + * @param array $patterns 匹配模式 * @return */ - public function punsubscribe() + public function punsubscribe(Array $patterns) { + } /** * - *Evaluate a LUA script serverside + *执行lua脚本 * @example - *
-     * $redis->eval("return 1"); // Returns an integer: 1
-     * $redis->eval("return {1,2,3}"); // Returns Array(1,2,3)
-     * $redis->del('mylist');
-     * $redis->rpush('mylist','a');
-     * $redis->rpush('mylist','b');
-     * $redis->rpush('mylist','c');
-     * // Nested response:  Array(1,2,3,Array('a','b','c'));
-     * $redis->eval("return {1,2,3,redis.call('lrange','mylist',0,-1)}}");
-     * 
- * @return message + * @param string $script 脚本 + * @param array $args 脚本参数 + * @param int $num_keys 应该进入KEYS数组的参数个数 + * @return mixed */ - public function eval() + public function eval(string $script, Array $args, int $num_keys) { + } /** * - * - * @example + *从脚本的SHA1散列而不是脚本本身执行LUA脚本 + * @example $script = 'return 1'; + * $sha = $redis->script('load', $script); + * $redis->evalSha($sha); // Returns 1 + * @param string $script_sha 脚本的散列值 + * @param array $args 脚本参数 + * @param int $num_keys 应该进入KEYS数组的参数个数 * @return */ - public function evalsha() + public function evalsha(string $script_sha, Array $args, int $num_keys) { + } /** * - *Scan the keyspace for keys. + *扫描键空间. * @example - * @param mixed $i_iterator - * @param mixed $str_node - * @param mixed $str_pattern - * @param mixed $i_count - * @return array|bool + *
+     * $iterator = null;
+     * while($keys = $redis->scan($iterator)) {
+     * foreach($keys as $key) {
+     * echo $key . PHP_EOL;
+     * }
+     * }
+     * 
+ * @param Long|NULL $i_iterator 迭代器 + * @param string $str_pattern 匹配的模式 + * @param int $i_count 每次迭代的长度 + * @return array */ - public function scan($i_iterator, $str_node, $str_pattern, $i_count) + public function scan(Long $i_iterator, string $str_pattern, int $i_count): array { + } /** * - * + *扫描hash的键 * @example - * @param mixed $str_key - * @param mixed $i_iterator - * @param mixed $str_pattern - * @param mixed $i_count + * @param string $str_key 键值 + * @param Long|NULL $i_iterator 迭代器 + * @param string $str_pattern 匹配的模式 + * @param int $i_count 每次迭代的长度 * @return */ - public function sscan($str_key, $i_iterator, $str_pattern, $i_count) + public function hscan(string $str_key, Long $i_iterator, string $str_pattern, int $i_count) { + } /** * - * + *扫描有序集合的键 * @example - * @param mixed $str_key - * @param mixed $i_iterator - * @param mixed $str_pattern - * @param mixed $i_count + * @param string $str_key 键值 + * @param Long|NULL $i_iterator 迭代器 + * @param string $str_pattern 匹配的模式 + * @param int $i_count 每次迭代的长度 * @return */ - public function zscan($str_key, $i_iterator, $str_pattern, $i_count) + public function zscan(string $str_key, Long $i_iterator, string $str_pattern, int $i_count) { + } /** * - * + *扫描集合的键 * @example - * @param mixed $str_key - * @param mixed $i_iterator - * @param mixed $str_pattern - * @param mixed $i_count + * @param string $str_key 键值 + * @param Long|NULL $i_iterator 迭代器 + * @param string $str_pattern 匹配的模式 + * @param int $i_count 每次迭代的长度 * @return */ - public function hscan($str_key, $i_iterator, $str_pattern, $i_count) + public function sscan(string $str_key, Long $i_iterator, string $str_pattern, int $i_count) { + } /** * - * - * @example - * @return + *获取运行模式,如 ATOMIC/MULTI/PIPELINE + * @example $redis->getMode(); + * @return int */ - public function getmode() + public function getmode(): int { + } /** * - * + *获取上次错误信息 * @example - * @return + *
+     * $redis->eval('this-is-not-lua');
+     * $err = $redis->getLastError();
+     * // "ERR Error compiling script (new function): user_script:1: '=' expected near '-'"
+     * 
+ * @return string */ - public function getlasterror() + public function getLastError(): string { + } /** * - * + *清除上次错误信息 * @example - * @return + *
+     * $redis->set('x', 'a');
+     * $redis->incr('x');
+     * $err = $redis->getLastError();
+     * // "ERR value is not an integer or out of range"
+     * $redis->clearLastError();
+     * $err = $redis->getLastError();
+     * // NULL
+     * 
+ * @return bool */ - public function clearlasterror() + public function clearLastError(): bool { + } /** * - * + *获取客户端选项 * @example - * @return + * // return Redis::SERIALIZER_NONE, Redis::SERIALIZER_PHP, or Redis::SERIALIZER_IGBINARY. + * $redis->getOption(Redis::OPT_SERIALIZER); + * @param string $optionName 选项名 + * @return int */ - public function getoption() + public function getOption(string $optionName): int { + } /** * - * + *设置客户端选项. * @example - * @return + *
+     * $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_NONE);        // don't serialize data
+     * $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);         // use built-in serialize/unserialize
+     * $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_IGBINARY);    // use igBinary serialize/unserialize
+     * $redis->setOption(Redis::OPT_PREFIX, 'myAppName:');                      // use custom prefix on all keys
+     * 
+ * @param string $optionName 选项名 + * @param string $optionValue 选项值 + * @return bool */ - public function setoption() + public function setOption(string $optionName, string $optionValue): bool { + } /** * - *A utility method to prefix the value with the prefix setting for phpredis. + *设置键前缀 * @example *
      * $redis->setOption(Redis::OPT_PREFIX, 'my-prefix:');
      * $redis->_prefix('my-value'); // Will return 'my-prefix:my-value'
      * 
+ * @param string $prefix 前缀 * @return string */ - public function _prefix() + public function _prefix(string $prefix): string { + } /** * - * + *用于手动序列化. * @example + *
+     * $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_NONE);
+     * $redis->_serialize("foo"); // returns "foo"
+     * $redis->_serialize(Array()); // Returns "Array"
+     * $redis->_serialize(new stdClass()); // Returns "Object"
+     * $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);
+     * $redis->_serialize("foo"); // Returns 's:3:"foo";'
+     * 
+ * @param string $value 被序列化的值 * @return */ - public function _serialize() + public function _serialize(string $value) { + } /** * - *A utility method to unserialize data with whatever serializer is set up. If there is no serializer set, the - *value will be returned unchanged. If there is a serializer set up, and the data passed in is malformed, an - *exception will be thrown. This can be useful if phpredis is serializing values, and you return something from - *redis in a LUA script that is serialized. + *反序列化方法. * @example *
      * $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);
      * $redis->_unserialize('a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}'); // Will return Array(1,2,3)
      * 
+ * @param string $value 被反序列化的值 * @return */ - public function _unserialize() + public function _unserialize(string $value) { + } /** * - * - * @example - * @return + *获取集群中的主服务器列表 + * @example foreach ($obj_cluster->_masters() as $arr_master) { + * $obj_cluster->echo($arr_master, "Hello: " . implode(':', $arr_master)); + * } + * @return array */ - public function _masters() + public function _masters(): array { + } /** * - * + *获取跳转的地址,格式为:host:port * @example - * @return + * @return string|NULL */ - public function _redir() + public function _redir(): ?string { + } /** * - *Enter and exit transactional mode. + *开始一个事务. * @example *
      * $ret = $redis->multi()
@@ -1654,36 +2706,38 @@ public function _redir()
      * //    2 => TRUE,
      * //    3 => 'val2');
      * 
- * @return Once + * @return */ public function multi() { + } /** * - * + *取消事务 * @example * @return */ - public function exec() + public function discard() { + } /** * - * + *执行事务 * @example * @return */ - public function discard() + public function exec() { + } /** * - *Watches a key for modifications by another client. If the key is modified between WATCH and EXEC, - *the MULTI/EXEC transaction will fail (return FALSE). unwatch cancels all the watching of all keys by this client. + *观察某个键在其他客户端的变化情况. * @example *
      * $redis->watch('x');
@@ -1693,95 +2747,110 @@ public function discard()
      * ->exec();
      * // $ret = FALSE if x has been modified between the call to WATCH and the call to EXEC.
      * 
+ * @param string|array $keys 键名 * @return */ - public function watch() + public function watch(string $keys) { + } /** * - * + *取消观察某个键在其他客户端的变化情况 * @example + * @param string|array $keys 键名 * @return */ - public function unwatch() + public function unwatch(string $keys) { + } /** * - *Performs a synchronous save. + *将数据同步到硬盘上 * @example $redis->save(); - * @return If + * @return boolean */ - public function save() + public function save(): boolean { + } /** * - *Performs a background save. - * @example $redis->bgSave(); - * @return If + *将数据存入到硬盘上(异步操作) + * @example + * @return */ - public function bgsave() + public function bgSave() { + } /** * - * - * @example - * @return + *删除当前数据库的所有键 + * @example $redis->flushDB(); + * @return bool */ - public function flushdb() + public function flushdb(): bool { + } /** * - * - * @example - * @return + *删除当前实例的所有键 + * @example $redis->flushAll(); + * @return bool */ - public function flushall() + public function flushall(): bool { + } /** * - * + *获取当前数据库的键的个数 * @example - * @return + *
+     * $count = $redis->dbSize();
+     * echo "Redis has $count keys\n";
+     * 
+ * @return int */ - public function dbsize() + public function dbsize(): int { + } /** * - *Starts the background rewrite of AOF (Append-Only File) + *开启后台写AOF日志操作 * @example $redis->bgrewriteaof(); - * @return bool: + * @return bool */ - public function bgrewriteaof() + public function bgrewriteaof(): bool { + } /** * - * - * @example - * @return + *获取上次数据同步到硬盘的时间 + * @example $redis->lastSave(); + * @return int */ - public function lastsave() + public function lastsave(): int { + } /** * - *Returns an associative array of strings and integers + *获取Redis服务器的信息和统计数据 * @example *
      * $redis->info();
@@ -1789,132 +2858,173 @@ public function lastsave()
      * $redis->info("COMMANDSTATS"); //Information on the commands that have been run (>=2.6 only)
      * $redis->info("CPU"); // just CPU information from Redis INFO
      * 
- * @return + * @return array */ - public function info() + public function info(): array { + } /** * - *Provide information on the role of a Redis instance in the context of replication, by returning if the instance is currently a master, slave, or sentinel. + *返回当前连接的服务器的角色,如master、alone、slave、sentinel * @example - *
-     * $role = $redis->role();
-     * 
- * @return string: + * @return string */ - public function role() + public function role(): string { + } /** * - *Return the current Redis server time. + *返回当前redis服务器时间. * @example - * @return unix + *
+     * var_dump( $redis->time() );
+     * // array(2) {
+     * //   [0] => string(10) "1342364352"
+     * //   [1] => string(6) "253002"
+     * // }
+     * 
+ * @return int */ - public function time() + public function time(): int { + } /** * - * + *返回一个随机的键 * @example - * @return + *
+     * $key = $redis->randomKey();
+     * $surprise = $redis->get($key);  // who knows what's in there.
+     * 
+ * @return string */ - public function randomkey() + public function randomkey(): string { + } /** * - *Check the current connection status + *检查当前redis连接状态(成功时返回PONG) * @example * @return string */ - public function ping() + public function ping(): string { + } /** * - *echo string $string Sends a string to Redis, which replies with the same string - * @example $redis->echo('eeee'); - * @return + *向redis发送一个字符串,而且redis服务器将返回一个相同的字符串 + * @example + * @param string $str 发送的字符串 + * @return string */ - public function echo() + public function echo(string $str): string { + } /** * - * + *获取所有命令列表 * @example - * @return + * @return array */ - public function command() + public function command(): array { + } /** * - * + *在redis服务器上执行命令 * @example + * @param string $command 执行的命令 + * @param string|array $args 参数 * @return */ - public function rawcommand() + public function rawcommand(string $command, string $args) { + } /** * - * + *获取集群节点信息 * @example - * @return + * @param string $args 参数(目前只支持slots) + * @return array */ - public function cluster() + public function cluster(string $args): array { + } /** * - *Issue the CLIENT command with various arguments. + *获取客户端相关参数或进行相关操作 * @example + * @param string $command 命令(CLIENT LIST +CLIENT GETNAME +CLIENT SETNAME [name] +CLIENT KILL [ip:port] +) + * @param string $args 参数 * @return */ - public function client() + public function client(string $command, string $args) { + } /** * - *Get or Set the redis config keys. + *获取或设置配置项. * @example *
      * $redis->config("GET", "*max-*-entries*");
      * $redis->config("SET", "dir", "/var/run/redis/dumps/");
      * 
+ * @param string $operation 操作(SET或GET) + * @param string $key 配置项或配置项匹配模式 + * @param string $value 配置值 * @return array */ - public function config() + public function config(string $operation, string $key, string $value): array { + } /** * - * + *查看订阅与发布系统状态,它由数个不同格式的子命令组成. * @example - * @return + *
+     * $redis->pubsub('channels'); // All channels
+     * $redis->pubsub('channels', '*pattern*'); // Just channels matching your pattern
+     * $redis->pubsub('numsub', array('chan1', 'chan2')); // Get subscriber counts for 'chan1' and 'chan2'
+     * $redis->pubsub('numpat'); // Get the number of pattern subscribers
+     * 
+ * @param string $subcommand 子命令(可以是channels, numsub, numpat) + * @param string|array $args 参数 + * @return array|int */ - public function pubsub() + public function pubsub(string $subcommand, string $args): ?array { + } /** * - *Execute the Redis SCRIPT command to perform various operations on the scripting subsystem. + *在脚本子系统上执行redis命令 * @example *
      * $redis->script('load', $script);
@@ -1926,20 +3036,26 @@ public function pubsub()
      * SCRIPT FLUSH should always return TRUE
      * SCRIPT KILL will return true if a script was able to be killed and false if not
      * SCRIPT EXISTS will return an array with TRUE or FALSE for each passed script
+     * @param string $command redis命令
+     * @param string|... $script 脚本
      * @return 
      */
-    public function script()
+    public function script(string $command, string $script)
     {
+    
     }
 
     /**
      * 
-     *Access the Redis slow log.
+     *获取慢操作日志
      * @example 
+     * @param string $command 执行的命令
+     * @param int $length 获取条目数
      * @return 
      */
-    public function slowlog()
+    public function slowlog(string $command, int $length)
     {
+    
     }
 
 }
diff --git a/src/Redis/RedisClusterException.php b/src/Redis/RedisClusterException.php
index e16c779..38d1abd 100644
--- a/src/Redis/RedisClusterException.php
+++ b/src/Redis/RedisClusterException.php
@@ -1,150 +1,165 @@
 start前创建;在swoole_process中使用原子计数器,必须在swoole_process->start前创建)
+     *初始化一个计数器对象
      * @example 
-     * @param int $value 创建一个原子计数对象(只能操作32位整数,最大支持42亿.在swoole_server中使用原子计数器,必须在swoole_server->start前创建;在swoole_process中使用原子计数器,必须在swoole_process->start前创建)
+     * @param int $value 初始值
      * @return 
      */
-    public function __construct($value)
+    public function __construct(int $value)
     {
+    
     }
 
     /**
      * 
      *增加计数
      * @example 
-     * @param int $add_value 增加计数
+     * @param int $add_value 要增加的数值,默认为1,必须为正整数
      * @return 
      */
-    public function add($add_value)
+    public function add(int $add_value)
     {
+    
     }
 
     /**
      * 
      *减少计数
      * @example 
-     * @param int $sub_value 减少计数
+     * @param int $sub_value 要减少的数值,默认为1
      * @return 
      */
-    public function sub($sub_value)
+    public function sub(int $sub_value)
     {
+    
     }
 
     /**
@@ -52,29 +55,78 @@ public function sub($sub_value)
      */
     public function get()
     {
+    
     }
 
     /**
      * 
      *将当前值设置为指定的数字
      * @example 
-     * @param int $value 将当前值设置为指定的数字
+     * @param int $value 指定要设置的目标数值
      * @return 
      */
-    public function set($value)
+    public function set(int $value)
     {
+    
     }
 
     /**
      * 
-     *如果当前数值等于参数1,则将当前数值设置为参数2($cmp_value,$set_value 必须为小于42亿的整数)
+     *当原子计数的值为0时程序进入等待状态。另外一个进程调用wakeup可以再次唤醒程序。底层基于Linux Futex实现,使用此特性,可以仅用4字节内存实现一个等待、通知、锁的功能
      * @example 
-     * @param int $cmp_value 如果当前数值等于参数1,则将当前数值设置为参数2($cmp_value,$set_value 必须为小于42亿的整数)
-     * @param int $new_value 如果当前数值等于参数1,则将当前数值设置为参数2($cmp_value,$set_value 必须为小于42亿的整数)
+     * @param float $timeout 指定超时时间,默认为-1,表示永不超时,会持续等待直到有其他进程唤醒;超时返回false,错误码为EAGAIN,可使用swoole_errno函数获取;成功返回true,表示有其他进程通过wakeup成功唤醒了当前的锁;使用wait/wakeup特性时,原子计数的值只能为0或1,否则会导致无法正常使用;当然原子计数的值为1时,表示不需要进入等待状态,资源当前就是可用。wait函数会立即返回true
      * @return 
      */
-    public function cmpset($cmp_value, $new_value)
+    public function wait(float $timeout)
     {
+    
+    }
+
+    /**
+     * 
+     *唤醒处于wait状态的其他进程
+     * @example 
+     * @param int $count 计数(当前原子计数如果为0时,表示没有进程正在wait,wakeup会立即返回true;当前原子计数如果为1时,表示当前有进程正在wait,wakeup会唤醒等待的进程,并返回true;如果同时有多个进程处于wait状态,$n参数可以控制唤醒的进程数量;被唤醒的进程返回后,会将原子计数设置为0,这时可以再次调用wakeup唤醒其他正在wait的进程)
+     * @return 
+     */
+    public function wakeup(int $count)
+    {
+    
+    }
+
+    /**
+     * 
+     *如果当前计数器的值与比较的值的相等,则设置它为新的值
+     * @example 
+     * @param int $cmp_value 用于比较的值
+     * @param int $new_value 用于设置的新值
+     * @return 
+     */
+    public function cmpset(int $cmp_value, int $new_value)
+    {
+    
+    }
+
+    /**
+     * 
+     *序列化函数调用的魔术方法(在PHP进行序列化时,serialize() 检查类中是否有 __sleep() ,如果有,则该函数将在任何序列化之前运行。该函数必须返回一个需要进行序列化保存的成员属性数组,并且只序列化该函数返回的这些成员属性. 该函数有两个作用: 第一. 在序列化之前,关闭对象可能具有的任何数据库连接等. 第二. 指定对象中需要被序列化的成员属性,如果某个属性比较大而不需要储存下来,可以不把它写进__sleep要返回的数组中,这样该属性就不会被序列化)
+     * @example 
+     * @return 
+     */
+    public function __sleep()
+    {
+    
+    }
+
+    /**
+     * 
+     *反序列化函数调用的魔术方法(unserialize() 从字节流中创建了一个对象之后,马上检查是否具有__wakeup 的函数的存在。如果存在,__wakeup 立刻被调用。使用 __wakeup 的目的是重建在序列化中可能丢失的任何数据库连接以及处理其它重新初始化的任务)
+     * @example 
+     * @return 
+     */
+    public function __wakeup()
+    {
+    
     }
 
 }
diff --git a/src/Swoole/Atomic/Long.php b/src/Swoole/Atomic/Long.php
new file mode 100644
index 0000000..e8ad5bf
--- /dev/null
+++ b/src/Swoole/Atomic/Long.php
@@ -0,0 +1,109 @@
+0,
+            'queue_bytes'=>0
+        ];
     }
 
 }
diff --git a/src/Swoole/Client.php b/src/Swoole/Client.php
index 3c47cef..a2dd801 100644
--- a/src/Swoole/Client.php
+++ b/src/Swoole/Client.php
@@ -1,12 +1,12 @@
 recv方法的第二个参数,阻塞等待直到收到指定长度的数据后返回
+    *阻塞等待直到收到指定长度的数据后返回
     */
     const MSG_WAITALL    =    256;
 
+    /**     
+    *读写被关闭
+    */
+    const SHUT_RDWR    =    2;
+
+    /**     
+    *读被关闭
+    */
+    const SHUT_RD    =    0;
+
+    /**     
+    *写被关闭
+    */
+    const SHUT_WR    =    1;
+
     /**
      * @var int $errCode 
-     * 错误码。errCode的值等于Linux errno。可使用socket_strerror将错误码转为错误信息
+     * 错误码
      * @access public
      */
     public $errCode    =    0;
 
     /**
      * @var int $sock 
-     * sock属性是此socket的文件描述符
+     * 此socket的文件描述符
      * @access public
      */
     public $sock    =    0;
 
     /**
-     * @var bool $reuse 
-     * 表示此连接是新创建的还是复用已存在的。与SWOOLE_KEEP配合使用
+     * @var boolean $reuse 
+     * 表示此连接是新创建的还是复用已存在的
      * @access public
      */
     public $reuse    =    '';
 
     /**
      * @var int $reuseCount 
-     * 
+     * 表示此连接复用次数
      * @access public
      */
     public $reuseCount    =    0;
 
+    /**
+     * @var int $type 
+     * 连接的类型
+     * @access public
+     */
+    public $type    =    0;
+
+    /**
+     * @var int $id 
+     * 客户端连接ID
+     * @access public
+     */
+    public $id;
+
+    /**
+     * @var array $setting 
+     * 配置选项
+     * @access public
+     */
+    public $setting    =    array();
+
+    /**
+     * @var callable $onConnect 
+     * 连接的回调函数
+     * @access private
+     */
+    private $onConnect;
+
+    /**
+     * @var callable $onError 
+     * 发生错误时的回调函数
+     * @access private
+     */
+    private $onError;
+
+    /**
+     * @var callable $onReceive 
+     * 客户端收到来自于服务器端的数据时会回调此函数
+     * @access private
+     */
+    private $onReceive;
+
+    /**
+     * @var callable $onClose 
+     * 连接被关闭时回调此函数
+     * @access private
+     */
+    private $onClose;
+
+    /**
+     * @var callable $onBufferFull 
+     * 当缓存区达到最高水位时触发此事件
+     * @access private
+     */
+    private $onBufferFull;
+
+    /**
+     * @var callable $onBufferEmpty 
+     * 当缓存区低于最低水位线时触发此事件
+     * @access private
+     */
+    private $onBufferEmpty;
+
+    /**
+     * @var callable $onSSLReady 
+     * 当SSL连接就绪时的回调函数
+     * @access private
+     */
+    private $onSSLReady;
+
     /**
      * 
-     *创建tcp/udp客户端
+     *创建tcp客户端对象
      * @example 
-     * @param int $type 创建tcp/udp客户端
-     * @param int $async 创建tcp/udp客户端
+     * @param int $type 表示socket的类型,如TCP/UDP(使用常量)
+     * @param boolean $async 表示同步阻塞还是异步非阻塞,默认为同步阻塞
      * @return 
      */
-    public function __construct($type, $async)
+    public function __construct(int $type, bool $async)
     {
+    
     }
 
     /**
      * 
-     *析构函数
+     *析构方法
      * @example 
      * @return 
      */
     public function __destruct()
     {
+    
     }
 
     /**
      * 
      *设置客户端参数
      * @example 
-     * @param array $settings 设置客户端参数
+     * @param array $settings 设置的参数
      * @return 
      */
     public function set(Array $settings)
     {
+    
     }
 
     /**
      * 
-     *连接到远程服务器
+     *连接远程服务器
      * @example 
-     * @param string $host 连接到远程服务器
-     * @param int $port 连接到远程服务器
-     * @param float $timeout 连接到远程服务器
-     * @param int $sock_flag 连接到远程服务器
-     * @return bool
+     * @param string $host 是远程服务器的地址,1.9.24或更高版本已支持自动异步解析域名,$host可直接传入域名
+     * @param int $port 是远程服务器端口
+     * @param float $timeout 是网络IO的超时,包括connect/send/recv,单位是s,支持浮点数。默认为0.5s,即500ms
+     * @param int $sock_flag 在UDP类型时表示是否启用udp_connect 设定此选项后将绑定$host与$port,此UDP将会丢弃非指定host/port的数据包;
+     * @return 
      */
-    public function connect($host, $port, $timeout, $sock_flag)
+    public function connect(string $host, int $port, float $timeout, int $sock_flag)
     {
+    
     }
 
     /**
      * 
-     *用于从服务器端接收数据
+     *从服务器端接收数据
      * @example 
-     * @param int $size 用于从服务器端接收数据
-     * @param int $flag 用于从服务器端接收数据
+     * @param int $size 接收数据的缓存区最大长度,此参数不要设置过大,否则会占用较大内存
+     * @param boolean $flag 是否等待所有数据到达后返回
      * @return string
      */
-    public function recv($size, $flag)
+    public function recv(int $size, bool $flag): string
     {
+    
     }
 
     /**
      * 
-     *发送数据到远程服务器,必须在建立连接后,才可向Server发送数据
+     *发送数据到远程服务器
      * @example 
-     * @param string $data 发送数据到远程服务器,必须在建立连接后,才可向Server发送数据
-     * @param  mixed $flag 
-     * @return int
+     * @param string $data 要发送的数据
+     * @param boolean $flag 是否等待所有数据到达后返回
+     * @return 
      */
-    public function send($data, $flag)
+    public function send(string $data, bool $flag)
     {
+    
     }
 
     /**
      * 
-     *使用管道发送数据
+     *将客户端收到的数据重定向到另外一个文件描述符,可以是服务器的连接fd、stream资源、sockets资源、其他Swoole_Client、Swoole_Process的管道
      * @example 
-     * @param int $dst_socket 使用管道发送数据
+     * @param int $dst_socket 目标文件描述符
      * @return 
      */
-    public function pipe($dst_socket)
+    public function pipe(int $dst_socket)
     {
+    
     }
 
     /**
      * 
-     *发送文件到服务器,本函数是基于sendfile操作系统调用的
+     *向服务器发送文件
      * @example 
-     * @param string $filename 发送文件到服务器,本函数是基于sendfile操作系统调用的
-     * @param int $offset 发送文件到服务器,本函数是基于sendfile操作系统调用的
-     * @return bool
+     * @param string $filename 指定要发送文件的路径
+     * @param int $offset 上传文件的偏移量,可以指定从文件的中间部分开始传输数据。此特性可用于支持断点续传
+     * @param int $length 发送数据的尺寸,默认为整个文件的尺寸
+     * @return boolean
      */
-    public function sendfile($filename, $offset)
+    public function sendfile(string $filename, int $offset, int $length): boolean
     {
+    
     }
 
     /**
      * 
-     *向任意IP:PORT的主机发送UDP数据包,仅支持SWOOLE_SOCK_UDP/SWOOLE_SOCK_UDP6类型的swoole_client对象。
+     *向任意主机发送UDP数据包
      * @example 
-     * @param string $ip 向任意IP:PORT的主机发送UDP数据包,仅支持SWOOLE_SOCK_UDP/SWOOLE_SOCK_UDP6类型的swoole_client对象。
-     * @param int $port 向任意IP:PORT的主机发送UDP数据包,仅支持SWOOLE_SOCK_UDP/SWOOLE_SOCK_UDP6类型的swoole_client对象。
-     * @param string $data 向任意IP:PORT的主机发送UDP数据包,仅支持SWOOLE_SOCK_UDP/SWOOLE_SOCK_UDP6类型的swoole_client对象。
-     * @return bool
+     * @param string $ip 目标主机的IP地址,支持IPv4/IPv6
+     * @param int $port 目标主机端口
+     * @param string $data 要发送的数据内容,不得超过64K
+     * @return boolean
      */
-    public function sendto($ip, $port, $data)
+    public function sendto(string $ip, int $port, string $data): boolean
     {
+    
     }
 
     /**
@@ -174,89 +269,132 @@ public function sendto($ip, $port, $data)
      */
     public function sleep()
     {
+    
     }
 
     /**
      * 
-     *调用此方法会重新监听可读事件,将socket连接从睡眠中唤醒(如果socket并未进入sleep模式,wakeup操作没有任何作用)
+     *调用此方法会重新监听可读事件,将socket连接从睡眠中唤醒
      * @example 
      * @return 
      */
     public function wakeup()
     {
+    
     }
 
     /**
      * 
-     *暂停数据接收
+     *停止接收数据
      * @example 
      * @return 
      */
     public function pause()
     {
+    
     }
 
     /**
      * 
-     *恢复数据接收
+     *恢复数据接收。与pause方法成对使用
      * @example 
      * @return 
      */
     public function resume()
     {
+    
+    }
+
+    /**
+     * 
+     *动态开启SSL隧道加密。客户端在建立连接时使用明文通信,中途希望改为SSL隧道加密通信,可以使用enableSSL方法来实现
+     * @example 
+     * @param callable $callback 启用后的回调函数
+     * @return 
+     */
+    public function enableSSL(Callable $callback)
+    {
+    
+    }
+
+    /**
+     * 
+     *获取服务器端证书信息
+     * @example 
+     * @return string | bool
+     */
+    public function getPeerCert(): ?string
+    {
+    
+    }
+
+    /**
+     * 
+     *验证服务端证书信息
+     * @example 
+     * @return 
+     */
+    public function verifyPeerCert()
+    {
+    
     }
 
     /**
      * 
      *返回swoole_client的连接状态
      * @example 
-     * @return bool
+     * @return 
      */
     public function isConnected()
     {
+    
     }
 
     /**
      * 
      *用于获取客户端socket的本地host:port,必须在连接之后才可以使用
      * @example 
-     * @return array
+     * @return 
      */
     public function getsockname()
     {
+    
     }
 
     /**
      * 
-     *获取对端socket的IP地址和端口,仅支持SWOOLE_SOCK_UDP/SWOOLE_SOCK_UDP6类型的swoole_client对象(此函数必须在$client->recv() 之后调用)
+     *获取对端socket的IP地址和端口
      * @example 
-     * @return bool
+     * @return 
      */
     public function getpeername()
     {
+    
     }
 
     /**
      * 
      *关闭连接
      * @example 
-     * @param bool $force 关闭连接
-     * @return bool
+     * @param boolean $force 表示强制关闭连接,可用于关闭SWOOLE_KEEP长连接
+     * @return 
      */
-    public function close($force)
+    public function close(bool $force)
     {
+    
     }
 
     /**
      * 
-     *注册异步事件回调函数,调用on方法会使当前的socket变成非阻塞的
+     *绑定事件(为事件注册函数)
      * @example 
-     * @param string $event_name 注册异步事件回调函数,调用on方法会使当前的socket变成非阻塞的
-     * @param string $callback 注册异步事件回调函数,调用on方法会使当前的socket变成非阻塞的
-     * @return int
+     * @param string $event_name 事件类型,支持connect/error/receive/close 4种
+     * @param callable $callback 回调函数,可以是函数名字符串、匿名函数、类静态方法、对象方法
+     * @return 
      */
-    public function on($event_name, $callback)
+    public function on(string $event_name, Callable $callback)
     {
+    
     }
 
 }
diff --git a/src/Swoole/Co.php b/src/Swoole/Co.php
new file mode 100644
index 0000000..f10fd14
--- /dev/null
+++ b/src/Swoole/Co.php
@@ -0,0 +1,279 @@
+finish()方法将任务处理的结果发送给worker进程。
+     * @access public
+     */
+    public $onFinish;
+
+    /**
+     * @var callable $onManagerStart 
+     * 当管理进程启动时调用它
+     * @access public
+     */
+    public $onManagerStart;
+
+    /**
+     * @var callable $onManagerStop 
+     * 当管理进程结束时调用它
+     * @access public
+     */
+    public $onManagerStop;
+
+    /**
+     * @var callable $onPipeMessage 
+     * 当工作进程收到由 sendMessage 发送的管道消息时会触发onPipeMessage事件
+     * @access public
+     */
+    public $onPipeMessage;
+
+    /**
+     * @var iterator $connections 
+     * TCP连接迭代器
+     * @access public
+     */
+    public $connections;
+
+    /**
+     * @var string $host 
+     * 连接的主机
+     * @access public
+     */
+    public $host;
+
+    /**
+     * @var int $port 
+     * 连接的主机的端口
+     * @access public
+     */
+    public $port    =    0;
+
+    /**
+     * @var int $type 
+     * socket的类型
+     * @access public
+     */
+    public $type    =    0;
+
+    /**
+     * @var int $mode 
+     * 运行模式(swoole提供了3种运行模式,默认为SWOOLE_PROCESS多进程模式)
+     * @access public
+     */
+    public $mode    =    0;
+
+    /**
+     * @var array $ports 
+     * 当监听多端口时的端口列表
+     * @access public
+     */
+    public $ports    =    array();
+
+    /**
+     * @var int $master_pid 
+     * 主进程ID
+     * @access public
+     */
+    public $master_pid    =    0;
+
+    /**
+     * @var int $manager_pid 
+     * 管理进程ID
+     * @access public
+     */
+    public $manager_pid    =    0;
+
+    /**
+     * @var int $worker_id 
+     * 当前工作进程(包括worker进程和task进程)编号
+     * @access public
+     */
+    public $worker_id    =    -1;
+
+    /**
+     * @var boolean $taskworker 
+     * 当前进程是否是task工作进程
+     * @access public
+     */
+    public $taskworker    =    '';
+
+    /**
+     * @var int $worker_pid 
+     * 当前工作进程ID(操作系统进程)
+     * @access public
+     */
+    public $worker_pid    =    0;
+
+    /**
+     * @var callable $onRequest 
+     * 请求回调函数
+     * @access public
+     */
+    public $onRequest;
+
+    /**
+     * @var callable $onHandshake 
+     * TCP握手时的回调函数
+     * @access public
+     */
+    public $onHandshake;
+
+    /**
+     * @var array $setting 
+     * 通过swoole_server:set()设置的参数会保存到setting属性上
+     * @access public
+     */
+    public $setting    =    array();
+
+    /**
+     * 
+     *绑定事件(为事件注册函数)
+     * @example 
+     * @param string $event_name 事件名称
+     * @param callable $callback 事件对应的回调函数
+     * @return 
+     */
+    public function on(string $event_name, Callable $callback)
+    {
+    
+    }
+
+    /**
+     * 
+     *启动HTTP server
+     * @example 
+     * @return 
+     */
+    public function start()
+    {
+    
+    }
+
+    /**
+     * 
+     *序列化函数调用的魔术方法(在PHP进行序列化时,serialize() 检查类中是否有 __sleep() ,如果有,则该函数将在任何序列化之前运行。该函数必须返回一个需要进行序列化保存的成员属性数组,并且只序列化该函数返回的这些成员属性. 该函数有两个作用: 第一. 在序列化之前,关闭对象可能具有的任何数据库连接等. 第二. 指定对象中需要被序列化的成员属性,如果某个属性比较大而不需要储存下来,可以不把它写进__sleep要返回的数组中,这样该属性就不会被序列化)
+     * @example 
+     * @return 
+     */
+    public function __sleep()
+    {
+    
+    }
+
+    /**
+     * 
+     *反序列化函数调用的魔术方法(unserialize() 从字节流中创建了一个对象之后,马上检查是否具有__wakeup 的函数的存在。如果存在,__wakeup 立刻被调用。使用 __wakeup 的目的是重建在序列化中可能丢失的任何数据库连接以及处理其它重新初始化的任务)
+     * @example 
+     * @return 
+     */
+    public function __wakeup()
+    {
+    
+    }
+
+    /**
+     * 
+     *swoole_server初始化方法
+     * @example 
+     * @param string $host 主机IP
+     * @param int $port 端口
+     * @param int $mode 运行模式
+     * @param int $sock_type socket类型
+     * @return 
+     */
+    public function __construct(string $host, int $port, int $mode, int $sock_type)
+    {
+    
+    }
+
+    /**
+     * 
+     *析构函数
+     * @example 
+     * @return 
+     */
+    public function __destruct()
+    {
+    
+    }
+
+    /**
+     * 
+     *添加监听端口(是addlistener的别名)
+     * @example 
+     * @param string $host 监听的主机
+     * @param int $port 监听的端口号
+     * @param int $sock_type socket类型
+     * @return 
+     */
+    public function listen(string $host, int $port, int $sock_type)
+    {
+    
+    }
+
+    /**
+     * 
+     *添加监听端口
+     * @example 
+     * @param string $host 监听的主机
+     * @param int $port 监听的端口号
+     * @param int $sock_type socket类型
+     * @return 
+     */
+    public function addlistener(string $host, int $port, int $sock_type)
+    {
+    
+    }
+
+    /**
+     * 
+     *设置swoole_server运行时的参数
+     * @example 
+     * @param array $settings 配置选项
+     * @return 
+     */
+    public function set(Array $settings)
+    {
+    
+    }
+
+    /**
+     * 
+     *向客户端发送数据
+     * @example 
+     * @param int $fd 连接句柄
+     * @param string $send_data 发送的数据
+     * @param int $reactor_id UDP服务器使用$fd保存客户端IP,$extraData保存server_fd和port
+     * @return 
+     */
+    public function send(int $fd, string $send_data, int $reactor_id)
+    {
+    
+    }
+
+    /**
+     * 
+     *向任意客户端发送UDP数据包
+     * @example 
+     * @param string $ip IPv4字符串,如192.168.1.102。如果IP不合法会返回错误
+     * @param int $port 为 1-65535的网络端口号,如果端口错误发送会失败
+     * @param string $send_data 发送的数据内容,可以是文本或者二进制内容
+     * @param int $server_socket 服务器可能会同时监听多个UDP端口,此参数可以指定使用哪个端口发送数据包
+     * @return 
+     */
+    public function sendto(string $ip, int $port, string $send_data, int $server_socket)
+    {
+    
+    }
+
+    /**
+     * 
+     *阻塞的向客户端发送数据
+     * @example 
+     * @param int $conn_fd 与客户端连接的句柄
+     * @param string $send_data 发送的数据
+     * @return 
+     */
+    public function sendwait(int $conn_fd, string $send_data)
+    {
+    
+    }
+
+    /**
+     * 
+     *检测fd对应的连接是否存在
+     * @example 
+     * @param int $fd 连接句柄
+     * @return 
+     */
+    public function exist(int $fd)
+    {
+    
+    }
+
+    /**
+     * 
+     *设置客户端连接为保护状态,不被心跳线程切断
+     * @example 
+     * @param int $fd 要设置保护状态的客户端连接fd
+     * @param boolean $is_protected 设置的状态,true表示保护状态,false表示不保护
+     * @return 
+     */
+    public function protect(int $fd, bool $is_protected)
+    {
+    
+    }
+
+    /**
+     * 
+     *向客户端发送文件
+     * @example 
+     * @param int $conn_fd 连接句柄
+     * @param string $filename 文件名
+     * @param int $offset 指定文件偏移量,可以从文件的某个位置起发送数据。默认为0,表示从文件头部开始发送
+     * @param int $length 指定发送的长度,默认为文件尺寸
+     * @return 
+     */
+    public function sendfile(int $conn_fd, string $filename, int $offset, int $length)
+    {
+    
+    }
+
+    /**
+     * 
+     *关闭客户端连接
+     * @example 
+     * @param int $fd 连接句柄
+     * @param boolean $reset 设置为true会强制关闭连接,丢弃发送队列中的数据
+     * @return 
+     */
+    public function close(int $fd, bool $reset)
+    {
+    
+    }
+
+    /**
+     * 
+     *确认连接,与enable_delay_receive或wait_for_bind配合使用
+     * @example 
+     * @param int $fd 连接句柄
+     * @return 
+     */
+    public function confirm(int $fd)
+    {
+    
+    }
+
+    /**
+     * 
+     *停止接收数据
+     * @example 
+     * @param int $fd 连接句柄
+     * @return 
+     */
+    public function pause(int $fd)
+    {
+    
+    }
+
+    /**
+     * 
+     *恢复数据接收。与pause方法成对使用
+     * @example 
+     * @param int $fd 连接句柄
+     * @return 
+     */
+    public function resume(int $fd)
+    {
+    
+    }
+
+    /**
+     * 
+     *投递一个任务到task_worker连接池中
+     * @example 
+     * @param mixed $data 要投递的任务数据,可以为除资源类型之外的任意PHP变量
+     * @param int $worker_id 可以制定要给投递给哪个task进程,传入ID即可
+     * @param callable $finish_callback 完成后的回调函数
+     * @return 
+     */
+    public function task($data, int $worker_id, Callable $finish_callback)
+    {
+    
+    }
+
+    /**
+     * 
+     *以阻塞的形式投递一个任务到task_worker连接池中
+     * @example 
+     * @param mixed $data 要投递的任务数据,可以为除资源类型之外的任意PHP变量
+     * @param float $timeout 超时时间
+     * @param int $worker_id 可以制定要给投递给哪个task进程,传入ID即可
+     * @return 
+     */
+    public function taskwait($data, float $timeout, int $worker_id)
+    {
+    
+    }
+
+    /**
+     * 
+     *并发执行多个Task
+     * @example 
+     * @param array $tasks 必须为数字索引数组,不支持关联索引数组,底层会遍历$tasks将任务逐个投递到Task进程
+     * @param double $timeout 超时时间
+     * @return 
+     */
+    public function taskWaitMulti(Array $tasks, double $timeout)
+    {
+    
+    }
+
+    /**
+     * 
+     *并发执行Task并进行协程调度
+     * @example 
+     * @param array $tasks 必须为数字索引数组,不支持关联索引数组,底层会遍历$tasks将任务逐个投递到Task进程
+     * @param double $timeout 超时时间
+     * @return array
+     */
+    public function taskCo(Array $tasks, double $timeout): array
+    {
+    
+    }
+
+    /**
+     * 
+     *用于在task进程中通知worker进程任务已完成
+     * @example 
+     * @param  mixed $data 
+     * @return 
+     */
+    public function finish($data)
+    {
+    
+    }
+
+    /**
+     * 
+     *重启所有工作进程
+     * @example 
+     * @return 
+     */
+    public function reload()
+    {
+    
+    }
+
+    /**
+     * 
+     *关闭服务器
+     * @example 
+     * @return 
+     */
+    public function shutdown()
+    {
+    
+    }
+
+    /**
+     * 
+     *停止当前worker进程
+     * @example 
+     * @param int $worker_id 工作进程ID
+     * @return 
+     */
+    public function stop(int $worker_id)
+    {
+    
+    }
+
+    /**
+     * 
+     *获取最近一次操作错误的错误码
+     *返回的错误码:
+     *1001 连接已经被Server端关闭了,出现这个错误一般是代码中已经执行了$serv->close()关闭了某个连接,但仍然调用$serv->send()向这个连接发送数据
+     * @example 
+     * @return 
+     */
+    public function getLastError()
+    {
+    
+    }
+
+    /**
+     * 
+     *检测所有服务器连接,并找出已经超时的连接
+     * @example 
+     * @param boolean $reactor_id 是否关闭超时的连接,默认为true
+     * @return 
+     */
+    public function heartbeat(bool $reactor_id)
+    {
+    
+    }
+
+    /**
+     * 
+     *获取客户端连接信息
+     * @example 
+     * @param  mixed $fd 连接句柄
+     * @param int $reactor_id reactor线程id
+     * @return from_id
+     */
+    public function connection_info($fd, int $reactor_id): from_id
+    {
+    
+    }
+
+    /**
+     * 
+     *用来遍历所有客户端连接
+     * @example 
+     * @param int $start_fd 起始fd
+     * @param int $find_count 每页取多少条
+     * @return 
+     */
+    public function connection_list(int $start_fd, int $find_count)
+    {
+    
+    }
+
+    /**
+     * 
+     *获取连接的信息,别名是swoole_server->connection_info
+     * @example 
+     * @param  mixed $fd 连接句柄
+     * @param int $reactor_id reactor线程id
+     * @return 
+     */
+    public function getClientInfo($fd, int $reactor_id)
+    {
+    
+    }
+
+    /**
+     * 
+     *用来遍历所有客户端连接(server->connection_list的别名)
+     * @example 
+     * @param int $start_fd 起始fd
+     * @param int $find_count 每页取多少条
+     * @return 
+     */
+    public function getClientList(int $start_fd, int $find_count)
+    {
+    
+    }
+
+    /**
+     * 
+     *在指定时间后执行某个回调函数
+     * @example 
+     * @param int $ms 指定时间,单位为毫秒
+     * @param callable $callback 回调函数
+     * @param array $param 给回调函数传入的参数
+     * @return 
+     */
+    public function after(int $ms, Callable $callback, Array $param)
+    {
+    
+    }
+
+    /**
+     * 
+     *添加定时器
+     * @example 
+     * @param int $ms 指定时间,单位为毫秒
+     * @param callable $callback 回调函数
+     * @return 
+     */
+    public function tick(int $ms, Callable $callback)
+    {
+    
+    }
+
+    /**
+     * 
+     *清除定时器
+     * @example 
+     * @param int $timer_id 定时器ID
+     * @return 
+     */
+    public function clearTimer(int $timer_id)
+    {
+    
+    }
+
+    /**
+     * 
+     *延迟执行一个PHP函数
+     * @example 
+     * @param callable $callback 执行的函数
+     * @return 
+     */
+    public function defer(Callable $callback)
+    {
+    
+    }
+
+    /**
+     * 
+     *向任意worker进程或task进程发送消息
+     * @example 
+     * @param int $dst_worker_id 目标worker的ID
+     * @param string $data 发送的消息
+     * @return 
+     */
+    public function sendMessage(int $dst_worker_id, string $data)
+    {
+    
+    }
+
+    /**
+     * 
+     *添加一个自定义的工作进程
+     * @example 
+     * @param Swoole\Process $process 进程对象
+     * @return 
+     */
+    public function addProcess(Swoole\Process $process)
+    {
+    
+    }
+
+    /**
+     * 
+     *得到当前server的活动TCP连接数
+     *array (
+     * @example 
+     * @return 
+     */
+    public function stats()
+    {
+    
+    }
+
+    /**
+     * 
+     *将连接绑定到某个用户定义的ID
+     * @example 
+     * @param int $fd 连接句柄
+     * @param int $uid 用户定义的ID
+     * @return 
+     */
+    public function bind(int $fd, int $uid)
+    {
+    
+    }
+
+}
+
diff --git a/src/Swoole/Co/Http2/Client.php b/src/Swoole/Co/Http2/Client.php
new file mode 100644
index 0000000..4b323c1
--- /dev/null
+++ b/src/Swoole/Co/Http2/Client.php
@@ -0,0 +1,167 @@
+ '192.168.56.102',
+     *     'user' => 'test',
+     *     'password' => 'test',
+     *     'database' => 'test',
+     *     'charset' => 'utf8',
+     * );
+     * @param array $server_config 连接配置信息
+     * @return 
+     */
+    public function connect(Array $server_config)
+    {
+    
+    }
+
+    /**
+     * 
+     *执行sql语句
+     * @example 
+     * @param string $sql 要执行的sql语句
+     * @param double $timeout 超时时间,超时的话会断开MySQL连接,0表示不设置超时时间
+     * @return array|boolean
+     */
+    public function query(string $sql, double $timeout): ?array
+    {
+    
+    }
+
+    /**
+     * 
+     *接收包(获取延迟收包的结果,当没有进行延迟收包或者收包超时,返回false)
+     * @example 
+     * @return mixed
+     */
+    public function recv()
+    {
+    
+    }
+
+    /**
+     * 
+     *启动事务
+     * @example 
+     * @return 
+     */
+    public function begin()
+    {
+    
+    }
+
+    /**
+     * 
+     *提交事务
+     * @example 
+     * @return 
+     */
+    public function commit()
+    {
+    
+    }
+
+    /**
+     * 
+     *回滚事务(必须先调用begin启动事务才能调用rollback否则底层会抛出异常)
+     * @example 
+     * @return 
+     */
+    public function rollback()
+    {
+    
+    }
+
+    /**
+     * 
+     *设置是否延迟
+     * @example 
+     * @param boolean $defer 为true时,表明该Client要延迟收包,为false时,表明该Client非延迟收包,默认值为true
+     * @return boolean
+     */
+    public function setDefer(bool $defer): boolean
+    {
+    
+    }
+
+    /**
+     * 
+     *返回当前设置的defer
+     * @example 
+     * @return boolean
+     */
+    public function getDefer(): boolean
+    {
+    
+    }
+
+    /**
+     * 
+     *关闭连接
+     * @example 
+     * @return 
+     */
+    public function close()
+    {
+    
+    }
+
+    /**
+     * 
+     *序列化函数调用的魔术方法(在PHP进行序列化时,serialize() 检查类中是否有 __sleep() ,如果有,则该函数将在任何序列化之前运行。该函数必须返回一个需要进行序列化保存的成员属性数组,并且只序列化该函数返回的这些成员属性. 该函数有两个作用: 第一. 在序列化之前,关闭对象可能具有的任何数据库连接等. 第二. 指定对象中需要被序列化的成员属性,如果某个属性比较大而不需要储存下来,可以不把它写进__sleep要返回的数组中,这样该属性就不会被序列化)
+     * @example 
+     * @return 
+     */
+    public function __sleep()
+    {
+    
+    }
+
+    /**
+     * 
+     *反序列化函数调用的魔术方法(unserialize() 从字节流中创建了一个对象之后,马上检查是否具有__wakeup 的函数的存在。如果存在,__wakeup 立刻被调用。使用 __wakeup 的目的是重建在序列化中可能丢失的任何数据库连接以及处理其它重新初始化的任务)
+     * @example 
+     * @return 
+     */
+    public function __wakeup()
+    {
+    
+    }
+
+}
+
diff --git a/src/Swoole/Co/Redis.php b/src/Swoole/Co/Redis.php
new file mode 100644
index 0000000..cba8f8a
--- /dev/null
+++ b/src/Swoole/Co/Redis.php
@@ -0,0 +1,2884 @@
+set('key', 'value');
+     * 带有效期的设置:
+     * $redis->set('key','value', 10);
+     * 当键不存在时,设置期有效期为10秒:
+     * $redis->set('key', 'value', Array('nx', 'ex'=>10));
+     * 当键存在时,设置期有效期为1000毫秒:
+     * $redis->set('key', 'value', Array('xx', 'px'=>1000));
+     * 
+     * @param string $key 设置的缓存键
+     * @param string $value 设置的缓存值
+     * @param int|array $options 附加项,可以是超时时间或者一个选项数组
+     * @return bool
+     */
+    public function set(string $key, string $value, int $options): bool
+    {
+    
+    }
+
+    /**
+     * 
+     *修改某个键的某个位置的位值
+     * @example 
+     * 
+     * $redis->set('key', "*");     // ord("*") = 42 = 0x2f = "0010 1010"
+     * $redis->setBit('key', 5, 1); // returns 0
+     * $redis->setBit('key', 7, 1); // returns 0
+     * $redis->get('key');          // chr(0x2f) = "/" = b("0010 1111")
+     * 
+ * @param string $key 键名 + * @param int $offset 开始位置 + * @param boolean|int $value 新值 + * @return int + */ + public function setBit(string $key, int $offset, int $value): int + { + + } + + /** + * + *设置键值并设置有效期 + * @example $redis->setex('key', 3600, 'value'); + * @param string $key 设置的缓存键 + * @param string $value 设置的缓存值 + * @param int $ttl 有效期 + * @return bool + */ + public function setEx(string $key, string $value, int $ttl): bool + { + + } + + /** + * + *设置键值并设置有效期(毫秒为单位) + * @example + * @param string $key 设置的缓存键 + * @param string $value 设置的缓存值 + * @param int $ttl 有效期(毫秒为单位) + * @return + */ + public function psetEx(string $key, string $value, int $ttl) + { + + } + + /** + * + *给列表指定位置设置新值 + * @example + *
+     * $redis->rPush('key1', 'A');
+     * $redis->rPush('key1', 'B');
+     * $redis->rPush('key1', 'C');  // key1 => [ 'A', 'B', 'C' ]
+     * $redis->lGet('key1', 0);     // 'A'
+     * $redis->lSet('key1', 0, 'X');
+     * $redis->lGet('key1', 0);     // 'X'
+     * 
+ * @param string $key 键名 + * @param int $index 索引值 + * @param string $value 新值 + * @return boolean + */ + public function lSet(string $key, int $index, string $value): boolean + { + + } + + /** + * + *获取指定的key的值 + * @example $redis->get('key'); + * @return string|bool + */ + public function get(): ?string + { + + } + + /** + * + *批量获取键名 + * @example + *
+     * $redis->delete('x', 'y', 'z', 'h');	// remove x y z
+     * $redis->mset(array('x' => 'a', 'y' => 'b', 'z' => 'c'));
+     * $redis->hset('h', 'field', 'value');
+     * var_dump($redis->mget(array('x', 'y', 'z', 'h')));
+     * // Output:
+     * // array(3) {
+     * // [0]=>
+     * // string(1) "a"
+     * // [1]=>
+     * // string(1) "b"
+     * // [2]=>
+     * // string(1) "c"
+     * // [3]=>
+     * // bool(false)
+     * // }
+     * 
+ * @param array $keys 键名数组 + * @return + */ + public function mGet(Array $keys) + { + + } + + /** + * + *删除一个或多个键 + * @example $redis->delete('key1', 'key2'); + * $redis->delete(array('key3', 'key4')); + * @param array|string $keys 键名 + * @return int + */ + public function del(array $keys): int + { + + } + + /** + * + *删除字典的某个或某些字段 + * @example + *
+     * $redis->hMSet('h',
+     * array(
+     * 'f1' => 'v1',
+     * 'f2' => 'v2',
+     * 'f3' => 'v3',
+     * 'f4' => 'v4',
+     * ));
+     * var_dump( $redis->hDel('h', 'f1') );        // int(1)
+     * var_dump( $redis->hDel('h', 'f2', 'f3') );  // int(2)
+     * s
+     * var_dump( $redis->hGetAll('h') );
+     * //// Output:
+     * //  array(1) {
+     * //    ["f4"]=> string(2) "v4"
+     * //  }
+     * 
+ * @param string $key 键名 + * @param string|array $fields 字段名 + * @return int + */ + public function hDel(string $key, string $fields): int + { + + } + + /** + * + *为字典的字段设置值 + * @example + *
+     * $redis->delete('h')
+     * $redis->hSet('h', 'key1', 'hello');  // 1, 'key1' => 'hello' in the hash at "h"
+     * $redis->hGet('h', 'key1');           // returns "hello"
+     * $redis->hSet('h', 'key1', 'plop');   // 0, value was replaced.
+     * $redis->hGet('h', 'key1');           // returns "plop"
+     * 
+ * @param string $key 键名 + * @param string $field 字段名 + * @param string $value 字段值 + * @return int + */ + public function hSet(string $key, string $field, string $value): int + { + + } + + /** + * + *批量设置字典字段的值 + * @example + *
+     * $redis->delete('user:1');
+     * $redis->hMset('user:1', array('name' => 'Joe', 'salary' => 2000));
+     * $redis->hIncrBy('user:1', 'salary', 100); // Joe earns 100 more now.
+     * 
+ * @param string $key 键名 + * @param array $fields 字段键值对 + * @return boolean + */ + public function hMSet(string $key, Array $fields): boolean + { + + } + + /** + * + *当字典的字段不存在时,为其设置值 + * @example + *
+     * $redis->delete('h')
+     * $redis->hSetNx('h', 'key1', 'hello'); // TRUE, 'key1' => 'hello' in the hash at "h"
+     * $redis->hSetNx('h', 'key1', 'world'); // FALSE, 'key1' => 'hello' in the hash at "h". No change since the field
+     * wasn't replaced.
+     * 
+ * @param string $key 键名 + * @param string $field 字段名 + * @param string $value 字段值 + * @return bool + */ + public function hSetNx(string $key, string $field, string $value): bool + { + + } + + /** + * + *删除一个或多个键 + * @example $redis->delete('key1', 'key2'); + * $redis->delete(array('key3', 'key4')); + * @param array|string $keys 键名 + * @return int + */ + public function delete(array $keys): int + { + + } + + /** + * + *批量设置值 + * @example + *
+     * $redis->mset(array('key0' => 'value0', 'key1' => 'value1'));
+     * var_dump($redis->get('key0'));
+     * var_dump($redis->get('key1'));
+     * // Output:
+     * // string(6) "value0"
+     * // string(6) "value1"
+     * 
+ * @param array $values 要设置的键值对 + * @return bool + */ + public function mSet(Array $values): bool + { + + } + + /** + * + *批量设置值(当不存在时设置) + * @example + *
+     * $redis->mset(array('key0' => 'value0', 'key1' => 'value1'));
+     * var_dump($redis->get('key0'));
+     * var_dump($redis->get('key1'));
+     * // Output:
+     * // string(6) "value0"
+     * // string(6) "value1"
+     * 
+ * @param array $values 要设置的键值对 + * @return bool + */ + public function mSetNx(Array $values): bool + { + + } + + /** + * + *根据匹配模式获取键名(如*) + * @example + * $allKeys = $redis->keys('*'); + * $keyWithUserPrefix = $redis->keys('user*'); + * @param string $pattern 匹配模式 + * @return array + */ + public function getKeys(string $pattern): array + { + + } + + /** + * + *根据匹配模式获取键名(如*) + * @example + * $allKeys = $redis->keys('*'); + * $keyWithUserPrefix = $redis->keys('user*'); + * @param string $pattern 匹配模式 + * @return array + */ + public function keys(string $pattern): array + { + + } + + /** + * + *判断键是否存在 + * @example + *
+     * $redis->set('key', 'value');
+     * $redis->exists('key');               //  TRUE
+     * $redis->exists('NonExistingKey');    // FALSE
+     * 
+ * @param string $key 键名 + * @return bool + */ + public function exists(string $key): bool + { + + } + + /** + * + *获取指定键的数据类型(需要根据常量匹配) + * @example $redis->type('key'); + * @param string $key 键名 + * @return int + */ + public function type(string $key): int + { + + } + + /** + * + *获取键值的长度 + * @example + *
+     * $redis->set('key', 'value');
+     * $redis->strlen('key'); // 5
+     * 
+ * @param string $key 键名 + * @return int + */ + public function strLen(string $key): int + { + + } + + /** + * + *从列表左侧删除一个元素 + * @example + *
+     * $redis->rPush('key1', 'A');
+     * $redis->rPush('key1', 'B');
+     * $redis->rPush('key1', 'C');  // key1 => [ 'A', 'B', 'C' ]
+     * $redis->lPop('key1');        // key1 => [ 'B', 'C' ]
+     * 
+ * @param string $key 键名 + * @return string + */ + public function lPop(string $key): string + { + + } + + /** + * + *是一个阻塞lPop原语。 如果至少有一个列表包含至少一个元素,则该元素将从列表头部弹出并返回给调用者。 如果所有通过参数传递的键标识的列表都是空的,blPop将在指定的超时期间阻塞,直到元素被推送到其中一个列表。 这个元素将被弹出。 + * @example + *
+     * // Non blocking feature
+     * $redis->lPush('key1', 'A');
+     * $redis->delete('key2');
+     * $redis->blPop('key1', 'key2', 10); // array('key1', 'A')
+     * // OR
+     * $redis->blPop(array('key1', 'key2'), 10); // array('key1', 'A')
+     * $redis->brPop('key1', 'key2', 10); // array('key1', 'A')
+     * // OR
+     * $redis->brPop(array('key1', 'key2'), 10); // array('key1', 'A')
+     * // Blocking feature
+     * // process 1
+     * $redis->delete('key1');
+     * $redis->blPop('key1', 10);
+     * // blocking for 10 seconds
+     * // process 2
+     * $redis->lPush('key1', 'A');
+     * // process 1
+     * // array('key1', 'A') is returned
+     * 
+ * @param string|...|array $key 键名 + * @param int $timeout 超时时间 + * @return array + */ + public function blPop(string $key, int $timeout): array + { + + } + + /** + * + *从列表右侧删除一个元素 + * @example + *
+     * $redis->rPush('key1', 'A');
+     * $redis->rPush('key1', 'B');
+     * $redis->rPush('key1', 'C');  // key1 => [ 'A', 'B', 'C' ]
+     * $redis->rPop('key1');        // key1 => [ 'A', 'B' ]
+     * 
+ * @param string $key 键名 + * @return string + */ + public function rPop(string $key): string + { + + } + + /** + * + *是一个阻塞rPop原语。 如果至少有一个列表包含至少一个元素,则该元素将从列表尾部弹出并返回给调用者。 如果所有通过参数传递的键标识的列表都是空的,brPop将在指定的超时期间阻塞,直到元素被推送到其中一个列表。 这个元素将被弹出。 + * @example + *
+     * // Non blocking feature
+     * $redis->lPush('key1', 'A');
+     * $redis->delete('key2');
+     * $redis->blPop('key1', 'key2', 10); // array('key1', 'A')
+     * // OR
+     * $redis->blPop(array('key1', 'key2'), 10); // array('key1', 'A')
+     * $redis->brPop('key1', 'key2', 10); // array('key1', 'A')
+     * // OR
+     * $redis->brPop(array('key1', 'key2'), 10); // array('key1', 'A')
+     * // Blocking feature
+     * // process 1
+     * $redis->delete('key1');
+     * $redis->blPop('key1', 10);
+     * // blocking for 10 seconds
+     * // process 2
+     * $redis->lPush('key1', 'A');
+     * // process 1
+     * // array('key1', 'A') is returned
+     * 
+ * @param string|...|array $key 键名 + * @param int $timeout 超时时间 + * @return array + */ + public function brPop(string $key, int $timeout): array + { + + } + + /** + * + *阻塞执行rpoplpush + * @example + * @param string $srcKey 要删除元素的队列键名 + * @param string $dstKey 要插入元素的队列的键名 + * @return string + */ + public function bRPopLPush(string $srcKey, string $dstKey): string + { + + } + + /** + * + *返回列表的长度 + * @example + * @param string|...|array $key 键名 + * @return int | bool + */ + public function lSize(string $key): ?int + { + + } + + /** + * + *返回列表的长度 + * @example + * @param string|...|array $key 键名 + * @return int | bool + */ + public function lLen(string $key): ?int + { + + } + + /** + * + *返回集合的元素个数 + * @example + * @param string $key 键名 + * @return int + */ + public function sSize(string $key): int + { + + } + + /** + * + *返回集合的元素个数 + * @example + * @param string $key 键名 + * @return int + */ + public function scard(string $key): int + { + + } + + /** + * + *随机删除元素的某个或某些成员,并返回这个删除的成员. + * @example + *
+     * $redis->sAdd('key1' , 'set1');
+     * $redis->sAdd('key1' , 'set2');
+     * $redis->sAdd('key1' , 'set3');   // 'key1' => {'set3', 'set1', 'set2'}
+     * $redis->sPop('key1');            // 'set1', 'key1' => {'set3', 'set2'}
+     * $redis->sPop('key1');            // 'set3', 'key1' => {'set2'}
+     * 
+ * @param string $key 键名 + * @param int $count 删除个数 + * @return string | bool + */ + public function sPop(string $key, int $count): ?string + { + + } + + /** + * + *返回集合的所有成员 + * @example + *
+     * $redis->delete('s');
+     * $redis->sAdd('s', 'a');
+     * $redis->sAdd('s', 'b');
+     * $redis->sAdd('s', 'a');
+     * $redis->sAdd('s', 'c');
+     * var_dump($redis->sMembers('s'));
+     * //array(3) {
+     * //  [0]=>
+     * //  string(1) "c"
+     * //  [1]=>
+     * //  string(1) "a"
+     * //  [2]=>
+     * //  string(1) "b"
+     * //}
+     * // The order is random and corresponds to redis' own internal representation of the set structure.
+     * 
+ * @param string $key 键名 + * @return array + */ + public function sMembers(string $key): array + { + + } + + /** + * + *返回集合的所有成员 + * @example + *
+     * $redis->delete('s');
+     * $redis->sAdd('s', 'a');
+     * $redis->sAdd('s', 'b');
+     * $redis->sAdd('s', 'a');
+     * $redis->sAdd('s', 'c');
+     * var_dump($redis->sMembers('s'));
+     * //array(3) {
+     * //  [0]=>
+     * //  string(1) "c"
+     * //  [1]=>
+     * //  string(1) "a"
+     * //  [2]=>
+     * //  string(1) "b"
+     * //}
+     * // The order is random and corresponds to redis' own internal representation of the set structure.
+     * 
+ * @param string $key 键名 + * @return array + */ + public function sGetMembers(string $key): array + { + + } + + /** + * + *随机返回一个集合的元素(不会删除它) + * @example + *
+     * $redis->sAdd('key1' , 'one');
+     * $redis->sAdd('key1' , 'two');
+     * $redis->sAdd('key1' , 'three');              // 'key1' => {'one', 'two', 'three'}
+     * var_dump( $redis->sRandMember('key1') );     // 'key1' => {'one', 'two', 'three'}
+     * // string(5) "three"
+     * var_dump( $redis->sRandMember('key1', 2) );  // 'key1' => {'one', 'two', 'three'}
+     * // array(2) {
+     * //   [0]=> string(2) "one"
+     * //   [1]=> string(2) "three"
+     * // }
+     * 
+ * @param string $key 键名 + * @return string | bool + */ + public function sRandMember(string $key): ?string + { + + } + + /** + * + *移除指定键的有效期,让它永久有效 + * @example $redis->persist('key'); + * @param string $key 键名 + * @return bool + */ + public function persist(string $key): bool + { + + } + + /** + * + *返回指定键的有效时间(秒) + * @example $redis->ttl('key'); + * @param string $key 键名 + * @return int + */ + public function ttl(string $key): int + { + + } + + /** + * + *返回指定键的有效时间(毫秒) + * @example $redis->pttl('key'); + * @param string $key 键名 + * @return int + */ + public function pttl(string $key): int + { + + } + + /** + * + *获取有序集合的成员数 + * @example + *
+     * $redis->zAdd('key', 0, 'val0');
+     * $redis->zAdd('key', 2, 'val2');
+     * $redis->zAdd('key', 10, 'val10');
+     * $redis->zCard('key');            // 3
+     * 
+ * @param string $key 集合键名 + * @return int + */ + public function zCard(string $key): int + { + + } + + /** + * + *获取有序集合的成员数 + * @example + *
+     * $redis->zAdd('key', 0, 'val0');
+     * $redis->zAdd('key', 2, 'val2');
+     * $redis->zAdd('key', 10, 'val10');
+     * $redis->zCard('key');            // 3
+     * 
+ * @param string $key 集合键名 + * @return int + */ + public function zSize(string $key): int + { + + } + + /** + * + *获取字典的字段个数 + * @example + *
+     * $redis->delete('h')
+     * $redis->hSet('h', 'key1', 'hello');
+     * $redis->hSet('h', 'key2', 'plop');
+     * $redis->hLen('h'); // returns 2
+     * 
+ * @param string $key 键名 + * @return int + */ + public function hLen(string $key): int + { + + } + + /** + * + *获取字典的字段名称列表. + * @example + *
+     * $redis->delete('h');
+     * $redis->hSet('h', 'a', 'x');
+     * $redis->hSet('h', 'b', 'y');
+     * $redis->hSet('h', 'c', 'z');
+     * $redis->hSet('h', 'd', 't');
+     * var_dump($redis->hKeys('h'));
+     * // Output:
+     * // array(4) {
+     * // [0]=>
+     * // string(1) "a"
+     * // [1]=>
+     * // string(1) "b"
+     * // [2]=>
+     * // string(1) "c"
+     * // [3]=>
+     * // string(1) "d"
+     * // }
+     * // The order is random and corresponds to redis' own internal representation of the set structure.
+     * 
+ * @param string $key 键名 + * @return array + */ + public function hKeys(string $key): array + { + + } + + /** + * + *获取字典的字段值列表 + * @example + *
+     * $redis->delete('h');
+     * $redis->hSet('h', 'a', 'x');
+     * $redis->hSet('h', 'b', 'y');
+     * $redis->hSet('h', 'c', 'z');
+     * $redis->hSet('h', 'd', 't');
+     * var_dump($redis->hVals('h'));
+     * // Output
+     * // array(4) {
+     * //   [0]=>
+     * //   string(1) "x"
+     * //   [1]=>
+     * //   string(1) "y"
+     * //   [2]=>
+     * //   string(1) "z"
+     * //   [3]=>
+     * //   string(1) "t"
+     * // }
+     * // The order is random and corresponds to redis' own internal representation of the set structure.
+     * 
+ * @param string $key 键名 + * @return array + */ + public function hVals(string $key): array + { + + } + + /** + * + *获取字典所有字段键值对 + * @example + *
+     * $redis->delete('h');
+     * $redis->hSet('h', 'a', 'x');
+     * $redis->hSet('h', 'b', 'y');
+     * $redis->hSet('h', 'c', 'z');
+     * $redis->hSet('h', 'd', 't');
+     * var_dump($redis->hGetAll('h'));
+     * // Output:
+     * // array(4) {
+     * //   ["a"]=>
+     * //   string(1) "x"
+     * //   ["b"]=>
+     * //   string(1) "y"
+     * //   ["c"]=>
+     * //   string(1) "z"
+     * //   ["d"]=>
+     * //   string(1) "t"
+     * // }
+     * // The order is random and corresponds to redis' own internal representation of the set structure.
+     * 
+ * @param string $key 键名 + * @return array + */ + public function hGetAll(string $key): array + { + + } + + /** + * + *调试命令(不建议使用) + * @example + * @return + */ + public function debug() + { + + } + + /** + * + *将dump导出的二进制数据恢复到可读的字符串. + * @example + *
+     * $redis->set('foo', 'bar');
+     * $val = $redis->dump('foo');
+     * $redis->restore('bar', 0, $val); // The key 'bar', will now be equal to the key 'foo'
+     * 
+ * @param string $key 键名 + * @param int $ttl 有效期 + * @param string $value dump导出的二进制数据 + * @return + */ + public function restore(string $key, int $ttl, string $value) + { + + } + + /** + * + *将某个键导出为一个二进制数据. + * @example + *
+     * $redis->set('foo', 'bar');
+     * $val = $redis->dump('foo'); // $val will be the Redis encoded key value
+     * 
+ * @param string $key 键名 + * @return string + */ + public function dump(string $key): string + { + + } + + /** + * + *给键重命名 + * @example + * @param string $srcKey 旧键名 + * @param string $dstKey 新键名 + * @return boolean + */ + public function renameKey(string $srcKey, string $dstKey): boolean + { + + } + + /** + * + *给键重命名 + * @example + * @param string $srcKey 旧键名 + * @param string $dstKey 新键名 + * @return boolean + */ + public function rename(string $srcKey, string $dstKey): boolean + { + + } + + /** + * + *当目标键名不存在时,给键重命名 + * @example + * @param string $srcKey 旧键名 + * @param string $dstKey 新键名 + * @return boolean + */ + public function renameNx(string $srcKey, string $dstKey): boolean + { + + } + + /** + * + *从一个队列的队尾删除一个元素,并将该元素插入到另一个队列的头部 + * @example + *
+     * $redis->delete('x', 'y');
+     * $redis->lPush('x', 'abc');
+     * $redis->lPush('x', 'def');
+     * $redis->lPush('y', '123');
+     * $redis->lPush('y', '456');
+     * // move the last of x to the front of y.
+     * var_dump($redis->rpoplpush('x', 'y'));
+     * var_dump($redis->lRange('x', 0, -1));
+     * var_dump($redis->lRange('y', 0, -1));
+     * //Output:
+     * //
+     * //string(3) "abc"
+     * //array(1) {
+     * //  [0]=>
+     * //  string(3) "def"
+     * //}
+     * //array(3) {
+     * //  [0]=>
+     * //  string(3) "abc"
+     * //  [1]=>
+     * //  string(3) "456"
+     * //  [2]=>
+     * //  string(3) "123"
+     * //}
+     * 
+ * @param string $srcKey 要删除元素的队列键名 + * @param string $dstKey 要插入元素的队列的键名 + * @return string + */ + public function rpoplpush(string $srcKey, string $dstKey): string + { + + } + + /** + * + *返回一个随机的键 + * @example + *
+     * $key = $redis->randomKey();
+     * $surprise = $redis->get($key);  // who knows what's in there.
+     * 
+ * @return string + */ + public function randomKey(): string + { + + } + + /** + * + *检查当前redis连接状态(成功时返回PONG) + * @example + * @return string + */ + public function ping(): string + { + + } + + /** + * + *设置连接的认证密码 + * @example $redis->auth('foobared'); + * @param string $password 认证密码 + * @return bool + */ + public function auth(string $password): bool + { + + } + + /** + * + *取消观察某个键在其他客户端的变化情况 + * @example + * @param string|array $keys 键名 + * @return + */ + public function unwatch(string $keys) + { + + } + + /** + * + *观察某个键在其他客户端的变化情况. + * @example + *
+     * $redis->watch('x');
+     * // long code here during the execution of which other clients could well modify `x`
+     * $ret = $redis->multi()
+     * ->incr('x')
+     * ->exec();
+     * // $ret = FALSE if x has been modified between the call to WATCH and the call to EXEC.
+     * 
+ * @param string|array $keys 键名 + * @return + */ + public function watch(string $keys) + { + + } + + /** + * + *将数据同步到硬盘上 + * @example $redis->save(); + * @return boolean + */ + public function save(): boolean + { + + } + + /** + * + *将数据存入到硬盘上(异步操作) + * @example + * @return + */ + public function bgSave() + { + + } + + /** + * + *获取上次数据同步到硬盘的时间 + * @example $redis->lastSave(); + * @return int + */ + public function lastSave(): int + { + + } + + /** + * + *删除当前数据库的所有键 + * @example $redis->flushDB(); + * @return bool + */ + public function flushDB(): bool + { + + } + + /** + * + *删除当前实例的所有键 + * @example $redis->flushAll(); + * @return bool + */ + public function flushAll(): bool + { + + } + + /** + * + *获取当前数据库的键的个数 + * @example + *
+     * $count = $redis->dbSize();
+     * echo "Redis has $count keys\n";
+     * 
+ * @return int + */ + public function dbSize(): int + { + + } + + /** + * + *开启后台写AOF日志操作 + * @example $redis->bgrewriteaof(); + * @return bool + */ + public function bgrewriteaof(): bool + { + + } + + /** + * + *返回当前redis服务器时间. + * @example + *
+     * var_dump( $redis->time() );
+     * // array(2) {
+     * //   [0] => string(10) "1342364352"
+     * //   [1] => string(6) "253002"
+     * // }
+     * 
+ * @return int + */ + public function time(): int + { + + } + + /** + * + *返回当前连接的服务器的角色,如master、alone、slave、sentinel + * @example + * @return string + */ + public function role(): string + { + + } + + /** + * + *修改某个键的某个位置的值 + * @example + *
+     * $redis->set('key', 'Hello world');
+     * $redis->setRange('key', 6, "redis"); // returns 11
+     * $redis->get('key');                  // "Hello redis"
+     * 
+ * @param string $key 键名 + * @param int $offset 开始位置 + * @param string $value 被替换的子串的值 + * @return string + */ + public function setRange(string $key, int $offset, string $value): string + { + + } + + /** + * + *当键不存在时设置其值 + * @example + * $redis->setnx('key', 'value'); + * + * @param string $key 设置的缓存键 + * @param string $value 设置的缓存值 + * @return bool + */ + public function setNx(string $key, string $value): bool + { + + } + + /** + * + *设置键的值,并返回它的旧的缓存值 + * @example + *
+     * $redis->set('x', '42');
+     * $exValue = $redis->getSet('x', 'lol');   // return '42', replaces x by 'lol'
+     * $newValue = $redis->get('x')'            // return 'lol'
+     * 
+ * @param string $key 设置的缓存键 + * @param string $value 设置的缓存值 + * @return string + */ + public function getSet(string $key, string $value): string + { + + } + + /** + * + *将字符串追加到键值后(返回值的长度) + * @example + *
+     * $redis->set('key', 'value1');
+     * $redis->append('key', 'value2'); // 12
+     * $redis->get('key');              // 'value1value2'
+     * 
+ * @param string $key 键名 + * @param string $value 追加的值 + * @return int + */ + public function append(string $key, string $value): int + { + + } + + /** + * + *如果列表存在,从左侧(头部)向列表插入元素 + * @example + *
+     * $redis->delete('key1');
+     * $redis->lPushx('key1', 'A');     // returns 0
+     * $redis->lPush('key1', 'A');      // returns 1
+     * $redis->lPushx('key1', 'B');     // returns 2
+     * $redis->lPushx('key1', 'C');     // returns 3
+     * // key1 now points to the following list: [ 'A', 'B', 'C' ]
+     * 
+ * @param string $key 键名 + * @param string $value 元素值 + * @return int + */ + public function lPushx(string $key, string $value): int + { + + } + + /** + * + *从左侧(头部)向列表插入元素 + * @example + *
+     * $redis->lPush('l', 'v1', 'v2', 'v3', 'v4')   // int(4)
+     * var_dump( $redis->lRange('l', 0, -1) );
+     * //// Output:
+     * // array(4) {
+     * //   [0]=> string(2) "v4"
+     * //   [1]=> string(2) "v3"
+     * //   [2]=> string(2) "v2"
+     * //   [3]=> string(2) "v1"
+     * // }
+     * 
+ * @param string $key 键名 + * @param string $value 元素值 + * @return int + */ + public function lPush(string $key, string $value): int + { + + } + + /** + * + *从右侧(尾部)向列表插入元素 + * @example + *
+     * $redis->rPush('l', 'v1', 'v2', 'v3', 'v4');    // int(4)
+     * var_dump( $redis->lRange('l', 0, -1) );
+     * //// Output:
+     * // array(4) {
+     * //   [0]=> string(2) "v1"
+     * //   [1]=> string(2) "v2"
+     * //   [2]=> string(2) "v3"
+     * //   [3]=> string(2) "v4"
+     * // }
+     * 
+ * @param string $key 键名 + * @param string $value 元素值 + * @return int + */ + public function rPush(string $key, string $value): int + { + + } + + /** + * + *如果列表存在,从右侧(尾部)向列表插入元素 + * @example + *
+     * $redis->delete('key1');
+     * $redis->rPushx('key1', 'A'); // returns 0
+     * $redis->rPush('key1', 'A'); // returns 1
+     * $redis->rPushx('key1', 'B'); // returns 2
+     * $redis->rPushx('key1', 'C'); // returns 3
+     * // key1 now points to the following list: [ 'A', 'B', 'C' ]
+     * 
+ * @param string $key 键名 + * @param string $value 元素值 + * @return int + */ + public function rPushx(string $key, string $value): int + { + + } + + /** + * + *是否包含某个成员 + * @example + * @param string $key 键名 + * @param string $member 成员值 + * @return boolean + */ + public function sContains(string $key, string $member): boolean + { + + } + + /** + * + *是否包含某个成员 + * @example + * @param string $key 键名 + * @param string $member 成员值 + * @return boolean + */ + public function sismember(string $key, string $member): boolean + { + + } + + /** + * + *获取指定成员的排序值(分数) + * @example + *
+     * $redis->zAdd('key', 2.5, 'val2');
+     * $redis->zScore('key', 'val2'); // 2.5
+     * 
+ * @param string $key 集合键名 + * @param string $member 成员值 + * @return double + */ + public function zScore(string $key, string $member): double + { + + } + + /** + * + *获取成员的排序值 + * @example + *
+     * $redis->delete('z');
+     * $redis->zAdd('key', 1, 'one');
+     * $redis->zAdd('key', 2, 'two');
+     * $redis->zRank('key', 'one');     // 0
+     * $redis->zRank('key', 'two');     // 1
+     * $redis->zRevRank('key', 'one');  // 1
+     * $redis->zRevRank('key', 'two');  // 0
+     * 
+ * @param string $key 集合键名 + * @param string $member 成员值 + * @return int + */ + public function zRank(string $key, string $member): int + { + + } + + /** + * + *获取成员的排位值(倒数) + * @example + * @param string $key 集合键名 + * @param string $member 成员值 + * @return int + */ + public function zRevRank(string $key, string $member): int + { + + } + + /** + * + *获取字典的某个字段的值 + * @example + * @param string $key 键名 + * @param string $field 字段名 + * @return string + */ + public function hGet(string $key, string $field): string + { + + } + + /** + * + *批量获取字典的字段值 + * @example + * @param string $key 键名 + * @param array $fields 字段名列表 + * @return array + */ + public function hMGet(string $key, Array $fields): array + { + + } + + /** + * + *判断字典的某个字段是否存在. + * @example + *
+     * $redis->hSet('h', 'a', 'x');
+     * $redis->hExists('h', 'a');               //  TRUE
+     * $redis->hExists('h', 'NonExistingKey');  // FALSE
+     * 
+ * @param string $key 键名 + * @param string $field 字段名 + * @return bool + */ + public function hExists(string $key, string $field): bool + { + + } + + /** + * + *将消息发布到消息通道(队列). + * @example $redis->publish('chan-1', 'hello, world!'); // send message. + * @param string $channel 消息频道 + * @param string $message 消息 + * @return int + */ + public function publish(string $channel, string $message): int + { + + } + + /** + * + *给有序集合成员增加排序值 + * @example + *
+     * $redis->delete('key');
+     * $redis->zIncrBy('key', 2.5, 'member1');  // key or member1 didn't exist, so member1's score is to 0
+     * // before the increment and now has the value 2.5
+     * $redis->zIncrBy('key', 1, 'member1');    // 3.5
+     * 
+ * @param string $key 目标集合键名 + * @param double $step 增加的步长 + * @param string $member 成员 + * @return float + */ + public function zIncrBy(string $key, double $step, string $member): float + { + + } + + /** + * + *向有序集合插入元素 + * @example + *
+     * 
+     * $redis->zAdd('z', 1, 'v2', 2, 'v2', 3, 'v3', 4, 'v4' );  // int(2)
+     * $redis->zRem('z', 'v2', 'v3');                           // int(2)
+     * var_dump( $redis->zRange('z', 0, -1) );
+     * //// Output:
+     * // array(2) {
+     * //   [0]=> string(2) "v1"
+     * //   [1]=> string(2) "v4"
+     * // }
+     * 
+ *
+ * @param string $key 集合键名 + * @param double $score 排序值 + * @param string $value 元素值 + * @return int + */ + public function zAdd(string $key, double $score, string $value): int + { + + } + + /** + * + *根据排序值范围来删除成员 + * @example + * @param string $key 集合键名 + * @param double $start 开始排序值 + * @param double $end 结束排序值 + * @return int + */ + public function zDeleteRangeByScore(string $key, double $start, double $end): int + { + + } + + /** + * + *根据排序值范围来删除成员 + * @example + * @param string $key 集合键名 + * @param double $start 开始排序值 + * @param double $end 结束排序值 + * @return int + */ + public function zRemRangeByScore(string $key, double $start, double $end): int + { + + } + + /** + * + *获取指定排序范围的成员数. + * @example + *
+     * $redis->zAdd('key', 0, 'val0');
+     * $redis->zAdd('key', 2, 'val2');
+     * $redis->zAdd('key', 10, 'val10');
+     * $redis->zCount('key', 0, 3); // 2, corresponding to array('val0', 'val2')
+     * 
+ * @param string $key 集合键名 + * @param double $start 开始排序值 + * @param double $end 结束排序值 + * @return int + */ + public function zCount(string $key, double $start, double $end): int + { + + } + + /** + * + *获取有序集合中指定范围的成员 + * @example + *
+     * $redis->zAdd('key1', 0, 'val0');
+     * $redis->zAdd('key1', 2, 'val2');
+     * $redis->zAdd('key1', 10, 'val10');
+     * $redis->zRange('key1', 0, -1); // array('val0', 'val2', 'val10')
+     * // with scores
+     * $redis->zRange('key1', 0, -1, true); // array('val0' => 0, 'val2' => 2, 'val10' => 10)
+     * 
+ * @param string $key 集合键名 + * @param int $start 索引开始值 + * @param int $end 索引结束值 + * @param boolean $withScores 是否返回成员的排序值 + * @return array + */ + public function zRange(string $key, int $start, int $end, bool $withScores): array + { + + } + + /** + * + *获取有序集合中指定范围的成员(倒序排列) + * @example + *
+     * $redis->zAdd('key', 0, 'val0');
+     * $redis->zAdd('key', 2, 'val2');
+     * $redis->zAdd('key', 10, 'val10');
+     * $redis->zRevRange('key', 0, -1); // array('val10', 'val2', 'val0')
+     * // with scores
+     * $redis->zRevRange('key', 0, -1, true); // array('val10' => 10, 'val2' => 2, 'val0' => 0)
+     * 
+ * @param string $key 集合键名 + * @param int $start 索引开始值 + * @param int $end 索引结束值 + * @param boolean $withScores 是否返回成员的排序值 + * @return array + */ + public function zRevRange(string $key, int $start, int $end, bool $withScores): array + { + + } + + /** + * + *获取有序集合中指定范围的成员(按排序值排列) + * @example + *
+     * $redis->zAdd('key', 0, 'val0');
+     * $redis->zAdd('key', 2, 'val2');
+     * $redis->zAdd('key', 10, 'val10');
+     * $redis->zRangeByScore('key', 0, 3);                                          // array('val0', 'val2')
+     * $redis->zRangeByScore('key', 0, 3, array('withscores' => TRUE);              // array('val0' => 0, 'val2' => 2)
+     * $redis->zRangeByScore('key', 0, 3, array('limit' => array(1, 1));                        // array('val2' => 2)
+     * $redis->zRangeByScore('key', 0, 3, array('limit' => array(1, 1));                        // array('val2')
+     * $redis->zRangeByScore('key', 0, 3, array('withscores' => TRUE, 'limit' => array(1, 1));  // array('val2' => 2)
+     * 
+ * @param string $key 集合键名 + * @param int $start 索引开始值 + * @param int $end 索引结束值 + * @param array $options 附加选项(可以是:withscores => TRUE, and limit => array($offset, $count)) + * @return array + */ + public function zRangeByScore(string $key, int $start, int $end, Array $options): array + { + + } + + /** + * + *获取有序集合中指定范围的成员(按排序值倒序排列) + * @example + *
+     * $redis->zAdd('key', 0, 'val0');
+     * $redis->zAdd('key', 2, 'val2');
+     * $redis->zAdd('key', 10, 'val10');
+     * $redis->zRangeByScore('key', 0, 3);                                          // array('val0', 'val2')
+     * $redis->zRangeByScore('key', 0, 3, array('withscores' => TRUE);              // array('val0' => 0, 'val2' => 2)
+     * $redis->zRangeByScore('key', 0, 3, array('limit' => array(1, 1));                        // array('val2' => 2)
+     * $redis->zRangeByScore('key', 0, 3, array('limit' => array(1, 1));                        // array('val2')
+     * $redis->zRangeByScore('key', 0, 3, array('withscores' => TRUE, 'limit' => array(1, 1));  // array('val2' => 2)
+     * 
+ * @param string $key 集合键名 + * @param int $start 索引开始值 + * @param int $end 索引结束值 + * @param array $options 附加选项(可以是:withscores => TRUE, and limit => array($offset, $count)) + * @return array + */ + public function zRevRangeByScore(string $key, int $start, int $end, Array $options): array + { + + } + + /** + * + *按字母字典的顺序返回成员 + * @example + *
+     * foreach (array('a', 'b', 'c', 'd', 'e', 'f', 'g') as $char) {
+     * $redis->zAdd('key', $char);
+     * }
+     * $redis->zRangeByLex('key', '-', '[c'); // array('a', 'b', 'c')
+     * $redis->zRangeByLex('key', '-', '(c'); // array('a', 'b')
+     * $redis->zRangeByLex('key', '-', '[c'); // array('b', 'c')
+     * 
+ * @param string $key 集合键名 + * @param int $min 最小的字母 + * @param int $max 最大的字母 + * @param int $offset 索引开始值 + * @param int $limit 成员数 + * @return array + */ + public function zRangeByLex(string $key, int $min, int $max, int $offset, int $limit): array + { + + } + + /** + * + *按字母字典的顺序返回成员(倒序排序) + * @example + * @param string $key 集合键名 + * @param int $min 最小的字母 + * @param int $max 最大的字母 + * @param int $offset 索引开始值 + * @param int $limit 成员数 + * @return + */ + public function zRevRangeByLex(string $key, int $min, int $max, int $offset, int $limit) + { + + } + + /** + * + *将两个有序集合的交集存入到一个指定的键中 + * @example + *
+     * $redis->delete('k1');
+     * $redis->delete('k2');
+     * $redis->delete('k3');
+     * $redis->delete('ko1');
+     * $redis->delete('ko2');
+     * $redis->delete('ko3');
+     * $redis->delete('ko4');
+     * $redis->zAdd('k1', 0, 'val0');
+     * $redis->zAdd('k1', 1, 'val1');
+     * $redis->zAdd('k1', 3, 'val3');
+     * $redis->zAdd('k2', 2, 'val1');
+     * $redis->zAdd('k2', 3, 'val3');
+     * $redis->zInter('ko1', array('k1', 'k2'));               // 2, 'ko1' => array('val1', 'val3')
+     * $redis->zInter('ko2', array('k1', 'k2'), array(1, 1));  // 2, 'ko2' => array('val1', 'val3')
+     * // Weighted zInter
+     * $redis->zInter('ko3', array('k1', 'k2'), array(1, 5), 'min'); // 2, 'ko3' => array('val1', 'val3')
+     * $redis->zInter('ko4', array('k1', 'k2'), array(1, 5), 'max'); // 2, 'ko4' => array('val3', 'val1')
+     * 
+ * @param string $dstKey 目标集合键名 + * @param array $zsetKeys 集合键名 + * @param array $zsetKeysWeight 集合键对应的权重 + * @param string $aggregateFunction 合并使用的函数(SUM, MIN, 或 MAX) + * @return int + */ + public function zInter(string $dstKey, Array $zsetKeys, Array $zsetKeysWeight, string $aggregateFunction): int + { + + } + + /** + * + *将两个有序集合的交集存入到一个指定的键中 + * @example + *
+     * $redis->delete('k1');
+     * $redis->delete('k2');
+     * $redis->delete('k3');
+     * $redis->delete('ko1');
+     * $redis->delete('ko2');
+     * $redis->delete('ko3');
+     * $redis->delete('ko4');
+     * $redis->zAdd('k1', 0, 'val0');
+     * $redis->zAdd('k1', 1, 'val1');
+     * $redis->zAdd('k1', 3, 'val3');
+     * $redis->zAdd('k2', 2, 'val1');
+     * $redis->zAdd('k2', 3, 'val3');
+     * $redis->zInter('ko1', array('k1', 'k2'));               // 2, 'ko1' => array('val1', 'val3')
+     * $redis->zInter('ko2', array('k1', 'k2'), array(1, 1));  // 2, 'ko2' => array('val1', 'val3')
+     * // Weighted zInter
+     * $redis->zInter('ko3', array('k1', 'k2'), array(1, 5), 'min'); // 2, 'ko3' => array('val1', 'val3')
+     * $redis->zInter('ko4', array('k1', 'k2'), array(1, 5), 'max'); // 2, 'ko4' => array('val3', 'val1')
+     * 
+ * @param string $dstKey 目标集合键名 + * @param array $zsetKeys 集合键名 + * @param array $zsetKeysWeight 集合键对应的权重 + * @param string $aggregateFunction 合并使用的函数(SUM, MIN, 或 MAX) + * @return int + */ + public function zinterstore(string $dstKey, Array $zsetKeys, Array $zsetKeysWeight, string $aggregateFunction): int + { + + } + + /** + * + *将两个有序集合的并集存入到一个指定的键中 + * @example + *
+     * $redis->delete('k1');
+     * $redis->delete('k2');
+     * $redis->delete('k3');
+     * $redis->delete('ko1');
+     * $redis->delete('ko2');
+     * $redis->delete('ko3');
+     * $redis->zAdd('k1', 0, 'val0');
+     * $redis->zAdd('k1', 1, 'val1');
+     * $redis->zAdd('k2', 2, 'val2');
+     * $redis->zAdd('k2', 3, 'val3');
+     * $redis->zUnion('ko1', array('k1', 'k2')); // 4, 'ko1' => array('val0', 'val1', 'val2', 'val3')
+     * // Weighted zUnion
+     * $redis->zUnion('ko2', array('k1', 'k2'), array(1, 1)); // 4, 'ko2' => array('val0', 'val1', 'val2', 'val3')
+     * $redis->zUnion('ko3', array('k1', 'k2'), array(5, 1)); // 4, 'ko3' => array('val0', 'val2', 'val3', 'val1')
+     * 
+ * @param string $dstKey 目标集合键名 + * @param array $zsetKeys 集合键名 + * @param array $zsetKeysWeight 集合键对应的权重 + * @param string $aggregateFunction 合并使用的函数(SUM, MIN, 或 MAX) + * @return int + */ + public function zUnion(string $dstKey, Array $zsetKeys, Array $zsetKeysWeight, string $aggregateFunction): int + { + + } + + /** + * + *将两个有序集合的并集存入到一个指定的键中 + * @example + *
+     * $redis->delete('k1');
+     * $redis->delete('k2');
+     * $redis->delete('k3');
+     * $redis->delete('ko1');
+     * $redis->delete('ko2');
+     * $redis->delete('ko3');
+     * $redis->zAdd('k1', 0, 'val0');
+     * $redis->zAdd('k1', 1, 'val1');
+     * $redis->zAdd('k2', 2, 'val2');
+     * $redis->zAdd('k2', 3, 'val3');
+     * $redis->zUnion('ko1', array('k1', 'k2')); // 4, 'ko1' => array('val0', 'val1', 'val2', 'val3')
+     * // Weighted zUnion
+     * $redis->zUnion('ko2', array('k1', 'k2'), array(1, 1)); // 4, 'ko2' => array('val0', 'val1', 'val2', 'val3')
+     * $redis->zUnion('ko3', array('k1', 'k2'), array(5, 1)); // 4, 'ko3' => array('val0', 'val2', 'val3', 'val1')
+     * 
+ * @param string $dstKey 目标集合键名 + * @param array $zsetKeys 集合键名 + * @param array $zsetKeysWeight 集合键对应的权重 + * @param string $aggregateFunction 合并使用的函数(SUM, MIN, 或 MAX) + * @return int + */ + public function zunionstore(string $dstKey, Array $zsetKeys, Array $zsetKeysWeight, string $aggregateFunction): int + { + + } + + /** + * + *按指定步长自增 + * @example + *
+     * $redis->incr('key1');        // key1 didn't exists, set to 0 before the increment and now has the value 1
+     * $redis->incr('key1');        // 2
+     * $redis->incr('key1');        // 3
+     * $redis->incr('key1');        // 4
+     * $redis->incrBy('key1', 10);  // 14
+     * 
+ * @param string $key 键名 + * @param int $step 自增步长 + * @return int + */ + public function incrBy(string $key, int $step): int + { + + } + + /** + * + *为指定字段增加指定的值. + * @example + *
+     * $redis->delete('h');
+     * $redis->hIncrBy('h', 'x', 2); // returns 2: h[x] = 2 now.
+     * $redis->hIncrBy('h', 'x', 1); // h[x] ← 2 + 1. Returns 3
+     * 
+ * @param string $key 键名 + * @param string $field 字段名 + * @param int $step 自增步长 + * @return int + */ + public function hIncrBy(string $key, string $field, int $step): int + { + + } + + /** + * + *键值自增 + * @example + *
+     * $redis->incr('key1'); // key1 didn't exists, set to 0 before the increment and now has the value 1
+     * $redis->incr('key1'); // 2
+     * $redis->incr('key1'); // 3
+     * $redis->incr('key1'); // 4
+     * 
+ * @param string $key 键名 + * @return int + */ + public function incr(string $key): int + { + + } + + /** + * + *按指定步长自减 + * @example + *
+     * $redis->decr('key1');        // key1 didn't exists, set to 0 before the increment and now has the value -1
+     * $redis->decr('key1');        // -2
+     * $redis->decr('key1');        // -3
+     * $redis->decrBy('key1', 10);  // -13
+     * 
+ * @param string $key 键名 + * @param float $step 自减步长 + * @return int + */ + public function decrBy(string $key, float $step): int + { + + } + + /** + * + *键值自减 + * @example + *
+     * $redis->decr('key1'); // key1 didn't exists, set to 0 before the increment and now has the value -1
+     * $redis->decr('key1'); // -2
+     * $redis->decr('key1'); // -3
+     * 
+ * @param string $key 键名 + * @return int + */ + public function decr(string $key): int + { + + } + + /** + * + *获取某个键的某个位置的位值 + * @example + *
+     * $redis->set('key', "\x7f");  // this is 0111 1111
+     * $redis->getBit('key', 0);    // 0
+     * $redis->getBit('key', 1);    // 1
+     * 
+ * @param string $key 键名 + * @param int $offset 所在位置 + * @return int + */ + public function getBit(string $key, int $offset): int + { + + } + + /** + * + *在列表中,在某个元素的前面或后面插入一个新值 + * @example + *
+     * $redis->delete('key1');
+     * $redis->lInsert('key1', Redis::AFTER, 'A', 'X');     // 0
+     * $redis->lPush('key1', 'A');
+     * $redis->lPush('key1', 'B');
+     * $redis->lPush('key1', 'C');
+     * $redis->lInsert('key1', Redis::BEFORE, 'C', 'X');    // 4
+     * $redis->lRange('key1', 0, -1);                       // array('A', 'B', 'X', 'C')
+     * $redis->lInsert('key1', Redis::AFTER, 'C', 'Y');     // 5
+     * $redis->lRange('key1', 0, -1);                       // array('A', 'B', 'X', 'C', 'Y')
+     * $redis->lInsert('key1', Redis::AFTER, 'W', 'value'); // -1
+     * 
+ * @param string $key 键名 + * @param string $position 位置(前面或后面,使用Redis::BEFORE | Redis::AFTER) + * @param string $element 元素 + * @param string $value 新值 + * @return int + */ + public function lInsert(string $key, string $position, string $element, string $value): int + { + + } + + /** + * + *获取列表中指定索引的值 + * @example + * @param string $key 键名 + * @param int $index 索引值 + * @return string | boolean + */ + public function lGet(string $key, int $index): ?string + { + + } + + /** + * + *获取列表中指定索引的值 + * @example + * @param string $key 键名 + * @param int $index 索引值 + * @return string | boolean + */ + public function lIndex(string $key, int $index): ?string + { + + } + + /** + * + *设置键的有效期 + * @example + * @param string $key 键名 + * @param int $ttl 有效期(秒数) + * @return boolean + */ + public function setTimeout(string $key, int $ttl): boolean + { + + } + + /** + * + *设置键的有效期 + * @example + * @param string $key 键名 + * @param int $ttl 有效期(秒数) + * @return boolean + */ + public function expire(string $key, int $ttl): boolean + { + + } + + /** + * + *设置键的有效期(毫秒为单位) + * @example + * @param string $key 键名 + * @param int $ttl 有效期(毫秒数) + * @return boolean + */ + public function pexpire(string $key, int $ttl): boolean + { + + } + + /** + * + *为某个键设置有效期为某个时间点 + * @example + *
+     * $redis->set('x', '42');
+     * $now = time(NULL);               // current timestamp
+     * $redis->expireAt('x', $now + 3); // x will disappear in 3 seconds.
+     * sleep(5);                        // wait 5 seconds
+     * $redis->get('x');                // will return `FALSE`, as 'x' has expired.
+     * 
+ * @param string $key 键名 + * @param int $expireTime 到期时间 + * @return bool + */ + public function expireAt(string $key, int $expireTime): bool + { + + } + + /** + * + *为某个键设置有效期为某个时间点(精确到毫秒) + * @example + *
+     * $redis->set('x', '42');
+     * $now = time(NULL);               // current timestamp
+     * $redis->expireAt('x', $now + 3); // x will disappear in 3 seconds.
+     * sleep(5);                        // wait 5 seconds
+     * $redis->get('x');                // will return `FALSE`, as 'x' has expired.
+     * 
+ * @param string $key 键名 + * @param int $expireTime 到期时间 + * @return bool + */ + public function pexpireAt(string $key, int $expireTime): bool + { + + } + + /** + * + *将某个键移动到其他数据库中 + * @example + *
+     * $redis->select(0);       // switch to DB 0
+     * $redis->set('x', '42');  // write 42 to x
+     * $redis->move('x', 1);    // move to DB 1
+     * $redis->select(1);       // switch to DB 1
+     * $redis->get('x');        // will return 42
+     * 
+ * @param string $key 键名 + * @param int $dbIndex 数据库编号 + * @return bool + */ + public function move(string $key, int $dbIndex): bool + { + + } + + /** + * + *切换数据库 + * @example + *
+     * $redis->select(0);       // switch to DB 0
+     * $redis->set('x', '42');  // write 42 to x
+     * $redis->move('x', 1);    // move to DB 1
+     * $redis->select(1);       // switch to DB 1
+     * $redis->get('x');        // will return 42
+     * 
+ * @param int $dbIndex 数据库编号 + * @return bool + */ + public function select(int $dbIndex): bool + { + + } + + /** + * + *获取一个键值的子字符串 + * @example + *
+     * $redis->set('key', 'string value');
+     * $redis->getRange('key', 0, 5);   // 'string'
+     * $redis->getRange('key', -5, -1); // 'value'
+     * 
+ * @param string $key 键名 + * @param int $start 开始位置 + * @param int $end 结束位置 + * @return string + */ + public function getRange(string $key, int $start, int $end): string + { + + } + + /** + * + *删除指定范围外的其他元素 + * @example + * @param string $key 键名 + * @param int $start 开始索引 + * @param int $end 结束索引 + * @return array | boolean + */ + public function listTrim(string $key, int $start, int $end): ?array + { + + } + + /** + * + *删除指定范围外的其他元素 + * @example + * @param string $key 键名 + * @param int $start 开始索引 + * @param int $end 结束索引 + * @return array | boolean + */ + public function ltrim(string $key, int $start, int $end): ?array + { + + } + + /** + * + *获取列表指定范围的值 + * @example + * @param string $key 键名 + * @param int $start 索引开始值 + * @param int $end 索引结束值 + * @return array + */ + public function lGetRange(string $key, int $start, int $end): array + { + + } + + /** + * + *获取列表指定范围的值 + * @example + * @param string $key 键名 + * @param int $start 索引开始值 + * @param int $end 索引结束值 + * @return array + */ + public function lRange(string $key, int $start, int $end): array + { + + } + + /** + * + *从列表中删除指定值的元素。 如果count为零,则删除所有匹配的元素。 如果计数是负数,则元素从尾部移到头部。 + * @example + * @param string $key 键名 + * @param string $value 元素值 + * @param int $count 删除的个数 + * @return int | bool + */ + public function lRem(string $key, string $value, int $count): ?int + { + + } + + /** + * + *从列表中删除指定值的元素。 如果count为零,则删除所有匹配的元素。 如果计数是负数,则元素从尾部移到头部。 + * @example + * @param string $key 键名 + * @param string $value 元素值 + * @param int $count 删除的个数 + * @return int | bool + */ + public function lRemove(string $key, string $value, int $count): ?int + { + + } + + /** + * + *根据排序范围删除成员 + * @example + *
+     * $redis->zAdd('key', 1, 'one');
+     * $redis->zAdd('key', 2, 'two');
+     * $redis->zAdd('key', 3, 'three');
+     * $redis->zRemRangeByRank('key', 0, 1); // 2
+     * $redis->zRange('key', 0, -1, array('withscores' => TRUE)); // array('three' => 3)
+     * 
+ * @param string $key 集合键名 + * @param double $start 开始排序值 + * @param double $end 结束排序值 + * @return int + */ + public function zDeleteRangeByRank(string $key, double $start, double $end): int + { + + } + + /** + * + *根据排序范围删除成员 + * @example + *
+     * $redis->zAdd('key', 1, 'one');
+     * $redis->zAdd('key', 2, 'two');
+     * $redis->zAdd('key', 3, 'three');
+     * $redis->zRemRangeByRank('key', 0, 1); // 2
+     * $redis->zRange('key', 0, -1, array('withscores' => TRUE)); // array('three' => 3)
+     * 
+ * @param string $key 集合键名 + * @param double $start 开始排序值 + * @param double $end 结束排序值 + * @return int + */ + public function zRemRangeByRank(string $key, double $start, double $end): int + { + + } + + /** + * + *按指定步长自增 + * @example + *
+     * $redis = new Redis();
+     * $redis->connect('127.0.0.1');
+     * $redis->set('x', 3);
+     * var_dump( $redis->incrByFloat('x', 1.5) );   // float(4.5)
+     * // ! SIC
+     * var_dump( $redis->get('x') );                // string(3) "4.5"
+     * 
+ * @param string $key 键名 + * @param float $step 自增步长 + * @return float + */ + public function incrByFloat(string $key, float $step): float + { + + } + + /** + * + *为指定字段增加指定的值 + * @example + *
+     * $redis = new Redis();
+     * $redis->connect('127.0.0.1');
+     * $redis->hset('h', 'float', 3);
+     * $redis->hset('h', 'int',   3);
+     * var_dump( $redis->hIncrByFloat('h', 'float', 1.5) ); // float(4.5)
+     * var_dump( $redis->hGetAll('h') );
+     * // Output
+     * array(2) {
+     * ["float"]=>
+     * string(3) "4.5"
+     * ["int"]=>
+     * string(1) "3"
+     * }
+     * 
+ * @param string $key 键名 + * @param string $field 字段名 + * @param double $step 自增步长 + * @return + */ + public function hIncrByFloat(string $key, string $field, double $step) + { + + } + + /** + * + *统计字符串的位数 + * @example + * @param string $key 键名 + * @return int + */ + public function bitCount(string $key): int + { + + } + + /** + * + *多个键的位操作,并将结果存入到指定的键中 + * @example + * @param string $operation 操作(有 AND, OR, NOT, XOR 4种可选择) + * @param string $dstKey 目标键 + * @param string $key1 键名1 + * @param string $key2 键名2 + * @param string|... $keyN 键名N + * @return int + */ + public function bitOp(string $operation, string $dstKey, string $key1, string $key2, string $keyN): int + { + + } + + /** + * + *给集合添加元素 + * @example + *
+     * $redis->sAdd('k', 'v1');                // int(1)
+     * $redis->sAdd('k', 'v1', 'v2', 'v3');    // int(2)
+     * 
+ * @param string $key 键名 + * @param string $value 元素值 + * @return int + */ + public function sAdd(string $key, string $value): int + { + + } + + /** + * + *将某个集合中的元素移动到另外一个集合中 + * @example + *
+     * $redis->sAdd('key1' , 'set11');
+     * $redis->sAdd('key1' , 'set12');
+     * $redis->sAdd('key1' , 'set13');          // 'key1' => {'set11', 'set12', 'set13'}
+     * $redis->sAdd('key2' , 'set21');
+     * $redis->sAdd('key2' , 'set22');          // 'key2' => {'set21', 'set22'}
+     * $redis->sMove('key1', 'key2', 'set13');  // 'key1' =>  {'set11', 'set12'}
+     * // 'key2' =>  {'set21', 'set22', 'set13'}
+     * 
+ * @param string $srcKey 原集合键名 + * @param string $dstKey 目标集合键名 + * @param string $member 成员 + * @return bool + */ + public function sMove(string $srcKey, string $dstKey, string $member): bool + { + + } + + /** + * + *获取多个集合的差集 + * @example + *
+     * $redis->delete('s0', 's1', 's2');
+     * $redis->sAdd('s0', '1');
+     * $redis->sAdd('s0', '2');
+     * $redis->sAdd('s0', '3');
+     * $redis->sAdd('s0', '4');
+     * $redis->sAdd('s1', '1');
+     * $redis->sAdd('s2', '3');
+     * var_dump($redis->sDiff('s0', 's1', 's2'));
+     * //array(2) {
+     * //  [0]=>
+     * //  string(1) "4"
+     * //  [1]=>
+     * //  string(1) "2"
+     * //}
+     * 
+ * @param string $key1 键名1 + * @param string|... $key2 键名2 + * @return array + */ + public function sDiff(string $key1, string $key2): array + { + + } + + /** + * + *获取多个集合的差集,并将结果存入到一个新的集合中 + * @example + *
+     * $redis->delete('s0', 's1', 's2');
+     * $redis->sAdd('s0', '1');
+     * $redis->sAdd('s0', '2');
+     * $redis->sAdd('s0', '3');
+     * $redis->sAdd('s0', '4');
+     * $redis->sAdd('s1', '1');
+     * $redis->sAdd('s2', '3');
+     * var_dump($redis->sDiffStore('dst', 's0', 's1', 's2'));
+     * var_dump($redis->sMembers('dst'));
+     * //int(2)
+     * //array(2) {
+     * //  [0]=>
+     * //  string(1) "4"
+     * //  [1]=>
+     * //  string(1) "2"
+     * //}
+     * 
+ * @param string $dstKey 目标键,存放结果的键 + * @param string $key1 键名1 + * @param string $key2 键名2 + * @param string|... $keyN 键名n + * @return int + */ + public function sDiffStore(string $dstKey, string $key1, string $key2, string $keyN): int + { + + } + + /** + * + *获取集合的并集 + * @example + *
+     * $redis->delete('s0', 's1', 's2');
+     * $redis->sAdd('s0', '1');
+     * $redis->sAdd('s0', '2');
+     * $redis->sAdd('s1', '3');
+     * $redis->sAdd('s1', '1');
+     * $redis->sAdd('s2', '3');
+     * $redis->sAdd('s2', '4');
+     * var_dump($redis->sUnion('s0', 's1', 's2'));
+     * array(4) {
+     * //  [0]=>
+     * //  string(1) "3"
+     * //  [1]=>
+     * //  string(1) "4"
+     * //  [2]=>
+     * //  string(1) "1"
+     * //  [3]=>
+     * //  string(1) "2"
+     * //}
+     * 
+ * @param string $key1 键名1 + * @param string|... $key2 键名2 + * @return array + */ + public function sUnion(string $key1, string $key2): array + { + + } + + /** + * + *获取多个集合的并集,并将结果存入到另外一个集合中 + * @example + *
+     * $redis->delete('s0', 's1', 's2');
+     * $redis->sAdd('s0', '1');
+     * $redis->sAdd('s0', '2');
+     * $redis->sAdd('s1', '3');
+     * $redis->sAdd('s1', '1');
+     * $redis->sAdd('s2', '3');
+     * $redis->sAdd('s2', '4');
+     * var_dump($redis->sUnionStore('dst', 's0', 's1', 's2'));
+     * var_dump($redis->sMembers('dst'));
+     * //int(4)
+     * //array(4) {
+     * //  [0]=>
+     * //  string(1) "3"
+     * //  [1]=>
+     * //  string(1) "4"
+     * //  [2]=>
+     * //  string(1) "1"
+     * //  [3]=>
+     * //  string(1) "2"
+     * //}
+     * 
+ * @param string $dstKey 目标键,存放结果的键 + * @param string $key1 键名1 + * @param string $key2 键名2 + * @param string|... $keyN 键名n + * @return int + */ + public function sUnionStore(string $dstKey, string $key1, string $key2, string $keyN): int + { + + } + + /** + * + *获取两个集合的交集 + * @example + *
+     * $redis->sAdd('key1', 'val1');
+     * $redis->sAdd('key1', 'val2');
+     * $redis->sAdd('key1', 'val3');
+     * $redis->sAdd('key1', 'val4');
+     * $redis->sAdd('key2', 'val3');
+     * $redis->sAdd('key2', 'val4');
+     * $redis->sAdd('key3', 'val3');
+     * $redis->sAdd('key3', 'val4');
+     * var_dump($redis->sInter('key1', 'key2', 'key3'));
+     * //array(2) {
+     * //  [0]=>
+     * //  string(4) "val4"
+     * //  [1]=>
+     * //  string(4) "val3"
+     * //}
+     * 
+ * @param string $key1 键名1 + * @param string $key2 键名2 + * @return array | boolean + */ + public function sInter(string $key1, string $key2): ?array + { + + } + + /** + * + *获取多个集合的交集,并将结果存入到另外一个集合中 + * @example + *
+     * $redis->sAdd('key1', 'val1');
+     * $redis->sAdd('key1', 'val2');
+     * $redis->sAdd('key1', 'val3');
+     * $redis->sAdd('key1', 'val4');
+     * $redis->sAdd('key2', 'val3');
+     * $redis->sAdd('key2', 'val4');
+     * $redis->sAdd('key3', 'val3');
+     * $redis->sAdd('key3', 'val4');
+     * var_dump($redis->sInterStore('output', 'key1', 'key2', 'key3'));
+     * var_dump($redis->sMembers('output'));
+     * //int(2)
+     * //
+     * //array(2) {
+     * //  [0]=>
+     * //  string(4) "val4"
+     * //  [1]=>
+     * //  string(4) "val3"
+     * //}
+     * 
+ * @param string $dstKey 目标键,存放结果的键 + * @param string $key1 键名1 + * @param string $key2 键名2 + * @param string|... $keyN 键名n + * @return int + */ + public function sInterStore(string $dstKey, string $key1, string $key2, string $keyN): int + { + + } + + /** + * + *删除集合元素 + * @example + * @param string $key 键名 + * @param string|... $member 成员 + * @return int + */ + public function sRemove(string $key, string $member): int + { + + } + + /** + * + *删除集合元素 + * @example + * @param string $key 键名 + * @param string|... $member 成员 + * @return int + */ + public function srem(string $key, string $member): int + { + + } + + /** + * + *删除有序集合中的某个成员 + * @example + * @param string $key 集合键名 + * @param string $member 成员值 + * @return int + */ + public function zDelete(string $key, string $member): int + { + + } + + /** + * + *删除有序集合中的某个成员 + * @example + * @param string $key 集合键名 + * @param string $member 成员值 + * @return int + */ + public function zRemove(string $key, string $member): int + { + + } + + /** + * + *删除有序集合中的某个成员 + * @example + * @param string $key 集合键名 + * @param string $member 成员值 + * @return int + */ + public function zRem(string $key, string $member): int + { + + } + + /** + * + *通过匹配模式来订阅这些匹配的消息频道 + * @example + *
+     * function psubscribe($redis, $pattern, $chan, $msg) {
+     * echo "Pattern: $pattern\n";
+     * echo "Channel: $chan\n";
+     * echo "Payload: $msg\n";
+     * }
+     * 
+ * @param array $patterns 匹配模式 + * @param string|array $callback 回调函数名称 + * @param mixed $value 返回值 + * @return + */ + public function pSubscribe(Array $patterns, string $callback, $value) + { + + } + + /** + * + *订阅消息 + * @example + *
+     * function f($redis, $chan, $msg) {
+     * switch($chan) {
+     * case 'chan-1':
+     * ...
+     * break;
+     * case 'chan-2':
+     * ...
+     * break;
+     * case 'chan-2':
+     * ...
+     * break;
+     * }
+     * }
+     * $redis->subscribe(array('chan-1', 'chan-2', 'chan-3'), 'f'); // subscribe to 3 chans
+     * 
+ * @param array $channels 订阅的消息频道 + * @param string|array $callback 回调函数名称 + * @param mixed $value 返回值 + * @return mixed + */ + public function subscribe(Array $channels, string $callback, $value) + { + + } + + /** + * + *开始一个事务. + * @example + *
+     * $ret = $redis->multi()
+     * ->set('key1', 'val1')
+     * ->get('key1')
+     * ->set('key2', 'val2')
+     * ->get('key2')
+     * ->exec();
+     * //$ret == array (
+     * //    0 => TRUE,
+     * //    1 => 'val1',
+     * //    2 => TRUE,
+     * //    3 => 'val2');
+     * 
+ * @return + */ + public function multi() + { + + } + + /** + * + *执行事务 + * @example + * @return + */ + public function exec() + { + + } + + /** + * + *执行lua脚本 + * @example + * @param string $script 脚本 + * @param array $args 脚本参数 + * @param int $num_keys 应该进入KEYS数组的参数个数 + * @return mixed + */ + public function eval(string $script, Array $args, int $num_keys) + { + + } + + /** + * + *从脚本的SHA1散列而不是脚本本身执行LUA脚本 + * @example $script = 'return 1'; + * $sha = $redis->script('load', $script); + * $redis->evalSha($sha); // Returns 1 + * @param string $script_sha 脚本的散列值 + * @param array $args 脚本参数 + * @param int $num_keys 应该进入KEYS数组的参数个数 + * @return + */ + public function evalSha(string $script_sha, Array $args, int $num_keys) + { + + } + + /** + * + *在脚本子系统上执行redis命令 + * @example + *
+     * $redis->script('load', $script);
+     * $redis->script('flush');
+     * $redis->script('kill');
+     * $redis->script('exists', $script1, [$script2, $script3, ...]);
+     * 
+ * SCRIPT LOAD will return the SHA1 hash of the passed script on success, and FALSE on failure. + * SCRIPT FLUSH should always return TRUE + * SCRIPT KILL will return true if a script was able to be killed and false if not + * SCRIPT EXISTS will return an array with TRUE or FALSE for each passed script + * @param string $command redis命令 + * @param string|... $script 脚本 + * @return + */ + public function script(string $command, string $script) + { + + } + + /** + * + *序列化函数调用的魔术方法(在PHP进行序列化时,serialize() 检查类中是否有 __sleep() ,如果有,则该函数将在任何序列化之前运行。该函数必须返回一个需要进行序列化保存的成员属性数组,并且只序列化该函数返回的这些成员属性. 该函数有两个作用: 第一. 在序列化之前,关闭对象可能具有的任何数据库连接等. 第二. 指定对象中需要被序列化的成员属性,如果某个属性比较大而不需要储存下来,可以不把它写进__sleep要返回的数组中,这样该属性就不会被序列化) + * @example + * @return + */ + public function __sleep() + { + + } + + /** + * + *反序列化函数调用的魔术方法(unserialize() 从字节流中创建了一个对象之后,马上检查是否具有__wakeup 的函数的存在。如果存在,__wakeup 立刻被调用。使用 __wakeup 的目的是重建在序列化中可能丢失的任何数据库连接以及处理其它重新初始化的任务) + * @example + * @return + */ + public function __wakeup() + { + + } + +} + diff --git a/src/Swoole/Co/Redis/Server.php b/src/Swoole/Co/Redis/Server.php new file mode 100644 index 0000000..b951bd3 --- /dev/null +++ b/src/Swoole/Co/Redis/Server.php @@ -0,0 +1,801 @@ +finish()方法将任务处理的结果发送给worker进程。 + * @access public + */ + public $onFinish; + + /** + * @var callable $onManagerStart + * 当管理进程启动时调用它 + * @access public + */ + public $onManagerStart; + + /** + * @var callable $onManagerStop + * 当管理进程结束时调用它 + * @access public + */ + public $onManagerStop; + + /** + * @var callable $onPipeMessage + * 当工作进程收到由 sendMessage 发送的管道消息时会触发onPipeMessage事件 + * @access public + */ + public $onPipeMessage; + + /** + * @var array $setting + * 通过swoole_server:set()设置的参数会保存到setting属性上 + * @access public + */ + public $setting = array(); + + /** + * @var iterator $connections + * TCP连接迭代器 + * @access public + */ + public $connections; + + /** + * @var string $host + * 连接的主机 + * @access public + */ + public $host; + + /** + * @var int $port + * 连接的主机的端口 + * @access public + */ + public $port = 0; + + /** + * @var int $type + * socket的类型 + * @access public + */ + public $type = 0; + + /** + * @var int $mode + * 运行模式(swoole提供了3种运行模式,默认为SWOOLE_PROCESS多进程模式) + * @access public + */ + public $mode = 0; + + /** + * @var array $ports + * 当监听多端口时的端口列表 + * @access public + */ + public $ports = array(); + + /** + * @var int $master_pid + * 主进程ID + * @access public + */ + public $master_pid = 0; + + /** + * @var int $manager_pid + * 管理进程ID + * @access public + */ + public $manager_pid = 0; + + /** + * @var int $worker_id + * 当前工作进程(包括worker进程和task进程)编号 + * @access public + */ + public $worker_id = -1; + + /** + * @var boolean $taskworker + * 当前进程是否是task工作进程 + * @access public + */ + public $taskworker = ''; + + /** + * @var int $worker_pid + * 当前工作进程ID(操作系统进程) + * @access public + */ + public $worker_pid = 0; + + /** + * + *启动server + * @example + * @return + */ + public function start() + { + + } + + /** + * + *设置Redis命令字的处理器 + * @example + * @param string $command 命令的名称 + * @param callable $callback 命令的处理函数,回调函数返回字符串类型时会自动发送给客户端 + * @param int $number_of_string_param 字符串参数的长度 + * @param int $type_of_array_param 数组参数元素的类型 + * @return + */ + public function setHandler(string $command, Callable $callback, int $number_of_string_param, int $type_of_array_param) + { + + } + + /** + * + *格式化命令响应数据 + * @example + * @param int $type 表示数据类型,NIL类型不需要传入$value,ERROR和STATUS类型$value可选,INT、STRING、SET、MAP必选 + * @param mixed $value 要处理的数据 + * @return + */ + public static function format(int $type, $value) + { + + } + + /** + * + *swoole_server初始化方法 + * @example + * @param string $host 主机IP + * @param int $port 端口 + * @param int $mode 运行模式 + * @param int $sock_type socket类型 + * @return + */ + public function __construct(string $host, int $port, int $mode, int $sock_type) + { + + } + + /** + * + *析构函数 + * @example + * @return + */ + public function __destruct() + { + + } + + /** + * + *添加监听端口(是addlistener的别名) + * @example + * @param string $host 监听的主机 + * @param int $port 监听的端口号 + * @param int $sock_type socket类型 + * @return + */ + public function listen(string $host, int $port, int $sock_type) + { + + } + + /** + * + *添加监听端口 + * @example + * @param string $host 监听的主机 + * @param int $port 监听的端口号 + * @param int $sock_type socket类型 + * @return + */ + public function addlistener(string $host, int $port, int $sock_type) + { + + } + + /** + * + *绑定事件(为事件注册函数) + * @example + * @param string $event_name 事件名称 + * @param callable $callback 事件对应的回调函数 + * @return + */ + public function on(string $event_name, Callable $callback) + { + + } + + /** + * + *设置swoole_server运行时的参数 + * @example + * @param array $settings 配置选项 + * @return + */ + public function set(Array $settings) + { + + } + + /** + * + *向客户端发送数据 + * @example + * @param int $fd 连接句柄 + * @param string $send_data 发送的数据 + * @param int $reactor_id UDP服务器使用$fd保存客户端IP,$extraData保存server_fd和port + * @return + */ + public function send(int $fd, string $send_data, int $reactor_id) + { + + } + + /** + * + *向任意客户端发送UDP数据包 + * @example + * @param string $ip IPv4字符串,如192.168.1.102。如果IP不合法会返回错误 + * @param int $port 为 1-65535的网络端口号,如果端口错误发送会失败 + * @param string $send_data 发送的数据内容,可以是文本或者二进制内容 + * @param int $server_socket 服务器可能会同时监听多个UDP端口,此参数可以指定使用哪个端口发送数据包 + * @return + */ + public function sendto(string $ip, int $port, string $send_data, int $server_socket) + { + + } + + /** + * + *阻塞的向客户端发送数据 + * @example + * @param int $conn_fd 与客户端连接的句柄 + * @param string $send_data 发送的数据 + * @return + */ + public function sendwait(int $conn_fd, string $send_data) + { + + } + + /** + * + *检测fd对应的连接是否存在 + * @example + * @param int $fd 连接句柄 + * @return + */ + public function exist(int $fd) + { + + } + + /** + * + *设置客户端连接为保护状态,不被心跳线程切断 + * @example + * @param int $fd 要设置保护状态的客户端连接fd + * @param boolean $is_protected 设置的状态,true表示保护状态,false表示不保护 + * @return + */ + public function protect(int $fd, bool $is_protected) + { + + } + + /** + * + *向客户端发送文件 + * @example + * @param int $conn_fd 连接句柄 + * @param string $filename 文件名 + * @param int $offset 指定文件偏移量,可以从文件的某个位置起发送数据。默认为0,表示从文件头部开始发送 + * @param int $length 指定发送的长度,默认为文件尺寸 + * @return + */ + public function sendfile(int $conn_fd, string $filename, int $offset, int $length) + { + + } + + /** + * + *关闭客户端连接 + * @example + * @param int $fd 连接句柄 + * @param boolean $reset 设置为true会强制关闭连接,丢弃发送队列中的数据 + * @return + */ + public function close(int $fd, bool $reset) + { + + } + + /** + * + *确认连接,与enable_delay_receive或wait_for_bind配合使用 + * @example + * @param int $fd 连接句柄 + * @return + */ + public function confirm(int $fd) + { + + } + + /** + * + *停止接收数据 + * @example + * @param int $fd 连接句柄 + * @return + */ + public function pause(int $fd) + { + + } + + /** + * + *恢复数据接收。与pause方法成对使用 + * @example + * @param int $fd 连接句柄 + * @return + */ + public function resume(int $fd) + { + + } + + /** + * + *投递一个任务到task_worker连接池中 + * @example + * @param mixed $data 要投递的任务数据,可以为除资源类型之外的任意PHP变量 + * @param int $worker_id 可以制定要给投递给哪个task进程,传入ID即可 + * @param callable $finish_callback 完成后的回调函数 + * @return + */ + public function task($data, int $worker_id, Callable $finish_callback) + { + + } + + /** + * + *以阻塞的形式投递一个任务到task_worker连接池中 + * @example + * @param mixed $data 要投递的任务数据,可以为除资源类型之外的任意PHP变量 + * @param float $timeout 超时时间 + * @param int $worker_id 可以制定要给投递给哪个task进程,传入ID即可 + * @return + */ + public function taskwait($data, float $timeout, int $worker_id) + { + + } + + /** + * + *并发执行多个Task + * @example + * @param array $tasks 必须为数字索引数组,不支持关联索引数组,底层会遍历$tasks将任务逐个投递到Task进程 + * @param double $timeout 超时时间 + * @return + */ + public function taskWaitMulti(Array $tasks, double $timeout) + { + + } + + /** + * + *并发执行Task并进行协程调度 + * @example + * @param array $tasks 必须为数字索引数组,不支持关联索引数组,底层会遍历$tasks将任务逐个投递到Task进程 + * @param double $timeout 超时时间 + * @return array + */ + public function taskCo(Array $tasks, double $timeout): array + { + + } + + /** + * + *用于在task进程中通知worker进程任务已完成 + * @example + * @param string $data 要传递的数据 + * @return + */ + public function finish(string $data) + { + + } + + /** + * + *重启所有工作进程 + * @example + * @return boolean + */ + public function reload(): boolean + { + + } + + /** + * + *关闭服务器 + * @example + * @return + */ + public function shutdown() + { + + } + + /** + * + *停止当前worker进程 + * @example + * @param int $worker_id 进程ID + * @return + */ + public function stop(int $worker_id) + { + + } + + /** + * + *获取最近一次操作错误的错误码 + *返回的错误码: + *1001 连接已经被Server端关闭了,出现这个错误一般是代码中已经执行了$serv->close()关闭了某个连接,但仍然调用$serv->send()向这个连接发送数据 + * @example + * @return + */ + public function getLastError() + { + + } + + /** + * + *检测所有服务器连接,并找出已经超时的连接 + * @example + * @param boolean $reactor_id 是否关闭超时的连接,默认为true + * @return + */ + public function heartbeat(bool $reactor_id) + { + + } + + /** + * + *获取客户端连接信息 + * @example + * @param mixed $fd 连接句柄 + * @param int $reactor_id reactor线程id + * @return from_id + */ + public function connection_info($fd, int $reactor_id): from_id + { + + } + + /** + * + *用来遍历所有客户端连接 + * @example + * @param int $start_fd 起始fd + * @param int $find_count 每页取多少条 + * @return + */ + public function connection_list(int $start_fd, int $find_count) + { + + } + + /** + * + *获取连接的信息,别名是swoole_server->connection_info + * @example + * @param mixed $fd 连接句柄 + * @param int $reactor_id reactor线程id + * @return + */ + public function getClientInfo($fd, int $reactor_id) + { + + } + + /** + * + *用来遍历所有客户端连接(server->connection_list的别名) + * @example + * @param int $start_fd 起始fd + * @param int $find_count 每页取多少条 + * @return + */ + public function getClientList(int $start_fd, int $find_count) + { + + } + + /** + * + *在指定时间后执行某个回调函数 + * @example + * @param int $ms 指定时间,单位为毫秒 + * @param callable $callback 回调函数 + * @param array $param 给回调函数传入的参数 + * @return + */ + public function after(int $ms, Callable $callback, Array $param) + { + + } + + /** + * + *添加定时器 + * @example + * @param int $ms 指定时间,单位为毫秒 + * @param callable $callback 回调函数 + * @return + */ + public function tick(int $ms, Callable $callback) + { + + } + + /** + * + *清除定时器 + * @example + * @param int $timer_id 定时器ID + * @return + */ + public function clearTimer(int $timer_id) + { + + } + + /** + * + *延迟执行一个PHP函数 + * @example + * @param callable $callback 执行的函数 + * @return + */ + public function defer(Callable $callback) + { + + } + + /** + * + *向任意worker进程或task进程发送消息 + * @example + * @param int $dst_worker_id 目标worker的ID + * @param string $data 发送的消息 + * @return + */ + public function sendMessage(int $dst_worker_id, string $data) + { + + } + + /** + * + *添加一个自定义的工作进程 + * @example + * @param Swoole\Process $process 进程对象 + * @return + */ + public function addProcess(Swoole\Process $process) + { + + } + + /** + * + *得到当前server的活动TCP连接数 + *array ( + * @example + * @return + */ + public function stats() + { + + } + + /** + * + *将连接绑定到某个用户定义的ID + * @example + * @param int $fd 连接句柄 + * @param int $uid 用户定义的ID + * @return + */ + public function bind(int $fd, int $uid) + { + + } + + /** + * + *序列化函数调用的魔术方法(在PHP进行序列化时,serialize() 检查类中是否有 __sleep() ,如果有,则该函数将在任何序列化之前运行。该函数必须返回一个需要进行序列化保存的成员属性数组,并且只序列化该函数返回的这些成员属性. 该函数有两个作用: 第一. 在序列化之前,关闭对象可能具有的任何数据库连接等. 第二. 指定对象中需要被序列化的成员属性,如果某个属性比较大而不需要储存下来,可以不把它写进__sleep要返回的数组中,这样该属性就不会被序列化) + * @example + * @return + */ + public function __sleep() + { + + } + + /** + * + *反序列化函数调用的魔术方法(unserialize() 从字节流中创建了一个对象之后,马上检查是否具有__wakeup 的函数的存在。如果存在,__wakeup 立刻被调用。使用 __wakeup 的目的是重建在序列化中可能丢失的任何数据库连接以及处理其它重新初始化的任务) + * @example + * @return + */ + public function __wakeup() + { + + } + +} + diff --git a/src/Swoole/Co/Server.php b/src/Swoole/Co/Server.php new file mode 100644 index 0000000..32be832 --- /dev/null +++ b/src/Swoole/Co/Server.php @@ -0,0 +1,738 @@ +finish()方法将任务处理的结果发送给worker进程。 + * @access public + */ + public $onFinish; + + /** + * @var callable $onManagerStart + * 当管理进程启动时调用它 + * @access public + */ + public $onManagerStart; + + /** + * @var callable $onManagerStop + * 当管理进程结束时调用它 + * @access public + */ + public $onManagerStop; + + /** + * @var callable $onPipeMessage + * 当工作进程收到由 sendMessage 发送的管道消息时会触发onPipeMessage事件 + * @access public + */ + public $onPipeMessage; + + /** + * @var array $setting + * 通过swoole_server:set()设置的参数会保存到setting属性上 + * @access public + */ + public $setting = array(); + + /** + * @var iterator $connections + * TCP连接迭代器 + * @access public + */ + public $connections; + + /** + * @var string $host + * 连接的主机 + * @access public + */ + public $host; + + /** + * @var int $port + * 连接的主机的端口 + * @access public + */ + public $port = 0; + + /** + * @var int $type + * socket的类型 + * @access public + */ + public $type = 0; + + /** + * @var int $mode + * 运行模式(swoole提供了3种运行模式,默认为SWOOLE_PROCESS多进程模式) + * @access public + */ + public $mode = 0; + + /** + * @var array $ports + * 当监听多端口时的端口列表 + * @access public + */ + public $ports = array(); + + /** + * @var int $master_pid + * 主进程ID + * @access public + */ + public $master_pid = 0; + + /** + * @var int $manager_pid + * 管理进程ID + * @access public + */ + public $manager_pid = 0; + + /** + * @var int $worker_id + * 当前工作进程(包括worker进程和task进程)编号 + * @access public + */ + public $worker_id = -1; + + /** + * @var boolean $taskworker + * 当前进程是否是task工作进程 + * @access public + */ + public $taskworker = ''; + + /** + * @var int $worker_pid + * 当前工作进程ID(操作系统进程) + * @access public + */ + public $worker_pid = 0; + + /** + * + *swoole_server初始化方法 + * @example + * @param string $host 主机IP + * @param int $port 端口 + * @param int $mode 运行模式 + * @param int $sock_type socket类型 + * @return + */ + public function __construct(string $host, int $port, int $mode, int $sock_type) + { + + } + + /** + * + *析构函数 + * @example + * @return + */ + public function __destruct() + { + + } + + /** + * + *添加监听端口(是addlistener的别名) + * @example + * @param string $host 监听的主机 + * @param int $port 监听的端口号 + * @param int $sock_type socket类型 + * @return + */ + public function listen(string $host, int $port, int $sock_type) + { + + } + + /** + * + *添加监听端口 + * @example + * @param string $host 监听的主机 + * @param int $port 监听的端口号 + * @param int $sock_type socket类型 + * @return + */ + public function addlistener(string $host, int $port, int $sock_type) + { + + } + + /** + * + *绑定事件(为事件注册函数) + * @example + * @param string $event_name 事件名称 + * @param callable $callback 事件对应的回调函数 + * @return + */ + public function on(string $event_name, Callable $callback) + { + + } + + /** + * + *设置swoole_server运行时的参数 + * @example + * @param array $settings 配置选项 + * @return + */ + public function set(Array $settings) + { + + } + + /** + * + *启动server + * @example + * @return + */ + public function start() + { + + } + + /** + * + *向客户端发送数据 + * @example + * @param int $fd 连接句柄 + * @param string $send_data 发送的数据 + * @param int $reactor_id UDP服务器使用$fd保存客户端IP,$extraData保存server_fd和port + * @return + */ + public function send(int $fd, string $send_data, int $reactor_id) + { + + } + + /** + * + *向任意客户端发送UDP数据包 + * @example + * @param string $ip IPv4字符串,如192.168.1.102。如果IP不合法会返回错误 + * @param int $port 为 1-65535的网络端口号,如果端口错误发送会失败 + * @param string $send_data 发送的数据内容,可以是文本或者二进制内容 + * @param int $server_socket 服务器可能会同时监听多个UDP端口,此参数可以指定使用哪个端口发送数据包 + * @return + */ + public function sendto(string $ip, int $port, string $send_data, int $server_socket) + { + + } + + /** + * + *阻塞的向客户端发送数据 + * @example + * @param int $conn_fd 与客户端连接的句柄 + * @param string $send_data 发送的数据 + * @return + */ + public function sendwait(int $conn_fd, string $send_data) + { + + } + + /** + * + *检测fd对应的连接是否存在 + * @example + * @param int $fd 连接句柄 + * @return + */ + public function exist(int $fd) + { + + } + + /** + * + *设置客户端连接为保护状态,不被心跳线程切断 + * @example + * @param int $fd 要设置保护状态的客户端连接fd + * @param boolean $is_protected 设置的状态,true表示保护状态,false表示不保护 + * @return + */ + public function protect(int $fd, bool $is_protected) + { + + } + + /** + * + *向客户端发送文件 + * @example + * @param int $conn_fd 连接句柄 + * @param string $filename 文件名 + * @param int $offset 指定文件偏移量,可以从文件的某个位置起发送数据。默认为0,表示从文件头部开始发送 + * @param int $length 指定发送的长度,默认为文件尺寸 + * @return + */ + public function sendfile(int $conn_fd, string $filename, int $offset, int $length) + { + + } + + /** + * + *关闭客户端连接 + * @example + * @param int $fd 连接句柄 + * @param boolean $reset 设置为true会强制关闭连接,丢弃发送队列中的数据 + * @return + */ + public function close(int $fd, bool $reset) + { + + } + + /** + * + *确认连接,与enable_delay_receive或wait_for_bind配合使用 + * @example + * @param int $fd 连接句柄 + * @return + */ + public function confirm(int $fd) + { + + } + + /** + * + *停止接收数据 + * @example + * @param int $fd 连接句柄 + * @return + */ + public function pause(int $fd) + { + + } + + /** + * + *恢复数据接收。与pause方法成对使用 + * @example + * @param int $fd 连接句柄 + * @return + */ + public function resume(int $fd) + { + + } + + /** + * + *投递一个任务到task_worker连接池中 + * @example + * @param mixed $data 要投递的任务数据,可以为除资源类型之外的任意PHP变量 + * @param int $worker_id 可以制定要给投递给哪个task进程,传入ID即可 + * @param callable $finish_callback 完成后的回调函数 + * @return + */ + public function task($data, int $worker_id, Callable $finish_callback) + { + + } + + /** + * + *以阻塞的形式投递一个任务到task_worker连接池中 + * @example + * @param mixed $data 要投递的任务数据,可以为除资源类型之外的任意PHP变量 + * @param float $timeout 超时时间 + * @param int $worker_id 可以制定要给投递给哪个task进程,传入ID即可 + * @return + */ + public function taskwait($data, float $timeout, int $worker_id) + { + + } + + /** + * + *并发执行多个Task + * @example + * @param array $tasks 必须为数字索引数组,不支持关联索引数组,底层会遍历$tasks将任务逐个投递到Task进程 + * @param double $timeout 超时时间 + * @return + */ + public function taskWaitMulti(Array $tasks, double $timeout) + { + + } + + /** + * + *并发执行Task并进行协程调度 + * @example + * @param array $tasks 必须为数字索引数组,不支持关联索引数组,底层会遍历$tasks将任务逐个投递到Task进程 + * @param double $timeout 超时时间 + * @return array + */ + public function taskCo(Array $tasks, double $timeout): array + { + + } + + /** + * + *用于在task进程中通知worker进程任务已完成 + * @example + * @param string $data 要传递的数据 + * @return + */ + public function finish(string $data) + { + + } + + /** + * + *重启所有工作进程 + * @example + * @return boolean + */ + public function reload(): boolean + { + + } + + /** + * + *关闭服务器 + * @example + * @return + */ + public function shutdown() + { + + } + + /** + * + *停止当前worker进程 + * @example + * @param int $worker_id 进程ID + * @return + */ + public function stop(int $worker_id) + { + + } + + /** + * + *获取最近一次操作错误的错误码 + *返回的错误码: + *1001 连接已经被Server端关闭了,出现这个错误一般是代码中已经执行了$serv->close()关闭了某个连接,但仍然调用$serv->send()向这个连接发送数据 + * @example + * @return + */ + public function getLastError() + { + + } + + /** + * + *检测所有服务器连接,并找出已经超时的连接 + * @example + * @param boolean $reactor_id 是否关闭超时的连接,默认为true + * @return + */ + public function heartbeat(bool $reactor_id) + { + + } + + /** + * + *获取客户端连接信息 + * @example + * @param mixed $fd 连接句柄 + * @param int $reactor_id reactor线程id + * @return from_id + */ + public function connection_info($fd, int $reactor_id): from_id + { + + } + + /** + * + *用来遍历所有客户端连接 + * @example + * @param int $start_fd 起始fd + * @param int $find_count 每页取多少条 + * @return + */ + public function connection_list(int $start_fd, int $find_count) + { + + } + + /** + * + *获取连接的信息,别名是swoole_server->connection_info + * @example + * @param mixed $fd 连接句柄 + * @param int $reactor_id reactor线程id + * @return + */ + public function getClientInfo($fd, int $reactor_id) + { + + } + + /** + * + *用来遍历所有客户端连接(server->connection_list的别名) + * @example + * @param int $start_fd 起始fd + * @param int $find_count 每页取多少条 + * @return + */ + public function getClientList(int $start_fd, int $find_count) + { + + } + + /** + * + *在指定时间后执行某个回调函数 + * @example + * @param int $ms 指定时间,单位为毫秒 + * @param callable $callback 回调函数 + * @param array $param 给回调函数传入的参数 + * @return + */ + public function after(int $ms, Callable $callback, Array $param) + { + + } + + /** + * + *添加定时器 + * @example + * @param int $ms 指定时间,单位为毫秒 + * @param callable $callback 回调函数 + * @return + */ + public function tick(int $ms, Callable $callback) + { + + } + + /** + * + *清除定时器 + * @example + * @param int $timer_id 定时器ID + * @return + */ + public function clearTimer(int $timer_id) + { + + } + + /** + * + *延迟执行一个PHP函数 + * @example + * @param callable $callback 执行的函数 + * @return + */ + public function defer(Callable $callback) + { + + } + + /** + * + *向任意worker进程或task进程发送消息 + * @example + * @param int $dst_worker_id 目标worker的ID + * @param string $data 发送的消息 + * @return + */ + public function sendMessage(int $dst_worker_id, string $data) + { + + } + + /** + * + *添加一个自定义的工作进程 + * @example + * @param Swoole\Process $process 进程对象 + * @return + */ + public function addProcess(Swoole\Process $process) + { + + } + + /** + * + *得到当前server的活动TCP连接数 + *array ( + * @example + * @return + */ + public function stats() + { + + } + + /** + * + *将连接绑定到某个用户定义的ID + * @example + * @param int $fd 连接句柄 + * @param int $uid 用户定义的ID + * @return + */ + public function bind(int $fd, int $uid) + { + + } + + /** + * + *序列化函数调用的魔术方法(在PHP进行序列化时,serialize() 检查类中是否有 __sleep() ,如果有,则该函数将在任何序列化之前运行。该函数必须返回一个需要进行序列化保存的成员属性数组,并且只序列化该函数返回的这些成员属性. 该函数有两个作用: 第一. 在序列化之前,关闭对象可能具有的任何数据库连接等. 第二. 指定对象中需要被序列化的成员属性,如果某个属性比较大而不需要储存下来,可以不把它写进__sleep要返回的数组中,这样该属性就不会被序列化) + * @example + * @return + */ + public function __sleep() + { + + } + + /** + * + *反序列化函数调用的魔术方法(unserialize() 从字节流中创建了一个对象之后,马上检查是否具有__wakeup 的函数的存在。如果存在,__wakeup 立刻被调用。使用 __wakeup 的目的是重建在序列化中可能丢失的任何数据库连接以及处理其它重新初始化的任务) + * @example + * @return + */ + public function __wakeup() + { + + } + +} + diff --git a/src/Swoole/Co/WebSocket/Server.php b/src/Swoole/Co/WebSocket/Server.php new file mode 100644 index 0000000..dc6ed92 --- /dev/null +++ b/src/Swoole/Co/WebSocket/Server.php @@ -0,0 +1,794 @@ +finish()方法将任务处理的结果发送给worker进程。 + * @access public + */ + public $onFinish; + + /** + * @var callable $onManagerStart + * 当管理进程启动时调用它 + * @access public + */ + public $onManagerStart; + + /** + * @var callable $onManagerStop + * 当管理进程结束时调用它 + * @access public + */ + public $onManagerStop; + + /** + * @var callable $onPipeMessage + * 当工作进程收到由 sendMessage 发送的管道消息时会触发onPipeMessage事件 + * @access public + */ + public $onPipeMessage; + + /** + * @var iterator $connections + * TCP连接迭代器 + * @access public + */ + public $connections; + + /** + * @var string $host + * 连接的主机 + * @access public + */ + public $host; + + /** + * @var int $port + * 连接的主机的端口 + * @access public + */ + public $port = 0; + + /** + * @var int $type + * socket的类型 + * @access public + */ + public $type = 0; + + /** + * @var int $mode + * 运行模式(swoole提供了3种运行模式,默认为SWOOLE_PROCESS多进程模式) + * @access public + */ + public $mode = 0; + + /** + * @var array $ports + * 当监听多端口时的端口列表 + * @access public + */ + public $ports = array(); + + /** + * @var int $master_pid + * 主进程ID + * @access public + */ + public $master_pid = 0; + + /** + * @var int $manager_pid + * 管理进程ID + * @access public + */ + public $manager_pid = 0; + + /** + * @var int $worker_id + * 当前工作进程(包括worker进程和task进程)编号 + * @access public + */ + public $worker_id = -1; + + /** + * @var boolean $taskworker + * 当前进程是否是task工作进程 + * @access public + */ + public $taskworker = ''; + + /** + * @var int $worker_pid + * 当前工作进程ID(操作系统进程) + * @access public + */ + public $worker_pid = 0; + + /** + * @var callable $onRequest + * 请求回调函数 + * @access public + */ + public $onRequest; + + /** + * @var callable $onHandshake + * TCP握手时的回调函数 + * @access public + */ + public $onHandshake; + + /** + * @var array $setting + * 通过swoole_server:set()设置的参数会保存到setting属性上 + * @access public + */ + public $setting = array(); + + /** + * + *绑定事件(为事件注册函数) + * @example + * @param string $event_name 事件名称 + * @param callable $callback 事件对应的回调函数 + * @return + */ + public function on(string $event_name, Callable $callback) + { + + } + + /** + * + *向websocket客户端连接推送数据,长度最大不得超过2M + * @example + * @param int $fd 客户端连接的ID,如果指定的$fd对应的TCP连接并非websocket客户端,将会发送失败 + * @param string $data 要发送的数据内容 + * @param int $opcode 指定发送数据内容的格式,默认为文本。发送二进制内容$opcode参数需要设置 + * @param boolean $finish 帧是否完成 + * @return + */ + public function push(int $fd, string $data, int $opcode, bool $finish) + { + + } + + /** + * + *检测fd对应的连接是否存在 + * @example + * @param int $fd 连接句柄 + * @return + */ + public function exist(int $fd) + { + + } + + /** + * + *打包数据 + * @example + * @param string $data 消息内容 + * @param int $opcode WebSocket的opcode指令类型,1表示文本,2表示二进制数据,9表示心跳ping + * @param boolean $finish 帧是否完成 + * @param boolean $mask 是否设置掩码 + * @return + */ + public static function pack(string $data, int $opcode, bool $finish, bool $mask) + { + + } + + /** + * + *参数据进行解包 + * @example + * @param string $data 解包的数据 + * @return + */ + public static function unpack(string $data) + { + + } + + /** + * + *启动server + * @example + * @return + */ + public function start() + { + + } + + /** + * + *序列化函数调用的魔术方法(在PHP进行序列化时,serialize() 检查类中是否有 __sleep() ,如果有,则该函数将在任何序列化之前运行。该函数必须返回一个需要进行序列化保存的成员属性数组,并且只序列化该函数返回的这些成员属性. 该函数有两个作用: 第一. 在序列化之前,关闭对象可能具有的任何数据库连接等. 第二. 指定对象中需要被序列化的成员属性,如果某个属性比较大而不需要储存下来,可以不把它写进__sleep要返回的数组中,这样该属性就不会被序列化) + * @example + * @return + */ + public function __sleep() + { + + } + + /** + * + *反序列化函数调用的魔术方法(unserialize() 从字节流中创建了一个对象之后,马上检查是否具有__wakeup 的函数的存在。如果存在,__wakeup 立刻被调用。使用 __wakeup 的目的是重建在序列化中可能丢失的任何数据库连接以及处理其它重新初始化的任务) + * @example + * @return + */ + public function __wakeup() + { + + } + + /** + * + *swoole_server初始化方法 + * @example + * @param string $host 主机IP + * @param int $port 端口 + * @param int $mode 运行模式 + * @param int $sock_type socket类型 + * @return + */ + public function __construct(string $host, int $port, int $mode, int $sock_type) + { + + } + + /** + * + *析构函数 + * @example + * @return + */ + public function __destruct() + { + + } + + /** + * + *添加监听端口(是addlistener的别名) + * @example + * @param string $host 监听的主机 + * @param int $port 监听的端口号 + * @param int $sock_type socket类型 + * @return + */ + public function listen(string $host, int $port, int $sock_type) + { + + } + + /** + * + *添加监听端口 + * @example + * @param string $host 监听的主机 + * @param int $port 监听的端口号 + * @param int $sock_type socket类型 + * @return + */ + public function addlistener(string $host, int $port, int $sock_type) + { + + } + + /** + * + *设置swoole_server运行时的参数 + * @example + * @param array $settings 配置选项 + * @return + */ + public function set(Array $settings) + { + + } + + /** + * + *向客户端发送数据 + * @example + * @param int $fd 连接句柄 + * @param string $send_data 发送的数据 + * @param int $reactor_id UDP服务器使用$fd保存客户端IP,$extraData保存server_fd和port + * @return + */ + public function send(int $fd, string $send_data, int $reactor_id) + { + + } + + /** + * + *向任意客户端发送UDP数据包 + * @example + * @param string $ip IPv4字符串,如192.168.1.102。如果IP不合法会返回错误 + * @param int $port 为 1-65535的网络端口号,如果端口错误发送会失败 + * @param string $send_data 发送的数据内容,可以是文本或者二进制内容 + * @param int $server_socket 服务器可能会同时监听多个UDP端口,此参数可以指定使用哪个端口发送数据包 + * @return + */ + public function sendto(string $ip, int $port, string $send_data, int $server_socket) + { + + } + + /** + * + *阻塞的向客户端发送数据 + * @example + * @param int $conn_fd 与客户端连接的句柄 + * @param string $send_data 发送的数据 + * @return + */ + public function sendwait(int $conn_fd, string $send_data) + { + + } + + /** + * + *设置客户端连接为保护状态,不被心跳线程切断 + * @example + * @param int $fd 要设置保护状态的客户端连接fd + * @param boolean $is_protected 设置的状态,true表示保护状态,false表示不保护 + * @return + */ + public function protect(int $fd, bool $is_protected) + { + + } + + /** + * + *向客户端发送文件 + * @example + * @param int $conn_fd 连接句柄 + * @param string $filename 文件名 + * @param int $offset 指定文件偏移量,可以从文件的某个位置起发送数据。默认为0,表示从文件头部开始发送 + * @param int $length 指定发送的长度,默认为文件尺寸 + * @return + */ + public function sendfile(int $conn_fd, string $filename, int $offset, int $length) + { + + } + + /** + * + *关闭客户端连接 + * @example + * @param int $fd 连接句柄 + * @param boolean $reset 设置为true会强制关闭连接,丢弃发送队列中的数据 + * @return + */ + public function close(int $fd, bool $reset) + { + + } + + /** + * + *确认连接,与enable_delay_receive或wait_for_bind配合使用 + * @example + * @param int $fd 连接句柄 + * @return + */ + public function confirm(int $fd) + { + + } + + /** + * + *停止接收数据 + * @example + * @param int $fd 连接句柄 + * @return + */ + public function pause(int $fd) + { + + } + + /** + * + *恢复数据接收。与pause方法成对使用 + * @example + * @param int $fd 连接句柄 + * @return + */ + public function resume(int $fd) + { + + } + + /** + * + *投递一个任务到task_worker连接池中 + * @example + * @param mixed $data 要投递的任务数据,可以为除资源类型之外的任意PHP变量 + * @param int $worker_id 可以制定要给投递给哪个task进程,传入ID即可 + * @param callable $finish_callback 完成后的回调函数 + * @return + */ + public function task($data, int $worker_id, Callable $finish_callback) + { + + } + + /** + * + *以阻塞的形式投递一个任务到task_worker连接池中 + * @example + * @param mixed $data 要投递的任务数据,可以为除资源类型之外的任意PHP变量 + * @param float $timeout 超时时间 + * @param int $worker_id 可以制定要给投递给哪个task进程,传入ID即可 + * @return + */ + public function taskwait($data, float $timeout, int $worker_id) + { + + } + + /** + * + *并发执行多个Task + * @example + * @param array $tasks 必须为数字索引数组,不支持关联索引数组,底层会遍历$tasks将任务逐个投递到Task进程 + * @param double $timeout 超时时间 + * @return + */ + public function taskWaitMulti(Array $tasks, double $timeout) + { + + } + + /** + * + *并发执行Task并进行协程调度 + * @example + * @param array $tasks 必须为数字索引数组,不支持关联索引数组,底层会遍历$tasks将任务逐个投递到Task进程 + * @param double $timeout 超时时间 + * @return array + */ + public function taskCo(Array $tasks, double $timeout): array + { + + } + + /** + * + *用于在task进程中通知worker进程任务已完成 + * @example + * @param string $data 要传递的数据 + * @return + */ + public function finish(string $data) + { + + } + + /** + * + *重启所有工作进程 + * @example + * @return boolean + */ + public function reload(): boolean + { + + } + + /** + * + *关闭服务器 + * @example + * @return + */ + public function shutdown() + { + + } + + /** + * + *停止当前worker进程 + * @example + * @param int $worker_id 进程ID + * @return + */ + public function stop(int $worker_id) + { + + } + + /** + * + *获取最近一次操作错误的错误码 + *返回的错误码: + *1001 连接已经被Server端关闭了,出现这个错误一般是代码中已经执行了$serv->close()关闭了某个连接,但仍然调用$serv->send()向这个连接发送数据 + * @example + * @return + */ + public function getLastError() + { + + } + + /** + * + *检测所有服务器连接,并找出已经超时的连接 + * @example + * @param boolean $reactor_id 是否关闭超时的连接,默认为true + * @return + */ + public function heartbeat(bool $reactor_id) + { + + } + + /** + * + *获取客户端连接信息 + * @example + * @param mixed $fd 连接句柄 + * @param int $reactor_id reactor线程id + * @return from_id + */ + public function connection_info($fd, int $reactor_id): from_id + { + + } + + /** + * + *用来遍历所有客户端连接 + * @example + * @param int $start_fd 起始fd + * @param int $find_count 每页取多少条 + * @return + */ + public function connection_list(int $start_fd, int $find_count) + { + + } + + /** + * + *获取连接的信息,别名是swoole_server->connection_info + * @example + * @param mixed $fd 连接句柄 + * @param int $reactor_id reactor线程id + * @return + */ + public function getClientInfo($fd, int $reactor_id) + { + + } + + /** + * + *用来遍历所有客户端连接(server->connection_list的别名) + * @example + * @param int $start_fd 起始fd + * @param int $find_count 每页取多少条 + * @return + */ + public function getClientList(int $start_fd, int $find_count) + { + + } + + /** + * + *在指定时间后执行某个回调函数 + * @example + * @param int $ms 指定时间,单位为毫秒 + * @param callable $callback 回调函数 + * @param array $param 给回调函数传入的参数 + * @return + */ + public function after(int $ms, Callable $callback, Array $param) + { + + } + + /** + * + *添加定时器 + * @example + * @param int $ms 指定时间,单位为毫秒 + * @param callable $callback 回调函数 + * @return + */ + public function tick(int $ms, Callable $callback) + { + + } + + /** + * + *清除定时器 + * @example + * @param int $timer_id 定时器ID + * @return + */ + public function clearTimer(int $timer_id) + { + + } + + /** + * + *延迟执行一个PHP函数 + * @example + * @param callable $callback 执行的函数 + * @return + */ + public function defer(Callable $callback) + { + + } + + /** + * + *向任意worker进程或task进程发送消息 + * @example + * @param int $dst_worker_id 目标worker的ID + * @param string $data 发送的消息 + * @return + */ + public function sendMessage(int $dst_worker_id, string $data) + { + + } + + /** + * + *添加一个自定义的工作进程 + * @example + * @param Swoole\Process $process 进程对象 + * @return + */ + public function addProcess(Swoole\Process $process) + { + + } + + /** + * + *得到当前server的活动TCP连接数 + *array ( + * @example + * @return + */ + public function stats() + { + + } + + /** + * + *将连接绑定到某个用户定义的ID + * @example + * @param int $fd 连接句柄 + * @param int $uid 用户定义的ID + * @return + */ + public function bind(int $fd, int $uid) + { + + } + +} + diff --git a/src/Swoole/Connection/Iterator.php b/src/Swoole/Connection/Iterator.php index a03aac7..b13e72a 100644 --- a/src/Swoole/Connection/Iterator.php +++ b/src/Swoole/Connection/Iterator.php @@ -1,24 +1,25 @@ recv方法的第二个参数,阻塞等待直到收到指定长度的数据后返回 + *阻塞等待直到收到指定长度的数据后返回 */ const MSG_WAITALL = 256; /** * @var int $errCode - * 错误码。errCode的值等于Linux errno。可使用socket_strerror将错误码转为错误信息 + * 错误码 * @access public */ public $errCode = 0; /** * @var int $sock - * sock属性是此socket的文件描述符 + * 此socket的文件描述符 * @access public */ public $sock = 0; + /** + * @var int $type + * socket 类型 + * @access public + */ + public $type = 0; + + /** + * @var array $setting + * 设置参数 + * @access public + */ + public $setting = array(); + + /** + * @var bool $connected + * 是否已连接 + * @access public + */ + public $connected = false; + /** * - *创建tcp/udp客户端 + *客户端初始化 * @example + * @param int $type 表示socket的类型,如TCP/UDP * @return */ - public function __construct() + public function __construct(int $type) { + } /** @@ -63,76 +86,96 @@ public function __construct() */ public function __destruct() { + } /** * *设置客户端参数 * @example + * @param array $settings 配置参数 * @return */ - public function set() + public function set(Array $settings) { + } /** * *连接到远程服务器 * @example - * @return bool + * @param string $host 远程服务器的地址 + * @param int $port 远程服务器端口 + * @param float $timeout 网络IO的超时,包括connect/send/recv,单位是s,支持浮点数。默认为0.1s,即100ms,超时发生时,连接会被自动close掉 + * @return */ - public function connect() + public function connect(string $host, int $port, float $timeout) { + } /** * - *用于从服务器端接收数据 + *用于从服务器端接收数据。底层会自动yield,等待数据接收完成后自动切换到当前协程 * @example * @return string */ - public function recv() + public function recv(): string { + } /** * - *发送数据到远程服务器,必须在建立连接后,才可向Server发送数据 + *发送数据 * @example - * @return int + * @param string $data 要发送的数据 + * @param boolean $flag 是否立即返回 + * @return */ - public function send() + public function send(string $data, bool $flag) { + } /** * *发送文件到服务器,本函数是基于sendfile操作系统调用的 * @example - * @return bool + * @param string $filename 指定要发送文件的路径 + * @param int $offset 上传文件的偏移量,可以指定从文件的中间部分开始传输数据。此特性可用于支持断点续传 + * @param int $length 发送数据的尺寸,默认为整个文件的尺寸 + * @return boolean */ - public function sendfile() + public function sendfile(string $filename, int $offset, int $length): boolean { + } /** * *向任意IP:PORT的主机发送UDP数据包,仅支持SWOOLE_SOCK_UDP/SWOOLE_SOCK_UDP6类型的swoole_client对象。 * @example - * @return bool + * @param string $ip 目标主机的IP地址,支持IPv4/IPv6 + * @param int $port 目标主机端口 + * @param string $data 要发送的数据内容,不得超过64K + * @return boolean */ - public function sendto() + public function sendto(string $ip, int $port, string $data): boolean { + } /** * *返回swoole_client的连接状态 * @example - * @return bool + * @return boolean */ - public function isConnected() + public function isConnected(): boolean { + } /** @@ -141,28 +184,53 @@ public function isConnected() * @example * @return array */ - public function getsockname() + public function getsockname(): array { + } /** * - *获取对端socket的IP地址和端口,仅支持SWOOLE_SOCK_UDP/SWOOLE_SOCK_UDP6类型的swoole_client对象(此函数必须在$client->recv() 之后调用) + *获取对端socket的IP地址和端口,仅支持SWOOLE_SOCK_UDP/SWOOLE_SOCK_UDP6类型的swoole_client对象 * @example - * @return bool + * @return boolean */ - public function getpeername() + public function getpeername(): boolean { + } /** * *关闭连接 * @example - * @return bool + * @return boolean + */ + public function close(): boolean + { + + } + + /** + * + *序列化函数调用的魔术方法(在PHP进行序列化时,serialize() 检查类中是否有 __sleep() ,如果有,则该函数将在任何序列化之前运行。该函数必须返回一个需要进行序列化保存的成员属性数组,并且只序列化该函数返回的这些成员属性. 该函数有两个作用: 第一. 在序列化之前,关闭对象可能具有的任何数据库连接等. 第二. 指定对象中需要被序列化的成员属性,如果某个属性比较大而不需要储存下来,可以不把它写进__sleep要返回的数组中,这样该属性就不会被序列化) + * @example + * @return + */ + public function __sleep() + { + + } + + /** + * + *反序列化函数调用的魔术方法(unserialize() 从字节流中创建了一个对象之后,马上检查是否具有__wakeup 的函数的存在。如果存在,__wakeup 立刻被调用。使用 __wakeup 的目的是重建在序列化中可能丢失的任何数据库连接以及处理其它重新初始化的任务) + * @example + * @return */ - public function close() + public function __wakeup() { + } } diff --git a/src/Swoole/Coroutine/Http/Client.php b/src/Swoole/Coroutine/Http/Client.php index 162663c..c831d7c 100644 --- a/src/Swoole/Coroutine/Http/Client.php +++ b/src/Swoole/Coroutine/Http/Client.php @@ -1,38 +1,144 @@ '192.168.56.102', + * 'user' => 'test', + * 'password' => 'test', + * 'database' => 'test', + * 'charset' => 'utf8', + * ); + * @param array $server_config 连接配置信息 + * @return + */ + public function connect(Array $server_config) + { + } /** * - *建立mysql连接 + *执行sql语句 * @example - * @return bool + * @param string $sql 要执行的sql语句 + * @param double $timeout 超时时间,超时的话会断开MySQL连接,0表示不设置超时时间 + * @return array|boolean */ - public function connect() + public function query(string $sql, double $timeout): ?array { + } /** * - *执行mysql查询 + *接收包(获取延迟收包的结果,当没有进行延迟收包或者收包超时,返回false) * @example - * @return array + * @return mixed */ - public function query() + public function recv() { + } /** * - * + *启动事务 * @example * @return */ - public function recv() + public function begin() { + } /** * - * + *提交事务 * @example * @return */ - public function setDefer() + public function commit() { + } /** * - * + *回滚事务(必须先调用begin启动事务才能调用rollback否则底层会抛出异常) * @example * @return */ - public function getDefer() + public function rollback() + { + + } + + /** + * + *设置是否延迟 + * @example + * @param boolean $defer 为true时,表明该Client要延迟收包,为false时,表明该Client非延迟收包,默认值为true + * @return boolean + */ + public function setDefer(bool $defer): boolean + { + + } + + /** + * + *返回当前设置的defer + * @example + * @return boolean + */ + public function getDefer(): boolean { + } /** @@ -152,6 +202,29 @@ public function getDefer() */ public function close() { + + } + + /** + * + *序列化函数调用的魔术方法(在PHP进行序列化时,serialize() 检查类中是否有 __sleep() ,如果有,则该函数将在任何序列化之前运行。该函数必须返回一个需要进行序列化保存的成员属性数组,并且只序列化该函数返回的这些成员属性. 该函数有两个作用: 第一. 在序列化之前,关闭对象可能具有的任何数据库连接等. 第二. 指定对象中需要被序列化的成员属性,如果某个属性比较大而不需要储存下来,可以不把它写进__sleep要返回的数组中,这样该属性就不会被序列化) + * @example + * @return + */ + public function __sleep() + { + + } + + /** + * + *反序列化函数调用的魔术方法(unserialize() 从字节流中创建了一个对象之后,马上检查是否具有__wakeup 的函数的存在。如果存在,__wakeup 立刻被调用。使用 __wakeup 的目的是重建在序列化中可能丢失的任何数据库连接以及处理其它重新初始化的任务) + * @example + * @return + */ + public function __wakeup() + { + } } diff --git a/src/Swoole/Coroutine/MySQL/Exception.php b/src/Swoole/Coroutine/MySQL/Exception.php index 93240b7..f3ba53c 100644 --- a/src/Swoole/Coroutine/MySQL/Exception.php +++ b/src/Swoole/Coroutine/MySQL/Exception.php @@ -1,19 +1,19 @@ connect ("host=127.0.0.1 port=5432 dbname=test user=root password="); + * $result = $pg -> query($conn, 'SELECT * FROM test;'); + * $arr = $pg -> fetchAll($result); + * var_dump($arr); + * }); + * @return + */ + public function __construct() + { + + } + + /** + * + *建立postgresql 非阻塞的协程连接 + * @example $a = new Swoole\Coroutine\PostgreSQL(); + * $conn = $a -> connect ("host=127.0.0.1 port=5432 dbname=test user=wuzhenyu password="); + * @param string $conninfo 连接信息 + * @return resource|bool + */ + public function connect(string $conninfo): ?resource + { + + } + + /** + * + *postgresql发送异步非阻塞 协程命令 + * @example + * @param string $query 执行sql语句 + * @return resource + */ + public function query(string $query): resource + { + + } + + /** + * + *提取结果中所有行作为一个数组 + * @example + * @param resource $result 通过query查询的结果 + * @param int $result_type 获取结果类型(如关联数组等) + * @return mixed + */ + public function fetchAll(resource $result, int $result_type) + { + + } + + /** + * + *返回影响的行数 + * @example + * @param resource $result 结果 + * @return + */ + public function affectedRows(resource $result) + { + + } + + /** + * + *返回结果行数 + * @example + * @param resource $result 结果集 + * @return int + */ + public function numRows(resource $result): int + { + + } + + /** + * + *查看表的元数据 异步非阻塞协程版 + * @example + * @param string $table_name 表名 + * @return + */ + public function metaData(string $table_name) + { + + } + + /** + * + *提取一行作为对象 + * @example + * @param resource $result 结果集 + * @param int $row 行号 + * @return + */ + public function fetchObject(resource $result, int $row) + { + + } + + /** + * + *提取一行作为关联数组 + * @example + * @param resource $result 结果集 + * @param int $row 要提取的行号 + * @return + */ + public function fetchAssoc(resource $result, int $row) + { + + } + + /** + * + *返回一个与所提取的行(元组/记录)相一致的数组。如果没有更多行可供提取,则返回 FALSE + * @example + * @param resource $result 结果集 + * @param int $row 行号 + * @return + */ + public function fetchArray(resource $result, int $row) + { + + } + + /** + * + *根据指定的 result 资源提取一行数据(记录)作为数组返回。每个得到的列依次存放在数组中,从偏移量 0 开始。 + * @example + * @param resource $result 结果集 + * @param int $row 行号 + * @return + */ + public function fetchRow(resource $result, int $row) + { + + } + + /** + * + *析构函数 + * @example + * @return + */ + public function __destruct() + { + + } + +} + diff --git a/src/Swoole/Coroutine/Redis.php b/src/Swoole/Coroutine/Redis.php index 5c36dd9..43106ba 100644 --- a/src/Swoole/Coroutine/Redis.php +++ b/src/Swoole/Coroutine/Redis.php @@ -1,16 +1,51 @@ - * $redis->connect('127.0.0.1', 6379); - * $redis->connect('127.0.0.1'); // port 6379 by default - * $redis->connect('127.0.0.1', 6379, 2.5); // 2.5 sec timeout. - * $redis->connect('/tmp/redis.sock'); // unix domain socket. - *
- * @return bool + * @param string $host 主机 + * @param int $port 端口 + * @return */ - public function connect() + public function connect(string $host, int $port) { + } /** * - *设置defer + *设置是否延迟 * @example + * @param boolean $defer bool值,为true时,表明该Client要延迟收包,为false时,表明该Client非延迟收包,默认值为true * @return */ - public function setDefer() + public function setDefer(bool $defer) { + } /** * - *获取当前defer + *返回当前设置的defer * @example - * @return + * @return boolean */ - public function getDefer() + public function getDefer(): boolean { + } /** * - * + *从服务器端接收数据 * @example - * @return + * @param int $size 接收数据的缓存区最大长度,此参数不要设置过大,否则会占用较大内存 + * @param boolean $flag 是否等待所有数据到达后返回 + * @return string */ - public function recv() + public function recv(int $size, bool $flag): string { + } /** * - *Disconnects from the Redis instance, except when pconnect is used. + *关闭连接 * @example * @return */ public function close() { + } /** * - *Set the string value in argument as value of the key. - * @example + *给指定的键设置值 + * @example 直接设置: + * $redis->set('key', 'value'); + * 带有效期的设置: + * $redis->set('key','value', 10); + * 当键不存在时,设置期有效期为10秒: + * $redis->set('key', 'value', Array('nx', 'ex'=>10)); + * 当键存在时,设置期有效期为1000毫秒: + * $redis->set('key', 'value', Array('xx', 'px'=>1000)); + * + * @param string $key 设置的缓存键 + * @param string $value 设置的缓存值 + * @param int|array $options 附加项,可以是超时时间或者一个选项数组 * @return bool */ - public function set() + public function set(string $key, string $value, int $options): bool { + } /** * - *Changes a single bit of a string. + *修改某个键的某个位置的位值 * @example *
      * $redis->set('key', "*");     // ord("*") = 42 = 0x2f = "0010 1010"
@@ -121,35 +174,47 @@ public function set()
      * $redis->setBit('key', 7, 1); // returns 0
      * $redis->get('key');          // chr(0x2f) = "/" = b("0010 1111")
      * 
- * @return int: + * @param string $key 键名 + * @param int $offset 开始位置 + * @param boolean|int $value 新值 + * @return int */ - public function setBit() + public function setBit(string $key, int $offset, int $value): int { + } /** * - * - * @example - * @return + *设置键值并设置有效期 + * @example $redis->setex('key', 3600, 'value'); + * @param string $key 设置的缓存键 + * @param string $value 设置的缓存值 + * @param int $ttl 有效期 + * @return bool */ - public function setEx() + public function setEx(string $key, string $value, int $ttl): bool { + } /** * - * + *设置键值并设置有效期(毫秒为单位) * @example + * @param string $key 设置的缓存键 + * @param string $value 设置的缓存值 + * @param int $ttl 有效期(毫秒为单位) * @return */ - public function psetEx() + public function psetEx(string $key, string $value, int $ttl) { + } /** * - *Set the list at index with the new value. + *给列表指定位置设置新值 * @example *
      * $redis->rPush('key1', 'A');
@@ -159,54 +224,72 @@ public function psetEx()
      * $redis->lSet('key1', 0, 'X');
      * $redis->lGet('key1', 0);     // 'X'
      * 
- * @return is + * @param string $key 键名 + * @param int $index 索引值 + * @param string $value 新值 + * @return boolean */ - public function lSet() + public function lSet(string $key, int $index, string $value): boolean { + } /** * - *Get the value related to the specified key + *获取指定的key的值 * @example $redis->get('key'); - * @return string|bool: + * @return string|bool */ - public function get() + public function get(): ?string { + } /** * - * + *批量获取键名 * @example + *
+     * $redis->delete('x', 'y', 'z', 'h');	// remove x y z
+     * $redis->mset(array('x' => 'a', 'y' => 'b', 'z' => 'c'));
+     * $redis->hset('h', 'field', 'value');
+     * var_dump($redis->mget(array('x', 'y', 'z', 'h')));
+     * // Output:
+     * // array(3) {
+     * // [0]=>
+     * // string(1) "a"
+     * // [1]=>
+     * // string(1) "b"
+     * // [2]=>
+     * // string(1) "c"
+     * // [3]=>
+     * // bool(false)
+     * // }
+     * 
+ * @param array $keys 键名数组 * @return */ - public function mGet() + public function mGet(Array $keys) { + } /** * - *Remove specified keys. - * @example - *
-     * $redis->set('key1', 'val1');
-     * $redis->set('key2', 'val2');
-     * $redis->set('key3', 'val3');
-     * $redis->set('key4', 'val4');
-     * $redis->delete('key1', 'key2');          // return 2
-     * $redis->delete(array('key3', 'key4'));   // return 2
-     * 
+ *删除一个或多个键 + * @example $redis->delete('key1', 'key2'); + * $redis->delete(array('key3', 'key4')); + * @param array|string $keys 键名 * @return int */ - public function del() + public function del(array $keys): int { + } /** * - *Removes a values from the hash stored at key. - *If the hash table doesn't exist, or the key doesn't exist, FALSE is returned. + *删除字典的某个或某些字段 * @example *
      * $redis->hMSet('h',
@@ -225,15 +308,18 @@ public function del()
      * //    ["f4"]=> string(2) "v4"
      * //  }
      * 
+ * @param string $key 键名 + * @param string|array $fields 字段名 * @return int */ - public function hDel() + public function hDel(string $key, string $fields): int { + } /** * - *Adds a value to the hash stored at key. If this value is already in the hash, FALSE is returned. + *为字典的字段设置值 * @example *
      * $redis->delete('h')
@@ -242,25 +328,37 @@ public function hDel()
      * $redis->hSet('h', 'key1', 'plop');   // 0, value was replaced.
      * $redis->hGet('h', 'key1');           // returns "plop"
      * 
- * @return 0 + * @param string $key 键名 + * @param string $field 字段名 + * @param string $value 字段值 + * @return int */ - public function hSet() + public function hSet(string $key, string $field, string $value): int { + } /** * - * + *批量设置字典字段的值 * @example - * @return + *
+     * $redis->delete('user:1');
+     * $redis->hMset('user:1', array('name' => 'Joe', 'salary' => 2000));
+     * $redis->hIncrBy('user:1', 'salary', 100); // Joe earns 100 more now.
+     * 
+ * @param string $key 键名 + * @param array $fields 字段键值对 + * @return boolean */ - public function hMSet() + public function hMSet(string $key, Array $fields): boolean { + } /** * - *Adds a value to the hash stored at key only if this field isn't already in the hash. + *当字典的字段不存在时,为其设置值 * @example *
      * $redis->delete('h')
@@ -268,104 +366,145 @@ public function hMSet()
      * $redis->hSetNx('h', 'key1', 'world'); // FALSE, 'key1' => 'hello' in the hash at "h". No change since the field
      * wasn't replaced.
      * 
+ * @param string $key 键名 + * @param string $field 字段名 + * @param string $value 字段值 * @return bool */ - public function hSetNx() + public function hSetNx(string $key, string $field, string $value): bool { + } /** * - * - * @example + *删除一个或多个键 + * @example $redis->delete('key1', 'key2'); + * $redis->delete(array('key3', 'key4')); + * @param array|string $keys 键名 * @return int */ - public function delete() + public function delete(array $keys): int { + } /** * - * + *批量设置值 * @example - * @return + *
+     * $redis->mset(array('key0' => 'value0', 'key1' => 'value1'));
+     * var_dump($redis->get('key0'));
+     * var_dump($redis->get('key1'));
+     * // Output:
+     * // string(6) "value0"
+     * // string(6) "value1"
+     * 
+ * @param array $values 要设置的键值对 + * @return bool */ - public function mSet() + public function mSet(Array $values): bool { + } /** * - * + *批量设置值(当不存在时设置) * @example - * @return + *
+     * $redis->mset(array('key0' => 'value0', 'key1' => 'value1'));
+     * var_dump($redis->get('key0'));
+     * var_dump($redis->get('key1'));
+     * // Output:
+     * // string(6) "value0"
+     * // string(6) "value1"
+     * 
+ * @param array $values 要设置的键值对 + * @return bool */ - public function mSetNx() + public function mSetNx(Array $values): bool { + } /** * - * + *根据匹配模式获取键名(如*) * @example - * @return + * $allKeys = $redis->keys('*'); + * $keyWithUserPrefix = $redis->keys('user*'); + * @param string $pattern 匹配模式 + * @return array */ - public function getKeys() + public function getKeys(string $pattern): array { + } /** * - *Returns the keys that match a certain pattern. + *根据匹配模式获取键名(如*) * @example - *
-     * $allKeys = $redis->keys('*');   // all keys will match this.
+     * $allKeys = $redis->keys('*');
      * $keyWithUserPrefix = $redis->keys('user*');
-     * 
+ * @param string $pattern 匹配模式 * @return array */ - public function keys() + public function keys(string $pattern): array { + } /** * - *Verify if the specified key exists. + *判断键是否存在 * @example *
      * $redis->set('key', 'value');
      * $redis->exists('key');               //  TRUE
      * $redis->exists('NonExistingKey');    // FALSE
      * 
- * @return bool: + * @param string $key 键名 + * @return bool */ - public function exists() + public function exists(string $key): bool { + } /** * - *Returns the type of data pointed by a given key. + *获取指定键的数据类型(需要根据常量匹配) * @example $redis->type('key'); - * @return - + * @param string $key 键名 + * @return int */ - public function type() + public function type(string $key): int { + } /** * - * + *获取键值的长度 * @example - * @return + *
+     * $redis->set('key', 'value');
+     * $redis->strlen('key'); // 5
+     * 
+ * @param string $key 键名 + * @return int */ - public function strLen() + public function strLen(string $key): int { + } /** * - *Returns and removes the first element of the list. + *从列表左侧删除一个元素 * @example *
      * $redis->rPush('key1', 'A');
@@ -373,18 +512,17 @@ public function strLen()
      * $redis->rPush('key1', 'C');  // key1 => [ 'A', 'B', 'C' ]
      * $redis->lPop('key1');        // key1 => [ 'B', 'C' ]
      * 
+ * @param string $key 键名 * @return string */ - public function lPop() + public function lPop(string $key): string { + } /** * - *Is a blocking lPop primitive. If at least one of the lists contains at least one element, - *the element will be popped from the head of the list and returned to the caller. - *Il all the list identified by the keys passed in arguments are empty, blPop will block - *during the specified timeout until an element is pushed to one of those lists. This element will be popped. + *是一个阻塞lPop原语。 如果至少有一个列表包含至少一个元素,则该元素将从列表头部弹出并返回给调用者。 如果所有通过参数传递的键标识的列表都是空的,blPop将在指定的超时期间阻塞,直到元素被推送到其中一个列表。 这个元素将被弹出。 * @example *
      * // Non blocking feature
@@ -406,15 +544,18 @@ public function lPop()
      * // process 1
      * // array('key1', 'A') is returned
      * 
+ * @param string|...|array $key 键名 + * @param int $timeout 超时时间 * @return array */ - public function blPop() + public function blPop(string $key, int $timeout): array { + } /** * - *Returns and removes the last element of the list. + *从列表右侧删除一个元素 * @example *
      * $redis->rPush('key1', 'A');
@@ -422,19 +563,17 @@ public function blPop()
      * $redis->rPush('key1', 'C');  // key1 => [ 'A', 'B', 'C' ]
      * $redis->rPop('key1');        // key1 => [ 'A', 'B' ]
      * 
+ * @param string $key 键名 * @return string */ - public function rPop() + public function rPop(string $key): string { + } /** * - *Is a blocking rPop primitive. If at least one of the lists contains at least one element, - *the element will be popped from the head of the list and returned to the caller. - *Il all the list identified by the keys passed in arguments are empty, brPop will - *block during the specified timeout until an element is pushed to one of those lists. T - *his element will be popped. + *是一个阻塞rPop原语。 如果至少有一个列表包含至少一个元素,则该元素将从列表尾部弹出并返回给调用者。 如果所有通过参数传递的键标识的列表都是空的,brPop将在指定的超时期间阻塞,直到元素被推送到其中一个列表。 这个元素将被弹出。 * @example *
      * // Non blocking feature
@@ -456,74 +595,79 @@ public function rPop()
      * // process 1
      * // array('key1', 'A') is returned
      * 
+ * @param string|...|array $key 键名 + * @param int $timeout 超时时间 * @return array */ - public function brPop() + public function brPop(string $key, int $timeout): array { + } /** * - * + *阻塞执行rpoplpush * @example - * @return + * @param string $srcKey 要删除元素的队列键名 + * @param string $dstKey 要插入元素的队列的键名 + * @return string */ - public function bRPopLPush() + public function bRPopLPush(string $srcKey, string $dstKey): string { + } /** * - * + *返回列表的长度 * @example - * @return + * @param string|...|array $key 键名 + * @return int | bool */ - public function lSize() + public function lSize(string $key): ?int { + } /** * - *Returns the size of a list identified by Key. If the list didn't exist or is empty, - *the command returns 0. If the data type identified by Key is not a list, the command return FALSE. + *返回列表的长度 * @example - *
-     * $redis->rPush('key1', 'A');
-     * $redis->rPush('key1', 'B');
-     * $redis->rPush('key1', 'C');  // key1 => [ 'A', 'B', 'C' ]
-     * $redis->lLen('key1');       // 3
-     * $redis->rPop('key1');
-     * $redis->lLen('key1');       // 2
-     * 
- * @return bool + * @param string|...|array $key 键名 + * @return int | bool */ - public function lLen() + public function lLen(string $key): ?int { + } /** * - * + *返回集合的元素个数 * @example - * @return + * @param string $key 键名 + * @return int */ - public function sSize() + public function sSize(string $key): int { + } /** * - * + *返回集合的元素个数 * @example - * @return + * @param string $key 键名 + * @return int */ - public function scard() + public function scard(string $key): int { + } /** * - *Removes and returns a random element from the set value at Key. + *随机删除元素的某个或某些成员,并返回这个删除的成员. * @example *
      * $redis->sAdd('key1' , 'set1');
@@ -532,15 +676,18 @@ public function scard()
      * $redis->sPop('key1');            // 'set1', 'key1' => {'set3', 'set2'}
      * $redis->sPop('key1');            // 'set3', 'key1' => {'set2'}
      * 
- * @return bool + * @param string $key 键名 + * @param int $count 删除个数 + * @return string | bool */ - public function sPop() + public function sPop(string $key, int $count): ?string { + } /** * - *Returns the contents of a set. + *返回集合的所有成员 * @example *
      * $redis->delete('s');
@@ -559,25 +706,46 @@ public function sPop()
      * //}
      * // The order is random and corresponds to redis' own internal representation of the set structure.
      * 
+ * @param string $key 键名 * @return array */ - public function sMembers() + public function sMembers(string $key): array { + } /** * - * + *返回集合的所有成员 * @example + *
+     * $redis->delete('s');
+     * $redis->sAdd('s', 'a');
+     * $redis->sAdd('s', 'b');
+     * $redis->sAdd('s', 'a');
+     * $redis->sAdd('s', 'c');
+     * var_dump($redis->sMembers('s'));
+     * //array(3) {
+     * //  [0]=>
+     * //  string(1) "c"
+     * //  [1]=>
+     * //  string(1) "a"
+     * //  [2]=>
+     * //  string(1) "b"
+     * //}
+     * // The order is random and corresponds to redis' own internal representation of the set structure.
+     * 
+ * @param string $key 键名 * @return array */ - public function sGetMembers() + public function sGetMembers(string $key): array { + } /** * - *Returns a random element(s) from the set value at Key, without removing it. + *随机返回一个集合的元素(不会删除它) * @example *
      * $redis->sAdd('key1' , 'one');
@@ -591,45 +759,53 @@ public function sGetMembers()
      * //   [1]=> string(2) "three"
      * // }
      * 
- * @return bool + * @param string $key 键名 + * @return string | bool */ - public function sRandMember() + public function sRandMember(string $key): ?string { + } /** * - *Remove the expiration timer from a key. + *移除指定键的有效期,让它永久有效 * @example $redis->persist('key'); - * @return bool: + * @param string $key 键名 + * @return bool */ - public function persist() + public function persist(string $key): bool { + } /** * - *Returns the time to live left for a given key, in seconds. If the key doesn't exist, FALSE is returned. + *返回指定键的有效时间(秒) * @example $redis->ttl('key'); - * @return int, + * @param string $key 键名 + * @return int */ - public function ttl() + public function ttl(string $key): int { + } /** * - *Returns a time to live left for a given key, in milliseconds. + *返回指定键的有效时间(毫秒) * @example $redis->pttl('key'); + * @param string $key 键名 * @return int */ - public function pttl() + public function pttl(string $key): int { + } /** * - *Returns the cardinality of an ordered set. + *获取有序集合的成员数 * @example *
      * $redis->zAdd('key', 0, 'val0');
@@ -637,25 +813,35 @@ public function pttl()
      * $redis->zAdd('key', 10, 'val10');
      * $redis->zCard('key');            // 3
      * 
+ * @param string $key 集合键名 * @return int */ - public function zCard() + public function zCard(string $key): int { + } /** * - * + *获取有序集合的成员数 * @example - * @return + *
+     * $redis->zAdd('key', 0, 'val0');
+     * $redis->zAdd('key', 2, 'val2');
+     * $redis->zAdd('key', 10, 'val10');
+     * $redis->zCard('key');            // 3
+     * 
+ * @param string $key 集合键名 + * @return int */ - public function zSize() + public function zSize(string $key): int { + } /** * - *Returns the length of a hash, in number of items + *获取字典的字段个数 * @example *
      * $redis->delete('h')
@@ -663,15 +849,17 @@ public function zSize()
      * $redis->hSet('h', 'key2', 'plop');
      * $redis->hLen('h'); // returns 2
      * 
+ * @param string $key 键名 * @return int */ - public function hLen() + public function hLen(string $key): int { + } /** * - *Returns the keys in a hash, as an array of strings. + *获取字典的字段名称列表. * @example *
      * $redis->delete('h');
@@ -693,15 +881,17 @@ public function hLen()
      * // }
      * // The order is random and corresponds to redis' own internal representation of the set structure.
      * 
+ * @param string $key 键名 * @return array */ - public function hKeys() + public function hKeys(string $key): array { + } /** * - *Returns the values in a hash, as an array of strings. + *获取字典的字段值列表 * @example *
      * $redis->delete('h');
@@ -723,15 +913,17 @@ public function hKeys()
      * // }
      * // The order is random and corresponds to redis' own internal representation of the set structure.
      * 
+ * @param string $key 键名 * @return array */ - public function hVals() + public function hVals(string $key): array { + } /** * - *Returns the whole hash, as an array of strings indexed by strings. + *获取字典所有字段键值对 * @example *
      * $redis->delete('h');
@@ -753,98 +945,102 @@ public function hVals()
      * // }
      * // The order is random and corresponds to redis' own internal representation of the set structure.
      * 
+ * @param string $key 键名 * @return array */ - public function hGetAll() + public function hGetAll(string $key): array { + } /** * - * + *调试命令(不建议使用) * @example * @return */ public function debug() { + } /** * - *Restore a key from the result of a DUMP operation. + *将dump导出的二进制数据恢复到可读的字符串. * @example *
      * $redis->set('foo', 'bar');
      * $val = $redis->dump('foo');
      * $redis->restore('bar', 0, $val); // The key 'bar', will now be equal to the key 'foo'
      * 
+ * @param string $key 键名 + * @param int $ttl 有效期 + * @param string $value dump导出的二进制数据 * @return */ - public function restore() + public function restore(string $key, int $ttl, string $value) { + } /** * - *Dump a key out of a redis database, the value of which can later be passed into redis using the RESTORE command. - *The data that comes out of DUMP is a binary representation of the key as Redis stores it. + *将某个键导出为一个二进制数据. * @example *
      * $redis->set('foo', 'bar');
      * $val = $redis->dump('foo'); // $val will be the Redis encoded key value
      * 
+ * @param string $key 键名 * @return string */ - public function dump() + public function dump(string $key): string { + } /** * - * + *给键重命名 * @example - * @return + * @param string $srcKey 旧键名 + * @param string $dstKey 新键名 + * @return boolean */ - public function renameKey() + public function renameKey(string $srcKey, string $dstKey): boolean { + } /** * - *Renames a key. + *给键重命名 * @example - *
-     * $redis->set('x', '42');
-     * $redis->rename('x', 'y');
-     * $redis->get('y');   // → 42
-     * $redis->get('x');   // → `FALSE`
-     * 
- * @return bool: + * @param string $srcKey 旧键名 + * @param string $dstKey 新键名 + * @return boolean */ - public function rename() + public function rename(string $srcKey, string $dstKey): boolean { + } /** * - *Renames a key. + *当目标键名不存在时,给键重命名 * @example - *
-     * $redis->set('x', '42');
-     * $redis->rename('x', 'y');
-     * $redis->get('y');   // → 42
-     * $redis->get('x');   // → `FALSE`
-     * 
- * @return bool: + * @param string $srcKey 旧键名 + * @param string $dstKey 新键名 + * @return boolean */ - public function renameNx() + public function renameNx(string $srcKey, string $dstKey): boolean { + } /** * - *Pops a value from the tail of a list, and pushes it to the front of another list. - *Also return this value. + *从一个队列的队尾删除一个元素,并将该元素插入到另一个队列的头部 * @example *
      * $redis->delete('x', 'y');
@@ -872,61 +1068,68 @@ public function renameNx()
      * //  string(3) "123"
      * //}
      * 
+ * @param string $srcKey 要删除元素的队列键名 + * @param string $dstKey 要插入元素的队列的键名 * @return string */ - public function rpoplpush() + public function rpoplpush(string $srcKey, string $dstKey): string { + } /** * - *Returns a random key. + *返回一个随机的键 * @example *
      * $key = $redis->randomKey();
      * $surprise = $redis->get($key);  // who knows what's in there.
      * 
- * @return string: + * @return string */ - public function randomKey() + public function randomKey(): string { + } /** * - *Check the current connection status + *检查当前redis连接状态(成功时返回PONG) * @example * @return string */ - public function ping() + public function ping(): string { + } /** * - *Authenticate the connection using a password. - *Warning: The password is sent in plain-text over the network. + *设置连接的认证密码 * @example $redis->auth('foobared'); - * @return bool: + * @param string $password 认证密码 + * @return bool */ - public function auth() + public function auth(string $password): bool { + } /** * - * + *取消观察某个键在其他客户端的变化情况 * @example + * @param string|array $keys 键名 * @return */ - public function unwatch() + public function unwatch(string $keys) { + } /** * - *Watches a key for modifications by another client. If the key is modified between WATCH and EXEC, - *the MULTI/EXEC transaction will fail (return FALSE). unwatch cancels all the watching of all keys by this client. + *观察某个键在其他客户端的变化情况. * @example *
      * $redis->watch('x');
@@ -936,89 +1139,98 @@ public function unwatch()
      * ->exec();
      * // $ret = FALSE if x has been modified between the call to WATCH and the call to EXEC.
      * 
+ * @param string|array $keys 键名 * @return */ - public function watch() + public function watch(string $keys) { + } /** * - *Performs a synchronous save. + *将数据同步到硬盘上 * @example $redis->save(); - * @return If + * @return boolean */ - public function save() + public function save(): boolean { + } /** * - * + *将数据存入到硬盘上(异步操作) * @example * @return */ public function bgSave() { + } /** * - *Returns the timestamp of the last disk save. + *获取上次数据同步到硬盘的时间 * @example $redis->lastSave(); - * @return int: + * @return int */ - public function lastSave() + public function lastSave(): int { + } /** * - *Removes all entries from the current database. + *删除当前数据库的所有键 * @example $redis->flushDB(); - * @return bool: + * @return bool */ - public function flushDB() + public function flushDB(): bool { + } /** * - *Removes all entries from all databases. + *删除当前实例的所有键 * @example $redis->flushAll(); - * @return bool: + * @return bool */ - public function flushAll() + public function flushAll(): bool { + } /** * - *Returns the current database's size. + *获取当前数据库的键的个数 * @example *
      * $count = $redis->dbSize();
      * echo "Redis has $count keys\n";
      * 
- * @return int: + * @return int */ - public function dbSize() + public function dbSize(): int { + } /** * - *Starts the background rewrite of AOF (Append-Only File) + *开启后台写AOF日志操作 * @example $redis->bgrewriteaof(); - * @return bool: + * @return bool */ - public function bgrewriteaof() + public function bgrewriteaof(): bool { + } /** * - *Return the current Redis server time. + *返回当前redis服务器时间. * @example *
      * var_dump( $redis->time() );
@@ -1027,80 +1239,97 @@ public function bgrewriteaof()
      * //   [1] => string(6) "253002"
      * // }
      * 
- * @return unix + * @return int */ - public function time() + public function time(): int { + } /** * - * + *返回当前连接的服务器的角色,如master、alone、slave、sentinel * @example - * @return + * @return string */ - public function role() + public function role(): string { + } /** * - *Changes a substring of a larger string. + *修改某个键的某个位置的值 * @example *
      * $redis->set('key', 'Hello world');
      * $redis->setRange('key', 6, "redis"); // returns 11
      * $redis->get('key');                  // "Hello redis"
      * 
- * @return string: + * @param string $key 键名 + * @param int $offset 开始位置 + * @param string $value 被替换的子串的值 + * @return string */ - public function setRange() + public function setRange(string $key, int $offset, string $value): string { + } /** * - * + *当键不存在时设置其值 * @example - * @return + * $redis->setnx('key', 'value'); + * + * @param string $key 设置的缓存键 + * @param string $value 设置的缓存值 + * @return bool */ - public function setNx() + public function setNx(string $key, string $value): bool { + } /** * - *Sets a value and returns the previous entry at that key. + *设置键的值,并返回它的旧的缓存值 * @example *
      * $redis->set('x', '42');
      * $exValue = $redis->getSet('x', 'lol');   // return '42', replaces x by 'lol'
      * $newValue = $redis->get('x')'            // return 'lol'
      * 
+ * @param string $key 设置的缓存键 + * @param string $value 设置的缓存值 * @return string */ - public function getSet() + public function getSet(string $key, string $value): string { + } /** * - *Append specified string to the string stored in specified key. + *将字符串追加到键值后(返回值的长度) * @example *
      * $redis->set('key', 'value1');
      * $redis->append('key', 'value2'); // 12
      * $redis->get('key');              // 'value1value2'
      * 
- * @return int: + * @param string $key 键名 + * @param string $value 追加的值 + * @return int */ - public function append() + public function append(string $key, string $value): int { + } /** * - *Adds the string value to the head (left) of the list if the list exists. + *如果列表存在,从左侧(头部)向列表插入元素 * @example *
      * $redis->delete('key1');
@@ -1110,16 +1339,18 @@ public function append()
      * $redis->lPushx('key1', 'C');     // returns 3
      * // key1 now points to the following list: [ 'A', 'B', 'C' ]
      * 
+ * @param string $key 键名 + * @param string $value 元素值 * @return int */ - public function lPushx() + public function lPushx(string $key, string $value): int { + } /** * - *Adds the string values to the head (left) of the list. Creates the list if the key didn't exist. - *If the key exists and is not a list, FALSE is returned. + *从左侧(头部)向列表插入元素 * @example *
      * $redis->lPush('l', 'v1', 'v2', 'v3', 'v4')   // int(4)
@@ -1132,16 +1363,18 @@ public function lPushx()
      * //   [3]=> string(2) "v1"
      * // }
      * 
+ * @param string $key 键名 + * @param string $value 元素值 * @return int */ - public function lPush() + public function lPush(string $key, string $value): int { + } /** * - *Adds the string values to the tail (right) of the list. Creates the list if the key didn't exist. - *If the key exists and is not a list, FALSE is returned. + *从右侧(尾部)向列表插入元素 * @example *
      * $redis->rPush('l', 'v1', 'v2', 'v3', 'v4');    // int(4)
@@ -1154,15 +1387,18 @@ public function lPush()
      * //   [3]=> string(2) "v4"
      * // }
      * 
+ * @param string $key 键名 + * @param string $value 元素值 * @return int */ - public function rPush() + public function rPush(string $key, string $value): int { + } /** * - *Adds the string value to the tail (right) of the list if the ist exists. FALSE in case of Failure. + *如果列表存在,从右侧(尾部)向列表插入元素 * @example *
      * $redis->delete('key1');
@@ -1172,50 +1408,61 @@ public function rPush()
      * $redis->rPushx('key1', 'C'); // returns 3
      * // key1 now points to the following list: [ 'A', 'B', 'C' ]
      * 
+ * @param string $key 键名 + * @param string $value 元素值 * @return int */ - public function rPushx() + public function rPushx(string $key, string $value): int { + } /** * - * + *是否包含某个成员 * @example - * @return + * @param string $key 键名 + * @param string $member 成员值 + * @return boolean */ - public function sContains() + public function sContains(string $key, string $member): boolean { + } /** * - * + *是否包含某个成员 * @example - * @return + * @param string $key 键名 + * @param string $member 成员值 + * @return boolean */ - public function sismember() + public function sismember(string $key, string $member): boolean { + } /** * - *Returns the score of a given member in the specified sorted set. + *获取指定成员的排序值(分数) * @example *
      * $redis->zAdd('key', 2.5, 'val2');
      * $redis->zScore('key', 'val2'); // 2.5
      * 
- * @return + * @param string $key 集合键名 + * @param string $member 成员值 + * @return double */ - public function zScore() + public function zScore(string $key, string $member): double { + } /** * - *Returns the rank of a given member in the specified sorted set, starting at 0 for the item - *with the smallest score. zRevRank starts at 0 for the item with the largest score. + *获取成员的排序值 * @example *
      * $redis->delete('z');
@@ -1226,77 +1473,88 @@ public function zScore()
      * $redis->zRevRank('key', 'one');  // 1
      * $redis->zRevRank('key', 'two');  // 0
      * 
+ * @param string $key 集合键名 + * @param string $member 成员值 * @return int */ - public function zRank() + public function zRank(string $key, string $member): int { + } /** * - * + *获取成员的排位值(倒数) * @example + * @param string $key 集合键名 + * @param string $member 成员值 * @return int */ - public function zRevRank() + public function zRevRank(string $key, string $member): int { + } /** * - *Gets a value from the hash stored at key. - *If the hash table doesn't exist, or the key doesn't exist, FALSE is returned. + *获取字典的某个字段的值 * @example + * @param string $key 键名 + * @param string $field 字段名 * @return string */ - public function hGet() + public function hGet(string $key, string $field): string { + } /** * - *Retirieve the values associated to the specified fields in the hash. + *批量获取字典的字段值 * @example - *
-     * $redis->delete('h');
-     * $redis->hSet('h', 'field1', 'value1');
-     * $redis->hSet('h', 'field2', 'value2');
-     * $redis->hmGet('h', array('field1', 'field2')); // returns array('field1' => 'value1', 'field2' => 'value2')
-     * 
- * @return with + * @param string $key 键名 + * @param array $fields 字段名列表 + * @return array */ - public function hMGet() + public function hMGet(string $key, Array $fields): array { + } /** * - *Verify if the specified member exists in a key. + *判断字典的某个字段是否存在. * @example *
      * $redis->hSet('h', 'a', 'x');
      * $redis->hExists('h', 'a');               //  TRUE
      * $redis->hExists('h', 'NonExistingKey');  // FALSE
      * 
- * @return bool: + * @param string $key 键名 + * @param string $field 字段名 + * @return bool */ - public function hExists() + public function hExists(string $key, string $field): bool { + } /** * - *Publish messages to channels. Warning: this function will probably change in the future. + *将消息发布到消息通道(队列). * @example $redis->publish('chan-1', 'hello, world!'); // send message. + * @param string $channel 消息频道 + * @param string $message 消息 * @return int */ - public function publish() + public function publish(string $channel, string $message): int { + } /** * - *Increments the score of a member from a sorted set by a given amount. + *给有序集合成员增加排序值 * @example *
      * $redis->delete('key');
@@ -1304,15 +1562,19 @@ public function publish()
      * // before the increment and now has the value 2.5
      * $redis->zIncrBy('key', 1, 'member1');    // 3.5
      * 
+ * @param string $key 目标集合键名 + * @param double $step 增加的步长 + * @param string $member 成员 * @return float */ - public function zIncrBy() + public function zIncrBy(string $key, double $step, string $member): float { + } /** * - *Adds the specified member with a given score to the sorted set stored at key. + *向有序集合插入元素 * @example *
      * 
@@ -1326,43 +1588,47 @@ public function zIncrBy()
      * // }
      * 
*
+ * @param string $key 集合键名 + * @param double $score 排序值 + * @param string $value 元素值 * @return int */ - public function zAdd() + public function zAdd(string $key, double $score, string $value): int { + } /** * - * + *根据排序值范围来删除成员 * @example - * @return + * @param string $key 集合键名 + * @param double $start 开始排序值 + * @param double $end 结束排序值 + * @return int */ - public function zDeleteRangeByScore() + public function zDeleteRangeByScore(string $key, double $start, double $end): int { + } /** * - *Deletes the elements of the sorted set stored at the specified key which have scores in the range [start,end]. + *根据排序值范围来删除成员 * @example - *
-     * $redis->zAdd('key', 0, 'val0');
-     * $redis->zAdd('key', 2, 'val2');
-     * $redis->zAdd('key', 10, 'val10');
-     * $redis->zRemRangeByScore('key', 0, 3); // 2
-     * 
+ * @param string $key 集合键名 + * @param double $start 开始排序值 + * @param double $end 结束排序值 * @return int */ - public function zRemRangeByScore() + public function zRemRangeByScore(string $key, double $start, double $end): int { + } /** * - *Returns the number of elements of the sorted set stored at the specified key which have - *scores in the range [start,end]. Adding a parenthesis before start or end excludes it - *from the range. +inf and -inf are also valid limits. + *获取指定排序范围的成员数. * @example *
      * $redis->zAdd('key', 0, 'val0');
@@ -1370,20 +1636,19 @@ public function zRemRangeByScore()
      * $redis->zAdd('key', 10, 'val10');
      * $redis->zCount('key', 0, 3); // 2, corresponding to array('val0', 'val2')
      * 
+ * @param string $key 集合键名 + * @param double $start 开始排序值 + * @param double $end 结束排序值 * @return int */ - public function zCount() + public function zCount(string $key, double $start, double $end): int { + } /** * - *Returns a range of elements from the ordered set stored at the specified key, - *with values in the range [start, end]. start and stop are interpreted as zero-based indices: - *0 the first element, - *1 the second ... - *-1 the last element, - *-2 the penultimate ... + *获取有序集合中指定范围的成员 * @example *
      * $redis->zAdd('key1', 0, 'val0');
@@ -1393,20 +1658,20 @@ public function zCount()
      * // with scores
      * $redis->zRange('key1', 0, -1, true); // array('val0' => 0, 'val2' => 2, 'val10' => 10)
      * 
+ * @param string $key 集合键名 + * @param int $start 索引开始值 + * @param int $end 索引结束值 + * @param boolean $withScores 是否返回成员的排序值 * @return array */ - public function zRange() + public function zRange(string $key, int $start, int $end, bool $withScores): array { + } /** * - *Returns the elements of the sorted set stored at the specified key in the range [start, end] - *in reverse order. start and stop are interpretated as zero-based indices: - *0 the first element, - *1 the second ... - *-1 the last element, - *-2 the penultimate ... + *获取有序集合中指定范围的成员(倒序排列) * @example *
      * $redis->zAdd('key', 0, 'val0');
@@ -1416,17 +1681,20 @@ public function zRange()
      * // with scores
      * $redis->zRevRange('key', 0, -1, true); // array('val10' => 10, 'val2' => 2, 'val0' => 0)
      * 
+ * @param string $key 集合键名 + * @param int $start 索引开始值 + * @param int $end 索引结束值 + * @param boolean $withScores 是否返回成员的排序值 * @return array */ - public function zRevRange() + public function zRevRange(string $key, int $start, int $end, bool $withScores): array { + } /** * - *Returns the elements of the sorted set stored at the specified key which have scores in the - *range [start,end]. Adding a parenthesis before start or end excludes it from the range. - *+inf and -inf are also valid limits. + *获取有序集合中指定范围的成员(按排序值排列) * @example *
      * $redis->zAdd('key', 0, 'val0');
@@ -1438,28 +1706,45 @@ public function zRevRange()
      * $redis->zRangeByScore('key', 0, 3, array('limit' => array(1, 1));                        // array('val2')
      * $redis->zRangeByScore('key', 0, 3, array('withscores' => TRUE, 'limit' => array(1, 1));  // array('val2' => 2)
      * 
+ * @param string $key 集合键名 + * @param int $start 索引开始值 + * @param int $end 索引结束值 + * @param array $options 附加选项(可以是:withscores => TRUE, and limit => array($offset, $count)) * @return array */ - public function zRangeByScore() + public function zRangeByScore(string $key, int $start, int $end, Array $options): array { + } /** * - * + *获取有序集合中指定范围的成员(按排序值倒序排列) * @example - * @return + *
+     * $redis->zAdd('key', 0, 'val0');
+     * $redis->zAdd('key', 2, 'val2');
+     * $redis->zAdd('key', 10, 'val10');
+     * $redis->zRangeByScore('key', 0, 3);                                          // array('val0', 'val2')
+     * $redis->zRangeByScore('key', 0, 3, array('withscores' => TRUE);              // array('val0' => 0, 'val2' => 2)
+     * $redis->zRangeByScore('key', 0, 3, array('limit' => array(1, 1));                        // array('val2' => 2)
+     * $redis->zRangeByScore('key', 0, 3, array('limit' => array(1, 1));                        // array('val2')
+     * $redis->zRangeByScore('key', 0, 3, array('withscores' => TRUE, 'limit' => array(1, 1));  // array('val2' => 2)
+     * 
+ * @param string $key 集合键名 + * @param int $start 索引开始值 + * @param int $end 索引结束值 + * @param array $options 附加选项(可以是:withscores => TRUE, and limit => array($offset, $count)) + * @return array */ - public function zRevRangeByScore() + public function zRevRangeByScore(string $key, int $start, int $end, Array $options): array { + } /** * - *Returns a lexigraphical range of members in a sorted set, assuming the members have the same score. The - *min and max values are required to start with '(' (exclusive), '[' (inclusive), or be exactly the values - *'-' (negative inf) or '+' (positive inf). The command must be called with either three *or* five - *arguments or will return FALSE. + *按字母字典的顺序返回成员 * @example *
      * foreach (array('a', 'b', 'c', 'd', 'e', 'f', 'g') as $char) {
@@ -1469,30 +1754,37 @@ public function zRevRangeByScore()
      * $redis->zRangeByLex('key', '-', '(c'); // array('a', 'b')
      * $redis->zRangeByLex('key', '-', '[c'); // array('b', 'c')
      * 
+ * @param string $key 集合键名 + * @param int $min 最小的字母 + * @param int $max 最大的字母 + * @param int $offset 索引开始值 + * @param int $limit 成员数 * @return array */ - public function zRangeByLex() + public function zRangeByLex(string $key, int $min, int $max, int $offset, int $limit): array { + } /** * - * + *按字母字典的顺序返回成员(倒序排序) * @example + * @param string $key 集合键名 + * @param int $min 最小的字母 + * @param int $max 最大的字母 + * @param int $offset 索引开始值 + * @param int $limit 成员数 * @return */ - public function zRevRangeByLex() + public function zRevRangeByLex(string $key, int $min, int $max, int $offset, int $limit) { + } /** * - *Creates an intersection of sorted sets given in second argument. - *The result of the union will be stored in the sorted set defined by the first argument. - *The third optional argument defines weights to apply to the sorted sets in input. - *In this case, the weights will be multiplied by the score of each element in the sorted set - *before applying the aggregation. The forth argument defines the AGGREGATE option which - *specify how the results of the union are aggregated. + *将两个有序集合的交集存入到一个指定的键中 * @example *
      * $redis->delete('k1');
@@ -1513,30 +1805,54 @@ public function zRevRangeByLex()
      * $redis->zInter('ko3', array('k1', 'k2'), array(1, 5), 'min'); // 2, 'ko3' => array('val1', 'val3')
      * $redis->zInter('ko4', array('k1', 'k2'), array(1, 5), 'max'); // 2, 'ko4' => array('val3', 'val1')
      * 
+ * @param string $dstKey 目标集合键名 + * @param array $zsetKeys 集合键名 + * @param array $zsetKeysWeight 集合键对应的权重 + * @param string $aggregateFunction 合并使用的函数(SUM, MIN, 或 MAX) * @return int */ - public function zInter() + public function zInter(string $dstKey, Array $zsetKeys, Array $zsetKeysWeight, string $aggregateFunction): int { + } /** * - * + *将两个有序集合的交集存入到一个指定的键中 * @example - * @return + *
+     * $redis->delete('k1');
+     * $redis->delete('k2');
+     * $redis->delete('k3');
+     * $redis->delete('ko1');
+     * $redis->delete('ko2');
+     * $redis->delete('ko3');
+     * $redis->delete('ko4');
+     * $redis->zAdd('k1', 0, 'val0');
+     * $redis->zAdd('k1', 1, 'val1');
+     * $redis->zAdd('k1', 3, 'val3');
+     * $redis->zAdd('k2', 2, 'val1');
+     * $redis->zAdd('k2', 3, 'val3');
+     * $redis->zInter('ko1', array('k1', 'k2'));               // 2, 'ko1' => array('val1', 'val3')
+     * $redis->zInter('ko2', array('k1', 'k2'), array(1, 1));  // 2, 'ko2' => array('val1', 'val3')
+     * // Weighted zInter
+     * $redis->zInter('ko3', array('k1', 'k2'), array(1, 5), 'min'); // 2, 'ko3' => array('val1', 'val3')
+     * $redis->zInter('ko4', array('k1', 'k2'), array(1, 5), 'max'); // 2, 'ko4' => array('val3', 'val1')
+     * 
+ * @param string $dstKey 目标集合键名 + * @param array $zsetKeys 集合键名 + * @param array $zsetKeysWeight 集合键对应的权重 + * @param string $aggregateFunction 合并使用的函数(SUM, MIN, 或 MAX) + * @return int */ - public function zinterstore() + public function zinterstore(string $dstKey, Array $zsetKeys, Array $zsetKeysWeight, string $aggregateFunction): int { + } /** * - *Creates an union of sorted sets given in second argument. - *The result of the union will be stored in the sorted set defined by the first argument. - *The third optionnel argument defines weights to apply to the sorted sets in input. - *In this case, the weights will be multiplied by the score of each element in the sorted set - *before applying the aggregation. The forth argument defines the AGGREGATE option which - *specify how the results of the union are aggregated. + *将两个有序集合的并集存入到一个指定的键中 * @example *
      * $redis->delete('k1');
@@ -1554,26 +1870,51 @@ public function zinterstore()
      * $redis->zUnion('ko2', array('k1', 'k2'), array(1, 1)); // 4, 'ko2' => array('val0', 'val1', 'val2', 'val3')
      * $redis->zUnion('ko3', array('k1', 'k2'), array(5, 1)); // 4, 'ko3' => array('val0', 'val2', 'val3', 'val1')
      * 
+ * @param string $dstKey 目标集合键名 + * @param array $zsetKeys 集合键名 + * @param array $zsetKeysWeight 集合键对应的权重 + * @param string $aggregateFunction 合并使用的函数(SUM, MIN, 或 MAX) * @return int */ - public function zUnion() + public function zUnion(string $dstKey, Array $zsetKeys, Array $zsetKeysWeight, string $aggregateFunction): int { + } /** * - * + *将两个有序集合的并集存入到一个指定的键中 * @example - * @return + *
+     * $redis->delete('k1');
+     * $redis->delete('k2');
+     * $redis->delete('k3');
+     * $redis->delete('ko1');
+     * $redis->delete('ko2');
+     * $redis->delete('ko3');
+     * $redis->zAdd('k1', 0, 'val0');
+     * $redis->zAdd('k1', 1, 'val1');
+     * $redis->zAdd('k2', 2, 'val2');
+     * $redis->zAdd('k2', 3, 'val3');
+     * $redis->zUnion('ko1', array('k1', 'k2')); // 4, 'ko1' => array('val0', 'val1', 'val2', 'val3')
+     * // Weighted zUnion
+     * $redis->zUnion('ko2', array('k1', 'k2'), array(1, 1)); // 4, 'ko2' => array('val0', 'val1', 'val2', 'val3')
+     * $redis->zUnion('ko3', array('k1', 'k2'), array(5, 1)); // 4, 'ko3' => array('val0', 'val2', 'val3', 'val1')
+     * 
+ * @param string $dstKey 目标集合键名 + * @param array $zsetKeys 集合键名 + * @param array $zsetKeysWeight 集合键对应的权重 + * @param string $aggregateFunction 合并使用的函数(SUM, MIN, 或 MAX) + * @return int */ - public function zunionstore() + public function zunionstore(string $dstKey, Array $zsetKeys, Array $zsetKeysWeight, string $aggregateFunction): int { + } /** * - *Increment the number stored at key by one. If the second argument is filled, it will be used as the integer - *value of the increment. + *按指定步长自增 * @example *
      * $redis->incr('key1');        // key1 didn't exists, set to 0 before the increment and now has the value 1
@@ -1582,30 +1923,37 @@ public function zunionstore()
      * $redis->incr('key1');        // 4
      * $redis->incrBy('key1', 10);  // 14
      * 
+ * @param string $key 键名 + * @param int $step 自增步长 * @return int */ - public function incrBy() + public function incrBy(string $key, int $step): int { + } /** * - *Increments the value of a member from a hash by a given amount. + *为指定字段增加指定的值. * @example *
      * $redis->delete('h');
      * $redis->hIncrBy('h', 'x', 2); // returns 2: h[x] = 2 now.
      * $redis->hIncrBy('h', 'x', 1); // h[x] ← 2 + 1. Returns 3
      * 
+ * @param string $key 键名 + * @param string $field 字段名 + * @param int $step 自增步长 * @return int */ - public function hIncrBy() + public function hIncrBy(string $key, string $field, int $step): int { + } /** * - *Increment the number stored at key by one. + *键值自增 * @example *
      * $redis->incr('key1'); // key1 didn't exists, set to 0 before the increment and now has the value 1
@@ -1613,16 +1961,17 @@ public function hIncrBy()
      * $redis->incr('key1'); // 3
      * $redis->incr('key1'); // 4
      * 
+ * @param string $key 键名 * @return int */ - public function incr() + public function incr(string $key): int { + } /** * - *Decrement the number stored at key by one. If the second argument is filled, it will be used as the integer - *value of the decrement. + *按指定步长自减 * @example *
      * $redis->decr('key1');        // key1 didn't exists, set to 0 before the increment and now has the value -1
@@ -1630,47 +1979,53 @@ public function incr()
      * $redis->decr('key1');        // -3
      * $redis->decrBy('key1', 10);  // -13
      * 
+ * @param string $key 键名 + * @param float $step 自减步长 * @return int */ - public function decrBy() + public function decrBy(string $key, float $step): int { + } /** * - *Decrement the number stored at key by one. + *键值自减 * @example *
      * $redis->decr('key1'); // key1 didn't exists, set to 0 before the increment and now has the value -1
      * $redis->decr('key1'); // -2
      * $redis->decr('key1'); // -3
      * 
+ * @param string $key 键名 * @return int */ - public function decr() + public function decr(string $key): int { + } /** * - *Return a single bit out of a larger string + *获取某个键的某个位置的位值 * @example *
      * $redis->set('key', "\x7f");  // this is 0111 1111
      * $redis->getBit('key', 0);    // 0
      * $redis->getBit('key', 1);    // 1
      * 
- * @return int: + * @param string $key 键名 + * @param int $offset 所在位置 + * @return int */ - public function getBit() + public function getBit(string $key, int $offset): int { + } /** * - *Insert value in the list before or after the pivot value. the parameter options - *specify the position of the insert (before or after). If the list didn't exists, - *or the pivot didn't exists, the value is not inserted. + *在列表中,在某个元素的前面或后面插入一个新值 * @example *
      * $redis->delete('key1');
@@ -1684,81 +2039,85 @@ public function getBit()
      * $redis->lRange('key1', 0, -1);                       // array('A', 'B', 'X', 'C', 'Y')
      * $redis->lInsert('key1', Redis::AFTER, 'W', 'value'); // -1
      * 
+ * @param string $key 键名 + * @param string $position 位置(前面或后面,使用Redis::BEFORE | Redis::AFTER) + * @param string $element 元素 + * @param string $value 新值 * @return int */ - public function lInsert() + public function lInsert(string $key, string $position, string $element, string $value): int { + } /** * - * + *获取列表中指定索引的值 * @example - * @return + * @param string $key 键名 + * @param int $index 索引值 + * @return string | boolean */ - public function lGet() + public function lGet(string $key, int $index): ?string { + } /** * - *Return the specified element of the list stored at the specified key. - *0 the first element, 1 the second ... -1 the last element, -2 the penultimate ... - *Return FALSE in case of a bad index or a key that doesn't point to a list. + *获取列表中指定索引的值 * @example - *
-     * $redis->rPush('key1', 'A');
-     * $redis->rPush('key1', 'B');
-     * $redis->rPush('key1', 'C');  // key1 => [ 'A', 'B', 'C' ]
-     * $redis->lGet('key1', 0);     // 'A'
-     * $redis->lGet('key1', -1);    // 'C'
-     * $redis->lGet('key1', 10);    // `FALSE`
-     * 
- * @return Bool + * @param string $key 键名 + * @param int $index 索引值 + * @return string | boolean */ - public function lIndex() + public function lIndex(string $key, int $index): ?string { + } /** * - * + *设置键的有效期 * @example - * @return + * @param string $key 键名 + * @param int $ttl 有效期(秒数) + * @return boolean */ - public function setTimeout() + public function setTimeout(string $key, int $ttl): boolean { + } /** * - *Sets an expiration date (a timeout) on an item. + *设置键的有效期 * @example - *
-     * $redis->set('x', '42');
-     * $redis->setTimeout('x', 3);  // x will disappear in 3 seconds.
-     * sleep(5);                    // wait 5 seconds
-     * $redis->get('x');            // will return `FALSE`, as 'x' has expired.
-     * 
- * @return bool: + * @param string $key 键名 + * @param int $ttl 有效期(秒数) + * @return boolean */ - public function expire() + public function expire(string $key, int $ttl): boolean { + } /** * - * + *设置键的有效期(毫秒为单位) * @example - * @return + * @param string $key 键名 + * @param int $ttl 有效期(毫秒数) + * @return boolean */ - public function pexpire() + public function pexpire(string $key, int $ttl): boolean { + } /** * - *Sets an expiration date (a timestamp) on an item. + *为某个键设置有效期为某个时间点 * @example *
      * $redis->set('x', '42');
@@ -1767,25 +2126,38 @@ public function pexpire()
      * sleep(5);                        // wait 5 seconds
      * $redis->get('x');                // will return `FALSE`, as 'x' has expired.
      * 
- * @return bool: + * @param string $key 键名 + * @param int $expireTime 到期时间 + * @return bool */ - public function expireAt() + public function expireAt(string $key, int $expireTime): bool { + } /** * - * + *为某个键设置有效期为某个时间点(精确到毫秒) * @example - * @return + *
+     * $redis->set('x', '42');
+     * $now = time(NULL);               // current timestamp
+     * $redis->expireAt('x', $now + 3); // x will disappear in 3 seconds.
+     * sleep(5);                        // wait 5 seconds
+     * $redis->get('x');                // will return `FALSE`, as 'x' has expired.
+     * 
+ * @param string $key 键名 + * @param int $expireTime 到期时间 + * @return bool */ - public function pexpireAt() + public function pexpireAt(string $key, int $expireTime): bool { + } /** * - *Moves a key to a different database. + *将某个键移动到其他数据库中 * @example *
      * $redis->select(0);       // switch to DB 0
@@ -1794,15 +2166,18 @@ public function pexpireAt()
      * $redis->select(1);       // switch to DB 1
      * $redis->get('x');        // will return 42
      * 
- * @return bool: + * @param string $key 键名 + * @param int $dbIndex 数据库编号 + * @return bool */ - public function move() + public function move(string $key, int $dbIndex): bool { + } /** * - *Switches to a given database. + *切换数据库 * @example *
      * $redis->select(0);       // switch to DB 0
@@ -1811,120 +2186,141 @@ public function move()
      * $redis->select(1);       // switch to DB 1
      * $redis->get('x');        // will return 42
      * 
+ * @param int $dbIndex 数据库编号 * @return bool */ - public function select() + public function select(int $dbIndex): bool { + } /** * - *Return a substring of a larger string + *获取一个键值的子字符串 * @example *
      * $redis->set('key', 'string value');
      * $redis->getRange('key', 0, 5);   // 'string'
      * $redis->getRange('key', -5, -1); // 'value'
      * 
- * @return string: + * @param string $key 键名 + * @param int $start 开始位置 + * @param int $end 结束位置 + * @return string */ - public function getRange() + public function getRange(string $key, int $start, int $end): string { + } /** * - * + *删除指定范围外的其他元素 * @example - * @return + * @param string $key 键名 + * @param int $start 开始索引 + * @param int $end 结束索引 + * @return array | boolean */ - public function listTrim() + public function listTrim(string $key, int $start, int $end): ?array { + } /** * - * + *删除指定范围外的其他元素 * @example - * @return + * @param string $key 键名 + * @param int $start 开始索引 + * @param int $end 结束索引 + * @return array | boolean */ - public function ltrim() + public function ltrim(string $key, int $start, int $end): ?array { + } /** * - * + *获取列表指定范围的值 * @example - * @return + * @param string $key 键名 + * @param int $start 索引开始值 + * @param int $end 索引结束值 + * @return array */ - public function lGetRange() + public function lGetRange(string $key, int $start, int $end): array { + } /** * - *Returns the specified elements of the list stored at the specified key in - *the range [start, end]. start and stop are interpretated as indices: 0 the first element, - *1 the second ... -1 the last element, -2 the penultimate ... + *获取列表指定范围的值 * @example - *
-     * $redis->rPush('key1', 'A');
-     * $redis->rPush('key1', 'B');
-     * $redis->rPush('key1', 'C');
-     * $redis->lRange('key1', 0, -1); // array('A', 'B', 'C')
-     * 
+ * @param string $key 键名 + * @param int $start 索引开始值 + * @param int $end 索引结束值 * @return array */ - public function lRange() + public function lRange(string $key, int $start, int $end): array { + } /** * - *Removes the first count occurences of the value element from the list. - *If count is zero, all the matching elements are removed. If count is negative, - *elements are removed from tail to head. + *从列表中删除指定值的元素。 如果count为零,则删除所有匹配的元素。 如果计数是负数,则元素从尾部移到头部。 * @example - *
-     * $redis->lPush('key1', 'A');
-     * $redis->lPush('key1', 'B');
-     * $redis->lPush('key1', 'C');
-     * $redis->lPush('key1', 'A');
-     * $redis->lPush('key1', 'A');
-     * $redis->lRange('key1', 0, -1);   // array('A', 'A', 'C', 'B', 'A')
-     * $redis->lRem('key1', 'A', 2);    // 2
-     * $redis->lRange('key1', 0, -1);   // array('C', 'B', 'A')
-     * 
- * @return bool + * @param string $key 键名 + * @param string $value 元素值 + * @param int $count 删除的个数 + * @return int | bool */ - public function lRem() + public function lRem(string $key, string $value, int $count): ?int { + } /** * - * + *从列表中删除指定值的元素。 如果count为零,则删除所有匹配的元素。 如果计数是负数,则元素从尾部移到头部。 * @example - * @return + * @param string $key 键名 + * @param string $value 元素值 + * @param int $count 删除的个数 + * @return int | bool */ - public function lRemove() + public function lRemove(string $key, string $value, int $count): ?int { + } /** * - * + *根据排序范围删除成员 * @example - * @return + *
+     * $redis->zAdd('key', 1, 'one');
+     * $redis->zAdd('key', 2, 'two');
+     * $redis->zAdd('key', 3, 'three');
+     * $redis->zRemRangeByRank('key', 0, 1); // 2
+     * $redis->zRange('key', 0, -1, array('withscores' => TRUE)); // array('three' => 3)
+     * 
+ * @param string $key 集合键名 + * @param double $start 开始排序值 + * @param double $end 结束排序值 + * @return int */ - public function zDeleteRangeByRank() + public function zDeleteRangeByRank(string $key, double $start, double $end): int { + } /** * - *Deletes the elements of the sorted set stored at the specified key which have rank in the range [start,end]. + *根据排序范围删除成员 * @example *
      * $redis->zAdd('key', 1, 'one');
@@ -1933,15 +2329,19 @@ public function zDeleteRangeByRank()
      * $redis->zRemRangeByRank('key', 0, 1); // 2
      * $redis->zRange('key', 0, -1, array('withscores' => TRUE)); // array('three' => 3)
      * 
+ * @param string $key 集合键名 + * @param double $start 开始排序值 + * @param double $end 结束排序值 * @return int */ - public function zRemRangeByRank() + public function zRemRangeByRank(string $key, double $start, double $end): int { + } /** * - *Increment the float value of a key by the given amount + *按指定步长自增 * @example *
      * $redis = new Redis();
@@ -1951,15 +2351,18 @@ public function zRemRangeByRank()
      * // ! SIC
      * var_dump( $redis->get('x') );                // string(3) "4.5"
      * 
- * @return + * @param string $key 键名 + * @param float $step 自增步长 + * @return float */ - public function incrByFloat() + public function incrByFloat(string $key, float $step): float { + } /** * - *Increment the float value of a hash field by the given amount + *为指定字段增加指定的值 * @example *
      * $redis = new Redis();
@@ -1976,65 +2379,64 @@ public function incrByFloat()
      * string(1) "3"
      * }
      * 
+ * @param string $key 键名 + * @param string $field 字段名 + * @param double $step 自增步长 * @return */ - public function hIncrByFloat() + public function hIncrByFloat(string $key, string $field, double $step) { + } /** * - *Count bits in a string. + *统计字符串的位数 * @example - *
-     * $redis->set('bit', '345'); // // 11 0011  0011 0100  0011 0101
-     * var_dump( $redis->bitCount('bit', 0, 0) ); // int(4)
-     * var_dump( $redis->bitCount('bit', 1, 1) ); // int(3)
-     * var_dump( $redis->bitCount('bit', 2, 2) ); // int(4)
-     * var_dump( $redis->bitCount('bit', 0, 2) ); // int(11)
-     * 
+ * @param string $key 键名 * @return int */ - public function bitCount() + public function bitCount(string $key): int { + } /** * - *Bitwise operation on multiple keys. + *多个键的位操作,并将结果存入到指定的键中 * @example - *
-     * $redis->set('bit1', '1'); // 11 0001
-     * $redis->set('bit2', '2'); // 11 0010
-     * $redis->bitOp('AND', 'bit', 'bit1', 'bit2'); // bit = 110000
-     * $redis->bitOp('OR',  'bit', 'bit1', 'bit2'); // bit = 110011
-     * $redis->bitOp('NOT', 'bit', 'bit1', 'bit2'); // bit = 110011
-     * $redis->bitOp('XOR', 'bit', 'bit1', 'bit2'); // bit = 11
-     * 
+ * @param string $operation 操作(有 AND, OR, NOT, XOR 4种可选择) + * @param string $dstKey 目标键 + * @param string $key1 键名1 + * @param string $key2 键名2 + * @param string|... $keyN 键名N * @return int */ - public function bitOp() + public function bitOp(string $operation, string $dstKey, string $key1, string $key2, string $keyN): int { + } /** * - *Adds a values to the set value stored at key. - *If this value is already in the set, FALSE is returned. + *给集合添加元素 * @example *
      * $redis->sAdd('k', 'v1');                // int(1)
      * $redis->sAdd('k', 'v1', 'v2', 'v3');    // int(2)
      * 
+ * @param string $key 键名 + * @param string $value 元素值 * @return int */ - public function sAdd() + public function sAdd(string $key, string $value): int { + } /** * - *Moves the specified member from the set at srcKey to the set at dstKey. + *将某个集合中的元素移动到另外一个集合中 * @example *
      * $redis->sAdd('key1' , 'set11');
@@ -2045,15 +2447,19 @@ public function sAdd()
      * $redis->sMove('key1', 'key2', 'set13');  // 'key1' =>  {'set11', 'set12'}
      * // 'key2' =>  {'set21', 'set22', 'set13'}
      * 
- * @return If + * @param string $srcKey 原集合键名 + * @param string $dstKey 目标集合键名 + * @param string $member 成员 + * @return bool */ - public function sMove() + public function sMove(string $srcKey, string $dstKey, string $member): bool { + } /** * - *Performs the difference between N sets and returns it. + *获取多个集合的差集 * @example *
      * $redis->delete('s0', 's1', 's2');
@@ -2071,15 +2477,18 @@ public function sMove()
      * //  string(1) "2"
      * //}
      * 
+ * @param string $key1 键名1 + * @param string|... $key2 键名2 * @return array */ - public function sDiff() + public function sDiff(string $key1, string $key2): array { + } /** * - *Performs the same action as sDiff, but stores the result in the first key + *获取多个集合的差集,并将结果存入到一个新的集合中 * @example *
      * $redis->delete('s0', 's1', 's2');
@@ -2099,15 +2508,20 @@ public function sDiff()
      * //  string(1) "2"
      * //}
      * 
- * @return int: + * @param string $dstKey 目标键,存放结果的键 + * @param string $key1 键名1 + * @param string $key2 键名2 + * @param string|... $keyN 键名n + * @return int */ - public function sDiffStore() + public function sDiffStore(string $dstKey, string $key1, string $key2, string $keyN): int { + } /** * - *Performs the union between N sets and returns it. + *获取集合的并集 * @example *
      * $redis->delete('s0', 's1', 's2');
@@ -2129,15 +2543,18 @@ public function sDiffStore()
      * //  string(1) "2"
      * //}
      * 
+ * @param string $key1 键名1 + * @param string|... $key2 键名2 * @return array */ - public function sUnion() + public function sUnion(string $key1, string $key2): array { + } /** * - *Performs the same action as sUnion, but stores the result in the first key + *获取多个集合的并集,并将结果存入到另外一个集合中 * @example *
      * $redis->delete('s0', 's1', 's2');
@@ -2161,17 +2578,20 @@ public function sUnion()
      * //  string(1) "2"
      * //}
      * 
+ * @param string $dstKey 目标键,存放结果的键 + * @param string $key1 键名1 + * @param string $key2 键名2 + * @param string|... $keyN 键名n * @return int */ - public function sUnionStore() + public function sUnionStore(string $dstKey, string $key1, string $key2, string $keyN): int { + } /** * - *Returns the members of a set resulting from the intersection of all the sets - *held at the specified keys. If just a single key is specified, then this command - *produces the members of this set. If one of the keys is missing, FALSE is returned. + *获取两个集合的交集 * @example *
      * $redis->sAdd('key1', 'val1');
@@ -2190,15 +2610,18 @@ public function sUnionStore()
      * //  string(4) "val3"
      * //}
      * 
- * @return If + * @param string $key1 键名1 + * @param string $key2 键名2 + * @return array | boolean */ - public function sInter() + public function sInter(string $key1, string $key2): ?array { + } /** * - *Performs a sInter command and stores the result in a new set. + *获取多个集合的交集,并将结果存入到另外一个集合中 * @example *
      * $redis->sAdd('key1', 'val1');
@@ -2220,85 +2643,106 @@ public function sInter()
      * //  string(4) "val3"
      * //}
      * 
- * @return int: + * @param string $dstKey 目标键,存放结果的键 + * @param string $key1 键名1 + * @param string $key2 键名2 + * @param string|... $keyN 键名n + * @return int */ - public function sInterStore() + public function sInterStore(string $dstKey, string $key1, string $key2, string $keyN): int { + } /** * - * + *删除集合元素 * @example - * @return + * @param string $key 键名 + * @param string|... $member 成员 + * @return int */ - public function sRemove() + public function sRemove(string $key, string $member): int { + } /** * - * + *删除集合元素 * @example - * @return + * @param string $key 键名 + * @param string|... $member 成员 + * @return int */ - public function srem() + public function srem(string $key, string $member): int { + } /** * - * + *删除有序集合中的某个成员 * @example + * @param string $key 集合键名 + * @param string $member 成员值 * @return int */ - public function zDelete() + public function zDelete(string $key, string $member): int { + } /** * - * + *删除有序集合中的某个成员 * @example - * @return + * @param string $key 集合键名 + * @param string $member 成员值 + * @return int */ - public function zRemove() + public function zRemove(string $key, string $member): int { + } /** * - *Deletes a specified member from the ordered set. + *删除有序集合中的某个成员 * @example - *
-     * $redis->zAdd('z', 1, 'v2', 2, 'v2', 3, 'v3', 4, 'v4' );  // int(2)
-     * $redis->zRem('z', 'v2', 'v3');                           // int(2)
-     * var_dump( $redis->zRange('z', 0, -1) );
-     * //// Output:
-     * // array(2) {
-     * //   [0]=> string(2) "v1"
-     * //   [1]=> string(2) "v4"
-     * // }
-     * 
+ * @param string $key 集合键名 + * @param string $member 成员值 * @return int */ - public function zRem() + public function zRem(string $key, string $member): int { + } /** * - * + *通过匹配模式来订阅这些匹配的消息频道 * @example + *
+     * function psubscribe($redis, $pattern, $chan, $msg) {
+     * echo "Pattern: $pattern\n";
+     * echo "Channel: $chan\n";
+     * echo "Payload: $msg\n";
+     * }
+     * 
+ * @param array $patterns 匹配模式 + * @param string|array $callback 回调函数名称 + * @param mixed $value 返回值 * @return */ - public function pSubscribe() + public function pSubscribe(Array $patterns, string $callback, $value) { + } /** * - *Subscribe to channels. Warning: this function will probably change in the future. + *订阅消息 * @example *
      * function f($redis, $chan, $msg) {
@@ -2316,15 +2760,19 @@ public function pSubscribe()
      * }
      * $redis->subscribe(array('chan-1', 'chan-2', 'chan-3'), 'f'); // subscribe to 3 chans
      * 
+ * @param array $channels 订阅的消息频道 + * @param string|array $callback 回调函数名称 + * @param mixed $value 返回值 * @return mixed */ - public function subscribe() + public function subscribe(Array $channels, string $callback, $value) { + } /** * - *Enter and exit transactional mode. + *开始一个事务. * @example *
      * $ret = $redis->multi()
@@ -2339,20 +2787,97 @@ public function subscribe()
      * //    2 => TRUE,
      * //    3 => 'val2');
      * 
- * @return Once + * @return */ public function multi() { + } /** * - * + *执行事务 * @example * @return */ public function exec() { + + } + + /** + * + *执行lua脚本 + * @example + * @param string $script 脚本 + * @param array $args 脚本参数 + * @param int $num_keys 应该进入KEYS数组的参数个数 + * @return mixed + */ + public function eval(string $script, Array $args, int $num_keys) + { + + } + + /** + * + *从脚本的SHA1散列而不是脚本本身执行LUA脚本 + * @example $script = 'return 1'; + * $sha = $redis->script('load', $script); + * $redis->evalSha($sha); // Returns 1 + * @param string $script_sha 脚本的散列值 + * @param array $args 脚本参数 + * @param int $num_keys 应该进入KEYS数组的参数个数 + * @return + */ + public function evalSha(string $script_sha, Array $args, int $num_keys) + { + + } + + /** + * + *在脚本子系统上执行redis命令 + * @example + *
+     * $redis->script('load', $script);
+     * $redis->script('flush');
+     * $redis->script('kill');
+     * $redis->script('exists', $script1, [$script2, $script3, ...]);
+     * 
+ * SCRIPT LOAD will return the SHA1 hash of the passed script on success, and FALSE on failure. + * SCRIPT FLUSH should always return TRUE + * SCRIPT KILL will return true if a script was able to be killed and false if not + * SCRIPT EXISTS will return an array with TRUE or FALSE for each passed script + * @param string $command redis命令 + * @param string|... $script 脚本 + * @return + */ + public function script(string $command, string $script) + { + + } + + /** + * + *序列化函数调用的魔术方法(在PHP进行序列化时,serialize() 检查类中是否有 __sleep() ,如果有,则该函数将在任何序列化之前运行。该函数必须返回一个需要进行序列化保存的成员属性数组,并且只序列化该函数返回的这些成员属性. 该函数有两个作用: 第一. 在序列化之前,关闭对象可能具有的任何数据库连接等. 第二. 指定对象中需要被序列化的成员属性,如果某个属性比较大而不需要储存下来,可以不把它写进__sleep要返回的数组中,这样该属性就不会被序列化) + * @example + * @return + */ + public function __sleep() + { + + } + + /** + * + *反序列化函数调用的魔术方法(unserialize() 从字节流中创建了一个对象之后,马上检查是否具有__wakeup 的函数的存在。如果存在,__wakeup 立刻被调用。使用 __wakeup 的目的是重建在序列化中可能丢失的任何数据库连接以及处理其它重新初始化的任务) + * @example + * @return + */ + public function __wakeup() + { + } } diff --git a/src/Swoole/Coroutine/Socket.php b/src/Swoole/Coroutine/Socket.php new file mode 100644 index 0000000..68e9946 --- /dev/null +++ b/src/Swoole/Coroutine/Socket.php @@ -0,0 +1,183 @@ +finish()方法将任务处理的结果发送给worker进程。 + * @access public + */ + public $onFinish; + + /** + * @var callable $onManagerStart + * 当管理进程启动时调用它 + * @access public + */ + public $onManagerStart; + + /** + * @var callable $onManagerStop + * 当管理进程结束时调用它 + * @access public + */ + public $onManagerStop; + + /** + * @var callable $onPipeMessage + * 当工作进程收到由 sendMessage 发送的管道消息时会触发onPipeMessage事件 + * @access public + */ + public $onPipeMessage; + + /** + * @var iterator $connections + * TCP连接迭代器 + * @access public + */ + public $connections; + + /** + * @var string $host + * 连接的主机 + * @access public + */ + public $host; + + /** + * @var int $port + * 连接的主机的端口 + * @access public + */ + public $port = 0; + + /** + * @var int $type + * socket的类型 + * @access public + */ + public $type = 0; + + /** + * @var int $mode + * 运行模式(swoole提供了3种运行模式,默认为SWOOLE_PROCESS多进程模式) + * @access public + */ + public $mode = 0; + + /** + * @var array $ports + * 当监听多端口时的端口列表 + * @access public */ - private $global = 0; + public $ports = array(); + + /** + * @var int $master_pid + * 主进程ID + * @access public + */ + public $master_pid = 0; + + /** + * @var int $manager_pid + * 管理进程ID + * @access public + */ + public $manager_pid = 0; + + /** + * @var int $worker_id + * 当前工作进程(包括worker进程和task进程)编号 + * @access public + */ + public $worker_id = -1; + + /** + * @var boolean $taskworker + * 当前进程是否是task工作进程 + * @access public + */ + public $taskworker = ''; + + /** + * @var int $worker_pid + * 当前工作进程ID(操作系统进程) + * @access public + */ + public $worker_pid = 0; + + /** + * @var callable $onRequest + * 请求回调函数 + * @access public + */ + public $onRequest; + + /** + * @var callable $onHandshake + * TCP握手时的回调函数 + * @access public + */ + public $onHandshake; + + /** + * @var array $setting + * 通过swoole_server:set()设置的参数会保存到setting属性上 + * @access public + */ + public $setting = array(); /** * - *注册Server的事件回调函数 + *绑定事件(为事件注册函数) * @example - * @param string $event_name 注册Server的事件回调函数 - * @param callable $callback 注册Server的事件回调函数 - * @return bool + * @param string $event_name 事件名称 + * @param callable $callback 事件对应的回调函数 + * @return */ - public function on($event_name, Callable $callback) + public function on(string $event_name, Callable $callback) { + } /** * - *启动server,监听所有TCP/UDP端口 + *启动HTTP server * @example - * @return bool + * @return */ public function start() { + + } + + /** + * + *序列化函数调用的魔术方法(在PHP进行序列化时,serialize() 检查类中是否有 __sleep() ,如果有,则该函数将在任何序列化之前运行。该函数必须返回一个需要进行序列化保存的成员属性数组,并且只序列化该函数返回的这些成员属性. 该函数有两个作用: 第一. 在序列化之前,关闭对象可能具有的任何数据库连接等. 第二. 指定对象中需要被序列化的成员属性,如果某个属性比较大而不需要储存下来,可以不把它写进__sleep要返回的数组中,这样该属性就不会被序列化) + * @example + * @return + */ + public function __sleep() + { + } /** * - *创建一个swoole http server对象 + *反序列化函数调用的魔术方法(unserialize() 从字节流中创建了一个对象之后,马上检查是否具有__wakeup 的函数的存在。如果存在,__wakeup 立刻被调用。使用 __wakeup 的目的是重建在序列化中可能丢失的任何数据库连接以及处理其它重新初始化的任务) * @example - * @param string $host 创建一个swoole http server对象 - * @param int $port 创建一个swoole http server对象 - * @param int $mode 创建一个swoole http server对象 - * @param int $sock_type 创建一个swoole http server对象 * @return */ - public function __construct($host, $port, $mode, $sock_type) + public function __wakeup() { + } /** * - *监听一个新的Server端口,此方法是addlistener的别名 + *swoole_server初始化方法 * @example - * @param string $host 监听一个新的Server端口,此方法是addlistener的别名 - * @param int $port 监听一个新的Server端口,此方法是addlistener的别名 - * @param int $sock_type 监听一个新的Server端口,此方法是addlistener的别名 + * @param string $host 主机IP + * @param int $port 端口 + * @param int $mode 运行模式 + * @param int $sock_type socket类型 * @return */ - public function listen($host, $port, $sock_type) + public function __construct(string $host, int $port, int $mode, int $sock_type) { + } /** * - *监听一个新的Server端口,此方法是addlistener的别名 + *析构函数 * @example - * @param string $host 监听一个新的Server端口,此方法是addlistener的别名 - * @param int $port 监听一个新的Server端口,此方法是addlistener的别名 - * @param int $sock_type 监听一个新的Server端口,此方法是addlistener的别名 * @return */ - public function addlistener($host, $port, $sock_type) + public function __destruct() { + } /** * - *设置选项 + *添加监听端口(是addlistener的别名) * @example - * @param array $settings 设置选项 + * @param string $host 监听的主机 + * @param int $port 监听的端口号 + * @param int $sock_type socket类型 + * @return + */ + public function listen(string $host, int $port, int $sock_type) + { + + } + + /** + * + *添加监听端口 + * @example + * @param string $host 监听的主机 + * @param int $port 监听的端口号 + * @param int $sock_type socket类型 + * @return + */ + public function addlistener(string $host, int $port, int $sock_type) + { + + } + + /** + * + *设置swoole_server运行时的参数 + * @example + * @param array $settings 配置选项 * @return */ public function set(Array $settings) { + } /** * *向客户端发送数据 * @example - * @param int $fd 向客户端发送数据 - * @param string $send_data 向客户端发送数据 - * @param int $reactor_id 向客户端发送数据 - * @return bool + * @param int $fd 连接句柄 + * @param string $send_data 发送的数据 + * @param int $reactor_id UDP服务器使用$fd保存客户端IP,$extraData保存server_fd和port + * @return */ - public function send($fd, $send_data, $reactor_id) + public function send(int $fd, string $send_data, int $reactor_id) { + } /** * - *向任意的客户端IP:PORT发送UDP数据包 + *向任意客户端发送UDP数据包 * @example - * @param string $ip 向任意的客户端IP:PORT发送UDP数据包 - * @param int $port 向任意的客户端IP:PORT发送UDP数据包 - * @param string $send_data 向任意的客户端IP:PORT发送UDP数据包 - * @param int $server_socket 向任意的客户端IP:PORT发送UDP数据包 - * @return bool + * @param string $ip IPv4字符串,如192.168.1.102。如果IP不合法会返回错误 + * @param int $port 为 1-65535的网络端口号,如果端口错误发送会失败 + * @param string $send_data 发送的数据内容,可以是文本或者二进制内容 + * @param int $server_socket 服务器可能会同时监听多个UDP端口,此参数可以指定使用哪个端口发送数据包 + * @return */ - public function sendto($ip, $port, $send_data, $server_socket) + public function sendto(string $ip, int $port, string $send_data, int $server_socket) { + } /** * - *阻塞地向客户端发送数据 + *阻塞的向客户端发送数据 * @example - * @param int $conn_fd 阻塞地向客户端发送数据 - * @param string $send_data 阻塞地向客户端发送数据 - * @return bool + * @param int $conn_fd 与客户端连接的句柄 + * @param string $send_data 发送的数据 + * @return */ - public function sendwait($conn_fd, $send_data) + public function sendwait(int $conn_fd, string $send_data) { + } /** * *检测fd对应的连接是否存在 * @example - * @param int $fd 检测fd对应的连接是否存在 - * @return bool + * @param int $fd 连接句柄 + * @return */ - public function exist($fd) + public function exist(int $fd) { + } /** * - *用于保护某些连接不被心跳线程切断 + *设置客户端连接为保护状态,不被心跳线程切断 * @example - * @param int $fd 用于保护某些连接不被心跳线程切断 - * @param bool $is_protected 用于保护某些连接不被心跳线程切断 + * @param int $fd 要设置保护状态的客户端连接fd + * @param boolean $is_protected 设置的状态,true表示保护状态,false表示不保护 * @return */ - public function protect($fd, $is_protected) + public function protect(int $fd, bool $is_protected) { + } /** * - *发送文件到TCP客户端连接 + *向客户端发送文件 * @example - * @param int $conn_fd 发送文件到TCP客户端连接 - * @param string $filename 发送文件到TCP客户端连接 - * @param int $offset 发送文件到TCP客户端连接 - * @return bool + * @param int $conn_fd 连接句柄 + * @param string $filename 文件名 + * @param int $offset 指定文件偏移量,可以从文件的某个位置起发送数据。默认为0,表示从文件头部开始发送 + * @param int $length 指定发送的长度,默认为文件尺寸 + * @return */ - public function sendfile($conn_fd, $filename, $offset) + public function sendfile(int $conn_fd, string $filename, int $offset, int $length) { + } /** * *关闭客户端连接 * @example - * @param int $fd 关闭客户端连接 - * @param bool $reset 关闭客户端连接 + * @param int $fd 连接句柄 + * @param boolean $reset 设置为true会强制关闭连接,丢弃发送队列中的数据 * @return */ - public function close($fd, $reset) + public function close(int $fd, bool $reset) { + } /** * - *连接确认 + *确认连接,与enable_delay_receive或wait_for_bind配合使用 * @example - * @param int $fd 连接确认 + * @param int $fd 连接句柄 * @return */ - public function confirm($fd) + public function confirm(int $fd) { + } /** * *停止接收数据 * @example - * @param int $fd 停止接收数据 + * @param int $fd 连接句柄 * @return */ - public function pause($fd) + public function pause(int $fd) { + } /** * - *恢复数据接收 + *恢复数据接收。与pause方法成对使用 * @example - * @param int $fd 恢复数据接收 + * @param int $fd 连接句柄 * @return */ - public function resume($fd) + public function resume(int $fd) { + } /** * - *投递一个异步任务到task_worker池中。此函数是非阻塞的,执行完毕会立即返回 + *投递一个任务到task_worker连接池中 * @example - * @param mixed $data 投递一个异步任务到task_worker池中。此函数是非阻塞的,执行完毕会立即返回 - * @param int $worker_id 投递一个异步任务到task_worker池中。此函数是非阻塞的,执行完毕会立即返回 - * @param callable $finish_callback 投递一个异步任务到task_worker池中。此函数是非阻塞的,执行完毕会立即返回 + * @param mixed $data 要投递的任务数据,可以为除资源类型之外的任意PHP变量 + * @param int $worker_id 可以制定要给投递给哪个task进程,传入ID即可 + * @param callable $finish_callback 完成后的回调函数 * @return */ - public function task($data, $worker_id, Callable $finish_callback) + public function task($data, int $worker_id, Callable $finish_callback) { + } /** * - *用于投递一个异步的任务到task进程池去执行。与task不同的是taskwait是阻塞等待的,直到任务完成或者超时返回。 + *以阻塞的形式投递一个任务到task_worker连接池中 * @example - * @param mixed $data 用于投递一个异步的任务到task进程池去执行。与task不同的是taskwait是阻塞等待的,直到任务完成或者超时返回。 - * @param float $timeout 用于投递一个异步的任务到task进程池去执行。与task不同的是taskwait是阻塞等待的,直到任务完成或者超时返回。 - * @param int $worker_id 用于投递一个异步的任务到task进程池去执行。与task不同的是taskwait是阻塞等待的,直到任务完成或者超时返回。 + * @param mixed $data 要投递的任务数据,可以为除资源类型之外的任意PHP变量 + * @param float $timeout 超时时间 + * @param int $worker_id 可以制定要给投递给哪个task进程,传入ID即可 * @return */ - public function taskwait($data, $timeout, $worker_id) + public function taskwait($data, float $timeout, int $worker_id) { + } /** * *并发执行多个Task * @example - * @param array $tasks 并发执行多个Task - * @param double $timeout 并发执行多个Task + * @param array $tasks 必须为数字索引数组,不支持关联索引数组,底层会遍历$tasks将任务逐个投递到Task进程 + * @param double $timeout 超时时间 * @return */ - public function taskWaitMulti(Array $tasks, $timeout) + public function taskWaitMulti(Array $tasks, double $timeout) + { + + } + + /** + * + *并发执行Task并进行协程调度 + * @example + * @param array $tasks 必须为数字索引数组,不支持关联索引数组,底层会遍历$tasks将任务逐个投递到Task进程 + * @param double $timeout 超时时间 + * @return array + */ + public function taskCo(Array $tasks, double $timeout): array { + } /** * - *此函数用于在task进程中通知worker进程,投递的任务已完成。此函数可以传递结果数据给worker进程 + *用于在task进程中通知worker进程任务已完成 * @example - * @param string $data 此函数用于在task进程中通知worker进程,投递的任务已完成。此函数可以传递结果数据给worker进程 + * @param mixed $data * @return */ public function finish($data) { + } /** * - *重启所有worker进程 + *重启所有工作进程 * @example * @return */ public function reload() { + } /** @@ -278,178 +556,197 @@ public function reload() */ public function shutdown() { + } /** * - *使当前worker进程停止运行,并立即触发onWorkerStop回调函数 + *停止当前worker进程 * @example - * @param int $worker_id 使当前worker进程停止运行,并立即触发onWorkerStop回调函数 + * @param int $worker_id 工作进程ID * @return */ - public function stop($worker_id) + public function stop(int $worker_id) { + } /** * - *获取最近一次操作错误的错误码。业务代码中可以根据错误码类型执行不同的逻辑。 + *获取最近一次操作错误的错误码 + *返回的错误码: + *1001 连接已经被Server端关闭了,出现这个错误一般是代码中已经执行了$serv->close()关闭了某个连接,但仍然调用$serv->send()向这个连接发送数据 * @example - * @return int + * @return */ public function getLastError() { + } /** * - *检测服务器所有连接,并找出已经超过约定时间的连接。如果指定if_close_connection,则自动关闭超时的连接。未指定仅返回连接的fd数组。 + *检测所有服务器连接,并找出已经超时的连接 * @example - * @param mixed $reactor_id + * @param boolean $reactor_id 是否关闭超时的连接,默认为true * @return */ - public function heartbeat($reactor_id) + public function heartbeat(bool $reactor_id) { + } /** * - *获取连接的信息 + *获取客户端连接信息 * @example - * @param int $fd 获取连接的信息 - * @param int $reactor_id 获取连接的信息 - * @return + * @param mixed $fd 连接句柄 + * @param int $reactor_id reactor线程id + * @return from_id */ - public function connection_info($fd, $reactor_id) + public function connection_info($fd, int $reactor_id): from_id { + } /** * - *用来遍历当前Server所有的客户端连接 + *用来遍历所有客户端连接 * @example - * @param int $start_fd 用来遍历当前Server所有的客户端连接 - * @param int $find_count 用来遍历当前Server所有的客户端连接 + * @param int $start_fd 起始fd + * @param int $find_count 每页取多少条 * @return */ - public function connection_list($start_fd, $find_count) + public function connection_list(int $start_fd, int $find_count) { + } /** * - *获取连接的信息 + *获取连接的信息,别名是swoole_server->connection_info * @example - * @param int $fd 获取连接的信息 - * @param int $reactor_id 获取连接的信息 + * @param mixed $fd 连接句柄 + * @param int $reactor_id reactor线程id * @return */ - public function getClientInfo($fd, $reactor_id) + public function getClientInfo($fd, int $reactor_id) { + } /** * - *用来遍历当前Server所有的客户端连接 + *用来遍历所有客户端连接(server->connection_list的别名) * @example - * @param int $start_fd 用来遍历当前Server所有的客户端连接 - * @param int $find_count 用来遍历当前Server所有的客户端连接 + * @param int $start_fd 起始fd + * @param int $find_count 每页取多少条 * @return */ - public function getClientList($start_fd, $find_count) + public function getClientList(int $start_fd, int $find_count) { + } /** * - *在指定的时间后执行函数 + *在指定时间后执行某个回调函数 * @example - * @param int $ms 在指定的时间后执行函数 - * @param callable $callback 在指定的时间后执行函数 - * @param array $param 在指定的时间后执行函数 + * @param int $ms 指定时间,单位为毫秒 + * @param callable $callback 回调函数 + * @param array $param 给回调函数传入的参数 * @return */ - public function after($ms, Callable $callback, Array $param) + public function after(int $ms, Callable $callback, Array $param) { + } /** * - *ick定时器,可以自定义回调函数 + *添加定时器 * @example - * @param int $ms ick定时器,可以自定义回调函数 - * @param callable $callback ick定时器,可以自定义回调函数 + * @param int $ms 指定时间,单位为毫秒 + * @param callable $callback 回调函数 * @return */ - public function tick($ms, Callable $callback) + public function tick(int $ms, Callable $callback) { + } /** * - *清除tick/after定时器,此函数是swoole_timer_clear的别名 + *清除定时器 * @example - * @param int $timer_id 清除tick/after定时器,此函数是swoole_timer_clear的别名 + * @param int $timer_id 定时器ID * @return */ - public function clearTimer($timer_id) + public function clearTimer(int $timer_id) { + } /** * - *延后执行一个PHP函数。Swoole底层会在EventLoop循环完成后执行此函数。此函数的目的是为了让一些PHP代码延后执行,程序优先处理IO事件 + *延迟执行一个PHP函数 * @example - * @param callable $callback 延后执行一个PHP函数。Swoole底层会在EventLoop循环完成后执行此函数。此函数的目的是为了让一些PHP代码延后执行,程序优先处理IO事件 + * @param callable $callback 执行的函数 * @return */ public function defer(Callable $callback) { + } /** * - *此函数可以向任意worker进程或者task进程发送消息。在非主进程和管理进程中可调用。收到消息的进程会触发onPipeMessage事件。 + *向任意worker进程或task进程发送消息 * @example - * @param int $dst_worker_id 此函数可以向任意worker进程或者task进程发送消息。在非主进程和管理进程中可调用。收到消息的进程会触发onPipeMessage事件。 - * @param string $data 此函数可以向任意worker进程或者task进程发送消息。在非主进程和管理进程中可调用。收到消息的进程会触发onPipeMessage事件。 + * @param int $dst_worker_id 目标worker的ID + * @param string $data 发送的消息 * @return */ - public function sendMessage($dst_worker_id, $data) + public function sendMessage(int $dst_worker_id, string $data) { + } /** * - *添加一个用户自定义的工作进程 + *添加一个自定义的工作进程 * @example - * @param object $process 添加一个用户自定义的工作进程 + * @param Swoole\Process $process 进程对象 * @return */ - public function addProcess($process) + public function addProcess(Swoole\Process $process) { + } /** * - *得到当前Server的活动TCP连接数,启动时间,accpet/close的总次数等信息 + *得到当前server的活动TCP连接数 + *array ( * @example - * @return array + * @return */ public function stats() { + } /** * - *将连接绑定一个用户定义的ID,可以设置dispatch_mode=5设置已此ID值进行hash固定分配。可以保证某一个UID的连接全部会分配到同一个Worker进程 + *将连接绑定到某个用户定义的ID * @example - * @param int $fd 将连接绑定一个用户定义的ID,可以设置dispatch_mode=5设置已此ID值进行hash固定分配。可以保证某一个UID的连接全部会分配到同一个Worker进程 - * @param int $uid 将连接绑定一个用户定义的ID,可以设置dispatch_mode=5设置已此ID值进行hash固定分配。可以保证某一个UID的连接全部会分配到同一个Worker进程 + * @param int $fd 连接句柄 + * @param int $uid 用户定义的ID * @return */ - public function bind($fd, $uid) + public function bind(int $fd, int $uid) { + } } diff --git a/src/Swoole/Http2/Client.php b/src/Swoole/Http2/Client.php new file mode 100644 index 0000000..ad85300 --- /dev/null +++ b/src/Swoole/Http2/Client.php @@ -0,0 +1,553 @@ +lock一致,但lockwait可以设置超时时间 + * @example + * @param float $timeout 超时时间 + * @return + */ + public function lockwait(float $timeout) + { + } /** * - *加锁操作。与lock方法不同的是,trylock()不会阻塞,它会立即返回。当返回false时表示抢锁失败,有其他进程持有锁。返回true时表示加锁成功,此时可以修改共享变量。 + *非阻塞的加锁操作 * @example * @return */ public function trylock() { + } /** * - *加锁。lock_read方法仅可用在读写锁(SWOOLE_RWLOCK)和文件锁(SWOOLE_FILELOCK)中,表示仅仅锁定读。在持有读锁的过程中,其他进程依然可以获得读锁,可以继续发生读操作。但不能$lock->lock()或$lock->trylock(),这两个方法是获取独占锁的 + *锁定读 * @example * @return */ public function lock_read() { + } /** * - *加锁。此方法与lock_read相同,但是非阻塞的。调用会立即返回,必须检测返回值以确定是否拿到了锁 + *非阻塞式锁定读 * @example * @return */ public function trylock_read() { + } /** * - *释放锁 + *释放锁操作 * @example * @return */ public function unlock() { + } } diff --git a/src/Swoole/Memory/Pool.php b/src/Swoole/Memory/Pool.php new file mode 100644 index 0000000..a5ec5ac --- /dev/null +++ b/src/Swoole/Memory/Pool.php @@ -0,0 +1,78 @@ + '192.168.56.102', * 'user' => 'test', - * 'password' => 'test', - * 'database' => 'test', - * 'charset' => 'utf8', + * 'password' => 'test', + * 'database' => 'test', + * 'charset' => 'utf8', * ); - * $db->connect($server, function($db, $result){ - * if (!$result) { - * echo 'connect failed'; - * } - * }) - * @param array $server_config 异步连接到MySQL服务器 - * @param callable $callback 异步连接到MySQL服务器 + * 回调函数:function onConnect(swoole_mysql $db, bool $result); + * @param array $server_config 连接配置信息 + * @param callable $callback 连接成功的回调 * @return */ public function connect(Array $server_config, Callable $callback) { + + } + + /** + * + *启动事务 + * @example + * @param callable $callback 启动一个MySQL事务,事务启动成功会回调指定的函数 + * @return + */ + public function begin(Callable $callback) + { + + } + + /** + * + *提交事务 + * @example + * @param callable $callback 提交事务,当服务器返回响应时回调此函数 + * @return + */ + public function commit(Callable $callback) + { + + } + + /** + * + *回滚事务(必须先调用begin启动事务才能调用rollback否则底层会抛出异常) + * @example + * @param callable $callback 回滚完成后执行的回调 + * @return + */ + public function rollback(Callable $callback) + { + } /** * - *执行SQL查询 - * @example $db->query('select * from user', function($link, $result){ - * var_dump($result); - * }) - * @param string $sql 执行SQL查询 - * @param callable $callback 执行SQL查询 + *执行sql语句 + * @example + * 回调函数:function onSQLReady(swoole_mysqli $link, mixed $result); + * 注:执行失败,$result为false,读取$link对象的error属性获得错误信息,errno属性获得错误码 + * 执行成功,SQL为非查询语句,$result为true,读取$link对象的affected_rows属性获得影响的行数,insert_id属性获得Insert操作的自增ID + * 执行成功,SQL为查询语句,$result为结果数组 + * @param string $sql 要执行的SQL语句 + * @param callable $callback 执行成功后会回调此函数 * @return */ - public function query($sql, Callable $callback) + public function query(string $sql, Callable $callback) { + } /** * - *关闭MySQL连接 + *关闭mysql连接 * @example * @return */ public function close() { + + } + + /** + * + *获取当前服务器状态 + * @example + * @return int + */ + public function getState(): int + { + } /** * - *设置事件回调函数。目前仅支持onClose事件回调 + *设置事件回调函数(目前仅支持onClose事件回调) * @example - * @param string $event_name 设置事件回调函数。目前仅支持onClose事件回调 - * @param callable $callback 设置事件回调函数。目前仅支持onClose事件回调 + * @param String $event_name 事件名称(目前仅支持Close) + * @param callable $callback 连接关闭时回调此函数 * @return */ - public function on($event_name, Callable $callback) + public function on(String $event_name, Callable $callback) { + } } diff --git a/src/Swoole/MySQL/Exception.php b/src/Swoole/MySQL/Exception.php index 6e1c603..70661c1 100644 --- a/src/Swoole/MySQL/Exception.php +++ b/src/Swoole/MySQL/Exception.php @@ -1,19 +1,19 @@ on("Message", function ($pool, $message) {echo "Message: {$message} + * "; + * $pool->write("hello "); + * $pool->write("world "); + * $pool->write("\n"); + * }); + * $pool->listen('127.0.0.1', 8089); + * $pool->start(); + * + * @param string $data 写入的数据内容。可多次调用write,底层会在onMessage函数退出后将数据全部写入socket中,并close连接 + * @return + */ + public function write(string $data) + { + + } + + /** + * + *启动工作进程 + * @example + * @return bool + */ + public function start(): bool + { + + } + + /** + * + *获取当前工作进程对象 + * @example $workerNum = 10; + * $pool = new Swoole\Process\Pool($workerNum); + * $pool->on("WorkerStart", function ($pool, $workerId) { + * $process = $pool->getProcess(); + * $process->exec("/bin/sh", ["ls", '-l']); + * }); + * @return \Swoole\Process + */ + public function getProcess() + { + + } + +} + diff --git a/src/Swoole/Redis.php b/src/Swoole/Redis.php index 8043190..92a7d2a 100644 --- a/src/Swoole/Redis.php +++ b/src/Swoole/Redis.php @@ -1,24 +1,114 @@ finish()方法将任务处理的结果发送给worker进程。 + * @access public + */ + public $onFinish; + + /** + * @var callable $onManagerStart + * 当管理进程启动时调用它 + * @access public + */ + public $onManagerStart; + + /** + * @var callable $onManagerStop + * 当管理进程结束时调用它 + * @access public + */ + public $onManagerStop; + + /** + * @var callable $onPipeMessage + * 当工作进程收到由 sendMessage 发送的管道消息时会触发onPipeMessage事件 + * @access public + */ + public $onPipeMessage; + + /** + * @var array $setting + * 通过swoole_server:set()设置的参数会保存到setting属性上 + * @access public + */ + public $setting = array(); + + /** + * @var iterator $connections + * TCP连接迭代器 + * @access public + */ + public $connections; + + /** + * @var string $host + * 连接的主机 + * @access public + */ + public $host; + + /** + * @var int $port + * 连接的主机的端口 + * @access public + */ + public $port = 0; + + /** + * @var int $type + * socket的类型 + * @access public + */ + public $type = 0; + + /** + * @var int $mode + * 运行模式(swoole提供了3种运行模式,默认为SWOOLE_PROCESS多进程模式) + * @access public + */ + public $mode = 0; + + /** + * @var array $ports + * 当监听多端口时的端口列表 + * @access public + */ + public $ports = array(); + + /** + * @var int $master_pid + * 主进程ID + * @access public + */ + public $master_pid = 0; + + /** + * @var int $manager_pid + * 管理进程ID + * @access public + */ + public $manager_pid = 0; + + /** + * @var int $worker_id + * 当前工作进程(包括worker进程和task进程)编号 + * @access public + */ + public $worker_id = -1; + + /** + * @var boolean $taskworker + * 当前进程是否是task工作进程 + * @access public + */ + public $taskworker = ''; + + /** + * @var int $worker_pid + * 当前工作进程ID(操作系统进程) + * @access public + */ + public $worker_pid = 0; + /** * - *启动server,监听所有TCP/UDP端口 + *启动server * @example - * @return bool + * @return */ public function start() { + } /** * *设置Redis命令字的处理器 * @example - * @param string $command 设置Redis命令字的处理器 - * @param callable $callback 设置Redis命令字的处理器 - * @param mixed $number_of_string_param - * @param mixed $type_of_array_param + * @param string $command 命令的名称 + * @param callable $callback 命令的处理函数,回调函数返回字符串类型时会自动发送给客户端 + * @param int $number_of_string_param 字符串参数的长度 + * @param int $type_of_array_param 数组参数元素的类型 * @return */ - public function setHandler($command, Callable $callback, $number_of_string_param, $type_of_array_param) + public function setHandler(string $command, Callable $callback, int $number_of_string_param, int $type_of_array_param) { + } /** * *格式化命令响应数据 * @example - * @param int $type 格式化命令响应数据 - * @param mixed $value 格式化命令响应数据 + * @param int $type 表示数据类型,NIL类型不需要传入$value,ERROR和STATUS类型$value可选,INT、STRING、SET、MAP必选 + * @param mixed $value 要处理的数据 + * @return + */ + public static function format(int $type, $value) + { + + } + + /** + * + *swoole_server初始化方法 + * @example + * @param string $host 主机IP + * @param int $port 端口 + * @param int $mode 运行模式 + * @param int $sock_type socket类型 * @return */ - public static function format($type, $value) + public function __construct(string $host, int $port, int $mode, int $sock_type) { + } /** * - *创建一个swoole tcp/udp server对象 + *析构函数 * @example - * @param string $host 创建一个swoole tcp/udp server对象 - * @param int $port 创建一个swoole tcp/udp server对象 - * @param int $mode 创建一个swoole tcp/udp server对象 - * @param int $sock_type 创建一个swoole tcp/udp server对象 * @return */ - public function __construct($host, $port, $mode, $sock_type) + public function __destruct() { + } /** * - *监听一个新的Server端口,此方法是addlistener的别名 + *添加监听端口(是addlistener的别名) * @example - * @param string $host 监听一个新的Server端口,此方法是addlistener的别名 - * @param int $port 监听一个新的Server端口,此方法是addlistener的别名 - * @param int $sock_type 监听一个新的Server端口,此方法是addlistener的别名 + * @param string $host 监听的主机 + * @param int $port 监听的端口号 + * @param int $sock_type socket类型 * @return */ - public function listen($host, $port, $sock_type) + public function listen(string $host, int $port, int $sock_type) { + } /** * - *监听一个新的Server端口,此方法是addlistener的别名 + *添加监听端口 * @example - * @param string $host 监听一个新的Server端口,此方法是addlistener的别名 - * @param int $port 监听一个新的Server端口,此方法是addlistener的别名 - * @param int $sock_type 监听一个新的Server端口,此方法是addlistener的别名 + * @param string $host 监听的主机 + * @param int $port 监听的端口号 + * @param int $sock_type socket类型 * @return */ - public function addlistener($host, $port, $sock_type) + public function addlistener(string $host, int $port, int $sock_type) { + } /** * - *注册Server的事件回调函数 + *绑定事件(为事件注册函数) * @example - * @param string $event_name 注册Server的事件回调函数 - * @param callable $callback 注册Server的事件回调函数 - * @return bool + * @param string $event_name 事件名称 + * @param callable $callback 事件对应的回调函数 + * @return */ - public function on($event_name, Callable $callback) + public function on(string $event_name, Callable $callback) { + } /** * - *设置选项 + *设置swoole_server运行时的参数 * @example - * @param array $settings 设置选项 + * @param array $settings 配置选项 * @return */ public function set(Array $settings) { + } /** * *向客户端发送数据 * @example - * @param int $fd 向客户端发送数据 - * @param string $send_data 向客户端发送数据 - * @param int $reactor_id 向客户端发送数据 - * @return bool + * @param int $fd 连接句柄 + * @param string $send_data 发送的数据 + * @param int $reactor_id UDP服务器使用$fd保存客户端IP,$extraData保存server_fd和port + * @return */ - public function send($fd, $send_data, $reactor_id) + public function send(int $fd, string $send_data, int $reactor_id) { + } /** * - *向任意的客户端IP:PORT发送UDP数据包 + *向任意客户端发送UDP数据包 * @example - * @param string $ip 向任意的客户端IP:PORT发送UDP数据包 - * @param int $port 向任意的客户端IP:PORT发送UDP数据包 - * @param string $send_data 向任意的客户端IP:PORT发送UDP数据包 - * @param int $server_socket 向任意的客户端IP:PORT发送UDP数据包 - * @return bool + * @param string $ip IPv4字符串,如192.168.1.102。如果IP不合法会返回错误 + * @param int $port 为 1-65535的网络端口号,如果端口错误发送会失败 + * @param string $send_data 发送的数据内容,可以是文本或者二进制内容 + * @param int $server_socket 服务器可能会同时监听多个UDP端口,此参数可以指定使用哪个端口发送数据包 + * @return */ - public function sendto($ip, $port, $send_data, $server_socket) + public function sendto(string $ip, int $port, string $send_data, int $server_socket) { + } /** * - *阻塞地向客户端发送数据 + *阻塞的向客户端发送数据 * @example - * @param int $conn_fd 阻塞地向客户端发送数据 - * @param string $send_data 阻塞地向客户端发送数据 - * @return bool + * @param int $conn_fd 与客户端连接的句柄 + * @param string $send_data 发送的数据 + * @return */ - public function sendwait($conn_fd, $send_data) + public function sendwait(int $conn_fd, string $send_data) { + } /** * *检测fd对应的连接是否存在 * @example - * @param int $fd 检测fd对应的连接是否存在 - * @return bool + * @param int $fd 连接句柄 + * @return */ - public function exist($fd) + public function exist(int $fd) { + } /** * - *用于保护某些连接不被心跳线程切断 + *设置客户端连接为保护状态,不被心跳线程切断 * @example - * @param int $fd 用于保护某些连接不被心跳线程切断 - * @param bool $is_protected 用于保护某些连接不被心跳线程切断 + * @param int $fd 要设置保护状态的客户端连接fd + * @param boolean $is_protected 设置的状态,true表示保护状态,false表示不保护 * @return */ - public function protect($fd, $is_protected) + public function protect(int $fd, bool $is_protected) { + } /** * - *发送文件到TCP客户端连接 + *向客户端发送文件 * @example - * @param int $conn_fd 发送文件到TCP客户端连接 - * @param string $filename 发送文件到TCP客户端连接 - * @param int $offset 发送文件到TCP客户端连接 - * @return bool + * @param int $conn_fd 连接句柄 + * @param string $filename 文件名 + * @param int $offset 指定文件偏移量,可以从文件的某个位置起发送数据。默认为0,表示从文件头部开始发送 + * @param int $length 指定发送的长度,默认为文件尺寸 + * @return */ - public function sendfile($conn_fd, $filename, $offset) + public function sendfile(int $conn_fd, string $filename, int $offset, int $length) { + } /** * *关闭客户端连接 * @example - * @param int $fd 关闭客户端连接 - * @param bool $reset 关闭客户端连接 + * @param int $fd 连接句柄 + * @param boolean $reset 设置为true会强制关闭连接,丢弃发送队列中的数据 * @return */ - public function close($fd, $reset) + public function close(int $fd, bool $reset) { + } /** * - *连接确认 + *确认连接,与enable_delay_receive或wait_for_bind配合使用 * @example - * @param int $fd 连接确认 + * @param int $fd 连接句柄 * @return */ - public function confirm($fd) + public function confirm(int $fd) { + } /** * *停止接收数据 * @example - * @param int $fd 停止接收数据 + * @param int $fd 连接句柄 * @return */ - public function pause($fd) + public function pause(int $fd) { + } /** * - *恢复数据接收 + *恢复数据接收。与pause方法成对使用 * @example - * @param int $fd 恢复数据接收 + * @param int $fd 连接句柄 * @return */ - public function resume($fd) + public function resume(int $fd) { + } /** * - *投递一个异步任务到task_worker池中。此函数是非阻塞的,执行完毕会立即返回 + *投递一个任务到task_worker连接池中 * @example - * @param mixed $data 投递一个异步任务到task_worker池中。此函数是非阻塞的,执行完毕会立即返回 - * @param int $worker_id 投递一个异步任务到task_worker池中。此函数是非阻塞的,执行完毕会立即返回 - * @param callable $finish_callback 投递一个异步任务到task_worker池中。此函数是非阻塞的,执行完毕会立即返回 + * @param mixed $data 要投递的任务数据,可以为除资源类型之外的任意PHP变量 + * @param int $worker_id 可以制定要给投递给哪个task进程,传入ID即可 + * @param callable $finish_callback 完成后的回调函数 * @return */ - public function task($data, $worker_id, Callable $finish_callback) + public function task($data, int $worker_id, Callable $finish_callback) { + } /** * - *用于投递一个异步的任务到task进程池去执行。与task不同的是taskwait是阻塞等待的,直到任务完成或者超时返回。 + *以阻塞的形式投递一个任务到task_worker连接池中 * @example - * @param mixed $data 用于投递一个异步的任务到task进程池去执行。与task不同的是taskwait是阻塞等待的,直到任务完成或者超时返回。 - * @param float $timeout 用于投递一个异步的任务到task进程池去执行。与task不同的是taskwait是阻塞等待的,直到任务完成或者超时返回。 - * @param int $worker_id 用于投递一个异步的任务到task进程池去执行。与task不同的是taskwait是阻塞等待的,直到任务完成或者超时返回。 + * @param mixed $data 要投递的任务数据,可以为除资源类型之外的任意PHP变量 + * @param float $timeout 超时时间 + * @param int $worker_id 可以制定要给投递给哪个task进程,传入ID即可 * @return */ - public function taskwait($data, $timeout, $worker_id) + public function taskwait($data, float $timeout, int $worker_id) { + } /** * *并发执行多个Task * @example - * @param array $tasks 并发执行多个Task - * @param double $timeout 并发执行多个Task + * @param array $tasks 必须为数字索引数组,不支持关联索引数组,底层会遍历$tasks将任务逐个投递到Task进程 + * @param double $timeout 超时时间 * @return */ - public function taskWaitMulti(Array $tasks, $timeout) + public function taskWaitMulti(Array $tasks, double $timeout) { + } /** * - *此函数用于在task进程中通知worker进程,投递的任务已完成。此函数可以传递结果数据给worker进程 + *并发执行Task并进行协程调度 * @example - * @param string $data 此函数用于在task进程中通知worker进程,投递的任务已完成。此函数可以传递结果数据给worker进程 - * @return + * @param array $tasks 必须为数字索引数组,不支持关联索引数组,底层会遍历$tasks将任务逐个投递到Task进程 + * @param double $timeout 超时时间 + * @return array */ - public function finish($data) + public function taskCo(Array $tasks, double $timeout): array { + } /** * - *重启所有worker进程 + *用于在task进程中通知worker进程任务已完成 * @example + * @param string $data 要传递的数据 * @return */ - public function reload() + public function finish(string $data) + { + + } + + /** + * + *重启所有工作进程 + * @example + * @return boolean + */ + public function reload(): boolean { + } /** @@ -332,178 +583,219 @@ public function reload() */ public function shutdown() { + } /** * - *使当前worker进程停止运行,并立即触发onWorkerStop回调函数 + *停止当前worker进程 * @example - * @param int $worker_id 使当前worker进程停止运行,并立即触发onWorkerStop回调函数 + * @param int $worker_id 进程ID * @return */ - public function stop($worker_id) + public function stop(int $worker_id) { + } /** * - *获取最近一次操作错误的错误码。业务代码中可以根据错误码类型执行不同的逻辑。 + *获取最近一次操作错误的错误码 + *返回的错误码: + *1001 连接已经被Server端关闭了,出现这个错误一般是代码中已经执行了$serv->close()关闭了某个连接,但仍然调用$serv->send()向这个连接发送数据 * @example - * @return int + * @return */ public function getLastError() { + } /** * - *检测服务器所有连接,并找出已经超过约定时间的连接。如果指定if_close_connection,则自动关闭超时的连接。未指定仅返回连接的fd数组。 + *检测所有服务器连接,并找出已经超时的连接 * @example - * @param mixed $reactor_id + * @param boolean $reactor_id 是否关闭超时的连接,默认为true * @return */ - public function heartbeat($reactor_id) + public function heartbeat(bool $reactor_id) { + } /** * - *获取连接的信息 + *获取客户端连接信息 * @example - * @param int $fd 获取连接的信息 - * @param int $reactor_id 获取连接的信息 - * @return + * @param mixed $fd 连接句柄 + * @param int $reactor_id reactor线程id + * @return from_id */ - public function connection_info($fd, $reactor_id) + public function connection_info($fd, int $reactor_id): from_id { + } /** * - *用来遍历当前Server所有的客户端连接 + *用来遍历所有客户端连接 * @example - * @param int $start_fd 用来遍历当前Server所有的客户端连接 - * @param int $find_count 用来遍历当前Server所有的客户端连接 + * @param int $start_fd 起始fd + * @param int $find_count 每页取多少条 * @return */ - public function connection_list($start_fd, $find_count) + public function connection_list(int $start_fd, int $find_count) { + } /** * - *获取连接的信息 + *获取连接的信息,别名是swoole_server->connection_info * @example - * @param int $fd 获取连接的信息 - * @param int $reactor_id 获取连接的信息 + * @param mixed $fd 连接句柄 + * @param int $reactor_id reactor线程id * @return */ - public function getClientInfo($fd, $reactor_id) + public function getClientInfo($fd, int $reactor_id) { + } /** * - *用来遍历当前Server所有的客户端连接 + *用来遍历所有客户端连接(server->connection_list的别名) * @example - * @param int $start_fd 用来遍历当前Server所有的客户端连接 - * @param int $find_count 用来遍历当前Server所有的客户端连接 + * @param int $start_fd 起始fd + * @param int $find_count 每页取多少条 * @return */ - public function getClientList($start_fd, $find_count) + public function getClientList(int $start_fd, int $find_count) { + } /** * - *在指定的时间后执行函数 + *在指定时间后执行某个回调函数 * @example - * @param int $ms 在指定的时间后执行函数 - * @param callable $callback 在指定的时间后执行函数 - * @param array $param 在指定的时间后执行函数 + * @param int $ms 指定时间,单位为毫秒 + * @param callable $callback 回调函数 + * @param array $param 给回调函数传入的参数 * @return */ - public function after($ms, Callable $callback, Array $param) + public function after(int $ms, Callable $callback, Array $param) { + } /** * - *tick定时器,可以自定义回调函数 + *添加定时器 * @example - * @param int $ms tick定时器,可以自定义回调函数 - * @param callable $callback tick定时器,可以自定义回调函数 + * @param int $ms 指定时间,单位为毫秒 + * @param callable $callback 回调函数 * @return */ - public function tick($ms, Callable $callback) + public function tick(int $ms, Callable $callback) { + } /** * - *清除tick/after定时器,此函数是swoole_timer_clear的别名 + *清除定时器 * @example - * @param int $timer_id 清除tick/after定时器,此函数是swoole_timer_clear的别名 + * @param int $timer_id 定时器ID * @return */ - public function clearTimer($timer_id) + public function clearTimer(int $timer_id) { + } /** * - *延后执行一个PHP函数。Swoole底层会在EventLoop循环完成后执行此函数。此函数的目的是为了让一些PHP代码延后执行,程序优先处理IO事件 + *延迟执行一个PHP函数 * @example - * @param callable $callback 延后执行一个PHP函数。Swoole底层会在EventLoop循环完成后执行此函数。此函数的目的是为了让一些PHP代码延后执行,程序优先处理IO事件 + * @param callable $callback 执行的函数 * @return */ public function defer(Callable $callback) { + } /** * - *此函数可以向任意worker进程或者task进程发送消息。在非主进程和管理进程中可调用。收到消息的进程会触发onPipeMessage事件。 + *向任意worker进程或task进程发送消息 * @example - * @param int $dst_worker_id 此函数可以向任意worker进程或者task进程发送消息。在非主进程和管理进程中可调用。收到消息的进程会触发onPipeMessage事件。 - * @param string $data 此函数可以向任意worker进程或者task进程发送消息。在非主进程和管理进程中可调用。收到消息的进程会触发onPipeMessage事件。 + * @param int $dst_worker_id 目标worker的ID + * @param string $data 发送的消息 * @return */ - public function sendMessage($dst_worker_id, $data) + public function sendMessage(int $dst_worker_id, string $data) { + } /** * - *添加一个用户自定义的工作进程 + *添加一个自定义的工作进程 * @example - * @param object $process 添加一个用户自定义的工作进程 + * @param Swoole\Process $process 进程对象 * @return */ - public function addProcess($process) + public function addProcess(Swoole\Process $process) { + } /** * - *得到当前Server的活动TCP连接数,启动时间,accpet/close的总次数等信息 + *得到当前server的活动TCP连接数 + *array ( * @example - * @return array + * @return */ public function stats() { + + } + + /** + * + *将连接绑定到某个用户定义的ID + * @example + * @param int $fd 连接句柄 + * @param int $uid 用户定义的ID + * @return + */ + public function bind(int $fd, int $uid) + { + + } + + /** + * + *序列化函数调用的魔术方法(在PHP进行序列化时,serialize() 检查类中是否有 __sleep() ,如果有,则该函数将在任何序列化之前运行。该函数必须返回一个需要进行序列化保存的成员属性数组,并且只序列化该函数返回的这些成员属性. 该函数有两个作用: 第一. 在序列化之前,关闭对象可能具有的任何数据库连接等. 第二. 指定对象中需要被序列化的成员属性,如果某个属性比较大而不需要储存下来,可以不把它写进__sleep要返回的数组中,这样该属性就不会被序列化) + * @example + * @return + */ + public function __sleep() + { + } /** * - *将连接绑定一个用户定义的ID,可以设置dispatch_mode=5设置已此ID值进行hash固定分配。可以保证某一个UID的连接全部会分配到同一个Worker进程 + *反序列化函数调用的魔术方法(unserialize() 从字节流中创建了一个对象之后,马上检查是否具有__wakeup 的函数的存在。如果存在,__wakeup 立刻被调用。使用 __wakeup 的目的是重建在序列化中可能丢失的任何数据库连接以及处理其它重新初始化的任务) * @example - * @param int $fd 将连接绑定一个用户定义的ID,可以设置dispatch_mode=5设置已此ID值进行hash固定分配。可以保证某一个UID的连接全部会分配到同一个Worker进程 - * @param int $uid 将连接绑定一个用户定义的ID,可以设置dispatch_mode=5设置已此ID值进行hash固定分配。可以保证某一个UID的连接全部会分配到同一个Worker进程 * @return */ - public function bind($fd, $uid) + public function __wakeup() { + } } diff --git a/src/Swoole/RingQueue.php b/src/Swoole/RingQueue.php new file mode 100644 index 0000000..79e7ad7 --- /dev/null +++ b/src/Swoole/RingQueue.php @@ -0,0 +1,72 @@ +finish()方法将任务处理的结果发送给worker进程。 + * @access public + */ + public $onFinish; + + /** + * @var callable $onManagerStart + * 当管理进程启动时调用它 + * @access public + */ + public $onManagerStart; + + /** + * @var callable $onManagerStop + * 当管理进程结束时调用它 + * @access public + */ + public $onManagerStop; + + /** + * @var callable $onPipeMessage + * 当工作进程收到由 sendMessage 发送的管道消息时会触发onPipeMessage事件 + * @access public + */ + public $onPipeMessage; + /** * @var array $setting - * 参数设置数组 + * 通过swoole_server:set()设置的参数会保存到setting属性上 + * @access public + */ + public $setting = array(); + + /** + * @var iterator $connections + * TCP连接迭代器 + * @access public + */ + public $connections; + + /** + * @var string $host + * 连接的主机 + * @access public + */ + public $host; + + /** + * @var int $port + * 连接的主机的端口 * @access public */ - public $setting; + public $port = 0; + + /** + * @var int $type + * socket的类型 + * @access public + */ + public $type = 0; + + /** + * @var int $mode + * 运行模式(swoole提供了3种运行模式,默认为SWOOLE_PROCESS多进程模式) + * @access public + */ + public $mode = 0; + + /** + * @var array $ports + * 当监听多端口时的端口列表 + * @access public + */ + public $ports = array(); /** * @var int $master_pid - * 返回当前服务器主进程的PID + * 主进程ID * @access public */ public $master_pid = 0; /** * @var int $manager_pid - * 返回当前服务器管理进程的PID + * 管理进程ID * @access public */ public $manager_pid = 0; /** * @var int $worker_id - * 得到当前Worker进程的编号,包括Task进程 + * 当前工作进程(包括worker进程和task进程)编号 * @access public */ - public $worker_id = 0; + public $worker_id = -1; /** - * @var int $worker_pid - * 得到当前Worker进程的操作系统进程ID。与posix_getpid()的返回值相同 + * @var boolean $taskworker + * 当前进程是否是task工作进程 * @access public */ - public $worker_pid = 0; + public $taskworker = ''; /** - * @var bool $taskworker - * 是否为任务进程(true表示当前的进程是Task工作进程;false表示当前的进程是Worker进程) + * @var int $worker_pid + * 当前工作进程ID(操作系统进程) * @access public */ - public $taskworker = 0; + public $worker_pid = 0; /** - * @var array $connections - * TCP连接迭代器,可以使用foreach遍历服务器当前所有的连接,此属性的功能与swoole_server->connnection_list是一致的,但是更加友好。遍历的元素为单个连接的fd - * @access public + * + *swoole_server初始化方法 + * @example + * @param string $host 主机IP + * @param int $port 端口 + * @param int $mode 运行模式 + * @param int $sock_type socket类型 + * @return */ - public $connections; + public function __construct(string $host, int $port, int $mode, int $sock_type) + { + + } /** * - *创建一个swoole tcp/udp server对象 + *析构函数 * @example - * @param string $host 创建一个swoole tcp/udp server对象 - * @param int $port 创建一个swoole tcp/udp server对象 - * @param int $mode 创建一个swoole tcp/udp server对象 - * @param int $sock_type 创建一个swoole tcp/udp server对象 * @return */ - public function __construct($host, $port, $mode, $sock_type) + public function __destruct() { + } /** * - *监听一个新的Server端口,此方法是addlistener的别名 + *添加监听端口(是addlistener的别名) * @example - * @param string $host 监听一个新的Server端口,此方法是addlistener的别名 - * @param int $port 监听一个新的Server端口,此方法是addlistener的别名 - * @param int $sock_type 监听一个新的Server端口,此方法是addlistener的别名 + * @param string $host 监听的主机 + * @param int $port 监听的端口号 + * @param int $sock_type socket类型 * @return */ - public function listen($host, $port, $sock_type) + public function listen(string $host, int $port, int $sock_type) { + } /** * - *监听一个新的Server端口,此方法是addlistener的别名 + *添加监听端口 * @example - * @param string $host 监听一个新的Server端口,此方法是addlistener的别名 - * @param int $port 监听一个新的Server端口,此方法是addlistener的别名 - * @param int $sock_type 监听一个新的Server端口,此方法是addlistener的别名 + * @param string $host 监听的主机 + * @param int $port 监听的端口号 + * @param int $sock_type socket类型 * @return */ - public function addlistener($host, $port, $sock_type) + public function addlistener(string $host, int $port, int $sock_type) { + } /** * - *注册Server的事件回调函数 + *绑定事件(为事件注册函数) * @example - * @param string $event_name 注册Server的事件回调函数 - * @param callable $callback 注册Server的事件回调函数 - * @return bool + * @param string $event_name 事件名称 + * @param callable $callback 事件对应的回调函数 + * @return */ - public function on($event_name, Callable $callback) + public function on(string $event_name, Callable $callback) { + } /** * - *设置选项 + *设置swoole_server运行时的参数 * @example - * @param array $settings 设置选项 + * @param array $settings 配置选项 * @return */ public function set(Array $settings) { + } /** * - *启动server,监听所有TCP/UDP端口 + *启动server * @example - * @return bool + * @return */ public function start() { + } /** * *向客户端发送数据 * @example - * @param int $fd 向客户端发送数据 - * @param string $send_data 向客户端发送数据 - * @param int $reactor_id 向客户端发送数据 - * @return bool + * @param int $fd 连接句柄 + * @param string $send_data 发送的数据 + * @param int $reactor_id UDP服务器使用$fd保存客户端IP,$extraData保存server_fd和port + * @return */ - public function send($fd, $send_data, $reactor_id) + public function send(int $fd, string $send_data, int $reactor_id) { + } /** * - *向任意的客户端IP:PORT发送UDP数据包 + *向任意客户端发送UDP数据包 * @example - * @param string $ip 向任意的客户端IP:PORT发送UDP数据包 - * @param int $port 向任意的客户端IP:PORT发送UDP数据包 - * @param string $send_data 向任意的客户端IP:PORT发送UDP数据包 - * @param int $server_socket 向任意的客户端IP:PORT发送UDP数据包 - * @return bool + * @param string $ip IPv4字符串,如192.168.1.102。如果IP不合法会返回错误 + * @param int $port 为 1-65535的网络端口号,如果端口错误发送会失败 + * @param string $send_data 发送的数据内容,可以是文本或者二进制内容 + * @param int $server_socket 服务器可能会同时监听多个UDP端口,此参数可以指定使用哪个端口发送数据包 + * @return */ - public function sendto($ip, $port, $send_data, $server_socket) + public function sendto(string $ip, int $port, string $send_data, int $server_socket) { + } /** * - *阻塞地向客户端发送数据 + *阻塞的向客户端发送数据 * @example - * @param int $conn_fd 阻塞地向客户端发送数据 - * @param string $send_data 阻塞地向客户端发送数据 - * @return bool + * @param int $conn_fd 与客户端连接的句柄 + * @param string $send_data 发送的数据 + * @return */ - public function sendwait($conn_fd, $send_data) + public function sendwait(int $conn_fd, string $send_data) { + } /** * *检测fd对应的连接是否存在 * @example - * @param int $fd 检测fd对应的连接是否存在 - * @return bool + * @param int $fd 连接句柄 + * @return */ - public function exist($fd) + public function exist(int $fd) { + } /** * - *用于保护某些连接不被心跳线程切断 + *设置客户端连接为保护状态,不被心跳线程切断 * @example - * @param int $fd 用于保护某些连接不被心跳线程切断 - * @param bool $is_protected 用于保护某些连接不被心跳线程切断 + * @param int $fd 要设置保护状态的客户端连接fd + * @param boolean $is_protected 设置的状态,true表示保护状态,false表示不保护 * @return */ - public function protect($fd, $is_protected) + public function protect(int $fd, bool $is_protected) { + } /** * - *发送文件到TCP客户端连接 + *向客户端发送文件 * @example - * @param int $conn_fd 发送文件到TCP客户端连接 - * @param string $filename 发送文件到TCP客户端连接 - * @param int $offset 发送文件到TCP客户端连接 - * @return bool + * @param int $conn_fd 连接句柄 + * @param string $filename 文件名 + * @param int $offset 指定文件偏移量,可以从文件的某个位置起发送数据。默认为0,表示从文件头部开始发送 + * @param int $length 指定发送的长度,默认为文件尺寸 + * @return */ - public function sendfile($conn_fd, $filename, $offset) + public function sendfile(int $conn_fd, string $filename, int $offset, int $length) { + } /** * *关闭客户端连接 * @example - * @param int $fd 关闭客户端连接 - * @param bool $reset 关闭客户端连接 + * @param int $fd 连接句柄 + * @param boolean $reset 设置为true会强制关闭连接,丢弃发送队列中的数据 * @return */ - public function close($fd, $reset) + public function close(int $fd, bool $reset) { + } /** * - *连接确认 + *确认连接,与enable_delay_receive或wait_for_bind配合使用 * @example - * @param int $fd 连接确认 + * @param int $fd 连接句柄 * @return */ - public function confirm($fd) + public function confirm(int $fd) { + } /** * *停止接收数据 * @example - * @param int $fd 停止接收数据 + * @param int $fd 连接句柄 * @return */ - public function pause($fd) + public function pause(int $fd) { + } /** * - *恢复数据接收 + *恢复数据接收。与pause方法成对使用 * @example - * @param int $fd 恢复数据接收 + * @param int $fd 连接句柄 * @return */ - public function resume($fd) + public function resume(int $fd) { + } /** * - *投递一个异步任务到task_worker池中。此函数是非阻塞的,执行完毕会立即返回 + *投递一个任务到task_worker连接池中 * @example - * @param mixed $data 投递一个异步任务到task_worker池中。此函数是非阻塞的,执行完毕会立即返回 - * @param int $worker_id 投递一个异步任务到task_worker池中。此函数是非阻塞的,执行完毕会立即返回 - * @param callable $finish_callback 投递一个异步任务到task_worker池中。此函数是非阻塞的,执行完毕会立即返回 + * @param mixed $data 要投递的任务数据,可以为除资源类型之外的任意PHP变量 + * @param int $worker_id 可以制定要给投递给哪个task进程,传入ID即可 + * @param callable $finish_callback 完成后的回调函数 * @return */ - public function task($data, $worker_id, Callable $finish_callback) + public function task($data, int $worker_id, Callable $finish_callback) { + } /** * - *用于投递一个异步的任务到task进程池去执行。与task不同的是taskwait是阻塞等待的,直到任务完成或者超时返回。 + *以阻塞的形式投递一个任务到task_worker连接池中 * @example - * @param mixed $data 用于投递一个异步的任务到task进程池去执行。与task不同的是taskwait是阻塞等待的,直到任务完成或者超时返回。 - * @param float $timeout 用于投递一个异步的任务到task进程池去执行。与task不同的是taskwait是阻塞等待的,直到任务完成或者超时返回。 - * @param int $worker_id 用于投递一个异步的任务到task进程池去执行。与task不同的是taskwait是阻塞等待的,直到任务完成或者超时返回。 + * @param mixed $data 要投递的任务数据,可以为除资源类型之外的任意PHP变量 + * @param float $timeout 超时时间 + * @param int $worker_id 可以制定要给投递给哪个task进程,传入ID即可 * @return */ - public function taskwait($data, $timeout, $worker_id) + public function taskwait($data, float $timeout, int $worker_id) { + } /** * *并发执行多个Task * @example - * @param array $tasks 并发执行多个Task - * @param double $timeout 并发执行多个Task + * @param array $tasks 必须为数字索引数组,不支持关联索引数组,底层会遍历$tasks将任务逐个投递到Task进程 + * @param double $timeout 超时时间 * @return */ - public function taskWaitMulti(Array $tasks, $timeout) + public function taskWaitMulti(Array $tasks, double $timeout) { + } /** * - *此函数用于在task进程中通知worker进程,投递的任务已完成。此函数可以传递结果数据给worker进程 + *并发执行Task并进行协程调度 * @example - * @param string $data 此函数用于在task进程中通知worker进程,投递的任务已完成。此函数可以传递结果数据给worker进程 - * @return + * @param array $tasks 必须为数字索引数组,不支持关联索引数组,底层会遍历$tasks将任务逐个投递到Task进程 + * @param double $timeout 超时时间 + * @return array */ - public function finish($data) + public function taskCo(Array $tasks, double $timeout): array { + } /** * - *重启所有worker进程 + *用于在task进程中通知worker进程任务已完成 * @example + * @param string $data 要传递的数据 * @return */ - public function reload() + public function finish(string $data) + { + + } + + /** + * + *重启所有工作进程 + * @example + * @return boolean + */ + public function reload(): boolean { + } /** @@ -320,178 +520,219 @@ public function reload() */ public function shutdown() { + } /** * - *使当前worker进程停止运行,并立即触发onWorkerStop回调函数 + *停止当前worker进程 * @example - * @param int $worker_id 使当前worker进程停止运行,并立即触发onWorkerStop回调函数 + * @param int $worker_id 进程ID * @return */ - public function stop($worker_id) + public function stop(int $worker_id) { + } /** * - *获取最近一次操作错误的错误码。业务代码中可以根据错误码类型执行不同的逻辑。 + *获取最近一次操作错误的错误码 + *返回的错误码: + *1001 连接已经被Server端关闭了,出现这个错误一般是代码中已经执行了$serv->close()关闭了某个连接,但仍然调用$serv->send()向这个连接发送数据 * @example - * @return int + * @return */ public function getLastError() { + } /** * - *检测服务器所有连接,并找出已经超过约定时间的连接。如果指定if_close_connection,则自动关闭超时的连接。未指定仅返回连接的fd数组。 + *检测所有服务器连接,并找出已经超时的连接 * @example - * @param mixed $reactor_id + * @param boolean $reactor_id 是否关闭超时的连接,默认为true * @return */ - public function heartbeat($reactor_id) + public function heartbeat(bool $reactor_id) { + } /** * - *获取连接的信息 + *获取客户端连接信息 * @example - * @param int $fd 获取连接的信息 - * @param int $reactor_id 获取连接的信息 - * @return + * @param mixed $fd 连接句柄 + * @param int $reactor_id reactor线程id + * @return from_id */ - public function connection_info($fd, $reactor_id) + public function connection_info($fd, int $reactor_id): from_id { + } /** * - *用来遍历当前Server所有的客户端连接 + *用来遍历所有客户端连接 * @example - * @param int $start_fd 用来遍历当前Server所有的客户端连接 - * @param int $find_count 用来遍历当前Server所有的客户端连接 + * @param int $start_fd 起始fd + * @param int $find_count 每页取多少条 * @return */ - public function connection_list($start_fd, $find_count) + public function connection_list(int $start_fd, int $find_count) { + } /** * - *获取连接的信息 + *获取连接的信息,别名是swoole_server->connection_info * @example - * @param int $fd 获取连接的信息 - * @param int $reactor_id 获取连接的信息 + * @param mixed $fd 连接句柄 + * @param int $reactor_id reactor线程id * @return */ - public function getClientInfo($fd, $reactor_id) + public function getClientInfo($fd, int $reactor_id) { + } /** * - *用来遍历当前Server所有的客户端连接 + *用来遍历所有客户端连接(server->connection_list的别名) * @example - * @param int $start_fd 用来遍历当前Server所有的客户端连接 - * @param int $find_count 用来遍历当前Server所有的客户端连接 + * @param int $start_fd 起始fd + * @param int $find_count 每页取多少条 * @return */ - public function getClientList($start_fd, $find_count) + public function getClientList(int $start_fd, int $find_count) { + } /** * - *在指定的时间后执行函数 + *在指定时间后执行某个回调函数 * @example - * @param int $ms 在指定的时间后执行函数 - * @param callable $callback 在指定的时间后执行函数 - * @param array $param 在指定的时间后执行函数 + * @param int $ms 指定时间,单位为毫秒 + * @param callable $callback 回调函数 + * @param array $param 给回调函数传入的参数 * @return */ - public function after($ms, Callable $callback, Array $param) + public function after(int $ms, Callable $callback, Array $param) { + } /** * - *tick定时器,可以自定义回调函数 + *添加定时器 * @example - * @param int $ms tick定时器,可以自定义回调函数 - * @param callable $callback tick定时器,可以自定义回调函数 + * @param int $ms 指定时间,单位为毫秒 + * @param callable $callback 回调函数 * @return */ - public function tick($ms, Callable $callback) + public function tick(int $ms, Callable $callback) { + } /** * - *清除tick/after定时器,此函数是swoole_timer_clear的别名 + *清除定时器 * @example - * @param int $timer_id 清除tick/after定时器,此函数是swoole_timer_clear的别名 + * @param int $timer_id 定时器ID * @return */ - public function clearTimer($timer_id) + public function clearTimer(int $timer_id) { + } /** * - *延后执行一个PHP函数。Swoole底层会在EventLoop循环完成后执行此函数。此函数的目的是为了让一些PHP代码延后执行,程序优先处理IO事件 + *延迟执行一个PHP函数 * @example - * @param callable $callback 延后执行一个PHP函数。Swoole底层会在EventLoop循环完成后执行此函数。此函数的目的是为了让一些PHP代码延后执行,程序优先处理IO事件 + * @param callable $callback 执行的函数 * @return */ public function defer(Callable $callback) { + } /** * - *此函数可以向任意worker进程或者task进程发送消息。在非主进程和管理进程中可调用。收到消息的进程会触发onPipeMessage事件。 + *向任意worker进程或task进程发送消息 * @example - * @param int $dst_worker_id 此函数可以向任意worker进程或者task进程发送消息。在非主进程和管理进程中可调用。收到消息的进程会触发onPipeMessage事件。 - * @param string $data 此函数可以向任意worker进程或者task进程发送消息。在非主进程和管理进程中可调用。收到消息的进程会触发onPipeMessage事件。 + * @param int $dst_worker_id 目标worker的ID + * @param string $data 发送的消息 * @return */ - public function sendMessage($dst_worker_id, $data) + public function sendMessage(int $dst_worker_id, string $data) { + } /** * - *添加一个用户自定义的工作进程 + *添加一个自定义的工作进程 * @example - * @param object $process 添加一个用户自定义的工作进程 + * @param Swoole\Process $process 进程对象 * @return */ - public function addProcess($process) + public function addProcess(Swoole\Process $process) { + } /** * - *得到当前Server的活动TCP连接数,启动时间,accpet/close的总次数等信息 + *得到当前server的活动TCP连接数 + *array ( * @example - * @return array + * @return */ public function stats() { + + } + + /** + * + *将连接绑定到某个用户定义的ID + * @example + * @param int $fd 连接句柄 + * @param int $uid 用户定义的ID + * @return + */ + public function bind(int $fd, int $uid) + { + + } + + /** + * + *序列化函数调用的魔术方法(在PHP进行序列化时,serialize() 检查类中是否有 __sleep() ,如果有,则该函数将在任何序列化之前运行。该函数必须返回一个需要进行序列化保存的成员属性数组,并且只序列化该函数返回的这些成员属性. 该函数有两个作用: 第一. 在序列化之前,关闭对象可能具有的任何数据库连接等. 第二. 指定对象中需要被序列化的成员属性,如果某个属性比较大而不需要储存下来,可以不把它写进__sleep要返回的数组中,这样该属性就不会被序列化) + * @example + * @return + */ + public function __sleep() + { + } /** * - *将连接绑定一个用户定义的ID,可以设置dispatch_mode=5设置已此ID值进行hash固定分配。可以保证某一个UID的连接全部会分配到同一个Worker进程 + *反序列化函数调用的魔术方法(unserialize() 从字节流中创建了一个对象之后,马上检查是否具有__wakeup 的函数的存在。如果存在,__wakeup 立刻被调用。使用 __wakeup 的目的是重建在序列化中可能丢失的任何数据库连接以及处理其它重新初始化的任务) * @example - * @param int $fd 将连接绑定一个用户定义的ID,可以设置dispatch_mode=5设置已此ID值进行hash固定分配。可以保证某一个UID的连接全部会分配到同一个Worker进程 - * @param int $uid 将连接绑定一个用户定义的ID,可以设置dispatch_mode=5设置已此ID值进行hash固定分配。可以保证某一个UID的连接全部会分配到同一个Worker进程 * @return */ - public function bind($fd, $uid) + public function __wakeup() { + } } diff --git a/src/Swoole/Server/Port.php b/src/Swoole/Server/Port.php index 926defb..22c8d74 100644 --- a/src/Swoole/Server/Port.php +++ b/src/Swoole/Server/Port.php @@ -1,16 +1,128 @@ column('id', swoole_table::TYPE_INT, 4); //1,2,4,8 - * $table->column('name', swoole_table::TYPE_STRING, 64); - * $table->column('num', swoole_table::TYPE_FLOAT); - * $table->create(); + *创建内存表(在使用column创建内存表结构时执行) + * @example * @return */ public function create() { + } /** @@ -72,137 +72,233 @@ public function create() */ public function destroy() { + } /** * - *设置行的数据,swoole_table使用key-value的方式来访问数据。 - * @example - * @param string $key 设置行的数据,swoole_table使用key-value的方式来访问数据。 - * @param array $value 设置行的数据,swoole_table使用key-value的方式来访问数据。 + *设置行的数据 + * @example $table->set('hello@qq.com', array('id' => 189, 'name' => 'rango3', 'num' => 3.1415)); + * @param string $key 数据的key,相同的$key对应同一行数据,如果set同一个key,会覆盖上一次的数据 + * @param array $value 必须是一个数组,必须与字段定义的$name完全相同 * @return */ - public function set($key, Array $value) + public function set(string $key, Array $value) { + } /** * *获取一行数据 * @example - * @param string $key 获取一行数据 - * @return array + * @param string $key 设置的key值 + * @param string $field 字段值 + * @return */ - public function get($key) + public function get(string $key, string $field) { + } /** * - *获取键的数量 + *获取数据行数 * @example * @return int */ - public function count() + public function count(): int { + } /** * - *删除指定key的值 + *删除数据 * @example - * @param string $key 删除指定key的值 - * @return boolean + * @param string $key 要删除的键 + * @return */ - public function del($key) + public function del(string $key) { + } /** * *检查table中是否存在某一个key * @example - * @param string $key 检查table中是否存在某一个key - * @return boolean + * @param mixed $key + * @return */ public function exist($key) { + } /** * *原子自增操作 * @example - * @param string $key 原子自增操作 - * @param number $column 原子自增操作 - * @param mixed $incrby 原子自增操作 + * @param string $key 指定数据的key,如果$key对应的行不存在,默认列的值为0 + * @param string $column 指定列名,仅支持浮点型和整型字段 + * @param mixed $incrby 增量,默认为1。如果列为整形,$incrby必须为int型,如果列为浮点型,$incrby必须为float类型失败返回false,成功返回最终的结果数值 * @return */ - public function incr($key, $column, $incrby) + public function incr(string $key, string $column, $incrby) { + } /** * *原子自减操作 * @example - * @param string $key 原子自减操作 - * @param number $column 原子自减操作 - * @param mixed $decrby 原子自减操作 + * @param string $key 指定数据的key,如果$key对应的行不存在,默认列的值为0 + * @param string $column 指定列名,仅支持浮点型和整型字段 + * @param mixed $decrby 减量,默认为1。如果列为整形,$decrby必须为int型,如果列为浮点型,$decrby必须为float类型失败返回false,成功返回最终的结果数值 + * @return + */ + public function decr(string $key, string $column, $decrby) + { + + } + + /** + * + *获取table占用的内存大小 + * @example + * @return int + */ + public function getMemorySize(): int + { + + } + + /** + * + *检查一个偏移位置是否存在 + * @example + * @param int $offset 偏移量 + * @return + */ + public function offsetExists(int $offset) + { + + } + + /** + * + *取一个偏移位置的值 + * @example + * @param int $offset 偏移量 * @return */ - public function decr($key, $column, $decrby) + public function offsetGet(int $offset) { + + } + + /** + * + *设置一个偏移位置的值(来自ArrayAccess接口) + * @example + * @param int $offset 偏移量 + * @param mixed $value 需要设置的值 + * @return + */ + public function offsetSet(int $offset, $value) + { + + } + + /** + * + *复位一个偏移位置的值 + * @example + * @param int $offset 偏移量 + * @return + */ + public function offsetUnset(int $offset) + { + + } + + /** + * + *序列化函数调用的魔术方法(在PHP进行序列化时,serialize() 检查类中是否有 __sleep() ,如果有,则该函数将在任何序列化之前运行。该函数必须返回一个需要进行序列化保存的成员属性数组,并且只序列化该函数返回的这些成员属性. 该函数有两个作用: 第一. 在序列化之前,关闭对象可能具有的任何数据库连接等. 第二. 指定对象中需要被序列化的成员属性,如果某个属性比较大而不需要储存下来,可以不把它写进__sleep要返回的数组中,这样该属性就不会被序列化) + * @example + * @return + */ + public function __sleep() + { + + } + + /** + * + *反序列化函数调用的魔术方法(unserialize() 从字节流中创建了一个对象之后,马上检查是否具有__wakeup 的函数的存在。如果存在,__wakeup 立刻被调用。使用 __wakeup 的目的是重建在序列化中可能丢失的任何数据库连接以及处理其它重新初始化的任务) + * @example + * @return + */ + public function __wakeup() + { + } /** * *返回到迭代器的第一个元素 * @example - * @return void + * @return */ public function rewind() { + } /** * - *向前移动到下一个元素 + *向前移动到下一个元素(此方法在 foreach 循环之后被调用) * @example - * @return void + * @return */ public function next() { + } /** * - *返回当前元素 + *返回迭代器当前元素 * @example - * @return mixed + * @return */ public function current() { + } /** * *返回当前元素的键 * @example - * @return scalar + * @return mixed */ public function key() { + } /** * - *此方法在 rewind() 和 next() 方法之后被调用以此用来检查当前位置是否有效 + *检查当前位置是否有效(迭代器方法,此方法在 Iterator::rewind() 和 Iterator::next() 方法之后被调用以此用来检查当前位置是否有效) * @example * @return boolean */ - public function valid() + public function valid(): boolean { + } } diff --git a/src/Swoole/Table/Row.php b/src/Swoole/Table/Row.php new file mode 100644 index 0000000..6e1d519 --- /dev/null +++ b/src/Swoole/Table/Row.php @@ -0,0 +1,89 @@ +finish()方法将任务处理的结果发送给worker进程。 + * @access public + */ + public $onFinish; + + /** + * @var callable $onManagerStart + * 当管理进程启动时调用它 + * @access public + */ + public $onManagerStart; + + /** + * @var callable $onManagerStop + * 当管理进程结束时调用它 + * @access public + */ + public $onManagerStop; + + /** + * @var callable $onPipeMessage + * 当工作进程收到由 sendMessage 发送的管道消息时会触发onPipeMessage事件 + * @access public + */ + public $onPipeMessage; + + /** + * @var iterator $connections + * TCP连接迭代器 + * @access public + */ + public $connections; + + /** + * @var string $host + * 连接的主机 + * @access public + */ + public $host; + + /** + * @var int $port + * 连接的主机的端口 + * @access public + */ + public $port = 0; + + /** + * @var int $type + * socket的类型 + * @access public + */ + public $type = 0; + + /** + * @var int $mode + * 运行模式(swoole提供了3种运行模式,默认为SWOOLE_PROCESS多进程模式) + * @access public + */ + public $mode = 0; + + /** + * @var array $ports + * 当监听多端口时的端口列表 + * @access public + */ + public $ports = array(); + + /** + * @var int $master_pid + * 主进程ID + * @access public + */ + public $master_pid = 0; + + /** + * @var int $manager_pid + * 管理进程ID + * @access public + */ + public $manager_pid = 0; + + /** + * @var int $worker_id + * 当前工作进程(包括worker进程和task进程)编号 + * @access public + */ + public $worker_id = -1; + + /** + * @var boolean $taskworker + * 当前进程是否是task工作进程 + * @access public + */ + public $taskworker = ''; + + /** + * @var int $worker_pid + * 当前工作进程ID(操作系统进程) + * @access public + */ + public $worker_pid = 0; + + /** + * @var callable $onRequest + * 请求回调函数 + * @access public + */ + public $onRequest; + + /** + * @var callable $onHandshake + * TCP握手时的回调函数 + * @access public + */ + public $onHandshake; + + /** + * @var array $setting + * 通过swoole_server:set()设置的参数会保存到setting属性上 + * @access public + */ + public $setting = array(); + /** * - *为事件绑定某个函数 + *绑定事件(为事件注册函数) * @example - * @param string $event_name 为事件绑定某个函数 - * @param callable $callback 为事件绑定某个函数 + * @param string $event_name 事件名称 + * @param callable $callback 事件对应的回调函数 * @return */ - public function on($event_name, Callable $callback) + public function on(string $event_name, Callable $callback) { + } /** * *向websocket客户端连接推送数据,长度最大不得超过2M * @example - * @param int $fd 向websocket客户端连接推送数据,长度最大不得超过2M - * @param string $data 向websocket客户端连接推送数据,长度最大不得超过2M - * @param int $opcode 向websocket客户端连接推送数据,长度最大不得超过2M - * @param boolean $finish 向websocket客户端连接推送数据,长度最大不得超过2M + * @param int $fd 客户端连接的ID,如果指定的$fd对应的TCP连接并非websocket客户端,将会发送失败 + * @param string $data 要发送的数据内容 + * @param int $opcode 指定发送数据内容的格式,默认为文本。发送二进制内容$opcode参数需要设置 + * @param boolean $finish 帧是否完成 * @return */ - public function push($fd, $data, $opcode, $finish) + public function push(int $fd, string $data, int $opcode, bool $finish) { + } /** * *检测fd对应的连接是否存在 * @example - * @param int $fd 检测fd对应的连接是否存在 - * @return bool + * @param int $fd 连接句柄 + * @return */ - public function exist($fd) + public function exist(int $fd) { + } /** * - *打包websocket数据帧 + *打包数据 * @example - * @param string $data 打包websocket数据帧 - * @param mixed $opcode - * @param mixed $finish - * @param mixed $mask + * @param string $data 消息内容 + * @param int $opcode WebSocket的opcode指令类型,1表示文本,2表示二进制数据,9表示心跳ping + * @param boolean $finish 帧是否完成 + * @param boolean $mask 是否设置掩码 * @return */ - public static function pack($data, $opcode, $finish, $mask) + public static function pack(string $data, int $opcode, bool $finish, bool $mask) { + } /** * - *解包websocket数据帧 + *参数据进行解包 * @example - * @param string $data 解包websocket数据帧 + * @param string $data 解包的数据 * @return */ - public static function unpack($data) + public static function unpack(string $data) { + } /** * - *启动websocket server + *启动server * @example - * @return bool + * @return */ public function start() { + + } + + /** + * + *序列化函数调用的魔术方法(在PHP进行序列化时,serialize() 检查类中是否有 __sleep() ,如果有,则该函数将在任何序列化之前运行。该函数必须返回一个需要进行序列化保存的成员属性数组,并且只序列化该函数返回的这些成员属性. 该函数有两个作用: 第一. 在序列化之前,关闭对象可能具有的任何数据库连接等. 第二. 指定对象中需要被序列化的成员属性,如果某个属性比较大而不需要储存下来,可以不把它写进__sleep要返回的数组中,这样该属性就不会被序列化) + * @example + * @return + */ + public function __sleep() + { + + } + + /** + * + *反序列化函数调用的魔术方法(unserialize() 从字节流中创建了一个对象之后,马上检查是否具有__wakeup 的函数的存在。如果存在,__wakeup 立刻被调用。使用 __wakeup 的目的是重建在序列化中可能丢失的任何数据库连接以及处理其它重新初始化的任务) + * @example + * @return + */ + public function __wakeup() + { + + } + + /** + * + *swoole_server初始化方法 + * @example + * @param string $host 主机IP + * @param int $port 端口 + * @param int $mode 运行模式 + * @param int $sock_type socket类型 + * @return + */ + public function __construct(string $host, int $port, int $mode, int $sock_type) + { + } /** * - *创建一个swoole tcp/udp server对象 + *析构函数 * @example - * @param string $host 创建一个swoole tcp/udp server对象 - * @param int $port 创建一个swoole tcp/udp server对象 - * @param int $mode 创建一个swoole tcp/udp server对象 - * @param int $sock_type 创建一个swoole tcp/udp server对象 * @return */ - public function __construct($host, $port, $mode, $sock_type) + public function __destruct() { + } /** * - *监听一个新的Server端口,此方法是addlistener的别名 + *添加监听端口(是addlistener的别名) * @example - * @param string $host 监听一个新的Server端口,此方法是addlistener的别名 - * @param int $port 监听一个新的Server端口,此方法是addlistener的别名 - * @param int $sock_type 监听一个新的Server端口,此方法是addlistener的别名 + * @param string $host 监听的主机 + * @param int $port 监听的端口号 + * @param int $sock_type socket类型 * @return */ - public function listen($host, $port, $sock_type) + public function listen(string $host, int $port, int $sock_type) { + } /** * - *监听一个新的Server端口,此方法是addlistener的别名 + *添加监听端口 * @example - * @param string $host 监听一个新的Server端口,此方法是addlistener的别名 - * @param int $port 监听一个新的Server端口,此方法是addlistener的别名 - * @param int $sock_type 监听一个新的Server端口,此方法是addlistener的别名 + * @param string $host 监听的主机 + * @param int $port 监听的端口号 + * @param int $sock_type socket类型 * @return */ - public function addlistener($host, $port, $sock_type) + public function addlistener(string $host, int $port, int $sock_type) { + } /** * - *设置选项 + *设置swoole_server运行时的参数 * @example - * @param array $settings 设置选项 + * @param array $settings 配置选项 * @return */ public function set(Array $settings) { + } /** * *向客户端发送数据 * @example - * @param int $fd 向客户端发送数据 - * @param string $send_data 向客户端发送数据 - * @param int $reactor_id 向客户端发送数据 - * @return bool + * @param int $fd 连接句柄 + * @param string $send_data 发送的数据 + * @param int $reactor_id UDP服务器使用$fd保存客户端IP,$extraData保存server_fd和port + * @return */ - public function send($fd, $send_data, $reactor_id) + public function send(int $fd, string $send_data, int $reactor_id) { + } /** * - *向任意的客户端IP:PORT发送UDP数据包 + *向任意客户端发送UDP数据包 * @example - * @param string $ip 向任意的客户端IP:PORT发送UDP数据包 - * @param int $port 向任意的客户端IP:PORT发送UDP数据包 - * @param string $send_data 向任意的客户端IP:PORT发送UDP数据包 - * @param int $server_socket 向任意的客户端IP:PORT发送UDP数据包 - * @return bool + * @param string $ip IPv4字符串,如192.168.1.102。如果IP不合法会返回错误 + * @param int $port 为 1-65535的网络端口号,如果端口错误发送会失败 + * @param string $send_data 发送的数据内容,可以是文本或者二进制内容 + * @param int $server_socket 服务器可能会同时监听多个UDP端口,此参数可以指定使用哪个端口发送数据包 + * @return */ - public function sendto($ip, $port, $send_data, $server_socket) + public function sendto(string $ip, int $port, string $send_data, int $server_socket) { + } /** * - *阻塞地向客户端发送数据 + *阻塞的向客户端发送数据 * @example - * @param int $conn_fd 阻塞地向客户端发送数据 - * @param string $send_data 阻塞地向客户端发送数据 - * @return bool + * @param int $conn_fd 与客户端连接的句柄 + * @param string $send_data 发送的数据 + * @return */ - public function sendwait($conn_fd, $send_data) + public function sendwait(int $conn_fd, string $send_data) { + } /** * - *用于保护某些连接不被心跳线程切断 + *设置客户端连接为保护状态,不被心跳线程切断 * @example - * @param int $fd 用于保护某些连接不被心跳线程切断 - * @param bool $is_protected 用于保护某些连接不被心跳线程切断 + * @param int $fd 要设置保护状态的客户端连接fd + * @param boolean $is_protected 设置的状态,true表示保护状态,false表示不保护 * @return */ - public function protect($fd, $is_protected) + public function protect(int $fd, bool $is_protected) { + } /** * - *发送文件到TCP客户端连接 + *向客户端发送文件 * @example - * @param int $conn_fd 发送文件到TCP客户端连接 - * @param string $filename 发送文件到TCP客户端连接 - * @param int $offset 发送文件到TCP客户端连接 - * @return bool + * @param int $conn_fd 连接句柄 + * @param string $filename 文件名 + * @param int $offset 指定文件偏移量,可以从文件的某个位置起发送数据。默认为0,表示从文件头部开始发送 + * @param int $length 指定发送的长度,默认为文件尺寸 + * @return */ - public function sendfile($conn_fd, $filename, $offset) + public function sendfile(int $conn_fd, string $filename, int $offset, int $length) { + } /** * *关闭客户端连接 * @example - * @param int $fd 关闭客户端连接 - * @param bool $reset 关闭客户端连接 + * @param int $fd 连接句柄 + * @param boolean $reset 设置为true会强制关闭连接,丢弃发送队列中的数据 * @return */ - public function close($fd, $reset) + public function close(int $fd, bool $reset) { + } /** * - *连接确认 + *确认连接,与enable_delay_receive或wait_for_bind配合使用 * @example - * @param int $fd 连接确认 + * @param int $fd 连接句柄 * @return */ - public function confirm($fd) + public function confirm(int $fd) { + } /** * *停止接收数据 * @example - * @param int $fd 停止接收数据 + * @param int $fd 连接句柄 * @return */ - public function pause($fd) + public function pause(int $fd) { + } /** * - *恢复数据接收 + *恢复数据接收。与pause方法成对使用 * @example - * @param int $fd 恢复数据接收 + * @param int $fd 连接句柄 * @return */ - public function resume($fd) + public function resume(int $fd) { + } /** * - *投递一个异步任务到task_worker池中。此函数是非阻塞的,执行完毕会立即返回 + *投递一个任务到task_worker连接池中 * @example - * @param mixed $data 投递一个异步任务到task_worker池中。此函数是非阻塞的,执行完毕会立即返回 - * @param int $worker_id 投递一个异步任务到task_worker池中。此函数是非阻塞的,执行完毕会立即返回 - * @param callable $finish_callback 投递一个异步任务到task_worker池中。此函数是非阻塞的,执行完毕会立即返回 + * @param mixed $data 要投递的任务数据,可以为除资源类型之外的任意PHP变量 + * @param int $worker_id 可以制定要给投递给哪个task进程,传入ID即可 + * @param callable $finish_callback 完成后的回调函数 * @return */ - public function task($data, $worker_id, Callable $finish_callback) + public function task($data, int $worker_id, Callable $finish_callback) { + } /** * - *用于投递一个异步的任务到task进程池去执行。与task不同的是taskwait是阻塞等待的,直到任务完成或者超时返回。 + *以阻塞的形式投递一个任务到task_worker连接池中 * @example - * @param mixed $data 用于投递一个异步的任务到task进程池去执行。与task不同的是taskwait是阻塞等待的,直到任务完成或者超时返回。 - * @param float $timeout 用于投递一个异步的任务到task进程池去执行。与task不同的是taskwait是阻塞等待的,直到任务完成或者超时返回。 - * @param int $worker_id 用于投递一个异步的任务到task进程池去执行。与task不同的是taskwait是阻塞等待的,直到任务完成或者超时返回。 + * @param mixed $data 要投递的任务数据,可以为除资源类型之外的任意PHP变量 + * @param float $timeout 超时时间 + * @param int $worker_id 可以制定要给投递给哪个task进程,传入ID即可 * @return */ - public function taskwait($data, $timeout, $worker_id) + public function taskwait($data, float $timeout, int $worker_id) { + } /** * *并发执行多个Task * @example - * @param array $tasks 并发执行多个Task - * @param double $timeout 并发执行多个Task + * @param array $tasks 必须为数字索引数组,不支持关联索引数组,底层会遍历$tasks将任务逐个投递到Task进程 + * @param double $timeout 超时时间 * @return */ - public function taskWaitMulti(Array $tasks, $timeout) + public function taskWaitMulti(Array $tasks, double $timeout) { + } /** * - *此函数用于在task进程中通知worker进程,投递的任务已完成。此函数可以传递结果数据给worker进程 + *并发执行Task并进行协程调度 * @example - * @param string $data 此函数用于在task进程中通知worker进程,投递的任务已完成。此函数可以传递结果数据给worker进程 - * @return + * @param array $tasks 必须为数字索引数组,不支持关联索引数组,底层会遍历$tasks将任务逐个投递到Task进程 + * @param double $timeout 超时时间 + * @return array */ - public function finish($data) + public function taskCo(Array $tasks, double $timeout): array { + } /** * - *重启所有worker进程 + *用于在task进程中通知worker进程任务已完成 * @example + * @param string $data 要传递的数据 * @return */ - public function reload() + public function finish(string $data) { + + } + + /** + * + *重启所有工作进程 + * @example + * @return boolean + */ + public function reload(): boolean + { + } /** @@ -310,178 +598,197 @@ public function reload() */ public function shutdown() { + } /** * - *使当前worker进程停止运行,并立即触发onWorkerStop回调函数 + *停止当前worker进程 * @example - * @param int $worker_id 使当前worker进程停止运行,并立即触发onWorkerStop回调函数 + * @param int $worker_id 进程ID * @return */ - public function stop($worker_id) + public function stop(int $worker_id) { + } /** * - *获取最近一次操作错误的错误码。业务代码中可以根据错误码类型执行不同的逻辑。 + *获取最近一次操作错误的错误码 + *返回的错误码: + *1001 连接已经被Server端关闭了,出现这个错误一般是代码中已经执行了$serv->close()关闭了某个连接,但仍然调用$serv->send()向这个连接发送数据 * @example - * @return int + * @return */ public function getLastError() { + } /** * - *检测服务器所有连接,并找出已经超过约定时间的连接。如果指定if_close_connection,则自动关闭超时的连接。未指定仅返回连接的fd数组。 + *检测所有服务器连接,并找出已经超时的连接 * @example - * @param mixed $reactor_id + * @param boolean $reactor_id 是否关闭超时的连接,默认为true * @return */ - public function heartbeat($reactor_id) + public function heartbeat(bool $reactor_id) { + } /** * - *获取连接的信息 + *获取客户端连接信息 * @example - * @param int $fd 获取连接的信息 - * @param int $reactor_id 获取连接的信息 - * @return + * @param mixed $fd 连接句柄 + * @param int $reactor_id reactor线程id + * @return from_id */ - public function connection_info($fd, $reactor_id) + public function connection_info($fd, int $reactor_id): from_id { + } /** * - *用来遍历当前Server所有的客户端连接 + *用来遍历所有客户端连接 * @example - * @param int $start_fd 用来遍历当前Server所有的客户端连接 - * @param int $find_count 用来遍历当前Server所有的客户端连接 + * @param int $start_fd 起始fd + * @param int $find_count 每页取多少条 * @return */ - public function connection_list($start_fd, $find_count) + public function connection_list(int $start_fd, int $find_count) { + } /** * - *获取连接的信息 + *获取连接的信息,别名是swoole_server->connection_info * @example - * @param int $fd 获取连接的信息 - * @param int $reactor_id 获取连接的信息 + * @param mixed $fd 连接句柄 + * @param int $reactor_id reactor线程id * @return */ - public function getClientInfo($fd, $reactor_id) + public function getClientInfo($fd, int $reactor_id) { + } /** * - *用来遍历当前Server所有的客户端连接 + *用来遍历所有客户端连接(server->connection_list的别名) * @example - * @param int $start_fd 用来遍历当前Server所有的客户端连接 - * @param int $find_count 用来遍历当前Server所有的客户端连接 + * @param int $start_fd 起始fd + * @param int $find_count 每页取多少条 * @return */ - public function getClientList($start_fd, $find_count) + public function getClientList(int $start_fd, int $find_count) { + } /** * - *在指定的时间后执行函数 + *在指定时间后执行某个回调函数 * @example - * @param int $ms 在指定的时间后执行函数 - * @param callable $callback 在指定的时间后执行函数 - * @param array $param 在指定的时间后执行函数 + * @param int $ms 指定时间,单位为毫秒 + * @param callable $callback 回调函数 + * @param array $param 给回调函数传入的参数 * @return */ - public function after($ms, Callable $callback, Array $param) + public function after(int $ms, Callable $callback, Array $param) { + } /** * - *ick定时器,可以自定义回调函数 + *添加定时器 * @example - * @param int $ms ick定时器,可以自定义回调函数 - * @param callable $callback ick定时器,可以自定义回调函数 + * @param int $ms 指定时间,单位为毫秒 + * @param callable $callback 回调函数 * @return */ - public function tick($ms, Callable $callback) + public function tick(int $ms, Callable $callback) { + } /** * - *清除tick/after定时器,此函数是swoole_timer_clear的别名 + *清除定时器 * @example - * @param int $timer_id 清除tick/after定时器,此函数是swoole_timer_clear的别名 + * @param int $timer_id 定时器ID * @return */ - public function clearTimer($timer_id) + public function clearTimer(int $timer_id) { + } /** * - *延后执行一个PHP函数。Swoole底层会在EventLoop循环完成后执行此函数。此函数的目的是为了让一些PHP代码延后执行,程序优先处理IO事件 + *延迟执行一个PHP函数 * @example - * @param callable $callback 延后执行一个PHP函数。Swoole底层会在EventLoop循环完成后执行此函数。此函数的目的是为了让一些PHP代码延后执行,程序优先处理IO事件 + * @param callable $callback 执行的函数 * @return */ public function defer(Callable $callback) { + } /** * - *此函数可以向任意worker进程或者task进程发送消息。在非主进程和管理进程中可调用。收到消息的进程会触发onPipeMessage事件。 + *向任意worker进程或task进程发送消息 * @example - * @param int $dst_worker_id 此函数可以向任意worker进程或者task进程发送消息。在非主进程和管理进程中可调用。收到消息的进程会触发onPipeMessage事件。 - * @param string $data 此函数可以向任意worker进程或者task进程发送消息。在非主进程和管理进程中可调用。收到消息的进程会触发onPipeMessage事件。 + * @param int $dst_worker_id 目标worker的ID + * @param string $data 发送的消息 * @return */ - public function sendMessage($dst_worker_id, $data) + public function sendMessage(int $dst_worker_id, string $data) { + } /** * - *添加一个用户自定义的工作进程 + *添加一个自定义的工作进程 * @example - * @param object $process 添加一个用户自定义的工作进程 + * @param Swoole\Process $process 进程对象 * @return */ - public function addProcess($process) + public function addProcess(Swoole\Process $process) { + } /** * - *得到当前Server的活动TCP连接数,启动时间,accpet/close的总次数等信息 + *得到当前server的活动TCP连接数 + *array ( * @example - * @return array + * @return */ public function stats() { + } /** * - *将连接绑定一个用户定义的ID,可以设置dispatch_mode=5设置已此ID值进行hash固定分配。可以保证某一个UID的连接全部会分配到同一个Worker进程 + *将连接绑定到某个用户定义的ID * @example - * @param int $fd 将连接绑定一个用户定义的ID,可以设置dispatch_mode=5设置已此ID值进行hash固定分配。可以保证某一个UID的连接全部会分配到同一个Worker进程 - * @param int $uid 将连接绑定一个用户定义的ID,可以设置dispatch_mode=5设置已此ID值进行hash固定分配。可以保证某一个UID的连接全部会分配到同一个Worker进程 + * @param int $fd 连接句柄 + * @param int $uid 用户定义的ID * @return */ - public function bind($fd, $uid) + public function bind(int $fd, int $uid) { + } } diff --git a/src/Swoole/swoole.namespace.php b/src/Swoole/swoole.namespace.php index 72d5630..4f2240a 100644 --- a/src/Swoole/swoole.namespace.php +++ b/src/Swoole/swoole.namespace.php @@ -1,224 +1,970 @@ wait操作,在Linux平台下相当手工调用一次epoll_wait。与swoole_event_wait不同的是,swoole_event_wait在底层内部维持了循环) +* @example +* +* @return +*/ +function swoole_event_dispatch() +{ + +} + +/** +* +*检测传入的$fd是否已加入了事件监听 +* @example +* +* @param int $fd:任意的socket文件描述符,参考 swoole_event_add 文档 +* @param int $events:检测的事件类型(SWOOLE_EVENT_READ:是否监听了可读事件SWOOLE_EVENT_WRITE:是否监听了可写事件;;SWOOLE_EVENT_READ | SWOOLE_EVENT_WRITE:监听可读或可写事件) +* @return +*/ +function swoole_event_isset(int $fd, int $events) +{ + } /** * -*添加一个在指定的时间后执行某个函数的定时器 +*添加一个在指定的时间后执行某个函数的定时器(执行成功返回定时器ID) * @example * -* @param int $ms -* @param callable $callback -* @param mixed $param +* @param int $ms:延迟的毫秒数 +* @param callable $callback:执行的函数 +* @param mixed $param:函数参数 * @return int */ -function swoole_timer_after($ms, Callable $callback, $param) +function swoole_timer_after(int $ms, Callable $callback, $param): int { + } /** @@ -360,12 +1156,13 @@ function swoole_timer_after($ms, Callable $callback, $param) *添加一个在指定时间循环执行某个函数的定时器 * @example * -* @param int $ms -* @param callable $callback +* @param int $ms:循环周期时间 +* @param callable $callback:执行的函数 * @return int */ -function swoole_timer_tick($ms, Callable $callback) +function swoole_timer_tick(int $ms, Callable $callback): int { + } /** @@ -373,11 +1170,12 @@ function swoole_timer_tick($ms, Callable $callback) *检查一个定时器是否存在 * @example * -* @param int $timer_id -* @return boolean +* @param int $timer_id:定时器ID +* @return bool */ -function swoole_timer_exists($timer_id) +function swoole_timer_exists(int $timer_id): bool { + } /** @@ -385,23 +1183,33 @@ function swoole_timer_exists($timer_id) *清除某个定时器 * @example * -* @param int $timer_id -* @return +* @param int $timer_id:定时器ID +* @return bool */ -function swoole_timer_clear($timer_id) +function swoole_timer_clear(int $timer_id): bool { + } /** * *置异步IO相关的选项 +*设置的选项可以为以下值: +* thread_num : 设置异步文件IO线程的数量 +* aio_mode : 设置异步文件IO的操作模式,目前支持SWOOLE_AIO_BASE(使用类似于Node.js的线程池同步阻塞模拟异步)、SWOOLE_AIO_LINUX(Linux Native AIO) 2种模式 +* enable_signalfd : 开启和关闭signalfd特性的使用 +* socket_buffer_size : 设置SOCKET内存缓存区尺寸 +* socket_dontwait :在内存缓存区已满的情况下禁止底层阻塞等待 +* log_file :设置日志文件路径 +* log_level : 设置错误日志等级 * @example -* -* @param array $settings +* swoole_async_set(array('thread_num'=>2)) +* @param array $settings:设置的选项 * @return */ function swoole_async_set(Array $settings) { + } /** @@ -409,14 +1217,18 @@ function swoole_async_set(Array $settings) *异步读文件,使用此函数读取文件是非阻塞的,当读操作完成时会自动回调指定的函数 * @example * -* @param string $filename -* @param callable $callback -* @param int $chunk_size -* @param int $offset -* @return boolean -*/ -function swoole_async_read($filename, Callable $callback, $chunk_size, $offset) +* @param string $filename:文件名 +* @param callable $callback:读操作完成后的回调函数, 其回调函数原型: + bool callback(string $filename, string $content); + * $filename,文件名称 + * $content,读取到的分段内容,如果内容为空,表明文件已读完 +* @param int $chunk_size:读的块大小 +* @param int $offset:读文件的指针偏移量 +* @return bool +*/ +function swoole_async_read(string $filename, Callable $callback, int $chunk_size, int $offset): bool { + } /** @@ -424,27 +1236,31 @@ function swoole_async_read($filename, Callable $callback, $chunk_size, $offset) *异步写文件,与swoole_async_writefile不同,write是分段读写的。不需要一次性将要写的内容放到内存里,所以只占用少量内存。swoole_async_write通过传入的offset参数来确定写入的位置 * @example * -* @param string $filename -* @param string $content -* @param int $offset -* @param callable $callback -* @return boolean +* @param string $filename:写入的文件名 +* @param string $content:写入的文件内容 +* @param int $offset:写入的文件位置(指针偏移) +* @param callable $callback:写完成后执行的回调函数 +* @return */ -function swoole_async_write($filename, $content, $offset, Callable $callback) +function swoole_async_write(string $filename, string $content, int $offset, Callable $callback) { + } /** * -*异步读取文件内容 +*异步读取文件内容(与readfile功能类似),完成后并执行某个函数 * @example -* -* @param string $filename -* @param callable $callback -* @return boolean +* swoole_async_readfile(__DIR__."/server.php", function($filename, $content) { +* echo "$filename: $content"; +* }); +* @param string $filename:文件名 +* @param callable $callback:读文件完成后的回调函数 +* @return */ -function swoole_async_readfile($filename, Callable $callback) +function swoole_async_readfile(string $filename, Callable $callback) { + } /** @@ -452,30 +1268,110 @@ function swoole_async_readfile($filename, Callable $callback) *异步写文件,调用此函数后会立即返回。当写入完成时会自动回调指定的callback函数 * @example * -* @param string $filename -* @param string $content -* @param callable $callback -* @param int $flags +* @param string $filename:写入的文件名 +* @param string $content:写入的内容 +* @param callable $callback:写文件完成后的回调函数 +* @param int $flags:其他写入选项,如可以使用FILE_APPEND表示追加到文件末尾 * @return */ -function swoole_async_writefile($filename, $content, Callable $callback, $flags) +function swoole_async_writefile(string $filename, string $content, Callable $callback, int $flags) { + } /** * *将域名解析为IP地址。调用此函数是非阻塞的,调用会立即返回 * @example -* swoole_async_dns_lookup("www.baidu.com", function($host, $ip){ -* echo "{$host} : {$ip} -* "; +* swoole_async_dns_lookup("www.baidu.com", function($host, $ip){ +* echo "{$host} : {$ip} +* "; * }); -* @param string $domain_name -* @param callable $callback +* @param string $hostname:域名 +* @param callable $callback:解析后的回调函数 +* @return +*/ +function swoole_async_dns_lookup(string $hostname, Callable $callback) +{ + +} + +/** +* +*协程DNS查询 +* @example +* +* @param string $domain_name:要查询的域名 +* @return string|bool +*/ +function swoole_async_dns_lookup_coro(string $domain_name): ?string +{ + +} + +/** +* +*创建一个协程 +* @example +* +* @param callable $func:执行的函数 +* @return +*/ +function swoole_coroutine_create(Callable $func) +{ + +} + +/** +* +*协程执行一个命令 +* @example +* +* @param string $command:执行的命令(如shell命令) +* @return +*/ +function swoole_coroutine_exec(string $command) +{ + +} + +/** +* +*通过协程延迟执行某个函数 +* @example +* +* @param Callable $callback:延迟执行的函数 +* @return +*/ +function swoole_coroutine_defer(Callable $callback) +{ + +} + +/** +* +*开启一个协程 +* @example +* +* @param callable | string | array $func:要执行的函数 +* @return +*/ +function go(callable $func) +{ + +} + +/** +* +*延迟执行某个函数 +* @example +* +* @param Callable $callback:延迟执行的函数 * @return */ -function swoole_async_dns_lookup($domain_name, Callable $callback) +function defer(Callable $callback) { + } /** @@ -483,29 +1379,31 @@ function swoole_async_dns_lookup($domain_name, Callable $callback) *swoole_client的并行处理中用了select来做IO事件循环 * @example * -* @param array $read_array -* @param array $write_array -* @param array $error_array -* @param float $timeout +* @param array $read_array:可读文件描述符 +* @param array $write_array:可写文件描述符 +* @param array $error_array:错误文件描述符 +* @param float $timeout:超时时间 * @return int */ -function swoole_client_select(Array $read_array, Array $write_array, Array $error_array, $timeout) +function swoole_client_select(Array $read_array, Array $write_array, Array $error_array, float $timeout): int { + } /** * -*swoole的并行处理中用了select来做IO事件循环 +*swoole的并行处理中用了select来做IO事件循环(是swoole_client_select的别名) * @example * -* @param array $read_array -* @param array $write_array -* @param array $error_array -* @param float $timeout -* @return int +* @param array $read_array:可读文件描述符 +* @param array $write_array:可写文件描述符 +* @param array $error_array:错误文件描述符 +* @param float $timeout:超时时间 +* @return */ -function swoole_select(Array $read_array, Array $write_array, Array $error_array, $timeout) +function swoole_select(Array $read_array, Array $write_array, Array $error_array, float $timeout) { + } /** @@ -513,11 +1411,12 @@ function swoole_select(Array $read_array, Array $write_array, Array $error_array *设置进程的名称(存在兼容性问题,优先使用PHP内置的cli_set_process_title函数) * @example * swoole_set_process_name('swoole_server'); -* @param string $process_name -* @return 无 +* @param string $process_name:进程名称 +* @return */ -function swoole_set_process_name($process_name) +function swoole_set_process_name(string $process_name) { + } /** @@ -525,23 +1424,36 @@ function swoole_set_process_name($process_name) *用于获取本地所有网络接口的IP地址(返回以interface名称为key的关联数组) * @example * $ips = swoole_get_local_ip(); +* @return array +*/ +function swoole_get_local_ip(): array +{ + +} + +/** * -* @return array (只返回IPv4地址,返回结果会过滤掉本地的loop地址127.0.0.1,类似于array('eth0'=>'192.168.0.25')) +*获取本地所有网络接口的mac地址(返回以interface名称为key的关联数组) +* @example +* $macs = swoole_get_local_mac(); +* @return array */ -function swoole_get_local_ip() +function swoole_get_local_mac(): array { + } /** * *从标准的Unix Errno错误码转换成错误信息 * @example -* $errmsg = swoole_strerror($errno); -* @param int $errno +* +* @param int $errno:标准错误码 * @return string */ -function swoole_strerror($errno) +function swoole_strerror(int $errno): string { + } /** @@ -551,19 +1463,47 @@ function swoole_strerror($errno) * echo swoole_strerror(swoole_errno()); * @return int */ -function swoole_errno() +function swoole_errno(): int { + } /** * -*动态加载扩展模块 +*获取指定的数据的哈希码 * @example * -* @param string $name -* @return +* @param string $data:指定的数据 +* @param int $type:类型 +* @return string +*/ +function swoole_hashcode(string $data, int $type): string +{ + +} + +/** +* +*获取文件的MIME类型 +* @example +* +* @param string $filename:文件名 +* @return string|null +*/ +function swoole_get_mime_type(string $filename): ?string +{ + +} + +/** +* +*请求状态是否为用户自定义关闭操作的开始阶段 +* @example +* +* @return bool */ -function swoole_load_module($name) +function swoole_call_user_shutdown_begin(): bool { + } diff --git a/src/Swoole/swoole.php b/src/Swoole/swoole.php index 66fc89e..118c396 100644 --- a/src/Swoole/swoole.php +++ b/src/Swoole/swoole.php @@ -1,224 +1,970 @@ wait操作,在Linux平台下相当手工调用一次epoll_wait。与swoole_event_wait不同的是,swoole_event_wait在底层内部维持了循环) +* @example +* +* @return +*/ +function swoole_event_dispatch() +{ + +} + +/** +* +*检测传入的$fd是否已加入了事件监听 +* @example +* +* @param int $fd:任意的socket文件描述符,参考 swoole_event_add 文档 +* @param int $events:检测的事件类型(SWOOLE_EVENT_READ:是否监听了可读事件SWOOLE_EVENT_WRITE:是否监听了可写事件;;SWOOLE_EVENT_READ | SWOOLE_EVENT_WRITE:监听可读或可写事件) +* @return +*/ +function swoole_event_isset(int $fd, int $events) +{ + } /** * -*添加一个在指定的时间后执行某个函数的定时器 +*添加一个在指定的时间后执行某个函数的定时器(执行成功返回定时器ID) * @example * -* @param int $ms -* @param callable $callback -* @param mixed $param +* @param int $ms:延迟的毫秒数 +* @param callable $callback:执行的函数 +* @param mixed $param:函数参数 * @return int */ -function swoole_timer_after($ms, Callable $callback, $param) +function swoole_timer_after(int $ms, Callable $callback, $param): int { + } /** @@ -360,12 +1156,13 @@ function swoole_timer_after($ms, Callable $callback, $param) *添加一个在指定时间循环执行某个函数的定时器 * @example * -* @param int $ms -* @param callable $callback +* @param int $ms:循环周期时间 +* @param callable $callback:执行的函数 * @return int */ -function swoole_timer_tick($ms, Callable $callback) +function swoole_timer_tick(int $ms, Callable $callback): int { + } /** @@ -373,11 +1170,12 @@ function swoole_timer_tick($ms, Callable $callback) *检查一个定时器是否存在 * @example * -* @param int $timer_id -* @return boolean +* @param int $timer_id:定时器ID +* @return bool */ -function swoole_timer_exists($timer_id) +function swoole_timer_exists(int $timer_id): bool { + } /** @@ -385,23 +1183,33 @@ function swoole_timer_exists($timer_id) *清除某个定时器 * @example * -* @param int $timer_id -* @return +* @param int $timer_id:定时器ID +* @return bool */ -function swoole_timer_clear($timer_id) +function swoole_timer_clear(int $timer_id): bool { + } /** * *置异步IO相关的选项 +*设置的选项可以为以下值: +* thread_num : 设置异步文件IO线程的数量 +* aio_mode : 设置异步文件IO的操作模式,目前支持SWOOLE_AIO_BASE(使用类似于Node.js的线程池同步阻塞模拟异步)、SWOOLE_AIO_LINUX(Linux Native AIO) 2种模式 +* enable_signalfd : 开启和关闭signalfd特性的使用 +* socket_buffer_size : 设置SOCKET内存缓存区尺寸 +* socket_dontwait :在内存缓存区已满的情况下禁止底层阻塞等待 +* log_file :设置日志文件路径 +* log_level : 设置错误日志等级 * @example -* -* @param array $settings +* swoole_async_set(array('thread_num'=>2)) +* @param array $settings:设置的选项 * @return */ function swoole_async_set(Array $settings) { + } /** @@ -409,14 +1217,18 @@ function swoole_async_set(Array $settings) *异步读文件,使用此函数读取文件是非阻塞的,当读操作完成时会自动回调指定的函数 * @example * -* @param string $filename -* @param callable $callback -* @param int $chunk_size -* @param int $offset -* @return boolean -*/ -function swoole_async_read($filename, Callable $callback, $chunk_size, $offset) +* @param string $filename:文件名 +* @param callable $callback:读操作完成后的回调函数, 其回调函数原型: + bool callback(string $filename, string $content); + * $filename,文件名称 + * $content,读取到的分段内容,如果内容为空,表明文件已读完 +* @param int $chunk_size:读的块大小 +* @param int $offset:读文件的指针偏移量 +* @return bool +*/ +function swoole_async_read(string $filename, Callable $callback, int $chunk_size, int $offset): bool { + } /** @@ -424,27 +1236,31 @@ function swoole_async_read($filename, Callable $callback, $chunk_size, $offset) *异步写文件,与swoole_async_writefile不同,write是分段读写的。不需要一次性将要写的内容放到内存里,所以只占用少量内存。swoole_async_write通过传入的offset参数来确定写入的位置 * @example * -* @param string $filename -* @param string $content -* @param int $offset -* @param callable $callback -* @return boolean +* @param string $filename:写入的文件名 +* @param string $content:写入的文件内容 +* @param int $offset:写入的文件位置(指针偏移) +* @param callable $callback:写完成后执行的回调函数 +* @return */ -function swoole_async_write($filename, $content, $offset, Callable $callback) +function swoole_async_write(string $filename, string $content, int $offset, Callable $callback) { + } /** * -*异步读取文件内容 +*异步读取文件内容(与readfile功能类似),完成后并执行某个函数 * @example -* -* @param string $filename -* @param callable $callback -* @return boolean +* swoole_async_readfile(__DIR__."/server.php", function($filename, $content) { +* echo "$filename: $content"; +* }); +* @param string $filename:文件名 +* @param callable $callback:读文件完成后的回调函数 +* @return */ -function swoole_async_readfile($filename, Callable $callback) +function swoole_async_readfile(string $filename, Callable $callback) { + } /** @@ -452,30 +1268,110 @@ function swoole_async_readfile($filename, Callable $callback) *异步写文件,调用此函数后会立即返回。当写入完成时会自动回调指定的callback函数 * @example * -* @param string $filename -* @param string $content -* @param callable $callback -* @param int $flags +* @param string $filename:写入的文件名 +* @param string $content:写入的内容 +* @param callable $callback:写文件完成后的回调函数 +* @param int $flags:其他写入选项,如可以使用FILE_APPEND表示追加到文件末尾 * @return */ -function swoole_async_writefile($filename, $content, Callable $callback, $flags) +function swoole_async_writefile(string $filename, string $content, Callable $callback, int $flags) { + } /** * *将域名解析为IP地址。调用此函数是非阻塞的,调用会立即返回 * @example -* swoole_async_dns_lookup("www.baidu.com", function($host, $ip){ -* echo "{$host} : {$ip} -* "; +* swoole_async_dns_lookup("www.baidu.com", function($host, $ip){ +* echo "{$host} : {$ip} +* "; * }); -* @param string $domain_name -* @param callable $callback +* @param string $hostname:域名 +* @param callable $callback:解析后的回调函数 +* @return +*/ +function swoole_async_dns_lookup(string $hostname, Callable $callback) +{ + +} + +/** +* +*协程DNS查询 +* @example +* +* @param string $domain_name:要查询的域名 +* @return string|bool +*/ +function swoole_async_dns_lookup_coro(string $domain_name): ?string +{ + +} + +/** +* +*创建一个协程 +* @example +* +* @param callable $func:执行的函数 +* @return +*/ +function swoole_coroutine_create(Callable $func) +{ + +} + +/** +* +*协程执行一个命令 +* @example +* +* @param string $command:执行的命令(如shell命令) +* @return +*/ +function swoole_coroutine_exec(string $command) +{ + +} + +/** +* +*通过协程延迟执行某个函数 +* @example +* +* @param Callable $callback:延迟执行的函数 +* @return +*/ +function swoole_coroutine_defer(Callable $callback) +{ + +} + +/** +* +*开启一个协程 +* @example +* +* @param callable | string | array $func:要执行的函数 +* @return +*/ +function go(callable $func) +{ + +} + +/** +* +*延迟执行某个函数 +* @example +* +* @param Callable $callback:延迟执行的函数 * @return */ -function swoole_async_dns_lookup($domain_name, Callable $callback) +function defer(Callable $callback) { + } /** @@ -483,29 +1379,31 @@ function swoole_async_dns_lookup($domain_name, Callable $callback) *swoole_client的并行处理中用了select来做IO事件循环 * @example * -* @param array $read_array -* @param array $write_array -* @param array $error_array -* @param float $timeout +* @param array $read_array:可读文件描述符 +* @param array $write_array:可写文件描述符 +* @param array $error_array:错误文件描述符 +* @param float $timeout:超时时间 * @return int */ -function swoole_client_select(Array $read_array, Array $write_array, Array $error_array, $timeout) +function swoole_client_select(Array $read_array, Array $write_array, Array $error_array, float $timeout): int { + } /** * -*swoole的并行处理中用了select来做IO事件循环 +*swoole的并行处理中用了select来做IO事件循环(是swoole_client_select的别名) * @example * -* @param array $read_array -* @param array $write_array -* @param array $error_array -* @param float $timeout -* @return int +* @param array $read_array:可读文件描述符 +* @param array $write_array:可写文件描述符 +* @param array $error_array:错误文件描述符 +* @param float $timeout:超时时间 +* @return */ -function swoole_select(Array $read_array, Array $write_array, Array $error_array, $timeout) +function swoole_select(Array $read_array, Array $write_array, Array $error_array, float $timeout) { + } /** @@ -513,11 +1411,12 @@ function swoole_select(Array $read_array, Array $write_array, Array $error_array *设置进程的名称(存在兼容性问题,优先使用PHP内置的cli_set_process_title函数) * @example * swoole_set_process_name('swoole_server'); -* @param string $process_name -* @return 无 +* @param string $process_name:进程名称 +* @return */ -function swoole_set_process_name($process_name) +function swoole_set_process_name(string $process_name) { + } /** @@ -525,23 +1424,36 @@ function swoole_set_process_name($process_name) *用于获取本地所有网络接口的IP地址(返回以interface名称为key的关联数组) * @example * $ips = swoole_get_local_ip(); +* @return array +*/ +function swoole_get_local_ip(): array +{ + +} + +/** * -* @return array (只返回IPv4地址,返回结果会过滤掉本地的loop地址127.0.0.1,类似于array('eth0'=>'192.168.0.25')) +*获取本地所有网络接口的mac地址(返回以interface名称为key的关联数组) +* @example +* $macs = swoole_get_local_mac(); +* @return array */ -function swoole_get_local_ip() +function swoole_get_local_mac(): array { + } /** * *从标准的Unix Errno错误码转换成错误信息 * @example -* $errmsg = swoole_strerror($errno); -* @param int $errno +* +* @param int $errno:标准错误码 * @return string */ -function swoole_strerror($errno) +function swoole_strerror(int $errno): string { + } /** @@ -551,19 +1463,47 @@ function swoole_strerror($errno) * echo swoole_strerror(swoole_errno()); * @return int */ -function swoole_errno() +function swoole_errno(): int { + } /** * -*动态加载扩展模块 +*获取指定的数据的哈希码 * @example * -* @param string $name -* @return +* @param string $data:指定的数据 +* @param int $type:类型 +* @return string +*/ +function swoole_hashcode(string $data, int $type): string +{ + +} + +/** +* +*获取文件的MIME类型 +* @example +* +* @param string $filename:文件名 +* @return string|null +*/ +function swoole_get_mime_type(string $filename): ?string +{ + +} + +/** +* +*请求状态是否为用户自定义关闭操作的开始阶段 +* @example +* +* @return bool */ -function swoole_load_module($name) +function swoole_call_user_shutdown_begin(): bool { + } diff --git a/src/Swoole/swoole_async.php b/src/Swoole/swoole_async.php index 24de8a5..2151816 100644 --- a/src/Swoole/swoole_async.php +++ b/src/Swoole/swoole_async.php @@ -1,8 +1,8 @@ start前创建;在swoole_process中使用原子计数器,必须在swoole_process->start前创建) + *初始化一个计数器对象 * @example - * @param int $value 创建一个原子计数对象(只能操作32位整数,最大支持42亿.在swoole_server中使用原子计数器,必须在swoole_server->start前创建;在swoole_process中使用原子计数器,必须在swoole_process->start前创建) + * @param int $value 初始值 * @return */ - public function __construct($value) + public function __construct(int $value) { + } /** * *增加计数 * @example - * @param int $add_value 增加计数 + * @param int $add_value 要增加的数值,默认为1,必须为正整数 * @return */ - public function add($add_value) + public function add(int $add_value) { + } /** * *减少计数 * @example - * @param int $sub_value 减少计数 + * @param int $sub_value 要减少的数值,默认为1 * @return */ - public function sub($sub_value) + public function sub(int $sub_value) { + } /** @@ -51,29 +54,78 @@ public function sub($sub_value) */ public function get() { + } /** * *将当前值设置为指定的数字 * @example - * @param int $value 将当前值设置为指定的数字 + * @param int $value 指定要设置的目标数值 * @return */ - public function set($value) + public function set(int $value) { + } /** * - *如果当前数值等于参数1,则将当前数值设置为参数2($cmp_value,$set_value 必须为小于42亿的整数) + *当原子计数的值为0时程序进入等待状态。另外一个进程调用wakeup可以再次唤醒程序。底层基于Linux Futex实现,使用此特性,可以仅用4字节内存实现一个等待、通知、锁的功能 * @example - * @param int $cmp_value 如果当前数值等于参数1,则将当前数值设置为参数2($cmp_value,$set_value 必须为小于42亿的整数) - * @param int $new_value 如果当前数值等于参数1,则将当前数值设置为参数2($cmp_value,$set_value 必须为小于42亿的整数) + * @param float $timeout 指定超时时间,默认为-1,表示永不超时,会持续等待直到有其他进程唤醒;超时返回false,错误码为EAGAIN,可使用swoole_errno函数获取;成功返回true,表示有其他进程通过wakeup成功唤醒了当前的锁;使用wait/wakeup特性时,原子计数的值只能为0或1,否则会导致无法正常使用;当然原子计数的值为1时,表示不需要进入等待状态,资源当前就是可用。wait函数会立即返回true * @return */ - public function cmpset($cmp_value, $new_value) + public function wait(float $timeout) { + + } + + /** + * + *唤醒处于wait状态的其他进程 + * @example + * @param int $count 计数(当前原子计数如果为0时,表示没有进程正在wait,wakeup会立即返回true;当前原子计数如果为1时,表示当前有进程正在wait,wakeup会唤醒等待的进程,并返回true;如果同时有多个进程处于wait状态,$n参数可以控制唤醒的进程数量;被唤醒的进程返回后,会将原子计数设置为0,这时可以再次调用wakeup唤醒其他正在wait的进程) + * @return + */ + public function wakeup(int $count) + { + + } + + /** + * + *如果当前计数器的值与比较的值的相等,则设置它为新的值 + * @example + * @param int $cmp_value 用于比较的值 + * @param int $new_value 用于设置的新值 + * @return + */ + public function cmpset(int $cmp_value, int $new_value) + { + + } + + /** + * + *序列化函数调用的魔术方法(在PHP进行序列化时,serialize() 检查类中是否有 __sleep() ,如果有,则该函数将在任何序列化之前运行。该函数必须返回一个需要进行序列化保存的成员属性数组,并且只序列化该函数返回的这些成员属性. 该函数有两个作用: 第一. 在序列化之前,关闭对象可能具有的任何数据库连接等. 第二. 指定对象中需要被序列化的成员属性,如果某个属性比较大而不需要储存下来,可以不把它写进__sleep要返回的数组中,这样该属性就不会被序列化) + * @example + * @return + */ + public function __sleep() + { + + } + + /** + * + *反序列化函数调用的魔术方法(unserialize() 从字节流中创建了一个对象之后,马上检查是否具有__wakeup 的函数的存在。如果存在,__wakeup 立刻被调用。使用 __wakeup 的目的是重建在序列化中可能丢失的任何数据库连接以及处理其它重新初始化的任务) + * @example + * @return + */ + public function __wakeup() + { + } } diff --git a/src/Swoole/swoole_atomic_long.php b/src/Swoole/swoole_atomic_long.php new file mode 100644 index 0000000..e26760d --- /dev/null +++ b/src/Swoole/swoole_atomic_long.php @@ -0,0 +1,108 @@ +0, + 'queue_bytes'=>0 + ]; } } diff --git a/src/Swoole/swoole_client.php b/src/Swoole/swoole_client.php index dee9fb9..283ea48 100644 --- a/src/Swoole/swoole_client.php +++ b/src/Swoole/swoole_client.php @@ -1,12 +1,12 @@ recv方法的第二个参数,阻塞等待直到收到指定长度的数据后返回 + *阻塞等待直到收到指定长度的数据后返回 */ const MSG_WAITALL = 256; + /** + *读写被关闭 + */ + const SHUT_RDWR = 2; + + /** + *读被关闭 + */ + const SHUT_RD = 0; + + /** + *写被关闭 + */ + const SHUT_WR = 1; + /** * @var int $errCode - * 错误码。errCode的值等于Linux errno。可使用socket_strerror将错误码转为错误信息 + * 错误码 * @access public */ public $errCode = 0; /** * @var int $sock - * sock属性是此socket的文件描述符 + * 此socket的文件描述符 * @access public */ public $sock = 0; /** - * @var bool $reuse - * 表示此连接是新创建的还是复用已存在的。与SWOOLE_KEEP配合使用 + * @var boolean $reuse + * 表示此连接是新创建的还是复用已存在的 * @access public */ public $reuse = ''; /** * @var int $reuseCount - * + * 表示此连接复用次数 * @access public */ public $reuseCount = 0; + /** + * @var int $type + * 连接的类型 + * @access public + */ + public $type = 0; + + /** + * @var int $id + * 客户端连接ID + * @access public + */ + public $id; + + /** + * @var array $setting + * 配置选项 + * @access public + */ + public $setting = array(); + + /** + * @var callable $onConnect + * 连接的回调函数 + * @access private + */ + private $onConnect; + + /** + * @var callable $onError + * 发生错误时的回调函数 + * @access private + */ + private $onError; + + /** + * @var callable $onReceive + * 客户端收到来自于服务器端的数据时会回调此函数 + * @access private + */ + private $onReceive; + + /** + * @var callable $onClose + * 连接被关闭时回调此函数 + * @access private + */ + private $onClose; + + /** + * @var callable $onBufferFull + * 当缓存区达到最高水位时触发此事件 + * @access private + */ + private $onBufferFull; + + /** + * @var callable $onBufferEmpty + * 当缓存区低于最低水位线时触发此事件 + * @access private + */ + private $onBufferEmpty; + + /** + * @var callable $onSSLReady + * 当SSL连接就绪时的回调函数 + * @access private + */ + private $onSSLReady; + /** * - *创建tcp/udp客户端 + *创建tcp客户端对象 * @example - * @param int $type 创建tcp/udp客户端 - * @param int $async 创建tcp/udp客户端 + * @param int $type 表示socket的类型,如TCP/UDP(使用常量) + * @param boolean $async 表示同步阻塞还是异步非阻塞,默认为同步阻塞 * @return */ - public function __construct($type, $async) + public function __construct(int $type, bool $async) { + } /** * - *析构函数 + *析构方法 * @example * @return */ public function __destruct() { + } /** * *设置客户端参数 * @example - * @param array $settings 设置客户端参数 + * @param array $settings 设置的参数 * @return */ public function set(Array $settings) { + } /** * - *连接到远程服务器 + *连接远程服务器 * @example - * @param string $host 连接到远程服务器 - * @param int $port 连接到远程服务器 - * @param float $timeout 连接到远程服务器 - * @param int $sock_flag 连接到远程服务器 - * @return bool + * @param string $host 是远程服务器的地址,1.9.24或更高版本已支持自动异步解析域名,$host可直接传入域名 + * @param int $port 是远程服务器端口 + * @param float $timeout 是网络IO的超时,包括connect/send/recv,单位是s,支持浮点数。默认为0.5s,即500ms + * @param int $sock_flag 在UDP类型时表示是否启用udp_connect 设定此选项后将绑定$host与$port,此UDP将会丢弃非指定host/port的数据包; + * @return */ - public function connect($host, $port, $timeout, $sock_flag) + public function connect(string $host, int $port, float $timeout, int $sock_flag) { + } /** * - *用于从服务器端接收数据 + *从服务器端接收数据 * @example - * @param int $size 用于从服务器端接收数据 - * @param int $flag 用于从服务器端接收数据 + * @param int $size 接收数据的缓存区最大长度,此参数不要设置过大,否则会占用较大内存 + * @param boolean $flag 是否等待所有数据到达后返回 * @return string */ - public function recv($size, $flag) + public function recv(int $size, bool $flag): string { + } /** * - *发送数据到远程服务器,必须在建立连接后,才可向Server发送数据 + *发送数据到远程服务器 * @example - * @param string $data 发送数据到远程服务器,必须在建立连接后,才可向Server发送数据 - * @param mixed $flag - * @return int + * @param string $data 要发送的数据 + * @param boolean $flag 是否等待所有数据到达后返回 + * @return */ - public function send($data, $flag) + public function send(string $data, bool $flag) { + } /** * - *使用管道发送数据 + *将客户端收到的数据重定向到另外一个文件描述符,可以是服务器的连接fd、stream资源、sockets资源、其他Swoole_Client、Swoole_Process的管道 * @example - * @param int $dst_socket 使用管道发送数据 + * @param int $dst_socket 目标文件描述符 * @return */ - public function pipe($dst_socket) + public function pipe(int $dst_socket) { + } /** * - *发送文件到服务器,本函数是基于sendfile操作系统调用的 + *向服务器发送文件 * @example - * @param string $filename 发送文件到服务器,本函数是基于sendfile操作系统调用的 - * @param int $offset 发送文件到服务器,本函数是基于sendfile操作系统调用的 - * @return bool + * @param string $filename 指定要发送文件的路径 + * @param int $offset 上传文件的偏移量,可以指定从文件的中间部分开始传输数据。此特性可用于支持断点续传 + * @param int $length 发送数据的尺寸,默认为整个文件的尺寸 + * @return boolean */ - public function sendfile($filename, $offset) + public function sendfile(string $filename, int $offset, int $length): boolean { + } /** * - *向任意IP:PORT的主机发送UDP数据包,仅支持SWOOLE_SOCK_UDP/SWOOLE_SOCK_UDP6类型的swoole_client对象。 + *向任意主机发送UDP数据包 * @example - * @param string $ip 向任意IP:PORT的主机发送UDP数据包,仅支持SWOOLE_SOCK_UDP/SWOOLE_SOCK_UDP6类型的swoole_client对象。 - * @param int $port 向任意IP:PORT的主机发送UDP数据包,仅支持SWOOLE_SOCK_UDP/SWOOLE_SOCK_UDP6类型的swoole_client对象。 - * @param string $data 向任意IP:PORT的主机发送UDP数据包,仅支持SWOOLE_SOCK_UDP/SWOOLE_SOCK_UDP6类型的swoole_client对象。 - * @return bool + * @param string $ip 目标主机的IP地址,支持IPv4/IPv6 + * @param int $port 目标主机端口 + * @param string $data 要发送的数据内容,不得超过64K + * @return boolean */ - public function sendto($ip, $port, $data) + public function sendto(string $ip, int $port, string $data): boolean { + } /** @@ -173,89 +268,132 @@ public function sendto($ip, $port, $data) */ public function sleep() { + } /** * - *调用此方法会重新监听可读事件,将socket连接从睡眠中唤醒(如果socket并未进入sleep模式,wakeup操作没有任何作用) + *调用此方法会重新监听可读事件,将socket连接从睡眠中唤醒 * @example * @return */ public function wakeup() { + } /** * - *暂停数据接收 + *停止接收数据 * @example * @return */ public function pause() { + } /** * - *恢复数据接收 + *恢复数据接收。与pause方法成对使用 * @example * @return */ public function resume() { + + } + + /** + * + *动态开启SSL隧道加密。客户端在建立连接时使用明文通信,中途希望改为SSL隧道加密通信,可以使用enableSSL方法来实现 + * @example + * @param callable $callback 启用后的回调函数 + * @return + */ + public function enableSSL(Callable $callback) + { + + } + + /** + * + *获取服务器端证书信息 + * @example + * @return string | bool + */ + public function getPeerCert(): ?string + { + + } + + /** + * + *验证服务端证书信息 + * @example + * @return + */ + public function verifyPeerCert() + { + } /** * *返回swoole_client的连接状态 * @example - * @return bool + * @return */ public function isConnected() { + } /** * *用于获取客户端socket的本地host:port,必须在连接之后才可以使用 * @example - * @return array + * @return */ public function getsockname() { + } /** * - *获取对端socket的IP地址和端口,仅支持SWOOLE_SOCK_UDP/SWOOLE_SOCK_UDP6类型的swoole_client对象(此函数必须在$client->recv() 之后调用) + *获取对端socket的IP地址和端口 * @example - * @return bool + * @return */ public function getpeername() { + } /** * *关闭连接 * @example - * @param bool $force 关闭连接 - * @return bool + * @param boolean $force 表示强制关闭连接,可用于关闭SWOOLE_KEEP长连接 + * @return */ - public function close($force) + public function close(bool $force) { + } /** * - *注册异步事件回调函数,调用on方法会使当前的socket变成非阻塞的 + *绑定事件(为事件注册函数) * @example - * @param string $event_name 注册异步事件回调函数,调用on方法会使当前的socket变成非阻塞的 - * @param string $callback 注册异步事件回调函数,调用on方法会使当前的socket变成非阻塞的 - * @return int + * @param string $event_name 事件类型,支持connect/error/receive/close 4种 + * @param callable $callback 回调函数,可以是函数名字符串、匿名函数、类静态方法、对象方法 + * @return */ - public function on($event_name, $callback) + public function on(string $event_name, Callable $callback) { + } } diff --git a/src/Swoole/swoole_client_coro.php b/src/Swoole/swoole_client_coro.php deleted file mode 100644 index f9dfc27..0000000 --- a/src/Swoole/swoole_client_coro.php +++ /dev/null @@ -1,168 +0,0 @@ -recv方法的第二个参数,阻塞等待直到收到指定长度的数据后返回 - */ - const MSG_WAITALL = 256; - - /** - * @var int $errCode - * 错误码。errCode的值等于Linux errno。可使用socket_strerror将错误码转为错误信息 - * @access public - */ - public $errCode = 0; - - /** - * @var int $sock - * sock属性是此socket的文件描述符 - * @access public - */ - public $sock = 0; - - /** - * - *创建tcp/udp客户端 - * @example - * @return - */ - public function __construct() - { - } - - /** - * - *析构函数 - * @example - * @return - */ - public function __destruct() - { - } - - /** - * - *设置客户端参数 - * @example - * @return - */ - public function set() - { - } - - /** - * - *连接到远程服务器 - * @example - * @return bool - */ - public function connect() - { - } - - /** - * - *用于从服务器端接收数据 - * @example - * @return string - */ - public function recv() - { - } - - /** - * - *发送数据到远程服务器,必须在建立连接后,才可向Server发送数据 - * @example - * @return int - */ - public function send() - { - } - - /** - * - *发送文件到服务器,本函数是基于sendfile操作系统调用的 - * @example - * @return bool - */ - public function sendfile() - { - } - - /** - * - *向任意IP:PORT的主机发送UDP数据包,仅支持SWOOLE_SOCK_UDP/SWOOLE_SOCK_UDP6类型的swoole_client对象。 - * @example - * @return bool - */ - public function sendto() - { - } - - /** - * - *返回swoole_client的连接状态 - * @example - * @return bool - */ - public function isConnected() - { - } - - /** - * - *用于获取客户端socket的本地host:port,必须在连接之后才可以使用 - * @example - * @return array - */ - public function getsockname() - { - } - - /** - * - *获取对端socket的IP地址和端口,仅支持SWOOLE_SOCK_UDP/SWOOLE_SOCK_UDP6类型的swoole_client对象(此函数必须在$client->recv() 之后调用) - * @example - * @return bool - */ - public function getpeername() - { - } - - /** - * - *关闭连接 - * @example - * @return bool - */ - public function close() - { - } - -} - diff --git a/src/Swoole/swoole_connection_iterator.php b/src/Swoole/swoole_connection_iterator.php index e1e6563..92617ba 100644 --- a/src/Swoole/swoole_connection_iterator.php +++ b/src/Swoole/swoole_connection_iterator.php @@ -1,23 +1,24 @@ finish()方法将任务处理的结果发送给worker进程。 + * @access public + */ + public $onFinish; + + /** + * @var callable $onManagerStart + * 当管理进程启动时调用它 + * @access public + */ + public $onManagerStart; + + /** + * @var callable $onManagerStop + * 当管理进程结束时调用它 + * @access public + */ + public $onManagerStop; + + /** + * @var callable $onPipeMessage + * 当工作进程收到由 sendMessage 发送的管道消息时会触发onPipeMessage事件 + * @access public + */ + public $onPipeMessage; + + /** + * @var iterator $connections + * TCP连接迭代器 + * @access public + */ + public $connections; + + /** + * @var string $host + * 连接的主机 + * @access public + */ + public $host; + + /** + * @var int $port + * 连接的主机的端口 + * @access public + */ + public $port = 0; + + /** + * @var int $type + * socket的类型 + * @access public + */ + public $type = 0; + + /** + * @var int $mode + * 运行模式(swoole提供了3种运行模式,默认为SWOOLE_PROCESS多进程模式) + * @access public + */ + public $mode = 0; + + /** + * @var array $ports + * 当监听多端口时的端口列表 + * @access public */ - private $global = 0; + public $ports = array(); + + /** + * @var int $master_pid + * 主进程ID + * @access public + */ + public $master_pid = 0; + + /** + * @var int $manager_pid + * 管理进程ID + * @access public + */ + public $manager_pid = 0; + + /** + * @var int $worker_id + * 当前工作进程(包括worker进程和task进程)编号 + * @access public + */ + public $worker_id = -1; + + /** + * @var boolean $taskworker + * 当前进程是否是task工作进程 + * @access public + */ + public $taskworker = ''; + + /** + * @var int $worker_pid + * 当前工作进程ID(操作系统进程) + * @access public + */ + public $worker_pid = 0; + + /** + * @var callable $onRequest + * 请求回调函数 + * @access public + */ + public $onRequest; + + /** + * @var callable $onHandshake + * TCP握手时的回调函数 + * @access public + */ + public $onHandshake; + + /** + * @var array $setting + * 通过swoole_server:set()设置的参数会保存到setting属性上 + * @access public + */ + public $setting = array(); /** * - *注册Server的事件回调函数 + *绑定事件(为事件注册函数) * @example - * @param string $event_name 注册Server的事件回调函数 - * @param callable $callback 注册Server的事件回调函数 - * @return bool + * @param string $event_name 事件名称 + * @param callable $callback 事件对应的回调函数 + * @return */ - public function on($event_name, Callable $callback) + public function on(string $event_name, Callable $callback) { + } /** * - *启动server,监听所有TCP/UDP端口 + *启动HTTP server * @example - * @return bool + * @return */ public function start() { + + } + + /** + * + *序列化函数调用的魔术方法(在PHP进行序列化时,serialize() 检查类中是否有 __sleep() ,如果有,则该函数将在任何序列化之前运行。该函数必须返回一个需要进行序列化保存的成员属性数组,并且只序列化该函数返回的这些成员属性. 该函数有两个作用: 第一. 在序列化之前,关闭对象可能具有的任何数据库连接等. 第二. 指定对象中需要被序列化的成员属性,如果某个属性比较大而不需要储存下来,可以不把它写进__sleep要返回的数组中,这样该属性就不会被序列化) + * @example + * @return + */ + public function __sleep() + { + } /** * - *创建一个swoole http server对象 + *反序列化函数调用的魔术方法(unserialize() 从字节流中创建了一个对象之后,马上检查是否具有__wakeup 的函数的存在。如果存在,__wakeup 立刻被调用。使用 __wakeup 的目的是重建在序列化中可能丢失的任何数据库连接以及处理其它重新初始化的任务) * @example - * @param string $host 创建一个swoole http server对象 - * @param int $port 创建一个swoole http server对象 - * @param int $mode 创建一个swoole http server对象 - * @param int $sock_type 创建一个swoole http server对象 * @return */ - public function __construct($host, $port, $mode, $sock_type) + public function __wakeup() { + } /** * - *监听一个新的Server端口,此方法是addlistener的别名 + *swoole_server初始化方法 * @example - * @param string $host 监听一个新的Server端口,此方法是addlistener的别名 - * @param int $port 监听一个新的Server端口,此方法是addlistener的别名 - * @param int $sock_type 监听一个新的Server端口,此方法是addlistener的别名 + * @param string $host 主机IP + * @param int $port 端口 + * @param int $mode 运行模式 + * @param int $sock_type socket类型 * @return */ - public function listen($host, $port, $sock_type) + public function __construct(string $host, int $port, int $mode, int $sock_type) { + } /** * - *监听一个新的Server端口,此方法是addlistener的别名 + *析构函数 * @example - * @param string $host 监听一个新的Server端口,此方法是addlistener的别名 - * @param int $port 监听一个新的Server端口,此方法是addlistener的别名 - * @param int $sock_type 监听一个新的Server端口,此方法是addlistener的别名 * @return */ - public function addlistener($host, $port, $sock_type) + public function __destruct() { + } /** * - *设置选项 + *添加监听端口(是addlistener的别名) * @example - * @param array $settings 设置选项 + * @param string $host 监听的主机 + * @param int $port 监听的端口号 + * @param int $sock_type socket类型 + * @return + */ + public function listen(string $host, int $port, int $sock_type) + { + + } + + /** + * + *添加监听端口 + * @example + * @param string $host 监听的主机 + * @param int $port 监听的端口号 + * @param int $sock_type socket类型 + * @return + */ + public function addlistener(string $host, int $port, int $sock_type) + { + + } + + /** + * + *设置swoole_server运行时的参数 + * @example + * @param array $settings 配置选项 * @return */ public function set(Array $settings) { + } /** * *向客户端发送数据 * @example - * @param int $fd 向客户端发送数据 - * @param string $send_data 向客户端发送数据 - * @param int $reactor_id 向客户端发送数据 - * @return bool + * @param int $fd 连接句柄 + * @param string $send_data 发送的数据 + * @param int $reactor_id UDP服务器使用$fd保存客户端IP,$extraData保存server_fd和port + * @return */ - public function send($fd, $send_data, $reactor_id) + public function send(int $fd, string $send_data, int $reactor_id) { + } /** * - *向任意的客户端IP:PORT发送UDP数据包 + *向任意客户端发送UDP数据包 * @example - * @param string $ip 向任意的客户端IP:PORT发送UDP数据包 - * @param int $port 向任意的客户端IP:PORT发送UDP数据包 - * @param string $send_data 向任意的客户端IP:PORT发送UDP数据包 - * @param int $server_socket 向任意的客户端IP:PORT发送UDP数据包 - * @return bool + * @param string $ip IPv4字符串,如192.168.1.102。如果IP不合法会返回错误 + * @param int $port 为 1-65535的网络端口号,如果端口错误发送会失败 + * @param string $send_data 发送的数据内容,可以是文本或者二进制内容 + * @param int $server_socket 服务器可能会同时监听多个UDP端口,此参数可以指定使用哪个端口发送数据包 + * @return */ - public function sendto($ip, $port, $send_data, $server_socket) + public function sendto(string $ip, int $port, string $send_data, int $server_socket) { + } /** * - *阻塞地向客户端发送数据 + *阻塞的向客户端发送数据 * @example - * @param int $conn_fd 阻塞地向客户端发送数据 - * @param string $send_data 阻塞地向客户端发送数据 - * @return bool + * @param int $conn_fd 与客户端连接的句柄 + * @param string $send_data 发送的数据 + * @return */ - public function sendwait($conn_fd, $send_data) + public function sendwait(int $conn_fd, string $send_data) { + } /** * *检测fd对应的连接是否存在 * @example - * @param int $fd 检测fd对应的连接是否存在 - * @return bool + * @param int $fd 连接句柄 + * @return */ - public function exist($fd) + public function exist(int $fd) { + } /** * - *用于保护某些连接不被心跳线程切断 + *设置客户端连接为保护状态,不被心跳线程切断 * @example - * @param int $fd 用于保护某些连接不被心跳线程切断 - * @param bool $is_protected 用于保护某些连接不被心跳线程切断 + * @param int $fd 要设置保护状态的客户端连接fd + * @param boolean $is_protected 设置的状态,true表示保护状态,false表示不保护 * @return */ - public function protect($fd, $is_protected) + public function protect(int $fd, bool $is_protected) { + } /** * - *发送文件到TCP客户端连接 + *向客户端发送文件 * @example - * @param int $conn_fd 发送文件到TCP客户端连接 - * @param string $filename 发送文件到TCP客户端连接 - * @param int $offset 发送文件到TCP客户端连接 - * @return bool + * @param int $conn_fd 连接句柄 + * @param string $filename 文件名 + * @param int $offset 指定文件偏移量,可以从文件的某个位置起发送数据。默认为0,表示从文件头部开始发送 + * @param int $length 指定发送的长度,默认为文件尺寸 + * @return */ - public function sendfile($conn_fd, $filename, $offset) + public function sendfile(int $conn_fd, string $filename, int $offset, int $length) { + } /** * *关闭客户端连接 * @example - * @param int $fd 关闭客户端连接 - * @param bool $reset 关闭客户端连接 + * @param int $fd 连接句柄 + * @param boolean $reset 设置为true会强制关闭连接,丢弃发送队列中的数据 * @return */ - public function close($fd, $reset) + public function close(int $fd, bool $reset) { + } /** * - *连接确认 + *确认连接,与enable_delay_receive或wait_for_bind配合使用 * @example - * @param int $fd 连接确认 + * @param int $fd 连接句柄 * @return */ - public function confirm($fd) + public function confirm(int $fd) { + } /** * *停止接收数据 * @example - * @param int $fd 停止接收数据 + * @param int $fd 连接句柄 * @return */ - public function pause($fd) + public function pause(int $fd) { + } /** * - *恢复数据接收 + *恢复数据接收。与pause方法成对使用 * @example - * @param int $fd 恢复数据接收 + * @param int $fd 连接句柄 * @return */ - public function resume($fd) + public function resume(int $fd) { + } /** * - *投递一个异步任务到task_worker池中。此函数是非阻塞的,执行完毕会立即返回 + *投递一个任务到task_worker连接池中 * @example - * @param mixed $data 投递一个异步任务到task_worker池中。此函数是非阻塞的,执行完毕会立即返回 - * @param int $worker_id 投递一个异步任务到task_worker池中。此函数是非阻塞的,执行完毕会立即返回 - * @param callable $finish_callback 投递一个异步任务到task_worker池中。此函数是非阻塞的,执行完毕会立即返回 + * @param mixed $data 要投递的任务数据,可以为除资源类型之外的任意PHP变量 + * @param int $worker_id 可以制定要给投递给哪个task进程,传入ID即可 + * @param callable $finish_callback 完成后的回调函数 * @return */ - public function task($data, $worker_id, Callable $finish_callback) + public function task($data, int $worker_id, Callable $finish_callback) { + } /** * - *用于投递一个异步的任务到task进程池去执行。与task不同的是taskwait是阻塞等待的,直到任务完成或者超时返回。 + *以阻塞的形式投递一个任务到task_worker连接池中 * @example - * @param mixed $data 用于投递一个异步的任务到task进程池去执行。与task不同的是taskwait是阻塞等待的,直到任务完成或者超时返回。 - * @param float $timeout 用于投递一个异步的任务到task进程池去执行。与task不同的是taskwait是阻塞等待的,直到任务完成或者超时返回。 - * @param int $worker_id 用于投递一个异步的任务到task进程池去执行。与task不同的是taskwait是阻塞等待的,直到任务完成或者超时返回。 + * @param mixed $data 要投递的任务数据,可以为除资源类型之外的任意PHP变量 + * @param float $timeout 超时时间 + * @param int $worker_id 可以制定要给投递给哪个task进程,传入ID即可 * @return */ - public function taskwait($data, $timeout, $worker_id) + public function taskwait($data, float $timeout, int $worker_id) { + } /** * *并发执行多个Task * @example - * @param array $tasks 并发执行多个Task - * @param double $timeout 并发执行多个Task + * @param array $tasks 必须为数字索引数组,不支持关联索引数组,底层会遍历$tasks将任务逐个投递到Task进程 + * @param double $timeout 超时时间 * @return */ - public function taskWaitMulti(Array $tasks, $timeout) + public function taskWaitMulti(Array $tasks, double $timeout) + { + + } + + /** + * + *并发执行Task并进行协程调度 + * @example + * @param array $tasks 必须为数字索引数组,不支持关联索引数组,底层会遍历$tasks将任务逐个投递到Task进程 + * @param double $timeout 超时时间 + * @return array + */ + public function taskCo(Array $tasks, double $timeout): array { + } /** * - *此函数用于在task进程中通知worker进程,投递的任务已完成。此函数可以传递结果数据给worker进程 + *用于在task进程中通知worker进程任务已完成 * @example - * @param string $data 此函数用于在task进程中通知worker进程,投递的任务已完成。此函数可以传递结果数据给worker进程 + * @param mixed $data * @return */ public function finish($data) { + } /** * - *重启所有worker进程 + *重启所有工作进程 * @example * @return */ public function reload() { + } /** @@ -277,178 +555,197 @@ public function reload() */ public function shutdown() { + } /** * - *使当前worker进程停止运行,并立即触发onWorkerStop回调函数 + *停止当前worker进程 * @example - * @param int $worker_id 使当前worker进程停止运行,并立即触发onWorkerStop回调函数 + * @param int $worker_id 工作进程ID * @return */ - public function stop($worker_id) + public function stop(int $worker_id) { + } /** * - *获取最近一次操作错误的错误码。业务代码中可以根据错误码类型执行不同的逻辑。 + *获取最近一次操作错误的错误码 + *返回的错误码: + *1001 连接已经被Server端关闭了,出现这个错误一般是代码中已经执行了$serv->close()关闭了某个连接,但仍然调用$serv->send()向这个连接发送数据 * @example - * @return int + * @return */ public function getLastError() { + } /** * - *检测服务器所有连接,并找出已经超过约定时间的连接。如果指定if_close_connection,则自动关闭超时的连接。未指定仅返回连接的fd数组。 + *检测所有服务器连接,并找出已经超时的连接 * @example - * @param mixed $reactor_id + * @param boolean $reactor_id 是否关闭超时的连接,默认为true * @return */ - public function heartbeat($reactor_id) + public function heartbeat(bool $reactor_id) { + } /** * - *获取连接的信息 + *获取客户端连接信息 * @example - * @param int $fd 获取连接的信息 - * @param int $reactor_id 获取连接的信息 - * @return + * @param mixed $fd 连接句柄 + * @param int $reactor_id reactor线程id + * @return from_id */ - public function connection_info($fd, $reactor_id) + public function connection_info($fd, int $reactor_id): from_id { + } /** * - *用来遍历当前Server所有的客户端连接 + *用来遍历所有客户端连接 * @example - * @param int $start_fd 用来遍历当前Server所有的客户端连接 - * @param int $find_count 用来遍历当前Server所有的客户端连接 + * @param int $start_fd 起始fd + * @param int $find_count 每页取多少条 * @return */ - public function connection_list($start_fd, $find_count) + public function connection_list(int $start_fd, int $find_count) { + } /** * - *获取连接的信息 + *获取连接的信息,别名是swoole_server->connection_info * @example - * @param int $fd 获取连接的信息 - * @param int $reactor_id 获取连接的信息 + * @param mixed $fd 连接句柄 + * @param int $reactor_id reactor线程id * @return */ - public function getClientInfo($fd, $reactor_id) + public function getClientInfo($fd, int $reactor_id) { + } /** * - *用来遍历当前Server所有的客户端连接 + *用来遍历所有客户端连接(server->connection_list的别名) * @example - * @param int $start_fd 用来遍历当前Server所有的客户端连接 - * @param int $find_count 用来遍历当前Server所有的客户端连接 + * @param int $start_fd 起始fd + * @param int $find_count 每页取多少条 * @return */ - public function getClientList($start_fd, $find_count) + public function getClientList(int $start_fd, int $find_count) { + } /** * - *在指定的时间后执行函数 + *在指定时间后执行某个回调函数 * @example - * @param int $ms 在指定的时间后执行函数 - * @param callable $callback 在指定的时间后执行函数 - * @param array $param 在指定的时间后执行函数 + * @param int $ms 指定时间,单位为毫秒 + * @param callable $callback 回调函数 + * @param array $param 给回调函数传入的参数 * @return */ - public function after($ms, Callable $callback, Array $param) + public function after(int $ms, Callable $callback, Array $param) { + } /** * - *ick定时器,可以自定义回调函数 + *添加定时器 * @example - * @param int $ms ick定时器,可以自定义回调函数 - * @param callable $callback ick定时器,可以自定义回调函数 + * @param int $ms 指定时间,单位为毫秒 + * @param callable $callback 回调函数 * @return */ - public function tick($ms, Callable $callback) + public function tick(int $ms, Callable $callback) { + } /** * - *清除tick/after定时器,此函数是swoole_timer_clear的别名 + *清除定时器 * @example - * @param int $timer_id 清除tick/after定时器,此函数是swoole_timer_clear的别名 + * @param int $timer_id 定时器ID * @return */ - public function clearTimer($timer_id) + public function clearTimer(int $timer_id) { + } /** * - *延后执行一个PHP函数。Swoole底层会在EventLoop循环完成后执行此函数。此函数的目的是为了让一些PHP代码延后执行,程序优先处理IO事件 + *延迟执行一个PHP函数 * @example - * @param callable $callback 延后执行一个PHP函数。Swoole底层会在EventLoop循环完成后执行此函数。此函数的目的是为了让一些PHP代码延后执行,程序优先处理IO事件 + * @param callable $callback 执行的函数 * @return */ public function defer(Callable $callback) { + } /** * - *此函数可以向任意worker进程或者task进程发送消息。在非主进程和管理进程中可调用。收到消息的进程会触发onPipeMessage事件。 + *向任意worker进程或task进程发送消息 * @example - * @param int $dst_worker_id 此函数可以向任意worker进程或者task进程发送消息。在非主进程和管理进程中可调用。收到消息的进程会触发onPipeMessage事件。 - * @param string $data 此函数可以向任意worker进程或者task进程发送消息。在非主进程和管理进程中可调用。收到消息的进程会触发onPipeMessage事件。 + * @param int $dst_worker_id 目标worker的ID + * @param string $data 发送的消息 * @return */ - public function sendMessage($dst_worker_id, $data) + public function sendMessage(int $dst_worker_id, string $data) { + } /** * - *添加一个用户自定义的工作进程 + *添加一个自定义的工作进程 * @example - * @param object $process 添加一个用户自定义的工作进程 + * @param Swoole\Process $process 进程对象 * @return */ - public function addProcess($process) + public function addProcess(Swoole\Process $process) { + } /** * - *得到当前Server的活动TCP连接数,启动时间,accpet/close的总次数等信息 + *得到当前server的活动TCP连接数 + *array ( * @example - * @return array + * @return */ public function stats() { + } /** * - *将连接绑定一个用户定义的ID,可以设置dispatch_mode=5设置已此ID值进行hash固定分配。可以保证某一个UID的连接全部会分配到同一个Worker进程 + *将连接绑定到某个用户定义的ID * @example - * @param int $fd 将连接绑定一个用户定义的ID,可以设置dispatch_mode=5设置已此ID值进行hash固定分配。可以保证某一个UID的连接全部会分配到同一个Worker进程 - * @param int $uid 将连接绑定一个用户定义的ID,可以设置dispatch_mode=5设置已此ID值进行hash固定分配。可以保证某一个UID的连接全部会分配到同一个Worker进程 + * @param int $fd 连接句柄 + * @param int $uid 用户定义的ID * @return */ - public function bind($fd, $uid) + public function bind(int $fd, int $uid) { + } } diff --git a/src/Swoole/swoole_lock.php b/src/Swoole/swoole_lock.php index 5390f9f..1c7a949 100644 --- a/src/Swoole/swoole_lock.php +++ b/src/Swoole/swoole_lock.php @@ -1,35 +1,69 @@ lock一致,但lockwait可以设置超时时间 + * @example + * @param float $timeout 超时时间 + * @return + */ + public function lockwait(float $timeout) + { + } /** * - *加锁操作。与lock方法不同的是,trylock()不会阻塞,它会立即返回。当返回false时表示抢锁失败,有其他进程持有锁。返回true时表示加锁成功,此时可以修改共享变量。 + *非阻塞的加锁操作 * @example * @return */ public function trylock() { + } /** * - *加锁。lock_read方法仅可用在读写锁(SWOOLE_RWLOCK)和文件锁(SWOOLE_FILELOCK)中,表示仅仅锁定读。在持有读锁的过程中,其他进程依然可以获得读锁,可以继续发生读操作。但不能$lock->lock()或$lock->trylock(),这两个方法是获取独占锁的 + *锁定读 * @example * @return */ public function lock_read() { + } /** * - *加锁。此方法与lock_read相同,但是非阻塞的。调用会立即返回,必须检测返回值以确定是否拿到了锁 + *非阻塞式锁定读 * @example * @return */ public function trylock_read() { + } /** * - *释放锁 + *释放锁操作 * @example * @return */ public function unlock() { + } } diff --git a/src/Swoole/swoole_mmap.php b/src/Swoole/swoole_mmap.php index cbe8338..7f3b12f 100644 --- a/src/Swoole/swoole_mmap.php +++ b/src/Swoole/swoole_mmap.php @@ -1,26 +1,27 @@ '192.168.56.102', * 'user' => 'test', - * 'password' => 'test', - * 'database' => 'test', - * 'charset' => 'utf8', + * 'password' => 'test', + * 'database' => 'test', + * 'charset' => 'utf8', * ); - * $db->connect($server, function($db, $result){ - * if (!$result) { - * echo 'connect failed'; - * } - * }) - * @param array $server_config 异步连接到MySQL服务器 - * @param callable $callback 异步连接到MySQL服务器 + * 回调函数:function onConnect(swoole_mysql $db, bool $result); + * @param array $server_config 连接配置信息 + * @param callable $callback 连接成功的回调 * @return */ public function connect(Array $server_config, Callable $callback) { + + } + + /** + * + *启动事务 + * @example + * @param callable $callback 启动一个MySQL事务,事务启动成功会回调指定的函数 + * @return + */ + public function begin(Callable $callback) + { + + } + + /** + * + *提交事务 + * @example + * @param callable $callback 提交事务,当服务器返回响应时回调此函数 + * @return + */ + public function commit(Callable $callback) + { + + } + + /** + * + *回滚事务(必须先调用begin启动事务才能调用rollback否则底层会抛出异常) + * @example + * @param callable $callback 回滚完成后执行的回调 + * @return + */ + public function rollback(Callable $callback) + { + } /** * - *执行SQL查询 - * @example $db->query('select * from user', function($link, $result){ - * var_dump($result); - * }) - * @param string $sql 执行SQL查询 - * @param callable $callback 执行SQL查询 + *执行sql语句 + * @example + * 回调函数:function onSQLReady(swoole_mysqli $link, mixed $result); + * 注:执行失败,$result为false,读取$link对象的error属性获得错误信息,errno属性获得错误码 + * 执行成功,SQL为非查询语句,$result为true,读取$link对象的affected_rows属性获得影响的行数,insert_id属性获得Insert操作的自增ID + * 执行成功,SQL为查询语句,$result为结果数组 + * @param string $sql 要执行的SQL语句 + * @param callable $callback 执行成功后会回调此函数 * @return */ - public function query($sql, Callable $callback) + public function query(string $sql, Callable $callback) { + } /** * - *关闭MySQL连接 + *关闭mysql连接 * @example * @return */ public function close() { + + } + + /** + * + *获取当前服务器状态 + * @example + * @return int + */ + public function getState(): int + { + } /** * - *设置事件回调函数。目前仅支持onClose事件回调 + *设置事件回调函数(目前仅支持onClose事件回调) * @example - * @param string $event_name 设置事件回调函数。目前仅支持onClose事件回调 - * @param callable $callback 设置事件回调函数。目前仅支持onClose事件回调 + * @param String $event_name 事件名称(目前仅支持Close) + * @param callable $callback 连接关闭时回调此函数 * @return */ - public function on($event_name, Callable $callback) + public function on(String $event_name, Callable $callback) { + } } diff --git a/src/Swoole/swoole_mysql_coro.php b/src/Swoole/swoole_mysql_coro.php deleted file mode 100644 index 07ef417..0000000 --- a/src/Swoole/swoole_mysql_coro.php +++ /dev/null @@ -1,157 +0,0 @@ -on("Message", function ($pool, $message) {echo "Message: {$message} + * "; + * $pool->write("hello "); + * $pool->write("world "); + * $pool->write("\n"); + * }); + * $pool->listen('127.0.0.1', 8089); + * $pool->start(); + * + * @param string $data 写入的数据内容。可多次调用write,底层会在onMessage函数退出后将数据全部写入socket中,并close连接 + * @return + */ + public function write(string $data) + { + + } + + /** + * + *启动工作进程 + * @example + * @return bool + */ + public function start(): bool + { + + } + + /** + * + *获取当前工作进程对象 + * @example $workerNum = 10; + * $pool = new Swoole\Process\Pool($workerNum); + * $pool->on("WorkerStart", function ($pool, $workerId) { + * $process = $pool->getProcess(); + * $process->exec("/bin/sh", ["ls", '-l']); + * }); + * @return \Swoole\Process + */ + public function getProcess(): \Swoole\Process + { + + } + +} + diff --git a/src/Swoole/swoole_redis.php b/src/Swoole/swoole_redis.php index 0d2aeeb..b6c8dbb 100644 --- a/src/Swoole/swoole_redis.php +++ b/src/Swoole/swoole_redis.php @@ -1,23 +1,113 @@ - * $redis->connect('127.0.0.1', 6379); - * $redis->connect('127.0.0.1'); // port 6379 by default - * $redis->connect('127.0.0.1', 6379, 2.5); // 2.5 sec timeout. - * $redis->connect('/tmp/redis.sock'); // unix domain socket. - * - * @return bool - */ - public function connect() - { - } - - /** - * - *设置defer - * @example - * @return - */ - public function setDefer() - { - } - - /** - * - *获取当前defer - * @example - * @return - */ - public function getDefer() - { - } - - /** - * - * - * @example - * @return - */ - public function recv() - { - } - - /** - * - *Disconnects from the Redis instance, except when pconnect is used. - * @example - * @return - */ - public function close() - { - } - - /** - * - *Set the string value in argument as value of the key. - * @example - * @return bool - */ - public function set() - { - } - - /** - * - *Changes a single bit of a string. - * @example - *
-     * $redis->set('key', "*");     // ord("*") = 42 = 0x2f = "0010 1010"
-     * $redis->setBit('key', 5, 1); // returns 0
-     * $redis->setBit('key', 7, 1); // returns 0
-     * $redis->get('key');          // chr(0x2f) = "/" = b("0010 1111")
-     * 
- * @return int: - */ - public function setBit() - { - } - - /** - * - * - * @example - * @return - */ - public function setEx() - { - } - - /** - * - * - * @example - * @return - */ - public function psetEx() - { - } - - /** - * - *Set the list at index with the new value. - * @example - *
-     * $redis->rPush('key1', 'A');
-     * $redis->rPush('key1', 'B');
-     * $redis->rPush('key1', 'C');  // key1 => [ 'A', 'B', 'C' ]
-     * $redis->lGet('key1', 0);     // 'A'
-     * $redis->lSet('key1', 0, 'X');
-     * $redis->lGet('key1', 0);     // 'X'
-     * 
- * @return is - */ - public function lSet() - { - } - - /** - * - *Get the value related to the specified key - * @example $redis->get('key'); - * @return string|bool: - */ - public function get() - { - } - - /** - * - * - * @example - * @return - */ - public function mGet() - { - } - - /** - * - *Remove specified keys. - * @example - *
-     * $redis->set('key1', 'val1');
-     * $redis->set('key2', 'val2');
-     * $redis->set('key3', 'val3');
-     * $redis->set('key4', 'val4');
-     * $redis->delete('key1', 'key2');          // return 2
-     * $redis->delete(array('key3', 'key4'));   // return 2
-     * 
- * @return int - */ - public function del() - { - } - - /** - * - *Removes a values from the hash stored at key. - *If the hash table doesn't exist, or the key doesn't exist, FALSE is returned. - * @example - *
-     * $redis->hMSet('h',
-     * array(
-     * 'f1' => 'v1',
-     * 'f2' => 'v2',
-     * 'f3' => 'v3',
-     * 'f4' => 'v4',
-     * ));
-     * var_dump( $redis->hDel('h', 'f1') );        // int(1)
-     * var_dump( $redis->hDel('h', 'f2', 'f3') );  // int(2)
-     * s
-     * var_dump( $redis->hGetAll('h') );
-     * //// Output:
-     * //  array(1) {
-     * //    ["f4"]=> string(2) "v4"
-     * //  }
-     * 
- * @return int - */ - public function hDel() - { - } - - /** - * - *Adds a value to the hash stored at key. If this value is already in the hash, FALSE is returned. - * @example - *
-     * $redis->delete('h')
-     * $redis->hSet('h', 'key1', 'hello');  // 1, 'key1' => 'hello' in the hash at "h"
-     * $redis->hGet('h', 'key1');           // returns "hello"
-     * $redis->hSet('h', 'key1', 'plop');   // 0, value was replaced.
-     * $redis->hGet('h', 'key1');           // returns "plop"
-     * 
- * @return 0 - */ - public function hSet() - { - } - - /** - * - * - * @example - * @return - */ - public function hMSet() - { - } - - /** - * - *Adds a value to the hash stored at key only if this field isn't already in the hash. - * @example - *
-     * $redis->delete('h')
-     * $redis->hSetNx('h', 'key1', 'hello'); // TRUE, 'key1' => 'hello' in the hash at "h"
-     * $redis->hSetNx('h', 'key1', 'world'); // FALSE, 'key1' => 'hello' in the hash at "h". No change since the field
-     * wasn't replaced.
-     * 
- * @return bool - */ - public function hSetNx() - { - } - - /** - * - * - * @example - * @return int - */ - public function delete() - { - } - - /** - * - * - * @example - * @return - */ - public function mSet() - { - } - - /** - * - * - * @example - * @return - */ - public function mSetNx() - { - } - - /** - * - * - * @example - * @return - */ - public function getKeys() - { - } - - /** - * - *Returns the keys that match a certain pattern. - * @example - *
-     * $allKeys = $redis->keys('*');   // all keys will match this.
-     * $keyWithUserPrefix = $redis->keys('user*');
-     * 
- * @return array - */ - public function keys() - { - } - - /** - * - *Verify if the specified key exists. - * @example - *
-     * $redis->set('key', 'value');
-     * $redis->exists('key');               //  TRUE
-     * $redis->exists('NonExistingKey');    // FALSE
-     * 
- * @return bool: - */ - public function exists() - { - } - - /** - * - *Returns the type of data pointed by a given key. - * @example $redis->type('key'); - * @return - - */ - public function type() - { - } - - /** - * - * - * @example - * @return - */ - public function strLen() - { - } - - /** - * - *Returns and removes the first element of the list. - * @example - *
-     * $redis->rPush('key1', 'A');
-     * $redis->rPush('key1', 'B');
-     * $redis->rPush('key1', 'C');  // key1 => [ 'A', 'B', 'C' ]
-     * $redis->lPop('key1');        // key1 => [ 'B', 'C' ]
-     * 
- * @return string - */ - public function lPop() - { - } - - /** - * - *Is a blocking lPop primitive. If at least one of the lists contains at least one element, - *the element will be popped from the head of the list and returned to the caller. - *Il all the list identified by the keys passed in arguments are empty, blPop will block - *during the specified timeout until an element is pushed to one of those lists. This element will be popped. - * @example - *
-     * // Non blocking feature
-     * $redis->lPush('key1', 'A');
-     * $redis->delete('key2');
-     * $redis->blPop('key1', 'key2', 10); // array('key1', 'A')
-     * // OR
-     * $redis->blPop(array('key1', 'key2'), 10); // array('key1', 'A')
-     * $redis->brPop('key1', 'key2', 10); // array('key1', 'A')
-     * // OR
-     * $redis->brPop(array('key1', 'key2'), 10); // array('key1', 'A')
-     * // Blocking feature
-     * // process 1
-     * $redis->delete('key1');
-     * $redis->blPop('key1', 10);
-     * // blocking for 10 seconds
-     * // process 2
-     * $redis->lPush('key1', 'A');
-     * // process 1
-     * // array('key1', 'A') is returned
-     * 
- * @return array - */ - public function blPop() - { - } - - /** - * - *Returns and removes the last element of the list. - * @example - *
-     * $redis->rPush('key1', 'A');
-     * $redis->rPush('key1', 'B');
-     * $redis->rPush('key1', 'C');  // key1 => [ 'A', 'B', 'C' ]
-     * $redis->rPop('key1');        // key1 => [ 'A', 'B' ]
-     * 
- * @return string - */ - public function rPop() - { - } - - /** - * - *Is a blocking rPop primitive. If at least one of the lists contains at least one element, - *the element will be popped from the head of the list and returned to the caller. - *Il all the list identified by the keys passed in arguments are empty, brPop will - *block during the specified timeout until an element is pushed to one of those lists. T - *his element will be popped. - * @example - *
-     * // Non blocking feature
-     * $redis->lPush('key1', 'A');
-     * $redis->delete('key2');
-     * $redis->blPop('key1', 'key2', 10); // array('key1', 'A')
-     * // OR
-     * $redis->blPop(array('key1', 'key2'), 10); // array('key1', 'A')
-     * $redis->brPop('key1', 'key2', 10); // array('key1', 'A')
-     * // OR
-     * $redis->brPop(array('key1', 'key2'), 10); // array('key1', 'A')
-     * // Blocking feature
-     * // process 1
-     * $redis->delete('key1');
-     * $redis->blPop('key1', 10);
-     * // blocking for 10 seconds
-     * // process 2
-     * $redis->lPush('key1', 'A');
-     * // process 1
-     * // array('key1', 'A') is returned
-     * 
- * @return array - */ - public function brPop() - { - } - - /** - * - * - * @example - * @return - */ - public function bRPopLPush() - { - } - - /** - * - * - * @example - * @return - */ - public function lSize() - { - } - - /** - * - *Returns the size of a list identified by Key. If the list didn't exist or is empty, - *the command returns 0. If the data type identified by Key is not a list, the command return FALSE. - * @example - *
-     * $redis->rPush('key1', 'A');
-     * $redis->rPush('key1', 'B');
-     * $redis->rPush('key1', 'C');  // key1 => [ 'A', 'B', 'C' ]
-     * $redis->lLen('key1');       // 3
-     * $redis->rPop('key1');
-     * $redis->lLen('key1');       // 2
-     * 
- * @return bool - */ - public function lLen() - { - } - - /** - * - * - * @example - * @return - */ - public function sSize() - { - } - - /** - * - * - * @example - * @return - */ - public function scard() - { - } - - /** - * - *Removes and returns a random element from the set value at Key. - * @example - *
-     * $redis->sAdd('key1' , 'set1');
-     * $redis->sAdd('key1' , 'set2');
-     * $redis->sAdd('key1' , 'set3');   // 'key1' => {'set3', 'set1', 'set2'}
-     * $redis->sPop('key1');            // 'set1', 'key1' => {'set3', 'set2'}
-     * $redis->sPop('key1');            // 'set3', 'key1' => {'set2'}
-     * 
- * @return bool - */ - public function sPop() - { - } - - /** - * - *Returns the contents of a set. - * @example - *
-     * $redis->delete('s');
-     * $redis->sAdd('s', 'a');
-     * $redis->sAdd('s', 'b');
-     * $redis->sAdd('s', 'a');
-     * $redis->sAdd('s', 'c');
-     * var_dump($redis->sMembers('s'));
-     * //array(3) {
-     * //  [0]=>
-     * //  string(1) "c"
-     * //  [1]=>
-     * //  string(1) "a"
-     * //  [2]=>
-     * //  string(1) "b"
-     * //}
-     * // The order is random and corresponds to redis' own internal representation of the set structure.
-     * 
- * @return array - */ - public function sMembers() - { - } - - /** - * - * - * @example - * @return array - */ - public function sGetMembers() - { - } - - /** - * - *Returns a random element(s) from the set value at Key, without removing it. - * @example - *
-     * $redis->sAdd('key1' , 'one');
-     * $redis->sAdd('key1' , 'two');
-     * $redis->sAdd('key1' , 'three');              // 'key1' => {'one', 'two', 'three'}
-     * var_dump( $redis->sRandMember('key1') );     // 'key1' => {'one', 'two', 'three'}
-     * // string(5) "three"
-     * var_dump( $redis->sRandMember('key1', 2) );  // 'key1' => {'one', 'two', 'three'}
-     * // array(2) {
-     * //   [0]=> string(2) "one"
-     * //   [1]=> string(2) "three"
-     * // }
-     * 
- * @return bool - */ - public function sRandMember() - { - } - - /** - * - *Remove the expiration timer from a key. - * @example $redis->persist('key'); - * @return bool: - */ - public function persist() - { - } - - /** - * - *Returns the time to live left for a given key, in seconds. If the key doesn't exist, FALSE is returned. - * @example $redis->ttl('key'); - * @return int, - */ - public function ttl() - { - } - - /** - * - *Returns a time to live left for a given key, in milliseconds. - * @example $redis->pttl('key'); - * @return int - */ - public function pttl() - { - } - - /** - * - *Returns the cardinality of an ordered set. - * @example - *
-     * $redis->zAdd('key', 0, 'val0');
-     * $redis->zAdd('key', 2, 'val2');
-     * $redis->zAdd('key', 10, 'val10');
-     * $redis->zCard('key');            // 3
-     * 
- * @return int - */ - public function zCard() - { - } - - /** - * - * - * @example - * @return - */ - public function zSize() - { - } - - /** - * - *Returns the length of a hash, in number of items - * @example - *
-     * $redis->delete('h')
-     * $redis->hSet('h', 'key1', 'hello');
-     * $redis->hSet('h', 'key2', 'plop');
-     * $redis->hLen('h'); // returns 2
-     * 
- * @return int - */ - public function hLen() - { - } - - /** - * - *Returns the keys in a hash, as an array of strings. - * @example - *
-     * $redis->delete('h');
-     * $redis->hSet('h', 'a', 'x');
-     * $redis->hSet('h', 'b', 'y');
-     * $redis->hSet('h', 'c', 'z');
-     * $redis->hSet('h', 'd', 't');
-     * var_dump($redis->hKeys('h'));
-     * // Output:
-     * // array(4) {
-     * // [0]=>
-     * // string(1) "a"
-     * // [1]=>
-     * // string(1) "b"
-     * // [2]=>
-     * // string(1) "c"
-     * // [3]=>
-     * // string(1) "d"
-     * // }
-     * // The order is random and corresponds to redis' own internal representation of the set structure.
-     * 
- * @return array - */ - public function hKeys() - { - } - - /** - * - *Returns the values in a hash, as an array of strings. - * @example - *
-     * $redis->delete('h');
-     * $redis->hSet('h', 'a', 'x');
-     * $redis->hSet('h', 'b', 'y');
-     * $redis->hSet('h', 'c', 'z');
-     * $redis->hSet('h', 'd', 't');
-     * var_dump($redis->hVals('h'));
-     * // Output
-     * // array(4) {
-     * //   [0]=>
-     * //   string(1) "x"
-     * //   [1]=>
-     * //   string(1) "y"
-     * //   [2]=>
-     * //   string(1) "z"
-     * //   [3]=>
-     * //   string(1) "t"
-     * // }
-     * // The order is random and corresponds to redis' own internal representation of the set structure.
-     * 
- * @return array - */ - public function hVals() - { - } - - /** - * - *Returns the whole hash, as an array of strings indexed by strings. - * @example - *
-     * $redis->delete('h');
-     * $redis->hSet('h', 'a', 'x');
-     * $redis->hSet('h', 'b', 'y');
-     * $redis->hSet('h', 'c', 'z');
-     * $redis->hSet('h', 'd', 't');
-     * var_dump($redis->hGetAll('h'));
-     * // Output:
-     * // array(4) {
-     * //   ["a"]=>
-     * //   string(1) "x"
-     * //   ["b"]=>
-     * //   string(1) "y"
-     * //   ["c"]=>
-     * //   string(1) "z"
-     * //   ["d"]=>
-     * //   string(1) "t"
-     * // }
-     * // The order is random and corresponds to redis' own internal representation of the set structure.
-     * 
- * @return array - */ - public function hGetAll() - { - } - - /** - * - * - * @example - * @return - */ - public function debug() - { - } - - /** - * - *Restore a key from the result of a DUMP operation. - * @example - *
-     * $redis->set('foo', 'bar');
-     * $val = $redis->dump('foo');
-     * $redis->restore('bar', 0, $val); // The key 'bar', will now be equal to the key 'foo'
-     * 
- * @return - */ - public function restore() - { - } - - /** - * - *Dump a key out of a redis database, the value of which can later be passed into redis using the RESTORE command. - *The data that comes out of DUMP is a binary representation of the key as Redis stores it. - * @example - *
-     * $redis->set('foo', 'bar');
-     * $val = $redis->dump('foo'); // $val will be the Redis encoded key value
-     * 
- * @return string - */ - public function dump() - { - } - - /** - * - * - * @example - * @return - */ - public function renameKey() - { - } - - /** - * - *Renames a key. - * @example - *
-     * $redis->set('x', '42');
-     * $redis->rename('x', 'y');
-     * $redis->get('y');   // → 42
-     * $redis->get('x');   // → `FALSE`
-     * 
- * @return bool: - */ - public function rename() - { - } - - /** - * - *Renames a key. - * @example - *
-     * $redis->set('x', '42');
-     * $redis->rename('x', 'y');
-     * $redis->get('y');   // → 42
-     * $redis->get('x');   // → `FALSE`
-     * 
- * @return bool: - */ - public function renameNx() - { - } - - /** - * - *Pops a value from the tail of a list, and pushes it to the front of another list. - *Also return this value. - * @example - *
-     * $redis->delete('x', 'y');
-     * $redis->lPush('x', 'abc');
-     * $redis->lPush('x', 'def');
-     * $redis->lPush('y', '123');
-     * $redis->lPush('y', '456');
-     * // move the last of x to the front of y.
-     * var_dump($redis->rpoplpush('x', 'y'));
-     * var_dump($redis->lRange('x', 0, -1));
-     * var_dump($redis->lRange('y', 0, -1));
-     * //Output:
-     * //
-     * //string(3) "abc"
-     * //array(1) {
-     * //  [0]=>
-     * //  string(3) "def"
-     * //}
-     * //array(3) {
-     * //  [0]=>
-     * //  string(3) "abc"
-     * //  [1]=>
-     * //  string(3) "456"
-     * //  [2]=>
-     * //  string(3) "123"
-     * //}
-     * 
- * @return string - */ - public function rpoplpush() - { - } - - /** - * - *Returns a random key. - * @example - *
-     * $key = $redis->randomKey();
-     * $surprise = $redis->get($key);  // who knows what's in there.
-     * 
- * @return string: - */ - public function randomKey() - { - } - - /** - * - *Check the current connection status - * @example - * @return string - */ - public function ping() - { - } - - /** - * - *Authenticate the connection using a password. - *Warning: The password is sent in plain-text over the network. - * @example $redis->auth('foobared'); - * @return bool: - */ - public function auth() - { - } - - /** - * - * - * @example - * @return - */ - public function unwatch() - { - } - - /** - * - *Watches a key for modifications by another client. If the key is modified between WATCH and EXEC, - *the MULTI/EXEC transaction will fail (return FALSE). unwatch cancels all the watching of all keys by this client. - * @example - *
-     * $redis->watch('x');
-     * // long code here during the execution of which other clients could well modify `x`
-     * $ret = $redis->multi()
-     * ->incr('x')
-     * ->exec();
-     * // $ret = FALSE if x has been modified between the call to WATCH and the call to EXEC.
-     * 
- * @return - */ - public function watch() - { - } - - /** - * - *Performs a synchronous save. - * @example $redis->save(); - * @return If - */ - public function save() - { - } - - /** - * - * - * @example - * @return - */ - public function bgSave() - { - } - - /** - * - *Returns the timestamp of the last disk save. - * @example $redis->lastSave(); - * @return int: - */ - public function lastSave() - { - } - - /** - * - *Removes all entries from the current database. - * @example $redis->flushDB(); - * @return bool: - */ - public function flushDB() - { - } - - /** - * - *Removes all entries from all databases. - * @example $redis->flushAll(); - * @return bool: - */ - public function flushAll() - { - } - - /** - * - *Returns the current database's size. - * @example - *
-     * $count = $redis->dbSize();
-     * echo "Redis has $count keys\n";
-     * 
- * @return int: - */ - public function dbSize() - { - } - - /** - * - *Starts the background rewrite of AOF (Append-Only File) - * @example $redis->bgrewriteaof(); - * @return bool: - */ - public function bgrewriteaof() - { - } - - /** - * - *Return the current Redis server time. - * @example - *
-     * var_dump( $redis->time() );
-     * // array(2) {
-     * //   [0] => string(10) "1342364352"
-     * //   [1] => string(6) "253002"
-     * // }
-     * 
- * @return unix - */ - public function time() - { - } - - /** - * - * - * @example - * @return - */ - public function role() - { - } - - /** - * - *Changes a substring of a larger string. - * @example - *
-     * $redis->set('key', 'Hello world');
-     * $redis->setRange('key', 6, "redis"); // returns 11
-     * $redis->get('key');                  // "Hello redis"
-     * 
- * @return string: - */ - public function setRange() - { - } - - /** - * - * - * @example - * @return - */ - public function setNx() - { - } - - /** - * - *Sets a value and returns the previous entry at that key. - * @example - *
-     * $redis->set('x', '42');
-     * $exValue = $redis->getSet('x', 'lol');   // return '42', replaces x by 'lol'
-     * $newValue = $redis->get('x')'            // return 'lol'
-     * 
- * @return string - */ - public function getSet() - { - } - - /** - * - *Append specified string to the string stored in specified key. - * @example - *
-     * $redis->set('key', 'value1');
-     * $redis->append('key', 'value2'); // 12
-     * $redis->get('key');              // 'value1value2'
-     * 
- * @return int: - */ - public function append() - { - } - - /** - * - *Adds the string value to the head (left) of the list if the list exists. - * @example - *
-     * $redis->delete('key1');
-     * $redis->lPushx('key1', 'A');     // returns 0
-     * $redis->lPush('key1', 'A');      // returns 1
-     * $redis->lPushx('key1', 'B');     // returns 2
-     * $redis->lPushx('key1', 'C');     // returns 3
-     * // key1 now points to the following list: [ 'A', 'B', 'C' ]
-     * 
- * @return int - */ - public function lPushx() - { - } - - /** - * - *Adds the string values to the head (left) of the list. Creates the list if the key didn't exist. - *If the key exists and is not a list, FALSE is returned. - * @example - *
-     * $redis->lPush('l', 'v1', 'v2', 'v3', 'v4')   // int(4)
-     * var_dump( $redis->lRange('l', 0, -1) );
-     * //// Output:
-     * // array(4) {
-     * //   [0]=> string(2) "v4"
-     * //   [1]=> string(2) "v3"
-     * //   [2]=> string(2) "v2"
-     * //   [3]=> string(2) "v1"
-     * // }
-     * 
- * @return int - */ - public function lPush() - { - } - - /** - * - *Adds the string values to the tail (right) of the list. Creates the list if the key didn't exist. - *If the key exists and is not a list, FALSE is returned. - * @example - *
-     * $redis->rPush('l', 'v1', 'v2', 'v3', 'v4');    // int(4)
-     * var_dump( $redis->lRange('l', 0, -1) );
-     * //// Output:
-     * // array(4) {
-     * //   [0]=> string(2) "v1"
-     * //   [1]=> string(2) "v2"
-     * //   [2]=> string(2) "v3"
-     * //   [3]=> string(2) "v4"
-     * // }
-     * 
- * @return int - */ - public function rPush() - { - } - - /** - * - *Adds the string value to the tail (right) of the list if the ist exists. FALSE in case of Failure. - * @example - *
-     * $redis->delete('key1');
-     * $redis->rPushx('key1', 'A'); // returns 0
-     * $redis->rPush('key1', 'A'); // returns 1
-     * $redis->rPushx('key1', 'B'); // returns 2
-     * $redis->rPushx('key1', 'C'); // returns 3
-     * // key1 now points to the following list: [ 'A', 'B', 'C' ]
-     * 
- * @return int - */ - public function rPushx() - { - } - - /** - * - * - * @example - * @return - */ - public function sContains() - { - } - - /** - * - * - * @example - * @return - */ - public function sismember() - { - } - - /** - * - *Returns the score of a given member in the specified sorted set. - * @example - *
-     * $redis->zAdd('key', 2.5, 'val2');
-     * $redis->zScore('key', 'val2'); // 2.5
-     * 
- * @return - */ - public function zScore() - { - } - - /** - * - *Returns the rank of a given member in the specified sorted set, starting at 0 for the item - *with the smallest score. zRevRank starts at 0 for the item with the largest score. - * @example - *
-     * $redis->delete('z');
-     * $redis->zAdd('key', 1, 'one');
-     * $redis->zAdd('key', 2, 'two');
-     * $redis->zRank('key', 'one');     // 0
-     * $redis->zRank('key', 'two');     // 1
-     * $redis->zRevRank('key', 'one');  // 1
-     * $redis->zRevRank('key', 'two');  // 0
-     * 
- * @return int - */ - public function zRank() - { - } - - /** - * - * - * @example - * @return int - */ - public function zRevRank() - { - } - - /** - * - *Gets a value from the hash stored at key. - *If the hash table doesn't exist, or the key doesn't exist, FALSE is returned. - * @example - * @return string - */ - public function hGet() - { - } - - /** - * - *Retirieve the values associated to the specified fields in the hash. - * @example - *
-     * $redis->delete('h');
-     * $redis->hSet('h', 'field1', 'value1');
-     * $redis->hSet('h', 'field2', 'value2');
-     * $redis->hmGet('h', array('field1', 'field2')); // returns array('field1' => 'value1', 'field2' => 'value2')
-     * 
- * @return with - */ - public function hMGet() - { - } - - /** - * - *Verify if the specified member exists in a key. - * @example - *
-     * $redis->hSet('h', 'a', 'x');
-     * $redis->hExists('h', 'a');               //  TRUE
-     * $redis->hExists('h', 'NonExistingKey');  // FALSE
-     * 
- * @return bool: - */ - public function hExists() - { - } - - /** - * - *Publish messages to channels. Warning: this function will probably change in the future. - * @example $redis->publish('chan-1', 'hello, world!'); // send message. - * @return int - */ - public function publish() - { - } - - /** - * - *Increments the score of a member from a sorted set by a given amount. - * @example - *
-     * $redis->delete('key');
-     * $redis->zIncrBy('key', 2.5, 'member1');  // key or member1 didn't exist, so member1's score is to 0
-     * // before the increment and now has the value 2.5
-     * $redis->zIncrBy('key', 1, 'member1');    // 3.5
-     * 
- * @return float - */ - public function zIncrBy() - { - } - - /** - * - *Adds the specified member with a given score to the sorted set stored at key. - * @example - *
-     * 
-     * $redis->zAdd('z', 1, 'v2', 2, 'v2', 3, 'v3', 4, 'v4' );  // int(2)
-     * $redis->zRem('z', 'v2', 'v3');                           // int(2)
-     * var_dump( $redis->zRange('z', 0, -1) );
-     * //// Output:
-     * // array(2) {
-     * //   [0]=> string(2) "v1"
-     * //   [1]=> string(2) "v4"
-     * // }
-     * 
- *
- * @return int - */ - public function zAdd() - { - } - - /** - * - * - * @example - * @return - */ - public function zDeleteRangeByScore() - { - } - - /** - * - *Deletes the elements of the sorted set stored at the specified key which have scores in the range [start,end]. - * @example - *
-     * $redis->zAdd('key', 0, 'val0');
-     * $redis->zAdd('key', 2, 'val2');
-     * $redis->zAdd('key', 10, 'val10');
-     * $redis->zRemRangeByScore('key', 0, 3); // 2
-     * 
- * @return int - */ - public function zRemRangeByScore() - { - } - - /** - * - *Returns the number of elements of the sorted set stored at the specified key which have - *scores in the range [start,end]. Adding a parenthesis before start or end excludes it - *from the range. +inf and -inf are also valid limits. - * @example - *
-     * $redis->zAdd('key', 0, 'val0');
-     * $redis->zAdd('key', 2, 'val2');
-     * $redis->zAdd('key', 10, 'val10');
-     * $redis->zCount('key', 0, 3); // 2, corresponding to array('val0', 'val2')
-     * 
- * @return int - */ - public function zCount() - { - } - - /** - * - *Returns a range of elements from the ordered set stored at the specified key, - *with values in the range [start, end]. start and stop are interpreted as zero-based indices: - *0 the first element, - *1 the second ... - *-1 the last element, - *-2 the penultimate ... - * @example - *
-     * $redis->zAdd('key1', 0, 'val0');
-     * $redis->zAdd('key1', 2, 'val2');
-     * $redis->zAdd('key1', 10, 'val10');
-     * $redis->zRange('key1', 0, -1); // array('val0', 'val2', 'val10')
-     * // with scores
-     * $redis->zRange('key1', 0, -1, true); // array('val0' => 0, 'val2' => 2, 'val10' => 10)
-     * 
- * @return array - */ - public function zRange() - { - } - - /** - * - *Returns the elements of the sorted set stored at the specified key in the range [start, end] - *in reverse order. start and stop are interpretated as zero-based indices: - *0 the first element, - *1 the second ... - *-1 the last element, - *-2 the penultimate ... - * @example - *
-     * $redis->zAdd('key', 0, 'val0');
-     * $redis->zAdd('key', 2, 'val2');
-     * $redis->zAdd('key', 10, 'val10');
-     * $redis->zRevRange('key', 0, -1); // array('val10', 'val2', 'val0')
-     * // with scores
-     * $redis->zRevRange('key', 0, -1, true); // array('val10' => 10, 'val2' => 2, 'val0' => 0)
-     * 
- * @return array - */ - public function zRevRange() - { - } - - /** - * - *Returns the elements of the sorted set stored at the specified key which have scores in the - *range [start,end]. Adding a parenthesis before start or end excludes it from the range. - *+inf and -inf are also valid limits. - * @example - *
-     * $redis->zAdd('key', 0, 'val0');
-     * $redis->zAdd('key', 2, 'val2');
-     * $redis->zAdd('key', 10, 'val10');
-     * $redis->zRangeByScore('key', 0, 3);                                          // array('val0', 'val2')
-     * $redis->zRangeByScore('key', 0, 3, array('withscores' => TRUE);              // array('val0' => 0, 'val2' => 2)
-     * $redis->zRangeByScore('key', 0, 3, array('limit' => array(1, 1));                        // array('val2' => 2)
-     * $redis->zRangeByScore('key', 0, 3, array('limit' => array(1, 1));                        // array('val2')
-     * $redis->zRangeByScore('key', 0, 3, array('withscores' => TRUE, 'limit' => array(1, 1));  // array('val2' => 2)
-     * 
- * @return array - */ - public function zRangeByScore() - { - } - - /** - * - * - * @example - * @return - */ - public function zRevRangeByScore() - { - } - - /** - * - *Returns a lexigraphical range of members in a sorted set, assuming the members have the same score. The - *min and max values are required to start with '(' (exclusive), '[' (inclusive), or be exactly the values - *'-' (negative inf) or '+' (positive inf). The command must be called with either three *or* five - *arguments or will return FALSE. - * @example - *
-     * foreach (array('a', 'b', 'c', 'd', 'e', 'f', 'g') as $char) {
-     * $redis->zAdd('key', $char);
-     * }
-     * $redis->zRangeByLex('key', '-', '[c'); // array('a', 'b', 'c')
-     * $redis->zRangeByLex('key', '-', '(c'); // array('a', 'b')
-     * $redis->zRangeByLex('key', '-', '[c'); // array('b', 'c')
-     * 
- * @return array - */ - public function zRangeByLex() - { - } - - /** - * - * - * @example - * @return - */ - public function zRevRangeByLex() - { - } - - /** - * - *Creates an intersection of sorted sets given in second argument. - *The result of the union will be stored in the sorted set defined by the first argument. - *The third optional argument defines weights to apply to the sorted sets in input. - *In this case, the weights will be multiplied by the score of each element in the sorted set - *before applying the aggregation. The forth argument defines the AGGREGATE option which - *specify how the results of the union are aggregated. - * @example - *
-     * $redis->delete('k1');
-     * $redis->delete('k2');
-     * $redis->delete('k3');
-     * $redis->delete('ko1');
-     * $redis->delete('ko2');
-     * $redis->delete('ko3');
-     * $redis->delete('ko4');
-     * $redis->zAdd('k1', 0, 'val0');
-     * $redis->zAdd('k1', 1, 'val1');
-     * $redis->zAdd('k1', 3, 'val3');
-     * $redis->zAdd('k2', 2, 'val1');
-     * $redis->zAdd('k2', 3, 'val3');
-     * $redis->zInter('ko1', array('k1', 'k2'));               // 2, 'ko1' => array('val1', 'val3')
-     * $redis->zInter('ko2', array('k1', 'k2'), array(1, 1));  // 2, 'ko2' => array('val1', 'val3')
-     * // Weighted zInter
-     * $redis->zInter('ko3', array('k1', 'k2'), array(1, 5), 'min'); // 2, 'ko3' => array('val1', 'val3')
-     * $redis->zInter('ko4', array('k1', 'k2'), array(1, 5), 'max'); // 2, 'ko4' => array('val3', 'val1')
-     * 
- * @return int - */ - public function zInter() - { - } - - /** - * - * - * @example - * @return - */ - public function zinterstore() - { - } - - /** - * - *Creates an union of sorted sets given in second argument. - *The result of the union will be stored in the sorted set defined by the first argument. - *The third optionnel argument defines weights to apply to the sorted sets in input. - *In this case, the weights will be multiplied by the score of each element in the sorted set - *before applying the aggregation. The forth argument defines the AGGREGATE option which - *specify how the results of the union are aggregated. - * @example - *
-     * $redis->delete('k1');
-     * $redis->delete('k2');
-     * $redis->delete('k3');
-     * $redis->delete('ko1');
-     * $redis->delete('ko2');
-     * $redis->delete('ko3');
-     * $redis->zAdd('k1', 0, 'val0');
-     * $redis->zAdd('k1', 1, 'val1');
-     * $redis->zAdd('k2', 2, 'val2');
-     * $redis->zAdd('k2', 3, 'val3');
-     * $redis->zUnion('ko1', array('k1', 'k2')); // 4, 'ko1' => array('val0', 'val1', 'val2', 'val3')
-     * // Weighted zUnion
-     * $redis->zUnion('ko2', array('k1', 'k2'), array(1, 1)); // 4, 'ko2' => array('val0', 'val1', 'val2', 'val3')
-     * $redis->zUnion('ko3', array('k1', 'k2'), array(5, 1)); // 4, 'ko3' => array('val0', 'val2', 'val3', 'val1')
-     * 
- * @return int - */ - public function zUnion() - { - } - - /** - * - * - * @example - * @return - */ - public function zunionstore() - { - } - - /** - * - *Increment the number stored at key by one. If the second argument is filled, it will be used as the integer - *value of the increment. - * @example - *
-     * $redis->incr('key1');        // key1 didn't exists, set to 0 before the increment and now has the value 1
-     * $redis->incr('key1');        // 2
-     * $redis->incr('key1');        // 3
-     * $redis->incr('key1');        // 4
-     * $redis->incrBy('key1', 10);  // 14
-     * 
- * @return int - */ - public function incrBy() - { - } - - /** - * - *Increments the value of a member from a hash by a given amount. - * @example - *
-     * $redis->delete('h');
-     * $redis->hIncrBy('h', 'x', 2); // returns 2: h[x] = 2 now.
-     * $redis->hIncrBy('h', 'x', 1); // h[x] ← 2 + 1. Returns 3
-     * 
- * @return int - */ - public function hIncrBy() - { - } - - /** - * - *Increment the number stored at key by one. - * @example - *
-     * $redis->incr('key1'); // key1 didn't exists, set to 0 before the increment and now has the value 1
-     * $redis->incr('key1'); // 2
-     * $redis->incr('key1'); // 3
-     * $redis->incr('key1'); // 4
-     * 
- * @return int - */ - public function incr() - { - } - - /** - * - *Decrement the number stored at key by one. If the second argument is filled, it will be used as the integer - *value of the decrement. - * @example - *
-     * $redis->decr('key1');        // key1 didn't exists, set to 0 before the increment and now has the value -1
-     * $redis->decr('key1');        // -2
-     * $redis->decr('key1');        // -3
-     * $redis->decrBy('key1', 10);  // -13
-     * 
- * @return int - */ - public function decrBy() - { - } - - /** - * - *Decrement the number stored at key by one. - * @example - *
-     * $redis->decr('key1'); // key1 didn't exists, set to 0 before the increment and now has the value -1
-     * $redis->decr('key1'); // -2
-     * $redis->decr('key1'); // -3
-     * 
- * @return int - */ - public function decr() - { - } - - /** - * - *Return a single bit out of a larger string - * @example - *
-     * $redis->set('key', "\x7f");  // this is 0111 1111
-     * $redis->getBit('key', 0);    // 0
-     * $redis->getBit('key', 1);    // 1
-     * 
- * @return int: - */ - public function getBit() - { - } - - /** - * - *Insert value in the list before or after the pivot value. the parameter options - *specify the position of the insert (before or after). If the list didn't exists, - *or the pivot didn't exists, the value is not inserted. - * @example - *
-     * $redis->delete('key1');
-     * $redis->lInsert('key1', Redis::AFTER, 'A', 'X');     // 0
-     * $redis->lPush('key1', 'A');
-     * $redis->lPush('key1', 'B');
-     * $redis->lPush('key1', 'C');
-     * $redis->lInsert('key1', Redis::BEFORE, 'C', 'X');    // 4
-     * $redis->lRange('key1', 0, -1);                       // array('A', 'B', 'X', 'C')
-     * $redis->lInsert('key1', Redis::AFTER, 'C', 'Y');     // 5
-     * $redis->lRange('key1', 0, -1);                       // array('A', 'B', 'X', 'C', 'Y')
-     * $redis->lInsert('key1', Redis::AFTER, 'W', 'value'); // -1
-     * 
- * @return int - */ - public function lInsert() - { - } - - /** - * - * - * @example - * @return - */ - public function lGet() - { - } - - /** - * - *Return the specified element of the list stored at the specified key. - *0 the first element, 1 the second ... -1 the last element, -2 the penultimate ... - *Return FALSE in case of a bad index or a key that doesn't point to a list. - * @example - *
-     * $redis->rPush('key1', 'A');
-     * $redis->rPush('key1', 'B');
-     * $redis->rPush('key1', 'C');  // key1 => [ 'A', 'B', 'C' ]
-     * $redis->lGet('key1', 0);     // 'A'
-     * $redis->lGet('key1', -1);    // 'C'
-     * $redis->lGet('key1', 10);    // `FALSE`
-     * 
- * @return Bool - */ - public function lIndex() - { - } - - /** - * - * - * @example - * @return - */ - public function setTimeout() - { - } - - /** - * - *Sets an expiration date (a timeout) on an item. - * @example - *
-     * $redis->set('x', '42');
-     * $redis->setTimeout('x', 3);  // x will disappear in 3 seconds.
-     * sleep(5);                    // wait 5 seconds
-     * $redis->get('x');            // will return `FALSE`, as 'x' has expired.
-     * 
- * @return bool: - */ - public function expire() - { - } - - /** - * - * - * @example - * @return - */ - public function pexpire() - { - } - - /** - * - *Sets an expiration date (a timestamp) on an item. - * @example - *
-     * $redis->set('x', '42');
-     * $now = time(NULL);               // current timestamp
-     * $redis->expireAt('x', $now + 3); // x will disappear in 3 seconds.
-     * sleep(5);                        // wait 5 seconds
-     * $redis->get('x');                // will return `FALSE`, as 'x' has expired.
-     * 
- * @return bool: - */ - public function expireAt() - { - } - - /** - * - * - * @example - * @return - */ - public function pexpireAt() - { - } - - /** - * - *Moves a key to a different database. - * @example - *
-     * $redis->select(0);       // switch to DB 0
-     * $redis->set('x', '42');  // write 42 to x
-     * $redis->move('x', 1);    // move to DB 1
-     * $redis->select(1);       // switch to DB 1
-     * $redis->get('x');        // will return 42
-     * 
- * @return bool: - */ - public function move() - { - } - - /** - * - *Switches to a given database. - * @example - *
-     * $redis->select(0);       // switch to DB 0
-     * $redis->set('x', '42');  // write 42 to x
-     * $redis->move('x', 1);    // move to DB 1
-     * $redis->select(1);       // switch to DB 1
-     * $redis->get('x');        // will return 42
-     * 
- * @return bool - */ - public function select() - { - } - - /** - * - *Return a substring of a larger string - * @example - *
-     * $redis->set('key', 'string value');
-     * $redis->getRange('key', 0, 5);   // 'string'
-     * $redis->getRange('key', -5, -1); // 'value'
-     * 
- * @return string: - */ - public function getRange() - { - } - - /** - * - * - * @example - * @return - */ - public function listTrim() - { - } - - /** - * - * - * @example - * @return - */ - public function ltrim() - { - } - - /** - * - * - * @example - * @return - */ - public function lGetRange() - { - } - - /** - * - *Returns the specified elements of the list stored at the specified key in - *the range [start, end]. start and stop are interpretated as indices: 0 the first element, - *1 the second ... -1 the last element, -2 the penultimate ... - * @example - *
-     * $redis->rPush('key1', 'A');
-     * $redis->rPush('key1', 'B');
-     * $redis->rPush('key1', 'C');
-     * $redis->lRange('key1', 0, -1); // array('A', 'B', 'C')
-     * 
- * @return array - */ - public function lRange() - { - } - - /** - * - *Removes the first count occurences of the value element from the list. - *If count is zero, all the matching elements are removed. If count is negative, - *elements are removed from tail to head. - * @example - *
-     * $redis->lPush('key1', 'A');
-     * $redis->lPush('key1', 'B');
-     * $redis->lPush('key1', 'C');
-     * $redis->lPush('key1', 'A');
-     * $redis->lPush('key1', 'A');
-     * $redis->lRange('key1', 0, -1);   // array('A', 'A', 'C', 'B', 'A')
-     * $redis->lRem('key1', 'A', 2);    // 2
-     * $redis->lRange('key1', 0, -1);   // array('C', 'B', 'A')
-     * 
- * @return bool - */ - public function lRem() - { - } - - /** - * - * - * @example - * @return - */ - public function lRemove() - { - } - - /** - * - * - * @example - * @return - */ - public function zDeleteRangeByRank() - { - } - - /** - * - *Deletes the elements of the sorted set stored at the specified key which have rank in the range [start,end]. - * @example - *
-     * $redis->zAdd('key', 1, 'one');
-     * $redis->zAdd('key', 2, 'two');
-     * $redis->zAdd('key', 3, 'three');
-     * $redis->zRemRangeByRank('key', 0, 1); // 2
-     * $redis->zRange('key', 0, -1, array('withscores' => TRUE)); // array('three' => 3)
-     * 
- * @return int - */ - public function zRemRangeByRank() - { - } - - /** - * - *Increment the float value of a key by the given amount - * @example - *
-     * $redis = new Redis();
-     * $redis->connect('127.0.0.1');
-     * $redis->set('x', 3);
-     * var_dump( $redis->incrByFloat('x', 1.5) );   // float(4.5)
-     * // ! SIC
-     * var_dump( $redis->get('x') );                // string(3) "4.5"
-     * 
- * @return - */ - public function incrByFloat() - { - } - - /** - * - *Increment the float value of a hash field by the given amount - * @example - *
-     * $redis = new Redis();
-     * $redis->connect('127.0.0.1');
-     * $redis->hset('h', 'float', 3);
-     * $redis->hset('h', 'int',   3);
-     * var_dump( $redis->hIncrByFloat('h', 'float', 1.5) ); // float(4.5)
-     * var_dump( $redis->hGetAll('h') );
-     * // Output
-     * array(2) {
-     * ["float"]=>
-     * string(3) "4.5"
-     * ["int"]=>
-     * string(1) "3"
-     * }
-     * 
- * @return - */ - public function hIncrByFloat() - { - } - - /** - * - *Count bits in a string. - * @example - *
-     * $redis->set('bit', '345'); // // 11 0011  0011 0100  0011 0101
-     * var_dump( $redis->bitCount('bit', 0, 0) ); // int(4)
-     * var_dump( $redis->bitCount('bit', 1, 1) ); // int(3)
-     * var_dump( $redis->bitCount('bit', 2, 2) ); // int(4)
-     * var_dump( $redis->bitCount('bit', 0, 2) ); // int(11)
-     * 
- * @return int - */ - public function bitCount() - { - } - - /** - * - *Bitwise operation on multiple keys. - * @example - *
-     * $redis->set('bit1', '1'); // 11 0001
-     * $redis->set('bit2', '2'); // 11 0010
-     * $redis->bitOp('AND', 'bit', 'bit1', 'bit2'); // bit = 110000
-     * $redis->bitOp('OR',  'bit', 'bit1', 'bit2'); // bit = 110011
-     * $redis->bitOp('NOT', 'bit', 'bit1', 'bit2'); // bit = 110011
-     * $redis->bitOp('XOR', 'bit', 'bit1', 'bit2'); // bit = 11
-     * 
- * @return int - */ - public function bitOp() - { - } - - /** - * - *Adds a values to the set value stored at key. - *If this value is already in the set, FALSE is returned. - * @example - *
-     * $redis->sAdd('k', 'v1');                // int(1)
-     * $redis->sAdd('k', 'v1', 'v2', 'v3');    // int(2)
-     * 
- * @return int - */ - public function sAdd() - { - } - - /** - * - *Moves the specified member from the set at srcKey to the set at dstKey. - * @example - *
-     * $redis->sAdd('key1' , 'set11');
-     * $redis->sAdd('key1' , 'set12');
-     * $redis->sAdd('key1' , 'set13');          // 'key1' => {'set11', 'set12', 'set13'}
-     * $redis->sAdd('key2' , 'set21');
-     * $redis->sAdd('key2' , 'set22');          // 'key2' => {'set21', 'set22'}
-     * $redis->sMove('key1', 'key2', 'set13');  // 'key1' =>  {'set11', 'set12'}
-     * // 'key2' =>  {'set21', 'set22', 'set13'}
-     * 
- * @return If - */ - public function sMove() - { - } - - /** - * - *Performs the difference between N sets and returns it. - * @example - *
-     * $redis->delete('s0', 's1', 's2');
-     * $redis->sAdd('s0', '1');
-     * $redis->sAdd('s0', '2');
-     * $redis->sAdd('s0', '3');
-     * $redis->sAdd('s0', '4');
-     * $redis->sAdd('s1', '1');
-     * $redis->sAdd('s2', '3');
-     * var_dump($redis->sDiff('s0', 's1', 's2'));
-     * //array(2) {
-     * //  [0]=>
-     * //  string(1) "4"
-     * //  [1]=>
-     * //  string(1) "2"
-     * //}
-     * 
- * @return array - */ - public function sDiff() - { - } - - /** - * - *Performs the same action as sDiff, but stores the result in the first key - * @example - *
-     * $redis->delete('s0', 's1', 's2');
-     * $redis->sAdd('s0', '1');
-     * $redis->sAdd('s0', '2');
-     * $redis->sAdd('s0', '3');
-     * $redis->sAdd('s0', '4');
-     * $redis->sAdd('s1', '1');
-     * $redis->sAdd('s2', '3');
-     * var_dump($redis->sDiffStore('dst', 's0', 's1', 's2'));
-     * var_dump($redis->sMembers('dst'));
-     * //int(2)
-     * //array(2) {
-     * //  [0]=>
-     * //  string(1) "4"
-     * //  [1]=>
-     * //  string(1) "2"
-     * //}
-     * 
- * @return int: - */ - public function sDiffStore() - { - } - - /** - * - *Performs the union between N sets and returns it. - * @example - *
-     * $redis->delete('s0', 's1', 's2');
-     * $redis->sAdd('s0', '1');
-     * $redis->sAdd('s0', '2');
-     * $redis->sAdd('s1', '3');
-     * $redis->sAdd('s1', '1');
-     * $redis->sAdd('s2', '3');
-     * $redis->sAdd('s2', '4');
-     * var_dump($redis->sUnion('s0', 's1', 's2'));
-     * array(4) {
-     * //  [0]=>
-     * //  string(1) "3"
-     * //  [1]=>
-     * //  string(1) "4"
-     * //  [2]=>
-     * //  string(1) "1"
-     * //  [3]=>
-     * //  string(1) "2"
-     * //}
-     * 
- * @return array - */ - public function sUnion() - { - } - - /** - * - *Performs the same action as sUnion, but stores the result in the first key - * @example - *
-     * $redis->delete('s0', 's1', 's2');
-     * $redis->sAdd('s0', '1');
-     * $redis->sAdd('s0', '2');
-     * $redis->sAdd('s1', '3');
-     * $redis->sAdd('s1', '1');
-     * $redis->sAdd('s2', '3');
-     * $redis->sAdd('s2', '4');
-     * var_dump($redis->sUnionStore('dst', 's0', 's1', 's2'));
-     * var_dump($redis->sMembers('dst'));
-     * //int(4)
-     * //array(4) {
-     * //  [0]=>
-     * //  string(1) "3"
-     * //  [1]=>
-     * //  string(1) "4"
-     * //  [2]=>
-     * //  string(1) "1"
-     * //  [3]=>
-     * //  string(1) "2"
-     * //}
-     * 
- * @return int - */ - public function sUnionStore() - { - } - - /** - * - *Returns the members of a set resulting from the intersection of all the sets - *held at the specified keys. If just a single key is specified, then this command - *produces the members of this set. If one of the keys is missing, FALSE is returned. - * @example - *
-     * $redis->sAdd('key1', 'val1');
-     * $redis->sAdd('key1', 'val2');
-     * $redis->sAdd('key1', 'val3');
-     * $redis->sAdd('key1', 'val4');
-     * $redis->sAdd('key2', 'val3');
-     * $redis->sAdd('key2', 'val4');
-     * $redis->sAdd('key3', 'val3');
-     * $redis->sAdd('key3', 'val4');
-     * var_dump($redis->sInter('key1', 'key2', 'key3'));
-     * //array(2) {
-     * //  [0]=>
-     * //  string(4) "val4"
-     * //  [1]=>
-     * //  string(4) "val3"
-     * //}
-     * 
- * @return If - */ - public function sInter() - { - } - - /** - * - *Performs a sInter command and stores the result in a new set. - * @example - *
-     * $redis->sAdd('key1', 'val1');
-     * $redis->sAdd('key1', 'val2');
-     * $redis->sAdd('key1', 'val3');
-     * $redis->sAdd('key1', 'val4');
-     * $redis->sAdd('key2', 'val3');
-     * $redis->sAdd('key2', 'val4');
-     * $redis->sAdd('key3', 'val3');
-     * $redis->sAdd('key3', 'val4');
-     * var_dump($redis->sInterStore('output', 'key1', 'key2', 'key3'));
-     * var_dump($redis->sMembers('output'));
-     * //int(2)
-     * //
-     * //array(2) {
-     * //  [0]=>
-     * //  string(4) "val4"
-     * //  [1]=>
-     * //  string(4) "val3"
-     * //}
-     * 
- * @return int: - */ - public function sInterStore() - { - } - - /** - * - * - * @example - * @return - */ - public function sRemove() - { - } - - /** - * - * - * @example - * @return - */ - public function srem() - { - } - - /** - * - * - * @example - * @return int - */ - public function zDelete() - { - } - - /** - * - * - * @example - * @return - */ - public function zRemove() - { - } - - /** - * - *Deletes a specified member from the ordered set. - * @example - *
-     * $redis->zAdd('z', 1, 'v2', 2, 'v2', 3, 'v3', 4, 'v4' );  // int(2)
-     * $redis->zRem('z', 'v2', 'v3');                           // int(2)
-     * var_dump( $redis->zRange('z', 0, -1) );
-     * //// Output:
-     * // array(2) {
-     * //   [0]=> string(2) "v1"
-     * //   [1]=> string(2) "v4"
-     * // }
-     * 
- * @return int - */ - public function zRem() - { - } - - /** - * - * - * @example - * @return - */ - public function pSubscribe() - { - } - - /** - * - *Subscribe to channels. Warning: this function will probably change in the future. - * @example - *
-     * function f($redis, $chan, $msg) {
-     * switch($chan) {
-     * case 'chan-1':
-     * ...
-     * break;
-     * case 'chan-2':
-     * ...
-     * break;
-     * case 'chan-2':
-     * ...
-     * break;
-     * }
-     * }
-     * $redis->subscribe(array('chan-1', 'chan-2', 'chan-3'), 'f'); // subscribe to 3 chans
-     * 
- * @return mixed - */ - public function subscribe() - { - } - - /** - * - *Enter and exit transactional mode. - * @example - *
-     * $ret = $redis->multi()
-     * ->set('key1', 'val1')
-     * ->get('key1')
-     * ->set('key2', 'val2')
-     * ->get('key2')
-     * ->exec();
-     * //$ret == array (
-     * //    0 => TRUE,
-     * //    1 => 'val1',
-     * //    2 => TRUE,
-     * //    3 => 'val2');
-     * 
- * @return Once - */ - public function multi() - { - } - - /** - * - * - * @example - * @return - */ - public function exec() - { - } - -} - diff --git a/src/Swoole/swoole_redis_server.php b/src/Swoole/swoole_redis_server.php index 0b27688..0d95111 100644 --- a/src/Swoole/swoole_redis_server.php +++ b/src/Swoole/swoole_redis_server.php @@ -1,326 +1,577 @@ finish()方法将任务处理的结果发送给worker进程。 + * @access public + */ + public $onFinish; + + /** + * @var callable $onManagerStart + * 当管理进程启动时调用它 + * @access public + */ + public $onManagerStart; + + /** + * @var callable $onManagerStop + * 当管理进程结束时调用它 + * @access public + */ + public $onManagerStop; + + /** + * @var callable $onPipeMessage + * 当工作进程收到由 sendMessage 发送的管道消息时会触发onPipeMessage事件 + * @access public + */ + public $onPipeMessage; + + /** + * @var array $setting + * 通过swoole_server:set()设置的参数会保存到setting属性上 + * @access public + */ + public $setting = array(); + + /** + * @var iterator $connections + * TCP连接迭代器 + * @access public + */ + public $connections; + + /** + * @var string $host + * 连接的主机 + * @access public + */ + public $host; + + /** + * @var int $port + * 连接的主机的端口 + * @access public + */ + public $port = 0; + + /** + * @var int $type + * socket的类型 + * @access public + */ + public $type = 0; + + /** + * @var int $mode + * 运行模式(swoole提供了3种运行模式,默认为SWOOLE_PROCESS多进程模式) + * @access public + */ + public $mode = 0; + + /** + * @var array $ports + * 当监听多端口时的端口列表 + * @access public + */ + public $ports = array(); + + /** + * @var int $master_pid + * 主进程ID + * @access public + */ + public $master_pid = 0; + + /** + * @var int $manager_pid + * 管理进程ID + * @access public + */ + public $manager_pid = 0; + + /** + * @var int $worker_id + * 当前工作进程(包括worker进程和task进程)编号 + * @access public + */ + public $worker_id = -1; + + /** + * @var boolean $taskworker + * 当前进程是否是task工作进程 + * @access public + */ + public $taskworker = ''; + + /** + * @var int $worker_pid + * 当前工作进程ID(操作系统进程) + * @access public + */ + public $worker_pid = 0; + /** * - *启动server,监听所有TCP/UDP端口 + *启动server * @example - * @return bool + * @return */ public function start() { + } /** * *设置Redis命令字的处理器 * @example - * @param string $command 设置Redis命令字的处理器 - * @param callable $callback 设置Redis命令字的处理器 - * @param mixed $number_of_string_param - * @param mixed $type_of_array_param + * @param string $command 命令的名称 + * @param callable $callback 命令的处理函数,回调函数返回字符串类型时会自动发送给客户端 + * @param int $number_of_string_param 字符串参数的长度 + * @param int $type_of_array_param 数组参数元素的类型 * @return */ - public function setHandler($command, Callable $callback, $number_of_string_param, $type_of_array_param) + public function setHandler(string $command, Callable $callback, int $number_of_string_param, int $type_of_array_param) { + } /** * *格式化命令响应数据 * @example - * @param int $type 格式化命令响应数据 - * @param mixed $value 格式化命令响应数据 + * @param int $type 表示数据类型,NIL类型不需要传入$value,ERROR和STATUS类型$value可选,INT、STRING、SET、MAP必选 + * @param mixed $value 要处理的数据 + * @return + */ + public static function format(int $type, $value) + { + + } + + /** + * + *swoole_server初始化方法 + * @example + * @param string $host 主机IP + * @param int $port 端口 + * @param int $mode 运行模式 + * @param int $sock_type socket类型 * @return */ - public static function format($type, $value) + public function __construct(string $host, int $port, int $mode, int $sock_type) { + } /** * - *创建一个swoole tcp/udp server对象 + *析构函数 * @example - * @param string $host 创建一个swoole tcp/udp server对象 - * @param int $port 创建一个swoole tcp/udp server对象 - * @param int $mode 创建一个swoole tcp/udp server对象 - * @param int $sock_type 创建一个swoole tcp/udp server对象 * @return */ - public function __construct($host, $port, $mode, $sock_type) + public function __destruct() { + } /** * - *监听一个新的Server端口,此方法是addlistener的别名 + *添加监听端口(是addlistener的别名) * @example - * @param string $host 监听一个新的Server端口,此方法是addlistener的别名 - * @param int $port 监听一个新的Server端口,此方法是addlistener的别名 - * @param int $sock_type 监听一个新的Server端口,此方法是addlistener的别名 + * @param string $host 监听的主机 + * @param int $port 监听的端口号 + * @param int $sock_type socket类型 * @return */ - public function listen($host, $port, $sock_type) + public function listen(string $host, int $port, int $sock_type) { + } /** * - *监听一个新的Server端口,此方法是addlistener的别名 + *添加监听端口 * @example - * @param string $host 监听一个新的Server端口,此方法是addlistener的别名 - * @param int $port 监听一个新的Server端口,此方法是addlistener的别名 - * @param int $sock_type 监听一个新的Server端口,此方法是addlistener的别名 + * @param string $host 监听的主机 + * @param int $port 监听的端口号 + * @param int $sock_type socket类型 * @return */ - public function addlistener($host, $port, $sock_type) + public function addlistener(string $host, int $port, int $sock_type) { + } /** * - *注册Server的事件回调函数 + *绑定事件(为事件注册函数) * @example - * @param string $event_name 注册Server的事件回调函数 - * @param callable $callback 注册Server的事件回调函数 - * @return bool + * @param string $event_name 事件名称 + * @param callable $callback 事件对应的回调函数 + * @return */ - public function on($event_name, Callable $callback) + public function on(string $event_name, Callable $callback) { + } /** * - *设置选项 + *设置swoole_server运行时的参数 * @example - * @param array $settings 设置选项 + * @param array $settings 配置选项 * @return */ public function set(Array $settings) { + } /** * *向客户端发送数据 * @example - * @param int $fd 向客户端发送数据 - * @param string $send_data 向客户端发送数据 - * @param int $reactor_id 向客户端发送数据 - * @return bool + * @param int $fd 连接句柄 + * @param string $send_data 发送的数据 + * @param int $reactor_id UDP服务器使用$fd保存客户端IP,$extraData保存server_fd和port + * @return */ - public function send($fd, $send_data, $reactor_id) + public function send(int $fd, string $send_data, int $reactor_id) { + } /** * - *向任意的客户端IP:PORT发送UDP数据包 + *向任意客户端发送UDP数据包 * @example - * @param string $ip 向任意的客户端IP:PORT发送UDP数据包 - * @param int $port 向任意的客户端IP:PORT发送UDP数据包 - * @param string $send_data 向任意的客户端IP:PORT发送UDP数据包 - * @param int $server_socket 向任意的客户端IP:PORT发送UDP数据包 - * @return bool + * @param string $ip IPv4字符串,如192.168.1.102。如果IP不合法会返回错误 + * @param int $port 为 1-65535的网络端口号,如果端口错误发送会失败 + * @param string $send_data 发送的数据内容,可以是文本或者二进制内容 + * @param int $server_socket 服务器可能会同时监听多个UDP端口,此参数可以指定使用哪个端口发送数据包 + * @return */ - public function sendto($ip, $port, $send_data, $server_socket) + public function sendto(string $ip, int $port, string $send_data, int $server_socket) { + } /** * - *阻塞地向客户端发送数据 + *阻塞的向客户端发送数据 * @example - * @param int $conn_fd 阻塞地向客户端发送数据 - * @param string $send_data 阻塞地向客户端发送数据 - * @return bool + * @param int $conn_fd 与客户端连接的句柄 + * @param string $send_data 发送的数据 + * @return */ - public function sendwait($conn_fd, $send_data) + public function sendwait(int $conn_fd, string $send_data) { + } /** * *检测fd对应的连接是否存在 * @example - * @param int $fd 检测fd对应的连接是否存在 - * @return bool + * @param int $fd 连接句柄 + * @return */ - public function exist($fd) + public function exist(int $fd) { + } /** * - *用于保护某些连接不被心跳线程切断 + *设置客户端连接为保护状态,不被心跳线程切断 * @example - * @param int $fd 用于保护某些连接不被心跳线程切断 - * @param bool $is_protected 用于保护某些连接不被心跳线程切断 + * @param int $fd 要设置保护状态的客户端连接fd + * @param boolean $is_protected 设置的状态,true表示保护状态,false表示不保护 * @return */ - public function protect($fd, $is_protected) + public function protect(int $fd, bool $is_protected) { + } /** * - *发送文件到TCP客户端连接 + *向客户端发送文件 * @example - * @param int $conn_fd 发送文件到TCP客户端连接 - * @param string $filename 发送文件到TCP客户端连接 - * @param int $offset 发送文件到TCP客户端连接 - * @return bool + * @param int $conn_fd 连接句柄 + * @param string $filename 文件名 + * @param int $offset 指定文件偏移量,可以从文件的某个位置起发送数据。默认为0,表示从文件头部开始发送 + * @param int $length 指定发送的长度,默认为文件尺寸 + * @return */ - public function sendfile($conn_fd, $filename, $offset) + public function sendfile(int $conn_fd, string $filename, int $offset, int $length) { + } /** * *关闭客户端连接 * @example - * @param int $fd 关闭客户端连接 - * @param bool $reset 关闭客户端连接 + * @param int $fd 连接句柄 + * @param boolean $reset 设置为true会强制关闭连接,丢弃发送队列中的数据 * @return */ - public function close($fd, $reset) + public function close(int $fd, bool $reset) { + } /** * - *连接确认 + *确认连接,与enable_delay_receive或wait_for_bind配合使用 * @example - * @param int $fd 连接确认 + * @param int $fd 连接句柄 * @return */ - public function confirm($fd) + public function confirm(int $fd) { + } /** * *停止接收数据 * @example - * @param int $fd 停止接收数据 + * @param int $fd 连接句柄 * @return */ - public function pause($fd) + public function pause(int $fd) { + } /** * - *恢复数据接收 + *恢复数据接收。与pause方法成对使用 * @example - * @param int $fd 恢复数据接收 + * @param int $fd 连接句柄 * @return */ - public function resume($fd) + public function resume(int $fd) { + } /** * - *投递一个异步任务到task_worker池中。此函数是非阻塞的,执行完毕会立即返回 + *投递一个任务到task_worker连接池中 * @example - * @param mixed $data 投递一个异步任务到task_worker池中。此函数是非阻塞的,执行完毕会立即返回 - * @param int $worker_id 投递一个异步任务到task_worker池中。此函数是非阻塞的,执行完毕会立即返回 - * @param callable $finish_callback 投递一个异步任务到task_worker池中。此函数是非阻塞的,执行完毕会立即返回 + * @param mixed $data 要投递的任务数据,可以为除资源类型之外的任意PHP变量 + * @param int $worker_id 可以制定要给投递给哪个task进程,传入ID即可 + * @param callable $finish_callback 完成后的回调函数 * @return */ - public function task($data, $worker_id, Callable $finish_callback) + public function task($data, int $worker_id, Callable $finish_callback) { + } /** * - *用于投递一个异步的任务到task进程池去执行。与task不同的是taskwait是阻塞等待的,直到任务完成或者超时返回。 + *以阻塞的形式投递一个任务到task_worker连接池中 * @example - * @param mixed $data 用于投递一个异步的任务到task进程池去执行。与task不同的是taskwait是阻塞等待的,直到任务完成或者超时返回。 - * @param float $timeout 用于投递一个异步的任务到task进程池去执行。与task不同的是taskwait是阻塞等待的,直到任务完成或者超时返回。 - * @param int $worker_id 用于投递一个异步的任务到task进程池去执行。与task不同的是taskwait是阻塞等待的,直到任务完成或者超时返回。 + * @param mixed $data 要投递的任务数据,可以为除资源类型之外的任意PHP变量 + * @param float $timeout 超时时间 + * @param int $worker_id 可以制定要给投递给哪个task进程,传入ID即可 * @return */ - public function taskwait($data, $timeout, $worker_id) + public function taskwait($data, float $timeout, int $worker_id) { + } /** * *并发执行多个Task * @example - * @param array $tasks 并发执行多个Task - * @param double $timeout 并发执行多个Task + * @param array $tasks 必须为数字索引数组,不支持关联索引数组,底层会遍历$tasks将任务逐个投递到Task进程 + * @param double $timeout 超时时间 * @return */ - public function taskWaitMulti(Array $tasks, $timeout) + public function taskWaitMulti(Array $tasks, double $timeout) { + } /** * - *此函数用于在task进程中通知worker进程,投递的任务已完成。此函数可以传递结果数据给worker进程 + *并发执行Task并进行协程调度 * @example - * @param string $data 此函数用于在task进程中通知worker进程,投递的任务已完成。此函数可以传递结果数据给worker进程 - * @return + * @param array $tasks 必须为数字索引数组,不支持关联索引数组,底层会遍历$tasks将任务逐个投递到Task进程 + * @param double $timeout 超时时间 + * @return array */ - public function finish($data) + public function taskCo(Array $tasks, double $timeout): array { + } /** * - *重启所有worker进程 + *用于在task进程中通知worker进程任务已完成 * @example + * @param string $data 要传递的数据 * @return */ - public function reload() + public function finish(string $data) + { + + } + + /** + * + *重启所有工作进程 + * @example + * @return boolean + */ + public function reload(): boolean { + } /** @@ -331,178 +582,219 @@ public function reload() */ public function shutdown() { + } /** * - *使当前worker进程停止运行,并立即触发onWorkerStop回调函数 + *停止当前worker进程 * @example - * @param int $worker_id 使当前worker进程停止运行,并立即触发onWorkerStop回调函数 + * @param int $worker_id 进程ID * @return */ - public function stop($worker_id) + public function stop(int $worker_id) { + } /** * - *获取最近一次操作错误的错误码。业务代码中可以根据错误码类型执行不同的逻辑。 + *获取最近一次操作错误的错误码 + *返回的错误码: + *1001 连接已经被Server端关闭了,出现这个错误一般是代码中已经执行了$serv->close()关闭了某个连接,但仍然调用$serv->send()向这个连接发送数据 * @example - * @return int + * @return */ public function getLastError() { + } /** * - *检测服务器所有连接,并找出已经超过约定时间的连接。如果指定if_close_connection,则自动关闭超时的连接。未指定仅返回连接的fd数组。 + *检测所有服务器连接,并找出已经超时的连接 * @example - * @param mixed $reactor_id + * @param boolean $reactor_id 是否关闭超时的连接,默认为true * @return */ - public function heartbeat($reactor_id) + public function heartbeat(bool $reactor_id) { + } /** * - *获取连接的信息 + *获取客户端连接信息 * @example - * @param int $fd 获取连接的信息 - * @param int $reactor_id 获取连接的信息 - * @return + * @param mixed $fd 连接句柄 + * @param int $reactor_id reactor线程id + * @return from_id */ - public function connection_info($fd, $reactor_id) + public function connection_info($fd, int $reactor_id): from_id { + } /** * - *用来遍历当前Server所有的客户端连接 + *用来遍历所有客户端连接 * @example - * @param int $start_fd 用来遍历当前Server所有的客户端连接 - * @param int $find_count 用来遍历当前Server所有的客户端连接 + * @param int $start_fd 起始fd + * @param int $find_count 每页取多少条 * @return */ - public function connection_list($start_fd, $find_count) + public function connection_list(int $start_fd, int $find_count) { + } /** * - *获取连接的信息 + *获取连接的信息,别名是swoole_server->connection_info * @example - * @param int $fd 获取连接的信息 - * @param int $reactor_id 获取连接的信息 + * @param mixed $fd 连接句柄 + * @param int $reactor_id reactor线程id * @return */ - public function getClientInfo($fd, $reactor_id) + public function getClientInfo($fd, int $reactor_id) { + } /** * - *用来遍历当前Server所有的客户端连接 + *用来遍历所有客户端连接(server->connection_list的别名) * @example - * @param int $start_fd 用来遍历当前Server所有的客户端连接 - * @param int $find_count 用来遍历当前Server所有的客户端连接 + * @param int $start_fd 起始fd + * @param int $find_count 每页取多少条 * @return */ - public function getClientList($start_fd, $find_count) + public function getClientList(int $start_fd, int $find_count) { + } /** * - *在指定的时间后执行函数 + *在指定时间后执行某个回调函数 * @example - * @param int $ms 在指定的时间后执行函数 - * @param callable $callback 在指定的时间后执行函数 - * @param array $param 在指定的时间后执行函数 + * @param int $ms 指定时间,单位为毫秒 + * @param callable $callback 回调函数 + * @param array $param 给回调函数传入的参数 * @return */ - public function after($ms, Callable $callback, Array $param) + public function after(int $ms, Callable $callback, Array $param) { + } /** * - *tick定时器,可以自定义回调函数 + *添加定时器 * @example - * @param int $ms tick定时器,可以自定义回调函数 - * @param callable $callback tick定时器,可以自定义回调函数 + * @param int $ms 指定时间,单位为毫秒 + * @param callable $callback 回调函数 * @return */ - public function tick($ms, Callable $callback) + public function tick(int $ms, Callable $callback) { + } /** * - *清除tick/after定时器,此函数是swoole_timer_clear的别名 + *清除定时器 * @example - * @param int $timer_id 清除tick/after定时器,此函数是swoole_timer_clear的别名 + * @param int $timer_id 定时器ID * @return */ - public function clearTimer($timer_id) + public function clearTimer(int $timer_id) { + } /** * - *延后执行一个PHP函数。Swoole底层会在EventLoop循环完成后执行此函数。此函数的目的是为了让一些PHP代码延后执行,程序优先处理IO事件 + *延迟执行一个PHP函数 * @example - * @param callable $callback 延后执行一个PHP函数。Swoole底层会在EventLoop循环完成后执行此函数。此函数的目的是为了让一些PHP代码延后执行,程序优先处理IO事件 + * @param callable $callback 执行的函数 * @return */ public function defer(Callable $callback) { + } /** * - *此函数可以向任意worker进程或者task进程发送消息。在非主进程和管理进程中可调用。收到消息的进程会触发onPipeMessage事件。 + *向任意worker进程或task进程发送消息 * @example - * @param int $dst_worker_id 此函数可以向任意worker进程或者task进程发送消息。在非主进程和管理进程中可调用。收到消息的进程会触发onPipeMessage事件。 - * @param string $data 此函数可以向任意worker进程或者task进程发送消息。在非主进程和管理进程中可调用。收到消息的进程会触发onPipeMessage事件。 + * @param int $dst_worker_id 目标worker的ID + * @param string $data 发送的消息 * @return */ - public function sendMessage($dst_worker_id, $data) + public function sendMessage(int $dst_worker_id, string $data) { + } /** * - *添加一个用户自定义的工作进程 + *添加一个自定义的工作进程 * @example - * @param object $process 添加一个用户自定义的工作进程 + * @param Swoole\Process $process 进程对象 * @return */ - public function addProcess($process) + public function addProcess(Swoole\Process $process) { + } /** * - *得到当前Server的活动TCP连接数,启动时间,accpet/close的总次数等信息 + *得到当前server的活动TCP连接数 + *array ( * @example - * @return array + * @return */ public function stats() { + + } + + /** + * + *将连接绑定到某个用户定义的ID + * @example + * @param int $fd 连接句柄 + * @param int $uid 用户定义的ID + * @return + */ + public function bind(int $fd, int $uid) + { + + } + + /** + * + *序列化函数调用的魔术方法(在PHP进行序列化时,serialize() 检查类中是否有 __sleep() ,如果有,则该函数将在任何序列化之前运行。该函数必须返回一个需要进行序列化保存的成员属性数组,并且只序列化该函数返回的这些成员属性. 该函数有两个作用: 第一. 在序列化之前,关闭对象可能具有的任何数据库连接等. 第二. 指定对象中需要被序列化的成员属性,如果某个属性比较大而不需要储存下来,可以不把它写进__sleep要返回的数组中,这样该属性就不会被序列化) + * @example + * @return + */ + public function __sleep() + { + } /** * - *将连接绑定一个用户定义的ID,可以设置dispatch_mode=5设置已此ID值进行hash固定分配。可以保证某一个UID的连接全部会分配到同一个Worker进程 + *反序列化函数调用的魔术方法(unserialize() 从字节流中创建了一个对象之后,马上检查是否具有__wakeup 的函数的存在。如果存在,__wakeup 立刻被调用。使用 __wakeup 的目的是重建在序列化中可能丢失的任何数据库连接以及处理其它重新初始化的任务) * @example - * @param int $fd 将连接绑定一个用户定义的ID,可以设置dispatch_mode=5设置已此ID值进行hash固定分配。可以保证某一个UID的连接全部会分配到同一个Worker进程 - * @param int $uid 将连接绑定一个用户定义的ID,可以设置dispatch_mode=5设置已此ID值进行hash固定分配。可以保证某一个UID的连接全部会分配到同一个Worker进程 * @return */ - public function bind($fd, $uid) + public function __wakeup() { + } } diff --git a/src/Swoole/swoole_ringqueue.php b/src/Swoole/swoole_ringqueue.php new file mode 100644 index 0000000..1b4c81e --- /dev/null +++ b/src/Swoole/swoole_ringqueue.php @@ -0,0 +1,71 @@ +finish()方法将任务处理的结果发送给worker进程。 + * @access public + */ + public $onFinish; + + /** + * @var callable $onManagerStart + * 当管理进程启动时调用它 + * @access public + */ + public $onManagerStart; + + /** + * @var callable $onManagerStop + * 当管理进程结束时调用它 + * @access public + */ + public $onManagerStop; + + /** + * @var callable $onPipeMessage + * 当工作进程收到由 sendMessage 发送的管道消息时会触发onPipeMessage事件 + * @access public + */ + public $onPipeMessage; + /** * @var array $setting - * 参数设置数组 + * 通过swoole_server:set()设置的参数会保存到setting属性上 + * @access public + */ + public $setting = array(); + + /** + * @var iterator $connections + * TCP连接迭代器 + * @access public + */ + public $connections; + + /** + * @var string $host + * 连接的主机 + * @access public + */ + public $host; + + /** + * @var int $port + * 连接的主机的端口 * @access public */ - public $setting; + public $port = 0; + + /** + * @var int $type + * socket的类型 + * @access public + */ + public $type = 0; + + /** + * @var int $mode + * 运行模式(swoole提供了3种运行模式,默认为SWOOLE_PROCESS多进程模式) + * @access public + */ + public $mode = 0; + + /** + * @var array $ports + * 当监听多端口时的端口列表 + * @access public + */ + public $ports = array(); /** * @var int $master_pid - * 返回当前服务器主进程的PID + * 主进程ID * @access public */ public $master_pid = 0; /** * @var int $manager_pid - * 返回当前服务器管理进程的PID + * 管理进程ID * @access public */ public $manager_pid = 0; /** * @var int $worker_id - * 得到当前Worker进程的编号,包括Task进程 + * 当前工作进程(包括worker进程和task进程)编号 * @access public */ - public $worker_id = 0; + public $worker_id = -1; /** - * @var int $worker_pid - * 得到当前Worker进程的操作系统进程ID。与posix_getpid()的返回值相同 + * @var boolean $taskworker + * 当前进程是否是task工作进程 * @access public */ - public $worker_pid = 0; + public $taskworker = ''; /** - * @var bool $taskworker - * 是否为任务进程(true表示当前的进程是Task工作进程;false表示当前的进程是Worker进程) + * @var int $worker_pid + * 当前工作进程ID(操作系统进程) * @access public */ - public $taskworker = 0; + public $worker_pid = 0; /** - * @var array $connections - * TCP连接迭代器,可以使用foreach遍历服务器当前所有的连接,此属性的功能与swoole_server->connnection_list是一致的,但是更加友好。遍历的元素为单个连接的fd - * @access public + * + *swoole_server初始化方法 + * @example + * @param string $host 主机IP + * @param int $port 端口 + * @param int $mode 运行模式 + * @param int $sock_type socket类型 + * @return */ - public $connections; + public function __construct(string $host, int $port, int $mode, int $sock_type) + { + + } /** * - *创建一个swoole tcp/udp server对象 + *析构函数 * @example - * @param string $host 创建一个swoole tcp/udp server对象 - * @param int $port 创建一个swoole tcp/udp server对象 - * @param int $mode 创建一个swoole tcp/udp server对象 - * @param int $sock_type 创建一个swoole tcp/udp server对象 * @return */ - public function __construct($host, $port, $mode, $sock_type) + public function __destruct() { + } /** * - *监听一个新的Server端口,此方法是addlistener的别名 + *添加监听端口(是addlistener的别名) * @example - * @param string $host 监听一个新的Server端口,此方法是addlistener的别名 - * @param int $port 监听一个新的Server端口,此方法是addlistener的别名 - * @param int $sock_type 监听一个新的Server端口,此方法是addlistener的别名 + * @param string $host 监听的主机 + * @param int $port 监听的端口号 + * @param int $sock_type socket类型 * @return */ - public function listen($host, $port, $sock_type) + public function listen(string $host, int $port, int $sock_type) { + } /** * - *监听一个新的Server端口,此方法是addlistener的别名 + *添加监听端口 * @example - * @param string $host 监听一个新的Server端口,此方法是addlistener的别名 - * @param int $port 监听一个新的Server端口,此方法是addlistener的别名 - * @param int $sock_type 监听一个新的Server端口,此方法是addlistener的别名 + * @param string $host 监听的主机 + * @param int $port 监听的端口号 + * @param int $sock_type socket类型 * @return */ - public function addlistener($host, $port, $sock_type) + public function addlistener(string $host, int $port, int $sock_type) { + } /** * - *注册Server的事件回调函数 + *绑定事件(为事件注册函数) * @example - * @param string $event_name 注册Server的事件回调函数 - * @param callable $callback 注册Server的事件回调函数 - * @return bool + * @param string $event_name 事件名称 + * @param callable $callback 事件对应的回调函数 + * @return */ - public function on($event_name, Callable $callback) + public function on(string $event_name, Callable $callback) { + } /** * - *设置选项 + *设置swoole_server运行时的参数 * @example - * @param array $settings 设置选项 + * @param array $settings 配置选项 * @return */ public function set(Array $settings) { + } /** * - *启动server,监听所有TCP/UDP端口 + *启动server * @example - * @return bool + * @return */ public function start() { + } /** * *向客户端发送数据 * @example - * @param int $fd 向客户端发送数据 - * @param string $send_data 向客户端发送数据 - * @param int $reactor_id 向客户端发送数据 - * @return bool + * @param int $fd 连接句柄 + * @param string $send_data 发送的数据 + * @param int $reactor_id UDP服务器使用$fd保存客户端IP,$extraData保存server_fd和port + * @return */ - public function send($fd, $send_data, $reactor_id) + public function send(int $fd, string $send_data, int $reactor_id) { + } /** * - *向任意的客户端IP:PORT发送UDP数据包 + *向任意客户端发送UDP数据包 * @example - * @param string $ip 向任意的客户端IP:PORT发送UDP数据包 - * @param int $port 向任意的客户端IP:PORT发送UDP数据包 - * @param string $send_data 向任意的客户端IP:PORT发送UDP数据包 - * @param int $server_socket 向任意的客户端IP:PORT发送UDP数据包 - * @return bool + * @param string $ip IPv4字符串,如192.168.1.102。如果IP不合法会返回错误 + * @param int $port 为 1-65535的网络端口号,如果端口错误发送会失败 + * @param string $send_data 发送的数据内容,可以是文本或者二进制内容 + * @param int $server_socket 服务器可能会同时监听多个UDP端口,此参数可以指定使用哪个端口发送数据包 + * @return */ - public function sendto($ip, $port, $send_data, $server_socket) + public function sendto(string $ip, int $port, string $send_data, int $server_socket) { + } /** * - *阻塞地向客户端发送数据 + *阻塞的向客户端发送数据 * @example - * @param int $conn_fd 阻塞地向客户端发送数据 - * @param string $send_data 阻塞地向客户端发送数据 - * @return bool + * @param int $conn_fd 与客户端连接的句柄 + * @param string $send_data 发送的数据 + * @return */ - public function sendwait($conn_fd, $send_data) + public function sendwait(int $conn_fd, string $send_data) { + } /** * *检测fd对应的连接是否存在 * @example - * @param int $fd 检测fd对应的连接是否存在 - * @return bool + * @param int $fd 连接句柄 + * @return */ - public function exist($fd) + public function exist(int $fd) { + } /** * - *用于保护某些连接不被心跳线程切断 + *设置客户端连接为保护状态,不被心跳线程切断 * @example - * @param int $fd 用于保护某些连接不被心跳线程切断 - * @param bool $is_protected 用于保护某些连接不被心跳线程切断 + * @param int $fd 要设置保护状态的客户端连接fd + * @param boolean $is_protected 设置的状态,true表示保护状态,false表示不保护 * @return */ - public function protect($fd, $is_protected) + public function protect(int $fd, bool $is_protected) { + } /** * - *发送文件到TCP客户端连接 + *向客户端发送文件 * @example - * @param int $conn_fd 发送文件到TCP客户端连接 - * @param string $filename 发送文件到TCP客户端连接 - * @param int $offset 发送文件到TCP客户端连接 - * @return bool + * @param int $conn_fd 连接句柄 + * @param string $filename 文件名 + * @param int $offset 指定文件偏移量,可以从文件的某个位置起发送数据。默认为0,表示从文件头部开始发送 + * @param int $length 指定发送的长度,默认为文件尺寸 + * @return */ - public function sendfile($conn_fd, $filename, $offset) + public function sendfile(int $conn_fd, string $filename, int $offset, int $length) { + } /** * *关闭客户端连接 * @example - * @param int $fd 关闭客户端连接 - * @param bool $reset 关闭客户端连接 + * @param int $fd 连接句柄 + * @param boolean $reset 设置为true会强制关闭连接,丢弃发送队列中的数据 * @return */ - public function close($fd, $reset) + public function close(int $fd, bool $reset) { + } /** * - *连接确认 + *确认连接,与enable_delay_receive或wait_for_bind配合使用 * @example - * @param int $fd 连接确认 + * @param int $fd 连接句柄 * @return */ - public function confirm($fd) + public function confirm(int $fd) { + } /** * *停止接收数据 * @example - * @param int $fd 停止接收数据 + * @param int $fd 连接句柄 * @return */ - public function pause($fd) + public function pause(int $fd) { + } /** * - *恢复数据接收 + *恢复数据接收。与pause方法成对使用 * @example - * @param int $fd 恢复数据接收 + * @param int $fd 连接句柄 * @return */ - public function resume($fd) + public function resume(int $fd) { + } /** * - *投递一个异步任务到task_worker池中。此函数是非阻塞的,执行完毕会立即返回 + *投递一个任务到task_worker连接池中 * @example - * @param mixed $data 投递一个异步任务到task_worker池中。此函数是非阻塞的,执行完毕会立即返回 - * @param int $worker_id 投递一个异步任务到task_worker池中。此函数是非阻塞的,执行完毕会立即返回 - * @param callable $finish_callback 投递一个异步任务到task_worker池中。此函数是非阻塞的,执行完毕会立即返回 + * @param mixed $data 要投递的任务数据,可以为除资源类型之外的任意PHP变量 + * @param int $worker_id 可以制定要给投递给哪个task进程,传入ID即可 + * @param callable $finish_callback 完成后的回调函数 * @return */ - public function task($data, $worker_id, Callable $finish_callback) + public function task($data, int $worker_id, Callable $finish_callback) { + } /** * - *用于投递一个异步的任务到task进程池去执行。与task不同的是taskwait是阻塞等待的,直到任务完成或者超时返回。 + *以阻塞的形式投递一个任务到task_worker连接池中 * @example - * @param mixed $data 用于投递一个异步的任务到task进程池去执行。与task不同的是taskwait是阻塞等待的,直到任务完成或者超时返回。 - * @param float $timeout 用于投递一个异步的任务到task进程池去执行。与task不同的是taskwait是阻塞等待的,直到任务完成或者超时返回。 - * @param int $worker_id 用于投递一个异步的任务到task进程池去执行。与task不同的是taskwait是阻塞等待的,直到任务完成或者超时返回。 + * @param mixed $data 要投递的任务数据,可以为除资源类型之外的任意PHP变量 + * @param float $timeout 超时时间 + * @param int $worker_id 可以制定要给投递给哪个task进程,传入ID即可 * @return */ - public function taskwait($data, $timeout, $worker_id) + public function taskwait($data, float $timeout, int $worker_id) { + } /** * *并发执行多个Task * @example - * @param array $tasks 并发执行多个Task - * @param double $timeout 并发执行多个Task + * @param array $tasks 必须为数字索引数组,不支持关联索引数组,底层会遍历$tasks将任务逐个投递到Task进程 + * @param double $timeout 超时时间 * @return */ - public function taskWaitMulti(Array $tasks, $timeout) + public function taskWaitMulti(Array $tasks, double $timeout) { + } /** * - *此函数用于在task进程中通知worker进程,投递的任务已完成。此函数可以传递结果数据给worker进程 + *并发执行Task并进行协程调度 * @example - * @param string $data 此函数用于在task进程中通知worker进程,投递的任务已完成。此函数可以传递结果数据给worker进程 - * @return + * @param array $tasks 必须为数字索引数组,不支持关联索引数组,底层会遍历$tasks将任务逐个投递到Task进程 + * @param double $timeout 超时时间 + * @return array */ - public function finish($data) + public function taskCo(Array $tasks, double $timeout): array { + } /** * - *重启所有worker进程 + *用于在task进程中通知worker进程任务已完成 * @example + * @param string $data 要传递的数据 * @return */ - public function reload() + public function finish(string $data) + { + + } + + /** + * + *重启所有工作进程 + * @example + * @return boolean + */ + public function reload(): boolean { + } /** @@ -319,178 +519,219 @@ public function reload() */ public function shutdown() { + } /** * - *使当前worker进程停止运行,并立即触发onWorkerStop回调函数 + *停止当前worker进程 * @example - * @param int $worker_id 使当前worker进程停止运行,并立即触发onWorkerStop回调函数 + * @param int $worker_id 进程ID * @return */ - public function stop($worker_id) + public function stop(int $worker_id) { + } /** * - *获取最近一次操作错误的错误码。业务代码中可以根据错误码类型执行不同的逻辑。 + *获取最近一次操作错误的错误码 + *返回的错误码: + *1001 连接已经被Server端关闭了,出现这个错误一般是代码中已经执行了$serv->close()关闭了某个连接,但仍然调用$serv->send()向这个连接发送数据 * @example - * @return int + * @return */ public function getLastError() { + } /** * - *检测服务器所有连接,并找出已经超过约定时间的连接。如果指定if_close_connection,则自动关闭超时的连接。未指定仅返回连接的fd数组。 + *检测所有服务器连接,并找出已经超时的连接 * @example - * @param mixed $reactor_id + * @param boolean $reactor_id 是否关闭超时的连接,默认为true * @return */ - public function heartbeat($reactor_id) + public function heartbeat(bool $reactor_id) { + } /** * - *获取连接的信息 + *获取客户端连接信息 * @example - * @param int $fd 获取连接的信息 - * @param int $reactor_id 获取连接的信息 - * @return + * @param mixed $fd 连接句柄 + * @param int $reactor_id reactor线程id + * @return from_id */ - public function connection_info($fd, $reactor_id) + public function connection_info($fd, int $reactor_id): from_id { + } /** * - *用来遍历当前Server所有的客户端连接 + *用来遍历所有客户端连接 * @example - * @param int $start_fd 用来遍历当前Server所有的客户端连接 - * @param int $find_count 用来遍历当前Server所有的客户端连接 + * @param int $start_fd 起始fd + * @param int $find_count 每页取多少条 * @return */ - public function connection_list($start_fd, $find_count) + public function connection_list(int $start_fd, int $find_count) { + } /** * - *获取连接的信息 + *获取连接的信息,别名是swoole_server->connection_info * @example - * @param int $fd 获取连接的信息 - * @param int $reactor_id 获取连接的信息 + * @param mixed $fd 连接句柄 + * @param int $reactor_id reactor线程id * @return */ - public function getClientInfo($fd, $reactor_id) + public function getClientInfo($fd, int $reactor_id) { + } /** * - *用来遍历当前Server所有的客户端连接 + *用来遍历所有客户端连接(server->connection_list的别名) * @example - * @param int $start_fd 用来遍历当前Server所有的客户端连接 - * @param int $find_count 用来遍历当前Server所有的客户端连接 + * @param int $start_fd 起始fd + * @param int $find_count 每页取多少条 * @return */ - public function getClientList($start_fd, $find_count) + public function getClientList(int $start_fd, int $find_count) { + } /** * - *在指定的时间后执行函数 + *在指定时间后执行某个回调函数 * @example - * @param int $ms 在指定的时间后执行函数 - * @param callable $callback 在指定的时间后执行函数 - * @param array $param 在指定的时间后执行函数 + * @param int $ms 指定时间,单位为毫秒 + * @param callable $callback 回调函数 + * @param array $param 给回调函数传入的参数 * @return */ - public function after($ms, Callable $callback, Array $param) + public function after(int $ms, Callable $callback, Array $param) { + } /** * - *tick定时器,可以自定义回调函数 + *添加定时器 * @example - * @param int $ms tick定时器,可以自定义回调函数 - * @param callable $callback tick定时器,可以自定义回调函数 + * @param int $ms 指定时间,单位为毫秒 + * @param callable $callback 回调函数 * @return */ - public function tick($ms, Callable $callback) + public function tick(int $ms, Callable $callback) { + } /** * - *清除tick/after定时器,此函数是swoole_timer_clear的别名 + *清除定时器 * @example - * @param int $timer_id 清除tick/after定时器,此函数是swoole_timer_clear的别名 + * @param int $timer_id 定时器ID * @return */ - public function clearTimer($timer_id) + public function clearTimer(int $timer_id) { + } /** * - *延后执行一个PHP函数。Swoole底层会在EventLoop循环完成后执行此函数。此函数的目的是为了让一些PHP代码延后执行,程序优先处理IO事件 + *延迟执行一个PHP函数 * @example - * @param callable $callback 延后执行一个PHP函数。Swoole底层会在EventLoop循环完成后执行此函数。此函数的目的是为了让一些PHP代码延后执行,程序优先处理IO事件 + * @param callable $callback 执行的函数 * @return */ public function defer(Callable $callback) { + } /** * - *此函数可以向任意worker进程或者task进程发送消息。在非主进程和管理进程中可调用。收到消息的进程会触发onPipeMessage事件。 + *向任意worker进程或task进程发送消息 * @example - * @param int $dst_worker_id 此函数可以向任意worker进程或者task进程发送消息。在非主进程和管理进程中可调用。收到消息的进程会触发onPipeMessage事件。 - * @param string $data 此函数可以向任意worker进程或者task进程发送消息。在非主进程和管理进程中可调用。收到消息的进程会触发onPipeMessage事件。 + * @param int $dst_worker_id 目标worker的ID + * @param string $data 发送的消息 * @return */ - public function sendMessage($dst_worker_id, $data) + public function sendMessage(int $dst_worker_id, string $data) { + } /** * - *添加一个用户自定义的工作进程 + *添加一个自定义的工作进程 * @example - * @param object $process 添加一个用户自定义的工作进程 + * @param Swoole\Process $process 进程对象 * @return */ - public function addProcess($process) + public function addProcess(Swoole\Process $process) { + } /** * - *得到当前Server的活动TCP连接数,启动时间,accpet/close的总次数等信息 + *得到当前server的活动TCP连接数 + *array ( * @example - * @return array + * @return */ public function stats() { + + } + + /** + * + *将连接绑定到某个用户定义的ID + * @example + * @param int $fd 连接句柄 + * @param int $uid 用户定义的ID + * @return + */ + public function bind(int $fd, int $uid) + { + + } + + /** + * + *序列化函数调用的魔术方法(在PHP进行序列化时,serialize() 检查类中是否有 __sleep() ,如果有,则该函数将在任何序列化之前运行。该函数必须返回一个需要进行序列化保存的成员属性数组,并且只序列化该函数返回的这些成员属性. 该函数有两个作用: 第一. 在序列化之前,关闭对象可能具有的任何数据库连接等. 第二. 指定对象中需要被序列化的成员属性,如果某个属性比较大而不需要储存下来,可以不把它写进__sleep要返回的数组中,这样该属性就不会被序列化) + * @example + * @return + */ + public function __sleep() + { + } /** * - *将连接绑定一个用户定义的ID,可以设置dispatch_mode=5设置已此ID值进行hash固定分配。可以保证某一个UID的连接全部会分配到同一个Worker进程 + *反序列化函数调用的魔术方法(unserialize() 从字节流中创建了一个对象之后,马上检查是否具有__wakeup 的函数的存在。如果存在,__wakeup 立刻被调用。使用 __wakeup 的目的是重建在序列化中可能丢失的任何数据库连接以及处理其它重新初始化的任务) * @example - * @param int $fd 将连接绑定一个用户定义的ID,可以设置dispatch_mode=5设置已此ID值进行hash固定分配。可以保证某一个UID的连接全部会分配到同一个Worker进程 - * @param int $uid 将连接绑定一个用户定义的ID,可以设置dispatch_mode=5设置已此ID值进行hash固定分配。可以保证某一个UID的连接全部会分配到同一个Worker进程 * @return */ - public function bind($fd, $uid) + public function __wakeup() { + } } diff --git a/src/Swoole/swoole_server_port.php b/src/Swoole/swoole_server_port.php index 750b9dc..0a86caf 100644 --- a/src/Swoole/swoole_server_port.php +++ b/src/Swoole/swoole_server_port.php @@ -1,15 +1,127 @@ column('id', swoole_table::TYPE_INT, 4); //1,2,4,8 - * $table->column('name', swoole_table::TYPE_STRING, 64); - * $table->column('num', swoole_table::TYPE_FLOAT); - * $table->create(); + *创建内存表(在使用column创建内存表结构时执行) + * @example * @return */ public function create() { + } /** @@ -71,137 +71,233 @@ public function create() */ public function destroy() { + } /** * - *设置行的数据,swoole_table使用key-value的方式来访问数据。 - * @example - * @param string $key 设置行的数据,swoole_table使用key-value的方式来访问数据。 - * @param array $value 设置行的数据,swoole_table使用key-value的方式来访问数据。 + *设置行的数据 + * @example $table->set('hello@qq.com', array('id' => 189, 'name' => 'rango3', 'num' => 3.1415)); + * @param string $key 数据的key,相同的$key对应同一行数据,如果set同一个key,会覆盖上一次的数据 + * @param array $value 必须是一个数组,必须与字段定义的$name完全相同 * @return */ - public function set($key, Array $value) + public function set(string $key, Array $value) { + } /** * *获取一行数据 * @example - * @param string $key 获取一行数据 - * @return array + * @param string $key 设置的key值 + * @param string $field 字段值 + * @return */ - public function get($key) + public function get(string $key, string $field) { + } /** * - *获取键的数量 + *获取数据行数 * @example * @return int */ - public function count() + public function count(): int { + } /** * - *删除指定key的值 + *删除数据 * @example - * @param string $key 删除指定key的值 - * @return boolean + * @param string $key 要删除的键 + * @return */ - public function del($key) + public function del(string $key) { + } /** * *检查table中是否存在某一个key * @example - * @param string $key 检查table中是否存在某一个key - * @return boolean + * @param mixed $key + * @return */ public function exist($key) { + } /** * *原子自增操作 * @example - * @param string $key 原子自增操作 - * @param number $column 原子自增操作 - * @param mixed $incrby 原子自增操作 + * @param string $key 指定数据的key,如果$key对应的行不存在,默认列的值为0 + * @param string $column 指定列名,仅支持浮点型和整型字段 + * @param mixed $incrby 增量,默认为1。如果列为整形,$incrby必须为int型,如果列为浮点型,$incrby必须为float类型失败返回false,成功返回最终的结果数值 * @return */ - public function incr($key, $column, $incrby) + public function incr(string $key, string $column, $incrby) { + } /** * *原子自减操作 * @example - * @param string $key 原子自减操作 - * @param number $column 原子自减操作 - * @param mixed $decrby 原子自减操作 + * @param string $key 指定数据的key,如果$key对应的行不存在,默认列的值为0 + * @param string $column 指定列名,仅支持浮点型和整型字段 + * @param mixed $decrby 减量,默认为1。如果列为整形,$decrby必须为int型,如果列为浮点型,$decrby必须为float类型失败返回false,成功返回最终的结果数值 + * @return + */ + public function decr(string $key, string $column, $decrby) + { + + } + + /** + * + *获取table占用的内存大小 + * @example + * @return int + */ + public function getMemorySize(): int + { + + } + + /** + * + *检查一个偏移位置是否存在 + * @example + * @param int $offset 偏移量 + * @return + */ + public function offsetExists(int $offset) + { + + } + + /** + * + *取一个偏移位置的值 + * @example + * @param int $offset 偏移量 * @return */ - public function decr($key, $column, $decrby) + public function offsetGet(int $offset) { + + } + + /** + * + *设置一个偏移位置的值(来自ArrayAccess接口) + * @example + * @param int $offset 偏移量 + * @param mixed $value 需要设置的值 + * @return + */ + public function offsetSet(int $offset, $value) + { + + } + + /** + * + *复位一个偏移位置的值 + * @example + * @param int $offset 偏移量 + * @return + */ + public function offsetUnset(int $offset) + { + + } + + /** + * + *序列化函数调用的魔术方法(在PHP进行序列化时,serialize() 检查类中是否有 __sleep() ,如果有,则该函数将在任何序列化之前运行。该函数必须返回一个需要进行序列化保存的成员属性数组,并且只序列化该函数返回的这些成员属性. 该函数有两个作用: 第一. 在序列化之前,关闭对象可能具有的任何数据库连接等. 第二. 指定对象中需要被序列化的成员属性,如果某个属性比较大而不需要储存下来,可以不把它写进__sleep要返回的数组中,这样该属性就不会被序列化) + * @example + * @return + */ + public function __sleep() + { + + } + + /** + * + *反序列化函数调用的魔术方法(unserialize() 从字节流中创建了一个对象之后,马上检查是否具有__wakeup 的函数的存在。如果存在,__wakeup 立刻被调用。使用 __wakeup 的目的是重建在序列化中可能丢失的任何数据库连接以及处理其它重新初始化的任务) + * @example + * @return + */ + public function __wakeup() + { + } /** * *返回到迭代器的第一个元素 * @example - * @return void + * @return */ public function rewind() { + } /** * - *向前移动到下一个元素 + *向前移动到下一个元素(此方法在 foreach 循环之后被调用) * @example - * @return void + * @return */ public function next() { + } /** * - *返回当前元素 + *返回迭代器当前元素 * @example - * @return mixed + * @return */ public function current() { + } /** * *返回当前元素的键 * @example - * @return scalar + * @return mixed */ public function key() { + } /** * - *此方法在 rewind() 和 next() 方法之后被调用以此用来检查当前位置是否有效 + *检查当前位置是否有效(迭代器方法,此方法在 Iterator::rewind() 和 Iterator::next() 方法之后被调用以此用来检查当前位置是否有效) * @example * @return boolean */ - public function valid() + public function valid(): boolean { + } } diff --git a/src/Swoole/swoole_table_row.php b/src/Swoole/swoole_table_row.php new file mode 100644 index 0000000..9c831cb --- /dev/null +++ b/src/Swoole/swoole_table_row.php @@ -0,0 +1,88 @@ +finish()方法将任务处理的结果发送给worker进程。 + * @access public + */ + public $onFinish; + + /** + * @var callable $onManagerStart + * 当管理进程启动时调用它 + * @access public + */ + public $onManagerStart; + + /** + * @var callable $onManagerStop + * 当管理进程结束时调用它 + * @access public + */ + public $onManagerStop; + + /** + * @var callable $onPipeMessage + * 当工作进程收到由 sendMessage 发送的管道消息时会触发onPipeMessage事件 + * @access public + */ + public $onPipeMessage; + + /** + * @var iterator $connections + * TCP连接迭代器 + * @access public + */ + public $connections; + + /** + * @var string $host + * 连接的主机 + * @access public + */ + public $host; + + /** + * @var int $port + * 连接的主机的端口 + * @access public + */ + public $port = 0; + + /** + * @var int $type + * socket的类型 + * @access public + */ + public $type = 0; + + /** + * @var int $mode + * 运行模式(swoole提供了3种运行模式,默认为SWOOLE_PROCESS多进程模式) + * @access public + */ + public $mode = 0; + + /** + * @var array $ports + * 当监听多端口时的端口列表 + * @access public + */ + public $ports = array(); + + /** + * @var int $master_pid + * 主进程ID + * @access public + */ + public $master_pid = 0; + + /** + * @var int $manager_pid + * 管理进程ID + * @access public + */ + public $manager_pid = 0; + + /** + * @var int $worker_id + * 当前工作进程(包括worker进程和task进程)编号 + * @access public + */ + public $worker_id = -1; + + /** + * @var boolean $taskworker + * 当前进程是否是task工作进程 + * @access public + */ + public $taskworker = ''; + + /** + * @var int $worker_pid + * 当前工作进程ID(操作系统进程) + * @access public + */ + public $worker_pid = 0; + + /** + * @var callable $onRequest + * 请求回调函数 + * @access public + */ + public $onRequest; + + /** + * @var callable $onHandshake + * TCP握手时的回调函数 + * @access public + */ + public $onHandshake; + + /** + * @var array $setting + * 通过swoole_server:set()设置的参数会保存到setting属性上 + * @access public + */ + public $setting = array(); + /** * - *为事件绑定某个函数 + *绑定事件(为事件注册函数) * @example - * @param string $event_name 为事件绑定某个函数 - * @param callable $callback 为事件绑定某个函数 + * @param string $event_name 事件名称 + * @param callable $callback 事件对应的回调函数 * @return */ - public function on($event_name, Callable $callback) + public function on(string $event_name, Callable $callback) { + } /** * *向websocket客户端连接推送数据,长度最大不得超过2M * @example - * @param int $fd 向websocket客户端连接推送数据,长度最大不得超过2M - * @param string $data 向websocket客户端连接推送数据,长度最大不得超过2M - * @param int $opcode 向websocket客户端连接推送数据,长度最大不得超过2M - * @param boolean $finish 向websocket客户端连接推送数据,长度最大不得超过2M + * @param int $fd 客户端连接的ID,如果指定的$fd对应的TCP连接并非websocket客户端,将会发送失败 + * @param string $data 要发送的数据内容 + * @param int $opcode 指定发送数据内容的格式,默认为文本。发送二进制内容$opcode参数需要设置 + * @param boolean $finish 帧是否完成 * @return */ - public function push($fd, $data, $opcode, $finish) + public function push(int $fd, string $data, int $opcode, bool $finish) { + } /** * *检测fd对应的连接是否存在 * @example - * @param int $fd 检测fd对应的连接是否存在 - * @return bool + * @param int $fd 连接句柄 + * @return */ - public function exist($fd) + public function exist(int $fd) { + } /** * - *打包websocket数据帧 + *打包数据 * @example - * @param string $data 打包websocket数据帧 - * @param mixed $opcode - * @param mixed $finish - * @param mixed $mask + * @param string $data 消息内容 + * @param int $opcode WebSocket的opcode指令类型,1表示文本,2表示二进制数据,9表示心跳ping + * @param boolean $finish 帧是否完成 + * @param boolean $mask 是否设置掩码 * @return */ - public static function pack($data, $opcode, $finish, $mask) + public static function pack(string $data, int $opcode, bool $finish, bool $mask) { + } /** * - *解包websocket数据帧 + *参数据进行解包 * @example - * @param string $data 解包websocket数据帧 + * @param string $data 解包的数据 * @return */ - public static function unpack($data) + public static function unpack(string $data) { + } /** * - *启动websocket server + *启动server * @example - * @return bool + * @return */ public function start() { + + } + + /** + * + *序列化函数调用的魔术方法(在PHP进行序列化时,serialize() 检查类中是否有 __sleep() ,如果有,则该函数将在任何序列化之前运行。该函数必须返回一个需要进行序列化保存的成员属性数组,并且只序列化该函数返回的这些成员属性. 该函数有两个作用: 第一. 在序列化之前,关闭对象可能具有的任何数据库连接等. 第二. 指定对象中需要被序列化的成员属性,如果某个属性比较大而不需要储存下来,可以不把它写进__sleep要返回的数组中,这样该属性就不会被序列化) + * @example + * @return + */ + public function __sleep() + { + + } + + /** + * + *反序列化函数调用的魔术方法(unserialize() 从字节流中创建了一个对象之后,马上检查是否具有__wakeup 的函数的存在。如果存在,__wakeup 立刻被调用。使用 __wakeup 的目的是重建在序列化中可能丢失的任何数据库连接以及处理其它重新初始化的任务) + * @example + * @return + */ + public function __wakeup() + { + + } + + /** + * + *swoole_server初始化方法 + * @example + * @param string $host 主机IP + * @param int $port 端口 + * @param int $mode 运行模式 + * @param int $sock_type socket类型 + * @return + */ + public function __construct(string $host, int $port, int $mode, int $sock_type) + { + } /** * - *创建一个swoole tcp/udp server对象 + *析构函数 * @example - * @param string $host 创建一个swoole tcp/udp server对象 - * @param int $port 创建一个swoole tcp/udp server对象 - * @param int $mode 创建一个swoole tcp/udp server对象 - * @param int $sock_type 创建一个swoole tcp/udp server对象 * @return */ - public function __construct($host, $port, $mode, $sock_type) + public function __destruct() { + } /** * - *监听一个新的Server端口,此方法是addlistener的别名 + *添加监听端口(是addlistener的别名) * @example - * @param string $host 监听一个新的Server端口,此方法是addlistener的别名 - * @param int $port 监听一个新的Server端口,此方法是addlistener的别名 - * @param int $sock_type 监听一个新的Server端口,此方法是addlistener的别名 + * @param string $host 监听的主机 + * @param int $port 监听的端口号 + * @param int $sock_type socket类型 * @return */ - public function listen($host, $port, $sock_type) + public function listen(string $host, int $port, int $sock_type) { + } /** * - *监听一个新的Server端口,此方法是addlistener的别名 + *添加监听端口 * @example - * @param string $host 监听一个新的Server端口,此方法是addlistener的别名 - * @param int $port 监听一个新的Server端口,此方法是addlistener的别名 - * @param int $sock_type 监听一个新的Server端口,此方法是addlistener的别名 + * @param string $host 监听的主机 + * @param int $port 监听的端口号 + * @param int $sock_type socket类型 * @return */ - public function addlistener($host, $port, $sock_type) + public function addlistener(string $host, int $port, int $sock_type) { + } /** * - *设置选项 + *设置swoole_server运行时的参数 * @example - * @param array $settings 设置选项 + * @param array $settings 配置选项 * @return */ public function set(Array $settings) { + } /** * *向客户端发送数据 * @example - * @param int $fd 向客户端发送数据 - * @param string $send_data 向客户端发送数据 - * @param int $reactor_id 向客户端发送数据 - * @return bool + * @param int $fd 连接句柄 + * @param string $send_data 发送的数据 + * @param int $reactor_id UDP服务器使用$fd保存客户端IP,$extraData保存server_fd和port + * @return */ - public function send($fd, $send_data, $reactor_id) + public function send(int $fd, string $send_data, int $reactor_id) { + } /** * - *向任意的客户端IP:PORT发送UDP数据包 + *向任意客户端发送UDP数据包 * @example - * @param string $ip 向任意的客户端IP:PORT发送UDP数据包 - * @param int $port 向任意的客户端IP:PORT发送UDP数据包 - * @param string $send_data 向任意的客户端IP:PORT发送UDP数据包 - * @param int $server_socket 向任意的客户端IP:PORT发送UDP数据包 - * @return bool + * @param string $ip IPv4字符串,如192.168.1.102。如果IP不合法会返回错误 + * @param int $port 为 1-65535的网络端口号,如果端口错误发送会失败 + * @param string $send_data 发送的数据内容,可以是文本或者二进制内容 + * @param int $server_socket 服务器可能会同时监听多个UDP端口,此参数可以指定使用哪个端口发送数据包 + * @return */ - public function sendto($ip, $port, $send_data, $server_socket) + public function sendto(string $ip, int $port, string $send_data, int $server_socket) { + } /** * - *阻塞地向客户端发送数据 + *阻塞的向客户端发送数据 * @example - * @param int $conn_fd 阻塞地向客户端发送数据 - * @param string $send_data 阻塞地向客户端发送数据 - * @return bool + * @param int $conn_fd 与客户端连接的句柄 + * @param string $send_data 发送的数据 + * @return */ - public function sendwait($conn_fd, $send_data) + public function sendwait(int $conn_fd, string $send_data) { + } /** * - *用于保护某些连接不被心跳线程切断 + *设置客户端连接为保护状态,不被心跳线程切断 * @example - * @param int $fd 用于保护某些连接不被心跳线程切断 - * @param bool $is_protected 用于保护某些连接不被心跳线程切断 + * @param int $fd 要设置保护状态的客户端连接fd + * @param boolean $is_protected 设置的状态,true表示保护状态,false表示不保护 * @return */ - public function protect($fd, $is_protected) + public function protect(int $fd, bool $is_protected) { + } /** * - *发送文件到TCP客户端连接 + *向客户端发送文件 * @example - * @param int $conn_fd 发送文件到TCP客户端连接 - * @param string $filename 发送文件到TCP客户端连接 - * @param int $offset 发送文件到TCP客户端连接 - * @return bool + * @param int $conn_fd 连接句柄 + * @param string $filename 文件名 + * @param int $offset 指定文件偏移量,可以从文件的某个位置起发送数据。默认为0,表示从文件头部开始发送 + * @param int $length 指定发送的长度,默认为文件尺寸 + * @return */ - public function sendfile($conn_fd, $filename, $offset) + public function sendfile(int $conn_fd, string $filename, int $offset, int $length) { + } /** * *关闭客户端连接 * @example - * @param int $fd 关闭客户端连接 - * @param bool $reset 关闭客户端连接 + * @param int $fd 连接句柄 + * @param boolean $reset 设置为true会强制关闭连接,丢弃发送队列中的数据 * @return */ - public function close($fd, $reset) + public function close(int $fd, bool $reset) { + } /** * - *连接确认 + *确认连接,与enable_delay_receive或wait_for_bind配合使用 * @example - * @param int $fd 连接确认 + * @param int $fd 连接句柄 * @return */ - public function confirm($fd) + public function confirm(int $fd) { + } /** * *停止接收数据 * @example - * @param int $fd 停止接收数据 + * @param int $fd 连接句柄 * @return */ - public function pause($fd) + public function pause(int $fd) { + } /** * - *恢复数据接收 + *恢复数据接收。与pause方法成对使用 * @example - * @param int $fd 恢复数据接收 + * @param int $fd 连接句柄 * @return */ - public function resume($fd) + public function resume(int $fd) { + } /** * - *投递一个异步任务到task_worker池中。此函数是非阻塞的,执行完毕会立即返回 + *投递一个任务到task_worker连接池中 * @example - * @param mixed $data 投递一个异步任务到task_worker池中。此函数是非阻塞的,执行完毕会立即返回 - * @param int $worker_id 投递一个异步任务到task_worker池中。此函数是非阻塞的,执行完毕会立即返回 - * @param callable $finish_callback 投递一个异步任务到task_worker池中。此函数是非阻塞的,执行完毕会立即返回 + * @param mixed $data 要投递的任务数据,可以为除资源类型之外的任意PHP变量 + * @param int $worker_id 可以制定要给投递给哪个task进程,传入ID即可 + * @param callable $finish_callback 完成后的回调函数 * @return */ - public function task($data, $worker_id, Callable $finish_callback) + public function task($data, int $worker_id, Callable $finish_callback) { + } /** * - *用于投递一个异步的任务到task进程池去执行。与task不同的是taskwait是阻塞等待的,直到任务完成或者超时返回。 + *以阻塞的形式投递一个任务到task_worker连接池中 * @example - * @param mixed $data 用于投递一个异步的任务到task进程池去执行。与task不同的是taskwait是阻塞等待的,直到任务完成或者超时返回。 - * @param float $timeout 用于投递一个异步的任务到task进程池去执行。与task不同的是taskwait是阻塞等待的,直到任务完成或者超时返回。 - * @param int $worker_id 用于投递一个异步的任务到task进程池去执行。与task不同的是taskwait是阻塞等待的,直到任务完成或者超时返回。 + * @param mixed $data 要投递的任务数据,可以为除资源类型之外的任意PHP变量 + * @param float $timeout 超时时间 + * @param int $worker_id 可以制定要给投递给哪个task进程,传入ID即可 * @return */ - public function taskwait($data, $timeout, $worker_id) + public function taskwait($data, float $timeout, int $worker_id) { + } /** * *并发执行多个Task * @example - * @param array $tasks 并发执行多个Task - * @param double $timeout 并发执行多个Task + * @param array $tasks 必须为数字索引数组,不支持关联索引数组,底层会遍历$tasks将任务逐个投递到Task进程 + * @param double $timeout 超时时间 * @return */ - public function taskWaitMulti(Array $tasks, $timeout) + public function taskWaitMulti(Array $tasks, double $timeout) { + } /** * - *此函数用于在task进程中通知worker进程,投递的任务已完成。此函数可以传递结果数据给worker进程 + *并发执行Task并进行协程调度 * @example - * @param string $data 此函数用于在task进程中通知worker进程,投递的任务已完成。此函数可以传递结果数据给worker进程 - * @return + * @param array $tasks 必须为数字索引数组,不支持关联索引数组,底层会遍历$tasks将任务逐个投递到Task进程 + * @param double $timeout 超时时间 + * @return array */ - public function finish($data) + public function taskCo(Array $tasks, double $timeout): array { + } /** * - *重启所有worker进程 + *用于在task进程中通知worker进程任务已完成 * @example + * @param string $data 要传递的数据 * @return */ - public function reload() + public function finish(string $data) { + + } + + /** + * + *重启所有工作进程 + * @example + * @return boolean + */ + public function reload(): boolean + { + } /** @@ -309,178 +597,197 @@ public function reload() */ public function shutdown() { + } /** * - *使当前worker进程停止运行,并立即触发onWorkerStop回调函数 + *停止当前worker进程 * @example - * @param int $worker_id 使当前worker进程停止运行,并立即触发onWorkerStop回调函数 + * @param int $worker_id 进程ID * @return */ - public function stop($worker_id) + public function stop(int $worker_id) { + } /** * - *获取最近一次操作错误的错误码。业务代码中可以根据错误码类型执行不同的逻辑。 + *获取最近一次操作错误的错误码 + *返回的错误码: + *1001 连接已经被Server端关闭了,出现这个错误一般是代码中已经执行了$serv->close()关闭了某个连接,但仍然调用$serv->send()向这个连接发送数据 * @example - * @return int + * @return */ public function getLastError() { + } /** * - *检测服务器所有连接,并找出已经超过约定时间的连接。如果指定if_close_connection,则自动关闭超时的连接。未指定仅返回连接的fd数组。 + *检测所有服务器连接,并找出已经超时的连接 * @example - * @param mixed $reactor_id + * @param boolean $reactor_id 是否关闭超时的连接,默认为true * @return */ - public function heartbeat($reactor_id) + public function heartbeat(bool $reactor_id) { + } /** * - *获取连接的信息 + *获取客户端连接信息 * @example - * @param int $fd 获取连接的信息 - * @param int $reactor_id 获取连接的信息 - * @return + * @param mixed $fd 连接句柄 + * @param int $reactor_id reactor线程id + * @return from_id */ - public function connection_info($fd, $reactor_id) + public function connection_info($fd, int $reactor_id): from_id { + } /** * - *用来遍历当前Server所有的客户端连接 + *用来遍历所有客户端连接 * @example - * @param int $start_fd 用来遍历当前Server所有的客户端连接 - * @param int $find_count 用来遍历当前Server所有的客户端连接 + * @param int $start_fd 起始fd + * @param int $find_count 每页取多少条 * @return */ - public function connection_list($start_fd, $find_count) + public function connection_list(int $start_fd, int $find_count) { + } /** * - *获取连接的信息 + *获取连接的信息,别名是swoole_server->connection_info * @example - * @param int $fd 获取连接的信息 - * @param int $reactor_id 获取连接的信息 + * @param mixed $fd 连接句柄 + * @param int $reactor_id reactor线程id * @return */ - public function getClientInfo($fd, $reactor_id) + public function getClientInfo($fd, int $reactor_id) { + } /** * - *用来遍历当前Server所有的客户端连接 + *用来遍历所有客户端连接(server->connection_list的别名) * @example - * @param int $start_fd 用来遍历当前Server所有的客户端连接 - * @param int $find_count 用来遍历当前Server所有的客户端连接 + * @param int $start_fd 起始fd + * @param int $find_count 每页取多少条 * @return */ - public function getClientList($start_fd, $find_count) + public function getClientList(int $start_fd, int $find_count) { + } /** * - *在指定的时间后执行函数 + *在指定时间后执行某个回调函数 * @example - * @param int $ms 在指定的时间后执行函数 - * @param callable $callback 在指定的时间后执行函数 - * @param array $param 在指定的时间后执行函数 + * @param int $ms 指定时间,单位为毫秒 + * @param callable $callback 回调函数 + * @param array $param 给回调函数传入的参数 * @return */ - public function after($ms, Callable $callback, Array $param) + public function after(int $ms, Callable $callback, Array $param) { + } /** * - *ick定时器,可以自定义回调函数 + *添加定时器 * @example - * @param int $ms ick定时器,可以自定义回调函数 - * @param callable $callback ick定时器,可以自定义回调函数 + * @param int $ms 指定时间,单位为毫秒 + * @param callable $callback 回调函数 * @return */ - public function tick($ms, Callable $callback) + public function tick(int $ms, Callable $callback) { + } /** * - *清除tick/after定时器,此函数是swoole_timer_clear的别名 + *清除定时器 * @example - * @param int $timer_id 清除tick/after定时器,此函数是swoole_timer_clear的别名 + * @param int $timer_id 定时器ID * @return */ - public function clearTimer($timer_id) + public function clearTimer(int $timer_id) { + } /** * - *延后执行一个PHP函数。Swoole底层会在EventLoop循环完成后执行此函数。此函数的目的是为了让一些PHP代码延后执行,程序优先处理IO事件 + *延迟执行一个PHP函数 * @example - * @param callable $callback 延后执行一个PHP函数。Swoole底层会在EventLoop循环完成后执行此函数。此函数的目的是为了让一些PHP代码延后执行,程序优先处理IO事件 + * @param callable $callback 执行的函数 * @return */ public function defer(Callable $callback) { + } /** * - *此函数可以向任意worker进程或者task进程发送消息。在非主进程和管理进程中可调用。收到消息的进程会触发onPipeMessage事件。 + *向任意worker进程或task进程发送消息 * @example - * @param int $dst_worker_id 此函数可以向任意worker进程或者task进程发送消息。在非主进程和管理进程中可调用。收到消息的进程会触发onPipeMessage事件。 - * @param string $data 此函数可以向任意worker进程或者task进程发送消息。在非主进程和管理进程中可调用。收到消息的进程会触发onPipeMessage事件。 + * @param int $dst_worker_id 目标worker的ID + * @param string $data 发送的消息 * @return */ - public function sendMessage($dst_worker_id, $data) + public function sendMessage(int $dst_worker_id, string $data) { + } /** * - *添加一个用户自定义的工作进程 + *添加一个自定义的工作进程 * @example - * @param object $process 添加一个用户自定义的工作进程 + * @param Swoole\Process $process 进程对象 * @return */ - public function addProcess($process) + public function addProcess(Swoole\Process $process) { + } /** * - *得到当前Server的活动TCP连接数,启动时间,accpet/close的总次数等信息 + *得到当前server的活动TCP连接数 + *array ( * @example - * @return array + * @return */ public function stats() { + } /** * - *将连接绑定一个用户定义的ID,可以设置dispatch_mode=5设置已此ID值进行hash固定分配。可以保证某一个UID的连接全部会分配到同一个Worker进程 + *将连接绑定到某个用户定义的ID * @example - * @param int $fd 将连接绑定一个用户定义的ID,可以设置dispatch_mode=5设置已此ID值进行hash固定分配。可以保证某一个UID的连接全部会分配到同一个Worker进程 - * @param int $uid 将连接绑定一个用户定义的ID,可以设置dispatch_mode=5设置已此ID值进行hash固定分配。可以保证某一个UID的连接全部会分配到同一个Worker进程 + * @param int $fd 连接句柄 + * @param int $uid 用户定义的ID * @return */ - public function bind($fd, $uid) + public function bind(int $fd, int $uid) { + } } diff --git a/src/Yac/Yac.php b/src/Yac/Yac.php index 84538f0..f5e9e60 100644 --- a/src/Yac/Yac.php +++ b/src/Yac/Yac.php @@ -1,38 +1,61 @@ goods = 'apple';//相当于$yac->set('goods', 'apple'); + * @param string $key 键 + * @param mixed $value 值 * @return */ - public function __set($key, $value) + public function __set(string $key, $value) { + } /** * - * - * @example - * @param mixed $keys + *获取某个键的值或某些键的值 + * @example $yac->get('goods'); + * $yac->get(array('goods', 'test')); + * @param mixed $keys 键名 * @return */ public function get($keys) { + } /** * - * - * @example - * @param mixed $key + *获取某个键值的魔术方法 + * @example return $yac->goods;//相当于$yac->get('goods') + * @param string $key 键名 * @return */ - public function __get($key) + public function __get(string $key) { + } /** * - * - * @example - * @param mixed $keys - * @param mixed $ttl + *删除某个键或某几个键 + * @example $yac->delete('goods'); + * $yac->delete(array('goods', 'test')); + * @param mixed $keys 要删除的键 + * @param int $ttl 延迟删除时间 * @return */ - public function delete($keys, $ttl) + public function delete($keys, int $ttl) { + } /** * - * + *刷新缓存,即清空缓存 * @example * @return */ public function flush() { + } /** * - * - * @example - * @return + *获取缓存使用情况等信息 + * @example var_dump($yac->info()); + * array(11) { ["memory_size"]=> int(541065216) + * ["slots_memory_size"]=> int(4194304) + * ["values_memory_size"]=> int(536870912) + * ["segment_size"]=> int(4194304) + * ["segment_num"]=> int(128) + * ["miss"]=> int(0) + * ["hits"]=> int(955) + * ["fails"]=> int(0) + * ["kicks"]=> int(0) + * ["slots_size"]=> int(32768) + * ["slots_used"]=> int(955) + * } + * @return array */ - public function info() + public function info(): array { + } /** * - * + *导出缓存 * @example * @return */ public function dump() { + } } diff --git a/src/Yaconf/Yaconf.php b/src/Yaconf/Yaconf.php index 6fdb58a..27c9405 100644 --- a/src/Yaconf/Yaconf.php +++ b/src/Yaconf/Yaconf.php @@ -1,35 +1,56 @@ = 3.0.2) -*Class YafX_Action_Abstract +*yaf中的操作定义(单独文件定义操作,通常是在控制器文件中定义操作,这里可以通过单独文件来定义操作) */ namespace Yaf; abstract class Action_Abstract extends \Yaf\Controller_Abstract { /** - * @var unknown $actions - * + * @var array $actions + * 操作列表 * @access public - public $actions; + */ + public $actions = array(); /** - * @var unknown $_module - * + * @var string $_module + * 当前模块对象 * @access protected + */ protected $_module; /** - * @var unknown $_name - * + * @var string $_name + * 当前操作名 * @access protected + */ protected $_name; /** - * @var unknown $_request - * + * @var Yaf_Request_Abstract $_request + * 当前请求对象 * @access protected + */ protected $_request; /** - * @var unknown $_response - * + * @var Yaf_Response_Abstract $_response + * 当前响应对象 * @access protected + */ protected $_response; /** - * @var unknown $_invoke_args - * + * @var array $_invoke_args + * 调用参数列表 * @access protected - protected $_invoke_args; + */ + protected $_invoke_args = array(); /** - * @var unknown $_view - * + * @var Yaf_View_Interface $_view + * 当前视图对象 * @access protected + */ protected $_view; /** - * @var unknown $_controller - * (Yaf >= 3.0.2) + * @var Yaf_Controller_Abstract $_controller * 当前请求的控制器实例 * @access protected - protected $_controller; - - /** - * - *(Yaf >= 3.0.2) - *动作入口方法,由Yaf框架自动调用 - * @example - * @return */ - public abstract function execute(); + protected $_controller; /** * - *(Yaf >= 3.0.2) *获取当前请求的控制器实例 * @example - * @return - */ - public function getController() - { - } - - /** - * - * - * @example - * @param mixed $tpl - * @param array $parameters - * @return - */ - protected function render($tpl, Array $parameters) - { - } - - /** - * - * - * @example - * @param mixed $tpl - * @param array $parameters - * @return - */ - protected function display($tpl, Array $parameters) - { - } - - /** - * - * - * @example - * @return - */ - public function getRequest() - { - } - - /** - * - * - * @example - * @return - */ - public function getResponse() - { - } - - /** - * - * - * @example - * @return - */ - public function getModuleName() - { - } - - /** - * - * - * @example - * @return - */ - public function getView() - { - } - - /** - * - * - * @example - * @param array $options - * @return - */ - public function initView(Array $options) - { - } - - /** - * - * - * @example - * @param mixed $view_directory - * @return + * @return Yaf_Action_Abstract */ - public function setViewpath($view_directory) + public function getController(): Yaf_Action_Abstract { + } /** * - * - * @example - * @return - */ - public function getViewpath() - { - } - - /** - * - * - * @example - * @param mixed $module - * @param mixed $controller - * @param mixed $action - * @param array $parameters - * @return - */ - public function forward($module, $controller, $action, Array $parameters) - { - } - - /** - * - * - * @example - * @param mixed $url - * @return - */ - public function redirect($url) - { - } - - /** - * - * - * @example - * @return - */ - public function getInvokeArgs() - { - } - - /** - * - * - * @example - * @param mixed $name - * @return - */ - public function getInvokeArg($name) - { - } - - /** - * - * - * @example - * @return - */ - public final function __construct() - { - } - - /** - * - * + *动作入口方法,由Yaf框架自动调用 * @example - * @return + * @param mixed $arg 参数 + * @param mixed $arg2 参数2 + * @return Yaf_Action_Abstract */ - private final function __clone() - { - } + public abstract function execute($arg, $arg2): Yaf_Action_Abstract; } diff --git a/src/Yaf/Application.php b/src/Yaf/Application.php index a5651d2..0c7b10e 100644 --- a/src/Yaf/Application.php +++ b/src/Yaf/Application.php @@ -1,279 +1,275 @@ = 3.0.2) -*Class YafX_Application +*为应用提供引导和依赖性检查的引导类 */ namespace Yaf; final class Application { /** - * @var unknown $config - * (Yaf >= 3.0.2) + * @var Yaf_Config_Abstract $config * 全局配置实例 * @access protected + */ protected $config; /** - * @var unknown $dispatcher - * (Yaf >= 3.0.2) - * YafX_Dispatcher实例,即分发器. + * @var Yaf_Dispatcher $dispatcher + * yaf_Dispatcher实例,即分发器. * @access protected + */ protected $dispatcher; /** - * @var unknown $_app - * (Yaf >= 3.0.2) + * @var Yaf_Application $_app * 过特殊的方式实现了单例模式, 此属性保存当前实例. * @access protected + */ protected static $_app; /** - * @var unknown $_modules - * (Yaf >= 3.0.2) + * @var array $_modules * 存在的模块名, 从配置文件中ap.modules读取. * @access protected - protected $_modules; + */ + protected $_modules = array(); /** - * @var unknown $_running - * (Yaf >= 3.0.2) - * 指明当前的YafX_Application是否已经运行. + * @var bool $_running + * 指明当前的yaf_Application是否已经运行. * @access protected - protected $_running = ''; + */ + protected $_running = false; /** - * @var unknown $_environ - * (Yaf >= 3.0.2) - * 前的环境名, 也就是YafX_Application在读取配置的时候, 获取的配置节名字. + * @var string $_environ + * 当前的环境名, 也就是yaf_Application在读取配置的时候, 获取的配置节名字. * 注:此值只能在Yaf扩展级的配置文件.ini里面进行修改,默认为product. * @access protected - protected $_environ = 'dev'; + */ + protected $_environ = 'product'; /** - * @var unknown $_err_no - * (Yaf >= 3.0.2) + * @var int $_err_no * 最近一次发生的错误代码. * @access protected + */ protected $_err_no = 0; /** - * @var unknown $_err_msg - * (Yaf >= 3.0.2) + * @var string $_err_msg * 最近一次产生的错误信息. * @access protected + */ protected $_err_msg = ''; /** * - *(Yaf >= 3.0.2) - *构造函数,根据配置初始化YafX_Application + *获取当前的yaf_Application实例. * @example - * @param mixed $config (Yaf >= 3.0.2) -构造函数,根据配置初始化YafX_Application - * @param mixed $environ - * @return + * @return Yaf_Application|null */ - public function __construct($config, $environ) + public static function app(): ?Yaf_Application { + } /** * - *(Yaf >= 3.0.2) - *运行YafX_Application + *调用bootstrap * @example - * @return + * @param Yaf_Bootstrap_Abstract $bootstrap 引导类 + * @return void */ - public function run() + public function bootstrap(Yaf_Bootstrap_Abstract $bootstrap) { + } /** * - *(Yaf >= 3.0.2) - *运行回调函数,一般在命令行模式下运行. + *运行yaf_Application * @example - * @param callable $entry (Yaf >= 3.0.2) -运行回调函数,一般在命令行模式下运行. - * @param mixed $... - * @return + * @return void */ - public function execute(Callable $entry, $...) + public function run() { + } /** * - *(Yaf >= 3.0.2) - *获取当前的YafX_Application实例. + *清除最近的错误信息,将设置$this->_err_no=0,$this->_err_msg=''. * @example - * @return + * @return Yaf_Application */ - public static function app() + public function clearLastError(): Yaf_Application { + } /** * - *(Yaf >= 3.0.2) - *获取当前YafX_Application的环境名,它被定义在yaf.environ,默认值为"product". + *构造函数,根据配置初始化yaf_Application * @example + * @param mixed $config 关联数组的配置, 或者一个指向ini格式的配置文件的路径的字符串. + * @param string $section 加载的配置节点,使用该节点的配置初始化应用. * @return */ - public function environ() + public function __construct($config, string $section = 'product') { + } /** * - *(Yaf >= 3.0.2) - *调用bootstrap + *运行回调函数,一般在命令行模式下运行. * @example - * @param mixed $bootstrap - * @return + * @param callable $entry 回调函数 + * @param mixed $parameter 零个或者多个回调函数参数 + * @return void */ - public function bootstrap($bootstrap) + public function execute(Callable $entry, $parameter) { + } /** * - *(Yaf >= 3.0.2) - *获取全局配置实例,即$this->config + *获取当前yaf_Application的环境名,它被定义在yaf.environ,默认值为"product". * @example - * @return + * @return string */ - public function getConfig() + public function environ(): string { + } /** * - *(Yaf >= 3.0.2) - *获取在配置文件中声明的模块,如果没有声明,它的默认值将是"Index". + *获取当前应用的主目录 * @example - * @return + * @return string */ - public function getModules() + public function getAppDirectory(): string { + } /** * - *(Yaf >= 3.0.2) - *获取当前请求的分发器YafX_Dispatcher的实例 + *获取全局配置实例,即$this->config * @example - * @return + * @return Yaf_Config_Abstract */ - public function getDispatcher() + public function getConfig(): Yaf_Config_Abstract { + } /** * - *(Yaf >= 3.0.2) - *设置应用的主目录 + *获取当前请求的分发器yaf_Dispatcher的实例 * @example - * @param String $directory (Yaf >= 3.0.2) -设置应用的主目录 - * @return + * @return Yaf_Dispatcher */ - public function setAppDirectory($directory) + public function getDispatcher(): Yaf_Dispatcher { + } /** * - *(Yaf >= 3.0.2) - *获取当前应用的主目录 + *获取最近产生的错误信息. * @example - * @return + * @return string */ - public function getAppDirectory() + public function getLastErrorMsg(): string { + } /** * - *(Yaf >= 3.0.2) *获取最近产生的错误代码. * @example - * @return + * @return int */ - public function getLastErrorNo() + public function getLastErrorNo(): int { + } /** * - *(Yaf >= 3.0.2) - *获取最近产生的错误信息. + *获取在配置文件中声明的模块,如果没有声明,它的默认值将是"Index". * @example - * @return + * @return array */ - public function getLastErrorMsg() + public function getModules(): array { + } /** * - *(Yaf >= 3.0.2) - *清除最近的错误信息,将设置$this->_err_no=0,$this->_err_msg=''. + *设置应用的主目录 * @example - * @return + * @param String $directory 目录路径. + * @return Yaf_Application */ - public function clearLastError() + public function setAppDirectory(String $directory): Yaf_Application { + } /** * - *(Yaf >= 3.0.2) - *重置__destruct魔术方法. + *重置__clone魔术方法,防止克隆yaf_Application(因为是单例模式). * @example * @return */ - public function __destruct() + private function __clone() { + } /** * - *(Yaf >= 3.0.2) - *重置__clone魔术方法,防止克隆YafX_Application(因为是单例模式). + *重置__destruct魔术方法. * @example * @return */ - private function __clone() + public function __destruct() { + } /** * - *(Yaf >= 3.0.2) *重置__sleep魔术方法. * @example * @return */ private function __sleep() { + } /** * - *(Yaf >= 3.0.2) *重置__wakeup魔术方法. * @example * @return */ private function __wakeup() { + } } diff --git a/src/Yaf/Bootstrap_Abstract.php b/src/Yaf/Bootstrap_Abstract.php index 5773ab4..727ebda 100644 --- a/src/Yaf/Bootstrap_Abstract.php +++ b/src/Yaf/Bootstrap_Abstract.php @@ -1,13 +1,12 @@ = 3.0.2) -*Class YafX_Bootstrap_Abstract +*应用引导类(一般需要一个类来继承它,可定义_init开头的方法) */ namespace Yaf; abstract class Bootstrap_Abstract diff --git a/src/Yaf/Config/Ini.php b/src/Yaf/Config/Ini.php index 7580e1e..e1ce4f9 100644 --- a/src/Yaf/Config/Ini.php +++ b/src/Yaf/Config/Ini.php @@ -1,249 +1,243 @@ = 3.0.2) -*Class YafX_Config_Ini +*yaf中ini配置文件类 */ namespace Yaf\Config; -final class Ini extends \Yaf\Config_Abstract +final class Ini extends \Yaf\Config_Abstract implements \Iterator,\ArrayAccess,\Countable { /** - * @var unknown $_config - * (Yaf >= 3.0.2) + * @var array $_config * 存储已解析的配置 * @access protected - protected $_config; + */ + protected $_config = array(); /** - * @var unknown $_readonly - * (Yaf >= 3.0.2) + * @var int $_readonly * 配置是否只读,默认为1. * @access protected - protected $_readonly = '1'; - - /** - * - *(Yaf >= 3.0.2) - *构造方法,初始化YafX_Config_Ini对象 - * @example - * @param mixed $config_file - * @param string $section (Yaf >= 3.0.2) -构造方法,初始化YafX_Config_Ini对象 - * @return */ - public function __construct($config_file, $section) - { - } + protected $_readonly = 1; /** * - *(Yaf >= 3.0.2) - *魔术方法,当isset()检测某个配置节点是否存在时调用 + *构造方法,初始化yaf_Config_Ini对象 * @example - * @param string $name (Yaf >= 3.0.2) -魔术方法,当isset()检测某个配置节点是否存在时调用 + * @param string $filename ini文件全路径 + * @param string $section 初始化时的配置节点名称 * @return */ - public function __isset($name) + public function __construct(string $filename, string $section) { + } /** * - *(Yaf >= 3.0.2) - *获取配置节点的值 - *当不传递$name参数时,返回配置对象本身 + *魔术方法,当isset()检测某个配置节点是否存在时调用 * @example - * @param mixed $name + * @param string $name 节点名称 * @return */ - public function get($name) + public function __isset(string $name) { + } /** * - *(Yaf >= 3.0.2) *设置配置节点值(无效) * @example - * @param string $name (Yaf >= 3.0.2) -设置配置节点值(无效) - * @param mixed $value - * @return + * @param string $name 变量名 + * @param mixed $value 配置值 + * @return Yaf_Config_Abstract */ - public function set($name, $value) + public function set(string $name, $value): Yaf_Config_Abstract { + } /** * - *(Yaf >= 3.0.2) *返回配置节点的数量 * @example - * @return + * @return int */ - public function count() + public function count(): int { + } /** * - *(Yaf >= 3.0.2) - *重置遍历位置(php.net文档有误) + *重置遍历位置 * @example * @return */ public function rewind() { + } /** * - *(Yaf >= 3.0.2) *返回当前节点 * @example - * @return + * @return mixed */ public function current() { + } /** * - *(Yaf >= 3.0.2) *向前移动到下一个元素 * @example - * @return + * @return mixed */ public function next() { + } /** * - *(Yaf >= 3.0.2) *判断是否可以继续遍历 * @example * @return */ public function valid() { + } /** * - *(Yaf >= 3.0.2) *返回当前配置节点的key * @example - * @return + * @return mixed */ public function key() { + + } + + /** + * + *撤消某个配置节点(无效) + * @example + * @param string $name 变量名 + * @return mixed + */ + public function offsetUnset(string $name) + { + } /** * - *(Yaf >= 3.0.2) + *测某个配置节点是否存在 * @example + * @param mixed $name 节点名称 * @return */ - public function toArray() + public function offsetExists($name) { + } /** * - *(Yaf >= 3.0.2) + *设置配置节点值(无效) * @example + * @param string $name 配置项名称 + * @param mixed $value 配置值 * @return */ - public function readonly() + public function offsetSet(string $name, $value) { + } /** * - *(Yaf >= 3.0.2) - *撤消某个配置节点(无效) + *获取配置节点的值 + *当不传递$name参数时,返回配置对象本身 * @example - * @param string $name (Yaf >= 3.0.2) -撤消某个配置节点(无效) + * @param string $name 索引值 * @return */ - public function offsetUnset($name) + public function offsetGet(string $name) { + } /** * - *(Yaf >= 3.0.2) *获取配置节点的值 *当不传递$name参数时,返回配置对象本身 * @example - * @param mixed $name + * @param string $name 配置项名称 * @return */ - public function offsetGet($name) + public function get(string $name) { + } /** * - *(Yaf >= 3.0.2) - *测某个配置节点是否存在 + *获取配置节点的值 + *当不传递$name参数时,返回配置对象本身 * @example - * @param mixed $name (Yaf >= 3.0.2) -测某个配置节点是否存在 + * @param string $name 配置项名称 * @return */ - public function offsetExists($name) + public function __get(string $name) { + } /** * - *(Yaf >= 3.0.2) *设置配置节点值(无效) * @example - * @param string $name (Yaf >= 3.0.2) -设置配置节点值(无效) - * @param mixed $value + * @param string $name 配置项名 + * @param mixed $value 配置值 * @return */ - public function offsetSet($name, $value) + public function __set(string $name, $value) { + } /** * - *(Yaf >= 3.0.2) - *获取配置节点的值 - *当不传递$name参数时,返回配置对象本身 + *将配置对象转化为数组 * @example - * @param mixed $name - * @return + * @return array */ - public function __get($name) + public function toArray(): array { + } /** * - *(Yaf >= 3.0.2) - *设置配置节点值(无效) + *配置是否只读 * @example - * @param string $name (Yaf >= 3.0.2) -设置配置节点值(无效) - * @param mixed $value - * @return + * @return bool */ - public function __set($name, $value) + public function readonly(): bool { + } } diff --git a/src/Yaf/Config/Simple.php b/src/Yaf/Config/Simple.php index 2e426ba..de6555a 100644 --- a/src/Yaf/Config/Simple.php +++ b/src/Yaf/Config/Simple.php @@ -1,251 +1,243 @@ = 3.0.2) -*Class YafX_Config_Simple +*基础配置对象 */ namespace Yaf\Config; -final class Simple extends \Yaf\Config_Abstract +final class Simple extends \Yaf\Config_Abstract implements \Iterator,\ArrayAccess,\Countable { /** - * @var unknown $_config - * (Yaf >= 3.0.2) + * @var array $_config * 存储已解析的配置 * @access protected - protected $_config; + */ + protected $_config = array(); /** - * @var unknown $_readonly - * (Yaf >= 3.0.2) + * @var int $_readonly * 配置是否只读,默认为1. * @access protected - protected $_readonly = ''; + */ + protected $_readonly = 0; /** * - *(Yaf >= 3.0.2) - *构造方法,初始化YafX_Config_Simple对象 + *构造方法,初始化yaf_Config_Simple对象 * @example - * @param mixed $config_file - * @param mixed $section + * @param string $config 储存配置的数组 + * @param string $readonly 是否只读 * @return */ - public function __construct($config_file, $section) + public function __construct(string $config, string $readonly) { + } /** * - *(Yaf >= 3.0.2) *魔术方法,当isset()检测某个配置节点是否存在时调用 * @example - * @param string $name (Yaf >= 3.0.2) -魔术方法,当isset()检测某个配置节点是否存在时调用 + * @param string $name 节点名称 * @return */ - public function __isset($name) + public function __isset(string $name) { + } /** * - *(Yaf >= 3.0.2) - *获取配置节点的值 - *当不传递$name参数时,返回配置对象本身 + *设置配置节点值(无效) * @example - * @param mixed $name - * @return + * @param string $name 变量名 + * @param mixed $value 配置值 + * @return Yaf_Config_Abstract */ - public function get($name) + public function set(string $name, $value): Yaf_Config_Abstract { + } /** * - *(Yaf >= 3.0.2) - *设置配置节点值 + *返回配置节点的数量 * @example - * @param string $name (Yaf >= 3.0.2) -设置配置节点值 - * @param mixed $value (Yaf >= 3.0.2) -设置配置节点值 - * @return + * @return int */ - public function set($name, $value) + public function count(): int { + } /** * - *(Yaf >= 3.0.2) - *返回配置节点的数量 + *重置遍历位置 * @example * @return */ - public function count() + public function rewind() { + } /** * - *(Yaf >= 3.0.2) - *撤消某个配置节点 + *返回当前节点 * @example - * @param string $name (Yaf >= 3.0.2) -撤消某个配置节点 - * @return + * @return mixed */ - public function offsetUnset($name) + public function current() { + } /** * - *(Yaf >= 3.0.2) - *重置遍历位置(php.net文档有误) + *向前移动到下一个元素 * @example - * @return + * @return mixed */ - public function rewind() + public function next() { + } /** * - *(Yaf >= 3.0.2) - *返回当前节点 + *判断是否可以继续遍历 * @example * @return */ - public function current() + public function valid() { + } /** * - *(Yaf >= 3.0.2) - *向前移动到下一个元素 + *返回当前配置节点的key * @example - * @return + * @return mixed */ - public function next() + public function key() { + } /** * - *(Yaf >= 3.0.2) - *判断是否可以继续遍历 + *撤消某个配置节点(无效) * @example - * @return + * @param string $name 变量名 + * @return mixed */ - public function valid() + public function offsetUnset(string $name) { + } /** * - *(Yaf >= 3.0.2) - *返回当前配置节点的key + *测某个配置节点是否存在 * @example + * @param mixed $name 节点名称 * @return */ - public function key() + public function offsetExists($name) { + } /** * - *(Yaf >= 3.0.2) + *设置配置节点值(无效) * @example + * @param string $name 配置项名称 + * @param mixed $value 配置值 * @return */ - public function readonly() + public function offsetSet(string $name, $value) { + } /** * - *(Yaf >= 3.0.2) + *获取配置节点的值 + *当不传递$name参数时,返回配置对象本身 * @example + * @param string $name 索引值 * @return */ - public function toArray() + public function offsetGet(string $name) { + } /** * - *(Yaf >= 3.0.2) - *设置配置节点值 + *获取配置节点的值 + *当不传递$name参数时,返回配置对象本身 * @example - * @param string $name (Yaf >= 3.0.2) -设置配置节点值 - * @param mixed $value (Yaf >= 3.0.2) -设置配置节点值 + * @param string $name 配置项名称 * @return */ - public function __set($name, $value) + public function get(string $name) { + } /** * - *(Yaf >= 3.0.2) *获取配置节点的值 *当不传递$name参数时,返回配置对象本身 * @example - * @param mixed $name + * @param string $name 配置项名称 * @return */ - public function __get($name) + public function __get(string $name) { + } /** * - *(Yaf >= 3.0.2) - *获取配置节点的值 - *当不传递$name参数时,返回配置对象本身 + *设置配置节点值(无效) * @example - * @param mixed $name + * @param string $name 配置项名 + * @param mixed $value 配置值 * @return */ - public function offsetGet($name) + public function __set(string $name, $value) { + } /** * - *(Yaf >= 3.0.2) - *测某个配置节点是否存在 + *将配置对象转化为数组 * @example - * @param mixed $name (Yaf >= 3.0.2) -测某个配置节点是否存在 - * @return + * @return array */ - public function offsetExists($name) + public function toArray(): array { + } /** * - *(Yaf >= 3.0.2) - *设置配置节点值 + *配置是否只读 * @example - * @param string $name (Yaf >= 3.0.2) -设置配置节点值 - * @param mixed $value (Yaf >= 3.0.2) -设置配置节点值 - * @return + * @return bool */ - public function offsetSet($name, $value) + public function readonly(): bool { + } } diff --git a/src/Yaf/Config_Abstract.php b/src/Yaf/Config_Abstract.php index b57c54f..4bae46f 100644 --- a/src/Yaf/Config_Abstract.php +++ b/src/Yaf/Config_Abstract.php @@ -1,67 +1,162 @@ = 3.0.2) -*Class YafX_Config_Abstract +*yaf配置抽象类 */ namespace Yaf; abstract class Config_Abstract { /** - * @var unknown $_config - * (Yaf >= 3.0.2) + * @var array $_config * 存储已解析的配置 * @access protected - protected $_config; + */ + protected $_config = array(); /** - * @var unknown $_readonly - * (Yaf >= 3.0.2) + * @var int $_readonly * 配置是否只读,默认为1. * @access protected - protected $_readonly = '1'; + */ + protected $_readonly = 1; /** * - *(Yaf >= 3.0.2) *获取配置节点的值 *当不传递$name参数时,返回配置对象本身 * @example - * @return + * @param string $name 配置键 + * @param mixed $value 默认值 + * @return mixed */ - public abstract function get(); + public abstract function get(string $name, $value); /** * - *(Yaf >= 3.0.2) - *设置配置节点的值 + *设置配置节点的值(只读) * @example - * @return + * @return Yaf_Config_Abstract */ - public abstract function set(); + public abstract function set(): Yaf_Config_Abstract; /** * - *(Yaf >= 3.0.2) - *返回配置只读的状态 + *配置是否只读 * @example - * @return + * @return bool */ - public abstract function readonly(); + public abstract function readonly(): bool; /** * - *(Yaf >= 3.0.2) *将配置转换为数组 * @example + * @return array + */ + public abstract function toArray(): array; + + /** + * + *获取配置节点的值 + *当不传递$name参数时,返回配置对象本身 + * @example + * @param string $name 配置键 + * @return mixed + */ + public function __get(string $name) + { + + } + + /** + * + *返回当前值 + * @example + * @return void + */ + public abstract function current(); + + /** + * + *返回下一个值 + * @example + * @return void + */ + public abstract function next(); + + /** + * + *返回当前键 + * @example * @return */ - public abstract function toArray(); + public abstract function key(); + + /** + * + *验证当前对象是否合法 + * @example + * @return void + */ + public abstract function valid(); + + /** + * + *将迭代器重置到第一个位置 + * @example + * @return void + */ + public abstract function rewind(); + + /** + * + *返回当前迭代器的个数 + * @example + * @return + */ + public abstract function count(); + + /** + * + *当前索引对应的对象是否存在 + * @example + * @param string $offset 索引 + * @return void + */ + public abstract function offsetExists(string $offset); + + /** + * + *通过索引获取当前对象 + * @example + * @param string $offset 索引 + * @return void + */ + public abstract function offsetGet(string $offset); + + /** + * + *通过索引设置值 + * @example + * @param string $offset 索引 + * @param mixed $value 配置值 + * @return void + */ + public abstract function offsetSet(string $offset, $value); + + /** + * + *通过索引删除值 + * @example + * @param string $offset 索引 + * @return void + */ + public abstract function offsetUnset(string $offset); } diff --git a/src/Yaf/Controller_Abstract.php b/src/Yaf/Controller_Abstract.php index 6517598..9c206ed 100644 --- a/src/Yaf/Controller_Abstract.php +++ b/src/Yaf/Controller_Abstract.php @@ -1,194 +1,194 @@ = 3.0.2) -*Class YafX_Controller_Abstract +*控制器抽象类 */ namespace Yaf; abstract class Controller_Abstract { /** - * @var unknown $actions - * (Yaf >= 3.0.2) + * @var array $actions * 动作名与动作类文件路径映射数组 * @access public - public $actions; + */ + public $actions = array(); /** - * @var unknown $_module - * (Yaf >= 3.0.2) + * @var string $_module * 当前请求的模块名 * @access protected + */ protected $_module; /** - * @var unknown $_name - * (Yaf >= 3.0.2) + * @var string $_name * 当前请求的控制器名 * @access protected + */ protected $_name; /** - * @var unknown $_request - * (Yaf >= 3.0.2) - * 当前请求对象,包括请求的所有相关信息 + * @var Yaf_Request_Abstract $_request + * 当前请求对象 * @access protected + */ protected $_request; /** - * @var unknown $_response - * (Yaf >= 3.0.2) - * 当前响应对象,保存响应的所有相关信息 + * @var Yaf_Response_Abstract $_response + * 当前响应对象 * @access protected + */ protected $_response; /** - * @var unknown $_invoke_args - * (Yaf >= 3.0.2) - * 储存调用参数 + * @var array $_invoke_args + * 调用参数列表 * @access protected - protected $_invoke_args; + */ + protected $_invoke_args = array(); /** - * @var unknown $_view - * (Yaf >= 3.0.2) - * 视图对象 + * @var Yaf_View_Interface $_view + * 当前视图对象 * @access protected + */ protected $_view; /** * - *(Yaf >= 3.0.2) *渲染动作对应的模板,并返回结果 * @example - * @param mixed $tpl - * @param array $parameters - * @return + * @param string $action_name 模板名称 + * @param array $var_array 模板变量数组 + * @return Yaf_Controller_Abstract */ - protected function render($tpl, Array $parameters) + protected function render(string $action_name, Array $var_array = []): Yaf_Controller_Abstract { + } /** * - *(Yaf >= 3.0.2) *渲染动作对应的模板,并直接输出结果 * @example - * @param mixed $tpl - * @param array $parameters - * @return + * @param string $action_name 模板名称 + * @param array $var_array 模板变量数组 + * @return Yaf_Controller_Abstract */ - protected function display($tpl, Array $parameters) + protected function display(string $action_name, Array $var_array = []): Yaf_Controller_Abstract { + } /** * - *(Yaf >= 3.0.2) *获取请求对象 * @example - * @return + * @return Yaf_Request_Abstract */ - public function getRequest() + public function getRequest(): Yaf_Request_Abstract { + } /** * - *(Yaf >= 3.0.2) *获取响应对象 * @example - * @return + * @return Yaf_Response_Abstract */ - public function getResponse() + public function getResponse(): Yaf_Response_Abstract { + } /** * - *(Yaf >= 3.0.2) *获取当前模块名 * @example - * @return + * @return string */ - public function getModuleName() + public function getModuleName(): string { + } /** * - *(Yaf >= 3.0.2) - *返回视图对象 + *初始化视图对象 * @example - * @return + * @return void */ - public function getView() + public function initView() { + } /** * - *(Yaf >= 3.0.2) - *初始化视图对象 + *返回视图对象 * @example - * @param array $options - * @return + * @return Yaf_View_Interface */ - public function initView(Array $options) + public function getView(): Yaf_View_Interface { + } /** * - * + *设置模板文件目录 * @example - * @param mixed $view_directory - * @return + * @param string $path 模板目录 + * @return void */ - public function setViewpath($view_directory) + public function setViewPath(string $path) { + } /** * - * + *获取模板文件目录 * @example - * @return + * @return string */ - public function getViewpath() + public function getViewPath(): string { + } /** * - *(Yaf >= 3.0.2) *将当前的请求转交给另外的Action(对用户来说是透明的,相当于Web服务器的代理). * @example - * @param mixed $module - * @param mixed $controller - * @param mixed $action - * @param mixed $parameters - * @return + * @param string $module 模块名 + * @param string $controller 控制器名称 + * @param string $action 操作名称 + * @param array $parameters 参数列表数组 + * @return void */ - public function forward($module, $controller, $action, $parameters) + public function forward(string $module, string $controller, string $action, Array $parameters = []) { + } /** * - *(Yaf >= 3.0.2) *将当前请求重定向到指定的URL(内部实现是通过发送Location报头实现,如:header("Location:http//www.phpboy.net/")) * @example - * @param mixed $url + * @param string $url 跳转的地址 * @return */ - public function redirect($url) + public function redirect(string $url) { + } /** @@ -200,40 +200,41 @@ public function redirect($url) */ public function getInvokeArgs() { + } /** * - *(Yaf >= 3.0.2) *获取指定调用参数名的值 * @example - * @param mixed $name + * @param string $name 参数名称 * @return */ - public function getInvokeArg($name) + public function getInvokeArg(string $name) { + } /** * - *(Yaf >= 3.0.2) - *屏蔽构造方法 + *构造方法 * @example * @return */ public final function __construct() { + } /** * - *(Yaf >= 3.0.2) - *屏蔽克隆的魔术方法 + *克隆的魔术方法 * @example * @return */ - private final function __clone() + public final function __clone() { + } } diff --git a/src/Yaf/Dispatcher.php b/src/Yaf/Dispatcher.php index 1716d90..374db2b 100644 --- a/src/Yaf/Dispatcher.php +++ b/src/Yaf/Dispatcher.php @@ -1,398 +1,402 @@ = 3.0.2) -*Class YafX_Dispatcher +*路由及请求分发器 */ namespace Yaf; final class Dispatcher { /** - * @var unknown $_router - * (Yaf >= 3.0.2) + * @var Yaf_Router $_router * 路由器对象. * @access protected + */ protected $_router; /** - * @var unknown $_view - * (Yaf >= 3.0.2) + * @var Yaf_View_Interface $_view * 视图对象. * @access protected + */ protected $_view; /** - * @var unknown $_request - * (Yaf >= 3.0.2) + * @var Yaf_Request_Abstract $_request * 当前请求对象(包含请求的所有信息). * @access protected + */ protected $_request; /** - * @var unknown $_plugins - * (Yaf >= 3.0.2) + * @var array $_plugins * 已注册的插件对象 * @access protected - protected $_plugins; + */ + protected $_plugins = array(); /** - * @var unknown $_instance - * (Yaf >= 3.0.2) - * YafX_Dispatcher实现了单例模式,此属性保存当前实例. + * @var Yaf_Dispatcher $_instance + * yaf_Dispatcher实现了单例模式,此属性保存当前实例. * @access protected + */ protected static $_instance; /** - * @var unknown $_auto_render - * (Yaf >= 3.0.2) + * @var int $_auto_render * 自动渲染功能开关,默认1. * 自动渲染是指根据当前请求的控制器Controller和动作Action自动寻找模块文件,加载与渲染模块,之后返回结果或者输出. * 如果设置为0,$this->_instantly_flush,$this->_return_response的设置将无效,也即: - * YafX_Dispatcher::getInstance()->flushInstantly($flag); - * YafX_Dispatcher::getInstance()->returnResponse($flag); + * yaf_Dispatcher::getInstance()->flushInstantly($flag); + * yaf_Dispatcher::getInstance()->returnResponse($flag); * 设置无效,并且不会渲染模板. * @access protected - protected $_auto_render = '1'; + */ + protected $_auto_render = 1; /** - * @var unknown $_return_response - * (Yaf >= 3.0.2) + * @var int $_return_response * 返回包含请求正文的响应对象开关,默认为0. - * 默认情况下,Yaf的自动渲染查找并渲染模板(render,并非display),渲染结果写入YafX_Response_Abstract实例的_body属性, + * 默认情况下,Yaf的自动渲染查找并渲染模板(render,并非display),渲染结果写入yaf_Response_Abstract实例的_body属性, * 在分发器结束分发之后,输出_body(数组遍历输出)属性的值,并清空_body. - * 设置此属性为1,分发器结束分发之后,不会输出和清空_body,可以通过YafX_Application的run(),YafX_Dispatcher的方法dispatch(), - * 或者YafX_Controller_Abstract的getResponse()等方法的调用返回响应对象, - * 进而调用YafX_Response_Abstract实例的getBody()方法获取响应正文.此属性依赖$this->_auto_render的设置, + * 设置此属性为1,分发器结束分发之后,不会输出和清空_body,可以通过yaf_Application的run(),yaf_Dispatcher的方法dispatch(), + * 或者yaf_Controller_Abstract的getResponse()等方法的调用返回响应对象, + * 进而调用yaf_Response_Abstract实例的getBody()方法获取响应正文.此属性依赖$this->_auto_render的设置, * 当$this->_auto_render=1时,响应正文包括渲染模板的结果,反之则不包括. * @access protected - protected $_return_response = ''; + */ + protected $_return_response = 0; /** - * @var unknown $_instantly_flush - * (Yaf >= 3.0.2) + * @var int $_instantly_flush * 立即输出响应正文开头,默认为0. - * 默认情况下,Yaf自动渲染调用YafX_Controller_Abstract的render方法,渲染模板. - * 当此属性设置为1时,Yaf调用YafX_Controller_Abstract的display方法,直接渲染并输出,但不设置YafX_Response_Abstract实例的_body属性. + * 默认情况下,Yaf自动渲染调用yaf_Controller_Abstract的render方法,渲染模板. + * 当此属性设置为1时,Yaf调用yaf_Controller_Abstract的display方法,直接渲染并输出,但不设置yaf_Response_Abstract实例的_body属性. * @access protected - protected $_instantly_flush = ''; + */ + protected $_instantly_flush = 0; /** - * @var unknown $_default_module - * (Yaf >= 3.0.2) + * @var string $_default_module * 默认模块名 * @access protected + */ protected $_default_module; /** - * @var unknown $_default_controller - * (Yaf >= 3.0.2) + * @var string $_default_controller * 默认控制器 * @access protected + */ protected $_default_controller; /** - * @var unknown $_default_action - * (Yaf >= 3.0.2) + * @var string $_default_action * 默认动作名 * @access protected + */ protected $_default_action; /** * - *(Yaf >= 3.0.2) - *重置__construct魔术方法. + *关闭自动渲染模板 * @example - * @return + * @return bool */ - private function __construct() + public function disableView(): bool { + } /** * - *(Yaf >= 3.0.2) - *重置__clone魔术方法,防止克隆YafX_Dispatcher(因为是单例模式). + *开启自动渲染模板 * @example - * @return + * @return Yaf_Dispatcher */ - private function __clone() + public function enableView(): Yaf_Dispatcher { + } /** * - *(Yaf >= 3.0.2) - *重置__sleep魔术方法. + *初始化视图对象 * @example - * @return + * @param string $tpl_dir 模板目录 + * @param mixed $options 全局的模板选项(配置相关) + * @return Yaf_View_Interface */ - private function __sleep() + public function initView(string $tpl_dir, $options): Yaf_View_Interface { + return Yaf_View_Simple(); } /** * - *(Yaf >= 3.0.2) - *重置__wakeup魔术方法. + *设置视图对象 * @example - * @return + * @param Yaf_View_Interface $view 视图对象实例 + * @return Yaf_Dispatcher */ - private function __wakeup() + public function setView(Yaf_View_Interface $view): Yaf_Dispatcher { + } /** * - *(Yaf >= 3.0.2) - *开启自动渲染模板 + *设置请求对象(在命令行或者其他API模式下构造请求很有用) * @example - * @return + * @param Yaf_Request_Abstract $request 手动实例化的请求对象 + * @return Yaf_Dispatcher */ - public function enableView() + public function setRequest(Yaf_Request_Abstract $request): Yaf_Dispatcher { + } /** * - *(Yaf >= 3.0.2) - *关闭自动渲染模板 + *返回应用实例 * @example - * @return + * @return Yaf_Application */ - public function disableView() + public function getApplication(): Yaf_Application { + } /** * - *(Yaf >= 3.0.2) - *初始化视图对象 + *返回路由器实例 * @example - * @param mixed $templates_dir - * @param mixed $options (Yaf >= 3.0.2) -初始化视图对象 - * @return + * @return Yaf_Router */ - public function initView($templates_dir, $options) + public function getRouter(): Yaf_Router { + } /** * - *(Yaf >= 3.0.2) - *设置视图对象 + *返回请求对象实例 * @example - * @param YafX_View_Interface $view (Yaf >= 3.0.2) -设置视图对象 - * @return + * @return Yaf_Request */ - public function setView($view) + public function getRequest(): Yaf_Request { + } /** * *(Yaf >= 3.0.2) - *设置请求对象(在命令行或者其他API模式下构造请求很有用) + *设置一个用户定义的错误处理函数(封装了PHP内置的set_error_handler函数) * @example - * @param YafX_Request_Abstract $request (Yaf >= 3.0.2) -设置请求对象(在命令行或者其他API模式下构造请求很有用) - * @return + * @param callable $callback PHP中可回调的结构 + * @param int $error_type 错误类型 + * @return Yaf_Dispatcher */ - public function setRequest($request) + public function setErrorHandler(Callable $callback, int $error_type = 32767): Yaf_Dispatcher { + } /** * - *(Yaf >= 3.0.2) - *返回应用实例 + *设置默认模块 * @example - * @return + * @param string $module 模块名 + * @return Yaf_Dispatcher */ - public function getApplication() + public function setDefaultModule(string $module): Yaf_Dispatcher { + } /** * - *返回路由器实例 + *设置默认的控制器 * @example - * @return + * @param string $controller 控制器名 + * @return Yaf_Dispatcher */ - public function getRouter() + public function setDefaultController(string $controller): Yaf_Dispatcher { + } /** * - *(Yaf >= 3.0.2) - *返回请求对象实例 + *设置默认的动作名 * @example - * @return + * @param string $action 操作名 + * @return Yaf_Dispatcher */ - public function getRequest() + public function setDefaultAction(string $action): Yaf_Dispatcher { + } /** * - *(Yaf >= 3.0.2) - *设置一个用户定义的错误处理函数(封装了PHP内置的set_error_handler函数) + *设置或者返回$this->_return_response属性的值 + *当传递$flag参数时,设置$this->_return_response=$flag,并返回Dispatcher + *当不传递任何参数时,返回$this->_return_response当前值 * @example - * @param callable $callback (Yaf >= 3.0.2) -设置一个用户定义的错误处理函数(封装了PHP内置的set_error_handler函数) - * @param mixed $error_types - * @return + * @param bool $flag 是否返回响应 + * @return Yaf_Dispatcher */ - public function setErrorHandler(Callable $callback, $error_types) + public function returnResponse(bool $flag): Yaf_Dispatcher { + } /** * - *(Yaf >= 3.0.2) - *设置默认模块 + *设置或者返回$this->_auto_render属性的值 + *当传递$flag参数时,设置$this->_auto_render=$flag,并返回Dispatcher + *当不传递任何参数时,返回$this->_auto_render属性的值 * @example - * @param string $module (Yaf >= 3.0.2) -设置默认模块 - * @return + * @param bool $flag 是否自动渲染 + * @return Yaf_Dispatcher */ - public function setDefaultModule($module) + public function autoRender(bool $flag): Yaf_Dispatcher { + } /** * - *(Yaf >= 3.0.2) - *设置默认的控制器 + *设置或者返回$this->_instantly_flush属性的值 + *当传递$flag参数时,设置$this->_instantly_flush=$flag,并返回Dispatcher + *当不传递任何参数时,返回$this->_instantly_flush属性的值 * @example - * @param string $controller (Yaf >= 3.0.2) -设置默认的控制器 - * @return + * @param bool $flag 是否即时刷新缓存 + * @return Yaf_Dispatcher */ - public function setDefaultController($controller) + public function flushInstantly(bool $flag): Yaf_Dispatcher { + } /** * - *(Yaf >= 3.0.2) - *设置默认的动作名 + *返回当前yaf_Dispatcher实例(单例模式) * @example - * @param mixed $action - * @return + * @return Yaf_Dispatcher */ - public function setDefaultAction($action) + public static function getInstance(): Yaf_Dispatcher { + } /** * - *(Yaf >= 3.0.2) - *设置或者返回$this->_return_response属性的值 - *当传递$flag参数时,设置$this->_return_response=$flag,并返回Dispatcher - *当不传递任何参数时,返回$this->_return_response当前值 + *手动分发请求 * @example - * @param mixed $flag - * @return + * @param Yaf_Request_Abstract $request 分发的请求对象 + * @return Yaf_Response_Abstract */ - public function returnResponse($flag) + public function dispatch(Yaf_Request_Abstract $request): Yaf_Response_Abstract { + return new Yaf_Response_Http(); } /** * - *(Yaf >= 3.0.2) - *设置或者返回$this->_auto_render属性的值 - *当传递$flag参数时,设置$this->_auto_render=$flag,并返回Dispatcher - *当不传递任何参数时,返回$this->_auto_render属性的值 + *开启/关闭异常抛出或返回当前状态 * @example - * @param mixed $flag - * @return + * @param bool $flag 是否抛出异常 + * @return Yaf_Dispatcher */ - public function autoRender($flag) + public function throwException(bool $flag): Yaf_Dispatcher { + } /** * - *(Yaf >= 3.0.2) - *设置或者返回$this->_instantly_flush属性的值 - *当传递$flag参数时,设置$this->_instantly_flush=$flag,并返回Dispatcher - *当不传递任何参数时,返回$this->_instantly_flush属性的值 + *开启/关闭自动异常捕获功能或返回当前状态 * @example - * @param mixed $flag - * @return + * @param bool $flag 是否捕获异常 + * @return Yaf_Dispatcher */ - public function flushInstantly($flag) + public function catchException(bool $flag): Yaf_Dispatcher { + } /** * - *(Yaf >= 3.0.2) - *返回当前YafX_Dispatcher实例(单例模式) + *注册插件 + * @example + * @param Yaf_Plugin_Abstract $plugin 实例化的插件对象 + * @return Yaf_Dispatcher + */ + public function registerPlugin(Yaf_Plugin_Abstract $plugin): Yaf_Dispatcher + { + + } + + /** + * + *重置__construct魔术方法. * @example * @return */ - public static function getInstance() + private function __construct() { + } /** * - *(Yaf >= 3.0.2) - *手动分发请求 + *重置__clone魔术方法,防止克隆yaf_Dispatcher(因为是单例模式). * @example - * @param YafX_Request_Abstract $request (Yaf >= 3.0.2) -手动分发请求 * @return */ - public function dispatch($request) + private function __clone() { + } /** * - *(Yaf >= 3.0.2) - *开启/关闭异常抛出或返回当前状态 + *重置__destruct魔术方法. * @example - * @param mixed $flag * @return */ - public function throwException($flag) + public function __destruct() { + } /** * - *(Yaf >= 3.0.2) - *开启/关闭自动异常捕获功能或返回当前状态 + *重置__sleep魔术方法. * @example - * @param mixed $flag * @return */ - public function catchException($flag) + private function __sleep() { + } /** * - *(Yaf >= 3.0.2) - *注册插件 + *重置__wakeup魔术方法. * @example - * @param YafX_Plugin_Abstract $plugin (Yaf >= 3.0.2) -注册插件 * @return */ - public function registerPlugin($plugin) + private function __wakeup() { + } } diff --git a/src/Yaf/Exception.php b/src/Yaf/Exception.php index 6e0adab..61f69dc 100644 --- a/src/Yaf/Exception.php +++ b/src/Yaf/Exception.php @@ -1,70 +1,74 @@ = 3.0.2) -*Class YafX_Exception +*yaf异常蕨类 */ namespace Yaf; -class Exception extends \Exception +class Exception extends \Exception implements \Throwable { /** - * @var unknown $file - * + * @var string $file + * 异常文件名称 * @access protected + */ protected $file; /** - * @var unknown $line - * + * @var int $line + * 异常文件行数 * @access protected + */ protected $line; /** - * @var unknown $message - * (Yaf >= 3.0.2) + * @var string $message * 异常信息 * @access protected + */ protected $message; /** - * @var unknown $code - * + * @var int $code + * 异常码 * @access protected + */ protected $code = 0; /** - * @var unknown $previous - * (Yaf >= 3.0.2) + * @var Throwable $previous * 上一个异常对象 * @access protected + */ protected $previous; /** * - * + *克隆方法 * @example * @return */ private final function __clone() { + } /** * - * + *初始化异常 * @example - * @param mixed $message - * @param mixed $code - * @param mixed $previous + * @param string $message 异常提示 + * @param int $code 异常码 + * @param Throwable $previous 上一个异常对象 * @return */ - public function __construct($message, $code, $previous) + public function __construct(string $message = '', int $code = 0, Throwable $previous) { + } /** @@ -75,86 +79,95 @@ public function __construct($message, $code, $previous) */ public function __wakeup() { + } /** * - * + *获取异常信息 * @example - * @return + * @return string */ - public final function getMessage() + public final function getMessage(): string { + } /** * - * + *获取异常码 * @example - * @return + * @return int */ - public final function getCode() + public final function getCode(): int { + } /** * - * + *获取异常文件名称 * @example - * @return + * @return string */ - public final function getFile() + public final function getFile(): string { + } /** * - * + *获取异常行数 * @example - * @return + * @return int */ - public final function getLine() + public final function getLine(): int { + } /** * - * + *获取trace调试数组 * @example - * @return + * @return array */ - public final function getTrace() + public final function getTrace(): array { + } /** * - * + *获取前一个异常对象 * @example - * @return + * @return Throwable */ public final function getPrevious() { + return new Exception(); } /** * - * + *获取调试信息的字符串 * @example - * @return + * @return string */ - public final function getTraceAsString() + public final function getTraceAsString(): string { + } /** * - * + *转化为字符串 * @example - * @return + * @return string */ - public function __toString() + public function __toString(): string { + } } diff --git a/src/Yaf/Exception/DispatchFailed.php b/src/Yaf/Exception/DispatchFailed.php index 5d2b03c..9945d4d 100644 --- a/src/Yaf/Exception/DispatchFailed.php +++ b/src/Yaf/Exception/DispatchFailed.php @@ -1,70 +1,74 @@ = 3.0.2) -*Class YafX_Exception_DispatchFailed +*yaf分发异常 */ namespace Yaf\Exception; -class DispatchFailed extends \Yaf\Exception +class DispatchFailed extends \Yaf\Exception implements \Throwable { /** - * @var unknown $file - * + * @var string $file + * 异常文件名称 * @access protected + */ protected $file; /** - * @var unknown $line - * + * @var int $line + * 异常文件行数 * @access protected + */ protected $line; /** - * @var unknown $message - * (Yaf >= 3.0.2) + * @var string $message * 异常信息 * @access protected + */ protected $message; /** - * @var unknown $code - * + * @var int $code + * 异常码 * @access protected + */ protected $code = 0; /** - * @var unknown $previous - * (Yaf >= 3.0.2) + * @var Throwable $previous * 上一个异常对象 * @access protected + */ protected $previous; /** * - * + *克隆方法 * @example * @return */ private final function __clone() { + } /** * - * + *初始化异常 * @example - * @param mixed $message - * @param mixed $code - * @param mixed $previous + * @param string $message 异常提示 + * @param int $code 异常码 + * @param Throwable $previous 上一个异常对象 * @return */ - public function __construct($message, $code, $previous) + public function __construct(string $message = '', int $code = 0, Throwable $previous) { + } /** @@ -75,86 +79,95 @@ public function __construct($message, $code, $previous) */ public function __wakeup() { + } /** * - * + *获取异常信息 * @example - * @return + * @return string */ - public final function getMessage() + public final function getMessage(): string { + } /** * - * + *获取异常码 * @example - * @return + * @return int */ - public final function getCode() + public final function getCode(): int { + } /** * - * + *获取异常文件名称 * @example - * @return + * @return string */ - public final function getFile() + public final function getFile(): string { + } /** * - * + *获取异常行数 * @example - * @return + * @return int */ - public final function getLine() + public final function getLine(): int { + } /** * - * + *获取trace调试数组 * @example - * @return + * @return array */ - public final function getTrace() + public final function getTrace(): array { + } /** * - * + *获取前一个异常对象 * @example - * @return + * @return Throwable */ public final function getPrevious() { + return new Exception(); } /** * - * + *获取调试信息的字符串 * @example - * @return + * @return string */ - public final function getTraceAsString() + public final function getTraceAsString(): string { + } /** * - * + *转化为字符串 * @example - * @return + * @return string */ - public function __toString() + public function __toString(): string { + } } diff --git a/src/Yaf/Exception/LoadFailed.php b/src/Yaf/Exception/LoadFailed.php index f1f7417..2f7c33c 100644 --- a/src/Yaf/Exception/LoadFailed.php +++ b/src/Yaf/Exception/LoadFailed.php @@ -1,70 +1,74 @@ = 3.0.2) -*Class YafX_Exception_LoadFailed +*yaf加载异常 */ namespace Yaf\Exception; -class LoadFailed extends \Yaf\Exception +class LoadFailed extends \Yaf\Exception implements \Throwable { /** - * @var unknown $file - * + * @var string $file + * 异常文件名称 * @access protected + */ protected $file; /** - * @var unknown $line - * + * @var int $line + * 异常文件行数 * @access protected + */ protected $line; /** - * @var unknown $message - * (Yaf >= 3.0.2) + * @var string $message * 异常信息 * @access protected + */ protected $message; /** - * @var unknown $code - * + * @var int $code + * 异常码 * @access protected + */ protected $code = 0; /** - * @var unknown $previous - * (Yaf >= 3.0.2) + * @var Throwable $previous * 上一个异常对象 * @access protected + */ protected $previous; /** * - * + *克隆方法 * @example * @return */ private final function __clone() { + } /** * - * + *初始化异常 * @example - * @param mixed $message - * @param mixed $code - * @param mixed $previous + * @param string $message 异常提示 + * @param int $code 异常码 + * @param Throwable $previous 上一个异常对象 * @return */ - public function __construct($message, $code, $previous) + public function __construct(string $message = '', int $code = 0, Throwable $previous) { + } /** @@ -75,86 +79,95 @@ public function __construct($message, $code, $previous) */ public function __wakeup() { + } /** * - * + *获取异常信息 * @example - * @return + * @return string */ - public final function getMessage() + public final function getMessage(): string { + } /** * - * + *获取异常码 * @example - * @return + * @return int */ - public final function getCode() + public final function getCode(): int { + } /** * - * + *获取异常文件名称 * @example - * @return + * @return string */ - public final function getFile() + public final function getFile(): string { + } /** * - * + *获取异常行数 * @example - * @return + * @return int */ - public final function getLine() + public final function getLine(): int { + } /** * - * + *获取trace调试数组 * @example - * @return + * @return array */ - public final function getTrace() + public final function getTrace(): array { + } /** * - * + *获取前一个异常对象 * @example - * @return + * @return Throwable */ public final function getPrevious() { + return new Exception(); } /** * - * + *获取调试信息的字符串 * @example - * @return + * @return string */ - public final function getTraceAsString() + public final function getTraceAsString(): string { + } /** * - * + *转化为字符串 * @example - * @return + * @return string */ - public function __toString() + public function __toString(): string { + } } diff --git a/src/Yaf/Exception/LoadFailed/Action.php b/src/Yaf/Exception/LoadFailed/Action.php index 70caf22..8e599d2 100644 --- a/src/Yaf/Exception/LoadFailed/Action.php +++ b/src/Yaf/Exception/LoadFailed/Action.php @@ -1,70 +1,74 @@ = 3.0.2) -*Class YafX_Exception_LoadFailed_Action +*操作文件加载异常 */ namespace Yaf\Exception\LoadFailed; -class Action extends \Yaf\Exception\LoadFailed +class Action extends \Yaf\Exception\LoadFailed implements \Throwable { /** - * @var unknown $file - * + * @var string $file + * 异常文件名称 * @access protected + */ protected $file; /** - * @var unknown $line - * + * @var int $line + * 异常文件行数 * @access protected + */ protected $line; /** - * @var unknown $message - * (Yaf >= 3.0.2) + * @var string $message * 异常信息 * @access protected + */ protected $message; /** - * @var unknown $code - * + * @var int $code + * 异常码 * @access protected + */ protected $code = 0; /** - * @var unknown $previous - * (Yaf >= 3.0.2) + * @var Throwable $previous * 上一个异常对象 * @access protected + */ protected $previous; /** * - * + *克隆方法 * @example * @return */ private final function __clone() { + } /** * - * + *初始化异常 * @example - * @param mixed $message - * @param mixed $code - * @param mixed $previous + * @param string $message 异常提示 + * @param int $code 异常码 + * @param Throwable $previous 上一个异常对象 * @return */ - public function __construct($message, $code, $previous) + public function __construct(string $message = '', int $code = 0, Throwable $previous) { + } /** @@ -75,86 +79,95 @@ public function __construct($message, $code, $previous) */ public function __wakeup() { + } /** * - * + *获取异常信息 * @example - * @return + * @return string */ - public final function getMessage() + public final function getMessage(): string { + } /** * - * + *获取异常码 * @example - * @return + * @return int */ - public final function getCode() + public final function getCode(): int { + } /** * - * + *获取异常文件名称 * @example - * @return + * @return string */ - public final function getFile() + public final function getFile(): string { + } /** * - * + *获取异常行数 * @example - * @return + * @return int */ - public final function getLine() + public final function getLine(): int { + } /** * - * + *获取trace调试数组 * @example - * @return + * @return array */ - public final function getTrace() + public final function getTrace(): array { + } /** * - * + *获取前一个异常对象 * @example - * @return + * @return Throwable */ public final function getPrevious() { + return new Exception(); } /** * - * + *获取调试信息的字符串 * @example - * @return + * @return string */ - public final function getTraceAsString() + public final function getTraceAsString(): string { + } /** * - * + *转化为字符串 * @example - * @return + * @return string */ - public function __toString() + public function __toString(): string { + } } diff --git a/src/Yaf/Exception/LoadFailed/Controller.php b/src/Yaf/Exception/LoadFailed/Controller.php index c37a6f3..06122e9 100644 --- a/src/Yaf/Exception/LoadFailed/Controller.php +++ b/src/Yaf/Exception/LoadFailed/Controller.php @@ -1,70 +1,74 @@ = 3.0.2) -*Class YafX_Exception_LoadFailed_Controller +*控制器加载异常 */ namespace Yaf\Exception\LoadFailed; -class Controller extends \Yaf\Exception\LoadFailed +class Controller extends \Yaf\Exception\LoadFailed implements \Throwable { /** - * @var unknown $file - * + * @var string $file + * 异常文件名称 * @access protected + */ protected $file; /** - * @var unknown $line - * + * @var int $line + * 异常文件行数 * @access protected + */ protected $line; /** - * @var unknown $message - * (Yaf >= 3.0.2) + * @var string $message * 异常信息 * @access protected + */ protected $message; /** - * @var unknown $code - * + * @var int $code + * 异常码 * @access protected + */ protected $code = 0; /** - * @var unknown $previous - * (Yaf >= 3.0.2) + * @var Throwable $previous * 上一个异常对象 * @access protected + */ protected $previous; /** * - * + *克隆方法 * @example * @return */ private final function __clone() { + } /** * - * + *初始化异常 * @example - * @param mixed $message - * @param mixed $code - * @param mixed $previous + * @param string $message 异常提示 + * @param int $code 异常码 + * @param Throwable $previous 上一个异常对象 * @return */ - public function __construct($message, $code, $previous) + public function __construct(string $message = '', int $code = 0, Throwable $previous) { + } /** @@ -75,86 +79,95 @@ public function __construct($message, $code, $previous) */ public function __wakeup() { + } /** * - * + *获取异常信息 * @example - * @return + * @return string */ - public final function getMessage() + public final function getMessage(): string { + } /** * - * + *获取异常码 * @example - * @return + * @return int */ - public final function getCode() + public final function getCode(): int { + } /** * - * + *获取异常文件名称 * @example - * @return + * @return string */ - public final function getFile() + public final function getFile(): string { + } /** * - * + *获取异常行数 * @example - * @return + * @return int */ - public final function getLine() + public final function getLine(): int { + } /** * - * + *获取trace调试数组 * @example - * @return + * @return array */ - public final function getTrace() + public final function getTrace(): array { + } /** * - * + *获取前一个异常对象 * @example - * @return + * @return Throwable */ public final function getPrevious() { + return new Exception(); } /** * - * + *获取调试信息的字符串 * @example - * @return + * @return string */ - public final function getTraceAsString() + public final function getTraceAsString(): string { + } /** * - * + *转化为字符串 * @example - * @return + * @return string */ - public function __toString() + public function __toString(): string { + } } diff --git a/src/Yaf/Exception/LoadFailed/Module.php b/src/Yaf/Exception/LoadFailed/Module.php index 5815694..a7054c9 100644 --- a/src/Yaf/Exception/LoadFailed/Module.php +++ b/src/Yaf/Exception/LoadFailed/Module.php @@ -1,70 +1,74 @@ = 3.0.2) -*Class YafX_Exception_LoadFailed_Module +*模块加载异常 */ namespace Yaf\Exception\LoadFailed; -class Module extends \Yaf\Exception\LoadFailed +class Module extends \Yaf\Exception\LoadFailed implements \Throwable { /** - * @var unknown $file - * + * @var string $file + * 异常文件名称 * @access protected + */ protected $file; /** - * @var unknown $line - * + * @var int $line + * 异常文件行数 * @access protected + */ protected $line; /** - * @var unknown $message - * (Yaf >= 3.0.2) + * @var string $message * 异常信息 * @access protected + */ protected $message; /** - * @var unknown $code - * + * @var int $code + * 异常码 * @access protected + */ protected $code = 0; /** - * @var unknown $previous - * (Yaf >= 3.0.2) + * @var Throwable $previous * 上一个异常对象 * @access protected + */ protected $previous; /** * - * + *克隆方法 * @example * @return */ private final function __clone() { + } /** * - * + *初始化异常 * @example - * @param mixed $message - * @param mixed $code - * @param mixed $previous + * @param string $message 异常提示 + * @param int $code 异常码 + * @param Throwable $previous 上一个异常对象 * @return */ - public function __construct($message, $code, $previous) + public function __construct(string $message = '', int $code = 0, Throwable $previous) { + } /** @@ -75,86 +79,95 @@ public function __construct($message, $code, $previous) */ public function __wakeup() { + } /** * - * + *获取异常信息 * @example - * @return + * @return string */ - public final function getMessage() + public final function getMessage(): string { + } /** * - * + *获取异常码 * @example - * @return + * @return int */ - public final function getCode() + public final function getCode(): int { + } /** * - * + *获取异常文件名称 * @example - * @return + * @return string */ - public final function getFile() + public final function getFile(): string { + } /** * - * + *获取异常行数 * @example - * @return + * @return int */ - public final function getLine() + public final function getLine(): int { + } /** * - * + *获取trace调试数组 * @example - * @return + * @return array */ - public final function getTrace() + public final function getTrace(): array { + } /** * - * + *获取前一个异常对象 * @example - * @return + * @return Throwable */ public final function getPrevious() { + return new Exception(); } /** * - * + *获取调试信息的字符串 * @example - * @return + * @return string */ - public final function getTraceAsString() + public final function getTraceAsString(): string { + } /** * - * + *转化为字符串 * @example - * @return + * @return string */ - public function __toString() + public function __toString(): string { + } } diff --git a/src/Yaf/Exception/LoadFailed/View.php b/src/Yaf/Exception/LoadFailed/View.php index 9c577ac..76cd09a 100644 --- a/src/Yaf/Exception/LoadFailed/View.php +++ b/src/Yaf/Exception/LoadFailed/View.php @@ -1,70 +1,74 @@ = 3.0.2) -*Class YafX_Exception_LoadFailed_View +*视图加载异常 */ namespace Yaf\Exception\LoadFailed; -class View extends \Yaf\Exception\LoadFailed +class View extends \Yaf\Exception\LoadFailed implements \Throwable { /** - * @var unknown $file - * + * @var string $file + * 异常文件名称 * @access protected + */ protected $file; /** - * @var unknown $line - * + * @var int $line + * 异常文件行数 * @access protected + */ protected $line; /** - * @var unknown $message - * (Yaf >= 3.0.2) + * @var string $message * 异常信息 * @access protected + */ protected $message; /** - * @var unknown $code - * + * @var int $code + * 异常码 * @access protected + */ protected $code = 0; /** - * @var unknown $previous - * (Yaf >= 3.0.2) + * @var Throwable $previous * 上一个异常对象 * @access protected + */ protected $previous; /** * - * + *克隆方法 * @example * @return */ private final function __clone() { + } /** * - * + *初始化异常 * @example - * @param mixed $message - * @param mixed $code - * @param mixed $previous + * @param string $message 异常提示 + * @param int $code 异常码 + * @param Throwable $previous 上一个异常对象 * @return */ - public function __construct($message, $code, $previous) + public function __construct(string $message = '', int $code = 0, Throwable $previous) { + } /** @@ -75,86 +79,95 @@ public function __construct($message, $code, $previous) */ public function __wakeup() { + } /** * - * + *获取异常信息 * @example - * @return + * @return string */ - public final function getMessage() + public final function getMessage(): string { + } /** * - * + *获取异常码 * @example - * @return + * @return int */ - public final function getCode() + public final function getCode(): int { + } /** * - * + *获取异常文件名称 * @example - * @return + * @return string */ - public final function getFile() + public final function getFile(): string { + } /** * - * + *获取异常行数 * @example - * @return + * @return int */ - public final function getLine() + public final function getLine(): int { + } /** * - * + *获取trace调试数组 * @example - * @return + * @return array */ - public final function getTrace() + public final function getTrace(): array { + } /** * - * + *获取前一个异常对象 * @example - * @return + * @return Throwable */ public final function getPrevious() { + return new Exception(); } /** * - * + *获取调试信息的字符串 * @example - * @return + * @return string */ - public final function getTraceAsString() + public final function getTraceAsString(): string { + } /** * - * + *转化为字符串 * @example - * @return + * @return string */ - public function __toString() + public function __toString(): string { + } } diff --git a/src/Yaf/Exception/RouterFailed.php b/src/Yaf/Exception/RouterFailed.php index ee167ce..faf2183 100644 --- a/src/Yaf/Exception/RouterFailed.php +++ b/src/Yaf/Exception/RouterFailed.php @@ -1,70 +1,74 @@ = 3.0.2) -*Class YafX_Exception_RouterFailed +*路由失败异常 */ namespace Yaf\Exception; -class RouterFailed extends \Yaf\Exception +class RouterFailed extends \Yaf\Exception implements \Throwable { /** - * @var unknown $file - * + * @var string $file + * 异常文件名称 * @access protected + */ protected $file; /** - * @var unknown $line - * + * @var int $line + * 异常文件行数 * @access protected + */ protected $line; /** - * @var unknown $message - * (Yaf >= 3.0.2) + * @var string $message * 异常信息 * @access protected + */ protected $message; /** - * @var unknown $code - * + * @var int $code + * 异常码 * @access protected + */ protected $code = 0; /** - * @var unknown $previous - * (Yaf >= 3.0.2) + * @var Throwable $previous * 上一个异常对象 * @access protected + */ protected $previous; /** * - * + *克隆方法 * @example * @return */ private final function __clone() { + } /** * - * + *初始化异常 * @example - * @param mixed $message - * @param mixed $code - * @param mixed $previous + * @param string $message 异常提示 + * @param int $code 异常码 + * @param Throwable $previous 上一个异常对象 * @return */ - public function __construct($message, $code, $previous) + public function __construct(string $message = '', int $code = 0, Throwable $previous) { + } /** @@ -75,86 +79,95 @@ public function __construct($message, $code, $previous) */ public function __wakeup() { + } /** * - * + *获取异常信息 * @example - * @return + * @return string */ - public final function getMessage() + public final function getMessage(): string { + } /** * - * + *获取异常码 * @example - * @return + * @return int */ - public final function getCode() + public final function getCode(): int { + } /** * - * + *获取异常文件名称 * @example - * @return + * @return string */ - public final function getFile() + public final function getFile(): string { + } /** * - * + *获取异常行数 * @example - * @return + * @return int */ - public final function getLine() + public final function getLine(): int { + } /** * - * + *获取trace调试数组 * @example - * @return + * @return array */ - public final function getTrace() + public final function getTrace(): array { + } /** * - * + *获取前一个异常对象 * @example - * @return + * @return Throwable */ public final function getPrevious() { + return new Exception(); } /** * - * + *获取调试信息的字符串 * @example - * @return + * @return string */ - public final function getTraceAsString() + public final function getTraceAsString(): string { + } /** * - * + *转化为字符串 * @example - * @return + * @return string */ - public function __toString() + public function __toString(): string { + } } diff --git a/src/Yaf/Exception/StartupError.php b/src/Yaf/Exception/StartupError.php index f7e685c..ff3043c 100644 --- a/src/Yaf/Exception/StartupError.php +++ b/src/Yaf/Exception/StartupError.php @@ -1,70 +1,74 @@ = 3.0.2) -*Class YafX_Exception_StartupError +*启动失败异常 */ namespace Yaf\Exception; -class StartupError extends \Yaf\Exception +class StartupError extends \Yaf\Exception implements \Throwable { /** - * @var unknown $file - * + * @var string $file + * 异常文件名称 * @access protected + */ protected $file; /** - * @var unknown $line - * + * @var int $line + * 异常文件行数 * @access protected + */ protected $line; /** - * @var unknown $message - * (Yaf >= 3.0.2) + * @var string $message * 异常信息 * @access protected + */ protected $message; /** - * @var unknown $code - * + * @var int $code + * 异常码 * @access protected + */ protected $code = 0; /** - * @var unknown $previous - * (Yaf >= 3.0.2) + * @var Throwable $previous * 上一个异常对象 * @access protected + */ protected $previous; /** * - * + *克隆方法 * @example * @return */ private final function __clone() { + } /** * - * + *初始化异常 * @example - * @param mixed $message - * @param mixed $code - * @param mixed $previous + * @param string $message 异常提示 + * @param int $code 异常码 + * @param Throwable $previous 上一个异常对象 * @return */ - public function __construct($message, $code, $previous) + public function __construct(string $message = '', int $code = 0, Throwable $previous) { + } /** @@ -75,86 +79,95 @@ public function __construct($message, $code, $previous) */ public function __wakeup() { + } /** * - * + *获取异常信息 * @example - * @return + * @return string */ - public final function getMessage() + public final function getMessage(): string { + } /** * - * + *获取异常码 * @example - * @return + * @return int */ - public final function getCode() + public final function getCode(): int { + } /** * - * + *获取异常文件名称 * @example - * @return + * @return string */ - public final function getFile() + public final function getFile(): string { + } /** * - * + *获取异常行数 * @example - * @return + * @return int */ - public final function getLine() + public final function getLine(): int { + } /** * - * + *获取trace调试数组 * @example - * @return + * @return array */ - public final function getTrace() + public final function getTrace(): array { + } /** * - * + *获取前一个异常对象 * @example - * @return + * @return Throwable */ public final function getPrevious() { + return new Exception(); } /** * - * + *获取调试信息的字符串 * @example - * @return + * @return string */ - public final function getTraceAsString() + public final function getTraceAsString(): string { + } /** * - * + *转化为字符串 * @example - * @return + * @return string */ - public function __toString() + public function __toString(): string { + } } diff --git a/src/Yaf/Exception/TypeError.php b/src/Yaf/Exception/TypeError.php index 6c0dc86..df82adc 100644 --- a/src/Yaf/Exception/TypeError.php +++ b/src/Yaf/Exception/TypeError.php @@ -1,70 +1,74 @@ = 3.0.2) -*Class YafX_Exception_TypeError +*类型错误异常 */ namespace Yaf\Exception; -class TypeError extends \Yaf\Exception +class TypeError extends \Yaf\Exception implements \Throwable { /** - * @var unknown $file - * + * @var string $file + * 异常文件名称 * @access protected + */ protected $file; /** - * @var unknown $line - * + * @var int $line + * 异常文件行数 * @access protected + */ protected $line; /** - * @var unknown $message - * (Yaf >= 3.0.2) + * @var string $message * 异常信息 * @access protected + */ protected $message; /** - * @var unknown $code - * + * @var int $code + * 异常码 * @access protected + */ protected $code = 0; /** - * @var unknown $previous - * (Yaf >= 3.0.2) + * @var Throwable $previous * 上一个异常对象 * @access protected + */ protected $previous; /** * - * + *克隆方法 * @example * @return */ private final function __clone() { + } /** * - * + *初始化异常 * @example - * @param mixed $message - * @param mixed $code - * @param mixed $previous + * @param string $message 异常提示 + * @param int $code 异常码 + * @param Throwable $previous 上一个异常对象 * @return */ - public function __construct($message, $code, $previous) + public function __construct(string $message = '', int $code = 0, Throwable $previous) { + } /** @@ -75,86 +79,95 @@ public function __construct($message, $code, $previous) */ public function __wakeup() { + } /** * - * + *获取异常信息 * @example - * @return + * @return string */ - public final function getMessage() + public final function getMessage(): string { + } /** * - * + *获取异常码 * @example - * @return + * @return int */ - public final function getCode() + public final function getCode(): int { + } /** * - * + *获取异常文件名称 * @example - * @return + * @return string */ - public final function getFile() + public final function getFile(): string { + } /** * - * + *获取异常行数 * @example - * @return + * @return int */ - public final function getLine() + public final function getLine(): int { + } /** * - * + *获取trace调试数组 * @example - * @return + * @return array */ - public final function getTrace() + public final function getTrace(): array { + } /** * - * + *获取前一个异常对象 * @example - * @return + * @return Throwable */ public final function getPrevious() { + return new Exception(); } /** * - * + *获取调试信息的字符串 * @example - * @return + * @return string */ - public final function getTraceAsString() + public final function getTraceAsString(): string { + } /** * - * + *转化为字符串 * @example - * @return + * @return string */ - public function __toString() + public function __toString(): string { + } } diff --git a/src/Yaf/Loader.php b/src/Yaf/Loader.php index 8310156..cc5b500 100644 --- a/src/Yaf/Loader.php +++ b/src/Yaf/Loader.php @@ -1,188 +1,198 @@ = 3.0.2) -*Class YafX_Loader +*yaf类加载器 */ namespace Yaf; final class Loader { /** - * @var unknown $_library - * (Yaf >= 3.0.2) + * @var string $_library * 当前应用本地类库目录 * @access protected + */ protected $_library; /** - * @var unknown $_global_library - * (Yaf >= 3.0.2) + * @var string $_global_library * 全局类库目录 * @access protected + */ protected $_global_library; /** - * @var unknown $_instance - * (Yaf >= 3.0.2) + * @var Yaf_Loader $_instance * 当前Loader实例(单例模式) * @access protected + */ protected static $_instance; /** * - *(Yaf >= 3.0.2) - *重置__construct魔术方法. + *__construct魔术方法. * @example * @return */ private function __construct() { + } /** * - *(Yaf >= 3.0.2) - *重置__clone魔术方法,防止克隆YafX_Loader(因为是单例模式). + *重置__clone魔术方法,防止克隆yaf_Loader(因为是单例模式). * @example * @return */ private function __clone() { + + } + + /** + * + *__destruct魔术方法. + * @example + * @return + */ + public function __destruct() + { + } /** * - *(Yaf >= 3.0.2) *重置__sleep魔术方法. * @example * @return */ private function __sleep() { + } /** * - *(Yaf >= 3.0.2) *重置__wakeup魔术方法. * @example * @return */ private function __wakeup() { + } /** * - *(Yaf >= 3.0.2) *自动装载类 * @example - * @param mixed $class_name + * @param string $class 类名 * @return */ - public function autoload($class_name) + public function autoload(string $class) { + } /** * - *(Yaf >= 3.0.2) - *获取YafX_Loader实例 + *获取yaf_Loader实例 * @example - * @param mixed $local_library_path - * @param mixed $global_library_path - * @return + * @param string $library 本地类库目录 + * @param string $global 全局类库目录 + * @return Yaf_Loader */ - public static function getInstance($local_library_path, $global_library_path) + public static function getInstance(string $library, string $global): Yaf_Loader { + } /** * - *(Yaf >= 3.0.2) *注册本地类前缀 * @example - * @param mixed $name_prefix + * @param mixed $namespace 一个或者多个类前缀 * @return */ - public function registerLocalNamespace($name_prefix) + public function registerLocalNamespace($namespace) { + } /** * - *(Yaf >= 3.0.2) *获取当前已经注册的本地类前缀 * @example - * @return + * @return string */ - public function getLocalNamespace() + public function getLocalNamespace(): string { + } /** * - *(Yaf >= 3.0.2) *清空已注册的本地类前缀 * @example * @return */ public function clearLocalNamespace() { + } /** * - *(Yaf >= 3.0.2) *判断一个类, 是否是本地类. * @example - * @param mixed $class_name - * @return + * @param string $class_name 类名 + * @return bool */ - public function isLocalName($class_name) + public function isLocalName(string $class_name): bool { + } /** * - *(Yaf >= 3.0.2) *手动导入文件 * @example - * @param mixed $file + * @param string $file include的全路径文件名 * @return */ - public static function import($file) + public static function import(string $file) { + } /** * - *(Yaf >= 3.0.2) *设置本地或者全局类库目录 * @example - * @param mixed $library_path - * @param mixed $is_global + * @param string $library 目录路径 + * @param bool $global 是否为全局类库 * @return */ - public function setLibraryPath($library_path, $is_global) + public function setLibraryPath(string $library, bool $global = false) { + } /** * - *(Yaf >= 3.0.2) *获取本地或者全局类库目录 * @example - * @param mixed $is_global - * @return + * @param bool $global 是否全局类库 + * @return string|bool */ - public function getLibraryPath($is_global) + public function getLibraryPath(bool $global = false): ?string { + } } diff --git a/src/Yaf/Plugin_Abstract.php b/src/Yaf/Plugin_Abstract.php index 50e0d0d..d8de5b6 100644 --- a/src/Yaf/Plugin_Abstract.php +++ b/src/Yaf/Plugin_Abstract.php @@ -1,117 +1,92 @@ = 3.0.2) -*Class YafX_Plugin_Abstract +*插件抽象类 */ namespace Yaf; abstract class Plugin_Abstract { /** * - *(Yaf >= 3.0.2) *在路由之前触发 * @example - * @param YafX_Request_Abstract $request (Yaf >= 3.0.2) -在路由之前触发 - * @param YafX_Response_Abstract $response (Yaf >= 3.0.2) -在路由之前触发 + * @param Yaf_Request_Abstract $request 当前请求对象 + * @param Yaf_Response_Abstract $response 当前响应对象 * @return */ - public function routerStartup($request, $response) + public function routerStartup(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) { + } /** * - *(Yaf >= 3.0.2) *路由结束之后触发 * @example - * @param YafX_Request_Abstract $request (Yaf >= 3.0.2) -路由结束之后触发 - * @param YafX_Response_Abstract $response (Yaf >= 3.0.2) -路由结束之后触发 + * @param Yaf_Request_Abstract $request 当前请求对象 + * @param Yaf_Response_Abstract $response 当前响应对象 * @return */ - public function routerShutdown($request, $response) + public function routerShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) { + } /** * - *(Yaf >= 3.0.2) *分发循环开始之前被触发 * @example - * @param YafX_Request_Abstract $request (Yaf >= 3.0.2) -分发循环开始之前被触发 - * @param YafX_Response_Abstract $response (Yaf >= 3.0.2) -分发循环开始之前被触发 + * @param YafX_Request_Abstract $request 当前请求对象 + * @param Yaf_Response_Abstract $response 当前响应对象 * @return */ - public function dispatchLoopStartup($request, $response) + public function dispatchLoopStartup(YafX_Request_Abstract $request, Yaf_Response_Abstract $response) { + } /** * - *(Yaf >= 3.0.2) - *dispatchLoopShutdown - * @example - * @param YafX_Request_Abstract $request (Yaf >= 3.0.2) -dispatchLoopShutdown - * @param YafX_Response_Abstract $response (Yaf >= 3.0.2) -dispatchLoopShutdown - * @return - */ - public function dispatchLoopShutdown($request, $response) - { - } - - /** - * - *(Yaf >= 3.0.2) *分发之前触发 * @example - * @param YafX_Request_Abstract $request (Yaf >= 3.0.2) -分发之前触发 - * @param YafX_Response_Abstract $response (Yaf >= 3.0.2) -分发之前触发 + * @param Yaf_Request_Abstract $request 当前请求对象 + * @param Yaf_Response_Abstract $response 当前响应对象 * @return */ - public function preDispatch($request, $response) + public function preDispatch(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) { + } /** * - *(Yaf >= 3.0.2) *分发结束之后触发 * @example - * @param YafX_Request_Abstract $request (Yaf >= 3.0.2) -分发结束之后触发 - * @param YafX_Response_Abstract $response (Yaf >= 3.0.2) -分发结束之后触发 + * @param Yaf_Request_Abstract $request 当前请求对象 + * @param Yaf_Response_Abstract $response 当前响应对象 * @return */ - public function postDispatch($request, $response) + public function postDispatch(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) { + } /** * - * + *分发循环结束 * @example - * @param Yaf\Request_Abstract $request - * @param Yaf\Response_Abstract $response + * @param Yaf_Request_Abstract $request 当前请求对象 + * @param Yaf_Response_Abstract $response 当前响应对象 * @return */ - public function preResponse($request, $response) + public function dispatchLoopShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) { + } } diff --git a/src/Yaf/Registry.php b/src/Yaf/Registry.php index 3dd8db3..a270efa 100644 --- a/src/Yaf/Registry.php +++ b/src/Yaf/Registry.php @@ -1,104 +1,99 @@ = 3.0.2) -*Class YafX_Registry +*yaf变量注册器 */ namespace Yaf; final class Registry { /** - * @var unknown $_instance - * (Yaf >= 3.0.2) + * @var Yaf_Registry $_instance * Registry实例(单例模式) * @access protected + */ protected static $_instance; /** - * @var unknown $_entries - * (Yaf >= 3.0.2) + * @var array $_entries * 注册变量栈 * @access protected - protected $_entries; + */ + protected $_entries = array(); /** * - *(Yaf >= 3.0.2) *重置__construct魔术方法. * @example * @return */ private function __construct() { + } /** * - *(Yaf >= 3.0.2) *重置__clone魔术方法,防止克隆Dispatcher(因为是单例模式). * @example * @return */ private function __clone() { + } /** * - *(Yaf >= 3.0.2) *获取注册变量值 * @example - * @param string $name (Yaf >= 3.0.2) -获取注册变量值 - * @return + * @param string $name 变量名 + * @return mixed */ - public static function get($name) + public static function get(string $name) { + } /** * - *(Yaf >= 3.0.2) *检测变量是否存在 * @example - * @param string $name (Yaf >= 3.0.2) -检测变量是否存在 - * @return + * @param string $name 变量名 + * @return bool */ - public static function has($name) + public static function has(string $name): bool { + } /** * - *(Yaf >= 3.0.2) *注册变量 * @example - * @param string $name (Yaf >= 3.0.2) -注册变量 - * @param mixed $value (Yaf >= 3.0.2) -注册变量 - * @return + * @param string $name 变量名 + * @param mixed $value 变量值 + * @return bool */ - public static function set($name, $value) + public static function set(string $name, $value): bool { + } /** * - *(Yaf >= 3.0.2) - *删除变量 + *删除注册器中的变量 * @example - * @param mixed $name + * @param string $name 变量名 * @return */ - public static function del($name) + public static function del(string $name) { + } } diff --git a/src/Yaf/Request/Http.php b/src/Yaf/Request/Http.php index 9ee13af..2d8105c 100644 --- a/src/Yaf/Request/Http.php +++ b/src/Yaf/Request/Http.php @@ -1,387 +1,387 @@ = 3.0.2) -*Class YafX_Request_Http +*http请求对象 */ namespace Yaf\Request; class Http extends \Yaf\Request_Abstract { /** - * @var unknown $module - * (Yaf >= 3.0.2) + * @var string $module * 当前请求的模块名 * @access public + */ public $module; /** - * @var unknown $controller - * (Yaf >= 3.0.2) + * @var string $controller * 当前请求的控制器名 * @access public + */ public $controller; /** - * @var unknown $action - * (Yaf >= 3.0.2) + * @var stirng $action * 当前请求的动作名 * @access public + */ public $action; /** - * @var unknown $method - * (Yaf >= 3.0.2) + * @var string $method * 当前请求的方法 getMethod * @access public + */ public $method; /** - * @var unknown $params - * (Yaf >= 3.0.2) + * @var array $params * 请求传递的参数 * @access protected - protected $params; + */ + protected $params = array(); /** - * @var unknown $language - * (Yaf >= 3.0.2) + * @var string $language * http报头中HTTP_ACCEPT_LANGUAGE的值 * @access protected + */ protected $language; /** - * @var unknown $_exception - * (Yaf >= 3.0.2) + * @var Yaf_Exception $_exception * 异常对象 * @access protected + */ protected $_exception; /** - * @var unknown $_base_uri - * (Yaf >= 3.0.2) + * @var string $_base_uri * 请求的Base URI(http请求 or cli模式下) * @access protected + */ protected $_base_uri = ''; /** - * @var unknown $uri - * (Yaf >= 3.0.2) + * @var string $uri * 请求的URI(http请求) * @access protected + */ protected $uri = ''; /** - * @var unknown $dispatched - * (Yaf >= 3.0.2) + * @var bool $dispatched * 请求是否完成了分发,默认为0 * @access protected - protected $dispatched = ''; + */ + protected $dispatched = false; /** - * @var unknown $routed - * (Yaf >= 3.0.2) + * @var bool $routed * 请求是否完成了路由,默认为0 * @access protected - protected $routed = ''; + */ + protected $routed = false; /** * - *(Yaf >= 3.0.2) - *获取$_GET中名为$name的参数值 + *构造方法 * @example + * @param string $request_uri 请求uri + * @param string $base_uri Base URI * @return */ - public function getQuery() + public function __construct(string $request_uri, string $base_uri) { + } /** * - *(Yaf >= 3.0.2) - *获取$_REQUEST中名为$name的参数值 + *获取$_GET中名为$name的参数值 * @example - * @return + * @param string $name 变量名 + * @param string $default 默认值 + * @return string */ - public function getRequest() + public function getQuery(string $name, string $default): string { + } /** * - *(Yaf >= 3.0.2) - *获取$_POST中名为$name的参数值 + *获取$_REQUEST中名为$name的参数值 * @example - * @return + * @param string $name 变量名 + * @return Yaf_Request_Abstract */ - public function getPost() + public function getRequest(string $name): Yaf_Request_Abstract { + } /** * - *(Yaf >= 3.0.2) - *获取$_COOKIE中名为$name的参数值 + *获取$_POST中名为$name的参数值 * @example - * @return + * @param string $name 变量名 + * @param string $default 默认值 + * @return string */ - public function getCookie() + public function getPost(string $name, string $default): string { + } /** * - *(Yaf >= 3.0.2) - *获取$_FILES中名为$name的参数值 + *获取$_COOKIE中名为$name的参数值 * @example - * @return + * @param string $name 变量名 + * @return string */ - public function getFiles() + public function getCookie(string $name): string { + } /** * - *(Yaf >= 3.0.2) - *获取全局变量中的值(扫描顺序为$_POST,$_GET,$_COOKIE,$_SERVER) + *获取$_FILES中名为$name的参数值 * @example - * @return + * @param string $name 变量名 + * @return array */ - public function get() + public function getFiles(string $name): array { + } /** * - *(Yaf >= 3.0.2) *判断是否为AJAX请求 * @example - * @return + * @return bool */ - public function isXmlHttpRequest() + public function isXmlHttpRequest(): bool { + } /** * - *(Yaf >= 3.0.2) - *构造方法 + *获取全局变量中的值(扫描顺序为$_POST,$_GET,$_COOKIE,$_SERVER) * @example - * @return + * @param string $name 变量名 + * @param mixed $default 默认值 + * @return string */ - public function __construct() + public function get(string $name, $default): string { + } /** * - *(Yaf >= 3.0.2) *重置__clone魔术方法 * @example * @return */ private function __clone() { + } /** * - *(Yaf >= 3.0.2) *判断是否为GET请求 * @example - * @return + * @return bool */ - public function isGet() + public function isGet(): bool { + } /** * - *(Yaf >= 3.0.2) *判断是否为POST请求 * @example - * @return + * @return bool */ - public function isPost() + public function isPost(): bool { + } /** * - *(Yaf >= 3.0.2) *判断是否为PUT请求 * @example - * @return + * @return bool */ - public function isPut() + public function isPut(): bool { + } /** * - *(Yaf >= 3.0.2) *判断是否为HEAD请求 * @example - * @return + * @return bool */ - public function isHead() + public function isHead(): bool { + } /** * - *(Yaf >= 3.0.2) *判断是否为Options请求 * @example - * @return + * @return bool */ - public function isOptions() + public function isOptions(): bool { + } /** * - *(Yaf >= 3.0.2) *判断是否为CLI请求 * @example - * @return + * @return bool */ - public function isCli() + public function isCli(): bool { + } /** * - *(Yaf >= 3.0.2) *获取服务器$_SERVER全局变量中的值 * @example - * @param string $name (Yaf >= 3.0.2) -获取服务器$_SERVER全局变量中的值 - * @param mixed $default (Yaf >= 3.0.2) -获取服务器$_SERVER全局变量中的值 - * @return + * @param string $name 变量名 + * @param mixed $default 默认值 + * @return mixed */ - public function getServer($name, $default) + public function getServer(string $name, $default) { + } /** * - *(Yaf >= 3.0.2) *获取环境变量$_ENV全局变量中的值 * @example - * @param string $name (Yaf >= 3.0.2) -获取环境变量$_ENV全局变量中的值 - * @param string $default (Yaf >= 3.0.2) -获取环境变量$_ENV全局变量中的值 - * @return + * @param string $name 变量名 + * @param string $default 默认值 + * @return mixed */ - public function getEnv($name, $default) + public function getEnv(string $name, string $default) { + } /** * - *(Yaf >= 3.0.2) *设置请求的参数 *当只有一个参数且为Array类型,如果存在对应的键值将覆盖 * @example - * @param string $name (Yaf >= 3.0.2) -设置请求的参数 -当只有一个参数且为Array类型,如果存在对应的键值将覆盖 - * @param mixed $value (Yaf >= 3.0.2) -设置请求的参数 -当只有一个参数且为Array类型,如果存在对应的键值将覆盖 + * @param string $name 变量名 + * @param mixed $value 变量值 * @return */ - public function setParam($name, $value) + public function setParam(string $name, $value) { + } /** * - *(Yaf >= 3.0.2) *获取请求的参数 * @example - * @param string $name (Yaf >= 3.0.2) -获取请求的参数 - * @param string $default (Yaf >= 3.0.2) -获取请求的参数 - * @return + * @param string $name 变量名 + * @param string $default 默认值 + * @return string */ - public function getParam($name, $default) + public function getParam(string $name, string $default): string { + } /** * - *(Yaf >= 3.0.2) *获取请求全部的参数 * @example - * @return + * @return array */ - public function getParams() + public function getParams(): array { + } /** * - *(Yaf >= 3.0.2) *获取异常对象 * @example - * @return + * @return Yaf_Exception */ - public function getException() + public function getException(): Yaf_Exception { + } /** * - *(Yaf >= 3.0.2) *获取当前模块名 * @example - * @return + * @return string */ - public function getModuleName() + public function getModuleName(): string { + } /** * - *(Yaf >= 3.0.2) *获取当前控制器名 * @example - * @return + * @return string */ - public function getControllerName() + public function getControllerName(): string { + } /** * - *(Yaf >= 3.0.2) *获取当前动作名 * @example - * @return + * @return string */ - public function getActionName() + public function getActionName(): string { + } /** * - *(Yaf >= 3.0.2) *设置请求的模块名 * @example - * @param mixed $module + * @param string $name 模块名 * @return */ - public function setModuleName($module) + public function setModuleName(string $name) { + } /** @@ -389,79 +389,80 @@ public function setModuleName($module) *(Yaf >= 3.0.2) *设置请求的控制器名 * @example - * @param mixed $controller + * @param string $name 控制器名称 * @return */ - public function setControllerName($controller) + public function setControllerName(string $name) { + } /** * - *(Yaf >= 3.0.2) *设置请求的动作名 * @example - * @param mixed $action + * @param string $name 操作名称 * @return */ - public function setActionName($action) + public function setActionName(string $name) { + } /** * - *(Yaf >= 3.0.2) *获取当前请求的方法 * @example - * @return + * @return string */ - public function getMethod() + public function getMethod(): string { + } /** * - *(Yaf >= 3.0.2) *获取当前请求的请求 * @example - * @return + * @return string */ - public function getLanguage() + public function getLanguage(): string { + } /** * - *(Yaf >= 3.0.2) *设置请求的Base URI * @example - * @param mixed $uri + * @param string $baseuri 基本uri * @return */ - public function setBaseUri($uri) + public function setBaseUri(string $baseuri) { + } /** * - *(Yaf >= 3.0.2) *获取请求的Base URI * @example - * @return + * @return string */ - public function getBaseUri() + public function getBaseUri(): string { + } /** * - *(Yaf >= 3.0.2) *获取请求的uri * @example - * @return + * @return string */ - public function getRequestUri() + public function getRequestUri(): string { + } /** @@ -469,56 +470,56 @@ public function getRequestUri() *(Yaf >= 3.0.2) *设置请求的URI * @example - * @param mixed $uri + * @param string $uri 请求uri * @return */ - public function setRequestUri($uri) + public function setRequestUri(string $uri) { + } /** * - *(Yaf >= 3.0.2) *判断请求是否完成了分发 * @example - * @return + * @return bool */ - public function isDispatched() + public function isDispatched(): bool { + } /** * - *(Yaf >= 3.0.2) *设置请求已经完成分发 * @example - * @return + * @return bool */ - public function setDispatched() + public function setDispatched(): bool { + } /** * - *(Yaf >= 3.0.2) *判断请求是否完成了路由 * @example - * @return + * @return bool */ - public function isRouted() + public function isRouted(): bool { + } /** * - *(Yaf >= 3.0.2) *设置请求已经完成了路由 * @example - * @param mixed $flag - * @return + * @return bool */ - public function setRouted($flag) + public function setRouted(): bool { + } } diff --git a/src/Yaf/Request/Simple.php b/src/Yaf/Request/Simple.php index feb9794..574da24 100644 --- a/src/Yaf/Request/Simple.php +++ b/src/Yaf/Request/Simple.php @@ -1,397 +1,397 @@ = 3.0.2) -*Class YafX_Request_Simple +*yaf简单请求类 */ namespace Yaf\Request; final class Simple extends \Yaf\Request_Abstract { /** - * + *http请求 */ const SCHEME_HTTP = 'http'; /** - * + *https请求 */ const SCHEME_HTTPS = 'https'; /** - * @var unknown $module - * (Yaf >= 3.0.2) + * @var string $module * 当前请求的模块名 * @access public + */ public $module; /** - * @var unknown $controller - * (Yaf >= 3.0.2) + * @var string $controller * 当前请求的控制器名 * @access public + */ public $controller; /** - * @var unknown $action - * (Yaf >= 3.0.2) + * @var stirng $action * 当前请求的动作名 * @access public + */ public $action; /** - * @var unknown $method - * (Yaf >= 3.0.2) + * @var string $method * 当前请求的方法 getMethod * @access public + */ public $method; /** - * @var unknown $params - * (Yaf >= 3.0.2) + * @var array $params * 请求传递的参数 * @access protected - protected $params; + */ + protected $params = array(); /** - * @var unknown $language - * (Yaf >= 3.0.2) + * @var string $language * http报头中HTTP_ACCEPT_LANGUAGE的值 * @access protected + */ protected $language; /** - * @var unknown $_exception - * (Yaf >= 3.0.2) + * @var Yaf_Exception $_exception * 异常对象 * @access protected + */ protected $_exception; /** - * @var unknown $_base_uri - * (Yaf >= 3.0.2) + * @var string $_base_uri * 请求的Base URI(http请求 or cli模式下) * @access protected + */ protected $_base_uri = ''; /** - * @var unknown $uri - * (Yaf >= 3.0.2) + * @var string $uri * 请求的URI(http请求) * @access protected + */ protected $uri = ''; /** - * @var unknown $dispatched - * (Yaf >= 3.0.2) + * @var bool $dispatched * 请求是否完成了分发,默认为0 * @access protected - protected $dispatched = ''; + */ + protected $dispatched = false; /** - * @var unknown $routed - * (Yaf >= 3.0.2) + * @var bool $routed * 请求是否完成了路由,默认为0 * @access protected - protected $routed = ''; + */ + protected $routed = false; /** * - *(Yaf >= 3.0.2) *构造方法 * @example + * @param string $request_uri 请求uri + * @param string $base_uri Base URI * @return */ - public function __construct() + public function __construct(string $request_uri, string $base_uri) { + } /** * - *(Yaf >= 3.0.2) - *重置__clone魔术方法 + *获取$_GET中名为$name的参数值 * @example - * @return + * @param string $name 变量名 + * @param string $default 默认值 + * @return string */ - private function __clone() + public function getQuery(string $name, string $default): string { + } /** * - *(Yaf >= 3.0.2) - *获取$_GET中名为$name的参数值 + *获取$_REQUEST中名为$name的参数值 * @example - * @return + * @param string $name 变量名 + * @return Yaf_Request_Abstract */ - public function getQuery() + public function getRequest(string $name): Yaf_Request_Abstract { + } /** * - *(Yaf >= 3.0.2) - *获取$_REQUEST中名为$name的参数值 + *获取$_POST中名为$name的参数值 * @example - * @return + * @param string $name 变量名 + * @param string $default 默认值 + * @return string */ - public function getRequest() + public function getPost(string $name, string $default): string { + } /** * - *(Yaf >= 3.0.2) - *获取$_POST中名为$name的参数值 + *获取$_COOKIE中名为$name的参数值 * @example - * @return + * @param string $name 变量名 + * @return string */ - public function getPost() + public function getCookie(string $name): string { + } /** * - *(Yaf >= 3.0.2) - *获取$_COOKIE中名为$name的参数值 + *获取$_FILES中名为$name的参数值 * @example - * @return + * @param string $name 变量名 + * @return array */ - public function getCookie() + public function getFiles(string $name): array { + } /** * - *(Yaf >= 3.0.2) - *获取$_FILES中名为$name的参数值 + *判断是否为AJAX请求 * @example - * @return + * @return bool */ - public function getFiles() + public function isXmlHttpRequest(): bool { + } /** * - *(Yaf >= 3.0.2) *获取全局变量中的值(扫描顺序为$_POST,$_GET,$_COOKIE,$_SERVER) * @example - * @return + * @param string $name 变量名 + * @param mixed $default 默认值 + * @return string */ - public function get() + public function get(string $name, $default): string { + } /** * - *(Yaf >= 3.0.2) - *判断是否为AJAX请求 + *重置__clone魔术方法 * @example * @return */ - public function isXmlHttpRequest() + private function __clone() { + } /** * - *(Yaf >= 3.0.2) *判断是否为GET请求 * @example - * @return + * @return bool */ - public function isGet() + public function isGet(): bool { + } /** * - *(Yaf >= 3.0.2) *判断是否为POST请求 * @example - * @return + * @return bool */ - public function isPost() + public function isPost(): bool { + } /** * - *(Yaf >= 3.0.2) *判断是否为PUT请求 * @example - * @return + * @return bool */ - public function isPut() + public function isPut(): bool { + } /** * - *(Yaf >= 3.0.2) *判断是否为HEAD请求 * @example - * @return + * @return bool */ - public function isHead() + public function isHead(): bool { + } /** * - *(Yaf >= 3.0.2) *判断是否为Options请求 * @example - * @return + * @return bool */ - public function isOptions() + public function isOptions(): bool { + } /** * - *(Yaf >= 3.0.2) *判断是否为CLI请求 * @example - * @return + * @return bool */ - public function isCli() + public function isCli(): bool { + } /** * - *(Yaf >= 3.0.2) *获取服务器$_SERVER全局变量中的值 * @example - * @param string $name (Yaf >= 3.0.2) -获取服务器$_SERVER全局变量中的值 - * @param mixed $default (Yaf >= 3.0.2) -获取服务器$_SERVER全局变量中的值 - * @return + * @param string $name 变量名 + * @param mixed $default 默认值 + * @return mixed */ - public function getServer($name, $default) + public function getServer(string $name, $default) { + } /** * - *(Yaf >= 3.0.2) *获取环境变量$_ENV全局变量中的值 * @example - * @param string $name (Yaf >= 3.0.2) -获取环境变量$_ENV全局变量中的值 - * @param string $default (Yaf >= 3.0.2) -获取环境变量$_ENV全局变量中的值 - * @return + * @param string $name 变量名 + * @param string $default 默认值 + * @return mixed */ - public function getEnv($name, $default) + public function getEnv(string $name, string $default) { + } /** * - *(Yaf >= 3.0.2) *设置请求的参数 *当只有一个参数且为Array类型,如果存在对应的键值将覆盖 * @example - * @param string $name (Yaf >= 3.0.2) -设置请求的参数 -当只有一个参数且为Array类型,如果存在对应的键值将覆盖 - * @param mixed $value (Yaf >= 3.0.2) -设置请求的参数 -当只有一个参数且为Array类型,如果存在对应的键值将覆盖 + * @param string $name 变量名 + * @param mixed $value 变量值 * @return */ - public function setParam($name, $value) + public function setParam(string $name, $value) { + } /** * - *(Yaf >= 3.0.2) *获取请求的参数 * @example - * @param string $name (Yaf >= 3.0.2) -获取请求的参数 - * @param string $default (Yaf >= 3.0.2) -获取请求的参数 - * @return + * @param string $name 变量名 + * @param string $default 默认值 + * @return string */ - public function getParam($name, $default) + public function getParam(string $name, string $default): string { + } /** * - *(Yaf >= 3.0.2) *获取请求全部的参数 * @example - * @return + * @return array */ - public function getParams() + public function getParams(): array { + } /** * - *(Yaf >= 3.0.2) *获取异常对象 * @example - * @return + * @return Yaf_Exception */ - public function getException() + public function getException(): Yaf_Exception { + } /** * - *(Yaf >= 3.0.2) *获取当前模块名 * @example - * @return + * @return string */ - public function getModuleName() + public function getModuleName(): string { + } /** * - *(Yaf >= 3.0.2) *获取当前控制器名 * @example - * @return + * @return string */ - public function getControllerName() + public function getControllerName(): string { + } /** * - *(Yaf >= 3.0.2) *获取当前动作名 * @example - * @return + * @return string */ - public function getActionName() + public function getActionName(): string { + } /** * - *(Yaf >= 3.0.2) *设置请求的模块名 * @example - * @param mixed $module + * @param string $name 模块名 * @return */ - public function setModuleName($module) + public function setModuleName(string $name) { + } /** @@ -399,79 +399,80 @@ public function setModuleName($module) *(Yaf >= 3.0.2) *设置请求的控制器名 * @example - * @param mixed $controller + * @param string $name 控制器名称 * @return */ - public function setControllerName($controller) + public function setControllerName(string $name) { + } /** * - *(Yaf >= 3.0.2) *设置请求的动作名 * @example - * @param mixed $action + * @param string $name 操作名称 * @return */ - public function setActionName($action) + public function setActionName(string $name) { + } /** * - *(Yaf >= 3.0.2) *获取当前请求的方法 * @example - * @return + * @return string */ - public function getMethod() + public function getMethod(): string { + } /** * - *(Yaf >= 3.0.2) *获取当前请求的请求 * @example - * @return + * @return string */ - public function getLanguage() + public function getLanguage(): string { + } /** * - *(Yaf >= 3.0.2) *设置请求的Base URI * @example - * @param mixed $uri + * @param string $baseuri 基本uri * @return */ - public function setBaseUri($uri) + public function setBaseUri(string $baseuri) { + } /** * - *(Yaf >= 3.0.2) *获取请求的Base URI * @example - * @return + * @return string */ - public function getBaseUri() + public function getBaseUri(): string { + } /** * - *(Yaf >= 3.0.2) *获取请求的uri * @example - * @return + * @return string */ - public function getRequestUri() + public function getRequestUri(): string { + } /** @@ -479,56 +480,56 @@ public function getRequestUri() *(Yaf >= 3.0.2) *设置请求的URI * @example - * @param mixed $uri + * @param string $uri 请求uri * @return */ - public function setRequestUri($uri) + public function setRequestUri(string $uri) { + } /** * - *(Yaf >= 3.0.2) *判断请求是否完成了分发 * @example - * @return + * @return bool */ - public function isDispatched() + public function isDispatched(): bool { + } /** * - *(Yaf >= 3.0.2) *设置请求已经完成分发 * @example - * @return + * @return bool */ - public function setDispatched() + public function setDispatched(): bool { + } /** * - *(Yaf >= 3.0.2) *判断请求是否完成了路由 * @example - * @return + * @return bool */ - public function isRouted() + public function isRouted(): bool { + } /** * - *(Yaf >= 3.0.2) *设置请求已经完成了路由 * @example - * @param mixed $flag - * @return + * @return bool */ - public function setRouted($flag) + public function setRouted(): bool { + } } diff --git a/src/Yaf/Request_Abstract.php b/src/Yaf/Request_Abstract.php index 85d10f1..e6c986d 100644 --- a/src/Yaf/Request_Abstract.php +++ b/src/Yaf/Request_Abstract.php @@ -1,446 +1,434 @@ = 3.0.2) -*Class YafX_Request_Abstract +*请求抽象类 */ namespace Yaf; abstract class Request_Abstract { /** - * + *http请求 */ const SCHEME_HTTP = 'http'; /** - * + *https请求 */ const SCHEME_HTTPS = 'https'; /** - * @var unknown $module - * (Yaf >= 3.0.2) + * @var string $module * 当前请求的模块名 * @access public + */ public $module; /** - * @var unknown $controller - * (Yaf >= 3.0.2) + * @var string $controller * 当前请求的控制器名 * @access public + */ public $controller; /** - * @var unknown $action - * (Yaf >= 3.0.2) + * @var stirng $action * 当前请求的动作名 * @access public + */ public $action; /** - * @var unknown $method - * (Yaf >= 3.0.2) + * @var string $method * 当前请求的方法 getMethod * @access public + */ public $method; /** - * @var unknown $params - * (Yaf >= 3.0.2) + * @var array $params * 请求传递的参数 * @access protected - protected $params; + */ + protected $params = array(); /** - * @var unknown $language - * (Yaf >= 3.0.2) + * @var string $language * http报头中HTTP_ACCEPT_LANGUAGE的值 * @access protected + */ protected $language; /** - * @var unknown $_exception - * (Yaf >= 3.0.2) + * @var Yaf_Exception $_exception * 异常对象 * @access protected + */ protected $_exception; /** - * @var unknown $_base_uri - * (Yaf >= 3.0.2) + * @var string $_base_uri * 请求的Base URI(http请求 or cli模式下) * @access protected + */ protected $_base_uri = ''; /** - * @var unknown $uri - * (Yaf >= 3.0.2) + * @var string $uri * 请求的URI(http请求) * @access protected + */ protected $uri = ''; /** - * @var unknown $dispatched - * (Yaf >= 3.0.2) + * @var bool $dispatched * 请求是否完成了分发,默认为0 * @access protected - protected $dispatched = ''; + */ + protected $dispatched = false; /** - * @var unknown $routed - * (Yaf >= 3.0.2) + * @var bool $routed * 请求是否完成了路由,默认为0 * @access protected - protected $routed = ''; + */ + protected $routed = false; /** * - *(Yaf >= 3.0.2) *判断是否为GET请求 * @example - * @return + * @return bool */ - public function isGet() + public function isGet(): bool { + } /** * - *(Yaf >= 3.0.2) *判断是否为POST请求 * @example - * @return + * @return bool */ - public function isPost() + public function isPost(): bool { + } /** * - *(Yaf >= 3.0.2) *判断是否为PUT请求 * @example - * @return + * @return bool */ - public function isPut() + public function isPut(): bool { + } /** * - *(Yaf >= 3.0.2) *判断是否为HEAD请求 * @example - * @return + * @return bool */ - public function isHead() + public function isHead(): bool { + } /** * - *(Yaf >= 3.0.2) *判断是否为Options请求 * @example - * @return + * @return bool */ - public function isOptions() + public function isOptions(): bool { + } /** * - *(Yaf >= 3.0.2) *判断是否为CLI请求 * @example - * @return + * @return bool */ - public function isCli() + public function isCli(): bool { + } /** * - *(Yaf >= 3.0.2) *判断是否为AJAX请求 * @example - * @return + * @return bool */ - public function isXmlHttpRequest() + public function isXmlHttpRequest(): bool { + } /** * - *(Yaf >= 3.0.2) *获取服务器$_SERVER全局变量中的值 * @example - * @param string $name (Yaf >= 3.0.2) -获取服务器$_SERVER全局变量中的值 - * @param mixed $default (Yaf >= 3.0.2) -获取服务器$_SERVER全局变量中的值 - * @return + * @param string $name 变量名 + * @param mixed $default 默认值 + * @return mixed */ - public function getServer($name, $default) + public function getServer(string $name, $default) { + } /** * - *(Yaf >= 3.0.2) *获取环境变量$_ENV全局变量中的值 * @example - * @param string $name (Yaf >= 3.0.2) -获取环境变量$_ENV全局变量中的值 - * @param string $default (Yaf >= 3.0.2) -获取环境变量$_ENV全局变量中的值 - * @return + * @param string $name 变量名 + * @param string $default 默认值 + * @return mixed */ - public function getEnv($name, $default) + public function getEnv(string $name, string $default) { + } /** * - *(Yaf >= 3.0.2) *设置请求的参数 *当只有一个参数且为Array类型,如果存在对应的键值将覆盖 * @example - * @param string $name (Yaf >= 3.0.2) -设置请求的参数 -当只有一个参数且为Array类型,如果存在对应的键值将覆盖 - * @param mixed $value (Yaf >= 3.0.2) -设置请求的参数 -当只有一个参数且为Array类型,如果存在对应的键值将覆盖 + * @param string $name 变量名 + * @param mixed $value 变量值 * @return */ - public function setParam($name, $value) + public function setParam(string $name, $value) { + } /** * - *(Yaf >= 3.0.2) *获取请求的参数 * @example - * @param string $name (Yaf >= 3.0.2) -获取请求的参数 - * @param string $default (Yaf >= 3.0.2) -获取请求的参数 + * @param string $name 变量名 + * @param string $default 默认值 * @return */ - public function getParam($name, $default) + public function getParam(string $name, string $default) { + } /** * - *(Yaf >= 3.0.2) *获取请求全部的参数 * @example - * @return + * @return array|null */ - public function getParams() + public function getParams(): ?array { + } /** * - *(Yaf >= 3.0.2) *获取异常对象 * @example - * @return + * @return Yaf_Exception */ - public function getException() + public function getException(): Yaf_Exception { + } /** * - *(Yaf >= 3.0.2) *获取当前模块名 * @example - * @return + * @return string */ - public function getModuleName() + public function getModuleName(): string { + } /** * - *(Yaf >= 3.0.2) *获取当前控制器名 * @example - * @return + * @return string */ - public function getControllerName() + public function getControllerName(): string { + } /** * - *(Yaf >= 3.0.2) *获取当前动作名 * @example - * @return + * @return string */ - public function getActionName() + public function getActionName(): string { + } /** * - *(Yaf >= 3.0.2) *设置请求的模块名 * @example - * @param mixed $module + * @param string $name 模块名 * @return */ - public function setModuleName($module) + public function setModuleName(string $name) { + } /** * - *(Yaf >= 3.0.2) *设置请求的控制器名 * @example - * @param mixed $controller + * @param string $name 控制器名称 * @return */ - public function setControllerName($controller) + public function setControllerName(string $name) { + } /** * - *(Yaf >= 3.0.2) *设置请求的动作名 * @example - * @param mixed $action + * @param string $name 操作名称 * @return */ - public function setActionName($action) + public function setActionName(string $name) { + } /** * - *(Yaf >= 3.0.2) *获取当前请求的方法 * @example - * @return + * @return string */ - public function getMethod() + public function getMethod(): string { + } /** * - *(Yaf >= 3.0.2) - *获取当前请求的请求 + *获取当前请求的请求的语言 * @example - * @return + * @return string */ - public function getLanguage() + public function getLanguage(): string { + } /** * - *(Yaf >= 3.0.2) *设置请求的Base URI * @example - * @param mixed $uri + * @param string $baseuri 基本请求地址 * @return */ - public function setBaseUri($uri) + public function setBaseUri(string $baseuri) { + } /** * - *(Yaf >= 3.0.2) *获取请求的Base URI * @example - * @return + * @return string */ - public function getBaseUri() + public function getBaseUri(): string { + } /** * - *(Yaf >= 3.0.2) *获取请求的uri * @example - * @return + * @return string */ - public function getRequestUri() + public function getRequestUri(): string { + } /** * - *(Yaf >= 3.0.2) *设置请求的URI * @example - * @param mixed $uri + * @param string $uri 请求uri * @return */ - public function setRequestUri($uri) + public function setRequestUri(string $uri) { + } /** * - *(Yaf >= 3.0.2) *判断请求是否完成了分发 * @example - * @return + * @return bool */ - public function isDispatched() + public function isDispatched(): bool { + } /** * - *(Yaf >= 3.0.2) *设置请求已经完成分发 * @example - * @return + * @return bool */ - public function setDispatched() + public function setDispatched(): bool { + } /** * - *(Yaf >= 3.0.2) *判断请求是否完成了路由 * @example - * @return + * @return bool */ - public function isRouted() + public function isRouted(): bool { + } /** * - *(Yaf >= 3.0.2) *设置请求已经完成了路由 * @example - * @param mixed $flag - * @return + * @return bool */ - public function setRouted($flag) + public function setRouted(): bool { + } } diff --git a/src/Yaf/Response/Cli.php b/src/Yaf/Response/Cli.php index df923f1..1d63317 100644 --- a/src/Yaf/Response/Cli.php +++ b/src/Yaf/Response/Cli.php @@ -1,166 +1,214 @@ = 3.0.2) -*Class YafX_Response_Cli +*命令行下响应对象 */ namespace Yaf\Response; class Cli extends \Yaf\Response_Abstract { /** - * + *默认内容 */ const DEFAULT_BODY = 'content'; /** - * @var unknown $_header - * (Yaf >= 3.0.2) + * @var array $_header * 响应报头 * @access protected - protected $_header; + */ + protected $_header = array(); /** - * @var unknown $_body - * (Yaf >= 3.0.2) - * 响应正文 + * @var string $_body + * 响应体 * @access protected + */ protected $_body; /** - * @var unknown $_sendheader - * (Yaf >= 3.0.2) + * @var bool $_sendheader * 是否开启已输出响应报头检测 * @access protected - protected $_sendheader = ''; + */ + protected $_sendheader = false; /** * - *(Yaf >= 3.0.2) *构造方法 * @example * @return */ public function __construct() { + } /** * - *(Yaf >= 3.0.2) *析构方法 * @example * @return */ public function __destruct() { + } /** * - *(Yaf >= 3.0.2) *重置__clone魔术方法 * @example * @return */ private function __clone() { + } /** * - *(Yaf >= 3.0.2) *返回响应正文的字符串 * @example * @return */ public function __toString() { + } /** * - *(Yaf >= 3.0.2) *设置类型为$name的响应正文内容 * @example - * @param string $body (Yaf >= 3.0.2) -设置类型为$name的响应正文内容 - * @param string $name (Yaf >= 3.0.2) -设置类型为$name的响应正文内容 + * @param string $body 响应正文内容(可覆盖原来的) + * @param string $name 响应正文类型,默认为content * @return */ - public function setBody($body, $name) + public function setBody(string $body, string $name = 'content') + { + + } + + /** + * + *获取类型为$name的响应正文内容 + * @example + * @param string $name 响应正文类型,默认为content + * @return string|null + */ + public function getBody(string $name = 'content'): ?string { + } /** * - *(Yaf >= 3.0.2) *设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的后面 * @example - * @param string $body (Yaf >= 3.0.2) -设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的后面 - * @param string $name (Yaf >= 3.0.2) -设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的后面 + * @param string $body 响应正文内容(可追加) + * @param string $name 响应正文类型,默认为content * @return */ - public function appendBody($body, $name) + public function appendBody(string $body, string $name) { + } /** * - *(Yaf >= 3.0.2) *设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的前面 * @example - * @param string $body (Yaf >= 3.0.2) -设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的前面 - * @param string $name (Yaf >= 3.0.2) -设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的前面 + * @param string $body 响应正文内容(可追加) + * @param string $name 响应正文类型,默认为content * @return */ - public function prependBody($body, $name) + public function prependBody(string $body, string $name) { + } /** * - *(Yaf >= 3.0.2) *清空响应正文 * @example - * @param mixed $name * @return */ - public function clearBody($name) + public function clearBody() { + } /** * - *(Yaf >= 3.0.2) - *获取类型为$name的响应正文内容 + *获取响应报头 + * @example + * @return array + */ + public function getHeader(): array + { + + } + + /** + * + *批量设置响应报头 + * @example + * @param array $headers 响应头列表 + * @return + */ + public function setAllHeaders(Array $headers) + { + + } + + /** + * + *设置响应报头 + * @example + * @return + */ + public function setHeader() + { + + } + + /** + * + *清空响应报头 + * @example + * @return + */ + public function clearHeaders() + { + + } + + /** + * + *将当前请求重定向到指定的URL(内部实现是通过发送Location报头实现,如:header("Location:http//www.phpboy.net/")) * @example - * @param string $name (Yaf >= 3.0.2) -获取类型为$name的响应正文内容 + * @param string $url 重定向的绝对URL * @return */ - public function getBody($name) + public function setRedirect(string $url) { + } /** * - *(Yaf >= 3.0.2) *输出所有的响应正文 * @example * @return */ public function response() { + } } diff --git a/src/Yaf/Response/Http.php b/src/Yaf/Response/Http.php index 887f092..95ccfc0 100644 --- a/src/Yaf/Response/Http.php +++ b/src/Yaf/Response/Http.php @@ -1,236 +1,221 @@ = 3.0.2) -*Class YafX_Response_Http +*HTTP响应 */ namespace Yaf\Response; class Http extends \Yaf\Response_Abstract { /** - * + *默认内容 */ const DEFAULT_BODY = 'content'; /** - * @var unknown $_header - * (Yaf >= 3.0.2) + * @var array $_header * 响应报头 * @access protected - protected $_header; + */ + protected $_header = array(); /** - * @var unknown $_body - * (Yaf >= 3.0.2) + * @var string $_body * 响应正文 * @access protected + */ protected $_body; /** - * @var unknown $_sendheader - * (Yaf >= 3.0.2) + * @var bool $_sendheader * 是否开启已输出响应报头检测 * @access protected - protected $_sendheader = '1'; + */ + protected $_sendheader = true; /** - * @var unknown $_response_code - * (Yaf >= 3.0.2) + * @var int $_response_code * 响应状态码 * @access protected + */ protected $_response_code = 0; /** * - *(Yaf >= 3.0.2) - *设置响应报头 + *构造方法 * @example - * @param mixed $name - * @param mixed $value - * @param mixed $rep - * @param mixed $response_code * @return */ - public function setHeader($name, $value, $rep, $response_code) + public function __construct() { + } /** * - *(Yaf >= 3.0.2) - *获取所有响应报头 + *析构方法 * @example - * @param mixed $headers * @return */ - public function setAllHeaders($headers) + public function __destruct() { + } /** * - *(Yaf >= 3.0.2) - *获取响应报头 + *重置__clone魔术方法 * @example - * @param mixed $name * @return */ - public function getHeader($name) + private function __clone() { + } /** * - *(Yaf >= 3.0.2) - *清空响应报头 + *返回响应正文的字符串 * @example * @return */ - public function clearHeaders() + public function __toString() { + } /** * - *(Yaf >= 3.0.2) - *将当前请求重定向到指定的URL(内部实现是通过发送Location报头实现,如:header("Location:http//www.phpboy.net/")) + *设置类型为$name的响应正文内容 * @example - * @param string $url (Yaf >= 3.0.2) -将当前请求重定向到指定的URL(内部实现是通过发送Location报头实现,如:header("Location:http//www.phpboy.net/")) + * @param string $body 响应正文内容(可覆盖原来的) + * @param string $name 响应正文类型,默认为content * @return */ - public function setRedirect($url) + public function setBody(string $body, string $name = 'content') { + } /** * - *(Yaf >= 3.0.2) - *输出所有的响应正文 + *获取类型为$name的响应正文内容 * @example + * @param string $name 响应正文类型,默认为content * @return */ - public function response() + public function getBody(string $name = 'content') { + } /** * - *(Yaf >= 3.0.2) - *构造方法 + *设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的后面 * @example + * @param string $body 响应正文内容(可追加) + * @param string $name 响应正文类型,默认为content * @return */ - public function __construct() + public function appendBody(string $body, string $name) { + } /** * - *(Yaf >= 3.0.2) - *析构方法 + *设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的前面 * @example + * @param string $body 响应正文内容(可追加) + * @param string $name 响应正文类型,默认为content * @return */ - public function __destruct() + public function prependBody(string $body, string $name) { + } /** * - *(Yaf >= 3.0.2) - *重置__clone魔术方法 + *清空响应正文 * @example * @return */ - private function __clone() + public function clearBody() { + } /** * - *(Yaf >= 3.0.2) - *返回响应正文的字符串 + *获取响应报头 * @example * @return */ - public function __toString() + public function getHeader() { + } /** * - *(Yaf >= 3.0.2) - *设置类型为$name的响应正文内容 + *批量设置响应报头 * @example - * @param string $body (Yaf >= 3.0.2) -设置类型为$name的响应正文内容 - * @param string $name (Yaf >= 3.0.2) -设置类型为$name的响应正文内容 + * @param array $headers 响应头列表 * @return */ - public function setBody($body, $name) + public function setAllHeaders(Array $headers) { + } /** * - *(Yaf >= 3.0.2) - *设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的后面 + *设置响应报头 * @example - * @param string $body (Yaf >= 3.0.2) -设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的后面 - * @param string $name (Yaf >= 3.0.2) -设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的后面 * @return */ - public function appendBody($body, $name) + public function setHeader() { + } /** * - *(Yaf >= 3.0.2) - *设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的前面 + *清空响应报头 * @example - * @param string $body (Yaf >= 3.0.2) -设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的前面 - * @param string $name (Yaf >= 3.0.2) -设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的前面 * @return */ - public function prependBody($body, $name) + public function clearHeaders() { + } /** * - *(Yaf >= 3.0.2) - *清空响应正文 + *将当前请求重定向到指定的URL(内部实现是通过发送Location报头实现,如:header("Location:http//www.phpboy.net/")) * @example - * @param mixed $name + * @param string $url 重定向的绝对URL * @return */ - public function clearBody($name) + public function setRedirect(string $url) { + } /** * - *(Yaf >= 3.0.2) - *获取类型为$name的响应正文内容 + *输出所有的响应正文 * @example - * @param string $name (Yaf >= 3.0.2) -获取类型为$name的响应正文内容 * @return */ - public function getBody($name) + public function response() { + } } diff --git a/src/Yaf/Response_Abstract.php b/src/Yaf/Response_Abstract.php index 9ef33ba..52e8bd5 100644 --- a/src/Yaf/Response_Abstract.php +++ b/src/Yaf/Response_Abstract.php @@ -1,166 +1,215 @@ = 3.0.2) -*Class YafX_Response_Abstract +*yaf响应抽象类 */ namespace Yaf; abstract class Response_Abstract { /** - * + *默认响应内容 */ const DEFAULT_BODY = 'content'; /** - * @var unknown $_header - * (Yaf >= 3.0.2) + * @var array $_header * 响应报头 * @access protected - protected $_header; + */ + protected $_header = array(); /** - * @var unknown $_body - * (Yaf >= 3.0.2) + * @var string $_body * 响应正文 * @access protected + */ protected $_body; /** - * @var unknown $_sendheader - * (Yaf >= 3.0.2) + * @var bool $_sendheader * 是否开启已输出响应报头检测 * @access protected - protected $_sendheader = ''; + */ + protected $_sendheader = false; /** * - *(Yaf >= 3.0.2) *构造方法 * @example * @return */ public function __construct() { + } /** * - *(Yaf >= 3.0.2) *析构方法 * @example * @return */ public function __destruct() { + } /** * - *(Yaf >= 3.0.2) *重置__clone魔术方法 * @example * @return */ private function __clone() { + } /** * - *(Yaf >= 3.0.2) *返回响应正文的字符串 * @example * @return */ public function __toString() { + } /** * - *(Yaf >= 3.0.2) *设置类型为$name的响应正文内容 * @example - * @param string $body (Yaf >= 3.0.2) -设置类型为$name的响应正文内容 - * @param string $name (Yaf >= 3.0.2) -设置类型为$name的响应正文内容 + * @param string $body 响应正文内容(可覆盖原来的) + * @param string $name 响应正文类型,默认为content * @return */ - public function setBody($body, $name) + public function setBody(string $body, string $name = 'content') { + + } + + /** + * + *获取类型为$name的响应正文内容 + * @example + * @param string $name 响应正文类型,默认为content + * @return string + */ + public function getBody(string $name = 'content'): string + { + } /** * - *(Yaf >= 3.0.2) *设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的后面 * @example - * @param string $body (Yaf >= 3.0.2) -设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的后面 - * @param string $name (Yaf >= 3.0.2) -设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的后面 + * @param string $body 响应正文内容(可追加) + * @param string $name 响应正文类型,默认为content * @return */ - public function appendBody($body, $name) + public function appendBody(string $body, string $name) { + } /** * - *(Yaf >= 3.0.2) *设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的前面 * @example - * @param string $body (Yaf >= 3.0.2) -设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的前面 - * @param string $name (Yaf >= 3.0.2) -设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的前面 + * @param string $body 响应正文内容(可追加) + * @param string $name 响应正文类型,默认为content * @return */ - public function prependBody($body, $name) + public function prependBody(string $body, string $name) { + } /** * - *(Yaf >= 3.0.2) *清空响应正文 * @example - * @param mixed $name * @return */ - public function clearBody($name) + public function clearBody() { + } /** * - *(Yaf >= 3.0.2) - *获取类型为$name的响应正文内容 + *获取响应报头 + * @example + * @return array + */ + public function getHeader(): array + { + + } + + /** + * + *批量设置响应报头 * @example - * @param string $name (Yaf >= 3.0.2) -获取类型为$name的响应正文内容 + * @param array $headers 响应头列表 * @return */ - public function getBody($name) + public function setAllHeaders(Array $headers) { + } /** * *(Yaf >= 3.0.2) + *设置响应报头 + * @example + * @return + */ + public function setHeader() + { + + } + + /** + * + *清空响应报头 + * @example + * @return + */ + public function clearHeaders() + { + + } + + /** + * + *将当前请求重定向到指定的URL(内部实现是通过发送Location报头实现,如:header("Location:http//www.phpboy.net/")) + * @example + * @param string $url 重定向的绝对URL + * @return + */ + public function setRedirect(string $url) + { + + } + + /** + * *输出所有的响应正文 * @example * @return */ public function response() { + } } diff --git a/src/Yaf/Route/Map.php b/src/Yaf/Route/Map.php index c52f0c8..95424fd 100644 --- a/src/Yaf/Route/Map.php +++ b/src/Yaf/Route/Map.php @@ -1,66 +1,66 @@ = 3.0.2) -*Class YafX_Route_Map +*map路由 */ namespace Yaf\Route; -final class Map +final class Map implements \Yaf\Route_Interface { /** * @var unknown $_ctl_router - * (Yaf >= 3.0.2) * 表示路由结果是作为动作的路由结果,还是控制器的路由结果,默认的是动作路由结果. * @access protected + */ protected $_ctl_router = ''; /** * @var unknown $_delimiter * * @access protected + */ protected $_delimiter; /** * - *(Yaf >= 3.0.2) *构造方法 * @example - * @param mixed $controller_prefer - * @param mixed $delimiter + * @param bool $controller_prefer 表示路由结果是作为动作的路由结果,还是控制器的路由结果,默认的是动作路由结果 + * @param string $delimiter 表示一个分隔符,如果设置了这个分隔符,那么在REQUEST_URI中,分隔符之前的作为路由信息载体,而之后的作为请求参数. * @return */ - public function __construct($controller_prefer, $delimiter) + public function __construct(bool $controller_prefer = false, string $delimiter = '') { + } /** * - *(Yaf >= 3.0.2) *路由请求 * @example - * @param mixed $request - * @return + * @param Yaf_Request_Abstract $request 请求对象 + * @return bool */ - public function route($request) + public function route(Yaf_Request_Abstract $request): bool { + } /** * - *(Yaf >= 2.3.2) - *组合uri,路由解析的逆操作 + *组装请求 * @example - * @param mixed $info - * @param mixed $query - * @return + * @param array $info 路径信息 + * @param array $query 查询字符串 + * @return string */ - public function assemble($info, $query) + public function assemble(Array $info, Array $query): string { + } } diff --git a/src/Yaf/Route/Regex.php b/src/Yaf/Route/Regex.php index de401ec..5dd2f6b 100644 --- a/src/Yaf/Route/Regex.php +++ b/src/Yaf/Route/Regex.php @@ -1,93 +1,90 @@ = 3.0.2) -*Class YafX_Route_Regex +*yaf正则路由 */ namespace Yaf\Route; -final class Regex +final class Regex implements \Yaf\Route_Interface { /** - * @var unknown $_route - * (Yaf >= 3.0.2) + * @var array $_route * 匹配模式(正则表达式) * @access protected - protected $_route; + */ + protected $_route = array(); /** - * @var unknown $_default - * (Yaf >= 3.0.2) + * @var array $_default * 路由信息 * @access protected - protected $_default; + */ + protected $_default = array(); /** - * @var unknown $_maps - * (Yaf >= 3.0.2) + * @var array $_maps * 模式分组的映射关系 * @access protected - protected $_maps; + */ + protected $_maps = array(); /** - * @var unknown $_verify - * (Yaf >= 3.0.2) - * 哥也不清楚(实在没有查到作用,源码也没看出所以然,问鸟哥!) + * @var array $_verify + * * @access protected - protected $_verify; + */ + protected $_verify = array(); /** - * @var unknown $_reverse + * @var string $_reverse * * @access protected + */ protected $_reverse; /** * - *(Yaf >= 3.0.2) *构造方法 * @example - * @param string $match (Yaf >= 3.0.2) -构造方法 - * @param array $route (Yaf >= 3.0.2) -构造方法 - * @param array $map (Yaf >= 3.0.2) -构造方法 - * @param mixed $verify - * @param mixed $reverse + * @param string $match 匹配模式(正则表达式) + * @param array $route 路由信息 + * @param array $map 模式分组的映射关系 + * @param array $verify + * @param string $reverse * @return */ - public function __construct($match, Array $route, Array $map, $verify, $reverse) + public function __construct(string $match, Array $route, Array $map, Array $verify, string $reverse ) { + } /** * - *(Yaf >= 3.0.2) *路由请求 * @example - * @param mixed $request - * @return + * @param Yaf_Request_Abstract $request 请求对象 + * @return bool */ - public function route($request) + public function route(Yaf_Request_Abstract $request): bool { + } /** * - *(Yaf >= 2.3.2) - *组合uri,路由解析的逆操作 + *组装请求 * @example - * @param mixed $info - * @param mixed $query - * @return + * @param array $info 路径信息 + * @param array $query 查询字符串 + * @return string */ - public function assemble($info, $query) + public function assemble(Array $info, Array $query): string { + } } diff --git a/src/Yaf/Route/Rewrite.php b/src/Yaf/Route/Rewrite.php index 10993bc..704a235 100644 --- a/src/Yaf/Route/Rewrite.php +++ b/src/Yaf/Route/Rewrite.php @@ -1,77 +1,74 @@ = 3.0.2) -*Class YafX_Route_Rewrite +*重写路由 */ namespace Yaf\Route; -final class Rewrite +final class Rewrite implements \Yaf\Route_Interface { /** - * @var unknown $_route - * (Yaf >= 3.0.2) - * 匹配模式(正则表达式) + * @var array $_route + * 路由信息 * @access protected - protected $_route; + */ + protected $_route = array(); /** - * @var unknown $_default - * (Yaf >= 3.0.2) - * 路由信息 + * @var array $_default + * 默认路由信息 * @access protected - protected $_default; + */ + protected $_default = array(); /** - * @var unknown $_verify - * (Yaf >= 3.0.2) - * 哥也不清楚(实在没有查到作用,源码也没看出所以然,问鸟哥!) + * @var array $_verify + * * @access protected - protected $_verify; + */ + protected $_verify = array(); /** * - *(Yaf >= 3.0.2) *构造方法 * @example - * @param string $match (Yaf >= 3.0.2) -构造方法 - * @param array $route (Yaf >= 3.0.2) -构造方法 - * @param mixed $verify + * @param string $match 匹配模式(正则表达式) + * @param array $route 路由信息 + * @param array $verify * @return */ - public function __construct($match, Array $route, $verify) + public function __construct(string $match, Array $route, Array $verify) { + } /** * - *(Yaf >= 3.0.2) *路由请求 * @example - * @param mixed $request - * @return + * @param Yaf_Request_Abstract $request 请求对象 + * @return bool */ - public function route($request) + public function route(Yaf_Request_Abstract $request): bool { + } /** * - *(Yaf >= 2.3.2) - *组合uri,路由解析的逆操作 + *组装请求 * @example - * @param mixed $info - * @param mixed $query - * @return + * @param array $info 路径信息 + * @param array $query 查询字符串 + * @return string */ - public function assemble($info, $query) + public function assemble(Array $info, Array $query): string { + } } diff --git a/src/Yaf/Route/Simple.php b/src/Yaf/Route/Simple.php index a563987..f22a50a 100644 --- a/src/Yaf/Route/Simple.php +++ b/src/Yaf/Route/Simple.php @@ -1,75 +1,74 @@ = 3.0.2) -*Class YafX_Route_Simple +*简单路由 */ namespace Yaf\Route; -final class Simple +final class Simple implements \Yaf\Route_Interface { /** - * @var unknown $controller - * (Yaf >= 3.0.2) + * @var string $controller * 控制器名 * @access protected + */ protected $controller; /** - * @var unknown $module - * (Yaf >= 3.0.2) + * @var string $module * 模块名 * @access protected + */ protected $module; /** - * @var unknown $action - * (Yaf >= 3.0.2) + * @var string $action * 动作名 * @access protected + */ protected $action; /** * - *(Yaf >= 3.0.2) *构造方法 * @example - * @param mixed $module_name - * @param mixed $controller_name - * @param mixed $action_name + * @param string $module 模块名 + * @param string $controller 控制器名 + * @param string $action 动作名 * @return */ - public function __construct($module_name, $controller_name, $action_name) + public function __construct(string $module, string $controller, string $action) { + } /** * - *(Yaf >= 3.0.2) *路由请求 * @example - * @param mixed $request - * @return + * @param Yaf_Request_Abstract $request 请求对象 + * @return bool */ - public function route($request) + public function route(Yaf_Request_Abstract $request): bool { + } /** * - *(Yaf >= 2.3.2) - *组合uri,路由解析的逆操作 + *组装请求 * @example - * @param mixed $info - * @param mixed $query - * @return + * @param array $info 路径信息 + * @param array $query 查询字符串 + * @return string */ - public function assemble($info, $query) + public function assemble(Array $info, Array $query): string { + } } diff --git a/src/Yaf/Route/Supervar.php b/src/Yaf/Route/Supervar.php index 4d1a292..0981387 100644 --- a/src/Yaf/Route/Supervar.php +++ b/src/Yaf/Route/Supervar.php @@ -1,59 +1,58 @@ = 3.0.2) -*Class YafX_Route_Supervar +*变量路由 */ namespace Yaf\Route; -final class Supervar +final class Supervar implements \Yaf\Route_Interface { /** - * @var unknown $_var_name - * (Yaf >= 3.0.2) + * @var string $_var_name * 全局路由变量名 * @access protected + */ protected $_var_name; /** * - *(Yaf >= 3.0.2) *构造方法 * @example - * @param mixed $supervar_name + * @param string $var 全局路由变量名 * @return */ - public function __construct($supervar_name) + public function __construct(string $var) { + } /** * - *(Yaf >= 3.0.2) *路由请求 * @example - * @param mixed $request - * @return + * @param Yaf_Request_Abstract $request 请求对象 + * @return bool */ - public function route($request) + public function route(Yaf_Request_Abstract $request): bool { + } /** * - *(Yaf >= 2.3.2) - *组合uri,路由解析的逆操作 + *组装请求 * @example - * @param mixed $info - * @param mixed $query - * @return + * @param array $info 路径信息 + * @param array $query 查询字符串 + * @return string */ - public function assemble($info, $query) + public function assemble(Array $info, Array $query): string { + } } diff --git a/src/Yaf/Route_Interface.php b/src/Yaf/Route_Interface.php index 4e8d924..a793bfe 100644 --- a/src/Yaf/Route_Interface.php +++ b/src/Yaf/Route_Interface.php @@ -1,34 +1,34 @@ = 3.0.2) -*Class YafX_Route_Static +*静态路由 */ namespace Yaf; -class Route_Static +class Route_Static implements \Yaf\Route_Interface { /** * - *(Yaf >= 3.0.2) *匹配请求 * @example - * @param mixed $uri + * @param string $uri 匹配的uri * @return */ - public function match($uri) + public function match(string $uri) { + } /** * - *(Yaf >= 3.0.2) *路由请求 * @example - * @param mixed $request - * @return + * @param Yaf_Request_Abstract $request 请求对象 + * @return bool */ - public function route($request) + public function route(Yaf_Request_Abstract $request): bool { + } /** * - *(Yaf >= 2.3.2) - *组合uri,路由解析的逆操作 + *组装请求 * @example - * @param mixed $info - * @param mixed $query - * @return + * @param array $info 路径信息 + * @param array $query 查询字符串 + * @return string */ - public function assemble($info, $query) + public function assemble(Array $info, Array $query): string { + } } diff --git a/src/Yaf/Router.php b/src/Yaf/Router.php index c2922ca..b8ecad4 100644 --- a/src/Yaf/Router.php +++ b/src/Yaf/Router.php @@ -1,106 +1,110 @@ = 3.0.2) -*Class YafX_Router +*yaf路由器 */ namespace Yaf; final class Router { /** - * @var unknown $_routes - * (Yaf >= 3.0.2) + * @var array $_routes * 路由器已有的路由协议栈, 默认的栈底总是名为"default"的Route_Static路由协议的实例 * @access protected - protected $_routes; + */ + protected $_routes = array(); /** - * @var unknown $_current - * (Yaf >= 3.0.2) + * @var int $_current * 在路由成功后, 路由生效的路由协议实例的索引 * @access protected + */ protected $_current; /** * - *(Yaf >= 3.0.2) *构造方法 * @example * @return */ public function __construct() { + } /** * - *(Yaf >= 3.0.2) *往Router中添加新的路由 * @example - * @return + * @param string $name 别名 + * @param Yaf_Route_Interface $route 路由对象 + * @return bool */ - public function addRoute() + public function addRoute(string $name, Yaf_Route_Interface $route): bool { + } /** * - *(Yaf >= 3.0.2) *向Router中添加配置文件或者配置数组定义的路由 * @example - * @return + * @param Yaf_Config_Abstract $config 配置对象 + * @return bool */ - public function addConfig() + public function addConfig(Yaf_Config_Abstract $config): bool { + } /** * - *(Yaf >= 3.0.2) *路由请求 * @example - * @return + * @param Yaf_Request_Abstract $request 请求对象 + * @return bool */ - public function route() + public function route(Yaf_Request_Abstract $request): bool { + } /** * - *(Yaf >= 3.0.2) *获取路由名对应的路由协议实例 * @example - * @return + * @param string $name 路由名 + * @return string */ - public function getRoute() + public function getRoute(string $name): string { + } /** * - *(Yaf >= 3.0.2) *获取已注册的所有路由协议 * @example - * @return + * @return array */ - public function getRoutes() + public function getRoutes(): array { + } /** * - *(Yaf >= 3.0.2) *获取当前路由成功的路由协议实例 * @example - * @return + * @return string */ - public function getCurrentRoute() + public function getCurrentRoute(): string { + } } diff --git a/src/Yaf/Session.php b/src/Yaf/Session.php index 1c2f960..6b7e475 100644 --- a/src/Yaf/Session.php +++ b/src/Yaf/Session.php @@ -1,333 +1,302 @@ = 3.0.2) -*Class YafX_Session +*yaf的会话对象 */ namespace Yaf; -final class Session +final class Session implements \Iterator,\Traversable,\ArrayAccess,\Countable { /** - * @var unknown $_instance - * + * @var Yaf_Session $_instance + * session对象 * @access protected + */ protected static $_instance; /** - * @var unknown $_session - * + * @var array $_session + * session存储对象 * @access protected - protected $_session; + */ + protected $_session = array(); /** - * @var unknown $_started - * + * @var bool $_started + * 是否开启session * @access protected - protected $_started = ''; + */ + protected $_started = false; /** * - *(Yaf >= 3.0.2) *重置__construct魔术方法. * @example * @return */ private function __construct() { + } /** * - *(Yaf >= 3.0.2) *重置__clone魔术方法(因为是单例模式). * @example * @return */ private function __clone() { + } /** * - *(Yaf >= 3.0.2) *重置__sleep魔术方法. * @example * @return */ private function __sleep() { + } /** * - *(Yaf >= 3.0.2) *重置__wakeup魔术方法. * @example * @return */ private function __wakeup() { + } /** * - *(Yaf >= 3.0.2) *获取Session实例(单例模式) * @example - * @return + * @return Yaf_Session */ - public static function getInstance() + public static function getInstance(): Yaf_Session { + } /** * - *(Yaf >= 3.0.2) *开启会话 * @example * @return */ public function start() { + } /** * - *(Yaf >= 3.0.2) - *获取session变量 + *重置__destruct魔术方法. * @example - * @param string $name (Yaf >= 3.0.2) -获取session变量 * @return */ - public function get($name) + public function __destruct() { + } /** * - * + *魔术方法,当isset()检测session变量是否存在时调用 * @example - * @param mixed $name + * @param string $name 节点名称 * @return */ - public function has($name) + public function __isset(string $name) { + } /** * - *(Yaf >= 3.0.2) - *设置session变量 + *获取session变量 * @example - * @param string $name (Yaf >= 3.0.2) -设置session变量 - * @param mixed $value (Yaf >= 3.0.2) -设置session变量 + * @param string $name 变量名 * @return */ - public function set($name, $value) + public function get(string $name) { + } /** * - *(Yaf >= 3.0.2) - *撤消session变量 + *设置session变量 * @example - * @param string $name (Yaf >= 3.0.2) -撤消session变量 + * @param string $name 变量名 + * @param mixed $value 变量值 * @return */ - public function del($name) + public function set(string $name, $value) { + } /** * - *(Yaf >= 3.0.2) - *返回session变量的数量 + *撤消session变量 * @example + * @param string $name 变量名 * @return */ - public function count() + public function del(string $name) { + } /** * - *(Yaf >= 3.0.2) - *重置遍历位置 + *返回session变量的数量 * @example * @return */ - public function rewind() + public function count() { + } /** * - *(Yaf >= 3.0.2) - *向前移动到下一个元素 + *重置遍历位置 * @example * @return */ - public function next() + public function rewind() { + } /** * - *(Yaf >= 3.0.2) *返回当前变量 * @example * @return */ public function current() { + } /** * - *(Yaf >= 3.0.2) - *返回当前配置节点的key + *向前移动到下一个元素 * @example * @return */ - public function key() + public function next() { + } /** * - *(Yaf >= 3.0.2) *判断是否可以继续遍历 * @example * @return */ public function valid() { + } /** * - * - * @example - * @return - */ - public function clear() - { - } - - /** - * - *(Yaf >= 3.0.2) - *获取session变量 + *返回当前配置节点的key * @example - * @param string $name (Yaf >= 3.0.2) -获取session变量 * @return */ - public function offsetGet($name) + public function key() { + } /** * - *(Yaf >= 3.0.2) - *设置session变量 + *撤消某个session变量 * @example - * @param string $name (Yaf >= 3.0.2) -设置session变量 - * @param mixed $value (Yaf >= 3.0.2) -设置session变量 + * @param string $name 变量名 * @return */ - public function offsetSet($name, $value) + public function offsetUnset(string $name) { + } /** * - *(Yaf >= 3.0.2) *测试某个session变量是否存在 * @example - * @param mixed $name (Yaf >= 3.0.2) -测试某个session变量是否存在 + * @param mixed $name 变量名 * @return */ public function offsetExists($name) { + } /** * - *(Yaf >= 3.0.2) - *撤消某个session变量 + *获取session变量 * @example - * @param string $name (Yaf >= 3.0.2) -撤消某个session变量 + * @param string $name 变量名 * @return */ - public function offsetUnset($name) + public function offsetGet(string $name) { + } /** * - *(Yaf >= 3.0.2) - *获取session变量值 - *当不传递$name参数时,返回全部变量 + *设置session变量 * @example - * @param mixed $name + * @param string $name 变量名 + * @param mixed $value 变量值 * @return */ - public function __get($name) + public function offsetSet(string $name, $value) { + } /** * - *(Yaf >= 3.0.2) - *魔术方法,当isset()检测session变量是否存在时调用 + *获取session变量值 + *当不传递$name参数时,返回全部变量 * @example - * @param string $name (Yaf >= 3.0.2) -魔术方法,当isset()检测session变量是否存在时调用 + * @param string $name session键名 * @return */ - public function __isset($name) + public function __get(string $name) { + } /** * - *(Yaf >= 3.0.2) *设置session变量 * @example - * @param string $name (Yaf >= 3.0.2) -设置session变量 - * @param mixed $value (Yaf >= 3.0.2) -设置session变量 - * @return - */ - public function __set($name, $value) - { - } - - /** - * - * - * @example - * @param mixed $name + * @param string $name 变量名 + * @param mixed $value 变量值 * @return */ - public function __unset($name) + public function __set(string $name, $value) { + } } diff --git a/src/Yaf/View/Simple.php b/src/Yaf/View/Simple.php index ab49b88..57130d4 100644 --- a/src/Yaf/View/Simple.php +++ b/src/Yaf/View/Simple.php @@ -1,209 +1,184 @@ = 3.0.2) -*Class YafX_View_Simple +*简单视图对象 */ namespace Yaf\View; -class Simple +class Simple implements \Yaf\View_Interface { /** - * @var unknown $_tpl_vars - * (Yaf >= 3.0.2) + * @var array $_tpl_vars * 储存所有模板变量 * @access protected - protected $_tpl_vars; + */ + protected $_tpl_vars = array(); /** - * @var unknown $_tpl_dir - * (Yaf >= 3.0.2) + * @var string $_tpl_dir * 模板文件目录 * @access protected + */ protected $_tpl_dir; /** - * @var unknown $_options - * (Yaf >= 3.0.2) + * @var array $_options + * 配置选项 * @access protected - protected $_options; + */ + protected $_options = array(); /** * - *(Yaf >= 3.0.2) *构造方法 * @example - * @param mixed $template_dir - * @param array $options (Yaf >= 3.0.2) -构造方法 + * @param string $tpl_dir 模板文件目录 + * @param array $options 此属性在php-5.4以下版本中适用,用以设置模板渲染的方式 * @return */ - public final function __construct($template_dir, Array $options) + public function __construct(string $tpl_dir, Array $options) { + } /** * - *(Yaf >= 3.0.2) *当isset检测某个属性是否存在时自动调用(判断是否传递某个模板变量) * @example - * @param string $name (Yaf >= 3.0.2) -当isset检测某个属性是否存在时自动调用(判断是否传递某个模板变量) + * @param string $name 模板变量名 * @return */ - public function __isset($name) + public function __isset(string $name) { + } /** * - *(Yaf >= 3.0.2) *获取某个模板变量的值 * @example - * @param string $name (Yaf >= 3.0.2) -获取某个模板变量的值 + * @param string $name 模板变量名 * @return */ - public function get($name) + public function __get(string $name) { + } /** * - *(Yaf >= 3.0.2) - *传递变量到模板 + *获取某个模板变量的值 * @example - * @param string $name (Yaf >= 3.0.2) -传递变量到模板 - * @param string $value (Yaf >= 3.0.2) -传递变量到模板 + * @param string $name 模板变量名 * @return */ - public function assign($name, $value) + public function get(string $name) { + } /** * - *(Yaf >= 3.0.2) - *渲染模板并返回结果 + *传递变量到模板 * @example - * @param string $tpl (Yaf >= 3.0.2) -渲染模板并返回结果 - * @param mixed $tpl_vars + * @param string $name 变量名 + * @param string $value 变量值 * @return */ - public function render($tpl, $tpl_vars) + public function __set(string $name, string $value) { + } /** * - * + *清空某个模板变量的值 * @example - * @param mixed $tpl_str - * @param mixed $vars + * @param string $name 模板变量名 * @return */ - public function eval($tpl_str, $vars) + public function clear(string $name) { + } /** * - *(Yaf >= 3.0.2) - *渲染模板并直接输出 + *传递变量到模板 * @example - * @param string $tpl (Yaf >= 3.0.2) -渲染模板并直接输出 - * @param mixed $tpl_vars + * @param string $name 变量名 + * @param string $value 变量值 * @return */ - public function display($tpl, $tpl_vars) + public function assign(string $name, string $value) { + } /** * - *(Yaf >= 3.0.2) *以引用的方式传递变量到模板 * @example - * @param string $name (Yaf >= 3.0.2) -以引用的方式传递变量到模板 - * @param string $value (Yaf >= 3.0.2) -以引用的方式传递变量到模板 - * @return - */ - public function assignRef($name, $value) - { - } - - /** - * - *(Yaf >= 3.0.2) - *清空某个模板变量的值 - * @example - * @param string $name (Yaf >= 3.0.2) -清空某个模板变量的值 + * @param string $name 变量名 + * @param string $value 变量值 * @return */ - public function clear($name) + public function assignRef(string $name, string $value) { + } /** * - *(Yaf >= 3.0.2) - *设置模板文件目录 + *渲染模板并直接输出 * @example - * @param mixed $template_dir + * @param string $tpl 模板文件名 + * @param array $var_array 模板变量数组 * @return */ - public function setScriptPath($template_dir) + public function display(string $tpl, Array $var_array = []) { + } /** * - *(Yaf >= 3.0.2) - *获取模板目录文件 + *渲染模板并返回结果 * @example + * @param string $tpl 模板文件名 + * @param array $var_array 模板变量数组 * @return */ - public function getScriptPath() + public function render(string $tpl, Array $var_array = []) { + } /** * - *(Yaf >= 3.0.2) - *获取某个模板变量的值 + *设置模板文件目录 * @example - * @param string $name (Yaf >= 3.0.2) -获取某个模板变量的值 + * @param string $tpl_dir 模板文件目录 * @return */ - public function __get($name) + public function setScriptPath(string $tpl_dir) { + } /** * - *(Yaf >= 3.0.2) - *传递变量到模板 + *获取模板目录文件 * @example - * @param string $name (Yaf >= 3.0.2) -传递变量到模板 - * @param string $value (Yaf >= 3.0.2) -传递变量到模板 - * @return + * @return string */ - public function __set($name, $value) + public function getScriptPath(): string { + } } diff --git a/src/Yaf/View_Interface.php b/src/Yaf/View_Interface.php index 57fdf1b..10af3bd 100644 --- a/src/Yaf/View_Interface.php +++ b/src/Yaf/View_Interface.php @@ -1,62 +1,62 @@ = 3.0.2) -*Class yaf_Action_Abstract +*yaf中的操作定义(单独文件定义操作,通常是在控制器文件中定义操作,这里可以通过单独文件来定义操作) */ abstract class Yaf_Action_Abstract extends Yaf_Controller_Abstract { /** - * @var unknown $actions - * + * @var array $actions + * 操作列表 * @access public - public $actions; + */ + public $actions = array(); /** - * @var unknown $_module - * + * @var string $_module + * 当前模块对象 * @access protected + */ protected $_module; /** - * @var unknown $_name - * + * @var string $_name + * 当前操作名 * @access protected + */ protected $_name; /** - * @var unknown $_request - * + * @var Yaf_Request_Abstract $_request + * 当前请求对象 * @access protected + */ protected $_request; /** - * @var unknown $_response - * + * @var Yaf_Response_Abstract $_response + * 当前响应对象 * @access protected + */ protected $_response; /** - * @var unknown $_invoke_args - * + * @var array $_invoke_args + * 调用参数列表 * @access protected - protected $_invoke_args; + */ + protected $_invoke_args = array(); /** - * @var unknown $_view - * + * @var Yaf_View_Interface $_view + * 当前视图对象 * @access protected + */ protected $_view; /** - * @var unknown $_controller - * (Yaf >= 3.0.2) + * @var Yaf_Controller_Abstract $_controller * 当前请求的控制器实例 * @access protected - protected $_controller; - - /** - * - *(Yaf >= 3.0.2) - *动作入口方法,由Yaf框架自动调用 - * @example - * @return */ - public abstract function execute(); + protected $_controller; /** * - *(Yaf >= 3.0.2) *获取当前请求的控制器实例 * @example - * @return - */ - public function getController() - { - } - - /** - * - * - * @example - * @param mixed $tpl - * @param array $parameters - * @return - */ - protected function render($tpl, Array $parameters) - { - } - - /** - * - * - * @example - * @param mixed $tpl - * @param array $parameters - * @return - */ - protected function display($tpl, Array $parameters) - { - } - - /** - * - * - * @example - * @return - */ - public function getRequest() - { - } - - /** - * - * - * @example - * @return - */ - public function getResponse() - { - } - - /** - * - * - * @example - * @return - */ - public function getModuleName() - { - } - - /** - * - * - * @example - * @return - */ - public function getView() - { - } - - /** - * - * - * @example - * @param array $options - * @return - */ - public function initView(Array $options) - { - } - - /** - * - * - * @example - * @param mixed $view_directory - * @return + * @return Yaf_Action_Abstract */ - public function setViewpath($view_directory) + public function getController(): Yaf_Action_Abstract { + } /** * - * - * @example - * @return - */ - public function getViewpath() - { - } - - /** - * - * - * @example - * @param mixed $module - * @param mixed $controller - * @param mixed $action - * @param array $parameters - * @return - */ - public function forward($module, $controller, $action, Array $parameters) - { - } - - /** - * - * - * @example - * @param mixed $url - * @return - */ - public function redirect($url) - { - } - - /** - * - * - * @example - * @return - */ - public function getInvokeArgs() - { - } - - /** - * - * - * @example - * @param mixed $name - * @return - */ - public function getInvokeArg($name) - { - } - - /** - * - * - * @example - * @return - */ - public final function __construct() - { - } - - /** - * - * + *动作入口方法,由Yaf框架自动调用 * @example - * @return + * @param mixed $arg 参数 + * @param mixed $arg2 参数2 + * @return Yaf_Action_Abstract */ - private final function __clone() - { - } + public abstract function execute($arg, $arg2): Yaf_Action_Abstract; } diff --git a/src/Yaf/Yaf_Application.php b/src/Yaf/Yaf_Application.php index 7a548ef..71ad208 100644 --- a/src/Yaf/Yaf_Application.php +++ b/src/Yaf/Yaf_Application.php @@ -1,278 +1,274 @@ = 3.0.2) -*Class yaf_Application +*为应用提供引导和依赖性检查的引导类 */ final class Yaf_Application { /** - * @var unknown $config - * (Yaf >= 3.0.2) + * @var Yaf_Config_Abstract $config * 全局配置实例 * @access protected + */ protected $config; /** - * @var unknown $dispatcher - * (Yaf >= 3.0.2) + * @var Yaf_Dispatcher $dispatcher * yaf_Dispatcher实例,即分发器. * @access protected + */ protected $dispatcher; /** - * @var unknown $_app - * (Yaf >= 3.0.2) + * @var Yaf_Application $_app * 过特殊的方式实现了单例模式, 此属性保存当前实例. * @access protected + */ protected static $_app; /** - * @var unknown $_modules - * (Yaf >= 3.0.2) + * @var array $_modules * 存在的模块名, 从配置文件中ap.modules读取. * @access protected - protected $_modules; + */ + protected $_modules = array(); /** - * @var unknown $_running - * (Yaf >= 3.0.2) + * @var bool $_running * 指明当前的yaf_Application是否已经运行. * @access protected - protected $_running = ''; + */ + protected $_running = false; /** - * @var unknown $_environ - * (Yaf >= 3.0.2) - * 前的环境名, 也就是yaf_Application在读取配置的时候, 获取的配置节名字. + * @var string $_environ + * 当前的环境名, 也就是yaf_Application在读取配置的时候, 获取的配置节名字. * 注:此值只能在Yaf扩展级的配置文件.ini里面进行修改,默认为product. * @access protected - protected $_environ = 'dev'; + */ + protected $_environ = 'product'; /** - * @var unknown $_err_no - * (Yaf >= 3.0.2) + * @var int $_err_no * 最近一次发生的错误代码. * @access protected + */ protected $_err_no = 0; /** - * @var unknown $_err_msg - * (Yaf >= 3.0.2) + * @var string $_err_msg * 最近一次产生的错误信息. * @access protected + */ protected $_err_msg = ''; /** * - *(Yaf >= 3.0.2) - *构造函数,根据配置初始化yaf_Application + *获取当前的yaf_Application实例. * @example - * @param mixed $config (Yaf >= 3.0.2) -构造函数,根据配置初始化yaf_Application - * @param mixed $environ - * @return + * @return Yaf_Application|null */ - public function __construct($config, $environ) + public static function app(): ?Yaf_Application { + } /** * - *(Yaf >= 3.0.2) - *运行yaf_Application + *调用bootstrap * @example - * @return + * @param Yaf_Bootstrap_Abstract $bootstrap 引导类 + * @return Yaf_Application */ - public function run() + public function bootstrap(Yaf_Bootstrap_Abstract $bootstrap):Yaf_Application { + } /** * - *(Yaf >= 3.0.2) - *运行回调函数,一般在命令行模式下运行. + *运行yaf_Application * @example - * @param callable $entry (Yaf >= 3.0.2) -运行回调函数,一般在命令行模式下运行. - * @param mixed $... - * @return + * @return void */ - public function execute(Callable $entry, $...) + public function run() { + } /** * - *(Yaf >= 3.0.2) - *获取当前的yaf_Application实例. + *清除最近的错误信息,将设置$this->_err_no=0,$this->_err_msg=''. * @example - * @return + * @return Yaf_Application */ - public static function app() + public function clearLastError(): Yaf_Application { + } /** * - *(Yaf >= 3.0.2) - *获取当前yaf_Application的环境名,它被定义在yaf.environ,默认值为"product". + *构造函数,根据配置初始化yaf_Application * @example + * @param mixed $config 关联数组的配置, 或者一个指向ini格式的配置文件的路径的字符串. + * @param string $section 加载的配置节点,使用该节点的配置初始化应用. * @return */ - public function environ() + public function __construct($config, string $section = 'product') { + } /** * - *(Yaf >= 3.0.2) - *调用bootstrap + *运行回调函数,一般在命令行模式下运行. * @example - * @param mixed $bootstrap - * @return + * @param callable $entry 回调函数 + * @param mixed $parameter 零个或者多个回调函数参数 + * @return void */ - public function bootstrap($bootstrap) + public function execute(Callable $entry, $parameter) { + } /** * - *(Yaf >= 3.0.2) - *获取全局配置实例,即$this->config + *获取当前yaf_Application的环境名,它被定义在yaf.environ,默认值为"product". * @example - * @return + * @return string */ - public function getConfig() + public function environ(): string { + } /** * - *(Yaf >= 3.0.2) - *获取在配置文件中声明的模块,如果没有声明,它的默认值将是"Index". + *获取当前应用的主目录 * @example - * @return + * @return string */ - public function getModules() + public function getAppDirectory(): string { + } /** * - *(Yaf >= 3.0.2) - *获取当前请求的分发器yaf_Dispatcher的实例 + *获取全局配置实例,即$this->config * @example - * @return + * @return Yaf_Config_Abstract */ - public function getDispatcher() + public function getConfig(): Yaf_Config_Abstract { + } /** * - *(Yaf >= 3.0.2) - *设置应用的主目录 + *获取当前请求的分发器yaf_Dispatcher的实例 * @example - * @param String $directory (Yaf >= 3.0.2) -设置应用的主目录 - * @return + * @return Yaf_Dispatcher */ - public function setAppDirectory($directory) + public function getDispatcher(): Yaf_Dispatcher { + } /** * - *(Yaf >= 3.0.2) - *获取当前应用的主目录 + *获取最近产生的错误信息. * @example - * @return + * @return string */ - public function getAppDirectory() + public function getLastErrorMsg(): string { + } /** * - *(Yaf >= 3.0.2) *获取最近产生的错误代码. * @example - * @return + * @return int */ - public function getLastErrorNo() + public function getLastErrorNo(): int { + } /** * - *(Yaf >= 3.0.2) - *获取最近产生的错误信息. + *获取在配置文件中声明的模块,如果没有声明,它的默认值将是"Index". * @example - * @return + * @return array */ - public function getLastErrorMsg() + public function getModules(): array { + } /** * - *(Yaf >= 3.0.2) - *清除最近的错误信息,将设置$this->_err_no=0,$this->_err_msg=''. + *设置应用的主目录 * @example - * @return + * @param String $directory 目录路径. + * @return Yaf_Application */ - public function clearLastError() + public function setAppDirectory(String $directory): Yaf_Application { + } /** * - *(Yaf >= 3.0.2) - *重置__destruct魔术方法. + *重置__clone魔术方法,防止克隆yaf_Application(因为是单例模式). * @example * @return */ - public function __destruct() + private function __clone() { + } /** * - *(Yaf >= 3.0.2) - *重置__clone魔术方法,防止克隆yaf_Application(因为是单例模式). + *重置__destruct魔术方法. * @example * @return */ - private function __clone() + public function __destruct() { + } /** * - *(Yaf >= 3.0.2) *重置__sleep魔术方法. * @example * @return */ private function __sleep() { + } /** * - *(Yaf >= 3.0.2) *重置__wakeup魔术方法. * @example * @return */ private function __wakeup() { + } } diff --git a/src/Yaf/Yaf_Bootstrap_Abstract.php b/src/Yaf/Yaf_Bootstrap_Abstract.php index 060772f..4062e0f 100644 --- a/src/Yaf/Yaf_Bootstrap_Abstract.php +++ b/src/Yaf/Yaf_Bootstrap_Abstract.php @@ -1,13 +1,12 @@ = 3.0.2) -*Class yaf_Bootstrap_Abstract +*应用引导类(一般需要一个类来继承它,可定义_init开头的方法) */ abstract class Yaf_Bootstrap_Abstract { diff --git a/src/Yaf/Yaf_Config_Abstract.php b/src/Yaf/Yaf_Config_Abstract.php index e2c5548..96b831d 100644 --- a/src/Yaf/Yaf_Config_Abstract.php +++ b/src/Yaf/Yaf_Config_Abstract.php @@ -1,66 +1,161 @@ = 3.0.2) -*Class yaf_Config_Abstract +*yaf配置抽象类 */ abstract class Yaf_Config_Abstract { /** - * @var unknown $_config - * (Yaf >= 3.0.2) + * @var array $_config * 存储已解析的配置 * @access protected - protected $_config; + */ + protected $_config = array(); /** - * @var unknown $_readonly - * (Yaf >= 3.0.2) + * @var int $_readonly * 配置是否只读,默认为1. * @access protected - protected $_readonly = '1'; + */ + protected $_readonly = 1; /** * - *(Yaf >= 3.0.2) *获取配置节点的值 *当不传递$name参数时,返回配置对象本身 * @example - * @return + * @param string $name 配置键 + * @param mixed $value 默认值 + * @return mixed */ - public abstract function get(); + public abstract function get(string $name, $value); /** * - *(Yaf >= 3.0.2) - *设置配置节点的值 + *设置配置节点的值(只读) * @example - * @return + * @return Yaf_Config_Abstract */ - public abstract function set(); + public abstract function set(): Yaf_Config_Abstract; /** * - *(Yaf >= 3.0.2) - *返回配置只读的状态 + *配置是否只读 * @example - * @return + * @return bool */ - public abstract function readonly(); + public abstract function readonly(): bool; /** * - *(Yaf >= 3.0.2) *将配置转换为数组 * @example + * @return array + */ + public abstract function toArray(): array; + + /** + * + *获取配置节点的值 + *当不传递$name参数时,返回配置对象本身 + * @example + * @param string $name 配置键 + * @return mixed + */ + public function __get(string $name) + { + + } + + /** + * + *返回当前值 + * @example + * @return void + */ + public abstract function current(); + + /** + * + *返回下一个值 + * @example + * @return void + */ + public abstract function next(); + + /** + * + *返回当前键 + * @example * @return */ - public abstract function toArray(); + public abstract function key(); + + /** + * + *验证当前对象是否合法 + * @example + * @return void + */ + public abstract function valid(); + + /** + * + *将迭代器重置到第一个位置 + * @example + * @return void + */ + public abstract function rewind(); + + /** + * + *返回当前迭代器的个数 + * @example + * @return + */ + public abstract function count(); + + /** + * + *当前索引对应的对象是否存在 + * @example + * @param string $offset 索引 + * @return void + */ + public abstract function offsetExists(string $offset); + + /** + * + *通过索引获取当前对象 + * @example + * @param string $offset 索引 + * @return void + */ + public abstract function offsetGet(string $offset); + + /** + * + *通过索引设置值 + * @example + * @param string $offset 索引 + * @param mixed $value 配置值 + * @return void + */ + public abstract function offsetSet(string $offset, $value); + + /** + * + *通过索引删除值 + * @example + * @param string $offset 索引 + * @return void + */ + public abstract function offsetUnset(string $offset); } diff --git a/src/Yaf/Yaf_Config_Ini.php b/src/Yaf/Yaf_Config_Ini.php index 52244b7..7be6ab3 100644 --- a/src/Yaf/Yaf_Config_Ini.php +++ b/src/Yaf/Yaf_Config_Ini.php @@ -1,248 +1,242 @@ = 3.0.2) -*Class yaf_Config_Ini +*yaf中ini配置文件类 */ -final class Yaf_Config_Ini extends Yaf_Config_Abstract +final class Yaf_Config_Ini extends Yaf_Config_Abstract implements Iterator, ArrayAccess, Countable { /** - * @var unknown $_config - * (Yaf >= 3.0.2) + * @var array $_config * 存储已解析的配置 * @access protected - protected $_config; + */ + protected $_config = array(); /** - * @var unknown $_readonly - * (Yaf >= 3.0.2) + * @var int $_readonly * 配置是否只读,默认为1. * @access protected - protected $_readonly = '1'; + */ + protected $_readonly = 1; /** * - *(Yaf >= 3.0.2) *构造方法,初始化yaf_Config_Ini对象 * @example - * @param mixed $config_file - * @param string $section (Yaf >= 3.0.2) -构造方法,初始化yaf_Config_Ini对象 + * @param string $filename ini文件全路径 + * @param string $section 初始化时的配置节点名称 * @return */ - public function __construct($config_file, $section) + public function __construct(string $filename, string $section) { + } /** * - *(Yaf >= 3.0.2) *魔术方法,当isset()检测某个配置节点是否存在时调用 * @example - * @param string $name (Yaf >= 3.0.2) -魔术方法,当isset()检测某个配置节点是否存在时调用 - * @return - */ - public function __isset($name) - { - } - - /** - * - *(Yaf >= 3.0.2) - *获取配置节点的值 - *当不传递$name参数时,返回配置对象本身 - * @example - * @param mixed $name + * @param string $name 节点名称 * @return */ - public function get($name) + public function __isset(string $name) { + } /** * - *(Yaf >= 3.0.2) *设置配置节点值(无效) * @example - * @param string $name (Yaf >= 3.0.2) -设置配置节点值(无效) - * @param mixed $value - * @return + * @param string $name 变量名 + * @param mixed $value 配置值 + * @return Yaf_Config_Abstract */ - public function set($name, $value) + public function set(string $name, $value): Yaf_Config_Abstract { + } /** * - *(Yaf >= 3.0.2) *返回配置节点的数量 * @example - * @return + * @return int */ - public function count() + public function count(): int { + } /** * - *(Yaf >= 3.0.2) - *重置遍历位置(php.net文档有误) + *重置遍历位置 * @example * @return */ public function rewind() { + } /** * - *(Yaf >= 3.0.2) *返回当前节点 * @example - * @return + * @return mixed */ public function current() { + } /** * - *(Yaf >= 3.0.2) *向前移动到下一个元素 * @example - * @return + * @return mixed */ public function next() { + } /** * - *(Yaf >= 3.0.2) *判断是否可以继续遍历 * @example * @return */ public function valid() { + } /** * - *(Yaf >= 3.0.2) *返回当前配置节点的key * @example - * @return + * @return mixed */ public function key() { + + } + + /** + * + *撤消某个配置节点(无效) + * @example + * @param string $name 变量名 + * @return mixed + */ + public function offsetUnset(string $name) + { + } /** * - *(Yaf >= 3.0.2) + *测某个配置节点是否存在 * @example + * @param mixed $name 节点名称 * @return */ - public function toArray() + public function offsetExists($name) { + } /** * - *(Yaf >= 3.0.2) + *设置配置节点值(无效) * @example + * @param string $name 配置项名称 + * @param mixed $value 配置值 * @return */ - public function readonly() + public function offsetSet(string $name, $value) { + } /** * - *(Yaf >= 3.0.2) - *撤消某个配置节点(无效) + *获取配置节点的值 + *当不传递$name参数时,返回配置对象本身 * @example - * @param string $name (Yaf >= 3.0.2) -撤消某个配置节点(无效) + * @param string $name 索引值 * @return */ - public function offsetUnset($name) + public function offsetGet(string $name) { + } /** * - *(Yaf >= 3.0.2) *获取配置节点的值 *当不传递$name参数时,返回配置对象本身 * @example - * @param mixed $name + * @param string $name 配置项名称 * @return */ - public function offsetGet($name) + public function get(string $name) { + } /** * - *(Yaf >= 3.0.2) - *测某个配置节点是否存在 + *获取配置节点的值 + *当不传递$name参数时,返回配置对象本身 * @example - * @param mixed $name (Yaf >= 3.0.2) -测某个配置节点是否存在 + * @param string $name 配置项名称 * @return */ - public function offsetExists($name) + public function __get(string $name) { + } /** * - *(Yaf >= 3.0.2) *设置配置节点值(无效) * @example - * @param string $name (Yaf >= 3.0.2) -设置配置节点值(无效) - * @param mixed $value + * @param string $name 配置项名 + * @param mixed $value 配置值 * @return */ - public function offsetSet($name, $value) + public function __set(string $name, $value) { + } /** * - *(Yaf >= 3.0.2) - *获取配置节点的值 - *当不传递$name参数时,返回配置对象本身 + *将配置对象转化为数组 * @example - * @param mixed $name - * @return + * @return array */ - public function __get($name) + public function toArray(): array { + } /** * - *(Yaf >= 3.0.2) - *设置配置节点值(无效) + *配置是否只读 * @example - * @param string $name (Yaf >= 3.0.2) -设置配置节点值(无效) - * @param mixed $value - * @return + * @return bool */ - public function __set($name, $value) + public function readonly(): bool { + } } diff --git a/src/Yaf/Yaf_Config_Simple.php b/src/Yaf/Yaf_Config_Simple.php index e377b84..756f379 100644 --- a/src/Yaf/Yaf_Config_Simple.php +++ b/src/Yaf/Yaf_Config_Simple.php @@ -1,250 +1,242 @@ = 3.0.2) -*Class yaf_Config_Simple +*基础配置对象 */ -final class Yaf_Config_Simple extends Yaf_Config_Abstract +final class Yaf_Config_Simple extends Yaf_Config_Abstract implements Iterator, ArrayAccess, Countable { /** - * @var unknown $_config - * (Yaf >= 3.0.2) + * @var array $_config * 存储已解析的配置 * @access protected - protected $_config; + */ + protected $_config = array(); /** - * @var unknown $_readonly - * (Yaf >= 3.0.2) + * @var int $_readonly * 配置是否只读,默认为1. * @access protected - protected $_readonly = ''; + */ + protected $_readonly = 0; /** * - *(Yaf >= 3.0.2) *构造方法,初始化yaf_Config_Simple对象 * @example - * @param mixed $config_file - * @param mixed $section + * @param string $config 储存配置的数组 + * @param string $readonly 是否只读 * @return */ - public function __construct($config_file, $section) + public function __construct(string $config, string $readonly) { + } /** * - *(Yaf >= 3.0.2) *魔术方法,当isset()检测某个配置节点是否存在时调用 * @example - * @param string $name (Yaf >= 3.0.2) -魔术方法,当isset()检测某个配置节点是否存在时调用 + * @param string $name 节点名称 * @return */ - public function __isset($name) + public function __isset(string $name) { + } /** * - *(Yaf >= 3.0.2) - *获取配置节点的值 - *当不传递$name参数时,返回配置对象本身 + *设置配置节点值(无效) * @example - * @param mixed $name - * @return + * @param string $name 变量名 + * @param mixed $value 配置值 + * @return Yaf_Config_Abstract */ - public function get($name) + public function set(string $name, $value): Yaf_Config_Abstract { + } /** * - *(Yaf >= 3.0.2) - *设置配置节点值 + *返回配置节点的数量 * @example - * @param string $name (Yaf >= 3.0.2) -设置配置节点值 - * @param mixed $value (Yaf >= 3.0.2) -设置配置节点值 - * @return + * @return int */ - public function set($name, $value) + public function count(): int { + } /** * - *(Yaf >= 3.0.2) - *返回配置节点的数量 + *重置遍历位置 * @example * @return */ - public function count() + public function rewind() { + } /** * - *(Yaf >= 3.0.2) - *撤消某个配置节点 + *返回当前节点 * @example - * @param string $name (Yaf >= 3.0.2) -撤消某个配置节点 - * @return + * @return mixed */ - public function offsetUnset($name) + public function current() { + } /** * - *(Yaf >= 3.0.2) - *重置遍历位置(php.net文档有误) + *向前移动到下一个元素 * @example - * @return + * @return mixed */ - public function rewind() + public function next() { + } /** * - *(Yaf >= 3.0.2) - *返回当前节点 + *判断是否可以继续遍历 * @example * @return */ - public function current() + public function valid() { + } /** * - *(Yaf >= 3.0.2) - *向前移动到下一个元素 + *返回当前配置节点的key * @example - * @return + * @return mixed */ - public function next() + public function key() { + } /** * - *(Yaf >= 3.0.2) - *判断是否可以继续遍历 + *撤消某个配置节点(无效) * @example - * @return + * @param string $name 变量名 + * @return mixed */ - public function valid() + public function offsetUnset(string $name) { + } /** * - *(Yaf >= 3.0.2) - *返回当前配置节点的key + *测某个配置节点是否存在 * @example + * @param mixed $name 节点名称 * @return */ - public function key() + public function offsetExists($name) { + } /** * - *(Yaf >= 3.0.2) + *设置配置节点值(无效) * @example + * @param string $name 配置项名称 + * @param mixed $value 配置值 * @return */ - public function readonly() + public function offsetSet(string $name, $value) { + } /** * - *(Yaf >= 3.0.2) + *获取配置节点的值 + *当不传递$name参数时,返回配置对象本身 * @example + * @param string $name 索引值 * @return */ - public function toArray() + public function offsetGet(string $name) { + } /** * - *(Yaf >= 3.0.2) - *设置配置节点值 + *获取配置节点的值 + *当不传递$name参数时,返回配置对象本身 * @example - * @param string $name (Yaf >= 3.0.2) -设置配置节点值 - * @param mixed $value (Yaf >= 3.0.2) -设置配置节点值 + * @param string $name 配置项名称 * @return */ - public function __set($name, $value) + public function get(string $name) { + } /** * - *(Yaf >= 3.0.2) *获取配置节点的值 *当不传递$name参数时,返回配置对象本身 * @example - * @param mixed $name + * @param string $name 配置项名称 * @return */ - public function __get($name) + public function __get(string $name) { + } /** * - *(Yaf >= 3.0.2) - *获取配置节点的值 - *当不传递$name参数时,返回配置对象本身 + *设置配置节点值(无效) * @example - * @param mixed $name + * @param string $name 配置项名 + * @param mixed $value 配置值 * @return */ - public function offsetGet($name) + public function __set(string $name, $value) { + } /** * - *(Yaf >= 3.0.2) - *测某个配置节点是否存在 + *将配置对象转化为数组 * @example - * @param mixed $name (Yaf >= 3.0.2) -测某个配置节点是否存在 - * @return + * @return array */ - public function offsetExists($name) + public function toArray(): array { + } /** * - *(Yaf >= 3.0.2) - *设置配置节点值 + *配置是否只读 * @example - * @param string $name (Yaf >= 3.0.2) -设置配置节点值 - * @param mixed $value (Yaf >= 3.0.2) -设置配置节点值 - * @return + * @return bool */ - public function offsetSet($name, $value) + public function readonly(): bool { + } } diff --git a/src/Yaf/Yaf_Controller_Abstract.php b/src/Yaf/Yaf_Controller_Abstract.php index a948eb5..fa80872 100644 --- a/src/Yaf/Yaf_Controller_Abstract.php +++ b/src/Yaf/Yaf_Controller_Abstract.php @@ -1,193 +1,193 @@ = 3.0.2) -*Class yaf_Controller_Abstract +*控制器抽象类 */ abstract class Yaf_Controller_Abstract { /** - * @var unknown $actions - * (Yaf >= 3.0.2) + * @var array $actions * 动作名与动作类文件路径映射数组 * @access public - public $actions; + */ + public $actions = array(); /** - * @var unknown $_module - * (Yaf >= 3.0.2) + * @var string $_module * 当前请求的模块名 * @access protected + */ protected $_module; /** - * @var unknown $_name - * (Yaf >= 3.0.2) + * @var string $_name * 当前请求的控制器名 * @access protected + */ protected $_name; /** - * @var unknown $_request - * (Yaf >= 3.0.2) - * 当前请求对象,包括请求的所有相关信息 + * @var Yaf_Request_Abstract $_request + * 当前请求对象 * @access protected + */ protected $_request; /** - * @var unknown $_response - * (Yaf >= 3.0.2) - * 当前响应对象,保存响应的所有相关信息 + * @var Yaf_Response_Abstract $_response + * 当前响应对象 * @access protected + */ protected $_response; /** - * @var unknown $_invoke_args - * (Yaf >= 3.0.2) - * 储存调用参数 + * @var array $_invoke_args + * 调用参数列表 * @access protected - protected $_invoke_args; + */ + protected $_invoke_args = array(); /** - * @var unknown $_view - * (Yaf >= 3.0.2) - * 视图对象 + * @var Yaf_View_Interface $_view + * 当前视图对象 * @access protected + */ protected $_view; /** * - *(Yaf >= 3.0.2) *渲染动作对应的模板,并返回结果 * @example - * @param mixed $tpl - * @param array $parameters - * @return + * @param string $action_name 模板名称 + * @param array $var_array 模板变量数组 + * @return Yaf_Controller_Abstract */ - protected function render($tpl, Array $parameters) + protected function render(string $action_name, Array $var_array = []): Yaf_Controller_Abstract { + } /** * - *(Yaf >= 3.0.2) *渲染动作对应的模板,并直接输出结果 * @example - * @param mixed $tpl - * @param array $parameters - * @return + * @param string $action_name 模板名称 + * @param array $var_array 模板变量数组 + * @return Yaf_Controller_Abstract */ - protected function display($tpl, Array $parameters) + protected function display(string $action_name, Array $var_array = []): Yaf_Controller_Abstract { + } /** * - *(Yaf >= 3.0.2) *获取请求对象 * @example - * @return + * @return Yaf_Request_Abstract */ - public function getRequest() + public function getRequest(): Yaf_Request_Abstract { + } /** * - *(Yaf >= 3.0.2) *获取响应对象 * @example - * @return + * @return Yaf_Response_Abstract */ - public function getResponse() + public function getResponse(): Yaf_Response_Abstract { + } /** * - *(Yaf >= 3.0.2) *获取当前模块名 * @example - * @return + * @return string */ - public function getModuleName() + public function getModuleName(): string { + } /** * - *(Yaf >= 3.0.2) - *返回视图对象 + *初始化视图对象 * @example - * @return + * @return void */ - public function getView() + public function initView() { + } /** * - *(Yaf >= 3.0.2) - *初始化视图对象 + *返回视图对象 * @example - * @param array $options - * @return + * @return Yaf_View_Interface */ - public function initView(Array $options) + public function getView(): Yaf_View_Interface { + } /** * - * + *设置模板文件目录 * @example - * @param mixed $view_directory - * @return + * @param string $path 模板目录 + * @return void */ - public function setViewpath($view_directory) + public function setViewPath(string $path) { + } /** * - * + *获取模板文件目录 * @example - * @return + * @return string */ - public function getViewpath() + public function getViewPath(): string { + } /** * - *(Yaf >= 3.0.2) *将当前的请求转交给另外的Action(对用户来说是透明的,相当于Web服务器的代理). * @example - * @param mixed $module - * @param mixed $controller - * @param mixed $action - * @param mixed $parameters - * @return + * @param string $module 模块名 + * @param string $controller 控制器名称 + * @param string $action 操作名称 + * @param array $parameters 参数列表数组 + * @return void */ - public function forward($module, $controller, $action, $parameters) + public function forward(string $module, string $controller, string $action, Array $parameters = []) { + } /** * - *(Yaf >= 3.0.2) *将当前请求重定向到指定的URL(内部实现是通过发送Location报头实现,如:header("Location:http//www.phpboy.net/")) * @example - * @param mixed $url + * @param string $url 跳转的地址 * @return */ - public function redirect($url) + public function redirect(string $url) { + } /** @@ -199,40 +199,41 @@ public function redirect($url) */ public function getInvokeArgs() { + } /** * - *(Yaf >= 3.0.2) *获取指定调用参数名的值 * @example - * @param mixed $name + * @param string $name 参数名称 * @return */ - public function getInvokeArg($name) + public function getInvokeArg(string $name) { + } /** * - *(Yaf >= 3.0.2) - *屏蔽构造方法 + *构造方法 * @example * @return */ public final function __construct() { + } /** * - *(Yaf >= 3.0.2) - *屏蔽克隆的魔术方法 + *克隆的魔术方法 * @example * @return */ - private final function __clone() + public final function __clone() { + } } diff --git a/src/Yaf/Yaf_Dispatcher.php b/src/Yaf/Yaf_Dispatcher.php index 6452f06..cad8c23 100644 --- a/src/Yaf/Yaf_Dispatcher.php +++ b/src/Yaf/Yaf_Dispatcher.php @@ -1,54 +1,52 @@ = 3.0.2) -*Class yaf_Dispatcher +*路由及请求分发器 */ final class Yaf_Dispatcher { /** - * @var unknown $_router - * (Yaf >= 3.0.2) + * @var Yaf_Router $_router * 路由器对象. * @access protected + */ protected $_router; /** - * @var unknown $_view - * (Yaf >= 3.0.2) + * @var Yaf_View_Interface $_view * 视图对象. * @access protected + */ protected $_view; /** - * @var unknown $_request - * (Yaf >= 3.0.2) + * @var Yaf_Request_Abstract $_request * 当前请求对象(包含请求的所有信息). * @access protected + */ protected $_request; /** - * @var unknown $_plugins - * (Yaf >= 3.0.2) + * @var array $_plugins * 已注册的插件对象 * @access protected - protected $_plugins; + */ + protected $_plugins = array(); /** - * @var unknown $_instance - * (Yaf >= 3.0.2) + * @var Yaf_Dispatcher $_instance * yaf_Dispatcher实现了单例模式,此属性保存当前实例. * @access protected + */ protected static $_instance; /** - * @var unknown $_auto_render - * (Yaf >= 3.0.2) + * @var int $_auto_render * 自动渲染功能开关,默认1. * 自动渲染是指根据当前请求的控制器Controller和动作Action自动寻找模块文件,加载与渲染模块,之后返回结果或者输出. * 如果设置为0,$this->_instantly_flush,$this->_return_response的设置将无效,也即: @@ -56,11 +54,11 @@ final class Yaf_Dispatcher * yaf_Dispatcher::getInstance()->returnResponse($flag); * 设置无效,并且不会渲染模板. * @access protected - protected $_auto_render = '1'; + */ + protected $_auto_render = 1; /** - * @var unknown $_return_response - * (Yaf >= 3.0.2) + * @var int $_return_response * 返回包含请求正文的响应对象开关,默认为0. * 默认情况下,Yaf的自动渲染查找并渲染模板(render,并非display),渲染结果写入yaf_Response_Abstract实例的_body属性, * 在分发器结束分发之后,输出_body(数组遍历输出)属性的值,并清空_body. @@ -69,329 +67,335 @@ final class Yaf_Dispatcher * 进而调用yaf_Response_Abstract实例的getBody()方法获取响应正文.此属性依赖$this->_auto_render的设置, * 当$this->_auto_render=1时,响应正文包括渲染模板的结果,反之则不包括. * @access protected - protected $_return_response = ''; + */ + protected $_return_response = 0; /** - * @var unknown $_instantly_flush - * (Yaf >= 3.0.2) + * @var int $_instantly_flush * 立即输出响应正文开头,默认为0. * 默认情况下,Yaf自动渲染调用yaf_Controller_Abstract的render方法,渲染模板. * 当此属性设置为1时,Yaf调用yaf_Controller_Abstract的display方法,直接渲染并输出,但不设置yaf_Response_Abstract实例的_body属性. * @access protected - protected $_instantly_flush = ''; + */ + protected $_instantly_flush = 0; /** - * @var unknown $_default_module - * (Yaf >= 3.0.2) + * @var string $_default_module * 默认模块名 * @access protected + */ protected $_default_module; /** - * @var unknown $_default_controller - * (Yaf >= 3.0.2) + * @var string $_default_controller * 默认控制器 * @access protected + */ protected $_default_controller; /** - * @var unknown $_default_action - * (Yaf >= 3.0.2) + * @var string $_default_action * 默认动作名 * @access protected + */ protected $_default_action; /** * - *(Yaf >= 3.0.2) - *重置__construct魔术方法. + *关闭自动渲染模板 * @example - * @return + * @return bool */ - private function __construct() + public function disableView(): bool { + } /** * - *(Yaf >= 3.0.2) - *重置__clone魔术方法,防止克隆yaf_Dispatcher(因为是单例模式). + *开启自动渲染模板 * @example - * @return + * @return Yaf_Dispatcher */ - private function __clone() + public function enableView(): Yaf_Dispatcher { + } /** * - *(Yaf >= 3.0.2) - *重置__sleep魔术方法. + *初始化视图对象 * @example - * @return + * @param string $tpl_dir 模板目录 + * @param mixed $options 全局的模板选项(配置相关) + * @return Yaf_View_Interface */ - private function __sleep() + public function initView(string $tpl_dir, $options): Yaf_View_Interface { + return Yaf_View_Simple(); } /** * - *(Yaf >= 3.0.2) - *重置__wakeup魔术方法. + *设置视图对象 * @example - * @return + * @param Yaf_View_Interface $view 视图对象实例 + * @return Yaf_Dispatcher */ - private function __wakeup() + public function setView(Yaf_View_Interface $view): Yaf_Dispatcher { + } /** * - *(Yaf >= 3.0.2) - *开启自动渲染模板 + *设置请求对象(在命令行或者其他API模式下构造请求很有用) * @example - * @return + * @param Yaf_Request_Abstract $request 手动实例化的请求对象 + * @return Yaf_Dispatcher */ - public function enableView() + public function setRequest(Yaf_Request_Abstract $request): Yaf_Dispatcher { + } /** * - *(Yaf >= 3.0.2) - *关闭自动渲染模板 + *返回应用实例 * @example - * @return + * @return Yaf_Application */ - public function disableView() + public function getApplication(): Yaf_Application { + } /** * - *(Yaf >= 3.0.2) - *初始化视图对象 + *返回路由器实例 * @example - * @param mixed $templates_dir - * @param mixed $options (Yaf >= 3.0.2) -初始化视图对象 - * @return + * @return Yaf_Router */ - public function initView($templates_dir, $options) + public function getRouter(): Yaf_Router { + } /** * - *(Yaf >= 3.0.2) - *设置视图对象 + *返回请求对象实例 * @example - * @param YafX_View_Interface $view (Yaf >= 3.0.2) -设置视图对象 - * @return + * @return Yaf_Request */ - public function setView($view) + public function getRequest(): Yaf_Request { + } /** * *(Yaf >= 3.0.2) - *设置请求对象(在命令行或者其他API模式下构造请求很有用) + *设置一个用户定义的错误处理函数(封装了PHP内置的set_error_handler函数) * @example - * @param YafX_Request_Abstract $request (Yaf >= 3.0.2) -设置请求对象(在命令行或者其他API模式下构造请求很有用) - * @return + * @param callable $callback PHP中可回调的结构 + * @param int $error_type 错误类型 + * @return Yaf_Dispatcher */ - public function setRequest($request) + public function setErrorHandler(Callable $callback, int $error_type = 32767): Yaf_Dispatcher { + } /** * - *(Yaf >= 3.0.2) - *返回应用实例 + *设置默认模块 * @example - * @return + * @param string $module 模块名 + * @return Yaf_Dispatcher */ - public function getApplication() + public function setDefaultModule(string $module): Yaf_Dispatcher { + } /** * - *返回路由器实例 + *设置默认的控制器 * @example - * @return + * @param string $controller 控制器名 + * @return Yaf_Dispatcher */ - public function getRouter() + public function setDefaultController(string $controller): Yaf_Dispatcher { + } /** * - *(Yaf >= 3.0.2) - *返回请求对象实例 + *设置默认的动作名 * @example - * @return + * @param string $action 操作名 + * @return Yaf_Dispatcher */ - public function getRequest() + public function setDefaultAction(string $action): Yaf_Dispatcher { + } /** * - *(Yaf >= 3.0.2) - *设置一个用户定义的错误处理函数(封装了PHP内置的set_error_handler函数) + *设置或者返回$this->_return_response属性的值 + *当传递$flag参数时,设置$this->_return_response=$flag,并返回Dispatcher + *当不传递任何参数时,返回$this->_return_response当前值 * @example - * @param callable $callback (Yaf >= 3.0.2) -设置一个用户定义的错误处理函数(封装了PHP内置的set_error_handler函数) - * @param mixed $error_types - * @return + * @param bool $flag 是否返回响应 + * @return Yaf_Dispatcher */ - public function setErrorHandler(Callable $callback, $error_types) + public function returnResponse(bool $flag): Yaf_Dispatcher { + } /** * - *(Yaf >= 3.0.2) - *设置默认模块 + *设置或者返回$this->_auto_render属性的值 + *当传递$flag参数时,设置$this->_auto_render=$flag,并返回Dispatcher + *当不传递任何参数时,返回$this->_auto_render属性的值 * @example - * @param string $module (Yaf >= 3.0.2) -设置默认模块 - * @return + * @param bool $flag 是否自动渲染 + * @return Yaf_Dispatcher */ - public function setDefaultModule($module) + public function autoRender(bool $flag): Yaf_Dispatcher { + } /** * - *(Yaf >= 3.0.2) - *设置默认的控制器 + *设置或者返回$this->_instantly_flush属性的值 + *当传递$flag参数时,设置$this->_instantly_flush=$flag,并返回Dispatcher + *当不传递任何参数时,返回$this->_instantly_flush属性的值 * @example - * @param string $controller (Yaf >= 3.0.2) -设置默认的控制器 - * @return + * @param bool $flag 是否即时刷新缓存 + * @return Yaf_Dispatcher */ - public function setDefaultController($controller) + public function flushInstantly(bool $flag): Yaf_Dispatcher { + } /** * - *(Yaf >= 3.0.2) - *设置默认的动作名 + *返回当前yaf_Dispatcher实例(单例模式) * @example - * @param mixed $action - * @return + * @return Yaf_Dispatcher */ - public function setDefaultAction($action) + public static function getInstance(): Yaf_Dispatcher { + } /** * - *(Yaf >= 3.0.2) - *设置或者返回$this->_return_response属性的值 - *当传递$flag参数时,设置$this->_return_response=$flag,并返回Dispatcher - *当不传递任何参数时,返回$this->_return_response当前值 + *手动分发请求 * @example - * @param mixed $flag - * @return + * @param Yaf_Request_Abstract $request 分发的请求对象 + * @return Yaf_Response_Abstract */ - public function returnResponse($flag) + public function dispatch(Yaf_Request_Abstract $request): Yaf_Response_Abstract { + return new Yaf_Response_Http(); } /** * - *(Yaf >= 3.0.2) - *设置或者返回$this->_auto_render属性的值 - *当传递$flag参数时,设置$this->_auto_render=$flag,并返回Dispatcher - *当不传递任何参数时,返回$this->_auto_render属性的值 + *开启/关闭异常抛出或返回当前状态 * @example - * @param mixed $flag - * @return + * @param bool $flag 是否抛出异常 + * @return Yaf_Dispatcher */ - public function autoRender($flag) + public function throwException(bool $flag): Yaf_Dispatcher { + } /** * - *(Yaf >= 3.0.2) - *设置或者返回$this->_instantly_flush属性的值 - *当传递$flag参数时,设置$this->_instantly_flush=$flag,并返回Dispatcher - *当不传递任何参数时,返回$this->_instantly_flush属性的值 + *开启/关闭自动异常捕获功能或返回当前状态 * @example - * @param mixed $flag - * @return + * @param bool $flag 是否捕获异常 + * @return Yaf_Dispatcher */ - public function flushInstantly($flag) + public function catchException(bool $flag): Yaf_Dispatcher { + } /** * - *(Yaf >= 3.0.2) - *返回当前yaf_Dispatcher实例(单例模式) + *注册插件 + * @example + * @param Yaf_Plugin_Abstract $plugin 实例化的插件对象 + * @return Yaf_Dispatcher + */ + public function registerPlugin(Yaf_Plugin_Abstract $plugin): Yaf_Dispatcher + { + + } + + /** + * + *重置__construct魔术方法. * @example * @return */ - public static function getInstance() + private function __construct() { + } /** * - *(Yaf >= 3.0.2) - *手动分发请求 + *重置__clone魔术方法,防止克隆yaf_Dispatcher(因为是单例模式). * @example - * @param YafX_Request_Abstract $request (Yaf >= 3.0.2) -手动分发请求 * @return */ - public function dispatch($request) + private function __clone() { + } /** * - *(Yaf >= 3.0.2) - *开启/关闭异常抛出或返回当前状态 + *重置__destruct魔术方法. * @example - * @param mixed $flag * @return */ - public function throwException($flag) + public function __destruct() { + } /** * - *(Yaf >= 3.0.2) - *开启/关闭自动异常捕获功能或返回当前状态 + *重置__sleep魔术方法. * @example - * @param mixed $flag * @return */ - public function catchException($flag) + private function __sleep() { + } /** * - *(Yaf >= 3.0.2) - *注册插件 + *重置__wakeup魔术方法. * @example - * @param YafX_Plugin_Abstract $plugin (Yaf >= 3.0.2) -注册插件 * @return */ - public function registerPlugin($plugin) + private function __wakeup() { + } } diff --git a/src/Yaf/Yaf_Exception.php b/src/Yaf/Yaf_Exception.php index bac49ac..c53137e 100644 --- a/src/Yaf/Yaf_Exception.php +++ b/src/Yaf/Yaf_Exception.php @@ -1,69 +1,73 @@ = 3.0.2) -*Class yaf_Exception +*yaf异常蕨类 */ -class Yaf_Exception extends Exception +class Yaf_Exception extends Exception implements Throwable { /** - * @var unknown $file - * + * @var string $file + * 异常文件名称 * @access protected + */ protected $file; /** - * @var unknown $line - * + * @var int $line + * 异常文件行数 * @access protected + */ protected $line; /** - * @var unknown $message - * (Yaf >= 3.0.2) + * @var string $message * 异常信息 * @access protected + */ protected $message; /** - * @var unknown $code - * + * @var int $code + * 异常码 * @access protected + */ protected $code = 0; /** - * @var unknown $previous - * (Yaf >= 3.0.2) + * @var Throwable $previous * 上一个异常对象 * @access protected + */ protected $previous; /** * - * + *克隆方法 * @example * @return */ private final function __clone() { + } /** * - * + *初始化异常 * @example - * @param mixed $message - * @param mixed $code - * @param mixed $previous + * @param string $message 异常提示 + * @param int $code 异常码 + * @param Throwable $previous 上一个异常对象 * @return */ - public function __construct($message, $code, $previous) + public function __construct(string $message = '', int $code = 0, Throwable $previous) { + } /** @@ -74,86 +78,95 @@ public function __construct($message, $code, $previous) */ public function __wakeup() { + } /** * - * + *获取异常信息 * @example - * @return + * @return string */ - public final function getMessage() + public final function getMessage(): string { + } /** * - * + *获取异常码 * @example - * @return + * @return int */ - public final function getCode() + public final function getCode(): int { + } /** * - * + *获取异常文件名称 * @example - * @return + * @return string */ - public final function getFile() + public final function getFile(): string { + } /** * - * + *获取异常行数 * @example - * @return + * @return int */ - public final function getLine() + public final function getLine(): int { + } /** * - * + *获取trace调试数组 * @example - * @return + * @return array */ - public final function getTrace() + public final function getTrace(): array { + } /** * - * + *获取前一个异常对象 * @example - * @return + * @return Throwable */ public final function getPrevious() { + return new Exception(); } /** * - * + *获取调试信息的字符串 * @example - * @return + * @return string */ - public final function getTraceAsString() + public final function getTraceAsString(): string { + } /** * - * + *转化为字符串 * @example - * @return + * @return string */ - public function __toString() + public function __toString(): string { + } } diff --git a/src/Yaf/Yaf_Exception_DispatchFailed.php b/src/Yaf/Yaf_Exception_DispatchFailed.php index 316e58b..c1ff52d 100644 --- a/src/Yaf/Yaf_Exception_DispatchFailed.php +++ b/src/Yaf/Yaf_Exception_DispatchFailed.php @@ -1,69 +1,73 @@ = 3.0.2) -*Class yaf_Exception_DispatchFailed +*yaf分发异常 */ -class Yaf_Exception_DispatchFailed extends Yaf_Exception +class Yaf_Exception_DispatchFailed extends Yaf_Exception implements Throwable { /** - * @var unknown $file - * + * @var string $file + * 异常文件名称 * @access protected + */ protected $file; /** - * @var unknown $line - * + * @var int $line + * 异常文件行数 * @access protected + */ protected $line; /** - * @var unknown $message - * (Yaf >= 3.0.2) + * @var string $message * 异常信息 * @access protected + */ protected $message; /** - * @var unknown $code - * + * @var int $code + * 异常码 * @access protected + */ protected $code = 0; /** - * @var unknown $previous - * (Yaf >= 3.0.2) + * @var Throwable $previous * 上一个异常对象 * @access protected + */ protected $previous; /** * - * + *克隆方法 * @example * @return */ private final function __clone() { + } /** * - * + *初始化异常 * @example - * @param mixed $message - * @param mixed $code - * @param mixed $previous + * @param string $message 异常提示 + * @param int $code 异常码 + * @param Throwable $previous 上一个异常对象 * @return */ - public function __construct($message, $code, $previous) + public function __construct(string $message = '', int $code = 0, Throwable $previous) { + } /** @@ -74,86 +78,95 @@ public function __construct($message, $code, $previous) */ public function __wakeup() { + } /** * - * + *获取异常信息 * @example - * @return + * @return string */ - public final function getMessage() + public final function getMessage(): string { + } /** * - * + *获取异常码 * @example - * @return + * @return int */ - public final function getCode() + public final function getCode(): int { + } /** * - * + *获取异常文件名称 * @example - * @return + * @return string */ - public final function getFile() + public final function getFile(): string { + } /** * - * + *获取异常行数 * @example - * @return + * @return int */ - public final function getLine() + public final function getLine(): int { + } /** * - * + *获取trace调试数组 * @example - * @return + * @return array */ - public final function getTrace() + public final function getTrace(): array { + } /** * - * + *获取前一个异常对象 * @example - * @return + * @return Throwable */ public final function getPrevious() { + return new Exception(); } /** * - * + *获取调试信息的字符串 * @example - * @return + * @return string */ - public final function getTraceAsString() + public final function getTraceAsString(): string { + } /** * - * + *转化为字符串 * @example - * @return + * @return string */ - public function __toString() + public function __toString(): string { + } } diff --git a/src/Yaf/Yaf_Exception_LoadFailed.php b/src/Yaf/Yaf_Exception_LoadFailed.php index 4dc8264..e1118ba 100644 --- a/src/Yaf/Yaf_Exception_LoadFailed.php +++ b/src/Yaf/Yaf_Exception_LoadFailed.php @@ -1,69 +1,73 @@ = 3.0.2) -*Class yaf_Exception_LoadFailed +*yaf加载异常 */ -class Yaf_Exception_LoadFailed extends Yaf_Exception +class Yaf_Exception_LoadFailed extends Yaf_Exception implements Throwable { /** - * @var unknown $file - * + * @var string $file + * 异常文件名称 * @access protected + */ protected $file; /** - * @var unknown $line - * + * @var int $line + * 异常文件行数 * @access protected + */ protected $line; /** - * @var unknown $message - * (Yaf >= 3.0.2) + * @var string $message * 异常信息 * @access protected + */ protected $message; /** - * @var unknown $code - * + * @var int $code + * 异常码 * @access protected + */ protected $code = 0; /** - * @var unknown $previous - * (Yaf >= 3.0.2) + * @var Throwable $previous * 上一个异常对象 * @access protected + */ protected $previous; /** * - * + *克隆方法 * @example * @return */ private final function __clone() { + } /** * - * + *初始化异常 * @example - * @param mixed $message - * @param mixed $code - * @param mixed $previous + * @param string $message 异常提示 + * @param int $code 异常码 + * @param Throwable $previous 上一个异常对象 * @return */ - public function __construct($message, $code, $previous) + public function __construct(string $message = '', int $code = 0, Throwable $previous) { + } /** @@ -74,86 +78,95 @@ public function __construct($message, $code, $previous) */ public function __wakeup() { + } /** * - * + *获取异常信息 * @example - * @return + * @return string */ - public final function getMessage() + public final function getMessage(): string { + } /** * - * + *获取异常码 * @example - * @return + * @return int */ - public final function getCode() + public final function getCode(): int { + } /** * - * + *获取异常文件名称 * @example - * @return + * @return string */ - public final function getFile() + public final function getFile(): string { + } /** * - * + *获取异常行数 * @example - * @return + * @return int */ - public final function getLine() + public final function getLine(): int { + } /** * - * + *获取trace调试数组 * @example - * @return + * @return array */ - public final function getTrace() + public final function getTrace(): array { + } /** * - * + *获取前一个异常对象 * @example - * @return + * @return Throwable */ public final function getPrevious() { + return new Exception(); } /** * - * + *获取调试信息的字符串 * @example - * @return + * @return string */ - public final function getTraceAsString() + public final function getTraceAsString(): string { + } /** * - * + *转化为字符串 * @example - * @return + * @return string */ - public function __toString() + public function __toString(): string { + } } diff --git a/src/Yaf/Yaf_Exception_LoadFailed_Action.php b/src/Yaf/Yaf_Exception_LoadFailed_Action.php index d00bc93..928829c 100644 --- a/src/Yaf/Yaf_Exception_LoadFailed_Action.php +++ b/src/Yaf/Yaf_Exception_LoadFailed_Action.php @@ -1,69 +1,73 @@ = 3.0.2) -*Class yaf_Exception_LoadFailed_Action +*操作文件加载异常 */ -class Yaf_Exception_LoadFailed_Action extends Yaf_Exception_LoadFailed +class Yaf_Exception_LoadFailed_Action extends Yaf_Exception_LoadFailed implements Throwable { /** - * @var unknown $file - * + * @var string $file + * 异常文件名称 * @access protected + */ protected $file; /** - * @var unknown $line - * + * @var int $line + * 异常文件行数 * @access protected + */ protected $line; /** - * @var unknown $message - * (Yaf >= 3.0.2) + * @var string $message * 异常信息 * @access protected + */ protected $message; /** - * @var unknown $code - * + * @var int $code + * 异常码 * @access protected + */ protected $code = 0; /** - * @var unknown $previous - * (Yaf >= 3.0.2) + * @var Throwable $previous * 上一个异常对象 * @access protected + */ protected $previous; /** * - * + *克隆方法 * @example * @return */ private final function __clone() { + } /** * - * + *初始化异常 * @example - * @param mixed $message - * @param mixed $code - * @param mixed $previous + * @param string $message 异常提示 + * @param int $code 异常码 + * @param Throwable $previous 上一个异常对象 * @return */ - public function __construct($message, $code, $previous) + public function __construct(string $message = '', int $code = 0, Throwable $previous) { + } /** @@ -74,86 +78,95 @@ public function __construct($message, $code, $previous) */ public function __wakeup() { + } /** * - * + *获取异常信息 * @example - * @return + * @return string */ - public final function getMessage() + public final function getMessage(): string { + } /** * - * + *获取异常码 * @example - * @return + * @return int */ - public final function getCode() + public final function getCode(): int { + } /** * - * + *获取异常文件名称 * @example - * @return + * @return string */ - public final function getFile() + public final function getFile(): string { + } /** * - * + *获取异常行数 * @example - * @return + * @return int */ - public final function getLine() + public final function getLine(): int { + } /** * - * + *获取trace调试数组 * @example - * @return + * @return array */ - public final function getTrace() + public final function getTrace(): array { + } /** * - * + *获取前一个异常对象 * @example - * @return + * @return Throwable */ public final function getPrevious() { + return new Exception(); } /** * - * + *获取调试信息的字符串 * @example - * @return + * @return string */ - public final function getTraceAsString() + public final function getTraceAsString(): string { + } /** * - * + *转化为字符串 * @example - * @return + * @return string */ - public function __toString() + public function __toString(): string { + } } diff --git a/src/Yaf/Yaf_Exception_LoadFailed_Controller.php b/src/Yaf/Yaf_Exception_LoadFailed_Controller.php index cdaf8a2..549f26a 100644 --- a/src/Yaf/Yaf_Exception_LoadFailed_Controller.php +++ b/src/Yaf/Yaf_Exception_LoadFailed_Controller.php @@ -1,69 +1,73 @@ = 3.0.2) -*Class yaf_Exception_LoadFailed_Controller +*控制器加载异常 */ -class Yaf_Exception_LoadFailed_Controller extends Yaf_Exception_LoadFailed +class Yaf_Exception_LoadFailed_Controller extends Yaf_Exception_LoadFailed implements Throwable { /** - * @var unknown $file - * + * @var string $file + * 异常文件名称 * @access protected + */ protected $file; /** - * @var unknown $line - * + * @var int $line + * 异常文件行数 * @access protected + */ protected $line; /** - * @var unknown $message - * (Yaf >= 3.0.2) + * @var string $message * 异常信息 * @access protected + */ protected $message; /** - * @var unknown $code - * + * @var int $code + * 异常码 * @access protected + */ protected $code = 0; /** - * @var unknown $previous - * (Yaf >= 3.0.2) + * @var Throwable $previous * 上一个异常对象 * @access protected + */ protected $previous; /** * - * + *克隆方法 * @example * @return */ private final function __clone() { + } /** * - * + *初始化异常 * @example - * @param mixed $message - * @param mixed $code - * @param mixed $previous + * @param string $message 异常提示 + * @param int $code 异常码 + * @param Throwable $previous 上一个异常对象 * @return */ - public function __construct($message, $code, $previous) + public function __construct(string $message = '', int $code = 0, Throwable $previous) { + } /** @@ -74,86 +78,95 @@ public function __construct($message, $code, $previous) */ public function __wakeup() { + } /** * - * + *获取异常信息 * @example - * @return + * @return string */ - public final function getMessage() + public final function getMessage(): string { + } /** * - * + *获取异常码 * @example - * @return + * @return int */ - public final function getCode() + public final function getCode(): int { + } /** * - * + *获取异常文件名称 * @example - * @return + * @return string */ - public final function getFile() + public final function getFile(): string { + } /** * - * + *获取异常行数 * @example - * @return + * @return int */ - public final function getLine() + public final function getLine(): int { + } /** * - * + *获取trace调试数组 * @example - * @return + * @return array */ - public final function getTrace() + public final function getTrace(): array { + } /** * - * + *获取前一个异常对象 * @example - * @return + * @return Throwable */ public final function getPrevious() { + return new Exception(); } /** * - * + *获取调试信息的字符串 * @example - * @return + * @return string */ - public final function getTraceAsString() + public final function getTraceAsString(): string { + } /** * - * + *转化为字符串 * @example - * @return + * @return string */ - public function __toString() + public function __toString(): string { + } } diff --git a/src/Yaf/Yaf_Exception_LoadFailed_Module.php b/src/Yaf/Yaf_Exception_LoadFailed_Module.php index 6b29042..dcbade9 100644 --- a/src/Yaf/Yaf_Exception_LoadFailed_Module.php +++ b/src/Yaf/Yaf_Exception_LoadFailed_Module.php @@ -1,69 +1,73 @@ = 3.0.2) -*Class yaf_Exception_LoadFailed_Module +*模块加载异常 */ -class Yaf_Exception_LoadFailed_Module extends Yaf_Exception_LoadFailed +class Yaf_Exception_LoadFailed_Module extends Yaf_Exception_LoadFailed implements Throwable { /** - * @var unknown $file - * + * @var string $file + * 异常文件名称 * @access protected + */ protected $file; /** - * @var unknown $line - * + * @var int $line + * 异常文件行数 * @access protected + */ protected $line; /** - * @var unknown $message - * (Yaf >= 3.0.2) + * @var string $message * 异常信息 * @access protected + */ protected $message; /** - * @var unknown $code - * + * @var int $code + * 异常码 * @access protected + */ protected $code = 0; /** - * @var unknown $previous - * (Yaf >= 3.0.2) + * @var Throwable $previous * 上一个异常对象 * @access protected + */ protected $previous; /** * - * + *克隆方法 * @example * @return */ private final function __clone() { + } /** * - * + *初始化异常 * @example - * @param mixed $message - * @param mixed $code - * @param mixed $previous + * @param string $message 异常提示 + * @param int $code 异常码 + * @param Throwable $previous 上一个异常对象 * @return */ - public function __construct($message, $code, $previous) + public function __construct(string $message = '', int $code = 0, Throwable $previous) { + } /** @@ -74,86 +78,95 @@ public function __construct($message, $code, $previous) */ public function __wakeup() { + } /** * - * + *获取异常信息 * @example - * @return + * @return string */ - public final function getMessage() + public final function getMessage(): string { + } /** * - * + *获取异常码 * @example - * @return + * @return int */ - public final function getCode() + public final function getCode(): int { + } /** * - * + *获取异常文件名称 * @example - * @return + * @return string */ - public final function getFile() + public final function getFile(): string { + } /** * - * + *获取异常行数 * @example - * @return + * @return int */ - public final function getLine() + public final function getLine(): int { + } /** * - * + *获取trace调试数组 * @example - * @return + * @return array */ - public final function getTrace() + public final function getTrace(): array { + } /** * - * + *获取前一个异常对象 * @example - * @return + * @return Throwable */ public final function getPrevious() { + return new Exception(); } /** * - * + *获取调试信息的字符串 * @example - * @return + * @return string */ - public final function getTraceAsString() + public final function getTraceAsString(): string { + } /** * - * + *转化为字符串 * @example - * @return + * @return string */ - public function __toString() + public function __toString(): string { + } } diff --git a/src/Yaf/Yaf_Exception_LoadFailed_View.php b/src/Yaf/Yaf_Exception_LoadFailed_View.php index dedd477..6a21d76 100644 --- a/src/Yaf/Yaf_Exception_LoadFailed_View.php +++ b/src/Yaf/Yaf_Exception_LoadFailed_View.php @@ -1,69 +1,73 @@ = 3.0.2) -*Class yaf_Exception_LoadFailed_View +*视图加载异常 */ -class Yaf_Exception_LoadFailed_View extends Yaf_Exception_LoadFailed +class Yaf_Exception_LoadFailed_View extends Yaf_Exception_LoadFailed implements Throwable { /** - * @var unknown $file - * + * @var string $file + * 异常文件名称 * @access protected + */ protected $file; /** - * @var unknown $line - * + * @var int $line + * 异常文件行数 * @access protected + */ protected $line; /** - * @var unknown $message - * (Yaf >= 3.0.2) + * @var string $message * 异常信息 * @access protected + */ protected $message; /** - * @var unknown $code - * + * @var int $code + * 异常码 * @access protected + */ protected $code = 0; /** - * @var unknown $previous - * (Yaf >= 3.0.2) + * @var Throwable $previous * 上一个异常对象 * @access protected + */ protected $previous; /** * - * + *克隆方法 * @example * @return */ private final function __clone() { + } /** * - * + *初始化异常 * @example - * @param mixed $message - * @param mixed $code - * @param mixed $previous + * @param string $message 异常提示 + * @param int $code 异常码 + * @param Throwable $previous 上一个异常对象 * @return */ - public function __construct($message, $code, $previous) + public function __construct(string $message = '', int $code = 0, Throwable $previous) { + } /** @@ -74,86 +78,95 @@ public function __construct($message, $code, $previous) */ public function __wakeup() { + } /** * - * + *获取异常信息 * @example - * @return + * @return string */ - public final function getMessage() + public final function getMessage(): string { + } /** * - * + *获取异常码 * @example - * @return + * @return int */ - public final function getCode() + public final function getCode(): int { + } /** * - * + *获取异常文件名称 * @example - * @return + * @return string */ - public final function getFile() + public final function getFile(): string { + } /** * - * + *获取异常行数 * @example - * @return + * @return int */ - public final function getLine() + public final function getLine(): int { + } /** * - * + *获取trace调试数组 * @example - * @return + * @return array */ - public final function getTrace() + public final function getTrace(): array { + } /** * - * + *获取前一个异常对象 * @example - * @return + * @return Throwable */ public final function getPrevious() { + return new Exception(); } /** * - * + *获取调试信息的字符串 * @example - * @return + * @return string */ - public final function getTraceAsString() + public final function getTraceAsString(): string { + } /** * - * + *转化为字符串 * @example - * @return + * @return string */ - public function __toString() + public function __toString(): string { + } } diff --git a/src/Yaf/Yaf_Exception_RouterFailed.php b/src/Yaf/Yaf_Exception_RouterFailed.php index a191652..b738d25 100644 --- a/src/Yaf/Yaf_Exception_RouterFailed.php +++ b/src/Yaf/Yaf_Exception_RouterFailed.php @@ -1,69 +1,73 @@ = 3.0.2) -*Class yaf_Exception_RouterFailed +*路由失败异常 */ -class Yaf_Exception_RouterFailed extends Yaf_Exception +class Yaf_Exception_RouterFailed extends Yaf_Exception implements Throwable { /** - * @var unknown $file - * + * @var string $file + * 异常文件名称 * @access protected + */ protected $file; /** - * @var unknown $line - * + * @var int $line + * 异常文件行数 * @access protected + */ protected $line; /** - * @var unknown $message - * (Yaf >= 3.0.2) + * @var string $message * 异常信息 * @access protected + */ protected $message; /** - * @var unknown $code - * + * @var int $code + * 异常码 * @access protected + */ protected $code = 0; /** - * @var unknown $previous - * (Yaf >= 3.0.2) + * @var Throwable $previous * 上一个异常对象 * @access protected + */ protected $previous; /** * - * + *克隆方法 * @example * @return */ private final function __clone() { + } /** * - * + *初始化异常 * @example - * @param mixed $message - * @param mixed $code - * @param mixed $previous + * @param string $message 异常提示 + * @param int $code 异常码 + * @param Throwable $previous 上一个异常对象 * @return */ - public function __construct($message, $code, $previous) + public function __construct(string $message = '', int $code = 0, Throwable $previous) { + } /** @@ -74,86 +78,95 @@ public function __construct($message, $code, $previous) */ public function __wakeup() { + } /** * - * + *获取异常信息 * @example - * @return + * @return string */ - public final function getMessage() + public final function getMessage(): string { + } /** * - * + *获取异常码 * @example - * @return + * @return int */ - public final function getCode() + public final function getCode(): int { + } /** * - * + *获取异常文件名称 * @example - * @return + * @return string */ - public final function getFile() + public final function getFile(): string { + } /** * - * + *获取异常行数 * @example - * @return + * @return int */ - public final function getLine() + public final function getLine(): int { + } /** * - * + *获取trace调试数组 * @example - * @return + * @return array */ - public final function getTrace() + public final function getTrace(): array { + } /** * - * + *获取前一个异常对象 * @example - * @return + * @return Throwable */ public final function getPrevious() { + return new Exception(); } /** * - * + *获取调试信息的字符串 * @example - * @return + * @return string */ - public final function getTraceAsString() + public final function getTraceAsString(): string { + } /** * - * + *转化为字符串 * @example - * @return + * @return string */ - public function __toString() + public function __toString(): string { + } } diff --git a/src/Yaf/Yaf_Exception_StartupError.php b/src/Yaf/Yaf_Exception_StartupError.php index 38018cb..e82c257 100644 --- a/src/Yaf/Yaf_Exception_StartupError.php +++ b/src/Yaf/Yaf_Exception_StartupError.php @@ -1,69 +1,73 @@ = 3.0.2) -*Class yaf_Exception_StartupError +*启动失败异常 */ -class Yaf_Exception_StartupError extends Yaf_Exception +class Yaf_Exception_StartupError extends Yaf_Exception implements Throwable { /** - * @var unknown $file - * + * @var string $file + * 异常文件名称 * @access protected + */ protected $file; /** - * @var unknown $line - * + * @var int $line + * 异常文件行数 * @access protected + */ protected $line; /** - * @var unknown $message - * (Yaf >= 3.0.2) + * @var string $message * 异常信息 * @access protected + */ protected $message; /** - * @var unknown $code - * + * @var int $code + * 异常码 * @access protected + */ protected $code = 0; /** - * @var unknown $previous - * (Yaf >= 3.0.2) + * @var Throwable $previous * 上一个异常对象 * @access protected + */ protected $previous; /** * - * + *克隆方法 * @example * @return */ private final function __clone() { + } /** * - * + *初始化异常 * @example - * @param mixed $message - * @param mixed $code - * @param mixed $previous + * @param string $message 异常提示 + * @param int $code 异常码 + * @param Throwable $previous 上一个异常对象 * @return */ - public function __construct($message, $code, $previous) + public function __construct(string $message = '', int $code = 0, Throwable $previous) { + } /** @@ -74,86 +78,95 @@ public function __construct($message, $code, $previous) */ public function __wakeup() { + } /** * - * + *获取异常信息 * @example - * @return + * @return string */ - public final function getMessage() + public final function getMessage(): string { + } /** * - * + *获取异常码 * @example - * @return + * @return int */ - public final function getCode() + public final function getCode(): int { + } /** * - * + *获取异常文件名称 * @example - * @return + * @return string */ - public final function getFile() + public final function getFile(): string { + } /** * - * + *获取异常行数 * @example - * @return + * @return int */ - public final function getLine() + public final function getLine(): int { + } /** * - * + *获取trace调试数组 * @example - * @return + * @return array */ - public final function getTrace() + public final function getTrace(): array { + } /** * - * + *获取前一个异常对象 * @example - * @return + * @return Throwable */ public final function getPrevious() { + return new Exception(); } /** * - * + *获取调试信息的字符串 * @example - * @return + * @return string */ - public final function getTraceAsString() + public final function getTraceAsString(): string { + } /** * - * + *转化为字符串 * @example - * @return + * @return string */ - public function __toString() + public function __toString(): string { + } } diff --git a/src/Yaf/Yaf_Exception_TypeError.php b/src/Yaf/Yaf_Exception_TypeError.php index 059b7eb..40c3ebe 100644 --- a/src/Yaf/Yaf_Exception_TypeError.php +++ b/src/Yaf/Yaf_Exception_TypeError.php @@ -1,69 +1,73 @@ = 3.0.2) -*Class yaf_Exception_TypeError +*类型错误异常 */ -class Yaf_Exception_TypeError extends Yaf_Exception +class Yaf_Exception_TypeError extends Yaf_Exception implements Throwable { /** - * @var unknown $file - * + * @var string $file + * 异常文件名称 * @access protected + */ protected $file; /** - * @var unknown $line - * + * @var int $line + * 异常文件行数 * @access protected + */ protected $line; /** - * @var unknown $message - * (Yaf >= 3.0.2) + * @var string $message * 异常信息 * @access protected + */ protected $message; /** - * @var unknown $code - * + * @var int $code + * 异常码 * @access protected + */ protected $code = 0; /** - * @var unknown $previous - * (Yaf >= 3.0.2) + * @var Throwable $previous * 上一个异常对象 * @access protected + */ protected $previous; /** * - * + *克隆方法 * @example * @return */ private final function __clone() { + } /** * - * + *初始化异常 * @example - * @param mixed $message - * @param mixed $code - * @param mixed $previous + * @param string $message 异常提示 + * @param int $code 异常码 + * @param Throwable $previous 上一个异常对象 * @return */ - public function __construct($message, $code, $previous) + public function __construct(string $message = '', int $code = 0, Throwable $previous) { + } /** @@ -74,86 +78,95 @@ public function __construct($message, $code, $previous) */ public function __wakeup() { + } /** * - * + *获取异常信息 * @example - * @return + * @return string */ - public final function getMessage() + public final function getMessage(): string { + } /** * - * + *获取异常码 * @example - * @return + * @return int */ - public final function getCode() + public final function getCode(): int { + } /** * - * + *获取异常文件名称 * @example - * @return + * @return string */ - public final function getFile() + public final function getFile(): string { + } /** * - * + *获取异常行数 * @example - * @return + * @return int */ - public final function getLine() + public final function getLine(): int { + } /** * - * + *获取trace调试数组 * @example - * @return + * @return array */ - public final function getTrace() + public final function getTrace(): array { + } /** * - * + *获取前一个异常对象 * @example - * @return + * @return Throwable */ public final function getPrevious() { + return new Exception(); } /** * - * + *获取调试信息的字符串 * @example - * @return + * @return string */ - public final function getTraceAsString() + public final function getTraceAsString(): string { + } /** * - * + *转化为字符串 * @example - * @return + * @return string */ - public function __toString() + public function __toString(): string { + } } diff --git a/src/Yaf/Yaf_Loader.php b/src/Yaf/Yaf_Loader.php index 39dcc49..4df8f85 100644 --- a/src/Yaf/Yaf_Loader.php +++ b/src/Yaf/Yaf_Loader.php @@ -1,187 +1,197 @@ = 3.0.2) -*Class yaf_Loader +*yaf类加载器 */ final class Yaf_Loader { /** - * @var unknown $_library - * (Yaf >= 3.0.2) + * @var string $_library * 当前应用本地类库目录 * @access protected + */ protected $_library; /** - * @var unknown $_global_library - * (Yaf >= 3.0.2) + * @var string $_global_library * 全局类库目录 * @access protected + */ protected $_global_library; /** - * @var unknown $_instance - * (Yaf >= 3.0.2) + * @var Yaf_Loader $_instance * 当前Loader实例(单例模式) * @access protected + */ protected static $_instance; /** * - *(Yaf >= 3.0.2) - *重置__construct魔术方法. + *__construct魔术方法. * @example * @return */ private function __construct() { + } /** * - *(Yaf >= 3.0.2) *重置__clone魔术方法,防止克隆yaf_Loader(因为是单例模式). * @example * @return */ private function __clone() { + + } + + /** + * + *__destruct魔术方法. + * @example + * @return + */ + public function __destruct() + { + } /** * - *(Yaf >= 3.0.2) *重置__sleep魔术方法. * @example * @return */ private function __sleep() { + } /** * - *(Yaf >= 3.0.2) *重置__wakeup魔术方法. * @example * @return */ private function __wakeup() { + } /** * - *(Yaf >= 3.0.2) *自动装载类 * @example - * @param mixed $class_name + * @param string $class 类名 * @return */ - public function autoload($class_name) + public function autoload(string $class) { + } /** * - *(Yaf >= 3.0.2) *获取yaf_Loader实例 * @example - * @param mixed $local_library_path - * @param mixed $global_library_path - * @return + * @param string $library 本地类库目录 + * @param string $global 全局类库目录 + * @return Yaf_Loader */ - public static function getInstance($local_library_path, $global_library_path) + public static function getInstance(string $library, string $global): Yaf_Loader { + } /** * - *(Yaf >= 3.0.2) *注册本地类前缀 * @example - * @param mixed $name_prefix + * @param mixed $namespace 一个或者多个类前缀 * @return */ - public function registerLocalNamespace($name_prefix) + public function registerLocalNamespace($namespace) { + } /** * - *(Yaf >= 3.0.2) *获取当前已经注册的本地类前缀 * @example - * @return + * @return string */ - public function getLocalNamespace() + public function getLocalNamespace(): string { + } /** * - *(Yaf >= 3.0.2) *清空已注册的本地类前缀 * @example * @return */ public function clearLocalNamespace() { + } /** * - *(Yaf >= 3.0.2) *判断一个类, 是否是本地类. * @example - * @param mixed $class_name - * @return + * @param string $class_name 类名 + * @return bool */ - public function isLocalName($class_name) + public function isLocalName(string $class_name): bool { + } /** * - *(Yaf >= 3.0.2) *手动导入文件 * @example - * @param mixed $file + * @param string $file include的全路径文件名 * @return */ - public static function import($file) + public static function import(string $file) { + } /** * - *(Yaf >= 3.0.2) *设置本地或者全局类库目录 * @example - * @param mixed $library_path - * @param mixed $is_global + * @param string $library 目录路径 + * @param bool $global 是否为全局类库 * @return */ - public function setLibraryPath($library_path, $is_global) + public function setLibraryPath(string $library, bool $global = false) { + } /** * - *(Yaf >= 3.0.2) *获取本地或者全局类库目录 * @example - * @param mixed $is_global - * @return + * @param bool $global 是否全局类库 + * @return string|bool */ - public function getLibraryPath($is_global) + public function getLibraryPath(bool $global = false): ?string { + } } diff --git a/src/Yaf/Yaf_Plugin_Abstract.php b/src/Yaf/Yaf_Plugin_Abstract.php index adb10be..247cc41 100644 --- a/src/Yaf/Yaf_Plugin_Abstract.php +++ b/src/Yaf/Yaf_Plugin_Abstract.php @@ -1,116 +1,91 @@ = 3.0.2) -*Class yaf_Plugin_Abstract +*插件抽象类 */ abstract class Yaf_Plugin_Abstract { /** * - *(Yaf >= 3.0.2) *在路由之前触发 * @example - * @param YafX_Request_Abstract $request (Yaf >= 3.0.2) -在路由之前触发 - * @param YafX_Response_Abstract $response (Yaf >= 3.0.2) -在路由之前触发 + * @param Yaf_Request_Abstract $request 当前请求对象 + * @param Yaf_Response_Abstract $response 当前响应对象 * @return */ - public function routerStartup($request, $response) + public function routerStartup(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) { + } /** * - *(Yaf >= 3.0.2) *路由结束之后触发 * @example - * @param YafX_Request_Abstract $request (Yaf >= 3.0.2) -路由结束之后触发 - * @param YafX_Response_Abstract $response (Yaf >= 3.0.2) -路由结束之后触发 + * @param Yaf_Request_Abstract $request 当前请求对象 + * @param Yaf_Response_Abstract $response 当前响应对象 * @return */ - public function routerShutdown($request, $response) + public function routerShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) { + } /** * - *(Yaf >= 3.0.2) *分发循环开始之前被触发 * @example - * @param YafX_Request_Abstract $request (Yaf >= 3.0.2) -分发循环开始之前被触发 - * @param YafX_Response_Abstract $response (Yaf >= 3.0.2) -分发循环开始之前被触发 + * @param YafX_Request_Abstract $request 当前请求对象 + * @param Yaf_Response_Abstract $response 当前响应对象 * @return */ - public function dispatchLoopStartup($request, $response) + public function dispatchLoopStartup(YafX_Request_Abstract $request, Yaf_Response_Abstract $response) { + } /** * - *(Yaf >= 3.0.2) - *dispatchLoopShutdown - * @example - * @param YafX_Request_Abstract $request (Yaf >= 3.0.2) -dispatchLoopShutdown - * @param YafX_Response_Abstract $response (Yaf >= 3.0.2) -dispatchLoopShutdown - * @return - */ - public function dispatchLoopShutdown($request, $response) - { - } - - /** - * - *(Yaf >= 3.0.2) *分发之前触发 * @example - * @param YafX_Request_Abstract $request (Yaf >= 3.0.2) -分发之前触发 - * @param YafX_Response_Abstract $response (Yaf >= 3.0.2) -分发之前触发 + * @param Yaf_Request_Abstract $request 当前请求对象 + * @param Yaf_Response_Abstract $response 当前响应对象 * @return */ - public function preDispatch($request, $response) + public function preDispatch(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) { + } /** * - *(Yaf >= 3.0.2) *分发结束之后触发 * @example - * @param YafX_Request_Abstract $request (Yaf >= 3.0.2) -分发结束之后触发 - * @param YafX_Response_Abstract $response (Yaf >= 3.0.2) -分发结束之后触发 + * @param Yaf_Request_Abstract $request 当前请求对象 + * @param Yaf_Response_Abstract $response 当前响应对象 * @return */ - public function postDispatch($request, $response) + public function postDispatch(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) { + } /** * - * + *分发循环结束 * @example - * @param Yaf_Request_Abstract $request - * @param Yaf_Response_Abstract $response + * @param Yaf_Request_Abstract $request 当前请求对象 + * @param Yaf_Response_Abstract $response 当前响应对象 * @return */ - public function preResponse($request, $response) + public function dispatchLoopShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) { + } } diff --git a/src/Yaf/Yaf_Registry.php b/src/Yaf/Yaf_Registry.php index 1a3aee5..0ed6f35 100644 --- a/src/Yaf/Yaf_Registry.php +++ b/src/Yaf/Yaf_Registry.php @@ -1,103 +1,98 @@ = 3.0.2) -*Class yaf_Registry +*yaf变量注册器 */ final class Yaf_Registry { /** - * @var unknown $_instance - * (Yaf >= 3.0.2) + * @var Yaf_Registry $_instance * Registry实例(单例模式) * @access protected + */ protected static $_instance; /** - * @var unknown $_entries - * (Yaf >= 3.0.2) + * @var array $_entries * 注册变量栈 * @access protected - protected $_entries; + */ + protected $_entries = array(); /** * - *(Yaf >= 3.0.2) *重置__construct魔术方法. * @example * @return */ private function __construct() { + } /** * - *(Yaf >= 3.0.2) *重置__clone魔术方法,防止克隆Dispatcher(因为是单例模式). * @example * @return */ private function __clone() { + } /** * - *(Yaf >= 3.0.2) *获取注册变量值 * @example - * @param string $name (Yaf >= 3.0.2) -获取注册变量值 - * @return + * @param string $name 变量名 + * @return mixed */ - public static function get($name) + public static function get(string $name) { + } /** * - *(Yaf >= 3.0.2) *检测变量是否存在 * @example - * @param string $name (Yaf >= 3.0.2) -检测变量是否存在 - * @return + * @param string $name 变量名 + * @return bool */ - public static function has($name) + public static function has(string $name): bool { + } /** * - *(Yaf >= 3.0.2) *注册变量 * @example - * @param string $name (Yaf >= 3.0.2) -注册变量 - * @param mixed $value (Yaf >= 3.0.2) -注册变量 - * @return + * @param string $name 变量名 + * @param mixed $value 变量值 + * @return bool */ - public static function set($name, $value) + public static function set(string $name, $value): bool { + } /** * - *(Yaf >= 3.0.2) - *删除变量 + *删除注册器中的变量 * @example - * @param mixed $name + * @param string $name 变量名 * @return */ - public static function del($name) + public static function del(string $name) { + } } diff --git a/src/Yaf/Yaf_Request_Abstract.php b/src/Yaf/Yaf_Request_Abstract.php index cd12ad9..25531ef 100644 --- a/src/Yaf/Yaf_Request_Abstract.php +++ b/src/Yaf/Yaf_Request_Abstract.php @@ -1,445 +1,433 @@ = 3.0.2) -*Class yaf_Request_Abstract +*请求抽象类 */ abstract class Yaf_Request_Abstract { /** - * + *http请求 */ const SCHEME_HTTP = 'http'; /** - * + *https请求 */ const SCHEME_HTTPS = 'https'; /** - * @var unknown $module - * (Yaf >= 3.0.2) + * @var string $module * 当前请求的模块名 * @access public + */ public $module; /** - * @var unknown $controller - * (Yaf >= 3.0.2) + * @var string $controller * 当前请求的控制器名 * @access public + */ public $controller; /** - * @var unknown $action - * (Yaf >= 3.0.2) + * @var stirng $action * 当前请求的动作名 * @access public + */ public $action; /** - * @var unknown $method - * (Yaf >= 3.0.2) + * @var string $method * 当前请求的方法 getMethod * @access public + */ public $method; /** - * @var unknown $params - * (Yaf >= 3.0.2) + * @var array $params * 请求传递的参数 * @access protected - protected $params; + */ + protected $params = array(); /** - * @var unknown $language - * (Yaf >= 3.0.2) + * @var string $language * http报头中HTTP_ACCEPT_LANGUAGE的值 * @access protected + */ protected $language; /** - * @var unknown $_exception - * (Yaf >= 3.0.2) + * @var Yaf_Exception $_exception * 异常对象 * @access protected + */ protected $_exception; /** - * @var unknown $_base_uri - * (Yaf >= 3.0.2) + * @var string $_base_uri * 请求的Base URI(http请求 or cli模式下) * @access protected + */ protected $_base_uri = ''; /** - * @var unknown $uri - * (Yaf >= 3.0.2) + * @var string $uri * 请求的URI(http请求) * @access protected + */ protected $uri = ''; /** - * @var unknown $dispatched - * (Yaf >= 3.0.2) + * @var bool $dispatched * 请求是否完成了分发,默认为0 * @access protected - protected $dispatched = ''; + */ + protected $dispatched = false; /** - * @var unknown $routed - * (Yaf >= 3.0.2) + * @var bool $routed * 请求是否完成了路由,默认为0 * @access protected - protected $routed = ''; + */ + protected $routed = false; /** * - *(Yaf >= 3.0.2) *判断是否为GET请求 * @example - * @return + * @return bool */ - public function isGet() + public function isGet(): bool { + } /** * - *(Yaf >= 3.0.2) *判断是否为POST请求 * @example - * @return + * @return bool */ - public function isPost() + public function isPost(): bool { + } /** * - *(Yaf >= 3.0.2) *判断是否为PUT请求 * @example - * @return + * @return bool */ - public function isPut() + public function isPut(): bool { + } /** * - *(Yaf >= 3.0.2) *判断是否为HEAD请求 * @example - * @return + * @return bool */ - public function isHead() + public function isHead(): bool { + } /** * - *(Yaf >= 3.0.2) *判断是否为Options请求 * @example - * @return + * @return bool */ - public function isOptions() + public function isOptions(): bool { + } /** * - *(Yaf >= 3.0.2) *判断是否为CLI请求 * @example - * @return + * @return bool */ - public function isCli() + public function isCli(): bool { + } /** * - *(Yaf >= 3.0.2) *判断是否为AJAX请求 * @example - * @return + * @return bool */ - public function isXmlHttpRequest() + public function isXmlHttpRequest(): bool { + } /** * - *(Yaf >= 3.0.2) *获取服务器$_SERVER全局变量中的值 * @example - * @param string $name (Yaf >= 3.0.2) -获取服务器$_SERVER全局变量中的值 - * @param mixed $default (Yaf >= 3.0.2) -获取服务器$_SERVER全局变量中的值 - * @return + * @param string $name 变量名 + * @param mixed $default 默认值 + * @return mixed */ - public function getServer($name, $default) + public function getServer(string $name, $default) { + } /** * - *(Yaf >= 3.0.2) *获取环境变量$_ENV全局变量中的值 * @example - * @param string $name (Yaf >= 3.0.2) -获取环境变量$_ENV全局变量中的值 - * @param string $default (Yaf >= 3.0.2) -获取环境变量$_ENV全局变量中的值 - * @return + * @param string $name 变量名 + * @param string $default 默认值 + * @return mixed */ - public function getEnv($name, $default) + public function getEnv(string $name, string $default) { + } /** * - *(Yaf >= 3.0.2) *设置请求的参数 *当只有一个参数且为Array类型,如果存在对应的键值将覆盖 * @example - * @param string $name (Yaf >= 3.0.2) -设置请求的参数 -当只有一个参数且为Array类型,如果存在对应的键值将覆盖 - * @param mixed $value (Yaf >= 3.0.2) -设置请求的参数 -当只有一个参数且为Array类型,如果存在对应的键值将覆盖 + * @param string $name 变量名 + * @param mixed $value 变量值 * @return */ - public function setParam($name, $value) + public function setParam(string $name, $value) { + } /** * - *(Yaf >= 3.0.2) *获取请求的参数 * @example - * @param string $name (Yaf >= 3.0.2) -获取请求的参数 - * @param string $default (Yaf >= 3.0.2) -获取请求的参数 + * @param string $name 变量名 + * @param string $default 默认值 * @return */ - public function getParam($name, $default) + public function getParam(string $name, string $default) { + } /** * - *(Yaf >= 3.0.2) *获取请求全部的参数 * @example - * @return + * @return array|null */ - public function getParams() + public function getParams(): ?array { + } /** * - *(Yaf >= 3.0.2) *获取异常对象 * @example - * @return + * @return Yaf_Exception */ - public function getException() + public function getException(): Yaf_Exception { + } /** * - *(Yaf >= 3.0.2) *获取当前模块名 * @example - * @return + * @return string */ - public function getModuleName() + public function getModuleName(): string { + } /** * - *(Yaf >= 3.0.2) *获取当前控制器名 * @example - * @return + * @return string */ - public function getControllerName() + public function getControllerName(): string { + } /** * - *(Yaf >= 3.0.2) *获取当前动作名 * @example - * @return + * @return string */ - public function getActionName() + public function getActionName(): string { + } /** * - *(Yaf >= 3.0.2) *设置请求的模块名 * @example - * @param mixed $module + * @param string $name 模块名 * @return */ - public function setModuleName($module) + public function setModuleName(string $name) { + } /** * - *(Yaf >= 3.0.2) *设置请求的控制器名 * @example - * @param mixed $controller + * @param string $name 控制器名称 * @return */ - public function setControllerName($controller) + public function setControllerName(string $name) { + } /** * - *(Yaf >= 3.0.2) *设置请求的动作名 * @example - * @param mixed $action + * @param string $name 操作名称 * @return */ - public function setActionName($action) + public function setActionName(string $name) { + } /** * - *(Yaf >= 3.0.2) *获取当前请求的方法 * @example - * @return + * @return string */ - public function getMethod() + public function getMethod(): string { + } /** * - *(Yaf >= 3.0.2) - *获取当前请求的请求 + *获取当前请求的请求的语言 * @example - * @return + * @return string */ - public function getLanguage() + public function getLanguage(): string { + } /** * - *(Yaf >= 3.0.2) *设置请求的Base URI * @example - * @param mixed $uri + * @param string $baseuri 基本请求地址 * @return */ - public function setBaseUri($uri) + public function setBaseUri(string $baseuri) { + } /** * - *(Yaf >= 3.0.2) *获取请求的Base URI * @example - * @return + * @return string */ - public function getBaseUri() + public function getBaseUri(): string { + } /** * - *(Yaf >= 3.0.2) *获取请求的uri * @example - * @return + * @return string */ - public function getRequestUri() + public function getRequestUri(): string { + } /** * - *(Yaf >= 3.0.2) *设置请求的URI * @example - * @param mixed $uri + * @param string $uri 请求uri * @return */ - public function setRequestUri($uri) + public function setRequestUri(string $uri) { + } /** * - *(Yaf >= 3.0.2) *判断请求是否完成了分发 * @example - * @return + * @return bool */ - public function isDispatched() + public function isDispatched(): bool { + } /** * - *(Yaf >= 3.0.2) *设置请求已经完成分发 * @example - * @return + * @return bool */ - public function setDispatched() + public function setDispatched(): bool { + } /** * - *(Yaf >= 3.0.2) *判断请求是否完成了路由 * @example - * @return + * @return bool */ - public function isRouted() + public function isRouted(): bool { + } /** * - *(Yaf >= 3.0.2) *设置请求已经完成了路由 * @example - * @param mixed $flag - * @return + * @return bool */ - public function setRouted($flag) + public function setRouted(): bool { + } } diff --git a/src/Yaf/Yaf_Request_Http.php b/src/Yaf/Yaf_Request_Http.php index 26c5b24..bff2e55 100644 --- a/src/Yaf/Yaf_Request_Http.php +++ b/src/Yaf/Yaf_Request_Http.php @@ -1,386 +1,386 @@ = 3.0.2) -*Class yaf_Request_Http +*http请求对象 */ class Yaf_Request_Http extends Yaf_Request_Abstract { /** - * @var unknown $module - * (Yaf >= 3.0.2) + * @var string $module * 当前请求的模块名 * @access public + */ public $module; /** - * @var unknown $controller - * (Yaf >= 3.0.2) + * @var string $controller * 当前请求的控制器名 * @access public + */ public $controller; /** - * @var unknown $action - * (Yaf >= 3.0.2) + * @var stirng $action * 当前请求的动作名 * @access public + */ public $action; /** - * @var unknown $method - * (Yaf >= 3.0.2) + * @var string $method * 当前请求的方法 getMethod * @access public + */ public $method; /** - * @var unknown $params - * (Yaf >= 3.0.2) + * @var array $params * 请求传递的参数 * @access protected - protected $params; + */ + protected $params = array(); /** - * @var unknown $language - * (Yaf >= 3.0.2) + * @var string $language * http报头中HTTP_ACCEPT_LANGUAGE的值 * @access protected + */ protected $language; /** - * @var unknown $_exception - * (Yaf >= 3.0.2) + * @var Yaf_Exception $_exception * 异常对象 * @access protected + */ protected $_exception; /** - * @var unknown $_base_uri - * (Yaf >= 3.0.2) + * @var string $_base_uri * 请求的Base URI(http请求 or cli模式下) * @access protected + */ protected $_base_uri = ''; /** - * @var unknown $uri - * (Yaf >= 3.0.2) + * @var string $uri * 请求的URI(http请求) * @access protected + */ protected $uri = ''; /** - * @var unknown $dispatched - * (Yaf >= 3.0.2) + * @var bool $dispatched * 请求是否完成了分发,默认为0 * @access protected - protected $dispatched = ''; + */ + protected $dispatched = false; /** - * @var unknown $routed - * (Yaf >= 3.0.2) + * @var bool $routed * 请求是否完成了路由,默认为0 * @access protected - protected $routed = ''; + */ + protected $routed = false; /** * - *(Yaf >= 3.0.2) - *获取$_GET中名为$name的参数值 + *构造方法 * @example + * @param string $request_uri 请求uri + * @param string $base_uri Base URI * @return */ - public function getQuery() + public function __construct(string $request_uri, string $base_uri) { + } /** * - *(Yaf >= 3.0.2) - *获取$_REQUEST中名为$name的参数值 + *获取$_GET中名为$name的参数值 * @example - * @return + * @param string $name 变量名 + * @param string $default 默认值 + * @return string */ - public function getRequest() + public function getQuery(string $name, string $default): string { + } /** * - *(Yaf >= 3.0.2) - *获取$_POST中名为$name的参数值 + *获取$_REQUEST中名为$name的参数值 * @example - * @return + * @param string $name 变量名 + * @return Yaf_Request_Abstract */ - public function getPost() + public function getRequest(string $name): Yaf_Request_Abstract { + } /** * - *(Yaf >= 3.0.2) - *获取$_COOKIE中名为$name的参数值 + *获取$_POST中名为$name的参数值 * @example - * @return + * @param string $name 变量名 + * @param string $default 默认值 + * @return string */ - public function getCookie() + public function getPost(string $name, string $default): string { + } /** * - *(Yaf >= 3.0.2) - *获取$_FILES中名为$name的参数值 + *获取$_COOKIE中名为$name的参数值 * @example - * @return + * @param string $name 变量名 + * @return string */ - public function getFiles() + public function getCookie(string $name): string { + } /** * - *(Yaf >= 3.0.2) - *获取全局变量中的值(扫描顺序为$_POST,$_GET,$_COOKIE,$_SERVER) + *获取$_FILES中名为$name的参数值 * @example - * @return + * @param string $name 变量名 + * @return array */ - public function get() + public function getFiles(string $name): array { + } /** * - *(Yaf >= 3.0.2) *判断是否为AJAX请求 * @example - * @return + * @return bool */ - public function isXmlHttpRequest() + public function isXmlHttpRequest(): bool { + } /** * - *(Yaf >= 3.0.2) - *构造方法 + *获取全局变量中的值(扫描顺序为$_POST,$_GET,$_COOKIE,$_SERVER) * @example - * @return + * @param string $name 变量名 + * @param mixed $default 默认值 + * @return string */ - public function __construct() + public function get(string $name, $default): string { + } /** * - *(Yaf >= 3.0.2) *重置__clone魔术方法 * @example * @return */ private function __clone() { + } /** * - *(Yaf >= 3.0.2) *判断是否为GET请求 * @example - * @return + * @return bool */ - public function isGet() + public function isGet(): bool { + } /** * - *(Yaf >= 3.0.2) *判断是否为POST请求 * @example - * @return + * @return bool */ - public function isPost() + public function isPost(): bool { + } /** * - *(Yaf >= 3.0.2) *判断是否为PUT请求 * @example - * @return + * @return bool */ - public function isPut() + public function isPut(): bool { + } /** * - *(Yaf >= 3.0.2) *判断是否为HEAD请求 * @example - * @return + * @return bool */ - public function isHead() + public function isHead(): bool { + } /** * - *(Yaf >= 3.0.2) *判断是否为Options请求 * @example - * @return + * @return bool */ - public function isOptions() + public function isOptions(): bool { + } /** * - *(Yaf >= 3.0.2) *判断是否为CLI请求 * @example - * @return + * @return bool */ - public function isCli() + public function isCli(): bool { + } /** * - *(Yaf >= 3.0.2) *获取服务器$_SERVER全局变量中的值 * @example - * @param string $name (Yaf >= 3.0.2) -获取服务器$_SERVER全局变量中的值 - * @param mixed $default (Yaf >= 3.0.2) -获取服务器$_SERVER全局变量中的值 - * @return + * @param string $name 变量名 + * @param mixed $default 默认值 + * @return mixed */ - public function getServer($name, $default) + public function getServer(string $name, $default) { + } /** * - *(Yaf >= 3.0.2) *获取环境变量$_ENV全局变量中的值 * @example - * @param string $name (Yaf >= 3.0.2) -获取环境变量$_ENV全局变量中的值 - * @param string $default (Yaf >= 3.0.2) -获取环境变量$_ENV全局变量中的值 - * @return + * @param string $name 变量名 + * @param string $default 默认值 + * @return mixed */ - public function getEnv($name, $default) + public function getEnv(string $name, string $default) { + } /** * - *(Yaf >= 3.0.2) *设置请求的参数 *当只有一个参数且为Array类型,如果存在对应的键值将覆盖 * @example - * @param string $name (Yaf >= 3.0.2) -设置请求的参数 -当只有一个参数且为Array类型,如果存在对应的键值将覆盖 - * @param mixed $value (Yaf >= 3.0.2) -设置请求的参数 -当只有一个参数且为Array类型,如果存在对应的键值将覆盖 + * @param string $name 变量名 + * @param mixed $value 变量值 * @return */ - public function setParam($name, $value) + public function setParam(string $name, $value) { + } /** * - *(Yaf >= 3.0.2) *获取请求的参数 * @example - * @param string $name (Yaf >= 3.0.2) -获取请求的参数 - * @param string $default (Yaf >= 3.0.2) -获取请求的参数 - * @return + * @param string $name 变量名 + * @param string $default 默认值 + * @return string */ - public function getParam($name, $default) + public function getParam(string $name, string $default): string { + } /** * - *(Yaf >= 3.0.2) *获取请求全部的参数 * @example - * @return + * @return array */ - public function getParams() + public function getParams(): array { + } /** * - *(Yaf >= 3.0.2) *获取异常对象 * @example - * @return + * @return Yaf_Exception */ - public function getException() + public function getException(): Yaf_Exception { + } /** * - *(Yaf >= 3.0.2) *获取当前模块名 * @example - * @return + * @return string */ - public function getModuleName() + public function getModuleName(): string { + } /** * - *(Yaf >= 3.0.2) *获取当前控制器名 * @example - * @return + * @return string */ - public function getControllerName() + public function getControllerName(): string { + } /** * - *(Yaf >= 3.0.2) *获取当前动作名 * @example - * @return + * @return string */ - public function getActionName() + public function getActionName(): string { + } /** * - *(Yaf >= 3.0.2) *设置请求的模块名 * @example - * @param mixed $module + * @param string $name 模块名 * @return */ - public function setModuleName($module) + public function setModuleName(string $name) { + } /** @@ -388,79 +388,80 @@ public function setModuleName($module) *(Yaf >= 3.0.2) *设置请求的控制器名 * @example - * @param mixed $controller + * @param string $name 控制器名称 * @return */ - public function setControllerName($controller) + public function setControllerName(string $name) { + } /** * - *(Yaf >= 3.0.2) *设置请求的动作名 * @example - * @param mixed $action + * @param string $name 操作名称 * @return */ - public function setActionName($action) + public function setActionName(string $name) { + } /** * - *(Yaf >= 3.0.2) *获取当前请求的方法 * @example - * @return + * @return string */ - public function getMethod() + public function getMethod(): string { + } /** * - *(Yaf >= 3.0.2) *获取当前请求的请求 * @example - * @return + * @return string */ - public function getLanguage() + public function getLanguage(): string { + } /** * - *(Yaf >= 3.0.2) *设置请求的Base URI * @example - * @param mixed $uri + * @param string $baseuri 基本uri * @return */ - public function setBaseUri($uri) + public function setBaseUri(string $baseuri) { + } /** * - *(Yaf >= 3.0.2) *获取请求的Base URI * @example - * @return + * @return string */ - public function getBaseUri() + public function getBaseUri(): string { + } /** * - *(Yaf >= 3.0.2) *获取请求的uri * @example - * @return + * @return string */ - public function getRequestUri() + public function getRequestUri(): string { + } /** @@ -468,56 +469,56 @@ public function getRequestUri() *(Yaf >= 3.0.2) *设置请求的URI * @example - * @param mixed $uri + * @param string $uri 请求uri * @return */ - public function setRequestUri($uri) + public function setRequestUri(string $uri) { + } /** * - *(Yaf >= 3.0.2) *判断请求是否完成了分发 * @example - * @return + * @return bool */ - public function isDispatched() + public function isDispatched(): bool { + } /** * - *(Yaf >= 3.0.2) *设置请求已经完成分发 * @example - * @return + * @return bool */ - public function setDispatched() + public function setDispatched(): bool { + } /** * - *(Yaf >= 3.0.2) *判断请求是否完成了路由 * @example - * @return + * @return bool */ - public function isRouted() + public function isRouted(): bool { + } /** * - *(Yaf >= 3.0.2) *设置请求已经完成了路由 * @example - * @param mixed $flag - * @return + * @return bool */ - public function setRouted($flag) + public function setRouted(): bool { + } } diff --git a/src/Yaf/Yaf_Request_Simple.php b/src/Yaf/Yaf_Request_Simple.php index a0b34bd..5bafe61 100644 --- a/src/Yaf/Yaf_Request_Simple.php +++ b/src/Yaf/Yaf_Request_Simple.php @@ -1,396 +1,396 @@ = 3.0.2) -*Class yaf_Request_Simple +*yaf简单请求类 */ final class Yaf_Request_Simple extends Yaf_Request_Abstract { /** - * + *http请求 */ const SCHEME_HTTP = 'http'; /** - * + *https请求 */ const SCHEME_HTTPS = 'https'; /** - * @var unknown $module - * (Yaf >= 3.0.2) + * @var string $module * 当前请求的模块名 * @access public + */ public $module; /** - * @var unknown $controller - * (Yaf >= 3.0.2) + * @var string $controller * 当前请求的控制器名 * @access public + */ public $controller; /** - * @var unknown $action - * (Yaf >= 3.0.2) + * @var stirng $action * 当前请求的动作名 * @access public + */ public $action; /** - * @var unknown $method - * (Yaf >= 3.0.2) + * @var string $method * 当前请求的方法 getMethod * @access public + */ public $method; /** - * @var unknown $params - * (Yaf >= 3.0.2) + * @var array $params * 请求传递的参数 * @access protected - protected $params; + */ + protected $params = array(); /** - * @var unknown $language - * (Yaf >= 3.0.2) + * @var string $language * http报头中HTTP_ACCEPT_LANGUAGE的值 * @access protected + */ protected $language; /** - * @var unknown $_exception - * (Yaf >= 3.0.2) + * @var Yaf_Exception $_exception * 异常对象 * @access protected + */ protected $_exception; /** - * @var unknown $_base_uri - * (Yaf >= 3.0.2) + * @var string $_base_uri * 请求的Base URI(http请求 or cli模式下) * @access protected + */ protected $_base_uri = ''; /** - * @var unknown $uri - * (Yaf >= 3.0.2) + * @var string $uri * 请求的URI(http请求) * @access protected + */ protected $uri = ''; /** - * @var unknown $dispatched - * (Yaf >= 3.0.2) + * @var bool $dispatched * 请求是否完成了分发,默认为0 * @access protected - protected $dispatched = ''; + */ + protected $dispatched = false; /** - * @var unknown $routed - * (Yaf >= 3.0.2) + * @var bool $routed * 请求是否完成了路由,默认为0 * @access protected - protected $routed = ''; + */ + protected $routed = false; /** * - *(Yaf >= 3.0.2) *构造方法 * @example + * @param string $request_uri 请求uri + * @param string $base_uri Base URI * @return */ - public function __construct() + public function __construct(string $request_uri, string $base_uri) { + } /** * - *(Yaf >= 3.0.2) - *重置__clone魔术方法 + *获取$_GET中名为$name的参数值 * @example - * @return + * @param string $name 变量名 + * @param string $default 默认值 + * @return string */ - private function __clone() + public function getQuery(string $name, string $default): string { + } /** * - *(Yaf >= 3.0.2) - *获取$_GET中名为$name的参数值 + *获取$_REQUEST中名为$name的参数值 * @example - * @return + * @param string $name 变量名 + * @return Yaf_Request_Abstract */ - public function getQuery() + public function getRequest(string $name): Yaf_Request_Abstract { + } /** * - *(Yaf >= 3.0.2) - *获取$_REQUEST中名为$name的参数值 + *获取$_POST中名为$name的参数值 * @example - * @return + * @param string $name 变量名 + * @param string $default 默认值 + * @return string */ - public function getRequest() + public function getPost(string $name, string $default): string { + } /** * - *(Yaf >= 3.0.2) - *获取$_POST中名为$name的参数值 + *获取$_COOKIE中名为$name的参数值 * @example - * @return + * @param string $name 变量名 + * @return string */ - public function getPost() + public function getCookie(string $name): string { + } /** * - *(Yaf >= 3.0.2) - *获取$_COOKIE中名为$name的参数值 + *获取$_FILES中名为$name的参数值 * @example - * @return + * @param string $name 变量名 + * @return array */ - public function getCookie() + public function getFiles(string $name): array { + } /** * - *(Yaf >= 3.0.2) - *获取$_FILES中名为$name的参数值 + *判断是否为AJAX请求 * @example - * @return + * @return bool */ - public function getFiles() + public function isXmlHttpRequest(): bool { + } /** * - *(Yaf >= 3.0.2) *获取全局变量中的值(扫描顺序为$_POST,$_GET,$_COOKIE,$_SERVER) * @example - * @return + * @param string $name 变量名 + * @param mixed $default 默认值 + * @return string */ - public function get() + public function get(string $name, $default): string { + } /** * - *(Yaf >= 3.0.2) - *判断是否为AJAX请求 + *重置__clone魔术方法 * @example * @return */ - public function isXmlHttpRequest() + private function __clone() { + } /** * - *(Yaf >= 3.0.2) *判断是否为GET请求 * @example - * @return + * @return bool */ - public function isGet() + public function isGet(): bool { + } /** * - *(Yaf >= 3.0.2) *判断是否为POST请求 * @example - * @return + * @return bool */ - public function isPost() + public function isPost(): bool { + } /** * - *(Yaf >= 3.0.2) *判断是否为PUT请求 * @example - * @return + * @return bool */ - public function isPut() + public function isPut(): bool { + } /** * - *(Yaf >= 3.0.2) *判断是否为HEAD请求 * @example - * @return + * @return bool */ - public function isHead() + public function isHead(): bool { + } /** * - *(Yaf >= 3.0.2) *判断是否为Options请求 * @example - * @return + * @return bool */ - public function isOptions() + public function isOptions(): bool { + } /** * - *(Yaf >= 3.0.2) *判断是否为CLI请求 * @example - * @return + * @return bool */ - public function isCli() + public function isCli(): bool { + } /** * - *(Yaf >= 3.0.2) *获取服务器$_SERVER全局变量中的值 * @example - * @param string $name (Yaf >= 3.0.2) -获取服务器$_SERVER全局变量中的值 - * @param mixed $default (Yaf >= 3.0.2) -获取服务器$_SERVER全局变量中的值 - * @return + * @param string $name 变量名 + * @param mixed $default 默认值 + * @return mixed */ - public function getServer($name, $default) + public function getServer(string $name, $default) { + } /** * - *(Yaf >= 3.0.2) *获取环境变量$_ENV全局变量中的值 * @example - * @param string $name (Yaf >= 3.0.2) -获取环境变量$_ENV全局变量中的值 - * @param string $default (Yaf >= 3.0.2) -获取环境变量$_ENV全局变量中的值 - * @return + * @param string $name 变量名 + * @param string $default 默认值 + * @return mixed */ - public function getEnv($name, $default) + public function getEnv(string $name, string $default) { + } /** * - *(Yaf >= 3.0.2) *设置请求的参数 *当只有一个参数且为Array类型,如果存在对应的键值将覆盖 * @example - * @param string $name (Yaf >= 3.0.2) -设置请求的参数 -当只有一个参数且为Array类型,如果存在对应的键值将覆盖 - * @param mixed $value (Yaf >= 3.0.2) -设置请求的参数 -当只有一个参数且为Array类型,如果存在对应的键值将覆盖 + * @param string $name 变量名 + * @param mixed $value 变量值 * @return */ - public function setParam($name, $value) + public function setParam(string $name, $value) { + } /** * - *(Yaf >= 3.0.2) *获取请求的参数 * @example - * @param string $name (Yaf >= 3.0.2) -获取请求的参数 - * @param string $default (Yaf >= 3.0.2) -获取请求的参数 - * @return + * @param string $name 变量名 + * @param string $default 默认值 + * @return string */ - public function getParam($name, $default) + public function getParam(string $name, string $default): string { + } /** * - *(Yaf >= 3.0.2) *获取请求全部的参数 * @example - * @return + * @return array */ - public function getParams() + public function getParams(): array { + } /** * - *(Yaf >= 3.0.2) *获取异常对象 * @example - * @return + * @return Yaf_Exception */ - public function getException() + public function getException(): Yaf_Exception { + } /** * - *(Yaf >= 3.0.2) *获取当前模块名 * @example - * @return + * @return string */ - public function getModuleName() + public function getModuleName(): string { + } /** * - *(Yaf >= 3.0.2) *获取当前控制器名 * @example - * @return + * @return string */ - public function getControllerName() + public function getControllerName(): string { + } /** * - *(Yaf >= 3.0.2) *获取当前动作名 * @example - * @return + * @return string */ - public function getActionName() + public function getActionName(): string { + } /** * - *(Yaf >= 3.0.2) *设置请求的模块名 * @example - * @param mixed $module + * @param string $name 模块名 * @return */ - public function setModuleName($module) + public function setModuleName(string $name) { + } /** @@ -398,79 +398,80 @@ public function setModuleName($module) *(Yaf >= 3.0.2) *设置请求的控制器名 * @example - * @param mixed $controller + * @param string $name 控制器名称 * @return */ - public function setControllerName($controller) + public function setControllerName(string $name) { + } /** * - *(Yaf >= 3.0.2) *设置请求的动作名 * @example - * @param mixed $action + * @param string $name 操作名称 * @return */ - public function setActionName($action) + public function setActionName(string $name) { + } /** * - *(Yaf >= 3.0.2) *获取当前请求的方法 * @example - * @return + * @return string */ - public function getMethod() + public function getMethod(): string { + } /** * - *(Yaf >= 3.0.2) *获取当前请求的请求 * @example - * @return + * @return string */ - public function getLanguage() + public function getLanguage(): string { + } /** * - *(Yaf >= 3.0.2) *设置请求的Base URI * @example - * @param mixed $uri + * @param string $baseuri 基本uri * @return */ - public function setBaseUri($uri) + public function setBaseUri(string $baseuri) { + } /** * - *(Yaf >= 3.0.2) *获取请求的Base URI * @example - * @return + * @return string */ - public function getBaseUri() + public function getBaseUri(): string { + } /** * - *(Yaf >= 3.0.2) *获取请求的uri * @example - * @return + * @return string */ - public function getRequestUri() + public function getRequestUri(): string { + } /** @@ -478,56 +479,56 @@ public function getRequestUri() *(Yaf >= 3.0.2) *设置请求的URI * @example - * @param mixed $uri + * @param string $uri 请求uri * @return */ - public function setRequestUri($uri) + public function setRequestUri(string $uri) { + } /** * - *(Yaf >= 3.0.2) *判断请求是否完成了分发 * @example - * @return + * @return bool */ - public function isDispatched() + public function isDispatched(): bool { + } /** * - *(Yaf >= 3.0.2) *设置请求已经完成分发 * @example - * @return + * @return bool */ - public function setDispatched() + public function setDispatched(): bool { + } /** * - *(Yaf >= 3.0.2) *判断请求是否完成了路由 * @example - * @return + * @return bool */ - public function isRouted() + public function isRouted(): bool { + } /** * - *(Yaf >= 3.0.2) *设置请求已经完成了路由 * @example - * @param mixed $flag - * @return + * @return bool */ - public function setRouted($flag) + public function setRouted(): bool { + } } diff --git a/src/Yaf/Yaf_Response_Abstract.php b/src/Yaf/Yaf_Response_Abstract.php index 2df25e4..b2e5b14 100644 --- a/src/Yaf/Yaf_Response_Abstract.php +++ b/src/Yaf/Yaf_Response_Abstract.php @@ -1,165 +1,214 @@ = 3.0.2) -*Class yaf_Response_Abstract +*yaf响应抽象类 */ abstract class Yaf_Response_Abstract { /** - * + *默认响应内容 */ const DEFAULT_BODY = 'content'; /** - * @var unknown $_header - * (Yaf >= 3.0.2) + * @var array $_header * 响应报头 * @access protected - protected $_header; + */ + protected $_header = array(); /** - * @var unknown $_body - * (Yaf >= 3.0.2) + * @var string $_body * 响应正文 * @access protected + */ protected $_body; /** - * @var unknown $_sendheader - * (Yaf >= 3.0.2) + * @var bool $_sendheader * 是否开启已输出响应报头检测 * @access protected - protected $_sendheader = ''; + */ + protected $_sendheader = false; /** * - *(Yaf >= 3.0.2) *构造方法 * @example * @return */ public function __construct() { + } /** * - *(Yaf >= 3.0.2) *析构方法 * @example * @return */ public function __destruct() { + } /** * - *(Yaf >= 3.0.2) *重置__clone魔术方法 * @example * @return */ private function __clone() { + } /** * - *(Yaf >= 3.0.2) *返回响应正文的字符串 * @example * @return */ public function __toString() { + } /** * - *(Yaf >= 3.0.2) *设置类型为$name的响应正文内容 * @example - * @param string $body (Yaf >= 3.0.2) -设置类型为$name的响应正文内容 - * @param string $name (Yaf >= 3.0.2) -设置类型为$name的响应正文内容 + * @param string $body 响应正文内容(可覆盖原来的) + * @param string $name 响应正文类型,默认为content * @return */ - public function setBody($body, $name) + public function setBody(string $body, string $name = 'content') { + + } + + /** + * + *获取类型为$name的响应正文内容 + * @example + * @param string $name 响应正文类型,默认为content + * @return string + */ + public function getBody(string $name = 'content'): string + { + } /** * - *(Yaf >= 3.0.2) *设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的后面 * @example - * @param string $body (Yaf >= 3.0.2) -设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的后面 - * @param string $name (Yaf >= 3.0.2) -设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的后面 + * @param string $body 响应正文内容(可追加) + * @param string $name 响应正文类型,默认为content * @return */ - public function appendBody($body, $name) + public function appendBody(string $body, string $name) { + } /** * - *(Yaf >= 3.0.2) *设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的前面 * @example - * @param string $body (Yaf >= 3.0.2) -设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的前面 - * @param string $name (Yaf >= 3.0.2) -设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的前面 + * @param string $body 响应正文内容(可追加) + * @param string $name 响应正文类型,默认为content * @return */ - public function prependBody($body, $name) + public function prependBody(string $body, string $name) { + } /** * - *(Yaf >= 3.0.2) *清空响应正文 * @example - * @param mixed $name * @return */ - public function clearBody($name) + public function clearBody() { + } /** * - *(Yaf >= 3.0.2) - *获取类型为$name的响应正文内容 + *获取响应报头 + * @example + * @return array + */ + public function getHeader(): array + { + + } + + /** + * + *批量设置响应报头 * @example - * @param string $name (Yaf >= 3.0.2) -获取类型为$name的响应正文内容 + * @param array $headers 响应头列表 * @return */ - public function getBody($name) + public function setAllHeaders(Array $headers) { + } /** * *(Yaf >= 3.0.2) + *设置响应报头 + * @example + * @return + */ + public function setHeader() + { + + } + + /** + * + *清空响应报头 + * @example + * @return + */ + public function clearHeaders() + { + + } + + /** + * + *将当前请求重定向到指定的URL(内部实现是通过发送Location报头实现,如:header("Location:http//www.phpboy.net/")) + * @example + * @param string $url 重定向的绝对URL + * @return + */ + public function setRedirect(string $url) + { + + } + + /** + * *输出所有的响应正文 * @example * @return */ public function response() { + } } diff --git a/src/Yaf/Yaf_Response_Cli.php b/src/Yaf/Yaf_Response_Cli.php index 554b1ed..5307c0a 100644 --- a/src/Yaf/Yaf_Response_Cli.php +++ b/src/Yaf/Yaf_Response_Cli.php @@ -1,165 +1,213 @@ = 3.0.2) -*Class yaf_Response_Cli +*命令行下响应对象 */ class Yaf_Response_Cli extends Yaf_Response_Abstract { /** - * + *默认内容 */ const DEFAULT_BODY = 'content'; /** - * @var unknown $_header - * (Yaf >= 3.0.2) + * @var array $_header * 响应报头 * @access protected - protected $_header; + */ + protected $_header = array(); /** - * @var unknown $_body - * (Yaf >= 3.0.2) - * 响应正文 + * @var string $_body + * 响应体 * @access protected + */ protected $_body; /** - * @var unknown $_sendheader - * (Yaf >= 3.0.2) + * @var bool $_sendheader * 是否开启已输出响应报头检测 * @access protected - protected $_sendheader = ''; + */ + protected $_sendheader = false; /** * - *(Yaf >= 3.0.2) *构造方法 * @example * @return */ public function __construct() { + } /** * - *(Yaf >= 3.0.2) *析构方法 * @example * @return */ public function __destruct() { + } /** * - *(Yaf >= 3.0.2) *重置__clone魔术方法 * @example * @return */ private function __clone() { + } /** * - *(Yaf >= 3.0.2) *返回响应正文的字符串 * @example * @return */ public function __toString() { + } /** * - *(Yaf >= 3.0.2) *设置类型为$name的响应正文内容 * @example - * @param string $body (Yaf >= 3.0.2) -设置类型为$name的响应正文内容 - * @param string $name (Yaf >= 3.0.2) -设置类型为$name的响应正文内容 + * @param string $body 响应正文内容(可覆盖原来的) + * @param string $name 响应正文类型,默认为content * @return */ - public function setBody($body, $name) + public function setBody(string $body, string $name = 'content') + { + + } + + /** + * + *获取类型为$name的响应正文内容 + * @example + * @param string $name 响应正文类型,默认为content + * @return string|null + */ + public function getBody(string $name = 'content'): ?string { + } /** * - *(Yaf >= 3.0.2) *设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的后面 * @example - * @param string $body (Yaf >= 3.0.2) -设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的后面 - * @param string $name (Yaf >= 3.0.2) -设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的后面 + * @param string $body 响应正文内容(可追加) + * @param string $name 响应正文类型,默认为content * @return */ - public function appendBody($body, $name) + public function appendBody(string $body, string $name) { + } /** * - *(Yaf >= 3.0.2) *设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的前面 * @example - * @param string $body (Yaf >= 3.0.2) -设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的前面 - * @param string $name (Yaf >= 3.0.2) -设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的前面 + * @param string $body 响应正文内容(可追加) + * @param string $name 响应正文类型,默认为content * @return */ - public function prependBody($body, $name) + public function prependBody(string $body, string $name) { + } /** * - *(Yaf >= 3.0.2) *清空响应正文 * @example - * @param mixed $name * @return */ - public function clearBody($name) + public function clearBody() { + } /** * - *(Yaf >= 3.0.2) - *获取类型为$name的响应正文内容 + *获取响应报头 + * @example + * @return array + */ + public function getHeader(): array + { + + } + + /** + * + *批量设置响应报头 + * @example + * @param array $headers 响应头列表 + * @return + */ + public function setAllHeaders(Array $headers) + { + + } + + /** + * + *设置响应报头 + * @example + * @return + */ + public function setHeader() + { + + } + + /** + * + *清空响应报头 + * @example + * @return + */ + public function clearHeaders() + { + + } + + /** + * + *将当前请求重定向到指定的URL(内部实现是通过发送Location报头实现,如:header("Location:http//www.phpboy.net/")) * @example - * @param string $name (Yaf >= 3.0.2) -获取类型为$name的响应正文内容 + * @param string $url 重定向的绝对URL * @return */ - public function getBody($name) + public function setRedirect(string $url) { + } /** * - *(Yaf >= 3.0.2) *输出所有的响应正文 * @example * @return */ public function response() { + } } diff --git a/src/Yaf/Yaf_Response_Http.php b/src/Yaf/Yaf_Response_Http.php index 146960a..47b6eba 100644 --- a/src/Yaf/Yaf_Response_Http.php +++ b/src/Yaf/Yaf_Response_Http.php @@ -1,235 +1,220 @@ = 3.0.2) -*Class yaf_Response_Http +*HTTP响应 */ class Yaf_Response_Http extends Yaf_Response_Abstract { /** - * + *默认内容 */ const DEFAULT_BODY = 'content'; /** - * @var unknown $_header - * (Yaf >= 3.0.2) + * @var array $_header * 响应报头 * @access protected - protected $_header; + */ + protected $_header = array(); /** - * @var unknown $_body - * (Yaf >= 3.0.2) + * @var string $_body * 响应正文 * @access protected + */ protected $_body; /** - * @var unknown $_sendheader - * (Yaf >= 3.0.2) + * @var bool $_sendheader * 是否开启已输出响应报头检测 * @access protected - protected $_sendheader = '1'; + */ + protected $_sendheader = true; /** - * @var unknown $_response_code - * (Yaf >= 3.0.2) + * @var int $_response_code * 响应状态码 * @access protected + */ protected $_response_code = 0; /** * - *(Yaf >= 3.0.2) - *设置响应报头 + *构造方法 * @example - * @param mixed $name - * @param mixed $value - * @param mixed $rep - * @param mixed $response_code * @return */ - public function setHeader($name, $value, $rep, $response_code) + public function __construct() { + } /** * - *(Yaf >= 3.0.2) - *获取所有响应报头 + *析构方法 * @example - * @param mixed $headers * @return */ - public function setAllHeaders($headers) + public function __destruct() { + } /** * - *(Yaf >= 3.0.2) - *获取响应报头 + *重置__clone魔术方法 * @example - * @param mixed $name * @return */ - public function getHeader($name) + private function __clone() { + } /** * - *(Yaf >= 3.0.2) - *清空响应报头 + *返回响应正文的字符串 * @example * @return */ - public function clearHeaders() + public function __toString() { + } /** * - *(Yaf >= 3.0.2) - *将当前请求重定向到指定的URL(内部实现是通过发送Location报头实现,如:header("Location:http//www.phpboy.net/")) + *设置类型为$name的响应正文内容 * @example - * @param string $url (Yaf >= 3.0.2) -将当前请求重定向到指定的URL(内部实现是通过发送Location报头实现,如:header("Location:http//www.phpboy.net/")) + * @param string $body 响应正文内容(可覆盖原来的) + * @param string $name 响应正文类型,默认为content * @return */ - public function setRedirect($url) + public function setBody(string $body, string $name = 'content') { + } /** * - *(Yaf >= 3.0.2) - *输出所有的响应正文 + *获取类型为$name的响应正文内容 * @example + * @param string $name 响应正文类型,默认为content * @return */ - public function response() + public function getBody(string $name = 'content') { + } /** * - *(Yaf >= 3.0.2) - *构造方法 + *设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的后面 * @example + * @param string $body 响应正文内容(可追加) + * @param string $name 响应正文类型,默认为content * @return */ - public function __construct() + public function appendBody(string $body, string $name) { + } /** * - *(Yaf >= 3.0.2) - *析构方法 + *设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的前面 * @example + * @param string $body 响应正文内容(可追加) + * @param string $name 响应正文类型,默认为content * @return */ - public function __destruct() + public function prependBody(string $body, string $name) { + } /** * - *(Yaf >= 3.0.2) - *重置__clone魔术方法 + *清空响应正文 * @example * @return */ - private function __clone() + public function clearBody() { + } /** * - *(Yaf >= 3.0.2) - *返回响应正文的字符串 + *获取响应报头 * @example * @return */ - public function __toString() + public function getHeader() { + } /** * - *(Yaf >= 3.0.2) - *设置类型为$name的响应正文内容 + *批量设置响应报头 * @example - * @param string $body (Yaf >= 3.0.2) -设置类型为$name的响应正文内容 - * @param string $name (Yaf >= 3.0.2) -设置类型为$name的响应正文内容 + * @param array $headers 响应头列表 * @return */ - public function setBody($body, $name) + public function setAllHeaders(Array $headers) { + } /** * - *(Yaf >= 3.0.2) - *设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的后面 + *设置响应报头 * @example - * @param string $body (Yaf >= 3.0.2) -设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的后面 - * @param string $name (Yaf >= 3.0.2) -设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的后面 * @return */ - public function appendBody($body, $name) + public function setHeader() { + } /** * - *(Yaf >= 3.0.2) - *设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的前面 + *清空响应报头 * @example - * @param string $body (Yaf >= 3.0.2) -设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的前面 - * @param string $name (Yaf >= 3.0.2) -设置类型为$name的响应正文内容, 如已存在,则追加到原来正文的前面 * @return */ - public function prependBody($body, $name) + public function clearHeaders() { + } /** * - *(Yaf >= 3.0.2) - *清空响应正文 + *将当前请求重定向到指定的URL(内部实现是通过发送Location报头实现,如:header("Location:http//www.phpboy.net/")) * @example - * @param mixed $name + * @param string $url 重定向的绝对URL * @return */ - public function clearBody($name) + public function setRedirect(string $url) { + } /** * - *(Yaf >= 3.0.2) - *获取类型为$name的响应正文内容 + *输出所有的响应正文 * @example - * @param string $name (Yaf >= 3.0.2) -获取类型为$name的响应正文内容 * @return */ - public function getBody($name) + public function response() { + } } diff --git a/src/Yaf/Yaf_Route_Interface.php b/src/Yaf/Yaf_Route_Interface.php index 98dc915..f7ca921 100644 --- a/src/Yaf/Yaf_Route_Interface.php +++ b/src/Yaf/Yaf_Route_Interface.php @@ -1,33 +1,33 @@ = 3.0.2) -*Class yaf_Route_Map +*map路由 */ -final class Yaf_Route_Map +final class Yaf_Route_Map implements Yaf_Route_Interface { /** * @var unknown $_ctl_router - * (Yaf >= 3.0.2) * 表示路由结果是作为动作的路由结果,还是控制器的路由结果,默认的是动作路由结果. * @access protected + */ protected $_ctl_router = ''; /** * @var unknown $_delimiter * * @access protected + */ protected $_delimiter; /** * - *(Yaf >= 3.0.2) *构造方法 * @example - * @param mixed $controller_prefer - * @param mixed $delimiter + * @param bool $controller_prefer 表示路由结果是作为动作的路由结果,还是控制器的路由结果,默认的是动作路由结果 + * @param string $delimiter 表示一个分隔符,如果设置了这个分隔符,那么在REQUEST_URI中,分隔符之前的作为路由信息载体,而之后的作为请求参数. * @return */ - public function __construct($controller_prefer, $delimiter) + public function __construct(bool $controller_prefer = false, string $delimiter = '') { + } /** * - *(Yaf >= 3.0.2) *路由请求 * @example - * @param mixed $request - * @return + * @param Yaf_Request_Abstract $request 请求对象 + * @return bool */ - public function route($request) + public function route(Yaf_Request_Abstract $request): bool { + } /** * - *(Yaf >= 2.3.2) - *组合uri,路由解析的逆操作 + *组装请求 * @example - * @param mixed $info - * @param mixed $query - * @return + * @param array $info 路径信息 + * @param array $query 查询字符串 + * @return string */ - public function assemble($info, $query) + public function assemble(Array $info, Array $query): string { + } } diff --git a/src/Yaf/Yaf_Route_Regex.php b/src/Yaf/Yaf_Route_Regex.php index 8be1866..42260ce 100644 --- a/src/Yaf/Yaf_Route_Regex.php +++ b/src/Yaf/Yaf_Route_Regex.php @@ -1,92 +1,89 @@ = 3.0.2) -*Class yaf_Route_Regex +*yaf正则路由 */ -final class Yaf_Route_Regex +final class Yaf_Route_Regex implements Yaf_Route_Interface { /** - * @var unknown $_route - * (Yaf >= 3.0.2) + * @var array $_route * 匹配模式(正则表达式) * @access protected - protected $_route; + */ + protected $_route = array(); /** - * @var unknown $_default - * (Yaf >= 3.0.2) + * @var array $_default * 路由信息 * @access protected - protected $_default; + */ + protected $_default = array(); /** - * @var unknown $_maps - * (Yaf >= 3.0.2) + * @var array $_maps * 模式分组的映射关系 * @access protected - protected $_maps; + */ + protected $_maps = array(); /** - * @var unknown $_verify - * (Yaf >= 3.0.2) - * 哥也不清楚(实在没有查到作用,源码也没看出所以然,问鸟哥!) + * @var array $_verify + * * @access protected - protected $_verify; + */ + protected $_verify = array(); /** - * @var unknown $_reverse + * @var string $_reverse * * @access protected + */ protected $_reverse; /** * - *(Yaf >= 3.0.2) *构造方法 * @example - * @param string $match (Yaf >= 3.0.2) -构造方法 - * @param array $route (Yaf >= 3.0.2) -构造方法 - * @param array $map (Yaf >= 3.0.2) -构造方法 - * @param mixed $verify - * @param mixed $reverse + * @param string $match 匹配模式(正则表达式) + * @param array $route 路由信息 + * @param array $map 模式分组的映射关系 + * @param array $verify + * @param string $reverse * @return */ - public function __construct($match, Array $route, Array $map, $verify, $reverse) + public function __construct(string $match, Array $route, Array $map, Array $verify, string $reverse ) { + } /** * - *(Yaf >= 3.0.2) *路由请求 * @example - * @param mixed $request - * @return + * @param Yaf_Request_Abstract $request 请求对象 + * @return bool */ - public function route($request) + public function route(Yaf_Request_Abstract $request): bool { + } /** * - *(Yaf >= 2.3.2) - *组合uri,路由解析的逆操作 + *组装请求 * @example - * @param mixed $info - * @param mixed $query - * @return + * @param array $info 路径信息 + * @param array $query 查询字符串 + * @return string */ - public function assemble($info, $query) + public function assemble(Array $info, Array $query): string { + } } diff --git a/src/Yaf/Yaf_Route_Rewrite.php b/src/Yaf/Yaf_Route_Rewrite.php index f784eff..1ca3142 100644 --- a/src/Yaf/Yaf_Route_Rewrite.php +++ b/src/Yaf/Yaf_Route_Rewrite.php @@ -1,76 +1,73 @@ = 3.0.2) -*Class yaf_Route_Rewrite +*重写路由 */ -final class Yaf_Route_Rewrite +final class Yaf_Route_Rewrite implements Yaf_Route_Interface { /** - * @var unknown $_route - * (Yaf >= 3.0.2) - * 匹配模式(正则表达式) + * @var array $_route + * 路由信息 * @access protected - protected $_route; + */ + protected $_route = array(); /** - * @var unknown $_default - * (Yaf >= 3.0.2) - * 路由信息 + * @var array $_default + * 默认路由信息 * @access protected - protected $_default; + */ + protected $_default = array(); /** - * @var unknown $_verify - * (Yaf >= 3.0.2) - * 哥也不清楚(实在没有查到作用,源码也没看出所以然,问鸟哥!) + * @var array $_verify + * * @access protected - protected $_verify; + */ + protected $_verify = array(); /** * - *(Yaf >= 3.0.2) *构造方法 * @example - * @param string $match (Yaf >= 3.0.2) -构造方法 - * @param array $route (Yaf >= 3.0.2) -构造方法 - * @param mixed $verify + * @param string $match 匹配模式(正则表达式) + * @param array $route 路由信息 + * @param array $verify * @return */ - public function __construct($match, Array $route, $verify) + public function __construct(string $match, Array $route, Array $verify) { + } /** * - *(Yaf >= 3.0.2) *路由请求 * @example - * @param mixed $request - * @return + * @param Yaf_Request_Abstract $request 请求对象 + * @return bool */ - public function route($request) + public function route(Yaf_Request_Abstract $request): bool { + } /** * - *(Yaf >= 2.3.2) - *组合uri,路由解析的逆操作 + *组装请求 * @example - * @param mixed $info - * @param mixed $query - * @return + * @param array $info 路径信息 + * @param array $query 查询字符串 + * @return string */ - public function assemble($info, $query) + public function assemble(Array $info, Array $query): string { + } } diff --git a/src/Yaf/Yaf_Route_Simple.php b/src/Yaf/Yaf_Route_Simple.php index 8857c26..4552a28 100644 --- a/src/Yaf/Yaf_Route_Simple.php +++ b/src/Yaf/Yaf_Route_Simple.php @@ -1,74 +1,73 @@ = 3.0.2) -*Class yaf_Route_Simple +*简单路由 */ -final class Yaf_Route_Simple +final class Yaf_Route_Simple implements Yaf_Route_Interface { /** - * @var unknown $controller - * (Yaf >= 3.0.2) + * @var string $controller * 控制器名 * @access protected + */ protected $controller; /** - * @var unknown $module - * (Yaf >= 3.0.2) + * @var string $module * 模块名 * @access protected + */ protected $module; /** - * @var unknown $action - * (Yaf >= 3.0.2) + * @var string $action * 动作名 * @access protected + */ protected $action; /** * - *(Yaf >= 3.0.2) *构造方法 * @example - * @param mixed $module_name - * @param mixed $controller_name - * @param mixed $action_name + * @param string $module 模块名 + * @param string $controller 控制器名 + * @param string $action 动作名 * @return */ - public function __construct($module_name, $controller_name, $action_name) + public function __construct(string $module, string $controller, string $action) { + } /** * - *(Yaf >= 3.0.2) *路由请求 * @example - * @param mixed $request - * @return + * @param Yaf_Request_Abstract $request 请求对象 + * @return bool */ - public function route($request) + public function route(Yaf_Request_Abstract $request): bool { + } /** * - *(Yaf >= 2.3.2) - *组合uri,路由解析的逆操作 + *组装请求 * @example - * @param mixed $info - * @param mixed $query - * @return + * @param array $info 路径信息 + * @param array $query 查询字符串 + * @return string */ - public function assemble($info, $query) + public function assemble(Array $info, Array $query): string { + } } diff --git a/src/Yaf/Yaf_Route_Static.php b/src/Yaf/Yaf_Route_Static.php index 6dc7744..4d3d95c 100644 --- a/src/Yaf/Yaf_Route_Static.php +++ b/src/Yaf/Yaf_Route_Static.php @@ -1,51 +1,50 @@ = 3.0.2) -*Class yaf_Route_Static +*静态路由 */ -class Yaf_Route_Static +class Yaf_Route_Static implements Yaf_Route_Interface { /** * - *(Yaf >= 3.0.2) *匹配请求 * @example - * @param mixed $uri + * @param string $uri 匹配的uri * @return */ - public function match($uri) + public function match(string $uri) { + } /** * - *(Yaf >= 3.0.2) *路由请求 * @example - * @param mixed $request - * @return + * @param Yaf_Request_Abstract $request 请求对象 + * @return bool */ - public function route($request) + public function route(Yaf_Request_Abstract $request): bool { + } /** * - *(Yaf >= 2.3.2) - *组合uri,路由解析的逆操作 + *组装请求 * @example - * @param mixed $info - * @param mixed $query - * @return + * @param array $info 路径信息 + * @param array $query 查询字符串 + * @return string */ - public function assemble($info, $query) + public function assemble(Array $info, Array $query): string { + } } diff --git a/src/Yaf/Yaf_Route_Supervar.php b/src/Yaf/Yaf_Route_Supervar.php index a55282e..43c1cb3 100644 --- a/src/Yaf/Yaf_Route_Supervar.php +++ b/src/Yaf/Yaf_Route_Supervar.php @@ -1,58 +1,57 @@ = 3.0.2) -*Class yaf_Route_Supervar +*变量路由 */ -final class Yaf_Route_Supervar +final class Yaf_Route_Supervar implements Yaf_Route_Interface { /** - * @var unknown $_var_name - * (Yaf >= 3.0.2) + * @var string $_var_name * 全局路由变量名 * @access protected + */ protected $_var_name; /** * - *(Yaf >= 3.0.2) *构造方法 * @example - * @param mixed $supervar_name + * @param string $var 全局路由变量名 * @return */ - public function __construct($supervar_name) + public function __construct(string $var) { + } /** * - *(Yaf >= 3.0.2) *路由请求 * @example - * @param mixed $request - * @return + * @param Yaf_Request_Abstract $request 请求对象 + * @return bool */ - public function route($request) + public function route(Yaf_Request_Abstract $request): bool { + } /** * - *(Yaf >= 2.3.2) - *组合uri,路由解析的逆操作 + *组装请求 * @example - * @param mixed $info - * @param mixed $query - * @return + * @param array $info 路径信息 + * @param array $query 查询字符串 + * @return string */ - public function assemble($info, $query) + public function assemble(Array $info, Array $query): string { + } } diff --git a/src/Yaf/Yaf_Router.php b/src/Yaf/Yaf_Router.php index b7b50e6..5b3c95e 100644 --- a/src/Yaf/Yaf_Router.php +++ b/src/Yaf/Yaf_Router.php @@ -1,105 +1,109 @@ = 3.0.2) -*Class yaf_Router +*yaf路由器 */ final class Yaf_Router { /** - * @var unknown $_routes - * (Yaf >= 3.0.2) + * @var array $_routes * 路由器已有的路由协议栈, 默认的栈底总是名为"default"的Route_Static路由协议的实例 * @access protected - protected $_routes; + */ + protected $_routes = array(); /** - * @var unknown $_current - * (Yaf >= 3.0.2) + * @var int $_current * 在路由成功后, 路由生效的路由协议实例的索引 * @access protected + */ protected $_current; /** * - *(Yaf >= 3.0.2) *构造方法 * @example * @return */ public function __construct() { + } /** * - *(Yaf >= 3.0.2) *往Router中添加新的路由 * @example - * @return + * @param string $name 别名 + * @param Yaf_Route_Interface $route 路由对象 + * @return bool */ - public function addRoute() + public function addRoute(string $name, Yaf_Route_Interface $route): bool { + } /** * - *(Yaf >= 3.0.2) *向Router中添加配置文件或者配置数组定义的路由 * @example - * @return + * @param Yaf_Config_Abstract $config 配置对象 + * @return bool */ - public function addConfig() + public function addConfig(Yaf_Config_Abstract $config): bool { + } /** * - *(Yaf >= 3.0.2) *路由请求 * @example - * @return + * @param Yaf_Request_Abstract $request 请求对象 + * @return bool */ - public function route() + public function route(Yaf_Request_Abstract $request): bool { + } /** * - *(Yaf >= 3.0.2) *获取路由名对应的路由协议实例 * @example - * @return + * @param string $name 路由名 + * @return string */ - public function getRoute() + public function getRoute(string $name): string { + } /** * - *(Yaf >= 3.0.2) *获取已注册的所有路由协议 * @example - * @return + * @return array */ - public function getRoutes() + public function getRoutes(): array { + } /** * - *(Yaf >= 3.0.2) *获取当前路由成功的路由协议实例 * @example - * @return + * @return string */ - public function getCurrentRoute() + public function getCurrentRoute(): string { + } } diff --git a/src/Yaf/Yaf_Session.php b/src/Yaf/Yaf_Session.php index 92c7fac..e9bca75 100644 --- a/src/Yaf/Yaf_Session.php +++ b/src/Yaf/Yaf_Session.php @@ -1,332 +1,301 @@ = 3.0.2) -*Class yaf_Session +*yaf的会话对象 */ -final class Yaf_Session +final class Yaf_Session implements Iterator,ArrayAccess, Countable { /** - * @var unknown $_instance - * + * @var Yaf_Session $_instance + * session对象 * @access protected + */ protected static $_instance; /** - * @var unknown $_session - * + * @var array $_session + * session存储对象 * @access protected - protected $_session; + */ + protected $_session = array(); /** - * @var unknown $_started - * + * @var bool $_started + * 是否开启session * @access protected - protected $_started = ''; + */ + protected $_started = false; /** * - *(Yaf >= 3.0.2) *重置__construct魔术方法. * @example * @return */ private function __construct() { + } /** * - *(Yaf >= 3.0.2) *重置__clone魔术方法(因为是单例模式). * @example * @return */ private function __clone() { + } /** * - *(Yaf >= 3.0.2) *重置__sleep魔术方法. * @example * @return */ private function __sleep() { + } /** * - *(Yaf >= 3.0.2) *重置__wakeup魔术方法. * @example * @return */ private function __wakeup() { + } /** * - *(Yaf >= 3.0.2) *获取Session实例(单例模式) * @example - * @return + * @return Yaf_Session */ - public static function getInstance() + public static function getInstance(): Yaf_Session { + } /** * - *(Yaf >= 3.0.2) *开启会话 * @example * @return */ public function start() { + } /** * - *(Yaf >= 3.0.2) - *获取session变量 + *重置__destruct魔术方法. * @example - * @param string $name (Yaf >= 3.0.2) -获取session变量 * @return */ - public function get($name) + public function __destruct() { + } /** * - * + *魔术方法,当isset()检测session变量是否存在时调用 * @example - * @param mixed $name + * @param string $name 节点名称 * @return */ - public function has($name) + public function __isset(string $name) { + } /** * - *(Yaf >= 3.0.2) - *设置session变量 + *获取session变量 * @example - * @param string $name (Yaf >= 3.0.2) -设置session变量 - * @param mixed $value (Yaf >= 3.0.2) -设置session变量 + * @param string $name 变量名 * @return */ - public function set($name, $value) + public function get(string $name) { + } /** * - *(Yaf >= 3.0.2) - *撤消session变量 + *设置session变量 * @example - * @param string $name (Yaf >= 3.0.2) -撤消session变量 + * @param string $name 变量名 + * @param mixed $value 变量值 * @return */ - public function del($name) + public function set(string $name, $value) { + } /** * - *(Yaf >= 3.0.2) - *返回session变量的数量 + *撤消session变量 * @example + * @param string $name 变量名 * @return */ - public function count() + public function del(string $name) { + } /** * - *(Yaf >= 3.0.2) - *重置遍历位置 + *返回session变量的数量 * @example * @return */ - public function rewind() + public function count() { + } /** * - *(Yaf >= 3.0.2) - *向前移动到下一个元素 + *重置遍历位置 * @example * @return */ - public function next() + public function rewind() { + } /** * - *(Yaf >= 3.0.2) *返回当前变量 * @example * @return */ public function current() { + } /** * - *(Yaf >= 3.0.2) - *返回当前配置节点的key + *向前移动到下一个元素 * @example * @return */ - public function key() + public function next() { + } /** * - *(Yaf >= 3.0.2) *判断是否可以继续遍历 * @example * @return */ public function valid() { + } /** * - * - * @example - * @return - */ - public function clear() - { - } - - /** - * - *(Yaf >= 3.0.2) - *获取session变量 + *返回当前配置节点的key * @example - * @param string $name (Yaf >= 3.0.2) -获取session变量 * @return */ - public function offsetGet($name) + public function key() { + } /** * - *(Yaf >= 3.0.2) - *设置session变量 + *撤消某个session变量 * @example - * @param string $name (Yaf >= 3.0.2) -设置session变量 - * @param mixed $value (Yaf >= 3.0.2) -设置session变量 + * @param string $name 变量名 * @return */ - public function offsetSet($name, $value) + public function offsetUnset(string $name) { + } /** * - *(Yaf >= 3.0.2) *测试某个session变量是否存在 * @example - * @param mixed $name (Yaf >= 3.0.2) -测试某个session变量是否存在 + * @param mixed $name 变量名 * @return */ public function offsetExists($name) { + } /** * - *(Yaf >= 3.0.2) - *撤消某个session变量 + *获取session变量 * @example - * @param string $name (Yaf >= 3.0.2) -撤消某个session变量 + * @param string $name 变量名 * @return */ - public function offsetUnset($name) + public function offsetGet(string $name) { + } /** * - *(Yaf >= 3.0.2) - *获取session变量值 - *当不传递$name参数时,返回全部变量 + *设置session变量 * @example - * @param mixed $name + * @param string $name 变量名 + * @param mixed $value 变量值 * @return */ - public function __get($name) + public function offsetSet(string $name, $value) { + } /** * - *(Yaf >= 3.0.2) - *魔术方法,当isset()检测session变量是否存在时调用 + *获取session变量值 + *当不传递$name参数时,返回全部变量 * @example - * @param string $name (Yaf >= 3.0.2) -魔术方法,当isset()检测session变量是否存在时调用 + * @param string $name session键名 * @return */ - public function __isset($name) + public function __get(string $name) { + } /** * - *(Yaf >= 3.0.2) *设置session变量 * @example - * @param string $name (Yaf >= 3.0.2) -设置session变量 - * @param mixed $value (Yaf >= 3.0.2) -设置session变量 - * @return - */ - public function __set($name, $value) - { - } - - /** - * - * - * @example - * @param mixed $name + * @param string $name 变量名 + * @param mixed $value 变量值 * @return */ - public function __unset($name) + public function __set(string $name, $value) { + } } diff --git a/src/Yaf/Yaf_View_Interface.php b/src/Yaf/Yaf_View_Interface.php index b0bcdef..2faa72e 100644 --- a/src/Yaf/Yaf_View_Interface.php +++ b/src/Yaf/Yaf_View_Interface.php @@ -1,61 +1,61 @@ = 3.0.2) -*Class yaf_View_Simple +*简单视图对象 */ -class Yaf_View_Simple +class Yaf_View_Simple implements Yaf_View_Interface { /** - * @var unknown $_tpl_vars - * (Yaf >= 3.0.2) + * @var array $_tpl_vars * 储存所有模板变量 * @access protected - protected $_tpl_vars; + */ + protected $_tpl_vars = array(); /** - * @var unknown $_tpl_dir - * (Yaf >= 3.0.2) + * @var string $_tpl_dir * 模板文件目录 * @access protected + */ protected $_tpl_dir; /** - * @var unknown $_options - * (Yaf >= 3.0.2) + * @var array $_options + * 配置选项 * @access protected - protected $_options; + */ + protected $_options = array(); /** * - *(Yaf >= 3.0.2) *构造方法 * @example - * @param mixed $template_dir - * @param array $options (Yaf >= 3.0.2) -构造方法 + * @param string $tpl_dir 模板文件目录 + * @param array $options 此属性在php-5.4以下版本中适用,用以设置模板渲染的方式 * @return */ - public final function __construct($template_dir, Array $options) + public function __construct(string $tpl_dir, Array $options) { + } /** * - *(Yaf >= 3.0.2) *当isset检测某个属性是否存在时自动调用(判断是否传递某个模板变量) * @example - * @param string $name (Yaf >= 3.0.2) -当isset检测某个属性是否存在时自动调用(判断是否传递某个模板变量) + * @param string $name 模板变量名 * @return */ - public function __isset($name) + public function __isset(string $name) { + } /** * - *(Yaf >= 3.0.2) *获取某个模板变量的值 * @example - * @param string $name (Yaf >= 3.0.2) -获取某个模板变量的值 + * @param string $name 模板变量名 * @return */ - public function get($name) + public function __get(string $name) { + } /** * - *(Yaf >= 3.0.2) - *传递变量到模板 + *获取某个模板变量的值 * @example - * @param string $name (Yaf >= 3.0.2) -传递变量到模板 - * @param string $value (Yaf >= 3.0.2) -传递变量到模板 + * @param string $name 模板变量名 * @return */ - public function assign($name, $value) + public function get(string $name) { + } /** * - *(Yaf >= 3.0.2) - *渲染模板并返回结果 + *传递变量到模板 * @example - * @param string $tpl (Yaf >= 3.0.2) -渲染模板并返回结果 - * @param mixed $tpl_vars + * @param string $name 变量名 + * @param string $value 变量值 * @return */ - public function render($tpl, $tpl_vars) + public function __set(string $name, string $value) { + } /** * - * + *清空某个模板变量的值 * @example - * @param mixed $tpl_str - * @param mixed $vars + * @param string $name 模板变量名 * @return */ - public function eval($tpl_str, $vars) + public function clear(string $name) { + } /** * - *(Yaf >= 3.0.2) - *渲染模板并直接输出 + *传递变量到模板 * @example - * @param string $tpl (Yaf >= 3.0.2) -渲染模板并直接输出 - * @param mixed $tpl_vars + * @param string $name 变量名 + * @param string $value 变量值 * @return */ - public function display($tpl, $tpl_vars) + public function assign(string $name, string $value) { + } /** * - *(Yaf >= 3.0.2) *以引用的方式传递变量到模板 * @example - * @param string $name (Yaf >= 3.0.2) -以引用的方式传递变量到模板 - * @param string $value (Yaf >= 3.0.2) -以引用的方式传递变量到模板 - * @return - */ - public function assignRef($name, $value) - { - } - - /** - * - *(Yaf >= 3.0.2) - *清空某个模板变量的值 - * @example - * @param string $name (Yaf >= 3.0.2) -清空某个模板变量的值 + * @param string $name 变量名 + * @param string $value 变量值 * @return */ - public function clear($name) + public function assignRef(string $name, string $value) { + } /** * - *(Yaf >= 3.0.2) - *设置模板文件目录 + *渲染模板并直接输出 * @example - * @param mixed $template_dir + * @param string $tpl 模板文件名 + * @param array $var_array 模板变量数组 * @return */ - public function setScriptPath($template_dir) + public function display(string $tpl, Array $var_array = []) { + } /** * - *(Yaf >= 3.0.2) - *获取模板目录文件 + *渲染模板并返回结果 * @example + * @param string $tpl 模板文件名 + * @param array $var_array 模板变量数组 * @return */ - public function getScriptPath() + public function render(string $tpl, Array $var_array = []) { + } /** * - *(Yaf >= 3.0.2) - *获取某个模板变量的值 + *设置模板文件目录 * @example - * @param string $name (Yaf >= 3.0.2) -获取某个模板变量的值 + * @param string $tpl_dir 模板文件目录 * @return */ - public function __get($name) + public function setScriptPath(string $tpl_dir) { + } /** * - *(Yaf >= 3.0.2) - *传递变量到模板 + *获取模板目录文件 * @example - * @param string $name (Yaf >= 3.0.2) -传递变量到模板 - * @param string $value (Yaf >= 3.0.2) -传递变量到模板 - * @return + * @return string */ - public function __set($name, $value) + public function getScriptPath(): string { + } } diff --git a/src/Yaf/yaf.namespace.php b/src/Yaf/yaf.namespace.php new file mode 100644 index 0000000..851fe2e --- /dev/null +++ b/src/Yaf/yaf.namespace.php @@ -0,0 +1,92 @@ +=7.0" + }, + "require-dev":{ + "shixinke/php-ide-helper":"dev-master" + } +} diff --git a/tests/swoole-project/test.php b/tests/swoole-project/test.php new file mode 100644 index 0000000..0b3c69e --- /dev/null +++ b/tests/swoole-project/test.php @@ -0,0 +1,6 @@ +