示例#1
0
 /**
  * 加载路由设置
  * @param \Yaf\Dispatcher $dispatcher
  */
 public function _initRoute(Yaf\Dispatcher $dispatcher)
 {
     if (defined('CONFIG_PATH') && is_file(CONFIG_PATH . 'routing.ini')) {
         $config = new Yaf\Config\Ini(CONFIG_PATH . 'routing.ini');
         $dispatcher->getRouter()->addConfig($config);
     }
 }
示例#2
0
 public function _initLayout(Yaf\Dispatcher $dispatcher)
 {
     $event = $this->profiler->startEvent('Init layout');
     if (!$dispatcher->getRequest()->isXmlHttpRequest()) {
         $layout = new Layout($this->config->layout->dir);
         $dispatcher->setView($layout);
     } else {
         //
     }
     $this->profiler->endEvent($event);
 }
示例#3
0
 public function _initPlugin(Yaf\Dispatcher $dispatcher)
 {
     //开启debug控制台输出
     if (APP_DEBUG) {
         $dispatcher->registerPlugin(new DebugPlugin());
     }
     //开启布局支持
     $dispatcher->registerPlugin(new LayoutPlugin());
     //开启性能分析
     if (APP_ANALYZE && function_exists('xhprof_enable')) {
         $dispatcher->registerPlugin(new XhprofPlugin());
     }
 }
示例#4
0
 public function errorAction($exception)
 {
     $this->getView()->setLayout(null);
     // fallback views path to global when error occured in modules.
     $config = Yaf\Application::app()->getConfig();
     $this->getView()->setScriptPath($config->application->directory . "/views");
     $this->getView()->e = $exception;
     $this->getView()->e_class = get_class($exception);
     $this->getView()->e_string_trace = $exception->getTraceAsString();
     $params = $this->getRequest()->getParams();
     unset($params['exception']);
     $this->getView()->params = array_merge(array(), $params, $this->getRequest()->getPost(), $this->getRequest()->getQuery());
     eYaf\Logger::getLogger()->logException($exception);
     switch ($exception->getCode()) {
         case YAF\ERR\AUTOLOAD_FAILED:
         case YAF\ERR\NOTFOUND\MODULE:
         case YAF\ERR\NOTFOUND\CONTROLLER:
         case YAF\ERR\NOTFOUND\ACTION:
             header('HTTP/1.1 404 Not Found');
             break;
         case 401:
             $this->forward('Index', 'application', 'accessDenied');
             header('HTTP/1.1 401 Unauthorized');
             Yaf\Dispatcher::getInstance()->disableView();
             echo $this->render('accessdenied');
             break;
         default:
             header("HTTP/1.1 500 Internal Server Error");
             break;
     }
     eYaf\Logger::stopLogging();
 }
示例#5
0
文件: Error.php 项目: tkaven/biyeyuan
 public function errorAction(E $exception)
 {
     if (Registry::get('config')->environment != 'pro') {
         echo '<pre>';
         print_r($exception);
     }
     Yaf\Dispatcher::getInstance()->autoRender(false);
     switch ($exception->getCode()) {
         case \YAF\ERR\NOTFOUND\MODULE:
         case \YAF\ERR\NOTFOUND\CONTROLLER:
         case \YAF\ERR\NOTFOUND\ACTION:
         case \YAF\ERR\NOTFOUND\VIEW:
         case 404:
             header("Content-type: text/html; charset=utf-8");
             header("status: 404 Not Found");
             $this->display("404");
             break;
         default:
             header("Content-type: text/html; charset=utf-8");
             header("status: 500 Internal Server Error");
             if (Registry::get('config')->environment == 'pro') {
                 $this->display("500");
             } else {
                 echo $exception->getMessage();
             }
             break;
     }
 }
示例#6
0
文件: Bootstrap.php 项目: airzhe/yaf
 public function _initRouter($dispatcher)
 {
     $router = Yaf\Dispatcher::getInstance()->getRouter();
     #$route = new Yaf\Route\Simple("m", "c", "a");
     #$router->addRoute("name", $route);
     $route = new Yaf\Route\Regex('/\\/product\\/([a-zA-Z]+)/', ['controller' => 'index', 'action' => 'test'], [1 => 'ident']);
     $router->addRoute('product', $route);
 }
示例#7
0
 public function setUp()
 {
     $this->application = Yaf\Registry::get('Application');
     if ($this->application) {
         return;
     }
     $this->application = new Yaf\Application(APPLICATION_PATH . "/config/application.ini", APPLICATION_ENVIRONMENT);
     $this->application->bootstrap();
     Yaf\Registry::set('Application', $this->application);
     Yaf\Dispatcher::getInstance()->setView(PHPUnit_MockYafView::getInstance());
 }
示例#8
0
 public function _initHooks(Yaf\Dispatcher $dispatcher)
 {
     //注册Hooks
     $dispatcher->registerPlugin(new \Hook\RequestPlugin());
     $dispatcher->registerPlugin(new \Hook\AuthenticatePlugin());
     $dispatcher->registerPlugin(new \Hook\AuthorizePlugin());
     $dispatcher->registerPlugin(new \Hook\ApiRoutePlugin());
     $dispatcher->registerPlugin(new \Hook\ResponsePlugin());
     $dispatcher->registerPlugin(new \Hook\PostEventPlugin());
 }
