How to install Symfony2 Bundles with Composer - symfony

I'm using Windows and I installed composer from its Windows installer. What I want to do is to install DoctrineMigrationsBundle to my project, so I added
"doctrine/doctrine-migrations-bundle": "dev-master"
to the composer.json file in the project and run
cd the project directory
php composer.phar update
but what I get is: Could not open input file: composer.phar
My whole composer.json file is
{
"name": "symfony/framework-standard-edition",
"description": "The \"Symfony Standard Edition\" distribution",
"autoload": {
"psr-0": { "": "src/" }
},
"require": {
"php": ">=5.3.3",
"symfony/symfony": "2.1.*",
"doctrine/orm": ">=2.2.3,<2.4-dev",
"doctrine/doctrine-bundle": "1.1.*",
"twig/extensions": "1.0.*#dev",
"symfony/assetic-bundle": "2.1.*",
"symfony/swiftmailer-bundle": "2.1.*",
"symfony/monolog-bundle": "2.1.*",
"sensio/distribution-bundle": "2.1.*",
"sensio/framework-extra-bundle": "2.1.*",
"sensio/generator-bundle": "2.1.*",
"jms/security-extra-bundle": "1.2.*",
"jms/di-extra-bundle": "1.1.*",
"kriswallsmith/assetic": "1.1.*#dev"
"doctrine/doctrine-migrations-bundle": "dev-master"
},
"scripts": {
"post-install-cmd": [
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
],
"post-update-cmd": [
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
]
},
"extra": {
"symfony-app-dir": "app",
"symfony-web-dir": "web"
}
}
Can you please help me to fix this?

As said by #AhmedSiouani, the error tells you that they can't find a composer.phar file.
Some things you can do:
Download the Composer-SetUp.exe and install Composer as told on the downloads page (scroll to 'Windows Installer');
Download the composer.phar file and put that in your project (not recommend);
Download the composer.phar file and put that in a directory which is in your PATH environment variable1;
Download the composer.phar file and create a composer.bat file which executes the composer.phar file. Put the code below in it and save it in a directory which is in your PATH environment variable1.
#echo off
php "path\to\composer.phar" %*
1: You can see which directories are in the PATH environment variable by
running echo %PATH% in your cmd.
You can also put the directory where this file lives in the PATH environment. To do that, go to Computer (right click) > Settings > Advanced Settings > Environments Variables (under the 'advanced' tab) and set the PATH variable with your directory path (or add the path to the current PATH variable, by putting a ; between the paths).

The error message is clear enough, it's not related to your composer.json file.
I think you just need to move your composer.phar file to your project directory.
Also, a much reusable solution would be to call it through your PATH environment variable.

Got the same issue with me "Could not open input file: composer.phar"
Fix : Go to the project directory and run following command
php -r "readfile('https://getcomposer.org/installer');" | php
and run
php composer.phar install or php composer.phar update
This will work awesome.

I working on fedora 17 I ran it on console to download composer.phar :
$ curl -s https://getcomposer.org/installer | php
then it's work now.

Make sure your code:
"kriswallsmith/assetic": "1.1.*#dev"
"doctrine/doctrine-migrations-bundle": "dev-master"
is changed to:
"kriswallsmith/assetic": "1.1.*#dev",
"doctrine/doctrine-migrations-bundle": "dev-master"
notice adding a , (comma).

Related

Composer says package of lower version is required in certain contexts. (Drupal)

I have a drupal profile called "orange_profile". It requires a bunch of common modules and requires drupal 9. If I go into the profile and run composer update it installs all the modules and core with proper versions (all beta or stable). Running composer depends drupal/core I can see that nothing is stuck below drupal 9.
But when I go to an actual site and try to install the profile it errors stating that the profile requires drupal ~8.0. I cannot get this to change.
Here is the error output:
composer require drupal/orange_profile:dev-2.0.x
./composer.json has been updated
Running composer update drupal/orange_profile
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Root composer.json requires drupal/orange_profile dev-2.0.x -> satisfiable by drupal/orange_profile[dev-2.0.x].
- drupal/orange_profile dev-2.0.x requires drupal/core ~8.0 -> found drupal/core[8.0.0-beta6, ..., 8.9.x-dev] but it conflicts with your root composer.json require (^9.1).
Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.
Installation failed, reverting ./composer.json and ./composer.lock to their original content.
Using -W does not help. In fact it sometimes still suggests that I use -W when I am using it.
Here are the composer.jsons:
Orange Profile
{
"name": "drupal/orange_profile",
"type": "drupal-profile",
"description": "Drupal Orange install profile with common modules.",
"homepage": "https://www.drupal.org/project/orange_profile",
"license": "GPL-2.0-or-later",
"require": {
"composer/installers": "^1.9",
"drupal/admin_toolbar": "^2.0",
"drupal/advagg": "^4.0",
"drupal/better_exposed_filters": "^5.0",
"drupal/ckeditor_font": "^1.0",
"drupal/ckeditor_media_embed": "^1.6",
"drupal/coffee": "^1.0",
"drupal/color_field": "^2.0",
"drupal/colorbutton": "^1.1",
"drupal/comments_order": "^1.1",
"drupal/config_inspector": "^1.0",
"drupal/core": "^9.1",
"drupal/ctools": "^3.0",
"drupal/easy_breadcrumb": "^1.12",
"drupal/editor_advanced_link": "^1.4",
"drupal/entity": "^1.2",
"drupal/entity_embed": "^1.0",
"drupal/entity_reference_revisions": "^1.5",
"drupal/field_group": "^3.0",
"drupal/google_analytics": "^3.1",
"drupal/google_tag": "^1.2",
"drupal/honeypot": "^2.0",
"drupal/hotjar": "^2.0",
"drupal/image_effects": "^3.0",
"drupal/imce": "^2.3",
"drupal/linkit": "^6.0",
"drupal/magnific_popup": "^1.4",
"drupal/mailsystem": "^4.1",
"drupal/menu_block": "^1.5",
"drupal/menu_trail_by_path": "^1.1",
"drupal/metatag": "^1.5",
"drupal/orange_starter": "2.0.x-dev",
"drupal/panelbutton": "^1.1",
"drupal/paragraphs": "^1.3",
"drupal/pathauto": "^1.2",
"drupal/schema_metatag": "^1.4",
"drupal/search_api": "^1.8",
"drupal/search_api_solr": "^4.1",
"drupal/simple_sitemap": "^3.8",
"drupal/swiftmailer": "^2.0",
"drupal/token": "^1.3",
"drupal/twig_tweak": "^2.0",
"drupal/userprotect": "^1.0",
"drupal/views_infinite_scroll": "^1.5",
"drupal/webform": "^6.0"
}
}
The site
{
"repositories": [
{
"type": "composer",
"url": "https://packages.drupal.org/8"
},
{
"type": "path",
"url": "../orange_profile",
"options": {
"symlink": false
}
}
],
"require": {
"drupal/core": "^9.1"
},
"conflict": {
"drupal/drupal": "*"
},
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"sort-packages": true
},
"extra": {
"drupal-scaffold": {
"locations": {
"web-root": "web/"
}
},
"installer-paths": {
"web/core": ["type:drupal-core"],
"web/libraries/{$name}": ["type:drupal-library"],
"web/modules/contrib/{$name}": ["type:drupal-module"],
"web/profiles/contrib/{$name}": ["type:drupal-profile"],
"web/themes/contrib/{$name}": ["type:drupal-theme"],
"drush/Commands/contrib/{$name}": ["type:drupal-drush"],
"web/modules/custom/{$name}": ["type:drupal-custom-module"],
"web/themes/custom/{$name}": ["type:drupal-custom-theme"]
}
}
}
This shows me trying to install just the core package and using a local version of the orange profile but the same happens when I am using the one from the remote repo and core-recommended.
My only hunch is that there is some dependencie down the way which has an odd requirement for something like doctrine as I have seen composer telling me that it's because the core 8.0.0-beta6 requires a specific commit of doctrine. This error appeared a couple times.
Anyone seen similar? I noticed while googling that others got the same or similar errors when trying to install certain modules like drupal/entity.
And one more side note, why can I only see what a package requires when it is installed? It would be more convenient for something like this to see the specific requirements of the profile that are asking for a lower core version.

Composer doesn't upgrade Symfony from 3.2 to 3.3

