PageRenderTime 59ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/propel/generator/lib/model/VendorInfo.php

https://bitbucket.org/bayrock/gw2spidy
PHP | 186 lines | 75 code | 22 blank | 89 comment | 1 complexity | b6c50423a4755d1c0fd268c6773ec7b7 MD5 | raw file
Possible License(s): BSD-3-Clause, BSD-2-Clause
  1. <?php
  2. /**
  3. * This file is part of the Propel package.
  4. * For the full copyright and license information, please view the LICENSE
  5. * file that was distributed with this source code.
  6. *
  7. * @license MIT License
  8. */
  9. require_once dirname(__FILE__) . '/XMLElement.php';
  10. require_once dirname(__FILE__) . '/../exception/EngineException.php';
  11. /**
  12. * Object to hold vendor-specific info.
  13. *
  14. * @author Hans Lellelid <hans@xmpl.org>
  15. * @version $Revision$
  16. * @package propel.generator.model
  17. */
  18. class VendorInfo extends XMLElement
  19. {
  20. /**
  21. * The vendor RDBMS type.
  22. *
  23. * @var string
  24. */
  25. private $type;
  26. /**
  27. * Vendor parameters.
  28. *
  29. * @var array
  30. */
  31. private $parameters = array();
  32. /**
  33. * Creates a new VendorInfo instance.
  34. *
  35. * @param string $type RDBMS type (optional)
  36. */
  37. public function __construct($type = null)
  38. {
  39. $this->type = $type;
  40. }
  41. /**
  42. * Sets up this object based on the attributes that were passed to loadFromXML().
  43. * @see parent::loadFromXML()
  44. */
  45. protected function setupObject()
  46. {
  47. $this->type = $this->getAttribute("type");
  48. }
  49. /**
  50. * Set RDBMS type for this vendor-specific info.
  51. *
  52. * @param string $v
  53. */
  54. public function setType($v)
  55. {
  56. $this->type = $v;
  57. }
  58. /**
  59. * Get RDBMS type for this vendor-specific info.
  60. *
  61. * @return string
  62. */
  63. public function getType()
  64. {
  65. return $this->type;
  66. }
  67. /**
  68. * Adds a new vendor parameter to this object.
  69. * @param array $attrib Attributes from XML.
  70. */
  71. public function addParameter($attrib)
  72. {
  73. $name = $attrib["name"];
  74. $this->parameters[$name] = $attrib["value"];
  75. }
  76. /**
  77. * Sets parameter value.
  78. *
  79. * @param string $name
  80. * @param mixed $value The value for the parameter.
  81. */
  82. public function setParameter($name, $value)
  83. {
  84. $this->parameters[$name] = $value;
  85. }
  86. /**
  87. * Gets parameter value.
  88. *
  89. * @param string $name
  90. * @return mixed Paramter value.
  91. */
  92. public function getParameter($name)
  93. {
  94. if (isset($this->parameters[$name])) {
  95. return $this->parameters[$name];
  96. }
  97. return null; // just to be explicit
  98. }
  99. /**
  100. * Whether parameter exists.
  101. *
  102. * @param string $name
  103. *
  104. * @return bool
  105. */
  106. public function hasParameter($name)
  107. {
  108. return isset($this->parameters[$name]);
  109. }
  110. /**
  111. * Sets assoc array of parameters for venfor specific info.
  112. *
  113. * @param array $params Paramter data.
  114. */
  115. public function setParameters(array $params = array())
  116. {
  117. $this->parameters = $params;
  118. }
  119. /**
  120. * Gets assoc array of parameters for venfor specific info.
  121. *
  122. * @return array
  123. */
  124. public function getParameters()
  125. {
  126. return $this->parameters;
  127. }
  128. /**
  129. * Tests whether this vendor info is empty
  130. *
  131. * @return boolean
  132. */
  133. public function isEmpty()
  134. {
  135. return empty($this->parameters);
  136. }
  137. /**
  138. * Gets a new merged VendorInfo object.
  139. * @param VendorInfo $info
  140. * @return VendorInfo new object with merged parameters
  141. */
  142. public function getMergedVendorInfo(VendorInfo $merge)
  143. {
  144. $newParams = array_merge($this->getParameters(), $merge->getParameters());
  145. $newInfo = new VendorInfo($this->getType());
  146. $newInfo->setParameters($newParams);
  147. return $newInfo;
  148. }
  149. /**
  150. * @see XMLElement::appendXml(DOMNode)
  151. */
  152. public function appendXml(DOMNode $node)
  153. {
  154. $doc = ($node instanceof DOMDocument) ? $node : $node->ownerDocument;
  155. $vendorNode = $node->appendChild($doc->createElement("vendor"));
  156. $vendorNode->setAttribute("type", $this->getType());
  157. foreach ($this->parameters as $key => $value) {
  158. $parameterNode = $doc->createElement("parameter");
  159. $parameterNode->setAttribute("name", $key);
  160. $parameterNode->setAttribute("value", $value);
  161. $vendorNode->appendChild($parameterNode);
  162. }
  163. }
  164. }