search
HomeBackend DevelopmentPHP Tutorial 豌豆框架0.6正式发布解决思路

豌豆框架0.6正式发布
[color=#339966]豌豆框架(英文名叫Wonderful Framework): [/color]是一个PHP开发框架, 支持PHP5以上版本, 它是免费的, 开源的, 是基于BSD协议发行的. 
是具有灵活的, 可扩展的, 可配置的, 组件化的框架结构. 采用面向对象的设计理念, 同时又支持传统的面向过程的, 在HTML中直接嵌入PHP代码的开发方式. 
支持MVC模式, 能让程序员更好的与美工合作, 甚至美工不需要会PHP. 
PhpTagLib, Action等等, 这些技术能开发者更好的开发出强大的分层设计构架. 
集成有单元测试/对象模仿功能, 还有依赖注入构架, 更好的支持敏捷开发. 
框架多处参考了JAVA中的技术, 并对这些技术更一步发挥. 
框架还有很多不足之处, 还需不断完善, 欢迎多提意见, 如有什么问题, 请向我们反馈. 欢迎你的参与! 

特点:
* 灵活, 扩展性强, 复用性高, 完全采用面向对象设计, 并带有一些有用的类库.
* 依赖注入, 实现了IoC构架, 为开发者更好的降低类的依赖性.
* 地址映射, 这是框架的基础, 开发者可以自己定义匹配地址, 并映射到专门的类中运行.
* 标签引擎, PhpTagLib是框架中重要的MVC实现, 允许开发者定义像HTML/XML这样的标签, 实现组件化开发.
* Action模块, 强大的数据处理构架, 支持采用标签方式调用, 支持多个Action合并使用.
* 迭代器, 扩展增强PHP的迭代器(Iterator)接口, 并融合进框架中的其它模块.
* 数据库, 对PEAR DB的重新封装, 支持同时连接多个数据库, 并提供通过标签直接查询.
* 分页类, 数据分页和分页导行分开, 可更好的扩展分页, 基于迭代器可以对任何数据的迭代器分页.
* 缓存, 提供统一的缓存构架, 开发者可以方便的扩展, 支持通过缓存标签缓存页面中的内容.
* 测试引擎, 支持TDD开发方法, 敏捷开发的必需品, 支持单独运行一个测试用例, 也支持运行测试组.
* 对象模仿, 不仅可以Mock指定的类/接口, 还可以Mock父类以分离父类进行测试.
* PlainObject, 支持写一个普通的类, 不继承任何类, 不实现任何接口, 可直接用做标签类或Action类使用.
* 传统页面, 可以直接访问传统的PHP页面, HTML页面, 图片, 脚本等等文件.
* 单一入口, 可以在入口程序中设置框架环境.
* 调试, 支持更详细的错误/异常提供, 支持提示环境中的一些信息.
* XML格式的配置文件, 使配置更直观, 灵活.
* 自带有PEAR中的一些基本和常用的类库.
* 免费的, 开源的. 使用BSD开源协议发行, 你可以用在任何项目中.

框架网站: http://www.wonderfulproject.cn
Google Code: http://code.google.com/p/wonderfulframework 

示例: http://www.wonderfulproject.cn/door.php/example.php

相关文章: 
PhpTagLib的MVC分层设计
迭代器(Iterator)和分页(Page)类库介绍
框架中Action的特性: 组件和组合
在框架中使用FCKEditor

趁过年时, 有些时间发布个新版本.
本框架主要定位在系统开发方面, 提供了些敏捷方面的技术.
随着框架在实际项目中不断应用和实践, 整体的构架已经趋向稳定, 且在易用性上也做了些改进.
将来框架会继续完善构架, 丰富各个库(类库, 标签库, Action库, Validator库), 增强易用性, 增加控制平台, 提高效率等等方面.

------解决方案--------------------
文档在那里?文档在那里?
------解决方案--------------------
大致看了一下demo

你的框架不太适合php

1、框架连autoload都没实现,要知道在PHP中引用包含文件是件很麻烦的事情。
2、MVC没看到M和V嘛,那个“PhpTagLib”算作V的话实在有点勉强
3、Action的参数很复杂呀――“WDF_ActionForm & $form, WDF_ActionErrors & $errors”,要知道没有IDE或工具自动生成代码的话,参数是越简单越好的。
4、输出用$this->response->writeln,这也太复杂了吧。$this->output不是挺好
5、XML格式的配置文件可以直接用PHP Array实现,,可读性也不差,PHP本身就是动态脚本,应该好好利用这个特点。
6、获取action参数要用$form->getValue,是不是复杂了点?
public function process(string $username) { ... } 这样最好了

这个框架实在太中规中矩了,要知道PHP是低效的动态脚本语言,不像java/C#,这样的框架不适合PHP

------解决方案--------------------
首先我还没看过源代码,所以有些所提问题的不周之处还请谅解。

> 1、框架连autoload都没实现,要知道在PHP中引用包含文件是件很麻烦的事情。 
>这个很早我就在想要怎么加入? 我是这样考虑的, autoload要怎么知道要载入哪个文件呢? 通过类命名规则? 那类名会很长呀! 也许可以用命名空间, 但PHP5.3才支持命名空间, 但这样的话其实命名还是很长, 除非使用别名, 别名会比include方便多少呢? 

一般通过类名实现autoload,根据优先级,到各个目录下寻找有无对应的包含文件,如果有同名类,可以用类似using(...);的函数来设置一个全局标记,告诉autoload应该优先到哪个目录加载。
实现autoload,主要依赖lib的目录组织,如果组织得好,会大大便于实现autoload。

-----------------

 
> 3、Action的参数很复杂呀――“WDF_ActionForm & $form, WDF_ActionErrors & $errors”,要知道没有IDE或工具自动生成代码的话,参数是越简单越好的。 
>嗯, 我也认同参数越简单越好, 但这已经是最简单了, 这两个参数对象已经把主要的数据进行归类了. 

为啥不把$form作为controller的成员,而要作为参数传递?
为啥不采用php内置的异常处理?class ActionException extends Exception { ... }
throw new ActionException(...);

--------------


> 6、获取action参数要用$form->getValue,是不是复杂了点? 
> public function process(string $username) { ... } 这样最好了 
> 不会最好, 反而更糟. 一个username一个参数, 那还有其它的数据呢? 有一个增加一个, 只会更糟. 


我的意思是这样:
public function process(string $username) { ... } 
$username是必要参数,缺少则controller报错

public function process(string $username = null) { ... } 
则表明$username是可选参数

页面传递的其余参数仍然可以通过$form来访问

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Explain how load balancing affects session management and how to address it.Explain how load balancing affects session management and how to address it.Apr 29, 2025 am 12:42 AM

Load balancing affects session management, but can be resolved with session replication, session stickiness, and centralized session storage. 1. Session Replication Copy session data between servers. 2. Session stickiness directs user requests to the same server. 3. Centralized session storage uses independent servers such as Redis to store session data to ensure data sharing.

Explain the concept of session locking.Explain the concept of session locking.Apr 29, 2025 am 12:39 AM

Sessionlockingisatechniqueusedtoensureauser'ssessionremainsexclusivetooneuseratatime.Itiscrucialforpreventingdatacorruptionandsecuritybreachesinmulti-userapplications.Sessionlockingisimplementedusingserver-sidelockingmechanisms,suchasReentrantLockinJ

Are there any alternatives to PHP sessions?Are there any alternatives to PHP sessions?Apr 29, 2025 am 12:36 AM

Alternatives to PHP sessions include Cookies, Token-based Authentication, Database-based Sessions, and Redis/Memcached. 1.Cookies manage sessions by storing data on the client, which is simple but low in security. 2.Token-based Authentication uses tokens to verify users, which is highly secure but requires additional logic. 3.Database-basedSessions stores data in the database, which has good scalability but may affect performance. 4. Redis/Memcached uses distributed cache to improve performance and scalability, but requires additional matching

Define the term 'session hijacking' in the context of PHP.Define the term 'session hijacking' in the context of PHP.Apr 29, 2025 am 12:33 AM

Sessionhijacking refers to an attacker impersonating a user by obtaining the user's sessionID. Prevention methods include: 1) encrypting communication using HTTPS; 2) verifying the source of the sessionID; 3) using a secure sessionID generation algorithm; 4) regularly updating the sessionID.

What is the full form of PHP?What is the full form of PHP?Apr 28, 2025 pm 04:58 PM

The article discusses PHP, detailing its full form, main uses in web development, comparison with Python and Java, and its ease of learning for beginners.

How does PHP handle form data?How does PHP handle form data?Apr 28, 2025 pm 04:57 PM

PHP handles form data using $\_POST and $\_GET superglobals, with security ensured through validation, sanitization, and secure database interactions.

What is the difference between PHP and ASP.NET?What is the difference between PHP and ASP.NET?Apr 28, 2025 pm 04:56 PM

The article compares PHP and ASP.NET, focusing on their suitability for large-scale web applications, performance differences, and security features. Both are viable for large projects, but PHP is open-source and platform-independent, while ASP.NET,

Is PHP a case-sensitive language?Is PHP a case-sensitive language?Apr 28, 2025 pm 04:55 PM

PHP's case sensitivity varies: functions are insensitive, while variables and classes are sensitive. Best practices include consistent naming and using case-insensitive functions for comparisons.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function