diff --git a/en/02_Developer_Guides/17_CLI/01_Sake.md b/en/02_Developer_Guides/17_CLI/01_Sake.md index bca8a8c47..377fc7982 100644 --- a/en/02_Developer_Guides/17_CLI/01_Sake.md +++ b/en/02_Developer_Guides/17_CLI/01_Sake.md @@ -102,3 +102,20 @@ Sake doesn't use your project's routing and controllers for normal execution. Ho ```bash sake navigate about-us/teams ``` + +## Accessing sake from outside a command {#sake-injector} + +When executing commands via the Sake CLI application, both the [`Sake`](api:SilverStripe\Cli\Sake) instance and the `Symfony\Component\Console\Command\Command` instance are added to the dependency injector. + +This allows you to access both the application itself and the current command from anywhere in your code execution chain: + +```php +use SilverStripe\Cli\Sake; +use SilverStripe\Core\Injector\Injector; +use Symfony\Component\Console\Command\Command; + +$sake = Injector::inst()->get(Sake::class); +$command = Injector::inst()->get(Command::class); +``` + +This mirrors the way that the [`HTTPRequest`](api:SilverStripe\Control\HTTPRequest) is added to the injector whenever an HTTP request is being processed. diff --git a/en/08_Changelogs/6.1.0.md b/en/08_Changelogs/6.1.0.md index 28107edb2..7b0c2ae21 100644 --- a/en/08_Changelogs/6.1.0.md +++ b/en/08_Changelogs/6.1.0.md @@ -100,6 +100,7 @@ Note that if you are using [`silverstripe/hybridsessions`](https://packagist.org ### Other new features - New [`FileIDHelper::VARIANT_SEPARATOR`](api:SilverStripe\Assets\FilenameParsing\FileIDHelper::VARIANT_SEPARATOR) improves discoverability of the string that separates variant names from original file names in the asset system. +- When executing commands via the [Sake CLI application](/developer_guides/cli/sake/), both the [`Sake`](api:SilverStripe\Cli\Sake) instance and the `Symfony\Component\Console\Command\Command` instance are added to the dependency injector. See [accessing sake from outside a command](/developer_guides/cli/sake/#sake-injector) for more details. ## API changes