Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
namespace Aws\Api;
3
 
4
/**
5
 * Represents an API operation.
6
 */
7
class Operation extends AbstractModel
8
{
9
    private $input;
10
    private $output;
11
    private $errors;
12
    private $staticContextParams = [];
13
    private $contextParams;
14
 
15
    public function __construct(array $definition, ShapeMap $shapeMap)
16
    {
17
        $definition['type'] = 'structure';
18
 
19
        if (!isset($definition['http']['method'])) {
20
            $definition['http']['method'] = 'POST';
21
        }
22
 
23
        if (!isset($definition['http']['requestUri'])) {
24
            $definition['http']['requestUri'] = '/';
25
        }
26
 
27
        if (isset($definition['staticContextParams'])) {
28
            $this->staticContextParams = $definition['staticContextParams'];
29
        }
30
 
31
        parent::__construct($definition, $shapeMap);
32
        $this->contextParams = $this->setContextParams();
33
    }
34
 
35
    /**
36
     * Returns an associative array of the HTTP attribute of the operation:
37
     *
38
     * - method: HTTP method of the operation
39
     * - requestUri: URI of the request (can include URI template placeholders)
40
     *
41
     * @return array
42
     */
43
    public function getHttp()
44
    {
45
        return $this->definition['http'];
46
    }
47
 
48
    /**
49
     * Get the input shape of the operation.
50
     *
51
     * @return StructureShape
52
     */
53
    public function getInput()
54
    {
55
        if (!$this->input) {
56
            if ($input = $this['input']) {
57
                $this->input = $this->shapeFor($input);
58
            } else {
59
                $this->input = new StructureShape([], $this->shapeMap);
60
            }
61
        }
62
 
63
        return $this->input;
64
    }
65
 
66
    /**
67
     * Get the output shape of the operation.
68
     *
69
     * @return StructureShape
70
     */
71
    public function getOutput()
72
    {
73
        if (!$this->output) {
74
            if ($output = $this['output']) {
75
                $this->output = $this->shapeFor($output);
76
            } else {
77
                $this->output = new StructureShape([], $this->shapeMap);
78
            }
79
        }
80
 
81
        return $this->output;
82
    }
83
 
84
    /**
85
     * Get an array of operation error shapes.
86
     *
87
     * @return Shape[]
88
     */
89
    public function getErrors()
90
    {
91
        if ($this->errors === null) {
92
            if ($errors = $this['errors']) {
93
                foreach ($errors as $key => $error) {
94
                    $errors[$key] = $this->shapeFor($error);
95
                }
96
                $this->errors = $errors;
97
            } else {
98
                $this->errors = [];
99
            }
100
        }
101
 
102
        return $this->errors;
103
    }
104
 
105
    /**
106
     * Gets static modeled static values used for
107
     * endpoint resolution.
108
     *
109
     * @return array
110
     */
111
    public function getStaticContextParams()
112
    {
113
        return $this->staticContextParams;
114
    }
115
 
116
    /**
117
     * Gets definition of modeled dynamic values used
118
     * for endpoint resolution
119
     *
120
     * @return array
121
     */
122
    public function getContextParams()
123
    {
124
        return $this->contextParams;
125
    }
126
 
127
    private function setContextParams()
128
    {
129
        $members = $this->getInput()->getMembers();
130
        $contextParams = [];
131
 
132
        foreach($members as $name => $shape) {
133
            if (!empty($contextParam = $shape->getContextParam())) {
134
                $contextParams[$contextParam['name']] = [
135
                    'shape' => $name,
136
                    'type' => $shape->getType()
137
                ];
138
            }
139
        }
140
        return $contextParams;
141
    }
142
}