]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add constructor to inject collator
authorAW-UC <git@a-wesemann.de>
Fri, 20 Feb 2015 13:03:34 +0000 (14:03 +0100)
committerAW-UC <git@a-wesemann.de>
Fri, 20 Feb 2015 13:03:34 +0000 (14:03 +0100)
Adding the possibility for instantiating \OC\NaturalSort with an
injected collator. This makes the use of a specific collator enforcable.

lib/private/naturalsort.php

index d511bfa3f6615132512868addc93f8416c272e87..57947f56afa97d5e01ecfa778e6d716cc817dd46 100644 (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