Re: How to port PHP projects which require composer

From: Naram Qashat <njqashat_at_gmail.com>
Date: Sat, 14 Jan 2023 16:22:55 UTC
On 2023-01-13 11:25, Dan Langille wrote:
> On Fri, Jan 13, 2023, at 10:12 AM, thierry@freebsd.org wrote:
>> Selon Dan Langille <dan@langille.org> le ven. 13 janv. 11:20:25 2023 :
>> 
>>> Hello,
>>> 
>>> I'm looking at porting https://github.com/vstelmakh/url-highlight
>>> for use by FreshPorts.
>>> 
>>> My current solution:
>>> 
>>> % sudo pkg install php81-composer
>>> % fetch -o url-highlight-v3.0.1.tar.gz
>>> https://github.com/vstelmakh/url-highlight/archive/refs/tags/v3.0.1.tar.gz
>>> % tar -xzf url-highlight-v3.0.1.tar.gz
>>> % composer require vstelmakh/url-highlight
>>> 
>>> At this point, everything I need is in the newly-created vendor 
>>> directory.
>>> 
>>> If I copy that vendor directory to /usr/local/www/freshports/, I can
>>> use it like this:
>>> 
>>> <?php
>>> 
>>> require_once($_SERVER['DOCUMENT_ROOT'] .  '/../vendor/autoload.php');
>>> use VStelmakh\UrlHighlight\Encoder\HtmlSpecialcharsEncoder;
>>> use VStelmakh\UrlHighlight\UrlHighlight;
>>> 
>>> ... etc
>>> 
>>> 
>>> What is the proper way to port code like this?
>> 
>> It would be very interesting to have a Mk/Uses/composer.mk, like we
>> have Mk/Uses/pear.mk.
>> 
>> Adding cyberbotx@cyberbotx.com to the list: do you think it is 
>> possible?

I don't know enough about how Mk/Uses/pear.mk to say for sure, but what 
little I've skimmed over makes it look like port using PEAR is for a 
single PEAR extension, which isn't the same as a PHP application using 
Composer. And I think a port using Composer would need some way to do 
its downloading since that couldn't be done outside of the fetch stage 
if I recall right?

Thanks,
Naram "CyberBotX" Qashat

> 
> FYI, what I do with net-mgmt/librenms[1] is manually build the vendor 
> directory
> and upload it as a separate DISTFILE.  It works, but it is a manual 
> process[2].
> 
> 1 - https://cgit.freebsd.org/ports/tree/net-mgmt/librenms/Makefile#n6
> 2 - https://gist.github.com/dlangille/e91b77ca4a32dfcbcdd7515ffb263e74
> --
>   Dan Langille
>   dan@langille.org