PageRenderTime 34ms CodeModel.GetById 0ms RepoModel.GetById 1ms app.codeStats 0ms

/branches/v1.6.1/Classes/PHPExcel/Style/Border.php

#
PHP | 181 lines | 71 code | 15 blank | 95 comment | 8 complexity | 26c803e77d1442d439907c399b3f2b78 MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.0, LGPL-2.1, GPL-3.0, LGPL-3.0
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2008 PHPExcel
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * @category PHPExcel
  22. * @package PHPExcel_Style
  23. * @copyright Copyright (c) 2006 - 2008 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version ##VERSION##, ##DATE##
  26. */
  27. /** PHPExcel_Style_Color */
  28. require_once 'PHPExcel/Style/Color.php';
  29. /** PHPExcel_IComparable */
  30. require_once 'PHPExcel/IComparable.php';
  31. /**
  32. * PHPExcel_Style_Border
  33. *
  34. * @category PHPExcel
  35. * @package PHPExcel_Style
  36. * @copyright Copyright (c) 2006 - 2008 PHPExcel (http://www.codeplex.com/PHPExcel)
  37. */
  38. class PHPExcel_Style_Border implements PHPExcel_IComparable
  39. {
  40. /* Border style */
  41. const BORDER_NONE = 'none';
  42. const BORDER_DASHDOT = 'dashDot';
  43. const BORDER_DASHDOTDOT = 'dashDotDot';
  44. const BORDER_DASHED = 'dashed';
  45. const BORDER_DOTTED = 'dotted';
  46. const BORDER_DOUBLE = 'double';
  47. const BORDER_HAIR = 'hair';
  48. const BORDER_MEDIUM = 'medium';
  49. const BORDER_MEDIUMDASHDOT = 'mediumDashDot';
  50. const BORDER_MEDIUMDASHDOTDOT = 'mediumDashDotDot';
  51. const BORDER_MEDIUMDASHED = 'mediumDashed';
  52. const BORDER_SLANTDASHDOT = 'slantDashDot';
  53. const BORDER_THICK = 'thick';
  54. const BORDER_THIN = 'thin';
  55. /**
  56. * Border style
  57. *
  58. * @var string
  59. */
  60. private $_borderStyle;
  61. /**
  62. * Border color
  63. *
  64. * @var PHPExcel_Style_Color
  65. */
  66. private $_borderColor;
  67. /**
  68. * Create a new PHPExcel_Style_Border
  69. */
  70. public function __construct()
  71. {
  72. // Initialise values
  73. $this->_borderStyle = PHPExcel_Style_Border::BORDER_NONE;
  74. $this->_borderColor = new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_BLACK);
  75. }
  76. /**
  77. * Apply styles from array
  78. *
  79. * <code>
  80. * $objPHPExcel->getActiveSheet()->getStyle('B2')->getBorders()->getTop()->applyFromArray(
  81. * array(
  82. * 'style' => PHPExcel_Style_Border::BORDER_DASHDOT,
  83. * 'color' => array(
  84. * 'rgb' => '808080'
  85. * )
  86. * )
  87. * );
  88. * </code>
  89. *
  90. * @param array $pStyles Array containing style information
  91. * @throws Exception
  92. */
  93. public function applyFromArray($pStyles = null) {
  94. if (is_array($pStyles)) {
  95. if (array_key_exists('style', $pStyles)) {
  96. $this->setBorderStyle($pStyles['style']);
  97. }
  98. if (array_key_exists('color', $pStyles)) {
  99. $this->getColor()->applyFromArray($pStyles['color']);
  100. }
  101. } else {
  102. throw new Exception("Invalid style array passed.");
  103. }
  104. }
  105. /**
  106. * Get Border style
  107. *
  108. * @return string
  109. */
  110. public function getBorderStyle() {
  111. return $this->_borderStyle;
  112. }
  113. /**
  114. * Set Border style
  115. *
  116. * @param string $pValue
  117. */
  118. public function setBorderStyle($pValue = PHPExcel_Style_Border::BORDER_NONE) {
  119. if ($pValue == '') {
  120. $pValue = PHPExcel_Style_Border::BORDER_NONE;
  121. }
  122. $this->_borderStyle = $pValue;
  123. }
  124. /**
  125. * Get Border Color
  126. *
  127. * @return PHPExcel_Style_Color
  128. */
  129. public function getColor() {
  130. return $this->_borderColor;
  131. }
  132. /**
  133. * Set Border Color
  134. *
  135. * @param PHPExcel_Style_Color $pValue
  136. * @throws Exception
  137. */
  138. public function setColor(PHPExcel_Style_Color $pValue = null) {
  139. $this->_borderColor = $pValue;
  140. }
  141. /**
  142. * Get hash code
  143. *
  144. * @return string Hash code
  145. */
  146. public function getHashCode() {
  147. return md5(
  148. $this->_borderStyle
  149. . $this->_borderColor->getHashCode()
  150. . __CLASS__
  151. );
  152. }
  153. /**
  154. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  155. */
  156. public function __clone() {
  157. $vars = get_object_vars($this);
  158. foreach ($vars as $key => $value) {
  159. if (is_object($value)) {
  160. $this->$key = clone $value;
  161. } else {
  162. $this->$key = $value;
  163. }
  164. }
  165. }
  166. }