Skip to content

Commit

Permalink
Merge pull request #583 from FreshPorts/582-better-dependency-lines-f…
Browse files Browse the repository at this point in the history
…or-php-ports

Add support for PHP_PKGNAME{PREFIX,SUFFIX}
  • Loading branch information
dlangille authored Aug 1, 2024
2 parents 8cef582 + eaf6d5c commit 24813c7
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion classes/port-display.php
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,20 @@ function Is_A_Python_Port_Suffix(&$matches) {
return $Is_A_Python_Port_Suffix;
}

function Is_A_PHP_Port_Prefix(&$matches) {
# find out of the python port starts with phpXX-
$Is_A_PHP_Port_Prefix = preg_match('/^php[0-9]+-(.*)/', $this->port->package_name ?? '', $matches);

return $Is_A_PHP_Port_Prefix;
}

function Is_A_PHP_Port_Suffix(&$matches) {
# find out of the python port end with -phpXX
$Is_A_PHP_Port_Suffix = preg_match('/(.*)-php[0-9]+$/', $this->port->package_name ?? '', $matches);

return $Is_A_PHP_Port_Suffix;
}

function DisplayDependencyLine() {
$port = $this->port;

Expand All @@ -740,6 +754,9 @@ function DisplayDependencyLine() {
$Is_A_Python_Port_Prefix = false;
$Is_A_Python_Port_Suffix = false;

$Is_A_PHP_Port_Prefix = false;
$Is_A_PHP_Port_Suffix = false;

# assume the default package name
$package_name = $port->package_name;

Expand All @@ -748,6 +765,11 @@ function DisplayDependencyLine() {
$USES_PYTHON = in_array(USES_PYTHON, preg_split('/\s+|:/', $port->uses));
}

// check to see if USES= contains php
if (!empty($port->uses)) {
$USES_PHP = in_array(USES_PHP, preg_split('/\s+|:/', $port->uses));
}


# if there is python in there...
if (!empty($USES_PYTHON)) {
Expand All @@ -761,8 +783,21 @@ function DisplayDependencyLine() {
}


# if there is PHP in there...
if (!empty($USES_PHP)) {
# it is a PHP port if it starts with php84-, for example.
$Is_A_PHP_Port_Prefix = $this->Is_A_PHP_Port_Prefix($prefix_matches);
# if a match for php84-pecl-imap, $matches[0]=> "php84-pecl-imap", $matches[1]=> "pecl-imap"

# it is a PHP port if it end with -py84, for example.
$Is_A_PHP_Port_Suffix = $this->Is_A_PHP_Port_Suffix($suffix_matches);
# if a match for arcanist-lib-php82, $matches[0]=> "arcanist-lib-php82", $matches[1]=> "arcanist-lib"
}


# This code presumes that only one of PYTHON_PKGNAMEPREFIX and PYTHON_PKGNAMESUFFIX appears in a given port
# Right now, I don't want to code that possibility.
# Similarly, when adding PHP_PKGNAMEPREFIX/SUFFIX, I'm assuming only one of the four is used at a time.
# Right now, I don't want to code that possibility that my assumption is false.
if ($Is_A_Python_Port_Prefix) {
$package_name = '${PYTHON_PKGNAMEPREFIX}' . $prefix_matches[1];
}
Expand All @@ -771,6 +806,14 @@ function DisplayDependencyLine() {
$package_name = $suffix_matches[1] . '${PYTHON_PKGNAMESUFFIX}';
}

if ($Is_A_PHP_Port_Prefix) {
$package_name = '${PHP_PKGNAMEPREFIX}' . $prefix_matches[1];
}

if ($Is_A_PHP_Port_Suffix) {
$package_name = $suffix_matches[1] . '${PHP_PKGNAMESUFFIX}';
}

$HTML .= $package_name . '>0:' . $this->DisplayPlainText();
if ($Is_A_Python_Port_Prefix) {
$HTML .= '@${PY_FLAVOR}';
Expand Down

0 comments on commit 24813c7

Please sign in to comment.