Merge branch '2.7' into 2.8

This commit is contained in:
mark_story 2015-10-15 22:10:56 -04:00
commit 707915e693
17 changed files with 157 additions and 124 deletions

View file

@ -1,7 +1,5 @@
<?php <?php
/** /**
* Index
*
* The Front Controller for handling every request * The Front Controller for handling every request
* *
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org) * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
@ -82,7 +80,7 @@ if (!defined('WWW_ROOT')) {
define('WWW_ROOT', dirname(__FILE__) . DS); define('WWW_ROOT', dirname(__FILE__) . DS);
} }
// for built-in server // For the built-in server
if (PHP_SAPI === 'cli-server') { if (PHP_SAPI === 'cli-server') {
if ($_SERVER['REQUEST_URI'] !== '/' && file_exists(WWW_ROOT . $_SERVER['PHP_SELF'])) { if ($_SERVER['REQUEST_URI'] !== '/' && file_exists(WWW_ROOT . $_SERVER['PHP_SELF'])) {
return false; return false;
@ -97,10 +95,8 @@ if (!defined('CAKE_CORE_INCLUDE_PATH')) {
if (!include 'Cake' . DS . 'bootstrap.php') { if (!include 'Cake' . DS . 'bootstrap.php') {
$failed = true; $failed = true;
} }
} else { } elseif (!include CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'bootstrap.php') {
if (!include CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'bootstrap.php') { $failed = true;
$failed = true;
}
} }
if (!empty($failed)) { if (!empty($failed)) {
trigger_error("CakePHP core could not be found. Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php. It should point to the directory containing your " . DS . "cake core directory and your " . DS . "vendors root directory.", E_USER_ERROR); trigger_error("CakePHP core could not be found. Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php. It should point to the directory containing your " . DS . "cake core directory and your " . DS . "vendors root directory.", E_USER_ERROR);

View file

@ -1,12 +1,19 @@
<?php <?php
/** /**
* Index
*
* The Front Controller for handling every request * The Front Controller for handling every request
* *
* 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 * @link http://cakephp.org CakePHP(tm) Project
* @package app.webroot * @package app.webroot
* @since CakePHP(tm) v 0.2.9 * @since CakePHP(tm) v 0.2.9
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/ */
/** /**
@ -73,7 +80,7 @@ if (!defined('WWW_ROOT')) {
define('WWW_ROOT', dirname(__FILE__) . DS); define('WWW_ROOT', dirname(__FILE__) . DS);
} }
// for built-in server // For the built-in server
if (PHP_SAPI === 'cli-server') { if (PHP_SAPI === 'cli-server') {
if ($_SERVER['REQUEST_URI'] !== '/' && file_exists(WWW_ROOT . $_SERVER['PHP_SELF'])) { if ($_SERVER['REQUEST_URI'] !== '/' && file_exists(WWW_ROOT . $_SERVER['PHP_SELF'])) {
return false; return false;
@ -88,10 +95,8 @@ if (!defined('CAKE_CORE_INCLUDE_PATH')) {
if (!include 'Cake' . DS . 'bootstrap.php') { if (!include 'Cake' . DS . 'bootstrap.php') {
$failed = true; $failed = true;
} }
} else { } elseif (!include CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'bootstrap.php') {
if (!include CAKE_CORE_INCLUDE_PATH . DS . 'Cake' . DS . 'bootstrap.php') { $failed = true;
$failed = true;
}
} }
if (!empty($failed)) { if (!empty($failed)) {
trigger_error("CakePHP core could not be found. Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php. It should point to the directory containing your " . DS . "cake core directory and your " . DS . "vendors root directory.", E_USER_ERROR); trigger_error("CakePHP core could not be found. Check the value of CAKE_CORE_INCLUDE_PATH in APP/webroot/index.php. It should point to the directory containing your " . DS . "cake core directory and your " . DS . "vendors root directory.", E_USER_ERROR);

View file

@ -155,7 +155,7 @@ class Component extends Object {
* @param string|array $url Either the string or URL array that is being redirected to. * @param string|array $url Either the string or URL array that is being redirected to.
* @param int $status The status code of the redirect * @param int $status The status code of the redirect
* @param bool $exit Will the script exit. * @param bool $exit Will the script exit.
* @return array|void Either an array or null. * @return array|null Either an array or null.
* @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::beforeRedirect * @link http://book.cakephp.org/2.0/en/controllers/components.html#Component::beforeRedirect
*/ */
public function beforeRedirect(Controller $controller, $url, $status = null, $exit = true) { public function beforeRedirect(Controller $controller, $url, $status = null, $exit = true) {

View file

@ -739,9 +739,9 @@ class DboSource extends DataSource {
/** /**
* Returns a single field of the first of query results for a given SQL query, or false if empty. * Returns a single field of the first of query results for a given SQL query, or false if empty.
* *
* @param string $name Name of the field * @param string $name The name of the field to get.
* @param string $sql SQL query * @param string $sql The SQL query.
* @return mixed Value of field read. * @return mixed Value of field read, or false if not found.
*/ */
public function field($name, $sql) { public function field($name, $sql) {
$data = $this->fetchRow($sql); $data = $this->fetchRow($sql);
@ -3209,7 +3209,7 @@ class DboSource extends DataSource {
* *
* @param string $table The name of the table to update. * @param string $table The name of the table to update.
* @param string $column The column to use when resetting the sequence value. * @param string $column The column to use when resetting the sequence value.
* @return bool|void success. * @return bool Success.
*/ */
public function resetSequence($table, $column) { public function resetSequence($table, $column) {
} }

View file

@ -1636,13 +1636,13 @@ class Model extends Object implements CakeEventListener {
} }
/** /**
* Returns the contents of a single field given the supplied conditions, in the * Returns the content of a single field given the supplied conditions,
* supplied order. * of the first record in the supplied order.
* *
* @param string $name Name of field to get * @param string $name The name of the field to get.
* @param array $conditions SQL conditions (defaults to NULL) * @param array $conditions SQL conditions (defaults to NULL).
* @param string $order SQL ORDER BY fragment * @param string $order SQL ORDER BY fragment.
* @return string field contents, or false if not found * @return string|false Field content, or false if not found.
* @link http://book.cakephp.org/2.0/en/models/retrieving-your-data.html#model-field * @link http://book.cakephp.org/2.0/en/models/retrieving-your-data.html#model-field
*/ */
public function field($name, $conditions = null, $order = null) { public function field($name, $conditions = null, $order = null) {

View file

@ -134,6 +134,7 @@ class CakeSocket {
$scheme = $this->config['protocol'] . '://'; $scheme = $this->config['protocol'] . '://';
} }
$this->_setSslContext($this->config['host']);
if (!empty($this->config['context'])) { if (!empty($this->config['context'])) {
$context = stream_context_create($this->config['context']); $context = stream_context_create($this->config['context']);
} else { } else {
@ -195,6 +196,45 @@ class CakeSocket {
return $this->connected; return $this->connected;
} }
/**
* Configure the SSL context options.
*
* @param string $host The host name being connected to.
*/
protected function _setSslContext($host) {
foreach ($this->config as $key => $value) {
if (substr($key, 0, 4) !== 'ssl_') {
continue;
}
$contextKey = substr($key, 4);
if (empty($this->config['context']['ssl'][$contextKey])) {
$this->config['context']['ssl'][$contextKey] = $value;
}
unset($this->config[$key]);
}
if (version_compare(PHP_VERSION, '5.3.2', '>=')) {
if (!isset($this->config['context']['ssl']['SNI_enabled'])) {
$this->config['context']['ssl']['SNI_enabled'] = true;
}
if (version_compare(PHP_VERSION, '5.6.0', '>=')) {
if (empty($this->config['context']['ssl']['peer_name'])) {
$this->config['context']['ssl']['peer_name'] = $host;
}
} else {
if (empty($this->config['context']['ssl']['SNI_server_name'])) {
$this->config['context']['ssl']['SNI_server_name'] = $host;
}
}
}
if (empty($this->config['context']['ssl']['cafile'])) {
$this->config['context']['ssl']['cafile'] = CAKE . 'Config' . DS . 'cacert.pem';
}
if (!empty($this->config['context']['ssl']['verify_host'])) {
$this->config['context']['ssl']['CN_match'] = $host;
}
unset($this->config['context']['ssl']['verify_host']);
}
/** /**
* socket_stream_client() does not populate errNum, or $errStr when there are * socket_stream_client() does not populate errNum, or $errStr when there are
* connection errors, as in the case of SSL verification failure. * connection errors, as in the case of SSL verification failure.
@ -405,6 +445,4 @@ class CakeSocket {
$this->setLastError(null, $errorMessage); $this->setLastError(null, $errorMessage);
throw new SocketException($errorMessage); throw new SocketException($errorMessage);
} }
} }

View file

@ -118,7 +118,8 @@ class SmtpTransport extends AbstractTransport {
'username' => null, 'username' => null,
'password' => null, 'password' => null,
'client' => null, 'client' => null,
'tls' => false 'tls' => false,
'ssl_allow_self_signed' => false
); );
$this->_config = array_merge($default, $this->_config, $config); $this->_config = array_merge($default, $this->_config, $config);
return $this->_config; return $this->_config;

View file

@ -72,7 +72,7 @@ class HttpSocket extends CakeSocket {
* Contain information about the last response (read only) * Contain information about the last response (read only)
* *
* @var array * @var array
*/ */
public $response = null; public $response = null;
/** /**
@ -361,8 +361,6 @@ class HttpSocket extends CakeSocket {
return false; return false;
} }
$this->_configContext($this->request['uri']['host']);
$this->request['raw'] = ''; $this->request['raw'] = '';
if ($this->request['line'] !== false) { if ($this->request['line'] !== false) {
$this->request['raw'] = $this->request['line']; $this->request['raw'] = $this->request['line'];
@ -374,6 +372,8 @@ class HttpSocket extends CakeSocket {
$this->request['raw'] .= "\r\n"; $this->request['raw'] .= "\r\n";
$this->request['raw'] .= $this->request['body']; $this->request['raw'] .= $this->request['body'];
// SSL context is set during the connect() method.
$this->write($this->request['raw']); $this->write($this->request['raw']);
$response = null; $response = null;
@ -700,47 +700,6 @@ class HttpSocket extends CakeSocket {
return true; return true;
} }
/**
* Configure the socket's context. Adds in configuration
* that can not be declared in the class definition.
*
* @param string $host The host you're connecting to.
* @return void
*/
protected function _configContext($host) {
foreach ($this->config as $key => $value) {
if (substr($key, 0, 4) !== 'ssl_') {
continue;
}
$contextKey = substr($key, 4);
if (empty($this->config['context']['ssl'][$contextKey])) {
$this->config['context']['ssl'][$contextKey] = $value;
}
unset($this->config[$key]);
}
if (version_compare(PHP_VERSION, '5.3.2', '>=')) {
if (!isset($this->config['context']['ssl']['SNI_enabled'])) {
$this->config['context']['ssl']['SNI_enabled'] = true;
}
if (version_compare(PHP_VERSION, '5.6.0', '>=')) {
if (empty($this->config['context']['ssl']['peer_name'])) {
$this->config['context']['ssl']['peer_name'] = $host;
}
} else {
if (empty($this->config['context']['ssl']['SNI_server_name'])) {
$this->config['context']['ssl']['SNI_server_name'] = $host;
}
}
}
if (empty($this->config['context']['ssl']['cafile'])) {
$this->config['context']['ssl']['cafile'] = CAKE . 'Config' . DS . 'cacert.pem';
}
if (!empty($this->config['context']['ssl']['verify_host'])) {
$this->config['context']['ssl']['CN_match'] = $host;
}
unset($this->config['context']['ssl']['verify_host']);
}
/** /**
* Takes a $uri array and turns it into a fully qualified URL string * Takes a $uri array and turns it into a fully qualified URL string
* *

View file

@ -207,8 +207,8 @@ class Router {
/** /**
* Set the default route class to use or return the current one * Set the default route class to use or return the current one
* *
* @param string $routeClass to set as default * @param string $routeClass The route class to set as default.
* @return mixed void|string * @return string|null The default route class.
* @throws RouterException * @throws RouterException
*/ */
public static function defaultRouteClass($routeClass = null) { public static function defaultRouteClass($routeClass = null) {

View file

@ -367,7 +367,37 @@ class CakeSocketTest extends CakeTestCase {
$this->Socket = new CakeSocket($config); $this->Socket = new CakeSocket($config);
$this->Socket->connect(); $this->Socket->connect();
$result = $this->Socket->context(); $result = $this->Socket->context();
$this->assertEquals($config['context'], $result); $this->assertSame($config['context']['ssl']['capture_peer'], $result['ssl']['capture_peer']);
} }
/**
* test configuring the context from the flat keys.
*
* @return void
*/
public function testConfigContext() {
$this->skipIf(!extension_loaded('openssl'), 'OpenSSL is not enabled cannot test SSL.');
$config = array(
'host' => 'smtp.gmail.com',
'port' => 465,
'timeout' => 5,
'ssl_verify_peer' => true,
'ssl_allow_self_signed' => false,
'ssl_verify_depth' => 5,
'ssl_verify_host' => true,
);
$this->Socket = new CakeSocket($config);
$this->Socket->connect();
$result = $this->Socket->context();
$this->assertTrue($result['ssl']['verify_peer']);
$this->assertFalse($result['ssl']['allow_self_signed']);
$this->assertEquals(5, $result['ssl']['verify_depth']);
$this->assertEquals('smtp.gmail.com', $result['ssl']['CN_match']);
$this->assertArrayNotHasKey('ssl_verify_peer', $this->Socket->config);
$this->assertArrayNotHasKey('ssl_allow_self_signed', $this->Socket->config);
$this->assertArrayNotHasKey('ssl_verify_host', $this->Socket->config);
$this->assertArrayNotHasKey('ssl_verify_depth', $this->Socket->config);
}
} }

View file

@ -946,7 +946,8 @@ class CakeEmailTest extends CakeTestCase {
'username' => null, 'username' => null,
'password' => null, 'password' => null,
'client' => null, 'client' => null,
'tls' => false 'tls' => false,
'ssl_allow_self_signed' => false
); );
$this->assertEquals($expected, $this->CakeEmail->transportClass()->config()); $this->assertEquals($expected, $this->CakeEmail->transportClass()->config());

View file

@ -314,23 +314,6 @@ class HttpSocketTest extends CakeTestCase {
$response = $this->Socket->request(true); $response = $this->Socket->request(true);
$this->assertFalse($response); $this->assertFalse($response);
$context = array(
'ssl' => array(
'verify_peer' => true,
'allow_self_signed' => false,
'verify_depth' => 5,
'SNI_enabled' => true,
'CN_match' => 'www.cakephp.org',
'cafile' => CAKE . 'Config' . DS . 'cacert.pem'
)
);
if (version_compare(PHP_VERSION, '5.6.0', '>=')) {
$context['ssl']['peer_name'] = 'www.cakephp.org';
} else {
$context['ssl']['SNI_server_name'] = 'www.cakephp.org';
}
$tests = array( $tests = array(
array( array(
'request' => 'http://www.cakephp.org/?foo=bar', 'request' => 'http://www.cakephp.org/?foo=bar',
@ -341,7 +324,10 @@ class HttpSocketTest extends CakeTestCase {
'protocol' => 'tcp', 'protocol' => 'tcp',
'port' => 80, 'port' => 80,
'timeout' => 30, 'timeout' => 30,
'context' => $context, 'ssl_verify_peer' => true,
'ssl_allow_self_signed' => false,
'ssl_verify_depth' => 5,
'ssl_verify_host' => true,
'request' => array( 'request' => array(
'uri' => array( 'uri' => array(
'scheme' => 'http', 'scheme' => 'http',
@ -1843,27 +1829,6 @@ class HttpSocketTest extends CakeTestCase {
$this->assertEquals(true, $return); $this->assertEquals(true, $return);
} }
/**
* test configuring the context from the flat keys.
*
* @return void
*/
public function testConfigContext() {
$this->Socket->expects($this->any())
->method('read')->will($this->returnValue(false));
$this->Socket->reset();
$this->Socket->request('http://example.com');
$this->assertTrue($this->Socket->config['context']['ssl']['verify_peer']);
$this->assertFalse($this->Socket->config['context']['ssl']['allow_self_signed']);
$this->assertEquals(5, $this->Socket->config['context']['ssl']['verify_depth']);
$this->assertEquals('example.com', $this->Socket->config['context']['ssl']['CN_match']);
$this->assertArrayNotHasKey('ssl_verify_peer', $this->Socket->config);
$this->assertArrayNotHasKey('ssl_allow_self_signed', $this->Socket->config);
$this->assertArrayNotHasKey('ssl_verify_host', $this->Socket->config);
$this->assertArrayNotHasKey('ssl_verify_depth', $this->Socket->config);
}
/** /**
* Test that requests fail when peer verification fails. * Test that requests fail when peer verification fails.
* *

View file

@ -353,6 +353,7 @@ class ValidateUser extends CakeTestModel {
'email' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'), 'email' => array('type' => 'string', 'null' => '', 'default' => '', 'length' => '255'),
'balance' => array('type' => 'float', 'null' => false, 'length' => '5,2'), 'balance' => array('type' => 'float', 'null' => false, 'length' => '5,2'),
'cost_decimal' => array('type' => 'decimal', 'null' => false, 'length' => '6,3'), 'cost_decimal' => array('type' => 'decimal', 'null' => false, 'length' => '6,3'),
'null_decimal' => array('type' => 'decimal', 'null' => false, 'length' => null),
'ratio' => array('type' => 'decimal', 'null' => false, 'length' => '10,6'), 'ratio' => array('type' => 'decimal', 'null' => false, 'length' => '10,6'),
'population' => array('type' => 'decimal', 'null' => false, 'length' => '15,0'), 'population' => array('type' => 'decimal', 'null' => false, 'length' => '15,0'),
'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''), 'created' => array('type' => 'date', 'null' => '1', 'default' => '', 'length' => ''),
@ -2045,6 +2046,17 @@ class FormHelperTest extends CakeTestCase {
); );
$this->assertTags($result, $expected); $this->assertTags($result, $expected);
$result = $this->Form->input('ValidateUser.null_decimal');
$expected = array(
'div' => array('class'),
'label' => array('for'),
'Null Decimal',
'/label',
'input' => array('name', 'type' => 'number', 'step' => 'any', 'id'),
'/div',
);
$this->assertTags($result, $expected);
$result = $this->Form->input('ValidateUser.ratio'); $result = $this->Form->input('ValidateUser.ratio');
$expected = array( $expected = array(
'div' => array('class'), 'div' => array('class'),

View file

@ -2927,4 +2927,29 @@ class PaginatorHelperTest extends CakeTestCase {
$this->assertSame($expected, $result); $this->assertSame($expected, $result);
} }
/**
* Verify that meta() uses URL options
*
* @return void
*/
public function testMetaPageUrlOptions() {
$this->Paginator->options(array(
'url' => array('?' => array('a' => 'b'))
));
$this->Paginator->request['paging'] = array(
'Article' => array(
'page' => 5,
'prevPage' => true,
'nextPage' => true,
'pageCount' => 10,
'options' => array(),
'paramType' => 'querystring'
)
);
$expected = '<link href="/?a=b&amp;page=4" rel="prev"/>';
$expected .= '<link href="/?a=b&amp;page=6" rel="next"/>';
$result = $this->Paginator->meta();
$this->assertSame($expected, $result);
}
} }

View file

@ -58,7 +58,7 @@ class CakeHtmlReporter extends CakeBaseReporter {
*/ */
public function paintDocumentStart() { public function paintDocumentStart() {
ob_start(); ob_start();
$this->params['baseDir']; $baseDir = $this->params['baseDir'];
include CAKE . 'TestSuite' . DS . 'templates' . DS . 'header.php'; include CAKE . 'TestSuite' . DS . 'templates' . DS . 'header.php';
} }
@ -69,7 +69,7 @@ class CakeHtmlReporter extends CakeBaseReporter {
* @return void * @return void
*/ */
public function paintTestMenu() { public function paintTestMenu() {
$this->baseUrl() . '?show=cases'; $cases = $this->baseUrl() . '?show=cases';
$plugins = App::objects('plugin', null, false); $plugins = App::objects('plugin', null, false);
sort($plugins); sort($plugins);
include CAKE . 'TestSuite' . DS . 'templates' . DS . 'menu.php'; include CAKE . 'TestSuite' . DS . 'templates' . DS . 'menu.php';

View file

@ -1209,10 +1209,10 @@ class FormHelper extends AppHelper {
if ($options['type'] === 'number' && if ($options['type'] === 'number' &&
!isset($options['step']) !isset($options['step'])
) { ) {
if ($type === 'decimal') { if ($type === 'decimal' && isset($fieldDef['length'])) {
$decimalPlaces = substr($fieldDef['length'], strpos($fieldDef['length'], ',') + 1); $decimalPlaces = substr($fieldDef['length'], strpos($fieldDef['length'], ',') + 1);
$options['step'] = sprintf('%.' . $decimalPlaces . 'F', pow(10, -1 * $decimalPlaces)); $options['step'] = sprintf('%.' . $decimalPlaces . 'F', pow(10, -1 * $decimalPlaces));
} elseif ($type === 'float') { } elseif ($type === 'float' || $type === 'decimal') {
$options['step'] = 'any'; $options['step'] = 'any';
} }
} }

View file

@ -980,25 +980,26 @@ class PaginatorHelper extends AppHelper {
* ### Options: * ### Options:
* *
* - `model` The model to use defaults to PaginatorHelper::defaultModel() * - `model` The model to use defaults to PaginatorHelper::defaultModel()
* - `block` The block name to append the output to, or false/absenst to return as a string * - `block` The block name to append the output to, or false/absent to return as a string
* *
* @param array $options Array of options * @param array $options Array of options.
* @return string|void Meta links * @return string|null Meta links.
*/ */
public function meta($options = array()) { public function meta($options = array()) {
$model = isset($options['model']) ? $options['model'] : null; $model = isset($options['model']) ? $options['model'] : null;
$params = $this->params($model); $params = $this->params($model);
$urlOptions = isset($this->options['url']) ? $this->options['url'] : array();
$links = array(); $links = array();
if ($this->hasPrev()) { if ($this->hasPrev()) {
$links[] = $this->Html->meta(array( $links[] = $this->Html->meta(array(
'rel' => 'prev', 'rel' => 'prev',
'link' => $this->url(array('page' => $params['page'] - 1), true) 'link' => $this->url(array_merge($urlOptions, array('page' => $params['page'] - 1)), true)
)); ));
} }
if ($this->hasNext()) { if ($this->hasNext()) {
$links[] = $this->Html->meta(array( $links[] = $this->Html->meta(array(
'rel' => 'next', 'rel' => 'next',
'link' => $this->url(array('page' => $params['page'] + 1), true) 'link' => $this->url(array_merge($urlOptions, array('page' => $params['page'] + 1)), true)
)); ));
} }
$out = implode($links); $out = implode($links);