Skip to content

Commit 7be9041

Browse files
committed
Updating the generator to use a more advanced configuration file
1 parent 8953133 commit 7be9041

28 files changed

+1130
-518
lines changed

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
language: php
2-
32
dist: trusty
4-
53
sudo: false
64

75
php:
86
- 7.0
7+
- 7.1
8+
- 7.2
99

1010
matrix:
1111
include:
12-
- php: 7.0
12+
- php: 7.1
1313
env:
1414
- BUILD_PHAR=true
1515

@@ -23,4 +23,4 @@ deploy:
2323
skip_cleanup: true
2424
on:
2525
tags: true
26-
php: '7.0'
26+
php: '7.1'

bin/php-cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env php
12
<?php
23

34
if (PHP_SAPI !== 'cli') {
@@ -11,11 +12,8 @@ if (!(bool)getenv('PHPCS_PHAR')) {
1112
}
1213

1314
use MyENA\CloudStackClientGenerator\Application;
14-
use Symfony\Component\Console\Formatter\OutputFormatter;
15-
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
16-
use Symfony\Component\Console\Output\ConsoleOutput;
1715

1816
error_reporting(-1);
1917

20-
$application = new Application('PHP CloudStack', '3.0.0');
18+
$application = new Application('PHP CloudStack', '5.0.0');
2119
$application->run();

composer.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
"email": "bgabor@ena.com"
2626
}
2727
],
28-
2928
"autoload": {
3029
"psr-4": {
3130
"MyENA\\CloudStackClientGenerator\\": "src/"
@@ -34,7 +33,6 @@
3433
"files/constants.php"
3534
]
3635
},
37-
3836
"require": {
3937
"php": "^7.0",
4038
"symfony/console": "@stable",
@@ -46,10 +44,8 @@
4644
"guzzlehttp/guzzle": "@stable"
4745
},
4846
"require-dev": {
49-
"myena/default-logger": "@stable",
50-
"phpunit/phpunit": "@stable"
47+
"myena/default-logger": "@stable"
5148
},
52-
5349
"scripts": {
5450
"build": [
5551
"rm -rf vendor",

files/config_prototype.yml

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,35 @@
1212

1313
# php_cs_generator must be the root key
1414
php_cs_generator:
15-
dev: # Name of this config. Accessible via the "config-env" option
16-
scheme: "http"
17-
host: ~ # dev.ourcloudstack.com
18-
port: 8080
19-
apipath: "client/api"
20-
consolepath: "client/console"
21-
out: ~ # choose output path
22-
namespace: "\\MyGreatNamespace"
23-
key: ~ # your api key
24-
secret: ~ # your api secret
25-
prod:
26-
host: prod.ourcloudstack.com
27-
port: 8765
28-
key: ~ # your api key
29-
secret: ~ # your api secret
15+
# environment configuration
16+
environments:
17+
dev: # Name of this config. Accessible via the "env" option
18+
scheme: "http"
19+
host: ~ # dev.ourcloudstack.com
20+
port: 8080
21+
apipath: "client/api"
22+
consolepath: "client/console"
23+
out: ~ # choose output path
24+
namespace: "\\MyGreatNamespace"
25+
key: ~ # your api key
26+
secret: ~ # your api secret
27+
logger:
28+
class: ~ # psr-3 compliant logger instance
29+
level: ~ #level the environment's logger should be
30+
http_client:
31+
class: ~ # any class that implements \GuzzleHttp\ClientInterface
32+
config:
33+
allow_redirects: true
34+
http_errors: true
35+
verify: false
36+
prod:
37+
host: prod.ourcloudstack.com
38+
port: 8765
39+
key: ~ # your api key
40+
secret: ~ # your api secret
41+
# allows you to extend the classes constructed by this lib with your own class
42+
overloaded_classes:
43+
- name: Tags # name of class you are overloading
44+
overload: MyGreatTagsClass # fully qualified name of class extending the base class
45+
- name: ListVirtualMachinesRequest
46+
overload: DoSomethingCrazyRequest

src/Client.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,53 @@
33
use GuzzleHttp\Psr7\Request;
44
use GuzzleHttp\Psr7\Uri;
55
use GuzzleHttp\RequestOptions;
6+
use MyENA\CloudStackClientGenerator\Configuration\Environment;
67

78
/**
89
* Class Client
910
* @package MyENA\CloudStackClientGenerator
1011
*/
1112
class Client {
12-
/** @var \MyENA\CloudStackClientGenerator\Configuration */
13-
protected $config;
13+
/** @var \MyENA\CloudStackClientGenerator\Configuration\Environment */
14+
protected $env;
1415

1516
/**
1617
* Client constructor.
17-
* @param \MyENA\CloudStackClientGenerator\Configuration $c
18+
* @param \MyENA\CloudStackClientGenerator\Configuration\Environment $e
1819
*/
19-
public function __construct(Configuration $c) {
20-
$this->config = $c;
20+
public function __construct(Environment $e) {
21+
$this->env = $e;
2122
}
2223

2324
/**
2425
* @param string $command
2526
* @param array $parameters
2627
* @param array $headers
2728
* @return \stdClass
29+
* @throws \Exception
30+
* @throws \GuzzleHttp\Exception\GuzzleException
2831
*/
2932
public function do(string $command, array $parameters = [], array $headers = []): \stdClass {
3033
static $defaultHeaders =
3134
['Accept' => ['application/json'], 'Content-Type' => ['application/x-www-form-urlencoded']];
3235

33-
$params = ['apikey' => $this->config->getKey(), 'command' => $command, 'response' => 'json'] + $parameters;
36+
$params = ['apikey' => $this->env->getKey(), 'command' => $command, 'response' => 'json'] + $parameters;
3437

3538
ksort($params);
3639

3740
$query = http_build_query($params, '', '&', PHP_QUERY_RFC3986);
3841

3942
$uri = new Uri(sprintf(
4043
'%s/%s?%s&signature=%s',
41-
$this->config->getCompiledAddress(),
42-
$this->config->getApiPath(),
44+
$this->env->getCompiledAddress(),
45+
$this->env->getApiPath(),
4346
$query,
44-
$this->config->buildSignature($query)
47+
$this->env->buildSignature($query)
4548
));
4649

4750
$r = new Request('GET', $uri, $headers + $defaultHeaders);
4851

49-
$resp = $this->config->HttpClient->send($r, [
52+
$resp = $this->env->getHttpClient()->send($r, [
5053
RequestOptions::HTTP_ERRORS => false,
5154
RequestOptions::DECODE_CONTENT => false,
5255
]);

0 commit comments

Comments
 (0)