Upgrade CakePHP from 2.2.5 to 2.9.5

This commit is contained in:
Brm Ko 2017-02-26 15:29:44 +01:00
parent 5a580df460
commit 235a541597
793 changed files with 60746 additions and 23753 deletions

View file

@ -0,0 +1,82 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since 2.8
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
abstract class BaseShellHelper {
/**
* Default config for this helper.
*
* @var array
*/
protected $_defaultConfig = array();
/**
* ConsoleOutput instance.
*
* @var ConsoleOutput
*/
protected $_consoleOutput;
/**
* Runtime config
*
* @var array
*/
protected $_config = array();
/**
* Whether the config property has already been configured with defaults
*
* @var bool
*/
protected $_configInitialized = false;
/**
* Constructor.
*
* @param ConsoleOutput $consoleOutput The ConsoleOutput instance to use.
* @param array $config The settings for this helper.
*/
public function __construct(ConsoleOutput $consoleOutput, array $config = array()) {
$this->_consoleOutput = $consoleOutput;
$this->config($config);
}
/**
* Initialize config & store config values
*
* @param null $config Config values to set
* @return array|void
*/
public function config($config = null) {
if ($config === null) {
return $this->_config;
}
if (!$this->_configInitialized) {
$this->_config = array_merge($this->_defaultConfig, $config);
$this->_configInitialized = true;
} else {
$this->_config = array_merge($this->_config, $config);
}
}
/**
* This method should output content using `$this->_consoleOutput`.
*
* @param array $args The arguments for the helper.
* @return void
*/
abstract public function output($args);
}

View file

@ -0,0 +1,122 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since 2.8
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses("BaseShellHelper", "Console/Helper");
/**
* Create a progress bar using a supplied callback.
*/
class ProgressShellHelper extends BaseShellHelper {
/**
* The current progress.
*
* @var int
*/
protected $_progress = 0;
/**
* The total number of 'items' to progress through.
*
* @var int
*/
protected $_total = 0;
/**
* The width of the bar.
*
* @var int
*/
protected $_width = 0;
/**
* Output a progress bar.
*
* Takes a number of options to customize the behavior:
*
* - `total` The total number of items in the progress bar. Defaults
* to 100.
* - `width` The width of the progress bar. Defaults to 80.
* - `callback` The callback that will be called in a loop to advance the progress bar.
*
* @param array $args The arguments/options to use when outputing the progress bar.
* @return void
* @throws RuntimeException
*/
public function output($args) {
$args += array('callback' => null);
if (isset($args[0])) {
$args['callback'] = $args[0];
}
if (!$args['callback'] || !is_callable($args['callback'])) {
throw new RuntimeException('Callback option must be a callable.');
}
$this->init($args);
$callback = $args['callback'];
while ($this->_progress < $this->_total) {
$callback($this);
$this->draw();
}
$this->_consoleOutput->write('');
}
/**
* Initialize the progress bar for use.
*
* - `total` The total number of items in the progress bar. Defaults
* to 100.
* - `width` The width of the progress bar. Defaults to 80.
*
* @param array $args The initialization data.
* @return void
*/
public function init(array $args = array()) {
$args += array('total' => 100, 'width' => 80);
$this->_progress = 0;
$this->_width = $args['width'];
$this->_total = $args['total'];
}
/**
* Increment the progress bar.
*
* @param int $num The amount of progress to advance by.
* @return void
*/
public function increment($num = 1) {
$this->_progress = min(max(0, $this->_progress + $num), $this->_total);
}
/**
* Render the progress bar based on the current state.
*
* @return void
*/
public function draw() {
$numberLen = strlen(' 100%');
$complete = round($this->_progress / $this->_total, 2);
$barLen = ($this->_width - $numberLen) * ($this->_progress / $this->_total);
$bar = '';
if ($barLen > 1) {
$bar = str_repeat('=', $barLen - 1) . '>';
}
$pad = ceil($this->_width - $numberLen - $barLen);
if ($pad > 0) {
$bar .= str_repeat(' ', $pad);
}
$percent = ($complete * 100) . '%';
$bar .= str_pad($percent, $numberLen, ' ', STR_PAD_LEFT);
$this->_consoleOutput->overwrite($bar, 0);
}
}

View file

@ -0,0 +1,124 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since 2.8
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses("BaseShellHelper", "Console/Helper");
/**
* Create a visually pleasing ASCII art table
* from 2 dimensional array data.
*/
class TableShellHelper extends BaseShellHelper {
/**
* Default config for this helper.
*
* @var array
*/
protected $_defaultConfig = array(
'headers' => true,
'rowSeparator' => false,
'headerStyle' => 'info',
);
/**
* Calculate the column widths
*
* @param array $rows The rows on which the columns width will be calculated on.
* @return array
*/
protected function _calculateWidths($rows) {
$widths = array();
foreach ($rows as $line) {
for ($i = 0, $len = count($line); $i < $len; $i++) {
$columnLength = mb_strlen($line[$i]);
if ($columnLength > (isset($widths[$i]) ? $widths[$i] : 0)) {
$widths[$i] = $columnLength;
}
}
}
return $widths;
}
/**
* Output a row separator.
*
* @param array $widths The widths of each column to output.
* @return void
*/
protected function _rowSeparator($widths) {
$out = '';
foreach ($widths as $column) {
$out .= '+' . str_repeat('-', $column + 2);
}
$out .= '+';
$this->_consoleOutput->write($out);
}
/**
* Output a row.
*
* @param array $row The row to output.
* @param array $widths The widths of each column to output.
* @param array $options Options to be passed.
* @return void
*/
protected function _render($row, $widths, $options = array()) {
$out = '';
foreach ($row as $i => $column) {
$pad = $widths[$i] - mb_strlen($column);
if (!empty($options['style'])) {
$column = $this->_addStyle($column, $options['style']);
}
$out .= '| ' . $column . str_repeat(' ', $pad) . ' ';
}
$out .= '|';
$this->_consoleOutput->write($out);
}
/**
* Output a table.
*
* @param array $rows The data to render out.
* @return void
*/
public function output($rows) {
$config = $this->config();
$widths = $this->_calculateWidths($rows);
$this->_rowSeparator($widths);
if ($config['headers'] === true) {
$this->_render(array_shift($rows), $widths, array('style' => $config['headerStyle']));
$this->_rowSeparator($widths);
}
foreach ($rows as $line) {
$this->_render($line, $widths);
if ($config['rowSeparator'] === true) {
$this->_rowSeparator($widths);
}
}
if ($config['rowSeparator'] !== true) {
$this->_rowSeparator($widths);
}
}
/**
* Add style tags
*
* @param string $text The text to be surrounded
* @param string $style The style to be applied
* @return string
*/
protected function _addStyle($text, $style) {
return '<' . $style . '>' . $text . '</' . $style . '>';
}
}