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

I want to use symfony2.1 for a new project. I am trying to install symfony2 with composer. But there were a few bugs / problems, so I have questions for each problem in bold style. Sometimes I don’t know if I am doing this correctly.

I want to use the stable version, so I chose version 2.1.0, not dev / master.

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

The result is the following:

 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 am doing php composer.phar update and the dependencies were installed without errors.

But I noticed that most packages do not have a stable version. For example, doctrine / common (2.3.x-dev), here is the complete 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 correct? Or is there another solution? I mean using packages that are stable and not in dev mode

The next day I will do an update for the composer again and notice that some libraries have been updated: all lib libraries for the dev-master branch that have new changes in the last day.
1b) So, I have to do a composer update at regular intervals when developing my application, combine new fixes, 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 

Since I did not find another solution, I continue and install the FOS UserBundle by adding this line "friendsofsymfony/user-bundle": "*" to composer.json. I do all the installation stuff and it works great.

Then I start installing Sonata AdminBundle by adding "sonata-project/admin-bundle": "dev-master" to composer.json. I chose the dev-master version because at http://packagist.org/packages/sonata-project/admin-bundle I found out that version 2.0.x-dev is not for symfony2.1.
In addition, AdminBundle has the ability for knplabs / knp-menu-bundle: 1.1. *
At http://packagist.org/packages/knplabs/knp-menu-bundle I see for 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 start 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 in front of the version number?

2b) What version will be used for these four when the dependency is 1.1 *?

When I start loading admin package debugs, 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 a few more sonata packages (doctrine-orm-admin-bundle, user set, page package, media package), and an error has occurred

  - 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 has disappeared. This is 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 to configure the sonata admin set. After I add the creation of the Post and PostAdmin object and configure the service for it (by the way, the configuration of the service is a bit poor), I noticed that I forgot to install the Knp Menu (the error was: non-existent service "knp_menu.factory )

I continue to https://github.com/KnpLabs/KnpMenuBundle/blob/master/Resources/doc/index.md and read the installation instructions to install it. The butt was obsolete. With smyfony2.1. $loader in autoload.php no longer has a registerNamespaces function, because it is not a UniversalClassLoader class, it is its class loader. Therefore, I need to create my own instance of UniversalClassLoader. And the paths are completely different from each other, now there is the parent directory knplabs , and the subdirectory has 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 legacy version of KnpMenu outdated and why is there only a leading branch on github and nothing for the versions that exist on http://packagist.org ?

I am new to symfony2 and composer, and sometimes it is very difficult to understand all this stuff.

+6
source share
1 answer

1a) Is this correct? Or is there another solution? I mean using packages that are stable and not in dev mode

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

As you can see, it uses version 2.1.* , Not the dev-master version, but since the latest version of the package starts with 2.1 , it will load dev-master . Later with symfony2.2 it should not use dev-master , but the latest version is 2.1 .

If you want a static version, you can simply replace * with the subversion you need, but I do not recommend this because you are not getting bug fixes.

1b) So, I have to do a composer update at regular intervals when developing my application, merging new fixes, etc.

Yes, it’s useful to update your dependencies from time to time. For example, if you think that you noticed an error or clicked it in production .

2a) Is there a difference if there is a leading v in front of the version number?

As we can read the packagist documentation (in the "Package Versioning" section) there is no difference. You can use both of them, and if you use 2.1.4 , it will look for version 2.1.4 or v2.1.4 .

2b) What version will be used for these four when the dependency is 1.1. *?

Last 1.1 subversion. For example, if the foobar package has the following versions: 1.1.1, 1.1.2 .. 1.1.6. And you need 1.1.* last one will be installed ( 1.1.6 ).

3), but when I repeat the step, the error has disappeared. This is normal?

It looks like the CLI cannot access the file, you may have opened it in the program. When you tried it a second time, it had access.

4) Why is the legacy KnpMenu construct obsolete and why is there only a leading branch on github and nothing for the versions that exist on http://packagist.org ?

First question: I do not know why the documentation is out of date. You must go into vendor/composer/autoload_namespaces.php and place the namespaces there, then it should work. Or, a better option, add these namespaces to the require parameter in the composer.json file. For more information, see the documents for the startup of the linker .

Second question: it uses tags for github.

+7
source

Source: https://habr.com/ru/post/924954/


All Articles