private function setParamProcessor($paramProcessor) { if ($paramProcessor === null) { $paramProcessor = Processor::newDefault(); } $this->paramProcessor = $paramProcessor; }
private function getProcessedParams(HookDefinition $definition, array $rawParams) { $processor = Processor::newDefault(); $processor->setParameters($rawParams, $definition->getParameters()); $params = array(); foreach ($processor->processParameters()->getParameters() as $param) { $params[$param->getName()] = $param->getValue(); } return $params; }
/** * @dataProvider processingProvider * @since 3.0 */ public function testParamProcessing(array $parameters, array $expectedValues) { $definitions = $this->getInstance()->getParamDefinitions(); $processor = Processor::newDefault(); $processor->setParameters($parameters, $definitions); $result = $processor->processParameters(); if ($result->hasFatal()) { $this->fail('Fatal error occurred during the param processing: ' . $processor->hasFatalError()->getMessage()); } $actual = $result->getParameters(); $expectedValues = array_merge($this->getDefaultValues(), $expectedValues); foreach ($expectedValues as $name => $expected) { $this->assertArrayHasKey($name, $actual); $this->assertEquals($expected, $actual[$name]->getValue(), 'Expected ' . var_export($expected, true) . ' should match actual ' . var_export($actual[$name]->getValue(), true)); } }
/** * @since 1.0 * * @param string $coordinates * @param string $inputName * @param boolean $isMandatory * @param boolean $isDisabled * @param array $params * * @return string */ public function getInputOutput($coordinates, $inputName, $isMandatory, $isDisabled, array $params) { $parameters = array(); foreach ($params as $key => $value) { if (!is_array($value) && !is_object($value) && !is_null($value)) { $parameters[$key] = $value; } } if (!is_null($coordinates)) { $parameters['locations'] = $coordinates; } $validator = Processor::newDefault(); $validator->setParameters($parameters, $this->getParameterInfo()); $processingResult = $validator->processParameters(); if ($processingResult->hasFatal()) { return $this->getFatalOutput($validator->getErrors()); } else { return $this->getMapOutput($validator->getParameterValues(), $inputName); } }
/** * Takes care of validation and rendering, and returns the output. * * @since 0.4 * * @param array $arguments * @param integer $type Item of the ParserHook::TYPE_ enum * * @return string */ public function validateAndRender(array $arguments, $type) { $names = $this->getNames(); $this->validator = Processor::newDefault(); $this->validator->getOptions()->setName($names[0]); if ($type === self::TYPE_FUNCTION) { $this->validator->setFunctionParams($arguments, $this->getParameterInfo($type), $this->getDefaultParameters($type)); } else { $this->validator->setParameters($arguments, $this->getParameterInfo($type)); } $this->validator->validateParameters(); $fatalError = $this->validator->hasFatalError(); if ($fatalError === false) { $output = $this->render($this->validator->getParameterValues()); } else { $output = $this->renderFatalError($fatalError); } return $output; }
public function testNewDefault() { $this->assertInstanceOf('ParamProcessor\\Processor', Processor::newDefault()); }
/** * Validates the layer. * * @since 0.7.1 */ protected function validate() { if ($this->hasValidated) { return; } $this->hasValidated = true; $validator = Processor::newDefault(); $validator->setParameters($this->properties, $this->getParameterDefinitions()); $validator->validateParameters(); if ($validator->hasErrors() !== false) { $this->errors = $validator->getErrors(); } $params = $validator->getParameterValues(); $this->properties = $params; }