Creating Wrappers
You
can write custom wrappers in PHP. This lets you extend PHP to
“speak” any protocol you want while
still letting you use the standard stream functions, such as
file_get_contents( )
.
Stream wrappers are implemented as a class with specific methods. These methods are called by the stream-handling code when a stream using your wrapper is opened, read from, written to, and so forth.
In all, there are 17 potential methods that make up a complete wrapper, but it’s rare to actually code all of these. Table 8-2 contains a list of wrapper methods and when they’re evoked.
Table 8-2. Wrapper methods
Method |
Function |
PHP 5 only? |
---|---|---|
|
|
No |
|
|
No |
|
|
No |
|
|
No |
|
|
No |
|
|
No |
|
|
No |
|
|
No |
|
|
No |
|
|
Yes |
|
|
Yes |
|
|
Yes |
|
|
No |
|
|
No |
|
|
No |
Get Upgrading to PHP 5 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.