Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Collapse empty tokens #39

Merged
merged 1 commit into from
Mar 23, 2015
Merged

Collapse empty tokens #39

merged 1 commit into from
Mar 23, 2015

Conversation

dantleech
Copy link
Member

This PR:

  • Throws an exception by default when a token provider produces an empty value
  • Adds a global token provider option collapse_empty which permits empty tokens and removes any trailing slash.

Fixes: #35

@dantleech dantleech force-pushed the collapse_empty branch 2 times, most recently from 3c7d0fe to baced10 Compare March 19, 2015 13:18

$tokens['{' . $name . '}'] = $tokenProvider->provideValue($uriContext, $optionsResolver->resolve($options['options']));
if ($isEmpty && true === $tokenProviderOptions['collapse_empty']) {
$tokens[$tokenString . '/'] = (string) $tokenValue;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We treat / as a de facto empty value and apply the same logic as we would for an empty string.

@dantleech
Copy link
Member Author

ping @wouterj @dbu

@dbu
Copy link
Member

dbu commented Mar 20, 2015

👍

private function configureGlobalOptions(OptionsResolver $optionsResolver)
{
$optionsResolver->setDefaults(array(
'collapse_empty' => false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about allow_empty? Collapse empty is pretty vague imo

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, collapse_empty hints that it does more than allowing empty, and it also allows to add a real allow_empty in the future if required.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, imo:

  • If a token is empty, it's trailing slash is stripped
  • By default, a token cannot be empty. An empty token throws an exception
  • You can change this behaviour by overriding allow_empty, which will allow an empty token

I think they are 2 generic and seperate processes. One is to always remove trailing slashes when a token is empty. The other is to allow or not to allow empty tokens. Only the second process can be changed by this option

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I undetstand your last point. But thinking about I can't see a situation where you would want to allow empty and not collapse slashes, so +1 for allow_empty.

// if the last segment is empty and allow empty is true, then remove the leading slash
array(
'/{locale}/{parent}',
'/de',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new.. if the the last segment is empty and allow empty is true, then remove the leading slash

@dantleech
Copy link
Member Author

Added some more logic and changed name from collapse_empty to allow_empty.

@wouterj
Copy link
Member

wouterj commented Mar 21, 2015

👍

@dantleech
Copy link
Member Author

Merged, see doc PR: symfony-cmf/symfony-cmf-docs#668

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handling empty tokens or "//" when generating URLs
3 participants