Confused with symfony2 bundles - php

I am little bit confused with symfony2 bundles.
I want to know that does everything in symfony is bundle including main application.
I was thinking as Core of site is somewhere i can write code to use bundles like we use plugins from main application code.
Or there is no core thing in Symfony . The core itself will be bundle

you can define your website completely as a bundle, meaning
Mycompany/MywebsiteBundle
Or you can define the different, sections of your website as different bundle, which i personally preffer
`Mycompany/ForumBundle
Mycompany/BlogBundle
Mycompany/NewsletterBundle`

Symfony2 is bundle-based framework
=> So, everything, as well as the core itself is a bundle.
You can see which bundle is loaded by default in app/AppKernel.php.
But Symfony2 does also include a library, organized by "components (vendor/symfony/src/Symfony/Components). Code in bundle can use this library..

Indeed, everything is a bundle. As per Symfony2 docs:
http://symfony.com/doc/2.0/book/page_creation.html#page-creation-bundles

Related

Symfony: Organising multi-client application’s business logic

Problem:
I’m unsure how to set up multi client application for Symfony so that we would not violate Symfony's best practices and work against the framework.
I would like to have one main Core namespace which would contain all the base model classes. Right next to the core I would like to set up client specific namespaces which would be used, based on client regional setting. For example LocalUS for US market, LocalUK, for UK market etc.
The Local* namespaces should take first priority for including twig templates, and as a fallback use core common shared views (as I understand, this is solvable via twig namespaces). Same goes for controllers and models - these are probably solvable via extending the Core namespaced classes? Is this all solvable via routing and providing paths for these Local* controllers?
I was looking up on github to see if there are any project that have similar setup but I couldn’t find anything.
A little background:
We have an older legacy PHP Application which was built in-house from ground up using plain PHP. As the application has grown over time, it has become hard to maintain good code quality and standards. It’s also very time consuming to teach new developers our application logic, since the application basically follows no standard design patterns and just does it’s own thing. A lot of the underlying code which handles routes, controllers etc seems to work like “magic” that nobody really dares to touch.
It is because of that we would like to migrate our application to Symfony3 framework. I’ve read some articles about the overall process of migrating legacy applications to symfony, and managed to do it with silex pretty well. Silex, however is a bit too lightweight, I found that the assetic service provider had a lot of functionality missing (twig namespacing etc), and decided it would be best if we could move to a full stack symfony framework instead.
Look into Symfony bundles - they do exactly what you need. You create a "base" bundle, than extend it with other bundles. That's how FOSUserBundle works - it provides everything you need, than you extend it and overwrite it.

Which php framework has module/bundle/whatever-reusable-package extending as default?

Right now I find out that extending modules in CodeIgniter framework using MX HMVC is very bad and not supported by default and I have a custom function in MY_Controller and you need to make a "hack"..the main point is it doesn't work good.
My question is if CodeIgniter didn't offer extending modules with other modules e.g. Drupal way of modules. Where e.g. you have core Views module and than module for extending Views so you can have Slideshow as a view and then another that add something else to the slideshow and every module use something from previous module in hierarchy like:
Views -> Views Slideshow -> Views Slideshow Extended
Which PHP frameworks has this "extending" ability in modular way. I am not looking for extensions of classic MVC controllers/models like:
class Views Slideshow extends Views {...
I need a PHP framework that have in mind extending of modules/bundles/whatever-packages
I have a hard time with CodeIgniter so I am looking for some other framework that is capable of this within a core. Thanks for your help.
Symfony2 definitely have this in mind, as everything is a Bundle. Even the framework is a Bundle.
You can pretty much overload almost everything in Symfony2, given that you use the service container instead of hard dependencies. Be careful that this might introduce some complexity (the price of the overloading feature). Also you can reduce complexity (and learning curve), as using the service container is not mandatory.
Please take a look at the documentation of Symfony2: Architecture, and more specifically the Understanding the bundle system

Why should not a Symfony2 bundle embed third-party libraries

Bundle Structure and Best Practices:
A bundle should not embed third-party libraries written in JavaScript,
CSS, or any other language.
Why shouldn't i create for example a bootstrap, or jQuery bundle?
I think it would be easier to maintain if all third-party CSS and JavaScript libraries live in their own bundle.
Well, for one, It's counter-intuitive. Symfony Bundles are for packages of PHP functionality and you're talking about bundling up front-end libraries.
Secondly - why would it be easier? Things like bootstrap and jQuery are public resources to begin with - they don't need a distributable bundle to achieve high re-use. PHP resources are not public and therefore benefit from this type of system.
The chaos comes when two or more bundles uses the same 3rd party library but different versions. A user of your bundle won't be able to choose which library to include and therefore can't use both bundles at the time.
It's fine to store them in a bundle folder if your bundle is a standalone application, i.e. your application's main bundle. For example, SonataAdminBundle includes 3rd party libraries: bootstrap.css, qtip, famfamfam icons.
look at MopaBootstrapBundle https://github.com/phiamo/MopaBootstrapBundle it integrates TwitterBootstrap & jQuery lib for you, also HTML5BoilerPlate if you enable initializr addon.

how to best structure application in symfony 2

I started using Symfony 2 after having experience with 5 php frameworks like Zend, CodeIgniter, Fuel, Yii and Cake. I am very confused on how to structure my project as better as I can. First of all I am confused in working with bundles. Bundles are some kind of modules used in other frameworks? Bascially I have my application and everything until now is stored in a bundles. If I want to make some helper functions and some libraries and abstract classes, I just make a new bundle for those?
See the Bundle Structure and Best Practices cookbook entry for basic ideas on the structure of a bundle.
I recommend having just one app specific bundle. I call it AppBundle.
Also, you don't have to have everything in bundles. Check this question for details.
Lots of other discussions on that matter:
Should everything really be a bundle on Symfony 2?
Confused with symfony2 bundles

Symfony2 Bundle System

I'm just working through the Symfony2 Bible and I'm a little stuck on the bundle system. It is a great feature but I'm not quite sure how to split my flat PHP application into bundles. It's my first time splitting my PHP code into a full featured MVC framework.
I'm working on a few online games (based on PHP) but how would I define the bundles ? Is it like one single onlinegame1 bundle with all the controllers and functions - Or like a login bundle, a register bundle, a war bundle - summarized one bundle for every single PHP file I got ?
I want to start clean and correct but I'm not quite sure if I understand that feature.
You could think of bundle as an independent reusable component - in most of the cases at least.
Let's imagine a personal blog website. I'd split it into ArticleBundle, UserBundle, CommentBundle and finally MainBundle which would stick all these other bundles together, creating your website. The main point is that you can take for example ArticleBundle and reuse it easily on other project without it being tied to any other bundle.
From Symfony2 book:
A bundle is similar to a plugin in other software, but even better.
The key difference is that everything is a bundle in Symfony2,
including both the core framework functionality and the code written
for your application. Bundles are first-class citizens in Symfony2.
This gives you the flexibility to use pre-built features packaged in
third-party bundles or to distribute your own bundles. It makes it
easy to pick and choose which features to enable in your application
and to optimize them the way you want.

Categories