コード例 #1
0
ファイル: Page.php プロジェクト: ryo88c/BEAR.Saturday
 /**
  * リソースリクエスト実行
  *
  * <pre>
  * htdocs/のページをリソースとして扱うクラスです。
  * readがページクラスのonInit()を呼び出しonInit内でsetされたものが結果になって帰ります。フォーマットはROです。
  * create, update, deleteはonAction()を呼び出します。
  *
  * $this->_config['options']に応じて次のどちらをpageリソースにするか決定されます。
  *
  *   1)pageが出力するHTML
  *   2)set()でセットされたリソース結果の集合
  * </pre>
  *
  * @return mixed
  * @throws BEAR_Exception
  */
 public function request()
 {
     $this->_setGetPost($this->_config['options']);
     $pageRawPath = substr($this->_config['uri'], 7);
     $url = parse_url($this->_config['uri']);
     $pageRawPath = $url['path'];
     $pageClass = 'page' . str_replace('/', '_', $pageRawPath);
     if (!class_exists($pageClass, false)) {
         $pageFile = str_replace('/', DIRECTORY_SEPARATOR, $pageRawPath) . '.php';
         BEAR_Main::includePage($pageFile);
     }
     if (!class_exists($pageClass, false)) {
         throw new BEAR_Exception("Page class[{$pageClass}] is not exist.");
     }
     $pageConfig = array('resource_id' => $pageClass, 'mode' => BEAR_Page::CONFIG_MODE_RESOURCE);
     $pageOptions = $this->_config['options'];
     if (isset($this->_config['options']['page'])) {
         $pageConfig = array_merge($pageConfig, (array) $this->_config['options']['page']);
     }
     if (isset($pageConfig['ua'])) {
         $pageConfig['enable_ua_sniffing'] = true;
     }
     $page = BEAR::factory($pageClass, $pageConfig, $pageOptions);
     $method = $this->_config['method'] === 'read' ? 'onInit' : 'onAction';
     $args = array_merge($page->getArgs(), $this->_config['values']);
     $cnt = $this->_roPrototye->countStack();
     $page->{$method}($args);
     $cnt = $this->_roPrototye->countStack() - $cnt;
     // リソースモード
     switch (true) {
         // resource
         case !isset($this->_config['options']['output']) || $this->_config['options']['output'] === 'resource':
             $result = $this->_outputResource($page, $cnt);
             break;
             // html
         // html
         case $this->_config['options']['output'] === 'html':
             $result = $this->_outputHtml($page);
             break;
         default:
             $info = array('output option' => $this->_config['options']['output']);
             throw $this->_exception('Unknown page resource options', compact('info'));
             break;
     }
     if (!$result instanceof BEAR_Ro) {
         $result = BEAR::factory('BEAR_Ro', array())->setBody($result);
     }
     return $result;
 }
コード例 #2
0
ファイル: Main.php プロジェクト: bearsaturday/bearsaturday
 /**
  * Inject multi UA
  *
  * @return void
  */
 public function onInjectUA()
 {
     // UA Sniffing
     BEAR_Main_Ua_Injector::inject($this, $this->_config);
     parent::onInject();
 }
コード例 #3
0
ファイル: Main.php プロジェクト: ryo88c/facebook_mock
 /**
  * インジェクト
  *
  * @return void
  */
 public function onInject()
 {
     // エージェントスニッフィング
     BEAR_Main_Ua_Injector::inject($this, $this->_config);
     parent::onInject();
 }
コード例 #4
0
ファイル: shell.php プロジェクト: ryo88c/BEAR.Saturday
     * @retun void
     */
    public function onOutput()
    {
        $this->output('ajax');
    }
    /**
     * bearシェルコマンド
     *
     * @param array $argv
     *
     * @return void
     */
    private function _shell(array $argv)
    {
        if (!isset($argv[1])) {
            $argv[1] = '--help';
        }
        $_SERVER['argv'] = $argv;
        $config = array('argv' => $argv, 'cli' => false);
        $shell = BEAR::dependency('BEAR_Dev_Shell', $config, true);
        $shell->execute();
        $display = $shell->getDisplay();
        $display = $display ? $display : 'Ok.';
        $buff = ob_get_clean();
        $result = '<pre>' . $display . $buff . '</pre>';
        $this->_ajax->addAjax('js', array('shell' => $result));
    }
}
BEAR_Main::run('Page_Shell');
コード例 #5
0
ファイル: Main.php プロジェクト: ryo88c/BEAR.Saturday
 /**
  * ページファイルのインクルード
  *
  * @param string $pageFile ページファイル
  *
  * @return void
  * @throws BEAR_Main_Exception
  */
 public static function includePage($pageFile)
 {
     self::$_isRunnable = false;
     $fullPathPageFile = _BEAR_APP_HOME . '/htdocs/' . $pageFile;
     if (!file_exists($fullPathPageFile)) {
         throw new BEAR_Main_Exception('Page file is not exit', array('info' => array('file' => $fullPathPageFile)));
     }
     include_once $fullPathPageFile;
     self::$_isRunnable = true;
 }