*
*/
class PropertyBag implements \ArrayAccess {
+ /**
+ * @var array - see legacyWarning */
+ public static $legacyWarnings = [];
+
protected $props = ['default' => []];
protected static $propMap = [
}
/**
- * @var string Just for unit testing.
+ * Just for unit testing.
+ *
+ * @var string
*/
public $lastWarning;
}
/**
+ * Log legacy warnings info.
+ *
* @param string $message
*/
protected function legacyWarning($message) {
- $message = "Deprecated code: $message";
+ if (empty(static::$legacyWarnings)) {
+ // First time we have been called.
+ register_shutdown_function([PropertyBag::class, 'writeLegacyWarnings']);
+ }
+ // Store warnings instead of logging immediately, as calls to Civi::log()
+ // can take over half a second to work in some hosting environments.
+ static::$legacyWarnings[$message] = TRUE;
+
+ // For unit tests:
$this->lastWarning = $message;
- Civi::log()->warning($message);
+ }
+
+ /**
+ * Save any legacy warnings to log.
+ *
+ * Called as a shutdown function.
+ */
+ public static function writeLegacyWarnings() {
+ if (!empty(static::$legacyWarnings)) {
+ $message = "Civi\\Payment\\PropertyBag related deprecation warnings:\n"
+ . implode("\n", array_keys(static::$legacyWarnings));
+ Civi::log()->warning($message, ['civi.tag' => 'deprecated']);
+ }
}
/**