Skip to content

Function to check if the kernel is loaded via the console or a web request. #51340

@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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy