<commit_before><?php
/**
 * Opine\Separation
 *
 * Copyright (c)2013, 2014 <NAME>, https://github.com/Opine-Org <<EMAIL>>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
namespace Opine;

class Separation {
    private $htmlFile;
    private $html;
    private $config;
    private $configFile;
    private $bindings = [];
    private $bindingsHash = [];
    private $engine;
    private $root;
    private $cache;
    private $dataCache = [];
    private $app = false;
    private $dataAPI = false;
    private $yamlSlow;
    private $route = false;
    private $debug = true;

    public function __construct($root, $engine, $cache, $config, $yamlSlow, $route, $app=false) {
        $this->root = $root;
        $this->engine = $engine;
        $this->cache = $cache;
        $this->yamlSlow = $yamlSlow;
        $this->route = $route;
        $this->app = $app;
        $this->config = $config;
        if (isset($config->db['dataAPI'])) {
            $this->dataAPI = $config->db['dataAPI'];
            if ($this->dataAPI == '%HTTP_HOST%' && isset($_SERVER['HTTP_HOST'])) {
                $this->baseURL = 'http://' . $_SERVER['HTTP_HOST'];
                $this->dataAPI = $this->baseURL;
            }
        }
        $this->route = $route;
    }

    public function showBindings () {
        return print_r($this->bindings, true);
    }

    public function app ($app=false) {
        if ($app !== false) {
            $app = $this->root . '/../' . $app;
        }
        return new Separation($this->root, $this->engine, $this->cache, $this->config, $this->yamlSlow, $this->route, $app);
    }

    public function debug () {
        $this->debug = true;
        return $this;
    }

    public function layout ($path) {
        $this->htmlFile = $this->root . '/layouts/' . $path . '.html';
        if (!file_exists($this->htmlFile)) {
            throw new \Exception('Can not load html file: ' . $this->htmlFile);
        }
        $this->html = file_get_contents($this->htmlFile);
        if ($this->app !== false) {
            if (substr($this->configFile, -4) != '.yml') {
                $this->configFile = $this->app . '.yml';
            }
            if (!file_exists($this->configFile)) {
                throw new \Exception('Can not config file: ' . $this->htmlFile);
            }
            $this->appConfig($this->configFile);
        }<commit_msg>more flexibility with app and layout paths<commit_after><?php
/**
 * Opine\Separation
 *
 * Copyright (c)2013, 2014 <NAME>, https://github.com/Opine-Org <<EMAIL>>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
namespace Opine;

class Separation {
    private $htmlFile;
    private $html;
    private $config;
    private $configFile;
    private $bindings = [];
    private $bindingsHash = [];
    private $engine;
    private $root;
    private $cache;
    private $dataCache = [];
    private $app = false;
    private $dataAPI = false;
    private $yamlSlow;
    private $route = false;
    private $debug = true;

    public function __construct($root, $engine, $cache, $config, $yamlSlow, $route, $app=false) {
        $this->root = $root;
        $this->engine = $engine;
        $this->cache = $cache;
        $this->yamlSlow = $yamlSlow;
        $this->route = $route;
        $this->app = $app;
        $this->config = $config;
        if (isset($config->db['dataAPI'])) {
            $this->dataAPI = $config->db['dataAPI'];
            if ($this->dataAPI == '%HTTP_HOST%' && isset($_SERVER['HTTP_HOST'])) {
                $this->baseURL = 'http://' . $_SERVER['HTTP_HOST'];
                $this->dataAPI = $this->baseURL;
            }
        }
        $this->route = $route;
    }

    public function showBindings () {
        return print_r($this->bindings, true);
    }

    public function app ($app=false) {
        if ($app !== false) {
            if (substr_count($app, '/') > 0) {
                if (substr($app, 0, 1) == '/') {
                    $app = $app;
                } else {
                    $app = $this->root . '/../' . $app;
                }
            } else {
                $app = $this->root . '/../' . $app;
            }
        }
        return new Separation($this->root, $this->engine, $this->cache, $this->config, $this->yamlSlow, $this->route, $app);
    }

    public function debug () {
        $this->debug = true;
        return $this;
    }

    public function layout ($path) {
        if (substr_count($path, '/') > 0) {
            if (substr($path, 0, 1) == '/') {
                $this->htmlFile = $path;    
            } else {
                $this->htmlFile = $this->root . '/../' . $path;
            }
        } else {
            $this->htmlFile = $this->root . '/layouts/' . $path . '.html';
        }
        if (!file_exists($this->htmlFile)) {
            throw new \Exception('Can not load html file: ' . $this->htmlFile);
        }
        $this->html = file_get_contents($this->htmlFile);
        if ($this->app !== false) {
            if (substr($this->app, -4) != '.yml') {
                $this->app .= '.yml';
            }
            if (!file_exists($this->app)) {
                throw new \Exception('Can not open config file: ' . $this->app);
            }
            $this->appConfig($this->app);
        }
{'fraction_non_alphanumeric': 0.13974690434072662, 'fraction_numerical': 0.003265750442237039, 'mean_word_length': 2.262316910785619, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 90, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, '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': '1025011', 'n_tokens_mistral': 2131, 'n_tokens_neox': 2035, 'n_words': 672}