PHP code example of itkg / consumer
1. Go to this page and download the library: Download itkg/consumer 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/ */
itkg / consumer example snippets
$service = new \Itkg\Consumer\Service\Service(
$eventDispatcher,
new Itkg\Consumer\Client\RestClient(array(
'timeout' => 10
)),
array(
'identifier' => 'my test'
)
);
$response = $service
->sendRequest(\Symfony\Component\HttpFoundation\Request::create('http://URL/OF/MY/WEBSERVICE.json'))
->getResponse();
$service = new \Itkg\Consumer\Service\Service(
$eventDispatcher,
new Itkg\Consumer\Client\RestClient(array(
'timeout' => 10
)),
array(
'identifier' => 'my test',
'logger' => new \Monolog\Logger('my_logger', array(new \Monolog\Handler\StreamHandler('/tmp/test'))),
)
);
$eventDispatcher->addSubscriber(new \Itkg\Consumer\Listener\LoggerListener());
$eventDispatcher->addSubscriber(
new \Itkg\Consumer\Listener\DeserializerListener(JMS\Serializer\SerializerBuilder::create()->build())
);
$service = new \Itkg\Consumer\Service\Service(
$eventDispatcher,
new Itkg\Consumer\Client\RestClient(array(
'timeout' => 10
)),
array(
'identifier' => 'my test',
'reponse_format' => 'xml,
'response_type' => 'My\Class
)
);
$object = $service->getResponse()->getDeserializedContent();
$eventDispatcher->addSubscriber(
new \Itkg\Consumer\Listener\CacheListener($eventDispatcher)
);
$service = new \Itkg\Consumer\Service\Service(
$eventDispatcher,
new Itkg\Consumer\Client\RestClient(array(
'timeout' => 10
)),
array(
'identifier' => 'my test',
'cache_adapter' => new \Itkg\Core\Cache\Adapter\Registry(),
'cache_ttl => 10000
)
);