X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=Civi%2FPayment%2FPropertyBag.php;h=6cea55241e7ec38f40ffe0c4bf99e3b59f018e1f;hb=ee4ac4e666956c3255b24525be6fc992760513a8;hp=c8db41457194200f3ed81adb5e1ef1c6004bc741;hpb=499543c54101eabc3319eb09dffa38ed2782c4c9;p=civicrm-core.git diff --git a/Civi/Payment/PropertyBag.php b/Civi/Payment/PropertyBag.php index c8db414571..6cea55241e 100644 --- a/Civi/Payment/PropertyBag.php +++ b/Civi/Payment/PropertyBag.php @@ -21,6 +21,12 @@ use CRM_Core_PseudoConstant; * */ class PropertyBag implements \ArrayAccess { + /** + * @var array + * - see legacyWarning + */ + public static $legacyWarnings = []; + protected $props = ['default' => []]; protected static $propMap = [ @@ -161,12 +167,34 @@ class PropertyBag implements \ArrayAccess { } /** + * 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']); + } } /** @@ -252,9 +280,9 @@ class PropertyBag implements \ArrayAccess { * @param array $data */ public function mergeLegacyInputParams($data) { - $this->legacyWarning("We have merged input params into the property bag for now but please rewrite code to not use this."); + $this->legacyWarning('We have merged input params into the property bag for now but please rewrite code to not use this.'); foreach ($data as $key => $value) { - if ($value !== NULL) { + if ($value !== NULL && $value !== '') { $this->offsetSet($key, $value); } }