mirror of
https://github.com/codeguy/php-the-right-way.git
synced 2025-08-06 05:57:26 +02:00
Fix PEAR with Composer
Composer version 2 removed PEAR support.
This commit is contained in:
@@ -40,19 +40,28 @@ installing. See the [Using channel docs][4] for more information on this topic.
|
||||
### Handling PEAR dependencies with Composer
|
||||
|
||||
If you are already using [Composer][5] and you would like to install some PEAR code too, you can use Composer to
|
||||
handle your PEAR dependencies. This example will install code from `pear2.php.net`:
|
||||
handle your PEAR dependencies. PEAR repositories are no longer directly supported by Composer version 2, so you must manually add a repository to install PEAR packages:
|
||||
|
||||
{% highlight json %}
|
||||
{
|
||||
"repositories": [
|
||||
{
|
||||
"type": "pear",
|
||||
"url": "https://pear2.php.net"
|
||||
"type": "package",
|
||||
"package": {
|
||||
"name": "pear2/pear2-http-request",
|
||||
"version": "2.5.1",
|
||||
"dist": {
|
||||
"url": "https://github.com/pear2/HTTP_Request/archive/refs/heads/master.zip",
|
||||
"type": "zip"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"pear-pear2/PEAR2_Text_Markdown": "*",
|
||||
"pear-pear2/PEAR2_HTTP_Request": "*"
|
||||
"pear2/pear2-http-request": "*"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {"PEAR2\\HTTP\\": "vendor/pear2/pear2-http-request/src/HTTP/"}
|
||||
}
|
||||
}
|
||||
{% endhighlight %}
|
||||
@@ -60,7 +69,7 @@ handle your PEAR dependencies. This example will install code from `pear2.php.ne
|
||||
The first section `"repositories"` will be used to let Composer know it should "initialize" (or "discover" in PEAR
|
||||
terminology) the pear repo. Then the `require` section will prefix the package name like this:
|
||||
|
||||
> pear-channel/Package
|
||||
> pear-channel/package
|
||||
|
||||
The "pear" prefix is hardcoded to avoid any conflicts, as a pear channel could be the same as another packages vendor
|
||||
name for example, then the channel short name (or full URL) can be used to reference which channel the package is in.
|
||||
@@ -68,16 +77,20 @@ name for example, then the channel short name (or full URL) can be used to refer
|
||||
When this code is installed it will be available in your vendor directory and automatically available through the
|
||||
Composer autoloader:
|
||||
|
||||
> vendor/pear-pear2.php.net/PEAR2_HTTP_Request/pear2/HTTP/Request.php
|
||||
> vendor/pear2/pear2-http-request/pear2/HTTP/Request.php
|
||||
|
||||
To use this PEAR package simply reference it like so:
|
||||
|
||||
{% highlight php %}
|
||||
<?php
|
||||
$request = new pear2\HTTP\Request();
|
||||
require __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
use PEAR2\HTTP\Request;
|
||||
|
||||
$request = new Request();
|
||||
{% endhighlight %}
|
||||
|
||||
* [Learn more about using PEAR with Composer][6]
|
||||
* [Learn more about using repositories with Composer][6]
|
||||
|
||||
|
||||
[1]: https://pear.php.net/
|
||||
@@ -85,4 +98,4 @@ $request = new pear2\HTTP\Request();
|
||||
[3]: https://pear.php.net/packages.php
|
||||
[4]: https://pear.php.net/manual/guide.users.commandline.channels.php
|
||||
[5]: /#composer_and_packagist
|
||||
[6]: https://getcomposer.org/doc/05-repositories.md#pear
|
||||
[6]: https://getcomposer.org/doc/05-repositories.md
|
||||
|
Reference in New Issue
Block a user