<commit_before><?php
/**
 * Controller Class
 * Implementing MVC Pattern
 * @author <NAME> <<EMAIL>, <EMAIL>>
 * @package gulliver.system
 * @access private
 */
class Controller  
{
    /**
     * @var boolean debug switch for general purpose
     */
    public $debug = null;
    /**
     * @var array - private array to store proxy data
     */
    private $__data__ = array();
    
    /**
     * @var object - private object to store the http request data 
     */
    private $__request__;
    
    /**
     * @var object - headPublisher object to handle the output
     */
    private $headPublisher = null;

    /**
     * @var string - response type var. possibles values: json|plain
     */
    private $responseType = '';
    
    /**
     * Magic setter method
     * 
     * @param string $name
     * @param string $value
     */
    public function __set($name, $value) 
    {
        $this->__data__[$name] = $value;
    }

    /**
     * Magic getter method
     * 
     * @param string $name
     * @return string or NULL if the internal var doesn't exist
     */
    public function __get($name) 
    {
        if (array_key_exists($name, $this->__data__)) {
            return $this->__data__[$name];
        }

        $trace = debug_backtrace();
        trigger_error(
            'Undefined property via __get(): ' . $name .
            ' in ' . $trace[0]['file'] .
            ' on line ' . $trace[0]['line'],
            E_USER_NOTICE);
        return null;
    }

    /**
     * Magic isset method
     * @param string $name
     */
    public function __isset($name) 
    {
        return isset($this->__data__[$name]);
    }

    
    /**
     * Magic unset method
     * @param string $name
     */
    public function __unset($name) 
    {
        unset($this->__data__[$name]);
    }

    /**
     * Set Response type method
     * @param string $type contains : json|plain
     */
    public function setResponseType($type)
    {
        $this->responseType = $type;
    }
    
    /**
     * call to execute a internal proxy method and handle its exceptions
     * @param string $name
     */
    public function call($name) 
    {
        try {
            $result = $this->$name($this->__request__);
            if ($this->responseType == 'json') {
                print G::json_encode($result);
            }
        } catch (Exception $e) {
            if ($this->responseType != 'json') {
                $result->exception->class = get_class($e);
                $result->exception->code = $e->getCode();

                $template = new TemplatePower(PATH_TEMPLATE . 'controller.exception.tpl');
                $template->prepare();
                $template->assign('controller', get_called_class());
                $template->assign('message', $e->getMessage());
                $template->assign('file',    $e->getFile());
                $template->assign('line',    $e->getLine());
                $template->assign('trace',   $e->getTraceAsString());

                echo $template->getOutputContent();
                
            } else {
                $result->success = false;
                $result->msg     = $e->getMessage();
                switch(get_class($e)) {
                    case 'Exception':       $error = "SYSTEM ERROR"; break;
                    case 'PMException':     $error = "PROCESSMAKER ERROR"; break;
                    case 'PropelException': $error = "DATABASE ERROR"; break;
                    case 'UserException':   $error = "USER ERROR"; break;
                }
                $result->error = $error;
                
                $result->exception->class = get_class($e);
                $result->exception->code = $e->getCode();
                print G::json_encode($result);
            }
        }
    }
    
    /**
     * Set the http request data
     * @param array $data<commit_msg>BUG 0000 fix for PHP < 5.3 version compatibility on controller class<commit_after><?php
/**
 * Controller Class
 * Implementing MVC Pattern
 * @author <NAME> <<EMAIL>, <EMAIL>>
 * @package gulliver.system
 * @access private
 */
class Controller  
{
    /**
     * @var boolean debug switch for general purpose
     */
    public $debug = null;
    /**
     * @var array - private array to store proxy data
     */
    private $__data__ = array();
    
    /**
     * @var object - private object to store the http request data 
     */
    private $__request__;
    
    /**
     * @var object - headPublisher object to handle the output
     */
    private $headPublisher = null;

    /**
     * @var string - response type var. possibles values: json|plain
     */
    private $responseType = '';
    
    /**
     * Magic setter method
     * 
     * @param string $name
     * @param string $value
     */
    public function __set($name, $value) 
    {
        $this->__data__[$name] = $value;
    }

    /**
     * Magic getter method
     * 
     * @param string $name
     * @return string or NULL if the internal var doesn't exist
     */
    public function __get($name) 
    {
        if (array_key_exists($name, $this->__data__)) {
            return $this->__data__[$name];
        }

        $trace = debug_backtrace();
        trigger_error(
            'Undefined property via __get(): ' . $name .
            ' in ' . $trace[0]['file'] .
            ' on line ' . $trace[0]['line'],
            E_USER_NOTICE);
        return null;
    }

    /**
     * Magic isset method
     * @param string $name
     */
    public function __isset($name) 
    {
        return isset($this->__data__[$name]);
    }

    
    /**
     * Magic unset method
     * @param string $name
     */
    public function __unset($name) 
    {
        unset($this->__data__[$name]);
    }

    /**
     * Set Response type method
     * @param string $type contains : json|plain
     */
    public function setResponseType($type)
    {
        $this->responseType = $type;
    }
    
    /**
     * call to execute a internal proxy method and handle its exceptions
     * @param string $name
     */
    public function call($name) 
    {
        try {
            $result = $this->$name($this->__request__);
            if ($this->responseType == 'json') {
                print G::json_encode($result);
            }
        } catch (Exception $e) {
            if ($this->responseType != 'json') {
                $result->exception->class = get_class($e);
                $result->exception->code = $e->getCode();

                $template = new TemplatePower(PATH_TEMPLATE . 'controller.exception.tpl');
                $template->prepare();
                $template->assign('controller', (function_exists('get_called_class') ? get_called_class() : 'Controller'));
                $template->assign('message', $e->getMessage());
                $template->assign('file',    $e->getFile());
                $template->assign('line',    $e->getLine());
                $template->assign('trace',   $e->getTraceAsString());

                echo $template->getOutputContent();
                
            } else {
                $result->success = false;
                $result->msg     = $e->getMessage();
                switch(get_class($e)) {
                    case 'Exception':       $error = "SYSTEM ERROR"; break;
                    case 'PMException':     $error = "PROCESSMAKER ERROR"; break;
                    case 'PropelException': $error = "DATABASE ERROR"; break;
                    case 'UserException':   $error = "USER ERROR"; break;
                }
                $result->error = $error;
                
                $result->exception->class = get_class($e);
                $result->exception->code = $e->getCode();
                print G::json_encode($result);
            }
        }
    }
    
    /**
     * Set the http request data
     * @param array $data
{'fraction_non_alphanumeric': 0.136986301369863, 'fraction_numerical': 0.0012683916793505834, 'mean_word_length': 1.6415410385259632, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 81, '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': '4921572', 'n_tokens_mistral': 2213, 'n_tokens_neox': 2137, 'n_words': 527}