Esempio n. 1
0
 /**
  * @runInSeparateProcess
  */
 public function testCase02()
 {
     if (!defined('YAF_MODE')) {
         //@todo for some reason this need to b true to pass the test
         Yaf_G::iniSet('yaf.use_spl_autoload', true);
         Yaf_G::iniSet('yaf.lowcase_path', false);
     } else {
         ini_set('yaf.use_spl_autoload', false);
         ini_set('yaf.lowcase_path', false);
     }
     $this->assertEquals('CLI', $this->request->getMethod());
     $this->assertEquals('index', $this->request->getModuleName());
     $this->assertEquals('dummy', $this->request->getControllerName());
     $this->assertEquals('index', $this->request->getActionName());
     $this->assertFalse($this->request->isDispatched());
     $this->assertTrue($this->request->isRouted());
     $this->request->setParam('name', 'Laruence');
     $this->assertEquals('Laruence', $this->request->getParam('name'));
     $this->assertNull($this->request->getParam('non-exists'));
     $this->assertTrue($this->request->isCli());
     $app = new Yaf_Application(array("application" => array("directory" => dirname(__FILE__))));
     try {
         $app->getDispatcher()->dispatch($this->request);
         $this->fail('An Yaf_Exception_LoadFailed_Controller ' . 'exception was not throwed');
     } catch (Exception $e) {
         $this->assertEquals('Could not find controller script ' . dirname(__FILE__) . '/controllers/Dummy.php', $e->getMessage());
     }
 }
Esempio n. 2
0
 /**
  * @runInSeparateProcess
  */
 public function testCase042()
 {
     $config = array("application" => array("directory" => TEST_APPLICATION_PATH, "dispatcher" => array("catchException" => 0, "throwException" => 1), "modules" => "module"));
     $app = new Yaf_Application($config);
     include dirname(__FILE__) . '/_files/testCase042.php';
     $request = new Yaf_Request_Http("/module/controller/index");
     try {
         $app->getDispatcher()->returnResponse(false)->dispatch($request);
     } catch (Yaf_Exception $e) {
         $this->assertEquals('exception', $e->getMessage());
     }
 }
Esempio n. 3
0
 /**
  * @runInSeparateProcess
  */
 public function testCase031()
 {
     $config = array("application" => array("directory" => TEST_APPLICATION_PATH, "dispatcher" => array("defaultRoute" => array("type" => "map", "delimiter" => '##', "controllerPrefer" => 1))));
     $app = new Yaf_Application($config);
     $routes = $app->getDispatcher()->getRouter()->getRoutes();
     $this->assertTrue(isset($routes['_default']));
     $this->assertInstanceOf('Yaf_Route_Map', $routes['_default']);
 }
Esempio n. 4
0
/**
 * Yaf client command
 *
 * @author      Xuexb<*****@*****.**>
 * @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);
//}
//$argv = isset($argv[3]) ? $argv[3] : '';
//$res = $app->execute(array('Controller_' . $controller, $action . 'Action'), $argv);
Esempio n. 5
0
File: index.php Progetto: xn1224/YOF
<?php

/*
 *  WEB 的入口文件
 */
// 如果有 xhprof 则开启跟踪功能
if (function_exists('xhprof_enable')) {
    xhprof_enable(XHPROF_FLAGS_NO_BUILTINS | XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY);
}
header('content-Type:text/html;charset=utf-8;');
define('APP_PATH', realpath(dirname(__FILE__) . '/../'));
/*
 * 之所有要先包含 init.php 而不放在Bootstrap.php 里, 
 * 因为这样可以根据 ENV 来判断要不要抛出 YAF 本身的前置错误
 * 如配置出错了, 不包含 init.php 会一片空白, 包含了在 DEV 下则会抛出错误提示
 */
Yaf_Loader::import(APP_PATH . '/application/init.php');
$app = new Yaf_Application(APP_PATH . '/conf/application.ini');
// 以下设置为自定义错误处理, 但不要 NOTICE 错误
$app->getDispatcher()->throwException(FALSE)->setErrorHandler('yofErrorHandler', E_ALL ^ E_NOTICE);
$app->bootstrap()->run();
Esempio n. 6
0
<?php

