<?php


namespace AutoAdmin\Bundle\Seo\Repository;

use AutoAdmin\Bundle\Content\Repository\AbstractContentRepository;


class RedirectRepository extends AbstractContentRepository
{
    public function contentFindOneByOriginLike(string $url)
    {
        $qb = $this->createContentQueryBuilder();

        $qb->andWhere(':url LIKE REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(_.origin, \'**\', \'%\'), \'*1*\', \'%\'), \'*2*\', \'%\'), \'*3*\', \'%\'), \'*4*\', \'%\')');
        $qb->setParameter('url', str_replace('%', '\%', $url));

        return (($res = $qb->getQuery()->execute()) && !empty($res[0])) ? $res[0] : null;
    }
}
