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
[process] provide a restart method. #5456
Changes from 1 commit
8252085
7dc25a9
286131b
34d821f
72c9793
76aedb6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,6 +143,21 @@ public function __destruct() | |
$this->stop(); | ||
} | ||
|
||
public function __clone() | ||
{ | ||
unset($this->exitcode); | ||
unset($this->fallbackExitcode); | ||
unset($this->processInformation); | ||
unset($this->stdout); | ||
unset($this->stderr); | ||
unset($this->pipes); | ||
unset($this->process); | ||
unset($this->fileHandles); | ||
unset($this->readBytes); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you should not unset the properties of the class but only reset the values in the object only There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure what you mean. Since the default state is non-set, unset() returns them to that state. Anything else like setting equal to null would not be equivalent. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If you try reading one of these properties before writing in it again, you will have an E_STRICT error. And if you write first, you will end with a public properties as properties added on the fly are public. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's good to know and seems somewhat non-intuitive. So what is the proper solution then to "reset the value" setting to null is the closest it seems. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is the way to do it. |
||
|
||
$this->status = self::STATUS_READY; | ||
} | ||
|
||
/** | ||
* Runs the process. | ||
* | ||
|
@@ -300,6 +315,29 @@ public function start($callback = null) | |
$this->updateStatus(); | ||
} | ||
|
||
/** | ||
* Restarts the process by cloning and invoking start(). | ||
* | ||
* @param Closure|string|array $callback A PHP callback to run whenever there is some | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the stop method documentation be updated to the same format? I just used what they had. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, it should There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated the documentation for restart() and placed the rest in separate request since there were more than just the one. |
||
* output available on STDOUT or STDERR | ||
* | ||
* @return Process The new process. | ||
* | ||
* @throws \RuntimeException When process can't be launch or is stopped | ||
* @throws \RuntimeException When process is already running | ||
* @see start() | ||
*/ | ||
public function restart($callback = null) | ||
{ | ||
if ($this->isRunning()) { | ||
throw new \RuntimeException('Process is already running'); | ||
} | ||
|
||
$process = clone $this; | ||
$process->start($callback); | ||
return $process; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing new line before |
||
} | ||
|
||
/** | ||
* Waits for the process to terminate. | ||
* | ||
|
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.
unset()
accepts multi values.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.
Yes, but is that preferred? and do you want them on one line or wrapped for each variable.
Or some variation.