Hi folks. I apologize if this is off-topic for the dev list, but I've
gotten no bites on the irc channel and it does deal with the symfony
internal API, so I'll give it a whirl here. Feel free to direct me
elsewhere.

I'm trying to build a user-specific menu that only contains internal
links the user has the credentials to view. I'm using the security.yml
files to manage the credentials for my modules, so I'd rather not
repeat these data in my menu code. Rather, I thought I might be able
to ask symfony itself to tell me what credentials are required to read
a given module/action pair. I've written code like so:

    $context = sfContext::getInstance();
    $controller = $context->getController();
    $router = sfRouting::getInstance();
    $modules_by_name = array(
      'Ask a Genius' => '@genius_index',
      'Manage Coaches' => '@students_index'
    );
    $my_modules = array();
    foreach ($modules_by_name as $name=>$route_name)
    {
      if ($route = $router->getRouteByName($route_name))
      {
        $params = $route[4]; // Is there any guarantee this won't change?
        $action = $controller->getAction($params['module'], $params['action']);
        $action->initialize($context);
        $credential = $action->getCredential();
        if ($this->hasCredential($credential))
        {
          $my_modules[$name] = $route_name;
        }
      }
    }

Sadly, the response from $action->getCredential() is always empty,
even after I've hit the given actions manually to ensure the
security.yml files have been parsed and cached. I tried tracing back
sfAction->setSecurityConfig() to see who calls it, but the answer
appears to be no one. It looks like the action I'm manually
constructing doesn't have its security metadata mixed in, but it's
unclear to me how that's supposed to happen. Any tips on how I might
do this and if it's a sane thing to try to do?

My specific example aside, the general task of testing the
accessibility of internal routes is not an uncommon requirement, and
it might be worthwhile for symfony to provide an API for this purpose.

Thanks for any help, and thanks for symfony itself.

- donald

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/symfony-devs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to