Example #1
0
 public function _initSmarty(Yaf_Dispatcher $dispatcher)
 {
     /* init smarty view engine */
     Yaf_Loader::import("Smarty/Adapter.php");
     $smarty = new Smarty_Adapter(null, Yaf_Application::app()->getConfig()->smarty);
     $dispatcher->setView($smarty);
 }
 function _initPlugin(Yaf_Dispatcher $dispatcher)
 {
     Yaf_Loader::import('vendor/autoload.php');
     $dispatcher->registerPlugin(new Plugin_Init());
     $dispatcher->registerPlugin(new Plugin_Smarty());
     $dispatcher->registerPlugin(new LoginPlugin());
 }
Example #3
0
 private static function initContext()
 {
     // set timezone
     date_default_timezone_set('PRC');
     // page start time,use $_SERVER['REQUEST_TIME'] instead above PHP 5.4+
     define('REQUEST_TIME_US', intval(microtime(true) * 1000000));
     // ODP pre-defined
     define('IS_ODP', true);
     define('ROOT_PATH', realpath(dirname(__FILE__) . '/../../../'));
     define('CONF_PATH', ROOT_PATH . '/conf');
     define('DATA_PATH', ROOT_PATH . '/data');
     define('BIN_PATH', ROOT_PATH . '/php/bin');
     define('LOG_PATH', ROOT_PATH . '/log');
     define('APP_PATH', ROOT_PATH . '/app');
     define('TPL_PATH', ROOT_PATH . '/template');
     define('LIB_PATH', ROOT_PATH . '/php/phplib');
     define('WEB_ROOT', ROOT_PATH . '/webroot');
     define('PHP_EXEC', BIN_PATH . '/php');
     $app_name == null && ($app_name = self::getAppName()) == null && ($app_name = 'unknown-app');
     define('ODP_APP', $app_name);
     define('APP', ODP_APP);
     $loader = \Yaf_Loader::getInstance(null, LIB_PATH);
     //var_dump($loader);
     define('CLIENT_IP', \Odp\Ip::getClientIp());
     define('USER_IP', \Odp\Ip::getUserIp());
     define('FRONTEND_IP', \Odp\Ip::getFrontendIp());
     // init autoloader
     // todo PSR-4 autoloader
     return true;
 }
Example #4
0
 /**
  * 
  * @param \Yaf_Dispatcher $dispatcher
  * @param  string $jqueryVer 使用的jquery文件,默认值:jquery-1.11.2.min.js
  * @return view
  */
 public static function initYafBySooh($dispatcher, $jqueryVer = 'jquery-1.11.2.min.js')
 {
     $router = $dispatcher->getRouter();
     $router->addRoute("byVar", new \Yaf_Route_Supervar(SOOH_ROUTE_VAR));
     \Yaf_Loader::getInstance()->registerLocalNameSpace($GLOBALS['CONF']['localLibs']);
     $req = $dispatcher->getRequest();
     $tmp = $req->get('__ONLY__');
     if ($tmp == 'body') {
         \SoohYaf\Viewext::$bodyonly = true;
     }
     $tmp = trim($req->get('__VIEW__'));
     //html(default),wap,  json
     define('VIW_INC_PATH', APP_PATH . '/application/views/_inc/');
     \SoohYaf\Viewext::$jqueryVer = $jqueryVer;
     if (!empty($tmp)) {
         $tmp = strtolower($tmp);
         \Sooh\Base\Ini::getInstance()->viewRenderType($tmp);
         if ($tmp == 'jsonp') {
             \Sooh\Base\Ini::getInstance()->initGobal(array('nameJsonP' => $req->get('jsonp', 'jsonp')));
         }
     }
     //		$tmp = $dispatcher->getRequest()->get('__GZIP__');
     //		if(!empty($tmp)){
     //			$tmp = strtolower ($tmp);
     //			if($tmp=='gzip')define("ZIP_OUTPUT",$tmp);
     //		}
     $view = new \SoohYaf\Viewext(null);
     $dispatcher->setView($view);
     $dispatcher->registerPlugin(new SoohPlugin());
     return $view;
 }
