symfony2.1 bundle version confusion, for symfony and sonata admin / knp menu bundle

timaschew picture timaschew · Sep 9, 2012 · Viewed 8k times · Source

I want to use symfony2.1 for a new project. I try to install symfony2 with composer. But there were multiple errors/problems and so I have also questions for each problem in bold font style. Sometimes I don't know if I do it the right way.

I want to use a stable version so I chosen the 2.1.0 version and not the dev/master.

php composer.phar create-project symfony/framework-standard-edition symfony v2.1.0

the result was this:

Installing symfony/framework-standard-edition (v2.1.0)
  - Installing symfony/framework-standard-edition (v2.1.0)
    Downloading: 100%

    Created project in symfony
    Loading composer repositories with package information
    Installing dependencies from lock file
    Your requirements could not be resolved to an installable set of packages.

      Problem 1
        - Installation request for symfony/symfony == 2.1.9999999.9999999-dev -> satisfiable by                                               symfony/symfony 2.1.x-dev.
        - Can only install one of: symfony/symfony dev-master, symfony/symfony 2.1.x-dev.
        - Installation request for symfony/symfony == 9999999-dev -> satisfiable by symfony/sym                                              fony dev-master.

So I do a php composer.phar update and the dependencies was installed without errors.

But I noticed that most bundles have no stable version. For example doctrine/common (2.3.x-dev), here is the full list

Loading composer repositories with package information
Updating dependencies
  - Installing doctrine/common (2.3.x-dev 605b1b8)
    Cloning 605b1b8b5a7bc8daf9111fb35483e5708e30de35

  - Installing doctrine/dbal (2.3.x-dev 239630b)
    Cloning 239630b61f03f39d198441eced1bfffb7b0e61d1

  - Installing twig/twig (dev-master 68b8c46)
    Cloning 68b8c4619c5bbe82bd345fe56070dec8c356610a

  - Installing symfony/symfony (2.1.x-dev e7059b4)
    Cloning e7059b44c78ca8e1e892adb4d93b5a482f4eb9b3

  - Installing swiftmailer/swiftmailer (dev-master e12e4ef)
    Cloning e12e4ef3a9d6dd60fb734a01984a6e6627aea764

  - Installing doctrine/orm (2.3.x-dev 4d9f24b)
    Cloning 4d9f24b2eef3af3a3e76c773994c19bbb0706f88

  - Installing doctrine/doctrine-bundle (dev-master v1.0.0)
    Cloning v1.0.0

  - Installing twig/extensions (dev-master f904575)
    Cloning f904575642b1213db69b4a98f08397e722ba1cae

  - Installing kriswallsmith/assetic (dev-master dfbb776)
    Cloning dfbb776288baf9319d1693195af2cb6e00729901

  - Installing symfony/assetic-bundle (dev-master 4e7e8a0)
    Cloning 4e7e8a039fa19434f04558473adbb201118af942

  - Installing symfony/swiftmailer-bundle (dev-master d2eae93)
    Cloning d2eae9385c029cbac031a90e6d2abc74b889a562

  - Installing monolog/monolog (dev-master a929570)
    Cloning a929570bb7688b39fefe4106f0ecf0ac35f37647

  - Installing symfony/monolog-bundle (dev-master v2.1.0-RC2)
    Cloning v2.1.0-RC2

  - Installing sensio/distribution-bundle (dev-master 9892129)
    Cloning 98921298951598e8707258cba2b6180b96faa91c

  - Installing sensio/framework-extra-bundle (dev-master v2.1.0)
    Cloning v2.1.0

  - Installing sensio/generator-bundle (dev-master v2.1.0-RC2)
    Cloning v2.1.0-RC2

  - Installing jms/metadata (1.1.1)
    Downloading: 100%

  - Installing jms/cg (1.0.0)
    Downloading: 100%

  - Installing jms/aop-bundle (1.0.0)
    Downloading: 100%

  - Installing jms/di-extra-bundle (1.1.x-dev af21952)
    Cloning af219527024c584d7311aa855d7522429c5bdb67

  - Installing jms/security-extra-bundle (1.2.x-dev 9ab6ace)
    Cloning 9ab6aceda50fc7a2b07d741ba4b3f0695508afcb

1a) Is this right? Or is there another solution? I mean to use bundles which are stable and not in dev mode

The next day I do again an composer update and noticed that some libs were updated: all libs for dev-master branch which has new changes within the last day.
1b) So I should do a composer update in regular intervals while developing my app, to merge new bugfixes, etc?

$ php composer.phar update
Loading composer repositories with package information
Updating dependencies
  - Updating swiftmailer/swiftmailer dev-master (e12e4e => c97353)
    Checking out c97353b1ebffe25a224146f69d17efe24c093def

  - Updating monolog/monolog dev-master (a92957 => e5bf7b)
    Checking out e5bf7ba5d1df622b68d004b3c0277bc94286e1b7

  - Updating friendsofsymfony/user-bundle dev-master (24edb2 => 878b7c)
    Checking out 878b7c8320159fb09e8e94d446c498b00142b206

  - Updating sonata-project/notification-bundle dev-master (5e7b50 => 9cef7d)
    Checking out 9cef7d224f224b4e4327f200f9bd57b798d4ab0a

  - Updating knplabs/gaufrette dev-master (861110 => 5ac439)
    Checking out 5ac439cd46eb461043e6bb73dae717528f674a57

  - Updating sonata-project/media-bundle dev-master (d04a61 => 233511)
    Checking out 2335114dab6ea9680d174df157f5a7b4551a54dc

Because I don't found out another solution I continue and install FOS UserBundle by adding this line "friendsofsymfony/user-bundle": "*" to the composer.json. I do the whole installation stuff and it works perfectly.

