What is the difference between a Symfony2 bundle vs a PSR-0 compatible 3rd party library?

StackOverflow https://stackoverflow.com/questions/11530084

  •  21-06-2021
  •  | 
  •  

Domanda

I understand that a bundle should contain the directory structure and other conventions outlined in the best practices documentation.

I still fail to see why I should choose between installing a library as a bundle or just installing a PSR-0 compatible library "as is" in a Symfony2 installation.

For instance, I want to install the Guzzle Http Client library. Currently I have two versions to choose from:

I can see that the bundle uses the library but since I am new to Symfony2, I can't yet grasp the 'big picture'. Can someone help me out?

È stato utile?

Soluzione

Using the bundle instead of the library will allow you to access the library from the ServiceContainer.

This will allow you to easily call the library; for instance in a Controller:

<?php
public function someAction(){
    // ...
    $guzzle = $this->get('guzzle.service_builder');
    // ...
}

check out http://symfony.com/doc/current/book/service_container.html

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top