Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] PSR-4 support #7

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
"squizlabs/php_codesniffer": "^3.5"
},
"autoload": {
"files": [
"lib/PostHog.php"
]
"psr-4": {
"Posthog": "lib"
}
},
"bin": [
"bin/posthog"
Expand Down
4 changes: 2 additions & 2 deletions lib/PostHog.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

require_once __DIR__ . '/PostHog/Client.php';
use Posthog\Client;

class PostHog {
private static $client;
Expand All @@ -12,7 +12,7 @@ class PostHog {
*/
public static function init($apiKey, $options = array()) {
self::assert($apiKey, "PostHog::init() requires an apiKey");
self::$client = new PostHog_Client($apiKey, $options);
self::$client = new Client($apiKey, $options);
}

/**
Expand Down
19 changes: 9 additions & 10 deletions lib/PostHog/Client.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?php

require_once(__DIR__ . '/Consumer.php');
require_once(__DIR__ . '/QueueConsumer.php');
require_once(__DIR__ . '/Consumer/File.php');
require_once(__DIR__ . '/Consumer/ForkCurl.php');
require_once(__DIR__ . '/Consumer/LibCurl.php');
require_once(__DIR__ . '/Consumer/Socket.php');
require_once(__DIR__ . '/Version.php');

class PostHog_Client {
namespace Posthog;

use Posthog\Consumer\File;
use Posthog\Consumer\ForkCurl;
use Posthog\Consumer\LibCurl;
use Posthog\Consumer\Socket;

class Client {
protected $consumer;

/**
Expand All @@ -22,7 +21,7 @@ class PostHog_Client {
*/
public function __construct($apiKey, $options = array()) {
$consumers = array(
"socket" => "PostHog_Consumer_Socket",
"socket" => "Socket",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come this is renamed but the other ones aren't?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way we are working with the classes here is not-optimal, I have to rewrite most of it but I ran "out of budget" for this PR.

"file" => "PostHog_Consumer_File",
"fork_curl" => "PostHog_Consumer_ForkCurl",
"lib_curl" => "PostHog_Consumer_LibCurl"
Expand Down
5 changes: 4 additions & 1 deletion lib/PostHog/Consumer.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php
abstract class PostHog_Consumer {

namespace Posthog;

abstract class Consumer {
protected $type = "Consumer";

protected $options;
Expand Down
6 changes: 5 additions & 1 deletion lib/PostHog/Consumer/File.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php

class PostHog_Consumer_File extends PostHog_Consumer {
namespace Posthog\Consumer;

use Posthog\Consumer;

class PostHog_Consumer_File extends Consumer {
protected $type = "File";

private $file_handle;
Expand Down
6 changes: 5 additions & 1 deletion lib/PostHog/Consumer/ForkCurl.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php

class PostHog_Consumer_ForkCurl extends PostHog_QueueConsumer {
namespace Posthog\Consumer;

use Posthog\QueueConsumer;

class PostHog_Consumer_ForkCurl extends QueueConsumer {
protected $type = "ForkCurl";

/**
Expand Down
6 changes: 5 additions & 1 deletion lib/PostHog/Consumer/LibCurl.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php

class PostHog_Consumer_LibCurl extends PostHog_QueueConsumer {
namespace Posthog\Consumer;

use Posthog\QueueConsumer;

class PostHog_Consumer_LibCurl extends QueueConsumer {
protected $type = "LibCurl";

/**
Expand Down
7 changes: 5 additions & 2 deletions lib/PostHog/Consumer/Socket.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@

<?php

class PostHog_Consumer_Socket extends PostHog_QueueConsumer {
namespace Posthog\Consumer;

use Posthog\QueueConsumer;

class Socket extends QueueConsumer {
protected $type = "Socket";
private $socket_failed;

Expand Down
4 changes: 3 additions & 1 deletion lib/PostHog/QueueConsumer.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

abstract class PostHog_QueueConsumer extends PostHog_Consumer {
namespace Posthog;

abstract class QueueConsumer extends Consumer {
protected $type = "QueueConsumer";

protected $queue;
Expand Down
6 changes: 3 additions & 3 deletions test/ConsumerFileTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

require_once __DIR__ . "/../lib/PostHog/Client.php";
use Posthog\Client;

class ConsumerFileTest extends PHPUnit\Framework\TestCase
{
Expand All @@ -14,7 +14,7 @@ public function setUp(): void
unlink($this->filename());
}

$this->client = new PostHog_Client(
$this->client = new Client(
"BrpS4SctoaCCsyjlnlun3OzyNJAafdlv__jUWaaJWXg",
array(
"consumer" => "file",
Expand Down Expand Up @@ -78,7 +78,7 @@ public function testSend()
public function testProductionProblems()
{
// Open to a place where we should not have write access.
$client = new PostHog_Client(
$client = new Client(
"BrpS4SctoaCCsyjlnlun3OzyNJAafdlv__jUWaaJWXg",
array(
"consumer" => "file",
Expand Down
2 changes: 1 addition & 1 deletion test/ConsumerForkCurlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ConsumerForkCurlTest extends PHPUnit\Framework\TestCase
public function setUp(): void
{
date_default_timezone_set("UTC");
$this->client = new PostHog_Client(
$this->client = new Client(
"OnMMoZ6YVozrgSBeZ9FpkC0ixH0ycYZn",
array(
"consumer" => "fork_curl",
Expand Down
2 changes: 1 addition & 1 deletion test/ConsumerLibCurlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ConsumerLibCurlTest extends PHPUnit\Framework\TestCase
public function setUp(): void
{
date_default_timezone_set("UTC");
$this->client = new PostHog_Client(
$this->client = new Client(
"BrpS4SctoaCCsyjlnlun3OzyNJAafdlv__jUWaaJWXg",
array(
"consumer" => "lib_curl",
Expand Down
12 changes: 6 additions & 6 deletions test/ConsumerSocketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function setUp(): void

public function testCapture()
{
$client = new PostHog_Client(
$client = new Client(
"BrpS4SctoaCCsyjlnlun3OzyNJAafdlv__jUWaaJWXg",
array(
"consumer" => "socket",
Expand All @@ -28,7 +28,7 @@ public function testCapture()

public function testIdentify()
{
$client = new PostHog_Client(
$client = new Client(
"BrpS4SctoaCCsyjlnlun3OzyNJAafdlv__jUWaaJWXg",
array(
"consumer" => "socket",
Expand All @@ -46,7 +46,7 @@ public function testIdentify()

public function testShortTimeout()
{
$client = new PostHog_Client(
$client = new Client(
"BrpS4SctoaCCsyjlnlun3OzyNJAafdlv__jUWaaJWXg",
array(
"timeout" => 0.01,
Expand All @@ -69,7 +69,7 @@ public function testShortTimeout()

public function testProductionProblems()
{
$client = new PostHog_Client("x",
$client = new Client("x",
array(
"consumer" => "socket",
"error_handler" => function () {
Expand All @@ -92,7 +92,7 @@ public function testLargeMessage()
"consumer" => "socket",
);

$client = new PostHog_Client("BrpS4SctoaCCsyjlnlun3OzyNJAafdlv__jUWaaJWXg", $options);
$client = new Client("BrpS4SctoaCCsyjlnlun3OzyNJAafdlv__jUWaaJWXg", $options);

$big_property = "";

Expand All @@ -112,7 +112,7 @@ public function testLargeMessage()
public function testConnectionError()
{
$this->expectException('RuntimeException');
$client = new PostHog_Client("x", array(
$client = new Client("x", array(
"consumer" => "socket",
"host" => "t.posthog.comcomcom",
"error_handler" => function ($errno, $errmsg) {
Expand Down
2 changes: 1 addition & 1 deletion test/PostHogTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

require_once __DIR__ . "/../lib/PostHog.php";
use Posthog;

class PostHogTest extends PHPUnit\Framework\TestCase
{
Expand Down