/** * Add a method to get a parameter of this operation after it has been filtered. * @throws APIBuilderException */ function addFilteredParameterMethod() { $methodGenerator = new MethodGenerator('getFilteredParameter'); $body = 'if (array_key_exists($name, $this->parameters) == false) {' . PHP_EOL; //TODO - make this be the correct type $body .= ' throw new \\Exception(\'Parameter \'.$name.\' does not exist.\');' . PHP_EOL; $body .= '}' . PHP_EOL; $body .= '' . PHP_EOL; $body .= '$value = $this->parameters[$name];' . PHP_EOL; $body .= '' . PHP_EOL; $paramFilterBlocks = []; foreach ($this->operationDefinition->getParameters() as $parameter) { $parameterFilters = $parameter->getFilters(); if (count($parameterFilters)) { //Only generate the filter block if a filter actually need to be applied $paramFilterBlocks[] = $this->generateParamFilterBlock($parameter); } } if (count($paramFilterBlocks)) { $body .= 'switch ($name) {' . PHP_EOL; $body .= '' . PHP_EOL; foreach ($paramFilterBlocks as $paramFilterBlock) { $body .= $paramFilterBlock . PHP_EOL; $body .= '' . PHP_EOL; } $body .= ' default:{}' . PHP_EOL; $body .= '' . PHP_EOL; $body .= '}' . PHP_EOL; } $body .= '' . PHP_EOL; $body .= 'return $value;' . PHP_EOL; $methodGenerator->setBody($body); $docBlock = $this->generateExecuteDocBlock('Apply any filters necessary to the parameter'); $parameterGenerator = new ParameterGenerator('name', 'string'); $methodGenerator->setParameter($parameterGenerator); $tag = createParamTag($parameterGenerator, "The name of the parameter to get."); $docBlock->setTag($tag); $methodGenerator->setDocBlock($docBlock); $this->classGenerator->addMethodFromGenerator($methodGenerator); }