当前位置: 首页>>代码示例>>PHP>>正文


PHP Request::factory方法代码示例

本文整理汇总了PHP中Request::factory方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::factory方法的具体用法?PHP Request::factory怎么用?PHP Request::factory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Request的用法示例。


在下文中一共展示了Request::factory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: response

 public static function response(Exception $e)
 {
     // get the response
     $response = parent::response($e);
     //  Log the Exception,
     Kohana_Exception::log($e);
     if (Kohana::DEVELOPMENT !== Kohana::$environment) {
         try {
             // fire error subrequest
             // directly output result
             echo Request::factory(Route::get('error')->uri(array('controller' => 'error', 'action' => 'view')))->post('exception', $e)->execute()->send_headers()->body();
             exit;
         } catch (Exception $e) {
             // Clean the output buffer if one exists
             ob_get_level() and ob_clean();
             // Display the exception text
             echo parent::text($e);
             // Exit with an error status
             exit;
         }
     }
     // end all output buffering
     $ob = ob_get_level();
     for ($i = 0; $i < $ob; $i++) {
         ob_end_clean();
     }
     // return the response as usual
     return $response;
 }
开发者ID:yubinchen18,项目名称:A-basic-website-project-for-a-company-using-the-MVC-pattern-in-Kohana-framework,代码行数:29,代码来源:Exception.php

示例2: find_product_url

 public function find_product_url($product_name)
 {
     $url = 'http://ek.ua/';
     $data = array('search_' => $product_name);
     $response = Request::factory($url)->query($data)->execute();
     //echo Debug::vars($response->body());
     //echo Debug::vars($response->headers());
     $response = $response->body();
     try {
         $doc = phpQuery::newDocument($response);
     } catch (Exception $ex) {
         $errors[] = $ex->getMessage();
         echo Debug::vars($errors);
     }
     if (!isset($errors)) {
         /* Нужно взять заголовок и найти в нем слово найдено */
         /*
          * что я заметил, удивительно но на разных машинах этот заголовои идет с разным классом
          * на данный момент этот класс oth
          */
         $str = $doc->find('h1.oth')->html();
         if (preg_match('/найдено/', $str)) {
             echo Debug::vars('алилуя !!!');
             die;
         }
         return $str;
     }
 }
开发者ID:bruhanda,项目名称:parser,代码行数:28,代码来源:Parser.php

示例3: getResponse

 private static function getResponse($aURL) {
     Retio_Bitly::$_cacheKey = Retio_Bitly::CACHE_PREFIX . substr(md5(Retio_Bitly::$_url), 0, 10) .'_'. Retio_Bitly::$_action;
     
     $data                   = Kohana::cache(Retio_Bitly::$_cacheKey);
     if ($data === NULL) {
         try {
             $rData   = Request::factory($aURL)->execute()->body();
             
             switch (Retio_Bitly::$_config->format) {
                 case 'json':
                     $object = json_decode($rData);
                     $data   = ($object->status_code === 200) ? $object->data : NULL;
                 break;
                 case 'xml':
                     $object = simplexml_load_string($rData);
                     $data   = ($object->status_code === 200) ? $object->data : NULL;
                 break;
                 case 'txt':
                     $data = trim($rData);
                 break;
             }
             
             if ($data != NULL)
                 Kohana::cache(Retio_Bitly::$_cacheKey, $data, Retio_Bitly::CACHE_TIME);
             
         } catch (Exception $e) {
             return FALSE;
         }
     }
     return $data;
 }
开发者ID:retio,项目名称:Retio-Bitly,代码行数:31,代码来源:bitly.php

示例4: keys

 /**
  * Returns a list of keys matching the pattern
  *
  * @param   string $pattern
  * @return  string
  */
 public static function keys($pattern)
 {
     if (is_array($pattern)) {
         $pattern = implode(' ', $pattern);
     }
     $lKey = Config::get('re_prefix') . 'keys:' . sha1($pattern);
     if (!R::factory()->exists($lKey)) {
         foreach (R::factory()->keys($pattern) as $key) {
             R::factory()->rPush($lKey, $key);
         }
         R::factory()->expire($lKey, Config::get('re_store_time'));
     }
     $start = (Request::factory()->getPage() - 1) * Config::get('re_limit');
     $end = $start + Config::get('re_limit');
     $keys = array();
     foreach (R::factory()->lRange($lKey, $start, $end) as $key) {
         $data = array('key' => $key, 'type' => Helper_Keys::getType($key), 'value' => Helper_Keys::getValue($key, Helper_Keys::getType($key)), 'ttl' => R::factory()->ttl($key));
         // Remove deleted keys from cache
         if ($data['type'] == 'not_found') {
             R::factory()->lRem($lKey, $key, 0);
         }
         $keys[] = $data;
     }
     $total = R::factory()->lSize($lKey);
     $dataUrl = array('cmd' => Request::factory()->getCmd(), 'db' => Request::factory()->getDb());
     $url = '/?' . http_build_query($dataUrl) . '&page=:id:';
     $paginator = Paginator::parsePaginator($total, Request::factory()->getPage(), $url, Config::get('re_limit'));
     $data = array('db' => Request::factory()->getDb(), 'paginator' => $paginator, 'keys' => $keys, 'cmd' => Request::factory()->getCmd(), 'cache' => $lKey);
     return View::factory('tables/keys', $data);
 }
