The first and fully functional PHP framework built exclusively for serverless. Support for IBM Cloud Functions
- 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)
- Step 1
composer create-project --prefer-dist sinevia/php-serverless .
- Step 2
vendor/bin/robo init
- 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)
Four environments are specified and available out of the box - local, testing, staging, live.
- Local. All development is done on local - (local)
- Testing. Automatic tests are run in testing - (testing)
- Staging. For user and manual testing depoy to staging - (staging)
- Live. For real live usage deploy to live - (live)
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
To run migrations for each environment:
vendor/bin/robo migrate local
vendor/bin/robo migrate staging
vendor/bin/robo migrate live
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
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
Two testing frameworks supported out of the box:
- Testify.php - very lean and straghtforward to work with (preferred, and preinstaled)
- PHPUnit - more mature, but heavy weight with many dependencies
To decide which modify the setting in the RoboFile.
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
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
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 are defined in file /app/functions.php. Feel free to change or remove.
Returns the top most (root, base) path of the application
Returns the top most (root, base) URL of the application
Returns a database instance
Returns an env variable from OPEN WHISK
Converts an image path to data URI
Checks if this is a GET request
Checks if this is a POST request
Joins multiple CSS files, and optionally minifies them
Joins multiple JavaScript files, and optionally minifies them
Redirects to the specified URL
Returns the requested $_REQUEST name-value pair if it exists
Returns the requested $_SESSION name-value pair if it exists
Returns a once value if it exists in $_SESSION. After the value is returned, it is deleted
Renders a template from app/views. If no extension is specified .phtml is added
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