本文整理汇总了PHP中CRM_Utils_Hook::singleton方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_Hook::singleton方法的具体用法?PHP CRM_Utils_Hook::singleton怎么用?PHP CRM_Utils_Hook::singleton使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Utils_Hook
的用法示例。
在下文中一共展示了CRM_Utils_Hook::singleton方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testHookAlterMailer
public function testHookAlterMailer()
{
$test = $this;
$mockMailer = new CRM_Utils_FakeObject(array('send' => function ($recipients, $headers, $body) use($test) {
$test->calls['send']++;
$test->assertEquals(array('to@example.org'), $recipients);
$test->assertEquals('Subject Example', $headers['Subject']);
}));
CRM_Utils_Hook::singleton()->setHook('civicrm_alterMailer', function (&$mailer, $driver, $params) use($test, $mockMailer) {
$test->calls['civicrm_alterMailer']++;
$test->assertTrue(is_string($driver) && !empty($driver));
$test->assertTrue(is_array($params));
$test->assertTrue(is_callable(array($mailer, 'send')));
$mailer = $mockMailer;
});
$params = array();
$params['groupName'] = 'CRM_Core_Config_MailerTest';
$params['from'] = 'From Example <from@example.com>';
$params['toName'] = 'To Example';
$params['toEmail'] = 'to@example.org';
$params['subject'] = 'Subject Example';
$params['text'] = 'Example text';
$params['html'] = '<p>Example HTML</p>';
CRM_Utils_Mail::send($params);
$this->assertEquals(1, $this->calls['civicrm_alterMailer']);
$this->assertEquals(1, $this->calls['send']);
// once more, just to make sure the hooks are called right #times
CRM_Utils_Mail::send($params);
CRM_Utils_Mail::send($params);
$this->assertEquals(1, $this->calls['civicrm_alterMailer']);
$this->assertEquals(3, $this->calls['send']);
}
示例2: tearDown
/**
*
*/
function tearDown()
{
$this->_mut->stop();
$this->quickCleanup(array('civicrm_mailing', 'civicrm_mailing_job', 'civicrm_contact'));
CRM_Utils_Hook::singleton()->reset();
parent::tearDown();
}
示例3: tearDown
function tearDown()
{
$this->quickCleanup(array('civicrm_job', 'civicrm_action_log', 'civicrm_action_schedule'));
$this->quickCleanUpFinancialEntities();
CRM_Utils_Hook::singleton()->reset();
parent::tearDown();
}
示例4: tearDown
public function tearDown()
{
CRM_Utils_Hook::singleton()->reset();
parent::tearDown();
$this->callAPISuccess('system', 'flush', array());
$this->quickCleanup(array('civicrm_domain'));
}
示例5: testHookCron
public function testHookCron()
{
$hook = $this->getMock('stdClass', array('civicrm_cron'));
$hook->expects($this->once())->method('civicrm_cron')->with($this->isInstanceOf('CRM_Core_JobManager'));
CRM_Utils_Hook::singleton()->setMock($hook);
$jobManager = new CRM_Core_JobManager();
$jobManager->execute(FALSE);
}
示例6: tearDown
/**
* (non-PHPdoc)
* @see CiviUnitTestCase::tearDown()
*/
public function tearDown()
{
CRM_Utils_Hook::singleton()->reset();
$tablesToTruncate = array('civicrm_contact', 'civicrm_group_contact', 'civicrm_group', 'civicrm_acl', 'civicrm_acl_cache', 'civicrm_acl_entity_role', 'civicrm_acl_contact_cache', 'civicrm_contribution', 'civicrm_participant', 'civicrm_uf_match');
$this->quickCleanup($tablesToTruncate);
$config = CRM_Core_Config::singleton();
unset($config->userPermissionClass->permissions);
}
示例7: tearDown
public function tearDown()
{
CRM_Utils_Hook::singleton()->reset();
$this->quickCleanup(array('civicrm_group'));
$config = CRM_Core_Config::singleton();
unset($config->userPermissionClass->permissions);
parent::tearDown();
}
示例8: tearDown
/**
* (non-PHPdoc)
* @see CiviUnitTestCase::tearDown()
*/
function tearDown()
{
CRM_Utils_Hook::singleton()->reset();
$tablesToTruncate = array('civicrm_contact');
$this->quickCleanup($tablesToTruncate);
$config = CRM_Core_Config::singleton();
unset($config->userPermissionClass->permissions);
}
示例9: pdf_shared_token
/**
* This hook is called once for every batch before the pdf template is rendered.
* You should use this for performance reasons when the token can be shared between chunk items (for example a contact
* address that is the same for all files)
*
* You can implement this hook to add/modify template tokens
* e.g. in your hook implementation call $template->assign('myCustomToken', 'my custom token');
* and place a token called {$myCustomToken} in the template.
*
* @param object $template
*
* @return mixed based on op. pre-hooks return a boolean or
* an error message which aborts the operation
* @access public
*/
static function pdf_shared_token(&$template, &$chunk)
{
if (version_compare(CRM_Utils_System::version(), '4.5', '<')) {
return CRM_Utils_Hook::singleton()->invoke(1, $template, $chunk_item, self::$null, self::$null, self::$null, 'civicrm_pdf_shared_token');
} else {
return CRM_Utils_Hook::singleton()->invoke(1, $template, $chunk_item, self::$null, self::$null, self::$null, self::$null, 'civicrm_pdf_shared_token');
}
}
示例10: tearDown
/**
*/
public function tearDown()
{
$this->_mut->stop();
// $this->quickCleanup(array('civicrm_mailing', 'civicrm_mailing_job', 'civicrm_contact'));
CRM_Utils_Hook::singleton()->reset();
CRM_Mailing_BAO_MailingJob::$mailsProcessed = 0;
// DGW
parent::tearDown();
}
示例11: mapAccountsData
/**
* This hook data transforms data stored in accounts_data to be formatted into a standard format.
*
* The called hook is expected to add a key 'civicrm_formatted' to the accountsData array
* with the data using the same field names as the relevant CiviCRM api.
*
* @param array $accountsData data from accounts system
* @param string $entity entity - eg. 'AccountContact'
* @param string $plugin plugin in use
*
* @return mixed
* Ignore value.
*/
public static function mapAccountsData(&$accountsData, $entity, $plugin)
{
$codeVersion = explode('.', CRM_Utils_System::version());
if (version_compare($codeVersion[0] . '.' . $codeVersion[1], 4.5) >= 0) {
return CRM_Utils_Hook::singleton()->invoke(3, $accountsData, $entity, $plugin, CRM_Core_DAO::$_nullObject, CRM_Core_DAO::$_nullObject, CRM_Core_DAO::$_nullObject, 'civicrm_mapAccountsData');
} else {
return CRM_Utils_Hook::singleton()->invoke(3, $accountsData, $entity, $plugin, CRM_Core_DAO::$_nullObject, CRM_Core_DAO::$_nullObject, 'civicrm_mapAccountsData');
}
}
示例12: invoke
private function invoke($fnSuffix, $numParams, &$arg1 = null, &$arg2 = null, &$arg3 = null, &$arg4 = null, &$arg5 = null)
{
$hook = CRM_Utils_Hook::singleton();
$civiVersion = CRM_Core_BAO_Domain::version();
if (version_compare('4.4', $civiVersion, '<=')) {
//in CiviCRM 4.4 the invoke function has 5 arguments maximum
return $hook->invoke($numParams, $arg1, $arg2, $arg3, $arg4, $arg5, $fnSuffix);
}
//in CiviCRM 4.5 and later the invoke function has 6 arguments
return $hook->invoke($numParams, $arg1, $arg2, $arg3, $arg4, $arg5, null, $fnSuffix);
}
示例13: setUp
public function setUp()
{
parent::setUp();
/** @var $hooks \CRM_Utils_Hook_UnitTests */
$hooks = \CRM_Utils_Hook::singleton();
$hooks->setHook('civicrm_caseTypes', array($this, 'hook_caseTypes'));
\CRM_Case_XMLRepository::singleton(TRUE);
\CRM_Case_XMLProcessor::flushStaticCaches();
// CRM-9404 - set-up is a bit cumbersome but had to put something in place to set up activity types & case types
//. Using XML was causing breakage as id numbers were changing over time
// & was really hard to troubleshoot as involved truncating option_value table to mitigate this & not leaving DB in a
// state where tests could run afterwards without re-loading.
$this->caseStatusGroup = $this->callAPISuccess('option_group', 'get', array('name' => 'case_status', 'format.only_id' => 1));
$optionValues = array('Medical evaluation' => 'Medical evaluation', 'Mental health evaluation' => "Mental health evaluation", 'Secure temporary housing' => 'Secure temporary housing', 'Long-term housing plan' => 'Long-term housing plan', 'ADC referral' => 'ADC referral', 'Income and benefits stabilization' => 'Income and benefits stabilization');
foreach ($optionValues as $name => $label) {
$activityTypes = $this->callAPISuccess('option_value', 'Create', array('option_group_id' => 2, 'name' => $name, 'label' => $label, 'component_id' => 7));
// store for cleanup
$this->optionValues[] = $activityTypes['id'];
}
// We used to be inconsistent about "HousingSupport" vs "housing_support".
// Now, the rule is simply: use the "name" from "civicrm_case_type.name".
$this->caseType = 'housing_support';
$this->caseTypeId = 1;
$this->tablesToTruncate = array('civicrm_activity', 'civicrm_contact', 'civicrm_custom_group', 'civicrm_custom_field', 'civicrm_case', 'civicrm_case_contact', 'civicrm_case_activity', 'civicrm_case_type', 'civicrm_activity_contact', 'civicrm_managed', 'civicrm_relationship', 'civicrm_relationship_type');
$this->quickCleanup($this->tablesToTruncate);
$this->loadAllFixtures();
// enable the default custom templates for the case type xml files
$this->customDirectories(array('template_path' => TRUE));
// case is not enabled by default
$enableResult = CRM_Core_BAO_ConfigSetting::enableComponent('CiviCase');
$this->assertTrue($enableResult, 'Cannot enable CiviCase in line ' . __LINE__);
// create a logged in USER since the code references it for source_contact_id
$this->createLoggedInUser();
$session = CRM_Core_Session::singleton();
$this->_loggedInUser = $session->get('userID');
/// note that activityType options are cached by the FULL set of options you pass in
// ie. because Activity api includes campaign in it's call cache is not flushed unless
// included in this call. Also note flush function doesn't work on this property as it sets to null not empty array
CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name', TRUE);
}
示例14: setUp
public function setUp()
{
parent::setUp();
CRM_Utils_Hook::singleton()->setHook('civicrm_fieldOptions', array($this, 'hook_civicrm_fieldOptions'));
}
示例15: clearModuleList
/**
* Flush information about loaded modules.
*/
public function clearModuleList()
{
CRM_Extension_System::singleton()->getCache()->flush();
CRM_Utils_Hook::singleton(TRUE);
CRM_Core_PseudoConstant::getModuleExtensions(TRUE);
CRM_Core_Module::getAll(TRUE);
}