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.
This commit is contained in:
AW-UC 2015-02-20 14:03:34 +01:00
parent 097d455213
commit bc668600cd
1 changed files with 13 additions and 0 deletions

View File

@ -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