Download the PHP package cloudfoundry-community/cf-helper-php without Composer
On this page you can find all versions of the php package cloudfoundry-community/cf-helper-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cloudfoundry-community/cf-helper-php
More information about cloudfoundry-community/cf-helper-php
Files in cloudfoundry-community/cf-helper-php
Package cf-helper-php
Short Description Cloudfoundry helper in php
License MIT
Informations about the package cf-helper-php
cf-helper-php
An helper for php application inside cloudfoundry to access application and services bindings information without parsing the json-formatted VCAP_APPLICATION
or VCAP_SERVICES
env vars. This is similar to the https://www.npmjs.org/package/cfenv node package.
You will never have to do this again:
This helper works with official php buildpack.
Usage
This php application is published as a composer package. Fetch it by adding the following to your composer.json:
And include it the page you want to load:
You can access the service binding or application information through the service manager class
Get your service(s)
For example you have a service called database
with this credentials:
You can simply get your service like this:
Get Application's informations
Simply like this:
Get a connector
cf-helper-php
provide some connectors by auto-detecting.
It give you the possibility to have a PDO object when database is provided in services, or a Predis\Client object when you provide a redis (look at Predis ) or a MongoClient object when a mongodb is provided.
To get this access just follow this this:
You can directly get credentials by doing $cfHelper->get<TypeConnector>Connector()->getCredentials()
it will give you an array with:
- host
- port
- pass
- user
- url (if url is provided by the service)
- sentencePdo (only for database connector)
- database (only for database connector)
Example usage of pdo connector
Set php configuration
With cf-helper-php
we help you to set your php configuration, add in a new file in root project directory called cfhelper.json
a php-ini
variable and set your php configuration, example:
Set your php project in development mode
By default this two buildpacks hide error and it's not very good when you're in development phase.
With cf-helper-php
you can say that you are in development and app will do the rest and even show you error with filp/whoops package, to do that add in a new file in root project directory called cfhelper.json
a cfhelper
variable and put type
variable in developement
:
Simulate CloudFoundry environment
You can half simulate a CloudFoudry environment by using a manifest.yml
, your environment variable from manifest will be set in $_ENV
.
You can also add simulate service by adding a key called serviceSimulate
in your manifest.yml
, example:
To run CloudFoundry simulation simply do: