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 |
---|---|---|---|---|---|---|---|---|---|---|---|
andersao/l5-repository | src/Prettus/Repository/Eloquent/BaseRepository.php | BaseRepository.applyConditions | protected function applyConditions(array $where)
{
foreach ($where as $field => $value) {
if (is_array($value)) {
list($field, $condition, $val) = $value;
$this->model = $this->model->where($field, $condition, $val);
} else {
$this->model = $this->model->where($field, '=', $value);
}
}
} | php | protected function applyConditions(array $where)
{
foreach ($where as $field => $value) {
if (is_array($value)) {
list($field, $condition, $val) = $value;
$this->model = $this->model->where($field, $condition, $val);
} else {
$this->model = $this->model->where($field, '=', $value);
}
}
} | [
"protected",
"function",
"applyConditions",
"(",
"array",
"$",
"where",
")",
"{",
"foreach",
"(",
"$",
"where",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"list",
"(",
"$",
"field",
",",
"$",
"condition",
",",
"$",
"val",
")",
"=",
"$",
"value",
";",
"$",
"this",
"->",
"model",
"=",
"$",
"this",
"->",
"model",
"->",
"where",
"(",
"$",
"field",
",",
"$",
"condition",
",",
"$",
"val",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"model",
"=",
"$",
"this",
"->",
"model",
"->",
"where",
"(",
"$",
"field",
",",
"'='",
",",
"$",
"value",
")",
";",
"}",
"}",
"}"
] | Applies the given where conditions to the model.
@param array $where
@return void | [
"Applies",
"the",
"given",
"where",
"conditions",
"to",
"the",
"model",
"."
] | f2008d8ff8af50036d2d155c0b5dbb07cbcd0ee4 | https://github.com/andersao/l5-repository/blob/f2008d8ff8af50036d2d155c0b5dbb07cbcd0ee4/src/Prettus/Repository/Eloquent/BaseRepository.php#L956-L966 | train |
andersao/l5-repository | src/Prettus/Repository/Eloquent/BaseRepository.php | BaseRepository.parserResult | public function parserResult($result)
{
if ($this->presenter instanceof PresenterInterface) {
if ($result instanceof Collection || $result instanceof LengthAwarePaginator) {
$result->each(function ($model) {
if ($model instanceof Presentable) {
$model->setPresenter($this->presenter);
}
return $model;
});
} elseif ($result instanceof Presentable) {
$result = $result->setPresenter($this->presenter);
}
if (!$this->skipPresenter) {
return $this->presenter->present($result);
}
}
return $result;
} | php | public function parserResult($result)
{
if ($this->presenter instanceof PresenterInterface) {
if ($result instanceof Collection || $result instanceof LengthAwarePaginator) {
$result->each(function ($model) {
if ($model instanceof Presentable) {
$model->setPresenter($this->presenter);
}
return $model;
});
} elseif ($result instanceof Presentable) {
$result = $result->setPresenter($this->presenter);
}
if (!$this->skipPresenter) {
return $this->presenter->present($result);
}
}
return $result;
} | [
"public",
"function",
"parserResult",
"(",
"$",
"result",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"presenter",
"instanceof",
"PresenterInterface",
")",
"{",
"if",
"(",
"$",
"result",
"instanceof",
"Collection",
"||",
"$",
"result",
"instanceof",
"LengthAwarePaginator",
")",
"{",
"$",
"result",
"->",
"each",
"(",
"function",
"(",
"$",
"model",
")",
"{",
"if",
"(",
"$",
"model",
"instanceof",
"Presentable",
")",
"{",
"$",
"model",
"->",
"setPresenter",
"(",
"$",
"this",
"->",
"presenter",
")",
";",
"}",
"return",
"$",
"model",
";",
"}",
")",
";",
"}",
"elseif",
"(",
"$",
"result",
"instanceof",
"Presentable",
")",
"{",
"$",
"result",
"=",
"$",
"result",
"->",
"setPresenter",
"(",
"$",
"this",
"->",
"presenter",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"skipPresenter",
")",
"{",
"return",
"$",
"this",
"->",
"presenter",
"->",
"present",
"(",
"$",
"result",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Wrapper result data
@param mixed $result
@return mixed | [
"Wrapper",
"result",
"data"
] | f2008d8ff8af50036d2d155c0b5dbb07cbcd0ee4 | https://github.com/andersao/l5-repository/blob/f2008d8ff8af50036d2d155c0b5dbb07cbcd0ee4/src/Prettus/Repository/Eloquent/BaseRepository.php#L989-L1010 | train |
andersao/l5-repository | src/Prettus/Repository/Generators/Generator.php | Generator.getName | public function getName()
{
$name = $this->name;
if (str_contains($this->name, '\\')) {
$name = str_replace('\\', '/', $this->name);
}
if (str_contains($this->name, '/')) {
$name = str_replace('/', '/', $this->name);
}
return Str::studly(str_replace(' ', '/', ucwords(str_replace('/', ' ', $name))));
} | php | public function getName()
{
$name = $this->name;
if (str_contains($this->name, '\\')) {
$name = str_replace('\\', '/', $this->name);
}
if (str_contains($this->name, '/')) {
$name = str_replace('/', '/', $this->name);
}
return Str::studly(str_replace(' ', '/', ucwords(str_replace('/', ' ', $name))));
} | [
"public",
"function",
"getName",
"(",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"name",
";",
"if",
"(",
"str_contains",
"(",
"$",
"this",
"->",
"name",
",",
"'\\\\'",
")",
")",
"{",
"$",
"name",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"this",
"->",
"name",
")",
";",
"}",
"if",
"(",
"str_contains",
"(",
"$",
"this",
"->",
"name",
",",
"'/'",
")",
")",
"{",
"$",
"name",
"=",
"str_replace",
"(",
"'/'",
",",
"'/'",
",",
"$",
"this",
"->",
"name",
")",
";",
"}",
"return",
"Str",
"::",
"studly",
"(",
"str_replace",
"(",
"' '",
",",
"'/'",
",",
"ucwords",
"(",
"str_replace",
"(",
"'/'",
",",
"' '",
",",
"$",
"name",
")",
")",
")",
")",
";",
"}"
] | Get name input.
@return string | [
"Get",
"name",
"input",
"."
] | f2008d8ff8af50036d2d155c0b5dbb07cbcd0ee4 | https://github.com/andersao/l5-repository/blob/f2008d8ff8af50036d2d155c0b5dbb07cbcd0ee4/src/Prettus/Repository/Generators/Generator.php#L135-L146 | train |
andersao/l5-repository | src/Prettus/Repository/Generators/Generator.php | Generator.getConfigGeneratorClassPath | public function getConfigGeneratorClassPath($class, $directoryPath = false)
{
switch ($class) {
case ('models' === $class):
$path = config('repository.generator.paths.models', 'Entities');
break;
case ('repositories' === $class):
$path = config('repository.generator.paths.repositories', 'Repositories');
break;
case ('interfaces' === $class):
$path = config('repository.generator.paths.interfaces', 'Repositories');
break;
case ('presenters' === $class):
$path = config('repository.generator.paths.presenters', 'Presenters');
break;
case ('transformers' === $class):
$path = config('repository.generator.paths.transformers', 'Transformers');
break;
case ('validators' === $class):
$path = config('repository.generator.paths.validators', 'Validators');
break;
case ('controllers' === $class):
$path = config('repository.generator.paths.controllers', 'Http\Controllers');
break;
case ('provider' === $class):
$path = config('repository.generator.paths.provider', 'RepositoryServiceProvider');
break;
case ('criteria' === $class):
$path = config('repository.generator.paths.criteria', 'Criteria');
break;
default:
$path = '';
}
if ($directoryPath) {
$path = str_replace('\\', '/', $path);
} else {
$path = str_replace('/', '\\', $path);
}
return $path;
} | php | public function getConfigGeneratorClassPath($class, $directoryPath = false)
{
switch ($class) {
case ('models' === $class):
$path = config('repository.generator.paths.models', 'Entities');
break;
case ('repositories' === $class):
$path = config('repository.generator.paths.repositories', 'Repositories');
break;
case ('interfaces' === $class):
$path = config('repository.generator.paths.interfaces', 'Repositories');
break;
case ('presenters' === $class):
$path = config('repository.generator.paths.presenters', 'Presenters');
break;
case ('transformers' === $class):
$path = config('repository.generator.paths.transformers', 'Transformers');
break;
case ('validators' === $class):
$path = config('repository.generator.paths.validators', 'Validators');
break;
case ('controllers' === $class):
$path = config('repository.generator.paths.controllers', 'Http\Controllers');
break;
case ('provider' === $class):
$path = config('repository.generator.paths.provider', 'RepositoryServiceProvider');
break;
case ('criteria' === $class):
$path = config('repository.generator.paths.criteria', 'Criteria');
break;
default:
$path = '';
}
if ($directoryPath) {
$path = str_replace('\\', '/', $path);
} else {
$path = str_replace('/', '\\', $path);
}
return $path;
} | [
"public",
"function",
"getConfigGeneratorClassPath",
"(",
"$",
"class",
",",
"$",
"directoryPath",
"=",
"false",
")",
"{",
"switch",
"(",
"$",
"class",
")",
"{",
"case",
"(",
"'models'",
"===",
"$",
"class",
")",
":",
"$",
"path",
"=",
"config",
"(",
"'repository.generator.paths.models'",
",",
"'Entities'",
")",
";",
"break",
";",
"case",
"(",
"'repositories'",
"===",
"$",
"class",
")",
":",
"$",
"path",
"=",
"config",
"(",
"'repository.generator.paths.repositories'",
",",
"'Repositories'",
")",
";",
"break",
";",
"case",
"(",
"'interfaces'",
"===",
"$",
"class",
")",
":",
"$",
"path",
"=",
"config",
"(",
"'repository.generator.paths.interfaces'",
",",
"'Repositories'",
")",
";",
"break",
";",
"case",
"(",
"'presenters'",
"===",
"$",
"class",
")",
":",
"$",
"path",
"=",
"config",
"(",
"'repository.generator.paths.presenters'",
",",
"'Presenters'",
")",
";",
"break",
";",
"case",
"(",
"'transformers'",
"===",
"$",
"class",
")",
":",
"$",
"path",
"=",
"config",
"(",
"'repository.generator.paths.transformers'",
",",
"'Transformers'",
")",
";",
"break",
";",
"case",
"(",
"'validators'",
"===",
"$",
"class",
")",
":",
"$",
"path",
"=",
"config",
"(",
"'repository.generator.paths.validators'",
",",
"'Validators'",
")",
";",
"break",
";",
"case",
"(",
"'controllers'",
"===",
"$",
"class",
")",
":",
"$",
"path",
"=",
"config",
"(",
"'repository.generator.paths.controllers'",
",",
"'Http\\Controllers'",
")",
";",
"break",
";",
"case",
"(",
"'provider'",
"===",
"$",
"class",
")",
":",
"$",
"path",
"=",
"config",
"(",
"'repository.generator.paths.provider'",
",",
"'RepositoryServiceProvider'",
")",
";",
"break",
";",
"case",
"(",
"'criteria'",
"===",
"$",
"class",
")",
":",
"$",
"path",
"=",
"config",
"(",
"'repository.generator.paths.criteria'",
",",
"'Criteria'",
")",
";",
"break",
";",
"default",
":",
"$",
"path",
"=",
"''",
";",
"}",
"if",
"(",
"$",
"directoryPath",
")",
"{",
"$",
"path",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"path",
")",
";",
"}",
"else",
"{",
"$",
"path",
"=",
"str_replace",
"(",
"'/'",
",",
"'\\\\'",
",",
"$",
"path",
")",
";",
"}",
"return",
"$",
"path",
";",
"}"
] | Get class-specific output paths.
@param $class
@return string | [
"Get",
"class",
"-",
"specific",
"output",
"paths",
"."
] | f2008d8ff8af50036d2d155c0b5dbb07cbcd0ee4 | https://github.com/andersao/l5-repository/blob/f2008d8ff8af50036d2d155c0b5dbb07cbcd0ee4/src/Prettus/Repository/Generators/Generator.php#L200-L242 | train |
spatie/laravel-backup | src/Tasks/Backup/BackupJob.php | BackupJob.dumpDatabases | protected function dumpDatabases(): array
{
return $this->dbDumpers->map(function (DbDumper $dbDumper, $key) {
consoleOutput()->info("Dumping database {$dbDumper->getDbName()}...");
$dbType = mb_strtolower(basename(str_replace('\\', '/', get_class($dbDumper))));
$dbName = $dbDumper->getDbName();
if ($dbDumper instanceof Sqlite) {
$dbName = $key.'-database';
}
$fileName = "{$dbType}-{$dbName}.{$this->getExtension($dbDumper)}";
if (config('backup.backup.gzip_database_dump')) {
$dbDumper->useCompressor(new GzipCompressor());
$fileName .= '.'.$dbDumper->getCompressorExtension();
}
if ($compressor = config('backup.backup.database_dump_compressor')) {
$dbDumper->useCompressor(new $compressor());
$fileName .= '.'.$dbDumper->getCompressorExtension();
}
$temporaryFilePath = $this->temporaryDirectory->path('db-dumps'.DIRECTORY_SEPARATOR.$fileName);
$dbDumper->dumpToFile($temporaryFilePath);
return $temporaryFilePath;
})->toArray();
} | php | protected function dumpDatabases(): array
{
return $this->dbDumpers->map(function (DbDumper $dbDumper, $key) {
consoleOutput()->info("Dumping database {$dbDumper->getDbName()}...");
$dbType = mb_strtolower(basename(str_replace('\\', '/', get_class($dbDumper))));
$dbName = $dbDumper->getDbName();
if ($dbDumper instanceof Sqlite) {
$dbName = $key.'-database';
}
$fileName = "{$dbType}-{$dbName}.{$this->getExtension($dbDumper)}";
if (config('backup.backup.gzip_database_dump')) {
$dbDumper->useCompressor(new GzipCompressor());
$fileName .= '.'.$dbDumper->getCompressorExtension();
}
if ($compressor = config('backup.backup.database_dump_compressor')) {
$dbDumper->useCompressor(new $compressor());
$fileName .= '.'.$dbDumper->getCompressorExtension();
}
$temporaryFilePath = $this->temporaryDirectory->path('db-dumps'.DIRECTORY_SEPARATOR.$fileName);
$dbDumper->dumpToFile($temporaryFilePath);
return $temporaryFilePath;
})->toArray();
} | [
"protected",
"function",
"dumpDatabases",
"(",
")",
":",
"array",
"{",
"return",
"$",
"this",
"->",
"dbDumpers",
"->",
"map",
"(",
"function",
"(",
"DbDumper",
"$",
"dbDumper",
",",
"$",
"key",
")",
"{",
"consoleOutput",
"(",
")",
"->",
"info",
"(",
"\"Dumping database {$dbDumper->getDbName()}...\"",
")",
";",
"$",
"dbType",
"=",
"mb_strtolower",
"(",
"basename",
"(",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"get_class",
"(",
"$",
"dbDumper",
")",
")",
")",
")",
";",
"$",
"dbName",
"=",
"$",
"dbDumper",
"->",
"getDbName",
"(",
")",
";",
"if",
"(",
"$",
"dbDumper",
"instanceof",
"Sqlite",
")",
"{",
"$",
"dbName",
"=",
"$",
"key",
".",
"'-database'",
";",
"}",
"$",
"fileName",
"=",
"\"{$dbType}-{$dbName}.{$this->getExtension($dbDumper)}\"",
";",
"if",
"(",
"config",
"(",
"'backup.backup.gzip_database_dump'",
")",
")",
"{",
"$",
"dbDumper",
"->",
"useCompressor",
"(",
"new",
"GzipCompressor",
"(",
")",
")",
";",
"$",
"fileName",
".=",
"'.'",
".",
"$",
"dbDumper",
"->",
"getCompressorExtension",
"(",
")",
";",
"}",
"if",
"(",
"$",
"compressor",
"=",
"config",
"(",
"'backup.backup.database_dump_compressor'",
")",
")",
"{",
"$",
"dbDumper",
"->",
"useCompressor",
"(",
"new",
"$",
"compressor",
"(",
")",
")",
";",
"$",
"fileName",
".=",
"'.'",
".",
"$",
"dbDumper",
"->",
"getCompressorExtension",
"(",
")",
";",
"}",
"$",
"temporaryFilePath",
"=",
"$",
"this",
"->",
"temporaryDirectory",
"->",
"path",
"(",
"'db-dumps'",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"fileName",
")",
";",
"$",
"dbDumper",
"->",
"dumpToFile",
"(",
"$",
"temporaryFilePath",
")",
";",
"return",
"$",
"temporaryFilePath",
";",
"}",
")",
"->",
"toArray",
"(",
")",
";",
"}"
] | Dumps the databases to the given directory.
Returns an array with paths to the dump files.
@return array | [
"Dumps",
"the",
"databases",
"to",
"the",
"given",
"directory",
".",
"Returns",
"an",
"array",
"with",
"paths",
"to",
"the",
"dump",
"files",
"."
] | d706e64c2500fda276d421551c140693156c0195 | https://github.com/spatie/laravel-backup/blob/d706e64c2500fda276d421551c140693156c0195/src/Tasks/Backup/BackupJob.php#L224-L254 | train |
spatie/laravel-backup | src/Tasks/Backup/FileSelection.php | FileSelection.excludeFilesFrom | public function excludeFilesFrom($excludeFilesAndDirectories): self
{
$this->excludeFilesAndDirectories = $this->excludeFilesAndDirectories->merge($this->sanitize($excludeFilesAndDirectories));
return $this;
} | php | public function excludeFilesFrom($excludeFilesAndDirectories): self
{
$this->excludeFilesAndDirectories = $this->excludeFilesAndDirectories->merge($this->sanitize($excludeFilesAndDirectories));
return $this;
} | [
"public",
"function",
"excludeFilesFrom",
"(",
"$",
"excludeFilesAndDirectories",
")",
":",
"self",
"{",
"$",
"this",
"->",
"excludeFilesAndDirectories",
"=",
"$",
"this",
"->",
"excludeFilesAndDirectories",
"->",
"merge",
"(",
"$",
"this",
"->",
"sanitize",
"(",
"$",
"excludeFilesAndDirectories",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Do not included the given files and directories.
@param array|string $excludeFilesAndDirectories
@return \Spatie\Backup\Tasks\Backup\FileSelection | [
"Do",
"not",
"included",
"the",
"given",
"files",
"and",
"directories",
"."
] | d706e64c2500fda276d421551c140693156c0195 | https://github.com/spatie/laravel-backup/blob/d706e64c2500fda276d421551c140693156c0195/src/Tasks/Backup/FileSelection.php#L47-L52 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Wire/AMQPWriter.php | AMQPWriter.write_bits | public function write_bits($bits)
{
$value = 0;
foreach ($bits as $n => $bit) {
$bit = $bit ? 1 : 0;
$value |= ($bit << $n);
}
$this->out .= chr($value);
return $this;
} | php | public function write_bits($bits)
{
$value = 0;
foreach ($bits as $n => $bit) {
$bit = $bit ? 1 : 0;
$value |= ($bit << $n);
}
$this->out .= chr($value);
return $this;
} | [
"public",
"function",
"write_bits",
"(",
"$",
"bits",
")",
"{",
"$",
"value",
"=",
"0",
";",
"foreach",
"(",
"$",
"bits",
"as",
"$",
"n",
"=>",
"$",
"bit",
")",
"{",
"$",
"bit",
"=",
"$",
"bit",
"?",
"1",
":",
"0",
";",
"$",
"value",
"|=",
"(",
"$",
"bit",
"<<",
"$",
"n",
")",
";",
"}",
"$",
"this",
"->",
"out",
".=",
"chr",
"(",
"$",
"value",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Write multiple bits as an octet
@param bool[] $bits
@return $this | [
"Write",
"multiple",
"bits",
"as",
"an",
"octet"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Wire/AMQPWriter.php#L143-L155 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Wire/AMQPWriter.php | AMQPWriter.write_octet | public function write_octet($n)
{
if ($n < 0 || $n > 255) {
throw new AMQPInvalidArgumentException('Octet out of range: ' . $n);
}
$this->out .= chr($n);
return $this;
} | php | public function write_octet($n)
{
if ($n < 0 || $n > 255) {
throw new AMQPInvalidArgumentException('Octet out of range: ' . $n);
}
$this->out .= chr($n);
return $this;
} | [
"public",
"function",
"write_octet",
"(",
"$",
"n",
")",
"{",
"if",
"(",
"$",
"n",
"<",
"0",
"||",
"$",
"n",
">",
"255",
")",
"{",
"throw",
"new",
"AMQPInvalidArgumentException",
"(",
"'Octet out of range: '",
".",
"$",
"n",
")",
";",
"}",
"$",
"this",
"->",
"out",
".=",
"chr",
"(",
"$",
"n",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Write an integer as an unsigned 8-bit value
@param int $n
@return $this
@throws \PhpAmqpLib\Exception\AMQPInvalidArgumentException | [
"Write",
"an",
"integer",
"as",
"an",
"unsigned",
"8",
"-",
"bit",
"value"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Wire/AMQPWriter.php#L164-L173 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Wire/AMQPWriter.php | AMQPWriter.write_short | public function write_short($n)
{
if ($n < 0 || $n > 65535) {
throw new AMQPInvalidArgumentException('Short out of range: ' . $n);
}
$this->out .= pack('n', $n);
return $this;
} | php | public function write_short($n)
{
if ($n < 0 || $n > 65535) {
throw new AMQPInvalidArgumentException('Short out of range: ' . $n);
}
$this->out .= pack('n', $n);
return $this;
} | [
"public",
"function",
"write_short",
"(",
"$",
"n",
")",
"{",
"if",
"(",
"$",
"n",
"<",
"0",
"||",
"$",
"n",
">",
"65535",
")",
"{",
"throw",
"new",
"AMQPInvalidArgumentException",
"(",
"'Short out of range: '",
".",
"$",
"n",
")",
";",
"}",
"$",
"this",
"->",
"out",
".=",
"pack",
"(",
"'n'",
",",
"$",
"n",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Write an integer as an unsigned 16-bit value
@param int $n
@return $this
@throws \PhpAmqpLib\Exception\AMQPInvalidArgumentException | [
"Write",
"an",
"integer",
"as",
"an",
"unsigned",
"16",
"-",
"bit",
"value"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Wire/AMQPWriter.php#L197-L206 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Wire/AMQPWriter.php | AMQPWriter.write_long | public function write_long($n)
{
if (($n < 0) || ($n > 4294967295)) {
throw new AMQPInvalidArgumentException('Long out of range: ' . $n);
}
//Numeric strings >PHP_INT_MAX on 32bit are casted to PHP_INT_MAX, damn PHP
if (empty($this->is64bits) && is_string($n)) {
$n = (float) $n;
}
$this->out .= pack('N', $n);
return $this;
} | php | public function write_long($n)
{
if (($n < 0) || ($n > 4294967295)) {
throw new AMQPInvalidArgumentException('Long out of range: ' . $n);
}
//Numeric strings >PHP_INT_MAX on 32bit are casted to PHP_INT_MAX, damn PHP
if (empty($this->is64bits) && is_string($n)) {
$n = (float) $n;
}
$this->out .= pack('N', $n);
return $this;
} | [
"public",
"function",
"write_long",
"(",
"$",
"n",
")",
"{",
"if",
"(",
"(",
"$",
"n",
"<",
"0",
")",
"||",
"(",
"$",
"n",
">",
"4294967295",
")",
")",
"{",
"throw",
"new",
"AMQPInvalidArgumentException",
"(",
"'Long out of range: '",
".",
"$",
"n",
")",
";",
"}",
"//Numeric strings >PHP_INT_MAX on 32bit are casted to PHP_INT_MAX, damn PHP",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"is64bits",
")",
"&&",
"is_string",
"(",
"$",
"n",
")",
")",
"{",
"$",
"n",
"=",
"(",
"float",
")",
"$",
"n",
";",
"}",
"$",
"this",
"->",
"out",
".=",
"pack",
"(",
"'N'",
",",
"$",
"n",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Write an integer as an unsigned 32-bit value
@param int $n
@return $this | [
"Write",
"an",
"integer",
"as",
"an",
"unsigned",
"32",
"-",
"bit",
"value"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Wire/AMQPWriter.php#L229-L242 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Wire/AMQPWriter.php | AMQPWriter.write_longlong | public function write_longlong($n)
{
if ($n < 0) {
throw new AMQPInvalidArgumentException('Longlong out of range: ' . $n);
}
// if PHP_INT_MAX is big enough for that
// direct $n<=PHP_INT_MAX check is unreliable on 64bit (values close to max) due to limited float precision
if (bcadd($n, -PHP_INT_MAX, 0) <= 0) {
// trick explained in http://www.php.net/manual/fr/function.pack.php#109328
if ($this->is64bits) {
list($hi, $lo) = $this->splitIntoQuads($n);
} else {
$hi = 0;
$lo = $n;
} //on 32bits hi quad is 0 a priori
$this->out .= pack('NN', $hi, $lo);
} else {
try {
$this->out .= self::packBigEndian($n, 8);
} catch (AMQPOutOfBoundsException $ex) {
throw new AMQPInvalidArgumentException('Longlong out of range: ' . $n, 0, $ex);
}
}
return $this;
} | php | public function write_longlong($n)
{
if ($n < 0) {
throw new AMQPInvalidArgumentException('Longlong out of range: ' . $n);
}
// if PHP_INT_MAX is big enough for that
// direct $n<=PHP_INT_MAX check is unreliable on 64bit (values close to max) due to limited float precision
if (bcadd($n, -PHP_INT_MAX, 0) <= 0) {
// trick explained in http://www.php.net/manual/fr/function.pack.php#109328
if ($this->is64bits) {
list($hi, $lo) = $this->splitIntoQuads($n);
} else {
$hi = 0;
$lo = $n;
} //on 32bits hi quad is 0 a priori
$this->out .= pack('NN', $hi, $lo);
} else {
try {
$this->out .= self::packBigEndian($n, 8);
} catch (AMQPOutOfBoundsException $ex) {
throw new AMQPInvalidArgumentException('Longlong out of range: ' . $n, 0, $ex);
}
}
return $this;
} | [
"public",
"function",
"write_longlong",
"(",
"$",
"n",
")",
"{",
"if",
"(",
"$",
"n",
"<",
"0",
")",
"{",
"throw",
"new",
"AMQPInvalidArgumentException",
"(",
"'Longlong out of range: '",
".",
"$",
"n",
")",
";",
"}",
"// if PHP_INT_MAX is big enough for that",
"// direct $n<=PHP_INT_MAX check is unreliable on 64bit (values close to max) due to limited float precision",
"if",
"(",
"bcadd",
"(",
"$",
"n",
",",
"-",
"PHP_INT_MAX",
",",
"0",
")",
"<=",
"0",
")",
"{",
"// trick explained in http://www.php.net/manual/fr/function.pack.php#109328",
"if",
"(",
"$",
"this",
"->",
"is64bits",
")",
"{",
"list",
"(",
"$",
"hi",
",",
"$",
"lo",
")",
"=",
"$",
"this",
"->",
"splitIntoQuads",
"(",
"$",
"n",
")",
";",
"}",
"else",
"{",
"$",
"hi",
"=",
"0",
";",
"$",
"lo",
"=",
"$",
"n",
";",
"}",
"//on 32bits hi quad is 0 a priori",
"$",
"this",
"->",
"out",
".=",
"pack",
"(",
"'NN'",
",",
"$",
"hi",
",",
"$",
"lo",
")",
";",
"}",
"else",
"{",
"try",
"{",
"$",
"this",
"->",
"out",
".=",
"self",
"::",
"packBigEndian",
"(",
"$",
"n",
",",
"8",
")",
";",
"}",
"catch",
"(",
"AMQPOutOfBoundsException",
"$",
"ex",
")",
"{",
"throw",
"new",
"AMQPInvalidArgumentException",
"(",
"'Longlong out of range: '",
".",
"$",
"n",
",",
"0",
",",
"$",
"ex",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Write an integer as an unsigned 64-bit value
@param int $n
@return $this | [
"Write",
"an",
"integer",
"as",
"an",
"unsigned",
"64",
"-",
"bit",
"value"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Wire/AMQPWriter.php#L266-L292 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Wire/AMQPWriter.php | AMQPWriter.write_shortstr | public function write_shortstr($s)
{
$len = mb_strlen($s, 'ASCII');
if ($len > 255) {
throw new AMQPInvalidArgumentException('String too long');
}
$this->write_octet($len);
$this->out .= $s;
return $this;
} | php | public function write_shortstr($s)
{
$len = mb_strlen($s, 'ASCII');
if ($len > 255) {
throw new AMQPInvalidArgumentException('String too long');
}
$this->write_octet($len);
$this->out .= $s;
return $this;
} | [
"public",
"function",
"write_shortstr",
"(",
"$",
"s",
")",
"{",
"$",
"len",
"=",
"mb_strlen",
"(",
"$",
"s",
",",
"'ASCII'",
")",
";",
"if",
"(",
"$",
"len",
">",
"255",
")",
"{",
"throw",
"new",
"AMQPInvalidArgumentException",
"(",
"'String too long'",
")",
";",
"}",
"$",
"this",
"->",
"write_octet",
"(",
"$",
"len",
")",
";",
"$",
"this",
"->",
"out",
".=",
"$",
"s",
";",
"return",
"$",
"this",
";",
"}"
] | Write a string up to 255 bytes long after encoding.
Assume UTF-8 encoding
@param string $s
@return $this
@throws \PhpAmqpLib\Exception\AMQPInvalidArgumentException | [
"Write",
"a",
"string",
"up",
"to",
"255",
"bytes",
"long",
"after",
"encoding",
".",
"Assume",
"UTF",
"-",
"8",
"encoding"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Wire/AMQPWriter.php#L344-L355 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Channel/AbstractChannel.php | AbstractChannel.prepare_method_frame | protected function prepare_method_frame($method_sig, $args = '', $pkt = null)
{
return $this->connection->prepare_channel_method_frame($this->channel_id, $method_sig, $args, $pkt);
} | php | protected function prepare_method_frame($method_sig, $args = '', $pkt = null)
{
return $this->connection->prepare_channel_method_frame($this->channel_id, $method_sig, $args, $pkt);
} | [
"protected",
"function",
"prepare_method_frame",
"(",
"$",
"method_sig",
",",
"$",
"args",
"=",
"''",
",",
"$",
"pkt",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"connection",
"->",
"prepare_channel_method_frame",
"(",
"$",
"this",
"->",
"channel_id",
",",
"$",
"method_sig",
",",
"$",
"args",
",",
"$",
"pkt",
")",
";",
"}"
] | This is here for performance reasons to batch calls to fwrite from basic.publish
@param array $method_sig
@param \PhpAmqpLib\Wire\AMQPWriter|string $args
@param \PhpAmqpLib\Wire\AMQPWriter $pkt
@return \PhpAmqpLib\Wire\AMQPWriter | [
"This",
"is",
"here",
"for",
"performance",
"reasons",
"to",
"batch",
"calls",
"to",
"fwrite",
"from",
"basic",
".",
"publish"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Channel/AbstractChannel.php#L257-L260 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Channel/AbstractChannel.php | AbstractChannel.wait | public function wait($allowed_methods = null, $non_blocking = false, $timeout = 0)
{
$this->debug->debug_allowed_methods($allowed_methods);
$deferred = $this->process_deferred_methods($allowed_methods);
if ($deferred['dispatch'] === true) {
return $this->dispatch_deferred_method($deferred['queued_method']);
}
// timeouts must be deactivated for non-blocking actions
if (true === $non_blocking) {
$timeout = null;
}
// No deferred methods? wait for new ones
while (true) {
try {
list($frame_type, $payload) = $this->next_frame($timeout);
} catch (AMQPNoDataException $e) {
// no data ready for non-blocking actions - stop and exit
break;
} catch (AMQPConnectionClosedException $exception) {
if ($this instanceof AMQPChannel) {
$this->do_close();
}
throw $exception;
}
$this->validate_method_frame($frame_type);
$this->validate_frame_payload($payload);
$method_sig = $this->build_method_signature($payload);
$args = $this->extract_args($payload);
$this->debug->debug_method_signature('> %s', $method_sig);
$amqpMessage = $this->maybe_wait_for_content($method_sig);
if ($this->should_dispatch_method($allowed_methods, $method_sig)) {
return $this->dispatch($method_sig, $args, $amqpMessage);
}
// Wasn't what we were looking for? save it for later
$this->debug->debug_method_signature('Queueing for later: %s', $method_sig);
$this->method_queue[] = array($method_sig, $args, $amqpMessage);
if ($non_blocking) {
break;
}
}
} | php | public function wait($allowed_methods = null, $non_blocking = false, $timeout = 0)
{
$this->debug->debug_allowed_methods($allowed_methods);
$deferred = $this->process_deferred_methods($allowed_methods);
if ($deferred['dispatch'] === true) {
return $this->dispatch_deferred_method($deferred['queued_method']);
}
// timeouts must be deactivated for non-blocking actions
if (true === $non_blocking) {
$timeout = null;
}
// No deferred methods? wait for new ones
while (true) {
try {
list($frame_type, $payload) = $this->next_frame($timeout);
} catch (AMQPNoDataException $e) {
// no data ready for non-blocking actions - stop and exit
break;
} catch (AMQPConnectionClosedException $exception) {
if ($this instanceof AMQPChannel) {
$this->do_close();
}
throw $exception;
}
$this->validate_method_frame($frame_type);
$this->validate_frame_payload($payload);
$method_sig = $this->build_method_signature($payload);
$args = $this->extract_args($payload);
$this->debug->debug_method_signature('> %s', $method_sig);
$amqpMessage = $this->maybe_wait_for_content($method_sig);
if ($this->should_dispatch_method($allowed_methods, $method_sig)) {
return $this->dispatch($method_sig, $args, $amqpMessage);
}
// Wasn't what we were looking for? save it for later
$this->debug->debug_method_signature('Queueing for later: %s', $method_sig);
$this->method_queue[] = array($method_sig, $args, $amqpMessage);
if ($non_blocking) {
break;
}
}
} | [
"public",
"function",
"wait",
"(",
"$",
"allowed_methods",
"=",
"null",
",",
"$",
"non_blocking",
"=",
"false",
",",
"$",
"timeout",
"=",
"0",
")",
"{",
"$",
"this",
"->",
"debug",
"->",
"debug_allowed_methods",
"(",
"$",
"allowed_methods",
")",
";",
"$",
"deferred",
"=",
"$",
"this",
"->",
"process_deferred_methods",
"(",
"$",
"allowed_methods",
")",
";",
"if",
"(",
"$",
"deferred",
"[",
"'dispatch'",
"]",
"===",
"true",
")",
"{",
"return",
"$",
"this",
"->",
"dispatch_deferred_method",
"(",
"$",
"deferred",
"[",
"'queued_method'",
"]",
")",
";",
"}",
"// timeouts must be deactivated for non-blocking actions",
"if",
"(",
"true",
"===",
"$",
"non_blocking",
")",
"{",
"$",
"timeout",
"=",
"null",
";",
"}",
"// No deferred methods? wait for new ones",
"while",
"(",
"true",
")",
"{",
"try",
"{",
"list",
"(",
"$",
"frame_type",
",",
"$",
"payload",
")",
"=",
"$",
"this",
"->",
"next_frame",
"(",
"$",
"timeout",
")",
";",
"}",
"catch",
"(",
"AMQPNoDataException",
"$",
"e",
")",
"{",
"// no data ready for non-blocking actions - stop and exit",
"break",
";",
"}",
"catch",
"(",
"AMQPConnectionClosedException",
"$",
"exception",
")",
"{",
"if",
"(",
"$",
"this",
"instanceof",
"AMQPChannel",
")",
"{",
"$",
"this",
"->",
"do_close",
"(",
")",
";",
"}",
"throw",
"$",
"exception",
";",
"}",
"$",
"this",
"->",
"validate_method_frame",
"(",
"$",
"frame_type",
")",
";",
"$",
"this",
"->",
"validate_frame_payload",
"(",
"$",
"payload",
")",
";",
"$",
"method_sig",
"=",
"$",
"this",
"->",
"build_method_signature",
"(",
"$",
"payload",
")",
";",
"$",
"args",
"=",
"$",
"this",
"->",
"extract_args",
"(",
"$",
"payload",
")",
";",
"$",
"this",
"->",
"debug",
"->",
"debug_method_signature",
"(",
"'> %s'",
",",
"$",
"method_sig",
")",
";",
"$",
"amqpMessage",
"=",
"$",
"this",
"->",
"maybe_wait_for_content",
"(",
"$",
"method_sig",
")",
";",
"if",
"(",
"$",
"this",
"->",
"should_dispatch_method",
"(",
"$",
"allowed_methods",
",",
"$",
"method_sig",
")",
")",
"{",
"return",
"$",
"this",
"->",
"dispatch",
"(",
"$",
"method_sig",
",",
"$",
"args",
",",
"$",
"amqpMessage",
")",
";",
"}",
"// Wasn't what we were looking for? save it for later",
"$",
"this",
"->",
"debug",
"->",
"debug_method_signature",
"(",
"'Queueing for later: %s'",
",",
"$",
"method_sig",
")",
";",
"$",
"this",
"->",
"method_queue",
"[",
"]",
"=",
"array",
"(",
"$",
"method_sig",
",",
"$",
"args",
",",
"$",
"amqpMessage",
")",
";",
"if",
"(",
"$",
"non_blocking",
")",
"{",
"break",
";",
"}",
"}",
"}"
] | Wait for some expected AMQP methods and dispatch to them.
Unexpected methods are queued up for later calls to this PHP
method.
@param array $allowed_methods
@param bool $non_blocking
@param int|float|null $timeout
@throws \PhpAmqpLib\Exception\AMQPOutOfBoundsException
@throws \PhpAmqpLib\Exception\AMQPRuntimeException
@throws \PhpAmqpLib\Exception\AMQPTimeoutException
@throws \ErrorException
@return mixed | [
"Wait",
"for",
"some",
"expected",
"AMQP",
"methods",
"and",
"dispatch",
"to",
"them",
".",
"Unexpected",
"methods",
"are",
"queued",
"up",
"for",
"later",
"calls",
"to",
"this",
"PHP",
"method",
"."
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Channel/AbstractChannel.php#L334-L384 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Wire/GenericContent.php | GenericContent.has | public function has($name)
{
return isset($this->properties[$name]) || isset($this->delivery_info[$name]);
} | php | public function has($name)
{
return isset($this->properties[$name]) || isset($this->delivery_info[$name]);
} | [
"public",
"function",
"has",
"(",
"$",
"name",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"properties",
"[",
"$",
"name",
"]",
")",
"||",
"isset",
"(",
"$",
"this",
"->",
"delivery_info",
"[",
"$",
"name",
"]",
")",
";",
"}"
] | Check whether a property exists in the 'properties' dictionary
or if present - in the 'delivery_info' dictionary.
@param string $name
@return bool | [
"Check",
"whether",
"a",
"property",
"exists",
"in",
"the",
"properties",
"dictionary",
"or",
"if",
"present",
"-",
"in",
"the",
"delivery_info",
"dictionary",
"."
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Wire/GenericContent.php#L51-L54 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Wire/GenericContent.php | GenericContent.get | public function get($name)
{
if (isset($this->properties[$name])) {
return $this->properties[$name];
}
if (isset($this->delivery_info[$name])) {
return $this->delivery_info[$name];
}
throw new \OutOfBoundsException(sprintf(
'No "%s" property',
$name
));
} | php | public function get($name)
{
if (isset($this->properties[$name])) {
return $this->properties[$name];
}
if (isset($this->delivery_info[$name])) {
return $this->delivery_info[$name];
}
throw new \OutOfBoundsException(sprintf(
'No "%s" property',
$name
));
} | [
"public",
"function",
"get",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"properties",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"properties",
"[",
"$",
"name",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"delivery_info",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"delivery_info",
"[",
"$",
"name",
"]",
";",
"}",
"throw",
"new",
"\\",
"OutOfBoundsException",
"(",
"sprintf",
"(",
"'No \"%s\" property'",
",",
"$",
"name",
")",
")",
";",
"}"
] | Look for additional properties in the 'properties' dictionary,
and if present - the 'delivery_info' dictionary.
@param string $name
@throws \OutOfBoundsException
@return mixed|AMQPChannel | [
"Look",
"for",
"additional",
"properties",
"in",
"the",
"properties",
"dictionary",
"and",
"if",
"present",
"-",
"the",
"delivery_info",
"dictionary",
"."
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Wire/GenericContent.php#L64-L78 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Wire/IO/AbstractIO.php | AbstractIO.write_heartbeat | protected function write_heartbeat()
{
$pkt = new AMQPWriter();
$pkt->write_octet(8);
$pkt->write_short(0);
$pkt->write_long(0);
$pkt->write_octet(0xCE);
$this->write($pkt->getvalue());
} | php | protected function write_heartbeat()
{
$pkt = new AMQPWriter();
$pkt->write_octet(8);
$pkt->write_short(0);
$pkt->write_long(0);
$pkt->write_octet(0xCE);
$this->write($pkt->getvalue());
} | [
"protected",
"function",
"write_heartbeat",
"(",
")",
"{",
"$",
"pkt",
"=",
"new",
"AMQPWriter",
"(",
")",
";",
"$",
"pkt",
"->",
"write_octet",
"(",
"8",
")",
";",
"$",
"pkt",
"->",
"write_short",
"(",
"0",
")",
";",
"$",
"pkt",
"->",
"write_long",
"(",
"0",
")",
";",
"$",
"pkt",
"->",
"write_octet",
"(",
"0xCE",
")",
";",
"$",
"this",
"->",
"write",
"(",
"$",
"pkt",
"->",
"getvalue",
"(",
")",
")",
";",
"}"
] | Sends a heartbeat message | [
"Sends",
"a",
"heartbeat",
"message"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Wire/IO/AbstractIO.php#L173-L181 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Wire/IO/AbstractIO.php | AbstractIO.cleanup_error_handler | protected function cleanup_error_handler()
{
restore_error_handler();
if ($this->last_error !== null) {
throw new \ErrorException(
$this->last_error['errstr'],
0,
$this->last_error['errno'],
$this->last_error['errfile'],
$this->last_error['errline']
);
}
} | php | protected function cleanup_error_handler()
{
restore_error_handler();
if ($this->last_error !== null) {
throw new \ErrorException(
$this->last_error['errstr'],
0,
$this->last_error['errno'],
$this->last_error['errfile'],
$this->last_error['errline']
);
}
} | [
"protected",
"function",
"cleanup_error_handler",
"(",
")",
"{",
"restore_error_handler",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"last_error",
"!==",
"null",
")",
"{",
"throw",
"new",
"\\",
"ErrorException",
"(",
"$",
"this",
"->",
"last_error",
"[",
"'errstr'",
"]",
",",
"0",
",",
"$",
"this",
"->",
"last_error",
"[",
"'errno'",
"]",
",",
"$",
"this",
"->",
"last_error",
"[",
"'errfile'",
"]",
",",
"$",
"this",
"->",
"last_error",
"[",
"'errline'",
"]",
")",
";",
"}",
"}"
] | throws an ErrorException if an error was handled
@throws \ErrorException | [
"throws",
"an",
"ErrorException",
"if",
"an",
"error",
"was",
"handled"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Wire/IO/AbstractIO.php#L196-L209 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Wire/IO/AbstractIO.php | AbstractIO.error_handler | public function error_handler($errno, $errstr, $errfile, $errline, $errcontext = null)
{
// throwing an exception in an error handler will halt execution
// set the last error and continue
$this->last_error = compact('errno', 'errstr', 'errfile', 'errline', 'errcontext');
} | php | public function error_handler($errno, $errstr, $errfile, $errline, $errcontext = null)
{
// throwing an exception in an error handler will halt execution
// set the last error and continue
$this->last_error = compact('errno', 'errstr', 'errfile', 'errline', 'errcontext');
} | [
"public",
"function",
"error_handler",
"(",
"$",
"errno",
",",
"$",
"errstr",
",",
"$",
"errfile",
",",
"$",
"errline",
",",
"$",
"errcontext",
"=",
"null",
")",
"{",
"// throwing an exception in an error handler will halt execution",
"// set the last error and continue",
"$",
"this",
"->",
"last_error",
"=",
"compact",
"(",
"'errno'",
",",
"'errstr'",
",",
"'errfile'",
",",
"'errline'",
",",
"'errcontext'",
")",
";",
"}"
] | Internal error handler to deal with stream and socket errors.
@param int $errno
@param string $errstr
@param string $errfile
@param int $errline
@param array $errcontext
@return void | [
"Internal",
"error",
"handler",
"to",
"deal",
"with",
"stream",
"and",
"socket",
"errors",
"."
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Wire/IO/AbstractIO.php#L221-L226 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Wire/AMQPReader.php | AMQPReader.reuse | public function reuse($str)
{
$this->str = $str;
$this->str_length = mb_strlen($this->str, 'ASCII');
$this->offset = 0;
$this->bitcount = $this->bits = 0;
} | php | public function reuse($str)
{
$this->str = $str;
$this->str_length = mb_strlen($this->str, 'ASCII');
$this->offset = 0;
$this->bitcount = $this->bits = 0;
} | [
"public",
"function",
"reuse",
"(",
"$",
"str",
")",
"{",
"$",
"this",
"->",
"str",
"=",
"$",
"str",
";",
"$",
"this",
"->",
"str_length",
"=",
"mb_strlen",
"(",
"$",
"this",
"->",
"str",
",",
"'ASCII'",
")",
";",
"$",
"this",
"->",
"offset",
"=",
"0",
";",
"$",
"this",
"->",
"bitcount",
"=",
"$",
"this",
"->",
"bits",
"=",
"0",
";",
"}"
] | Resets the object from the injected param
Used to not need to create a new AMQPReader instance every time.
when we can just pass a string and reset the object state.
NOTE: since we are working with strings we don't need to pass an AbstractIO
or a timeout.
@param string $str | [
"Resets",
"the",
"object",
"from",
"the",
"injected",
"param"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Wire/AMQPReader.php#L81-L87 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Wire/AMQPReader.php | AMQPReader.wait | protected function wait()
{
$timeout = $this->getTimeout();
if (null === $timeout) {
// timeout=null just poll state and return instantly
$sec = 0;
$usec = 0;
} elseif ($timeout > 0) {
list($sec, $usec) = MiscHelper::splitSecondsMicroseconds($this->getTimeout());
} else {
// wait indefinitely for data if timeout=0
$sec = null;
$usec = 0;
}
$result = $this->io->select($sec, $usec);
if ($result === false) {
throw new AMQPIOWaitException('A network error occurred while awaiting for incoming data');
}
if ($result === 0) {
if ($timeout > 0) {
throw new AMQPTimeoutException(sprintf(
'The connection timed out after %s sec while awaiting incoming data',
$timeout
));
} else {
throw new AMQPNoDataException('No data is ready to read');
}
}
} | php | protected function wait()
{
$timeout = $this->getTimeout();
if (null === $timeout) {
// timeout=null just poll state and return instantly
$sec = 0;
$usec = 0;
} elseif ($timeout > 0) {
list($sec, $usec) = MiscHelper::splitSecondsMicroseconds($this->getTimeout());
} else {
// wait indefinitely for data if timeout=0
$sec = null;
$usec = 0;
}
$result = $this->io->select($sec, $usec);
if ($result === false) {
throw new AMQPIOWaitException('A network error occurred while awaiting for incoming data');
}
if ($result === 0) {
if ($timeout > 0) {
throw new AMQPTimeoutException(sprintf(
'The connection timed out after %s sec while awaiting incoming data',
$timeout
));
} else {
throw new AMQPNoDataException('No data is ready to read');
}
}
} | [
"protected",
"function",
"wait",
"(",
")",
"{",
"$",
"timeout",
"=",
"$",
"this",
"->",
"getTimeout",
"(",
")",
";",
"if",
"(",
"null",
"===",
"$",
"timeout",
")",
"{",
"// timeout=null just poll state and return instantly",
"$",
"sec",
"=",
"0",
";",
"$",
"usec",
"=",
"0",
";",
"}",
"elseif",
"(",
"$",
"timeout",
">",
"0",
")",
"{",
"list",
"(",
"$",
"sec",
",",
"$",
"usec",
")",
"=",
"MiscHelper",
"::",
"splitSecondsMicroseconds",
"(",
"$",
"this",
"->",
"getTimeout",
"(",
")",
")",
";",
"}",
"else",
"{",
"// wait indefinitely for data if timeout=0",
"$",
"sec",
"=",
"null",
";",
"$",
"usec",
"=",
"0",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"io",
"->",
"select",
"(",
"$",
"sec",
",",
"$",
"usec",
")",
";",
"if",
"(",
"$",
"result",
"===",
"false",
")",
"{",
"throw",
"new",
"AMQPIOWaitException",
"(",
"'A network error occurred while awaiting for incoming data'",
")",
";",
"}",
"if",
"(",
"$",
"result",
"===",
"0",
")",
"{",
"if",
"(",
"$",
"timeout",
">",
"0",
")",
"{",
"throw",
"new",
"AMQPTimeoutException",
"(",
"sprintf",
"(",
"'The connection timed out after %s sec while awaiting incoming data'",
",",
"$",
"timeout",
")",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"AMQPNoDataException",
"(",
"'No data is ready to read'",
")",
";",
"}",
"}",
"}"
] | Waits until some data is retrieved from the socket.
AMQPTimeoutException can be raised if the timeout is set
@throws \PhpAmqpLib\Exception\AMQPIOWaitException on network errors
@throws \PhpAmqpLib\Exception\AMQPTimeoutException when timeout is set and no data received
@throws \PhpAmqpLib\Exception\AMQPNoDataException when no data is ready to read from IO | [
"Waits",
"until",
"some",
"data",
"is",
"retrieved",
"from",
"the",
"socket",
"."
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Wire/AMQPReader.php#L119-L150 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Wire/AMQPReader.php | AMQPReader.read_longlong | public function read_longlong()
{
$this->bitcount = $this->bits = 0;
list(, $hi, $lo) = unpack('N2', $this->rawread(8));
$msb = self::getLongMSB($hi);
if (empty($this->is64bits)) {
if ($msb) {
$hi = sprintf('%u', $hi);
}
if (self::getLongMSB($lo)) {
$lo = sprintf('%u', $lo);
}
}
return bcadd($this->is64bits && !$msb ? $hi << 32 : bcmul($hi, '4294967296', 0), $lo, 0);
} | php | public function read_longlong()
{
$this->bitcount = $this->bits = 0;
list(, $hi, $lo) = unpack('N2', $this->rawread(8));
$msb = self::getLongMSB($hi);
if (empty($this->is64bits)) {
if ($msb) {
$hi = sprintf('%u', $hi);
}
if (self::getLongMSB($lo)) {
$lo = sprintf('%u', $lo);
}
}
return bcadd($this->is64bits && !$msb ? $hi << 32 : bcmul($hi, '4294967296', 0), $lo, 0);
} | [
"public",
"function",
"read_longlong",
"(",
")",
"{",
"$",
"this",
"->",
"bitcount",
"=",
"$",
"this",
"->",
"bits",
"=",
"0",
";",
"list",
"(",
",",
"$",
"hi",
",",
"$",
"lo",
")",
"=",
"unpack",
"(",
"'N2'",
",",
"$",
"this",
"->",
"rawread",
"(",
"8",
")",
")",
";",
"$",
"msb",
"=",
"self",
"::",
"getLongMSB",
"(",
"$",
"hi",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"is64bits",
")",
")",
"{",
"if",
"(",
"$",
"msb",
")",
"{",
"$",
"hi",
"=",
"sprintf",
"(",
"'%u'",
",",
"$",
"hi",
")",
";",
"}",
"if",
"(",
"self",
"::",
"getLongMSB",
"(",
"$",
"lo",
")",
")",
"{",
"$",
"lo",
"=",
"sprintf",
"(",
"'%u'",
",",
"$",
"lo",
")",
";",
"}",
"}",
"return",
"bcadd",
"(",
"$",
"this",
"->",
"is64bits",
"&&",
"!",
"$",
"msb",
"?",
"$",
"hi",
"<<",
"32",
":",
"bcmul",
"(",
"$",
"hi",
",",
"'4294967296'",
",",
"0",
")",
",",
"$",
"lo",
",",
"0",
")",
";",
"}"
] | Even on 64 bit systems PHP integers are singed.
Since we need an unsigned value here we return it
as a string.
@return string | [
"Even",
"on",
"64",
"bit",
"systems",
"PHP",
"integers",
"are",
"singed",
".",
"Since",
"we",
"need",
"an",
"unsigned",
"value",
"here",
"we",
"return",
"it",
"as",
"a",
"string",
"."
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Wire/AMQPReader.php#L308-L325 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Wire/AMQPReader.php | AMQPReader.read_array | public function read_array($returnObject = false)
{
$this->bitcount = $this->bits = 0;
// Determine array length and its end position
$arrayLength = $this->read_php_int();
$endOffset = $this->offset + $arrayLength;
$result = $returnObject ? new AMQPArray() : array();
// Read values until we reach the end of the array
while ($this->offset < $endOffset) {
$fieldType = AMQPAbstractCollection::getDataTypeForSymbol($this->rawread(1));
$fieldValue = $this->read_value($fieldType, $returnObject);
$returnObject ? $result->push($fieldValue, $fieldType) : $result[] = $fieldValue;
}
return $result;
} | php | public function read_array($returnObject = false)
{
$this->bitcount = $this->bits = 0;
// Determine array length and its end position
$arrayLength = $this->read_php_int();
$endOffset = $this->offset + $arrayLength;
$result = $returnObject ? new AMQPArray() : array();
// Read values until we reach the end of the array
while ($this->offset < $endOffset) {
$fieldType = AMQPAbstractCollection::getDataTypeForSymbol($this->rawread(1));
$fieldValue = $this->read_value($fieldType, $returnObject);
$returnObject ? $result->push($fieldValue, $fieldType) : $result[] = $fieldValue;
}
return $result;
} | [
"public",
"function",
"read_array",
"(",
"$",
"returnObject",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"bitcount",
"=",
"$",
"this",
"->",
"bits",
"=",
"0",
";",
"// Determine array length and its end position",
"$",
"arrayLength",
"=",
"$",
"this",
"->",
"read_php_int",
"(",
")",
";",
"$",
"endOffset",
"=",
"$",
"this",
"->",
"offset",
"+",
"$",
"arrayLength",
";",
"$",
"result",
"=",
"$",
"returnObject",
"?",
"new",
"AMQPArray",
"(",
")",
":",
"array",
"(",
")",
";",
"// Read values until we reach the end of the array",
"while",
"(",
"$",
"this",
"->",
"offset",
"<",
"$",
"endOffset",
")",
"{",
"$",
"fieldType",
"=",
"AMQPAbstractCollection",
"::",
"getDataTypeForSymbol",
"(",
"$",
"this",
"->",
"rawread",
"(",
"1",
")",
")",
";",
"$",
"fieldValue",
"=",
"$",
"this",
"->",
"read_value",
"(",
"$",
"fieldType",
",",
"$",
"returnObject",
")",
";",
"$",
"returnObject",
"?",
"$",
"result",
"->",
"push",
"(",
"$",
"fieldValue",
",",
"$",
"fieldType",
")",
":",
"$",
"result",
"[",
"]",
"=",
"$",
"fieldValue",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Reads the array in the next value.
@param bool $returnObject Whether to return AMQPArray instance instead of plain array
@return array|AMQPArray | [
"Reads",
"the",
"array",
"in",
"the",
"next",
"value",
"."
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Wire/AMQPReader.php#L433-L451 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Wire/AMQPReader.php | AMQPReader.read_value | public function read_value($fieldType, $collectionsAsObjects = false)
{
$this->bitcount = $this->bits = 0;
switch ($fieldType) {
case AMQPAbstractCollection::T_INT_SHORTSHORT:
//according to AMQP091 spec, 'b' is not bit, it is short-short-int, also valid for rabbit/qpid
//$val=$this->read_bit();
$val = $this->read_signed_octet();
break;
case AMQPAbstractCollection::T_INT_SHORTSHORT_U:
$val = $this->read_octet();
break;
case AMQPAbstractCollection::T_INT_SHORT:
$val = $this->read_signed_short();
break;
case AMQPAbstractCollection::T_INT_SHORT_U:
$val = $this->read_short();
break;
case AMQPAbstractCollection::T_INT_LONG:
$val = $this->read_signed_long();
break;
case AMQPAbstractCollection::T_INT_LONG_U:
$val = $this->read_long();
break;
case AMQPAbstractCollection::T_INT_LONGLONG:
$val = $this->read_signed_longlong();
break;
case AMQPAbstractCollection::T_INT_LONGLONG_U:
$val = $this->read_longlong();
break;
case AMQPAbstractCollection::T_DECIMAL:
$e = $this->read_octet();
$n = $this->read_signed_long();
$val = new AMQPDecimal($n, $e);
break;
case AMQPAbstractCollection::T_TIMESTAMP:
$val = $this->read_timestamp();
break;
case AMQPAbstractCollection::T_BOOL:
$val = $this->read_octet();
break;
case AMQPAbstractCollection::T_STRING_SHORT:
$val = $this->read_shortstr();
break;
case AMQPAbstractCollection::T_STRING_LONG:
$val = $this->read_longstr();
break;
case AMQPAbstractCollection::T_ARRAY:
$val = $this->read_array($collectionsAsObjects);
break;
case AMQPAbstractCollection::T_TABLE:
$val = $this->read_table($collectionsAsObjects);
break;
case AMQPAbstractCollection::T_VOID:
$val = null;
break;
case AMQPAbstractCollection::T_BYTES:
$val = $this->read_longstr();
break;
default:
throw new AMQPInvalidArgumentException(sprintf(
'Unsupported type "%s"',
$fieldType
));
}
return isset($val) ? $val : null;
} | php | public function read_value($fieldType, $collectionsAsObjects = false)
{
$this->bitcount = $this->bits = 0;
switch ($fieldType) {
case AMQPAbstractCollection::T_INT_SHORTSHORT:
//according to AMQP091 spec, 'b' is not bit, it is short-short-int, also valid for rabbit/qpid
//$val=$this->read_bit();
$val = $this->read_signed_octet();
break;
case AMQPAbstractCollection::T_INT_SHORTSHORT_U:
$val = $this->read_octet();
break;
case AMQPAbstractCollection::T_INT_SHORT:
$val = $this->read_signed_short();
break;
case AMQPAbstractCollection::T_INT_SHORT_U:
$val = $this->read_short();
break;
case AMQPAbstractCollection::T_INT_LONG:
$val = $this->read_signed_long();
break;
case AMQPAbstractCollection::T_INT_LONG_U:
$val = $this->read_long();
break;
case AMQPAbstractCollection::T_INT_LONGLONG:
$val = $this->read_signed_longlong();
break;
case AMQPAbstractCollection::T_INT_LONGLONG_U:
$val = $this->read_longlong();
break;
case AMQPAbstractCollection::T_DECIMAL:
$e = $this->read_octet();
$n = $this->read_signed_long();
$val = new AMQPDecimal($n, $e);
break;
case AMQPAbstractCollection::T_TIMESTAMP:
$val = $this->read_timestamp();
break;
case AMQPAbstractCollection::T_BOOL:
$val = $this->read_octet();
break;
case AMQPAbstractCollection::T_STRING_SHORT:
$val = $this->read_shortstr();
break;
case AMQPAbstractCollection::T_STRING_LONG:
$val = $this->read_longstr();
break;
case AMQPAbstractCollection::T_ARRAY:
$val = $this->read_array($collectionsAsObjects);
break;
case AMQPAbstractCollection::T_TABLE:
$val = $this->read_table($collectionsAsObjects);
break;
case AMQPAbstractCollection::T_VOID:
$val = null;
break;
case AMQPAbstractCollection::T_BYTES:
$val = $this->read_longstr();
break;
default:
throw new AMQPInvalidArgumentException(sprintf(
'Unsupported type "%s"',
$fieldType
));
}
return isset($val) ? $val : null;
} | [
"public",
"function",
"read_value",
"(",
"$",
"fieldType",
",",
"$",
"collectionsAsObjects",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"bitcount",
"=",
"$",
"this",
"->",
"bits",
"=",
"0",
";",
"switch",
"(",
"$",
"fieldType",
")",
"{",
"case",
"AMQPAbstractCollection",
"::",
"T_INT_SHORTSHORT",
":",
"//according to AMQP091 spec, 'b' is not bit, it is short-short-int, also valid for rabbit/qpid",
"//$val=$this->read_bit();",
"$",
"val",
"=",
"$",
"this",
"->",
"read_signed_octet",
"(",
")",
";",
"break",
";",
"case",
"AMQPAbstractCollection",
"::",
"T_INT_SHORTSHORT_U",
":",
"$",
"val",
"=",
"$",
"this",
"->",
"read_octet",
"(",
")",
";",
"break",
";",
"case",
"AMQPAbstractCollection",
"::",
"T_INT_SHORT",
":",
"$",
"val",
"=",
"$",
"this",
"->",
"read_signed_short",
"(",
")",
";",
"break",
";",
"case",
"AMQPAbstractCollection",
"::",
"T_INT_SHORT_U",
":",
"$",
"val",
"=",
"$",
"this",
"->",
"read_short",
"(",
")",
";",
"break",
";",
"case",
"AMQPAbstractCollection",
"::",
"T_INT_LONG",
":",
"$",
"val",
"=",
"$",
"this",
"->",
"read_signed_long",
"(",
")",
";",
"break",
";",
"case",
"AMQPAbstractCollection",
"::",
"T_INT_LONG_U",
":",
"$",
"val",
"=",
"$",
"this",
"->",
"read_long",
"(",
")",
";",
"break",
";",
"case",
"AMQPAbstractCollection",
"::",
"T_INT_LONGLONG",
":",
"$",
"val",
"=",
"$",
"this",
"->",
"read_signed_longlong",
"(",
")",
";",
"break",
";",
"case",
"AMQPAbstractCollection",
"::",
"T_INT_LONGLONG_U",
":",
"$",
"val",
"=",
"$",
"this",
"->",
"read_longlong",
"(",
")",
";",
"break",
";",
"case",
"AMQPAbstractCollection",
"::",
"T_DECIMAL",
":",
"$",
"e",
"=",
"$",
"this",
"->",
"read_octet",
"(",
")",
";",
"$",
"n",
"=",
"$",
"this",
"->",
"read_signed_long",
"(",
")",
";",
"$",
"val",
"=",
"new",
"AMQPDecimal",
"(",
"$",
"n",
",",
"$",
"e",
")",
";",
"break",
";",
"case",
"AMQPAbstractCollection",
"::",
"T_TIMESTAMP",
":",
"$",
"val",
"=",
"$",
"this",
"->",
"read_timestamp",
"(",
")",
";",
"break",
";",
"case",
"AMQPAbstractCollection",
"::",
"T_BOOL",
":",
"$",
"val",
"=",
"$",
"this",
"->",
"read_octet",
"(",
")",
";",
"break",
";",
"case",
"AMQPAbstractCollection",
"::",
"T_STRING_SHORT",
":",
"$",
"val",
"=",
"$",
"this",
"->",
"read_shortstr",
"(",
")",
";",
"break",
";",
"case",
"AMQPAbstractCollection",
"::",
"T_STRING_LONG",
":",
"$",
"val",
"=",
"$",
"this",
"->",
"read_longstr",
"(",
")",
";",
"break",
";",
"case",
"AMQPAbstractCollection",
"::",
"T_ARRAY",
":",
"$",
"val",
"=",
"$",
"this",
"->",
"read_array",
"(",
"$",
"collectionsAsObjects",
")",
";",
"break",
";",
"case",
"AMQPAbstractCollection",
"::",
"T_TABLE",
":",
"$",
"val",
"=",
"$",
"this",
"->",
"read_table",
"(",
"$",
"collectionsAsObjects",
")",
";",
"break",
";",
"case",
"AMQPAbstractCollection",
"::",
"T_VOID",
":",
"$",
"val",
"=",
"null",
";",
"break",
";",
"case",
"AMQPAbstractCollection",
"::",
"T_BYTES",
":",
"$",
"val",
"=",
"$",
"this",
"->",
"read_longstr",
"(",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"AMQPInvalidArgumentException",
"(",
"sprintf",
"(",
"'Unsupported type \"%s\"'",
",",
"$",
"fieldType",
")",
")",
";",
"}",
"return",
"isset",
"(",
"$",
"val",
")",
"?",
"$",
"val",
":",
"null",
";",
"}"
] | Reads the next value as the provided field type.
@param int $fieldType One of AMQPAbstractCollection::T_* constants
@param bool $collectionsAsObjects Description
@return mixed
@throws \PhpAmqpLib\Exception\AMQPDataReadException | [
"Reads",
"the",
"next",
"value",
"as",
"the",
"provided",
"field",
"type",
"."
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Wire/AMQPReader.php#L469-L537 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Connection/AbstractConnection.php | AbstractConnection.connect | protected function connect()
{
try {
// Loop until we connect
while (!$this->isConnected()) {
// Assume we will connect, until we dont
$this->setIsConnected(true);
// Connect the socket
$this->io->connect();
$this->channels = array();
// The connection object itself is treated as channel 0
parent::__construct($this, 0);
$this->input = new AMQPReader(null, $this->io);
$this->write($this->amqp_protocol_header);
$this->wait(array($this->waitHelper->get_wait('connection.start')),false,$this->connection_timeout);
$this->x_start_ok(
$this->getLibraryProperties(),
$this->login_method,
$this->login_response,
$this->locale
);
$this->wait_tune_ok = true;
while ($this->wait_tune_ok) {
$this->wait(array(
$this->waitHelper->get_wait('connection.secure'),
$this->waitHelper->get_wait('connection.tune')
));
}
$host = $this->x_open($this->vhost, '', $this->insist);
if (!$host) {
//Reconnected
$this->io->reenableHeartbeat();
return null; // we weren't redirected
}
$this->setIsConnected(false);
$this->closeChannels();
// we were redirected, close the socket, loop and try again
$this->close_socket();
}
} catch (\Exception $e) {
// Something went wrong, set the connection status
$this->setIsConnected(false);
$this->closeChannels();
$this->close_input();
$this->close_socket();
throw $e; // Rethrow exception
}
} | php | protected function connect()
{
try {
// Loop until we connect
while (!$this->isConnected()) {
// Assume we will connect, until we dont
$this->setIsConnected(true);
// Connect the socket
$this->io->connect();
$this->channels = array();
// The connection object itself is treated as channel 0
parent::__construct($this, 0);
$this->input = new AMQPReader(null, $this->io);
$this->write($this->amqp_protocol_header);
$this->wait(array($this->waitHelper->get_wait('connection.start')),false,$this->connection_timeout);
$this->x_start_ok(
$this->getLibraryProperties(),
$this->login_method,
$this->login_response,
$this->locale
);
$this->wait_tune_ok = true;
while ($this->wait_tune_ok) {
$this->wait(array(
$this->waitHelper->get_wait('connection.secure'),
$this->waitHelper->get_wait('connection.tune')
));
}
$host = $this->x_open($this->vhost, '', $this->insist);
if (!$host) {
//Reconnected
$this->io->reenableHeartbeat();
return null; // we weren't redirected
}
$this->setIsConnected(false);
$this->closeChannels();
// we were redirected, close the socket, loop and try again
$this->close_socket();
}
} catch (\Exception $e) {
// Something went wrong, set the connection status
$this->setIsConnected(false);
$this->closeChannels();
$this->close_input();
$this->close_socket();
throw $e; // Rethrow exception
}
} | [
"protected",
"function",
"connect",
"(",
")",
"{",
"try",
"{",
"// Loop until we connect",
"while",
"(",
"!",
"$",
"this",
"->",
"isConnected",
"(",
")",
")",
"{",
"// Assume we will connect, until we dont",
"$",
"this",
"->",
"setIsConnected",
"(",
"true",
")",
";",
"// Connect the socket",
"$",
"this",
"->",
"io",
"->",
"connect",
"(",
")",
";",
"$",
"this",
"->",
"channels",
"=",
"array",
"(",
")",
";",
"// The connection object itself is treated as channel 0",
"parent",
"::",
"__construct",
"(",
"$",
"this",
",",
"0",
")",
";",
"$",
"this",
"->",
"input",
"=",
"new",
"AMQPReader",
"(",
"null",
",",
"$",
"this",
"->",
"io",
")",
";",
"$",
"this",
"->",
"write",
"(",
"$",
"this",
"->",
"amqp_protocol_header",
")",
";",
"$",
"this",
"->",
"wait",
"(",
"array",
"(",
"$",
"this",
"->",
"waitHelper",
"->",
"get_wait",
"(",
"'connection.start'",
")",
")",
",",
"false",
",",
"$",
"this",
"->",
"connection_timeout",
")",
";",
"$",
"this",
"->",
"x_start_ok",
"(",
"$",
"this",
"->",
"getLibraryProperties",
"(",
")",
",",
"$",
"this",
"->",
"login_method",
",",
"$",
"this",
"->",
"login_response",
",",
"$",
"this",
"->",
"locale",
")",
";",
"$",
"this",
"->",
"wait_tune_ok",
"=",
"true",
";",
"while",
"(",
"$",
"this",
"->",
"wait_tune_ok",
")",
"{",
"$",
"this",
"->",
"wait",
"(",
"array",
"(",
"$",
"this",
"->",
"waitHelper",
"->",
"get_wait",
"(",
"'connection.secure'",
")",
",",
"$",
"this",
"->",
"waitHelper",
"->",
"get_wait",
"(",
"'connection.tune'",
")",
")",
")",
";",
"}",
"$",
"host",
"=",
"$",
"this",
"->",
"x_open",
"(",
"$",
"this",
"->",
"vhost",
",",
"''",
",",
"$",
"this",
"->",
"insist",
")",
";",
"if",
"(",
"!",
"$",
"host",
")",
"{",
"//Reconnected",
"$",
"this",
"->",
"io",
"->",
"reenableHeartbeat",
"(",
")",
";",
"return",
"null",
";",
"// we weren't redirected",
"}",
"$",
"this",
"->",
"setIsConnected",
"(",
"false",
")",
";",
"$",
"this",
"->",
"closeChannels",
"(",
")",
";",
"// we were redirected, close the socket, loop and try again",
"$",
"this",
"->",
"close_socket",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"// Something went wrong, set the connection status",
"$",
"this",
"->",
"setIsConnected",
"(",
"false",
")",
";",
"$",
"this",
"->",
"closeChannels",
"(",
")",
";",
"$",
"this",
"->",
"close_input",
"(",
")",
";",
"$",
"this",
"->",
"close_socket",
"(",
")",
";",
"throw",
"$",
"e",
";",
"// Rethrow exception",
"}",
"}"
] | Connects to the AMQP server | [
"Connects",
"to",
"the",
"AMQP",
"server"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Connection/AbstractConnection.php#L207-L263 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Connection/AbstractConnection.php | AbstractConnection.reconnect | public function reconnect()
{
// Try to close the AMQP connection
$this->safeClose();
// Reconnect the socket/stream then AMQP
$this->io->close();
$this->setIsConnected(false); // getIO can initiate the connection setting via LazyConnection, set it here to be sure
$this->connect();
} | php | public function reconnect()
{
// Try to close the AMQP connection
$this->safeClose();
// Reconnect the socket/stream then AMQP
$this->io->close();
$this->setIsConnected(false); // getIO can initiate the connection setting via LazyConnection, set it here to be sure
$this->connect();
} | [
"public",
"function",
"reconnect",
"(",
")",
"{",
"// Try to close the AMQP connection",
"$",
"this",
"->",
"safeClose",
"(",
")",
";",
"// Reconnect the socket/stream then AMQP",
"$",
"this",
"->",
"io",
"->",
"close",
"(",
")",
";",
"$",
"this",
"->",
"setIsConnected",
"(",
"false",
")",
";",
"// getIO can initiate the connection setting via LazyConnection, set it here to be sure",
"$",
"this",
"->",
"connect",
"(",
")",
";",
"}"
] | Reconnects using the original connection settings.
This will not recreate any channels that were established previously | [
"Reconnects",
"using",
"the",
"original",
"connection",
"settings",
".",
"This",
"will",
"not",
"recreate",
"any",
"channels",
"that",
"were",
"established",
"previously"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Connection/AbstractConnection.php#L269-L277 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Connection/AbstractConnection.php | AbstractConnection.safeClose | protected function safeClose()
{
try {
if (isset($this->input) && $this->input) {
$this->close();
}
} catch (\Exception $e) {
// Nothing here
}
} | php | protected function safeClose()
{
try {
if (isset($this->input) && $this->input) {
$this->close();
}
} catch (\Exception $e) {
// Nothing here
}
} | [
"protected",
"function",
"safeClose",
"(",
")",
"{",
"try",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"input",
")",
"&&",
"$",
"this",
"->",
"input",
")",
"{",
"$",
"this",
"->",
"close",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"// Nothing here",
"}",
"}"
] | Attempts to close the connection safely | [
"Attempts",
"to",
"close",
"the",
"connection",
"safely"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Connection/AbstractConnection.php#L297-L306 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Connection/AbstractConnection.php | AbstractConnection.wait_frame | protected function wait_frame($timeout = 0)
{
if (is_null($this->input))
{
$this->setIsConnected(false);
throw new AMQPConnectionClosedException('Broken pipe or closed connection');
}
$currentTimeout = $this->input->getTimeout();
$this->input->setTimeout($timeout);
try {
// frame_type + channel_id + size
$this->wait_frame_reader->reuse(
$this->input->read(AMQPReader::OCTET + AMQPReader::SHORT + AMQPReader::LONG)
);
$frame_type = $this->wait_frame_reader->read_octet();
$class = self::$PROTOCOL_CONSTANTS_CLASS;
if (!array_key_exists($frame_type, $class::$FRAME_TYPES)) {
throw new AMQPInvalidFrameException('Invalid frame type ' . $frame_type);
}
$channel = $this->wait_frame_reader->read_short();
$size = $this->wait_frame_reader->read_long();
// payload + ch
$this->wait_frame_reader->reuse($this->input->read(AMQPReader::OCTET + (int) $size));
$payload = $this->wait_frame_reader->read($size);
$ch = $this->wait_frame_reader->read_octet();
} catch (AMQPTimeoutException $e) {
$this->input->setTimeout($currentTimeout);
throw $e;
} catch (AMQPNoDataException $e) {
if ($this->input) {
$this->input->setTimeout($currentTimeout);
}
throw $e;
} catch (AMQPConnectionClosedException $exception) {
$this->do_close();
throw $exception;
}
$this->input->setTimeout($currentTimeout);
if ($ch != 0xCE) {
throw new AMQPInvalidFrameException(sprintf(
'Framing error, unexpected byte: %x',
$ch
));
}
return array($frame_type, $channel, $payload);
} | php | protected function wait_frame($timeout = 0)
{
if (is_null($this->input))
{
$this->setIsConnected(false);
throw new AMQPConnectionClosedException('Broken pipe or closed connection');
}
$currentTimeout = $this->input->getTimeout();
$this->input->setTimeout($timeout);
try {
// frame_type + channel_id + size
$this->wait_frame_reader->reuse(
$this->input->read(AMQPReader::OCTET + AMQPReader::SHORT + AMQPReader::LONG)
);
$frame_type = $this->wait_frame_reader->read_octet();
$class = self::$PROTOCOL_CONSTANTS_CLASS;
if (!array_key_exists($frame_type, $class::$FRAME_TYPES)) {
throw new AMQPInvalidFrameException('Invalid frame type ' . $frame_type);
}
$channel = $this->wait_frame_reader->read_short();
$size = $this->wait_frame_reader->read_long();
// payload + ch
$this->wait_frame_reader->reuse($this->input->read(AMQPReader::OCTET + (int) $size));
$payload = $this->wait_frame_reader->read($size);
$ch = $this->wait_frame_reader->read_octet();
} catch (AMQPTimeoutException $e) {
$this->input->setTimeout($currentTimeout);
throw $e;
} catch (AMQPNoDataException $e) {
if ($this->input) {
$this->input->setTimeout($currentTimeout);
}
throw $e;
} catch (AMQPConnectionClosedException $exception) {
$this->do_close();
throw $exception;
}
$this->input->setTimeout($currentTimeout);
if ($ch != 0xCE) {
throw new AMQPInvalidFrameException(sprintf(
'Framing error, unexpected byte: %x',
$ch
));
}
return array($frame_type, $channel, $payload);
} | [
"protected",
"function",
"wait_frame",
"(",
"$",
"timeout",
"=",
"0",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"input",
")",
")",
"{",
"$",
"this",
"->",
"setIsConnected",
"(",
"false",
")",
";",
"throw",
"new",
"AMQPConnectionClosedException",
"(",
"'Broken pipe or closed connection'",
")",
";",
"}",
"$",
"currentTimeout",
"=",
"$",
"this",
"->",
"input",
"->",
"getTimeout",
"(",
")",
";",
"$",
"this",
"->",
"input",
"->",
"setTimeout",
"(",
"$",
"timeout",
")",
";",
"try",
"{",
"// frame_type + channel_id + size",
"$",
"this",
"->",
"wait_frame_reader",
"->",
"reuse",
"(",
"$",
"this",
"->",
"input",
"->",
"read",
"(",
"AMQPReader",
"::",
"OCTET",
"+",
"AMQPReader",
"::",
"SHORT",
"+",
"AMQPReader",
"::",
"LONG",
")",
")",
";",
"$",
"frame_type",
"=",
"$",
"this",
"->",
"wait_frame_reader",
"->",
"read_octet",
"(",
")",
";",
"$",
"class",
"=",
"self",
"::",
"$",
"PROTOCOL_CONSTANTS_CLASS",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"frame_type",
",",
"$",
"class",
"::",
"$",
"FRAME_TYPES",
")",
")",
"{",
"throw",
"new",
"AMQPInvalidFrameException",
"(",
"'Invalid frame type '",
".",
"$",
"frame_type",
")",
";",
"}",
"$",
"channel",
"=",
"$",
"this",
"->",
"wait_frame_reader",
"->",
"read_short",
"(",
")",
";",
"$",
"size",
"=",
"$",
"this",
"->",
"wait_frame_reader",
"->",
"read_long",
"(",
")",
";",
"// payload + ch",
"$",
"this",
"->",
"wait_frame_reader",
"->",
"reuse",
"(",
"$",
"this",
"->",
"input",
"->",
"read",
"(",
"AMQPReader",
"::",
"OCTET",
"+",
"(",
"int",
")",
"$",
"size",
")",
")",
";",
"$",
"payload",
"=",
"$",
"this",
"->",
"wait_frame_reader",
"->",
"read",
"(",
"$",
"size",
")",
";",
"$",
"ch",
"=",
"$",
"this",
"->",
"wait_frame_reader",
"->",
"read_octet",
"(",
")",
";",
"}",
"catch",
"(",
"AMQPTimeoutException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"input",
"->",
"setTimeout",
"(",
"$",
"currentTimeout",
")",
";",
"throw",
"$",
"e",
";",
"}",
"catch",
"(",
"AMQPNoDataException",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"input",
")",
"{",
"$",
"this",
"->",
"input",
"->",
"setTimeout",
"(",
"$",
"currentTimeout",
")",
";",
"}",
"throw",
"$",
"e",
";",
"}",
"catch",
"(",
"AMQPConnectionClosedException",
"$",
"exception",
")",
"{",
"$",
"this",
"->",
"do_close",
"(",
")",
";",
"throw",
"$",
"exception",
";",
"}",
"$",
"this",
"->",
"input",
"->",
"setTimeout",
"(",
"$",
"currentTimeout",
")",
";",
"if",
"(",
"$",
"ch",
"!=",
"0xCE",
")",
"{",
"throw",
"new",
"AMQPInvalidFrameException",
"(",
"sprintf",
"(",
"'Framing error, unexpected byte: %x'",
",",
"$",
"ch",
")",
")",
";",
"}",
"return",
"array",
"(",
"$",
"frame_type",
",",
"$",
"channel",
",",
"$",
"payload",
")",
";",
"}"
] | Waits for a frame from the server
@param int|float|null $timeout
@return array
@throws \Exception
@throws \PhpAmqpLib\Exception\AMQPTimeoutException
@throws \PhpAmqpLib\Exception\AMQPRuntimeException | [
"Waits",
"for",
"a",
"frame",
"from",
"the",
"server"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Connection/AbstractConnection.php#L534-L588 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Connection/AbstractConnection.php | AbstractConnection.wait_channel | protected function wait_channel($channel_id, $timeout = 0)
{
// Keeping the original timeout unchanged.
$_timeout = $timeout;
while (true) {
$now = time();
try {
list($frame_type, $frame_channel, $payload) = $this->wait_frame($_timeout);
} catch (AMQPTimeoutException $e) {
if ( $this->heartbeat && microtime(true) - ($this->heartbeat*2) > $this->last_frame ) {
$this->debug->debug_msg("missed server heartbeat (at threshold * 2)");
$this->setIsConnected(false);
throw new AMQPHeartbeatMissedException("Missed server heartbeat");
}
throw $e;
}
$this->last_frame = microtime(true);
if ($frame_channel === 0 && $frame_type === 8) {
// skip heartbeat frames and reduce the timeout by the time passed
$this->debug->debug_msg("received server heartbeat");
if($_timeout > 0) {
$_timeout -= time() - $now;
if($_timeout <= 0) {
// If timeout has been reached, throw the exception without calling wait_frame
throw new AMQPTimeoutException("Timeout waiting on channel");
}
}
continue;
} else {
if ($frame_channel == $channel_id) {
return array($frame_type, $payload);
}
// Not the channel we were looking for. Queue this frame
//for later, when the other channel is looking for frames.
// Make sure the channel still exists, it could have been
// closed by a previous Exception.
if (isset($this->channels[$frame_channel])) {
array_push($this->channels[$frame_channel]->frame_queue, array($frame_type, $payload));
}
// If we just queued up a method for channel 0 (the Connection
// itself) it's probably a close method in reaction to some
// error, so deal with it right away.
if (($frame_type == 1) && ($frame_channel == 0)) {
$this->wait();
}
}
}
} | php | protected function wait_channel($channel_id, $timeout = 0)
{
// Keeping the original timeout unchanged.
$_timeout = $timeout;
while (true) {
$now = time();
try {
list($frame_type, $frame_channel, $payload) = $this->wait_frame($_timeout);
} catch (AMQPTimeoutException $e) {
if ( $this->heartbeat && microtime(true) - ($this->heartbeat*2) > $this->last_frame ) {
$this->debug->debug_msg("missed server heartbeat (at threshold * 2)");
$this->setIsConnected(false);
throw new AMQPHeartbeatMissedException("Missed server heartbeat");
}
throw $e;
}
$this->last_frame = microtime(true);
if ($frame_channel === 0 && $frame_type === 8) {
// skip heartbeat frames and reduce the timeout by the time passed
$this->debug->debug_msg("received server heartbeat");
if($_timeout > 0) {
$_timeout -= time() - $now;
if($_timeout <= 0) {
// If timeout has been reached, throw the exception without calling wait_frame
throw new AMQPTimeoutException("Timeout waiting on channel");
}
}
continue;
} else {
if ($frame_channel == $channel_id) {
return array($frame_type, $payload);
}
// Not the channel we were looking for. Queue this frame
//for later, when the other channel is looking for frames.
// Make sure the channel still exists, it could have been
// closed by a previous Exception.
if (isset($this->channels[$frame_channel])) {
array_push($this->channels[$frame_channel]->frame_queue, array($frame_type, $payload));
}
// If we just queued up a method for channel 0 (the Connection
// itself) it's probably a close method in reaction to some
// error, so deal with it right away.
if (($frame_type == 1) && ($frame_channel == 0)) {
$this->wait();
}
}
}
} | [
"protected",
"function",
"wait_channel",
"(",
"$",
"channel_id",
",",
"$",
"timeout",
"=",
"0",
")",
"{",
"// Keeping the original timeout unchanged.",
"$",
"_timeout",
"=",
"$",
"timeout",
";",
"while",
"(",
"true",
")",
"{",
"$",
"now",
"=",
"time",
"(",
")",
";",
"try",
"{",
"list",
"(",
"$",
"frame_type",
",",
"$",
"frame_channel",
",",
"$",
"payload",
")",
"=",
"$",
"this",
"->",
"wait_frame",
"(",
"$",
"_timeout",
")",
";",
"}",
"catch",
"(",
"AMQPTimeoutException",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"heartbeat",
"&&",
"microtime",
"(",
"true",
")",
"-",
"(",
"$",
"this",
"->",
"heartbeat",
"*",
"2",
")",
">",
"$",
"this",
"->",
"last_frame",
")",
"{",
"$",
"this",
"->",
"debug",
"->",
"debug_msg",
"(",
"\"missed server heartbeat (at threshold * 2)\"",
")",
";",
"$",
"this",
"->",
"setIsConnected",
"(",
"false",
")",
";",
"throw",
"new",
"AMQPHeartbeatMissedException",
"(",
"\"Missed server heartbeat\"",
")",
";",
"}",
"throw",
"$",
"e",
";",
"}",
"$",
"this",
"->",
"last_frame",
"=",
"microtime",
"(",
"true",
")",
";",
"if",
"(",
"$",
"frame_channel",
"===",
"0",
"&&",
"$",
"frame_type",
"===",
"8",
")",
"{",
"// skip heartbeat frames and reduce the timeout by the time passed",
"$",
"this",
"->",
"debug",
"->",
"debug_msg",
"(",
"\"received server heartbeat\"",
")",
";",
"if",
"(",
"$",
"_timeout",
">",
"0",
")",
"{",
"$",
"_timeout",
"-=",
"time",
"(",
")",
"-",
"$",
"now",
";",
"if",
"(",
"$",
"_timeout",
"<=",
"0",
")",
"{",
"// If timeout has been reached, throw the exception without calling wait_frame",
"throw",
"new",
"AMQPTimeoutException",
"(",
"\"Timeout waiting on channel\"",
")",
";",
"}",
"}",
"continue",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"frame_channel",
"==",
"$",
"channel_id",
")",
"{",
"return",
"array",
"(",
"$",
"frame_type",
",",
"$",
"payload",
")",
";",
"}",
"// Not the channel we were looking for. Queue this frame",
"//for later, when the other channel is looking for frames.",
"// Make sure the channel still exists, it could have been",
"// closed by a previous Exception.",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"channels",
"[",
"$",
"frame_channel",
"]",
")",
")",
"{",
"array_push",
"(",
"$",
"this",
"->",
"channels",
"[",
"$",
"frame_channel",
"]",
"->",
"frame_queue",
",",
"array",
"(",
"$",
"frame_type",
",",
"$",
"payload",
")",
")",
";",
"}",
"// If we just queued up a method for channel 0 (the Connection",
"// itself) it's probably a close method in reaction to some",
"// error, so deal with it right away.",
"if",
"(",
"(",
"$",
"frame_type",
"==",
"1",
")",
"&&",
"(",
"$",
"frame_channel",
"==",
"0",
")",
")",
"{",
"$",
"this",
"->",
"wait",
"(",
")",
";",
"}",
"}",
"}",
"}"
] | Waits for a frame from the server destined for a particular channel.
@param string $channel_id
@param int|float|null $timeout
@return array | [
"Waits",
"for",
"a",
"frame",
"from",
"the",
"server",
"destined",
"for",
"a",
"particular",
"channel",
"."
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Connection/AbstractConnection.php#L597-L651 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Connection/AbstractConnection.php | AbstractConnection.close | public function close($reply_code = 0, $reply_text = '', $method_sig = array(0, 0))
{
$result = null;
$this->io->disableHeartbeat();
if (empty($this->protocolWriter) || !$this->isConnected()) {
return $result;
}
try {
$this->closeChannels();
list($class_id, $method_id, $args) = $this->protocolWriter->connectionClose(
$reply_code,
$reply_text,
$method_sig[0],
$method_sig[1]
);
$this->send_method_frame(array($class_id, $method_id), $args);
$result = $this->wait(
array($this->waitHelper->get_wait('connection.close_ok')),
false,
$this->connection_timeout
);
} catch (\Exception $exception) {
$this->do_close();
throw $exception;
}
$this->setIsConnected(false);
return $result;
} | php | public function close($reply_code = 0, $reply_text = '', $method_sig = array(0, 0))
{
$result = null;
$this->io->disableHeartbeat();
if (empty($this->protocolWriter) || !$this->isConnected()) {
return $result;
}
try {
$this->closeChannels();
list($class_id, $method_id, $args) = $this->protocolWriter->connectionClose(
$reply_code,
$reply_text,
$method_sig[0],
$method_sig[1]
);
$this->send_method_frame(array($class_id, $method_id), $args);
$result = $this->wait(
array($this->waitHelper->get_wait('connection.close_ok')),
false,
$this->connection_timeout
);
} catch (\Exception $exception) {
$this->do_close();
throw $exception;
}
$this->setIsConnected(false);
return $result;
} | [
"public",
"function",
"close",
"(",
"$",
"reply_code",
"=",
"0",
",",
"$",
"reply_text",
"=",
"''",
",",
"$",
"method_sig",
"=",
"array",
"(",
"0",
",",
"0",
")",
")",
"{",
"$",
"result",
"=",
"null",
";",
"$",
"this",
"->",
"io",
"->",
"disableHeartbeat",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"protocolWriter",
")",
"||",
"!",
"$",
"this",
"->",
"isConnected",
"(",
")",
")",
"{",
"return",
"$",
"result",
";",
"}",
"try",
"{",
"$",
"this",
"->",
"closeChannels",
"(",
")",
";",
"list",
"(",
"$",
"class_id",
",",
"$",
"method_id",
",",
"$",
"args",
")",
"=",
"$",
"this",
"->",
"protocolWriter",
"->",
"connectionClose",
"(",
"$",
"reply_code",
",",
"$",
"reply_text",
",",
"$",
"method_sig",
"[",
"0",
"]",
",",
"$",
"method_sig",
"[",
"1",
"]",
")",
";",
"$",
"this",
"->",
"send_method_frame",
"(",
"array",
"(",
"$",
"class_id",
",",
"$",
"method_id",
")",
",",
"$",
"args",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"wait",
"(",
"array",
"(",
"$",
"this",
"->",
"waitHelper",
"->",
"get_wait",
"(",
"'connection.close_ok'",
")",
")",
",",
"false",
",",
"$",
"this",
"->",
"connection_timeout",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"exception",
")",
"{",
"$",
"this",
"->",
"do_close",
"(",
")",
";",
"throw",
"$",
"exception",
";",
"}",
"$",
"this",
"->",
"setIsConnected",
"(",
"false",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Requests a connection close
@param int $reply_code
@param string $reply_text
@param array $method_sig
@return mixed|null | [
"Requests",
"a",
"connection",
"close"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Connection/AbstractConnection.php#L681-L711 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Connection/AbstractConnection.php | AbstractConnection.connection_open_ok | protected function connection_open_ok($args)
{
$this->known_hosts = $args->read_shortstr();
$this->debug->debug_msg('Open OK! known_hosts: ' . $this->known_hosts);
} | php | protected function connection_open_ok($args)
{
$this->known_hosts = $args->read_shortstr();
$this->debug->debug_msg('Open OK! known_hosts: ' . $this->known_hosts);
} | [
"protected",
"function",
"connection_open_ok",
"(",
"$",
"args",
")",
"{",
"$",
"this",
"->",
"known_hosts",
"=",
"$",
"args",
"->",
"read_shortstr",
"(",
")",
";",
"$",
"this",
"->",
"debug",
"->",
"debug_msg",
"(",
"'Open OK! known_hosts: '",
".",
"$",
"this",
"->",
"known_hosts",
")",
";",
"}"
] | Signals that the connection is ready
@param AMQPReader $args | [
"Signals",
"that",
"the",
"connection",
"is",
"ready"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Connection/AbstractConnection.php#L780-L784 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Connection/AbstractConnection.php | AbstractConnection.connection_redirect | protected function connection_redirect($args)
{
$host = $args->read_shortstr();
$this->known_hosts = $args->read_shortstr();
$this->debug->debug_msg(sprintf(
'Redirected to [%s], known_hosts [%s]',
$host,
$this->known_hosts
));
return $host;
} | php | protected function connection_redirect($args)
{
$host = $args->read_shortstr();
$this->known_hosts = $args->read_shortstr();
$this->debug->debug_msg(sprintf(
'Redirected to [%s], known_hosts [%s]',
$host,
$this->known_hosts
));
return $host;
} | [
"protected",
"function",
"connection_redirect",
"(",
"$",
"args",
")",
"{",
"$",
"host",
"=",
"$",
"args",
"->",
"read_shortstr",
"(",
")",
";",
"$",
"this",
"->",
"known_hosts",
"=",
"$",
"args",
"->",
"read_shortstr",
"(",
")",
";",
"$",
"this",
"->",
"debug",
"->",
"debug_msg",
"(",
"sprintf",
"(",
"'Redirected to [%s], known_hosts [%s]'",
",",
"$",
"host",
",",
"$",
"this",
"->",
"known_hosts",
")",
")",
";",
"return",
"$",
"host",
";",
"}"
] | Asks the client to use a different server
@param AMQPReader $args
@return string | [
"Asks",
"the",
"client",
"to",
"use",
"a",
"different",
"server"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Connection/AbstractConnection.php#L792-L803 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Connection/AbstractConnection.php | AbstractConnection.x_secure_ok | protected function x_secure_ok($response)
{
$args = new AMQPWriter();
$args->write_longstr($response);
$this->send_method_frame(array(10, 21), $args);
} | php | protected function x_secure_ok($response)
{
$args = new AMQPWriter();
$args->write_longstr($response);
$this->send_method_frame(array(10, 21), $args);
} | [
"protected",
"function",
"x_secure_ok",
"(",
"$",
"response",
")",
"{",
"$",
"args",
"=",
"new",
"AMQPWriter",
"(",
")",
";",
"$",
"args",
"->",
"write_longstr",
"(",
"$",
"response",
")",
";",
"$",
"this",
"->",
"send_method_frame",
"(",
"array",
"(",
"10",
",",
"21",
")",
",",
"$",
"args",
")",
";",
"}"
] | Security mechanism response
@param string $response | [
"Security",
"mechanism",
"response"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Connection/AbstractConnection.php#L820-L825 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Connection/AbstractConnection.php | AbstractConnection.connection_start | protected function connection_start($args)
{
$this->version_major = $args->read_octet();
$this->version_minor = $args->read_octet();
$this->server_properties = $args->read_table();
$this->mechanisms = explode(' ', $args->read_longstr());
$this->locales = explode(' ', $args->read_longstr());
$this->debug->debug_connection_start(
$this->version_major,
$this->version_minor,
$this->server_properties,
$this->mechanisms,
$this->locales
);
} | php | protected function connection_start($args)
{
$this->version_major = $args->read_octet();
$this->version_minor = $args->read_octet();
$this->server_properties = $args->read_table();
$this->mechanisms = explode(' ', $args->read_longstr());
$this->locales = explode(' ', $args->read_longstr());
$this->debug->debug_connection_start(
$this->version_major,
$this->version_minor,
$this->server_properties,
$this->mechanisms,
$this->locales
);
} | [
"protected",
"function",
"connection_start",
"(",
"$",
"args",
")",
"{",
"$",
"this",
"->",
"version_major",
"=",
"$",
"args",
"->",
"read_octet",
"(",
")",
";",
"$",
"this",
"->",
"version_minor",
"=",
"$",
"args",
"->",
"read_octet",
"(",
")",
";",
"$",
"this",
"->",
"server_properties",
"=",
"$",
"args",
"->",
"read_table",
"(",
")",
";",
"$",
"this",
"->",
"mechanisms",
"=",
"explode",
"(",
"' '",
",",
"$",
"args",
"->",
"read_longstr",
"(",
")",
")",
";",
"$",
"this",
"->",
"locales",
"=",
"explode",
"(",
"' '",
",",
"$",
"args",
"->",
"read_longstr",
"(",
")",
")",
";",
"$",
"this",
"->",
"debug",
"->",
"debug_connection_start",
"(",
"$",
"this",
"->",
"version_major",
",",
"$",
"this",
"->",
"version_minor",
",",
"$",
"this",
"->",
"server_properties",
",",
"$",
"this",
"->",
"mechanisms",
",",
"$",
"this",
"->",
"locales",
")",
";",
"}"
] | Starts connection negotiation
@param AMQPReader $args | [
"Starts",
"connection",
"negotiation"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Connection/AbstractConnection.php#L832-L847 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Connection/AbstractConnection.php | AbstractConnection.connection_tune | protected function connection_tune($args)
{
$v = $args->read_short();
if ($v) {
$this->channel_max = $v;
}
$v = $args->read_long();
if ($v) {
$this->frame_max = $v;
}
// use server proposed value if not set
if ($this->heartbeat === null) {
$this->heartbeat = $args->read_short();
}
$this->x_tune_ok($this->channel_max, $this->frame_max, $this->heartbeat);
} | php | protected function connection_tune($args)
{
$v = $args->read_short();
if ($v) {
$this->channel_max = $v;
}
$v = $args->read_long();
if ($v) {
$this->frame_max = $v;
}
// use server proposed value if not set
if ($this->heartbeat === null) {
$this->heartbeat = $args->read_short();
}
$this->x_tune_ok($this->channel_max, $this->frame_max, $this->heartbeat);
} | [
"protected",
"function",
"connection_tune",
"(",
"$",
"args",
")",
"{",
"$",
"v",
"=",
"$",
"args",
"->",
"read_short",
"(",
")",
";",
"if",
"(",
"$",
"v",
")",
"{",
"$",
"this",
"->",
"channel_max",
"=",
"$",
"v",
";",
"}",
"$",
"v",
"=",
"$",
"args",
"->",
"read_long",
"(",
")",
";",
"if",
"(",
"$",
"v",
")",
"{",
"$",
"this",
"->",
"frame_max",
"=",
"$",
"v",
";",
"}",
"// use server proposed value if not set",
"if",
"(",
"$",
"this",
"->",
"heartbeat",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"heartbeat",
"=",
"$",
"args",
"->",
"read_short",
"(",
")",
";",
"}",
"$",
"this",
"->",
"x_tune_ok",
"(",
"$",
"this",
"->",
"channel_max",
",",
"$",
"this",
"->",
"frame_max",
",",
"$",
"this",
"->",
"heartbeat",
")",
";",
"}"
] | Proposes connection tuning parameters
@param AMQPReader $args | [
"Proposes",
"connection",
"tuning",
"parameters"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Connection/AbstractConnection.php#L870-L888 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Connection/AbstractConnection.php | AbstractConnection.x_tune_ok | protected function x_tune_ok($channel_max, $frame_max, $heartbeat)
{
$args = new AMQPWriter();
$args->write_short($channel_max);
$args->write_long($frame_max);
$args->write_short($heartbeat);
$this->send_method_frame(array(10, 31), $args);
$this->wait_tune_ok = false;
} | php | protected function x_tune_ok($channel_max, $frame_max, $heartbeat)
{
$args = new AMQPWriter();
$args->write_short($channel_max);
$args->write_long($frame_max);
$args->write_short($heartbeat);
$this->send_method_frame(array(10, 31), $args);
$this->wait_tune_ok = false;
} | [
"protected",
"function",
"x_tune_ok",
"(",
"$",
"channel_max",
",",
"$",
"frame_max",
",",
"$",
"heartbeat",
")",
"{",
"$",
"args",
"=",
"new",
"AMQPWriter",
"(",
")",
";",
"$",
"args",
"->",
"write_short",
"(",
"$",
"channel_max",
")",
";",
"$",
"args",
"->",
"write_long",
"(",
"$",
"frame_max",
")",
";",
"$",
"args",
"->",
"write_short",
"(",
"$",
"heartbeat",
")",
";",
"$",
"this",
"->",
"send_method_frame",
"(",
"array",
"(",
"10",
",",
"31",
")",
",",
"$",
"args",
")",
";",
"$",
"this",
"->",
"wait_tune_ok",
"=",
"false",
";",
"}"
] | Negotiates connection tuning parameters
@param int $channel_max
@param int $frame_max
@param int $heartbeat | [
"Negotiates",
"connection",
"tuning",
"parameters"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Connection/AbstractConnection.php#L897-L905 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Connection/AbstractConnection.php | AbstractConnection.closeChannels | protected function closeChannels()
{
foreach ($this->channels as $key => $channel) {
// channels[0] is this connection object, so don't close it yet
if ($key === 0) {
continue;
}
try {
$channel->close();
} catch (\Exception $e) {
/* Ignore closing errors */
}
}
} | php | protected function closeChannels()
{
foreach ($this->channels as $key => $channel) {
// channels[0] is this connection object, so don't close it yet
if ($key === 0) {
continue;
}
try {
$channel->close();
} catch (\Exception $e) {
/* Ignore closing errors */
}
}
} | [
"protected",
"function",
"closeChannels",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"channels",
"as",
"$",
"key",
"=>",
"$",
"channel",
")",
"{",
"// channels[0] is this connection object, so don't close it yet",
"if",
"(",
"$",
"key",
"===",
"0",
")",
"{",
"continue",
";",
"}",
"try",
"{",
"$",
"channel",
"->",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"/* Ignore closing errors */",
"}",
"}",
"}"
] | Closes all available channels | [
"Closes",
"all",
"available",
"channels"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Connection/AbstractConnection.php#L990-L1003 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Channel/AMQPChannel.php | AMQPChannel.channel_alert | protected function channel_alert($reader)
{
$reply_code = $reader->read_short();
$reply_text = $reader->read_shortstr();
$details = $reader->read_table();
array_push($this->alerts, array($reply_code, $reply_text, $details));
} | php | protected function channel_alert($reader)
{
$reply_code = $reader->read_short();
$reply_text = $reader->read_shortstr();
$details = $reader->read_table();
array_push($this->alerts, array($reply_code, $reply_text, $details));
} | [
"protected",
"function",
"channel_alert",
"(",
"$",
"reader",
")",
"{",
"$",
"reply_code",
"=",
"$",
"reader",
"->",
"read_short",
"(",
")",
";",
"$",
"reply_text",
"=",
"$",
"reader",
"->",
"read_shortstr",
"(",
")",
";",
"$",
"details",
"=",
"$",
"reader",
"->",
"read_table",
"(",
")",
";",
"array_push",
"(",
"$",
"this",
"->",
"alerts",
",",
"array",
"(",
"$",
"reply_code",
",",
"$",
"reply_text",
",",
"$",
"details",
")",
")",
";",
"}"
] | Only for AMQP0.8.0
This method allows the server to send a non-fatal warning to
the client. This is used for methods that are normally
asynchronous and thus do not have confirmations, and for which
the server may detect errors that need to be reported. Fatal
errors are handled as channel or connection exceptions; non-
fatal errors are sent through this method.
@param AMQPReader $reader | [
"Only",
"for",
"AMQP0",
".",
"8",
".",
"0",
"This",
"method",
"allows",
"the",
"server",
"to",
"send",
"a",
"non",
"-",
"fatal",
"warning",
"to",
"the",
"client",
".",
"This",
"is",
"used",
"for",
"methods",
"that",
"are",
"normally",
"asynchronous",
"and",
"thus",
"do",
"not",
"have",
"confirmations",
"and",
"for",
"which",
"the",
"server",
"may",
"detect",
"errors",
"that",
"need",
"to",
"be",
"reported",
".",
"Fatal",
"errors",
"are",
"handled",
"as",
"channel",
"or",
"connection",
"exceptions",
";",
"non",
"-",
"fatal",
"errors",
"are",
"sent",
"through",
"this",
"method",
"."
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Channel/AMQPChannel.php#L150-L156 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Channel/AMQPChannel.php | AMQPChannel.close | public function close($reply_code = 0, $reply_text = '', $method_sig = array(0, 0))
{
$this->callbacks = array();
if ($this->is_open === false || $this->connection === null) {
$this->do_close();
return null; // already closed
}
list($class_id, $method_id, $args) = $this->protocolWriter->channelClose(
$reply_code,
$reply_text,
$method_sig[0],
$method_sig[1]
);
try {
$this->send_method_frame(array($class_id, $method_id), $args);
} catch (\Exception $e) {
$this->do_close();
throw $e;
}
return $this->wait(array(
$this->waitHelper->get_wait('channel.close_ok')
), false, $this->channel_rpc_timeout );
} | php | public function close($reply_code = 0, $reply_text = '', $method_sig = array(0, 0))
{
$this->callbacks = array();
if ($this->is_open === false || $this->connection === null) {
$this->do_close();
return null; // already closed
}
list($class_id, $method_id, $args) = $this->protocolWriter->channelClose(
$reply_code,
$reply_text,
$method_sig[0],
$method_sig[1]
);
try {
$this->send_method_frame(array($class_id, $method_id), $args);
} catch (\Exception $e) {
$this->do_close();
throw $e;
}
return $this->wait(array(
$this->waitHelper->get_wait('channel.close_ok')
), false, $this->channel_rpc_timeout );
} | [
"public",
"function",
"close",
"(",
"$",
"reply_code",
"=",
"0",
",",
"$",
"reply_text",
"=",
"''",
",",
"$",
"method_sig",
"=",
"array",
"(",
"0",
",",
"0",
")",
")",
"{",
"$",
"this",
"->",
"callbacks",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"is_open",
"===",
"false",
"||",
"$",
"this",
"->",
"connection",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"do_close",
"(",
")",
";",
"return",
"null",
";",
"// already closed",
"}",
"list",
"(",
"$",
"class_id",
",",
"$",
"method_id",
",",
"$",
"args",
")",
"=",
"$",
"this",
"->",
"protocolWriter",
"->",
"channelClose",
"(",
"$",
"reply_code",
",",
"$",
"reply_text",
",",
"$",
"method_sig",
"[",
"0",
"]",
",",
"$",
"method_sig",
"[",
"1",
"]",
")",
";",
"try",
"{",
"$",
"this",
"->",
"send_method_frame",
"(",
"array",
"(",
"$",
"class_id",
",",
"$",
"method_id",
")",
",",
"$",
"args",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"do_close",
"(",
")",
";",
"throw",
"$",
"e",
";",
"}",
"return",
"$",
"this",
"->",
"wait",
"(",
"array",
"(",
"$",
"this",
"->",
"waitHelper",
"->",
"get_wait",
"(",
"'channel.close_ok'",
")",
")",
",",
"false",
",",
"$",
"this",
"->",
"channel_rpc_timeout",
")",
";",
"}"
] | Request a channel close
@param int $reply_code
@param string $reply_text
@param array $method_sig
@throws \PhpAmqpLib\Exception\AMQPTimeoutException if the specified operation timeout was exceeded
@return mixed | [
"Request",
"a",
"channel",
"close"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Channel/AMQPChannel.php#L167-L193 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Channel/AMQPChannel.php | AMQPChannel.access_request | public function access_request(
$realm,
$exclusive = false,
$passive = false,
$active = false,
$write = false,
$read = false
) {
list($class_id, $method_id, $args) = $this->protocolWriter->accessRequest(
$realm,
$exclusive,
$passive,
$active,
$write,
$read
);
$this->send_method_frame(array($class_id, $method_id), $args);
return $this->wait(array(
$this->waitHelper->get_wait('access.request_ok')
), false, $this->channel_rpc_timeout);
} | php | public function access_request(
$realm,
$exclusive = false,
$passive = false,
$active = false,
$write = false,
$read = false
) {
list($class_id, $method_id, $args) = $this->protocolWriter->accessRequest(
$realm,
$exclusive,
$passive,
$active,
$write,
$read
);
$this->send_method_frame(array($class_id, $method_id), $args);
return $this->wait(array(
$this->waitHelper->get_wait('access.request_ok')
), false, $this->channel_rpc_timeout);
} | [
"public",
"function",
"access_request",
"(",
"$",
"realm",
",",
"$",
"exclusive",
"=",
"false",
",",
"$",
"passive",
"=",
"false",
",",
"$",
"active",
"=",
"false",
",",
"$",
"write",
"=",
"false",
",",
"$",
"read",
"=",
"false",
")",
"{",
"list",
"(",
"$",
"class_id",
",",
"$",
"method_id",
",",
"$",
"args",
")",
"=",
"$",
"this",
"->",
"protocolWriter",
"->",
"accessRequest",
"(",
"$",
"realm",
",",
"$",
"exclusive",
",",
"$",
"passive",
",",
"$",
"active",
",",
"$",
"write",
",",
"$",
"read",
")",
";",
"$",
"this",
"->",
"send_method_frame",
"(",
"array",
"(",
"$",
"class_id",
",",
"$",
"method_id",
")",
",",
"$",
"args",
")",
";",
"return",
"$",
"this",
"->",
"wait",
"(",
"array",
"(",
"$",
"this",
"->",
"waitHelper",
"->",
"get_wait",
"(",
"'access.request_ok'",
")",
")",
",",
"false",
",",
"$",
"this",
"->",
"channel_rpc_timeout",
")",
";",
"}"
] | Requests an access ticket
@param string $realm
@param bool $exclusive
@param bool $passive
@param bool $active
@param bool $write
@param bool $read
@throws \PhpAmqpLib\Exception\AMQPTimeoutException if the specified operation timeout was exceeded
@return mixed | [
"Requests",
"an",
"access",
"ticket"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Channel/AMQPChannel.php#L308-L330 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Channel/AMQPChannel.php | AMQPChannel.exchange_delete | public function exchange_delete(
$exchange,
$if_unused = false,
$nowait = false,
$ticket = null
) {
$ticket = $this->getTicket($ticket);
list($class_id, $method_id, $args) = $this->protocolWriter->exchangeDelete(
$ticket,
$exchange,
$if_unused,
$nowait
);
$this->send_method_frame(array($class_id, $method_id), $args);
if ($nowait) {
return null;
}
return $this->wait(array(
$this->waitHelper->get_wait('exchange.delete_ok')
), false, $this->channel_rpc_timeout);
} | php | public function exchange_delete(
$exchange,
$if_unused = false,
$nowait = false,
$ticket = null
) {
$ticket = $this->getTicket($ticket);
list($class_id, $method_id, $args) = $this->protocolWriter->exchangeDelete(
$ticket,
$exchange,
$if_unused,
$nowait
);
$this->send_method_frame(array($class_id, $method_id), $args);
if ($nowait) {
return null;
}
return $this->wait(array(
$this->waitHelper->get_wait('exchange.delete_ok')
), false, $this->channel_rpc_timeout);
} | [
"public",
"function",
"exchange_delete",
"(",
"$",
"exchange",
",",
"$",
"if_unused",
"=",
"false",
",",
"$",
"nowait",
"=",
"false",
",",
"$",
"ticket",
"=",
"null",
")",
"{",
"$",
"ticket",
"=",
"$",
"this",
"->",
"getTicket",
"(",
"$",
"ticket",
")",
";",
"list",
"(",
"$",
"class_id",
",",
"$",
"method_id",
",",
"$",
"args",
")",
"=",
"$",
"this",
"->",
"protocolWriter",
"->",
"exchangeDelete",
"(",
"$",
"ticket",
",",
"$",
"exchange",
",",
"$",
"if_unused",
",",
"$",
"nowait",
")",
";",
"$",
"this",
"->",
"send_method_frame",
"(",
"array",
"(",
"$",
"class_id",
",",
"$",
"method_id",
")",
",",
"$",
"args",
")",
";",
"if",
"(",
"$",
"nowait",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"wait",
"(",
"array",
"(",
"$",
"this",
"->",
"waitHelper",
"->",
"get_wait",
"(",
"'exchange.delete_ok'",
")",
")",
",",
"false",
",",
"$",
"this",
"->",
"channel_rpc_timeout",
")",
";",
"}"
] | Deletes an exchange
@param string $exchange
@param bool $if_unused
@param bool $nowait
@param int|null $ticket
@throws \PhpAmqpLib\Exception\AMQPTimeoutException if the specified operation timeout was exceeded
@return mixed|null | [
"Deletes",
"an",
"exchange"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Channel/AMQPChannel.php#L414-L437 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Channel/AMQPChannel.php | AMQPChannel.exchange_bind | public function exchange_bind(
$destination,
$source,
$routing_key = '',
$nowait = false,
$arguments = array(),
$ticket = null
) {
$ticket = $this->getTicket($ticket);
list($class_id, $method_id, $args) = $this->protocolWriter->exchangeBind(
$ticket,
$destination,
$source,
$routing_key,
$nowait,
$arguments
);
$this->send_method_frame(array($class_id, $method_id), $args);
if ($nowait) {
return null;
}
return $this->wait(array(
$this->waitHelper->get_wait('exchange.bind_ok')
), false, $this->channel_rpc_timeout);
} | php | public function exchange_bind(
$destination,
$source,
$routing_key = '',
$nowait = false,
$arguments = array(),
$ticket = null
) {
$ticket = $this->getTicket($ticket);
list($class_id, $method_id, $args) = $this->protocolWriter->exchangeBind(
$ticket,
$destination,
$source,
$routing_key,
$nowait,
$arguments
);
$this->send_method_frame(array($class_id, $method_id), $args);
if ($nowait) {
return null;
}
return $this->wait(array(
$this->waitHelper->get_wait('exchange.bind_ok')
), false, $this->channel_rpc_timeout);
} | [
"public",
"function",
"exchange_bind",
"(",
"$",
"destination",
",",
"$",
"source",
",",
"$",
"routing_key",
"=",
"''",
",",
"$",
"nowait",
"=",
"false",
",",
"$",
"arguments",
"=",
"array",
"(",
")",
",",
"$",
"ticket",
"=",
"null",
")",
"{",
"$",
"ticket",
"=",
"$",
"this",
"->",
"getTicket",
"(",
"$",
"ticket",
")",
";",
"list",
"(",
"$",
"class_id",
",",
"$",
"method_id",
",",
"$",
"args",
")",
"=",
"$",
"this",
"->",
"protocolWriter",
"->",
"exchangeBind",
"(",
"$",
"ticket",
",",
"$",
"destination",
",",
"$",
"source",
",",
"$",
"routing_key",
",",
"$",
"nowait",
",",
"$",
"arguments",
")",
";",
"$",
"this",
"->",
"send_method_frame",
"(",
"array",
"(",
"$",
"class_id",
",",
"$",
"method_id",
")",
",",
"$",
"args",
")",
";",
"if",
"(",
"$",
"nowait",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"wait",
"(",
"array",
"(",
"$",
"this",
"->",
"waitHelper",
"->",
"get_wait",
"(",
"'exchange.bind_ok'",
")",
")",
",",
"false",
",",
"$",
"this",
"->",
"channel_rpc_timeout",
")",
";",
"}"
] | Binds dest exchange to source exchange
@param string $destination
@param string $source
@param string $routing_key
@param bool $nowait
@param array $arguments
@param int|null $ticket
@throws \PhpAmqpLib\Exception\AMQPTimeoutException if the specified operation timeout was exceeded
@return mixed|null | [
"Binds",
"dest",
"exchange",
"to",
"source",
"exchange"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Channel/AMQPChannel.php#L460-L488 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Channel/AMQPChannel.php | AMQPChannel.queue_bind | public function queue_bind(
$queue,
$exchange,
$routing_key = '',
$nowait = false,
$arguments = array(),
$ticket = null
) {
$ticket = $this->getTicket($ticket);
list($class_id, $method_id, $args) = $this->protocolWriter->queueBind(
$ticket,
$queue,
$exchange,
$routing_key,
$nowait,
$arguments
);
$this->send_method_frame(array($class_id, $method_id), $args);
if ($nowait) {
return null;
}
return $this->wait(array(
$this->waitHelper->get_wait('queue.bind_ok')
), false, $this->channel_rpc_timeout);
} | php | public function queue_bind(
$queue,
$exchange,
$routing_key = '',
$nowait = false,
$arguments = array(),
$ticket = null
) {
$ticket = $this->getTicket($ticket);
list($class_id, $method_id, $args) = $this->protocolWriter->queueBind(
$ticket,
$queue,
$exchange,
$routing_key,
$nowait,
$arguments
);
$this->send_method_frame(array($class_id, $method_id), $args);
if ($nowait) {
return null;
}
return $this->wait(array(
$this->waitHelper->get_wait('queue.bind_ok')
), false, $this->channel_rpc_timeout);
} | [
"public",
"function",
"queue_bind",
"(",
"$",
"queue",
",",
"$",
"exchange",
",",
"$",
"routing_key",
"=",
"''",
",",
"$",
"nowait",
"=",
"false",
",",
"$",
"arguments",
"=",
"array",
"(",
")",
",",
"$",
"ticket",
"=",
"null",
")",
"{",
"$",
"ticket",
"=",
"$",
"this",
"->",
"getTicket",
"(",
"$",
"ticket",
")",
";",
"list",
"(",
"$",
"class_id",
",",
"$",
"method_id",
",",
"$",
"args",
")",
"=",
"$",
"this",
"->",
"protocolWriter",
"->",
"queueBind",
"(",
"$",
"ticket",
",",
"$",
"queue",
",",
"$",
"exchange",
",",
"$",
"routing_key",
",",
"$",
"nowait",
",",
"$",
"arguments",
")",
";",
"$",
"this",
"->",
"send_method_frame",
"(",
"array",
"(",
"$",
"class_id",
",",
"$",
"method_id",
")",
",",
"$",
"args",
")",
";",
"if",
"(",
"$",
"nowait",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"wait",
"(",
"array",
"(",
"$",
"this",
"->",
"waitHelper",
"->",
"get_wait",
"(",
"'queue.bind_ok'",
")",
")",
",",
"false",
",",
"$",
"this",
"->",
"channel_rpc_timeout",
")",
";",
"}"
] | Binds queue to an exchange
@param string $queue
@param string $exchange
@param string $routing_key
@param bool $nowait
@param array $arguments
@param int|null $ticket
@throws \PhpAmqpLib\Exception\AMQPTimeoutException if the specified operation timeout was exceeded
@return mixed|null | [
"Binds",
"queue",
"to",
"an",
"exchange"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Channel/AMQPChannel.php#L557-L585 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Channel/AMQPChannel.php | AMQPChannel.queue_unbind | public function queue_unbind(
$queue,
$exchange,
$routing_key = '',
$arguments = array(),
$ticket = null
) {
$ticket = $this->getTicket($ticket);
list($class_id, $method_id, $args) = $this->protocolWriter->queueUnbind(
$ticket,
$queue,
$exchange,
$routing_key,
$arguments
);
$this->send_method_frame(array($class_id, $method_id), $args);
return $this->wait(array(
$this->waitHelper->get_wait('queue.unbind_ok')
), false, $this->channel_rpc_timeout);
} | php | public function queue_unbind(
$queue,
$exchange,
$routing_key = '',
$arguments = array(),
$ticket = null
) {
$ticket = $this->getTicket($ticket);
list($class_id, $method_id, $args) = $this->protocolWriter->queueUnbind(
$ticket,
$queue,
$exchange,
$routing_key,
$arguments
);
$this->send_method_frame(array($class_id, $method_id), $args);
return $this->wait(array(
$this->waitHelper->get_wait('queue.unbind_ok')
), false, $this->channel_rpc_timeout);
} | [
"public",
"function",
"queue_unbind",
"(",
"$",
"queue",
",",
"$",
"exchange",
",",
"$",
"routing_key",
"=",
"''",
",",
"$",
"arguments",
"=",
"array",
"(",
")",
",",
"$",
"ticket",
"=",
"null",
")",
"{",
"$",
"ticket",
"=",
"$",
"this",
"->",
"getTicket",
"(",
"$",
"ticket",
")",
";",
"list",
"(",
"$",
"class_id",
",",
"$",
"method_id",
",",
"$",
"args",
")",
"=",
"$",
"this",
"->",
"protocolWriter",
"->",
"queueUnbind",
"(",
"$",
"ticket",
",",
"$",
"queue",
",",
"$",
"exchange",
",",
"$",
"routing_key",
",",
"$",
"arguments",
")",
";",
"$",
"this",
"->",
"send_method_frame",
"(",
"array",
"(",
"$",
"class_id",
",",
"$",
"method_id",
")",
",",
"$",
"args",
")",
";",
"return",
"$",
"this",
"->",
"wait",
"(",
"array",
"(",
"$",
"this",
"->",
"waitHelper",
"->",
"get_wait",
"(",
"'queue.unbind_ok'",
")",
")",
",",
"false",
",",
"$",
"this",
"->",
"channel_rpc_timeout",
")",
";",
"}"
] | Unbind queue from an exchange
@param string $queue
@param string $exchange
@param string $routing_key
@param array $arguments
@param int|null $ticket
@throws \PhpAmqpLib\Exception\AMQPTimeoutException if the specified operation timeout was exceeded
@return mixed | [
"Unbind",
"queue",
"from",
"an",
"exchange"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Channel/AMQPChannel.php#L607-L629 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Channel/AMQPChannel.php | AMQPChannel.queue_declare_ok | protected function queue_declare_ok($reader)
{
$queue = $reader->read_shortstr();
$message_count = $reader->read_long();
$consumer_count = $reader->read_long();
return array($queue, $message_count, $consumer_count);
} | php | protected function queue_declare_ok($reader)
{
$queue = $reader->read_shortstr();
$message_count = $reader->read_long();
$consumer_count = $reader->read_long();
return array($queue, $message_count, $consumer_count);
} | [
"protected",
"function",
"queue_declare_ok",
"(",
"$",
"reader",
")",
"{",
"$",
"queue",
"=",
"$",
"reader",
"->",
"read_shortstr",
"(",
")",
";",
"$",
"message_count",
"=",
"$",
"reader",
"->",
"read_long",
"(",
")",
";",
"$",
"consumer_count",
"=",
"$",
"reader",
"->",
"read_long",
"(",
")",
";",
"return",
"array",
"(",
"$",
"queue",
",",
"$",
"message_count",
",",
"$",
"consumer_count",
")",
";",
"}"
] | Confirms a queue definition
@param AMQPReader $reader
@return string[] | [
"Confirms",
"a",
"queue",
"definition"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Channel/AMQPChannel.php#L693-L700 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Channel/AMQPChannel.php | AMQPChannel.queue_delete | public function queue_delete($queue = '', $if_unused = false, $if_empty = false, $nowait = false, $ticket = null)
{
$ticket = $this->getTicket($ticket);
list($class_id, $method_id, $args) = $this->protocolWriter->queueDelete(
$ticket,
$queue,
$if_unused,
$if_empty,
$nowait
);
$this->send_method_frame(array($class_id, $method_id), $args);
if ($nowait) {
return null;
}
return $this->wait(array(
$this->waitHelper->get_wait('queue.delete_ok')
), false, $this->channel_rpc_timeout);
} | php | public function queue_delete($queue = '', $if_unused = false, $if_empty = false, $nowait = false, $ticket = null)
{
$ticket = $this->getTicket($ticket);
list($class_id, $method_id, $args) = $this->protocolWriter->queueDelete(
$ticket,
$queue,
$if_unused,
$if_empty,
$nowait
);
$this->send_method_frame(array($class_id, $method_id), $args);
if ($nowait) {
return null;
}
return $this->wait(array(
$this->waitHelper->get_wait('queue.delete_ok')
), false, $this->channel_rpc_timeout);
} | [
"public",
"function",
"queue_delete",
"(",
"$",
"queue",
"=",
"''",
",",
"$",
"if_unused",
"=",
"false",
",",
"$",
"if_empty",
"=",
"false",
",",
"$",
"nowait",
"=",
"false",
",",
"$",
"ticket",
"=",
"null",
")",
"{",
"$",
"ticket",
"=",
"$",
"this",
"->",
"getTicket",
"(",
"$",
"ticket",
")",
";",
"list",
"(",
"$",
"class_id",
",",
"$",
"method_id",
",",
"$",
"args",
")",
"=",
"$",
"this",
"->",
"protocolWriter",
"->",
"queueDelete",
"(",
"$",
"ticket",
",",
"$",
"queue",
",",
"$",
"if_unused",
",",
"$",
"if_empty",
",",
"$",
"nowait",
")",
";",
"$",
"this",
"->",
"send_method_frame",
"(",
"array",
"(",
"$",
"class_id",
",",
"$",
"method_id",
")",
",",
"$",
"args",
")",
";",
"if",
"(",
"$",
"nowait",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"wait",
"(",
"array",
"(",
"$",
"this",
"->",
"waitHelper",
"->",
"get_wait",
"(",
"'queue.delete_ok'",
")",
")",
",",
"false",
",",
"$",
"this",
"->",
"channel_rpc_timeout",
")",
";",
"}"
] | Deletes a queue
@param string $queue
@param bool $if_unused
@param bool $if_empty
@param bool $nowait
@param int|null $ticket
@throws \PhpAmqpLib\Exception\AMQPTimeoutException if the specified operation timeout was exceeded
@return mixed|null | [
"Deletes",
"a",
"queue"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Channel/AMQPChannel.php#L713-L734 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Channel/AMQPChannel.php | AMQPChannel.queue_purge | public function queue_purge($queue = '', $nowait = false, $ticket = null)
{
$ticket = $this->getTicket($ticket);
list($class_id, $method_id, $args) = $this->protocolWriter->queuePurge($ticket, $queue, $nowait);
$this->send_method_frame(array($class_id, $method_id), $args);
if ($nowait) {
return null;
}
return $this->wait(array(
$this->waitHelper->get_wait('queue.purge_ok')
), false, $this->channel_rpc_timeout);
} | php | public function queue_purge($queue = '', $nowait = false, $ticket = null)
{
$ticket = $this->getTicket($ticket);
list($class_id, $method_id, $args) = $this->protocolWriter->queuePurge($ticket, $queue, $nowait);
$this->send_method_frame(array($class_id, $method_id), $args);
if ($nowait) {
return null;
}
return $this->wait(array(
$this->waitHelper->get_wait('queue.purge_ok')
), false, $this->channel_rpc_timeout);
} | [
"public",
"function",
"queue_purge",
"(",
"$",
"queue",
"=",
"''",
",",
"$",
"nowait",
"=",
"false",
",",
"$",
"ticket",
"=",
"null",
")",
"{",
"$",
"ticket",
"=",
"$",
"this",
"->",
"getTicket",
"(",
"$",
"ticket",
")",
";",
"list",
"(",
"$",
"class_id",
",",
"$",
"method_id",
",",
"$",
"args",
")",
"=",
"$",
"this",
"->",
"protocolWriter",
"->",
"queuePurge",
"(",
"$",
"ticket",
",",
"$",
"queue",
",",
"$",
"nowait",
")",
";",
"$",
"this",
"->",
"send_method_frame",
"(",
"array",
"(",
"$",
"class_id",
",",
"$",
"method_id",
")",
",",
"$",
"args",
")",
";",
"if",
"(",
"$",
"nowait",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"wait",
"(",
"array",
"(",
"$",
"this",
"->",
"waitHelper",
"->",
"get_wait",
"(",
"'queue.purge_ok'",
")",
")",
",",
"false",
",",
"$",
"this",
"->",
"channel_rpc_timeout",
")",
";",
"}"
] | Purges a queue
@param string $queue
@param bool $nowait
@param int|null $ticket
@throws \PhpAmqpLib\Exception\AMQPTimeoutException if the specified operation timeout was exceeded
@return mixed|null | [
"Purges",
"a",
"queue"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Channel/AMQPChannel.php#L756-L770 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Channel/AMQPChannel.php | AMQPChannel.basic_ack | public function basic_ack($delivery_tag, $multiple = false)
{
list($class_id, $method_id, $args) = $this->protocolWriter->basicAck($delivery_tag, $multiple);
$this->send_method_frame(array($class_id, $method_id), $args);
} | php | public function basic_ack($delivery_tag, $multiple = false)
{
list($class_id, $method_id, $args) = $this->protocolWriter->basicAck($delivery_tag, $multiple);
$this->send_method_frame(array($class_id, $method_id), $args);
} | [
"public",
"function",
"basic_ack",
"(",
"$",
"delivery_tag",
",",
"$",
"multiple",
"=",
"false",
")",
"{",
"list",
"(",
"$",
"class_id",
",",
"$",
"method_id",
",",
"$",
"args",
")",
"=",
"$",
"this",
"->",
"protocolWriter",
"->",
"basicAck",
"(",
"$",
"delivery_tag",
",",
"$",
"multiple",
")",
";",
"$",
"this",
"->",
"send_method_frame",
"(",
"array",
"(",
"$",
"class_id",
",",
"$",
"method_id",
")",
",",
"$",
"args",
")",
";",
"}"
] | Acknowledges one or more messages
@param string $delivery_tag
@param bool $multiple | [
"Acknowledges",
"one",
"or",
"more",
"messages"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Channel/AMQPChannel.php#L789-L793 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Channel/AMQPChannel.php | AMQPChannel.basic_ack_from_server | protected function basic_ack_from_server(AMQPReader $reader)
{
$delivery_tag = $reader->read_longlong();
$multiple = (bool) $reader->read_bit();
if (!isset($this->published_messages[$delivery_tag])) {
throw new AMQPRuntimeException(sprintf(
'Server ack\'ed unknown delivery_tag "%s"',
$delivery_tag
));
}
$this->internal_ack_handler($delivery_tag, $multiple, $this->ack_handler);
} | php | protected function basic_ack_from_server(AMQPReader $reader)
{
$delivery_tag = $reader->read_longlong();
$multiple = (bool) $reader->read_bit();
if (!isset($this->published_messages[$delivery_tag])) {
throw new AMQPRuntimeException(sprintf(
'Server ack\'ed unknown delivery_tag "%s"',
$delivery_tag
));
}
$this->internal_ack_handler($delivery_tag, $multiple, $this->ack_handler);
} | [
"protected",
"function",
"basic_ack_from_server",
"(",
"AMQPReader",
"$",
"reader",
")",
"{",
"$",
"delivery_tag",
"=",
"$",
"reader",
"->",
"read_longlong",
"(",
")",
";",
"$",
"multiple",
"=",
"(",
"bool",
")",
"$",
"reader",
"->",
"read_bit",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"published_messages",
"[",
"$",
"delivery_tag",
"]",
")",
")",
"{",
"throw",
"new",
"AMQPRuntimeException",
"(",
"sprintf",
"(",
"'Server ack\\'ed unknown delivery_tag \"%s\"'",
",",
"$",
"delivery_tag",
")",
")",
";",
"}",
"$",
"this",
"->",
"internal_ack_handler",
"(",
"$",
"delivery_tag",
",",
"$",
"multiple",
",",
"$",
"this",
"->",
"ack_handler",
")",
";",
"}"
] | Called when the server sends a basic.ack
@param AMQPReader $reader
@throws AMQPRuntimeException | [
"Called",
"when",
"the",
"server",
"sends",
"a",
"basic",
".",
"ack"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Channel/AMQPChannel.php#L801-L814 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Channel/AMQPChannel.php | AMQPChannel.basic_nack_from_server | protected function basic_nack_from_server($reader)
{
$delivery_tag = $reader->read_longlong();
$multiple = (bool) $reader->read_bit();
if (!isset($this->published_messages[$delivery_tag])) {
throw new AMQPRuntimeException(sprintf(
'Server nack\'ed unknown delivery_tag "%s"',
$delivery_tag
));
}
$this->internal_ack_handler($delivery_tag, $multiple, $this->nack_handler);
} | php | protected function basic_nack_from_server($reader)
{
$delivery_tag = $reader->read_longlong();
$multiple = (bool) $reader->read_bit();
if (!isset($this->published_messages[$delivery_tag])) {
throw new AMQPRuntimeException(sprintf(
'Server nack\'ed unknown delivery_tag "%s"',
$delivery_tag
));
}
$this->internal_ack_handler($delivery_tag, $multiple, $this->nack_handler);
} | [
"protected",
"function",
"basic_nack_from_server",
"(",
"$",
"reader",
")",
"{",
"$",
"delivery_tag",
"=",
"$",
"reader",
"->",
"read_longlong",
"(",
")",
";",
"$",
"multiple",
"=",
"(",
"bool",
")",
"$",
"reader",
"->",
"read_bit",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"published_messages",
"[",
"$",
"delivery_tag",
"]",
")",
")",
"{",
"throw",
"new",
"AMQPRuntimeException",
"(",
"sprintf",
"(",
"'Server nack\\'ed unknown delivery_tag \"%s\"'",
",",
"$",
"delivery_tag",
")",
")",
";",
"}",
"$",
"this",
"->",
"internal_ack_handler",
"(",
"$",
"delivery_tag",
",",
"$",
"multiple",
",",
"$",
"this",
"->",
"nack_handler",
")",
";",
"}"
] | Called when the server sends a basic.nack
@param AMQPReader $reader
@throws AMQPRuntimeException | [
"Called",
"when",
"the",
"server",
"sends",
"a",
"basic",
".",
"nack"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Channel/AMQPChannel.php#L822-L835 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Channel/AMQPChannel.php | AMQPChannel.basic_nack | public function basic_nack($delivery_tag, $multiple = false, $requeue = false)
{
list($class_id, $method_id, $args) = $this->protocolWriter->basicNack($delivery_tag, $multiple, $requeue);
$this->send_method_frame(array($class_id, $method_id), $args);
} | php | public function basic_nack($delivery_tag, $multiple = false, $requeue = false)
{
list($class_id, $method_id, $args) = $this->protocolWriter->basicNack($delivery_tag, $multiple, $requeue);
$this->send_method_frame(array($class_id, $method_id), $args);
} | [
"public",
"function",
"basic_nack",
"(",
"$",
"delivery_tag",
",",
"$",
"multiple",
"=",
"false",
",",
"$",
"requeue",
"=",
"false",
")",
"{",
"list",
"(",
"$",
"class_id",
",",
"$",
"method_id",
",",
"$",
"args",
")",
"=",
"$",
"this",
"->",
"protocolWriter",
"->",
"basicNack",
"(",
"$",
"delivery_tag",
",",
"$",
"multiple",
",",
"$",
"requeue",
")",
";",
"$",
"this",
"->",
"send_method_frame",
"(",
"array",
"(",
"$",
"class_id",
",",
"$",
"method_id",
")",
",",
"$",
"args",
")",
";",
"}"
] | Rejects one or several received messages
@param string $delivery_tag
@param bool $multiple
@param bool $requeue | [
"Rejects",
"one",
"or",
"several",
"received",
"messages"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Channel/AMQPChannel.php#L893-L897 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Channel/AMQPChannel.php | AMQPChannel.basic_cancel | public function basic_cancel($consumer_tag, $nowait = false, $noreturn = false)
{
list($class_id, $method_id, $args) = $this->protocolWriter->basicCancel($consumer_tag, $nowait);
$this->send_method_frame(array($class_id, $method_id), $args);
if ($nowait || $noreturn) {
unset($this->callbacks[$consumer_tag]);
return $consumer_tag;
}
return $this->wait(array(
$this->waitHelper->get_wait('basic.cancel_ok')
), false, $this->channel_rpc_timeout);
} | php | public function basic_cancel($consumer_tag, $nowait = false, $noreturn = false)
{
list($class_id, $method_id, $args) = $this->protocolWriter->basicCancel($consumer_tag, $nowait);
$this->send_method_frame(array($class_id, $method_id), $args);
if ($nowait || $noreturn) {
unset($this->callbacks[$consumer_tag]);
return $consumer_tag;
}
return $this->wait(array(
$this->waitHelper->get_wait('basic.cancel_ok')
), false, $this->channel_rpc_timeout);
} | [
"public",
"function",
"basic_cancel",
"(",
"$",
"consumer_tag",
",",
"$",
"nowait",
"=",
"false",
",",
"$",
"noreturn",
"=",
"false",
")",
"{",
"list",
"(",
"$",
"class_id",
",",
"$",
"method_id",
",",
"$",
"args",
")",
"=",
"$",
"this",
"->",
"protocolWriter",
"->",
"basicCancel",
"(",
"$",
"consumer_tag",
",",
"$",
"nowait",
")",
";",
"$",
"this",
"->",
"send_method_frame",
"(",
"array",
"(",
"$",
"class_id",
",",
"$",
"method_id",
")",
",",
"$",
"args",
")",
";",
"if",
"(",
"$",
"nowait",
"||",
"$",
"noreturn",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"callbacks",
"[",
"$",
"consumer_tag",
"]",
")",
";",
"return",
"$",
"consumer_tag",
";",
"}",
"return",
"$",
"this",
"->",
"wait",
"(",
"array",
"(",
"$",
"this",
"->",
"waitHelper",
"->",
"get_wait",
"(",
"'basic.cancel_ok'",
")",
")",
",",
"false",
",",
"$",
"this",
"->",
"channel_rpc_timeout",
")",
";",
"}"
] | Ends a queue consumer
@param string $consumer_tag
@param bool $nowait
@param bool $noreturn
@throws \PhpAmqpLib\Exception\AMQPTimeoutException if the specified operation timeout was exceeded
@return mixed | [
"Ends",
"a",
"queue",
"consumer"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Channel/AMQPChannel.php#L908-L921 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Channel/AMQPChannel.php | AMQPChannel.basic_consume | public function basic_consume(
$queue = '',
$consumer_tag = '',
$no_local = false,
$no_ack = false,
$exclusive = false,
$nowait = false,
$callback = null,
$ticket = null,
$arguments = array()
) {
$ticket = $this->getTicket($ticket);
list($class_id, $method_id, $args) = $this->protocolWriter->basicConsume(
$ticket,
$queue,
$consumer_tag,
$no_local,
$no_ack,
$exclusive,
$nowait,
$this->protocolVersion == '0.9.1' ? $arguments : null
);
$this->send_method_frame(array($class_id, $method_id), $args);
if (false === $nowait) {
$consumer_tag = $this->wait(array(
$this->waitHelper->get_wait('basic.consume_ok')
), false, $this->channel_rpc_timeout);
}
$this->callbacks[$consumer_tag] = $callback;
return $consumer_tag;
} | php | public function basic_consume(
$queue = '',
$consumer_tag = '',
$no_local = false,
$no_ack = false,
$exclusive = false,
$nowait = false,
$callback = null,
$ticket = null,
$arguments = array()
) {
$ticket = $this->getTicket($ticket);
list($class_id, $method_id, $args) = $this->protocolWriter->basicConsume(
$ticket,
$queue,
$consumer_tag,
$no_local,
$no_ack,
$exclusive,
$nowait,
$this->protocolVersion == '0.9.1' ? $arguments : null
);
$this->send_method_frame(array($class_id, $method_id), $args);
if (false === $nowait) {
$consumer_tag = $this->wait(array(
$this->waitHelper->get_wait('basic.consume_ok')
), false, $this->channel_rpc_timeout);
}
$this->callbacks[$consumer_tag] = $callback;
return $consumer_tag;
} | [
"public",
"function",
"basic_consume",
"(",
"$",
"queue",
"=",
"''",
",",
"$",
"consumer_tag",
"=",
"''",
",",
"$",
"no_local",
"=",
"false",
",",
"$",
"no_ack",
"=",
"false",
",",
"$",
"exclusive",
"=",
"false",
",",
"$",
"nowait",
"=",
"false",
",",
"$",
"callback",
"=",
"null",
",",
"$",
"ticket",
"=",
"null",
",",
"$",
"arguments",
"=",
"array",
"(",
")",
")",
"{",
"$",
"ticket",
"=",
"$",
"this",
"->",
"getTicket",
"(",
"$",
"ticket",
")",
";",
"list",
"(",
"$",
"class_id",
",",
"$",
"method_id",
",",
"$",
"args",
")",
"=",
"$",
"this",
"->",
"protocolWriter",
"->",
"basicConsume",
"(",
"$",
"ticket",
",",
"$",
"queue",
",",
"$",
"consumer_tag",
",",
"$",
"no_local",
",",
"$",
"no_ack",
",",
"$",
"exclusive",
",",
"$",
"nowait",
",",
"$",
"this",
"->",
"protocolVersion",
"==",
"'0.9.1'",
"?",
"$",
"arguments",
":",
"null",
")",
";",
"$",
"this",
"->",
"send_method_frame",
"(",
"array",
"(",
"$",
"class_id",
",",
"$",
"method_id",
")",
",",
"$",
"args",
")",
";",
"if",
"(",
"false",
"===",
"$",
"nowait",
")",
"{",
"$",
"consumer_tag",
"=",
"$",
"this",
"->",
"wait",
"(",
"array",
"(",
"$",
"this",
"->",
"waitHelper",
"->",
"get_wait",
"(",
"'basic.consume_ok'",
")",
")",
",",
"false",
",",
"$",
"this",
"->",
"channel_rpc_timeout",
")",
";",
"}",
"$",
"this",
"->",
"callbacks",
"[",
"$",
"consumer_tag",
"]",
"=",
"$",
"callback",
";",
"return",
"$",
"consumer_tag",
";",
"}"
] | Starts a queue consumer
@param string $queue
@param string $consumer_tag
@param bool $no_local
@param bool $no_ack
@param bool $exclusive
@param bool $nowait
@param callable|null $callback
@param int|null $ticket
@param array $arguments
@throws \PhpAmqpLib\Exception\AMQPTimeoutException if the specified operation timeout was exceeded
@return mixed|string | [
"Starts",
"a",
"queue",
"consumer"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Channel/AMQPChannel.php#L969-L1003 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Channel/AMQPChannel.php | AMQPChannel.basic_deliver | protected function basic_deliver($reader, $message)
{
$consumer_tag = $reader->read_shortstr();
$delivery_tag = $reader->read_longlong();
$redelivered = $reader->read_bit();
$exchange = $reader->read_shortstr();
$routing_key = $reader->read_shortstr();
$message->delivery_info = array(
'channel' => $this,
'consumer_tag' => $consumer_tag,
'delivery_tag' => $delivery_tag,
'redelivered' => $redelivered,
'exchange' => $exchange,
'routing_key' => $routing_key
);
if (isset($this->callbacks[$consumer_tag])) {
call_user_func($this->callbacks[$consumer_tag], $message);
}
} | php | protected function basic_deliver($reader, $message)
{
$consumer_tag = $reader->read_shortstr();
$delivery_tag = $reader->read_longlong();
$redelivered = $reader->read_bit();
$exchange = $reader->read_shortstr();
$routing_key = $reader->read_shortstr();
$message->delivery_info = array(
'channel' => $this,
'consumer_tag' => $consumer_tag,
'delivery_tag' => $delivery_tag,
'redelivered' => $redelivered,
'exchange' => $exchange,
'routing_key' => $routing_key
);
if (isset($this->callbacks[$consumer_tag])) {
call_user_func($this->callbacks[$consumer_tag], $message);
}
} | [
"protected",
"function",
"basic_deliver",
"(",
"$",
"reader",
",",
"$",
"message",
")",
"{",
"$",
"consumer_tag",
"=",
"$",
"reader",
"->",
"read_shortstr",
"(",
")",
";",
"$",
"delivery_tag",
"=",
"$",
"reader",
"->",
"read_longlong",
"(",
")",
";",
"$",
"redelivered",
"=",
"$",
"reader",
"->",
"read_bit",
"(",
")",
";",
"$",
"exchange",
"=",
"$",
"reader",
"->",
"read_shortstr",
"(",
")",
";",
"$",
"routing_key",
"=",
"$",
"reader",
"->",
"read_shortstr",
"(",
")",
";",
"$",
"message",
"->",
"delivery_info",
"=",
"array",
"(",
"'channel'",
"=>",
"$",
"this",
",",
"'consumer_tag'",
"=>",
"$",
"consumer_tag",
",",
"'delivery_tag'",
"=>",
"$",
"delivery_tag",
",",
"'redelivered'",
"=>",
"$",
"redelivered",
",",
"'exchange'",
"=>",
"$",
"exchange",
",",
"'routing_key'",
"=>",
"$",
"routing_key",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"callbacks",
"[",
"$",
"consumer_tag",
"]",
")",
")",
"{",
"call_user_func",
"(",
"$",
"this",
"->",
"callbacks",
"[",
"$",
"consumer_tag",
"]",
",",
"$",
"message",
")",
";",
"}",
"}"
] | Notifies the client of a consumer message
@param AMQPReader $reader
@param AMQPMessage $message | [
"Notifies",
"the",
"client",
"of",
"a",
"consumer",
"message"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Channel/AMQPChannel.php#L1022-L1042 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Channel/AMQPChannel.php | AMQPChannel.basic_get | public function basic_get($queue = '', $no_ack = false, $ticket = null)
{
$ticket = $this->getTicket($ticket);
list($class_id, $method_id, $args) = $this->protocolWriter->basicGet($ticket, $queue, $no_ack);
$this->send_method_frame(array($class_id, $method_id), $args);
return $this->wait(array(
$this->waitHelper->get_wait('basic.get_ok'),
$this->waitHelper->get_wait('basic.get_empty')
), false, $this->channel_rpc_timeout);
} | php | public function basic_get($queue = '', $no_ack = false, $ticket = null)
{
$ticket = $this->getTicket($ticket);
list($class_id, $method_id, $args) = $this->protocolWriter->basicGet($ticket, $queue, $no_ack);
$this->send_method_frame(array($class_id, $method_id), $args);
return $this->wait(array(
$this->waitHelper->get_wait('basic.get_ok'),
$this->waitHelper->get_wait('basic.get_empty')
), false, $this->channel_rpc_timeout);
} | [
"public",
"function",
"basic_get",
"(",
"$",
"queue",
"=",
"''",
",",
"$",
"no_ack",
"=",
"false",
",",
"$",
"ticket",
"=",
"null",
")",
"{",
"$",
"ticket",
"=",
"$",
"this",
"->",
"getTicket",
"(",
"$",
"ticket",
")",
";",
"list",
"(",
"$",
"class_id",
",",
"$",
"method_id",
",",
"$",
"args",
")",
"=",
"$",
"this",
"->",
"protocolWriter",
"->",
"basicGet",
"(",
"$",
"ticket",
",",
"$",
"queue",
",",
"$",
"no_ack",
")",
";",
"$",
"this",
"->",
"send_method_frame",
"(",
"array",
"(",
"$",
"class_id",
",",
"$",
"method_id",
")",
",",
"$",
"args",
")",
";",
"return",
"$",
"this",
"->",
"wait",
"(",
"array",
"(",
"$",
"this",
"->",
"waitHelper",
"->",
"get_wait",
"(",
"'basic.get_ok'",
")",
",",
"$",
"this",
"->",
"waitHelper",
"->",
"get_wait",
"(",
"'basic.get_empty'",
")",
")",
",",
"false",
",",
"$",
"this",
"->",
"channel_rpc_timeout",
")",
";",
"}"
] | Direct access to a queue if no message was available in the queue, return null
@param string $queue
@param bool $no_ack
@param int|null $ticket
@throws \PhpAmqpLib\Exception\AMQPTimeoutException if the specified operation timeout was exceeded
@return mixed | [
"Direct",
"access",
"to",
"a",
"queue",
"if",
"no",
"message",
"was",
"available",
"in",
"the",
"queue",
"return",
"null"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Channel/AMQPChannel.php#L1053-L1064 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Channel/AMQPChannel.php | AMQPChannel.basic_get_ok | protected function basic_get_ok($reader, $message)
{
$delivery_tag = $reader->read_longlong();
$redelivered = $reader->read_bit();
$exchange = $reader->read_shortstr();
$routing_key = $reader->read_shortstr();
$message_count = $reader->read_long();
$message->delivery_info = array(
'delivery_tag' => $delivery_tag,
'redelivered' => $redelivered,
'exchange' => $exchange,
'routing_key' => $routing_key,
'message_count' => $message_count
);
return $message;
} | php | protected function basic_get_ok($reader, $message)
{
$delivery_tag = $reader->read_longlong();
$redelivered = $reader->read_bit();
$exchange = $reader->read_shortstr();
$routing_key = $reader->read_shortstr();
$message_count = $reader->read_long();
$message->delivery_info = array(
'delivery_tag' => $delivery_tag,
'redelivered' => $redelivered,
'exchange' => $exchange,
'routing_key' => $routing_key,
'message_count' => $message_count
);
return $message;
} | [
"protected",
"function",
"basic_get_ok",
"(",
"$",
"reader",
",",
"$",
"message",
")",
"{",
"$",
"delivery_tag",
"=",
"$",
"reader",
"->",
"read_longlong",
"(",
")",
";",
"$",
"redelivered",
"=",
"$",
"reader",
"->",
"read_bit",
"(",
")",
";",
"$",
"exchange",
"=",
"$",
"reader",
"->",
"read_shortstr",
"(",
")",
";",
"$",
"routing_key",
"=",
"$",
"reader",
"->",
"read_shortstr",
"(",
")",
";",
"$",
"message_count",
"=",
"$",
"reader",
"->",
"read_long",
"(",
")",
";",
"$",
"message",
"->",
"delivery_info",
"=",
"array",
"(",
"'delivery_tag'",
"=>",
"$",
"delivery_tag",
",",
"'redelivered'",
"=>",
"$",
"redelivered",
",",
"'exchange'",
"=>",
"$",
"exchange",
",",
"'routing_key'",
"=>",
"$",
"routing_key",
",",
"'message_count'",
"=>",
"$",
"message_count",
")",
";",
"return",
"$",
"message",
";",
"}"
] | Provides client with a message
@param AMQPReader $reader
@param AMQPMessage $message
@return AMQPMessage | [
"Provides",
"client",
"with",
"a",
"message"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Channel/AMQPChannel.php#L1082-L1099 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Channel/AMQPChannel.php | AMQPChannel.basic_publish | public function basic_publish(
$msg,
$exchange = '',
$routing_key = '',
$mandatory = false,
$immediate = false,
$ticket = null
) {
$pkt = new AMQPWriter();
$pkt->write($this->pre_publish($exchange, $routing_key, $mandatory, $immediate, $ticket));
try {
$this->connection->send_content(
$this->channel_id,
60,
0,
mb_strlen($msg->body, 'ASCII'),
$msg->serialize_properties(),
$msg->body,
$pkt
);
} catch (AMQPConnectionClosedException $e) {
$this->do_close();
throw $e;
}
if ($this->next_delivery_tag > 0) {
$this->published_messages[$this->next_delivery_tag] = $msg;
$this->next_delivery_tag = bcadd($this->next_delivery_tag, '1', 0);
}
} | php | public function basic_publish(
$msg,
$exchange = '',
$routing_key = '',
$mandatory = false,
$immediate = false,
$ticket = null
) {
$pkt = new AMQPWriter();
$pkt->write($this->pre_publish($exchange, $routing_key, $mandatory, $immediate, $ticket));
try {
$this->connection->send_content(
$this->channel_id,
60,
0,
mb_strlen($msg->body, 'ASCII'),
$msg->serialize_properties(),
$msg->body,
$pkt
);
} catch (AMQPConnectionClosedException $e) {
$this->do_close();
throw $e;
}
if ($this->next_delivery_tag > 0) {
$this->published_messages[$this->next_delivery_tag] = $msg;
$this->next_delivery_tag = bcadd($this->next_delivery_tag, '1', 0);
}
} | [
"public",
"function",
"basic_publish",
"(",
"$",
"msg",
",",
"$",
"exchange",
"=",
"''",
",",
"$",
"routing_key",
"=",
"''",
",",
"$",
"mandatory",
"=",
"false",
",",
"$",
"immediate",
"=",
"false",
",",
"$",
"ticket",
"=",
"null",
")",
"{",
"$",
"pkt",
"=",
"new",
"AMQPWriter",
"(",
")",
";",
"$",
"pkt",
"->",
"write",
"(",
"$",
"this",
"->",
"pre_publish",
"(",
"$",
"exchange",
",",
"$",
"routing_key",
",",
"$",
"mandatory",
",",
"$",
"immediate",
",",
"$",
"ticket",
")",
")",
";",
"try",
"{",
"$",
"this",
"->",
"connection",
"->",
"send_content",
"(",
"$",
"this",
"->",
"channel_id",
",",
"60",
",",
"0",
",",
"mb_strlen",
"(",
"$",
"msg",
"->",
"body",
",",
"'ASCII'",
")",
",",
"$",
"msg",
"->",
"serialize_properties",
"(",
")",
",",
"$",
"msg",
"->",
"body",
",",
"$",
"pkt",
")",
";",
"}",
"catch",
"(",
"AMQPConnectionClosedException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"do_close",
"(",
")",
";",
"throw",
"$",
"e",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"next_delivery_tag",
">",
"0",
")",
"{",
"$",
"this",
"->",
"published_messages",
"[",
"$",
"this",
"->",
"next_delivery_tag",
"]",
"=",
"$",
"msg",
";",
"$",
"this",
"->",
"next_delivery_tag",
"=",
"bcadd",
"(",
"$",
"this",
"->",
"next_delivery_tag",
",",
"'1'",
",",
"0",
")",
";",
"}",
"}"
] | Publishes a message
@param AMQPMessage $msg
@param string $exchange
@param string $routing_key
@param bool $mandatory
@param bool $immediate
@param int|null $ticket | [
"Publishes",
"a",
"message"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Channel/AMQPChannel.php#L1151-L1181 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Channel/AMQPChannel.php | AMQPChannel.basic_recover | public function basic_recover($requeue = false)
{
list($class_id, $method_id, $args) = $this->protocolWriter->basicRecover($requeue);
$this->send_method_frame(array($class_id, $method_id), $args);
return $this->wait(array(
$this->waitHelper->get_wait('basic.recover_ok')
), false, $this->channel_rpc_timeout);
} | php | public function basic_recover($requeue = false)
{
list($class_id, $method_id, $args) = $this->protocolWriter->basicRecover($requeue);
$this->send_method_frame(array($class_id, $method_id), $args);
return $this->wait(array(
$this->waitHelper->get_wait('basic.recover_ok')
), false, $this->channel_rpc_timeout);
} | [
"public",
"function",
"basic_recover",
"(",
"$",
"requeue",
"=",
"false",
")",
"{",
"list",
"(",
"$",
"class_id",
",",
"$",
"method_id",
",",
"$",
"args",
")",
"=",
"$",
"this",
"->",
"protocolWriter",
"->",
"basicRecover",
"(",
"$",
"requeue",
")",
";",
"$",
"this",
"->",
"send_method_frame",
"(",
"array",
"(",
"$",
"class_id",
",",
"$",
"method_id",
")",
",",
"$",
"args",
")",
";",
"return",
"$",
"this",
"->",
"wait",
"(",
"array",
"(",
"$",
"this",
"->",
"waitHelper",
"->",
"get_wait",
"(",
"'basic.recover_ok'",
")",
")",
",",
"false",
",",
"$",
"this",
"->",
"channel_rpc_timeout",
")",
";",
"}"
] | Redelivers unacknowledged messages
@param bool $requeue
@throws \PhpAmqpLib\Exception\AMQPTimeoutException if the specified operation timeout was exceeded
@return mixed | [
"Redelivers",
"unacknowledged",
"messages"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Channel/AMQPChannel.php#L1287-L1295 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Channel/AMQPChannel.php | AMQPChannel.basic_reject | public function basic_reject($delivery_tag, $requeue)
{
list($class_id, $method_id, $args) = $this->protocolWriter->basicReject($delivery_tag, $requeue);
$this->send_method_frame(array($class_id, $method_id), $args);
} | php | public function basic_reject($delivery_tag, $requeue)
{
list($class_id, $method_id, $args) = $this->protocolWriter->basicReject($delivery_tag, $requeue);
$this->send_method_frame(array($class_id, $method_id), $args);
} | [
"public",
"function",
"basic_reject",
"(",
"$",
"delivery_tag",
",",
"$",
"requeue",
")",
"{",
"list",
"(",
"$",
"class_id",
",",
"$",
"method_id",
",",
"$",
"args",
")",
"=",
"$",
"this",
"->",
"protocolWriter",
"->",
"basicReject",
"(",
"$",
"delivery_tag",
",",
"$",
"requeue",
")",
";",
"$",
"this",
"->",
"send_method_frame",
"(",
"array",
"(",
"$",
"class_id",
",",
"$",
"method_id",
")",
",",
"$",
"args",
")",
";",
"}"
] | Rejects an incoming message
@param string $delivery_tag
@param bool $requeue | [
"Rejects",
"an",
"incoming",
"message"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Channel/AMQPChannel.php#L1311-L1315 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Channel/AMQPChannel.php | AMQPChannel.basic_return | protected function basic_return($reader, $message)
{
$callback = $this->basic_return_callback;
if (!is_callable($callback)) {
$this->debug->debug_msg('Skipping unhandled basic_return message');
return null;
}
$reply_code = $reader->read_short();
$reply_text = $reader->read_shortstr();
$exchange = $reader->read_shortstr();
$routing_key = $reader->read_shortstr();
call_user_func_array($callback, array(
$reply_code,
$reply_text,
$exchange,
$routing_key,
$message,
));
} | php | protected function basic_return($reader, $message)
{
$callback = $this->basic_return_callback;
if (!is_callable($callback)) {
$this->debug->debug_msg('Skipping unhandled basic_return message');
return null;
}
$reply_code = $reader->read_short();
$reply_text = $reader->read_shortstr();
$exchange = $reader->read_shortstr();
$routing_key = $reader->read_shortstr();
call_user_func_array($callback, array(
$reply_code,
$reply_text,
$exchange,
$routing_key,
$message,
));
} | [
"protected",
"function",
"basic_return",
"(",
"$",
"reader",
",",
"$",
"message",
")",
"{",
"$",
"callback",
"=",
"$",
"this",
"->",
"basic_return_callback",
";",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"callback",
")",
")",
"{",
"$",
"this",
"->",
"debug",
"->",
"debug_msg",
"(",
"'Skipping unhandled basic_return message'",
")",
";",
"return",
"null",
";",
"}",
"$",
"reply_code",
"=",
"$",
"reader",
"->",
"read_short",
"(",
")",
";",
"$",
"reply_text",
"=",
"$",
"reader",
"->",
"read_shortstr",
"(",
")",
";",
"$",
"exchange",
"=",
"$",
"reader",
"->",
"read_shortstr",
"(",
")",
";",
"$",
"routing_key",
"=",
"$",
"reader",
"->",
"read_shortstr",
"(",
")",
";",
"call_user_func_array",
"(",
"$",
"callback",
",",
"array",
"(",
"$",
"reply_code",
",",
"$",
"reply_text",
",",
"$",
"exchange",
",",
"$",
"routing_key",
",",
"$",
"message",
",",
")",
")",
";",
"}"
] | Returns a failed message
@param AMQPReader $reader
@param AMQPMessage $message
@return null | [
"Returns",
"a",
"failed",
"message"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Channel/AMQPChannel.php#L1324-L1344 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Channel/AMQPChannel.php | AMQPChannel.tx_rollback | public function tx_rollback()
{
$this->send_method_frame(array(90, 30));
return $this->wait(array(
$this->waitHelper->get_wait('tx.rollback_ok')
), false, $this->channel_rpc_timeout);
} | php | public function tx_rollback()
{
$this->send_method_frame(array(90, 30));
return $this->wait(array(
$this->waitHelper->get_wait('tx.rollback_ok')
), false, $this->channel_rpc_timeout);
} | [
"public",
"function",
"tx_rollback",
"(",
")",
"{",
"$",
"this",
"->",
"send_method_frame",
"(",
"array",
"(",
"90",
",",
"30",
")",
")",
";",
"return",
"$",
"this",
"->",
"wait",
"(",
"array",
"(",
"$",
"this",
"->",
"waitHelper",
"->",
"get_wait",
"(",
"'tx.rollback_ok'",
")",
")",
",",
"false",
",",
"$",
"this",
"->",
"channel_rpc_timeout",
")",
";",
"}"
] | Rollbacks the current transaction
@throws \PhpAmqpLib\Exception\AMQPTimeoutException if the specified operation timeout was exceeded
@return mixed | [
"Rollbacks",
"the",
"current",
"transaction"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Channel/AMQPChannel.php#L1373-L1380 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Channel/AMQPChannel.php | AMQPChannel.confirm_select | public function confirm_select($nowait = false)
{
list($class_id, $method_id, $args) = $this->protocolWriter->confirmSelect($nowait);
$this->send_method_frame(array($class_id, $method_id), $args);
if ($nowait) {
return null;
}
$this->wait(array(
$this->waitHelper->get_wait('confirm.select_ok')
), false, $this->channel_rpc_timeout);
$this->next_delivery_tag = 1;
} | php | public function confirm_select($nowait = false)
{
list($class_id, $method_id, $args) = $this->protocolWriter->confirmSelect($nowait);
$this->send_method_frame(array($class_id, $method_id), $args);
if ($nowait) {
return null;
}
$this->wait(array(
$this->waitHelper->get_wait('confirm.select_ok')
), false, $this->channel_rpc_timeout);
$this->next_delivery_tag = 1;
} | [
"public",
"function",
"confirm_select",
"(",
"$",
"nowait",
"=",
"false",
")",
"{",
"list",
"(",
"$",
"class_id",
",",
"$",
"method_id",
",",
"$",
"args",
")",
"=",
"$",
"this",
"->",
"protocolWriter",
"->",
"confirmSelect",
"(",
"$",
"nowait",
")",
";",
"$",
"this",
"->",
"send_method_frame",
"(",
"array",
"(",
"$",
"class_id",
",",
"$",
"method_id",
")",
",",
"$",
"args",
")",
";",
"if",
"(",
"$",
"nowait",
")",
"{",
"return",
"null",
";",
"}",
"$",
"this",
"->",
"wait",
"(",
"array",
"(",
"$",
"this",
"->",
"waitHelper",
"->",
"get_wait",
"(",
"'confirm.select_ok'",
")",
")",
",",
"false",
",",
"$",
"this",
"->",
"channel_rpc_timeout",
")",
";",
"$",
"this",
"->",
"next_delivery_tag",
"=",
"1",
";",
"}"
] | Puts the channel into confirm mode
Beware that only non-transactional channels may be put into confirm mode and vice versa
@param bool $nowait
@throws \PhpAmqpLib\Exception\AMQPTimeoutException if the specified operation timeout was exceeded
@return null | [
"Puts",
"the",
"channel",
"into",
"confirm",
"mode",
"Beware",
"that",
"only",
"non",
"-",
"transactional",
"channels",
"may",
"be",
"put",
"into",
"confirm",
"mode",
"and",
"vice",
"versa"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Channel/AMQPChannel.php#L1399-L1413 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Channel/AMQPChannel.php | AMQPChannel.wait_for_pending_acks | public function wait_for_pending_acks($timeout = 0)
{
$functions = array(
$this->waitHelper->get_wait('basic.ack'),
$this->waitHelper->get_wait('basic.nack'),
);
while (count($this->published_messages) !== 0) {
if ($timeout > 0) {
$this->wait($functions, true, $timeout);
} else {
$this->wait($functions);
}
}
} | php | public function wait_for_pending_acks($timeout = 0)
{
$functions = array(
$this->waitHelper->get_wait('basic.ack'),
$this->waitHelper->get_wait('basic.nack'),
);
while (count($this->published_messages) !== 0) {
if ($timeout > 0) {
$this->wait($functions, true, $timeout);
} else {
$this->wait($functions);
}
}
} | [
"public",
"function",
"wait_for_pending_acks",
"(",
"$",
"timeout",
"=",
"0",
")",
"{",
"$",
"functions",
"=",
"array",
"(",
"$",
"this",
"->",
"waitHelper",
"->",
"get_wait",
"(",
"'basic.ack'",
")",
",",
"$",
"this",
"->",
"waitHelper",
"->",
"get_wait",
"(",
"'basic.nack'",
")",
",",
")",
";",
"while",
"(",
"count",
"(",
"$",
"this",
"->",
"published_messages",
")",
"!==",
"0",
")",
"{",
"if",
"(",
"$",
"timeout",
">",
"0",
")",
"{",
"$",
"this",
"->",
"wait",
"(",
"$",
"functions",
",",
"true",
",",
"$",
"timeout",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"wait",
"(",
"$",
"functions",
")",
";",
"}",
"}",
"}"
] | Waits for pending acks and nacks from the server.
If there are no pending acks, the method returns immediately
@param int $timeout Waits until $timeout value is reached | [
"Waits",
"for",
"pending",
"acks",
"and",
"nacks",
"from",
"the",
"server",
".",
"If",
"there",
"are",
"no",
"pending",
"acks",
"the",
"method",
"returns",
"immediately"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Channel/AMQPChannel.php#L1430-L1444 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Channel/AMQPChannel.php | AMQPChannel.tx_select | public function tx_select()
{
$this->send_method_frame(array(90, 10));
return $this->wait(array(
$this->waitHelper->get_wait('tx.select_ok')
), false, $this->channel_rpc_timeout);
} | php | public function tx_select()
{
$this->send_method_frame(array(90, 10));
return $this->wait(array(
$this->waitHelper->get_wait('tx.select_ok')
), false, $this->channel_rpc_timeout);
} | [
"public",
"function",
"tx_select",
"(",
")",
"{",
"$",
"this",
"->",
"send_method_frame",
"(",
"array",
"(",
"90",
",",
"10",
")",
")",
";",
"return",
"$",
"this",
"->",
"wait",
"(",
"array",
"(",
"$",
"this",
"->",
"waitHelper",
"->",
"get_wait",
"(",
"'tx.select_ok'",
")",
")",
",",
"false",
",",
"$",
"this",
"->",
"channel_rpc_timeout",
")",
";",
"}"
] | Selects standard transaction mode
@throws \PhpAmqpLib\Exception\AMQPTimeoutException if the specified operation timeout was exceeded
@return mixed | [
"Selects",
"standard",
"transaction",
"mode"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Channel/AMQPChannel.php#L1474-L1481 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Channel/AMQPChannel.php | AMQPChannel.set_return_listener | public function set_return_listener($callback)
{
if (!is_callable($callback)) {
throw new \InvalidArgumentException(sprintf(
'Given callback "%s" should be callable. %s type was given.',
$callback,
gettype($callback)
));
}
$this->basic_return_callback = $callback;
} | php | public function set_return_listener($callback)
{
if (!is_callable($callback)) {
throw new \InvalidArgumentException(sprintf(
'Given callback "%s" should be callable. %s type was given.',
$callback,
gettype($callback)
));
}
$this->basic_return_callback = $callback;
} | [
"public",
"function",
"set_return_listener",
"(",
"$",
"callback",
")",
"{",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"callback",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Given callback \"%s\" should be callable. %s type was given.'",
",",
"$",
"callback",
",",
"gettype",
"(",
"$",
"callback",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"basic_return_callback",
"=",
"$",
"callback",
";",
"}"
] | Sets callback for basic_return
@param callable $callback
@throws \InvalidArgumentException if $callback is not callable | [
"Sets",
"callback",
"for",
"basic_return"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Channel/AMQPChannel.php#L1533-L1544 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Channel/AMQPChannel.php | AMQPChannel.set_nack_handler | public function set_nack_handler($callback)
{
if (!is_callable($callback)) {
throw new \InvalidArgumentException(sprintf(
'Given callback "%s" should be callable. %s type was given.',
$callback,
gettype($callback)
));
}
$this->nack_handler = $callback;
} | php | public function set_nack_handler($callback)
{
if (!is_callable($callback)) {
throw new \InvalidArgumentException(sprintf(
'Given callback "%s" should be callable. %s type was given.',
$callback,
gettype($callback)
));
}
$this->nack_handler = $callback;
} | [
"public",
"function",
"set_nack_handler",
"(",
"$",
"callback",
")",
"{",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"callback",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Given callback \"%s\" should be callable. %s type was given.'",
",",
"$",
"callback",
",",
"gettype",
"(",
"$",
"callback",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"nack_handler",
"=",
"$",
"callback",
";",
"}"
] | Sets a handler which called for any message nack'ed by the server, with the AMQPMessage as first argument.
@param callable $callback
@throws \InvalidArgumentException | [
"Sets",
"a",
"handler",
"which",
"called",
"for",
"any",
"message",
"nack",
"ed",
"by",
"the",
"server",
"with",
"the",
"AMQPMessage",
"as",
"first",
"argument",
"."
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Channel/AMQPChannel.php#L1552-L1563 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Channel/AMQPChannel.php | AMQPChannel.set_ack_handler | public function set_ack_handler($callback)
{
if (!is_callable($callback)) {
throw new \InvalidArgumentException(sprintf(
'Given callback "%s" should be callable. %s type was given.',
$callback,
gettype($callback)
));
}
$this->ack_handler = $callback;
} | php | public function set_ack_handler($callback)
{
if (!is_callable($callback)) {
throw new \InvalidArgumentException(sprintf(
'Given callback "%s" should be callable. %s type was given.',
$callback,
gettype($callback)
));
}
$this->ack_handler = $callback;
} | [
"public",
"function",
"set_ack_handler",
"(",
"$",
"callback",
")",
"{",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"callback",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Given callback \"%s\" should be callable. %s type was given.'",
",",
"$",
"callback",
",",
"gettype",
"(",
"$",
"callback",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"ack_handler",
"=",
"$",
"callback",
";",
"}"
] | Sets a handler which called for any message ack'ed by the server, with the AMQPMessage as first argument.
@param callable $callback
@throws \InvalidArgumentException | [
"Sets",
"a",
"handler",
"which",
"called",
"for",
"any",
"message",
"ack",
"ed",
"by",
"the",
"server",
"with",
"the",
"AMQPMessage",
"as",
"first",
"argument",
"."
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Channel/AMQPChannel.php#L1571-L1582 | train |
php-amqplib/php-amqplib | demo/amqp_consumer_signals.php | Consumer.start | public function start()
{
if ($this->restart) {
echo 'Restarting consumer.' . PHP_EOL;
$this->restart = false;
} else {
echo 'Starting consumer.' . PHP_EOL;
}
$exchange = 'router';
$queue = 'msgs';
$this->channel = $this->connection->channel();
$this->channel->queue_declare($queue, false, true, false, false);
$this->channel->exchange_declare($exchange, AMQPExchangeType::DIRECT, false, true, false);
$this->channel->queue_bind($queue, $exchange);
$this->channel->basic_consume(
$queue,
$this->consumerTag,
false,
false,
false,
false,
[$this,'messageHandler'],
null,
['x-cancel-on-ha-failover' => ['t', true]] // fail over to another node
);
echo 'Enter wait.' . PHP_EOL;
while ($this->channel->is_consuming()) {
$this->channel->wait();
}
echo 'Exit wait.' . PHP_EOL;
} | php | public function start()
{
if ($this->restart) {
echo 'Restarting consumer.' . PHP_EOL;
$this->restart = false;
} else {
echo 'Starting consumer.' . PHP_EOL;
}
$exchange = 'router';
$queue = 'msgs';
$this->channel = $this->connection->channel();
$this->channel->queue_declare($queue, false, true, false, false);
$this->channel->exchange_declare($exchange, AMQPExchangeType::DIRECT, false, true, false);
$this->channel->queue_bind($queue, $exchange);
$this->channel->basic_consume(
$queue,
$this->consumerTag,
false,
false,
false,
false,
[$this,'messageHandler'],
null,
['x-cancel-on-ha-failover' => ['t', true]] // fail over to another node
);
echo 'Enter wait.' . PHP_EOL;
while ($this->channel->is_consuming()) {
$this->channel->wait();
}
echo 'Exit wait.' . PHP_EOL;
} | [
"public",
"function",
"start",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"restart",
")",
"{",
"echo",
"'Restarting consumer.'",
".",
"PHP_EOL",
";",
"$",
"this",
"->",
"restart",
"=",
"false",
";",
"}",
"else",
"{",
"echo",
"'Starting consumer.'",
".",
"PHP_EOL",
";",
"}",
"$",
"exchange",
"=",
"'router'",
";",
"$",
"queue",
"=",
"'msgs'",
";",
"$",
"this",
"->",
"channel",
"=",
"$",
"this",
"->",
"connection",
"->",
"channel",
"(",
")",
";",
"$",
"this",
"->",
"channel",
"->",
"queue_declare",
"(",
"$",
"queue",
",",
"false",
",",
"true",
",",
"false",
",",
"false",
")",
";",
"$",
"this",
"->",
"channel",
"->",
"exchange_declare",
"(",
"$",
"exchange",
",",
"AMQPExchangeType",
"::",
"DIRECT",
",",
"false",
",",
"true",
",",
"false",
")",
";",
"$",
"this",
"->",
"channel",
"->",
"queue_bind",
"(",
"$",
"queue",
",",
"$",
"exchange",
")",
";",
"$",
"this",
"->",
"channel",
"->",
"basic_consume",
"(",
"$",
"queue",
",",
"$",
"this",
"->",
"consumerTag",
",",
"false",
",",
"false",
",",
"false",
",",
"false",
",",
"[",
"$",
"this",
",",
"'messageHandler'",
"]",
",",
"null",
",",
"[",
"'x-cancel-on-ha-failover'",
"=>",
"[",
"'t'",
",",
"true",
"]",
"]",
"// fail over to another node",
")",
";",
"echo",
"'Enter wait.'",
".",
"PHP_EOL",
";",
"while",
"(",
"$",
"this",
"->",
"channel",
"->",
"is_consuming",
"(",
")",
")",
"{",
"$",
"this",
"->",
"channel",
"->",
"wait",
"(",
")",
";",
"}",
"echo",
"'Exit wait.'",
".",
"PHP_EOL",
";",
"}"
] | Start a consumer on an existing connection
@return void | [
"Start",
"a",
"consumer",
"on",
"an",
"existing",
"connection"
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/demo/amqp_consumer_signals.php#L127-L160 | train |
php-amqplib/php-amqplib | PhpAmqpLib/Helper/MiscHelper.php | MiscHelper.hexdump | public static function hexdump($data, $htmloutput = true, $uppercase = false, $return = false)
{
// Init
$hexi = '';
$ascii = '';
$dump = $htmloutput ? '<pre>' : '';
$offset = 0;
$len = mb_strlen($data, 'ASCII');
// Upper or lower case hexidecimal
$hexFormat = $uppercase ? 'X' : 'x';
// Iterate string
for ($i = $j = 0; $i < $len; $i++) {
// Convert to hexidecimal
// We must use concatenation here because the $hexFormat value
// is needed for sprintf() to parse the format
$hexi .= sprintf('%02' . $hexFormat . ' ', ord($data[$i]));
// Replace non-viewable bytes with '.'
if (ord($data[$i]) >= 32) {
$ascii .= $htmloutput ? htmlentities($data[$i]) : $data[$i];
} else {
$ascii .= '.';
}
// Add extra column spacing
if ($j === 7) {
$hexi .= ' ';
$ascii .= ' ';
}
// Add row
if (++$j === 16 || $i === $len - 1) {
// Join the hexi / ascii output
// We must use concatenation here because the $hexFormat value
// is needed for sprintf() to parse the format
$dump .= sprintf('%04' . $hexFormat . ' %-49s %s', $offset, $hexi, $ascii);
// Reset vars
$hexi = $ascii = '';
$offset += 16;
$j = 0;
// Add newline
if ($i !== $len - 1) {
$dump .= PHP_EOL;
}
}
}
// Finish dump
$dump .= $htmloutput ? '</pre>' : '';
$dump .= PHP_EOL;
if ($return) {
return $dump;
}
echo $dump;
} | php | public static function hexdump($data, $htmloutput = true, $uppercase = false, $return = false)
{
// Init
$hexi = '';
$ascii = '';
$dump = $htmloutput ? '<pre>' : '';
$offset = 0;
$len = mb_strlen($data, 'ASCII');
// Upper or lower case hexidecimal
$hexFormat = $uppercase ? 'X' : 'x';
// Iterate string
for ($i = $j = 0; $i < $len; $i++) {
// Convert to hexidecimal
// We must use concatenation here because the $hexFormat value
// is needed for sprintf() to parse the format
$hexi .= sprintf('%02' . $hexFormat . ' ', ord($data[$i]));
// Replace non-viewable bytes with '.'
if (ord($data[$i]) >= 32) {
$ascii .= $htmloutput ? htmlentities($data[$i]) : $data[$i];
} else {
$ascii .= '.';
}
// Add extra column spacing
if ($j === 7) {
$hexi .= ' ';
$ascii .= ' ';
}
// Add row
if (++$j === 16 || $i === $len - 1) {
// Join the hexi / ascii output
// We must use concatenation here because the $hexFormat value
// is needed for sprintf() to parse the format
$dump .= sprintf('%04' . $hexFormat . ' %-49s %s', $offset, $hexi, $ascii);
// Reset vars
$hexi = $ascii = '';
$offset += 16;
$j = 0;
// Add newline
if ($i !== $len - 1) {
$dump .= PHP_EOL;
}
}
}
// Finish dump
$dump .= $htmloutput ? '</pre>' : '';
$dump .= PHP_EOL;
if ($return) {
return $dump;
}
echo $dump;
} | [
"public",
"static",
"function",
"hexdump",
"(",
"$",
"data",
",",
"$",
"htmloutput",
"=",
"true",
",",
"$",
"uppercase",
"=",
"false",
",",
"$",
"return",
"=",
"false",
")",
"{",
"// Init",
"$",
"hexi",
"=",
"''",
";",
"$",
"ascii",
"=",
"''",
";",
"$",
"dump",
"=",
"$",
"htmloutput",
"?",
"'<pre>'",
":",
"''",
";",
"$",
"offset",
"=",
"0",
";",
"$",
"len",
"=",
"mb_strlen",
"(",
"$",
"data",
",",
"'ASCII'",
")",
";",
"// Upper or lower case hexidecimal",
"$",
"hexFormat",
"=",
"$",
"uppercase",
"?",
"'X'",
":",
"'x'",
";",
"// Iterate string",
"for",
"(",
"$",
"i",
"=",
"$",
"j",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"len",
";",
"$",
"i",
"++",
")",
"{",
"// Convert to hexidecimal",
"// We must use concatenation here because the $hexFormat value",
"// is needed for sprintf() to parse the format",
"$",
"hexi",
".=",
"sprintf",
"(",
"'%02'",
".",
"$",
"hexFormat",
".",
"' '",
",",
"ord",
"(",
"$",
"data",
"[",
"$",
"i",
"]",
")",
")",
";",
"// Replace non-viewable bytes with '.'",
"if",
"(",
"ord",
"(",
"$",
"data",
"[",
"$",
"i",
"]",
")",
">=",
"32",
")",
"{",
"$",
"ascii",
".=",
"$",
"htmloutput",
"?",
"htmlentities",
"(",
"$",
"data",
"[",
"$",
"i",
"]",
")",
":",
"$",
"data",
"[",
"$",
"i",
"]",
";",
"}",
"else",
"{",
"$",
"ascii",
".=",
"'.'",
";",
"}",
"// Add extra column spacing",
"if",
"(",
"$",
"j",
"===",
"7",
")",
"{",
"$",
"hexi",
".=",
"' '",
";",
"$",
"ascii",
".=",
"' '",
";",
"}",
"// Add row",
"if",
"(",
"++",
"$",
"j",
"===",
"16",
"||",
"$",
"i",
"===",
"$",
"len",
"-",
"1",
")",
"{",
"// Join the hexi / ascii output",
"// We must use concatenation here because the $hexFormat value",
"// is needed for sprintf() to parse the format",
"$",
"dump",
".=",
"sprintf",
"(",
"'%04'",
".",
"$",
"hexFormat",
".",
"' %-49s %s'",
",",
"$",
"offset",
",",
"$",
"hexi",
",",
"$",
"ascii",
")",
";",
"// Reset vars",
"$",
"hexi",
"=",
"$",
"ascii",
"=",
"''",
";",
"$",
"offset",
"+=",
"16",
";",
"$",
"j",
"=",
"0",
";",
"// Add newline",
"if",
"(",
"$",
"i",
"!==",
"$",
"len",
"-",
"1",
")",
"{",
"$",
"dump",
".=",
"PHP_EOL",
";",
"}",
"}",
"}",
"// Finish dump",
"$",
"dump",
".=",
"$",
"htmloutput",
"?",
"'</pre>'",
":",
"''",
";",
"$",
"dump",
".=",
"PHP_EOL",
";",
"if",
"(",
"$",
"return",
")",
"{",
"return",
"$",
"dump",
";",
"}",
"echo",
"$",
"dump",
";",
"}"
] | View any string as a hexdump.
This is most commonly used to view binary data from streams
or sockets while debugging, but can be used to view any string
with non-viewable characters.
@version 1.3.2
@author Aidan Lister <aidan@php.net>
@author Peter Waller <iridum@php.net>
@link http://aidanlister.com/repos/v/function.hexdump.php
@param string $data The string to be dumped
@param bool $htmloutput Set to false for non-HTML output
@param bool $uppercase Set to true for uppercase hex
@param bool $return Set to true to return the dump
@return string|null | [
"View",
"any",
"string",
"as",
"a",
"hexdump",
"."
] | 614bb57a3b600cd3c005fdcb8aa55a89ca0069f3 | https://github.com/php-amqplib/php-amqplib/blob/614bb57a3b600cd3c005fdcb8aa55a89ca0069f3/PhpAmqpLib/Helper/MiscHelper.php#L60-L120 | train |
flarum/core | src/Forum/Content/Discussion.php | Discussion.getApiDocument | protected function getApiDocument(User $actor, array $params)
{
$response = $this->api->send('Flarum\Api\Controller\ShowDiscussionController', $actor, $params);
$statusCode = $response->getStatusCode();
if ($statusCode === 404) {
throw new RouteNotFoundException;
}
return json_decode($response->getBody());
} | php | protected function getApiDocument(User $actor, array $params)
{
$response = $this->api->send('Flarum\Api\Controller\ShowDiscussionController', $actor, $params);
$statusCode = $response->getStatusCode();
if ($statusCode === 404) {
throw new RouteNotFoundException;
}
return json_decode($response->getBody());
} | [
"protected",
"function",
"getApiDocument",
"(",
"User",
"$",
"actor",
",",
"array",
"$",
"params",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"api",
"->",
"send",
"(",
"'Flarum\\Api\\Controller\\ShowDiscussionController'",
",",
"$",
"actor",
",",
"$",
"params",
")",
";",
"$",
"statusCode",
"=",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
";",
"if",
"(",
"$",
"statusCode",
"===",
"404",
")",
"{",
"throw",
"new",
"RouteNotFoundException",
";",
"}",
"return",
"json_decode",
"(",
"$",
"response",
"->",
"getBody",
"(",
")",
")",
";",
"}"
] | Get the result of an API request to show a discussion.
@param User $actor
@param array $params
@return object
@throws RouteNotFoundException | [
"Get",
"the",
"result",
"of",
"an",
"API",
"request",
"to",
"show",
"a",
"discussion",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Forum/Content/Discussion.php#L108-L118 | train |
flarum/core | src/Foundation/Application.php | Application.url | public function url($path = null)
{
$config = $this->make('flarum.config');
$url = array_get($config, 'url', array_get($_SERVER, 'REQUEST_URI'));
if (is_array($url)) {
if (isset($url[$path])) {
return $url[$path];
}
$url = $url['base'];
}
if ($path) {
$url .= '/'.array_get($config, "paths.$path", $path);
}
return $url;
} | php | public function url($path = null)
{
$config = $this->make('flarum.config');
$url = array_get($config, 'url', array_get($_SERVER, 'REQUEST_URI'));
if (is_array($url)) {
if (isset($url[$path])) {
return $url[$path];
}
$url = $url['base'];
}
if ($path) {
$url .= '/'.array_get($config, "paths.$path", $path);
}
return $url;
} | [
"public",
"function",
"url",
"(",
"$",
"path",
"=",
"null",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"make",
"(",
"'flarum.config'",
")",
";",
"$",
"url",
"=",
"array_get",
"(",
"$",
"config",
",",
"'url'",
",",
"array_get",
"(",
"$",
"_SERVER",
",",
"'REQUEST_URI'",
")",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"url",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"url",
"[",
"$",
"path",
"]",
")",
")",
"{",
"return",
"$",
"url",
"[",
"$",
"path",
"]",
";",
"}",
"$",
"url",
"=",
"$",
"url",
"[",
"'base'",
"]",
";",
"}",
"if",
"(",
"$",
"path",
")",
"{",
"$",
"url",
".=",
"'/'",
".",
"array_get",
"(",
"$",
"config",
",",
"\"paths.$path\"",
",",
"$",
"path",
")",
";",
"}",
"return",
"$",
"url",
";",
"}"
] | Get the URL to the Flarum installation.
@param string $path
@return string | [
"Get",
"the",
"URL",
"to",
"the",
"Flarum",
"installation",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Foundation/Application.php#L142-L160 | train |
flarum/core | src/Notification/NotificationServiceProvider.php | NotificationServiceProvider.registerNotificationTypes | public function registerNotificationTypes()
{
$blueprints = [
DiscussionRenamedBlueprint::class => ['alert']
];
$this->app->make('events')->fire(
new ConfigureNotificationTypes($blueprints)
);
foreach ($blueprints as $blueprint => $enabled) {
Notification::setSubjectModel(
$type = $blueprint::getType(),
$blueprint::getSubjectModel()
);
User::addPreference(
User::getNotificationPreferenceKey($type, 'alert'),
'boolval',
in_array('alert', $enabled)
);
if ((new ReflectionClass($blueprint))->implementsInterface(MailableInterface::class)) {
User::addPreference(
User::getNotificationPreferenceKey($type, 'email'),
'boolval',
in_array('email', $enabled)
);
}
}
} | php | public function registerNotificationTypes()
{
$blueprints = [
DiscussionRenamedBlueprint::class => ['alert']
];
$this->app->make('events')->fire(
new ConfigureNotificationTypes($blueprints)
);
foreach ($blueprints as $blueprint => $enabled) {
Notification::setSubjectModel(
$type = $blueprint::getType(),
$blueprint::getSubjectModel()
);
User::addPreference(
User::getNotificationPreferenceKey($type, 'alert'),
'boolval',
in_array('alert', $enabled)
);
if ((new ReflectionClass($blueprint))->implementsInterface(MailableInterface::class)) {
User::addPreference(
User::getNotificationPreferenceKey($type, 'email'),
'boolval',
in_array('email', $enabled)
);
}
}
} | [
"public",
"function",
"registerNotificationTypes",
"(",
")",
"{",
"$",
"blueprints",
"=",
"[",
"DiscussionRenamedBlueprint",
"::",
"class",
"=>",
"[",
"'alert'",
"]",
"]",
";",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'events'",
")",
"->",
"fire",
"(",
"new",
"ConfigureNotificationTypes",
"(",
"$",
"blueprints",
")",
")",
";",
"foreach",
"(",
"$",
"blueprints",
"as",
"$",
"blueprint",
"=>",
"$",
"enabled",
")",
"{",
"Notification",
"::",
"setSubjectModel",
"(",
"$",
"type",
"=",
"$",
"blueprint",
"::",
"getType",
"(",
")",
",",
"$",
"blueprint",
"::",
"getSubjectModel",
"(",
")",
")",
";",
"User",
"::",
"addPreference",
"(",
"User",
"::",
"getNotificationPreferenceKey",
"(",
"$",
"type",
",",
"'alert'",
")",
",",
"'boolval'",
",",
"in_array",
"(",
"'alert'",
",",
"$",
"enabled",
")",
")",
";",
"if",
"(",
"(",
"new",
"ReflectionClass",
"(",
"$",
"blueprint",
")",
")",
"->",
"implementsInterface",
"(",
"MailableInterface",
"::",
"class",
")",
")",
"{",
"User",
"::",
"addPreference",
"(",
"User",
"::",
"getNotificationPreferenceKey",
"(",
"$",
"type",
",",
"'email'",
")",
",",
"'boolval'",
",",
"in_array",
"(",
"'email'",
",",
"$",
"enabled",
")",
")",
";",
"}",
"}",
"}"
] | Register notification types. | [
"Register",
"notification",
"types",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Notification/NotificationServiceProvider.php#L33-L63 | train |
flarum/core | src/Frontend/Compiler/RevisionCompiler.php | RevisionCompiler.getFilenameForRevision | protected function getFilenameForRevision(string $revision): string
{
$ext = pathinfo($this->filename, PATHINFO_EXTENSION);
return substr_replace($this->filename, '-'.$revision, -strlen($ext) - 1, 0);
} | php | protected function getFilenameForRevision(string $revision): string
{
$ext = pathinfo($this->filename, PATHINFO_EXTENSION);
return substr_replace($this->filename, '-'.$revision, -strlen($ext) - 1, 0);
} | [
"protected",
"function",
"getFilenameForRevision",
"(",
"string",
"$",
"revision",
")",
":",
"string",
"{",
"$",
"ext",
"=",
"pathinfo",
"(",
"$",
"this",
"->",
"filename",
",",
"PATHINFO_EXTENSION",
")",
";",
"return",
"substr_replace",
"(",
"$",
"this",
"->",
"filename",
",",
"'-'",
".",
"$",
"revision",
",",
"-",
"strlen",
"(",
"$",
"ext",
")",
"-",
"1",
",",
"0",
")",
";",
"}"
] | Get the filename for the given revision.
@param string $revision
@return string | [
"Get",
"the",
"filename",
"for",
"the",
"given",
"revision",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Frontend/Compiler/RevisionCompiler.php#L190-L195 | train |
flarum/core | src/Notification/NotificationRepository.php | NotificationRepository.findByUser | public function findByUser(User $user, $limit = null, $offset = 0)
{
$primaries = Notification::select(
app('flarum.db')->raw('MAX(id) AS id'),
app('flarum.db')->raw('SUM(read_at IS NULL) AS unread_count')
)
->where('user_id', $user->id)
->whereIn('type', $user->getAlertableNotificationTypes())
->where('is_deleted', false)
->whereSubjectVisibleTo($user)
->groupBy('type', 'subject_id')
->orderByRaw('MAX(created_at) DESC')
->skip($offset)
->take($limit);
return Notification::select('notifications.*', app('flarum.db')->raw('p.unread_count'))
->mergeBindings($primaries->getQuery())
->join(app('flarum.db')->raw('('.$primaries->toSql().') p'), 'notifications.id', '=', app('flarum.db')->raw('p.id'))
->latest()
->get();
} | php | public function findByUser(User $user, $limit = null, $offset = 0)
{
$primaries = Notification::select(
app('flarum.db')->raw('MAX(id) AS id'),
app('flarum.db')->raw('SUM(read_at IS NULL) AS unread_count')
)
->where('user_id', $user->id)
->whereIn('type', $user->getAlertableNotificationTypes())
->where('is_deleted', false)
->whereSubjectVisibleTo($user)
->groupBy('type', 'subject_id')
->orderByRaw('MAX(created_at) DESC')
->skip($offset)
->take($limit);
return Notification::select('notifications.*', app('flarum.db')->raw('p.unread_count'))
->mergeBindings($primaries->getQuery())
->join(app('flarum.db')->raw('('.$primaries->toSql().') p'), 'notifications.id', '=', app('flarum.db')->raw('p.id'))
->latest()
->get();
} | [
"public",
"function",
"findByUser",
"(",
"User",
"$",
"user",
",",
"$",
"limit",
"=",
"null",
",",
"$",
"offset",
"=",
"0",
")",
"{",
"$",
"primaries",
"=",
"Notification",
"::",
"select",
"(",
"app",
"(",
"'flarum.db'",
")",
"->",
"raw",
"(",
"'MAX(id) AS id'",
")",
",",
"app",
"(",
"'flarum.db'",
")",
"->",
"raw",
"(",
"'SUM(read_at IS NULL) AS unread_count'",
")",
")",
"->",
"where",
"(",
"'user_id'",
",",
"$",
"user",
"->",
"id",
")",
"->",
"whereIn",
"(",
"'type'",
",",
"$",
"user",
"->",
"getAlertableNotificationTypes",
"(",
")",
")",
"->",
"where",
"(",
"'is_deleted'",
",",
"false",
")",
"->",
"whereSubjectVisibleTo",
"(",
"$",
"user",
")",
"->",
"groupBy",
"(",
"'type'",
",",
"'subject_id'",
")",
"->",
"orderByRaw",
"(",
"'MAX(created_at) DESC'",
")",
"->",
"skip",
"(",
"$",
"offset",
")",
"->",
"take",
"(",
"$",
"limit",
")",
";",
"return",
"Notification",
"::",
"select",
"(",
"'notifications.*'",
",",
"app",
"(",
"'flarum.db'",
")",
"->",
"raw",
"(",
"'p.unread_count'",
")",
")",
"->",
"mergeBindings",
"(",
"$",
"primaries",
"->",
"getQuery",
"(",
")",
")",
"->",
"join",
"(",
"app",
"(",
"'flarum.db'",
")",
"->",
"raw",
"(",
"'('",
".",
"$",
"primaries",
"->",
"toSql",
"(",
")",
".",
"') p'",
")",
",",
"'notifications.id'",
",",
"'='",
",",
"app",
"(",
"'flarum.db'",
")",
"->",
"raw",
"(",
"'p.id'",
")",
")",
"->",
"latest",
"(",
")",
"->",
"get",
"(",
")",
";",
"}"
] | Find a user's notifications.
@param User $user
@param int|null $limit
@param int $offset
@return \Illuminate\Database\Eloquent\Collection | [
"Find",
"a",
"user",
"s",
"notifications",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Notification/NotificationRepository.php#L27-L47 | train |
flarum/core | src/Notification/NotificationRepository.php | NotificationRepository.markAllAsRead | public function markAllAsRead(User $user)
{
Notification::where('user_id', $user->id)->update(['read_at' => Carbon::now()]);
} | php | public function markAllAsRead(User $user)
{
Notification::where('user_id', $user->id)->update(['read_at' => Carbon::now()]);
} | [
"public",
"function",
"markAllAsRead",
"(",
"User",
"$",
"user",
")",
"{",
"Notification",
"::",
"where",
"(",
"'user_id'",
",",
"$",
"user",
"->",
"id",
")",
"->",
"update",
"(",
"[",
"'read_at'",
"=>",
"Carbon",
"::",
"now",
"(",
")",
"]",
")",
";",
"}"
] | Mark all of a user's notifications as read.
@param User $user
@return void | [
"Mark",
"all",
"of",
"a",
"user",
"s",
"notifications",
"as",
"read",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Notification/NotificationRepository.php#L56-L59 | train |
flarum/core | src/Http/AccessToken.php | AccessToken.generate | public static function generate($userId, $lifetime = 3600)
{
$token = new static;
$token->token = str_random(40);
$token->user_id = $userId;
$token->created_at = Carbon::now();
$token->last_activity_at = Carbon::now();
$token->lifetime_seconds = $lifetime;
return $token;
} | php | public static function generate($userId, $lifetime = 3600)
{
$token = new static;
$token->token = str_random(40);
$token->user_id = $userId;
$token->created_at = Carbon::now();
$token->last_activity_at = Carbon::now();
$token->lifetime_seconds = $lifetime;
return $token;
} | [
"public",
"static",
"function",
"generate",
"(",
"$",
"userId",
",",
"$",
"lifetime",
"=",
"3600",
")",
"{",
"$",
"token",
"=",
"new",
"static",
";",
"$",
"token",
"->",
"token",
"=",
"str_random",
"(",
"40",
")",
";",
"$",
"token",
"->",
"user_id",
"=",
"$",
"userId",
";",
"$",
"token",
"->",
"created_at",
"=",
"Carbon",
"::",
"now",
"(",
")",
";",
"$",
"token",
"->",
"last_activity_at",
"=",
"Carbon",
"::",
"now",
"(",
")",
";",
"$",
"token",
"->",
"lifetime_seconds",
"=",
"$",
"lifetime",
";",
"return",
"$",
"token",
";",
"}"
] | Generate an access token for the specified user.
@param int $userId
@param int $lifetime
@return static | [
"Generate",
"an",
"access",
"token",
"for",
"the",
"specified",
"user",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Http/AccessToken.php#L46-L57 | train |
flarum/core | src/Http/RouteCollectionUrlGenerator.php | RouteCollectionUrlGenerator.route | public function route($name, $parameters = [])
{
$path = $this->routes->getPath($name, $parameters);
$path = ltrim($path, '/');
return $this->baseUrl.'/'.$path;
} | php | public function route($name, $parameters = [])
{
$path = $this->routes->getPath($name, $parameters);
$path = ltrim($path, '/');
return $this->baseUrl.'/'.$path;
} | [
"public",
"function",
"route",
"(",
"$",
"name",
",",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"routes",
"->",
"getPath",
"(",
"$",
"name",
",",
"$",
"parameters",
")",
";",
"$",
"path",
"=",
"ltrim",
"(",
"$",
"path",
",",
"'/'",
")",
";",
"return",
"$",
"this",
"->",
"baseUrl",
".",
"'/'",
".",
"$",
"path",
";",
"}"
] | Generate a URL to a named route.
@param string $name
@param array $parameters
@return string | [
"Generate",
"a",
"URL",
"to",
"a",
"named",
"route",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Http/RouteCollectionUrlGenerator.php#L43-L49 | train |
flarum/core | src/Foundation/AbstractValidator.php | AbstractValidator.assertValid | public function assertValid(array $attributes)
{
$validator = $this->makeValidator($attributes);
if ($validator->fails()) {
throw new ValidationException($validator);
}
} | php | public function assertValid(array $attributes)
{
$validator = $this->makeValidator($attributes);
if ($validator->fails()) {
throw new ValidationException($validator);
}
} | [
"public",
"function",
"assertValid",
"(",
"array",
"$",
"attributes",
")",
"{",
"$",
"validator",
"=",
"$",
"this",
"->",
"makeValidator",
"(",
"$",
"attributes",
")",
";",
"if",
"(",
"$",
"validator",
"->",
"fails",
"(",
")",
")",
"{",
"throw",
"new",
"ValidationException",
"(",
"$",
"validator",
")",
";",
"}",
"}"
] | Throw an exception if a model is not valid.
@param array $attributes | [
"Throw",
"an",
"exception",
"if",
"a",
"model",
"is",
"not",
"valid",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Foundation/AbstractValidator.php#L59-L66 | train |
flarum/core | src/Foundation/AbstractValidator.php | AbstractValidator.makeValidator | protected function makeValidator(array $attributes)
{
$rules = array_only($this->getRules(), array_keys($attributes));
$validator = $this->validator->make($attributes, $rules, $this->getMessages());
$this->events->dispatch(
new Validating($this, $validator)
);
return $validator;
} | php | protected function makeValidator(array $attributes)
{
$rules = array_only($this->getRules(), array_keys($attributes));
$validator = $this->validator->make($attributes, $rules, $this->getMessages());
$this->events->dispatch(
new Validating($this, $validator)
);
return $validator;
} | [
"protected",
"function",
"makeValidator",
"(",
"array",
"$",
"attributes",
")",
"{",
"$",
"rules",
"=",
"array_only",
"(",
"$",
"this",
"->",
"getRules",
"(",
")",
",",
"array_keys",
"(",
"$",
"attributes",
")",
")",
";",
"$",
"validator",
"=",
"$",
"this",
"->",
"validator",
"->",
"make",
"(",
"$",
"attributes",
",",
"$",
"rules",
",",
"$",
"this",
"->",
"getMessages",
"(",
")",
")",
";",
"$",
"this",
"->",
"events",
"->",
"dispatch",
"(",
"new",
"Validating",
"(",
"$",
"this",
",",
"$",
"validator",
")",
")",
";",
"return",
"$",
"validator",
";",
"}"
] | Make a new validator instance for this model.
@param array $attributes
@return \Illuminate\Validation\Validator | [
"Make",
"a",
"new",
"validator",
"instance",
"for",
"this",
"model",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Foundation/AbstractValidator.php#L90-L101 | train |
flarum/core | src/Forum/Content/Index.php | Index.getApiDocument | private function getApiDocument(User $actor, array $params)
{
return json_decode($this->api->send(ListDiscussionsController::class, $actor, $params)->getBody());
} | php | private function getApiDocument(User $actor, array $params)
{
return json_decode($this->api->send(ListDiscussionsController::class, $actor, $params)->getBody());
} | [
"private",
"function",
"getApiDocument",
"(",
"User",
"$",
"actor",
",",
"array",
"$",
"params",
")",
"{",
"return",
"json_decode",
"(",
"$",
"this",
"->",
"api",
"->",
"send",
"(",
"ListDiscussionsController",
"::",
"class",
",",
"$",
"actor",
",",
"$",
"params",
")",
"->",
"getBody",
"(",
")",
")",
";",
"}"
] | Get the result of an API request to list discussions.
@param User $actor
@param array $params
@return object | [
"Get",
"the",
"result",
"of",
"an",
"API",
"request",
"to",
"list",
"discussions",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Forum/Content/Index.php#L89-L92 | train |
flarum/core | src/Api/ApiServiceProvider.php | ApiServiceProvider.registerNotificationSerializers | protected function registerNotificationSerializers()
{
$blueprints = [];
$serializers = [
'discussionRenamed' => BasicDiscussionSerializer::class
];
$this->app->make('events')->fire(
new ConfigureNotificationTypes($blueprints, $serializers)
);
foreach ($serializers as $type => $serializer) {
NotificationSerializer::setSubjectSerializer($type, $serializer);
}
} | php | protected function registerNotificationSerializers()
{
$blueprints = [];
$serializers = [
'discussionRenamed' => BasicDiscussionSerializer::class
];
$this->app->make('events')->fire(
new ConfigureNotificationTypes($blueprints, $serializers)
);
foreach ($serializers as $type => $serializer) {
NotificationSerializer::setSubjectSerializer($type, $serializer);
}
} | [
"protected",
"function",
"registerNotificationSerializers",
"(",
")",
"{",
"$",
"blueprints",
"=",
"[",
"]",
";",
"$",
"serializers",
"=",
"[",
"'discussionRenamed'",
"=>",
"BasicDiscussionSerializer",
"::",
"class",
"]",
";",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'events'",
")",
"->",
"fire",
"(",
"new",
"ConfigureNotificationTypes",
"(",
"$",
"blueprints",
",",
"$",
"serializers",
")",
")",
";",
"foreach",
"(",
"$",
"serializers",
"as",
"$",
"type",
"=>",
"$",
"serializer",
")",
"{",
"NotificationSerializer",
"::",
"setSubjectSerializer",
"(",
"$",
"type",
",",
"$",
"serializer",
")",
";",
"}",
"}"
] | Register notification serializers. | [
"Register",
"notification",
"serializers",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Api/ApiServiceProvider.php#L108-L122 | train |
flarum/core | src/Api/ApiServiceProvider.php | ApiServiceProvider.populateRoutes | protected function populateRoutes(RouteCollection $routes)
{
$factory = $this->app->make(RouteHandlerFactory::class);
$callback = include __DIR__.'/routes.php';
$callback($routes, $factory);
$this->app->make('events')->fire(
new ConfigureApiRoutes($routes, $factory)
);
} | php | protected function populateRoutes(RouteCollection $routes)
{
$factory = $this->app->make(RouteHandlerFactory::class);
$callback = include __DIR__.'/routes.php';
$callback($routes, $factory);
$this->app->make('events')->fire(
new ConfigureApiRoutes($routes, $factory)
);
} | [
"protected",
"function",
"populateRoutes",
"(",
"RouteCollection",
"$",
"routes",
")",
"{",
"$",
"factory",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"RouteHandlerFactory",
"::",
"class",
")",
";",
"$",
"callback",
"=",
"include",
"__DIR__",
".",
"'/routes.php'",
";",
"$",
"callback",
"(",
"$",
"routes",
",",
"$",
"factory",
")",
";",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'events'",
")",
"->",
"fire",
"(",
"new",
"ConfigureApiRoutes",
"(",
"$",
"routes",
",",
"$",
"factory",
")",
")",
";",
"}"
] | Populate the API routes.
@param RouteCollection $routes | [
"Populate",
"the",
"API",
"routes",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Api/ApiServiceProvider.php#L129-L139 | train |
flarum/core | src/User/User.php | User.rename | public function rename($username)
{
if ($username !== $this->username) {
$oldUsername = $this->username;
$this->username = $username;
$this->raise(new Renamed($this, $oldUsername));
}
return $this;
} | php | public function rename($username)
{
if ($username !== $this->username) {
$oldUsername = $this->username;
$this->username = $username;
$this->raise(new Renamed($this, $oldUsername));
}
return $this;
} | [
"public",
"function",
"rename",
"(",
"$",
"username",
")",
"{",
"if",
"(",
"$",
"username",
"!==",
"$",
"this",
"->",
"username",
")",
"{",
"$",
"oldUsername",
"=",
"$",
"this",
"->",
"username",
";",
"$",
"this",
"->",
"username",
"=",
"$",
"username",
";",
"$",
"this",
"->",
"raise",
"(",
"new",
"Renamed",
"(",
"$",
"this",
",",
"$",
"oldUsername",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Rename the user.
@param string $username
@return $this | [
"Rename",
"the",
"user",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/User/User.php#L179-L189 | train |
flarum/core | src/User/User.php | User.changeEmail | public function changeEmail($email)
{
if ($email !== $this->email) {
$this->email = $email;
$this->raise(new EmailChanged($this));
}
return $this;
} | php | public function changeEmail($email)
{
if ($email !== $this->email) {
$this->email = $email;
$this->raise(new EmailChanged($this));
}
return $this;
} | [
"public",
"function",
"changeEmail",
"(",
"$",
"email",
")",
"{",
"if",
"(",
"$",
"email",
"!==",
"$",
"this",
"->",
"email",
")",
"{",
"$",
"this",
"->",
"email",
"=",
"$",
"email",
";",
"$",
"this",
"->",
"raise",
"(",
"new",
"EmailChanged",
"(",
"$",
"this",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Change the user's email.
@param string $email
@return $this | [
"Change",
"the",
"user",
"s",
"email",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/User/User.php#L197-L206 | train |
flarum/core | src/User/User.php | User.requestEmailChange | public function requestEmailChange($email)
{
if ($email !== $this->email) {
$this->raise(new EmailChangeRequested($this, $email));
}
return $this;
} | php | public function requestEmailChange($email)
{
if ($email !== $this->email) {
$this->raise(new EmailChangeRequested($this, $email));
}
return $this;
} | [
"public",
"function",
"requestEmailChange",
"(",
"$",
"email",
")",
"{",
"if",
"(",
"$",
"email",
"!==",
"$",
"this",
"->",
"email",
")",
"{",
"$",
"this",
"->",
"raise",
"(",
"new",
"EmailChangeRequested",
"(",
"$",
"this",
",",
"$",
"email",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Request that the user's email be changed.
@param string $email
@return $this | [
"Request",
"that",
"the",
"user",
"s",
"email",
"be",
"changed",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/User/User.php#L214-L221 | train |
flarum/core | src/User/User.php | User.changeAvatarPath | public function changeAvatarPath($path)
{
$this->avatar_url = $path;
$this->raise(new AvatarChanged($this));
return $this;
} | php | public function changeAvatarPath($path)
{
$this->avatar_url = $path;
$this->raise(new AvatarChanged($this));
return $this;
} | [
"public",
"function",
"changeAvatarPath",
"(",
"$",
"path",
")",
"{",
"$",
"this",
"->",
"avatar_url",
"=",
"$",
"path",
";",
"$",
"this",
"->",
"raise",
"(",
"new",
"AvatarChanged",
"(",
"$",
"this",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Change the path of the user avatar.
@param string $path
@return $this | [
"Change",
"the",
"path",
"of",
"the",
"user",
"avatar",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/User/User.php#L278-L285 | train |
flarum/core | src/User/User.php | User.getAvatarUrlAttribute | public function getAvatarUrlAttribute(string $value = null)
{
if ($value && strpos($value, '://') === false) {
return app(UrlGenerator::class)->to('forum')->path('assets/avatars/'.$value);
}
return $value;
} | php | public function getAvatarUrlAttribute(string $value = null)
{
if ($value && strpos($value, '://') === false) {
return app(UrlGenerator::class)->to('forum')->path('assets/avatars/'.$value);
}
return $value;
} | [
"public",
"function",
"getAvatarUrlAttribute",
"(",
"string",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"value",
"&&",
"strpos",
"(",
"$",
"value",
",",
"'://'",
")",
"===",
"false",
")",
"{",
"return",
"app",
"(",
"UrlGenerator",
"::",
"class",
")",
"->",
"to",
"(",
"'forum'",
")",
"->",
"path",
"(",
"'assets/avatars/'",
".",
"$",
"value",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Get the URL of the user's avatar.
@todo Allow different storage locations to be used
@param string|null $value
@return string | [
"Get",
"the",
"URL",
"of",
"the",
"user",
"s",
"avatar",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/User/User.php#L294-L301 | train |
flarum/core | src/User/User.php | User.checkPassword | public function checkPassword($password)
{
$valid = static::$dispatcher->until(new CheckingPassword($this, $password));
if ($valid !== null) {
return $valid;
}
return static::$hasher->check($password, $this->password);
} | php | public function checkPassword($password)
{
$valid = static::$dispatcher->until(new CheckingPassword($this, $password));
if ($valid !== null) {
return $valid;
}
return static::$hasher->check($password, $this->password);
} | [
"public",
"function",
"checkPassword",
"(",
"$",
"password",
")",
"{",
"$",
"valid",
"=",
"static",
"::",
"$",
"dispatcher",
"->",
"until",
"(",
"new",
"CheckingPassword",
"(",
"$",
"this",
",",
"$",
"password",
")",
")",
";",
"if",
"(",
"$",
"valid",
"!==",
"null",
")",
"{",
"return",
"$",
"valid",
";",
"}",
"return",
"static",
"::",
"$",
"hasher",
"->",
"check",
"(",
"$",
"password",
",",
"$",
"this",
"->",
"password",
")",
";",
"}"
] | Check if a given password matches the user's password.
@param string $password
@return bool | [
"Check",
"if",
"a",
"given",
"password",
"matches",
"the",
"user",
"s",
"password",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/User/User.php#L319-L328 | train |
flarum/core | src/User/User.php | User.activate | public function activate()
{
if ($this->is_email_confirmed !== true) {
$this->is_email_confirmed = true;
$this->raise(new Activated($this));
}
return $this;
} | php | public function activate()
{
if ($this->is_email_confirmed !== true) {
$this->is_email_confirmed = true;
$this->raise(new Activated($this));
}
return $this;
} | [
"public",
"function",
"activate",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"is_email_confirmed",
"!==",
"true",
")",
"{",
"$",
"this",
"->",
"is_email_confirmed",
"=",
"true",
";",
"$",
"this",
"->",
"raise",
"(",
"new",
"Activated",
"(",
"$",
"this",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Activate the user's account.
@return $this | [
"Activate",
"the",
"user",
"s",
"account",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/User/User.php#L335-L344 | train |
flarum/core | src/User/User.php | User.hasPermission | public function hasPermission($permission)
{
if ($this->isAdmin()) {
return true;
}
if (is_null($this->permissions)) {
$this->permissions = $this->getPermissions();
}
return in_array($permission, $this->permissions);
} | php | public function hasPermission($permission)
{
if ($this->isAdmin()) {
return true;
}
if (is_null($this->permissions)) {
$this->permissions = $this->getPermissions();
}
return in_array($permission, $this->permissions);
} | [
"public",
"function",
"hasPermission",
"(",
"$",
"permission",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isAdmin",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"permissions",
")",
")",
"{",
"$",
"this",
"->",
"permissions",
"=",
"$",
"this",
"->",
"getPermissions",
"(",
")",
";",
"}",
"return",
"in_array",
"(",
"$",
"permission",
",",
"$",
"this",
"->",
"permissions",
")",
";",
"}"
] | Check whether the user has a certain permission based on their groups.
@param string $permission
@return bool | [
"Check",
"whether",
"the",
"user",
"has",
"a",
"certain",
"permission",
"based",
"on",
"their",
"groups",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/User/User.php#L352-L363 | train |
flarum/core | src/User/User.php | User.hasPermissionLike | public function hasPermissionLike($match)
{
if ($this->isAdmin()) {
return true;
}
if (is_null($this->permissions)) {
$this->permissions = $this->getPermissions();
}
foreach ($this->permissions as $permission) {
if (substr($permission, -strlen($match)) === $match) {
return true;
}
}
return false;
} | php | public function hasPermissionLike($match)
{
if ($this->isAdmin()) {
return true;
}
if (is_null($this->permissions)) {
$this->permissions = $this->getPermissions();
}
foreach ($this->permissions as $permission) {
if (substr($permission, -strlen($match)) === $match) {
return true;
}
}
return false;
} | [
"public",
"function",
"hasPermissionLike",
"(",
"$",
"match",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isAdmin",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"permissions",
")",
")",
"{",
"$",
"this",
"->",
"permissions",
"=",
"$",
"this",
"->",
"getPermissions",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"permissions",
"as",
"$",
"permission",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"permission",
",",
"-",
"strlen",
"(",
"$",
"match",
")",
")",
"===",
"$",
"match",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Check whether the user has a permission that is like the given string,
based on their groups.
@param string $match
@return bool | [
"Check",
"whether",
"the",
"user",
"has",
"a",
"permission",
"that",
"is",
"like",
"the",
"given",
"string",
"based",
"on",
"their",
"groups",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/User/User.php#L372-L389 | train |
flarum/core | src/User/User.php | User.getUnreadNotifications | protected function getUnreadNotifications()
{
static $cached = null;
if (is_null($cached)) {
$cached = $this->notifications()
->whereIn('type', $this->getAlertableNotificationTypes())
->whereNull('read_at')
->where('is_deleted', false)
->whereSubjectVisibleTo($this)
->get();
}
return $cached;
} | php | protected function getUnreadNotifications()
{
static $cached = null;
if (is_null($cached)) {
$cached = $this->notifications()
->whereIn('type', $this->getAlertableNotificationTypes())
->whereNull('read_at')
->where('is_deleted', false)
->whereSubjectVisibleTo($this)
->get();
}
return $cached;
} | [
"protected",
"function",
"getUnreadNotifications",
"(",
")",
"{",
"static",
"$",
"cached",
"=",
"null",
";",
"if",
"(",
"is_null",
"(",
"$",
"cached",
")",
")",
"{",
"$",
"cached",
"=",
"$",
"this",
"->",
"notifications",
"(",
")",
"->",
"whereIn",
"(",
"'type'",
",",
"$",
"this",
"->",
"getAlertableNotificationTypes",
"(",
")",
")",
"->",
"whereNull",
"(",
"'read_at'",
")",
"->",
"where",
"(",
"'is_deleted'",
",",
"false",
")",
"->",
"whereSubjectVisibleTo",
"(",
"$",
"this",
")",
"->",
"get",
"(",
")",
";",
"}",
"return",
"$",
"cached",
";",
"}"
] | Get all notifications that have not been read yet.
@return \Illuminate\Database\Eloquent\Collection | [
"Get",
"all",
"notifications",
"that",
"have",
"not",
"been",
"read",
"yet",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/User/User.php#L419-L433 | train |
flarum/core | src/User/User.php | User.getNewNotificationCount | public function getNewNotificationCount()
{
return $this->getUnreadNotifications()->filter(function ($notification) {
return $notification->created_at > $this->read_notifications_at ?: 0;
})->count();
} | php | public function getNewNotificationCount()
{
return $this->getUnreadNotifications()->filter(function ($notification) {
return $notification->created_at > $this->read_notifications_at ?: 0;
})->count();
} | [
"public",
"function",
"getNewNotificationCount",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"getUnreadNotifications",
"(",
")",
"->",
"filter",
"(",
"function",
"(",
"$",
"notification",
")",
"{",
"return",
"$",
"notification",
"->",
"created_at",
">",
"$",
"this",
"->",
"read_notifications_at",
"?",
":",
"0",
";",
"}",
")",
"->",
"count",
"(",
")",
";",
"}"
] | Get the number of new, unseen notifications for the user.
@return int | [
"Get",
"the",
"number",
"of",
"new",
"unseen",
"notifications",
"for",
"the",
"user",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/User/User.php#L440-L445 | train |
flarum/core | src/User/User.php | User.getPreferencesAttribute | public function getPreferencesAttribute($value)
{
$defaults = array_map(function ($value) {
return $value['default'];
}, static::$preferences);
$user = array_only((array) json_decode($value, true), array_keys(static::$preferences));
return array_merge($defaults, $user);
} | php | public function getPreferencesAttribute($value)
{
$defaults = array_map(function ($value) {
return $value['default'];
}, static::$preferences);
$user = array_only((array) json_decode($value, true), array_keys(static::$preferences));
return array_merge($defaults, $user);
} | [
"public",
"function",
"getPreferencesAttribute",
"(",
"$",
"value",
")",
"{",
"$",
"defaults",
"=",
"array_map",
"(",
"function",
"(",
"$",
"value",
")",
"{",
"return",
"$",
"value",
"[",
"'default'",
"]",
";",
"}",
",",
"static",
"::",
"$",
"preferences",
")",
";",
"$",
"user",
"=",
"array_only",
"(",
"(",
"array",
")",
"json_decode",
"(",
"$",
"value",
",",
"true",
")",
",",
"array_keys",
"(",
"static",
"::",
"$",
"preferences",
")",
")",
";",
"return",
"array_merge",
"(",
"$",
"defaults",
",",
"$",
"user",
")",
";",
"}"
] | Get the values of all registered preferences for this user, by
transforming their stored preferences and merging them with the defaults.
@param string $value
@return array | [
"Get",
"the",
"values",
"of",
"all",
"registered",
"preferences",
"for",
"this",
"user",
"by",
"transforming",
"their",
"stored",
"preferences",
"and",
"merging",
"them",
"with",
"the",
"defaults",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/User/User.php#L454-L463 | train |
flarum/core | src/User/User.php | User.setPreference | public function setPreference($key, $value)
{
if (isset(static::$preferences[$key])) {
$preferences = $this->preferences;
if (! is_null($transformer = static::$preferences[$key]['transformer'])) {
$preferences[$key] = call_user_func($transformer, $value);
} else {
$preferences[$key] = $value;
}
$this->preferences = $preferences;
}
return $this;
} | php | public function setPreference($key, $value)
{
if (isset(static::$preferences[$key])) {
$preferences = $this->preferences;
if (! is_null($transformer = static::$preferences[$key]['transformer'])) {
$preferences[$key] = call_user_func($transformer, $value);
} else {
$preferences[$key] = $value;
}
$this->preferences = $preferences;
}
return $this;
} | [
"public",
"function",
"setPreference",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"preferences",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"preferences",
"=",
"$",
"this",
"->",
"preferences",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"transformer",
"=",
"static",
"::",
"$",
"preferences",
"[",
"$",
"key",
"]",
"[",
"'transformer'",
"]",
")",
")",
"{",
"$",
"preferences",
"[",
"$",
"key",
"]",
"=",
"call_user_func",
"(",
"$",
"transformer",
",",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"preferences",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"$",
"this",
"->",
"preferences",
"=",
"$",
"preferences",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set the value of a preference for this user.
@param string $key
@param mixed $value
@return $this | [
"Set",
"the",
"value",
"of",
"a",
"preference",
"for",
"this",
"user",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/User/User.php#L518-L533 | train |
flarum/core | src/User/User.php | User.permissions | public function permissions()
{
$groupIds = [Group::GUEST_ID];
// If a user's account hasn't been activated, they are essentially no
// more than a guest. If they are activated, we can give them the
// standard 'member' group, as well as any other groups they've been
// assigned to.
if ($this->is_email_confirmed) {
$groupIds = array_merge($groupIds, [Group::MEMBER_ID], $this->groups->pluck('id')->all());
}
event(new PrepareUserGroups($this, $groupIds));
return Permission::whereIn('group_id', $groupIds);
} | php | public function permissions()
{
$groupIds = [Group::GUEST_ID];
// If a user's account hasn't been activated, they are essentially no
// more than a guest. If they are activated, we can give them the
// standard 'member' group, as well as any other groups they've been
// assigned to.
if ($this->is_email_confirmed) {
$groupIds = array_merge($groupIds, [Group::MEMBER_ID], $this->groups->pluck('id')->all());
}
event(new PrepareUserGroups($this, $groupIds));
return Permission::whereIn('group_id', $groupIds);
} | [
"public",
"function",
"permissions",
"(",
")",
"{",
"$",
"groupIds",
"=",
"[",
"Group",
"::",
"GUEST_ID",
"]",
";",
"// If a user's account hasn't been activated, they are essentially no",
"// more than a guest. If they are activated, we can give them the",
"// standard 'member' group, as well as any other groups they've been",
"// assigned to.",
"if",
"(",
"$",
"this",
"->",
"is_email_confirmed",
")",
"{",
"$",
"groupIds",
"=",
"array_merge",
"(",
"$",
"groupIds",
",",
"[",
"Group",
"::",
"MEMBER_ID",
"]",
",",
"$",
"this",
"->",
"groups",
"->",
"pluck",
"(",
"'id'",
")",
"->",
"all",
"(",
")",
")",
";",
"}",
"event",
"(",
"new",
"PrepareUserGroups",
"(",
"$",
"this",
",",
"$",
"groupIds",
")",
")",
";",
"return",
"Permission",
"::",
"whereIn",
"(",
"'group_id'",
",",
"$",
"groupIds",
")",
";",
"}"
] | Define the relationship with the permissions of all of the groups that
the user is in.
@return \Illuminate\Database\Eloquent\Builder | [
"Define",
"the",
"relationship",
"with",
"the",
"permissions",
"of",
"all",
"of",
"the",
"groups",
"that",
"the",
"user",
"is",
"in",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/User/User.php#L633-L648 | train |
flarum/core | src/Http/CookieFactory.php | CookieFactory.make | public function make($name, $value = null, $maxAge = null)
{
$cookie = SetCookie::create($this->getName($name), $value);
// Make sure we send both the MaxAge and Expires parameters (the former
// is not supported by all browser versions)
if ($maxAge) {
$cookie = $cookie
->withMaxAge($maxAge)
->withExpires(time() + $maxAge);
}
if ($this->domain != null) {
$cookie = $cookie->withDomain($this->domain);
}
return $cookie
->withPath($this->path)
->withSecure($this->secure)
->withHttpOnly(true);
} | php | public function make($name, $value = null, $maxAge = null)
{
$cookie = SetCookie::create($this->getName($name), $value);
// Make sure we send both the MaxAge and Expires parameters (the former
// is not supported by all browser versions)
if ($maxAge) {
$cookie = $cookie
->withMaxAge($maxAge)
->withExpires(time() + $maxAge);
}
if ($this->domain != null) {
$cookie = $cookie->withDomain($this->domain);
}
return $cookie
->withPath($this->path)
->withSecure($this->secure)
->withHttpOnly(true);
} | [
"public",
"function",
"make",
"(",
"$",
"name",
",",
"$",
"value",
"=",
"null",
",",
"$",
"maxAge",
"=",
"null",
")",
"{",
"$",
"cookie",
"=",
"SetCookie",
"::",
"create",
"(",
"$",
"this",
"->",
"getName",
"(",
"$",
"name",
")",
",",
"$",
"value",
")",
";",
"// Make sure we send both the MaxAge and Expires parameters (the former",
"// is not supported by all browser versions)",
"if",
"(",
"$",
"maxAge",
")",
"{",
"$",
"cookie",
"=",
"$",
"cookie",
"->",
"withMaxAge",
"(",
"$",
"maxAge",
")",
"->",
"withExpires",
"(",
"time",
"(",
")",
"+",
"$",
"maxAge",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"domain",
"!=",
"null",
")",
"{",
"$",
"cookie",
"=",
"$",
"cookie",
"->",
"withDomain",
"(",
"$",
"this",
"->",
"domain",
")",
";",
"}",
"return",
"$",
"cookie",
"->",
"withPath",
"(",
"$",
"this",
"->",
"path",
")",
"->",
"withSecure",
"(",
"$",
"this",
"->",
"secure",
")",
"->",
"withHttpOnly",
"(",
"true",
")",
";",
"}"
] | Make a new cookie instance.
This method returns a cookie instance for use with the Set-Cookie HTTP header.
It will be pre-configured according to Flarum's base URL and protocol.
@param string $name
@param string $value
@param int $maxAge
@return \Dflydev\FigCookies\SetCookie | [
"Make",
"a",
"new",
"cookie",
"instance",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Http/CookieFactory.php#L73-L93 | train |
flarum/core | src/User/UserRepository.php | UserRepository.getIdForUsername | public function getIdForUsername($username, User $actor = null)
{
$query = User::where('username', 'like', $username);
return $this->scopeVisibleTo($query, $actor)->value('id');
} | php | public function getIdForUsername($username, User $actor = null)
{
$query = User::where('username', 'like', $username);
return $this->scopeVisibleTo($query, $actor)->value('id');
} | [
"public",
"function",
"getIdForUsername",
"(",
"$",
"username",
",",
"User",
"$",
"actor",
"=",
"null",
")",
"{",
"$",
"query",
"=",
"User",
"::",
"where",
"(",
"'username'",
",",
"'like'",
",",
"$",
"username",
")",
";",
"return",
"$",
"this",
"->",
"scopeVisibleTo",
"(",
"$",
"query",
",",
"$",
"actor",
")",
"->",
"value",
"(",
"'id'",
")",
";",
"}"
] | Get the ID of a user with the given username.
@param string $username
@param User|null $actor
@return int|null | [
"Get",
"the",
"ID",
"of",
"a",
"user",
"with",
"the",
"given",
"username",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/User/UserRepository.php#L76-L81 | train |
flarum/core | src/User/UserRepository.php | UserRepository.getIdsForUsername | public function getIdsForUsername($string, User $actor = null)
{
$string = $this->escapeLikeString($string);
$query = User::where('username', 'like', '%'.$string.'%')
->orderByRaw('username = ? desc', [$string])
->orderByRaw('username like ? desc', [$string.'%']);
return $this->scopeVisibleTo($query, $actor)->pluck('id')->all();
} | php | public function getIdsForUsername($string, User $actor = null)
{
$string = $this->escapeLikeString($string);
$query = User::where('username', 'like', '%'.$string.'%')
->orderByRaw('username = ? desc', [$string])
->orderByRaw('username like ? desc', [$string.'%']);
return $this->scopeVisibleTo($query, $actor)->pluck('id')->all();
} | [
"public",
"function",
"getIdsForUsername",
"(",
"$",
"string",
",",
"User",
"$",
"actor",
"=",
"null",
")",
"{",
"$",
"string",
"=",
"$",
"this",
"->",
"escapeLikeString",
"(",
"$",
"string",
")",
";",
"$",
"query",
"=",
"User",
"::",
"where",
"(",
"'username'",
",",
"'like'",
",",
"'%'",
".",
"$",
"string",
".",
"'%'",
")",
"->",
"orderByRaw",
"(",
"'username = ? desc'",
",",
"[",
"$",
"string",
"]",
")",
"->",
"orderByRaw",
"(",
"'username like ? desc'",
",",
"[",
"$",
"string",
".",
"'%'",
"]",
")",
";",
"return",
"$",
"this",
"->",
"scopeVisibleTo",
"(",
"$",
"query",
",",
"$",
"actor",
")",
"->",
"pluck",
"(",
"'id'",
")",
"->",
"all",
"(",
")",
";",
"}"
] | Find users by matching a string of words against their username,
optionally making sure they are visible to a certain user.
@param string $string
@param User|null $actor
@return array | [
"Find",
"users",
"by",
"matching",
"a",
"string",
"of",
"words",
"against",
"their",
"username",
"optionally",
"making",
"sure",
"they",
"are",
"visible",
"to",
"a",
"certain",
"user",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/User/UserRepository.php#L91-L100 | train |
flarum/core | src/Group/Group.php | Group.rename | public function rename($nameSingular, $namePlural)
{
$this->name_singular = $nameSingular;
$this->name_plural = $namePlural;
$this->raise(new Renamed($this));
return $this;
} | php | public function rename($nameSingular, $namePlural)
{
$this->name_singular = $nameSingular;
$this->name_plural = $namePlural;
$this->raise(new Renamed($this));
return $this;
} | [
"public",
"function",
"rename",
"(",
"$",
"nameSingular",
",",
"$",
"namePlural",
")",
"{",
"$",
"this",
"->",
"name_singular",
"=",
"$",
"nameSingular",
";",
"$",
"this",
"->",
"name_plural",
"=",
"$",
"namePlural",
";",
"$",
"this",
"->",
"raise",
"(",
"new",
"Renamed",
"(",
"$",
"this",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Rename the group.
@param string $nameSingular
@param string $namePlural
@return $this | [
"Rename",
"the",
"group",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Group/Group.php#L100-L108 | train |