~chroot64bit/zivios/gentoo-experimental

« back to all changes in this revision

Viewing changes to application/library/Zend/Amf/Parse/TypeLoader.php

  • Committer: Mustafa A. Hashmi
  • Date: 2008-12-04 13:32:21 UTC
  • Revision ID: mhashmi@zivios.org-20081204133221-0nd1trunwevijj38
Inclusion of new installation framework with ties to zend layout and dojo layout

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Zend Framework
 
4
 *
 
5
 * LICENSE
 
6
 *
 
7
 * This source file is subject to the new BSD license that is bundled
 
8
 * with this package in the file LICENSE.txt.
 
9
 * It is also available through the world-wide-web at this URL:
 
10
 * http://framework.zend.com/license/new-bsd
 
11
 * If you did not receive a copy of the license and are unable to
 
12
 * obtain it through the world-wide-web, please send an email
 
13
 * to license@zend.com so we can send you a copy immediately.
 
14
 *
 
15
 * @category   Zend
 
16
 * @package    Zend_Amf
 
17
 * @subpackage Parse
 
18
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 
19
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 
20
 */
 
21
 
 
22
require_once 'Zend/Amf/Value/Messaging/AcknowledgeMessage.php';
 
23
require_once 'Zend/Amf/Value/Messaging/AsyncMessage.php';
 
24
require_once 'Zend/Amf/Value/Messaging/CommandMessage.php';
 
25
require_once 'Zend/Amf/Value/Messaging/ErrorMessage.php';
 
26
require_once 'Zend/Amf/Value/Messaging/RemotingMessage.php';
 
27
 
 
28
/**
 
29
 * Loads a local class and executes the instantiation of that class.
 
30
 *
 
31
 * @todo       PHP 5.3 can drastically change this class w/ namespace and the new call_user_func w/ namespace
 
32
 * @package    Zend_Amf
 
33
 * @subpackage Parse
 
34
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 
35
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 
36
 */
 
37
final class Zend_Amf_Parse_TypeLoader
 
38
{
 
39
    /**
 
40
     * @var string callback class
 
41
     */
 
42
    public static $callbackClass;
 
43
 
 
44
    /**
 
45
     * @var array AMF class map
 
46
     */
 
47
    public static $classMap = array (
 
48
        'flex.messaging.messages.AcknowledgeMessage' => 'Zend_Amf_Value_Messaging_AcknowledgeMessage',
 
49
        'flex.messaging.messages.ErrorMessage'       => 'Zend_Amf_Value_Messaging_AsyncMessage',
 
50
        'flex.messaging.messages.CommandMessage'     => 'Zend_Amf_Value_Messaging_CommandMessage',
 
51
        'flex.messaging.messages.ErrorMessage'       => 'Zend_Amf_Value_Messaging_ErrorMessage',
 
52
        'flex.messaging.messages.RemotingMessage'    => 'Zend_Amf_Value_Messaging_RemotingMessage',
 
53
    );
 
54
 
 
55
    /**
 
56
     * @var array Default class map
 
57
     */
 
58
    protected static $_defaultClassMap = array(
 
59
        'flex.messaging.messages.AcknowledgeMessage' => 'Zend_Amf_Value_Messaging_AcknowledgeMessage',
 
60
        'flex.messaging.messages.ErrorMessage'       => 'Zend_Amf_Value_Messaging_AsyncMessage',
 
61
        'flex.messaging.messages.CommandMessage'     => 'Zend_Amf_Value_Messaging_CommandMessage',
 
62
        'flex.messaging.messages.ErrorMessage'       => 'Zend_Amf_Value_Messaging_ErrorMessage',
 
63
        'flex.messaging.messages.RemotingMessage'    => 'Zend_Amf_Value_Messaging_RemotingMessage',
 
64
    );
 
65
 
 
66
    /**
 
67
     * Load the mapped class type into a callback.
 
68
     *
 
69
     * @param  string $className
 
70
     * @return object|false
 
71
     */
 
72
    public static function loadType($className)
 
73
    {
 
74
        $class    = false;
 
75
        $callBack = false;
 
76
        $class    = self::getMappedClassName($className);
 
77
        if (!class_exists($class)) {
 
78
            require_once 'Zend/Amf/Exception.php';
 
79
            throw new Zend_Amf_Exception($className .' mapped class '. $class . ' is not defined');
 
80
        }
 
81
 
 
82
        return $class;
 
83
    }
 
84
 
 
85
    /**
 
86
     * Looks up the supplied call name to its mapped class name
 
87
     *
 
88
     * @param  string $className
 
89
     * @return string
 
90
     */
 
91
    public static function getMappedClassName($className)
 
92
    {
 
93
        $mappedName = array_search($className, self::$classMap);
 
94
 
 
95
        if ($mappedName) {
 
96
            return $mappedName;
 
97
        }
 
98
 
 
99
        $mappedName = array_search($className, array_flip(self::$classMap));
 
100
 
 
101
        if ($mappedName) {
 
102
            return $mappedName;
 
103
        }
 
104
 
 
105
        return false;
 
106
    }
 
107
 
 
108
    /**
 
109
     * Map PHP class names to ActionScript class names
 
110
     *
 
111
     * Allows users to map the class names of there action script classes
 
112
     * to the equivelent php class name. Used in deserialization to load a class
 
113
     * and serialiation to set the class name of the returned object.
 
114
     *
 
115
     * @param  string $asClassName
 
116
     * @param  string $phpClassName
 
117
     * @return void
 
118
     */
 
119
    public static function setMapping($asClassName, $phpClassName)
 
120
    {
 
121
        self::$classMap[$asClassName] = $phpClassName;
 
122
    }
 
123
 
 
124
    /**
 
125
     * Reset type map
 
126
     *
 
127
     * @return void
 
128
     */
 
129
    public static function resetMap()
 
130
    {
 
131
        self::$classMap = self::$_defaultClassMap;
 
132
    }
 
133
}