Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/vendor
/*.phar
/*.iml
composer.lock
86 changes: 68 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,28 +125,78 @@ With `cf-helper-php` you can say that you are in development and app will do the

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:

```yml
#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
You can simulate a CloudFoudry environment by using a `vcap.json`, your environment variable from manifest will be set in `$_ENV`. This JSON format will mimic what you would find in VCAP_APPLICATION and VCAP_SERVICES, with the addition of an 'ENV' parameter to add environment variables.

```json
{
"VCAP_SERVICES": {
"user-provided": [
{
"label": "user-provided",
"name": "managed-ELK-logging",
"tags": [],
"instance_name": "managed-ELK-logging",
"binding_name": null,
"credentials": {},
"syslog_drain_url": "syslog://tcplogs-epg.localdomain:5000",
"volume_mounts": []
}
],
"p.redis": [
{
"label": "p.redis",
"provider": null,
"plan": "cache-large",
"name": "redis-sessions",
"tags": [
"redis",
"pivotal",
"on-demand"
],
"instance_name": "redis-sessions",
"binding_name": null,
"credentials": {
"host": "q-s0.redis-instance.svc-dmd.service-instance-8e8fb07f-9c0b-4313-8748-0cf61f0ee989.bosh",
"password": "redispassword",
"port": 6379
},
"syslog_drain_url": null,
"volume_mounts": []
}
]
},
"VCAP_APPLICATION": {
"cf_api": "https://api.sys.pcf.localdomain",
"limits": {
"fds": 16384
},
"application_name": "api-active",
"application_uris": [
"api-qa.apps.pcf.localdomain"
],
"name": "api-active",
"space_name": "epg02-qa",
"space_id": "d3325332-9abb-4136-9232-f7e244f51817",
"organization_id": "4fe703b7-199c-4a63-aaa9-6261de724641",
"organization_name": "epg02-local-team",
"uris": [
"api-qa.apps.pcf.localdomain"
],
"users": null,
"application_id": "8bee55d9-5f5c-4d70-88a7-f1c159d9652e"
},
"ENV": {
"APPLICATION_VERSION": "1.0.0"
}
}

```

To run CloudFoundry simulation simply do:
```php
$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);
$cfHelper->simulateCloudFoundry(); //it use vcap.json which is in the same folder where this script is called
//to set another vcap.json:
$cfHelper->simulateCloudFoundry("your_vcap.json");
```


Expand Down
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
"CfCommunity\\CfHelper\\": "src/CfCommunity/CfHelper/"
}
},
"autoload-dev": {
"psr-4": {
"Test\\CfCommunity\\CfHelper\\": "tests/CfCommunity/CfHelper"
}
},
"suggest": {
"predis/predis": "Let's you have a redis connection for RedisConnector",
"mongodb/mongodb": "Use mongodb in for auto connection"
Expand Down
123 changes: 120 additions & 3 deletions src/CfCommunity/CfHelper/Application/ApplicationInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace CfCommunity\CfHelper\Application;


/**
* Class ApplicationInfo
* @package CfCommunity\CfHelper\Application
Expand All @@ -38,13 +37,36 @@ class ApplicationInfo
* @var int
*/
public $port;
/**
* @var string
*/
public $space_name;
/**
* @var string
*/
public $space_id;
/**
* @var string
*/
public $organization_name;
/**
* @var string
*/
public $organization_id;
/**
* @var string
*/
public $application_id;
/**
* @var object
*/
public $limits;

/**
*
*/
public function __construct()
{

}


Expand Down Expand Up @@ -128,4 +150,99 @@ public function setVersion($version)
$this->version = $version;
}

}
/**
* @return string
*/
public function getSpaceName()
{
return $this->space_name;
}

/**
* @param string $space_name
*/
public function setSpaceName(string $space_name)
{
$this->space_name = $space_name;
}

/**
* @return string
*/
public function getSpaceId()
{
return $this->space_id;
}

/**
* @param string $space_id
*/
public function setSpaceId(string $space_id)
{
$this->space_id = $space_id;
}

/**
* @return string
*/
public function getOrganizationName()
{
return $this->organization_name;
}

/**
* @param string $organization_name
*/
public function setOrganizationName(string $organization_name)
{
$this->organization_name = $organization_name;
}

/**
* @return string
*/
public function getOrganizationId()
{
return $this->organization_id;
}

/**
* @param string $organization_id
*/
public function setOrganizationId(string $organization_id)
{
$this->organization_id = $organization_id;
}

/**
* @return string
*/
public function getApplicationId()
{
return $this->application_id;
}

/**
* @param string $application_id
*/
public function setApplicationId(string $application_id)
{
$this->application_id = $application_id;
}

/**
* @return object
*/
public function getLimits()
{
return $this->limits;
}

/**
* @param object $limits
*/
public function setLimits(object $limits)
{
$this->limits = $limits;
}
}
19 changes: 14 additions & 5 deletions src/CfCommunity/CfHelper/CfHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
class CfHelper
{
const DETECT_CLOUDFOUNDRY = 'VCAP_APPLICATION';
private const DETECT_CLOUDFOUNDRY = 'VCAP_APPLICATION';

private $serviceManager;

Expand All @@ -46,6 +46,11 @@ class CfHelper
*/
private $connectorsState = array();

/**
* CfHelper constructor.
* @param ServiceManager|null $serviceManager
* @throws ConnectorNotUniqException
*/
public function __construct(ServiceManager $serviceManager = null)
{
if (empty($serviceManager)) {
Expand All @@ -57,6 +62,10 @@ public function __construct(ServiceManager $serviceManager = null)
$this->addConnector(new RedisConnector());
}

/**
* @param Connector $connector
* @throws ConnectorNotUniqException
*/
public function addConnector(Connector $connector)
{
if ($this->hasConnector($connector)) {
Expand Down Expand Up @@ -105,11 +114,11 @@ public function getApplicationInfo()
}

/**
* @param string $manifestYml
* @param string $jsonFile
*/
public function simulateCloudFoundry($manifestYml = "services.json")
public function simulateCloudFoundry($jsonFile = 'vcap.json')
{
CloudFoundrySimulator::simulate($manifestYml);
CloudFoundrySimulator::simulate($jsonFile);
}

public function isInCloudFoundry()
Expand Down Expand Up @@ -159,4 +168,4 @@ public function getConnector($name)
}
throw new ConnectorNotFoundException($name);
}
}
}
4 changes: 0 additions & 4 deletions src/CfCommunity/CfHelper/Connectors/AbstractUriConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@
* Date: 18/03/2015
*/


namespace CfCommunity\CfHelper\Connectors;


use CfCommunity\CfHelper\Services\Service;
use CfCommunity\CfHelper\Services\ServiceManager;

Expand Down Expand Up @@ -83,6 +81,4 @@ public function getCredentials()
{
return $this->credentials;
}


}
13 changes: 6 additions & 7 deletions src/CfCommunity/CfHelper/Connectors/Connector.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* Copyright (C) 2018 Arthur Halet
*
Expand All @@ -20,25 +19,25 @@ interface Connector
/**
*
*/
function load();
public function load();

/**
* @return mixed
*/
function getCredentials();
public function getCredentials();

/**
* @return mixed
*/
function getConnection();
public function getConnection();

/**
* @return string
*/
function getName();
public function getName();

/**
* @param ServiceManager $serviceManager
*/
function setServiceManager(ServiceManager $serviceManager);
}
public function setServiceManager(ServiceManager $serviceManager);
}
Loading