/** * buildSimpleMethods * * @param $resourceName * @param $resourcePath * @param array $methodsAllowed * @param array $methods * * @return void */ protected function buildSimpleMethods($resourceName, $resourcePath, array $methodsAllowed, array $methods) { $methods = array_reverse($methods, true); foreach ($methods as $methodName => $methodProperties) { if (!in_array($methodName, $methodsAllowed)) { continue; } $methodOptions = new BasicOptions($methodProperties); $fullPath = $resourcePath . $methodOptions->get('path', '/' . $methodName); $controllerMethod = $methodOptions->get('controllerMethod', $methodName); $resourceKey = $this->getResourceKey($resourceName, $methodName, $controllerMethod); $this->addPath($fullPath, $methodOptions->get('httpVerb', 'GET'), $resourceKey); } }
/** * buildResourceOperationCollection * * @param string $resourceKey * * @return OperationCollection * @throws ResourceException */ protected function buildResourceOperationCollection($resourceKey) { if (array_key_exists($resourceKey, $this->operations)) { return $this->operations[$resourceKey]; } $resourceConfig = $this->getResourceConfig(); $resourceKeys = explode('::', $resourceKey); $resourceName = $resourceKeys[0]; $methodName = $resourceKeys[1]; $controllerMethod = $resourceKeys[2]; if (!array_key_exists($resourceName, $resourceConfig)) { throw new ResourceException('Resource config missing for ' . $resourceName); } /** @var Options $resourceOptions */ $resourceOptions = $resourceConfig[$resourceName]; $methods = $resourceOptions->get('methods', []); if (!array_key_exists($methodName, $methods)) { throw new ResourceException('Resource method config missing for ' . $methodName); } $operations = new BasicOperationCollection(); $methodOptions = new BasicOptions($methods[$methodName]); // Controller Pre $this->buildOperations($operations, $resourceOptions->get('preServiceNames', []), $resourceOptions->getOptions('preServiceOptions'), $resourceOptions->getOptions('preServicePriority')); // Method Pre $this->buildOperations($operations, $methodOptions->get('preServiceNames', []), $methodOptions->getOptions('preServiceOptions'), $methodOptions->getOptions('preServicePriority')); // ControllerMethod $controllerOptions = $resourceOptions->getOptions('controllerServiceOptions'); $controllerOptions->set('method', $controllerMethod); $operations->addOperation($this->buildOperation($resourceOptions->get('controllerServiceName'), $this->serviceManager->get($resourceOptions->get('controllerServiceName')), $controllerOptions, 1000)); // Method Post $this->buildOperations($operations, $methodOptions->get('postServiceNames', []), $methodOptions->getOptions('postServiceOptions'), $methodOptions->getOptions('postServicePriority')); // Controller Post $this->buildOperations($operations, $resourceOptions->get('postServiceNames', []), $resourceOptions->getOptions('postServiceOptions'), $resourceOptions->getOptions('postServicePriority')); $this->operations[$resourceKey] = $operations; return $this->operations[$resourceKey]; }