本文整理汇总了PHP中CM_Service_Manager类的典型用法代码示例。如果您正苦于以下问题:PHP CM_Service_Manager类的具体用法?PHP CM_Service_Manager怎么用?PHP CM_Service_Manager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CM_Service_Manager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _getServiceManager
/**
* @param string $codeGoogleAnalytics
* @param string $codeKissMetrics
* @return CM_Service_Manager
*/
protected function _getServiceManager($codeGoogleAnalytics, $codeKissMetrics)
{
$serviceManager = new CM_Service_Manager();
$serviceManager->registerInstance('googleanalytics', new CMService_GoogleAnalytics_Client($codeGoogleAnalytics));
$serviceManager->registerInstance('kissmetrics', new CMService_KissMetrics_Client($codeKissMetrics));
$serviceManager->registerInstance('trackings', new CM_Service_Trackings(['googleanalytics', 'kissmetrics']));
return $serviceManager;
}
示例2: testServiceInstantiation
public function testServiceInstantiation()
{
$serviceManager = new CM_Service_Manager();
$serviceManager->registerWithArray('stream-message', ['class' => 'CM_MessageStream_Factory', 'method' => ['name' => 'createService', 'arguments' => ['adapterClass' => 'CM_MessageStream_Adapter_SocketRedis', 'adapterArguments' => ['servers' => [['httpHost' => 'localhost', 'httpPort' => 8085, 'sockjsUrls' => ['http://localhost:8090']]]]]]]);
$stream = $serviceManager->get('stream-message');
$this->assertSame(true, $stream instanceof CM_MessageStream_Service);
$adapter = $stream->getAdapter();
$this->assertSame(true, $adapter instanceof CM_MessageStream_Adapter_SocketRedis);
/** @var CM_MessageStream_Adapter_SocketRedis $adapter */
$this->assertSame($serviceManager, $adapter->getServiceManager());
}
示例3: setUp
protected function setUp()
{
$serviceManager = new CM_Service_Manager();
$this->_filesystemDefault = new CM_File_Filesystem(new CM_File_Filesystem_Adapter_Local());
$this->_filesystemFoo = new CM_File_Filesystem(new CM_File_Filesystem_Adapter_Local());
$serviceManager->registerInstance('filesystem-usercontent-default', $this->_filesystemDefault);
$serviceManager->registerInstance('filesystem-usercontent-foo', $this->_filesystemFoo);
$config = array('default' => array('url' => 'http://example.com/default', 'filesystem' => 'filesystem-usercontent-default'), 'foo' => array('url' => 'http://example.com/foo', 'filesystem' => 'filesystem-usercontent-foo'));
$this->_service = new CM_Service_UserContent($config);
$this->_service->setServiceManager($serviceManager);
}
示例4: testGetUrl
public function testGetUrl()
{
$serviceManager = new CM_Service_Manager();
$filesystemDefault = new CM_File_Filesystem(new CM_File_Filesystem_Adapter_Local());
$filesystemFoo = new CM_File_Filesystem(new CM_File_Filesystem_Adapter_Local());
$serviceManager->registerInstance('filesystem-usercontent-default', $filesystemDefault);
$serviceManager->registerInstance('filesystem-usercontent-foo', $filesystemFoo);
$serviceConfig = array('default' => array('url' => 'http://example.com/default', 'filesystem' => 'filesystem-usercontent-default'), 'foo' => array('url' => 'http://example.com/foo', 'filesystem' => 'filesystem-usercontent-foo'));
$serviceManager->registerInstance('usercontent', new CM_Service_UserContent($serviceConfig));
$userFile = new CM_File_UserContent('foo', 'my.jpg', null, $serviceManager);
$this->assertSame('http://example.com/foo/foo/my.jpg', $userFile->getUrl());
$userFile = new CM_File_UserContent('bar', 'my.jpg', null, $serviceManager);
$this->assertSame('http://example.com/default/bar/my.jpg', $userFile->getUrl());
}
示例5: execute
/**
* @param array|null $parameters
* @param bool|null $disableQueryBuffering
* @throws CM_Db_Exception
* @return CM_Db_Result
*/
public function execute(array $parameters = null, $disableQueryBuffering = null)
{
$disableQueryBuffering = (bool) $disableQueryBuffering;
$retryCount = 1;
for ($try = 0; true; $try++) {
try {
if ($disableQueryBuffering) {
$this->_client->setBuffered(false);
}
@$this->_pdoStatement->execute($parameters);
if ($disableQueryBuffering) {
$this->_client->setBuffered(true);
}
CM_Service_Manager::getInstance()->getDebug()->incStats('mysql', $this->getQueryString());
return new CM_Db_Result($this->_pdoStatement);
} catch (PDOException $e) {
if ($try < $retryCount && $this->_client->isConnectionLossError($e)) {
$this->_client->disconnect();
$this->_client->connect();
$this->_reCreatePdoStatement();
continue;
}
throw new CM_Db_Exception('Cannot execute SQL statement', null, ['tries' => $try, 'originalExceptionMessage' => $e->getMessage(), 'query' => $this->_pdoStatement->queryString]);
}
}
throw new CM_Db_Exception('Line should never be reached');
}
示例6: testWithoutWhere
public function testWithoutWhere()
{
$client = CM_Service_Manager::getInstance()->getDatabases()->getMaster();
$query = new CM_Db_Query_UpdateSequence($client, 't`est', 's`ort', -1, null, 4, 9);
$this->assertSame('UPDATE `t``est` SET `s``ort` = `s``ort` + ? WHERE `s``ort` BETWEEN ? AND ?', $query->getSqlTemplate());
$this->assertEquals(array(-1, 4, 9), $query->getParameters());
}
示例7: testGetSetRuntime
public function testGetSetRuntime()
{
$defaultTimeZoneBackup = date_default_timezone_get();
$interval = '1 day';
$timezone = new DateTimeZone('Europe/Berlin');
$event1 = new CM_Clockwork_Event('foo', $interval);
$event2 = new CM_Clockwork_Event('bar', $interval);
$date1 = new DateTime('2014-10-31 08:00:00', $timezone);
$date2 = new DateTime('2014-10-31 08:02:03', $timezone);
$context = 'persistence-test';
$storage = new CM_Clockwork_Storage_FileSystem($context);
$serviceManager = CM_Service_Manager::getInstance();
$storage->setServiceManager($serviceManager);
$filepath = 'clockwork/' . md5($context) . '.json';
$file = new CM_File($filepath, $serviceManager->getFilesystems()->getData());
$this->assertFalse($file->exists());
$this->assertFalse($file->getParentDirectory()->exists());
$storage->setRuntime($event1, $date1);
$this->assertTrue($file->getParentDirectory()->exists());
$this->assertTrue($file->exists());
$storage->setRuntime($event2, $date2);
date_default_timezone_set('Antarctica/Vostok');
$storage = new CM_Clockwork_Storage_FileSystem($context);
$storage->setServiceManager($serviceManager);
$this->assertEquals($date1, $storage->getLastRuntime($event1));
$this->assertEquals($date2, $storage->getLastRuntime($event2));
date_default_timezone_set($defaultTimeZoneBackup);
}
示例8: testImportVideoThumbnail
public function testImportVideoThumbnail()
{
$testFile1 = CM_File::create('test1.png', 'foo1', CM_Service_Manager::getInstance()->getFilesystems()->getTmp());
$testFile2 = CM_File::create('test2.png', 'foo2', CM_Service_Manager::getInstance()->getFilesystems()->getTmp());
$cli = new CM_MediaStreams_Cli();
// streamchannel exists
/** @var CM_Model_StreamChannel_Media $streamChannel */
$streamChannel = CMTest_TH::createStreamChannel(null, null, 'foobar');
$this->assertCount(0, $streamChannel->getThumbnails());
$cli->importVideoThumbnail('foobar', $testFile1, 1234);
$this->assertCount(1, $streamChannel->getThumbnails());
/** @var CM_StreamChannel_Thumbnail $thumbnail */
$thumbnail = $streamChannel->getThumbnails()->getItem(0);
$this->assertSame(1234, $thumbnail->getCreateStamp());
$this->assertSame('foo1', $thumbnail->getFile()->read());
// archive exists
$archive = CM_Model_StreamChannelArchive_Media::createStatic(['streamChannel' => $streamChannel]);
$streamChannel->delete();
$cli->importVideoThumbnail('foobar', $testFile2, 1235);
$this->assertCount(2, $streamChannel->getThumbnails());
/** @var CM_StreamChannel_Thumbnail $thumbnail */
$thumbnail = $archive->getThumbnails()->getItem(1);
$this->assertSame(1235, $thumbnail->getCreateStamp());
$this->assertSame('foo2', $thumbnail->getFile()->read());
}
示例9: _getEmailVerification
/**
* @return CM_Service_EmailVerification_ClientInterface
*/
protected function _getEmailVerification()
{
if ($this->getParams()->getBoolean('disable-email-verification', false)) {
return new CM_Service_EmailVerification_Standard();
}
return CM_Service_Manager::getInstance()->get('email-verification', 'CM_Service_EmailVerification_ClientInterface');
}
示例10: __construct
/**
* @param string $name
* @param CM_Service_Manager $serviceManager
*/
public function __construct($name, CM_Service_Manager $serviceManager = null)
{
$this->_construct(array('name' => $name));
if (null === $serviceManager) {
$serviceManager = CM_Service_Manager::getInstance();
}
$this->setServiceManager($serviceManager);
}
示例11: testRunJobLimit
public function testRunJobLimit()
{
$serviceManager = new CM_Service_Manager();
$logger = $this->mockObject('CM_Log_Logger');
$serviceManager->registerInstance('logger', $logger);
if (!extension_loaded('gearman')) {
$this->markTestSkipped('Gearman Pecl Extension not installed.');
}
$gearmanWorker = $this->mockClass('GearmanWorker')->newInstanceWithoutConstructor();
$workMethod = $gearmanWorker->mockMethod('work')->set(true);
CM_Config::get()->CM_Jobdistribution_JobWorker->servers = [];
$worker = $this->mockClass(CM_Jobdistribution_JobWorker::class)->newInstance([5]);
$worker->mockMethod('_getGearmanWorker')->set($gearmanWorker);
/** @var CM_Jobdistribution_JobWorker $worker */
$worker->setServiceManager($serviceManager);
$worker->run();
$this->assertSame(5, $workMethod->getCallCount());
}
示例12: _deleteOlderThan
/**
* @param int $age
*/
protected function _deleteOlderThan($age)
{
$age = (int) $age;
$deleteOlderThan = time() - $age;
$criteria = $this->_getCriteria();
$criteria['createdAt'] = ['$lt' => new MongoDate($deleteOlderThan)];
$mongoDb = CM_Service_Manager::getInstance()->getMongoDb();
$mongoDb->remove(self::COLLECTION_NAME, $criteria, ['socketTimeoutMS' => 50000]);
$this->_change();
}
示例13: onUnsubscribe
public function onUnsubscribe(CM_Model_Stream_Subscribe $streamSubscribe)
{
if ($this->hasUser()) {
$user = $streamSubscribe->getUser();
if ($user && !$this->isSubscriber($user, $streamSubscribe)) {
$delayedJobQueue = CM_Service_Manager::getInstance()->getDelayedJobQueue();
$delayedJobQueue->addJob(new CM_User_OfflineJob(), ['user' => $user], CM_Model_User::OFFLINE_DELAY);
}
}
}
示例14: prepare
public function prepare(CM_Frontend_Environment $environment, CM_Frontend_ViewResponse $viewResponse)
{
$debug = CM_Service_Manager::getInstance()->getDebug();
$stats = $debug->getStats();
ksort($stats);
$viewResponse->set('stats', $stats);
$cacheNames = array('CM_Cache_Storage_Memcache', 'CM_Cache_Storage_Apc', 'CM_Cache_Storage_File');
$viewResponse->getJs()->setProperty('cacheNames', $cacheNames);
$viewResponse->set('cacheNames', $cacheNames);
}
示例15: _execute
protected function _execute(CM_Params $params)
{
$indexClassName = $params->getString('indexClassName');
$id = $params->getString('id');
$client = CM_Service_Manager::getInstance()->getElasticsearch()->getClient();
/** @var CM_Elasticsearch_Type_Abstract $index */
$index = new $indexClassName($client);
$index->updateDocuments(array($id));
$index->refreshIndex();
}