<commit_before><?php

require_once ('ELSTR_EnterpriseApplication_Abstract.php');
require_once ('ELSTR_Server_Abstract.php');
require_once ('Zend/Session.php');
require_once ('ELSTR_Exception.php');

/**
 * This is the abstract class every WidgetServer must implement.
 * Note: $acl and $user are optional, but must be set if one of the applications needs ACL control.
 *
 * These methods must be implemented:
 * _initEnterpriseApplications($acl, $user) : Tell the WidgetServer which applications to use with $this->registerEnterpriseApplication()
 *
 * @author <NAME>
 * @version 1.0
 * @created 19-Okt-2009 17:41:37
 */
abstract class ELSTR_WidgetServer_Abstract extends ELSTR_Server_Abstract {

    protected $m_enterpriseApplications;
    protected $m_params;
    protected $m_options;

    /**
     * Constructor of the WidgetServer
     *
     * @param <type> $application ZEND Application
     * @param <type> $params Get/JSON Poste parameters from the request
     */
    function __construct($application, $params = null) {
        parent::__construct($application);
        $this->m_enterpriseApplications = array();
        // set options
        $options = $application->getOption(get_class($this));
        if (isset($options)) {
            $this->m_options = $options;
        }
        // Init
        $this->_initEnterpriseApplications($this->m_application);
        $this->m_params = $params;
    }

    /**
     * The implementation class must implement this method in order
     * to add all the applications needed to the $m_enterpriseApplications array
     * [OPTIPON] This could later be replaced by pure configuration
     */
    abstract protected function _initEnterpriseApplications();

    /**
     * This function will be called by the RequestHandler. Inside the handle
     * function the response musst be generated and returned. This method will
     * first Check against the ACL, if the user is allowed to handle the request.
     *
     * @return void
     */
    public function handle() {
        // Get acl and user object from application
        $acl = $this->m_application->getBootstrap()->getResource('acl');
        $user = $this->m_application->getBootstrap()->getResource('user');

        $username = $user->getUsername();
        // Check on Widget Level
        if ($acl->isAllowed($username, get_class($this))) {
            // check if method ressource is defined, if not allow to execute
            if ($acl->has($this->_getMethod() . '@' . get_class($this))) {
                // check on method ressource is defined
                if ($acl->isAllowed($username, $this->_getMethod() . '@' . get_class($this))) {
                    $this->_handle();
                } else {
                    throw new ELSTR_Exception(null, 1007, null, $this);
                }
            } else {
                $this->_handle();
            }
        } else {
            throw new ELSTR_Exception(null, 1006, null, $this);
        }
    }

    /**
     * This method must returen the name of the method to be called by handle
     * Depending on the request method (GET, POST) and the argument specification
     * this might be implemented in different flavours.
     *
     * @return
     */
    abstract protected function _getMethod();

    /**
     * Handle will call the _handle method to actually handle the request.
     * This method must be implmented according to the Response realized by
     * the Widget (e.g. JSON, Stream, etc.)
     *
     * @return void
     */
    abstract protected function _handle();

    /**
     * Register an application for this WidgetServer
     * Carefull: yet, only one instance of an application can be registered at a time
     *
     * @param $application ELSTR_EnterpriseApplication_Abstract
     * @return void
     */
    protected function registerEnterpriseApplication($enterpriseApplication) {
        $this->m_enterpriseApplications[get_class($enterpriseApplication)] = $enterpriseApplication;
    }