//require bootstarap file, must .
require './www/bootstrap.php';
$yaf = new Yaf_Application(array('application' => array('directory' => ROOT_APP, 'modules' => '')));
$dispatcher = $yaf->getDispatcher();
$dispatcher->autoRender(FALSE);
$yaf->run();
Esempio n. 7
0
<?php

//php.ini 设置 yaf.use_spl_autoload=on
define("APP_PATH", dirname(__DIR__));
/* 指向public的上一级 */
if (!defined('SOOH_INDEX_FILE')) {
    define('SOOH_INDEX_FILE', 'index.php');
}
define('SOOH_ROUTE_VAR', '__');
error_log("-------------------------------------------------------tart:route=" . $_GET['__'] . " cmd=" . $_GET['cmd'] . " pid=" . getmypid());
include dirname(__DIR__) . '/conf/globals.php';
$ini = \Sooh\Base\Ini::getInstance();
$app = new Yaf_Application(APP_PATH . "/conf/application.ini");
$dispatcher = $app->getDispatcher();
if (!empty($reqeustReal)) {
    $dispatcher->setRequest($reqeustReal);
}
$view = \SoohYaf\SoohPlugin::initYafBySooh($dispatcher);
$dispatcher->returnResponse(TRUE);
try {
    $response = $app->run();
} catch (\ErrorException $e) {
    $view->assign('code', $e->getCode());
    $view->assign('msg', $e->getMessage());
    error_log("Error Caught at index.php:" . $e->getMessage() . "\n" . \Sooh\DB\Broker::lastCmd() . "\n" . $e->getTraceAsString() . "\n");
    $response = new Yaf_Response_Http();
    $response->setBody($view->render('ctrl/action.phtml'));
}
if ($ini->viewRenderType() === 'json') {
    header('Content-type: application/json');
}
Esempio n. 8
0
<?php

/**
 * php index.php request_uri="/swoole/server"
 * php index.php -cswoole -aserver
 */
ini_set('display_errors', 1);
error_reporting(E_ALL);
date_default_timezone_set('Asia/Shanghai');
define("APPLICATION_PATH", dirname(dirname(__FILE__)));
define("DEBUG_TOOLS", true);
if (DEBUG_TOOLS) {
    require_once APPLICATION_PATH . '/src/library/DebugTools.php';
    #DebugTools::startTimeMemory();
}
require_once APPLICATION_PATH . "/src/tools/hprose-php/Hprose.php";
require_once APPLICATION_PATH . "/src/tools/xapian/xapian.php";
$app = new Yaf_Application(APPLICATION_PATH . "/conf/application.ini");
$request = new Yaf_Request_Simple();
$opt = getopt("c:a:");
if (isset($opt['c']) && isset($opt['a'])) {
    $request->setRequestUri($opt['c'] . "/" . $opt['a']);
}
$app->getDispatcher()->dispatch($request);
if (DEBUG_TOOLS) {
    #DebugTools::useTimeMemory();
}
Esempio n. 9
0
<?php

/**
 * Created by PhpStorm.
 * User: gw
 * Date: 12/9/15
 * Time: 10:58 PM
 */
declare (strict_types=1);
ini_set('yaf.library', 'amie');
ini_set("yaf.action_prefer", '1');
define('APPLICATION_PATH', dirname(dirname(__FILE__)));
$application = new Yaf_Application(APPLICATION_PATH . "/conf/application.ini");
$dispatcher = $application->getDispatcher();
$route = new Yaf_Route_Simple('m', 'c', 'a');
$dispatcher->getRouter()->addRoute('simple', $route);
//?c=index&a=item&key1=abc&key2=123
var_dump($route->assemble(array(':a' => 'item', ':c' => 'index'), array('key1' => 'abc', 'key2' => '123')));
$request = new Yaf_Request_Http('?c=index&a=item&key1=abc&key2=123');
$dispatcher->getRouter()->route($request);
//$dispatcher->dispatch($request);
var_dump($dispatcher->getRouter()->getRoutes());
var_dump($dispatcher->getRouter()->getCurrentRoute());
Esempio n. 10
0
<?php

