<commit_before><?php

/*
 * This file is part of SlimController.
 *
 * @author <NAME> <<EMAIL>>
 * @copyright 2012 <NAME>
 * @version 0.1.2
 * @package SlimController
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace SlimController;

/**
 * Implements a basic controller functionallity.
 * It should not be instanciated directly but extended from.
 */

abstract class SlimController
{

    /**
     * @const string
     */
    const VERSION = '0.1.4';

    /**
     * @var \Slim\Slim
     */
    protected $app;

    /**
     * @var bool Whether cleanup params or not
     */
    private $paramCleanup = true;

    /**
     * @var string Prefix for params
     */
    private $paramPrefix = 'data.';

    /**
     * @var array Stash of GET & POST params
     */
    private $paramsParams = null;

    /**
     * @var array Stash of GET params
     */
    private $paramsGet = null;

    /**
     * @var array Stash of POST params
     */
    private $paramsPost = null;

    /**
     * @var string
     */
    protected $renderTemplateSuffix = null;

    /**
     * Constructor for TodoQueue\Controller\Login
     *
     * @param \Slim\Slim $app Ref to slim app
     */
    public function __construct(\Slim\Slim &$app)
    {
        $this->app = $app;
        if ($renderTemplateSuffix = $app->config('controller.template_suffix')) {
            $this->renderTemplateSuffix = $renderTemplateSuffix;
        }
        if (!is_null($paramPrefix = $app->config('controller.param_prefix'))) {
            $this->paramPrefix = $paramPrefix;
        }
        $this->renderTemplateSuffix = $app->config('controller.template_suffix');
    }

    /**
     * Renders output with given template
     *
     * @param string $template Name of the template to be rendererd
     * @param array  $args     Args for view
     */
    protected function render($template, $args = null)
    {
        if (!is_null($args)) {
            $this->app->view()->appendData($args);
        }
        if (!is_null($this->renderTemplateSuffix)
            && !preg_match('/\.'. $this->renderTemplateSuffix. '$/', $template)
        ) {
            $template .= '.'. $this->renderTemplateSuffix;
        }
        print $this->app->view()->render($template);
    }

    /**
     * Performs redirect
     *
     * @param string $path
     */
    protected function redirect($path)
    {
        return $this->app->redirect($path);
    }

    /**
     * Slim's request object
     *
     * @return \Slim\Request
     */
    protected function request()
    {
        return $this->app->request();
    }


    /**
     * Returns a single parameter of the "data[Object][Key]" format.
     *
     * <code>
     $paramValue = $this->param('prefix.name'); // prefix[name] -> "string value"
     $paramValue = $this->param('prefix.name', 'post'); // prefix[name] -> "string value"<commit_msg>Fix phpdoc comment \Slim\Request -> \Slim\Http\Request<commit_after><?php

/*
 * This file is part of SlimController.
 *
 * @author <NAME> <<EMAIL>>
 * @copyright 2012 <NAME>
 * @version 0.1.2
 * @package SlimController
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace SlimController;

/**
 * Implements a basic controller functionallity.
 * It should not be instanciated directly but extended from.
 */

abstract class SlimController
{

    /**
     * @const string
     */
    const VERSION = '0.1.4';

    /**
     * @var \Slim\Slim
     */
    protected $app;

    /**
     * @var bool Whether cleanup params or not
     */
    private $paramCleanup = true;

    /**
     * @var string Prefix for params
     */
    private $paramPrefix = 'data.';

    /**
     * @var array Stash of GET & POST params
     */
    private $paramsParams = null;

    /**
     * @var array Stash of GET params
     */
    private $paramsGet = null;

    /**
     * @var array Stash of POST params
     */
    private $paramsPost = null;

    /**
     * @var string
     */
    protected $renderTemplateSuffix = null;

    /**
     * Constructor for TodoQueue\Controller\Login
     *
     * @param \Slim\Slim $app Ref to slim app
     */
    public function __construct(\Slim\Slim &$app)
    {
        $this->app = $app;
        if ($renderTemplateSuffix = $app->config('controller.template_suffix')) {
            $this->renderTemplateSuffix = $renderTemplateSuffix;
        }
        if (!is_null($paramPrefix = $app->config('controller.param_prefix'))) {
            $this->paramPrefix = $paramPrefix;
        }
        $this->renderTemplateSuffix = $app->config('controller.template_suffix');
    }

    /**
     * Renders output with given template
     *
     * @param string $template Name of the template to be rendererd
     * @param array  $args     Args for view
     */
    protected function render($template, $args = null)
    {
        if (!is_null($args)) {
            $this->app->view()->appendData($args);
        }
        if (!is_null($this->renderTemplateSuffix)
            && !preg_match('/\.'. $this->renderTemplateSuffix. '$/', $template)
        ) {
            $template .= '.'. $this->renderTemplateSuffix;
        }
        print $this->app->view()->render($template);
    }

    /**
     * Performs redirect
     *
     * @param string $path
     */
    protected function redirect($path)
    {
        return $this->app->redirect($path);
    }

    /**
     * Slim's request object
     *
     * @return \Slim\Http\Request
     */
    protected function request()
    {
        return $this->app->request();
    }


    /**
     * Returns a single parameter of the "data[Object][Key]" format.
     *
     * <code>
     $paramValue = $this->param('prefix.name'); // prefix[name] -> "string value"
     $paramValue = $this->param('prefix.name', 'post'); // prefix[name] -> "string value"
{'fraction_non_alphanumeric': 0.1422326832548756, 'fraction_numerical': 0.0033624747814391394, 'mean_word_length': 2.116291251964379, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 62, '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': '4311405', 'n_tokens_mistral': 1798, 'n_tokens_neox': 1750, 'n_words': 445}