<commit_before><?php
namespace Bolt\Configuration;

/**
 * Inherits from default and adds some specific checks for composer installs.
 *
 * @author <NAME> <<EMAIL>> 
 **/

class ComposerChecks extends LowlevelChecks
{
    
    public $composerSuffix = <<< EOM
    </strong></p><p>When using Bolt as a Composer package it will need to have access to the following folders:</p>
    <ol>
        <li class="status-%s">A writable config directory at: <code>%s</code></li>
        <li class="status-%s">For a default SQLite install, a writable directory at: <code>%s</code></li>
        <li class="status-%s">A writable cache directory at: <code>%s</code></li>
        <li class="status-%s">A writable extensions directory at: <code>%s</code></li>
        <li class="status-%s">A writable extensions assets directory at: <code>%s</code></li>
    </ol>
    <p>If any of the above are failing, create the folder and make it writable to the web server.</p>
    <strong>
EOM;


    /**
     * The constructor requires a resource manager object to perform checks against.
     * This should ideally be typehinted to Bolt\Configuration\ResourceManager
     *
     * @return void
     **/
    public function __construct($config = null)
    {
        parent::__construct($config);
        $this->addCheck('extensions', true);
        $this->addCheck('publicAssets', true);
        $this->addCheck('database', true);
        $this->addCheck('config', true);
    }
    
    
    
    public function checkConfig()
    {                    
        $this->checkDir($this->config->getPath('config'));
    }
    
    public function checkCache()
    {                    
        $this->checkDir($this->config->getPath('cache'));
    }
    
    public function checkDatabase()
    {                    
        $this->checkDir($this->config->getPath('database'));
    }
    
    public function checkExtensions()
    {                    
        $this->checkDir($this->config->getPath('extensions'));
    }
    
    public function checkPublicAssets()
    {                    
        $this->checkDir($this->config->getPath('web')."/extensions");
    }
    
    protected function checkSummary()
    {
        $status = array();
        $status[] = $this->composerSuffix;
        $checks = array(
            $this->config->getPath('config'),
            $this->config->getPath('database'),
            $this->config->getPath('cache'),
            $this->config->getPath('extensions'),
            $this->config->getPath('web')."/extensions"
        );
        foreach($checks as $check) {
            if(is_readable($check) && is_writable($check)) {
                $status[] = 'ok';
                $status[] = $check;
            } else {
                $status[] = 'error';
                $status[] = $check;
            }
        }
        return call_user_func_array('sprintf', $status);
    }
    
    
    protected function checkDir($location)
    {
        // As a last resort we can try to create the directory here:
        if(!is_dir($location)) {
            @mkdir($location, 0777, true);
        }
        
        if (!is_dir($location)) {
            throw new LowlevelException(
                "The default folder <code>" . $location . 
                "</code> doesn't exist. Make sure it's " .
                "present and writable to the user that the webserver is using.". $this->checkSummary());
        } elseif (!is_writable($location)) {
            throw new LowlevelException(
                "The default folder <code>" . $location . 
                "</code> isn't writable. Make sure it's writable to the user that the webserver is using.".$this->checkSummary()
            );
        }
    }


}
<commit_msg>no need for these to be on the top of the stack<commit_after><?php
namespace Bolt\Configuration;

/**
 * Inherits from default and adds some specific checks for composer installs.
 *
 * @author <NAME> <<EMAIL>> 
 **/

class ComposerChecks extends LowlevelChecks
{
    
    public $composerSuffix = <<< EOM
    </strong></p><p>When using Bolt as a Composer package it will need to have access to the following folders:</p>
    <ol>
        <li class="status-%s">A writable config directory at: <code>%s</code></li>
        <li class="status-%s">For a default SQLite install, a writable directory at: <code>%s</code></li>
        <li class="status-%s">A writable cache directory at: <code>%s</code></li>
        <li class="status-%s">A writable extensions directory at: <code>%s</code></li>
        <li class="status-%s">A writable extensions assets directory at: <code>%s</code></li>
    </ol>
    <p>If any of the above are failing, create the folder and make it writable to the web server.</p>
    <strong>
EOM;


    /**
     * The constructor requires a resource manager object to perform checks against.
     * This should ideally be typehinted to Bolt\Configuration\ResourceManager
     *
     * @return void
     **/
    public function __construct($config = null)
    {
        parent::__construct($config);
        $this->addCheck('extensions');
        $this->addCheck('publicAssets');
        $this->addCheck('database', true);
        $this->addCheck('config', true);
    }
    
    
    
    public function checkConfig()
    {                    
        $this->checkDir($this->config->getPath('config'));
    }
    
    public function checkCache()
    {                    
        $this->checkDir($this->config->getPath('cache'));
    }
    
    public function checkDatabase()
    {                    
        $this->checkDir($this->config->getPath('database'));
    }
    
    public function checkExtensions()
    {                    
        $this->checkDir($this->config->getPath('extensions'));
    }
    
    public function checkPublicAssets()
    {                    
        $this->checkDir($this->config->getPath('web')."/extensions");
    }
    
    protected function checkSummary()
    {
        $status = array();
        $status[] = $this->composerSuffix;
        $checks = array(
            $this->config->getPath('config'),
            $this->config->getPath('database'),
            $this->config->getPath('cache'),
            $this->config->getPath('extensions'),
            $this->config->getPath('web')."/extensions"
        );
        foreach($checks as $check) {
            if(is_readable($check) && is_writable($check)) {
                $status[] = 'ok';
                $status[] = $check;
            } else {
                $status[] = 'error';
                $status[] = $check;
            }
        }
        return call_user_func_array('sprintf', $status);
    }
    
    
    protected function checkDir($location)
    {
        // As a last resort we can try to create the directory here:
        if(!is_dir($location)) {
            @mkdir($location, 0777, true);
        }
        
        if (!is_dir($location)) {
            throw new LowlevelException(
                "The default folder <code>" . $location . 
                "</code> doesn't exist. Make sure it's " .
                "present and writable to the user that the webserver is using.". $this->checkSummary());
        } elseif (!is_writable($location)) {
            throw new LowlevelException(
                "The default folder <code>" . $location . 
                "</code> isn't writable. Make sure it's writable to the user that the webserver is using.".$this->checkSummary()
            );
        }
    }


}

{'fraction_non_alphanumeric': 0.14010695187165775, 'fraction_numerical': 0.0010695187165775401, 'mean_word_length': 2.0068327974276525, 'pattern_counts': {'":': 0, '<': 83, '<?xml version=': 0, '>': 139, 'https://': 0, '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': '3304304', 'n_tokens_mistral': 2090, 'n_tokens_neox': 2039, 'n_words': 527}