Currently I use 5.2.3 version of Symfony. I want to use feature from this pull request https://github.com/symfony/symfony/pull/36851. It's rather github / composer related question rather than symfony itself. How to do it?
So far I try:
{
...
"symfony/form": "5.2.*-dev", // changes I made to composer.json
...
}
The composer update end successfully:
- Upgrading symfony/form (v5.2.4 => 5.2.x-dev 7664ad9): Extracting archive
But still If I use choice_translation_parameters in code I get:
public function buildForm(FormBuilderInterface $builder, array $options)
{
...
$builder->add('amount', ChoiceType::class, ["label" => "rese.amount?", "choices" => $roomAmountChoices, "choice_translation_parameters" => []]);
...
}
An error has occurred resolving the options of the form "Symfony\Component\Form\Extension\Core\Type\ChoiceType": The option "choice_translation_parameters" does not exist. Defined options are: "action", "allow_file_upload", "attr", "attr_translation_parameters", "auto_initialize", "block_name", "block_prefix", "by_reference", "choice_attr", "choice_filter", "choice_label", "choice_loader", "choice_name", "choice_translation_domain", "choice_value", "choices", "compound", "csrf_field_name", "csrf_message", "csrf_protection", "csrf_token_id", "csrf_token_manager", "data", "data_class", "disabled", "ea_crud_form", "empty_data", "error_bubbling", "expanded", "getter", "group_by", "help", "help_attr", "help_html", "help_translation_parameters", "inherit_data", "invalid_message", "invalid_message_parameters", "is_empty_callback", "label", "label_attr", "label_format", "label_html", "label_translation_parameters", "mapped", "method", "multiple", "placeholder", "post_max_size_message", "preferred_choices", "property_path", "required", "row_attr", "setter", "translation_domain", "trim", "upload_max_size_message".
Using *-dev isn't going to work because the code is still waiting to be merged into symfony/symfony.
Take a look at http://vvv.tobiassjosten.net/php/have-composer-use-development-branches/ for instructions how to override a package with a different repository.
In your case the composer.json would have:
"repositories": [
{
"type": "git",
"url": "https://github.com/VincentLanglet/symfony.git"
}
]
Warning: This will be good for short periods of time but going into production with this is risky. You will get the feature you want but are relying on the author to keep updated with the real symfony master.
Since it is an open (unmerged) branch, you can not directly pull it. You have to get this registered in your composer.json using repository pattern.
Something similar to
{
"repositories": [
{
"type": "git",
"url": "https://github.com/VincentLanglet/symfony.git"
}
],
"require": {
"symfony/form": "^5.2"
}
}
You (in this example me, because i answer to my own question ) do everything right, just pick wrong branch. Change it to:
{
...
"symfony/form": "5.*-dev",
...
}
If you take a closer look on symfony/form repository history you notice that previously composer pick branch which doesn't include commit with feature you request.
Related
I am using 3 packages in my Laravel 5.8 application:
Backpack CRUD (which uses Backpack Base) https://github.com/Laravel-Backpack/CRUD
Styde\HTML https://github.com/StydeNet/html/
Prologue\Alerts https://github.com/prologuephp/alerts
These are clashing because Backpack Base relies on the Global Alias for "Alert" being set to use PrologueAlert. See an example of how it uses \Alert here:
private function checkLicenseCodeExists()
{
if ($this->app->environment() != 'local' && !config('backpack.base.license_code')) {
\Alert::add('warning', "<strong>You're using unlicensed software.</strong> Please ask your web developer to <a target='_blank' href='http://backpackforlaravel.com'>purchase a license code</a> to hide this message.");
}
}
Source: https://github.com/Laravel-Backpack/Base/blob/1.1.4/src/BaseServiceProvider.php#L264
Because I haven't bought that license yet I started seeing an error caused because that above snippet was trying to pass a string to Alert::add() but it was calling the add() method on Styde\Html\Alert\Container::add() which expects the parameter to be an instance of Styde\Html\Alert\Message instead of calling it on Prologue's version of Alert which accepts a string. It's calling the wrong "Alert"!
Even though my application is specifically set to use PrologueAlert for Alert
// config/app.php
'aliases' => [
...
'Alert' => Prologue\Alerts\Facades\Alert::class
]
I have discovered the reason is that in version 1.7 Styde moved the Aliases for his package from the protected $globalAliases variable on HTMLServiceProvider.php to the composer.json auto-discover section
"extra": {
"laravel": {
"providers": [
],
"aliases": {
"Field": "Styde\\Html\\Facades\\Field",
"Alert": "Styde\\Html\\Facades\\Alert",
"Menu": "Styde\\Html\\Facades\\Menu",
"Form": "Collective\\Html\\FormFacade",
"Html": "Collective\\Html\\HtmlFacade"
},
"dont-discover": [
"laravelcollective/html"
]
}
}
Source: https://github.com/StydeNet/html/commit/f51138fb42bef458f3f0e101b98344162b7327ba#diff-b5d0ee8c97c7abd7e3fa29b9a27d1780
Now, it seems my application is prioritising Styde's alias of "Alert" over my own application-set value!
Other than rolling back to use version 1.6 of Styde, how can I force Laravel to prioritise my own defined aliases over ones discovered via the composer.json?
I found the solution! It was actually inspired by a snippet in my original post.
You can add an extra section to your application's composer.json that get read by the Laravel application and used to decide which packages to ignore during auto-discover like this:
// composer.json
{
...
"extra": {
"laravel": {
"dont-discover": [
"styde/html"
]
}
}
}
This then allows you to pick and choose aliases from the problematic package and define as many or as few of the them as you like in your config/app.php (for my application I was only using the Field alias from Styde/Html so that was the only one I had to add to my App config).
I think as more and more package maintainers start leveraging the auto-discover feature this is going to become a more widely used feature.
Afterthought: This is a shift in the relationship between Composer and Laravel. Whereas the composer.json file was traditionally just a package manager that would be run at installation and then not used when the application is running, it is now a config file that is read by the application. I learned this the hard way as our pipeline that packages-up and deploys the code used to tidy up files that weren't required in the production environment. It was deleting composer.json which started the error happening again in our QA environment.
I want to set up a main project depending on other local projects. That works actually fine. But when a dependency has a dependency by itself, composer update exists with an error.
Set up:
I have three packages.
/home/programming/git
vendor.main
vendor.depA
vendor.depB
vendor/main depends on vendor.depA which in turn depends on vendor.depB.
What works
The vendor/main composer.json defines a dependency on vendor.depA:
{
"name": "vendor/main",
"description": "main",
"repositories": [
{ "type": "vcs", "url": "/home/user/programming/git/vendor.depA/" },
{ "type": "vcs", "url": "/home/user/programming/git/vendor.depB/" }
],
"require": {
"vendor/depA": "dev-master"
}
}
And vendor.depA has no other dependency:
{
"description": ". . .",
"name": "vendor/depA"
}
composer update works as expected and installs vendor/depA.
What doesn't work
If vendor.depA defines a dependency on vendor/depB composer update fails:
{
"description": ". . .",
"name": "vendor/depA",
"require": {
"vendor/depB": "dev-master"
}
}
Adding the repository to the vendor.depA's composer.json doesn't help.
composer update runs through, if I add the dependency to vendor.main's composer.json (so, there is no typo, or another problem with vendor/depB, etc), but that doesn't really help, since depA should have the dependency.
What am I doing wrong here?
Edit: The error message
~/composer.phar update Loading composer repositories with package
information Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of
packages.
Problem 1
- vendor/depA dev-master requires vendor/depB dev-master -> no matching package found.
- vendor/depA dev-master requires vendor/depB dev-master -> no matching package found.
- Installation request for vendor/depA dev-master -> satisfiable by vendor/depA[dev-master].
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setting see
<https://getcomposer.org/doc/04-schema.md#minimum-stability> for more
details.
- It's a private package and you forgot to add a custom repository to find it
Read <https://getcomposer.org/doc/articles/troubleshooting.md> for
further common problems.
I think that is not working with "dev-master". In you case that makes no sense then "dev-master" is always the latest version of your master branch. So you should tag a commit and work with tags and set your requirement depending on a tag number.
Here is an example how you can define a package if you really want to define it in your composer file.
"repositories": [
{
"type": "package",
"package": {
"name": "vendor/yourpackage",
"version": "v1.0.0",
"source": {
"url": "git#your.gitserver.com:vendor/project.git",
"type": "git",
"reference": "dd6ed3c8"
}
}
}
]
Then you have created a package with the specified version number "1.0.0" and that package is set to a git commit.
The repo is template-PHP-project. When I use the Submit function on packagist.org I get a pop-up that just says "undefined".
Clearly there is something wrong with my composer.json but I don't know what. (I can run composer update without errors.) It contains the following:
{
"name": "unixnut/template-php-project",
"description": "A self-contained project that uses the Composer autoloader to load class files",
"license": "GPL",
"authors": [
{
"name": "Alastair Irvine",
"email": "alastair#plug.org.au"
}
],
"require": {},
"include-path": ["app/include", "contrib"],
"autoload": {
"psr-4": {
"XYZ\\": "app/classes/XYZ"
}
}
}
Try to use composer validate command.
I just validated your file locally, and the only error is about the license. Fix and check again.
$ composer validate
./composer.json is valid, but with a few warnings
See https://getcomposer.org/doc/04-schema.md for details on the schema
License "GPL" is not a valid SPDX license identifier, see https://spdx.org/licenses/ if you use an open license.
If the software is closed-source, you may use "proprietary" as license.
I was updating my yii2 via composer then reverted back to the old beta version.
Here is the error on my composer:
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package bower-asset/jquery could not be found in any version, there may be a typ
o in the package name.
Potential causes:
- A typo in the package name
- The package is not available in a stable-enough version according to your minimum-stability setti
ng
see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.
Read <http://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.
Tried searching for bower-asset/jquery at packagist but it is not found.
Thanks for the help :)
Finally fixed it, just followed the steps on the UPGRADE.md doc
If you are using Composer to upgrade Yii, you should run the following command first (once for all) to install the composer-asset-plugin:
composer global require "fxp/composer-asset-plugin:^1.2.0"
(See http://www.yiiframework.com/doc-2.0/guide-start-installation.html#installing-from-composer for latest version.)
You may also need to add the following code to your project's composer.json file :
"extra": {
"asset-installer-paths": {
"npm-asset-library": "vendor/npm",
"bower-asset-library": "vendor/bower"
}
}
Hopes this helps :)
For me helps to remove folder ~/.composer and execute command:
php composer.phar global require "fxp/composer-asset-plugin:1.*"
Then just run again
php composer.phar update
Found a cleaner solution. Just add following repository in your composer.json file
"repositories": [
{
"type": "composer",
"url": "https://asset-packagist.org"
}
]
and watch the magic
If you don't want to use fxp/composer-asset-plugin then all you have to do is to follow these simple instructions from Yii2 documentation.
Using asset-packagist repository
This way will satisfy requirements of the majority of projects, that need NPM or Bower packages.
Note: Since 2.0.13 both Basic and Advanced application templates are
pre-configured to use asset-packagist by default, so you can skip this
section.
In the composer.json of your project, add the following lines:
"repositories": [
{
"type": "composer",
"url": "https://asset-packagist.org"
}
]
Adjust #npm and #bower aliases in you application configuration:
$config = [
...
'aliases' => [
'#bower' => '#vendor/bower-asset',
'#npm' => '#vendor/npm-asset',
],
...
];
Visit asset-packagist.org to know, how it works.
If you don't need the update for bower-asset, you can require yidas/yii2-composer-bower-skip before yiisoft/yii2. in composer.json file:
"require": {
"php": ">=5.4.0",
"yidas/yii2-composer-bower-skip": "~2.0.0",
"yiisoft/yii2": "~2.0.5",
"yiisoft/yii2-bootstrap": "~2.0.0"
}
After that, you can update Composer smoothly without bower-asset.
See https://github.com/yidas/yii2-composer-bower-skip
Just in case for anyone upgrading Yii 2.0.41 - 2.0.43,
should be noted that you need to install the "external" bower-asset.
Run the following
composer require yidas/yii2-bower-asset
Then, need to update the aliases inside config (depends on your structure) for the Yii to handle the new bower-asset folder.
// here is important part
'aliases' => [
'#bower' => '#vendor/yidas/yii2-bower-asset/bower',
],
//below is just another config just ignore. example purpose don't copy
'components' => [
'db' => [
Then, reload your Yii app. Should be fine.
-Extra-
Here is the example of the composer.json for anyone who need the updates to 2.0.43
{
"name": "yiisoft/yii2-app-advanced",
"description": "Yii 2 Advanced Application Template",
"keywords": ["yii2", "framework", "advanced", "application template"],
"homepage": "http://www.yiiframework.com/",
"type": "project",
"license": "BSD-3-Clause",
"support": {
"issues": "https://github.com/yiisoft/yii2/issues?state=open",
"forum": "http://www.yiiframework.com/forum/",
"wiki": "http://www.yiiframework.com/wiki/",
"irc": "irc://irc.freenode.net/yii",
"source": "https://github.com/yiisoft/yii2"
},
"minimum-stability": "dev",
"require": {
"php": ">=5.4.0",
"yiisoft/yii2": "2.0.43",
"yiisoft/yii2-bootstrap": "*",
"yiisoft/yii2-swiftmailer": "~2.0#dev",
"yiisoft/yii2-redis": "~2.0.0",
"yiisoft/yii2-elasticsearch": "~2.0.0",
"bryglen/yii2-apns-gcm": "1.0.5",
"snhccm/baidu-push": "dev-master",
"google/cloud": "dev-master",
"minishlink/web-push": "6.0.7",
"understeam/yii2-fcm": "~0.1",
"yidas/yii2-bower-asset": "2.0.13"
},
"require-dev": {
"codeception/codeception": "*",
"yiisoft/yii2-debug": "*",
"yiisoft/yii2-gii": "*",
"yiisoft/yii2-faker": "*"
},
"config": {
"process-timeout": 1800
},
"extra": {
"asset-installer-paths": {
"npm-asset-library": "vendor/npm",
"bower-asset-library": "vendor/bower"
}
}
}
As described in YII2 repository documentation: https://asset-packagist.org/site/about
We can solve this problem by adding aliases on those folders in our config.
It will looks like that:
$config = [
...
'aliases' => [
'#bower' => '#vendor/bower-asset',
'#npm' => '#vendor/npm-asset',
],
...
];
It works perfectly!
Simple and clean solution:
In composer.json just replace the bower-asset/jquery line with:
"yidas/yii2-bower-asset":"*"
I propose we add also bower-asset/datatables to the yidas/yii2-bower-asset
My Problems with accepted solution of adding fxp/composer-asset-plugin are that the plugin is significantly slowing down the composer system, impacts everywhere, isn't always portable across operating systems and environments, has errors with PHP7.2 relating to inconsistent method names. So, I prefer my quicker to develop, faster at runtime, more local, and more compatible solution.
I tried all the mentioned steps like adding following in main.php
$config = [
...
'aliases' => [
'#bower' => '#vendor/bower-asset',
'#npm' => '#vendor/npm-asset',
],
...
];
composer.json
"repositories": [
{
"type": "composer",
"url": "https://asset-packagist.org"
}
]
Doing "composer install/update" was still not installing bower packages given by yii2-bootstrap.
I found, I was using composer.phar 2x to set this up. I downgraded composer.phar to 1x and all works well without having the need of fxp/composer-asset-plugin plugin.
I've forked https://github.com/jasonlewis/basset and is now trying to add my fork to my project. But it doesn't seem to read my forked composer.json file after I've run composer update, why? What am I doing wrong?
I've added this repository after require: {}:
"repositories": [
{
"type":"package",
"package": {
"name": "marwelln/basset",
"version":"master",
"source": {
"url": "https://github.com/Marwelln/basset.git",
"type": "git",
"reference":"master"
}
}
}
],
My forked composer.json looks like this (nothing is changed from the original except name):
{
"name": "marwelln/basset",
"description": "A better asset management package for Laravel.",
"keywords": ["assets", "basset", "laravel"],
"license": "BSD-2-Clause",
"authors": [
{
"name": "Jason Lewis",
"email": "jason.lewis1991#gmail.com"
}
],
"require": {
"php": ">=5.3.0",
"kriswallsmith/assetic": "1.1.*"
},
"require-dev": {
"mockery/mockery": ">=0.7.2",
"illuminate/config": "4.0.*",
"illuminate/console": "4.0.*",
"illuminate/filesystem": "4.0.*",
"illuminate/log": "4.0.*",
"illuminate/routing": "4.0.*",
"illuminate/support": "4.0.*",
"symfony/process": "2.3.*"
},
"suggest": {
"aws/aws-sdk-php": "Deploy static assets directly to your S3 buckets.",
"rackspace/php-cloudfiles": "Deploy static assets directly to your Cloud Files container."
},
"autoload": {
"psr-0": {
"Basset": "src/"
},
"classmap": [
"tests/Cases/FilterTestCase.php"
],
"files": ["src/helpers.php"]
},
"extra": {
"branch-alias": {
"dev-master": "4.0-dev"
}
},
"minimum-stability": "dev"
}
With this, the Basset namespace isn't registered in autoload_namespace.php nor am getting "kriswallsmith/assetic": "1.1.*", but if I use the original require: { "jasonlewis/basset" : "dev-master"} it adds it just fine. What is it I'm missing?
You've done some things that are considered not the best practice with Composer.
First of all, you should try to avoid including repositories of the type "package" with all the details of where to find the stuff you need. This will become a maintenance nightmare in the long run. Packages should only be included in your composer.json if you are absolutely sure the maintainer of the software will not include a composer.json file himself. The documentation states on http://getcomposer.org/doc/04-schema.md#repositories:
package: If you depend on a project that does not have any support for composer whatsoever you can define the package inline using a package repository. You basically just inline the
composer.json object.
This case does not apply here, because you maintain the repository to be used yourself and should be able to put in a composer.json.
Now the process of forking and extending an existing library and then using that within your code is supported by Composer, but not the way you did it. First of all, you SHOULD replace the name of the vendor, because you take over that role, and your repository and the software should be distinguishable from other packages. So it is the correct thing to rename "jasonlewis/basset" into "marwelln/basset" and only use that name if you want to reference your own version.
Now the problem might be that if you forked a popular library, and are using other libraries that do require the original, you'll end up adding both packages. That's what the "replace" field is for: You can state in your own composer.json that you think your package is able to replace the original software. Some details are here: http://getcomposer.org/doc/04-schema.md#replace
I gave a detailed answer on how "replace" works here: How does the "replace" property work with composer?
In the end, I think you should do the following (and you still can change that):
Clone the original, change the composer.json to bear your own vendor name as the "name" and add a "replace" with the version of the original software you are changing. You should probably be strict about the version, because you really only replace the version you know about. If later you still know you replace a newer version, you can change the "replace" info.
Then you have to add your own repository as you did, and require the software name with your own vendor name.
You probably did most of that at some point in time, but the step with adding the replacement info is the missing link.
I changed repository to this:
"repositories": [
{
"type":"vcs",
"url": "https://github.com/Marwelln/basset"
}
],
And then used jasonlewis/basset instead of marwelln/basset. It's now working as it should.