@@ -46,7 +46,7 @@ class Watch implements Executable
4646 private $ collectionName ;
4747 private $ pipeline ;
4848 private $ options ;
49- private $ manager ;
49+ private $ resumeCallable ;
5050
5151 /**
5252 * Constructs an aggregate command for creating a change stream.
@@ -107,13 +107,13 @@ public function __construct(Manager $manager, $databaseName, $collectionName, ar
107107 }
108108 }
109109
110- $ this ->manager = $ manager ;
111110 $ this ->databaseName = (string ) $ databaseName ;
112111 $ this ->collectionName = (string ) $ collectionName ;
113112 $ this ->pipeline = $ pipeline ;
114113 $ this ->options = $ options ;
115114
116115 $ this ->aggregate = $ this ->createAggregate ();
116+ $ this ->resumeCallable = $ this ->createResumeCallable ($ manager );
117117 }
118118
119119 /**
@@ -129,7 +129,7 @@ public function execute(Server $server)
129129 {
130130 $ cursor = $ this ->aggregate ->execute ($ server );
131131
132- return new ChangeStream ($ cursor , $ this ->createResumeCallable () );
132+ return new ChangeStream ($ cursor , $ this ->resumeCallable );
133133 }
134134
135135 /**
@@ -153,9 +153,9 @@ private function createAggregate()
153153 return new Aggregate ($ this ->databaseName , $ this ->collectionName , $ pipeline , $ aggregateOptions );
154154 }
155155
156- private function createResumeCallable ()
156+ private function createResumeCallable (Manager $ manager )
157157 {
158- return function ($ resumeToken = null ) {
158+ return function ($ resumeToken = null ) use ( $ manager ) {
159159 /* If a resume token was provided, recreate the Aggregate operation
160160 * using the new resume token. */
161161 if ($ resumeToken !== null ) {
@@ -165,7 +165,7 @@ private function createResumeCallable()
165165
166166 /* Select a new server using the read preference, execute this
167167 * operation on it, and return the new ChangeStream. */
168- $ server = $ this -> manager ->selectServer ($ this ->options ['readPreference ' ]);
168+ $ server = $ manager ->selectServer ($ this ->options ['readPreference ' ]);
169169
170170 return $ this ->execute ($ server );
171171 };
0 commit comments