Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Commit

Permalink
changed namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
michel-pi committed Nov 11, 2019
1 parent a29c0d7 commit a441c00
Show file tree
Hide file tree
Showing 25 changed files with 132 additions and 129 deletions.
16 changes: 8 additions & 8 deletions src/Components/Endpoints/CosmeticsEndpoint.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

namespace MichelPi\FortniteApi\Components\Endpoints;

use MichelPi\FortniteApi\Components\HttpClient;
use MichelPi\FortniteApi\Components\Objects\Cosmetic;
use MichelPi\FortniteApi\Components\Tasks\CosmeticArrayTask;
use MichelPi\FortniteApi\Components\Tasks\CosmeticTask;
use MichelPi\FortniteApi\FortniteApi;
use MichelPi\FortniteApi\FortniteApiError;
namespace FortniteApi\Components\Endpoints;

use FortniteApi\Components\HttpClient;
use FortniteApi\Components\Objects\Cosmetic;
use FortniteApi\Components\Tasks\CosmeticArrayTask;
use FortniteApi\Components\Tasks\CosmeticTask;
use FortniteApi\FortniteApi;
use FortniteApi\FortniteApiError;

/**
* Provides access to the /cosmetics/ endpoint
Expand Down
12 changes: 6 additions & 6 deletions src/Components/Endpoints/NewsEndpoint.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

namespace MichelPi\FortniteApi\Components\Endpoints;
namespace FortniteApi\Components\Endpoints;

use MichelPi\FortniteApi\Components\HttpClient;
use MichelPi\FortniteApi\Components\Tasks\NewsEntryTask;
use MichelPi\FortniteApi\Components\Tasks\NewsTask;
use MichelPi\FortniteApi\FortniteApi;
use MichelPi\FortniteApi\FortniteApiError;
use FortniteApi\Components\HttpClient;
use FortniteApi\Components\Tasks\NewsEntryTask;
use FortniteApi\Components\Tasks\NewsTask;
use FortniteApi\FortniteApi;
use FortniteApi\FortniteApiError;

/**
* Provides access to the /news/ endpoint.
Expand Down
10 changes: 5 additions & 5 deletions src/Components/Endpoints/ShopEndpoint.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace MichelPi\FortniteApi\Components\Endpoints;
namespace FortniteApi\Components\Endpoints;

use MichelPi\FortniteApi\Components\HttpClient;
use MichelPi\FortniteApi\Components\Tasks\ShopTask;
use MichelPi\FortniteApi\FortniteApi;
use MichelPi\FortniteApi\FortniteApiError;
use FortniteApi\Components\HttpClient;
use FortniteApi\Components\Tasks\ShopTask;
use FortniteApi\FortniteApi;
use FortniteApi\FortniteApiError;

/**
* Provides access to the /shop/ endpoint.
Expand Down
4 changes: 2 additions & 2 deletions src/Components/HttpClient.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace MichelPi\FortniteApi\Components;
namespace FortniteApi\Components;

use GuzzleHttp\Client;
use MichelPi\FortniteApi\Config\Config;
use FortniteApi\Config\Config;

class HttpClient
{
Expand Down
2 changes: 1 addition & 1 deletion src/Components/JsonSerializer.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace MichelPi\FortniteApi\Components;
namespace FortniteApi\Components;

class JsonSerializer
{
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Objects/Cosmetic.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace MichelPi\FortniteApi\Components\Objects;
namespace FortniteApi\Components\Objects;

use Exception;
use MichelPi\FortniteApi\Components\Objects\Reflection\Activator;
use FortniteApi\Components\Objects\Reflection\Activator;

class Cosmetic
{
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Objects/Image.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace MichelPi\FortniteApi\Components\Objects;
namespace FortniteApi\Components\Objects;

use Exception;
use MichelPi\FortniteApi\Components\Objects\Reflection\Activator;
use FortniteApi\Components\Objects\Reflection\Activator;

class Image
{
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Objects/News.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace MichelPi\FortniteApi\Components\Objects;
namespace FortniteApi\Components\Objects;

use Exception;
use MichelPi\FortniteApi\Components\Objects\Reflection\Activator;
use FortniteApi\Components\Objects\Reflection\Activator;

class News
{
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Objects/NewsEntry.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace MichelPi\FortniteApi\Components\Objects;
namespace FortniteApi\Components\Objects;

use Exception;
use MichelPi\FortniteApi\Components\Objects\Reflection\Activator;
use FortniteApi\Components\Objects\Reflection\Activator;

class NewsEntry
{
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Objects/NewsMessage.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace MichelPi\FortniteApi\Components\Objects;
namespace FortniteApi\Components\Objects;

use Exception;
use MichelPi\FortniteApi\Components\Objects\Reflection\Activator;
use FortniteApi\Components\Objects\Reflection\Activator;

class NewsMessage
{
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Objects/Option.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace MichelPi\FortniteApi\Components\Objects;
namespace FortniteApi\Components\Objects;

use Exception;
use MichelPi\FortniteApi\Components\Objects\Reflection\Activator;
use FortniteApi\Components\Objects\Reflection\Activator;

class Option
{
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Objects/Reflection/Activator.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace MichelPi\FortniteApi\Components\Objects\Reflection;
namespace FortniteApi\Components\Objects\Reflection;

use MichelPi\FortniteApi\Components\JsonSerializer;
use FortniteApi\Components\JsonSerializer;

class Activator
{
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Objects/Shop.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace MichelPi\FortniteApi\Components\Objects;
namespace FortniteApi\Components\Objects;

use Exception;
use MichelPi\FortniteApi\Components\Objects\Reflection\Activator;
use FortniteApi\Components\Objects\Reflection\Activator;

class Shop
{
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Objects/ShopEntry.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace MichelPi\FortniteApi\Components\Objects;
namespace FortniteApi\Components\Objects;

use Exception;
use MichelPi\FortniteApi\Components\Objects\Reflection\Activator;
use FortniteApi\Components\Objects\Reflection\Activator;

class ShopEntry
{
Expand Down
119 changes: 61 additions & 58 deletions src/Components/Objects/Variant.php
Original file line number Diff line number Diff line change
@@ -1,76 +1,79 @@
<?php

namespace MichelPi\FortniteApi\Components\Objects;
namespace FortniteApi\Components\Objects\Reflection;

use Exception;
use MichelPi\FortniteApi\Components\Objects\Reflection\Activator;
use FortniteApi\Components\JsonSerializer;

class Variant
class Activator
{
/**
* Undocumented variable
*
* @var Activator
*/
private static $_activator;

