public function setUp() { restore_error_handler(); if (!BEAR::exists('BEAR_Session')) { BEAR::set('BEAR_Session', BEAR::factory('BEAR_Session', array('adapter' => 0, 'prefix' => ''))); } $this->_token = new BEAR_Form_Token(array()); $this->_token->onInject(); }
public static function onAutoload($class) { static $growlApp; BEAR::onAutoload($class); $ref = new ReflectionClass($class); $file = $ref->getFileName(); if (!$growlApp) { $growlApp = new Net_Growl_Application(__CLASS__, array("Growl_Notify")); } $growl = Net_Growl::singleton($growlApp, null, null); $growl->setNotificationLimit(16); if (BEAR::exists($class)) { $config = BEAR::get($class)->getConfig(); } $growl->notify("Growl_Notify", $class, $class); }
/** * プロファイリングストップ * * プロファイラーリンクの表示します * * @param int $type 0:xhprof 1:xh gui * * @return void */ public static function stop($type = 0) { $xhprof_data = xhprof_disable(); $isAjax = BEAR::dependency('BEAR_Page_Ajax')->isAjaxRequest(); if ($isAjax === true || PHP_SAPI === 'cli') { return; } $xhprofRuns = new XHProfRuns_Default(); if (BEAR::exists('app')) { $app = BEAR::get('app'); $appName = $app['core']['info']['id']; } else { $appName = 'bear.app'; } $baseHref = self::$_profilerInfo[$type]['href']; $runId = $xhprofRuns->save_run($xhprof_data, $appName); $href = "{$baseHref}/index.php?run={$runId}&source={$appName}"; $link = '<br><a style="padding: 3px; background-color: red; color: white; font-family:'; $link .= 'Verdana; font-style: normal; font-variant: normal; font-weight: bold; font-size: 8pt;'; $link .= ' " name="" target="_blank" href="' . $href . '"">' . self::$_profilerInfo[$type]['label'] . '</a>'; echo $link; }
/** * リソーステンプレートに適用さたHTML文字列を取得 * * @param mixed $body リソースボディ * * @return string */ protected function _getHtml($body) { if (BEAR::exists('App_Main')) { $enableUaSniffing = BEAR::dependency('App_Main')->getConfig('enable_ua_sniffing'); } else { $enableUaSniffing = false; } if ($enableUaSniffing === true) { $fullPath = BEAR::dependency('BEAR_Agent')->getRoleFile(_BEAR_APP_HOME . $this->_config['path'] . 'elements', $this->_config['request']['options']['template'], 'tpl'); } else { $fullPath = _BEAR_APP_HOME . $this->_config['path'] . 'elements/' . $this->_config['request']['options']['template'] . '.tpl'; } if (realpath($fullPath)) { $smarty = BEAR::dependency('BEAR_Smarty'); $smarty->assign('body', $body); $result = $smarty->fetch($fullPath); } else { $errorMsg = "Invalid template path [{$fullPath}]"; trigger_error($errorMsg, E_USER_WARNING); // __toStringでは例外NG if ($this->_config['debug']) { $result = '<span style="border: 1px solid red;">' . $errorMsg . '</span>'; } } return $result; }
/** * HTML表示 * * onInit()でセットされたリソース結果をHTML出力します。 * * @param string $tplName テンプレート名 * @param array $options オプション * * @return void * @internal $this->_config['mode']がself::CONFIG_MODE_HTMLでないときはunit test用にHTTP出力されません。 */ public function display($tplName = null, array $options = array()) { if (BEAR::exists('pager')) { $pager = (array) BEAR::get('pager'); $this->set('pager', $pager); } $this->_pageRo = $this->_viewAdapter()->display($tplName, $options); // add page BEAR_Page_Hedaers header $pageHeaders = (array) BEAR::dependency('BEAR_Page_Header')->getHeaders(); $roHeaders = $this->_pageRo->getHeaders(); $headers = array_merge($roHeaders, $pageHeaders); $this->_pageRo->setHeaders($headers); $this->_outputHttp($this->_pageRo); }
/** * リソースリクエスト * * @return BEAR_Ro * @throws Exception Ro内部で発生した例外 */ public function request() { $uri = $this->_config['uri']; $values = $this->_config['values']; $options = $this->_config['options']; // URIのクエリーと$valuesをmerge $parse = parse_url($uri); if (!isset($parse['scheme'])) { $this->_mergeQuery($uri, $values); } $isNotRead = $this->_config['method'] !== BEAR_Resource::METHOD_READ; if (!$isNotRead) { $hasCsrfOption = false; } elseif (isset($options[BEAR_Resource::OPTION_CSRF]) && $options[BEAR_Resource::OPTION_CSRF] === true) { // リソースリクエストオプション $hasCsrfOption = true; } elseif ($this->_config[BEAR_Resource::OPTION_CSRF] === true) { // yaml $hasCsrfOption = true; } else { $hasCsrfOption = false; } if (!$isNotRead) { $hasPoeOption = false; } elseif (isset($options[BEAR_Resource::OPTION_POE]) && $options[BEAR_Resource::OPTION_POE] === true) { // リソースリクエストオプション $hasPoeOption = true; } elseif ($this->_config[BEAR_Resource::OPTION_POE] === true) { // yaml $hasPoeOption = true; } else { $hasPoeOption = false; } if ($hasCsrfOption || $hasPoeOption) { $formToken = BEAR::dependency('BEAR_Form_Token'); /* @var $formToken BEAR_Form_Token */ $isTokenCsrfValid = $hasCsrfOption ? $formToken->isTokenCsrfValid() : true; if ($isTokenCsrfValid !== true) { throw $this->_exception('CSRF'); } $isTokenPoeValid = $hasPoeOption ? $formToken->isTokenPoeValid() : true; if ($isTokenPoeValid !== true) { $headers = array('request config' => $this->_config, 'msg' => 'invalid token'); $code = BEAR::CODE_BAD_REQUEST; $config = compact('headers', 'code'); $ro = BEAR::factory('BEAR_Ro', $config); $ro->setConfig('uri', $uri); $ro->setConfig('values', $values); $ro->setConfig('options', $options); return $ro; } else { $formToken->newSessionToken(); } } $config = $this->_config; $config['uri'] = $uri; $config['values'] = $values; $resourceRequestCache = BEAR::factory('BEAR_Resource_Request_Cache', $config); try { $ro = $resourceRequestCache->request(); // 中で例外が発生しなかったらPOEオプションで使ったトークンを使用済みにマークする // @todo staticコールを廃止 // BEAR_Form::finishTokens(); /* @todo 下のifブロックを置き換える $isOkRo = ($ro instanceof BEAR_Ro && $ro->getCode() === BEAR::CODE_OK); $isNotRo = ($ro instanceof BEAR_Ro === false); if (!$isOkRo && $isNotRo) { $body = $ro; $ro = BEAR::factory('BEAR_Ro'); $ro->setBody($body); } */ if ($ro instanceof BEAR_Ro && $ro->getCode() === BEAR::CODE_OK) { // $options ポストプロセスクラス } elseif ($ro instanceof BEAR_Ro === false) { $body = $ro; $ro = BEAR::factory('BEAR_Ro'); $ro->setBody($body); } $request = "{$this->_config['method']} {$uri}" . ($values ? '?' . http_build_query($values) : ''); self::_actionPostProcess($ro); } catch (Exception $e) { if (get_class($e) === 'Panda_Exception') { // HTTPエラー画面 Panda::onException($e); throw $e; } if (BEAR::exists('page')) { $page = BEAR::get('page'); if (method_exists($page, 'onException')) { $page->onException($e); } } if ($this->_config['debug']) { $info = method_exists($e, 'getInfo') ? $e->getInfo() : ''; Panda::error(get_class($e), $e->getCode() . ' ' . $e->getMessage(), $info); } //エラー (400=bad requset, or 500=server error $trace = $e->getTrace(); $refTrace =& $trace; $trace = array_shift($refTrace); if (isset($trace['args'])) { $args = $trace['args']; } else { $args = ''; } $headers = array(); $exception = array('class' => get_class($e), 'msg' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine()); $headers['_exception'] = $exception; if (method_exists($e, 'getInfo')) { $headers['_info'] = $e->getInfo(); } $ro = BEAR::factory('BEAR_Ro'); $ro->setHeaders($headers)->setCode($e->getCode()); } if ($this->_config['debug']) { BEAR::dependency('BEAR_Ro_Debug', $this->_config)->debugShowResource($ro); } return $ro; }
/** * ページャーリンクの登録 * * ページャーリンクのHTMLとメタ情報を'pager'というキーでサービスに登録します。 * 登録済みの場合は何もしません。 * * @param array $links * @param array $info * * @return BEAR_Pager */ public function setPagerLinks(array $links, array $info) { if (!BEAR::exists('pager')) { BEAR::set('pager', new ArrayObject(array('links' => $links, 'info' => $info))); } return $this; }