<commit_before><?php

namespace Unity\Component\Config\Drivers\File;

use Unity\Component\Config\Drivers\Driver;
use Unity\Component\Config\Drivers\File\Exceptions\ConfigFileNotFoundException;
use Unity\Component\Config\Drivers\File\Exceptions\UndefinedExtensionException;

abstract class FileDriver extends Driver
{
    /** @var string */
    protected $ext;

    /**
     * Sets the extension of config files
     *
     * @param $ext
     */
    function setExt($ext)
    {
        $this->ext = ltrim($ext, '.');
    }

    /**
     * Gets the extension of config files
     *
     * @return string
     * @throws UndefinedExtensionException
     */
    function getExt()
    {
        return $this->ext;
    }

    /**
     * Checks if FileDriver::$ext is defined
     *
     * @return bool
     */
    function hasExt()
    {
        return !empty($this->ext);
    }

    /**
     * Checks if $filename file exists
     *
     * @param $configFile
     * @return bool
     */
    function fileExists($configFile)
    {
        return file_exists($configFile);
    }

    /**
     * Gets the filename with extension
     *
     * @param $filename
     * @return string
     */
    function getFilenameWithExt($filename)
    {
        return $filename . '.' . $this->getExt();
    }

    /**
     * Returns the full path to access the
     * configuration file based in the $source
     *
     * @param $filename
     * @param $source
     * @return string
     */
    function getFullPath($filename, $source)
    {
        return $source . $this->getFilenameWithExt($filename);
    }
}<commit_msg>Added $resolverMethod property Added method get() Added method getConfigArray() Added method callResolver() Added method getResolverMethod() Renamed getFullPath() to getFile()<commit_after><?php

namespace Unity\Component\Config\Drivers\File;

use Unity\Component\Config\Drivers\Driver;
use Unity\Component\Config\Drivers\File\Exceptions\ConfigNotFoundException;

abstract class FileDriver extends Driver implements FileDriverInterface
{
    /** @var string */
    protected $ext;

    /** @var string  */
    private $resolverMethod = 'resolve';

    /**
     * Sets the extension of config files
     *
     * @param $ext
     */
    function setExt($ext)
    {
        $this->ext = ltrim($ext, '.');
    }

    /**
     * Gets the extension of config files
     *
     * @return string
     */
    function getExt()
    {
        return $this->ext;
    }

    /**
     * Checks if FileDriver::$ext is defined
     *
     * @return bool
     */
    function hasExt()
    {
        return !empty($this->ext);
    }

    /**
     * Gets the configuration
     *
     * @param string $config The required configuration
     * @param $source
     * @return mixed
     * @throws ConfigNotFoundException
     */
    function get($config, $source)
    {
        /**
         * Gets the `$filename` and the `$searchKeys`
         * from the `$config` notation
         */
        $this->denote($config, $filename, $searchKeys);

        /**
         * Gets the configuration array calling
         * the `Implementor::resolve()` method
         */
        $configArray = $this->getConfigArray($filename, $source);

        /**
         * Returns the configuration value that
         * matches the `$config` notation
         */
        $config = $this->getConfigValue($configArray, $searchKeys);

        /**
         * If $config is empty, that means no
         * configuration was found
         */
        if(empty($config))
            throw new ConfigNotFoundException("Cannot find configuration \"$config\"");

        return $config;
    }

    /**
     * Gets the configuration array containing
     * in the file
     *
     * @param $filename
     * @param $source
     * @return mixed
     * @throws ConfigNotFoundException
     */
    function getConfigArray($filename, $source)
    {
        $configArray = null;

        /**
         * If `$source is an array, search
         * the `$filename` in each `$source`
         */
        if(is_array($source))
            foreach ($source as $src) {
                $configArray = $this->callResolver($filename, $src);

                /** If was found a configuration, stop searching */
                if($configArray)
                    break;
            }
        else
            $configArray = $this->callResolver($filename, $source);

        /** If was found a configuration, return it */
        if($configArray)
            return $configArray;
    }

    /**
     * Calls the `Implementor::resolve()` method
     *
     * @param $filename
     * @param $src
     * @return mixed
     */
    function callResolver($filename, $src)
    {
        $file = $this->getFile($filename, $src);

        return call_user_func_array(
            [
                $this,
                $this->getResolverMethod()
            ],
            [$file]
        );
    }

    /**
     * Returns the `Implementor` resolver method name
     *
     * @return string
     */
    function getResolverMethod()
    {
        return $this->resolverMethod;
    }

    /**
     * Returns the full path to access the
     * configuration file based in a `$source`
     *
     * @param $filename
     * @param $source
     * @return string
     */
    function getFile($filename, $source)
    {
        return $source . $this->getFilenameWithExt($filename);
    }

    /**
     * Checks if $filename file exists
     *
     * @param $configFile
     * @return bool
     */
    function fileExists($configFile)
    {
        return file_exists($configFile);
    }

    /**
     * Gets the filename with extension
     *
     * @param $filename
     * @return string
     */
    function getFilenameWithExt($filename)
    {
        return $filename . '.' . $this->getExt();
    }
}
{'fraction_non_alphanumeric': 0.11941580756013746, 'fraction_numerical': 0.0, 'mean_word_length': 1.8816831683168316, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '645129', 'n_tokens_mistral': 1639, 'n_tokens_neox': 1594, 'n_words': 404}