本文整理汇总了PHP中OA_ServiceLocator::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP OA_ServiceLocator::instance方法的具体用法?PHP OA_ServiceLocator::instance怎么用?PHP OA_ServiceLocator::instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OA_ServiceLocator
的用法示例。
在下文中一共展示了OA_ServiceLocator::instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
function __construct()
{
// Check auto-maintenance settings
$aConf = $GLOBALS['_MAX']['CONF'];
$this->isAutoMaintenanceEnabled = !empty($aConf['maintenance']['autoMaintenance']);
// Get time 1 hour ago
$oServiceLocator =& OA_ServiceLocator::instance();
$oNow = $oServiceLocator->get('now');
if ($oNow) {
$oOneHourAgo = new Date($oNow);
} else {
$oOneHourAgo = new Date();
}
$oOneHourAgo->subtractSpan(new Date_Span('0-1-0-0'));
// Get last runs
$oLastCronRun = OX_Maintenance::getLastScheduledRun();
$oLastRun = OX_Maintenance::getLastRun();
// Reset minutes and seconds
if (isset($oLastCronRun)) {
$oLastCronRun->setMinute(0);
$oLastCronRun->setSecond(0);
}
if (isset($oLastRun)) {
$oLastRun->setMinute(0);
$oLastRun->setSecond(0);
}
// Check if any kind of maintenance was run
if (isset($oLastCronRun) && !$oOneHourAgo->after($oLastCronRun)) {
$this->isScheduledMaintenanceRunning = true;
} elseif (isset($oLastRun) && !$oOneHourAgo->after($oLastRun)) {
$this->isAutoMaintenanceRunning = true;
}
}
示例2: Date
/**
* A method to get the "now" date class, eventually subtracting
* some time
*
* @param int $subtractSeconds
* @return Date
*/
function &getDate($subtractSeconds = 0)
{
$oServiceLocator =& OA_ServiceLocator::instance();
$oNow = new Date($oServiceLocator->get('now'));
if ($subtractSeconds) {
$oNow->subtractSeconds($subtractSeconds);
}
return $oNow;
}
示例3: _useDefaultDal
function _useDefaultDal()
{
$oServiceLocator =& OA_ServiceLocator::instance();
$dal =& $oServiceLocator->get('MAX_Dal_Inventory_Trackers');
if (!$dal) {
$dal = new MAX_Dal_Inventory_Trackers();
}
$this->_dal =& $dal;
}
示例4: _useDefaultDal
function _useDefaultDal()
{
$oServiceLocator =& OA_ServiceLocator::instance();
$dal =& $oServiceLocator->get('OA_Dal_PasswordRecovery');
if (!$dal) {
$dal = new OA_Dal_PasswordRecovery();
}
$this->_dal =& $dal;
}
示例5: _saveSummary
/**
* A private method for summarising data into the final tables when
* at least one hour is complete.
*
* @access private
* @param PEAR::Date $oStartDate The start date of the complete hour(s).
* @param PEAR::Date $oEndDate The end date of the complete hour(s).
*/
function _saveSummary($oStartDate, $oEndDate)
{
$message = '- Updating the data_summary_ad_hourly table for data after ' . $oStartDate->format('%Y-%m-%d %H:%M:%S') . ' ' . $oStartDate->tz->getShortName();
$this->oController->report .= $message . ".\n";
OA::debug($message, PEAR_LOG_DEBUG);
$oServiceLocator =& OA_ServiceLocator::instance();
$oDal =& $oServiceLocator->get('OX_Dal_Maintenance_Statistics');
$aTypes = array('types' => array(0 => 'request', 1 => 'impression', 2 => 'click'), 'connections' => array(1 => MAX_CONNECTION_AD_IMPRESSION, 2 => MAX_CONNECTION_AD_CLICK));
$oDal->saveSummary($oStartDate, $oEndDate, $aTypes, 'data_intermediate_ad', 'data_summary_ad_hourly');
}
示例6: testRunnerHasResources
function testRunnerHasResources()
{
// Mock the OA_Dal_Maintenance_Priority class used in the constructor method
$oDal = new MockOA_Dal_Maintenance_Priority($this);
$oServiceLocator =& OA_ServiceLocator::instance();
$oServiceLocator->register('OA_Dal_Maintenance_Priority', $oDal);
$task = new OA_Maintenance_Priority_AdServer_Task();
$this->assertTrue(is_object($task->oDal));
$this->assertTrue(is_a($task->oDal, 'MockOA_Dal_Maintenance_Priority'));
}
示例7: strtolower
/**
* Method to create/register/return the Maintenance Priority table class.
*
* @access private
* @return OA_DB_Table_Priority
*/
function &_getMaxTablePriorityObj()
{
$dbType = strtolower($GLOBALS['_MAX']['CONF']['database']['type']);
$oServiceLocator =& OA_ServiceLocator::instance();
$oTable = $oServiceLocator->get('OA_DB_Table_Priority');
if (!$oTable) {
$oTable =& OA_DB_Table_Priority::singleton();
$oServiceLocator->register('OA_DB_Table_Priority', $oTable);
}
return $oTable;
}
示例8: run
/**
* The implementation of the OA_Task::run() method that performs
* the required task of activating/deactivating campaigns.
*/
function run()
{
if ($this->oController->updateIntermediate) {
$oServiceLocator =& OA_ServiceLocator::instance();
$oDate =& $oServiceLocator->get('now');
$oDal =& $oServiceLocator->get('OX_Dal_Maintenance_Statistics');
$message = '- Managing (activating/deactivating) campaigns';
$this->oController->report .= "{$message}.\n";
OA::debug($message);
$this->report .= $oDal->manageCampaigns($oDate);
}
}
示例9: testRun
/**
* A method to test the run() method.
*/
function testRun()
{
$oServiceLocator =& OA_ServiceLocator::instance();
$aConf =& $GLOBALS['_MAX']['CONF'];
$className = 'OX_Dal_Maintenance_Statistics_' . ucfirst(strtolower($aConf['database']['type']));
$mockClassName = 'MockOX_Dal_Maintenance_Statistics_' . ucfirst(strtolower($aConf['database']['type']));
$aConf['maintenance']['operationInterval'] = 60;
// Test 1: Test with the bucket data not having been migrated,
// and ensure that the DAL calls to de-duplicate and
// reject conversions are not made
// Set the controller class
$oMaintenanceStatistics = new OX_Maintenance_Statistics();
$oServiceLocator->register('Maintenance_Statistics_Controller', $oMaintenanceStatistics);
// Mock the MSE DAL used to de-duplicate conversions,
// and set the expectations of the calls to the DAL
Mock::generate($className);
$oDal = new $mockClassName($this);
$oDal->expectNever('deduplicateConversions');
$oDal->expectNever('rejectEmptyVarConversions');
$oDal->OX_Dal_Maintenance_Statistics();
$oServiceLocator->register('OX_Dal_Maintenance_Statistics', $oDal);
// Set the controlling class' status and test
$oDeDuplicateConversions = new OX_Maintenance_Statistics_Task_DeDuplicateConversions();
$oDeDuplicateConversions->oController->updateIntermediate = false;
$oDeDuplicateConversions->run();
$oDal->tally();
// Test 2: Test with the bucket data having been migrated, and
// ensure that the DALL calls to de-duplicate and reject
// conversions are made correctly
// Set the controller class
$oMaintenanceStatistics = new OX_Maintenance_Statistics();
$oServiceLocator->register('Maintenance_Statistics_Controller', $oMaintenanceStatistics);
// Mock the MSE DAL used to de-duplicate conversions,
// and set the expectations of the calls to the DAL
Mock::generate($className);
$oDal = new $mockClassName($this);
$oDate = new Date('2008-09-08 16:59:59');
$oDate->addSeconds(1);
$oDal->expectOnce('deduplicateConversions', array($oDate, new Date('2008-09-08 17:59:59')));
$oDal->expectOnce('rejectEmptyVarConversions', array($oDate, new Date('2008-09-08 17:59:59')));
$oDal->OX_Dal_Maintenance_Statistics();
$oServiceLocator->register('OX_Dal_Maintenance_Statistics', $oDal);
// Set the controlling class' status and test
$oDeDuplicateConversions = new OX_Maintenance_Statistics_Task_DeDuplicateConversions();
$oDeDuplicateConversions->oController->updateIntermediate = true;
$oDeDuplicateConversions->oController->oLastDateIntermediate = new Date('2008-09-08 16:59:59');
$oDeDuplicateConversions->oController->oUpdateIntermediateToDate = new Date('2008-09-08 17:59:59');
$oDeDuplicateConversions->run();
$oDal->tally();
TestEnv::restoreConfig();
}
示例10: run
/**
* The implementation of the OA_Task::run() method that performs
* the required task of managing conversions.
*/
function run()
{
if ($this->oController->updateIntermediate) {
// Preapre the start date for the management of conversions
$oStartDate = new Date();
$oStartDate->copy($this->oController->oLastDateIntermediate);
$oStartDate->addSeconds(1);
// Get the MSE DAL to perform the conversion management
$oServiceLocator =& OA_ServiceLocator::instance();
$oDal =& $oServiceLocator->get('OX_Dal_Maintenance_Statistics');
// Manage conversions
$oDal->manageConversions($oStartDate, $this->oController->oUpdateIntermediateToDate);
}
}
示例11: run
/**
* The main method of the class, that is run by the controlling
* task runner class.
*/
function run()
{
OA::debug('Running Maintenance Priority Engine: Priority Compensation', PEAR_LOG_DEBUG);
// Record the start of this Priority Compensation run
$oStartDate = new Date();
// Prepare an array for the priority results
$aPriorities = array();
// Get the details of the last time Priority Compensation started running
$aDates = $this->oDal->getMaintenancePriorityLastRunInfo(DAL_PRIORITY_UPDATE_PRIORITY_COMPENSATION, array('start_run', 'end_run'));
if (!is_null($aDates)) {
// Set the details of the last time Priority Compensation started running
$this->aLastRun['start_run'] = new Date($aDates['start_run']);
// Set the details of the current date/time
$oServiceLocator =& OA_ServiceLocator::instance();
$this->aLastRun['now'] =& $oServiceLocator->get('now');
}
// Get all creative/zone information
$aZones =& $this->_buildClasses();
// For every zone with creatives linked to it...
if (!empty($aZones)) {
$this->globalMessage = '';
OA::debug('- Calculating priority values for creative/zone pairs', PEAR_LOG_DEBUG);
foreach ($aZones as $oZone) {
// Is this Zone ID 0, the Direct Selection zone?
if ($oZone->id == 0) {
// Calculate simplistic priorities based on the required impression
// values without any form of priority compensation based on past
// information about previous priorities, as this is the Direct
// Selection zone, and priority compensation adjustment is not required
OA::debug(' - Calculating priority values for creatives in Zone ID ' . $oZone->id . ': Basic', PEAR_LOG_DEBUG);
$aPriorities[$oZone->id] = $this->initialPriorities($oZone);
} else {
// Calculate the priorities based on the required impression
// values and the past information about previous priorities
OA::debug(' - Calculating priority values for creatives in Zone ID ' . $oZone->id . ': Compensated', PEAR_LOG_DEBUG);
$aPriorities[$oZone->id] = $this->compensatedPriorities($oZone);
}
}
// Store the calculated priorities
$this->oDal->updatePriorities($aPriorities);
// Record the completion of the task in the database; note that the $oUpdateTo
// parameter is "null", as this value is not appropriate when recording Priority
// Compensation task runs - all that matters are the start and end dates
OA::debug('- Recording completion of the Priority Compensation task', PEAR_LOG_DEBUG);
$oEndDate = new Date();
$this->oDal->setMaintenancePriorityLastRunInfo($oStartDate, $oEndDate, null, DAL_PRIORITY_UPDATE_PRIORITY_COMPENSATION);
}
}
示例12: run
/**
* The implementation of the OA_Task::run() method that performs
* the required task of de-duplicating and rejecting conversions.
*/
function run()
{
if ($this->oController->updateIntermediate) {
// Preapre the start date for the de-duplication/rejection
$oStartDate = new Date();
$oStartDate->copy($this->oController->oLastDateIntermediate);
$oStartDate->addSeconds(1);
// Get the MSE DAL to perform the de-duplication
$oServiceLocator =& OA_ServiceLocator::instance();
$oDal =& $oServiceLocator->get('OX_Dal_Maintenance_Statistics');
// De-duplicate conversions
$oDal->deduplicateConversions($oStartDate, $this->oController->oUpdateIntermediateToDate);
// Reject empty variable conversions
$oDal->rejectEmptyVarConversions($oStartDate, $this->oController->oUpdateIntermediateToDate);
}
}
示例13: run
/**
* A method to run distributed maintenance.
*/
function run()
{
if (empty($GLOBALS['_MAX']['CONF']['lb']['enabled'])) {
OA::debug('Distributed stats disabled, not running Maintenance Distributed Engine', PEAR_LOG_INFO);
return;
}
if (!empty($GLOBALS['_MAX']['CONF']['rawDatabase'])) {
$GLOBALS['_MAX']['CONF']['database'] = $GLOBALS['_MAX']['CONF']['rawDatabase'] + $GLOBALS['_MAX']['CONF']['database'];
OA::debug('rawDatabase functionality is being used, switching settings', PEAR_LOG_INFO);
}
$oLock =& OA_DB_AdvisoryLock::factory();
if (!$oLock->get(OA_DB_ADVISORYLOCK_DISTRIBUTED)) {
OA::debug('Maintenance Distributed Engine Already Running', PEAR_LOG_INFO);
return;
}
OA::debug('Running Maintenance Distributed Engine', PEAR_LOG_INFO);
// Attempt to increase PHP memory
OX_increaseMemoryLimit(OX_getMinimumRequiredMemory('maintenance'));
// Ensure the current time is registered with the OA_ServiceLocator
$oServiceLocator =& OA_ServiceLocator::instance();
$oNow =& $oServiceLocator->get('now');
if (!$oNow) {
// Record the current time, and register with the OA_ServiceLocator
$oNow = new Date();
$oServiceLocator->register('now', $oNow);
}
OA::debug(' - Current time is ' . $oNow->format('%Y-%m-%d %H:%M:%S') . ' ' . $oNow->tz->getShortName(), PEAR_LOG_DEBUG);
// Get the components of the deliveryLog extension
$aBuckets = OX_Component::getComponents('deliveryLog');
// Copy buckets' records with "interval_start" up to and including previous OI start,
// and then prune the data processed
$aPreviousOperationIntervalDates = OX_OperationInterval::convertDateToPreviousOperationIntervalStartAndEndDates($oNow);
OA::debug(' - Will process data for all operation intervals before and up to start', PEAR_LOG_DEBUG);
OA::debug(' time of ' . $aPreviousOperationIntervalDates['start']->format('%Y-%m-%d %H:%M:%S') . ' ' . $aPreviousOperationIntervalDates['start']->tz->getShortName(), PEAR_LOG_DEBUG);
foreach ($aBuckets as $sBucketName => $oBucketClass) {
if ($oBucketClass->testStatisticsMigration($oBucketClass->getStatisticsMigration())) {
$oBucketClass->processBucket($aPreviousOperationIntervalDates['start']);
$oBucketClass->pruneBucket($aPreviousOperationIntervalDates['start']);
} else {
OA::debug(' - Skipping ' . $sBucketName, PEAR_LOG_DEBUG);
}
}
$oLock->release();
OA::debug('Maintenance Distributed Engine Completed', PEAR_LOG_INFO);
}
示例14: init
/**
* initialisation
*
* load the 'requestset' config file
* do not load the dataset yet - allow child scenario to choose
*
* @param string $filename - name of scenario's dataset and config
* @param string $dbname database name
*/
function init($filename)
{
$GLOBALS['_MAX']['CONF']['table']['prefix'] = '';
// assign the inputs
$this->requestFile = SCENARIOS_REQUESTSETS . $filename . '.php';
// load the request data
$this->loadRequestset();
// tweak some conf vals
$GLOBALS['_MAX']['COOKIE']['newViewerId'] = '';
$_COOKIE = $HTTP_COOKIE_VARS = array();
// get service locator instance
$this->oServiceLocator =& OA_ServiceLocator::instance();
// start with a clean set of tables
OA_DB_Table_Core::destroy();
$this->oCoreTables =& OA_DB_Table_Core::singleton();
// get the database handler
$this->oDbh =& OA_DB::singleton();
// fake the date/time
$this->setDateTime();
}
示例15: insertDefaultData
/**
* A method to insert the default data into the database.
*
* The default data are:
*
* - Test Advertiser 1
* - Placement 11
* - High Priority
* - Daily target of 120 impressions (5 per
* hour assuming even delivery each hour)
* - Advertisement 111
* - Banner Weight 1
* - Placement 12
* - High Priority
* - Runs from 2005-01-01 to 2005-12-31
* - Total target of 87,600 (10 per hour
* assuming even delivery each hour)
* - Advertisement 121
* - Banner Weight 2
* - Advertisement 122
* - Banner Weight 1
*
* - Test Advertiser 2
* - Placement 21
* - Placement 22
*
* - Test Publisher 1
* - Zone 11
* - Zone 12
*
* - Test Publisher 2
* - Zone 21
* - Zone 22
*
* - Advertisement 111 is linked to Zone 11
* - Advertisement 121 is linked to Zone 21
* - Advertisement 122 is linked to Zone 21 AND Zone 22
*
* @static
* @access public
* @TODO Complete the specification of the default data and the implementation
* of the creation thereof.
*/
function insertDefaultData()
{
$oDbh =& OA_DB::singleton();
// Set now
$oServiceLocator =& OA_ServiceLocator::instance();
$oldNow = $oServiceLocator->get('now');
$oServiceLocator->register('now', new Date('2005-03-01'));
// Add a default agency
$agencyID = Admin_DA::addAgency(array('name' => 'Test Agency', 'contact' => 'Contact Name', 'username' => 'agency', 'email' => 'agency@example.com', 'active' => 1));
// Add two advertisers for the agency
$advertiserOneID = Admin_DA::addAdvertiser(array('agencyid' => $agencyID, 'clientname' => 'Test Advertiser 1', 'contact' => 'Contact Name 1', 'clientusername' => 'advertiser1', 'email' => 'advertiser1@example.com'));
$advertiserTwoID = Admin_DA::addAdvertiser(array('agencyid' => $agencyID, 'clientname' => 'Test Advertiser 2', 'contact' => 'Contact Name 2', 'clientusername' => 'advertiser2', 'email' => 'advertiser2@example.com'));
// Add the advertiser's placements (campaigns) & advertisements
$campaignOneOneID = Admin_DA::addPlacement(array('campaignname' => 'Campaign 11 - Manual Daily Target of 120', 'clientid' => $advertiserOneID, 'views' => -1, 'clicks' => -1, 'conversions' => -1, 'status' => OA_ENTITY_STATUS_RUNNING, 'priority' => 2, 'target_impression' => 120, 'target_click' => -1, 'target_conversion' => -1));
$adOneOneOneID = Admin_DA::addAd(array('campaignid' => $campaignOneOneID, 'description' => 'Advertisement 111', 'active' => 't', 'weight' => 1, 'htmltemplate' => '', 'url' => '', 'bannertext' => '', 'compiledlimitation' => '', 'append' => ''));
$campaignOneTwoID = Admin_DA::addPlacement(array('campaignname' => 'Campaign 22 - Auto Distribution of 87,600 Impressions', 'clientid' => $advertiserOneID, 'views' => 87600, 'clicks' => -1, 'conversions' => -1, 'status' => OA_ENTITY_STATUS_RUNNING, 'priority' => 2, 'target_impression' => -1, 'target_click' => -1, 'target_conversion' => -1, 'activate_time' => '2005-01-01 00:00:00', 'expire_time' => '2005-12-31 23:59:59'));
$adOneTwoOneID = Admin_DA::addAd(array('campaignid' => $campaignOneTwoID, 'description' => 'Advertisement 121', 'active' => 't', 'weight' => 2, 'htmltemplate' => '', 'url' => '', 'bannertext' => '', 'compiledlimitation' => '', 'append' => ''));
$adOneTwoTwoID = Admin_DA::addAd(array('campaignid' => $campaignOneTwoID, 'description' => 'Advertisement 122', 'active' => 't', 'weight' => 1, 'htmltemplate' => '', 'url' => '', 'bannertext' => '', 'compiledlimitation' => '', 'append' => ''));
// Add two publishers for the agency
$publisherOneID = Admin_DA::addPublisher(array('agencyid' => $agencyID, 'name' => 'Test Publisher 1', 'contact' => 'Contact Name 1', 'username' => 'publisher1', 'email' => 'publisher1@example.com'));
$publisherTwoID = Admin_DA::addPublisher(array('agencyid' => $agencyID, 'name' => 'Test Publisher 1', 'contact' => 'Contact Name 1', 'username' => 'publisher1', 'email' => 'publisher1@example.com'));
// Add the publisher's zones
$zoneOneOneID = Admin_DA::addZone(array('affiliateid' => $publisherOneID, 'zonename' => 'Zone 11', 'type' => 0, 'category' => '', 'ad_selection' => '', 'chain' => '', 'prepend' => '', 'append' => '', 'what' => ''));
$zoneOneTwoID = Admin_DA::addZone(array('affiliateid' => $publisherOneID, 'zonename' => 'Zone 12', 'type' => 0, 'category' => '', 'ad_selection' => '', 'chain' => '', 'prepend' => '', 'append' => '', 'what' => ''));
$zoneTwoOneID = Admin_DA::addZone(array('affiliateid' => $publisherOneID, 'zonename' => 'Zone 21', 'type' => 0, 'category' => '', 'ad_selection' => '', 'chain' => '', 'prepend' => '', 'append' => '', 'what' => ''));
$zoneTwoTwoID = Admin_DA::addZone(array('affiliateid' => $publisherOneID, 'zonename' => 'Zone 22', 'type' => 0, 'category' => '', 'ad_selection' => '', 'chain' => '', 'prepend' => '', 'append' => '', 'what' => ''));
// Link the ads to the zones
Admin_DA::addAdZone(array('ad_id' => $adOneOneOneID, 'zone_id' => $zoneOneOneID, 'link_type' => 1));
Admin_DA::addAdZone(array('ad_id' => $adOneTwoOneID, 'zone_id' => $zoneTwoOneID, 'link_type' => 1));
Admin_DA::addAdZone(array('ad_id' => $adOneTwoTwoID, 'zone_id' => $zoneTwoOneID, 'link_type' => 1));
Admin_DA::addAdZone(array('ad_id' => $adOneTwoTwoID, 'zone_id' => $zoneTwoTwoID, 'link_type' => 1));
// Restore "now"
if ($oldNow) {
$oServiceLocator->register('now', $oldNow);
} else {
$oServiceLocator->remove('now');
}
}