├── .gitattributes
├── .travis.yml
├── CREDITS
├── EXPERIMENTAL
├── LICENSE
├── README.md
├── config.m4
├── config.w32
├── configs
├── ini.c
└── simple.c
├── package2.xml
├── php_yaf.h
├── requests
├── http.c
└── simple.c
├── response
├── cli.c
└── http.c
├── routes
├── interface.c
├── map.c
├── regex.c
├── rewrite.c
├── simple.c
├── static.c
└── supervar.c
├── tests
├── 001.phpt
├── 002.phpt
├── 003.phpt
├── 004.phpt
├── 005.phpt
├── 006.phpt
├── 007.phpt
├── 008.phpt
├── 009.phpt
├── 010.phpt
├── 011.phpt
├── 012.phpt
├── 013.phpt
├── 014.phpt
├── 015.phpt
├── 016.phpt
├── 017.phpt
├── 018.phpt
├── 019.phpt
├── 020.phpt
├── 021.phpt
├── 022.phpt
├── 023.phpt
├── 024.phpt
├── 025.phpt
├── 026.phpt
├── 027.phpt
├── 028.phpt
├── 029.phpt
├── 030.phpt
├── 031.phpt
├── 032.phpt
├── 033.phpt
├── 034.phpt
├── 035.phpt
├── 036.phpt
├── 037.phpt
├── 038.phpt
├── 039.phpt
├── 040.phpt
├── 041.phpt
├── 042.phpt
├── 043.phpt
├── 044.phpt
├── 045.phpt
├── 046.phpt
├── 047.phpt
├── 048.phpt
├── 049.phpt
├── 050.phpt
├── 051.phpt
├── 052.phpt
├── 053.phpt
├── 054.phpt
├── 055.phpt
├── 056.phpt
├── 057.phpt
├── 058.phpt
├── 059.phpt
├── 060.phpt
├── 061.phpt
├── 062.phpt
├── bug61493.phpt
├── bug62702.phpt
├── bug63381.phpt
├── bug63438.phpt
├── bug63900.phpt
├── build.inc
├── simple.ini
└── system.ini
├── tools
├── cg
│ ├── README.md
│ ├── templates
│ │ ├── .htaccess.tpl
│ │ ├── application
│ │ │ ├── Bootstrap.php.tpl
│ │ │ ├── controllers
│ │ │ │ ├── Error.php.tpl
│ │ │ │ └── Index.php.tpl
│ │ │ ├── library
│ │ │ │ └── readme.txt.tpl
│ │ │ ├── models
│ │ │ │ └── Sample.php.tpl
│ │ │ ├── plugins
│ │ │ │ └── Sample.php.tpl
│ │ │ └── views
│ │ │ │ ├── error
│ │ │ │ └── error.phtml.tpl
│ │ │ │ └── index
│ │ │ │ └── index.phtml.tpl
│ │ ├── conf
│ │ │ └── application.ini.tpl
│ │ ├── index.php.tpl
│ │ └── readme.txt.tpl
│ └── yaf_cg
├── yaf.php
└── yaf_classes.php
├── travis
└── compile.sh
├── views
├── interface.c
└── simple.c
├── yaf.c
├── yaf.dsp
├── yaf.php
├── yaf_action.c
├── yaf_action.h
├── yaf_application.c
├── yaf_application.h
├── yaf_bootstrap.c
├── yaf_bootstrap.h
├── yaf_config.c
├── yaf_config.h
├── yaf_controller.c
├── yaf_controller.h
├── yaf_dispatcher.c
├── yaf_dispatcher.h
├── yaf_exception.c
├── yaf_exception.h
├── yaf_loader.c
├── yaf_loader.h
├── yaf_logo.h
├── yaf_namespace.h
├── yaf_plugin.c
├── yaf_plugin.h
├── yaf_registry.c
├── yaf_registry.h
├── yaf_request.c
├── yaf_request.h
├── yaf_response.c
├── yaf_response.h
├── yaf_router.c
├── yaf_router.h
├── yaf_session.c
├── yaf_session.h
├── yaf_view.c
└── yaf_view.h
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.phpt eol=lf
2 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: php
2 |
3 | php:
4 | - 5.2
5 | - 5.3
6 | - 5.4
7 |
8 | notifications:
9 | email: false
10 | irc: "irc.efnet.org#php.yaf"
11 |
12 | env:
13 | - REPORT_EXIT_STATUS=1 NO_INTERACTION=1
14 |
15 | #Compile
16 | before_script:
17 | - ./travis/compile.sh
18 |
19 | # Run PHPs run-tests.php
20 | script: make test
21 |
--------------------------------------------------------------------------------
/CREDITS:
--------------------------------------------------------------------------------
1 | Yaf
2 | Xinchen Hui
3 |
--------------------------------------------------------------------------------
/EXPERIMENTAL:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wenjun1055/annotated_yaf_source/67267bfbb5f005738d6e03a44c0e8ac26410f777/EXPERIMENTAL
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | --------------------------------------------------------------------
2 | The PHP License, version 3.01
3 | Copyright (c) 1999 - 2011 The PHP Group. All rights reserved.
4 | --------------------------------------------------------------------
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, is permitted provided that the following conditions
8 | are met:
9 |
10 | 1. Redistributions of source code must retain the above copyright
11 | notice, this list of conditions and the following disclaimer.
12 |
13 | 2. Redistributions in binary form must reproduce the above copyright
14 | notice, this list of conditions and the following disclaimer in
15 | the documentation and/or other materials provided with the
16 | distribution.
17 |
18 | 3. The name "PHP" must not be used to endorse or promote products
19 | derived from this software without prior written permission. For
20 | written permission, please contact group@php.net.
21 |
22 | 4. Products derived from this software may not be called "PHP", nor
23 | may "PHP" appear in their name, without prior written permission
24 | from group@php.net. You may indicate that your software works in
25 | conjunction with PHP by saying "Foo for PHP" instead of calling
26 | it "PHP Foo" or "phpfoo"
27 |
28 | 5. The PHP Group may publish revised and/or new versions of the
29 | license from time to time. Each version will be given a
30 | distinguishing version number.
31 | Once covered code has been published under a particular version
32 | of the license, you may always continue to use it under the terms
33 | of that version. You may also choose to use such covered code
34 | under the terms of any subsequent version of the license
35 | published by the PHP Group. No one other than the PHP Group has
36 | the right to modify the terms applicable to covered code created
37 | under this License.
38 |
39 | 6. Redistributions of any form whatsoever must retain the following
40 | acknowledgment:
41 | "This product includes PHP software, freely available from
42 | ".
43 |
44 | THIS SOFTWARE IS PROVIDED BY THE PHP DEVELOPMENT TEAM ``AS IS'' AND
45 | ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
46 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
47 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PHP
48 | DEVELOPMENT TEAM OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
49 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
50 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
51 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
53 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
55 | OF THE POSSIBILITY OF SUCH DAMAGE.
56 |
57 | --------------------------------------------------------------------
58 |
59 | This software consists of voluntary contributions made by many
60 | individuals on behalf of the PHP Group.
61 |
62 | The PHP Group can be contacted via Email at group@php.net.
63 |
64 | For more information on the PHP Group and the PHP project,
65 | please see .
66 |
67 | PHP includes the Zend Engine, freely available at
68 | .
69 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Annotated Yaf Source
2 |
3 | 此项目纯属膜拜鸟哥的yaf,边学边看边注释吧。
4 |
5 |
6 | 源码是 [<< yaf-2.2.9 >>](https://github.com/laruence/php-yaf/tree/yaf-2.2.9)
--------------------------------------------------------------------------------
/config.m4:
--------------------------------------------------------------------------------
1 | PHP_ARG_ENABLE(yaf, whether to enable yaf support,
2 | [ --enable-yaf Enable yaf support])
3 |
4 | AC_ARG_ENABLE(yaf-debug,
5 | [ --enable-yaf-debug Enable yaf debug mode default=no],
6 | [PHP_YAF_DEBUG=$enableval],
7 | [PHP_YAF_DEBUG="no"])
8 |
9 | if test "$PHP_YAF" != "no"; then
10 |
11 | if test "$PHP_YAF_DEBUG" = "yes"; then
12 | AC_DEFINE(PHP_YAF_DEBUG,1,[define to 1 if you want to change the POST/GET by php script])
13 | else
14 | AC_DEFINE(PHP_YAF_DEBUG,0,[define to 1 if you want to change the POST/GET by php script])
15 | fi
16 |
17 | AC_MSG_CHECKING([PHP version])
18 |
19 | tmp_version=$PHP_VERSION
20 | if test -z "$tmp_version"; then
21 | if test -z "$PHP_CONFIG"; then
22 | AC_MSG_ERROR([php-config not found])
23 | fi
24 | php_version=`$PHP_CONFIG --version 2>/dev/null|head -n 1|sed -e 's#\([0-9]\.[0-9]*\.[0-9]*\)\(.*\)#\1#'`
25 | else
26 | php_version=`echo "$tmp_version"|sed -e 's#\([0-9]\.[0-9]*\.[0-9]*\)\(.*\)#\1#'`
27 | fi
28 |
29 | if test -z "$php_version"; then
30 | AC_MSG_ERROR([failed to detect PHP version, please report])
31 | fi
32 |
33 | ac_IFS=$IFS
34 | IFS="."
35 | set $php_version
36 | IFS=$ac_IFS
37 | yaf_php_version=`expr [$]1 \* 1000000 + [$]2 \* 1000 + [$]3`
38 |
39 | if test "$yaf_php_version" -le "5002000"; then
40 | AC_MSG_ERROR([You need at least PHP 5.2.0 to be able to use this version of Yaf. PHP $php_version found])
41 | else
42 | AC_MSG_RESULT([$php_version, ok])
43 | fi
44 | PHP_NEW_EXTENSION(yaf, yaf.c yaf_application.c yaf_bootstrap.c yaf_dispatcher.c yaf_exception.c yaf_config.c yaf_request.c yaf_response.c yaf_view.c yaf_controller.c yaf_action.c yaf_router.c yaf_loader.c yaf_registry.c yaf_plugin.c yaf_session.c, $ext_shared)
45 | fi
46 |
--------------------------------------------------------------------------------
/config.w32:
--------------------------------------------------------------------------------
1 | // $Id: config.w32 765 2010-10-21 13:04:03Z huixinchen $
2 | // vim:ft=javascript
3 |
4 | ARG_ENABLE("yaf", "enable yaf support", "no");
5 |
6 | if (PHP_YAF == "yes") {
7 | EXTENSION("yaf", "yaf.c yaf_application.c yaf_loader.c yaf_bootstrap.c yaf_config.c yaf_dispatcher.c yaf_registry.c yaf_controller.c yaf_action.c yaf_view.c yaf_request.c yaf_response.c yaf_router.c yaf_exception.c yaf_plugin.c yaf_session.c");
8 |
9 | AC_DEFINE("HAVE_YAF", 1, "Have Yaf Support");
10 | }
11 |
--------------------------------------------------------------------------------
/php_yaf.h:
--------------------------------------------------------------------------------
1 | /*
2 | +----------------------------------------------------------------------+
3 | | Yet Another Framework |
4 | +----------------------------------------------------------------------+
5 | | This source file is subject to version 3.01 of the PHP license, |
6 | | that is bundled with this package in the file LICENSE, and is |
7 | | available through the world-wide-web at the following url: |
8 | | http://www.php.net/license/3_01.txt |
9 | | If you did not receive a copy of the PHP license and are unable to |
10 | | obtain it through the world-wide-web, please send a note to |
11 | | license@php.net so we can mail you a copy immediately. |
12 | +----------------------------------------------------------------------+
13 | | Author: Xinchen Hui |
14 | +----------------------------------------------------------------------+
15 | */
16 |
17 | /* $Id: php_yaf.h 328979 2013-01-04 10:50:55Z laruence $ */
18 |
19 | #ifndef PHP_YAF_H
20 | #define PHP_YAF_H
21 |
22 | extern zend_module_entry yaf_module_entry;
23 | #define phpext_yaf_ptr &yaf_module_entry
24 |
25 | #ifdef PHP_WIN32
26 | #define PHP_YAF_API __declspec(dllexport)
27 | #ifndef _MSC_VER
28 | #define _MSC_VER 1600
29 | #endif
30 | #else
31 | #define PHP_YAF_API
32 | #endif
33 |
34 | #ifdef ZTS
35 | #include "TSRM.h"
36 | #endif
37 |
38 | #ifdef ZTS
39 | #define YAF_G(v) TSRMG(yaf_globals_id, zend_yaf_globals *, v)
40 | #else
41 | #define YAF_G(v) (yaf_globals.v)
42 | #endif
43 |
44 | #define YAF_VERSION "2.2.9"
45 |
46 | #define YAF_STARTUP_FUNCTION(module) ZEND_MINIT_FUNCTION(yaf_##module)
47 | #define YAF_RINIT_FUNCTION(module) ZEND_RINIT_FUNCTION(yaf_##module)
48 | #define YAF_STARTUP(module) ZEND_MODULE_STARTUP_N(yaf_##module)(INIT_FUNC_ARGS_PASSTHRU)
49 | #define YAF_SHUTDOWN_FUNCTION(module) ZEND_MINIT_FUNCTION(yaf_##module)
50 | #define YAF_SHUTDOWN(module) ZEND_MODULE_SHUTDOWN_N(yaf_##module)(INIT_FUNC_ARGS_PASSTHRU)
51 |
52 | #if ((PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION > 2)) || (PHP_MAJOR_VERSION > 5)
53 | #define YAF_HAVE_NAMESPACE
54 | #else
55 | #define Z_SET_REFCOUNT_P(pz, rc) (pz)->refcount = rc
56 | #define Z_SET_REFCOUNT_PP(ppz, rc) Z_SET_REFCOUNT_P(*(ppz), rc)
57 | #define Z_ADDREF_P ZVAL_ADDREF
58 | #define Z_REFCOUNT_P ZVAL_REFCOUNT
59 | #define Z_DELREF_P ZVAL_DELREF
60 | #endif
61 |
62 | #define yaf_application_t zval
63 | #define yaf_view_t zval
64 | #define yaf_controller_t zval
65 | #define yaf_request_t zval
66 | #define yaf_router_t zval
67 | #define yaf_route_t zval
68 | #define yaf_dispatcher_t zval
69 | #define yaf_action_t zval
70 | #define yaf_loader_t zval
71 | #define yaf_response_t zval
72 | #define yaf_config_t zval
73 | #define yaf_registry_t zval
74 | #define yaf_plugin_t zval
75 | #define yaf_session_t zval
76 | #define yaf_exception_t zval
77 |
78 | #define YAF_ME(c, m, a, f) {m, PHP_MN(c), a, (zend_uint) (sizeof(a)/sizeof(struct _zend_arg_info)-1), f},
79 |
80 | extern PHPAPI void php_var_dump(zval **struc, int level TSRMLS_DC);
81 | extern PHPAPI void php_debug_zval_dump(zval **struc, int level TSRMLS_DC);
82 |
83 | ZEND_BEGIN_MODULE_GLOBALS(yaf)
84 | char *ext; //脚本后缀
85 | char *base_uri; //base_uri
86 | char *environ; //环境名称, 当用INI作为Yaf的配置文件时, 这个指明了Yaf将要在INI配置中读取的节的名字
87 | char *directory; //application目录路径
88 | char *local_library; //本地类库
89 | char *local_namespaces; //本地类前缀(字符串形式,类似::Foo:Bar:)
90 | char *global_library; //全局类库
91 | char *view_directory; //视图文件目录路径
92 | char *view_ext; //视图文件后缀
93 | char *default_module; //默认module
94 | char *default_controller; //默认controller
95 | char *default_action; //默认action
96 | char *bootstrap; //bootstrap路径
97 | char *name_separator; //类名分隔符
98 | long name_separator_len; //类名分隔符长度
99 | zend_bool lowcase_path; //开启的情况下,路径信息中的目录部分都会被转换成小写
100 | zend_bool use_spl_autoload; //开启的情况下,Yaf在加载不成功的情况下,会继续让PHP的自动加载函数加载,从性能考虑,除非特殊情况,否则保持这个选项关闭
101 | zend_bool throw_exception;
102 | zend_bool cache_config; //是否缓存配置文件(只针对INI配置文件生效),打开此选项可在复杂配置的情况下提高性能
103 | zend_bool action_prefer; //当PATH_INFO只有一部分的时候,将其作为controller还是action,配置打开则为action
104 | zend_bool name_suffix; //在处理Controller, Action, Plugin, Model的时候, 类名中关键信息是否是后缀式,比如UserModel, 而在前缀模式下则是ModelUser
105 | zend_bool autoload_started;
106 | zend_bool running;
107 | zend_bool in_exception;
108 | zend_bool catch_exception;
109 | zend_bool suppressing_warning;
110 | /* {{{ This only effects internally */
111 | zend_bool st_compatible; //打开后到model下找相关Dao和Service
112 | /* }}} */
113 | long forward_limit; //forward最大嵌套深度
114 | HashTable *configs; //配置缓存
115 | zval *modules;
116 | zval *default_route; //默认路由
117 | #if ((PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 4))
118 | uint buf_nesting;
119 | void *buffer;
120 | void *owrite_handler;
121 | #endif
122 | zval *active_ini_file_section; //ini配置文件活跃的单节,类似[common]
123 | zval *ini_wanted_section;
124 | uint parsing_flag; //配置文件解析进度标识
125 | #ifdef YAF_HAVE_NAMESPACE
126 | zend_bool use_namespace; //开启的情况下, Yaf将会使用命名空间方式注册自己的类, 比如Yaf_Application将会变成Yaf\Application
127 | #endif
128 | ZEND_END_MODULE_GLOBALS(yaf)
129 |
130 | PHP_MINIT_FUNCTION(yaf);
131 | PHP_MSHUTDOWN_FUNCTION(yaf);
132 | PHP_RINIT_FUNCTION(yaf);
133 | PHP_RSHUTDOWN_FUNCTION(yaf);
134 | PHP_MINFO_FUNCTION(yaf);
135 |
136 | extern ZEND_DECLARE_MODULE_GLOBALS(yaf);
137 |
138 | #endif
139 | /*
140 | * Local variables:
141 | * tab-width: 4
142 | * c-basic-offset: 4
143 | * End:
144 | * vim600: noet sw=4 ts=4 fdm=marker
145 | * vim<600: noet sw=4 ts=4
146 | */
147 |
--------------------------------------------------------------------------------
/response/cli.c:
--------------------------------------------------------------------------------
1 | /*
2 | +----------------------------------------------------------------------+
3 | | Yet Another Framework |
4 | +----------------------------------------------------------------------+
5 | | This source file is subject to version 3.01 of the PHP license, |
6 | | that is bundled with this package in the file LICENSE, and is |
7 | | available through the world-wide-web at the following url: |
8 | | http://www.php.net/license/3_01.txt |
9 | | If you did not receive a copy of the PHP license and are unable to |
10 | | obtain it through the world-wide-web, please send a note to |
11 | | license@php.net so we can mail you a copy immediately. |
12 | +----------------------------------------------------------------------+
13 | | Author: Xinchen Hui |
14 | +----------------------------------------------------------------------+
15 | */
16 |
17 | /* $Id: cli.c 321289 2011-12-21 02:53:29Z laruence $ */
18 |
19 |
20 | zend_class_entry * yaf_response_cli_ce;
21 |
22 | /** {{{ yaf_response_methods
23 | */
24 | zend_function_entry yaf_response_cli_methods[] = {
25 | {NULL, NULL, NULL}
26 | };
27 | /* }}} */
28 |
29 | /** {{{ YAF_STARTUP_FUNCTION
30 | */
31 | YAF_STARTUP_FUNCTION(response_cli) {
32 | zend_class_entry ce;
33 |
34 | YAF_INIT_CLASS_ENTRY(ce, "Yaf_Response_Cli", "Yaf\\Response\\Cli", yaf_response_cli_methods);
35 | /* class Yaf_Response_Cli extends Yaf_Response_Abstract */
36 | yaf_response_cli_ce = zend_register_internal_class_ex(&ce, yaf_response_ce, NULL TSRMLS_CC);
37 |
38 | return SUCCESS;
39 | }
40 | /* }}} */
41 |
42 | /*
43 | * Local variables:
44 | * tab-width: 4
45 | * c-basic-offset: 4
46 | * End:
47 | * vim600: noet sw=4 ts=4 fdm=marker
48 | * vim<600: noet sw=4 ts=4
49 | */
50 |
--------------------------------------------------------------------------------
/response/http.c:
--------------------------------------------------------------------------------
1 | /*
2 | +----------------------------------------------------------------------+
3 | | Yet Another Framework |
4 | +----------------------------------------------------------------------+
5 | | This source file is subject to version 3.01 of the PHP license, |
6 | | that is bundled with this package in the file LICENSE, and is |
7 | | available through the world-wide-web at the following url: |
8 | | http://www.php.net/license/3_01.txt |
9 | | If you did not receive a copy of the PHP license and are unable to |
10 | | obtain it through the world-wide-web, please send a note to |
11 | | license@php.net so we can mail you a copy immediately. |
12 | +----------------------------------------------------------------------+
13 | | Author: Xinchen Hui |
14 | +----------------------------------------------------------------------+
15 | */
16 |
17 | /* $Id: http.c 321289 2011-12-21 02:53:29Z laruence $ */
18 |
19 | zend_class_entry *yaf_response_http_ce;
20 |
21 | /** {{{ yaf_response_methods
22 | */
23 | zend_function_entry yaf_response_http_methods[] = {
24 | {NULL, NULL, NULL}
25 | };
26 | /* }}} */
27 |
28 | /** {{{ YAF_STARTUP_FUNCTION
29 | */
30 | YAF_STARTUP_FUNCTION(response_http) {
31 | zend_class_entry ce;
32 |
33 | YAF_INIT_CLASS_ENTRY(ce, "Yaf_Response_Http", "Yaf\\Response\\Http", yaf_response_http_methods);
34 | /* class Yaf_Response_Http extends Yaf_Response_Abstract */
35 | yaf_response_http_ce = zend_register_internal_class_ex(&ce, yaf_response_ce, NULL TSRMLS_CC);
36 |
37 | /**
38 | * protected $_sendheader = true;
39 | * protected $_response_code = 200;
40 | */
41 | zend_declare_property_bool(yaf_response_http_ce, ZEND_STRL(YAF_RESPONSE_PROPERTY_NAME_HEADEREXCEPTION), 1, ZEND_ACC_PROTECTED TSRMLS_CC);
42 | zend_declare_property_long(yaf_response_http_ce, ZEND_STRL(YAF_RESPONSE_PROPERTY_NAME_RESPONSECODE), 200, ZEND_ACC_PROTECTED TSRMLS_CC);
43 |
44 | return SUCCESS;
45 | }
46 | /* }}} */
47 |
48 | /*
49 | * Local variables:
50 | * tab-width: 4
51 | * c-basic-offset: 4
52 | * End:
53 | * vim600: noet sw=4 ts=4 fdm=marker
54 | * vim<600: noet sw=4 ts=4
55 | */
56 |
--------------------------------------------------------------------------------
/routes/interface.c:
--------------------------------------------------------------------------------
1 | /*
2 | +----------------------------------------------------------------------+
3 | | Yet Another Framework |
4 | +----------------------------------------------------------------------+
5 | | This source file is subject to version 3.01 of the PHP license, |
6 | | that is bundled with this package in the file LICENSE, and is |
7 | | available through the world-wide-web at the following url: |
8 | | http://www.php.net/license/3_01.txt |
9 | | If you did not receive a copy of the PHP license and are unable to |
10 | | obtain it through the world-wide-web, please send a note to |
11 | | license@php.net so we can mail you a copy immediately. |
12 | +----------------------------------------------------------------------+
13 | | Author: Xinchen Hui |
14 | +----------------------------------------------------------------------+
15 | */
16 |
17 | /* $Id: interface.c 326042 2012-06-08 10:49:59Z laruence $ */
18 |
19 | #include "ext/standard/php_smart_str.h"
20 |
21 | #define YAF_ROUTE_PROPETY_NAME_MATCH "_route"
22 | #define YAF_ROUTE_PROPETY_NAME_ROUTE "_default"
23 | #define YAF_ROUTE_PROPETY_NAME_MAP "_maps"
24 | #define YAF_ROUTE_PROPETY_NAME_VERIFY "_verify"
25 |
26 | #define YAF_ROUTER_URL_DELIMIETER "/"
27 | #define YAF_ROUTE_REGEX_DILIMITER '#'
28 |
29 | /* {{{ YAF_ARG_INFO
30 | */
31 | YAF_BEGIN_ARG_INFO_EX(yaf_route_route_arginfo, 0, 0, 1)
32 | YAF_ARG_INFO(0, request)
33 | YAF_END_ARG_INFO()
34 | /* }}} */
35 |
36 | zend_class_entry *yaf_route_ce;
37 |
38 | #include "static.c"
39 | #include "simple.c"
40 | #include "supervar.c"
41 | #include "rewrite.c"
42 | #include "regex.c"
43 | #include "map.c"
44 |
45 | /* {{{ yaf_route_t * yaf_route_instance(yaf_route_t *this_ptr, zval *config TSRMLS_DC)
46 | */
47 | yaf_route_t * yaf_route_instance(yaf_route_t *this_ptr, zval *config TSRMLS_DC) {
48 | zval **match, **def, **map, **ppzval;
49 | yaf_route_t *instance = NULL;
50 |
51 | /* config必须为数组 */
52 | if (!config || IS_ARRAY != Z_TYPE_P(config)) {
53 | return NULL;
54 | }
55 |
56 | /* routes.sample.type值必须为字符串,不然的话返回null */
57 | if (zend_hash_find(Z_ARRVAL_P(config), ZEND_STRS("type"), (void **)&ppzval) == FAILURE
58 | || IS_STRING != Z_TYPE_PP(ppzval)) {
59 | return NULL;
60 | }
61 |
62 | if (Z_STRLEN_PP(ppzval) == (sizeof("rewrite") - 1)
63 | && strncasecmp(Z_STRVAL_PP(ppzval), "rewrite", sizeof("rewrite") - 1) == 0) { /* routes.sample.type = "rewrite" */
64 | /* routes.sample.match必须存在,且值为字符串 */
65 | if (zend_hash_find(Z_ARRVAL_P(config), ZEND_STRS("match"), (void **)&match) == FAILURE
66 | || Z_TYPE_PP(match) != IS_STRING) {
67 | return NULL;
68 | }
69 | /* routes.sample.route必须存在,且值数组 */
70 | if (zend_hash_find(Z_ARRVAL_P(config), ZEND_STRS("route"), (void **)&def) == FAILURE
71 | || Z_TYPE_PP(def) != IS_ARRAY) {
72 | return NULL;
73 | }
74 | /* 初始化类Yaf_Route_Rewrite */
75 | instance = yaf_route_rewrite_instance(NULL, *match, *def, NULL TSRMLS_CC);
76 | } else if (Z_STRLEN_PP(ppzval) == (sizeof("regex") - 1)
77 | && strncasecmp(Z_STRVAL_PP(ppzval), "regex", sizeof("regex") - 1) == 0) { /* routes.sample.regex = "rewrite" */
78 | /* routes.sample.match必须存在,且值为字符串 */
79 | if (zend_hash_find(Z_ARRVAL_P(config), ZEND_STRS("match"), (void **)&match) == FAILURE || Z_TYPE_PP(match) != IS_STRING) {
80 | return NULL;
81 | }
82 | /* routes.sample.route必须存在,且值数组 */
83 | if (zend_hash_find(Z_ARRVAL_P(config), ZEND_STRS("route"), (void **)&def) == FAILURE
84 | || Z_TYPE_PP(def) != IS_ARRAY) {
85 | return NULL;
86 | }
87 | /* routes.sample.map必须存在,且值数组 */
88 | if (zend_hash_find(Z_ARRVAL_P(config), ZEND_STRS("map"), (void **)&map) == FAILURE || Z_TYPE_PP(map) != IS_ARRAY) {
89 | return NULL;
90 | }
91 | /* 初始化类Yaf_Route_Regex */
92 | instance = yaf_route_regex_instance(NULL, *match, *def, *map, NULL TSRMLS_CC);
93 | } else if (Z_STRLEN_PP(ppzval) == (sizeof("map") - 1)
94 | && strncasecmp(Z_STRVAL_PP(ppzval), "map", sizeof("map") - 1) == 0) { /* routes.sample.regex = "map" */
95 | char *delimiter = NULL;
96 | uint delim_len = 0;
97 | zend_bool controller_prefer = 0;
98 | /* routes.sample.controllerPrefer = "xxx" */
99 | if (zend_hash_find(Z_ARRVAL_P(config), ZEND_STRS("controllerPrefer"), (void **)&ppzval) == SUCCESS) {
100 | zval *tmp = *ppzval;
101 | Z_ADDREF_P(tmp);
102 | convert_to_boolean_ex(&tmp);
103 | controller_prefer = Z_BVAL_P(tmp);
104 | zval_ptr_dtor(&tmp);
105 | }
106 | /* routes.sample.delimiter = "xxx" 值必须为字符串 */
107 | if (zend_hash_find(Z_ARRVAL_P(config), ZEND_STRS("delimiter"), (void **)&ppzval) == SUCCESS
108 | && Z_TYPE_PP(ppzval) == IS_STRING) {
109 | delimiter = Z_STRVAL_PP(ppzval);
110 | delim_len = Z_STRLEN_PP(ppzval);
111 | }
112 | /* 初始化类Yaf_Route_Map */
113 | instance = yaf_route_map_instance(NULL, controller_prefer, delimiter, delim_len TSRMLS_CC);
114 | } else if (Z_STRLEN_PP(ppzval) == (sizeof("simple") - 1)
115 | && strncasecmp(Z_STRVAL_PP(ppzval), "simple", sizeof("simple") - 1) == 0) { /* routes.sample.regex = "simple" */
116 | /* routes.sample.module = "xxx" 必须存在,且值必须为字符串 */
117 | if (zend_hash_find(Z_ARRVAL_P(config), ZEND_STRS("module"), (void **)&match) == FAILURE
118 | || Z_TYPE_PP(match) != IS_STRING) {
119 | return NULL;
120 | }
121 | /* routes.sample.controller = "xxx" 必须存在,且值必须为字符串 */
122 | if (zend_hash_find(Z_ARRVAL_P(config), ZEND_STRS("controller"), (void **)&def) == FAILURE
123 | || Z_TYPE_PP(def) != IS_STRING) {
124 | return NULL;
125 | }
126 | /* routes.sample.action = "xxx" 必须存在,且值必须为字符串 */
127 | if (zend_hash_find(Z_ARRVAL_P(config), ZEND_STRS("action"), (void **)&map) == FAILURE
128 | || Z_TYPE_PP(map) != IS_STRING) {
129 | return NULL;
130 | }
131 | /* 初始化类Yaf_Route_Simple */
132 | instance = yaf_route_simple_instance(NULL, *match, *def, *map TSRMLS_CC);
133 | } else if (Z_STRLEN_PP(ppzval) == (sizeof("supervar") - 1)
134 | && strncasecmp(Z_STRVAL_PP(ppzval), "supervar", sizeof("supervar") - 1) == 0) { /* routes.sample.regex = "supervar" */
135 | /* routes.sample.varname = "xxx" 必须存在,且值必须为字符串 */
136 | if (zend_hash_find(Z_ARRVAL_P(config), ZEND_STRS("varname"), (void **)&match) == FAILURE
137 | || Z_TYPE_PP(match) != IS_STRING) {
138 | return NULL;
139 | }
140 | /* 初始化类Yaf_Route_Supervar */
141 | instance = yaf_route_supervar_instance(NULL, *match TSRMLS_CC);
142 | }
143 | /* 返回初始化路由后返回的实例 */
144 | return instance;
145 | }
146 | /* }}} */
147 |
148 | /** {{{ yaf_route_methods
149 | */
150 | zend_function_entry yaf_route_methods[] = {
151 | PHP_ABSTRACT_ME(yaf_route, route, yaf_route_route_arginfo)
152 | {NULL, NULL, NULL}
153 | };
154 | /* }}} */
155 |
156 | /** {{{ YAF_STARTUP_FUNCTION
157 | */
158 | YAF_STARTUP_FUNCTION(route) {
159 | zend_class_entry ce;
160 | YAF_INIT_CLASS_ENTRY(ce, "Yaf_Route_Interface", "Yaf\\Route_Interface", yaf_route_methods);
161 | /* interface Yaf_Route_Interface */
162 | yaf_route_ce = zend_register_internal_interface(&ce TSRMLS_CC);
163 |
164 | YAF_STARTUP(route_static);
165 | YAF_STARTUP(route_simple);
166 | YAF_STARTUP(route_supervar);
167 | YAF_STARTUP(route_rewrite);
168 | YAF_STARTUP(route_regex);
169 | YAF_STARTUP(route_map);
170 |
171 | return SUCCESS;
172 | }
173 | /* }}} */
174 |
175 | /*
176 | * Local variables:
177 | * tab-width: 4
178 | * c-basic-offset: 4
179 | * End:
180 | * vim600: noet sw=4 ts=4 fdm=marker
181 | * vim<600: noet sw=4 ts=4
182 | */
183 |
--------------------------------------------------------------------------------
/routes/simple.c:
--------------------------------------------------------------------------------
1 | /*
2 | +----------------------------------------------------------------------+
3 | | Yet Another Framework |
4 | +----------------------------------------------------------------------+
5 | | This source file is subject to version 3.01 of the PHP license, |
6 | | that is bundled with this package in the file LICENSE, and is |
7 | | available through the world-wide-web at the following url: |
8 | | http://www.php.net/license/3_01.txt |
9 | | If you did not receive a copy of the PHP license and are unable to |
10 | | obtain it through the world-wide-web, please send a note to |
11 | | license@php.net so we can mail you a copy immediately. |
12 | +----------------------------------------------------------------------+
13 | | Author: Xinchen Hui |
14 | +----------------------------------------------------------------------+
15 | */
16 |
17 | /* $Id: simple.c 327549 2012-09-09 03:02:48Z laruence $ */
18 |
19 | zend_class_entry *yaf_route_simple_ce;
20 |
21 | #define YAF_ROUTE_SIMPLE_VAR_NAME_MODULE "module"
22 | #define YAF_ROUTE_SIMPLE_VAR_NAME_CONTROLLER "controller"
23 | #define YAF_ROUTE_SIMPLE_VAR_NAME_ACTION "action"
24 |
25 | /** {{{ ARG_INFO
26 | */
27 | ZEND_BEGIN_ARG_INFO_EX(yaf_route_simple_construct_arginfo, 0, 0, 3)
28 | ZEND_ARG_INFO(0, module_name)
29 | ZEND_ARG_INFO(0, controller_name)
30 | ZEND_ARG_INFO(0, action_name)
31 | ZEND_END_ARG_INFO()
32 | /* }}} */
33 |
34 | /** {{{ int yaf_route_simple_route(yaf_route_t *route, yaf_request_t *request TSRMLS_DC)
35 | */
36 | int yaf_route_simple_route(yaf_route_t *route, yaf_request_t *request TSRMLS_DC) {
37 | zval *module, *controller, *action;
38 | zval *nmodule, *ncontroller, *naction;
39 | /**
40 | * $nmoduel = $this->moduel
41 | * $ncontroller = $this->controller
42 | * $naction = $this->action
43 | */
44 | nmodule = zend_read_property(yaf_route_simple_ce, route, ZEND_STRL(YAF_ROUTE_SIMPLE_VAR_NAME_MODULE), 1 TSRMLS_CC);
45 | ncontroller = zend_read_property(yaf_route_simple_ce, route, ZEND_STRL(YAF_ROUTE_SIMPLE_VAR_NAME_CONTROLLER), 1 TSRMLS_CC);
46 | naction = zend_read_property(yaf_route_simple_ce, route, ZEND_STRL(YAF_ROUTE_SIMPLE_VAR_NAME_ACTION), 1 TSRMLS_CC);
47 |
48 | /* if there is no expect parameter in supervars, then null will be return */
49 | /**
50 | * $moduel = $_GET[$nmodule]
51 | * $controller = $_GET[$ncontroller]
52 | * $action = $_GET[$naction]
53 | */
54 | module = yaf_request_query(YAF_GLOBAL_VARS_GET, Z_STRVAL_P(nmodule), Z_STRLEN_P(nmodule) TSRMLS_CC);
55 | controller = yaf_request_query(YAF_GLOBAL_VARS_GET, Z_STRVAL_P(ncontroller), Z_STRLEN_P(ncontroller) TSRMLS_CC);
56 | action = yaf_request_query(YAF_GLOBAL_VARS_GET, Z_STRVAL_P(naction), Z_STRLEN_P(naction) TSRMLS_CC);
57 |
58 | if (ZVAL_IS_NULL(module) && ZVAL_IS_NULL(controller) && ZVAL_IS_NULL(action)) { /* 三个都不存在,返回0 */
59 | return 0;
60 | }
61 |
62 | if (Z_TYPE_P(module) == IS_STRING && yaf_application_is_module_name(Z_STRVAL_P(module), Z_STRLEN_P(module) TSRMLS_CC)) { /* moduel是字符串,并且是已经注册了的合法module */
63 | /* Yaf_Request_Abstract::$module = $module */
64 | zend_update_property(yaf_request_ce, request, ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_MODULE), module TSRMLS_CC);
65 | }
66 | /**
67 | * Yaf_Request_Abstract::$controller = $controller
68 | * Yaf_Request_Abstract::$action = $action
69 | */
70 | zend_update_property(yaf_request_ce, request, ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_CONTROLLER), controller TSRMLS_CC);
71 | zend_update_property(yaf_request_ce, request, ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_ACTION), action TSRMLS_CC);
72 |
73 | return 1;
74 | }
75 | /* }}} */
76 |
77 | /** {{{ yaf_route_t * yaf_route_simple_instance(yaf_route_t *this_ptr, zval *module, zval *controller, zval *action TSRMLS_DC)
78 | * 实例化,给成员变量赋值
79 | */
80 | yaf_route_t * yaf_route_simple_instance(yaf_route_t *this_ptr, zval *module, zval *controller, zval *action TSRMLS_DC) {
81 | yaf_route_t *instance;
82 |
83 | if (this_ptr) {
84 | instance = this_ptr;
85 | } else {
86 | MAKE_STD_ZVAL(instance);
87 | object_init_ex(instance, yaf_route_simple_ce);
88 | }
89 |
90 | /**
91 | * $this->moduel = $module
92 | * $this->controller = $controller
93 | * $this->action = $action
94 | */
95 | zend_update_property(yaf_route_simple_ce, instance, ZEND_STRL(YAF_ROUTE_SIMPLE_VAR_NAME_MODULE), module TSRMLS_CC);
96 | zend_update_property(yaf_route_simple_ce, instance, ZEND_STRL(YAF_ROUTE_SIMPLE_VAR_NAME_CONTROLLER), controller TSRMLS_CC);
97 | zend_update_property(yaf_route_simple_ce, instance, ZEND_STRL(YAF_ROUTE_SIMPLE_VAR_NAME_ACTION), action TSRMLS_CC);
98 | /* $return $this */
99 | return instance;
100 | }
101 | /* }}} */
102 |
103 | /** {{{ proto public Yaf_Route_Simple::route(Yaf_Request $req)
104 | */
105 | PHP_METHOD(yaf_route_simple, route) {
106 | yaf_request_t *request;
107 |
108 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &request, yaf_request_ce) == FAILURE) {
109 | return;
110 | } else {
111 | RETURN_BOOL(yaf_route_simple_route(getThis(), request TSRMLS_CC));
112 | }
113 | }
114 | /* }}} */
115 |
116 | /** {{{ proto public Yaf_Route_Simple::__construct(string $module, string $controller, string $action)
117 | */
118 | PHP_METHOD(yaf_route_simple, __construct) {
119 | zval *module, *controller, *action;
120 |
121 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zzz", &module, &controller, &action) == FAILURE) {
122 | YAF_UNINITIALIZED_OBJECT(getThis());
123 | return;
124 | }
125 |
126 | if (IS_STRING != Z_TYPE_P(module)
127 | || IS_STRING != Z_TYPE_P(controller)
128 | || IS_STRING != Z_TYPE_P(action)) { /* moduel/controller/action都必须是字符串,且都是必须存在的 */
129 | YAF_UNINITIALIZED_OBJECT(getThis());
130 | yaf_trigger_error(YAF_ERR_TYPE_ERROR TSRMLS_CC, "Expect 3 string paramsters", yaf_route_simple_ce->name);
131 | RETURN_FALSE;
132 | } else {
133 | (void)yaf_route_simple_instance(getThis(), module, controller, action TSRMLS_CC);
134 | }
135 | }
136 | /* }}} */
137 |
138 | /** {{{ yaf_route_simple_methods
139 | */
140 | zend_function_entry yaf_route_simple_methods[] = {
141 | PHP_ME(yaf_route_simple, __construct, yaf_route_simple_construct_arginfo, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
142 | PHP_ME(yaf_route_simple, route, yaf_route_route_arginfo, ZEND_ACC_PUBLIC)
143 | {NULL, NULL, NULL}
144 | };
145 | /* }}} */
146 |
147 | /** {{{ YAF_STARTUP_FUNCTION
148 | */
149 | YAF_STARTUP_FUNCTION(route_simple) {
150 | zend_class_entry ce;
151 |
152 | YAF_INIT_CLASS_ENTRY(ce, "Yaf_Route_Simple", "Yaf\\Route\\Simple", yaf_route_simple_methods);
153 | yaf_route_simple_ce = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC);
154 | zend_class_implements(yaf_route_simple_ce TSRMLS_CC, 1, yaf_route_ce);
155 | /* final class Yaf_Route_Simple implements Yaf_Route_Interface */
156 | yaf_route_simple_ce->ce_flags |= ZEND_ACC_FINAL_CLASS;
157 |
158 | /**
159 | * protected $controller = null
160 | * protected $module = null
161 | * protected $action = null
162 | */
163 | zend_declare_property_null(yaf_route_simple_ce, ZEND_STRL(YAF_ROUTE_SIMPLE_VAR_NAME_CONTROLLER), ZEND_ACC_PROTECTED TSRMLS_CC);
164 | zend_declare_property_null(yaf_route_simple_ce, ZEND_STRL(YAF_ROUTE_SIMPLE_VAR_NAME_MODULE), ZEND_ACC_PROTECTED TSRMLS_CC);
165 | zend_declare_property_null(yaf_route_simple_ce, ZEND_STRL(YAF_ROUTE_SIMPLE_VAR_NAME_ACTION), ZEND_ACC_PROTECTED TSRMLS_CC);
166 |
167 | return SUCCESS;
168 | }
169 | /* }}} */
170 |
171 | /*
172 | * Local variables:
173 | * tab-width: 4
174 | * c-basic-offset: 4
175 | * End:
176 | * vim600: noet sw=4 ts=4 fdm=marker
177 | * vim<600: noet sw=4 ts=4
178 | */
179 |
--------------------------------------------------------------------------------
/routes/static.c:
--------------------------------------------------------------------------------
1 | /*
2 | +----------------------------------------------------------------------+
3 | | Yet Another Framework |
4 | +----------------------------------------------------------------------+
5 | | This source file is subject to version 3.01 of the PHP license, |
6 | | that is bundled with this package in the file LICENSE, and is |
7 | | available through the world-wide-web at the following url: |
8 | | http://www.php.net/license/3_01.txt |
9 | | If you did not receive a copy of the PHP license and are unable to |
10 | | obtain it through the world-wide-web, please send a note to |
11 | | license@php.net so we can mail you a copy immediately. |
12 | +----------------------------------------------------------------------+
13 | | Author: Xinchen Hui |
14 | +----------------------------------------------------------------------+
15 | */
16 |
17 | /* $Id: static.c 327627 2012-09-13 06:12:38Z laruence $ */
18 |
19 | zend_class_entry * yaf_route_static_ce;
20 |
21 | /** {{{ ARG_INFO
22 | */
23 | ZEND_BEGIN_ARG_INFO_EX(yaf_route_static_match_arginfo, 0, 0, 1)
24 | ZEND_ARG_INFO(0, uri)
25 | ZEND_END_ARG_INFO()
26 | /* }}} */
27 |
28 | /**
29 | * 分割request_uri,然后经过判断得到module/controller/action/params并赋值给Yaf_Request_Abstract相应的成员变量
30 | */
31 | static int yaf_route_pathinfo_route(yaf_request_t *request, char *req_uri, int req_uri_len TSRMLS_DC) /* {{{ */ {
32 | zval *params;
33 | char *module = NULL, *controller = NULL, *action = NULL, *rest = NULL;
34 | /* 进行一些列的/分割,从req_uri中得到module/controller/action */
35 | do {
36 | #define strip_slashs(p) while (*p == ' ' || *p == '/') { ++p; }
37 | char *s, *p;
38 | char *uri;
39 | /* req_uri不存在或者为/ */
40 | if (req_uri_len == 0
41 | || (req_uri_len == 1 && *req_uri == '/')) {
42 | break;
43 | }
44 |
45 | uri = req_uri;
46 | s = p = uri;
47 |
48 | if (req_uri_len) {
49 | char *q = req_uri + req_uri_len - 1;
50 | while (q > req_uri && (*q == ' ' || *q == '/')) {
51 | *q-- = '\0';
52 | }
53 | }
54 |
55 | strip_slashs(p); /* 跳过/或者空格 */
56 |
57 |
58 | if ((s = strstr(p, "/")) != NULL) { /* 第一次截取,尝试获取module名字 */
59 | if (yaf_application_is_module_name(p, s-p TSRMLS_CC)) { //是moduel名
60 | module = estrndup(p, s - p);
61 | p = s + 1;
62 | strip_slashs(p); /* 跳过/或者空格 */
63 | if ((s = strstr(p, "/")) != NULL) { //再次分割查找controller
64 | controller = estrndup(p, s - p);
65 | p = s + 1;
66 | }
67 | } else { //不是moduel名,把它当做controller
68 | controller = estrndup(p, s - p);
69 | p = s + 1;
70 | }
71 | }
72 |
73 | strip_slashs(p); /* 跳过/或者空格 */
74 | if ((s = strstr(p, "/")) != NULL) { /* 还能截取就把截取得到的当做action */
75 | action = estrndup(p, s - p);
76 | p = s + 1;
77 | }
78 |
79 | strip_slashs(p); /* 跳过/或者空格 */
80 | if (*p != '\0') { /* 经过前面的分割并且跳过过后还没到字符串的结尾 */
81 | do {
82 | if (!module && !controller && !action) { //根本没有切割过
83 | if (yaf_application_is_module_name(p, strlen(p) TSRMLS_CC)) { /* 判断整个p是不是module名 */
84 | module = estrdup(p);
85 | break;
86 | }
87 | }
88 |
89 | if (!controller) { /* 经过相应分割过后没有得到controller,而字符串还没到结尾,就当剩下的为controller */
90 | controller = estrdup(p);
91 | break;
92 | }
93 |
94 | if (!action) { /* 经过相应分割过后没有得到action,而字符串还没到结尾,就当剩下的为action */
95 | action = estrdup(p);
96 | break;
97 | }
98 |
99 | rest = estrdup(p); /* 经过相应分割过后,req_uri还有剩余就放到rest */
100 | } while (0);
101 | }
102 |
103 | if (module && controller == NULL) { /* module/controller/action三个中只成功得到module,而没有得到controller,则认为这个module为controller */
104 | controller = module;
105 | module = NULL;
106 | } else if (module && action == NULL) { /* module/controller/action三个中只成功得到module,而没有得到action,则认为这个module为controller,controller为action */
107 | action = controller;
108 | controller = module;
109 | module = NULL;
110 | } else if (controller && action == NULL ) { /* module/controller/action三个中只成功得到controller,而没有得到action,到底作为controller还是action根据配置来 */
111 | /* /controller */
112 | if (YAF_G(action_prefer)) { //当PATH_INFO只有一部分的时候,将其作为controller还是action,配置打开则为action
113 | action = controller;
114 | controller = NULL;
115 | }
116 | }
117 | } while (0);
118 |
119 | if (module != NULL) {
120 | /* Yaf_Request_Abstract::$module = $module */
121 | zend_update_property_string(yaf_request_ce, request, ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_MODULE), module TSRMLS_CC);
122 | efree(module);
123 | }
124 | if (controller != NULL) {
125 | /* Yaf_Request_Abstract::$controller = $controller */
126 | zend_update_property_string(yaf_request_ce, request, ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_CONTROLLER), controller TSRMLS_CC);
127 | efree(controller);
128 | }
129 |
130 | if (action != NULL) {
131 | /* Yaf_Request_Abstract::$action = $action */
132 | zend_update_property_string(yaf_request_ce, request, ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_ACTION), action TSRMLS_CC);
133 | efree(action);
134 | }
135 |
136 | if (rest) { /* 将request_uri分割module/controller/action后剩余的部分进行参数的键值对的分割 */
137 | params = yaf_router_parse_parameters(rest TSRMLS_CC);
138 | /* 将得到的参数的键值对添加到Yaf_Request_Abstract::$params中 */
139 | (void)yaf_request_set_params_multi(request, params TSRMLS_CC);
140 | zval_ptr_dtor(¶ms);
141 | efree(rest);
142 | }
143 |
144 | return 1;
145 | }
146 | /* }}} */
147 |
148 | /** {{{ int yaf_route_static_route(yaf_route_t *route, yaf_request_t *request TSRMLS_DC)
149 | * 判断得到request_uri,然后传递给yaf_route_pathinfo_route分割得到module/controller/action/params
150 | */
151 | int yaf_route_static_route(yaf_route_t *route, yaf_request_t *request TSRMLS_DC) {
152 | zval *zuri, *base_uri;
153 | char *req_uri;
154 | int req_uri_len;
155 | /* $zuri = Yaf_Request_Abstract::$uri */
156 | zuri = zend_read_property(yaf_request_ce, request, ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_URI), 1 TSRMLS_CC);
157 | /* $base_uri = Yaf_Request_Abstract::$_base_uri */
158 | base_uri = zend_read_property(yaf_request_ce, request, ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_BASE), 1 TSRMLS_CC);
159 |
160 | /* 判断然后截取获得真正的request_uri */
161 | if (base_uri && IS_STRING == Z_TYPE_P(base_uri)
162 | && !strncasecmp(Z_STRVAL_P(zuri), Z_STRVAL_P(base_uri), Z_STRLEN_P(base_uri))) { /* $base_uri为合法字符串,并且$base_uri为$zuri开头的一部分 */
163 | /* $req_uri = substr($zuri, strlen($base_uri)); */
164 | req_uri = estrdup(Z_STRVAL_P(zuri) + Z_STRLEN_P(base_uri));
165 | /* $req_uri_len = strlen($zuri) - strlen($base_uri) */
166 | req_uri_len = Z_STRLEN_P(zuri) - Z_STRLEN_P(base_uri);
167 | } else {
168 | /* $req_uri = $zuri; */
169 | req_uri = estrdup(Z_STRVAL_P(zuri));
170 | /* $req_uri_len = strlen($zuri); */
171 | req_uri_len = Z_STRLEN_P(zuri);
172 | }
173 |
174 | yaf_route_pathinfo_route(request, req_uri, req_uri_len TSRMLS_CC);
175 | efree(req_uri);
176 | return 1;
177 | }
178 | /* }}} */
179 |
180 | /** {{{ proto public Yaf_Router_Classical::route(Yaf_Request $req)
181 | */
182 | PHP_METHOD(yaf_route_static, route) {
183 | yaf_request_t *request;
184 | /* 接收Yaf_Request_Abstract的实例 */
185 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &request, yaf_request_ce) == FAILURE) {
186 | return;
187 | } else {
188 | RETURN_BOOL(yaf_route_static_route(getThis(), request TSRMLS_CC));
189 | }
190 | }
191 | /* }}} */
192 |
193 | /** {{{ proto public Yaf_Router_Classical::match(string $uri)
194 | */
195 | PHP_METHOD(yaf_route_static, match) {
196 | RETURN_TRUE;
197 | }
198 | /* }}} */
199 |
200 | /** {{{ yaf_route_static_methods
201 | */
202 | zend_function_entry yaf_route_static_methods[] = {
203 | PHP_ME(yaf_route_static, match, yaf_route_static_match_arginfo, ZEND_ACC_PUBLIC)
204 | PHP_ME(yaf_route_static, route, yaf_route_route_arginfo, ZEND_ACC_PUBLIC)
205 | {NULL, NULL, NULL}
206 | };
207 | /* }}} */
208 |
209 | /** {{{ YAF_STARTUP_FUNCTION
210 | */
211 | YAF_STARTUP_FUNCTION(route_static) {
212 | zend_class_entry ce;
213 |
214 | /* final class Yaf_Route_Static implements Yaf_Route_Interface */
215 | YAF_INIT_CLASS_ENTRY(ce, "Yaf_Route_Static", "Yaf\\Route_Static", yaf_route_static_methods);
216 | yaf_route_static_ce = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC);
217 | zend_class_implements(yaf_route_static_ce TSRMLS_CC, 1, yaf_route_ce);
218 |
219 | return SUCCESS;
220 | }
221 | /* }}} */
222 |
223 | /*
224 | * Local variables:
225 | * tab-width: 4
226 | * c-basic-offset: 4
227 | * End:
228 | * vim600: noet sw=4 ts=4 fdm=marker
229 | * vim<600: noet sw=4 ts=4
230 | */
231 |
232 |
--------------------------------------------------------------------------------
/routes/supervar.c:
--------------------------------------------------------------------------------
1 | /*
2 | +----------------------------------------------------------------------+
3 | | Yet Another Framework |
4 | +----------------------------------------------------------------------+
5 | | This source file is subject to version 3.01 of the PHP license, |
6 | | that is bundled with this package in the file LICENSE, and is |
7 | | available through the world-wide-web at the following url: |
8 | | http://www.php.net/license/3_01.txt |
9 | | If you did not receive a copy of the PHP license and are unable to |
10 | | obtain it through the world-wide-web, please send a note to |
11 | | license@php.net so we can mail you a copy immediately. |
12 | +----------------------------------------------------------------------+
13 | | Author: Xinchen Hui |
14 | +----------------------------------------------------------------------+
15 | */
16 |
17 | /* $Id: supervar.c 327549 2012-09-09 03:02:48Z laruence $ */
18 |
19 | #define YAF_ROUTE_SUPERVAR_PROPETY_NAME_VAR "_var_name"
20 |
21 | zend_class_entry *yaf_route_supervar_ce;
22 |
23 | /** {{{ ARG_INFO
24 | */
25 | ZEND_BEGIN_ARG_INFO_EX(yaf_route_supervar_construct_arginfo, 0, 0, 1)
26 | ZEND_ARG_INFO(0, supervar_name)
27 | ZEND_END_ARG_INFO()
28 | /* }}} */
29 |
30 | /** {{{ int yaf_route_supervar_route(yaf_route_t *route, yaf_request_t *request TSRMLS_DC)
31 | */
32 | int yaf_route_supervar_route(yaf_route_t *route, yaf_request_t *request TSRMLS_DC) {
33 | zval *varname, *zuri;
34 | char *req_uri;
35 |
36 | varname = zend_read_property(yaf_route_supervar_ce, route, ZEND_STRL(YAF_ROUTE_SUPERVAR_PROPETY_NAME_VAR), 1 TSRMLS_CC);
37 |
38 | zuri = yaf_request_query(YAF_GLOBAL_VARS_GET, Z_STRVAL_P(varname), Z_STRLEN_P(varname) TSRMLS_CC);
39 |
40 | if (!zuri || ZVAL_IS_NULL(zuri)) {
41 | return 0;
42 | }
43 |
44 | req_uri = estrndup(Z_STRVAL_P(zuri), Z_STRLEN_P(zuri));
45 | yaf_route_pathinfo_route(request, req_uri, Z_STRLEN_P(zuri) TSRMLS_CC);
46 | efree(req_uri);
47 | return 1;
48 | }
49 | /* }}} */
50 |
51 | /** {{{ yaf_route_t * yaf_route_supervar_instance(yaf_route_t *this_ptr, zval *name TSRMLS_DC)
52 | */
53 | yaf_route_t * yaf_route_supervar_instance(yaf_route_t *this_ptr, zval *name TSRMLS_DC) {
54 | yaf_route_t *instance;
55 |
56 | if (!name || IS_STRING != Z_TYPE_P(name) || !Z_STRLEN_P(name)) {
57 | return NULL;
58 | }
59 |
60 | if (this_ptr) {
61 | instance = this_ptr;
62 | } else {
63 | MAKE_STD_ZVAL(instance);
64 | object_init_ex(instance, yaf_route_supervar_ce);
65 | }
66 | /* $this->_var_name = $var */
67 | zend_update_property(yaf_route_supervar_ce, instance, ZEND_STRL(YAF_ROUTE_SUPERVAR_PROPETY_NAME_VAR), name TSRMLS_CC);
68 | /* return $this */
69 | return instance;
70 | }
71 | /* }}} */
72 |
73 | /** {{{ proto public Yaf_Route_Supervar::route(Yaf_Request_Abstarct $request)
74 | */
75 | PHP_METHOD(yaf_route_supervar, route) {
76 | yaf_request_t *request;
77 |
78 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &request, yaf_request_ce) == FAILURE) {
79 | return;
80 | } else {
81 | RETURN_BOOL(yaf_route_supervar_route(getThis(), request TSRMLS_CC));
82 | }
83 | }
84 | /** }}} */
85 |
86 | /** {{{ proto public Yaf_Route_Supervar::__construct(string $varname)
87 | */
88 | PHP_METHOD(yaf_route_supervar, __construct) {
89 | zval *var;
90 |
91 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &var) == FAILURE) {
92 | YAF_UNINITIALIZED_OBJECT(getThis());
93 | return;
94 | }
95 |
96 | if (Z_TYPE_P(var) != IS_STRING || !Z_STRLEN_P(var)) { /* 必须传递$var */
97 | YAF_UNINITIALIZED_OBJECT(getThis());
98 | yaf_trigger_error(YAF_ERR_TYPE_ERROR TSRMLS_CC, "Expects a valid string super var name", yaf_route_supervar_ce->name);
99 | RETURN_FALSE;
100 | }
101 | /**
102 | * Why:这里为什么不调用yaf_route_supervar_instance,而是自己直接赋值呢
103 | * $this->_var_name = $var
104 | */
105 | zend_update_property(yaf_route_supervar_ce, getThis(), ZEND_STRL(YAF_ROUTE_SUPERVAR_PROPETY_NAME_VAR), var TSRMLS_CC);
106 | }
107 | /** }}} */
108 |
109 | /** {{{ yaf_route_supervar_methods
110 | */
111 | zend_function_entry yaf_route_supervar_methods[] = {
112 | PHP_ME(yaf_route_supervar, __construct, yaf_route_supervar_construct_arginfo, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
113 | PHP_ME(yaf_route_supervar, route, yaf_route_route_arginfo, ZEND_ACC_PUBLIC)
114 | {NULL, NULL, NULL}
115 | };
116 | /* }}} */
117 |
118 | /** {{{ YAF_STARTUP_FUNCTION
119 | */
120 | YAF_STARTUP_FUNCTION(route_supervar) {
121 | zend_class_entry ce;
122 | YAF_INIT_CLASS_ENTRY(ce, "Yaf_Route_Supervar", "Yaf\\Route\\Supervar", yaf_route_supervar_methods);
123 | yaf_route_supervar_ce = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC);
124 | /* final class Yaf_Route_Supervar implements Yaf_Route_Interface */
125 | zend_class_implements(yaf_route_supervar_ce TSRMLS_CC, 1, yaf_route_ce);
126 | yaf_route_supervar_ce->ce_flags |= ZEND_ACC_FINAL_CLASS;
127 | /* protected $_var_name = null */
128 | zend_declare_property_null(yaf_route_supervar_ce, ZEND_STRL(YAF_ROUTE_SUPERVAR_PROPETY_NAME_VAR), ZEND_ACC_PROTECTED TSRMLS_CC);
129 |
130 | return SUCCESS;
131 | }
132 | /* }}} */
133 |
134 | /*
135 | * Local variables:
136 | * tab-width: 4
137 | * c-basic-offset: 4
138 | * End:
139 | * vim600: noet sw=4 ts=4 fdm=marker
140 | * vim<600: noet sw=4 ts=4
141 | */
142 |
143 |
--------------------------------------------------------------------------------
/tests/001.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for yaf presence
3 | --SKIPIF--
4 |
5 | --FILE--
6 |
20 | --EXPECT--
21 | yaf extension is available
22 |
--------------------------------------------------------------------------------
/tests/002.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf_Request_Simple
3 | --SKIPIF--
4 |
5 | --FILE--
6 | setParam("name", "Laruence"));
10 | var_dump($request->isCli());
11 | var_dump($request->isXmlHttpRequest());
12 | var_dump($request->isPost());
13 | var_dump($request->getParam("name"));
14 | var_dump($request->getParam("notexists"));
15 |
16 | $app = new Yaf_Application(array("application" => array(
17 | "directory" => dirname(__FILE__),
18 | )));
19 |
20 | try {
21 | $app->getDispatcher()->dispatch($request);
22 | } catch (Yaf_Exception_LoadFailed_Controller $e) {
23 | var_dump($e->getMessage());
24 | }
25 |
26 | var_dump($request->get("xxx"));
27 | var_dump($request->getQuery("xxx"));
28 | var_dump($request->getServer("xxx"));
29 | var_dump($request->getPost("xxx"));
30 | var_dump($request->getCookie("xxx"));
31 | var_dump($request->getEnv("xxx"));
32 | echo "------default value-------\n";
33 | var_dump($request->get("xxx", "123"));
34 | print_r($request->getQuery("xxx", new stdClass()));
35 | print_r($request->getServer("xxx", array()));
36 | var_dump($request->getPost("xxx", NULL));
37 | var_dump($request->getCookie("xxx"), false);
38 | var_dump($request->getEnv("xxx"), "2.13232");
39 | echo "------params-------\n";
40 | var_dump($request->setParam("xxxx"));
41 | var_dump($request->getParam("xxxx"));
42 | var_dump($request->getParams());
43 |
44 | ?>
45 | --EXPECTF--
46 | Yaf_Request_Simple Object
47 | (
48 | [module] => index
49 | [controller] => dummy
50 | [action] => index
51 | [method] => CLI
52 | [params:protected] => Array
53 | (
54 | )
55 |
56 | [language:protected] =>
57 | [_exception:protected] =>
58 | [_base_uri:protected] =>
59 | [uri:protected] =>
60 | [dispatched:protected] =>
61 | [routed:protected] => 1
62 | )
63 | bool(true)
64 | bool(true)
65 | bool(false)
66 | bool(false)
67 | string(8) "Laruence"
68 | NULL
69 | string(%d) "Failed opening controller script %scontrollers%cDummy.php: No such file or directory"
70 | NULL
71 | NULL
72 | NULL
73 | NULL
74 | NULL
75 | NULL
76 | ------default value-------
77 | string(3) "123"
78 | stdClass Object
79 | (
80 | )
81 | Array
82 | (
83 | )
84 | NULL
85 | NULL
86 | bool(false)
87 | NULL
88 | string(7) "2.13232"
89 | ------params-------
90 |
91 | Warning: Yaf_Request_Abstract::setParam() expects parameter 1 to be array, string given in %s002.php on line %d
92 | NULL
93 | NULL
94 | array(1) {
95 | ["name"]=>
96 | string(8) "Laruence"
97 | }
98 |
--------------------------------------------------------------------------------
/tests/003.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf_Loader
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.use_spl_autoload=0
7 | yaf.lowcase_path=0
8 | --FILE--
9 | registerLocalNamespace("Baidu");
13 | $loader->registerLocalNamespace("Sina");
14 | $loader->registerLocalNamespace(array("Wb", "Inf", NULL, array(), "123"));
15 | var_dump($loader->getLocalNamespace());
16 | var_dump($loader->isLocalName("Baidu_Name"));
17 |
18 | try {
19 | var_dump($loader->autoload("Baidu_Name"));
20 | } catch (Yaf_Exception_LoadFailed $e) {
21 | var_dump($e->getMessage());
22 | }
23 | try {
24 | var_dump($loader->autoload("Global_Name"));
25 | } catch (Yaf_Exception_LoadFailed $e) {
26 | var_dump($e->getMessage());
27 | }
28 |
29 | ?>
30 | --EXPECTF--
31 | string(21) "Baidu%cSina%cWb%cInf%c123"
32 | bool(true)
33 |
34 | Warning: Yaf_Loader::autoload(): Failed opening script %sBaidu%cName.php: No such file or directory in %s
35 | bool(true)
36 |
37 | Warning: Yaf_Loader::autoload(): Failed opening script %sglobal%cGlobal%cName.php: No such file or directory in %s
38 | bool(true)
39 |
--------------------------------------------------------------------------------
/tests/004.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf_Registry
3 | --SKIPIF--
4 |
5 | --FILE--
6 |
24 | --EXPECT--
25 | string(14) "Ageli Platform"
26 | bool(true)
27 | NULL
28 | bool(false)
29 |
--------------------------------------------------------------------------------
/tests/005.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf_Response
3 | --SKIPIF--
4 |
5 | --FILE--
6 | appendBody($body);
17 | $response->prependBody($string);
18 | $response->appendBody("kfjdaksljfklajdsfkljasdkljfkjasdf");
19 |
20 | $body = $response->getBody();
21 | unset($body);
22 |
23 | var_dump(Yaf_Response_Abstract::DEFAULT_BODY);
24 | print_r($response->getBody(NULL));
25 | debug_zval_dump($response->getBody(Yaf_Response_Http::DEFAULT_BODY));
26 | unset($string);
27 | debug_zval_dump($response->getBody());
28 | echo $response;
29 | debug_zval_dump($response->getBody());
30 | $response->response();
31 | debug_zval_dump($response->getBody());
32 | ?>
33 | --EXPECTF--
34 | string(7) "content"
35 | Array
36 | (
37 | [content] => laruenceifjakdsljfklasdjfkljasdkljfkljadsfkfjdaksljfklajdsfkljasdkljfkjasdf
38 | )
39 | string(75) "laruenceifjakdsljfklasdjfkljasdkljfkljadsfkfjdaksljfklajdsfkljasdkljfkjasdf" refcount(1)
40 | string(75) "laruenceifjakdsljfklasdjfkljasdkljfkljadsfkfjdaksljfklajdsfkljasdkljfkjasdf" refcount(1)
41 | laruenceifjakdsljfklasdjfkljasdkljfkljadsfkfjdaksljfklajdsfkljasdkljfkjasdfstring(75) "laruenceifjakdsljfklasdjfkljasdkljfkljadsfkfjdaksljfklajdsfkljasdkljfkjasdf" refcount(1)
42 | laruenceifjakdsljfklasdjfkljasdkljfkljadsfkfjdaksljfklajdsfkljasdkljfkjasdfstring(75) "laruenceifjakdsljfklasdjfkljasdkljfkljadsfkfjdaksljfklajdsfkljasdkljfkjasdf" refcount(1)
43 |
--------------------------------------------------------------------------------
/tests/006.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf_Route_Static
3 | --SKIPIF--
4 |
5 | --FILE--
6 | route($request));
18 |
19 | print_r($request);
20 | ?>
21 | --EXPECTF--
22 | bool(true)
23 | Yaf_Request_Http Object
24 | (
25 | [module] =>
26 | [controller] => controller
27 | [action] => action
28 | [method] => Cli
29 | [params:protected] => Array
30 | (
31 | [name] => laruence
32 | [age] => 28
33 | )
34 |
35 | [language:protected] =>
36 | [_exception:protected] =>
37 | [_base_uri:protected] => /prefix/
38 | [uri:protected] => /prefix/controller/action/name/laruence/age/28
39 | [dispatched:protected] =>
40 | [routed:protected] =>
41 | )
42 |
--------------------------------------------------------------------------------
/tests/007.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf_Config_Simple
3 | --SKIPIF--
4 |
5 | --FILE--
6 | array(
9 | 'name' => 'value',
10 | 'dummy' => 'foo',
11 | ),
12 | 'section2' => "laruence",
13 | );
14 |
15 | $config1 = new Yaf_Config_Simple($config, 'section2');
16 | print_r($config1);
17 | $config2 = new Yaf_Config_Simple($config, 'section1');
18 | var_dump($config2->readonly());
19 | $config2->new = "value";
20 | var_dump(isset($config->new));
21 | $config3 = new Yaf_Config_Simple($config);
22 | unset($config);
23 |
24 | echo "Isset config3 section:";
25 | var_dump(isset($config3["section2"]));
26 | $config3->new = "value";
27 | echo "Config3 readonly:";
28 | var_dump($config3->readonly());
29 |
30 | foreach($config3 as $key => $val) {
31 | print_r($key);
32 | print_r("=>");
33 | print_r($val);
34 | print_r("\n");
35 | }
36 |
37 | print_r($config3->toArray());
38 |
39 | $sick = @new Yaf_Config_Simple();
40 |
41 | var_dump($sick->__isset(1));
42 | var_dump($sick->__get(2));
43 | $sick->total = 1;
44 | var_dump(count($sick));
45 | var_dump($sick->total);
46 | ?>
47 | --EXPECTF--
48 | Yaf_Config_Simple Object
49 | (
50 | [_config:protected] => Array
51 | (
52 | [section1] => Array
53 | (
54 | [name] => value
55 | [dummy] => foo
56 | )
57 |
58 | [section2] => laruence
59 | )
60 |
61 | [_readonly:protected] => 1
62 | )
63 | bool(true)
64 | bool(false)
65 | Isset config3 section:bool(true)
66 | Config3 readonly:bool(false)
67 | section1=>Yaf_Config_Simple Object
68 | (
69 | [_config:protected] => Array
70 | (
71 | [name] => value
72 | [dummy] => foo
73 | )
74 |
75 | [_readonly:protected] =>
76 | )
77 |
78 | section2=>laruence
79 | new=>value
80 | Array
81 | (
82 | [section1] => Array
83 | (
84 | [name] => value
85 | [dummy] => foo
86 | )
87 |
88 | [section2] => laruence
89 | [new] => value
90 | )
91 | bool(false)
92 | bool(false)
93 | int(1)
94 | int(1)
95 |
--------------------------------------------------------------------------------
/tests/008.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf_Router
3 | --SKIPIF--
4 |
5 | --FILE--
6 | addRoute("simple", $route)->addRoute("super", $sroute);
14 | print_r($router);
15 | var_dump($router->getCurrentRoute());
16 | print_r($router->getRoutes());
17 | print_r($router->getRoute("simple"));
18 | var_dump($router->getRoute("noexists"));
19 | ?>
20 | --EXPECTF--
21 | Yaf_Router Object
22 | (
23 | [_routes:protected] => Array
24 | (
25 | [_default] => Yaf_Route_Static Object
26 | (
27 | )
28 |
29 | [simple] => Yaf_Route_Simple Object
30 | (
31 | [controller:protected] => c
32 | [module:protected] => m
33 | [action:protected] => a
34 | )
35 |
36 | [super] => Yaf_Route_Supervar Object
37 | (
38 | [_var_name:protected] => r
39 | )
40 |
41 | )
42 |
43 | [_current:protected] =>
44 | )
45 | NULL
46 | Array
47 | (
48 | [_default] => Yaf_Route_Static Object
49 | (
50 | )
51 |
52 | [simple] => Yaf_Route_Simple Object
53 | (
54 | [controller:protected] => c
55 | [module:protected] => m
56 | [action:protected] => a
57 | )
58 |
59 | [super] => Yaf_Route_Supervar Object
60 | (
61 | [_var_name:protected] => r
62 | )
63 |
64 | )
65 | Yaf_Route_Simple Object
66 | (
67 | [controller:protected] => c
68 | [module:protected] => m
69 | [action:protected] => a
70 | )
71 | NULL
72 |
--------------------------------------------------------------------------------
/tests/009.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf_View_Simple
3 | --SKIPIF--
4 |
5 | --FILE--
6 | assign("name", $value);
10 | unset($value);
11 | print_r($view);
12 | var_dump(strlen($view->render(dirname(__FILE__) . "/001.phpt")));
13 | var_dump($view->name);
14 | var_dump($view->noexists);
15 | print_r($view);
16 | ?>
17 | --EXPECTF--
18 | Yaf_View_Simple Object
19 | (
20 | [_tpl_vars:protected] => Array
21 | (
22 | [name] => laruence
23 | )
24 |
25 | [_tpl_dir:protected] => %s
26 | [_options:protected] =>
27 | )
28 | int(116)
29 | string(8) "laruence"
30 | NULL
31 | Yaf_View_Simple Object
32 | (
33 | [_tpl_vars:protected] => Array
34 | (
35 | [name] => laruence
36 | )
37 |
38 | [_tpl_dir:protected] => %s
39 | [_options:protected] =>
40 | )
41 |
--------------------------------------------------------------------------------
/tests/011.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf_Route_Rewrite
3 | --SKIPIF--
4 |
5 | --FILE--
6 | "version",
15 | )
16 | );
17 |
18 | $router->addRoute("subdir", $route)->addRoute("ap", new Yaf_Route_Rewrite(
19 | "/ap/:version/*",
20 | array(
21 | "action" => 'ap',
22 | )
23 | ))->route($request);
24 |
25 | var_dump($router->getCurrentRoute());
26 | var_dump($request->getParam('version'));
27 | var_dump($request->getActionName());
28 | var_dump($request->getControllerName());
29 | var_dump($request->getParam('name'));
30 |
31 | ?>
32 | --EXPECTF--
33 | string(2) "ap"
34 | string(3) "1.2"
35 | string(2) "ap"
36 | NULL
37 | string(5) "value"
38 |
--------------------------------------------------------------------------------
/tests/012.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf_Route_Regex
3 | --SKIPIF--
4 |
5 | --FILE--
6 | "version",
15 | ),
16 | array(
17 | )
18 | );
19 |
20 | $router->addRoute("subdir", $route)->addRoute("ap", new Yaf_Route_Regex(
21 | "#^/ap/([^/]*)/*#i",
22 | array(
23 | "action" => 'ap',
24 | ),
25 | array(
26 | 1 => 'version',
27 | )
28 | ))->route($request);
29 |
30 | var_dump($router->getCurrentRoute());
31 | var_dump($request->getParam('version'));
32 | var_dump($request->getActionName());
33 | var_dump($request->getControllerName());
34 | var_dump($request->getParam('name'));
35 |
36 | ?>
37 | --EXPECTF--
38 | string(2) "ap"
39 | string(3) "1.2"
40 | string(2) "ap"
41 | NULL
42 | NULL
43 |
--------------------------------------------------------------------------------
/tests/013.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf_Router and Config Routes
3 | --SKIPIF--
4 |
5 | --FILE--
6 | routes;
12 | print_r($routes);
13 |
14 | $router = new Yaf_Router();
15 | $router->addConfig($routes);
16 |
17 | print_r($router->getRoutes());
18 | ?>
19 | --EXPECTF--
20 | Yaf_Config_Ini Object
21 | (
22 | [_config:protected] => Array
23 | (
24 | [regex] => Array
25 | (
26 | [type] => regex
27 | [match] => ^/ap/(.*)
28 | [route] => Array
29 | (
30 | [controller] => Index
31 | [action] => action
32 | )
33 |
34 | [map] => Array
35 | (
36 | [0] => name
37 | [1] => name
38 | [2] => value
39 | )
40 |
41 | )
42 |
43 | [simple] => Array
44 | (
45 | [type] => simple
46 | [controller] => c
47 | [module] => m
48 | [action] => a
49 | )
50 |
51 | [supervar] => Array
52 | (
53 | [type] => supervar
54 | [varname] => c
55 | )
56 |
57 | [rewrite] => Array
58 | (
59 | [type] => rewrite
60 | [match] => /yaf/:name/:value
61 | [route] => Array
62 | (
63 | [controller] => Index
64 | [action] => action
65 | )
66 |
67 | )
68 |
69 | )
70 |
71 | [_readonly:protected] => 1
72 | )
73 | Array
74 | (
75 | [_default] => Yaf_Route_Static Object
76 | (
77 | )
78 |
79 | [regex] => Yaf_Route_Regex Object
80 | (
81 | [_route:protected] => ^/ap/(.*)
82 | [_default:protected] => Array
83 | (
84 | [controller] => Index
85 | [action] => action
86 | )
87 |
88 | [_maps:protected] => Array
89 | (
90 | [0] => name
91 | [1] => name
92 | [2] => value
93 | )
94 |
95 | [_verify:protected] =>
96 | )
97 |
98 | [simple] => Yaf_Route_Simple Object
99 | (
100 | [controller:protected] => c
101 | [module:protected] => m
102 | [action:protected] => a
103 | )
104 |
105 | [supervar] => Yaf_Route_Supervar Object
106 | (
107 | [_var_name:protected] => c
108 | )
109 |
110 | [rewrite] => Yaf_Route_Rewrite Object
111 | (
112 | [_route:protected] => /yaf/:name/:value
113 | [_default:protected] => Array
114 | (
115 | [controller] => Index
116 | [action] => action
117 | )
118 |
119 | [_verify:protected] =>
120 | )
121 |
122 | )
123 |
--------------------------------------------------------------------------------
/tests/014.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf_Application
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.environ=product
7 | --FILE--
8 |
15 | --EXPECTF--
16 | Yaf_Application Object
17 | (
18 | [config:protected] => Yaf_Config_Ini Object
19 | (
20 | [_config:protected] => Array
21 | (
22 | [application] => Array
23 | (
24 | [directory] => %stests/applcation
25 | )
26 |
27 | [name] => extra
28 | [array] => Array
29 | (
30 | [1] => 1
31 | [name] => new_name
32 | [2] => test
33 | )
34 |
35 | [5] => 5
36 | [routes] => Array
37 | (
38 | [regex] => Array
39 | (
40 | [type] => regex
41 | [match] => ^/ap/(.*)
42 | [route] => Array
43 | (
44 | [controller] => Index
45 | [action] => action
46 | )
47 |
48 | [map] => Array
49 | (
50 | [0] => name
51 | [1] => name
52 | [2] => value
53 | )
54 |
55 | )
56 |
57 | [simple] => Array
58 | (
59 | [type] => simple
60 | [controller] => c
61 | [module] => m
62 | [action] => a
63 | )
64 |
65 | [supervar] => Array
66 | (
67 | [type] => supervar
68 | [varname] => c
69 | )
70 |
71 | [rewrite] => Array
72 | (
73 | [type] => rewrite
74 | [match] => /yaf/:name/:value
75 | [route] => Array
76 | (
77 | [controller] => Index
78 | [action] => action
79 | )
80 |
81 | )
82 |
83 | )
84 |
85 | [value] => 2
86 | )
87 |
88 | [_readonly:protected] => 1
89 | )
90 |
91 | [dispatcher:protected] => Yaf_Dispatcher Object
92 | (
93 | [_router:protected] => Yaf_Router Object
94 | (
95 | [_routes:protected] => Array
96 | (
97 | [_default] => Yaf_Route_Static Object
98 | (
99 | )
100 |
101 | )
102 |
103 | [_current:protected] =>
104 | )
105 |
106 | [_view:protected] =>
107 | [_request:protected] => Yaf_Request_Http Object
108 | (
109 | [module] =>
110 | [controller] =>
111 | [action] =>
112 | [method] => Cli
113 | [params:protected] => Array
114 | (
115 | )
116 |
117 | [language:protected] =>
118 | [_exception:protected] =>
119 | [_base_uri:protected] =>
120 | [uri:protected] =>
121 | [dispatched:protected] =>
122 | [routed:protected] =>
123 | )
124 |
125 | [_plugins:protected] => Array
126 | (
127 | )
128 |
129 | [_auto_render:protected] => 1
130 | [_return_response:protected] =>
131 | [_instantly_flush:protected] =>
132 | [_default_module:protected] => Index
133 | [_default_controller:protected] => Index
134 | [_default_action:protected] => index
135 | )
136 |
137 | [_modules:protected] => Array
138 | (
139 | [0] => Index
140 | )
141 |
142 | [_running:protected] =>
143 | [_environ:protected] => product
144 | [_err_no:protected] => 0
145 | [_err_msg:protected] =>
146 | )
147 |
--------------------------------------------------------------------------------
/tests/015.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf_Exception
3 | --SKIPIF--
4 |
5 | --FILE--
6 | getPrevious());
11 | var_dump($exception->getMessage());
12 | var_dump($exception->getPrevious()->getCode());
13 | ?>
14 | --EXPECTF--
15 | bool(true)
16 | string(9) "Exception"
17 | int(100)
18 |
--------------------------------------------------------------------------------
/tests/016.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf_Session
3 | --SKIPIF--
4 |
5 | --FILE--
6 | age = $age;
13 | unset($age);
14 |
15 | unset($session);
16 | $session2 = Yaf_Session::getInstance();
17 | $session2["company"] = "Baidu";
18 |
19 | var_dump(isset($session2->age));
20 | var_dump($session2->has("name"));
21 | var_dump(count($session2));
22 | foreach ($session2 as $key => $value) {
23 | echo $key , "=>", $value, "\n";
24 | }
25 |
26 | unset($session2);
27 | $session3 = Yaf_Session::getInstance();
28 |
29 | $session3->del("name");
30 | unset($session3["company"]);
31 | unset($session3->age);
32 |
33 | var_dump(count($session3));
34 | ?>
35 | --EXPECTF--
36 | bool(true)
37 | bool(true)
38 | int(3)
39 | name=>Laruence
40 | age=>28
41 | company=>Baidu
42 | int(0)
43 |
--------------------------------------------------------------------------------
/tests/017.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Bug (mem leak and crash in Yaf_Config_Ini)
3 | --SKIPIF--
4 |
5 | --FILE--
6 | get("\0"));
10 | ?>
11 | --EXPECTF--
12 | Warning: Yaf_Config_Ini::__construct() expects at least 1 parameter, 0 given in %s on line %d
13 | NULL
14 |
--------------------------------------------------------------------------------
/tests/018.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Bug Yaf_Config_Ini crash due to inaccurate refcount
3 | --SKIPIF--
4 |
5 | --FILE--
6 |
11 | --EXPECTF--
12 | Yaf_Config_Ini Object
13 | (
14 | [_config:protected] => Array
15 | (
16 | [application] => Array
17 | (
18 | [directory] => APPLICATION_PATH/applcation
19 | )
20 |
21 | [name] => base
22 | [array] => Array
23 | (
24 | [1] => 1
25 | [name] => name
26 | )
27 |
28 | [5] => 5
29 | [routes] => Array
30 | (
31 | [regex] => Array
32 | (
33 | [type] => regex
34 | [match] => ^/ap/(.*)
35 | [route] => Array
36 | (
37 | [controller] => Index
38 | [action] => action
39 | )
40 |
41 | [map] => Array
42 | (
43 | [0] => name
44 | [1] => name
45 | [2] => value
46 | )
47 |
48 | )
49 |
50 | [simple] => Array
51 | (
52 | [type] => simple
53 | [controller] => c
54 | [module] => m
55 | [action] => a
56 | )
57 |
58 | [supervar] => Array
59 | (
60 | [type] => supervar
61 | [varname] => c
62 | )
63 |
64 | [rewrite] => Array
65 | (
66 | [type] => rewrite
67 | [match] => /yaf/:name/:value
68 | [route] => Array
69 | (
70 | [controller] => Index
71 | [action] => action
72 | )
73 |
74 | )
75 |
76 | )
77 |
78 | )
79 |
80 | [_readonly:protected] => 1
81 | )
82 |
--------------------------------------------------------------------------------
/tests/019.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Yaf_Router::getCurrent with number key
3 | --SKIPIF--
4 |
5 | --FILE--
6 | addConfig(
12 | array(
13 | array(
14 | "type" => "regex",
15 | "match" => "#^/ap/([^/]*)/*#i",
16 | "route" => array(
17 | array(
18 | "action" => 'ap',
19 | ),
20 | ),
21 | "map" => array(
22 | 1 => 'version',
23 | )
24 | )
25 | )
26 | )->route($request);
27 |
28 | var_dump($router->getCurrentRoute());
29 | var_dump($request->getParam("version"));
30 |
31 | ?>
32 | --EXPECT--
33 | int(0)
34 | string(3) "1.2"
35 |
--------------------------------------------------------------------------------
/tests/020.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf_Application
3 | --SKIPIF--
4 |
5 | --INI--
6 | --FILE--
7 | array(
10 | "directory" => realpath(dirname(__FILE__)),
11 | "dispatcher" => array(
12 | "catchException" => 0,
13 | "throwException" => 0,
14 | ),
15 | ),
16 | );
17 |
18 | function error_handler($errno, $errstr, $errfile, $errline) {
19 | var_dump(Yaf_Application::app()->getLastErrorNo());
20 | var_dump(Yaf_Application::app()->getLastErrorMsg());
21 | Yaf_Application::app()->clearLastError();
22 | var_dump(Yaf_Application::app()->getLastErrorNo());
23 | var_dump(Yaf_Application::app()->getLastErrorMsg());
24 | }
25 |
26 | $app = new Yaf_Application($config);
27 | $app->getDispatcher()->setErrorHandler("error_handler", E_RECOVERABLE_ERROR);
28 | $app->run();
29 | ?>
30 | --EXPECTF--
31 | int(516)
32 | string(%d) "Failed opening controller script %s: %s"
33 | int(0)
34 | string(0) ""
35 |
--------------------------------------------------------------------------------
/tests/021.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf_Application
3 | --SKIPIF--
4 |
5 | --INI--
6 | --FILE--
7 | getDispatcher()->setErrorHandler("error_handler", E_RECOVERABLE_ERROR);
18 | $app->run();
19 | ?>
20 | --EXPECTF--
21 | error occurrd instead of exception threw
22 |
--------------------------------------------------------------------------------
/tests/022.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf_Application
3 | --SKIPIF--
4 |
5 | --INI--
6 | --FILE--
7 | array(
10 | "directory" => realpath(dirname(__FILE__)),
11 | "dispatcher" => array(
12 | "catchException" => 0,
13 | "throwException" => 0,
14 | ),
15 | ),
16 | );
17 |
18 | $app = new Yaf_Application($config);
19 | var_dump($app->getAppDirectory());
20 | $dir = $app->getAppDirectory() . "/tmp";
21 | mkdir($dir);
22 | $app->setAppDirectory($dir);
23 | var_dump($app->getAppDirectory());
24 | $app->run();
25 | ?>
26 | --CLEAN--
27 |
30 | --EXPECTF--
31 | string(%d) "%stests"
32 | string(%d) "%stmp"
33 |
34 | Catchable fatal error: Yaf_Application::run(): Failed opening controller script %stmp%ccontrollers%cIndex.php: No such file or directory in %s022.php on line %d
35 |
--------------------------------------------------------------------------------
/tests/023.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf_Loader::set/get(library_path)
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.use_spl_autoload=0
7 | yaf.lowcase_path=0
8 | --FILE--
9 | registerLocalNamespace(array("Foo"));
12 |
13 | $loader->autoload("Foo_Bar");
14 | $loader->autoload("Bar_Foo");
15 |
16 | $loader->setLibraryPath("/foobar", FALSE);
17 | $loader->autoload("Foo_Bar");
18 | $loader->autoload("Bar_Foo");
19 |
20 | $loader->setLibraryPath("/foobar", TRUE);
21 | $loader->autoload("Foo_Bar");
22 | $loader->autoload("Bar_Foo");
23 |
24 | $loader->autoload("Bar_Model");
25 | ?>
26 | --EXPECTF--
27 | Warning: Yaf_Loader::autoload(): Failed opening script /foo%cFoo%cBar.php: No such file or directory in %s023.php on line %d
28 |
29 | Warning: Yaf_Loader::autoload(): Failed opening script /bar%cBar%cFoo.php: No such file or directory in %s023.php on line %d
30 |
31 | Warning: Yaf_Loader::autoload(): Failed opening script /foobar%cFoo%cBar.php: No such file or directory in %s023.php on line %d
32 |
33 | Warning: Yaf_Loader::autoload(): Failed opening script /bar%cBar%cFoo.php: No such file or directory in %s023.php on line %d
34 |
35 | Warning: Yaf_Loader::autoload(): Failed opening script /foobar%cFoo%cBar.php: No such file or directory in %s023.php on line %d
36 |
37 | Warning: Yaf_Loader::autoload(): Failed opening script %cfoobar%cBar%cFoo.php: No such file or directory in %s023.php on line %d
38 |
39 | Warning: Yaf_Loader::autoload(): Couldn't load a framework MVC class without an Yaf_Application initializing in %s023.php on line %d
40 |
--------------------------------------------------------------------------------
/tests/024.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf_Loader::getInstace() paramters
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.library="/php/global/dir"
7 | --FILE--
8 | getLibraryPath());
12 | var_dump($loader->getLibraryPath(TRUE));
13 | $config = array(
14 | "application" => array(
15 | "directory" => realpath(dirname(__FILE__)),
16 | ),
17 | );
18 |
19 | $app = new Yaf_Application($config);
20 | var_dump($loader->getLibraryPath());
21 | var_dump($loader->getLibraryPath(TRUE));
22 | ?>
23 | --EXPECTF--
24 | string(4) "/foo"
25 | string(4) "/bar"
26 | string(%d) "%slibrary"
27 | string(15) "/php/global/dir"
28 |
--------------------------------------------------------------------------------
/tests/025.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf_Loader with namespace configuration
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.library="/php/global/dir"
7 | --FILE--
8 | array(
11 | "directory" => realpath(dirname(__FILE__)),
12 | "library" => array(
13 | "directory" => "/tmp",
14 | "namespace" => "Foo, Bar",
15 | ),
16 | ),
17 | );
18 |
19 | $app = new Yaf_Application($config);
20 | Yaf_Loader::getInstance()->registerLocalNamespace("Dummy");
21 | print_r(Yaf_Loader::getInstance());
22 | var_dump(Yaf_Loader::getInstance()->isLocalName("Bar_Name"));
23 |
24 | ?>
25 | --EXPECTF--
26 | Yaf_Loader Object
27 | (
28 | [_library:protected] => /tmp
29 | [_global_library:protected] => /php/global/dir
30 | )
31 | bool(true)
32 |
--------------------------------------------------------------------------------
/tests/026.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf_Response::setBody/prependBody/appendBody
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.library="/php/global/dir"
7 | --FILE--
8 | setBody("ell")->appendBody("o")->setBody(" W", "footer")->prependBody("H")->appendBody("orld", "footer");
11 | print_r($response);
12 | echo $response;
13 | ?>
14 | --EXPECTF--
15 | Yaf_Response_Http Object
16 | (
17 | [_header:protected] => Array
18 | (
19 | )
20 |
21 | [_body:protected] => Array
22 | (
23 | [content] => Hello
24 | [footer] => World
25 | )
26 |
27 | [_sendheader:protected] => 1
28 | [_response_code:protected] => 200
29 | )
30 | Hello World
31 |
--------------------------------------------------------------------------------
/tests/027.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf autoload controller
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.use_spl_autoload=0
7 | yaf.library="/php/global/dir"
8 | yar.environ="product"
9 | --FILE--
10 | array(
13 | "directory" => realpath(dirname(__FILE__)),
14 | "dispatcher" => array(
15 | "catchException" => 0,
16 | "throwException" => 0,
17 | ),
18 | ),
19 | );
20 |
21 | function main() {
22 | $dummy = new NoExistsController();
23 | }
24 |
25 | $app = new Yaf_Application($config);
26 | var_dump($app->environ());
27 | var_dump(count($app->getConfig()->application));
28 | $app->execute(123);
29 | $app->execute("main");
30 | ?>
31 | --EXPECTF--
32 | string(7) "product"
33 | int(2)
34 |
35 | Warning: Yaf_Application::execute(%sbe a valid callback%sin %s027.php on line %d
36 |
37 | Warning: Yaf_Loader::autoload(): Failed opening script %scontrollers%cNoExists.php: No such file or directory in %s027.php on line %d
38 |
39 | Fatal error: Class 'NoExistsController' not found in %s027.php on line %d
40 |
--------------------------------------------------------------------------------
/tests/028.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Bug segfault while call exit in a view template
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.library="/php/global/dir"
7 | --FILE--
8 | assign("name", "laruence");
15 | $tpl = APPLICATION_PATH . '/tpls/foo.phtml';
16 |
17 | file_put_contents($tpl, <<
20 | HTML
21 | );
22 | echo $view->render($tpl);
23 | ?>
24 | --CLEAN--
25 |
30 | --EXPECTF--
31 | okey
32 |
--------------------------------------------------------------------------------
/tests/029.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf_View_Simple::get and clear
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.library="/php/global/dir"
7 | --FILE--
8 | assign("a", "b");
11 | $view->assign("b", "a");
12 | print_r($view->get("a"));
13 | print_r($view->get());
14 | $view->clear("b");
15 | print_r($view->get());
16 | $view->clear();
17 | print_r($view->get());
18 | ?>
19 | --EXPECTF--
20 | bArray
21 | (
22 | [a] => b
23 | [b] => a
24 | )
25 | Array
26 | (
27 | [a] => b
28 | )
29 | Array
30 | (
31 | )
32 |
--------------------------------------------------------------------------------
/tests/030.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf_Config_Ini::__construct with section
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.library="/php/global/dir"
7 | --FILE--
8 | getMessage());
15 | }
16 |
17 | ?>
18 | --EXPECTF--
19 | There is no section 'ex' in '%ssimple.ini'
20 |
--------------------------------------------------------------------------------
/tests/031.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for application.dispatcher.defaultRoute
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.library="/php/global/dir"
7 | --FILE--
8 | array(
11 | "directory" => realpath(dirname(__FILE__)),
12 | "dispatcher" => array(
13 | "defaultRoute" => array(
14 | "type" => "map",
15 | "delimiter" => '##',
16 | "controllerPrefer" => 1,
17 | ),
18 | ),
19 | ),
20 | );
21 |
22 | $app = new Yaf_Application($config);
23 | print_r($app->getDispatcher()->getRouter()->getRoutes());
24 | ?>
25 | --EXPECTF--
26 | Array
27 | (
28 | [_default] => Yaf_Route_Map Object
29 | (
30 | [_ctl_router:protected] => 1
31 | [_delimeter:protected] => ##
32 | )
33 |
34 | )
35 |
--------------------------------------------------------------------------------
/tests/032.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf_Config_Ini with env
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.directory=/foo/bar
7 | --FILE--
8 |
14 | --EXPECTF--
15 | Yaf_Config_Ini Object
16 | (
17 | [_config:protected] => Array
18 | (
19 | [env] => bar
20 | [ini] => /foo/bar
21 | [const] => Dummy
22 | )
23 |
24 | [_readonly:protected] => 1
25 | )
26 |
--------------------------------------------------------------------------------
/tests/033.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf_View_Simple with predefined template dir
3 | --SKIPIF--
4 |
5 | --FILE--
6 | array(
9 | "directory" => realpath(dirname(__FILE__)),
10 | "dispatcher" => array(
11 | "catchException" => 0,
12 | "throwException" => 1,
13 | ),
14 | "modules" => "module",
15 | ),
16 | );
17 |
18 | class ControllerController extends Yaf_Controller_Abstract {
19 | public function actionAction() {
20 | }
21 |
22 | public function indexAction() {
23 | Yaf_Dispatcher::getInstance()->disableView();
24 | $this->forward("dummy");
25 | }
26 |
27 | public function dummyAction() {
28 | Yaf_Dispatcher::getInstance()->enableView();
29 | }
30 | }
31 |
32 |
33 | $app = new Yaf_Application($config);
34 | $request = new Yaf_Request_Http("/module/controller/action");
35 |
36 | try {
37 | $app->getDispatcher()->returnResponse(false)->dispatch($request);
38 | } catch (Yaf_Exception $e) {
39 | echo $e->getMessage(), "\n";
40 | }
41 |
42 | $view = new Yaf_View_Simple(dirname(__FILE__) . 'no-exists');
43 | $app->getDispatcher()->setView($view);
44 | try {
45 | $app->getDispatcher()->returnResponse(false)->dispatch($request);
46 | } catch (Yaf_Exception $e) {
47 | echo $e->getMessage(), "\n";
48 | }
49 |
50 | $request = new Yaf_Request_Http("/module/controller/index");
51 | try {
52 | $app->getDispatcher()->returnResponse(false)->dispatch($request);
53 | } catch (Yaf_Exception $e) {
54 | echo $e->getMessage(), "\n";
55 | }
56 | ?>
57 | --EXPECTF--
58 | Failed opening template %stests%cmodules%cModule%cviews%ccontroller%caction.phtml: No such file or directory
59 | Failed opening template %stestsno-exists%ccontroller%caction.phtml: No such file or directory
60 | Failed opening template %stestsno-exists%ccontroller%cdummy.phtml: No such file or directory
61 |
--------------------------------------------------------------------------------
/tests/034.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf_View_Simple::eval
3 | --SKIPIF--
4 |
5 | --INI--
6 | --FILE--
7 |
17 | =\$name?>
18 | PHP;
19 |
20 | $view->assign("entry", array('a', 'b', 'c'));
21 | echo $view->eval($tpl, array('name' => 'template'));
22 |
23 | ?>
24 | --EXPECTF--
25 | template
26 | 1. a
27 | 1. b
28 | 1. c
29 | template
30 |
--------------------------------------------------------------------------------
/tests/035.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf_View_Simple with short_tag_open
3 | --SKIPIF--
4 | = 0) {
7 | print "skip PHP 5.4 remove short_open_tag";
8 | }
9 | ?>
10 | --INI--
11 | short_open_tag = 0
12 | --FILE--
13 | ";
18 |
19 | file_put_contents($tpl, $content);
20 |
21 | echo $view->render($tpl, array('name' => 'template'));
22 | echo "\n";
23 | $view->display($tpl, array('name' => 'template'));
24 | $view = new Yaf_View_Simple(dirname(__FILE__), array("short_tag" => 0));
25 | echo "\n";
26 | var_dump(ini_get("short_open_tag"));
27 | $view->display($tpl, array('name' => 'template'));
28 | echo "\n";
29 | print_r($view);
30 | unlink($tpl);
31 | ?>
32 | --EXPECTF--
33 | template
34 | template
35 | string(1) "0"
36 | =$name?>
37 | Yaf_View_Simple Object
38 | (
39 | [_tpl_vars:protected] => Array
40 | (
41 | )
42 |
43 | [_tpl_dir:protected] => %s
44 | [_options:protected] => Array
45 | (
46 | [short_tag] => 0
47 | )
48 |
49 | )
50 |
--------------------------------------------------------------------------------
/tests/036.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf_Route_Static with arbitrary urls
3 | --SKIPIF--
4 |
5 | --INI--
6 | --FILE--
7 | array(
18 | "directory" => '/tmp/',
19 | "modules" => 'Index,My',
20 | ),
21 | );
22 |
23 | $app = new Yaf_Application($config);
24 |
25 | $route = Yaf_Dispatcher::getInstance()->getRouter();
26 |
27 | foreach ($url as $u) {
28 | $req = new Yaf_Request_Http($u);
29 | $route->route($req);
30 | echo $u, " : ", "m=>", $req->getModuleName(), " c=>", $req->getControllerName(), " a=>", $req->getActionName();
31 | if (($args = $req->getParams())) {
32 | echo " args=>";
33 | foreach ($args as $k => $v) {
34 | echo $k , "->", $v , ",";
35 | }
36 | }
37 | echo "\n";
38 | }
39 |
40 | ini_set("yaf.action_prefer", 1);
41 | $url = array(
42 | "/", "/foo", "/foo/",
43 | "/my", "/my/", "/my/foo", "/my//foo/",
44 | );
45 |
46 | foreach ($url as $u) {
47 | $req = new Yaf_Request_Http($u);
48 | $route->route($req);
49 | echo $u, " : ", "m=>", $req->getModuleName(), " c=>", $req->getControllerName(), " a=>", $req->getActionName();
50 | if (($args = $req->getParams())) {
51 | echo " args=>";
52 | foreach ($args as $k => $v) {
53 | echo $k , "->", $v , ",";
54 | }
55 | }
56 | echo "\n";
57 | }
58 |
59 | ?>
60 | --EXPECTF--
61 | / : m=> c=> a=>
62 | /foo : m=> c=>foo a=>
63 | /foo/ : m=> c=>foo a=>
64 | /foo///bar : m=> c=>foo a=>bar
65 | foo/bar : m=> c=>foo a=>bar
66 | /foo/bar/ : m=> c=>foo a=>bar
67 | /foo/bar/dummy : m=> c=>foo a=>bar args=>dummy->,
68 | /foo///bar/dummy/ : m=> c=>foo a=>bar args=>dummy->,
69 | foo/bar/dummy/ : m=> c=>foo a=>bar args=>dummy->,
70 | /my : m=> c=>my a=>
71 | /my/ : m=> c=>my a=>
72 | /my/foo : m=> c=>my a=>foo
73 | /my/foo/ : m=> c=>my a=>foo
74 | my/foo/bar : m=>my c=>foo a=>bar
75 | my/foo/bar/ : m=>my c=>foo a=>bar
76 | /m/index/index : m=> c=>m a=>index args=>index->,
77 | /my/foo/bar/dummy/1 : m=>my c=>foo a=>bar args=>dummy->1,
78 | my/foo/bar/dummy/1/a/2///// : m=>my c=>foo a=>bar args=>dummy->1,a->2,
79 | /my/index/index : m=>my c=>index a=>index
80 | my/index : m=> c=>my a=>index
81 | /foo/index : m=> c=>foo a=>index
82 | index/foo : m=> c=>index a=>foo
83 | / : m=> c=> a=>
84 | /foo : m=> c=> a=>foo
85 | /foo/ : m=> c=> a=>foo
86 | /my : m=> c=>my a=>
87 | /my/ : m=> c=>my a=>
88 | /my/foo : m=> c=>my a=>foo
89 | /my//foo/ : m=> c=>my a=>foo
90 |
--------------------------------------------------------------------------------
/tests/037.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf_Loader and open_basedir
3 | --SKIPIF--
4 |
12 | --INI--
13 | yaf.lowcase_path=0
14 | --FILE--
15 | import($dir . "/Dummy.php");
23 | $loader->autoload("Dummy");
24 | ?>
25 | --CLEAN--
26 |
29 | --EXPECTF--
30 | Warning: Yaf_Loader::import(): open_basedir restriction in effect. File(%sDummy.php) is not within the allowed path(s): (%sfoo) in %s037.php on line %d
31 |
32 | Warning: Yaf_Loader::import(%sDummy.php): failed to open stream: Operation not permitted in %s037.php on line %d
33 |
34 | Warning: Yaf_Loader::import(): Failed opening '%sDummy.php' for inclusion (include_path='%s') in %s037.php on line %d
35 |
36 | Warning: Yaf_Loader::autoload(): open_basedir restriction in effect. File(%sDummy.php) is not within the allowed path(s): (%sfoo) in %s037.php on line %d
37 |
38 | Warning: Yaf_Loader::autoload(%sDummy.php): failed to open stream: Operation not permitted in %s037.php on line %d
39 |
40 | Warning: Yaf_Loader::autoload(): Failed opening '%sDummy.php' for inclusion (include_path='%s') in %s037.php on line %d
41 |
42 | Warning: Yaf_Loader::autoload(): Failed opening script %sDummy.php: Operation not permitted in %s037.php on line %d
43 |
--------------------------------------------------------------------------------
/tests/038.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf_View_Simple error message outputing
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.library="/php/global/dir"
7 | log_errors=0
8 | display_errors=1
9 | --FILE--
10 | assign("name", "laruence");
17 | $tpl = APPLICATION_PATH . '/tpls/foo.phtml';
18 |
19 | file_put_contents($tpl, <<
24 | HTML
25 | );
26 |
27 | echo $view->render($tpl);
28 | ?>
29 | --CLEAN--
30 |
35 | --EXPECTF--
36 | Parse error: syntax error, unexpected '{' in %sfoo.phtml on line %d
37 |
--------------------------------------------------------------------------------
/tests/039.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf_View_Simple recursive render error message outputing
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.library="/php/global/dir"
7 | log_errors=0
8 | display_errors=1
9 | --FILE--
10 | assign("name", "laruence");
16 | $tpl = APPLICATION_PATH . '/tpls/foo.phtml';
17 | $tpl2 = APPLICATION_PATH . '/tpls/foo2.phtml';
18 |
19 | file_put_contents($tpl, <<render(\$tpl);
22 | ?>
23 | HTML
24 | );
25 |
26 | file_put_contents($tpl2, <<
31 | HTML
32 | );
33 |
34 | echo $view->render($tpl, array('tpl' => $tpl2));
35 | ?>
36 | --CLEAN--
37 |
42 | --EXPECTF--
43 | Parse error: syntax error, unexpected '{' in %sfoo2.phtml on line %d
44 |
--------------------------------------------------------------------------------
/tests/040.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Fixed bug that segv in Yaf_View_Simple::render if the tpl is not a string
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.library="/php/global/dir"
7 | --FILE--
8 | render(NULL);
11 | $view->render(0);
12 | $view->render(true);
13 | echo "okey";
14 | ?>
15 | --EXPECT--
16 | okey
17 |
--------------------------------------------------------------------------------
/tests/041.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for controller return false preventing auto-renderring
3 | --SKIPIF--
4 |
5 | --FILE--
6 | array(
9 | "directory" => realpath(dirname(__FILE__)),
10 | "dispatcher" => array(
11 | "catchException" => 0,
12 | "throwException" => 1,
13 | ),
14 | "modules" => "module",
15 | ),
16 | );
17 |
18 | class ControllerController extends Yaf_Controller_Abstract {
19 | public function actionAction() {
20 | }
21 |
22 | public function indexAction() {
23 | $this->forward("controller", "dummy");
24 | return FALSE; /* don't auto-render */
25 | }
26 |
27 | public function dummyAction() {
28 | Yaf_Dispatcher::getInstance()->enableView();
29 | }
30 | }
31 |
32 |
33 | $app = new Yaf_Application($config);
34 | $request = new Yaf_Request_Http("/module/controller/action");
35 |
36 | try {
37 | $app->getDispatcher()->returnResponse(false)->dispatch($request);
38 | } catch (Yaf_Exception $e) {
39 | echo $e->getMessage(), "\n";
40 | }
41 |
42 | $view = new Yaf_View_Simple(dirname(__FILE__) . 'no-exists');
43 | $app->getDispatcher()->setView($view);
44 | try {
45 | $app->getDispatcher()->returnResponse(false)->dispatch($request);
46 | } catch (Yaf_Exception $e) {
47 | echo $e->getMessage(), "\n";
48 | }
49 |
50 | $request = new Yaf_Request_Http("/module/controller/index");
51 | try {
52 | $app->getDispatcher()->returnResponse(false)->dispatch($request);
53 | } catch (Yaf_Exception $e) {
54 | echo $e->getMessage(), "\n";
55 | }
56 | ?>
57 | --EXPECTF--
58 | Failed opening template %stests%cmodules%cModule%cviews%ccontroller%caction.phtml: No such file or directory
59 | Failed opening template %stestsno-exists%ccontroller%caction.phtml: No such file or directory
60 | Failed opening template %stestsno-exists%ccontroller%cdummy.phtml: No such file or directory
61 |
--------------------------------------------------------------------------------
/tests/042.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for throw exception in Yaf_Controller::init
3 | --SKIPIF--
4 |
5 | --FILE--
6 | array(
9 | "directory" => realpath(dirname(__FILE__)),
10 | "dispatcher" => array(
11 | "catchException" => 0,
12 | "throwException" => 1,
13 | ),
14 | "modules" => "module",
15 | ),
16 | );
17 |
18 | class ControllerController extends Yaf_Controller_Abstract {
19 | public function init() {
20 | throw new Yaf_Exception("exception");
21 | }
22 |
23 | public function indexAction() {
24 | echo "okey";
25 | return FALSE;
26 | }
27 | }
28 |
29 |
30 | $app = new Yaf_Application($config);
31 | $request = new Yaf_Request_Http("/module/controller/index");
32 |
33 | try {
34 | $app->getDispatcher()->returnResponse(false)->dispatch($request);
35 | } catch (Yaf_Exception $e) {
36 | echo $e->getMessage(), "\n";
37 | }
38 | ?>
39 | --EXPECTF--
40 | exception
41 |
--------------------------------------------------------------------------------
/tests/043.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for yaf.system settings
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.library="/tmp"
7 | yaf.use_spl_autoload=1
8 | yaf.cache_config=0
9 | yaf.name_suffix=1
10 | yaf.name_separator=""
11 | yaf.lowcase_path=1
12 | --FILE--
13 |
27 | --EXPECTF--
28 | bool(true)
29 | bool(true)
30 | bool(true)
31 | bool(true)
32 | bool(false)
33 | bool(true)
34 |
35 | Warning: Yaf_Loader::autoload(): Failed opening script %sapplcation%cplugins%cABC%cEFG.php: No such file or directory in %s043.php on line %d
36 |
37 | Fatal error: Class 'Plugin__ABC_EFG' not found in %s043.php on line %d
38 |
--------------------------------------------------------------------------------
/tests/044.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Memleaks in Yaf_Dispatcher::getInstance()
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.use_namespace=0
7 | --FILE--
8 |
18 | --EXPECTF--
19 | string(14) "Yaf_Dispatcher"
20 |
--------------------------------------------------------------------------------
/tests/045.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for segfault while use closure as error handler
3 | --SKIPIF--
4 |
8 | --FILE--
9 | array(
12 | "directory" => realpath(dirname(__FILE__)),
13 | "dispatcher" => array(
14 | "catchException" => 0,
15 | "throwException" => 0,
16 | ),
17 | ),
18 | );
19 |
20 | class Bootstrap extends Yaf_Bootstrap_Abstract {
21 | protected function _initErrorHandler(Yaf_Dispatcher $dispatcher) {
22 | $dispatcher->setErrorHandler(function($errorCode, $errorMessage, $file, $line) {
23 | throw new ErrorException($errorMessage, 0, $errorCode, $file, $line);
24 | });
25 | }
26 | }
27 |
28 | class IndexController extends Yaf_Controller_Abstract {
29 | public function indexAction() {
30 | echo $undefined_var;
31 | return FALSE;
32 | }
33 | }
34 |
35 |
36 | $app = new Yaf_Application($config);
37 | try {
38 | $app->bootstrap()->run();
39 | } catch (Exception $e) {
40 | var_dump($e->getMessage());
41 | }
42 | ?>
43 | --EXPECTF--
44 | string(33) "Undefined variable: undefined_var"
45 |
--------------------------------------------------------------------------------
/tests/046.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf_Loader with single class
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.use_spl_autoload=0
7 | yaf.lowcase_path=0
8 | --FILE--
9 | array(
12 | "directory" => realpath(dirname(__FILE__)),
13 | "library" => array(
14 | "directory" => "/tmp",
15 | "namespace" => "Foo",
16 | ),
17 | ),
18 | );
19 | $app = new Yaf_Application($config);
20 | $loader = Yaf_Loader::getInstance();
21 | var_dump($loader->isLocalName("Foo_Bar"));
22 | var_dump($loader->isLocalName("Foo"));
23 | $loader->clearLocalNamespace();
24 | $loader->registerLocalNamespace("Bar");
25 | var_dump($loader->isLocalName("Foo_Bar"));
26 | var_dump($loader->isLocalName("Bar"));
27 | ?>
28 | --EXPECTF--
29 | bool(true)
30 | bool(true)
31 | bool(false)
32 | bool(true)
33 |
--------------------------------------------------------------------------------
/tests/047.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf_Loader with spl_autoload
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.use_spl_autoload=0
7 | yaf.lowcase_path=0
8 | --FILE--
9 | array(
12 | "directory" => realpath(dirname(__FILE__)),
13 | "library" => array(
14 | "directory" => "/tmp",
15 | "namespace" => "Foo",
16 | ),
17 | ),
18 | );
19 |
20 | function pre_load($name) {
21 | var_dump($name);
22 | }
23 |
24 | function load($name) {
25 | eval("class " . $name . " {} ");
26 | return TRUE;
27 | }
28 |
29 | spl_autoload_register("pre_load");
30 |
31 | $app = new Yaf_Application($config);
32 |
33 | spl_autoload_register("load");
34 |
35 | $a = new Foo();
36 |
37 | print_r($a);
38 | ?>
39 | --EXPECTF--
40 | string(3) "Foo"
41 |
42 | Warning: Yaf_Loader::autoload(): Failed opening script %stmp%cFoo.php: No such file or directory in %s047.php on line %d
43 | Foo Object
44 | (
45 | )
46 |
--------------------------------------------------------------------------------
/tests/048.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Sample application
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.use_spl_autoload=0
7 | yaf.lowcase_path=0
8 |
9 | --FILE--
10 | array(
16 | "directory" => APPLICATION_PATH,
17 | "dispatcher" => array (
18 | "catchException" => true,
19 | ),
20 | "library" => array(
21 | ),
22 | ),
23 | );
24 |
25 | file_put_contents(APPLICATION_PATH . "/controllers/Error.php", <<getMessage());
30 | return FALSE;
31 | }
32 | }
33 | PHP
34 | );
35 |
36 | file_put_contents(APPLICATION_PATH . "/Bootstrap.php", <<getConfig());
41 | }
42 | public function _initPlugin(Yaf_Dispatcher \$dispatcher) {
43 | \$dispatcher->registerPlugin(new TestPlugin());
44 | }
45 | }
46 | PHP
47 | );
48 |
49 | file_put_contents(APPLICATION_PATH . "/plugins/Test.php", <<application->dispatcher->catchException);
87 | \$this->getView()->assignRef("ref", \$value);
88 | }
89 | }
90 | PHP
91 | );
92 |
93 | file_put_contents(APPLICATION_PATH . "/views/index/index.phtml",
94 | "");
95 |
96 | $app = new Yaf_Application($config);
97 | $app->bootstrap()->run();
98 |
99 | ?>
100 | --CLEAN--
101 |
106 | --EXPECTF--
107 | string(13) "routerStartup"
108 | string(14) "routerShutdown"
109 | string(19) "dispatchLoopStartup"
110 | string(11) "preDispatch"
111 | string(4) "init"
112 | string(6) "action"
113 | bool(true)
114 | string(12) "postDispatch"
115 | string(43) "dispatchLoopShutdown, global var is:changed"
116 | string(4) "view"
117 |
--------------------------------------------------------------------------------
/tests/049.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Sample application with exception
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.use_spl_autoload=0
7 | yaf.lowcase_path=0
8 |
9 | --FILE--
10 | array(
16 | "directory" => APPLICATION_PATH,
17 | "dispatcher" => array (
18 | "catchException" => true,
19 | ),
20 | "library" => array(
21 | ),
22 | ),
23 | );
24 |
25 | file_put_contents(APPLICATION_PATH . "/controllers/Error.php", <<_view->msg = \$exception->getMessage();
30 | }
31 | }
32 | PHP
33 | );
34 |
35 | file_put_contents(APPLICATION_PATH . "/Bootstrap.php", <<getConfig());
40 | }
41 | public function _initPlugin(Yaf_Dispatcher \$dispatcher) {
42 | \$dispatcher->registerPlugin(new TestPlugin());
43 | }
44 | public function _initReturn(Yaf_Dispatcher \$dispatcher) {
45 | \$dispatcher->returnResponse(true);
46 | }
47 | }
48 | PHP
49 | );
50 |
51 | file_put_contents(APPLICATION_PATH . "/plugins/Test.php", <<");
91 |
92 | mkdir(APPLICATION_PATH . "/views/error/");
93 | file_put_contents(APPLICATION_PATH . "/views/error/error.phtml",
94 | "catched: =\$msg?>");
95 |
96 | $app = new Yaf_Application($config);
97 | $app->bootstrap()->run();
98 | ?>
99 | --CLEAN--
100 |
105 | --EXPECTF--
106 | string(13) "routerStartup"
107 | string(14) "routerShutdown"
108 | string(19) "dispatchLoopStartup"
109 | string(11) "preDispatch"
110 | string(4) "init"
111 | string(6) "action"
112 | catched: view exception
113 |
--------------------------------------------------------------------------------
/tests/050.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Sample application with return response
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.use_spl_autoload=0
7 | yaf.lowcase_path=0
8 |
9 | --FILE--
10 | array(
16 | "directory" => APPLICATION_PATH,
17 | ),
18 | );
19 |
20 | file_put_contents(APPLICATION_PATH . "/Bootstrap.php", <<returnResponse(true);
25 | }
26 | }
27 | PHP
28 | );
29 |
30 | file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<bootstrap()->run();
43 | var_dump("-------");
44 | echo $response;
45 | ?>
46 | --CLEAN--
47 |
52 | --EXPECTF--
53 | string(7) "-------"
54 | view
55 |
--------------------------------------------------------------------------------
/tests/051.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Fixed bug that segfault while a abnormal object set to Yaf_Route*::route
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.use_spl_autoload=0
7 | yaf.lowcase_path=0
8 | --FILE--
9 | route($x);
13 |
14 | $x = new Yaf_Route_Static();
15 | $x->route($x);
16 |
17 | $x = new Yaf_Route_Rewrite("#^/test#", array("controller" => "info"), array());
18 | $x->route($x);
19 |
20 | $x = new Yaf_Route_Supervar("r");
21 | $x->route($x);
22 |
23 | $x = new Yaf_Route_Regex("#^/test#", array("controller" => "info"), array());
24 | $x->route($x);
25 |
26 | echo "okey";
27 | ?>
28 | --EXPECTF--
29 | okey
30 |
--------------------------------------------------------------------------------
/tests/052.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf_Request APis
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.use_spl_autoload=0
7 | --FILE--
8 | get("xxx"));
13 | var_dump($request->getQuery("xxx"));
14 | var_dump($request->getServer("xxx"));
15 | var_dump($request->getPost("xxx"));
16 | var_dump($request->getCookie("xxx"));
17 | var_dump($request->getEnv("xxx"));
18 | echo "------default value-------\n";
19 | var_dump($request->get("xxx", "123"));
20 | print_r($request->getQuery("xxx", new stdClass()));
21 | print_r($request->getServer("xxx", array()));
22 | var_dump($request->getPost("xxx", NULL));
23 | var_dump($request->getCookie("xxx"), false);
24 | var_dump($request->getEnv("xxx"), "2.13232");
25 | echo "------params-------\n";
26 | var_dump($request->setParam("xxxx"));
27 | var_dump($request->getParam("xxxx"));
28 | var_dump($request->getParams());
29 | echo "-----others-----\n";
30 | var_dump($request->isXmlHttpRequest());
31 | var_dump($request->isCli());
32 | var_dump($request->isPost());
33 | ?>
34 | --EXPECTF--
35 | Warning: Yaf_Request_Http::__construct() expects at most 2 parameters, 3 given in %s052.php on line %d
36 | bool(false)
37 | NULL
38 | NULL
39 | NULL
40 | NULL
41 | NULL
42 | NULL
43 | ------default value-------
44 | string(3) "123"
45 | stdClass Object
46 | (
47 | )
48 | Array
49 | (
50 | )
51 | NULL
52 | NULL
53 | bool(false)
54 | NULL
55 | string(7) "2.13232"
56 | ------params-------
57 |
58 | Warning: Yaf_Request_Abstract::setParam() expects parameter 1 to be array, string given in %s052.php on line %d
59 | NULL
60 | NULL
61 | array(0) {
62 | }
63 | -----others-----
64 | bool(false)
65 | bool(true)
66 | bool(false)
67 |
--------------------------------------------------------------------------------
/tests/053.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Custom view engine
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.use_spl_autoload=0
7 | yaf.lowcase_path=0
8 | --FILE--
9 | array(
15 | "directory" => APPLICATION_PATH,
16 | ),
17 | );
18 |
19 | class SimpleView extends Yaf_View_Simple {
20 | public function __constrct() {
21 | }
22 |
23 | public function assign($name, $value = NULL) {
24 | $this->_tpls_vars[$name] = $value;
25 | }
26 | }
27 |
28 | $tpl_dir = APPLICATION_PATH . "/views";
29 | file_put_contents(APPLICATION_PATH . "/Bootstrap.php", <<setView(new SimpleView('{$tpl_dir}'));
34 | }
35 | }
36 | PHP
37 | );
38 |
39 | file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<_view->name = "custom view";
44 | }
45 | }
46 | PHP
47 | );
48 |
49 | file_put_contents($tpl_dir . "/index/index.phtml", "=\$name?>");
50 |
51 | $app = new Yaf_Application($config);
52 | $response = $app->bootstrap()->run();
53 | echo $response;
54 | ?>
55 | --CLEAN--
56 |
61 | --EXPECTF--
62 | custom view
63 |
--------------------------------------------------------------------------------
/tests/054.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | check for Various segfault
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.use_spl_autoload=0
7 | yaf.lowcase_path=0
8 | --FILE--
9 | getMessage());
14 | }
15 |
16 | $request = new Yaf_Request_Simple(NULL);
17 | var_dump($request->isOptions());
18 |
19 |
20 | $config = new Yaf_Config_Simple(array());
21 | $config->key();
22 | echo "okey";
23 | ?>
24 | --EXPECTF--
25 | string(%d) "Argument is not a valid ini file '%s'"
26 | bool(false)
27 | okey
28 |
--------------------------------------------------------------------------------
/tests/055.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | check for Yaf_Dispatcher::autoRender
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.use_spl_autoload=0
7 | yaf.lowcase_path=0
8 | --FILE--
9 | autoRender(true);
13 | var_dump(Yaf_Dispatcher::getInstance()->autoRender());
14 | Yaf_Dispatcher::getInstance()->autoRender(false);
15 | var_dump(Yaf_Dispatcher::getInstance()->autoRender());
16 | ?>
17 | --EXPECTF--
18 | bool(true)
19 | bool(false)
20 |
--------------------------------------------------------------------------------
/tests/056.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | check for Yaf_Dispatcher::throwException
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.use_spl_autoload=0
7 | yaf.lowcase_path=0
8 | --FILE--
9 | throwException(true);
13 | var_dump(Yaf_Dispatcher::getInstance()->throwException());
14 | Yaf_Dispatcher::getInstance()->throwException(false);
15 | var_dump(Yaf_Dispatcher::getInstance()->throwException());
16 | ?>
17 | --EXPECTF--
18 | bool(true)
19 | bool(false)
20 |
--------------------------------------------------------------------------------
/tests/057.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | check for Yaf_Dispatcher::catchException
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.use_spl_autoload=0
7 | yaf.lowcase_path=0
8 | --FILE--
9 | catchException(true);
13 | var_dump(Yaf_Dispatcher::getInstance()->catchException());
14 | Yaf_Dispatcher::getInstance()->catchException(false);
15 | var_dump(Yaf_Dispatcher::getInstance()->catchException());
16 | ?>
17 | --EXPECTF--
18 | bool(true)
19 | bool(false)
20 |
--------------------------------------------------------------------------------
/tests/058.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | check for Yaf_Dispatcher::flushInstantly
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.use_spl_autoload=0
7 | yaf.lowcase_path=0
8 | --FILE--
9 | flushInstantly(true);
13 | var_dump(Yaf_Dispatcher::getInstance()->flushInstantly());
14 | Yaf_Dispatcher::getInstance()->flushInstantly(false);
15 | var_dump(Yaf_Dispatcher::getInstance()->flushInstantly());
16 | ?>
17 | --EXPECTF--
18 | bool(true)
19 | bool(false)
20 |
--------------------------------------------------------------------------------
/tests/059.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check nesting view render
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.use_spl_autoload=0
7 | yaf.lowcase_path=0
8 | --FILE--
9 | array(
15 | "directory" => APPLICATION_PATH,
16 | ),
17 | );
18 |
19 | file_put_contents(APPLICATION_PATH . "/Bootstrap.php", <<returnResponse(true);
24 | }
25 | }
26 | PHP
27 | );
28 |
29 | file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<flushInstantly(true);
34 | }
35 | public function indexAction() {
36 | var_dump(\$this->_view->getScriptPath());
37 | }
38 | }
39 | PHP
40 | );
41 |
42 | file_put_contents(APPLICATION_PATH . "/views/index/index.phtml", "display('index/sub.phtml', array('content' => 'dummy'));?>");
43 | file_put_contents(APPLICATION_PATH . "/views/index/sub.phtml", "eval('foobar'); ?>");
44 |
45 | $app = new Yaf_Application($config);
46 | $response = $app->bootstrap()->run();
47 | ?>
48 | --CLEAN--
49 |
53 | --EXPECTF--
54 | string(%d) "%sapplication%cviews"
55 | Yaf_View_Simple Object
56 | (
57 | [_tpl_vars:protected] => Array
58 | (
59 | )
60 |
61 | [_tpl_dir:protected] =>
62 | [_options:protected] =>
63 | )
64 | dummyfoobar
65 |
--------------------------------------------------------------------------------
/tests/060.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for working with other autoloaders
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.use_spl_autoload=1
7 | yaf.lowcase_path=0
8 | --FILE--
9 | array(
20 | "directory" => APPLICATION_PATH,
21 | ),
22 | );
23 |
24 | file_put_contents(APPLICATION_PATH . "/Bootstrap.php", <<setErrorHandler(array("Bootstrap", "errorHandler"));
37 | }
38 | }
39 | PHP
40 | );
41 |
42 | file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<_view->obj = \$obj;
48 | }
49 | }
50 | PHP
51 | );
52 |
53 | file_put_contents(APPLICATION_PATH . "/views/index/index.phtml", "");
54 |
55 | $app = new Yaf_Application($config);
56 | $response = $app->bootstrap()->run();
57 | ?>
58 | --CLEAN--
59 |
63 | --EXPECTF--
64 | Dummy
65 |
--------------------------------------------------------------------------------
/tests/061.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Bug empty template file interrupts forward chain
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.use_spl_autoload=1
7 | yaf.lowcase_path=0
8 | --FILE--
9 | array(
15 | "directory" => APPLICATION_PATH,
16 | ),
17 | );
18 |
19 | file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<forward("dummy");
24 | }
25 | public function dummyAction() {
26 | }
27 | }
28 | PHP
29 | );
30 |
31 | file_put_contents(APPLICATION_PATH . "/controllers/Dummy.php", <<run();
45 | ?>
46 | --CLEAN--
47 |
51 | --EXPECTF--
52 | Dummy
53 |
--------------------------------------------------------------------------------
/tests/062.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Check for Yaf_View_Simple and application's template directory
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.library="/php/global/dir"
7 | --FILE--
8 | getMessage());
14 | }
15 |
16 | $config = array(
17 | "application" => array(
18 | "directory" => dirname(__FILE__),
19 | ),
20 | );
21 | $app = new Yaf_Application($config);
22 |
23 | $view = Yaf_Dispatcher::getInstance()->initView(array());
24 | var_dump($view->getScriptPath());
25 | ?>
26 | --EXPECTF--
27 | string(%d) "Expects an absolute path for templates directory"
28 | NULL
29 |
--------------------------------------------------------------------------------
/tests/bug61493.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Bug #61493 (Can't remove item when using unset() with a Yaf_Config_Simple instance)
3 | --CREDITS--
4 | littlemiaor at gmail dot com
5 | --SKIPIF--
6 |
7 | --FILE--
8 | 'bar',
12 | ), false);
13 |
14 | unset($config['foo']);
15 | print_r($config);
16 | ?>
17 | --EXPECTF--
18 | Yaf_Config_Simple Object
19 | (
20 | [_config:protected] => Array
21 | (
22 | )
23 |
24 | [_readonly:protected] =>
25 | )
26 |
--------------------------------------------------------------------------------
/tests/bug62702.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | FR #62702 (Make baseuri case-insensitive)
3 | --SKIPIF--
4 |
5 | --FILE--
6 | route($request);
11 | var_dump($request->getControllerName());
12 |
13 | $request = new Yaf_Request_Http("/Sample/ABC", "/sample");
14 | $router->route($request);
15 | var_dump($request->getControllerName());
16 |
17 |
18 | $router = new Yaf_Route_Map(true);
19 | $request = new Yaf_Request_Http("/sample/A/B/C", "/sample");
20 | $router->route($request);
21 | var_dump($request->getControllerName());
22 |
23 | $request = new Yaf_Request_Http("/sample", "/sAmplE");
24 | $router->route($request);
25 | var_dump($request->getControllerName());
26 |
27 | $router = new Yaf_Route_Regex("#^/test#", array("controller" => "info"), array());
28 | $request = new Yaf_Request_Http("/test/", "/Test");
29 | $router->route($request);
30 | var_dump($request->getControllerName());
31 |
32 | $request = new Yaf_Request_Http("/sample/test", "/sAmplE");
33 | $router->route($request);
34 | var_dump($request->getControllerName());
35 |
36 | $router = new Yaf_Route_Rewrite("/test", array("controller" => "info"), array());
37 | $request = new Yaf_Request_Http("/test/", "/Test");
38 | $router->route($request);
39 | var_dump($request->getControllerName());
40 |
41 | $request = new Yaf_Request_Http("/sample/test", "/sAmplE");
42 | $router->route($request);
43 | var_dump($request->getControllerName());
44 | ?>
45 | --EXPECTF--
46 | NULL
47 | string(3) "ABC"
48 | string(5) "A_B_C"
49 | NULL
50 | NULL
51 | string(4) "info"
52 | NULL
53 | string(4) "info"
54 |
--------------------------------------------------------------------------------
/tests/bug63381.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Bug #63381 ($_SERVER['SCRIPT_NAME'] changed by yaf)
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.use_spl_autoload=1
7 | yaf.lowcase_path=0
8 | --FILE--
9 | array(
20 | "directory" => APPLICATION_PATH,
21 | ),
22 | );
23 |
24 | file_put_contents(APPLICATION_PATH . "/controllers/Index.php", <<run();
46 |
47 | var_dump($server === $_SERVER);
48 | var_dump($cookie === $_COOKIE);
49 | var_dump($get === $_GET);
50 | var_dump($post === $_POST);
51 |
52 | ?>
53 | --CLEAN--
54 |
58 | --EXPECTF--
59 | bool(true)
60 | bool(true)
61 | bool(true)
62 | bool(true)
63 |
--------------------------------------------------------------------------------
/tests/bug63438.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Bug #63438 (Strange behavior with nested rendering)
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.use_spl_autoload=1
7 | yaf.lowcase_path=0
8 | --FILE--
9 | render($file);
22 | }
23 |
24 | file_put_contents(dirname(__FILE__) . '/outer.phtml', "1 3\n");
25 | file_put_contents(dirname(__FILE__) . '/inner.phtml', "2");
26 | print (view('outer.phtml'));
27 |
28 | file_put_contents(dirname(__FILE__) . '/outer.phtml', "1 display('inner.phtml');?> 3\n");
29 | print (view('outer.phtml'));
30 |
31 | file_put_contents(dirname(__FILE__) . '/outer.phtml', "1 eval('2');?> 3\n");
32 | print (view('outer.phtml'));
33 |
34 | file_put_contents(dirname(__FILE__) . '/outer.phtml', "1 display('inner.phtml');?> 3\n");
35 | file_put_contents(dirname(__FILE__) . '/inner.phtml', "");
36 | print (view('outer.phtml'));
37 | ?>
38 | --CLEAN--
39 |
43 | --EXPECTF--
44 | 1 2 3
45 | 1 2 3
46 | 1 2 3
47 | 1
48 | Fatal error: Call to undefined function undefined_function() in %sinner.phtml on line %d
49 | done
50 |
--------------------------------------------------------------------------------
/tests/bug63900.phpt:
--------------------------------------------------------------------------------
1 | --TEST--
2 | Bug #63900 (Segfault if separated action executes failed)
3 | --SKIPIF--
4 |
5 | --INI--
6 | yaf.use_spl_autoload=1
7 | yaf.lowcase_path=0
8 | yaf.throw_exception=0
9 | yaf.catch_exception=1
10 | --FILE--
11 | array(
17 | "directory" => APPLICATION_PATH,
18 | ),
19 | );
20 |
21 | file_put_contents(APPLICATION_PATH . "/controllers/Index.php", << "controllers/IndexAction.php",
26 | );
27 | }
28 | PHP
29 | );
30 |
31 | file_put_contents(APPLICATION_PATH . "/controllers/IndexAction.php", <<run();
45 | echo "Okey";
46 | ?>
47 | --CLEAN--
48 |
52 | --EXPECTF--
53 | Okey
54 |
--------------------------------------------------------------------------------
/tests/build.inc:
--------------------------------------------------------------------------------
1 |
42 |
--------------------------------------------------------------------------------
/tests/simple.ini:
--------------------------------------------------------------------------------
1 | [base]
2 | application.directory=APPLICATION_PATH "/applcation"
3 | name = "base"
4 | array.1 = 1
5 | 5=5
6 | array.name="name"
7 | routes.regex.type="regex"
8 | routes.regex.match="^/ap/(.*)"
9 | routes.regex.route.controller="Index"
10 | routes.regex.route.action="action"
11 | routes.regex.map.0="name"
12 | routes.regex.map.1="name"
13 | routes.regex.map.2="value"
14 | routes.simple.type="simple"
15 | routes.simple.controller="c"
16 | routes.simple.module="m"
17 | routes.simple.action="a"
18 | routes.supervar.type="supervar"
19 | routes.supervar.varname="c"
20 | routes.rewrite.type="rewrite"
21 | routes.rewrite.match="/yaf/:name/:value"
22 | routes.rewrite.route.controller="Index"
23 | routes.rewrite.route.action="action"
24 |
25 | [extra : base ]
26 | value = "2"
27 | name = "extra"
28 | array.name = "new_name"
29 | array.2 = "test"
30 |
31 | [product : extra]
32 |
33 | [nocatch : extra]
34 | application.dispatcher.throwException=Off
35 | application.dispatcher.catchException=yes
36 | routes.rewrite.match="/yaf/:name/:age"
37 |
38 | [envtest]
39 | env=${FOO}
40 | ini=${yaf.directory}
41 | const=FOO
42 |
43 |
--------------------------------------------------------------------------------
/tests/system.ini:
--------------------------------------------------------------------------------
1 | [base]
2 | application.directory=APPLICATION_PATH "/applcation"
3 | application.system.lowcase_path=0
4 | application.system.name_suffix=0
5 | application.system.name_separator="__"
6 | [product : base]
7 | ;only yaf runtime configure can be set
8 | application.system.open_basedir=APPLICATION_PATH
9 | application.system.use_spl_autoload=0
10 | application.system.open_basedir=APPLICATION_PATH
11 | application.system.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa=0
12 | application.system.library=APPLICATION_PATH
13 | application.system.cache_config=Off
14 |
--------------------------------------------------------------------------------
/tools/cg/README.md:
--------------------------------------------------------------------------------
1 | ##Yaf Codes Generator
2 |
3 | ###Usage
4 | ```
5 | php yaf_cg Sample
6 | ```
7 |
8 | will generator folder "Sample" under output:
9 | ```
10 | $ ls output/Sample/
11 | application/ conf/ index.php readme.txt
12 | ```
13 |
--------------------------------------------------------------------------------
/tools/cg/templates/.htaccess.tpl:
--------------------------------------------------------------------------------
1 | RewriteEngine On
2 | RewriteCond %{REQUEST_FILENAME} !-f
3 | RewriteRule .* index.php
4 |
--------------------------------------------------------------------------------
/tools/cg/templates/application/Bootstrap.php.tpl:
--------------------------------------------------------------------------------
1 | getConfig();
15 | Yaf_Registry::set('config', $arrConfig);
16 | }
17 |
18 | public function _initPlugin(Yaf_Dispatcher $dispatcher) {
19 | //注册一个插件
20 | $objSamplePlugin = new SamplePlugin();
21 | $dispatcher->registerPlugin($objSamplePlugin);
22 | }
23 |
24 | public function _initRoute(Yaf_Dispatcher $dispatcher) {
25 | //在这里注册自己的路由协议,默认使用简单路由
26 | }
27 |
28 | public function _initView(Yaf_Dispatcher $dispatcher){
29 | //在这里注册自己的view控制器,例如smarty,firekylin
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/tools/cg/templates/application/controllers/Error.php.tpl:
--------------------------------------------------------------------------------
1 | getView()->assign("exception", $exception);
14 | //5. render by Yaf
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/tools/cg/templates/application/controllers/Index.php.tpl:
--------------------------------------------------------------------------------
1 | getRequest()->getQuery("get", "default value");
18 |
19 | //2. fetch model
20 | $model = new SampleModel();
21 |
22 | //3. assign
23 | $this->getView()->assign("content", $model->selectSample());
24 | $this->getView()->assign("name", $name);
25 |
26 | //4. render by Yaf, 如果这里返回FALSE, Yaf将不会调用自动视图引擎Render模板
27 | return TRUE;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/tools/cg/templates/application/library/readme.txt.tpl:
--------------------------------------------------------------------------------
1 | 项目库文件放在这里
--------------------------------------------------------------------------------
/tools/cg/templates/application/models/Sample.php.tpl:
--------------------------------------------------------------------------------
1 | getMessage();
3 | ?>
4 |
--------------------------------------------------------------------------------
/tools/cg/templates/application/views/index/index.phtml.tpl:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/tools/cg/templates/conf/application.ini.tpl:
--------------------------------------------------------------------------------
1 | [common]
2 | application.directory = APPLICATION_PATH "/application"
3 | application.dispatcher.catchException = TRUE
4 |
5 | [product : common]
6 |
--------------------------------------------------------------------------------
/tools/cg/templates/index.php.tpl:
--------------------------------------------------------------------------------
1 | bootstrap()->run();
8 | ?>
9 |
--------------------------------------------------------------------------------
/tools/cg/templates/readme.txt.tpl:
--------------------------------------------------------------------------------
1 | 可以按照以下步骤来部署和运行程序:
2 | 1.请确保机器{&$DEV_PC&}已经安装了Yaf框架, 并且已经加载入PHP;
3 | 2.把{&$APP_NAME&}目录Copy到Webserver的DocumentRoot目录下;
4 | 3.需要在php.ini里面启用如下配置,生产的代码才能正确运行:
5 | yaf.environ="product"
6 | 4.重启Webserver;
7 | 5.访问http://yourhost/{&$APP_NAME&}/,出现Hellow Word!, 表示运行成功,否则请查看php错误日志;
8 |
--------------------------------------------------------------------------------
/tools/cg/yaf_cg:
--------------------------------------------------------------------------------
1 | #!/bin/env php
2 | $author,//开发人员
33 | 'APP_NAME' => $app_name,//app名字,请确保这也是一个合法的文件夹名
34 | 'DEV_PC' => $author . '@' . $hostname ,//开发机,用于生产makefile自动部署
35 | );
36 |
37 | define('INPUT_DIR', dirname(__FILE__).'/templates');
38 |
39 | $strOutputRoot = $app_path;
40 |
41 | if(file_exists($strOutputRoot)) {
42 | rename($strOutputRoot, $strOutputRoot.date('Ymd-His', time()));
43 | }
44 |
45 | $arrTpls = getAllTpls();
46 | foreach($arrTpls as $strFultTplPath) {
47 | $strContent = processTemplates($strFultTplPath);
48 | $strRelativeTplPath = substr($strFultTplPath, strlen(INPUT_DIR)+1);
49 | $strOutputRelativePath = convertPath($strRelativeTplPath);
50 | $strOutputPath = $strOutputRoot.'/'.$strOutputRelativePath;
51 | $strOutputDir = dirname($strOutputPath);
52 | if(!file_exists($strOutputDir))
53 | {
54 | mkdir($strOutputDir, 0777, true);
55 | }
56 | file_put_contents($strOutputPath, $strContent);
57 | }
58 |
59 | echo "DONE\n";
60 |
61 | //获取所有的代码模板文件
62 | function getAllTpls()
63 | {
64 | $intFirst = 0;
65 | $intLast = 1;
66 | $arrQueue = array(INPUT_DIR);
67 | $arrFiles = array ();
68 | while ($intFirst < $intLast)
69 | {
70 | $strPath = $arrQueue[$intFirst++];
71 | if (!is_dir($strPath))
72 | {
73 | if (file_exists($strPath))
74 | {
75 | $arrSep = explode('.', $strPath);
76 | //只取.tpl文件
77 | if($arrSep[count($arrSep) - 1] == 'tpl')
78 | {
79 | array_push($arrFiles, $strPath);
80 | }
81 | }
82 | }
83 | else
84 | {
85 | $arrPaths = scandir($strPath);
86 | if (count($arrPaths) == 0)
87 | {
88 | continue;
89 | }
90 | foreach ($arrPaths as $strSubPath)
91 | {
92 | if ($strSubPath === '.' || $strSubPath === '..')
93 | {
94 | continue;
95 | }
96 | $strCurPath = $strPath.'/'.$strSubPath;
97 | $arrQueue[$intLast++] = $strCurPath;
98 | }
99 | }
100 | }
101 | return $arrFiles;
102 | }
103 |
104 | //将模板文件名转换成输出的文件名
105 | function convertPath($strPath)
106 | {
107 | global $conf;
108 | //去掉模板后缀
109 | $strPath = str_replace('.tpl', '', $strPath);
110 |
111 | $arrSep = explode('.', $strPath);
112 | $bolIsPhp = false;
113 | if($arrSep[count($arrSep) - 1] == 'php')
114 | {
115 | $bolIsPhp = true;
116 | }
117 | //替换文件名中的模板变量
118 | $strToFind = '$APP_NAME$';
119 | $strToRelace = $bolIsPhp? ucfirst($conf['APP_NAME']) : $conf['APP_NAME'];
120 | $strPath = str_replace($strToFind, $strToRelace, $strPath);
121 | return $strPath;
122 | }
123 |
124 | //以后如果需要,可以用smarty等复杂的模板引擎来处理
125 | function processTemplates($strTpl)
126 | {
127 | $strContent = file_get_contents($strTpl);
128 | $arrSearch = array();
129 | $arrReplace = array();
130 | global $conf;
131 | foreach($conf as $strKey => $strValue)
132 | {
133 | $arrSearch[] = '{&$'.$strKey.'&}';
134 | $arrReplace[] = $strValue;
135 | }
136 |
137 | $strResult = str_replace($arrSearch, $arrReplace, $strContent);
138 | return $strResult;
139 | }
140 |
--------------------------------------------------------------------------------
/tools/yaf.php:
--------------------------------------------------------------------------------
1 | $value) {
12 | if (strncasecmp($value, "Yaf_", 3)) {
13 | unset($classes[$key]);
14 | }
15 | }
16 |
17 | echo "isFinal()) {
24 | echo "final ";
25 | }
26 |
27 | if ($class->isAbstract()) {
28 | echo "abstract ";
29 | }
30 |
31 | if ($class->isInterface()) {
32 | echo "Interface ", $class_name;
33 | } else {
34 | echo "class ", $class_name;
35 | }
36 |
37 | /* parent */
38 | $parent = $class->getParentClass();
39 | if ($parent) {
40 | echo " extends ", $parent->getName();
41 | }
42 |
43 | /* interface */
44 | $interfaces = $class->getInterfaceNames();
45 | if (count($interfaces)) {
46 | echo " implements ", join(", ", $interfaces);
47 | }
48 | echo " { \n";
49 |
50 | $indent .= "\t";
51 | /* constants */
52 | echo $indent, "/* constants */\n";
53 | $constatnts = $class->getConstants();
54 | foreach ($constatnts as $k => $v) {
55 | echo $indent, "const ", $k , " = ", $v , ";\n";
56 | }
57 | echo "\n";
58 |
59 | /* properties */
60 | echo $indent, "/* properties */\n";
61 | $properties = $class->getProperties();
62 | $values = $class->getDefaultProperties();
63 | foreach ($properties as $p) {
64 | echo $indent;
65 | if ($p->isStatic()) {
66 | echo "static ";
67 | }
68 |
69 | if ($p->isPublic()) {
70 | echo "public ";
71 | } else if ($p->isProtected()) {
72 | echo "protected ";
73 | } else {
74 | echo "private ";
75 | }
76 |
77 | echo '$', $p->getName(), " = ";
78 |
79 | if (isset($values[$p->getName()])) {
80 | echo '"', $values[$p->getName()], '"';
81 | } else {
82 | echo "NULL";
83 | }
84 | echo ";\n";
85 | }
86 | echo "\n";
87 |
88 | /* methods */
89 | echo $indent, "/* methods */\n";
90 | $methods = $class->getMethods();
91 | foreach ($methods as $m) {
92 | echo $indent;
93 | echo implode(' ', Reflection::getModifierNames($m->getModifiers()));
94 | echo " function ", $m->getName(), "(";
95 | $parameters = $m->getParameters();
96 | $number = count($parameters);
97 | $index = 0;
98 | foreach ($parameters as $a) {
99 | if (($type = $a->getClass())) {
100 | echo $type->getName(), " ";
101 | } else if ($a->isArray()) {
102 | echo "array ";
103 | }
104 |
105 | if ($a->isPassedByReference()) {
106 | echo "&";
107 | }
108 |
109 | $name = $a->getName();
110 | if ($name == "...") {
111 | echo '$_ = "..."';
112 | } else {
113 | echo "$", $name;
114 | }
115 |
116 | if ($a->isOptional()) {
117 | if ($a->isDefaultValueAvailable()) {
118 | echo " = ", $a->getDefaultValue();
119 | } else {
120 | echo " = NULL";
121 | }
122 | }
123 |
124 | if (++$index < $number) {
125 | echo ", ";
126 | }
127 | }
128 |
129 | echo ") {\n";
130 | echo $indent, "}\n";
131 | }
132 | echo "}\n\n";
133 | }
134 |
--------------------------------------------------------------------------------
/travis/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | phpize && ./configure && make
3 |
--------------------------------------------------------------------------------
/views/interface.c:
--------------------------------------------------------------------------------
1 | /*
2 | +----------------------------------------------------------------------+
3 | | Yet Another Framework |
4 | +----------------------------------------------------------------------+
5 | | This source file is subject to version 3.01 of the PHP license, |
6 | | that is bundled with this package in the file LICENSE, and is |
7 | | available through the world-wide-web at the following url: |
8 | | http://www.php.net/license/3_01.txt |
9 | | If you did not receive a copy of the PHP license and are unable to |
10 | | obtain it through the world-wide-web, please send a note to |
11 | | license@php.net so we can mail you a copy immediately. |
12 | +----------------------------------------------------------------------+
13 | | Author: Xinchen Hui |
14 | +----------------------------------------------------------------------+
15 | */
16 |
17 | /* $Id: interface.c 327426 2012-09-02 04:01:00Z laruence $ */
18 |
19 | zend_class_entry *yaf_view_interface_ce;
20 |
21 | /* {{{ ARG_INFO
22 | */
23 | ZEND_BEGIN_ARG_INFO_EX(yaf_view_assign_arginfo, 0, 0, 1)
24 | ZEND_ARG_INFO(0, name)
25 | ZEND_ARG_INFO(0, value)
26 | ZEND_END_ARG_INFO()
27 |
28 | ZEND_BEGIN_ARG_INFO_EX(yaf_view_display_arginfo, 0, 0, 1)
29 | ZEND_ARG_INFO(0, tpl)
30 | ZEND_ARG_INFO(0, tpl_vars)
31 | ZEND_END_ARG_INFO()
32 |
33 | ZEND_BEGIN_ARG_INFO_EX(yaf_view_render_arginfo, 0, 0, 1)
34 | ZEND_ARG_INFO(0, tpl)
35 | ZEND_ARG_INFO(0, tpl_vars)
36 | ZEND_END_ARG_INFO()
37 |
38 | ZEND_BEGIN_ARG_INFO_EX(yaf_view_setpath_arginfo, 0, 0, 1)
39 | ZEND_ARG_INFO(0, template_dir)
40 | ZEND_END_ARG_INFO()
41 |
42 | ZEND_BEGIN_ARG_INFO_EX(yaf_view_getpath_arginfo, 0, 0, 0)
43 | ZEND_END_ARG_INFO()
44 | /* }}} */
45 |
46 | /** {{{ yaf_view_interface_methods
47 | */
48 | zend_function_entry yaf_view_interface_methods[] = {
49 | ZEND_ABSTRACT_ME(yaf_view, assign, yaf_view_assign_arginfo)
50 | ZEND_ABSTRACT_ME(yaf_view, display, yaf_view_display_arginfo)
51 | ZEND_ABSTRACT_ME(yaf_view, render, yaf_view_render_arginfo)
52 | ZEND_ABSTRACT_ME(yaf_view, setScriptPath, yaf_view_setpath_arginfo)
53 | ZEND_ABSTRACT_ME(yaf_view, getScriptPath, yaf_view_getpath_arginfo)
54 | {NULL, NULL, NULL}
55 | };
56 | /* }}} */
57 |
58 | /** {{{ YAF_STARTUP_FUNCTION
59 | */
60 | YAF_STARTUP_FUNCTION(view_interface) {
61 | zend_class_entry ce;
62 | YAF_INIT_CLASS_ENTRY(ce, "Yaf_View_Interface", "Yaf\\View_Interface", yaf_view_interface_methods);
63 | /* interface Yaf_View_Interface */
64 | yaf_view_interface_ce = zend_register_internal_interface(&ce TSRMLS_CC);
65 |
66 | return SUCCESS;
67 | }
68 | /* }}} */
69 |
70 | /*
71 | * Local variables:
72 | * tab-width: 4
73 | * c-basic-offset: 4
74 | * End:
75 | * vim600: noet sw=4 ts=4 fdm=marker
76 | * vim<600: noet sw=4 ts=4
77 | */
78 |
79 |
--------------------------------------------------------------------------------
/yaf.php:
--------------------------------------------------------------------------------
1 | ";
3 |
4 | if(!extension_loaded('ap')) {
5 | dl('ap.' . PHP_SHLIB_SUFFIX);
6 | }
7 | $module = 'ap';
8 | $functions = get_extension_funcs($module);
9 | echo "Functions available in the test extension:$br\n";
10 | foreach($functions as $func) {
11 | echo $func."$br\n";
12 | }
13 | echo "$br\n";
14 | $function = 'confirm_' . $module . '_compiled';
15 | if (extension_loaded($module)) {
16 | $str = $function($module);
17 | } else {
18 | $str = "Module $module is not compiled into PHP";
19 | }
20 | echo "$str\n";
21 | ?>
22 |
--------------------------------------------------------------------------------
/yaf_action.c:
--------------------------------------------------------------------------------
1 | /*
2 | +----------------------------------------------------------------------+
3 | | Yet Another Framework |
4 | +----------------------------------------------------------------------+
5 | | This source file is subject to version 3.01 of the PHP license, |
6 | | that is bundled with this package in the file LICENSE, and is |
7 | | available through the world-wide-web at the following url: |
8 | | http://www.php.net/license/3_01.txt |
9 | | If you did not receive a copy of the PHP license and are unable to |
10 | | obtain it through the world-wide-web, please send a note to |
11 | | license@php.net so we can mail you a copy immediately. |
12 | +----------------------------------------------------------------------+
13 | | Author: Xinchen Hui |
14 | +----------------------------------------------------------------------+
15 | */
16 |
17 | /* $Id: yaf_action.c 321289 2011-12-21 02:53:29Z laruence $ */
18 |
19 | #ifdef HAVE_CONFIG_H
20 | #include "config.h"
21 | #endif
22 |
23 | #include "php.h"
24 | #include "php_ini.h"
25 | #include "main/SAPI.h"
26 |
27 | #include "php_yaf.h"
28 | #include "yaf_namespace.h"
29 | #include "yaf_request.h"
30 | #include "yaf_response.h"
31 | #include "yaf_view.h"
32 | #include "yaf_exception.h"
33 | #include "yaf_controller.h"
34 | #include "yaf_action.h"
35 |
36 | zend_class_entry *yaf_action_ce;
37 |
38 | /** {{{ ARG_INFO
39 | */
40 |
41 | /* }}} */
42 |
43 | /** {{{ proto public Yaf_Action_Abstract::getController(void)
44 | */
45 | PHP_METHOD(yaf_action, getController) {
46 | /* 从当前对象中获取$_controller */
47 | yaf_controller_t *controller = zend_read_property(yaf_action_ce, getThis(), ZEND_STRL(YAF_ACTION_PROPERTY_NAME_CTRL), 1 TSRMLS_CC);
48 | /* 返回$_controller */
49 | RETURN_ZVAL(controller, 1, 0);
50 | }
51 | /* }}} */
52 |
53 | /** {{{ yaf_controller_methods
54 | */
55 | zend_function_entry yaf_action_methods[] = {
56 | PHP_ABSTRACT_ME(yaf_action_controller, execute, NULL)
57 | PHP_ME(yaf_action, getController, NULL, ZEND_ACC_PUBLIC)
58 | {NULL, NULL, NULL}
59 | };
60 | /* }}} */
61 |
62 | /** {{{ YAF_STARTUP_FUNCTION
63 | */
64 | YAF_STARTUP_FUNCTION(action) {
65 | zend_class_entry ce;
66 | YAF_INIT_CLASS_ENTRY(ce, "Yaf_Action_Abstract", "Yaf\\Action_Abstract", yaf_action_methods);
67 | /* Yaf_Action_Abstract类继承了Yaf_Controller类 */
68 | yaf_action_ce = zend_register_internal_class_ex(&ce, yaf_controller_ce, NULL TSRMLS_CC);
69 | /* 将Yaf_Action_Abstract定义为抽象类 */
70 | yaf_action_ce->ce_flags |= ZEND_ACC_IMPLICIT_ABSTRACT_CLASS;
71 | /* 初始化$_controller=null */
72 | zend_declare_property_null(yaf_action_ce, ZEND_STRL(YAF_ACTION_PROPERTY_NAME_CTRL), ZEND_ACC_PROTECTED TSRMLS_CC);
73 |
74 | return SUCCESS;
75 | }
76 | /* }}} */
77 |
78 | /*
79 | * Local variables:
80 | * tab-width: 4
81 | * c-basic-offset: 4
82 | * End:
83 | * vim600: noet sw=4 ts=4 fdm=marker
84 | * vim<600: noet sw=4 ts=4
85 | */
86 |
--------------------------------------------------------------------------------
/yaf_action.h:
--------------------------------------------------------------------------------
1 | /*
2 | +----------------------------------------------------------------------+
3 | | Yet Another Framework |
4 | +----------------------------------------------------------------------+
5 | | This source file is subject to version 3.01 of the PHP license, |
6 | | that is bundled with this package in the file LICENSE, and is |
7 | | available through the world-wide-web at the following url: |
8 | | http://www.php.net/license/3_01.txt |
9 | | If you did not receive a copy of the PHP license and are unable to |
10 | | obtain it through the world-wide-web, please send a note to |
11 | | license@php.net so we can mail you a copy immediately. |
12 | +----------------------------------------------------------------------+
13 | | Author: Xinchen Hui |
14 | +----------------------------------------------------------------------+
15 | */
16 |
17 | /* $Id: yaf_action.h 321289 2011-12-21 02:53:29Z laruence $ */
18 |
19 | #ifndef YAF_ACTION_H
20 | #define YAF_ACTION_H
21 |
22 | #define YAF_ACTION_EXECUTOR_NAME "execute"
23 | #define YAF_ACTION_PROPERTY_NAME_CTRL "_controller"
24 |
25 | extern zend_class_entry * yaf_action_ce;
26 |
27 | YAF_STARTUP_FUNCTION(action);
28 | #endif
29 | /*
30 | * Local variables:
31 | * tab-width: 4
32 | * c-basic-offset: 4
33 | * End:
34 | * vim600: noet sw=4 ts=4 fdm=marker
35 | * vim<600: noet sw=4 ts=4
36 | */
37 |
38 |
--------------------------------------------------------------------------------
/yaf_application.h:
--------------------------------------------------------------------------------
1 | /*
2 | +----------------------------------------------------------------------+
3 | | Yet Another Framework |
4 | +----------------------------------------------------------------------+
5 | | This source file is subject to version 3.01 of the PHP license, |
6 | | that is bundled with this package in the file LICENSE, and is |
7 | | available through the world-wide-web at the following url: |
8 | | http://www.php.net/license/3_01.txt |
9 | | If you did not receive a copy of the PHP license and are unable to |
10 | | obtain it through the world-wide-web, please send a note to |
11 | | license@php.net so we can mail you a copy immediately. |
12 | +----------------------------------------------------------------------+
13 | | Author: Xinchen Hui |
14 | +----------------------------------------------------------------------+
15 | */
16 |
17 | /* $Id: yaf_application.h 321289 2011-12-21 02:53:29Z laruence $ */
18 |
19 | #ifndef PHP_YAF_APPLICATION_H
20 | #define PHP_YAF_APPLICATION_H
21 |
22 | #define YAF_APPLICATION_PROPERTY_NAME_CONFIG "config"
23 | #define YAF_APPLICATION_PROPERTY_NAME_DISPATCHER "dispatcher"
24 | #define YAF_APPLICATION_PROPERTY_NAME_RUN "_running"
25 | #define YAF_APPLICATION_PROPERTY_NAME_APP "_app"
26 | #define YAF_APPLICATION_PROPERTY_NAME_ENV "_environ"
27 | #define YAF_APPLICATION_PROPERTY_NAME_MODULES "_modules"
28 | #define YAF_APPLICATION_PROPERTY_NAME_ERRNO "_err_no"
29 | #define YAF_APPLICATION_PROPERTY_NAME_ERRMSG "_err_msg"
30 |
31 | extern zend_class_entry *yaf_application_ce;
32 |
33 | int yaf_application_is_module_name(char *name, int len TSRMLS_DC);
34 |
35 | YAF_STARTUP_FUNCTION(application);
36 | #endif
37 |
--------------------------------------------------------------------------------
/yaf_bootstrap.c:
--------------------------------------------------------------------------------
1 | /*
2 | +----------------------------------------------------------------------+
3 | | Yet Another Framework |
4 | +----------------------------------------------------------------------+
5 | | This source file is subject to version 3.01 of the PHP license, |
6 | | that is bundled with this package in the file LICENSE, and is |
7 | | available through the world-wide-web at the following url: |
8 | | http://www.php.net/license/3_01.txt |
9 | | If you did not receive a copy of the PHP license and are unable to |
10 | | obtain it through the world-wide-web, please send a note to |
11 | | license@php.net so we can mail you a copy immediately. |
12 | +----------------------------------------------------------------------+
13 | | Author: Xinchen Hui |
14 | +----------------------------------------------------------------------+
15 | */
16 |
17 | /* $Id: yaf_bootstrap.c 321289 2011-12-21 02:53:29Z laruence $ */
18 |
19 | #ifdef HAVE_CONFIG_H
20 | #include "config.h"
21 | #endif
22 |
23 | #include "php.h"
24 | #include "main/SAPI.h"
25 |
26 | #include "php_yaf.h"
27 | #include "yaf_namespace.h"
28 | #include "yaf_bootstrap.h"
29 |
30 | zend_class_entry *yaf_bootstrap_ce;
31 |
32 | /** {{{ yaf_bootstrap_methods
33 | */
34 | zend_function_entry yaf_bootstrap_methods[] = {
35 | {NULL, NULL, NULL}
36 | };
37 | /* }}} */
38 |
39 | /** {{{ YAF_STARTUP_FUNCTION
40 | */
41 | YAF_STARTUP_FUNCTION(bootstrap) {
42 | zend_class_entry ce;
43 |
44 | YAF_INIT_CLASS_ENTRY(ce, "Yaf_Bootstrap_Abstract", "Yaf\\Bootstrap_Abstract", yaf_bootstrap_methods);
45 | yaf_bootstrap_ce = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC);
46 | /* 将Yaf_Bootstrap_Abstract定义为抽象类 */
47 | yaf_bootstrap_ce->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;
48 |
49 | return SUCCESS;
50 | }
51 | /* }}} */
52 |
53 | /*
54 | * Local variables:
55 | * tab-width: 4
56 | * c-basic-offset: 4
57 | * End:
58 | * vim600: noet sw=4 ts=4 fdm=marker
59 | * vim<600: noet sw=4 ts=4
60 | */
61 |
--------------------------------------------------------------------------------
/yaf_bootstrap.h:
--------------------------------------------------------------------------------
1 | /*
2 | +----------------------------------------------------------------------+
3 | | Yet Another Framework |
4 | +----------------------------------------------------------------------+
5 | | This source file is subject to version 3.01 of the PHP license, |
6 | | that is bundled with this package in the file LICENSE, and is |
7 | | available through the world-wide-web at the following url: |
8 | | http://www.php.net/license/3_01.txt |
9 | | If you did not receive a copy of the PHP license and are unable to |
10 | | obtain it through the world-wide-web, please send a note to |
11 | | license@php.net so we can mail you a copy immediately. |
12 | +----------------------------------------------------------------------+
13 | | Author: Xinchen Hui |
14 | +----------------------------------------------------------------------+
15 | */
16 |
17 | /* $Id: yaf_bootstrap.h 321289 2011-12-21 02:53:29Z laruence $ */
18 |
19 | #ifndef YAF_BOOTSTRAP_H
20 | #define YAF_BOOTSTRAP_H
21 |
22 | #define YAF_DEFAULT_BOOTSTRAP "Bootstrap"
23 | #define YAF_DEFAULT_BOOTSTRAP_LOWER "bootstrap"
24 | #define YAF_DEFAULT_BOOTSTRAP_LEN 10
25 | #define YAF_BOOTSTRAP_INITFUNC_PREFIX "_init"
26 |
27 | extern zend_class_entry *yaf_bootstrap_ce;
28 |
29 | YAF_STARTUP_FUNCTION(bootstrap);
30 | #endif
31 | /*
32 | * Local variables:
33 | * tab-width: 4
34 | * c-basic-offset: 4
35 | * End:
36 | * vim600: noet sw=4 ts=4 fdm=marker
37 | * vim<600: noet sw=4 ts=4
38 | */
39 |
--------------------------------------------------------------------------------
/yaf_config.h:
--------------------------------------------------------------------------------
1 | /*
2 | +----------------------------------------------------------------------+
3 | | Yet Another Framework |
4 | +----------------------------------------------------------------------+
5 | | This source file is subject to version 3.01 of the PHP license, |
6 | | that is bundled with this package in the file LICENSE, and is |
7 | | available through the world-wide-web at the following url: |
8 | | http://www.php.net/license/3_01.txt |
9 | | If you did not receive a copy of the PHP license and are unable to |
10 | | obtain it through the world-wide-web, please send a note to |
11 | | license@php.net so we can mail you a copy immediately. |
12 | +----------------------------------------------------------------------+
13 | | Author: Xinchen Hui |
14 | +----------------------------------------------------------------------+
15 | */
16 |
17 | /* $Id: yaf_config.h 321289 2011-12-21 02:53:29Z laruence $ */
18 |
19 | #ifndef YAF_CONFIG_H
20 | #define YAF_CONFIG_H
21 |
22 | #define YAF_EXTRACT_FUNC_NAME "extract"
23 | #define YAF_CONFIG_PROPERT_NAME "_config"
24 | #define YAF_CONFIG_PROPERT_NAME_READONLY "_readonly"
25 |
26 | struct _yaf_config_cache {
27 | long ctime; //缓存的时间标识,生成缓存时配置文件最后修改的时间
28 | HashTable *data; //配置文件内容
29 | };
30 |
31 | typedef struct _yaf_config_cache yaf_config_cache;
32 |
33 | extern zend_class_entry *yaf_config_ce;
34 |
35 | yaf_config_t * yaf_config_instance(yaf_config_t *this_ptr, zval *arg1, zval *arg2 TSRMLS_DC);
36 | void yaf_config_unserialize(yaf_config_t *self, HashTable *data TSRMLS_DC);
37 |
38 | #ifndef pestrndup
39 | /* before php-5.2.4, pestrndup is not defined */
40 | #define pestrndup(s, length, persistent) ((persistent)?zend_strndup((s),(length)):estrndup((s),(length)))
41 | #endif
42 |
43 | YAF_STARTUP_FUNCTION(config);
44 | #endif
45 | /*
46 | * Local variables:
47 | * tab-width: 4
48 | * c-basic-offset: 4
49 | * End:
50 | * vim600: noet sw=4 ts=4 fdm=marker
51 | * vim<600: noet sw=4 ts=4
52 | */
53 |
--------------------------------------------------------------------------------
/yaf_controller.h:
--------------------------------------------------------------------------------
1 | /*
2 | +----------------------------------------------------------------------+
3 | | Yet Another Framework |
4 | +----------------------------------------------------------------------+
5 | | This source file is subject to version 3.01 of the PHP license, |
6 | | that is bundled with this package in the file LICENSE, and is |
7 | | available through the world-wide-web at the following url: |
8 | | http://www.php.net/license/3_01.txt |
9 | | If you did not receive a copy of the PHP license and are unable to |
10 | | obtain it through the world-wide-web, please send a note to |
11 | | license@php.net so we can mail you a copy immediately. |
12 | +----------------------------------------------------------------------+
13 | | Author: Xinchen Hui |
14 | +----------------------------------------------------------------------+
15 | */
16 |
17 | /* $Id: yaf_controller.h 327558 2012-09-09 05:59:24Z laruence $ */
18 |
19 | #ifndef YAF_CONTROLLER_H
20 | #define YAF_CONTROLLER_H
21 |
22 | #define YAF_CONTROLLER_PROPERTY_NAME_MODULE "_module"
23 | #define YAF_CONTROLLER_PROPERTY_NAME_NAME "_name"
24 | #define YAF_CONTROLLER_PROPERTY_NAME_SCRIPT "_script_path"
25 | #define YAF_CONTROLLER_PROPERTY_NAME_RESPONSE "_response"
26 | #define YAF_CONTROLLER_PROPERTY_NAME_REQUEST "_request"
27 | #define YAF_CONTROLLER_PROPERTY_NAME_ARGS "_invoke_args"
28 | #define YAF_CONTROLLER_PROPERTY_NAME_ACTIONS "actions"
29 | #define YAF_CONTROLLER_PROPERTY_NAME_VIEW "_view"
30 |
31 | #define YAF_CONTROLLER_PROPERTY_NAME_RENDER "yafAutoRender"
32 |
33 | extern zend_class_entry *yaf_controller_ce;
34 | int yaf_controller_construct(zend_class_entry *ce, yaf_controller_t *self,
35 | yaf_request_t *request, yaf_response_t *response, yaf_view_t *view, zval *args TSRMLS_DC);
36 | zval * yaf_controller_render(zval *instance, char *action_name, int len, zval *var_array TSRMLS_DC);
37 | int yaf_controller_display(zval *instance, char *action_name, int len, zval *var_array TSRMLS_DC);
38 | YAF_STARTUP_FUNCTION(controller);
39 | #endif
40 | /*
41 | * Local variables:
42 | * tab-width: 4
43 | * c-basic-offset: 4
44 | * End:
45 | * vim600: noet sw=4 ts=4 fdm=marker
46 | * vim<600: noet sw=4 ts=4
47 | */
48 |
49 |
--------------------------------------------------------------------------------
/yaf_dispatcher.h:
--------------------------------------------------------------------------------
1 | /*
2 | +----------------------------------------------------------------------+
3 | | Yet Another Framework |
4 | +----------------------------------------------------------------------+
5 | | This source file is subject to version 3.01 of the PHP license, |
6 | | that is bundled with this package in the file LICENSE, and is |
7 | | available through the world-wide-web at the following url: |
8 | | http://www.php.net/license/3_01.txt |
9 | | If you did not receive a copy of the PHP license and are unable to |
10 | | obtain it through the world-wide-web, please send a note to |
11 | | license@php.net so we can mail you a copy immediately. |
12 | +----------------------------------------------------------------------+
13 | | Author: Xinchen Hui |
14 | +----------------------------------------------------------------------+
15 | */
16 |
17 | /* $Id: yaf_dispatcher.h 315725 2011-08-29 16:59:33Z laruence $ */
18 |
19 | #ifndef PHP_YAF_DISPATCHER_H
20 | #define PHP_YAF_DISPATCHER_H
21 |
22 | #define YAF_DISPATCHER_PROPERTY_NAME_REQUEST "_request"
23 | #define YAF_DISPATCHER_PROPERTY_NAME_VIEW "_view"
24 | #define YAF_DISPATCHER_PROPERTY_NAME_ROUTER "_router"
25 | #define YAF_DISPATCHER_PROPERTY_NAME_INSTANCE "_instance"
26 | #define YAF_DISPATCHER_PROPERTY_NAME_RENDER "_auto_render"
27 | #define YAF_DISPATCHER_PROPERTY_NAME_RETURN "_return_response"
28 | #define YAF_DISPATCHER_PROPERTY_NAME_FLUSH "_instantly_flush" //标示着, 是否在有输出的时候, 直接响应给客户端, 不写入Yaf_Response_Abstract对象.
29 | #define YAF_DISPATCHER_PROPERTY_NAME_ARGS "_invoke_args"
30 |
31 | #define YAF_DISPATCHER_PROPERTY_NAME_MODULE "_default_module"
32 | #define YAF_DISPATCHER_PROPERTY_NAME_CONTROLLER "_default_controller"
33 | #define YAF_DISPATCHER_PROPERTY_NAME_ACTION "_default_action"
34 |
35 | #define YAF_ERROR_CONTROLLER "Error"
36 | #define YAF_ERROR_ACTION "error"
37 |
38 | #define YAF_DISPATCHER_PROPERTY_NAME_PLUGINS "_plugins"
39 |
40 | #define YAF_PLUGIN_HOOK_ROUTESTARTUP "routerstartup"
41 | #define YAF_PLUGIN_HOOK_ROUTESHUTDOWN "routershutdown"
42 | #define YAF_PLUGIN_HOOK_LOOPSTARTUP "dispatchloopstartup"
43 | #define YAF_PLUGIN_HOOK_PREDISPATCH "predispatch"
44 | #define YAF_PLUGIN_HOOK_POSTDISPATCH "postdispatch"
45 | #define YAF_PLUGIN_HOOK_LOOPSHUTDOWN "dispatchloopshutdown"
46 | #define YAF_PLUGIN_HOOK_PRERESPONSE "preresponse"
47 |
48 | /* 调用插件 */
49 | #define YAF_PLUGIN_HANDLE(p, n, request, response) \
50 | do { \
51 | if (!ZVAL_IS_NULL(p)) { \
52 | zval **_t_plugin;\
53 | for(zend_hash_internal_pointer_reset(Z_ARRVAL_P(p));\
54 | zend_hash_has_more_elements(Z_ARRVAL_P(p)) == SUCCESS;\
55 | zend_hash_move_forward(Z_ARRVAL_P(p))) {\
56 | if (zend_hash_get_current_data(Z_ARRVAL_P(p), (void**)&_t_plugin) == SUCCESS) {\
57 | if (zend_hash_exists(&(Z_OBJCE_PP(_t_plugin)->function_table), n, sizeof(n))) {\
58 | zend_call_method_with_2_params(_t_plugin, Z_OBJCE_PP(_t_plugin), NULL, n, NULL, request, response);\
59 | }\
60 | }\
61 | }\
62 | }\
63 | } while(0)
64 |
65 | extern zend_class_entry *yaf_dispatcher_ce;
66 |
67 | yaf_dispatcher_t * yaf_dispatcher_instance(yaf_dispatcher_t *this_ptr TSRMLS_DC);
68 | yaf_response_t * yaf_dispatcher_dispatch(yaf_dispatcher_t *dispatcher TSRMLS_DC);
69 | int yaf_dispatcher_set_request(yaf_dispatcher_t *dispatcher, yaf_request_t *request TSRMLS_DC);
70 |
71 | PHP_METHOD(yaf_application, app);
72 | PHP_FUNCTION(set_error_handler);
73 | YAF_STARTUP_FUNCTION(dispatcher);
74 | #endif
75 |
--------------------------------------------------------------------------------
/yaf_exception.h:
--------------------------------------------------------------------------------
1 | /*
2 | +----------------------------------------------------------------------+
3 | | Yet Another Framework |
4 | +----------------------------------------------------------------------+
5 | | This source file is subject to version 3.01 of the PHP license, |
6 | | that is bundled with this package in the file LICENSE, and is |
7 | | available through the world-wide-web at the following url: |
8 | | http://www.php.net/license/3_01.txt |
9 | | If you did not receive a copy of the PHP license and are unable to |
10 | | obtain it through the world-wide-web, please send a note to |
11 | | license@php.net so we can mail you a copy immediately. |
12 | +----------------------------------------------------------------------+
13 | | Author: Xinchen Hui |
14 | +----------------------------------------------------------------------+
15 | */
16 |
17 | /* $Id: yaf_exception.h 327549 2012-09-09 03:02:48Z laruence $ */
18 |
19 | #ifndef YAF_EXCEPTION_H
20 | #define YAF_EXCEPTION_H
21 |
22 | #define YAF_MAX_BUILDIN_EXCEPTION 10
23 |
24 | #define YAF_ERR_BASE 512
25 | #define YAF_UERR_BASE 1024
26 | #define YAF_ERR_MASK 127
27 |
28 | #define YAF_ERR_STARTUP_FAILED 512
29 | #define YAF_ERR_ROUTE_FAILED 513
30 | #define YAF_ERR_DISPATCH_FAILED 514
31 | #define YAF_ERR_NOTFOUND_MODULE 515
32 | #define YAF_ERR_NOTFOUND_CONTROLLER 516
33 | #define YAF_ERR_NOTFOUND_ACTION 517
34 | #define YAF_ERR_NOTFOUND_VIEW 518
35 | #define YAF_ERR_CALL_FAILED 519
36 | #define YAF_ERR_AUTOLOAD_FAILED 520
37 | #define YAF_ERR_TYPE_ERROR 521
38 |
39 | #define YAF_EXCEPTION_OFFSET(x) (x & YAF_ERR_MASK)
40 |
41 | #define YAF_CORRESPOND_ERROR(x) (x>>9L)
42 |
43 | #define YAF_EXCEPTION_HANDLE(dispatcher, request, response) \
44 | if (EG(exception)) { \
45 | if (YAF_G(catch_exception)) { \
46 | yaf_dispatcher_exception_handler(dispatcher, request, response TSRMLS_CC); \
47 | } \
48 | zval_ptr_dtor(&response); \
49 | return NULL; \
50 | }
51 |
52 | #define YAF_EXCEPTION_HANDLE_NORET(dispatcher, request, response) \
53 | if (EG(exception)) { \
54 | if (YAF_G(catch_exception)) { \
55 | yaf_dispatcher_exception_handler(dispatcher, request, response TSRMLS_CC); \
56 | } \
57 | }
58 |
59 | #define YAF_EXCEPTION_ERASE_EXCEPTION() \
60 | do { \
61 | EG(current_execute_data)->opline = EG(opline_before_exception); \
62 | } while(0)
63 |
64 | #define YAF_UNINITIALIZED_OBJECT(obj) \
65 | do { \
66 | zval_dtor(obj); \
67 | ZVAL_FALSE(obj); \
68 | } while(0)
69 |
70 | extern zend_class_entry *yaf_ce_RuntimeException;
71 | extern zend_class_entry *yaf_exception_ce;
72 | extern zend_class_entry *yaf_buildin_exceptions[YAF_MAX_BUILDIN_EXCEPTION];
73 | void yaf_trigger_error(int type TSRMLS_DC, char *format, ...);
74 | void yaf_throw_exception(long code, char *message TSRMLS_DC);
75 |
76 | YAF_STARTUP_FUNCTION(exception);
77 |
78 | #endif
79 | /*
80 | * Local variables:
81 | * tab-width: 4
82 | * c-basic-offset: 4
83 | * End:
84 | * vim600: noet sw=4 ts=4 fdm=marker
85 | * vim<600: noet sw=4 ts=4
86 | */
87 |
--------------------------------------------------------------------------------
/yaf_loader.h:
--------------------------------------------------------------------------------
1 | /*
2 | +----------------------------------------------------------------------+
3 | | Yet Another Framework |
4 | +----------------------------------------------------------------------+
5 | | This source file is subject to version 3.01 of the PHP license, |
6 | | that is bundled with this package in the file LICENSE, and is |
7 | | available through the world-wide-web at the following url: |
8 | | http://www.php.net/license/3_01.txt |
9 | | If you did not receive a copy of the PHP license and are unable to |
10 | | obtain it through the world-wide-web, please send a note to |
11 | | license@php.net so we can mail you a copy immediately. |
12 | +----------------------------------------------------------------------+
13 | | Author: Xinchen Hui |
14 | +----------------------------------------------------------------------+
15 | */
16 |
17 | /* $Id: yaf_loader.h 327580 2012-09-10 06:31:34Z laruence $ */
18 |
19 | #ifndef YAF_LOADER_H
20 | #define YAF_LOADER_H
21 |
22 | #define YAF_DEFAULT_VIEW_EXT "phtml"
23 | #define YAF_DEFAULT_LIBRARY_EXT YAF_DEFAULT_CONTROLLER_EXT
24 |
25 | #define YAF_LIBRARY_DIRECTORY_NAME "library"
26 | #define YAF_CONTROLLER_DIRECTORY_NAME "controllers"
27 | #define YAF_PLUGIN_DIRECTORY_NAME "plugins"
28 | #define YAF_MODULE_DIRECTORY_NAME "modules"
29 | #define YAF_VIEW_DIRECTORY_NAME "views"
30 | #define YAF_MODEL_DIRECTORY_NAME "models"
31 |
32 | #define YAF_SPL_AUTOLOAD_REGISTER_NAME "spl_autoload_register"
33 | #define YAF_AUTOLOAD_FUNC_NAME "autoload"
34 | #define YAF_LOADER_PROPERTY_NAME_INSTANCE "_instance"
35 | #define YAF_LOADER_PROPERTY_NAME_NAMESPACE "_local_ns"
36 |
37 | #define YAF_LOADER_CONTROLLER "Controller"
38 | #define YAF_LOADER_LEN_CONTROLLER 10
39 | #define YAF_LOADER_MODEL "Model"
40 | #define YAF_LOADER_LEN_MODEL 5
41 | #define YAF_LOADER_PLUGIN "Plugin"
42 | #define YAF_LOADER_LEN_PLUGIN 6
43 | #define YAF_LOADER_RESERVERD "Yaf_"
44 | #define YAF_LOADER_LEN_RESERVERD 3
45 |
46 | /* {{{ This only effects internally */
47 | #define YAF_LOADER_DAO "Dao_"
48 | #define YAF_LOADER_LEN_DAO 4
49 | #define YAF_LOADER_SERVICE "Service_"
50 | #define YAF_LOADER_LEN_SERVICE 8
51 | /* }}} */
52 |
53 | #define YAF_LOADER_PROPERTY_NAME_LIBRARY "_library"
54 | #define YAF_LOADER_PROPERTY_NAME_GLOBAL_LIB "_global_library"
55 |
56 | #if ((PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION > 2)) || (PHP_MAJOR_VERSION > 5)
57 | #define YAF_STORE_EG_ENVIRON() \
58 | { \
59 | zval ** __old_return_value_pp = EG(return_value_ptr_ptr); \
60 | zend_op ** __old_opline_ptr = EG(opline_ptr); \
61 | zend_op_array * __old_op_array = EG(active_op_array);
62 |
63 | #define YAF_RESTORE_EG_ENVIRON() \
64 | EG(return_value_ptr_ptr) = __old_return_value_pp;\
65 | EG(opline_ptr) = __old_opline_ptr; \
66 | EG(active_op_array) = __old_op_array; \
67 | }
68 |
69 | #else
70 |
71 | #define YAF_STORE_EG_ENVIRON() \
72 | { \
73 | zval ** __old_return_value_pp = EG(return_value_ptr_ptr); \
74 | zend_op ** __old_opline_ptr = EG(opline_ptr); \
75 | zend_op_array * __old_op_array = EG(active_op_array); \
76 | zend_function_state * __old_func_state = EG(function_state_ptr);
77 |
78 | #define YAF_RESTORE_EG_ENVIRON() \
79 | EG(return_value_ptr_ptr) = __old_return_value_pp;\
80 | EG(opline_ptr) = __old_opline_ptr; \
81 | EG(active_op_array) = __old_op_array; \
82 | EG(function_state_ptr) = __old_func_state; \
83 | }
84 |
85 | #endif
86 |
87 | extern zend_class_entry *yaf_loader_ce;
88 |
89 | int yaf_internal_autoload(char *file_name, uint name_len, char **directory TSRMLS_DC);
90 | int yaf_loader_import(char *path, int len, int use_path TSRMLS_DC);
91 | int yaf_register_autoloader(yaf_loader_t *loader TSRMLS_DC);
92 | int yaf_loader_register_namespace_single(char *prefix, uint len TSRMLS_DC);
93 | yaf_loader_t * yaf_loader_instance(yaf_loader_t *this_ptr, char *library_path, char *global_path TSRMLS_DC);
94 |
95 | extern PHPAPI int php_stream_open_for_zend_ex(const char *filename, zend_file_handle *handle, int mode TSRMLS_DC);
96 |
97 | YAF_STARTUP_FUNCTION(loader);
98 |
99 | #endif
100 | /*
101 | * Local variables:
102 | * tab-width: 4
103 | * c-basic-offset: 4
104 | * End:
105 | * vim600: noet sw=4 ts=4 fdm=marker
106 | * vim<600: noet sw=4 ts=4
107 | */
108 |
--------------------------------------------------------------------------------
/yaf_namespace.h:
--------------------------------------------------------------------------------
1 | /*
2 | +----------------------------------------------------------------------+
3 | | Yet Another Framework |
4 | +----------------------------------------------------------------------+
5 | | This source file is subject to version 3.01 of the PHP license, |
6 | | that is bundled with this package in the file LICENSE, and is |
7 | | available through the world-wide-web at the following url: |
8 | | http://www.php.net/license/3_01.txt |
9 | | If you did not receive a copy of the PHP license and are unable to |
10 | | obtain it through the world-wide-web, please send a note to |
11 | | license@php.net so we can mail you a copy immediately. |
12 | +----------------------------------------------------------------------+
13 | | Author: Xinchen Hui |
14 | +----------------------------------------------------------------------+
15 | */
16 |
17 | /* $Id: yaf_namespace.h 321289 2011-12-21 02:53:29Z laruence $ */
18 |
19 | #ifndef YAF_NAMESPACE_H
20 | #define YAF_NAMESPACE_H
21 |
22 | #if ((PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION > 2)) || (PHP_MAJOR_VERSION > 5)
23 | #define YAF_BEGIN_ARG_INFO ZEND_BEGIN_ARG_INFO
24 | #define YAF_BEGIN_ARG_INFO_EX ZEND_BEGIN_ARG_INFO_EX
25 |
26 | #define namespace_switch(n) \
27 | (YAF_G(use_namespace)? n##_ns : n)
28 |
29 | #define YAF_INIT_CLASS_ENTRY(ce, name, name_ns, methods) \
30 | if(YAF_G(use_namespace)) { \
31 | INIT_CLASS_ENTRY(ce, name_ns, methods); \
32 | } else { \
33 | INIT_CLASS_ENTRY(ce, name, methods); \
34 | }
35 | #else
36 |
37 | #ifdef YAF_HAVE_NAMESPACE
38 | #undef YAF_HAVE_NAMESPACE
39 | #endif
40 |
41 | #define namespace_switch(n) (n)
42 | #define YAF_INIT_CLASS_ENTRY(ce, name, name_ns, methods) INIT_CLASS_ENTRY(ce, name, methods)
43 | #define YAF_BEGIN_ARG_INFO static ZEND_BEGIN_ARG_INFO
44 | #define YAF_BEGIN_ARG_INFO_EX static ZEND_BEGIN_ARG_INFO_EX
45 |
46 | #endif
47 |
48 | #define YAF_END_ARG_INFO ZEND_END_ARG_INFO
49 | #define YAF_ARG_INFO ZEND_ARG_INFO
50 | #define YAF_ARG_OBJ_INFO ZEND_ARG_OBJ_INFO
51 | #define YAF_ARG_ARRAY_INFO ZEND_ARG_ARRAY_INFO
52 |
53 | #endif /* PHP_YAF_H */
54 |
55 | /*
56 | * Local variables:
57 | * tab-width: 4
58 | * c-basic-offset: 4
59 | * End:
60 | * vim600: noet sw=4 ts=4 fdm=marker
61 | * vim<600: noet sw=4 ts=4
62 | */
63 |
--------------------------------------------------------------------------------
/yaf_plugin.c:
--------------------------------------------------------------------------------
1 | /*
2 | +----------------------------------------------------------------------+
3 | | Yet Another Framework |
4 | +----------------------------------------------------------------------+
5 | | This source file is subject to version 3.01 of the PHP license, |
6 | | that is bundled with this package in the file LICENSE, and is |
7 | | available through the world-wide-web at the following url: |
8 | | http://www.php.net/license/3_01.txt |
9 | | If you did not receive a copy of the PHP license and are unable to |
10 | | obtain it through the world-wide-web, please send a note to |
11 | | license@php.net so we can mail you a copy immediately. |
12 | +----------------------------------------------------------------------+
13 | | Author: Xinchen Hui |
14 | +----------------------------------------------------------------------+
15 | */
16 |
17 | /* $Id: yaf_plugin.c 321289 2011-12-21 02:53:29Z laruence $ */
18 |
19 | #ifdef HAVE_CONFIG_H
20 | #include "config.h"
21 | #endif
22 |
23 | #include "php.h"
24 | #include "php_ini.h"
25 | #include "main/SAPI.h"
26 | #include "Zend/zend_interfaces.h"
27 | #include "Zend/zend_exceptions.h"
28 | #include "Zend/zend_alloc.h"
29 | #include "ext/standard/info.h"
30 | #include "ext/standard/php_string.h"
31 | #include "zend_objects.h"
32 |
33 | #include "php_yaf.h"
34 | #include "yaf_namespace.h"
35 | #include "yaf_plugin.h"
36 |
37 | zend_class_entry * yaf_plugin_ce;
38 |
39 | /** {{{ ARG_INFO
40 | */
41 | ZEND_BEGIN_ARG_INFO_EX(plugin_arg, 0, 0, 2)
42 | ZEND_ARG_OBJ_INFO(0, request, Yaf_Request_Abstract, 0)
43 | ZEND_ARG_OBJ_INFO(0, response, Yaf_Response_Abstract, 0)
44 | ZEND_END_ARG_INFO()
45 |
46 | #ifdef YAF_HAVE_NAMESPACE
47 | ZEND_BEGIN_ARG_INFO_EX(plugin_arg_ns, 0, 0, 2)
48 | ZEND_ARG_OBJ_INFO(0, request, Yaf\\Request_Abstract, 0)
49 | ZEND_ARG_OBJ_INFO(0, response, Yaf\\Response_Abstract, 0)
50 | ZEND_END_ARG_INFO()
51 | #endif
52 | /* }}} */
53 |
54 | /** {{{ proto public Yaf_Plugin::routerStartup(Yaf_Request_Abstract $request, Yaf_Response_Abstarct $response)
55 | */
56 | PHP_METHOD(yaf_plugin, routerStartup) {
57 | RETURN_TRUE;
58 | }
59 | /* }}} */
60 |
61 | /** {{{ proto public Yaf_Plugin::routerShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstarct $response)
62 | */
63 | PHP_METHOD(yaf_plugin, routerShutdown) {
64 | RETURN_TRUE;
65 | }
66 | /* }}} */
67 |
68 | /** {{{ proto public Yaf_Plugin::dispatchLoopStartup(Yaf_Request_Abstract $request, Yaf_Response_Abstarct $response)
69 | */
70 | PHP_METHOD(yaf_plugin, dispatchLoopStartup) {
71 | RETURN_TRUE;
72 | }
73 | /* }}} */
74 |
75 | /** {{{ proto public Yaf_Plugin::preDispatch(Yaf_Request_Abstract $request, Yaf_Response_Abstarct $response)
76 | */
77 | PHP_METHOD(yaf_plugin, preDispatch) {
78 | RETURN_TRUE;
79 | }
80 | /* }}} */
81 |
82 | /** {{{ proto public Yaf_Plugin::postDispatch(Yaf_Request_Abstract $request, Yaf_Response_Abstarct $response)
83 | */
84 | PHP_METHOD(yaf_plugin, postDispatch) {
85 | RETURN_TRUE;
86 | }
87 | /* }}} */
88 |
89 | /** {{{ proto public Yaf_Plugin::dispatchLoopShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstarct $response)
90 | */
91 | PHP_METHOD(yaf_plugin, dispatchLoopShutdown) {
92 | RETURN_TRUE;
93 | }
94 | /* }}} */
95 |
96 | /** {{{ proto public Yaf_Plugin::preResponse(Yaf_Request_Abstract $request, Yaf_Response_Abstarct $response)
97 | */
98 | PHP_METHOD(yaf_plugin, preResponse) {
99 | RETURN_TRUE;
100 | }
101 | /* }}} */
102 |
103 | /** {{{ yaf_plugin_methods
104 | */
105 | zend_function_entry yaf_plugin_methods[] = {
106 | PHP_ME(yaf_plugin, routerStartup, plugin_arg, ZEND_ACC_PUBLIC)
107 | PHP_ME(yaf_plugin, routerShutdown, plugin_arg, ZEND_ACC_PUBLIC)
108 | PHP_ME(yaf_plugin, dispatchLoopStartup, plugin_arg, ZEND_ACC_PUBLIC)
109 | PHP_ME(yaf_plugin, dispatchLoopShutdown, plugin_arg, ZEND_ACC_PUBLIC)
110 | PHP_ME(yaf_plugin, preDispatch, plugin_arg, ZEND_ACC_PUBLIC)
111 | PHP_ME(yaf_plugin, postDispatch, plugin_arg, ZEND_ACC_PUBLIC)
112 | PHP_ME(yaf_plugin, preResponse, plugin_arg, ZEND_ACC_PUBLIC)
113 | {NULL, NULL, NULL}
114 | };
115 |
116 | #ifdef YAF_HAVE_NAMESPACE
117 | zend_function_entry yaf_plugin_methods_ns[] = {
118 | PHP_ME(yaf_plugin, routerStartup, plugin_arg_ns, ZEND_ACC_PUBLIC)
119 | PHP_ME(yaf_plugin, routerShutdown, plugin_arg_ns, ZEND_ACC_PUBLIC)
120 | PHP_ME(yaf_plugin, dispatchLoopStartup, plugin_arg_ns, ZEND_ACC_PUBLIC)
121 | PHP_ME(yaf_plugin, dispatchLoopShutdown, plugin_arg_ns, ZEND_ACC_PUBLIC)
122 | PHP_ME(yaf_plugin, preDispatch, plugin_arg_ns, ZEND_ACC_PUBLIC)
123 | PHP_ME(yaf_plugin, postDispatch, plugin_arg_ns, ZEND_ACC_PUBLIC)
124 | PHP_ME(yaf_plugin, preResponse, plugin_arg_ns, ZEND_ACC_PUBLIC)
125 | {NULL, NULL, NULL}
126 | };
127 | #endif
128 | /* }}} */
129 |
130 | /** {{{ YAF_STARTUP_FUNCTION
131 | */
132 | YAF_STARTUP_FUNCTION(plugin) {
133 | zend_class_entry ce;
134 | YAF_INIT_CLASS_ENTRY(ce, "Yaf_Plugin_Abstract", "Yaf\\Plugin_Abstract", namespace_switch(yaf_plugin_methods));
135 | /* abstract class Yaf_Plugin_Abstract */
136 | yaf_plugin_ce = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC);
137 | yaf_plugin_ce->ce_flags |= ZEND_ACC_EXPLICIT_ABSTRACT_CLASS;
138 |
139 | return SUCCESS;
140 | }
141 | /* }}} */
142 |
143 | /*
144 | * Local variables:
145 | * tab-width: 4
146 | * c-basic-offset: 4
147 | * End:
148 | * vim600: noet sw=4 ts=4 fdm=marker
149 | * vim<600: noet sw=4 ts=4
150 | */
151 |
--------------------------------------------------------------------------------
/yaf_plugin.h:
--------------------------------------------------------------------------------
1 | /*
2 | +----------------------------------------------------------------------+
3 | | Yet Another Framework |
4 | +----------------------------------------------------------------------+
5 | | This source file is subject to version 3.01 of the PHP license, |
6 | | that is bundled with this package in the file LICENSE, and is |
7 | | available through the world-wide-web at the following url: |
8 | | http://www.php.net/license/3_01.txt |
9 | | If you did not receive a copy of the PHP license and are unable to |
10 | | obtain it through the world-wide-web, please send a note to |
11 | | license@php.net so we can mail you a copy immediately. |
12 | +----------------------------------------------------------------------+
13 | | Author: Xinchen Hui |
14 | +----------------------------------------------------------------------+
15 | */
16 |
17 | /* $Id: yaf_plugin.h 321289 2011-12-21 02:53:29Z laruence $ */
18 |
19 | #ifndef YAF_PLUGIN_H
20 | #define YAF_PLUGIN_H
21 |
22 | extern zend_class_entry *yaf_plugin_ce;
23 |
24 | YAF_STARTUP_FUNCTION(plugin);
25 | #endif
26 | /*
27 | * Local variables:
28 | * tab-width: 4
29 | * c-basic-offset: 4
30 | * End:
31 | * vim600: noet sw=4 ts=4 fdm=marker
32 | * vim<600: noet sw=4 ts=4
33 | */
34 |
--------------------------------------------------------------------------------
/yaf_registry.c:
--------------------------------------------------------------------------------
1 | /*
2 | +----------------------------------------------------------------------+
3 | | Yet Another Framework |
4 | +----------------------------------------------------------------------+
5 | | This source file is subject to version 3.01 of the PHP license, |
6 | | that is bundled with this package in the file LICENSE, and is |
7 | | available through the world-wide-web at the following url: |
8 | | http://www.php.net/license/3_01.txt |
9 | | If you did not receive a copy of the PHP license and are unable to |
10 | | obtain it through the world-wide-web, please send a note to |
11 | | license@php.net so we can mail you a copy immediately. |
12 | +----------------------------------------------------------------------+
13 | | Author: Xinchen Hui |
14 | +----------------------------------------------------------------------+
15 | */
16 |
17 | /* $Id: yaf_registry.c 328268 2012-11-07 14:44:04Z laruence $ */
18 |
19 | #ifdef HAVE_CONFIG_H
20 | #include "config.h"
21 | #endif
22 |
23 | #include "php.h"
24 | #include "php_ini.h"
25 | #include "main/SAPI.h"
26 |
27 | #include "php_yaf.h"
28 | #include "yaf_namespace.h"
29 | #include "yaf_registry.h"
30 |
31 | zend_class_entry *yaf_registry_ce;
32 |
33 | /* {{{ ARG_INFO
34 | */
35 | ZEND_BEGIN_ARG_INFO_EX(yaf_registry_get_arginfo, 0, 0, 1)
36 | ZEND_ARG_INFO(0, name)
37 | ZEND_END_ARG_INFO()
38 |
39 | ZEND_BEGIN_ARG_INFO_EX(yaf_registry_has_arginfo, 0, 0, 1)
40 | ZEND_ARG_INFO(0, name)
41 | ZEND_END_ARG_INFO()
42 |
43 | ZEND_BEGIN_ARG_INFO_EX(yaf_registry_del_arginfo, 0, 0, 1)
44 | ZEND_ARG_INFO(0, name)
45 | ZEND_END_ARG_INFO()
46 |
47 | ZEND_BEGIN_ARG_INFO_EX(yaf_registry_set_arginfo, 0, 0, 2)
48 | ZEND_ARG_INFO(0, name)
49 | ZEND_ARG_INFO(0, value)
50 | ZEND_END_ARG_INFO()
51 | /* }}} */
52 |
53 | /** {{{ yaf_registry_t *yaf_registry_instance(yaf_registry_t *this_ptr TSRMLS_DC)
54 | */
55 | yaf_registry_t *yaf_registry_instance(yaf_registry_t *this_ptr TSRMLS_DC) {
56 |
57 | /* 读取当前类 Yaf\\Registry 的静态属性 $_instance */
58 | yaf_registry_t *instance = zend_read_static_property(yaf_registry_ce, ZEND_STRL(YAF_REGISTRY_PROPERTY_NAME_INSTANCE), 1 TSRMLS_CC);
59 |
60 | /* 判断instance的类型是否为类,并且是否是yaf_registry_ce的实例 */
61 | if (Z_TYPE_P(instance) != IS_OBJECT || !instanceof_function(Z_OBJCE_P(instance), yaf_registry_ce TSRMLS_CC)) {
62 | zval *regs;
63 |
64 | /* 为yaf_registry_ce实例化一个对象$_instance */
65 | MAKE_STD_ZVAL(instance);
66 | object_init_ex(instance, yaf_registry_ce);
67 |
68 | /* 为类增的属性$_entries赋空数组值 */
69 | MAKE_STD_ZVAL(regs);
70 | array_init(regs);
71 | zend_update_property(yaf_registry_ce, instance, ZEND_STRL(YAF_REGISTRY_PROPERTY_NAME_ENTRYS), regs TSRMLS_CC);
72 |
73 | /* 更新类yaf_registry_ce的静态属性$_instance */
74 | zend_update_static_property(yaf_registry_ce, ZEND_STRL(YAF_REGISTRY_PROPERTY_NAME_INSTANCE), instance TSRMLS_CC);
75 |
76 | zval_ptr_dtor(®s);
77 | zval_ptr_dtor(&instance);
78 | }
79 |
80 | return instance;
81 | }
82 | /* }}} */
83 |
84 | /** {{{ int yaf_registry_is_set(char *name, int len TSRMLS_DC)
85 | */
86 | int yaf_registry_is_set(char *name, int len TSRMLS_DC) {
87 | yaf_registry_t *registry;
88 | zval *entrys;
89 |
90 | /* 获取当前类的实例 */
91 | registry = yaf_registry_instance(NULL TSRMLS_CC);
92 | /* 获取当前类的属性$_entries */
93 | entrys = zend_read_property(yaf_registry_ce, registry, ZEND_STRL(YAF_REGISTRY_PROPERTY_NAME_ENTRYS), 1 TSRMLS_CC);
94 | /* 判断在属性$_entries中是否有name这个键存在 */
95 | return zend_hash_exists(Z_ARRVAL_P(entrys), name, len + 1);
96 | }
97 | /* }}} */
98 |
99 | /** {{{ proto private Yaf_Registry::__construct(void)
100 | */
101 | PHP_METHOD(yaf_registry, __construct) {
102 | }
103 | /* }}} */
104 |
105 | /** {{{ proto private Yaf_Registry::__clone(void)
106 | */
107 | PHP_METHOD(yaf_registry, __clone) {
108 | }
109 | /* }}} */
110 |
111 | /** {{{ proto public static Yaf_Registry::get($name)
112 | */
113 | PHP_METHOD(yaf_registry, get) {
114 | char *name;
115 | uint len;
116 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len) == FAILURE) {
117 | return;
118 | } else {
119 | zval **ppzval, *entrys;
120 | yaf_registry_t *registry;
121 |
122 | /* 获取当前类的实例 */
123 | registry = yaf_registry_instance(NULL TSRMLS_CC);
124 | /* 获取类属性$_entries */
125 | entrys = zend_read_property(yaf_registry_ce, registry, ZEND_STRL(YAF_REGISTRY_PROPERTY_NAME_ENTRYS), 1 TSRMLS_CC);
126 |
127 | /* $_entries存在并且类型是数组 */
128 | if (entrys && Z_TYPE_P(entrys) == IS_ARRAY) {
129 | /* 在$_entries这个类属性中查找name这个键对应的value,并返回 */
130 | if (zend_hash_find(Z_ARRVAL_P(entrys), name, len + 1, (void **) &ppzval) == SUCCESS) {
131 | RETURN_ZVAL(*ppzval, 1, 0);
132 | }
133 | }
134 | }
135 |
136 | RETURN_NULL();
137 | }
138 | /* }}} */
139 |
140 | /** {{{ proto public static Yaf_Registry::set($name, $value)
141 | */
142 | PHP_METHOD(yaf_registry, set) {
143 | zval *value;
144 | char *name;
145 | uint len;
146 |
147 | /* 获取用户传入的key和name */
148 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz", &name, &len, &value) == FAILURE) {
149 | return;
150 | } else {
151 | yaf_registry_t *registry;
152 | zval *entrys;
153 |
154 | /* 获取类的实例化 */
155 | registry = yaf_registry_instance(NULL TSRMLS_CC);
156 | /* 获取类属性$_entries */
157 | entrys = zend_read_property(yaf_registry_ce, registry, ZEND_STRL(YAF_REGISTRY_PROPERTY_NAME_ENTRYS), 1 TSRMLS_CC);
158 |
159 | /* ++refcount__gc */
160 | Z_ADDREF_P(value);
161 | /* 将心的键值对加入$_entries */
162 | if (zend_hash_update(Z_ARRVAL_P(entrys), name, len + 1, &value, sizeof(zval *), NULL) == SUCCESS) {
163 | RETURN_TRUE;
164 | }
165 | }
166 |
167 | RETURN_FALSE;
168 | }
169 | /* }}} */
170 |
171 | /** {{{ proto public static Yaf_Registry::del($name)
172 | */
173 | PHP_METHOD(yaf_registry, del) {
174 | char *name;
175 | uint len;
176 | /* 获取要删除的键值 */
177 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len) == FAILURE) {
178 | return;
179 | } else {
180 | yaf_registry_t *registry;
181 | zval *entrys;
182 |
183 | /* 获取类的实例化 */
184 | registry = yaf_registry_instance(NULL TSRMLS_CC);
185 | /* 获取类属性$_entries */
186 | entrys = zend_read_property(yaf_registry_ce, registry, ZEND_STRL(YAF_REGISTRY_PROPERTY_NAME_ENTRYS), 1 TSRMLS_CC);
187 |
188 | /* 从$_entries数组中删除name对应的键值对 */
189 | zend_hash_del(Z_ARRVAL_P(entrys), name, len + 1);
190 | }
191 |
192 | RETURN_TRUE;
193 | }
194 | /* }}} */
195 |
196 | /** {{{ proto public Yaf_Registry::has($name)
197 | */
198 | PHP_METHOD(yaf_registry, has) {
199 | char *name;
200 | uint len;
201 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &len) == FAILURE) {
202 | return;
203 | } else {
204 | RETURN_BOOL(yaf_registry_is_set(name, len TSRMLS_CC));
205 | }
206 | }
207 | /* }}} */
208 |
209 | /** {{{ proto public Yaf_Registry::getInstance(void)
210 | */
211 | PHP_METHOD(yaf_registry, getInstance) {
212 | /* 获取或者生成当前类的实例并返回 */
213 | yaf_registry_t *registry = yaf_registry_instance(NULL TSRMLS_CC);
214 | RETURN_ZVAL(registry, 1, 0);
215 | }
216 | /* }}} */
217 |
218 | /** {{{ yaf_registry_methods
219 | */
220 | zend_function_entry yaf_registry_methods[] = {
221 | PHP_ME(yaf_registry, __construct, NULL, ZEND_ACC_CTOR|ZEND_ACC_PRIVATE)
222 | PHP_ME(yaf_registry, __clone, NULL, ZEND_ACC_CLONE|ZEND_ACC_PRIVATE)
223 | PHP_ME(yaf_registry, get, yaf_registry_get_arginfo, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
224 | PHP_ME(yaf_registry, has, yaf_registry_has_arginfo, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
225 | PHP_ME(yaf_registry, set, yaf_registry_set_arginfo, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
226 | PHP_ME(yaf_registry, del, yaf_registry_del_arginfo, ZEND_ACC_PUBLIC|ZEND_ACC_STATIC)
227 | {NULL, NULL, NULL}
228 | };
229 | /* }}} */
230 |
231 | /** {{{ YAF_STARTUP_FUNCTION
232 | */
233 | YAF_STARTUP_FUNCTION(registry) {
234 | zend_class_entry ce;
235 |
236 | YAF_INIT_CLASS_ENTRY(ce, "Yaf_Registry", "Yaf\\Registry", yaf_registry_methods);
237 |
238 | /* 在模块初始化阶段注册当前类为final类型 */
239 | yaf_registry_ce = zend_register_internal_class_ex(&ce, NULL, NULL TSRMLS_CC);
240 | yaf_registry_ce->ce_flags |= ZEND_ACC_FINAL_CLASS;
241 |
242 | /* 为类定义两个属性$_instance和$_entries,默认值都为null */
243 | zend_declare_property_null(yaf_registry_ce, ZEND_STRL(YAF_REGISTRY_PROPERTY_NAME_INSTANCE), ZEND_ACC_PROTECTED|ZEND_ACC_STATIC TSRMLS_CC);
244 | zend_declare_property_null(yaf_registry_ce, ZEND_STRL(YAF_REGISTRY_PROPERTY_NAME_ENTRYS), ZEND_ACC_PROTECTED TSRMLS_CC);
245 |
246 | return SUCCESS;
247 | }
248 | /* }}} */
249 |
250 | /*
251 | * Local variables:
252 | * tab-width: 4
253 | * c-basic-offset: 4
254 | * End:
255 | * vim600: noet sw=4 ts=4 fdm=marker
256 | * vim<600: noet sw=4 ts=4
257 | */
258 |
--------------------------------------------------------------------------------
/yaf_registry.h:
--------------------------------------------------------------------------------
1 | /*
2 | +----------------------------------------------------------------------+
3 | | Yet Another Framework |
4 | +----------------------------------------------------------------------+
5 | | This source file is subject to version 3.01 of the PHP license, |
6 | | that is bundled with this package in the file LICENSE, and is |
7 | | available through the world-wide-web at the following url: |
8 | | http://www.php.net/license/3_01.txt |
9 | | If you did not receive a copy of the PHP license and are unable to |
10 | | obtain it through the world-wide-web, please send a note to |
11 | | license@php.net so we can mail you a copy immediately. |
12 | +----------------------------------------------------------------------+
13 | | Author: Xinchen Hui |
14 | +----------------------------------------------------------------------+
15 | */
16 |
17 | /* $Id: yaf_registry.h 321289 2011-12-21 02:53:29Z laruence $ */
18 |
19 | #ifndef YAF_REGISTRY_H
20 | #define YAF_REGISTRY_H
21 |
22 | #define YAF_REGISTRY_PROPERTY_NAME_ENTRYS "_entries"
23 | #define YAF_REGISTRY_PROPERTY_NAME_INSTANCE "_instance"
24 |
25 | extern zend_class_entry *yaf_registry_ce;
26 |
27 | YAF_STARTUP_FUNCTION(registry);
28 | #endif
29 | /*
30 | * Local variables:
31 | * tab-width: 4
32 | * c-basic-offset: 4
33 | * End:
34 | * vim600: noet sw=4 ts=4 fdm=marker
35 | * vim<600: noet sw=4 ts=4
36 | */
37 |
--------------------------------------------------------------------------------
/yaf_request.h:
--------------------------------------------------------------------------------
1 | /*
2 | +----------------------------------------------------------------------+
3 | | Yet Another Framework |
4 | +----------------------------------------------------------------------+
5 | | This source file is subject to version 3.01 of the PHP license, |
6 | | that is bundled with this package in the file LICENSE, and is |
7 | | available through the world-wide-web at the following url: |
8 | | http://www.php.net/license/3_01.txt |
9 | | If you did not receive a copy of the PHP license and are unable to |
10 | | obtain it through the world-wide-web, please send a note to |
11 | | license@php.net so we can mail you a copy immediately. |
12 | +----------------------------------------------------------------------+
13 | | Author: Xinchen Hui |
14 | +----------------------------------------------------------------------+
15 | */
16 |
17 | /* $Id: yaf_request.h 327591 2012-09-10 10:56:13Z laruence $ */
18 |
19 | #ifndef YAF_REQUEST_H
20 | #define YAF_REQUEST_H
21 |
22 | #define YAF_REQUEST_PROPERTY_NAME_MODULE "module"
23 | #define YAF_REQUEST_PROPERTY_NAME_CONTROLLER "controller"
24 | #define YAF_REQUEST_PROPERTY_NAME_ACTION "action"
25 | #define YAF_REQUEST_PROPERTY_NAME_METHOD "method"
26 | #define YAF_REQUEST_PROPERTY_NAME_PARAMS "params"
27 | #define YAF_REQUEST_PROPERTY_NAME_URI "uri"
28 | #define YAF_REQUEST_PROPERTY_NAME_STATE "dispatched"
29 | #define YAF_REQUEST_PROPERTY_NAME_LANG "language"
30 | #define YAF_REQUEST_PROPERTY_NAME_ROUTED "routed"
31 | #define YAF_REQUEST_PROPERTY_NAME_BASE "_base_uri"
32 | #define YAF_REQUEST_PROPERTY_NAME_EXCEPTION "_exception"
33 |
34 | #define YAF_REQUEST_SERVER_URI "request_uri="
35 |
36 | #define YAF_GLOBAL_VARS_TYPE unsigned int
37 | #define YAF_GLOBAL_VARS_POST TRACK_VARS_POST
38 | #define YAF_GLOBAL_VARS_GET TRACK_VARS_GET
39 | #define YAF_GLOBAL_VARS_ENV TRACK_VARS_ENV
40 | #define YAF_GLOBAL_VARS_FILES TRACK_VARS_FILES
41 | #define YAF_GLOBAL_VARS_SERVER TRACK_VARS_SERVER
42 | #define YAF_GLOBAL_VARS_REQUEST TRACK_VARS_REQUEST
43 | #define YAF_GLOBAL_VARS_COOKIE TRACK_VARS_COOKIE
44 |
45 | #define YAF_REQUEST_IS_METHOD(x) \
46 | PHP_METHOD(yaf_request, is##x) {\
47 | zval * method = zend_read_property(Z_OBJCE_P(getThis()), getThis(), ZEND_STRL(YAF_REQUEST_PROPERTY_NAME_METHOD), 0 TSRMLS_CC);\
48 | if (strncasecmp(#x, Z_STRVAL_P(method), Z_STRLEN_P(method)) == 0) { \
49 | RETURN_TRUE; \
50 | } \
51 | RETURN_FALSE; \
52 | }
53 |
54 | #define YAF_REQUEST_METHOD(ce, x, type) \
55 | PHP_METHOD(ce, get##x) { \
56 | char *name; \
57 | int len; \
58 | zval *ret; \
59 | zval *def = NULL; \
60 | if (ZEND_NUM_ARGS() == 0) { \
61 | ret = yaf_request_query(type, NULL, 0 TSRMLS_CC); \
62 | }else if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|z", &name, &len, &def) == FAILURE) { \
63 | return; \
64 | } else { \
65 | ret = yaf_request_query(type, name, len TSRMLS_CC); \
66 | if (ZVAL_IS_NULL(ret)) { \
67 | if (def != NULL) { \
68 | zval_ptr_dtor(&ret); \
69 | RETURN_ZVAL(def, 1, 0); \
70 | } \
71 | } \
72 | } \
73 | RETURN_ZVAL(ret, 1, 1); \
74 | }
75 |
76 | extern zend_class_entry * yaf_request_ce;
77 |
78 | zval * yaf_request_query(uint type, char * name, uint len TSRMLS_DC);
79 | yaf_request_t * yaf_request_instance(yaf_request_t *this_ptr, char *info TSRMLS_DC);
80 | int yaf_request_set_base_uri(yaf_request_t *request, char *base_uri, char *request_uri TSRMLS_DC);
81 | PHPAPI void php_session_start(TSRMLS_D);
82 |
83 | zval * yaf_request_get_method(yaf_request_t *instance TSRMLS_DC);
84 | zval * yaf_request_get_param(yaf_request_t *instance, char *key, int len TSRMLS_DC);
85 | zval * yaf_request_get_language(yaf_request_t *instance TSRMLS_DC);
86 |
87 | int yaf_request_is_routed(yaf_request_t *request TSRMLS_DC);
88 | int yaf_request_is_dispatched(yaf_request_t *request TSRMLS_DC);
89 | int yaf_request_set_dispatched(yaf_request_t *request, int flag TSRMLS_DC);
90 | int yaf_request_set_routed(yaf_request_t *request, int flag TSRMLS_DC);
91 | int yaf_request_set_params_single(yaf_request_t *instance, char *key, int len, zval *value TSRMLS_DC);
92 | int yaf_request_set_params_multi(yaf_request_t *instance, zval *values TSRMLS_DC);
93 |
94 | YAF_STARTUP_FUNCTION(request);
95 |
96 | #endif
97 | /*
98 | * Local variables:
99 | * tab-width: 4
100 | * c-basic-offset: 4
101 | * End:
102 | * vim600: noet sw=4 ts=4 fdm=marker
103 | * vim<600: noet sw=4 ts=4
104 | */
105 |
--------------------------------------------------------------------------------
/yaf_response.h:
--------------------------------------------------------------------------------
1 | /*
2 | +----------------------------------------------------------------------+
3 | | Yet Another Framework |
4 | +----------------------------------------------------------------------+
5 | | This source file is subject to version 3.01 of the PHP license, |
6 | | that is bundled with this package in the file LICENSE, and is |
7 | | available through the world-wide-web at the following url: |
8 | | http://www.php.net/license/3_01.txt |
9 | | If you did not receive a copy of the PHP license and are unable to |
10 | | obtain it through the world-wide-web, please send a note to |
11 | | license@php.net so we can mail you a copy immediately. |
12 | +----------------------------------------------------------------------+
13 | | Author: Xinchen Hui |
14 | +----------------------------------------------------------------------+
15 | */
16 |
17 | /* $Id: yaf_response.h 327510 2012-09-07 04:16:31Z laruence $ */
18 |
19 | #ifndef PHP_YAF_RESPONSE_H
20 | #define PHP_YAF_RESPONSE_H
21 |
22 | #define YAF_RESPONSE_PROPERTY_NAME_HEADER "_header"
23 | #define YAF_RESPONSE_PROPERTY_NAME_BODY "_body"
24 | #define YAF_RESPONSE_PROPERTY_NAME_HEADEREXCEPTION "_sendheader"
25 | #define YAF_RESPONSE_PROPERTY_NAME_RESPONSECODE "_response_code"
26 | #define YAF_RESPONSE_PROPERTY_NAME_DEFAULTBODY "content"
27 | #define YAF_RESPONSE_PROPERTY_NAME_DEFAULTBODYNAME "DEFAULT_BODY"
28 |
29 | #define YAF_RESPONSE_REPLACE 0
30 | #define YAF_RESPONSE_PREPEND 1
31 | #define YAF_RESPONSE_APPEND 2
32 |
33 | extern zend_class_entry *yaf_response_ce;
34 | extern zend_class_entry *yaf_response_http_ce;
35 | extern zend_class_entry *yaf_response_cli_ce;
36 |
37 | yaf_response_t * yaf_response_instance(yaf_response_t *this_ptr, char *sapi_name TSRMLS_DC);
38 | int yaf_response_alter_body(yaf_response_t *response, char *name, int name_len, char *body, long body_len, int flag TSRMLS_DC);
39 | int yaf_response_send(yaf_response_t *response TSRMLS_DC);
40 | int yaf_response_set_redirect(yaf_response_t *response, char *url, int len TSRMLS_DC);
41 | int yaf_response_clear_body(yaf_response_t *response, char *name, uint name_len TSRMLS_DC);
42 |
43 | YAF_STARTUP_FUNCTION(response);
44 |
45 | #endif
46 |
--------------------------------------------------------------------------------
/yaf_router.h:
--------------------------------------------------------------------------------
1 | /*
2 | +----------------------------------------------------------------------+
3 | | Yet Another Framework |
4 | +----------------------------------------------------------------------+
5 | | This source file is subject to version 3.01 of the PHP license, |
6 | | that is bundled with this package in the file LICENSE, and is |
7 | | available through the world-wide-web at the following url: |
8 | | http://www.php.net/license/3_01.txt |
9 | | If you did not receive a copy of the PHP license and are unable to |
10 | | obtain it through the world-wide-web, please send a note to |
11 | | license@php.net so we can mail you a copy immediately. |
12 | +----------------------------------------------------------------------+
13 | | Author: Xinchen Hui |
14 | +----------------------------------------------------------------------+
15 | */
16 |
17 | /* $Id: yaf_router.h 327580 2012-09-10 06:31:34Z laruence $ */
18 |
19 | #ifndef YAF_ROUTER_H
20 | #define YAF_ROUTER_H
21 |
22 | #define YAF_ROUTER_DEFAULT_ACTION "index"
23 | #define YAF_ROUTER_DEFAULT_CONTROLLER "Index"
24 | #define YAF_ROUTER_DEFAULT_MODULE "Index"
25 | #define YAF_DEFAULT_EXT "php"
26 |
27 | #define YAF_ROUTER_PROPERTY_NAME_ROUTERS "_routes" //路由器已有的路由协议栈, 默认的栈底总是名为"default"的Yaf_Route_Static路由协议的实例.
28 | #define YAF_ROUTER_PROPERTY_NAME_CURRENT_ROUTE "_current" //在路由成功后, 路由生效的路由协议名
29 |
30 | extern zend_class_entry * yaf_router_ce;
31 |
32 | yaf_router_t * yaf_router_instance(yaf_router_t *this_ptr TSRMLS_DC);
33 | zval * yaf_router_parse_parameters(char *uri TSRMLS_DC);
34 | int yaf_router_route(yaf_router_t *router, yaf_request_t *request TSRMLS_DC);
35 |
36 | YAF_STARTUP_FUNCTION(router);
37 | #endif
38 | /*
39 | * Local variables:
40 | * tab-width: 4
41 | * c-basic-offset: 4
42 | * End:
43 | * vim600: noet sw=4 ts=4 fdm=marker
44 | * vim<600: noet sw=4 ts=4
45 | */
46 |
--------------------------------------------------------------------------------
/yaf_session.h:
--------------------------------------------------------------------------------
1 | /*
2 | +----------------------------------------------------------------------+
3 | | Yet Another Framework |
4 | +----------------------------------------------------------------------+
5 | | This source file is subject to version 3.01 of the PHP license, |
6 | | that is bundled with this package in the file LICENSE, and is |
7 | | available through the world-wide-web at the following url: |
8 | | http://www.php.net/license/3_01.txt |
9 | | If you did not receive a copy of the PHP license and are unable to |
10 | | obtain it through the world-wide-web, please send a note to |
11 | | license@php.net so we can mail you a copy immediately. |
12 | +----------------------------------------------------------------------+
13 | | Author: Xinchen Hui |
14 | +----------------------------------------------------------------------+
15 | */
16 |
17 | /* $Id: yaf_session.h 315615 2011-08-27 14:14:48Z laruence $ */
18 |
19 | #ifndef YAF_SESSION_H
20 | #define YAF_SESSION_H
21 |
22 | #define YAF_SESSION_PROPERTY_NAME_STATUS "_started"
23 | #define YAF_SESSION_PROPERTY_NAME_SESSION "_session"
24 | #define YAF_SESSION_PROPERTY_NAME_INSTANCE "_instance"
25 |
26 | extern zend_class_entry *yaf_session_ce;
27 |
28 | PHPAPI void php_session_start(TSRMLS_D);
29 | YAF_STARTUP_FUNCTION(session);
30 | #endif
31 | /*
32 | * Local variables:
33 | * tab-width: 4
34 | * c-basic-offset: 4
35 | * End:
36 | * vim600: noet sw=4 ts=4 fdm=marker
37 | * vim<600: noet sw=4 ts=4
38 | */
39 |
--------------------------------------------------------------------------------
/yaf_view.c:
--------------------------------------------------------------------------------
1 | /*
2 | +----------------------------------------------------------------------+
3 | | Yet Another Framework |
4 | +----------------------------------------------------------------------+
5 | | This source file is subject to version 3.01 of the PHP license, |
6 | | that is bundled with this package in the file LICENSE, and is |
7 | | available through the world-wide-web at the following url: |
8 | | http://www.php.net/license/3_01.txt |
9 | | If you did not receive a copy of the PHP license and are unable to |
10 | | obtain it through the world-wide-web, please send a note to |
11 | | license@php.net so we can mail you a copy immediately. |
12 | +----------------------------------------------------------------------+
13 | | Author: Xinchen Hui |
14 | +----------------------------------------------------------------------+
15 | */
16 |
17 | /* $Id: yaf_view.c 321289 2011-12-21 02:53:29Z laruence $ */
18 |
19 | #ifdef HAVE_CONFIG_H
20 | #include "config.h"
21 | #endif
22 |
23 | #include "php.h"
24 | #include "php_ini.h"
25 | #include "main/SAPI.h"
26 | #include "Zend/zend_interfaces.h"
27 | #include "Zend/zend_exceptions.h"
28 | #include "Zend/zend_alloc.h"
29 |
30 | #include "php_yaf.h"
31 | #include "yaf_namespace.h"
32 | #include "yaf_exception.h"
33 | #include "yaf_loader.h"
34 | #include "yaf_view.h"
35 |
36 | #include "views/interface.c"
37 | #include "views/simple.c"
38 | /* 调试信息 */
39 | #if 0
40 | static yaf_view_struct yaf_buildin_views[] = {
41 | {"classical", &yaf_view_simple_ce, yaf_view_simple_init},
42 | {NULL, NULL, NULL}
43 | };
44 | #endif
45 | /* 调试信息 */
46 | #if 0
47 | /** {{{ yaf_view_t * yaf_view_instance(yaf_view_t *this_ptr TSRMLS_DC)
48 | */
49 | yaf_view_t * yaf_view_instance(yaf_view_t *this_ptr TSRMLS_DC) {
50 | yaf_view_t *view = NULL;
51 | yaf_view_struct *p = yaf_buildin_views;
52 |
53 | for(;;++p) {
54 | yaf_current_view = p;
55 | yaf_view_ce = *(p->ce);
56 | break;
57 | }
58 |
59 | yaf_view_ce = *(yaf_current_view->ce);
60 |
61 | MAKE_STD_ZVAL(view);
62 | object_init_ex(view, *(yaf_current_view->ce));
63 |
64 | if (yaf_current_view->init) {
65 | yaf_current_view->init(view TSRMLS_CC);
66 | }
67 | MAKE_STD_ZVAL(view);
68 | object_init_ex(view, yaf_view_simple_ce);
69 | yaf_view_simple_init(view TSRMLS_CC);
70 |
71 | return view;
72 | }
73 | /* }}} */
74 | #endif
75 |
76 | /** {{{ YAF_STARTUP_FUNCTION
77 | */
78 | YAF_STARTUP_FUNCTION(view) {
79 | YAF_STARTUP(view_interface);
80 | YAF_STARTUP(view_simple);
81 |
82 | return SUCCESS;
83 | }
84 | /* }}} */
85 |
86 | /*
87 | * Local variables:
88 | * tab-width: 4
89 | * c-basic-offset: 4
90 | * End:
91 | * vim600: noet sw=4 ts=4 fdm=marker
92 | * vim<600: noet sw=4 ts=4
93 | */
94 |
--------------------------------------------------------------------------------
/yaf_view.h:
--------------------------------------------------------------------------------
1 | /*
2 | +----------------------------------------------------------------------+
3 | | Yet Another Framework |
4 | +----------------------------------------------------------------------+
5 | | This source file is subject to version 3.01 of the PHP license, |
6 | | that is bundled with this package in the file LICENSE, and is |
7 | | available through the world-wide-web at the following url: |
8 | | http://www.php.net/license/3_01.txt |
9 | | If you did not receive a copy of the PHP license and are unable to |
10 | | obtain it through the world-wide-web, please send a note to |
11 | | license@php.net so we can mail you a copy immediately. |
12 | +----------------------------------------------------------------------+
13 | | Author: Xinchen Hui |
14 | +----------------------------------------------------------------------+
15 | */
16 |
17 | /* $Id: yaf_view.h 328256 2012-11-06 08:44:52Z laruence $ */
18 |
19 | #ifndef YAF_VIEW_H
20 | #define YAF_VIEW_H
21 |
22 | #define yaf_view_instance yaf_view_simple_instance
23 | #define yaf_view_ce yaf_view_simple_ce
24 |
25 | #define YAF_VIEW_PROPERTY_NAME_TPLVARS "_tpl_vars"
26 | #define YAF_VIEW_PROPERTY_NAME_TPLDIR "_tpl_dir"
27 | #define YAF_VIEW_PROPERTY_NAME_OPTS "_options"
28 |
29 | #if ((PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 4))
30 | struct _yaf_view_simple_buffer {
31 | char *buffer;
32 | unsigned long size;
33 | unsigned long len;
34 | struct _yaf_view_simple_buffer *prev;
35 | };
36 |
37 | typedef struct _yaf_view_simple_buffer yaf_view_simple_buffer;
38 |
39 | typedef int(*yaf_body_write_func)(const char *str, uint str_length TSRMLS_DC);
40 |
41 | #define YAF_REDIRECT_OUTPUT_BUFFER(seg) \
42 | do { \
43 | if (!YAF_G(owrite_handler)) { \
44 | YAF_G(owrite_handler) = OG(php_body_write); \ /* 内容输出函数 */
45 | } \
46 | OG(php_body_write) = yaf_view_simple_render_write; \
47 | old_scope = EG(scope); \
48 | EG(scope) = yaf_view_simple_ce; \
49 | seg = (yaf_view_simple_buffer *)emalloc(sizeof(yaf_view_simple_buffer)); \
50 | memset(seg, 0, sizeof(yaf_view_simple_buffer)); \
51 | seg->prev = YAF_G(buffer);\
52 | YAF_G(buffer) = seg; \
53 | YAF_G(buf_nesting)++;\
54 | } while (0)
55 |
56 | #define YAF_RESTORE_OUTPUT_BUFFER(seg) \
57 | do { \
58 | EG(scope) = old_scope; \
59 | YAF_G(buffer) = seg->prev; \
60 | if (!(--YAF_G(buf_nesting))) { \
61 | OG(php_body_write) = (yaf_body_write_func)YAF_G(owrite_handler); \
62 | if (YAF_G(buffer)) { \
63 | php_error_docref(NULL TSRMLS_CC, E_ERROR, "Yaf output buffer collapsed"); \
64 | } else { \
65 | YAF_G(owrite_handler) = NULL; \
66 | } \
67 | } \
68 | if (seg->size) { \
69 | efree(seg->buffer); \
70 | } \
71 | efree(seg); \
72 | } while (0)
73 | #endif
74 |
75 | extern zend_class_entry *yaf_view_interface_ce;
76 | extern zend_class_entry *yaf_view_simple_ce;
77 |
78 | yaf_view_t * yaf_view_instance(yaf_view_t * this_ptr, zval *tpl_dir, zval *options TSRMLS_DC);
79 | int yaf_view_simple_render(yaf_view_t *view, zval *tpl, zval * vars, zval *ret TSRMLS_DC);
80 | int yaf_view_simple_display(yaf_view_t *view, zval *tpl, zval * vars, zval *ret TSRMLS_DC);
81 | int yaf_view_simple_assign_multi(yaf_view_t *view, zval *value TSRMLS_DC);
82 | void yaf_view_simple_clear_assign(yaf_view_t *view, char *name, uint len TSRMLS_DC);
83 |
84 | YAF_STARTUP_FUNCTION(view);
85 | #endif
86 | /*
87 | * Local variables:
88 | * tab-width: 4
89 | * c-basic-offset: 4
90 | * End:
91 | * vim600: noet sw=4 ts=4 fdm=marker
92 | * vim<600: noet sw=4 ts=4
93 | */
94 |
--------------------------------------------------------------------------------