Skip to content
This repository was archived by the owner on Mar 9, 2023. It is now read-only.

Commit

Permalink
CHG: updated PHP library
Browse files Browse the repository at this point in the history
  • Loading branch information
tuegeb committed Jul 4, 2016
1 parent 860d6f2 commit 7097853
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 49 deletions.
51 changes: 44 additions & 7 deletions src/lib/FACTFinder/Adapter/AbstractAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ abstract class AbstractAdapter
* @var object The processed response content.
*/
private $responseContent = null;

/**
* @var string The last error message.
*/
private $error = null;

/**
* @var string The last stack trace.
*/
private $stackTrace = null;

/**
* @param string $loggerClass Class name of logger to use. The class should
Expand Down Expand Up @@ -98,16 +108,16 @@ protected function useJsonResponseContentProcessor()
// stdClass objects don't really have any advantages over plain
// arrays but miss out on some of the built-in array functions.
$jsonData = json_decode($string, true);

if (is_null($jsonData))
throw new \InvalidArgumentException(
"json_decode() raised an error: ".json_last_error()
);

if(is_array($jsonData) && isset($jsonData['error'])) {
$this->log->error("FACT-Finder returned error: " . strip_tags($jsonData['error']));
$this->error = strip_tags($jsonData['error']);
$this->log->error("FACT-Finder returned error: " . $this->error);
if(isset($jsonData['stacktrace'])) {
$this->log->error("Stacktrace:\n" . $jsonData['stacktrace']);
$this->stackTrace = $jsonData['stacktrace'];
$this->log->error("Stacktrace:\n" . $this->stackTrace);
}
}
return $jsonData;
Expand All @@ -121,9 +131,11 @@ protected function useXmlResponseContentProcessor()
// The constructor throws an exception on error
$response = new \SimpleXMLElement($string);
if(isset($response->error)) {
$this->log->error("FACT-Finder returned error: " . strip_tags($response->error));
$this->error = strip_tags($response->error);
$this->log->error("FACT-Finder returned error: " . $this->error);
if(isset($response->stacktrace)) {
$this->log->error("Stacktrace:\n" . $response->stacktrace);
$this->stackTrace = $response->stacktrace;
$this->log->error("Stacktrace:\n" . $this->stackTrace);
}
}
return $response;
Expand Down Expand Up @@ -191,9 +203,34 @@ protected function convertServerQueryToClientUrl($query)

return $this->urlBuilder->generateUrl($parameters);
}


/**
* Returns true if the response is valid or false if an error occurred.
*
* @return bool
*/
protected function isValidResponse($jsonData)
{
return (!empty($jsonData) && !isset($jsonData['error']));
}

/**
* Returns a message if an error occurred.
*
* @return string
*/
public function getError()
{
return $this->error;
}

/**
* Returns the stack trace if an error occurred.
*
* @return string
*/
public function getStackTrace()
{
return $this->stackTrace;
}
}
66 changes: 33 additions & 33 deletions src/lib/FACTFinder/Adapter/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private function createResult()

$jsonData = $this->getResponseContent();

if (parent::isValidResponse($jsonData) && isset($jsonData['searchResult'])) {
if ($this->isValidResponse($jsonData)) {
$searchResultData = $jsonData['searchResult'];
$refKey = $searchResultData['refKey'];

Expand Down Expand Up @@ -192,7 +192,7 @@ private function createSingleWordSearch()
$singleWordSearch = array();

$jsonData = $this->getResponseContent();
if (parent::isValidResponse($jsonData) && !empty($jsonData['searchResult']['singleWordResults']))
if ($this->isValidResponse($jsonData) && !empty($jsonData['searchResult']['singleWordResults']))
{
foreach ($jsonData['searchResult']['singleWordResults'] as $swsData)
{
Expand Down Expand Up @@ -233,7 +233,7 @@ public function getStatus()
$status = $searchStatusEnum::NoResult();

$jsonData = $this->getResponseContent();
if (parent::isValidResponse($jsonData) && isset($jsonData['searchResult']))
if ($this->isValidResponse($jsonData))
{
switch($jsonData['searchResult']['resultStatus'])
{
Expand All @@ -257,7 +257,7 @@ public function getArticleNumberStatus()
$status = $articleNumberSearchStatusEnum::IsNoArticleNumberSearch();

$jsonData = $this->getResponseContent();
if (parent::isValidResponse($jsonData) && isset($jsonData['searchResult']))
if ($this->isValidResponse($jsonData))
{
switch ($jsonData['searchResult']['resultArticleNumberStatus'])
{
Expand All @@ -278,7 +278,7 @@ public function getArticleNumberStatus()
public function isSearchTimedOut()
{
$jsonData = $this->getResponseContent();
if (parent::isValidResponse($jsonData) && isset($jsonData['searchResult']))
if ($this->isValidResponse($jsonData))
{
return $jsonData['searchResult']['timedOut'];
}
Expand All @@ -305,7 +305,7 @@ private function createAfterSearchNavigation()

$filterGroups = array();

if (parent::isValidResponse($jsonData) && isset($jsonData['searchResult']['groups'])) {
if ($this->isValidResponse($jsonData) && isset($jsonData['searchResult']['groups'])) {
foreach ($jsonData['searchResult']['groups'] as $groupData)
$filterGroups[] = $this->createFilterGroup($groupData);
}
Expand Down Expand Up @@ -503,7 +503,7 @@ public function createResultsPerPageOptions()

$jsonData = $this->getResponseContent();

if (parent::isValidResponse($jsonData) && isset($jsonData['searchResult']))
if ($this->isValidResponse($jsonData))
{
$rppData = $jsonData['searchResult']['resultsPerPageList'];
if (!empty($rppData))
Expand Down Expand Up @@ -559,7 +559,7 @@ private function createPaging()

$jsonData = $this->getResponseContent();

if (parent::isValidResponse($jsonData) && isset($jsonData['searchResult']))
if ($this->isValidResponse($jsonData))
{
$pagingData = $jsonData['searchResult']['paging'];
if (!empty($pagingData))
Expand Down Expand Up @@ -644,7 +644,7 @@ private function createSorting()

$jsonData = $this->getResponseContent();

if (parent::isValidResponse($jsonData) && isset($jsonData['searchResult']))
if ($this->isValidResponse($jsonData))
{
$sortingData = $jsonData['searchResult']['sortsList'];
if (!empty($sortingData))
Expand Down Expand Up @@ -692,7 +692,7 @@ private function createBreadCrumbTrail()

$jsonData = $this->getResponseContent();

if (parent::isValidResponse($jsonData) && isset($jsonData['searchResult']))
if ($this->isValidResponse($jsonData))
{
$breadCrumbTrailData = $jsonData['searchResult']['breadCrumbTrailItems'];
if (!empty($breadCrumbTrailData))
Expand All @@ -705,11 +705,19 @@ private function createBreadCrumbTrail()
);

$breadCrumbTypeEnum = FF::getClassName('Data\BreadCrumbType');
if ($breadCrumbData['type'] == 'filter')
switch ($breadCrumbData['type'])
{
case 'filter':
$type = $breadCrumbTypeEnum::Filter();
else
break;
case 'advisor':
$type = $breadCrumbTypeEnum::Advisor();
break;
default:
$type = $breadCrumbTypeEnum::Search();

break;
}

$breadCrumbs[] = FF::getInstance(
'Data\BreadCrumb',
$breadCrumbData['text'],
Expand Down Expand Up @@ -749,7 +757,7 @@ private function createCampaigns()
$campaigns = array();
$jsonData = $this->getResponseContent();

if (parent::isValidResponse($jsonData) && isset($jsonData['searchResult']['campaigns'])) {
if ($this->isValidResponse($jsonData) && isset($jsonData['searchResult']['campaigns'])) {
foreach ($jsonData['searchResult']['campaigns'] as $campaignData) {
$campaign = $this->createEmptyCampaignObject($campaignData);

Expand Down Expand Up @@ -940,24 +948,6 @@ private function createAdvisorAnswer($answerData, $recursive = false)
$followUpQuestions
);
}

/**
* @return string
*/
public function getError()
{
$jsonData = $this->getResponseContent();
return isset($jsonData['error']) ? $jsonData['error'] : null;
}

/**
* @return string
*/
public function getStackTrace()
{
$jsonData = $this->getResponseContent();
return isset($jsonData['stacktrace']) ? $jsonData['stacktrace'] : null;
}

/**
* Value for parameter "followSearch" for followups on initial search like filters, pagination, ...
Expand All @@ -970,7 +960,7 @@ public function getFollowSearchValue()
{
$jsonData = $this->getResponseContent();
//use searchParams of result if available
if (parent::isValidResponse($jsonData) && $jsonData['searchResult'] && isset($jsonData['searchResult']['searchParams'])) {
if ($this->isValidResponse($jsonData) && isset($jsonData['searchResult']['searchParams'])) {
$parameters = FF::getInstance(
'Util\Parameters',
$jsonData['searchResult']['searchParams']
Expand Down Expand Up @@ -998,4 +988,14 @@ public function getFollowSearchValue()
}
return $followSearch;
}

/**
* Returns true if the search response is valid or false if an error occurred.
*
* @return bool
*/
protected function isValidResponse($jsonData)
{
return (!empty($jsonData) && !isset($jsonData['error']) && isset($jsonData['searchResult']));
}
}
16 changes: 8 additions & 8 deletions src/lib/FACTFinder/Adapter/Tracking.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ public function setupTrackingFromRequest($sid = null)
/**
* Track a detail click on a product.
*
* @param string $id id of product
* @param string $id tracking id of product (see field with the role "Product number for tracking")
* @param string $sid session id (if empty, then try to set using the function session_id() )
* @param string $query query which led to the product
* @param int $pos position of product in the search result
* @param string $masterid masterId of product if variant
* @param string $masterId master id of the product (see field with the role "Master article number")
* @param string $cookieId cookie id (optional)
* @param int $origPos original position of product in the search result. this data is delivered by FACT-Finder (optional - is set equals to $position by default)
* @param int $page page number where the product was clicked (optional - is 1 by default)
Expand Down Expand Up @@ -151,8 +151,8 @@ public function setupClickTracking(
/**
* Track a product which was added to the cart.
*
* @param string $id id of product
* @param string $masterid masterId of product if variant
* @param string $id tracking id of product (see field with the role "Product number for tracking")
* @param string $masterId master id of the product (see field with the role "Master article number")
* @param string $tile title of product (optional - is empty by default)
* @param string $query query which led to the product (only if module Semantic Enhancer is used)
* @param string $sid session id (if empty, then try to set using the function session_id() )
Expand Down Expand Up @@ -215,8 +215,8 @@ public function setupCartTracking(
/**
* Track a product which was purchased.
*
* @param string $id id of product
* @param string $masterid masterId of product if variant
* @param string $id tracking id of product (see field with the role "Product number for tracking")
* @param string $masterId master id of the product (see field with the role "Master article number")
* @param string $tile title of product (optional - is empty by default)
* @param string $query query which led to the product (only if module Semantic Enhancer is used)
* @param string $sid session id (if empty, then try to set using the function session_id() )
Expand Down Expand Up @@ -280,9 +280,9 @@ public function setupCheckoutTracking(
/**
* Track a click on a recommended product.
*
* @param string $id id of product
* @param string $id tracking id of product (see field with the role "Product number for tracking")
* @param int $mainId ID of the product for which the clicked-upon item was recommended
* @param string $masterid masterId of product if variant
* @param string $masterId master id of the product (see field with the role "Master article number")
* @param string $sid session id (if empty, then try to set using the function session_id() )
* @param string $cookieId cookie id (optional)
* @param string $userid id of user (optional if modul personalisation is not used)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/FACTFinder/Core/Server/EasyCurlDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private function prepareConnectionOptions(
) {
if ($this->configuration->isDebugEnabled()
&& isset($_SERVER['HTTP_REFERER'])
&& !$connectionData->issetConnectionOptions(CURLOPT_REFERER)
&& !$connectionData->issetConnectionOption(CURLOPT_REFERER)
) {
$connectionData->setConnectionOption(
CURLOPT_REFERER,
Expand Down
3 changes: 3 additions & 0 deletions src/lib/FACTFinder/Data/BreadCrumbType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class BreadCrumbType
{
static private $search;
static private $filter;
static private $advisor;

static private $nextID = 0;
private $id;
Expand All @@ -24,13 +25,15 @@ static public function initialize()
{
self::$search = new BreadCrumbType();
self::$filter = new BreadCrumbType();
self::$advisor = new BreadCrumbType();

self::$initialized = true;
}
}

static public function Search() { return self::$search; }
static public function Filter() { return self::$filter; }
static public function Advisor() { return self::$advisor; }
}

BreadCrumbType::initialize();

0 comments on commit 7097853

Please sign in to comment.