Composer won't update due to changes on the current branch - php

We have composer as our dependency injection framework which will pull in a library we created, foobar, which works fine. The library foobar has 14 version v1.1.1 -> v1.1.14. All the way up to .12 composer updated the app fine. But now we are getting this error:
Update failed (Source directory /home/username/dev/git/appname/vendor/foorbar/library has unpushed changes on the current branch:
Branch v1.1.14 could not be found on the origin remote and appears to be unpushed)
The composer.json:
{
"name": "App",
"description": "Foo Bar",
"require": {
"php": ">=5.3.3",
"zendframework/zendframework": "2.2.",
"foobarzf2lib/library": "v1.1."
},
"minimum-stability": "stable",
"repositories": [
{
"type": "package",
"package": {
"name": "foobarzf2lib/library",
"version": "v1.1.14",
"source": {
"url": "https://git-codecommit.eu-west-1.amazonaws.com/v1/repos/foobarzf2lib",
"type": "git",
"reference": "test"
},
"autoload": {
"psr-4": {
"FooBar\\" : "FooBar/"
}
}
}
}
]
}
More things to know:
Vendor is ignored in git.
Tried doing $ composer.phar clearcache.
Would be ideal to not have to delete the library every time.

Remove vendor folder and reinstall packages.

Branch v1.1.14 could not be found on the origin remote and appears to be unpushed)
This means that wherever you're pulling the package from does not have a v1.1.14.
Make sure you push v1.1.14 to the package provider and everything should be fine.

