本文整理汇总了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();
}
示例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();
}
}));
}
示例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();
}
示例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;
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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()]);
}
}
示例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;
}
示例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'));
}
示例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());
}
示例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();
}
示例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();
}
示例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));
}
}