Skip to content

Commit

Permalink
Merge pull request #6 from promo-sapiens/feature/upgrade-cakephp36
Browse files Browse the repository at this point in the history
upgrade for deprecated method calls in cakephp 3.6
  • Loading branch information
rochamarcelo committed Apr 24, 2018
2 parents 6b55c38 + 2edb4f4 commit e648f52
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
17 changes: 9 additions & 8 deletions src/Controller/Component/DiComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class DiComponent extends Component
public function startup(Event $event)
{
$controller = $this->_registry->getController();
$request = $controller->request;
$injections = $this->config('injections');
$action = $request->params['action'];
$request = $controller->getRequest();
$injections = $this->getConfig('injections');
$action = $request->getParam('action');

if ( !isset($injections[$action]) ) {
return;
Expand All @@ -36,8 +36,9 @@ public function startup(Event $event)
foreach ($injections[$action] as $dependency ) {
$params[] = $this->di()->get($dependency);
}
$this->originalPass = $request->params['pass'];
$request->params['pass'] = array_merge($params, $request->params['pass']);
$this->originalPass = $request->getParam('pass');
$pass = array_merge($params, $request->getParam('pass'));
$controller->setRequest($controller->getRequest()->withParam('pass', $pass));
}

/**
Expand All @@ -50,13 +51,13 @@ public function startup(Event $event)
public function beforeRender(Event $event)
{
$controller = $this->_registry->getController();
$injections = $this->config('injections');
$action = $controller->request->params['action'];
$injections = $this->getConfig('injections');
$action = $controller->getRequest()->getParam('action');

if ( !isset($injections[$action]) ) {
return;
}

$controller->request->params['pass'] = $this->originalPass;
$controller->setRequest($controller->getRequest()->withParam('pass', $this->originalPass));
}
}
2 changes: 1 addition & 1 deletion src/Di/InvokeActionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ trait InvokeActionTrait
*/
public function invokeAction()
{
$request = $this->request;
$request = $this->getRequest();
if (!isset($request)) {
throw new LogicException('No Request object configured. Cannot invoke action');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Event/ActionInjectionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function implementedEvents()
public function injectDependency(Event $event, array $actionArgs)
{
$className = '\\' . get_class($event->getSubject());
$action = $event->getSubject()->request->getParam('action');
$action = $event->getSubject()->getRequest()->getParam('action');

if (isset($this->injectionsMap[$className][$action])) {
$args = [];
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Event/ContainerDispatchListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Cake\Http\ActionDispatcher;
use Cake\Http\Response;
use Cake\Http\ServerRequest;
use Cake\Network\Session;
use Cake\Http\Session;
use Cake\TestSuite\TestCase;
use RochaMarcelo\CakePimpleDi\Di\DiTrait;
use RochaMarcelo\CakePimpleDi\Event\ContainerDispatchListener;
Expand Down
6 changes: 3 additions & 3 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
'defaults' => 'php'
]);

Cache::config([
Cache::setConfig([
'_cake_core_' => [
'engine' => 'File',
'prefix' => 'cake_core_',
Expand All @@ -77,7 +77,7 @@
putenv('db_dsn=sqlite::memory:');
}

ConnectionManager::config('test', [
ConnectionManager::setConfig('test', [
'className' => 'Cake\Database\Connection',
'driver' => getenv('db_class'),
'dsn' => getenv('db_dsn'),
Expand All @@ -87,7 +87,7 @@
'timezone' => 'UTC'
]);

Log::config([