<commit_before><?php

namespace Bloge\Renderers;

use Bloge\NotFoundException;

/**
 * Basic renderer
 * 
 * This renderer renders raw PHP templates
 * 
 * @package bloge
 */
class PHP implements IRenderer
{
    /**
     * @var string $path
     */
    protected $path;
    
    /**
     * @var array $data
     */
    protected $data = [];
    
    /**
     * @param string $path
     */
    public function __construct($path)
    {
        $this->path = chop($path, '/');
    }
    
    /**
     * @param string $view
     * @param array $data
     * @return string
     */
    public function partial($view, array $data = [])
    {
        $view = \Bloge\removeExtension($view);
        $path = "{$this->path}/$view.php";
        
        if (!file_exists($path)) {
            throw new NotFoundException($view);
        }
        
        return \Bloge\render($path, array_merge($this->data, $data));
    }
    
    /**
     * @{inheritDoc} 
     */
    public function render(array $data = [])
    {
        $layout = isset($data['layout']) 
            ? $data['layout'] 
            : 'layout.php';
        
        $data['theme'] = $this;
        $this->data = $data;
        
        return $this->partial($layout, $data);
    }
}<commit_msg>Move '$theme' injection in partial method<commit_after><?php

namespace Bloge\Renderers;

use Bloge\NotFoundException;

/**
 * Basic renderer
 * 
 * This renderer renders raw PHP templates
 * 
 * @package bloge
 */
class PHP implements IRenderer
{
    /**
     * @var string $path
     */
    protected $path;
    
    /**
     * @var array $data
     */
    protected $data = [];
    
    /**
     * @param string $path
     */
    public function __construct($path)
    {
        $this->path = chop($path, '/');
    }
    
    /**
     * @param string $view
     * @param array $data
     * @return string
     */
    public function partial($view, array $data = [])
    {
        $data['theme'] = $this;
        $view = \Bloge\removeExtension($view);
        $path = "{$this->path}/$view.php";
        
        if (!file_exists($path)) {
            throw new NotFoundException($view);
        }
        
        return \Bloge\render($path, array_merge($this->data, $data));
    }
    
    /**
     * @{inheritDoc} 
     */
    public function render(array $data = [])
    {
        $this->data = $data;
        $layout = isset($data['layout']) 
            ? $data['layout'] 
            : 'layout';
        
        return $this->partial($layout, $data);
    }
}
{'fraction_non_alphanumeric': 0.15958713775307662, 'fraction_numerical': 0.0, 'mean_word_length': 1.7272727272727273, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '2187064', 'n_tokens_mistral': 784, 'n_tokens_neox': 772, 'n_words': 163}