44 public static function factory($config, array $options = array())
47 if (!self::$descriptionLoader) {
52 return self::$descriptionLoader->load($config, $options);
58 public function __construct(array $config = array())
70 $this->operations = array();
71 $this->
fromArray(json_decode($json,
true));
77 'name' => $this->name,
78 'apiVersion' => $this->apiVersion,
79 'baseUrl' => $this->baseUrl,
80 'description' => $this->description
82 $result[
'operations'] = array();
84 $result[
'operations'][$operation->getName() ?:
$name] = $operation->toArray();
86 if (!empty($this->models)) {
87 $result[
'models'] = array();
88 foreach ($this->models as $id => $model) {
93 return array_filter($result);
117 foreach (array_keys($this->operations) as
$name) {
126 return isset($this->operations[
$name]);
132 if (!isset($this->operations[
$name])) {
140 return $this->operations[
$name];
159 if (!isset($this->models[$id])) {
163 if (!($this->models[$id] instanceof Parameter)) {
164 $this->models[$id] =
new Parameter($this->models[$id] + array(
'name' => $id), $this);
167 return $this->models[$id];
173 foreach (array_keys($this->models) as $id) {
182 return isset($this->models[$id]);
192 public function addModel(Parameter $model)
194 $this->models[$model->getName()] = $model;
216 return isset($this->extraData[$key]) ? $this->extraData[$key] :
null;
219 public function setData($key, $value)
221 $this->extraData[$key] = $value;
232 protected function fromArray(array $config)
235 static $defaultKeys = array(
'name',
'models',
'apiVersion',
'baseUrl',
'description');
237 foreach ($defaultKeys as $key) {
238 if (isset($config[$key])) {
239 $this->{$key} = $config[$key];
244 if (isset($config[
'basePath'])) {
245 $this->baseUrl = $config[
'basePath'];
249 $this->models = (array) $this->models;
250 $this->operations = (array) $this->operations;
253 $defaultKeys[] =
'operations';
256 if (isset($config[
'operations'])) {
257 foreach ($config[
'operations'] as
$name => $operation) {
258 if (!($operation instanceof
Operation) && !is_array($operation)) {
260 . gettype($operation));
262 $this->operations[
$name] = $operation;
267 foreach (array_diff(array_keys($config), $defaultKeys) as $key) {
268 $this->extraData[$key] = $config[$key];