本文整理汇总了PHP中Piwik\Container\StaticContainer::getContainer方法的典型用法代码示例。如果您正苦于以下问题:PHP StaticContainer::getContainer方法的具体用法?PHP StaticContainer::getContainer怎么用?PHP StaticContainer::getContainer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Piwik\Container\StaticContainer
的用法示例。
在下文中一共展示了StaticContainer::getContainer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: hasKey
public function hasKey($key)
{
if ($key === 'auth') {
$key = 'Piwik\\Auth';
}
return StaticContainer::getContainer()->has($key);
}
示例2: initAuthenticationObject
public function initAuthenticationObject($activateCookieAuth = false)
{
$auth = new Auth();
StaticContainer::getContainer()->set('Piwik\\Auth', $auth);
$login = new Login();
return $login->initAuthenticationFromCookie($auth, $activateCookieAuth);
}
示例3: __construct
/**
* Constructor.
*
* @param string[] $options The string options applied to the generate:travis-yml command.
*/
public function __construct($options)
{
$this->options = $options;
if (class_exists('\\Piwik\\Container\\StaticContainer')) {
$this->logger = \Piwik\Container\StaticContainer::getContainer()->get('Psr\\Log\\LoggerInterface');
}
$this->view = new TravisYmlView();
}
示例4: test_WidgetIsRenderable_ToPreventBreakingTheAPI
/**
* @param array $widget
*
* @dataProvider availableWidgetsProvider
*/
public function test_WidgetIsRenderable_ToPreventBreakingTheAPI($widget)
{
$params = $widget['parameters'];
$parameters = array();
$resolver = new ControllerResolver(StaticContainer::getContainer());
$controller = $resolver->getController($params['module'], $params['action'], $parameters);
$this->assertNotEmpty($controller, $widget['name'] . ' is not renderable with following params: ' . json_encode($params) . '. This breaks the API, please make sure to keep the URL working');
}
示例5: getProviders
/**
* @return MetricsProvider[]
*/
private function getProviders()
{
$container = StaticContainer::getContainer();
$providers = array($container->get('Piwik\\Plugins\\SEO\\Metric\\Google'), $container->get('Piwik\\Plugins\\SEO\\Metric\\Bing'), $container->get('Piwik\\Plugins\\SEO\\Metric\\Alexa'), $container->get('Piwik\\Plugins\\SEO\\Metric\\DomainAge'), $container->get('Piwik\\Plugins\\SEO\\Metric\\Dmoz'));
/**
* Use this event to register new SEO metrics providers.
*
* @param array $providers Contains an array of Piwik\Plugins\SEO\Metric\MetricsProvider instances.
*/
Piwik::postEvent('SEO.getMetricsProviders', array(&$providers));
return $providers;
}
示例6: getInstance
/**
* You can create your own Users Plugin to override this class.
* Example of how you would overwrite the UsersManager_API with your own class:
* Call the following in your plugin __construct() for example:
*
* StaticContainer::getContainer()->set('UsersManager_API', \Piwik\Plugins\MyCustomUsersManager\API::getInstance());
*
* @throws Exception
* @return \Piwik\Plugins\UsersManager\API
*/
public static function getInstance()
{
try {
$instance = StaticContainer::get('UsersManager_API');
if (!$instance instanceof API) {
// Exception is caught below and corrected
throw new Exception('UsersManager_API must inherit API');
}
self::$instance = $instance;
} catch (Exception $e) {
self::$instance = StaticContainer::get('Piwik\\Plugins\\UsersManager\\API');
StaticContainer::getContainer()->set('UsersManager_API', self::$instance);
}
return self::$instance;
}
示例7: getInstance
/**
* Returns the singleton instance for the derived class. If the singleton instance
* has not been created, this method will create it.
*
* @return static
*/
public static function getInstance()
{
$class = get_called_class();
if (!isset(self::$instances[$class])) {
$container = StaticContainer::getContainer();
$refl = new \ReflectionClass($class);
if (!$refl->getConstructor() || $refl->getConstructor()->isPublic()) {
self::$instances[$class] = $container->get($class);
} else {
/** @var LoggerInterface $logger */
$logger = $container->get('Psr\\Log\\LoggerInterface');
// BC with API defining a protected constructor
$logger->notice('The API class {class} defines a protected constructor which is deprecated, make the constructor public instead', array('class' => $class));
self::$instances[$class] = new $class();
}
}
return self::$instances[$class];
}
示例8: getReportMetadata
/**
* @param array $reports
* @param array $info
* @return mixed
*/
public function getReportMetadata(&$reports, $info)
{
$idSites = $info['idSites'];
// If only one website is selected, we add the Graph URL
if (count($idSites) != 1) {
return;
}
$idSite = reset($idSites);
// in case API.getReportMetadata was not called with date/period we use sane defaults
if (empty($info['period'])) {
$info['period'] = 'day';
}
if (empty($info['date'])) {
$info['date'] = 'today';
}
// need two sets of period & date, one for single period graphs, one for multiple periods graphs
if (Period::isMultiplePeriod($info['date'], $info['period'])) {
$periodForMultiplePeriodGraph = $info['period'];
$dateForMultiplePeriodGraph = $info['date'];
$periodForSinglePeriodGraph = 'range';
$dateForSinglePeriodGraph = $info['date'];
} else {
$periodForSinglePeriodGraph = $info['period'];
$dateForSinglePeriodGraph = $info['date'];
$piwikSite = new Site($idSite);
if ($periodForSinglePeriodGraph == 'range') {
// for period=range, show the configured sub-periods
$periodForMultiplePeriodGraph = Config::getInstance()->General['graphs_default_period_to_plot_when_period_range'];
$dateForMultiplePeriodGraph = $dateForSinglePeriodGraph;
} else {
if ($info['period'] == 'day' || !Config::getInstance()->General['graphs_show_evolution_within_selected_period']) {
// for period=day, always show the last n days
// if graphs_show_evolution_within_selected_period=false, show the last n periods
$periodForMultiplePeriodGraph = $periodForSinglePeriodGraph;
$dateForMultiplePeriodGraph = Range::getRelativeToEndDate($periodForSinglePeriodGraph, 'last' . self::GRAPH_EVOLUTION_LAST_PERIODS, $dateForSinglePeriodGraph, $piwikSite);
} else {
// if graphs_show_evolution_within_selected_period=true, show the days within the period
// (except if the period is day, see above)
$periodForMultiplePeriodGraph = 'day';
$period = PeriodFactory::build($info['period'], $info['date']);
$start = $period->getDateStart()->toString();
$end = $period->getDateEnd()->toString();
$dateForMultiplePeriodGraph = $start . ',' . $end;
}
}
}
$token_auth = Common::getRequestVar('token_auth', false);
$segment = Request::getRawSegmentFromRequest();
/** @var Scheduler $scheduler */
$scheduler = StaticContainer::getContainer()->get('Piwik\\Scheduler\\Scheduler');
$isRunningTask = $scheduler->isRunningTask();
// add the idSubtable if it exists
$idSubtable = Common::getRequestVar('idSubtable', false);
$urlPrefix = "index.php?";
foreach ($reports as &$report) {
$reportModule = $report['module'];
$reportAction = $report['action'];
$reportUniqueId = $reportModule . '_' . $reportAction;
$parameters = array();
$parameters['module'] = 'API';
$parameters['method'] = 'ImageGraph.get';
$parameters['idSite'] = $idSite;
$parameters['apiModule'] = $reportModule;
$parameters['apiAction'] = $reportAction;
if (!empty($token_auth)) {
$parameters['token_auth'] = $token_auth;
}
// Forward custom Report parameters to the graph URL
if (!empty($report['parameters'])) {
$parameters = array_merge($parameters, $report['parameters']);
}
if (empty($report['dimension'])) {
$parameters['period'] = $periodForMultiplePeriodGraph;
$parameters['date'] = $dateForMultiplePeriodGraph;
} else {
$parameters['period'] = $periodForSinglePeriodGraph;
$parameters['date'] = $dateForSinglePeriodGraph;
}
if ($idSubtable !== false) {
$parameters['idSubtable'] = $idSubtable;
}
if (!empty($_GET['_restrictSitesToLogin']) && $isRunningTask) {
$parameters['_restrictSitesToLogin'] = $_GET['_restrictSitesToLogin'];
}
if (!empty($segment)) {
$parameters['segment'] = $segment;
}
$report['imageGraphUrl'] = $urlPrefix . Url::getQueryStringFromParameters($parameters);
// thanks to API.getRowEvolution, reports with dimensions can now be plotted using an evolution graph
// however, most reports with a fixed set of dimension values are excluded
// this is done so Piwik Mobile and Scheduled Reports do not display them
$reportWithDimensionsSupportsEvolution = empty($report['constantRowsCount']) || in_array($reportUniqueId, self::$CONSTANT_ROW_COUNT_REPORT_EXCEPTIONS);
$reportSupportsEvolution = !in_array($reportUniqueId, self::$REPORTS_DISABLED_EVOLUTION_GRAPH);
if ($reportSupportsEvolution && $reportWithDimensionsSupportsEvolution) {
$parameters['period'] = $periodForMultiplePeriodGraph;
//.........这里部分代码省略.........
示例9: getDeleteDataInfo
protected function getDeleteDataInfo()
{
Piwik::checkUserHasSuperUserAccess();
$deleteDataInfos = array();
$deleteDataInfos["config"] = PrivacyManager::getPurgeDataSettings();
$deleteDataInfos["deleteTables"] = "<br/>" . implode(", ", LogDataPurger::getDeleteTableLogTables());
/** @var Scheduler $scheduler */
$scheduler = StaticContainer::getContainer()->get('Piwik\\Scheduler\\Scheduler');
$scheduleTimetable = $scheduler->getScheduledTimeForMethod("PrivacyManager", "deleteLogTables");
$optionTable = Option::get(self::OPTION_LAST_DELETE_PIWIK_LOGS);
//If task was already rescheduled, read time from taskTimetable. Else, calculate next possible runtime.
if (!empty($scheduleTimetable) && $scheduleTimetable - time() > 0) {
$nextPossibleSchedule = (int) $scheduleTimetable;
} else {
$date = Date::factory("today");
$nextPossibleSchedule = $date->addDay(1)->getTimestamp();
}
//deletion schedule did not run before
if (empty($optionTable)) {
$deleteDataInfos["lastRun"] = false;
//next run ASAP (with next schedule run)
$date = Date::factory("today");
$deleteDataInfos["nextScheduleTime"] = $nextPossibleSchedule;
} else {
$deleteDataInfos["lastRun"] = $optionTable;
$deleteDataInfos["lastRunPretty"] = Date::factory((int) $optionTable)->getLocalized(Date::DATE_FORMAT_SHORT);
//Calculate next run based on last run + interval
$nextScheduleRun = (int) ($deleteDataInfos["lastRun"] + $deleteDataInfos["config"]["delete_logs_schedule_lowest_interval"] * 24 * 60 * 60);
//is the calculated next run in the past? (e.g. plugin was disabled in the meantime or something) -> run ASAP
if ($nextScheduleRun - time() <= 0) {
$deleteDataInfos["nextScheduleTime"] = $nextPossibleSchedule;
} else {
$deleteDataInfos["nextScheduleTime"] = $nextScheduleRun;
}
}
$formatter = new Formatter();
$deleteDataInfos["nextRunPretty"] = $formatter->getPrettyTimeFromSeconds($deleteDataInfos["nextScheduleTime"] - time());
return $deleteDataInfos;
}
示例10: initAuthenticationObject
/**
* Initializes the authentication object.
* Listens to Request.initAuthenticationObject hook.
*/
function initAuthenticationObject($activateCookieAuth = false)
{
$this->initAuthenticationFromCookie(StaticContainer::getContainer()->get('Piwik\\Auth'), $activateCookieAuth);
}
示例11: getInstance
/**
* @return Scheduler
*/
private static function getInstance()
{
return StaticContainer::getContainer()->get('Piwik\\Scheduler\\Scheduler');
}
示例12: getSitesIdWithAtLeastViewAccess
/**
* Returns the list of websites ID with the 'view' or 'admin' access for the current user.
* For the superUser it returns all the websites in the database.
*
* @param bool $_restrictSitesToLogin
* @return array list of websites ID
*/
public function getSitesIdWithAtLeastViewAccess($_restrictSitesToLogin = false)
{
/** @var Scheduler $scheduler */
$scheduler = StaticContainer::getContainer()->get('Piwik\\Scheduler\\Scheduler');
if (Piwik::hasUserSuperUserAccess() && !$scheduler->isRunningTask()) {
return Access::getInstance()->getSitesIdWithAtLeastViewAccess();
}
if (!empty($_restrictSitesToLogin) && (Piwik::hasUserSuperUserAccessOrIsTheUser($_restrictSitesToLogin) || $scheduler->isRunningTask())) {
if (Piwik::hasTheUserSuperUserAccess($_restrictSitesToLogin)) {
return Access::getInstance()->getSitesIdWithAtLeastViewAccess();
}
$accessRaw = Access::getInstance()->getRawSitesWithSomeViewAccess($_restrictSitesToLogin);
$sitesId = array();
foreach ($accessRaw as $access) {
$sitesId[] = $access['idsite'];
}
return $sitesId;
} else {
return Access::getInstance()->getSitesIdWithAtLeastViewAccess();
}
}
示例13: initAuthenticationObject
/**
* Initializes the authentication object.
* Listens to Request.initAuthenticationObject hook.
*/
function initAuthenticationObject($activateCookieAuth = false)
{
$auth = new Auth();
StaticContainer::getContainer()->set('Piwik\\Auth', $auth);
$this->initAuthenticationFromCookie($auth, $activateCookieAuth);
}
示例14: getMeasurableSettings
/**
* @api
*
* Get measurable settings for a specific plugin.
*
* @param string $pluginName The name of a plugin.
* @param int $idSite The ID of a site. If a site is about to be created pass idSite = 0.
* @param string|null $idType If null, idType will be detected automatically if the site already exists. Only
* needed to set a value when idSite = 0 (this is the case when a site is about)
* to be created.
*
* @return MeasurableSettings|null Returns null if no MeasurableSettings implemented by this plugin or when plugin
* is not loaded and activated. Returns an instance of the settings otherwise.
*/
public function getMeasurableSettings($pluginName, $idSite, $idType = null)
{
$plugin = $this->getLoadedAndActivated($pluginName);
if ($plugin) {
$component = $plugin->findComponent('MeasurableSettings', 'Piwik\\Settings\\Measurable\\MeasurableSettings');
if ($component) {
return StaticContainer::getContainer()->make($component, array('idSite' => $idSite, 'idMeasurableType' => $idType));
}
}
}
示例15: initAuthenticationObject
/**
* Initializes the authentication object.
* Listens to Request.initAuthenticationObject hook.
*/
function initAuthenticationObject($activateCookieAuth = false)
{
$auth = AuthBase::factory();
StaticContainer::getContainer()->set('Piwik\\Auth', $auth);
Login::initAuthenticationFromCookie($auth, $activateCookieAuth);
}