Skip to content

Commit 45616f9

Browse files
authored
Merge pull request #967 from petk/patch-pear
Fix PEAR with Composer
2 parents a551416 + a494f29 commit 45616f9

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

_posts/04-03-01-PEAR.md

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,49 +40,62 @@ installing. See the [Using channel docs][4] for more information on this topic.
4040
### Handling PEAR dependencies with Composer
4141

4242
If you are already using [Composer][5] and you would like to install some PEAR code too, you can use Composer to
43-
handle your PEAR dependencies. This example will install code from `pear2.php.net`:
43+
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:
4444

4545
{% highlight json %}
4646
{
4747
"repositories": [
4848
{
49-
"type": "pear",
50-
"url": "https://pear2.php.net"
49+
"type": "package",
50+
"package": {
51+
"name": "pear2/pear2-http-request",
52+
"version": "2.5.1",
53+
"dist": {
54+
"url": "https://github.com/pear2/HTTP_Request/archive/refs/heads/master.zip",
55+
"type": "zip"
56+
}
57+
}
5158
}
5259
],
5360
"require": {
54-
"pear-pear2/PEAR2_Text_Markdown": "*",
55-
"pear-pear2/PEAR2_HTTP_Request": "*"
61+
"pear2/pear2-http-request": "*"
62+
},
63+
"autoload": {
64+
"psr-4": {"PEAR2\\HTTP\\": "vendor/pear2/pear2-http-request/src/HTTP/"}
5665
}
5766
}
5867
{% endhighlight %}
5968

6069
The first section `"repositories"` will be used to let Composer know it should "initialize" (or "discover" in PEAR
6170
terminology) the pear repo. Then the `require` section will prefix the package name like this:
6271

63-
> pear-channel/Package
72+
> pear-channel/package
6473
6574
The "pear" prefix is hardcoded to avoid any conflicts, as a pear channel could be the same as another packages vendor
6675
name for example, then the channel short name (or full URL) can be used to reference which channel the package is in.
6776

6877
When this code is installed it will be available in your vendor directory and automatically available through the
6978
Composer autoloader:
7079

71-
> vendor/pear-pear2.php.net/PEAR2_HTTP_Request/pear2/HTTP/Request.php
80+
> vendor/pear2/pear2-http-request/pear2/HTTP/Request.php
7281
7382
To use this PEAR package simply reference it like so:
7483

7584
{% highlight php %}
7685
<?php
77-
$request = new pear2\HTTP\Request();
86+
require __DIR__ . '/vendor/autoload.php';
87+
88+
use PEAR2\HTTP\Request;
89+
90+
$request = new Request();
7891
{% endhighlight %}
7992
80-
* [Learn more about using PEAR with Composer][6]
93+
* [Learn more about using repositories with Composer][6]
8194
8295
8396
[1]: https://pear.php.net/
8497
[2]: https://pear.php.net/manual/installation.getting.php
8598
[3]: https://pear.php.net/packages.php
8699
[4]: https://pear.php.net/manual/guide.users.commandline.channels.php
87100
[5]: /#composer_and_packagist
88-
[6]: https://getcomposer.org/doc/05-repositories.md#pear
101+
[6]: https://getcomposer.org/doc/05-repositories.md

0 commit comments

Comments
 (0)