/** * Add to service xml description identifier by REST info * @param SimpleXmlElement $xmlProduct * @param array $serviceRest */ private function addXmlIdentifier($xmlProduct, $serviceRest) { if($serviceRest['1c_id'] != null ) { $xmlProduct->addChild("Ид", $serviceRest['1c_id']); } else { $xmlProduct->addChild("Ид", $serviceRest['servicename']); } }
/** * arrayToXml * * @param string $array Array to convert to xml * @param string $rootNodeName Name of the root node * @param string $xml SimpleXmlElement * @return string $asXml String of xml built from array */ public static function arrayToXml($array, $rootNodeName = 'data', $xml = null, $charset = null) { if ($xml === null) { $xml = new SimpleXmlElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><{$rootNodeName}/>"); } foreach ($array as $key => $value) { $key = preg_replace('/[^a-z]/i', '', $key); if (is_array($value) && !empty($value)) { $node = $xml->addChild($key); foreach ($value as $k => $v) { if (is_numeric($v)) { unset($value[$k]); $node->addAttribute($k, $v); } } self::arrayToXml($value, $rootNodeName, $node, $charset); } else { if (is_int($key)) { $xml->addChild($value, 'true'); } else { $charset = $charset ? $charset : 'utf-8'; if (strcasecmp($charset, 'utf-8') !== 0 && strcasecmp($charset, 'utf8') !== 0) { $value = iconv($charset, 'UTF-8', $value); } $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); $xml->addChild($key, $value); } } } return $xml->asXML(); }
/** * arrayToXml * * @param string $array Array to convert to xml * @param string $rootNodeName Name of the root node * @param string $xml SimpleXmlElement * @return string $asXml String of xml built from array */ public static function arrayToXml($array, $rootNodeName = 'data', $xml = null) { if ($xml === null) { $xml = new SimpleXmlElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><{$rootNodeName}/>"); } foreach ($array as $key => $value) { $key = preg_replace('/[^a-z]/i', '', $key); if (is_array($value) && !empty($value)) { $node = $xml->addChild($key); foreach ($value as $k => $v) { if (is_numeric($v)) { unset($value[$k]); $node->addAttribute($k, $v); } } self::arrayToXml($value, $rootNodeName, $node); } else { if (is_int($key)) { $xml->addChild($value, 'true'); } else { $value = htmlentities($value); $xml->addChild($key, $value); } } } return $xml->asXML(); }
/** * arrayToXml * * @param string $array Array to convert to xml * @param string $rootNodeName Name of the root node * @param string $xml SimpleXmlElement * @return string $asXml String of xml built from array */ public function arrayToXml($array, $rootNodeName = 'data', $xml = null) { if ($xml === null) { $xml = new SimpleXmlElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><{$rootNodeName}/>"); } foreach ($array as $key => $value) { if (is_array($value)) { $node = $xml->addChild($key); $this->arrayToXml($value, $rootNodeName, $node); } else { $value = htmlentities($value); $xml->addChild($key, $value); } } return $xml->asXML(); }
/** * Add props to order, specified for website. * @param SimpleXmlElement $document * @param array $salesOrderRest */ protected function addOrderProps($document, $salesOrderRest) { $documentProps = $document->addChild("ЗначенияРеквизитов"); $documentProp = $documentProps->addChild("ЗначениеРеквизита"); $documentProp->addChild("Наименование", "Номер по 1С"); $documentProp->addChild("Значение", $salesOrderRest['fromsite']); if ($salesOrderRest['sostatus'] == "Created") { $documentProp = $documentProps->addChild("ЗначениеРеквизита"); $documentProp->addChild("Наименование", "Проведен"); $documentProp->addChild("Значение", "false"); } if ($salesOrderRest['sostatus'] == "Approved") { $documentProp = $documentProps->addChild("ЗначениеРеквизита"); $documentProp->addChild("Наименование", "Проведен"); $documentProp->addChild("Значение", "true"); } if ($salesOrderRest['sostatus'] == "Delivered") { $documentProp = $documentProps->addChild("ЗначениеРеквизита"); $documentProp->addChild("Наименование", "Проведен"); $documentProp->addChild("Значение", "true"); $documentProp = $documentProps->addChild("ЗначениеРеквизита"); $documentProp->addChild("Наименование", "Номер оплаты по 1С"); $documentProp->addChild("Значение", $salesOrderRest['salesorder_no']); } if ($salesOrderRest['sostatus'] == "Cancelled") { $documentProp = $documentProps->addChild("ЗначениеРеквизита"); $documentProp->addChild("Наименование", "Отменен"); $documentProp->addChild("Значение", "true"); $documentProp = $documentProps->addChild("ЗначениеРеквизита"); $documentProp->addChild("Наименование", "Проведен"); $documentProp->addChild("Значение", "false"); } }
/** * Add to account xml description identifier. * @param SimpleXmlElement $account * @param array $accountRest */ private function addXmlAccountId($account, $accountRest) { $accountId = $accountRest['1c_id']; if($accountId == null) { $accountId = $accountRest['accountname']; } $account->addChild("Ид", $accountId); }
protected function _serializeRecurser($graphNodes, SimpleXmlElement $xmlNode) { // @todo find a better way to handle concurrency.. if no clone, _position in node gets messed up if ($graphNodes instanceof Zend_Tool_Project_Structure_Node) { $graphNodes = clone $graphNodes; } foreach ($graphNodes as $graphNode) { if ($graphNode->isDeleted()) { continue; } $nodeName = $graphNode->getContext()->getName(); $nodeName[0] = strtolower($nodeName[0]); $newNode = $xmlNode->addChild($nodeName); $reflectionClass = new ReflectionClass($graphNode->getContext()); if ($graphNode->isEnabled() == false) { $newNode->addAttribute('enabled', 'false'); } foreach ($graphNode->getPersistentParameters() as $paramName => $paramValue) { $newNode->addAttribute($paramName, $paramValue); } if ($graphNode->hasChildren()) { self::_serializeRecurser($graphNode, $newNode); } } }
/** * Add props to xml description, specified for product. Need to identificate * inventory as product in One Es. * @param SimpleXmlElement $xmlProduct */ private function addXmlProps($xmlProduct) { $props = $xmlProduct->addChild("ЗначенияРеквизитов"); $prop = $props->addChild("ЗначениеРеквизита"); $prop->addChild("Наименование","ВидНоменклатуры"); $prop->addChild("Значение","Товар"); $prop = $props->addChild("ЗначениеРеквизита"); $prop->addChild("Наименование","ТипНоменклатуры"); $prop->addChild("Значение","Товар"); }
/** * afterStep * * @param mixed $event */ public function afterStep($event) { $code = $event->getTestResult()->getResultCode(); if (TestResult::FAILED === $code) { if ($event->getTestResult()->hasException()) { $failureNode = $this->currentTestcase->addChild('failure', $event->getStep()->getKeyword() . " " . $event->getStep()->getText() . ":\n\n" . $event->getTestResult()->getException()->getMessage()); $failureNode->addAttribute('type', \get_class($event->getTestResult()->getException())); } } }
/** * {@inheritdoc} */ public function export(array $data) { $countriesElement = new \SimpleXmlElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><countries/>"); foreach ($data as $iso => $name) { $countryElement = $countriesElement->addChild('country'); $countryElement->addChild('iso', $iso); $countryElement->addChild('name', $countryElement->ownerDocument->createCDATASection($name)); } return $countriesElement->asXML(); }
/** * Converts method calls into InboundXML verbs. * * @return SimpleXmlElement A SimpleXmlElement */ public function __call($verb, array $args) { /** convert verbs input like-this-one to LikeThisOne **/ $verb = preg_replace("/[-_]([a-z])/e", "ucfirst('\\1')", ucwords($verb)); /** Let's first go check if the verb exists **/ $this->_validateVerb(ucfirst($verb)); /** Let's go validate nesting **/ $this->_validateNesting(ucfirst($verb)); list($noun, $attrs) = $args + array('', array()); if (is_array($noun)) { list($attrs, $noun) = array($noun, ''); } $child = empty($noun) ? $this->element->addChild(ucfirst($verb)) : $this->element->addChild(ucfirst($verb), $noun); foreach ($attrs as $name => $value) { /** Validation of verb attributes **/ $this->_validateAttribute($name, $verb); $child->addAttribute($name, $value); } return new self($child); }
/** * Populate the protected $_data SimpleXmlElement with the passed in array * Warning: no validation is done so you can end up with some crazy SimpleXmlElement objects * if you aren't careful passing in valid arrays. * * The array keys may be camelCaseWords or dash-type-words. If they are camelCaseWords, they * will be converted to dash-type-words for the SimpleXmlElement. * * @param array $data * @param string $wrapper * @return void */ public function hydrate(array $data, $wrapper) { $wrapper = SpreedlyCommon::camelToDash($wrapper); $xml = '<' . $wrapper . '/>'; $xml = new SimpleXmlElement($xml); foreach ($data as $key => $value) { $key = SpreedlyCommon::camelToDash($key); $xml->addChild($key, $value); } $this->setData($xml); }
/** * Output as XML * * @param array $shellList The shell list. * @return void */ protected function _asXml($shellList) { $shells = new SimpleXmlElement('<shells></shells>'); foreach ($shellList as $command) { $callable = $command; $shell = $shells->addChild('shell'); $shell->addAttribute('name', $command); $shell->addAttribute('call_as', $callable); $shell->addAttribute('help', $callable . ' -h'); } $this->out($shells->saveXML()); }
public static function arrayToXml(\SimpleXMLElement $object = null, $data = array()) { foreach ($data as $key => $value) { if (is_object($value)) { $value = ArrayUtilsVTT::objectToArray($value); } if ($load = simplexml_load_string($value)) { $keyXMl = null; $doc = new \DOMDocument(); $doc->loadXML($object->asXML()); $appendXml = $doc->createDocumentFragment(); $keyXMl = is_numeric($key) ? StringUtilsVTT::ToPluralString($load->children()->getName()) : $key; $stringXml = "<{$keyXMl}>"; foreach ($load as $item) { $stringXml .= $item->asXML(); } $stringXml .= "</{$keyXMl}>"; $appendXml->appendXML($stringXml); $doc->documentElement->appendChild($appendXml); $object = new \SimpleXmlElement($doc->saveXML()); continue; } if (is_array($value)) { if (!is_numeric($key)) { $new_object = $object->addChild($key); } else { $new_object = $object->addChild($object->getName()); } self::arrayToXml($new_object, $value, false); } else { if (!is_numeric($key)) { $object->addChild($key, $value); } else { $object->addChild($object->getName(), $value); } } } return $object; }
/** * afterScenario * * @param mixed $event */ public function afterScenario(AfterScenarioTested $event) { $this->testcaseTimer->stop(); $code = $event->getTestResult()->getResultCode(); $testResultString = array(TestResult::PASSED => 'passed', TestResult::SKIPPED => 'skipped', TestResult::PENDING => 'pending', TestResult::FAILED => 'failed'); $this->testsuiteStats[$code]++; $this->currentTestcase->addAttribute('time', \round($this->testcaseTimer->getTime(), 3)); $this->currentTestcase->addAttribute('status', $testResultString[$code]); if ($this->lastStepFailure) { $failureNode = $this->currentTestcase->addChild('failure', $this->lastStepFailureException->getMessage()); $failureNode->addAttribute('message', $this->lastStepFailure); } }
public function asXml() { $xml = new SimpleXmlElement("<blueprint></blueprint>"); $xml->addAttribute("key", $this->getKey()); $xml->addAttribute("type", "form"); $xml->addAttribute("name", $this->getName()); foreach ($this->fields() as $field) { $f = $xml->addChild("field"); $f->addAttribute("key", $field->getKey()); $f->addChild("displayName", $field->getDisplayName()); $f->addChild("format", $field->getFormat()); $f->addChild("href", $field->getHref()); } return $xml->asXml(); }
/** * afterStep * * @param mixed $event */ public function afterStep($event) { $code = $event->getTestResult()->getResultCode(); if (TestResult::FAILED === $code) { if ($event->getTestResult()->hasException()) { $failureNode = $this->currentTestcase->addChild('failure'); $failureText = $event->getStep()->getKeyword() . " " . $event->getStep()->getText() . ":\n\n" . $event->getTestResult()->getException()->getMessage(); // add cdata $node = dom_import_simplexml($failureNode); $no = $node->ownerDocument; $node->appendChild($no->createCDATASection($failureText)); $failureNode->addAttribute('type', \get_class($event->getTestResult()->getException())); } } }
public function asXml() { $xml = new SimpleXmlElement("<blueprint></blueprint>"); $xml->addAttribute("key", $this->getKey()); $xml->addAttribute("type", "join"); foreach ($this->fields() as $field) { $f = $xml->addChild("field"); $f->addAttribute("key", $field->getKey()); $f->addChild("displayName", $field->getDisplayName()); $f->addChild("dataType", $field->getDataType()); if ($field->isRequired()) { $f->addChild("required", "true"); } else { $f->addChild("required", "false"); } $f->addChild("minimum", $field->getMin()); $f->addChild("maximum", $field->getMax()); if ($field->isUnique()) { $f->addChild("unique", "true"); } else { $f->addChild("unique", "false"); } $f->addChild("example", $field->getExample()); $f->addChild("foreignKey", $field->getForeignKey()); $f->addChild("foreignValue", $field->getForeignValue()); switch ($field->getDataType()) { case "string": $f->addChild("encType", $field->getEncType()); $f->addChild("regexp", $field->getRegexp()); break; case "decimal": $f->addChild("precision", $field->getPrecision()); break; case "enum": $e = $f->addChild("enumOptions"); foreach ($field->getEnumOptions() as $option) { $o = $e->addChild("option", $option); } break; case "text": case "binary": $f->addChild("mimeType", $field->getMimeType()); break; } } return $xml->asXml(); }
public function serialize($fmt, $app) { if (trim($fmt) === '') { $fmt = 'application/json'; } $types = explode(',', $fmt); $count = count($types); $base = $app->request->getUrl() . $app->request->getRootUri(); for ($i = 0; $i < $count; $i++) { if (strstr($types[$i], 'application/xml') !== false) { $app->response->headers->set('Content-Type', 'application/xml;odata.metadata=minimal'); $xml = new SimpleXmlElement('<?xml version="1.0" encoding="utf-8"?><service/>'); $xml->addAttribute('xmlns', 'http://www.w3.org/2007/app'); $xml->addAttribute('xmlns:atom', 'http://www.w3.org/2005/Atom'); $xml->addAttribute('xmlns:m', 'http://docs.oasis-open.org/odata/ns/metadata'); $xml->addAttribute('xml:base', $base); $xml->addAttribute('m:context', $base . '/$metadata'); $workspace = $xml->addChild('workspace'); $title = $workspace->addChild('atom:title', 'Default'); $title->addAttribute('type', 'text'); foreach ($this->collections as $collection) { $col = $workspace->addChild('collection'); $col->addAttribute('href', $collection->getUrl()); $title = $col->addChild('atom:title', $collection->getName()); $title->addAttribute('type', 'text'); } echo $xml->asXml(); return; } else { if (strstr($types[$i], 'application/json') !== false) { $app->response->headers->set('Content-Type', 'application/json;odata.metadata=minimal'); $resp = array(); $resp['@odata.context'] = $base . '/$metadata'; $collections = array(); foreach ($this->collections as $collection) { array_push($collections, array('name' => $collection->getName(), 'kind' => 'EntitySet', 'url' => $collection->getUrl())); } $resp['value'] = $collections; echo json_encode($resp); return; } } } $app->response->setStatus(406); echo 'Unknown format for Service Doc: ' . $fmt; error_log($fmt); }
/** * Tests getting child by name * @covers \Copycat\Structure\SimpleXmlElement::getChild() */ public function testGetChild() { $element = new SimpleXmlElement('<Test></Test>'); $element->addChild('foo', 'bar'); $this->assertInstanceOf('\\Copycat\\Structure\\SimpleXmlElement', $element->getChild('foo')); $this->assertEquals('bar', $element->getChild('foo')); try { $caught = false; $element->getChild('bar'); } catch (Exception $exception) { $caught = true; $this->assertEquals('There is no bar', $exception->getMessage()); } if (!$caught) { $this->fail('Exception was not caught'); } }
/** * Save given favourite site to xml file. */ public static function saveFavouriteSites($favId, $favType, $favName, $favLink, $configFilePath) { $favourites = FavouriteSitesUtil::getFavouriteSites($configFilePath); if ($favType == "mixed") { $favType = "movie"; } $favourites[$favType] = array($favId, $favName, $favLink); //Save to xml $simpleXml = new SimpleXmlElement('<?xml version="1.0" encoding="UTF-8"?><favourite></favourite>'); foreach ($favourites as $type => $favourite) { $element = $simpleXml->addChild("website", $favourite[2]); $element->addAttribute("id", $favourite[0]); $element->addAttribute("name", $favourite[1]); $element->addAttribute("type", $type); } $fp = fopen($configFilePath, 'w'); fwrite($fp, $simpleXml->asXML()); fclose($fp); }
/** * Converts a single ClassMetadata instance to the exported format * and returns it * * @param ClassMetadataInfo $metadata * @return mixed $exported */ public function exportClassMetadata(ClassMetadataInfo $metadata) { $xml = new \SimpleXmlElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><doctrine-mapping " . "xmlns=\"http://doctrine-project.org/schemas/orm/doctrine-mapping\" " . "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " . "xsi:schemaLocation=\"http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd\" />"); /*$xml->addAttribute('xmlns', 'http://doctrine-project.org/schemas/orm/doctrine-mapping'); $xml->addAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance'); $xml->addAttribute('xsi:schemaLocation', 'http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd');*/ if ($metadata->isMappedSuperclass) { $root = $xml->addChild('mapped-superclass'); } else { $root = $xml->addChild('entity'); } if ($metadata->customRepositoryClassName) { $root->addAttribute('repository-class', $metadata->customRepositoryClassName); } $root->addAttribute('name', $metadata->name); if (isset($metadata->table['name'])) { $root->addAttribute('table', $metadata->table['name']); } if (isset($metadata->table['schema'])) { $root->addAttribute('schema', $metadata->table['schema']); } if (isset($metadata->table['inheritance-type'])) { $root->addAttribute('inheritance-type', $metadata->table['inheritance-type']); } if ($metadata->discriminatorColumn) { $discriminatorColumnXml = $root->addChild('discriminator-column'); $discriminatorColumnXml->addAttribute('name', $metadata->discriminatorColumn['name']); $discriminatorColumnXml->addAttribute('type', $metadata->discriminatorColumn['type']); if (isset($metadata->discriminatorColumn['length'])) { $discriminatorColumnXml->addAttribute('length', $metadata->discriminatorColumn['length']); } } if ($metadata->discriminatorMap) { $discriminatorMapXml = $root->addChild('discriminator-map'); foreach ($metadata->discriminatorMap as $value => $className) { $discriminatorMappingXml = $discriminatorMapXml->addChild('discriminator-mapping'); $discriminatorMappingXml->addAttribute('value', $value); $discriminatorMappingXml->addAttribute('class', $className); } } $trackingPolicy = $this->_getChangeTrackingPolicyString($metadata->changeTrackingPolicy); if ($trackingPolicy != 'DEFERRED_IMPLICIT') { $root->addChild('change-tracking-policy', $trackingPolicy); } if (isset($metadata->table['indexes'])) { $indexesXml = $root->addChild('indexes'); foreach ($metadata->table['indexes'] as $name => $index) { $indexXml = $indexesXml->addChild('index'); $indexXml->addAttribute('name', $name); $indexXml->addAttribute('columns', implode(',', $index['columns'])); } } if (isset($metadata->table['uniqueConstraints'])) { $uniqueConstraintsXml = $root->addChild('unique-constraints'); foreach ($metadata->table['uniqueConstraints'] as $name => $unique) { $uniqueConstraintXml = $uniqueConstraintsXml->addChild('unique-constraint'); $uniqueConstraintXml->addAttribute('name', $name); $uniqueConstraintXml->addAttribute('columns', implode(',', $unique['columns'])); } } $fields = $metadata->fieldMappings; $id = array(); foreach ($fields as $name => $field) { if (isset($field['id']) && $field['id']) { $id[$name] = $field; unset($fields[$name]); } } if (!$metadata->isIdentifierComposite && ($idGeneratorType = $this->_getIdGeneratorTypeString($metadata->generatorType))) { $id[$metadata->getSingleIdentifierFieldName()]['generator']['strategy'] = $idGeneratorType; } if ($id) { foreach ($id as $field) { $idXml = $root->addChild('id'); $idXml->addAttribute('name', $field['fieldName']); $idXml->addAttribute('type', $field['type']); if (isset($field['columnName'])) { $idXml->addAttribute('column', $field['columnName']); } if (isset($field['length'])) { $idXml->addAttribute('length', $field['length']); } if (isset($field['associationKey']) && $field['associationKey']) { $idXml->addAttribute('association-key', 'true'); } if ($idGeneratorType = $this->_getIdGeneratorTypeString($metadata->generatorType)) { $generatorXml = $idXml->addChild('generator'); $generatorXml->addAttribute('strategy', $idGeneratorType); } } } if ($fields) { foreach ($fields as $field) { $fieldXml = $root->addChild('field'); $fieldXml->addAttribute('name', $field['fieldName']); $fieldXml->addAttribute('type', $field['type']); if (isset($field['columnName'])) { $fieldXml->addAttribute('column', $field['columnName']); } if (isset($field['length'])) { $fieldXml->addAttribute('length', $field['length']); } if (isset($field['precision'])) { $fieldXml->addAttribute('precision', $field['precision']); } if (isset($field['scale'])) { $fieldXml->addAttribute('scale', $field['scale']); } if (isset($field['unique']) && $field['unique']) { $fieldXml->addAttribute('unique', $field['unique']); } if (isset($field['options'])) { $optionsXml = $fieldXml->addChild('options'); foreach ($field['options'] as $key => $value) { $optionsXml->addAttribute($key, $value); } } if (isset($field['version'])) { $fieldXml->addAttribute('version', $field['version']); } if (isset($field['columnDefinition'])) { $fieldXml->addAttribute('column-definition', $field['columnDefinition']); } if (isset($field['nullable'])) { $fieldXml->addAttribute('nullable', $field['nullable'] ? 'true' : 'false'); } } } $orderMap = array(ClassMetadataInfo::ONE_TO_ONE, ClassMetadataInfo::ONE_TO_MANY, ClassMetadataInfo::MANY_TO_ONE, ClassMetadataInfo::MANY_TO_MANY); uasort($metadata->associationMappings, function ($m1, $m2) use(&$orderMap) { $a1 = array_search($m1['type'], $orderMap); $a2 = array_search($m2['type'], $orderMap); return strcmp($a1, $a2); }); foreach ($metadata->associationMappings as $name => $associationMapping) { if ($associationMapping['type'] == ClassMetadataInfo::ONE_TO_ONE) { $associationMappingXml = $root->addChild('one-to-one'); } else { if ($associationMapping['type'] == ClassMetadataInfo::MANY_TO_ONE) { $associationMappingXml = $root->addChild('many-to-one'); } else { if ($associationMapping['type'] == ClassMetadataInfo::ONE_TO_MANY) { $associationMappingXml = $root->addChild('one-to-many'); } else { if ($associationMapping['type'] == ClassMetadataInfo::MANY_TO_MANY) { $associationMappingXml = $root->addChild('many-to-many'); } } } } $associationMappingXml->addAttribute('field', $associationMapping['fieldName']); $associationMappingXml->addAttribute('target-entity', $associationMapping['targetEntity']); if (isset($associationMapping['mappedBy'])) { $associationMappingXml->addAttribute('mapped-by', $associationMapping['mappedBy']); } if (isset($associationMapping['inversedBy'])) { $associationMappingXml->addAttribute('inversed-by', $associationMapping['inversedBy']); } if (isset($associationMapping['indexBy'])) { $associationMappingXml->addAttribute('index-by', $associationMapping['indexBy']); } if (isset($associationMapping['orphanRemoval']) && $associationMapping['orphanRemoval'] !== false) { $associationMappingXml->addAttribute('orphan-removal', 'true'); } if (isset($associationMapping['joinTable']) && $associationMapping['joinTable']) { $joinTableXml = $associationMappingXml->addChild('join-table'); $joinTableXml->addAttribute('name', $associationMapping['joinTable']['name']); $joinColumnsXml = $joinTableXml->addChild('join-columns'); foreach ($associationMapping['joinTable']['joinColumns'] as $joinColumn) { $joinColumnXml = $joinColumnsXml->addChild('join-column'); $joinColumnXml->addAttribute('name', $joinColumn['name']); $joinColumnXml->addAttribute('referenced-column-name', $joinColumn['referencedColumnName']); if (isset($joinColumn['onDelete'])) { $joinColumnXml->addAttribute('on-delete', $joinColumn['onDelete']); } } $inverseJoinColumnsXml = $joinTableXml->addChild('inverse-join-columns'); foreach ($associationMapping['joinTable']['inverseJoinColumns'] as $inverseJoinColumn) { $inverseJoinColumnXml = $inverseJoinColumnsXml->addChild('join-column'); $inverseJoinColumnXml->addAttribute('name', $inverseJoinColumn['name']); $inverseJoinColumnXml->addAttribute('referenced-column-name', $inverseJoinColumn['referencedColumnName']); if (isset($inverseJoinColumn['onDelete'])) { $inverseJoinColumnXml->addAttribute('on-delete', $inverseJoinColumn['onDelete']); } if (isset($inverseJoinColumn['columnDefinition'])) { $inverseJoinColumnXml->addAttribute('column-definition', $inverseJoinColumn['columnDefinition']); } if (isset($inverseJoinColumn['nullable'])) { $inverseJoinColumnXml->addAttribute('nullable', $inverseJoinColumn['nullable']); } if (isset($inverseJoinColumn['orderBy'])) { $inverseJoinColumnXml->addAttribute('order-by', $inverseJoinColumn['orderBy']); } } } if (isset($associationMapping['joinColumns'])) { $joinColumnsXml = $associationMappingXml->addChild('join-columns'); foreach ($associationMapping['joinColumns'] as $joinColumn) { $joinColumnXml = $joinColumnsXml->addChild('join-column'); $joinColumnXml->addAttribute('name', $joinColumn['name']); $joinColumnXml->addAttribute('referenced-column-name', $joinColumn['referencedColumnName']); if (isset($joinColumn['onDelete'])) { $joinColumnXml->addAttribute('on-delete', $joinColumn['onDelete']); } if (isset($joinColumn['columnDefinition'])) { $joinColumnXml->addAttribute('column-definition', $joinColumn['columnDefinition']); } if (isset($joinColumn['nullable'])) { $joinColumnXml->addAttribute('nullable', $joinColumn['nullable']); } } } if (isset($associationMapping['orderBy'])) { $orderByXml = $associationMappingXml->addChild('order-by'); foreach ($associationMapping['orderBy'] as $name => $direction) { $orderByFieldXml = $orderByXml->addChild('order-by-field'); $orderByFieldXml->addAttribute('name', $name); $orderByFieldXml->addAttribute('direction', $direction); } } $cascade = array(); if ($associationMapping['isCascadeRemove']) { $cascade[] = 'cascade-remove'; } if ($associationMapping['isCascadePersist']) { $cascade[] = 'cascade-persist'; } if ($associationMapping['isCascadeRefresh']) { $cascade[] = 'cascade-refresh'; } if ($associationMapping['isCascadeMerge']) { $cascade[] = 'cascade-merge'; } if ($associationMapping['isCascadeDetach']) { $cascade[] = 'cascade-detach'; } if (count($cascade) === 5) { $cascade = array('cascade-all'); } if ($cascade) { $cascadeXml = $associationMappingXml->addChild('cascade'); foreach ($cascade as $type) { $cascadeXml->addChild($type); } } } if (isset($metadata->lifecycleCallbacks) && count($metadata->lifecycleCallbacks) > 0) { $lifecycleCallbacksXml = $root->addChild('lifecycle-callbacks'); foreach ($metadata->lifecycleCallbacks as $name => $methods) { foreach ($methods as $method) { $lifecycleCallbackXml = $lifecycleCallbacksXml->addChild('lifecycle-callback'); $lifecycleCallbackXml->addAttribute('type', $name); $lifecycleCallbackXml->addAttribute('method', $method); } } } return $this->_asXml($xml); }
/** * Output as XML * * @param array $shellList The shell list. * @return void */ protected function _asXml($shellList) { $plugins = CakePlugin::loaded(); $shells = new SimpleXmlElement('<shells></shells>'); foreach ($shellList as $plugin => $commands) { foreach ($commands as $command) { $callable = $command; if (in_array($plugin, $plugins)) { $callable = Inflector::camelize($plugin) . '.' . $command; } $shell = $shells->addChild('shell'); $shell->addAttribute('name', $command); $shell->addAttribute('call_as', $callable); $shell->addAttribute('provider', $plugin); $shell->addAttribute('help', $callable . ' -h'); } } $this->stdout->outputAs(ConsoleOutput::RAW); $this->out($shells->saveXml()); }
/** * Append the option's xml into the parent. * * @param SimpleXmlElement $parent The parent element. * * @return SimpleXmlElement The parent with this option appended. */ public function xml(SimpleXmlElement $parent) { $option = $parent->addChild('option'); $option->addAttribute('name', '--' . $this->_name); $short = ''; if (strlen($this->_short)) { $short = $this->_short; } $option->addAttribute('short', '-' . $short); $option->addAttribute('boolean', $this->_boolean); $option->addChild('default', $this->_default); $choices = $option->addChild('choices'); foreach ($this->_choices as $valid) { $choices->addChild('choice', $valid); } return $parent; }
/** * beforeExample * * @param ScenarioTested $event * * @return void */ public function beforeExample(ScenarioTested $event) { $this->currentTestcase = $this->currentTestsuite->addChild('testcase'); $this->currentTestcase->addAttribute('name', $this->currentOutlineTitle . ' Line #' . $event->getScenario()->getLine()); $this->testcaseTimer->start(); }
/** * Append this subcommand to the Parent element * * @param SimpleXmlElement $parent The parent element. * @return SimpleXmlElement The parent with this subcommand appended. */ public function xml(SimpleXmlElement $parent) { $command = $parent->addChild('command'); $command->addAttribute('name', $this->_name); $command->addAttribute('help', $this->_help); return $parent; }
/** * Get the help as an xml string. * * @param boolean $string * Return the SimpleXml object or a string. Defaults to true. * @return mixed. See $string */ public function xml($string = true) { $parser = $this->_parser; $xml = new SimpleXmlElement('<shell></shell>'); $xml->addChild('command', $parser->command()); $xml->addChild('description', $parser->description()); $xml->addChild('epilog', $parser->epilog()); $subcommands = $xml->addChild('subcommands'); foreach ($parser->subcommands() as $command) { $command->xml($subcommands); } $options = $xml->addChild('options'); foreach ($parser->options() as $option) { $option->xml($options); } $arguments = $xml->addChild('arguments'); foreach ($parser->arguments() as $argument) { $argument->xml($arguments); } return $string ? $xml->asXml() : $xml; }
/** * Append this arguments XML representation to the passed in SimpleXml object. * * @param SimpleXmlElement $parent The parent element. * @return SimpleXmlElement The parent with this argument appended. */ public function xml(SimpleXmlElement $parent) { $option = $parent->addChild('argument'); $option->addAttribute('name', $this->_name); $option->addAttribute('help', $this->_help); $option->addAttribute('required', $this->isRequired()); $choices = $option->addChild('choices'); foreach ($this->_choices as $valid) { $choices->addChild('choice', $valid); } return $parent; }
/** * @param SimpleXmlElement $xml */ protected function addShippingContentsInfo(&$xml) { $contents = $xml->addChild('ShippingContents'); foreach ($this->getItems() as $item) { $detail = $contents->addChild('ItemDetail'); $detail->addChild('Description', $item['name'] . ' - ' . $item['description']); $detail->addChild('Quantity', $item['quantity']); $detail->addChild('Value', round(isset($item['price']) ? $item['price'] : 0, 2)); $weight = $this->parseWeight($item['weight']); $detail->addChild('NetPounds', $weight['pounds']); $detail->addChild('NetOunces', $weight['ounces']); $detail->addChild('HSTariffNumber'); $detail->addChild('CountryOfOrigin'); } }
/** * Output as XML * * @param array $shellList * @return void */ protected function _asXml($shellList) { $plugins = CakePlugin::loaded(); $shells = new SimpleXmlElement('<shells></shells>'); foreach ($shellList as $name => $location) { $source = current($location); $callable = $name; if (in_array($source, $plugins)) { $callable = Inflector::camelize($source) . '.' . $name; } $shell = $shells->addChild('shell'); $shell->addAttribute('name', $name); $shell->addAttribute('call_as', $callable); $shell->addAttribute('provider', $source); $shell->addAttribute('help', $callable . ' -h'); } $this->stdout->outputAs(ConsoleOutput::RAW); $this->out($shells->saveXml()); }