More progress on PHP to service interaction. Moved to composer for managing dependencies, including adding a dependency on GuzzleHttp.

This commit is contained in:
Jakub Oleksy 2014-12-03 12:20:15 -07:00
Родитель 340ee06d55
Коммит 4fb9d1a8e5
13 изменённых файлов: 51 добавлений и 56 удалений

5
.gitignore поставляемый
Просмотреть файл

@ -1,3 +1,8 @@
## Ignore Composer
vendor
*.lock
*.phar
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

Просмотреть файл

@ -37,6 +37,11 @@
<Folder Include="ApplicationInsights\Tests\" />
</ItemGroup>
<ItemGroup>
<Content Include=".gitattributes" />
<Content Include=".gitignore" />
<Content Include="composer.json" />
<Content Include="LICENSE" />
<Content Include="phpunit.xml" />
<Content Include="README.md" />
</ItemGroup>
</Project>

Просмотреть файл

@ -5,14 +5,6 @@ VisualStudioVersion = 12.0.30723.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{A0786B88-2ADB-4C21-ABE8-AA2D79766269}") = "Application.Insights", "Application.Insights.phpproj", "{6C54EAC1-21B0-4DBE-A7C8-59E4A4F81316}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{BD4B101A-09FF-434E-800B-A9F17513944B}"
ProjectSection(SolutionItems) = preProject
..\.gitattributes = ..\.gitattributes
..\.gitignore = ..\.gitignore
..\LICENSE = ..\LICENSE
..\README.md = ..\README.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU

Просмотреть файл

@ -1,13 +1,5 @@
<?php
namespace ApplicationInsights;
/**
* Handles loading of classes needed for ApplicationInsights SDK.
* @param string $pClassName
*/
function autoLoadClasses($pClassName) {
include($pClassName . ".php");
}
spl_autoload_register("ApplicationInsights\autoLoadClasses");
require 'vendor/autoload.php';
?>

Просмотреть файл

@ -11,6 +11,14 @@ class Data implements \JsonSerializable
*/
private $_data;
/**
* Creates a new Data.
*/
function __construct()
{
$this->_data['baseData'] = NULL;
}
/**
* Gets the baseType field.
*/

Просмотреть файл

@ -11,6 +11,13 @@ class Device implements \JsonSerializable
*/
private $_data;
/**
* Creates a new Device.
*/
function __construct()
{
}
/**
* Gets the id field.
*/

Просмотреть файл

@ -11,6 +11,17 @@ class Envelope implements \JsonSerializable
*/
private $_data;
/**
* Creates a new Envelope.
*/
function __construct()
{
$this->_data['ver'] = 1;
$this->_data['name'] = NULL;
$this->_data['time'] = NULL;
$this->_data['sampleRate'] = 100.0;
}
/**
* Gets the ver field.
*/

Просмотреть файл

@ -28,6 +28,8 @@ class EventData implements \JsonSerializable
{
$this->_envelope_type_name = 'Microsoft.ApplicationInsights.Event';
$this->_data_type_name = 'EventData';
$this->_data['ver'] = 2;
$this->_data['name'] = NULL;
}
/**

Просмотреть файл

@ -33,6 +33,7 @@ class TelemetryChannel
}
$envelope = new Contracts\Envelope();
$envelope->set_ver(2);
$envelope->set_name($data->get_envelope_type_name());
$envelope->set_time(gmdate('c') . 'Z');
$envelope->set_ikey('f22d426f-57e2-47c3-9668-c58013a26eb4');

Просмотреть файл

@ -18,12 +18,6 @@ class TelemetrySender
*/
private $_queue;
/**
* When set, instead of sending the data to the endpoint, the class will send the data it would have sent to this callback.
* @var callable
*/
private $_verificationCallback;
/**
* Initializes a new TelemetrySender.
* @param string $endpointURL Optional. Allows caller to override which endpoint to send data to.
@ -32,7 +26,6 @@ class TelemetrySender
function __construct($endpointURL = 'http://dc.services.visualstudio.com/v2/track')
{
$this->_endpointURL = $endpointURL;
$this->_verificationCallback = NULL;
$this->_queue = [];
}
@ -54,23 +47,6 @@ class TelemetrySender
$this->_endpointURL = $endpointURL;
}
/**
* If set, returns the callback to use for verification; otherwise NULL.
* @return callable
*/
public function getVerificationCallback()
{
return $this->_verificationCallback;
}
/**
* Sets the callback to use for verification.
* @param string $verificationCallback
*/
public function setVerificationCallback($verificationCallback)
{
return $this->_verificationCallback = $verificationCallback;
}
/**
* Returns the current queue.
@ -88,6 +64,15 @@ class TelemetrySender
public function send($telemetryItem)
{
$serializedTelemetryItem = json_encode($telemetryItem);
$client = new \GuzzleHttp\Client();
$response = $client->post($this->_endpointURL, [
'headers' => ['Accept' => 'application/json',
'Content-Type' => 'application/json; charset=utf-8'],
'body' => utf8_encode($serializedTelemetryItem),
'proxy' => '127.0.0.1:8888'
]);
}
}

Просмотреть файл

@ -7,13 +7,6 @@ use ApplicationInsights\TelemetryClient;
*/
class TelemetryClientTest extends \PHPUnit_Framework_TestCase
{
/**
* Verifies the object is constructed properly.
*/
public function testConstructor()
{
}
public function testCurrent()
{
$telemetryClient = new TelemetryClient();

Просмотреть файл

@ -11,7 +11,7 @@ class TelemetrySenderTest extends \PHPUnit_Framework_TestCase
/**
* Verifies the object is constructed properly.
*/
public function testConstructor()
public function test_constructor()
{
$telemetrySender = new TelemetrySender();
$this->assertEquals($telemetrySender->getEndpointURL(), 'http://dc.services.visualstudio.com/v2/track', 'Default Endpoint URL is incorrect.');
@ -19,17 +19,11 @@ class TelemetrySenderTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($telemetrySender->getVerificationCallback(), NULL, 'Callback should be NULL by default.');
}
public function telemetrySenderCallback($encodedItem)
{
echo $encodedItem;
}
public function testCurrent()
{
$envelope = new Envelope();
$envelope->setIKey('f22d426f-57e2-47c3-9668-c58013a26eb4');
$telemetrySender = new TelemetrySender();
$telemetrySender->setVerificationCallback(array($this, 'telemetrySenderCallback'));
$telemetrySender->send($envelope);
}
}

Просмотреть файл

@ -20,5 +20,5 @@
timeoutForMediumTests="10"
timeoutForLargeTests="60"
strict="false"
verbose="false"
verbose="true"
<!-- ... --></phpunit>