Skip to content
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

support worker:$protocolRoot for custom protocols #846

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
logs
vendor
composer.lock
.buildpath
.project
.settings
Expand Down
11 changes: 9 additions & 2 deletions src/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,13 @@ class Worker
*/
public static $processTitle = 'WorkerMan';

/**
* Custom Protocols Root Namespace
*
* @var string
*/
public static $protocolRoot = 'Protocols\\';

/**
* After sending the stop command to the child process stopTimeout seconds,
* if the process is still living then forced to kill.
Expand Down Expand Up @@ -2290,11 +2297,11 @@ protected function parseSocketAddress() {
// Check application layer protocol class.
if (!isset(self::BUILD_IN_TRANSPORTS[$scheme])) {
$scheme = \ucfirst($scheme);
$this->protocol = \substr($scheme,0,1)==='\\' ? $scheme : 'Protocols\\' . $scheme;
$this->protocol = \substr($scheme,0,1)==='\\' ? $scheme : self::$protocolRoot . $scheme;
if (!\class_exists($this->protocol)) {
$this->protocol = "Workerman\\Protocols\\$scheme";
if (!\class_exists($this->protocol)) {
throw new Exception("class \\Protocols\\$scheme not exist");
throw new Exception("protocol $scheme not exist");
}
}

Expand Down