8000 Function to check if the kernel is loaded via the console or a web request. · Issue #51340 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
Function to check if the kernel is loaded via the console or a web request. #51340
Closed
@y4roc

Description

@y4roc

Description

I had the problem that I had to check in a service if the function is called via CLI or web.

Depending on that, I had to make different calculations. That's where my idea comes from, that you could put a function isCLI() or isWeb() into the kernel.

Example

class MyService {
  public function __constructor(
    private readonly KernelInterface $kernel
  ){}
  
  public function myFunction(): void {
    if(!$this->kernel->isCLI())
    {
      return;
    }
    // Do things in CLI without Request()
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0