Symfony2 è sicuramente uno dei framework migliori in circolazione, ma non sono tutte rose e fiori, soprattutto per chi inizia a sviluppare ed è alle prime armi. In questa presentazione vorrei condividere la mie esperienza di apprendimento ed utilizzo del framework, cercando di mettere in evidenza i miei momenti wtf e alcune linee guida per sviluppare applicazioni manutenibili
40. use DoctrineDBALTypesType;
use DoctrineDBALPlatformsAbstractPlatform;
/**
* NewObject datatype
*/
class NewObjectType extends Type
{
public function convertToPHPValue($value, AbstractPlatform $platform)
{
$listeners = $platform -> getEventManager() -> getListeners('getContainer');
$listener = array_shift($listeners);
$container = $listener -> getContainer();
return $container -> get('service');
}
}
if u can it doesn’t mean you have to
41. class A
{
protected $first_service;
protected $second_service;
public function __construct(ContainerInterface $container)
{
$this->first_service = $container->get(‘firstService’);
$this->second_service = $container->get(‘secondService’);
}
}
passing around the DIC is bad
42. class A
{
protected $first_service;
protected $second_service;
public function __construct(FirstService $first, SecondService $second)
{
$this->first_service = $first;
$this->second_service = $second;
}
}
in services.yml:
services:
my.service:
arguments:
- "@first_service"
- "@second_service"
class: MyClassA
passing around the DIC is bad