Completed
Pull Request — master (#49)
by John
02:41
created

SwaggerDocument::getOperationObject()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 2
eloc 5
nc 2
nop 2
1
<?php
2
/*
3
 * This file is part of the KleijnWeb\SwaggerBundle package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace KleijnWeb\SwaggerBundle\Document;
10
11
use Symfony\Component\Yaml\Yaml;
12
13
/**
14
 * @author John Kleijn <[email protected]>
15
 */
16
class SwaggerDocument
17
{
18
    /**
19
     * @var string
20
     */
21
    private $uri;
22
23
    /**
24
     * @var object
25
     */
26
    private $definition;
27
28
    /**
29
     * @var OperationObject[]
30
     */
31
    private $operations;
32
33
    /**
34
     * @param string $pathFileName
35
     * @param object $definition
36
     */
37
    public function __construct($pathFileName, $definition)
38
    {
39
        $this->uri = $pathFileName;
40
        $this->definition = $definition;
41
    }
42
43
    /**
44
     * @return object
45
     */
46
    public function getDefinition()
47
    {
48
        return $this->definition;
49
    }
50
51
    /**
52
     * @return object
53
     */
54
    public function getPathDefinitions()
55
    {
56
        return $this->definition->paths;
57
    }
58
59
    /**
60
     * @param string $path
61
     * @param string $method
62
     *
63
     * @return OperationObject
64
     */
65
    public function getOperationObject($path, $method)
66
    {
67
        $key = "$path::$method";
68
69
        if (isset($this->operations[$key])) {
70
            return $this->operations[$key];
71
        }
72
73
        return $this->operations[$key] = new OperationObject($this, $path, $method);
74
    }
75
76
    /**
77
     * @deprecated
78
     *
79
     * @param string $path
80
     * @param string $method
81
     *
82
     * @return object
83
     */
84
    public function getOperationDefinition($path, $method)
85
    {
86
        return $this->getOperationObject($path, $method)->getDefinition();
87
    }
88
}
89