1 | <?php |
||
8 | class NytController extends Controller |
||
9 | { |
||
10 | const API_URL = 'http://api.nytimes.com/svc'; |
||
11 | const RELATIVE_URL = '/books/v3/lists/overview.json?api-key={apiKey}'; |
||
12 | |||
13 | /** |
||
14 | * Instance of Guzzle Client |
||
15 | * @var object |
||
16 | */ |
||
17 | protected $client; |
||
18 | |||
19 | /** |
||
20 | * BaseUrl |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $baseUrl; |
||
24 | |||
25 | /** |
||
26 | * Initialize the Controller with necessary arguments |
||
27 | */ |
||
28 | public function __construct() |
||
34 | |||
35 | /** |
||
36 | * Get relative url |
||
37 | * |
||
38 | * @return string |
||
39 | */ |
||
40 | public function getRelativeUrl() |
||
44 | |||
45 | /** |
||
46 | * Get the response from New York times API |
||
47 | * @param string $relativeUrl |
||
48 | */ |
||
49 | private function setGetResponse($relativeUrl) |
||
53 | |||
54 | /** |
||
55 | * Get the whole response from a get operation |
||
56 | * @return array |
||
57 | */ |
||
58 | private function getResponse() |
||
62 | |||
63 | /** |
||
64 | * Get the data response from a get operation |
||
65 | * @return array |
||
66 | */ |
||
67 | private function getData() |
||
71 | |||
72 | /** |
||
73 | * Return all the data to the New York times API dashboard |
||
74 | * @return array |
||
75 | */ |
||
76 | public function getPage() |
||
82 | } |
||
83 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: