source: trunk/instant_messenger/controller.php @ 151

Revision 151, 1.6 KB checked in by niltonneto, 16 years ago (diff)

Commit da nova versão do módulo, usando agente em C.
Vide Página do módulo do Trac:
http://www.expressolivre.org/dev/wiki/messenger

A versão anterior encontra-se na subpasta bkp (32/64).

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2if ( !$_GET['act'] )
3        echo "controller - #0 : invalid action";
4else
5{
6        #$header = getallheaders();
7        #if ( !$header['ThreadId'] )
8        #       echo "controller - #1 : invalid thread id";
9        #else
10        #{
11                #header('ThreadId: ' . $header['ThreadId']);
12                header('ThreadId: ' . $_GET['act']);
13                list($type, $file, $complement) = explode('.', $_GET['act']);
14                switch ( $type )
15                {
16                        case '$this' :
17                        case '$class' :
18                        case '$obj' :
19                                factory($file, $complement);
20                                break;
21                        case '$file' :
22                        case '$xml' :
23                        case '$js' :
24                        case '$css' :
25                                shop();
26                                break;
27                        default : echo "controller - #2 : invalid type";
28                }
29        #}
30}
31
32exit(0);
33
34function factory($class = false, $method = false)
35{
36        if ( !$class || !$method )
37        {
38                echo "controller - #3 : invalid class or method";
39                return false;
40        }
41
42        # Load dinamically class file.
43        $filename = 'inc/class.'.$class.'.inc.php';
44        if ( !file_exists($filename) )
45        {
46                echo "controller - #4 : class not exists";
47                return false;
48        }
49        require_once $filename;
50
51        # Create new Object  (class loaded).
52        $obj = new $class;
53        # Prepare parameters for execution.
54        $params = array();
55
56        $request_method = $_SERVER['REQUEST_METHOD'];
57        switch ( $request_method )
58        {
59                case 'GET' :
60                        array_shift($_GET);
61                        $params = $_GET;
62                break;
63                case 'POST' :
64                        $params = $_POST;
65                break;
66                case 'HEAD' :
67                case 'PUT' :
68                default :
69                        echo "controller - #5 : request method not avaible";
70                        return false;
71        }
72
73        # if params is not empty, then class method with parameters.
74        if ( $params )
75                $result = $obj -> $method($params);
76        else
77                $result = $obj -> $method();
78
79        printf("%s", $result);
80}
81
82function shop()
83{
84}
85?>
Note: See TracBrowser for help on using the repository browser.