Exemple #1
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);
 }
 public function _initLocalName()
 {
     Loader::getInstance()->registerLocalNamespace(array('Smarty', 'Swift', 'Munee'));
 }
Exemple #3
0
 /**
  * Init namespaces
  */
 protected function _initNamespaces()
 {
     $namespaces = $this->_config->application->namespaces->toArray();
     \Yaf\Loader::getInstance()->registerLocalNameSpace($namespaces);
 }
#!/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();
 /**
  * 自定义逻辑加载类
  * @param Dispatcher $dispatcher
  */
 public function _initLoader(Dispatcher $dispatcher)
 {
     Loader::getInstance(rtrim(APPLICATION_PATH, '/'))->registerLocalNamespace('logic');
 }
Exemple #6
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;
 }
Exemple #7
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'));
 }
Exemple #9
0
 /**
  * @brief 注册app的本地命名空间
  *		  可以再注册自己的自动加载器
  * @param \Yaf\Dispatcher $dispatcher
  */
 public function _initLoader(\Yaf\Dispatcher $dispatcher)
 {
     \Yaf\Loader::getInstance()->registerLocalNameSpace($this->_arrLocalNameSpace);
 }
Exemple #10
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);