<commit_before><?php namespace Orchestra\Asset;

use Illuminate\Support\Str;
use Orchestra\Html\HtmlBuilder;
use Illuminate\Filesystem\Filesystem;

class Dispatcher
{
    /**
     * Filesystem instance.
     *
     * @var \Illuminate\Filesystem\Filesystem
     */
    protected $files;

    /**
     * Html builder instance.
     *
     * @var \Orchestra\Html\HtmlBuilder
     */
    protected $html;

    /**
     * Dependency resolver instance.
     *
     * @var \Orchestra\Asset\DependencyResolver
     */
    protected $resolver;

    /**
     * Public path location.
     *
     * @var string
     */
    protected $path;

    /**
     * Use asset versioning.
     *
     * @var bool
     */
    public $useVersioning = false;

    /**
     * Create a new asset dispatcher instance.
     *
     * @param \Illuminate\Filesystem\Filesystem  $files
     * @param \Orchestra\Html\HtmlBuilder  $html
     * @param \Orchestra\Asset\DependencyResolver  $resolver
     * @param $path
     */
    public function __construct(Filesystem $files, HtmlBuilder $html, DependencyResolver $resolver, $path)
    {
        $this->files    = $files;
        $this->html     = $html;
        $this->resolver = $resolver;
        $this->path     = $path;
    }

    /**
     * Enable asset versioning.
     *
     * @return void
     */
    public function addVersioning()
    {
        $this->useVersioning = true;
    }

    /**
     * Disable asset versioning.
     *
     * @return void
     */
    public function removeVersioning()
    {
        $this->useVersioning = false;
    }

    /**
     * Dispatch assets by group.
     *
     * @param  string  $group
     * @param  array  $assets
     * @param  string|null  $prefix
     *
     * @return string
     */
    public function run($group, array $assets = [], $prefix = null)
    {
        $html = '';

        if (! isset($assets[$group]) || count($assets[$group]) == 0) {
            return $html;
        }

        is_null($prefix) || $this->path = rtrim($prefix, '/');

        foreach ($this->resolver->arrange($assets[$group]) as $data) {
            $html .= $this->asset($group, $data);
        }

        return $html;
    }

    /**
     * Get the HTML link to a registered asset.
     *
     * @param  string  $group
     * @param  array   $asset
     *
     * @return string
     */
    public function asset($group, $asset)
    {
        if (! isset($asset)) {
            return '';
        }

        $asset['source'] = $this->getAssetSourceUrl($asset['source']);

        return call_user_func_array([$this->html, $group], [$asset['source'], $asset['attributes']]);
    }

    /**
     * Determine if path is local.
     *
     * @param  string  $path
     *
     * @return bool
     */
    protected function isLocalPath($path)
    {
        if (Str::startsWith($path, ['https://', 'http://', '//'])) {
            return false;
        }

        return (filter_var($path, FILTER_VALIDATE_URL) === false);
    }

    /**<commit_msg>Avoid using `call_user_func_array` for parameter with known length.<commit_after><?php namespace Orchestra\Asset;

use Illuminate\Support\Str;
use Orchestra\Html\HtmlBuilder;
use Illuminate\Filesystem\Filesystem;

class Dispatcher
{
    /**
     * Filesystem instance.
     *
     * @var \Illuminate\Filesystem\Filesystem
     */
    protected $files;

    /**
     * Html builder instance.
     *
     * @var \Orchestra\Html\HtmlBuilder
     */
    protected $html;

    /**
     * Dependency resolver instance.
     *
     * @var \Orchestra\Asset\DependencyResolver
     */
    protected $resolver;

    /**
     * Public path location.
     *
     * @var string
     */
    protected $path;

    /**
     * Use asset versioning.
     *
     * @var bool
     */
    public $useVersioning = false;

    /**
     * Create a new asset dispatcher instance.
     *
     * @param \Illuminate\Filesystem\Filesystem  $files
     * @param \Orchestra\Html\HtmlBuilder  $html
     * @param \Orchestra\Asset\DependencyResolver  $resolver
     * @param $path
     */
    public function __construct(Filesystem $files, HtmlBuilder $html, DependencyResolver $resolver, $path)
    {
        $this->files    = $files;
        $this->html     = $html;
        $this->resolver = $resolver;
        $this->path     = $path;
    }

    /**
     * Enable asset versioning.
     *
     * @return void
     */
    public function addVersioning()
    {
        $this->useVersioning = true;
    }

    /**
     * Disable asset versioning.
     *
     * @return void
     */
    public function removeVersioning()
    {
        $this->useVersioning = false;
    }

    /**
     * Dispatch assets by group.
     *
     * @param  string  $group
     * @param  array  $assets
     * @param  string|null  $prefix
     *
     * @return string
     */
    public function run($group, array $assets = [], $prefix = null)
    {
        $html = '';

        if (! isset($assets[$group]) || count($assets[$group]) == 0) {
            return $html;
        }

        is_null($prefix) || $this->path = rtrim($prefix, '/');

        foreach ($this->resolver->arrange($assets[$group]) as $data) {
            $html .= $this->asset($group, $data);
        }

        return $html;
    }

    /**
     * Get the HTML link to a registered asset.
     *
     * @param  string  $group
     * @param  array   $asset
     *
     * @return string
     */
    public function asset($group, $asset)
    {
        if (! isset($asset)) {
            return '';
        }

        $asset['source'] = $this->getAssetSourceUrl($asset['source']);

        return call_user_func([$this->html, $group], $asset['source'], $asset['attributes']);
    }

    /**
     * Determine if path is local.
     *
     * @param  string  $path
     *
     * @return bool
     */
    protected function isLocalPath($path)
    {
        if (Str::startsWith($path, ['https://', 'http://', '//'])) {
            return false;
        }

        return (filter_var($path, FILTER_VALIDATE_URL) === false);
    }

    /**
{'fraction_non_alphanumeric': 0.1441575637206223, 'fraction_numerical': 0.00033101621979476995, 'mean_word_length': 1.8384217942696102, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3173606', 'n_tokens_mistral': 1857, 'n_tokens_neox': 1839, 'n_words': 395}