HEX
Server: Apache/2.4.34 (Red Hat) OpenSSL/1.0.2k-fips
System: Linux WORDPRESS 3.10.0-1160.118.1.el7.x86_64 #1 SMP Thu Apr 4 03:33:23 EDT 2024 x86_64
User: digital (1020)
PHP: 7.2.24
Disabled: NONE
Upload Files
File: /datos/www/fabricas.colombiatrade.com.co/vendor2/drush/drush/src/Backend/BackendPathEvaluator.php
<?php
namespace Drush\Backend;

use Consolidation\SiteAlias\SiteAlias;
use Consolidation\SiteAlias\HostPath;
use Drush\Drush;

class BackendPathEvaluator
{
    /**
     * Evaluate will check to see if the provided host path
     * contains a path alias. If it does, the alias will
     * be resolved, and the result of the resolution will be
     * injected into the HostPath, replacing the alias.
     *
     * @param HostPath $path The host and path to evaluate aliases on.
     */
    public function evaluate(HostPath $path)
    {
        $resolvedPath = $this->resolve($path);
        if (!$resolvedPath) {
            return;
        }

        $path->replacePathAlias($resolvedPath);
    }

    /**
     * Resolve will check to see if the provided host path
     * contains a path alias. If it does, the alias will
     * be resolved, and the result of the resolution will be
     * returned.
     *
     * @param HostPath $path The host and path to resolve aliases on.
     * @return string
     */
    public function resolve(HostPath $path)
    {
        if (!$path->hasPathAlias()) {
            return false;
        }

        // If HostPath is `@site:%files`, then the path alias is `files`.
        $pathAlias = $path->getPathAlias();
        return $this->lookup($path->getSiteAlias(), $pathAlias);
    }

    /**
     * Lookup will use the provided alias record to look up and return
     * the value of a path alias.
     *
     * @param SiteAlias $aliasRecord the host to use for lookups
     * @param $pathAlias the alias to look up (`files`, not `%files`)
     * @return string
     */
    public function lookup(SiteAlias $aliasRecord, $pathAlias)
    {
        if ($aliasRecord->has("paths.$pathAlias")) {
            return $aliasRecord->get("paths.$pathAlias");
        }

        return $this->request($aliasRecord, $pathAlias);
    }

    /**
     * Request the value of the path alias from the site associated with
     * the alias record.
     *
     * @param SiteAlias $aliasRecord the host to use for lookups
     * @param string $pathAlias the alias to look up (`files`, not `%files`)
     * @return string
     */
    public function request(SiteAlias $aliasRecord, $pathAlias)
    {
        // The drupal:directory command uses a path evaluator, which
        // calls this function, so we cannot use dd here, as that
        // would be recursive.
        $process = Drush::drush($aliasRecord, 'core-status', [], ['project' => $pathAlias, 'fields' => '%paths', 'format' => 'json']);
        $process->setSimulated(false);
        $process->mustRun();
        $json = $process->getOutputAsJson();
        if (isset($json['%paths']["%{$pathAlias}"])) {
            return $json['%paths']["%{$pathAlias}"];
        }
        throw new \Exception(dt('Cannot evaluate path alias %{path} for site alias {site}', ['path' => $pathAlias, 'site' => $aliasRecord->name()]));
    }
}