Inject logger
This commit is contained in:
parent
20bfbb0fd9
commit
32afdcbefe
|
@ -12,16 +12,19 @@ class SearchResultSorter {
|
||||||
private $search;
|
private $search;
|
||||||
private $encoding;
|
private $encoding;
|
||||||
private $key;
|
private $key;
|
||||||
|
private $log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $search the search term as was given by the user
|
* @param $search the search term as was given by the user
|
||||||
* @param $key the array key containing the value that should be compared
|
* @param $key the array key containing the value that should be compared
|
||||||
* against
|
* against
|
||||||
* @param $encoding optional, encoding to use, defaults to UTF-8
|
* @param $encoding optional, encoding to use, defaults to UTF-8
|
||||||
|
* @param $log optional, an \OC\Log instance
|
||||||
*/
|
*/
|
||||||
public function __construct($search, $key, $encoding = 'UTF-8') {
|
public function __construct($search, $key, $encoding = 'UTF-8', \OC\Log $log = null) {
|
||||||
$this->encoding = $encoding;
|
$this->encoding = $encoding;
|
||||||
$this->key = $key;
|
$this->key = $key;
|
||||||
|
$this->log = is_null($log) ? new \OC\Log() : $log;
|
||||||
$this->search = mb_strtolower($search, $this->encoding);
|
$this->search = mb_strtolower($search, $this->encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,8 +35,8 @@ class SearchResultSorter {
|
||||||
*/
|
*/
|
||||||
public function sort($a, $b) {
|
public function sort($a, $b) {
|
||||||
if(!isset($a[$this->key]) || !isset($b[$this->key])) {
|
if(!isset($a[$this->key]) || !isset($b[$this->key])) {
|
||||||
\OCP\Util::writeLog('core', 'Sharing: cannot sort due to missing'.
|
$this->log->error('Sharing dialogue: cannot sort due to missing array key',
|
||||||
'array key', \OC_Log::ERROR);
|
array('app' => 'core'));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
$nameA = mb_strtolower($a[$this->key], $this->encoding);
|
$nameA = mb_strtolower($a[$this->key], $this->encoding);
|
||||||
|
|
|
@ -37,4 +37,11 @@ class Test_Share_Search extends \PHPUnit_Framework_TestCase {
|
||||||
$this->assertTrue($result[2]['foobar'] === 'Bicyclerepairwoman');
|
$this->assertTrue($result[2]['foobar'] === 'Bicyclerepairwoman');
|
||||||
$this->assertTrue($result[3]['foobar'] === 'woot');
|
$this->assertTrue($result[3]['foobar'] === 'woot');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException PHPUnit_Framework_Error
|
||||||
|
*/
|
||||||
|
public function testSortWrongLog() {
|
||||||
|
$sorter = new \OC\Share\SearchResultSorter('foo', 'bar', 'UTF-8', 'foobar');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue