PHP code example of peterfox / graphaware-reco-client
1. Go to this page and download the library: Download peterfox/graphaware-reco-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
peterfox / graphaware-reco-client example snippets
use GraphAwareReco\Bridge\Guzzle\Client;
use GraphAwareReco\Bridge\Guzzle\RecommendationDescriptionBuilder;
use GraphAwareReco\Domain\Common\RecommendationFactory;
use GraphAwareReco\Domain\Common\RecommendationService;
use GraphAwareReco\Domain\Common\JsonResponseParser;
use GuzzleHttp\Client as Guzzle;
use GuzzleHttp\Command\Guzzle\GuzzleClient;
$service = new RecommendationService('http://localhost:7474/');
$description = RecommendationDescriptionBuilder::getDescriptionFromService($service);
$guzzle = new GuzzleClient(new Guzzle(), $description, ['defaults' => []]);
$client = new Client($guzzle, new RecommendationFactory(), new JsonResponseParser());
use GraphAwareReco\Domain\Model\RecommendationService as RecommendationServiceInterface;
class RecommendationService implements RecommendationServiceInterface
{
/**
* @var string
*/
private $baseUrl;
/**
* @param string $baseUrl
*/
public function __construct($baseUrl)
{
$this->baseUrl = $baseUrl;
}
/**
* @return string
*/
public function getBaseUrl()
{
return $this->baseUrl;
}
/**
* @return array
*/
public function getUriParameters()
{
return ['id' => 'string'];
}
/**
* @return array
*/
public function getQueryParameters()
{
return ['limit' => 'string'];
}
/**
* @return string
*/
public function getRecommendationPath()
{
return '/graphaware/recommendation/{id}';
}
}
use GraphAwareReco\Domain\Model\JsonResponseParser as ResponseParserInterface;
class JsonResponseParser implements ResponseParserInterface
{
/**
* @param array $result
* @return array
*/
public function parse(array $result)
{
return $result;
}
}
use GraphAwareReco\Domain\Model\Recommendation as RecommendationInterface;
use GraphAwareReco\Domain\Model\Score;
class Recommendation implements RecommendationInterface
{
/**
* @var
*/
private $identifier;
/**
* @var
*/
private $uuid;
/**
* @var
*/
private $score;
public function __construct($identifier, $uuid, $score)
{
$this->identifier = $identifier;
$this->uuid = $uuid;
$this->score = $score;
}
/**
* @return string
*/
public function getUUID()
{
return $this->uuid;
}
/**
* @return mixed
*/
public function getItemIdentifier()
{
return $this->identifier;
}
/**
* @return Score
*/
public function getScore()
{
$this->score;
}
}
use GraphAwareReco\Domain\Common\Recommendation as RecommendationImpl;
use GraphAwareReco\Domain\Model\Recommendation;
use GraphAwareReco\Domain\Model\RecommendationFactory as RecommendationFactoryInterface;
use GraphAwareReco\Domain\Model\Score;
class RecommendationFactory implements RecommendationFactoryInterface
{
/**
* @param array $data
* @return Recommendation
*/
public function getRecommendation(array $data)
{
return new RecommendationImpl($data['id'], $data['uuid'], Score::fromArray($data['score']));
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.