-
-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automatically load services in the src/ directory #1165
Conversation
This one is up for discussion, because I do not think that we should add any autoloading/autowiring magic besides the existing, well known and well documented Symfony defaults that you can enable in your |
What do you think about adding a pre-configured |
Where did you suggest this? |
Here: contao/managed-edition#42 I accidentally opened it in the wrong repository back then. |
I like it better. 🙈 |
That won't work. If there is no |
But implementing contao/managed-edition#42 is actually the point of this PR 😉 |
True, but the skeleton could also contain a That being said, I think I am more in favor of this PR now 😁
👍
Personally, in my projects, I use the ADR pattern and regular dependency injection via constructor and thus and only include the following: App\Action\:
resource: ../src/Action
public: true namespace App\Action\ExampleAction;
use Doctrine\DBAL\Connection;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route("/example")
*/
class ExampleAction
{
private $db;
public function __construct(Connection $db)
{
$this->db = $db;
}
public function __invoke(Request $request): Response
{
return new Response('Hello World!');
}
} No tags needed. Service only needs to be public. May be you could add that? This way is also described in the getting started section of the documentation currently 😁 |
...er-bundle/tests/Fixtures/HttpKernel/WithMixedNamespace/src/EventListener/InvalidListener.php
Show resolved
Hide resolved
@@ -216,6 +216,10 @@ public function registerContainerConfiguration(LoaderInterface $loader): void | |||
if ($servicesFile = $this->getConfigFile('services.yml')) { | |||
$loader->load($servicesFile); | |||
} | |||
|
|||
if (is_dir($this->getProjectDir().'/src')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition is also true when unit testing the manager-bundle separately, therefore the bundles test fails: https://github.com/contao/contao/pull/1165/checks?check_run_id=393653023#step:4:888
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When testing the bundle selaratey, its dependencies should still be installed? So core-bundle should be there as well as SecurityBundle ??
Thank you @aschempp. |
This will finally add automatic autoloading for classes in the src folder. Due to Symfony's handling, it's a little bit complex. Here's how it works:
App\
service definition is available (e.g. in theconfig/services.yml
)autoload.php
and not a YAML file.App\
namespace in thesrc/
folder, but probably something else (e.g.src/AppBundle/…
). Then remove all services and ignore all errors.We might discuss whether we want to automatically tag controllers like Symfony does: https://github.com/symfony/recipes/blob/master/symfony/framework-bundle/4.2/config/services.yaml#L22
I don't really see that point though, you can either extend
AbstractController
or tag the service yourself through annotations – something that's possible in Contao but not in Symfony (thanks to the ServiceAnnotationBundle 😉 )This PR is complemented by contao/manager-plugin#22 which makes sure the
App\
namespace is always registered in Composer. That's already the case for all regular managed edition because it was in the distributioncomposer.json
, but it shouldn't be necessary to work.