Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions en/02_Developer_Guides/17_CLI/01_Sake.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
1 change: 1 addition & 0 deletions en/08_Changelogs/6.1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down