I'm currently writing an install script for our platform, and it needs to be able to create a composer.json file, and then run Composer. I've done that and it works fine, for the most part. The issue I'm having is that one of our dependencies runs a task upon installation of every subsequent package (for copying over config yaml files to the main project's directory), using Composer's script option. So for instance, in the generated Composer.json file is a bit that looks like this:
"scripts": {
"post-package-install": [
"Super\\Cool\\Task::postInstall"
],
"pre-package-update": [
"Super\\Cool\\Task::preUpdate"
],
"post-package-update": [
"Super\\Cool\\Task::postUpdate"
]
},
If I delete the vendor folder and then run Composer manually within the directory, the events work fine, but running it from my install script leaves me with an error message of
Class Super\Cool\Task is not autoloadable, can not call post-package-install script.
My only feeling is that perhaps Composer is trying to run its autoloader from the location of within my script, rather than the location of the composer.json file, but that's just a hunch
Does anyone know a way around this? Or is this a bug within Composer?
Just an update, it turns out this was an issue that has already been fixed. Running composer self-update fixed it
Related
I'm writing a package for Packagist and I'm facing a problem with Composer. I need to copy a file from my package to the project root after install, but nothing is happening after the package installation.
After reading Composer documentation, I found that I should put a script inside the event post-install-cmd, inside the script section into composer.json file.
So, I added this to my package composer.json file
"scripts": {
"post-install-cmd": [
"php -r \"copy('vendor/myvendor/mypackage/myfile', 'myfile');\""
]
}
To install the package I'm doing
$ composer require myvendor/mypackage --dev
After the package installation everything seems fine, but the file is not being copied and no error is shown.
See https://getcomposer.org/doc/articles/scripts.md for the documentation of scripts. The most relevant part is:
Note: Only scripts defined in the root package's composer.json are
executed. If a dependency of the root package specifies its own
scripts, Composer does not execute those additional scripts.
So, you cannot define any scripts in your module. There is a bug report about that, but the maintainer of composer is not a friend of executing the scripts of dependencies
I have built some migration classes in my application to create the tables I need, but I keep getting errors. I need to run this command:
composer dump-autoload
Only then it works again as expected. Am I doing something wrong that generates this error or this is a normal behaviour with migrations?
Below is the error that I get when running the migration process:
[Symfony\Component\Debug\Exception\FatalErrorException]
Class 'CreateVideoStatusTable' not found
OK so I think i know the issue you're having.
Basically, because Composer can't see the migration files you are creating, you are having to run the dump-autoload command which won't download anything new, but looks for all of the classes it needs to include again. It just regenerates the list of all classes that need to be included in the project (autoload_classmap.php), and this is why your migration is working after you run that command.
How to fix it (possibly)
You need to add some extra information to your composer.json file.
"autoload": {
"classmap": [
"PATH TO YOUR MIGRATIONS FOLDER"
],
}
You need to add the path to your migrations folder to the classmap array. Then run the following three commands...
php artisan clear-compiled
composer dump-autoload
php artisan optimize
This will clear the current compiled files, update the classes it needs and then write them back out so you don't have to do it again.
Ideally, you execute composer dump-autoload -o , for a faster load of your webpages. The only reason it is not default, is because it takes a bit longer to generate (but is only slightly noticable).
Hope you can manage to get this sorted, as its very annoying indeed :(
You should run:
composer dump-autoload
and if does not work you should re-install composer
Short answer: classmaps are static while PSR autoloading is dynamic.
If you don't want to use classmaps, use PSR autoloading instead.
My error was placing a function inside config/fortify.php, in my case it was an anonymous function that gave the error.
The definitive solution for this is to see what files I normally modify in the config/ folder.
In many places they say delete the files from bootstrap/cache/* but it didn't work in my case, and it didn't really make sense. In any case I leave you the commands:
php artisan clear-compiled
composer dump-autoload
php artisan optimize
But I really recommend that you go through the base laravel config files that you have configured. here you will find the error.
Asked Here but no proper response.
Hi, When I tried to use paypal sdk, and when I tried to submit the details, it is showing this error.
Fatal error: require(): Failed opening required '/home/wwwrapid/public_html/test/samples/vendor/paypal/paypal-merchant-sdk-php-4f570f5/lib/services/PayPalAPIInterfaceService/PayPalAPIInterfaceService.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/wwwrapid/public_html/test/merchant-sdk-php-master/samples/PPAutoloader.php on line 451
When I go through the folders path, I dont find any folder named 'vendor'.
I have been searching the solution for this for two days. Some sites say it's a composer error and installing composer solves the issue. and this is the code for that.
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
My problem is I am not able to understand what they mean? I don't even know where to add this code? I mean in which file? How can that composer be installed on my site?
If you're on Windows the easiest thing to do is download the Windows installer and use it.
In order for Composer to install, though, you're going to need PHP installed. The easiest way to do this is to just configure a local server setup using WAMP or something similar. You'll need do that prior to installing Composer.
Once all of that is done you'll be able to utilize Composer to manage PHP packages within your projects. It's really pretty awesome stuff, but it can be a little confusing if you've never worked with it before.
Basically, once it's installed, you can just create a composer.json file at your project root. This file is basically a config file that tells Composer what PHP packages you want to use (among other things.)
For PayPal's SDK you could setup a composer.json file with nothing but this in it:
"require": {
"php": ">=5.3.0",
"ext-curl": "*",
"ext-json": "*",
"paypal/rest-api-sdk-php" : "0.5.*"
}
Then, from the command line, you can browse to the project root (where the composer.json file is) and run "composer update".
This would look at the composer.json file and download any/all packages that are required based on that line. In this case it would be pulling in the PayPal REST API SDK, and then all of the samples that PayPal provides would work for you.
Composer is what creates that /vendor directory and sets up an autoloader for you. Hope that helps.
A developer has sent me his project to work with, but when ever I try to update or install my vendors everything works great until the very end and it outputs the message bellow.
C:\xampp\htdocs\BigWaveMedia\davinkit>php artisan migrate
{
"error": {
"type": "Exception",
"message": "expected color value: failed at `.clearfix;` C:\\xampp\\htdocs\\BigWaveMedia\\davinkit\\app\\start\/..\/..\/public\/less\/style.less on line 102",
"file": "C:\\xampp\\htdocs\\davinkit\\vendor\\leafo\\lessphp\\lessc.inc.php",
"line": 3258
}
}
C:\xampp\htdocs\BigWaveMedia\davinkit>
Any ideas at all? Here is a full log http://pastebin.com/y9q4Rc5z
When you run composer update, composer generates a file called composer.lock which lists all your packages and the currently installed versions. This allows you to later run composer install, which will install the packages listed in that file, recreating the environment that you were last using.
It appears from your log that some of the versions of packages that are listed in your composer.lock file are no longer available. Thus, when you run composer install, it complains and fails. This is usually no big deal - just run composer update and it will attempt to build a set of packages that work together and write a new composer.lock file.
However, you're running into a different problem. It appears that, in your composer.json file, the original developer has added some pre- or post- update actions that are failing, specifically a php artisan migrate command. This can be avoided by running the following: composer update --no-scripts
This will run the composer update but will skip over the scripts added to the file. You should be able to successfully run the update this way.
However, this does not solve the problem long-term. There are two problems:
A migration is for database changes, not random stuff like compiling assets. Go through the migrations and remove that code from there.
Assets should not be compiled each time you run composer update. Remove that step from the composer.json file.
From what I've read, best practice seems to be compiling assets on an as-needed basis during development (ie. when you're making changes to your LESS files - ideally using a tool like gulp.js) and before deployment.
The following works for me:
composer update --no-scripts
this is command for composer update please try this...
composer self-update
write this command in your terminal :
composer update
You can use :
composer self-update --2
To update to 2.0.8 version (Latest stable version)
I'm trying to use PHP PhantomJS but it's require some package to run ..
I'm composer in php and when I'm trying to install dependencies on root PHP PhantomJS
composer install
says
Loading composer repositories with package information
Installing dependencies (including require-dev)
Nothing to install or update
Generating autoload files
I'm confused ... anybody can help how install package that's need to run PHP PhantomJS script?
If you downloaded it, you have everything you need without using Composer. Composer is for downloading this and other packages, but this is not the only way of getting packages. :)
Now the easiest way to use that package is to have a new clean empty directory and execute this line:
composer require jonnyw/php-phantomjs:2.*
Now magic happens, including the creation of a composer.json file, download of that package, creation of autoloading files, and then you are done.
With an otherwise empty directory you couldn't do very much, so in order to make use of that package (or others) inside your own code, go to the root directory of your code, and execute above line. The same things happen, and then you are pretty much done - apart from the fact that you need to include the autoloader file in your own code if you want to use that package.
Install PhantomJS via Composer
Use the package "jakoch/phantomjs-installer".
It installs the PhantomJS binary for Linux, Windows or Mac into the /bin folder of your project.
Simply add the following lines to your projects composer.json file:
{
"require": {
"jakoch/phantomjs-installer": "3.0.0"
},
"scripts": {
"post-install-cmd": [
"PhantomInstaller\\Installer::installPhantomJS"
],
"post-update-cmd": [
"PhantomInstaller\\Installer::installPhantomJS"
]
},
"config": {
"bin-dir": "bin"
}
}
The version number determines which version of PhantomJS is fetched.
Execute composer update or composer install