The proxy file will place within your application so that it can access your session data to determine the client’s ID. At current stage, the proxy only supports PHP application.
By default, there a file called proxy.php which already extended the proxy class (Jsrs_Proxy_Abstract) with the class name, “Standard”. The only function you need to override is the “_getClient” function.
You can determine by using your session data:
The function is accessing the session data and determines the user’s type. Of course, this might different depends on your application. The function must return either the full class name or the client object itself. The client object must be child class from Jsrs_Proxy_Client_Abstract. Read on the next section on defining user’s type.
You can override the default property that defined in the Jsrs_Proxy_Abstract class too:
If your JsRS server was hosted in another server, you might want to replace it with the IP address or the host name. You can change the listening port number if your server is listening at different port number. The $_defaultPermissive is to determine whether a message should be rejecting if the permission function was not defined (eg: sfPlus, cfSayHello). If you set to “denied”, means any server or client remote function that without defining the permission control function, will be rejected. By default, this value is “allowed”.
You might need to define the types of user that connected to your live application. By defining the user’s type, you can set the permission of each function for each type of user. By default, the “Standard” user class was defined for you. You must define at least 1 user type in order to run JsRS. For instance you wished to define a member user type:
You should save this class file as Member.php under /proxy/client/. This proxy will prevent the Member type of user to call a remote function name “redirect”. Note the prefix in front of the function. “cf” is refer to client function, while “sf” is refer to server function. The users with Member type are NOT able to call the server function “plus” too. Any non-false value returned will allowed the message being pass through the proxy and send to the server. Throwing an exception will caused the message being reject:
Throwing the proxy exception (Jsrs_Proxy_Exception) will invoke the exception handler in the client (exceptionHandler). You can throw any other exception object such as RuntimeException or Exception, these exceptional objects will NOT invoke the exceptionHandler function in the client script.
Beside of controlling the remote function, you can control the event received too:
Note: For those functions that did not defined in your client class, by default, the message will be received or sent through. You can change this behavior by overriding the default value of $_defaultPermissive to “denied” in the Jsrs_Proxy_Abstract class.
The Helper class is to reduce the needs of extending your client class in order to perform some custom functionality. Most of the time, you might focus on the client class file (Jsrs_Proxy_Client_Class). For some client remote function, you might want to check the permission based on the MySQL database. Building the database connection on each client class is very troublesome neither extending your client class is a good idea too. What the Helper class can offer you is to allow you to define a class that access to the MySQL database and call it from your client class like this:
You can use this helper “IsAdmin” on any client class with the same statement. Please be careful with the helper name, the first character must be capital letter and the name must be exactly same as the Helper class file.
The $_helper object is defined in the Jsrs_Proxy_Client_Abstract. You don’t have to worry about it. Just call it directly to get your result.
By default, there is one helper class, “ServerBroker”. You can use this to invoke any server’s function without connecting to the server. The result returned is in array format. To call the function, you need at least one parameter which is the server’s function name. The second parameter has to be an array which represents your parameter. The parameter array can be an associative array. Example:
To make a server function call, do this:
The $result will return you an associative array with this value:
Notice on how the parameter being passed. You have to put all the value in the array and pass the array in the second parameter of the Helper class.
You must place your Helper class under /Proxy/Helper and your Helper class must inherit from Jsrs_Proxy_Helper_Abstract. You have to override the “run” method in order to perform your custom task. The “run” function is the default function when calling a Helper class:
For instance you want to define a MySQL database accessing Helper, you created a Helper class file named Jsrs_Proxy_Helper_IsAdmin.php in /Proxy/Helper:
You can always extends your Helper class. For example you have few Helper class that needs to access to MySQL database, you can create a MySQL Helper class that will automatically connect to the database once the Helper class was called. Then you will extends those Helper that needs to access the database from this parent class.