/** * init() parses the resources array, determining the resource type from url * parameters set in the Request->resources array. * This method "delegates" requests to nested controllers. If an additional controller * is on the route, we stop processing and instantiate the next controller. * */ public function init() { $resourcesIterator = new SimpleIterator($this->resources); $resourcesData = $this->request->getResourceData(); $renderFlag = true; while ($resourcesIterator->hasNext()) { $resourceValue = $resourcesIterator->next(); if (!empty($resourcesData['CONTROLLERS'][$resourceValue])) { $renderFlag = false; $truncatedResources = $resourcesIterator->truncateFromIndex($resourcesIterator->getIndex()); $controller = new $resourcesData['CONTROLLERS'][$resourceValue]->className($truncatedResources); $controller->init(); return; } if (is_numeric($resourceValue)) { $this->request->setRequestedIds($resourceValue, $this->controllerName); continue; } if (is_string($resourceValue)) { //call setRequestedTag and then figure out what to do (method, fetch by value etc.) $this->request->setRequestedTag($resourceValue); } } if ($renderFlag) { $this->callMethod(); } }
/** * This method sets and returns an array of values to be used by the ORM. * It will filter API requests and DB requests, setting dependencies to be * handled by the Connectors for each. * * @param array $resourceArray * */ public function parseResources($resourceArray) { $rv = []; $resourcesIterator = new SimpleIterator($resourceArray); $current = $resourcesIterator->current(); while ($next = $resourcesIterator->next()) { $currentType = CoreApp::getResourceType($current); $nextType = CoreApp::getResourceType($next); $currentValid = $this->validateResource($current); if ($currentType == 'controller' && $currentValid) { $rv['joins'][] = $current; } if ($nextType == 'int' && $currentValid) { $rv['constraints'][] = (object) array("resource" => $current, "value" => $next); } $current = $next; } return $rv; }