Skip to content

Commit

Permalink
Merge pull request #131 from Jakub-Fajkus/fix-phpgenerator-bc-break
Browse files Browse the repository at this point in the history
Fix NetteGenerator BC break
  • Loading branch information
Spamercz authored Mar 15, 2022
2 parents 7190f4e + 7d3e386 commit 98ec56a
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Events/DI/EventsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,12 @@ public function afterCompile(ClassTypeGenerator $class)
/** @hack This tries to add the event invokation right after the code, generated by NetteExtension. */
$foundNetteInitStart = $foundNetteInitEnd = FALSE;
$lines = explode(";\n", trim($init->getBody() ?: ''));
$init->setBody(NULL);
$init->setBody('');
while (($line = array_shift($lines)) !== NULL) {
if ($foundNetteInitStart && !$foundNetteInitEnd &&
stripos($line, 'Nette\\') === FALSE && stripos($line, 'set_include_path') === FALSE && stripos($line, 'date_default_timezone_set') === FALSE
) {
$init->addBody(GeneratorHelpers::format(
$init->addBody( (new \Nette\PhpGenerator\Dumper)->format(
'$this->getService(?)->createEvent(?)->dispatch($this);',
$this->prefix('manager'),
[DIContainer::class, 'onInitialize']
Expand All @@ -206,7 +206,7 @@ public function afterCompile(ClassTypeGenerator $class)
}

if (!$foundNetteInitEnd) {
$init->addBody(GeneratorHelpers::format(
$init->addBody( (new \Nette\PhpGenerator\Dumper)->format(
'$this->getService(?)->createEvent(?)->dispatch($this);',
$this->prefix('manager'),
[DIContainer::class, 'onInitialize']
Expand Down

0 comments on commit 98ec56a

Please sign in to comment.