1+ <?php
2+ namespace Contentstack \Test ;
3+
4+ require_once __DIR__ . '/constants.php ' ;
5+
6+ use Contentstack \Config ;
7+
8+ class REST
9+ {
10+ private $ results = array ();
11+
12+ public function __construct () {
13+ $ myfile = fopen (RESULT_PATH , "r " ) or die ("Unable to open file! " );
14+ $ this ->results = json_decode (fread ($ myfile , filesize (RESULT_PATH )), true );
15+ fclose ($ myfile );
16+ }
17+
18+ /*
19+ * Remove system keys from the values
20+ * */
21+ public function sanatize ($ value = array ())
22+ {
23+ unset($ value ['SYS_ACL ' ]);
24+ unset($ value ['DEFAULT_ACL ' ]);
25+ unset($ value ['roles ' ]);
26+ return $ value ;
27+ }
28+
29+ /*
30+ * Set method is used to add the variable to the private variable of current instance
31+ * @param
32+ * string|$key - key which will hold the value
33+ * array|$value - value of the key
34+ * @return null
35+ * */
36+ public function set ($ key = '' , $ value = '' )
37+ {
38+ // unset values
39+ if (is_array ($ value ) && isset ($ value [0 ]) && is_array ($ value [0 ])) {
40+ foreach ($ value as $ k => $ val ) {
41+ $ val = $ this ->sanatize ($ val );
42+ $ value [$ k ] = $ val ;
43+ }
44+ } else {
45+ $ value = $ this ->sanatize ($ value );
46+ }
47+ // unset values
48+
49+ // before set get the data
50+ $ tmpValue = ($ this ->get ($ key )) ? $ this ->get ($ key ) : array ();
51+ $ this ->results [$ key ] = array_merge ($ value , $ tmpValue );
52+ }
53+
54+ /*
55+ * Get method is used to fetch the matched key's value of current instance
56+ * @param
57+ * string|$key - key which will hold the value
58+ * @return string|array|$value
59+ * */
60+ public function get ($ key = '' )
61+ {
62+ return ($ key && isset ($ this ->results [$ key ])) ? $ this ->results [$ key ] : array ();
63+ }
64+
65+ public function getAPIKEY () {
66+ $ stack = $ this ->get ('stack ' );
67+ return $ stack ['api_key ' ];
68+ }
69+
70+ public function getAccessToken () {
71+ $ stack = $ this ->get ('stack ' );
72+ if (gettype ($ stack ['delivery_token ' ]) === 'string ' ) {
73+ return $ stack ['delivery_token ' ];
74+ }
75+ return $ stack ['discrete_variables ' ]['access_token ' ];
76+ }
77+
78+ public function getEnvironmentName () {
79+ $ stack = $ this ->get ('stack ' );
80+ if (gettype ($ stack ['environment ' ]) === 'string ' ) {
81+ return $ stack ['environment ' ];
82+ }
83+ $ environment = $ this ->get ('environment ' );
84+ return $ environment ['name ' ];
85+ }
86+
87+ public function getHost () {
88+ $ host = $ this ->get ('host ' );
89+ if (gettype ($ host ) === 'string ' ) {
90+ return $ host ;
91+ }
92+ return NULL ;
93+ }
94+ }
95+
96+ function debug ($ input = array (), $ exit = false )
97+ {
98+ echo "<pre> " ;
99+ print_r ($ input );
100+ echo "</pre> " ;
101+ if ($ exit ) exit ();
102+ }
0 commit comments