Example #5
0
 /**
  * 开启调试输出
  * @method _initDebug
  * @author NewFuture
  */
 public function _initDebug()
 {
     if (Config::get('isdebug')) {
         /*加载 PHP Console Debug模块*/
         Yaf_Loader::import('PhpConsole/__autoload.php');
         $connector = PhpConsole\Connector::getInstance();
         if ($connector->isActiveClient()) {
             Log::write('PHP Console 已经链接', 'INFO');
             $handler = PhpConsole\Handler::getInstance();
             $dispatcher = $connector->getDebugDispatcher();
             $handler->start();
             $connector->setSourcesBasePath(APP_PATH);
             $connector->setServerEncoding('utf8');
             $dispatcher->detectTraceAndSource = true;
             //跟踪信息
             if ($pwd = Config::get('debug.auth')) {
                 $connector->setPassword($pwd);
                 $evalProvider = $connector->getEvalDispatcher()->getEvalProvider();
                 // $evalProvider->disableFileAccessByOpenBaseDir();             // means disable functions like include(), require(), file_get_contents() & etc
                 // $evalProvider->addSharedVar('uri', $_SERVER['REQUEST_URI']); // so you can access $_SERVER['REQUEST_URI'] just as $uri in terminal
                 // $evalProvider->addSharedVarReference('post', $_POST);
                 $connector->startEvalRequestsListener();
             }
         }
         PhpConsole\Helper::register();
     }
 }
Example #6
0
 /**
  * 函数名称:_initBase
  * 功能描述:引入基础base类
  */
 public function _initBase()
 {
     Yaf_Loader::import(BASE_PATH . '/BaseAdminController.php');
     Yaf_Loader::import(BASE_PATH . '/BaseIndexController.php');
     Yaf_Loader::import(BASE_PATH . '/BaseAdminModel.php');
     Yaf_Loader::import(BASE_PATH . '/BaseIndexModel.php');
 }
Example #7
0
 /**
  * [路由设置]
  */
 public function _initRoutes(Yaf_Dispatcher $dispatcher)
 {
     $router = $dispatcher->getRouter();
     //$router->addConfig(Yaf_Registry::get('config')->routes);
     Yaf_Loader::import(APP_CONFIG . '/route.php');
     $router->addConfig($routeConfigs);
 }
Example #8
0
 public function __construct()
 {
     $config = Yaf_Application::app()->getConfig();
     Yaf_Loader::import('L_Wechat');
     $options = array('token' => self::WX_TOKEN, 'appid' => $config['wx_appID'], 'appsecret' => $config['wx_appsecret'], 'access_token' => $config['wx_access_token'], 'expires' => $config['wx_expires']);
     $this->wxSDK = new L_Wechat($options);
 }
Example #9
0
 public function _initCore()
 {
     define('TB_PREFIX', 'zt_');
     define('APP_NAME', 'YOF-DEMO');
     define('LIB_PATH', APP_PATH . '/application/library');
     define('MODEL_PATH', APP_PATH . '/application/model');
     define('FUNC_PATH', APP_PATH . '/application/function');
     define('ADMIN_PATH', APP_PATH . '/application/modules/Admin');
     // CSS, JS, IMG PATH
     define('CSS_PATH', '/css');
     define('JS_PATH', '/js');
     define('IMG_PATH', '/img');
     // Admin CSS, JS PATH
     define('ADMIN_CSS_PATH', '/admin/css');
     define('ADMIN_JS_PATH', '/admin/js');
     Yaf_Loader::import('M_Model.pdo.php');
     Yaf_Loader::import('Helper.class.php');
     Helper::import('Basic');
     Helper::import('Network');
     Yaf_Loader::import('C_Basic.php');
     Yaf_Loader::import(LIB_PATH . '/yar/Yar_Basic.php');
     // header.html and left.html
     define('HEADER_HTML', APP_PATH . '/public/common/header.html');
     define('LEFT_HTML', APP_PATH . '/public/common/left.html');
     // API KEY for api sign
     define('API_KEY', 'THIS_is_OUR_API_keY');
 }
