- What's new
- Installing Remoting components
- Installing AMFPHP
- Testing AMFPHP
- 10,000 foot view of Remoting
- Creating Remoting methods
- Method table reference
- Helper classes
- Class mapping
- Sending recordsets
- Manual recordsets
- Pageable recordsets
- Consuming web services (SOAP)
- Other platforms
- The service browser
- Debugging primer
- NetConnection debugger
- Debugging proxies
- NetDebug::trace and exceptions
- Common confusing errors
The NetDebug class
The NetDebug class is a class loaded for all services and methods that contains a single static method: trace. You use it as follows:
When invoking this class from a method, it will create a new header in the returned AMF data containing the “Hello World!” string. You will see this trace in the NetConnection debugger. The method also accepts objects, arrays, and even resultsets. Please note that unlike local calls to trace, remote trace calls take up bandwidth when sent and server CPU time when serialized; therefore you should call $this->disableTraces() in gateway.php when deploying.
The Authenticate class
The Authenticate class is available to every method in your services and allows to perform authentication checks and operations on logging.
There are several methods available for the Authenticate class:
$bool = Authenticate::isAuthenticated(); $bool = Authenticate::getAuthUser(); $bool = Authenticate::isUserInRole($roles); $bool = Authenticate::login($name, $roles); $bool = Authenticate::logout();
For most practical purposes, the most useful will be the logout method, which will logout the user. Do remember that Flash may still send a credentials header that will log the user in again against your will; use setCredentials(null, null) back in Flash to solve the issue.
isUserAuthenticated checks if the user is currently logged in, regardless of whether the method itself is protected or not. getAuthUser will retrieve the logged in user’s username. isUserInRole will check the current logged in user against a comma-separated list of roles. login can be used to login a user manually, although you should really leave this to AMFPHP itself unless you know what you’re doing.
The DateWrapper class
The DateWrapper class was created as a means to alleviate the pain of using Flash dates as input to your functions. Flash dates are mapped to Unix timestamps multiplied by 1000; in addition, no timezone information is available in these dates, which can cause errors especially if you are using the DateChooser component.
The DateWrapper class is therefore included by default for use by any of your services. You use it as follows:
$dw = new DateWrapper($flashDate); $dw->getClientDate(); $dw->getServerDate(); $dw->getRawDate(); $dw->getTimezone();
Note that the returned dates from getClientDate and getServerDate should only be used with gmdate, as they are formatted according to Greenwich time. The timezone that is used is a global variable that is created before hand during unserialization; it is always the timezone in the last date encountered during unserialization. Therefore please be aware that the class may not work properly if you send several dates with different timezones during the same method call (why you would want to do that is beyond us).
Say that your client is in New York, and your server is in California. He sends a date of noon on January 15th. Therefore getClientDate will return noon, and getServerDate will return 9:00 in the morning. You can easily see that you might need one or the other or both of these times depending on the context.