<commit_before><?php

namespace Encore\Config;

use Encore\Namespacer\NamespacableTrait;
use Symfony\Component\Filesystem\Filesystem;

class FileLoader implements LoaderInterface
{
    use NamespacableTrait;

    /**
    * A cache of whether namespaces and groups exists.
    *
    * @var array
    */
    protected $exists = array();

    /**
    * The Symfony Filesystem component
    *
    * @var Symfony\Component\Filesystem\Filesystem
    */
    protected $fs;

    /**
    * The configuration file path
    *
    * @var string
    */
    protected $path;

    /**
    * The operating system
    *
    * @var string
    */
    protected $os = null;

    /**
    * The constructor
    *
    * @param Symfony\Component\Filesystem\Filesystem
    * @param $path
    * @param $os
    */
    public function __construct(Filesystem $fs, $path, $os = null)
    {
        $this->fs = $fs;
        $this->path = $path;
        $this->os = $os;
    }

    /**
    * Load the given configuration group.
    *
    * @param string $mode
    * @param string $group
    * @param string $namespace
    * @return array
    */
    public function load($mode, $group, $namespace = null)
    {
        $items = array();

        // Lets find where the path is
        $path = $this->getPath($namespace);

        if (is_null($path)) return $items;

        // First things first... Is there a top-level config file?
        $file = "{$path}/{$group}.php";

        if ($this->fs->exists($file)) {
            $items = require $file;
        }

        // Do we have an operating system specific config file?
        $file = "{$path}/{$this->os}/{$group}.php";

        if ($this->fs->exists($file)) {
            $items = $this->mergeItems($items, $file);
        }

        // Do we have an application mode specific config file?
        $file = "{$path}/{$mode}/{$group}.php";

        if ($this->fs->exists($file)) {
            $items = $this->mergeItems($items, $file);
        }

        // And lastly we'll check if we have an mode and OS specific
        // config file.
        $file = "{$path}/{$this->os}/{$mode}/{$group}.php";

        if ($this->fs->exists($file)) {
            $items = $this->mergeMode($items, $file);
        }

        return $items;
    }

    /**
    * Determine if the given configuration group exists.
    *
    * @param string $group
    * @param string $namespace
    * @return bool
    */
    public function exists($group, $namespace = null)
    {
        $key = $group.$namespace;

        // Check if we have a cached answer
        if (isset($this->exists[$key])) return $this->exists[$key];<commit_msg>Only run OS specific checks if an OS is specified<commit_after><?php

namespace Encore\Config;

use Encore\Namespacer\NamespacableTrait;
use Symfony\Component\Filesystem\Filesystem;

class FileLoader implements LoaderInterface
{
    use NamespacableTrait;

    /**
    * A cache of whether namespaces and groups exists.
    *
    * @var array
    */
    protected $exists = array();

    /**
    * The Symfony Filesystem component
    *
    * @var Symfony\Component\Filesystem\Filesystem
    */
    protected $fs;

    /**
    * The configuration file path
    *
    * @var string
    */
    protected $path;

    /**
    * The operating system
    *
    * @var string
    */
    protected $os = null;

    /**
    * The constructor
    *
    * @param Symfony\Component\Filesystem\Filesystem
    * @param $path
    * @param $os
    */
    public function __construct(Filesystem $fs, $path, $os = null)
    {
        $this->fs = $fs;
        $this->path = $path;
        $this->os = $os;
    }

    /**
    * Load the given configuration group.
    *
    * @param string $mode
    * @param string $group
    * @param string $namespace
    * @return array
    */
    public function load($mode, $group, $namespace = null)
    {
        $items = array();

        // Lets find where the path is
        $path = $this->getPath($namespace);

        if (is_null($path)) return $items;

        // First things first... Is there a top-level config file?
        $file = "{$path}/{$group}.php";

        if ($this->fs->exists($file)) {
            $items = require $file;
        }

        if ($this->os) {
            // Do we have an operating system specific config file?
            $file = "{$path}/{$this->os}/{$group}.php";

            if ($this->fs->exists($file)) {
                $items = $this->mergeItems($items, $file);
            }
        }

        // Do we have an application mode specific config file?
        $file = "{$path}/{$mode}/{$group}.php";

        if ($this->fs->exists($file)) {
            $items = $this->mergeItems($items, $file);
        }

        if ($this->os) {
            // And lastly we'll check if we have an mode and OS specific
            // config file.
            $file = "{$path}/{$this->os}/{$mode}/{$group}.php";

            if ($this->fs->exists($file)) {
                $items = $this->mergeMode($items, $file);
            }
        }

        return $items;
    }

    /**
    * Determine if the given configuration group exists.
    *
    * @param string $group
    * @param string $namespace
    * @return bool
    */
    public function exists($group, $namespace = null)
    {
        $key = $group.$namespace;

        // Check if we have a cached answer
        if (isset($this->exists[$key])) return $this->exists[$key];
{'fraction_non_alphanumeric': 0.14739564093091984, 'fraction_numerical': 0.0, 'mean_word_length': 1.8988222698072805, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, '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': '5856995', 'n_tokens_mistral': 1628, 'n_tokens_neox': 1581, 'n_words': 434}