/**
* Undocumented variable
*
* @var null|string
*/
public $type;
/**
* Undocumented variable
*
* @var null|Option[]|array
*/
public $options;

public static function createObject($body)
{
return self::getActivator()->createObjectFromBody($body);
}
private $activator;
private $initializer;

public static function createObjectArray($body)
public function __construct($activator, $initializer)
{
return self::getActivator()->createArrayFromBody($body);
$this->activator = $activator;
$this->initializer = $initializer;
}

/**
* Undocumented function
*
* @param Variant $obj
* @param array|mixed $body
* @return bool
*/
private static function initializeObject(&$obj, &$body)
public function createObjectFromBody($body)
{
try {
$obj->type = $body["type"];
$obj->options = Option::createObjectArray($body["options"]);

return true;
} catch (Exception $ex) {
return false;
if (empty($body)) {
return null;
}

if (is_string($body)) {
$body = JsonSerializer::deserialize($body);

if ($body === false) {
return null;
}
}

if (array_key_exists("status", $body) && array_key_exists("data", $body)) {
$body = $body["data"];
}

$obj = call_user_func($this->activator);

if (call_user_func_array($this->initializer, array(&$obj, &$body))) {
return $obj;
} else {
return null;
}
}

/**
* Undocumented function
*
* @return Activator
*/
private static function getActivator()
public function createArrayFromBody($body)
{
if (empty(self::$_activator)) {
self::$_activator = new Activator(function () {
return new Variant();
}, function (&$obj, &$body) {
return self::initializeObject($obj, $body);
});
if (empty($body)) {
return null;
}

return self::$_activator;
if (is_string($body)) {
$body = JsonSerializer::deserialize($body);

if ($body === false) {
return null;
}
}

if (array_key_exists("status", $body) && array_key_exists("data", $body)) {
$body = $body["data"];
}

$result = [];

foreach ($body as $item) {
$obj = call_user_func($this->activator);

if (call_user_func_array($this->initializer, array(&$obj, &$item))) {
$result[] = $obj;
}
}

if (count($result) == 0) {
return null;
} else {
return $result;
}
}
}
2 changes: 1 addition & 1 deletion src/Components/Tasks/Awaitable.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace MichelPi\FortniteApi\Components\Tasks;
namespace FortniteApi\Components\Tasks;

use GuzzleHttp\Promise\Promise;

Expand Down
8 changes: 4 additions & 4 deletions src/Components/Tasks/CosmeticArrayTask.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace MichelPi\FortniteApi\Components\Tasks;
namespace FortniteApi\Components\Tasks;

use Exception;
use MichelPi\FortniteApi\Components\HttpClient;
use MichelPi\FortniteApi\Components\Objects\Cosmetic;
use MichelPi\FortniteApi\FortniteApiError;
use FortniteApi\Components\HttpClient;
use FortniteApi\Components\Objects\Cosmetic;
use FortniteApi\FortniteApiError;
use Psr\Http\Message\ResponseInterface as Response;

class CosmeticArrayTask extends Awaitable
Expand Down
8 changes: 4 additions & 4 deletions src/Components/Tasks/CosmeticTask.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace MichelPi\FortniteApi\Components\Tasks;
namespace FortniteApi\Components\Tasks;

use Exception;
use MichelPi\FortniteApi\Components\HttpClient;
use MichelPi\FortniteApi\Components\Objects\Cosmetic;
use MichelPi\FortniteApi\FortniteApiError;
use FortniteApi\Components\HttpClient;
use FortniteApi\Components\Objects\Cosmetic;
use FortniteApi\FortniteApiError;
use Psr\Http\Message\ResponseInterface as Response;

class CosmeticTask extends Awaitable
Expand Down
8 changes: 4 additions & 4 deletions src/Components/Tasks/NewsEntryTask.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace MichelPi\FortniteApi\Components\Tasks;
namespace FortniteApi\Components\Tasks;

use Exception;
use MichelPi\FortniteApi\Components\HttpClient;
use MichelPi\FortniteApi\Components\Objects\NewsEntry;
use MichelPi\FortniteApi\FortniteApiError;
use FortniteApi\Components\HttpClient;
use FortniteApi\Components\Objects\NewsEntry;
use FortniteApi\FortniteApiError;
use Psr\Http\Message\ResponseInterface as Response;

class NewsEntryTask extends Awaitable
Expand Down
8 changes: 4 additions & 4 deletions src/Components/Tasks/NewsTask.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace MichelPi\FortniteApi\Components\Tasks;
namespace FortniteApi\Components\Tasks;

use Exception;
use MichelPi\FortniteApi\Components\HttpClient;
use MichelPi\FortniteApi\Components\Objects\News;
use MichelPi\FortniteApi\FortniteApiError;
use FortniteApi\Components\HttpClient;
use FortniteApi\Components\Objects\News;
use FortniteApi\FortniteApiError;
use Psr\Http\Message\ResponseInterface as Response;

class NewsTask extends Awaitable
Expand Down
Loading

0 comments on commit a441c00

Please sign in to comment.