Example #10
0
 /**
  * method to control and navigate the user to the right view
  */
 public function init()
 {
     if (APPLICATION_ENV === 'prod') {
         // TODO: set the branch through config
         $branch = 'production';
         if (file_exists(APPLICATION_PATH . '/.git/refs/heads/' . $branch)) {
             $this->commit = rtrim(file_get_contents(APPLICATION_PATH . '/.git/refs/heads/' . $branch), "\n");
         } else {
             $this->commit = md5(date('ymd'));
         }
     } else {
         $this->commit = md5(time());
     }
     $this->baseUrl = $this->getRequest()->getBaseUri();
     $this->addCss($this->baseUrl . '/css/bootstrap.min.css');
     $this->addCss($this->baseUrl . '/css/bootstrap-datetimepicker.min.css');
     $this->addCss($this->baseUrl . '/css/bootstrap-switch.css');
     $this->addCss($this->baseUrl . '/css/bootstrap-multiselect.css');
     $this->addCss($this->baseUrl . '/css/jsoneditor.css');
     $this->addCss($this->baseUrl . '/css/main.css');
     $this->addJs($this->baseUrl . '/js/vendor/bootstrap.min.js');
     $this->addJs($this->baseUrl . '/js/plugins.js');
     $this->addJs($this->baseUrl . '/js/moment.js');
     $this->addJs($this->baseUrl . '/js/bootstrap-datetimepicker.min.js');
     $this->addJs($this->baseUrl . '/js/jquery.jsoneditor.js');
     $this->addJs($this->baseUrl . '/js/bootstrap-multiselect.js');
     $this->addJs($this->baseUrl . '/js/bootstrap-switch.js');
     $this->addJs($this->baseUrl . '/js/jquery.csv-0.71.min.js');
     $this->addJs($this->baseUrl . '/js/main.js');
     Yaf_Loader::getInstance(APPLICATION_PATH . '/application/helpers')->registerLocalNamespace('Admin');
 }
Example #11
0
 public function _initCore()
 {
     define('TB_PK', 'id');
     // 表的主键, 用于 SelectByID 等
     define('TB_PREFIX', 'zt_');
     // 表前缀
     define('APP_NAME', 'YOF-DEMO');
     define('LIB_PATH', APP_PATH . '/application/library/');
     define('MODEL_PATH', APP_PATH . '/application/model');
     define('FUNC_PATH', APP_PATH . '/application/function');
     define('ADMIN_PATH', APP_PATH . '/application/modules/Admin');
     // CSS, JS, IMG PATH
     define('CSS_PATH', '/css');
     define('JS_PATH', '/js');
     define('IMG_PATH', '/img');
     // Admin CSS, JS PATH
     define('ADMIN_CSS_PATH', '/admin/css');
     define('ADMIN_JS_PATH', '/admin/js');
     // 设置自动加载的目录
     ini_set('yaf.library', LIB_PATH);
     // 导入 F_Basic.php 与 F_Network.php
     Helper::import('Basic');
     Helper::import('Network');
     Yaf_Loader::import('C_Basic.php');
     Yaf_Loader::import(LIB_PATH . '/yar/Yar_Basic.php');
     // header.html and left.html
     define('HEADER_HTML', APP_PATH . '/public/common/header.html');
     define('LEFT_HTML', APP_PATH . '/public/common/left.html');
     // API KEY for api sign
     define('API_KEY', 'THIS_is_OUR_API_keY');
 }
Example #12
0
 public function _initPlugin(Yaf_Dispatcher $dispatcher)
 {
     // set include paths of the system.
     set_include_path(get_include_path() . PATH_SEPARATOR . Yaf_Loader::getInstance()->getLibraryPath());
     /* register a billrun plugin system from config */
     $config = Yaf_Application::app()->getConfig();
     if (isset($config->plugins)) {
         $plugins = $config->plugins->toArray();
         $dispatcher = Billrun_Dispatcher::getInstance();
         foreach ($plugins as $plugin) {
             Billrun_Log::getInstance()->log("Load plugin " . $plugin, Zend_log::DEBUG);
             $dispatcher->attach(new $plugin());
         }
     }
     if (isset($config->chains)) {
         $chains = $config->chains->toArray();
         $dispatcherChain = Billrun_Dispatcher::getInstance(array('type' => 'chain'));
         foreach ($chains as $chain) {
             Billrun_Log::getInstance()->log("Load plugin " . $chain, Zend_log::DEBUG);
             $dispatcherChain->attach(new $chain());
         }
     }
     // make the base action auto load (required by controllers actions)
     Yaf_Loader::getInstance(APPLICATION_PATH . '/application/helpers')->registerLocalNamespace('Action');
 }
