Overview

Namespaces

  • LeanCloud
    • Engine
    • Operation
    • Storage
    • Uploader

Classes

  • LeanCloud\ACL
  • LeanCloud\AppRouter
  • LeanCloud\Bytes
  • LeanCloud\Client
  • LeanCloud\Engine\Cloud
  • LeanCloud\Engine\LaravelEngine
  • LeanCloud\Engine\LeanEngine
  • LeanCloud\Engine\SlimEngine
  • LeanCloud\File
  • LeanCloud\GeoPoint
  • LeanCloud\LeanObject
  • LeanCloud\MIMEType
  • LeanCloud\Operation\ArrayOperation
  • LeanCloud\Operation\DeleteOperation
  • LeanCloud\Operation\IncrementOperation
  • LeanCloud\Operation\RelationOperation
  • LeanCloud\Operation\SetOperation
  • LeanCloud\Push
  • LeanCloud\Query
  • LeanCloud\Region
  • LeanCloud\Relation
  • LeanCloud\Role
  • LeanCloud\RouteCache
  • LeanCloud\SaveOption
  • LeanCloud\SMS
  • LeanCloud\Storage\CookieStorage
  • LeanCloud\Storage\SessionStorage
  • LeanCloud\Uploader\QCloudUploader
  • LeanCloud\Uploader\QiniuUploader
  • LeanCloud\Uploader\S3Uploader
  • LeanCloud\Uploader\SimpleUploader
  • LeanCloud\User

Interfaces

  • LeanCloud\Operation\IOperation
  • LeanCloud\Storage\IStorage

Exceptions

  • LeanCloud\BatchRequestError
  • LeanCloud\CloudException
  • LeanCloud\Engine\FunctionError
  • Overview
  • Namespace
  • Class
 1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 
<?php

namespace LeanCloud\Engine;

/**
 * LeanEngine as Slim middleware
 *
 * Add it in a Slim application:
 *
 * ```php
 * $app = new \Slim\App();
 * $app->add(new SlimEngine());
 * ```
 *
 * @link http://www.slimframework.com/docs/concepts/middleware.html
 */
class SlimEngine extends LeanEngine {

    /**
     * Get request header value
     *
     * @param string $key Header key
     * @return string
     */
    protected function getHeaderLine($key) {
        return $this->request->getHeaderLine($key);
    }

    /**
     * Get request body string
     *
     * @return string
     */
    protected function getBody() {
        return $this->request->getBody()->getContents();
    }

    /*
     * Ideally we would like to write to Slim response and send
     * the response to client. But we did not yet find a good way
     * to end the request as Slime middleware. As a work around,
     * we fallback to PHP native functions to do that. Pull request
     * is welcome.
     * 
     * @see LeanEngine::withHeader LeanEngine::send
     */
    // protected function withHeader($key, $val) {}
    // protected function send($key, $val) {}

    /**
     * Slim middleware entry point
     *
     * @param  \Psr\Http\Message\ServerRequestInterface $request  PSR7 request
     * @param  \Psr\Http\Message\ResponseInterface      $response PSR7 response
     * @param  callable                                 $next     Next middleware
     * @return \Psr\Http\Message\ResponseInterface
     */
    public function __invoke($request, $response, $next) {
        $this->request  = $request;
        $this->response = $response;
        $this->dispatch($request->getMethod(),
                        $request->getUri());
        return $next($this->request, $this->response);
    }
}

API documentation generated by ApiGen