<commit_before><?php
/**
 * @package     Nooku_Server
 * @subpackage  Application
 * @copyright   Copyright (C) 2007 - 2012 <NAME>. All rights reserved.
 * @license     GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link        http://www.nooku.org
 */

use Nooku\Framework;

/**
 * Application Router Class
.*
 * @author      <NAME> <http://nooku.assembla.com/profile/johanjanssens>
 * @package     Nooku_Server
 * @subpackage  Application
 */
class ApplicationRouter extends Framework\DispatcherRouter
{
    public function parse(Framework\HttpUrl $url)
	{
        $vars = array();
        $path = trim($url->getPath(), '/');

        //Remove base path
        $path = substr_replace($path, '', 0, strlen($this->getService('request')->getBaseUrl()->getPath()));

        // Set the format
        if(!empty($url->format)) {
            $url->query['format'] = $url->format;
        }

        //Parse site route
        $url->query['site'] = $this->getService('application')->getSite();

        $path = str_replace($url->query['site'], '', $path);
        $path = ltrim($path, '/');

        //Parse component route
        if(!empty($path))
        {
            $segments = explode('/', $path);

            if(isset($segments[0]))
            {
                $vars['option'] = 'com_'.$segments[0];

                if(isset($segments[1])) {
                    $vars['view']   = $segments[1];
                } else {
                    $vars['view']   = $segments[0];
                }
            }
        }

        $url->query = array_merge($url->query, $vars);
        $url->path  = '';

        return true;
	}

	public function build(Framework\HttpUrl $url)
	{
        $query    = $url->query;
        $segments = array();

        //Build site route
        $site = $this->getService('application')->getSite();
        if($site != 'default' && $site != $this->getService('application')->getRequest()->getUrl()->toString(HttpUrl::HOST)) {
            $segments[] = $site;
        }

	    //Build commponent route
        if(isset($query['option']))
        {
            $segments[] = substr($query['option'], 4);
            unset($query['option']);

            if(isset($query['view']))
            {
                if($query['view'] != $segments[0]) {
                    $segments[] = $query['view'];
                }

                unset($query['view']);
            }
        }

        $url->query  = $query;

        //Build the route
        $route  = implode('/', $segments);

        //Add the format to the uri
        $format = isset($url->query['format']) ? $url->query['format'] : 'html';

        if($this->getService('application')->getCfg('sef_suffix'))
        {
            $url->format = $format;
            unset($url->query['format']);
        }
        else<commit_msg>Docblocks<commit_after><?php
/**
 * @package     Nooku_Server
 * @subpackage  Application
 * @copyright   Copyright (C) 2007 - 2012 <NAME>. All rights reserved.
 * @license     GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
 * @link        http://www.nooku.org
 */

use Nooku\Framework;

/**
 * Application Router Class
.*
 * @author      <NAME> <http://nooku.assembla.com/profile/johanjanssens>
 * @package     Nooku_Server
 * @subpackage  Application
 */
class ApplicationRouter extends Framework\DispatcherRouter
{
    public function parse(Framework\HttpUrl $url)
	{
        $vars = array();
        $path = trim($url->getPath(), '/');

        //Remove base path
        $path = substr_replace($path, '', 0, strlen($this->getService('request')->getBaseUrl()->getPath()));

        // Set the format
        if(!empty($url->format)) {
            $url->query['format'] = $url->format;
        }

        //Parse site route
        $url->query['site'] = $this->getService('application')->getSite();

        $path = str_replace($url->query['site'], '', $path);
        $path = ltrim($path, '/');

        //Parse component route
        if(!empty($path))
        {
            $segments = explode('/', $path);

            if(isset($segments[0]))
            {
                $vars['option'] = 'com_'.$segments[0];

                if(isset($segments[1])) {
                    $vars['view']   = $segments[1];
                } else {
                    $vars['view']   = $segments[0];
                }
            }
        }

        $url->query = array_merge($url->query, $vars);
        $url->path  = '';

        return true;
	}

	public function build(Framework\HttpUrl $url)
	{
        $query    = $url->query;
        $segments = array();

        //Build site route
        $site = $this->getService('application')->getSite();
        if($site != 'default' && $site != $this->getService('application')->getRequest()->getUrl()->toString(HttpUrl::HOST)) {
            $segments[] = $site;
        }

	    //Build component route
        if(isset($query['option']))
        {
            $segments[] = substr($query['option'], 4);
            unset($query['option']);

            if(isset($query['view']))
            {
                if($query['view'] != $segments[0]) {
                    $segments[] = $query['view'];
                }

                unset($query['view']);
            }
        }

        $url->query  = $query;

        //Build the route
        $route  = implode('/', $segments);

        //Add the format to the uri
        $format = isset($url->query['format']) ? $url->query['format'] : 'html';

        if($this->getService('application')->getCfg('sef_suffix'))
        {
            $url->format = $format;
            unset($url->query['format']);
        }
        else
{'fraction_non_alphanumeric': 0.18365538025172842, 'fraction_numerical': 0.006027300124091473, 'mean_word_length': 1.8366013071895424, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '409105', 'n_tokens_mistral': 1695, 'n_tokens_neox': 1619, 'n_words': 289}