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


PHP HTTP_Exception::factory方法代码示例

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


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

示例1: action_role

 /**
  * Shows list of permissions per role
  *
  * @throws HTTP_Exception_404
  */
 public function action_role()
 {
     $id = $this->request->param('id', 1);
     $role = ORM::factory('role', $id);
     if (!$role->loaded()) {
         throw HTTP_Exception::factory(404, 'Attempt to access non-existent role.');
     }
     if (isset($_POST['permissions']) and $this->valid_post('role')) {
         $per_insert = DB::insert('permissions', array('rid', 'permission', 'module'));
         foreach ($_POST['role'] as $key => $val) {
             if (isset($val['name'])) {
                 $per_insert->values(array($role->id, $val['name'], $val['module']));
             }
         }
         try {
             DB::delete('permissions')->where('rid', '=', $role->id)->execute();
             $per_insert->execute();
             Message::success(__('Permissions saved successfully!'));
             // Redirect to listing
             $this->request->redirect(Route::get('admin/permission')->uri(array('action' => 'role', 'id' => $role->id)));
         } catch (ORM_Validation_Exception $e) {
             Message::error(__('Permissions save failed!'));
             $this->_errors = array('models', TRUE);
         }
     }
     $role_perms = DB::select()->from('permissions')->as_object()->execute();
     $this->title = __(':role Permissions', array(':role' => $role->name));
     $view = View::factory('admin/permission/role')->set('permissions', ACL::all())->bind('errors', $this->_errors)->bind('perms', $role_perms)->bind('role', $role)->bind('id', $id);
     $this->response->body($view);
 }
开发者ID:MenZil-Team,项目名称:cms,代码行数:35,代码来源:permission.php

示例2: action_gather

 /**
  * Callback for 'gather' response on call to Twilio
  */
 public function action_gather()
 {
     if ($this->request->method() != 'POST') {
         // Only POST is allowed
         throw HTTP_Exception::factory(405, 'The :method method is not supported. Supported methods are :allowed_methods', array(':method' => $this->request->method(), ':allowed_methods' => Http_Request::POST))->allowed(Http_Request::POST);
     }
     $provider = DataProvider::factory('twilio');
     // Authenticate the request
     $options = $provider->options();
     if ($this->request->post('AccountSid') !== $options['account_sid']) {
         // Could not authenticate the request?
         throw HTTP_Exception::factory(403, 'Incorrect or missing AccountSid');
     }
     // Remove Non-Numeric characters because that's what the DB has
     $to = preg_replace("/[^0-9,.]/", "", $this->request->post('To'));
     $from = preg_replace("/[^0-9,.]/", "", $this->request->post('From'));
     $message_sid = $this->request->post('CallSid');
     $digits = $this->request->post('Digits');
     if ($digits == 1) {
         $message_text = 'IVR: Okay';
     } else {
         if ($digits == 2) {
             $message_text = 'IVR: Not Okay';
         } else {
             // HALT
             Kohana::$log->add(Log::ERROR, __("':digits' is not a valid IVR response", array(":digits" => $digits)));
             return;
         }
     }
     $provider->receive(Message_Type::IVR, $from, $message_text, $to, NULL, $message_sid);
 }
开发者ID:puffadder,项目名称:platform,代码行数:34,代码来源:Twilio.php

示例3: action_index

 public function action_index()
 {
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('Home'))->set_url(Route::url('default')));
     Breadcrumbs::add(Breadcrumb::factory()->set_title(__('User Profile')));
     $seoname = $this->request->param('seoname', NULL);
     if ($seoname !== NULL) {
         $user = new Model_User();
         $user->where('seoname', '=', $seoname)->limit(1)->cached()->find();
         if ($user->loaded()) {
             $this->template->title = __('User Profile') . ' - ' . $user->name;
             //$this->template->meta_description = $user->name;//@todo phpseo
             $this->template->bind('content', $content);
             $ads = new Model_Ad();
             $ads = $ads->where('id_user', '=', $user->id_user)->where('status', '=', Model_Ad::STATUS_PUBLISHED)->order_by('created', 'desc')->cached()->find_all();
             // case when user dont have any ads
             if ($ads->count() == 0) {
                 $profile_ads = NULL;
             }
             $this->template->content = View::factory('pages/userprofile', array('user' => $user, 'profile_ads' => $ads));
         } else {
             //throw 404
             throw HTTP_Exception::factory(404, __('Page not found'));
         }
     } else {
         //throw 404
         throw HTTP_Exception::factory(404, __('Page not found'));
     }
 }
