Zend Framework: Zend_Path Component Proposal
| Proposed Component Name | Zend_Path |
|---|---|
| Developer Notes | http://framework.zend.com/wiki/display/ZFDEV/Zend_Path |
| Proposers | Stefan Gehrig Matthew Weier O'Phinney (Zend Liaison) |
| Revision | 0.1 - 29 March 2008: opened proposal. 0.1.1 - 3 April 2008: Changed layout to use decks. 0.2 - 13 April 2008: Added methods to handle include path. 0.3 - 15 April 2008: Added object oriented approach propsed by Thomas Fritz 0.4 - 5 July 2008: Changed repository location (wiki revision: 22) |
Table of Contents
1. Overview
Zend_Path is a collection of helper methods to improve file and path handling regardless of the underlying operating system (Windows or Unix-based). It mimics the interface of the .NET System.IO.Path static class.
2. References
- PHP Manual Filesystem Functions
- .NET Framework Class Library Path Class (System.IO.Path)
- Method to mimic sys_get_temp_dir()
3. Component Requirements, Constraints, and Acceptance Criteria
- This component will provide system-independent path constants such as directory Separator, path separator and volume separator.
- This component will provide an easy method to change a file extension.
- This component will provide an easy method to combine two or more paths or a path and a file.
- This component will be able to extract the directory name from a path.
- This component will be able to extract the file extension from a path. The "extension" in the context of this proposal is defined as the part after the last period of the filename.
- This component will be able to extract the file name from a path.
- This component will be able to extract the file name without extension from a path.
- This component will be able to retrieve the root path for a given path.
- This component will be able to determine the system's temp path.
- This component will be able to normalize a path (resolving '..' - like realpath() does) even on paths that do not currently exist on the filesystem.
- This component will provide convenience methods to work with the PHP include path.
4. Dependencies on Other Framework Components
none
5. Theory of Operation
The component simply provides static methods which can be called whenever appropriate.
6. Milestones / Tasks
- Milestone 1: [DONE] Write initial proposal
- Milestone 2: [CURRENT] Review by community
- Milestone 3: [DONE] Checked in at http://svn2.assembla.com/svn/zf-proposals/trunk
- Milestone 4: Review by Zend
- Milestone 5: Component incubated
- Milestone 6: [DONE] Write unit tests
- Milestone 7: Write documentation
- Milestone 8: Component cored
7. Class Index
- Zend_Path
- Zend_Path_Item
8. Use Cases
9. Class Skeletons
I'd really like to see this in core. Maybe some functions can be added to search files in a path and function to help construct include paths:
Maybe a good thing to note somewhere: What is an extention? Is it the part after the last or the first period?
Hi Vincent,
good question about the definition of the "extension". In my opinion it should be the part after the last period. That's the way windows handles this (e.g. the extension of "my.word.document.docx" is "docx").
I added you proposed methods regarding the include paths to the proposal. Thanks a lot.
Hi Stefan!
I'd also like to see this in core.
And as Vincent noted, some methods would be nice to add. Like the Search methods if path is an directory.
A method which can be used to check if a given path is within a defined 'root path'.
I would also allow to instantiate a new instance of Zend_Path like Zend_Uri.
So you can:
Hi Thomas,
Thanks a lot for your comment.
I added you ideas to the proposal:
- Zend_Path::isWithinPath() to check if a given path is located within a defined root path.
- Zend_Path:factory() and the accompanying Zend_Path_Item class that represents a single filesystem item. The Zend_Path_Item simple proxies all calls to the static Zend_Path-methods.
Regarding your proposal about addRegex() or allowing the addition of validators to a path-object, I actually have to admint that I don't know what you want this to do. Do you want a path validation function? If so, I'd think that a method name validate() would be more catchy.
Best regards
Stefan
Checked in at SVN url http://svn2.assembla.com/svn/zf-proposals/Zend_Path/trunk.
Changend SVN url to http://svn2.assembla.com/svn/zf-proposals/trunk
I was looking for exactly this, so I've checked-out your SVN.
This looks very very promising ![]()
I hope it gets in the core fast! I will start using it from now
But I think there's a small bug in:
- Path.php 23 2008-07-05 08:57:19Z sgehrig
Because the idea of this class is to unify all paths to the forwards slashes, right?
While the following will replace all '/' for the OS specific directory separator:
So I think this should be like:
Thanks
Hi Patrick,
I hope the code keeps what it promises ![]()
Regarding your "bug":
Actually it was my idea to normalize directory separators to its system specfic default, which means a forward slash on all non-Windows-OSs and the backslash on Windows-OSs. Personally I'd have no problem to normalize everything to forward slashes but I have no experience if this'd induce some side-effects or even problems on Windows-OSs.
Are there any problems when normalizing to the system-specific directory separator?
Best regards
Stefan
> Actually it was my idea to normalize directory separators to its system specfic default
Sounds good, but then the current _normalizeDirectorySeparators function does not meet the goal. Because now you only replace the '/' with the OS-specific separator, but to completely meet the goal you should replace the '\' and '/' to a OS-specific separator.
I always set all my paths in config-files based on the *nix directory separator ('/'), but when running on Windows there often the '/' and '\' are combined in one path because I use something like
To get this working I think the _normalizeDirectorySeparators function should be something like this:
I'll try and do some more tests this weekend ![]()
Hi Patrick,
you're right... I changed the method to your proposed code.
Are you using the component on a Windows system? I'm asking because I haven't tested Zend_Path on *nix-based systems yet.
Best regards
Stefan
2 more comments by: Goran Juric, Stefan Gehrig
| Zend Rejection The Zend team is rejecting this proposal at this time. In almost every case, the methods proposed are wrappers for existing PHP function calls and/or constants, and are more verbose. In a few cases, they wrap multiple function calls, bringing added value, but we do not feel these cases justify the creation of the class. There are several methods, however, that we would like to add to Zend_Loader:
|
ZF Home Page
Code Browser
Wiki Dashboard
I like this proposal, it makes some stuff quite easier. On most systems you have to struggle with the tmp_filename functions. A common ways is always good there. I'd like to see this component moving to the core.