Skip to content

Commit 6f575e9

Browse files
author
Jamie Hannaford
committed
Merge branch 'new-func'
2 parents 32c329c + 2ddb87c commit 6f575e9

File tree

21 files changed

+262
-225
lines changed

21 files changed

+262
-225
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.idea/
2+
.test/
23
coverage/
34
vendor/
45

src/Common/Api/AbstractParams.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ abstract class AbstractParams
1414
// types
1515
const STRING_TYPE = "string";
1616
const BOOL_TYPE = "boolean";
17+
const BOOLEAN_TYPE = self::BOOL_TYPE;
1718
const OBJECT_TYPE = "object";
1819
const ARRAY_TYPE = "array";
1920
const NULL_TYPE = "NULL";
2021
const INT_TYPE = 'integer';
22+
const INTEGER_TYPE = self::INT_TYPE;
2123

2224
public static function isSupportedLocation($val)
2325
{

src/Common/Api/Parameter.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,6 @@ public function __construct(array $data)
125125
{
126126
$this->hydrate($data);
127127

128-
if (!$this->type) {
129-
$this->type = 'string';
130-
}
131-
132128
$this->required = (bool)$this->required;
133129

134130
$this->stockLocation($data);
@@ -272,7 +268,7 @@ private function hasCorrectType($userValue)
272268
{
273269
// Helper fn to see whether an array is associative (i.e. a JSON object)
274270
$isAssociative = function ($value) {
275-
return is_array($value) && (bool)count(array_filter(array_keys($value), 'is_string'));
271+
return is_array($value) && array_keys($value) !== range(0, count($value) - 1);
276272
};
277273

278274
// For params defined as objects, we'll let the user get away with
@@ -285,6 +281,10 @@ private function hasCorrectType($userValue)
285281
return is_a($userValue, $this->type);
286282
}
287283

284+
if (!$this->type) {
285+
return true;
286+
}
287+
288288
return gettype($userValue) == $this->type;
289289
}
290290

src/Common/HydratorStrategyTrait.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,12 @@ private function hydrate(array $data, array $aliases = [])
2424
}
2525
}
2626
}
27+
28+
private function set($key, $property, array $data, callable $fn = null)
29+
{
30+
if (isset($data[$key]) && property_exists($this, $property)) {
31+
$value = $fn ? call_user_func($fn, $data[$key]) : $data[$key];
32+
$this->$property = $value;
33+
}
34+
}
2735
}

src/Common/Resource/AbstractResource.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ private function parseDocBlockValue($type, $val)
116116
private function isNotNativeType($type)
117117
{
118118
return !in_array($type, [
119-
'string', 'bool', 'boolean', 'null', 'array', 'object', 'int', 'integer', 'float', 'numeric', 'mixed'
119+
'string', 'bool', 'boolean', 'double', 'null', 'array', 'object', 'int', 'integer', 'float', 'numeric',
120+
'mixed'
120121
]);
121122
}
122123

src/Common/Resource/HasWaiterTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ private function shouldHalt($timeout, $startTime)
9595
* or exceed this timeout, the blocking operation will immediately cease. If FALSE
9696
* is provided, the timeout will never be considered.
9797
*/
98-
public function waitUntilActive($timeout = 60)
98+
public function waitUntilActive($timeout = false)
9999
{
100-
$this->waitUntil('ACTIVE');
100+
$this->waitUntil('ACTIVE', $timeout);
101101
}
102102

103103
public function waitUntilDeleted($timeout = 60, $sleepPeriod = 1)

src/Common/Service/Builder.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use GuzzleHttp\Client;
66
use GuzzleHttp\ClientInterface;
77
use GuzzleHttp\Middleware as GuzzleMiddleware;
8-
use OpenStack\Common\Auth\ServiceUrlResolver;
98
use OpenStack\Common\Auth\Token;
109
use OpenStack\Common\Transport\HandlerStack;
1110
use OpenStack\Common\Transport\Middleware;
@@ -26,6 +25,9 @@ class Builder
2625
*/
2726
private $globalOptions = [];
2827

