简体   繁体   中英

Symfony 2 reusable bundles

Let's say I want to create a Blog in Symfony which lives in BlogBundle . But this BlogBundle has dependencies on other bundles like FOSUserBundle, KnpPaginator bundle, FMBbCodeBundle or whatever I end up using. Does this mean I can't really reuse the BlogBundle in another project. The Best Practices for Reusable Bundles chapter of the symfony cookbook says

A bundle must not embed third-party PHP libraries. It should rely on the standard Symfony autoloading instead.

But what does that mean exactly? Can't I use anything that isn't programmed by me?

If that is the case, I'd have to reinvent the wheel for the most basic problems I encounter in developing my bundle. For example I would have to come up with my own paginator to paginate content, create my own user manager and so on.. I don't see a point in that as I would waste my time fixing problems that have already been done much better than I could do.

Or does the cookbook mean I can't use anything that doesn't live inside a bundle. This would make much more sense to me.

It really irritates me that nobody really has done a blogbundle or something similar that gets good feedback and is mentioned anywhere in the top lists. I know, Symfony isn't meant to have a solution that just works out of the box and some coding is necessary, but still. All the bundles I can find that seem to be very popular are the ones that do something like parse BB Code, take care of User Management and other things that are hard and tedious to do, but never something bigger than doing only one task.

I hope you understand what I mean and can help me with my problem. Thanks in advance!

A bundle must not embed third-party PHP libraries. It should rely on the standard Symfony autoloading instead.

This means that you shouldn't copy code of other libraries to your Bundle (directory). Instead that you should add them as a dependencies to your composer.json .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM