Adding Composer as Manager of Drupal 8 - composer-php

I installed D8 manually but I need Composer to Manage and Install Drush and Drupal Console.
I found docs about fresh install, but I would to know if it's possible to add Composer as Drupal components manager after a manual druapl install ?
Actually I have Composer and Drush9 installed. But I can't do update for D8 because Composer doesn't find infos about this:
~/www/mgasquet/sited8 $ composer outdated
behat/mink-selenium2-driver dev-master 93474c6 dev-master 3ab9f31 Selenium2 (WebDriver) driver for Mink framework
brumann/polyfill-unserialize v1.0.3 v1.0.4 Backports unserialize options introduced in PHP 7.0 to older PHP versions.
composer/installers v1.6.0 v1.7.0 A multi-framework Composer library installer
dflydev/dot-access-data v1.1.0 v2.0.0 Given a deep data structure, access data by dot notation.
doctrine/annotations v1.2.7 v1.7.0 Docblock Annotations Parser
doctrine/cache v1.6.2 v1.8.0 Caching library offering an object-oriented API for many cache backends
doctrine/collections v1.3.0 v1.6.2 Collections Abstraction library
doctrine/common v2.6.2 v2.10.0 Common Library for Doctrine projects
doctrine/inflector v1.1.0 v1.3.0 Common String Manipulations with regard to casing and singular/plural rules.
doctrine/instantiator 1.0.5 1.2.0 A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer v1.0.1 1.1.0 Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.
drupal/coder 8.3.1 8.3.6 Coder is a library to review Drupal code.
egulias/email-validator 2.1.7 2.1.11 A library for validating emails against several RFCs
grasmash/yaml-expander 1.4.0 2.0.0 Expands internal property references in a yaml file.
Thanks for tips.
EDIT: is this a good and actual way ? tuto
EDIT2: as I must update modules too, I face off a little issue ragarding "minimum-stability" , I put this in my composer.json,
"minimum-stability": "dev",
"prefer-stable": true,
But it replace dev version by alpha ones. I prefer using dev or stable not alpha or beta, RC admitted. How can I do that ?
EDIT3: modules aren't downloaded in modules/contrib, so do I need to add this to my composer.json ?
"extra": {
"installer-paths": {
"modules/contrib/{$name}/": ["type:drupal-module"],
"themes/contrib/{$name}/": ["type:drupal-theme"]
},

You can definitely attempt the recommendations on the guide you linked to. Take a full code, database, and file backup of the site first.
That said, I highly recommend you re-build the site using drupal-project. After which:
run composer require for all of your contributed modules / themes
copy any custom modules / themes
re-import the database
copy over your files directory
P.S. to anyone viewing this answer in the future please check the core strategic initiative for up to date info.

Related

TYPO3 8.7 Install an extension without composer

I have a T3 8 project that was installed WITHOUT composer.
For the project I need the Ext t3api, which can only be installed (???) WITH composer.
Is it possible to install it somehow?
EXT:t3api is available via TER (https://extensions.typo3.org/extension/t3api). So it's installable via extensionmanager.
Another way would be uploading the extension's folder to typo3conf/ext/ (foldername = extensionkey - in this case "t3api"). Then the extensionmanager will find it and allow you to active/install it.
Update:
Dependencies to PHP packages (like some symfony/* packages) cannot be handled directly by TYPO3 (ext_emconf.php). Therefore, you have to build your own extension with the code of these packages and configure the appropriate autoloading.
There's already a good thread "How do I install Composer PHP packages without Composer?"

Composer: how to know a package by what other package is required

I've found nesbo/carbon in my vendor folder. It is a really useful library and I'm curious to know which other package I installed requires it.
How can I know this?
Lets look at composer why or composer depends command. This command shows which other packages depend on a certain package. Show usage
This is usage example
$ composer depends psr/log
symfony/debug v3.2.2 requires psr/log (~1.0)

How to change dev-master releases to stable composer

I am creating a sockets package in PHP for Laravel, but I can not just use the composer require because the package is in dev-master and of course I do not want to change my entire main application to accept packages in dev-master. Could someone help me make a release stable discoverable by packagist?

How to skip suggestions when composer installing

Locally when I run composer install it doesn't show anything about suggestions. In our CI environment it provides a long list of suggestions I'd like to avoid. I want to see the output of what's being loaded from cache and that kind of thing, just don't want to see this. I've been through the docs and haven't been able to figure out how to hide this.
The suggestions are (among many others)...
symfony/security-core suggests installing symfony/expression-language (For using the expression voter)
symfony/routing suggests installing symfony/expression-language (For using expression matching)
predis/predis suggests installing ext-phpiredis (Allows faster serialization and deserialization of the Redis protocol)
phpseclib/phpseclib suggests installing ext-gmp (Install the GMP (GNU Multiple Precision) extension in order to speed up arbitrary precision integer arithmetic operations.)
phpseclib/phpseclib suggests installing pear-pear/PHP_Compat (Install PHP_Compat to get phpseclib working on PHP < 4.3.3.)
patchwork/utf8 suggests installing ext-intl (Use Intl for best performance)
monolog/monolog suggests installing aws/aws-sdk-php (Allow sending log messages to AWS services like DynamoDB)
How can I hide this output?
As of composer 1.6.3, there is a --no-suggest option that hides all suggestions when running composer install or composer update.
When you run composer install on a project that has a composer.lock file, it just installs the versions locked in the composer.lock file and nothing. In other words, the required packages and versions are already resolved and it's just installing it.
When you run composer install on a project with no composer.lock file, Composer will resolve the required packages and their versions and will store it in the composer.lock file before installing them. In this case, the project was not set up and you get notified about other suggested packages.
In the second case, there is no way you can hide the suggested packages list from the output (at least, at the time of writing this answer). In the first case, nothing is new, so it isn't shown at all.
The solution will be to push your composer.lock file to the server, which is a good practice after all (you don't want your production server to have other versions of the dependencies than your dev environment, newer versions might broke your site).
Since composer 1.6.3, the --no-suggest doesn't show anything about suggestions. But in composer 2, this option is deprecated, it has no effect and will break in composer 3 (see this link for more details).
Hope that will help in 2021!

Composer: how to install `dev` packages in Symfony 2.3?

Trying to install the KnpGaufretteBundle in a Symfony 2.3 project, I'm having no luck. The problem is:
minimum-stability:stable (in composer.json);
the bundle I require is dev-master version still.
Reading this in the Symfony docs was frustrating:
If you know of a cool bundle or PHP library that still requires a dev
minimum stability, talk to the lead developer and convince him to tag
a stable release.
I'm not changing the minimum stability of the whole project to dev, as it would certainly make a huge mess - I mean, can't I use stable packages and dev packages side by side?
Am I missing something about composer maybe?
Edit (14 August 2013)
According to Sven's answer below, I've edited my composer.json (you can find it here) and it started to work. Anyway, this is a partial solution, because inline aliases do not work for dependencies - so in my case I'd have to specify all dependencies of "less-than-stable" packages first, and alias them one by one.
just use
"knplabs/knp-gaufrette-bundle": "dev-master#dev"
if you need the latest dev version
you can also change minimum-stability to dev and add "prefer-stable": true like this:
"minimum-stability": "dev",
"prefer-stable": true,
then composer will always try to find a stable version and if nothing found install dev, so your symfony packages will be still stable.
But in your case composer will install v0.1.4 (latest stable of knplabs/knp-gaufrette-bundle), so you need dev-master#dev anyway. prefer-stable is just a hint for you.
Have a look at aliases: http://getcomposer.org/doc/articles/aliases.md
They are supposed to allow you to address a branch (which by definition is always in development, because you can only access the latest commit) in a way that that branch should be the logical extension of a version tag.
For a yet untagged project, a proper assumed tag version would be like "0.0.0".
You should try the inline alias for the bundle.

Resources