Skip to content

Commit

Permalink
PostHog#3: Update composer.json to support PSR-4
Browse files Browse the repository at this point in the history
  • Loading branch information
wundo authored and adrienbrault committed Mar 31, 2021
1 parent 405465c commit 168c5b9
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 33 deletions.
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
18 changes: 8 additions & 10 deletions lib/PostHog/Client.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
<?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');
namespace Posthog;

class PostHog_Client {
use Posthog\Consumer\File;
use Posthog\Consumer\ForkCurl;
use Posthog\Consumer\LibCurl;
use Posthog\Consumer\Socket;

class Client {

/**
* Consumer object handles queueing and bundling requests to Posthog.
*
* @var \Posthog\Consumer
*/
protected $consumer;

/**
* Create a new posthog object with your app's API key
Expand All @@ -28,7 +26,7 @@ class PostHog_Client {
*/
public function __construct($apiKey, $options = array()) {
$consumers = array(
"socket" => "PostHog_Consumer_Socket",
"socket" => "Socket",
"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
6 changes: 5 additions & 1 deletion lib/PostHog/Consumer/Socket.php
Original file line number Diff line number Diff line change
@@ -1,6 +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

0 comments on commit 168c5b9

Please sign in to comment.