Platformsh\Cli\Local\LocalBuild::getActiveBuilds PHP Method

getActiveBuilds() protected method

protected getActiveBuilds ( string $projectRoot ) : array
$projectRoot string
return array The absolute paths to any active builds in the project.
    protected function getActiveBuilds($projectRoot)
    {
        $www = $projectRoot . '/' . $this->config->get('local.web_root');
        if (!file_exists($www)) {
            return [];
        }
        $links = [$www];
        if (!is_link($www) && is_dir($www)) {
            $finder = new Finder();
            /** @var \Symfony\Component\Finder\SplFileInfo $file */
            foreach ($finder->in($www)->directories()->depth(0) as $file) {
                $links[] = $file->getPathname();
            }
        }
        $activeBuilds = [];
        $buildsDir = $projectRoot . '/' . $this->config->get('local.build_dir');
        foreach ($links as $link) {
            if (is_link($link) && ($target = readlink($link))) {
                // Make the target into an absolute path.
                $target = $target[0] === DIRECTORY_SEPARATOR ? $target : realpath(dirname($link) . '/' . $target);
                if (!$target) {
                    continue;
                }
                // Ignore the target if it doesn't point to a build in 'builds'.
                if (strpos($target, $buildsDir) === false) {
                    continue;
                }
                // The target should just be one level below the 'builds'
                // directory, not more.
                while (dirname($target) != $buildsDir) {
                    $target = dirname($target);
                    if (strpos($target, $buildsDir) === false) {
                        throw new \Exception('Error resolving active build directory');
                    }
                }
                $activeBuilds[] = $target;
            }
        }
        return $activeBuilds;
    }