Skip to content

Commit

Permalink
add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
benwalch committed Oct 6, 2023
1 parent 2815553 commit 828b9f3
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
2 changes: 1 addition & 1 deletion UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

### New Features
- [BC BREAK] Config node `mode` has been removed and will be handled internally which simplifies i18n usability
- Configurable cookie expire flag
- Fully configurable redirector adapters

***

Expand Down
57 changes: 56 additions & 1 deletion docs/51_RedirectorAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,33 @@ redirector gets applied.

### Cookie Redirector
> Priority: `300`
If enabled, visitor gets redirected to the last selected locale
If enabled, visitor gets redirected to the last selected locale

Configuration:
```
config:
cookie:
path:
domain:
secure:
http_only:
same_site:
expire:
```

### GEO Redirector
> Priority: `200`
If enabled, visitor gets redirected based on IP and browser language

Configuration
```
config:
rules:
- { ignore_country: false, strict_country: true, strict_language: false }
- { ignore_country: false, strict_country: false, strict_language: false }
...
```

### Fallback Redirector
> Priority: `100`
If enabled, visitor gets redirected based on the `default_locale` setting defined in i18n settings (available in each zone)
Expand Down Expand Up @@ -52,6 +73,22 @@ App\Services\I18nBundle\RedirectorAdapter\Website:
- { name: i18n.adapter.redirector, alias: website, priority: 110 }
```
### 2. Enable
you can also provide config for your redirector
```yaml
# config/config.yaml
i18n:
registry:
rediretor:
website:
enabled: true
config:
my_config_node: 'value'
# etc ...

```

### 3. Create a class

Create a class, extend it from `AbstractRedirector`.
Expand All @@ -64,6 +101,7 @@ namespace App\Services\I18nBundle\RedirectorAdapter;
use I18nBundle\Adapter\Redirector\AbstractRedirector;
use I18nBundle\Adapter\Redirector\RedirectorBag;
use I18nBundle\Model\ZoneSiteInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class Website extends AbstractRedirector
{
Expand All @@ -73,6 +111,9 @@ class Website extends AbstractRedirector
if ($this->lastRedirectorWasSuccessful($redirectorBag) === true) {
return;
}

// get custom config
$myConfigValue = $this->config['my_config_node'];

// get the last decision bag
$lastDecisionBag = $redirectorBag->getLastRedirectorDecision();
Expand Down Expand Up @@ -144,5 +185,19 @@ class Website extends AbstractRedirector
$this->setDecision(['valid' => false]);
}
}

protected function getConfigResolver(): ?OptionsResolver
{
$optionsResolver = new OptionsResolver();

// preare your options resolver
$optionsResolver->setRequired('my_config_node');
$optionsResolver->setAllowedTypes('my_config_node', 'string');
// etc ..

return $optionsResolver;

}

}
```

0 comments on commit 828b9f3

Please sign in to comment.