<commit_before>RedirectHandlerModule
=====================

[![PHP version](https://badge.fury.io/ph/samsonasik%2Fredirect-handler-module.svg)](https://badge.fury.io/ph/samsonasik%2Fredirect-handler-module)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
[![Build Status](https://travis-ci.org/samsonasik/RedirectHandlerModule.svg?branch=master)](https://travis-ci.org/samsonasik/RedirectHandlerModule)
[![Coverage Status](https://coveralls.io/repos/samsonasik/RedirectHandlerModule/badge.svg?branch=master)](https://coveralls.io/r/samsonasik/RedirectHandlerModule)
[![Downloads](https://img.shields.io/packagist/dt/samsonasik/redirect-handler-module.svg?style=flat-square)](https://packagist.org/packages/samsonasik/redirect-handler-module)

*RedirectHandlerModule* is a module for handling redirect when the given url to redirect plugin is not registered in your zf2/zf3 application. It simply override existing ZF2/ZF3 redirect plugin, so we can just use it.

For example, we use `redirect()` plugin in your controller:

```php
$redirect = '/foo'; // may be a variable from GET
return $this->redirect()->toUrl($redirect);
```

if the passed `$redirect` as url is a valid and registered in the routes, it uses default `redirect()` implementation, otherwise, it will redirect to default `default_url` registered in `config/autoload/redirect-handler-module.local.php`:

For example, we define:

```php
return array(
    'redirect_handler_module' => array(
        'allow_not_routed_url' => false,
        'default_url' => '/',
        'options' => array(
            'exclude_urls' => array(
                // 'https://www.github.com/samsonasik/RedirectHandlerModule',
            ), // to allow excluded urls to be allowed
        ),
    ),
);
```

It means, we can't allow to make redirect to outside registered routes, whenever found un-registered url in routes, then we will be redirected to default_url. For specific urls that exceptional ( allowed to be redirected even not registered in routes), you can register at `exclude_urls` options. 

It disable redirect o self, so you can't redirect to self. While default implementation of redirect to self will silently, you can trigger your listener to handle redirect to self in your Module::onBootstrap($e):

```php
class Module
{
    public function onBootstrap($e)
    {
        $eventManager  = $e->getApplication()->getEventManager();
        $sharedManager = $eventManager->getSharedManager();

        $sharedManager->attach('RedirectHandlerModule\Controller\Plugin\Redirect', 'redirect-same-url', function() {
            die('You need to use different URL for Redirect');
        });
    }
}
```

Installation
------------<commit_msg>wording<commit_after>RedirectHandlerModule
=====================

[![PHP version](https://badge.fury.io/ph/samsonasik%2Fredirect-handler-module.svg)](https://badge.fury.io/ph/samsonasik%2Fredirect-handler-module)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
[![Build Status](https://travis-ci.org/samsonasik/RedirectHandlerModule.svg?branch=master)](https://travis-ci.org/samsonasik/RedirectHandlerModule)
[![Coverage Status](https://coveralls.io/repos/samsonasik/RedirectHandlerModule/badge.svg?branch=master)](https://coveralls.io/r/samsonasik/RedirectHandlerModule)
[![Downloads](https://img.shields.io/packagist/dt/samsonasik/redirect-handler-module.svg?style=flat-square)](https://packagist.org/packages/samsonasik/redirect-handler-module)

*RedirectHandlerModule* is a module for handling redirect when the given url to redirect plugin is not registered in your zf2/zf3 application. It simply override existing ZF2/ZF3 redirect plugin, so we can just use it.

For example, we use `redirect()` plugin in your controller:

```php
$redirect = '/foo'; // may be a variable from GET
return $this->redirect()->toUrl($redirect);
```

if the passed `$redirect` as url is a valid and registered in the routes, it uses default `redirect()` implementation, otherwise, it will redirect to default `default_url` registered in `config/autoload/redirect-handler-module.local.php`:

For example, we define:

```php
return array(
    'redirect_handler_module' => array(
        'allow_not_routed_url' => false,
        'default_url' => '/',
        'options' => array(
            'exclude_urls' => array(
                // 'https://www.github.com/samsonasik/RedirectHandlerModule',
            ), // to allow excluded urls to be allowed
        ),
    ),
);
```

It means, we can't allow to make redirect to outside registered routes, whenever found un-registered url in routes, then we will be redirected to default_url. For specific urls that exceptional ( allowed to be redirected even not registered in routes), you can register at `exclude_urls` options. 

It disable redirect to self, so you can't redirect to self. While default implementation of redirect to self will silently, you can trigger your listener to handle redirect to self in your Module::onBootstrap($e):

```php
class Module
{
    public function onBootstrap($e)
    {
        $eventManager  = $e->getApplication()->getEventManager();
        $sharedManager = $eventManager->getSharedManager();

        $sharedManager->attach('RedirectHandlerModule\Controller\Plugin\Redirect', 'redirect-same-url', function() {
            die('You need to use different URL for Redirect');
        });
    }
}
```

Installation
------------
{'fraction_non_alphanumeric': 0.1354639549664064, 'fraction_numerical': 0.002179044852006537, 'mean_word_length': 4.301251203079884, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 20, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4341733', 'n_tokens_mistral': 1596, 'n_tokens_neox': 1543, 'n_words': 434}