Skip to content

Commit 8e63a27

Browse files
committed
Don't override existing aliases for Form and Html
Some other packages register the same Form or Html aliases, but use different identifiers for the class within the IOC. This commit adds a check for whether there is already an existing facade aliased so it does not overwrite them
1 parent a7c79ed commit 8e63a27

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

src/Kris/LaravelFormBuilder/FormBuilderServiceProvider.php

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,13 @@ private function registerFormIfHeeded()
7777
return $form->setSessionStore($app['session.store']);
7878
});
7979

80-
AliasLoader::getInstance()->alias(
81-
'Form',
82-
'Illuminate\Html\FormFacade'
83-
);
80+
if (! $this->aliasExists('Form')) {
81+
82+
AliasLoader::getInstance()->alias(
83+
'Form',
84+
'Illuminate\Html\FormFacade'
85+
);
86+
}
8487
}
8588
}
8689

@@ -95,10 +98,24 @@ private function registerHtmlIfNeeded()
9598
return new HtmlBuilder($app['url']);
9699
});
97100

98-
AliasLoader::getInstance()->alias(
99-
'Html',
100-
'Illuminate\Html\HtmlFacade'
101-
);
101+
if (! $this->aliasExists('Html')) {
102+
103+
AliasLoader::getInstance()->alias(
104+
'Html',
105+
'Illuminate\Html\HtmlFacade'
106+
);
107+
}
102108
}
103109
}
110+
111+
/**
112+
* Check if an alias already exists in the IOC
113+
* @param $alias
114+
* @return bool
115+
*/
116+
private function aliasExists($alias)
117+
{
118+
return array_key_exists($alias, AliasLoader::getInstance()->getAliases());
119+
}
120+
104121
}

0 commit comments

Comments
 (0)