Hi again,

Thanks for your response. I've put some new comments below.


Marcus Boerger wrote:
Hello Arnold,

  some interesting ideas indeed. See my comments below.

best regards
marcus

Monday, February 26, 2007, 8:48:32 PM, you wrote:

Hi,

I've got a few feature suggestions for SplFileInfo and DirectoryIteratorRecursive. I'm creating yet another php file manager. I've noticed that I needed to add quite some code to make it act the way gnome nautilus does. I believe these feature would be a good addition.

SplFileInfo:
- Add parameter $flags to constructor. The flags are passed to any fileinfo object created.
In case we need flags this will be added to the constructor or as
seperate getter/setter. My preference is actually the latter.
Sure that works just as well, but it would be useful if the flags are passed down. That way you can also use it on a DirectoryIterator.
- Add flags FOLLOW_LINK_ALWAYS, FOLLOW_LINK_EXISTS, FOLLOW_LINK_NEVER for the constructor. Functions as getPerms and getOwner will look at this setting.
I will need to check whether I Can do that. If so I will add flags as well.
Until then you can overwrite hasChildren() to return "parent::hasChildren()
&& !this->isLink()" to solve the third flag. The second flag also needs to
verify the target by using getLinkTarget() (see below). Finally the first
flag is simplywhat we have right now
I believe that there is a bit of miscommunication here. The flags should determine if stat or lstat is used to get the properties of the files. Currently spl always uses stat. Perhaps the names I came up with aren't perfect.
.

 - Add getBasename, to get the basename of either a dir or file.
Did you overlook this? or don't you like it.

 - Function getLinkTarget, does readlink($this->getPathname())
added in HEAD as getLinkTarget()
Perfect
 - Function getRealpath, does realpath($this->getPathname())
added in HEAD as getRealPath()
Excellent
 - Function getOwnerName and getGroupName
Use posix_getpwuid() and posix_getgrgid() *if available*. I prefer not to
have them in SPL.
Ok very well
 - Function isHidden, to check wether a file is hidden
I don't think we have support for windows' hidden flag, do we? Under
*nix as I just reminded you can simply check whether thefilename starts
with a dot.
Yes that true, but it would be nice to have a function which returns a boolean and work for both windows and unix. Perhaps a workaround can be thought off for windows.
 - Functions getTypeInfo and getMime, to get info of the file using libmagic
there are getType and getMTime, that should be enough no?
No the name are almost the same, but the output isn't. I'm talking about integrating the features provided by fileinfo (http://www.php.net/fileinfo). Perhaps the names aren't chosen well.
 - Function setDirInfoClass, set a info class specially for directories
What I could do is providing a slow mechanism that actually does a stat
call and checks the dir flag. Then internally add a pointer for the
directory info class and a getter/setter for that. It would be initialized
to null and thegetter would see the normal info class as long as it is
null. That way the directory info is bound to the standard info class
until you explicitly split it. Would this solve your problem?

Maybe for PHP 5.3 there should be a stat cache tospeeed things up.
Yes that would be perfect.
PS. Currently looping with a DirectoryIterator returns a DirectoryIterator for each child, dirs as well as files, instead of the class set using setInfoClass(). Is this correct? It wasn't what I expected. RecursiveDirectoryIterator work like I expected.
DirectoryIteratorRecursive:
 - Add flag DIRS_ONLY for the constructor, to only loop through directories
This is achieved by a FilterIterator: ParentIterator
Yes but if you want to loop recursively through the directories, creating an object for each file gives a huge overhead. Glob has a directory only flag, may that feature can be used.
 - Add flag WITHOUT_HIDDEN_FILES for the constructor, not to loop
through hidden files
Can be done easily by providing a filter.
Ok that is fine.
 - Function getFileCount
That would require to loop through the directory which is not what we want.
If you need the count after usingthe elements you can for example loop
through a CachingIterator which ha sa newly introduced count method that
will give you the number of elements used.
Isn't there a way you can easily get this information from the system? Anyhow I much rather have a loop in c through a set of filenames, than looping in php using the iterator. I believe having the ability to give the number of files of a directory is really useful, even if you don't want to do anything with the files from the dir. For example: gnome nautilus displays the number files for each dir instead of the filesize.
If you like these features, but don't have time to implement them, I can see if I can write a patch. I'm quite new at writing PHP extensions, but I know the basics.
Thanks again. If you need any help, please let me know.

Best regards,
Arnold

Reply via email to