Error in composer.json file after installing module - php

I have run the command to run composer require phpmailer/phpmailer which created a file composer.json and composer.lock, however, the first one shows an error in the opening bracket { and says "Missing property name, missing property description". Why doesn't add those properties automatically or how to add them in a proper way so I don't cause any other issue?
{
"require": {
"phpmailer/phpmailer": "^6.1"
}
}

Related

Why does 'composer dumpautoload -o' fix 'Class not found' PHP error?

I have a Laravel 5.8 project that is dependent on a private package.
When I run composer install the package is installed and shows up in the vendor folder.
project composer.json
{
...
"require": {
"php": ">=7.0",
"company/api-request": ">=1.0.0"
}
...
}
package src/ApiRequest.php
<?php
namespace Company;
class APIRequest
{
...
}
package composer.json
{
...
"autoload": {
"psr-4": {
"Company\\": "src/"
}
}
...
}
When I call the package
\Company\APIRequest::run();
I am getting
Message: Class 'Company\APIRequest' not found
I know the PHP syntax is correct because when I run composer dumpautoload -o the error is gone, but why is it necessary?
I expect composer install or composer update should be sufficient; I have no problem with external packages.
Am I missing anything here?
If the class name and file name don't match, that would cause the auto-loading to not work since that is a requirement with PSR-4. From the docs:
The terminating class name corresponds to a file name ending in .php. The file name MUST match the case of the terminating class name.
If that's the case, composer dumpautoload -o is probably working around this for you, see this Reddit post:
The reason -o works, is Composer creates a giant associative array where classname = filename

Adding git repository with Composer for development branch where no composer.json present

I have been trying to install a git repository that does not have a composer.json file. I followed the instructions on the composer website and also found in this stackexchange post: Composer - adding git repository without composer.json
However, I am still not able to get it to work. I keep getting an error stating: "The requested package phpredis/phredis could not be found in any version, there may be a typo in the package name.
This is my composer.json file on my system (note that predis/predis loads fine but I want to use the other redis package):
{
"respositories": [
{
"type":"package",
"package":
{
"name":"phpredis/phpredis",
"version":"develop",
"dist":
{
"url":"https://github.com/phpredis/phpredis.git",
"type":"git"
}
}
}
],
"require": {
"predis/predis": "^1.0",
"phpredis/phpredis":"dev-master#dev"
}
}
I know that I must be making a simple error somewhere but I have spent hours and can't figure it out. Thanks for the help.
It's useless to fiddle with any composer.json replacement for this repository because it contains C software that needs to be compiled and installed as a PHP extension. Composer won't do this for you, it can only manage PHP source code.

Class 'Pimple\Container' not found

I am trying to install Pimple in my project following https://github.com/silexphp/Pimple readme file.
Error message I receive is:
Fatal error: Class 'Pimple\Container' not found in E:\www\public\index.php on line 9
My composer.json file is:
{
...
"require-dev": {
"phpunit/phpunit": "5.1.*"
},
"require": {
"pimple/pimple": "~3.0"
}
}
When I do:
composer update
or
composer install
the message is: Nothing to install or update
In vendor/bin I can see only phpunit files. I can see however pimple in composer.lock
My PHP index.php file:
<?php
use Pimple\Container;
$co = new Container();
?>
Could you please help me make it work?
vendor/autoload.php was not included and this caused the error.
Try to delete Vendor content, and install dev again througth composer.

Have Composer auto-load PEAR's code (e.g. PEAR.php) for archive_tar from within vendor directory?

I have a development machine with PEAR installed on it (in /usr/share/php/PEAR.php) and a production system without PEAR installed on it.
On the production box, I get this error that I don't get on the dev machine:
A PHP Error was encountered
Severity: Warning
Message: require_once(PEAR.php): failed to open stream: No such file or directory
Filename: Archive/Tar.php
Line Number: 42
Fatal error: require_once(): Failed opening required 'PEAR.php' (include_path='.:') in /www/application/vendor/pear/archive_tar/Archive/Tar.php on line 42
See line 42 here: https://github.com/pear/Archive_Tar/blob/master/Archive/Tar.php#L42
I don't want to install PEAR on the production box because it's installed system wide. It seems much cleaner to me if I can install PEAR.php and all its associated files from composer itself.
All the questions relating to Composer and PEAR that I can find are related to installing the package from Composer.
But what I want to do is have Composer auto-load the PEAR code from within the project's vendor directory so that I don't have to globally install PEAR on the production system.
There's a practically identical question here: How do I get PEAR.php with Composer?
But it looks like he's accepted his own answer which didn't even fix the problem.
My composer.json looks like:
{
"require": {
"pear/archive_tar": "*",
}
}
It seems like, if what I propose is possible, I would add "pear/pear" or something to require and it would install the PEAR code itself in the project directory, but I can't find such a package.
Eventually found a Github gist where someone listed "pear-pear/PEAR" as the package you need:
}
"repositories": [
{
"type": "pear",
"url": "http://pear.php.net"
}
],
"require": {
"pear-pear/PEAR": "*",
"pear/archive_tar": "*"
}
}
I found the secret sauce: Composer doesn't actually seem to honor 'pear' as the alias for pear.php.net. So if you want pear (but not pear2)-style dependencies, here's my snippet:
"repositories": [
{
"type": "pear",
"url": "https://pear.php.net"
}
],
"require": {
"pear-pear.php.net/PEAR": "*",
"pear-pear.php.net/archite_tar": "*"
}
Note that the url must be 'https' or composer will complain and/or fail.

composer does not generate autoload.php

i install composer for windows using this link http://getcomposer.org/download/ > http://getcomposer.org/Composer-Setup.exe
my web server is WAMP php 5.4 with openssl enabled.
i created composer.json with this code
{
"require": {
"doctrine/orm": "*"
}
}
and run with this code in .php file
<?php
// bootstrap.php
// Include Composer Autoload (relative to project root).
require_once "vendor/autoload.php";
and i got error Warning: require_once(vendor/autoload.php): failed to open stream
how to get composer's autoload.php?
why composer does not generate it?
how to use doctrine without composer?
Did you actually look to see if a vendor/autoload.php was created?
Did composer throw any error messages? Unless you got an error then I'm willing to bet that a vendor/autoload files was made. Is there anything in vendor?
I'm guessing that your bootstrap.php is not in your root directory (same directory as composer.json). If so you need to adjust the path in your require statement.
Remove the autoload part from your composer.json, then run composer install
This will generate an updated autoload object, good luck!
"autoload": {
"classmap": [
"..."
]
}

Categories