<commit_before><?php

namespace Triun\ModelBase;

use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Config;

use Triun\ModelBase\Modifiers;

/**
 * Class ModelBaseConfig
 *
 * @package Triun\ModelBase
 */
class ModelBaseConfig
{
    /**
     * Config file.
     */
    const CONFIG_FILE = 'model-base';

    /**
     * @var string
     */
    const WILDCARD_CONNECTION_STUD = '{{Connection}}';

    /**
     * @var string
     */
    const WILDCARD_DRIVER_STUD = '{{Driver}}';

    /**
     * @var string[]
     */
    protected $modifiers = [

        // Connection
        Modifiers\ConnectionModifier::class,

        // Table
        Modifiers\TableModifier::class,

        // Timestamps
        Modifiers\TimestampsModifier::class,

        // Dates
        Modifiers\DatesModifier::class,

        // Soft Deletes
        Modifiers\SoftDeletesModifier::class,

        // Attributes
        Modifiers\AttributesModifier::class,

        // CamelToSnake Attributes
        Modifiers\CamelToSnakeModifier::class,

        // For custom aliases
        Modifiers\ColumnAliasModifier::class,

        // PhpDoc tags
        Modifiers\PhpDocModifier::class,

        // PhpDoc tags
        Modifiers\AuthModifier::class,

        // Custom
        Modifiers\CustomModelOptionsModifier::class,

        // Relations
        // Input transformations
        // ValueObjects
    ];

    /**
     * Util configuration.
     * This config will have the following priority:
     * - config parameters in constructor.
     * - laravel config (/config/model-base.php).
     * - default config (../config/model-base.php).
     *
     * @var array
     */
    protected $items = [];

    /**
     * @var \Illuminate\Database\Connection
     */
    protected $connection;

    /**
     * ModelBaseConfig constructor.
     *
     * @param \Illuminate\Database\Connection $connection
     */
    public function __construct($connection)
    {
        $this->items = array_merge(
            $this->loadConfig(static::CONFIG_FILE),
            $this->loadConfig(static::CONFIG_FILE . '.drivers.' . $connection->getDriverName()),
            $this->loadConfig(static::CONFIG_FILE . '.connections.' . $connection->getName())
            // $this->loadConfig(static::CONFIG_FILE.'.tables.'.$tableName),
            // $this->loadConfig(static::CONFIG_FILE.'.connections.'.$connection->getName().'.tables.'.$tableName),
        );

        $this->connection = $connection;
    }

    /**
     * @param $name
     *
     * @return array|mixed
     */
    protected function loadConfig($name)
    {
        return Config::has($name) ? Config::get($name) : [];
    }

    /**
     * Determine if the given configuration value exists.
     *
     * @param string $key
     *
     * @return bool
     */
    public function has($key)
    {
        return Arr::has($this->items, $key);
    }

    /**
     * Get the specified configuration value.
     *
     * @param string $key
     * @param mixed  $default
     *
     * @return mixed
     */
    public function get($key, $default = null)
    {
        return Arr::get($this->items, $key, $default);
    }

    /**
     * Set a given configuration value.
     *
     * @param array|string $key
     * @param mixed        $value
     *
     * @return void
     */
    /*public function set($key, $value = null)
    {
        if (is_array($key)) {
            foreach ($key as $innerKey => $innerValue) {
                Arr::set($this->items, $innerKey, $innerValue);
            }
        } else {
            Arr::set($this->items, $key, $value);
        }
    }*/

