<commit_before><?php

/**
 * This file is part of the Cygnite package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Cygnite\Mvc\Controller;

use Exception;
use Cygnite\Base\EventHandler\Event;
use Cygnite\Common\Encrypt;
use Cygnite\Common\SessionManager\Session;
use Cygnite\Foundation\Application as App;
use Cygnite\Helpers\Inflector;
use Cygnite\Mvc\View\ViewFactory;
use Cygnite\Mvc\ControllerViewBridgeTrait;

/**
 * AbstractBaseController.
 *
 * Extend the features of BaseController.
 *
 * @author <NAME> <<EMAIL>>
 */
abstract class AbstractBaseController
{
    use ControllerViewBridgeTrait;

    protected $validProperties = ['layout', 'templateEngine', 'templateExtension', 'autoReload', 'twigDebug'];

    private $class;

    /**
     * Constructor function
     *
     * Configure parameters for View
     */
    public function __construct()
    {
        $this->configure();
    }

    //prevent clone.
    private function __clone()
    {
    }

    /**
     * Magic Method for handling errors and undefined methods.
     *
     * @param $method
     * @param $arguments
     * @return AbstractBaseController|mixed|void
     * @throws \Exception
     */
    public function __call($method, $arguments)
    {
        if (in_array($method, $this->validFlashMessage)) {
            return $this->setFlashMessage($method, $arguments);
        }

        if (!method_exists($this, $method)) {
            throw new Exception("Undefined method [$method] called by ".get_class($this).' Controller');
        }
    }

    /**
     * @param string $uri
     * @param string $type
     * @param int    $httpResponseCode
     * @return $this
     */
    protected function redirectTo($uri = '', $type = 'location', $httpResponseCode = 302)
    {
        $url = $this->get('cygnite.common.url-manager.url');
        $url->redirectTo($uri, $type, $httpResponseCode);

        return $this;
    }

    /**
     * <code>
     * // Call the "index" method on the "user" controller
     *  $response = $this->call('admin::user@index');
     *
     * // Call the "user/admin" controller and pass parameters
     *   $response = $this->call('modules.admin.user@profile', $arguments);
     * </code>
     */
    public function call($resource, $arguments = [])
    {
        list($name, $method) = explode('@', $resource);

        $method = $method.'Action';
        $class = array_map('ucfirst', explode('.', $name));
        $className = Inflector::classify(end($class)).'Controller';
        $namespace = str_replace(end($class), '', $class);
        $class = '\\'.APP_NS.'\\'.implode('\\', $namespace).$className;

        return $this->_call(new $class, $method, $arguments);
    }

    public function getContainer()
    {
        return App::instance();
    }

    /**
     * @param $name
     */
    public function setController($name)
    {
        $this->class = $name;
    }

    /**
     * @return string
     */
    public function getController()
    {
        return isset($this->class) ? $this->class : get_called_class();
    }


    public function configure()
    {
        foreach ($this->validProperties as $key => $property) {

            $method = 'set'.ucfirst($property);

            if ($this->property($this, $property)) {
                $this->view()->{$method}($this->{$property});
            }
        }
    }

    /**
     * @param $class
     * @param $property
     * @return bool
     */
    public function property($class, $property)
    {
        return property_exists($class, $property);
    }

    /**
     * @param       $view
     * @param array $params
     * @return mixed
     */
    public function render($view, $params = [], $return = false)
    {
        return $this->view()->render($view, $params, $return);
    }

    /**
     * @return mixed
     */
    public function view()
    {
        return ViewFactory::make();
    }
}
<commit_msg>Cygnite\Mvc\Controller\AbstractBaseController:  Added template() method and fixed calling static method on object<commit_after><?php

/**
 * This file is part of the Cygnite package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Cygnite\Mvc\Controller;

use Exception;
use Cygnite\Common\Encrypt;
use Cygnite\Helpers\Inflector;
use Cygnite\Mvc\View\ViewFactory;
use Cygnite\Common\UrlManager\Url;
use Cygnite\Base\EventHandler\Event;
use Cygnite\Common\SessionManager\Session;
use Cygnite\Foundation\Application as App;
use Cygnite\Mvc\ControllerViewBridgeTrait;

/**
 * AbstractBaseController.
 *
 * Extend the features of BaseController.
 *
 * @author <NAME> <<EMAIL>>
 */
abstract class AbstractBaseController
{
    use ControllerViewBridgeTrait;

    protected $validProperties = ['layout', 'templateEngine', 'templateExtension', 'autoReload', 'twigDebug'];

    private $class;

    /**
     * Constructor function
     *
     * Configure parameters for View
     */
    public function __construct()
    {
        $this->configure();
    }

    //prevent clone.
    private function __clone()
    {
    }

    /**
     * Magic Method for handling errors and undefined methods.
     *
     * @param $method
     * @param $arguments
     * @return AbstractBaseController|mixed|void
     * @throws \Exception
     */
    public function __call($method, $arguments)
    {
        if (in_array($method, $this->validFlashMessage)) {
            return $this->setFlashMessage($method, $arguments);
        }

        if (!method_exists($this, $method)) {
            throw new Exception("Undefined method [$method] called by ".get_class($this).' Controller');
        }
    }

    /**
     * @param string $uri
     * @param string $type
     * @param int    $httpResponseCode
     * @return $this
     */
    protected function redirectTo($uri = '', $type = 'location', $httpResponseCode = 302)
    {
        Url::redirectTo($uri, $type, $httpResponseCode);

        return $this;
    }

    /**
     * <code>
     * // Call the "index" method on the "user" controller
     *  $response = $this->call('admin::user@index');
     *
     * // Call the "user/admin" controller and pass parameters
     *   $response = $this->call('modules.admin.user@profile', $arguments);
     * </code>
     */
    public function call($resource, $arguments = [])
    {
        list($name, $method) = explode('@', $resource);

        $method = $method.'Action';
        $class = array_map('ucfirst', explode('.', $name));
        $className = Inflector::classify(end($class)).'Controller';
        $namespace = str_replace(end($class), '', $class);
        $class = '\\'.APP_NS.'\\'.implode('\\', $namespace).$className;

        return $this->_call(new $class, $method, $arguments);
    }

    public function getContainer()
    {
        return App::instance();
    }

    /**
     * @param $name
     */
    public function setController($name)
    {
        $this->class = $name;
    }

    /**
     * @return string
     */
    public function getController()
    {
        return isset($this->class) ? $this->class : get_called_class();
    }


    public function configure()
    {
        foreach ($this->validProperties as $key => $property) {

            $method = 'set'.ucfirst($property);

            if ($this->property($this, $property)) {
                $this->view()->{$method}($this->{$property});
            }
        }
    }

    /**
     * @param $class
     * @param $property
     * @return bool
     */
    public function property($class, $property)
    {
        return property_exists($class, $property);
    }

    /**
     * @param       $view
     * @param array $params
     * @return mixed
     */
    public function render($view, $params = [], $return = false)
    {
        return $this->view()->render($view, $params, $return);
    }

    /**
     * @param       $view
     * @param array $params
     * @return mixed
     */
    public function template($view, $params = [], $return = false)
    {
        return $this->view()->template($view, $params, $return);
    }

    /**
     * @return mixed
     */
    public function view()
    {
        return ViewFactory::make();
    }
}

{'fraction_non_alphanumeric': 0.15008976660682227, 'fraction_numerical': 0.000718132854578097, 'mean_word_length': 2.3953677366924016, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 57, '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': '822505', 'n_tokens_mistral': 2465, 'n_tokens_neox': 2415, 'n_words': 573}