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 8070011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:15:24+00:00 2026-06-05T13:15:24+00:00

I am building a custom validator. In a controller I would get the security

  • 0

I am building a custom validator. In a controller I would get the security context using:

$this->get('security.context')->getToken()->getUser()

I can’t manage to do the same in a custom validator; could anyone help me out?

Thanks so much!

  • 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-05T13:15:26+00:00Added an answer on June 5, 2026 at 1:15 pm

    You either need to extend ContainerAware with your filter class then call setContainer on the class when you instantiate it or pass through the container to the class on construct. This is because filters are not container aware by default like the controller is.

    To do it by constructor you can add the __construct method like below to your filter class:

    protected $container;
    
    public function __construct($container){
        $this->container = $container;   
    }
    

    Either way you will need to use container in your call:

    $this->container->get('security.context')->getToken()->getUser()
    

    Check this link https://groups.google.com/forum/?fromgroups#!topic/symfony2/WWIc8N7KZrg for extending container aware idea for doctrine entities, might be of some help.

    Edit

    Looking at the docs for validator you can add a service if it has any dependencies:

    services:
        validator.unique.your_validator_name:
            class: Fully\Qualified\Validator\Class\Name
            tags:
                - { name: validator.constraint_validator, alias: alias_name }
    

    why not add an argument to that for the container:

    arguments:  [@security.context] 
    

    and then use the construct method?

    protected $security_context;
    
    public function __construct($security_context){
        $this->security_context = $security_context;   
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building a custom Content Management System for my client, using C#2008, ASP.Net
I am building custom reports in Microsoft CRM and am using the CRM_URL parameter
I'm building custom content filtering system using custom radio buttons. There are some problems
When building a custom control, how would you access the content between the opening
I am building a custom win32 control/widget and would like to change the cursor
I asked a question about building custom Thread Safe Generic List now I am
I'm building a custom Ubuntu kernel and have modified one of the source files.
I'm building a custom UITableView with each of the cells containing a piece of
I'm building a custom RTE that converts user input to a homebrewn markup, now
I’m building a custom robotish machine that has 8 switches I need to interface

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.