Showing
47 changed files
with
1813 additions
and
0 deletions
.gitmodules
0 → 100644
compile/README.md
0 → 100644
1 | +存放模板预编译文件 |
compile/m.yohobuy.com/README.md
0 → 100644
1 | +WAP |
compile/www.yohobuy.com/README.md
0 → 100644
1 | +PC |
composer.json
0 → 100644
1 | +{ | ||
2 | + "name": "YOHO!有货", | ||
3 | + "description": "YOHO!有货WEB版本", | ||
4 | + "keywords": [ | ||
5 | + "yohobuy", | ||
6 | + "有货" | ||
7 | + ], | ||
8 | + "homepage": "http://git.dev.yoho.cn/web/yohobuy.git", | ||
9 | + "type": "project", | ||
10 | + "authors": [ | ||
11 | + { | ||
12 | + "name": "fei.hong", | ||
13 | + "email": "fei.hong@yoho.cn", | ||
14 | + "homepage": "www.yoho.cn" | ||
15 | + } | ||
16 | + ], | ||
17 | + "require": { | ||
18 | + "php": ">=5.3.0" | ||
19 | + }, | ||
20 | + "extra": { | ||
21 | + "branch-alias": { | ||
22 | + "dev-master": "master", | ||
23 | + "dev-test": "test", | ||
24 | + "dev-develop": "develop" | ||
25 | + } | ||
26 | + } | ||
27 | +} |
docs/README.md
0 → 100644
1 | +该目录用于存放相关的文档 |
library/Action/AbstractAction.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +/** | ||
4 | + * 所有Controller控制器的基类 | ||
5 | + * | ||
6 | + * @name AbstractAction | ||
7 | + * @package | ||
8 | + * @copyright yoho.inc | ||
9 | + * @version 1.0 (2015-9-15 11:55:25) | ||
10 | + * @author fei.hong <fei.hong@yoho.cn> | ||
11 | + */ | ||
12 | +namespace Action; | ||
13 | + | ||
14 | +use Yaf\Controller_Abstract; | ||
15 | +use Yaf\Dispatcher; | ||
16 | + | ||
17 | +use Hood\Cache; | ||
18 | + | ||
19 | +class AbstractAction extends Controller_Abstract | ||
20 | +{ | ||
21 | + | ||
22 | + /** | ||
23 | + * HTTP请求对象 | ||
24 | + * | ||
25 | + * @var object | ||
26 | + */ | ||
27 | + protected $_request; | ||
28 | + | ||
29 | + /** | ||
30 | + * 初始化 | ||
31 | + */ | ||
32 | + public function init() | ||
33 | + { | ||
34 | + $this->_request = $this->getRequest(); | ||
35 | + } | ||
36 | + | ||
37 | + /** | ||
38 | + * 封装一下获取get参数 | ||
39 | + * | ||
40 | + * @param String $key | ||
41 | + * @param mixed $default | ||
42 | + * @return mixed | ||
43 | + */ | ||
44 | + protected function get($key, $default = null) | ||
45 | + { | ||
46 | + return $this->_request->getQuery($key, $default); | ||
47 | + } | ||
48 | + | ||
49 | + /** | ||
50 | + * 封装一下获取post参数 | ||
51 | + * | ||
52 | + * @param String $key | ||
53 | + * @param mixed $default | ||
54 | + * @return mixed | ||
55 | + */ | ||
56 | + protected function post($key, $default = null) | ||
57 | + { | ||
58 | + return $this->_request->getPost($key, $default); | ||
59 | + } | ||
60 | + | ||
61 | + /** | ||
62 | + * 关闭模板自动渲染 | ||
63 | + * | ||
64 | + * @return void | ||
65 | + */ | ||
66 | + protected function disableView() | ||
67 | + { | ||
68 | + Dispatcher::getInstance()->autoRender(false); | ||
69 | + } | ||
70 | + | ||
71 | + /** | ||
72 | + * 使用Memcache缓存 | ||
73 | + * | ||
74 | + * @param string $node | ||
75 | + * @param string $childNode | ||
76 | + * @return object | ||
77 | + */ | ||
78 | + protected function memcache($node = null, $childNode = 'hosts') | ||
79 | + { | ||
80 | + if (PATH_SEPARATOR === '\\') { | ||
81 | + return Cache::memcache($node, $childNode); | ||
82 | + } else { | ||
83 | + return Cache::memcached($node, $childNode); | ||
84 | + } | ||
85 | + } | ||
86 | + | ||
87 | +} |
library/Action/RootAction.php
0 → 100644
1 | +<?php | ||
2 | +namespace Action; | ||
3 | + | ||
4 | +use Configs\StaticJS; | ||
5 | +use Configs\StaticCss; | ||
6 | +use Hood\Action as HoodAction; | ||
7 | +use Yaf\Registry; | ||
8 | +use Yaf\Dispatcher; | ||
9 | +use Hood\Session; | ||
10 | +use Hood\Cache; | ||
11 | + | ||
12 | +class RootAction extends HoodAction | ||
13 | +{ | ||
14 | + protected $_appConfig = array(); | ||
15 | + | ||
16 | + public function init() | ||
17 | + { | ||
18 | + $this->_appConfig = Registry::get('appConfig'); | ||
19 | + } | ||
20 | + | ||
21 | + | ||
22 | + public function _assign($name, $value) | ||
23 | + { | ||
24 | + return $this->getView()->assign($name, $value); | ||
25 | + } | ||
26 | + | ||
27 | + /** | ||
28 | + * 获取JS URL | ||
29 | + * | ||
30 | + * @param String $jsName | ||
31 | + * @return String | ||
32 | + */ | ||
33 | + public function _js($jsName, $local = false) | ||
34 | + { | ||
35 | + if (isset(StaticJS::$res[$jsName])) { | ||
36 | + $js = $this->_appConfig['website']['static']['url']; | ||
37 | + if ($local == false) { | ||
38 | + $js .= StaticJS::$res[$jsName]; | ||
39 | + } else { | ||
40 | + $js = StaticJS::$res[$jsName]; | ||
41 | + } | ||
42 | + return $js; | ||
43 | + } | ||
44 | + return ''; | ||
45 | + } | ||
46 | + | ||
47 | + /** | ||
48 | + * 获取Css URL | ||
49 | + * | ||
50 | + * @param String $cssName | ||
51 | + * @return String | ||
52 | + */ | ||
53 | + public function _css($cssName, $local = false) | ||
54 | + { | ||
55 | + if (isset(StaticCss::$res[$cssName])) { | ||
56 | + $css = $this->_appConfig['website']['static']['url']; | ||
57 | + if ($local == false) { | ||
58 | + $css .= StaticCss::$res[$cssName]; | ||
59 | + } else { | ||
60 | + $css = StaticCss::$res[$cssName]; | ||
61 | + } | ||
62 | + return $css; | ||
63 | + } | ||
64 | + return ''; | ||
65 | + } | ||
66 | + | ||
67 | + /** | ||
68 | + * 获取JS URL | ||
69 | + * | ||
70 | + * @param String $jsName | ||
71 | + * @return String | ||
72 | + */ | ||
73 | + public function _viewScriptPush(array $jsList, $scriptName = '_footerScript') | ||
74 | + { | ||
75 | + $script = $this->_viewScript($scriptName); | ||
76 | + foreach ($jsList as $js) { | ||
77 | + $script->appendFile($this->_js($js, true)); | ||
78 | + } | ||
79 | + } | ||
80 | + | ||
81 | + /** | ||
82 | + * 获取JS URL | ||
83 | + * | ||
84 | + * @param String $jsName | ||
85 | + * @return String | ||
86 | + */ | ||
87 | + public function _viewCssPush(array $cssList, $linkName = '_headLink') | ||
88 | + { | ||
89 | + $link = $this->_viewLink($linkName); | ||
90 | + foreach ($cssList as $css) { | ||
91 | + $link->appendFile($this->_css($css, true)); | ||
92 | + } | ||
93 | + } | ||
94 | + | ||
95 | + /** | ||
96 | + * 获取参数 | ||
97 | + * @param null $name | ||
98 | + * @param null $default | ||
99 | + * @return mixed | ||
100 | + */ | ||
101 | + protected function _getEnv($name = null, $default = null) | ||
102 | + { | ||
103 | + return $this->getRequest()->getEnv($name, $default); | ||
104 | + } | ||
105 | + | ||
106 | + /** | ||
107 | + * 封装一下获取param参数 | ||
108 | + * @param String $key | ||
109 | + * @param mixed $default | ||
110 | + * @return mixed | ||
111 | + */ | ||
112 | + protected function _getParam($key, $default = null) | ||
113 | + { | ||
114 | + $request = $this->_request->getRequest(); | ||
115 | + $route = $this->getRequest()->getParams(); | ||
116 | + $allParams = array_merge($request, $route); | ||
117 | + return isset($allParams[$key]) ? $allParams[$key] : $default; | ||
118 | + } | ||
119 | + | ||
120 | + /** | ||
121 | + * 获取所有参数 | ||
122 | + * @return array | ||
123 | + */ | ||
124 | + protected function _getParams() | ||
125 | + { | ||
126 | + return $this->_request->getParams(); | ||
127 | + } | ||
128 | + | ||
129 | + /** | ||
130 | + * 获取所有参数 | ||
131 | + * @return mixed | ||
132 | + */ | ||
133 | + protected function _getRequests() | ||
134 | + { | ||
135 | + return $this->_request->getRequest(); | ||
136 | + } | ||
137 | + | ||
138 | + /** | ||
139 | + * 封装一下获取get参数 | ||
140 | + * @param String $key | ||
141 | + * @param mixed $default | ||
142 | + * @return mixed | ||
143 | + */ | ||
144 | + protected function _get($key, $default = null) | ||
145 | + { | ||
146 | + return $this->getRequest()->getQuery($key, $default); | ||
147 | + } | ||
148 | + | ||
149 | + /** | ||
150 | + * 封装一下获取post参数 | ||
151 | + * @param String $key | ||
152 | + * @param mixed $default | ||
153 | + * @return mixed | ||
154 | + */ | ||
155 | + protected function _post($key, $default = null) | ||
156 | + { | ||
157 | + return $this->getRequest()->getPost($key, $default); | ||
158 | + } | ||
159 | + | ||
160 | + /** | ||
161 | + * 封装一下获取post参数 | ||
162 | + * @param String $key | ||
163 | + * @param mixed $default | ||
164 | + * @return mixed | ||
165 | + */ | ||
166 | + protected function _typePost($key, $settype = null, $default = null) | ||
167 | + { | ||
168 | + $result = $this->getRequest()->getPost($key, $default); | ||
169 | + switch ($settype) { | ||
170 | + case 'bool': | ||
171 | + $result = (bool)$result; | ||
172 | + break; | ||
173 | + case 'int': | ||
174 | + $result = (int)$result; | ||
175 | + break; | ||
176 | + case 'string': | ||
177 | + $result = (string)$result; | ||
178 | + break; | ||
179 | + case 'float': | ||
180 | + $result = (float)$result; | ||
181 | + break; | ||
182 | + case 'binary': | ||
183 | + $result = (binary)$result; | ||
184 | + break; | ||
185 | + default: | ||
186 | + $result = $result; | ||
187 | + break; | ||
188 | + } | ||
189 | + return $result; | ||
190 | + } | ||
191 | + | ||
192 | + /** | ||
193 | + * 关闭模板 & Layout | ||
194 | + */ | ||
195 | + public function _disable() | ||
196 | + { | ||
197 | + $this->disableLayout(); | ||
198 | + $this->disableView(); | ||
199 | + } | ||
200 | + | ||
201 | + /** | ||
202 | + * 关闭模板 | ||
203 | + */ | ||
204 | + public function disableView() | ||
205 | + { | ||
206 | + Dispatcher::getInstance()->autoRender(FALSE); | ||
207 | + } | ||
208 | + | ||
209 | + /** | ||
210 | + * 关闭Layout | ||
211 | + */ | ||
212 | + public function disableLayout() | ||
213 | + { | ||
214 | + $this->getView()->setLayout(''); | ||
215 | + } | ||
216 | + | ||
217 | + /** | ||
218 | + * @param string $namespace | ||
219 | + * @return \Hood\Core\Session\SessionNamespace | ||
220 | + */ | ||
221 | + public function _session($namespace = 'session_default') | ||
222 | + { | ||
223 | + if (isset($this->_appConfig['website']['session']) && $this->_appConfig['website']['session'] == 'file') { | ||
224 | + return Session::fileStart($namespace); | ||
225 | + } else { | ||
226 | + return Session::start($namespace); | ||
227 | + } | ||
228 | + } | ||
229 | + | ||
230 | + public function _mc($node = null, $childNode = 'hosts'){ | ||
231 | + return Cache::memcached($node, $childNode); | ||
232 | + } | ||
233 | +} |
library/LibModels/Concurrent.php
0 → 100644
1 | +<?php | ||
2 | +/** | ||
3 | + * User: haisheng.shen@yoho.cn | ||
4 | + * Date: 15-2-9 下午2:08 | ||
5 | + */ | ||
6 | + | ||
7 | +namespace LibModels; | ||
8 | + | ||
9 | + | ||
10 | +class Concurrent | ||
11 | +{ | ||
12 | + | ||
13 | + | ||
14 | + /** | ||
15 | + * 添加并行的请求 | ||
16 | + * @param $url | ||
17 | + * @param $method | ||
18 | + * @param callable $callback | ||
19 | + * @param null $errorCallback | ||
20 | + */ | ||
21 | + public static function call($url, $method, array $parameters = array(), callable $callback = null, callable $errorCallback=null) | ||
22 | + { | ||
23 | + \Yar_Concurrent_Client::call($url, $method, $parameters, $callback, $errorCallback); | ||
24 | + } | ||
25 | + | ||
26 | + | ||
27 | + /** | ||
28 | + * 发起请求 | ||
29 | + * @param null $callback | ||
30 | + * @param null $errorCallback | ||
31 | + */ | ||
32 | + public static function loop(callable $callback=null, callable $errorCallback=null) | ||
33 | + { | ||
34 | + \Yar_Concurrent_Client::loop($callback, $errorCallback); | ||
35 | + } | ||
36 | + | ||
37 | + | ||
38 | + /** | ||
39 | + * 非并行yar实例的数组 | ||
40 | + * @var array | ||
41 | + */ | ||
42 | + protected static $yarInstance = array(); | ||
43 | + | ||
44 | + /** | ||
45 | + * 非并行yar的实例 | ||
46 | + * @param $url | ||
47 | + * @return mixed | ||
48 | + */ | ||
49 | + public static function single($url, $method, array $parameters =array(), callable $callback=null, callable $errorCallback = null) | ||
50 | + { | ||
51 | + $key = md5($url); | ||
52 | + if (!isset(self::$yarInstance[$key])) { | ||
53 | + self::$yarInstance[$key] = new \Yar_Client($url); | ||
54 | + } | ||
55 | + try { | ||
56 | + $result = call_user_func_array(array(self::$yarInstance[$key], $method), $parameters); | ||
57 | + $callback($result); | ||
58 | + } catch (\Yar_Server_Exception $e) { | ||
59 | + if (!empty($errorCallback)) { | ||
60 | + $errorCallback($e); | ||
61 | + } | ||
62 | + } | ||
63 | + } | ||
64 | + | ||
65 | + | ||
66 | + /** | ||
67 | + * 根据参数来选择并行或者非并行 | ||
68 | + * @param $url | ||
69 | + * @param $method | ||
70 | + * @param array $params | ||
71 | + * @param callable $callback | ||
72 | + * @param callable $errorCallback | ||
73 | + * @param bool $concurrent | ||
74 | + */ | ||
75 | + public static function choise($url, $method, array $params=array(), callable $callback=null, callable $errorCallback = null, $concurrent=true) | ||
76 | + { | ||
77 | + if ($concurrent) { | ||
78 | + self::call($url, $method, $params, $callback, $errorCallback); | ||
79 | + } else { | ||
80 | + self::single($url, $method, $params, $callback, $errorCallback); | ||
81 | + } | ||
82 | + } | ||
83 | +} |
library/LibModels/ModelsConcurrent.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +/** | ||
4 | + * Created by PhpStorm. | ||
5 | + * User: Zip | ||
6 | + * Date: 14/11/27 | ||
7 | + * Time: 下午1:10 | ||
8 | + */ | ||
9 | +namespace LibModels; | ||
10 | + | ||
11 | +use Hood\Concurrent as hoodConcurrent; | ||
12 | + | ||
13 | +class ModelsConcurrent | ||
14 | +{ | ||
15 | + static protected $uri = 'http://service.example.yohobuy.com/service/product/v1'; | ||
16 | + | ||
17 | + /** | ||
18 | + * @var Concurrent|Concurrent\Yar\Concurrent | ||
19 | + */ | ||
20 | + static private $concurrent; | ||
21 | + | ||
22 | + | ||
23 | + /** | ||
24 | + * @return Concurrent|Concurrent\Yar\Concurrent | ||
25 | + */ | ||
26 | + static protected function connect() | ||
27 | + { | ||
28 | + if (empty(self::$concurrent)) { | ||
29 | + self::$concurrent = hoodConcurrent::yarConcurrent(self::$uri); | ||
30 | + } | ||
31 | + return self::$concurrent; | ||
32 | + } | ||
33 | + | ||
34 | + static public function loop() | ||
35 | + { | ||
36 | + self::connect()->loop('Models\ModelsConcurrent::callback', 'Models\ModelsConcurrent::errorCallback'); | ||
37 | + } | ||
38 | + | ||
39 | + static public function errorCallback($type, $error, $callinfo) | ||
40 | + { | ||
41 | + print_r($error); | ||
42 | + } | ||
43 | + | ||
44 | + static public function callback($ret, $callinfo) | ||
45 | + { | ||
46 | + | ||
47 | + } | ||
48 | +} |
library/Package/composer.json
0 → 100644
1 | +{ | ||
2 | + "name": "依赖包管理", | ||
3 | + "description": "有货项目依赖第三方的包管理", | ||
4 | + "keywords": [ | ||
5 | + "yohobuy", | ||
6 | + "package" | ||
7 | + ], | ||
8 | + "homepage": "", | ||
9 | + "type": "library", | ||
10 | + "repositories": [ | ||
11 | + { | ||
12 | + "packagist": false | ||
13 | + } | ||
14 | + ], | ||
15 | + "authors": [ | ||
16 | + { | ||
17 | + "name": "hf", | ||
18 | + "email": "fei.hong@yoho.cn", | ||
19 | + "homepage": "www.yoho.cn" | ||
20 | + } | ||
21 | + ], | ||
22 | + "require": { | ||
23 | + "php": ">=5.3.0" | ||
24 | + } | ||
25 | +} |
library/Package/vendor/autoload.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +/* | ||
4 | + * This file is part of Composer. | ||
5 | + * | ||
6 | + * (c) Nils Adermann <naderman@naderman.de> | ||
7 | + * Jordi Boggiano <j.boggiano@seld.be> | ||
8 | + * | ||
9 | + * For the full copyright and license information, please view the LICENSE | ||
10 | + * file that was distributed with this source code. | ||
11 | + */ | ||
12 | + | ||
13 | +namespace Composer\Autoload; | ||
14 | + | ||
15 | +/** | ||
16 | + * ClassLoader implements a PSR-0 class loader | ||
17 | + * | ||
18 | + * See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md | ||
19 | + * | ||
20 | + * $loader = new \Composer\Autoload\ClassLoader(); | ||
21 | + * | ||
22 | + * // register classes with namespaces | ||
23 | + * $loader->add('Symfony\Component', __DIR__.'/component'); | ||
24 | + * $loader->add('Symfony', __DIR__.'/framework'); | ||
25 | + * | ||
26 | + * // activate the autoloader | ||
27 | + * $loader->register(); | ||
28 | + * | ||
29 | + * // to enable searching the include path (eg. for PEAR packages) | ||
30 | + * $loader->setUseIncludePath(true); | ||
31 | + * | ||
32 | + * In this example, if you try to use a class in the Symfony\Component | ||
33 | + * namespace or one of its children (Symfony\Component\Console for instance), | ||
34 | + * the autoloader will first look for the class under the component/ | ||
35 | + * directory, and it will then fallback to the framework/ directory if not | ||
36 | + * found before giving up. | ||
37 | + * | ||
38 | + * This class is loosely based on the Symfony UniversalClassLoader. | ||
39 | + * | ||
40 | + * @author Fabien Potencier <fabien@symfony.com> | ||
41 | + * @author Jordi Boggiano <j.boggiano@seld.be> | ||
42 | + */ | ||
43 | +class ClassLoader | ||
44 | +{ | ||
45 | + // PSR-4 | ||
46 | + private $prefixLengthsPsr4 = array(); | ||
47 | + private $prefixDirsPsr4 = array(); | ||
48 | + private $fallbackDirsPsr4 = array(); | ||
49 | + | ||
50 | + // PSR-0 | ||
51 | + private $prefixesPsr0 = array(); | ||
52 | + private $fallbackDirsPsr0 = array(); | ||
53 | + | ||
54 | + private $useIncludePath = false; | ||
55 | + private $classMap = array(); | ||
56 | + | ||
57 | + private $classMapAuthoritative = false; | ||
58 | + | ||
59 | + public function getPrefixes() | ||
60 | + { | ||
61 | + if (!empty($this->prefixesPsr0)) { | ||
62 | + return call_user_func_array('array_merge', $this->prefixesPsr0); | ||
63 | + } | ||
64 | + | ||
65 | + return array(); | ||
66 | + } | ||
67 | + | ||
68 | + public function getPrefixesPsr4() | ||
69 | + { | ||
70 | + return $this->prefixDirsPsr4; | ||
71 | + } | ||
72 | + | ||
73 | + public function getFallbackDirs() | ||
74 | + { | ||
75 | + return $this->fallbackDirsPsr0; | ||
76 | + } | ||
77 | + | ||
78 | + public function getFallbackDirsPsr4() | ||
79 | + { | ||
80 | + return $this->fallbackDirsPsr4; | ||
81 | + } | ||
82 | + | ||
83 | + public function getClassMap() | ||
84 | + { | ||
85 | + return $this->classMap; | ||
86 | + } | ||
87 | + | ||
88 | + /** | ||
89 | + * @param array $classMap Class to filename map | ||
90 | + */ | ||
91 | + public function addClassMap(array $classMap) | ||
92 | + { | ||
93 | + if ($this->classMap) { | ||
94 | + $this->classMap = array_merge($this->classMap, $classMap); | ||
95 | + } else { | ||
96 | + $this->classMap = $classMap; | ||
97 | + } | ||
98 | + } | ||
99 | + | ||
100 | + /** | ||
101 | + * Registers a set of PSR-0 directories for a given prefix, either | ||
102 | + * appending or prepending to the ones previously set for this prefix. | ||
103 | + * | ||
104 | + * @param string $prefix The prefix | ||
105 | + * @param array|string $paths The PSR-0 root directories | ||
106 | + * @param bool $prepend Whether to prepend the directories | ||
107 | + */ | ||
108 | + public function add($prefix, $paths, $prepend = false) | ||
109 | + { | ||
110 | + if (!$prefix) { | ||
111 | + if ($prepend) { | ||
112 | + $this->fallbackDirsPsr0 = array_merge( | ||
113 | + (array) $paths, | ||
114 | + $this->fallbackDirsPsr0 | ||
115 | + ); | ||
116 | + } else { | ||
117 | + $this->fallbackDirsPsr0 = array_merge( | ||
118 | + $this->fallbackDirsPsr0, | ||
119 | + (array) $paths | ||
120 | + ); | ||
121 | + } | ||
122 | + | ||
123 | + return; | ||
124 | + } | ||
125 | + | ||
126 | + $first = $prefix[0]; | ||
127 | + if (!isset($this->prefixesPsr0[$first][$prefix])) { | ||
128 | + $this->prefixesPsr0[$first][$prefix] = (array) $paths; | ||
129 | + | ||
130 | + return; | ||
131 | + } | ||
132 | + if ($prepend) { | ||
133 | + $this->prefixesPsr0[$first][$prefix] = array_merge( | ||
134 | + (array) $paths, | ||
135 | + $this->prefixesPsr0[$first][$prefix] | ||
136 | + ); | ||
137 | + } else { | ||
138 | + $this->prefixesPsr0[$first][$prefix] = array_merge( | ||
139 | + $this->prefixesPsr0[$first][$prefix], | ||
140 | + (array) $paths | ||
141 | + ); | ||
142 | + } | ||
143 | + } | ||
144 | + | ||
145 | + /** | ||
146 | + * Registers a set of PSR-4 directories for a given namespace, either | ||
147 | + * appending or prepending to the ones previously set for this namespace. | ||
148 | + * | ||
149 | + * @param string $prefix The prefix/namespace, with trailing '\\' | ||
150 | + * @param array|string $paths The PSR-0 base directories | ||
151 | + * @param bool $prepend Whether to prepend the directories | ||
152 | + * | ||
153 | + * @throws \InvalidArgumentException | ||
154 | + */ | ||
155 | + public function addPsr4($prefix, $paths, $prepend = false) | ||
156 | + { | ||
157 | + if (!$prefix) { | ||
158 | + // Register directories for the root namespace. | ||
159 | + if ($prepend) { | ||
160 | + $this->fallbackDirsPsr4 = array_merge( | ||
161 | + (array) $paths, | ||
162 | + $this->fallbackDirsPsr4 | ||
163 | + ); | ||
164 | + } else { | ||
165 | + $this->fallbackDirsPsr4 = array_merge( | ||
166 | + $this->fallbackDirsPsr4, | ||
167 | + (array) $paths | ||
168 | + ); | ||
169 | + } | ||
170 | + } elseif (!isset($this->prefixDirsPsr4[$prefix])) { | ||
171 | + // Register directories for a new namespace. | ||
172 | + $length = strlen($prefix); | ||
173 | + if ('\\' !== $prefix[$length - 1]) { | ||
174 | + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); | ||
175 | + } | ||
176 | + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; | ||
177 | + $this->prefixDirsPsr4[$prefix] = (array) $paths; | ||
178 | + } elseif ($prepend) { | ||
179 | + // Prepend directories for an already registered namespace. | ||
180 | + $this->prefixDirsPsr4[$prefix] = array_merge( | ||
181 | + (array) $paths, | ||
182 | + $this->prefixDirsPsr4[$prefix] | ||
183 | + ); | ||
184 | + } else { | ||
185 | + // Append directories for an already registered namespace. | ||
186 | + $this->prefixDirsPsr4[$prefix] = array_merge( | ||
187 | + $this->prefixDirsPsr4[$prefix], | ||
188 | + (array) $paths | ||
189 | + ); | ||
190 | + } | ||
191 | + } | ||
192 | + | ||
193 | + /** | ||
194 | + * Registers a set of PSR-0 directories for a given prefix, | ||
195 | + * replacing any others previously set for this prefix. | ||
196 | + * | ||
197 | + * @param string $prefix The prefix | ||
198 | + * @param array|string $paths The PSR-0 base directories | ||
199 | + */ | ||
200 | + public function set($prefix, $paths) | ||
201 | + { | ||
202 | + if (!$prefix) { | ||
203 | + $this->fallbackDirsPsr0 = (array) $paths; | ||
204 | + } else { | ||
205 | + $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; | ||
206 | + } | ||
207 | + } | ||
208 | + | ||
209 | + /** | ||
210 | + * Registers a set of PSR-4 directories for a given namespace, | ||
211 | + * replacing any others previously set for this namespace. | ||
212 | + * | ||
213 | + * @param string $prefix The prefix/namespace, with trailing '\\' | ||
214 | + * @param array|string $paths The PSR-4 base directories | ||
215 | + * | ||
216 | + * @throws \InvalidArgumentException | ||
217 | + */ | ||
218 | + public function setPsr4($prefix, $paths) | ||
219 | + { | ||
220 | + if (!$prefix) { | ||
221 | + $this->fallbackDirsPsr4 = (array) $paths; | ||
222 | + } else { | ||
223 | + $length = strlen($prefix); | ||
224 | + if ('\\' !== $prefix[$length - 1]) { | ||
225 | + throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); | ||
226 | + } | ||
227 | + $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length; | ||
228 | + $this->prefixDirsPsr4[$prefix] = (array) $paths; | ||
229 | + } | ||
230 | + } | ||
231 | + | ||
232 | + /** | ||
233 | + * Turns on searching the include path for class files. | ||
234 | + * | ||
235 | + * @param bool $useIncludePath | ||
236 | + */ | ||
237 | + public function setUseIncludePath($useIncludePath) | ||
238 | + { | ||
239 | + $this->useIncludePath = $useIncludePath; | ||
240 | + } | ||
241 | + | ||
242 | + /** | ||
243 | + * Can be used to check if the autoloader uses the include path to check | ||
244 | + * for classes. | ||
245 | + * | ||
246 | + * @return bool | ||
247 | + */ | ||
248 | + public function getUseIncludePath() | ||
249 | + { | ||
250 | + return $this->useIncludePath; | ||
251 | + } | ||
252 | + | ||
253 | + /** | ||
254 | + * Turns off searching the prefix and fallback directories for classes | ||
255 | + * that have not been registered with the class map. | ||
256 | + * | ||
257 | + * @param bool $classMapAuthoritative | ||
258 | + */ | ||
259 | + public function setClassMapAuthoritative($classMapAuthoritative) | ||
260 | + { | ||
261 | + $this->classMapAuthoritative = $classMapAuthoritative; | ||
262 | + } | ||
263 | + | ||
264 | + /** | ||
265 | + * Should class lookup fail if not found in the current class map? | ||
266 | + * | ||
267 | + * @return bool | ||
268 | + */ | ||
269 | + public function isClassMapAuthoritative() | ||
270 | + { | ||
271 | + return $this->classMapAuthoritative; | ||
272 | + } | ||
273 | + | ||
274 | + /** | ||
275 | + * Registers this instance as an autoloader. | ||
276 | + * | ||
277 | + * @param bool $prepend Whether to prepend the autoloader or not | ||
278 | + */ | ||
279 | + public function register($prepend = false) | ||
280 | + { | ||
281 | + spl_autoload_register(array($this, 'loadClass'), true, $prepend); | ||
282 | + } | ||
283 | + | ||
284 | + /** | ||
285 | + * Unregisters this instance as an autoloader. | ||
286 | + */ | ||
287 | + public function unregister() | ||
288 | + { | ||
289 | + spl_autoload_unregister(array($this, 'loadClass')); | ||
290 | + } | ||
291 | + | ||
292 | + /** | ||
293 | + * Loads the given class or interface. | ||
294 | + * | ||
295 | + * @param string $class The name of the class | ||
296 | + * @return bool|null True if loaded, null otherwise | ||
297 | + */ | ||
298 | + public function loadClass($class) | ||
299 | + { | ||
300 | + if ($file = $this->findFile($class)) { | ||
301 | + includeFile($file); | ||
302 | + | ||
303 | + return true; | ||
304 | + } | ||
305 | + } | ||
306 | + | ||
307 | + /** | ||
308 | + * Finds the path to the file where the class is defined. | ||
309 | + * | ||
310 | + * @param string $class The name of the class | ||
311 | + * | ||
312 | + * @return string|false The path if found, false otherwise | ||
313 | + */ | ||
314 | + public function findFile($class) | ||
315 | + { | ||
316 | + // work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731 | ||
317 | + if ('\\' == $class[0]) { | ||
318 | + $class = substr($class, 1); | ||
319 | + } | ||
320 | + | ||
321 | + // class map lookup | ||
322 | + if (isset($this->classMap[$class])) { | ||
323 | + return $this->classMap[$class]; | ||
324 | + } | ||
325 | + if ($this->classMapAuthoritative) { | ||
326 | + return false; | ||
327 | + } | ||
328 | + | ||
329 | + $file = $this->findFileWithExtension($class, '.php'); | ||
330 | + | ||
331 | + // Search for Hack files if we are running on HHVM | ||
332 | + if ($file === null && defined('HHVM_VERSION')) { | ||
333 | + $file = $this->findFileWithExtension($class, '.hh'); | ||
334 | + } | ||
335 | + | ||
336 | + if ($file === null) { | ||
337 | + // Remember that this class does not exist. | ||
338 | + return $this->classMap[$class] = false; | ||
339 | + } | ||
340 | + | ||
341 | + return $file; | ||
342 | + } | ||
343 | + | ||
344 | + private function findFileWithExtension($class, $ext) | ||
345 | + { | ||
346 | + // PSR-4 lookup | ||
347 | + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; | ||
348 | + | ||
349 | + $first = $class[0]; | ||
350 | + if (isset($this->prefixLengthsPsr4[$first])) { | ||
351 | + foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) { | ||
352 | + if (0 === strpos($class, $prefix)) { | ||
353 | + foreach ($this->prefixDirsPsr4[$prefix] as $dir) { | ||
354 | + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) { | ||
355 | + return $file; | ||
356 | + } | ||
357 | + } | ||
358 | + } | ||
359 | + } | ||
360 | + } | ||
361 | + | ||
362 | + // PSR-4 fallback dirs | ||
363 | + foreach ($this->fallbackDirsPsr4 as $dir) { | ||
364 | + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { | ||
365 | + return $file; | ||
366 | + } | ||
367 | + } | ||
368 | + | ||
369 | + // PSR-0 lookup | ||
370 | + if (false !== $pos = strrpos($class, '\\')) { | ||
371 | + // namespaced class name | ||
372 | + $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1) | ||
373 | + . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); | ||
374 | + } else { | ||
375 | + // PEAR-like class name | ||
376 | + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; | ||
377 | + } | ||
378 | + | ||
379 | + if (isset($this->prefixesPsr0[$first])) { | ||
380 | + foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { | ||
381 | + if (0 === strpos($class, $prefix)) { | ||
382 | + foreach ($dirs as $dir) { | ||
383 | + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { | ||
384 | + return $file; | ||
385 | + } | ||
386 | + } | ||
387 | + } | ||
388 | + } | ||
389 | + } | ||
390 | + | ||
391 | + // PSR-0 fallback dirs | ||
392 | + foreach ($this->fallbackDirsPsr0 as $dir) { | ||
393 | + if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { | ||
394 | + return $file; | ||
395 | + } | ||
396 | + } | ||
397 | + | ||
398 | + // PSR-0 include paths. | ||
399 | + if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) { | ||
400 | + return $file; | ||
401 | + } | ||
402 | + } | ||
403 | +} | ||
404 | + | ||
405 | +/** | ||
406 | + * Scope isolated include. | ||
407 | + * | ||
408 | + * Prevents access to $this/self from included files. | ||
409 | + */ | ||
410 | +function includeFile($file) | ||
411 | +{ | ||
412 | + include $file; | ||
413 | +} |
1 | +<?php | ||
2 | + | ||
3 | +// autoload_real.php @generated by Composer | ||
4 | + | ||
5 | +class ComposerAutoloaderInit3f4063230841d94400077da033fc02ab | ||
6 | +{ | ||
7 | + private static $loader; | ||
8 | + | ||
9 | + public static function loadClassLoader($class) | ||
10 | + { | ||
11 | + if ('Composer\Autoload\ClassLoader' === $class) { | ||
12 | + require __DIR__ . '/ClassLoader.php'; | ||
13 | + } | ||
14 | + } | ||
15 | + | ||
16 | + public static function getLoader() | ||
17 | + { | ||
18 | + if (null !== self::$loader) { | ||
19 | + return self::$loader; | ||
20 | + } | ||
21 | + | ||
22 | + spl_autoload_register(array('ComposerAutoloaderInit3f4063230841d94400077da033fc02ab', 'loadClassLoader'), true, true); | ||
23 | + self::$loader = $loader = new \Composer\Autoload\ClassLoader(); | ||
24 | + spl_autoload_unregister(array('ComposerAutoloaderInit3f4063230841d94400077da033fc02ab', 'loadClassLoader')); | ||
25 | + | ||
26 | + $map = require __DIR__ . '/autoload_namespaces.php'; | ||
27 | + foreach ($map as $namespace => $path) { | ||
28 | + $loader->set($namespace, $path); | ||
29 | + } | ||
30 | + | ||
31 | + $map = require __DIR__ . '/autoload_psr4.php'; | ||
32 | + foreach ($map as $namespace => $path) { | ||
33 | + $loader->setPsr4($namespace, $path); | ||
34 | + } | ||
35 | + | ||
36 | + $classMap = require __DIR__ . '/autoload_classmap.php'; | ||
37 | + if ($classMap) { | ||
38 | + $loader->addClassMap($classMap); | ||
39 | + } | ||
40 | + | ||
41 | + $loader->register(true); | ||
42 | + | ||
43 | + return $loader; | ||
44 | + } | ||
45 | +} | ||
46 | + | ||
47 | +function composerRequire3f4063230841d94400077da033fc02ab($file) | ||
48 | +{ | ||
49 | + require $file; | ||
50 | +} |
library/Plugin/Layout.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +/** | ||
4 | + * Created by PhpStorm. | ||
5 | + * User: liuziyang | ||
6 | + * Date: 14-1-12 | ||
7 | + * Time: 16:32 | ||
8 | + */ | ||
9 | +namespace Plugin; | ||
10 | +use Yaf\View_Interface; | ||
11 | +use Yaf\View; | ||
12 | +use Yaf\Application; | ||
13 | +class Layout implements View_Interface | ||
14 | +{ | ||
15 | + public $breadcrumb = array(); | ||
16 | + | ||
17 | + public $engine; | ||
18 | + | ||
19 | + protected $options = array(); | ||
20 | + | ||
21 | + protected $layout_path; | ||
22 | + | ||
23 | + protected $layout; | ||
24 | + | ||
25 | + protected $content; | ||
26 | + | ||
27 | + protected $tpl_vars = array(); | ||
28 | + | ||
29 | + protected $tpl_dir; | ||
30 | + | ||
31 | + public function __construct($path, $options = array()) | ||
32 | + { | ||
33 | + $this->layout_path = $path; | ||
34 | + $this->options = $options; | ||
35 | + } | ||
36 | + | ||
37 | + protected function engine() | ||
38 | + { | ||
39 | + $this->engine = $this->engine ?: new View\Simple( | ||
40 | + $this->tpl_dir, | ||
41 | + $this->options | ||
42 | + ); | ||
43 | + return $this->engine; | ||
44 | + } | ||
45 | + | ||
46 | + public function setScriptPath($path) | ||
47 | + { | ||
48 | + if (is_readable($path)) { | ||
49 | + $this->tpl_dir = $path; | ||
50 | + $this->engine()->setScriptPath($path); | ||
51 | + $this->layout_path = $path . "/../layouts"; | ||
52 | + return true; | ||
53 | + } | ||
54 | + throw new Exception("Invalid path: {$path}"); | ||
55 | + } | ||
56 | + | ||
57 | + public function getScriptPath() | ||
58 | + { | ||
59 | + return $this->engine()->getScriptPath(); | ||
60 | + } | ||
61 | + | ||
62 | + public function setLayout($name) | ||
63 | + { | ||
64 | + $this->layout = $name; | ||
65 | + } | ||
66 | + | ||
67 | + public function getLayout() | ||
68 | + { | ||
69 | + return $this->layout; | ||
70 | + } | ||
71 | + | ||
72 | + public function setLayoutPath($path) | ||
73 | + { | ||
74 | + $this->layout_path = $path; | ||
75 | + return $this; | ||
76 | + } | ||
77 | + | ||
78 | + public function getLayoutPath() | ||
79 | + { | ||
80 | + $config = Application::app()->getConfig()->get('application'); | ||
81 | + return $this->layout_path . "/" . $this->layout . ".{$config->view->ext}"; | ||
82 | + } | ||
83 | + | ||
84 | + public function __set($name, $value) | ||
85 | + { | ||
86 | + $this->assign($name, $value); | ||
87 | + } | ||
88 | + | ||
89 | + public function __isset($name) | ||
90 | + { | ||
91 | + return (null !== $this->engine()->$name); | ||
92 | + } | ||
93 | + | ||
94 | + public function __unset($name) | ||
95 | + { | ||
96 | + $this->engine()->clear($name); | ||
97 | + } | ||
98 | + | ||
99 | + public function assign($name, $value = null) | ||
100 | + { | ||
101 | + $this->tpl_vars[$name] = $value; | ||
102 | + $this->engine()->assign($name, $value); | ||
103 | + } | ||
104 | + | ||
105 | + public function assignRef($name, &$value) | ||
106 | + { | ||
107 | + $this->tpl_vars[$name] = $value; | ||
108 | + $this->engine()->assignRef($name, $value); | ||
109 | + } | ||
110 | + | ||
111 | + public function clearVars($name) | ||
112 | + { | ||
113 | + $this->tpl_vars = array(); | ||
114 | + $this->engine()->clear($name); | ||
115 | + } | ||
116 | + | ||
117 | + public function render($tpl, $tpl_vars = array()) | ||
118 | + { | ||
119 | + $tpl_vars = array_merge($this->tpl_vars, $tpl_vars); | ||
120 | + $this->content = $this->engine()->render($tpl, $tpl_vars); | ||
121 | + if (null == $this->layout) { | ||
122 | + return $this->content; | ||
123 | + } | ||
124 | + $ref = new \ReflectionClass($this->engine()); | ||
125 | + $prop = $ref->getProperty('_tpl_vars'); | ||
126 | + $prop->setAccessible(true); | ||
127 | + $view_vars = $prop->getValue($this->engine()); | ||
128 | + $tpl_vars = array_merge($tpl_vars, $view_vars); | ||
129 | + $tpl_vars['content'] = $this->content; | ||
130 | + $this->engine()->assign('breadcrumb', $this->breadcrumb); | ||
131 | + return $this->engine()->render( | ||
132 | + $this->getLayoutPath(), | ||
133 | + $tpl_vars | ||
134 | + ); | ||
135 | + } | ||
136 | + | ||
137 | + public function display($tpl, $tpl_vars = array()) | ||
138 | + { | ||
139 | + echo $this->render($tpl, $tpl_vars); | ||
140 | + } | ||
141 | +} |
library/Plugin/LightnCandy.php
0 → 100644
This diff could not be displayed because it is too large.
library/Plugin/Routes.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +/** | ||
4 | + * Created by PhpStorm. | ||
5 | + * User: liuziyang | ||
6 | + * Date: 14-1-15 | ||
7 | + * Time: 16:13 | ||
8 | + */ | ||
9 | +namespace Plugin; | ||
10 | + | ||
11 | +use Yaf\Plugin_abstract; | ||
12 | +use Yaf\Request_Abstract; | ||
13 | +use Yaf\Response_Abstract; | ||
14 | +use Yaf\Registry; | ||
15 | +use Yaf\Dispatcher; | ||
16 | +use Yaf\Loader; | ||
17 | +class Routes extends Plugin_abstract | ||
18 | +{ | ||
19 | + /** | ||
20 | + * | ||
21 | + * | ||
22 | + * 在路由之前触发,这个是7个事件中, 最早的一个. 但是一些全局自定的工作, 还是应该放在Bootstrap中去完成 | ||
23 | + * @param Request_Abstract $request | ||
24 | + * @param Response_Abstract $response | ||
25 | + * @return bool|void | ||
26 | + */ | ||
27 | + public function routerStartup(Request_Abstract $request, Response_Abstract $response) | ||
28 | + { | ||
29 | + $_httpResult = explode('.', $request->getServer('HTTP_HOST')); | ||
30 | + $level = 'm'; | ||
31 | + if (count($_httpResult) == 3) { | ||
32 | + list ($level, $domainName, $suffix) = $_httpResult; | ||
33 | + } else if (count($_httpResult) == 4) { | ||
34 | + $level = $_httpResult[0] . '.' . $_httpResult[1]; | ||
35 | + } | ||
36 | + $_config = Registry::get('appConfig'); | ||
37 | + $_modulesList = array(); | ||
38 | + if (!empty($_config['application']['modules'])) { | ||
39 | + $_modules = $_config['application']['modules']; | ||
40 | + $_modulesList = explode(',', $_modules); | ||
41 | + } | ||
42 | + | ||
43 | + $newDomain = array( | ||
44 | + 'guang.m'=>'guang' | ||
45 | + ); | ||
46 | + if (isset($newDomain[strtolower($level)]) ) { | ||
47 | + $level = $newDomain[$level]; | ||
48 | + $request->module = ucfirst(strtolower($level)); | ||
49 | + | ||
50 | + } else if ($level != 'www' && in_array(ucfirst($level), $_modulesList, true)) { | ||
51 | + $request->module = ucfirst($level); | ||
52 | + } else { | ||
53 | + $request->module = 'Default'; | ||
54 | + $level = 'Default'; | ||
55 | + } | ||
56 | + $dispatcher = Dispatcher::getInstance(); | ||
57 | + $app = $dispatcher->getApplication(); | ||
58 | + $file = $app->getAppDirectory() . "/modules/" . ucfirst($level) . "/__init.php"; | ||
59 | + if (file_exists($file)) { | ||
60 | + Loader::import($file); | ||
61 | + } | ||
62 | + } | ||
63 | + | ||
64 | + /** | ||
65 | + * | ||
66 | + * | ||
67 | + * 路由结束之后触发,此时路由一定正确完成, 否则这个事件不会触发 | ||
68 | + * @param Request_Abstract $request | ||
69 | + * @param Response_Abstract $response | ||
70 | + * @return bool|void | ||
71 | + */ | ||
72 | + public function routerShutdown(Request_Abstract $request, Response_Abstract $response) | ||
73 | + { | ||
74 | + | ||
75 | + } | ||
76 | + | ||
77 | + /** | ||
78 | + * | ||
79 | + * | ||
80 | + * 分发循环开始之前被触发 | ||
81 | + * @param Request_Abstract $request | ||
82 | + * @param Response_Abstract $response | ||
83 | + * @return bool|void | ||
84 | + */ | ||
85 | + public function dispatchLoopStartup(Request_Abstract $request, Response_Abstract $response) | ||
86 | + { | ||
87 | + | ||
88 | + } | ||
89 | + | ||
90 | + /** | ||
91 | + * | ||
92 | + * | ||
93 | + * 分发之前触发 如果在一个请求处理过程中, 发生了forward, 则这个事件会被触发多次 | ||
94 | + * @param Request_Abstract $request | ||
95 | + * @param Response_Abstract $response | ||
96 | + * @return bool|void | ||
97 | + */ | ||
98 | + public function preDispatch(Request_Abstract $request, Response_Abstract $response) | ||
99 | + { | ||
100 | + | ||
101 | + } | ||
102 | + | ||
103 | + /** | ||
104 | + * | ||
105 | + * | ||
106 | + * 分发结束之后触发,此时动作已经执行结束, 视图也已经渲染完成. 和preDispatch类似, 此事件也可能触发多次 | ||
107 | + * @param Request_Abstract $request | ||
108 | + * @param Response_Abstract $response | ||
109 | + * @return bool|void | ||
110 | + */ | ||
111 | + public function postDispatch(Request_Abstract $request, Response_Abstract $response) | ||
112 | + { | ||
113 | + | ||
114 | + } | ||
115 | + | ||
116 | + /** | ||
117 | + * | ||
118 | + * | ||
119 | + * 分发循环结束之后触发,此时表示所有的业务逻辑都已经运行完成, 但是响应还没有发送 | ||
120 | + * @param Request_Abstract $request | ||
121 | + * @param Response_Abstract $response | ||
122 | + * @return bool|void | ||
123 | + */ | ||
124 | + public function dispatchLoopShutdown(Request_Abstract $request, Response_Abstract $response) | ||
125 | + { | ||
126 | + | ||
127 | + } | ||
128 | + | ||
129 | + /** | ||
130 | + * @param Request_Abstract $request | ||
131 | + * @param Response_Abstract $response | ||
132 | + * @return bool|void | ||
133 | + */ | ||
134 | + public function preResponse(Request_Abstract $request, Response_Abstract $response) | ||
135 | + { | ||
136 | + | ||
137 | + } | ||
138 | +} |
library/Plugin/TemplateLayout.php
0 → 100644
1 | +<?php | ||
2 | + | ||
3 | +/** | ||
4 | + * 模板视图 | ||
5 | + * | ||
6 | + * @name TemplateLayout | ||
7 | + * @package library/Plugin | ||
8 | + * @copyright yoho.inc | ||
9 | + * @version 1.0 (2015-9-15 14:14:02) | ||
10 | + * @author fei.hong <fei.hong@yoho.cn> | ||
11 | + */ | ||
12 | +namespace Plugin; | ||
13 | + | ||
14 | +use Yaf\View_Interface; | ||
15 | +use Yaf\Dispatcher; | ||
16 | +use Yaf\Application; | ||
17 | + | ||
18 | +use Plugin\LightnCandy; | ||
19 | + | ||
20 | +class TemplateLayout implements View_Interface | ||
21 | +{ | ||
22 | + | ||
23 | + /* 属性 */ | ||
24 | + protected $_tpl_vars; | ||
25 | + protected $_tpl_dir; | ||
26 | + | ||
27 | + /** | ||
28 | + * 传递给视图变量 | ||
29 | + * | ||
30 | + * @param mixed $name | ||
31 | + * @param mixed $value | ||
32 | + */ | ||
33 | + public function assign($name, $value = null) | ||
34 | + { | ||
35 | + $this->tpl_vars[$name] = $value; | ||
36 | + } | ||
37 | + | ||
38 | + /** | ||
39 | + * 清除一个视图变量 | ||
40 | + * | ||
41 | + * @param mixed $name | ||
42 | + * @return void | ||
43 | + */ | ||
44 | + public function clear($name = null) | ||
45 | + { | ||
46 | + if (isset($this->tpl_vars[$name])) { | ||
47 | + unset($this->tpl_vars[$name]); | ||
48 | + } else { | ||
49 | + $this->tpl_vars = array(); | ||
50 | + } | ||
51 | + } | ||
52 | + | ||
53 | + /** | ||
54 | + * 渲染视图模板,并直接输出到客户端 | ||
55 | + * | ||
56 | + * @param string $tpl | ||
57 | + * @param array $tpl_vars | ||
58 | + */ | ||
59 | + public function display($tpl, $tpl_vars = array()) | ||
60 | + { | ||
61 | + echo $this->render($tpl, $tpl_vars); | ||
62 | + } | ||
63 | + | ||
64 | + /** | ||
65 | + * 渲染视图模板 | ||
66 | + * | ||
67 | + * @param string $tpl | ||
68 | + * @param array $tpl_vars | ||
69 | + * @return string | ||
70 | + */ | ||
71 | + public function render($tpl, $tpl_vars = array()) | ||
72 | + { | ||
73 | + $request = Dispatcher::getInstance()->getRequest(); | ||
74 | + $config = Application::app()->getConfig()->get('application'); | ||
75 | + $tplExt = '.' . $config->view->ext; | ||
76 | + $viewPath = $this->getScriptPath() . '/' . $request->module; | ||
77 | + $viewName = $viewPath . '/' . $request->controller . '/' . $tpl . $tplExt; | ||
78 | + // 判断视图模板文件是否存在, 不存在则直接返回空 | ||
79 | + if (!file_exists($viewName)) { | ||
80 | + return ''; | ||
81 | + } | ||
82 | + | ||
83 | + $tpl_vars = array_merge($this->tpl_vars, $tpl_vars); | ||
84 | + // 取得模板的最后修改时间戳 | ||
85 | + $lastModifyTime = filemtime($viewName); | ||
86 | + // 使用MD5生成唯一的键名 | ||
87 | + $makeKey = md5($viewName . strval($lastModifyTime)); | ||
88 | + // 模板编译成PHP文件所存放的目录 | ||
89 | + $compilePath = $config->template->compile; | ||
90 | + // 模板编译成PHP文件所存放的文件路径 | ||
91 | + $compilePhp = $compilePath . '/' . $makeKey . '.php'; | ||
92 | + | ||
93 | + // 已渲染过该模板,则直接引PHP文件 | ||
94 | + if (is_readable($compilePhp)) { | ||
95 | + LightnCandy::getContext(); | ||
96 | + $renderer = include($compilePhp); | ||
97 | + } | ||
98 | + // 第一次渲染该模板的流程:取得模板内容 => 预编译成PHP函数 => 写入服务器生成PHP文件 | ||
99 | + else { | ||
100 | + $template = file_get_contents($viewName, false, null); | ||
101 | + $phpStr = LightnCandy::compile($template, array( | ||
102 | + // DEBUG: LightnCandy::FLAG_RENDER_DEBUG | LightnCandy::FLAG_ERROR_EXCEPTION | ||
103 | + 'flags' => LightnCandy::FLAG_MUSTACHE | LightnCandy::FLAG_HANDLEBARS, // 使用MUSTACHE和HANDLEBARS的模板格式 | ||
104 | + 'basedir' => array($viewPath . '/partials'), // 模板里使用 {{> partial_name}} 时查找的目录 | ||
105 | + 'fileext' => array($tplExt), // 允许查找文件的后缀 | ||
106 | + )); | ||
107 | + // 文件流方式读取PHP方法 | ||
108 | + $renderer = LightnCandy::prepare($phpStr); | ||
109 | + // 将编译过的函数写入PHP文件 | ||
110 | + file_put_contents($compilePhp, $phpStr); | ||
111 | + } | ||
112 | + | ||
113 | + // 装载内容,调用PHP函数 | ||
114 | + try { | ||
115 | + $result = $renderer($this->_tpl_vars); | ||
116 | + } catch (Exception $e) { | ||
117 | + $result = ''; | ||
118 | + } | ||
119 | + | ||
120 | + return $result; | ||
121 | + } | ||
122 | + | ||
123 | + /** | ||
124 | + * 设置视图模板目录 | ||
125 | + * | ||
126 | + * @param string $path | ||
127 | + * @return boolean | ||
128 | + */ | ||
129 | + public function setScriptPath($path) | ||
130 | + { | ||
131 | + $result = false; | ||
132 | + if (is_readable($path)) { | ||
133 | + $this->tpl_dir = $path; | ||
134 | + $result = true; | ||
135 | + } | ||
136 | + return $result; | ||
137 | + } | ||
138 | + | ||
139 | + /** | ||
140 | + * 获取视图模板目录 | ||
141 | + * | ||
142 | + * @return string | ||
143 | + */ | ||
144 | + public function getScriptPath() | ||
145 | + { | ||
146 | + return $this->_tpl_dir; | ||
147 | + } | ||
148 | + | ||
149 | +} |
script/README.md
0 → 100644
1 | +该目录存放相关的服务器脚本 |
script/database/README.md
0 → 100644
1 | +该目录存放相关数据库表结构 |
script/server/README.md
0 → 100644
1 | +该目录存放相关的服务器配置 |
template/README.md
0 → 100644
1 | +该目录用于存放前端相关的模板 |
tests/README.md
0 → 100644
1 | +存放相关的单元测试用例 |
yohobuy/m.yohobuy.com/README.md
0 → 100644
1 | +有货WAP网站 |
1 | +<?php | ||
2 | + | ||
3 | +/** | ||
4 | + * 启动运行 | ||
5 | + * | ||
6 | + * @name Bootstrap | ||
7 | + * @author fei.hong | ||
8 | + * @desc 所有在Bootstrap类中, 以_init开头的方法, 都会被Yaf调用, | ||
9 | + * @see http://www.php.net/manual/en/class.yaf-bootstrap-abstract.php | ||
10 | + * 这些方法, 都接受一个参数:Yaf_Dispatcher $dispatcher | ||
11 | + * 调用的次序, 和申明的次序相同 | ||
12 | + */ | ||
13 | +use Yaf\Bootstrap_Abstract; | ||
14 | +use Yaf\Dispatcher; | ||
15 | +use Yaf\Application; | ||
16 | +use Yaf\Registry; | ||
17 | +use Yaf\Loader; | ||
18 | +use Yaf\Config; | ||
19 | + | ||
20 | +use Plugin\TemplateLayout; | ||
21 | + | ||
22 | +class Bootstrap extends Bootstrap_Abstract | ||
23 | +{ | ||
24 | + private $_config; | ||
25 | + | ||
26 | + /** | ||
27 | + * 初始化配置 | ||
28 | + * @param Yaf_Dispatcher $dispatcher | ||
29 | + */ | ||
30 | + public function _initConfig(Dispatcher $dispatcher) | ||
31 | + { | ||
32 | + define('REQUEST_METHOD', strtoupper($dispatcher->getRequest()->getMethod())); | ||
33 | + $this->_config = Application::app()->getConfig(); | ||
34 | + Registry::set('appConfig', $this->_config); | ||
35 | + } | ||
36 | + | ||
37 | + /** | ||
38 | + * 初始化应用 | ||
39 | + * @param Yaf_Dispatcher $dispatcher | ||
40 | + */ | ||
41 | + public function _initApplication(Dispatcher $dispatcher) | ||
42 | + { | ||
43 | + defined('APPLICATION_SYSTEM_CONFIG') || define('APPLICATION_SYSTEM_CONFIG', $this->_config->application->servers->config); | ||
44 | + if (APPLICATION_ENV !== 'production') { | ||
45 | + error_reporting(E_ALL); | ||
46 | + ini_set('display_startup_errors', 1); | ||
47 | + ini_set('display_errors', 1); | ||
48 | + } | ||
49 | + Loader::getInstance()->registerLocalNameSpace(explode(',', $this->_config->application->namespaces)); | ||
50 | + } | ||
51 | + | ||
52 | + /** | ||
53 | + * 初始化插件 | ||
54 | + * @param Yaf_Dispatcher $dispatcher | ||
55 | + */ | ||
56 | + public function _initPlugin(Dispatcher $dispatcher) | ||
57 | + { | ||
58 | + | ||
59 | + } | ||
60 | + | ||
61 | + /** | ||
62 | + * 初始化路由 | ||
63 | + * @param Yaf_Dispatcher $dispatcher | ||
64 | + */ | ||
65 | + public function _initRoute(Dispatcher $dispatcher) | ||
66 | + { | ||
67 | + $config = new Config\Ini(APPLICATION_PATH . '/configs/routes.ini'); | ||
68 | + if (isset($config->routes)) { | ||
69 | + $dispatcher->getRouter()->addConfig($config->routes); | ||
70 | + } | ||
71 | + } | ||
72 | + | ||
73 | + /** | ||
74 | + * 初始化Layout | ||
75 | + * @param Yaf_Dispatcher $dispatcher | ||
76 | + */ | ||
77 | + public function _initLayout(Dispatcher $dispatcher) | ||
78 | + { | ||
79 | + // 判断到不是AJAX请求时, 使用自定义的模板渲染 (Mustache or Handlebars) | ||
80 | + if (!$dispatcher->getRequest()->isXmlHttpRequest()) { | ||
81 | + $layout = new TemplateLayout(); | ||
82 | + $layout->setScriptPath($this->_config->application->layout->path); | ||
83 | + $dispatcher->setView($layout); | ||
84 | + } | ||
85 | + // 关闭自动渲染模板 | ||
86 | + else { | ||
87 | + $dispatcher->autoRender(false); | ||
88 | + } | ||
89 | + } | ||
90 | + | ||
91 | + /** | ||
92 | + * 初始化第三方包 | ||
93 | + * @param Dispatcher $dispatcher | ||
94 | + */ | ||
95 | + public function _initPackage(Dispatcher $dispatcher) | ||
96 | + { | ||
97 | + if ($this->_config->composer->autoload == 1) { | ||
98 | + require $this->_config->composer->path . '/vendor/autoload.php'; | ||
99 | + } | ||
100 | + } | ||
101 | + | ||
102 | +} |
1 | +<?php | ||
2 | + | ||
3 | +/** | ||
4 | + * @name ErrorController | ||
5 | + * @desc 错误控制器, 在发生未捕获的异常时刻被调用 | ||
6 | + * @see http://www.php.net/manual/en/yaf-dispatcher.catchexception.php | ||
7 | + * @author liuziyang | ||
8 | + */ | ||
9 | +use Action\AbstractAction; | ||
10 | + | ||
11 | +class ErrorController extends AbstractAction | ||
12 | +{ | ||
13 | + | ||
14 | + public function errorAction($exception) | ||
15 | + { | ||
16 | + header('HTTP/1.1 404 Not Found'); | ||
17 | + header('Status: 404 Not Found'); | ||
18 | + | ||
19 | + exit(); | ||
20 | + } | ||
21 | + | ||
22 | + public function notFoundAction() | ||
23 | + { | ||
24 | + header('HTTP/1.1 404 Not Found'); | ||
25 | + header('Status: 404 Not Found'); | ||
26 | + | ||
27 | + exit(); | ||
28 | + } | ||
29 | + | ||
30 | +} |
1 | +[common] | ||
2 | +;;默认项目 | ||
3 | +application.directory = APPLICATION_PATH "/application" | ||
4 | +;;website library | ||
5 | +application.library = ROOT_PATH "/library" | ||
6 | +;;默认模块 | ||
7 | +application.modules = "Default,Test" | ||
8 | +;;加载 | ||
9 | +application.bootstrap = APPLICATION_PATH "/application/Bootstrap.php" | ||
10 | +;;view文件的扩展名 | ||
11 | +application.view.ext = "phtml" | ||
12 | +;;默认layouts | ||
13 | +application.layout.path = APPLICATION_PATH "/application/layouts" | ||
14 | +;;layouts 默认文件 | ||
15 | +application.layout.default = "default" | ||
16 | +;;默认Controller | ||
17 | +application.dispatcher.defaultController = "index" | ||
18 | +;;默认Action | ||
19 | +application.dispatcher.defaultAction = "index" | ||
20 | + | ||
21 | +;;初始化命名空间 | ||
22 | +application.namespaces = "Action,Configs,Plugin" | ||
23 | + | ||
24 | +;;使用composer | ||
25 | +composer.autoload = 0 | ||
26 | +composer.path = APPLICATION_PATH "/library/Package" | ||
27 | + | ||
28 | +yaf.use_namespace = 1 | ||
29 | + | ||
30 | +;;调试模式 | ||
31 | +application.debug = True | ||
32 | +application.servers.config = APPLICATION_PATH "/configs/core" | ||
33 | + | ||
34 | +;出错的时候是否抛出异常 | ||
35 | +application.dispatcher.throwException = True | ||
36 | + | ||
37 | +;是否使用默认的异常 捕获Controller, 如果开启, 在有未捕获的异常的时候, | ||
38 | +;控制权会交给ErrorController的errorAction 方法, | ||
39 | +;可以通过$request->getException()获得此异常对象 False | ||
40 | +application.dispatcher.catchException = True | ||
41 | + | ||
42 | +;模板预编译目录,该目录需要有读写权限 | ||
43 | +application.template.compile = ROOT_PATH "/compile/m.yohobuy.com" |
1 | +[common] | ||
2 | +;;默认项目 | ||
3 | +application.directory = APPLICATION_PATH "/application" | ||
4 | +;;website library | ||
5 | +application.library = ROOT_PATH "/library" | ||
6 | +;;默认模块 | ||
7 | +application.modules = "Default,Test" | ||
8 | +;;加载 | ||
9 | +application.bootstrap = APPLICATION_PATH "/application/Bootstrap.php" | ||
10 | +;;view文件的扩展名 | ||
11 | +application.view.ext = "phtml" | ||
12 | +;;默认layouts | ||
13 | +application.layout.path = APPLICATION_PATH "/application/layouts" | ||
14 | +;;layouts 默认文件 | ||
15 | +application.layout.default = "default" | ||
16 | +;;默认Controller | ||
17 | +application.dispatcher.defaultController = "index" | ||
18 | +;;默认Action | ||
19 | +application.dispatcher.defaultAction = "index" | ||
20 | + | ||
21 | +;;初始化命名空间 | ||
22 | +application.namespaces = "Action,Configs,Plugin" | ||
23 | + | ||
24 | +;;使用composer | ||
25 | +composer.autoload = 0 | ||
26 | +composer.path = APPLICATION_PATH "/library/Package" | ||
27 | + | ||
28 | +yaf.use_namespace = 1 | ||
29 | + | ||
30 | +;;调试模式 | ||
31 | +application.debug = False | ||
32 | +application.servers.config = APPLICATION_PATH "/configs/core" | ||
33 | + | ||
34 | +;出错的时候是否抛出异常 | ||
35 | +application.dispatcher.throwException = False | ||
36 | + | ||
37 | +;是否使用默认的异常 捕获Controller, 如果开启, 在有未捕获的异常的时候, | ||
38 | +;控制权会交给ErrorController的errorAction 方法, | ||
39 | +;可以通过$request->getException()获得此异常对象 | ||
40 | +application.dispatcher.catchException = False | ||
41 | + | ||
42 | +;模板预编译目录,该目录需要有读写权限 | ||
43 | +application.template.compile = ROOT_PATH "/compile/m.yohobuy.com" |
1 | +[common] | ||
2 | +;;默认项目 | ||
3 | +application.directory = APPLICATION_PATH "/application" | ||
4 | +;;website library | ||
5 | +application.library = ROOT_PATH "/library" | ||
6 | +;;默认模块 | ||
7 | +application.modules = "Default,Test" | ||
8 | +;;加载 | ||
9 | +application.bootstrap = APPLICATION_PATH "/application/Bootstrap.php" | ||
10 | +;;view文件的扩展名 | ||
11 | +application.view.ext = "phtml" | ||
12 | +;;默认layouts | ||
13 | +application.layout.path = APPLICATION_PATH "/application/layouts" | ||
14 | +;;layouts 默认文件 | ||
15 | +application.layout.default = "default" | ||
16 | +;;默认Controller | ||
17 | +application.dispatcher.defaultController = "index" | ||
18 | +;;默认Action | ||
19 | +application.dispatcher.defaultAction = "index" | ||
20 | + | ||
21 | +;;初始化命名空间 | ||
22 | +application.namespaces = "Action,Configs,Plugin" | ||
23 | + | ||
24 | +;;使用composer | ||
25 | +composer.autoload = 0 | ||
26 | +composer.path = APPLICATION_PATH "/library/Package" | ||
27 | + | ||
28 | +yaf.use_namespace = 1 | ||
29 | + | ||
30 | +;;调试模式 | ||
31 | +application.debug = True | ||
32 | +application.servers.config = APPLICATION_PATH "/configs/core" | ||
33 | + | ||
34 | +;出错的时候是否抛出异常 | ||
35 | +application.dispatcher.throwException = True | ||
36 | + | ||
37 | +;是否使用默认的异常 捕获Controller, 如果开启, 在有未捕获的异常的时候, | ||
38 | +;控制权会交给ErrorController的errorAction 方法, | ||
39 | +;可以通过$request->getException()获得此异常对象 False | ||
40 | +application.dispatcher.catchException = True | ||
41 | + | ||
42 | +;模板预编译目录,该目录需要有读写权限 | ||
43 | +application.template.compile = ROOT_PATH "/compile/m.yohobuy.com" |
yohobuy/m.yohobuy.com/configs/routes.ini
0 → 100644
1 | +; default | ||
2 | +routes.index.type = "rewrite" | ||
3 | +routes.index.match = "/(index|index.html)$" | ||
4 | +routes.index.route.module = Default | ||
5 | +routes.index.route.controller = Index | ||
6 | +routes.index.route.action = Index | ||
7 | + | ||
8 | +; error | ||
9 | +routes.notfound.type = "rewrite" | ||
10 | +routes.notfound.match = "/error.html" | ||
11 | +routes.notfound.route.module = Default | ||
12 | +routes.notfound.route.controller = Error | ||
13 | +routes.notfound.route.action = notfound |
yohobuy/m.yohobuy.com/public/crossdomain.xml
0 → 100644
yohobuy/m.yohobuy.com/public/favicon.ico
0 → 100644
No preview for this file type
yohobuy/m.yohobuy.com/public/index-dev.php
0 → 100644
1 | +<?php | ||
2 | +use Yaf\Application; | ||
3 | + | ||
4 | +define('APPLICATION_PATH', dirname(__DIR__)); | ||
5 | +define('ROOT_PATH', dirname(dirname(APPLICATION_PATH))); | ||
6 | +defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'developer'); | ||
7 | + | ||
8 | +$application = new Application(APPLICATION_PATH . '/configs/application.developer.ini'); | ||
9 | +$application->bootstrap()->run(); |
yohobuy/m.yohobuy.com/public/index-test.php
0 → 100644
1 | +<?php | ||
2 | +use Yaf\Application; | ||
3 | + | ||
4 | +define('APPLICATION_PATH', dirname(__DIR__)); | ||
5 | +define('ROOT_PATH', dirname(dirname(APPLICATION_PATH))); | ||
6 | +defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'testing'); | ||
7 | + | ||
8 | +$application = new Application(APPLICATION_PATH . '/configs/application.testing.ini'); | ||
9 | +$application->bootstrap()->run(); |
yohobuy/m.yohobuy.com/public/index.php
0 → 100644
1 | +<?php | ||
2 | +use Yaf\Application; | ||
3 | + | ||
4 | +define('APPLICATION_PATH', dirname(__DIR__)); | ||
5 | +define('ROOT_PATH', dirname(dirname(APPLICATION_PATH))); | ||
6 | +defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'production'); | ||
7 | + | ||
8 | +$application = new Application(APPLICATION_PATH . '/configs/application.production.ini'); | ||
9 | +$application->bootstrap()->run(); |
yohobuy/www.yohobuy.com/README.md
0 → 100644
1 | +有货PC网站 |
-
Please register or login to post a comment