Composer treats the local repository (the one inside the vendor folder) as leading. Whenever composer thinks it is not connected any longer (or diverged) for the checkout in place, it refuses to update (which I think is good and sane).
This may seem cumbersome but that is perhaps the price to pay for the ease of use. Composer is actually managing that git checkout while taking care of updates (it has various remotes configured and then a cache, all without additional setup).
In my case I can see similar errors (not the exact error message as asked about, I get a notification one or some files were changed without any direct changes when the remote did change non-fast-forward) and I resolved it the following way (perhaps it works in case of a missing branch, too? Nevertheless reviewing the issue with a git command similar to the following might shed better insights):
git -C <path> pull && composer update
Could work then, where <path> is the directory path given in composers' error message. If it does not, a more specific error message from git hopefully says more.
Point in case is that you need to resolve the version conflict before composer continues. That is similar when you have a merge conflict in git, you can't do the next commit without resolving it as otherwise you'd have files in the repository with merge conflict markers (and won't compile).
In case of interest, one aspect of my git configuration is pull.rebase=merges. That is in principle to do a rebase on pull (IIRC perhaps preserving some merges).
As an alternative - and similar to removing the whole vendor folder - removing just the reported path should work. As this is git, that repository is gone and as composer was concerned of it, it is not any longer:
rm -rf -- <path> && composer update
where <path> is (must be) the path in the composer error message. Take care with rm -rf, it can be easily over-reaching - just fyi.
(this is similar to the reported resolution in composers issue tracker)

Related

Instruct composer to use different class when ambiguous

When performing a composer update, I received the following warning:
Warning: Ambiguous class resolution, "Normalizer" was found in both "/var/www/concrete5/vendor/patchwork/utf8/src/Normalizer.php" and "/var/www/concrete5/vendor/voku/portable-utf8/src/Normalizer.php", the first will be used.
The site is now experiencing errors which I think might be related.
How can I instruct composer to use the second file (i.e. /var/www/concrete5/vendor/voku/portable-utf8/src/Normalizer.php) instead of the first?
Note that I have tried adding the following to exclude-from-classmap to composer.json and while it suppresses the warning, doesn't appear to have any impact.
"autoload-dev": {
"psr-4": {
"ConcreteComposer\\" : "./tests"
},
"exclude-from-classmap": [
"vendor/patchwork/utf8/src/Normalizer.php"
]
},
exclude-from-classmap has effect only when classmap is used for autoloading specified class. In your case class is loaded using PSR rules, but you may use optimized autolader, which generates classmap for all classes:
composer install -o
Also, since you placed this rule inside of autoload-dev, it will not have effect when you run composer install with --no-dev flag.

Symfony 4.x public dir rename to public_html

I got a little struggle with renaming dir to public_html for web host.
According to latest tutorial I'm trying to successfully rename it, but every time when i'm trying to run local server using console command I'm getting an error:
[ERROR] The document root directory ".../.../App/public" does not exist.
I'm sure that I'm doing something wrong with code. But I don't know where. I'm very beginner with Symfony.
Here's my code from composer.json:
"extra": {
"symfony": {
"allow-contrib": false,
"require": "4.2.*",
}
"public-dir": "public_html"
},
Did I understood something wrong with it?
Thanks for help.
If the code snippet represents exactly what you have in your composer.json then I have noticed that it is not correctly formatted json file. In the "extra", after the value of "symfony" key, you need to put a separator "," then in the next line you may add more key:value pairs. AS in:
"extra": {
"symfony": {
"allow-contrib": false,
"require": "4.2.*",
},
"public-dir": "new_public_html_dirname"
}
A not well formatted json file will prevent it from being executed. I hope it helps.
It is important to run composer update.
composer update
As the index.php file is the first file being run (by the webserver) you should just be able to rename the public directory to public_html and it will work, and not need to change anything in the composer.json (though how that would affect the framework code, without at least running any composer-scripts, I do not know).
I've just created a new Symfony 4.2.3 project, and done nothing more than renaming the directory, and running (most) bin/console commands are not affected.
The in-built server will have issues, but you can tell it which directory to use as the docroot with:
mv public public_html
bin/console server:start --docroot=public_html/
[OK] Server listening on http://127.0.0.1:8000
The changes to composer.json are not required.

How do I install my github project to the root directory with composer? [duplicate]

This question already has an answer here:
Project Structure with composer
(1 answer)
Closed 4 years ago.
I'm making a request handler for php, which will route requests to specific files on the server. I have a .htaccess file that routes every request to DOCUMENT_ROOT/Server/handleRequest.php, which then handles everything else from there. To make this work, I copy the .htaccess file and Server folder to the root folder for my site.
I've been successful in getting composer to install my project to the vendor directory under vendor/JakarCo/PHP-Request-Handler. I would like all the files (at the very least, the .htaccess file) to be installed directly into the site's document root folder (one level above the vendor folder).
I am trying to use oomphinc/composer-installers-extender to set a custom path, and it's not working, and I can't figure out how to fix it.
The composer.json in the request handler is
{
"name": "JakarCo/PHP-Request-Handler",
"description": "php request handler",
"type": "library",
"license": "proprietary",
"require": {
"php": "^5.3.6 || ^7.0",
"oomphinc/composer-installers-extender": "#dev"
},
"extra": {
"installer-types": ["library"],
"installer-paths": {
"my/path/": ["JakarCo/PHP-Request-Handler/"],
"path/to/libraries/JakarCo/": ["type:library"]
}
}
}
The composer.json for the project that is including the request handler is:
{
"repositories": [
{
"url": "https://github.com/JakarCo/PHP-Request-Handler",
"type": "vcs"
}
],
"require": {
"JakarCo/PHP-Request-Handler": "dev-master"
}
}
When I run composer update from from the site's root folder, it runs successfully (now with nothing to change). So I deleted the vendor folder and the composer.lock file and ran composer install and had three successful installs, of composer/installer, the oomphinc one, and mine. But mine is still going into the vendor/JakarCo/PHP-Request-Handler, when the Server folder and .htaccess files need to go into the site's root folder.
I suspect my problem is with installer-paths, but I can't figure out how it's supposed to be. Also, I'm probably not supposed to use #dev for the oomphinc version, but I don't know what else to put.
I'm experienced with PHP, but very out of practice, and am new to using composer and git.
UPDATE
This turned out bad. Very bad lol. The composer.json from the request handler project overwrote the composer.json file that i was using to include it.
--
I wrote my own installer using https://getcomposer.org/doc/articles/custom-installers.md as a guide, just copy-pasting what they had.
Important notes: The composer.json for the site I'm working on requires a pointer to the Request Handler and a pointer to the Request Handler installer as below. I tried to put the pointer to the installer in the request handler project, but I later read that the repositories part is only read by the root composer. That is, the composer.json file in the working directory from which you call composer install/composer update. Alternatively, the installer project can be added to packagist then the Request Handler project would be able to require it directly.
I had a hard time getting the installer to start working. That's because the $packageType passed to supports() in the installer is lower case, and the type i specified includes uppercase, so the return $packageType === 'JakarCo-request-installer turned into `return $packageType == strtolower('JakarCo-request-installer').
Another problem I had was composer telling me that the directory name returned by 'getInstallPath' could not be empty, when I was doing return '/'. I changed to return ./ and still had problems. I did composer clear-cache then rm -rf vendor then rm composer.lock then re-rann composer install and now it is working.
This could all be much better, but for now I'm just needing the basic functionality. I will improve the quality of my code later. I'm new to composer and it's all kind of overwhelming, and I find the documentation hard to follow.
{
"repositories": [
{
"type": "vcs",
"url": "https://github.com/JakarCo/PHP-Request-Handler"
},
{
"type": "vcs",
"url": "https://github.com/JakarCo/PHP-Request-Handler-Installer"
}
],
"require": {
"JakarCo/PHP-Request-Handler": "dev-master",
"JakarCo/PHP-Request-Handler-Installer": "dev-master"
}
}
So, the repositories had to be defined in the site project. Defining the repositories in the Request Handler project did nothing and then Request-handler-installer could not be found, because composer does not recursively function in that matter, unless your projects are on packagist, in which case you do not define repositories. Annoying, but workable.

Changing vendor directory can't find files anymore using Symfony 3.4

I'm trying to change the directory of my dependencies on a Symfony 3.4 application.
I need that because I'm working on macOS with Docker and I'd rather have them not shared with the host since the file synchronization is too slow.
The related documentation, says:
The change in the composer.json will look like this:
{
"config": {
"bin-dir": "bin",
"vendor-dir": "/some/dir/vendor"
},
}
That I did
Then, update the path to the autoload.php file in app/autoload.php:
// app/autoload.php
// ...
$loader = require '/some/dir/vendor/autoload.php';
I don't have any autoload.php file in my app directory.
Am I missing something in the doc ?
The application generates the following fatal error:
Warning: require(/some/dir/vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php): failed to open stream: No such file or directory in /vendor/composer/autoload_real.php on line 66
Fatal error: require(): Failed opening required '/some/dir/vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php' (include_path='.:/usr/local/lib/php') in /vendor/composer/autoload_real.php on line 66
I originally created the application with:
$ composer create-project symfony/framework-standard-edition test "3.*"
Open your composer.json file in editor.
Look for "autoload-dev" section
Remove whole "files" part (if exist)
Save file
Run composer install once again
Enjoy the party.
Sample code:
"autoload-dev": {
"psr-4": {
"App\\Tests\\": "tests/"
},
"files": [
"vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php"
]
},
In Symfony 3.4, the file app/autoload.php is removed so you should:
replace old vendor path by the new vendor path directly in web/app.php, web/app_dev.php, bin/console and var/SymfonyRequirements.php files
Rerun the command $ composer install
I had the same issue and it was resolved doing the next.
Follow these 3 steps
1. First of all, modify composer.json to use the new vendor path:
"config": {
...,
"vendor-dir": "/app-vendor"
},
And remove the next line:
"files": ["vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php"]
2. Secondly, if you are using docker-compose add a new volume where you'll put your vendors.
volumes:
...
- /app-vendor
PD: /app-vendor is a mounted volume which is now empty directory.
3. Lastly, write require '/app-vendor/autoload.php'; to:
my_project_name/bin/console
my_project_name/web/app.php
my_project_name/web/app_dev.php
PD1: Simply, this line is pointing to the new vendor path.
PD2: It's not necessary to modify any other file (like var/SymfonyRequirements.php as I could read).
Check your changes
Once the changes are ready, remove vendor/ and also remove the containers to avoid future problems.
Start your new containers and execute composer install. Now, /vendor will be /app-vendor, it won't be in the root folder of the project anymore.
For more details, I'd recommend you to go to my docker-symfony repository and check the commits. You'll see a benchmark progression and another tips like cached volumes and non-shared /cache && /logs folders.
All for Symfony 3.4.

Laravel Controller load files due to ClassLoader and incorrect composer files

Ok, newbie at Laravel. I used composer to download laravel. It created a directory structure like...
vendor\laravel\laravel\app
vendor\laravel\laravel\bootstrap
vendor\laravel\laravel\public
vendor\laravel\framework\....
vendor\laravel\laravel\composer.json
along with many other vendor and laravel directories.
and where my initial composer.json file was in the root directory.
I moved the contents of the vendor\laravel\laravel directory to the top level so that I have a directory structure like...
app\...
bootstrap\...
public\...
vendor\laravel\framework\...
composer.json
vendor\ many other directories...
I updated the index.php directory so that it referred to the new locations of the bootstrap\autoload.php and bootstrap\start.php directories.
I can load the index.php and I get the Laravel image map signifying that all is working.
So, now I go and modify the routes.php to be...
Route::controller('home', 'HomeController');
and try to load the home directory. I get the error...
"include(D:\dev\wamp\www\ltest3\vendor/laravel/laravel/app/controllers/BaseController.php): failed to open stream: No such file or directory"
The problem is that the vendor\composer\autoload_classmap.php still has the old laravel\app controller mappings. e.g.
return array(
'BaseController' => $vendorDir . '/laravel/laravel/app/controllers/BaseController.php',
'DatabaseSeeder' => $vendorDir . '/laravel/laravel/app/database/seeds/DatabaseSeeder.php',
'HomeController' => $vendorDir . '/laravel/laravel/app/controllers/HomeController.php',
instead of the new location at /app/controllers/
If I try to run composer update on the composer.json in my root directory, I get error after awhile of processing...
Failed to execute git status --porcelain --untracked-files=no
So, not sure how to get composer to update the autoload classmap to use my new directory location.
Do people normally leave the vendor\laravel\laravel directory in is original location?
Seems that the composer will probably attempt to update the laravel directory again, but not sure since I get the error.
Here is my full composer.json in the root directory. This was the one that was originally in the vendor\laravel\laravel directory and created by other initial composer run, maybe that is problem.
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
"laravel/framework": "4.1.*"
},
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php"
]
},
"scripts": {
"post-install-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-update-cmd": [
"php artisan clear-compiled",
"php artisan optimize"
],
"post-create-project-cmd": [
"php artisan key:generate"
]
},
"config": {
"preferred-install": "dist"
},
"minimum-stability": "stable"
}
All vendor files whether they belong to Laravel or third party should be in the same location /vendor. This is not just a amtter of mapping in bootstrap but this is important for when you need to update any package in composer. You might need to do this on a delicate environment so why not keep it as it should be? Is there a reason?
Composer is used on many other frameworks and I believe that in all of them you need a vendor directory.
Got it working, thanks to Cryode and user2094178 pointing out that my directory structure was not correct to start off with. I am going to go over several of the issues that I ran into, hopefully helping others that may have the same problem. fyi, this is on Windows 7 running WAMP.
I think where things all went wrong was that I tried to install Laravael by creating a composer.json file with a require of laravel. When running composer, it didn't know that I wanted Laravel as my main project framework, so it just installed all of Laravel down in the vendor directory. There were no top-level app, bootstrap, public, etc. directories.
Scrapped this install and started off from scratch using the directions specified at http://geekanddummy.com/how-to-laravel-4-tutorial-part-1-installation/ (e.g. ran composer create-project laravel/laravel). Ran into the following issues...
1) composer/git complains about https issues. composer continued with warnings on every download but continued to download files using http. When it got to symfphony filesystem.git, it got a fatal error
Failed to clone git#github.com:symfony/Filesystem.git via git, https, ssh protocols, aborting
To resolve this I ran a small php script that output phpinfo(). Determined the location of my php.ini file and removed the comment for "extension=php_openssl.dll". I had already done this for WAMP and Apache, but found out PHP at the command line was using a different php.ini
2) Did a test of git and ssl using "ssh git#github.com" at the command line. Had an issue that it could not authenticate, permission denied. Added environment variable HOME, set it to ..
set HOME=%HOMEPATH%
After this, ssh worked and added an ssh key successfully for github.
3) Deleted the entire project directory and started back from scratch, did not see a way to recover and continue. Next issue was that I got a git error "exceeded the timeout of 300 seconds" when retrieving symfony/Filesystem.git. Fixed this by adding the following composer environment variable..
set COMPOSER_PROCESS_TIMEOUT=2000
4) Deleted entire project and started again from scratch. All was downloaded fine this time. I have the top level app, bootstrap, public, and vendor directories. Loading the laravel\public\index.php works, I see the "You have arrived" page.

Categories