Slim 4.* PHP tencent serverless component.
npm install @twn39/tencent-php-slim
Slim 4.* PHP tencent serverless component.
```
npm i -g serverless
``
composer install slim/slim
composer install slim/http
composer install guzzlehttp/psr7
composer install pimple/pimple
composer install slim/psr7
Make sure the composer.json file contains follow section:
`json`
"require": {
"slim/slim": "^4.3",
"slim/http": "^0.8.0",
"ext-json": "*",
"guzzlehttp/psr7": "^1.6",
"pimple/pimple": "^3.2",
"slim/psr7": "^0.6.0"
}
The project root must contain two files, app.php and container.php.
app.php:
` use Slim\Http\Response; $app = AppFactory::create(); $app->get('/', function(Request $request, Response $response) { return $response->withJson([ return $app;php`
use GuzzleHttp\Psr7\Request; // notice this request namespace
use Slim\Factory\AppFactory;
var_dump($this->get('event'));
'hello' => 'serverless slim php.'
]);
});
container.php
` $container = new \Pimple\Container(); // here define the dependencies return $container;php`
> notice: don't require autoload.php in the head of any file.
create the serverless configure file, serverless.yml:
`yml`serverless.yml
slimphp:
component: '@twn39/tencent-php-slim'
inputs:
region: ap-shanghai
```
serverless --debug