{"action":"created","comment":{"url":"https://api.github.com/repos/mongodb/mongo-php-library/pulls/comments/168912104","pull_request_review_id":97364928,"id":168912104,"diff_hunk":"@@ -29,33 +31,66 @@\n  */\n class Explain implements Executable\n {\n-\n     const VERBOSITY_ALL_PLANS = 'allPlansExecution';\n     const VERBOSITY_EXEC_STATS = 'executionStats';\n     const VERBOSITY_QUERY = 'queryPlanner';\n \n+    private static $wireVersionForExplain = 2;\n+    private static $wireVersionForDistinct = 4;\n+    private static $wireVersionForFindAndModify = 4;\n+\n     private $databaseName;\n     private $explainable;\n     private $options;\n \n-    /* The Explainable knows what collection it targets, so we only need\n-     * a database to run `explain` on. Alternatively, we might decide to also\n-     * pull the database from Explainable somehow, since all Operations we\n-     * might explain also require a database name.\n+    /**\n+     * Constructs an explain command for explainable operations.\n+     *\n+     * Supported options:\n+     *\n+     *  * verbosity (string): The mode in which the explain command will be run.\n      *\n-     * Options will at least be verbosity (the only documented explain option)\n-     * and typeMap, which we can apply to the cursor before the execute()\n-     * method returns current($cursor->toArray()) or $cursor->toArray()[0]\n-     * (both are equivalent). */\n+     *  * typeMap (array): Type map for BSON deserialization. This will be used\n+     *    used for the returned command result document.\n+     *\n+     * @param string $databaseName      Database name\n+     * @param Explainable $explainable  Operation to explain\n+     * @param array  $options           Command options\n+     * @throws InvalidArgumentException for parameter/option parsing errors\n+     */\n     public function __construct($databaseName, Explainable $explainable, array $options = [])\n     {\n+        if (isset($options['verbosity']) && ! is_string($options['verbosity'])) {\n+            throw InvalidArgumentException::invalidType('\"verbosity\" option', $options['verbosity'], 'string');\n+        }\n+\n+        if (isset($options['typeMap']) && ! is_array($options['typeMap'])) {\n+            throw InvalidArgumentException::invalidType('\"typeMap\" option', $options['typeMap'], 'array');\n+        }\n+\n         $this->databaseName = $databaseName;\n         $this->explainable = $explainable;\n         $this->options = $options;\n     }\n \n     public function execute(Server $server)\n     {\n+        if (! \\MongoDB\\server_supports_feature($server, self::$wireVersionForExplain)) {\n+            throw UnsupportedException::explainNotSupported();\n+        }\n+\n+        if ($this->explainable instanceOf \\MongoDB\\Operation\\Distinct) {\n+            if (! \\MongoDB\\server_supports_feature($server, self::$wireVersionForDistinct)) {\n+                throw UnsupportedException::explainNotSupported();\n+            }\n+        }\n+\n+        if ($this->explainable instanceOf \\MongoDB\\Operation\\FindAndModify) {\n+            if (! \\MongoDB\\server_supports_feature($server, self::$wireVersionForFindAndModify)) {","path":"src/Operation/Explain.php","position":90,"original_position":77,"commit_id":"ac082beca33317fe6fab05ac03d3f6a691b286e4","original_commit_id":"9474b75055758ca1cade6aced1f6353877bab70b","user":{"login":"jmikola","id":244663,"avatar_url":"https://avatars3.githubusercontent.com/u/244663?v=4","gravatar_id":"","url":"https://api.github.com/users/jmikola","html_url":"https://github.com/jmikola","followers_url":"https://api.github.com/users/jmikola/followers","following_url":"https://api.github.com/users/jmikola/following{/other_user}","gists_url":"https://api.github.com/users/jmikola/gists{/gist_id}","starred_url":"https://api.github.com/users/jmikola/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmikola/subscriptions","organizations_url":"https://api.github.com/users/jmikola/orgs","repos_url":"https://api.github.com/users/jmikola/repos","events_url":"https://api.github.com/users/jmikola/events{/privacy}","received_events_url":"https://api.github.com/users/jmikola/received_events","type":"User","site_admin":false},"body":"These can easily be combined into a single condition with `&&`. It'd only make sense to keep them separate if we expected to do other things for FindAndModify instances apart from the wire version check.","created_at":"2018-02-17T04:32:09Z","updated_at":"2018-02-17T04:52:38Z","html_url":"https://github.com/mongodb/mongo-php-library/pull/497#discussion_r168912104","pull_request_url":"https://api.github.com/repos/mongodb/mongo-php-library/pulls/497","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/mongodb/mongo-php-library/pulls/comments/168912104"},"html":{"href":"https://github.com/mongodb/mongo-php-library/pull/497#discussion_r168912104"},"pull_request":{"href":"https://api.github.com/repos/mongodb/mongo-php-library/pulls/497"}}},"pull_request":{"url":"https://api.github.com/repos/mongodb/mongo-php-library/pulls/497","id":169248089,"html_url":"https://github.com/mongodb/mongo-php-library/pull/497","diff_url":"https://github.com/mongodb/mongo-php-library/pull/497.diff","patch_url":"https://github.com/mongodb/mongo-php-library/pull/497.patch","issue_url":"https://api.github.com/repos/mongodb/mongo-php-library/issues/497","number":497,"state":"open","locked":false,"title":"PHPLIB-156: Create methods for explain on Find and Count","user":{"login":"kvwalker","id":7121013,"avatar_url":"https://avatars3.githubusercontent.com/u/7121013?v=4","gravatar_id":"","url":"https://api.github.com/users/kvwalker","html_url":"https://github.com/kvwalker","followers_url":"https://api.github.com/users/kvwalker/followers","following_url":"https://api.github.com/users/kvwalker/following{/other_user}","gists_url":"https://api.github.com/users/kvwalker/gists{/gist_id}","starred_url":"https://api.github.com/users/kvwalker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kvwalker/subscriptions","organizations_url":"https://api.github.com/users/kvwalker/orgs","repos_url":"https://api.github.com/users/kvwalker/repos","events_url":"https://api.github.com/users/kvwalker/events{/privacy}","received_events_url":"https://api.github.com/users/kvwalker/received_events","type":"User","site_admin":false},"body":"https://jira.mongodb.org/browse/PHPLIB-156","created_at":"2018-02-14T23:13:10Z","updated_at":"2018-02-17T04:52:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4c9d91ca11803df9edd6ad4fc3b7ed111a8740cf","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/mongodb/mongo-php-library/pulls/497/commits","review_comments_url":"https://api.github.com/repos/mongodb/mongo-php-library/pulls/497/comments","review_comment_url":"https://api.github.com/repos/mongodb/mongo-php-library/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mongodb/mongo-php-library/issues/497/comments","statuses_url":"https://api.github.com/repos/mongodb/mongo-php-library/statuses/ac082beca33317fe6fab05ac03d3f6a691b286e4","head":{"label":"kvwalker:PHPLIB-156","ref":"PHPLIB-156","sha":"ac082beca33317fe6fab05ac03d3f6a691b286e4","user":{"login":"kvwalker","id":7121013,"avatar_url":"https://avatars3.githubusercontent.com/u/7121013?v=4","gravatar_id":"","url":"https://api.github.com/users/kvwalker","html_url":"https://github.com/kvwalker","followers_url":"https://api.github.com/users/kvwalker/followers","following_url":"https://api.github.com/users/kvwalker/following{/other_user}","gists_url":"https://api.github.com/users/kvwalker/gists{/gist_id}","starred_url":"https://api.github.com/users/kvwalker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kvwalker/subscriptions","organizations_url":"https://api.github.com/users/kvwalker/orgs","repos_url":"https://api.github.com/users/kvwalker/repos","events_url":"https://api.github.com/users/kvwalker/events{/privacy}","received_events_url":"https://api.github.com/users/kvwalker/received_events","type":"User","site_admin":false},"repo":{"id":107586508,"name":"mongo-php-library","full_name":"kvwalker/mongo-php-library","owner":{"login":"kvwalker","id":7121013,"avatar_url":"https://avatars3.githubusercontent.com/u/7121013?v=4","gravatar_id":"","url":"https://api.github.com/users/kvwalker","html_url":"https://github.com/kvwalker","followers_url":"https://api.github.com/users/kvwalker/followers","following_url":"https://api.github.com/users/kvwalker/following{/other_user}","gists_url":"https://api.github.com/users/kvwalker/gists{/gist_id}","starred_url":"https://api.github.com/users/kvwalker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kvwalker/subscriptions","organizations_url":"https://api.github.com/users/kvwalker/orgs","repos_url":"https://api.github.com/users/kvwalker/repos","events_url":"https://api.github.com/users/kvwalker/events{/privacy}","received_events_url":"https://api.github.com/users/kvwalker/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kvwalker/mongo-php-library","description":"MongoDB PHP library","fork":true,"url":"https://api.github.com/repos/kvwalker/mongo-php-library","forks_url":"https://api.github.com/repos/kvwalker/mongo-php-library/forks","keys_url":"https://api.github.com/repos/kvwalker/mongo-php-library/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kvwalker/mongo-php-library/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kvwalker/mongo-php-library/teams","hooks_url":"https://api.github.com/repos/kvwalker/mongo-php-library/hooks","issue_events_url":"https://api.github.com/repos/kvwalker/mongo-php-library/issues/events{/number}","events_url":"https://api.github.com/repos/kvwalker/mongo-php-library/events","assignees_url":"https://api.github.com/repos/kvwalker/mongo-php-library/assignees{/user}","branches_url":"https://api.github.com/repos/kvwalker/mongo-php-library/branches{/branch}","tags_url":"https://api.github.com/repos/kvwalker/mongo-php-library/tags","blobs_url":"https://api.github.com/repos/kvwalker/mongo-php-library/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kvwalker/mongo-php-library/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kvwalker/mongo-php-library/git/refs{/sha}","trees_url":"https://api.github.com/repos/kvwalker/mongo-php-library/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kvwalker/mongo-php-library/statuses/{sha}","languages_url":"https://api.github.com/repos/kvwalker/mongo-php-library/languages","stargazers_url":"https://api.github.com/repos/kvwalker/mongo-php-library/stargazers","contributors_url":"https://api.github.com/repos/kvwalker/mongo-php-library/contributors","subscribers_url":"https://api.github.com/repos/kvwalker/mongo-php-library/subscribers","subscription_url":"https://api.github.com/repos/kvwalker/mongo-php-library/subscription","commits_url":"https://api.github.com/repos/kvwalker/mongo-php-library/commits{/sha}","git_commits_url":"https://api.github.com/repos/kvwalker/mongo-php-library/git/commits{/sha}","comments_url":"https://api.github.com/repos/kvwalker/mongo-php-library/comments{/number}","issue_comment_url":"https://api.github.com/repos/kvwalker/mongo-php-library/issues/comments{/number}","contents_url":"https://api.github.com/repos/kvwalker/mongo-php-library/contents/{+path}","compare_url":"https://api.github.com/repos/kvwalker/mongo-php-library/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kvwalker/mongo-php-library/merges","archive_url":"https://api.github.com/repos/kvwalker/mongo-php-library/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kvwalker/mongo-php-library/downloads","issues_url":"https://api.github.com/repos/kvwalker/mongo-php-library/issues{/number}","pulls_url":"https://api.github.com/repos/kvwalker/mongo-php-library/pulls{/number}","milestones_url":"https://api.github.com/repos/kvwalker/mongo-php-library/milestones{/number}","notifications_url":"https://api.github.com/repos/kvwalker/mongo-php-library/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kvwalker/mongo-php-library/labels{/name}","releases_url":"https://api.github.com/repos/kvwalker/mongo-php-library/releases{/id}","deployments_url":"https://api.github.com/repos/kvwalker/mongo-php-library/deployments","created_at":"2017-10-19T18:58:56Z","updated_at":"2017-10-19T18:58:58Z","pushed_at":"2018-02-16T21:44:20Z","git_url":"git://github.com/kvwalker/mongo-php-library.git","ssh_url":"git@github.com:kvwalker/mongo-php-library.git","clone_url":"https://github.com/kvwalker/mongo-php-library.git","svn_url":"https://github.com/kvwalker/mongo-php-library","homepage":"https://docs.mongodb.com/php-library/","size":1642,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"mongodb:master","ref":"master","sha":"966511c8c5a26087dfff0881d907f390ef0b93e8","user":{"login":"mongodb","id":45120,"avatar_url":"https://avatars1.githubusercontent.com/u/45120?v=4","gravatar_id":"","url":"https://api.github.com/users/mongodb","html_url":"https://github.com/mongodb","followers_url":"https://api.github.com/users/mongodb/followers","following_url":"https://api.github.com/users/mongodb/following{/other_user}","gists_url":"https://api.github.com/users/mongodb/gists{/gist_id}","starred_url":"https://api.github.com/users/mongodb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mongodb/subscriptions","organizations_url":"https://api.github.com/users/mongodb/orgs","repos_url":"https://api.github.com/users/mongodb/repos","events_url":"https://api.github.com/users/mongodb/events{/privacy}","received_events_url":"https://api.github.com/users/mongodb/received_events","type":"Organization","site_admin":false},"repo":{"id":27557391,"name":"mongo-php-library","full_name":"mongodb/mongo-php-library","owner":{"login":"mongodb","id":45120,"avatar_url":"https://avatars1.githubusercontent.com/u/45120?v=4","gravatar_id":"","url":"https://api.github.com/users/mongodb","html_url":"https://github.com/mongodb","followers_url":"https://api.github.com/users/mongodb/followers","following_url":"https://api.github.com/users/mongodb/following{/other_user}","gists_url":"https://api.github.com/users/mongodb/gists{/gist_id}","starred_url":"https://api.github.com/users/mongodb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mongodb/subscriptions","organizations_url":"https://api.github.com/users/mongodb/orgs","repos_url":"https://api.github.com/users/mongodb/repos","events_url":"https://api.github.com/users/mongodb/events{/privacy}","received_events_url":"https://api.github.com/users/mongodb/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mongodb/mongo-php-library","description":"MongoDB PHP library","fork":false,"url":"https://api.github.com/repos/mongodb/mongo-php-library","forks_url":"https://api.github.com/repos/mongodb/mongo-php-library/forks","keys_url":"https://api.github.com/repos/mongodb/mongo-php-library/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mongodb/mongo-php-library/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mongodb/mongo-php-library/teams","hooks_url":"https://api.github.com/repos/mongodb/mongo-php-library/hooks","issue_events_url":"https://api.github.com/repos/mongodb/mongo-php-library/issues/events{/number}","events_url":"https://api.github.com/repos/mongodb/mongo-php-library/events","assignees_url":"https://api.github.com/repos/mongodb/mongo-php-library/assignees{/user}","branches_url":"https://api.github.com/repos/mongodb/mongo-php-library/branches{/branch}","tags_url":"https://api.github.com/repos/mongodb/mongo-php-library/tags","blobs_url":"https://api.github.com/repos/mongodb/mongo-php-library/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mongodb/mongo-php-library/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mongodb/mongo-php-library/git/refs{/sha}","trees_url":"https://api.github.com/repos/mongodb/mongo-php-library/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mongodb/mongo-php-library/statuses/{sha}","languages_url":"https://api.github.com/repos/mongodb/mongo-php-library/languages","stargazers_url":"https://api.github.com/repos/mongodb/mongo-php-library/stargazers","contributors_url":"https://api.github.com/repos/mongodb/mongo-php-library/contributors","subscribers_url":"https://api.github.com/repos/mongodb/mongo-php-library/subscribers","subscription_url":"https://api.github.com/repos/mongodb/mongo-php-library/subscription","commits_url":"https://api.github.com/repos/mongodb/mongo-php-library/commits{/sha}","git_commits_url":"https://api.github.com/repos/mongodb/mongo-php-library/git/commits{/sha}","comments_url":"https://api.github.com/repos/mongodb/mongo-php-library/comments{/number}","issue_comment_url":"https://api.github.com/repos/mongodb/mongo-php-library/issues/comments{/number}","contents_url":"https://api.github.com/repos/mongodb/mongo-php-library/contents/{+path}","compare_url":"https://api.github.com/repos/mongodb/mongo-php-library/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mongodb/mongo-php-library/merges","archive_url":"https://api.github.com/repos/mongodb/mongo-php-library/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mongodb/mongo-php-library/downloads","issues_url":"https://api.github.com/repos/mongodb/mongo-php-library/issues{/number}","pulls_url":"https://api.github.com/repos/mongodb/mongo-php-library/pulls{/number}","milestones_url":"https://api.github.com/repos/mongodb/mongo-php-library/milestones{/number}","notifications_url":"https://api.github.com/repos/mongodb/mongo-php-library/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mongodb/mongo-php-library/labels{/name}","releases_url":"https://api.github.com/repos/mongodb/mongo-php-library/releases{/id}","deployments_url":"https://api.github.com/repos/mongodb/mongo-php-library/deployments","created_at":"2014-12-04T19:55:40Z","updated_at":"2018-02-16T14:17:33Z","pushed_at":"2018-02-16T21:44:22Z","git_url":"git://github.com/mongodb/mongo-php-library.git","ssh_url":"git@github.com:mongodb/mongo-php-library.git","clone_url":"https://github.com/mongodb/mongo-php-library.git","svn_url":"https://github.com/mongodb/mongo-php-library","homepage":"https://docs.mongodb.com/php-library/","size":1606,"stargazers_count":653,"watchers_count":653,"language":"PHP","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":163,"mirror_url":null,"archived":false,"open_issues_count":39,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":163,"open_issues":39,"watchers":653,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mongodb/mongo-php-library/pulls/497"},"html":{"href":"https://github.com/mongodb/mongo-php-library/pull/497"},"issue":{"href":"https://api.github.com/repos/mongodb/mongo-php-library/issues/497"},"comments":{"href":"https://api.github.com/repos/mongodb/mongo-php-library/issues/497/comments"},"review_comments":{"href":"https://api.github.com/repos/mongodb/mongo-php-library/pulls/497/comments"},"review_comment":{"href":"https://api.github.com/repos/mongodb/mongo-php-library/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mongodb/mongo-php-library/pulls/497/commits"},"statuses":{"href":"https://api.github.com/repos/mongodb/mongo-php-library/statuses/ac082beca33317fe6fab05ac03d3f6a691b286e4"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"jmikola"}}