Esempio n. 1
0
 /**
  * testUrlUtiliry
  */
 public function testUrlUtiliry()
 {
     $url = 'текст урл на русском с пробелами';
     $utility = new UrlUtility();
     $validUrl = $utility->process($url);
     $this->assertEquals('tekst-url-na-russkom-s-probelami', $validUrl);
 }
Esempio n. 2
0
 /**
  * @param LifecycleEventArgs $args
  */
 public function prePersist(LifeCycleEventArgs $args)
 {
     /** @var UrlInterface $object */
     $object = $args->getEntity();
     if ($object instanceof UrlInterface) {
         $urlUtility = new UrlUtility();
         $processedUrl = $urlUtility->process($object->getMetaUrl());
         $found = $args->getEntityManager()->getRepository(get_class($object))->findOneBy(['metaUrl' => $processedUrl]);
         if ($found) {
             throw new \LogicException('Given URL already exists');
         }
         $object->setMetaUrl($processedUrl);
     }
 }