From 7b4bbb3472164c3c1c105f27f31d2edb603377f2 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 24 Mar 2015 22:46:56 -0700 Subject: [PATCH] CRM-16173 - Move construction of RegistrationClient to container --- Civi/Core/Container.php | 12 ++++++++++++ api/v3/Cxn.php | 9 +++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Civi/Core/Container.php b/Civi/Core/Container.php index 3df0ebfb1b..93d5bdce0e 100644 --- a/Civi/Core/Container.php +++ b/Civi/Core/Container.php @@ -97,6 +97,12 @@ class Container { )) ->setFactoryService(self::SELF)->setFactoryMethod('createApiKernel'); + $container->setDefinition('cxn_reg_client', new Definition( + '\Civi\Cxn\Rpc\RegistrationClient', + array() + )) + ->setFactoryService(self::SELF)->setFactoryMethod('createRegistrationClient'); + // Expose legacy singletons as services in the container. $singletons = array( 'resources' => 'CRM_Core_Resources', @@ -212,4 +218,10 @@ class Container { return $kernel; } + public function createRegistrationClient() { + $cxnStore = new \CRM_Cxn_CiviCxnStore(); + $client = new \Civi\Cxn\Rpc\RegistrationClient(NULL, $cxnStore, \CRM_Cxn_BAO_Cxn::getSiteCallbackUrl()); + $client->setLog(new \CRM_Utils_SystemLogger()); + return $client; + } } diff --git a/api/v3/Cxn.php b/api/v3/Cxn.php index 2d805d87bc..a136fa7690 100644 --- a/api/v3/Cxn.php +++ b/api/v3/Cxn.php @@ -25,7 +25,6 @@ +--------------------------------------------------------------------+ */ - /** * @param array $params * Array with keys: @@ -54,11 +53,9 @@ function civicrm_api3_cxn_register($params) { } \Civi\Cxn\Rpc\AppMeta::validate($params['appMeta']); - // FIXME Move cxnStore and client into Container. - $cxnStore = new CRM_Cxn_CiviCxnStore(); try { - $client = new \Civi\Cxn\Rpc\RegistrationClient(NULL, $cxnStore, CRM_Cxn_BAO_Cxn::getSiteCallbackUrl()); - $client->setLog(new CRM_Utils_SystemLogger()); + /** @var \Civi\Cxn\Rpc\RegistrationClient $client */ + $client = \Civi\Core\Container::singleton()->get('cxn_reg_client'); list($cxnId, $isOk) = $client->register($params['appMeta']); CRM_Cxn_BAO_Cxn::updateAppMeta($params['appMeta']); } @@ -71,7 +68,7 @@ function civicrm_api3_cxn_register($params) { $result = array( 'cxnId' => $cxnId, ); - return civicrm_api3_create_success(); + return civicrm_api3_create_success($result); } else { return civicrm_api3_create_error('Connection failed'); -- 2.25.1