<commit_before><?php

namespace luya\components;

use Yii;
use luya\helpers\Url;

/**
 * @todo see http://www.yiiframework.com/doc-2.0/guide-runtime-routing.html#adding-rules-dynamically
 * @todo change to public $ruleConfig = ['class' => 'yii\web\UrlRule'];
 *
 * @author nadar
 */
class UrlManager extends \yii\web\UrlManager
{
    public $enablePrettyUrl = true;

    public $showScriptName = false;

    public $ruleConfig = ['class' => '\luya\base\UrlRule'];

    private $_contextNavItemId = false;

    public function parseRequest($request)
    {
        $route = parent::parseRequest($request);

        /**
         * @todo previous `!is_object(\yii::$app->composition)`can remove?`how to handle?
         */
        if (!(Yii::$app->has('composition'))) {
            return $route;
        }

        $composition = \yii::$app->composition->getFull();

        $length = strlen($composition);
        if (substr($route[0], 0, $length) == $composition) {
            $route[0] = substr($route[0], $length);
        }

        return $route;
    }

    public function addRules($rules, $append = true)
    {
        foreach ($rules as $key => $rule) {
            if (isset($rule['composition'])) {
                foreach ($rule['composition'] as $comp => $pattern) {
                    $rules[] = [
                        'pattern' => $pattern,
                        'route' => $comp.'/'.$rule['route'],
                    ];
                }
            }
        }<commit_msg>use Yii in urlManager<commit_after><?php

namespace luya\components;

use Yii;
use luya\helpers\Url;

/**
 * @todo see http://www.yiiframework.com/doc-2.0/guide-runtime-routing.html#adding-rules-dynamically
 * @todo change to public $ruleConfig = ['class' => 'yii\web\UrlRule'];
 *
 * @author nadar
 */
class UrlManager extends \yii\web\UrlManager
{
    public $enablePrettyUrl = true;

    public $showScriptName = false;

    public $ruleConfig = ['class' => '\luya\base\UrlRule'];

    private $_contextNavItemId = false;

    public function parseRequest($request)
    {
        $route = parent::parseRequest($request);

        /**
         * @todo previous `!is_object(\yii::$app->composition)`can remove?`how to handle?
         */
        if (!(Yii::$app->has('composition'))) {
            return $route;
        }
        
        $composition = Yii::$app->composition->getFull();

        $length = strlen($composition);
        if (substr($route[0], 0, $length) == $composition) {
            $route[0] = substr($route[0], $length);
        }
        
        return $route;
    }

    public function addRules($rules, $append = true)
    {
        foreach ($rules as $key => $rule) {
            if (isset($rule['composition'])) {
                foreach ($rule['composition'] as $comp => $pattern) {
                    $rules[] = [
                        'pattern' => $pattern,
                        'route' => $comp.'/'.$rule['route'],
                    ];
                }
            }
        }
{'fraction_non_alphanumeric': 0.1635157545605307, 'fraction_numerical': 0.003980099502487562, 'mean_word_length': 2.000995024875622, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6934058', 'n_tokens_mistral': 931, 'n_tokens_neox': 883, 'n_words': 177}