开发者ID:xingcuntian,项目名称:readmin,代码行数:36,代码来源:Keys.php

示例5: handler

 public static function handler(Exception $e)
 {
     if (Kohana::$environment !== Kohana::PRODUCTION) {
         parent::handler($e);
     } else {
         try {
             //not saving 404 as error
             if ($e->getCode() != 404) {
                 Kohana::$log->add(Log::ERROR, parent::text($e));
             }
             $params = array('action' => 500, 'origuri' => rawurlencode(Arr::get($_SERVER, 'REQUEST_URI')), 'message' => rawurlencode($e->getMessage()));
             if ($e instanceof HTTP_Exception) {
                 $params['action'] = $e->getCode();
             }
             //d($params);
             // Error sub-request.
             echo Request::factory(Route::get('error')->uri($params))->execute()->send_headers()->body();
         } catch (Exception $e) {
             // Clean the output buffer if one exists
             ob_get_level() and ob_clean();
             // Display the exception text
             echo parent::text($e);
             // Exit with an error status
             exit(1);
         }
     }
 }
开发者ID:Wildboard,项目名称:WbWebApp,代码行数:27,代码来源:exception.php

示例6: doRequest

 public function doRequest($request)
 {
     $_COOKIE = $request->getCookies();
     $_SERVER = $request->getServer();
     $_FILES = $this->remapFiles($request->getFiles());
     $uri = str_replace('http://localhost', '', $request->getUri());
     $_SERVER['KOHANA_ENV'] = 'testing';
     $_SERVER['REQUEST_METHOD'] = strtoupper($request->getMethod());
     $_SERVER['REQUEST_URI'] = strtoupper($uri);
     $this->_initRequest();
     $kohanaRequest = \Request::factory($uri);
     $kohanaRequest->method($_SERVER['REQUEST_METHOD']);
     if (strtoupper($request->getMethod()) == 'GET') {
         $kohanaRequest->query($this->remapRequestParameters($request->getParameters()));
     }
     if (strtoupper($request->getMethod()) == 'POST') {
         $kohanaRequest->post($this->remapRequestParameters($request->getParameters()));
     }
     $kohanaRequest->cookie($_COOKIE);
     $kohanaRequest::$initial = $kohanaRequest;
     $content = $kohanaRequest->execute()->render();
     $headers = (array) $kohanaRequest->response()->headers();
     $headers['Content-type'] = "text/html; charset=UTF-8";
     $response = new Response($content, 200, $headers);
     return $response;
 }
开发者ID:itillawarra,项目名称:cmfive,代码行数:26,代码来源:Kohana.php

示例7: get_access_token

 /**
  * Получение access token для авторизации
  * @return bool
  * @throws Kohana_Exception
  */
 private function get_access_token()
 {
     $params = Arr::get($_SERVER, 'QUERY_STRING');
     parse_str($params, $params);
     if (empty($params['code'])) {
         Controller::redirect($this->login_query());
     }
     if (!$params) {
         # TODO: Throw custom Exception for VK
         throw new Kohana_Exception('NO QUERY PARAMS');
     }
     if (isset($error)) {
         # TODO: Throw custom Exception for VK
         throw new Kohana_Exception('Error: ' . $error . ' Description: ' . $error_description);
     }
     $params = array('client_id' => self::$config['APP_ID'], 'code' => $params['code'], 'client_secret' => self::$config['APP_SECRET'], 'redirect_uri' => self::$config['REDIRECT_URI']);
     $resp = Request::factory(self::$config['GET_TOKEN_URI'])->method('GET')->query($params)->execute();
     $resp = json_decode($resp);
     if (empty($resp->access_token)) {
         # TODO: Throw custom Exception for VK
         throw new Kohana_Exception('Error: ' . $resp->error . ' Description: ' . $resp->error_description);
     }
     Session::instance()->set('vk_token', $resp->access_token);
     Session::instance()->set('vk_user_id', $resp->user_id);
     return true;
 }
