-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
Merlin
committed
Mar 16, 2024
1 parent
613ead1
commit c582cf5
Showing
6 changed files
with
108 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
namespace Brick\VarExporter; | ||
|
||
final class Code implements CodeInterface { | ||
|
||
/** | ||
* @var string[] | ||
*/ | ||
private array $lines; | ||
|
||
/** | ||
* @param string[] $lines | ||
*/ | ||
private function __construct(array $lines) { | ||
$this->lines = $lines; | ||
} | ||
|
||
public static function create(string ...$lines): self { | ||
return new self($lines); | ||
} | ||
|
||
public function toLines(): array | ||
{ | ||
return $this->lines; | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
namespace Brick\VarExporter; | ||
|
||
interface CodeInterface { | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function toLines(): array; | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Brick\VarExporter\Internal\ObjectExporter; | ||
|
||
use Brick\VarExporter\Internal\ObjectExporter; | ||
use Brick\VarExporter\CodeInterface; | ||
|
||
/** | ||
* Handles instances of LiteralInterface. | ||
* | ||
* @internal This class is for internal use, and not part of the public API. It may change at any time without warning. | ||
*/ | ||
final class CodeExporter extends ObjectExporter | ||
{ | ||
|
||
public function supports(\ReflectionObject $reflectionObject): bool | ||
{ | ||
return $this->exporter->allowCode | ||
&& $reflectionObject->implementsInterface(CodeInterface::class); | ||
} | ||
|
||
public function export(object $object, \ReflectionObject $reflectionObject, array $path, array $parentIds): array | ||
{ | ||
assert($object instanceof CodeInterface); | ||
return $object->toLines(); | ||
} | ||
|
||
} |
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