public function locateFunctionSource()

in src/ProjectContext.php [50:79]


    public function locateFunctionSource(?string $functionSource): ?string
    {
        // Ensure function source is loaded relative to the application root
        if ($functionSource) {
            if (0 !== strpos($functionSource, '/')) {
                // Make the path absolute
                $absoluteSource = $this->documentRoot . $functionSource;
            } else {
                $absoluteSource = $functionSource;
            }

            if (!file_exists($absoluteSource)) {
                throw new RuntimeException(sprintf(
                    'Unable to load function from "%s"',
                    $functionSource
                ));
            }

            return $absoluteSource;
        }

        if (file_exists($defaultSource = $this->documentRoot . 'index.php')) {
            // When running from vendor/google/cloud-functions-framework, default to
            // "index.php" in the root of the application.
            return $defaultSource;
        }

        // No function source found. Assume the function source is autoloaded.
        return null;
    }