2 Star 9 Fork 0

暖暖の、拥抱♬ / Candyphp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

本文档最后修订日期:
2022-10-19

前言

版本说明

当前文档对应框架版本是3.0.1,如果与您使用的框架版本不符,则有可能本文档的部分或者全部内容将不适用于您正在使用的框架。 在3.x中,我们进行了整体的框架重构,因此与3.x之前的版本不兼容。如果您正在使用2.x或更早的版本,请参看升级章节的内容。

关于workerman

当前内置workerman的版本为4.1.4,因功能需要已对框架做出多出修改,故暂时无法跟随版本直接更新,涉及的修改点:

  • 修改Workerman的Autoloader类 修改加载方法支持加载框架类和方法
  • 修改Workerman的Autoloader类 兼容原生类创建
  • 修改Workerman的Worker类 增加自定义command命令功能
  • 修改Workerman的Http类 缩短缓存键值
  • 修改Workerman的Http类 修改gzip配置位置 便于开启gzip
  • 修改Workerman的Request类 修改Session方法 可以指定session_id后开启
  • 修改Workerman的Request类 新增全局变量服务于框架
  • 修改Workerman的Response类 gzip参数
  • 修改Workerman的Response类 max-age参数
  • 修改Workerman的Response类 staticAgrs参数
  • 修改Workerman的Response类 补全httpStatus信息
  • 修改Workerman的Response类 获取httpStatus信息方法
  • 修改Workerman的Response类 gzip压缩
  • 修改Workerman的Response类 添加清除 cookie功能
  • 修改Workerman的Session类 兼容框架的缓存驱动

在原来webserver的基础上修复的小bug和开发新特性:

  • WebServer类 修复目录错误
  • WebServer类 去掉默认目录绑定返回502错误
  • WebServer类 修改绑定模式支持泛解析
  • WebServer类 修改ssl模式添加强制跳转
  • WebServer类 添加 $_SERVER['SCRIPT_NAME'] 变量
  • WebServer类 支持PATHINFO模式

框架内置了组件:

  • Channel组件
  • GatewayWorker组件
  • GlobalData组件
  • JsonRpc组件
  • WebServer组件
  • WebSocket组件

其他

  • 内置了自动reload 在linux系统内开发 自动更新

更多的信息请查看更新记录。

综述

感谢您了解CandyPHP开源框架。

CandyPHP 是标准的 MVC 模式框架,理解和使用简单方便,上手迅速。

此框架下2.x开始引入PHP引擎 workerman 实现常规ApacheNginx模式运行和Cli模式运行并存特性,3.x开始重构优化进一步规范和提升框架速度和便携行。

  • 高内聚的可插拔插件和无限的拓展的模块设计
  • 简洁清晰的文件结构
  • 完善详细的报错信息

标准的MVC 模式框架,单入口单项目和单入口多项目两种运行方式,功能和模版分离,自动建立模块等诸多特性只为让您的代码书写更流畅,程序运行更稳定。

运行环境

运行环境为PHP7+

性能&安全性

CandyPHP秉承一切输入都不可信原则,内置安全类对一切输入进行过滤和检查,DBServer引入PDO、Mysqli等进行参数绑定和检查。内置函数防注入、XSS、CSRF等安全问题。

代码尽量精简和考虑性能优化并且引入workerman 框架可以使用常驻内存的Cli运行模式进一步提升执行效率。

交流方式

CandyPHP官方QQ群:219268056

准备好了吗?接下来,我们将为您详细介绍如何使用CandyPHP框架!

目录结构

框架目录结构

以下是未初始化之前框架的目录结构

/ 根目录
|
├─Candy		框架目录
|   ├─Class		框架扩展类库目录
|   ├─Core		框架核心类库目录
|   ├─Func		框架函数库目录
|   ├─Tpl		框架初始化素材库
|   ├─Vendor		框架第三方扩展类库
|   ├─Autoload.php	框架载入入口
|   └─Version.php	框架版本号
|
├─index.php	默认入口文件
|
└─candys	Cli启动文件

项目目录结构

以下是项目初始化后的目录结构

