示例#1
0
 /**
  * 设置application
  */
 public function setApplication()
 {
     $application = null;
     define('APPLICATION_NOT_RUN', true);
     Loader::import(APPLICATION_PATH . 'public/index.php');
     Registry::set('application', $application);
 }
示例#2
0
 /**
  * Initialize locate library.
  * @param \Yaf\Dispatcher $dispatcher
  * @return void
  */
 public function _initLibrary(\Yaf\Dispatcher $dispatcher)
 {
     //注册本地类前缀
     $namespace = $dispatcher->config->application->library->localnamespace;
     $namespace = explode(',', $namespace);
     \Yaf\Loader::getInstance()->registerLocalNamespace($namespace);
 }
示例#3
0
 function _initPlugin(Dispatcher $dispatcher)
 {
     Loader::import('vendor/autoload.php');
     $dispatcher->registerPlugin(new PHPConfig());
     $dispatcher->registerPlugin(new LoginPlugin());
     $dispatcher->registerPlugin(new Module(array(Module::TYPE_CLI => array('enable' => true))));
 }
示例#4
0
 /**
  * 导入模块下lib目录下的文件
  *
  * @access public
  * @param string $class_name 包含命名空间的类名称
  * @return bool|void
  */
 public static function lib($class_name)
 {
     if (class_exists($class_name, false)) {
         return true;
     }
     return InternalLoader::import(ROOT_PATH . DS . APP_NAME . DS . 'modules' . DS . $class_name . ".php");
 }
