├── .gitattributes ├── .gitignore ├── Docs ├── FullDemo.md └── README.md ├── Examples └── start.php ├── Image ├── AppAssistantEnglish.png ├── AppGithubEnglish.png ├── AppWeather2English.png ├── AppWeatherEnglish.png ├── DemoShow.png ├── EnglishVersion1.png ├── EnglishVersion2.png ├── QRCodePHPCreeper.png ├── QRCodePHPCreeperForWechat.png ├── alipay.png ├── qqgroup.jpg ├── qrcode-taobaodianpu.png └── wechat.png ├── LICENSE.txt ├── README.md ├── composer.json └── src ├── Cookie.php ├── Crontab.php ├── Downloader.php ├── Kernel ├── Language │ ├── en.php │ └── zh.php ├── Library │ ├── Common │ │ └── Functions.php │ ├── Crontab │ │ └── Crontab.php │ ├── Helper │ │ ├── Benchmark.php │ │ └── Tool.php │ ├── Polyfill │ │ └── Uuid.php │ └── phpQuery │ │ ├── demo.php │ │ ├── phpQuery.php │ │ └── phpQuery │ │ ├── Callback.php │ │ ├── DOMDocumentWrapper.php │ │ ├── DOMEvent.php │ │ ├── Zend │ │ ├── Exception.php │ │ ├── Http │ │ │ ├── Client.php │ │ │ ├── Client │ │ │ │ ├── Adapter │ │ │ │ │ ├── Exception.php │ │ │ │ │ ├── Interface.php │ │ │ │ │ ├── Proxy.php │ │ │ │ │ ├── Socket.php │ │ │ │ │ └── Test.php │ │ │ │ └── Exception.php │ │ │ ├── Cookie.php │ │ │ ├── CookieJar.php │ │ │ ├── Exception.php │ │ │ └── Response.php │ │ ├── Json │ │ │ ├── Decoder.php │ │ │ ├── Encoder.php │ │ │ └── Exception.php │ │ ├── Loader.php │ │ ├── Registry.php │ │ ├── Uri.php │ │ ├── Uri │ │ │ ├── Exception.php │ │ │ └── Http.php │ │ └── Validate │ │ │ ├── Abstract.php │ │ │ ├── Alnum.php │ │ │ ├── Alpha.php │ │ │ ├── Barcode.php │ │ │ ├── Barcode │ │ │ ├── Ean13.php │ │ │ └── UpcA.php │ │ │ ├── Between.php │ │ │ ├── Ccnum.php │ │ │ ├── Date.php │ │ │ ├── Digits.php │ │ │ ├── EmailAddress.php │ │ │ ├── Exception.php │ │ │ ├── File │ │ │ ├── Count.php │ │ │ ├── Exists.php │ │ │ ├── Extension.php │ │ │ ├── FilesSize.php │ │ │ ├── ImageSize.php │ │ │ ├── MimeType.php │ │ │ ├── NotExists.php │ │ │ ├── Size.php │ │ │ └── Upload.php │ │ │ ├── Float.php │ │ │ ├── GreaterThan.php │ │ │ ├── Hex.php │ │ │ ├── Hostname.php │ │ │ ├── Hostname │ │ │ ├── At.php │ │ │ ├── Ch.php │ │ │ ├── De.php │ │ │ ├── Fi.php │ │ │ ├── Hu.php │ │ │ ├── Interface.php │ │ │ ├── Li.php │ │ │ ├── No.php │ │ │ └── Se.php │ │ │ ├── Identical.php │ │ │ ├── InArray.php │ │ │ ├── Int.php │ │ │ ├── Interface.php │ │ │ ├── Ip.php │ │ │ ├── LessThan.php │ │ │ ├── NotEmpty.php │ │ │ ├── Regex.php │ │ │ └── StringLength.php │ │ ├── bootstrap.example.php │ │ ├── compat │ │ └── mbstring.php │ │ ├── phpQueryEvents.php │ │ ├── phpQueryObject.php │ │ └── plugins │ │ ├── Scripts.php │ │ ├── Scripts │ │ ├── __config.example.php │ │ ├── example.php │ │ ├── fix_webroot.php │ │ ├── google_login.php │ │ ├── print_source.php │ │ └── print_websafe.php │ │ ├── WebBrowser.php │ │ └── example.php ├── Middleware │ ├── Database │ │ └── Database.php │ ├── DropDuplicate │ │ ├── BloomFilterLocal.php │ │ ├── BloomFilterPredis.php │ │ └── BloomFilterRedis.php │ ├── HeadlessBrowser │ │ └── Chrome.php │ ├── HttpClient │ │ ├── Curl.php │ │ └── Guzzle.php │ ├── LockManager │ │ ├── DistributedRedLock.php │ │ ├── FileLock.php │ │ ├── PredisLock.php │ │ └── RedisLock.php │ └── MessageQueue │ │ ├── AmqpExtension.php │ │ ├── Base │ │ ├── Context.php │ │ ├── Entity.php │ │ ├── Exchange.php │ │ ├── Message.php │ │ └── Queue.php │ │ ├── PhpQueue.php │ │ ├── PredisClient.php │ │ └── RedisExtension.php ├── PHPCreeper.php ├── Plugin │ └── ProxyPlugin.php ├── Service │ ├── Provider │ │ ├── DropDuplicateServiceProvider.php │ │ ├── ExtractorServiceProvider.php │ │ ├── HeadlessBrowserServiceProvider.php │ │ ├── HttpServiceProvider.php │ │ ├── LanguageServiceProvider.php │ │ ├── LockServiceProvider.php │ │ ├── PluginServiceProvider.php │ │ ├── QueueServiceProvider.php │ │ └── SystemServiceProvider.php │ ├── Service.php │ └── Wrapper │ │ ├── DropDuplicateService.php │ │ ├── ExtractorService.php │ │ ├── HeadlessBrowserFactoryService.php │ │ ├── HttpFactoryService.php │ │ ├── LanguageService.php │ │ ├── LockFactoryService.php │ │ ├── PluginService.php │ │ └── QueueFactoryService.php ├── Slot │ ├── BrokerInterface.php │ ├── DropDuplicateInterface.php │ ├── HttpClientInterface.php │ ├── LockInterface.php │ └── PluginInterface.php └── Task.php ├── PHPCreeper.php ├── Parser.php ├── Producer.php ├── Server.php ├── Timer.php └── Tool.php /.gitattributes: -------------------------------------------------------------------------------- 1 | *.js linguist-language=PHP 2 | *.css linguist-language=PHP 3 | *.html linguist-language=PHP 4 | *.c linguist-language=C 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | *.lock 3 | *.pid 4 | .idea 5 | .buildpath 6 | .project 7 | .settings 8 | .DS_Store 9 | logs 10 | vendor 11 | Examples/debug.php 12 | -------------------------------------------------------------------------------- /Image/AppAssistantEnglish.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blogdaren/PHPCreeper/e00d8e3cd1a5ed5558c5fc254a411923f66891d7/Image/AppAssistantEnglish.png -------------------------------------------------------------------------------- /Image/AppGithubEnglish.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blogdaren/PHPCreeper/e00d8e3cd1a5ed5558c5fc254a411923f66891d7/Image/AppGithubEnglish.png -------------------------------------------------------------------------------- /Image/AppWeather2English.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blogdaren/PHPCreeper/e00d8e3cd1a5ed5558c5fc254a411923f66891d7/Image/AppWeather2English.png -------------------------------------------------------------------------------- /Image/AppWeatherEnglish.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blogdaren/PHPCreeper/e00d8e3cd1a5ed5558c5fc254a411923f66891d7/Image/AppWeatherEnglish.png -------------------------------------------------------------------------------- /Image/DemoShow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blogdaren/PHPCreeper/e00d8e3cd1a5ed5558c5fc254a411923f66891d7/Image/DemoShow.png -------------------------------------------------------------------------------- /Image/EnglishVersion1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blogdaren/PHPCreeper/e00d8e3cd1a5ed5558c5fc254a411923f66891d7/Image/EnglishVersion1.png -------------------------------------------------------------------------------- /Image/EnglishVersion2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blogdaren/PHPCreeper/e00d8e3cd1a5ed5558c5fc254a411923f66891d7/Image/EnglishVersion2.png -------------------------------------------------------------------------------- /Image/QRCodePHPCreeper.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blogdaren/PHPCreeper/e00d8e3cd1a5ed5558c5fc254a411923f66891d7/Image/QRCodePHPCreeper.png -------------------------------------------------------------------------------- /Image/QRCodePHPCreeperForWechat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blogdaren/PHPCreeper/e00d8e3cd1a5ed5558c5fc254a411923f66891d7/Image/QRCodePHPCreeperForWechat.png -------------------------------------------------------------------------------- /Image/alipay.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blogdaren/PHPCreeper/e00d8e3cd1a5ed5558c5fc254a411923f66891d7/Image/alipay.png -------------------------------------------------------------------------------- /Image/qqgroup.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blogdaren/PHPCreeper/e00d8e3cd1a5ed5558c5fc254a411923f66891d7/Image/qqgroup.jpg -------------------------------------------------------------------------------- /Image/qrcode-taobaodianpu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blogdaren/PHPCreeper/e00d8e3cd1a5ed5558c5fc254a411923f66891d7/Image/qrcode-taobaodianpu.png -------------------------------------------------------------------------------- /Image/wechat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/blogdaren/PHPCreeper/e00d8e3cd1a5ed5558c5fc254a411923f66891d7/Image/wechat.png -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020-2099 blogdaren 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "blogdaren/phpcreeper", 3 | "type": "library", 4 | "keywords": ["spider", "crawler", "multi-process", "event-loop", "async", "headless"], 5 | "homepage": "http://www.phpcreeper.com", 6 | "description": "A new generation of multi-process async event-driven spider engine based on Workerman", 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "blogdaren", 11 | "email": "blogdaren@163.com" 12 | } 13 | ], 14 | "support": { 15 | "wiki": "http://www.phpcreeper.com/docs/", 16 | "source": "https://github.com/blogdaren/PHPCreeper" 17 | }, 18 | "require": { 19 | "php": ">=7.0.0", 20 | "workerman/workerman": ">=3.5.0,<5.0.0", 21 | "blogdaren/configurator": "^1.0", 22 | "blogdaren/logger": "^1.1.2", 23 | "guzzlehttp/guzzle": "^6.4 || ^7.0", 24 | "predis/predis": "2.0.*", 25 | "chrome-php/chrome": "^1.11" 26 | }, 27 | "suggest": { 28 | "ext-event": "For better performance" 29 | }, 30 | "autoload": { 31 | "psr-4": { 32 | "PHPCreeper\\" : "src/" 33 | }, 34 | "files": [ 35 | "src/Kernel/Library/Common/Functions.php" 36 | ] 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Cookie.php: -------------------------------------------------------------------------------- 1 | 6 | * @link http://www.phpcreeper.com 7 | * @create 2024-04-23 8 | */ 9 | 10 | namespace PHPCreeper; 11 | 12 | use HeadlessChromium\Cookies\Cookie as HeadlessChromiumCookie; 13 | 14 | class Cookie extends HeadlessChromiumCookie 15 | { 16 | 17 | } 18 | 19 | -------------------------------------------------------------------------------- /src/Crontab.php: -------------------------------------------------------------------------------- 1 | 6 | * @link http://www.phpcreeper.com 7 | * @create 2022-08-16 8 | */ 9 | 10 | namespace PHPCreeper; 11 | 12 | use PHPCreeper\Kernel\Library\Crontab\Crontab as Crontable; 13 | 14 | class Crontab extends Crontable 15 | { 16 | /** 17 | * 18 | * 秒 分 时 日 月 周 19 | * 0 1 2 3 4 5 20 | * | | | | | | 21 | * | | | | | +------ day of week (0 - 6) (Sunday=0) 22 | * | | | | +------ month (1 - 12) 23 | * | | | +-------- day of month (1 - 31) 24 | * | | +---------- hour (0 - 23) 25 | * | +------------ min (0 - 59) 26 | * +-------------- sec (0-59)[可省略,如果没有0位,则最小时间粒度是分钟] 27 | * 28 | */ 29 | } 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/Kernel/Language/zh.php: -------------------------------------------------------------------------------- 1 | 6 | * @link http://www.phpcreeper.com 7 | * @create 2019-09-20 8 | */ 9 | 10 | return [ 11 | 'queue_start_url_invalid' => "初始任务: 检测到初始任务URL配置无效, 请检查配置确保正确设置初始任务URL.......", 12 | 'queue_url_invalid' => "生产任务: 检测到任务URL配置无效, 请确认是否已经正确设置任务URL.......", 13 | 'queue_full' => "队列监控: Task 队列任务已经达到阀值%max_number%, 当前积压任务总量为: %task_number%", 14 | 'queue_empty' => "队列监控: Task 队列任务已被消费一空, 间隔 %crawl_interval% 秒后继续消费任务.................", 15 | 'queue_push_task' => "生产任务: 检测到新建任务并压入队: %task_url%", 16 | 'queue_push_exception_task' => "生产任务: 检测到异常任务并压入队: %task_url%", 17 | 'queue_duplicate_task' => "生产任务: 检测到重复任务直接丢弃: %task_url%", 18 | 'queue_inactive_task' => "生产任务: 检测到冻结任务直接丢弃: %task_url%", 19 | //'network_connect_success' => "网络巡检:检测到本机至远程Parser的异步连接建立成功, 继续从 Task 队列提取任务.", 20 | 'downloader_connect_success' => "网络巡检:检测到本机至远程解析器的异步连接建立成功: %downloader_client_address%", 21 | 'downloader_connect_failed' => "网络异常:检测到本机至远程解析器异步连接已断开: %parser_socket%, %reconnect_time%秒后尝试重连", 22 | 'downloader_task_args_invalid' => "参数校验: 检测到读取缓存时任务参数为空, 也许是你疏忽忘记了提供有效的 task_url", 23 | 'downloader_cache_disabled' => "缓存校验: 检测到已禁用任务缓存, 任务ID: %task_id%", 24 | 'downloader_cache_enabled' => "缓存校验: 检测到已启用任务缓存, 任务ID: %task_id%", 25 | 'downloader_create_cache_failed'=> "权限校验: 检测到下载任务时缓存目录禁写, 请确认是否是否赋予了必要的写权限, 当前缓存目录是: %cache_path%", 26 | 'downloader_read_from_cache' => "下载任务: 下载器命中到任务缓存, 任务ID: %task_id% 【缓存文件: %cache_path%】", 27 | 'downloader_write_into_cache' => "下载任务: 下载器硬更新任务缓存, 任务ID: %task_id% 【缓存文件: %cache_path%】", 28 | 'downloader_rebuild_task_null' => "参数校验: 检测到下载任务时任务参数为空, 也许是你疏忽忘记了提供有效的 task_url", 29 | 'downloader_get_one_task' => "消费任务: 下载器成功获得一条任务: %task_url%", 30 | 'downloader_download_task_yes' => "下载任务: 检测到任务下载成功", 31 | 'downloader_download_task_no' => "下载任务: 检测到任务下载失败", 32 | 'downloader_forward_args' => "参数校验: 检测到 forward(\$task) 参数无效, 正确姿势:\$task = ['task' => [], 'download_data' => '']", 33 | 'downloader_buffer_full' => "流量控制: 检测到对端的消费能力已经弱于本端的生产能力, 即将限流直至对端提高强消费能力.", 34 | 'downloader_buffer_drain' => "流量控制: 检测到本端发送缓冲区空间富裕,继续向对端推送数据...................", 35 | 'downloader_forward_data' => "异步分发: 下载器已将下载源数据成功分发至远程 Parser 服务器...................", 36 | 'downloader_close_connection' => "网络巡检: 检测到当前连接请求数已经超过最大请求%max_request%, 关闭连接并%reconnect_time%秒后尝试重连.", 37 | 'downloader_connect_error' => "网络巡检: 检测到下载器与解析器建立异步连接失败:请检查Parser地址配置是否正确.", 38 | 'downloader_got_replay_null' => "收到反馈: 检测到解析器响应为空:原因很可能是下载器和解析器socket通信协议设定不一致.", 39 | 'downloader_lost_connections' => "网络巡检:检测到下载器获取不到可用的任务连接对象.............................", 40 | 'downloader_lost_channel' => "网络巡检:检测到下载器获取不到可用的任务连接通道.............................", 41 | 'downloader_download_filesize_exceed' => "下载任务:检检到要下载的文件大小(%file_size%字节)超过了预设的最大值(%default_max_file_size%字节), 丢弃任务.....", 42 | 'http_transfer_exception' => "请求异常: %exception_msg% (exception_code: %exception_code%) (task_url: %url%)", 43 | 'http_transfer_compress' => "压缩传输: 检测到已启用压缩方式传输数据: 压缩算法%algorithm%...................", 44 | 'http_assemble_method' => "打包传输: 检测到已启用打包方式传输数据: 打包方式%assemble_method%...................", 45 | 'parser_close_connection' => "网络巡检: 检测到下载器在指定时间内未发送任何请求, 连接被关闭, %reconnect_time%秒后尝试重连..", 46 | 'parser_connected_success' => "网络巡检:检测到远程下载器至本机的异步连接建立成功: %parser_server_address%", 47 | 'parser_task_success' => "解析封包:第%connection_id%号连接:封包解析成功 (%task_id%)", 48 | 'parser_task_report' => "收到反馈:第%connection_id%号连接:封包处理成功 (%task_id%)", 49 | 'parser_find_url' => "新子任务:解析器成功提取到新子任务并压入任务队列: %sub_url%", 50 | 'task_exceed_max_depth' => "采集深度:检测到采集深度已经超过最大深度%max_depth%, 不再入队: %sub_url%", 51 | 'ping_from_downloader' => "心跳监控:检测到来自下载器的心跳数据包:心跳间隔为 %interval% 秒.......................", 52 | 'ext_msgpack_not_install' => "数据打包:检测到数据打包方式为msgpack, 但是msgpack扩展并未安装, 尝试切换为json", 53 | 'invalid_httpclient_object' => "危险行为:检测到非法的 httpClient 对象, 要求必须实现 HttpClientInterface 接口", 54 | 'invalid_queueclient_object' => "危险行为:检测到非法的 queueClient 对象, 要求必须实现 BrokerInterface 接口", 55 | 'work_as_single_worker_mode' => "工作模式:当前为单worker工作模式,注意该模式下只能运行下载器实例", 56 | 'logger_prefix_producer' => "Producer | %worker_name% | PID:%process_id% | %worker_id%号生产器进程", 57 | 'logger_prefix_downloader' => "Downloader | %worker_name% | PID:%process_id% | %worker_id%号下载器进程", 58 | 'logger_prefix_parser' => "Parser | %worker_name% | PID:%process_id% | %worker_id%号解析器进程", 59 | 'logger_prefix_server' => "Server | %worker_name% | PID:%process_id% | %worker_id%号服务器进程", 60 | 'track_request_args' => "请求参数:%request_args%", 61 | 'track_task_package' => "任务数据:%task_package%", 62 | 'redis_server_error' => "服务巡检:%error_msg%, 以多worker模式运行时依赖[redis-server]服务, 请检查[redis-server]服务有没有启动 或 防火墙有没有放行服务端口, 当前进程将在休眠%sleep_time%秒之后自动退出并重启后继续运行.", 63 | 'ext_redis_class_not_found' => "服务巡检: 没有找到类Redis, 因为没有找到redis扩展, 请自行安装PHP官方扩展phpredis, 当前进程将在休眠%sleep_time%秒之后退出并重启后继续运行.", 64 | 'http_method_head_error' => "HEAD请求: %error_msg%", 65 | 'headless_browser_enabled' => "无头浏览:检测到已启用无头浏览器【%bin%】.............................", 66 | 'headless_browser_disabled' => "无头浏览:检测到已禁用无头浏览器......................................", 67 | 'headless_browser_binary_not_found' => "无头浏览:无头浏览器二进制文件【%bin%】找不到, 请自行安装无头浏览器...", 68 | 'headless_browser_exception' => "无头浏览:", 69 | 'headless_browser_proxy_server' => "无头浏览:检测到已启用代理服务器: %proxy_server%", 70 | 'headless_browser_proxy_credential' => "无头浏览:检测到提交给代理服务器的使用凭据【%proxy_username% 和 %proxy_password%】", 71 | 72 | //若干待配字段...... 73 | ]; 74 | 75 | 76 | -------------------------------------------------------------------------------- /src/Kernel/Library/Common/Functions.php: -------------------------------------------------------------------------------- 1 | 6 | * @link http://www.phpcreeper.com 7 | * @version 1.0.0 8 | * @modify 2018-10-13 9 | */ 10 | 11 | 12 | //定义默认的下载文件缓存目录 13 | !defined("DEFAULT_DOWNLOAD_CACHE_DIR") && define("DEFAULT_DOWNLOAD_CACHE_DIR", sys_get_temp_dir() . '/DownloadCache4PHPCreeper/'); 14 | 15 | //定义业务异常时进程的休眠时间 16 | !defined('PROCESS_SLEEP_TIME') && define('PROCESS_SLEEP_TIME', 10); 17 | 18 | /** 19 | * 打印可能要用到的
开始标签
 20 |  */
 21 | if(!function_exists('echoPossibleStartPreLable'))
 22 | {
 23 |     function echoPossibleStartPreLable()
 24 |     {
 25 |         if(PHP_SAPI != 'cli')  echo "
";
 26 |         if(PHP_SAPI == 'cli')  echo PHP_EOL;
 27 |     }
 28 | }
 29 | 
 30 | /**
 31 |  * 打印可能要用到的
结束标签 32 | */ 33 | if(!function_exists('echoPossibleEndPreLable')) 34 | { 35 | function echoPossibleEndPreLable() 36 | { 37 | if(PHP_SAPI != 'cli') echo "
" . str_repeat("=", 100) . PHP_EOL; 38 | if(PHP_SAPI == 'cli') echo PHP_EOL . str_repeat("=", 100) . PHP_EOL; 39 | } 40 | } 41 | 42 | /** 43 | * 打印人性化数据结构: var_dump();exit; 44 | */ 45 | if(!function_exists('ddump')) 46 | { 47 | function ddump($data = null) 48 | { 49 | if(count(func_get_args()) > 1) 50 | { 51 | $data = func_get_args(); 52 | } 53 | 54 | echoPossibleStartPreLable(); 55 | var_dump($data); 56 | echoPossibleEndPreLable(); 57 | exit; 58 | } 59 | } 60 | 61 | /** 62 | * 打印人性化数据结构: var_dump(); pp()函数别名; 63 | */ 64 | if(!function_exists('vdump')) 65 | { 66 | function vdump($data = null) 67 | { 68 | if(count(func_get_args()) > 1) 69 | { 70 | $data = func_get_args(); 71 | } 72 | 73 | echoPossibleStartPreLable(); 74 | var_dump($data); 75 | echoPossibleEndPreLable(); 76 | } 77 | } 78 | 79 | /** 80 | * 打印人性化数据结构并中断运行 81 | */ 82 | if(!function_exists('dprint')) 83 | { 84 | function dprint($data = null) 85 | { 86 | if(count(func_get_args()) > 1) 87 | { 88 | $data = func_get_args(); 89 | } 90 | 91 | echoPossibleStartPreLable(); 92 | print_r($data); 93 | echoPossibleEndPreLable(); 94 | exit; 95 | } 96 | } 97 | 98 | /** 99 | * 打印人性化数据结构 100 | */ 101 | if(!function_exists('pprint')) 102 | { 103 | function pprint($data = null) 104 | { 105 | if(count(func_get_args()) > 1) 106 | { 107 | $data = func_get_args(); 108 | } 109 | 110 | echoPossibleStartPreLable(); 111 | print_r($data); 112 | echoPossibleEndPreLable(); 113 | } 114 | } 115 | 116 | /** 117 | * 递归检测目录 118 | * 119 | * @param string $dir 120 | * 121 | * @return array 122 | */ 123 | if(!function_exists('scanDirectory')) 124 | { 125 | function scanDirectory($dir) 126 | { 127 | static $box; 128 | 129 | $handle = opendir($dir); 130 | 131 | while(false !== ($entry = readdir($handle))) 132 | { 133 | //过滤 (.|..|svn) 等目录 134 | $mode = "/(^\.{1,2}$|svn)/is"; 135 | 136 | if(preg_match($mode, $entry)) 137 | { 138 | continue; 139 | } 140 | 141 | $tmp = $dir . '/' . $entry; 142 | if(is_dir($tmp)) 143 | { 144 | scanDirectory($tmp); 145 | } 146 | else 147 | { 148 | $name = substr($entry, 0, strpos($entry, '.')); 149 | if(preg_match('/php$/', $tmp)) 150 | { 151 | $_name = strtolower($name); 152 | $box[$_name] = $tmp; 153 | } 154 | } 155 | } 156 | 157 | return $box; 158 | } 159 | } 160 | 161 | 162 | 163 | -------------------------------------------------------------------------------- /src/Kernel/Library/Helper/Benchmark.php: -------------------------------------------------------------------------------- 1 | 5 | * Benchmark::start("benchmark1"); 6 | * sleep(2); 7 | * Benchmark::stop("benchmark1"); 8 | * echo Benchmark::getElapsedTime("benchmark1"); 9 | * 10 | */ 11 | 12 | namespace PHPCreeper\Kernel\Library\Helper; 13 | 14 | class Benchmark 15 | { 16 | protected static $benchmark_results = array(); 17 | protected static $benchmark_starttimes = array(); 18 | protected static $benchmark_startcount = array(); 19 | protected static $temporary_benchmarks = array(); 20 | 21 | /** 22 | * Starts the clock for the given benchmark. 23 | * 24 | * @param string $identifie The benchmark name/identifier. 25 | * @param bool $temporary_benchmark If set to TRUE, the benchmark will not be returned by methods 26 | * like getAllBenchmarks() and printAllBenchmarks() 27 | * 28 | * return void 29 | */ 30 | public static function start($identifier = 'default', $temporary_benchmark = false) 31 | { 32 | self::$benchmark_starttimes[$identifier] = self::getmicrotime(); 33 | 34 | if (isset(self::$benchmark_startcount[$identifier])) 35 | self::$benchmark_startcount[$identifier] = self::$benchmark_startcount[$identifier] + 1; 36 | else self::$benchmark_startcount[$identifier] = 1; 37 | 38 | if ($temporary_benchmark == true) 39 | { 40 | self::$temporary_benchmarks[$identifier] = true; 41 | } 42 | } 43 | 44 | /** 45 | * @brief getCallCount 46 | * 47 | * @param string $identifier 48 | * 49 | * @return int 50 | */ 51 | public static function getCallCount($identifier) 52 | { 53 | return self::$benchmark_startcount[$identifier]; 54 | } 55 | 56 | /** 57 | * Stops the benchmark-clock for the given benchmark. 58 | * 59 | * @param string The benchmark name/identifier. 60 | * 61 | * @return int 62 | */ 63 | public static function stop($identifier = 'default') 64 | { 65 | if (isset(self::$benchmark_starttimes[$identifier])) 66 | { 67 | $elapsed_time = self::getmicrotime() - self::$benchmark_starttimes[$identifier]; 68 | 69 | if (isset(self::$benchmark_results[$identifier])) self::$benchmark_results[$identifier] += $elapsed_time; 70 | else self::$benchmark_results[$identifier] = $elapsed_time; 71 | 72 | return $elapsed_time; 73 | } 74 | 75 | return null; 76 | } 77 | 78 | /** 79 | * Gets the elapsed time for the given benchmark. 80 | * 81 | * @param string The benchmark name/identifier. 82 | * 83 | * @return float 84 | */ 85 | public static function getElapsedTime($identifier = 'default', $len = 2) 86 | { 87 | if (isset(self::$benchmark_results[$identifier])) 88 | { 89 | $time = self::$benchmark_results[$identifier]; 90 | 91 | return Tool::getNoRoundFloatValue($time, $len); 92 | } 93 | } 94 | 95 | /** 96 | * @brief Resets the clock for the given benchmark. 97 | * 98 | * @param string $identifier 99 | * 100 | * @return void 101 | */ 102 | public static function reset($identifier) 103 | { 104 | if (isset(self::$benchmark_results[$identifier])) 105 | { 106 | self::$benchmark_results[$identifier] = 0; 107 | } 108 | } 109 | 110 | /** 111 | * Resets all clocks for all benchmarks. 112 | * 113 | * @param array $retain_benachmarks Optional. Numeric array containing benchmark-identifiers that should NOT get resetted. 114 | * 115 | * @return void 116 | */ 117 | public static function resetAll($retain_benchmarks = array()) 118 | { 119 | // If no benchmarks should be retained 120 | if (count($retain_benchmarks) == 0) 121 | { 122 | self::$benchmark_results = array(); 123 | return; 124 | } 125 | 126 | // Else reset all benchmarks BUT the retain_benachmarks 127 | @reset(self::$benchmark_results); 128 | while (list($identifier) = @each(self::$benchmark_results)) 129 | { 130 | if (!in_array($identifier, $retain_benchmarks)) 131 | { 132 | self::$benchmark_results[$identifier] = 0; 133 | } 134 | } 135 | } 136 | 137 | /** 138 | * @brief printAllBenchmarks 139 | * 140 | * @param string $linebreak 141 | * 142 | * @return void 143 | */ 144 | public static function printAllBenchmarks($linebreak = "
") 145 | { 146 | @reset(self::$benchmark_results); 147 | while (list($identifier, $elapsed_time) = @each(self::$benchmark_results)) 148 | { 149 | if (!isset(self::$temporary_benchmarks[$identifier])) echo $identifier.": ".$elapsed_time." sec" . $linebreak; 150 | } 151 | } 152 | 153 | /** 154 | * Returns all registered benchmark-results. 155 | * 156 | * @return array 157 | */ 158 | public static function getAllBenchmarks() 159 | { 160 | $benchmarks = array(); 161 | 162 | @reset(self::$benchmark_results); 163 | while (list($identifier, $elapsed_time) = @each(self::$benchmark_results)) 164 | { 165 | if (!isset(self::$temporary_benchmarks[$identifier])) $benchmarks[$identifier] = $elapsed_time; 166 | } 167 | 168 | return $benchmarks; 169 | } 170 | 171 | /** 172 | * Returns the current time in seconds and milliseconds. 173 | * 174 | * @return float 175 | */ 176 | public static function getmicrotime() 177 | { 178 | return microtime(true); 179 | } 180 | } 181 | 182 | 183 | 184 | -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/demo.php: -------------------------------------------------------------------------------- 1 | '); 12 | 13 | // FILL IT 14 | // array syntax works like ->find() here 15 | $doc['div']->append(''); 16 | // array set changes inner html 17 | $doc['div ul'] = '
  • 1
  • 2
  • 3
  • '; 18 | 19 | // MANIPULATE IT 20 | $li = null; 21 | // almost everything can be a chain 22 | $doc['ul > li'] 23 | ->addClass('my-new-class') 24 | ->filter(':last') 25 | ->addClass('last-li') 26 | // save it anywhere in the chain 27 | ->toReference($li); 28 | 29 | // SELECT DOCUMENT 30 | // pq(); is using selected document as default 31 | phpQuery::selectDocument($doc); 32 | // documents are selected when created or by above method 33 | // query all unordered lists in last selected document 34 | $ul = pq('ul')->insertAfter('div'); 35 | 36 | // ITERATE IT 37 | // all direct LIs from $ul 38 | foreach($ul['> li'] as $li) { 39 | // iteration returns PLAIN dom nodes, NOT phpQuery objects 40 | $tagName = $li->tagName; 41 | $childNodes = $li->childNodes; 42 | // so you NEED to wrap it within phpQuery, using pq(); 43 | pq($li)->addClass('my-second-new-class'); 44 | } 45 | 46 | // PRINT OUTPUT 47 | // 1st way 48 | print phpQuery::getDocument($doc->getDocumentID()); 49 | // 2nd way 50 | print phpQuery::getDocument(pq('div')->getDocumentID()); 51 | // 3rd way 52 | print pq('div')->getDocument(); 53 | // 4th way 54 | print $doc->htmlOuter(); 55 | // 5th way 56 | print $doc; 57 | // another... 58 | print $doc['ul']; 59 | -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/phpQuery/Callback.php: -------------------------------------------------------------------------------- 1 | 25 | * 26 | * @TODO honor paramStructure 27 | */ 28 | class Callback 29 | implements ICallbackNamed { 30 | public $callback = null; 31 | public $params = null; 32 | protected $name; 33 | public function __construct($callback, $param1 = null, $param2 = null, 34 | $param3 = null) { 35 | $params = func_get_args(); 36 | $params = array_slice($params, 1); 37 | if ($callback instanceof Callback) { 38 | // TODO implement recurention 39 | } else { 40 | $this->callback = $callback; 41 | $this->params = $params; 42 | } 43 | } 44 | public function getName() { 45 | return 'Callback: '.$this->name; 46 | } 47 | public function hasName() { 48 | return isset($this->name) && $this->name; 49 | } 50 | public function setName($name) { 51 | $this->name = $name; 52 | return $this; 53 | } 54 | // TODO test me 55 | // public function addParams() { 56 | // $params = func_get_args(); 57 | // return new Callback($this->callback, $this->params+$params); 58 | // } 59 | } 60 | /** 61 | * 62 | * @author Tobiasz Cudnik 63 | */ 64 | class CallbackBody extends Callback { 65 | public function __construct($paramList, $code, $param1 = null, $param2 = null, 66 | $param3 = null) { 67 | $params = func_get_args(); 68 | $params = array_slice($params, 2); 69 | $this->callback = function($paramList){ 70 | return $code; 71 | }; 72 | $this->params = $params; 73 | } 74 | } 75 | /** 76 | * Callback type which on execution returns reference passed during creation. 77 | * 78 | * @author Tobiasz Cudnik 79 | */ 80 | class CallbackReturnReference extends Callback 81 | implements ICallbackNamed { 82 | protected $reference; 83 | public function __construct(&$reference, $name = null){ 84 | $this->reference =& $reference; 85 | $this->callback = array($this, 'callback'); 86 | } 87 | public function callback() { 88 | return $this->reference; 89 | } 90 | public function getName() { 91 | return 'Callback: '.$this->name; 92 | } 93 | public function hasName() { 94 | return isset($this->name) && $this->name; 95 | } 96 | } 97 | /** 98 | * Callback type which on execution returns value passed during creation. 99 | * 100 | * @author Tobiasz Cudnik 101 | */ 102 | class CallbackReturnValue extends Callback 103 | implements ICallbackNamed { 104 | protected $value; 105 | protected $name; 106 | public function __construct($value, $name = null){ 107 | $this->value =& $value; 108 | $this->name = $name; 109 | $this->callback = array($this, 'callback'); 110 | } 111 | public function callback() { 112 | return $this->value; 113 | } 114 | public function __toString() { 115 | return $this->getName(); 116 | } 117 | public function getName() { 118 | return 'Callback: '.$this->name; 119 | } 120 | public function hasName() { 121 | return isset($this->name) && $this->name; 122 | } 123 | } 124 | /** 125 | * CallbackParameterToReference can be used when we don't really want a callback, 126 | * only parameter passed to it. CallbackParameterToReference takes first 127 | * parameter's value and passes it to reference. 128 | * 129 | * @author Tobiasz Cudnik 130 | */ 131 | class CallbackParameterToReference extends Callback { 132 | /** 133 | * @param $reference 134 | * @TODO implement $paramIndex; 135 | * param index choose which callback param will be passed to reference 136 | */ 137 | public function __construct(&$reference){ 138 | $this->callback =& $reference; 139 | } 140 | } 141 | //class CallbackReference extends Callback { 142 | // /** 143 | // * 144 | // * @param $reference 145 | // * @param $paramIndex 146 | // * @todo implement $paramIndex; param index choose which callback param will be passed to reference 147 | // */ 148 | // public function __construct(&$reference, $name = null){ 149 | // $this->callback =& $reference; 150 | // } 151 | //} 152 | class CallbackParam {} 153 | -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/phpQuery/DOMEvent.php: -------------------------------------------------------------------------------- 1 | 8 | * @package phpQuery 9 | * @todo implement ArrayAccess ? 10 | */ 11 | class DOMEvent { 12 | /** 13 | * Returns a boolean indicating whether the event bubbles up through the DOM or not. 14 | * 15 | * @var unknown_type 16 | */ 17 | public $bubbles = true; 18 | /** 19 | * Returns a boolean indicating whether the event is cancelable. 20 | * 21 | * @var unknown_type 22 | */ 23 | public $cancelable = true; 24 | /** 25 | * Returns a reference to the currently registered target for the event. 26 | * 27 | * @var unknown_type 28 | */ 29 | public $currentTarget; 30 | /** 31 | * Returns detail about the event, depending on the type of event. 32 | * 33 | * @var unknown_type 34 | * @link http://developer.mozilla.org/en/DOM/event.detail 35 | */ 36 | public $detail; // ??? 37 | /** 38 | * Used to indicate which phase of the event flow is currently being evaluated. 39 | * 40 | * NOT IMPLEMENTED 41 | * 42 | * @var unknown_type 43 | * @link http://developer.mozilla.org/en/DOM/event.eventPhase 44 | */ 45 | public $eventPhase; // ??? 46 | /** 47 | * The explicit original target of the event (Mozilla-specific). 48 | * 49 | * NOT IMPLEMENTED 50 | * 51 | * @var unknown_type 52 | */ 53 | public $explicitOriginalTarget; // moz only 54 | /** 55 | * The original target of the event, before any retargetings (Mozilla-specific). 56 | * 57 | * NOT IMPLEMENTED 58 | * 59 | * @var unknown_type 60 | */ 61 | public $originalTarget; // moz only 62 | /** 63 | * Identifies a secondary target for the event. 64 | * 65 | * @var unknown_type 66 | */ 67 | public $relatedTarget; 68 | /** 69 | * Returns a reference to the target to which the event was originally dispatched. 70 | * 71 | * @var unknown_type 72 | */ 73 | public $target; 74 | /** 75 | * Returns the time that the event was created. 76 | * 77 | * @var unknown_type 78 | */ 79 | public $timeStamp; 80 | /** 81 | * Returns the name of the event (case-insensitive). 82 | */ 83 | public $type; 84 | public $runDefault = true; 85 | public $data = null; 86 | public function __construct($data) { 87 | foreach($data as $k => $v) { 88 | $this->$k = $v; 89 | } 90 | if (! $this->timeStamp) 91 | $this->timeStamp = time(); 92 | } 93 | /** 94 | * Cancels the event (if it is cancelable). 95 | * 96 | */ 97 | public function preventDefault() { 98 | $this->runDefault = false; 99 | } 100 | /** 101 | * Stops the propagation of events further along in the DOM. 102 | * 103 | */ 104 | public function stopPropagation() { 105 | $this->bubbles = false; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/phpQuery/Zend/Exception.php: -------------------------------------------------------------------------------- 1 | getUri(); 53 | } 54 | 55 | /** 56 | * Convenience function, checks that a $uri string is well-formed 57 | * by validating it but not returning an object. Returns TRUE if 58 | * $uri is a well-formed URI, or FALSE otherwise. 59 | * 60 | * @param string $uri The URI to check 61 | * @return boolean 62 | */ 63 | public static function check($uri) 64 | { 65 | try { 66 | $uri = self::factory($uri); 67 | } catch (Exception $e) { 68 | return false; 69 | } 70 | 71 | return $uri->valid(); 72 | } 73 | 74 | /** 75 | * Create a new Zend_Uri object for a URI. If building a new URI, then $uri should contain 76 | * only the scheme (http, ftp, etc). Otherwise, supply $uri with the complete URI. 77 | * 78 | * @param string $uri The URI form which a Zend_Uri instance is created 79 | * @throws Zend_Uri_Exception When an empty string was supplied for the scheme 80 | * @throws Zend_Uri_Exception When an illegal scheme is supplied 81 | * @throws Zend_Uri_Exception When the scheme is not supported 82 | * @return Zend_Uri 83 | * @link http://www.faqs.org/rfcs/rfc2396.html 84 | */ 85 | public static function factory($uri = 'http') 86 | { 87 | // Separate the scheme from the scheme-specific parts 88 | $uri = explode(':', $uri, 2); 89 | $scheme = strtolower($uri[0]); 90 | $schemeSpecific = isset($uri[1]) === true ? $uri[1] : ''; 91 | 92 | if (strlen($scheme) === 0) { 93 | require_once 'Zend/Uri/Exception.php'; 94 | throw new Zend_Uri_Exception('An empty string was supplied for the scheme'); 95 | } 96 | 97 | // Security check: $scheme is used to load a class file, so only alphanumerics are allowed. 98 | if (ctype_alnum($scheme) === false) { 99 | require_once 'Zend/Uri/Exception.php'; 100 | throw new Zend_Uri_Exception('Illegal scheme supplied, only alphanumeric characters are permitted'); 101 | } 102 | 103 | /** 104 | * Create a new Zend_Uri object for the $uri. If a subclass of Zend_Uri exists for the 105 | * scheme, return an instance of that class. Otherwise, a Zend_Uri_Exception is thrown. 106 | */ 107 | switch ($scheme) { 108 | case 'http': 109 | // Break intentionally omitted 110 | case 'https': 111 | $className = 'Zend_Uri_Http'; 112 | break; 113 | 114 | case 'mailto': 115 | // TODO 116 | default: 117 | require_once 'Zend/Uri/Exception.php'; 118 | throw new Zend_Uri_Exception("Scheme \"$scheme\" is not supported"); 119 | break; 120 | } 121 | 122 | Zend_Loader::loadClass($className); 123 | $schemeHandler = new $className($scheme, $schemeSpecific); 124 | 125 | return $schemeHandler; 126 | } 127 | 128 | /** 129 | * Get the URI's scheme 130 | * 131 | * @return string|false Scheme or false if no scheme is set. 132 | */ 133 | public function getScheme() 134 | { 135 | if (empty($this->_scheme) === false) { 136 | return $this->_scheme; 137 | } else { 138 | return false; 139 | } 140 | } 141 | 142 | /** 143 | * Zend_Uri and its subclasses cannot be instantiated directly. 144 | * Use Zend_Uri::factory() to return a new Zend_Uri object. 145 | * 146 | * @param string $scheme The scheme of the URI 147 | * @param string $schemeSpecific The scheme-specific part of the URI 148 | */ 149 | abstract protected function __construct($scheme, $schemeSpecific = ''); 150 | 151 | /** 152 | * Return a string representation of this URI. 153 | * 154 | * @return string 155 | */ 156 | abstract public function getUri(); 157 | 158 | /** 159 | * Returns TRUE if this URI is valid, or FALSE otherwise. 160 | * 161 | * @return boolean 162 | */ 163 | abstract public function valid(); 164 | } 165 | -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/phpQuery/Zend/Uri/Exception.php: -------------------------------------------------------------------------------- 1 | "'%value%' has not only alphabetic and digit characters", 69 | self::STRING_EMPTY => "'%value%' is an empty string" 70 | ); 71 | 72 | /** 73 | * Sets default option values for this instance 74 | * 75 | * @param boolean $allowWhiteSpace 76 | * @return void 77 | */ 78 | public function __construct($allowWhiteSpace = false) 79 | { 80 | $this->allowWhiteSpace = (boolean) $allowWhiteSpace; 81 | } 82 | 83 | /** 84 | * Defined by Zend_Validate_Interface 85 | * 86 | * Returns true if and only if $value contains only alphabetic and digit characters 87 | * 88 | * @param string $value 89 | * @return boolean 90 | */ 91 | public function isValid($value) 92 | { 93 | $valueString = (string) $value; 94 | 95 | $this->_setValue($valueString); 96 | 97 | if ('' === $valueString) { 98 | $this->_error(self::STRING_EMPTY); 99 | return false; 100 | } 101 | 102 | if (null === self::$_filter) { 103 | /** 104 | * @see Zend_Filter_Alnum 105 | */ 106 | require_once 'Zend/Filter/Alnum.php'; 107 | self::$_filter = new Zend_Filter_Alnum(); 108 | } 109 | 110 | self::$_filter->allowWhiteSpace = $this->allowWhiteSpace; 111 | 112 | if ($valueString !== self::$_filter->filter($valueString)) { 113 | $this->_error(self::NOT_ALNUM); 114 | return false; 115 | } 116 | 117 | return true; 118 | } 119 | 120 | } 121 | -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/phpQuery/Zend/Validate/Alpha.php: -------------------------------------------------------------------------------- 1 | "'%value%' has not only alphabetic characters", 69 | self::STRING_EMPTY => "'%value%' is an empty string" 70 | ); 71 | 72 | /** 73 | * Sets default option values for this instance 74 | * 75 | * @param boolean $allowWhiteSpace 76 | * @return void 77 | */ 78 | public function __construct($allowWhiteSpace = false) 79 | { 80 | $this->allowWhiteSpace = (boolean) $allowWhiteSpace; 81 | } 82 | 83 | /** 84 | * Defined by Zend_Validate_Interface 85 | * 86 | * Returns true if and only if $value contains only alphabetic characters 87 | * 88 | * @param string $value 89 | * @return boolean 90 | */ 91 | public function isValid($value) 92 | { 93 | $valueString = (string) $value; 94 | 95 | $this->_setValue($valueString); 96 | 97 | if ('' === $valueString) { 98 | $this->_error(self::STRING_EMPTY); 99 | return false; 100 | } 101 | 102 | if (null === self::$_filter) { 103 | /** 104 | * @see Zend_Filter_Alpha 105 | */ 106 | require_once 'Zend/Filter/Alpha.php'; 107 | self::$_filter = new Zend_Filter_Alpha(); 108 | } 109 | 110 | self::$_filter->allowWhiteSpace = $this->allowWhiteSpace; 111 | 112 | if ($valueString !== self::$_filter->filter($valueString)) { 113 | $this->_error(self::NOT_ALPHA); 114 | return false; 115 | } 116 | 117 | return true; 118 | } 119 | 120 | } 121 | -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/phpQuery/Zend/Validate/Barcode.php: -------------------------------------------------------------------------------- 1 | setType($barcodeType); 55 | } 56 | 57 | /** 58 | * Sets a new barcode validator 59 | * 60 | * @param string $barcodeType - Barcode validator to use 61 | * @return void 62 | * @throws Zend_Validate_Exception 63 | */ 64 | public function setType($barcodeType) 65 | { 66 | switch (strtolower($barcodeType)) { 67 | case 'upc': 68 | case 'upc-a': 69 | $className = 'UpcA'; 70 | break; 71 | case 'ean13': 72 | case 'ean-13': 73 | $className = 'Ean13'; 74 | break; 75 | default: 76 | require_once 'Zend/Validate/Exception.php'; 77 | throw new Zend_Validate_Exception("Barcode type '$barcodeType' is not supported'"); 78 | break; 79 | } 80 | 81 | require_once 'Zend/Validate/Barcode/' . $className . '.php'; 82 | 83 | $class = 'Zend_Validate_Barcode_' . $className; 84 | $this->_barcodeValidator = new $class; 85 | } 86 | 87 | /** 88 | * Defined by Zend_Validate_Interface 89 | * 90 | * Returns true if and only if $value contains a valid barcode 91 | * 92 | * @param string $value 93 | * @return boolean 94 | */ 95 | public function isValid($value) 96 | { 97 | return call_user_func(array($this->_barcodeValidator, 'isValid'), $value); 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/phpQuery/Zend/Validate/Barcode/Ean13.php: -------------------------------------------------------------------------------- 1 | "'%value%' is an invalid EAN-13 barcode", 57 | self::INVALID_LENGTH => "'%value%' should be 13 characters", 58 | ); 59 | 60 | /** 61 | * Defined by Zend_Validate_Interface 62 | * 63 | * Returns true if and only if $value contains a valid barcode 64 | * 65 | * @param string $value 66 | * @return boolean 67 | */ 68 | public function isValid($value) 69 | { 70 | $valueString = (string) $value; 71 | $this->_setValue($valueString); 72 | 73 | if (strlen($valueString) !== 13) { 74 | $this->_error(self::INVALID_LENGTH); 75 | return false; 76 | } 77 | 78 | $barcode = strrev(substr($valueString, 0, -1)); 79 | $oddSum = 0; 80 | $evenSum = 0; 81 | 82 | for ($i = 0; $i < 12; $i++) { 83 | if ($i % 2 === 0) { 84 | $oddSum += $barcode[$i] * 3; 85 | } elseif ($i % 2 === 1) { 86 | $evenSum += $barcode[$i]; 87 | } 88 | } 89 | 90 | $calculation = ($oddSum + $evenSum) % 10; 91 | $checksum = ($calculation === 0) ? 0 : 10 - $calculation; 92 | 93 | if ($valueString[12] != $checksum) { 94 | $this->_error(self::INVALID); 95 | return false; 96 | } 97 | 98 | return true; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/phpQuery/Zend/Validate/Barcode/UpcA.php: -------------------------------------------------------------------------------- 1 | "'%value%' is an invalid UPC-A barcode", 57 | self::INVALID_LENGTH => "'%value%' should be 12 characters", 58 | ); 59 | 60 | /** 61 | * Defined by Zend_Validate_Interface 62 | * 63 | * Returns true if and only if $value contains a valid barcode 64 | * 65 | * @param string $value 66 | * @return boolean 67 | */ 68 | public function isValid($value) 69 | { 70 | $valueString = (string) $value; 71 | $this->_setValue($valueString); 72 | 73 | if (strlen($valueString) !== 12) { 74 | $this->_error(self::INVALID_LENGTH); 75 | return false; 76 | } 77 | 78 | $barcode = substr($valueString, 0, -1); 79 | $oddSum = 0; 80 | $evenSum = 0; 81 | 82 | for ($i = 0; $i < 11; $i++) { 83 | if ($i % 2 === 0) { 84 | $oddSum += $barcode[$i] * 3; 85 | } elseif ($i % 2 === 1) { 86 | $evenSum += $barcode[$i]; 87 | } 88 | } 89 | 90 | $calculation = ($oddSum + $evenSum) % 10; 91 | $checksum = ($calculation === 0) ? 0 : 10 - $calculation; 92 | 93 | if ($valueString[11] != $checksum) { 94 | $this->_error(self::INVALID); 95 | return false; 96 | } 97 | 98 | return true; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/phpQuery/Zend/Validate/Between.php: -------------------------------------------------------------------------------- 1 | "'%value%' is not between '%min%' and '%max%', inclusively", 55 | self::NOT_BETWEEN_STRICT => "'%value%' is not strictly between '%min%' and '%max%'" 56 | ); 57 | 58 | /** 59 | * Additional variables available for validation failure messages 60 | * 61 | * @var array 62 | */ 63 | protected $_messageVariables = array( 64 | 'min' => '_min', 65 | 'max' => '_max' 66 | ); 67 | 68 | /** 69 | * Minimum value 70 | * 71 | * @var mixed 72 | */ 73 | protected $_min; 74 | 75 | /** 76 | * Maximum value 77 | * 78 | * @var mixed 79 | */ 80 | protected $_max; 81 | 82 | /** 83 | * Whether to do inclusive comparisons, allowing equivalence to min and/or max 84 | * 85 | * If false, then strict comparisons are done, and the value may equal neither 86 | * the min nor max options 87 | * 88 | * @var boolean 89 | */ 90 | protected $_inclusive; 91 | 92 | /** 93 | * Sets validator options 94 | * 95 | * @param mixed $min 96 | * @param mixed $max 97 | * @param boolean $inclusive 98 | * @return void 99 | */ 100 | public function __construct($min, $max, $inclusive = true) 101 | { 102 | $this->setMin($min) 103 | ->setMax($max) 104 | ->setInclusive($inclusive); 105 | } 106 | 107 | /** 108 | * Returns the min option 109 | * 110 | * @return mixed 111 | */ 112 | public function getMin() 113 | { 114 | return $this->_min; 115 | } 116 | 117 | /** 118 | * Sets the min option 119 | * 120 | * @param mixed $min 121 | * @return Zend_Validate_Between Provides a fluent interface 122 | */ 123 | public function setMin($min) 124 | { 125 | $this->_min = $min; 126 | return $this; 127 | } 128 | 129 | /** 130 | * Returns the max option 131 | * 132 | * @return mixed 133 | */ 134 | public function getMax() 135 | { 136 | return $this->_max; 137 | } 138 | 139 | /** 140 | * Sets the max option 141 | * 142 | * @param mixed $max 143 | * @return Zend_Validate_Between Provides a fluent interface 144 | */ 145 | public function setMax($max) 146 | { 147 | $this->_max = $max; 148 | return $this; 149 | } 150 | 151 | /** 152 | * Returns the inclusive option 153 | * 154 | * @return boolean 155 | */ 156 | public function getInclusive() 157 | { 158 | return $this->_inclusive; 159 | } 160 | 161 | /** 162 | * Sets the inclusive option 163 | * 164 | * @param boolean $inclusive 165 | * @return Zend_Validate_Between Provides a fluent interface 166 | */ 167 | public function setInclusive($inclusive) 168 | { 169 | $this->_inclusive = $inclusive; 170 | return $this; 171 | } 172 | 173 | /** 174 | * Defined by Zend_Validate_Interface 175 | * 176 | * Returns true if and only if $value is between min and max options, inclusively 177 | * if inclusive option is true. 178 | * 179 | * @param mixed $value 180 | * @return boolean 181 | */ 182 | public function isValid($value) 183 | { 184 | $this->_setValue($value); 185 | 186 | if ($this->_inclusive) { 187 | if ($this->_min > $value || $value > $this->_max) { 188 | $this->_error(self::NOT_BETWEEN); 189 | return false; 190 | } 191 | } else { 192 | if ($this->_min >= $value || $value >= $this->_max) { 193 | $this->_error(self::NOT_BETWEEN_STRICT); 194 | return false; 195 | } 196 | } 197 | return true; 198 | } 199 | 200 | } 201 | -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/phpQuery/Zend/Validate/Ccnum.php: -------------------------------------------------------------------------------- 1 | "'%value%' must contain between 13 and 19 digits", 62 | self::CHECKSUM => "Luhn algorithm (mod-10 checksum) failed on '%value%'" 63 | ); 64 | 65 | /** 66 | * Defined by Zend_Validate_Interface 67 | * 68 | * Returns true if and only if $value follows the Luhn algorithm (mod-10 checksum) 69 | * 70 | * @param string $value 71 | * @return boolean 72 | */ 73 | public function isValid($value) 74 | { 75 | $this->_setValue($value); 76 | 77 | if (null === self::$_filter) { 78 | /** 79 | * @see Zend_Filter_Digits 80 | */ 81 | require_once 'Zend/Filter/Digits.php'; 82 | self::$_filter = new Zend_Filter_Digits(); 83 | } 84 | 85 | $valueFiltered = self::$_filter->filter($value); 86 | 87 | $length = strlen($valueFiltered); 88 | 89 | if ($length < 13 || $length > 19) { 90 | $this->_error(self::LENGTH); 91 | return false; 92 | } 93 | 94 | $sum = 0; 95 | $weight = 2; 96 | 97 | for ($i = $length - 2; $i >= 0; $i--) { 98 | $digit = $weight * $valueFiltered[$i]; 99 | $sum += floor($digit / 10) + $digit % 10; 100 | $weight = $weight % 2 + 1; 101 | } 102 | 103 | if ((10 - $sum % 10) % 10 != $valueFiltered[$length - 1]) { 104 | $this->_error(self::CHECKSUM, $valueFiltered); 105 | return false; 106 | } 107 | 108 | return true; 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/phpQuery/Zend/Validate/Digits.php: -------------------------------------------------------------------------------- 1 | "'%value%' contains not only digit characters", 62 | self::STRING_EMPTY => "'%value%' is an empty string" 63 | ); 64 | 65 | /** 66 | * Defined by Zend_Validate_Interface 67 | * 68 | * Returns true if and only if $value only contains digit characters 69 | * 70 | * @param string $value 71 | * @return boolean 72 | */ 73 | public function isValid($value) 74 | { 75 | $valueString = (string) $value; 76 | 77 | $this->_setValue($valueString); 78 | 79 | if ('' === $valueString) { 80 | $this->_error(self::STRING_EMPTY); 81 | return false; 82 | } 83 | 84 | if (null === self::$_filter) { 85 | /** 86 | * @see Zend_Filter_Digits 87 | */ 88 | require_once 'Zend/Filter/Digits.php'; 89 | self::$_filter = new Zend_Filter_Digits(); 90 | } 91 | 92 | if ($valueString !== self::$_filter->filter($valueString)) { 93 | $this->_error(self::NOT_DIGITS); 94 | return false; 95 | } 96 | 97 | return true; 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/phpQuery/Zend/Validate/Exception.php: -------------------------------------------------------------------------------- 1 | "The file '%value%' does not exist" 47 | ); 48 | 49 | /** 50 | * Internal list of directories 51 | * @var string 52 | */ 53 | protected $_directory = ''; 54 | 55 | /** 56 | * @var array Error message template variables 57 | */ 58 | protected $_messageVariables = array( 59 | 'directory' => '_directory' 60 | ); 61 | 62 | /** 63 | * Sets validator options 64 | * 65 | * @param string|array $directory 66 | * @return void 67 | */ 68 | public function __construct($directory = array()) 69 | { 70 | $this->setDirectory($directory); 71 | } 72 | 73 | /** 74 | * Returns the set file directories which are checked 75 | * 76 | * @param boolean $asArray Returns the values as array, when false an concated string is returned 77 | * @return string 78 | */ 79 | public function getDirectory($asArray = false) 80 | { 81 | $asArray = (bool) $asArray; 82 | $directory = (string) $this->_directory; 83 | if ($asArray) { 84 | $directory = explode(',', $directory); 85 | } 86 | 87 | return $directory; 88 | } 89 | 90 | /** 91 | * Sets the file directory which will be checked 92 | * 93 | * @param string|array $directory The directories to validate 94 | * @return Zend_Validate_File_Extension Provides a fluent interface 95 | */ 96 | public function setDirectory($directory) 97 | { 98 | $this->_directory = null; 99 | $this->addDirectory($directory); 100 | return $this; 101 | } 102 | 103 | /** 104 | * Adds the file directory which will be checked 105 | * 106 | * @param string|array $directory The directory to add for validation 107 | * @return Zend_Validate_File_Extension Provides a fluent interface 108 | */ 109 | public function addDirectory($directory) 110 | { 111 | $directories = $this->getDirectory(true); 112 | if (is_string($directory)) { 113 | $directory = explode(',', $directory); 114 | } 115 | 116 | foreach ($directory as $content) { 117 | if (empty($content) || !is_string($content)) { 118 | continue; 119 | } 120 | 121 | $directories[] = trim($content); 122 | } 123 | $directories = array_unique($directories); 124 | 125 | // Sanity check to ensure no empty values 126 | foreach ($directories as $key => $dir) { 127 | if (empty($dir)) { 128 | unset($directories[$key]); 129 | } 130 | } 131 | 132 | $this->_directory = implode(',', $directories); 133 | 134 | return $this; 135 | } 136 | 137 | /** 138 | * Defined by Zend_Validate_Interface 139 | * 140 | * Returns true if and only if the file already exists in the set directories 141 | * 142 | * @param string $value Real file to check for existance 143 | * @param array $file File data from Zend_File_Transfer 144 | * @return boolean 145 | */ 146 | public function isValid($value, $file = null) 147 | { 148 | $directories = $this->getDirectory(true); 149 | if (($file !== null) and (!empty($file['destination']))) { 150 | $directories[] = $file['destination']; 151 | } else if (!isset($file['name'])) { 152 | $file['name'] = $value; 153 | } 154 | 155 | $check = false; 156 | foreach ($directories as $directory) { 157 | if (empty($directory)) { 158 | continue; 159 | } 160 | 161 | $check = true; 162 | if (!file_exists($directory . DIRECTORY_SEPARATOR . $file['name'])) { 163 | $this->_throw($file, self::DOES_NOT_EXIST); 164 | return false; 165 | } 166 | } 167 | 168 | if (!$check) { 169 | $this->_throw($file, self::DOES_NOT_EXIST); 170 | return false; 171 | } 172 | 173 | return true; 174 | } 175 | 176 | /** 177 | * Throws an error of the given type 178 | * 179 | * @param string $file 180 | * @param string $errorType 181 | * @return false 182 | */ 183 | protected function _throw($file, $errorType) 184 | { 185 | if ($file !== null) { 186 | $this->_value = $file['name']; 187 | } 188 | 189 | $this->_error($errorType); 190 | return false; 191 | } 192 | } 193 | -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/phpQuery/Zend/Validate/File/FilesSize.php: -------------------------------------------------------------------------------- 1 | "The files in sum exceed the maximum allowed size", 49 | self::TOO_SMALL => "All files are in sum smaller than required", 50 | self::NOT_READABLE => "One or more files can not be read" 51 | ); 52 | 53 | /** 54 | * @var array Error message template variables 55 | */ 56 | protected $_messageVariables = array( 57 | 'min' => '_min', 58 | 'max' => '_max' 59 | ); 60 | 61 | /** 62 | * Minimum filesize 63 | * 64 | * @var integer 65 | */ 66 | protected $_min; 67 | 68 | /** 69 | * Maximum filesize 70 | * 71 | * @var integer|null 72 | */ 73 | protected $_max; 74 | 75 | /** 76 | * Internal file array 77 | * 78 | * @var array 79 | */ 80 | protected $_files; 81 | 82 | /** 83 | * Internal file size counter 84 | * 85 | * @var integer 86 | */ 87 | protected $_size; 88 | 89 | /** 90 | * Sets validator options 91 | * 92 | * Min limits the used diskspace for all files, when used with max=null it is the maximum filesize 93 | * It also accepts an array with the keys 'min' and 'max' 94 | * 95 | * @param integer|array $min Minimum diskspace for all files 96 | * @param integer $max Maximum diskspace for all files 97 | * @return void 98 | */ 99 | public function __construct($min, $max = null) 100 | { 101 | $this->_files = array(); 102 | $this->_size = 0; 103 | parent::__construct($min, $max); 104 | } 105 | 106 | /** 107 | * Defined by Zend_Validate_Interface 108 | * 109 | * Returns true if and only if the disk usage of all files is at least min and 110 | * not bigger than max (when max is not null). 111 | * 112 | * @param string|array $value Real file to check for size 113 | * @param array $file File data from Zend_File_Transfer 114 | * @return boolean 115 | */ 116 | public function isValid($value, $file = null) 117 | { 118 | if (is_string($value)) { 119 | $value = array($value); 120 | } 121 | 122 | foreach ($value as $files) { 123 | // Is file readable ? 124 | if (!@is_readable($files)) { 125 | $this->_throw($file, self::NOT_READABLE); 126 | return false; 127 | } 128 | 129 | if (!isset($this->_files[$files])) { 130 | $this->_files[$files] = $files; 131 | } else { 132 | // file already counted... do not count twice 133 | continue; 134 | } 135 | 136 | // limited to 2GB files 137 | $size = @filesize($files); 138 | $this->_size += $size; 139 | $this->_setValue($this->_size); 140 | if (($this->_max !== null) && ($this->_max < $this->_size)) { 141 | $this->_throw($file, self::TOO_BIG); 142 | } 143 | } 144 | 145 | // Check that aggregate files are >= minimum size 146 | if (($this->_min !== null) && ($this->_size < $this->_min)) { 147 | $this->_throw($file, self::TOO_SMALL); 148 | } 149 | 150 | if (count($this->_messages) > 0) { 151 | return false; 152 | } else { 153 | return true; 154 | } 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/phpQuery/Zend/Validate/File/NotExists.php: -------------------------------------------------------------------------------- 1 | "The file '%value%' does exist" 47 | ); 48 | 49 | /** 50 | * Defined by Zend_Validate_Interface 51 | * 52 | * Returns true if and only if the file does not exist in the set destinations 53 | * 54 | * @param string $value Real file to check for 55 | * @param array $file File data from Zend_File_Transfer 56 | * @return boolean 57 | */ 58 | public function isValid($value, $file = null) 59 | { 60 | $directories = $this->getDirectory(true); 61 | if (($file !== null) and (!empty($file['destination']))) { 62 | $directories[] = $file['destination']; 63 | } else if (!isset($file['name'])) { 64 | $file['name'] = $value; 65 | } 66 | 67 | foreach ($directories as $directory) { 68 | if (empty($directory)) { 69 | continue; 70 | } 71 | 72 | $check = true; 73 | if (file_exists($directory . DIRECTORY_SEPARATOR . $file['name'])) { 74 | $this->_throw($file, self::DOES_EXIST); 75 | return false; 76 | } 77 | } 78 | 79 | if (!isset($check)) { 80 | $this->_throw($file, self::DOES_EXIST); 81 | return false; 82 | } 83 | 84 | return true; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/phpQuery/Zend/Validate/Float.php: -------------------------------------------------------------------------------- 1 | "'%value%' does not appear to be a float" 46 | ); 47 | 48 | /** 49 | * Defined by Zend_Validate_Interface 50 | * 51 | * Returns true if and only if $value is a floating-point value 52 | * 53 | * @param string $value 54 | * @return boolean 55 | */ 56 | public function isValid($value) 57 | { 58 | $valueString = (string) $value; 59 | 60 | $this->_setValue($valueString); 61 | 62 | $locale = localeconv(); 63 | 64 | $valueFiltered = str_replace($locale['thousands_sep'], '', $valueString); 65 | $valueFiltered = str_replace($locale['decimal_point'], '.', $valueFiltered); 66 | 67 | if (strval(floatval($valueFiltered)) != $valueFiltered) { 68 | $this->_error(); 69 | return false; 70 | } 71 | 72 | return true; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/phpQuery/Zend/Validate/GreaterThan.php: -------------------------------------------------------------------------------- 1 | "'%value%' is not greater than '%min%'" 46 | ); 47 | 48 | /** 49 | * @var array 50 | */ 51 | protected $_messageVariables = array( 52 | 'min' => '_min' 53 | ); 54 | 55 | /** 56 | * Minimum value 57 | * 58 | * @var mixed 59 | */ 60 | protected $_min; 61 | 62 | /** 63 | * Sets validator options 64 | * 65 | * @param mixed $min 66 | * @return void 67 | */ 68 | public function __construct($min) 69 | { 70 | $this->setMin($min); 71 | } 72 | 73 | /** 74 | * Returns the min option 75 | * 76 | * @return mixed 77 | */ 78 | public function getMin() 79 | { 80 | return $this->_min; 81 | } 82 | 83 | /** 84 | * Sets the min option 85 | * 86 | * @param mixed $min 87 | * @return Zend_Validate_GreaterThan Provides a fluent interface 88 | */ 89 | public function setMin($min) 90 | { 91 | $this->_min = $min; 92 | return $this; 93 | } 94 | 95 | /** 96 | * Defined by Zend_Validate_Interface 97 | * 98 | * Returns true if and only if $value is greater than min option 99 | * 100 | * @param mixed $value 101 | * @return boolean 102 | */ 103 | public function isValid($value) 104 | { 105 | $this->_setValue($value); 106 | 107 | if ($this->_min >= $value) { 108 | $this->_error(); 109 | return false; 110 | } 111 | return true; 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/phpQuery/Zend/Validate/Hex.php: -------------------------------------------------------------------------------- 1 | "'%value%' has not only hexadecimal digit characters" 50 | ); 51 | 52 | /** 53 | * Defined by Zend_Validate_Interface 54 | * 55 | * Returns true if and only if $value contains only hexadecimal digit characters 56 | * 57 | * @param string $value 58 | * @return boolean 59 | */ 60 | public function isValid($value) 61 | { 62 | $valueString = (string) $value; 63 | 64 | $this->_setValue($valueString); 65 | 66 | if (!ctype_xdigit($valueString)) { 67 | $this->_error(); 68 | return false; 69 | } 70 | 71 | return true; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/phpQuery/Zend/Validate/Hostname/At.php: -------------------------------------------------------------------------------- 1 | 'Tokens do not match', 47 | self::MISSING_TOKEN => 'No token was provided to match against', 48 | ); 49 | 50 | /** 51 | * Original token against which to validate 52 | * @var string 53 | */ 54 | protected $_token; 55 | 56 | /** 57 | * Sets validator options 58 | * 59 | * @param string $token 60 | * @return void 61 | */ 62 | public function __construct($token = null) 63 | { 64 | if (null !== $token) { 65 | $this->setToken($token); 66 | } 67 | } 68 | 69 | /** 70 | * Set token against which to compare 71 | * 72 | * @param string $token 73 | * @return Zend_Validate_Identical 74 | */ 75 | public function setToken($token) 76 | { 77 | $this->_token = (string) $token; 78 | return $this; 79 | } 80 | 81 | /** 82 | * Retrieve token 83 | * 84 | * @return string 85 | */ 86 | public function getToken() 87 | { 88 | return $this->_token; 89 | } 90 | 91 | /** 92 | * Defined by Zend_Validate_Interface 93 | * 94 | * Returns true if and only if a token has been set and the provided value 95 | * matches that token. 96 | * 97 | * @param string $value 98 | * @return boolean 99 | */ 100 | public function isValid($value) 101 | { 102 | $this->_setValue($value); 103 | $token = $this->getToken(); 104 | 105 | if (empty($token)) { 106 | $this->_error(self::MISSING_TOKEN); 107 | return false; 108 | } 109 | 110 | if ($value !== $token) { 111 | $this->_error(self::NOT_SAME); 112 | return false; 113 | } 114 | 115 | return true; 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/phpQuery/Zend/Validate/InArray.php: -------------------------------------------------------------------------------- 1 | "'%value%' was not found in the haystack" 46 | ); 47 | 48 | /** 49 | * Haystack of possible values 50 | * 51 | * @var array 52 | */ 53 | protected $_haystack; 54 | 55 | /** 56 | * Whether a strict in_array() invocation is used 57 | * 58 | * @var boolean 59 | */ 60 | protected $_strict; 61 | 62 | /** 63 | * Sets validator options 64 | * 65 | * @param array $haystack 66 | * @param boolean $strict 67 | * @return void 68 | */ 69 | public function __construct(array $haystack, $strict = false) 70 | { 71 | $this->setHaystack($haystack) 72 | ->setStrict($strict); 73 | } 74 | 75 | /** 76 | * Returns the haystack option 77 | * 78 | * @return mixed 79 | */ 80 | public function getHaystack() 81 | { 82 | return $this->_haystack; 83 | } 84 | 85 | /** 86 | * Sets the haystack option 87 | * 88 | * @param mixed $haystack 89 | * @return Zend_Validate_InArray Provides a fluent interface 90 | */ 91 | public function setHaystack(array $haystack) 92 | { 93 | $this->_haystack = $haystack; 94 | return $this; 95 | } 96 | 97 | /** 98 | * Returns the strict option 99 | * 100 | * @return boolean 101 | */ 102 | public function getStrict() 103 | { 104 | return $this->_strict; 105 | } 106 | 107 | /** 108 | * Sets the strict option 109 | * 110 | * @param boolean $strict 111 | * @return Zend_Validate_InArray Provides a fluent interface 112 | */ 113 | public function setStrict($strict) 114 | { 115 | $this->_strict = $strict; 116 | return $this; 117 | } 118 | 119 | /** 120 | * Defined by Zend_Validate_Interface 121 | * 122 | * Returns true if and only if $value is contained in the haystack option. If the strict 123 | * option is true, then the type of $value is also checked. 124 | * 125 | * @param mixed $value 126 | * @return boolean 127 | */ 128 | public function isValid($value) 129 | { 130 | $this->_setValue($value); 131 | if (!in_array($value, $this->_haystack, $this->_strict)) { 132 | $this->_error(); 133 | return false; 134 | } 135 | return true; 136 | } 137 | 138 | } 139 | -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/phpQuery/Zend/Validate/Int.php: -------------------------------------------------------------------------------- 1 | "'%value%' does not appear to be an integer" 46 | ); 47 | 48 | /** 49 | * Defined by Zend_Validate_Interface 50 | * 51 | * Returns true if and only if $value is a valid integer 52 | * 53 | * @param string $value 54 | * @return boolean 55 | */ 56 | public function isValid($value) 57 | { 58 | $valueString = (string) $value; 59 | 60 | $this->_setValue($valueString); 61 | 62 | $locale = localeconv(); 63 | 64 | $valueFiltered = str_replace($locale['decimal_point'], '.', $valueString); 65 | $valueFiltered = str_replace($locale['thousands_sep'], '', $valueFiltered); 66 | 67 | if (strval(intval($valueFiltered)) != $valueFiltered) { 68 | $this->_error(); 69 | return false; 70 | } 71 | 72 | return true; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/phpQuery/Zend/Validate/Interface.php: -------------------------------------------------------------------------------- 1 | "'%value%' does not appear to be a valid IP address" 46 | ); 47 | 48 | /** 49 | * Defined by Zend_Validate_Interface 50 | * 51 | * Returns true if and only if $value is a valid IP address 52 | * 53 | * @param mixed $value 54 | * @return boolean 55 | */ 56 | public function isValid($value) 57 | { 58 | $valueString = (string) $value; 59 | 60 | $this->_setValue($valueString); 61 | 62 | if (ip2long($valueString) === false) { 63 | $this->_error(); 64 | return false; 65 | } 66 | 67 | return true; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/phpQuery/Zend/Validate/LessThan.php: -------------------------------------------------------------------------------- 1 | "'%value%' is not less than '%max%'" 46 | ); 47 | 48 | /** 49 | * @var array 50 | */ 51 | protected $_messageVariables = array( 52 | 'max' => '_max' 53 | ); 54 | 55 | /** 56 | * Maximum value 57 | * 58 | * @var mixed 59 | */ 60 | protected $_max; 61 | 62 | /** 63 | * Sets validator options 64 | * 65 | * @param mixed $max 66 | * @return void 67 | */ 68 | public function __construct($max) 69 | { 70 | $this->setMax($max); 71 | } 72 | 73 | /** 74 | * Returns the max option 75 | * 76 | * @return mixed 77 | */ 78 | public function getMax() 79 | { 80 | return $this->_max; 81 | } 82 | 83 | /** 84 | * Sets the max option 85 | * 86 | * @param mixed $max 87 | * @return Zend_Validate_LessThan Provides a fluent interface 88 | */ 89 | public function setMax($max) 90 | { 91 | $this->_max = $max; 92 | return $this; 93 | } 94 | 95 | /** 96 | * Defined by Zend_Validate_Interface 97 | * 98 | * Returns true if and only if $value is less than max option 99 | * 100 | * @param mixed $value 101 | * @return boolean 102 | */ 103 | public function isValid($value) 104 | { 105 | $this->_setValue($value); 106 | if ($this->_max <= $value) { 107 | $this->_error(); 108 | return false; 109 | } 110 | return true; 111 | } 112 | 113 | } 114 | -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/phpQuery/Zend/Validate/NotEmpty.php: -------------------------------------------------------------------------------- 1 | "Value is empty, but a non-empty value is required" 46 | ); 47 | 48 | /** 49 | * Defined by Zend_Validate_Interface 50 | * 51 | * Returns true if and only if $value is not an empty value. 52 | * 53 | * @param string $value 54 | * @return boolean 55 | */ 56 | public function isValid($value) 57 | { 58 | $this->_setValue((string) $value); 59 | 60 | if (is_string($value) 61 | && (('' === $value) 62 | || preg_match('/^\s+$/s', $value)) 63 | ) { 64 | $this->_error(); 65 | return false; 66 | } elseif (!is_string($value) && empty($value)) { 67 | $this->_error(); 68 | return false; 69 | } 70 | 71 | return true; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/phpQuery/Zend/Validate/Regex.php: -------------------------------------------------------------------------------- 1 | "'%value%' does not match against pattern '%pattern%'" 46 | ); 47 | 48 | /** 49 | * @var array 50 | */ 51 | protected $_messageVariables = array( 52 | 'pattern' => '_pattern' 53 | ); 54 | 55 | /** 56 | * Regular expression pattern 57 | * 58 | * @var string 59 | */ 60 | protected $_pattern; 61 | 62 | /** 63 | * Sets validator options 64 | * 65 | * @param string $pattern 66 | * @return void 67 | */ 68 | public function __construct($pattern) 69 | { 70 | $this->setPattern($pattern); 71 | } 72 | 73 | /** 74 | * Returns the pattern option 75 | * 76 | * @return string 77 | */ 78 | public function getPattern() 79 | { 80 | return $this->_pattern; 81 | } 82 | 83 | /** 84 | * Sets the pattern option 85 | * 86 | * @param string $pattern 87 | * @return Zend_Validate_Regex Provides a fluent interface 88 | */ 89 | public function setPattern($pattern) 90 | { 91 | $this->_pattern = (string) $pattern; 92 | return $this; 93 | } 94 | 95 | /** 96 | * Defined by Zend_Validate_Interface 97 | * 98 | * Returns true if and only if $value matches against the pattern option 99 | * 100 | * @param string $value 101 | * @throws Zend_Validate_Exception if there is a fatal error in pattern matching 102 | * @return boolean 103 | */ 104 | public function isValid($value) 105 | { 106 | $valueString = (string) $value; 107 | 108 | $this->_setValue($valueString); 109 | 110 | $status = @preg_match($this->_pattern, $valueString); 111 | if (false === $status) { 112 | /** 113 | * @see Zend_Validate_Exception 114 | */ 115 | require_once 'Zend/Validate/Exception.php'; 116 | throw new Zend_Validate_Exception("Internal error matching pattern '$this->_pattern' against value '$valueString'"); 117 | } 118 | if (!$status) { 119 | $this->_error(); 120 | return false; 121 | } 122 | return true; 123 | } 124 | 125 | } 126 | -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/phpQuery/Zend/Validate/StringLength.php: -------------------------------------------------------------------------------- 1 | "'%value%' is less than %min% characters long", 47 | self::TOO_LONG => "'%value%' is greater than %max% characters long" 48 | ); 49 | 50 | /** 51 | * @var array 52 | */ 53 | protected $_messageVariables = array( 54 | 'min' => '_min', 55 | 'max' => '_max' 56 | ); 57 | 58 | /** 59 | * Minimum length 60 | * 61 | * @var integer 62 | */ 63 | protected $_min; 64 | 65 | /** 66 | * Maximum length 67 | * 68 | * If null, there is no maximum length 69 | * 70 | * @var integer|null 71 | */ 72 | protected $_max; 73 | 74 | /** 75 | * Sets validator options 76 | * 77 | * @param integer $min 78 | * @param integer $max 79 | * @return void 80 | */ 81 | public function __construct($min = 0, $max = null) 82 | { 83 | $this->setMin($min); 84 | $this->setMax($max); 85 | } 86 | 87 | /** 88 | * Returns the min option 89 | * 90 | * @return integer 91 | */ 92 | public function getMin() 93 | { 94 | return $this->_min; 95 | } 96 | 97 | /** 98 | * Sets the min option 99 | * 100 | * @param integer $min 101 | * @throws Zend_Validate_Exception 102 | * @return Zend_Validate_StringLength Provides a fluent interface 103 | */ 104 | public function setMin($min) 105 | { 106 | if (null !== $this->_max && $min > $this->_max) { 107 | /** 108 | * @see Zend_Validate_Exception 109 | */ 110 | require_once 'Zend/Validate/Exception.php'; 111 | throw new Zend_Validate_Exception("The minimum must be less than or equal to the maximum length, but $min >" 112 | . " $this->_max"); 113 | } 114 | $this->_min = max(0, (integer) $min); 115 | return $this; 116 | } 117 | 118 | /** 119 | * Returns the max option 120 | * 121 | * @return integer|null 122 | */ 123 | public function getMax() 124 | { 125 | return $this->_max; 126 | } 127 | 128 | /** 129 | * Sets the max option 130 | * 131 | * @param integer|null $max 132 | * @throws Zend_Validate_Exception 133 | * @return Zend_Validate_StringLength Provides a fluent interface 134 | */ 135 | public function setMax($max) 136 | { 137 | if (null === $max) { 138 | $this->_max = null; 139 | } else if ($max < $this->_min) { 140 | /** 141 | * @see Zend_Validate_Exception 142 | */ 143 | require_once 'Zend/Validate/Exception.php'; 144 | throw new Zend_Validate_Exception("The maximum must be greater than or equal to the minimum length, but " 145 | . "$max < $this->_min"); 146 | } else { 147 | $this->_max = (integer) $max; 148 | } 149 | 150 | return $this; 151 | } 152 | 153 | /** 154 | * Defined by Zend_Validate_Interface 155 | * 156 | * Returns true if and only if the string length of $value is at least the min option and 157 | * no greater than the max option (when the max option is not null). 158 | * 159 | * @param string $value 160 | * @return boolean 161 | */ 162 | public function isValid($value) 163 | { 164 | $valueString = (string) $value; 165 | $this->_setValue($valueString); 166 | $length = iconv_strlen($valueString); 167 | if ($length < $this->_min) { 168 | $this->_error(self::TOO_SHORT); 169 | } 170 | if (null !== $this->_max && $this->_max < $length) { 171 | $this->_error(self::TOO_LONG); 172 | } 173 | if (count($this->_messages)) { 174 | return false; 175 | } else { 176 | return true; 177 | } 178 | } 179 | 180 | } 181 | -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/phpQuery/bootstrap.example.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/phpQuery/compat/mbstring.php: -------------------------------------------------------------------------------- 1 | document) 33 | $pq->find('*')->add($pq->document) 34 | ->trigger($type, $data); 35 | } 36 | } else { 37 | if (isset($data[0]) && $data[0] instanceof DOMEvent) { 38 | $event = $data[0]; 39 | $event->relatedTarget = $event->target; 40 | $event->target = $node; 41 | $data = array_slice($data, 1); 42 | } else { 43 | $event = new DOMEvent(array( 44 | 'type' => $type, 45 | 'target' => $node, 46 | 'timeStamp' => time(), 47 | )); 48 | } 49 | $i = 0; 50 | while($node) { 51 | // TODO whois 52 | phpQuery::debug("Triggering ".($i?"bubbled ":'')."event '{$type}' on " 53 | ."node \n");//.phpQueryObject::whois($node)."\n"); 54 | $event->currentTarget = $node; 55 | $eventNode = self::getNode($documentID, $node); 56 | if (isset($eventNode->eventHandlers)) { 57 | foreach($eventNode->eventHandlers as $eventType => $handlers) { 58 | $eventNamespace = null; 59 | if (strpos($type, '.') !== false) 60 | list($eventName, $eventNamespace) = explode('.', $eventType); 61 | else 62 | $eventName = $eventType; 63 | if ($name != $eventName) 64 | continue; 65 | if ($namespace && $eventNamespace && $namespace != $eventNamespace) 66 | continue; 67 | foreach($handlers as $handler) { 68 | phpQuery::debug("Calling event handler\n"); 69 | $event->data = $handler['data'] 70 | ? $handler['data'] 71 | : null; 72 | $params = array_merge(array($event), $data); 73 | $return = phpQuery::callbackRun($handler['callback'], $params); 74 | if ($return === false) { 75 | $event->bubbles = false; 76 | } 77 | } 78 | } 79 | } 80 | // to bubble or not to bubble... 81 | if (! $event->bubbles) 82 | break; 83 | $node = $node->parentNode; 84 | $i++; 85 | } 86 | } 87 | } 88 | /** 89 | * Binds a handler to one or more events (like click) for each matched element. 90 | * Can also bind custom events. 91 | * 92 | * @param DOMNode|phpQueryObject|string $document 93 | * @param unknown_type $type 94 | * @param unknown_type $data Optional 95 | * @param unknown_type $callback 96 | * 97 | * @TODO support '!' (exclusive) events 98 | * @TODO support more than event in $type (space-separated) 99 | * @TODO support binding to global events 100 | */ 101 | public static function add($document, $node, $type, $data, $callback = null) { 102 | phpQuery::debug("Binding '$type' event"); 103 | $documentID = phpQuery::getDocumentID($document); 104 | // if (is_null($callback) && is_callable($data)) { 105 | // $callback = $data; 106 | // $data = null; 107 | // } 108 | $eventNode = self::getNode($documentID, $node); 109 | if (! $eventNode) 110 | $eventNode = self::setNode($documentID, $node); 111 | if (!isset($eventNode->eventHandlers[$type])) 112 | $eventNode->eventHandlers[$type] = array(); 113 | $eventNode->eventHandlers[$type][] = array( 114 | 'callback' => $callback, 115 | 'data' => $data, 116 | ); 117 | } 118 | /** 119 | * Enter description here... 120 | * 121 | * @param DOMNode|phpQueryObject|string $document 122 | * @param unknown_type $type 123 | * @param unknown_type $callback 124 | * 125 | * @TODO namespace events 126 | * @TODO support more than event in $type (space-separated) 127 | */ 128 | public static function remove($document, $node, $type = null, $callback = null) { 129 | $documentID = phpQuery::getDocumentID($document); 130 | $eventNode = self::getNode($documentID, $node); 131 | if (is_object($eventNode) && isset($eventNode->eventHandlers[$type])) { 132 | if ($callback) { 133 | foreach($eventNode->eventHandlers[$type] as $k => $handler) 134 | if ($handler['callback'] == $callback) 135 | unset($eventNode->eventHandlers[$type][$k]); 136 | } else { 137 | unset($eventNode->eventHandlers[$type]); 138 | } 139 | } 140 | } 141 | protected static function getNode($documentID, $node) { 142 | foreach(phpQuery::$documents[$documentID]->eventsNodes as $eventNode) { 143 | if ($node->isSameNode($eventNode)) 144 | return $eventNode; 145 | } 146 | } 147 | protected static function setNode($documentID, $node) { 148 | phpQuery::$documents[$documentID]->eventsNodes[] = $node; 149 | return phpQuery::$documents[$documentID]->eventsNodes[ 150 | count(phpQuery::$documents[$documentID]->eventsNodes)-1 151 | ]; 152 | } 153 | protected static function issetGlobal($documentID, $type) { 154 | return isset(phpQuery::$documents[$documentID]) 155 | ? in_array($type, phpQuery::$documents[$documentID]->eventsGlobal) 156 | : false; 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/phpQuery/plugins/Scripts.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/phpQuery/plugins/Scripts/__config.example.php: -------------------------------------------------------------------------------- 1 | array('login@mail', 'password'), 9 | ); 10 | ?> -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/phpQuery/plugins/Scripts/example.php: -------------------------------------------------------------------------------- 1 | find($params[0]); 14 | ?> -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/phpQuery/plugins/Scripts/fix_webroot.php: -------------------------------------------------------------------------------- 1 | filter($filter) as $el) { 9 | $el = pq($el, $self->getDocumentID()); 10 | // imgs and scripts 11 | if ( $el->is('img') || $el->is('script') ) 12 | $el->attr('src', $params[0].$el->attr('src')); 13 | // css 14 | if ( $el->is('link') ) 15 | $el->attr('href', $params[0].$el->attr('href')); 16 | } -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/phpQuery/plugins/Scripts/google_login.php: -------------------------------------------------------------------------------- 1 | 8 | */ 9 | phpQuery::ajaxAllowHost( 10 | 'code.google.com', 11 | 'google.com', 'www.google.com', 12 | 'mail.google.com', 13 | 'docs.google.com', 14 | 'reader.google.com' 15 | ); 16 | if (! function_exists('ndfasui8923')) { 17 | function ndfasui8923($browser, $scope) { 18 | extract($scope); 19 | $browser 20 | ->WebBrowser() 21 | ->find('#Email') 22 | ->val($config['google_login'][0])->end() 23 | ->find('#Passwd') 24 | ->val($config['google_login'][1]) 25 | ->parents('form') 26 | ->submit(); 27 | } 28 | $ndfasui8923 = new Callback('ndfasui8923', new CallbackParam, compact( 29 | 'config', 'self', 'return', 'params' 30 | )); 31 | } 32 | phpQuery::plugin('WebBrowser'); 33 | $self->document->xhr = phpQuery::$plugins->browserGet( 34 | 'https://www.google.com/accounts/Login', 35 | $ndfasui8923 36 | ); 37 | //$self->document->xhr = phpQuery::$plugins->browserGet('https://www.google.com/accounts/Login', create_function('$browser', " 38 | // \$browser 39 | // ->WebBrowser() 40 | // ->find('#Email') 41 | // ->val('{$config['google_login'][0]}')->end() 42 | // ->find('#Passwd') 43 | // ->val('".str_replace("'", "\\'", $config['google_login'][1])."') 44 | // ->parents('form') 45 | // ->submit();" 46 | //)); 47 | ?> -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/phpQuery/plugins/Scripts/print_source.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | /** @var phpQueryObject */ 8 | $self = $self; 9 | $return = htmlspecialchars($self); -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/phpQuery/plugins/Scripts/print_websafe.php: -------------------------------------------------------------------------------- 1 | 6 | */ 7 | /** @var phpQueryObject */ 8 | $self = $self; 9 | $self 10 | ->find('script') 11 | ->add('meta[http-equiv=refresh]') 12 | ->add('meta[http-equiv=Refresh]') 13 | ->remove(); -------------------------------------------------------------------------------- /src/Kernel/Library/phpQuery/phpQuery/plugins/example.php: -------------------------------------------------------------------------------- 1 | plugin('example') 9 | * pq('ul')->plugin('example', 'example.php') 10 | * 11 | * Plugin classes are never intialized, just method calls are forwarded 12 | * in static way from phpQuery. 13 | * 14 | * Have fun writing plugins :) 15 | */ 16 | 17 | /** 18 | * phpQuery plugin class extending phpQuery object. 19 | * Methods from this class are callable on every phpQuery object. 20 | * 21 | * Class name prefix 'phpQueryObjectPlugin_' must be preserved. 22 | */ 23 | abstract class phpQueryObjectPlugin_example { 24 | /** 25 | * Limit binded methods. 26 | * 27 | * null means all public. 28 | * array means only specified ones. 29 | * 30 | * @var array|null 31 | */ 32 | public static $phpQueryMethods = null; 33 | /** 34 | * Enter description here... 35 | * 36 | * @param phpQueryObject $self 37 | */ 38 | public static function example($self, $arg1) { 39 | // this method can be called on any phpQuery object, like this: 40 | // pq('div')->example('$arg1 Value') 41 | 42 | // do something 43 | $self->append('Im just an example !'); 44 | // change stack of result object 45 | return $self->find('div'); 46 | } 47 | protected static function helperFunction() { 48 | // this method WONT be avaible as phpQuery method, 49 | // because it isn't publicly callable 50 | } 51 | } 52 | 53 | /** 54 | * phpQuery plugin class extending phpQuery static namespace. 55 | * Methods from this class are callable as follows: 56 | * phpQuery::$plugins->staticMethod() 57 | * 58 | * Class name prefix 'phpQueryPlugin_' must be preserved. 59 | */ 60 | abstract class phpQueryPlugin_example { 61 | /** 62 | * Limit binded methods. 63 | * 64 | * null means all public. 65 | * array means only specified ones. 66 | * 67 | * @var array|null 68 | */ 69 | public static $phpQueryMethods = null; 70 | public static function staticMethod() { 71 | // this method can be called within phpQuery class namespace, like this: 72 | // phpQuery::$plugins->staticMethod() 73 | } 74 | } 75 | ?> -------------------------------------------------------------------------------- /src/Kernel/Middleware/DropDuplicate/BloomFilterLocal.php: -------------------------------------------------------------------------------- 1 | 6 | * @version 1.0.0 7 | * @modify 2019-10-30 8 | */ 9 | namespace PHPCreeper\Kernel\Middleware\DropDuplicate; 10 | 11 | use PHPCreeper\Kernel\Slot\BloomInterface; 12 | 13 | class BloomFilterLocal implements DropDuplicateInterface 14 | { 15 | /** 16 | * element size 17 | * 18 | * @var int 19 | */ 20 | private $n = 0; 21 | 22 | /** 23 | * vector bits 24 | * 25 | * @var int 26 | */ 27 | private $m; 28 | 29 | /** 30 | * hash count 31 | * 32 | * @var int 33 | */ 34 | private $k; 35 | 36 | /** 37 | * hash algorithm 38 | * 39 | * @var string 40 | */ 41 | private $hash; 42 | 43 | /** 44 | * mask 45 | * 46 | * @var int 47 | */ 48 | private $mask; 49 | 50 | /** 51 | * chunk size 52 | * 53 | * @var int 54 | */ 55 | private $chunk_size; 56 | 57 | /** 58 | * bit_array 59 | * 60 | * @var int 61 | */ 62 | private $bit_array; 63 | 64 | /** 65 | * @brief __construct 66 | * 67 | * @param int $m 68 | * @param int $k 69 | * @param string $h 70 | * 71 | * @return void 72 | */ 73 | public function __construct($m = 1048576, $k = 3, $h = 'md5') 74 | { 75 | if($m < 8) 76 | { 77 | throw new \Exception('The bit array length must be at least 8 bits.'); 78 | } 79 | 80 | if(($m & ($m - 1)) !== 0) 81 | { 82 | throw new \Exception('The bit array length must be power of 2.'); 83 | } 84 | 85 | if($m > 8589934592) 86 | { 87 | throw new \Exception('The maximum data structure size is 1GB.'); 88 | } 89 | 90 | $this->m = $m; 91 | $this->k = $k; 92 | $this->hash = $h; 93 | $address_bits = (int)log($m, 2); 94 | $this->mask = (1 << $address_bits) - 8; 95 | $this->chunk_size = (int)ceil($address_bits / 8); 96 | $this->hash_times = ((int)ceil($this->chunk_size * $this->k / strlen(hash($this->hash, null, true)))) - 1; 97 | $this->bit_array = (binary)(str_repeat("\0", $this->getSize(true))); 98 | } 99 | 100 | /** 101 | * @brief calculateProbability 102 | * 103 | * @param int $n 104 | * 105 | * @return number 106 | */ 107 | public function calculateProbability($n = 0) 108 | { 109 | return pow(1 - pow(1 - 1 / $this->m, $this->k * ($n ?: $this->n)), $this->k); 110 | } 111 | 112 | /** 113 | * @brief calculateCapacity 114 | * 115 | * @param int $p 116 | * 117 | * @return float 118 | */ 119 | public function calculateCapacity($p) 120 | { 121 | return floor($this->m * log(2) / log($p, 1 - pow(1 - 1/$this->m, $this->m * log(2)))); 122 | } 123 | 124 | /** 125 | * @brief getElementCount 126 | * 127 | * @return int 128 | */ 129 | public function getElementCount() 130 | { 131 | return $this->n; 132 | } 133 | 134 | /** 135 | * @brief getSize 136 | * 137 | * @param boolean $bytes 138 | * 139 | * @return int 140 | */ 141 | public function getSize($bytes = false) 142 | { 143 | return $this->m >> ($bytes ? 3 : 0); 144 | } 145 | 146 | /** 147 | * @brief getHashCount 148 | * 149 | * @return int 150 | */ 151 | public function getHashCount() 152 | { 153 | return $this->k; 154 | } 155 | 156 | /** 157 | * @brief report 158 | * 159 | * @param int $p 160 | * 161 | * @return string 162 | */ 163 | public function report($p = null) 164 | { 165 | $units = array('','K','M','G','T','P','E','Z','Y'); 166 | $size = $this->getSize(true); 167 | $magnitude = intval(floor(log($size,1024))); 168 | $unit = $units[$magnitude]; 169 | $size /= pow(1024,$magnitude); 170 | 171 | return 'Allocated '.$this->getSize().' bits ('.$size.' '.$unit.'Bytes)'.PHP_EOL. 172 | 'Using '.$this->getHashCount(). ' ('.($this->chunk_size << 3).'b) hashes'.PHP_EOL. 173 | 'Contains '.$this->getElementCount().' elements'.PHP_EOL. 174 | (isset($p) ? 'Capacity of '.number_format($this->calculateCapacity($p)).' (p='.$p.')'.PHP_EOL : ''); 175 | } 176 | 177 | /** 178 | * @brief add element 179 | * 180 | * @param string $key 181 | * 182 | * @return void 183 | */ 184 | public function add($key) 185 | { 186 | $hash = hash($this->hash, $key, true); 187 | 188 | for($i = 0; $i < $this->hash_times; $i++) 189 | { 190 | $hash .= hash($this->hash, $hash, true); 191 | } 192 | 193 | for($index = 0; $index < $this->k; $index++) 194 | { 195 | $hash_sub = hexdec(unpack('H*',substr($hash,$index * $this->chunk_size, $this->chunk_size))[1]); 196 | $word = ($hash_sub & $this->mask) >> 3; 197 | $this->bit_array[$word] = $this->bit_array[$word] | chr(1 << ($hash_sub & 7)); 198 | } 199 | 200 | $this->n++; 201 | } 202 | 203 | /** 204 | * @brief check whether element exists in bit array or not 205 | * 206 | * @param string $key 207 | * 208 | * @return boolean 209 | */ 210 | public function has($key) 211 | { 212 | $hash = hash($this->hash,$key,true); 213 | for($i = 0; $i < $this->hash_times; $i++) 214 | { 215 | $hash .= hash($this->hash,$hash,true); 216 | } 217 | 218 | for($index = 0; $index < $this->k; $index++) 219 | { 220 | $hash_sub = hexdec(unpack('H*',substr($hash,$index*$this->chunk_size,$this->chunk_size))[1]); 221 | if((ord($this->bit_array[($hash_sub & $this->mask) >> 3]) & (1 << ($hash_sub & 7))) === 0) return false; 222 | } 223 | 224 | return true; 225 | } 226 | 227 | } 228 | 229 | 230 | 231 | 232 | -------------------------------------------------------------------------------- /src/Kernel/Middleware/HttpClient/Curl.php: -------------------------------------------------------------------------------- 1 | 6 | * @version 1.0.0 7 | * @modify 2019-11-06 8 | */ 9 | 10 | namespace PHPCreeper\Kernel\Middleware\LockManager; 11 | 12 | use PHPCreeper\Kernel\Slot\LockInterface; 13 | 14 | class FileLock implements LockInterface 15 | { 16 | //file path where to store lock 17 | private $path = null; 18 | 19 | //file handler 20 | private $handler = null; 21 | 22 | //lock particle size: the smaller particle size the bigger hash number 23 | private $hashNumber = 100; 24 | 25 | /** 26 | * @brief __construct 27 | * 28 | * @return void 29 | */ 30 | public function __construct() 31 | { 32 | } 33 | 34 | /** 35 | * @brief init the lock key and directory 36 | * 37 | * @param string $key 38 | * @param string $directory 39 | * 40 | * @return void 41 | */ 42 | public function init($key, $directory = '/tmp') 43 | { 44 | if(empty($directory) || !is_writeable($directory)) 45 | { 46 | $directory = sys_get_temp_dir(); 47 | } 48 | 49 | $hash = $this->hash($key) % $this->hashNumber; 50 | $this->path = $directory . DIRECTORY_SEPARATOR . $hash . '.txt'; 51 | } 52 | 53 | /** 54 | * hash string 55 | * 56 | * @param string $string 57 | * 58 | * @return int 59 | */ 60 | private function hash($string) 61 | { 62 | $crc = abs(crc32($string)); 63 | 64 | if($crc & 0x80000000) 65 | { 66 | $crc ^= 0xffffffff; 67 | $crc += 1; 68 | } 69 | 70 | return $crc; 71 | } 72 | 73 | /** 74 | * @brief lock 75 | * 76 | * @param string $key 77 | * @param string $directory 78 | * 79 | * @return boolean 80 | */ 81 | public function lock($key = '', $directory = '') 82 | { 83 | self::init($key, $directory); 84 | 85 | $this->handler = fopen($this->path, 'w+'); 86 | 87 | if(false === $this->handler) return false; 88 | 89 | return flock($this->handler, LOCK_EX); 90 | } 91 | 92 | /** 93 | * @brief unlock 94 | * 95 | * @param string $key 96 | * 97 | * @return boolean 98 | */ 99 | public function unlock($key = '', $timeout = 0) 100 | { 101 | if(false !== $this->handler) 102 | { 103 | flock($this->handler, LOCK_UN); 104 | clearstatcache(); 105 | } 106 | 107 | return fclose($this->handler); 108 | } 109 | } 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /src/Kernel/Middleware/MessageQueue/Base/Context.php: -------------------------------------------------------------------------------- 1 | 6 | * @version 1.0.0 7 | * @modify 2019-06-18 8 | */ 9 | 10 | namespace PHPCreeper\Kernel\Middleware\MessageQueue\Base; 11 | 12 | class Context 13 | { 14 | /** 15 | * @brief __construct 16 | * 17 | * @return null 18 | */ 19 | public function __construct() 20 | { 21 | } 22 | 23 | /** 24 | * @brief getMessageEntity 25 | * 26 | * @param string $body 27 | * @param string $headers 28 | * @param string $properties 29 | * 30 | * @return object 31 | */ 32 | public function getMessageEntity($body = '', $headers = array(), $properties = []) 33 | { 34 | return new Message($body, $headers, $properties); 35 | } 36 | 37 | /** 38 | * @brief getExchangeEntity 39 | * 40 | * @param string $name 41 | * 42 | * @return object 43 | */ 44 | public function getExchangeEntity($name = '') 45 | { 46 | return new Exchange($name); 47 | } 48 | 49 | /** 50 | * @brief getQueueEntity 51 | * 52 | * @param string $name 53 | * 54 | * @return object 55 | */ 56 | public function getQueueEntity($name = '') 57 | { 58 | return new Queue($name); 59 | } 60 | 61 | /** 62 | * @brief convertMessage 63 | * 64 | * @param string $extEnvelope 65 | * 66 | * @return object 67 | */ 68 | public function convertMessage(\AMQPEnvelope $extEnvelope) 69 | { 70 | $message = new Message( 71 | $extEnvelope->getBody(), 72 | $extEnvelope->getHeaders(), 73 | [ 74 | 'message_id' => $extEnvelope->getMessageId(), 75 | 'correlation_id' => $extEnvelope->getCorrelationId(), 76 | 'app_id' => $extEnvelope->getAppId(), 77 | 'type' => $extEnvelope->getType(), 78 | 'content_encoding' => $extEnvelope->getContentEncoding(), 79 | 'content_type' => $extEnvelope->getContentType(), 80 | 'expiration' => $extEnvelope->getExpiration(), 81 | 'priority' => $extEnvelope->getPriority(), 82 | 'reply_to' => $extEnvelope->getReplyTo(), 83 | 'timestamp' => $extEnvelope->getTimeStamp(), 84 | 'user_id' => $extEnvelope->getUserId(), 85 | ] 86 | ); 87 | $message->setRedelivered($extEnvelope->isRedelivery()); 88 | $message->setDeliveryTag($extEnvelope->getDeliveryTag()); 89 | $message->setRoutingKey($extEnvelope->getRoutingKey()); 90 | 91 | return $message; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/Kernel/Middleware/MessageQueue/Base/Exchange.php: -------------------------------------------------------------------------------- 1 | 6 | * @version 1.0.0 7 | * @modify 2019-06-18 8 | */ 9 | 10 | namespace PHPCreeper\Middleware\MessageQueue\Base; 11 | 12 | class Exchange extends Entity 13 | { 14 | const TYPE_DIRECT = 'direct'; 15 | const TYPE_FANOUT = 'fanout'; 16 | const TYPE_TOPIC = 'topic'; 17 | const TYPE_HEADERS = 'headers'; 18 | const FLAG_INTERNAL = 2048; 19 | const FLAG_NOPARAM = 0; 20 | const FLAG_DURABLE = 1; 21 | 22 | /** 23 | * constructor 24 | * 25 | * @param string $name 26 | * @return null 27 | */ 28 | public function __construct(string $name) 29 | { 30 | $this->type = self::TYPE_DIRECT; 31 | parent::__construct($name); 32 | } 33 | 34 | /** 35 | * remove flags 36 | * 37 | * @return null 38 | */ 39 | public function removeFlags() 40 | { 41 | $this->flags = self::FLAG_NOPARAM; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Kernel/Middleware/MessageQueue/Base/Message.php: -------------------------------------------------------------------------------- 1 | 6 | * @version 1.0.0 7 | * @modify 2019-06-17 8 | */ 9 | 10 | namespace PHPCreeper\Middleware\MessageQueue\Base; 11 | 12 | class Message extends Entity 13 | { 14 | const DELIVERY_MODE_NON_PERSISTENT = 1; 15 | const DELIVERY_MODE_PERSISTENT = 2; 16 | const FLAG_NOPARAM = 0; 17 | const FLAG_MANDATORY = 1; 18 | const FLAG_IMMEDIATE = 2; 19 | 20 | /** 21 | * the delivertag 22 | * 23 | * @var int|null 24 | */ 25 | private $deliveryTag = ''; 26 | 27 | /** 28 | * the consumerTag 29 | * 30 | * @var string|null 31 | */ 32 | private $consumerTag = ''; 33 | 34 | /** 35 | * redelivered or not 36 | * 37 | * @var bool 38 | */ 39 | private $redelivered = false; 40 | 41 | /** 42 | * the routing key 43 | * 44 | * @var string 45 | */ 46 | private $routingKey = ''; 47 | 48 | /** 49 | * construtor 50 | * 51 | * @return null 52 | */ 53 | public function __construct($body = '', $properties = array(), $headers = array()) 54 | { 55 | $this->redelivered = false; 56 | parent::__construct(uniqid('msg_'), $headers, $body, $properties); 57 | } 58 | 59 | /** 60 | * set redelivered status 61 | * 62 | * @return null 63 | */ 64 | public function setRedelivered(bool $redelivered) 65 | { 66 | $this->redelivered = (bool)$redelivered; 67 | } 68 | 69 | /** 70 | * get redelivered status 71 | * 72 | * @return boolean 73 | */ 74 | public function getRedelivered() 75 | { 76 | return $this->redelivered; 77 | } 78 | 79 | /** 80 | * set the deliveryTag 81 | * 82 | * @return null 83 | */ 84 | public function setDeliveryTag(int $deliveryTag = null) 85 | { 86 | $this->deliveryTag = $deliveryTag; 87 | } 88 | 89 | /** 90 | * get the deliveryTag 91 | * 92 | * @return string 93 | */ 94 | public function getDeliveryTag() 95 | { 96 | return $this->deliveryTag; 97 | } 98 | 99 | /** 100 | * set the consumerTag 101 | * 102 | * @return null 103 | */ 104 | public function setConsumerTag(string $consumerTag = null) 105 | { 106 | $this->consumerTag = $consumerTag; 107 | } 108 | 109 | /** 110 | * get the consumerTag 111 | * 112 | * @return string 113 | */ 114 | public function getConsumerTag() 115 | { 116 | return $this->consumerTag; 117 | } 118 | 119 | /** 120 | * set the routing key 121 | * 122 | * @return null 123 | */ 124 | public function setRoutingKey(string $routingKey = null) 125 | { 126 | $this->routingKey = $routingKey; 127 | } 128 | 129 | /** 130 | * get the routing key 131 | * 132 | * @return string 133 | */ 134 | public function getRoutingKey() 135 | { 136 | return $this->routingKey; 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /src/Kernel/Middleware/MessageQueue/Base/Queue.php: -------------------------------------------------------------------------------- 1 | 6 | * @version 1.0.0 7 | * @modify 2019-06-17 8 | */ 9 | 10 | namespace PHPCreeper\Middleware\MessageQueue\Base; 11 | 12 | class Queue extends Entity 13 | { 14 | const FLAG_EXCLUSIVE = 2097152; 15 | const FLAG_IFEMPTY = 4194304; 16 | const FLAG_DURABLE = 2; 17 | 18 | /** 19 | * the consumerTag 20 | * 21 | * @var string 22 | */ 23 | private $consumerTag; 24 | 25 | /** 26 | * constructor 27 | * 28 | * @return null 29 | */ 30 | public function __construct(string $name) 31 | { 32 | parent::__construct($name); 33 | } 34 | 35 | /** 36 | * set the consumerTag 37 | * 38 | * @return null 39 | */ 40 | public function setConsumerTag(string $consumerTag = null) 41 | { 42 | $this->consumerTag = $consumerTag; 43 | } 44 | 45 | /** 46 | * get the consumerTag 47 | * 48 | * @return string 49 | */ 50 | public function getConsumerTag() 51 | { 52 | return $this->consumerTag; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Kernel/Middleware/MessageQueue/PhpQueue.php: -------------------------------------------------------------------------------- 1 | 6 | * @link http://www.phpcreeper.com 7 | * @create 2022-10-30 8 | */ 9 | 10 | namespace PHPCreeper\Kernel\Middleware\MessageQueue; 11 | 12 | use PHPCreeper\Kernel\Slot\BrokerInterface; 13 | 14 | class PhpQueue implements BrokerInterface 15 | { 16 | /** 17 | * php queue object 18 | * 19 | * @var object 20 | */ 21 | protected $_phpQueueObject = NULL; 22 | 23 | /** 24 | * @brief __construct 25 | * 26 | * @param array $config 27 | * 28 | * @return void 29 | */ 30 | public function __construct($config = []) 31 | { 32 | if(empty($this->_phpQueueObject)) 33 | { 34 | $this->_phpQueueObject = new \SplQueue(); 35 | } 36 | 37 | $this->_phpQueueObject->setIteratorMode(\SplQueue::IT_MODE_DELETE); 38 | } 39 | 40 | /** 41 | * @brief push data into queue 42 | * 43 | * @param string $queue_name 44 | * @param string $text 45 | * 46 | * @return boolean 47 | */ 48 | public function push($queue_name = '', $text = '') 49 | { 50 | $text = json_encode($text); 51 | 52 | return $this->_phpQueueObject->enqueue($text); 53 | } 54 | 55 | /** 56 | * @brief pop data from queue 57 | * 58 | * @param string $queue_name 59 | * @param boolean $wait 60 | * 61 | * @return string 62 | */ 63 | public function pop($queue_name = '', $wait = false) 64 | { 65 | $message = ''; 66 | 67 | if(!$this->_phpQueueObject->isEmpty()) 68 | { 69 | $message = $this->_phpQueueObject->dequeue(); 70 | $message = json_decode($message, true); 71 | } 72 | 73 | return $message; 74 | } 75 | 76 | /** 77 | * @brief the queue length 78 | * 79 | * @param string $queue_name 80 | * 81 | * @return int 82 | */ 83 | public function llen($queue_name = '') 84 | { 85 | return $this->_phpQueueObject->count(); 86 | } 87 | 88 | /** 89 | * @brief close 90 | * 91 | * @return void 92 | */ 93 | public function close() 94 | { 95 | } 96 | 97 | /** 98 | * @brief acknowledge 99 | * 100 | * @param string $queue_name 101 | * @param string $delivery_tag 102 | * 103 | * @return void 104 | */ 105 | public function acknowledge($queue_name, $delivery_tag) 106 | { 107 | } 108 | 109 | /** 110 | * @brief purge 111 | * 112 | * @param string $queue_name 113 | * 114 | * @return void 115 | */ 116 | public function purge($queue_name) 117 | { 118 | } 119 | } 120 | 121 | 122 | -------------------------------------------------------------------------------- /src/Kernel/Plugin/ProxyPlugin.php: -------------------------------------------------------------------------------- 1 | 6 | * @version 1.0.0 7 | * @modify 2020-03-02 8 | */ 9 | 10 | namespace PHPCreeper\Kernel\Plugin; 11 | 12 | use PHPCreeper\Kernel\PHPCreeper; 13 | 14 | class ProxyPlugin 15 | { 16 | /** 17 | * @brief __construct 18 | * 19 | * @param object $phpcreeper 20 | * 21 | * @return void 22 | */ 23 | public function __construct($phpcreeper) 24 | { 25 | $this->phpcreeper = $phpcreeper; 26 | } 27 | 28 | /** 29 | * @brief install plugin 30 | * 31 | * @param object $phpcreeper 32 | * @param mixed $args 33 | * 34 | * @return void 35 | */ 36 | static public function install(PHPCreeper $phpcreeper, ...$args) 37 | { 38 | $phpcreeper->getService()->inject('getSystemTime', function(){ 39 | return (new ProxyPlugin($this))->getSystemTime(); 40 | }); 41 | } 42 | 43 | /** 44 | * @brief get system time 45 | * 46 | * @return int 47 | */ 48 | public function getSystemTime() 49 | { 50 | return time(); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/Kernel/Service/Provider/DropDuplicateServiceProvider.php: -------------------------------------------------------------------------------- 1 | 6 | * @version 1.0.0 7 | * @modify 2019-11-06 8 | */ 9 | 10 | namespace PHPCreeper\Kernel\Service\Provider; 11 | 12 | use PHPCreeper\Kernel\Service\Service; 13 | use PHPCreeper\Kernel\Service\Wrapper\DropDuplicateService; 14 | 15 | class DropDuplicateServiceProvider 16 | { 17 | /** 18 | * @brief 闭包式服务注射器 19 | * 20 | * 注 意: 闭包里的 $this 指向的是PHPCreeper对象, 内部机制参考核心PHPCreeper类. 21 | * 22 | * @param object $service 23 | * 24 | * @return array 25 | */ 26 | public function render(Service $service) 27 | { 28 | $service->inject('bindDropDuplicateFilter', function($type = 'redis', ...$args){ 29 | return $this->dropDuplicateFilter = DropDuplicateService::create($type, ...$args); 30 | }); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Kernel/Service/Provider/ExtractorServiceProvider.php: -------------------------------------------------------------------------------- 1 | 6 | * @version 1.0.0 7 | * @modify 2019-11-06 8 | */ 9 | 10 | namespace PHPCreeper\Kernel\Service\Provider; 11 | 12 | use PHPCreeper\Kernel\Service\Service; 13 | use PHPCreeper\Kernel\Service\Wrapper\ExtractorService; 14 | 15 | class ExtractorServiceProvider 16 | { 17 | /** 18 | * @brief 闭包式服务注射器 19 | * 20 | * 注 意: 闭包里的 $this 指向的是PHPCreeper对象, 内部机制参考核心PHPCreeper类. 21 | * 22 | * @param object $service 23 | * 24 | * @return array 25 | */ 26 | public function render(Service $service) 27 | { 28 | $service->inject('bindExtractor', function(...$args){ 29 | return $this->extractor = ExtractorService::init($this, ...$args); 30 | }); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Kernel/Service/Provider/HeadlessBrowserServiceProvider.php: -------------------------------------------------------------------------------- 1 | 6 | * @link http://www.phpcreeper.com 7 | * @create 2024-04-19 8 | */ 9 | 10 | namespace PHPCreeper\Kernel\Service\Provider; 11 | 12 | use PHPCreeper\Kernel\Service\Service; 13 | use PHPCreeper\Kernel\Service\Wrapper\HeadlessBrowserFactoryService; 14 | 15 | class HeadlessBrowserServiceProvider 16 | { 17 | /** 18 | * @brief 闭包式服务注射器 19 | * 20 | * 注 意: 闭包里的 $this 指向的是PHPCreeper对象, 内部机制参考核心PHPCreeper类. 21 | * 22 | * @param object $service 23 | * 24 | * @return array 25 | */ 26 | public function render(Service $service) 27 | { 28 | $service->inject('bindHeadlessBrowser', function($type = '', ...$args){ 29 | return $this->headlessBrowser = HeadlessBrowserFactoryService::create($type, ...$args); 30 | }); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Kernel/Service/Provider/HttpServiceProvider.php: -------------------------------------------------------------------------------- 1 | 6 | * @version 1.0.0 7 | * @modify 2019-11-06 8 | */ 9 | 10 | namespace PHPCreeper\Kernel\Service\Provider; 11 | 12 | use PHPCreeper\Kernel\Service\Service; 13 | use PHPCreeper\Kernel\Service\Wrapper\HttpFactoryService; 14 | 15 | class HttpServiceProvider 16 | { 17 | /** 18 | * @brief 闭包式服务注射器 19 | * 20 | * 注 意: 闭包里的 $this 指向的是PHPCreeper对象, 内部机制参考核心PHPCreeper类. 21 | * 22 | * @param object $service 23 | * 24 | * @return array 25 | */ 26 | public function render(Service $service) 27 | { 28 | $service->inject('bindHttpClient', function($type = '', ...$args){ 29 | return $this->httpClient = HttpFactoryService::createHttpClient($type, ...$args); 30 | }); 31 | 32 | /* 33 | *$service->inject('get', function($url, ...$args){ 34 | * return HttpService::get($url, ...$args); 35 | *}); 36 | */ 37 | 38 | /* 39 | *$service->inject('post', function($url, ...$args){ 40 | * return HttpService::post($url, ...$args); 41 | *}); 42 | */ 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Kernel/Service/Provider/LanguageServiceProvider.php: -------------------------------------------------------------------------------- 1 | 6 | * @version 1.0.0 7 | * @modify 2019-09-20 8 | */ 9 | 10 | namespace PHPCreeper\Kernel\Service\Provider; 11 | 12 | use PHPCreeper\PHPCreeper; 13 | use PHPCreeper\Kernel\Service\Service; 14 | use PHPCreeper\Kernel\Service\Wrapper\LanguageService; 15 | 16 | class LanguageServiceProvider 17 | { 18 | /** 19 | * @brief 闭包式服务注射器 20 | * 21 | * 注 意: 闭包里的 $this 指向的是PHPCreeper对象, 内部机制参考核心PHPCreeper类. 22 | * 23 | * @param object $service 24 | * 25 | * @return array 26 | */ 27 | public function render(Service $service) 28 | { 29 | $service->inject('bindLangConfig', function($type = 'zh'){ 30 | return $this->langConfig = PHPCreeper::$langConfigBackup = LanguageService::load($type); 31 | }); 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /src/Kernel/Service/Provider/LockServiceProvider.php: -------------------------------------------------------------------------------- 1 | 6 | * @version 1.0.0 7 | * @modify 2019-11-06 8 | */ 9 | 10 | namespace PHPCreeper\Kernel\Service\Provider; 11 | 12 | use PHPCreeper\Kernel\Service\Service; 13 | use PHPCreeper\Kernel\Service\Wrapper\LockFactoryService; 14 | 15 | class LockServiceProvider 16 | { 17 | /** 18 | * @brief 闭包式服务注射器 19 | * 20 | * 注 意: 闭包里的 $this 指向的是PHPCreeper对象, 内部机制参考核心PHPCreeper类. 21 | * 22 | * @param object $service 23 | * 24 | * @return array 25 | */ 26 | public function render(Service $service) 27 | { 28 | $service->inject('bindLockHelper', function($type = '', ...$args){ 29 | return $this->lockHelper = LockFactoryService::createLockHelper($type, ...$args); 30 | }); 31 | } 32 | } 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/Kernel/Service/Provider/PluginServiceProvider.php: -------------------------------------------------------------------------------- 1 | 6 | * @version 1.0.0 7 | * @modify 2019-11-06 8 | */ 9 | 10 | namespace PHPCreeper\Kernel\Service\Provider; 11 | 12 | use PHPCreeper\Kernel\Service\Service; 13 | use PHPCreeper\Kernel\Service\Wrapper\PluginService; 14 | 15 | class PluginServiceProvider 16 | { 17 | /** 18 | * @brief 闭包式服务注射器 19 | * 20 | * 注 意: 闭包里的 $this 指向的是PHPCreeper对象, 内部机制参考核心PHPCreeper类. 21 | * 22 | * @param object $service 23 | * 24 | * @return array 25 | */ 26 | public function render(Service $service) 27 | { 28 | $service->inject('installPlugin', function($plugins, ...$args){ 29 | return PluginService::install($this, $plugins, ...$args); 30 | }); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Kernel/Service/Provider/QueueServiceProvider.php: -------------------------------------------------------------------------------- 1 | 6 | * @version 1.0.0 7 | * @modify 2019-11-06 8 | */ 9 | 10 | namespace PHPCreeper\Kernel\Service\Provider; 11 | 12 | use PHPCreeper\Kernel\Service\Service; 13 | use PHPCreeper\Kernel\Service\Wrapper\QueueFactoryService; 14 | 15 | class QueueServiceProvider 16 | { 17 | /** 18 | * @brief 闭包式服务注射器 19 | * 20 | * 注 意: 闭包里的 $this 指向的是PHPCreeper对象, 内部机制参考核心PHPCreeper类. 21 | * 22 | * @param object $service 23 | * 24 | * @return array 25 | */ 26 | public function render(Service $service) 27 | { 28 | $service->inject('bindQueueClient', function($type = '', ...$args){ 29 | return $this->queueClient = QueueFactoryService::createQueueClient($type, ...$args); 30 | }); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Kernel/Service/Provider/SystemServiceProvider.php: -------------------------------------------------------------------------------- 1 | 6 | * @version 1.0.0 7 | * @modify 2019-11-06 8 | */ 9 | 10 | namespace PHPCreeper\Kernel\Service\Provider; 11 | 12 | use PHPCreeper\Kernel\Service\Service; 13 | use PHPCreeper\Kernel\Service\Wrapper\QueueFactoryService; 14 | use PHPCreeper\Kernel\Task; 15 | use PHPCreeper\Kernel\Middleware\Database\Database; 16 | 17 | class SystemServiceProvider 18 | { 19 | /** 20 | * @brief 闭包式服务注射器 21 | * 22 | * 注 意: 闭包里的 $this 指向的是PHPCreeper对象, 内部机制参考核心PHPCreeper类. 23 | * 24 | * @param object $service 25 | * 26 | * @return array 27 | */ 28 | public function render(Service $service) 29 | { 30 | $service->inject('bindRedisClient', function($type, ...$args){ 31 | return $this->redisClient = QueueFactoryService::createQueueClient($type, ...$args); 32 | }); 33 | 34 | $service->inject('getTaskMan', function($task_options = []){ 35 | return Task::getInstance($this, $task_options); 36 | }); 37 | 38 | $service->inject('newTaskMan', function($task_options = []){ 39 | return Task::newInstance($this, $task_options); 40 | }); 41 | 42 | $service->inject('getDbo', function($options = []){ 43 | return Database::getInstance($options); 44 | }); 45 | 46 | $service->inject('newDbo', function($options = []){ 47 | return Database::newInstance($options); 48 | }); 49 | 50 | $service->inject('createTask', function($options = []){ 51 | return Task::newInstance($this, [])->createTask($options); 52 | }); 53 | 54 | $service->inject('createMultiTask', function($options = []){ 55 | return Task::newInstance($this, [])->createMultiTask($options); 56 | }); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Kernel/Service/Service.php: -------------------------------------------------------------------------------- 1 | 6 | * @version 1.0.0 7 | * @modify 2019-09-04 8 | */ 9 | 10 | namespace PHPCreeper\Kernel\Service; 11 | 12 | use PHPCreeper\Kernel\PHPCreeper; 13 | use \Closure; 14 | 15 | class Service 16 | { 17 | /** 18 | * record used to store service 19 | * 20 | * @var array 21 | */ 22 | public $record = array(); 23 | 24 | /** 25 | * @brief __construct 26 | * 27 | * @param array $providers 28 | * @param object $phpcreeper 29 | * 30 | * @return void 31 | */ 32 | public function __construct($providers, PHPCreeper $phpcreeper) 33 | { 34 | array_walk($providers, function($provider){ 35 | (new $provider())->render($this); 36 | }); 37 | } 38 | 39 | /** 40 | * @brief get service by name 41 | * 42 | * @param string $name 43 | * 44 | * @return closure 45 | */ 46 | public function getName($name) 47 | { 48 | if(!isset($this->record[$name])) 49 | { 50 | pprint("method [$name] not inject yet", array_keys($this->record)); 51 | return; 52 | } 53 | 54 | return $this->record[$name]; 55 | } 56 | 57 | /** 58 | * @brief inject service 59 | * 60 | * @param string $name 61 | * @param closure $callback 62 | * 63 | * @return void 64 | */ 65 | public function inject($name, Closure $callback) 66 | { 67 | !array_key_exists($name, $this->record) && $this->record[$name] = $callback; 68 | } 69 | 70 | /** 71 | * @brief get record 72 | * 73 | * @return array 74 | */ 75 | public function getRecord() 76 | { 77 | return $this->record; 78 | } 79 | 80 | } 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /src/Kernel/Service/Wrapper/DropDuplicateService.php: -------------------------------------------------------------------------------- 1 | 6 | * @version 1.0.0 7 | * @modify 2019-11-01 8 | */ 9 | 10 | namespace PHPCreeper\Kernel\Service\Wrapper; 11 | 12 | use PHPCreeper\Kernel\Slot\DropDuplicateInterface; 13 | use PHPCreeper\Kernel\Middleware\DropDuplicate\BloomFilterLocal; 14 | use PHPCreeper\Kernel\Middleware\DropDuplicate\BloomFilterRedis; 15 | use PHPCreeper\Kernel\Middleware\DropDuplicate\BloomFilterPredis; 16 | 17 | class DropDuplicateService 18 | { 19 | /** 20 | * drop duplicate filter 21 | * 22 | * @var array 23 | */ 24 | static private $_dropDuplicateFilter = null; 25 | 26 | /** 27 | * @brief create one instance 28 | * 29 | * @param string|callback $type 30 | * @param mixed $args 31 | * 32 | * @return object 33 | */ 34 | static public function create($type = 'redis', ...$args) 35 | { 36 | if(empty($type) || $type == 'predis'){ 37 | $filter = new BloomFilterPredis(...$args); 38 | }elseif($type == 'redis'){ 39 | $filter = new BloomFilterRedis(...$args); 40 | }elseif($type == 'local'){ 41 | $filter = new BloomFilterLocal(...$args); 42 | }elseif(is_callable($type)){ 43 | $filter = call_user_func($type, ...$args); 44 | }else{ 45 | $filter = new BloomFilterLocal(...$args); 46 | } 47 | 48 | return $filter; 49 | } 50 | } 51 | 52 | 53 | -------------------------------------------------------------------------------- /src/Kernel/Service/Wrapper/HeadlessBrowserFactoryService.php: -------------------------------------------------------------------------------- 1 | 6 | * @link http://www.phpcreeper.com 7 | * @create 2024-04-21 8 | */ 9 | 10 | namespace PHPCreeper\Kernel\Service\Wrapper; 11 | 12 | use PHPCreeper\Kernel\PHPCreeper; 13 | use PHPCreeper\Kernel\Middleware\HeadlessBrowser\Chrome; 14 | 15 | class HeadlessBrowserFactoryService 16 | { 17 | /** 18 | * @brief create headless browser instance 19 | * 20 | * @param string|callback $type 21 | * @param mixed $args 22 | * 23 | * @return object 24 | */ 25 | static public function create($type = 'chrome', ...$args) 26 | { 27 | if(empty($type) || $type == 'chrome'){ 28 | $browser = new Chrome(...$args); 29 | }elseif(is_callable($type)){ 30 | $browser = call_user_func($type, ...$args); 31 | }else{ 32 | $browser = new Chrome(...$args); 33 | } 34 | 35 | return $browser; 36 | } 37 | } 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/Kernel/Service/Wrapper/HttpFactoryService.php: -------------------------------------------------------------------------------- 1 | 6 | * @version 1.0.0 7 | * @modify 2019-11-06 8 | */ 9 | 10 | namespace PHPCreeper\Kernel\Service\Wrapper; 11 | 12 | use PHPCreeper\Kernel\PHPCreeper; 13 | use PHPCreeper\Kernel\Middleware\HttpClient\Guzzle; 14 | use PHPCreeper\Kernel\Middleware\HttpClient\Curl; 15 | 16 | class HttpFactoryService 17 | { 18 | /** 19 | * http client instance 20 | * 21 | * @var array 22 | */ 23 | static private $_client = null; 24 | 25 | /** 26 | * @brief create http client 27 | * 28 | * @param string|callback $type 29 | * @param mixed $args 30 | * 31 | * @return object 32 | */ 33 | static public function createHttpClient($type = 'guzzle', ...$args) 34 | { 35 | if(empty($type) || $type == 'guzzle'){ 36 | $client = new Guzzle(...$args); 37 | }elseif($type == 'curl'){ 38 | $client = new Guzzle(...$args); 39 | }elseif(is_callable($type)){ 40 | $client = call_user_func($type, ...$args); 41 | }else{ 42 | $client = new Guzzle(...$args); 43 | } 44 | 45 | return $client; 46 | } 47 | } 48 | 49 | 50 | -------------------------------------------------------------------------------- /src/Kernel/Service/Wrapper/LanguageService.php: -------------------------------------------------------------------------------- 1 | 6 | * @version 1.0.0 7 | * @modify 2019-11-06 8 | */ 9 | 10 | namespace PHPCreeper\Kernel\Service\Wrapper; 11 | 12 | class LanguageService 13 | { 14 | /** 15 | * language config 16 | * 17 | * @var array 18 | */ 19 | static private $_lang_config = []; 20 | 21 | /** 22 | * @brief load language 23 | * 24 | * @param string $type 25 | * 26 | * @return array 27 | */ 28 | static public function load($type = 'zh') 29 | { 30 | if(empty(self::$_lang_config)) 31 | { 32 | (empty($type) || !is_string($type)) && $type = 'zh'; 33 | $config_file = dirname(dirname(dirname(__FILE__))) . '/Language/' . $type . '.php'; 34 | 35 | if(!is_file($config_file) || !file_exists($config_file)) 36 | { 37 | $config_file = dirname(__FILE__, 3) . '/Language/zh.php'; 38 | } 39 | 40 | self::$_lang_config = include_once($config_file); 41 | } 42 | 43 | return self::$_lang_config; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/Kernel/Service/Wrapper/LockFactoryService.php: -------------------------------------------------------------------------------- 1 | 6 | * @version 1.0.0 7 | * @modify 2019-11-01 8 | */ 9 | 10 | namespace PHPCreeper\Kernel\Service\Wrapper; 11 | 12 | use PHPCreeper\Kernel\Slot\LockInterface; 13 | use PHPCreeper\Kernel\Middleware\LockManager\PredisLock; 14 | use PHPCreeper\Kernel\Middleware\LockManager\RedisLock; 15 | use PHPCreeper\Kernel\Middleware\LockManager\FileLock; 16 | 17 | class LockFactoryService 18 | { 19 | /** 20 | * lock helper instance 21 | * 22 | * @var object 23 | */ 24 | static private $_helper = null; 25 | 26 | /** 27 | * @brief create lock helper 28 | * 29 | * @param string|callback $type 30 | * @param mixed $args 31 | * 32 | * @return object 33 | */ 34 | static public function createLockHelper($type = 'redis', ...$args) 35 | { 36 | if(empty($type) || 'predis' == $type){ 37 | $helper = new PredisLock(...$args); 38 | }elseif('redis' == $type){ 39 | $helper = new RedisLock(...$args); 40 | }elseif('file' == $type){ 41 | $helper = new FileLock(...$args); 42 | }elseif(is_callable($type)){ 43 | $helper = call_user_func($type, ...$args); 44 | }else{ 45 | $helper = new FileLock(...$args); 46 | } 47 | 48 | return $helper; 49 | } 50 | } 51 | 52 | 53 | -------------------------------------------------------------------------------- /src/Kernel/Service/Wrapper/PluginService.php: -------------------------------------------------------------------------------- 1 | 6 | * @version 1.0.0 7 | * @modify 2019-11-06 8 | */ 9 | 10 | namespace PHPCreeper\Kernel\Service\Wrapper; 11 | 12 | use PHPCreeper\Kernel\PHPCreeper; 13 | 14 | class PluginService 15 | { 16 | /** 17 | * @brief install plugin 18 | * 19 | * @param object $phpcreeper 20 | * @param string | array $plugins 21 | * @param mixed $args 22 | * 23 | * @return object 24 | */ 25 | static public function install(PHPCreeper $phpcreeper, $plugins, ...$args) 26 | { 27 | if(is_array($plugins)) 28 | { 29 | foreach($plugins as $plugin) 30 | { 31 | $plugin::install($phpcreeper); 32 | } 33 | } 34 | else 35 | { 36 | $plugins::install($phpcreeper, ...$args); 37 | } 38 | 39 | return $phpcreeper; 40 | } 41 | } 42 | 43 | 44 | -------------------------------------------------------------------------------- /src/Kernel/Service/Wrapper/QueueFactoryService.php: -------------------------------------------------------------------------------- 1 | 6 | * @version 1.0.0 7 | * @modify 2019-11-06 8 | */ 9 | 10 | namespace PHPCreeper\Kernel\Service\Wrapper; 11 | 12 | use PHPCreeper\Kernel\Middleware\MessageQueue\BrokeInterface; 13 | use PHPCreeper\Kernel\Middleware\MessageQueue\PredisClient; 14 | use PHPCreeper\Kernel\Middleware\MessageQueue\RedisExtension; 15 | use PHPCreeper\Kernel\Middleware\MessageQueue\AmqpExtension; 16 | use PHPCreeper\Kernel\Middleware\MessageQueue\PhpQueue; 17 | 18 | class QueueFactoryService 19 | { 20 | /** 21 | * queue client instance 22 | * 23 | * @var array 24 | */ 25 | static private $_client = null; 26 | 27 | /** 28 | * @brief create queue client 29 | * 30 | * @param string|callback $type 31 | * @param mixed $args 32 | * 33 | * @return object 34 | */ 35 | static public function createQueueClient($type = 'redis', ...$args) 36 | { 37 | if(empty($type) || $type == 'predis'){ 38 | $client = new PredisClient(...$args); 39 | }elseif($type == 'redis'){ 40 | $client = new RedisExtension(...$args); 41 | }elseif($type == 'amqp'){ 42 | $client = new AmqpExtension(...$args); 43 | }elseif($type == 'php'){ 44 | $client = new PhpQueue(...$args); 45 | }elseif(is_callable($type)){ 46 | $client = call_user_func($type, ...$args); 47 | }else{ 48 | $client = new RedisExtension(...$args); 49 | } 50 | 51 | return $client; 52 | } 53 | } 54 | 55 | 56 | -------------------------------------------------------------------------------- /src/Kernel/Slot/BrokerInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * @version 1.0.0 7 | * @modify 2019-06-17 8 | */ 9 | 10 | namespace PHPCreeper\Kernel\Slot; 11 | 12 | interface BrokerInterface 13 | { 14 | /** 15 | * @brief __construct 16 | * 17 | * @param array $config 18 | * 19 | * @return null 20 | */ 21 | public function __construct($config = array()); 22 | 23 | /** 24 | * @brief close connection 25 | * 26 | * @return boolean 27 | */ 28 | public function close(); 29 | 30 | /** 31 | * @brief push data info queue 32 | * 33 | * @param string $text 34 | * 35 | * @return bool|string 36 | */ 37 | public function push($queue_name = '', $text = ''); 38 | 39 | /** 40 | * @brief pop data from queue 41 | * 42 | * @param string $queue_name 43 | * @param string $wait 44 | * 45 | * @return boolean|string 46 | */ 47 | public function pop($queue_name, $wait = false); 48 | 49 | /** 50 | * @brief message acknowledge 51 | * 52 | * @param string $queue_name 53 | * @param int $delivery_tag 54 | * 55 | * @return boolean 56 | */ 57 | public function acknowledge($queue_name, $delivery_tag); 58 | 59 | /** 60 | * @brief purge queue 61 | * 62 | * @param string $queue_name 63 | * 64 | * @return boolean 65 | */ 66 | public function purge($queue_name); 67 | } 68 | -------------------------------------------------------------------------------- /src/Kernel/Slot/DropDuplicateInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * @version 1.0.0 7 | * @modify 2019-09-04 8 | */ 9 | 10 | namespace PHPCreeper\Kernel\Slot; 11 | 12 | use PHPCreeper\Kernel\PHPCreeper; 13 | 14 | Interface DropDuplicateInterface 15 | { 16 | /** 17 | * @brief add element to bit array, called collections. 18 | * 19 | * @param string $element 20 | * 21 | * @return void 22 | */ 23 | public function add($element); 24 | 25 | /** 26 | * @brief check whether element exists bit array, called collections. 27 | * 28 | * @param string $element 29 | * 30 | * @return boolean 31 | */ 32 | public function has($element); 33 | } 34 | -------------------------------------------------------------------------------- /src/Kernel/Slot/HttpClientInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * @version 1.0.0 7 | * @modify 2019-09-04 8 | */ 9 | 10 | namespace PHPCreeper\Kernel\Slot; 11 | 12 | interface HttpClientInterface 13 | { 14 | /** 15 | * create and send an HTTP request 16 | * 17 | * @param string $method http method 18 | * @param string|UriInterface $uri URI object or string 19 | * @param array $options request options 20 | * 21 | * @return ResponseInterface 22 | */ 23 | public function request($method, $uri, array $options = []); 24 | 25 | /** 26 | * get response status code 27 | * 28 | * @return int 29 | */ 30 | public function getResponseStatusCode(); 31 | 32 | /** 33 | * get response status message 34 | * 35 | * @return string 36 | */ 37 | public function getResponseStatusMessage(); 38 | 39 | /** 40 | * get response body 41 | * 42 | * @return string 43 | */ 44 | public function getResponseBody(); 45 | } 46 | -------------------------------------------------------------------------------- /src/Kernel/Slot/LockInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * @version 1.0.0 7 | * @modify 2019-11-06 8 | */ 9 | 10 | namespace PHPCreeper\Kernel\Slot; 11 | 12 | interface LockInterface 13 | { 14 | /** 15 | * @brief lock 16 | * 17 | * @param string $key 18 | * 19 | * @return int 20 | */ 21 | public function lock($key); 22 | 23 | /** 24 | * @brief unlock 25 | * 26 | * @param string $key 27 | * @param int $timeout 28 | * 29 | * @return boolean 30 | */ 31 | public function unlock($key, $timeout = 0); 32 | } 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /src/Kernel/Slot/PluginInterface.php: -------------------------------------------------------------------------------- 1 | 6 | * @version 1.0.0 7 | * @modify 2019-09-04 8 | */ 9 | 10 | namespace PHPCreeper\Kernel\Slot; 11 | 12 | use PHPCreeper\Kernel\PHPCreeper; 13 | 14 | interface PluginInterface 15 | { 16 | /** 17 | * @brief install plugin 18 | * 19 | * @param object $phpcreeper 20 | * @param string | array $plugins 21 | * @param mixed $args 22 | * 23 | * @return object 24 | */ 25 | static public function install(PHPCreeper $phpcreeper, ...$args); 26 | } 27 | -------------------------------------------------------------------------------- /src/PHPCreeper.php: -------------------------------------------------------------------------------- 1 | 6 | * @link http://www.phpcreeper.com 7 | * @create 2024-01-30 8 | */ 9 | 10 | namespace PHPCreeper; 11 | 12 | use PHPCreeper\Kernel\PHPCreeper as KernelPHPCreeper; 13 | 14 | class PHPCreeper extends KernelPHPCreeper 15 | { 16 | 17 | } 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/Server.php: -------------------------------------------------------------------------------- 1 | 6 | * @link http://www.phpcreeper.com 7 | * @create 2021-09-20 8 | */ 9 | 10 | namespace PHPCreeper; 11 | 12 | use PHPCreeper\Kernel\PHPCreeper; 13 | use PHPCreeper\Kernel\Library\Helper\Tool; 14 | use PHPCreeper\Timer; 15 | use Configurator\Configurator; 16 | use Logger\Logger; 17 | 18 | class Server extends PHPCreeper 19 | { 20 | /** 21 | * @brief run worker instance 22 | * 23 | * @return void 24 | */ 25 | public function run() 26 | { 27 | $this->onWorkerStart = array($this, 'onWorkerStart'); 28 | $this->onWorkerStop = array($this, 'onWorkerStop'); 29 | $this->onWorkerReload = array($this, 'onWorkerReload'); 30 | $this->onConnect = array($this, 'onConnect'); 31 | $this->onClose = array($this, 'onClose'); 32 | $this->onMessage = array($this, 'onMessage'); 33 | $this->onBufferFull = array($this, 'onBufferFull'); 34 | $this->onBufferClose = array($this, 'onBufferClose'); 35 | $this->onError = array($this, 'onError'); 36 | 37 | parent::run(); 38 | } 39 | 40 | /** 41 | * @brief onWorkerStart 42 | * 43 | * @param object $worker 44 | * 45 | * @return boolean|void 46 | */ 47 | public function onWorkerStart($worker) 48 | { 49 | //global init 50 | $this->initMiddleware()->initLogger(); 51 | 52 | //trigger user callback 53 | $returning = $this->triggerUserCallback('onServerStart', $this); 54 | if(false === $returning) return false; 55 | } 56 | 57 | /** 58 | * @brief onWorkerStop 59 | * 60 | * @return void 61 | */ 62 | public function onWorkerStop($worker) 63 | { 64 | //trigger user callback 65 | $returning = $this->triggerUserCallback('onServerStop', $this); 66 | if(false === $returning) return false; 67 | } 68 | 69 | /** 70 | * @brief onWorkerReload 71 | * 72 | * @param object $worker 73 | * 74 | * @return boolean|void 75 | */ 76 | public function onWorkerReload($worker) 77 | { 78 | //trigger user callback 79 | $returning = $this->triggerUserCallback('onServerReload', $this); 80 | if(false === $returning) return false; 81 | } 82 | 83 | /** 84 | * @brief onConnect 85 | * 86 | * @param object $connection 87 | * 88 | * @return boolean|void 89 | */ 90 | public function onConnect($connection) 91 | { 92 | //trigger user callback 93 | $returning = $this->triggerUserCallback('onServerConnect', $connection); 94 | if(false === $returning) return false; 95 | } 96 | 97 | /** 98 | * @brief onClose 99 | * 100 | * @param object $connection 101 | * 102 | * @return boolean|void 103 | */ 104 | public function onClose($connection) 105 | { 106 | //trigger user callback 107 | $returning = $this->triggerUserCallback('onServerClose', $connection); 108 | if(false === $returning) return false; 109 | } 110 | 111 | /** 112 | * @brief onMessage 113 | * 114 | * @param object $connection 115 | * @param string $data 116 | * 117 | * @return boolean|void 118 | */ 119 | public function onMessage($connection, $data) 120 | { 121 | //trigger user callback 122 | $returning = $this->triggerUserCallback('onServerMessage', $connection, $data); 123 | if(false === $returning) return false; 124 | } 125 | 126 | /** 127 | * @brief onBufferFull 128 | * 129 | * @param object $connection 130 | * 131 | * @return boolean|void 132 | */ 133 | public function onBufferFull($connection) 134 | { 135 | //trigger user callback 136 | $returning = $this->triggerUserCallback('onServerBufferFull', $connection); 137 | if(false === $returning) return false; 138 | } 139 | 140 | /** 141 | * @brief onBufferDrain 142 | * 143 | * @param object $connection 144 | * 145 | * @return boolean|void 146 | */ 147 | public function onBufferDrain($connection) 148 | { 149 | //trigger user callback 150 | $returning = $this->triggerUserCallback('onServerBufferDrain', $connection); 151 | if(false === $returning) return false; 152 | } 153 | 154 | /** 155 | * @brief onError 156 | * 157 | * @param object $connection 158 | * @param string $code 159 | * @param string $msg 160 | * 161 | * @return boolean|void 162 | */ 163 | public function onError($connection, $code, $msg) 164 | { 165 | //trigger user callback 166 | $returning = $this->triggerUserCallback('onServerError', $connection, $code, $msg); 167 | if(false === $returning) return false; 168 | } 169 | 170 | 171 | 172 | } 173 | 174 | 175 | -------------------------------------------------------------------------------- /src/Timer.php: -------------------------------------------------------------------------------- 1 | 6 | * @link http://www.phpcreeper.com 7 | * @create 2022-06-12 8 | */ 9 | 10 | namespace PHPCreeper; 11 | 12 | use Workerman\Lib\Timer as WorkermanTimer; 13 | 14 | class Timer extends WorkermanTimer 15 | { 16 | 17 | } 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/Tool.php: -------------------------------------------------------------------------------- 1 | 6 | * @link http://www.phpcreeper.com 7 | * @create 2022-09-10 8 | */ 9 | 10 | namespace PHPCreeper; 11 | 12 | use PHPCreeper\Kernel\Library\Helper\Tool as HelperTool; 13 | 14 | class Tool extends HelperTool 15 | { 16 | 17 | } 18 | 19 | 20 | --------------------------------------------------------------------------------