_id stringlengths 2 7 | title stringlengths 3 151 | partition stringclasses 3
values | text stringlengths 83 13k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q14300 | Parameters.fetchParametersAsync | train | public function fetchParametersAsync(): \Generator
{
$refetchable = $this->isRefetchable();
if ($this->fetched && !$refetchable) {
return $this->params;
}
$params = yield call([$this, 'getParameters']);
if (!$refetchable) {
$this->params = $params;
}
return $params;
} | php | {
"resource": ""
} |
q14301 | MTProto.connect_to_all_dcs_async | train | public function connect_to_all_dcs_async(): \Generator
{
$this->datacenter->__construct($this, $this->settings['connection'], $this->settings['connection_settings']);
$dcs = [];
foreach ($this->datacenter->get_dcs() as $new_dc) {
$dcs[] = $this->datacenter->dc_connect_async($new_dc);
}
yield $dcs;
yield $this->init_authorization_async();
$dcs = [];
foreach ($this->datacenter->get_dcs(false) as $new_dc) {
$dcs[] = $this->datacenter->dc_connect_async($new_dc);
}
yield $dcs;
yield $this->init_authorization_async();
if (!$this->phoneConfigWatcherId) {
$this->phoneConfigWatcherId = Loop::repeat(24 * 3600 * 1000, [$this, 'get_phone_config_async']);
}
yield $this->get_phone_config_async();
$this->logger->logger("Started phone config fetcher");
} | php | {
"resource": ""
} |
q14302 | Conversation.repeat | train | public function repeat($question = '')
{
$conversation = $this->bot->getStoredConversation();
if (! $question instanceof Question && ! $question) {
$question = unserialize($conversation['question']);
}
$next = $conversation['next'];
$additionalParameters = unserialize($conversation['additionalParameters']);
if (is_string($next)) {
$next = unserialize($next)->getClosure();
} elseif (is_array($next)) {
$next = Collection::make($next)->map(function ($callback) {
if ($this->bot->getDriver()->serializesCallbacks() && ! $this->bot->runsOnSocket()) {
$callback['callback'] = unserialize($callback['callback'])->getClosure();
}
return $callback;
})->toArray();
}
$this->ask($question, $next, $additionalParameters);
} | php | {
"resource": ""
} |
q14303 | DriverManager.loadFromName | train | public static function loadFromName($name, array $config, Request $request = null)
{
/*
* Use the driver class basename without "Driver" if we're dealing with a
* DriverInterface object.
*/
if (class_exists($name) && is_subclass_of($name, DriverInterface::class)) {
$name = preg_replace('#(Driver$)#', '', basename(str_replace('\\', '/', $name)));
}
/*
* Use the driver name constant if we try to load a driver by it's
* fully qualified class name.
*/
if (class_exists($name) && is_subclass_of($name, HttpDriver::class)) {
$name = $name::DRIVER_NAME;
}
if (is_null($request)) {
$request = Request::createFromGlobals();
}
foreach (self::getAvailableDrivers() as $driver) {
/** @var HttpDriver $driver */
$driver = new $driver($request, $config, new Curl());
if ($driver->getName() === $name) {
return $driver;
}
}
return new NullDriver($request, [], new Curl());
} | php | {
"resource": ""
} |
q14304 | DriverManager.loadDriver | train | public static function loadDriver($driver, $explicit = false)
{
array_unshift(self::$drivers, $driver);
if (method_exists($driver, 'loadExtension')) {
call_user_func([$driver, 'loadExtension']);
}
if (method_exists($driver, 'additionalDrivers') && $explicit === false) {
$additionalDrivers = (array) call_user_func([$driver, 'additionalDrivers']);
foreach ($additionalDrivers as $additionalDriver) {
self::loadDriver($additionalDriver);
}
}
self::$drivers = array_unique(self::$drivers);
} | php | {
"resource": ""
} |
q14305 | DriverManager.unloadDriver | train | public static function unloadDriver($driver)
{
foreach (array_keys(self::$drivers, $driver) as $key) {
unset(self::$drivers[$key]);
}
} | php | {
"resource": ""
} |
q14306 | DriverManager.verifyServices | train | public static function verifyServices(array $config, Request $request = null)
{
$request = (isset($request)) ? $request : Request::createFromGlobals();
foreach (self::getAvailableHttpDrivers() as $driver) {
$driver = new $driver($request, $config, new Curl());
if ($driver instanceof VerifiesService && ! is_null($driver->verifyRequest($request))) {
return true;
}
}
return false;
} | php | {
"resource": ""
} |
q14307 | ApiAi.getResponse | train | protected function getResponse(IncomingMessage $message)
{
$response = $this->http->post($this->apiUrl, [], [
'query' => [$message->getText()],
'sessionId' => md5($message->getConversationIdentifier()),
'lang' => $this->lang,
], [
'Authorization: Bearer '.$this->token,
'Content-Type: application/json; charset=utf-8',
], true);
$this->response = json_decode($response->getContent());
return $this->response;
} | php | {
"resource": ""
} |
q14308 | BotManFactory.createForSocket | train | public static function createForSocket(
array $config,
LoopInterface $loop,
CacheInterface $cache = null,
StorageInterface $storageDriver = null
) {
$port = isset($config['port']) ? $config['port'] : 8080;
$socket = new Server($loop);
if (empty($cache)) {
$cache = new ArrayCache();
}
if (empty($storageDriver)) {
$storageDriver = new FileStorage(__DIR__);
}
$driverManager = new DriverManager($config, new Curl());
$botman = new BotMan($cache, DriverManager::loadFromName('Null', $config), $config, $storageDriver);
$botman->runsOnSocket(true);
$socket->on('connection', function ($conn) use ($botman, $driverManager) {
$conn->on('data', function ($data) use ($botman, $driverManager) {
$requestData = json_decode($data, true);
$request = new Request($requestData['query'], $requestData['request'], $requestData['attributes'], [], [], [], $requestData['content']);
$driver = $driverManager->getMatchingDriver($request);
$botman->setDriver($driver);
$botman->listen();
});
});
$socket->listen($port);
return $botman;
} | php | {
"resource": ""
} |
q14309 | BotManFactory.passRequestToSocket | train | public static function passRequestToSocket($port = 8080, Request $request = null)
{
if (empty($request)) {
$request = Request::createFromGlobals();
}
$client = stream_socket_client('tcp://127.0.0.1:'.$port);
fwrite($client, json_encode([
'attributes' => $request->attributes->all(),
'query' => $request->query->all(),
'request' => $request->request->all(),
'content' => $request->getContent(),
]));
fclose($client);
} | php | {
"resource": ""
} |
q14310 | BotMan.getBotMessages | train | public function getBotMessages()
{
return Collection::make($this->getDriver()->getMessages())->filter(function (IncomingMessage $message) {
return $message->isFromBot();
})->toArray();
} | php | {
"resource": ""
} |
q14311 | BotMan.on | train | public function on($names, $callback)
{
if (! is_array($names)) {
$names = [$names];
}
$callable = $this->getCallable($callback);
foreach ($names as $name) {
$this->events[] = [
'name' => $name,
'callback' => $callable,
];
}
} | php | {
"resource": ""
} |
q14312 | BotMan.group | train | public function group(array $attributes, Closure $callback)
{
$previousGroupAttributes = $this->groupAttributes;
$this->groupAttributes = array_merge_recursive($previousGroupAttributes, $attributes);
\call_user_func($callback, $this);
$this->groupAttributes = $previousGroupAttributes;
} | php | {
"resource": ""
} |
q14313 | BotMan.fireDriverEvents | train | protected function fireDriverEvents()
{
$driverEvent = $this->getDriver()->hasMatchingEvent();
if ($driverEvent instanceof DriverEventInterface) {
$this->firedDriverEvents = true;
Collection::make($this->events)->filter(function ($event) use ($driverEvent) {
return $driverEvent->getName() === $event['name'];
})->each(function ($event) use ($driverEvent) {
/**
* Load the message, so driver events can reply.
*/
$messages = $this->getDriver()->getMessages();
if (isset($messages[0])) {
$this->message = $messages[0];
}
\call_user_func_array($event['callback'], [$driverEvent->getPayload(), $this]);
});
}
} | php | {
"resource": ""
} |
q14314 | BotMan.listen | train | 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 | {
"resource": ""
} |
q14315 | BotMan.callMatchingMessages | train | 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 | {
"resource": ""
} |
q14316 | BotMan.callFallbackMessage | train | 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 | {
"resource": ""
} |
q14317 | HandlesConversations.getStoredConversation | train | 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 | {
"resource": ""
} |
q14318 | HandlesConversations.touchCurrentConversation | train | 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 | {
"resource": ""
} |
q14319 | HandlesConversations.removeStoredConversation | train | 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 | {
"resource": ""
} |
q14320 | HandlesExceptions.exception | train | public function exception(string $exception, $closure)
{
$this->exceptionHandler->register($exception, $this->getCallable($closure));
} | php | {
"resource": ""
} |
q14321 | Curl.get | train | public function get($url, array $urlParameters = [], array $headers = [], $asJSON = false)
{
$request = $this->prepareRequest($url, $urlParameters, $headers);
return $this->executeRequest($request);
} | php | {
"resource": ""
} |
q14322 | Curl.prepareRequest | train | 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 | {
"resource": ""
} |
q14323 | Curl.executeRequest | train | 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 | {
"resource": ""
} |
q14324 | Command.applyGroupAttributes | train | 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 | {
"resource": ""
} |
q14325 | PhpFpm.start | train | 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 | {
"resource": ""
} |
q14326 | PhpFpm.proxy | train | 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 | {
"resource": ""
} |
q14327 | PhpFpm.killExistingFpm | train | 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 | {
"resource": ""
} |
q14328 | PhpFpm.waitUntilStopped | train | 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 | {
"resource": ""
} |
q14329 | LambdaRuntime.processNextEvent | train | 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 | {
"resource": ""
} |
q14330 | LambdaRuntime.waitNextInvocation | train | 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 | {
"resource": ""
} |
q14331 | LambdaRuntime.failInitialization | train | 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 | {
"resource": ""
} |
q14332 | SimpleLambdaClient.invoke | train | 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 | {
"resource": ""
} |
q14333 | FileRepository.getCached | train | public function getCached()
{
return $this->app['cache']->remember($this->config('cache.key'), $this->config('cache.lifetime'), function () {
return $this->toCollection()->toArray();
});
} | php | {
"resource": ""
} |
q14334 | FileRepository.find | train | public function find($name)
{
foreach ($this->all() as $module) {
if ($module->getLowerName() === strtolower($name)) {
return $module;
}
}
return;
} | php | {
"resource": ""
} |
q14335 | FileRepository.findByAlias | train | public function findByAlias($alias)
{
foreach ($this->all() as $module) {
if ($module->getAlias() === $alias) {
return $module;
}
}
return;
} | php | {
"resource": ""
} |
q14336 | FileRepository.findRequirements | train | public function findRequirements($name)
{
$requirements = [];
$module = $this->findOrFail($name);
foreach ($module->getRequires() as $requirementName) {
$requirements[] = $this->findByAlias($requirementName);
}
return $requirements;
} | php | {
"resource": ""
} |
q14337 | FileRepository.findOrFail | train | public function findOrFail($name)
{
$module = $this->find($name);
if ($module !== null) {
return $module;
}
throw new ModuleNotFoundException("Module [{$name}] does not exist!");
} | php | {
"resource": ""
} |
q14338 | FileRepository.getModulePath | train | public function getModulePath($module)
{
try {
return $this->findOrFail($module)->getPath() . '/';
} catch (ModuleNotFoundException $e) {
return $this->getPath() . '/' . Str::studly($module) . '/';
}
} | php | {
"resource": ""
} |
q14339 | FileRepository.setUsed | train | public function setUsed($name)
{
$module = $this->findOrFail($name);
$this->app['files']->put($this->getUsedStoragePath(), $module);
} | php | {
"resource": ""
} |
q14340 | FileRepository.forgetUsed | train | public function forgetUsed()
{
if ($this->app['files']->exists($this->getUsedStoragePath())) {
$this->app['files']->delete($this->getUsedStoragePath());
}
} | php | {
"resource": ""
} |
q14341 | FileRepository.install | train | public function install($name, $version = 'dev-master', $type = 'composer', $subtree = false)
{
$installer = new Installer($name, $version, $type, $subtree);
return $installer->run();
} | php | {
"resource": ""
} |
q14342 | Installer.run | train | 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 | {
"resource": ""
} |
q14343 | Installer.getRepoUrl | train | 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 | {
"resource": ""
} |
q14344 | Installer.getPackageName | train | public function getPackageName()
{
if (is_null($this->version)) {
return $this->name . ':dev-master';
}
return $this->name . ':' . $this->version;
} | php | {
"resource": ""
} |
q14345 | SchemaParser.addRelationColumn | train | protected function addRelationColumn($key, $field, $column)
{
$relatedColumn = Str::snake(class_basename($field)) . '_id';
$method = 'integer';
return "->{$method}('{$relatedColumn}')";
} | php | {
"resource": ""
} |
q14346 | Json.update | train | public function update(array $data)
{
$this->attributes = new Collection(array_merge($this->attributes->toArray(), $data));
return $this->save();
} | php | {
"resource": ""
} |
q14347 | SeedCommand.getSeederName | train | 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 | {
"resource": ""
} |
q14348 | SeedCommand.getSeederNames | train | 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 | {
"resource": ""
} |
q14349 | Migrator.rollback | train | 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 | {
"resource": ""
} |
q14350 | Migrator.reset | train | 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 | {
"resource": ""
} |
q14351 | PublishCommand.publish | train | 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 | {
"resource": ""
} |
q14352 | FileGenerator.generate | train | public function generate()
{
if (!$this->filesystem->exists($path = $this->getPath())) {
return $this->filesystem->put($path, $this->getContents());
}
throw new FileAlreadyExistException('File already exists!');
} | php | {
"resource": ""
} |
q14353 | InstallCommand.installFromFile | train | 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 | {
"resource": ""
} |
q14354 | ModelMakeCommand.handleOptionalMigrationOption | train | 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 | {
"resource": ""
} |
q14355 | MigrationLoaderTrait.loadMigrationFiles | train | 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 | {
"resource": ""
} |
q14356 | Module.register | train | public function register()
{
$this->registerAliases();
$this->registerProviders();
if ($this->isLoadFilesOnBoot() === false) {
$this->registerFiles();
}
$this->fireEvent('register');
} | php | {
"resource": ""
} |
q14357 | ControllerMakeCommand.getStubName | train | 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 | {
"resource": ""
} |
q14358 | ModuleGenerator.getReplacement | train | 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 | {
"resource": ""
} |
q14359 | WhatsProt.disconnect | train | 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 | {
"resource": ""
} |
q14360 | WhatsProt.loginWithPassword | train | 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 | {
"resource": ""
} |
q14361 | WhatsProt.pollMessage | train | 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 | {
"resource": ""
} |
q14362 | WhatsProt.sendGetCipherKeysFromUser | train | 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 | {
"resource": ""
} |
q14363 | WhatsProt.sendBroadcastAudio | train | 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 | {
"resource": ""
} |
q14364 | WhatsProt.sendBroadcastImage | train | 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 | {
"resource": ""
} |
q14365 | WhatsProt.sendBroadcastLocation | train | 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 | {
"resource": ""
} |
q14366 | WhatsProt.sendBroadcastMessage | train | 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 | {
"resource": ""
} |
q14367 | WhatsProt.sendBroadcastVideo | train | 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 | {
"resource": ""
} |
q14368 | WhatsProt.sendDeleteBroadcastLists | train | 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 | {
"resource": ""
} |
q14369 | WhatsProt.sendClearDirty | train | 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 | {
"resource": ""
} |
q14370 | WhatsProt.sendChangeNumber | train | 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 | {
"resource": ""
} |
q14371 | WhatsProt.sendGetGroupV2Info | train | 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 | {
"resource": ""
} |
q14372 | WhatsProt.sendGetPrivacyBlockedList | train | 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 | {
"resource": ""
} |
q14373 | WhatsProt.sendGetPrivacySettings | train | 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 | {
"resource": ""
} |
q14374 | WhatsProt.sendSetPrivacySettings | train | 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 | {
"resource": ""
} |
q14375 | WhatsProt.sendGetProfilePicture | train | 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 | {
"resource": ""
} |
q14376 | WhatsProt.sendGetServerProperties | train | 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 | {
"resource": ""
} |
q14377 | WhatsProt.sendGetServicePricing | train | 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 | {
"resource": ""
} |
q14378 | WhatsProt.sendExtendAccount | train | 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 | {
"resource": ""
} |
q14379 | WhatsProt.sendGetBroadcastLists | train | 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 | {
"resource": ""
} |
q14380 | WhatsProt.sendGetNormalizedJid | train | 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 | {
"resource": ""
} |
q14381 | WhatsProt.sendRemoveAccount | train | 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 | {
"resource": ""
} |
q14382 | WhatsProt.sendPing | train | 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 | {
"resource": ""
} |
q14383 | WhatsProt.sendGetStatuses | train | 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 | {
"resource": ""
} |
q14384 | WhatsProt.sendGroupsChatCreate | train | 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 | {
"resource": ""
} |
q14385 | WhatsProt.sendSetGroupSubject | train | 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 | {
"resource": ""
} |
q14386 | WhatsProt.sendGroupsLeave | train | 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 | {
"resource": ""
} |
q14387 | WhatsProt.sendGroupsParticipantsRemove | train | public function sendGroupsParticipantsRemove($groupId, $participant)
{
$msgId = $this->createMsgId();
$this->sendGroupsChangeParticipants($groupId, $participant, 'remove', $msgId);
} | php | {
"resource": ""
} |
q14388 | WhatsProt.sendPromoteParticipants | train | public function sendPromoteParticipants($gId, $participant)
{
$msgId = $this->createMsgId();
$this->sendGroupsChangeParticipants($gId, $participant, 'promote', $msgId);
} | php | {
"resource": ""
} |
q14389 | WhatsProt.sendDemoteParticipants | train | public function sendDemoteParticipants($gId, $participant)
{
$msgId = $this->createMsgId();
$this->sendGroupsChangeParticipants($gId, $participant, 'demote', $msgId);
} | php | {
"resource": ""
} |
q14390 | WhatsProt.sendNextMessage | train | 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 | {
"resource": ""
} |
q14391 | WhatsProt.sendPong | train | 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 | {
"resource": ""
} |
q14392 | WhatsProt.sendPresenceSubscription | train | public function sendPresenceSubscription($to)
{
$node = new ProtocolNode('presence', ['type' => 'subscribe', 'to' => $this->getJID($to)], null, '');
$this->sendNode($node);
} | php | {
"resource": ""
} |
q14393 | WhatsProt.sendPresenceUnsubscription | train | public function sendPresenceUnsubscription($to)
{
$node = new ProtocolNode('presence', ['type' => 'unsubscribe', 'to' => $this->getJID($to)], null, '');
$this->sendNode($node);
} | php | {
"resource": ""
} |
q14394 | WhatsProt.sendSetPrivacyBlockedList | train | 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 | {
"resource": ""
} |
q14395 | WhatsProt.sendSetRecoveryToken | train | 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 | {
"resource": ""
} |
q14396 | WhatsProt.sendStatusUpdate | train | 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 | {
"resource": ""
} |
q14397 | WhatsProt.rejectCall | train | 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 | {
"resource": ""
} |
q14398 | WhatsProt.createMsgId | train | 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 | {
"resource": ""
} |
q14399 | WhatsProt.createIqId | train | public function createIqId()
{
$iqId = $this->iqCounter;
$this->iqCounter++;
$id = dechex($iqId);
return $id;
} | php | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.