开发者ID:Kapitonova,项目名称:codex,代码行数:31,代码来源:Vkontakte.php

示例8: handlers

 public static function handlers(Exception $e)
 {
     die;
     if (stripos(get_class($e), 'Smarty')) {
         echo 'Smarty Found';
     }
     if (Kohana::DEVELOPMENT === Kohana::$environment) {
         parent::handler($e);
     } else {
         try {
             Kohana::$log->add(Log::ERROR, parent::text($e));
             $attributes = array('code' => 500, 'e' => rawurlencode($e->getMessage()));
             if ($e instanceof HTTP_Exception) {
                 $attributes['code'] = $e->getCode();
             }
             // Error sub-request.
             echo Request::factory(Route::get('error')->uri($attributes))->execute()->send_headers()->body();
         } catch (Exception $e) {
             // Clean the output buffer if one exists
             ob_get_level() and ob_clean();
             // Display the exception text
             echo parent::text($e);
             // Exit with an error status
             exit(1);
         }
     }
 }
开发者ID:astar3086,项目名称:studio_logistic,代码行数:27,代码来源:exception.php

示例9: response

 /**
  * Attempt to query error/500 manually, as we cannot catch exceptions through traditional HMVC requests.
  * Catch potential exceptions such as database is down and display a lightweight error message.
  *
  * @param Exception $e
  * @return Response
  */
 public static function response(Exception $e)
 {
     if (Kohana::$environment >= Kohana::DEVELOPMENT) {
         return parent::response($e);
     }
     try {
         // Create the request, we need to set controller and action manual as they
         // otherwise gets set in execute method.
         $request = Request::factory();
         $request->controller(Kohana_Exception::$_controller);
         $request->action(Kohana_Exception::$_method);
         // Setup the response object
         $response = Response::factory();
         $response->status(500);
         $response->headers('Content-Type', Kohana_Exception::$error_view_content_type . '; charset=' . Kohana::$charset);
         // Call the controller.
         $controller = new Controller_Error($request, $response);
         return $controller->execute();
     } catch (Exception $e) {
         // Render the fallback view.
         $view = View::factory('errors/fallback');
         $response = Response::factory();
         $response->status(500);
         $response->body($view->render());
         return $response;
     }
 }
开发者ID:modulargaming,项目名称:modulargaming,代码行数:34,代码来源:Exception.php

示例10: action_comment_report

 /**
  * Email daily comment report
  */
 public function action_comment_report()
 {
     // Check if SwiftMailer installed
     if (!Kohana::find_file('vendor', 'swift/lib/swift_required')) {
         $this->request->response = 'Can not email daily comment report.  SwiftMailer is not installed.';
         return;
     }
     // Generate report
     $report = Request::factory('comments/blog-admin/report/86400')->execute()->response;
     try {
         // Include the SwiftMailer autoloader
         require_once Kohana::find_file('vendor', 'swift/lib/swift_required');
         // Create the message
         $message = Swift_Message::newInstance()->setContentType(Kohana::config('blog.comment_report.email_type'))->setSubject(Kohana::config('blog.comment_report.email_subject'))->setFrom(Kohana::config('blog.comment_report.email_from'))->setTo(Kohana::config('blog.comment_report.email_to'))->setBody($report);
         // Create the transport
         $transport = Swift_SmtpTransport::newInstance()->setHost(Kohana::config('email.options.hostname'))->setPort(Kohana::config('email.options.port'))->setEncryption(Kohana::config('email.options.encryption'))->setUsername(Kohana::config('email.options.username'))->setPassword(Kohana::config('email.options.password'));
         // Create the mailer
         $mailer = Swift_Mailer::newInstance($transport);
         // Send the message
         $mailer->send($message);
         $this->request->response = 'Daily comment report email sent.';
     } catch (Exception $e) {
         Kohana::$log->add(Kohana::ERROR, 'Error occured sending daily comment report. ' . $e->getMessage());
         $this->request->response = 'Error sending email report.' . PHP_EOL;
     }
 }
开发者ID:vimofthevine,项目名称:kohana-blog,代码行数:29,代码来源:cron.php

