what is the "core" of symfony2? - symfony

the core seems to be everything beneath /vendor/symfony/src/Symfony.
There you have three folders:
/Bridge
/Bundle
/Component
What is the purpose of /Bridge and /Bundle?
Also am I right that core means actually two things?
the core library in /Component
the whole setup with caching of routes/config/templates, admin interface, ...

Symfony2 framework is made of: Components, Bridges, and Bundles.
A Component is a standalone library which can be used independently.
A Bridge is a set of classes from one component that extends another library/component. It has been created so components can stay as decoupled as possible. This is also here for a good reason: If you want to use the Form component but do not use Doctrine as an ORM, you don't care about the specific Type created for Doctrine.
A Bundle is a glue between components or Third-Party libraries. The glue of all these components and bridges that make the Symfony2 framework is the FrameworkBundle.
Then, you have the distributions. A distribution is a set of Bundles, third-party libraries and default configurations that makes the installation of Symfony2 really easy for a project.

Related

Symfony 4 and Microservices

Say I'm going to create few microservices: Alpha, Beta, Gamma.
In terms of Application structure using older Symfony version like 2, I'd create a bundle for each service, but bundles are no longer recommended in Symfony 4. So... Should I create separate repositories for every service or still create a bundles in a one App?
If you have different microservices, as in different applications, you will not need bundles. You can keep them in different repositories, but a common practice is to use a so called mono-repository. As the name suggests, with a mono-repository you keep all of the projects in a single repository. This has the benefit that changes spanning all projects can be done more easily and in sync. The drawback is that it requires more effort when managing and might cause additional overhead when building and deploying as it will not be easy to see which service has changed so must likely you rebuild all of them. There are a few books and presentations on mono-repositories you might want to check out. In short, Symfony does not restrict how you manage your services. You can have a single repository for all projects or multiple repositories.
If you want to serve all "services" through the same application, even without bundles, you can do so by using namespaces to separate the logic, e.g. for controllers:
my_app
- src
- Controller
- Alpha
- IndexController
- Beta
- IndexController
This should work out of the Box with the default configuration and even if you deviate you can make things like argument resolvers work by just pointing the configuration to the correct folder. Obviously this will require you to make sure that code is not shared between services should you ever want to extract them into their own application. There are some static code analyis tools that help you with keeping your architecture clean, i.e. make sure Alpha does not use code from Gamma and vice versa.
If you want to separate the apps more clearly by doing something like this:
my_app
- src
- AlphaApp
- ...
- BetaApp
- ...
You can still do that but it will require more manual work and the recipes will not work anymore, requiring you to do manual changes to most configurations and moving around files. How to do it depends on whether you want a shared kernel or a separate kernel for each service, but if you go that route I recommend keeping separate projects in the same repository, as it will probably yield cleaner results and be less work.
You can still create bundles in symfony4 though its not recommended by best practices. see https://symfony.com/doc/current/best_practices/creating-the-project.html

What is the difference between a bundle, component and a service in Symfony Framework?

What is a difference between bundle, component, service in Symfony? Thank you in advance
Bundle: A collection of code and other files written for use in a Symfony application.
http://symfony.com/doc/current/book/bundles.html
Component: Parts of the Framework that handle a certain task. They can also be used without the Framework.
http://symfony.com/doc/current/components/index.html
Service: Just a php class that provides certain functionality. It can be loaded through the Service Container which automatically handles dependencies.
http://symfony.com/doc/current/book/service_container.html
As I understand:
Components - standalone official libraries that can be used ether separately from Symfony framework or as a part of so called "Symfony-framework-skeleton". They are independent from other libraries.
Bundles - libraries that are additional to "core Symfony". They are dependent from Symfony components.
Services - libraries written by usual users for local projects that can be reused in different projects.
Service is any php class that has a relation with the dependency injection container, meaning that the container is able to manage it.
A component is a self contained entity that has usability even outside of a symfony based application, a library like PDO.
A bundle is symfony flex abstraction for providing simple modularity including configurations and automations.
So a bundle can be made out of a component.

About the default AppBundle in Symfony2

When creating a new SF2 project, the project contains an AppBundle by default. Should this be removed like the AcmeDemoBundle?
Symfony best practice
For most projects, you should store everything inside the AppBundle.
http://symfony.com/doc/current/best_practices/business-logic.html
Multiple bundles
I tend to create multiple bundles, e.g. I have these bundles in src/:
MyProjectEntityBundle
MyProjectBackendBundle
MyProjectHomePageBundle
And for reusable components I create a symfony bundle that I put into a git repository and load it via composer using satis. So for example I have some bundles in vendor/:
VendorCmsUtilBundle
VendorImageThumbnailBundle
"Domain Driven Design (DDD)"
I have yet to try this approach (I will soon):
http://williamdurand.fr/2013/08/07/ddd-with-symfony2-folder-structure-and-code-first/
As #Marcel Burkhard pointed out, the AppBundle is where you should put all your application logic according to Symfony best practices. Of course you can throw it away and build your own, but it's definitely not like the Acme Demo bundle.
I disagree with the strategy of splitting Entities and Frontend / Backend in different bundles.
I agree with the strategy of creating your own "utility" bundle(s) so that you can reuse your code in different projects via composer.

