id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
|
|---|---|---|---|---|---|---|---|---|---|---|---|
220,600
|
swooletw/laravel-swoole
|
src/Server/Manager.php
|
Manager.createPidFile
|
protected function createPidFile()
{
$pidFile = $this->getPidFile();
$pid = $this->container->make(Server::class)->master_pid;
file_put_contents($pidFile, $pid);
}
|
php
|
protected function createPidFile()
{
$pidFile = $this->getPidFile();
$pid = $this->container->make(Server::class)->master_pid;
file_put_contents($pidFile, $pid);
}
|
[
"protected",
"function",
"createPidFile",
"(",
")",
"{",
"$",
"pidFile",
"=",
"$",
"this",
"->",
"getPidFile",
"(",
")",
";",
"$",
"pid",
"=",
"$",
"this",
"->",
"container",
"->",
"make",
"(",
"Server",
"::",
"class",
")",
"->",
"master_pid",
";",
"file_put_contents",
"(",
"$",
"pidFile",
",",
"$",
"pid",
")",
";",
"}"
] |
Create pid file.
|
[
"Create",
"pid",
"file",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Server/Manager.php#L343-L349
|
220,601
|
swooletw/laravel-swoole
|
src/Server/Manager.php
|
Manager.addProcess
|
public function addProcess(Process $process): void
{
$this->container->make(Server::class)->addProcess($process);
}
|
php
|
public function addProcess(Process $process): void
{
$this->container->make(Server::class)->addProcess($process);
}
|
[
"public",
"function",
"addProcess",
"(",
"Process",
"$",
"process",
")",
":",
"void",
"{",
"$",
"this",
"->",
"container",
"->",
"make",
"(",
"Server",
"::",
"class",
")",
"->",
"addProcess",
"(",
"$",
"process",
")",
";",
"}"
] |
Add process to http server
@param \Swoole\Process $process
|
[
"Add",
"process",
"to",
"http",
"server"
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Server/Manager.php#L403-L406
|
220,602
|
swooletw/laravel-swoole
|
src/Server/Manager.php
|
Manager.isAsyncTaskPayload
|
protected function isAsyncTaskPayload($payload): bool
{
$data = json_decode($payload, true);
if (JSON_ERROR_NONE !== json_last_error()) {
return false;
}
return isset($data['job']);
}
|
php
|
protected function isAsyncTaskPayload($payload): bool
{
$data = json_decode($payload, true);
if (JSON_ERROR_NONE !== json_last_error()) {
return false;
}
return isset($data['job']);
}
|
[
"protected",
"function",
"isAsyncTaskPayload",
"(",
"$",
"payload",
")",
":",
"bool",
"{",
"$",
"data",
"=",
"json_decode",
"(",
"$",
"payload",
",",
"true",
")",
";",
"if",
"(",
"JSON_ERROR_NONE",
"!==",
"json_last_error",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"isset",
"(",
"$",
"data",
"[",
"'job'",
"]",
")",
";",
"}"
] |
Indicates if the payload is async task.
@param mixed $payload
@return boolean
|
[
"Indicates",
"if",
"the",
"payload",
"is",
"async",
"task",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Server/Manager.php#L458-L467
|
220,603
|
swooletw/laravel-swoole
|
src/Server/Sandbox.php
|
Sandbox.initialize
|
public function initialize()
{
if (! $this->app instanceof Container) {
throw new SandboxException('A base app has not been set.');
}
$this->setInitialConfig();
$this->setInitialProviders();
$this->setInitialResetters();
return $this;
}
|
php
|
public function initialize()
{
if (! $this->app instanceof Container) {
throw new SandboxException('A base app has not been set.');
}
$this->setInitialConfig();
$this->setInitialProviders();
$this->setInitialResetters();
return $this;
}
|
[
"public",
"function",
"initialize",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"app",
"instanceof",
"Container",
")",
"{",
"throw",
"new",
"SandboxException",
"(",
"'A base app has not been set.'",
")",
";",
"}",
"$",
"this",
"->",
"setInitialConfig",
"(",
")",
";",
"$",
"this",
"->",
"setInitialProviders",
"(",
")",
";",
"$",
"this",
"->",
"setInitialResetters",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Initialize based on base app.
@throws \SwooleTW\Http\Exceptions\SandboxException
|
[
"Initialize",
"based",
"on",
"base",
"app",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Server/Sandbox.php#L120-L131
|
220,604
|
swooletw/laravel-swoole
|
src/Server/Sandbox.php
|
Sandbox.run
|
public function run(Request $request)
{
if (! $this->getSnapshot() instanceof Container) {
throw new SandboxException('Sandbox is not enabled.');
}
$shouldUseOb = $this->config->get('swoole_http.ob_output', true);
if ($shouldUseOb) {
return $this->prepareObResponse($request);
}
return $this->prepareResponse($request);
}
|
php
|
public function run(Request $request)
{
if (! $this->getSnapshot() instanceof Container) {
throw new SandboxException('Sandbox is not enabled.');
}
$shouldUseOb = $this->config->get('swoole_http.ob_output', true);
if ($shouldUseOb) {
return $this->prepareObResponse($request);
}
return $this->prepareResponse($request);
}
|
[
"public",
"function",
"run",
"(",
"Request",
"$",
"request",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"getSnapshot",
"(",
")",
"instanceof",
"Container",
")",
"{",
"throw",
"new",
"SandboxException",
"(",
"'Sandbox is not enabled.'",
")",
";",
"}",
"$",
"shouldUseOb",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'swoole_http.ob_output'",
",",
"true",
")",
";",
"if",
"(",
"$",
"shouldUseOb",
")",
"{",
"return",
"$",
"this",
"->",
"prepareObResponse",
"(",
"$",
"request",
")",
";",
"}",
"return",
"$",
"this",
"->",
"prepareResponse",
"(",
"$",
"request",
")",
";",
"}"
] |
Run framework.
@param \Illuminate\Http\Request $request
@return \Illuminate\Http\Response
@throws \SwooleTW\Http\Exceptions\SandboxException
@throws \ReflectionException
|
[
"Run",
"framework",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Server/Sandbox.php#L170-L183
|
220,605
|
swooletw/laravel-swoole
|
src/Server/Sandbox.php
|
Sandbox.prepareResponse
|
protected function prepareResponse(Request $request)
{
// handle request with laravel or lumen
$response = $this->handleRequest($request);
// process terminating logics
$this->terminate($request, $response);
return $response;
}
|
php
|
protected function prepareResponse(Request $request)
{
// handle request with laravel or lumen
$response = $this->handleRequest($request);
// process terminating logics
$this->terminate($request, $response);
return $response;
}
|
[
"protected",
"function",
"prepareResponse",
"(",
"Request",
"$",
"request",
")",
"{",
"// handle request with laravel or lumen",
"$",
"response",
"=",
"$",
"this",
"->",
"handleRequest",
"(",
"$",
"request",
")",
";",
"// process terminating logics",
"$",
"this",
"->",
"terminate",
"(",
"$",
"request",
",",
"$",
"response",
")",
";",
"return",
"$",
"response",
";",
"}"
] |
Handle request for non-ob case.
@param \Illuminate\Http\Request $request
@return \Illuminate\Http\Response
@throws \ReflectionException
|
[
"Handle",
"request",
"for",
"non",
"-",
"ob",
"case",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Server/Sandbox.php#L193-L202
|
220,606
|
swooletw/laravel-swoole
|
src/Server/Sandbox.php
|
Sandbox.prepareObResponse
|
protected function prepareObResponse(Request $request)
{
ob_start();
// handle request with laravel or lumen
$response = $this->handleRequest($request);
// prepare content for ob
$content = '';
$isFile = false;
if ($isStream = $response instanceof StreamedResponse) {
$response->sendContent();
} elseif ($response instanceof SymfonyResponse) {
$content = $response->getContent();
} elseif (! $isFile = $response instanceof BinaryFileResponse) {
$content = (string) $response;
}
// process terminating logics
$this->terminate($request, $response);
// append ob content to response
if (! $isFile && ob_get_length() > 0) {
if ($isStream) {
$response->output = ob_get_contents();
} else {
$response->setContent(ob_get_contents() . $content);
}
}
ob_end_clean();
return $response;
}
|
php
|
protected function prepareObResponse(Request $request)
{
ob_start();
// handle request with laravel or lumen
$response = $this->handleRequest($request);
// prepare content for ob
$content = '';
$isFile = false;
if ($isStream = $response instanceof StreamedResponse) {
$response->sendContent();
} elseif ($response instanceof SymfonyResponse) {
$content = $response->getContent();
} elseif (! $isFile = $response instanceof BinaryFileResponse) {
$content = (string) $response;
}
// process terminating logics
$this->terminate($request, $response);
// append ob content to response
if (! $isFile && ob_get_length() > 0) {
if ($isStream) {
$response->output = ob_get_contents();
} else {
$response->setContent(ob_get_contents() . $content);
}
}
ob_end_clean();
return $response;
}
|
[
"protected",
"function",
"prepareObResponse",
"(",
"Request",
"$",
"request",
")",
"{",
"ob_start",
"(",
")",
";",
"// handle request with laravel or lumen",
"$",
"response",
"=",
"$",
"this",
"->",
"handleRequest",
"(",
"$",
"request",
")",
";",
"// prepare content for ob",
"$",
"content",
"=",
"''",
";",
"$",
"isFile",
"=",
"false",
";",
"if",
"(",
"$",
"isStream",
"=",
"$",
"response",
"instanceof",
"StreamedResponse",
")",
"{",
"$",
"response",
"->",
"sendContent",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"response",
"instanceof",
"SymfonyResponse",
")",
"{",
"$",
"content",
"=",
"$",
"response",
"->",
"getContent",
"(",
")",
";",
"}",
"elseif",
"(",
"!",
"$",
"isFile",
"=",
"$",
"response",
"instanceof",
"BinaryFileResponse",
")",
"{",
"$",
"content",
"=",
"(",
"string",
")",
"$",
"response",
";",
"}",
"// process terminating logics",
"$",
"this",
"->",
"terminate",
"(",
"$",
"request",
",",
"$",
"response",
")",
";",
"// append ob content to response",
"if",
"(",
"!",
"$",
"isFile",
"&&",
"ob_get_length",
"(",
")",
">",
"0",
")",
"{",
"if",
"(",
"$",
"isStream",
")",
"{",
"$",
"response",
"->",
"output",
"=",
"ob_get_contents",
"(",
")",
";",
"}",
"else",
"{",
"$",
"response",
"->",
"setContent",
"(",
"ob_get_contents",
"(",
")",
".",
"$",
"content",
")",
";",
"}",
"}",
"ob_end_clean",
"(",
")",
";",
"return",
"$",
"response",
";",
"}"
] |
Handle request for ob output.
@param \Illuminate\Http\Request $request
@return \Illuminate\Http\Response
@throws \ReflectionException
|
[
"Handle",
"request",
"for",
"ob",
"output",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Server/Sandbox.php#L212-L245
|
220,607
|
swooletw/laravel-swoole
|
src/Server/Sandbox.php
|
Sandbox.handleRequest
|
protected function handleRequest(Request $request)
{
if ($this->isLaravel()) {
return $this->getKernel()->handle($request);
}
return $this->getApplication()->dispatch($request);
}
|
php
|
protected function handleRequest(Request $request)
{
if ($this->isLaravel()) {
return $this->getKernel()->handle($request);
}
return $this->getApplication()->dispatch($request);
}
|
[
"protected",
"function",
"handleRequest",
"(",
"Request",
"$",
"request",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isLaravel",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getKernel",
"(",
")",
"->",
"handle",
"(",
"$",
"request",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getApplication",
"(",
")",
"->",
"dispatch",
"(",
"$",
"request",
")",
";",
"}"
] |
Handle request through Laravel or Lumen.
@param \Illuminate\Http\Request $request
@return \Illuminate\Http\Response
|
[
"Handle",
"request",
"through",
"Laravel",
"or",
"Lumen",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Server/Sandbox.php#L254-L261
|
220,608
|
swooletw/laravel-swoole
|
src/Server/Sandbox.php
|
Sandbox.enable
|
public function enable()
{
if (! $this->config instanceof ConfigContract) {
throw new SandboxException('Please initialize after setting base app.');
}
$this->setInstance($app = $this->getApplication());
$this->resetApp($app);
}
|
php
|
public function enable()
{
if (! $this->config instanceof ConfigContract) {
throw new SandboxException('Please initialize after setting base app.');
}
$this->setInstance($app = $this->getApplication());
$this->resetApp($app);
}
|
[
"public",
"function",
"enable",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"config",
"instanceof",
"ConfigContract",
")",
"{",
"throw",
"new",
"SandboxException",
"(",
"'Please initialize after setting base app.'",
")",
";",
"}",
"$",
"this",
"->",
"setInstance",
"(",
"$",
"app",
"=",
"$",
"this",
"->",
"getApplication",
"(",
")",
")",
";",
"$",
"this",
"->",
"resetApp",
"(",
"$",
"app",
")",
";",
"}"
] |
Set laravel snapshot to container and facade.
@throws \SwooleTW\Http\Exceptions\SandboxException
|
[
"Set",
"laravel",
"snapshot",
"to",
"container",
"and",
"facade",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Server/Sandbox.php#L312-L320
|
220,609
|
swooletw/laravel-swoole
|
src/Server/Sandbox.php
|
Sandbox.setInstance
|
public function setInstance(Container $app)
{
$app->instance('app', $app);
$app->instance(Container::class, $app);
if ($this->framework === 'lumen') {
$app->instance(LumenApplication::class, $app);
}
Container::setInstance($app);
Context::setApp($app);
Facade::clearResolvedInstances();
Facade::setFacadeApplication($app);
}
|
php
|
public function setInstance(Container $app)
{
$app->instance('app', $app);
$app->instance(Container::class, $app);
if ($this->framework === 'lumen') {
$app->instance(LumenApplication::class, $app);
}
Container::setInstance($app);
Context::setApp($app);
Facade::clearResolvedInstances();
Facade::setFacadeApplication($app);
}
|
[
"public",
"function",
"setInstance",
"(",
"Container",
"$",
"app",
")",
"{",
"$",
"app",
"->",
"instance",
"(",
"'app'",
",",
"$",
"app",
")",
";",
"$",
"app",
"->",
"instance",
"(",
"Container",
"::",
"class",
",",
"$",
"app",
")",
";",
"if",
"(",
"$",
"this",
"->",
"framework",
"===",
"'lumen'",
")",
"{",
"$",
"app",
"->",
"instance",
"(",
"LumenApplication",
"::",
"class",
",",
"$",
"app",
")",
";",
"}",
"Container",
"::",
"setInstance",
"(",
"$",
"app",
")",
";",
"Context",
"::",
"setApp",
"(",
"$",
"app",
")",
";",
"Facade",
"::",
"clearResolvedInstances",
"(",
")",
";",
"Facade",
"::",
"setFacadeApplication",
"(",
"$",
"app",
")",
";",
"}"
] |
Replace app's self bindings.
@param \Illuminate\Container\Container $app
|
[
"Replace",
"app",
"s",
"self",
"bindings",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Server/Sandbox.php#L336-L349
|
220,610
|
swooletw/laravel-swoole
|
src/Helpers/MimeType.php
|
MimeType.from
|
public static function from($filename)
{
$extension = strtok(pathinfo($filename, PATHINFO_EXTENSION), '?');
return self::getMimeTypeFromExtension($extension);
}
|
php
|
public static function from($filename)
{
$extension = strtok(pathinfo($filename, PATHINFO_EXTENSION), '?');
return self::getMimeTypeFromExtension($extension);
}
|
[
"public",
"static",
"function",
"from",
"(",
"$",
"filename",
")",
"{",
"$",
"extension",
"=",
"strtok",
"(",
"pathinfo",
"(",
"$",
"filename",
",",
"PATHINFO_EXTENSION",
")",
",",
"'?'",
")",
";",
"return",
"self",
"::",
"getMimeTypeFromExtension",
"(",
"$",
"extension",
")",
";",
"}"
] |
Get the MIME type for a file based on the file's extension.
@param string $filename
@return string
|
[
"Get",
"the",
"MIME",
"type",
"for",
"a",
"file",
"based",
"on",
"the",
"file",
"s",
"extension",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Helpers/MimeType.php#L793-L798
|
220,611
|
swooletw/laravel-swoole
|
src/Concerns/ResetApplication.php
|
ResetApplication.setInitialProviders
|
protected function setInitialProviders()
{
$app = $this->getBaseApp();
$providers = $this->config->get('swoole_http.providers', []);
foreach ($providers as $provider) {
if (class_exists($provider) && ! in_array($provider, $this->providers)) {
$providerClass = new $provider($app);
$this->providers[$provider] = $providerClass;
}
}
}
|
php
|
protected function setInitialProviders()
{
$app = $this->getBaseApp();
$providers = $this->config->get('swoole_http.providers', []);
foreach ($providers as $provider) {
if (class_exists($provider) && ! in_array($provider, $this->providers)) {
$providerClass = new $provider($app);
$this->providers[$provider] = $providerClass;
}
}
}
|
[
"protected",
"function",
"setInitialProviders",
"(",
")",
"{",
"$",
"app",
"=",
"$",
"this",
"->",
"getBaseApp",
"(",
")",
";",
"$",
"providers",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'swoole_http.providers'",
",",
"[",
"]",
")",
";",
"foreach",
"(",
"$",
"providers",
"as",
"$",
"provider",
")",
"{",
"if",
"(",
"class_exists",
"(",
"$",
"provider",
")",
"&&",
"!",
"in_array",
"(",
"$",
"provider",
",",
"$",
"this",
"->",
"providers",
")",
")",
"{",
"$",
"providerClass",
"=",
"new",
"$",
"provider",
"(",
"$",
"app",
")",
";",
"$",
"this",
"->",
"providers",
"[",
"$",
"provider",
"]",
"=",
"$",
"providerClass",
";",
"}",
"}",
"}"
] |
Initialize customized service providers.
|
[
"Initialize",
"customized",
"service",
"providers",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Concerns/ResetApplication.php#L46-L57
|
220,612
|
swooletw/laravel-swoole
|
src/Websocket/Pusher.php
|
Pusher.push
|
public function push($payload): void
{
// attach sender if not broadcast
if (! $this->broadcast && $this->sender && ! $this->hasDescriptor($this->sender)) {
$this->addDescriptor($this->sender);
}
// check if to broadcast to other clients
if ($this->shouldBroadcast()) {
$this->addDescriptors($this->getWebsocketConnections());
}
// push message to designated fds
foreach ($this->descriptors as $descriptor) {
if ($this->shouldPushToDescriptor($descriptor)) {
$this->server->push($descriptor, $payload, $this->opcode);
}
}
}
|
php
|
public function push($payload): void
{
// attach sender if not broadcast
if (! $this->broadcast && $this->sender && ! $this->hasDescriptor($this->sender)) {
$this->addDescriptor($this->sender);
}
// check if to broadcast to other clients
if ($this->shouldBroadcast()) {
$this->addDescriptors($this->getWebsocketConnections());
}
// push message to designated fds
foreach ($this->descriptors as $descriptor) {
if ($this->shouldPushToDescriptor($descriptor)) {
$this->server->push($descriptor, $payload, $this->opcode);
}
}
}
|
[
"public",
"function",
"push",
"(",
"$",
"payload",
")",
":",
"void",
"{",
"// attach sender if not broadcast",
"if",
"(",
"!",
"$",
"this",
"->",
"broadcast",
"&&",
"$",
"this",
"->",
"sender",
"&&",
"!",
"$",
"this",
"->",
"hasDescriptor",
"(",
"$",
"this",
"->",
"sender",
")",
")",
"{",
"$",
"this",
"->",
"addDescriptor",
"(",
"$",
"this",
"->",
"sender",
")",
";",
"}",
"// check if to broadcast to other clients",
"if",
"(",
"$",
"this",
"->",
"shouldBroadcast",
"(",
")",
")",
"{",
"$",
"this",
"->",
"addDescriptors",
"(",
"$",
"this",
"->",
"getWebsocketConnections",
"(",
")",
")",
";",
"}",
"// push message to designated fds",
"foreach",
"(",
"$",
"this",
"->",
"descriptors",
"as",
"$",
"descriptor",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"shouldPushToDescriptor",
"(",
"$",
"descriptor",
")",
")",
"{",
"$",
"this",
"->",
"server",
"->",
"push",
"(",
"$",
"descriptor",
",",
"$",
"payload",
",",
"$",
"this",
"->",
"opcode",
")",
";",
"}",
"}",
"}"
] |
Push message to related descriptors
@param mixed $payload
@return void
|
[
"Push",
"message",
"to",
"related",
"descriptors"
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Websocket/Pusher.php#L250-L268
|
220,613
|
swooletw/laravel-swoole
|
src/Helpers/FW.php
|
FW.version
|
public static function version(string $expression = self::VERSION_WITHOUT_BUG_FIX): string
{
if (static::is(static::LARAVEL)) {
return static::extractVersion(constant('Illuminate\Foundation\Application::VERSION'), $expression);
}
/** @var \Laravel\Lumen\Application $app */
$app = call_user_func('Laravel\Lumen\Application::getInstance');
if ($version = static::extractVersion($app->version(), $expression)) {
return $version;
}
throw new LogicException('No any version found.');
}
|
php
|
public static function version(string $expression = self::VERSION_WITHOUT_BUG_FIX): string
{
if (static::is(static::LARAVEL)) {
return static::extractVersion(constant('Illuminate\Foundation\Application::VERSION'), $expression);
}
/** @var \Laravel\Lumen\Application $app */
$app = call_user_func('Laravel\Lumen\Application::getInstance');
if ($version = static::extractVersion($app->version(), $expression)) {
return $version;
}
throw new LogicException('No any version found.');
}
|
[
"public",
"static",
"function",
"version",
"(",
"string",
"$",
"expression",
"=",
"self",
"::",
"VERSION_WITHOUT_BUG_FIX",
")",
":",
"string",
"{",
"if",
"(",
"static",
"::",
"is",
"(",
"static",
"::",
"LARAVEL",
")",
")",
"{",
"return",
"static",
"::",
"extractVersion",
"(",
"constant",
"(",
"'Illuminate\\Foundation\\Application::VERSION'",
")",
",",
"$",
"expression",
")",
";",
"}",
"/** @var \\Laravel\\Lumen\\Application $app */",
"$",
"app",
"=",
"call_user_func",
"(",
"'Laravel\\Lumen\\Application::getInstance'",
")",
";",
"if",
"(",
"$",
"version",
"=",
"static",
"::",
"extractVersion",
"(",
"$",
"app",
"->",
"version",
"(",
")",
",",
"$",
"expression",
")",
")",
"{",
"return",
"$",
"version",
";",
"}",
"throw",
"new",
"LogicException",
"(",
"'No any version found.'",
")",
";",
"}"
] |
Returns application version
@param string $expression
@return string
|
[
"Returns",
"application",
"version"
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Helpers/FW.php#L70-L84
|
220,614
|
swooletw/laravel-swoole
|
src/Websocket/SocketIO/Strategies/HeartbeatStrategy.php
|
HeartbeatStrategy.handle
|
public function handle($server, $frame)
{
$packet = $frame->data;
$packetLength = strlen($packet);
$payload = '';
if (Packet::getPayload($packet)) {
return false;
}
if ($isPing = Packet::isSocketType($packet, 'ping')) {
$payload .= Packet::PONG;
}
if ($isPing && $packetLength > 1) {
$payload .= substr($packet, 1, $packetLength - 1);
}
if ($isPing) {
$server->push($frame->fd, $payload);
}
return true;
}
|
php
|
public function handle($server, $frame)
{
$packet = $frame->data;
$packetLength = strlen($packet);
$payload = '';
if (Packet::getPayload($packet)) {
return false;
}
if ($isPing = Packet::isSocketType($packet, 'ping')) {
$payload .= Packet::PONG;
}
if ($isPing && $packetLength > 1) {
$payload .= substr($packet, 1, $packetLength - 1);
}
if ($isPing) {
$server->push($frame->fd, $payload);
}
return true;
}
|
[
"public",
"function",
"handle",
"(",
"$",
"server",
",",
"$",
"frame",
")",
"{",
"$",
"packet",
"=",
"$",
"frame",
"->",
"data",
";",
"$",
"packetLength",
"=",
"strlen",
"(",
"$",
"packet",
")",
";",
"$",
"payload",
"=",
"''",
";",
"if",
"(",
"Packet",
"::",
"getPayload",
"(",
"$",
"packet",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"isPing",
"=",
"Packet",
"::",
"isSocketType",
"(",
"$",
"packet",
",",
"'ping'",
")",
")",
"{",
"$",
"payload",
".=",
"Packet",
"::",
"PONG",
";",
"}",
"if",
"(",
"$",
"isPing",
"&&",
"$",
"packetLength",
">",
"1",
")",
"{",
"$",
"payload",
".=",
"substr",
"(",
"$",
"packet",
",",
"1",
",",
"$",
"packetLength",
"-",
"1",
")",
";",
"}",
"if",
"(",
"$",
"isPing",
")",
"{",
"$",
"server",
"->",
"push",
"(",
"$",
"frame",
"->",
"fd",
",",
"$",
"payload",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
If return value is true will skip decoding.
@param \Swoole\WebSocket\Server $server
@param \Swoole\WebSocket\Frame $frame
@return boolean
|
[
"If",
"return",
"value",
"is",
"true",
"will",
"skip",
"decoding",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Websocket/SocketIO/Strategies/HeartbeatStrategy.php#L17-L40
|
220,615
|
swooletw/laravel-swoole
|
src/Concerns/InteractsWithSwooleQueue.php
|
InteractsWithSwooleQueue.isSwooleQueuePacket
|
protected function isSwooleQueuePacket($packet)
{
if (! is_string($packet)) {
return false;
}
$decoded = json_decode($packet, true);
return JSON_ERROR_NONE === json_last_error() && isset($decoded['job']);
}
|
php
|
protected function isSwooleQueuePacket($packet)
{
if (! is_string($packet)) {
return false;
}
$decoded = json_decode($packet, true);
return JSON_ERROR_NONE === json_last_error() && isset($decoded['job']);
}
|
[
"protected",
"function",
"isSwooleQueuePacket",
"(",
"$",
"packet",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"packet",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"decoded",
"=",
"json_decode",
"(",
"$",
"packet",
",",
"true",
")",
";",
"return",
"JSON_ERROR_NONE",
"===",
"json_last_error",
"(",
")",
"&&",
"isset",
"(",
"$",
"decoded",
"[",
"'job'",
"]",
")",
";",
"}"
] |
Indicates if a packet is swoole's queue job.
@param mixed
|
[
"Indicates",
"if",
"a",
"packet",
"is",
"swoole",
"s",
"queue",
"job",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Concerns/InteractsWithSwooleQueue.php#L15-L24
|
220,616
|
swooletw/laravel-swoole
|
src/HttpServiceProvider.php
|
HttpServiceProvider.configureSwooleServer
|
protected function configureSwooleServer()
{
$config = $this->app->make('config');
$options = $config->get('swoole_http.server.options');
// only enable task worker in websocket mode and for queue driver
if ($config->get('queue.default') !== 'swoole' && ! $this->isWebsocket) {
unset($options['task_worker_num']);
}
static::$server->set($options);
}
|
php
|
protected function configureSwooleServer()
{
$config = $this->app->make('config');
$options = $config->get('swoole_http.server.options');
// only enable task worker in websocket mode and for queue driver
if ($config->get('queue.default') !== 'swoole' && ! $this->isWebsocket) {
unset($options['task_worker_num']);
}
static::$server->set($options);
}
|
[
"protected",
"function",
"configureSwooleServer",
"(",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'config'",
")",
";",
"$",
"options",
"=",
"$",
"config",
"->",
"get",
"(",
"'swoole_http.server.options'",
")",
";",
"// only enable task worker in websocket mode and for queue driver",
"if",
"(",
"$",
"config",
"->",
"get",
"(",
"'queue.default'",
")",
"!==",
"'swoole'",
"&&",
"!",
"$",
"this",
"->",
"isWebsocket",
")",
"{",
"unset",
"(",
"$",
"options",
"[",
"'task_worker_num'",
"]",
")",
";",
"}",
"static",
"::",
"$",
"server",
"->",
"set",
"(",
"$",
"options",
")",
";",
"}"
] |
Set swoole server configurations.
|
[
"Set",
"swoole",
"server",
"configurations",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/HttpServiceProvider.php#L146-L157
|
220,617
|
swooletw/laravel-swoole
|
src/HttpServiceProvider.php
|
HttpServiceProvider.registerDatabaseDriver
|
protected function registerDatabaseDriver()
{
$this->app->extend(DatabaseManager::class, function (DatabaseManager $db) {
$db->extend('mysql-coroutine', function ($config, $name) {
$config['name'] = $name;
$connection = new MySqlConnection(
$this->getNewMySqlConnection($config, 'write'),
$config['database'],
$config['prefix'],
$config
);
if (isset($config['read'])) {
$connection->setReadPdo($this->getNewMySqlConnection($config, 'read'));
}
return $connection;
});
return $db;
});
}
|
php
|
protected function registerDatabaseDriver()
{
$this->app->extend(DatabaseManager::class, function (DatabaseManager $db) {
$db->extend('mysql-coroutine', function ($config, $name) {
$config['name'] = $name;
$connection = new MySqlConnection(
$this->getNewMySqlConnection($config, 'write'),
$config['database'],
$config['prefix'],
$config
);
if (isset($config['read'])) {
$connection->setReadPdo($this->getNewMySqlConnection($config, 'read'));
}
return $connection;
});
return $db;
});
}
|
[
"protected",
"function",
"registerDatabaseDriver",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"extend",
"(",
"DatabaseManager",
"::",
"class",
",",
"function",
"(",
"DatabaseManager",
"$",
"db",
")",
"{",
"$",
"db",
"->",
"extend",
"(",
"'mysql-coroutine'",
",",
"function",
"(",
"$",
"config",
",",
"$",
"name",
")",
"{",
"$",
"config",
"[",
"'name'",
"]",
"=",
"$",
"name",
";",
"$",
"connection",
"=",
"new",
"MySqlConnection",
"(",
"$",
"this",
"->",
"getNewMySqlConnection",
"(",
"$",
"config",
",",
"'write'",
")",
",",
"$",
"config",
"[",
"'database'",
"]",
",",
"$",
"config",
"[",
"'prefix'",
"]",
",",
"$",
"config",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'read'",
"]",
")",
")",
"{",
"$",
"connection",
"->",
"setReadPdo",
"(",
"$",
"this",
"->",
"getNewMySqlConnection",
"(",
"$",
"config",
",",
"'read'",
")",
")",
";",
"}",
"return",
"$",
"connection",
";",
"}",
")",
";",
"return",
"$",
"db",
";",
"}",
")",
";",
"}"
] |
Register database driver for coroutine mysql.
|
[
"Register",
"database",
"driver",
"for",
"coroutine",
"mysql",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/HttpServiceProvider.php#L180-L202
|
220,618
|
swooletw/laravel-swoole
|
src/HttpServiceProvider.php
|
HttpServiceProvider.getNewMySqlConnection
|
protected function getNewMySqlConnection(array $config, string $connection = null)
{
if ($connection && isset($config[$connection])) {
$config = array_merge($config, $config[$connection]);
}
return ConnectorFactory::make(FW::version())->connect($config);
}
|
php
|
protected function getNewMySqlConnection(array $config, string $connection = null)
{
if ($connection && isset($config[$connection])) {
$config = array_merge($config, $config[$connection]);
}
return ConnectorFactory::make(FW::version())->connect($config);
}
|
[
"protected",
"function",
"getNewMySqlConnection",
"(",
"array",
"$",
"config",
",",
"string",
"$",
"connection",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"connection",
"&&",
"isset",
"(",
"$",
"config",
"[",
"$",
"connection",
"]",
")",
")",
"{",
"$",
"config",
"=",
"array_merge",
"(",
"$",
"config",
",",
"$",
"config",
"[",
"$",
"connection",
"]",
")",
";",
"}",
"return",
"ConnectorFactory",
"::",
"make",
"(",
"FW",
"::",
"version",
"(",
")",
")",
"->",
"connect",
"(",
"$",
"config",
")",
";",
"}"
] |
Get a new mysql connection.
@param array $config
@param string $connection
@return \PDO
|
[
"Get",
"a",
"new",
"mysql",
"connection",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/HttpServiceProvider.php#L212-L219
|
220,619
|
swooletw/laravel-swoole
|
src/HttpServiceProvider.php
|
HttpServiceProvider.registerSwooleQueueDriver
|
protected function registerSwooleQueueDriver()
{
$this->app->afterResolving('queue', function (QueueManager $manager) {
$manager->addConnector('swoole', function () {
return new SwooleTaskConnector($this->app->make(Server::class));
});
});
}
|
php
|
protected function registerSwooleQueueDriver()
{
$this->app->afterResolving('queue', function (QueueManager $manager) {
$manager->addConnector('swoole', function () {
return new SwooleTaskConnector($this->app->make(Server::class));
});
});
}
|
[
"protected",
"function",
"registerSwooleQueueDriver",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"afterResolving",
"(",
"'queue'",
",",
"function",
"(",
"QueueManager",
"$",
"manager",
")",
"{",
"$",
"manager",
"->",
"addConnector",
"(",
"'swoole'",
",",
"function",
"(",
")",
"{",
"return",
"new",
"SwooleTaskConnector",
"(",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"Server",
"::",
"class",
")",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Register queue driver for swoole async task.
|
[
"Register",
"queue",
"driver",
"for",
"swoole",
"async",
"task",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/HttpServiceProvider.php#L224-L231
|
220,620
|
swooletw/laravel-swoole
|
src/Websocket/SimpleParser.php
|
SimpleParser.decode
|
public function decode($frame)
{
$data = json_decode($frame->data, true);
return [
'event' => $data['event'] ?? null,
'data' => $data['data'] ?? null,
];
}
|
php
|
public function decode($frame)
{
$data = json_decode($frame->data, true);
return [
'event' => $data['event'] ?? null,
'data' => $data['data'] ?? null,
];
}
|
[
"public",
"function",
"decode",
"(",
"$",
"frame",
")",
"{",
"$",
"data",
"=",
"json_decode",
"(",
"$",
"frame",
"->",
"data",
",",
"true",
")",
";",
"return",
"[",
"'event'",
"=>",
"$",
"data",
"[",
"'event'",
"]",
"??",
"null",
",",
"'data'",
"=>",
"$",
"data",
"[",
"'data'",
"]",
"??",
"null",
",",
"]",
";",
"}"
] |
Input message on websocket connected.
Define and return event name and payload data here.
@param \Swoole\Websocket\Frame $frame
@return array
|
[
"Input",
"message",
"on",
"websocket",
"connected",
".",
"Define",
"and",
"return",
"event",
"name",
"and",
"payload",
"data",
"here",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Websocket/SimpleParser.php#L38-L46
|
220,621
|
swooletw/laravel-swoole
|
src/Websocket/Rooms/TableRoom.php
|
TableRoom.initRoomsTable
|
protected function initRoomsTable(): void
{
$this->rooms = new Table($this->config['room_rows']);
$this->rooms->column('value', Table::TYPE_STRING, $this->config['room_size']);
$this->rooms->create();
}
|
php
|
protected function initRoomsTable(): void
{
$this->rooms = new Table($this->config['room_rows']);
$this->rooms->column('value', Table::TYPE_STRING, $this->config['room_size']);
$this->rooms->create();
}
|
[
"protected",
"function",
"initRoomsTable",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"rooms",
"=",
"new",
"Table",
"(",
"$",
"this",
"->",
"config",
"[",
"'room_rows'",
"]",
")",
";",
"$",
"this",
"->",
"rooms",
"->",
"column",
"(",
"'value'",
",",
"Table",
"::",
"TYPE_STRING",
",",
"$",
"this",
"->",
"config",
"[",
"'room_size'",
"]",
")",
";",
"$",
"this",
"->",
"rooms",
"->",
"create",
"(",
")",
";",
"}"
] |
Init rooms table
|
[
"Init",
"rooms",
"table"
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Websocket/Rooms/TableRoom.php#L150-L155
|
220,622
|
swooletw/laravel-swoole
|
src/Websocket/Rooms/TableRoom.php
|
TableRoom.initFdsTable
|
protected function initFdsTable()
{
$this->fds = new Table($this->config['client_rows']);
$this->fds->column('value', Table::TYPE_STRING, $this->config['client_size']);
$this->fds->create();
}
|
php
|
protected function initFdsTable()
{
$this->fds = new Table($this->config['client_rows']);
$this->fds->column('value', Table::TYPE_STRING, $this->config['client_size']);
$this->fds->create();
}
|
[
"protected",
"function",
"initFdsTable",
"(",
")",
"{",
"$",
"this",
"->",
"fds",
"=",
"new",
"Table",
"(",
"$",
"this",
"->",
"config",
"[",
"'client_rows'",
"]",
")",
";",
"$",
"this",
"->",
"fds",
"->",
"column",
"(",
"'value'",
",",
"Table",
"::",
"TYPE_STRING",
",",
"$",
"this",
"->",
"config",
"[",
"'client_size'",
"]",
")",
";",
"$",
"this",
"->",
"fds",
"->",
"create",
"(",
")",
";",
"}"
] |
Init descriptors table
|
[
"Init",
"descriptors",
"table"
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Websocket/Rooms/TableRoom.php#L160-L165
|
220,623
|
swooletw/laravel-swoole
|
src/Websocket/Rooms/TableRoom.php
|
TableRoom.setValue
|
public function setValue($key, array $value, string $table)
{
$this->checkTable($table);
$this->$table->set($key, ['value' => json_encode($value)]);
return $this;
}
|
php
|
public function setValue($key, array $value, string $table)
{
$this->checkTable($table);
$this->$table->set($key, ['value' => json_encode($value)]);
return $this;
}
|
[
"public",
"function",
"setValue",
"(",
"$",
"key",
",",
"array",
"$",
"value",
",",
"string",
"$",
"table",
")",
"{",
"$",
"this",
"->",
"checkTable",
"(",
"$",
"table",
")",
";",
"$",
"this",
"->",
"$",
"table",
"->",
"set",
"(",
"$",
"key",
",",
"[",
"'value'",
"=>",
"json_encode",
"(",
"$",
"value",
")",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Set value to table
@param $key
@param array $value
@param string $table
@return $this
|
[
"Set",
"value",
"to",
"table"
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Websocket/Rooms/TableRoom.php#L176-L183
|
220,624
|
swooletw/laravel-swoole
|
src/Websocket/Rooms/TableRoom.php
|
TableRoom.getValue
|
public function getValue(string $key, string $table)
{
$this->checkTable($table);
$value = $this->$table->get($key);
return $value ? json_decode($value['value'], true) : [];
}
|
php
|
public function getValue(string $key, string $table)
{
$this->checkTable($table);
$value = $this->$table->get($key);
return $value ? json_decode($value['value'], true) : [];
}
|
[
"public",
"function",
"getValue",
"(",
"string",
"$",
"key",
",",
"string",
"$",
"table",
")",
"{",
"$",
"this",
"->",
"checkTable",
"(",
"$",
"table",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"$",
"table",
"->",
"get",
"(",
"$",
"key",
")",
";",
"return",
"$",
"value",
"?",
"json_decode",
"(",
"$",
"value",
"[",
"'value'",
"]",
",",
"true",
")",
":",
"[",
"]",
";",
"}"
] |
Get value from table
@param string $key
@param string $table
@return array|mixed
|
[
"Get",
"value",
"from",
"table"
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Websocket/Rooms/TableRoom.php#L193-L200
|
220,625
|
swooletw/laravel-swoole
|
src/Websocket/Rooms/TableRoom.php
|
TableRoom.checkTable
|
protected function checkTable(string $table)
{
if (! property_exists($this, $table) || ! $this->$table instanceof Table) {
throw new \InvalidArgumentException("Invalid table name: `{$table}`.");
}
}
|
php
|
protected function checkTable(string $table)
{
if (! property_exists($this, $table) || ! $this->$table instanceof Table) {
throw new \InvalidArgumentException("Invalid table name: `{$table}`.");
}
}
|
[
"protected",
"function",
"checkTable",
"(",
"string",
"$",
"table",
")",
"{",
"if",
"(",
"!",
"property_exists",
"(",
"$",
"this",
",",
"$",
"table",
")",
"||",
"!",
"$",
"this",
"->",
"$",
"table",
"instanceof",
"Table",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Invalid table name: `{$table}`.\"",
")",
";",
"}",
"}"
] |
Check table for exists
@param string $table
|
[
"Check",
"table",
"for",
"exists"
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Websocket/Rooms/TableRoom.php#L207-L212
|
220,626
|
swooletw/laravel-swoole
|
src/Websocket/SocketIO/SocketIOParser.php
|
SocketIOParser.encode
|
public function encode(string $event, $data)
{
$packet = Packet::MESSAGE . Packet::EVENT;
$shouldEncode = is_array($data) || is_object($data);
$data = $shouldEncode ? json_encode($data) : $data;
$format = $shouldEncode ? '["%s",%s]' : '["%s","%s"]';
return $packet . sprintf($format, $event, $data);
}
|
php
|
public function encode(string $event, $data)
{
$packet = Packet::MESSAGE . Packet::EVENT;
$shouldEncode = is_array($data) || is_object($data);
$data = $shouldEncode ? json_encode($data) : $data;
$format = $shouldEncode ? '["%s",%s]' : '["%s","%s"]';
return $packet . sprintf($format, $event, $data);
}
|
[
"public",
"function",
"encode",
"(",
"string",
"$",
"event",
",",
"$",
"data",
")",
"{",
"$",
"packet",
"=",
"Packet",
"::",
"MESSAGE",
".",
"Packet",
"::",
"EVENT",
";",
"$",
"shouldEncode",
"=",
"is_array",
"(",
"$",
"data",
")",
"||",
"is_object",
"(",
"$",
"data",
")",
";",
"$",
"data",
"=",
"$",
"shouldEncode",
"?",
"json_encode",
"(",
"$",
"data",
")",
":",
"$",
"data",
";",
"$",
"format",
"=",
"$",
"shouldEncode",
"?",
"'[\"%s\",%s]'",
":",
"'[\"%s\",\"%s\"]'",
";",
"return",
"$",
"packet",
".",
"sprintf",
"(",
"$",
"format",
",",
"$",
"event",
",",
"$",
"data",
")",
";",
"}"
] |
Encode output payload for websocket push.
@param string $event
@param mixed $data
@return mixed
|
[
"Encode",
"output",
"payload",
"for",
"websocket",
"push",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Websocket/SocketIO/SocketIOParser.php#L28-L36
|
220,627
|
swooletw/laravel-swoole
|
src/Websocket/SocketIO/SocketIOParser.php
|
SocketIOParser.decode
|
public function decode($frame)
{
$payload = Packet::getPayload($frame->data);
return [
'event' => $payload['event'] ?? null,
'data' => $payload['data'] ?? null,
];
}
|
php
|
public function decode($frame)
{
$payload = Packet::getPayload($frame->data);
return [
'event' => $payload['event'] ?? null,
'data' => $payload['data'] ?? null,
];
}
|
[
"public",
"function",
"decode",
"(",
"$",
"frame",
")",
"{",
"$",
"payload",
"=",
"Packet",
"::",
"getPayload",
"(",
"$",
"frame",
"->",
"data",
")",
";",
"return",
"[",
"'event'",
"=>",
"$",
"payload",
"[",
"'event'",
"]",
"??",
"null",
",",
"'data'",
"=>",
"$",
"payload",
"[",
"'data'",
"]",
"??",
"null",
",",
"]",
";",
"}"
] |
Decode message from websocket client.
Define and return payload here.
@param \Swoole\Websocket\Frame $frame
@return array
|
[
"Decode",
"message",
"from",
"websocket",
"client",
".",
"Define",
"and",
"return",
"payload",
"here",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Websocket/SocketIO/SocketIOParser.php#L46-L54
|
220,628
|
swooletw/laravel-swoole
|
src/Websocket/Authenticatable.php
|
Authenticatable.logout
|
public function logout()
{
if (is_null($userId = $this->getUserId())) {
return null;
}
return $this->leave(static::USER_PREFIX . $userId);
}
|
php
|
public function logout()
{
if (is_null($userId = $this->getUserId())) {
return null;
}
return $this->leave(static::USER_PREFIX . $userId);
}
|
[
"public",
"function",
"logout",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"userId",
"=",
"$",
"this",
"->",
"getUserId",
"(",
")",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"leave",
"(",
"static",
"::",
"USER_PREFIX",
".",
"$",
"userId",
")",
";",
"}"
] |
Logout with current sender's fd.
@return mixed
|
[
"Logout",
"with",
"current",
"sender",
"s",
"fd",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Websocket/Authenticatable.php#L46-L53
|
220,629
|
swooletw/laravel-swoole
|
src/Websocket/Authenticatable.php
|
Authenticatable.toUser
|
public function toUser($users)
{
$users = is_object($users) ? func_get_args() : $users;
$userIds = array_map(function (AuthenticatableContract $user) {
$this->checkUser($user);
return $user->getAuthIdentifier();
}, $users);
return $this->toUserId($userIds);
}
|
php
|
public function toUser($users)
{
$users = is_object($users) ? func_get_args() : $users;
$userIds = array_map(function (AuthenticatableContract $user) {
$this->checkUser($user);
return $user->getAuthIdentifier();
}, $users);
return $this->toUserId($userIds);
}
|
[
"public",
"function",
"toUser",
"(",
"$",
"users",
")",
"{",
"$",
"users",
"=",
"is_object",
"(",
"$",
"users",
")",
"?",
"func_get_args",
"(",
")",
":",
"$",
"users",
";",
"$",
"userIds",
"=",
"array_map",
"(",
"function",
"(",
"AuthenticatableContract",
"$",
"user",
")",
"{",
"$",
"this",
"->",
"checkUser",
"(",
"$",
"user",
")",
";",
"return",
"$",
"user",
"->",
"getAuthIdentifier",
"(",
")",
";",
"}",
",",
"$",
"users",
")",
";",
"return",
"$",
"this",
"->",
"toUserId",
"(",
"$",
"userIds",
")",
";",
"}"
] |
Set multiple recepients' fds by users.
@param $users
@return \SwooleTW\Http\Websocket\Authenticatable
|
[
"Set",
"multiple",
"recepients",
"fds",
"by",
"users",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Websocket/Authenticatable.php#L62-L73
|
220,630
|
swooletw/laravel-swoole
|
src/Websocket/Authenticatable.php
|
Authenticatable.toUserId
|
public function toUserId($userIds)
{
$userIds = is_string($userIds) || is_integer($userIds) ? func_get_args() : $userIds;
foreach ($userIds as $userId) {
$fds = $this->room->getClients(static::USER_PREFIX . $userId);
$this->to($fds);
}
return $this;
}
|
php
|
public function toUserId($userIds)
{
$userIds = is_string($userIds) || is_integer($userIds) ? func_get_args() : $userIds;
foreach ($userIds as $userId) {
$fds = $this->room->getClients(static::USER_PREFIX . $userId);
$this->to($fds);
}
return $this;
}
|
[
"public",
"function",
"toUserId",
"(",
"$",
"userIds",
")",
"{",
"$",
"userIds",
"=",
"is_string",
"(",
"$",
"userIds",
")",
"||",
"is_integer",
"(",
"$",
"userIds",
")",
"?",
"func_get_args",
"(",
")",
":",
"$",
"userIds",
";",
"foreach",
"(",
"$",
"userIds",
"as",
"$",
"userId",
")",
"{",
"$",
"fds",
"=",
"$",
"this",
"->",
"room",
"->",
"getClients",
"(",
"static",
"::",
"USER_PREFIX",
".",
"$",
"userId",
")",
";",
"$",
"this",
"->",
"to",
"(",
"$",
"fds",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Set multiple recepients' fds by userIds.
@param $userIds
@return \SwooleTW\Http\Websocket\Authenticatable
|
[
"Set",
"multiple",
"recepients",
"fds",
"by",
"userIds",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Websocket/Authenticatable.php#L82-L92
|
220,631
|
swooletw/laravel-swoole
|
src/Websocket/Authenticatable.php
|
Authenticatable.getUserId
|
public function getUserId()
{
if (! is_null($this->userId)) {
return $this->userId;
}
$rooms = $this->room->getRooms($this->getSender());
foreach ($rooms as $room) {
if (count($explode = explode(static::USER_PREFIX, $room)) === 2) {
$this->userId = $explode[1];
}
}
return $this->userId;
}
|
php
|
public function getUserId()
{
if (! is_null($this->userId)) {
return $this->userId;
}
$rooms = $this->room->getRooms($this->getSender());
foreach ($rooms as $room) {
if (count($explode = explode(static::USER_PREFIX, $room)) === 2) {
$this->userId = $explode[1];
}
}
return $this->userId;
}
|
[
"public",
"function",
"getUserId",
"(",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"userId",
")",
")",
"{",
"return",
"$",
"this",
"->",
"userId",
";",
"}",
"$",
"rooms",
"=",
"$",
"this",
"->",
"room",
"->",
"getRooms",
"(",
"$",
"this",
"->",
"getSender",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"rooms",
"as",
"$",
"room",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"explode",
"=",
"explode",
"(",
"static",
"::",
"USER_PREFIX",
",",
"$",
"room",
")",
")",
"===",
"2",
")",
"{",
"$",
"this",
"->",
"userId",
"=",
"$",
"explode",
"[",
"1",
"]",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"userId",
";",
"}"
] |
Get current auth user id by sender's fd.
|
[
"Get",
"current",
"auth",
"user",
"id",
"by",
"sender",
"s",
"fd",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Websocket/Authenticatable.php#L97-L112
|
220,632
|
swooletw/laravel-swoole
|
src/Transformers/Request.php
|
Request.createIlluminateRequest
|
protected function createIlluminateRequest($get, $post, $cookie, $files, $server, $content = null)
{
IlluminateRequest::enableHttpMethodParameterOverride();
/*
|--------------------------------------------------------------------------
| Copy from \Symfony\Component\HttpFoundation\Request::createFromGlobals().
|--------------------------------------------------------------------------
|
| With the php's bug #66606, the php's built-in web server
| stores the Content-Type and Content-Length header values in
| HTTP_CONTENT_TYPE and HTTP_CONTENT_LENGTH fields.
|
*/
if ('cli-server' === PHP_SAPI) {
if (array_key_exists('HTTP_CONTENT_LENGTH', $server)) {
$server['CONTENT_LENGTH'] = $server['HTTP_CONTENT_LENGTH'];
}
if (array_key_exists('HTTP_CONTENT_TYPE', $server)) {
$server['CONTENT_TYPE'] = $server['HTTP_CONTENT_TYPE'];
}
}
$request = new SymfonyRequest($get, $post, [], $cookie, $files, $server, $content);
if (0 === strpos($request->headers->get('CONTENT_TYPE'), 'application/x-www-form-urlencoded')
&& in_array(strtoupper($request->server->get('REQUEST_METHOD', 'GET')), ['PUT', 'DELETE', 'PATCH'])
) {
parse_str($request->getContent(), $data);
$request->request = new ParameterBag($data);
}
$this->illuminateRequest = IlluminateRequest::createFromBase($request);
}
|
php
|
protected function createIlluminateRequest($get, $post, $cookie, $files, $server, $content = null)
{
IlluminateRequest::enableHttpMethodParameterOverride();
/*
|--------------------------------------------------------------------------
| Copy from \Symfony\Component\HttpFoundation\Request::createFromGlobals().
|--------------------------------------------------------------------------
|
| With the php's bug #66606, the php's built-in web server
| stores the Content-Type and Content-Length header values in
| HTTP_CONTENT_TYPE and HTTP_CONTENT_LENGTH fields.
|
*/
if ('cli-server' === PHP_SAPI) {
if (array_key_exists('HTTP_CONTENT_LENGTH', $server)) {
$server['CONTENT_LENGTH'] = $server['HTTP_CONTENT_LENGTH'];
}
if (array_key_exists('HTTP_CONTENT_TYPE', $server)) {
$server['CONTENT_TYPE'] = $server['HTTP_CONTENT_TYPE'];
}
}
$request = new SymfonyRequest($get, $post, [], $cookie, $files, $server, $content);
if (0 === strpos($request->headers->get('CONTENT_TYPE'), 'application/x-www-form-urlencoded')
&& in_array(strtoupper($request->server->get('REQUEST_METHOD', 'GET')), ['PUT', 'DELETE', 'PATCH'])
) {
parse_str($request->getContent(), $data);
$request->request = new ParameterBag($data);
}
$this->illuminateRequest = IlluminateRequest::createFromBase($request);
}
|
[
"protected",
"function",
"createIlluminateRequest",
"(",
"$",
"get",
",",
"$",
"post",
",",
"$",
"cookie",
",",
"$",
"files",
",",
"$",
"server",
",",
"$",
"content",
"=",
"null",
")",
"{",
"IlluminateRequest",
"::",
"enableHttpMethodParameterOverride",
"(",
")",
";",
"/*\n |--------------------------------------------------------------------------\n | Copy from \\Symfony\\Component\\HttpFoundation\\Request::createFromGlobals().\n |--------------------------------------------------------------------------\n |\n | With the php's bug #66606, the php's built-in web server\n | stores the Content-Type and Content-Length header values in\n | HTTP_CONTENT_TYPE and HTTP_CONTENT_LENGTH fields.\n |\n */",
"if",
"(",
"'cli-server'",
"===",
"PHP_SAPI",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"'HTTP_CONTENT_LENGTH'",
",",
"$",
"server",
")",
")",
"{",
"$",
"server",
"[",
"'CONTENT_LENGTH'",
"]",
"=",
"$",
"server",
"[",
"'HTTP_CONTENT_LENGTH'",
"]",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"'HTTP_CONTENT_TYPE'",
",",
"$",
"server",
")",
")",
"{",
"$",
"server",
"[",
"'CONTENT_TYPE'",
"]",
"=",
"$",
"server",
"[",
"'HTTP_CONTENT_TYPE'",
"]",
";",
"}",
"}",
"$",
"request",
"=",
"new",
"SymfonyRequest",
"(",
"$",
"get",
",",
"$",
"post",
",",
"[",
"]",
",",
"$",
"cookie",
",",
"$",
"files",
",",
"$",
"server",
",",
"$",
"content",
")",
";",
"if",
"(",
"0",
"===",
"strpos",
"(",
"$",
"request",
"->",
"headers",
"->",
"get",
"(",
"'CONTENT_TYPE'",
")",
",",
"'application/x-www-form-urlencoded'",
")",
"&&",
"in_array",
"(",
"strtoupper",
"(",
"$",
"request",
"->",
"server",
"->",
"get",
"(",
"'REQUEST_METHOD'",
",",
"'GET'",
")",
")",
",",
"[",
"'PUT'",
",",
"'DELETE'",
",",
"'PATCH'",
"]",
")",
")",
"{",
"parse_str",
"(",
"$",
"request",
"->",
"getContent",
"(",
")",
",",
"$",
"data",
")",
";",
"$",
"request",
"->",
"request",
"=",
"new",
"ParameterBag",
"(",
"$",
"data",
")",
";",
"}",
"$",
"this",
"->",
"illuminateRequest",
"=",
"IlluminateRequest",
"::",
"createFromBase",
"(",
"$",
"request",
")",
";",
"}"
] |
Create Illuminate Request.
@param array $get
@param array $post
@param array $cookie
@param array $files
@param array $server
@param string $content
@return void
|
[
"Create",
"Illuminate",
"Request",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Transformers/Request.php#L69-L103
|
220,633
|
swooletw/laravel-swoole
|
src/Transformers/Request.php
|
Request.toIlluminateParameters
|
protected static function toIlluminateParameters(SwooleRequest $request)
{
$get = $request->get ?? [];
$post = $request->post ?? [];
$cookie = $request->cookie ?? [];
$files = $request->files ?? [];
$header = $request->header ?? [];
$server = $request->server ?? [];
$server = static::transformServerParameters($server, $header);
$content = $request->rawContent();
return [$get, $post, $cookie, $files, $server, $content];
}
|
php
|
protected static function toIlluminateParameters(SwooleRequest $request)
{
$get = $request->get ?? [];
$post = $request->post ?? [];
$cookie = $request->cookie ?? [];
$files = $request->files ?? [];
$header = $request->header ?? [];
$server = $request->server ?? [];
$server = static::transformServerParameters($server, $header);
$content = $request->rawContent();
return [$get, $post, $cookie, $files, $server, $content];
}
|
[
"protected",
"static",
"function",
"toIlluminateParameters",
"(",
"SwooleRequest",
"$",
"request",
")",
"{",
"$",
"get",
"=",
"$",
"request",
"->",
"get",
"??",
"[",
"]",
";",
"$",
"post",
"=",
"$",
"request",
"->",
"post",
"??",
"[",
"]",
";",
"$",
"cookie",
"=",
"$",
"request",
"->",
"cookie",
"??",
"[",
"]",
";",
"$",
"files",
"=",
"$",
"request",
"->",
"files",
"??",
"[",
"]",
";",
"$",
"header",
"=",
"$",
"request",
"->",
"header",
"??",
"[",
"]",
";",
"$",
"server",
"=",
"$",
"request",
"->",
"server",
"??",
"[",
"]",
";",
"$",
"server",
"=",
"static",
"::",
"transformServerParameters",
"(",
"$",
"server",
",",
"$",
"header",
")",
";",
"$",
"content",
"=",
"$",
"request",
"->",
"rawContent",
"(",
")",
";",
"return",
"[",
"$",
"get",
",",
"$",
"post",
",",
"$",
"cookie",
",",
"$",
"files",
",",
"$",
"server",
",",
"$",
"content",
"]",
";",
"}"
] |
Transforms request parameters.
@param \Swoole\Http\Request $request
@return array
|
[
"Transforms",
"request",
"parameters",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Transformers/Request.php#L128-L140
|
220,634
|
swooletw/laravel-swoole
|
src/Transformers/Request.php
|
Request.handleStatic
|
public static function handleStatic($swooleRequest, $swooleResponse, string $publicPath)
{
$uri = $swooleRequest->server['request_uri'] ?? '';
$extension = strtok(pathinfo($uri, PATHINFO_EXTENSION), '?');
$fileName = $publicPath . $uri;
if ($extension && in_array($extension, static::EXTENSION_BLACKLIST)) {
return false;
}
if (! is_file($fileName) || ! filesize($fileName)) {
return false;
}
$swooleResponse->status(IlluminateResponse::HTTP_OK);
$swooleResponse->header('Content-Type', MimeType::get($extension));
$swooleResponse->sendfile($fileName);
return true;
}
|
php
|
public static function handleStatic($swooleRequest, $swooleResponse, string $publicPath)
{
$uri = $swooleRequest->server['request_uri'] ?? '';
$extension = strtok(pathinfo($uri, PATHINFO_EXTENSION), '?');
$fileName = $publicPath . $uri;
if ($extension && in_array($extension, static::EXTENSION_BLACKLIST)) {
return false;
}
if (! is_file($fileName) || ! filesize($fileName)) {
return false;
}
$swooleResponse->status(IlluminateResponse::HTTP_OK);
$swooleResponse->header('Content-Type', MimeType::get($extension));
$swooleResponse->sendfile($fileName);
return true;
}
|
[
"public",
"static",
"function",
"handleStatic",
"(",
"$",
"swooleRequest",
",",
"$",
"swooleResponse",
",",
"string",
"$",
"publicPath",
")",
"{",
"$",
"uri",
"=",
"$",
"swooleRequest",
"->",
"server",
"[",
"'request_uri'",
"]",
"??",
"''",
";",
"$",
"extension",
"=",
"strtok",
"(",
"pathinfo",
"(",
"$",
"uri",
",",
"PATHINFO_EXTENSION",
")",
",",
"'?'",
")",
";",
"$",
"fileName",
"=",
"$",
"publicPath",
".",
"$",
"uri",
";",
"if",
"(",
"$",
"extension",
"&&",
"in_array",
"(",
"$",
"extension",
",",
"static",
"::",
"EXTENSION_BLACKLIST",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"is_file",
"(",
"$",
"fileName",
")",
"||",
"!",
"filesize",
"(",
"$",
"fileName",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"swooleResponse",
"->",
"status",
"(",
"IlluminateResponse",
"::",
"HTTP_OK",
")",
";",
"$",
"swooleResponse",
"->",
"header",
"(",
"'Content-Type'",
",",
"MimeType",
"::",
"get",
"(",
"$",
"extension",
")",
")",
";",
"$",
"swooleResponse",
"->",
"sendfile",
"(",
"$",
"fileName",
")",
";",
"return",
"true",
";",
"}"
] |
Handle static request.
@param \Swoole\Http\Request $swooleRequest
@param \Swoole\Http\Response $swooleResponse
@param string $publicPath
@return boolean
|
[
"Handle",
"static",
"request",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Transformers/Request.php#L182-L201
|
220,635
|
swooletw/laravel-swoole
|
src/Server/AccessOutput.php
|
AccessOutput.log
|
public function log(Request $request, Response $response): void
{
$host = $request->url();
$method = $request->method();
$agent = $request->userAgent();
$date = $this->date($response->getDate());
$status = $response->status();
$style = $this->style($status);
$this->output->writeln(
sprintf("%s %s %s <$style>%d</$style> %s", $host, $date, $method, $status, $agent)
);
}
|
php
|
public function log(Request $request, Response $response): void
{
$host = $request->url();
$method = $request->method();
$agent = $request->userAgent();
$date = $this->date($response->getDate());
$status = $response->status();
$style = $this->style($status);
$this->output->writeln(
sprintf("%s %s %s <$style>%d</$style> %s", $host, $date, $method, $status, $agent)
);
}
|
[
"public",
"function",
"log",
"(",
"Request",
"$",
"request",
",",
"Response",
"$",
"response",
")",
":",
"void",
"{",
"$",
"host",
"=",
"$",
"request",
"->",
"url",
"(",
")",
";",
"$",
"method",
"=",
"$",
"request",
"->",
"method",
"(",
")",
";",
"$",
"agent",
"=",
"$",
"request",
"->",
"userAgent",
"(",
")",
";",
"$",
"date",
"=",
"$",
"this",
"->",
"date",
"(",
"$",
"response",
"->",
"getDate",
"(",
")",
")",
";",
"$",
"status",
"=",
"$",
"response",
"->",
"status",
"(",
")",
";",
"$",
"style",
"=",
"$",
"this",
"->",
"style",
"(",
"$",
"status",
")",
";",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"sprintf",
"(",
"\"%s %s %s <$style>%d</$style> %s\"",
",",
"$",
"host",
",",
"$",
"date",
",",
"$",
"method",
",",
"$",
"status",
",",
"$",
"agent",
")",
")",
";",
"}"
] |
Access log.
@param \Illuminate\Http\Request $request
@param \Symfony\Component\HttpFoundation\Response $response
|
[
"Access",
"log",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Server/AccessOutput.php#L38-L50
|
220,636
|
swooletw/laravel-swoole
|
src/Websocket/Rooms/RedisRoom.php
|
RedisRoom.setRedis
|
public function setRedis(?RedisClient $redis = null)
{
if (! $redis) {
$server = Arr::get($this->config, 'server', []);
$options = Arr::get($this->config, 'options', []);
// forbid setting prefix from options
if (Arr::has($options, 'prefix')) {
$options = Arr::except($options, 'prefix');
}
$redis = new RedisClient($server, $options);
}
$this->redis = $redis;
}
|
php
|
public function setRedis(?RedisClient $redis = null)
{
if (! $redis) {
$server = Arr::get($this->config, 'server', []);
$options = Arr::get($this->config, 'options', []);
// forbid setting prefix from options
if (Arr::has($options, 'prefix')) {
$options = Arr::except($options, 'prefix');
}
$redis = new RedisClient($server, $options);
}
$this->redis = $redis;
}
|
[
"public",
"function",
"setRedis",
"(",
"?",
"RedisClient",
"$",
"redis",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"redis",
")",
"{",
"$",
"server",
"=",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"config",
",",
"'server'",
",",
"[",
"]",
")",
";",
"$",
"options",
"=",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"config",
",",
"'options'",
",",
"[",
"]",
")",
";",
"// forbid setting prefix from options",
"if",
"(",
"Arr",
"::",
"has",
"(",
"$",
"options",
",",
"'prefix'",
")",
")",
"{",
"$",
"options",
"=",
"Arr",
"::",
"except",
"(",
"$",
"options",
",",
"'prefix'",
")",
";",
"}",
"$",
"redis",
"=",
"new",
"RedisClient",
"(",
"$",
"server",
",",
"$",
"options",
")",
";",
"}",
"$",
"this",
"->",
"redis",
"=",
"$",
"redis",
";",
"}"
] |
Set redis client.
@param \Predis\Client|null $redis
|
[
"Set",
"redis",
"client",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Websocket/Rooms/RedisRoom.php#L58-L73
|
220,637
|
swooletw/laravel-swoole
|
src/Websocket/Rooms/RedisRoom.php
|
RedisRoom.addValue
|
public function addValue($key, array $values, string $table)
{
$this->checkTable($table);
$redisKey = $this->getKey($key, $table);
$this->redis->pipeline(function (Pipeline $pipe) use ($redisKey, $values) {
foreach ($values as $value) {
$pipe->sadd($redisKey, $value);
}
});
return $this;
}
|
php
|
public function addValue($key, array $values, string $table)
{
$this->checkTable($table);
$redisKey = $this->getKey($key, $table);
$this->redis->pipeline(function (Pipeline $pipe) use ($redisKey, $values) {
foreach ($values as $value) {
$pipe->sadd($redisKey, $value);
}
});
return $this;
}
|
[
"public",
"function",
"addValue",
"(",
"$",
"key",
",",
"array",
"$",
"values",
",",
"string",
"$",
"table",
")",
"{",
"$",
"this",
"->",
"checkTable",
"(",
"$",
"table",
")",
";",
"$",
"redisKey",
"=",
"$",
"this",
"->",
"getKey",
"(",
"$",
"key",
",",
"$",
"table",
")",
";",
"$",
"this",
"->",
"redis",
"->",
"pipeline",
"(",
"function",
"(",
"Pipeline",
"$",
"pipe",
")",
"use",
"(",
"$",
"redisKey",
",",
"$",
"values",
")",
"{",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"$",
"pipe",
"->",
"sadd",
"(",
"$",
"redisKey",
",",
"$",
"value",
")",
";",
"}",
"}",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Add value to redis.
@param $key
@param array $values
@param string $table
@return $this
|
[
"Add",
"value",
"to",
"redis",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Websocket/Rooms/RedisRoom.php#L137-L149
|
220,638
|
swooletw/laravel-swoole
|
src/Websocket/Rooms/RedisRoom.php
|
RedisRoom.removeValue
|
public function removeValue($key, array $values, string $table)
{
$this->checkTable($table);
$redisKey = $this->getKey($key, $table);
$this->redis->pipeline(function (Pipeline $pipe) use ($redisKey, $values) {
foreach ($values as $value) {
$pipe->srem($redisKey, $value);
}
});
return $this;
}
|
php
|
public function removeValue($key, array $values, string $table)
{
$this->checkTable($table);
$redisKey = $this->getKey($key, $table);
$this->redis->pipeline(function (Pipeline $pipe) use ($redisKey, $values) {
foreach ($values as $value) {
$pipe->srem($redisKey, $value);
}
});
return $this;
}
|
[
"public",
"function",
"removeValue",
"(",
"$",
"key",
",",
"array",
"$",
"values",
",",
"string",
"$",
"table",
")",
"{",
"$",
"this",
"->",
"checkTable",
"(",
"$",
"table",
")",
";",
"$",
"redisKey",
"=",
"$",
"this",
"->",
"getKey",
"(",
"$",
"key",
",",
"$",
"table",
")",
";",
"$",
"this",
"->",
"redis",
"->",
"pipeline",
"(",
"function",
"(",
"Pipeline",
"$",
"pipe",
")",
"use",
"(",
"$",
"redisKey",
",",
"$",
"values",
")",
"{",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"$",
"pipe",
"->",
"srem",
"(",
"$",
"redisKey",
",",
"$",
"value",
")",
";",
"}",
"}",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Remove value from reddis.
@param $key
@param array $values
@param string $table
@return $this
|
[
"Remove",
"value",
"from",
"reddis",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Websocket/Rooms/RedisRoom.php#L160-L172
|
220,639
|
swooletw/laravel-swoole
|
src/Websocket/Rooms/RedisRoom.php
|
RedisRoom.cleanRooms
|
protected function cleanRooms(): void
{
if (count($keys = $this->redis->keys("{$this->prefix}*"))) {
$this->redis->del($keys);
}
}
|
php
|
protected function cleanRooms(): void
{
if (count($keys = $this->redis->keys("{$this->prefix}*"))) {
$this->redis->del($keys);
}
}
|
[
"protected",
"function",
"cleanRooms",
"(",
")",
":",
"void",
"{",
"if",
"(",
"count",
"(",
"$",
"keys",
"=",
"$",
"this",
"->",
"redis",
"->",
"keys",
"(",
"\"{$this->prefix}*\"",
")",
")",
")",
"{",
"$",
"this",
"->",
"redis",
"->",
"del",
"(",
"$",
"keys",
")",
";",
"}",
"}"
] |
Clean all rooms.
|
[
"Clean",
"all",
"rooms",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Websocket/Rooms/RedisRoom.php#L241-L246
|
220,640
|
swooletw/laravel-swoole
|
src/Websocket/Websocket.php
|
Websocket.to
|
public function to($values): self
{
$values = is_string($values) || is_integer($values) ? func_get_args() : $values;
foreach ($values as $value) {
if (! in_array($value, $this->to)) {
$this->to[] = $value;
}
}
return $this;
}
|
php
|
public function to($values): self
{
$values = is_string($values) || is_integer($values) ? func_get_args() : $values;
foreach ($values as $value) {
if (! in_array($value, $this->to)) {
$this->to[] = $value;
}
}
return $this;
}
|
[
"public",
"function",
"to",
"(",
"$",
"values",
")",
":",
"self",
"{",
"$",
"values",
"=",
"is_string",
"(",
"$",
"values",
")",
"||",
"is_integer",
"(",
"$",
"values",
")",
"?",
"func_get_args",
"(",
")",
":",
"$",
"values",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"value",
",",
"$",
"this",
"->",
"to",
")",
")",
"{",
"$",
"this",
"->",
"to",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Set multiple recipients fd or room names.
@param integer, string, array
@return $this
|
[
"Set",
"multiple",
"recipients",
"fd",
"or",
"room",
"names",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Websocket/Websocket.php#L110-L121
|
220,641
|
swooletw/laravel-swoole
|
src/Websocket/Websocket.php
|
Websocket.join
|
public function join($rooms): self
{
$rooms = is_string($rooms) || is_integer($rooms) ? func_get_args() : $rooms;
$this->room->add($this->sender, $rooms);
return $this;
}
|
php
|
public function join($rooms): self
{
$rooms = is_string($rooms) || is_integer($rooms) ? func_get_args() : $rooms;
$this->room->add($this->sender, $rooms);
return $this;
}
|
[
"public",
"function",
"join",
"(",
"$",
"rooms",
")",
":",
"self",
"{",
"$",
"rooms",
"=",
"is_string",
"(",
"$",
"rooms",
")",
"||",
"is_integer",
"(",
"$",
"rooms",
")",
"?",
"func_get_args",
"(",
")",
":",
"$",
"rooms",
";",
"$",
"this",
"->",
"room",
"->",
"add",
"(",
"$",
"this",
"->",
"sender",
",",
"$",
"rooms",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Join sender to multiple rooms.
@param string, array $rooms
@return $this
|
[
"Join",
"sender",
"to",
"multiple",
"rooms",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Websocket/Websocket.php#L130-L137
|
220,642
|
swooletw/laravel-swoole
|
src/Websocket/Websocket.php
|
Websocket.leave
|
public function leave($rooms = []): self
{
$rooms = is_string($rooms) || is_integer($rooms) ? func_get_args() : $rooms;
$this->room->delete($this->sender, $rooms);
return $this;
}
|
php
|
public function leave($rooms = []): self
{
$rooms = is_string($rooms) || is_integer($rooms) ? func_get_args() : $rooms;
$this->room->delete($this->sender, $rooms);
return $this;
}
|
[
"public",
"function",
"leave",
"(",
"$",
"rooms",
"=",
"[",
"]",
")",
":",
"self",
"{",
"$",
"rooms",
"=",
"is_string",
"(",
"$",
"rooms",
")",
"||",
"is_integer",
"(",
"$",
"rooms",
")",
"?",
"func_get_args",
"(",
")",
":",
"$",
"rooms",
";",
"$",
"this",
"->",
"room",
"->",
"delete",
"(",
"$",
"this",
"->",
"sender",
",",
"$",
"rooms",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Make sender leave multiple rooms.
@param array $rooms
@return $this
|
[
"Make",
"sender",
"leave",
"multiple",
"rooms",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Websocket/Websocket.php#L146-L153
|
220,643
|
swooletw/laravel-swoole
|
src/Websocket/Websocket.php
|
Websocket.on
|
public function on(string $event, $callback)
{
if (! is_string($callback) && ! is_callable($callback)) {
throw new InvalidArgumentException(
'Invalid websocket callback. Must be a string or callable.'
);
}
$this->callbacks[$event] = $callback;
return $this;
}
|
php
|
public function on(string $event, $callback)
{
if (! is_string($callback) && ! is_callable($callback)) {
throw new InvalidArgumentException(
'Invalid websocket callback. Must be a string or callable.'
);
}
$this->callbacks[$event] = $callback;
return $this;
}
|
[
"public",
"function",
"on",
"(",
"string",
"$",
"event",
",",
"$",
"callback",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"callback",
")",
"&&",
"!",
"is_callable",
"(",
"$",
"callback",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Invalid websocket callback. Must be a string or callable.'",
")",
";",
"}",
"$",
"this",
"->",
"callbacks",
"[",
"$",
"event",
"]",
"=",
"$",
"callback",
";",
"return",
"$",
"this",
";",
"}"
] |
Register an event name with a closure binding.
@param string
@param callback
@return $this
|
[
"Register",
"an",
"event",
"name",
"with",
"a",
"closure",
"binding",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Websocket/Websocket.php#L214-L225
|
220,644
|
swooletw/laravel-swoole
|
src/Websocket/Websocket.php
|
Websocket.close
|
public function close(int $fd = null)
{
return App::make(Server::class)->close($fd ?: $this->sender);
}
|
php
|
public function close(int $fd = null)
{
return App::make(Server::class)->close($fd ?: $this->sender);
}
|
[
"public",
"function",
"close",
"(",
"int",
"$",
"fd",
"=",
"null",
")",
"{",
"return",
"App",
"::",
"make",
"(",
"Server",
"::",
"class",
")",
"->",
"close",
"(",
"$",
"fd",
"?",
":",
"$",
"this",
"->",
"sender",
")",
";",
"}"
] |
Close current connection.
@param integer
@return boolean
|
[
"Close",
"current",
"connection",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Websocket/Websocket.php#L275-L278
|
220,645
|
swooletw/laravel-swoole
|
src/Websocket/Websocket.php
|
Websocket.getFds
|
protected function getFds()
{
$fds = array_filter($this->to, function ($value) {
return is_integer($value);
});
$rooms = array_diff($this->to, $fds);
foreach ($rooms as $room) {
$clients = $this->room->getClients($room);
// fallback fd with wrong type back to fds array
if (empty($clients) && is_numeric($room)) {
$fds[] = $room;
} else {
$fds = array_merge($fds, $clients);
}
}
return array_values(array_unique($fds));
}
|
php
|
protected function getFds()
{
$fds = array_filter($this->to, function ($value) {
return is_integer($value);
});
$rooms = array_diff($this->to, $fds);
foreach ($rooms as $room) {
$clients = $this->room->getClients($room);
// fallback fd with wrong type back to fds array
if (empty($clients) && is_numeric($room)) {
$fds[] = $room;
} else {
$fds = array_merge($fds, $clients);
}
}
return array_values(array_unique($fds));
}
|
[
"protected",
"function",
"getFds",
"(",
")",
"{",
"$",
"fds",
"=",
"array_filter",
"(",
"$",
"this",
"->",
"to",
",",
"function",
"(",
"$",
"value",
")",
"{",
"return",
"is_integer",
"(",
"$",
"value",
")",
";",
"}",
")",
";",
"$",
"rooms",
"=",
"array_diff",
"(",
"$",
"this",
"->",
"to",
",",
"$",
"fds",
")",
";",
"foreach",
"(",
"$",
"rooms",
"as",
"$",
"room",
")",
"{",
"$",
"clients",
"=",
"$",
"this",
"->",
"room",
"->",
"getClients",
"(",
"$",
"room",
")",
";",
"// fallback fd with wrong type back to fds array",
"if",
"(",
"empty",
"(",
"$",
"clients",
")",
"&&",
"is_numeric",
"(",
"$",
"room",
")",
")",
"{",
"$",
"fds",
"[",
"]",
"=",
"$",
"room",
";",
"}",
"else",
"{",
"$",
"fds",
"=",
"array_merge",
"(",
"$",
"fds",
",",
"$",
"clients",
")",
";",
"}",
"}",
"return",
"array_values",
"(",
"array_unique",
"(",
"$",
"fds",
")",
")",
";",
"}"
] |
Get all fds we're going to push data to.
|
[
"Get",
"all",
"fds",
"we",
"re",
"going",
"to",
"push",
"data",
"to",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Websocket/Websocket.php#L321-L339
|
220,646
|
swooletw/laravel-swoole
|
src/Websocket/Websocket.php
|
Websocket.reset
|
public function reset($force = false)
{
$this->isBroadcast = false;
$this->to = [];
if ($force) {
$this->sender = null;
$this->userId = null;
}
return $this;
}
|
php
|
public function reset($force = false)
{
$this->isBroadcast = false;
$this->to = [];
if ($force) {
$this->sender = null;
$this->userId = null;
}
return $this;
}
|
[
"public",
"function",
"reset",
"(",
"$",
"force",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"isBroadcast",
"=",
"false",
";",
"$",
"this",
"->",
"to",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"force",
")",
"{",
"$",
"this",
"->",
"sender",
"=",
"null",
";",
"$",
"this",
"->",
"userId",
"=",
"null",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Reset some data status.
@param bool $force
@return $this
|
[
"Reset",
"some",
"data",
"status",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Websocket/Websocket.php#L348-L359
|
220,647
|
swooletw/laravel-swoole
|
src/Websocket/Websocket.php
|
Websocket.middleware
|
public function middleware($middleware = null)
{
if (is_null($middleware)) {
return $this->middleware;
}
if (is_string($middleware)) {
$middleware = func_get_args();
}
$this->middleware = array_unique(array_merge($this->middleware, $middleware));
return $this;
}
|
php
|
public function middleware($middleware = null)
{
if (is_null($middleware)) {
return $this->middleware;
}
if (is_string($middleware)) {
$middleware = func_get_args();
}
$this->middleware = array_unique(array_merge($this->middleware, $middleware));
return $this;
}
|
[
"public",
"function",
"middleware",
"(",
"$",
"middleware",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"middleware",
")",
")",
"{",
"return",
"$",
"this",
"->",
"middleware",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"middleware",
")",
")",
"{",
"$",
"middleware",
"=",
"func_get_args",
"(",
")",
";",
"}",
"$",
"this",
"->",
"middleware",
"=",
"array_unique",
"(",
"array_merge",
"(",
"$",
"this",
"->",
"middleware",
",",
"$",
"middleware",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Get or set middleware.
@param array|string|null $middleware
@return array|\SwooleTW\Http\Websocket\Websocket
|
[
"Get",
"or",
"set",
"middleware",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Websocket/Websocket.php#L368-L381
|
220,648
|
swooletw/laravel-swoole
|
src/Websocket/Websocket.php
|
Websocket.setContainer
|
public function setContainer(Container $container)
{
$pipeline = $this->pipeline;
$closure = function () use ($container) {
$this->container = $container;
};
$resetPipeline = $closure->bindTo($pipeline, $pipeline);
$resetPipeline();
return $this;
}
|
php
|
public function setContainer(Container $container)
{
$pipeline = $this->pipeline;
$closure = function () use ($container) {
$this->container = $container;
};
$resetPipeline = $closure->bindTo($pipeline, $pipeline);
$resetPipeline();
return $this;
}
|
[
"public",
"function",
"setContainer",
"(",
"Container",
"$",
"container",
")",
"{",
"$",
"pipeline",
"=",
"$",
"this",
"->",
"pipeline",
";",
"$",
"closure",
"=",
"function",
"(",
")",
"use",
"(",
"$",
"container",
")",
"{",
"$",
"this",
"->",
"container",
"=",
"$",
"container",
";",
"}",
";",
"$",
"resetPipeline",
"=",
"$",
"closure",
"->",
"bindTo",
"(",
"$",
"pipeline",
",",
"$",
"pipeline",
")",
";",
"$",
"resetPipeline",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Set container to pipeline.
@param \Illuminate\Contracts\Container\Container $container
@return $this
|
[
"Set",
"container",
"to",
"pipeline",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Websocket/Websocket.php#L398-L410
|
220,649
|
swooletw/laravel-swoole
|
src/Websocket/Websocket.php
|
Websocket.setRequestThroughMiddleware
|
protected function setRequestThroughMiddleware($request)
{
return $this->pipeline
->send($request)
->through($this->middleware)
->then(function ($request) {
return $request;
});
}
|
php
|
protected function setRequestThroughMiddleware($request)
{
return $this->pipeline
->send($request)
->through($this->middleware)
->then(function ($request) {
return $request;
});
}
|
[
"protected",
"function",
"setRequestThroughMiddleware",
"(",
"$",
"request",
")",
"{",
"return",
"$",
"this",
"->",
"pipeline",
"->",
"send",
"(",
"$",
"request",
")",
"->",
"through",
"(",
"$",
"this",
"->",
"middleware",
")",
"->",
"then",
"(",
"function",
"(",
"$",
"request",
")",
"{",
"return",
"$",
"request",
";",
"}",
")",
";",
"}"
] |
Set the given request through the middleware.
@param \Illuminate\Http\Request $request
@return \Illuminate\Http\Request
|
[
"Set",
"the",
"given",
"request",
"through",
"the",
"middleware",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Websocket/Websocket.php#L441-L449
|
220,650
|
swooletw/laravel-swoole
|
src/Concerns/InteractsWithWebsocket.php
|
InteractsWithWebsocket.isWebsocketPushPacket
|
protected function isWebsocketPushPacket($packet)
{
if (! is_array($packet)) {
return false;
}
return $this->isWebsocket
&& array_key_exists('action', $packet)
&& $packet['action'] === Websocket::PUSH_ACTION;
}
|
php
|
protected function isWebsocketPushPacket($packet)
{
if (! is_array($packet)) {
return false;
}
return $this->isWebsocket
&& array_key_exists('action', $packet)
&& $packet['action'] === Websocket::PUSH_ACTION;
}
|
[
"protected",
"function",
"isWebsocketPushPacket",
"(",
"$",
"packet",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"packet",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"isWebsocket",
"&&",
"array_key_exists",
"(",
"'action'",
",",
"$",
"packet",
")",
"&&",
"$",
"packet",
"[",
"'action'",
"]",
"===",
"Websocket",
"::",
"PUSH_ACTION",
";",
"}"
] |
Indicates if a packet is websocket push action.
@param mixed
|
[
"Indicates",
"if",
"a",
"packet",
"is",
"websocket",
"push",
"action",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Concerns/InteractsWithWebsocket.php#L159-L168
|
220,651
|
swooletw/laravel-swoole
|
src/Concerns/InteractsWithWebsocket.php
|
InteractsWithWebsocket.pushMessage
|
public function pushMessage($server, array $data)
{
$pusher = Pusher::make($data, $server);
$pusher->push($this->payloadParser->encode(
$pusher->getEvent(),
$pusher->getMessage()
));
}
|
php
|
public function pushMessage($server, array $data)
{
$pusher = Pusher::make($data, $server);
$pusher->push($this->payloadParser->encode(
$pusher->getEvent(),
$pusher->getMessage()
));
}
|
[
"public",
"function",
"pushMessage",
"(",
"$",
"server",
",",
"array",
"$",
"data",
")",
"{",
"$",
"pusher",
"=",
"Pusher",
"::",
"make",
"(",
"$",
"data",
",",
"$",
"server",
")",
";",
"$",
"pusher",
"->",
"push",
"(",
"$",
"this",
"->",
"payloadParser",
"->",
"encode",
"(",
"$",
"pusher",
"->",
"getEvent",
"(",
")",
",",
"$",
"pusher",
"->",
"getMessage",
"(",
")",
")",
")",
";",
"}"
] |
Push websocket message to clients.
@param \Swoole\Websocket\Server $server
@param mixed $data
|
[
"Push",
"websocket",
"message",
"to",
"clients",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Concerns/InteractsWithWebsocket.php#L177-L184
|
220,652
|
swooletw/laravel-swoole
|
src/Concerns/InteractsWithWebsocket.php
|
InteractsWithWebsocket.prepareWebsocket
|
protected function prepareWebsocket()
{
$config = $this->container->make('config');
$isWebsocket = $config->get('swoole_http.websocket.enabled');
$parser = $config->get('swoole_websocket.parser');
if ($isWebsocket) {
$this->events = array_merge($this->events ?? [], $this->wsEvents);
$this->isServerWebsocket = true;
$this->setPayloadParser(new $parser);
}
}
|
php
|
protected function prepareWebsocket()
{
$config = $this->container->make('config');
$isWebsocket = $config->get('swoole_http.websocket.enabled');
$parser = $config->get('swoole_websocket.parser');
if ($isWebsocket) {
$this->events = array_merge($this->events ?? [], $this->wsEvents);
$this->isServerWebsocket = true;
$this->setPayloadParser(new $parser);
}
}
|
[
"protected",
"function",
"prepareWebsocket",
"(",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"container",
"->",
"make",
"(",
"'config'",
")",
";",
"$",
"isWebsocket",
"=",
"$",
"config",
"->",
"get",
"(",
"'swoole_http.websocket.enabled'",
")",
";",
"$",
"parser",
"=",
"$",
"config",
"->",
"get",
"(",
"'swoole_websocket.parser'",
")",
";",
"if",
"(",
"$",
"isWebsocket",
")",
"{",
"$",
"this",
"->",
"events",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"events",
"??",
"[",
"]",
",",
"$",
"this",
"->",
"wsEvents",
")",
";",
"$",
"this",
"->",
"isServerWebsocket",
"=",
"true",
";",
"$",
"this",
"->",
"setPayloadParser",
"(",
"new",
"$",
"parser",
")",
";",
"}",
"}"
] |
Prepare settings if websocket is enabled.
|
[
"Prepare",
"settings",
"if",
"websocket",
"is",
"enabled",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Concerns/InteractsWithWebsocket.php#L211-L222
|
220,653
|
swooletw/laravel-swoole
|
src/Concerns/InteractsWithWebsocket.php
|
InteractsWithWebsocket.loadWebsocketRoutes
|
protected function loadWebsocketRoutes()
{
$routePath = $this->container->make('config')
->get('swoole_websocket.route_file');
if (! file_exists($routePath)) {
$routePath = __DIR__ . '/../../routes/websocket.php';
}
return require $routePath;
}
|
php
|
protected function loadWebsocketRoutes()
{
$routePath = $this->container->make('config')
->get('swoole_websocket.route_file');
if (! file_exists($routePath)) {
$routePath = __DIR__ . '/../../routes/websocket.php';
}
return require $routePath;
}
|
[
"protected",
"function",
"loadWebsocketRoutes",
"(",
")",
"{",
"$",
"routePath",
"=",
"$",
"this",
"->",
"container",
"->",
"make",
"(",
"'config'",
")",
"->",
"get",
"(",
"'swoole_websocket.route_file'",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"routePath",
")",
")",
"{",
"$",
"routePath",
"=",
"__DIR__",
".",
"'/../../routes/websocket.php'",
";",
"}",
"return",
"require",
"$",
"routePath",
";",
"}"
] |
Load websocket routes file.
|
[
"Load",
"websocket",
"routes",
"file",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Concerns/InteractsWithWebsocket.php#L324-L334
|
220,654
|
swooletw/laravel-swoole
|
src/Concerns/InteractsWithWebsocket.php
|
InteractsWithWebsocket.isWebsocketPushPayload
|
public function isWebsocketPushPayload($payload): bool
{
if (! is_array($payload)) {
return false;
}
return $this->isServerWebsocket
&& ($payload['action'] ?? null) === Websocket::PUSH_ACTION
&& array_key_exists('data', $payload);
}
|
php
|
public function isWebsocketPushPayload($payload): bool
{
if (! is_array($payload)) {
return false;
}
return $this->isServerWebsocket
&& ($payload['action'] ?? null) === Websocket::PUSH_ACTION
&& array_key_exists('data', $payload);
}
|
[
"public",
"function",
"isWebsocketPushPayload",
"(",
"$",
"payload",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"payload",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"isServerWebsocket",
"&&",
"(",
"$",
"payload",
"[",
"'action'",
"]",
"??",
"null",
")",
"===",
"Websocket",
"::",
"PUSH_ACTION",
"&&",
"array_key_exists",
"(",
"'data'",
",",
"$",
"payload",
")",
";",
"}"
] |
Indicates if the payload is websocket push.
@param mixed $payload
@return boolean
|
[
"Indicates",
"if",
"the",
"payload",
"is",
"websocket",
"push",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Concerns/InteractsWithWebsocket.php#L343-L352
|
220,655
|
swooletw/laravel-swoole
|
src/Websocket/SocketIO/Packet.php
|
Packet.getSocketType
|
public static function getSocketType(string $packet)
{
$type = $packet[0] ?? null;
if (! array_key_exists($type, static::$socketTypes)) {
return null;
}
return (int) $type;
}
|
php
|
public static function getSocketType(string $packet)
{
$type = $packet[0] ?? null;
if (! array_key_exists($type, static::$socketTypes)) {
return null;
}
return (int) $type;
}
|
[
"public",
"static",
"function",
"getSocketType",
"(",
"string",
"$",
"packet",
")",
"{",
"$",
"type",
"=",
"$",
"packet",
"[",
"0",
"]",
"??",
"null",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"type",
",",
"static",
"::",
"$",
"socketTypes",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"(",
"int",
")",
"$",
"type",
";",
"}"
] |
Get socket packet type of a raw payload.
@param string $packet
@return int|null
|
[
"Get",
"socket",
"packet",
"type",
"of",
"a",
"raw",
"payload",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Websocket/SocketIO/Packet.php#L113-L122
|
220,656
|
swooletw/laravel-swoole
|
src/Websocket/SocketIO/Packet.php
|
Packet.getPayload
|
public static function getPayload(string $packet)
{
$packet = trim($packet);
$start = strpos($packet, '[');
if ($start === false || substr($packet, -1) !== ']') {
return null;
}
$data = substr($packet, $start, strlen($packet) - $start);
$data = json_decode($data, true);
if (is_null($data)) {
return null;
}
return [
'event' => $data[0],
'data' => $data[1] ?? null,
];
}
|
php
|
public static function getPayload(string $packet)
{
$packet = trim($packet);
$start = strpos($packet, '[');
if ($start === false || substr($packet, -1) !== ']') {
return null;
}
$data = substr($packet, $start, strlen($packet) - $start);
$data = json_decode($data, true);
if (is_null($data)) {
return null;
}
return [
'event' => $data[0],
'data' => $data[1] ?? null,
];
}
|
[
"public",
"static",
"function",
"getPayload",
"(",
"string",
"$",
"packet",
")",
"{",
"$",
"packet",
"=",
"trim",
"(",
"$",
"packet",
")",
";",
"$",
"start",
"=",
"strpos",
"(",
"$",
"packet",
",",
"'['",
")",
";",
"if",
"(",
"$",
"start",
"===",
"false",
"||",
"substr",
"(",
"$",
"packet",
",",
"-",
"1",
")",
"!==",
"']'",
")",
"{",
"return",
"null",
";",
"}",
"$",
"data",
"=",
"substr",
"(",
"$",
"packet",
",",
"$",
"start",
",",
"strlen",
"(",
"$",
"packet",
")",
"-",
"$",
"start",
")",
";",
"$",
"data",
"=",
"json_decode",
"(",
"$",
"data",
",",
"true",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"data",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"[",
"'event'",
"=>",
"$",
"data",
"[",
"0",
"]",
",",
"'data'",
"=>",
"$",
"data",
"[",
"1",
"]",
"??",
"null",
",",
"]",
";",
"}"
] |
Get data packet from a raw payload.
@param string $packet
@return array|null
|
[
"Get",
"data",
"packet",
"from",
"a",
"raw",
"payload",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Websocket/SocketIO/Packet.php#L131-L151
|
220,657
|
swooletw/laravel-swoole
|
src/Websocket/SocketIO/Packet.php
|
Packet.isSocketType
|
public static function isSocketType($packet, string $typeName)
{
$type = array_search(strtoupper($typeName), static::$socketTypes);
if ($type === false) {
return false;
}
return static::getSocketType($packet) === $type;
}
|
php
|
public static function isSocketType($packet, string $typeName)
{
$type = array_search(strtoupper($typeName), static::$socketTypes);
if ($type === false) {
return false;
}
return static::getSocketType($packet) === $type;
}
|
[
"public",
"static",
"function",
"isSocketType",
"(",
"$",
"packet",
",",
"string",
"$",
"typeName",
")",
"{",
"$",
"type",
"=",
"array_search",
"(",
"strtoupper",
"(",
"$",
"typeName",
")",
",",
"static",
"::",
"$",
"socketTypes",
")",
";",
"if",
"(",
"$",
"type",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"return",
"static",
"::",
"getSocketType",
"(",
"$",
"packet",
")",
"===",
"$",
"type",
";",
"}"
] |
Return if a socket packet belongs to specific type.
@param $packet
@param string $typeName
@return bool
|
[
"Return",
"if",
"a",
"socket",
"packet",
"belongs",
"to",
"specific",
"type",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Websocket/SocketIO/Packet.php#L161-L170
|
220,658
|
swooletw/laravel-swoole
|
src/HotReload/FSProcess.php
|
FSProcess.make
|
public function make(?callable $callback = null)
{
$mcb = function ($type, $buffer) use ($callback) {
if (! $this->locked && AppProcess::OUT === $type && $event = FSEventParser::toEvent($buffer)) {
$this->locked = true;
($callback) ? $callback($event) : null;
$this->locked = false;
unset($event);
}
};
return new SwooleProcess(function () use ($mcb) {
(new AppProcess($this->configure()))->setTimeout(0)->run($mcb);
}, false, false);
}
|
php
|
public function make(?callable $callback = null)
{
$mcb = function ($type, $buffer) use ($callback) {
if (! $this->locked && AppProcess::OUT === $type && $event = FSEventParser::toEvent($buffer)) {
$this->locked = true;
($callback) ? $callback($event) : null;
$this->locked = false;
unset($event);
}
};
return new SwooleProcess(function () use ($mcb) {
(new AppProcess($this->configure()))->setTimeout(0)->run($mcb);
}, false, false);
}
|
[
"public",
"function",
"make",
"(",
"?",
"callable",
"$",
"callback",
"=",
"null",
")",
"{",
"$",
"mcb",
"=",
"function",
"(",
"$",
"type",
",",
"$",
"buffer",
")",
"use",
"(",
"$",
"callback",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"locked",
"&&",
"AppProcess",
"::",
"OUT",
"===",
"$",
"type",
"&&",
"$",
"event",
"=",
"FSEventParser",
"::",
"toEvent",
"(",
"$",
"buffer",
")",
")",
"{",
"$",
"this",
"->",
"locked",
"=",
"true",
";",
"(",
"$",
"callback",
")",
"?",
"$",
"callback",
"(",
"$",
"event",
")",
":",
"null",
";",
"$",
"this",
"->",
"locked",
"=",
"false",
";",
"unset",
"(",
"$",
"event",
")",
";",
"}",
"}",
";",
"return",
"new",
"SwooleProcess",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"mcb",
")",
"{",
"(",
"new",
"AppProcess",
"(",
"$",
"this",
"->",
"configure",
"(",
")",
")",
")",
"->",
"setTimeout",
"(",
"0",
")",
"->",
"run",
"(",
"$",
"mcb",
")",
";",
"}",
",",
"false",
",",
"false",
")",
";",
"}"
] |
Make swoole process.
@param callable|null $callback
@return \Swoole\Process
|
[
"Make",
"swoole",
"process",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/HotReload/FSProcess.php#L63-L77
|
220,659
|
swooletw/laravel-swoole
|
src/Concerns/WithApplication.php
|
WithApplication.bootstrap
|
protected function bootstrap()
{
if ($this->framework === 'laravel') {
$bootstrappers = $this->getBootstrappers();
$this->app->bootstrapWith($bootstrappers);
} else {
// for Lumen 5.7
// https://github.com/laravel/lumen-framework/commit/42cbc998375718b1a8a11883e033617024e57260#diff-c9248b3167fc44af085b81db2e292837
if (method_exists($this->app, 'boot')) {
$this->app->boot();
}
$this->app->withFacades();
}
$this->preResolveInstances();
}
|
php
|
protected function bootstrap()
{
if ($this->framework === 'laravel') {
$bootstrappers = $this->getBootstrappers();
$this->app->bootstrapWith($bootstrappers);
} else {
// for Lumen 5.7
// https://github.com/laravel/lumen-framework/commit/42cbc998375718b1a8a11883e033617024e57260#diff-c9248b3167fc44af085b81db2e292837
if (method_exists($this->app, 'boot')) {
$this->app->boot();
}
$this->app->withFacades();
}
$this->preResolveInstances();
}
|
[
"protected",
"function",
"bootstrap",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"framework",
"===",
"'laravel'",
")",
"{",
"$",
"bootstrappers",
"=",
"$",
"this",
"->",
"getBootstrappers",
"(",
")",
";",
"$",
"this",
"->",
"app",
"->",
"bootstrapWith",
"(",
"$",
"bootstrappers",
")",
";",
"}",
"else",
"{",
"// for Lumen 5.7",
"// https://github.com/laravel/lumen-framework/commit/42cbc998375718b1a8a11883e033617024e57260#diff-c9248b3167fc44af085b81db2e292837",
"if",
"(",
"method_exists",
"(",
"$",
"this",
"->",
"app",
",",
"'boot'",
")",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"boot",
"(",
")",
";",
"}",
"$",
"this",
"->",
"app",
"->",
"withFacades",
"(",
")",
";",
"}",
"$",
"this",
"->",
"preResolveInstances",
"(",
")",
";",
"}"
] |
Bootstrap framework.
|
[
"Bootstrap",
"framework",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Concerns/WithApplication.php#L28-L43
|
220,660
|
swooletw/laravel-swoole
|
src/Concerns/WithApplication.php
|
WithApplication.setFramework
|
protected function setFramework($framework)
{
$framework = strtolower($framework);
if (! in_array($framework, ['laravel', 'lumen'])) {
throw new FrameworkNotSupportException($framework);
}
$this->framework = $framework;
}
|
php
|
protected function setFramework($framework)
{
$framework = strtolower($framework);
if (! in_array($framework, ['laravel', 'lumen'])) {
throw new FrameworkNotSupportException($framework);
}
$this->framework = $framework;
}
|
[
"protected",
"function",
"setFramework",
"(",
"$",
"framework",
")",
"{",
"$",
"framework",
"=",
"strtolower",
"(",
"$",
"framework",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"framework",
",",
"[",
"'laravel'",
",",
"'lumen'",
"]",
")",
")",
"{",
"throw",
"new",
"FrameworkNotSupportException",
"(",
"$",
"framework",
")",
";",
"}",
"$",
"this",
"->",
"framework",
"=",
"$",
"framework",
";",
"}"
] |
Set framework.
@param string $framework
@throws \Exception
|
[
"Set",
"framework",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Concerns/WithApplication.php#L86-L95
|
220,661
|
swooletw/laravel-swoole
|
src/Concerns/WithApplication.php
|
WithApplication.preResolveInstances
|
protected function preResolveInstances()
{
$resolves = $this->container->make('config')
->get('swoole_http.pre_resolved', []);
foreach ($resolves as $abstract) {
if ($this->getApplication()->offsetExists($abstract)) {
$this->getApplication()->make($abstract);
}
}
}
|
php
|
protected function preResolveInstances()
{
$resolves = $this->container->make('config')
->get('swoole_http.pre_resolved', []);
foreach ($resolves as $abstract) {
if ($this->getApplication()->offsetExists($abstract)) {
$this->getApplication()->make($abstract);
}
}
}
|
[
"protected",
"function",
"preResolveInstances",
"(",
")",
"{",
"$",
"resolves",
"=",
"$",
"this",
"->",
"container",
"->",
"make",
"(",
"'config'",
")",
"->",
"get",
"(",
"'swoole_http.pre_resolved'",
",",
"[",
"]",
")",
";",
"foreach",
"(",
"$",
"resolves",
"as",
"$",
"abstract",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getApplication",
"(",
")",
"->",
"offsetExists",
"(",
"$",
"abstract",
")",
")",
"{",
"$",
"this",
"->",
"getApplication",
"(",
")",
"->",
"make",
"(",
"$",
"abstract",
")",
";",
"}",
"}",
"}"
] |
Reslove some instances before request.
@throws \ReflectionException
|
[
"Reslove",
"some",
"instances",
"before",
"request",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Concerns/WithApplication.php#L128-L138
|
220,662
|
swooletw/laravel-swoole
|
src/Concerns/WithApplication.php
|
WithApplication.getBootstrappers
|
protected function getBootstrappers()
{
$kernel = $this->getApplication()->make(Kernel::class);
$reflection = new \ReflectionObject($kernel);
$bootstrappersMethod = $reflection->getMethod('bootstrappers');
$bootstrappersMethod->setAccessible(true);
$bootstrappers = $bootstrappersMethod->invoke($kernel);
array_splice($bootstrappers, -2, 0, ['Illuminate\Foundation\Bootstrap\SetRequestForConsole']);
return $bootstrappers;
}
|
php
|
protected function getBootstrappers()
{
$kernel = $this->getApplication()->make(Kernel::class);
$reflection = new \ReflectionObject($kernel);
$bootstrappersMethod = $reflection->getMethod('bootstrappers');
$bootstrappersMethod->setAccessible(true);
$bootstrappers = $bootstrappersMethod->invoke($kernel);
array_splice($bootstrappers, -2, 0, ['Illuminate\Foundation\Bootstrap\SetRequestForConsole']);
return $bootstrappers;
}
|
[
"protected",
"function",
"getBootstrappers",
"(",
")",
"{",
"$",
"kernel",
"=",
"$",
"this",
"->",
"getApplication",
"(",
")",
"->",
"make",
"(",
"Kernel",
"::",
"class",
")",
";",
"$",
"reflection",
"=",
"new",
"\\",
"ReflectionObject",
"(",
"$",
"kernel",
")",
";",
"$",
"bootstrappersMethod",
"=",
"$",
"reflection",
"->",
"getMethod",
"(",
"'bootstrappers'",
")",
";",
"$",
"bootstrappersMethod",
"->",
"setAccessible",
"(",
"true",
")",
";",
"$",
"bootstrappers",
"=",
"$",
"bootstrappersMethod",
"->",
"invoke",
"(",
"$",
"kernel",
")",
";",
"array_splice",
"(",
"$",
"bootstrappers",
",",
"-",
"2",
",",
"0",
",",
"[",
"'Illuminate\\Foundation\\Bootstrap\\SetRequestForConsole'",
"]",
")",
";",
"return",
"$",
"bootstrappers",
";",
"}"
] |
Get bootstrappers.
@return array
@throws \ReflectionException
|
[
"Get",
"bootstrappers",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Concerns/WithApplication.php#L146-L158
|
220,663
|
swooletw/laravel-swoole
|
src/Server/Resetters/ResetProviders.php
|
ResetProviders.rebindProviderContainer
|
protected function rebindProviderContainer($app, $provider)
{
$closure = function () use ($app) {
$this->app = $app;
};
$resetProvider = $closure->bindTo($provider, $provider);
$resetProvider();
}
|
php
|
protected function rebindProviderContainer($app, $provider)
{
$closure = function () use ($app) {
$this->app = $app;
};
$resetProvider = $closure->bindTo($provider, $provider);
$resetProvider();
}
|
[
"protected",
"function",
"rebindProviderContainer",
"(",
"$",
"app",
",",
"$",
"provider",
")",
"{",
"$",
"closure",
"=",
"function",
"(",
")",
"use",
"(",
"$",
"app",
")",
"{",
"$",
"this",
"->",
"app",
"=",
"$",
"app",
";",
"}",
";",
"$",
"resetProvider",
"=",
"$",
"closure",
"->",
"bindTo",
"(",
"$",
"provider",
",",
"$",
"provider",
")",
";",
"$",
"resetProvider",
"(",
")",
";",
"}"
] |
Rebind service provider's container.
@param $app
@param $provider
|
[
"Rebind",
"service",
"provider",
"s",
"container",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Server/Resetters/ResetProviders.php#L44-L52
|
220,664
|
swooletw/laravel-swoole
|
src/Middleware/AccessLog.php
|
AccessLog.terminate
|
public function terminate(Request $request, Response $response)
{
$this->output->log($request, $response);
}
|
php
|
public function terminate(Request $request, Response $response)
{
$this->output->log($request, $response);
}
|
[
"public",
"function",
"terminate",
"(",
"Request",
"$",
"request",
",",
"Response",
"$",
"response",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"log",
"(",
"$",
"request",
",",
"$",
"response",
")",
";",
"}"
] |
Handle the outgoing request and response.
@param \Illuminate\Http\Request $request
@param \Symfony\Component\HttpFoundation\Response $response
|
[
"Handle",
"the",
"outgoing",
"request",
"and",
"response",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Middleware/AccessLog.php#L51-L54
|
220,665
|
swooletw/laravel-swoole
|
src/Commands/HttpServerCommand.php
|
HttpServerCommand.start
|
protected function start()
{
if ($this->isRunning($this->getCurrentPid())) {
$this->error('Failed! swoole_http_server process is already running.');
return;
}
$host = Arr::get($this->config, 'server.host');
$port = Arr::get($this->config, 'server.port');
$hotReloadEnabled = Arr::get($this->config, 'hot_reload.enabled');
$accessLogEnabled = Arr::get($this->config, 'server.access_log');
$this->info('Starting swoole http server...');
$this->info("Swoole http server started: <http://{$host}:{$port}>");
if ($this->isDaemon()) {
$this->info(
'> (You can run this command to ensure the ' .
'swoole_http_server process is running: ps aux|grep "swoole")'
);
}
$manager = $this->laravel->make(Manager::class);
$server = $this->laravel->make(Server::class);
if ($accessLogEnabled) {
$this->registerAccessLog();
}
if ($hotReloadEnabled) {
$manager->addProcess($this->getHotReloadProcess($server));
}
$manager->run();
}
|
php
|
protected function start()
{
if ($this->isRunning($this->getCurrentPid())) {
$this->error('Failed! swoole_http_server process is already running.');
return;
}
$host = Arr::get($this->config, 'server.host');
$port = Arr::get($this->config, 'server.port');
$hotReloadEnabled = Arr::get($this->config, 'hot_reload.enabled');
$accessLogEnabled = Arr::get($this->config, 'server.access_log');
$this->info('Starting swoole http server...');
$this->info("Swoole http server started: <http://{$host}:{$port}>");
if ($this->isDaemon()) {
$this->info(
'> (You can run this command to ensure the ' .
'swoole_http_server process is running: ps aux|grep "swoole")'
);
}
$manager = $this->laravel->make(Manager::class);
$server = $this->laravel->make(Server::class);
if ($accessLogEnabled) {
$this->registerAccessLog();
}
if ($hotReloadEnabled) {
$manager->addProcess($this->getHotReloadProcess($server));
}
$manager->run();
}
|
[
"protected",
"function",
"start",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isRunning",
"(",
"$",
"this",
"->",
"getCurrentPid",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"'Failed! swoole_http_server process is already running.'",
")",
";",
"return",
";",
"}",
"$",
"host",
"=",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"config",
",",
"'server.host'",
")",
";",
"$",
"port",
"=",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"config",
",",
"'server.port'",
")",
";",
"$",
"hotReloadEnabled",
"=",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"config",
",",
"'hot_reload.enabled'",
")",
";",
"$",
"accessLogEnabled",
"=",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"config",
",",
"'server.access_log'",
")",
";",
"$",
"this",
"->",
"info",
"(",
"'Starting swoole http server...'",
")",
";",
"$",
"this",
"->",
"info",
"(",
"\"Swoole http server started: <http://{$host}:{$port}>\"",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isDaemon",
"(",
")",
")",
"{",
"$",
"this",
"->",
"info",
"(",
"'> (You can run this command to ensure the '",
".",
"'swoole_http_server process is running: ps aux|grep \"swoole\")'",
")",
";",
"}",
"$",
"manager",
"=",
"$",
"this",
"->",
"laravel",
"->",
"make",
"(",
"Manager",
"::",
"class",
")",
";",
"$",
"server",
"=",
"$",
"this",
"->",
"laravel",
"->",
"make",
"(",
"Server",
"::",
"class",
")",
";",
"if",
"(",
"$",
"accessLogEnabled",
")",
"{",
"$",
"this",
"->",
"registerAccessLog",
"(",
")",
";",
"}",
"if",
"(",
"$",
"hotReloadEnabled",
")",
"{",
"$",
"manager",
"->",
"addProcess",
"(",
"$",
"this",
"->",
"getHotReloadProcess",
"(",
"$",
"server",
")",
")",
";",
"}",
"$",
"manager",
"->",
"run",
"(",
")",
";",
"}"
] |
Run swoole_http_server.
|
[
"Run",
"swoole_http_server",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Commands/HttpServerCommand.php#L94-L128
|
220,666
|
swooletw/laravel-swoole
|
src/Commands/HttpServerCommand.php
|
HttpServerCommand.stop
|
protected function stop()
{
$pid = $this->getCurrentPid();
if (! $this->isRunning($pid)) {
$this->error("Failed! There is no swoole_http_server process running.");
return;
}
$this->info('Stopping swoole http server...');
$isRunning = $this->killProcess($pid, SIGTERM, 15);
if ($isRunning) {
$this->error('Unable to stop the swoole_http_server process.');
return;
}
// I don't known why Swoole didn't trigger "onShutdown" after sending SIGTERM.
// So we should manually remove the pid file.
$this->removePidFile();
$this->info('> success');
}
|
php
|
protected function stop()
{
$pid = $this->getCurrentPid();
if (! $this->isRunning($pid)) {
$this->error("Failed! There is no swoole_http_server process running.");
return;
}
$this->info('Stopping swoole http server...');
$isRunning = $this->killProcess($pid, SIGTERM, 15);
if ($isRunning) {
$this->error('Unable to stop the swoole_http_server process.');
return;
}
// I don't known why Swoole didn't trigger "onShutdown" after sending SIGTERM.
// So we should manually remove the pid file.
$this->removePidFile();
$this->info('> success');
}
|
[
"protected",
"function",
"stop",
"(",
")",
"{",
"$",
"pid",
"=",
"$",
"this",
"->",
"getCurrentPid",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"isRunning",
"(",
"$",
"pid",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"\"Failed! There is no swoole_http_server process running.\"",
")",
";",
"return",
";",
"}",
"$",
"this",
"->",
"info",
"(",
"'Stopping swoole http server...'",
")",
";",
"$",
"isRunning",
"=",
"$",
"this",
"->",
"killProcess",
"(",
"$",
"pid",
",",
"SIGTERM",
",",
"15",
")",
";",
"if",
"(",
"$",
"isRunning",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"'Unable to stop the swoole_http_server process.'",
")",
";",
"return",
";",
"}",
"// I don't known why Swoole didn't trigger \"onShutdown\" after sending SIGTERM.",
"// So we should manually remove the pid file.",
"$",
"this",
"->",
"removePidFile",
"(",
")",
";",
"$",
"this",
"->",
"info",
"(",
"'> success'",
")",
";",
"}"
] |
Stop swoole_http_server.
|
[
"Stop",
"swoole_http_server",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Commands/HttpServerCommand.php#L133-L158
|
220,667
|
swooletw/laravel-swoole
|
src/Commands/HttpServerCommand.php
|
HttpServerCommand.restart
|
protected function restart()
{
$pid = $this->getCurrentPid();
if ($this->isRunning($pid)) {
$this->stop();
}
$this->start();
}
|
php
|
protected function restart()
{
$pid = $this->getCurrentPid();
if ($this->isRunning($pid)) {
$this->stop();
}
$this->start();
}
|
[
"protected",
"function",
"restart",
"(",
")",
"{",
"$",
"pid",
"=",
"$",
"this",
"->",
"getCurrentPid",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isRunning",
"(",
"$",
"pid",
")",
")",
"{",
"$",
"this",
"->",
"stop",
"(",
")",
";",
"}",
"$",
"this",
"->",
"start",
"(",
")",
";",
"}"
] |
Restart swoole http server.
|
[
"Restart",
"swoole",
"http",
"server",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Commands/HttpServerCommand.php#L163-L172
|
220,668
|
swooletw/laravel-swoole
|
src/Commands/HttpServerCommand.php
|
HttpServerCommand.showInfos
|
protected function showInfos()
{
$pid = $this->getCurrentPid();
$isRunning = $this->isRunning($pid);
$host = Arr::get($this->config, 'server.host');
$port = Arr::get($this->config, 'server.port');
$reactorNum = Arr::get($this->config, 'server.options.reactor_num');
$workerNum = Arr::get($this->config, 'server.options.worker_num');
$taskWorkerNum = Arr::get($this->config, 'server.options.task_worker_num');
$isWebsocket = Arr::get($this->config, 'websocket.enabled');
$logFile = Arr::get($this->config, 'server.options.log_file');
$table = [
['PHP Version', 'Version' => phpversion()],
['Swoole Version', 'Version' => swoole_version()],
['Laravel Version', $this->getApplication()->getVersion()],
['Listen IP', $host],
['Listen Port', $port],
['Server Status', $isRunning ? 'Online' : 'Offline'],
['Reactor Num', $reactorNum],
['Worker Num', $workerNum],
['Task Worker Num', $isWebsocket ? $taskWorkerNum : 0],
['Websocket Mode', $isWebsocket ? 'On' : 'Off'],
['PID', $isRunning ? $pid : 'None'],
['Log Path', $logFile],
];
$this->table(['Name', 'Value'], $table);
}
|
php
|
protected function showInfos()
{
$pid = $this->getCurrentPid();
$isRunning = $this->isRunning($pid);
$host = Arr::get($this->config, 'server.host');
$port = Arr::get($this->config, 'server.port');
$reactorNum = Arr::get($this->config, 'server.options.reactor_num');
$workerNum = Arr::get($this->config, 'server.options.worker_num');
$taskWorkerNum = Arr::get($this->config, 'server.options.task_worker_num');
$isWebsocket = Arr::get($this->config, 'websocket.enabled');
$logFile = Arr::get($this->config, 'server.options.log_file');
$table = [
['PHP Version', 'Version' => phpversion()],
['Swoole Version', 'Version' => swoole_version()],
['Laravel Version', $this->getApplication()->getVersion()],
['Listen IP', $host],
['Listen Port', $port],
['Server Status', $isRunning ? 'Online' : 'Offline'],
['Reactor Num', $reactorNum],
['Worker Num', $workerNum],
['Task Worker Num', $isWebsocket ? $taskWorkerNum : 0],
['Websocket Mode', $isWebsocket ? 'On' : 'Off'],
['PID', $isRunning ? $pid : 'None'],
['Log Path', $logFile],
];
$this->table(['Name', 'Value'], $table);
}
|
[
"protected",
"function",
"showInfos",
"(",
")",
"{",
"$",
"pid",
"=",
"$",
"this",
"->",
"getCurrentPid",
"(",
")",
";",
"$",
"isRunning",
"=",
"$",
"this",
"->",
"isRunning",
"(",
"$",
"pid",
")",
";",
"$",
"host",
"=",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"config",
",",
"'server.host'",
")",
";",
"$",
"port",
"=",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"config",
",",
"'server.port'",
")",
";",
"$",
"reactorNum",
"=",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"config",
",",
"'server.options.reactor_num'",
")",
";",
"$",
"workerNum",
"=",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"config",
",",
"'server.options.worker_num'",
")",
";",
"$",
"taskWorkerNum",
"=",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"config",
",",
"'server.options.task_worker_num'",
")",
";",
"$",
"isWebsocket",
"=",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"config",
",",
"'websocket.enabled'",
")",
";",
"$",
"logFile",
"=",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"config",
",",
"'server.options.log_file'",
")",
";",
"$",
"table",
"=",
"[",
"[",
"'PHP Version'",
",",
"'Version'",
"=>",
"phpversion",
"(",
")",
"]",
",",
"[",
"'Swoole Version'",
",",
"'Version'",
"=>",
"swoole_version",
"(",
")",
"]",
",",
"[",
"'Laravel Version'",
",",
"$",
"this",
"->",
"getApplication",
"(",
")",
"->",
"getVersion",
"(",
")",
"]",
",",
"[",
"'Listen IP'",
",",
"$",
"host",
"]",
",",
"[",
"'Listen Port'",
",",
"$",
"port",
"]",
",",
"[",
"'Server Status'",
",",
"$",
"isRunning",
"?",
"'Online'",
":",
"'Offline'",
"]",
",",
"[",
"'Reactor Num'",
",",
"$",
"reactorNum",
"]",
",",
"[",
"'Worker Num'",
",",
"$",
"workerNum",
"]",
",",
"[",
"'Task Worker Num'",
",",
"$",
"isWebsocket",
"?",
"$",
"taskWorkerNum",
":",
"0",
"]",
",",
"[",
"'Websocket Mode'",
",",
"$",
"isWebsocket",
"?",
"'On'",
":",
"'Off'",
"]",
",",
"[",
"'PID'",
",",
"$",
"isRunning",
"?",
"$",
"pid",
":",
"'None'",
"]",
",",
"[",
"'Log Path'",
",",
"$",
"logFile",
"]",
",",
"]",
";",
"$",
"this",
"->",
"table",
"(",
"[",
"'Name'",
",",
"'Value'",
"]",
",",
"$",
"table",
")",
";",
"}"
] |
Display PHP and Swoole miscs infos.
|
[
"Display",
"PHP",
"and",
"Swoole",
"miscs",
"infos",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Commands/HttpServerCommand.php#L211-L239
|
220,669
|
swooletw/laravel-swoole
|
src/Commands/HttpServerCommand.php
|
HttpServerCommand.initAction
|
protected function initAction()
{
$this->action = $this->argument('action');
if (! in_array($this->action, ['start', 'stop', 'restart', 'reload', 'infos'], true)) {
$this->error(
"Invalid argument '{$this->action}'. Expected 'start', 'stop', 'restart', 'reload' or 'infos'."
);
return;
}
}
|
php
|
protected function initAction()
{
$this->action = $this->argument('action');
if (! in_array($this->action, ['start', 'stop', 'restart', 'reload', 'infos'], true)) {
$this->error(
"Invalid argument '{$this->action}'. Expected 'start', 'stop', 'restart', 'reload' or 'infos'."
);
return;
}
}
|
[
"protected",
"function",
"initAction",
"(",
")",
"{",
"$",
"this",
"->",
"action",
"=",
"$",
"this",
"->",
"argument",
"(",
"'action'",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"this",
"->",
"action",
",",
"[",
"'start'",
",",
"'stop'",
",",
"'restart'",
",",
"'reload'",
",",
"'infos'",
"]",
",",
"true",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"\"Invalid argument '{$this->action}'. Expected 'start', 'stop', 'restart', 'reload' or 'infos'.\"",
")",
";",
"return",
";",
"}",
"}"
] |
Initialize command action.
|
[
"Initialize",
"command",
"action",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Commands/HttpServerCommand.php#L244-L255
|
220,670
|
swooletw/laravel-swoole
|
src/Commands/HttpServerCommand.php
|
HttpServerCommand.isRunning
|
protected function isRunning($pid)
{
if (! $pid) {
return false;
}
try {
return Process::kill($pid, 0);
} catch (Throwable $e) {
return false;
}
}
|
php
|
protected function isRunning($pid)
{
if (! $pid) {
return false;
}
try {
return Process::kill($pid, 0);
} catch (Throwable $e) {
return false;
}
}
|
[
"protected",
"function",
"isRunning",
"(",
"$",
"pid",
")",
"{",
"if",
"(",
"!",
"$",
"pid",
")",
"{",
"return",
"false",
";",
"}",
"try",
"{",
"return",
"Process",
"::",
"kill",
"(",
"$",
"pid",
",",
"0",
")",
";",
"}",
"catch",
"(",
"Throwable",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"}"
] |
If Swoole process is running.
@param int $pid
@return bool
|
[
"If",
"Swoole",
"process",
"is",
"running",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Commands/HttpServerCommand.php#L284-L295
|
220,671
|
swooletw/laravel-swoole
|
src/Commands/HttpServerCommand.php
|
HttpServerCommand.killProcess
|
protected function killProcess($pid, $sig, $wait = 0)
{
Process::kill($pid, $sig);
if ($wait) {
$start = time();
do {
if (! $this->isRunning($pid)) {
break;
}
usleep(100000);
} while (time() < $start + $wait);
}
return $this->isRunning($pid);
}
|
php
|
protected function killProcess($pid, $sig, $wait = 0)
{
Process::kill($pid, $sig);
if ($wait) {
$start = time();
do {
if (! $this->isRunning($pid)) {
break;
}
usleep(100000);
} while (time() < $start + $wait);
}
return $this->isRunning($pid);
}
|
[
"protected",
"function",
"killProcess",
"(",
"$",
"pid",
",",
"$",
"sig",
",",
"$",
"wait",
"=",
"0",
")",
"{",
"Process",
"::",
"kill",
"(",
"$",
"pid",
",",
"$",
"sig",
")",
";",
"if",
"(",
"$",
"wait",
")",
"{",
"$",
"start",
"=",
"time",
"(",
")",
";",
"do",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isRunning",
"(",
"$",
"pid",
")",
")",
"{",
"break",
";",
"}",
"usleep",
"(",
"100000",
")",
";",
"}",
"while",
"(",
"time",
"(",
")",
"<",
"$",
"start",
"+",
"$",
"wait",
")",
";",
"}",
"return",
"$",
"this",
"->",
"isRunning",
"(",
"$",
"pid",
")",
";",
"}"
] |
Kill process.
@param int $pid
@param int $sig
@param int $wait
@return bool
|
[
"Kill",
"process",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Commands/HttpServerCommand.php#L306-L323
|
220,672
|
swooletw/laravel-swoole
|
src/Commands/HttpServerCommand.php
|
HttpServerCommand.getCurrentPid
|
protected function getCurrentPid()
{
if ($this->currentPid) {
return $this->currentPid;
}
$path = $this->getPidPath();
return $this->currentPid = file_exists($path)
? (int) file_get_contents($path) ?? $this->removePidFile()
: null;
}
|
php
|
protected function getCurrentPid()
{
if ($this->currentPid) {
return $this->currentPid;
}
$path = $this->getPidPath();
return $this->currentPid = file_exists($path)
? (int) file_get_contents($path) ?? $this->removePidFile()
: null;
}
|
[
"protected",
"function",
"getCurrentPid",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"currentPid",
")",
"{",
"return",
"$",
"this",
"->",
"currentPid",
";",
"}",
"$",
"path",
"=",
"$",
"this",
"->",
"getPidPath",
"(",
")",
";",
"return",
"$",
"this",
"->",
"currentPid",
"=",
"file_exists",
"(",
"$",
"path",
")",
"?",
"(",
"int",
")",
"file_get_contents",
"(",
"$",
"path",
")",
"??",
"$",
"this",
"->",
"removePidFile",
"(",
")",
":",
"null",
";",
"}"
] |
Get pid.
@return int|null
|
[
"Get",
"pid",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Commands/HttpServerCommand.php#L330-L341
|
220,673
|
swooletw/laravel-swoole
|
src/Commands/HttpServerCommand.php
|
HttpServerCommand.checkEnvironment
|
protected function checkEnvironment()
{
if (OS::is(OS::WIN)) {
$this->error('Swoole extension doesn\'t support Windows OS.');
exit(1);
}
if (! extension_loaded('swoole')) {
$this->error('Can\'t detect Swoole extension installed.');
exit(1);
}
if (! version_compare(swoole_version(), '4.3.1', 'ge')) {
$this->error('Your Swoole version must be higher than `4.3.1`.');
exit(1);
}
}
|
php
|
protected function checkEnvironment()
{
if (OS::is(OS::WIN)) {
$this->error('Swoole extension doesn\'t support Windows OS.');
exit(1);
}
if (! extension_loaded('swoole')) {
$this->error('Can\'t detect Swoole extension installed.');
exit(1);
}
if (! version_compare(swoole_version(), '4.3.1', 'ge')) {
$this->error('Your Swoole version must be higher than `4.3.1`.');
exit(1);
}
}
|
[
"protected",
"function",
"checkEnvironment",
"(",
")",
"{",
"if",
"(",
"OS",
"::",
"is",
"(",
"OS",
"::",
"WIN",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"'Swoole extension doesn\\'t support Windows OS.'",
")",
";",
"exit",
"(",
"1",
")",
";",
"}",
"if",
"(",
"!",
"extension_loaded",
"(",
"'swoole'",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"'Can\\'t detect Swoole extension installed.'",
")",
";",
"exit",
"(",
"1",
")",
";",
"}",
"if",
"(",
"!",
"version_compare",
"(",
"swoole_version",
"(",
")",
",",
"'4.3.1'",
",",
"'ge'",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"'Your Swoole version must be higher than `4.3.1`.'",
")",
";",
"exit",
"(",
"1",
")",
";",
"}",
"}"
] |
Check running enironment.
|
[
"Check",
"running",
"enironment",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Commands/HttpServerCommand.php#L374-L393
|
220,674
|
swooletw/laravel-swoole
|
src/Commands/HttpServerCommand.php
|
HttpServerCommand.registerAccessLog
|
protected function registerAccessLog()
{
$this->laravel->singleton(OutputStyle::class, function () {
return new OutputStyle($this->input, $this->output);
});
$this->laravel->singleton(AccessOutput::class, function () {
return new AccessOutput(new ConsoleOutput);
});
$this->laravel->singleton(AccessLog::class, function (Container $container) {
return new AccessLog($container->make(AccessOutput::class));
});
}
|
php
|
protected function registerAccessLog()
{
$this->laravel->singleton(OutputStyle::class, function () {
return new OutputStyle($this->input, $this->output);
});
$this->laravel->singleton(AccessOutput::class, function () {
return new AccessOutput(new ConsoleOutput);
});
$this->laravel->singleton(AccessLog::class, function (Container $container) {
return new AccessLog($container->make(AccessOutput::class));
});
}
|
[
"protected",
"function",
"registerAccessLog",
"(",
")",
"{",
"$",
"this",
"->",
"laravel",
"->",
"singleton",
"(",
"OutputStyle",
"::",
"class",
",",
"function",
"(",
")",
"{",
"return",
"new",
"OutputStyle",
"(",
"$",
"this",
"->",
"input",
",",
"$",
"this",
"->",
"output",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"laravel",
"->",
"singleton",
"(",
"AccessOutput",
"::",
"class",
",",
"function",
"(",
")",
"{",
"return",
"new",
"AccessOutput",
"(",
"new",
"ConsoleOutput",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"laravel",
"->",
"singleton",
"(",
"AccessLog",
"::",
"class",
",",
"function",
"(",
"Container",
"$",
"container",
")",
"{",
"return",
"new",
"AccessLog",
"(",
"$",
"container",
"->",
"make",
"(",
"AccessOutput",
"::",
"class",
")",
")",
";",
"}",
")",
";",
"}"
] |
Register access log services.
|
[
"Register",
"access",
"log",
"services",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Commands/HttpServerCommand.php#L398-L411
|
220,675
|
swooletw/laravel-swoole
|
src/Transformers/Response.php
|
Response.sendContent
|
protected function sendContent()
{
$illuminateResponse = $this->getIlluminateResponse();
if ($illuminateResponse instanceof StreamedResponse && property_exists($illuminateResponse, 'output')) {
// TODO Add Streamed Response with output
$this->swooleResponse->end($illuminateResponse->output);
} elseif ($illuminateResponse instanceof BinaryFileResponse) {
$this->swooleResponse->sendfile($illuminateResponse->getFile()->getPathname());
} else {
$this->sendInChunk($illuminateResponse->getContent());
}
}
|
php
|
protected function sendContent()
{
$illuminateResponse = $this->getIlluminateResponse();
if ($illuminateResponse instanceof StreamedResponse && property_exists($illuminateResponse, 'output')) {
// TODO Add Streamed Response with output
$this->swooleResponse->end($illuminateResponse->output);
} elseif ($illuminateResponse instanceof BinaryFileResponse) {
$this->swooleResponse->sendfile($illuminateResponse->getFile()->getPathname());
} else {
$this->sendInChunk($illuminateResponse->getContent());
}
}
|
[
"protected",
"function",
"sendContent",
"(",
")",
"{",
"$",
"illuminateResponse",
"=",
"$",
"this",
"->",
"getIlluminateResponse",
"(",
")",
";",
"if",
"(",
"$",
"illuminateResponse",
"instanceof",
"StreamedResponse",
"&&",
"property_exists",
"(",
"$",
"illuminateResponse",
",",
"'output'",
")",
")",
"{",
"// TODO Add Streamed Response with output",
"$",
"this",
"->",
"swooleResponse",
"->",
"end",
"(",
"$",
"illuminateResponse",
"->",
"output",
")",
";",
"}",
"elseif",
"(",
"$",
"illuminateResponse",
"instanceof",
"BinaryFileResponse",
")",
"{",
"$",
"this",
"->",
"swooleResponse",
"->",
"sendfile",
"(",
"$",
"illuminateResponse",
"->",
"getFile",
"(",
")",
"->",
"getPathname",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"sendInChunk",
"(",
"$",
"illuminateResponse",
"->",
"getContent",
"(",
")",
")",
";",
"}",
"}"
] |
Send HTTP content.
|
[
"Send",
"HTTP",
"content",
"."
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Transformers/Response.php#L110-L122
|
220,676
|
swooletw/laravel-swoole
|
src/Transformers/Response.php
|
Response.sendInChunk
|
protected function sendInChunk($content)
{
if (strlen($content) <= static::CHUNK_SIZE) {
$this->swooleResponse->end($content);
return;
}
foreach (str_split($content, static::CHUNK_SIZE) as $chunk) {
$this->swooleResponse->write($chunk);
}
$this->swooleResponse->end();
}
|
php
|
protected function sendInChunk($content)
{
if (strlen($content) <= static::CHUNK_SIZE) {
$this->swooleResponse->end($content);
return;
}
foreach (str_split($content, static::CHUNK_SIZE) as $chunk) {
$this->swooleResponse->write($chunk);
}
$this->swooleResponse->end();
}
|
[
"protected",
"function",
"sendInChunk",
"(",
"$",
"content",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"content",
")",
"<=",
"static",
"::",
"CHUNK_SIZE",
")",
"{",
"$",
"this",
"->",
"swooleResponse",
"->",
"end",
"(",
"$",
"content",
")",
";",
"return",
";",
"}",
"foreach",
"(",
"str_split",
"(",
"$",
"content",
",",
"static",
"::",
"CHUNK_SIZE",
")",
"as",
"$",
"chunk",
")",
"{",
"$",
"this",
"->",
"swooleResponse",
"->",
"write",
"(",
"$",
"chunk",
")",
";",
"}",
"$",
"this",
"->",
"swooleResponse",
"->",
"end",
"(",
")",
";",
"}"
] |
Send content in chunk
@param string $content
|
[
"Send",
"content",
"in",
"chunk"
] |
5b2b08a45eeb99e32ae66a0b362dc3916164ad31
|
https://github.com/swooletw/laravel-swoole/blob/5b2b08a45eeb99e32ae66a0b362dc3916164ad31/src/Transformers/Response.php#L129-L141
|
220,677
|
Seldaek/monolog
|
src/Monolog/Formatter/LogmaticFormatter.php
|
LogmaticFormatter.format
|
public function format(array $record): string
{
if (!empty($this->hostname)) {
$record["hostname"] = $this->hostname;
}
if (!empty($this->appname)) {
$record["appname"] = $this->appname;
}
$record["@marker"] = static::MARKERS;
return parent::format($record);
}
|
php
|
public function format(array $record): string
{
if (!empty($this->hostname)) {
$record["hostname"] = $this->hostname;
}
if (!empty($this->appname)) {
$record["appname"] = $this->appname;
}
$record["@marker"] = static::MARKERS;
return parent::format($record);
}
|
[
"public",
"function",
"format",
"(",
"array",
"$",
"record",
")",
":",
"string",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"hostname",
")",
")",
"{",
"$",
"record",
"[",
"\"hostname\"",
"]",
"=",
"$",
"this",
"->",
"hostname",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"appname",
")",
")",
"{",
"$",
"record",
"[",
"\"appname\"",
"]",
"=",
"$",
"this",
"->",
"appname",
";",
"}",
"$",
"record",
"[",
"\"@marker\"",
"]",
"=",
"static",
"::",
"MARKERS",
";",
"return",
"parent",
"::",
"format",
"(",
"$",
"record",
")",
";",
"}"
] |
Appends the 'hostname' and 'appname' parameter for indexing by Logmatic.
@see http://doc.logmatic.io/docs/basics-to-send-data
@see \Monolog\Formatter\JsonFormatter::format()
|
[
"Appends",
"the",
"hostname",
"and",
"appname",
"parameter",
"for",
"indexing",
"by",
"Logmatic",
"."
] |
ebb804e432e8fe0fe96828f30d89c45581d36d07
|
https://github.com/Seldaek/monolog/blob/ebb804e432e8fe0fe96828f30d89c45581d36d07/src/Monolog/Formatter/LogmaticFormatter.php#L53-L65
|
220,678
|
Seldaek/monolog
|
src/Monolog/Formatter/JsonFormatter.php
|
JsonFormatter.formatBatchNewlines
|
protected function formatBatchNewlines(array $records): string
{
$instance = $this;
$oldNewline = $this->appendNewline;
$this->appendNewline = false;
array_walk($records, function (&$value, $key) use ($instance) {
$value = $instance->format($value);
});
$this->appendNewline = $oldNewline;
return implode("\n", $records);
}
|
php
|
protected function formatBatchNewlines(array $records): string
{
$instance = $this;
$oldNewline = $this->appendNewline;
$this->appendNewline = false;
array_walk($records, function (&$value, $key) use ($instance) {
$value = $instance->format($value);
});
$this->appendNewline = $oldNewline;
return implode("\n", $records);
}
|
[
"protected",
"function",
"formatBatchNewlines",
"(",
"array",
"$",
"records",
")",
":",
"string",
"{",
"$",
"instance",
"=",
"$",
"this",
";",
"$",
"oldNewline",
"=",
"$",
"this",
"->",
"appendNewline",
";",
"$",
"this",
"->",
"appendNewline",
"=",
"false",
";",
"array_walk",
"(",
"$",
"records",
",",
"function",
"(",
"&",
"$",
"value",
",",
"$",
"key",
")",
"use",
"(",
"$",
"instance",
")",
"{",
"$",
"value",
"=",
"$",
"instance",
"->",
"format",
"(",
"$",
"value",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"appendNewline",
"=",
"$",
"oldNewline",
";",
"return",
"implode",
"(",
"\"\\n\"",
",",
"$",
"records",
")",
";",
"}"
] |
Use new lines to separate records instead of a
JSON-encoded array.
|
[
"Use",
"new",
"lines",
"to",
"separate",
"records",
"instead",
"of",
"a",
"JSON",
"-",
"encoded",
"array",
"."
] |
ebb804e432e8fe0fe96828f30d89c45581d36d07
|
https://github.com/Seldaek/monolog/blob/ebb804e432e8fe0fe96828f30d89c45581d36d07/src/Monolog/Formatter/JsonFormatter.php#L113-L125
|
220,679
|
Seldaek/monolog
|
src/Monolog/Formatter/NormalizerFormatter.php
|
NormalizerFormatter.setJsonPrettyPrint
|
public function setJsonPrettyPrint(bool $enable): self
{
if ($enable) {
$this->jsonEncodeOptions |= JSON_PRETTY_PRINT;
} else {
$this->jsonEncodeOptions ^= JSON_PRETTY_PRINT;
}
return $this;
}
|
php
|
public function setJsonPrettyPrint(bool $enable): self
{
if ($enable) {
$this->jsonEncodeOptions |= JSON_PRETTY_PRINT;
} else {
$this->jsonEncodeOptions ^= JSON_PRETTY_PRINT;
}
return $this;
}
|
[
"public",
"function",
"setJsonPrettyPrint",
"(",
"bool",
"$",
"enable",
")",
":",
"self",
"{",
"if",
"(",
"$",
"enable",
")",
"{",
"$",
"this",
"->",
"jsonEncodeOptions",
"|=",
"JSON_PRETTY_PRINT",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"jsonEncodeOptions",
"^=",
"JSON_PRETTY_PRINT",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Enables `json_encode` pretty print.
|
[
"Enables",
"json_encode",
"pretty",
"print",
"."
] |
ebb804e432e8fe0fe96828f30d89c45581d36d07
|
https://github.com/Seldaek/monolog/blob/ebb804e432e8fe0fe96828f30d89c45581d36d07/src/Monolog/Formatter/NormalizerFormatter.php#L97-L106
|
220,680
|
Seldaek/monolog
|
src/Monolog/Formatter/NormalizerFormatter.php
|
NormalizerFormatter.toJson
|
protected function toJson($data, bool $ignoreErrors = false)
{
// suppress json_encode errors since it's twitchy with some inputs
if ($ignoreErrors) {
return @$this->jsonEncode($data);
}
$json = $this->jsonEncode($data);
if ($json === false) {
$json = $this->handleJsonError(json_last_error(), $data);
}
return $json;
}
|
php
|
protected function toJson($data, bool $ignoreErrors = false)
{
// suppress json_encode errors since it's twitchy with some inputs
if ($ignoreErrors) {
return @$this->jsonEncode($data);
}
$json = $this->jsonEncode($data);
if ($json === false) {
$json = $this->handleJsonError(json_last_error(), $data);
}
return $json;
}
|
[
"protected",
"function",
"toJson",
"(",
"$",
"data",
",",
"bool",
"$",
"ignoreErrors",
"=",
"false",
")",
"{",
"// suppress json_encode errors since it's twitchy with some inputs",
"if",
"(",
"$",
"ignoreErrors",
")",
"{",
"return",
"@",
"$",
"this",
"->",
"jsonEncode",
"(",
"$",
"data",
")",
";",
"}",
"$",
"json",
"=",
"$",
"this",
"->",
"jsonEncode",
"(",
"$",
"data",
")",
";",
"if",
"(",
"$",
"json",
"===",
"false",
")",
"{",
"$",
"json",
"=",
"$",
"this",
"->",
"handleJsonError",
"(",
"json_last_error",
"(",
")",
",",
"$",
"data",
")",
";",
"}",
"return",
"$",
"json",
";",
"}"
] |
Return the JSON representation of a value
@param mixed $data
@throws \RuntimeException if encoding fails and errors are not ignored
@return string|bool
|
[
"Return",
"the",
"JSON",
"representation",
"of",
"a",
"value"
] |
ebb804e432e8fe0fe96828f30d89c45581d36d07
|
https://github.com/Seldaek/monolog/blob/ebb804e432e8fe0fe96828f30d89c45581d36d07/src/Monolog/Formatter/NormalizerFormatter.php#L244-L258
|
220,681
|
Seldaek/monolog
|
src/Monolog/Formatter/NormalizerFormatter.php
|
NormalizerFormatter.handleJsonError
|
private function handleJsonError(int $code, $data): string
{
if ($code !== JSON_ERROR_UTF8) {
$this->throwEncodeError($code, $data);
}
if (is_string($data)) {
$this->detectAndCleanUtf8($data);
} elseif (is_array($data)) {
array_walk_recursive($data, [$this, 'detectAndCleanUtf8']);
} else {
$this->throwEncodeError($code, $data);
}
$json = $this->jsonEncode($data);
if ($json === false) {
$this->throwEncodeError(json_last_error(), $data);
}
return $json;
}
|
php
|
private function handleJsonError(int $code, $data): string
{
if ($code !== JSON_ERROR_UTF8) {
$this->throwEncodeError($code, $data);
}
if (is_string($data)) {
$this->detectAndCleanUtf8($data);
} elseif (is_array($data)) {
array_walk_recursive($data, [$this, 'detectAndCleanUtf8']);
} else {
$this->throwEncodeError($code, $data);
}
$json = $this->jsonEncode($data);
if ($json === false) {
$this->throwEncodeError(json_last_error(), $data);
}
return $json;
}
|
[
"private",
"function",
"handleJsonError",
"(",
"int",
"$",
"code",
",",
"$",
"data",
")",
":",
"string",
"{",
"if",
"(",
"$",
"code",
"!==",
"JSON_ERROR_UTF8",
")",
"{",
"$",
"this",
"->",
"throwEncodeError",
"(",
"$",
"code",
",",
"$",
"data",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"data",
")",
")",
"{",
"$",
"this",
"->",
"detectAndCleanUtf8",
"(",
"$",
"data",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"array_walk_recursive",
"(",
"$",
"data",
",",
"[",
"$",
"this",
",",
"'detectAndCleanUtf8'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"throwEncodeError",
"(",
"$",
"code",
",",
"$",
"data",
")",
";",
"}",
"$",
"json",
"=",
"$",
"this",
"->",
"jsonEncode",
"(",
"$",
"data",
")",
";",
"if",
"(",
"$",
"json",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"throwEncodeError",
"(",
"json_last_error",
"(",
")",
",",
"$",
"data",
")",
";",
"}",
"return",
"$",
"json",
";",
"}"
] |
Handle a json_encode failure.
If the failure is due to invalid string encoding, try to clean the
input and encode again. If the second encoding attempt fails, the
initial error is not encoding related or the input can't be cleaned then
raise a descriptive exception.
@param int $code return code of json_last_error function
@param mixed $data data that was meant to be encoded
@throws \RuntimeException if failure can't be corrected
@return string JSON encoded data after error correction
|
[
"Handle",
"a",
"json_encode",
"failure",
"."
] |
ebb804e432e8fe0fe96828f30d89c45581d36d07
|
https://github.com/Seldaek/monolog/blob/ebb804e432e8fe0fe96828f30d89c45581d36d07/src/Monolog/Formatter/NormalizerFormatter.php#L282-L303
|
220,682
|
Seldaek/monolog
|
src/Monolog/Formatter/NormalizerFormatter.php
|
NormalizerFormatter.throwEncodeError
|
private function throwEncodeError(int $code, $data)
{
switch ($code) {
case JSON_ERROR_DEPTH:
$msg = 'Maximum stack depth exceeded';
break;
case JSON_ERROR_STATE_MISMATCH:
$msg = 'Underflow or the modes mismatch';
break;
case JSON_ERROR_CTRL_CHAR:
$msg = 'Unexpected control character found';
break;
case JSON_ERROR_UTF8:
$msg = 'Malformed UTF-8 characters, possibly incorrectly encoded';
break;
default:
$msg = 'Unknown error';
}
throw new \RuntimeException('JSON encoding failed: '.$msg.'. Encoding: '.var_export($data, true));
}
|
php
|
private function throwEncodeError(int $code, $data)
{
switch ($code) {
case JSON_ERROR_DEPTH:
$msg = 'Maximum stack depth exceeded';
break;
case JSON_ERROR_STATE_MISMATCH:
$msg = 'Underflow or the modes mismatch';
break;
case JSON_ERROR_CTRL_CHAR:
$msg = 'Unexpected control character found';
break;
case JSON_ERROR_UTF8:
$msg = 'Malformed UTF-8 characters, possibly incorrectly encoded';
break;
default:
$msg = 'Unknown error';
}
throw new \RuntimeException('JSON encoding failed: '.$msg.'. Encoding: '.var_export($data, true));
}
|
[
"private",
"function",
"throwEncodeError",
"(",
"int",
"$",
"code",
",",
"$",
"data",
")",
"{",
"switch",
"(",
"$",
"code",
")",
"{",
"case",
"JSON_ERROR_DEPTH",
":",
"$",
"msg",
"=",
"'Maximum stack depth exceeded'",
";",
"break",
";",
"case",
"JSON_ERROR_STATE_MISMATCH",
":",
"$",
"msg",
"=",
"'Underflow or the modes mismatch'",
";",
"break",
";",
"case",
"JSON_ERROR_CTRL_CHAR",
":",
"$",
"msg",
"=",
"'Unexpected control character found'",
";",
"break",
";",
"case",
"JSON_ERROR_UTF8",
":",
"$",
"msg",
"=",
"'Malformed UTF-8 characters, possibly incorrectly encoded'",
";",
"break",
";",
"default",
":",
"$",
"msg",
"=",
"'Unknown error'",
";",
"}",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'JSON encoding failed: '",
".",
"$",
"msg",
".",
"'. Encoding: '",
".",
"var_export",
"(",
"$",
"data",
",",
"true",
")",
")",
";",
"}"
] |
Throws an exception according to a given code with a customized message
@param int $code return code of json_last_error function
@param mixed $data data that was meant to be encoded
@throws \RuntimeException
|
[
"Throws",
"an",
"exception",
"according",
"to",
"a",
"given",
"code",
"with",
"a",
"customized",
"message"
] |
ebb804e432e8fe0fe96828f30d89c45581d36d07
|
https://github.com/Seldaek/monolog/blob/ebb804e432e8fe0fe96828f30d89c45581d36d07/src/Monolog/Formatter/NormalizerFormatter.php#L312-L332
|
220,683
|
Seldaek/monolog
|
src/Monolog/Handler/CubeHandler.php
|
CubeHandler.connectUdp
|
protected function connectUdp(): void
{
if (!extension_loaded('sockets')) {
throw new MissingExtensionException('The sockets extension is required to use udp URLs with the CubeHandler');
}
$this->udpConnection = socket_create(AF_INET, SOCK_DGRAM, 0);
if (!$this->udpConnection) {
throw new \LogicException('Unable to create a socket');
}
if (!socket_connect($this->udpConnection, $this->host, $this->port)) {
throw new \LogicException('Unable to connect to the socket at ' . $this->host . ':' . $this->port);
}
}
|
php
|
protected function connectUdp(): void
{
if (!extension_loaded('sockets')) {
throw new MissingExtensionException('The sockets extension is required to use udp URLs with the CubeHandler');
}
$this->udpConnection = socket_create(AF_INET, SOCK_DGRAM, 0);
if (!$this->udpConnection) {
throw new \LogicException('Unable to create a socket');
}
if (!socket_connect($this->udpConnection, $this->host, $this->port)) {
throw new \LogicException('Unable to connect to the socket at ' . $this->host . ':' . $this->port);
}
}
|
[
"protected",
"function",
"connectUdp",
"(",
")",
":",
"void",
"{",
"if",
"(",
"!",
"extension_loaded",
"(",
"'sockets'",
")",
")",
"{",
"throw",
"new",
"MissingExtensionException",
"(",
"'The sockets extension is required to use udp URLs with the CubeHandler'",
")",
";",
"}",
"$",
"this",
"->",
"udpConnection",
"=",
"socket_create",
"(",
"AF_INET",
",",
"SOCK_DGRAM",
",",
"0",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"udpConnection",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Unable to create a socket'",
")",
";",
"}",
"if",
"(",
"!",
"socket_connect",
"(",
"$",
"this",
"->",
"udpConnection",
",",
"$",
"this",
"->",
"host",
",",
"$",
"this",
"->",
"port",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Unable to connect to the socket at '",
".",
"$",
"this",
"->",
"host",
".",
"':'",
".",
"$",
"this",
"->",
"port",
")",
";",
"}",
"}"
] |
Establish a connection to an UDP socket
@throws \LogicException when unable to connect to the socket
@throws MissingExtensionException when there is no socket extension
|
[
"Establish",
"a",
"connection",
"to",
"an",
"UDP",
"socket"
] |
ebb804e432e8fe0fe96828f30d89c45581d36d07
|
https://github.com/Seldaek/monolog/blob/ebb804e432e8fe0fe96828f30d89c45581d36d07/src/Monolog/Handler/CubeHandler.php#L66-L80
|
220,684
|
Seldaek/monolog
|
src/Monolog/Handler/CubeHandler.php
|
CubeHandler.connectHttp
|
protected function connectHttp(): void
{
if (!extension_loaded('curl')) {
throw new MissingExtensionException('The curl extension is required to use http URLs with the CubeHandler');
}
$this->httpConnection = curl_init('http://'.$this->host.':'.$this->port.'/1.0/event/put');
if (!$this->httpConnection) {
throw new \LogicException('Unable to connect to ' . $this->host . ':' . $this->port);
}
curl_setopt($this->httpConnection, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($this->httpConnection, CURLOPT_RETURNTRANSFER, true);
}
|
php
|
protected function connectHttp(): void
{
if (!extension_loaded('curl')) {
throw new MissingExtensionException('The curl extension is required to use http URLs with the CubeHandler');
}
$this->httpConnection = curl_init('http://'.$this->host.':'.$this->port.'/1.0/event/put');
if (!$this->httpConnection) {
throw new \LogicException('Unable to connect to ' . $this->host . ':' . $this->port);
}
curl_setopt($this->httpConnection, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($this->httpConnection, CURLOPT_RETURNTRANSFER, true);
}
|
[
"protected",
"function",
"connectHttp",
"(",
")",
":",
"void",
"{",
"if",
"(",
"!",
"extension_loaded",
"(",
"'curl'",
")",
")",
"{",
"throw",
"new",
"MissingExtensionException",
"(",
"'The curl extension is required to use http URLs with the CubeHandler'",
")",
";",
"}",
"$",
"this",
"->",
"httpConnection",
"=",
"curl_init",
"(",
"'http://'",
".",
"$",
"this",
"->",
"host",
".",
"':'",
".",
"$",
"this",
"->",
"port",
".",
"'/1.0/event/put'",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"httpConnection",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Unable to connect to '",
".",
"$",
"this",
"->",
"host",
".",
"':'",
".",
"$",
"this",
"->",
"port",
")",
";",
"}",
"curl_setopt",
"(",
"$",
"this",
"->",
"httpConnection",
",",
"CURLOPT_CUSTOMREQUEST",
",",
"\"POST\"",
")",
";",
"curl_setopt",
"(",
"$",
"this",
"->",
"httpConnection",
",",
"CURLOPT_RETURNTRANSFER",
",",
"true",
")",
";",
"}"
] |
Establish a connection to an http server
@throws \LogicException when unable to connect to the socket
@throws MissingExtensionException when no curl extension
|
[
"Establish",
"a",
"connection",
"to",
"an",
"http",
"server"
] |
ebb804e432e8fe0fe96828f30d89c45581d36d07
|
https://github.com/Seldaek/monolog/blob/ebb804e432e8fe0fe96828f30d89c45581d36d07/src/Monolog/Handler/CubeHandler.php#L88-L102
|
220,685
|
Seldaek/monolog
|
src/Monolog/Logger.php
|
Logger.setHandlers
|
public function setHandlers(array $handlers): self
{
$this->handlers = [];
foreach (array_reverse($handlers) as $handler) {
$this->pushHandler($handler);
}
return $this;
}
|
php
|
public function setHandlers(array $handlers): self
{
$this->handlers = [];
foreach (array_reverse($handlers) as $handler) {
$this->pushHandler($handler);
}
return $this;
}
|
[
"public",
"function",
"setHandlers",
"(",
"array",
"$",
"handlers",
")",
":",
"self",
"{",
"$",
"this",
"->",
"handlers",
"=",
"[",
"]",
";",
"foreach",
"(",
"array_reverse",
"(",
"$",
"handlers",
")",
"as",
"$",
"handler",
")",
"{",
"$",
"this",
"->",
"pushHandler",
"(",
"$",
"handler",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Set handlers, replacing all existing ones.
If a map is passed, keys will be ignored.
@param HandlerInterface[] $handlers
|
[
"Set",
"handlers",
"replacing",
"all",
"existing",
"ones",
"."
] |
ebb804e432e8fe0fe96828f30d89c45581d36d07
|
https://github.com/Seldaek/monolog/blob/ebb804e432e8fe0fe96828f30d89c45581d36d07/src/Monolog/Logger.php#L203-L211
|
220,686
|
Seldaek/monolog
|
src/Monolog/Logger.php
|
Logger.reset
|
public function reset(): void
{
foreach ($this->handlers as $handler) {
if ($handler instanceof ResettableInterface) {
$handler->reset();
}
}
foreach ($this->processors as $processor) {
if ($processor instanceof ResettableInterface) {
$processor->reset();
}
}
}
|
php
|
public function reset(): void
{
foreach ($this->handlers as $handler) {
if ($handler instanceof ResettableInterface) {
$handler->reset();
}
}
foreach ($this->processors as $processor) {
if ($processor instanceof ResettableInterface) {
$processor->reset();
}
}
}
|
[
"public",
"function",
"reset",
"(",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"this",
"->",
"handlers",
"as",
"$",
"handler",
")",
"{",
"if",
"(",
"$",
"handler",
"instanceof",
"ResettableInterface",
")",
"{",
"$",
"handler",
"->",
"reset",
"(",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"this",
"->",
"processors",
"as",
"$",
"processor",
")",
"{",
"if",
"(",
"$",
"processor",
"instanceof",
"ResettableInterface",
")",
"{",
"$",
"processor",
"->",
"reset",
"(",
")",
";",
"}",
"}",
"}"
] |
Ends a log cycle and resets all handlers and processors to their initial state.
Resetting a Handler or a Processor means flushing/cleaning all buffers, resetting internal
state, and getting it back to a state in which it can receive log records again.
This is useful in case you want to avoid logs leaking between two requests or jobs when you
have a long running process like a worker or an application server serving multiple requests
in one process.
|
[
"Ends",
"a",
"log",
"cycle",
"and",
"resets",
"all",
"handlers",
"and",
"processors",
"to",
"their",
"initial",
"state",
"."
] |
ebb804e432e8fe0fe96828f30d89c45581d36d07
|
https://github.com/Seldaek/monolog/blob/ebb804e432e8fe0fe96828f30d89c45581d36d07/src/Monolog/Logger.php#L363-L376
|
220,687
|
Seldaek/monolog
|
src/Monolog/Logger.php
|
Logger.handleException
|
protected function handleException(Throwable $e, array $record)
{
if (!$this->exceptionHandler) {
throw $e;
}
call_user_func($this->exceptionHandler, $e, $record);
}
|
php
|
protected function handleException(Throwable $e, array $record)
{
if (!$this->exceptionHandler) {
throw $e;
}
call_user_func($this->exceptionHandler, $e, $record);
}
|
[
"protected",
"function",
"handleException",
"(",
"Throwable",
"$",
"e",
",",
"array",
"$",
"record",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"exceptionHandler",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"call_user_func",
"(",
"$",
"this",
"->",
"exceptionHandler",
",",
"$",
"e",
",",
"$",
"record",
")",
";",
"}"
] |
Delegates exception management to the custom exception handler,
or throws the exception if no custom handler is set.
|
[
"Delegates",
"exception",
"management",
"to",
"the",
"custom",
"exception",
"handler",
"or",
"throws",
"the",
"exception",
"if",
"no",
"custom",
"handler",
"is",
"set",
"."
] |
ebb804e432e8fe0fe96828f30d89c45581d36d07
|
https://github.com/Seldaek/monolog/blob/ebb804e432e8fe0fe96828f30d89c45581d36d07/src/Monolog/Logger.php#L598-L605
|
220,688
|
Seldaek/monolog
|
src/Monolog/Handler/SqsHandler.php
|
SqsHandler.write
|
protected function write(array $record): void
{
if (!isset($record['formatted']) || 'string' !== gettype($record['formatted'])) {
throw new \InvalidArgumentException('SqsHandler accepts only formatted records as a string');
}
$messageBody = $record['formatted'];
if (strlen($messageBody) >= static::MAX_MESSAGE_SIZE) {
$messageBody = substr($messageBody, 0, static::HEAD_MESSAGE_SIZE);
}
$this->client->sendMessage([
'QueueUrl' => $this->queueUrl,
'MessageBody' => $messageBody,
]);
}
|
php
|
protected function write(array $record): void
{
if (!isset($record['formatted']) || 'string' !== gettype($record['formatted'])) {
throw new \InvalidArgumentException('SqsHandler accepts only formatted records as a string');
}
$messageBody = $record['formatted'];
if (strlen($messageBody) >= static::MAX_MESSAGE_SIZE) {
$messageBody = substr($messageBody, 0, static::HEAD_MESSAGE_SIZE);
}
$this->client->sendMessage([
'QueueUrl' => $this->queueUrl,
'MessageBody' => $messageBody,
]);
}
|
[
"protected",
"function",
"write",
"(",
"array",
"$",
"record",
")",
":",
"void",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"record",
"[",
"'formatted'",
"]",
")",
"||",
"'string'",
"!==",
"gettype",
"(",
"$",
"record",
"[",
"'formatted'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'SqsHandler accepts only formatted records as a string'",
")",
";",
"}",
"$",
"messageBody",
"=",
"$",
"record",
"[",
"'formatted'",
"]",
";",
"if",
"(",
"strlen",
"(",
"$",
"messageBody",
")",
">=",
"static",
"::",
"MAX_MESSAGE_SIZE",
")",
"{",
"$",
"messageBody",
"=",
"substr",
"(",
"$",
"messageBody",
",",
"0",
",",
"static",
"::",
"HEAD_MESSAGE_SIZE",
")",
";",
"}",
"$",
"this",
"->",
"client",
"->",
"sendMessage",
"(",
"[",
"'QueueUrl'",
"=>",
"$",
"this",
"->",
"queueUrl",
",",
"'MessageBody'",
"=>",
"$",
"messageBody",
",",
"]",
")",
";",
"}"
] |
Writes the record down to the log of the implementing handler.
@param array $record
|
[
"Writes",
"the",
"record",
"down",
"to",
"the",
"log",
"of",
"the",
"implementing",
"handler",
"."
] |
ebb804e432e8fe0fe96828f30d89c45581d36d07
|
https://github.com/Seldaek/monolog/blob/ebb804e432e8fe0fe96828f30d89c45581d36d07/src/Monolog/Handler/SqsHandler.php#L47-L62
|
220,689
|
Seldaek/monolog
|
src/Monolog/Handler/HipChatHandler.php
|
HipChatHandler.finalizeWrite
|
protected function finalizeWrite(): void
{
$res = $this->getResource();
if (is_resource($res)) {
@fread($res, 2048);
}
$this->closeSocket();
}
|
php
|
protected function finalizeWrite(): void
{
$res = $this->getResource();
if (is_resource($res)) {
@fread($res, 2048);
}
$this->closeSocket();
}
|
[
"protected",
"function",
"finalizeWrite",
"(",
")",
":",
"void",
"{",
"$",
"res",
"=",
"$",
"this",
"->",
"getResource",
"(",
")",
";",
"if",
"(",
"is_resource",
"(",
"$",
"res",
")",
")",
"{",
"@",
"fread",
"(",
"$",
"res",
",",
"2048",
")",
";",
"}",
"$",
"this",
"->",
"closeSocket",
"(",
")",
";",
"}"
] |
Finalizes the request by reading some bytes and then closing the socket
If we do not read some but close the socket too early, hipchat sometimes
drops the request entirely.
|
[
"Finalizes",
"the",
"request",
"by",
"reading",
"some",
"bytes",
"and",
"then",
"closing",
"the",
"socket"
] |
ebb804e432e8fe0fe96828f30d89c45581d36d07
|
https://github.com/Seldaek/monolog/blob/ebb804e432e8fe0fe96828f30d89c45581d36d07/src/Monolog/Handler/HipChatHandler.php#L190-L197
|
220,690
|
Seldaek/monolog
|
src/Monolog/Handler/HipChatHandler.php
|
HipChatHandler.combineRecords
|
private function combineRecords(array $records): array
{
$batchRecord = null;
$batchRecords = [];
$messages = [];
$formattedMessages = [];
$level = 0;
$levelName = null;
$datetime = null;
foreach ($records as $record) {
$record = $this->processRecord($record);
if ($record['level'] > $level) {
$level = $record['level'];
$levelName = $record['level_name'];
}
if (null === $datetime) {
$datetime = $record['datetime'];
}
$messages[] = $record['message'];
$messageStr = implode(PHP_EOL, $messages);
$formattedMessages[] = $this->getFormatter()->format($record);
$formattedMessageStr = implode('', $formattedMessages);
$batchRecord = [
'message' => $messageStr,
'formatted' => $formattedMessageStr,
'context' => [],
'extra' => [],
];
if (!$this->validateStringLength($batchRecord['formatted'], static::MAXIMUM_MESSAGE_LENGTH)) {
// Pop the last message and implode the remaining messages
$lastMessage = array_pop($messages);
$lastFormattedMessage = array_pop($formattedMessages);
$batchRecord['message'] = implode(PHP_EOL, $messages);
$batchRecord['formatted'] = implode('', $formattedMessages);
$batchRecords[] = $batchRecord;
$messages = [$lastMessage];
$formattedMessages = [$lastFormattedMessage];
$batchRecord = null;
}
}
if (null !== $batchRecord) {
$batchRecords[] = $batchRecord;
}
// Set the max level and datetime for all records
foreach ($batchRecords as &$batchRecord) {
$batchRecord = array_merge(
$batchRecord,
[
'level' => $level,
'level_name' => $levelName,
'datetime' => $datetime,
]
);
}
return $batchRecords;
}
|
php
|
private function combineRecords(array $records): array
{
$batchRecord = null;
$batchRecords = [];
$messages = [];
$formattedMessages = [];
$level = 0;
$levelName = null;
$datetime = null;
foreach ($records as $record) {
$record = $this->processRecord($record);
if ($record['level'] > $level) {
$level = $record['level'];
$levelName = $record['level_name'];
}
if (null === $datetime) {
$datetime = $record['datetime'];
}
$messages[] = $record['message'];
$messageStr = implode(PHP_EOL, $messages);
$formattedMessages[] = $this->getFormatter()->format($record);
$formattedMessageStr = implode('', $formattedMessages);
$batchRecord = [
'message' => $messageStr,
'formatted' => $formattedMessageStr,
'context' => [],
'extra' => [],
];
if (!$this->validateStringLength($batchRecord['formatted'], static::MAXIMUM_MESSAGE_LENGTH)) {
// Pop the last message and implode the remaining messages
$lastMessage = array_pop($messages);
$lastFormattedMessage = array_pop($formattedMessages);
$batchRecord['message'] = implode(PHP_EOL, $messages);
$batchRecord['formatted'] = implode('', $formattedMessages);
$batchRecords[] = $batchRecord;
$messages = [$lastMessage];
$formattedMessages = [$lastFormattedMessage];
$batchRecord = null;
}
}
if (null !== $batchRecord) {
$batchRecords[] = $batchRecord;
}
// Set the max level and datetime for all records
foreach ($batchRecords as &$batchRecord) {
$batchRecord = array_merge(
$batchRecord,
[
'level' => $level,
'level_name' => $levelName,
'datetime' => $datetime,
]
);
}
return $batchRecords;
}
|
[
"private",
"function",
"combineRecords",
"(",
"array",
"$",
"records",
")",
":",
"array",
"{",
"$",
"batchRecord",
"=",
"null",
";",
"$",
"batchRecords",
"=",
"[",
"]",
";",
"$",
"messages",
"=",
"[",
"]",
";",
"$",
"formattedMessages",
"=",
"[",
"]",
";",
"$",
"level",
"=",
"0",
";",
"$",
"levelName",
"=",
"null",
";",
"$",
"datetime",
"=",
"null",
";",
"foreach",
"(",
"$",
"records",
"as",
"$",
"record",
")",
"{",
"$",
"record",
"=",
"$",
"this",
"->",
"processRecord",
"(",
"$",
"record",
")",
";",
"if",
"(",
"$",
"record",
"[",
"'level'",
"]",
">",
"$",
"level",
")",
"{",
"$",
"level",
"=",
"$",
"record",
"[",
"'level'",
"]",
";",
"$",
"levelName",
"=",
"$",
"record",
"[",
"'level_name'",
"]",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"datetime",
")",
"{",
"$",
"datetime",
"=",
"$",
"record",
"[",
"'datetime'",
"]",
";",
"}",
"$",
"messages",
"[",
"]",
"=",
"$",
"record",
"[",
"'message'",
"]",
";",
"$",
"messageStr",
"=",
"implode",
"(",
"PHP_EOL",
",",
"$",
"messages",
")",
";",
"$",
"formattedMessages",
"[",
"]",
"=",
"$",
"this",
"->",
"getFormatter",
"(",
")",
"->",
"format",
"(",
"$",
"record",
")",
";",
"$",
"formattedMessageStr",
"=",
"implode",
"(",
"''",
",",
"$",
"formattedMessages",
")",
";",
"$",
"batchRecord",
"=",
"[",
"'message'",
"=>",
"$",
"messageStr",
",",
"'formatted'",
"=>",
"$",
"formattedMessageStr",
",",
"'context'",
"=>",
"[",
"]",
",",
"'extra'",
"=>",
"[",
"]",
",",
"]",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"validateStringLength",
"(",
"$",
"batchRecord",
"[",
"'formatted'",
"]",
",",
"static",
"::",
"MAXIMUM_MESSAGE_LENGTH",
")",
")",
"{",
"// Pop the last message and implode the remaining messages",
"$",
"lastMessage",
"=",
"array_pop",
"(",
"$",
"messages",
")",
";",
"$",
"lastFormattedMessage",
"=",
"array_pop",
"(",
"$",
"formattedMessages",
")",
";",
"$",
"batchRecord",
"[",
"'message'",
"]",
"=",
"implode",
"(",
"PHP_EOL",
",",
"$",
"messages",
")",
";",
"$",
"batchRecord",
"[",
"'formatted'",
"]",
"=",
"implode",
"(",
"''",
",",
"$",
"formattedMessages",
")",
";",
"$",
"batchRecords",
"[",
"]",
"=",
"$",
"batchRecord",
";",
"$",
"messages",
"=",
"[",
"$",
"lastMessage",
"]",
";",
"$",
"formattedMessages",
"=",
"[",
"$",
"lastFormattedMessage",
"]",
";",
"$",
"batchRecord",
"=",
"null",
";",
"}",
"}",
"if",
"(",
"null",
"!==",
"$",
"batchRecord",
")",
"{",
"$",
"batchRecords",
"[",
"]",
"=",
"$",
"batchRecord",
";",
"}",
"// Set the max level and datetime for all records",
"foreach",
"(",
"$",
"batchRecords",
"as",
"&",
"$",
"batchRecord",
")",
"{",
"$",
"batchRecord",
"=",
"array_merge",
"(",
"$",
"batchRecord",
",",
"[",
"'level'",
"=>",
"$",
"level",
",",
"'level_name'",
"=>",
"$",
"levelName",
",",
"'datetime'",
"=>",
"$",
"datetime",
",",
"]",
")",
";",
"}",
"return",
"$",
"batchRecords",
";",
"}"
] |
Combines multiple records into one. Error level of the combined record
will be the highest level from the given records. Datetime will be taken
from the first record.
|
[
"Combines",
"multiple",
"records",
"into",
"one",
".",
"Error",
"level",
"of",
"the",
"combined",
"record",
"will",
"be",
"the",
"highest",
"level",
"from",
"the",
"given",
"records",
".",
"Datetime",
"will",
"be",
"taken",
"from",
"the",
"first",
"record",
"."
] |
ebb804e432e8fe0fe96828f30d89c45581d36d07
|
https://github.com/Seldaek/monolog/blob/ebb804e432e8fe0fe96828f30d89c45581d36d07/src/Monolog/Handler/HipChatHandler.php#L220-L286
|
220,691
|
Seldaek/monolog
|
src/Monolog/Handler/Slack/SlackRecord.php
|
SlackRecord.generateAttachmentField
|
private function generateAttachmentField(string $title, $value): array
{
$value = is_array($value)
? sprintf('```%s```', $this->stringify($value))
: $value;
return array(
'title' => ucfirst($title),
'value' => $value,
'short' => false,
);
}
|
php
|
private function generateAttachmentField(string $title, $value): array
{
$value = is_array($value)
? sprintf('```%s```', $this->stringify($value))
: $value;
return array(
'title' => ucfirst($title),
'value' => $value,
'short' => false,
);
}
|
[
"private",
"function",
"generateAttachmentField",
"(",
"string",
"$",
"title",
",",
"$",
"value",
")",
":",
"array",
"{",
"$",
"value",
"=",
"is_array",
"(",
"$",
"value",
")",
"?",
"sprintf",
"(",
"'```%s```'",
",",
"$",
"this",
"->",
"stringify",
"(",
"$",
"value",
")",
")",
":",
"$",
"value",
";",
"return",
"array",
"(",
"'title'",
"=>",
"ucfirst",
"(",
"$",
"title",
")",
",",
"'value'",
"=>",
"$",
"value",
",",
"'short'",
"=>",
"false",
",",
")",
";",
"}"
] |
Generates attachment field
@param string|array $value
|
[
"Generates",
"attachment",
"field"
] |
ebb804e432e8fe0fe96828f30d89c45581d36d07
|
https://github.com/Seldaek/monolog/blob/ebb804e432e8fe0fe96828f30d89c45581d36d07/src/Monolog/Handler/Slack/SlackRecord.php#L223-L234
|
220,692
|
Seldaek/monolog
|
src/Monolog/Handler/Slack/SlackRecord.php
|
SlackRecord.generateAttachmentFields
|
private function generateAttachmentFields(array $data): array
{
$fields = array();
foreach ($this->normalizerFormatter->format($data) as $key => $value) {
$fields[] = $this->generateAttachmentField($key, $value);
}
return $fields;
}
|
php
|
private function generateAttachmentFields(array $data): array
{
$fields = array();
foreach ($this->normalizerFormatter->format($data) as $key => $value) {
$fields[] = $this->generateAttachmentField($key, $value);
}
return $fields;
}
|
[
"private",
"function",
"generateAttachmentFields",
"(",
"array",
"$",
"data",
")",
":",
"array",
"{",
"$",
"fields",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"normalizerFormatter",
"->",
"format",
"(",
"$",
"data",
")",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"fields",
"[",
"]",
"=",
"$",
"this",
"->",
"generateAttachmentField",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"fields",
";",
"}"
] |
Generates a collection of attachment fields from array
|
[
"Generates",
"a",
"collection",
"of",
"attachment",
"fields",
"from",
"array"
] |
ebb804e432e8fe0fe96828f30d89c45581d36d07
|
https://github.com/Seldaek/monolog/blob/ebb804e432e8fe0fe96828f30d89c45581d36d07/src/Monolog/Handler/Slack/SlackRecord.php#L239-L247
|
220,693
|
Seldaek/monolog
|
src/Monolog/Handler/NativeMailerHandler.php
|
NativeMailerHandler.addParameter
|
public function addParameter($parameters): self
{
$this->parameters = array_merge($this->parameters, (array) $parameters);
return $this;
}
|
php
|
public function addParameter($parameters): self
{
$this->parameters = array_merge($this->parameters, (array) $parameters);
return $this;
}
|
[
"public",
"function",
"addParameter",
"(",
"$",
"parameters",
")",
":",
"self",
"{",
"$",
"this",
"->",
"parameters",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"parameters",
",",
"(",
"array",
")",
"$",
"parameters",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Add parameters to the message
@param string|array $parameters Custom added parameters
|
[
"Add",
"parameters",
"to",
"the",
"message"
] |
ebb804e432e8fe0fe96828f30d89c45581d36d07
|
https://github.com/Seldaek/monolog/blob/ebb804e432e8fe0fe96828f30d89c45581d36d07/src/Monolog/Handler/NativeMailerHandler.php#L106-L111
|
220,694
|
Seldaek/monolog
|
src/Monolog/Registry.php
|
Registry.addLogger
|
public static function addLogger(Logger $logger, ?string $name = null, bool $overwrite = false)
{
$name = $name ?: $logger->getName();
if (isset(self::$loggers[$name]) && !$overwrite) {
throw new InvalidArgumentException('Logger with the given name already exists');
}
self::$loggers[$name] = $logger;
}
|
php
|
public static function addLogger(Logger $logger, ?string $name = null, bool $overwrite = false)
{
$name = $name ?: $logger->getName();
if (isset(self::$loggers[$name]) && !$overwrite) {
throw new InvalidArgumentException('Logger with the given name already exists');
}
self::$loggers[$name] = $logger;
}
|
[
"public",
"static",
"function",
"addLogger",
"(",
"Logger",
"$",
"logger",
",",
"?",
"string",
"$",
"name",
"=",
"null",
",",
"bool",
"$",
"overwrite",
"=",
"false",
")",
"{",
"$",
"name",
"=",
"$",
"name",
"?",
":",
"$",
"logger",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"loggers",
"[",
"$",
"name",
"]",
")",
"&&",
"!",
"$",
"overwrite",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Logger with the given name already exists'",
")",
";",
"}",
"self",
"::",
"$",
"loggers",
"[",
"$",
"name",
"]",
"=",
"$",
"logger",
";",
"}"
] |
Adds new logging channel to the registry
@param Logger $logger Instance of the logging channel
@param string|null $name Name of the logging channel ($logger->getName() by default)
@param bool $overwrite Overwrite instance in the registry if the given name already exists?
@throws \InvalidArgumentException If $overwrite set to false and named Logger instance already exists
|
[
"Adds",
"new",
"logging",
"channel",
"to",
"the",
"registry"
] |
ebb804e432e8fe0fe96828f30d89c45581d36d07
|
https://github.com/Seldaek/monolog/blob/ebb804e432e8fe0fe96828f30d89c45581d36d07/src/Monolog/Registry.php#L55-L64
|
220,695
|
Seldaek/monolog
|
src/Monolog/Handler/FingersCrossedHandler.php
|
FingersCrossedHandler.activate
|
public function activate(): void
{
if ($this->stopBuffering) {
$this->buffering = false;
}
if (!$this->handler instanceof HandlerInterface) {
$record = end($this->buffer) ?: null;
$this->handler = call_user_func($this->handler, $record, $this);
if (!$this->handler instanceof HandlerInterface) {
throw new \RuntimeException("The factory callable should return a HandlerInterface");
}
}
$this->handler->handleBatch($this->buffer);
$this->buffer = [];
}
|
php
|
public function activate(): void
{
if ($this->stopBuffering) {
$this->buffering = false;
}
if (!$this->handler instanceof HandlerInterface) {
$record = end($this->buffer) ?: null;
$this->handler = call_user_func($this->handler, $record, $this);
if (!$this->handler instanceof HandlerInterface) {
throw new \RuntimeException("The factory callable should return a HandlerInterface");
}
}
$this->handler->handleBatch($this->buffer);
$this->buffer = [];
}
|
[
"public",
"function",
"activate",
"(",
")",
":",
"void",
"{",
"if",
"(",
"$",
"this",
"->",
"stopBuffering",
")",
"{",
"$",
"this",
"->",
"buffering",
"=",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"handler",
"instanceof",
"HandlerInterface",
")",
"{",
"$",
"record",
"=",
"end",
"(",
"$",
"this",
"->",
"buffer",
")",
"?",
":",
"null",
";",
"$",
"this",
"->",
"handler",
"=",
"call_user_func",
"(",
"$",
"this",
"->",
"handler",
",",
"$",
"record",
",",
"$",
"this",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"handler",
"instanceof",
"HandlerInterface",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"The factory callable should return a HandlerInterface\"",
")",
";",
"}",
"}",
"$",
"this",
"->",
"handler",
"->",
"handleBatch",
"(",
"$",
"this",
"->",
"buffer",
")",
";",
"$",
"this",
"->",
"buffer",
"=",
"[",
"]",
";",
"}"
] |
Manually activate this logger regardless of the activation strategy
|
[
"Manually",
"activate",
"this",
"logger",
"regardless",
"of",
"the",
"activation",
"strategy"
] |
ebb804e432e8fe0fe96828f30d89c45581d36d07
|
https://github.com/Seldaek/monolog/blob/ebb804e432e8fe0fe96828f30d89c45581d36d07/src/Monolog/Handler/FingersCrossedHandler.php#L93-L108
|
220,696
|
Seldaek/monolog
|
src/Monolog/Handler/FingersCrossedHandler.php
|
FingersCrossedHandler.flushBuffer
|
private function flushBuffer(): void
{
if (null !== $this->passthruLevel) {
$level = $this->passthruLevel;
$this->buffer = array_filter($this->buffer, function ($record) use ($level) {
return $record['level'] >= $level;
});
if (count($this->buffer) > 0) {
$this->handler->handleBatch($this->buffer);
}
}
$this->buffer = [];
$this->buffering = true;
}
|
php
|
private function flushBuffer(): void
{
if (null !== $this->passthruLevel) {
$level = $this->passthruLevel;
$this->buffer = array_filter($this->buffer, function ($record) use ($level) {
return $record['level'] >= $level;
});
if (count($this->buffer) > 0) {
$this->handler->handleBatch($this->buffer);
}
}
$this->buffer = [];
$this->buffering = true;
}
|
[
"private",
"function",
"flushBuffer",
"(",
")",
":",
"void",
"{",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"passthruLevel",
")",
"{",
"$",
"level",
"=",
"$",
"this",
"->",
"passthruLevel",
";",
"$",
"this",
"->",
"buffer",
"=",
"array_filter",
"(",
"$",
"this",
"->",
"buffer",
",",
"function",
"(",
"$",
"record",
")",
"use",
"(",
"$",
"level",
")",
"{",
"return",
"$",
"record",
"[",
"'level'",
"]",
">=",
"$",
"level",
";",
"}",
")",
";",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"buffer",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"handler",
"->",
"handleBatch",
"(",
"$",
"this",
"->",
"buffer",
")",
";",
"}",
"}",
"$",
"this",
"->",
"buffer",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"buffering",
"=",
"true",
";",
"}"
] |
Resets the state of the handler. Stops forwarding records to the wrapped handler.
|
[
"Resets",
"the",
"state",
"of",
"the",
"handler",
".",
"Stops",
"forwarding",
"records",
"to",
"the",
"wrapped",
"handler",
"."
] |
ebb804e432e8fe0fe96828f30d89c45581d36d07
|
https://github.com/Seldaek/monolog/blob/ebb804e432e8fe0fe96828f30d89c45581d36d07/src/Monolog/Handler/FingersCrossedHandler.php#L169-L183
|
220,697
|
Seldaek/monolog
|
src/Monolog/Formatter/MongoDBFormatter.php
|
MongoDBFormatter.legacyGetMongoDbDateTime
|
private function legacyGetMongoDbDateTime(\DateTimeInterface $value): UTCDateTime
{
$milliseconds = floor($value->format('U.u') * 1000);
$milliseconds = (PHP_INT_SIZE == 8) //64-bit OS?
? (int) $milliseconds
: (string) $milliseconds;
return new UTCDateTime($milliseconds);
}
|
php
|
private function legacyGetMongoDbDateTime(\DateTimeInterface $value): UTCDateTime
{
$milliseconds = floor($value->format('U.u') * 1000);
$milliseconds = (PHP_INT_SIZE == 8) //64-bit OS?
? (int) $milliseconds
: (string) $milliseconds;
return new UTCDateTime($milliseconds);
}
|
[
"private",
"function",
"legacyGetMongoDbDateTime",
"(",
"\\",
"DateTimeInterface",
"$",
"value",
")",
":",
"UTCDateTime",
"{",
"$",
"milliseconds",
"=",
"floor",
"(",
"$",
"value",
"->",
"format",
"(",
"'U.u'",
")",
"*",
"1000",
")",
";",
"$",
"milliseconds",
"=",
"(",
"PHP_INT_SIZE",
"==",
"8",
")",
"//64-bit OS?",
"?",
"(",
"int",
")",
"$",
"milliseconds",
":",
"(",
"string",
")",
"$",
"milliseconds",
";",
"return",
"new",
"UTCDateTime",
"(",
"$",
"milliseconds",
")",
";",
"}"
] |
This is needed to support MongoDB Driver v1.19 and below
See https://github.com/mongodb/mongo-php-driver/issues/426
It can probably be removed in 2.1 or later once MongoDB's 1.2 is released and widely adopted
|
[
"This",
"is",
"needed",
"to",
"support",
"MongoDB",
"Driver",
"v1",
".",
"19",
"and",
"below"
] |
ebb804e432e8fe0fe96828f30d89c45581d36d07
|
https://github.com/Seldaek/monolog/blob/ebb804e432e8fe0fe96828f30d89c45581d36d07/src/Monolog/Formatter/MongoDBFormatter.php#L131-L140
|
220,698
|
Seldaek/monolog
|
src/Monolog/Handler/ProcessHandler.php
|
ProcessHandler.ensureProcessIsStarted
|
private function ensureProcessIsStarted(): void
{
if (is_resource($this->process) === false) {
$this->startProcess();
$this->handleStartupErrors();
}
}
|
php
|
private function ensureProcessIsStarted(): void
{
if (is_resource($this->process) === false) {
$this->startProcess();
$this->handleStartupErrors();
}
}
|
[
"private",
"function",
"ensureProcessIsStarted",
"(",
")",
":",
"void",
"{",
"if",
"(",
"is_resource",
"(",
"$",
"this",
"->",
"process",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"startProcess",
"(",
")",
";",
"$",
"this",
"->",
"handleStartupErrors",
"(",
")",
";",
"}",
"}"
] |
Makes sure that the process is actually started, and if not, starts it,
assigns the stream pipes, and handles startup errors, if any.
|
[
"Makes",
"sure",
"that",
"the",
"process",
"is",
"actually",
"started",
"and",
"if",
"not",
"starts",
"it",
"assigns",
"the",
"stream",
"pipes",
"and",
"handles",
"startup",
"errors",
"if",
"any",
"."
] |
ebb804e432e8fe0fe96828f30d89c45581d36d07
|
https://github.com/Seldaek/monolog/blob/ebb804e432e8fe0fe96828f30d89c45581d36d07/src/Monolog/Handler/ProcessHandler.php#L104-L111
|
220,699
|
Seldaek/monolog
|
src/Monolog/Handler/ProcessHandler.php
|
ProcessHandler.startProcess
|
private function startProcess(): void
{
$this->process = proc_open($this->command, static::DESCRIPTOR_SPEC, $this->pipes, $this->cwd);
foreach ($this->pipes as $pipe) {
stream_set_blocking($pipe, false);
}
}
|
php
|
private function startProcess(): void
{
$this->process = proc_open($this->command, static::DESCRIPTOR_SPEC, $this->pipes, $this->cwd);
foreach ($this->pipes as $pipe) {
stream_set_blocking($pipe, false);
}
}
|
[
"private",
"function",
"startProcess",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"process",
"=",
"proc_open",
"(",
"$",
"this",
"->",
"command",
",",
"static",
"::",
"DESCRIPTOR_SPEC",
",",
"$",
"this",
"->",
"pipes",
",",
"$",
"this",
"->",
"cwd",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"pipes",
"as",
"$",
"pipe",
")",
"{",
"stream_set_blocking",
"(",
"$",
"pipe",
",",
"false",
")",
";",
"}",
"}"
] |
Starts the actual process and sets all streams to non-blocking.
|
[
"Starts",
"the",
"actual",
"process",
"and",
"sets",
"all",
"streams",
"to",
"non",
"-",
"blocking",
"."
] |
ebb804e432e8fe0fe96828f30d89c45581d36d07
|
https://github.com/Seldaek/monolog/blob/ebb804e432e8fe0fe96828f30d89c45581d36d07/src/Monolog/Handler/ProcessHandler.php#L116-L123
|
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.