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


PHP Slim::halt方法代码示例

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


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

示例1: testSlimHaltOutsideCallback

 /**
  * Test Slim::halt outside route callback
  *
  * Pre-conditions:
  * Slim::halt is invoked outside of a route callback
  *
  * Post-conditions:
  * The new response should be returned with the expected
  * status code and body, regardless of the current route
  * callback's expected output.
  */
 public function testSlimHaltOutsideCallback() {
     $this->setExpectedException('Slim_Exception_Stop');
     Slim::init();
     Slim::halt(500, 'External error');
     Slim::get('/', function () {
         echo "foo";
     });
     Slim::run();
     $this->assertEquals(Slim::response()->status(), 500);
     $this->assertEquals(Slim::response()->body(), 'External error');
 }
开发者ID:ntdt,项目名称:Slim,代码行数:22,代码来源:SlimTest.php

示例2: Slim

require 'Slim/Slim.php';
//With custom settings
$app = new Slim();
//Mailchimp help route
$app->get('/mailchimp', function () use($app) {
    $app->render('mailchimp.php');
});
//Mailchimp webhook
$app->post('/mailchimp', function () use($app) {
    require_once 'MCAPI.class.php';
    $emailField = $app->request()->get('email');
    $listId = $app->request()->get('listid');
    $apiKey = $app->request()->get('apikey');
    //Make sure we have required data.
    if (empty($emailField) || empty($listId) || empty($apiKey)) {
        $app->halt(500, 'Your hook is missing required GET parameters.');
    }
    $email = $app->request()->post($emailField);
    $forename = $app->request()->post($app->request()->get('forename'));
    $surname = $app->request()->post($app->request()->get('surname'));
    $rid = $app->request()->post('id');
    //Make sure we have required data.
    if (empty($email)) {
        $app->halt(500, 'Your hook is missing email address.');
    }
    //If double opt in parameter is present, subscribe with double opt-in.
    $doubleOptIn = false;
    if (!is_null($app->request()->get('doubleoptin'))) {
        $doubleOptIn = true;
    }
    $api = new MCAPI($apiKey);
开发者ID:mikelovely,项目名称:webhooks,代码行数:31,代码来源:index.php

示例3: testHaltDoesNotLeaveOutputBuffersOpen

 /**
  * Test halt does not leave output buffers open
  */
 public function testHaltDoesNotLeaveOutputBuffersOpen()
 {
     $level_start = ob_get_level();
     $s = new Slim();
     $s->get('/bar', function () use($s) {
         $s->halt(500, '');
     });
     $s->run();
     $this->assertEquals($level_start, ob_get_level());
 }
开发者ID:rs3d,项目名称:Slimplr,代码行数:13,代码来源:SlimTest.php

示例4: testHalt

 /**
  * Test halt
  */
 public function testHalt()
 {
     $s = new Slim();
     $s->get('/bar', function () use($s) {
         echo "Foo!";
         //<-- Should not be in response body!
         $s->halt(500, 'Something broke');
     });
     $s->call();
     list($status, $header, $body) = $s->response()->finalize();
     $this->assertEquals(500, $status);
     $this->assertEquals('Something broke', $body);
 }
开发者ID:renvieir,项目名称:emprestae,代码行数:16,代码来源:SlimTest.php

示例5: testSlimHaltOutsideCallback

 /**
  * Test Slim Halt outside route callback
  *
  * Pre-conditions:
  * Slim app instantiated;
  * Slim::halt is invoked outside of a route callback;
  *
  * Post-conditions:
  * The new response should be returned with the expected
  * status code and body, regardless of the current route
  * callback's expected output.
  */
 public function testSlimHaltOutsideCallback()
 {
     $this->setExpectedException('Slim_Exception_Stop');
     $app = new Slim();
     $app->halt(500, 'External error');
     $app->get('/', function () {
         echo "foo";
     });
     $app->run();
     $this->assertEquals(500, $app->response()->status());
     $this->assertEquals('External error', $app->response()->body());
 }
开发者ID:inscriptionweb,项目名称:lebonmail,代码行数:24,代码来源:SlimTest.php

示例6: etag

 /**
  * Set ETag HTTP Response Header
  *
  * Set the etag header and stop if the conditional GET request matches.
  * The `value` argument is a unique identifier for the current resource.
  * The `type` argument indicates whether the etag should be used as a strong or
  * weak cache validator.
  *
  * When the current request includes an 'If-None-Match' header with
  * a matching etag, execution is immediately stopped. If the request
  * method is GET or HEAD, a '304 Not Modified' response is sent.
  *
  * @param 	string 						$value 	The etag value
  * @param 	string 						$type 	The type of etag to create; either "strong" or "weak"
  * @throws 	InvalidArgumentException 			If provided type is invalid
  * @return 	void
  */
 public static function etag($value, $type = 'strong')
 {
     //Ensure type is correct
     if (!in_array($type, array('strong', 'weak'))) {
         throw new InvalidArgumentException('Invalid Slim::etag type. Expected "strong" or "weak".');
     }
     //Set etag value
     $value = '"' . $value . '"';
     if ($type === 'weak') {
         $value = 'W/' . $value;
     }
     Slim::response()->header('ETag', $value);
     //Check conditional GET
     if ($etagsHeader = Slim::request()->header('IF_NONE_MATCH')) {
         $etags = preg_split('@\\s*,\\s*@', $etagsHeader);
         if (in_array($value, $etags) || in_array('*', $etags)) {
             Slim::halt(304);
         }
     }
 }
开发者ID:Jud,项目名称:Slim,代码行数:37,代码来源:Slim.php


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