Skip to content

Commit

Permalink
Merge pull request #4 from cakephp/2.x
Browse files Browse the repository at this point in the history
2.x sync
  • Loading branch information
bancer committed Nov 21, 2017
2 parents 895f6ca + 10fcd76 commit 9a69363
Show file tree
Hide file tree
Showing 37 changed files with 475 additions and 175 deletions.
11 changes: 11 additions & 0 deletions .travis.yml
Expand Up @@ -10,6 +10,7 @@ php:
- 5.6
- 7.0
- 7.1
- 7.2

env:
matrix:
Expand Down Expand Up @@ -38,6 +39,15 @@ matrix:
- php: 7.1
env: DB=mysql PHPUNIT=5.7.19

- php: 7.2
env: DB=mysql PHPUNIT=5.7.19
allow_failures:
- php: 7.2
env: DB=mysql

- php: 7.2
env: DB=mysql PHPUNIT=5.7.19


before_script:
- composer require "phpunit/phpunit=$PHPUNIT"
Expand All @@ -52,6 +62,7 @@ before_script:
- sh -c "if [ '$DB' = 'pgsql' ]; then psql -c 'CREATE SCHEMA test3;' -U postgres -d cakephp_test; fi"
- chmod -R 777 ./app/tmp
- if [[ ${TRAVIS_PHP_VERSION:0:3} == "5.3" ]] ; then pecl install timezonedb ; fi
- if [[ ${TRAVIS_PHP_VERSION:0:3} == "7.2" ]] ; then pecl install mcrypt ; fi
- sh -c "if [ '$PHPCS' = '1' ]; then composer require 'cakephp/cakephp-codesniffer:1.*'; fi"
- sh -c "if [ '$PHPCS' = '1' ]; then vendors/bin/phpcs --config-set installed_paths vendors/cakephp/cakephp-codesniffer; fi"
- echo "extension = memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
Expand Down
8 changes: 4 additions & 4 deletions lib/Cake/Console/Shell.php
Expand Up @@ -415,7 +415,7 @@ public function dispatchShell() {
* @param string $command The command name to run on this shell. If this argument is empty,
* and the shell has a `main()` method, that will be called instead.
* @param array $argv Array of arguments to run the shell with. This array should be missing the shell name.
* @return void
* @return int|bool
* @link https://book.cakephp.org/2.0/en/console-and-shells.html#Shell::runCommand
*/
public function runCommand($command, $argv) {
Expand Down Expand Up @@ -469,7 +469,7 @@ public function runCommand($command, $argv) {
* Display the help in the correct format
*
* @param string $command The command to get help for.
* @return void
* @return int|bool
*/
protected function _displayHelp($command) {
$format = 'text';
Expand Down Expand Up @@ -571,7 +571,7 @@ public function in($prompt, $options = null, $default = null) {
* @param string $prompt Prompt text.
* @param string|array $options Array or string of options.
* @param string $default Default input value.
* @return Either the default value, or the user-provided input.
* @return string|int the default value, or the user-provided input.
*/
protected function _getInput($prompt, $options, $default) {
if (!is_array($options)) {
Expand Down Expand Up @@ -726,7 +726,7 @@ public function hr($newlines = 0, $width = 63) {
*
* @param string $title Title of the error
* @param string $message An optional error message
* @return void
* @return int
* @link https://book.cakephp.org/2.0/en/console-and-shells.html#Shell::error
*/
public function error($title, $message = null) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Controller/Component/Acl/DbAcl.php
Expand Up @@ -52,7 +52,7 @@ public function __construct() {
/**
* Initializes the containing component and sets the Aro/Aco objects to it.
*
* @param AclComponent $component The AclComponent instance.
* @param Component $component The AclComponent instance.
* @return void
*/
public function initialize(Component $component) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Controller/Component/Auth/BlowfishAuthenticate.php
Expand Up @@ -7,8 +7,8 @@
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of the files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
* @link https://cakephp.org CakePHP(tm) Project
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
* @link https://cakephp.org CakePHP(tm) Project
* @license https://opensource.org/licenses/mit-license.php MIT License
*/

Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Controller/Component/Auth/DigestAuthenticate.php
Expand Up @@ -44,7 +44,7 @@
* Due to the Digest authentication specification, digest auth requires a special password value. You
* can generate this password using `DigestAuthenticate::password()`
*
* `$digestPass = DigestAuthenticate::password($username, env('SERVER_NAME'), $password);`
* `$digestPass = DigestAuthenticate::password($username, $password, env('SERVER_NAME'));`
*
* Its recommended that you store this digest auth only password separate from password hashes used for other
* login methods. For example `User.digest_pass` could be used for a digest password, while `User.password` would
Expand Down Expand Up @@ -136,7 +136,7 @@ public function getUser(CakeRequest $request) {
/**
* Gets the digest headers from the request/environment.
*
* @return array Array of digest information.
* @return array|bool|null Array of digest information.
*/
protected function _getDigest() {
$digest = env('PHP_AUTH_DIGEST');
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Controller/Component/AuthComponent.php
Expand Up @@ -761,7 +761,7 @@ public function redirectUrl($url = null) {
*
* @param CakeRequest $request The request that contains authentication data.
* @param CakeResponse $response The response
* @return array User record data, or false, if the user could not be identified.
* @return array|bool User record data, or false, if the user could not be identified.
*/
public function identify(CakeRequest $request, CakeResponse $response) {
if (empty($this->_authenticateObjects)) {
Expand Down
75 changes: 18 additions & 57 deletions lib/Cake/Controller/Component/CookieComponent.php
Expand Up @@ -229,27 +229,14 @@ public function write($key, $value = null, $encrypt = true, $expires = null) {
}

foreach ($key as $name => $value) {
$names = array($name);
if (strpos($name, '.') !== false) {
$names = explode('.', $name, 2);
}
$firstName = $names[0];
$isMultiValue = (is_array($value) || count($names) > 1);

if (!isset($this->_values[$this->name][$firstName]) && $isMultiValue) {
$this->_values[$this->name][$firstName] = array();
}

if (count($names) > 1) {
$this->_values[$this->name][$firstName] = Hash::insert(
$this->_values[$this->name][$firstName],
$names[1],
$value
);
$this->_values[$this->name] = Hash::insert($this->_values[$this->name], $name, $value);
list($name) = explode('.', $name, 2);
$value = $this->_values[$this->name][$name];
} else {
$this->_values[$this->name][$firstName] = $value;
$this->_values[$this->name][$name] = $value;
}
$this->_write('[' . $firstName . ']', $this->_values[$this->name][$firstName]);
$this->_write('[' . $name . ']', $value);
}
$this->_encrypted = true;
}
Expand All @@ -274,22 +261,7 @@ public function read($key = null) {
if ($key === null) {
return $this->_values[$this->name];
}

if (strpos($key, '.') !== false) {
$names = explode('.', $key, 2);
$key = $names[0];
}
if (!isset($this->_values[$this->name][$key])) {
return null;
}

if (!empty($names[1])) {
if (is_array($this->_values[$this->name][$key])) {
return Hash::get($this->_values[$this->name][$key], $names[1]);
}
return null;
}
return $this->_values[$this->name][$key];
return Hash::get($this->_values[$this->name], $key);
}

/**
Expand Down Expand Up @@ -329,20 +301,16 @@ public function delete($key) {
$this->read();
}
if (strpos($key, '.') === false) {
if (isset($this->_values[$this->name][$key]) && is_array($this->_values[$this->name][$key])) {
foreach ($this->_values[$this->name][$key] as $idx => $val) {
$this->_delete("[$key][$idx]");
}
}
$this->_delete("[$key]");
unset($this->_values[$this->name][$key]);
return;
}
$names = explode('.', $key, 2);
if (isset($this->_values[$this->name][$names[0]]) && is_array($this->_values[$this->name][$names[0]])) {
$this->_values[$this->name][$names[0]] = Hash::remove($this->_values[$this->name][$names[0]], $names[1]);
$this->_delete('[' . $key . ']');
} else {
$this->_values[$this->name] = Hash::remove((array)$this->_values[$this->name], $key);
list($key) = explode('.', $key, 2);
if (isset($this->_values[$this->name][$key])) {
$value = $this->_values[$this->name][$key];
$this->_write('[' . $key . ']', $value);
}
}
$this->_delete('[' . implode('][', $names) . ']');
}

/**
Expand All @@ -360,14 +328,7 @@ public function destroy() {
}

foreach ($this->_values[$this->name] as $name => $value) {
if (is_array($value)) {
foreach ($value as $key => $val) {
unset($this->_values[$this->name][$name][$key]);
$this->_delete("[$name][$key]");
}
}
unset($this->_values[$this->name][$name]);
$this->_delete("[$name]");
$this->delete($name);
}
}

Expand Down Expand Up @@ -494,7 +455,7 @@ protected function _encrypt($value) {
* Decrypts $value using public $type method in Security class
*
* @param array $values Values to decrypt
* @return string decrypted string
* @return array decrypted string
*/
protected function _decrypt($values) {
$decrypted = array();
Expand All @@ -516,7 +477,7 @@ protected function _decrypt($values) {
* Decodes and decrypts a single value.
*
* @param string $value The value to decode & decrypt.
* @return string Decoded value.
* @return string|array Decoded value.
*/
protected function _decode($value) {
$prefix = 'Q2FrZQ==.';
Expand Down Expand Up @@ -552,7 +513,7 @@ protected function _implode(array $array) {
* Maintains reading backwards compatibility with 1.x CookieComponent::_implode().
*
* @param string $string A string containing JSON encoded data, or a bare string.
* @return array Map of key and values
* @return string|array Map of key and values
*/
protected function _explode($string) {
$first = substr($string, 0, 1);
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Controller/Component/EmailComponent.php
Expand Up @@ -282,7 +282,7 @@ public function initialize(Controller $controller) {
* If you are rendering a template this variable will be sent to the templates as `$content`
* @param string $template Template to use when sending email
* @param string $layout Layout to use to enclose email body
* @return bool Success
* @return array Success
*/
public function send($content = null, $template = null, $layout = null) {
$lib = new CakeEmail();
Expand Down
12 changes: 9 additions & 3 deletions lib/Cake/Controller/Component/SessionComponent.php
Expand Up @@ -136,7 +136,13 @@ public function error() {
* @deprecated 3.0.0 Since 2.7, use the FlashComponent instead.
*/
public function setFlash($message, $element = 'default', $params = array(), $key = 'flash') {
CakeSession::write('Message.' . $key, compact('message', 'element', 'params'));
$messages = (array)CakeSession::read('Message.' . $key);
$messages[] = array(
'message' => $message,
'element' => $element,
'params' => $params,
);
CakeSession::write('Message.' . $key, $messages);
}

/**
Expand All @@ -147,7 +153,7 @@ public function setFlash($message, $element = 'default', $params = array(), $key
* @return void
*/
public function renew() {
return CakeSession::renew();
CakeSession::renew();
}

/**
Expand All @@ -170,7 +176,7 @@ public function valid() {
* @link https://book.cakephp.org/2.0/en/core-libraries/components/sessions.html#SessionComponent::destroy
*/
public function destroy() {
return CakeSession::destroy();
CakeSession::destroy();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Event/CakeEvent.php
Expand Up @@ -111,7 +111,7 @@ public function subject() {
/**
* Stops the event from being used anymore
*
* @return void
* @return bool
*/
public function stopPropagation() {
return $this->_stopped = true;
Expand Down
6 changes: 3 additions & 3 deletions lib/Cake/Model/Behavior/TranslateBehavior.php
Expand Up @@ -432,7 +432,7 @@ public function beforeSave(Model $Model, $options = array()) {
* is disabled.
*
* @param Model $Model Model using this behavior.
* @return void
* @return bool true.
*/
protected function _setRuntimeData(Model $Model) {
$locale = $this->_getLocale($Model);
Expand Down Expand Up @@ -465,7 +465,7 @@ protected function _setRuntimeData(Model $Model) {
* This solves issues with saveAssociated and validate = first.
*
* @param Model $Model Model using this behavior.
* @return void
* @return bool true.
*/
public function afterValidate(Model $Model) {
$Model->data[$Model->alias] = array_merge(
Expand All @@ -481,7 +481,7 @@ public function afterValidate(Model $Model) {
* @param Model $Model Model the callback is called on
* @param bool $created Whether or not the save created a record.
* @param array $options Options passed from Model::save().
* @return void
* @return bool true.
*/
public function afterSave(Model $Model, $created, $options = array()) {
if (!isset($this->runtime[$Model->alias]['beforeValidate']) && !isset($this->runtime[$Model->alias]['beforeSave'])) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Model/BehaviorCollection.php
Expand Up @@ -73,7 +73,7 @@ public function init($modelName, $behaviors = array()) {
*
* @param string $behavior Behavior name.
* @param array $config Configuration options.
* @return void
* @return bool true.
* @deprecated 3.0.0 Will be removed in 3.0. Replaced with load().
*/
public function attach($behavior, $config = array()) {
Expand All @@ -97,7 +97,7 @@ public function attach($behavior, $config = array()) {
*
* @param string $behavior CamelCased name of the behavior to load
* @param array $config Behavior configuration parameters
* @return bool True on success, false on failure
* @return bool True on success.
* @throws MissingBehaviorException when a behavior could not be found.
*/
public function load($behavior, $config = array()) {
Expand Down
16 changes: 14 additions & 2 deletions lib/Cake/Model/Datasource/CakeSession.php
Expand Up @@ -134,6 +134,13 @@ class CakeSession {
*/
protected static $_cookieName = null;

/**
* Whether this session is running under a CLI environment
*
* @var bool
*/
protected static $_isCLI = false;

/**
* Pseudo constructor.
*
Expand All @@ -155,6 +162,7 @@ public static function init($base = null) {
}

static::$_initialized = true;
static::$_isCLI = (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg');
}

/**
Expand Down Expand Up @@ -596,14 +604,18 @@ protected static function _cookieName() {
* @return bool
*/
protected static function _hasSession() {
return static::started() || isset($_COOKIE[static::_cookieName()]) || (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg');
return static::started()
|| !ini_get('session.use_cookies')
|| isset($_COOKIE[static::_cookieName()])
|| static::$_isCLI
|| (ini_get('session.use_trans_sid') && isset($_GET[session_name()]));
}

/**
* Find the handler class and make sure it implements the correct interface.
*
* @param string $handler Handler name.
* @return void
* @return CakeSessionHandlerInterface
* @throws CakeSessionException
*/
protected static function _getHandler($handler) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Model/Datasource/Database/Sqlite.php
Expand Up @@ -212,7 +212,7 @@ public function describe($model) {
* @param array $fields The fields to update.
* @param array $values The values to set columns to.
* @param mixed $conditions array of conditions to use.
* @return array
* @return bool
*/
public function update(Model $model, $fields = array(), $values = null, $conditions = null) {
if (empty($values) && !empty($fields)) {
Expand Down

0 comments on commit 9a69363

Please sign in to comment.