-
Notifications
You must be signed in to change notification settings - Fork 20
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
Extend File System Class #215
base: main
Are you sure you want to change the base?
Conversation
@costdev Can you take a look here before I go too far and see if there are any issues with this approach. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the ping @namithj! I don't see any immediate issues.
I understand the desire to extend WP_Filesystem_Direct
as this is indeed extending the underlying functionality, and there's no need to, for example, repeat the contents of WP_Filesystem_Direct::chmod()
elsewhere. I think it's fine to keep going.
What other methods do you intend to introduce to this class?
I will be overriding the get_contents_array function to introduce a two new parameters (no of lines to read and read direction) which will let us read from bottom up and also modify it to read via file pointer and iterate over the required no of lines instead of pulling the whole content into memory as it does now. |
The Read Routine
PHP Doc Alignment
I will try and push the changes today so that we can merge this in |
Code review suggestions
Signed-off-by: Namith Jawahar <[email protected]>
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php'; | ||
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php'; | ||
WP_Filesystem(); | ||
return new Filesystem_Direct( false ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means that after calling $wp_filesystem = self::init_filesystem()
, $wp_filesystem
will always be truthy (objects are always truthy). The if ( ! $wp_filesystem )
condition in Debug::verify_filesystem()
will never pass in this circumstance and the method will always return true
.
Therefore, we can likely remove Debug::verify_filesystem()
altogether since it's a private
method, and self::init_filesystem()
is called in all methods that call self::verify_filesystem()
.
} | ||
return $content; | ||
|
||
return $file_content; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can now change the @return
annotation in the docblock to:
@return array|WP_Error An array of lines in the file, limited to $limit, or a WP_Error object on failure.
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php'; | ||
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php'; | ||
WP_Filesystem(); | ||
return new Filesystem_Direct( false ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, we can store the filesystem object to a static property to avoid re-running WP_Filesystem()
and creating a new object each time.
/**
* The filesystem.
*
* @var Filesystem_Direct
*/
private static $filesystem;
// init_filesystem()
if ( ! self::$filesystem instanceof Filesystem_Direct ) {
require_once ABSPATH . 'wp-admin/includes/file.php';
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php';
require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php';
WP_Filesystem();
self::$filesystem = new Filesystem_Direct( false );
}
return self::$filesystem;
@@ -31,23 +31,20 @@ private static function get_file_path() { | |||
/** | |||
* Initializes the WordPress Filesystem. | |||
* | |||
* @return WP_Filesystem_Base|false The filesystem object or false on failure. | |||
* @return WP_Filesystem_Direct|false The filesystem object or false on failure. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @return WP_Filesystem_Direct|false The filesystem object or false on failure. | |
* @return Filesystem_Direct The filesystem object. |
We don't use the WP_
prefix for the class name, and the method can't return false
.
* | ||
* @since 2.5.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* | |
* @since 2.5.0 |
Not applicable to AspireUpdate.
Extend File System Class
Pull Request
What changed?
(Please list the changes you made...)
Why did it change?
(Please list the reasons you made the changes...)
Did you fix any specific issues?
(Please tag any specific issues here...)
CERTIFICATION
By opening this pull request, I do agree to abide by the Code of Conduct and be bound by the terms of the Contribution Guidelines in effect on the date and time of my contribution as proven by the revision information in GitHub.