/** * This method checks a given configuration. * @param array $inConfiguration List of parameters that define the configuration. * @return array If the given configuration is valid, then the method returns an empty array. * Otherwise, the method returns a list of error messages. */ public static function checkConfiguration(array $inConfiguration) { $set = new SpecificationsSet(); $set->addInputSpecification(new Specification(DocOption::DOC_PATH))->addInputSpecification(new Specification(DocOption::SCHEMA_PATH))->addInputSpecification(new Specification(EntryPointOption::PROC_BASE_NS))->addInputSpecification(new Specification(EntryPointOption::SQL_BASE_NS))->addInputSpecification(new Specification(EntryPointOption::PROC_REPO_PATH))->addInputSpecification(new Specification(EntryPointOption::SQL_REPO_PATH)); if ($set->check($inConfiguration)) { return []; } return array_values($set->getErrorsOnInputsInIsolationFromTheOthers()); }
/** * {@inheritdoc} * @see InterfaceConnector */ public static function checkConfiguration(array $inConfiguration) { $set = new SpecificationsSet(); foreach (self::getConfigurationParameters() as $_parameterSpec) { $name = $_parameterSpec[InterfaceConnector::OPTION_NAME]; $mandatory = $_parameterSpec[InterfaceConnector::OPTION_MANDATORY]; $set->addInputSpecification(new Specification($name, $mandatory, !$mandatory)); } if ($set->check($inConfiguration)) { return []; } return array_values($set->getErrorsOnInputsInIsolationFromTheOthers()); }
protected function setUp() { $validatorV1 = function ($inValue) { if (1 === preg_match('/^A|B|C$/', $inValue)) { return true; } return "The given value <{$inValue}> is not valid."; }; $validatorV2 = function ($inValue) { if (1 === preg_match('/^A|B|C$/', $inValue)) { return true; } return "The given value <{$inValue}> is not valid."; }; $this->__validator1 = $validatorV1; $this->__validator2 = $validatorV2; $this->__inputA = new Specification("A"); // Is not mandatory, may be null, no validator. $this->__inputB = new Specification("B"); // Is not mandatory, must not be null, no validator. $this->__inputV1 = new Specification("V1"); // Is not mandatory, must not be null, validator. $this->__inputC = new Specification("C"); // Is mandatory, may be null, no validator. $this->__inputD = new Specification("D"); // Is mandatory, must not be null, no validator. $this->__inputV2 = new Specification("V2"); // Is mandatory, must not be null, validator. $this->__inputA->setMandatory(false)->setCanBeNull(); $this->__inputB->setMandatory(false)->setCanNotBeNull(); $this->__inputV1->setMandatory(false)->setCanNotBeNull()->setValidator($validatorV1); $this->__inputC->setMandatory(true)->setCanBeNull(); $this->__inputD->setMandatory(true)->setCanNotBeNull(); $this->__inputV2->setMandatory(true)->setCanNotBeNull()->setValidator($validatorV2); $this->__set = new SpecificationsSet(); $this->__set->addInputSpecification($this->__inputA)->addInputSpecification($this->__inputB)->addInputSpecification($this->__inputC)->addInputSpecification($this->__inputD)->addInputSpecification($this->__inputV1)->addInputSpecification($this->__inputV2); }
return "The file which path is \"{$inPath}\" does not exist."; }; // We say that: // - The name of the input is "Path". // - The input is mandatory. // - The input can not be null. // - The input has a validator. $pathSpecification = new Specification("Path", true, false, $pathValidator); // You can also use mutators to specify an input. // The input named "token" is not mandatory and its value can be null. // It does not have any specific validator. $tokenSpecification = new Specification("Token"); $tokenSpecification->setMandatory(false)->setCanBeNull(); // Create a set of specifications. $set = new SpecificationsSet(); $set->addInputSpecification($pathSpecification)->addInputSpecification($tokenSpecification); // Print a summary. foreach ($set->inputsSummary() as $_name => $_summary) { echo "{$_name} => {$_summary}\n"; } // Note: you may specify a final validator. // If the file exists, and if a token is specified, then make sure that the token is found in the file. // If everything is OK, the validator must return an empty array. // Otherwise, it must return a list of errors' identifiers (you are free to return any kind of values...). // Note: here we return a list of error messages $finalValidator = function ($inInputs) { $data = file_get_contents($inInputs['Path']); if (array_key_exists('Token', $inInputs) && !is_null($inInputs['Token'])) { if (false === strstr($data, $inInputs['Token'])) { return ["The file " . $inInputs['Path'] . " exists, but it does not contain the token <" . $inInputs['Token'] . "> !"]; } else {