define('APPLICATION_PATH', dirname(__FILE__));
$application = new Yaf_Application(APPLICATION_PATH . "/conf/application.ini");
$application->getDispatcher()->throwException(FALSE);
$application->getDispatcher()->setErrorHandler("myErrorHandler");
$application->bootstrap()->run();
function myErrorHandler($errno, $errstr, $errfile, $errline)
{
    switch ($errno) {
        case YAF_ERR_NOTFOUND_CONTROLLER:
        case YAF_ERR_NOTFOUND_MODULE:
        case YAF_ERR_NOTFOUND_ACTION:
            header("Not Found");
            break;
        default:
            echo 'errno: ' . $errno . '<br>';
            echo 'errstr: ' . str_replace(APPLICATION_PATH, '[PATH]', $errstr) . '<br>';
            echo 'errfile: ' . str_replace(APPLICATION_PATH, '[PATH]', $errfile) . '<br>';
            echo 'errline: ' . $errline . '<br>';
            break;
    }
    return true;
}
Esempio n. 11
0
 /**
  * 启动程序
  *
  * @author          mrmsl <*****@*****.**>
  * @date            2013-01-22 15:06:16
  *
  * @return void 无返回值
  */
 public function bootstrap()
 {
     ob_get_level() != 0 && ob_end_clean();
     header('content-type: text/html; charset=utf-8');
     if (APP_DEBUG || !is_file(RUNTIME_FILE)) {
         $this->_buildRuntimeFile();
         if (APP_DEBUG && is_file(RUNTIME_FILE)) {
             unlink(RUNTIME_FILE);
         }
     } else {
         require RUNTIME_FILE;
     }
     $app = new Yaf_Application(CONF_FILE);
     $app->getDispatcher()->registerPlugin(new BootstrapPlugin());
     $app->bootstrap()->run();
 }
Esempio n. 12
0
 /**
  * @runInSeparateProcess
  */
 public function testCase041()
 {
     $config = array("application" => array("directory" => TEST_APPLICATION_PATH . 'application/', "dispatcher" => array("catchException" => 0, "throwException" => 1), "modules" => "module"));
     include dirname(__FILE__) . '/testCase041.php';
     $app = new Yaf_Application($config);
     $request = new Yaf_Request_Http("/module/controller/action");
     try {
         $app->getDispatcher()->returnResponse(false)->dispatch($request);
         $this->fail('Should raise an exception that the view template ' . 'modules/Testview/views/controller/action.phtml ' . 'is not found');
     } catch (Exception $e) {
         $this->assertEquals('Unable to find template ' . TEST_APPLICATION_PATH . 'application/modules/Module/views/' . 'controller/action.phtml', $e->getMessage());
     }
     $view = new Yaf_View_Simple(TEST_APPLICATION_PATH . 'no-exists');
     $app->getDispatcher()->setView($view);
     try {
         $app->getDispatcher()->returnResponse(false)->dispatch($request);
         $this->fail('Should raise an exception that the view template ' . 'no-exists/controller/action.phtml ' . 'is not found');
     } catch (Yaf_Exception $e) {
         $this->assertEquals('Unable to find template ' . TEST_APPLICATION_PATH . 'no-exists/controller/action.phtml', $e->getMessage());
     }
     $request = new Yaf_Request_Http("/module/controller/index");
     try {
         $app->getDispatcher()->returnResponse(false)->dispatch($request);
         $this->fail('Should raise an exception that the view template ' . 'no-exists/controller/dummy.phtml ' . 'is not found');
     } catch (Yaf_Exception $e) {
         $this->assertEquals('Unable to find template ' . TEST_APPLICATION_PATH . 'no-exists/controller/dummy.phtml', $e->getMessage());
     }
 }