Commit 048222df authored by totten's avatar totten

\Civi - Use facade instead of Civi\Core\Container::singleton()

parent 711aa5d7
......@@ -119,7 +119,7 @@ class CRM_Admin_Form_Job extends CRM_Admin_Form {
require_once 'api/api.php';
/** @var \Civi\API\Kernel $apiKernel */
$apiKernel = \Civi\Core\Container::singleton()->get('civi_api_kernel');
$apiKernel = \Civi::service('civi_api_kernel');
$apiRequest = \Civi\API\Request::create($fields['api_entity'], $fields['api_action'], array('version' => 3), NULL);
try {
$apiKernel->resolve($apiRequest);
......
......@@ -431,7 +431,7 @@ WHERE id = %1
}
// grab a lock so other processes dont compete and do the same query
$lock = Civi\Core\Container::singleton()->get('lockManager')->acquire("data.core.group.{$groupID}");
$lock = Civi::service('lockManager')->acquire("data.core.group.{$groupID}");
if (!$lock->isAcquired()) {
// this can cause inconsistent results since we dont know if the other process
// will fill up the cache before our calling routine needs it.
......
......@@ -153,7 +153,7 @@ class CRM_Core_BAO_Cache extends CRM_Core_DAO_Cache {
// get a lock so that multiple ajax requests on the same page
// dont trample on each other
// CRM-11234
$lock = Civi\Core\Container::singleton()->get('lockManager')->acquire("cache.{$group}_{$path}._{$componentID}");
$lock = Civi::service('lockManager')->acquire("cache.{$group}_{$path}._{$componentID}");
if (!$lock->isAcquired()) {
CRM_Core_Error::fatal();
}
......
......@@ -525,7 +525,7 @@ class CRM_Core_Config extends CRM_Core_Config_Variables {
* @deprecated
*/
public static function getMailer() {
return Civi\Core\Container::singleton()->get('pear_mail');
return Civi::service('pear_mail');
}
/**
......
......@@ -434,13 +434,13 @@ class CRM_Core_DAO extends DB_DataObject {
$this->update();
$event = new \Civi\Core\DAO\Event\PostUpdate($this);
\Civi\Core\Container::singleton()->get('dispatcher')->dispatch("DAO::post-update", $event);
\Civi::service('dispatcher')->dispatch("DAO::post-update", $event);
}
else {
$this->insert();
$event = new \Civi\Core\DAO\Event\PostUpdate($this);
\Civi\Core\Container::singleton()->get('dispatcher')->dispatch("DAO::post-insert", $event);
\Civi::service('dispatcher')->dispatch("DAO::post-insert", $event);
}
$this->free();
......@@ -478,7 +478,7 @@ class CRM_Core_DAO extends DB_DataObject {
$result = parent::delete($useWhere);
$event = new \Civi\Core\DAO\Event\PostDelete($this, $result);
\Civi\Core\Container::singleton()->get('dispatcher')->dispatch("DAO::post-delete", $event);
\Civi::service('dispatcher')->dispatch("DAO::post-delete", $event);
return $result;
}
......
......@@ -75,8 +75,7 @@ class CRM_Cxn_ApiRouter {
}
$whitelist = \Civi\API\WhitelistRule::createAll($cxn['perm']['api']);
Civi\Core\Container::singleton()
->get('dispatcher')
\Civi::service('dispatcher')
->addSubscriber(new \Civi\API\Subscriber\WhitelistSubscriber($whitelist));
CRM_Core_Config::singleton()->userPermissionTemp = new CRM_Core_Permission_Temp();
if ($cxn['perm']['grant'] === '*') {
......
......@@ -2853,7 +2853,7 @@ WHERE civicrm_mailing_job.id = %1
// check if we are using global locks
foreach ($lockArray as $lockID) {
$cronLock = Civi\Core\Container::singleton()->get('lockManager')->acquire("worker.mailing.send.{$lockID}");
$cronLock = Civi::service('lockManager')->acquire("worker.mailing.send.{$lockID}");
if ($cronLock->isAcquired()) {
$gotCronLock = TRUE;
break;
......
......@@ -136,7 +136,7 @@ class CRM_Mailing_BAO_MailingJob extends CRM_Mailing_DAO_MailingJob {
while ($job->fetch()) {
// still use job level lock for each child job
$lock = Civi\Core\Container::singleton()->get('lockManager')->acquire("data.mailing.job.{$job->id}");
$lock = Civi::service('lockManager')->acquire("data.mailing.job.{$job->id}");
if (!$lock->isAcquired()) {
continue;
}
......@@ -185,7 +185,7 @@ class CRM_Mailing_BAO_MailingJob extends CRM_Mailing_DAO_MailingJob {
// Get the mailer
if ($mode === NULL) {
$mailer = \Civi\Core\Container::singleton()->get('pear_mail');
$mailer = \Civi::service('pear_mail');
}
elseif ($mode == 'sms') {
$mailer = CRM_SMS_Provider::singleton(array('mailing_id' => $job->mailing_id));
......@@ -341,7 +341,7 @@ class CRM_Mailing_BAO_MailingJob extends CRM_Mailing_DAO_MailingJob {
// X Number of child jobs
while ($job->fetch()) {
// still use job level lock for each child job
$lock = Civi\Core\Container::singleton()->get('lockManager')->acquire("data.mailing.job.{$job->id}");
$lock = Civi::service('lockManager')->acquire("data.mailing.job.{$job->id}");
if (!$lock->isAcquired()) {
continue;
}
......
......@@ -172,7 +172,7 @@ class CRM_Mailing_Event_BAO_Forward extends CRM_Mailing_Event_DAO_Forward {
$mailing_obj->find(TRUE);
$config = CRM_Core_Config::singleton();
$mailer = \Civi\Core\Container::singleton()->get('pear_mail');
$mailer = \Civi::service('pear_mail');
$recipient = NULL;
$attachments = NULL;
......
......@@ -201,7 +201,7 @@ class CRM_Mailing_Event_BAO_Reply extends CRM_Mailing_Event_DAO_Reply {
CRM_Mailing_BAO_Mailing::addMessageIdHeader($h, 'r', $eq->job_id, $queue_id, $eq->hash);
$config = CRM_Core_Config::singleton();
$mailer = \Civi\Core\Container::singleton()->get('pear_mail');
$mailer = \Civi::service('pear_mail');
if (is_object($mailer)) {
$errorScope = CRM_Core_TemporaryErrorScope::ignoreException();
......@@ -293,7 +293,7 @@ class CRM_Mailing_Event_BAO_Reply extends CRM_Mailing_Event_DAO_Reply {
$h = $message->headers($headers);
CRM_Mailing_BAO_Mailing::addMessageIdHeader($h, 'a', $eq->job_id, queue_id, $eq->hash);
$mailer = \Civi\Core\Container::singleton()->get('pear_mail');
$mailer = \Civi::service('pear_mail');
if (is_object($mailer)) {
$errorScope = CRM_Core_TemporaryErrorScope::ignoreException();
$mailer->send($to, $h, $b);
......
......@@ -287,7 +287,7 @@ class CRM_Mailing_Event_BAO_Resubscribe {
$b = CRM_Utils_Mail::setMimeParams($message);
$h = $message->headers($headers);
$mailer = \Civi\Core\Container::singleton()->get('pear_mail');
$mailer = \Civi::service('pear_mail');
if (is_object($mailer)) {
$errorScope = CRM_Core_TemporaryErrorScope::ignoreException();
......
......@@ -291,7 +291,7 @@ SELECT civicrm_email.id as email_id
$this->id,
$this->hash
);
$mailer = \Civi\Core\Container::singleton()->get('pear_mail');
$mailer = \Civi::service('pear_mail');
if (is_object($mailer)) {
$errorScope = CRM_Core_TemporaryErrorScope::ignoreException();
......
......@@ -406,7 +406,7 @@ WHERE email = %2
$b = CRM_Utils_Mail::setMimeParams($message);
$h = $message->headers($headers);
$mailer = \Civi\Core\Container::singleton()->get('pear_mail');
$mailer = \Civi::service('pear_mail');
if (is_object($mailer)) {
$errorScope = CRM_Core_TemporaryErrorScope::ignoreException();
......
......@@ -273,8 +273,8 @@ abstract class CRM_Utils_Hook {
*/
public static function pre($op, $objectName, $id, &$params) {
$event = new \Civi\Core\Event\PreEvent($op, $objectName, $id, $params);
\Civi\Core\Container::singleton()->get('dispatcher')->dispatch("hook_civicrm_pre", $event);
\Civi\Core\Container::singleton()->get('dispatcher')->dispatch("hook_civicrm_pre::$objectName", $event);
\Civi::service('dispatcher')->dispatch("hook_civicrm_pre", $event);
\Civi::service('dispatcher')->dispatch("hook_civicrm_pre::$objectName", $event);
return self::singleton()
->invoke(4, $op, $objectName, $id, $params, self::$_nullObject, self::$_nullObject, 'civicrm_pre');
}
......@@ -297,8 +297,8 @@ abstract class CRM_Utils_Hook {
*/
public static function post($op, $objectName, $objectId, &$objectRef) {
$event = new \Civi\Core\Event\PostEvent($op, $objectName, $objectId, $objectRef);
\Civi\Core\Container::singleton()->get('dispatcher')->dispatch("hook_civicrm_post", $event);
\Civi\Core\Container::singleton()->get('dispatcher')->dispatch("hook_civicrm_post::$objectName", $event);
\Civi::service('dispatcher')->dispatch("hook_civicrm_post", $event);
\Civi::service('dispatcher')->dispatch("hook_civicrm_post::$objectName", $event);
return self::singleton()
->invoke(4, $op, $objectName, $objectId, $objectRef, self::$_nullObject, self::$_nullObject, 'civicrm_post');
}
......@@ -1611,7 +1611,7 @@ abstract class CRM_Utils_Hook {
// == 4.5+ ==
$event = new \Civi\Core\Event\UnhandledExceptionEvent($exception, self::$_nullObject);
\Civi\Core\Container::singleton()->get('dispatcher')->dispatch("hook_civicrm_unhandled_exception", $event);
\Civi::service('dispatcher')->dispatch("hook_civicrm_unhandled_exception", $event);
}
/**
......@@ -1861,7 +1861,7 @@ abstract class CRM_Utils_Hook {
*/
public static function caseChange(\Civi\CCase\Analyzer $analyzer) {
$event = new \Civi\CCase\Event\CaseChangeEvent($analyzer);
\Civi\Core\Container::singleton()->get('dispatcher')->dispatch("hook_civicrm_caseChange", $event);
\Civi::service('dispatcher')->dispatch("hook_civicrm_caseChange", $event);
return self::singleton()->invoke(1, $angularModules,
self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject, self::$_nullObject,
......
......@@ -260,7 +260,7 @@ class CRM_Utils_Mail {
$to = array($params['toEmail']);
$result = NULL;
$mailer = \Civi\Core\Container::singleton()->get('pear_mail');
$mailer = \Civi::service('pear_mail');
// Mail_smtp and Mail_sendmail mailers require Bcc anc Cc emails
// be included in both $to and $headers['Cc', 'Bcc']
......
......@@ -50,7 +50,7 @@ class Main extends \CRM_Core_Page {
public function __construct($title = NULL, $mode = NULL, $res = NULL) {
parent::__construct($title, $mode);
$this->res = \CRM_Core_Resources::singleton();
$this->angular = \Civi\Core\Container::singleton()->get('angular');
$this->angular = \Civi::service('angular');
$this->region = \CRM_Utils_Request::retrieve('snippet', 'String') ? 'ajax-snippet' : 'html-header';
}
......
......@@ -26,7 +26,7 @@ class Modules extends \CRM_Core_Page {
/**
* @var \Civi\Angular\Manager $angular
*/
$angular = \Civi\Core\Container::singleton()->get('angular');
$angular = \Civi::service('angular');
$moduleNames = $this->parseModuleNames(\CRM_Utils_Request::retrieve('modules', 'String'), $angular);
switch (\CRM_Utils_Request::retrieve('format', 'String')) {
......
......@@ -72,11 +72,11 @@ class Resolver {
switch ($url['scheme']) {
case 'obj':
// Object: Lookup in container.
return Container::singleton()->get($url['host']);
return \Civi::service($url['host']);
case 'call':
// Callback: Object/method in container.
$obj = Container::singleton()->get($url['host']);
$obj = \Civi::service($url['host']);
return array($obj, ltrim($url['path'], '/'));
case 'api3':
......
......@@ -20,7 +20,7 @@
* @return array|int
*/
function civicrm_api($entity, $action, $params, $extra = NULL) {
return \Civi\Core\Container::singleton()->get('civi_api_kernel')->run($entity, $action, $params, $extra);
return \Civi::service('civi_api_kernel')->run($entity, $action, $params, $extra);
}
/**
......
......@@ -91,7 +91,7 @@ function civicrm_api3_cxn_register($params) {
try {
/** @var \Civi\Cxn\Rpc\RegistrationClient $client */
$client = \Civi\Core\Container::singleton()->get('cxn_reg_client');
$client = \Civi::service('cxn_reg_client');
list($cxnId, $result) = $client->register($appMeta);
CRM_Cxn_BAO_Cxn::updateAppMeta($appMeta);
}
......@@ -133,7 +133,7 @@ function civicrm_api3_cxn_unregister($params) {
$appMeta = CRM_Cxn_BAO_Cxn::getAppMeta($cxnId);
/** @var \Civi\Cxn\Rpc\RegistrationClient $client */
$client = \Civi\Core\Container::singleton()->get('cxn_reg_client');
$client = \Civi::service('cxn_reg_client');
list($cxnId, $result) = $client->unregister($appMeta, CRM_Utils_Array::value('force', $params, FALSE));
return $result;
......@@ -240,7 +240,7 @@ function civicrm_api3_cxn_getlink($params) {
}
/** @var \Civi\Cxn\Rpc\RegistrationClient $client */
$client = \Civi\Core\Container::singleton()->get('cxn_reg_client');
$client = \Civi::service('cxn_reg_client');
return $client->call($appMeta, 'Cxn', 'getlink', array(
'page' => $params['page'],
));
......
......@@ -170,7 +170,7 @@ function civicrm_api3_generic_getfields($apiRequest, $unique = TRUE) {
// find any supplemental information
$hypApiRequest = array('entity' => $apiRequest['entity'], 'action' => $action, 'version' => $apiRequest['version']);
try {
list ($apiProvider, $hypApiRequest) = \Civi\Core\Container::singleton()->get('civi_api_kernel')->resolve($hypApiRequest);
list ($apiProvider, $hypApiRequest) = \Civi::service('civi_api_kernel')->resolve($hypApiRequest);
if (isset($hypApiRequest['function'])) {
$helper = '_' . $hypApiRequest['function'] . '_spec';
}
......
......@@ -39,7 +39,7 @@
*/
function civicrm_api3_generic_getActions($apiRequest) {
civicrm_api3_verify_mandatory($apiRequest, NULL, array('entity'));
$mfp = \Civi\Core\Container::singleton()->get('magic_function_provider');
$mfp = \Civi::service('magic_function_provider');
$actions = $mfp->getActionNames($apiRequest['version'], $apiRequest['entity']);
return civicrm_api3_create_success($actions, $apiRequest['params'], $apiRequest['entity'], 'getactions');
}
......@@ -178,7 +178,7 @@ function civicrm_api3_job_send_reminder($params) {
// in that case (ie. makes it non-configurable via the UI). Another approach would be to set a default of 0
// in the _spec function - but since that is a deprecated value it seems more contentious than this approach
$params['rowCount'] = 0;
$lock = Civi\Core\Container::singleton()->get('lockManager')->acquire('worker.core.ActionSchedule');
$lock = Civi::service('lockManager')->acquire('worker.core.ActionSchedule');
if (!$lock->isAcquired()) {
return civicrm_api3_create_error('Could not acquire lock, another ActionSchedule process is running');
}
......@@ -354,7 +354,7 @@ function civicrm_api3_job_process_sms($params) {
* @return array
*/
function civicrm_api3_job_fetch_bounces($params) {
$lock = Civi\Core\Container::singleton()->get('lockManager')->acquire('worker.mailing.EmailProcessor');
$lock = Civi::service('lockManager')->acquire('worker.mailing.EmailProcessor');
if (!$lock->isAcquired()) {
return civicrm_api3_create_error('Could not acquire lock, another EmailProcessor process is running');
}
......@@ -377,7 +377,7 @@ function civicrm_api3_job_fetch_bounces($params) {
* @return array
*/
function civicrm_api3_job_fetch_activities($params) {
$lock = Civi\Core\Container::singleton()->get('lockManager')->acquire('worker.mailing.EmailProcessor');
$lock = Civi::service('lockManager')->acquire('worker.mailing.EmailProcessor');
if (!$lock->isAcquired()) {
return civicrm_api3_create_error('Could not acquire lock, another EmailProcessor process is running');
}
......@@ -430,7 +430,7 @@ function civicrm_api3_job_process_participant($params) {
* true if success, else false
*/
function civicrm_api3_job_process_membership($params) {
$lock = Civi\Core\Container::singleton()->get('lockManager')->acquire('worker.member.UpdateMembership');
$lock = Civi::service('lockManager')->acquire('worker.member.UpdateMembership');
if (!$lock->isAcquired()) {
return civicrm_api3_create_error('Could not acquire lock, another Membership Processing process is running');
}
......@@ -627,7 +627,7 @@ function civicrm_api3_job_disable_expired_relationships($params) {
* @throws \API_Exception
*/
function civicrm_api3_job_group_rebuild($params) {
$lock = Civi\Core\Container::singleton()->get('lockManager')->acquire('worker.core.GroupRebuild');
$lock = Civi::service('lockManager')->acquire('worker.core.GroupRebuild');
if (!$lock->isAcquired()) {
throw new API_Exception('Could not acquire lock, another EmailProcessor process is running');
}
......
......@@ -697,7 +697,7 @@ CRM_Utils_System::authenticateScript(TRUE);
//log the execution of script
CRM_Core_Error::debug_log_message('ContributionProcessor.php');
$lock = Civi\Core\Container::singleton()->get('lockManager')->acquire('worker.contribute.CiviContributeProcessor');
$lock = Civi::service('lockManager')->acquire('worker.contribute.CiviContributeProcessor');
if ($lock->isAcquired()) {
// try to unset any time limits
......
......@@ -55,14 +55,14 @@ class CRM_Core_ManagedEntitiesTest extends CiviUnitTestCase {
),
);
$this->apiKernel = \Civi\Core\Container::singleton()->get('civi_api_kernel');
$this->apiKernel = \Civi::service('civi_api_kernel');
$this->adhocProvider = new \Civi\API\Provider\AdhocProvider(3, 'CustomSearch');
$this->apiKernel->registerApiProvider($this->adhocProvider);
}
public function tearDown() {
parent::tearDown();
\Civi\Core\Container::singleton(TRUE);
\Civi::reset();
}
/**
......
......@@ -76,7 +76,7 @@ namespace Civi\Core {
*/
public function testCall() {
// Note: ResolverTestExampleService is implemented at the bottom of this file.
Container::singleton()->set('callbackTestService', new ResolverTestExampleService());
\Civi::container()->set('callbackTestService', new ResolverTestExampleService());
$cb = $this->resolver->get('call://callbackTestService/ping');
$expected = 'service dummy received foo';
$actual = call_user_func($cb, 'foo');
......@@ -116,7 +116,7 @@ namespace Civi\Core {
*/
public function testObj() {
// Note: ResolverTestExampleService is implemented at the bottom of this file.
Container::singleton()->set('callbackTestService', new ResolverTestExampleService());
\Civi::container()->set('callbackTestService', new ResolverTestExampleService());
$obj = $this->resolver->get('obj://callbackTestService');
$this->assertTrue($obj instanceof ResolverTestExampleService);
}
......
......@@ -398,7 +398,7 @@ class CiviUnitTestCase extends PHPUnit_Extensions_Database_TestCase {
// initialize the object once db is loaded
$config = CRM_Core_Config::singleton();
Civi\Core\Container::singleton(TRUE);
\Civi::reset();
// when running unit tests, use mockup user framework
$config->setUserFramework('UnitTests');
......
......@@ -62,7 +62,7 @@ class api_v3_AttachmentTest extends CiviUnitTestCase {
protected function tearDown() {
parent::tearDown();
$this->cleanupFiles();
\Civi\Core\Container::singleton(TRUE);
\Civi::reset();
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment