Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Attributes
Zend_Text_Table_Column Class Reference

Public Member Functions

 __construct ($content=null, $align=null, $colSpan=null, $charset=null)
 
 setContent ($content, $charset=null)
 
 setAlign ($align)
 
 setColSpan ($colSpan)
 
 getColSpan ()
 
 render ($columnWidth, $padding=0)
 

Data Fields

const ALIGN_LEFT = 'left'
 
const ALIGN_CENTER = 'center'
 
const ALIGN_RIGHT = 'right'
 

Protected Attributes

 $_content = ''
 
 $_align = self::ALIGN_LEFT
 
 $_colSpan = 1
 
 $_allowedAligns = array(self::ALIGN_LEFT, self::ALIGN_CENTER, self::ALIGN_RIGHT)
 

Detailed Description

Definition at line 40 of file Column.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $content = null,
  $align = null,
  $colSpan = null,
  $charset = null 
)

Create a column for a Zend_Text_Table_Row object.

Parameters
string$contentThe content of the column
string$alignThe align of the content
integer$colSpanThe colspan of the column
string$charsetThe encoding of the content

Definition at line 85 of file Column.php.

86  {
87  if ($content !== null) {
88  $this->setContent($content, $charset);
89  }
90 
91  if ($align !== null) {
92  $this->setAlign($align);
93  }
94 
95  if ($colSpan !== null) {
96  $this->setColSpan($colSpan);
97  }
98  }
setContent($content, $charset=null)
Definition: Column.php:112
setColSpan($colSpan)
Definition: Column.php:166

Member Function Documentation

◆ getColSpan()

getColSpan ( )

Get the colspan

Returns
integer

Definition at line 183 of file Column.php.

184  {
185  return $this->_colSpan;
186  }

◆ render()

render (   $columnWidth,
  $padding = 0 
)

Render the column width the given column width

Parameters
integer$columnWidthThe width of the column
integer$paddingThe padding for the column
Exceptions
Zend_Text_Table_ExceptionWhen $columnWidth is lower than 1
Zend_Text_Table_ExceptionWhen padding is greater than columnWidth
Returns
string

Definition at line 197 of file Column.php.

198  {
199  if (is_int($columnWidth) === false or $columnWidth < 1) {
200  #require_once 'Zend/Text/Table/Exception.php';
201  throw new Zend_Text_Table_Exception('$columnWidth must be an integer and greater than 0');
202  }
203 
204  $columnWidth -= ($padding * 2);
205 
206  if ($columnWidth < 1) {
207  #require_once 'Zend/Text/Table/Exception.php';
208  throw new Zend_Text_Table_Exception('Padding (' . $padding . ') is greater than column width');
209  }
210 
211  switch ($this->_align) {
212  case self::ALIGN_LEFT:
213  $padMode = STR_PAD_RIGHT;
214  break;
215 
216  case self::ALIGN_CENTER:
217  $padMode = STR_PAD_BOTH;
218  break;
219 
220  case self::ALIGN_RIGHT:
221  $padMode = STR_PAD_LEFT;
222  break;
223 
224  default:
225  // This can never happen, but the CS tells I have to have it ...
226  break;
227  }
228 
229  $outputCharset = Zend_Text_Table::getOutputCharset();
230  $lines = explode("\n", Zend_Text_MultiByte::wordWrap($this->_content, $columnWidth, "\n", true, $outputCharset));
231  $paddedLines = array();
232 
233  foreach ($lines AS $line) {
234  $paddedLines[] = str_repeat(' ', $padding)
235  . Zend_Text_MultiByte::strPad($line, $columnWidth, ' ', $padMode, $outputCharset)
236  . str_repeat(' ', $padding);
237  }
238 
239  $result = implode("\n", $paddedLines);
240 
241  return $result;
242  }
static wordWrap($string, $width=75, $break="\n", $cut=false, $charset='utf-8')
Definition: MultiByte.php:42
static getOutputCharset()
Definition: Table.php:317
static strPad($input, $padLength, $padString=' ', $padType=STR_PAD_RIGHT, $charset='utf-8')
Definition: MultiByte.php:104

◆ setAlign()

setAlign (   $align)

Set the align

Parameters
string$alignAlign of the column
Exceptions
Zend_Text_Table_ExceptionWhen supplied align is invalid
Returns
Zend_Text_Table_Column

Definition at line 147 of file Column.php.

148  {
149  if (in_array($align, $this->_allowedAligns) === false) {
150  #require_once 'Zend/Text/Table/Exception.php';
151  throw new Zend_Text_Table_Exception('Invalid align supplied');
152  }
153 
154  $this->_align = $align;
155 
156  return $this;
157  }

◆ setColSpan()

setColSpan (   $colSpan)

Set the colspan

Parameters
int$colSpan
Exceptions
Zend_Text_Table_ExceptionWhen $colSpan is smaller than 1
Returns
Zend_Text_Table_Column

Definition at line 166 of file Column.php.

167  {
168  if (is_int($colSpan) === false or $colSpan < 1) {
169  #require_once 'Zend/Text/Table/Exception.php';
170  throw new Zend_Text_Table_Exception('$colSpan must be an integer and greater than 0');
171  }
172 
173  $this->_colSpan = $colSpan;
174 
175  return $this;
176  }

◆ setContent()

setContent (   $content,
  $charset = null 
)

Set the content.

If $charset is not defined, it is assumed that $content is encoded in the charset defined via Zend_Text_Table::setInputCharset() (defaults to utf-8).

Parameters
string$contentContent of the column
string$charsetThe charset of the content
Exceptions
Zend_Text_Table_ExceptionWhen $content is not a string
Returns
Zend_Text_Table_Column

Definition at line 112 of file Column.php.

113  {
114  if (is_string($content) === false) {
115  #require_once 'Zend/Text/Table/Exception.php';
116  throw new Zend_Text_Table_Exception('$content must be a string');
117  }
118 
119  if ($charset === null) {
120  $inputCharset = Zend_Text_Table::getInputCharset();
121  } else {
122  $inputCharset = strtolower($charset);
123  }
124 
125  $outputCharset = Zend_Text_Table::getOutputCharset();
126 
127  if ($inputCharset !== $outputCharset) {
128  if (PHP_OS !== 'AIX') {
129  // AIX does not understand these character sets
130  $content = iconv($inputCharset, $outputCharset, $content);
131  }
132 
133  }
134 
135  $this->_content = $content;
136 
137  return $this;
138  }
static getInputCharset()
Definition: Table.php:297
static getOutputCharset()
Definition: Table.php:317

Field Documentation

◆ $_align

$_align = self::ALIGN_LEFT
protected

Definition at line 61 of file Column.php.

◆ $_allowedAligns

$_allowedAligns = array(self::ALIGN_LEFT, self::ALIGN_CENTER, self::ALIGN_RIGHT)
protected

Definition at line 75 of file Column.php.

◆ $_colSpan

$_colSpan = 1
protected

Definition at line 68 of file Column.php.

◆ $_content

$_content = ''
protected

Definition at line 54 of file Column.php.

◆ ALIGN_CENTER

const ALIGN_CENTER = 'center'

Definition at line 46 of file Column.php.

◆ ALIGN_LEFT

const ALIGN_LEFT = 'left'

Aligns for columns

Definition at line 45 of file Column.php.

◆ ALIGN_RIGHT

const ALIGN_RIGHT = 'right'

Definition at line 47 of file Column.php.


The documentation for this class was generated from the following file: