<commit_before><?php

    /**
     * SabreAMF_ClassMapper 
     * 
     * @package SabreAMF 
     * @version $Id$
     * @copyright 2006 Rooftop Solutions
     * @author <NAME> <<EMAIL>> 
     * @licence http://www.freebsd.org/copyright/license.html  BSD License (4 Clause) 
     */

    require_once 'SabreAMF/AMF3/RemotingMessage.php';
    require_once 'SabreAMF/AMF3/CommandMessage.php';
    require_once 'SabreAMF/AMF3/AcknowledgeMessage.php';
    require_once 'SabreAMF/AMF3/ErrorMessage.php';
    
    final class SabreAMF_ClassMapper {

        /**
         * @var array
         */
        static public $maps = array(
            'flex.messaging.messages.RemotingMessage'    => 'SabreAMF_AMF3_RemotingMessage',
            'flex.messaging.messages.CommandMessage'     => 'SabreAMF_AMF3_CommandMessage',
            'flex.messaging.messages.AcknowledgeMessage' => 'SabreAMF_AMF3_AcknowledgeMessage',
            'flex.messaging.messages.ErrorMessage'       => 'SabreAMF_AMF3_ErrorMessage',
        );

        /**
         * Assign this callback to intercept calls to getLocalClass
         *
         * @var callback
         */
        static public $onGetLocalClass;

        /**
         * Assign this callback to intercept calls to getRemoteClass
         *
         * @var callback
         */
        static public $onGetRemoteClass;

        /**
         * The Constructor
         * 
         * We make the constructor private so the class cannot be initialized
         * 
         * @return void
         */
        private function __construct() { }

        /**
         * Register a new class to be mapped 
         * 
         * @param string $remoteClass 
         * @param string $localClass 
         * @return void
         */
        static public function registerClass($remoteClass,$localClass) {

            self::$maps[$remoteClass] = $localClass;

        }

        /**
         * Get the local classname for a remote class 
         *
         * This method will return FALSE when the class is not found
         * 
         * @param string $remoteClass 
         * @return mixed 
         */
        static public function getLocalClass($remoteClass) {

            if (is_callable(self::$onGetLocalClass)) {
                $localClass = call_user_func(self::$onGetLocalClass,$remoteClass);
                if ($localClass) return $localClass;
            }
            return (isset(self::$maps[$remoteClass]))?self::$maps[$remoteClass]:false;

        }

        /**
         * Get the remote classname for a local class 
         * 
         * This method will return FALSE when the class is not found
         * 
         * @param string $localClass 
         * @return mixed 
         */
        static public function getRemoteClass($localClass) {

            if (is_callable(self::$onGetRemoteClass)) {
                $remoteClass = call_user_func(self::$onGetRemotelass,$localClass);
                if ($remoteClass) return $remoteClass;
            }
            return array_search($localClass,self::$maps);

        }

    }

?><commit_msg>Added a few exceptions<commit_after><?php

    /**
     * SabreAMF_ClassMapper 
     * 
     * @package SabreAMF 
     * @version $Id$
     * @copyright 2006 Rooftop Solutions
     * @author <NAME> <<EMAIL>> 
     * @licence http://www.freebsd.org/copyright/license.html  BSD License (4 Clause) 
     */

    require_once 'SabreAMF/AMF3/RemotingMessage.php';
    require_once 'SabreAMF/AMF3/CommandMessage.php';
    require_once 'SabreAMF/AMF3/AcknowledgeMessage.php';
    require_once 'SabreAMF/AMF3/ErrorMessage.php';
    
    final class SabreAMF_ClassMapper {

        /**
         * @var array
         */
        static public $maps = array(
            'flex.messaging.messages.RemotingMessage'    => 'SabreAMF_AMF3_RemotingMessage',
            'flex.messaging.messages.CommandMessage'     => 'SabreAMF_AMF3_CommandMessage',
            'flex.messaging.messages.AcknowledgeMessage' => 'SabreAMF_AMF3_AcknowledgeMessage',
            'flex.messaging.messages.ErrorMessage'       => 'SabreAMF_AMF3_ErrorMessage',
        );

        /**
         * Assign this callback to intercept calls to getLocalClass
         *
         * @var callback
         */
        static public $onGetLocalClass;

        /**
         * Assign this callback to intercept calls to getRemoteClass
         *
         * @var callback
         */
        static public $onGetRemoteClass;

        /**
         * The Constructor
         * 
         * We make the constructor private so the class cannot be initialized
         * 
         * @return void
         */
        private function __construct() { }

        /**
         * Register a new class to be mapped 
         * 
         * @param string $remoteClass 
         * @param string $localClass 
         * @return void
         */
        static public function registerClass($remoteClass,$localClass) {

            self::$maps[$remoteClass] = $localClass;

        }

        /**
         * Get the local classname for a remote class 
         *
         * This method will return FALSE when the class is not found
         * 
         * @param string $remoteClass 
         * @return mixed 
         */
        static public function getLocalClass($remoteClass) {

            $localClass = false;
            $cb = false;
            if (is_callable(self::$onGetLocalClass)) {
                $cb = true;
                $localClass = call_user_func(self::$onGetLocalClass,$remoteClass);
            }
            if (!$localClass) $localClass=(isset(self::$maps[$remoteClass]))?self::$maps[$remoteClass]:false;
            if (!$localClass) return false;
            if (!is_string($localClass) && $cb) {
                throw new Exception('Classname received from onGetLocalClass should be a string or return false. ' . gettype($localClass) . ' was returned');
            }
            if (!class_exists($localClass)) {
                throw new Exception('Class ' . $localClass . ' is not defined');
            }
            return false;

        }

        /**
         * Get the remote classname for a local class 
         * 
         * This method will return FALSE when the class is not found
         * 
         * @param string $localClass 
         * @return mixed 
         */
        static public function getRemoteClass($localClass) {

            $localClass = false;
            $cb = false;
            if (is_callable(self::$onGetRemoteClass)) {
                $cb = true;
                $remoteClass = call_user_func(self::$onGetRemotelass,$localClass);
            }
            if (!$remoteClass) $remoteClass = array_search($localClass,self::$maps);
            if (!$remoteClass) return false;
            if (!is_string($remoteClass) && $cb) {
                throw new Exception('Classname received from onGetLocalClass should be a string or return false. ' . gettype($localClass) . ' was returned');
            }
            return $remoteClass; 

        }

    }

?>
{'fraction_non_alphanumeric': 0.09954558364101107, 'fraction_numerical': 0.003692132916785004, 'mean_word_length': 1.8037420382165605, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '778405', 'n_tokens_mistral': 1984, 'n_tokens_neox': 1897, 'n_words': 441}