-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
138 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Cocur\Slugify\Bridge\Latte; | ||
|
||
use Cocur\Slugify\SlugifyInterface; | ||
|
||
/** | ||
* SlugifyHelper | ||
* | ||
* @package cocur/slugify | ||
* @subpackage bridge | ||
* @author Lukáš Unger <[email protected]> | ||
* @license http://www.opensource.org/licenses/MIT The MIT License | ||
*/ | ||
class SlugifyHelper | ||
{ | ||
|
||
/** @var SlugifyInterface */ | ||
private $slugify; | ||
|
||
public function __construct(SlugifyInterface $slugify) | ||
{ | ||
$this->slugify = $slugify; | ||
} | ||
|
||
/** | ||
* @param string | ||
* @param string | ||
* @return string | ||
*/ | ||
public function slugify($string, $separator = '-') | ||
{ | ||
return $this->slugify->slugify($string, $separator); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace Cocur\Slugify\Bridge\Nette; | ||
|
||
use Nette\DI\CompilerExtension; | ||
use Nette\DI\ServiceDefinition; | ||
|
||
/** | ||
* SlugifyExtension | ||
* | ||
* @package cocur/slugify | ||
* @subpackage bridge | ||
* @author Lukáš Unger <[email protected]> | ||
* @license http://www.opensource.org/licenses/MIT The MIT License | ||
*/ | ||
class SlugifyExtension extends CompilerExtension | ||
{ | ||
|
||
public function loadConfiguration() | ||
{ | ||
$builder = $this->getContainerBuilder(); | ||
|
||
$builder->addDefinition($this->prefix('slugify')) | ||
->setClass('Cocur\Slugify\SlugifyInterface') | ||
->setFactory('Cocur\Slugify\Slugify'); | ||
|
||
$builder->addDefinition($this->prefix('helpers')) | ||
->setClass('Cocur\Slugify\Bridge\Latte\SlugifyHelper') | ||
->setInject(false); | ||
} | ||
|
||
public function beforeCompile() | ||
{ | ||
$builder = $this->getContainerBuilder(); | ||
|
||
$self = $this; | ||
$registerToLatte = function(ServiceDefinition $def) use ($self) { | ||
$def->addSetup('addFilter', array('slugify', array($self->prefix('@helpers'), 'slugify'))); | ||
}; | ||
|
||
$latteFactory = $builder->getByType('Nette\Bridges\ApplicationLatte\ILatteFactory') ?: 'nette.latteFactory'; | ||
if ($builder->hasDefinition($latteFactory)) { | ||
$registerToLatte($builder->getDefinition($latteFactory)); | ||
} | ||
|
||
if ($builder->hasDefinition('nette.latte')) { | ||
$registerToLatte($builder->getDefinition('nette.latte')); | ||
} | ||
} | ||
|
||
} |