Skip to content

Commit e1d0258

Browse files
authored
Fixing deprecations from CakePHP 3.6
1 parent e4642b9 commit e1d0258

File tree

1 file changed

+39
-51
lines changed

1 file changed

+39
-51
lines changed
Lines changed: 39 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
<?php
22
/**
33
* Impersonate component for Cakephp3
4-
*
4+
*
55
* Component to use impersonate to easily access as others user account
6-
*
7-
*
6+
*
7+
*
88
*/
9+
910
namespace CakeImpersonate\Controller\Component;
1011

11-
use Cake\Controller\Component\AuthComponent;
1212
use Cake\Controller\Component;
13-
use Cake\Controller\ComponentRegistry;
14-
use Cake\Core\Configure;
15-
use Cake\Event\Event;
16-
use Cake\ORM\Table;
13+
use Cake\ORM\Entity;
14+
1715
/**
1816
* Impersonate component
1917
*/
@@ -26,68 +24,58 @@ class ImpersonateComponent extends Component
2624
* @var array
2725
*/
2826
protected $_defaultConfig = [];
29-
30-
31-
/**
32-
* Initialize and use all Controller library
33-
*
34-
* return none
35-
*/
36-
public function initialize(array $config)
37-
{
38-
$this->controller = $this->_registry->getController();
39-
40-
}
41-
27+
4228
/**
4329
* Function impersonate
4430
*
45-
* receive user Id
46-
* return true
31+
* @param mixed $id
32+
* @return bool
4733
*/
48-
public function login($id){
49-
50-
$this->controller->loadModel('Users');
51-
52-
$originalAuth = $this->request->getSession()->read('Auth');
53-
54-
$users = $this->controller->Users->get($id);
55-
$this->controller->Auth->setUser($users->toArray());
56-
$this->request->getSession()->write('OriginalAuth',$originalAuth);
57-
34+
public function login($id)
35+
{
36+
$this->getController()->loadModel('Users');
37+
38+
$originalAuth = $this->getController()->getRequest()->getSession()->read('Auth');
39+
40+
/** @var Entity $users */
41+
$users = $this->getController()->Users->get($id);
42+
$this->getController()->Auth->setUser($users->toArray());
43+
$this->getController()->getRequest()->getSession()->write('OriginalAuth', $originalAuth);
44+
5845
return true;
5946
}
60-
47+
6148
/**
6249
* Function isImpersonate
6350
*
64-
* To check wether current account is under impersonate
65-
* return boolean
51+
* To check if current account is being impersonated
52+
* @return bool
6653
*/
67-
public function isImpersonate() {
68-
69-
if($this->request->getSession()->read('OriginalAuth')){
54+
public function isImpersonate()
55+
{
56+
if ($this->getController()->getRequest()->getSession()->read('OriginalAuth')) {
57+
7058
return true;
7159
}
72-
60+
7361
return false;
7462
}
75-
63+
7664
/**
7765
* Function logout
7866
*
79-
* To logout impersonate account
80-
* return true
67+
* To log out of impersonated account
68+
*
69+
* @return bool
8170
*/
82-
public function logout() {
83-
84-
if($this->isImpersonate()) {
85-
$Auth = $this->request->session()->read('OriginalAuth');
86-
$this->request->getSession()->write('Auth',$Auth);
87-
88-
$this->request->getSession()->delete('OriginalAuth');
71+
public function logout()
72+
{
73+
if ($this->isImpersonate()) {
74+
$Auth = $this->getController()->getRequest()->getSession()->read('OriginalAuth');
75+
$this->getController()->getRequest()->getSession()->write('Auth', $Auth);
76+
$this->getController()->getRequest()->getSession()->delete('OriginalAuth');
8977
}
90-
78+
9179
return true;
9280
}
9381
}

0 commit comments

Comments
 (0)