Example #13
0
 public function __construct()
 {
     $config = Yaf_Application::app()->getConfig();
     Yaf_Loader::import('L_Wechat.class.php');
     $options = array('token' => $config['wx_token'], 'appid' => $config['wx_appID'], 'appsecret' => $config['wx_appSecret']);
     $this->wxSDK = new L_Wechat($options);
 }
Example #14
0
 public function _initConfig(\Yaf_Dispatcher $dispatcher)
 {
     /*{{{*/
     $this->config = Yaf_Application::app()->getConfig()->toArray();
     Yaf_Registry::set('configarr', $this->config);
     // 加载默认定义
     \Yaf_Loader::import(APP_PATH . '/conf/defines.inc.php');
 }
Example #15
0
 function __construct()
 {
     Yaf_Loader::import('qiniu/io.php');
     Yaf_Loader::import('qiniu/rs.php');
     Yaf_Loader::import('qiniu/config.php');
     $this->bucket = $bucket;
     $this->accessKey = $accessKey;
     $this->secretKey = $secretKey;
 }
Example #16
0
 function __construct()
 {
     Yaf_Loader::import('qiniu/io.php');
     Yaf_Loader::import('qiniu/rs.php');
     $config = Yaf_Application::app()->getConfig();
     $this->bucket = $config['qiniu_bucket'];
     $this->accessKey = $config['qiniu_accessKey'];
     $this->secretKey = $config['qiniu_secretKey'];
 }
Example #17
0
 public static function autoload($class)
 {
     if (strpos($class, 'Builder') === strlen($class) - 7) {
         Yaf_Loader::import(sprintf('%s/application/views/builder/%s.php', APPLICATION_PATH, $class));
     } else {
         if (strpos($class, 'Halo') === 0) {
             Yaf_Loader::import(sprintf('%s/library/halo/%s.php', APPLICATION_PATH, $class));
         }
     }
 }
Example #18
0
 public static function loadEssentials()
 {
     Yaf_Loader::import(sprintf('%s/yaf/YafController.php', LIB_PATH));
     Yaf_Loader::import(sprintf('%s/yaf/YafDebug.php', LIB_PATH));
     Yaf_Loader::import(sprintf('%s/yaf/YafView.php', LIB_PATH));
     Yaf_Loader::import(sprintf('%s/yaf/LocalAutoLoader.php', LIB_PATH));
     Yaf_Loader::import(sprintf('%s/yaf/yar.php', LIB_PATH));
     Yaf_Loader::import(sprintf('%s/yaf/YafController.php', LIB_PATH));
     LocalAutoLoader::register();
 }
Example #19
0
 /**
  * initialize method for yaf controller (instead of constructor)
  */
 public function init()
 {
     // all output will be store at class output class
     $this->output = new stdClass();
     $this->getView()->output = $this->output;
     // set the actions autoloader
     Yaf_Loader::getInstance(APPLICATION_PATH . '/application/helpers')->registerLocalNamespace("Action");
     $this->setActions();
     $this->setOutputMethod();
 }
Example #20
0
 public static function getInstance()
 {
     if (!self::$instance) {
         $file_system = Yaf_Registry::get('config')->file->file_system;
         if (!empty($file_system) && file_exists(dirname(__FILE__) . '/' . $file_system . '.php')) {
             Yaf_Loader::import(dirname(__FILE__) . '/' . $file_system . '.php');
             self::$instance = new $file_system();
         }
     }
     return self::$instance;
 }
