We now have seen enough of the PHP mapping to develop a complete client to access our remote file system. For reference, here is the Slice definition once more:
To exercise the file system, the client does a recursive listing of the file system, starting at the root directory. For each node in the file system, the client shows the name of the node and whether that node is a file or directory. If the node is a file, the client retrieves the contents of the file and prints them.
The program first defines the listRecursive function, which is a helper function to print the contents of the file system, and the main program follows. Let us look at the main program first:
Most of the work happens in listRecursive. The function is passed a proxy to a directory to list, and an indent level. (The indent level increments with each recursive call and allows the code to print the name of each node at an indent level that corresponds to the depth of the tree at that node.)
listRecursive calls the
list operation on the directory and iterates over the returned sequence of nodes:
1. The code uses ice_checkedCast to narrow the
Node proxy to a
Directory proxy, and uses
ice_uncheckedCast to narrow the
Node proxy to a
File proxy. Exactly one of those casts will succeed, so there is no need to call
ice_checkedCast twice: if the
Node is‑a Directory, the code uses the proxy returned by
ice_checkedCast; if
ice_checkedCast fails, we
know that the Node
is‑a File and, therefore,
ice_uncheckedCast is sufficient to get a
File proxy.