    /**
     * fnmatch separated by |
     * http://php.net/fnmatch
     * '*gr[ae]y' is gray and grey
     * 'gray|grey' is also gray and grey
     * '*At|*_at finish in 'At' or '_at'
     *
     * @param string|string[] $rules
     * @param string          $value
     * @param bool            $case_sensitive
     *
     * @return bool
     */
    public function match($rules, $value, $case_sensitive = false)
    {
//        return fnmatch($rules, $value);

        if (is_string($rules)) {
            $rules = explode('|', $rules);
        }

        foreach ($rules as $rule) {
            $rule = str_replace(' ', '', $rule);<commit_msg>Minor change<commit_after><?php

namespace Triun\ModelBase;

use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Config;

use Triun\ModelBase\Modifiers;

/**
 * Class ModelBaseConfig
 *
 * @package Triun\ModelBase
 */
class ModelBaseConfig
{
    /**
     * Config file.
     */
    const CONFIG_FILE = 'model-base';

    /**
     * @var string
     */
    const WILDCARD_CONNECTION_STUD = '{{Connection}}';

    /**
     * @var string
     */
    const WILDCARD_DRIVER_STUD = '{{Driver}}';

    /**
     * @var string[]
     */
    protected $modifiers = [

        // Connection
        Modifiers\ConnectionModifier::class,

        // Table
        Modifiers\TableModifier::class,

        // Timestamps
        Modifiers\TimestampsModifier::class,

        // Dates
        Modifiers\DatesModifier::class,

        // Soft Deletes
        Modifiers\SoftDeletesModifier::class,

        // Attributes
        Modifiers\AttributesModifier::class,

        // CamelToSnake Attributes
        Modifiers\CamelToSnakeModifier::class,

        // For custom aliases
        Modifiers\ColumnAliasModifier::class,

        // PhpDoc tags
        Modifiers\PhpDocModifier::class,

        // PhpDoc tags
        Modifiers\AuthModifier::class,

        // Custom
        Modifiers\CustomModelOptionsModifier::class,

        // Relations
        // Input transformations
        // ValueObjects
    ];

    /**
     * Util configuration.
     * This config will have the following priority:
     * - config parameters in constructor.
     * - laravel config (/config/model-base.php).
     * - default config (../config/model-base.php).
     *
     * @var array
     */
    protected $items = [];

    /**
     * @var \Illuminate\Database\Connection
     */
    protected $connection;

    /**
     * ModelBaseConfig constructor.
     *
     * @param \Illuminate\Database\Connection $connection
     */
    public function __construct($connection)
    {
        $this->items = array_merge(
            $this->loadConfig(static::CONFIG_FILE),
            $this->loadConfig(static::CONFIG_FILE . '.drivers.' . $connection->getDriverName()),
            $this->loadConfig(static::CONFIG_FILE . '.connections.' . $connection->getName())
            // $this->loadConfig(static::CONFIG_FILE.'.tables.'.$tableName),
            // $this->loadConfig(static::CONFIG_FILE.'.connections.'.$connection->getName().'.tables.'.$tableName),
        );

        $this->connection = $connection;
    }

    /**
     * @param $name
     *
     * @return array|mixed
     */
    protected function loadConfig($name)
    {
        return Config::has($name) ? Config::get($name) : [];
    }

    /**
     * Determine if the given configuration value exists.
     *
     * @param string $key
     *
     * @return bool
     */
    public function has($key)
    {
        return Arr::has($this->items, $key);
    }

    /**
     * Get the specified configuration value.
     *
     * @param string $key
     * @param mixed  $default
     *
     * @return mixed
     */
    public function get($key, $default = null)
    {
        return Arr::get($this->items, $key, $default);
    }

    /**
     * Set a given configuration value.
     *
     * @param array|string $key
     * @param mixed        $value
     *
     * @return void
     */
    /*public function set($key, $value = null)
    {
        if (is_array($key)) {
            foreach ($key as $innerKey => $innerValue) {
                Arr::set($this->items, $innerKey, $innerValue);
            }
        } else {
            Arr::set($this->items, $key, $value);
        }
    }*/

    /**
     * fnmatch separated by |
     * http://php.net/fnmatch
     * '*gr[ae]y' is gray and grey
     * 'gray|grey' is also gray and grey
     * '*At|*_at finish in 'At' or '_at'
     *
     * @param string|string[] $rules
     * @param string          $value
     * @param bool            $case_sensitive
     *
     * @return bool
     */
    public function match($rules, $value, $case_sensitive = false)
    {
        //return fnmatch($rules, $value);

        if (is_string($rules)) {
            $rules = explode('|', $rules);
        }

        foreach ($rules as $rule) {
            $rule = str_replace(' ', '', $rule);
{'fraction_non_alphanumeric': 0.1406049281793764, 'fraction_numerical': 0.0, 'mean_word_length': 1.8932432432432433, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, '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': '3675819', 'n_tokens_mistral': 2535, 'n_tokens_neox': 2496, 'n_words': 502}