Skip to content
Snippets Groups Projects
Commit 40ce9bab authored by Demian Katz's avatar Demian Katz
Browse files

Set up Summon connection to use dependency injection for logging; improved log...

Set up Summon connection to use dependency injection for logging; improved log output; expanded some comments.
parent 3e6d1b75
No related merge requests found
...@@ -28,10 +28,8 @@ ...@@ -28,10 +28,8 @@
*/ */
namespace VuFind\Connection; namespace VuFind\Connection;
use SerialsSolutions\Summon\Zend2 as BaseSummon, use SerialsSolutions\Summon\Zend2 as BaseSummon,
VuFind\Config\Reader as ConfigReader, VuFind\Config\Reader as ConfigReader, VuFind\Http\Client as HttpClient,
VuFind\Http\Client as HttpClient, VuFind\Solr\Utils as SolrUtils, Zend\Log\Logger;
VuFind\Log\Logger,
VuFind\Solr\Utils as SolrUtils;
/** /**
* Summon Search API Interface (VuFind implementation) * Summon Search API Interface (VuFind implementation)
...@@ -48,15 +46,25 @@ class Summon extends BaseSummon ...@@ -48,15 +46,25 @@ class Summon extends BaseSummon
/** /**
* Should boolean operators in the search string be treated as * Should boolean operators in the search string be treated as
* case-insensitive (false), or must they be ALL UPPERCASE (true)? * case-insensitive (false), or must they be ALL UPPERCASE (true)?
*
* @var bool
*/ */
protected $caseSensitiveBooleans = true; protected $caseSensitiveBooleans = true;
/** /**
* Will we include snippets in responses? * Will we include snippets in responses?
*
* @var bool * @var bool
*/ */
protected $snippets = false; protected $snippets = false;
/**
* Logger object for debug info (or false for no debugging).
*
* @var Logger|bool
*/
protected $logger = false;
/** /**
* Constructor * Constructor
* *
...@@ -91,12 +99,6 @@ class Summon extends BaseSummon ...@@ -91,12 +99,6 @@ class Summon extends BaseSummon
$this->snippets = $config->General->snippets; $this->snippets = $config->General->snippets;
} }
// Set default debug behavior:
$this->logger = Logger::getInstance();
if (!isset($options['debug'])) {
$options['debug'] = $this->logger->debugNeeded();
}
$timeout = isset($config->General->timeout) $timeout = isset($config->General->timeout)
? $config->General->timeout : 30; ? $config->General->timeout : 30;
parent::__construct( parent::__construct(
...@@ -106,6 +108,21 @@ class Summon extends BaseSummon ...@@ -106,6 +108,21 @@ class Summon extends BaseSummon
); );
} }
/**
* Set the logger
*
* @param Logger $logger Logger to use.
*
* @return void
*/
public function setLogger(Logger $logger)
{
// Adjust debug property based on logger settings:
$this->debug = method_exists($logger, 'debugNeeded')
? $logger->debugNeeded() : true;
$this->logger = $logger;
}
/** /**
* Print a message if debug is enabled. * Print a message if debug is enabled.
* *
...@@ -115,8 +132,8 @@ class Summon extends BaseSummon ...@@ -115,8 +132,8 @@ class Summon extends BaseSummon
*/ */
protected function debugPrint($msg) protected function debugPrint($msg)
{ {
if ($this->debug) { if ($this->debug && $this->logger) {
$this->logger->debug("<pre>{$msg}</pre>\n"); $this->logger->debug("$msg\n");
} }
} }
......
...@@ -60,6 +60,7 @@ class Results extends BaseResults ...@@ -60,6 +60,7 @@ class Results extends BaseResults
$id = isset($config->Summon->apiId) ? $config->Summon->apiId : null; $id = isset($config->Summon->apiId) ? $config->Summon->apiId : null;
$key = isset($config->Summon->apiKey) ? $config->Summon->apiKey : null; $key = isset($config->Summon->apiKey) ? $config->Summon->apiKey : null;
$conn = new SummonConnection($id, $key); $conn = new SummonConnection($id, $key);
$conn->setLogger(\VuFind\Log\Logger::getInstance());
} }
return $conn; return $conn;
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment