Skip to content

Commit

Permalink
Merge branch '3.0' into 3.0-new-bake-templates
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Sep 13, 2014
2 parents 205f3e9 + 9ade219 commit a93a0c2
Show file tree
Hide file tree
Showing 133 changed files with 2,246 additions and 1,159 deletions.
4 changes: 0 additions & 4 deletions appveyor.yml
Expand Up @@ -13,12 +13,9 @@ environment:
db_password: 'Password12!'
PHP: "C:/PHP"
matrix:
- db: 2008
db_dsn: 'sqlsrv:Server=.\SQL2008R2SP2;Database=cakephp;MultipleActiveResultSets=false'
- db: 2012
db_dsn: 'sqlsrv:Server=.\SQL2012SP1;Database=cakephp;MultipleActiveResultSets=false'
services:
- mssql2008r2sp2
- mssql2012sp1
init:
- SET PATH=C:\php\;%PATH%
Expand All @@ -41,7 +38,6 @@ install:
- php -r "readfile('https://getcomposer.org/installer');" | php
- php composer.phar install --prefer-dist --no-interaction --dev
test_script:
- sqlcmd -S ".\SQL2008R2SP2" -U sa -P Password12! -Q "create database cakephp;"
- sqlcmd -S ".\SQL2012SP1" -U sa -P Password12! -Q "create database cakephp;"
- cd C:\projects\cakephp
- vendor\bin\phpunit.bat
7 changes: 5 additions & 2 deletions composer.json
Expand Up @@ -32,7 +32,8 @@
"autoload": {
"psr-4": {
"Cake\\": "src"
}
},
"files": ["src/Core/functions.php"]
},
"autoload-dev": {
"psr-4": {
Expand All @@ -42,6 +43,8 @@
"replace": {
"cakephp/collection": "self.version",
"cakephp/event": "self.version",
"cakephp/validation": "self.version"
"cakephp/validation": "self.version",
"cakephp/utility": "self.version",
"cakephp/core": "self.version"
}
}
2 changes: 1 addition & 1 deletion src/Auth/BaseAuthenticate.php
Expand Up @@ -81,7 +81,7 @@ abstract class BaseAuthenticate {
* @param \Cake\Controller\ComponentRegistry $registry The Component registry used on this request.
* @param array $config Array of config to use.
*/
public function __construct(ComponentRegistry $registry, $config) {
public function __construct(ComponentRegistry $registry, array $config = []) {
$this->_registry = $registry;
$this->config($config);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Auth/BasicAuthenticate.php
Expand Up @@ -82,8 +82,8 @@ public function getUser(Request $request) {
/**
* Handles an unauthenticated access attempt by sending appropriate login headers
*
* @param Request $request A request object.
* @param Response $response A response object.
* @param \Cake\Network\Request $request A request object.
* @param \Cake\Network\Response $response A response object.
* @return void
* @throws \Cake\Network\Exception\UnauthorizedException
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Auth/DigestAuthenticate.php
Expand Up @@ -77,7 +77,7 @@ class DigestAuthenticate extends BasicAuthenticate {
* used on this request.
* @param array $config Array of config to use.
*/
public function __construct(ComponentRegistry $registry, $config) {
public function __construct(ComponentRegistry $registry, array $config = []) {
$this->_registry = $registry;

$this->config([
Expand Down
5 changes: 3 additions & 2 deletions src/Cache/Engine/ApcEngine.php
Expand Up @@ -71,13 +71,14 @@ public function write($key, $value) {
* Read a key from the cache
*
* @param string $key Identifier for the data
* @return mixed The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it
* @return mixed The cached data, or false if the data doesn't exist,
* has expired, or if there was an error fetching it
*/
public function read($key) {
$key = $this->_key($key);

$time = time();
$cachetime = intval(apc_fetch($key . '_expires'));
$cachetime = (int)apc_fetch($key . '_expires');
if ($cachetime !== 0 && ($cachetime < $time || ($time + $this->_config['duration']) < $cachetime)) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Cache/Engine/FileEngine.php
Expand Up @@ -180,7 +180,7 @@ public function read($key) {

$this->_File->rewind();
$time = time();
$cachetime = intval($this->_File->current());
$cachetime = (int)$this->_File->current();

if ($cachetime !== false &&
($cachetime < $time || ($time + $this->_config['duration']) < $cachetime)
Expand Down
6 changes: 3 additions & 3 deletions src/Cache/Engine/WincacheEngine.php
Expand Up @@ -73,14 +73,14 @@ public function write($key, $value) {
* Read a key from the cache
*
* @param string $key Identifier for the data
* @return mixed The cached data, or false if the data doesn't exist, has expired, or if
* there was an error fetching it
* @return mixed The cached data, or false if the data doesn't exist,
* has expired, or if there was an error fetching it
*/
public function read($key) {
$key = $this->_key($key);

$time = time();
$cachetime = intval(wincache_ucache_get($key . '_expires'));
$cachetime = (int)wincache_ucache_get($key . '_expires');
if ($cachetime < $time || ($time + $this->_config['duration']) < $cachetime) {
return false;
}
Expand Down
5 changes: 3 additions & 2 deletions src/Cache/Engine/XcacheEngine.php
Expand Up @@ -87,14 +87,15 @@ public function write($key, $value) {
* Read a key from the cache
*
* @param string $key Identifier for the data
* @return mixed The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it
* @return mixed The cached data, or false if the data doesn't exist,
* has expired, or if there was an error fetching it
*/
public function read($key) {
$key = $this->_key($key);

if (xcache_isset($key)) {
$time = time();
$cachetime = intval(xcache_get($key . '_expires'));
$cachetime = (int)xcache_get($key . '_expires');
if ($cachetime < $time || ($time + $this->_config['duration']) < $cachetime) {
return false;
}
Expand Down
7 changes: 5 additions & 2 deletions src/Console/ConsoleOutput.php
Expand Up @@ -159,8 +159,11 @@ class ConsoleOutput {
public function __construct($stream = 'php://stdout') {
$this->_output = fopen($stream, 'w');

if (DS === '\\' && !(bool)env('ANSICON')) {
$this->_outputAs = static::PLAIN;
if (
(DS === '\\' && !(bool)env('ANSICON')) ||
(function_exists('posix_isatty') && !posix_isatty($this->_output))
) {
$this->_outputAs = self::PLAIN;
}
}

Expand Down
101 changes: 81 additions & 20 deletions src/Console/ShellDispatcher.php
Expand Up @@ -18,13 +18,13 @@
use Cake\Core\App;
use Cake\Core\Configure;
use Cake\Core\Exception\Exception;
use Cake\Core\Plugin;
use Cake\Utility\Inflector;

/**
* Shell dispatcher handles dispatching cli commands.
*
* Consult https://github.com/cakephp/app/tree/master/App/Console/cake.php
* for how this class is used in practice.
* Consult /bin/cake.php for how this class is used in practice.
*/
class ShellDispatcher {

Expand Down Expand Up @@ -55,6 +55,8 @@ public function __construct($args = [], $bootstrap = true) {
set_time_limit(0);
$this->args = (array)$args;

$this->addShortPluginAliases();

if ($bootstrap) {
$this->_initEnvironment();
}
Expand All @@ -69,12 +71,27 @@ public function __construct($args = [], $bootstrap = true) {
*
* If you re-use an alias the last alias set will be the one available.
*
* ### Usage
*
* Aliasing a shell named ClassName:
*
* `$this->alias('alias', 'ClassName');`
*
* Getting the original name for a given alias:
*
* `$this->alias('alias');`
*
* @param string $short The new short name for the shell.
* @param string $original The original full name for the shell.
* @return void
* @param string|null $original The original full name for the shell.
* @return string|false The aliased class name, or false if the alias does not exist
*/
public static function alias($short, $original) {
static::$_aliases[$short] = $original;
public static function alias($short, $original = null) {
$short = Inflector::camelize($short);
if ($original) {
static::$_aliases[$short] = $original;
}

return isset(static::$_aliases[$short]) ? static::$_aliases[$short] : false;
}

/**
Expand Down Expand Up @@ -164,30 +181,62 @@ protected function _dispatch() {
return $Shell->runCommand($this->args, true);
}

/**
* For all loaded plugins, add a short alias
*
* This permits a plugin which implements a shell of the same name to be accessed
* Using the plugin name alone
*
* @return void
*/
public function addShortPluginAliases() {
$plugins = Plugin::loaded();

foreach ($plugins as $plugin) {
self::alias($plugin, "$plugin.$plugin");
}
}

/**
* Get shell to use, either plugin shell or application shell
*
* All paths in the loaded shell paths are searched.
* All paths in the loaded shell paths are searched, handles alias
* dereferencing
*
* @param string $shell Optionally the name of a plugin
* @return \Cake\Console\Shell A shell instance.
* @throws \Cake\Console\Exception\MissingShellException when errors are encountered.
*/
public function findShell($shell) {
$className = $this->_shellExists($shell);
if (!$className && isset(static::$_aliases[$shell])) {
$shell = static::$_aliases[$shell];
if (!$className) {
$shell = $this->_handleAlias($shell);
$className = $this->_shellExists($shell);
}
if ($className) {
list($plugin) = pluginSplit($shell);
$instance = new $className();
$instance->plugin = Inflector::camelize(trim($plugin, '.'));
return $instance;

if (!$className) {
throw new MissingShellException([
'class' => $shell,
]);
}
throw new MissingShellException([
'class' => $shell,
]);

return $this->_createShell($className, $shell);
}

/**
* If the input matches an alias, return the aliased shell name
*
* @param string $shell Optionally the name of a plugin or alias
* @return string Shell name with plugin prefix
*/
protected function _handleAlias($shell) {
$aliased = static::alias($shell);
if ($aliased) {
$shell = $aliased;
}

$class = array_map('Cake\Utility\Inflector::camelize', explode('.', $shell));
return implode('.', $class);
}

/**
Expand All @@ -197,15 +246,27 @@ public function findShell($shell) {
* @return string|bool Either the classname or false.
*/
protected function _shellExists($shell) {
$class = array_map('Cake\Utility\Inflector::camelize', explode('.', $shell));
$class = implode('.', $class);
$class = App::className($class, 'Shell', 'Shell');
$class = App::className($shell, 'Shell', 'Shell');
if (class_exists($class)) {
return $class;
}
return false;
}

/**
* Create the given shell name, and set the plugin property
*
* @param string $className The class name to instanciate
* @param string $shortName The plugin-prefixed shell name
* @return \Cake\Console\Shell A shell instance.
*/
protected function _createShell($className, $shortName) {
list($plugin) = pluginSplit($shortName);
$instance = new $className();
$instance->plugin = trim($plugin, '.');
return $instance;
}

/**
* Removes first argument and shifts other arguments up
*
Expand Down
27 changes: 9 additions & 18 deletions src/Controller/Component/AuthComponent.php
Expand Up @@ -105,8 +105,10 @@ class AuthComponent extends Component {
* - `flash` - Settings to use when Auth needs to do a flash message with
* FlashComponent::set(). Available keys are:
*
* - `key` - The message domain to use for flashes generated by this component, defaults to 'auth'.
* - `params` - The array of additional params to use, defaults to []
* - `key` - The message domain to use for flashes generated by this component,
* defaults to 'auth'.
* - `element` - Flash element to use, defaults to 'default'.
* - `params` - The array of additional params to use, defaults to ['class' => 'error']
*
* - `loginAction` - A URL (defined as a string or array) to the controller action
* that handles logins. Defaults to `/users/login`.
Expand Down Expand Up @@ -422,7 +424,7 @@ protected function _setDefaults() {
'flash' => [
'element' => 'default',
'key' => 'auth',
'params' => []
'params' => ['class' => 'error']
],
'loginAction' => [
'controller' => 'Users',
Expand Down Expand Up @@ -785,26 +787,15 @@ public function getAuthenticate($alias) {
}

/**
* Set a flash message. Uses the Session component, and values from `flash` config.
* Set a flash message. Uses the Flash component with values from `flash` config.
*
* @param string $message The message to set.
* @param string $type Message type. Defaults to 'error'.
* @return void
*/
public function flash($message, $type = 'error') {
if ($message === false) {
return;
}
$flashConfig = $this->_config['flash'];
$key = $flashConfig['key'];
$params = [];
if (isset($flashConfig['params'])) {
$params = $flashConfig['params'];
}
if (empty($params['element'])) {
$params['element'] = 'error';
public function flash($message) {
if ($message !== false) {
$this->Flash->set($message, $this->_config['flash']);
}
$this->Flash->set($message, $params + compact('key'));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Component/CookieComponent.php
Expand Up @@ -130,7 +130,7 @@ public function __construct(ComponentRegistry $collection, array $config = array
parent::__construct($collection, $config);

if (!$this->_config['key']) {
$this->config('key', Configure::read('Security.salt'));
$this->config('key', Security::salt());
}

$controller = $collection->getController();
Expand Down

0 comments on commit a93a0c2

Please sign in to comment.