开发者ID:nick-catanchin-ie,项目名称:openclassifieds2,代码行数:28,代码来源:user.php

示例4: action_login

 public function action_login()
 {
     $this->view->username = '';
     $this->view->return_to = Arr::get($_REQUEST, 'return_to', '');
     if ($this->request->post('login') !== NULL) {
         Auth::instance()->logout();
         // Just in case we're logged in.
         $this->view->username = trim($this->request->post('username'));
         $password = trim($this->request->post('password'));
         Auth::instance()->login($this->view->username, $password);
         if (Auth::instance()->logged_in()) {
             try {
                 $dbms = new WebDB_DBMS();
                 $dbms->refresh_cache();
                 $this->add_flash_message('You are now logged in.', 'info');
                 Kohana::$log->add(Kohana_Log::INFO, $this->view->username . ' logged in.');
             } catch (Exception $e) {
                 $msg = 'Unable to log in as :username.';
                 throw HTTP_Exception::factory(500, $msg, array(':username' => $this->view->username), $e);
             }
             $this->redirect($this->view->return_to);
         } else {
             Kohana::$log->add(Kohana_Log::INFO, 'Failed log in: ' . $this->view->username);
             $this->add_template_message('Login failed.  Please try again.');
         }
     }
     // if ($this->request->post('login') !== NULL)
 }
开发者ID:samwilson,项目名称:kohana_webdb,代码行数:28,代码来源:User.php

示例5: action_index

 public function action_index()
 {
     try {
         if ($token = $this->grantAccessToken()) {
             // @see http://tools.ietf.org/html/rfc6749#section-5.1
             // server MUST disable caching in headers when tokens are involved
             $this->response->status(200);
             $this->response->headers(array('Cache-Control' => 'no-store', 'Pragma' => 'no-cache'));
             $this->response->headers('content-type', 'application/json; charset=' . Kohana::$charset);
             $this->response->body(JSON::encode($token));
             return;
         }
     } catch (Oauth2_Exception $e) {
         // Throw an exception because there was a problem with the client's request
         $response = array('error' => $e->getError(), 'error_description' => $e->getMessage());
         $this->response->status($e->getCode());
         $this->response->headers(array('Cache-Control' => 'no-store', 'Pragma' => 'no-cache'));
         $this->response->headers('content-type', 'application/json; charset=' . Kohana::$charset);
         $this->response->body(json_encode($response));
         return;
     } catch (Exception $e) {
         /**
          * Something went wrong!
          *
          * Throw an error when a non-library specific exception has been thrown
          *
          * You should probably show a nice error page :)
          *
          * Do NOT redirect the user back to the client.
          */
         throw HTTP_Exception::factory(500, $e->getMessage());
     }
 }
开发者ID:MenZil-Team,项目名称:cms,代码行数:33,代码来源:token.php

示例6: action_reply

 /**
  * Handle incoming SMS from Twilio
  */
 public function action_reply()
 {
     //Check if data provider is available
     $providers_available = Kohana::$config->load('features.data-providers');
     if (!$providers_available['twilio']) {
         throw HTTP_Exception::factory(403, 'The Twilio data source is not currently available. It can be accessed by upgrading to a higher Ushahidi tier.');
     }
     if ($this->request->method() != 'POST') {
         // Only POST is allowed
         throw HTTP_Exception::factory(405, 'The :method method is not supported. Supported methods are :allowed_methods', array(':method' => $this->request->method(), ':allowed_methods' => Http_Request::POST))->allowed(Http_Request::POST);
     }
     $provider = DataProvider::factory('twilio');
     // Authenticate the request
     $options = $provider->options();
     if ($this->request->post('AccountSid') !== $options['account_sid']) {
         throw HTTP_Exception::factory(403, 'Incorrect or missing AccountSid');
     }
     // Remove Non-Numeric characters because that's what the DB has
     $to = preg_replace("/[^0-9,.]/", "", $this->request->post('To'));
     $from = preg_replace("/[^0-9,.]/", "", $this->request->post('From'));
     $message_text = $this->request->post('Body');
     $message_sid = $this->request->post('MessageSid');
     // @todo use other info from twillio, ie: location, media
     $provider->receive(Message_Type::SMS, $from, $message_text, $to, NULL, $message_sid);
     // If we have an auto response configured, return the response messages
     if (!empty($options['sms_auto_response'])) {
         $body = View::factory('twillio/sms_response')->set('response', $options['sms_auto_response'])->render();
         // Set the correct content-type header
         $this->response->headers('Content-Type', 'text/xml');
         $this->response->body($body);
     }
 }
