<commit_before><?php

namespace Winata\Service\View;

use Winata\ServiceManager\ServiceManagerInterface;
use Winata\Service\ServiceInterface;

class View implements ServiceInterface
{
    protected $serviceManager;

    protected $template;

    protected $content;

    protected $properties;

    public function __construct(ServiceManagerInterface $serviceManager)
    {
        $this->serviceManager = $serviceManager;
    }

    public function __set($key, $value)
    {
        $this->properties[$key] = $value;
    }

    public function __get($key)
    {
        if (! isset($this->properties[$key])) {
            return null;
        }

        return $this->properties[$key];
    }

    public function __toString()
    {
        $config = $this->serviceManager->getConfig();
        $route  = $this->serviceManager->getService('router');

        ob_start();
        require $config['view_manager']['module_path']
            . '/' . $route->getModule()
            . '/' . $route->getController()
            . '/' . $route->getAction()
            . '.phtml';
        $this->content = ob_get_contents();
        ob_end_clean();

        ob_start();
        require $config['view_manager']['template_path'] . '/default.phtml';
        $template = ob_get_contents();
        ob_end_clean();

        return $template;
    }

    public function setProperties(array $properties = null)
    {
        $this->properties = $properties;
    }

    public function getProperties()
    {
        return $this->properties;
    }
}<commit_msg>add 'setLayout' and 'getLayout' to modify content layout<commit_after><?php

namespace Winata\Service\View;

use Winata\ServiceManager\ServiceManagerInterface;
use Winata\Service\ServiceInterface;

class View implements ServiceInterface
{
    protected $serviceManager;

    protected $layout = 'default.phtml';

    protected $content;

    protected $properties;

    public function __construct(ServiceManagerInterface $serviceManager)
    {
        $this->serviceManager = $serviceManager;
    }

    public function __set($key, $value)
    {
        $this->properties[$key] = $value;
    }

    public function __get($key)
    {
        if (! isset($this->properties[$key])) {
            return null;
        }

        return $this->properties[$key];
    }

    public function __toString()
    {
        $config = $this->serviceManager->getConfig();
        $route  = $this->serviceManager->getService('router');

        ob_start();
        require $config['view_manager']['module_path']
            . '/' . $route->getModule()
            . '/' . $route->getController()
            . '/' . $route->getAction()
            . '.phtml';
        $this->content = ob_get_contents();
        ob_end_clean();

        ob_start();
        require $config['view_manager']['layout_path'] . '/default.phtml';
        $template = ob_get_contents();
        ob_end_clean();

        return $template;
    }

    public function setProperties(array $properties = null)
    {
        $this->properties = $properties;
    }

    public function getProperties()
    {
        return $this->properties;
    }

    public function setLayout($layout)
    {
        if (file_exists($config['view_manager']['layout_path'] . '/' . $layout)) {
            $this->layout = $layout;
        } elseif (file_exists($config['view_manager']['layout_path'] . '/' . $layout . 'phtml')) {
            $this->layout = $layout . '.phtml';
        } else {
            throw new \Exception("Layout dengan nama \"{$layout}\" tidak ditemukan!");
        }
    }

    public function getLayout()
    {
        return $this->layout;
    }
}
{'fraction_non_alphanumeric': 0.14055236532677057, 'fraction_numerical': 0.0, 'mean_word_length': 2.359044995408632, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 34, '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': '2992935', 'n_tokens_mistral': 1032, 'n_tokens_neox': 1006, 'n_words': 193}