Skip to content

Commit

Permalink
(dev/core#174) Update top-level interfaces to show PSR-16 support
Browse files Browse the repository at this point in the history
  • Loading branch information
totten committed Jun 27, 2018
1 parent 6c1c4ff commit ebf0eb5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 32 deletions.
30 changes: 6 additions & 24 deletions CRM/Utils/Cache/Interface.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,14 @@
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2018
*
* CRM_Utils_Cache_Interface
* CRM_Utils_Cache_Interface is a long-standing interface used within CiviCRM
* for interacting with a cache service. In style and substance, it is extremely
* similar to PHP-FIG's SimpleCache interface (PSR-16). Consequently, beginning
* with CiviCRM v5.4, this extends \Psr\SimpleCache\CacheInterface.
*
* PHP-FIG has been developing a draft standard for caching,
* PSR-6. The standard has not been ratified yet. When
* making changes to this interface, please take care to
* avoid *conflicst* with PSR-6's CacheItemPoolInterface. At
* time of writing, they do not conflict. Avoiding conflicts
* will enable more transition paths where Civi
* simultaneously supports both interfaces in the same
* implementation.
*
* For example, the current interface defines:
*
* function get($key) => mixed $value
*
* and PSR-6 defines:
*
* function getItem($key) => ItemInterface $item
*
* These are different styles (e.g. "weak item" vs "strong item"),
* but the two methods do not *conflict*. They can coexist,
* and you can trivially write adapters between the two.
*
* @see https://github.com/php-fig/fig-standards/blob/master/proposed/cache.md
* @see https://www.php-fig.org/psr/psr-16/
*/
interface CRM_Utils_Cache_Interface {
interface CRM_Utils_Cache_Interface extends \Psr\SimpleCache\CacheInterface {

/**
* Set the value in the cache.
Expand Down
11 changes: 3 additions & 8 deletions Civi.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,15 @@ class Civi {
public static $statics = array();

/**
* EXPERIMENTAL. Retrieve a named cache instance.
*
* This interface is flagged as experimental due to political
* ambiguity in PHP community -- PHP-FIG has an open but
* somewhat controversial draft standard for caching. Based on
* the current draft, it's expected that this function could
* simultaneously support both CRM_Utils_Cache_Interface and
* PSR-6, but that depends on whether PSR-6 changes any more.
* Retrieve a named cache instance.
*
* @param string $name
* The name of the cache. The 'default' cache is biased toward
* high-performance caches (eg memcache/redis/apc) when
* available and falls back to single-request (static) caching.
* @return CRM_Utils_Cache_Interface
* NOTE: Beginning in CiviCRM v5.4, the cache instance complies with
* PSR-16 (\Psr\SimpleCache\CacheInterface).
*/
public static function cache($name = 'default') {
return \Civi\Core\Container::singleton()->get('cache.' . $name);
Expand Down

0 comments on commit ebf0eb5

Please sign in to comment.