Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Rob Allen:
Notes for working on the OpenWhisk PHP Runtime
Jul 04, 2018 @ 15:19:03

Continuing the theme of posts related to using PHP on the OpenWhisk serverless platform, Rob Allen has posted a few notes for working with the PHP runtime.

These are some notes for working on the OpenWhisk PHP Runtime, but are probably applicable to the other runtimes too.

His notes cover:

  • some basic setup
  • building the two containers (PHP 7.1 and 7.2)
  • running tests
  • using the container interactively
  • checking the format of Scala files

Commands are included for each item along with some of the output to expect.

tagged: openwhisk runtime notes container test scala tutorial

Link: https://akrabat.com/notes-for-working-on-the-openwhisk-php-runtime/

Rob Allen:
Using Fractal as your OpenWhisk API's view layer
Jun 27, 2018 @ 14:49:40

Rob Allen continues his series of posts covering the use of PHP on the OpenWhisk platform. In his latest post he shows how to usr Fractal as the view layer for your application (as installed via Composer). Fractal is a project from the PHP League that "provides a presentation and transformation layer for complex data output, the like found in RESTful APIs, and works really well with JSON."

When writing an API, it’s common to produce an output that conforms to a known media type such as JSON API or HAL, etc. I’m a strong believer that even though I’m writing an API, my application has a view layer. It’s not the same as building an HTML page, but you still need to separate out the code that creates the structured output from your model layer. For a couple of APIs that I’ve written recently, I’ve used Fractal for this.

He starts with some example code showing how to use Fractal to transform data that's come from his datasource. This includes both the script to use the Manager and the class defining the "transformer" for the todo data. He then moves this over and integrates it with an OpenWhisk application, making use of the dependency injection container to create transformer and manager instances. His final example shows this setup in action as the result of a call to fetch all current todo items.

tagged: openwhisk view layer fractal phpleague tutorial json transform

Link: https://akrabat.com/using-fractal-as-your-apis-view-layer/

Rob Allen:
Dependency Injection with OpenWhisk PHP
Jun 20, 2018 @ 14:55:13

Rob Allen has continued his series of posts covering the use of PHP on the OpenWhisk platform. In his latest tutorial he shows how to use dependency injection for use in "non-trivial PHP applications".

Any non-trivial PHP applications use various components to do its work, from PDO though to classes from Packagist. It’s fairly common in a standard PHP application to use Dependency Injection to configure and load these classes when necessary. How do we do this in a serverless environment such as OpenWhisk?

This question comes up because we do not have a single entry point into our application, instead we have one entry point per action. If we’re using Serverless to write an API, then we probably

He uses a common connection type - PDO to a database - to illustrate a method for injecting dependencies in a serverless application. In his example, he starts with a simple script that returns a set of "todo" items from the database (with the PDO connection code embedded in it). Using dependency injection is a better way to manage that PDO connection so he shows how to update it to use the Pimple DI container and inject it via the constructor to make it available to the rest of the application.

tagged: dependency injection serverless openwhisk tutorial pdo database

Link: https://akrabat.com/di-with-openwhisk-php/

Rob Allen:
Using Composer with Serverless & OpenWhisk
Jun 12, 2018 @ 17:36:46

Rob Allen has posted a quick tutorial to his site showing how to user Composer in a PHP project on OpenWhisk. OpenWhisk is Apache's serverless cloud platform that's easy to scale and relatively easy to use. This is the latest in a series of posts from Rob covering its use in PHP projects.

Every PHP project I write has dependencies on components from Packagist and my Serverless OpenWhisk PHP projects are no different. It turns out that adding Composer dependencies is trivial.

He uses a simple action that coverts a number to the matching string, showing the yaml configuration changes and code to include to define the action. The action makes use of the NFNumberToWord package which is then added via Composer. He deploys the action and calls it directly, showing the result to be the correct string for the number "123". He also mentions an archive file (zip) that the serverless functionality creates containing all of the files related to the project. He shows the configuration option you can use to split these by action, making it easier to create a more modular system.

tagged: composer service openwhisk tutorial serverless deploy apache

Link: https://akrabat.com/using-composer-with-serverless-openwhisk/

Rob Allen:
Using Composer packages with OpenWhisk
Jan 03, 2018 @ 15:41:55

Rob Allen has a post to his site for the OpenWhisk (a serverless cloud platform) users out there that want to use Composer to install dependencies required by your application.

When creating new OpenWhisk actions in PHP, It's likely that you'll want to take advantage of the rich ecosystem of Composer packages on Packagist.org.

The OpenWhisk PHP runtime has you covered with some pre-installed Composer packages and also the ability to upload your own using a zip file.

He starts by mentioning the two packages that come installed by default: Guzzle and the ramsey/uuid library. He then gets into the upload of your own project files as a ZIP file and how to install the package locally, bundle it up into this archive and push it using the wsk command line tool.

tagged: composer package openwhisk serverless architecture packagist guzzle uuid tutorial

Link: https://akrabat.com/using-composer-packages-with-openwhisk/


Trending Topics: