File indexing completed on 2025-01-26 05:30:06

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Wildfire
0017  * @subpackage Plugin
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  * @version    $Id$
0021  */
0022 
0023 /** Zend_Wildfire_Plugin_FirePhp */
0024 // require_once 'Zend/Wildfire/Plugin/FirePhp.php';
0025 
0026 /** Zend_Wildfire_Plugin_FirePhp_Message */
0027 // require_once 'Zend/Wildfire/Plugin/FirePhp/Message.php';
0028 
0029 /**
0030  * A message envelope that can be updated for the duration of the requet before
0031  * it gets flushed at the end of the request.
0032  *
0033  * @category   Zend
0034  * @package    Zend_Wildfire
0035  * @subpackage Plugin
0036  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0037  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0038  */
0039 class Zend_Wildfire_Plugin_FirePhp_TableMessage extends Zend_Wildfire_Plugin_FirePhp_Message
0040 {
0041     /**
0042      * The header of the table containing all columns
0043      * @var array
0044      */
0045     protected $_header = null;
0046 
0047     /**
0048      * The rows of the table
0049      * $var array
0050      */
0051     protected $_rows = array();
0052 
0053     /**
0054      * Constructor
0055      *
0056      * @param string $label The label of the table
0057      */
0058     function __construct($label)
0059     {
0060         parent::__construct(Zend_Wildfire_Plugin_FirePhp::TABLE, null);
0061         $this->setLabel($label);
0062     }
0063 
0064     /**
0065      * Set the table header
0066      *
0067      * @param array $header The header columns
0068      * @return void
0069      */
0070     public function setHeader($header)
0071     {
0072         $this->_header = $header;
0073     }
0074 
0075     /**
0076      * Append a row to the end of the table.
0077      *
0078      * @param array $row An array of column values representing a row.
0079      * @return void
0080      */
0081     public function addRow($row)
0082     {
0083         $this->_rows[] = $row;
0084     }
0085 
0086     /**
0087      * Get the actual message to be sent in its final format.
0088      *
0089      * @return mixed Returns the message to be sent.
0090      */
0091     public function getMessage()
0092     {
0093         $table = $this->_rows;
0094         if($this->_header) {
0095             array_unshift($table,$this->_header);
0096         }
0097         return $table;
0098     }
0099 
0100     /**
0101      * Returns the row at the given index
0102      *
0103      * @param integer $index The index of the row
0104      * @return array Returns the row
0105      * @throws Zend_Wildfire_Exception
0106      */
0107     public function getRowAt($index)
0108     {
0109         $count = $this->getRowCount();
0110 
0111         if($index < 0 || $index > $count-1) {
0112             // require_once 'Zend/Wildfire/Exception.php';
0113             throw new Zend_Wildfire_Exception('Row index('.$index.') out of bounds('.$count.')!');
0114         }
0115 
0116         return $this->_rows[$index];
0117     }
0118 
0119     /**
0120      * Sets the row on the given index to a new row
0121      *
0122      * @param integer $index The index of the row
0123      * @param array $row The new data for the row
0124      * @throws Zend_Wildfire_Exception
0125      */
0126     public function setRowAt($index, $row)
0127     {
0128         $count = $this->getRowCount();
0129 
0130         if($index < 0 || $index > $count-1) {
0131             // require_once 'Zend/Wildfire/Exception.php';
0132             throw new Zend_Wildfire_Exception('Row index('.$index.') out of bounds('.$count.')!');
0133         }
0134 
0135         $this->_rows[$index] = $row;
0136     }
0137 
0138     /**
0139      * Returns the number of rows
0140      *
0141      * @return integer
0142      */
0143     public function getRowCount()
0144     {
0145         return count($this->_rows);
0146     }
0147 
0148     /**
0149      * Returns the last row of the table
0150      *
0151      * @return array Returns the last row
0152      * @throws Zend_Wildfire_Exception
0153      */
0154     public function getLastRow()
0155     {
0156         $count = $this->getRowCount();
0157 
0158         if($count==0) {
0159             // require_once 'Zend/Wildfire/Exception.php';
0160             throw new Zend_Wildfire_Exception('Cannot get last row as no rows exist!');
0161         }
0162 
0163         return $this->_rows[$count-1];
0164     }
0165 }