From: AW-UC Date: Fri, 20 Feb 2015 13:03:34 +0000 (+0100) Subject: Add constructor to inject collator X-Git-Tag: v8.1.0alpha1~419^2~2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=bc668600cd9c44c9b1efe0d520005ad10e577a02;p=nextcloud-server.git Add constructor to inject collator Adding the possibility for instantiating \OC\NaturalSort with an injected collator. This makes the use of a specific collator enforcable. --- diff --git a/lib/private/naturalsort.php b/lib/private/naturalsort.php index d511bfa3f66..57947f56afa 100644 --- a/lib/private/naturalsort.php +++ b/lib/private/naturalsort.php @@ -14,6 +14,19 @@ class NaturalSort { private $collator; private $cache = array(); + /** + * Instantiate a new \OC\NaturalSort instance. + * @param object $injectedCollator + */ + public function __construct($injectedCollator = null) { + // inject an instance of \Collator('en_US') to force using the php5-intl Collator + // or inject an instance of \OC\NaturalSort_DefaultCollator to force using Owncloud's default collator + if (isset($injectedCollator)) { + $this->collator = $injectedCollator; + \OC_Log::write('core', 'forced use of '.get_class($injectedCollator), \OC_Log::DEBUG); + } + } + /** * Split the given string in chunks of numbers and strings * @param string $t string