<commit_before><?php

abstract class CM_Component_Abstract extends CM_View_Abstract {

    /** @var CM_Model_User|null */
    protected $_viewer;

    /** @var CM_Render */
    protected $_render;

    /** @var string */
    protected $_tplName = 'default.tpl';

    /** @var CM_ComponentFrontendHandler */
    protected $_js = null;

    /** @var CM_Params */
    protected $_params;

    /**
     * @param CM_Render            $render
     * @param CM_Params|array|null $params
     * @param CM_Model_User|null   $viewer
     */
    public function __construct(CM_Render $render, $params = null, CM_Model_User $viewer = null) {
        $this->_render = $render;
        $this->_viewer = $viewer;
        if (is_null($params)) {
            $params = CM_Params::factory();
        }
        if (is_array($params)) {
            $params = CM_Params::factory($params);
        }
        $this->_params = $params;
        $this->_js = new CM_ComponentFrontendHandler();

        if ($this->_params->has('template')) {
            $this->setTplName($this->_params->getString('template'));
        }
    }

    /**
     * Checks if a component can be accessed by the currently set user
     *
     * Access for everyone is default. Should be overloaded by every component
     *
     * @internal param \CM_Render $render
     * @return
     */
    abstract public function checkAccessible();

    /**
     * @return CM_Render
     */
    public function getRender() {
        return $this->_render;
    }

    /**
     * @return CM_ComponentFrontendHandler
     */
    public function getFrontendHandler() {
        return $this->_js;
    }

    /**
     * @return CM_Params
     */
    public function getParams() {
        return $this->_params;
    }

    public function prepare(CM_Params $params) {
    }

    /**
     * @return string
     */
    public function getTplName() {
        return $this->_tplName;
    }

    /**
     * @param string $filename
     * @throws CM_Exception_Invalid
     */
    public function setTplName($filename) {
        $filename = (string) $filename . '.tpl';
        if (preg_match('/[^\w\.-]/', $filename)) {
            throw new CM_Exception_Invalid('Invalid tpl-name `' . $filename . '`');
        }
        $this->_tplName = $filename;
    }

    /**
     * Get auto id prefixed id value for an html element.
     *
     * @param string $id_value
     * @return string
     */
    final public function getTagAutoId($id_value) {
        return $this->getAutoId() . '-' . $id_value;
    }

    /**
     * Checks if a user is set on the component
     *
     * @throws CM_Exception_AuthRequired If no user is set
     */
    protected function _checkViewer() {
        $this->_getViewer(true);
    }

    /**
     * @param boolean $needed OPTIONAL Throw a CM_Exception_AuthRequired if not authenticated
     * @return CM_Model_User|null
     * @throws CM_Exception_AuthRequired
     */
    protected function _getViewer($needed = false) {
        if (!$this->_viewer) {
            if ($needed) {
                throw new CM_Exception_AuthRequired();
            }
            return null;
        }
        return $this->_viewer;
    }

    public static function ajax_reload(CM_Params $params, CM_ComponentFrontendHandler $handler, CM_Response_View_Ajax $response) {
        return $response->reloadComponent($params->getAll());
    }

    /**
     * @param string             $className
     * @param CM_Render          $render
     * @param CM_Params|array    $params
     * @param CM_Model_User|null $viewer
     * @throws CM_Exception
     * @return CM_Component_Abstract
     */
    public static function factory($className, CM_Render $render, $params = null, CM_Model_User $viewer = null) {
        if (!class_exists($className) || !is_subclass_of($className, __CLASS__)) {
            throw new CM_Exception('Cannot find valid class definition for component `' . $className . '`.');
        }
        $component = new $className($params, $viewer);
        return $component;
    }

    /**
     * @param string $property
     * @param mixed  $value
     */
    protected function _setJsParam($property, $value) {
        $this->_js->setParam($property, $value);
    }
}<commit_msg>Fix: Pass render to component<commit_after><?php

abstract class CM_Component_Abstract extends CM_View_Abstract {

