承接 sinevia/php-serverless 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sinevia/php-serverless

Composer 安装命令:

composer require sinevia/php-serverless

包简介

PHP Serverless

README 文档

README

The first and fully functional PHP framework built exclusively for serverless. Support for IBM Cloud Functions

Build status GitHub stars HitCount

FEATURES

  • Easy to learn and start. All required is in this README file.
  • Fully automated and extendable via RoboFile (learn more).
  • Powerful and super fast router (learn more).
  • Lean database library (learn more). Eloquent optional.
  • Lean template engine (learn more). Blade optional.
  • Lean testing framework (learn more). PhpUnit optional.
  • Uses tested serverless deployment framework (learn more)

INSTALLATION

  1. Step 1
composer create-project --prefer-dist sinevia/php-serverless .
  1. Step 2
vendor/bin/robo init

AFTER INSTALLATION

  • Delete the phpunit.xml file, if you are not going to use PHPUnit for testing
  • Change the settings in /app/config (serverless function name, etc)
  • Change the settings in /env.php (not required usually)

WORKFLOW

Four environments are specified and available out of the box - local, testing, staging, live.

  1. Local. All development is done on local - (local)
  2. Testing. Automatic tests are run in testing - (testing)
  3. Staging. For user and manual testing depoy to staging - (staging)
  4. Live. For real live usage deploy to live - (live)

DEVELOPMENT

To start working on the project run the built in PHP server:

php -S localhost:32222

or using the helper function

vendor/bin/robo serve

Then open in browser: http://localhost:32222/

or using the helper function

vendor/bin/robo open local

DATABASE

To run migrations for each environment:

vendor/bin/robo migrate local
vendor/bin/robo migrate staging
vendor/bin/robo migrate live

DEPLOYMENT

The deployment will run your tests, and will continue only if your tests are successful

To deploy to your staging function

vendor/bin/robo deploy staging

To deploy to your live function

vendor/bin/robo deploy live

HELPER FUNCTIONS

A RoboFile exists with automated functionality.

  • Run database migrations on local
vendor/bin/robo migrate local
  • Run database migrations on staging
vendor/bin/robo migrate local
  • Run database migrations on live
vendor/bin/robo migrate live
  • Serve the site for development
vendor/bin/robo serve
  • Open local/dev url from terminal
vendor/bin/robo open local
  • Open staging url from terminal
vendor/bin/robo open staging
  • Open live url from terminal
vendor/bin/robo open live
  • Deploy to staging
vendor/bin/robo deploy staging
  • Deploy to live
vendor/bin/robo deploy live

TESTING

Two testing frameworks supported out of the box:

  1. Testify.php - very lean and straghtforward to work with (preferred, and preinstaled)
  2. PHPUnit - more mature, but heavy weight with many dependencies

To decide which modify the setting in the RoboFile.

Testing with Testify.php

Testify is a small PHP testing library with no extenal dependencies: https://github.com/BafS/Testify.php

Place your tests in /tests/test.php

To run the tests

php tests/test.php

or

vendor/bin/robo test

Testing with PHPUnit

PHPUnit is a huge PHP testing library. Beware it will come with lots of composer dependencies: https://phpunit.de/

To install the framework with all the dependencies

composer require --dev phpunit/phpunit

Place your settigs in /phpunit.xml. Place your tests in /tests

To run the tests

vendor/bin/phpunit

or

vendor/bin/robo test

SERVING STATIC FILES

Multiple options

Local CSS and JavaScript files are best to be served minified inline. Helper functions are added

<?php echo joinCss(['/css/main.css','/css/secondary.css']); ?>

Small images (i.e. favicon) serve inline as data.

<img src="<?php echo image2DataUri('/public/img/avatar.png'); ?>" />

To serve static files separately place them in the public directory.

/public/css/main.css

For remote static files use CDN, S3 or other storage.

FUNCTIONS

Functions are defined in file /app/functions.php. Feel free to change or remove.

basePath($path = '')

Returns the top most (root, base) path of the application

baseUrl($path = '')

Returns the top most (root, base) URL of the application

db()

Returns a database instance

env($key, $default = '')

Returns an env variable from OPEN WHISK

htmlFormatPriceWithCurrencySymbol($amount, $currency)

image2DataUri($imagePath)

Converts an image path to data URI

isGet

Checks if this is a GET request

isPost

Checks if this is a POST request

joinCss($styles, $options = [])

Joins multiple CSS files, and optionally minifies them

joinJs($scripts, $options = [])

Joins multiple JavaScript files, and optionally minifies them

redirect($url)

Redirects to the specified URL

req($name, $default = null, $functions = [])

Returns the requested $_REQUEST name-value pair if it exists

sess($name, $default = null, $functions = [], $options = [])

Returns the requested $_SESSION name-value pair if it exists

once($name, $default = null, $functions = [], $options = [])

Returns a once value if it exists in $_SESSION. After the value is returned, it is deleted

function reqOrSess($name, $default = null, $functions = [])

ui($view, $vars = array(), $options = array())

Renders a template from app/views. If no extension is specified .phtml is added

view($view, $data)

Renders a Blade template from /views. A /cache folder is required. If using Eloquent for data management this function will clash, delete it, or rename it i.e. to uiBlade($view, $data).

To use the view function you must install Blade:

composer require jenssegers/blade

sinevia/php-serverless 适用场景与选型建议

sinevia/php-serverless 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 46 次下载、GitHub Stars 达 3, 最近一次更新时间为 2019 年 05 月 31 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 sinevia/php-serverless 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 sinevia/php-serverless 我们能提供哪些服务?
定制开发 / 二次开发

基于 sinevia/php-serverless 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 46
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2019-05-31