Skip to content
slim 4.* tencent serverless component
JavaScript PHP
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
doc
.gitignore
lambda.php
package.json
readme.md
serverless.js

readme.md

Serverless Components

Slim 4.* PHP tencent serverless component.

Install serverless framework

npm i -g serverless

Install Slimphp & components

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:

  "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"
    }

Create app.php & container.php

The project root must contain two files, app.php and container.php.

app.php:

<?php

use Slim\Http\Response;
use GuzzleHttp\Psr7\Request;   // notice this request namespace
use Slim\Factory\AppFactory;

$app = AppFactory::create();

$app->get('/', function(Request $request, Response $response) {
    var_dump($this->get('event'));

    return $response->withJson([
        'hello' => 'serverless slim php.'
    ]);
});

return $app;

container.php

<?php

$container = new \Pimple\Container();

// here define the dependencies

return $container;

notice: don't require autoload.php in the head of any file.

Configure the serverless

create the serverless configure file, serverless.yml:

# serverless.yml
 
slimphp:
  component: '@twn39/tencent-php-slim'
  inputs:
    region: ap-shanghai

Deploy

serverless --debug

Have fun !

You can’t perform that action at this time.