Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[HttpFoundation] Adding getString() method to ParameterBag #48219

Copy link
Copy link
Closed
@silasjoisten

Description

@silasjoisten
Issue body actions

Description

I have seen that there are several different ways to get a parameter from the parameter bag. For example

  • getBoolean()
  • getInteger()
  • getAlpha()
  • getAlnum()
  • etc.

It would be a nice small feature to add a function which returns a string. Benefit would be you dont have to cast the type always by yourself and have a strict type

Example

// src/Security/FormAuthenticator.php

class FormAuthenticator extends AbstractLoginFormAuthenticator
{
  // ...
   public function authenticate(Request $request): Passport
      {
         -$username = (string)$request->request->get('username', '');
         +$username = $request->request->getString('username');
         -$password = (string)$request->request->get('password', '');
         +$password = $request->request->getString('password');
         -$csrfToken = (string)$request->request->get('_csrf_token', '');
         +$csrfToken = $request->request->getString('_csrf_token');
  
         return new Passport(
             new UserBadge($username),
             new PasswordCredentials($password),
             [new CsrfTokenBadge('authentication', $csrfToken)],
         );
      }

// ...
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.