getPluginNameFromBacktrace() public static method

Extracts the plugin name from a backtrace array. Returns false if we can't find one.
public static getPluginNameFromBacktrace ( array $backtrace ) : string | false
$backtrace array The result of {@link debug_backtrace()} or [Exception::getTrace()](http://www.php.net/manual/en/exception.gettrace.php).
return string | false
 /**
  * Returns the name of the plugin/class that triggered the log.
  *
  * @return string
  */
 private function getLoggingClassName()
 {
     $backtrace = $this->getBacktrace();
     $name = Plugin::getPluginNameFromBacktrace($backtrace);
     // if we can't determine the plugin, use the name of the calling class
     if ($name == false) {
         $name = $this->getClassNameThatIsLogging($backtrace);
     }
     return $name;
 }
 private function getPluginsToLoadDuringTest()
 {
     $plugins = $this->vars->getCoreAndSupportedPlugins();
     // make sure the plugin that executed this method is included in the plugins to load
     $extraPlugins = array_merge(self::$extraPluginsToLoad, $this->vars->pluginsToLoad ?: array(), array(Plugin::getPluginNameFromBacktrace(debug_backtrace()), Plugin::getPluginNameFromNamespace($this->vars->testCaseClass), Plugin::getPluginNameFromNamespace($this->vars->fixtureClass), Plugin::getPluginNameFromNamespace(get_called_class())));
     foreach ($extraPlugins as $pluginName) {
         if (empty($pluginName)) {
             continue;
         }
         if (in_array($pluginName, $plugins)) {
             continue;
         }
         $plugins[] = $pluginName;
     }
     return $plugins;
 }
Example #3
0
 public static function loadAllPlugins($testEnvironment = null, $testCaseClass = false, $extraPluginsToLoad = array())
 {
     if (empty($testEnvironment)) {
         $testEnvironment = new Piwik_TestingEnvironment();
     }
     DbHelper::createTables();
     $pluginsManager = \Piwik\Plugin\Manager::getInstance();
     $plugins = $testEnvironment->getCoreAndSupportedPlugins();
     // make sure the plugin that executed this method is included in the plugins to load
     $extraPlugins = array_merge($extraPluginsToLoad, array(\Piwik\Plugin::getPluginNameFromBacktrace(debug_backtrace()), \Piwik\Plugin::getPluginNameFromNamespace($testCaseClass), \Piwik\Plugin::getPluginNameFromNamespace(get_called_class())));
     foreach ($extraPlugins as $pluginName) {
         if (empty($pluginName)) {
             continue;
         }
         if (in_array($pluginName, $plugins)) {
             continue;
         }
         $plugins[] = $pluginName;
         if ($testEnvironment) {
             $testEnvironment->pluginsToLoad = array_merge($testEnvironment->pluginsToLoad ?: array(), array($pluginName));
         }
     }
     Log::debug("Plugins to load during tests: " . implode(', ', $plugins));
     $pluginsManager->loadPlugins($plugins);
 }
Example #4
0
 private function doLog($level, $message, $sprintfParams = array())
 {
     if (!$this->shouldLoggerLog($level)) {
         return;
     }
     $datetime = date("Y-m-d H:i:s");
     if (is_string($message) && !empty($sprintfParams)) {
         $message = vsprintf($message, $sprintfParams);
     }
     if (version_compare(phpversion(), '5.3.6', '>=')) {
         $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT);
     } else {
         $backtrace = debug_backtrace();
     }
     $tag = Plugin::getPluginNameFromBacktrace($backtrace);
     // if we can't determine the plugin, use the name of the calling class
     if ($tag == false) {
         $tag = $this->getClassNameThatIsLogging($backtrace);
     }
     $this->writeMessage($level, $tag, $datetime, $message);
 }