-
Notifications
You must be signed in to change notification settings - Fork 499
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
final attribute on the CURL class breaks caching plugin functionality. #802
Comments
@gnif Thanks for reporting this. To be honest, I don't see anything in the above issue which justifies the need to Is there any particular reason why you are not using a code pattern along the lines of the below ? class cURL_With_Caching
{
private $curl;
public function __construct() {
$this->curl = new WpOrg\Requests\Transport\Curl();
}
public function request($url, $headers = array(), $data = array(), $options = array())
{
// custom caching logic here
// use default logic
return $this->curl->request($url, $headers, $data, $options);
}
} |
I had not considered this however it does seem like a bit of a hack as to remain compatible I would need to implement Edit: Note I am happy with the proposed solution, it just feels backwards to me. |
@gnif An alternative might be to not add a new transport at all, but to hook into Requests via the hooking mechanism ? |
No because the hooking mechanism doesn't allow for overriding and/or preventing the default behaviour of the request. The entire point of this plugin is to use and return a locally cached request if one exists instead of performing an external request again. See: Line 456 in 5a44c92
Line 93 in 5a44c92
|
@gnif I'd like to recommend you this explanation, why you should implement the https://ocramius.github.io/blog/when-to-declare-classes-final/ |
To be frank I feel that all proposed solutions here are not ideal (including mine). Even if I implement the Like I said, I am happy with this solution, but IMO it's still not great. If there is no desire to make any changes as a result of this issue, feel free to close it. I appreciate the effort those have put in here to assist me. |
As a hosting provider that provides tailored WordPress hosting for numerous clients we are often tasked with working around poorly written plugins and/or code that does not cache fetched results from external sources. As such we have developed a plugin that extends the Curl transport with a caching mechanism based on a whitelist of URLs.
As of the update to the 2.0.0 requests library, it is now impossible to do this anymore due to the use of the final keyword on the Curl class.
Here is how we were doing this:
Our class would then override the request method and either inherit the default functionality or respond with a cached value:
Instead we now get the fatal error:
Please remove the final attribute from the Curl class.
The text was updated successfully, but these errors were encountered: