8000 feature #11951 New php library structure made easier (pyrech) · symfony/symfony@108f929 · GitHub
[go: up one dir, main page]

Skip to content

Commit 108f929

Browse files
committed
feature #11951 New php library structure made easier (pyrech)
This PR was merged into the 2.6-dev branch. Discussion ---------- New php library structure made easier | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - [This article](https://medium.com/@christophewillemsen/stop-making-bundles-think-bundles-deadd27b88c0) from @ikwattro gives some good ideas on how to ease the creation of a PHP package: - which is not a bundle usable only on a symfony full stack framework - without requiring to maintain 2 repos (one for the lib and the other for the bundle) The only drawback is that Symfony requires the DI extension to be on a given location. So I created a new method Bundle#getContainerExtensionClass than can be easily overwritten if you want to move the Extension class in another directory. Commits ------- 8eda6b5 New php library structure made easier
2 parents 240648d + 8eda6b5 commit 108f929

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/Symfony/Component/HttpKernel/Bundle/Bundle.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,12 @@ public function build(ContainerBuilder $container)
7272
public function getContainerExtension()
7373
{
7474
if (null === $this->extension) {
75-
$basename = preg_replace('/Bundle$/', '', $this->getName());
76-
77-
$class = $this->getNamespace().'\\DependencyInjection\\'.$basename.'Extension';
75+
$class = $this->getContainerExtensionClass();
7876
if (class_exists($class)) {
7977
$extension = new $class();
8078

8179
// check naming convention
80+
$basename = preg_replace('/Bundle$/', '', $this->getName());
8281
$expectedAlias = Container::underscore($basename);
8382
if ($expectedAlias != $extension->getAlias()) {
8483
throw new \LogicException(sprintf(
@@ -197,4 +196,16 @@ public function registerCommands(Application $application)
197196
}
198197
}
199198
}
199+
200+
/**
201+
* Returns the bundle's container extension class.
202+
*
203+
* @return string
204+
*/
205+
protected function getContainerExtensionClass()
206+
{
207+
$basename = preg_replace('/Bundle$/', '', $this->getName());
208+
209+
return $this->getNamespace().'\\DependencyInjection\\'.$basename.'Extension';
210+
}
200211
}

0 commit comments

Comments
 (0)
0