Edit: questo post è stato superato dalla pubblicazione di questa guida. Viene lasciato sul blog per motivi storici, ma si consiglia di seguire quanto spiegato nella guida suddetta.
Sappiamo che Symfony2 predilige l’utilizzo di git come sistema di versionamento. Tuttavia, potrebbero esserci tutta una serie di ragioni per cui un progetto abbia bisogno di subversion: la stessa documentazione ufficiale ne fa un accenno, purtroppo senza addentrarsi nei dettagli.
Ecco qui cosa fare per avere un progetto Symfony2 funzionante con svn. Diamo per scontato di trovarci un una cartella in cui è stato fatto un checkout di un repository e in cui la cartella vendor di Symfony2 non sia presente (per esempio, perché il repository contiene uno scheletro di progetto simile a quello della Standard Edition senza venditori).
La prima cosa da fare è aggiungere i vari bundle e le altre dipendenza in externals:
mkdir vendor
svn pe svn:externals vendor
Nella finestra dell’editor, inserire le seguenti righe:
symfony http://svn.github.com/symfony/symfony.git
twig http://svn.github.com/fabpot/Twig.git
monolog http://svn.github.com/Seldaek/monolog.git
doctrine-common http://svn.github.com/doctrine/common.git
doctrine-dbal http://svn.github.com/doctrine/dbal.git
doctrine http://svn.github.com/doctrine/doctrine2.git
swiftmailer http://svn.github.com/swiftmailer/swiftmailer.git
assetic http://svn.github.com/kriswallsmith/assetic.git
twig-extensions http://svn.github.com/fabpot/Twig-extensions.git
metadata http://svn.github.com/schmittjoh/metadata.git
doctrine-extensions http://svn.github.com/l3pp4rd/DoctrineExtensions.git
bundles/Stof/DoctrineExtensionsBundle http://svn.github.com/stof/StofDoctrineExtensionsBundle.git
bundles/Sensio/Bundle/FrameworkExtraBundle http://svn.github.com/sensio/SensioFrameworkExtraBundle.git
bundles/Sensio/Bundle/DistributionBundle http://svn.github.com/sensio/SensioDistributionBundle.git
bundles/Sensio/Bundle/GeneratorBundle http://svn.github.com/sensio/SensioGeneratorBundle.git
bundles/JMS/SecurityExtraBundle http://svn.github.com/schmittjoh/JMSSecurityExtraBundle.git
cg-library http://svn.github.com/schmittjoh/cg-library.git
bundles/JMS/AopBundle http://svn.github.com/schmittjoh/JMSAopBundle.git
symfony/src/Symfony/Bundle/AsseticBundle http://svn.github.com/symfony/AsseticBundle.git
Si noti che sono stati aggiunti, oltre ai bundle di base, alcuni altri bundle utili.
Il problema di questo approccio è che github, almeno attualmente, non supporta il checkout di tag o branch tramite svn. Per questo le versioni dei vari venditori importate saranno quelle dei rispettivi master, quindi le versioni in sviluppo. Se quindi si riscontrano errori o eccezioni dovuti per esempio a metodi mancanti, si verifichi che il file app/bootstrap.php.cache contenga tutto ciò che è necessario. Ovviamente, va adattato anche il file relativo all’autoload:
// app/autoload.php
$loader->registerNamespaces(array(
'Symfony' => array(__DIR__.'/../vendor/symfony/src', __DIR__.'/../vendor/bundles'),
'Sensio' => __DIR__.'/../vendor/bundles',
'JMS' => __DIR__.'/../vendor/bundles',
'CG' => __DIR__.'/../vendor/cg-library/src',
'Doctrine\\Common' => __DIR__.'/../vendor/doctrine-common/lib',
'Doctrine\\DBAL' => __DIR__.'/../vendor/doctrine-dbal/lib',
'Doctrine' => __DIR__.'/../vendor/doctrine/lib',
'Monolog' => __DIR__.'/../vendor/monolog/src',
'Assetic' => __DIR__.'/../vendor/assetic/src',
'Metadata' => __DIR__.'/../vendor/metadata/src',
'Gedmo' => __DIR__.'/../vendor/doctrine-extensions/lib',
'Stof' => __DIR__.'/../vendor/bundles',
));
e anche quello relativo all’attivazione dei bundle:
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Symfony\Bundle\DoctrineBundle\DoctrineBundle(),
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new JMS\AopBundle\JMSAopBundle(),
new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
);
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
}
return $bundles;
}
Aggiornamento: si può adattare facilmente app/bootstrap.php.cache con il comando
php ./vendor/bundles/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php