<?php
class Url
{
    private $url;

    private $rewrite = array();

    public function __construct($url)
    {
        $this->url = $url;
    }

    public function addRewrite($rewrite)
    {
        $this->rewrite[] = $rewrite;
    }

    public function link($route, $args = '', $connection = 'NONSSL', $routeComplete = 'true', $domain = false, $rewrite = true)
    {

        $url = $this->url;

        if ($routeComplete == 'true') {
            $url .= 'index.php?route=' . $route;

            if ($args) {
                $url .= '&' . ltrim($args, '&');
            }

            if ($rewrite) {
                foreach ($this->rewrite as $rewrite) {
                    $url = $rewrite->rewrite($url);
                }
            }
        }

        if ($domain) {
            $url = $this->url . $route;
        }

        return $url;
    }

    public function linkAnchor($route, $args = '', $anchor = '',  $connection = 'NONSSL', $routeComplete = true)
    {

        $url = $this->url;

        if ($routeComplete == 'true') {
            $url .= 'index.php?route=' . $route;

            if ($args) {
                $url .= '&' . ltrim($args, '&');
            }

            if ($anchor) {
                $url .= '#' . $anchor;
            }
        }

        return $url;
    }

    public function linkRewrite($route)
    {

        $url = $this->url;
    }
}
