Complete PHP-based workflow application for Ferrero DAM system: - OAuth2 authentication with automatic token management - Campaign discovery and filtering - Folder structure navigation - Asset download (individual and bulk) - Metadata extraction and display - Clean step-by-step web interface Status: Fully functional and production-ready 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
115 lines
No EOL
2.8 KiB
PHP
115 lines
No EOL
2.8 KiB
PHP
<?php
|
|
|
|
class Config
|
|
{
|
|
private $configFile;
|
|
private $config;
|
|
|
|
public function __construct($configFile = 'config.json')
|
|
{
|
|
$this->configFile = $configFile;
|
|
$this->loadConfig();
|
|
}
|
|
|
|
private function loadConfig()
|
|
{
|
|
$defaultConfig = [
|
|
'baseUrl' => '',
|
|
'apiKey' => '',
|
|
'timeout' => 30,
|
|
'headers' => [
|
|
'Content-Type' => 'application/json',
|
|
'Accept' => 'application/json'
|
|
],
|
|
'logging' => [
|
|
'enabled' => true,
|
|
'logFile' => 'logs/test_results.log',
|
|
'logLevel' => 'INFO'
|
|
]
|
|
];
|
|
|
|
if (file_exists($this->configFile)) {
|
|
$fileConfig = json_decode(file_get_contents($this->configFile), true);
|
|
$this->config = array_merge($defaultConfig, $fileConfig ?: []);
|
|
} else {
|
|
$this->config = $defaultConfig;
|
|
}
|
|
}
|
|
|
|
public function get($key = null)
|
|
{
|
|
if ($key === null) {
|
|
return $this->config;
|
|
}
|
|
|
|
$keys = explode('.', $key);
|
|
$value = $this->config;
|
|
|
|
foreach ($keys as $k) {
|
|
if (isset($value[$k])) {
|
|
$value = $value[$k];
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
return $value;
|
|
}
|
|
|
|
public function set($key, $value)
|
|
{
|
|
$keys = explode('.', $key);
|
|
$config = &$this->config;
|
|
|
|
foreach ($keys as $k) {
|
|
if (!isset($config[$k])) {
|
|
$config[$k] = [];
|
|
}
|
|
$config = &$config[$k];
|
|
}
|
|
|
|
$config = $value;
|
|
}
|
|
|
|
public function save()
|
|
{
|
|
$json = json_encode($this->config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
|
|
return file_put_contents($this->configFile, $json) !== false;
|
|
}
|
|
|
|
public function getEnvironmentVariables()
|
|
{
|
|
$envVars = [];
|
|
|
|
if (!empty($this->config['baseUrl'])) {
|
|
$envVars['baseUrl'] = $this->config['baseUrl'];
|
|
}
|
|
|
|
if (!empty($this->config['apiKey'])) {
|
|
$envVars['apiKey'] = $this->config['apiKey'];
|
|
}
|
|
|
|
return $envVars;
|
|
}
|
|
|
|
public function validateConfig()
|
|
{
|
|
$errors = [];
|
|
|
|
if (empty($this->config['baseUrl'])) {
|
|
$errors[] = 'Base URL is required';
|
|
} elseif (!filter_var($this->config['baseUrl'], FILTER_VALIDATE_URL)) {
|
|
$errors[] = 'Base URL must be a valid URL';
|
|
}
|
|
|
|
if (empty($this->config['apiKey'])) {
|
|
$errors[] = 'API Key is required';
|
|
}
|
|
|
|
if (!is_numeric($this->config['timeout']) || $this->config['timeout'] <= 0) {
|
|
$errors[] = 'Timeout must be a positive number';
|
|
}
|
|
|
|
return $errors;
|
|
}
|
|
} |