From 998ffd04c7b6164da46645e7b1cc6fbe7488e6ee Mon Sep 17 00:00:00 2001 From: Vaidas Lungis Date: Wed, 18 Mar 2015 14:31:44 +0200 Subject: [PATCH] refactor $app->getApiClient(); to $api = $this->di['api_client'] or $this->di['is_client_logged']; getApiClient is deprecated --- src/bb-di.php | 8 +++++++- src/bb-modules/Client/Controller/Client.php | 6 +++--- src/bb-modules/Email/Controller/Client.php | 4 ++-- src/bb-modules/Example/Controller/Client.php | 4 ++-- src/bb-modules/Invoice/Controller/Client.php | 2 +- src/bb-modules/Order/Controller/Client.php | 4 ++-- src/bb-modules/Servicedownloadable/Controller/Client.php | 2 +- src/bb-modules/Support/Controller/Client.php | 4 ++-- tests/bb-modules/Example/Controller/ClientTest.php | 2 -- 9 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/bb-di.php b/src/bb-di.php index 4d18ec385..aa9c430d7 100644 --- a/src/bb-di.php +++ b/src/bb-di.php @@ -163,10 +163,16 @@ $di['twig'] = function () use ($di) { return $twig; }; -$di['loggedin_client'] = function() use ($di) { + +$di['is_client_logged'] = function() use($di) { if(!$di['auth']->isClientLoggedIn()) { throw new Exception('Client is not logged in'); } + return true; +}; + +$di['loggedin_client'] = function() use ($di) { + $di['is_client_logged']; $client_id = $di['session']->get('client_id'); return $di['db']->getExistingModelById('Client', $client_id); }; diff --git a/src/bb-modules/Client/Controller/Client.php b/src/bb-modules/Client/Controller/Client.php index 2fe5b8ef4..650ac6193 100644 --- a/src/bb-modules/Client/Controller/Client.php +++ b/src/bb-modules/Client/Controller/Client.php @@ -65,7 +65,7 @@ class Client implements \Box\InjectionAwareInterface public function get_client_index(\Box_App $app) { - $api = $app->getApiClient(); + $this->di['is_client_logged']; return $app->render('mod_client_index'); } @@ -80,14 +80,14 @@ class Client implements \Box\InjectionAwareInterface public function get_client_logout(\Box_App $app) { - $api = $app->getApiClient(); + $api = $this->di['api_client']; $api->profile_logout(); $app->redirect('/'); } public function get_client_page(\Box_App $app, $page) { - $api = $app->getApiClient(); + $this->di['is_client_logged']; $template = 'mod_client_'.$page; return $app->render($template); } diff --git a/src/bb-modules/Email/Controller/Client.php b/src/bb-modules/Email/Controller/Client.php index 2d72761df..4d0452bf2 100644 --- a/src/bb-modules/Email/Controller/Client.php +++ b/src/bb-modules/Email/Controller/Client.php @@ -41,12 +41,12 @@ class Client implements \Box\InjectionAwareInterface public function get_emails(\Box_App $app) { - $api = $app->getApiClient(); + $this->di['is_client_logged']; return $app->render('mod_email_index'); } public function get_email(\Box_App $app, $id) { - $api = $app->getApiClient(); + $api = $this->di['api_client']; $data = array('id'=>$id); $email = $api->email_get($data); return $app->render('mod_email_email', array('email'=>$email)); diff --git a/src/bb-modules/Example/Controller/Client.php b/src/bb-modules/Example/Controller/Client.php index 7a99115c0..803aef9a4 100644 --- a/src/bb-modules/Example/Controller/Client.php +++ b/src/bb-modules/Example/Controller/Client.php @@ -57,8 +57,8 @@ class Client implements \Box\InjectionAwareInterface public function get_protected(\Box_App $app) { - // call $app->getApiClient() method to validate if client is logged in - $api = $app->getApiClient(); + // call $this->di['is_client_logged'] method to validate if client is logged in + $this->di['is_client_logged']; return $app->render('mod_example_index', array('show_protected'=>true)); } } \ No newline at end of file diff --git a/src/bb-modules/Invoice/Controller/Client.php b/src/bb-modules/Invoice/Controller/Client.php index 467da1f81..0cb8548d2 100644 --- a/src/bb-modules/Invoice/Controller/Client.php +++ b/src/bb-modules/Invoice/Controller/Client.php @@ -48,7 +48,7 @@ class Client implements \Box\InjectionAwareInterface public function get_invoices(\Box_App $app) { - $api = $app->getApiClient(); + $this->di['is_client_logged']; return $app->render('mod_invoice_index'); } diff --git a/src/bb-modules/Order/Controller/Client.php b/src/bb-modules/Order/Controller/Client.php index fefa5bfba..3b6daf330 100644 --- a/src/bb-modules/Order/Controller/Client.php +++ b/src/bb-modules/Order/Controller/Client.php @@ -72,13 +72,13 @@ class Client implements \Box\InjectionAwareInterface public function get_orders(\Box_App $app) { - $api = $app->getApiClient(); + $this->di['is_client_logged']; return $app->render('mod_order_list'); } public function get_order(\Box_App $app, $id) { - $api = $app->getApiClient(); + $api = $this->di['api_client']; $data = array( 'id' => $id, ); diff --git a/src/bb-modules/Servicedownloadable/Controller/Client.php b/src/bb-modules/Servicedownloadable/Controller/Client.php index a309a19d3..f9fef8bac 100644 --- a/src/bb-modules/Servicedownloadable/Controller/Client.php +++ b/src/bb-modules/Servicedownloadable/Controller/Client.php @@ -39,7 +39,7 @@ class Client implements \Box\InjectionAwareInterface public function get_download(\Box_App $app, $id) { - $api = $app->getApiClient(); + $api = $this->di['api_client']; $data = array( 'order_id' => $id, ); diff --git a/src/bb-modules/Support/Controller/Client.php b/src/bb-modules/Support/Controller/Client.php index 10f5706ad..9da41eb37 100644 --- a/src/bb-modules/Support/Controller/Client.php +++ b/src/bb-modules/Support/Controller/Client.php @@ -43,13 +43,13 @@ class Client implements \Box\InjectionAwareInterface public function get_tickets(\Box_App $app) { - $api = $app->getApiClient(); + $this->di['is_client_logged']; return $app->render('mod_support_tickets'); } public function get_ticket(\Box_App $app, $id) { - $api = $app->getApiClient(); + $api = $this->di['api_client']; $ticket = $api->support_ticket_get(array('id'=>$id)); return $app->render('mod_support_ticket', array('ticket'=>$ticket)); } diff --git a/tests/bb-modules/Example/Controller/ClientTest.php b/tests/bb-modules/Example/Controller/ClientTest.php index 15fee1712..ca196fa86 100644 --- a/tests/bb-modules/Example/Controller/ClientTest.php +++ b/tests/bb-modules/Example/Controller/ClientTest.php @@ -43,8 +43,6 @@ class ClientTest extends \PHPUnit_Framework_TestCase { public function testget_protected() { $boxAppMock = $this->getMockBuilder('\Box_App')->disableOriginalConstructor()->getMock(); - $boxAppMock->expects($this->atLeastOnce()) - ->method('getApiClient'); $boxAppMock->expects($this->atLeastOnce()) ->method('render') ->with('mod_example_index');