Archive for the Tag: 'zend'
Zend Studio Neon Beta
Just tried a little. Pretty cool.
1. Really modern IDE (based on Eclipse)
2. Zend Framework support
3. Refactory support (poor…… so far)
4. Debug and Profile
5. PHPUnit
6. PHPDoc
7. SVN and CVS
8. BIRT
9. Other Zend stuffs integration
10. WYSIWYG editor
11. FTP
12. Database
Microsoft和Zend的合作
前2天Microsoft和Zend宣布了双方的合作. 重点在于PHP在windows上的部署, 性能和稳定性. 为此微软为之开发了IIS的FastCGI模块(Scott Gu的介绍Blog). 而Zend也为此成立专门的Lab和管理人员来提升PHP在windows上的稳定性和性能.
随着web 2.0的风潮, 微软已经变得越来越开放, CodePlex上很多项目其实是Internal的CodePlex上出来的. 而各个开发Team的PM, Dev, Test也都有着各自的blog发布相关的信息及收集feedback.
而微软和Zend的合作, 让我感觉俨然PHP真正成了Zend自家的东西.
Zend Framework Preview 0.2.0 Release
发布了一堆所谓的新特性, 目前都还在incubator目录中, 不知道具体是指什么, 邮件列表中也看到有人问了. 新的东西有:
* New MVC implementation
* New HTTP request and response objects make it easy to automate
unit testing for web apps without a web server, and also make it
possible to use MVC for command-line and PHP-GTK application development
* Enhanced pure PHP Lucene-compatible search engine component
* New Mysqli DB adapter
* New JSON server
* New REST client and server
* New XmlRpc client and server
* New Acl component
* New Session component
* New Web Services clients for Delicious and Audioscrobbler
* New Registry component
* Significant improvements to many other components
imporving是好事. 可惜Diggmore的一部分代码耦合在Zend本身. 其实所谓的新MVC, 最大的改变也只是抛弃了原来的token, 而把其封装城了Request和Response. 不过幸好, 如果你并没有实现自己的dispatcher, front, router… 等等, 那也还好. 可惜diggmore那时候偏偏去实现了他的接口. 我真是有够白痴… download: http://framework.zend.com/download
新的components还都挺不错的. 特别是server那块. 同时发布的还有google GData的PHP的client的lib实现.
How to Integrate HessianPHP with Diggmore Action
Hessian是Caucho的一个Web Service协议, 使用二进制数据传输. 相比SOAP来更加简单, 而且速度更快. 目前该协议有多种语言的实现, 如java, .net, ruby等等. 而HessianPHP是hessian的PHP的实现.
Diggmore是PHPMore在Zend Framework基础上所做的一个框架性应用. Action是Diggmore中的基本执行单元. 执行的时候会by Name的Autoware. 下面是一个简单的范例.
code 1 HessianResultType
require_once(dirname(__FILE__).”/ResultType.php”);
require_once(dirname(__FILE__).”/../3rd/hessianphp/HessianService.php”);
/**
* @package DiggMore
* @subpackage Core
* @copyright Copyright (c) 2006 PHP More. (http://www.phpmore.com/)
* @author Binzy Wu
*/
class HessianResultType implements ResultType
{
/**
*
* @see ResultType::process
*
*/
public function process($result, Action $action, $controller = null)
{
$wrapper = new HessianService();
$action_config = $action->getConfig();
$resource = $action_config[$result][’resource’];
$wrapper->registerObject($action->$resource);
$wrapper->displayInfo = true;
$wrapper->service();
}
}
(more…)
Essential Zend Controller (3)
3. Zend Controller之Router
[English Version]
Router的核心工作非常简单. 便是从请求的参数中为Zend_Controller_Front产生Zend_Controller_Dispatcher_Token. Zend Framework默认的Router是通过解析请求的URI来处理的. 如http://your.com/test/add会被解析成一个叫”TestController”的Controller和controller中一个叫”addAction”的方法. controller信息和action信息及其他参数将被封装成Zend_Controller_Dispatcher_Token.
在我们知道原理以后, 我们可以非常轻松的写我们所需要的router. 如, 当我们的web server不支持url_rewriter的时候我们需要一个NoRewriterRouter. 而当我们在一个虚拟主机的子目录里, 那么我们可能需要一个SubDirectoryRouter..
在diggmore的开发过程中, 我写了一个SubDirectoryRouter. 和最初在maillist里流传的稍有不同, 稍微严谨一些.
/**
*
* Sub Directory Router for diggmore
*
*/
class SubDirectoryRouter implements Zend_Controller_Router_Interface
{
//
private $sub_directory;
public function setSubDirectory($sub_directory)
{
$this->sub_directory = $sub_directory;
return $this;
}
public function route(Zend_Controller_Dispatcher_Interface $dispatcher)
{
//
$path = $_SERVER[’REQUEST_URI’];
if (strstr($path, ‘?’)) {
$path = substr($path, 0, strpos($path, ‘?’));
}
$path = explode(’/', trim($path, ‘/’));
$start = 2;
if ($this->sub_directory != ”)
{
//
$tmp = explode(’/', trim($this->sub_directory, ‘/’));
$start = sizeof($tmp) + 2;
}
$controller = $path[$start-2];
$action = isset($path[$start-1]) ? $path[$start-1] : null;
$params = array();
for ($i=$start; $i $params[$path[$i]] = isset($path[$i+1]) ? $path[$i+1] : null;
}
$token = new Zend_Controller_Dispatcher_Token($controller, $action, $params);
if (!$dispatcher->isDispatchable($token)) {
throw new Zend_Controller_Router_Exception(’Request could not be mapped to a route.’);
} else {
return $token;
}
}
}
Essential Zend Controller (2)
2. Zend Controller之Front
Zend Controller本身的处理流程较为简单直接. 下图来自HaoHappy的Zend文档中文译本中. 核心流程便如图所示.
但细节上却不尽如此.
首先Zend Framework采用了传统的Front Controller模式来对整个Request的处理进行了封装. 整个Front大致如下图所示.
Zend_Ctonroller_Front中最重要的方法就是dispatch了, 可以看作是一个Application的整个执行中心. 在dispatch方法中, 第一个动作是调用Router来根据Url进行route, 第二个动作便是调用Dispatcher来根据route过来的Action (实质是Controller_Dispather_Token)来进行dispatch, 而这个过程将根据Action的具体信息来循环执行, 即如果所执行的Action返回的还是一个Controller_Dispatcher_Token, 即Action的话, dispatch便会继续执行下一个Action. 这样设计可以实现简单的Action Chain.
同时在route和dispath前后都会通知plugin(s), 以达到各种处理的目的, 比如执行时间的统计, log的记录等等. Zend_Ctonroller_Front中的_plugins属性是Plugin_Broker, 即Plugin代理, 用于真正装配Plugin及执行Plugin, 而Plugin_Broker本身自然也是一个Plugin.
另外要提到一下, 从Front的实现中可以看到一个特性, 即方法都返回自身. 如:
[code=php]Zend_Front::getInstance()
->setControllerDirectory($controllerDirectory)
->dispatch();[/code]
Martin Fowler称之为FluentInterface. 这样的写法有利有弊. 不作讨论.
zendframework
Essential Zend Controller (1)
其实我本无意取这样的Title, 不过想不到其他的, 就用吧.
1. Zend Controller中的7个基本角色
Front: 相当于Application的Container.
Plugins_Broker: Plugins的代理.
Plugins: Front的Plugins, 可对整个Application的过程及Action进行操作或者记录.
Router: 根据Request的Url来route到具体的Controller及Action
Dispatcher: 根据route过来的dispatch token来创建Controller并执行Action.
Controller: Zend Framework中的Controller是一个Action的聚合体, 本身起一个真正执行具体Action的作用.
Action: 聚合于Controller内部, 具体体现为一个个Action方法. 在Action内部可调用业务逻辑层进行处理并获得model给view.
待续…
Zend