/ 根目录
|
├─Addons	扩展目录
|   └─Demo	演示扩展目录
|
├─Application   项目目录
|   └─Home	默认项目目录
|      ├─Controls	控制器目录
|      ├─Languages	语言库目录
|      ├─Models		数据模型目录
|      └─Views		默认模版目录(未特殊设定位置时才有)
|
├─Candy		框架目录
|
├─Plugins	插件目录
|   ├─Demo	演示插件目录
|   └─Home	默认项目扩展二开目录
|
├─Public	公共目录
|   ├─css	公共样式目录
|   ├─images	公共图片目录
|   ├─js	公共js目录
|   ├─thumbs	默认缩略图目录
|   └─uploads	默认上传目录
|
├─Runtime	运行缓存目录
|   ├─Cache	缓存目录
|   ├─Comps	模版编译目录
|   ├─Controls	控制器编译目录
|   ├─Data	数据目录
|   ├─Logs	记录目录
|   ├─Models	模型编译目录
|   ├─Tmps	临时缓存目录
|   └─init.lock	初始化锁定文件
|
├─Source	项目资源配置目录
|   ├─Class	项目扩展类库目录
|   ├─Func	项目函数库目录
|   ├─Inc	项目配置目录
|      ├─Addon.inc.php		扩展配置
|      ├─HomeRoute.inc.php	Home路由配置
|      ├─App.inc.php		项目权限菜单配置
|      ├─AttackCode.inc.php	输入过滤配置
|      ├─Command.inc.php	框架扩展命令配置
|      ├─Config.inc.php		基本配置
|      ├─Init.inc.php		初始化配置
|      ├─Plug.inc.php		插件配置
|      ├─Route.inc.php		全局路由配置
|      ├─Sensitive.inc.php	违禁词配置
|      ├─Specialclass.inc.php	特殊类库配置
|      └─System.inc.php		系统配置
|
|   └─Vendor	项目第三方扩展类目录
|
├─Template	默认Home模版目录
|   └─default	前台默认模版目录
|
├─index.php	默认入口文件
|
└─candys	Cli启动文件

准备工作和核心配置

准备工作

开始之前请确认PHP引擎支持PATHINFO和伪静态。 cli模式下自动支持。

规则隐藏了index.php文件名,并屏蔽了对/Core、/Source、/Temp等关键路径的访问,以及当HTTP状态码为4xx或5xx时,展示友好的出错页面。同时将流量牵引至/index.php。

核心配置

Apache和Nginx初始化时仅需要对/Source/Inc/Init.inc.php内的几项做简单的修改或者直接默认也是可以的。

  • defined('DEBUG') OR define('DEBUG', 1);

DEBUG (Int) 1 : 调试模式,1 代表开启、0 代表关闭,默认开启。

当调试模式关闭时,报错等级将调整至最低 (意味着某些不重要的错误将会被忽略) ,而当调试模式开启时,框架会自动对修改过的模板文件进行编译,并告知浏览器对所有页面都不进行缓存;同时在发生错误时显示详细的报错信息 (可能包含文件路径、出错类型或数据库信息)

在调试模式关闭的情况下,系统会自动开启记录日志的配置项,报错信息将会被写入日志中,日志位置/Runtime/Logs/error.log

  • $tplpath = 'Home@./Template'; 项目模版文件夹的位置, 值为字符串,@分开 前面为项目名称,后面为路径。自定义时使用,不需要可以注销或删除。

框架默认的模版文件夹路径为:Application/项目名/Views

Cli模式下除了以上的配置 还需要修改service文件配置

$servers数组包含了所有的服务器配置,所以只是修改这个数组就可以。其中webserver项目配置WEB服务其中server为多服务配置每个子数组表示一组服务其中 count表示进程数、gzip表示gzip等级0表示不开启、max-age表示缓存时间、list域名绑定信息。

rpc RPC服务配置 globaldata 全局变量配置 task 自动计划任务配置

把代码解压到根目录,配置完(也可以啥都不做),直接访问就ok了,会自动创建默认的Home项目和初始化所有的目录

Home是默认应用 也是系统缺省应用 比其他应用多一些特性,比如缺省保护、应用名省略。。。

举例:

https://domain.com/Admin/Index/index.html 是Admin应用

https://domain.com/Home/Index/index.html 是Home应用

但是Home一般的样式是这样的 https://domain.com/Index/index.html

新应用创建

框架新应用的创建也十分简单,不过一定要在 debug模式下哦

举例:

创建一个名称为 User的应用, 在debug模式下 直接输入地址 https://domain.com/User/?add

OK!应用创建完成,所有的应用目录、初始的操作、默认模版和应该的路由配置完全搞定。够不够简单!!!

常量

扩展类库

配置项

语法

模版

缓存及自动编译

文件引入

路由

重名策略

报错机制

升级

安全规范

高性能

版权声明&联系方式

本框架为免费开源、遵循Apache2开源协议的框架,但不得删除框架内文件的版权信息,违者必究。 This framework is free and open source, following the framework of Apache2 open source protocol, but the copyright information of files are not allowed to be deleted,violators will be prosecuted to the maximum extent possible. ©2020 fingerboy. All rights reserved.

反馈Bug,可加入 QQ群 或发送邮件至 fingerboy@qq.cn 进行反馈。

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

轻量级candyphp框架结合workerman从4.x版本开发,支持Workerman Apache Nginx iis Cli 访问 展开 收起
PHP 等 3 种语言
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
PHP
1
https://gitee.com/minicloud/candyphp.git
git@gitee.com:minicloud/candyphp.git
minicloud
candyphp
Candyphp
master

搜索帮助

14c37bed 8189591 565d56ea 8189591