-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added first version of Laminas integration #261
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace Cocur\Slugify\Bridge\Laminas; | ||
|
||
use Cocur\Slugify\Slugify; | ||
use Laminas\ModuleManager\Feature\ServiceProviderInterface; | ||
use Laminas\ModuleManager\Feature\ViewHelperProviderInterface; | ||
use Zend\ServiceManager\Config; | ||
|
||
/** | ||
* Class Module | ||
* @package cocur/slugify | ||
* @subpackage bridge | ||
* @license http://www.opensource.org/licenses/MIT The MIT License | ||
*/ | ||
class Module implements ServiceProviderInterface, ViewHelperProviderInterface | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you want to make an update of the ZF / Laminas bridge then the support should also be extended for Mezzio (formerly Expressive). Examples can be found in laminas-db: As you can see, the module class consumes the configuration from config-provider class. |
||
{ | ||
const CONFIG_KEY = 'cocur_slugify'; | ||
|
||
/** | ||
* Expected to return \Laminas\ServiceManager\Config object or array to | ||
* seed such an object. | ||
* | ||
* @return array<string,array<string,string>> | ||
*/ | ||
public function getServiceConfig() | ||
{ | ||
return [ | ||
'factories' => [ | ||
Slugify::class => SlugifyService::class, | ||
], | ||
'aliases' => [ | ||
'slugify' => Slugify::class, | ||
] | ||
]; | ||
} | ||
|
||
/** | ||
* Expected to return \Laminas\ServiceManager\Config object or array to | ||
* seed such an object. | ||
* | ||
* @return array<string,array<string,string>>|Config | ||
*/ | ||
public function getViewHelperConfig() | ||
{ | ||
return [ | ||
'aliases' => [ | ||
'slugify' => SlugifyViewHelper::class | ||
], | ||
'factories' => [ | ||
SlugifyViewHelper::class => SlugifyViewHelperFactory::class | ||
] | ||
]; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest a filter here instead of a service because this package provides a conversion / transformation of (string) data. |
||
{ | ||
|
||
/** | ||
* | ||
* @param ContainerInterface $container | ||
* @param string $requestedName | ||
* @param array $options | ||
* @return object | ||
*/ | ||
public function __invoke(ContainerInterface $container, $requestedName, array $options = null): Slugify { | ||
$config = $container->get('Config'); | ||
|
||
$slugifyOptions = isset($config[Module::CONFIG_KEY]['options']) ? $config[Module::CONFIG_KEY]['options'] : []; | ||
$provider = isset($config[Module::CONFIG_KEY]['provider']) ? $config[Module::CONFIG_KEY]['provider'] : null; | ||
|
||
return new Slugify($slugifyOptions, $provider); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Cocur\Slugify\Bridge\Laminas; | ||
|
||
use Cocur\Slugify\SlugifyInterface; | ||
use Laminas\View\Helper\AbstractHelper; | ||
|
||
/** | ||
* Class SlugifyViewHelper | ||
* @package cocur/slugify | ||
* @subpackage bridge | ||
* @license http://www.opensource.org/licenses/MIT The MIT License | ||
*/ | ||
class SlugifyViewHelper extends AbstractHelper | ||
{ | ||
/** | ||
* @var SlugifyInterface | ||
*/ | ||
protected $slugify; | ||
|
||
/** | ||
* @param SlugifyInterface $slugify | ||
* | ||
* @codeCoverageIgnore | ||
*/ | ||
public function __construct(SlugifyInterface $slugify) | ||
{ | ||
$this->slugify = $slugify; | ||
} | ||
|
||
/** | ||
* @param string $string | ||
* @param string|null $separator | ||
* | ||
* @return string | ||
*/ | ||
public function __invoke($string, $separator = null) | ||
{ | ||
return $this->slugify->slugify($string, $separator); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?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 | ||
{ | ||
|
||
/** | ||
* | ||
* @param ContainerInterface $container | ||
* @param string $requestedName | ||
* @param array $options | ||
* @return SlugifyViewHelper | ||
*/ | ||
public function __invoke(ContainerInterface $container, $requestedName, array $options = null): SlugifyViewHelper | ||
{ | ||
$slugify = $container->get('Cocur\Slugify\Slugify'); | ||
return new SlugifyViewHelper($slugify); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
easily...