    /** @var CM_Model_User|null */
    protected $_viewer;

    /** @var CM_Render */
    protected $_render;

    /** @var string */
    protected $_tplName = 'default.tpl';

    /** @var CM_ComponentFrontendHandler */
    protected $_js = null;

    /** @var CM_Params */
    protected $_params;

    /**
     * @param CM_Render            $render
     * @param CM_Params|array|null $params
     * @param CM_Model_User|null   $viewer
     */
    public function __construct(CM_Render $render, $params = null, CM_Model_User $viewer = null) {
        $this->_render = $render;
        $this->_viewer = $viewer;
        if (is_null($params)) {
            $params = CM_Params::factory();
        }
        if (is_array($params)) {
            $params = CM_Params::factory($params);
        }
        $this->_params = $params;
        $this->_js = new CM_ComponentFrontendHandler();

        if ($this->_params->has('template')) {
            $this->setTplName($this->_params->getString('template'));
        }
    }

    /**
     * Checks if a component can be accessed by the currently set user
     *
     * Access for everyone is default. Should be overloaded by every component
     *
     * @internal param \CM_Render $render
     * @return
     */
    abstract public function checkAccessible();

    /**
     * @return CM_Render
     */
    public function getRender() {
        return $this->_render;
    }

    /**
     * @return CM_ComponentFrontendHandler
     */
    public function getFrontendHandler() {
        return $this->_js;
    }

    /**
     * @return CM_Params
     */
    public function getParams() {
        return $this->_params;
    }

    public function prepare(CM_Params $params) {
    }

    /**
     * @return string
     */
    public function getTplName() {
        return $this->_tplName;
    }

    /**
     * @param string $filename
     * @throws CM_Exception_Invalid
     */
    public function setTplName($filename) {
        $filename = (string) $filename . '.tpl';
        if (preg_match('/[^\w\.-]/', $filename)) {
            throw new CM_Exception_Invalid('Invalid tpl-name `' . $filename . '`');
        }
        $this->_tplName = $filename;
    }

    /**
     * Get auto id prefixed id value for an html element.
     *
     * @param string $id_value
     * @return string
     */
    final public function getTagAutoId($id_value) {
        return $this->getAutoId() . '-' . $id_value;
    }

    /**
     * Checks if a user is set on the component
     *
     * @throws CM_Exception_AuthRequired If no user is set
     */
    protected function _checkViewer() {
        $this->_getViewer(true);
    }

    /**
     * @param boolean $needed OPTIONAL Throw a CM_Exception_AuthRequired if not authenticated
     * @return CM_Model_User|null
     * @throws CM_Exception_AuthRequired
     */
    protected function _getViewer($needed = false) {
        if (!$this->_viewer) {
            if ($needed) {
                throw new CM_Exception_AuthRequired();
            }
            return null;
        }
        return $this->_viewer;
    }

    public static function ajax_reload(CM_Params $params, CM_ComponentFrontendHandler $handler, CM_Response_View_Ajax $response) {
        return $response->reloadComponent($params->getAll());
    }

    /**
     * @param string             $className
     * @param CM_Render          $render
     * @param CM_Params|array    $params
     * @param CM_Model_User|null $viewer
     * @throws CM_Exception
     * @return CM_Component_Abstract
     */
    public static function factory($className, CM_Render $render, $params = null, CM_Model_User $viewer = null) {
        if (!class_exists($className) || !is_subclass_of($className, __CLASS__)) {
            throw new CM_Exception('Cannot find valid class definition for component `' . $className . '`.');
        }
        $component = new $className($render, $params, $viewer);
        return $component;
    }

    /**
     * @param string $property
     * @param mixed  $value
     */
    protected function _setJsParam($property, $value) {
        $this->_js->setParam($property, $value);
    }
}
{'fraction_non_alphanumeric': 0.12360080122540355, 'fraction_numerical': 0.0, 'mean_word_length': 2.181409295352324, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, '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': '6417907', 'n_tokens_mistral': 2481, 'n_tokens_neox': 2443, 'n_words': 591}