protected function setUp() { $this->object = new \Nethgui\Adapter\ParameterSet(); $this->arrayAdapter = $this->getMockBuilder('\\Nethgui\\Adapter\\ArrayAdapter')->disableOriginalConstructor()->getMock(); $this->scalarAdapter = $this->getMockBuilder('\\Nethgui\\Adapter\\ScalarAdapter')->disableOriginalConstructor()->getMock(); $this->object->addAdapter($this->arrayAdapter, 'arrayAdapter'); $this->object->addAdapter($this->scalarAdapter, 'scalarAdapter'); $this->object['inner'] = $this->getMock('\\Nethgui\\Adapter\\ParameterSet'); $this->object['pi'] = 3.14; }
/** * Declare a Module parameter. * * - A parameter is validated through $validationRule. It obtains its value * from $valueProvider. * - A value provider can be a callback function or an adapter object. * - The callback function can return the parameter value or an adapter * itself. * * NOTE: If you are using an adapter keep in mind that the * Host Configuration link is available after initialization only: don't * call in class constructor in this case! * * @see \Nethgui\System\PlatformInterface::getIdentityAdapter() * @see \Nethgui\System\PlatformInterface::getMapAdapter() * * @param string $parameterName The name of the parameter * @param mixed $validator Optional - A regular expression catching the correct value format OR An constant-integer corresponding to a predefined validator OR boolean FALSE for a readonly parameter * @param mixed $valueProvider Optional - A callback function, an adapter instance or an array of arguments to create an adapter * @return AbstractController */ protected function declareParameter($parameterName, $validator = FALSE, $valueProvider = NULL) { if (is_string($validator) && $validator[0] == '/') { $validator = $this->createValidator()->regexp($validator); } elseif ($validator === FALSE) { $validator = $this->createValidator()->forceResult(FALSE); } elseif (is_integer($validator)) { $validator = $this->createValidator($validator); } // At this point $validator MUST be an object implementing the right interface if (!$validator instanceof \Nethgui\System\ValidatorInterface) { throw new \InvalidArgumentException(sprintf('%s: Invalid validator instance for parameter `%s`', get_class($this), $parameterName), 1322149486); } $this->validators[$parameterName] = $validator; if (is_callable($valueProvider)) { // Create a read-only Map Adapter using $valueProvider as read-callback $this->parameters->addAdapter($this->getPlatform()->getMapAdapter($valueProvider, NULL, array()), $parameterName); } elseif ($valueProvider instanceof \Nethgui\Adapter\AdapterInterface) { $this->parameters->addAdapter($valueProvider, $parameterName); } elseif (is_array($valueProvider)) { $this->parameters[$parameterName] = $this->getAdapterForParameter($parameterName, $valueProvider); } elseif (is_null($valueProvider)) { $this->parameters[$parameterName] = NULL; } else { throw new \InvalidArgumentException(sprintf('%s: Invalid `valueProvider` argument', get_class($this)), 1322149487); } return $this; }