What are Modules in a project?

Hi i want to know what is meant by modules in a project??how they are classified and how many modules we can have in a project?can anyone explain with simple examples??What modules we can have in a typical online shopping website?
In .net context I believe one can draw 2 meanings not sure what specific you are looking for.
One is modular programming by following design principles like "Separation of concerns", "Single Responsibility", "loose coupling". This means divide you code into classes based on these principles and further group these classes again based on these principles into modules.
In ASP.NET or C# or in general we create class library projects and use them across the entire project. Like all the logging functionality is put in some classes and these classes are include in an class library project which can be called "Logging module". Whenever you need logging in any of the project you can include this module and use the functionality.
Some examples:
Web module for HTTP requests ( The WebApp)
Repository and Data access Layer modules. (DAL code)
Models module containing all the business entities.
WebService modules for integrating with other apps.
Logging for debugging and problem identification
Infrastructure/Utility modules for utility like functionalities and
application configuration.
Business logic modules.
Transaction gateway module.
Other way to define module in .net is they are PE files and I believe they have extension .netmodule which contain Metadata but they do not contain the assembly manifest. To use a module you have to create a PE file with the necessary assembly manifest.
Create a module:
csc /t:module ufo.cs
Create assembly using the module:
csc /t:library /addmodule:ufo.netmodule /out:airvehicles.dll helicopter.cs
Above 2 commands are from this link
The module is an external code that you plugin on your site and runs in order to do some actions.
(source: codeguru.com)
We make and use modules to have the ability to share the actions of the module with others with out giving the source code, and vice versa, we use modules from other that we do not have access to the source code. Or we can simple use module for have the ability so simplify our code and remove it easy if we do not need it.
We can have as modules as we like, but each module place extra overhead on our code - after all is need to make more thinks there.
More about modules: http://www.codeguru.com/csharp/.net/net_asp/article.php/c19389/HTTP-Handlers-and-HTTP-Modules-in-ASPNET.htm
How to create module: http://support.microsoft.com/kb/307996

Sensiolabs/Symfony duplicated components: Which ones should I use?

Pimple or Container?
http://pimple.sensiolabs.org/
http://components.symfony-project.org/dependency-injection/
Twig or Template?
http://twig.sensiolabs.org/
http://components.symfony-project.org/templating/
I'm not asking for an opinion, I just want to know this:
Why are these components being distributed with different names?
Which ones are newer?
Which are the ones being used by symfony 2 ?
Is there a list for components like Pimple and Twig? Like there is for Container and Template: http://components.symfony-project.org/
There are 3 categories of projects you have listed.
Third-party library. While provided by sensiolabs, these are standalone libraries not under the symfony namespace.
Old Symfony 1.x components, also standalone but under the Symfony namespace. Available at components.symfony-project.org, compatible with PHP 5.2.
Symfony2 components, part of the Symfony2 package, but can also be used standalone. Compatible with PHP 5.3+.
Ok, so let's categorize the projects you've listed.
Category 1
Pimple
Twig
There is currently no Pimple bundle for Symfony2. The recommended way to go with is to use the Symfony2 DependencyInjection component, which ships with the framework.
Note: Pimple is heavily used by Silex, so if you like Pimple, you might want to take a look at it. It's a different framework that is based on Symfony2 components.
Twig, on the other hand, is supported very well by the Symfony2 core framework. There is a core Bundle for it, and most of the documentation suggests you use it. It is definitely the recommended way to do templating in Symfony2.
For a list of more of these, take a look at Fabien Potencier's GitHub profile. IMO the important ones are: Twig, Silex, Pimple, Goutte, (Pirum, Sismo).
Category 2
Symfony Components DependencyInjection
Symfony Components Templating
These are old and should no longer be used.
Category 3
Symfony2 DependencyInjection Component
Symfony2 Templating Component
Symfony2 Twig Bundle
These are all part of the Symfony2 framework, and you should use them. They are the latest and greatest.
Hope that answers your questions!
I think that you could use http://components.symfony-project.org components if you have some kind of legacy project that uses php 5.2 or your server has php older than 5.3.
I have a project, I' m doing some rewriting, but it's legacy php 5.2 so I decited to use the old components (http://components.symfony-project.org) instead of new symfony's 2.0 components

Resources