I'm trying to upgrade my project to latest Symfony.
The 3.1 to 3.2 was flawless.
Now it's been a hour I'm trying to upgrade to 3.3 and I still do'nt have a clue why it doesn't happen.
The strangest part is I don't have any error message when running the composer update command, but the symfony version doesn't change. I checked on the debug bar and with the bin/console --version command, still 3.2.10.
bin/console --version
Symfony 3.2.10 (kernel: app, env: dev, debug: true)
My composer.json is, I suppose, correctly specified :
"require" : {
"php" : ">=7.0",
"symfony/symfony" : "3.3.*",
"doctrine/orm" : "^2.5",
"doctrine/doctrine-bundle" : "^1.6",
"doctrine/doctrine-cache-bundle" : "^1.2",
"symfony/swiftmailer-bundle" : "^2.3",
"symfony/monolog-bundle" : "^2.8",
"symfony/polyfill-apcu" : "^1.0",
"sensio/distribution-bundle" : "^5.0",
"sensio/framework-extra-bundle" : "^3.0.2",
"incenteev/composer-parameter-handler" : "^2.0",
"symfony/assetic-bundle" : "^2",
"friendsofsymfony/user-bundle" : "~2.0",
"knplabs/knp-menu-bundle" : "^2.0",
"egeloen/ckeditor-bundle" : "^4.0",
"twig/twig" : "#stable",
"twig/extensions" : "^1.4",
"stof/doctrine-extensions-bundle" : "^1.2",
"friendsofsymfony/jsrouting-bundle" : "^1.6",
"yavin/symfony-form-tree" : "~1.0",
"cnerta/breadcrumb-bundle" : "2.1.*",
"symfony/security-acl" : "^v3",
"petrepatrasc/google-map-bundle" : "^2.3",
"debril/rss-atom-bundle" : "^3.0",
"beberlei/DoctrineExtensions" : "^1.0",
"symfony/http-kernel" : "~3.0",
"tilleuls/ovh-bundle" : "1.0.*",
"st/flagiconcss-bundle" : "~1.0",
"th3mouk/yahoo-weather-api" : "^1.0",
"jms/serializer-bundle" : "^1.2"
},
Here is the console output :
composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
> Incenteev\ParameterHandler\ScriptHandler::buildParameters
Updating the "app/config/parameters.yml" file
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache
// Clearing the cache for the dev environment with debug
// And the rest is usual assetic and cache clear stuff
I also tried to upgrade just symfony/symfony, no difference.
Does anyone have a clue ?
Thank you for your time and your help.
The problem is probably that one of your dependencies requires the lower version.
You can use:
composer why symfony/symfony 3.2.*
to find out which dependency it is. Then you probably have to update that dependency first.
To make sure everything works you should do this one by one using:
composer require dependency/dep ?
Where ? is the new version constraint. Then run your tests and then do the same with symfony:
composer update symfony/symfony
OP's edit :
The problem was due to Eclipse not writing the composer.json file to disk anymore, don't ask me why.
However, I mark this answer as the solution because the composer why command is what pushed me in the right direction.

Can't install laravel packages, symfony/process has wrong version

I tried to install some packages that need a 2.* version but the new laravel version uses 3.*
Is there any way to "downgrade" the package or do I have to wait until the packages are updated to the latest version?
I had the same issue, when I wanted to install sclable/php-latex. It needed symfony process higher than 2.7. Installed was version 3.x.
I thought, everything should be fine, but it did not work.
You just have to modify your composer.json file and set the version higher than 2.
"symfony/process": "^2.7"
as here my composer.json file
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": [ "framework", "laravel" ],
"license": "MIT",
"type": "project",
"minimum-stability": "beta",
"prefer-stable": true,
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.2.*",
"barryvdh/laravel-debugbar": "^2.2",
"symfony/process": "^2.7",
"sclable/php-latex": "0.*",
"anahkiasen/former": "^4.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "~4.0",
"symfony/css-selector": "2.8.*|3.0.*",
"symfony/dom-crawler": "2.8.*|3.0.*"
},
Then make an composer update:
composer update -verbose

how to solve deprecation of Twig_Function, Twig_Function_Method, Twig_Function_Node

