Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 4, 2025

This PR addresses the inability to set custom network timeouts when using ODataClient->request(). Previously, ODataRequest::__construct() hardcoded the timeout to 0 with no way to override it, and ODataClient->request() directly instantiated and executed the request.

Problem

Users could not configure custom timeouts without overriding the entire ODataClient::request() method, which is cumbersome and error-prone.

Solution

Added a protected createRequest() method to ODataClient that can be overridden in subclasses to customize request creation, including setting custom timeouts.

Changes

  • Added ODataClient::createRequest() - Protected method that creates ODataRequest instances
  • Modified ODataClient::request() - Now uses createRequest() instead of direct instantiation
  • Updated README.md - Added "Advanced Usage" section with custom timeout configuration examples
  • Maintains full backward compatibility - All existing code continues to work unchanged

Usage

class CustomTimeoutODataClient extends ODataClient {
    private $customTimeout;
    
    public function __construct($baseUrl, $authProvider = null, $httpProvider = null, $timeout = 30) {
        parent::__construct($baseUrl, $authProvider, $httpProvider);
        $this->customTimeout = $timeout;
    }
    
    protected function createRequest($method, $requestUri) {
        $request = parent::createRequest($method, $requestUri);
        $request->setTimeout($this->customTimeout);
        return $request;
    }
}

// Usage
$httpProvider = new GuzzleHttpProvider();
$client = new CustomTimeoutODataClient('https://api.example.com/odata', null, $httpProvider, 60);
$result = $client->from('Products')->get(); // Uses 60-second timeout

This approach follows the template method pattern and allows users to customize request creation without having to override the entire request flow.

Fixes #118.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Add option to set timeout Add createRequest method to allow timeout configuration through subclassing Sep 4, 2025
Copilot AI requested a review from anderly September 4, 2025 04:24
@anderly
Copy link
Member

anderly commented Sep 4, 2025

@copilot update the readme to mention usage

Copy link
Contributor Author

Copilot AI commented Sep 4, 2025

@copilot update the readme to mention usage

I've updated the README.md with an "Advanced Usage" section that includes documentation for the custom timeout configuration feature. The section shows how to subclass ODataClient and override the createRequest method to set custom timeouts. Commit: a4ff3ed

@anderly anderly marked this pull request as ready for review September 4, 2025 04:49
@anderly anderly merged commit 3aec0e4 into master Sep 4, 2025
12 checks passed
@anderly anderly deleted the copilot/fix-118 branch September 4, 2025 05:17
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.

Add option to set timeout

2 participants