开发者ID:gjorgiev,项目名称:platform,代码行数:35,代码来源:Twilio.php

示例7: action_share

 /**
  * REST endpoint for sharing droplets via email
  */
 public function action_share()
 {
     $this->template = '';
     $this->auto_render = FALSE;
     if ($this->request->method() != "POST") {
         throw HTTP_Exception::factory(405)->allowed('POST');
     }
     // Extract the input data to be used for sending the email
     $post = Arr::extract($_POST, array('recipient', 'drop_title', 'drop_url', 'security_code'));
     $csrf_token = $this->request->headers('x-csrf-token');
     // Setup validation
     $validation = Validation::factory($post)->rule('recipient', 'not_empty')->rule('recipient', 'email')->rule('security_code', 'Captcha::valid')->rule('drop_title', 'not_empty')->rule('drop_url', 'url');
     // Validate
     if (!CSRF::valid($csrf_token) or !$validation->check()) {
         Kohana::$log->add(Log::DEBUG, "CSRF token or form validation failure");
         throw HTTP_Exception::factory(400);
     } else {
         list($recipient, $subject) = array($post['recipient'], $post['drop_title']);
         // Modify the mail body to include the email address of the
         // use sharing content
         $mail_body = __(":user has shared a drop with you via SwiftRiver\n\n:url", array(':user' => $this->user['owner']['username'], ':url' => $post['drop_url']));
         // Send the email
         Swiftriver_Mail::send($recipient, $subject, $mail_body);
     }
 }
开发者ID:aliyubash23,项目名称:SwiftRiver,代码行数:28,代码来源:Base.php

示例8: action_index

 public function action_index()
 {
     try {
         // Validating
         $this->validateRevokeRequest();
         if ($this->token_info['access_token'] == $this->token && !empty($this->token_info['refresh_token'])) {
             $result = Model::factory('oauth')->revoke_access_refresh($this->token);
         } elseif ($this->token_info['access_token'] == $this->token && empty($this->token_info['refresh_token'])) {
             $result = Model::factory('oauth')->revoke_access($this->token);
         } elseif ($this->token_info['refresh_token'] == $this->token) {
             $result = Model::factory('oauth')->revoke_refresh($this->token);
         }
         $this->response->body(json_encode(array('Response' => "Status Code: 200")));
         return;
     } catch (Oauth2_Exception $e) {
         // Throw an exception because there was a problem with the client's request
         $response = array('error' => $e->getError(), 'error_description' => $e->getMessage());
         $this->response->status($e->getCode());
         $this->response->headers(array('Cache-Control' => 'no-store', 'Pragma' => 'no-cache'));
         $this->response->body(json_encode($response));
     } catch (Exception $e) {
         /**
          * Something went wrong!
          *
          * Throw an error when a non-library specific exception has been thrown
          *
          * You should probably show a nice error page :)
          *
          * Do NOT redirect the user back to the client.
          */
         throw HTTP_Exception::factory(500, $e->getMessage());
     }
 }
开发者ID:MenZil-Team,项目名称:cms,代码行数:33,代码来源:revoke.php

示例9: create_email

 /**
  * creates a user from email if exists doesn't...
  * @param  string $email 
  * @param  string $name  
  * @param  string $password
  * @return Model_User        
  */
 public static function create_email($email, $name = NULL, $password = NULL)
 {
     $user = new self();
     $user->where('email', '=', $email)->limit(1)->find();
     if (!$user->loaded()) {
         if ($password === NULL) {
             $password = Text::random('alnum', 8);
         }
         $user->email = $email;
         $user->name = ($name === NULL or !isset($name)) ? substr($email, 0, strpos($email, '@')) : $name;
         $user->status = self::STATUS_ACTIVE;
         $user->id_role = Model_Role::ROLE_USER;
         $user->seoname = $user->gen_seo_title($user->name);
         $user->password = $password;
         $user->subscriber = 1;
         $user->last_ip = ip2long(Request::$client_ip);
         $user->country = euvat::country_code();
         //geo info EU
         try {
             $user->save();
             //send welcome email
             $url = $user->ql('oc-panel', array('controller' => 'profile', 'action' => 'edit'), TRUE);
             $user->email('auth-register', array('[USER.PWD]' => $password, '[URL.QL]' => $url));
         } catch (ORM_Validation_Exception $e) {
             throw HTTP_Exception::factory(500, $e->getMessage());
         }
     }
     return $user;
 }
