1
|
|
|
<?php |
2
|
|
|
namespace Solvire\API\JSONSchema; |
3
|
|
|
|
4
|
|
|
use Solvire\Utilities\OptionsChecker as Ch; |
5
|
|
|
use Solvire\Application\Environment as Ev; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* |
9
|
|
|
* @author solvire <[email protected]> |
10
|
|
|
* @package JSONSchema |
11
|
|
|
* @namespace Solvire\API\JSONSchema |
12
|
|
|
*/ |
13
|
|
|
class JSONSchemaAppliance implements Schemable |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
protected $base = null; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* |
20
|
|
|
* @var ResourceCollection |
21
|
|
|
*/ |
22
|
|
|
protected $resources = null; |
23
|
|
|
|
24
|
3 |
|
public function __construct($baseOptions = null) |
25
|
|
|
{ |
26
|
3 |
|
$this->constructBase($baseOptions); |
27
|
3 |
|
$this->resources = new ResourceCollection(); |
28
|
3 |
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* |
32
|
|
|
* @param \Solvire\API\JSONSchema\Resource $resource |
33
|
|
|
* @return \Solvire\API\JSONSchema\JSONSchemaAppliance |
34
|
|
|
*/ |
35
|
|
|
public function registerResource(Resource $resource) |
36
|
|
|
{ |
37
|
|
|
if ($this->resources == null) |
38
|
|
|
$this->resources = new ResourceCollection(); |
39
|
|
|
|
40
|
|
|
$this->resources->add($resource); |
|
|
|
|
41
|
|
|
return $this; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* |
46
|
|
|
* @param array $options |
47
|
|
|
*/ |
48
|
3 |
|
public function constructBase(array $options = null) |
49
|
|
|
{ |
50
|
3 |
|
if (! isset($this->base)) |
51
|
3 |
|
$this->base = new Base(); |
52
|
|
|
|
53
|
3 |
|
$this->base->setBaseUrl(isset($options['baseUrl']) ? $options['baseUrl'] : Ev::get('API_BASE_URL')); |
|
|
|
|
54
|
3 |
|
$this->base->setBasePath(isset($options['basePath']) ? $options['basePath'] : Ev::get('API_BASE_PATH')); |
|
|
|
|
55
|
3 |
|
$this->base->setDocumentationUrl(isset($options['documentationUrl']) ? $options['documentationUrl'] : Ev::get('API_DOCUMENTATION_URL')); |
|
|
|
|
56
|
3 |
|
$this->base->setName(isset($options['applicationName']) ? $options['applicationName'] : Ev::get('APPLICATION_NAME')); |
|
|
|
|
57
|
3 |
|
$this->base->setId(isset($options['id']) ? $options['id'] : Ev::get('APPLICATION_NAME') . ":" . Ev::get('API_VERSION')); |
|
|
|
|
58
|
3 |
|
$this->base->setVersion(isset($options['version']) ? $options['version'] : Ev::get('API_VERSION')); |
|
|
|
|
59
|
3 |
|
$this->base->setDescription(isset($options['description']) ? $options['description'] : Ev::get('API_DESCRIPTION')); |
|
|
|
|
60
|
3 |
|
} |
61
|
|
|
|
62
|
|
|
public function setAuthScopes($auths) |
63
|
|
|
{ |
64
|
|
|
// these should be Auth collection |
65
|
|
|
foreach ($auths as $auth) { |
66
|
|
|
if (! ($auth instanceof Auth)) |
67
|
|
|
throw new \Exception("bad auth object"); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* (non-PHPdoc) |
73
|
|
|
* |
74
|
|
|
* @see \Solvire\API\JSONSchema\Schemable::allSet() |
75
|
|
|
*/ |
76
|
2 |
|
public function allSet() |
77
|
|
|
{ |
78
|
2 |
|
return $this->base->allSet(); |
79
|
|
|
} |
80
|
|
|
|
81
|
3 |
|
public function toSchema() |
82
|
|
|
{ |
83
|
3 |
|
return $this->base->toSchema(); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: