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


PHP Slim::request方法代码示例

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


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

示例1: request

 private function request($method, $path, $data = array(), $optionalHeaders = array())
 {
     // Capture STDOUT
     ob_start();
     $options = array('REQUEST_METHOD' => strtoupper($method), 'PATH_INFO' => $path, 'SERVER_NAME' => 'local.dev');
     if ($method === 'get') {
         $options['QUERY_STRING'] = http_build_query($data);
     } elseif (is_array($data)) {
         $options['slim.input'] = http_build_query($data);
     } else {
         $options['slim.input'] = $data;
     }
     // Prepare a mock environment
     Slim\Environment::mock(array_merge($options, $optionalHeaders));
     $env = Slim\Environment::getInstance();
     $this->app->router = new NoCacheRouter($this->app->router);
     $this->app->request = new Slim\Http\Request($env);
     // Custom headers
     $this->app->request->headers = new Slim\Http\Headers($env);
     $this->app->response = new Slim\Http\Response();
     // Establish some useful references to the slim app properties
     $this->request = $this->app->request();
     $this->response = $this->app->response();
     // Execute our app
     $this->app->run();
     // Return the application output. Also available in `response->body()`
     return ob_get_clean();
 }
开发者ID:hochanh,项目名称:slim-test-helpers,代码行数:28,代码来源:WebTestClient.php

示例2: initialize

/**
 * A group of Twig functions for use in view templates
 *
 * @param  Twig_Environment $env
 * @param  Slim             $app
 * @return void
 */
function initialize(Twig_Environment $env, Slim $app)
{
    $env->addExtension(new TwigExtension());
    $env->addFunction(new Twig_SimpleFunction('urlFor', function ($routeName, $params = array()) use($app) {
        $url = $app->urlFor($routeName, $params);
        return $url;
    }));
    $env->addFunction(new Twig_SimpleFunction('hash', function ($value) {
        return md5($value);
    }));
    $env->addFunction(new Twig_SimpleFunction('gravatar', function ($email_hash, $size = 40) {
        $size = (int) $size == 0 ? 20 : (int) $size;
        $url = 'https://secure.gravatar.com/avatar/' . $email_hash . '?d=mm&s=' . $size;
        if (empty($email_hash)) {
            $url .= '&f=y';
        }
        return $url;
    }));
    $env->addFunction(new Twig_SimpleFunction('getCurrentUrl', function () {
        return $_SERVER['REQUEST_URI'];
    }));
    $env->addFunction(new Twig_SimpleFunction('urlForTalk', function ($eventSlug, $talkSlug, $params = array()) use($app) {
        return $app->urlFor('talk', array('eventSlug' => $eventSlug, 'talkSlug' => $talkSlug));
    }));
    $env->addFunction(new Twig_SimpleFunction('shortUrlForTalk', function ($talkStub) use($app) {
        $scheme = $app->request()->getScheme();
        $host = $app->request()->headers('host');
        return "{$scheme}://{$host}" . $app->urlFor('talk-quicklink', array('talkStub' => $talkStub));
    }));
    $env->addFunction(new Twig_SimpleFunction('shortUrlForEvent', function ($eventStub) use($app) {
        $scheme = $app->request()->getScheme();
        $host = $app->request()->headers('host');
        return "{$scheme}://{$host}" . $app->urlFor('event-quicklink', array('stub' => $eventStub));
    }));
    $env->addFunction(new Twig_SimpleFunction('dateRange', function ($start, $end, $format = 'd.m.Y', $separator = ' - ') use($app) {
        $formatter = new \Org_Heigl\DateRange\DateRangeFormatter();
        $formatter->setFormat($format);
        $formatter->setSeparator($separator);
        if (!$start instanceof \DateTimeInterface) {
            $start = new \DateTime($start);
        }
        if (!$end instanceof \DateTimeInterface) {
            $end = new \DateTime($end);
        }
        return $formatter->getDateRange($start, $end);
    }));
    /**
     * wrapped Slim request function getPath()
     */
    $env->addFunction(new Twig_SimpleFunction('currentPath', function () use($app) {
        $request = $app->request;
        $params = $app->request->get();
        $queryString = http_build_query($params);
        if ($queryString) {
            return $request->getPath() . urlencode('?' . $queryString);
        } else {
            return $request->getPath();
        }
    }));
}
开发者ID:e3betht,项目名称:joindin-web2,代码行数:67,代码来源:Functions.php