    /**
     * Get a registered servcie
     *
     * @param $name String
     * @return ELSTR_Service_Abstract
     */
    public function getEnterpriseApplication($name) {
        if (array_key_exists($name, $this->m_enterpriseApplications)) {
            return $this->m_enterpriseApplications[$name];
        }<commit_msg>updated docblock for correct wsdl handling<commit_after><?php

require_once ('ELSTR_EnterpriseApplication_Abstract.php');
require_once ('ELSTR_Server_Abstract.php');
require_once ('Zend/Session.php');
require_once ('ELSTR_Exception.php');

/**
 * This is the abstract class every WidgetServer must implement.
 * Note: $acl and $user are optional, but must be set if one of the applications needs ACL control.
 *
 * These methods must be implemented:
 * _initEnterpriseApplications($acl, $user) : Tell the WidgetServer which applications to use with $this->registerEnterpriseApplication()
 *
 * @author <NAME>
 * @version 1.0
 * @created 19-Okt-2009 17:41:37
 */
abstract class ELSTR_WidgetServer_Abstract extends ELSTR_Server_Abstract {

    protected $m_enterpriseApplications;
    protected $m_params;
    protected $m_options;

    /**
     * Constructor of the WidgetServer
     *
     * @param <type> $application ZEND Application
     * @param <type> $params Get/JSON Poste parameters from the request
     */
    function __construct($application, $params = null) {
        parent::__construct($application);
        $this->m_enterpriseApplications = array();
        // set options
        $options = $application->getOption(get_class($this));
        if (isset($options)) {
            $this->m_options = $options;
        }
        // Init
        $this->_initEnterpriseApplications($this->m_application);
        $this->m_params = $params;
    }

    /**
     * The implementation class must implement this method in order
     * to add all the applications needed to the $m_enterpriseApplications array
     * [OPTIPON] This could later be replaced by pure configuration
     */
    abstract protected function _initEnterpriseApplications();

    /**
     * This function will be called by the RequestHandler. Inside the handle
     * function the response musst be generated and returned. This method will
     * first Check against the ACL, if the user is allowed to handle the request.
     *
     * @return void
     */
    public function handle() {
        // Get acl and user object from application
        $acl = $this->m_application->getBootstrap()->getResource('acl');
        $user = $this->m_application->getBootstrap()->getResource('user');

        $username = $user->getUsername();
        // Check on Widget Level
        if ($acl->isAllowed($username, get_class($this))) {
            // check if method ressource is defined, if not allow to execute
            if ($acl->has($this->_getMethod() . '@' . get_class($this))) {
                // check on method ressource is defined
                if ($acl->isAllowed($username, $this->_getMethod() . '@' . get_class($this))) {
                    $this->_handle();
                } else {
                    throw new ELSTR_Exception(null, 1007, null, $this);
                }
            } else {
                $this->_handle();
            }
        } else {
            throw new ELSTR_Exception(null, 1006, null, $this);
        }
    }

    /**
     * This method must returen the name of the method to be called by handle
     * Depending on the request method (GET, POST) and the argument specification
     * this might be implemented in different flavours.
     *
     * @return
     */
    abstract protected function _getMethod();

    /**
     * Handle will call the _handle method to actually handle the request.
     * This method must be implmented according to the Response realized by
     * the Widget (e.g. JSON, Stream, etc.)
     *
     * @return void
     */
    abstract protected function _handle();

    /**
     * Register an application for this WidgetServer
     * Carefull: yet, only one instance of an application can be registered at a time
     *
     * @param $application ELSTR_EnterpriseApplication_Abstract
     * @return void
     */
    protected function registerEnterpriseApplication($enterpriseApplication) {
        $this->m_enterpriseApplications[get_class($enterpriseApplication)] = $enterpriseApplication;
    }

    /**
     * Get a registered servcie
     *
     * @param  string $name
     * @return object ELSTR_Service_Abstract
     */
    public function getEnterpriseApplication($name) {
        if (array_key_exists($name, $this->m_enterpriseApplications)) {
            return $this->m_enterpriseApplications[$name];
        }
{'fraction_non_alphanumeric': 0.10123087541700218, 'fraction_numerical': 0.005061543770850109, 'mean_word_length': 2.64070351758794, 'pattern_counts': {'":': 0, '<': 11, '<?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': '1549885', 'n_tokens_mistral': 2307, 'n_tokens_neox': 2228, 'n_words': 724}