loadConfig(); $this->activeEnvironment = $environment ?? $this->config['active_environment']; } private function loadConfig() { $this->config = [ // Environment configurations 'environments' => [ 'test' => [ 'baseUrl' => 'https://test.dam.ferrero.com/otmmapi', 'authUrl' => 'https://test.dam.ferrero.com/otdsws/oauth2/token', 'description' => 'Test Environment' ], 'production' => [ 'baseUrl' => 'https://ppr.dam.ferrero.com/otmmapi', 'authUrl' => 'https://ppr.dam.ferrero.com/otdsws/oauth2/token', 'description' => 'Production Environment' ] ], // Active environment (switch between 'test' and 'production') 'active_environment' => 'production', // Postman collection file (using old working collection with OAuth2 configured) 'postman_collection' => 'Content Scaling Flow.postman_collection_Oliver(New).json', // Credentials file 'credentials_file' => 'Creds.txt', // Folder names (consistent across environments) 'folder_names' => [ 'master_assets' => '01. Master Assets', 'final_assets' => '01. Final Assets', 'localized_assets' => 'Localized Assets' ], // Status field configuration 'status_field' => [ 'field_id' => 'CONTENT.SCALING.STATUS', 'field_name' => 'Content Scaling Status', 'values' => [ 'A0' => 'Local Campaign Created', 'A1' => 'Local Campaign ready for localization', 'A2' => 'Selected Master Assets sent to Agency', 'A3' => 'Localized Asset received from Agency', 'A4' => 'Localization completed', 'A5' => 'Rework needed from agency', 'A6' => 'Assets to be reworked received by the Agency', 'B1' => 'Master campaign ready for re-mastering', 'B2' => 'Master campaign received from Agency' ] ], // Download configuration 'downloads' => [ 'base_path' => 'downloads', 'organize_by_campaign' => true, 'preserve_metadata' => true ], // Upload configuration 'uploads' => [ 'allowed_extensions' => ['jpg', 'jpeg', 'png', 'gif', 'pdf', 'ai', 'psd', 'eps', 'tif', 'tiff', 'mov', 'mp4', 'avi', 'zip', 'txt', 'doc', 'docx', 'xls', 'xlsx'], 'max_file_size' => 100 * 1024 * 1024, // 100MB (for video files) 'preserve_filenames' => true ], // API settings 'api' => [ 'timeout' => 120, 'retry_attempts' => 3, 'retry_delay' => 2 ], // Logging 'logging' => [ 'enabled' => true, 'log_dir' => 'logs', 'log_file' => 'workflow_v3.log', 'log_level' => 'INFO' ] ]; } /** * Get configuration value by key (supports dot notation) */ 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; } /** * Get current environment configuration */ public function getEnvironment() { return $this->config['environments'][$this->activeEnvironment] ?? null; } /** * Get base URL for current environment */ public function getBaseUrl() { $env = $this->getEnvironment(); return $env['baseUrl'] ?? ''; } /** * Get auth URL for current environment */ public function getAuthUrl() { $env = $this->getEnvironment(); return $env['authUrl'] ?? ''; } /** * Get active environment name */ public function getActiveEnvironment() { return $this->activeEnvironment; } /** * Switch environment */ public function switchEnvironment($environment) { if (!isset($this->config['environments'][$environment])) { throw new Exception("Invalid environment: {$environment}"); } $this->activeEnvironment = $environment; } /** * Get status description by code */ public function getStatusDescription($statusCode) { return $this->config['status_field']['values'][$statusCode] ?? 'Unknown Status'; } /** * Get all status codes */ public function getAllStatuses() { return $this->config['status_field']['values']; } /** * Get folder name by type */ public function getFolderName($type) { return $this->config['folder_names'][$type] ?? null; } /** * Get download path for campaign */ public function getDownloadPath($campaignId, $subFolder = '') { $basePath = $this->config['downloads']['base_path']; if ($this->config['downloads']['organize_by_campaign']) { $path = $basePath . '/' . $campaignId; if ($subFolder) { $path .= '/' . $subFolder; } return $path; } return $basePath; } /** * Validate configuration */ public function validate() { $errors = []; // Check if active environment exists if (!isset($this->config['environments'][$this->activeEnvironment])) { $errors[] = "Active environment '{$this->activeEnvironment}' not configured"; } // Check if Postman collection exists $collectionPath = $this->config['postman_collection']; if (!file_exists($collectionPath)) { $errors[] = "Postman collection not found: {$collectionPath}"; } // Check if credentials file exists $credsFile = $this->config['credentials_file']; if (!file_exists($credsFile)) { $errors[] = "Credentials file not found: {$credsFile}"; } // Check download directory $downloadPath = $this->config['downloads']['base_path']; if (!is_dir($downloadPath) && !mkdir($downloadPath, 0755, true)) { $errors[] = "Cannot create download directory: {$downloadPath}"; } // Check log directory $logDir = $this->config['logging']['log_dir']; if (!is_dir($logDir) && !mkdir($logDir, 0755, true)) { $errors[] = "Cannot create log directory: {$logDir}"; } return $errors; } /** * Get environment info for display */ public function getEnvironmentInfo() { $env = $this->getEnvironment(); return [ 'name' => $this->activeEnvironment, 'description' => $env['description'] ?? '', 'baseUrl' => $env['baseUrl'] ?? '', 'authUrl' => $env['authUrl'] ?? '' ]; } }