How to port PHP projects which require composer

From: Dan Langille <dan_at_langille.org>
Date: Fri, 13 Jan 2023 10:20:25 UTC
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?

More information below:


The output of the composer command is:

Info from https://repo.packagist.org: #StandWithUkraine
./composer.json has been updated
Running composer update vstelmakh/url-highlight
Loading composer repositories with package information
Updating dependencies
Nothing to modify in lock file
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 2 installs, 0 updates, 0 removals
   - Installing symfony/polyfill-php72 (v1.27.0): Extracting archive
   - Installing vstelmakh/url-highlight (v3.0.1): Extracting archive
Generating autoload files
1 package you are using is looking for funding.
Use the `composer fund` command to find out more!
No security vulnerability advisories found
Using version ^3.0 for vstelmakh/url-highlight

The vendor directory contains:

[empty dan ~/tmp] % find vendor 10:15:04
vendor
vendor/autoload.php
vendor/vstelmakh
vendor/vstelmakh/url-highlight
vendor/vstelmakh/url-highlight/LICENSE
vendor/vstelmakh/url-highlight/README.md
vendor/vstelmakh/url-highlight/src
vendor/vstelmakh/url-highlight/src/Matcher
vendor/vstelmakh/url-highlight/src/Matcher/UrlMatch.php
vendor/vstelmakh/url-highlight/src/Matcher/EncodedMatcher.php
vendor/vstelmakh/url-highlight/src/Matcher/MatcherInterface.php
vendor/vstelmakh/url-highlight/src/Matcher/MatcherFactory.php
vendor/vstelmakh/url-highlight/src/Matcher/Matcher.php
vendor/vstelmakh/url-highlight/src/Domains.php
vendor/vstelmakh/url-highlight/src/Replacer
vendor/vstelmakh/url-highlight/src/Replacer/ReplacerFactory.php
vendor/vstelmakh/url-highlight/src/Replacer/Replacer.php
vendor/vstelmakh/url-highlight/src/Replacer/ReplacerInterface.php
vendor/vstelmakh/url-highlight/src/Validator
vendor/vstelmakh/url-highlight/src/Validator/ValidatorInterface.php
vendor/vstelmakh/url-highlight/src/Validator/Validator.php
vendor/vstelmakh/url-highlight/src/Encoder
vendor/vstelmakh/url-highlight/src/Encoder/EncoderInterface.php
vendor/vstelmakh/url-highlight/src/Encoder/HtmlSpecialcharsEncoder.php
vendor/vstelmakh/url-highlight/src/Encoder/HtmlEntitiesEncoder.php
vendor/vstelmakh/url-highlight/src/Util
vendor/vstelmakh/url-highlight/src/Util/LinkHelper.php
vendor/vstelmakh/url-highlight/src/Util/CaseInsensitiveSet.php
vendor/vstelmakh/url-highlight/src/Util/CaseInsensitiveMap.php
vendor/vstelmakh/url-highlight/src/Util/StringHelper.php
vendor/vstelmakh/url-highlight/src/UrlHighlight.php
vendor/vstelmakh/url-highlight/src/Filter
vendor/vstelmakh/url-highlight/src/Filter/FilterInterface.php
vendor/vstelmakh/url-highlight/src/Filter/BalancedFilter.php
vendor/vstelmakh/url-highlight/src/Highlighter
vendor/vstelmakh/url-highlight/src/Highlighter/MarkdownHighlighter.php
vendor/vstelmakh/url-highlight/src/Highlighter/HighlighterInterface.php
vendor/vstelmakh/url-highlight/src/Highlighter/HtmlHighlighter.php
vendor/vstelmakh/url-highlight/composer.json
vendor/composer
vendor/composer/autoload_real.php
vendor/composer/ClassLoader.php
vendor/composer/autoload_psr4.php
vendor/composer/installed.json
vendor/composer/installed.php
vendor/composer/autoload_static.php
vendor/composer/InstalledVersions.php
vendor/composer/autoload_classmap.php
vendor/composer/LICENSE
vendor/composer/platform_check.php
vendor/composer/autoload_namespaces.php
vendor/composer/autoload_files.php
vendor/symfony
vendor/symfony/polyfill-php72
vendor/symfony/polyfill-php72/composer.json
vendor/symfony/polyfill-php72/Php72.php
vendor/symfony/polyfill-php72/bootstrap.php
vendor/symfony/polyfill-php72/README.md
vendor/symfony/polyfill-php72/LICENSE



-- 
Dan Langille - dan@langille.org
https://langille.org/