CollectionTrait - Use "splats". Split out "adders". Define interfaces.
authorTim Otten <totten@civicrm.org>
Tue, 18 Aug 2020 03:45:29 +0000 (20:45 -0700)
committerSeamus Lee <seamuslee001@gmail.com>
Thu, 3 Sep 2020 22:02:17 +0000 (08:02 +1000)
commit060617e9df668cd7d422b6b32276364cd3368310
treec9e45218b3d78913e6805e2745c2570ceb41e4bf
parentfcf926ad4ab1df90dd9d553a75f7385124420220
CollectionTrait - Use "splats". Split out "adders". Define interfaces.

In the prior commits, the signatures for `addScriptFile()`,
`addScriptUrl()`, etc are not strictly interoperable between
`CRM_Core_Resources` and `CollectionTrait`.  This is because they use
key-value options instead of positional options.  This makes it easier
disregard positional options that don't make sense (e.g.  when calling
`CRM_Core_Region::addScriptFile()`, it's silly to reserve a positional
argument for the `$region` option).

The signatures *can* be unified by using "splats" (ie `...$options`) to
accept either key-value options or backward-compatible positional options.
The ultimate is hope is that:

* `CRM_Core_Resources`, `CRM_Core_Region`, and `CRM_Core_Bundle` all
  implement the `CollectionAdderInterface`.
* `CRM_Core_Resources`, `CRM_Core_Region`, and `CRM_Core_Bundle` all
  accept options in either format (key-value or positional).
* The positional format will fade-away.

The methods in CollectionTrait are newer terrain, so it's safer to change
those signatures, so we do that first.

Note that CollectionTrait formally builds on CollectionAdderTrait. This
ensures that IDE navigation to (eg) `CRM_Core_Region::add()` and
`CRM_Core_Resources_Bundle::add()` works as expected.
CRM/Core/Region.php
CRM/Core/Resources/CollectionAdderInterface.php [new file with mode: 0644]
CRM/Core/Resources/CollectionAdderTrait.php [new file with mode: 0644]
CRM/Core/Resources/CollectionInterface.php [new file with mode: 0644]
CRM/Core/Resources/CollectionTrait.php