Installation:
composer require nuvoleweb/robo-config
Add Trait to RoboFile.php:
use NuvoleWeb\Robo\Task\Config\loadTasks;
Create Configuration Files:
robo.yml.distrobo.yml (optional)robo.yml.dist:
site:
name: "Default Site"
url: "http://localhost"
Access Config in Robo:
$siteName = $this->config('site.name');
Run a command with CLI overrides:
./vendor/bin/robo my-task -o "site.url: http://example.com"
Verify config resolution:
// In RoboFile.php
public function myTask() {
$url = $this->config('site.url'); // Resolves to "http://example.com"
$this->say("Site URL: {$url}");
}
Hierarchical Overrides:
robo.yml.dist → Local overrides in robo.yml → CLI overrides (-o flag).# robo.yml.dist
database:
host: "localhost"
# robo.yml (local)
database:
host: "127.0.0.1"
./vendor/bin/robo db:backup -o "database.host: db.example.com"
Dynamic References:
Use !property.path syntax to reference other config values:
# robo.yml.dist
app:
name: "MyApp"
version: "1.0"
build:
version: !app.version
Environment-Specific Configs:
robo.yml for local dev, robo.yml.prod for production (load via CLI or script)../vendor/bin/robo deploy -c robo.yml.prod
PHP Config Generation: Convert YAML snippets to PHP arrays for frameworks like Drupal/Silex:
$this->taskWriteConfiguration('config.php', 'settings')
->setConfigKey('config')
->run();
Task Dependencies: Pass resolved config to other tasks:
$this->taskComposerInstall()
->option('no-dev', $this->config('install.no_dev'))
->run();
Validation:
Add custom validation in RoboFile.php:
public function validateConfig() {
if (empty($this->config('site.url'))) {
throw new \RuntimeException("Site URL is required!");
}
}
Modular Configs:
Split configs into multiple files (e.g., robo.db.yml, robo.api.yml) and merge them:
$this->config->merge('robo.db.yml');
File Priority:
robo.yml overrides robo.yml.dist only if it exists. Ensure robo.yml is committed to version control if shared configs are needed.-o) always take precedence.Circular References:
Avoid infinite loops with !property.path:
# ❌ Invalid (circular)
a: !b.value
b:
value: !a
PHP Config Conflicts:
taskWriteConfiguration for new files or validate content first.Case Sensitivity: Config keys are case-sensitive in YAML. Ensure consistency:
# ❌ Fails
site.Name: "Test" # Won't resolve $this->config('site.name')
Dump Config:
$this->say("Full config:\n" . print_r($this->config->all(), true));
Validate YAML:
Use robo.yml.dist as a template and validate with:
./vendor/bin/robo config:validate
CLI Override Debugging: Verify overrides with:
./vendor/bin/robo --help # Shows supported -o flags
Environment Variables:
Combine with vlucas/phpdotenv for env vars:
$this->config->set('db.host', getenv('DB_HOST'));
Default Values:
Use config('key', 'default'):
$timeout = $this->config('http.timeout', 30);
Custom Tasks: Extend the config system for project-specific needs:
use NuvoleWeb\Robo\Task\Config\ConfigAwareTrait;
class MyTask extends \Robo\Tasks {
use ConfigAwareTrait;
public function run() {
$this->say("Using config: " . $this->config('my.key'));
}
}
CI/CD Integration:
-o flags to tweak configs in pipelines (e.g., -o "deploy.env: production").- run: ./vendor/bin/robo deploy -o "deploy.target: staging"
Performance: Cache resolved configs in long-running processes:
$this->config->cache(true); // Disable auto-reload
How can I help you explore Laravel packages today?