root/trunk/src/main/php/net/stubbles/service/jsonrpc/stubJsonRpcProcessor.php

Revision 1544, 3.0 kB (checked in by mikey, 1 month ago)

implemented enhancement #141: abstract processor should provide template construction method

Line 
1 <?php
2 /**
3  * JSON-RPC processor (generic proxy for web services).
4  *
5  * @author      Richard Sternagel <richard.sternagel@1und1.de>
6  * @author      Stephan Schmidt <schst@stubbles.net>
7  * @author      Frank Kleine <mikey@stubbles.net>
8  * @package     stubbles
9  * @subpackage  service_jsonrpc
10  */
11 stubClassLoader::load('net::stubbles::lang::stubRegistry',
12                       'net::stubbles::websites::processors::stubAbstractProcessor'
13 );
14 /**
15  * JSON-RPC processor (generic proxy for web services).
16  *
17  * @package     stubbles
18  * @subpackage  service_jsonrpc
19  * @link        http://json-rpc.org/wiki/specification
20  */
21 class stubJsonRpcProcessor extends stubAbstractProcessor
22 {
23     /**
24      * registry key for the service config file
25      */
26     const KEY_SERVICE_FILE = 'net.stubbles.service.jsonrpc.configfile';
27     /**
28      * configuration file with list of client classes
29      *
30      * @var  string
31      */
32     protected $configFile;
33
34     /**
35      * optional template method to do some constructor work in derived classes
36      */
37     protected function doConstruct()
38     {
39         $this->configFile = stubConfig::getConfigPath() . DIRECTORY_SEPARATOR . stubRegistry::getConfig(self::KEY_SERVICE_FILE, 'json-rpc-service.ini');
40     }
41
42     /**
43      * processes the request
44      *
45      * This method only dispatches the request to different subprocessors.
46      */
47     public function process()
48     {
49         $fqClassName = $this->getSubProcessorClassName();
50         $nqClassName = stubClassLoader::getNonQualifiedClassName($fqClassName);
51         if (class_exists($nqClassName, false) === false) {
52             stubClassLoader::load($fqClassName);
53         }
54         
55         $subProcessor = new $nqClassName();
56         $subProcessor->process($this->request, $this->session, $this->response, $this->loadClassMap());
57     }
58
59     /**
60      * loads the class map
61      *
62      * @return  array<string,string>
63      * @throws  stubFileNotFoundException
64      */
65     protected function loadClassMap()
66     {
67         if (file_exists($this->configFile) === false || is_readable($this->configFile) === false) {
68             stubClassLoader::load('net::stubbles::lang::exceptions::stubFileNotFoundException');
69             throw new stubFileNotFoundException($this->configFile);
70         }
71         
72         return parse_ini_file($this->configFile);
73     }
74
75     /**
76      * returns the subprocessor class to be used
77      *
78      * @return  string
79      */
80     protected function getSubProcessorClassName()
81     {
82         if ($this->request->getMethod() === 'post') {
83             return 'net::stubbles::service::jsonrpc::subprocessors::stubJsonRpcPostSubProcessor';
84         } elseif ($this->request->hasValue('__generateProxy') === true) {
85             return 'net::stubbles::service::jsonrpc::subprocessors::stubJsonRpcGenerateProxiesSubProcessor';
86         } elseif ($this->request->hasValue('__smd') === true) {
87             return 'net::stubbles::service::jsonrpc::subprocessors::stubJsonRpcGenerateSmdSubProcessor';
88         }
89
90         return 'net::stubbles::service::jsonrpc::subprocessors::stubJsonRpcGetSubProcessor';
91     }
92 }
93 ?>
Note: See TracBrowser for help on using the browser.