Pro PHP- Patterns, Frameworks, Testing and More

(vip2019) #1
CHAPTER 11 ■ SPL FILE AND DIRECTORY HANDLING^165

array (
'path' => '/path/to/file',
'filename' => 'filename.php',
'pathname' => '/path/to/file/filename.php',
'perms' => 33261,
'inode' => 886570,
'size' => 1131,
'owner' => 1002,
'group' => 1002,
'atime' => 1167067832,
'mtime' => 1167067771,
'ctime' => 1167067771,
'type' => 'file',
'isWritable' => true,
'isReadable' => true,
'isExecutable' => true,
'isFile' => true,
'isDir' => false,
'isLink' => false,
)

Using SPLFileInfo is pretty straightforward. Do be aware that if you do not provide a path
and file name, then the pathname and path properties will omit the path. The path value is the
same as calling dirname() on the construction parameter, and the pathname value is just a copy of
the input parameter.

■Note The perms mask can be decoded in standard bitwise manner. If you are unfamiliar with this,
you can review an example in the fileperms() function documentation in the PHP manual, at http://
http://www.php.net/fileperms.

The SPLFileInfo class supports extension through its provision of two key methods:

setInfoClass: This defaults to SPLFileInfo. If you extend the SPLFileInfo class, you will
want to set this value to the name of your extended class.

setFileClass: This defaults to an SPLFileObject class. If you extend this class, you should set
this value to ensure that your extended class is what is provided by consumers of SPLFileInfo.

McArthur_819-9C11.fm Page 165 Thursday, February 28, 2008 7:49 AM

Free download pdf