示例3:

 /**
  * constructor
  */
 final function __construct()
 {
     self::$app || (self::$app = \Slim\Slim::getInstance());
     $this->request = self::$app->request();
     $this->response = self::$app->response();
     $this->config = self::$app->config;
     $this->validator = self::$app->validator;
     $this->init();
 }
开发者ID:donghaichen,项目名称:Clover,代码行数:12,代码来源:BaseController.php

示例4: jsonRequest

 /**
  * Decode json data from request
  * @return mixed|null
  */
 protected function jsonRequest()
 {
     $input = null;
     try {
         $input = Json::decode(trim($this->app->request()->getBody()), true);
     } catch (JsonException $ex) {
         $input = null;
     }
     return $input;
 }
开发者ID:nogo,项目名称:feedbox,代码行数:14,代码来源:AbstractController.php

示例5: action_update

 public function action_update(Slim $app, $setupId, $fitId)
 {
     if (!$app->user->isLoggedin()) {
         return false;
     }
     $newFit = $app->request()->post('fit');
     $newDesc = $app->request()->post('description');
     $newQuantity = $app->request()->post('quantity');
     $app->evefit->updateFit($newFit, $newDesc, $newQuantity, $setupId, $fitId);
 }
开发者ID:Covert-Inferno,项目名称:eveATcheck,代码行数:10,代码来源:fit.php

示例6: editFeed

 /**
  * PUT /feed/:id
  *
  * @param int $id
  */
 public function editFeed($id)
 {
     $feed = new Feed();
     if ($feed->read($id)) {
         $feed->setArray(json_decode($this->app->request()->getBody(), true));
         $this->app->render($feed->save() ? 200 : 500, ['response' => $feed->id]);
     } else {
         $this->app->render(404);
     }
 }
开发者ID:nextglory,项目名称:CacoCloud,代码行数:15,代码来源:REST.php

示例7: edit

 public function edit($key)
 {
     $config = new Config();
     if (!$config->readKey($key)) {
         $this->app->render(404);
         return;
     }
     $config->setArray(json_decode($this->app->request()->getBody(), true));
     if ($config->save()) {
         $this->app->render(200, ['response' => $config->id]);
     } else {
         $this->app->render(500);
     }
 }
开发者ID:nextglory,项目名称:CacoCloud,代码行数:14,代码来源:REST.php

示例8: __construct

 public function __construct(Slim $app, array $params = array())
 {
     $this->app = $app;
     $this->request = $app->request();
     $this->response = $app->response();
     $this->params = $this->buildParams($params);
 }
开发者ID:benconnito,项目名称:kopper,代码行数:7,代码来源:Controller.php

示例9: sendMail

 /**
  * POST /:key/mail/account/:id/send
  *
  * @param string $key
  * @param int $id
  */
 public function sendMail($key, $id)
 {
     $smtpAccount = $this->mcryptAccount->one($key, $id)->getSmtp();
     $mailData = json_decode($this->app->request()->getBody(), true);
     $mail = new PHPMailer(true);
     $mail->isSMTP();
     $mail->CharSet = 'utf-8';
     $mail->setFrom($smtpAccount->email, $smtpAccount->realName);
     $mail->Host = $smtpAccount->host;
     $mail->Port = $smtpAccount->port;
     $mail->SMTPAuth = $smtpAccount->auth;
     $mail->Username = $smtpAccount->userName;
     $mail->Password = $smtpAccount->password;
     $mail->Subject = trim($mailData['subject']);
     $mail->Body = trim($mailData['body']);
     if (isset($mailData['to']) && !empty($mailData['to'])) {
         $mail->addAddress($mailData['to']);
     }
     if (isset($mailData['cc']) && !empty($mailData['cc'])) {
         $mail->addCC($mailData['cc']);
     }
     if (isset($mailData['bcc']) && !empty($mailData['bcc'])) {
         $mail->addBCC($mailData['bcc']);
     }
     try {
         $this->app->render(200, ['response' => $mail->send()]);
     } catch (\phpmailerException $e) {
         $this->app->render(500, ['error' => $e->getMessage()]);
     }
 }
