68publishers / doctrine-sluggable
Doctrine Sluggable extension
Installs: 3 449
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 4
Forks: 0
Open Issues: 1
Requires
- php: ^7.1 || ^8.1
- behat/transliterator: ^1.2
- doctrine/orm: ^2.11
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.19
- mockery/mockery: ^1.2
- nette/di: ^2.4
- nette/tester: ^1.7
- roave/security-advisories: dev-latest
Suggests
- nette/di: For integration into Nette Framework
This package is auto-updated.
Last update: 2024-12-06 04:32:56 UTC
README
⚠️ Warning! This package does not have active support, it exists only for the historical needs of the author.
Doctrine Sluggable
🔤 Doctrine Sluggable extension!
Simple usage and integration into Nette Framework.
Installation
The best way to install 68publishers/doctrine-sluggable
is using Composer:
$ composer require 68publishers/doctrine-sluggable
then register SluggableEventSubscriber
into EventManager
like this:
<?php /** @var Doctrine\ORM\EntityManager $em */ /** @var Doctrine\Common\Annotations\Reader $reader */ $subscriber = new SixtyEightPublishers\DoctrineSluggable\SluggableEventSubscriber( new SixtyEightPublishers\DoctrineSluggable\DefinitionStorage\AnnotationSluggableDefinitionStorage($reader) ); $em->getEventManager()->addEventSubscriber($subscriber);
but you'd better use compiler extension if you are using Nette
Framework:
extensions: sluggable: SixtyEightPublishers\DoctrineSluggable\Bridge\Nette\SluggableExtension
Usage
Example entity:
<?php use Doctrine\ORM\Mapping as ORM; use SixtyEightPublishers\DoctrineSluggable\Annotation as Sluggable; /** * @ORM\Entity */ class Product { /** * @ORM\Column(type="string", length=255) * * @var string */ private $name; /** * @ORM\ManyToOne(targetEntity="Category") * * @var Category */ private $category; /** * @Sluggable\Slug( * strategy="SixtyEightPublishers\DoctrineSluggable\Strategy\GenerateOnInsertStrategy", * strategyOptions={ * "fields": {"name"}, * "checkOnUpdate": true * }, * finder="SixtyEightPublishers\DoctrineSluggable\Finder\FieldBasedSimilarSlugFinder", * finderOptions={ * "field": "category", * "type": "outer" * }, * transliterator="SixtyEightPublishers\DoctrineSluggable\Transliterator\CamelCaseTransliterator" * ) * @ORM\Column(type="string", length=255) * * @var string */ private $slug; /** * @return string */ public function getSlug() : string { # slug is generated on EntityManager's onFlush event if (NULL === $this->slug) { throw new RuntimeException('Slug is not set.'); } return $this->slug; } }
Options
@todo
Contributing
Before committing any changes, don't forget to run
$ vendor/bin/php-cs-fixer fix --config=.php_cs.dist -v --dry-run
and
$ vendor/bin/tester ./tests