Create Runtime Code #160
Unanswered
designermonkey
asked this question in
Q&A
Replies: 2 comments 1 reply
-
I was testing this with: <?php declare(strict_types=1);
namespace Demo;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
#[CoversClass(Config::class)]
class ConfigTest extends TestCase
{
public function testThatConfigClassIsLoadedFromEnvArray(): void
{
$env = array_change_key_case(
parse_ini_file(__DIR__ . '/../.env.example'),
CASE_LOWER
);
$subject = new Config(...$env);
$this->assertSame(1025, $subject->smtp_port);
}
} for example. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hello! How can such a class be useful at all? Why would you want to create such a class dynamically? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I would like to experiment with using this to create a Config class at runtime based on a
.env
file for example.I don't know enough about autoloaders and composer to make much progress, so I'm wondering if anyone has ideas?
Here's what I've got so far:
I'm trying to make it so that when composer tries to autoload the Config class, it loads this file which in turn loads this autoloader, loads the class, then unloads the autoloader.
Is this even possible?
Beta Was this translation helpful? Give feedback.
All reactions