示例#5
0
 public function init($yaf_app)
 {
     static $initialized = false;
     if (!$initialized) {
         $initialized = true;
         \Yaf\Loader::import(YK_CORE_ROOT . '/func.php');
         $config = $yaf_app->getConfig()->toArray();
         \Yaf\Registry::set('_config', $config);
         $level = $config['debug'] ? $config['debug'] == 1 ? E_ERROR : E_ALL : 0;
         define('MAIN_DEBUG', $config['debug']);
         if (MAIN_DEBUG) {
             ini_set('display_error', 'On');
         }
         error_reporting($level);
         define('TIMESTAMP', time());
         \Yaf\Registry::set('_clientip', isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'N/A');
         \Yaf\Registry::set('_clientport', isset($_SERVER['REMOTE_PORT']) ? $_SERVER['REMOTE_PORT'] : 0);
         \Yaf\Registry::set('_gzip', !isset($_SERVER['HTTP_ACCEPT_ENCODING']) || strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') === false || !function_exists('ob_gzhandler') ? false : true);
         set_timeoffset($config['timeoffset']);
         //重置视图
         $view = new view();
         \Yaf\Registry::set('_view', $view);
         $yaf_app->getDispatcher()->setView($view);
         define('CHARSET', 'utf-8');
         //end
     }
 }
示例#6
0
 /**
  * setup yaf
  */
 private function __setUpYafApplication()
 {
     $this->__setUpPHPIniVariables();
     // Import application and bootstrap.
     \Yaf\Loader::import(dirname(__DIR__) . '/public/index.php');
     $this->__setUpApplicationInit();
     \Yaf\Dispatcher::getInstance()->registerPlugin(new \YafUnit\Plugin\View());
     \Yaf\Registry::set('ApplicationInit', true);
 }
示例#7
0
 public function muneeAction()
 {
     // Define webroot
     define('WEBROOT', APPLICATION_PATH . "/public");
     // Include munee.phar
     Loader::import("Munee/autoload.php");
     //Error
     ob_clean();
     // Echo out the response
     echo \Munee\Dispatcher::run(new \Munee\Request(array('css' => array('lessifyAllCss' => false), 'image' => array('checkReferrer' => false))));
     die;
 }
示例#8
0
 /**
  * 加载函数目录
  */
 public function _initFunction(\Yaf\Dispatcher $dispatcher)
 {
     $import_function = $this->config->get('application.function');
     if ($import_function) {
         $import_function = explode(',', $import_function);
         foreach ($import_function as $item) {
             $item = trim($item);
             $file = CORE_LIB_PATH . '/function/' . $item . '.php';
             if (!is_file($file)) {
                 continue;
             }
             \Yaf\Loader::import($file);
         }
     }
 }
示例#9
0
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 14/11/26
 * Time: 下午2:48
 */
namespace Smarty;

use Yaf\View_Interface;
use Yaf\Loader;
Loader::import("Smarty/libs/Smarty.class.php");
Loader::import("Smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php");
Loader::import("Smarty/libs/sysplugins/smarty_internal_templatelexer.php");
Loader::import("Smarty/libs/sysplugins/smarty_internal_templateparser.php");
Loader::import("Smarty/libs/sysplugins/smarty_internal_compilebase.php");
Loader::import("Smarty/libs/sysplugins/smarty_internal_write_file.php");
class Adapter implements View_Interface
{
    /**
     * Smarty object
     * @var Smarty
     */
    public $_smarty;
    /**
     * smarty插件入口
     *
     * @param null $tmplPath
     * @param array $extraParams
     * @throws Exception
     * @throws \SmartyException
     */
示例#10
0
<?php

/**
 * 命令行执行PHP 入口
 * @author Lancer He <*****@*****.**>
 */
set_time_limit(0);
ini_set('memory_limit', '256M');
// define it for not auto running.
// like testcase, so that we can depand cli argv to choose which controller run it.
define('APPLICATION_NOT_RUN', true);
// Import application and bootstrap.
\Yaf\Loader::import(dirname(__FILE__) . '/../public/index.php');
// Init a request for cli mode, Like
//      php ./application/Cli.php "request_uri=/cli/crontab/sendmailtorepayment"
//          module:cli, controller:crontab, action:sendMailToPayment
//      php ./application/Cli.php "request_uri=/cli/daemon/backup"
//          module:cli, controller:daemon, action:backup
$request = new \Yaf\Request\Simple();
// route uri => request
\Yaf\Dispatcher::getInstance()->getRouter()->route($request);
// dispatch this request
\Yaf\Dispatcher::getInstance()->dispatch($request);
示例#11
0
 /**
  * 自定义逻辑加载类
  * @param Dispatcher $dispatcher
  */
 public function _initLoader(Dispatcher $dispatcher)
 {
     Loader::getInstance(rtrim(APPLICATION_PATH, '/'))->registerLocalNamespace('logic');
 }
示例#12
0
 /**
  * @brief 注册app的本地命名空间
  *		  可以再注册自己的自动加载器
  * @param \Yaf\Dispatcher $dispatcher
  */
 public function _initLoader(\Yaf\Dispatcher $dispatcher)
 {
     \Yaf\Loader::getInstance()->registerLocalNameSpace($this->_arrLocalNameSpace);
 }
示例#13
0
 /**
  * 公用函数载入
  */
 public function _initFunction()
 {
     \Yaf\Loader::import('Common/functions.php');
 }
示例#14
0
 /**
  * 数据合法性检查
  */
 protected function validate()
 {
     try {
         // 读取校验文件
         $module = MODULES_NAME;
         $controller = CONTROLLER_NAME . 'Form';
         $action = ACTION_NAME . 'Rules';
         // 数据校验
         Loader::import(APPLICATION_PATH . "modules/{$module}/validates/{$controller}.php");
         $rules = $controller::$action();
         return Validate::validity($rules);
     } catch (\Security\FormException $e) {
         // ajax输出
         IS_AJAX and $this->jsonp([$rules[$e->getCode()][0] => $e->getMessage()], 412);
         // 页面输出
         $this->view(['notify' => $e->getMessage()], 'common/notify', TRUE);
         exit;
     }
 }
示例#15
0
 public function _initUtil(\Yaf\Dispatcher $dispatcher)
 {
     \Yaf\Loader::import('Common/Util.php');
 }
示例#16
0
 /**
  * call api
  *
  * @throws Exception
  */
 function call()
 {
     $validResponseFormat = array('json', 'jsonp', 'html', 'text', 'javascript', 'mixed');
     $responseFormat = $this->responseFormat;
     $responseFormatError = false;
     if (!in_array($responseFormat, $validResponseFormat)) {
         $this->responseFormat = 'text';
         $responseFormatError = true;
     }
     if ($this->responseFormat === 'json') {
         if (!isset($this->contentType)) {
             $this->contentType = 'Content-type: application/json; charset=utf-8';
         }
     } elseif ($this->responseFormat === 'html') {
         if (!isset($this->contentType)) {
             $this->contentType = 'Content-type: text/html; charset=utf-8';
         }
     } elseif ($this->responseFormat === 'text') {
         if (!isset($this->contentType)) {
             $this->contentType = 'Content-type: text/plain; charset=utf-8';
         }
     } elseif ($this->responseFormat === 'jsonp') {
         if (!isset($this->contentType)) {
             $this->contentType = 'Content-Type: application/javascript; charset=utf-8';
         }
     } elseif ($this->responseFormat === 'javascript') {
         if (!isset($this->contentType)) {
             $this->contentType = 'Content-Type: application/javascript; charset=utf-8';
         }
     }
     if ($responseFormatError) {
         return 'unknown response format "' . $responseFormat . '"';
     }
     header($this->contentType);
     $method = $this->method;
     if (false === strpos($method, '.')) {
         $this->method .= '.index';
     }
     list($className, $methodNameOri) = explode('.', $this->method);
     if (empty($className) || empty($methodNameOri)) {
         $errorMessage = 'method is invliad, method=' . $method;
         throw new ApiException($errorMessage, ApiException::ERROR_METHOD);
     }
     $className = str_replace('_', '\\', $className);
     $className = explode('\\', $className);
     foreach ($className as &$v) {
         $v = ucfirst($v);
     }
     $className = implode('\\', $className) . 'Model';
     $prefix = 'Api';
     if (!empty($this->module)) {
         $prefix .= '\\' . $this->module;
     }
     if (!empty($this->version)) {
         $prefix .= '\\' . str_replace('.', 'd', ucfirst($this->version));
     }
     $classNameFix = $prefix . '\\Fix\\' . $className;
     $classNameAction = $prefix . '\\Action\\' . $className;
     $loader = Loader::getInstance();
     if ($loader->autoload($classNameFix)) {
         $api = $classNameFix::getInstance();
     } elseif ($loader->autoload($classNameAction)) {
         $api = $classNameAction::getInstance();
     }
     $methodName = '_api' . ucfirst($methodNameOri);
     if (!isset($api) || !is_callable(array($api, $methodName))) {
         $errorMessage = 'method not found, method=' . $method;
         throw new ApiException($errorMessage, ApiException::ERROR_METHOD);
     }
     $api->setParamAll($this->param);
     $api->apiInit();
     $res = $api->{$methodName}();
     return $res;
 }
示例#17
0
 public function _initSmarty(Dispatcher $dispatcher)
 {
     Loader::import("smarty/Adapter.php");
     $smarty = new Smarty_Adapter(null, Registry::get("config")->get("smarty")->get("index"));
     Registry::set("Smarty", $smarty);
     $dispatcher->setView($smarty);
 }
#!/usr/bin/env /opt/install/php/bin/php
<?php 
namespace Bin;

use Yaf\Loader as InternalLoader;
declare (ticks=1);
$loader = InternalLoader::getInstance(realpath(dirname(dirname(__FILE__))), ini_get('yaf.library'));
$loader->registerLocalNamespace(array('Bin'));
spl_autoload_register(array($loader, 'autoload'));
// load worker configure file for command line
// path to beanstalk-config.ini
$config_dir = "beanstalk-config.ini";
$configArray = parse_ini_file($config_dir, true);
// todo  alternative loader beanstalkd-config.ini here
$mgr = new WorkerBeanstalkManager($loader);
$mgr->run();
示例#19
0
 public function _initLocalName()
 {
     /** we put class Smarty_Adapter under the local library directory */
     \Yaf\Loader::getInstance()->registerLocalNamespace('Smarty');
 }
 /**
  * 注册本地类
  */
 public function _initRegisterLocalNamespace()
 {
     Loader::getInstance()->registerLocalNamespace(array('Zend', 'Ku'));
 }
示例#21
0
 function _initAutoload(Dispatcher $dispatcher)
 {
     Loader::import('vendor/autoload.php');
 }
示例#22
0
 /**
  * Init namespaces
  */
 protected function _initNamespaces()
 {
     $namespaces = $this->_config->application->namespaces->toArray();
     \Yaf\Loader::getInstance()->registerLocalNameSpace($namespaces);
 }
示例#23
0
文件: cli.php 项目: vzina/yaf-api
#!/usr/bin/env php
<?php 
/**
 * 命令行执行PHP 入口
 * php ./app/cli.php "/crontab/sendmailt?a=1&b=c"
 * php ./app/cli.php "/{控制器名}/{方法名}?{参数}"
 */
set_time_limit(0);
ini_set('memory_limit', '256M');
// define it for not auto running.
// like testcase, so that we can depand cli argv to choose which controller run it.
define('APPLICATION_NOT_RUN', true);
// Import application and bootstrap.
\Yaf\Loader::import(dirname(__DIR__) . '/public/index.php');
$request = new \Yaf\Request\Simple();
// parse cli
global $argc, $argv;
if ($argc > 1) {
    $module = '';
    $uri = $argv[1];
    if (preg_match('/^[^?]*%/i', $uri)) {
        list($module, $uri) = explode('%', $uri, 2);
    }
    $module = strtolower($module);
    $modules = \Yaf\Application::app()->getModules();
    if (in_array(ucfirst($module), $modules)) {
        $request->setModuleName($module);
    }
    if (false === strpos($uri, '?')) {
        $args = array();
    } else {
示例#24
0
 public function _initHelper()
 {
     Loader::import(APP_PATH . 'helper' . DS . 'functions.php');
 }
示例#25
0
<?php

// Define path to application directory
defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
// Define application environment
define('APPLICATION_ENV', 'testing');
// Starting application
$app = new \Yaf\Application(APPLICATION_PATH . "/configs/application.ini");
// Running bootstrap
//$app->bootstrap();
$config = $app->getConfig();
$namespaces = $config->application->namespaces->toArray();
\Yaf\Loader::getInstance()->registerLocalNameSpace($namespaces);