Skip to content

Commit

Permalink
Merge pull request #566 from FriendsOfCake/cake-34
Browse files Browse the repository at this point in the history
Bump up to CakePHP 3.4
  • Loading branch information
ADmad authored Jan 28, 2018
2 parents fba0c5e + 5435fec commit c0139f2
Show file tree
Hide file tree
Showing 38 changed files with 310 additions and 272 deletions.
10 changes: 4 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: php

php:
- 5.5
- 5.6
- 7.0
- 7.1
Expand Down Expand Up @@ -30,21 +29,20 @@ matrix:
before_script:
- if [[ $TRAVIS_PHP_VERSION != 7.0 && $TRAVIS_PHP_VERSION != 7.2 ]]; then phpenv config-rm xdebug.ini; fi

- if [[ $TRAVIS_PHP_VERSION = 5.5 ]]; then composer require --dev friendsofcake/search:^3.0; fi
- if [[ $TRAVIS_PHP_VERSION != 5.5 ]]; then composer install --prefer-dist --no-interaction; fi
- composer install --prefer-dist --no-interaction

- if [[ $DB = 'mysql' ]]; then mysql -e 'CREATE DATABASE cakephp_test;'; fi
- if [[ $DB = 'pgsql' ]]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi

- if [[ $PHPCS = 1 ]]; then composer require cakephp/cakephp-codesniffer:"2.*"; fi
- if [[ $PHPSTAN = 1 ]]; then composer require phpstan/phpstan:^0.8; fi
- if [[ $PHPCS = 1 ]]; then composer require cakephp/cakephp-codesniffer:^3.0; fi
- if [[ $PHPSTAN = 1 ]]; then composer require phpstan/phpstan:^0.9; fi

script:
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION != 7.0 ]]; then vendor/bin/phpunit; fi
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.0 ]]; then vendor/bin/phpunit --coverage-clover=clover.xml; fi

- if [[ $PHPCS = 1 ]]; then vendor/bin/phpcs -p --extensions=php --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi
- if [[ $PHPSTAN = 1 ]]; then vendor/bin/phpstan analyse -c phpstan.neon -l 3 src; fi
- if [[ $PHPSTAN = 1 ]]; then vendor/bin/phpstan analyse -c phpstan.neon -l 4 src; fi

