/** * Generates the actual interfaces */ public function generate() { $interfacesData = json_decode($this->json, true); foreach ($interfacesData as $interface) { $filename = $interface['name'] . '.java'; $interfaceObject = new JAVAInterfaceObject(); $interfaceObject->setName($interface['name']); foreach ($interface['methods'] as $method) { $methodObject = new JAVAMethod(); $methodObject->setName($method['name']); $methodObject->setReturnValue($method['returnType']); $methodObject->setScope($method['scope']); $methodObject->setComment($method['comment']); foreach ($method['parameters'] as $parameter) { $parameterObject = new Parameter(); $parameterObject->setName($parameter['name']); $parameterObject->setType($parameter['type']); $methodObject->addParameter($parameterObject); } foreach ($method['annotations'] as $annotation) { $annotationObject = new Annotation(); $annotationObject->setName($annotation['name']); $annotationObject->setValue($annotation['value']); $annotationObject->setInterpreter('@'); $methodObject->addAnnotation($annotationObject); } $interfaceObject->addMethod($methodObject); } file_put_contents($this->folder . DIRECTORY_SEPARATOR . $filename, $interfaceObject->toString()); } }
/** * @param \hergot\databroker\DataAdapter\Parameter $parameter * @throws \InvalidArgumentException */ public function addParameter(Parameter $parameter) { if (isset($this->parameters[$parameter->getName()])) { throw new \InvalidArgumentException('Parameter with name "' . $parameter->getName() . '" already defined'); } $this->parameters[$parameter->getName()] = $parameter; }
/** * @see ItemParameterManipulation::doManipulation * * @since 0.7.5 */ public function doManipulation(&$value, Parameter $parameter, array &$parameters) { global $egMapsDefaultGeoService; static $validatedDefault = false; if (!MapsGeocoders::canGeocode()) { throw new MWException('There are no geocoders registered, so no geocoding can happen.'); } // Get rid of any aliases. $value = $this->getMainIndentifier($value); // Override the defaulting. if ($parameter->wasSetToDefault() && is_string($this->mappingServiceParam) && array_key_exists($this->mappingServiceParam, $parameters)) { $value = self::resolveOverrides($value, $parameters[$this->mappingServiceParam]->getValue()); } if ($value === '' || !array_key_exists($value, MapsGeocoders::$registeredGeocoders)) { if (!$validatedDefault) { if (!array_key_exists($egMapsDefaultGeoService, MapsGeocoders::$registeredGeocoders)) { $geoServices = array_keys(MapsGeocoders::$registeredGeocoders); $egMapsDefaultGeoService = array_shift($geoServices); if (is_null($egMapsDefaultGeoService)) { throw new MWException('Tried to geocode while there are no geocoders available at ' . __METHOD__); } } } if (array_key_exists($egMapsDefaultGeoService, MapsGeocoders::$registeredGeocoders)) { $value = $egMapsDefaultGeoService; } else { throw new MWException('Attempt to use the default geocoder while it does not exist.'); } } }
/** * @see ItemParameterManipulation::doManipulation * * @since 0.4 */ public function doManipulation(&$value, Parameter $parameter, array &$parameters) { // When the value defaulted to a boolean, there is no need for this manipulation. if (!is_bool($value) || !$parameter->wasSetToDefault()) { $value = in_array($value, array('yes', 'on')); } }
/** * * @param Parameter $parameter * @return void * @throws \InvalidArgumentException */ private function addParameter(Parameter $parameter) { $name = $parameter->getDefinition()->getName(); if (array_key_exists($name, $this->parameters)) { throw new \InvalidArgumentException("Parameter '{$name}' provided multiple times."); } $this->parameters[$name] = $parameter; }
public function addParameter(Parameter $parameter, $in = true) { if ($in) { $this->inputParameters[$parameter->getName()] = $parameter; } else { $this->outputParameters[$parameter->getName()] = $parameter; } }
public function testWithersReturnNewModifiedInstance() { $parameter = new Parameter('foo', 'bar'); $newParam = $parameter->withValue('rab'); $this->assertNotSame($newParam, $parameter); $this->assertEquals('bar', $parameter->getValue()); $this->assertEquals('rab', $newParam->getValue()); }
/** * @see ItemParameterManipulation::doManipulation * * @since 0.7 */ public function doManipulation(&$value, Parameter $parameter, array &$parameters) { // If there are multiple points and the value was not provided or incorrect (=defaulted), // set it to false, so the mapping service can figure out the optimal value. if ($parameter->wasSetToDefault() && count($parameters['coordinates']->getValue()) > 1) { $value = false; } }
/** * @see ItemParameterCriterion::getItemErrorMessage */ protected function getItemErrorMessage(Parameter $parameter) { global $wgLang; if ($this->lowerBound == $this->upperBound) { return wfMsgExt('validator-error-invalid-length', 'parsemag', $parameter->getOriginalName(), $wgLang->formatNum($this->lowerBound)); } else { return wfMsgExt('validator-error-invalid-length-range', 'parsemag', $parameter->getOriginalName(), $wgLang->formatNum($this->lowerBound), $wgLang->formatNum($this->upperBound)); } }
/** * Validate a parameter against the criterion. * * @param Parameter $parameter * @param array $parameters * * @since 0.4 */ public function manipulate(Parameter &$parameter, array &$parameters) { if (is_array($parameter->getValue())) { $value =& $parameter->getValue(); foreach ($value as &$item) { $this->doManipulation($item, $parameter, $parameters); } } else { $this->doManipulation($parameter->getValue(), $parameter, $parameters); } }
/** * Adds a parameter to the widget * * @param Parameter $new_parameter * @return void */ public function addParameter($new_parameter) { if (!$new_parameter instanceof Parameter) { throw new \MWException('Method addParameter() of widget ' . static::GetName() . ' requires an argument of type "Parameter".'); } $new_parameter_name = $new_parameter->getName(); if (array_key_exists($new_parameter_name, $this->parameters)) { throw new \MWException('Cannot add parameter "' . $new_parameter_name . '". Each parameter needs a disctinct name.'); } $this->parameters[$new_parameter_name] = $new_parameter; }
public function defineParameter($key, $type, $label, $default = null) { if (isset($this->parameter[$key])) { throw new \InvalidArgumentException('Parameter already define in bag: ' . $key); } $parameter = new Parameter(); $parameter->setKey($key); $parameter->setType($type); $parameter->setLabel($label); $parameter->setDefault($default); $this->parameter[$key] = $parameter; }
public function testRequirementParameterSuccess() { $parameter = new Parameter(); $parameter->name = "NEEDLE_LENGTH"; $parameter->type = "float"; $parameter->widget = null; $parameter->value = null; $parameter->priority = 2; $parameter->paramable_id = '-1'; $parameter->paramable_type = ''; $this->assertTrue($parameter->save()); }
/** * @see ParameterManipulation::manipulate * * @since 1.0.1 */ public function manipulate(Parameter &$parameter, array &$parameters) { if (!in_array($parameters['type']->getValue(), $parameter->getValue())) { if ($parameters['type']->wasSetToDefault()) { if (count($parameter->getValue()) > 0) { $types = $parameter->getValue(); $parameters['type']->setValue($types[0]); } } else { array_unshift($parameter->getValue(), $parameters['type']->getValue()); } } }
private function setParameter(Parameter $param) { $set_param_head = 'SET_PARAM ' . $param->getKey(); try { if ($param->isRawValue()) { $raw_value = self::BEGIN_RAW . "\n" . base64_encode($param->getValue()) . "\n" . self::END_RAW; return $this->socket_client->request($set_param_head . ' ' . self::RAW_VALUE_ANNOUNCMENT . "\n" . $raw_value); } else { return $this->socket_client->request($set_param_head . ' ' . $param->getValue()); } } catch (\Exception $e) { throw $e; } }
/** * @see ParameterManipulation::manipulate * * @since 0.7 */ public function manipulate(Parameter &$parameter, array &$parameters) { global $egMapsOLLayerGroups, $egMapsOLAvailableLayers; $layerDefs = array(); $layerNames = array(); foreach ($parameter->getValue() as $layerOrGroup) { $lcLayerOrGroup = strtolower($layerOrGroup); // Layer groups. Loop over all items and add them when not present yet. if (array_key_exists($lcLayerOrGroup, $egMapsOLLayerGroups)) { foreach ($egMapsOLLayerGroups[$lcLayerOrGroup] as $layerName) { if (!in_array($layerName, $layerNames)) { if (is_array($egMapsOLAvailableLayers[$layerName])) { $layerDefs[] = 'new ' . $egMapsOLAvailableLayers[$layerName][0]; } else { $layerDefs[] = 'new ' . $egMapsOLAvailableLayers[$layerName]; } $layerNames[] = $layerName; } } } elseif (array_key_exists($lcLayerOrGroup, $egMapsOLAvailableLayers)) { if (!in_array($lcLayerOrGroup, $layerNames)) { if (is_array($egMapsOLAvailableLayers[$lcLayerOrGroup])) { $layerDefs[] = 'new ' . $egMapsOLAvailableLayers[$lcLayerOrGroup][0]; } else { $layerDefs[] = 'new ' . $egMapsOLAvailableLayers[$lcLayerOrGroup]; } $layerNames[] = $lcLayerOrGroup; } } else { $title = Title::newFromText($layerOrGroup, Maps_NS_LAYER); if ($title->getNamespace() == Maps_NS_LAYER && $title->exists()) { $layerPage = new MapsLayerPage($title); if ($layerPage->hasValidDefinition('openlayers')) { $layer = $layerPage->getLayer(); if (!in_array($layerOrGroup, $layerNames)) { $layerDefs[] = $layer->getJavaScriptDefinition(); $layerNames[] = $layerOrGroup; } } else { wfWarn("Invalid layer ({$layerOrGroup}) encountered after validation."); } } else { wfWarn("Invalid layer ({$layerOrGroup}) encountered after validation."); } } } $parameter->setValue($layerDefs); MapsMappingServices::getServiceInstance('openlayers')->addLayerDependencies($this->getDependencies($layerNames)); }
public function parse($ex_file, $s_file) { global $VERSION; $css = file_get_contents($s_file); $ex = parse_ini_file($ex_file, TRUE); print "<style>"; print "\n/* Generated by exCSS v." . $VERSION . "*/\n"; if (isset($ex['ExtendedCSS'])) { while ($cur = current($ex['ExtendedCSS'])) { $var = key($ex['ExtendedCSS']); $var_value = $ex['ExtendedCSS'][$var]; $css = str_replace("\$" . $var, $var_value, $css); next($ex['ExtendedCSS']); } } if (isset($ex['Grid'])) { $parts = $ex['Grid']['grid-parts']; // how many parts like 1 or 4 $height = $ex['Grid']['grid-height']; // height like 50% or 100% $props = $ex['Grid']['grid-props']; // proportions like 1-2-1 or 2-3-2 $grid = new Grid($parts, $height, $props); } foreach (array_keys($ex) as $x) { if ($x == 'Grid' || $x == 'ExtendedCSS') { continue; } // now there can only be things like .div1 or #div2 or div if (isset($ex["Grid"])) { if (isset($ex[$x]['grid-position'])) { $element_data = $grid->generateCSS($x, $ex[$x]['grid-position']); print $element_data; } } if (isset($ex[$x]["animation"])) { $object = $x; $anim_name = $ex[$x]["animation"]; $par = explode(';', $ex[$x]['animation-parameter']); $parameter = new Parameter(); foreach ($par as $i) { $temp = explode(':', $i); $parameter->add($temp[0], $temp[1]); } $anim = new Animation($anim_name, $object, $parameter); } } print "\n" . $css . "\n\n.container{\n\n\tdisplay: table;\n\twidth:100%;\n\theight:100%;\n\n}\n\n</style>\n"; }
/** * @param Parameter $param The schema of the parameter being populated * @param string $name The parameter/header name * @param mixed $value The user-defined header value */ private function stockHeader(Parameter $param, $name, $value) { if ($name == 'metadata' || $name == 'removeMetadata') { foreach ($value as $key => $keyVal) { $schema = $param->getItemSchema() ?: new Parameter(['prefix' => $param->getPrefix()]); $this->stockHeader($schema, $key, $keyVal); } } if (is_string($value) || is_numeric($value)) { if ($prefix = $param->getPrefix()) { $name = $prefix . $name; } $this->headers[$name] = $value; } }
/** * <ul> * <li>By default the option is <i>OFF</i></li> * <li>The output when option is <i>ON</i> is this parameter name</li> * <li>The output when option is <i>OFF</i> is empty string</li> * <li>The parameter is not required</li> * </ul> * @param string $name The parameter name, case insensitive * @throws \MWException When $name not set */ public function __construct($name) { parent::__construct($name); $this->default_value = false; $this->output_on = $name; $this->output_off = ''; }
private function _build() { $deploy = $this->_get_deploy(); // get domains $domains = array(); foreach ($deploy->{'domains'} as $d) { $domain = Domain::fromJson($d); $domains[$domain->getId()] = $domain; Logger::debug("load domain %s", $domain->toString()); } // get layers foreach ($deploy->{'layers'} as $l) { $domain = $domains[$l->{'domain_id'}]; $layer = new Layer($l->{'id'}, $domain); $this->_layers[$l->{'id'}] = $layer; Logger::debug("load layer %s", $layer->toString()); } // assign experiments foreach ($deploy->{'experiments'} as $e) { $exp = Experiment::fromJson($e); $this->_exps[$exp->getId()] = $exp; $layer = $this->_layers[$exp->getLayerId()]; $layer->assign($exp); Logger::debug("load exp %s", $exp->toString()); } foreach ($deploy->{'parameters'} as $p) { $param = Parameter::fromJson($p); $this->_baseParams[$param->getName()] = $param->getValue(); Logger::debug("load param %s => %s", $param->getName(), $param->getValue()); } }
public function convertSqlToJob(SQLTokenIterator $tokens) { $parameterCondition = new ParameterConditionJob(); try { $parameter = Parameter::getByValue(strtolower($tokens->getExclusiveTokenString())); if (is_null($parameter)) { throw new MalformedSqlException("Invalid parameter value given for parameter condition!"); } $parameterCondition->setParameter($parameter); $tokens->seekIndex($tokens->getExclusiveTokenIndex()); } catch (MalformedSqlException $exception) { throw new MalformedSqlException($exception->getMessage(), $tokens); } catch (\Exception $exception) { throw new ErrorException("Tried to parse parameter-condition when token-iterator does not point to valid parameter!"); } switch ($parameter) { case Parameter::SEPARATOR: if (!$this->valueParser->canParseTokens($tokens)) { throw new MalformedSqlException("Missing valid value after parameter-condition {$parameterCondition->getParameter()->getValue()}!", $tokens); } $parameterCondition->setValue($this->valueParser->convertSqlToJob($tokens)); break; } return $parameterCondition; }
/** * @see DataPermissionInterface::__construct() * @param string type * @param integer $id */ function __construct($type, $id) { if (is_numeric($id) and $type) { $this->type = $type; switch ($type) { case "file": $this->id = $id; $this->object = File::get_instance($id); break; case "value": $this->id = $id; $this->object = Value::get_instance($id); break; case "parameter": $this->id = $id; $this->object = Parameter::get_instance($id); break; case "folder": $this->id = $id; $this->object = Folder::get_instance($id); break; } $this->automatic = $this->object->get_automatic(); $this->permission = $this->object->get_permission(); $this->owner_id = $this->object->get_owner_id(); $this->owner_group_id = $this->object->get_owner_group_id(); } else { $this->id = null; $this->object = null; } }
public function encode($value) { if (!is_a($value, $this->class)) { throw new ValidationException("input value on parameter: [{$this->getName()}] is not of type: [{$this->class}]"); } return parent::encode($value); }
public function &updateMethodDetails(&$Class, $method_name, $method_details, &$SourceAnalyzer) { $Method = $this->findOrCreateBy('name AND klass_id', $method_name, $Class->getId()); $SourceAnalyzer->log(($Method->has_been_created ? 'Adding ' : 'Updating') . ' method ' . $method_name); $Method->setAttributes(array('description' => $method_details['doc'], 'is_private' => $method_details['is_private'], 'returns_reference' => $method_details['returns_reference'])); $Method->save(); $ParameterInstance = new Parameter(); foreach ($method_details['params'] as $parameter_details) { $ParameterInstance->updateParameterDetails($Method, $parameter_details); } if ($method_details['category'] != 'none') { $Category = new Category(); $Category->updateCategoryDetails($Method, $method_details, $SourceAnalyzer); } // parameters doc_metadata category_id return $Method; }
/** * Returns the value to initially display with the input. * * @since 0.4.6 * * @return string */ protected function getValueToUse() { $value = $this->currentValue === false ? $this->param->getDefault() : $this->currentValue; if ( $this->param->isList() && is_array( $value ) ) { $value = implode( $this->param->getDelimiter(), $value ); } return $value; }
/** * @covers Phossa\Config\Reference\Parameter::deReferenceArray() */ public function testDeReferenceArray1() { $data = ['new1' => '${test1}', 'new2' => '${test2}']; // get() will auto dereference pool $this->assertEquals('wow3', $this->object->get('test1')); // dereference $data $method = $this->getMethod('deReferenceArray'); $method->invokeArgs($this->object, [&$data]); $this->assertEquals(['new1' => 'wow3', 'new2' => ['test3' => 'wow3']], $data); }
public function test_RegisterWithFactoryParam_ResolveNamed() { $counter = 0; $this->registerType('Test\\ClassA')->named('test')->onActivated(function () use(&$counter) { $counter++; }); $this->registerType('ClassN22')->withParams(Parameter::named('test')); $c = $this->resolve('ClassN22'); $this->assertEquals(0, $counter); $c->a->createInstance(); $this->assertEquals(1, $counter); }
/** * @return float The time it took to execute in milliseconds */ private function measure() { $closure = $this->method->getMethod(); if ($this->parameter !== null) { // Make sure getParameter() won't be measured. $parameterValue = $this->parameter->getParameter(); $start = microtime(true); $closure($this->iterationCount, $parameterValue); return (microtime(true) - $start) * 1000.0; } // Have to omit the parameter because the closure won't accept it. $start = microtime(true); $closure($this->iterationCount); return (microtime(true) - $start) * 1000.0; }
protected function SetupParameter() { // Lookup Object PK information from Query String (if applicable) // Set mode to Edit or New depending on what's found $intId = QApplication::QueryString('intId'); if ($intId) { $this->objParameter = Parameter::Load($intId); if (!$this->objParameter) { throw new Exception('Could not find a Parameter object with PK arguments: ' . $intId); } $this->strTitleVerb = QApplication::Translate('Edit'); $this->blnEditMode = true; } else { $this->objParameter = new Parameter(); $this->strTitleVerb = QApplication::Translate('Create'); $this->blnEditMode = false; } }
/** * Gets an internationalized error message to construct a ValidationError with * when the criteria validation failed. (for list values when all values are invalid) * * @param Parameter $parameter * * @since 0.4 * * @return string */ protected function getFullListErrorMessage(Parameter $parameter) { return wfMsgExt('validator-error-problem', 'parsemag', $parameter->getOriginalName()); }