PHPackages                             cloudfoundry-community/cf-helper-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. cloudfoundry-community/cf-helper-php

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

cloudfoundry-community/cf-helper-php
====================================

Cloudfoundry helper in php

2.0.1(6y ago)1868.6k↓19.7%10[1 issues](https://github.com/cloudfoundry-community/cf-helper-php/issues)[2 PRs](https://github.com/cloudfoundry-community/cf-helper-php/pulls)1MITPHP

Since Mar 30Pushed 2y ago33 watchersCompare

[ Source](https://github.com/cloudfoundry-community/cf-helper-php)[ Packagist](https://packagist.org/packages/cloudfoundry-community/cf-helper-php)[ RSS](/packages/cloudfoundry-community-cf-helper-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (19)Used By (1)

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  node package. You will never have to do this again:

```
// Don't do this
$vcap_services = json_decode($_ENV['VCAP_SERVICES']);
```

This helper works with official [php buildpack](https://github.com/cloudfoundry/php-buildpack).

Usage
-----

[](#usage)

This php application is published as a composer package. Fetch it by adding the following to your composer.json:

```
"cloudfoundry-community/cf-helper-php": "^2.0"
```

And include it the page you want to load:

```
require_once __DIR__ .'/vendor/autoload.php';
use CfCommunity\CfHelper\CfHelper;
$cfHelper = new CfHelper();
```

You can access the service binding or application information through the service manager class

### Get your service(s)

[](#get-your-services)

For example you have a service called `database` with this credentials:

```
{
    "hostname": "localhost",
    "username": "jojo",
    "password": "toto",
    "port": "3306"
}
```

You can simply get your service like this:

```
$serviceManager = $cfHelper->getServiceManager();
$dbService = $serviceManager->getService('database'); //or regular expression example: getService('.*database.*')
//and for example get the host credential
$host = $dbService->getValue('hostname');//or regular expression example: getValue('ho[A-Za-z]+')

//get all your services
$services = $serviceManager->getAllServices();

//...
```

### Get Application's informations

[](#get-applications-informations)

Simply like this:

```
$applicationInfo = $cfHelper->getApplicationInfo();
$version = $applicationInfo->getVersion();
$name = $applicationInfo->getName();
$uris = $applicationInfo->getUris();

//for other information contains in VCAP_APPLICATION like limits get with that
$limits = $applicationInfo->limits;
```

### Get a connector

[](#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](https://github.com/nrk/predis) ) or a [MongoClient](http://php.net/manual/fr/class.mongodb.php) object when a mongodb is provided.

To get this access just follow this this:

```
$pdo = $cfHelper->getDatabaseConnector()->getConnection();
$redis = $cfHelper->getRedisConnector()->getConnection();
$mongodb = $cfHelper->getMongoDbConnector()->getConnection();
```

You can directly get credentials by doing `$cfHelper->getConnector()->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

[](#example-usage-of-pdo-connector)

```
require_once __DIR__ .'/vendor/autoload.php';
use CfCommunity\CfHelper\CfHelper;
$cfHelper = new CfHelper();

//if we are in cloud foundry we use the connection given by cf-helper-php otherwise we use our database in local
if ($cfHelper->isInCloudFoundry()) {
    $db = $cfHelper->getDatabaseConnector()->getConnection();
} else {
    $db = new PDO('mysql:host=localhost;dbname=mydbinlocal;charset=utf8', 'root', '');
}
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//...
```

Set php configuration
---------------------

[](#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:

```
"php-ini": {
    "display_errors": "On",
    "error_reporting": 24575, //equal to E_ALL & ~E_DEPRECATED
}
```

Set your php project in development mode
----------------------------------------

[](#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](https://github.com/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`:

```
//in cfhelper.json in your root project directory
"cfhelper":{
    "type": "development"
}
```

Simulate CloudFoundry environment
---------------------------------

[](#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:

```
#manifest.yml
---
#manifest
applications:
  - name: test
    memory: 1G
    env:
      MYAPP_APP_DIR: /home/vcap/app
      MYAPP_LOGS_DIR: /logs_dir
serviceSimulate:
  DATABASE: {"host": "localhost", "username": "jojo", "password": "toto", "port": "3306"} # a service database will be accessible, prefer writing with {'key": 'value'} to simplify your cups command
```

To run CloudFoundry simulation simply do:

```
$cfHelper->simulateCloudFoundry(); //it use manifest.yml which is in the same folder where this script is called
//to set another manifest.yml:
$cfHelper->simulateCloudFoundry("your_manifest.yml);
```

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity40

Moderate usage in the ecosystem

Community23

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 93.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~102 days

Recently: every ~262 days

Total

18

Last Release

2322d ago

Major Versions

1.7.0 → v2.x-dev2019-06-12

### Community

Maintainers

![](https://www.gravatar.com/avatar/b9ba88d407b0fba1107b4644f27fbabe80a816da59208e2907f7d3902c8f862d?d=identicon)[ArthurHlt](/maintainers/ArthurHlt)

---

Top Contributors

[![ArthurHlt](https://avatars.githubusercontent.com/u/5410858?v=4)](https://github.com/ArthurHlt "ArthurHlt (86 commits)")[![samuelchemla](https://avatars.githubusercontent.com/u/160230317?v=4)](https://github.com/samuelchemla "samuelchemla (4 commits)")[![Guilluxnow](https://avatars.githubusercontent.com/u/72024971?v=4)](https://github.com/Guilluxnow "Guilluxnow (1 commits)")[![nicolas-wallerand](https://avatars.githubusercontent.com/u/6265652?v=4)](https://github.com/nicolas-wallerand "nicolas-wallerand (1 commits)")

---

Tags

helperservicesCloudFoundryvcapservices

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/cloudfoundry-community-cf-helper-php/health.svg)

```
[![Health](https://phpackages.com/badges/cloudfoundry-community-cf-helper-php/health.svg)](https://phpackages.com/packages/cloudfoundry-community-cf-helper-php)
```

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[bryanjhv/slim-session

Session middleware and helper for Slim framework 4.

233961.5k16](/packages/bryanjhv-slim-session)[laravelista/ekko

Framework agnostic PHP package for marking navigation items active.

278673.4k4](/packages/laravelista-ekko)[sylius/registry

Services registry.

6211.0M40](/packages/sylius-registry)[beste/json

A simple JSON helper to decode and encode JSON

4222.7M3](/packages/beste-json)[chillerlan/php-settings-container

A container class for immutable settings objects. Not a DI container.

3427.3M21](/packages/chillerlan-php-settings-container)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
