/** * @param string $key * @param ArrayOf $model * @param array $data * @throws \Exception */ public function decodeArrayOf($key, $model, $data) { if ($data == null) { $data = array(); } CodeGuard::checkTypeAndThrow($data, 'array'); $model->exchangeArray(array()); foreach ($data as $item) { if ($model->hasGenerator()) { $object = $model->generate($item); $this->_decode($object, $item, ''); $model[] = $object; } else { if (is_array($item)) { throw new \Exception("Must not decode array for value type '{$key}'"); } $model[] = $item; } } }
/** * Reads a MultiText from the XmlNode $sxeNode given by the element 'gloss' * * @param SimpleXMLElement $sxeNode * @param MultiText $multiText * @param ArrayOf $inputSystems * @return MultiText */ public function readMultiTextGloss($sxeNode, $multiText, $inputSystems = null) { CodeGuard::checkTypeAndThrow($multiText, 'Api\\Model\\Languageforge\\Lexicon\\MultiText'); if ($sxeNode->getName() != 'gloss') { throw new \Exception("'" . $sxeNode->getName() . "' is not a gloss"); } $inputSystemTag = (string) $sxeNode['lang']; $multiText->form($inputSystemTag, (string) $sxeNode->text); $this->projectModel->addInputSystem($inputSystemTag); // TODO InputSystems should extend ArrayOf (or Map) and become more useful. CP 2014-10 if (isset($inputSystems)) { // i.e. $inputSystems->ensureFieldHasInputSystem($inputSystemTag); $inputSystems->value($inputSystemTag); } }
/** * Ensures that the value $value is set * @param string $value */ public function value($value) { if ($this->values->array_search($value) === FALSE) { $this->values[] = $value; } }