<commit_before><?php

namespace Luminary\Services\ApiLoader;

use Illuminate\Console\Application as Artisan;
use Illuminate\Console\Scheduling\Schedule;
use Luminary\Application;
use Luminary\Contracts\Console\Kernel;
use Luminary\Services\ApiLoader\Helpers\Cache;
use Luminary\Services\ApiLoader\Helpers\Directory;
use Luminary\Services\ApiLoader\Registry\Registrar;
use Luminary\Services\ApiLoader\Registry\Registry;

class ApiLoader
{
    /**
     * The Api path from root
     *
     * @var string
     */
    public $basePath = 'api';

    /**
     * The Registrar Instance
     *
     * @var \Luminary\Services\ApiLoader\Registry\Registrar
     */
    protected $registrar;

    /**
     * The Registry Instance
     *
     * @var \Luminary\Services\ApiLoader\Registry\Registry
     */
    protected $registry;


    /**
     * The Luminary Application Instance
     *
     * @var Application
     */
    protected $app;

    /**
     * ApiLoader constructor.
     * @param Registrar $registrar
     * @param Registry $registry
     * @param Application $app
     */
    public function __construct(Registrar $registrar, Registry $registry, Application $app)
    {
        $this->registrar = $registrar;
        $this->registry = $registry;
        $this->app = $app;
    }

    /**
     * Dynamically load the ApiLoaders
     *
     * @param array $loaders
     * @return \Luminary\Services\ApiLoader\ApiLoader
     */
    public function load(array $loaders) :ApiLoader
    {
        if (! $this->loadCached()) {
            foreach ($loaders as $loader) {
                $loader = new $loader($this->registrar);
                $path = $this->basePath($loader->path());

                $loader->load($path);
            }
        }

        return $this;
    }

    /**
     * Load the API Loader cache
     * if exists
     *<commit_msg>Added check that loader directory exists before loading<commit_after><?php

namespace Luminary\Services\ApiLoader;

use Illuminate\Console\Application as Artisan;
use Illuminate\Console\Scheduling\Schedule;
use Luminary\Application;
use Luminary\Contracts\Console\Kernel;
use Luminary\Services\ApiLoader\Helpers\Cache;
use Luminary\Services\ApiLoader\Helpers\Directory;
use Luminary\Services\ApiLoader\Registry\Registrar;
use Luminary\Services\ApiLoader\Registry\Registry;
use Luminary\Services\Filesystem\App\Storage;

class ApiLoader
{
    /**
     * The Api path from root
     *
     * @var string
     */
    public $basePath = 'api';

    /**
     * The Registrar Instance
     *
     * @var \Luminary\Services\ApiLoader\Registry\Registrar
     */
    protected $registrar;

    /**
     * The Registry Instance
     *
     * @var \Luminary\Services\ApiLoader\Registry\Registry
     */
    protected $registry;


    /**
     * The Luminary Application Instance
     *
     * @var Application
     */
    protected $app;

    /**
     * ApiLoader constructor.
     * @param Registrar $registrar
     * @param Registry $registry
     * @param Application $app
     */
    public function __construct(Registrar $registrar, Registry $registry, Application $app)
    {
        $this->registrar = $registrar;
        $this->registry = $registry;
        $this->app = $app;
    }

    /**
     * Dynamically load the ApiLoaders
     *
     * @param array $loaders
     * @return \Luminary\Services\ApiLoader\ApiLoader
     */
    public function load(array $loaders) :ApiLoader
    {
        if (! $this->loadCached()) {
            foreach ($loaders as $loader) {
                $loader = new $loader($this->registrar);
                $path = $this->basePath($loader->path());

                // Run loader only if directory exists
                if (! Storage::isDirectory($path)) {
                    continue;
                }

                $loader->load($path);
            }
        }

        return $this;
    }

    /**
     * Load the API Loader cache
     * if exists
     *
{'fraction_non_alphanumeric': 0.11463352777073295, 'fraction_numerical': 0.0, 'mean_word_length': 2.1653290529695024, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 0, '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': '6070223', 'n_tokens_mistral': 1178, 'n_tokens_neox': 1149, 'n_words': 248}