Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helpers refactoring #1416

Merged
merged 3 commits into from
Dec 4, 2013
Merged

Helpers refactoring #1416

merged 3 commits into from
Dec 4, 2013

Conversation

samdark
Copy link
Member

@samdark samdark commented Dec 4, 2013

Moved file and path related methods from StringHelper to FileHelper, renamed StringHelper byte methods not to be misused as string methods

…renamed StringHelper byte methods not to be misused as string methods
@qiangxue
Copy link
Member

qiangxue commented Dec 4, 2013

I think we should keep basename and dirname in StringHelper. They are about string manipulation, not file system manipulation. They are often used for strings not related with file paths. We have discussed about this before.

@samdark
Copy link
Member Author

samdark commented Dec 4, 2013

I've got at least three people complaining about FS-related stuff is in StringHelper and I feel bad about these methods being in this helper as well. Maybe another helper called "path" or something?

@@ -26,7 +26,7 @@ class BaseStringHelper
* @param string $string the string being measured for length
* @return integer the number of bytes in the given string.
*/
public static function strlen($string)
public static function byteLen($string)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest naming it as byteLength(). We always use full words in names other than those inherited from existing PHP function names.

@qiangxue
Copy link
Member

qiangxue commented Dec 4, 2013

The functions are provided really just for string manipulation. As you can see, they are used to extract part of the string from class names, etc., which has nothing to do with file systems. I don't think we should create a new class to hold them. The class FileHelper only deals with file systems.

@armpogart
Copy link

I often use basename for string manipulation that has nothing to do with files directly. So it's not very logical to place it in FileHelper. Though in native PHP it is in Filesystem functions, so the first place to search for that function is File related class.

@egorpromo
Copy link
Contributor

I think basename() and dirname() should be in Yii class. They are special functions and could be both in StringHelper and in FileHelper at the same time.

qiangxue added a commit that referenced this pull request Dec 4, 2013
@qiangxue qiangxue merged commit 4df9b6c into master Dec 4, 2013
@qiangxue qiangxue deleted the helpers-renames branch December 4, 2013 19:09
@mikehaertl
Copy link
Contributor

I have to second this: I'd never have expected these methods in StringHelper. Even if it's only string manipulation: The manipulation performed is clearly filesystem related.

Following this logic, the dirname() method from PHP would also be in the string section of the PHP manual instead of the filesystem section, as it's also just performing some string manipulation. This is not the case.

@klimov-paul
Copy link
Member

StringHelper::dirname and StringHelper::basename are served for the namespace manipulation mainly.

@cebe
Copy link
Member

cebe commented Apr 1, 2014

@mikehaertl for file system you can use the PHP functions basename() and dirname(). The helper is there because the PHP functions do not work on namespaces.

@mikehaertl
Copy link
Contributor

I understand that. Still I don't really see these methods as generic string related methods. So StringHelper really feels wrong. A class like yii\helpers\Namespace would be way more clean IMO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants