Classes

File mvc/dispatcher/DispatcherUrlMapping.class.php

File mvc/dispatcher/DispatcherUrlMapping.class.php

 1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 
<?php
/**
 * @package     MVC
 * @subpackage  Dispatcher
 * @copyright   &copy; 2005-2019 PHPBoost
 * @license     https://www.gnu.org/licenses/gpl-3.0.html GNU/GPL-3.0
 * @author      Loic ROUCHON <horn@phpboost.com>
 * @version     PHPBoost 5.2 - last update: 2018 10 30
 * @since       PHPBoost 3.0 - 2010 10 06
 * @contributor Julien BRISWALTER <j1.seth@phpboost.com>
 * @contributor Arnaud GENET <elenwii@phpboost.com>
*/

class DispatcherUrlMapping extends UrlMapping
{
    private $high_priority = false;
    private $low_priority = false;

    /**
     * @param UrlMapping[] $mappings
     */
    public function __construct($dispatcher_name, $match = '([\w/_-]*)$', $from_path = '', $redirect_path = '')
    {
        if (!empty($from_path))
        {
            if ($from_path == 'root')
            {
                $from = '^' . $match;
                $to = $dispatcher_name . '?url=/' . ($redirect_path ? $redirect_path : '$1');
                $this->low_priority = true;
            }
            else
            {
                $dispatcher_path = ltrim(TextHelper::substr($from_path, 0, TextHelper::strrpos($from_path, '/') + 1), '/');
                $from = '^' . $dispatcher_path . $match;
                $to = $dispatcher_name . '?url=/' . $dispatcher_path . '$1';
                $this->high_priority = true;
            }
        }
        else
        {
            $dispatcher_path = ltrim(TextHelper::substr($dispatcher_name, 0, TextHelper::strrpos($dispatcher_name, '/') + 1), '/');
            $from = '^' . $dispatcher_path . $match;
            $to = $dispatcher_name . '?url=/$1';
        }
        parent::__construct($from, $to);
    }

    /**
     * Check if the Url must be placed in high priority in the .htaccess file
     */
    public function is_high_priority()
    {
        return $this->high_priority;
    }

    /**
     * Check if the Url must be placed in low priority in the .htaccess file
     */
    public function is_low_priority()
    {
        return $this->low_priority;
    }
}
?>