本文整理汇总了PHP中Yaf_Loader::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP Yaf_Loader::getInstance方法的具体用法?PHP Yaf_Loader::getInstance怎么用?PHP Yaf_Loader::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Yaf_Loader
的用法示例。
在下文中一共展示了Yaf_Loader::getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _initPlugin
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');
}
示例2: init
/**
* 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');
}
示例3: initContext
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;
}
示例4: initApp
/**
* 初始化APP的数据
*
* @param string $app 启用的app的名称,如:test
*/
private static function initApp($app)
{
if (empty($app)) {
return FALSE;
}
Ym_Timer::startRecord();
define('YPP_APP', $app);
define('YPP_APP_ROOT', YPP_DIR_APP . '/' . YPP_APP);
define('YPP_APP_LIB', YPP_APP_ROOT . '/library');
define('YPP_APP_LOG', YPP_DIR_LOG . '/' . YPP_APP);
// 声明loader,加载APP类文件
Yaf_Loader::getInstance(YPP_APP_LIB);
// 初始化配置
Ym_Config::init();
$env = Ym_Config::getAppItem('env:monitor.env');
if ($env) {
define('YPP_APP_ENV', $env);
} else {
define('YPP_APP_ENV', 'dev');
}
// 初始化日志
if (YPP_APP_ENV == 'pro') {
$logConf['levels'] = array('debug' => 1, 'warning' => 4, 'error' => 5, 'fatal' => 6, 'alert' => 7, 'emergency' => 8);
}
$logConf['logPath'] = YPP_APP_LOG;
$logConf['logFile'] = YPP_APP;
Ym_Logger::init($logConf);
//Ym_Logger::info('test');
// 加载application.ini
self::$app = new Yaf_Application(YPP_DIR_CONF . '/app/' . YPP_APP . '/application.ini');
}
示例5: initYafBySooh
/**
*
* @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;
}
示例6: init
/**
* 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();
}
示例7: _initLoader
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'));
}
示例8: routerStartup
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);
}
示例9: __construct
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);
}
示例10: bootstrap
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;
}
示例11: date_default_timezone_set
<?php
/**
* Yaf client command
*
* @author Xuexb<jeffxiaobo@foxmail.com>
* @package xiaobo/sh
* @since Version 1.0.1 @20140423
* @copyright Copyright (c) 2014, Yeahmobi, Inc.
*/
date_default_timezone_set('Asia/Shanghai');
define('YPP_APP', 'yeahmonitor');
define('YPP_APP_ROOT', YPP_DIR_APP . '/' . YPP_APP);
define('YPP_APP_LIB', YPP_APP_ROOT . '/library');
// 声明loader
Yaf_Loader::getInstance(YPP_APP_LIB, YPP_ROOT_PHPLIB);
// 初始化配置和日志类
Ym_Config::init();
$logConf['logPath'] = YPP_DIR_LOG . '/app/' . YPP_APP;
$logConf['logFile'] = YPP_APP;
Ym_Logger::init($logConf);
// 加载application.ini
$app = new Yaf_Application(YPP_DIR_CONF . '/app/' . YPP_APP . '/application.ini');
$app->bootstrap();
$app->getDispatcher()->dispatch(new Yaf_Request_Simple());
//方法2:不试用带module的模式
//$controller = isset($argv[1]) ? $argv[1] : '';
//$action = isset($argv[2]) ? $argv[2] : '';
//if (!$controller || !$action) {
// die('Please Use like this: /dianyi/app/ypp/bin/php yafClient.php controller action [argv]' . PHP_EOL);
//}
示例12: routerStartup
/**
* 路由开始事件
*
* @author mrmsl <msl-138@163.com>
* @date 2012-12-25 10:03:34
* @lastmodify 2013-01-21 15:28:59 by mrmsl
*
* @param object $request Yaf_Request_Http实例
* @param object $response Yaf_Response_Http实例
*
* @return void 无返回值
*/
public function routerStartup(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response)
{
Yaf_Loader::getInstance(LIB_PATH, LIB_PATH);
//注册项目及全局类库路径
Yaf_Dispatcher::getInstance()->disableView();
//禁用自动渲染模板输出
$this->_init();
}
示例13: init
/**
* method to control and navigate the user to the right view
*/
public function init()
{
$this->baseUrl = $this->getRequest()->getBaseUri();
Yaf_Loader::getInstance(APPLICATION_PATH . '/application/helpers')->registerLocalNamespace('Admin');
}
示例14: testCase037
/**
* @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());
}
}
示例15: _initBase
function _initBase(Yaf_Dispatcher $dispatcher)
{
// 如果非命令行,则输出 header 头
if (!core::is_cmd()) {
header("Expires: 0");
header("Cache-Control: private, post-check=0, pre-check=0, max-age=0");
header("Pragma: no-cache");
header('Content-Type: text/html; charset=UTF-8');
header('X-Powered-By: http://www.lianchuangbrothers.com/');
// 隐藏 PHP 版本 X-Powered-By: PHP/5.5.9
header('Server: Microsoft-IIS/11.11');
}
//错误处理
$dispatcher->setErrorHandler([get_class($this), 'error_handler']);
//添加路由协议
$dispatcher->getRouter()->addConfig((new Yaf_Config_Ini(APP_PATH . '/conf/routes.ini'))->routes);
//注册本地类
Yaf_Loader::getInstance()->registerLocalNameSpace(['helper', 'misc']);
// 加载数据库
Yaf_Registry::set('db', new medoo(Yaf_Registry::get("config")->get('database')->default->toArray()));
//memcache
//Yaf_Registry::set('memcache', new Memcache);
//Yaf_Registry::get('memcache')->pconnect(Yaf_Registry::get("config")->get('memcache')->default->host, Yaf_Registry::get("config")->get('memcache')->default->port, 2.5);
//redis
Yaf_Registry::set('redis', new redis());
//连接redis
Yaf_Registry::get('redis')->pconnect(Yaf_Registry::get("config")->get('redis')->default->host, Yaf_Registry::get("config")->get('redis')->default->port, 2.5);
//redis密码
Yaf_Registry::get('redis')->auth(Yaf_Registry::get("config")->get('redis')->default->password);
//使用php内置的serialize/unserialize 方法对数据进行处理
Yaf_Registry::get('redis')->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);
//rediskey加前缀
Yaf_Registry::get('redis')->setOption(Redis::OPT_PREFIX, Yaf_Registry::get("config")->get('redis')->default->prefix);
core::ob_start();
}