Example #21
0
 /**
  * 构造方法
  *
  * @return void
  */
 protected function __construct()
 {
     \Yaf_Loader::import(APP_PATH . 'library/Thirdpart/Smarty/libs/Smarty.class.php');
     $this->_smarty = new \Smarty();
     $this->_smarty->setTemplateDir('');
     $this->_smarty->setCompileDir(TMP_PATH . 'smarty-compile/');
     $this->_smarty->setCacheDir(TMP_PATH . 'smarty-cache/');
     $this->_smarty->setPluginsDir(APP_PATH . 'library/Smarty/Plugins/');
     $this->_smarty->left_delimiter = '<!--{';
     $this->_smarty->right_delimiter = '}-->';
     $this->_smarty->enableSecurity('Comm\\Smarty_Security_Policy');
 }
Example #22
0
 public function _initCore()
 {
     // 设置自动加载的目录
     ini_set('yaf.library', LIB_PATH);
     // 加载核心组件
     Yaf_Loader::import(CORE_PATH . '/BasicController.php');
     Yaf_Loader::import(CORE_PATH . '/Helper.php');
     Yaf_Loader::import(CORE_PATH . '/Model.php');
     Yaf_Loader::import(CORE_PATH . '/Rdb.php');
     // 导入 FunctionBasic.php
     Yaf_Loader::import(FUNC_PATH . '/FunctionBasic.php');
 }
Example #23
0
 public function _initLoader(Yaf_Dispatcher $dispatcher)
 {
     //        echo 'aaaa';
     //        exit;
     $autoload = Yaf_Loader::getInstance();
     $autoload->registerLocalNameSpace(array("Foo", "Bar"));
     //$autoload->autoload('Foo_Dummy_Bar');
     $a = new Foo\Dummy\Bar();
     //$a->abc();
     //        echo 'aaaa';
     //        exit;
     //var_dump(class_exists('Foo_Dummy_Bar'));
 }
Example #24
0
 public function _initCore()
 {
     // 设置自动加载的目录
     ini_set('yaf.library', LIB_PATH);
     // 加载核心组件
     Yaf_Loader::import(CORE_PATH . '/C_Basic.php');
     Yaf_Loader::import(CORE_PATH . '/Helper.php');
     Yaf_Loader::import(CORE_PATH . '/Model.php');
     Yaf_Loader::import(LIB_PATH . '/yar/Yar_Basic.php');
     // 导入 F_Basic.php 与 F_Network.php
     Helper::import('Basic');
     Helper::import('Network');
 }
Example #25
0
 public static function getInstance()
 {
     if (!self::$instance) {
         $caching_system = Yaf_Registry::get('config')->cache->caching_system;
         if (!empty($caching_system) && file_exists(dirname(__FILE__) . '/' . $caching_system . '.php')) {
             Yaf_Loader::import(dirname(__FILE__) . '/' . $caching_system . '.php');
             self::$instance = new $caching_system();
             self::$instance->blacklist = Yaf_Registry::get('cache_exclude_table');
             if (!defined('CACHE_KEY_PREFIX')) {
                 define('CACHE_KEY_PREFIX', 'cye_');
             }
         }
     }
     return self::$instance;
 }
Example #26
0
 public function _initAutoLoad()
 {
     spl_autoload_register(function ($className) {
         $items = explode('_', $className);
         $layer = strtolower(array_shift($items));
         $filename = array_pop($items) . '.php';
         $filePath = strtolower(implode('/', $items));
         $filePath = YPP_APP_ROOT . '/' . $layer . 's/' . $filePath . '/' . $filename;
         if (is_file($filePath)) {
             Yaf_Loader::import($filePath);
             return true;
         }
         return false;
     });
 }
Example #27
0
 public function routerStartup(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response)
 {
     $this->config = Yaf_Application::app()->getConfig();
     $this->fileload = Yaf_Loader::getInstance();
     if (isset($this->config->application->autolibrary) && !empty($this->config->application->autolibrary)) {
         $autoclass = explode(',', $this->config->application->autolibrary);
         foreach ($autoclass as $v) {
             if (is_dir(APPLICATION_PATH . '/' . $v)) {
                 $this->getlist(APPLICATION_PATH . '/' . $v, 'class');
             } else {
                 throw new Exception(APPLICATION_PATH . '/' . $v . '不是目录');
             }
         }
     }
     $this->fileload->setLibraryPath(APPLICATION_PATH . '/library', true);
 }
