This repository has been archived by the owner on Apr 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
132 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?php | ||
|
||
namespace MichelPi\FortniteApi\Components; | ||
namespace FortniteApi\Components; | ||
|
||
class JsonSerializer | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.