28+
/** @var string */
29+
private $rootNamespace;
30+
2931
/**
3032
* Defaults that will be applied to options if no values are provided by the user.
3133
*
@@ -38,9 +40,10 @@ class Builder
3840
* Eventually they will be merged (and if necessary overridden) by the
3941
* service-specific options passed in.
4042
*/
41-
public function __construct(array $globalOptions = [])
43+
public function __construct(array $globalOptions = [], $rootNamespace = 'OpenStack')
4244
{
4345
$this->globalOptions = $globalOptions;
46+
$this->rootNamespace = $rootNamespace;
4447
}
4548

4649
/**
@@ -53,7 +56,7 @@ public function __construct(array $globalOptions = [])
5356
*/
5457
private function getClasses($serviceName, $serviceVersion)
5558
{
56-
$rootNamespace = sprintf("OpenStack\\%s\\v%d", $serviceName, $serviceVersion);
59+
$rootNamespace = sprintf("%s\\%s\\v%d", $this->rootNamespace, $serviceName, $serviceVersion);
5760

5861
return [
5962
sprintf("%s\\Api", $rootNamespace),
@@ -164,4 +167,4 @@ private function mergeOptions(array $serviceOptions)
164167

165168
return $options;
166169
}
167-
}
170+
}

src/Compute/v2/Models/Server.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ class Server extends AbstractResource implements
8585

8686
protected $aliases = [
8787
'block_device_mapping_v2' => 'blockDeviceMapping',
88-
'accessIPv4' => 'ipv4',
89-
'accessIPv6' => 'ipv6',
90-
'tenant_id' => 'tenantId',
91-
'user_id' => 'userId',
92-
'security_groups' => 'securityGroups',
93-
'OS-EXT-STS:task_state' => 'taskState',
88+
'accessIPv4' => 'ipv4',
89+
'accessIPv6' => 'ipv6',
90+
'tenant_id' => 'tenantId',
91+
'user_id' => 'userId',
92+
'security_groups' => 'securityGroups',
93+
'OS-EXT-STS:task_state' => 'taskState',
9494
];
9595

9696
/**
@@ -141,7 +141,7 @@ public function changePassword($newPassword)
141141
{
142142
$this->execute($this->api->changeServerPassword(), [
143143
'id' => $this->id,
144-
'password' => $newPassword
144+
'password' => $newPassword,
145145
]);
146146
}
147147

@@ -171,7 +171,7 @@ public function rebuild(array $options)
171171
{
172172
$options['id'] = $this->id;
173173
$response = $this->execute($this->api->rebuildServer(), $options);
174-
174+
175175
$this->populateFromResponse($response);
176176
}
177177

@@ -184,7 +184,7 @@ public function rebuild(array $options)
184184
public function resize($flavorId)
185185
{
186186
$response = $this->execute($this->api->resizeServer(), [
187-
'id' => $this->id,
187+
'id' => $this->id,
188188
'flavorId' => $flavorId,
189189
]);
190190

src/Identity/v2/Api.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
/**
88
* Represents the OpenStack Identity v2 API.
99
*
10-
* @internal
1110
* @package OpenStack\Identity\v2
1211
*/
1312
class Api implements ApiInterface

src/Identity/v2/Service.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace OpenStack\Identity\v2;
44

5+
use GuzzleHttp\ClientInterface;
56
use OpenStack\Common\Auth\IdentityService;
67
use OpenStack\Common\Service\AbstractService;
78
use OpenStack\Identity\v2\Models\Catalog;
@@ -14,6 +15,11 @@
1415
*/
1516
class Service extends AbstractService implements IdentityService
1617
{
18+
public static function factory(ClientInterface $client)
19+
{
20+
return new static($client, new Api());
21+
}
22+
1723
public function authenticate(array $options = [])
1824
{
1925
$definition = $this->api->postToken();

0 commit comments

Comments
 (0)