after_success:
- if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.0 ]]; then bash <(curl -s https://codecov.io/bash); fi
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
}
],
"require":{
"cakephp/cakephp": "^3.2.2"
"cakephp/cakephp": "^3.4.0"
},
"require-dev": {
"phpunit/phpunit": "<6.0",
Expand Down
7 changes: 7 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ parameters:
- '#Call to an undefined method Crud\\Action\\BaseAction::view\(\)#'
- '#Call to an undefined method Crud\\Action\\BaseAction::viewVar\(\)#'
- '#Call to an undefined method Crud\\Action\\BaseAction::findMethod\(\)#'
- '#Call to an undefined method object::getLogs\(\)#'
- '#Access to an undefined property object::\$url#'
- '#Access to an undefined property object::\$success#'
- '#Access to an undefined property object::\$entity#'
- '#Access to an undefined property object::\$query#'
- '#Access to an undefined property object::\$args#'
- '#Access to an undefined property object::\$action#'
16 changes: 8 additions & 8 deletions src/Action/AddAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected function _get()
{
$subject = $this->_subject([
'success' => true,
'entity' => $this->_entity($this->_request()->query ?: null, ['validate' => false] + $this->saveOptions())
'entity' => $this->_entity($this->_request()->getQuery() ?: null, ['validate' => false] + $this->saveOptions())
]);

$this->_trigger('beforeRender', $subject);
Expand All @@ -106,12 +106,12 @@ protected function _get()
/**
* HTTP POST handler
*
* @return \Cake\Network\Response|null
* @return \Cake\Http\Response|null
*/
protected function _post()
{
$subject = $this->_subject([
'entity' => $this->_entity($this->_request()->data, $this->saveOptions()),
'entity' => $this->_entity($this->_request()->getData(), $this->saveOptions()),
'saveMethod' => $this->saveMethod(),
'saveOptions' => $this->saveOptions()
]);
Expand All @@ -126,13 +126,13 @@ protected function _post()
return $this->_success($subject);
}

return $this->_error($subject);
$this->_error($subject);
}

/**
* HTTP PUT handler
*
* @return \Cake\Network\Response|null
* @return \Cake\Http\Response|null
*/
protected function _put()
{
Expand All @@ -143,7 +143,7 @@ protected function _put()
* Post success callback
*
* @param \Crud\Event\Subject $subject Event subject
* @return \Cake\Network\Response
* @return \Cake\Http\Response
*/
protected function _success(Subject $subject)
{
Expand All @@ -159,7 +159,7 @@ protected function _success(Subject $subject)
* Post error callback
*
* @param \Crud\Event\Subject $subject Event subject
* @return \Cake\Network\Response|void
* @return void
*/
protected function _error(Subject $subject)
{
Expand All @@ -174,7 +174,7 @@ protected function _error(Subject $subject)
* Stopped callback
*
* @param \Crud\Event\Subject $subject Event subject
* @return \Cake\Network\Response
* @return \Cake\Http\Response
*/
protected function _stopped(Subject $subject)
{
Expand Down
47 changes: 24 additions & 23 deletions src/Action/BaseAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ public function handle($args = [])
$args = (array)$args;
}

$method = '_' . strtolower($this->_request()->method());
$method = '_' . strtolower($this->_request()->getMethod());

if (method_exists($this, $method)) {
$this->_responding = true;
$this->_controller()->eventManager()->on($this);
$this->_controller()->getEventManager()->on($this);

return call_user_func_array([$this, $method], $args);
}

if (method_exists($this, '_handle')) {
$this->_responding = true;
$this->_controller()->eventManager()->on($this);
$this->_controller()->getEventManager()->on($this);

return call_user_func_array([$this, '_handle'], $args);
}
Expand All @@ -85,7 +85,7 @@ public function handle($args = [])
*/
public function responding()
{
return (bool)$this->_responding;
return $this->_responding;
}

/**
Expand All @@ -95,7 +95,7 @@ public function responding()
*/
public function enable()
{
$this->config('enabled', true);
$this->setConfig('enabled', true);
}

/**
Expand All @@ -105,7 +105,7 @@ public function enable()
*/
public function enabled()
{
return $this->config('enabled');
return $this->getConfig('enabled');
}

/**
Expand All @@ -115,7 +115,7 @@ public function enabled()
*/
public function disable()
{
$this->config('enabled', false);
$this->setConfig('enabled', false);
}

/**
Expand All @@ -134,9 +134,9 @@ public function message($type, array $replacements = [])

$crud = $this->_crud();

$config = $this->config('messages.' . $type);
$config = $this->getConfig('messages.' . $type);
if (empty($config)) {
$config = $crud->config('messages.' . $type);
$config = $crud->getConfig('messages.' . $type);
if (empty($config)) {
throw new \Exception(sprintf('Invalid message type "%s"', $type));
}
Expand All @@ -150,7 +150,7 @@ public function message($type, array $replacements = [])
'element' => 'default',
'params' => ['class' => 'message'],
'key' => 'flash',
'type' => $this->config('action') . '.' . $type,
'type' => $this->getConfig('action') . '.' . $type,
'name' => $this->resourceName()
], $config);

Expand All @@ -160,9 +160,9 @@ public function message($type, array $replacements = [])

$config['params']['original'] = ucfirst(str_replace('{name}', $config['name'], $config['text']));

$domain = $this->config('messages.domain');
$domain = $this->getConfig('messages.domain');
if (!$domain) {
$domain = $crud->config('messages.domain') ?: 'crud';
$domain = $crud->getConfig('messages.domain') ?: 'crud';
}

$config['text'] = __d($domain, $config['params']['original']);
Expand All @@ -184,6 +184,7 @@ public function message($type, array $replacements = [])
* @param string $type Message type
* @param \Crud\Event\Subject $subject Event subject
* @return void
* @throws \Exception
*/
public function setFlash($type, Subject $subject)
{
Expand Down Expand Up @@ -224,15 +225,15 @@ public function setFlash($type, Subject $subject)
public function redirectConfig($name = null, $config = null)
{
if ($name === null && $config === null) {
return $this->config('redirect');
return $this->getConfig('redirect');
}

$path = sprintf('redirect.%s', $name);
if ($config === null) {
return $this->config($path);
return $this->getConfig($path);
}

return $this->config($path, $config);
return $this->setConfig($path, $config);
}

/**
Expand All @@ -244,7 +245,7 @@ public function redirectConfig($name = null, $config = null)
*/
public function scope()
{
return $this->config('scope');
return $this->getConfig('scope');
}

/**
Expand All @@ -255,11 +256,11 @@ public function scope()
*/
public function publishSuccess(Event $event)
{
if (!isset($event->subject->success)) {
if (!isset($event->subject()->success)) {
return false;
}

$this->_controller()->set('success', $event->subject->success);
$this->_controller()->set('success', $event->subject()->success);
}

/**
Expand All @@ -274,14 +275,14 @@ public function publishSuccess(Event $event)
public function resourceName($value = null)
{
if ($value !== null) {
return $this->config('name', $value);
return $this->setConfig('name', $value);
}

if (empty($this->_config['name'])) {
$this->config('name', $this->_deriveResourceName());
$this->setConfig('name', $this->_deriveResourceName());
}

return $this->config('name');
return $this->getConfig('name');
}

/**
Expand All @@ -291,7 +292,7 @@ public function resourceName($value = null)
*/
protected function _deriveResourceName()
{
$inflectionType = $this->config('inflection');
$inflectionType = $this->getConfig('inflection');

if ($inflectionType === null) {
$inflectionType = $this->scope() === 'entity' ? 'singular' : 'plural';
Expand Down Expand Up @@ -331,7 +332,7 @@ public function implementedEvents()
*/
public function subjectEntityKey()
{
$key = $this->config('entityKey');
$key = $this->getConfig('entityKey');
if ($key !== null) {
return $key;
}
Expand Down
10 changes: 5 additions & 5 deletions src/Action/Bulk/BaseAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ abstract class BaseAction extends CrudBaseAction
/**
* Handle a bulk event
*
* @return \Cake\Network\Response
* @return \Cake\Http\Response
*/
protected function _handle()
{
Expand Down Expand Up @@ -71,11 +71,11 @@ protected function _handle()
*/
protected function _processIds()
{
$ids = $this->_controller()->request->data('id');
$ids = $this->_controller()->request->getData('id');

$all = false;
if (is_array($ids)) {
$all = Hash::get((array)$ids, '_all', false);
$all = Hash::get($ids, '_all', false);
unset($ids['_all']);
}

Expand Down Expand Up @@ -127,7 +127,7 @@ protected function _constructSubject(array $ids)
*/
protected function _getFindConfig(array $ids)
{
$config = (array)$this->config('findConfig');
$config = (array)$this->getConfig('findConfig');
if (!empty($config)) {
return $config;
}
Expand Down Expand Up @@ -173,7 +173,7 @@ protected function _error(Subject $subject)
* Stopped callback
*
* @param \Crud\Event\Subject $subject Event subject
* @return \Cake\Network\Response
* @return \Cake\Http\Response
*/
protected function _stopped(Subject $subject)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Action/Bulk/SetValueAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public function __construct(Controller $Controller, $config = [])
/**
* Handle a bulk event
*
* @return \Cake\Network\Response
* @return \Cake\Http\Response
* @throws \Crud\Error\Exception\ActionNotConfiguredException
*/
protected function _handle()
{
$field = $this->config('field');
$field = $this->getConfig('field');
if (empty($field)) {
throw new ActionNotConfiguredException('No field value specified');
}
Expand All @@ -59,8 +59,8 @@ protected function _handle()
*/
protected function _bulk(Query $query = null)
{
$field = $this->config('field');
$value = $this->config('value');
$field = $this->getConfig('field');
$value = $this->getConfig('value');
$query->update()->set([$field => $value]);
$statement = $query->execute();
$statement->closeCursor();
Expand Down
6 changes: 3 additions & 3 deletions src/Action/Bulk/ToggleAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public function __construct(Controller $Controller, $config = [])
/**
* Handle a bulk event
*
* @return \Cake\Network\Response
* @return \Cake\Http\Response
* @throws \Crud\Error\Exception\ActionNotConfiguredException
*/
protected function _handle()
{
$field = $this->config('field');
$field = $this->getConfig('field');
if (empty($field)) {
throw new ActionNotConfiguredException('No field value specified');
}
Expand All @@ -59,7 +59,7 @@ protected function _handle()
*/
protected function _bulk(Query $query = null)
{
$field = $this->config('field');
$field = $this->getConfig('field');
$expression = [new QueryExpression(sprintf('%1$s= NOT %1$s', $field))];
$query->update()->set($expression);
$statement = $query->execute();
Expand Down
Loading

0 comments on commit c0139f2

Please sign in to comment.