Haehnchen / idea-php-symfony2-plugin

IntelliJ IDEA / PhpStorm Symfony Plugin
https://plugins.jetbrains.com/plugin/7219
MIT License
911 stars 137 forks source link

Make Method References easier to use with arrays #228

Open Blackskyliner opened 10 years ago

Blackskyliner commented 10 years ago

Hi there,

I have to following problem and the documentation didn't pointed out how to do this right.

I got a function where I got an array parameter like so: @param array $rules Array with #Route elements - Now this obviously doesn't work but it would feel kinda natural to me if it were working.

Maybe with some modifiers like #Route:key and #Route:value so it would be more specific. In my case I would need both the key and value mapping inside the array as I specify some routing redirection thingy in there whereas it is a source => destination mapping.

Is there a way to do this with the current supplied possibilities (with annotations!)? If so then why is the documentation about it either bad or non-existent?

(I feel the examples in the documentation are just not good enough to point out how some of the annotation features really work... - Therefore I also can't make them better as I don't exactly know how the feature really works in it's depths)

If this feature does not exist could it be, somehow, added?

Haehnchen commented 10 years ago

#Route:key are not supported, can u give me some real life code snippets? iam currently extracting all that stuff into an external plugin because its not only related to symfony2. so provide much info as possible

Blackskyliner commented 10 years ago

If the following header would be enough for an example:

/**
 * Set the Redirect
 *
 * The $rules define when to trigger the redirect
 * The KeyValue Pairs are route-mappings. Keys represent the refer route and 
 * values represent the rout of the current request, 
 * so we can decide if we should trigger the redirect.
 *
 * The $scope defines a namespace in which the redirect is valid.
 * If we leave $scrope with the route of our current request we delete the redirect.
 *
 * @param string $returnUrl Target URL if a $rule triggers.
 * @param array  $rules     Array with #Route:key and #Route:value elements.
 * @param string $scope     Scope (#Route)
 */
public function setRedirect($returnUrl, array $rules, $scope = null) { /* ... */ }

Usage would be:

setRedirect(
    $this->generateUrl('acme_first_steps'),
    array(
        // If 'payment_complete' redirects to 'profile' then intercept and redirect to 'first_steps'
        'acme_payment_complete' => 'acme_profile', 
    ),
    'acme_payment_' // ... but only if we never leaved the 'payment_*' scope.
);

Whereas $scope would not be an complete Route but thats my problem in the end, its not so common nor widely used..

But I'd like to see some completion for the array keys in the $rules array, I sometimes use routes as key in an array to map specific "things" to routes.

Hopefully this are enough information.

Haehnchen commented 10 years ago

found also this one:

                return $this->get('oro_ui.router')->redirectAfterSave(
                    ['route' => 'orocrm_call_update', 'parameters' => ['id' => $entity->getId()]],
                    ['route' => 'orocrm_call_index'],
                    $entity
                );