@@ -358,6 +358,117 @@ if you run castor [in verbose mode](../going-further/interacting-with-castor/log
358358Additionally, if this command fails when Castor is not in verbose mode, it will
359359ask you if you want to retry the command with the verbose arguments.
360360
361+ ### Configuration flags
362+
363+ Castor allows you to configure optional features through configuration flags.
364+ These flags control behavior changes that may be introduced in future versions
365+ of Castor, allowing you to opt-in or opt-out of specific features.
366+
367+ You can enable or disable flags when creating a context by using the ` config `
368+ parameter:
369+
370+ ``` php
371+ use Castor\Attribute\AsContext;
372+ use Castor\Config;
373+ use Castor\ConfigFlag;
374+ use Castor\Context;
375+
376+ #[AsContext(name: 'my_context')]
377+ function create_context(): Context
378+ {
379+ return new Context(
380+ config: (new Config())
381+ ->withEnabled(ConfigFlag::ContextAwareFilesystem)
382+ );
383+ }
384+ ```
385+
386+ You can also explicitly disable flags:
387+
388+ ``` php
389+ use Castor\Attribute\AsContext;
390+ use Castor\Config;
391+ use Castor\ConfigFlag;
392+ use Castor\Context;
393+
394+ #[AsContext(name: 'my_context')]
395+ function create_context(): Context
396+ {
397+ return new Context(
398+ config: (new Config())
399+ ->withDisabled(ConfigFlag::ContextAwareFilesystem)
400+ );
401+ }
402+ ```
403+
404+ Multiple flags can be configured at once:
405+
406+ ``` php
407+ use Castor\Config;
408+ use Castor\ConfigFlag;
409+
410+ $config = (new Config())
411+ ->withEnabled(ConfigFlag::ContextAwareFilesystem)
412+ ->withDisabled(ConfigFlag::SomeOtherFlag);
413+ ```
414+
415+ #### Checking flag status
416+
417+ You can check whether a flag is enabled in your tasks:
418+
419+ ``` php
420+ use Castor\Attribute\AsTask;
421+
422+ use function Castor\context;
423+ use function Castor\io;
424+
425+ #[AsTask()]
426+ function check_flags(): void
427+ {
428+ $context = context();
429+
430+ if ($context->config->isEnabled(ConfigFlag::ContextAwareFilesystem)) {
431+ io()->writeln('ContextAwareFilesystem is enabled.');
432+ }
433+ }
434+ ```
435+
436+ #### Available flags
437+
438+ - ` ConfigFlag::ContextAwareFilesystem ` : When enabled, filesystem operations
439+ will be automatically aware of the context's working directory.
440+
441+ #### Deprecation warnings
442+
443+ Configuration flags support a deprecation system to help you prepare for future
444+ versions of Castor. When a flag is not explicitly configured, or when it's
445+ configured to a value that will change in a future version, Castor will emit
446+ a deprecation warning.
447+
448+ These warnings help you understand:
449+
450+ - Which flags are not configured in your project
451+ - What the current default value is
452+ - What the future default value will be
453+ - In which version the default will change
454+
455+ To avoid these warnings, explicitly configure the flags you use:
456+
457+ ``` php
458+ use Castor\Config;
459+ use Castor\ConfigFlag;
460+ use Castor\Context;
461+
462+ return new Context(
463+ config: (new Config())
464+ ->withEnabled(ConfigFlag::ContextAwareFilesystem)
465+ );
466+ ```
467+
468+ > [ !TIP]
469+ > Check the [ configuration flags example] ( https://github.com/jolicode/castor/blob/main/examples/basic/context/config.php )
470+ > for a complete working example.
471+
361472## Advanced usage
362473
363474See [ this documentation] ( ../going-further/interacting-with-castor/advanced-context.md ) for more usage about
0 commit comments