/** * Process the following URIs: * api/v1/truck_driver/ - to get all truck drivers. * api/v1/truck_driver/count/ - to get the total number of all drivers. * api/v1/truck_driver/{id}/ - to get a driver by ID. * api/v1/truck_driver/{id}/truck/ - to get a truck driver's truck. * @return TruckDriver|Truck */ private function process_truck_driver_get() { $truckDriverCtr = new TruckDriver_Controller(); // URI: api/v1/truck_driver/ if (empty($this->arguments) && $this->verb === '') { // Return truck drivers, if there are any, otherwise - null. if ($truckDrivers = $truckDriverCtr->get_all_truck_drivers()) { foreach ($truckDrivers as &$td) { $td = $td->get_all_fields(); } return $truckDrivers; } } else { // URI: api/v1/truck_driver/{action}/ if ($this->verb !== '') { // URI: api/v1/truck_driver/count/ if ($this->verb === 'count') { return $truckDriverCtr->count_truck_drivers(); } } elseif (count($this->arguments) === 1) { // Return a truck driver, if there is such, otherwise - null. if ($truckDriver = $truckDriverCtr->get_truck_driver_by_id($this->arguments[0])) { return $truckDriver->get_all_fields(); } } elseif (count($this->arguments) === 2 && $this->arguments[1] === 'truck') { $tctr = new Truck_Controller(); // Return a truck driver's truck, if they have such, otherwise - null. if ($truck = $tctr->get_truck_driver_truck($this->arguments[0])) { return $truck->get_all_fields(); } } } return null; }