@@ -28,95 +28,18 @@ public function __construct(array $params)
2828 // Extract API version
2929 $ apiEndpointVersion = explode ('/ ' , $ params ['apiBaseUrl ' ])[3 ];
3030
31- $ intApiVersion = $ this ->getIntApiVersion ($ apiEndpointVersion );
32-
3331 # Provide access to version specific API endpoints
34- if ($ intApiVersion >= $ this ->v1dot2IntApiVersion ()) {
35- throw new \Exception ('Unsupported API Version ( ' . @$ apiEndpointVersion . '). Please check for new versions of OSTSdk. ' );
36- } elseif ($ intApiVersion >= $ this ->v1dot1IntApiVersion ()) {
37- $ this ->services = new \OST \V1Dot1 \Manifest ($ params );
38- } elseif ($ intApiVersion >= $ this ->v1IntApiVersion ()) {
32+ if (is_null ($ apiEndpointVersion ) || $ apiEndpointVersion == '' ) {
33+ $ this ->services = new \OST \V0 \Manifest ($ params );
34+ } elseif (strtolower ($ apiEndpointVersion ) == 'v1 ' ) {
3935 $ this ->services = new \OST \V1 \Manifest ($ params );
36+ } elseif (strtolower ($ apiEndpointVersion ) == 'v1.1 ' ) {
37+ $ this ->services = new \OST \V1Dot1 \Manifest ($ params );
4038 } else {
41- $ this -> services = new \OST \ V0 \ Manifest ( $ params );
39+ throw new \Exception ( ' Api endpoint is invalid ' );
4240 }
4341
4442 }
4543
46- /**
47- * from API Version string generate a integer
48- *
49- * @param string $apiEndpointVersion api version from the URL
50- *
51- * @throws \Exception
52- *
53- * @return int
54- */
55- private function getIntApiVersion ($ apiEndpointVersion )
56- {
57-
58- if (empty ($ apiEndpointVersion )) {
59- return $ this ->v0IntApiVersion ();
60- }
61-
62- // apply regex match to check if version is in valid format
63- preg_match ('/^v(\d{1,3})\.?(\d{0,3})\.?(\*|\d{0,3})$/ ' , $ apiEndpointVersion , $ matches , PREG_OFFSET_CAPTURE );
64-
65- if (empty ($ matches )) {
66- throw new \Exception ('Api version ' . $ apiEndpointVersion . ' is invalid ' );
67- }
68-
69- $ intApiVersion = 0 ;
70-
71- $ intApiVersion += (int )$ matches [1 ][0 ] * 1000000 ;
72-
73- $ intApiVersion += (empty ($ matches [2 ][0 ]) ? 0 : (int )$ matches [2 ][0 ] * 1000 );
74-
75- $ intApiVersion += (empty ($ matches [3 ][0 ]) ? 0 : (int )$ matches [3 ][0 ]);
76-
77- return $ intApiVersion ;
78-
79- }
80-
81- /**
82- * Int API Version for V0
83- *
84- * @return int
85- */
86- private function v0IntApiVersion ()
87- {
88- return 0 ;
89- }
90-
91- /**
92- * Int API Version for V1.0
93- *
94- * @return int
95- */
96- private function v1IntApiVersion ()
97- {
98- return 1000000 ;
99- }
100-
101- /**
102- * Int API Version for V1.1
103- *
104- * @return int
105- */
106- private function v1dot1IntApiVersion ()
107- {
108- return 1001000 ;
109- }
110-
111- /**
112- * Int API Version for V1.2
113- *
114- * @return int
115- */
116- private function v1dot2IntApiVersion ()
117- {
118- return 1002000 ;
119- }
120-
12144
12245}
0 commit comments