<commit_before><?php
namespace DreamFactory\Core\Azure\Components;

use DreamFactory\Core\Azure\Models\AzureConfig;
use DreamFactory\Core\Components\FileServiceWithContainer;
use DreamFactory\Core\Contracts\ServiceConfigHandlerInterface;
use DreamFactory\Core\Models\FilePublicPath;
use DreamFactory\Library\Utility\ArrayUtils;

class AzureBlobConfig implements ServiceConfigHandlerInterface
{
    use FileServiceWithContainer;

    /**
     * {@inheritdoc}
     */
    public static function getConfig($id, $protect = true)
    {
        $config = [];

        /** @var AzureConfig $azureConfig */
        if (!empty($azureConfig = AzureConfig::find($id))) {
            $azureConfig->protectedView = $protect;
            $config = $azureConfig->toArray();
        }

        /** @var FilePublicPath $pathConfig */
        if (!empty($pathConfig = FilePublicPath::find($id))) {
            $config = array_merge($config, $pathConfig->toArray());
        }

        return $config;
    }

    /**
     * {@inheritdoc}
     */
    public static function validateConfig($config, $create=true)
    {
        return (AzureConfig::validateConfig($config, $create) && FilePublicPath::validateConfig($config, $create));
    }

    /**
     * {@inheritdoc}
     */
    public static function setConfig($id, $config)
    {
        /** @var AzureConfig $azureConfig */
        $azureConfig = AzureConfig::find($id);
        /** @var FilePublicPath $pathConfig */
        $pathConfig = FilePublicPath::find($id);
        $configPath = [
            'public_path' => array_get($config, 'public_path'),
            'container'   => array_get($config, 'container')
        ];
        $configAzure = [
            'service_id'   => array_get($config, 'service_id'),
            'account_name' => array_get($config, 'account_name'),
            'account_key'  => array_get($config, 'account_key'),
            'protocol'     => array_get($config, 'protocol')
        ];

        ArrayUtils::removeNull($configAzure);
        ArrayUtils::removeNull($configPath);

        if (!empty($azureConfig)) {
            $azureConfig->update($configAzure);
        } else {
            //Making sure service_id is the first item in the config.
            //This way service_id will be set first and is available
            //for use right away. This helps setting an auto-generated
            //field that may depend on parent data. See OAuthConfig->setAttribute.
            $configAzure = array_reverse($configAzure, true);
            $configAzure['service_id'] = $id;
            $configAzure = array_reverse($configAzure, true);
            AzureConfig::create($configAzure);
        }

        if (!empty($pathConfig)) {
            $pathConfig->update($configPath);
        } else {
            //Making sure service_id is the first item in the config.
            //This way service_id will be set first and is available
            //for use right away. This helps setting an auto-generated
            //field that may depend on parent data. See OAuthConfig->setAttribute.
            $configPath = array_reverse($configPath, true);
            $configPath['service_id'] = $id;
            $configPath = array_reverse($configPath, true);
            FilePublicPath::create($configPath);
        }
    }

    /**
     * {@inheritdoc}
     */
    public static function getConfigSchema()
    {
        $azureConfig = new AzureConfig();
        $pathConfig = new FilePublicPath();
        $out = null;

        $azureSchema = $azureConfig->getConfigSchema();
        $pathSchema = $pathConfig->getConfigSchema();

        static::updatePathSchema($pathSchema);

        if (!empty($azureSchema)) {
            $out = $azureSchema;
        }
        if (!empty($pathSchema)) {
            $out = ($out) ? array_merge($out, $pathSchema) : $pathSchema;
        }

        return $out;
    }

    /**
     * {@inheritdoc}
     */
    public static function removeConfig($id)
    {
        // deleting is not necessary here due to cascading on_delete relationship in database
    }

    /**
     * {@inheritdoc}
     */
    public static function getAvailableConfigs()
    {
        return null;
    }
}<commit_msg>File service config rework from df-core.<commit_after><?php
namespace DreamFactory\Core\Azure\Components;