After update symfony from 2.3 to 2.7, I am getting many deprecation warning messages for which I found no link for solving that issue.
The warning message I am getting is:
DEPRECATED - The Twig_Function class is deprecated since version 1.12 and will be removed in 2.0. Use Twig_SimpleFunction instead. -
Called from require() at line 154
Called from DebugClassLoader::loadClass()
Called from spl_autoload_call() at line 25
Called from require() at line 154
Called from DebugClassLoader::loadClass()
Called from spl_autoload_call() at line 22
Called from MenuExtension::getFunctions() at line 1282
Called from Twig_Environment::initExtension() at line 1263
Called from Twig_Environment::initExtensions() at line 1196
Called from Twig_Environment::getUnaryOperators() at line 371
Called from Twig_Lexer::getOperatorRegex() at line 65
Called from Twig_Lexer::__construct() at line 529
Called from Twig_Environment::getLexer() at line 557
Called from Twig_Environment::tokenize() at line 647
Called from Twig_Environment::compileSource() at line 382
Called from Twig_Environment::loadTemplate() at line 126
Called from TwigEngine::load() at line 50
Called from TwigEngine::render() at line 72
Called from TwigEngine::render() at line 97
Called from TwigEngine::renderResponse() at line 176
Called from Controller::render() at line 65
Called from DefaultController::indexAction()
Called from call_user_func_array() at line 3109
Called from HttpKernel::handleRaw() at line 3071
Called from HttpKernel::handle() at line 3222
Called from ContainerAwareHttpKernel::handle() at line 2444
Called from Kernel::handle() at line 34
For your information, this is the twig version I am using:
php composer.phar show -i | grep twig
twig/extensions v1.0.1 Common additional features for Twig that do not directly belong in core
twig/twig v1.22.1 Twig, the flexible, fast, and secure template language for PHP
NB. In my opinion, the deprecations come from the fact that some bundles I installed use some deprecated functions. So, below is composer.json file in case it could help.
"require": {
"php": ">=5.3.9",
"symfony/symfony": "2.7.*",
"doctrine/orm": "~2.2,>=2.2.3,<2.5",
"doctrine/dbal": "<2.5",
"doctrine/doctrine-bundle": "~1.4",
"twig/extensions": "1.0.*",
"symfony/assetic-bundle": "~2.3",
"symfony/swiftmailer-bundle": "~2.3",
"symfony/monolog-bundle": "~2.4",
"sensio/distribution-bundle": "~3.0,>=3.0.12",
"sensio/framework-extra-bundle": "~3.0,>=3.0.2",
"incenteev/composer-parameter-handler": "~2.0",
"friendsofsymfony/user-bundle": "v2.0.0-alpha3",
"lunetics/locale-bundle": "v2.4.2",
"stof/doctrine-extensions-bundle": "1.2.*#dev",
"knplabs/knp-menu": "2.0.*#dev",
"knplabs/knp-menu-bundle": "2.0.*#dev",
"coresphere/console-bundle": "0.3.0",
"knplabs/knp-markdown-bundle": "1.4.*#dev",
"lunetics/timezone-bundle": "dev-master",
"knplabs/knp-time-bundle": "1.4.0",
"a2lix/translation-form-bundle": "1.*#dev",
"knplabs/doctrine-behaviors": "1.2.*#dev",
"genemu/form-bundle": "2.2.*#dev",
"friendsofsymfony/jsrouting-bundle": "#stable",
"willdurand/geocoder": "#stable",
"misd/guzzle-bundle": "1.1.*#dev",
"friendsofsymfony/rest-bundle": "1.4.*#dev",
"jms/serializer-bundle": "0.13.*#dev",
"imagine/imagine": "0.5.*#dev",
"liip/imagine-bundle": "1.0.*#dev",
"nelmio/api-doc-bundle": "#stable",
"hwi/oauth-bundle": "0.4.*#dev",
"friendsofsymfony/facebook-bundle": "dev-master",
"willdurand/geocoder-bundle": "3.0.*#dev",
"google/apiclient": "1.0.*#dev",
"vich/uploader-bundle": "0.10.0",
"nomaya/social-bundle": "1.0.*#dev",
"jms/i18n-routing-bundle": "dev-master"
}
NB. I have similar warning messages for Twig_Function_Method, Twig_Function_Node, ...
NB. This link tells us that there are deprecations but without specifying how to solve them.
I found the bundles causing me the deprecations. To find them, just look after the files containing the word Twig_Function_Method for example through this command:
grep --exclude-dir={'./app/cache/','./app/logs/'} -rnw '.' -e "Twig_Filter_Method"
The result was this:
./vendor/jms/translation-bundle/JMS/TranslationBundle/Twig/TranslationExtension.php:56: 'desc' => new \Twig_Filter_Method($this, 'desc'),
./vendor/jms/translation-bundle/JMS/TranslationBundle/Twig/TranslationExtension.php:57: 'meaning' => new \Twig_Filter_Method($this, 'meaning'),
./vendor/jms/serializer/src/JMS/Serializer/Twig/SerializerExtension.php:46: 'serialize' => new \Twig_Filter_Method($this, 'serialize'),
./vendor/nelmio/api-doc-bundle/Nelmio/ApiDocBundle/Twig/Extension/MarkdownExtension.php:22: 'extra_markdown' => new \Twig_Filter_Method($this, 'markdown', array('is_safe' => array('html'))),
./vendor/knplabs/knp-time-bundle/Knp/Bundle/TimeBundle/Twig/Extension/TimeExtension.php:46: 'ago' => new \Twig_Filter_Method($this, 'diff', array(
./vendor/twig/twig/doc/deprecated.rst:45: * ``Twig_Filter_Method``
./vendor/twig/twig/doc/advanced_legacy.rst:707:You can also use ``Twig_Filter_Method`` instead of ``Twig_Filter_Function``
./vendor/twig/twig/doc/advanced_legacy.rst:715: 'rot13' => new Twig_Filter_Method($this, 'rot13Filter'),
./vendor/twig/twig/doc/advanced_legacy.rst:727:The first argument of the ``Twig_Filter_Method`` constructor is always
./vendor/twig/twig/doc/advanced_legacy.rst:747: 'date' => new Twig_Filter_Method($this, 'dateFilter'),
./vendor/twig/twig/lib/Twig/Filter/Method.php:12:#trigger_error('The Twig_Filter_Method class is deprecated since version 1.12 and will be removed in 2.0. Use Twig_SimpleFilter instead.', E_USER_DEPRECATED);
./vendor/twig/twig/lib/Twig/Filter/Method.php:23:class Twig_Filter_Method extends Twig_Filter
As conclusion, these are the bundles causing me deprecations: jms/translation-bundle, nelmio/api-doc-bundle, knplabs/knp-time-bundle.
I will be waiting that these bundles got update.
I hope the answer will be helping other.
I found this thread because i got the same issues with updating twig.
In the logs you'll find this line:
/logs/symfony/dev.log:7000:[2017-04-05 10:10:57] php.INFO: The Twig_Function_Node class is deprecated since version 1.12 and will be removed in 2.0. Use Twig_SimpleFunction instead.
Maybe that help the next ones who will arrive here.
Just replace:
'form_range' => new \Twig_Function_Node(...);
with:
'form_range' => new \Twig_SimpleFunction(...),

CSS/JS/Images from Bundle location will be always removed after composer.phar update

I have a tiny problem that i don't understand. I have some Bundle project generated by Symfony command, and they create a generic bundle folder in web/bundle/mypersonalbundle. OK, but one of them always be empty when I do an update from composer.phar. And only One! Thanks for your help !
$ php composer.phar update
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Removing doctrine/cache (v1.2.0)
- Installing doctrine/cache (v1.3.0)
Loading from cache
...
Installing assets using the hard copy option
Installing assets for Symfony\Bundle\FrameworkBundle into web/bundles/framework
Installing assets for OS\MyPersonalBundleBundle into web/bundles/mypersonalbundle # <--- ?
Installing assets for Sensio\Bundle\DistributionBundle into web/bundles/sensiodistribution
I'm Ok with updating the FrameworkBundle and DistributionBundle, but Why my personalbundle ?
Here is my composer.json "require" configuration :
"require" : {
"symfony/symfony" : "2.3.*",
"symfony/swiftmailer-bundle" : "2.3.*",
"friendsofsymfony/user-bundle" : "~2.0#dev",
"doctrine/orm" : ">=2.2.3,<2.4-dev",
"symfony/assetic-bundle" : "2.3.*",
"incenteev/composer-parameter-handler" : "~2.0",
"twig/extensions" : "1.0.*",
"php" : ">=5.3.3",
"sensio/generator-bundle" : "2.3.*",
"symfony/monolog-bundle" : "2.3.*",
"sensio/framework-extra-bundle" : "2.3.*",
"doctrine/doctrine-bundle" : "1.2.*",
"sensio/distribution-bundle" : "2.3.*"
},
My personalBundle is well registered like my other bundles in AppKernel.php :
$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\AsseticBundle\AsseticBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new FOS\UserBundle\FOSUserBundle(),
new My\PersonalBundleBundle\MyPersonalBundleBundle(),
new My\PersonalBundle2Bundle\MyPersonalBundle2Bundle(),
new My\PersonalBundle3Bundle\MyPersonalBundle3Bundle(),
);
You have a MyPersonalBundle.
In this Bundle, you have a Resources directory.
In this directory, you can create a directory named "public" then put your css, js, img files in it. Directory in the public directory are allowed.
When you will use composer, it will do the php app/console assets:install command.
This command copy the content of the public directory in web/bundle/mypersonalbundle.
Advice : use the extra option in composer.json to create a symlink instead of using the hard copy.
"extra": {
"symfony-app-dir": "app",
"symfony-web-dir": "web",
"symfony-assets-install": "symlink"
}
and the command will be php app/console assets:install --symlink

Resources