Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 0 additions & 86 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,92 +305,6 @@ The `authorization-guards.global.php` file provides configuration to restrict ac
]
```

## Slug

In terms of business logic, any application launched in production needs to be indexed by search engines as friendly as possible.

Here comes the *Slug module* that works together with the application's routing system, which adds the option to customize each route replacing the old pattern such as the name of the route as well as its action with a chosen alias. On top of that, it allows you to replace the attributes with a more coherent version without losing their main functionality.

The `slug.global.php.dist` is the main configuration for *Slug module* .

```php
// How to add a registered route to your slug configuration.
'slug_configuration' => [
// Detect a duplicate alias to avoid confusion.
// We may have duplicate aliases but it is not recommended
// that it requires future development on each project.
'detect_duplicates' => true,
// Main slug declaration.
'slug_route' => [
[
'route' => '[route name]', // <- Specify the route name.
'action' => '[route action]', // <- Specify the route action.
'alias' => '/[alias]', // <- Here you must add an alias for the
// specific route ex: /list/detail -> /product-detail.
'exchange' => [ // <- If you want to exchange your route
// attribute specify the exchange configuration or leave it empty.
'[attribute name]' => [ // <- Attribute name.
'table' => '[table name]', // <- The main table from which the attribute belongs.
'identifier' => '[table identifier]', // <- This must be the main attribute afferent column.
'exchangeColumn' => '[exchange column name]', // <- Specify the main column from which the slug will be generated.
'slugColumn' => '[slug column]' // <- This will be the main storage column for the generated slug.
],
.
.
// You can add here more attribute.
]
],
.
.
// You can add here more routes.
]
]
```
The main functionality of the `exchange` key is to replace one or more attributes that play the role of unique identifier later being used in controllers to access certain information, these unique identifiers can have an unfriendly format, irrelevant to the end user.

Therefore, we can replace the attribute with an auto-generated value from the column specified in the `exchangeColumn` key and then saved in the `slugColumn`.

Of course, we will have to make certain changes in the respective table requiring a field in which the generated value will be saved.

```php
// Example of slug configuration.
'slug_configuration' => [
'detect_duplicates' => true,
'slug_route' => [
[
'route' => 'page',
'action' => 'home',
'alias' => '/home-page',
'exchange' => []
],
// The slug configuration will replace the basic route pattern with a specified alias so
// the route path will be changed from `/page/home` to `/home-page`.
[
'route' => 'product',
'action' => 'detail',
'alias' => '/product',
'exchange' => [
'uuid' => [
'table' => 'products',
'identifier' => 'uuid',
'exchangeColumn' => 'name',
'slugColumn' => 'slug'
],
]
],
// The above configuration will replace the `uuid` attribute from
// the route declaration path `/product[/{action}[/{uuid}]]` with a generated value from
// `exchangeColumn` and stored in `slugColumn` key without changing his main functionality
// Therefore, changing the path with a more friendly format from
// `/product/detail/2e4c49d2-8187-11eb-a1c1-0c4de9a75a56` to `/product/product-name`.
]
]
```

*Remember that you can add the slug configuration only to a valid registered route !*

For redirect response you must use `UrlHelperPlugin::class` to generate the url, this class can detect the slug configuration.

## Languages

The `local.php.dist` file provides an example for working with multiple languages. The `translator` variable can be expanded to other languages using [Poedit](https://poedit.net/) which can edit `.po` files like the example in `data/language/da_DK/LC_MESSAGES/messages.po`. The compiled file will have the extension `.mo`
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@
"Frontend\\Contact\\": "src/Contact/src/",
"Frontend\\Page\\": "src/Page/src/",
"Frontend\\Plugin\\": "src/Plugin/src/",
"Frontend\\User\\": "src/User/src/",
"Frontend\\Slug\\": "src/Slug/src/"
"Frontend\\User\\": "src/User/src/"
}
},
"autoload-dev": {
Expand Down
36 changes: 0 additions & 36 deletions config/autoload/slug.global.php.dist

This file was deleted.

4 changes: 0 additions & 4 deletions config/autoload/templates.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
declare(strict_types=1);

use Dot\DebugBar\Extension\DebugBarExtension;
use Frontend\Slug\Factory\RouteExtensionFactory;
use Twig\Environment;
use Mezzio\Twig\TwigEnvironmentFactory;
use Mezzio\Twig\TwigRendererFactory;
use Laminas\ServiceManager\Factory\InvokableFactory;
use Mezzio\Template\TemplateRendererInterface;
use Dot\Twig\Extension\DateExtension;
use Dot\Twig\Extension\TranslationExtension;
use Frontend\Slug\TwigExtension\RouteExtension;

return [
'dependencies' => [
Expand All @@ -20,7 +18,6 @@
TemplateRendererInterface::class => TwigRendererFactory::class,
DateExtension::class => InvokableFactory::class,
TranslationExtension::class => InvokableFactory::class,
RouteExtension::class => RouteExtensionFactory::class,
],
],
'debug' => false,
Expand All @@ -36,7 +33,6 @@
'extensions' => [
DateExtension::class,
TranslationExtension::class,
RouteExtension::class,
DebugBarExtension::class,
],
'optimizations' => -1,
Expand Down
1 change: 0 additions & 1 deletion config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class_exists(\Mezzio\Swoole\ConfigProvider::class)
\Frontend\Page\ConfigProvider::class,
\Frontend\Plugin\ConfigProvider::class,
\Frontend\User\ConfigProvider::class,
\Frontend\Slug\ConfigProvider::class,

// Load application config in a pre-defined order in such a way that local settings
// overwrite global settings. (Loaded as first to last):
Expand Down
4 changes: 0 additions & 4 deletions config/pipeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
use Dot\Rbac\Guard\Middleware\ForbiddenHandler;
use Dot\Rbac\Guard\Middleware\RbacGuardMiddleware;
use Frontend\App\Middleware\AuthMiddleware;
use Frontend\Slug\Middleware\SlugMiddleware;

/**
* Setup middleware pipeline:
Expand Down Expand Up @@ -55,9 +54,6 @@
// - $app->pipe('/docs', $apiDocMiddleware);
// - $app->pipe('/files', $filesMiddleware);

// Slug Middleware must be triggered before RouteMiddleware!
$app->pipe(SlugMiddleware::class);

// Register the routing middleware in the middleware pipeline.
// This middleware registers the Mezzio\Router\RouteResult request attribute.
$app->pipe(RouteMiddleware::class);
Expand Down
10 changes: 3 additions & 7 deletions src/Plugin/src/Factory/PluginManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

namespace Frontend\Plugin\Factory;

use Dot\Controller\Plugin\UrlHelperPlugin;
use Frontend\Plugin\PluginManager;
use Frontend\Plugin\TemplatePlugin;
use Frontend\Plugin\UrlHelperPlugin;
use Frontend\Slug\SlugInterface;
use Mezzio\Helper\UrlHelper;
use Mezzio\Template\TemplateRendererInterface;
use Psr\Container\ContainerExceptionInterface;
Expand All @@ -31,12 +30,9 @@ public function __invoke(ContainerInterface $container): PluginManager
$pluginManager = new PluginManager($container, $container->get('config')['dot_controller']['plugin_manager']);

//register the built-in plugins, if the required component is present
if ($container->has(UrlHelper::class) && $container->has(SlugInterface::class)) {
if ($container->has(UrlHelper::class)) {
$pluginManager->setFactory('url', function (ContainerInterface $container) {
return new UrlHelperPlugin(
$container->get(UrlHelper::class),
$container->get(SlugInterface::class)
);
return new UrlHelperPlugin($container->get(UrlHelper::class));
});
}

Expand Down
83 changes: 0 additions & 83 deletions src/Plugin/src/UrlHelperPlugin.php

This file was deleted.

49 changes: 0 additions & 49 deletions src/Slug/src/ConfigProvider.php

This file was deleted.

Loading