Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9023733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:49:55+00:00 2026-06-16T05:49:55+00:00

Is there a way to access the kernel from inside a compiler pass? I’ve

  • 0

Is there a way to access the kernel from inside a compiler pass? I’ve tried this:

    ...
    public function process(ContainerBuilder $container)
    {
        $kernel = $container->get('kernel');
    }
    ...

This throws an error. Is there another way to do it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:49:56+00:00Added an answer on June 16, 2026 at 5:49 am

    As far as I can tell, Kernel isn’t available anywhere in a CompilerPass, by default.

    But you can add it in by doing this:

    In your AppKernel, pass $this to the bundle the compiler pass is in.

    • Add a constructor to your Bundle object, which accepts the Kernel as a parameter and stores it as a property.
    • In your Bundle::build() function, pass the Kernel to your CompilerPass instance.
    • In your CompilerPass, at a constructor to accept the Kernel as a parameter and store it as a property.
    • Then you can use $this->kernel in your compiler pass.

    // app/AppKernel.php
    new My\Bundle($this);
    
    // My\Bundle\MyBundle.php
    use Symfony\Component\HttpKernel\KernelInterface;
    
    class MyBundle extends Bundle {
    protected $kernel;
    
    public function __construct(KernelInterface $kernel)
    {
      $this->kernel = $kernel;
    }
    
    public function build(ContainerBuilder $container)
    {
        parent::build($container);
        $container->addCompilerPass(new MyCompilerPass($this->kernel));
    }
    
    // My\Bundle\DependencyInjection\MyCompilerPass.php
    use Symfony\Component\HttpKernel\KernelInterface;
    
    class MyCompilerPass implements CompilerPassInterface
    protected $kernel;
    
    public function __construct(KernelInterface $kernel)
    {
       $this->kernel = $kernel;
    }
    
    public function process(ContainerBuilder $container)
    {
        // Do something with $this->kernel
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to access the local variable of a function from a
Is there a way to access domain objects in a groovy script? I've tried
Are there any way to access or set iphone's alarm? Im assuming if this
Is there any way to access the owning UITableView from within a UITableViewCell ?
Is there a way to access My.Resources thru Xaml? Like this <Image Source={Binding MyImage,
Is there a way to access the Cassini local web server from Windows 7's
Is there a way to access the DOM from the event fired by DOMContentLoaded
Is there a way to access internet from Zune HD (from XNA app or
Is there a way to access one instance of a class inside functions in
Is there a way to access to an id of selectItem JSF from JavaScript

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.