PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/vendor/symfony/lib/plugins/sfPropelPlugin/lib/vendor/propel-generator/classes/propel/engine/database/model/VendorInfo.php

https://bitbucket.org/ealexandru/jobeet
PHP | 182 lines | 70 code | 18 blank | 94 comment | 1 complexity | c8c7c25f3524cac87ddc34ab2efaad13 MD5 | raw file
Possible License(s): ISC, AGPL-3.0, LGPL-2.1, BSD-3-Clause, LGPL-3.0
  1. <?php
  2. /*
  3. * $Id: VendorInfo.php 1262 2009-10-26 20:54:39Z francois $
  4. *
  5. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  6. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  7. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  8. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  9. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. *
  17. * This software consists of voluntary contributions made by many individuals
  18. * and is licensed under the LGPL. For more information please see
  19. * <http://propel.phpdb.org>.
  20. */
  21. require_once 'propel/engine/database/model/XMLElement.php';
  22. include_once 'propel/engine/EngineException.php';
  23. /**
  24. * Object to hold vendor-specific info.
  25. *
  26. * @author Hans Lellelid <hans@xmpl.org>
  27. * @version $Revision: 1262 $
  28. * @package propel.engine.database.model
  29. */
  30. class VendorInfo extends XMLElement {
  31. /**
  32. * The vendor RDBMS type.
  33. *
  34. * @var string
  35. */
  36. private $type;
  37. /**
  38. * Vendor parameters.
  39. *
  40. * @var array
  41. */
  42. private $parameters = array();
  43. /**
  44. * Creates a new VendorInfo instance.
  45. *
  46. * @param string $type RDBMS type (optional)
  47. */
  48. public function __construct($type = null)
  49. {
  50. $this->type = $type;
  51. }
  52. /**
  53. * Sets up this object based on the attributes that were passed to loadFromXML().
  54. * @see parent::loadFromXML()
  55. */
  56. protected function setupObject()
  57. {
  58. $this->type = $this->getAttribute("type");
  59. }
  60. /**
  61. * Set RDBMS type for this vendor-specific info.
  62. *
  63. * @param string $v
  64. */
  65. public function setType($v)
  66. {
  67. $this->type = $v;
  68. }
  69. /**
  70. * Get RDBMS type for this vendor-specific info.
  71. *
  72. * @return string
  73. */
  74. public function getType()
  75. {
  76. return $this->type;
  77. }
  78. /**
  79. * Adds a new vendor parameter to this object.
  80. * @param array $attrib Attributes from XML.
  81. */
  82. public function addParameter($attrib)
  83. {
  84. $name = $attrib["name"];
  85. $this->parameters[$name] = $attrib["value"];
  86. }
  87. /**
  88. * Sets parameter value.
  89. *
  90. * @param string $name
  91. * @param mixed $value The value for the parameter.
  92. */
  93. public function setParameter($name, $value)
  94. {
  95. $this->parameters[$name] = $value;
  96. }
  97. /**
  98. * Gets parameter value.
  99. *
  100. * @param string $name
  101. * @return mixed Paramter value.
  102. */
  103. public function getParameter($name)
  104. {
  105. if (isset($this->parameters[$name])) {
  106. return $this->parameters[$name];
  107. }
  108. return null; // just to be explicit
  109. }
  110. /**
  111. * Whether parameter exists.
  112. *
  113. * @param string $name
  114. */
  115. public function hasParameter($name)
  116. {
  117. return isset($this->parameters[$name]);
  118. }
  119. /**
  120. * Sets assoc array of parameters for venfor specific info.
  121. *
  122. * @param array $params Paramter data.
  123. */
  124. public function setParameters(array $params = array())
  125. {
  126. $this->parameters = $params;
  127. }
  128. /**
  129. * Gets assoc array of parameters for venfor specific info.
  130. *
  131. * @return array
  132. */
  133. public function getParameters()
  134. {
  135. return $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. }