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

Commit

Permalink
???
Browse files Browse the repository at this point in the history
  • Loading branch information
michel-pi committed Nov 11, 2019
1 parent a441c00 commit f426acf
Showing 1 changed file with 58 additions and 61 deletions.
119 changes: 58 additions & 61 deletions src/Components/Objects/Variant.php
Original file line number Diff line number Diff line change
@@ -1,79 +1,76 @@
<?php

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

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

class Activator
class Variant
{
private $activator;
private $initializer;

public function __construct($activator, $initializer)
/**
* 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)
{
$this->activator = $activator;
$this->initializer = $initializer;
return self::getActivator()->createObjectFromBody($body);
}

public function createObjectFromBody($body)
public static function createObjectArray($body)
{
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;
}
return self::getActivator()->createArrayFromBody($body);
}

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

return true;
} catch (Exception $ex) {
return false;
}
}

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;
}
/**
* Undocumented function
*
* @return Activator
*/
private static function getActivator()
{
if (empty(self::$_activator)) {
self::$_activator = new Activator(function () {
return new Variant();
}, function (&$obj, &$body) {
return self::initializeObject($obj, $body);
});
}

if (count($result) == 0) {
return null;
} else {
return $result;
}
return self::$_activator;
}
}

0 comments on commit f426acf

Please sign in to comment.