本文整理汇总了PHP中Piwik\Container\StaticContainer类的典型用法代码示例。如果您正苦于以下问题:PHP StaticContainer类的具体用法?PHP StaticContainer怎么用?PHP StaticContainer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StaticContainer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
// Replace this with dependency injection once available
/** @var DiagnosticService $diagnosticService */
$diagnosticService = StaticContainer::get('Piwik\\Plugins\\Diagnostics\\DiagnosticService');
$showAll = $input->getOption('all');
$report = $diagnosticService->runDiagnostics();
foreach ($report->getAllResults() as $result) {
$items = $result->getItems();
if (!$showAll && $result->getStatus() === DiagnosticResult::STATUS_OK) {
continue;
}
if (count($items) === 1) {
$output->writeln($result->getLabel() . ': ' . $this->formatItem($items[0]), OutputInterface::OUTPUT_PLAIN);
continue;
}
$output->writeln($result->getLabel() . ':');
foreach ($items as $item) {
$output->writeln("\t- " . $this->formatItem($item), OutputInterface::OUTPUT_PLAIN);
}
}
if ($report->hasWarnings()) {
$output->writeln(sprintf('<comment>%d warnings detected</comment>', $report->getWarningCount()));
}
if ($report->hasErrors()) {
$output->writeln(sprintf('<error>%d errors detected</error>', $report->getErrorCount()));
return 1;
}
return 0;
}
示例2: configureSegments
protected function configureSegments()
{
$idSite = Common::getRequestVar('idSite', 0, 'int');
if (empty($idSite)) {
return array();
}
$configuration = StaticContainer::get('Piwik\\Plugins\\CustomDimensions\\Dao\\Configuration');
$dimensions = $configuration->getCustomDimensionsForSite($idSite);
foreach ($dimensions as $dimension) {
if (!$dimension['active']) {
continue;
}
$segment = new Segment();
$segment->setSegment(CustomDimensionsRequestProcessor::buildCustomDimensionTrackingApiName($dimension));
$segment->setType(Segment::TYPE_DIMENSION);
$segment->setName($dimension['name']);
$columnName = LogTable::buildCustomDimensionColumnName($dimension);
if ($dimension['scope'] === CustomDimensions::SCOPE_ACTION) {
$segment->setSqlSegment('log_link_visit_action. ' . $columnName);
$segment->setCategory('General_Actions');
$segment->setSuggestedValuesCallback(function ($idSite, $maxValuesToReturn) use($dimension) {
$autoSuggest = new AutoSuggest();
return $autoSuggest->getMostUsedActionDimensionValues($dimension, $idSite, $maxValuesToReturn);
});
} elseif ($dimension['scope'] === CustomDimensions::SCOPE_VISIT) {
$segment->setSqlSegment('log_visit. ' . $columnName);
$segment->setCategory('General_Visit');
} else {
continue;
}
$this->addSegment($segment);
}
}
示例3: __construct
/**
* Constructor.
*
* @param string|null $serverHostName The hostname of the LDAP server. If not null, an attempt
* to connect is made.
* @param int $port The server port to use.
* @throws Exception if a connection is attempted and it fails.
*/
public function __construct($serverHostName = null, $port = ServerInfo::DEFAULT_LDAP_PORT, $timeout = self::DEFAULT_TIMEOUT_SECS, LoggerInterface $logger = null)
{
$this->logger = $logger ?: StaticContainer::get('Psr\\Log\\LoggerInterface');
if (!empty($serverHostName)) {
$this->connect($serverHostName, $port, $timeout);
}
}
示例4: setUp
public function setUp()
{
parent::setUp();
/** @var PluginManager $manager */
$manager = StaticContainer::get('Piwik\\Plugin\\Manager');
$manager->loadPlugins(array('Events', 'Contents'));
}
示例5: __construct
/**
* Constructor.
*
* @param string $name The persisted name of the setting.
* @param mixed $defaultValue Default value for this setting if no value was specified.
* @param string $type Eg an array, int, ... see TYPE_* constants
* @param string $pluginName The name of the plugin the setting belongs to
* @param int $idSite The idSite this setting belongs to.
*/
public function __construct($name, $defaultValue, $type, $pluginName, $idSite)
{
parent::__construct($name, $defaultValue, $type, $pluginName);
$this->idSite = $idSite;
$storageFactory = StaticContainer::get('Piwik\\Settings\\Storage\\Factory');
$this->storage = $storageFactory->getMeasurableSettingsStorage($idSite, $this->pluginName);
}
示例6: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$path = StaticContainer::get('path.tmp') . '/logs/';
$cmd = sprintf('tail -f %s*.log', $path);
$output->writeln('Executing command: ' . $cmd);
passthru($cmd);
}
示例7: hasKey
public function hasKey($key)
{
if ($key === 'auth') {
$key = 'Piwik\\Auth';
}
return StaticContainer::getContainer()->has($key);
}
示例8: init
function init()
{
HTML_QuickForm2_Factory::registerRule('checkLogin', 'Piwik\\Plugins\\Installation\\Rule_isValidLoginString');
HTML_QuickForm2_Factory::registerRule('checkEmail', 'Piwik\\Plugins\\Installation\\Rule_isValidEmailString');
$login = $this->addElement('text', 'login')->setLabel(Piwik::translate('Installation_SuperUserLogin'));
$login->addRule('required', Piwik::translate('General_Required', Piwik::translate('Installation_SuperUserLogin')));
$login->addRule('checkLogin');
$password = $this->addElement('password', 'password')->setLabel(Piwik::translate('Installation_Password'));
$password->addRule('required', Piwik::translate('General_Required', Piwik::translate('Installation_Password')));
$pwMinLen = UsersManager::PASSWORD_MIN_LENGTH;
$pwLenInvalidMessage = Piwik::translate('UsersManager_ExceptionInvalidPassword', array($pwMinLen));
$password->addRule('length', $pwLenInvalidMessage, array('min' => $pwMinLen));
$passwordBis = $this->addElement('password', 'password_bis')->setLabel(Piwik::translate('Installation_PasswordRepeat'));
$passwordBis->addRule('required', Piwik::translate('General_Required', Piwik::translate('Installation_PasswordRepeat')));
$passwordBis->addRule('eq', Piwik::translate('Installation_PasswordDoNotMatch'), $password);
$email = $this->addElement('text', 'email')->setLabel(Piwik::translate('Installation_Email'));
$email->addRule('required', Piwik::translate('General_Required', Piwik::translate('Installation_Email')));
$email->addRule('checkEmail', Piwik::translate('UsersManager_ExceptionInvalidEmail'));
$this->addElement('checkbox', 'subscribe_newsletter_piwikorg', null, array('content' => ' ' . Piwik::translate('Installation_PiwikOrgNewsletter')));
$professionalServicesNewsletter = Piwik::translate('Installation_ProfessionalServicesNewsletter', array("<a href='http://piwik.org/consulting/?pk_medium=App_Newsletter_link&pk_source=Piwik_App&pk_campaign=App_Installation' style='color:#444;' rel='noreferrer' target='_blank'>", "</a>"));
$currentLanguage = StaticContainer::get('Piwik\\Translation\\Translator')->getCurrentLanguage();
$this->addElement('checkbox', 'subscribe_newsletter_professionalservices', null, array('content' => ' ' . $professionalServicesNewsletter));
$this->addElement('submit', 'submit', array('value' => Piwik::translate('General_Next') . ' »', 'class' => 'btn'));
// default values
$this->addDataSource(new HTML_QuickForm2_DataSource_Array(array('subscribe_newsletter_piwikorg' => 1, 'subscribe_newsletter_professionalservices' => $currentLanguage == 'de' ? 0 : 1)));
}
示例9: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$invalidator = StaticContainer::get('Piwik\\Archive\\ArchiveInvalidator');
$cascade = $input->getOption('cascade');
$dryRun = $input->getOption('dry-run');
$sites = $this->getSitesToInvalidateFor($input);
$periodTypes = $this->getPeriodTypesToInvalidateFor($input);
$dateRanges = $this->getDateRangesToInvalidateFor($input);
$segments = $this->getSegmentsToInvalidateFor($input, $sites);
foreach ($periodTypes as $periodType) {
foreach ($dateRanges as $dateRange) {
foreach ($segments as $segment) {
$segmentStr = $segment ? $segment->getString() : '';
$output->writeln("Invalidating {$periodType} periods in {$dateRange} [segment = {$segmentStr}]...");
$dates = $this->getPeriodDates($periodType, $dateRange);
if ($dryRun) {
$output->writeln("[Dry-run] invalidating archives for site = [ " . implode(', ', $sites) . " ], dates = [ " . implode(', ', $dates) . " ], period = [ {$periodType} ], segment = [ " . "{$segmentStr} ], cascade = [ " . (int) $cascade . " ]");
} else {
$invalidationResult = $invalidator->markArchivesAsInvalidated($sites, $dates, $periodType, $segment, $cascade);
if ($output->getVerbosity() > OutputInterface::VERBOSITY_NORMAL) {
$output->writeln($invalidationResult->makeOutputLogs());
}
}
}
}
}
}
示例10: configure
public static function configure(WidgetConfig $config)
{
$config->setCategoryId('About Piwik');
$config->setName('ProfessionalServices_WidgetProfessionalServicesForPiwik');
$advertising = StaticContainer::get('Piwik\\ProfessionalServices\\Advertising');
$config->setIsEnabled($advertising->areAdsForProfessionalServicesEnabled());
}
示例11: initAuthenticationObject
public function initAuthenticationObject($activateCookieAuth = false)
{
$auth = new Auth();
StaticContainer::getContainer()->set('Piwik\\Auth', $auth);
$login = new Login();
return $login->initAuthenticationFromCookie($auth, $activateCookieAuth);
}
示例12: tableInsertBatch
/**
* Performs a batch insert into a specific table using either LOAD DATA INFILE or plain INSERTs,
* as a fallback. On MySQL, LOAD DATA INFILE is 20x faster than a series of plain INSERTs.
*
* @param string $tableName PREFIXED table name! you must call Common::prefixTable() before passing the table name
* @param array $fields array of unquoted field names
* @param array $values array of data to be inserted
* @param bool $throwException Whether to throw an exception that was caught while trying
* LOAD DATA INFILE, or not.
* @throws Exception
* @return bool True if the bulk LOAD was used, false if we fallback to plain INSERTs
*/
public static function tableInsertBatch($tableName, $fields, $values, $throwException = false)
{
$filePath = StaticContainer::get('path.tmp') . '/assets/' . $tableName . '-' . Common::generateUniqId() . '.csv';
$loadDataInfileEnabled = Config::getInstance()->General['enable_load_data_infile'];
if ($loadDataInfileEnabled && Db::get()->hasBulkLoader()) {
try {
$fileSpec = array('delim' => "\t", 'quote' => '"', 'escape' => '\\\\', 'escapespecial_cb' => function ($str) {
return str_replace(array(chr(92), chr(34)), array(chr(92) . chr(92), chr(92) . chr(34)), $str);
}, 'eol' => "\r\n", 'null' => 'NULL');
// hack for charset mismatch
if (!DbHelper::isDatabaseConnectionUTF8() && !isset(Config::getInstance()->database['charset'])) {
$fileSpec['charset'] = 'latin1';
}
self::createCSVFile($filePath, $fileSpec, $values);
if (!is_readable($filePath)) {
throw new Exception("File {$filePath} could not be read.");
}
$rc = self::createTableFromCSVFile($tableName, $fields, $filePath, $fileSpec);
if ($rc) {
unlink($filePath);
return true;
}
} catch (Exception $e) {
if ($throwException) {
throw $e;
}
}
}
// if all else fails, fallback to a series of INSERTs
@unlink($filePath);
self::tableInsertBatchIterate($tableName, $fields, $values);
return false;
}
示例13: __construct
public function __construct()
{
$this->requestProcessors = StaticContainer::get('tracker.request.processors');
$this->visitorRecognizer = StaticContainer::get('Piwik\\Tracker\\VisitorRecognizer');
$this->visitProperties = null;
$this->userSettings = StaticContainer::get('Piwik\\Tracker\\Settings');
}
示例14: test_removeFile_shouldRemoveFile
public function test_removeFile_shouldRemoveFile()
{
$tmpFile = StaticContainer::get('path.tmp') . '/filesystem-test-file';
touch($tmpFile);
Filesystem::remove($tmpFile);
$this->assertFileNotExists($tmpFile);
}
示例15: triggerWebtreesAdminTasks
public function triggerWebtreesAdminTasks()
{
$settings = new Settings();
$this->logger = \Piwik\Container\StaticContainer::get('Psr\\Log\\LoggerInterface');
$this->logger->info('Webtrees Admin Task triggered');
$rooturl = $settings->getSetting('webtreesRootUrl');
if (!$rooturl || strlen($rooturl->getValue()) === 0) {
return;
}
$token = $settings->getSetting('webtreesToken');
if (!$token || strlen($token->getValue()) === 0) {
return;
}
$taskname = $settings->getSetting('webtreesTaskName');
if (!$taskname || strlen($taskname->getValue()) === 0) {
return;
}
$url = sprintf('%1$s/module.php?mod=perso_admintasks&mod_action=trigger&force=%2$s&task=%3$s', $rooturl->getValue(), $token->getValue(), $taskname->getValue());
$this->logger->info('webtrees url : {url}', array('url' => $url));
try {
\Piwik\Http::sendHttpRequest($url, Webtrees::SOCKET_TIMEOUT);
} catch (Exception $e) {
$this->logger->warning('an error occured', array('exception' => $e));
}
}