Then I start to install the Sonata AdminBundle by adding "sonata-project/admin-bundle": "dev-master" to the composer.json. I chose the dev-master version because on http://packagist.org/packages/sonata-project/admin-bundle I found out that the version 2.0.x-dev is not for symfony2.1.
Furthermore the AdminBundle has a depdency for knplabs/knp-menu-bundle: 1.1.*
On http://packagist.org/packages/knplabs/knp-menu-bundle I see for the version v1.1.0 that there is another dependency for knplabs/knp-menu: 1.1.*
Then on http://packagist.org/packages/knplabs/knp-menu I found 4 versions that begins with 1.1:

  • 1.1.x-dev
  • v1.1.2
  • v1.1.1
  • v1.1.0

2a) Is there a difference if there is a leading v before the version number?

2b) Which version will be used of these four, when the dependency is 1.1* ?

When I start to load the admin bundle deps I see the result:

$ php composer.phar update
Loading composer repositories with package information
Updating dependencies
  - Installing knplabs/knp-menu (1.1.x-dev v1.1.2)
    Cloning v1.1.2

  - Installing knplabs/knp-menu-bundle (v1.1.0)
    Downloading: 100%

  - Installing sonata-project/admin-bundle (dev-master 20d5e4a)
    Cloning 20d5e4a659bddb5fc0bcfc4755643dbc4e3f7ec1

I install some more sonata bundles (doctrine-orm-admin-bundle, user-bundle, page-bundle, media-bundle) and there was an error

  - Installing imagine/imagine (v0.3.0)
    Downloading: 100%



  [ErrorException]
  rename(C:\wamp\www\symfony\vendor/imagine/Imagine/avalanche123-Imagine-a23b4f5,afcc946468d0cf073686fe7e1ae19eb2): access denied
   (code: 5)

3) but when I repeat the step the error was gone. Is this normal?

$ php composer.phar update
Loading composer repositories with package information
Updating dependencies
  - Installing imagine/imagine (v0.3.0)
    Downloading: 100%

  - Installing knplabs/gaufrette (dev-master 8611109)
    Cloning 8611109aeb0bd43fd88485c20fec7fc85b021b84

  - Installing sonata-project/media-bundle (dev-master d04a617)
    Cloning d04a617d81383a6e1ba65ee99c2ea4379e7daf4e

Then I continued with the configuration of sonata admin bundle. After I add a create a Post entity and a PostAdmin and configure a service for it (btw: the service configuration is a little bit poor), noticed that I forget to install the Knp Menu (the error was: non-existent service "knp_menu.factory)

I go on https://github.com/KnpLabs/KnpMenuBundle/blob/master/Resources/doc/index.md and see the instruction details to install it. Butt there were outdated. Since smyfony2.1. the $loader in the autoload.php has no registerNamespaces function anymore, because this is not the UniversalClassLoader class, its the composer classloader. So I have to create an own UniversalClassLoader instance. And the paths are completly different, there is now a parent knplabs directory and the sub directory also changed.

use Symfony\Component\ClassLoader\UniversalClassLoader;
use Doctrine\Common\Annotations\AnnotationRegistry;

$loader = require __DIR__.'/../vendor/autoload.php';

// intl
if (!function_exists('intl_get_error_code')) {
    require_once __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';

    $loader->add('', __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs');
}

$universalLoader = new UniversalClassLoader();
$universalLoader->registerNamespaces(array(
        'Knp\Menu' => __DIR__.'../vendor/knplabs/knp-menu/src',
        'Knp\Bundle' => __DIR__.'/../vendor/knplabs/knp-menu-bundle'
));
$universalLoader->register();


AnnotationRegistry::registerLoader(array($loader, 'loadClass'));

return $loader;

4) Why is the KnpMenu install construction outdated and why there is only a master branch on github and nothing for the versions which exist on http://packagist.org?

I'm new to symfony2 and composer and it's sometimes really hard to understand this whole stuff.

Answer

Wouter J picture Wouter J · Sep 9, 2012

1a) Is this right? Or is there another solution? I mean to use bundles which are stable and not in dev mode

Symfony21 will standard choose the best version for you. You can see these versions in the composer.json file of the symfony/framework-standard-edition package (symfony/symfony-standard on github).

As you can see it uses the 2.1.* versions and not the dev-master versions, but because the latest version of the package begins with 2.1 it will load the dev-master. Later, with symfony2.2 it shouldn't use the dev-master, but the latest 2.1 version of the package.

If you want a static version you can just replace the * with the subversion you want, but I don't recommend this because you don't get the bug fixes.

1b) So I should do a composer update in regular intervals while developing my app, to merge new bugfixes, etc?

Yes, it is good to update your dependencies from time to time. For instance if you think you spot a bug or if you push it in production.

2a) Is there a difference if there is a leading v before the version number?

As we can read in the packagist documentation (under Managing package versions) there is no difference. You can use them both and if you use 2.1.4 it will look for a 2.1.4 version or v2.1.4.

2b) Which version will be used of these four, when the dependency is 1.1.* ?

The latest 1.1 subversion. For instance if you foobar package has these versions: 1.1.1, 1.1.2 .. 1.1.6. And you require 1.1.* the latest (1.1.6) will be installed.

3) but when I repeat the step the error was gone. Is this normal?

It looks like the CLI can't access the file, you maybe opened it in a program. When you tried it the second time it had access.

4) Why is the KnpMenu install construction outdated and why there is only a master branch on github and nothing for the versions which exist on http://packagist.org?

First question: I don't know why the documentation is outdated. You should go into the vendor/composer/autoload_namespaces.php file and put the namespaces there, then it should work. Or, the better option, add these namespaces to the require setting in the composer.json file. See the composer autoload docs for more information.

Second question: It uses the tags on github too.