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 |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access