PHPExcel_Style
[ class tree: PHPExcel_Style ] [ index: PHPExcel_Style ] [ all elements ]

Source for file Border.php

Documentation is available at Border.php

  1. <?php
  2. /**
  3.  * PHPExcel
  4.  *
  5.  * Copyright (c) 2006 - 2009 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 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    1.6.5, 2009-01-05
  26.  */
  27.  
  28.  
  29. /** PHPExcel_Style_Color */
  30. require_once 'PHPExcel/Style/Color.php';
  31.  
  32. /** PHPExcel_IComparable */
  33. require_once 'PHPExcel/IComparable.php';
  34.  
  35.  
  36. /**
  37.  * PHPExcel_Style_Border
  38.  *
  39.  * @category   PHPExcel
  40.  * @package    PHPExcel_Style
  41.  * @copyright  Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
  42.  */
  43. class PHPExcel_Style_Border implements PHPExcel_IComparable
  44. {
  45.     /* Border style */
  46.     const BORDER_NONE                'none';
  47.     const BORDER_DASHDOT            'dashDot';
  48.     const BORDER_DASHDOTDOT            'dashDotDot';
  49.     const BORDER_DASHED                'dashed';
  50.     const BORDER_DOTTED                'dotted';
  51.     const BORDER_DOUBLE                'double';
  52.     const BORDER_HAIR                'hair';
  53.     const BORDER_MEDIUM                'medium';
  54.     const BORDER_MEDIUMDASHDOT        'mediumDashDot';
  55.     const BORDER_MEDIUMDASHDOTDOT    'mediumDashDotDot';
  56.     const BORDER_MEDIUMDASHED        'mediumDashed';
  57.     const BORDER_SLANTDASHDOT        'slantDashDot';
  58.     const BORDER_THICK                'thick';
  59.     const BORDER_THIN                'thin';
  60.     
  61.     /**
  62.      * Border style
  63.      *
  64.      * @var string 
  65.      */
  66.     private $_borderStyle;
  67.     
  68.     /**
  69.      * Border color
  70.      * 
  71.      * @var PHPExcel_Style_Color 
  72.      */
  73.     private $_borderColor;
  74.     
  75.     /**
  76.      * Parent
  77.      *
  78.      * @var PHPExcel_Style_Borders 
  79.      */
  80.     private $_parent;
  81.     
  82.     /**
  83.      * Parent Property Name
  84.      *
  85.      * @var string 
  86.      */
  87.     private $_parentPropertyName;
  88.         
  89.     /**
  90.      * Create a new PHPExcel_Style_Border
  91.      */
  92.     public function __construct()
  93.     {
  94.         // Initialise values
  95.         $this->_borderStyle            = PHPExcel_Style_Border::BORDER_NONE;
  96.         $this->_borderColor            = new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_BLACK);
  97.     }
  98.  
  99.     /**
  100.      * Property Prepare bind
  101.      *
  102.      * Configures this object for late binding as a property of a parent object
  103.      *     
  104.      * @param $parent 
  105.      * @param $parentPropertyName 
  106.      */
  107.     public function propertyPrepareBind($parent$parentPropertyName)
  108.     {
  109.         // Initialize parent PHPExcel_Style for late binding. This relationship purposely ends immediately when this object
  110.         // is bound to the PHPExcel_Style object pointed to so as to prevent circular references.
  111.         $this->_parent                 = $parent;
  112.         $this->_parentPropertyName    = $parentPropertyName;
  113.     }
  114.     
  115.     /**
  116.      * Property Get Bound
  117.      *
  118.      * Returns the PHPExcel_Style_Border that is actual bound to PHPExcel_Style_Borders
  119.      *
  120.      * @return PHPExcel_Style_Border 
  121.      */
  122.     private function propertyGetBound({
  123.         if(!isset($this->_parent))
  124.             return $this;                                                                // I am bound
  125.  
  126.         if($this->_parent->propertyIsBound($this->_parentPropertyName))
  127.         {
  128.             switch($this->_parentPropertyName)                                            // Another one is bound
  129.             {
  130.                 case "_left":
  131.                     return $this->_parent->getLeft();        
  132.  
  133.                 case "_right":
  134.                     return $this->_parent->getRight();        
  135.  
  136.                 case "_top":
  137.                     return $this->_parent->getTop();    
  138.                     
  139.                 case "_bottom":
  140.                     return $this->_parent->getBottom();
  141.  
  142.                 case "_diagonal":
  143.                     return $this->_parent->getDiagonal();    
  144.  
  145.                 case "_vertical":
  146.                     return $this->_parent->getVertical();
  147.  
  148.                 case "_horizontal":
  149.                     return $this->_parent->getHorizontal();
  150.             }
  151.         }
  152.  
  153.         return $this;                                                                    // No one is bound yet
  154.     }
  155.     
  156.     /**
  157.      * Property Begin Bind
  158.      *
  159.      * If no PHPExcel_Style_Border has been bound to PHPExcel_Style_Borders then bind this one. Return the actual bound one.
  160.      *
  161.      * @return PHPExcel_Style_Border 
  162.      */
  163.     private function propertyBeginBind({
  164.     
  165.         if(!isset($this->_parent))
  166.             return $this;                                                                // I am already bound
  167.  
  168.         if($this->_parent->propertyIsBound($this->_parentPropertyName))
  169.         {
  170.             switch($this->_parentPropertyName)                                            // Another one is already bound
  171.             {
  172.                 case "_left":
  173.                     return $this->_parent->getLeft();        
  174.  
  175.                 case "_right":
  176.                     return $this->_parent->getRight();        
  177.  
  178.                 case "_top":
  179.                     return $this->_parent->getTop();    
  180.                     
  181.                 case "_bottom":
  182.                     return $this->_parent->getBottom();
  183.  
  184.                 case "_diagonal":
  185.                     return $this->_parent->getDiagonal();    
  186.  
  187.                 case "_vertical":
  188.                     return $this->_parent->getVertical();
  189.  
  190.                 case "_horizontal":
  191.                     return $this->_parent->getHorizontal();
  192.             }
  193.         }
  194.             
  195.         $this->_parent->propertyCompleteBind($this$this->_parentPropertyName);        // Bind myself
  196.         $this->_parent = null;
  197.         return $this;
  198.     }
  199.         
  200.     /**
  201.      * Apply styles from array
  202.      * 
  203.      * <code>
  204.      * $objPHPExcel->getActiveSheet()->getStyle('B2')->getBorders()->getTop()->applyFromArray(
  205.      *         array(
  206.      *             'style' => PHPExcel_Style_Border::BORDER_DASHDOT,
  207.      *             'color' => array(
  208.      *                 'rgb' => '808080'
  209.      *             )
  210.      *         )
  211.      * );
  212.      * </code>
  213.      * 
  214.      * @param    array    $pStyles    Array containing style information
  215.      * @throws    Exception
  216.      */
  217.     public function applyFromArray($pStyles null{
  218.         if (is_array($pStyles)) {
  219.             if (array_key_exists('style'$pStyles)) {
  220.                 $this->setBorderStyle($pStyles['style']);
  221.             }
  222.             if (array_key_exists('color'$pStyles)) {
  223.                 $this->getColor()->applyFromArray($pStyles['color']);
  224.             }
  225.         else {
  226.             throw new Exception("Invalid style array passed.");
  227.         }
  228.     }
  229.     
  230.     /**
  231.      * Get Border style
  232.      *
  233.      * @return string 
  234.      */
  235.     public function getBorderStyle({
  236.         return $this->propertyGetBound()->_borderStyle;
  237.     }
  238.     
  239.     /**
  240.      * Set Border style
  241.      *
  242.      * @param string $pValue 
  243.      */
  244.     public function setBorderStyle($pValue PHPExcel_Style_Border::BORDER_NONE{
  245.     
  246.         if ($pValue == ''{
  247.             $pValue PHPExcel_Style_Border::BORDER_NONE;
  248.         }
  249.         $this->propertyBeginBind()->_borderStyle $pValue;
  250.     }
  251.     
  252.     /**
  253.      * Get Border Color
  254.      *
  255.      * @return PHPExcel_Style_Color 
  256.      */
  257.     public function getColor({
  258.         // It's a get but it may lead to a modified color which we won't detect but in which case we must bind.
  259.         // So bind as an assurance.
  260.         return $this->propertyBeginBind()->_borderColor;
  261.     }
  262.     
  263.     /**
  264.      * Set Border Color
  265.      *
  266.      * @param     PHPExcel_Style_Color $pValue 
  267.      * @throws     Exception
  268.      */
  269.     public function setColor(PHPExcel_Style_Color $pValue null{
  270.            $this->propertyBeginBind()->_borderColor $pValue;
  271.     }
  272.     
  273.     /**
  274.      * Get hash code
  275.      *
  276.      * @return string    Hash code
  277.      */    
  278.     public function getHashCode({
  279.         $property $this->propertyGetBound();
  280.         return md5(
  281.               $property->_borderStyle
  282.             . $property->_borderColor->getHashCode()
  283.             . __CLASS__
  284.         );
  285.     }
  286.     
  287.     /**
  288.      * Hash index
  289.      *
  290.      * @var string 
  291.      */
  292.     private $_hashIndex;
  293.     
  294.     /**
  295.      * Get hash index
  296.      * 
  297.      * Note that this index may vary during script execution! Only reliable moment is
  298.      * while doing a write of a workbook and when changes are not allowed.
  299.      *
  300.      * @return string    Hash index
  301.      */
  302.     public function getHashIndex({
  303.         return $this->_hashIndex;
  304.     }
  305.     
  306.     /**
  307.      * Set hash index
  308.      * 
  309.      * Note that this index may vary during script execution! Only reliable moment is
  310.      * while doing a write of a workbook and when changes are not allowed.
  311.      *
  312.      * @param string    $value    Hash index
  313.      */
  314.     public function setHashIndex($value{
  315.         $this->_hashIndex = $value;
  316.     }
  317.     
  318.     /**
  319.      * Implement PHP __clone to create a deep clone, not just a shallow copy.
  320.      */
  321.     public function __clone({
  322.         $vars get_object_vars($this);
  323.         foreach ($vars as $key => $value{
  324.             if (is_object($value)) {
  325.                 $this->$key clone $value;
  326.             else {
  327.                 $this->$key $value;
  328.             }
  329.         }
  330.     }
  331. }

Documentation generated on Mon, 05 Jan 2009 20:36:28 +0100 by phpDocumentor 1.4.1