示例#9
0
 public function _initView(Yaf\Dispatcher $dispatcher)
 {
     $view = new \SlatePF\Extras\ExtrasView();
     $path = $view->getScriptPath();
     // plain text TEST
     $view->on('txt', function ($file, $data) use($path) {
         return file_get_contents($path . $file) . ' THIS IS JUST A TEST';
     });
     // twig
     $view->on('twig', function ($file, $data) use($path) {
         $loader = new Twig_Loader_Filesystem($path);
         $twig = new Twig_Environment($loader);
         return $twig->loadTemplate($file)->render($data);
     });
     //protobuf
     $view->on('pb', function ($file, $data) use($path) {
         include $path . $file;
         exit;
     });
     $dispatcher->disableView();
     // disable auto-render
     $dispatcher->setView($view);
 }
示例#10
0
 public function _initRest(Yaf\Dispatcher $dispatcher)
 {
     $dispatcher->disableView();
     //如果不是cli就调用rest路由
     if (!$dispatcher->getRequest()->isCli()) {
         $router = $dispatcher->getRouter();
         $route = new RestRoute();
         $router->addRoute("rest", $route);
         //设置模板目录
         $view_engine = new Yaf\View\Simple(APPLICATION_PATH . '/application/views');
         $dispatcher->setView($view_engine);
         //启用权限控制插件
         $auth = new AuthPlugin();
         $dispatcher->registerPlugin($auth);
     } else {
         $command = new CommandLinePlugin();
         $dispatcher->registerPlugin($command);
     }
 }
示例#11
0
 public function _initView(Yaf\Dispatcher $dispatcher)
 {
     $view = new \views\wittyAdapter(\Yaf\Registry::get("config")->witty);
     $dispatcher->setView($view);
 }
示例#12
0
 public function _initPluginUser(Yaf\Dispatcher $dispatcher)
 {
     $system = new SystemPlugin();
     $dispatcher->registerPlugin($system);
 }
示例#13
0
 public function _initPlugin(Yaf\Dispatcher $dispatcher)
 {
     //注册一个插件
     $objSamplePlugin = new SamplePlugin();
     $dispatcher->registerPlugin($objSamplePlugin);
 }
示例#14
0
 public function updateAction($id)
 {
     $resource = $this->getResource($id);
     if (null === $resource) {
         return $this->forwardTo404();
     }
     $model = $this->get_model_name();
     if ($resource->updateAttributes($this->get_resource_params($model))) {
         $this->redirect($this->get_index_url());
         return false;
     } else {
         Yaf\Dispatcher::getInstance()->disableView();
         echo $this->render('edit', array('resource' => $resource, 'index_url' => $this->get_index_url()));
         return false;
     }
 }
 public function _initLayout(Yaf\Dispatcher $dispatcher)
 {
     $layout = new Layout($this->config->application->layout->directory);
     $dispatcher->setView($layout);
 }
示例#16
0
 public function getView()
 {
     return Yaf\Dispatcher::getInstance()->initView(APPLICATION_VIEWS);
 }
示例#17
0
文件: cli.php 项目: loncool/yaf-admin
<?php

/**
 * cli方式执行请求
 * eg:
 * php cli.php "request_uri=/index/index/testcli/p1/helloworld/p2/god" 
 */
define('APPLICATION_PATH', dirname(dirname(__FILE__)));
require APPLICATION_PATH . '/vendor/autoload.php';
$application = new Yaf\Application(APPLICATION_PATH . "/conf/application.ini");
$request = new Yaf\Request\Simple();
Yaf\Dispatcher::getInstance()->dispatch($request);
示例#18
0
文件: _init.php 项目: Yansor/yafblog
<?php

$dis = Yaf\Dispatcher::getInstance();
//Initialize Routes for Admin module
$routes = new Yaf\Config\Ini(__DIR__ . "/config" . "/routes.ini");
$dis->getRouter()->addConfig($routes->admin);
示例#19
0
 /**
  * Using twig as templating engine
  *
  * @param Yaf_Dispatcher $dispatcher
  */
 protected function _initView(Yaf\Dispatcher $dispatcher)
 {
     $view = new Cooltime\View\Twig(APPLICATION_PATH . "/application/views", Yaf\Application::app()->getConfig()->twig->toArray());
     $dispatcher->setView($view);
 }
示例#20
0
 /**
  * 初始化插件
  *
  * @param Yaf_Dispatcher $dispatcher
  */
 public function _initPlugin(Yaf\Dispatcher $dispatcher)
 {
     $site = new SitePlugin();
     $dispatcher->registerPlugin($site);
 }
示例#21
0
 /**
  * Get the current page from the request query string.
  *
  * @param  int  $total
  * @param  int  $per_page
  * @return int
  */
 public static function page($total, $per_page)
 {
     $query = Yaf\Dispatcher::getInstance()->getRequest()->getQuery();
     $page = isset($query['page']) ? (int) $query['page'] : 1;
     // The page will be validated and adjusted if it is less than one or greater
     // than the last page. For example, if the current page is not an integer or
     // less than one, one will be returned. If the current page is greater than
     // the last page, the last page will be returned.
     if (is_numeric($page) and $page > ($last = ceil($total / $per_page))) {
         return $last > 0 ? $last : 1;
     }
     return static::valid($page) ? $page : 1;
 }
示例#22
0
 public function _initConfig()
 {
     Yaf\Dispatcher::getInstance()->autoRender(FALSE);
     // 关闭自动加载模板
 }
示例#23
0
 /**
  * 加载插件
  * @param \Yaf\Dispatcher $dispatcher
  */
 public function _initPlugin(Yaf\Dispatcher $dispatcher)
 {
     $dispatcher->registerPlugin(new TplPlugin());
     $dispatcher->registerPlugin(new SystemPlugin());
 }
示例#24
0
 /**
  * 初始化模板引擎
  */
 public function _initView(Yaf\Dispatcher $dispatcher)
 {
     $dispatcher->disableView();
 }