Skip to content

Commit

Permalink
load from base64
Browse files Browse the repository at this point in the history
  • Loading branch information
saeedvaziry committed Feb 25, 2025
1 parent 1e0e85f commit bd99c91
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ class Loader
/**
* @return null|LoaderInterface
*/
public static function load(string $path, ?string $loaderPath = null)
public static function load(string $path, ?string $encodedLoader = null)
{
if ($loaderPath !== null) {
$loaderClass = self::getLoaderClassFromPath($loaderPath);
if ($encodedLoader !== null) {
$loaderClass = self::getLoaderClassFrom($encodedLoader);

if ($loaderClass !== null) {
return new $loaderClass($path);
Expand Down Expand Up @@ -47,20 +47,13 @@ public static function load(string $path, ?string $loaderPath = null)
return null;
}

private static function getLoaderClassFromPath(string $path)
private static function getLoaderClassFrom(string $encodedLoader)
{
if (! file_exists($path)) {
return null;
}

$declaredClassesBefore = get_declared_classes();

require_once $path;

$loader = base64_decode($encodedLoader);
eval(str_replace('<?php', '', $loader));
$declaredClassesAfter = get_declared_classes();

$newClasses = array_diff($declaredClassesAfter, $declaredClassesBefore);

if (empty($newClasses)) {
return null;
}
Expand Down
5 changes: 5 additions & 0 deletions src/Loaders/BaseLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ public function casters(): array
{
return [];
}

public static function supports(string $path): bool
{
return false;
}
}

0 comments on commit bd99c91

Please sign in to comment.