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
sequence
docstring
stringlengths
3
47.2k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
botman/botman
src/BotMan.php
BotMan.listen
public function listen() { try { $isVerificationRequest = $this->verifyServices(); if (! $isVerificationRequest) { $this->fireDriverEvents(); if ($this->firedDriverEvents === false) { $this->loadActiveConversation(); if ($this->loadedConversation === false) { $this->callMatchingMessages(); } /* * If the driver has a "messagesHandled" method, call it. * This method can be used to trigger driver methods * once the messages are handles. */ if (method_exists($this->getDriver(), 'messagesHandled')) { $this->getDriver()->messagesHandled(); } } $this->firedDriverEvents = false; $this->message = new IncomingMessage('', '', ''); } } catch (\Throwable $e) { $this->exceptionHandler->handleException($e, $this); } }
php
public function listen() { try { $isVerificationRequest = $this->verifyServices(); if (! $isVerificationRequest) { $this->fireDriverEvents(); if ($this->firedDriverEvents === false) { $this->loadActiveConversation(); if ($this->loadedConversation === false) { $this->callMatchingMessages(); } /* * If the driver has a "messagesHandled" method, call it. * This method can be used to trigger driver methods * once the messages are handles. */ if (method_exists($this->getDriver(), 'messagesHandled')) { $this->getDriver()->messagesHandled(); } } $this->firedDriverEvents = false; $this->message = new IncomingMessage('', '', ''); } } catch (\Throwable $e) { $this->exceptionHandler->handleException($e, $this); } }
[ "public", "function", "listen", "(", ")", "{", "try", "{", "$", "isVerificationRequest", "=", "$", "this", "->", "verifyServices", "(", ")", ";", "if", "(", "!", "$", "isVerificationRequest", ")", "{", "$", "this", "->", "fireDriverEvents", "(", ")", ";", "if", "(", "$", "this", "->", "firedDriverEvents", "===", "false", ")", "{", "$", "this", "->", "loadActiveConversation", "(", ")", ";", "if", "(", "$", "this", "->", "loadedConversation", "===", "false", ")", "{", "$", "this", "->", "callMatchingMessages", "(", ")", ";", "}", "/*\n * If the driver has a \"messagesHandled\" method, call it.\n * This method can be used to trigger driver methods\n * once the messages are handles.\n */", "if", "(", "method_exists", "(", "$", "this", "->", "getDriver", "(", ")", ",", "'messagesHandled'", ")", ")", "{", "$", "this", "->", "getDriver", "(", ")", "->", "messagesHandled", "(", ")", ";", "}", "}", "$", "this", "->", "firedDriverEvents", "=", "false", ";", "$", "this", "->", "message", "=", "new", "IncomingMessage", "(", "''", ",", "''", ",", "''", ")", ";", "}", "}", "catch", "(", "\\", "Throwable", "$", "e", ")", "{", "$", "this", "->", "exceptionHandler", "->", "handleException", "(", "$", "e", ",", "$", "this", ")", ";", "}", "}" ]
Try to match messages with the ones we should listen to.
[ "Try", "to", "match", "messages", "with", "the", "ones", "we", "should", "listen", "to", "." ]
ac9ecf78d25f8e5703125efb2be8b5898f67cd54
https://github.com/botman/botman/blob/ac9ecf78d25f8e5703125efb2be8b5898f67cd54/src/BotMan.php#L409-L440
train
botman/botman
src/BotMan.php
BotMan.callMatchingMessages
protected function callMatchingMessages() { $matchingMessages = $this->conversationManager->getMatchingMessages($this->getMessages(), $this->middleware, $this->getConversationAnswer(), $this->getDriver()); foreach ($matchingMessages as $matchingMessage) { $this->command = $matchingMessage->getCommand(); $callback = $this->command->getCallback(); $callback = $this->getCallable($callback); // Set the message first, so it's available for middlewares $this->message = $matchingMessage->getMessage(); $commandMiddleware = Collection::make($this->command->getMiddleware())->filter(function ($middleware) { return $middleware instanceof Heard; })->toArray(); $this->message = $this->middleware->applyMiddleware('heard', $matchingMessage->getMessage(), $commandMiddleware); $parameterNames = $this->compileParameterNames($this->command->getPattern()); $parameters = $matchingMessage->getMatches(); if (\count($parameterNames) !== \count($parameters)) { $parameters = array_merge( //First, all named parameters (eg. function ($a, $b, $c)) array_filter( $parameters, '\is_string', ARRAY_FILTER_USE_KEY ), //Then, all other unsorted parameters (regex non named results) array_filter( $parameters, '\is_integer', ARRAY_FILTER_USE_KEY ) ); } $this->matches = $parameters; array_unshift($parameters, $this); $parameters = $this->conversationManager->addDataParameters($this->message, $parameters); if (call_user_func_array($callback, $parameters)) { return; } } if (empty($matchingMessages) && empty($this->getBotMessages()) && ! \is_null($this->fallbackMessage)) { $this->callFallbackMessage(); } }
php
protected function callMatchingMessages() { $matchingMessages = $this->conversationManager->getMatchingMessages($this->getMessages(), $this->middleware, $this->getConversationAnswer(), $this->getDriver()); foreach ($matchingMessages as $matchingMessage) { $this->command = $matchingMessage->getCommand(); $callback = $this->command->getCallback(); $callback = $this->getCallable($callback); // Set the message first, so it's available for middlewares $this->message = $matchingMessage->getMessage(); $commandMiddleware = Collection::make($this->command->getMiddleware())->filter(function ($middleware) { return $middleware instanceof Heard; })->toArray(); $this->message = $this->middleware->applyMiddleware('heard', $matchingMessage->getMessage(), $commandMiddleware); $parameterNames = $this->compileParameterNames($this->command->getPattern()); $parameters = $matchingMessage->getMatches(); if (\count($parameterNames) !== \count($parameters)) { $parameters = array_merge( //First, all named parameters (eg. function ($a, $b, $c)) array_filter( $parameters, '\is_string', ARRAY_FILTER_USE_KEY ), //Then, all other unsorted parameters (regex non named results) array_filter( $parameters, '\is_integer', ARRAY_FILTER_USE_KEY ) ); } $this->matches = $parameters; array_unshift($parameters, $this); $parameters = $this->conversationManager->addDataParameters($this->message, $parameters); if (call_user_func_array($callback, $parameters)) { return; } } if (empty($matchingMessages) && empty($this->getBotMessages()) && ! \is_null($this->fallbackMessage)) { $this->callFallbackMessage(); } }
[ "protected", "function", "callMatchingMessages", "(", ")", "{", "$", "matchingMessages", "=", "$", "this", "->", "conversationManager", "->", "getMatchingMessages", "(", "$", "this", "->", "getMessages", "(", ")", ",", "$", "this", "->", "middleware", ",", "$", "this", "->", "getConversationAnswer", "(", ")", ",", "$", "this", "->", "getDriver", "(", ")", ")", ";", "foreach", "(", "$", "matchingMessages", "as", "$", "matchingMessage", ")", "{", "$", "this", "->", "command", "=", "$", "matchingMessage", "->", "getCommand", "(", ")", ";", "$", "callback", "=", "$", "this", "->", "command", "->", "getCallback", "(", ")", ";", "$", "callback", "=", "$", "this", "->", "getCallable", "(", "$", "callback", ")", ";", "// Set the message first, so it's available for middlewares", "$", "this", "->", "message", "=", "$", "matchingMessage", "->", "getMessage", "(", ")", ";", "$", "commandMiddleware", "=", "Collection", "::", "make", "(", "$", "this", "->", "command", "->", "getMiddleware", "(", ")", ")", "->", "filter", "(", "function", "(", "$", "middleware", ")", "{", "return", "$", "middleware", "instanceof", "Heard", ";", "}", ")", "->", "toArray", "(", ")", ";", "$", "this", "->", "message", "=", "$", "this", "->", "middleware", "->", "applyMiddleware", "(", "'heard'", ",", "$", "matchingMessage", "->", "getMessage", "(", ")", ",", "$", "commandMiddleware", ")", ";", "$", "parameterNames", "=", "$", "this", "->", "compileParameterNames", "(", "$", "this", "->", "command", "->", "getPattern", "(", ")", ")", ";", "$", "parameters", "=", "$", "matchingMessage", "->", "getMatches", "(", ")", ";", "if", "(", "\\", "count", "(", "$", "parameterNames", ")", "!==", "\\", "count", "(", "$", "parameters", ")", ")", "{", "$", "parameters", "=", "array_merge", "(", "//First, all named parameters (eg. function ($a, $b, $c))", "array_filter", "(", "$", "parameters", ",", "'\\is_string'", ",", "ARRAY_FILTER_USE_KEY", ")", ",", "//Then, all other unsorted parameters (regex non named results)", "array_filter", "(", "$", "parameters", ",", "'\\is_integer'", ",", "ARRAY_FILTER_USE_KEY", ")", ")", ";", "}", "$", "this", "->", "matches", "=", "$", "parameters", ";", "array_unshift", "(", "$", "parameters", ",", "$", "this", ")", ";", "$", "parameters", "=", "$", "this", "->", "conversationManager", "->", "addDataParameters", "(", "$", "this", "->", "message", ",", "$", "parameters", ")", ";", "if", "(", "call_user_func_array", "(", "$", "callback", ",", "$", "parameters", ")", ")", "{", "return", ";", "}", "}", "if", "(", "empty", "(", "$", "matchingMessages", ")", "&&", "empty", "(", "$", "this", "->", "getBotMessages", "(", ")", ")", "&&", "!", "\\", "is_null", "(", "$", "this", "->", "fallbackMessage", ")", ")", "{", "$", "this", "->", "callFallbackMessage", "(", ")", ";", "}", "}" ]
Call matching message callbacks.
[ "Call", "matching", "message", "callbacks", "." ]
ac9ecf78d25f8e5703125efb2be8b5898f67cd54
https://github.com/botman/botman/blob/ac9ecf78d25f8e5703125efb2be8b5898f67cd54/src/BotMan.php#L445-L499
train
botman/botman
src/BotMan.php
BotMan.callFallbackMessage
protected function callFallbackMessage() { $messages = $this->getMessages(); if (! isset($messages[0])) { return; } $this->message = $messages[0]; $this->fallbackMessage = $this->getCallable($this->fallbackMessage); \call_user_func($this->fallbackMessage, $this); }
php
protected function callFallbackMessage() { $messages = $this->getMessages(); if (! isset($messages[0])) { return; } $this->message = $messages[0]; $this->fallbackMessage = $this->getCallable($this->fallbackMessage); \call_user_func($this->fallbackMessage, $this); }
[ "protected", "function", "callFallbackMessage", "(", ")", "{", "$", "messages", "=", "$", "this", "->", "getMessages", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "messages", "[", "0", "]", ")", ")", "{", "return", ";", "}", "$", "this", "->", "message", "=", "$", "messages", "[", "0", "]", ";", "$", "this", "->", "fallbackMessage", "=", "$", "this", "->", "getCallable", "(", "$", "this", "->", "fallbackMessage", ")", ";", "\\", "call_user_func", "(", "$", "this", "->", "fallbackMessage", ",", "$", "this", ")", ";", "}" ]
Call the fallback method.
[ "Call", "the", "fallback", "method", "." ]
ac9ecf78d25f8e5703125efb2be8b5898f67cd54
https://github.com/botman/botman/blob/ac9ecf78d25f8e5703125efb2be8b5898f67cd54/src/BotMan.php#L504-L517
train
botman/botman
src/Traits/HandlesConversations.php
HandlesConversations.getStoredConversation
public function getStoredConversation($message = null) { if (is_null($message)) { $message = $this->getMessage(); } $conversation = $this->cache->get($message->getConversationIdentifier()); if (is_null($conversation)) { $conversation = $this->cache->get($message->getOriginatedConversationIdentifier()); } return $conversation; }
php
public function getStoredConversation($message = null) { if (is_null($message)) { $message = $this->getMessage(); } $conversation = $this->cache->get($message->getConversationIdentifier()); if (is_null($conversation)) { $conversation = $this->cache->get($message->getOriginatedConversationIdentifier()); } return $conversation; }
[ "public", "function", "getStoredConversation", "(", "$", "message", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "message", ")", ")", "{", "$", "message", "=", "$", "this", "->", "getMessage", "(", ")", ";", "}", "$", "conversation", "=", "$", "this", "->", "cache", "->", "get", "(", "$", "message", "->", "getConversationIdentifier", "(", ")", ")", ";", "if", "(", "is_null", "(", "$", "conversation", ")", ")", "{", "$", "conversation", "=", "$", "this", "->", "cache", "->", "get", "(", "$", "message", "->", "getOriginatedConversationIdentifier", "(", ")", ")", ";", "}", "return", "$", "conversation", ";", "}" ]
Get a stored conversation array from the cache for a given message. @param null|IncomingMessage $message @return array
[ "Get", "a", "stored", "conversation", "array", "from", "the", "cache", "for", "a", "given", "message", "." ]
ac9ecf78d25f8e5703125efb2be8b5898f67cd54
https://github.com/botman/botman/blob/ac9ecf78d25f8e5703125efb2be8b5898f67cd54/src/Traits/HandlesConversations.php#L56-L68
train
botman/botman
src/Traits/HandlesConversations.php
HandlesConversations.touchCurrentConversation
public function touchCurrentConversation() { if (! is_null($this->currentConversationData)) { $touched = $this->currentConversationData; $touched['time'] = microtime(); $this->cache->put($this->message->getConversationIdentifier(), $touched, $this->config['config']['conversation_cache_time'] ?? 30); } }
php
public function touchCurrentConversation() { if (! is_null($this->currentConversationData)) { $touched = $this->currentConversationData; $touched['time'] = microtime(); $this->cache->put($this->message->getConversationIdentifier(), $touched, $this->config['config']['conversation_cache_time'] ?? 30); } }
[ "public", "function", "touchCurrentConversation", "(", ")", "{", "if", "(", "!", "is_null", "(", "$", "this", "->", "currentConversationData", ")", ")", "{", "$", "touched", "=", "$", "this", "->", "currentConversationData", ";", "$", "touched", "[", "'time'", "]", "=", "microtime", "(", ")", ";", "$", "this", "->", "cache", "->", "put", "(", "$", "this", "->", "message", "->", "getConversationIdentifier", "(", ")", ",", "$", "touched", ",", "$", "this", "->", "config", "[", "'config'", "]", "[", "'conversation_cache_time'", "]", "??", "30", ")", ";", "}", "}" ]
Touch and update the current conversation. @return void
[ "Touch", "and", "update", "the", "current", "conversation", "." ]
ac9ecf78d25f8e5703125efb2be8b5898f67cd54
https://github.com/botman/botman/blob/ac9ecf78d25f8e5703125efb2be8b5898f67cd54/src/Traits/HandlesConversations.php#L75-L83
train
botman/botman
src/Traits/HandlesConversations.php
HandlesConversations.removeStoredConversation
public function removeStoredConversation($message = null) { /* * Only remove it from the cache if it was not modified * after we loaded the data from the cache. */ if ($this->getStoredConversation($message)['time'] == $this->currentConversationData['time']) { $this->cache->pull($this->message->getConversationIdentifier()); $this->cache->pull($this->message->getOriginatedConversationIdentifier()); } }
php
public function removeStoredConversation($message = null) { /* * Only remove it from the cache if it was not modified * after we loaded the data from the cache. */ if ($this->getStoredConversation($message)['time'] == $this->currentConversationData['time']) { $this->cache->pull($this->message->getConversationIdentifier()); $this->cache->pull($this->message->getOriginatedConversationIdentifier()); } }
[ "public", "function", "removeStoredConversation", "(", "$", "message", "=", "null", ")", "{", "/*\n * Only remove it from the cache if it was not modified\n * after we loaded the data from the cache.\n */", "if", "(", "$", "this", "->", "getStoredConversation", "(", "$", "message", ")", "[", "'time'", "]", "==", "$", "this", "->", "currentConversationData", "[", "'time'", "]", ")", "{", "$", "this", "->", "cache", "->", "pull", "(", "$", "this", "->", "message", "->", "getConversationIdentifier", "(", ")", ")", ";", "$", "this", "->", "cache", "->", "pull", "(", "$", "this", "->", "message", "->", "getOriginatedConversationIdentifier", "(", ")", ")", ";", "}", "}" ]
Remove a stored conversation array from the cache for a given message. @param null|IncomingMessage $message
[ "Remove", "a", "stored", "conversation", "array", "from", "the", "cache", "for", "a", "given", "message", "." ]
ac9ecf78d25f8e5703125efb2be8b5898f67cd54
https://github.com/botman/botman/blob/ac9ecf78d25f8e5703125efb2be8b5898f67cd54/src/Traits/HandlesConversations.php#L104-L114
train
botman/botman
src/Traits/HandlesExceptions.php
HandlesExceptions.exception
public function exception(string $exception, $closure) { $this->exceptionHandler->register($exception, $this->getCallable($closure)); }
php
public function exception(string $exception, $closure) { $this->exceptionHandler->register($exception, $this->getCallable($closure)); }
[ "public", "function", "exception", "(", "string", "$", "exception", ",", "$", "closure", ")", "{", "$", "this", "->", "exceptionHandler", "->", "register", "(", "$", "exception", ",", "$", "this", "->", "getCallable", "(", "$", "closure", ")", ")", ";", "}" ]
Register a custom exception handler. @param string $exception @param callable $closure
[ "Register", "a", "custom", "exception", "handler", "." ]
ac9ecf78d25f8e5703125efb2be8b5898f67cd54
https://github.com/botman/botman/blob/ac9ecf78d25f8e5703125efb2be8b5898f67cd54/src/Traits/HandlesExceptions.php#L15-L18
train
botman/botman
src/Http/Curl.php
Curl.get
public function get($url, array $urlParameters = [], array $headers = [], $asJSON = false) { $request = $this->prepareRequest($url, $urlParameters, $headers); return $this->executeRequest($request); }
php
public function get($url, array $urlParameters = [], array $headers = [], $asJSON = false) { $request = $this->prepareRequest($url, $urlParameters, $headers); return $this->executeRequest($request); }
[ "public", "function", "get", "(", "$", "url", ",", "array", "$", "urlParameters", "=", "[", "]", ",", "array", "$", "headers", "=", "[", "]", ",", "$", "asJSON", "=", "false", ")", "{", "$", "request", "=", "$", "this", "->", "prepareRequest", "(", "$", "url", ",", "$", "urlParameters", ",", "$", "headers", ")", ";", "return", "$", "this", "->", "executeRequest", "(", "$", "request", ")", ";", "}" ]
Send a get request to a URL. @param string $url @param array $urlParameters @param array $headers @param bool $asJSON @return Response
[ "Send", "a", "get", "request", "to", "a", "URL", "." ]
ac9ecf78d25f8e5703125efb2be8b5898f67cd54
https://github.com/botman/botman/blob/ac9ecf78d25f8e5703125efb2be8b5898f67cd54/src/Http/Curl.php#L41-L46
train
botman/botman
src/Http/Curl.php
Curl.prepareRequest
protected static function prepareRequest($url, $parameters = [], $headers = []) { $request = curl_init(); if ($query = http_build_query($parameters)) { $url .= '?'.$query; } curl_setopt($request, CURLOPT_URL, $url); curl_setopt($request, CURLOPT_RETURNTRANSFER, true); curl_setopt($request, CURLOPT_HTTPHEADER, $headers); curl_setopt($request, CURLINFO_HEADER_OUT, true); curl_setopt($request, CURLOPT_SSL_VERIFYPEER, true); return $request; }
php
protected static function prepareRequest($url, $parameters = [], $headers = []) { $request = curl_init(); if ($query = http_build_query($parameters)) { $url .= '?'.$query; } curl_setopt($request, CURLOPT_URL, $url); curl_setopt($request, CURLOPT_RETURNTRANSFER, true); curl_setopt($request, CURLOPT_HTTPHEADER, $headers); curl_setopt($request, CURLINFO_HEADER_OUT, true); curl_setopt($request, CURLOPT_SSL_VERIFYPEER, true); return $request; }
[ "protected", "static", "function", "prepareRequest", "(", "$", "url", ",", "$", "parameters", "=", "[", "]", ",", "$", "headers", "=", "[", "]", ")", "{", "$", "request", "=", "curl_init", "(", ")", ";", "if", "(", "$", "query", "=", "http_build_query", "(", "$", "parameters", ")", ")", "{", "$", "url", ".=", "'?'", ".", "$", "query", ";", "}", "curl_setopt", "(", "$", "request", ",", "CURLOPT_URL", ",", "$", "url", ")", ";", "curl_setopt", "(", "$", "request", ",", "CURLOPT_RETURNTRANSFER", ",", "true", ")", ";", "curl_setopt", "(", "$", "request", ",", "CURLOPT_HTTPHEADER", ",", "$", "headers", ")", ";", "curl_setopt", "(", "$", "request", ",", "CURLINFO_HEADER_OUT", ",", "true", ")", ";", "curl_setopt", "(", "$", "request", ",", "CURLOPT_SSL_VERIFYPEER", ",", "true", ")", ";", "return", "$", "request", ";", "}" ]
Prepares a request using curl. @param string $url [description] @param array $parameters [description] @param array $headers [description] @return resource
[ "Prepares", "a", "request", "using", "curl", "." ]
ac9ecf78d25f8e5703125efb2be8b5898f67cd54
https://github.com/botman/botman/blob/ac9ecf78d25f8e5703125efb2be8b5898f67cd54/src/Http/Curl.php#L56-L71
train
botman/botman
src/Http/Curl.php
Curl.executeRequest
public function executeRequest($request) { $body = curl_exec($request); $info = curl_getinfo($request); curl_close($request); $statusCode = $info['http_code'] === 0 ? 500 : $info['http_code']; return new Response((string) $body, $statusCode, []); }
php
public function executeRequest($request) { $body = curl_exec($request); $info = curl_getinfo($request); curl_close($request); $statusCode = $info['http_code'] === 0 ? 500 : $info['http_code']; return new Response((string) $body, $statusCode, []); }
[ "public", "function", "executeRequest", "(", "$", "request", ")", "{", "$", "body", "=", "curl_exec", "(", "$", "request", ")", ";", "$", "info", "=", "curl_getinfo", "(", "$", "request", ")", ";", "curl_close", "(", "$", "request", ")", ";", "$", "statusCode", "=", "$", "info", "[", "'http_code'", "]", "===", "0", "?", "500", ":", "$", "info", "[", "'http_code'", "]", ";", "return", "new", "Response", "(", "(", "string", ")", "$", "body", ",", "$", "statusCode", ",", "[", "]", ")", ";", "}" ]
Executes a curl request. @param resource $request @return Response
[ "Executes", "a", "curl", "request", "." ]
ac9ecf78d25f8e5703125efb2be8b5898f67cd54
https://github.com/botman/botman/blob/ac9ecf78d25f8e5703125efb2be8b5898f67cd54/src/Http/Curl.php#L79-L89
train
botman/botman
src/Commands/Command.php
Command.applyGroupAttributes
public function applyGroupAttributes(array $attributes) { if (isset($attributes['middleware'])) { $this->middleware($attributes['middleware']); } if (isset($attributes['driver'])) { $this->driver($attributes['driver']); } if (isset($attributes['recipient'])) { $this->recipient($attributes['recipient']); } if (isset($attributes['stop_conversation']) && $attributes['stop_conversation'] === true) { $this->stopsConversation(); } if (isset($attributes['skip_conversation']) && $attributes['skip_conversation'] === true) { $this->skipsConversation(); } }
php
public function applyGroupAttributes(array $attributes) { if (isset($attributes['middleware'])) { $this->middleware($attributes['middleware']); } if (isset($attributes['driver'])) { $this->driver($attributes['driver']); } if (isset($attributes['recipient'])) { $this->recipient($attributes['recipient']); } if (isset($attributes['stop_conversation']) && $attributes['stop_conversation'] === true) { $this->stopsConversation(); } if (isset($attributes['skip_conversation']) && $attributes['skip_conversation'] === true) { $this->skipsConversation(); } }
[ "public", "function", "applyGroupAttributes", "(", "array", "$", "attributes", ")", "{", "if", "(", "isset", "(", "$", "attributes", "[", "'middleware'", "]", ")", ")", "{", "$", "this", "->", "middleware", "(", "$", "attributes", "[", "'middleware'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "attributes", "[", "'driver'", "]", ")", ")", "{", "$", "this", "->", "driver", "(", "$", "attributes", "[", "'driver'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "attributes", "[", "'recipient'", "]", ")", ")", "{", "$", "this", "->", "recipient", "(", "$", "attributes", "[", "'recipient'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "attributes", "[", "'stop_conversation'", "]", ")", "&&", "$", "attributes", "[", "'stop_conversation'", "]", "===", "true", ")", "{", "$", "this", "->", "stopsConversation", "(", ")", ";", "}", "if", "(", "isset", "(", "$", "attributes", "[", "'skip_conversation'", "]", ")", "&&", "$", "attributes", "[", "'skip_conversation'", "]", "===", "true", ")", "{", "$", "this", "->", "skipsConversation", "(", ")", ";", "}", "}" ]
Apply possible group attributes. @param array $attributes
[ "Apply", "possible", "group", "attributes", "." ]
ac9ecf78d25f8e5703125efb2be8b5898f67cd54
https://github.com/botman/botman/blob/ac9ecf78d25f8e5703125efb2be8b5898f67cd54/src/Commands/Command.php#L58-L79
train
mnapoli/bref
src/Runtime/PhpFpm.php
PhpFpm.start
public function start(): void { // In case Lambda stopped our process (e.g. because of a timeout) we need to make sure PHP-FPM has stopped // as well and restart it if ($this->isReady()) { $this->killExistingFpm(); } if (! is_dir(dirname(self::SOCKET))) { mkdir(dirname(self::SOCKET)); } /** * --nodaemonize: we want to keep control of the process * --force-stderr: force logs to be sent to stderr, which will allow us to send them to CloudWatch */ $this->fpm = new Process(['php-fpm', '--nodaemonize', '--force-stderr', '--fpm-config', $this->configFile]); $this->fpm->setTimeout(null); $this->fpm->start(function ($type, $output): void { // Send any PHP-FPM log to CloudWatch echo $output; }); $connection = new UnixDomainSocket(self::SOCKET, 1000, 30000); $this->client = new Client($connection); $this->waitUntilReady(); }
php
public function start(): void { // In case Lambda stopped our process (e.g. because of a timeout) we need to make sure PHP-FPM has stopped // as well and restart it if ($this->isReady()) { $this->killExistingFpm(); } if (! is_dir(dirname(self::SOCKET))) { mkdir(dirname(self::SOCKET)); } /** * --nodaemonize: we want to keep control of the process * --force-stderr: force logs to be sent to stderr, which will allow us to send them to CloudWatch */ $this->fpm = new Process(['php-fpm', '--nodaemonize', '--force-stderr', '--fpm-config', $this->configFile]); $this->fpm->setTimeout(null); $this->fpm->start(function ($type, $output): void { // Send any PHP-FPM log to CloudWatch echo $output; }); $connection = new UnixDomainSocket(self::SOCKET, 1000, 30000); $this->client = new Client($connection); $this->waitUntilReady(); }
[ "public", "function", "start", "(", ")", ":", "void", "{", "// In case Lambda stopped our process (e.g. because of a timeout) we need to make sure PHP-FPM has stopped", "// as well and restart it", "if", "(", "$", "this", "->", "isReady", "(", ")", ")", "{", "$", "this", "->", "killExistingFpm", "(", ")", ";", "}", "if", "(", "!", "is_dir", "(", "dirname", "(", "self", "::", "SOCKET", ")", ")", ")", "{", "mkdir", "(", "dirname", "(", "self", "::", "SOCKET", ")", ")", ";", "}", "/**\n * --nodaemonize: we want to keep control of the process\n * --force-stderr: force logs to be sent to stderr, which will allow us to send them to CloudWatch\n */", "$", "this", "->", "fpm", "=", "new", "Process", "(", "[", "'php-fpm'", ",", "'--nodaemonize'", ",", "'--force-stderr'", ",", "'--fpm-config'", ",", "$", "this", "->", "configFile", "]", ")", ";", "$", "this", "->", "fpm", "->", "setTimeout", "(", "null", ")", ";", "$", "this", "->", "fpm", "->", "start", "(", "function", "(", "$", "type", ",", "$", "output", ")", ":", "void", "{", "// Send any PHP-FPM log to CloudWatch", "echo", "$", "output", ";", "}", ")", ";", "$", "connection", "=", "new", "UnixDomainSocket", "(", "self", "::", "SOCKET", ",", "1000", ",", "30000", ")", ";", "$", "this", "->", "client", "=", "new", "Client", "(", "$", "connection", ")", ";", "$", "this", "->", "waitUntilReady", "(", ")", ";", "}" ]
Start the PHP-FPM process.
[ "Start", "the", "PHP", "-", "FPM", "process", "." ]
5987c3a9a1b3127dc4d88b541172fcf481da880b
https://github.com/mnapoli/bref/blob/5987c3a9a1b3127dc4d88b541172fcf481da880b/src/Runtime/PhpFpm.php#L49-L76
train
mnapoli/bref
src/Runtime/PhpFpm.php
PhpFpm.proxy
public function proxy($event): LambdaResponse { if (! isset($event['httpMethod'])) { throw new \Exception('The lambda was not invoked via HTTP through API Gateway: this is not supported by this runtime'); } $request = $this->eventToFastCgiRequest($event); try { $response = $this->client->sendRequest($request); } catch (\Throwable $e) { throw new FastCgiCommunicationFailed(sprintf( 'Error communicating with PHP-FPM to read the HTTP response. A root cause of this can be that the Lambda (or PHP) timed out, for example when trying to connect to a remote API or database, if this happens continuously check for those! Original exception message: %s %s', get_class($e), $e->getMessage() ), 0, $e); } $responseHeaders = $response->getHeaders(); $responseHeaders = array_change_key_case($responseHeaders, CASE_LOWER); // Extract the status code if (isset($responseHeaders['status'])) { [$status] = explode(' ', $responseHeaders['status']); } else { $status = 200; } unset($responseHeaders['status']); return new LambdaResponse((int) $status, $responseHeaders, $response->getBody()); }
php
public function proxy($event): LambdaResponse { if (! isset($event['httpMethod'])) { throw new \Exception('The lambda was not invoked via HTTP through API Gateway: this is not supported by this runtime'); } $request = $this->eventToFastCgiRequest($event); try { $response = $this->client->sendRequest($request); } catch (\Throwable $e) { throw new FastCgiCommunicationFailed(sprintf( 'Error communicating with PHP-FPM to read the HTTP response. A root cause of this can be that the Lambda (or PHP) timed out, for example when trying to connect to a remote API or database, if this happens continuously check for those! Original exception message: %s %s', get_class($e), $e->getMessage() ), 0, $e); } $responseHeaders = $response->getHeaders(); $responseHeaders = array_change_key_case($responseHeaders, CASE_LOWER); // Extract the status code if (isset($responseHeaders['status'])) { [$status] = explode(' ', $responseHeaders['status']); } else { $status = 200; } unset($responseHeaders['status']); return new LambdaResponse((int) $status, $responseHeaders, $response->getBody()); }
[ "public", "function", "proxy", "(", "$", "event", ")", ":", "LambdaResponse", "{", "if", "(", "!", "isset", "(", "$", "event", "[", "'httpMethod'", "]", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'The lambda was not invoked via HTTP through API Gateway: this is not supported by this runtime'", ")", ";", "}", "$", "request", "=", "$", "this", "->", "eventToFastCgiRequest", "(", "$", "event", ")", ";", "try", "{", "$", "response", "=", "$", "this", "->", "client", "->", "sendRequest", "(", "$", "request", ")", ";", "}", "catch", "(", "\\", "Throwable", "$", "e", ")", "{", "throw", "new", "FastCgiCommunicationFailed", "(", "sprintf", "(", "'Error communicating with PHP-FPM to read the HTTP response. A root cause of this can be that the Lambda (or PHP) timed out, for example when trying to connect to a remote API or database, if this happens continuously check for those! Original exception message: %s %s'", ",", "get_class", "(", "$", "e", ")", ",", "$", "e", "->", "getMessage", "(", ")", ")", ",", "0", ",", "$", "e", ")", ";", "}", "$", "responseHeaders", "=", "$", "response", "->", "getHeaders", "(", ")", ";", "$", "responseHeaders", "=", "array_change_key_case", "(", "$", "responseHeaders", ",", "CASE_LOWER", ")", ";", "// Extract the status code", "if", "(", "isset", "(", "$", "responseHeaders", "[", "'status'", "]", ")", ")", "{", "[", "$", "status", "]", "=", "explode", "(", "' '", ",", "$", "responseHeaders", "[", "'status'", "]", ")", ";", "}", "else", "{", "$", "status", "=", "200", ";", "}", "unset", "(", "$", "responseHeaders", "[", "'status'", "]", ")", ";", "return", "new", "LambdaResponse", "(", "(", "int", ")", "$", "status", ",", "$", "responseHeaders", ",", "$", "response", "->", "getBody", "(", ")", ")", ";", "}" ]
Proxy the API Gateway event to PHP-FPM and return its response. @param mixed $event
[ "Proxy", "the", "API", "Gateway", "event", "to", "PHP", "-", "FPM", "and", "return", "its", "response", "." ]
5987c3a9a1b3127dc4d88b541172fcf481da880b
https://github.com/mnapoli/bref/blob/5987c3a9a1b3127dc4d88b541172fcf481da880b/src/Runtime/PhpFpm.php#L108-L138
train
mnapoli/bref
src/Runtime/PhpFpm.php
PhpFpm.killExistingFpm
private function killExistingFpm(): void { // Never seen this happen but just in case if (! file_exists(self::PID_FILE)) { unlink(self::SOCKET); return; } $pid = (int) file_get_contents(self::PID_FILE); // Never seen this happen but just in case if ($pid <= 0) { echo "PHP-FPM's PID file contained an invalid PID, assuming PHP-FPM isn't running.\n"; unlink(self::SOCKET); unlink(self::PID_FILE); return; } // Check if the process is running if (posix_getpgid($pid) === false) { // PHP-FPM is not running anymore, we can cleanup unlink(self::SOCKET); unlink(self::PID_FILE); return; } echo "PHP-FPM seems to be running already, this might be because Lambda stopped the bootstrap process but didn't leave us an opportunity to stop PHP-FPM. Stopping PHP-FPM now to restart from a blank slate.\n"; // PHP-FPM is running, let's try to kill it properly $result = posix_kill($pid, SIGTERM); if ($result === false) { echo "PHP-FPM's PID file contained a PID that doesn't exist, assuming PHP-FPM isn't running.\n"; unlink(self::SOCKET); unlink(self::PID_FILE); return; } $this->waitUntilStopped($pid); unlink(self::SOCKET); unlink(self::PID_FILE); }
php
private function killExistingFpm(): void { // Never seen this happen but just in case if (! file_exists(self::PID_FILE)) { unlink(self::SOCKET); return; } $pid = (int) file_get_contents(self::PID_FILE); // Never seen this happen but just in case if ($pid <= 0) { echo "PHP-FPM's PID file contained an invalid PID, assuming PHP-FPM isn't running.\n"; unlink(self::SOCKET); unlink(self::PID_FILE); return; } // Check if the process is running if (posix_getpgid($pid) === false) { // PHP-FPM is not running anymore, we can cleanup unlink(self::SOCKET); unlink(self::PID_FILE); return; } echo "PHP-FPM seems to be running already, this might be because Lambda stopped the bootstrap process but didn't leave us an opportunity to stop PHP-FPM. Stopping PHP-FPM now to restart from a blank slate.\n"; // PHP-FPM is running, let's try to kill it properly $result = posix_kill($pid, SIGTERM); if ($result === false) { echo "PHP-FPM's PID file contained a PID that doesn't exist, assuming PHP-FPM isn't running.\n"; unlink(self::SOCKET); unlink(self::PID_FILE); return; } $this->waitUntilStopped($pid); unlink(self::SOCKET); unlink(self::PID_FILE); }
[ "private", "function", "killExistingFpm", "(", ")", ":", "void", "{", "// Never seen this happen but just in case", "if", "(", "!", "file_exists", "(", "self", "::", "PID_FILE", ")", ")", "{", "unlink", "(", "self", "::", "SOCKET", ")", ";", "return", ";", "}", "$", "pid", "=", "(", "int", ")", "file_get_contents", "(", "self", "::", "PID_FILE", ")", ";", "// Never seen this happen but just in case", "if", "(", "$", "pid", "<=", "0", ")", "{", "echo", "\"PHP-FPM's PID file contained an invalid PID, assuming PHP-FPM isn't running.\\n\"", ";", "unlink", "(", "self", "::", "SOCKET", ")", ";", "unlink", "(", "self", "::", "PID_FILE", ")", ";", "return", ";", "}", "// Check if the process is running", "if", "(", "posix_getpgid", "(", "$", "pid", ")", "===", "false", ")", "{", "// PHP-FPM is not running anymore, we can cleanup", "unlink", "(", "self", "::", "SOCKET", ")", ";", "unlink", "(", "self", "::", "PID_FILE", ")", ";", "return", ";", "}", "echo", "\"PHP-FPM seems to be running already, this might be because Lambda stopped the bootstrap process but didn't leave us an opportunity to stop PHP-FPM. Stopping PHP-FPM now to restart from a blank slate.\\n\"", ";", "// PHP-FPM is running, let's try to kill it properly", "$", "result", "=", "posix_kill", "(", "$", "pid", ",", "SIGTERM", ")", ";", "if", "(", "$", "result", "===", "false", ")", "{", "echo", "\"PHP-FPM's PID file contained a PID that doesn't exist, assuming PHP-FPM isn't running.\\n\"", ";", "unlink", "(", "self", "::", "SOCKET", ")", ";", "unlink", "(", "self", "::", "PID_FILE", ")", ";", "return", ";", "}", "$", "this", "->", "waitUntilStopped", "(", "$", "pid", ")", ";", "unlink", "(", "self", "::", "SOCKET", ")", ";", "unlink", "(", "self", "::", "PID_FILE", ")", ";", "}" ]
This methods makes sure to kill any existing PHP-FPM process.
[ "This", "methods", "makes", "sure", "to", "kill", "any", "existing", "PHP", "-", "FPM", "process", "." ]
5987c3a9a1b3127dc4d88b541172fcf481da880b
https://github.com/mnapoli/bref/blob/5987c3a9a1b3127dc4d88b541172fcf481da880b/src/Runtime/PhpFpm.php#L236-L276
train
mnapoli/bref
src/Runtime/PhpFpm.php
PhpFpm.waitUntilStopped
private function waitUntilStopped(int $pid): void { $wait = 5000; // 5ms $timeout = 1000000; // 1 sec $elapsed = 0; while (posix_getpgid($pid) !== false) { usleep($wait); $elapsed += $wait; if ($elapsed > $timeout) { throw new \Exception('Timeout while waiting for PHP-FPM to stop'); } } }
php
private function waitUntilStopped(int $pid): void { $wait = 5000; // 5ms $timeout = 1000000; // 1 sec $elapsed = 0; while (posix_getpgid($pid) !== false) { usleep($wait); $elapsed += $wait; if ($elapsed > $timeout) { throw new \Exception('Timeout while waiting for PHP-FPM to stop'); } } }
[ "private", "function", "waitUntilStopped", "(", "int", "$", "pid", ")", ":", "void", "{", "$", "wait", "=", "5000", ";", "// 5ms", "$", "timeout", "=", "1000000", ";", "// 1 sec", "$", "elapsed", "=", "0", ";", "while", "(", "posix_getpgid", "(", "$", "pid", ")", "!==", "false", ")", "{", "usleep", "(", "$", "wait", ")", ";", "$", "elapsed", "+=", "$", "wait", ";", "if", "(", "$", "elapsed", ">", "$", "timeout", ")", "{", "throw", "new", "\\", "Exception", "(", "'Timeout while waiting for PHP-FPM to stop'", ")", ";", "}", "}", "}" ]
Wait until PHP-FPM has stopped.
[ "Wait", "until", "PHP", "-", "FPM", "has", "stopped", "." ]
5987c3a9a1b3127dc4d88b541172fcf481da880b
https://github.com/mnapoli/bref/blob/5987c3a9a1b3127dc4d88b541172fcf481da880b/src/Runtime/PhpFpm.php#L281-L293
train
mnapoli/bref
src/Runtime/LambdaRuntime.php
LambdaRuntime.processNextEvent
public function processNextEvent(callable $handler): void { /** @var Context $context */ [$event, $context] = $this->waitNextInvocation(); try { $this->sendResponse($context->getAwsRequestId(), $handler($event, $context)); } catch (\Throwable $e) { $this->signalFailure($context->getAwsRequestId(), $e); } }
php
public function processNextEvent(callable $handler): void { /** @var Context $context */ [$event, $context] = $this->waitNextInvocation(); try { $this->sendResponse($context->getAwsRequestId(), $handler($event, $context)); } catch (\Throwable $e) { $this->signalFailure($context->getAwsRequestId(), $e); } }
[ "public", "function", "processNextEvent", "(", "callable", "$", "handler", ")", ":", "void", "{", "/** @var Context $context */", "[", "$", "event", ",", "$", "context", "]", "=", "$", "this", "->", "waitNextInvocation", "(", ")", ";", "try", "{", "$", "this", "->", "sendResponse", "(", "$", "context", "->", "getAwsRequestId", "(", ")", ",", "$", "handler", "(", "$", "event", ",", "$", "context", ")", ")", ";", "}", "catch", "(", "\\", "Throwable", "$", "e", ")", "{", "$", "this", "->", "signalFailure", "(", "$", "context", "->", "getAwsRequestId", "(", ")", ",", "$", "e", ")", ";", "}", "}" ]
Process the next event. @param callable $handler This callable takes two parameters, an $event parameter (array) and a $context parameter (Context) and must return anything serializable to JSON. Example: $lambdaRuntime->processNextEvent(function (array $event, Context $context) { return 'Hello ' . $event['name'] . '. We have ' . $context->getRemainingTimeInMillis()/1000 . ' seconds left'; }); @throws \Exception
[ "Process", "the", "next", "event", "." ]
5987c3a9a1b3127dc4d88b541172fcf481da880b
https://github.com/mnapoli/bref/blob/5987c3a9a1b3127dc4d88b541172fcf481da880b/src/Runtime/LambdaRuntime.php#L84-L94
train
mnapoli/bref
src/Runtime/LambdaRuntime.php
LambdaRuntime.waitNextInvocation
private function waitNextInvocation(): array { if ($this->handler === null) { $this->handler = curl_init("http://{$this->apiUrl}/2018-06-01/runtime/invocation/next"); curl_setopt($this->handler, CURLOPT_FOLLOWLOCATION, true); curl_setopt($this->handler, CURLOPT_FAILONERROR, true); } // Retrieve invocation ID $contextBuilder = new ContextBuilder; curl_setopt($this->handler, CURLOPT_HEADERFUNCTION, function ($ch, $header) use ($contextBuilder) { if (! preg_match('/:\s*/', $header)) { return strlen($header); } [$name, $value] = preg_split('/:\s*/', $header, 2); $name = strtolower($name); $value = trim($value); if ($name === 'lambda-runtime-aws-request-id') { $contextBuilder->setAwsRequestId($value); } if ($name === 'lambda-runtime-deadline-ms') { $contextBuilder->setDeadlineMs(intval($value)); } if ($name === 'lambda-runtime-invoked-function-arn') { $contextBuilder->setInvokedFunctionArn($value); } if ($name === 'lambda-runtime-trace-id') { $contextBuilder->setTraceId($value); } return strlen($header); }); // Retrieve body $body = ''; curl_setopt($this->handler, CURLOPT_WRITEFUNCTION, function ($ch, $chunk) use (&$body) { $body .= $chunk; return strlen($chunk); }); curl_exec($this->handler); if (curl_errno($this->handler) > 0) { $message = curl_error($this->handler); $this->closeHandler(); throw new \Exception('Failed to fetch next Lambda invocation: ' . $message); } if ($body === '') { throw new \Exception('Empty Lambda runtime API response'); } $context = $contextBuilder->buildContext(); if ($context->getAwsRequestId() === '') { throw new \Exception('Failed to determine the Lambda invocation ID'); } $event = json_decode($body, true); return [$event, $context]; }
php
private function waitNextInvocation(): array { if ($this->handler === null) { $this->handler = curl_init("http://{$this->apiUrl}/2018-06-01/runtime/invocation/next"); curl_setopt($this->handler, CURLOPT_FOLLOWLOCATION, true); curl_setopt($this->handler, CURLOPT_FAILONERROR, true); } // Retrieve invocation ID $contextBuilder = new ContextBuilder; curl_setopt($this->handler, CURLOPT_HEADERFUNCTION, function ($ch, $header) use ($contextBuilder) { if (! preg_match('/:\s*/', $header)) { return strlen($header); } [$name, $value] = preg_split('/:\s*/', $header, 2); $name = strtolower($name); $value = trim($value); if ($name === 'lambda-runtime-aws-request-id') { $contextBuilder->setAwsRequestId($value); } if ($name === 'lambda-runtime-deadline-ms') { $contextBuilder->setDeadlineMs(intval($value)); } if ($name === 'lambda-runtime-invoked-function-arn') { $contextBuilder->setInvokedFunctionArn($value); } if ($name === 'lambda-runtime-trace-id') { $contextBuilder->setTraceId($value); } return strlen($header); }); // Retrieve body $body = ''; curl_setopt($this->handler, CURLOPT_WRITEFUNCTION, function ($ch, $chunk) use (&$body) { $body .= $chunk; return strlen($chunk); }); curl_exec($this->handler); if (curl_errno($this->handler) > 0) { $message = curl_error($this->handler); $this->closeHandler(); throw new \Exception('Failed to fetch next Lambda invocation: ' . $message); } if ($body === '') { throw new \Exception('Empty Lambda runtime API response'); } $context = $contextBuilder->buildContext(); if ($context->getAwsRequestId() === '') { throw new \Exception('Failed to determine the Lambda invocation ID'); } $event = json_decode($body, true); return [$event, $context]; }
[ "private", "function", "waitNextInvocation", "(", ")", ":", "array", "{", "if", "(", "$", "this", "->", "handler", "===", "null", ")", "{", "$", "this", "->", "handler", "=", "curl_init", "(", "\"http://{$this->apiUrl}/2018-06-01/runtime/invocation/next\"", ")", ";", "curl_setopt", "(", "$", "this", "->", "handler", ",", "CURLOPT_FOLLOWLOCATION", ",", "true", ")", ";", "curl_setopt", "(", "$", "this", "->", "handler", ",", "CURLOPT_FAILONERROR", ",", "true", ")", ";", "}", "// Retrieve invocation ID", "$", "contextBuilder", "=", "new", "ContextBuilder", ";", "curl_setopt", "(", "$", "this", "->", "handler", ",", "CURLOPT_HEADERFUNCTION", ",", "function", "(", "$", "ch", ",", "$", "header", ")", "use", "(", "$", "contextBuilder", ")", "{", "if", "(", "!", "preg_match", "(", "'/:\\s*/'", ",", "$", "header", ")", ")", "{", "return", "strlen", "(", "$", "header", ")", ";", "}", "[", "$", "name", ",", "$", "value", "]", "=", "preg_split", "(", "'/:\\s*/'", ",", "$", "header", ",", "2", ")", ";", "$", "name", "=", "strtolower", "(", "$", "name", ")", ";", "$", "value", "=", "trim", "(", "$", "value", ")", ";", "if", "(", "$", "name", "===", "'lambda-runtime-aws-request-id'", ")", "{", "$", "contextBuilder", "->", "setAwsRequestId", "(", "$", "value", ")", ";", "}", "if", "(", "$", "name", "===", "'lambda-runtime-deadline-ms'", ")", "{", "$", "contextBuilder", "->", "setDeadlineMs", "(", "intval", "(", "$", "value", ")", ")", ";", "}", "if", "(", "$", "name", "===", "'lambda-runtime-invoked-function-arn'", ")", "{", "$", "contextBuilder", "->", "setInvokedFunctionArn", "(", "$", "value", ")", ";", "}", "if", "(", "$", "name", "===", "'lambda-runtime-trace-id'", ")", "{", "$", "contextBuilder", "->", "setTraceId", "(", "$", "value", ")", ";", "}", "return", "strlen", "(", "$", "header", ")", ";", "}", ")", ";", "// Retrieve body", "$", "body", "=", "''", ";", "curl_setopt", "(", "$", "this", "->", "handler", ",", "CURLOPT_WRITEFUNCTION", ",", "function", "(", "$", "ch", ",", "$", "chunk", ")", "use", "(", "&", "$", "body", ")", "{", "$", "body", ".=", "$", "chunk", ";", "return", "strlen", "(", "$", "chunk", ")", ";", "}", ")", ";", "curl_exec", "(", "$", "this", "->", "handler", ")", ";", "if", "(", "curl_errno", "(", "$", "this", "->", "handler", ")", ">", "0", ")", "{", "$", "message", "=", "curl_error", "(", "$", "this", "->", "handler", ")", ";", "$", "this", "->", "closeHandler", "(", ")", ";", "throw", "new", "\\", "Exception", "(", "'Failed to fetch next Lambda invocation: '", ".", "$", "message", ")", ";", "}", "if", "(", "$", "body", "===", "''", ")", "{", "throw", "new", "\\", "Exception", "(", "'Empty Lambda runtime API response'", ")", ";", "}", "$", "context", "=", "$", "contextBuilder", "->", "buildContext", "(", ")", ";", "if", "(", "$", "context", "->", "getAwsRequestId", "(", ")", "===", "''", ")", "{", "throw", "new", "\\", "Exception", "(", "'Failed to determine the Lambda invocation ID'", ")", ";", "}", "$", "event", "=", "json_decode", "(", "$", "body", ",", "true", ")", ";", "return", "[", "$", "event", ",", "$", "context", "]", ";", "}" ]
Wait for the next lambda invocation and retrieve its data. This call is blocking because the Lambda runtime API is blocking. @see https://docs.aws.amazon.com/lambda/latest/dg/runtimes-api.html#runtimes-api-next
[ "Wait", "for", "the", "next", "lambda", "invocation", "and", "retrieve", "its", "data", "." ]
5987c3a9a1b3127dc4d88b541172fcf481da880b
https://github.com/mnapoli/bref/blob/5987c3a9a1b3127dc4d88b541172fcf481da880b/src/Runtime/LambdaRuntime.php#L103-L163
train
mnapoli/bref
src/Runtime/LambdaRuntime.php
LambdaRuntime.failInitialization
public function failInitialization(string $message, ?\Throwable $error = null): void { // Log the exception in CloudWatch echo "$message\n"; if ($error) { if ($error instanceof \Exception) { $errorMessage = get_class($error) . ': ' . $error->getMessage(); } else { $errorMessage = $error->getMessage(); } printf( "Fatal error: %s in %s:%d\nStack trace:\n%s", $errorMessage, $error->getFile(), $error->getLine(), $error->getTraceAsString() ); } $url = "http://{$this->apiUrl}/2018-06-01/runtime/init/error"; $this->postJson($url, [ 'errorMessage' => $message . ' ' . ($error ? $error->getMessage() : ''), 'errorType' => $error ? get_class($error) : 'Internal', 'stackTrace' => $error ? explode(PHP_EOL, $error->getTraceAsString()) : [], ]); exit(1); }
php
public function failInitialization(string $message, ?\Throwable $error = null): void { // Log the exception in CloudWatch echo "$message\n"; if ($error) { if ($error instanceof \Exception) { $errorMessage = get_class($error) . ': ' . $error->getMessage(); } else { $errorMessage = $error->getMessage(); } printf( "Fatal error: %s in %s:%d\nStack trace:\n%s", $errorMessage, $error->getFile(), $error->getLine(), $error->getTraceAsString() ); } $url = "http://{$this->apiUrl}/2018-06-01/runtime/init/error"; $this->postJson($url, [ 'errorMessage' => $message . ' ' . ($error ? $error->getMessage() : ''), 'errorType' => $error ? get_class($error) : 'Internal', 'stackTrace' => $error ? explode(PHP_EOL, $error->getTraceAsString()) : [], ]); exit(1); }
[ "public", "function", "failInitialization", "(", "string", "$", "message", ",", "?", "\\", "Throwable", "$", "error", "=", "null", ")", ":", "void", "{", "// Log the exception in CloudWatch", "echo", "\"$message\\n\"", ";", "if", "(", "$", "error", ")", "{", "if", "(", "$", "error", "instanceof", "\\", "Exception", ")", "{", "$", "errorMessage", "=", "get_class", "(", "$", "error", ")", ".", "': '", ".", "$", "error", "->", "getMessage", "(", ")", ";", "}", "else", "{", "$", "errorMessage", "=", "$", "error", "->", "getMessage", "(", ")", ";", "}", "printf", "(", "\"Fatal error: %s in %s:%d\\nStack trace:\\n%s\"", ",", "$", "errorMessage", ",", "$", "error", "->", "getFile", "(", ")", ",", "$", "error", "->", "getLine", "(", ")", ",", "$", "error", "->", "getTraceAsString", "(", ")", ")", ";", "}", "$", "url", "=", "\"http://{$this->apiUrl}/2018-06-01/runtime/init/error\"", ";", "$", "this", "->", "postJson", "(", "$", "url", ",", "[", "'errorMessage'", "=>", "$", "message", ".", "' '", ".", "(", "$", "error", "?", "$", "error", "->", "getMessage", "(", ")", ":", "''", ")", ",", "'errorType'", "=>", "$", "error", "?", "get_class", "(", "$", "error", ")", ":", "'Internal'", ",", "'stackTrace'", "=>", "$", "error", "?", "explode", "(", "PHP_EOL", ",", "$", "error", "->", "getTraceAsString", "(", ")", ")", ":", "[", "]", ",", "]", ")", ";", "exit", "(", "1", ")", ";", "}" ]
Abort the lambda and signal to the runtime API that we failed to initialize this instance. @see https://docs.aws.amazon.com/lambda/latest/dg/runtimes-api.html#runtimes-api-initerror
[ "Abort", "the", "lambda", "and", "signal", "to", "the", "runtime", "API", "that", "we", "failed", "to", "initialize", "this", "instance", "." ]
5987c3a9a1b3127dc4d88b541172fcf481da880b
https://github.com/mnapoli/bref/blob/5987c3a9a1b3127dc4d88b541172fcf481da880b/src/Runtime/LambdaRuntime.php#L210-L237
train
mnapoli/bref
src/Lambda/SimpleLambdaClient.php
SimpleLambdaClient.invoke
public function invoke(string $functionName, $event = null): InvocationResult { $rawResult = $this->lambda->invoke([ 'FunctionName' => $functionName, 'LogType' => 'Tail', 'Payload' => $event ?? '', ]); /** @var StreamInterface $resultPayload */ $resultPayload = $rawResult->get('Payload'); $resultPayload = json_decode($resultPayload->getContents(), true); $invocationResult = new InvocationResult($rawResult, $resultPayload); $error = $rawResult->get('FunctionError'); if ($error) { throw new InvocationFailed($invocationResult); } return $invocationResult; }
php
public function invoke(string $functionName, $event = null): InvocationResult { $rawResult = $this->lambda->invoke([ 'FunctionName' => $functionName, 'LogType' => 'Tail', 'Payload' => $event ?? '', ]); /** @var StreamInterface $resultPayload */ $resultPayload = $rawResult->get('Payload'); $resultPayload = json_decode($resultPayload->getContents(), true); $invocationResult = new InvocationResult($rawResult, $resultPayload); $error = $rawResult->get('FunctionError'); if ($error) { throw new InvocationFailed($invocationResult); } return $invocationResult; }
[ "public", "function", "invoke", "(", "string", "$", "functionName", ",", "$", "event", "=", "null", ")", ":", "InvocationResult", "{", "$", "rawResult", "=", "$", "this", "->", "lambda", "->", "invoke", "(", "[", "'FunctionName'", "=>", "$", "functionName", ",", "'LogType'", "=>", "'Tail'", ",", "'Payload'", "=>", "$", "event", "??", "''", ",", "]", ")", ";", "/** @var StreamInterface $resultPayload */", "$", "resultPayload", "=", "$", "rawResult", "->", "get", "(", "'Payload'", ")", ";", "$", "resultPayload", "=", "json_decode", "(", "$", "resultPayload", "->", "getContents", "(", ")", ",", "true", ")", ";", "$", "invocationResult", "=", "new", "InvocationResult", "(", "$", "rawResult", ",", "$", "resultPayload", ")", ";", "$", "error", "=", "$", "rawResult", "->", "get", "(", "'FunctionError'", ")", ";", "if", "(", "$", "error", ")", "{", "throw", "new", "InvocationFailed", "(", "$", "invocationResult", ")", ";", "}", "return", "$", "invocationResult", ";", "}" ]
Synchronously invoke a function. @param mixed $event Event data (can be null). @throws InvocationFailed
[ "Synchronously", "invoke", "a", "function", "." ]
5987c3a9a1b3127dc4d88b541172fcf481da880b
https://github.com/mnapoli/bref/blob/5987c3a9a1b3127dc4d88b541172fcf481da880b/src/Lambda/SimpleLambdaClient.php#L30-L50
train
nWidart/laravel-modules
src/FileRepository.php
FileRepository.getCached
public function getCached() { return $this->app['cache']->remember($this->config('cache.key'), $this->config('cache.lifetime'), function () { return $this->toCollection()->toArray(); }); }
php
public function getCached() { return $this->app['cache']->remember($this->config('cache.key'), $this->config('cache.lifetime'), function () { return $this->toCollection()->toArray(); }); }
[ "public", "function", "getCached", "(", ")", "{", "return", "$", "this", "->", "app", "[", "'cache'", "]", "->", "remember", "(", "$", "this", "->", "config", "(", "'cache.key'", ")", ",", "$", "this", "->", "config", "(", "'cache.lifetime'", ")", ",", "function", "(", ")", "{", "return", "$", "this", "->", "toCollection", "(", ")", "->", "toArray", "(", ")", ";", "}", ")", ";", "}" ]
Get cached modules. @return array
[ "Get", "cached", "modules", "." ]
044b76ec322305bf65ff44f7f1754127ba5b94ad
https://github.com/nWidart/laravel-modules/blob/044b76ec322305bf65ff44f7f1754127ba5b94ad/src/FileRepository.php#L178-L183
train
nWidart/laravel-modules
src/FileRepository.php
FileRepository.find
public function find($name) { foreach ($this->all() as $module) { if ($module->getLowerName() === strtolower($name)) { return $module; } } return; }
php
public function find($name) { foreach ($this->all() as $module) { if ($module->getLowerName() === strtolower($name)) { return $module; } } return; }
[ "public", "function", "find", "(", "$", "name", ")", "{", "foreach", "(", "$", "this", "->", "all", "(", ")", "as", "$", "module", ")", "{", "if", "(", "$", "module", "->", "getLowerName", "(", ")", "===", "strtolower", "(", "$", "name", ")", ")", "{", "return", "$", "module", ";", "}", "}", "return", ";", "}" ]
Find a specific module. @param $name @return mixed|void
[ "Find", "a", "specific", "module", "." ]
044b76ec322305bf65ff44f7f1754127ba5b94ad
https://github.com/nWidart/laravel-modules/blob/044b76ec322305bf65ff44f7f1754127ba5b94ad/src/FileRepository.php#L318-L327
train
nWidart/laravel-modules
src/FileRepository.php
FileRepository.findByAlias
public function findByAlias($alias) { foreach ($this->all() as $module) { if ($module->getAlias() === $alias) { return $module; } } return; }
php
public function findByAlias($alias) { foreach ($this->all() as $module) { if ($module->getAlias() === $alias) { return $module; } } return; }
[ "public", "function", "findByAlias", "(", "$", "alias", ")", "{", "foreach", "(", "$", "this", "->", "all", "(", ")", "as", "$", "module", ")", "{", "if", "(", "$", "module", "->", "getAlias", "(", ")", "===", "$", "alias", ")", "{", "return", "$", "module", ";", "}", "}", "return", ";", "}" ]
Find a specific module by its alias. @param $alias @return mixed|void
[ "Find", "a", "specific", "module", "by", "its", "alias", "." ]
044b76ec322305bf65ff44f7f1754127ba5b94ad
https://github.com/nWidart/laravel-modules/blob/044b76ec322305bf65ff44f7f1754127ba5b94ad/src/FileRepository.php#L334-L343
train
nWidart/laravel-modules
src/FileRepository.php
FileRepository.findRequirements
public function findRequirements($name) { $requirements = []; $module = $this->findOrFail($name); foreach ($module->getRequires() as $requirementName) { $requirements[] = $this->findByAlias($requirementName); } return $requirements; }
php
public function findRequirements($name) { $requirements = []; $module = $this->findOrFail($name); foreach ($module->getRequires() as $requirementName) { $requirements[] = $this->findByAlias($requirementName); } return $requirements; }
[ "public", "function", "findRequirements", "(", "$", "name", ")", "{", "$", "requirements", "=", "[", "]", ";", "$", "module", "=", "$", "this", "->", "findOrFail", "(", "$", "name", ")", ";", "foreach", "(", "$", "module", "->", "getRequires", "(", ")", "as", "$", "requirementName", ")", "{", "$", "requirements", "[", "]", "=", "$", "this", "->", "findByAlias", "(", "$", "requirementName", ")", ";", "}", "return", "$", "requirements", ";", "}" ]
Find all modules that are required by a module. If the module cannot be found, throw an exception. @param $name @return array @throws ModuleNotFoundException
[ "Find", "all", "modules", "that", "are", "required", "by", "a", "module", ".", "If", "the", "module", "cannot", "be", "found", "throw", "an", "exception", "." ]
044b76ec322305bf65ff44f7f1754127ba5b94ad
https://github.com/nWidart/laravel-modules/blob/044b76ec322305bf65ff44f7f1754127ba5b94ad/src/FileRepository.php#L352-L363
train
nWidart/laravel-modules
src/FileRepository.php
FileRepository.findOrFail
public function findOrFail($name) { $module = $this->find($name); if ($module !== null) { return $module; } throw new ModuleNotFoundException("Module [{$name}] does not exist!"); }
php
public function findOrFail($name) { $module = $this->find($name); if ($module !== null) { return $module; } throw new ModuleNotFoundException("Module [{$name}] does not exist!"); }
[ "public", "function", "findOrFail", "(", "$", "name", ")", "{", "$", "module", "=", "$", "this", "->", "find", "(", "$", "name", ")", ";", "if", "(", "$", "module", "!==", "null", ")", "{", "return", "$", "module", ";", "}", "throw", "new", "ModuleNotFoundException", "(", "\"Module [{$name}] does not exist!\"", ")", ";", "}" ]
Find a specific module, if there return that, otherwise throw exception. @param $name @return Module @throws ModuleNotFoundException
[ "Find", "a", "specific", "module", "if", "there", "return", "that", "otherwise", "throw", "exception", "." ]
044b76ec322305bf65ff44f7f1754127ba5b94ad
https://github.com/nWidart/laravel-modules/blob/044b76ec322305bf65ff44f7f1754127ba5b94ad/src/FileRepository.php#L374-L383
train
nWidart/laravel-modules
src/FileRepository.php
FileRepository.getModulePath
public function getModulePath($module) { try { return $this->findOrFail($module)->getPath() . '/'; } catch (ModuleNotFoundException $e) { return $this->getPath() . '/' . Str::studly($module) . '/'; } }
php
public function getModulePath($module) { try { return $this->findOrFail($module)->getPath() . '/'; } catch (ModuleNotFoundException $e) { return $this->getPath() . '/' . Str::studly($module) . '/'; } }
[ "public", "function", "getModulePath", "(", "$", "module", ")", "{", "try", "{", "return", "$", "this", "->", "findOrFail", "(", "$", "module", ")", "->", "getPath", "(", ")", ".", "'/'", ";", "}", "catch", "(", "ModuleNotFoundException", "$", "e", ")", "{", "return", "$", "this", "->", "getPath", "(", ")", ".", "'/'", ".", "Str", "::", "studly", "(", "$", "module", ")", ".", "'/'", ";", "}", "}" ]
Get module path for a specific module. @param $module @return string
[ "Get", "module", "path", "for", "a", "specific", "module", "." ]
044b76ec322305bf65ff44f7f1754127ba5b94ad
https://github.com/nWidart/laravel-modules/blob/044b76ec322305bf65ff44f7f1754127ba5b94ad/src/FileRepository.php#L404-L411
train
nWidart/laravel-modules
src/FileRepository.php
FileRepository.setUsed
public function setUsed($name) { $module = $this->findOrFail($name); $this->app['files']->put($this->getUsedStoragePath(), $module); }
php
public function setUsed($name) { $module = $this->findOrFail($name); $this->app['files']->put($this->getUsedStoragePath(), $module); }
[ "public", "function", "setUsed", "(", "$", "name", ")", "{", "$", "module", "=", "$", "this", "->", "findOrFail", "(", "$", "name", ")", ";", "$", "this", "->", "app", "[", "'files'", "]", "->", "put", "(", "$", "this", "->", "getUsedStoragePath", "(", ")", ",", "$", "module", ")", ";", "}" ]
Set module used for cli session. @param $name @throws ModuleNotFoundException
[ "Set", "module", "used", "for", "cli", "session", "." ]
044b76ec322305bf65ff44f7f1754127ba5b94ad
https://github.com/nWidart/laravel-modules/blob/044b76ec322305bf65ff44f7f1754127ba5b94ad/src/FileRepository.php#L465-L470
train
nWidart/laravel-modules
src/FileRepository.php
FileRepository.forgetUsed
public function forgetUsed() { if ($this->app['files']->exists($this->getUsedStoragePath())) { $this->app['files']->delete($this->getUsedStoragePath()); } }
php
public function forgetUsed() { if ($this->app['files']->exists($this->getUsedStoragePath())) { $this->app['files']->delete($this->getUsedStoragePath()); } }
[ "public", "function", "forgetUsed", "(", ")", "{", "if", "(", "$", "this", "->", "app", "[", "'files'", "]", "->", "exists", "(", "$", "this", "->", "getUsedStoragePath", "(", ")", ")", ")", "{", "$", "this", "->", "app", "[", "'files'", "]", "->", "delete", "(", "$", "this", "->", "getUsedStoragePath", "(", ")", ")", ";", "}", "}" ]
Forget the module used for cli session.
[ "Forget", "the", "module", "used", "for", "cli", "session", "." ]
044b76ec322305bf65ff44f7f1754127ba5b94ad
https://github.com/nWidart/laravel-modules/blob/044b76ec322305bf65ff44f7f1754127ba5b94ad/src/FileRepository.php#L475-L480
train
nWidart/laravel-modules
src/FileRepository.php
FileRepository.install
public function install($name, $version = 'dev-master', $type = 'composer', $subtree = false) { $installer = new Installer($name, $version, $type, $subtree); return $installer->run(); }
php
public function install($name, $version = 'dev-master', $type = 'composer', $subtree = false) { $installer = new Installer($name, $version, $type, $subtree); return $installer->run(); }
[ "public", "function", "install", "(", "$", "name", ",", "$", "version", "=", "'dev-master'", ",", "$", "type", "=", "'composer'", ",", "$", "subtree", "=", "false", ")", "{", "$", "installer", "=", "new", "Installer", "(", "$", "name", ",", "$", "version", ",", "$", "type", ",", "$", "subtree", ")", ";", "return", "$", "installer", "->", "run", "(", ")", ";", "}" ]
Install the specified module. @param string $name @param string $version @param string $type @param bool $subtree @return \Symfony\Component\Process\Process
[ "Install", "the", "specified", "module", "." ]
044b76ec322305bf65ff44f7f1754127ba5b94ad
https://github.com/nWidart/laravel-modules/blob/044b76ec322305bf65ff44f7f1754127ba5b94ad/src/FileRepository.php#L607-L612
train
nWidart/laravel-modules
src/Process/Installer.php
Installer.run
public function run() { $process = $this->getProcess(); $process->setTimeout($this->timeout); if ($this->console instanceof Command) { $process->run(function ($type, $line) { $this->console->line($line); }); } return $process; }
php
public function run() { $process = $this->getProcess(); $process->setTimeout($this->timeout); if ($this->console instanceof Command) { $process->run(function ($type, $line) { $this->console->line($line); }); } return $process; }
[ "public", "function", "run", "(", ")", "{", "$", "process", "=", "$", "this", "->", "getProcess", "(", ")", ";", "$", "process", "->", "setTimeout", "(", "$", "this", "->", "timeout", ")", ";", "if", "(", "$", "this", "->", "console", "instanceof", "Command", ")", "{", "$", "process", "->", "run", "(", "function", "(", "$", "type", ",", "$", "line", ")", "{", "$", "this", "->", "console", "->", "line", "(", "$", "line", ")", ";", "}", ")", ";", "}", "return", "$", "process", ";", "}" ]
Run the installation process. @return \Symfony\Component\Process\Process
[ "Run", "the", "installation", "process", "." ]
044b76ec322305bf65ff44f7f1754127ba5b94ad
https://github.com/nWidart/laravel-modules/blob/044b76ec322305bf65ff44f7f1754127ba5b94ad/src/Process/Installer.php#L136-L149
train
nWidart/laravel-modules
src/Process/Installer.php
Installer.getRepoUrl
public function getRepoUrl() { switch ($this->type) { case 'github': return "git@github.com:{$this->name}.git"; case 'github-https': return "https://github.com/{$this->name}.git"; case 'gitlab': return "git@gitlab.com:{$this->name}.git"; break; case 'bitbucket': return "git@bitbucket.org:{$this->name}.git"; default: // Check of type 'scheme://host/path' if (filter_var($this->type, FILTER_VALIDATE_URL)) { return $this->type; } // Check of type 'user@host' if (filter_var($this->type, FILTER_VALIDATE_EMAIL)) { return "{$this->type}:{$this->name}.git"; } return; break; } }
php
public function getRepoUrl() { switch ($this->type) { case 'github': return "git@github.com:{$this->name}.git"; case 'github-https': return "https://github.com/{$this->name}.git"; case 'gitlab': return "git@gitlab.com:{$this->name}.git"; break; case 'bitbucket': return "git@bitbucket.org:{$this->name}.git"; default: // Check of type 'scheme://host/path' if (filter_var($this->type, FILTER_VALIDATE_URL)) { return $this->type; } // Check of type 'user@host' if (filter_var($this->type, FILTER_VALIDATE_EMAIL)) { return "{$this->type}:{$this->name}.git"; } return; break; } }
[ "public", "function", "getRepoUrl", "(", ")", "{", "switch", "(", "$", "this", "->", "type", ")", "{", "case", "'github'", ":", "return", "\"git@github.com:{$this->name}.git\"", ";", "case", "'github-https'", ":", "return", "\"https://github.com/{$this->name}.git\"", ";", "case", "'gitlab'", ":", "return", "\"git@gitlab.com:{$this->name}.git\"", ";", "break", ";", "case", "'bitbucket'", ":", "return", "\"git@bitbucket.org:{$this->name}.git\"", ";", "default", ":", "// Check of type 'scheme://host/path'", "if", "(", "filter_var", "(", "$", "this", "->", "type", ",", "FILTER_VALIDATE_URL", ")", ")", "{", "return", "$", "this", "->", "type", ";", "}", "// Check of type 'user@host'", "if", "(", "filter_var", "(", "$", "this", "->", "type", ",", "FILTER_VALIDATE_EMAIL", ")", ")", "{", "return", "\"{$this->type}:{$this->name}.git\"", ";", "}", "return", ";", "break", ";", "}", "}" ]
Get git repo url. @return string|null
[ "Get", "git", "repo", "url", "." ]
044b76ec322305bf65ff44f7f1754127ba5b94ad
https://github.com/nWidart/laravel-modules/blob/044b76ec322305bf65ff44f7f1754127ba5b94ad/src/Process/Installer.php#L188-L219
train
nWidart/laravel-modules
src/Process/Installer.php
Installer.getPackageName
public function getPackageName() { if (is_null($this->version)) { return $this->name . ':dev-master'; } return $this->name . ':' . $this->version; }
php
public function getPackageName() { if (is_null($this->version)) { return $this->name . ':dev-master'; } return $this->name . ':' . $this->version; }
[ "public", "function", "getPackageName", "(", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "version", ")", ")", "{", "return", "$", "this", "->", "name", ".", "':dev-master'", ";", "}", "return", "$", "this", "->", "name", ".", "':'", ".", "$", "this", "->", "version", ";", "}" ]
Get composer package name. @return string
[ "Get", "composer", "package", "name", "." ]
044b76ec322305bf65ff44f7f1754127ba5b94ad
https://github.com/nWidart/laravel-modules/blob/044b76ec322305bf65ff44f7f1754127ba5b94ad/src/Process/Installer.php#L248-L255
train
nWidart/laravel-modules
src/Support/Migrations/SchemaParser.php
SchemaParser.addRelationColumn
protected function addRelationColumn($key, $field, $column) { $relatedColumn = Str::snake(class_basename($field)) . '_id'; $method = 'integer'; return "->{$method}('{$relatedColumn}')"; }
php
protected function addRelationColumn($key, $field, $column) { $relatedColumn = Str::snake(class_basename($field)) . '_id'; $method = 'integer'; return "->{$method}('{$relatedColumn}')"; }
[ "protected", "function", "addRelationColumn", "(", "$", "key", ",", "$", "field", ",", "$", "column", ")", "{", "$", "relatedColumn", "=", "Str", "::", "snake", "(", "class_basename", "(", "$", "field", ")", ")", ".", "'_id'", ";", "$", "method", "=", "'integer'", ";", "return", "\"->{$method}('{$relatedColumn}')\"", ";", "}" ]
Add relation column. @param int $key @param string $field @param string $column @return string
[ "Add", "relation", "column", "." ]
044b76ec322305bf65ff44f7f1754127ba5b94ad
https://github.com/nWidart/laravel-modules/blob/044b76ec322305bf65ff44f7f1754127ba5b94ad/src/Support/Migrations/SchemaParser.php#L171-L178
train
nWidart/laravel-modules
src/Json.php
Json.update
public function update(array $data) { $this->attributes = new Collection(array_merge($this->attributes->toArray(), $data)); return $this->save(); }
php
public function update(array $data) { $this->attributes = new Collection(array_merge($this->attributes->toArray(), $data)); return $this->save(); }
[ "public", "function", "update", "(", "array", "$", "data", ")", "{", "$", "this", "->", "attributes", "=", "new", "Collection", "(", "array_merge", "(", "$", "this", "->", "attributes", "->", "toArray", "(", ")", ",", "$", "data", ")", ")", ";", "return", "$", "this", "->", "save", "(", ")", ";", "}" ]
Update json contents from array data. @param array $data @return bool
[ "Update", "json", "contents", "from", "array", "data", "." ]
044b76ec322305bf65ff44f7f1754127ba5b94ad
https://github.com/nWidart/laravel-modules/blob/044b76ec322305bf65ff44f7f1754127ba5b94ad/src/Json.php#L157-L162
train
nWidart/laravel-modules
src/Commands/SeedCommand.php
SeedCommand.getSeederName
public function getSeederName($name) { $name = Str::studly($name); $namespace = $this->laravel['modules']->config('namespace'); $seederPath = GenerateConfigReader::read('seeder'); $seederPath = str_replace('/', '\\', $seederPath->getPath()); return $namespace . '\\' . $name . '\\' . $seederPath . '\\' . $name . 'DatabaseSeeder'; }
php
public function getSeederName($name) { $name = Str::studly($name); $namespace = $this->laravel['modules']->config('namespace'); $seederPath = GenerateConfigReader::read('seeder'); $seederPath = str_replace('/', '\\', $seederPath->getPath()); return $namespace . '\\' . $name . '\\' . $seederPath . '\\' . $name . 'DatabaseSeeder'; }
[ "public", "function", "getSeederName", "(", "$", "name", ")", "{", "$", "name", "=", "Str", "::", "studly", "(", "$", "name", ")", ";", "$", "namespace", "=", "$", "this", "->", "laravel", "[", "'modules'", "]", "->", "config", "(", "'namespace'", ")", ";", "$", "seederPath", "=", "GenerateConfigReader", "::", "read", "(", "'seeder'", ")", ";", "$", "seederPath", "=", "str_replace", "(", "'/'", ",", "'\\\\'", ",", "$", "seederPath", "->", "getPath", "(", ")", ")", ";", "return", "$", "namespace", ".", "'\\\\'", ".", "$", "name", ".", "'\\\\'", ".", "$", "seederPath", ".", "'\\\\'", ".", "$", "name", ".", "'DatabaseSeeder'", ";", "}" ]
Get master database seeder name for the specified module. @param string $name @return string
[ "Get", "master", "database", "seeder", "name", "for", "the", "specified", "module", "." ]
044b76ec322305bf65ff44f7f1754127ba5b94ad
https://github.com/nWidart/laravel-modules/blob/044b76ec322305bf65ff44f7f1754127ba5b94ad/src/Commands/SeedCommand.php#L157-L166
train
nWidart/laravel-modules
src/Commands/SeedCommand.php
SeedCommand.getSeederNames
public function getSeederNames($name) { $name = Str::studly($name); $seederPath = GenerateConfigReader::read('seeder'); $seederPath = str_replace('/', '\\', $seederPath->getPath()); $foundModules = []; foreach ($this->laravel['modules']->config('scan.paths') as $path) { $namespace = array_slice(explode('/', $path), -1)[0]; $foundModules[] = $namespace . '\\' . $name . '\\' . $seederPath . '\\' . $name . 'DatabaseSeeder'; } return $foundModules; }
php
public function getSeederNames($name) { $name = Str::studly($name); $seederPath = GenerateConfigReader::read('seeder'); $seederPath = str_replace('/', '\\', $seederPath->getPath()); $foundModules = []; foreach ($this->laravel['modules']->config('scan.paths') as $path) { $namespace = array_slice(explode('/', $path), -1)[0]; $foundModules[] = $namespace . '\\' . $name . '\\' . $seederPath . '\\' . $name . 'DatabaseSeeder'; } return $foundModules; }
[ "public", "function", "getSeederNames", "(", "$", "name", ")", "{", "$", "name", "=", "Str", "::", "studly", "(", "$", "name", ")", ";", "$", "seederPath", "=", "GenerateConfigReader", "::", "read", "(", "'seeder'", ")", ";", "$", "seederPath", "=", "str_replace", "(", "'/'", ",", "'\\\\'", ",", "$", "seederPath", "->", "getPath", "(", ")", ")", ";", "$", "foundModules", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "laravel", "[", "'modules'", "]", "->", "config", "(", "'scan.paths'", ")", "as", "$", "path", ")", "{", "$", "namespace", "=", "array_slice", "(", "explode", "(", "'/'", ",", "$", "path", ")", ",", "-", "1", ")", "[", "0", "]", ";", "$", "foundModules", "[", "]", "=", "$", "namespace", ".", "'\\\\'", ".", "$", "name", ".", "'\\\\'", ".", "$", "seederPath", ".", "'\\\\'", ".", "$", "name", ".", "'DatabaseSeeder'", ";", "}", "return", "$", "foundModules", ";", "}" ]
Get master database seeder name for the specified module under a different namespace than Modules. @param string $name @return array $foundModules array containing namespace paths
[ "Get", "master", "database", "seeder", "name", "for", "the", "specified", "module", "under", "a", "different", "namespace", "than", "Modules", "." ]
044b76ec322305bf65ff44f7f1754127ba5b94ad
https://github.com/nWidart/laravel-modules/blob/044b76ec322305bf65ff44f7f1754127ba5b94ad/src/Commands/SeedCommand.php#L175-L189
train
nWidart/laravel-modules
src/Migrations/Migrator.php
Migrator.rollback
public function rollback() { $migrations = $this->getLast($this->getMigrations(true)); $this->requireFiles($migrations->toArray()); $migrated = []; foreach ($migrations as $migration) { $data = $this->find($migration); if ($data->count()) { $migrated[] = $migration; $this->down($migration); $data->delete(); } } return $migrated; }
php
public function rollback() { $migrations = $this->getLast($this->getMigrations(true)); $this->requireFiles($migrations->toArray()); $migrated = []; foreach ($migrations as $migration) { $data = $this->find($migration); if ($data->count()) { $migrated[] = $migration; $this->down($migration); $data->delete(); } } return $migrated; }
[ "public", "function", "rollback", "(", ")", "{", "$", "migrations", "=", "$", "this", "->", "getLast", "(", "$", "this", "->", "getMigrations", "(", "true", ")", ")", ";", "$", "this", "->", "requireFiles", "(", "$", "migrations", "->", "toArray", "(", ")", ")", ";", "$", "migrated", "=", "[", "]", ";", "foreach", "(", "$", "migrations", "as", "$", "migration", ")", "{", "$", "data", "=", "$", "this", "->", "find", "(", "$", "migration", ")", ";", "if", "(", "$", "data", "->", "count", "(", ")", ")", "{", "$", "migrated", "[", "]", "=", "$", "migration", ";", "$", "this", "->", "down", "(", "$", "migration", ")", ";", "$", "data", "->", "delete", "(", ")", ";", "}", "}", "return", "$", "migrated", ";", "}" ]
Rollback migration. @return array
[ "Rollback", "migration", "." ]
044b76ec322305bf65ff44f7f1754127ba5b94ad
https://github.com/nWidart/laravel-modules/blob/044b76ec322305bf65ff44f7f1754127ba5b94ad/src/Migrations/Migrator.php#L122-L143
train
nWidart/laravel-modules
src/Migrations/Migrator.php
Migrator.reset
public function reset() { $migrations = $this->getMigrations(true); $this->requireFiles($migrations); $migrated = []; foreach ($migrations as $migration) { $data = $this->find($migration); if ($data->count()) { $migrated[] = $migration; $this->down($migration); $data->delete(); } } return $migrated; }
php
public function reset() { $migrations = $this->getMigrations(true); $this->requireFiles($migrations); $migrated = []; foreach ($migrations as $migration) { $data = $this->find($migration); if ($data->count()) { $migrated[] = $migration; $this->down($migration); $data->delete(); } } return $migrated; }
[ "public", "function", "reset", "(", ")", "{", "$", "migrations", "=", "$", "this", "->", "getMigrations", "(", "true", ")", ";", "$", "this", "->", "requireFiles", "(", "$", "migrations", ")", ";", "$", "migrated", "=", "[", "]", ";", "foreach", "(", "$", "migrations", "as", "$", "migration", ")", "{", "$", "data", "=", "$", "this", "->", "find", "(", "$", "migration", ")", ";", "if", "(", "$", "data", "->", "count", "(", ")", ")", "{", "$", "migrated", "[", "]", "=", "$", "migration", ";", "$", "this", "->", "down", "(", "$", "migration", ")", ";", "$", "data", "->", "delete", "(", ")", ";", "}", "}", "return", "$", "migrated", ";", "}" ]
Reset migration. @return array
[ "Reset", "migration", "." ]
044b76ec322305bf65ff44f7f1754127ba5b94ad
https://github.com/nWidart/laravel-modules/blob/044b76ec322305bf65ff44f7f1754127ba5b94ad/src/Migrations/Migrator.php#L150-L171
train
nWidart/laravel-modules
src/Commands/PublishCommand.php
PublishCommand.publish
public function publish($name) { if ($name instanceof Module) { $module = $name; } else { $module = $this->laravel['modules']->findOrFail($name); } with(new AssetPublisher($module)) ->setRepository($this->laravel['modules']) ->setConsole($this) ->publish(); $this->line("<info>Published</info>: {$module->getStudlyName()}"); }
php
public function publish($name) { if ($name instanceof Module) { $module = $name; } else { $module = $this->laravel['modules']->findOrFail($name); } with(new AssetPublisher($module)) ->setRepository($this->laravel['modules']) ->setConsole($this) ->publish(); $this->line("<info>Published</info>: {$module->getStudlyName()}"); }
[ "public", "function", "publish", "(", "$", "name", ")", "{", "if", "(", "$", "name", "instanceof", "Module", ")", "{", "$", "module", "=", "$", "name", ";", "}", "else", "{", "$", "module", "=", "$", "this", "->", "laravel", "[", "'modules'", "]", "->", "findOrFail", "(", "$", "name", ")", ";", "}", "with", "(", "new", "AssetPublisher", "(", "$", "module", ")", ")", "->", "setRepository", "(", "$", "this", "->", "laravel", "[", "'modules'", "]", ")", "->", "setConsole", "(", "$", "this", ")", "->", "publish", "(", ")", ";", "$", "this", "->", "line", "(", "\"<info>Published</info>: {$module->getStudlyName()}\"", ")", ";", "}" ]
Publish assets from the specified module. @param string $name
[ "Publish", "assets", "from", "the", "specified", "module", "." ]
044b76ec322305bf65ff44f7f1754127ba5b94ad
https://github.com/nWidart/laravel-modules/blob/044b76ec322305bf65ff44f7f1754127ba5b94ad/src/Commands/PublishCommand.php#L55-L69
train
nWidart/laravel-modules
src/Generators/FileGenerator.php
FileGenerator.generate
public function generate() { if (!$this->filesystem->exists($path = $this->getPath())) { return $this->filesystem->put($path, $this->getContents()); } throw new FileAlreadyExistException('File already exists!'); }
php
public function generate() { if (!$this->filesystem->exists($path = $this->getPath())) { return $this->filesystem->put($path, $this->getContents()); } throw new FileAlreadyExistException('File already exists!'); }
[ "public", "function", "generate", "(", ")", "{", "if", "(", "!", "$", "this", "->", "filesystem", "->", "exists", "(", "$", "path", "=", "$", "this", "->", "getPath", "(", ")", ")", ")", "{", "return", "$", "this", "->", "filesystem", "->", "put", "(", "$", "path", ",", "$", "this", "->", "getContents", "(", ")", ")", ";", "}", "throw", "new", "FileAlreadyExistException", "(", "'File already exists!'", ")", ";", "}" ]
Generate the file.
[ "Generate", "the", "file", "." ]
044b76ec322305bf65ff44f7f1754127ba5b94ad
https://github.com/nWidart/laravel-modules/blob/044b76ec322305bf65ff44f7f1754127ba5b94ad/src/Generators/FileGenerator.php#L120-L127
train
nWidart/laravel-modules
src/Commands/InstallCommand.php
InstallCommand.installFromFile
protected function installFromFile() { if (!file_exists($path = base_path('modules.json'))) { $this->error("File 'modules.json' does not exist in your project root."); return; } $modules = Json::make($path); $dependencies = $modules->get('require', []); foreach ($dependencies as $module) { $module = collect($module); $this->install( $module->get('name'), $module->get('version'), $module->get('type') ); } }
php
protected function installFromFile() { if (!file_exists($path = base_path('modules.json'))) { $this->error("File 'modules.json' does not exist in your project root."); return; } $modules = Json::make($path); $dependencies = $modules->get('require', []); foreach ($dependencies as $module) { $module = collect($module); $this->install( $module->get('name'), $module->get('version'), $module->get('type') ); } }
[ "protected", "function", "installFromFile", "(", ")", "{", "if", "(", "!", "file_exists", "(", "$", "path", "=", "base_path", "(", "'modules.json'", ")", ")", ")", "{", "$", "this", "->", "error", "(", "\"File 'modules.json' does not exist in your project root.\"", ")", ";", "return", ";", "}", "$", "modules", "=", "Json", "::", "make", "(", "$", "path", ")", ";", "$", "dependencies", "=", "$", "modules", "->", "get", "(", "'require'", ",", "[", "]", ")", ";", "foreach", "(", "$", "dependencies", "as", "$", "module", ")", "{", "$", "module", "=", "collect", "(", "$", "module", ")", ";", "$", "this", "->", "install", "(", "$", "module", "->", "get", "(", "'name'", ")", ",", "$", "module", "->", "get", "(", "'version'", ")", ",", "$", "module", "->", "get", "(", "'type'", ")", ")", ";", "}", "}" ]
Install modules from modules.json file.
[ "Install", "modules", "from", "modules", ".", "json", "file", "." ]
044b76ec322305bf65ff44f7f1754127ba5b94ad
https://github.com/nWidart/laravel-modules/blob/044b76ec322305bf65ff44f7f1754127ba5b94ad/src/Commands/InstallCommand.php#L57-L78
train
nWidart/laravel-modules
src/Commands/ModelMakeCommand.php
ModelMakeCommand.handleOptionalMigrationOption
private function handleOptionalMigrationOption() { if ($this->option('migration') === true) { $migrationName = 'create_' . $this->createMigrationName() . '_table'; $this->call('module:make-migration', ['name' => $migrationName, 'module' => $this->argument('module')]); } }
php
private function handleOptionalMigrationOption() { if ($this->option('migration') === true) { $migrationName = 'create_' . $this->createMigrationName() . '_table'; $this->call('module:make-migration', ['name' => $migrationName, 'module' => $this->argument('module')]); } }
[ "private", "function", "handleOptionalMigrationOption", "(", ")", "{", "if", "(", "$", "this", "->", "option", "(", "'migration'", ")", "===", "true", ")", "{", "$", "migrationName", "=", "'create_'", ".", "$", "this", "->", "createMigrationName", "(", ")", ".", "'_table'", ";", "$", "this", "->", "call", "(", "'module:make-migration'", ",", "[", "'name'", "=>", "$", "migrationName", ",", "'module'", "=>", "$", "this", "->", "argument", "(", "'module'", ")", "]", ")", ";", "}", "}" ]
Create the migration file with the given model if migration flag was used
[ "Create", "the", "migration", "file", "with", "the", "given", "model", "if", "migration", "flag", "was", "used" ]
044b76ec322305bf65ff44f7f1754127ba5b94ad
https://github.com/nWidart/laravel-modules/blob/044b76ec322305bf65ff44f7f1754127ba5b94ad/src/Commands/ModelMakeCommand.php#L95-L101
train
nWidart/laravel-modules
src/Traits/MigrationLoaderTrait.php
MigrationLoaderTrait.loadMigrationFiles
protected function loadMigrationFiles($module) { $path = $this->laravel['modules']->getModulePath($module) . $this->getMigrationGeneratorPath(); $files = $this->laravel['files']->glob($path . '/*_*.php'); foreach ($files as $file) { $this->laravel['files']->requireOnce($file); } }
php
protected function loadMigrationFiles($module) { $path = $this->laravel['modules']->getModulePath($module) . $this->getMigrationGeneratorPath(); $files = $this->laravel['files']->glob($path . '/*_*.php'); foreach ($files as $file) { $this->laravel['files']->requireOnce($file); } }
[ "protected", "function", "loadMigrationFiles", "(", "$", "module", ")", "{", "$", "path", "=", "$", "this", "->", "laravel", "[", "'modules'", "]", "->", "getModulePath", "(", "$", "module", ")", ".", "$", "this", "->", "getMigrationGeneratorPath", "(", ")", ";", "$", "files", "=", "$", "this", "->", "laravel", "[", "'files'", "]", "->", "glob", "(", "$", "path", ".", "'/*_*.php'", ")", ";", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "$", "this", "->", "laravel", "[", "'files'", "]", "->", "requireOnce", "(", "$", "file", ")", ";", "}", "}" ]
Include all migrations files from the specified module. @param string $module
[ "Include", "all", "migrations", "files", "from", "the", "specified", "module", "." ]
044b76ec322305bf65ff44f7f1754127ba5b94ad
https://github.com/nWidart/laravel-modules/blob/044b76ec322305bf65ff44f7f1754127ba5b94ad/src/Traits/MigrationLoaderTrait.php#L12-L21
train
nWidart/laravel-modules
src/Module.php
Module.register
public function register() { $this->registerAliases(); $this->registerProviders(); if ($this->isLoadFilesOnBoot() === false) { $this->registerFiles(); } $this->fireEvent('register'); }
php
public function register() { $this->registerAliases(); $this->registerProviders(); if ($this->isLoadFilesOnBoot() === false) { $this->registerFiles(); } $this->fireEvent('register'); }
[ "public", "function", "register", "(", ")", "{", "$", "this", "->", "registerAliases", "(", ")", ";", "$", "this", "->", "registerProviders", "(", ")", ";", "if", "(", "$", "this", "->", "isLoadFilesOnBoot", "(", ")", "===", "false", ")", "{", "$", "this", "->", "registerFiles", "(", ")", ";", "}", "$", "this", "->", "fireEvent", "(", "'register'", ")", ";", "}" ]
Register the module.
[ "Register", "the", "module", "." ]
044b76ec322305bf65ff44f7f1754127ba5b94ad
https://github.com/nWidart/laravel-modules/blob/044b76ec322305bf65ff44f7f1754127ba5b94ad/src/Module.php#L248-L259
train
nWidart/laravel-modules
src/Commands/ControllerMakeCommand.php
ControllerMakeCommand.getStubName
private function getStubName() { if ($this->option('plain') === true) { $stub = '/controller-plain.stub'; } elseif ($this->option('api') === true) { $stub = '/controller-api.stub'; } else { $stub = '/controller.stub'; } return $stub; }
php
private function getStubName() { if ($this->option('plain') === true) { $stub = '/controller-plain.stub'; } elseif ($this->option('api') === true) { $stub = '/controller-api.stub'; } else { $stub = '/controller.stub'; } return $stub; }
[ "private", "function", "getStubName", "(", ")", "{", "if", "(", "$", "this", "->", "option", "(", "'plain'", ")", "===", "true", ")", "{", "$", "stub", "=", "'/controller-plain.stub'", ";", "}", "elseif", "(", "$", "this", "->", "option", "(", "'api'", ")", "===", "true", ")", "{", "$", "stub", "=", "'/controller-api.stub'", ";", "}", "else", "{", "$", "stub", "=", "'/controller.stub'", ";", "}", "return", "$", "stub", ";", "}" ]
Get the stub file name based on the options @return string
[ "Get", "the", "stub", "file", "name", "based", "on", "the", "options" ]
044b76ec322305bf65ff44f7f1754127ba5b94ad
https://github.com/nWidart/laravel-modules/blob/044b76ec322305bf65ff44f7f1754127ba5b94ad/src/Commands/ControllerMakeCommand.php#L127-L138
train
nWidart/laravel-modules
src/Generators/ModuleGenerator.php
ModuleGenerator.getReplacement
protected function getReplacement($stub) { $replacements = $this->module->config('stubs.replacements'); if (!isset($replacements[$stub])) { return []; } $keys = $replacements[$stub]; $replaces = []; foreach ($keys as $key) { if (method_exists($this, $method = 'get' . ucfirst(Str::studly(strtolower($key))) . 'Replacement')) { $replaces[$key] = $this->$method(); } else { $replaces[$key] = null; } } return $replaces; }
php
protected function getReplacement($stub) { $replacements = $this->module->config('stubs.replacements'); if (!isset($replacements[$stub])) { return []; } $keys = $replacements[$stub]; $replaces = []; foreach ($keys as $key) { if (method_exists($this, $method = 'get' . ucfirst(Str::studly(strtolower($key))) . 'Replacement')) { $replaces[$key] = $this->$method(); } else { $replaces[$key] = null; } } return $replaces; }
[ "protected", "function", "getReplacement", "(", "$", "stub", ")", "{", "$", "replacements", "=", "$", "this", "->", "module", "->", "config", "(", "'stubs.replacements'", ")", ";", "if", "(", "!", "isset", "(", "$", "replacements", "[", "$", "stub", "]", ")", ")", "{", "return", "[", "]", ";", "}", "$", "keys", "=", "$", "replacements", "[", "$", "stub", "]", ";", "$", "replaces", "=", "[", "]", ";", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "if", "(", "method_exists", "(", "$", "this", ",", "$", "method", "=", "'get'", ".", "ucfirst", "(", "Str", "::", "studly", "(", "strtolower", "(", "$", "key", ")", ")", ")", ".", "'Replacement'", ")", ")", "{", "$", "replaces", "[", "$", "key", "]", "=", "$", "this", "->", "$", "method", "(", ")", ";", "}", "else", "{", "$", "replaces", "[", "$", "key", "]", "=", "null", ";", "}", "}", "return", "$", "replaces", ";", "}" ]
Get array replacement for the specified stub. @param $stub @return array
[ "Get", "array", "replacement", "for", "the", "specified", "stub", "." ]
044b76ec322305bf65ff44f7f1754127ba5b94ad
https://github.com/nWidart/laravel-modules/blob/044b76ec322305bf65ff44f7f1754127ba5b94ad/src/Generators/ModuleGenerator.php#L380-L401
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.disconnect
public function disconnect() { if (is_resource($this->socket)) { @socket_shutdown($this->socket, 2); @socket_close($this->socket); } $this->socket = null; $this->loginStatus = Constants::DISCONNECTED_STATUS; $this->logFile('info', 'Disconnected from WA server'); $this->eventManager()->fire('onDisconnect', [ $this->phoneNumber, $this->socket, ] ); }
php
public function disconnect() { if (is_resource($this->socket)) { @socket_shutdown($this->socket, 2); @socket_close($this->socket); } $this->socket = null; $this->loginStatus = Constants::DISCONNECTED_STATUS; $this->logFile('info', 'Disconnected from WA server'); $this->eventManager()->fire('onDisconnect', [ $this->phoneNumber, $this->socket, ] ); }
[ "public", "function", "disconnect", "(", ")", "{", "if", "(", "is_resource", "(", "$", "this", "->", "socket", ")", ")", "{", "@", "socket_shutdown", "(", "$", "this", "->", "socket", ",", "2", ")", ";", "@", "socket_close", "(", "$", "this", "->", "socket", ")", ";", "}", "$", "this", "->", "socket", "=", "null", ";", "$", "this", "->", "loginStatus", "=", "Constants", "::", "DISCONNECTED_STATUS", ";", "$", "this", "->", "logFile", "(", "'info'", ",", "'Disconnected from WA server'", ")", ";", "$", "this", "->", "eventManager", "(", ")", "->", "fire", "(", "'onDisconnect'", ",", "[", "$", "this", "->", "phoneNumber", ",", "$", "this", "->", "socket", ",", "]", ")", ";", "}" ]
Disconnect from the WhatsApp network.
[ "Disconnect", "from", "the", "WhatsApp", "network", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L221-L236
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.loginWithPassword
public function loginWithPassword($password) { $this->password = $password; if (is_readable($this->challengeFilename)) { $challengeData = file_get_contents($this->challengeFilename); if ($challengeData) { $this->challengeData = $challengeData; } } $login = new Login($this, $this->password); $login->doLogin(); }
php
public function loginWithPassword($password) { $this->password = $password; if (is_readable($this->challengeFilename)) { $challengeData = file_get_contents($this->challengeFilename); if ($challengeData) { $this->challengeData = $challengeData; } } $login = new Login($this, $this->password); $login->doLogin(); }
[ "public", "function", "loginWithPassword", "(", "$", "password", ")", "{", "$", "this", "->", "password", "=", "$", "password", ";", "if", "(", "is_readable", "(", "$", "this", "->", "challengeFilename", ")", ")", "{", "$", "challengeData", "=", "file_get_contents", "(", "$", "this", "->", "challengeFilename", ")", ";", "if", "(", "$", "challengeData", ")", "{", "$", "this", "->", "challengeData", "=", "$", "challengeData", ";", "}", "}", "$", "login", "=", "new", "Login", "(", "$", "this", ",", "$", "this", "->", "password", ")", ";", "$", "login", "->", "doLogin", "(", ")", ";", "}" ]
Login to the WhatsApp server with your password. If you already know your password you can log into the Whatsapp server using this method. @param string $password Your whatsapp password. You must already know this!
[ "Login", "to", "the", "WhatsApp", "server", "with", "your", "password", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L277-L288
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.pollMessage
public function pollMessage() { if (!$this->isConnected()) { throw new ConnectionException('Connection Closed!'); } $r = [$this->socket]; $w = []; $e = []; $s = socket_select($r, $w, $e, Constants::TIMEOUT_SEC, Constants::TIMEOUT_USEC); if ($s) { // Something to read if ($stanza = $this->readStanza()) { $this->processInboundData($stanza); return true; } } if (time() - $this->timeout > 60) { if ($this->pingCounter >= 3) { $this->sendOfflineStatus(); $this->disconnect(); $this->iqCounter = 1; $this->connect(); $this->loginWithPassword($this->password); $this->pingCounter = 1; } else { $this->sendPing(); $this->pingCounter++; } } return false; }
php
public function pollMessage() { if (!$this->isConnected()) { throw new ConnectionException('Connection Closed!'); } $r = [$this->socket]; $w = []; $e = []; $s = socket_select($r, $w, $e, Constants::TIMEOUT_SEC, Constants::TIMEOUT_USEC); if ($s) { // Something to read if ($stanza = $this->readStanza()) { $this->processInboundData($stanza); return true; } } if (time() - $this->timeout > 60) { if ($this->pingCounter >= 3) { $this->sendOfflineStatus(); $this->disconnect(); $this->iqCounter = 1; $this->connect(); $this->loginWithPassword($this->password); $this->pingCounter = 1; } else { $this->sendPing(); $this->pingCounter++; } } return false; }
[ "public", "function", "pollMessage", "(", ")", "{", "if", "(", "!", "$", "this", "->", "isConnected", "(", ")", ")", "{", "throw", "new", "ConnectionException", "(", "'Connection Closed!'", ")", ";", "}", "$", "r", "=", "[", "$", "this", "->", "socket", "]", ";", "$", "w", "=", "[", "]", ";", "$", "e", "=", "[", "]", ";", "$", "s", "=", "socket_select", "(", "$", "r", ",", "$", "w", ",", "$", "e", ",", "Constants", "::", "TIMEOUT_SEC", ",", "Constants", "::", "TIMEOUT_USEC", ")", ";", "if", "(", "$", "s", ")", "{", "// Something to read", "if", "(", "$", "stanza", "=", "$", "this", "->", "readStanza", "(", ")", ")", "{", "$", "this", "->", "processInboundData", "(", "$", "stanza", ")", ";", "return", "true", ";", "}", "}", "if", "(", "time", "(", ")", "-", "$", "this", "->", "timeout", ">", "60", ")", "{", "if", "(", "$", "this", "->", "pingCounter", ">=", "3", ")", "{", "$", "this", "->", "sendOfflineStatus", "(", ")", ";", "$", "this", "->", "disconnect", "(", ")", ";", "$", "this", "->", "iqCounter", "=", "1", ";", "$", "this", "->", "connect", "(", ")", ";", "$", "this", "->", "loginWithPassword", "(", "$", "this", "->", "password", ")", ";", "$", "this", "->", "pingCounter", "=", "1", ";", "}", "else", "{", "$", "this", "->", "sendPing", "(", ")", ";", "$", "this", "->", "pingCounter", "++", ";", "}", "}", "return", "false", ";", "}" ]
Fetch a single message node. @throws Exception @return bool
[ "Fetch", "a", "single", "message", "node", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L297-L334
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendGetCipherKeysFromUser
public function sendGetCipherKeysFromUser($numbers, $replaceKey = false) { if (!is_array($numbers)) { $numbers = [$numbers]; } $this->replaceKey = $replaceKey; $msgId = $this->nodeId['cipherKeys'] = $this->createIqId(); $userNode = []; foreach ($numbers as $number) { $userNode[] = new ProtocolNode('user', [ 'jid' => $this->getJID($number), ], null, null); } $keyNode = new ProtocolNode('key', null, $userNode, null); $node = new ProtocolNode('iq', [ 'id' => $msgId, 'xmlns' => 'encrypt', 'type' => 'get', 'to' => Constants::WHATSAPP_SERVER, ], [$keyNode], null); $this->sendNode($node); $this->waitForServer($msgId); }
php
public function sendGetCipherKeysFromUser($numbers, $replaceKey = false) { if (!is_array($numbers)) { $numbers = [$numbers]; } $this->replaceKey = $replaceKey; $msgId = $this->nodeId['cipherKeys'] = $this->createIqId(); $userNode = []; foreach ($numbers as $number) { $userNode[] = new ProtocolNode('user', [ 'jid' => $this->getJID($number), ], null, null); } $keyNode = new ProtocolNode('key', null, $userNode, null); $node = new ProtocolNode('iq', [ 'id' => $msgId, 'xmlns' => 'encrypt', 'type' => 'get', 'to' => Constants::WHATSAPP_SERVER, ], [$keyNode], null); $this->sendNode($node); $this->waitForServer($msgId); }
[ "public", "function", "sendGetCipherKeysFromUser", "(", "$", "numbers", ",", "$", "replaceKey", "=", "false", ")", "{", "if", "(", "!", "is_array", "(", "$", "numbers", ")", ")", "{", "$", "numbers", "=", "[", "$", "numbers", "]", ";", "}", "$", "this", "->", "replaceKey", "=", "$", "replaceKey", ";", "$", "msgId", "=", "$", "this", "->", "nodeId", "[", "'cipherKeys'", "]", "=", "$", "this", "->", "createIqId", "(", ")", ";", "$", "userNode", "=", "[", "]", ";", "foreach", "(", "$", "numbers", "as", "$", "number", ")", "{", "$", "userNode", "[", "]", "=", "new", "ProtocolNode", "(", "'user'", ",", "[", "'jid'", "=>", "$", "this", "->", "getJID", "(", "$", "number", ")", ",", "]", ",", "null", ",", "null", ")", ";", "}", "$", "keyNode", "=", "new", "ProtocolNode", "(", "'key'", ",", "null", ",", "$", "userNode", ",", "null", ")", ";", "$", "node", "=", "new", "ProtocolNode", "(", "'iq'", ",", "[", "'id'", "=>", "$", "msgId", ",", "'xmlns'", "=>", "'encrypt'", ",", "'type'", "=>", "'get'", ",", "'to'", "=>", "Constants", "::", "WHATSAPP_SERVER", ",", "]", ",", "[", "$", "keyNode", "]", ",", "null", ")", ";", "$", "this", "->", "sendNode", "(", "$", "node", ")", ";", "$", "this", "->", "waitForServer", "(", "$", "msgId", ")", ";", "}" ]
Send a request to get cipher keys from an user. @param $number Phone number of the user you want to get the cipher keys.
[ "Send", "a", "request", "to", "get", "cipher", "keys", "from", "an", "user", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L403-L430
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendBroadcastAudio
public function sendBroadcastAudio($targets, $path, $storeURLmedia = false, $fsize = 0, $fhash = '') { if (!is_array($targets)) { $targets = [$targets]; } // Return message ID. Make pull request for this. return $this->sendMessageAudio($targets, $path, $storeURLmedia, $fsize, $fhash); }
php
public function sendBroadcastAudio($targets, $path, $storeURLmedia = false, $fsize = 0, $fhash = '') { if (!is_array($targets)) { $targets = [$targets]; } // Return message ID. Make pull request for this. return $this->sendMessageAudio($targets, $path, $storeURLmedia, $fsize, $fhash); }
[ "public", "function", "sendBroadcastAudio", "(", "$", "targets", ",", "$", "path", ",", "$", "storeURLmedia", "=", "false", ",", "$", "fsize", "=", "0", ",", "$", "fhash", "=", "''", ")", "{", "if", "(", "!", "is_array", "(", "$", "targets", ")", ")", "{", "$", "targets", "=", "[", "$", "targets", "]", ";", "}", "// Return message ID. Make pull request for this.", "return", "$", "this", "->", "sendMessageAudio", "(", "$", "targets", ",", "$", "path", ",", "$", "storeURLmedia", ",", "$", "fsize", ",", "$", "fhash", ")", ";", "}" ]
Send a Broadcast Message with audio. The recipients MUST have your number (synced) and in their contact list otherwise the message will not deliver to that person. Approx 20 (unverified) is the maximum number of targets @param array $targets An array of numbers to send to. @param string $path URL or local path to the audio file to send @param bool $storeURLmedia Keep a copy of the audio file on your server @param int $fsize @param string $fhash @return string|null Message ID if successfully, null if not.
[ "Send", "a", "Broadcast", "Message", "with", "audio", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L511-L518
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendBroadcastImage
public function sendBroadcastImage($targets, $path, $storeURLmedia = false, $fsize = 0, $fhash = '', $caption = '') { if (!is_array($targets)) { $targets = [$targets]; } // Return message ID. Make pull request for this. return $this->sendMessageImage($targets, $path, $storeURLmedia, $fsize, $fhash, $caption); }
php
public function sendBroadcastImage($targets, $path, $storeURLmedia = false, $fsize = 0, $fhash = '', $caption = '') { if (!is_array($targets)) { $targets = [$targets]; } // Return message ID. Make pull request for this. return $this->sendMessageImage($targets, $path, $storeURLmedia, $fsize, $fhash, $caption); }
[ "public", "function", "sendBroadcastImage", "(", "$", "targets", ",", "$", "path", ",", "$", "storeURLmedia", "=", "false", ",", "$", "fsize", "=", "0", ",", "$", "fhash", "=", "''", ",", "$", "caption", "=", "''", ")", "{", "if", "(", "!", "is_array", "(", "$", "targets", ")", ")", "{", "$", "targets", "=", "[", "$", "targets", "]", ";", "}", "// Return message ID. Make pull request for this.", "return", "$", "this", "->", "sendMessageImage", "(", "$", "targets", ",", "$", "path", ",", "$", "storeURLmedia", ",", "$", "fsize", ",", "$", "fhash", ",", "$", "caption", ")", ";", "}" ]
Send a Broadcast Message with an image. The recipients MUST have your number (synced) and in their contact list otherwise the message will not deliver to that person. Approx 20 (unverified) is the maximum number of targets @param array $targets An array of numbers to send to. @param string $path URL or local path to the image file to send @param bool $storeURLmedia Keep a copy of the audio file on your server @param int $fsize @param string $fhash @param string $caption @return string|null Message ID if successfully, null if not.
[ "Send", "a", "Broadcast", "Message", "with", "an", "image", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L537-L544
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendBroadcastLocation
public function sendBroadcastLocation($targets, $long, $lat, $name = null, $url = null) { if (!is_array($targets)) { $targets = [$targets]; } // Return message ID. Make pull request for this. return $this->sendMessageLocation($targets, $long, $lat, $name, $url); }
php
public function sendBroadcastLocation($targets, $long, $lat, $name = null, $url = null) { if (!is_array($targets)) { $targets = [$targets]; } // Return message ID. Make pull request for this. return $this->sendMessageLocation($targets, $long, $lat, $name, $url); }
[ "public", "function", "sendBroadcastLocation", "(", "$", "targets", ",", "$", "long", ",", "$", "lat", ",", "$", "name", "=", "null", ",", "$", "url", "=", "null", ")", "{", "if", "(", "!", "is_array", "(", "$", "targets", ")", ")", "{", "$", "targets", "=", "[", "$", "targets", "]", ";", "}", "// Return message ID. Make pull request for this.", "return", "$", "this", "->", "sendMessageLocation", "(", "$", "targets", ",", "$", "long", ",", "$", "lat", ",", "$", "name", ",", "$", "url", ")", ";", "}" ]
Send a Broadcast Message with location data. The recipients MUST have your number (synced) and in their contact list otherwise the message will not deliver to that person. If no name is supplied , receiver will see large sized google map thumbnail of entered Lat/Long but NO name/url for location. With name supplied, a combined map thumbnail/name box is displayed Approx 20 (unverified) is the maximum number of targets @param array $targets An array of numbers to send to. @param float $long The longitude of the location eg 54.31652 @param float $lat The latitude if the location eg -6.833496 @param string $name (Optional) A name to describe the location @param string $url (Optional) A URL to link location to web resource @return string Message ID
[ "Send", "a", "Broadcast", "Message", "with", "location", "data", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L566-L573
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendBroadcastMessage
public function sendBroadcastMessage($targets, $message) { $bodyNode = new ProtocolNode('body', null, null, $message); // Return message ID. Make pull request for this. return $this->sendBroadcast($targets, $bodyNode, 'text'); }
php
public function sendBroadcastMessage($targets, $message) { $bodyNode = new ProtocolNode('body', null, null, $message); // Return message ID. Make pull request for this. return $this->sendBroadcast($targets, $bodyNode, 'text'); }
[ "public", "function", "sendBroadcastMessage", "(", "$", "targets", ",", "$", "message", ")", "{", "$", "bodyNode", "=", "new", "ProtocolNode", "(", "'body'", ",", "null", ",", "null", ",", "$", "message", ")", ";", "// Return message ID. Make pull request for this.", "return", "$", "this", "->", "sendBroadcast", "(", "$", "targets", ",", "$", "bodyNode", ",", "'text'", ")", ";", "}" ]
Send a Broadcast Message. The recipients MUST have your number (synced) and in their contact list otherwise the message will not deliver to that person. Approx 20 (unverified) is the maximum number of targets @param array $targets An array of numbers to send to. @param string $message Your message @return string Message ID
[ "Send", "a", "Broadcast", "Message", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L588-L593
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendBroadcastVideo
public function sendBroadcastVideo($targets, $path, $storeURLmedia = false, $fsize = 0, $fhash = '', $caption = '') { if (!is_array($targets)) { $targets = [$targets]; } // Return message ID. Make pull request for this. return $this->sendMessageVideo($targets, $path, $storeURLmedia, $fsize, $fhash, $caption); }
php
public function sendBroadcastVideo($targets, $path, $storeURLmedia = false, $fsize = 0, $fhash = '', $caption = '') { if (!is_array($targets)) { $targets = [$targets]; } // Return message ID. Make pull request for this. return $this->sendMessageVideo($targets, $path, $storeURLmedia, $fsize, $fhash, $caption); }
[ "public", "function", "sendBroadcastVideo", "(", "$", "targets", ",", "$", "path", ",", "$", "storeURLmedia", "=", "false", ",", "$", "fsize", "=", "0", ",", "$", "fhash", "=", "''", ",", "$", "caption", "=", "''", ")", "{", "if", "(", "!", "is_array", "(", "$", "targets", ")", ")", "{", "$", "targets", "=", "[", "$", "targets", "]", ";", "}", "// Return message ID. Make pull request for this.", "return", "$", "this", "->", "sendMessageVideo", "(", "$", "targets", ",", "$", "path", ",", "$", "storeURLmedia", ",", "$", "fsize", ",", "$", "fhash", ",", "$", "caption", ")", ";", "}" ]
Send a Broadcast Message with a video. The recipients MUST have your number (synced) and in their contact list otherwise the message will not deliver to that person. Approx 20 (unverified) is the maximum number of targets @param array $targets An array of numbers to send to. @param string $path URL or local path to the video file to send @param bool $storeURLmedia Keep a copy of the audio file on your server @param int $fsize @param string $fhash @param string $caption @return string|null Message ID if successfully, null if not.
[ "Send", "a", "Broadcast", "Message", "with", "a", "video", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L612-L619
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendDeleteBroadcastLists
public function sendDeleteBroadcastLists($lists) { $msgId = $this->createIqId(); $listNode = []; if ($lists != null && count($lists) > 0) { for ($i = 0; $i < count($lists); $i++) { $listNode[$i] = new ProtocolNode('list', ['id' => $lists[$i]], null, null); } } else { $listNode = null; } $deleteNode = new ProtocolNode('delete', null, $listNode, null); $node = new ProtocolNode('iq', [ 'id' => $msgId, 'xmlns' => 'w:b', 'type' => 'set', 'to' => Constants::WHATSAPP_SERVER, ], [$deleteNode], null); $this->sendNode($node); }
php
public function sendDeleteBroadcastLists($lists) { $msgId = $this->createIqId(); $listNode = []; if ($lists != null && count($lists) > 0) { for ($i = 0; $i < count($lists); $i++) { $listNode[$i] = new ProtocolNode('list', ['id' => $lists[$i]], null, null); } } else { $listNode = null; } $deleteNode = new ProtocolNode('delete', null, $listNode, null); $node = new ProtocolNode('iq', [ 'id' => $msgId, 'xmlns' => 'w:b', 'type' => 'set', 'to' => Constants::WHATSAPP_SERVER, ], [$deleteNode], null); $this->sendNode($node); }
[ "public", "function", "sendDeleteBroadcastLists", "(", "$", "lists", ")", "{", "$", "msgId", "=", "$", "this", "->", "createIqId", "(", ")", ";", "$", "listNode", "=", "[", "]", ";", "if", "(", "$", "lists", "!=", "null", "&&", "count", "(", "$", "lists", ")", ">", "0", ")", "{", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "lists", ")", ";", "$", "i", "++", ")", "{", "$", "listNode", "[", "$", "i", "]", "=", "new", "ProtocolNode", "(", "'list'", ",", "[", "'id'", "=>", "$", "lists", "[", "$", "i", "]", "]", ",", "null", ",", "null", ")", ";", "}", "}", "else", "{", "$", "listNode", "=", "null", ";", "}", "$", "deleteNode", "=", "new", "ProtocolNode", "(", "'delete'", ",", "null", ",", "$", "listNode", ",", "null", ")", ";", "$", "node", "=", "new", "ProtocolNode", "(", "'iq'", ",", "[", "'id'", "=>", "$", "msgId", ",", "'xmlns'", "=>", "'w:b'", ",", "'type'", "=>", "'set'", ",", "'to'", "=>", "Constants", "::", "WHATSAPP_SERVER", ",", "]", ",", "[", "$", "deleteNode", "]", ",", "null", ")", ";", "$", "this", "->", "sendNode", "(", "$", "node", ")", ";", "}" ]
Delete Broadcast lists. @param string array $lists Contains the broadcast-id list
[ "Delete", "Broadcast", "lists", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L627-L648
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendClearDirty
public function sendClearDirty($categories) { $msgId = $this->createIqId(); $catnodes = []; foreach ($categories as $category) { $catnode = new ProtocolNode('clean', ['type' => $category], null, null); $catnodes[] = $catnode; } $node = new ProtocolNode('iq', [ 'id' => $msgId, 'type' => 'set', 'to' => Constants::WHATSAPP_SERVER, 'xmlns' => 'urn:xmpp:whatsapp:dirty', ], $catnodes, null); $this->sendNode($node); }
php
public function sendClearDirty($categories) { $msgId = $this->createIqId(); $catnodes = []; foreach ($categories as $category) { $catnode = new ProtocolNode('clean', ['type' => $category], null, null); $catnodes[] = $catnode; } $node = new ProtocolNode('iq', [ 'id' => $msgId, 'type' => 'set', 'to' => Constants::WHATSAPP_SERVER, 'xmlns' => 'urn:xmpp:whatsapp:dirty', ], $catnodes, null); $this->sendNode($node); }
[ "public", "function", "sendClearDirty", "(", "$", "categories", ")", "{", "$", "msgId", "=", "$", "this", "->", "createIqId", "(", ")", ";", "$", "catnodes", "=", "[", "]", ";", "foreach", "(", "$", "categories", "as", "$", "category", ")", "{", "$", "catnode", "=", "new", "ProtocolNode", "(", "'clean'", ",", "[", "'type'", "=>", "$", "category", "]", ",", "null", ",", "null", ")", ";", "$", "catnodes", "[", "]", "=", "$", "catnode", ";", "}", "$", "node", "=", "new", "ProtocolNode", "(", "'iq'", ",", "[", "'id'", "=>", "$", "msgId", ",", "'type'", "=>", "'set'", ",", "'to'", "=>", "Constants", "::", "WHATSAPP_SERVER", ",", "'xmlns'", "=>", "'urn:xmpp:whatsapp:dirty'", ",", "]", ",", "$", "catnodes", ",", "null", ")", ";", "$", "this", "->", "sendNode", "(", "$", "node", ")", ";", "}" ]
Clears the "dirty" status on your account. @param array $categories
[ "Clears", "the", "dirty", "status", "on", "your", "account", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L655-L673
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendChangeNumber
public function sendChangeNumber($number, $identity) { $msgId = $this->createIqId(); $usernameNode = new ProtocolNode('username', null, null, $number); $passwordNode = new ProtocolNode('password', null, null, urldecode($identity)); $modifyNode = new ProtocolNode('modify', null, [$usernameNode, $passwordNode], null); $iqNode = new ProtocolNode('iq', [ 'xmlns' => 'urn:xmpp:whatsapp:account', 'id' => $msgId, 'type' => 'get', 'to' => 'c.us', ], [$modifyNode], null); $this->sendNode($iqNode); }
php
public function sendChangeNumber($number, $identity) { $msgId = $this->createIqId(); $usernameNode = new ProtocolNode('username', null, null, $number); $passwordNode = new ProtocolNode('password', null, null, urldecode($identity)); $modifyNode = new ProtocolNode('modify', null, [$usernameNode, $passwordNode], null); $iqNode = new ProtocolNode('iq', [ 'xmlns' => 'urn:xmpp:whatsapp:account', 'id' => $msgId, 'type' => 'get', 'to' => 'c.us', ], [$modifyNode], null); $this->sendNode($iqNode); }
[ "public", "function", "sendChangeNumber", "(", "$", "number", ",", "$", "identity", ")", "{", "$", "msgId", "=", "$", "this", "->", "createIqId", "(", ")", ";", "$", "usernameNode", "=", "new", "ProtocolNode", "(", "'username'", ",", "null", ",", "null", ",", "$", "number", ")", ";", "$", "passwordNode", "=", "new", "ProtocolNode", "(", "'password'", ",", "null", ",", "null", ",", "urldecode", "(", "$", "identity", ")", ")", ";", "$", "modifyNode", "=", "new", "ProtocolNode", "(", "'modify'", ",", "null", ",", "[", "$", "usernameNode", ",", "$", "passwordNode", "]", ",", "null", ")", ";", "$", "iqNode", "=", "new", "ProtocolNode", "(", "'iq'", ",", "[", "'xmlns'", "=>", "'urn:xmpp:whatsapp:account'", ",", "'id'", "=>", "$", "msgId", ",", "'type'", "=>", "'get'", ",", "'to'", "=>", "'c.us'", ",", "]", ",", "[", "$", "modifyNode", "]", ",", "null", ")", ";", "$", "this", "->", "sendNode", "(", "$", "iqNode", ")", ";", "}" ]
Transfer your number to new one. @param string $number @param string $identity
[ "Transfer", "your", "number", "to", "new", "one", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L733-L751
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendGetGroupV2Info
public function sendGetGroupV2Info($groupID) { $msgId = $this->nodeId['get_groupv2_info'] = $this->createIqId(); $queryNode = new ProtocolNode('query', [ 'request' => 'interactive', ], null, null); $node = new ProtocolNode('iq', [ 'id' => $msgId, 'xmlns' => 'w:g2', 'type' => 'get', 'to' => $this->getJID($groupID), ], [$queryNode], null); $this->sendNode($node); }
php
public function sendGetGroupV2Info($groupID) { $msgId = $this->nodeId['get_groupv2_info'] = $this->createIqId(); $queryNode = new ProtocolNode('query', [ 'request' => 'interactive', ], null, null); $node = new ProtocolNode('iq', [ 'id' => $msgId, 'xmlns' => 'w:g2', 'type' => 'get', 'to' => $this->getJID($groupID), ], [$queryNode], null); $this->sendNode($node); }
[ "public", "function", "sendGetGroupV2Info", "(", "$", "groupID", ")", "{", "$", "msgId", "=", "$", "this", "->", "nodeId", "[", "'get_groupv2_info'", "]", "=", "$", "this", "->", "createIqId", "(", ")", ";", "$", "queryNode", "=", "new", "ProtocolNode", "(", "'query'", ",", "[", "'request'", "=>", "'interactive'", ",", "]", ",", "null", ",", "null", ")", ";", "$", "node", "=", "new", "ProtocolNode", "(", "'iq'", ",", "[", "'id'", "=>", "$", "msgId", ",", "'xmlns'", "=>", "'w:g2'", ",", "'type'", "=>", "'get'", ",", "'to'", "=>", "$", "this", "->", "getJID", "(", "$", "groupID", ")", ",", "]", ",", "[", "$", "queryNode", "]", ",", "null", ")", ";", "$", "this", "->", "sendNode", "(", "$", "node", ")", ";", "}" ]
Send a request to get new Groups V2 info. @param $groupID The group JID
[ "Send", "a", "request", "to", "get", "new", "Groups", "V2", "info", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L769-L787
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendGetPrivacyBlockedList
public function sendGetPrivacyBlockedList() { $msgId = $this->nodeId['privacy'] = $this->createIqId(); $child = new ProtocolNode('list', [ 'name' => 'default', ], null, null); $child2 = new ProtocolNode('query', [], [$child], null); $node = new ProtocolNode('iq', [ 'id' => $msgId, 'xmlns' => 'jabber:iq:privacy', 'type' => 'get', ], [$child2], null); $this->sendNode($node); }
php
public function sendGetPrivacyBlockedList() { $msgId = $this->nodeId['privacy'] = $this->createIqId(); $child = new ProtocolNode('list', [ 'name' => 'default', ], null, null); $child2 = new ProtocolNode('query', [], [$child], null); $node = new ProtocolNode('iq', [ 'id' => $msgId, 'xmlns' => 'jabber:iq:privacy', 'type' => 'get', ], [$child2], null); $this->sendNode($node); }
[ "public", "function", "sendGetPrivacyBlockedList", "(", ")", "{", "$", "msgId", "=", "$", "this", "->", "nodeId", "[", "'privacy'", "]", "=", "$", "this", "->", "createIqId", "(", ")", ";", "$", "child", "=", "new", "ProtocolNode", "(", "'list'", ",", "[", "'name'", "=>", "'default'", ",", "]", ",", "null", ",", "null", ")", ";", "$", "child2", "=", "new", "ProtocolNode", "(", "'query'", ",", "[", "]", ",", "[", "$", "child", "]", ",", "null", ")", ";", "$", "node", "=", "new", "ProtocolNode", "(", "'iq'", ",", "[", "'id'", "=>", "$", "msgId", ",", "'xmlns'", "=>", "'jabber:iq:privacy'", ",", "'type'", "=>", "'get'", ",", "]", ",", "[", "$", "child2", "]", ",", "null", ")", ";", "$", "this", "->", "sendNode", "(", "$", "node", ")", ";", "}" ]
Send a request to get a list of people you have currently blocked.
[ "Send", "a", "request", "to", "get", "a", "list", "of", "people", "you", "have", "currently", "blocked", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L792-L809
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendGetPrivacySettings
public function sendGetPrivacySettings() { $msgId = $this->nodeId['privacy_settings'] = $this->createIqId(); $privacyNode = new ProtocolNode('privacy', null, null, null); $node = new ProtocolNode('iq', [ 'to' => Constants::WHATSAPP_SERVER, 'id' => $msgId, 'xmlns' => 'privacy', 'type' => 'get', ], [$privacyNode], null); $this->sendNode($node); }
php
public function sendGetPrivacySettings() { $msgId = $this->nodeId['privacy_settings'] = $this->createIqId(); $privacyNode = new ProtocolNode('privacy', null, null, null); $node = new ProtocolNode('iq', [ 'to' => Constants::WHATSAPP_SERVER, 'id' => $msgId, 'xmlns' => 'privacy', 'type' => 'get', ], [$privacyNode], null); $this->sendNode($node); }
[ "public", "function", "sendGetPrivacySettings", "(", ")", "{", "$", "msgId", "=", "$", "this", "->", "nodeId", "[", "'privacy_settings'", "]", "=", "$", "this", "->", "createIqId", "(", ")", ";", "$", "privacyNode", "=", "new", "ProtocolNode", "(", "'privacy'", ",", "null", ",", "null", ",", "null", ")", ";", "$", "node", "=", "new", "ProtocolNode", "(", "'iq'", ",", "[", "'to'", "=>", "Constants", "::", "WHATSAPP_SERVER", ",", "'id'", "=>", "$", "msgId", ",", "'xmlns'", "=>", "'privacy'", ",", "'type'", "=>", "'get'", ",", "]", ",", "[", "$", "privacyNode", "]", ",", "null", ")", ";", "$", "this", "->", "sendNode", "(", "$", "node", ")", ";", "}" ]
Send a request to get privacy settings.
[ "Send", "a", "request", "to", "get", "privacy", "settings", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L814-L827
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendSetPrivacySettings
public function sendSetPrivacySettings($category, $value) { $msgId = $this->createIqId(); $categoryNode = new ProtocolNode('category', [ 'name' => $category, 'value' => $value, ], null, null); $privacyNode = new ProtocolNode('privacy', null, [$categoryNode], null); $node = new ProtocolNode('iq', [ 'to' => Constants::WHATSAPP_SERVER, 'type' => 'set', 'id' => $msgId, 'xmlns' => 'privacy', ], [$privacyNode], null); $this->sendNode($node); }
php
public function sendSetPrivacySettings($category, $value) { $msgId = $this->createIqId(); $categoryNode = new ProtocolNode('category', [ 'name' => $category, 'value' => $value, ], null, null); $privacyNode = new ProtocolNode('privacy', null, [$categoryNode], null); $node = new ProtocolNode('iq', [ 'to' => Constants::WHATSAPP_SERVER, 'type' => 'set', 'id' => $msgId, 'xmlns' => 'privacy', ], [$privacyNode], null); $this->sendNode($node); }
[ "public", "function", "sendSetPrivacySettings", "(", "$", "category", ",", "$", "value", ")", "{", "$", "msgId", "=", "$", "this", "->", "createIqId", "(", ")", ";", "$", "categoryNode", "=", "new", "ProtocolNode", "(", "'category'", ",", "[", "'name'", "=>", "$", "category", ",", "'value'", "=>", "$", "value", ",", "]", ",", "null", ",", "null", ")", ";", "$", "privacyNode", "=", "new", "ProtocolNode", "(", "'privacy'", ",", "null", ",", "[", "$", "categoryNode", "]", ",", "null", ")", ";", "$", "node", "=", "new", "ProtocolNode", "(", "'iq'", ",", "[", "'to'", "=>", "Constants", "::", "WHATSAPP_SERVER", ",", "'type'", "=>", "'set'", ",", "'id'", "=>", "$", "msgId", ",", "'xmlns'", "=>", "'privacy'", ",", "]", ",", "[", "$", "privacyNode", "]", ",", "null", ")", ";", "$", "this", "->", "sendNode", "(", "$", "node", ")", ";", "}" ]
Set privacy of 'last seen', status or profile picture to all, contacts or none. @param string $category Options: 'last', 'status' or 'profile' @param string $value Options: 'all', 'contacts' or 'none'
[ "Set", "privacy", "of", "last", "seen", "status", "or", "profile", "picture", "to", "all", "contacts", "or", "none", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L837-L856
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendGetProfilePicture
public function sendGetProfilePicture($number, $large = false) { $msgId = $this->nodeId['getprofilepic'] = $this->createIqId(); $hash = []; $hash['type'] = 'image'; if (!$large) { $hash['type'] = 'preview'; } $picture = new ProtocolNode('picture', $hash, null, null); $node = new ProtocolNode('iq', [ 'id' => $msgId, 'type' => 'get', 'xmlns' => 'w:profile:picture', 'to' => $this->getJID($number), ], [$picture], null); $this->sendNode($node); }
php
public function sendGetProfilePicture($number, $large = false) { $msgId = $this->nodeId['getprofilepic'] = $this->createIqId(); $hash = []; $hash['type'] = 'image'; if (!$large) { $hash['type'] = 'preview'; } $picture = new ProtocolNode('picture', $hash, null, null); $node = new ProtocolNode('iq', [ 'id' => $msgId, 'type' => 'get', 'xmlns' => 'w:profile:picture', 'to' => $this->getJID($number), ], [$picture], null); $this->sendNode($node); }
[ "public", "function", "sendGetProfilePicture", "(", "$", "number", ",", "$", "large", "=", "false", ")", "{", "$", "msgId", "=", "$", "this", "->", "nodeId", "[", "'getprofilepic'", "]", "=", "$", "this", "->", "createIqId", "(", ")", ";", "$", "hash", "=", "[", "]", ";", "$", "hash", "[", "'type'", "]", "=", "'image'", ";", "if", "(", "!", "$", "large", ")", "{", "$", "hash", "[", "'type'", "]", "=", "'preview'", ";", "}", "$", "picture", "=", "new", "ProtocolNode", "(", "'picture'", ",", "$", "hash", ",", "null", ",", "null", ")", ";", "$", "node", "=", "new", "ProtocolNode", "(", "'iq'", ",", "[", "'id'", "=>", "$", "msgId", ",", "'type'", "=>", "'get'", ",", "'xmlns'", "=>", "'w:profile:picture'", ",", "'to'", "=>", "$", "this", "->", "getJID", "(", "$", "number", ")", ",", "]", ",", "[", "$", "picture", "]", ",", "null", ")", ";", "$", "this", "->", "sendNode", "(", "$", "node", ")", ";", "}" ]
Get profile picture of specified user. @param string $number Number or JID of user @param bool $large Request large picture
[ "Get", "profile", "picture", "of", "specified", "user", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L866-L886
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendGetServerProperties
public function sendGetServerProperties() { $id = $this->createIqId(); $child = new ProtocolNode('props', null, null, null); $node = new ProtocolNode('iq', [ 'id' => $id, 'type' => 'get', 'xmlns' => 'w', 'to' => Constants::WHATSAPP_SERVER, ], [$child], null); $this->sendNode($node); }
php
public function sendGetServerProperties() { $id = $this->createIqId(); $child = new ProtocolNode('props', null, null, null); $node = new ProtocolNode('iq', [ 'id' => $id, 'type' => 'get', 'xmlns' => 'w', 'to' => Constants::WHATSAPP_SERVER, ], [$child], null); $this->sendNode($node); }
[ "public", "function", "sendGetServerProperties", "(", ")", "{", "$", "id", "=", "$", "this", "->", "createIqId", "(", ")", ";", "$", "child", "=", "new", "ProtocolNode", "(", "'props'", ",", "null", ",", "null", ",", "null", ")", ";", "$", "node", "=", "new", "ProtocolNode", "(", "'iq'", ",", "[", "'id'", "=>", "$", "id", ",", "'type'", "=>", "'get'", ",", "'xmlns'", "=>", "'w'", ",", "'to'", "=>", "Constants", "::", "WHATSAPP_SERVER", ",", "]", ",", "[", "$", "child", "]", ",", "null", ")", ";", "$", "this", "->", "sendNode", "(", "$", "node", ")", ";", "}" ]
Send a request to get the current server properties.
[ "Send", "a", "request", "to", "get", "the", "current", "server", "properties", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L930-L943
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendGetServicePricing
public function sendGetServicePricing($lg, $lc) { $msgId = $this->createIqId(); $pricingNode = new ProtocolNode('pricing', [ 'lg' => $lg, 'lc' => $lc, ], null, null); $node = new ProtocolNode('iq', [ 'id' => $msgId, 'xmlns' => 'urn:xmpp:whatsapp:account', 'type' => 'get', 'to' => Constants::WHATSAPP_SERVER, ], [$pricingNode], null); $this->sendNode($node); }
php
public function sendGetServicePricing($lg, $lc) { $msgId = $this->createIqId(); $pricingNode = new ProtocolNode('pricing', [ 'lg' => $lg, 'lc' => $lc, ], null, null); $node = new ProtocolNode('iq', [ 'id' => $msgId, 'xmlns' => 'urn:xmpp:whatsapp:account', 'type' => 'get', 'to' => Constants::WHATSAPP_SERVER, ], [$pricingNode], null); $this->sendNode($node); }
[ "public", "function", "sendGetServicePricing", "(", "$", "lg", ",", "$", "lc", ")", "{", "$", "msgId", "=", "$", "this", "->", "createIqId", "(", ")", ";", "$", "pricingNode", "=", "new", "ProtocolNode", "(", "'pricing'", ",", "[", "'lg'", "=>", "$", "lg", ",", "'lc'", "=>", "$", "lc", ",", "]", ",", "null", ",", "null", ")", ";", "$", "node", "=", "new", "ProtocolNode", "(", "'iq'", ",", "[", "'id'", "=>", "$", "msgId", ",", "'xmlns'", "=>", "'urn:xmpp:whatsapp:account'", ",", "'type'", "=>", "'get'", ",", "'to'", "=>", "Constants", "::", "WHATSAPP_SERVER", ",", "]", ",", "[", "$", "pricingNode", "]", ",", "null", ")", ";", "$", "this", "->", "sendNode", "(", "$", "node", ")", ";", "}" ]
Send a request to get the current service pricing. @param string $lg Language @param string $lc Country
[ "Send", "a", "request", "to", "get", "the", "current", "service", "pricing", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L953-L970
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendExtendAccount
public function sendExtendAccount() { $msgId = $this->createIqId(); $extendingNode = new ProtocolNode('extend', null, null, null); $node = new ProtocolNode('iq', [ 'id' => $msgId, 'xmlns' => 'urn:xmpp:whatsapp:account', 'type' => 'set', 'to' => Constants::WHATSAPP_SERVER, ], [$extendingNode], null); $this->sendNode($node); }
php
public function sendExtendAccount() { $msgId = $this->createIqId(); $extendingNode = new ProtocolNode('extend', null, null, null); $node = new ProtocolNode('iq', [ 'id' => $msgId, 'xmlns' => 'urn:xmpp:whatsapp:account', 'type' => 'set', 'to' => Constants::WHATSAPP_SERVER, ], [$extendingNode], null); $this->sendNode($node); }
[ "public", "function", "sendExtendAccount", "(", ")", "{", "$", "msgId", "=", "$", "this", "->", "createIqId", "(", ")", ";", "$", "extendingNode", "=", "new", "ProtocolNode", "(", "'extend'", ",", "null", ",", "null", ",", "null", ")", ";", "$", "node", "=", "new", "ProtocolNode", "(", "'iq'", ",", "[", "'id'", "=>", "$", "msgId", ",", "'xmlns'", "=>", "'urn:xmpp:whatsapp:account'", ",", "'type'", "=>", "'set'", ",", "'to'", "=>", "Constants", "::", "WHATSAPP_SERVER", ",", "]", ",", "[", "$", "extendingNode", "]", ",", "null", ")", ";", "$", "this", "->", "sendNode", "(", "$", "node", ")", ";", "}" ]
Send a request to extend the account.
[ "Send", "a", "request", "to", "extend", "the", "account", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L975-L988
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendGetBroadcastLists
public function sendGetBroadcastLists() { $msgId = $this->nodeId['get_lists'] = $this->createIqId(); $listsNode = new ProtocolNode('lists', null, null, null); $node = new ProtocolNode('iq', [ 'id' => $msgId, 'xmlns' => 'w:b', 'type' => 'get', 'to' => Constants::WHATSAPP_SERVER, ], [$listsNode], null); $this->sendNode($node); }
php
public function sendGetBroadcastLists() { $msgId = $this->nodeId['get_lists'] = $this->createIqId(); $listsNode = new ProtocolNode('lists', null, null, null); $node = new ProtocolNode('iq', [ 'id' => $msgId, 'xmlns' => 'w:b', 'type' => 'get', 'to' => Constants::WHATSAPP_SERVER, ], [$listsNode], null); $this->sendNode($node); }
[ "public", "function", "sendGetBroadcastLists", "(", ")", "{", "$", "msgId", "=", "$", "this", "->", "nodeId", "[", "'get_lists'", "]", "=", "$", "this", "->", "createIqId", "(", ")", ";", "$", "listsNode", "=", "new", "ProtocolNode", "(", "'lists'", ",", "null", ",", "null", ",", "null", ")", ";", "$", "node", "=", "new", "ProtocolNode", "(", "'iq'", ",", "[", "'id'", "=>", "$", "msgId", ",", "'xmlns'", "=>", "'w:b'", ",", "'type'", "=>", "'get'", ",", "'to'", "=>", "Constants", "::", "WHATSAPP_SERVER", ",", "]", ",", "[", "$", "listsNode", "]", ",", "null", ")", ";", "$", "this", "->", "sendNode", "(", "$", "node", ")", ";", "}" ]
Gets all the broadcast lists for an account.
[ "Gets", "all", "the", "broadcast", "lists", "for", "an", "account", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L993-L1006
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendGetNormalizedJid
public function sendGetNormalizedJid($countryCode, $number) { $msgId = $this->createIqId(); $ccNode = new ProtocolNode('cc', null, null, $countryCode); $inNode = new ProtocolNode('in', null, null, $number); $normalizeNode = new ProtocolNode('normalize', null, [$ccNode, $inNode], null); $node = new ProtocolNode('iq', [ 'id' => $msgId, 'xmlns' => 'urn:xmpp:whatsapp:account', 'type' => 'get', 'to' => Constants::WHATSAPP_SERVER, ], [$normalizeNode], null); $this->sendNode($node); }
php
public function sendGetNormalizedJid($countryCode, $number) { $msgId = $this->createIqId(); $ccNode = new ProtocolNode('cc', null, null, $countryCode); $inNode = new ProtocolNode('in', null, null, $number); $normalizeNode = new ProtocolNode('normalize', null, [$ccNode, $inNode], null); $node = new ProtocolNode('iq', [ 'id' => $msgId, 'xmlns' => 'urn:xmpp:whatsapp:account', 'type' => 'get', 'to' => Constants::WHATSAPP_SERVER, ], [$normalizeNode], null); $this->sendNode($node); }
[ "public", "function", "sendGetNormalizedJid", "(", "$", "countryCode", ",", "$", "number", ")", "{", "$", "msgId", "=", "$", "this", "->", "createIqId", "(", ")", ";", "$", "ccNode", "=", "new", "ProtocolNode", "(", "'cc'", ",", "null", ",", "null", ",", "$", "countryCode", ")", ";", "$", "inNode", "=", "new", "ProtocolNode", "(", "'in'", ",", "null", ",", "null", ",", "$", "number", ")", ";", "$", "normalizeNode", "=", "new", "ProtocolNode", "(", "'normalize'", ",", "null", ",", "[", "$", "ccNode", ",", "$", "inNode", "]", ",", "null", ")", ";", "$", "node", "=", "new", "ProtocolNode", "(", "'iq'", ",", "[", "'id'", "=>", "$", "msgId", ",", "'xmlns'", "=>", "'urn:xmpp:whatsapp:account'", ",", "'type'", "=>", "'get'", ",", "'to'", "=>", "Constants", "::", "WHATSAPP_SERVER", ",", "]", ",", "[", "$", "normalizeNode", "]", ",", "null", ")", ";", "$", "this", "->", "sendNode", "(", "$", "node", ")", ";", "}" ]
Send a request to get the normalized mobile number representing the JID. @param string $countryCode Country Code @param string $number Mobile Number
[ "Send", "a", "request", "to", "get", "the", "normalized", "mobile", "number", "representing", "the", "JID", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L1014-L1029
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendRemoveAccount
public function sendRemoveAccount($lg = null, $lc = null, $feedback = null) { $msgId = $this->createIqId(); if ($feedback != null && strlen($feedback) > 0) { if ($lg == null) { $lg = ''; } if ($lc == null) { $lc = ''; } $child = new ProtocolNode('body', [ 'lg' => $lg, 'lc' => $lc, ], null, $feedback); $childNode = [$child]; } else { $childNode = null; } $removeNode = new ProtocolNode('remove', null, $childNode, null); $node = new ProtocolNode('iq', [ 'to' => Constants::WHATSAPP_SERVER, 'xmlns' => 'urn:xmpp:whatsapp:account', 'type' => 'get', 'id' => $msgId, ], [$removeNode], null); $this->sendNode($node); $this->waitForServer($msgId); }
php
public function sendRemoveAccount($lg = null, $lc = null, $feedback = null) { $msgId = $this->createIqId(); if ($feedback != null && strlen($feedback) > 0) { if ($lg == null) { $lg = ''; } if ($lc == null) { $lc = ''; } $child = new ProtocolNode('body', [ 'lg' => $lg, 'lc' => $lc, ], null, $feedback); $childNode = [$child]; } else { $childNode = null; } $removeNode = new ProtocolNode('remove', null, $childNode, null); $node = new ProtocolNode('iq', [ 'to' => Constants::WHATSAPP_SERVER, 'xmlns' => 'urn:xmpp:whatsapp:account', 'type' => 'get', 'id' => $msgId, ], [$removeNode], null); $this->sendNode($node); $this->waitForServer($msgId); }
[ "public", "function", "sendRemoveAccount", "(", "$", "lg", "=", "null", ",", "$", "lc", "=", "null", ",", "$", "feedback", "=", "null", ")", "{", "$", "msgId", "=", "$", "this", "->", "createIqId", "(", ")", ";", "if", "(", "$", "feedback", "!=", "null", "&&", "strlen", "(", "$", "feedback", ")", ">", "0", ")", "{", "if", "(", "$", "lg", "==", "null", ")", "{", "$", "lg", "=", "''", ";", "}", "if", "(", "$", "lc", "==", "null", ")", "{", "$", "lc", "=", "''", ";", "}", "$", "child", "=", "new", "ProtocolNode", "(", "'body'", ",", "[", "'lg'", "=>", "$", "lg", ",", "'lc'", "=>", "$", "lc", ",", "]", ",", "null", ",", "$", "feedback", ")", ";", "$", "childNode", "=", "[", "$", "child", "]", ";", "}", "else", "{", "$", "childNode", "=", "null", ";", "}", "$", "removeNode", "=", "new", "ProtocolNode", "(", "'remove'", ",", "null", ",", "$", "childNode", ",", "null", ")", ";", "$", "node", "=", "new", "ProtocolNode", "(", "'iq'", ",", "[", "'to'", "=>", "Constants", "::", "WHATSAPP_SERVER", ",", "'xmlns'", "=>", "'urn:xmpp:whatsapp:account'", ",", "'type'", "=>", "'get'", ",", "'id'", "=>", "$", "msgId", ",", "]", ",", "[", "$", "removeNode", "]", ",", "null", ")", ";", "$", "this", "->", "sendNode", "(", "$", "node", ")", ";", "$", "this", "->", "waitForServer", "(", "$", "msgId", ")", ";", "}" ]
Removes an account from WhatsApp. @param string $lg Language @param string $lc Country @param string $feedback User Feedback
[ "Removes", "an", "account", "from", "WhatsApp", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L1038-L1071
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendPing
public function sendPing() { $msgId = $this->createIqId(); $pingNode = new ProtocolNode('ping', null, null, null); $node = new ProtocolNode('iq', [ 'id' => $msgId, 'xmlns' => 'w:p', 'type' => 'get', 'to' => Constants::WHATSAPP_SERVER, ], [$pingNode], null); $this->sendNode($node); }
php
public function sendPing() { $msgId = $this->createIqId(); $pingNode = new ProtocolNode('ping', null, null, null); $node = new ProtocolNode('iq', [ 'id' => $msgId, 'xmlns' => 'w:p', 'type' => 'get', 'to' => Constants::WHATSAPP_SERVER, ], [$pingNode], null); $this->sendNode($node); }
[ "public", "function", "sendPing", "(", ")", "{", "$", "msgId", "=", "$", "this", "->", "createIqId", "(", ")", ";", "$", "pingNode", "=", "new", "ProtocolNode", "(", "'ping'", ",", "null", ",", "null", ",", "null", ")", ";", "$", "node", "=", "new", "ProtocolNode", "(", "'iq'", ",", "[", "'id'", "=>", "$", "msgId", ",", "'xmlns'", "=>", "'w:p'", ",", "'type'", "=>", "'get'", ",", "'to'", "=>", "Constants", "::", "WHATSAPP_SERVER", ",", "]", ",", "[", "$", "pingNode", "]", ",", "null", ")", ";", "$", "this", "->", "sendNode", "(", "$", "node", ")", ";", "}" ]
Send a ping to the server.
[ "Send", "a", "ping", "to", "the", "server", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L1076-L1089
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendGetStatuses
public function sendGetStatuses($jids) { if (!is_array($jids)) { $jids = [$jids]; } $children = []; foreach ($jids as $jid) { $children[] = new ProtocolNode('user', ['jid' => $this->getJID($jid)], null, null); } $iqId = $this->nodeId['getstatuses'] = $this->createIqId(); $node = new ProtocolNode('iq', [ 'to' => Constants::WHATSAPP_SERVER, 'type' => 'get', 'xmlns' => 'status', 'id' => $iqId, ], [ new ProtocolNode('status', null, $children, null), ], null); $this->sendNode($node); }
php
public function sendGetStatuses($jids) { if (!is_array($jids)) { $jids = [$jids]; } $children = []; foreach ($jids as $jid) { $children[] = new ProtocolNode('user', ['jid' => $this->getJID($jid)], null, null); } $iqId = $this->nodeId['getstatuses'] = $this->createIqId(); $node = new ProtocolNode('iq', [ 'to' => Constants::WHATSAPP_SERVER, 'type' => 'get', 'xmlns' => 'status', 'id' => $iqId, ], [ new ProtocolNode('status', null, $children, null), ], null); $this->sendNode($node); }
[ "public", "function", "sendGetStatuses", "(", "$", "jids", ")", "{", "if", "(", "!", "is_array", "(", "$", "jids", ")", ")", "{", "$", "jids", "=", "[", "$", "jids", "]", ";", "}", "$", "children", "=", "[", "]", ";", "foreach", "(", "$", "jids", "as", "$", "jid", ")", "{", "$", "children", "[", "]", "=", "new", "ProtocolNode", "(", "'user'", ",", "[", "'jid'", "=>", "$", "this", "->", "getJID", "(", "$", "jid", ")", "]", ",", "null", ",", "null", ")", ";", "}", "$", "iqId", "=", "$", "this", "->", "nodeId", "[", "'getstatuses'", "]", "=", "$", "this", "->", "createIqId", "(", ")", ";", "$", "node", "=", "new", "ProtocolNode", "(", "'iq'", ",", "[", "'to'", "=>", "Constants", "::", "WHATSAPP_SERVER", ",", "'type'", "=>", "'get'", ",", "'xmlns'", "=>", "'status'", ",", "'id'", "=>", "$", "iqId", ",", "]", ",", "[", "new", "ProtocolNode", "(", "'status'", ",", "null", ",", "$", "children", ",", "null", ")", ",", "]", ",", "null", ")", ";", "$", "this", "->", "sendNode", "(", "$", "node", ")", ";", "}" ]
Get the current status message of a specific user. @param mixed $jids The users' JIDs
[ "Get", "the", "current", "status", "message", "of", "a", "specific", "user", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L1096-L1120
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendGroupsChatCreate
public function sendGroupsChatCreate($subject, $participants) { if (!is_array($participants)) { $participants = [$participants]; } $participantNode = []; foreach ($participants as $participant) { $participantNode[] = new ProtocolNode('participant', [ 'jid' => $this->getJID($participant), ], null, null); } $id = $this->nodeId['groupcreate'] = $this->createIqId(); $createNode = new ProtocolNode('create', [ 'subject' => $subject, ], $participantNode, null); $iqNode = new ProtocolNode('iq', [ 'xmlns' => 'w:g2', 'id' => $id, 'type' => 'set', 'to' => Constants::WHATSAPP_GROUP_SERVER, ], [$createNode], null); $this->sendNode($iqNode); $this->waitForServer($id); $groupId = $this->groupId; $this->eventManager()->fire('onGroupCreate', [ $this->phoneNumber, $groupId, ]); return $groupId; }
php
public function sendGroupsChatCreate($subject, $participants) { if (!is_array($participants)) { $participants = [$participants]; } $participantNode = []; foreach ($participants as $participant) { $participantNode[] = new ProtocolNode('participant', [ 'jid' => $this->getJID($participant), ], null, null); } $id = $this->nodeId['groupcreate'] = $this->createIqId(); $createNode = new ProtocolNode('create', [ 'subject' => $subject, ], $participantNode, null); $iqNode = new ProtocolNode('iq', [ 'xmlns' => 'w:g2', 'id' => $id, 'type' => 'set', 'to' => Constants::WHATSAPP_GROUP_SERVER, ], [$createNode], null); $this->sendNode($iqNode); $this->waitForServer($id); $groupId = $this->groupId; $this->eventManager()->fire('onGroupCreate', [ $this->phoneNumber, $groupId, ]); return $groupId; }
[ "public", "function", "sendGroupsChatCreate", "(", "$", "subject", ",", "$", "participants", ")", "{", "if", "(", "!", "is_array", "(", "$", "participants", ")", ")", "{", "$", "participants", "=", "[", "$", "participants", "]", ";", "}", "$", "participantNode", "=", "[", "]", ";", "foreach", "(", "$", "participants", "as", "$", "participant", ")", "{", "$", "participantNode", "[", "]", "=", "new", "ProtocolNode", "(", "'participant'", ",", "[", "'jid'", "=>", "$", "this", "->", "getJID", "(", "$", "participant", ")", ",", "]", ",", "null", ",", "null", ")", ";", "}", "$", "id", "=", "$", "this", "->", "nodeId", "[", "'groupcreate'", "]", "=", "$", "this", "->", "createIqId", "(", ")", ";", "$", "createNode", "=", "new", "ProtocolNode", "(", "'create'", ",", "[", "'subject'", "=>", "$", "subject", ",", "]", ",", "$", "participantNode", ",", "null", ")", ";", "$", "iqNode", "=", "new", "ProtocolNode", "(", "'iq'", ",", "[", "'xmlns'", "=>", "'w:g2'", ",", "'id'", "=>", "$", "id", ",", "'type'", "=>", "'set'", ",", "'to'", "=>", "Constants", "::", "WHATSAPP_GROUP_SERVER", ",", "]", ",", "[", "$", "createNode", "]", ",", "null", ")", ";", "$", "this", "->", "sendNode", "(", "$", "iqNode", ")", ";", "$", "this", "->", "waitForServer", "(", "$", "id", ")", ";", "$", "groupId", "=", "$", "this", "->", "groupId", ";", "$", "this", "->", "eventManager", "(", ")", "->", "fire", "(", "'onGroupCreate'", ",", "[", "$", "this", "->", "phoneNumber", ",", "$", "groupId", ",", "]", ")", ";", "return", "$", "groupId", ";", "}" ]
Create a group chat. @param string $subject The group Subject @param array $participants An array with the participants numbers. @return string The group ID.
[ "Create", "a", "group", "chat", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L1133-L1172
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendSetGroupSubject
public function sendSetGroupSubject($gjid, $subject) { $child = new ProtocolNode('subject', null, null, $subject); $node = new ProtocolNode('iq', [ 'id' => $this->createIqId(), 'type' => 'set', 'to' => $this->getJID($gjid), 'xmlns' => 'w:g2', ], [$child], null); $this->sendNode($node); }
php
public function sendSetGroupSubject($gjid, $subject) { $child = new ProtocolNode('subject', null, null, $subject); $node = new ProtocolNode('iq', [ 'id' => $this->createIqId(), 'type' => 'set', 'to' => $this->getJID($gjid), 'xmlns' => 'w:g2', ], [$child], null); $this->sendNode($node); }
[ "public", "function", "sendSetGroupSubject", "(", "$", "gjid", ",", "$", "subject", ")", "{", "$", "child", "=", "new", "ProtocolNode", "(", "'subject'", ",", "null", ",", "null", ",", "$", "subject", ")", ";", "$", "node", "=", "new", "ProtocolNode", "(", "'iq'", ",", "[", "'id'", "=>", "$", "this", "->", "createIqId", "(", ")", ",", "'type'", "=>", "'set'", ",", "'to'", "=>", "$", "this", "->", "getJID", "(", "$", "gjid", ")", ",", "'xmlns'", "=>", "'w:g2'", ",", "]", ",", "[", "$", "child", "]", ",", "null", ")", ";", "$", "this", "->", "sendNode", "(", "$", "node", ")", ";", "}" ]
Change group's subject. @param string $gjid The group id @param string $subject The subject
[ "Change", "group", "s", "subject", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L1180-L1192
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendGroupsLeave
public function sendGroupsLeave($gjids) { $msgId = $this->nodeId['leavegroup'] = $this->createIqId(); if (!is_array($gjids)) { $gjids = [$this->getJID($gjids)]; } $nodes = []; foreach ($gjids as $gjid) { $nodes[] = new ProtocolNode('group', [ 'id' => $this->getJID($gjid), ], null, null); } $leave = new ProtocolNode('leave', [ 'action' => 'delete', ], $nodes, null); $node = new ProtocolNode('iq', [ 'id' => $msgId, 'to' => Constants::WHATSAPP_GROUP_SERVER, 'type' => 'set', 'xmlns' => 'w:g2', ], [$leave], null); $this->sendNode($node); }
php
public function sendGroupsLeave($gjids) { $msgId = $this->nodeId['leavegroup'] = $this->createIqId(); if (!is_array($gjids)) { $gjids = [$this->getJID($gjids)]; } $nodes = []; foreach ($gjids as $gjid) { $nodes[] = new ProtocolNode('group', [ 'id' => $this->getJID($gjid), ], null, null); } $leave = new ProtocolNode('leave', [ 'action' => 'delete', ], $nodes, null); $node = new ProtocolNode('iq', [ 'id' => $msgId, 'to' => Constants::WHATSAPP_GROUP_SERVER, 'type' => 'set', 'xmlns' => 'w:g2', ], [$leave], null); $this->sendNode($node); }
[ "public", "function", "sendGroupsLeave", "(", "$", "gjids", ")", "{", "$", "msgId", "=", "$", "this", "->", "nodeId", "[", "'leavegroup'", "]", "=", "$", "this", "->", "createIqId", "(", ")", ";", "if", "(", "!", "is_array", "(", "$", "gjids", ")", ")", "{", "$", "gjids", "=", "[", "$", "this", "->", "getJID", "(", "$", "gjids", ")", "]", ";", "}", "$", "nodes", "=", "[", "]", ";", "foreach", "(", "$", "gjids", "as", "$", "gjid", ")", "{", "$", "nodes", "[", "]", "=", "new", "ProtocolNode", "(", "'group'", ",", "[", "'id'", "=>", "$", "this", "->", "getJID", "(", "$", "gjid", ")", ",", "]", ",", "null", ",", "null", ")", ";", "}", "$", "leave", "=", "new", "ProtocolNode", "(", "'leave'", ",", "[", "'action'", "=>", "'delete'", ",", "]", ",", "$", "nodes", ",", "null", ")", ";", "$", "node", "=", "new", "ProtocolNode", "(", "'iq'", ",", "[", "'id'", "=>", "$", "msgId", ",", "'to'", "=>", "Constants", "::", "WHATSAPP_GROUP_SERVER", ",", "'type'", "=>", "'set'", ",", "'xmlns'", "=>", "'w:g2'", ",", "]", ",", "[", "$", "leave", "]", ",", "null", ")", ";", "$", "this", "->", "sendNode", "(", "$", "node", ")", ";", "}" ]
Leave a group chat. @param mixed $gjids Group or group's ID(s)
[ "Leave", "a", "group", "chat", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L1199-L1229
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendGroupsParticipantsRemove
public function sendGroupsParticipantsRemove($groupId, $participant) { $msgId = $this->createMsgId(); $this->sendGroupsChangeParticipants($groupId, $participant, 'remove', $msgId); }
php
public function sendGroupsParticipantsRemove($groupId, $participant) { $msgId = $this->createMsgId(); $this->sendGroupsChangeParticipants($groupId, $participant, 'remove', $msgId); }
[ "public", "function", "sendGroupsParticipantsRemove", "(", "$", "groupId", ",", "$", "participant", ")", "{", "$", "msgId", "=", "$", "this", "->", "createMsgId", "(", ")", ";", "$", "this", "->", "sendGroupsChangeParticipants", "(", "$", "groupId", ",", "$", "participant", ",", "'remove'", ",", "$", "msgId", ")", ";", "}" ]
Remove participant from a group. @param string $groupId The group ID. @param string $participant The number of the participant you want to remove
[ "Remove", "participant", "from", "a", "group", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L1249-L1253
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendPromoteParticipants
public function sendPromoteParticipants($gId, $participant) { $msgId = $this->createMsgId(); $this->sendGroupsChangeParticipants($gId, $participant, 'promote', $msgId); }
php
public function sendPromoteParticipants($gId, $participant) { $msgId = $this->createMsgId(); $this->sendGroupsChangeParticipants($gId, $participant, 'promote', $msgId); }
[ "public", "function", "sendPromoteParticipants", "(", "$", "gId", ",", "$", "participant", ")", "{", "$", "msgId", "=", "$", "this", "->", "createMsgId", "(", ")", ";", "$", "this", "->", "sendGroupsChangeParticipants", "(", "$", "gId", ",", "$", "participant", ",", "'promote'", ",", "$", "msgId", ")", ";", "}" ]
Promote participant of a group; Make a participant an admin of a group. @param string $gId The group ID. @param string $participant The number of the participant you want to promote
[ "Promote", "participant", "of", "a", "group", ";", "Make", "a", "participant", "an", "admin", "of", "a", "group", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L1261-L1265
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendDemoteParticipants
public function sendDemoteParticipants($gId, $participant) { $msgId = $this->createMsgId(); $this->sendGroupsChangeParticipants($gId, $participant, 'demote', $msgId); }
php
public function sendDemoteParticipants($gId, $participant) { $msgId = $this->createMsgId(); $this->sendGroupsChangeParticipants($gId, $participant, 'demote', $msgId); }
[ "public", "function", "sendDemoteParticipants", "(", "$", "gId", ",", "$", "participant", ")", "{", "$", "msgId", "=", "$", "this", "->", "createMsgId", "(", ")", ";", "$", "this", "->", "sendGroupsChangeParticipants", "(", "$", "gId", ",", "$", "participant", ",", "'demote'", ",", "$", "msgId", ")", ";", "}" ]
Demote participant of a group; remove participant of being admin of a group. @param string $gId The group ID. @param string $participant The number of the participant you want to demote
[ "Demote", "participant", "of", "a", "group", ";", "remove", "participant", "of", "being", "admin", "of", "a", "group", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L1273-L1277
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendNextMessage
public function sendNextMessage() { if (count($this->outQueue) > 0) { $msgnode = array_shift($this->outQueue); $msgnode->refreshTimes(); $this->lastId = $msgnode->getAttribute('id'); $this->sendNode($msgnode); } else { $this->lastId = false; } }
php
public function sendNextMessage() { if (count($this->outQueue) > 0) { $msgnode = array_shift($this->outQueue); $msgnode->refreshTimes(); $this->lastId = $msgnode->getAttribute('id'); $this->sendNode($msgnode); } else { $this->lastId = false; } }
[ "public", "function", "sendNextMessage", "(", ")", "{", "if", "(", "count", "(", "$", "this", "->", "outQueue", ")", ">", "0", ")", "{", "$", "msgnode", "=", "array_shift", "(", "$", "this", "->", "outQueue", ")", ";", "$", "msgnode", "->", "refreshTimes", "(", ")", ";", "$", "this", "->", "lastId", "=", "$", "msgnode", "->", "getAttribute", "(", "'id'", ")", ";", "$", "this", "->", "sendNode", "(", "$", "msgnode", ")", ";", "}", "else", "{", "$", "this", "->", "lastId", "=", "false", ";", "}", "}" ]
Send the next message.
[ "Send", "the", "next", "message", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L1491-L1501
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendPong
public function sendPong($msgid) { $messageNode = new ProtocolNode('iq', [ 'to' => Constants::WHATSAPP_SERVER, 'id' => $msgid, 'type' => 'result', ], null, ''); $this->sendNode($messageNode); $this->eventManager()->fire('onSendPong', [ $this->phoneNumber, $msgid, ]); }
php
public function sendPong($msgid) { $messageNode = new ProtocolNode('iq', [ 'to' => Constants::WHATSAPP_SERVER, 'id' => $msgid, 'type' => 'result', ], null, ''); $this->sendNode($messageNode); $this->eventManager()->fire('onSendPong', [ $this->phoneNumber, $msgid, ]); }
[ "public", "function", "sendPong", "(", "$", "msgid", ")", "{", "$", "messageNode", "=", "new", "ProtocolNode", "(", "'iq'", ",", "[", "'to'", "=>", "Constants", "::", "WHATSAPP_SERVER", ",", "'id'", "=>", "$", "msgid", ",", "'type'", "=>", "'result'", ",", "]", ",", "null", ",", "''", ")", ";", "$", "this", "->", "sendNode", "(", "$", "messageNode", ")", ";", "$", "this", "->", "eventManager", "(", ")", "->", "fire", "(", "'onSendPong'", ",", "[", "$", "this", "->", "phoneNumber", ",", "$", "msgid", ",", "]", ")", ";", "}" ]
Send a pong to the WhatsApp server. I'm alive! @param string $msgid The id of the message.
[ "Send", "a", "pong", "to", "the", "WhatsApp", "server", ".", "I", "m", "alive!" ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L1517-L1532
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendPresenceSubscription
public function sendPresenceSubscription($to) { $node = new ProtocolNode('presence', ['type' => 'subscribe', 'to' => $this->getJID($to)], null, ''); $this->sendNode($node); }
php
public function sendPresenceSubscription($to) { $node = new ProtocolNode('presence', ['type' => 'subscribe', 'to' => $this->getJID($to)], null, ''); $this->sendNode($node); }
[ "public", "function", "sendPresenceSubscription", "(", "$", "to", ")", "{", "$", "node", "=", "new", "ProtocolNode", "(", "'presence'", ",", "[", "'type'", "=>", "'subscribe'", ",", "'to'", "=>", "$", "this", "->", "getJID", "(", "$", "to", ")", "]", ",", "null", ",", "''", ")", ";", "$", "this", "->", "sendNode", "(", "$", "node", ")", ";", "}" ]
Send presence subscription, automatically receive presence updates as long as the socket is open. @param string $to Phone number.
[ "Send", "presence", "subscription", "automatically", "receive", "presence", "updates", "as", "long", "as", "the", "socket", "is", "open", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L1559-L1563
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendPresenceUnsubscription
public function sendPresenceUnsubscription($to) { $node = new ProtocolNode('presence', ['type' => 'unsubscribe', 'to' => $this->getJID($to)], null, ''); $this->sendNode($node); }
php
public function sendPresenceUnsubscription($to) { $node = new ProtocolNode('presence', ['type' => 'unsubscribe', 'to' => $this->getJID($to)], null, ''); $this->sendNode($node); }
[ "public", "function", "sendPresenceUnsubscription", "(", "$", "to", ")", "{", "$", "node", "=", "new", "ProtocolNode", "(", "'presence'", ",", "[", "'type'", "=>", "'unsubscribe'", ",", "'to'", "=>", "$", "this", "->", "getJID", "(", "$", "to", ")", "]", ",", "null", ",", "''", ")", ";", "$", "this", "->", "sendNode", "(", "$", "node", ")", ";", "}" ]
Unsubscribe, will stop subscription. @param string $to Phone number.
[ "Unsubscribe", "will", "stop", "subscription", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L1570-L1574
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendSetPrivacyBlockedList
public function sendSetPrivacyBlockedList($blockedJids = []) { if (!is_array($blockedJids)) { $blockedJids = [$blockedJids]; } $items = []; foreach ($blockedJids as $index => $jid) { $item = new ProtocolNode('item', [ 'type' => 'jid', 'value' => $this->getJID($jid), 'action' => 'deny', 'order' => $index + 1, //WhatsApp stream crashes on zero index ], null, null); $items[] = $item; } $child = new ProtocolNode('list', [ 'name' => 'default', ], $items, null); $child2 = new ProtocolNode('query', null, [$child], null); $node = new ProtocolNode('iq', [ 'id' => $this->createIqId(), 'xmlns' => 'jabber:iq:privacy', 'type' => 'set', ], [$child2], null); $this->sendNode($node); }
php
public function sendSetPrivacyBlockedList($blockedJids = []) { if (!is_array($blockedJids)) { $blockedJids = [$blockedJids]; } $items = []; foreach ($blockedJids as $index => $jid) { $item = new ProtocolNode('item', [ 'type' => 'jid', 'value' => $this->getJID($jid), 'action' => 'deny', 'order' => $index + 1, //WhatsApp stream crashes on zero index ], null, null); $items[] = $item; } $child = new ProtocolNode('list', [ 'name' => 'default', ], $items, null); $child2 = new ProtocolNode('query', null, [$child], null); $node = new ProtocolNode('iq', [ 'id' => $this->createIqId(), 'xmlns' => 'jabber:iq:privacy', 'type' => 'set', ], [$child2], null); $this->sendNode($node); }
[ "public", "function", "sendSetPrivacyBlockedList", "(", "$", "blockedJids", "=", "[", "]", ")", "{", "if", "(", "!", "is_array", "(", "$", "blockedJids", ")", ")", "{", "$", "blockedJids", "=", "[", "$", "blockedJids", "]", ";", "}", "$", "items", "=", "[", "]", ";", "foreach", "(", "$", "blockedJids", "as", "$", "index", "=>", "$", "jid", ")", "{", "$", "item", "=", "new", "ProtocolNode", "(", "'item'", ",", "[", "'type'", "=>", "'jid'", ",", "'value'", "=>", "$", "this", "->", "getJID", "(", "$", "jid", ")", ",", "'action'", "=>", "'deny'", ",", "'order'", "=>", "$", "index", "+", "1", ",", "//WhatsApp stream crashes on zero index", "]", ",", "null", ",", "null", ")", ";", "$", "items", "[", "]", "=", "$", "item", ";", "}", "$", "child", "=", "new", "ProtocolNode", "(", "'list'", ",", "[", "'name'", "=>", "'default'", ",", "]", ",", "$", "items", ",", "null", ")", ";", "$", "child2", "=", "new", "ProtocolNode", "(", "'query'", ",", "null", ",", "[", "$", "child", "]", ",", "null", ")", ";", "$", "node", "=", "new", "ProtocolNode", "(", "'iq'", ",", "[", "'id'", "=>", "$", "this", "->", "createIqId", "(", ")", ",", "'xmlns'", "=>", "'jabber:iq:privacy'", ",", "'type'", "=>", "'set'", ",", "]", ",", "[", "$", "child2", "]", ",", "null", ")", ";", "$", "this", "->", "sendNode", "(", "$", "node", ")", ";", "}" ]
Set the list of numbers you wish to block receiving from. @param mixed $blockedJids One or more numbers to block messages from.
[ "Set", "the", "list", "of", "numbers", "you", "wish", "to", "block", "receiving", "from", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L1592-L1624
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendSetRecoveryToken
public function sendSetRecoveryToken($token) { $child = new ProtocolNode('pin', [ 'xmlns' => 'w:ch:p', ], null, $token); $node = new ProtocolNode('iq', [ 'id' => $this->createIqId(), 'type' => 'set', 'to' => Constants::WHATSAPP_SERVER, ], [$child], null); $this->sendNode($node); }
php
public function sendSetRecoveryToken($token) { $child = new ProtocolNode('pin', [ 'xmlns' => 'w:ch:p', ], null, $token); $node = new ProtocolNode('iq', [ 'id' => $this->createIqId(), 'type' => 'set', 'to' => Constants::WHATSAPP_SERVER, ], [$child], null); $this->sendNode($node); }
[ "public", "function", "sendSetRecoveryToken", "(", "$", "token", ")", "{", "$", "child", "=", "new", "ProtocolNode", "(", "'pin'", ",", "[", "'xmlns'", "=>", "'w:ch:p'", ",", "]", ",", "null", ",", "$", "token", ")", ";", "$", "node", "=", "new", "ProtocolNode", "(", "'iq'", ",", "[", "'id'", "=>", "$", "this", "->", "createIqId", "(", ")", ",", "'type'", "=>", "'set'", ",", "'to'", "=>", "Constants", "::", "WHATSAPP_SERVER", ",", "]", ",", "[", "$", "child", "]", ",", "null", ")", ";", "$", "this", "->", "sendNode", "(", "$", "node", ")", ";", "}" ]
Set the recovery token for your account to allow you to retrieve your password at a later stage. @param string $token A user generated token.
[ "Set", "the", "recovery", "token", "for", "your", "account", "to", "allow", "you", "to", "retrieve", "your", "password", "at", "a", "later", "stage", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L1667-L1682
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendStatusUpdate
public function sendStatusUpdate($txt) { $child = new ProtocolNode('status', null, null, $txt); $nodeID = $this->createIqId(); $node = new ProtocolNode('iq', [ 'to' => Constants::WHATSAPP_SERVER, 'type' => 'set', 'id' => $nodeID, 'xmlns' => 'status', ], [$child], null); $this->sendNode($node); $this->eventManager()->fire('onSendStatusUpdate', [ $this->phoneNumber, $txt, ]); }
php
public function sendStatusUpdate($txt) { $child = new ProtocolNode('status', null, null, $txt); $nodeID = $this->createIqId(); $node = new ProtocolNode('iq', [ 'to' => Constants::WHATSAPP_SERVER, 'type' => 'set', 'id' => $nodeID, 'xmlns' => 'status', ], [$child], null); $this->sendNode($node); $this->eventManager()->fire('onSendStatusUpdate', [ $this->phoneNumber, $txt, ]); }
[ "public", "function", "sendStatusUpdate", "(", "$", "txt", ")", "{", "$", "child", "=", "new", "ProtocolNode", "(", "'status'", ",", "null", ",", "null", ",", "$", "txt", ")", ";", "$", "nodeID", "=", "$", "this", "->", "createIqId", "(", ")", ";", "$", "node", "=", "new", "ProtocolNode", "(", "'iq'", ",", "[", "'to'", "=>", "Constants", "::", "WHATSAPP_SERVER", ",", "'type'", "=>", "'set'", ",", "'id'", "=>", "$", "nodeID", ",", "'xmlns'", "=>", "'status'", ",", "]", ",", "[", "$", "child", "]", ",", "null", ")", ";", "$", "this", "->", "sendNode", "(", "$", "node", ")", ";", "$", "this", "->", "eventManager", "(", ")", "->", "fire", "(", "'onSendStatusUpdate'", ",", "[", "$", "this", "->", "phoneNumber", ",", "$", "txt", ",", "]", ")", ";", "}" ]
Update the user status. @param string $txt The text of the message status to send.
[ "Update", "the", "user", "status", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L1689-L1707
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.rejectCall
public function rejectCall($to, $id, $callId) { $rejectNode = new ProtocolNode('reject', [ 'call-id' => $callId, ], null, null); $callNode = new ProtocolNode('call', [ 'id' => $id, 'to' => $this->getJID($to), ], [$rejectNode], null); $this->sendNode($callNode); }
php
public function rejectCall($to, $id, $callId) { $rejectNode = new ProtocolNode('reject', [ 'call-id' => $callId, ], null, null); $callNode = new ProtocolNode('call', [ 'id' => $id, 'to' => $this->getJID($to), ], [$rejectNode], null); $this->sendNode($callNode); }
[ "public", "function", "rejectCall", "(", "$", "to", ",", "$", "id", ",", "$", "callId", ")", "{", "$", "rejectNode", "=", "new", "ProtocolNode", "(", "'reject'", ",", "[", "'call-id'", "=>", "$", "callId", ",", "]", ",", "null", ",", "null", ")", ";", "$", "callNode", "=", "new", "ProtocolNode", "(", "'call'", ",", "[", "'id'", "=>", "$", "id", ",", "'to'", "=>", "$", "this", "->", "getJID", "(", "$", "to", ")", ",", "]", ",", "[", "$", "rejectNode", "]", ",", "null", ")", ";", "$", "this", "->", "sendNode", "(", "$", "callNode", ")", ";", "}" ]
Rejects a call. @param array $to Phone number. @param string $id The main node id @param string $callId The call-id
[ "Rejects", "a", "call", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L1766-L1780
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.createMsgId
protected function createMsgId() { $msg = hex2bin($this->messageId); $chars = str_split($msg); $chars_val = array_map('ord', $chars); $pos = count($chars_val) - 1; while (true) { if ($chars_val[$pos] < 255) { $chars_val[$pos]++; break; } else { $chars_val[$pos] = 0; $pos--; } } $chars = array_map('chr', $chars_val); $msg = bin2hex(implode($chars)); $this->messageId = $msg; return $this->messageId; }
php
protected function createMsgId() { $msg = hex2bin($this->messageId); $chars = str_split($msg); $chars_val = array_map('ord', $chars); $pos = count($chars_val) - 1; while (true) { if ($chars_val[$pos] < 255) { $chars_val[$pos]++; break; } else { $chars_val[$pos] = 0; $pos--; } } $chars = array_map('chr', $chars_val); $msg = bin2hex(implode($chars)); $this->messageId = $msg; return $this->messageId; }
[ "protected", "function", "createMsgId", "(", ")", "{", "$", "msg", "=", "hex2bin", "(", "$", "this", "->", "messageId", ")", ";", "$", "chars", "=", "str_split", "(", "$", "msg", ")", ";", "$", "chars_val", "=", "array_map", "(", "'ord'", ",", "$", "chars", ")", ";", "$", "pos", "=", "count", "(", "$", "chars_val", ")", "-", "1", ";", "while", "(", "true", ")", "{", "if", "(", "$", "chars_val", "[", "$", "pos", "]", "<", "255", ")", "{", "$", "chars_val", "[", "$", "pos", "]", "++", ";", "break", ";", "}", "else", "{", "$", "chars_val", "[", "$", "pos", "]", "=", "0", ";", "$", "pos", "--", ";", "}", "}", "$", "chars", "=", "array_map", "(", "'chr'", ",", "$", "chars_val", ")", ";", "$", "msg", "=", "bin2hex", "(", "implode", "(", "$", "chars", ")", ")", ";", "$", "this", "->", "messageId", "=", "$", "msg", ";", "return", "$", "this", "->", "messageId", ";", "}" ]
Create a unique msg id. @return string A message id string.
[ "Create", "a", "unique", "msg", "id", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L1813-L1833
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.createIqId
public function createIqId() { $iqId = $this->iqCounter; $this->iqCounter++; $id = dechex($iqId); return $id; }
php
public function createIqId() { $iqId = $this->iqCounter; $this->iqCounter++; $id = dechex($iqId); return $id; }
[ "public", "function", "createIqId", "(", ")", "{", "$", "iqId", "=", "$", "this", "->", "iqCounter", ";", "$", "this", "->", "iqCounter", "++", ";", "$", "id", "=", "dechex", "(", "$", "iqId", ")", ";", "return", "$", "id", ";", "}" ]
iq id. @return string Iq id
[ "iq", "id", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L1841-L1848
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.debugPrint
public function debugPrint($debugMsg) { if ($this->debug) { if (is_array($debugMsg) || is_object($debugMsg)) { print_r($debugMsg); } else { echo $debugMsg; } return true; } return false; }
php
public function debugPrint($debugMsg) { if ($this->debug) { if (is_array($debugMsg) || is_object($debugMsg)) { print_r($debugMsg); } else { echo $debugMsg; } return true; } return false; }
[ "public", "function", "debugPrint", "(", "$", "debugMsg", ")", "{", "if", "(", "$", "this", "->", "debug", ")", "{", "if", "(", "is_array", "(", "$", "debugMsg", ")", "||", "is_object", "(", "$", "debugMsg", ")", ")", "{", "print_r", "(", "$", "debugMsg", ")", ";", "}", "else", "{", "echo", "$", "debugMsg", ";", "}", "return", "true", ";", "}", "return", "false", ";", "}" ]
Print a message to the debug console. @param mixed $debugMsg The debug message. @return bool
[ "Print", "a", "message", "to", "the", "debug", "console", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L1857-L1870
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.isLoggedIn
public function isLoggedIn() { //If you aren't connected you can't be logged in! ($this->isConnected()) //We are connected - but are we logged in? (the rest) return $this->isConnected() && !empty($this->loginStatus) && $this->loginStatus === Constants::CONNECTED_STATUS; }
php
public function isLoggedIn() { //If you aren't connected you can't be logged in! ($this->isConnected()) //We are connected - but are we logged in? (the rest) return $this->isConnected() && !empty($this->loginStatus) && $this->loginStatus === Constants::CONNECTED_STATUS; }
[ "public", "function", "isLoggedIn", "(", ")", "{", "//If you aren't connected you can't be logged in! ($this->isConnected())", "//We are connected - but are we logged in? (the rest)", "return", "$", "this", "->", "isConnected", "(", ")", "&&", "!", "empty", "(", "$", "this", "->", "loginStatus", ")", "&&", "$", "this", "->", "loginStatus", "===", "Constants", "::", "CONNECTED_STATUS", ";", "}" ]
Have we an active connection with WhatsAPP AND a valid login already? @return bool
[ "Have", "we", "an", "active", "connection", "with", "WhatsAPP", "AND", "a", "valid", "login", "already?" ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L1884-L1889
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.getMediaFile
protected function getMediaFile($filepath, $maxsizebytes = 5242880) { if (filter_var($filepath, FILTER_VALIDATE_URL) !== false) { $this->mediaFileInfo = []; $this->mediaFileInfo['url'] = $filepath; $media = file_get_contents($filepath); $this->mediaFileInfo['filesize'] = strlen($media); if ($this->mediaFileInfo['filesize'] < $maxsizebytes) { $this->mediaFileInfo['filepath'] = tempnam($this->dataFolder.Constants::MEDIA_FOLDER, 'WHA'); file_put_contents($this->mediaFileInfo['filepath'], $media); $this->mediaFileInfo['filemimetype'] = get_mime($this->mediaFileInfo['filepath']); $this->mediaFileInfo['fileextension'] = getExtensionFromMime($this->mediaFileInfo['filemimetype']); return true; } else { return false; } } elseif (file_exists($filepath)) { //Local file $this->mediaFileInfo['filesize'] = filesize($filepath); if ($this->mediaFileInfo['filesize'] < $maxsizebytes) { $this->mediaFileInfo['filepath'] = $filepath; $this->mediaFileInfo['fileextension'] = pathinfo($filepath, PATHINFO_EXTENSION); $this->mediaFileInfo['filemimetype'] = get_mime($filepath); return true; } else { return false; } } return false; }
php
protected function getMediaFile($filepath, $maxsizebytes = 5242880) { if (filter_var($filepath, FILTER_VALIDATE_URL) !== false) { $this->mediaFileInfo = []; $this->mediaFileInfo['url'] = $filepath; $media = file_get_contents($filepath); $this->mediaFileInfo['filesize'] = strlen($media); if ($this->mediaFileInfo['filesize'] < $maxsizebytes) { $this->mediaFileInfo['filepath'] = tempnam($this->dataFolder.Constants::MEDIA_FOLDER, 'WHA'); file_put_contents($this->mediaFileInfo['filepath'], $media); $this->mediaFileInfo['filemimetype'] = get_mime($this->mediaFileInfo['filepath']); $this->mediaFileInfo['fileextension'] = getExtensionFromMime($this->mediaFileInfo['filemimetype']); return true; } else { return false; } } elseif (file_exists($filepath)) { //Local file $this->mediaFileInfo['filesize'] = filesize($filepath); if ($this->mediaFileInfo['filesize'] < $maxsizebytes) { $this->mediaFileInfo['filepath'] = $filepath; $this->mediaFileInfo['fileextension'] = pathinfo($filepath, PATHINFO_EXTENSION); $this->mediaFileInfo['filemimetype'] = get_mime($filepath); return true; } else { return false; } } return false; }
[ "protected", "function", "getMediaFile", "(", "$", "filepath", ",", "$", "maxsizebytes", "=", "5242880", ")", "{", "if", "(", "filter_var", "(", "$", "filepath", ",", "FILTER_VALIDATE_URL", ")", "!==", "false", ")", "{", "$", "this", "->", "mediaFileInfo", "=", "[", "]", ";", "$", "this", "->", "mediaFileInfo", "[", "'url'", "]", "=", "$", "filepath", ";", "$", "media", "=", "file_get_contents", "(", "$", "filepath", ")", ";", "$", "this", "->", "mediaFileInfo", "[", "'filesize'", "]", "=", "strlen", "(", "$", "media", ")", ";", "if", "(", "$", "this", "->", "mediaFileInfo", "[", "'filesize'", "]", "<", "$", "maxsizebytes", ")", "{", "$", "this", "->", "mediaFileInfo", "[", "'filepath'", "]", "=", "tempnam", "(", "$", "this", "->", "dataFolder", ".", "Constants", "::", "MEDIA_FOLDER", ",", "'WHA'", ")", ";", "file_put_contents", "(", "$", "this", "->", "mediaFileInfo", "[", "'filepath'", "]", ",", "$", "media", ")", ";", "$", "this", "->", "mediaFileInfo", "[", "'filemimetype'", "]", "=", "get_mime", "(", "$", "this", "->", "mediaFileInfo", "[", "'filepath'", "]", ")", ";", "$", "this", "->", "mediaFileInfo", "[", "'fileextension'", "]", "=", "getExtensionFromMime", "(", "$", "this", "->", "mediaFileInfo", "[", "'filemimetype'", "]", ")", ";", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}", "elseif", "(", "file_exists", "(", "$", "filepath", ")", ")", "{", "//Local file", "$", "this", "->", "mediaFileInfo", "[", "'filesize'", "]", "=", "filesize", "(", "$", "filepath", ")", ";", "if", "(", "$", "this", "->", "mediaFileInfo", "[", "'filesize'", "]", "<", "$", "maxsizebytes", ")", "{", "$", "this", "->", "mediaFileInfo", "[", "'filepath'", "]", "=", "$", "filepath", ";", "$", "this", "->", "mediaFileInfo", "[", "'fileextension'", "]", "=", "pathinfo", "(", "$", "filepath", ",", "PATHINFO_EXTENSION", ")", ";", "$", "this", "->", "mediaFileInfo", "[", "'filemimetype'", "]", "=", "get_mime", "(", "$", "filepath", ")", ";", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}", "return", "false", ";", "}" ]
Retrieves media file and info from either a URL or localpath. @param string $filepath The URL or path to the mediafile you wish to send @param int $maxsizebytes The maximum size in bytes the media file can be. Default 5MB @return bool false if file information can not be obtained.
[ "Retrieves", "media", "file", "and", "info", "from", "either", "a", "URL", "or", "localpath", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L2024-L2058
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.processInboundData
protected function processInboundData($data) { $node = $this->reader->nextTree($data); if ($node != null) { $this->processInboundDataNode($node); } }
php
protected function processInboundData($data) { $node = $this->reader->nextTree($data); if ($node != null) { $this->processInboundDataNode($node); } }
[ "protected", "function", "processInboundData", "(", "$", "data", ")", "{", "$", "node", "=", "$", "this", "->", "reader", "->", "nextTree", "(", "$", "data", ")", ";", "if", "(", "$", "node", "!=", "null", ")", "{", "$", "this", "->", "processInboundDataNode", "(", "$", "node", ")", ";", "}", "}" ]
Process inbound data. @param $data @throws Exception
[ "Process", "inbound", "data", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L2077-L2083
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.processMediaImage
protected function processMediaImage($node) { $media = $node->getChild('media'); if ($media != null) { $filename = $media->getAttribute('file'); $url = $media->getAttribute('url'); //save thumbnail file_put_contents($this->dataFolder.Constants::MEDIA_FOLDER.DIRECTORY_SEPARATOR.'thumb_'.$filename, $media->getData()); //download and save original file_put_contents($this->dataFolder.Constants::MEDIA_FOLDER.DIRECTORY_SEPARATOR.$filename, file_get_contents($url)); } }
php
protected function processMediaImage($node) { $media = $node->getChild('media'); if ($media != null) { $filename = $media->getAttribute('file'); $url = $media->getAttribute('url'); //save thumbnail file_put_contents($this->dataFolder.Constants::MEDIA_FOLDER.DIRECTORY_SEPARATOR.'thumb_'.$filename, $media->getData()); //download and save original file_put_contents($this->dataFolder.Constants::MEDIA_FOLDER.DIRECTORY_SEPARATOR.$filename, file_get_contents($url)); } }
[ "protected", "function", "processMediaImage", "(", "$", "node", ")", "{", "$", "media", "=", "$", "node", "->", "getChild", "(", "'media'", ")", ";", "if", "(", "$", "media", "!=", "null", ")", "{", "$", "filename", "=", "$", "media", "->", "getAttribute", "(", "'file'", ")", ";", "$", "url", "=", "$", "media", "->", "getAttribute", "(", "'url'", ")", ";", "//save thumbnail", "file_put_contents", "(", "$", "this", "->", "dataFolder", ".", "Constants", "::", "MEDIA_FOLDER", ".", "DIRECTORY_SEPARATOR", ".", "'thumb_'", ".", "$", "filename", ",", "$", "media", "->", "getData", "(", ")", ")", ";", "//download and save original", "file_put_contents", "(", "$", "this", "->", "dataFolder", ".", "Constants", "::", "MEDIA_FOLDER", ".", "DIRECTORY_SEPARATOR", ".", "$", "filename", ",", "file_get_contents", "(", "$", "url", ")", ")", ";", "}", "}" ]
Process and save media image. @param ProtocolNode $node ProtocolNode containing media
[ "Process", "and", "save", "media", "image", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L2423-L2436
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.processProfilePicture
protected function processProfilePicture($node) { $pictureNode = $node->getChild('picture'); if ($pictureNode != null) { if ($pictureNode->getAttribute('type') == 'preview') { $filename = $this->dataFolder.Constants::PICTURES_FOLDER.DIRECTORY_SEPARATOR.'preview_'.$node->getAttribute('from').'jpg'; } else { $filename = $this->dataFolder.Constants::PICTURES_FOLDER.DIRECTORY_SEPARATOR.$node->getAttribute('from').'.jpg'; } file_put_contents($filename, $pictureNode->getData()); } }
php
protected function processProfilePicture($node) { $pictureNode = $node->getChild('picture'); if ($pictureNode != null) { if ($pictureNode->getAttribute('type') == 'preview') { $filename = $this->dataFolder.Constants::PICTURES_FOLDER.DIRECTORY_SEPARATOR.'preview_'.$node->getAttribute('from').'jpg'; } else { $filename = $this->dataFolder.Constants::PICTURES_FOLDER.DIRECTORY_SEPARATOR.$node->getAttribute('from').'.jpg'; } file_put_contents($filename, $pictureNode->getData()); } }
[ "protected", "function", "processProfilePicture", "(", "$", "node", ")", "{", "$", "pictureNode", "=", "$", "node", "->", "getChild", "(", "'picture'", ")", ";", "if", "(", "$", "pictureNode", "!=", "null", ")", "{", "if", "(", "$", "pictureNode", "->", "getAttribute", "(", "'type'", ")", "==", "'preview'", ")", "{", "$", "filename", "=", "$", "this", "->", "dataFolder", ".", "Constants", "::", "PICTURES_FOLDER", ".", "DIRECTORY_SEPARATOR", ".", "'preview_'", ".", "$", "node", "->", "getAttribute", "(", "'from'", ")", ".", "'jpg'", ";", "}", "else", "{", "$", "filename", "=", "$", "this", "->", "dataFolder", ".", "Constants", "::", "PICTURES_FOLDER", ".", "DIRECTORY_SEPARATOR", ".", "$", "node", "->", "getAttribute", "(", "'from'", ")", ".", "'.jpg'", ";", "}", "file_put_contents", "(", "$", "filename", ",", "$", "pictureNode", "->", "getData", "(", ")", ")", ";", "}", "}" ]
Processes received picture node. @param ProtocolNode $node ProtocolNode containing the picture
[ "Processes", "received", "picture", "node", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L2443-L2456
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.processTempMediaFile
protected function processTempMediaFile($storeURLmedia) { if (!isset($this->mediaFileInfo['url'])) { return false; } if ($storeURLmedia && is_file($this->mediaFileInfo['filepath'])) { rename($this->mediaFileInfo['filepath'], $this->mediaFileInfo['filepath'].'.'.$this->mediaFileInfo['fileextension']); } elseif (is_file($this->mediaFileInfo['filepath'])) { unlink($this->mediaFileInfo['filepath']); } }
php
protected function processTempMediaFile($storeURLmedia) { if (!isset($this->mediaFileInfo['url'])) { return false; } if ($storeURLmedia && is_file($this->mediaFileInfo['filepath'])) { rename($this->mediaFileInfo['filepath'], $this->mediaFileInfo['filepath'].'.'.$this->mediaFileInfo['fileextension']); } elseif (is_file($this->mediaFileInfo['filepath'])) { unlink($this->mediaFileInfo['filepath']); } }
[ "protected", "function", "processTempMediaFile", "(", "$", "storeURLmedia", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "mediaFileInfo", "[", "'url'", "]", ")", ")", "{", "return", "false", ";", "}", "if", "(", "$", "storeURLmedia", "&&", "is_file", "(", "$", "this", "->", "mediaFileInfo", "[", "'filepath'", "]", ")", ")", "{", "rename", "(", "$", "this", "->", "mediaFileInfo", "[", "'filepath'", "]", ",", "$", "this", "->", "mediaFileInfo", "[", "'filepath'", "]", ".", "'.'", ".", "$", "this", "->", "mediaFileInfo", "[", "'fileextension'", "]", ")", ";", "}", "elseif", "(", "is_file", "(", "$", "this", "->", "mediaFileInfo", "[", "'filepath'", "]", ")", ")", "{", "unlink", "(", "$", "this", "->", "mediaFileInfo", "[", "'filepath'", "]", ")", ";", "}", "}" ]
If the media file was originally from a URL, this function either deletes it or renames it depending on the user option. @param bool $storeURLmedia Save or delete the media file from local server
[ "If", "the", "media", "file", "was", "originally", "from", "a", "URL", "this", "function", "either", "deletes", "it", "or", "renames", "it", "depending", "on", "the", "user", "option", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L2464-L2475
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.readStanza
public function readStanza() { $buff = ''; if ($this->isConnected()) { $header = @socket_read($this->socket, 3); //read stanza header // if($header !== false && strlen($header) > 1){ if ($header === false) { $this->eventManager()->fire('onClose', [ $this->phoneNumber, 'Socket EOF', ] ); } if (strlen($header) == 0) { //no data received return; } if (strlen($header) != 3) { throw new ConnectionException('Failed to read stanza header'); } $treeLength = (ord($header[0]) & 0x0F) << 16; $treeLength |= ord($header[1]) << 8; $treeLength |= ord($header[2]) << 0; //read full length $buff = socket_read($this->socket, $treeLength); //$trlen = $treeLength; $len = strlen($buff); //$prev = 0; while (strlen($buff) < $treeLength) { $toRead = $treeLength - strlen($buff); $buff .= socket_read($this->socket, $toRead); if ($len == strlen($buff)) { //no new data read, fuck it break; } $len = strlen($buff); } if (strlen($buff) != $treeLength) { throw new ConnectionException('Tree length did not match received length (buff = '.strlen($buff)." & treeLength = $treeLength)"); } $buff = $header.$buff; } return $buff; }
php
public function readStanza() { $buff = ''; if ($this->isConnected()) { $header = @socket_read($this->socket, 3); //read stanza header // if($header !== false && strlen($header) > 1){ if ($header === false) { $this->eventManager()->fire('onClose', [ $this->phoneNumber, 'Socket EOF', ] ); } if (strlen($header) == 0) { //no data received return; } if (strlen($header) != 3) { throw new ConnectionException('Failed to read stanza header'); } $treeLength = (ord($header[0]) & 0x0F) << 16; $treeLength |= ord($header[1]) << 8; $treeLength |= ord($header[2]) << 0; //read full length $buff = socket_read($this->socket, $treeLength); //$trlen = $treeLength; $len = strlen($buff); //$prev = 0; while (strlen($buff) < $treeLength) { $toRead = $treeLength - strlen($buff); $buff .= socket_read($this->socket, $toRead); if ($len == strlen($buff)) { //no new data read, fuck it break; } $len = strlen($buff); } if (strlen($buff) != $treeLength) { throw new ConnectionException('Tree length did not match received length (buff = '.strlen($buff)." & treeLength = $treeLength)"); } $buff = $header.$buff; } return $buff; }
[ "public", "function", "readStanza", "(", ")", "{", "$", "buff", "=", "''", ";", "if", "(", "$", "this", "->", "isConnected", "(", ")", ")", "{", "$", "header", "=", "@", "socket_read", "(", "$", "this", "->", "socket", ",", "3", ")", ";", "//read stanza header", "// if($header !== false && strlen($header) > 1){", "if", "(", "$", "header", "===", "false", ")", "{", "$", "this", "->", "eventManager", "(", ")", "->", "fire", "(", "'onClose'", ",", "[", "$", "this", "->", "phoneNumber", ",", "'Socket EOF'", ",", "]", ")", ";", "}", "if", "(", "strlen", "(", "$", "header", ")", "==", "0", ")", "{", "//no data received", "return", ";", "}", "if", "(", "strlen", "(", "$", "header", ")", "!=", "3", ")", "{", "throw", "new", "ConnectionException", "(", "'Failed to read stanza header'", ")", ";", "}", "$", "treeLength", "=", "(", "ord", "(", "$", "header", "[", "0", "]", ")", "&", "0x0F", ")", "<<", "16", ";", "$", "treeLength", "|=", "ord", "(", "$", "header", "[", "1", "]", ")", "<<", "8", ";", "$", "treeLength", "|=", "ord", "(", "$", "header", "[", "2", "]", ")", "<<", "0", ";", "//read full length", "$", "buff", "=", "socket_read", "(", "$", "this", "->", "socket", ",", "$", "treeLength", ")", ";", "//$trlen = $treeLength;", "$", "len", "=", "strlen", "(", "$", "buff", ")", ";", "//$prev = 0;", "while", "(", "strlen", "(", "$", "buff", ")", "<", "$", "treeLength", ")", "{", "$", "toRead", "=", "$", "treeLength", "-", "strlen", "(", "$", "buff", ")", ";", "$", "buff", ".=", "socket_read", "(", "$", "this", "->", "socket", ",", "$", "toRead", ")", ";", "if", "(", "$", "len", "==", "strlen", "(", "$", "buff", ")", ")", "{", "//no new data read, fuck it", "break", ";", "}", "$", "len", "=", "strlen", "(", "$", "buff", ")", ";", "}", "if", "(", "strlen", "(", "$", "buff", ")", "!=", "$", "treeLength", ")", "{", "throw", "new", "ConnectionException", "(", "'Tree length did not match received length (buff = '", ".", "strlen", "(", "$", "buff", ")", ".", "\" & treeLength = $treeLength)\"", ")", ";", "}", "$", "buff", "=", "$", "header", ".", "$", "buff", ";", "}", "return", "$", "buff", ";", "}" ]
Read 1024 bytes from the whatsapp server. @throws Exception
[ "Read", "1024", "bytes", "from", "the", "whatsapp", "server", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L2604-L2653
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendCheckAndSendMedia
protected function sendCheckAndSendMedia($filepath, $maxSize, $to, $type, $allowedExtensions, $storeURLmedia, $caption = '') { if ($this->getMediaFile($filepath, $maxSize) == true) { if (in_array(strtolower($this->mediaFileInfo['fileextension']), $allowedExtensions)) { $b64hash = base64_encode(hash_file('sha256', $this->mediaFileInfo['filepath'], true)); //request upload and get Message ID $id = $this->sendRequestFileUpload($b64hash, $type, $this->mediaFileInfo['filesize'], $this->mediaFileInfo['filepath'], $to, $caption); $this->processTempMediaFile($storeURLmedia); // Return message ID. Make pull request for this. return $id; } else { //Not allowed file type. $this->processTempMediaFile($storeURLmedia); return; } } else { //Didn't get media file details. return; } }
php
protected function sendCheckAndSendMedia($filepath, $maxSize, $to, $type, $allowedExtensions, $storeURLmedia, $caption = '') { if ($this->getMediaFile($filepath, $maxSize) == true) { if (in_array(strtolower($this->mediaFileInfo['fileextension']), $allowedExtensions)) { $b64hash = base64_encode(hash_file('sha256', $this->mediaFileInfo['filepath'], true)); //request upload and get Message ID $id = $this->sendRequestFileUpload($b64hash, $type, $this->mediaFileInfo['filesize'], $this->mediaFileInfo['filepath'], $to, $caption); $this->processTempMediaFile($storeURLmedia); // Return message ID. Make pull request for this. return $id; } else { //Not allowed file type. $this->processTempMediaFile($storeURLmedia); return; } } else { //Didn't get media file details. return; } }
[ "protected", "function", "sendCheckAndSendMedia", "(", "$", "filepath", ",", "$", "maxSize", ",", "$", "to", ",", "$", "type", ",", "$", "allowedExtensions", ",", "$", "storeURLmedia", ",", "$", "caption", "=", "''", ")", "{", "if", "(", "$", "this", "->", "getMediaFile", "(", "$", "filepath", ",", "$", "maxSize", ")", "==", "true", ")", "{", "if", "(", "in_array", "(", "strtolower", "(", "$", "this", "->", "mediaFileInfo", "[", "'fileextension'", "]", ")", ",", "$", "allowedExtensions", ")", ")", "{", "$", "b64hash", "=", "base64_encode", "(", "hash_file", "(", "'sha256'", ",", "$", "this", "->", "mediaFileInfo", "[", "'filepath'", "]", ",", "true", ")", ")", ";", "//request upload and get Message ID", "$", "id", "=", "$", "this", "->", "sendRequestFileUpload", "(", "$", "b64hash", ",", "$", "type", ",", "$", "this", "->", "mediaFileInfo", "[", "'filesize'", "]", ",", "$", "this", "->", "mediaFileInfo", "[", "'filepath'", "]", ",", "$", "to", ",", "$", "caption", ")", ";", "$", "this", "->", "processTempMediaFile", "(", "$", "storeURLmedia", ")", ";", "// Return message ID. Make pull request for this.", "return", "$", "id", ";", "}", "else", "{", "//Not allowed file type.", "$", "this", "->", "processTempMediaFile", "(", "$", "storeURLmedia", ")", ";", "return", ";", "}", "}", "else", "{", "//Didn't get media file details.", "return", ";", "}", "}" ]
Checks that the media file to send is of allowable filetype and within size limits. @param string $filepath The URL/URI to the media file @param int $maxSize Maximum filesize allowed for media type @param string $to Recipient ID/number @param string $type media filetype. 'audio', 'video', 'image' @param array $allowedExtensions An array of allowable file types for the media file @param bool $storeURLmedia Keep a copy of the media file @param string $caption * @return string|null Message ID if successfully, null if not.
[ "Checks", "that", "the", "media", "file", "to", "send", "is", "of", "allowable", "filetype", "and", "within", "size", "limits", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L2668-L2688
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendBroadcast
protected function sendBroadcast($targets, $node, $type) { if (!is_array($targets)) { $targets = [$targets]; } $toNodes = []; foreach ($targets as $target) { $jid = $this->getJID($target); $hash = ['jid' => $jid]; $toNode = new ProtocolNode('to', $hash, null, null); $toNodes[] = $toNode; } $broadcastNode = new ProtocolNode('broadcast', null, $toNodes, null); $msgId = $this->createMsgId(); $messageNode = new ProtocolNode('message', [ 'to' => time().'@broadcast', 'type' => $type, 'id' => $msgId, ], [$node, $broadcastNode], null); $this->sendNode($messageNode); $this->waitForServer($msgId); //listen for response $this->eventManager()->fire('onSendMessage', [ $this->phoneNumber, $targets, $msgId, $node, ]); return $msgId; }
php
protected function sendBroadcast($targets, $node, $type) { if (!is_array($targets)) { $targets = [$targets]; } $toNodes = []; foreach ($targets as $target) { $jid = $this->getJID($target); $hash = ['jid' => $jid]; $toNode = new ProtocolNode('to', $hash, null, null); $toNodes[] = $toNode; } $broadcastNode = new ProtocolNode('broadcast', null, $toNodes, null); $msgId = $this->createMsgId(); $messageNode = new ProtocolNode('message', [ 'to' => time().'@broadcast', 'type' => $type, 'id' => $msgId, ], [$node, $broadcastNode], null); $this->sendNode($messageNode); $this->waitForServer($msgId); //listen for response $this->eventManager()->fire('onSendMessage', [ $this->phoneNumber, $targets, $msgId, $node, ]); return $msgId; }
[ "protected", "function", "sendBroadcast", "(", "$", "targets", ",", "$", "node", ",", "$", "type", ")", "{", "if", "(", "!", "is_array", "(", "$", "targets", ")", ")", "{", "$", "targets", "=", "[", "$", "targets", "]", ";", "}", "$", "toNodes", "=", "[", "]", ";", "foreach", "(", "$", "targets", "as", "$", "target", ")", "{", "$", "jid", "=", "$", "this", "->", "getJID", "(", "$", "target", ")", ";", "$", "hash", "=", "[", "'jid'", "=>", "$", "jid", "]", ";", "$", "toNode", "=", "new", "ProtocolNode", "(", "'to'", ",", "$", "hash", ",", "null", ",", "null", ")", ";", "$", "toNodes", "[", "]", "=", "$", "toNode", ";", "}", "$", "broadcastNode", "=", "new", "ProtocolNode", "(", "'broadcast'", ",", "null", ",", "$", "toNodes", ",", "null", ")", ";", "$", "msgId", "=", "$", "this", "->", "createMsgId", "(", ")", ";", "$", "messageNode", "=", "new", "ProtocolNode", "(", "'message'", ",", "[", "'to'", "=>", "time", "(", ")", ".", "'@broadcast'", ",", "'type'", "=>", "$", "type", ",", "'id'", "=>", "$", "msgId", ",", "]", ",", "[", "$", "node", ",", "$", "broadcastNode", "]", ",", "null", ")", ";", "$", "this", "->", "sendNode", "(", "$", "messageNode", ")", ";", "$", "this", "->", "waitForServer", "(", "$", "msgId", ")", ";", "//listen for response", "$", "this", "->", "eventManager", "(", ")", "->", "fire", "(", "'onSendMessage'", ",", "[", "$", "this", "->", "phoneNumber", ",", "$", "targets", ",", "$", "msgId", ",", "$", "node", ",", "]", ")", ";", "return", "$", "msgId", ";", "}" ]
Send a broadcast. @param array $targets Array of numbers to send to @param object $node @param $type @return string
[ "Send", "a", "broadcast", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L2699-L2736
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendData
public function sendData($data) { if ($this->isConnected()) { if (socket_write($this->socket, $data, strlen($data)) === false) { $this->eventManager()->fire('onClose', [ $this->phoneNumber, 'Connection closed!', ] ); } } }
php
public function sendData($data) { if ($this->isConnected()) { if (socket_write($this->socket, $data, strlen($data)) === false) { $this->eventManager()->fire('onClose', [ $this->phoneNumber, 'Connection closed!', ] ); } } }
[ "public", "function", "sendData", "(", "$", "data", ")", "{", "if", "(", "$", "this", "->", "isConnected", "(", ")", ")", "{", "if", "(", "socket_write", "(", "$", "this", "->", "socket", ",", "$", "data", ",", "strlen", "(", "$", "data", ")", ")", "===", "false", ")", "{", "$", "this", "->", "eventManager", "(", ")", "->", "fire", "(", "'onClose'", ",", "[", "$", "this", "->", "phoneNumber", ",", "'Connection closed!'", ",", "]", ")", ";", "}", "}", "}" ]
Send data to the WhatsApp server. @param string $data @throws Exception
[ "Send", "data", "to", "the", "WhatsApp", "server", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L2745-L2757
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendGetGroupsFiltered
protected function sendGetGroupsFiltered($type) { $msgID = $this->nodeId['getgroups'] = $this->createIqId(); $child = new ProtocolNode($type, null, null, null); $node = new ProtocolNode('iq', [ 'id' => $msgID, 'type' => 'get', 'xmlns' => 'w:g2', 'to' => Constants::WHATSAPP_GROUP_SERVER, ], [$child], null); $this->sendNode($node); }
php
protected function sendGetGroupsFiltered($type) { $msgID = $this->nodeId['getgroups'] = $this->createIqId(); $child = new ProtocolNode($type, null, null, null); $node = new ProtocolNode('iq', [ 'id' => $msgID, 'type' => 'get', 'xmlns' => 'w:g2', 'to' => Constants::WHATSAPP_GROUP_SERVER, ], [$child], null); $this->sendNode($node); }
[ "protected", "function", "sendGetGroupsFiltered", "(", "$", "type", ")", "{", "$", "msgID", "=", "$", "this", "->", "nodeId", "[", "'getgroups'", "]", "=", "$", "this", "->", "createIqId", "(", ")", ";", "$", "child", "=", "new", "ProtocolNode", "(", "$", "type", ",", "null", ",", "null", ",", "null", ")", ";", "$", "node", "=", "new", "ProtocolNode", "(", "'iq'", ",", "[", "'id'", "=>", "$", "msgID", ",", "'type'", "=>", "'get'", ",", "'xmlns'", "=>", "'w:g2'", ",", "'to'", "=>", "Constants", "::", "WHATSAPP_GROUP_SERVER", ",", "]", ",", "[", "$", "child", "]", ",", "null", ")", ";", "$", "this", "->", "sendNode", "(", "$", "node", ")", ";", "}" ]
Send the getGroupList request to WhatsApp. @param string $type Type of list of groups to retrieve. "owning" or "participating"
[ "Send", "the", "getGroupList", "request", "to", "WhatsApp", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L2764-L2777
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendGroupsChangeParticipants
protected function sendGroupsChangeParticipants($groupId, $participant, $tag, $id) { $participants = new ProtocolNode('participant', ['jid' => $this->getJID($participant)], null, ''); $childHash = []; $child = new ProtocolNode($tag, $childHash, [$participants], ''); $node = new ProtocolNode('iq', [ 'id' => $id, 'type' => 'set', 'xmlns' => 'w:g2', 'to' => $this->getJID($groupId), ], [$child], ''); $this->sendNode($node); }
php
protected function sendGroupsChangeParticipants($groupId, $participant, $tag, $id) { $participants = new ProtocolNode('participant', ['jid' => $this->getJID($participant)], null, ''); $childHash = []; $child = new ProtocolNode($tag, $childHash, [$participants], ''); $node = new ProtocolNode('iq', [ 'id' => $id, 'type' => 'set', 'xmlns' => 'w:g2', 'to' => $this->getJID($groupId), ], [$child], ''); $this->sendNode($node); }
[ "protected", "function", "sendGroupsChangeParticipants", "(", "$", "groupId", ",", "$", "participant", ",", "$", "tag", ",", "$", "id", ")", "{", "$", "participants", "=", "new", "ProtocolNode", "(", "'participant'", ",", "[", "'jid'", "=>", "$", "this", "->", "getJID", "(", "$", "participant", ")", "]", ",", "null", ",", "''", ")", ";", "$", "childHash", "=", "[", "]", ";", "$", "child", "=", "new", "ProtocolNode", "(", "$", "tag", ",", "$", "childHash", ",", "[", "$", "participants", "]", ",", "''", ")", ";", "$", "node", "=", "new", "ProtocolNode", "(", "'iq'", ",", "[", "'id'", "=>", "$", "id", ",", "'type'", "=>", "'set'", ",", "'xmlns'", "=>", "'w:g2'", ",", "'to'", "=>", "$", "this", "->", "getJID", "(", "$", "groupId", ")", ",", "]", ",", "[", "$", "child", "]", ",", "''", ")", ";", "$", "this", "->", "sendNode", "(", "$", "node", ")", ";", "}" ]
Change participants of a group. @param string $groupId The group ID. @param string $participant The participant. @param string $tag The tag action. 'add', 'remove', 'promote' or 'demote' @param $id
[ "Change", "participants", "of", "a", "group", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L2787-L2803
train
mgp25/Chat-API
src/whatsprot.class.php
WhatsProt.sendMessageNode
protected function sendMessageNode($to, $node, $id = null, $plaintextNode = null) { $msgId = ($id == null) ? $this->createMsgId() : $id; $to = $this->getJID($to); if ($node->getTag() == 'body' || $node->getTag() == 'enc') { $type = 'text'; } else { $type = 'media'; } $messageNode = new ProtocolNode('message', [ 'to' => $to, 'type' => $type, 'id' => $msgId, 't' => time(), 'notify' => $this->name, ], [$node], ''); $this->sendNode($messageNode); if ($node->getTag() == 'enc') { $node = $plaintextNode; } $this->logFile('info', '{type} message with id {id} sent to {to}', ['type' => $type, 'id' => $msgId, 'to' => ExtractNumber($to)]); $this->eventManager()->fire('onSendMessage', [ $this->phoneNumber, $to, $msgId, $node, ]); // $this->waitForServer($msgId); return $msgId; }
php
protected function sendMessageNode($to, $node, $id = null, $plaintextNode = null) { $msgId = ($id == null) ? $this->createMsgId() : $id; $to = $this->getJID($to); if ($node->getTag() == 'body' || $node->getTag() == 'enc') { $type = 'text'; } else { $type = 'media'; } $messageNode = new ProtocolNode('message', [ 'to' => $to, 'type' => $type, 'id' => $msgId, 't' => time(), 'notify' => $this->name, ], [$node], ''); $this->sendNode($messageNode); if ($node->getTag() == 'enc') { $node = $plaintextNode; } $this->logFile('info', '{type} message with id {id} sent to {to}', ['type' => $type, 'id' => $msgId, 'to' => ExtractNumber($to)]); $this->eventManager()->fire('onSendMessage', [ $this->phoneNumber, $to, $msgId, $node, ]); // $this->waitForServer($msgId); return $msgId; }
[ "protected", "function", "sendMessageNode", "(", "$", "to", ",", "$", "node", ",", "$", "id", "=", "null", ",", "$", "plaintextNode", "=", "null", ")", "{", "$", "msgId", "=", "(", "$", "id", "==", "null", ")", "?", "$", "this", "->", "createMsgId", "(", ")", ":", "$", "id", ";", "$", "to", "=", "$", "this", "->", "getJID", "(", "$", "to", ")", ";", "if", "(", "$", "node", "->", "getTag", "(", ")", "==", "'body'", "||", "$", "node", "->", "getTag", "(", ")", "==", "'enc'", ")", "{", "$", "type", "=", "'text'", ";", "}", "else", "{", "$", "type", "=", "'media'", ";", "}", "$", "messageNode", "=", "new", "ProtocolNode", "(", "'message'", ",", "[", "'to'", "=>", "$", "to", ",", "'type'", "=>", "$", "type", ",", "'id'", "=>", "$", "msgId", ",", "'t'", "=>", "time", "(", ")", ",", "'notify'", "=>", "$", "this", "->", "name", ",", "]", ",", "[", "$", "node", "]", ",", "''", ")", ";", "$", "this", "->", "sendNode", "(", "$", "messageNode", ")", ";", "if", "(", "$", "node", "->", "getTag", "(", ")", "==", "'enc'", ")", "{", "$", "node", "=", "$", "plaintextNode", ";", "}", "$", "this", "->", "logFile", "(", "'info'", ",", "'{type} message with id {id} sent to {to}'", ",", "[", "'type'", "=>", "$", "type", ",", "'id'", "=>", "$", "msgId", ",", "'to'", "=>", "ExtractNumber", "(", "$", "to", ")", "]", ")", ";", "$", "this", "->", "eventManager", "(", ")", "->", "fire", "(", "'onSendMessage'", ",", "[", "$", "this", "->", "phoneNumber", ",", "$", "to", ",", "$", "msgId", ",", "$", "node", ",", "]", ")", ";", "// $this->waitForServer($msgId);", "return", "$", "msgId", ";", "}" ]
Send node to the servers. @param $to @param ProtocolNode $node @param null $id @return string Message ID.
[ "Send", "node", "to", "the", "servers", "." ]
bfe098d148d9f0c7cff3675d30fdd34c9d970b41
https://github.com/mgp25/Chat-API/blob/bfe098d148d9f0c7cff3675d30fdd34c9d970b41/src/whatsprot.class.php#L2814-L2851
train