开发者ID:nextglory,项目名称:CacoCloud,代码行数:36,代码来源:REST.php

示例10: __construct

 /**
  * Constructor
  * 
  * @param Slim $app
  */
 public function __construct(Slim $app, array $config = [])
 {
     $this->app = $app;
     $this->dic = $app->dic;
     $this->request = $app->request();
     $this->response = $app->response();
     $this->config = $config;
 }
开发者ID:chippyash,项目名称:slim-dic,代码行数:13,代码来源:AbstractController.php

示例11: subscribeAction

 /**
  * Handle the subscription form request
  */
 public function subscribeAction()
 {
     try {
         $this->subscribeForm->validate($this->app->request()->params());
     } catch (FormValidationException $e) {
         $this->session->flash('message', 'Oh no, you have entered invalid data. Please correct your input and try again.');
         $this->session->flash('errors', $e->getErrors());
         $this->session->flash('input', $this->app->request()->params());
         $this->app->response->redirect($this->app->urlFor('home'));
         return;
     }
     //
     // TODO: Subscribe the client to your newsletter list... or stuff
     //
     $this->session->flash('message', 'Thanks for your request. You have successfully subscribed for our newsletter.');
     $this->app->response->redirect($this->app->urlFor('home'));
 }
开发者ID:seanc,项目名称:slim-boilerplate-1,代码行数:20,代码来源:HomeController.php

示例12: __invoke

 /**
  * Call this class as a function.
  *
  * @return void
  */
 public function __invoke()
 {
     $request = MessageBridge::newOAuth2Request($this->slim->request());
     $response = new OAuth2\Response();
     $isValid = $this->server->validateAuthorizeRequest($request, $response);
     if (!$isValid) {
         MessageBridge::mapResponse($response, $this->slim->response());
         return;
     }
     $authorized = $this->slim->request()->params('authorized');
     if (empty($authorized)) {
         $this->slim->render($this->template, ['client_id' => $request->query('client_id', false)]);
         return;
     }
     //@TODO implement user_id
     $this->server->handleAuthorizeRequest($request, $response, $authorized === 'yes');
     MessageBridge::mapResponse($response, $this->slim->response());
 }
开发者ID:tularamaurya,项目名称:slim-oauth2-routes,代码行数:23,代码来源:Authorize.php

示例13: request

 public function request($method, $path, $options = array())
 {
     ob_start();
     Environment::mock(array_merge(array('PATH_INFO' => $path, 'SERVER_NAME' => 'slim-test.dev', 'REQUEST_METHOD' => $method), $options));
     $app = new Slim();
     $this->app = $app;
     $this->request = $app->request();
     $this->response = $app->response();
     return ob_get_clean();
 }
开发者ID:emeka-osuagwu,项目名称:sweetemoji,代码行数:10,代码来源:RouteTest.php

示例14: request

 public function request($method, $path, $options = array())
 {
     // Capture STDOUT
     ob_start();
     // Prepare a mock environment
     Environment::mock(array_merge(array('REQUEST_METHOD' => $method, 'PATH_INFO' => $path, 'SERVER_NAME' => 'mock.matrix42.com'), $options));
     $app = new Slim();
     $this->app = $app;
     $this->request = $app->request();
     $this->response = $app->response();
     // Return STDOUT
     return ob_get_clean();
 }
开发者ID:akarimgh,项目名称:matrix42-slim-api,代码行数:13,代码来源:test-route.php

示例15: action_index

 /**
  * Detail page
  *
  * @param \Slim\Slim $app
  */
 public function action_index(Slim $app, $setupId)
 {
     if (!$app->user->isLoggedin()) {
         return false;
     }
     $setup = $app->evefit->getSetup($setupId);
     $tour = $app->rulechecker->getTournament();
     if ($app->request()->isAjax()) {
         $app->render('setup/setupDetails.twig', array('setup' => $setup, 'tournament' => $tour, 'user' => $app->user));
     } else {
         $app->render('setup/details.twig', array('setup' => $setup, 'tournament' => $tour, 'user' => $app->user));
     }
 }
开发者ID:Covert-Inferno,项目名称:eveATcheck,代码行数:18,代码来源:details.php


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