<commit_before><?php

namespace Anax\Url;

/**
 * A helper to create urls.
 *
 */
class CUrl
{
    use \Anax\TConfigure;



    /**
     * Properties
     *
     */
    const URL_CLEAN  = 'clean';  // controller/action/param1/param2
    const URL_APPEND = 'append'; // index.php/controller/action/param1/param2

    private $urlType = self::URL_APPEND; // What type of urls to generate

    private $siteUrl = null; // Siteurl to prepend to all absolute urls created
    private $baseUrl = null; // Baseurl to prepend to all relative urls created
    private $scriptName = null; // Name of the frontcontroller script


    private $staticSiteUrl = null; // Siteurl to prepend to all absolute urls for assets
    private $staticBaseUrl = null; // Baseurl to prepend to all relative urls for assets



    /**
     * Set default values from configuration.
     *
     * @return this.
     */
    public function setDefaultsFromConfiguration()
    {
        $set = [
            "urlType",
            "siteUrl",
            "baseUrl",
            "staticSiteUrl",
            "staticBaseUrl",
            "scriptName",
        ];
        
        foreach ($set as $item) {
            if (!isset($this->config[$item])) {
                continue;
            }
            
            $this->$item = $this->config[$item];
        }

        return $this;
    }



    /**
     * Create an url and prepending the baseUrl.
     *
     * @param string $uri     part of uri to use when creating an url.
     *                        "" or null means baseurl to current
     *                        frontcontroller.
     * @param string $baseuri optional base to prepend uri.
     *
     * @return string as resulting url.
     */
    public function create($uri = null, $baseuri = null)
    {
        if (empty($uri) && empty($baseuri)) {
            // Empty uri means baseurl
            return $this->baseUrl
                . (($this->urlType == self::URL_APPEND)
                    ? "/$this->scriptName"
                    : null);
        } elseif (empty($uri)) {
            // Empty uri means baseurl with appended $baseuri
            ;
        } elseif (substr($uri, 0, 7) == "http://"
            || substr($uri, 0, 8) == "https://"
            || substr($uri, 0, 2) == "//"
        ) {
            // Fully qualified, just leave as is.
            return $uri;
        } elseif ($uri[0] == "/") {
            // Absolute url, prepend with siteUrl
            //return rtrim($this->siteUrl . rtrim($uri, '/'), '/');
            return $this->siteUrl . $uri;
        } elseif ($uri[0] == "#"
            || $uri[0] == "?"
            || $uri[0] == "!"
        ) {
            // Hashtag url to local page, or query part, or ! special
            // leave as is.
            return $uri;
        } elseif (substr($uri, 0, 7) == "mailto:"
            || substr(html_entity_decode($uri), 0, 7) == "mailto:") {
            // Leave mailto links as is
            // The odd fix is for markdown converting mailto: to UTF-8
            // Might be a better way to solve this...
            return $uri;
        }

        // Prepend uri with baseuri
        $uri = rtrim($uri, "/");
        if (!empty($baseuri)) {
            $uri = rtrim($baseuri, "/") . "/$uri";
        }

        // Remove the trailing index part of the url
        if (basename($uri) == "index") {<commit_msg>Fix: CUrl not to remove ending slash.<commit_after><?php

namespace Anax\Url;

/**
 * A helper to create urls.
 *
 */
class CUrl
{
    use \Anax\TConfigure;



    /**
     * Properties
     *
     */
    const URL_CLEAN  = 'clean';  // controller/action/param1/param2
    const URL_APPEND = 'append'; // index.php/controller/action/param1/param2

    private $urlType = self::URL_APPEND; // What type of urls to generate

    private $siteUrl = null; // Siteurl to prepend to all absolute urls created
    private $baseUrl = null; // Baseurl to prepend to all relative urls created
    private $scriptName = null; // Name of the frontcontroller script


    private $staticSiteUrl = null; // Siteurl to prepend to all absolute urls for assets
    private $staticBaseUrl = null; // Baseurl to prepend to all relative urls for assets



    /**
     * Set default values from configuration.
     *
     * @return this.
     */
    public function setDefaultsFromConfiguration()
    {
        $set = [
            "urlType",
            "siteUrl",
            "baseUrl",
            "staticSiteUrl",
            "staticBaseUrl",
            "scriptName",
        ];
        
        foreach ($set as $item) {
            if (!isset($this->config[$item])) {
                continue;
            }
            
            $this->$item = $this->config[$item];
        }

        return $this;
    }



    /**
     * Create an url and prepending the baseUrl.
     *
     * @param string $uri     part of uri to use when creating an url.
     *                        "" or null means baseurl to current
     *                        frontcontroller.
     * @param string $baseuri optional base to prepend uri.
     *
     * @return string as resulting url.
     */
    public function create($uri = null, $baseuri = null)
    {
        if (empty($uri) && empty($baseuri)) {
            // Empty uri means baseurl
            return $this->baseUrl
                . (($this->urlType == self::URL_APPEND)
                    ? "/$this->scriptName"
                    : null);
        } elseif (empty($uri)) {
            // Empty uri means baseurl with appended $baseuri
            ;
        } elseif (substr($uri, 0, 7) == "http://"
            || substr($uri, 0, 8) == "https://"
            || substr($uri, 0, 2) == "//"
        ) {
            // Fully qualified, just leave as is.
            return $uri;
        } elseif ($uri[0] == "/") {
            // Absolute url, prepend with siteUrl
            //return rtrim($this->siteUrl . rtrim($uri, '/'), '/');
            return $this->siteUrl . $uri;
        } elseif ($uri[0] == "#"
            || $uri[0] == "?"
        ) {
            // Hashtag url to local page, or query part leave as is.
            return $uri;
        } elseif (substr($uri, 0, 7) == "mailto:"
            || substr(html_entity_decode($uri), 0, 7) == "mailto:") {
            // Leave mailto links as is
            // The odd fix is for markdown converting mailto: to UTF-8
            // Might be a better way to solve this...
            return $uri;
        }

        // Prepend uri with baseuri
        $uri = rtrim($uri, "/");
        if (!empty($baseuri)) {
            $uri = rtrim($baseuri, "/") . "/$uri";
        }

        // Remove the trailing index part of the url
        if (basename($uri) == "index") {
{'fraction_non_alphanumeric': 0.13244246473645138, 'fraction_numerical': 0.005493689680772086, 'mean_word_length': 1.5209580838323353, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '301109', 'n_tokens_mistral': 1956, 'n_tokens_neox': 1885, 'n_words': 577}