Twig in Silex from Symfony core - symfony

Is it possible to use Twig in Silex from Symfony2 project instead from the standalone bundle?
I already have Symfony integrated as submodule, so is it still necessary to use Twig alongside symfony in the vendor dir?
That would save me one submodule, i mean its no problem thou, i am just curious.
It would be great if i just would have to change the *twig.class_path* to some dir in symfony.
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => __DIR__.'/../views',
'twig.class_path' => __DIR__.'/../vendor/twig/lib',
));
I am a bit lost in symfony, there is some Twig in Bridges and some in Bundle, but first i need to know if its possible at all.

No, that is not possible.
There are following libraries in existence:
Twig - a standalone template engine for PHP.
TwigServiceProvider - integration between twig and silex, this is included with silex.
TwigBridge - a Symfony2 bridge which adds useful features to twig, allowing tighter integration with Symfony2
TwigBundle - a Symfony2 core bundle that provides integration between Symfony2 and twig, depends on the TwigBridge
As you can see, twig is not included with the Symfony2 core. It is an external dependency, that you have to tie in to Symfony2, and you also have to tie into silex.

Related

Can Symfony Bundle be used in non-Symfony project (f.e. Zend)?

Can I reuse my Bundle created in Symfony in non-Symfony project, f.e. Zend? (Or I only can reuse Components?)
What about services from that Bundle?
A Symfony bundle can certainly be included in with other projects, via a composer.json & composer.lock file - it doesn't mean that there is any useful code to run within that bundle however.
If there is useful code as part of the bundle, then you can use it directly, but a Symfony Bundle is just a library that will usually include some Symfony-specific configuration.
Best practice for a bundle is to put any useful, common code, into a separate library (which could be used independently - such as what Symfony calls a 'Component'), and then enable that code (for example creating Symfony services, or configuration) with the bundle configuration.
There have been projects that are Symfony bundles, and also have the configurations for other frameworks as well, such as Silex, and also appropriate Laravel configurations within the same codebase.

Doctrine uploadable extension in Symfony

I read this doc in order to understand how the doctrine uploadable extension works so I can use it in my Symfony projects.
The problem is at the usage example, where I see an object called $listener and I really can not figure out where does it come from.
I intend to use a similar piece of code in one of my controllers, but I don't know to instantiate that listener, or where to grab it from.
If you look into the github project in question, you can see that they have a documentation in how to install and use them with symfony 2:
Install Gedmo Doctrine2 extensions in Symfony2
And if you don't want to do the hard work, there is also a pre-made bundle:
Integration bundle for DoctrineExtensions by l3pp4rd in Symfony2 (documentation)
Please note that while the bundle should be easier to install, it is made by a third party, not by the extensions developer, and it might not be as up to date.

Location of propel.ini for symfony2?

I am migrating from symfony1 to symfony2, I have hard time implementing propel behaviors. Where do I actually have the propel.ini in symfony2?
Well in sf1.4, it was inside root config directory. How about symfony2?
The Propel ORM Symfony2 page says this:
You can add a app/config/propel.ini file in your project to specify some configuration parameters. ... However, the recommended way to configure Propel is to rely on build properties.
You can define build properties by creating a propel.ini file in app/config like below, but you can also follow the Symfony2 convention by adding build properties in app/config/config.yml
So I believe you can come close to the Symfony1 behaviour by creating app/config/propel.ini, but the more idiomatic way is to use app/config/config.yml as that page illustrates.
Caveat: I haven't used Propel with Symfony2, so this answer is solely based on the manual.

Create a bundle in vendors in Symfony2

I am trying to create a bundle in vendors in Symfony2.
MyBundle(MineUserBundle) needs to inherit other two bundle in vendors FOSUserBundle and HWIOAuthBundle.
How to get inherit both bundles properties, templates etc in Mybundle?
vendors
FOSUserBundle
HWIOAuthBundle
MineUserBundle
Here MineUserBundle needs to have all features of other two bundle.
How to get the process work?
Since you are using namespaces it does not mater into which folder you are going to deploy your Bundle. Just include use statements in your bundle with ones you need:
use Path\To\FOS\UserBundle;
use Path\ToHWIO\AuthBundle;
And you can extend whatever you need.
But if you really want to install your bundle to vendor directory, then you have to configure define it in your deps file.
[YourVendorYouBundle]
git=git#github.com:yourRepository/YourVendorYouBundle.git
target=/bundles/YourVendor/YouBundle

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