use DreamFactory\Core\Azure\Models\AzureConfig;
use DreamFactory\Core\Contracts\ServiceConfigHandlerInterface;
use DreamFactory\Core\Models\FilePublicPath;
use DreamFactory\Library\Utility\ArrayUtils;

class AzureBlobConfig implements ServiceConfigHandlerInterface
{
    /**
     * {@inheritdoc}
     */
    public static function getConfig($id, $protect = true)
    {
        $config = [];

        /** @var AzureConfig $azureConfig */
        if (!empty($azureConfig = AzureConfig::find($id))) {
            $azureConfig->protectedView = $protect;
            $config = $azureConfig->toArray();
        }

        /** @var FilePublicPath $pathConfig */
        if (!empty($pathConfig = FilePublicPath::find($id))) {
            $config = array_merge($config, $pathConfig->toArray());
        }

        return $config;
    }

    /**
     * {@inheritdoc}
     */
    public static function validateConfig($config, $create=true)
    {
        return (AzureConfig::validateConfig($config, $create) && FilePublicPath::validateConfig($config, $create));
    }

    /**
     * {@inheritdoc}
     */
    public static function setConfig($id, $config)
    {
        /** @var AzureConfig $azureConfig */
        $azureConfig = AzureConfig::find($id);
        /** @var FilePublicPath $pathConfig */
        $pathConfig = FilePublicPath::find($id);
        $configPath = [
            'public_path' => array_get($config, 'public_path'),
            'container'   => array_get($config, 'container')
        ];
        $configAzure = [
            'service_id'   => array_get($config, 'service_id'),
            'account_name' => array_get($config, 'account_name'),
            'account_key'  => array_get($config, 'account_key'),
            'protocol'     => array_get($config, 'protocol')
        ];

        ArrayUtils::removeNull($configAzure);
        ArrayUtils::removeNull($configPath);

        if (!empty($azureConfig)) {
            $azureConfig->update($configAzure);
        } else {
            //Making sure service_id is the first item in the config.
            //This way service_id will be set first and is available
            //for use right away. This helps setting an auto-generated
            //field that may depend on parent data. See OAuthConfig->setAttribute.
            $configAzure = array_reverse($configAzure, true);
            $configAzure['service_id'] = $id;
            $configAzure = array_reverse($configAzure, true);
            AzureConfig::create($configAzure);
        }

        if (!empty($pathConfig)) {
            $pathConfig->update($configPath);
        } else {
            //Making sure service_id is the first item in the config.
            //This way service_id will be set first and is available
            //for use right away. This helps setting an auto-generated
            //field that may depend on parent data. See OAuthConfig->setAttribute.
            $configPath = array_reverse($configPath, true);
            $configPath['service_id'] = $id;
            $configPath = array_reverse($configPath, true);
            FilePublicPath::create($configPath);
        }
    }

    /**
     * {@inheritdoc}
     */
    public static function getConfigSchema()
    {
        $out = null;
        $azureConfig = new AzureConfig();
        if (!empty($azureSchema = $azureConfig->getConfigSchema())) {
            $out = $azureSchema;
        }
        $pathConfig = new FilePublicPath();
        if (!empty($pathSchema = $pathConfig->getConfigSchema())) {
            $out = ($out) ? array_merge($out, $pathSchema) : $pathSchema;
        }

        return $out;
    }

    /**
     * {@inheritdoc}
     */
    public static function removeConfig($id)
    {
        // deleting is not necessary here due to cascading on_delete relationship in database
    }

    /**
     * {@inheritdoc}
     */
    public static function getAvailableConfigs()
    {
        return null;
    }
}
{'fraction_non_alphanumeric': 0.12648845686512758, 'fraction_numerical': 0.0, 'mean_word_length': 2.302969502407705, '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': '4421293', 'n_tokens_mistral': 2196, 'n_tokens_neox': 2162, 'n_words': 506}