Authored by hf

init frame code

Showing 47 changed files with 1813 additions and 0 deletions
[submodule "framework"]
path = framework
url = http://git.dev.yoho.cn/web/yaf-hood.git
branch = master
... ...
存放模板预编译文件
\ No newline at end of file
... ...
WAP
\ No newline at end of file
... ...
PC
\ No newline at end of file
... ...
{
"name": "YOHO!有货",
"description": "YOHO!有货WEB版本",
"keywords": [
"yohobuy",
"有货"
],
"homepage": "http://git.dev.yoho.cn/web/yohobuy.git",
"type": "project",
"authors": [
{
"name": "fei.hong",
"email": "fei.hong@yoho.cn",
"homepage": "www.yoho.cn"
}
],
"require": {
"php": ">=5.3.0"
},
"extra": {
"branch-alias": {
"dev-master": "master",
"dev-test": "test",
"dev-develop": "develop"
}
}
}
\ No newline at end of file
... ...
该目录用于存放相关的文档
\ No newline at end of file
... ...
framework @ 119c247f
Subproject commit 119c247f5cf929aa1e059e40609bb16dd6b58f05
... ...
<?php
/**
* 所有Controller控制器的基类
*
* @name AbstractAction
* @package
* @copyright yoho.inc
* @version 1.0 (2015-9-15 11:55:25)
* @author fei.hong <fei.hong@yoho.cn>
*/
namespace Action;
use Yaf\Controller_Abstract;
use Yaf\Dispatcher;
use Hood\Cache;
class AbstractAction extends Controller_Abstract
{
/**
* HTTP请求对象
*
* @var object
*/
protected $_request;
/**
* 初始化
*/
public function init()
{
$this->_request = $this->getRequest();
}
/**
* 封装一下获取get参数
*
* @param String $key
* @param mixed $default
* @return mixed
*/
protected function get($key, $default = null)
{
return $this->_request->getQuery($key, $default);
}
/**
* 封装一下获取post参数
*
* @param String $key
* @param mixed $default
* @return mixed
*/
protected function post($key, $default = null)
{
return $this->_request->getPost($key, $default);
}
/**
* 关闭模板自动渲染
*
* @return void
*/
protected function disableView()
{
Dispatcher::getInstance()->autoRender(false);
}
/**
* 使用Memcache缓存
*
* @param string $node
* @param string $childNode
* @return object
*/
protected function memcache($node = null, $childNode = 'hosts')
{
if (PATH_SEPARATOR === '\\') {
return Cache::memcache($node, $childNode);
} else {
return Cache::memcached($node, $childNode);
}
}
}
... ...
<?php
namespace Action;
use Configs\StaticJS;
use Configs\StaticCss;
use Hood\Action as HoodAction;
use Yaf\Registry;
use Yaf\Dispatcher;
use Hood\Session;
use Hood\Cache;
class RootAction extends HoodAction
{
protected $_appConfig = array();
public function init()
{
$this->_appConfig = Registry::get('appConfig');
}
public function _assign($name, $value)
{
return $this->getView()->assign($name, $value);
}
/**
* 获取JS URL
*
* @param String $jsName
* @return String
*/
public function _js($jsName, $local = false)
{
if (isset(StaticJS::$res[$jsName])) {
$js = $this->_appConfig['website']['static']['url'];
if ($local == false) {
$js .= StaticJS::$res[$jsName];
} else {
$js = StaticJS::$res[$jsName];
}
return $js;
}
return '';
}
/**
* 获取Css URL
*
* @param String $cssName
* @return String
*/
public function _css($cssName, $local = false)
{
if (isset(StaticCss::$res[$cssName])) {
$css = $this->_appConfig['website']['static']['url'];
if ($local == false) {
$css .= StaticCss::$res[$cssName];
} else {
$css = StaticCss::$res[$cssName];
}
return $css;
}
return '';
}
/**
* 获取JS URL
*
* @param String $jsName
* @return String
*/
public function _viewScriptPush(array $jsList, $scriptName = '_footerScript')
{
$script = $this->_viewScript($scriptName);
foreach ($jsList as $js) {
$script->appendFile($this->_js($js, true));
}
}
/**
* 获取JS URL
*
* @param String $jsName
* @return String
*/
public function _viewCssPush(array $cssList, $linkName = '_headLink')
{
$link = $this->_viewLink($linkName);
foreach ($cssList as $css) {
$link->appendFile($this->_css($css, true));
}
}
/**
* 获取参数
* @param null $name
* @param null $default
* @return mixed
*/
protected function _getEnv($name = null, $default = null)
{
return $this->getRequest()->getEnv($name, $default);
}
/**
* 封装一下获取param参数
* @param String $key
* @param mixed $default
* @return mixed
*/
protected function _getParam($key, $default = null)
{
$request = $this->_request->getRequest();
$route = $this->getRequest()->getParams();
$allParams = array_merge($request, $route);
return isset($allParams[$key]) ? $allParams[$key] : $default;
}
/**
* 获取所有参数
* @return array
*/
protected function _getParams()
{
return $this->_request->getParams();
}
/**
* 获取所有参数
* @return mixed
*/
protected function _getRequests()
{
return $this->_request->getRequest();
}
/**
* 封装一下获取get参数
* @param String $key
* @param mixed $default
* @return mixed
*/
protected function _get($key, $default = null)
{
return $this->getRequest()->getQuery($key, $default);
}
/**
* 封装一下获取post参数
* @param String $key
* @param mixed $default
* @return mixed
*/
protected function _post($key, $default = null)
{
return $this->getRequest()->getPost($key, $default);
}
/**
* 封装一下获取post参数
* @param String $key
* @param mixed $default
* @return mixed
*/
protected function _typePost($key, $settype = null, $default = null)
{
$result = $this->getRequest()->getPost($key, $default);
switch ($settype) {
case 'bool':
$result = (bool)$result;
break;
case 'int':
$result = (int)$result;
break;
case 'string':
$result = (string)$result;
break;
case 'float':
$result = (float)$result;
break;
case 'binary':
$result = (binary)$result;
break;
default:
$result = $result;
break;
}
return $result;
}
/**
* 关闭模板 & Layout
*/
public function _disable()
{
$this->disableLayout();
$this->disableView();
}
/**
* 关闭模板
*/
public function disableView()
{
Dispatcher::getInstance()->autoRender(FALSE);
}
/**
* 关闭Layout
*/
public function disableLayout()
{
$this->getView()->setLayout('');
}
/**
* @param string $namespace
* @return \Hood\Core\Session\SessionNamespace
*/
public function _session($namespace = 'session_default')
{
if (isset($this->_appConfig['website']['session']) && $this->_appConfig['website']['session'] == 'file') {
return Session::fileStart($namespace);
} else {
return Session::start($namespace);
}
}
public function _mc($node = null, $childNode = 'hosts'){
return Cache::memcached($node, $childNode);
}
}
\ No newline at end of file
... ...
<?php
/**
* User: haisheng.shen@yoho.cn
* Date: 15-2-9 下午2:08
*/
namespace LibModels;
class Concurrent
{
/**
* 添加并行的请求
* @param $url
* @param $method
* @param callable $callback
* @param null $errorCallback
*/
public static function call($url, $method, array $parameters = array(), callable $callback = null, callable $errorCallback=null)
{
\Yar_Concurrent_Client::call($url, $method, $parameters, $callback, $errorCallback);
}
/**
* 发起请求
* @param null $callback
* @param null $errorCallback
*/
public static function loop(callable $callback=null, callable $errorCallback=null)
{
\Yar_Concurrent_Client::loop($callback, $errorCallback);
}
/**
* 非并行yar实例的数组
* @var array
*/
protected static $yarInstance = array();
/**
* 非并行yar的实例
* @param $url
* @return mixed
*/
public static function single($url, $method, array $parameters =array(), callable $callback=null, callable $errorCallback = null)
{
$key = md5($url);
if (!isset(self::$yarInstance[$key])) {
self::$yarInstance[$key] = new \Yar_Client($url);
}
try {
$result = call_user_func_array(array(self::$yarInstance[$key], $method), $parameters);
$callback($result);
} catch (\Yar_Server_Exception $e) {
if (!empty($errorCallback)) {
$errorCallback($e);
}
}
}
/**
* 根据参数来选择并行或者非并行
* @param $url
* @param $method
* @param array $params
* @param callable $callback
* @param callable $errorCallback
* @param bool $concurrent
*/
public static function choise($url, $method, array $params=array(), callable $callback=null, callable $errorCallback = null, $concurrent=true)
{
if ($concurrent) {
self::call($url, $method, $params, $callback, $errorCallback);
} else {
self::single($url, $method, $params, $callback, $errorCallback);
}
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: Zip
* Date: 14/11/27
* Time: 下午1:10
*/
namespace LibModels;
use Hood\Concurrent as hoodConcurrent;
class ModelsConcurrent
{
static protected $uri = 'http://service.example.yohobuy.com/service/product/v1';
/**
* @var Concurrent|Concurrent\Yar\Concurrent
*/
static private $concurrent;
/**
* @return Concurrent|Concurrent\Yar\Concurrent
*/
static protected function connect()
{
if (empty(self::$concurrent)) {
self::$concurrent = hoodConcurrent::yarConcurrent(self::$uri);
}
return self::$concurrent;
}
static public function loop()
{
self::connect()->loop('Models\ModelsConcurrent::callback', 'Models\ModelsConcurrent::errorCallback');
}
static public function errorCallback($type, $error, $callinfo)
{
print_r($error);
}
static public function callback($ret, $callinfo)
{
}
}
\ No newline at end of file
... ...
{
"name": "依赖包管理",
"description": "有货项目依赖第三方的包管理",
"keywords": [
"yohobuy",
"package"
],
"homepage": "",
"type": "library",
"repositories": [
{
"packagist": false
}
],
"authors": [
{
"name": "hf",
"email": "fei.hong@yoho.cn",
"homepage": "www.yoho.cn"
}
],
"require": {
"php": ">=5.3.0"
}
}
\ No newline at end of file
... ...
<?php
// autoload.php @generated by Composer
require_once __DIR__ . '/composer' . '/autoload_real.php';
return ComposerAutoloaderInit3f4063230841d94400077da033fc02ab::getLoader();
... ...
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Autoload;
/**
* ClassLoader implements a PSR-0 class loader
*
* See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md
*
* $loader = new \Composer\Autoload\ClassLoader();
*
* // register classes with namespaces
* $loader->add('Symfony\Component', __DIR__.'/component');
* $loader->add('Symfony', __DIR__.'/framework');
*
* // activate the autoloader
* $loader->register();
*
* // to enable searching the include path (eg. for PEAR packages)
* $loader->setUseIncludePath(true);
*
* In this example, if you try to use a class in the Symfony\Component
* namespace or one of its children (Symfony\Component\Console for instance),
* the autoloader will first look for the class under the component/
* directory, and it will then fallback to the framework/ directory if not
* found before giving up.
*
* This class is loosely based on the Symfony UniversalClassLoader.
*
* @author Fabien Potencier <fabien@symfony.com>
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
class ClassLoader
{
// PSR-4
private $prefixLengthsPsr4 = array();
private $prefixDirsPsr4 = array();
private $fallbackDirsPsr4 = array();
// PSR-0
private $prefixesPsr0 = array();
private $fallbackDirsPsr0 = array();
private $useIncludePath = false;
private $classMap = array();
private $classMapAuthoritative = false;
public function getPrefixes()
{
if (!empty($this->prefixesPsr0)) {
return call_user_func_array('array_merge', $this->prefixesPsr0);
}
return array();
}
public function getPrefixesPsr4()
{
return $this->prefixDirsPsr4;
}
public function getFallbackDirs()
{
return $this->fallbackDirsPsr0;
}
public function getFallbackDirsPsr4()
{
return $this->fallbackDirsPsr4;
}
public function getClassMap()
{
return $this->classMap;
}
/**
* @param array $classMap Class to filename map
*/
public function addClassMap(array $classMap)
{
if ($this->classMap) {
$this->classMap = array_merge($this->classMap, $classMap);
} else {
$this->classMap = $classMap;
}
}
/**
* Registers a set of PSR-0 directories for a given prefix, either
* appending or prepending to the ones previously set for this prefix.
*
* @param string $prefix The prefix
* @param array|string $paths The PSR-0 root directories
* @param bool $prepend Whether to prepend the directories
*/
public function add($prefix, $paths, $prepend = false)
{
if (!$prefix) {
if ($prepend) {
$this->fallbackDirsPsr0 = array_merge(
(array) $paths,
$this->fallbackDirsPsr0
);
} else {
$this->fallbackDirsPsr0 = array_merge(
$this->fallbackDirsPsr0,
(array) $paths
);
}
return;
}
$first = $prefix[0];
if (!isset($this->prefixesPsr0[$first][$prefix])) {
$this->prefixesPsr0[$first][$prefix] = (array) $paths;
return;
}
if ($prepend) {
$this->prefixesPsr0[$first][$prefix] = array_merge(
(array) $paths,
$this->prefixesPsr0[$first][$prefix]
);
} else {
$this->prefixesPsr0[$first][$prefix] = array_merge(
$this->prefixesPsr0[$first][$prefix],
(array) $paths
);
}
}
/**
* Registers a set of PSR-4 directories for a given namespace, either
* appending or prepending to the ones previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-0 base directories
* @param bool $prepend Whether to prepend the directories
*
* @throws \InvalidArgumentException
*/
public function addPsr4($prefix, $paths, $prepend = false)
{
if (!$prefix) {
// Register directories for the root namespace.
if ($prepend) {
$this->fallbackDirsPsr4 = array_merge(
(array) $paths,
$this->fallbackDirsPsr4
);
} else {
$this->fallbackDirsPsr4 = array_merge(
$this->fallbackDirsPsr4,
(array) $paths
);
}
} elseif (!isset($this->prefixDirsPsr4[$prefix])) {
// Register directories for a new namespace.
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = (array) $paths;
} elseif ($prepend) {
// Prepend directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
(array) $paths,
$this->prefixDirsPsr4[$prefix]
);
} else {
// Append directories for an already registered namespace.
$this->prefixDirsPsr4[$prefix] = array_merge(
$this->prefixDirsPsr4[$prefix],
(array) $paths
);
}
}
/**
* Registers a set of PSR-0 directories for a given prefix,
* replacing any others previously set for this prefix.
*
* @param string $prefix The prefix
* @param array|string $paths The PSR-0 base directories
*/
public function set($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr0 = (array) $paths;
} else {
$this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
}
}
/**
* Registers a set of PSR-4 directories for a given namespace,
* replacing any others previously set for this namespace.
*
* @param string $prefix The prefix/namespace, with trailing '\\'
* @param array|string $paths The PSR-4 base directories
*
* @throws \InvalidArgumentException
*/
public function setPsr4($prefix, $paths)
{
if (!$prefix) {
$this->fallbackDirsPsr4 = (array) $paths;
} else {
$length = strlen($prefix);
if ('\\' !== $prefix[$length - 1]) {
throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
}
$this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
$this->prefixDirsPsr4[$prefix] = (array) $paths;
}
}
/**
* Turns on searching the include path for class files.
*
* @param bool $useIncludePath
*/
public function setUseIncludePath($useIncludePath)
{
$this->useIncludePath = $useIncludePath;
}
/**
* Can be used to check if the autoloader uses the include path to check
* for classes.
*
* @return bool
*/
public function getUseIncludePath()
{
return $this->useIncludePath;
}
/**
* Turns off searching the prefix and fallback directories for classes
* that have not been registered with the class map.
*
* @param bool $classMapAuthoritative
*/
public function setClassMapAuthoritative($classMapAuthoritative)
{
$this->classMapAuthoritative = $classMapAuthoritative;
}
/**
* Should class lookup fail if not found in the current class map?
*
* @return bool
*/
public function isClassMapAuthoritative()
{
return $this->classMapAuthoritative;
}
/**
* Registers this instance as an autoloader.
*
* @param bool $prepend Whether to prepend the autoloader or not
*/
public function register($prepend = false)
{
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
}
/**
* Unregisters this instance as an autoloader.
*/
public function unregister()
{
spl_autoload_unregister(array($this, 'loadClass'));
}
/**
* Loads the given class or interface.
*
* @param string $class The name of the class
* @return bool|null True if loaded, null otherwise
*/
public function loadClass($class)
{
if ($file = $this->findFile($class)) {
includeFile($file);
return true;
}
}
/**
* Finds the path to the file where the class is defined.
*
* @param string $class The name of the class
*
* @return string|false The path if found, false otherwise
*/
public function findFile($class)
{
// work around for PHP 5.3.0 - 5.3.2 https://bugs.php.net/50731
if ('\\' == $class[0]) {
$class = substr($class, 1);
}
// class map lookup
if (isset($this->classMap[$class])) {
return $this->classMap[$class];
}
if ($this->classMapAuthoritative) {
return false;
}
$file = $this->findFileWithExtension($class, '.php');
// Search for Hack files if we are running on HHVM
if ($file === null && defined('HHVM_VERSION')) {
$file = $this->findFileWithExtension($class, '.hh');
}
if ($file === null) {
// Remember that this class does not exist.
return $this->classMap[$class] = false;
}
return $file;
}
private function findFileWithExtension($class, $ext)
{
// PSR-4 lookup
$logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
$first = $class[0];
if (isset($this->prefixLengthsPsr4[$first])) {
foreach ($this->prefixLengthsPsr4[$first] as $prefix => $length) {
if (0 === strpos($class, $prefix)) {
foreach ($this->prefixDirsPsr4[$prefix] as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $length))) {
return $file;
}
}
}
}
}
// PSR-4 fallback dirs
foreach ($this->fallbackDirsPsr4 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
return $file;
}
}
// PSR-0 lookup
if (false !== $pos = strrpos($class, '\\')) {
// namespaced class name
$logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
. strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
} else {
// PEAR-like class name
$logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
}
if (isset($this->prefixesPsr0[$first])) {
foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
if (0 === strpos($class, $prefix)) {
foreach ($dirs as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
}
}
}
// PSR-0 fallback dirs
foreach ($this->fallbackDirsPsr0 as $dir) {
if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
return $file;
}
}
// PSR-0 include paths.
if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
return $file;
}
}
}
/**
* Scope isolated include.
*
* Prevents access to $this/self from included files.
*/
function includeFile($file)
{
include $file;
}
... ...
<?php
// autoload_classmap.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
);
... ...
<?php
// autoload_namespaces.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
);
... ...
<?php
// autoload_psr4.php @generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
// 'QBill\\' => array($vendorDir . '/QBill/src/QBill'),
// 'Bill\\' => array($vendorDir . '/QBill/src/Models/Bill'),
);
... ...
<?php
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit3f4063230841d94400077da033fc02ab
{
private static $loader;
public static function loadClassLoader($class)
{
if ('Composer\Autoload\ClassLoader' === $class) {
require __DIR__ . '/ClassLoader.php';
}
}
public static function getLoader()
{
if (null !== self::$loader) {
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit3f4063230841d94400077da033fc02ab', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
spl_autoload_unregister(array('ComposerAutoloaderInit3f4063230841d94400077da033fc02ab', 'loadClassLoader'));
$map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
$loader->set($namespace, $path);
}
$map = require __DIR__ . '/autoload_psr4.php';
foreach ($map as $namespace => $path) {
$loader->setPsr4($namespace, $path);
}
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
$loader->addClassMap($classMap);
}
$loader->register(true);
return $loader;
}
}
function composerRequire3f4063230841d94400077da033fc02ab($file)
{
require $file;
}
... ...
<?php
/**
* Created by PhpStorm.
* User: liuziyang
* Date: 14-1-12
* Time: 16:32
*/
namespace Plugin;
use Yaf\View_Interface;
use Yaf\View;
use Yaf\Application;
class Layout implements View_Interface
{
public $breadcrumb = array();
public $engine;
protected $options = array();
protected $layout_path;
protected $layout;
protected $content;
protected $tpl_vars = array();
protected $tpl_dir;
public function __construct($path, $options = array())
{
$this->layout_path = $path;
$this->options = $options;
}
protected function engine()
{
$this->engine = $this->engine ?: new View\Simple(
$this->tpl_dir,
$this->options
);
return $this->engine;
}
public function setScriptPath($path)
{
if (is_readable($path)) {
$this->tpl_dir = $path;
$this->engine()->setScriptPath($path);
$this->layout_path = $path . "/../layouts";
return true;
}
throw new Exception("Invalid path: {$path}");
}
public function getScriptPath()
{
return $this->engine()->getScriptPath();
}
public function setLayout($name)
{
$this->layout = $name;
}
public function getLayout()
{
return $this->layout;
}
public function setLayoutPath($path)
{
$this->layout_path = $path;
return $this;
}
public function getLayoutPath()
{
$config = Application::app()->getConfig()->get('application');
return $this->layout_path . "/" . $this->layout . ".{$config->view->ext}";
}
public function __set($name, $value)
{
$this->assign($name, $value);
}
public function __isset($name)
{
return (null !== $this->engine()->$name);
}
public function __unset($name)
{
$this->engine()->clear($name);
}
public function assign($name, $value = null)
{
$this->tpl_vars[$name] = $value;
$this->engine()->assign($name, $value);
}
public function assignRef($name, &$value)
{
$this->tpl_vars[$name] = $value;
$this->engine()->assignRef($name, $value);
}
public function clearVars($name)
{
$this->tpl_vars = array();
$this->engine()->clear($name);
}
public function render($tpl, $tpl_vars = array())
{
$tpl_vars = array_merge($this->tpl_vars, $tpl_vars);
$this->content = $this->engine()->render($tpl, $tpl_vars);
if (null == $this->layout) {
return $this->content;
}
$ref = new \ReflectionClass($this->engine());
$prop = $ref->getProperty('_tpl_vars');
$prop->setAccessible(true);
$view_vars = $prop->getValue($this->engine());
$tpl_vars = array_merge($tpl_vars, $view_vars);
$tpl_vars['content'] = $this->content;
$this->engine()->assign('breadcrumb', $this->breadcrumb);
return $this->engine()->render(
$this->getLayoutPath(),
$tpl_vars
);
}
public function display($tpl, $tpl_vars = array())
{
echo $this->render($tpl, $tpl_vars);
}
}
... ...
This diff could not be displayed because it is too large.
<?php
/**
* Created by PhpStorm.
* User: liuziyang
* Date: 14-1-15
* Time: 16:13
*/
namespace Plugin;
use Yaf\Plugin_abstract;
use Yaf\Request_Abstract;
use Yaf\Response_Abstract;
use Yaf\Registry;
use Yaf\Dispatcher;
use Yaf\Loader;
class Routes extends Plugin_abstract
{
/**
*
*
* 在路由之前触发,这个是7个事件中, 最早的一个. 但是一些全局自定的工作, 还是应该放在Bootstrap中去完成
* @param Request_Abstract $request
* @param Response_Abstract $response
* @return bool|void
*/
public function routerStartup(Request_Abstract $request, Response_Abstract $response)
{
$_httpResult = explode('.', $request->getServer('HTTP_HOST'));
$level = 'm';
if (count($_httpResult) == 3) {
list ($level, $domainName, $suffix) = $_httpResult;
} else if (count($_httpResult) == 4) {
$level = $_httpResult[0] . '.' . $_httpResult[1];
}
$_config = Registry::get('appConfig');
$_modulesList = array();
if (!empty($_config['application']['modules'])) {
$_modules = $_config['application']['modules'];
$_modulesList = explode(',', $_modules);
}
$newDomain = array(
'guang.m'=>'guang'
);
if (isset($newDomain[strtolower($level)]) ) {
$level = $newDomain[$level];
$request->module = ucfirst(strtolower($level));
} else if ($level != 'www' && in_array(ucfirst($level), $_modulesList, true)) {
$request->module = ucfirst($level);
} else {
$request->module = 'Default';
$level = 'Default';
}
$dispatcher = Dispatcher::getInstance();
$app = $dispatcher->getApplication();
$file = $app->getAppDirectory() . "/modules/" . ucfirst($level) . "/__init.php";
if (file_exists($file)) {
Loader::import($file);
}
}
/**
*
*
* 路由结束之后触发,此时路由一定正确完成, 否则这个事件不会触发
* @param Request_Abstract $request
* @param Response_Abstract $response
* @return bool|void
*/
public function routerShutdown(Request_Abstract $request, Response_Abstract $response)
{
}
/**
*
*
* 分发循环开始之前被触发
* @param Request_Abstract $request
* @param Response_Abstract $response
* @return bool|void
*/
public function dispatchLoopStartup(Request_Abstract $request, Response_Abstract $response)
{
}
/**
*
*
* 分发之前触发 如果在一个请求处理过程中, 发生了forward, 则这个事件会被触发多次
* @param Request_Abstract $request
* @param Response_Abstract $response
* @return bool|void
*/
public function preDispatch(Request_Abstract $request, Response_Abstract $response)
{
}
/**
*
*
* 分发结束之后触发,此时动作已经执行结束, 视图也已经渲染完成. 和preDispatch类似, 此事件也可能触发多次
* @param Request_Abstract $request
* @param Response_Abstract $response
* @return bool|void
*/
public function postDispatch(Request_Abstract $request, Response_Abstract $response)
{
}
/**
*
*
* 分发循环结束之后触发,此时表示所有的业务逻辑都已经运行完成, 但是响应还没有发送
* @param Request_Abstract $request
* @param Response_Abstract $response
* @return bool|void
*/
public function dispatchLoopShutdown(Request_Abstract $request, Response_Abstract $response)
{
}
/**
* @param Request_Abstract $request
* @param Response_Abstract $response
* @return bool|void
*/
public function preResponse(Request_Abstract $request, Response_Abstract $response)
{
}
}
\ No newline at end of file
... ...
<?php
/**
* 模板视图
*
* @name TemplateLayout
* @package library/Plugin
* @copyright yoho.inc
* @version 1.0 (2015-9-15 14:14:02)
* @author fei.hong <fei.hong@yoho.cn>
*/
namespace Plugin;
use Yaf\View_Interface;
use Yaf\Dispatcher;
use Yaf\Application;
use Plugin\LightnCandy;
class TemplateLayout implements View_Interface
{
/* 属性 */
protected $_tpl_vars;
protected $_tpl_dir;
/**
* 传递给视图变量
*
* @param mixed $name
* @param mixed $value
*/
public function assign($name, $value = null)
{
$this->tpl_vars[$name] = $value;
}
/**
* 清除一个视图变量
*
* @param mixed $name
* @return void
*/
public function clear($name = null)
{
if (isset($this->tpl_vars[$name])) {
unset($this->tpl_vars[$name]);
} else {
$this->tpl_vars = array();
}
}
/**
* 渲染视图模板,并直接输出到客户端
*
* @param string $tpl
* @param array $tpl_vars
*/
public function display($tpl, $tpl_vars = array())
{
echo $this->render($tpl, $tpl_vars);
}
/**
* 渲染视图模板
*
* @param string $tpl
* @param array $tpl_vars
* @return string
*/
public function render($tpl, $tpl_vars = array())
{
$request = Dispatcher::getInstance()->getRequest();
$config = Application::app()->getConfig()->get('application');
$tplExt = '.' . $config->view->ext;
$viewPath = $this->getScriptPath() . '/' . $request->module;
$viewName = $viewPath . '/' . $request->controller . '/' . $tpl . $tplExt;
// 判断视图模板文件是否存在, 不存在则直接返回空
if (!file_exists($viewName)) {
return '';
}
$tpl_vars = array_merge($this->tpl_vars, $tpl_vars);
// 取得模板的最后修改时间戳
$lastModifyTime = filemtime($viewName);
// 使用MD5生成唯一的键名
$makeKey = md5($viewName . strval($lastModifyTime));
// 模板编译成PHP文件所存放的目录
$compilePath = $config->template->compile;
// 模板编译成PHP文件所存放的文件路径
$compilePhp = $compilePath . '/' . $makeKey . '.php';
// 已渲染过该模板,则直接引PHP文件
if (is_readable($compilePhp)) {
LightnCandy::getContext();
$renderer = include($compilePhp);
}
// 第一次渲染该模板的流程:取得模板内容 => 预编译成PHP函数 => 写入服务器生成PHP文件
else {
$template = file_get_contents($viewName, false, null);
$phpStr = LightnCandy::compile($template, array(
// DEBUG: LightnCandy::FLAG_RENDER_DEBUG | LightnCandy::FLAG_ERROR_EXCEPTION
'flags' => LightnCandy::FLAG_MUSTACHE | LightnCandy::FLAG_HANDLEBARS, // 使用MUSTACHE和HANDLEBARS的模板格式
'basedir' => array($viewPath . '/partials'), // 模板里使用 {{> partial_name}} 时查找的目录
'fileext' => array($tplExt), // 允许查找文件的后缀
));
// 文件流方式读取PHP方法
$renderer = LightnCandy::prepare($phpStr);
// 将编译过的函数写入PHP文件
file_put_contents($compilePhp, $phpStr);
}
// 装载内容,调用PHP函数
try {
$result = $renderer($this->_tpl_vars);
} catch (Exception $e) {
$result = '';
}
return $result;
}
/**
* 设置视图模板目录
*
* @param string $path
* @return boolean
*/
public function setScriptPath($path)
{
$result = false;
if (is_readable($path)) {
$this->tpl_dir = $path;
$result = true;
}
return $result;
}
/**
* 获取视图模板目录
*
* @return string
*/
public function getScriptPath()
{
return $this->_tpl_dir;
}
}
... ...
该目录存放相关的服务器脚本
\ No newline at end of file
... ...
该目录存放相关数据库表结构
\ No newline at end of file
... ...
该目录存放相关的服务器配置
\ No newline at end of file
... ...
该目录用于存放前端相关的模板
\ No newline at end of file
... ...
存放相关的单元测试用例
\ No newline at end of file
... ...
有货WAP网站
\ No newline at end of file
... ...
<?php
/**
* 启动运行
*
* @name Bootstrap
* @author fei.hong
* @desc 所有在Bootstrap类中, 以_init开头的方法, 都会被Yaf调用,
* @see http://www.php.net/manual/en/class.yaf-bootstrap-abstract.php
* 这些方法, 都接受一个参数:Yaf_Dispatcher $dispatcher
* 调用的次序, 和申明的次序相同
*/
use Yaf\Bootstrap_Abstract;
use Yaf\Dispatcher;
use Yaf\Application;
use Yaf\Registry;
use Yaf\Loader;
use Yaf\Config;
use Plugin\TemplateLayout;
class Bootstrap extends Bootstrap_Abstract
{
private $_config;
/**
* 初始化配置
* @param Yaf_Dispatcher $dispatcher
*/
public function _initConfig(Dispatcher $dispatcher)
{
define('REQUEST_METHOD', strtoupper($dispatcher->getRequest()->getMethod()));
$this->_config = Application::app()->getConfig();
Registry::set('appConfig', $this->_config);
}
/**
* 初始化应用
* @param Yaf_Dispatcher $dispatcher
*/
public function _initApplication(Dispatcher $dispatcher)
{
defined('APPLICATION_SYSTEM_CONFIG') || define('APPLICATION_SYSTEM_CONFIG', $this->_config->application->servers->config);
if (APPLICATION_ENV !== 'production') {
error_reporting(E_ALL);
ini_set('display_startup_errors', 1);
ini_set('display_errors', 1);
}
Loader::getInstance()->registerLocalNameSpace(explode(',', $this->_config->application->namespaces));
}
/**
* 初始化插件
* @param Yaf_Dispatcher $dispatcher
*/
public function _initPlugin(Dispatcher $dispatcher)
{
}
/**
* 初始化路由
* @param Yaf_Dispatcher $dispatcher
*/
public function _initRoute(Dispatcher $dispatcher)
{
$config = new Config\Ini(APPLICATION_PATH . '/configs/routes.ini');
if (isset($config->routes)) {
$dispatcher->getRouter()->addConfig($config->routes);
}
}
/**
* 初始化Layout
* @param Yaf_Dispatcher $dispatcher
*/
public function _initLayout(Dispatcher $dispatcher)
{
// 判断到不是AJAX请求时, 使用自定义的模板渲染 (Mustache or Handlebars)
if (!$dispatcher->getRequest()->isXmlHttpRequest()) {
$layout = new TemplateLayout();
$layout->setScriptPath($this->_config->application->layout->path);
$dispatcher->setView($layout);
}
// 关闭自动渲染模板
else {
$dispatcher->autoRender(false);
}
}
/**
* 初始化第三方包
* @param Dispatcher $dispatcher
*/
public function _initPackage(Dispatcher $dispatcher)
{
if ($this->_config->composer->autoload == 1) {
require $this->_config->composer->path . '/vendor/autoload.php';
}
}
}
... ...
<?php
/**
* @name ErrorController
* @desc 错误控制器, 在发生未捕获的异常时刻被调用
* @see http://www.php.net/manual/en/yaf-dispatcher.catchexception.php
* @author liuziyang
*/
use Action\AbstractAction;
class ErrorController extends AbstractAction
{
public function errorAction($exception)
{
header('HTTP/1.1 404 Not Found');
header('Status: 404 Not Found');
exit();
}
public function notFoundAction()
{
header('HTTP/1.1 404 Not Found');
header('Status: 404 Not Found');
exit();
}
}
... ...
<?php
/**
* 会员账单
*/
class IndexController extends AbstractAction
{
public function indexAction()
{
echo 'hello world';
}
}
\ No newline at end of file
... ...
[common]
;;默认项目
application.directory = APPLICATION_PATH "/application"
;;website library
application.library = ROOT_PATH "/library"
;;默认模块
application.modules = "Default,Test"
;;加载
application.bootstrap = APPLICATION_PATH "/application/Bootstrap.php"
;;view文件的扩展名
application.view.ext = "phtml"
;;默认layouts
application.layout.path = APPLICATION_PATH "/application/layouts"
;;layouts 默认文件
application.layout.default = "default"
;;默认Controller
application.dispatcher.defaultController = "index"
;;默认Action
application.dispatcher.defaultAction = "index"
;;初始化命名空间
application.namespaces = "Action,Configs,Plugin"
;;使用composer
composer.autoload = 0
composer.path = APPLICATION_PATH "/library/Package"
yaf.use_namespace = 1
;;调试模式
application.debug = True
application.servers.config = APPLICATION_PATH "/configs/core"
;出错的时候是否抛出异常
application.dispatcher.throwException = True
;是否使用默认的异常 捕获Controller, 如果开启, 在有未捕获的异常的时候,
;控制权会交给ErrorController的errorAction 方法,
;可以通过$request->getException()获得此异常对象 False
application.dispatcher.catchException = True
;模板预编译目录,该目录需要有读写权限
application.template.compile = ROOT_PATH "/compile/m.yohobuy.com"
\ No newline at end of file
... ...
[common]
;;默认项目
application.directory = APPLICATION_PATH "/application"
;;website library
application.library = ROOT_PATH "/library"
;;默认模块
application.modules = "Default,Test"
;;加载
application.bootstrap = APPLICATION_PATH "/application/Bootstrap.php"
;;view文件的扩展名
application.view.ext = "phtml"
;;默认layouts
application.layout.path = APPLICATION_PATH "/application/layouts"
;;layouts 默认文件
application.layout.default = "default"
;;默认Controller
application.dispatcher.defaultController = "index"
;;默认Action
application.dispatcher.defaultAction = "index"
;;初始化命名空间
application.namespaces = "Action,Configs,Plugin"
;;使用composer
composer.autoload = 0
composer.path = APPLICATION_PATH "/library/Package"
yaf.use_namespace = 1
;;调试模式
application.debug = False
application.servers.config = APPLICATION_PATH "/configs/core"
;出错的时候是否抛出异常
application.dispatcher.throwException = False
;是否使用默认的异常 捕获Controller, 如果开启, 在有未捕获的异常的时候,
;控制权会交给ErrorController的errorAction 方法,
;可以通过$request->getException()获得此异常对象
application.dispatcher.catchException = False
;模板预编译目录,该目录需要有读写权限
application.template.compile = ROOT_PATH "/compile/m.yohobuy.com"
\ No newline at end of file
... ...
[common]
;;默认项目
application.directory = APPLICATION_PATH "/application"
;;website library
application.library = ROOT_PATH "/library"
;;默认模块
application.modules = "Default,Test"
;;加载
application.bootstrap = APPLICATION_PATH "/application/Bootstrap.php"
;;view文件的扩展名
application.view.ext = "phtml"
;;默认layouts
application.layout.path = APPLICATION_PATH "/application/layouts"
;;layouts 默认文件
application.layout.default = "default"
;;默认Controller
application.dispatcher.defaultController = "index"
;;默认Action
application.dispatcher.defaultAction = "index"
;;初始化命名空间
application.namespaces = "Action,Configs,Plugin"
;;使用composer
composer.autoload = 0
composer.path = APPLICATION_PATH "/library/Package"
yaf.use_namespace = 1
;;调试模式
application.debug = True
application.servers.config = APPLICATION_PATH "/configs/core"
;出错的时候是否抛出异常
application.dispatcher.throwException = True
;是否使用默认的异常 捕获Controller, 如果开启, 在有未捕获的异常的时候,
;控制权会交给ErrorController的errorAction 方法,
;可以通过$request->getException()获得此异常对象 False
application.dispatcher.catchException = True
;模板预编译目录,该目录需要有读写权限
application.template.compile = ROOT_PATH "/compile/m.yohobuy.com"
\ No newline at end of file
... ...
[common]
servers.host = 127.0.0.1:11211:90
[memcached:common]
servers.hosts = 127.0.0.1:11212:90,127.0.0.1:11213:10
[redis]
servers.hosts = 192.168.1.168:6379
\ No newline at end of file
... ...
[common]
servers.host = 127.0.0.1:11211:90
[memcached:common]
servers.hosts = 127.0.0.1:11212:90,127.0.0.1:11213:10
[redis]
servers.hosts = 127.0.0.1:6379
\ No newline at end of file
... ...
[common]
servers.host = 127.0.0.1:11211:90
[memcached:common]
servers.hosts = 127.0.0.1:11213
[redis]
servers.hosts = 127.0.0.1:6379
\ No newline at end of file
... ...
[mysql]
charset = UTF8
persistent = FALSE
collation = utf8_unicode_ci
timeout = 3
[database]
yhb_bill.username = yohodb
yhb_bill.passwd = yohonj_9646_mysql
yhb_bill.write = 123.56.86.219:5511
yhb_bill.read = 123.56.86.219:5511
\ No newline at end of file
... ...
[mysql]
charset = UTF8
persistent = FALSE
collation = utf8_unicode_ci
timeout = 3
[database]
yhb_bill.username = yohodb
yhb_bill.passwd = yohonj_9646_mysql
yhb_bill.write = 123.56.86.219:5511
yhb_bill.read = 123.56.86.219:5511
\ No newline at end of file
... ...
[mysql]
charset = UTF8
persistent = FALSE
collation = utf8_unicode_ci
timeout = 3
[database]
yhb_bill.username = yohodb
yhb_bill.passwd = yohonj_9646_mysql
yhb_bill.write = 10.170.183.158:5511
yhb_bill.read = 10.170.183.158:5511
\ No newline at end of file
... ...
; default
routes.index.type = "rewrite"
routes.index.match = "/(index|index.html)$"
routes.index.route.module = Default
routes.index.route.controller = Index
routes.index.route.action = Index
; error
routes.notfound.type = "rewrite"
routes.notfound.match = "/error.html"
routes.notfound.route.module = Default
routes.notfound.route.controller = Error
routes.notfound.route.action = notfound
\ No newline at end of file
... ...
<?xml version="1.0"?>
<cross-domain-policy>
<allow-access-from domain="*.yohobuy.com" />
</cross-domain-policy>
\ No newline at end of file
... ...
No preview for this file type
<?php
use Yaf\Application;
define('APPLICATION_PATH', dirname(__DIR__));
define('ROOT_PATH', dirname(dirname(APPLICATION_PATH)));
defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'developer');
$application = new Application(APPLICATION_PATH . '/configs/application.developer.ini');
$application->bootstrap()->run();
\ No newline at end of file
... ...
<?php
use Yaf\Application;
define('APPLICATION_PATH', dirname(__DIR__));
define('ROOT_PATH', dirname(dirname(APPLICATION_PATH)));
defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'testing');
$application = new Application(APPLICATION_PATH . '/configs/application.testing.ini');
$application->bootstrap()->run();
\ No newline at end of file
... ...
<?php
use Yaf\Application;
define('APPLICATION_PATH', dirname(__DIR__));
define('ROOT_PATH', dirname(dirname(APPLICATION_PATH)));
defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'production');
$application = new Application(APPLICATION_PATH . '/configs/application.production.ini');
$application->bootstrap()->run();
\ No newline at end of file
... ...
有货PC网站
\ No newline at end of file
... ...