示例11: action_png

 public function action_png()
 {
     $dbname = $this->database->get_name();
     $graph = Request::factory($dbname . '/erd.dot')->execute()->body();
     $this->cache_dir = Kohana::$cache_dir . DIRECTORY_SEPARATOR . 'webdb' . DIRECTORY_SEPARATOR . 'erd';
     if (!is_dir($this->cache_dir)) {
         mkdir($this->cache_dir, 0777, TRUE);
     }
     $dot_filename = $this->cache_dir . DIRECTORY_SEPARATOR . $dbname . '.dot';
     $png_filename = $this->cache_dir . DIRECTORY_SEPARATOR . $dbname . '.png';
     file_put_contents($dot_filename, $graph);
     $dot = Kohana::$config->load('webdb/erd')->get('dot');
     $cmd = '"' . $dot . '"' . ' -Tpng';
     $cmd .= ' -o' . escapeshellarg($png_filename);
     //output
     $cmd .= ' ' . escapeshellarg($dot_filename);
     //input
     $cmd .= ' 2>&1';
     exec($cmd, $out, $error);
     if ($error != 0) {
         throw new HTTP_Exception_500('Unable to produce PNG. Command was: ' . $cmd . ' Output was: ' . implode(PHP_EOL, $out));
     } else {
         $this->response->send_file($png_filename, $dbname . '_erd.png', array('inline' => TRUE));
     }
 }
开发者ID:samwilson,项目名称:kohana_webdb_erd,代码行数:25,代码来源:ERD.php

示例12: anchorActionEdit

 public static function anchorActionEdit($key, $field)
 {
     $params = array('db' => Request::factory()->getDb(), 'cmd' => 'HSET ' . $key . ' ' . $field, 'back' => Request::factory()->getBack());
     $url = 'http://' . Request::factory()->getServerName() . '/?' . http_build_query($params);
     $title = 'HSET ' . htmlspecialchars($key) . ' ' . htmlspecialchars($field);
     return '<a class="cmd" href="' . $url . '" title="' . $title . '"><i class="icon-pencil"></i> Edit</a>';
 }
开发者ID:xingcuntian,项目名称:readmin,代码行数:7,代码来源:Hashes.php

示例13: action_subreq

 public function action_subreq()
 {
     foreach (array('main', 'globals') as $method) {
         $uri = "reqs/{$method}";
         $this->_cases[$uri] = Request::factory($uri)->execute();
     }
 }
开发者ID:ukd1,项目名称:kohana,代码行数:7,代码来源:request.php

示例14: huia_auth

 protected function huia_auth($username, $password)
 {
     $auth_url = Kohana::$config->load('huia/manager.auth_url');
     if (!$auth_url) {
         return FALSE;
     }
     try {
         $request = Request::factory($auth_url);
         $request->method(Request::POST);
         $request->post('username', $username);
         $request->post('password', $password);
         $response = $request->execute();
         $user = @json_decode($response->body());
         if (!$user or isset($user->error) or !isset($user->email)) {
             return FALSE;
         }
         $model = ORM::factory('User')->find_by_email($user->email);
         if (!$model->loaded()) {
             $model->values((array) $user);
             $model->password = $password;
             $model = $model->create();
             $roles = array($this->get_role('admin', 'Administrative user, has access to everything.'), $this->get_role('login', 'Login privileges, granted after account confirmation'));
             $model->add('roles', $roles);
         } else {
             if (Auth::instance()->hash($password) !== $model->password) {
                 $model->password = $password;
                 $model->update();
             }
         }
         Auth::instance()->force_login($model->username);
         return TRUE;
     } catch (Exception $e) {
         return FALSE;
     }
 }
开发者ID:huiancg,项目名称:kohana-huia-manager,代码行数:35,代码来源:Login.php

示例15: execute

 public function execute($method, $url, array $post = array())
 {
     $redirects_count = 1;
     \Request::$initial = NULL;
     $this->_request = \Request::factory($url)->method($method)->post($post)->body(http_build_query($post));
     if ($this->_previous_url) {
         $this->_request->referrer($this->_previous_url);
     }
     $this->_previous_url = $this->current_url() . \URL::query($this->_request->query(), FALSE);
     \Request::$initial = $this->_request;
     $this->_response = $this->_request->execute();
     while ($this->_response->status() >= 300 and $this->_response->status() < 400) {
         $redirects_count++;
         if ($redirects_count >= $this->max_redirects()) {
             throw new Exception_Toomanyredirects('Maximum Number of redirects (5) for url :url', array(':url' => $url));
         }
         $url_parts = parse_url($this->_response->headers('location'));
         $query = isset($url_parts['query']) ? $url_parts['query'] : '';
         parse_str($query, $query);
         $_GET = $query;
         $url = $url_parts['path'];
         \Request::$initial = NULL;
         $this->_request = \Request::factory($url);
         \Request::$initial = $this->_request;
         $this->_response = $this->_request->execute();
     }
     return $this->_response->body();
 }
开发者ID:openbuildings,项目名称:spiderling,代码行数:28,代码来源:Kohana.php


注:本文中的Request::factory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。