开发者ID:Ryanker,项目名称:open-eshop,代码行数:36,代码来源:user.php

示例10: create

 /**
  * upload files
  */
 protected function create($model, $form)
 {
     // check rights
     if (!Acl::instance()->allowed($this->_controller, 'create')) {
         throw HTTP_Exception::factory(403, 'Create not allowed on :controller', array(':controller' => $this->_controller));
     }
     $hash = FALSE;
     Event::raise($this, Event::BEFORE_CREATE_FORM_PARSE, array('model' => NULL, 'form' => $form));
     if ($form->valid()) {
         $hash = Upload::process('file', $this->_settings->get('path_temp'), $this->_settings->get('extensions'), $this->_settings->get('unzip'));
     }
     if ($hash !== FALSE) {
         return $hash;
     } else {
         if ($form->submitted()) {
             // set error in form
             $form->element('file', 0)->error('not_empty');
         }
         // create viewer
         $viewer = Viewer::factory('Form', $form)->text(Text::instance());
         // render form
         $view = View::factory($this->_settings->get('view.create'), array('viewer' => $viewer));
         // event
         Event::raise($this, Event::BEFORE_CREATE_RENDER, array('model' => NULL, 'form' => $form, 'viewer' => $viewer, 'view' => $view));
         // render
         $this->response->body($view->render());
         return FALSE;
     }
 }
开发者ID:yubinchen18,项目名称:A-basic-website-project-for-a-company-using-the-MVC-pattern-in-Kohana-framework,代码行数:32,代码来源:File.php

示例11: renew

 /**
  * expired featured ads
  * @return void
  */
 public static function renew()
 {
     if (Core::config('general.subscriptions') == TRUE) {
         //get expired subscription that are active
         $subscriptions = new Model_Subscription();
         $subscriptions = $subscriptions->where('status', '=', 1)->where('expire_date', '<=', Date::unix2mysql())->order_by('created', 'desc')->find_all();
         foreach ($subscriptions as $s) {
             //disable the plan
             $s->status = 0;
             try {
                 $s->save();
             } catch (Exception $e) {
                 throw HTTP_Exception::factory(500, $e->getMessage());
             }
             $plan = $s->plan;
             if ($plan->loaded() and $plan->status == 1) {
                 //generate a new order
                 $order = Model_Order::new_order(NULL, $s->user, $plan->id_plan, $plan->price, core::config('payment.paypal_currency'), __('Subscription to ') . $plan->name);
                 //free plan no checkout
                 if ($plan->price == 0) {
                     $order->confirm_payment('cash');
                 } else {
                     $checkout_url = $s->user->ql('default', array('controller' => 'plan', 'action' => 'checkout', 'id' => $order->id_order));
                     $s->user->email('plan-expired', array('[PLAN.NAME]' => $plan->name, '[URL.CHECKOUT]' => $checkout_url));
                 }
             }
             //if plan loaded
         }
         //end foreach
     }
     //if subscription active
 }
开发者ID:ThomWensink,项目名称:openclassifieds2,代码行数:36,代码来源:subscription.php