Example #28
0
 /**
  * @runInSeparateProcess
  */
 public function testCase037()
 {
     //ini_set('open_basedir', '.');
     //unfortunately setting open_basedir will make
     //phpunit to not work
     $globalDir = '/tmp/';
     if (!defined('YAF_MODE')) {
         Yaf_G::iniSet('yaf.library', $globalDir);
         Yaf_G::iniSet('yaf.lowcase_path', false);
     } else {
         ini_set('yaf.library', $globalDir);
         ini_set('yaf.lowcase_path', false);
     }
     $this->loader = Yaf_Loader::getInstance('/tmp');
     $this->loader->import("/tmp/1.php");
     try {
         $this->loader->autoload("Foo_Bar");
     } catch (PHPUnit_Framework_Error_Warning $e) {
         $this->assertContains('Could not find script /tmp/Foo/Bar.php', $e->getMessage());
     }
 }
Example #29
0
 public function __construct()
 {
     $rpc_dir = dirname(dirname(__DIR__)) . "/thrift";
     $yaf_load = Yaf_Loader::getInstance();
     $yaf_load->setLibraryPath($rpc_dir, true);
     require_once $rpc_dir . "/Thrift/ClassLoader/ThriftClassLoader.php";
     $loader = new Thrift\ClassLoader\ThriftClassLoader();
     $loader->registerNamespace('Thrift', $rpc_dir);
     $loader->registerNamespace('swoole', $rpc_dir);
     $loader->registerNamespace('Bin', $rpc_dir);
     $loader->registerDefinition('Bin', $rpc_dir);
     $loader->register();
     $config_obj = Yaf_Registry::get("config");
     $rpc_config = $config_obj->rpc->toArray();
     $socket = new Thrift\Transport\TSocket($rpc_config['host'], $rpc_config['port']);
     $this->transport = new Thrift\Transport\TFramedTransport($socket);
     $protocol = new Thrift\Protocol\TBinaryProtocol($this->transport);
     $this->transport->open();
     $this->client = new Bin\rpc\rpcClient($protocol);
     //$yaf_load->setLibraryPath(dirname($rpc_dir).'/library',true);
 }
Example #30
0
 public function bootstrap()
 {
     $bootstrapClass = Yaf_Bootstrap_Abstract::YAF_DEFAULT_BOOTSTRAP;
     if (isset($this->_options['bootstrap'])) {
         $bootstrap = $this->_options['bootstrap'];
     } else {
         $bootstrap = $this->getAppDirectory() . DIRECTORY_SEPARATOR . $bootstrapClass . '.' . Yaf_G::get('ext');
     }
     $loader = Yaf_Loader::getInstance();
     if (Yaf_Loader::import($bootstrap)) {
         if (!class_exists($bootstrapClass)) {
             throw new Yaf_Exception('Couldn\'t find class Bootstrap in ' . $bootstrap);
         } else {
             $bootstrap = new $bootstrapClass();
             if (!$bootstrap instanceof Yaf_Bootstrap_Abstract) {
                 throw new Yaf_Exception('Expect a Yaf_Bootstrap_Abstract instance, ' . get_class($bootstrap) . ' give ');
             }
             if (version_compare(PHP_VERSION, '5.2.6') === -1) {
                 $class = new ReflectionObject($bootstrap);
                 $classMethods = $class->getMethods();
                 $methodNames = array();
                 foreach ($classMethods as $method) {
                     $methodNames[] = $method->getName();
                 }
             } else {
                 $methodNames = get_class_methods($bootstrap);
             }
             $initMethodLength = strlen(Yaf_Bootstrap_Abstract::YAF_BOOTSTRAP_INITFUNC_PREFIX);
             foreach ($methodNames as $method) {
                 if ($initMethodLength < strlen($method) && Yaf_Bootstrap_Abstract::YAF_BOOTSTRAP_INITFUNC_PREFIX === substr($method, 0, $initMethodLength)) {
                     $bootstrap->{$method}($this->_dispatcher);
                 }
             }
         }
     } else {
         throw new Yaf_Exception('Couldn\'t find bootstrap file ' . $bootstrap);
     }
     return $this;
 }