Efficiently\Larasset\Asset::assetPath PHP Метод

assetPath() публичный Метод

Computes the path to asset in public directory.
public assetPath ( string $source, array $options = [] ) : string
$source string
$options array
Результат string
    public function assetPath($source, array $options = [])
    {
        $source = (string) $source;
        if (!$source) {
            return "";
            // Short circuit
        }
        if (preg_match(static::URI_REGEXP, $source)) {
            return $source;
            // Short circuit
        }
        $assetPrefix = array_get($options, 'prefix', $this->assetsPrefix);
        if (is_callable($assetPrefix) && is_object($assetPrefix)) {
            $assetPrefix = $assetPrefix();
        }
        $assetHost = array_get($options, 'host');
        if (is_callable($assetHost) && is_object($assetHost)) {
            $assetHost = $assetHost();
        }
        $assetPort = $this->assetPort;
        if (is_callable($assetPort) && is_object($assetPort)) {
            $assetPort = $assetPort();
        }
        $protocol = Request::secure() ? "https://" : "http://";
        if (App::environment() !== (getenv('ASSETS_ENV') ?: 'production')) {
            $assetHost = $assetHost ?: $protocol . $this->getHostname() . ":" . $assetPort;
            $assetLocation = $assetHost . $assetPrefix;
        } else {
            $assetLocation = $assetHost . $assetPrefix;
            $manifest = static::manifest();
        }
        // TODO: Sanitize/purify $source var
        $sourceName = $source;
        if (isset($manifest) && $manifest->getAssets()) {
            $sourceName = array_get($manifest->getAssets(), $sourceName, $sourceName);
        }
        $assetPath = "{$assetLocation}/{$sourceName}";
        if (File::exists(public_path() . $assetPath) || preg_match(static::URI_REGEXP, $assetPath)) {
            return $assetPath;
        } else {
            // TODO: The root path of the Laravel application is hardcoded here, it might be a problem
            return '/' . preg_replace('/^\\//', '', $source);
        }
    }