Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,53 @@ You can then use the `Slugify::slugify()` method in your controllers:
$url = Slugify::slugify("welcome to the homepage");
```

### Laminas
Comment thread
loco8878 marked this conversation as resolved.
Outdated

Slugify can be easily used in Laminas applications. Included bridge provides a service and a view helper
Comment thread
loco8878 marked this conversation as resolved.
Outdated
already registered for you.

Just enable the module in your configuration like this.

```php
return array(
Comment thread
loco8878 marked this conversation as resolved.
Outdated
//...

'modules' => array(
'Application',
'Cocur\Slugify\Bridge\Laminas' // <- Add this line
Comment thread
loco8878 marked this conversation as resolved.
//...
)

//...
);
```

After that you can retrieve the `Cocur\Slugify\Slugify` service (or the `slugify` alias) and generate a slug.

```php
/** @var \Laminas\ServiceManager\ServiceManager $sm */
$slugify = $sm->get('Cocur\Slugify\Slugify');
Comment thread
loco8878 marked this conversation as resolved.
$slug = $slugify->slugify('Hällo Wörld');
$anotherSlug = $slugify->slugify('Hällo Wörld', '_');
```

In your view templates use the `slugify` helper to generate slugs.

```php
<?php echo $this->slugify('Hällo Wörld') ?>
<?php echo $this->slugify('Hällo Wörld', '_') ?>
```

The service (which is also used in the view helper) can be customized by defining this configuration key.

```php
return array(
'cocur_slugify' => array(
'reg_exp' => '/([^a-zA-Z0-9]|-)+/'
)
);
```

### Zend Framework 2
Comment thread
loco8878 marked this conversation as resolved.
Outdated

Slugify can be easely used in Zend Framework 2 applications. Included bridge provides a service and a view helper
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
"symfony/http-kernel": "^3.4 || ^4.3 || ^5.0 || ^6.0",
"symfony/phpunit-bridge": "^5.4 || ^6.0",
"twig/twig": "^2.12.1 || ~3.0",
"zendframework/zend-modulemanager": "~2.2",
"zendframework/zend-servicemanager": "~2.2",
"zendframework/zend-view": "~2.2"
"laminas/laminas-modulemanager": "~2.8",
"laminas/laminas-servicemanager": "~3.3",
"laminas/laminas-view": "~2.9"
},
"autoload": {
"psr-4": {
Expand Down
55 changes: 55 additions & 0 deletions src/Bridge/Laminas/ConfigProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Cocur\Slugify\Bridge\Laminas;

use Cocur\Slugify\Slugify;

class ConfigProvider
{
/**
* Retrieve laminas default configuration.
*
* @return array
*/
public function __invoke(): array
{
return [
'dependencies' => $this->getDependencyConfig(),
'view_helpers' => $this->getViewHelperConfig(),
];
Comment thread
loco8878 marked this conversation as resolved.
}

/**
* Retrieve laminas default dependency configuration.
*
* @return array
*/
public function getDependencyConfig(): array
{
return [
'factories' => [
Slugify::class => SlugifyService::class,
],
'aliases' => [
'slugify' => Slugify::class,
]
];
}

Comment thread
loco8878 marked this conversation as resolved.
/**
* Retrieve laminas view helper dependency configuration.
*
* @return array
*/
public function getViewHelperConfig(): array
{
return [
'aliases' => [
'slugify' => SlugifyViewHelper::class
],
'factories' => [
SlugifyViewHelper::class => SlugifyViewHelperFactory::class
]
];
}
}
24 changes: 24 additions & 0 deletions src/Bridge/Laminas/Module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Cocur\Slugify\Bridge\Laminas;

/**
* Class Module
* @package cocur/slugify
* @subpackage bridge
* @license http://www.opensource.org/licenses/MIT The MIT License
*/
class Module
{
public const CONFIG_KEY = 'cocur_slugify';

public function getConfig(): array
{
$provider = new ConfigProvider();
$config = $provider();
$config['service_manager'] = $config['dependencies'];
unset($config['dependencies']);

return $config;
}
}
35 changes: 35 additions & 0 deletions src/Bridge/Laminas/SlugifyService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Cocur\Slugify\Bridge\Laminas;

use Cocur\Slugify\Slugify;
use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;

/**
* Class SlugifyService
* @package cocur/slugify
* @subpackage bridge
* @license http://www.opensource.org/licenses/MIT The MIT License
*/
class SlugifyService implements FactoryInterface
Comment thread
loco8878 marked this conversation as resolved.
Outdated
{
/**
* @param ContainerInterface $container
* @param $requestedName
* @param array|null $options
* @return Slugify
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null): Slugify
Comment thread
loco8878 marked this conversation as resolved.
Outdated
{
$config = $container->get('Config');

$slugifyOptions = $config[Module::CONFIG_KEY]['options'] ?? [];
$provider = $config[Module::CONFIG_KEY]['provider'] ?? null;

return new Slugify($slugifyOptions, $provider);
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace Cocur\Slugify\Bridge\ZF2;
namespace Cocur\Slugify\Bridge\Laminas;

use Cocur\Slugify\SlugifyInterface;
use Zend\View\Helper\AbstractHelper;
use Laminas\View\Helper\AbstractHelper;

/**
* Class SlugifyViewHelper
Expand Down Expand Up @@ -34,7 +34,7 @@ public function __construct(SlugifyInterface $slugify)
*
* @return string
*/
public function __invoke(string $string, string $separator = null)
public function __invoke($string, $separator = null)
{
return $this->slugify->slugify($string, $separator);
}
Expand Down
32 changes: 32 additions & 0 deletions src/Bridge/Laminas/SlugifyViewHelperFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Cocur\Slugify\Bridge\Laminas;

use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;

/**
* Class SlugifyViewHelperFactory
* @package cocur/slugify
* @subpackage bridge
* @license http://www.opensource.org/licenses/MIT The MIT License
*/
class SlugifyViewHelperFactory implements FactoryInterface
Comment thread
loco8878 marked this conversation as resolved.
Outdated
{

/**
* @param ContainerInterface $container
* @param $requestedName
* @param array|null $options
* @return SlugifyViewHelper
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null): SlugifyViewHelper
Comment thread
loco8878 marked this conversation as resolved.
Outdated
{
$slugify = $container->get('Cocur\Slugify\Slugify');

return new SlugifyViewHelper($slugify);
}

}
50 changes: 0 additions & 50 deletions src/Bridge/ZF2/Module.php

This file was deleted.

30 changes: 0 additions & 30 deletions src/Bridge/ZF2/SlugifyService.php

This file was deleted.

28 changes: 0 additions & 28 deletions src/Bridge/ZF2/SlugifyViewHelperFactory.php

This file was deleted.

Loading