示例12: action_complete

 public function action_complete()
 {
     // Get the transaction details.
     $fetch = $this->_gateway->fetchTransaction($this->_payment_vars())->send();
     $data = $fetch->getData();
     // Add the buyer email to parameters.
     $parameters = $this->_payment_vars() + array('email' => $data['EMAIL']);
     /** @var Payment_PayPal_CreateRecurringPaymentsRequest $request */
     $request = $this->_gateway->createRecurringPaymentsProfile($parameters);
     // Overwrite Item Category.
     $data = $request->getData();
     $data['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = $this->_config['itemCategory'];
     /** @var Omnipay\PayPal\Message\ExpressAuthorizeResponse $response */
     $response = $request->sendData($data);
     if ($response->isSuccessful()) {
         $response_data = $response->getData();
         // Get the transaction details.
         // $fetch = $this->_gateway->fetchTransaction($this->_payment_vars())->send();
         // $data = $fetch->getData();
         ORM::factory('Payment_Subscription')->values(array('user_id' => $this->user->id, 'package_id' => $this->_package->id, 'status' => Model_Payment_Subscription::PENDING, 'recurring_payment_id' => $response_data['PROFILEID']))->create();
         Hint::success(Kohana::message('payment', 'payment.success'));
         $this->redirect(Route::get('payment')->uri());
     } else {
         // Log the error.
         Kohana::$log->add(Log::ERROR, IPN::array_to_string($response->getData()));
         throw HTTP_Exception::factory('403', 'Something went wrong, no cash should have been drawn, if the error proceeds contact support!');
     }
 }
开发者ID:modulargaming,项目名称:payment,代码行数:28,代码来源:Recurring.php

示例13: before

 /**
  * Ensure we are calling this controller from the install.php by checking the MG_INSTALL constant.
  * And throw a HTTP 404 exception if that is not the case.
  *
  * @throws HTTP_Exception
  */
 public function before()
 {
     // Ensure we are in the install.php file.
     if (!defined('MG_INSTALL') or MG_INSTALL !== TRUE) {
         throw HTTP_Exception::factory(404, 'File not found!');
     }
 }
开发者ID:modulargaming,项目名称:core,代码行数:13,代码来源:Install.php

示例14: action_index

 /**
  * Serve the file to the browser AND cache it for direct access if in STAGING OR PRODUCTION.
  */
 public function action_index()
 {
     $file = $this->request->param('file');
     $ext = pathinfo($file, PATHINFO_EXTENSION);
     $path = Kohana::find_file('assets', $file, FALSE);
     if ($path === FALSE) {
         throw HTTP_Exception::factory('404', 'File not found!');
     }
     $dir = DOCROOT . 'assets' . DIRECTORY_SEPARATOR;
     // Set the proper headers for browser caching
     $this->response->headers('content-type', File::mime_by_ext($ext));
     $this->response->headers('last-modified', date('r', filemtime($path)));
     $content = file_get_contents($path);
     $this->response->body($content);
     // Don't cache the assets unless we are in STAGING OR PRODUCTION.
     if (Kohana::$environment >= Kohana::STAGING) {
         return;
     }
     // Only cache for specific extensions.
     if (!in_array($ext, $this->_cache_extensions)) {
         return;
     }
     // Check if assets sub dir exist.
     $parts = explode('/', $file);
     $file = array_pop($parts);
     foreach ($parts as $part) {
         $dir .= $part . DIRECTORY_SEPARATOR;
         if (!is_dir($dir)) {
             mkdir($dir);
         }
     }
     file_put_contents($dir . $file, $content);
 }
开发者ID:modulargaming,项目名称:core,代码行数:36,代码来源:Assets.php

示例15: action_index

 public function action_index()
 {
     // Set up custom error view
     Kohana_Exception::$error_view = 'error/data-provider';
     //Check if data provider is available
     $providers_available = Kohana::$config->load('features.data-providers');
     if (!$providers_available['smssync']) {
         throw HTTP_Exception::factory(403, 'The SMS Sync data source is not currently available. It can be accessed by upgrading to a higher Ushahidi tier.');
     }
     $methods_with_http_request = [Http_Request::POST, Http_Request::GET];
     if (!in_array($this->request->method(), $methods_with_http_request)) {
         // Only POST or GET is allowed
         throw HTTP_Exception::factory(405, 'The :method method is not supported. Supported methods are :allowed_methods', array(':method' => $this->request->method(), ':allowed_methods' => implode(',', $methods_with_http_request)))->allowed($methods_with_http_request);
     }
     $this->_provider = DataProvider::factory('smssync');
     $this->options = $this->_provider->options();
     // Ensure we're always returning a payload..
     // This will be overwritten later if incoming or task methods are run
     $this->_json['payload'] = ['success' => TRUE, 'error' => NULL];
     // Process incoming messages from SMSSync only if the request is POST
     if ($this->request->method() == 'POST') {
         $this->_incoming();
     }
     // Attempt Task if request is GET and task type is 'send'
     if ($this->request->method() == 'GET' and $this->request->query('task') == 'send') {
         $this->_task();
     }
     // Set the response
     $this->_set_response();
 }
开发者ID:tobiasziegler,项目名称:platform,代码行数:30,代码来源:Smssync.php


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