Redaxscript\Template\Helper::getCanonical PHP Метод

getCanonical() публичный статический Метод

get the canonical
С версии: 3.0.0
public static getCanonical ( ) : string
Результат string
    public static function getCanonical()
    {
        $firstTable = Registry::get('firstTable');
        $secondTable = Registry::get('secondTable');
        $lastTable = Registry::get('lastTable');
        $firstParameter = Registry::get('firstParameter');
        $secondParameter = Registry::get('secondParameter');
        $categoryParameter = $secondTable === 'categories' ? $secondParameter : $firstParameter;
        $fullRoute = Registry::get('fullRoute');
        /* find route */
        if ($firstTable === 'categories' && $lastTable === 'articles') {
            $categoryId = Db::forTablePrefix($firstTable)->where('alias', $categoryParameter)->findOne()->id;
            $articlesTotal = Db::forTablePrefix('articles')->where('category', $categoryId)->count();
            if ($articlesTotal === 1) {
                $route = $firstParameter;
                if ($secondTable === 'categories') {
                    $route .= '/' . $secondParameter;
                }
            }
        }
        /* handle route  */
        if ($route) {
            return Registry::get('parameterRoute') . $route;
        }
        return $fullRoute;
    }

Usage Example

Пример #1
0
 /**
  * testGetCanonical
  *
  * @since 3.0.0
  *
  * @param array $registryArray
  * @param string $expect
  *
  * @dataProvider providerGetCanonical
  */
 public function testCanonical($registryArray = [], $expect = null)
 {
     /* setup */
     $this->_registry->init($registryArray);
     /* actual */
     $actual = Template\Helper::getCanonical();
     /* compare */
     $this->assertEquals($expect, $actual);
 }