repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6 values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1 value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
yajra/laravel-datatables-buttons | src/Services/DataTable.php | DataTable.csv | public function csv()
{
$ext = '.' . strtolower($this->csvWriter);
return $this->buildExcelFile()->download($this->getFilename() . $ext, $this->csvWriter);
} | php | public function csv()
{
$ext = '.' . strtolower($this->csvWriter);
return $this->buildExcelFile()->download($this->getFilename() . $ext, $this->csvWriter);
} | [
"public",
"function",
"csv",
"(",
")",
"{",
"$",
"ext",
"=",
"'.'",
".",
"strtolower",
"(",
"$",
"this",
"->",
"csvWriter",
")",
";",
"return",
"$",
"this",
"->",
"buildExcelFile",
"(",
")",
"->",
"download",
"(",
"$",
"this",
"->",
"getFilename",
"(",
")",
".",
"$",
"ext",
",",
"$",
"this",
"->",
"csvWriter",
")",
";",
"}"
] | Export results to CSV file.
@return mixed | [
"Export",
"results",
"to",
"CSV",
"file",
"."
] | train | https://github.com/yajra/laravel-datatables-buttons/blob/291c129ab9db63e5ec5353336181e8c6a95e3e19/src/Services/DataTable.php#L486-L491 |
yajra/laravel-datatables-buttons | src/Services/DataTable.php | DataTable.pdf | public function pdf()
{
if ('snappy' == config('datatables-buttons.pdf_generator', 'snappy')) {
return $this->snappyPdf();
}
return $this->buildExcelFile()->download($this->getFilename() . '.pdf', $this->pdfWriter);
} | php | public function pdf()
{
if ('snappy' == config('datatables-buttons.pdf_generator', 'snappy')) {
return $this->snappyPdf();
}
return $this->buildExcelFile()->download($this->getFilename() . '.pdf', $this->pdfWriter);
} | [
"public",
"function",
"pdf",
"(",
")",
"{",
"if",
"(",
"'snappy'",
"==",
"config",
"(",
"'datatables-buttons.pdf_generator'",
",",
"'snappy'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"snappyPdf",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"buildExcelFile",
"(",
")",
"->",
"download",
"(",
"$",
"this",
"->",
"getFilename",
"(",
")",
".",
"'.pdf'",
",",
"$",
"this",
"->",
"pdfWriter",
")",
";",
"}"
] | Export results to PDF file.
@return mixed | [
"Export",
"results",
"to",
"PDF",
"file",
"."
] | train | https://github.com/yajra/laravel-datatables-buttons/blob/291c129ab9db63e5ec5353336181e8c6a95e3e19/src/Services/DataTable.php#L498-L505 |
yajra/laravel-datatables-buttons | src/Services/DataTable.php | DataTable.snappyPdf | public function snappyPdf()
{
/** @var \Barryvdh\Snappy\PdfWrapper $snappy */
$snappy = resolve('snappy.pdf.wrapper');
$options = config('datatables-buttons.snappy.options');
$orientation = config('datatables-buttons.snappy.orientation');
$snappy->setOptions($options)->setOrientation($orientation);
return $snappy->loadHTML($this->printPreview())->download($this->getFilename() . '.pdf');
} | php | public function snappyPdf()
{
/** @var \Barryvdh\Snappy\PdfWrapper $snappy */
$snappy = resolve('snappy.pdf.wrapper');
$options = config('datatables-buttons.snappy.options');
$orientation = config('datatables-buttons.snappy.orientation');
$snappy->setOptions($options)->setOrientation($orientation);
return $snappy->loadHTML($this->printPreview())->download($this->getFilename() . '.pdf');
} | [
"public",
"function",
"snappyPdf",
"(",
")",
"{",
"/** @var \\Barryvdh\\Snappy\\PdfWrapper $snappy */",
"$",
"snappy",
"=",
"resolve",
"(",
"'snappy.pdf.wrapper'",
")",
";",
"$",
"options",
"=",
"config",
"(",
"'datatables-buttons.snappy.options'",
")",
";",
"$",
"orientation",
"=",
"config",
"(",
"'datatables-buttons.snappy.orientation'",
")",
";",
"$",
"snappy",
"->",
"setOptions",
"(",
"$",
"options",
")",
"->",
"setOrientation",
"(",
"$",
"orientation",
")",
";",
"return",
"$",
"snappy",
"->",
"loadHTML",
"(",
"$",
"this",
"->",
"printPreview",
"(",
")",
")",
"->",
"download",
"(",
"$",
"this",
"->",
"getFilename",
"(",
")",
".",
"'.pdf'",
")",
";",
"}"
] | PDF version of the table using print preview blade template.
@return mixed | [
"PDF",
"version",
"of",
"the",
"table",
"using",
"print",
"preview",
"blade",
"template",
"."
] | train | https://github.com/yajra/laravel-datatables-buttons/blob/291c129ab9db63e5ec5353336181e8c6a95e3e19/src/Services/DataTable.php#L512-L522 |
yajra/laravel-datatables-buttons | src/Services/DataTable.php | DataTable.with | public function with($key, $value = null)
{
if (is_array($key)) {
$this->attributes = array_merge($this->attributes, $key);
} else {
$this->attributes[$key] = $value;
}
return $this;
} | php | public function with($key, $value = null)
{
if (is_array($key)) {
$this->attributes = array_merge($this->attributes, $key);
} else {
$this->attributes[$key] = $value;
}
return $this;
} | [
"public",
"function",
"with",
"(",
"$",
"key",
",",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"key",
")",
")",
"{",
"$",
"this",
"->",
"attributes",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"attributes",
",",
"$",
"key",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"attributes",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set a custom class attribute.
@param mixed $key
@param mixed|null $value
@return $this | [
"Set",
"a",
"custom",
"class",
"attribute",
"."
] | train | https://github.com/yajra/laravel-datatables-buttons/blob/291c129ab9db63e5ec5353336181e8c6a95e3e19/src/Services/DataTable.php#L557-L566 |
yajra/laravel-datatables-buttons | src/Services/DataTable.php | DataTable.applyScopes | protected function applyScopes($query)
{
foreach ($this->scopes as $scope) {
$scope->apply($query);
}
return $query;
} | php | protected function applyScopes($query)
{
foreach ($this->scopes as $scope) {
$scope->apply($query);
}
return $query;
} | [
"protected",
"function",
"applyScopes",
"(",
"$",
"query",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"scopes",
"as",
"$",
"scope",
")",
"{",
"$",
"scope",
"->",
"apply",
"(",
"$",
"query",
")",
";",
"}",
"return",
"$",
"query",
";",
"}"
] | Apply query scopes.
@param \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder $query
@return mixed | [
"Apply",
"query",
"scopes",
"."
] | train | https://github.com/yajra/laravel-datatables-buttons/blob/291c129ab9db63e5ec5353336181e8c6a95e3e19/src/Services/DataTable.php#L587-L594 |
yajra/laravel-datatables-buttons | src/Services/DataTable.php | DataTable.hasScopes | protected function hasScopes(array $scopes, $validateAll = false)
{
$filteredScopes = array_filter($this->scopes, function ($scope) use ($scopes) {
return in_array(get_class($scope), $scopes);
});
return $validateAll ? count($filteredScopes) === count($scopes) : ! empty($filteredScopes);
} | php | protected function hasScopes(array $scopes, $validateAll = false)
{
$filteredScopes = array_filter($this->scopes, function ($scope) use ($scopes) {
return in_array(get_class($scope), $scopes);
});
return $validateAll ? count($filteredScopes) === count($scopes) : ! empty($filteredScopes);
} | [
"protected",
"function",
"hasScopes",
"(",
"array",
"$",
"scopes",
",",
"$",
"validateAll",
"=",
"false",
")",
"{",
"$",
"filteredScopes",
"=",
"array_filter",
"(",
"$",
"this",
"->",
"scopes",
",",
"function",
"(",
"$",
"scope",
")",
"use",
"(",
"$",
"scopes",
")",
"{",
"return",
"in_array",
"(",
"get_class",
"(",
"$",
"scope",
")",
",",
"$",
"scopes",
")",
";",
"}",
")",
";",
"return",
"$",
"validateAll",
"?",
"count",
"(",
"$",
"filteredScopes",
")",
"===",
"count",
"(",
"$",
"scopes",
")",
":",
"!",
"empty",
"(",
"$",
"filteredScopes",
")",
";",
"}"
] | Determine if the DataTable has scopes.
@param array $scopes
@param bool $validateAll
@return bool | [
"Determine",
"if",
"the",
"DataTable",
"has",
"scopes",
"."
] | train | https://github.com/yajra/laravel-datatables-buttons/blob/291c129ab9db63e5ec5353336181e8c6a95e3e19/src/Services/DataTable.php#L603-L610 |
yajra/laravel-datatables-buttons | src/Generators/DataTablesMakeCommand.php | DataTablesMakeCommand.buildClass | protected function buildClass($name)
{
$stub = parent::buildClass($name);
return $this->replaceModelImport($stub)
->replaceModel($stub)
->replaceColumns($stub)
->replaceAction($stub)
->replaceFilename($stub);
} | php | protected function buildClass($name)
{
$stub = parent::buildClass($name);
return $this->replaceModelImport($stub)
->replaceModel($stub)
->replaceColumns($stub)
->replaceAction($stub)
->replaceFilename($stub);
} | [
"protected",
"function",
"buildClass",
"(",
"$",
"name",
")",
"{",
"$",
"stub",
"=",
"parent",
"::",
"buildClass",
"(",
"$",
"name",
")",
";",
"return",
"$",
"this",
"->",
"replaceModelImport",
"(",
"$",
"stub",
")",
"->",
"replaceModel",
"(",
"$",
"stub",
")",
"->",
"replaceColumns",
"(",
"$",
"stub",
")",
"->",
"replaceAction",
"(",
"$",
"stub",
")",
"->",
"replaceFilename",
"(",
"$",
"stub",
")",
";",
"}"
] | Build the class with the given name.
@param string $name
@return string | [
"Build",
"the",
"class",
"with",
"the",
"given",
"name",
"."
] | train | https://github.com/yajra/laravel-datatables-buttons/blob/291c129ab9db63e5ec5353336181e8c6a95e3e19/src/Generators/DataTablesMakeCommand.php#L43-L52 |
yajra/laravel-datatables-buttons | src/Generators/DataTablesMakeCommand.php | DataTablesMakeCommand.getModel | protected function getModel()
{
$name = $this->getNameInput();
$rootNamespace = $this->laravel->getNamespace();
$model = $this->option('model') || $this->option('model-namespace');
$modelNamespace = $this->option('model-namespace') ? $this->option('model-namespace') : $this->laravel['config']->get('datatables-buttons.namespace.model');
return $model
? $rootNamespace . '\\' . ($modelNamespace ? $modelNamespace . '\\' : '') . str_singular($name)
: $rootNamespace . '\\User';
} | php | protected function getModel()
{
$name = $this->getNameInput();
$rootNamespace = $this->laravel->getNamespace();
$model = $this->option('model') || $this->option('model-namespace');
$modelNamespace = $this->option('model-namespace') ? $this->option('model-namespace') : $this->laravel['config']->get('datatables-buttons.namespace.model');
return $model
? $rootNamespace . '\\' . ($modelNamespace ? $modelNamespace . '\\' : '') . str_singular($name)
: $rootNamespace . '\\User';
} | [
"protected",
"function",
"getModel",
"(",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"getNameInput",
"(",
")",
";",
"$",
"rootNamespace",
"=",
"$",
"this",
"->",
"laravel",
"->",
"getNamespace",
"(",
")",
";",
"$",
"model",
"=",
"$",
"this",
"->",
"option",
"(",
"'model'",
")",
"||",
"$",
"this",
"->",
"option",
"(",
"'model-namespace'",
")",
";",
"$",
"modelNamespace",
"=",
"$",
"this",
"->",
"option",
"(",
"'model-namespace'",
")",
"?",
"$",
"this",
"->",
"option",
"(",
"'model-namespace'",
")",
":",
"$",
"this",
"->",
"laravel",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'datatables-buttons.namespace.model'",
")",
";",
"return",
"$",
"model",
"?",
"$",
"rootNamespace",
".",
"'\\\\'",
".",
"(",
"$",
"modelNamespace",
"?",
"$",
"modelNamespace",
".",
"'\\\\'",
":",
"''",
")",
".",
"str_singular",
"(",
"$",
"name",
")",
":",
"$",
"rootNamespace",
".",
"'\\\\User'",
";",
"}"
] | Get model name to use. | [
"Get",
"model",
"name",
"to",
"use",
"."
] | train | https://github.com/yajra/laravel-datatables-buttons/blob/291c129ab9db63e5ec5353336181e8c6a95e3e19/src/Generators/DataTablesMakeCommand.php#L72-L82 |
yajra/laravel-datatables-buttons | src/Generators/DataTablesMakeCommand.php | DataTablesMakeCommand.getStub | protected function getStub()
{
$config = $this->laravel['config'];
return $config->get('datatables-buttons.stub')
? base_path() . $config->get('datatables-buttons.stub') . '/datatables.stub'
: __DIR__ . '/stubs/datatables.stub';
} | php | protected function getStub()
{
$config = $this->laravel['config'];
return $config->get('datatables-buttons.stub')
? base_path() . $config->get('datatables-buttons.stub') . '/datatables.stub'
: __DIR__ . '/stubs/datatables.stub';
} | [
"protected",
"function",
"getStub",
"(",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"laravel",
"[",
"'config'",
"]",
";",
"return",
"$",
"config",
"->",
"get",
"(",
"'datatables-buttons.stub'",
")",
"?",
"base_path",
"(",
")",
".",
"$",
"config",
"->",
"get",
"(",
"'datatables-buttons.stub'",
")",
".",
"'/datatables.stub'",
":",
"__DIR__",
".",
"'/stubs/datatables.stub'",
";",
"}"
] | Get the stub file for the generator.
@return string | [
"Get",
"the",
"stub",
"file",
"for",
"the",
"generator",
"."
] | train | https://github.com/yajra/laravel-datatables-buttons/blob/291c129ab9db63e5ec5353336181e8c6a95e3e19/src/Generators/DataTablesMakeCommand.php#L171-L178 |
yajra/laravel-datatables-buttons | src/ButtonsServiceProvider.php | ButtonsServiceProvider.publishAssets | protected function publishAssets()
{
$this->publishes([
__DIR__ . '/config/config.php' => config_path('datatables-buttons.php'),
], 'datatables-buttons');
$this->publishes([
__DIR__ . '/resources/assets/buttons.server-side.js' => public_path('vendor/datatables/buttons.server-side.js'),
], 'datatables-buttons');
$this->publishes([
__DIR__ . '/resources/views' => base_path('/resources/views/vendor/datatables'),
], 'datatables-buttons');
} | php | protected function publishAssets()
{
$this->publishes([
__DIR__ . '/config/config.php' => config_path('datatables-buttons.php'),
], 'datatables-buttons');
$this->publishes([
__DIR__ . '/resources/assets/buttons.server-side.js' => public_path('vendor/datatables/buttons.server-side.js'),
], 'datatables-buttons');
$this->publishes([
__DIR__ . '/resources/views' => base_path('/resources/views/vendor/datatables'),
], 'datatables-buttons');
} | [
"protected",
"function",
"publishAssets",
"(",
")",
"{",
"$",
"this",
"->",
"publishes",
"(",
"[",
"__DIR__",
".",
"'/config/config.php'",
"=>",
"config_path",
"(",
"'datatables-buttons.php'",
")",
",",
"]",
",",
"'datatables-buttons'",
")",
";",
"$",
"this",
"->",
"publishes",
"(",
"[",
"__DIR__",
".",
"'/resources/assets/buttons.server-side.js'",
"=>",
"public_path",
"(",
"'vendor/datatables/buttons.server-side.js'",
")",
",",
"]",
",",
"'datatables-buttons'",
")",
";",
"$",
"this",
"->",
"publishes",
"(",
"[",
"__DIR__",
".",
"'/resources/views'",
"=>",
"base_path",
"(",
"'/resources/views/vendor/datatables'",
")",
",",
"]",
",",
"'datatables-buttons'",
")",
";",
"}"
] | Publish datatables assets. | [
"Publish",
"datatables",
"assets",
"."
] | train | https://github.com/yajra/laravel-datatables-buttons/blob/291c129ab9db63e5ec5353336181e8c6a95e3e19/src/ButtonsServiceProvider.php#L29-L42 |
yajra/laravel-datatables-buttons | src/ButtonsServiceProvider.php | ButtonsServiceProvider.register | public function register()
{
$this->mergeConfigFrom(__DIR__ . '/config/config.php', 'datatables-buttons');
$this->app->register(HtmlServiceProvider::class);
$this->app->register(ExcelServiceProvider::class);
} | php | public function register()
{
$this->mergeConfigFrom(__DIR__ . '/config/config.php', 'datatables-buttons');
$this->app->register(HtmlServiceProvider::class);
$this->app->register(ExcelServiceProvider::class);
} | [
"public",
"function",
"register",
"(",
")",
"{",
"$",
"this",
"->",
"mergeConfigFrom",
"(",
"__DIR__",
".",
"'/config/config.php'",
",",
"'datatables-buttons'",
")",
";",
"$",
"this",
"->",
"app",
"->",
"register",
"(",
"HtmlServiceProvider",
"::",
"class",
")",
";",
"$",
"this",
"->",
"app",
"->",
"register",
"(",
"ExcelServiceProvider",
"::",
"class",
")",
";",
"}"
] | Register the service provider.
@return void | [
"Register",
"the",
"service",
"provider",
"."
] | train | https://github.com/yajra/laravel-datatables-buttons/blob/291c129ab9db63e5ec5353336181e8c6a95e3e19/src/ButtonsServiceProvider.php#L58-L64 |
yajra/laravel-datatables-buttons | src/Transformers/DataArrayTransformer.php | DataArrayTransformer.transform | public function transform(array $row, $columns, $type = 'printable')
{
if ($columns instanceof Collection) {
return $this->buildColumnByCollection($row, $columns, $type);
}
return array_only($row, $columns);
} | php | public function transform(array $row, $columns, $type = 'printable')
{
if ($columns instanceof Collection) {
return $this->buildColumnByCollection($row, $columns, $type);
}
return array_only($row, $columns);
} | [
"public",
"function",
"transform",
"(",
"array",
"$",
"row",
",",
"$",
"columns",
",",
"$",
"type",
"=",
"'printable'",
")",
"{",
"if",
"(",
"$",
"columns",
"instanceof",
"Collection",
")",
"{",
"return",
"$",
"this",
"->",
"buildColumnByCollection",
"(",
"$",
"row",
",",
"$",
"columns",
",",
"$",
"type",
")",
";",
"}",
"return",
"array_only",
"(",
"$",
"row",
",",
"$",
"columns",
")",
";",
"}"
] | Transform row data by columns definition.
@param array $row
@param mixed $columns
@param string $type
@return array | [
"Transform",
"row",
"data",
"by",
"columns",
"definition",
"."
] | train | https://github.com/yajra/laravel-datatables-buttons/blob/291c129ab9db63e5ec5353336181e8c6a95e3e19/src/Transformers/DataArrayTransformer.php#L17-L24 |
yajra/laravel-datatables-buttons | src/Transformers/DataArrayTransformer.php | DataArrayTransformer.buildColumnByCollection | protected function buildColumnByCollection(array $row, Collection $columns, $type = 'printable')
{
$results = [];
foreach ($columns->all() as $column) {
if ($column[$type]) {
$title = $column['title'];
$data = array_get($row, $column['data']);
if ($type == 'exportable') {
$title = $this->decodeContent($title);
$dataType = gettype($data);
$data = $this->decodeContent($data);
settype($data, $dataType);
}
$results[$title] = $data;
}
}
return $results;
} | php | protected function buildColumnByCollection(array $row, Collection $columns, $type = 'printable')
{
$results = [];
foreach ($columns->all() as $column) {
if ($column[$type]) {
$title = $column['title'];
$data = array_get($row, $column['data']);
if ($type == 'exportable') {
$title = $this->decodeContent($title);
$dataType = gettype($data);
$data = $this->decodeContent($data);
settype($data, $dataType);
}
$results[$title] = $data;
}
}
return $results;
} | [
"protected",
"function",
"buildColumnByCollection",
"(",
"array",
"$",
"row",
",",
"Collection",
"$",
"columns",
",",
"$",
"type",
"=",
"'printable'",
")",
"{",
"$",
"results",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"columns",
"->",
"all",
"(",
")",
"as",
"$",
"column",
")",
"{",
"if",
"(",
"$",
"column",
"[",
"$",
"type",
"]",
")",
"{",
"$",
"title",
"=",
"$",
"column",
"[",
"'title'",
"]",
";",
"$",
"data",
"=",
"array_get",
"(",
"$",
"row",
",",
"$",
"column",
"[",
"'data'",
"]",
")",
";",
"if",
"(",
"$",
"type",
"==",
"'exportable'",
")",
"{",
"$",
"title",
"=",
"$",
"this",
"->",
"decodeContent",
"(",
"$",
"title",
")",
";",
"$",
"dataType",
"=",
"gettype",
"(",
"$",
"data",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"decodeContent",
"(",
"$",
"data",
")",
";",
"settype",
"(",
"$",
"data",
",",
"$",
"dataType",
")",
";",
"}",
"$",
"results",
"[",
"$",
"title",
"]",
"=",
"$",
"data",
";",
"}",
"}",
"return",
"$",
"results",
";",
"}"
] | Transform row column by collection.
@param array $row
@param \Illuminate\Support\Collection $columns
@param string $type
@return array | [
"Transform",
"row",
"column",
"by",
"collection",
"."
] | train | https://github.com/yajra/laravel-datatables-buttons/blob/291c129ab9db63e5ec5353336181e8c6a95e3e19/src/Transformers/DataArrayTransformer.php#L34-L53 |
yajra/laravel-datatables-buttons | src/Transformers/DataArrayTransformer.php | DataArrayTransformer.decodeContent | protected function decodeContent($data)
{
try {
$decoded = html_entity_decode(strip_tags($data), ENT_QUOTES, 'UTF-8');
return str_replace("\xc2\xa0", ' ', $decoded);
} catch (\Exception $e) {
return $data;
}
} | php | protected function decodeContent($data)
{
try {
$decoded = html_entity_decode(strip_tags($data), ENT_QUOTES, 'UTF-8');
return str_replace("\xc2\xa0", ' ', $decoded);
} catch (\Exception $e) {
return $data;
}
} | [
"protected",
"function",
"decodeContent",
"(",
"$",
"data",
")",
"{",
"try",
"{",
"$",
"decoded",
"=",
"html_entity_decode",
"(",
"strip_tags",
"(",
"$",
"data",
")",
",",
"ENT_QUOTES",
",",
"'UTF-8'",
")",
";",
"return",
"str_replace",
"(",
"\"\\xc2\\xa0\"",
",",
"' '",
",",
"$",
"decoded",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"return",
"$",
"data",
";",
"}",
"}"
] | Decode content to a readable text value.
@param string $data
@return string | [
"Decode",
"content",
"to",
"a",
"readable",
"text",
"value",
"."
] | train | https://github.com/yajra/laravel-datatables-buttons/blob/291c129ab9db63e5ec5353336181e8c6a95e3e19/src/Transformers/DataArrayTransformer.php#L61-L70 |
GetStream/stream-laravel | src/GetStream/StreamLaravel/StreamLaravelServiceProvider.php | StreamLaravelServiceProvider.boot | public function boot()
{
if (method_exists($this, 'publishes')) {
$this->loadViewsFrom(__DIR__.'/../../views', 'stream-laravel');
$this->publishes([
__DIR__.'/../../config/config.php' => config_path('stream-laravel.php'),
__DIR__.'/../../views' => base_path('resources/views/vendor/stream-laravel'),
]);
} else {
$this->package('get-stream/stream-laravel');
}
} | php | public function boot()
{
if (method_exists($this, 'publishes')) {
$this->loadViewsFrom(__DIR__.'/../../views', 'stream-laravel');
$this->publishes([
__DIR__.'/../../config/config.php' => config_path('stream-laravel.php'),
__DIR__.'/../../views' => base_path('resources/views/vendor/stream-laravel'),
]);
} else {
$this->package('get-stream/stream-laravel');
}
} | [
"public",
"function",
"boot",
"(",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"'publishes'",
")",
")",
"{",
"$",
"this",
"->",
"loadViewsFrom",
"(",
"__DIR__",
".",
"'/../../views'",
",",
"'stream-laravel'",
")",
";",
"$",
"this",
"->",
"publishes",
"(",
"[",
"__DIR__",
".",
"'/../../config/config.php'",
"=>",
"config_path",
"(",
"'stream-laravel.php'",
")",
",",
"__DIR__",
".",
"'/../../views'",
"=>",
"base_path",
"(",
"'resources/views/vendor/stream-laravel'",
")",
",",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"package",
"(",
"'get-stream/stream-laravel'",
")",
";",
"}",
"}"
] | Bootstrap the application events.
@return void | [
"Bootstrap",
"the",
"application",
"events",
"."
] | train | https://github.com/GetStream/stream-laravel/blob/2756a00a922db49b1ce0cdd572bb6ac31cea2b0e/src/GetStream/StreamLaravel/StreamLaravelServiceProvider.php#L14-L26 |
GetStream/stream-laravel | src/GetStream/StreamLaravel/StreamLaravelServiceProvider.php | StreamLaravelServiceProvider.register | public function register()
{
if (method_exists($this, 'publishes')) {
$this->registerResources();
}
$this->app->singleton('feed_manager', function ($app) {
$manager_class = $app['config']->get('stream-laravel::feed_manager_class');
$api_key = $app['config']->get('stream-laravel::api_key');
$api_secret = $app['config']->get('stream-laravel::api_secret');
return new $manager_class($api_key, $api_secret, $this->app['config']);
});
} | php | public function register()
{
if (method_exists($this, 'publishes')) {
$this->registerResources();
}
$this->app->singleton('feed_manager', function ($app) {
$manager_class = $app['config']->get('stream-laravel::feed_manager_class');
$api_key = $app['config']->get('stream-laravel::api_key');
$api_secret = $app['config']->get('stream-laravel::api_secret');
return new $manager_class($api_key, $api_secret, $this->app['config']);
});
} | [
"public",
"function",
"register",
"(",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"'publishes'",
")",
")",
"{",
"$",
"this",
"->",
"registerResources",
"(",
")",
";",
"}",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'feed_manager'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"manager_class",
"=",
"$",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'stream-laravel::feed_manager_class'",
")",
";",
"$",
"api_key",
"=",
"$",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'stream-laravel::api_key'",
")",
";",
"$",
"api_secret",
"=",
"$",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'stream-laravel::api_secret'",
")",
";",
"return",
"new",
"$",
"manager_class",
"(",
"$",
"api_key",
",",
"$",
"api_secret",
",",
"$",
"this",
"->",
"app",
"[",
"'config'",
"]",
")",
";",
"}",
")",
";",
"}"
] | Register the service provider.
@return void | [
"Register",
"the",
"service",
"provider",
"."
] | train | https://github.com/GetStream/stream-laravel/blob/2756a00a922db49b1ce0cdd572bb6ac31cea2b0e/src/GetStream/StreamLaravel/StreamLaravelServiceProvider.php#L33-L46 |
GetStream/stream-laravel | src/GetStream/StreamLaravel/StreamLaravelServiceProvider.php | StreamLaravelServiceProvider.registerResources | protected function registerResources()
{
$userConfigFile = $this->app->configPath().'/stream-laravel.php';
$packageConfigFile = __DIR__.'/../../config/config.php';
$config = $this->app['files']->getRequire($packageConfigFile);
if (file_exists($userConfigFile)) {
$userConfig = $this->app['files']->getRequire($userConfigFile);
$config = array_replace_recursive($config, $userConfig);
}
$namespace = 'stream-laravel::';
foreach($config as $key => $value) {
$this->app['config']->set($namespace . $key , $value);
}
} | php | protected function registerResources()
{
$userConfigFile = $this->app->configPath().'/stream-laravel.php';
$packageConfigFile = __DIR__.'/../../config/config.php';
$config = $this->app['files']->getRequire($packageConfigFile);
if (file_exists($userConfigFile)) {
$userConfig = $this->app['files']->getRequire($userConfigFile);
$config = array_replace_recursive($config, $userConfig);
}
$namespace = 'stream-laravel::';
foreach($config as $key => $value) {
$this->app['config']->set($namespace . $key , $value);
}
} | [
"protected",
"function",
"registerResources",
"(",
")",
"{",
"$",
"userConfigFile",
"=",
"$",
"this",
"->",
"app",
"->",
"configPath",
"(",
")",
".",
"'/stream-laravel.php'",
";",
"$",
"packageConfigFile",
"=",
"__DIR__",
".",
"'/../../config/config.php'",
";",
"$",
"config",
"=",
"$",
"this",
"->",
"app",
"[",
"'files'",
"]",
"->",
"getRequire",
"(",
"$",
"packageConfigFile",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"userConfigFile",
")",
")",
"{",
"$",
"userConfig",
"=",
"$",
"this",
"->",
"app",
"[",
"'files'",
"]",
"->",
"getRequire",
"(",
"$",
"userConfigFile",
")",
";",
"$",
"config",
"=",
"array_replace_recursive",
"(",
"$",
"config",
",",
"$",
"userConfig",
")",
";",
"}",
"$",
"namespace",
"=",
"'stream-laravel::'",
";",
"foreach",
"(",
"$",
"config",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"app",
"[",
"'config'",
"]",
"->",
"set",
"(",
"$",
"namespace",
".",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"}"
] | Register the package resources.
@return void | [
"Register",
"the",
"package",
"resources",
"."
] | train | https://github.com/GetStream/stream-laravel/blob/2756a00a922db49b1ce0cdd572bb6ac31cea2b0e/src/GetStream/StreamLaravel/StreamLaravelServiceProvider.php#L53-L69 |
GetStream/stream-laravel | src/GetStream/StreamLaravel/StreamLumenServiceProvider.php | StreamLumenServiceProvider.boot | public function boot()
{
if (method_exists($this, 'publishes')) {
$this->loadViewsFrom(__DIR__.'/../../views', 'stream-laravel');
$this->publishes([
__DIR__.'/../../config/config.php' => app()->configure('stream-laravel.php'),
__DIR__.'/../../views' => base_path('resources/views/vendor/stream-laravel'),
]);
} else {
$this->package('get-stream/stream-laravel');
}
} | php | public function boot()
{
if (method_exists($this, 'publishes')) {
$this->loadViewsFrom(__DIR__.'/../../views', 'stream-laravel');
$this->publishes([
__DIR__.'/../../config/config.php' => app()->configure('stream-laravel.php'),
__DIR__.'/../../views' => base_path('resources/views/vendor/stream-laravel'),
]);
} else {
$this->package('get-stream/stream-laravel');
}
} | [
"public",
"function",
"boot",
"(",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"'publishes'",
")",
")",
"{",
"$",
"this",
"->",
"loadViewsFrom",
"(",
"__DIR__",
".",
"'/../../views'",
",",
"'stream-laravel'",
")",
";",
"$",
"this",
"->",
"publishes",
"(",
"[",
"__DIR__",
".",
"'/../../config/config.php'",
"=>",
"app",
"(",
")",
"->",
"configure",
"(",
"'stream-laravel.php'",
")",
",",
"__DIR__",
".",
"'/../../views'",
"=>",
"base_path",
"(",
"'resources/views/vendor/stream-laravel'",
")",
",",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"package",
"(",
"'get-stream/stream-laravel'",
")",
";",
"}",
"}"
] | Bootstrap the application events.
@return void | [
"Bootstrap",
"the",
"application",
"events",
"."
] | train | https://github.com/GetStream/stream-laravel/blob/2756a00a922db49b1ce0cdd572bb6ac31cea2b0e/src/GetStream/StreamLaravel/StreamLumenServiceProvider.php#L14-L26 |
GetStream/stream-laravel | src/GetStream/StreamLaravel/StreamLumenServiceProvider.php | StreamLumenServiceProvider.register | public function register()
{
if (method_exists($this, 'publishes')) {
$this->registerResources();
}
$this->app->singleton('feed_manager', function($app) {
$manager_class = config('stream-laravel.feed_manager_class');
$api_key = config('stream-laravel.api_key');
$api_secret = config('stream-laravel.api_secret');
return new $manager_class($api_key, $api_secret, $this->app['config']);
});
} | php | public function register()
{
if (method_exists($this, 'publishes')) {
$this->registerResources();
}
$this->app->singleton('feed_manager', function($app) {
$manager_class = config('stream-laravel.feed_manager_class');
$api_key = config('stream-laravel.api_key');
$api_secret = config('stream-laravel.api_secret');
return new $manager_class($api_key, $api_secret, $this->app['config']);
});
} | [
"public",
"function",
"register",
"(",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"'publishes'",
")",
")",
"{",
"$",
"this",
"->",
"registerResources",
"(",
")",
";",
"}",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'feed_manager'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"manager_class",
"=",
"config",
"(",
"'stream-laravel.feed_manager_class'",
")",
";",
"$",
"api_key",
"=",
"config",
"(",
"'stream-laravel.api_key'",
")",
";",
"$",
"api_secret",
"=",
"config",
"(",
"'stream-laravel.api_secret'",
")",
";",
"return",
"new",
"$",
"manager_class",
"(",
"$",
"api_key",
",",
"$",
"api_secret",
",",
"$",
"this",
"->",
"app",
"[",
"'config'",
"]",
")",
";",
"}",
")",
";",
"}"
] | Register the service provider.
@return void | [
"Register",
"the",
"service",
"provider",
"."
] | train | https://github.com/GetStream/stream-laravel/blob/2756a00a922db49b1ce0cdd572bb6ac31cea2b0e/src/GetStream/StreamLaravel/StreamLumenServiceProvider.php#L33-L46 |
GetStream/stream-laravel | src/GetStream/StreamLaravel/StreamLaravelManager.php | StreamLaravelManager.getNotificationFeed | public function getNotificationFeed($user_id)
{
$user_feed = $this->config->get("stream-laravel::notification_feed");
return $this->client->feed($user_feed, $user_id);
} | php | public function getNotificationFeed($user_id)
{
$user_feed = $this->config->get("stream-laravel::notification_feed");
return $this->client->feed($user_feed, $user_id);
} | [
"public",
"function",
"getNotificationFeed",
"(",
"$",
"user_id",
")",
"{",
"$",
"user_feed",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"\"stream-laravel::notification_feed\"",
")",
";",
"return",
"$",
"this",
"->",
"client",
"->",
"feed",
"(",
"$",
"user_feed",
",",
"$",
"user_id",
")",
";",
"}"
] | @param string $user_id
@return \GetStream\Stream\Feed | [
"@param",
"string",
"$user_id"
] | train | https://github.com/GetStream/stream-laravel/blob/2756a00a922db49b1ce0cdd572bb6ac31cea2b0e/src/GetStream/StreamLaravel/StreamLaravelManager.php#L63-L67 |
GetStream/stream-laravel | src/GetStream/StreamLaravel/StreamLaravelManager.php | StreamLaravelManager.getNewsFeeds | public function getNewsFeeds($user_id)
{
$feeds = [];
$news_feeds = $this->config->get("stream-laravel::news_feeds");
foreach ($news_feeds as $feed) {
$feeds[$feed] = $this->client->feed($feed, $user_id);
}
return $feeds;
} | php | public function getNewsFeeds($user_id)
{
$feeds = [];
$news_feeds = $this->config->get("stream-laravel::news_feeds");
foreach ($news_feeds as $feed) {
$feeds[$feed] = $this->client->feed($feed, $user_id);
}
return $feeds;
} | [
"public",
"function",
"getNewsFeeds",
"(",
"$",
"user_id",
")",
"{",
"$",
"feeds",
"=",
"[",
"]",
";",
"$",
"news_feeds",
"=",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"\"stream-laravel::news_feeds\"",
")",
";",
"foreach",
"(",
"$",
"news_feeds",
"as",
"$",
"feed",
")",
"{",
"$",
"feeds",
"[",
"$",
"feed",
"]",
"=",
"$",
"this",
"->",
"client",
"->",
"feed",
"(",
"$",
"feed",
",",
"$",
"user_id",
")",
";",
"}",
"return",
"$",
"feeds",
";",
"}"
] | @param string $user_id
@return array | [
"@param",
"string",
"$user_id"
] | train | https://github.com/GetStream/stream-laravel/blob/2756a00a922db49b1ce0cdd572bb6ac31cea2b0e/src/GetStream/StreamLaravel/StreamLaravelManager.php#L74-L82 |
GetStream/stream-laravel | src/GetStream/StreamLaravel/Eloquent/ActivityTrait.php | ActivityTrait.createActivity | public function createActivity()
{
$activity = [];
$activity['actor'] = $this->activityActor();
$activity['verb'] = $this->activityVerb();
$activity['object'] = $this->activityObject();
$activity['foreign_id'] = $this->activityForeignId();
$activity['time'] = $this->activityTime();
$to = $this->activityNotify();
if ( $to !== null )
{
$activity['to'] = [];
foreach ( $to as $feed )
{
$activity['to'][] = $feed->getId();
}
}
$extra_data = $this->activityExtraData();
if ( $extra_data !== null )
{
$activity = array_merge($activity, $extra_data);
}
return $activity;
} | php | public function createActivity()
{
$activity = [];
$activity['actor'] = $this->activityActor();
$activity['verb'] = $this->activityVerb();
$activity['object'] = $this->activityObject();
$activity['foreign_id'] = $this->activityForeignId();
$activity['time'] = $this->activityTime();
$to = $this->activityNotify();
if ( $to !== null )
{
$activity['to'] = [];
foreach ( $to as $feed )
{
$activity['to'][] = $feed->getId();
}
}
$extra_data = $this->activityExtraData();
if ( $extra_data !== null )
{
$activity = array_merge($activity, $extra_data);
}
return $activity;
} | [
"public",
"function",
"createActivity",
"(",
")",
"{",
"$",
"activity",
"=",
"[",
"]",
";",
"$",
"activity",
"[",
"'actor'",
"]",
"=",
"$",
"this",
"->",
"activityActor",
"(",
")",
";",
"$",
"activity",
"[",
"'verb'",
"]",
"=",
"$",
"this",
"->",
"activityVerb",
"(",
")",
";",
"$",
"activity",
"[",
"'object'",
"]",
"=",
"$",
"this",
"->",
"activityObject",
"(",
")",
";",
"$",
"activity",
"[",
"'foreign_id'",
"]",
"=",
"$",
"this",
"->",
"activityForeignId",
"(",
")",
";",
"$",
"activity",
"[",
"'time'",
"]",
"=",
"$",
"this",
"->",
"activityTime",
"(",
")",
";",
"$",
"to",
"=",
"$",
"this",
"->",
"activityNotify",
"(",
")",
";",
"if",
"(",
"$",
"to",
"!==",
"null",
")",
"{",
"$",
"activity",
"[",
"'to'",
"]",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"to",
"as",
"$",
"feed",
")",
"{",
"$",
"activity",
"[",
"'to'",
"]",
"[",
"]",
"=",
"$",
"feed",
"->",
"getId",
"(",
")",
";",
"}",
"}",
"$",
"extra_data",
"=",
"$",
"this",
"->",
"activityExtraData",
"(",
")",
";",
"if",
"(",
"$",
"extra_data",
"!==",
"null",
")",
"{",
"$",
"activity",
"=",
"array_merge",
"(",
"$",
"activity",
",",
"$",
"extra_data",
")",
";",
"}",
"return",
"$",
"activity",
";",
"}"
] | The activity data for this instance
@return array | [
"The",
"activity",
"data",
"for",
"this",
"instance"
] | train | https://github.com/GetStream/stream-laravel/blob/2756a00a922db49b1ce0cdd572bb6ac31cea2b0e/src/GetStream/StreamLaravel/Eloquent/ActivityTrait.php#L127-L155 |
voryx/Thruway | src/Authentication/AuthorizationManager.php | AuthorizationManager.isAuthorizedTo | public function isAuthorizedTo(Session $session, ActionMessageInterface $actionMsg)
{
// authorization
$action = $actionMsg->getActionName();
$uri = $actionMsg->getUri();
$authenticationDetails = $session->getAuthenticationDetails();
// admin can do anything - pretty important
// if this isn't here - then we can't setup any other rules
if ($authenticationDetails->hasAuthRole('admin')) {
return true;
}
if (!$this->isReady()) {
return false;
}
$rolesToCheck = ['default'];
if (count($authenticationDetails->getAuthRoles()) > 0) {
$rolesToCheck = array_merge($rolesToCheck, $authenticationDetails->getAuthRoles());
}
return $this->isAuthorizedByRolesActionAndUri($rolesToCheck, $action, $uri);
} | php | public function isAuthorizedTo(Session $session, ActionMessageInterface $actionMsg)
{
// authorization
$action = $actionMsg->getActionName();
$uri = $actionMsg->getUri();
$authenticationDetails = $session->getAuthenticationDetails();
// admin can do anything - pretty important
// if this isn't here - then we can't setup any other rules
if ($authenticationDetails->hasAuthRole('admin')) {
return true;
}
if (!$this->isReady()) {
return false;
}
$rolesToCheck = ['default'];
if (count($authenticationDetails->getAuthRoles()) > 0) {
$rolesToCheck = array_merge($rolesToCheck, $authenticationDetails->getAuthRoles());
}
return $this->isAuthorizedByRolesActionAndUri($rolesToCheck, $action, $uri);
} | [
"public",
"function",
"isAuthorizedTo",
"(",
"Session",
"$",
"session",
",",
"ActionMessageInterface",
"$",
"actionMsg",
")",
"{",
"// authorization",
"$",
"action",
"=",
"$",
"actionMsg",
"->",
"getActionName",
"(",
")",
";",
"$",
"uri",
"=",
"$",
"actionMsg",
"->",
"getUri",
"(",
")",
";",
"$",
"authenticationDetails",
"=",
"$",
"session",
"->",
"getAuthenticationDetails",
"(",
")",
";",
"// admin can do anything - pretty important",
"// if this isn't here - then we can't setup any other rules",
"if",
"(",
"$",
"authenticationDetails",
"->",
"hasAuthRole",
"(",
"'admin'",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"isReady",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"rolesToCheck",
"=",
"[",
"'default'",
"]",
";",
"if",
"(",
"count",
"(",
"$",
"authenticationDetails",
"->",
"getAuthRoles",
"(",
")",
")",
">",
"0",
")",
"{",
"$",
"rolesToCheck",
"=",
"array_merge",
"(",
"$",
"rolesToCheck",
",",
"$",
"authenticationDetails",
"->",
"getAuthRoles",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"isAuthorizedByRolesActionAndUri",
"(",
"$",
"rolesToCheck",
",",
"$",
"action",
",",
"$",
"uri",
")",
";",
"}"
] | Check to see if an action is authorized on a specific uri given the
context of the session attempting the action
actionMsg should be an instance of: register, call, subscribe, or publish messages
@param Session $session
@param ActionMessageInterface $actionMsg
@throws \Exception
@return boolean | [
"Check",
"to",
"see",
"if",
"an",
"action",
"is",
"authorized",
"on",
"a",
"specific",
"uri",
"given",
"the",
"context",
"of",
"the",
"session",
"attempting",
"the",
"action"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Authentication/AuthorizationManager.php#L117-L141 |
voryx/Thruway | src/Authentication/AuthenticationDetails.php | AuthenticationDetails.createAnonymous | static public function createAnonymous()
{
$authDetails = new AuthenticationDetails();
$authDetails->setAuthId('anonymous');
$authDetails->setAuthMethod('anonymous');
$authDetails->addAuthRole('anonymous');
return $authDetails;
} | php | static public function createAnonymous()
{
$authDetails = new AuthenticationDetails();
$authDetails->setAuthId('anonymous');
$authDetails->setAuthMethod('anonymous');
$authDetails->addAuthRole('anonymous');
return $authDetails;
} | [
"static",
"public",
"function",
"createAnonymous",
"(",
")",
"{",
"$",
"authDetails",
"=",
"new",
"AuthenticationDetails",
"(",
")",
";",
"$",
"authDetails",
"->",
"setAuthId",
"(",
"'anonymous'",
")",
";",
"$",
"authDetails",
"->",
"setAuthMethod",
"(",
"'anonymous'",
")",
";",
"$",
"authDetails",
"->",
"addAuthRole",
"(",
"'anonymous'",
")",
";",
"return",
"$",
"authDetails",
";",
"}"
] | Create anonymous
@return \Thruway\Authentication\AuthenticationDetails | [
"Create",
"anonymous"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Authentication/AuthenticationDetails.php#L129-L137 |
voryx/Thruway | src/Subscription/StateHandlerRegistration.php | StateHandlerRegistration.publishState | public function publishState(Subscription $subscription)
{
//Pause all non-state building event messages
$subscription->pauseForState();
$sessionId = $subscription->getSession()->getSessionId();
$this->clientSession->call($this->getProcedureName(),
[$subscription->getUri(), $sessionId, $subscription->getOptions(), $subscription->getSession()->getAuthenticationDetails()])->then(
function ($res) use ($subscription) {
$pubId = null;
if (isset($res[0])) {
$pubId = $res[0];
}
$subscription->unPauseForState($pubId);
},
function ($error) use ($subscription) {
Logger::error($this, "Could not call '{$this->getProcedureName()}'");
$subscription->unPauseForState();
}
);
} | php | public function publishState(Subscription $subscription)
{
//Pause all non-state building event messages
$subscription->pauseForState();
$sessionId = $subscription->getSession()->getSessionId();
$this->clientSession->call($this->getProcedureName(),
[$subscription->getUri(), $sessionId, $subscription->getOptions(), $subscription->getSession()->getAuthenticationDetails()])->then(
function ($res) use ($subscription) {
$pubId = null;
if (isset($res[0])) {
$pubId = $res[0];
}
$subscription->unPauseForState($pubId);
},
function ($error) use ($subscription) {
Logger::error($this, "Could not call '{$this->getProcedureName()}'");
$subscription->unPauseForState();
}
);
} | [
"public",
"function",
"publishState",
"(",
"Subscription",
"$",
"subscription",
")",
"{",
"//Pause all non-state building event messages",
"$",
"subscription",
"->",
"pauseForState",
"(",
")",
";",
"$",
"sessionId",
"=",
"$",
"subscription",
"->",
"getSession",
"(",
")",
"->",
"getSessionId",
"(",
")",
";",
"$",
"this",
"->",
"clientSession",
"->",
"call",
"(",
"$",
"this",
"->",
"getProcedureName",
"(",
")",
",",
"[",
"$",
"subscription",
"->",
"getUri",
"(",
")",
",",
"$",
"sessionId",
",",
"$",
"subscription",
"->",
"getOptions",
"(",
")",
",",
"$",
"subscription",
"->",
"getSession",
"(",
")",
"->",
"getAuthenticationDetails",
"(",
")",
"]",
")",
"->",
"then",
"(",
"function",
"(",
"$",
"res",
")",
"use",
"(",
"$",
"subscription",
")",
"{",
"$",
"pubId",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"res",
"[",
"0",
"]",
")",
")",
"{",
"$",
"pubId",
"=",
"$",
"res",
"[",
"0",
"]",
";",
"}",
"$",
"subscription",
"->",
"unPauseForState",
"(",
"$",
"pubId",
")",
";",
"}",
",",
"function",
"(",
"$",
"error",
")",
"use",
"(",
"$",
"subscription",
")",
"{",
"Logger",
"::",
"error",
"(",
"$",
"this",
",",
"\"Could not call '{$this->getProcedureName()}'\"",
")",
";",
"$",
"subscription",
"->",
"unPauseForState",
"(",
")",
";",
"}",
")",
";",
"}"
] | Gets and published the topics state to this subscription
@param Subscription $subscription
@return mixed | [
"Gets",
"and",
"published",
"the",
"topics",
"state",
"to",
"this",
"subscription"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Subscription/StateHandlerRegistration.php#L51-L73 |
voryx/Thruway | src/Role/Broker.php | Broker.getFeatures | public function getFeatures()
{
$features = new \stdClass();
$features->subscriber_blackwhite_listing = true;
$features->publisher_exclusion = true;
$features->subscriber_metaevents = true;
return $features;
} | php | public function getFeatures()
{
$features = new \stdClass();
$features->subscriber_blackwhite_listing = true;
$features->publisher_exclusion = true;
$features->subscriber_metaevents = true;
return $features;
} | [
"public",
"function",
"getFeatures",
"(",
")",
"{",
"$",
"features",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"features",
"->",
"subscriber_blackwhite_listing",
"=",
"true",
";",
"$",
"features",
"->",
"publisher_exclusion",
"=",
"true",
";",
"$",
"features",
"->",
"subscriber_metaevents",
"=",
"true",
";",
"return",
"$",
"features",
";",
"}"
] | Return supported features
@return \stdClass | [
"Return",
"supported",
"features"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Role/Broker.php#L120-L129 |
voryx/Thruway | src/Role/Broker.php | Broker.processSubscribe | protected function processSubscribe(Session $session, SubscribeMessage $msg)
{
// get a subscription group "hash"
/** @var MatcherInterface $matcher */
$matcher = $this->getMatcherForMatchType($msg->getMatchType());
if ($matcher === false) {
Logger::alert($this,
"no matching match type for \"" . $msg->getMatchType() . "\" for URI \"" . $msg->getUri() . "\"");
return;
}
if (!$matcher->uriIsValid($msg->getUri(), $msg->getOptions())) {
$errorMsg = ErrorMessage::createErrorMessageFromMessage($msg);
$session->sendMessage($errorMsg->setErrorURI('wamp.error.invalid_uri'));
return;
}
$matchHash = $matcher->getMatchHash($msg->getUri(), $msg->getOptions());
if (!isset($this->subscriptionGroups[$matchHash])) {
$this->subscriptionGroups[$matchHash] = new SubscriptionGroup($matcher, $msg->getUri(), $msg->getOptions());
}
/** @var SubscriptionGroup $subscriptionGroup */
$subscriptionGroup = $this->subscriptionGroups[$matchHash];
$subscription = $subscriptionGroup->processSubscribe($session, $msg);
$registry = $this->getStateHandlerRegistry();
if ($registry !== null) {
$registry->processSubscriptionAdded($subscription);
}
} | php | protected function processSubscribe(Session $session, SubscribeMessage $msg)
{
// get a subscription group "hash"
/** @var MatcherInterface $matcher */
$matcher = $this->getMatcherForMatchType($msg->getMatchType());
if ($matcher === false) {
Logger::alert($this,
"no matching match type for \"" . $msg->getMatchType() . "\" for URI \"" . $msg->getUri() . "\"");
return;
}
if (!$matcher->uriIsValid($msg->getUri(), $msg->getOptions())) {
$errorMsg = ErrorMessage::createErrorMessageFromMessage($msg);
$session->sendMessage($errorMsg->setErrorURI('wamp.error.invalid_uri'));
return;
}
$matchHash = $matcher->getMatchHash($msg->getUri(), $msg->getOptions());
if (!isset($this->subscriptionGroups[$matchHash])) {
$this->subscriptionGroups[$matchHash] = new SubscriptionGroup($matcher, $msg->getUri(), $msg->getOptions());
}
/** @var SubscriptionGroup $subscriptionGroup */
$subscriptionGroup = $this->subscriptionGroups[$matchHash];
$subscription = $subscriptionGroup->processSubscribe($session, $msg);
$registry = $this->getStateHandlerRegistry();
if ($registry !== null) {
$registry->processSubscriptionAdded($subscription);
}
} | [
"protected",
"function",
"processSubscribe",
"(",
"Session",
"$",
"session",
",",
"SubscribeMessage",
"$",
"msg",
")",
"{",
"// get a subscription group \"hash\"",
"/** @var MatcherInterface $matcher */",
"$",
"matcher",
"=",
"$",
"this",
"->",
"getMatcherForMatchType",
"(",
"$",
"msg",
"->",
"getMatchType",
"(",
")",
")",
";",
"if",
"(",
"$",
"matcher",
"===",
"false",
")",
"{",
"Logger",
"::",
"alert",
"(",
"$",
"this",
",",
"\"no matching match type for \\\"\"",
".",
"$",
"msg",
"->",
"getMatchType",
"(",
")",
".",
"\"\\\" for URI \\\"\"",
".",
"$",
"msg",
"->",
"getUri",
"(",
")",
".",
"\"\\\"\"",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"$",
"matcher",
"->",
"uriIsValid",
"(",
"$",
"msg",
"->",
"getUri",
"(",
")",
",",
"$",
"msg",
"->",
"getOptions",
"(",
")",
")",
")",
"{",
"$",
"errorMsg",
"=",
"ErrorMessage",
"::",
"createErrorMessageFromMessage",
"(",
"$",
"msg",
")",
";",
"$",
"session",
"->",
"sendMessage",
"(",
"$",
"errorMsg",
"->",
"setErrorURI",
"(",
"'wamp.error.invalid_uri'",
")",
")",
";",
"return",
";",
"}",
"$",
"matchHash",
"=",
"$",
"matcher",
"->",
"getMatchHash",
"(",
"$",
"msg",
"->",
"getUri",
"(",
")",
",",
"$",
"msg",
"->",
"getOptions",
"(",
")",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"subscriptionGroups",
"[",
"$",
"matchHash",
"]",
")",
")",
"{",
"$",
"this",
"->",
"subscriptionGroups",
"[",
"$",
"matchHash",
"]",
"=",
"new",
"SubscriptionGroup",
"(",
"$",
"matcher",
",",
"$",
"msg",
"->",
"getUri",
"(",
")",
",",
"$",
"msg",
"->",
"getOptions",
"(",
")",
")",
";",
"}",
"/** @var SubscriptionGroup $subscriptionGroup */",
"$",
"subscriptionGroup",
"=",
"$",
"this",
"->",
"subscriptionGroups",
"[",
"$",
"matchHash",
"]",
";",
"$",
"subscription",
"=",
"$",
"subscriptionGroup",
"->",
"processSubscribe",
"(",
"$",
"session",
",",
"$",
"msg",
")",
";",
"$",
"registry",
"=",
"$",
"this",
"->",
"getStateHandlerRegistry",
"(",
")",
";",
"if",
"(",
"$",
"registry",
"!==",
"null",
")",
"{",
"$",
"registry",
"->",
"processSubscriptionAdded",
"(",
"$",
"subscription",
")",
";",
"}",
"}"
] | Process subscribe message
@param \Thruway\Session $session
@param \Thruway\Message\SubscribeMessage $msg
@throws \Exception | [
"Process",
"subscribe",
"message"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Role/Broker.php#L138-L171 |
voryx/Thruway | src/Role/Broker.php | Broker.processPublish | protected function processPublish(Session $session, PublishMessage $msg)
{
if ($msg->getPublicationId() === null) {
$msg->setPublicationId(Utils::getUniqueId());
}
/** @var SubscriptionGroup $subscriptionGroup */
foreach ($this->subscriptionGroups as $subscriptionGroup) {
$subscriptionGroup->processPublish($session, $msg);
}
if ($msg->acknowledge()) {
$session->sendMessage(new PublishedMessage($msg->getRequestId(), $msg->getPublicationId()));
}
} | php | protected function processPublish(Session $session, PublishMessage $msg)
{
if ($msg->getPublicationId() === null) {
$msg->setPublicationId(Utils::getUniqueId());
}
/** @var SubscriptionGroup $subscriptionGroup */
foreach ($this->subscriptionGroups as $subscriptionGroup) {
$subscriptionGroup->processPublish($session, $msg);
}
if ($msg->acknowledge()) {
$session->sendMessage(new PublishedMessage($msg->getRequestId(), $msg->getPublicationId()));
}
} | [
"protected",
"function",
"processPublish",
"(",
"Session",
"$",
"session",
",",
"PublishMessage",
"$",
"msg",
")",
"{",
"if",
"(",
"$",
"msg",
"->",
"getPublicationId",
"(",
")",
"===",
"null",
")",
"{",
"$",
"msg",
"->",
"setPublicationId",
"(",
"Utils",
"::",
"getUniqueId",
"(",
")",
")",
";",
"}",
"/** @var SubscriptionGroup $subscriptionGroup */",
"foreach",
"(",
"$",
"this",
"->",
"subscriptionGroups",
"as",
"$",
"subscriptionGroup",
")",
"{",
"$",
"subscriptionGroup",
"->",
"processPublish",
"(",
"$",
"session",
",",
"$",
"msg",
")",
";",
"}",
"if",
"(",
"$",
"msg",
"->",
"acknowledge",
"(",
")",
")",
"{",
"$",
"session",
"->",
"sendMessage",
"(",
"new",
"PublishedMessage",
"(",
"$",
"msg",
"->",
"getRequestId",
"(",
")",
",",
"$",
"msg",
"->",
"getPublicationId",
"(",
")",
")",
")",
";",
"}",
"}"
] | Process publish message
@param \Thruway\Session $session
@param \Thruway\Message\PublishMessage $msg | [
"Process",
"publish",
"message"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Role/Broker.php#L179-L193 |
voryx/Thruway | src/Role/Broker.php | Broker.processUnsubscribe | protected function processUnsubscribe(Session $session, UnsubscribeMessage $msg)
{
$subscription = false;
// should probably be more efficient about this - maybe later
/** @var SubscriptionGroup $subscriptionGroup */
foreach ($this->subscriptionGroups as $subscriptionGroup) {
$result = $subscriptionGroup->processUnsubscribe($session, $msg);
if ($result !== false) {
$subscription = $result;
}
}
if ($subscription === false) {
$errorMsg = ErrorMessage::createErrorMessageFromMessage($msg);
$session->sendMessage($errorMsg->setErrorURI('wamp.error.no_such_subscription'));
return;
}
} | php | protected function processUnsubscribe(Session $session, UnsubscribeMessage $msg)
{
$subscription = false;
// should probably be more efficient about this - maybe later
/** @var SubscriptionGroup $subscriptionGroup */
foreach ($this->subscriptionGroups as $subscriptionGroup) {
$result = $subscriptionGroup->processUnsubscribe($session, $msg);
if ($result !== false) {
$subscription = $result;
}
}
if ($subscription === false) {
$errorMsg = ErrorMessage::createErrorMessageFromMessage($msg);
$session->sendMessage($errorMsg->setErrorURI('wamp.error.no_such_subscription'));
return;
}
} | [
"protected",
"function",
"processUnsubscribe",
"(",
"Session",
"$",
"session",
",",
"UnsubscribeMessage",
"$",
"msg",
")",
"{",
"$",
"subscription",
"=",
"false",
";",
"// should probably be more efficient about this - maybe later",
"/** @var SubscriptionGroup $subscriptionGroup */",
"foreach",
"(",
"$",
"this",
"->",
"subscriptionGroups",
"as",
"$",
"subscriptionGroup",
")",
"{",
"$",
"result",
"=",
"$",
"subscriptionGroup",
"->",
"processUnsubscribe",
"(",
"$",
"session",
",",
"$",
"msg",
")",
";",
"if",
"(",
"$",
"result",
"!==",
"false",
")",
"{",
"$",
"subscription",
"=",
"$",
"result",
";",
"}",
"}",
"if",
"(",
"$",
"subscription",
"===",
"false",
")",
"{",
"$",
"errorMsg",
"=",
"ErrorMessage",
"::",
"createErrorMessageFromMessage",
"(",
"$",
"msg",
")",
";",
"$",
"session",
"->",
"sendMessage",
"(",
"$",
"errorMsg",
"->",
"setErrorURI",
"(",
"'wamp.error.no_such_subscription'",
")",
")",
";",
"return",
";",
"}",
"}"
] | Process Unsubscribe message
@param \Thruway\Session $session
@param \Thruway\Message\UnsubscribeMessage $msg | [
"Process",
"Unsubscribe",
"message"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Role/Broker.php#L201-L220 |
voryx/Thruway | src/Call.php | Call.processYield | public function processYield(Session $session, YieldMessage $msg)
{
$keepIndex = true;
$details = new \stdClass();
$yieldOptions = $msg->getOptions();
if (is_object($yieldOptions) && isset($yieldOptions->progress) && $yieldOptions->progress) {
if ($this->isProgressive()) {
$details->progress = true;
} else {
// not sure what to do here - just going to drop progress
// if we are getting progress messages that the caller didn't ask for
return $keepIndex;
}
} else {
$this->getRegistration()->removeCall($this);
$keepIndex = false;
}
$resultMessage = new ResultMessage(
$this->getCallMessage()->getRequestId(),
$details,
$msg->getArguments(),
$msg->getArgumentsKw()
);
$this->getCallerSession()->sendMessage($resultMessage);
return $keepIndex;
} | php | public function processYield(Session $session, YieldMessage $msg)
{
$keepIndex = true;
$details = new \stdClass();
$yieldOptions = $msg->getOptions();
if (is_object($yieldOptions) && isset($yieldOptions->progress) && $yieldOptions->progress) {
if ($this->isProgressive()) {
$details->progress = true;
} else {
// not sure what to do here - just going to drop progress
// if we are getting progress messages that the caller didn't ask for
return $keepIndex;
}
} else {
$this->getRegistration()->removeCall($this);
$keepIndex = false;
}
$resultMessage = new ResultMessage(
$this->getCallMessage()->getRequestId(),
$details,
$msg->getArguments(),
$msg->getArgumentsKw()
);
$this->getCallerSession()->sendMessage($resultMessage);
return $keepIndex;
} | [
"public",
"function",
"processYield",
"(",
"Session",
"$",
"session",
",",
"YieldMessage",
"$",
"msg",
")",
"{",
"$",
"keepIndex",
"=",
"true",
";",
"$",
"details",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"yieldOptions",
"=",
"$",
"msg",
"->",
"getOptions",
"(",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"yieldOptions",
")",
"&&",
"isset",
"(",
"$",
"yieldOptions",
"->",
"progress",
")",
"&&",
"$",
"yieldOptions",
"->",
"progress",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isProgressive",
"(",
")",
")",
"{",
"$",
"details",
"->",
"progress",
"=",
"true",
";",
"}",
"else",
"{",
"// not sure what to do here - just going to drop progress",
"// if we are getting progress messages that the caller didn't ask for",
"return",
"$",
"keepIndex",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"getRegistration",
"(",
")",
"->",
"removeCall",
"(",
"$",
"this",
")",
";",
"$",
"keepIndex",
"=",
"false",
";",
"}",
"$",
"resultMessage",
"=",
"new",
"ResultMessage",
"(",
"$",
"this",
"->",
"getCallMessage",
"(",
")",
"->",
"getRequestId",
"(",
")",
",",
"$",
"details",
",",
"$",
"msg",
"->",
"getArguments",
"(",
")",
",",
"$",
"msg",
"->",
"getArgumentsKw",
"(",
")",
")",
";",
"$",
"this",
"->",
"getCallerSession",
"(",
")",
"->",
"sendMessage",
"(",
"$",
"resultMessage",
")",
";",
"return",
"$",
"keepIndex",
";",
"}"
] | Process Yield message
@param \Thruway\Session $session
@param \Thruway\Message\YieldMessage $msg
@return bool if we need to keep the call indexed | [
"Process",
"Yield",
"message"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Call.php#L121-L151 |
voryx/Thruway | src/Call.php | Call.processCancel | public function processCancel(Session $session, CancelMessage $msg)
{
if ($this->getCallerSession() !== $session) {
Logger::warning($this, 'session attempted to cancel call they did not own.');
return false;
}
if ($this->getCalleeSession() === null) {
// this call has not been sent to a callee yet (it is in a queue)
// we can just kill it and say it was canceled
$errorMsg = ErrorMessage::createErrorMessageFromMessage($msg, 'wamp.error.canceled');
$details = $errorMsg->getDetails() ?: (object)[];
$details->_thruway_removed_from_queue = true;
$session->sendMessage($errorMsg);
return true;
}
$details = (object)[];
if ($this->getCalleeSession()->getHelloMessage() instanceof HelloMessage) {
$details = $this->getCalleeSession()->getHelloMessage()->getDetails();
}
$calleeSupportsCancel = false;
if (isset($details->roles->callee->features->call_canceling)
&& is_scalar($details->roles->callee->features->call_canceling)) {
$calleeSupportsCancel = (bool)$details->roles->callee->features->call_canceling;
}
if (!$calleeSupportsCancel) {
$errorMsg = ErrorMessage::createErrorMessageFromMessage($msg);
$errorMsg->setErrorURI('wamp.error.not_supported');
$session->sendMessage($errorMsg);
return false;
}
$this->setCancelMessage($msg);
$this->canceling = true;
$calleeSession = $this->getCalleeSession();
$interruptMessage = new InterruptMessage($this->getInvocationRequestId(), (object)[]);
$calleeSession->sendMessage($interruptMessage);
$this->setInterruptMessage($interruptMessage);
if (isset($msg->getOptions()->mode) && is_scalar($msg->getOptions()->mode) && $msg->getOptions()->mode === 'killnowait') {
$errorMsg = ErrorMessage::createErrorMessageFromMessage($msg, 'wamp.error.canceled');
$session->sendMessage($errorMsg);
return true;
}
return false;
} | php | public function processCancel(Session $session, CancelMessage $msg)
{
if ($this->getCallerSession() !== $session) {
Logger::warning($this, 'session attempted to cancel call they did not own.');
return false;
}
if ($this->getCalleeSession() === null) {
// this call has not been sent to a callee yet (it is in a queue)
// we can just kill it and say it was canceled
$errorMsg = ErrorMessage::createErrorMessageFromMessage($msg, 'wamp.error.canceled');
$details = $errorMsg->getDetails() ?: (object)[];
$details->_thruway_removed_from_queue = true;
$session->sendMessage($errorMsg);
return true;
}
$details = (object)[];
if ($this->getCalleeSession()->getHelloMessage() instanceof HelloMessage) {
$details = $this->getCalleeSession()->getHelloMessage()->getDetails();
}
$calleeSupportsCancel = false;
if (isset($details->roles->callee->features->call_canceling)
&& is_scalar($details->roles->callee->features->call_canceling)) {
$calleeSupportsCancel = (bool)$details->roles->callee->features->call_canceling;
}
if (!$calleeSupportsCancel) {
$errorMsg = ErrorMessage::createErrorMessageFromMessage($msg);
$errorMsg->setErrorURI('wamp.error.not_supported');
$session->sendMessage($errorMsg);
return false;
}
$this->setCancelMessage($msg);
$this->canceling = true;
$calleeSession = $this->getCalleeSession();
$interruptMessage = new InterruptMessage($this->getInvocationRequestId(), (object)[]);
$calleeSession->sendMessage($interruptMessage);
$this->setInterruptMessage($interruptMessage);
if (isset($msg->getOptions()->mode) && is_scalar($msg->getOptions()->mode) && $msg->getOptions()->mode === 'killnowait') {
$errorMsg = ErrorMessage::createErrorMessageFromMessage($msg, 'wamp.error.canceled');
$session->sendMessage($errorMsg);
return true;
}
return false;
} | [
"public",
"function",
"processCancel",
"(",
"Session",
"$",
"session",
",",
"CancelMessage",
"$",
"msg",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getCallerSession",
"(",
")",
"!==",
"$",
"session",
")",
"{",
"Logger",
"::",
"warning",
"(",
"$",
"this",
",",
"'session attempted to cancel call they did not own.'",
")",
";",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"getCalleeSession",
"(",
")",
"===",
"null",
")",
"{",
"// this call has not been sent to a callee yet (it is in a queue)",
"// we can just kill it and say it was canceled",
"$",
"errorMsg",
"=",
"ErrorMessage",
"::",
"createErrorMessageFromMessage",
"(",
"$",
"msg",
",",
"'wamp.error.canceled'",
")",
";",
"$",
"details",
"=",
"$",
"errorMsg",
"->",
"getDetails",
"(",
")",
"?",
":",
"(",
"object",
")",
"[",
"]",
";",
"$",
"details",
"->",
"_thruway_removed_from_queue",
"=",
"true",
";",
"$",
"session",
"->",
"sendMessage",
"(",
"$",
"errorMsg",
")",
";",
"return",
"true",
";",
"}",
"$",
"details",
"=",
"(",
"object",
")",
"[",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"getCalleeSession",
"(",
")",
"->",
"getHelloMessage",
"(",
")",
"instanceof",
"HelloMessage",
")",
"{",
"$",
"details",
"=",
"$",
"this",
"->",
"getCalleeSession",
"(",
")",
"->",
"getHelloMessage",
"(",
")",
"->",
"getDetails",
"(",
")",
";",
"}",
"$",
"calleeSupportsCancel",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"details",
"->",
"roles",
"->",
"callee",
"->",
"features",
"->",
"call_canceling",
")",
"&&",
"is_scalar",
"(",
"$",
"details",
"->",
"roles",
"->",
"callee",
"->",
"features",
"->",
"call_canceling",
")",
")",
"{",
"$",
"calleeSupportsCancel",
"=",
"(",
"bool",
")",
"$",
"details",
"->",
"roles",
"->",
"callee",
"->",
"features",
"->",
"call_canceling",
";",
"}",
"if",
"(",
"!",
"$",
"calleeSupportsCancel",
")",
"{",
"$",
"errorMsg",
"=",
"ErrorMessage",
"::",
"createErrorMessageFromMessage",
"(",
"$",
"msg",
")",
";",
"$",
"errorMsg",
"->",
"setErrorURI",
"(",
"'wamp.error.not_supported'",
")",
";",
"$",
"session",
"->",
"sendMessage",
"(",
"$",
"errorMsg",
")",
";",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"setCancelMessage",
"(",
"$",
"msg",
")",
";",
"$",
"this",
"->",
"canceling",
"=",
"true",
";",
"$",
"calleeSession",
"=",
"$",
"this",
"->",
"getCalleeSession",
"(",
")",
";",
"$",
"interruptMessage",
"=",
"new",
"InterruptMessage",
"(",
"$",
"this",
"->",
"getInvocationRequestId",
"(",
")",
",",
"(",
"object",
")",
"[",
"]",
")",
";",
"$",
"calleeSession",
"->",
"sendMessage",
"(",
"$",
"interruptMessage",
")",
";",
"$",
"this",
"->",
"setInterruptMessage",
"(",
"$",
"interruptMessage",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"msg",
"->",
"getOptions",
"(",
")",
"->",
"mode",
")",
"&&",
"is_scalar",
"(",
"$",
"msg",
"->",
"getOptions",
"(",
")",
"->",
"mode",
")",
"&&",
"$",
"msg",
"->",
"getOptions",
"(",
")",
"->",
"mode",
"===",
"'killnowait'",
")",
"{",
"$",
"errorMsg",
"=",
"ErrorMessage",
"::",
"createErrorMessageFromMessage",
"(",
"$",
"msg",
",",
"'wamp.error.canceled'",
")",
";",
"$",
"session",
"->",
"sendMessage",
"(",
"$",
"errorMsg",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | processCancel processes cancel message from the caller.
Return true if the Call should be removed from active calls
@param Session $session
@param CancelMessage $msg
@return bool | [
"processCancel",
"processes",
"cancel",
"message",
"from",
"the",
"caller",
".",
"Return",
"true",
"if",
"the",
"Call",
"should",
"be",
"removed",
"from",
"active",
"calls"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Call.php#L161-L213 |
voryx/Thruway | src/Call.php | Call.getInvocationMessage | public function getInvocationMessage()
{
if ($this->invocationMessage === null) {
// try to create one
if ($this->registration === null) {
throw new \Exception('You must set the registration prior to calling getInvocationMessage');
}
if ($this->callMessage === null) {
throw new \Exception('You must set the CallMessage prior to calling getInvocationMessage');
}
$invocationMessage = InvocationMessage::createMessageFrom($this->getCallMessage(), $this->getRegistration());
$invocationMessage->setRequestId($this->getInvocationRequestId());
$details = [];
if ($this->getRegistration()->getDiscloseCaller() === true && $this->getCallerSession()->getAuthenticationDetails()) {
$authenticationDetails = $this->getCallerSession()->getAuthenticationDetails();
$details = [
'caller' => $this->getCallerSession()->getSessionId(),
'authid' => $authenticationDetails->getAuthId(),
'authrole' => $authenticationDetails->getAuthRole(),
'authroles' => $authenticationDetails->getAuthRoles(),
'authmethod' => $authenticationDetails->getAuthMethod(),
];
if ($authenticationDetails->getAuthExtra() !== null) {
$details['_thruway_authextra'] = $authenticationDetails->getAuthExtra();
}
}
// TODO: check to see if callee supports progressive call
$callOptions = $this->getCallMessage()->getOptions();
$isProgressive = false;
if (is_object($callOptions) && isset($callOptions->receive_progress) && $callOptions->receive_progress) {
$details = array_merge($details, ['receive_progress' => true]);
$isProgressive = true;
}
// if nothing was added to details - change ot stdClass so it will serialize correctly
if (count($details) === 0) {
$details = new \stdClass();
}
$invocationMessage->setDetails($details);
$this->setIsProgressive($isProgressive);
$this->setInvocationMessage($invocationMessage);
}
return $this->invocationMessage;
} | php | public function getInvocationMessage()
{
if ($this->invocationMessage === null) {
// try to create one
if ($this->registration === null) {
throw new \Exception('You must set the registration prior to calling getInvocationMessage');
}
if ($this->callMessage === null) {
throw new \Exception('You must set the CallMessage prior to calling getInvocationMessage');
}
$invocationMessage = InvocationMessage::createMessageFrom($this->getCallMessage(), $this->getRegistration());
$invocationMessage->setRequestId($this->getInvocationRequestId());
$details = [];
if ($this->getRegistration()->getDiscloseCaller() === true && $this->getCallerSession()->getAuthenticationDetails()) {
$authenticationDetails = $this->getCallerSession()->getAuthenticationDetails();
$details = [
'caller' => $this->getCallerSession()->getSessionId(),
'authid' => $authenticationDetails->getAuthId(),
'authrole' => $authenticationDetails->getAuthRole(),
'authroles' => $authenticationDetails->getAuthRoles(),
'authmethod' => $authenticationDetails->getAuthMethod(),
];
if ($authenticationDetails->getAuthExtra() !== null) {
$details['_thruway_authextra'] = $authenticationDetails->getAuthExtra();
}
}
// TODO: check to see if callee supports progressive call
$callOptions = $this->getCallMessage()->getOptions();
$isProgressive = false;
if (is_object($callOptions) && isset($callOptions->receive_progress) && $callOptions->receive_progress) {
$details = array_merge($details, ['receive_progress' => true]);
$isProgressive = true;
}
// if nothing was added to details - change ot stdClass so it will serialize correctly
if (count($details) === 0) {
$details = new \stdClass();
}
$invocationMessage->setDetails($details);
$this->setIsProgressive($isProgressive);
$this->setInvocationMessage($invocationMessage);
}
return $this->invocationMessage;
} | [
"public",
"function",
"getInvocationMessage",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"invocationMessage",
"===",
"null",
")",
"{",
"// try to create one",
"if",
"(",
"$",
"this",
"->",
"registration",
"===",
"null",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'You must set the registration prior to calling getInvocationMessage'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"callMessage",
"===",
"null",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'You must set the CallMessage prior to calling getInvocationMessage'",
")",
";",
"}",
"$",
"invocationMessage",
"=",
"InvocationMessage",
"::",
"createMessageFrom",
"(",
"$",
"this",
"->",
"getCallMessage",
"(",
")",
",",
"$",
"this",
"->",
"getRegistration",
"(",
")",
")",
";",
"$",
"invocationMessage",
"->",
"setRequestId",
"(",
"$",
"this",
"->",
"getInvocationRequestId",
"(",
")",
")",
";",
"$",
"details",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"getRegistration",
"(",
")",
"->",
"getDiscloseCaller",
"(",
")",
"===",
"true",
"&&",
"$",
"this",
"->",
"getCallerSession",
"(",
")",
"->",
"getAuthenticationDetails",
"(",
")",
")",
"{",
"$",
"authenticationDetails",
"=",
"$",
"this",
"->",
"getCallerSession",
"(",
")",
"->",
"getAuthenticationDetails",
"(",
")",
";",
"$",
"details",
"=",
"[",
"'caller'",
"=>",
"$",
"this",
"->",
"getCallerSession",
"(",
")",
"->",
"getSessionId",
"(",
")",
",",
"'authid'",
"=>",
"$",
"authenticationDetails",
"->",
"getAuthId",
"(",
")",
",",
"'authrole'",
"=>",
"$",
"authenticationDetails",
"->",
"getAuthRole",
"(",
")",
",",
"'authroles'",
"=>",
"$",
"authenticationDetails",
"->",
"getAuthRoles",
"(",
")",
",",
"'authmethod'",
"=>",
"$",
"authenticationDetails",
"->",
"getAuthMethod",
"(",
")",
",",
"]",
";",
"if",
"(",
"$",
"authenticationDetails",
"->",
"getAuthExtra",
"(",
")",
"!==",
"null",
")",
"{",
"$",
"details",
"[",
"'_thruway_authextra'",
"]",
"=",
"$",
"authenticationDetails",
"->",
"getAuthExtra",
"(",
")",
";",
"}",
"}",
"// TODO: check to see if callee supports progressive call",
"$",
"callOptions",
"=",
"$",
"this",
"->",
"getCallMessage",
"(",
")",
"->",
"getOptions",
"(",
")",
";",
"$",
"isProgressive",
"=",
"false",
";",
"if",
"(",
"is_object",
"(",
"$",
"callOptions",
")",
"&&",
"isset",
"(",
"$",
"callOptions",
"->",
"receive_progress",
")",
"&&",
"$",
"callOptions",
"->",
"receive_progress",
")",
"{",
"$",
"details",
"=",
"array_merge",
"(",
"$",
"details",
",",
"[",
"'receive_progress'",
"=>",
"true",
"]",
")",
";",
"$",
"isProgressive",
"=",
"true",
";",
"}",
"// if nothing was added to details - change ot stdClass so it will serialize correctly",
"if",
"(",
"count",
"(",
"$",
"details",
")",
"===",
"0",
")",
"{",
"$",
"details",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"}",
"$",
"invocationMessage",
"->",
"setDetails",
"(",
"$",
"details",
")",
";",
"$",
"this",
"->",
"setIsProgressive",
"(",
"$",
"isProgressive",
")",
";",
"$",
"this",
"->",
"setInvocationMessage",
"(",
"$",
"invocationMessage",
")",
";",
"}",
"return",
"$",
"this",
"->",
"invocationMessage",
";",
"}"
] | Get InvocationMessage
@throws \Exception
@return \Thruway\Message\InvocationMessage | [
"Get",
"InvocationMessage"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Call.php#L281-L334 |
voryx/Thruway | src/Procedure.php | Procedure.processRegister | public function processRegister(Session $session, RegisterMessage $msg)
{
$registration = Registration::createRegistrationFromRegisterMessage($session, $msg);
if (count($this->registrations) > 0) {
// we already have something registered
if ($this->getAllowMultipleRegistrations()) {
return $this->addRegistration($registration, $msg);
} else {
// we are not allowed multiple registrations, but we may want
// to replace an orphaned session
$errorMsg = ErrorMessage::createErrorMessageFromMessage($msg, 'wamp.error.procedure_already_exists');
$options = $msg->getOptions();
// get the existing registration
/** @var Registration $oldRegistration */
$oldRegistration = $this->registrations[0];
if (isset($options->replace_orphaned_session) && ($options->replace_orphaned_session === 'yes' || $options->replace_orphaned_session === true)) {
try {
$oldRegistration->getSession()->ping(5)
->then(function ($res) use ($session, $errorMsg) {
// the ping came back - send procedure_already_exists
$session->sendMessage($errorMsg);
}, function ($r) use ($oldRegistration, $session, $registration, $msg) {
// bring down the exiting session because the
// ping timed out
$deadSession = $oldRegistration->getSession();
// this should do all the cleanup needed and remove the
// registration from this procedure also
$deadSession->shutdown();
// complete this registration now
return $this->addRegistration($registration, $msg);
});
} catch (\Exception $e) {
$session->sendMessage($errorMsg);
}
} else {
$session->sendMessage($errorMsg);
}
}
} else {
// this is the first registration
// setup the procedure to match the options
$this->setDiscloseCaller($registration->getDiscloseCaller());
$this->setAllowMultipleRegistrations($registration->getAllowMultipleRegistrations());
$this->setInvokeType($registration->getInvokeType());
return $this->addRegistration($registration, $msg);
}
} | php | public function processRegister(Session $session, RegisterMessage $msg)
{
$registration = Registration::createRegistrationFromRegisterMessage($session, $msg);
if (count($this->registrations) > 0) {
// we already have something registered
if ($this->getAllowMultipleRegistrations()) {
return $this->addRegistration($registration, $msg);
} else {
// we are not allowed multiple registrations, but we may want
// to replace an orphaned session
$errorMsg = ErrorMessage::createErrorMessageFromMessage($msg, 'wamp.error.procedure_already_exists');
$options = $msg->getOptions();
// get the existing registration
/** @var Registration $oldRegistration */
$oldRegistration = $this->registrations[0];
if (isset($options->replace_orphaned_session) && ($options->replace_orphaned_session === 'yes' || $options->replace_orphaned_session === true)) {
try {
$oldRegistration->getSession()->ping(5)
->then(function ($res) use ($session, $errorMsg) {
// the ping came back - send procedure_already_exists
$session->sendMessage($errorMsg);
}, function ($r) use ($oldRegistration, $session, $registration, $msg) {
// bring down the exiting session because the
// ping timed out
$deadSession = $oldRegistration->getSession();
// this should do all the cleanup needed and remove the
// registration from this procedure also
$deadSession->shutdown();
// complete this registration now
return $this->addRegistration($registration, $msg);
});
} catch (\Exception $e) {
$session->sendMessage($errorMsg);
}
} else {
$session->sendMessage($errorMsg);
}
}
} else {
// this is the first registration
// setup the procedure to match the options
$this->setDiscloseCaller($registration->getDiscloseCaller());
$this->setAllowMultipleRegistrations($registration->getAllowMultipleRegistrations());
$this->setInvokeType($registration->getInvokeType());
return $this->addRegistration($registration, $msg);
}
} | [
"public",
"function",
"processRegister",
"(",
"Session",
"$",
"session",
",",
"RegisterMessage",
"$",
"msg",
")",
"{",
"$",
"registration",
"=",
"Registration",
"::",
"createRegistrationFromRegisterMessage",
"(",
"$",
"session",
",",
"$",
"msg",
")",
";",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"registrations",
")",
">",
"0",
")",
"{",
"// we already have something registered",
"if",
"(",
"$",
"this",
"->",
"getAllowMultipleRegistrations",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"addRegistration",
"(",
"$",
"registration",
",",
"$",
"msg",
")",
";",
"}",
"else",
"{",
"// we are not allowed multiple registrations, but we may want",
"// to replace an orphaned session",
"$",
"errorMsg",
"=",
"ErrorMessage",
"::",
"createErrorMessageFromMessage",
"(",
"$",
"msg",
",",
"'wamp.error.procedure_already_exists'",
")",
";",
"$",
"options",
"=",
"$",
"msg",
"->",
"getOptions",
"(",
")",
";",
"// get the existing registration",
"/** @var Registration $oldRegistration */",
"$",
"oldRegistration",
"=",
"$",
"this",
"->",
"registrations",
"[",
"0",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"->",
"replace_orphaned_session",
")",
"&&",
"(",
"$",
"options",
"->",
"replace_orphaned_session",
"===",
"'yes'",
"||",
"$",
"options",
"->",
"replace_orphaned_session",
"===",
"true",
")",
")",
"{",
"try",
"{",
"$",
"oldRegistration",
"->",
"getSession",
"(",
")",
"->",
"ping",
"(",
"5",
")",
"->",
"then",
"(",
"function",
"(",
"$",
"res",
")",
"use",
"(",
"$",
"session",
",",
"$",
"errorMsg",
")",
"{",
"// the ping came back - send procedure_already_exists",
"$",
"session",
"->",
"sendMessage",
"(",
"$",
"errorMsg",
")",
";",
"}",
",",
"function",
"(",
"$",
"r",
")",
"use",
"(",
"$",
"oldRegistration",
",",
"$",
"session",
",",
"$",
"registration",
",",
"$",
"msg",
")",
"{",
"// bring down the exiting session because the",
"// ping timed out",
"$",
"deadSession",
"=",
"$",
"oldRegistration",
"->",
"getSession",
"(",
")",
";",
"// this should do all the cleanup needed and remove the",
"// registration from this procedure also",
"$",
"deadSession",
"->",
"shutdown",
"(",
")",
";",
"// complete this registration now",
"return",
"$",
"this",
"->",
"addRegistration",
"(",
"$",
"registration",
",",
"$",
"msg",
")",
";",
"}",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"session",
"->",
"sendMessage",
"(",
"$",
"errorMsg",
")",
";",
"}",
"}",
"else",
"{",
"$",
"session",
"->",
"sendMessage",
"(",
"$",
"errorMsg",
")",
";",
"}",
"}",
"}",
"else",
"{",
"// this is the first registration",
"// setup the procedure to match the options",
"$",
"this",
"->",
"setDiscloseCaller",
"(",
"$",
"registration",
"->",
"getDiscloseCaller",
"(",
")",
")",
";",
"$",
"this",
"->",
"setAllowMultipleRegistrations",
"(",
"$",
"registration",
"->",
"getAllowMultipleRegistrations",
"(",
")",
")",
";",
"$",
"this",
"->",
"setInvokeType",
"(",
"$",
"registration",
"->",
"getInvokeType",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"addRegistration",
"(",
"$",
"registration",
",",
"$",
"msg",
")",
";",
"}",
"}"
] | Process register
@param Session $session
@param \Thruway\Message\RegisterMessage $msg
@return bool
@throws \Exception | [
"Process",
"register"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Procedure.php#L76-L127 |
voryx/Thruway | src/Procedure.php | Procedure.addRegistration | private function addRegistration(Registration $registration, RegisterMessage $msg)
{
try {
// make sure the uri is exactly the same
if ($registration->getProcedureName() !== $this->getProcedureName()) {
throw new \Exception('Attempt to add registration to procedure with different procedure name.');
}
// make sure options match
if (strcasecmp($registration->getInvokeType(), $this->getInvokeType()) !== 0) {
throw new \Exception('Registration and procedure must agree on invocation type');
}
if ($registration->getDiscloseCaller() !== $this->getDiscloseCaller()) {
throw new \Exception('Registration and procedure must agree on disclose caller');
}
$this->registrations[] = $registration;
$registration->getSession()->sendMessage(new RegisteredMessage($msg->getRequestId(), $registration->getId()));
// now that we have added a new registration, process the queue if we are using it
if ($this->getAllowMultipleRegistrations()) {
$this->processQueue();
}
return true;
} catch (\Exception $e) {
$registration->getSession()->sendMessage(ErrorMessage::createErrorMessageFromMessage($msg));
return false;
}
} | php | private function addRegistration(Registration $registration, RegisterMessage $msg)
{
try {
// make sure the uri is exactly the same
if ($registration->getProcedureName() !== $this->getProcedureName()) {
throw new \Exception('Attempt to add registration to procedure with different procedure name.');
}
// make sure options match
if (strcasecmp($registration->getInvokeType(), $this->getInvokeType()) !== 0) {
throw new \Exception('Registration and procedure must agree on invocation type');
}
if ($registration->getDiscloseCaller() !== $this->getDiscloseCaller()) {
throw new \Exception('Registration and procedure must agree on disclose caller');
}
$this->registrations[] = $registration;
$registration->getSession()->sendMessage(new RegisteredMessage($msg->getRequestId(), $registration->getId()));
// now that we have added a new registration, process the queue if we are using it
if ($this->getAllowMultipleRegistrations()) {
$this->processQueue();
}
return true;
} catch (\Exception $e) {
$registration->getSession()->sendMessage(ErrorMessage::createErrorMessageFromMessage($msg));
return false;
}
} | [
"private",
"function",
"addRegistration",
"(",
"Registration",
"$",
"registration",
",",
"RegisterMessage",
"$",
"msg",
")",
"{",
"try",
"{",
"// make sure the uri is exactly the same",
"if",
"(",
"$",
"registration",
"->",
"getProcedureName",
"(",
")",
"!==",
"$",
"this",
"->",
"getProcedureName",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Attempt to add registration to procedure with different procedure name.'",
")",
";",
"}",
"// make sure options match",
"if",
"(",
"strcasecmp",
"(",
"$",
"registration",
"->",
"getInvokeType",
"(",
")",
",",
"$",
"this",
"->",
"getInvokeType",
"(",
")",
")",
"!==",
"0",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Registration and procedure must agree on invocation type'",
")",
";",
"}",
"if",
"(",
"$",
"registration",
"->",
"getDiscloseCaller",
"(",
")",
"!==",
"$",
"this",
"->",
"getDiscloseCaller",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Registration and procedure must agree on disclose caller'",
")",
";",
"}",
"$",
"this",
"->",
"registrations",
"[",
"]",
"=",
"$",
"registration",
";",
"$",
"registration",
"->",
"getSession",
"(",
")",
"->",
"sendMessage",
"(",
"new",
"RegisteredMessage",
"(",
"$",
"msg",
"->",
"getRequestId",
"(",
")",
",",
"$",
"registration",
"->",
"getId",
"(",
")",
")",
")",
";",
"// now that we have added a new registration, process the queue if we are using it",
"if",
"(",
"$",
"this",
"->",
"getAllowMultipleRegistrations",
"(",
")",
")",
"{",
"$",
"this",
"->",
"processQueue",
"(",
")",
";",
"}",
"return",
"true",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"registration",
"->",
"getSession",
"(",
")",
"->",
"sendMessage",
"(",
"ErrorMessage",
"::",
"createErrorMessageFromMessage",
"(",
"$",
"msg",
")",
")",
";",
"return",
"false",
";",
"}",
"}"
] | Add registration
@param \Thruway\Registration $registration
@return bool
@throws \Exception | [
"Add",
"registration"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Procedure.php#L136-L167 |
voryx/Thruway | src/Procedure.php | Procedure.getRegistrationById | public function getRegistrationById($registrationId)
{
/** @var Registration $registration */
foreach ($this->registrations as $registration) {
if ($registration->getId() === $registrationId) {
return $registration;
}
}
return false;
} | php | public function getRegistrationById($registrationId)
{
/** @var Registration $registration */
foreach ($this->registrations as $registration) {
if ($registration->getId() === $registrationId) {
return $registration;
}
}
return false;
} | [
"public",
"function",
"getRegistrationById",
"(",
"$",
"registrationId",
")",
"{",
"/** @var Registration $registration */",
"foreach",
"(",
"$",
"this",
"->",
"registrations",
"as",
"$",
"registration",
")",
"{",
"if",
"(",
"$",
"registration",
"->",
"getId",
"(",
")",
"===",
"$",
"registrationId",
")",
"{",
"return",
"$",
"registration",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Get registration by ID
@param $registrationId
@return bool|Registration | [
"Get",
"registration",
"by",
"ID"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Procedure.php#L175-L185 |
voryx/Thruway | src/Procedure.php | Procedure.processUnregister | public function processUnregister(Session $session, UnregisterMessage $msg)
{
for ($i = 0; $i < count($this->registrations); $i++) {
/** @var Registration $registration */
$registration = $this->registrations[$i];
if ($registration->getId() == $msg->getRegistrationId()) {
// make sure the session is the correct session
if ($registration->getSession() !== $session) {
$session->sendMessage(ErrorMessage::createErrorMessageFromMessage($msg, 'wamp.error.no_such_registration'));
//$this->manager->warning('Tried to unregister a procedure that belongs to a different session.');
return false;
}
array_splice($this->registrations, $i, 1);
// TODO: need to handle any calls that are hanging around
$session->sendMessage(UnregisteredMessage::createFromUnregisterMessage($msg));
return true;
}
}
$session->sendMessage(ErrorMessage::createErrorMessageFromMessage($msg, 'wamp.error.no_such_registration'));
return false;
} | php | public function processUnregister(Session $session, UnregisterMessage $msg)
{
for ($i = 0; $i < count($this->registrations); $i++) {
/** @var Registration $registration */
$registration = $this->registrations[$i];
if ($registration->getId() == $msg->getRegistrationId()) {
// make sure the session is the correct session
if ($registration->getSession() !== $session) {
$session->sendMessage(ErrorMessage::createErrorMessageFromMessage($msg, 'wamp.error.no_such_registration'));
//$this->manager->warning('Tried to unregister a procedure that belongs to a different session.');
return false;
}
array_splice($this->registrations, $i, 1);
// TODO: need to handle any calls that are hanging around
$session->sendMessage(UnregisteredMessage::createFromUnregisterMessage($msg));
return true;
}
}
$session->sendMessage(ErrorMessage::createErrorMessageFromMessage($msg, 'wamp.error.no_such_registration'));
return false;
} | [
"public",
"function",
"processUnregister",
"(",
"Session",
"$",
"session",
",",
"UnregisterMessage",
"$",
"msg",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"this",
"->",
"registrations",
")",
";",
"$",
"i",
"++",
")",
"{",
"/** @var Registration $registration */",
"$",
"registration",
"=",
"$",
"this",
"->",
"registrations",
"[",
"$",
"i",
"]",
";",
"if",
"(",
"$",
"registration",
"->",
"getId",
"(",
")",
"==",
"$",
"msg",
"->",
"getRegistrationId",
"(",
")",
")",
"{",
"// make sure the session is the correct session",
"if",
"(",
"$",
"registration",
"->",
"getSession",
"(",
")",
"!==",
"$",
"session",
")",
"{",
"$",
"session",
"->",
"sendMessage",
"(",
"ErrorMessage",
"::",
"createErrorMessageFromMessage",
"(",
"$",
"msg",
",",
"'wamp.error.no_such_registration'",
")",
")",
";",
"//$this->manager->warning('Tried to unregister a procedure that belongs to a different session.');",
"return",
"false",
";",
"}",
"array_splice",
"(",
"$",
"this",
"->",
"registrations",
",",
"$",
"i",
",",
"1",
")",
";",
"// TODO: need to handle any calls that are hanging around",
"$",
"session",
"->",
"sendMessage",
"(",
"UnregisteredMessage",
"::",
"createFromUnregisterMessage",
"(",
"$",
"msg",
")",
")",
";",
"return",
"true",
";",
"}",
"}",
"$",
"session",
"->",
"sendMessage",
"(",
"ErrorMessage",
"::",
"createErrorMessageFromMessage",
"(",
"$",
"msg",
",",
"'wamp.error.no_such_registration'",
")",
")",
";",
"return",
"false",
";",
"}"
] | process unregister
@param \Thruway\Session $session
@param \Thruway\Message\UnregisterMessage $msg
@return bool | [
"process",
"unregister"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Procedure.php#L194-L220 |
voryx/Thruway | src/Procedure.php | Procedure.processCall | public function processCall(Session $session, Call $call)
{
// find a registration to call
if (count($this->registrations) === 0) {
$session->sendMessage(ErrorMessage::createErrorMessageFromMessage($call->getCallMessage(), 'wamp.error.no_such_procedure'));
return false;
}
// just send it to the first one if we don't allow multiple registrations
if (!$this->getAllowMultipleRegistrations()) {
$this->registrations[0]->processCall($call);
} else {
$this->callQueue->enqueue($call);
$this->processQueue();
}
return true;
} | php | public function processCall(Session $session, Call $call)
{
// find a registration to call
if (count($this->registrations) === 0) {
$session->sendMessage(ErrorMessage::createErrorMessageFromMessage($call->getCallMessage(), 'wamp.error.no_such_procedure'));
return false;
}
// just send it to the first one if we don't allow multiple registrations
if (!$this->getAllowMultipleRegistrations()) {
$this->registrations[0]->processCall($call);
} else {
$this->callQueue->enqueue($call);
$this->processQueue();
}
return true;
} | [
"public",
"function",
"processCall",
"(",
"Session",
"$",
"session",
",",
"Call",
"$",
"call",
")",
"{",
"// find a registration to call",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"registrations",
")",
"===",
"0",
")",
"{",
"$",
"session",
"->",
"sendMessage",
"(",
"ErrorMessage",
"::",
"createErrorMessageFromMessage",
"(",
"$",
"call",
"->",
"getCallMessage",
"(",
")",
",",
"'wamp.error.no_such_procedure'",
")",
")",
";",
"return",
"false",
";",
"}",
"// just send it to the first one if we don't allow multiple registrations",
"if",
"(",
"!",
"$",
"this",
"->",
"getAllowMultipleRegistrations",
"(",
")",
")",
"{",
"$",
"this",
"->",
"registrations",
"[",
"0",
"]",
"->",
"processCall",
"(",
"$",
"call",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"callQueue",
"->",
"enqueue",
"(",
"$",
"call",
")",
";",
"$",
"this",
"->",
"processQueue",
"(",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Process call
@param \Thruway\Session $session
@param Call $call
@throws \Exception
@return bool | Call | [
"Process",
"call"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Procedure.php#L230-L247 |
voryx/Thruway | src/Procedure.php | Procedure.processQueue | public function processQueue()
{
if (!$this->getAllowMultipleRegistrations()) {
throw new \Exception('Queuing only allowed when there are multiple registrations');
}
// find the best candidate
while ($this->callQueue->count() > 0) {
$registration = NULL;
if (strcasecmp($this->getInvokeType(), Registration::FIRST_REGISTRATION) === 0) {
$registration = $this->getNextFirstRegistration();
} else if (strcasecmp($this->getInvokeType(), Registration::LAST_REGISTRATION) === 0) {
$registration = $this->getNextLastRegistration();
} else if (strcasecmp($this->getInvokeType(), Registration::RANDOM_REGISTRATION) === 0) {
$registration = $this->getNextRandomRegistration();
} else if (strcasecmp($this->getInvokeType(), Registration::ROUNDROBIN_REGISTRATION) === 0) {
$registration = $this->getNextRoundRobinRegistration();
} else if (strcasecmp($this->getInvokeType(), Registration::THRUWAY_REGISTRATION) === 0) {
$registration = $this->getNextThruwayRegistration();
}
if ($registration === NULL) {
break;
}
$call = $this->callQueue->dequeue();
$registration->processCall($call);
}
} | php | public function processQueue()
{
if (!$this->getAllowMultipleRegistrations()) {
throw new \Exception('Queuing only allowed when there are multiple registrations');
}
// find the best candidate
while ($this->callQueue->count() > 0) {
$registration = NULL;
if (strcasecmp($this->getInvokeType(), Registration::FIRST_REGISTRATION) === 0) {
$registration = $this->getNextFirstRegistration();
} else if (strcasecmp($this->getInvokeType(), Registration::LAST_REGISTRATION) === 0) {
$registration = $this->getNextLastRegistration();
} else if (strcasecmp($this->getInvokeType(), Registration::RANDOM_REGISTRATION) === 0) {
$registration = $this->getNextRandomRegistration();
} else if (strcasecmp($this->getInvokeType(), Registration::ROUNDROBIN_REGISTRATION) === 0) {
$registration = $this->getNextRoundRobinRegistration();
} else if (strcasecmp($this->getInvokeType(), Registration::THRUWAY_REGISTRATION) === 0) {
$registration = $this->getNextThruwayRegistration();
}
if ($registration === NULL) {
break;
}
$call = $this->callQueue->dequeue();
$registration->processCall($call);
}
} | [
"public",
"function",
"processQueue",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"getAllowMultipleRegistrations",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Queuing only allowed when there are multiple registrations'",
")",
";",
"}",
"// find the best candidate",
"while",
"(",
"$",
"this",
"->",
"callQueue",
"->",
"count",
"(",
")",
">",
"0",
")",
"{",
"$",
"registration",
"=",
"NULL",
";",
"if",
"(",
"strcasecmp",
"(",
"$",
"this",
"->",
"getInvokeType",
"(",
")",
",",
"Registration",
"::",
"FIRST_REGISTRATION",
")",
"===",
"0",
")",
"{",
"$",
"registration",
"=",
"$",
"this",
"->",
"getNextFirstRegistration",
"(",
")",
";",
"}",
"else",
"if",
"(",
"strcasecmp",
"(",
"$",
"this",
"->",
"getInvokeType",
"(",
")",
",",
"Registration",
"::",
"LAST_REGISTRATION",
")",
"===",
"0",
")",
"{",
"$",
"registration",
"=",
"$",
"this",
"->",
"getNextLastRegistration",
"(",
")",
";",
"}",
"else",
"if",
"(",
"strcasecmp",
"(",
"$",
"this",
"->",
"getInvokeType",
"(",
")",
",",
"Registration",
"::",
"RANDOM_REGISTRATION",
")",
"===",
"0",
")",
"{",
"$",
"registration",
"=",
"$",
"this",
"->",
"getNextRandomRegistration",
"(",
")",
";",
"}",
"else",
"if",
"(",
"strcasecmp",
"(",
"$",
"this",
"->",
"getInvokeType",
"(",
")",
",",
"Registration",
"::",
"ROUNDROBIN_REGISTRATION",
")",
"===",
"0",
")",
"{",
"$",
"registration",
"=",
"$",
"this",
"->",
"getNextRoundRobinRegistration",
"(",
")",
";",
"}",
"else",
"if",
"(",
"strcasecmp",
"(",
"$",
"this",
"->",
"getInvokeType",
"(",
")",
",",
"Registration",
"::",
"THRUWAY_REGISTRATION",
")",
"===",
"0",
")",
"{",
"$",
"registration",
"=",
"$",
"this",
"->",
"getNextThruwayRegistration",
"(",
")",
";",
"}",
"if",
"(",
"$",
"registration",
"===",
"NULL",
")",
"{",
"break",
";",
"}",
"$",
"call",
"=",
"$",
"this",
"->",
"callQueue",
"->",
"dequeue",
"(",
")",
";",
"$",
"registration",
"->",
"processCall",
"(",
"$",
"call",
")",
";",
"}",
"}"
] | Process the Queue
@throws \Exception | [
"Process",
"the",
"Queue"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Procedure.php#L254-L282 |
voryx/Thruway | src/Procedure.php | Procedure.removeCall | public function removeCall(Call $call)
{
$newQueue = new \SplQueue();
while (!$this->callQueue->isEmpty()) {
$c = $this->callQueue->dequeue();
if ($c === $call)
continue;
$newQueue->enqueue($c);
}
$this->callQueue = $newQueue;
$registration = $call->getRegistration();
if ($registration) {
$registration->removeCall($call);
}
} | php | public function removeCall(Call $call)
{
$newQueue = new \SplQueue();
while (!$this->callQueue->isEmpty()) {
$c = $this->callQueue->dequeue();
if ($c === $call)
continue;
$newQueue->enqueue($c);
}
$this->callQueue = $newQueue;
$registration = $call->getRegistration();
if ($registration) {
$registration->removeCall($call);
}
} | [
"public",
"function",
"removeCall",
"(",
"Call",
"$",
"call",
")",
"{",
"$",
"newQueue",
"=",
"new",
"\\",
"SplQueue",
"(",
")",
";",
"while",
"(",
"!",
"$",
"this",
"->",
"callQueue",
"->",
"isEmpty",
"(",
")",
")",
"{",
"$",
"c",
"=",
"$",
"this",
"->",
"callQueue",
"->",
"dequeue",
"(",
")",
";",
"if",
"(",
"$",
"c",
"===",
"$",
"call",
")",
"continue",
";",
"$",
"newQueue",
"->",
"enqueue",
"(",
"$",
"c",
")",
";",
"}",
"$",
"this",
"->",
"callQueue",
"=",
"$",
"newQueue",
";",
"$",
"registration",
"=",
"$",
"call",
"->",
"getRegistration",
"(",
")",
";",
"if",
"(",
"$",
"registration",
")",
"{",
"$",
"registration",
"->",
"removeCall",
"(",
"$",
"call",
")",
";",
"}",
"}"
] | Remove all references to Call to it can be GCed
@param Call $call | [
"Remove",
"all",
"references",
"to",
"Call",
"to",
"it",
"can",
"be",
"GCed"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Procedure.php#L356-L373 |
voryx/Thruway | src/Procedure.php | Procedure.getCallByRequestId | public function getCallByRequestId($requestId)
{
/* @var $registration \Thruway\Registration */
foreach ($this->registrations as $registration) {
$call = $registration->getCallByRequestId($requestId);
if ($call) {
return $call;
}
}
return false;
} | php | public function getCallByRequestId($requestId)
{
/* @var $registration \Thruway\Registration */
foreach ($this->registrations as $registration) {
$call = $registration->getCallByRequestId($requestId);
if ($call) {
return $call;
}
}
return false;
} | [
"public",
"function",
"getCallByRequestId",
"(",
"$",
"requestId",
")",
"{",
"/* @var $registration \\Thruway\\Registration */",
"foreach",
"(",
"$",
"this",
"->",
"registrations",
"as",
"$",
"registration",
")",
"{",
"$",
"call",
"=",
"$",
"registration",
"->",
"getCallByRequestId",
"(",
"$",
"requestId",
")",
";",
"if",
"(",
"$",
"call",
")",
"{",
"return",
"$",
"call",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Get call by request ID
@param int $requestId
@return \Thruway\Call|boolean | [
"Get",
"call",
"by",
"request",
"ID"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Procedure.php#L381-L392 |
voryx/Thruway | src/Procedure.php | Procedure.leave | public function leave(Session $session)
{
// remove all registrations that belong to this session
/* @var $registration \Thruway\Registration */
foreach ($this->registrations as $i => $registration) {
if ($registration->getSession() === $session) {
// if this session is the callee on pending calls - error them out
$registration->errorAllPendingCalls();
array_splice($this->registrations, $i, 1);
}
}
} | php | public function leave(Session $session)
{
// remove all registrations that belong to this session
/* @var $registration \Thruway\Registration */
foreach ($this->registrations as $i => $registration) {
if ($registration->getSession() === $session) {
// if this session is the callee on pending calls - error them out
$registration->errorAllPendingCalls();
array_splice($this->registrations, $i, 1);
}
}
} | [
"public",
"function",
"leave",
"(",
"Session",
"$",
"session",
")",
"{",
"// remove all registrations that belong to this session",
"/* @var $registration \\Thruway\\Registration */",
"foreach",
"(",
"$",
"this",
"->",
"registrations",
"as",
"$",
"i",
"=>",
"$",
"registration",
")",
"{",
"if",
"(",
"$",
"registration",
"->",
"getSession",
"(",
")",
"===",
"$",
"session",
")",
"{",
"// if this session is the callee on pending calls - error them out",
"$",
"registration",
"->",
"errorAllPendingCalls",
"(",
")",
";",
"array_splice",
"(",
"$",
"this",
"->",
"registrations",
",",
"$",
"i",
",",
"1",
")",
";",
"}",
"}",
"}"
] | process session leave
@param \Thruway\Session $session | [
"process",
"session",
"leave"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Procedure.php#L487-L498 |
voryx/Thruway | src/Procedure.php | Procedure.managerGetRegistrations | public function managerGetRegistrations()
{
$registrations = $this->getRegistrations();
$regInfo = [];
/** @var Registration $reg */
foreach ($registrations as $reg) {
$regInfo[] = [
'id' => $reg->getId(),
'invoke' => $reg->getInvokeType(),
'thruway_multiregister' => $reg->getAllowMultipleRegistrations(),
'disclose_caller' => $reg->getDiscloseCaller(),
'session' => $reg->getSession()->getSessionId(),
'authid' => $reg->getSession()->getAuthenticationDetails()->getAuthId(),
'statistics' => $reg->getStatistics()
];
}
} | php | public function managerGetRegistrations()
{
$registrations = $this->getRegistrations();
$regInfo = [];
/** @var Registration $reg */
foreach ($registrations as $reg) {
$regInfo[] = [
'id' => $reg->getId(),
'invoke' => $reg->getInvokeType(),
'thruway_multiregister' => $reg->getAllowMultipleRegistrations(),
'disclose_caller' => $reg->getDiscloseCaller(),
'session' => $reg->getSession()->getSessionId(),
'authid' => $reg->getSession()->getAuthenticationDetails()->getAuthId(),
'statistics' => $reg->getStatistics()
];
}
} | [
"public",
"function",
"managerGetRegistrations",
"(",
")",
"{",
"$",
"registrations",
"=",
"$",
"this",
"->",
"getRegistrations",
"(",
")",
";",
"$",
"regInfo",
"=",
"[",
"]",
";",
"/** @var Registration $reg */",
"foreach",
"(",
"$",
"registrations",
"as",
"$",
"reg",
")",
"{",
"$",
"regInfo",
"[",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"reg",
"->",
"getId",
"(",
")",
",",
"'invoke'",
"=>",
"$",
"reg",
"->",
"getInvokeType",
"(",
")",
",",
"'thruway_multiregister'",
"=>",
"$",
"reg",
"->",
"getAllowMultipleRegistrations",
"(",
")",
",",
"'disclose_caller'",
"=>",
"$",
"reg",
"->",
"getDiscloseCaller",
"(",
")",
",",
"'session'",
"=>",
"$",
"reg",
"->",
"getSession",
"(",
")",
"->",
"getSessionId",
"(",
")",
",",
"'authid'",
"=>",
"$",
"reg",
"->",
"getSession",
"(",
")",
"->",
"getAuthenticationDetails",
"(",
")",
"->",
"getAuthId",
"(",
")",
",",
"'statistics'",
"=>",
"$",
"reg",
"->",
"getStatistics",
"(",
")",
"]",
";",
"}",
"}"
] | todo: This was part of the manager stuff - but may be used by some tests | [
"todo",
":",
"This",
"was",
"part",
"of",
"the",
"manager",
"stuff",
"-",
"but",
"may",
"be",
"used",
"by",
"some",
"tests"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Procedure.php#L504-L521 |
voryx/Thruway | Examples/MetaEvent/InternalClient.php | InternalClient.onSessionLeave | public function onSessionLeave($args, $kwArgs, $options)
{
if (!empty($args[0]['session'])) {
foreach ($this->_sessions as $key => $details) {
if ($args[0]['session'] == $details['session']) {
echo "Session {$details['session']} leaved\n";
unset($this->_sessions[$key]);
return;
}
}
}
} | php | public function onSessionLeave($args, $kwArgs, $options)
{
if (!empty($args[0]['session'])) {
foreach ($this->_sessions as $key => $details) {
if ($args[0]['session'] == $details['session']) {
echo "Session {$details['session']} leaved\n";
unset($this->_sessions[$key]);
return;
}
}
}
} | [
"public",
"function",
"onSessionLeave",
"(",
"$",
"args",
",",
"$",
"kwArgs",
",",
"$",
"options",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"args",
"[",
"0",
"]",
"[",
"'session'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_sessions",
"as",
"$",
"key",
"=>",
"$",
"details",
")",
"{",
"if",
"(",
"$",
"args",
"[",
"0",
"]",
"[",
"'session'",
"]",
"==",
"$",
"details",
"[",
"'session'",
"]",
")",
"{",
"echo",
"\"Session {$details['session']} leaved\\n\"",
";",
"unset",
"(",
"$",
"this",
"->",
"_sessions",
"[",
"$",
"key",
"]",
")",
";",
"return",
";",
"}",
"}",
"}",
"}"
] | Handle on session leaved
@param array $args
@param array $kwArgs
@param array $options
@return void
@link https://github.com/crossbario/crossbar/wiki/Session-Metaevents | [
"Handle",
"on",
"session",
"leaved"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/Examples/MetaEvent/InternalClient.php#L90-L101 |
voryx/Thruway | src/RealmManager.php | RealmManager.getRealm | public function getRealm($realmName)
{
if (!is_scalar($realmName)) {
throw new \InvalidArgumentException('Non-string value given for realm name');
}
if (!array_key_exists($realmName, $this->realms)) {
if ($this->getAllowRealmAutocreate()) {
Logger::debug($this, 'Creating new realm \'' . $realmName . '\'');
$realm = new Realm($realmName);
$this->addRealm($realm);
} else {
throw new RealmNotFoundException();
}
}
return $this->realms[$realmName];
} | php | public function getRealm($realmName)
{
if (!is_scalar($realmName)) {
throw new \InvalidArgumentException('Non-string value given for realm name');
}
if (!array_key_exists($realmName, $this->realms)) {
if ($this->getAllowRealmAutocreate()) {
Logger::debug($this, 'Creating new realm \'' . $realmName . '\'');
$realm = new Realm($realmName);
$this->addRealm($realm);
} else {
throw new RealmNotFoundException();
}
}
return $this->realms[$realmName];
} | [
"public",
"function",
"getRealm",
"(",
"$",
"realmName",
")",
"{",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"realmName",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Non-string value given for realm name'",
")",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"realmName",
",",
"$",
"this",
"->",
"realms",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getAllowRealmAutocreate",
"(",
")",
")",
"{",
"Logger",
"::",
"debug",
"(",
"$",
"this",
",",
"'Creating new realm \\''",
".",
"$",
"realmName",
".",
"'\\''",
")",
";",
"$",
"realm",
"=",
"new",
"Realm",
"(",
"$",
"realmName",
")",
";",
"$",
"this",
"->",
"addRealm",
"(",
"$",
"realm",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"RealmNotFoundException",
"(",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"realms",
"[",
"$",
"realmName",
"]",
";",
"}"
] | Get Realm by realm name
@param string $realmName
@throws \Thruway\Exception\InvalidRealmNameException
@throws \Thruway\Exception\RealmNotFoundException
@return \Thruway\Realm | [
"Get",
"Realm",
"by",
"realm",
"name"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/RealmManager.php#L117-L134 |
voryx/Thruway | src/RealmManager.php | RealmManager.addRealm | public function addRealm(Realm $realm)
{
$realmName = $realm->getRealmName();
if (!static::validRealmName($realm->getRealmName())) {
throw new InvalidRealmNameException;
}
if (array_key_exists($realm->getRealmName(), $this->realms)) {
throw new \Exception('There is already a realm \'' . $realm->getRealmName() . '\'');
}
Logger::debug($this, 'Adding realm \'' . $realmName . '\'');
$this->realms[$realm->getRealmName()] = $realm;
$this->router->getEventDispatcher()->dispatch('new_realm', new NewRealmEvent($realm));
} | php | public function addRealm(Realm $realm)
{
$realmName = $realm->getRealmName();
if (!static::validRealmName($realm->getRealmName())) {
throw new InvalidRealmNameException;
}
if (array_key_exists($realm->getRealmName(), $this->realms)) {
throw new \Exception('There is already a realm \'' . $realm->getRealmName() . '\'');
}
Logger::debug($this, 'Adding realm \'' . $realmName . '\'');
$this->realms[$realm->getRealmName()] = $realm;
$this->router->getEventDispatcher()->dispatch('new_realm', new NewRealmEvent($realm));
} | [
"public",
"function",
"addRealm",
"(",
"Realm",
"$",
"realm",
")",
"{",
"$",
"realmName",
"=",
"$",
"realm",
"->",
"getRealmName",
"(",
")",
";",
"if",
"(",
"!",
"static",
"::",
"validRealmName",
"(",
"$",
"realm",
"->",
"getRealmName",
"(",
")",
")",
")",
"{",
"throw",
"new",
"InvalidRealmNameException",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"$",
"realm",
"->",
"getRealmName",
"(",
")",
",",
"$",
"this",
"->",
"realms",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'There is already a realm \\''",
".",
"$",
"realm",
"->",
"getRealmName",
"(",
")",
".",
"'\\''",
")",
";",
"}",
"Logger",
"::",
"debug",
"(",
"$",
"this",
",",
"'Adding realm \\''",
".",
"$",
"realmName",
".",
"'\\''",
")",
";",
"$",
"this",
"->",
"realms",
"[",
"$",
"realm",
"->",
"getRealmName",
"(",
")",
"]",
"=",
"$",
"realm",
";",
"$",
"this",
"->",
"router",
"->",
"getEventDispatcher",
"(",
")",
"->",
"dispatch",
"(",
"'new_realm'",
",",
"new",
"NewRealmEvent",
"(",
"$",
"realm",
")",
")",
";",
"}"
] | Add new realm
@param \Thruway\Realm $realm
@throws \Thruway\Exception\InvalidRealmNameException
@throws \Exception | [
"Add",
"new",
"realm"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/RealmManager.php#L143-L160 |
voryx/Thruway | src/Module/RouterModuleClient.php | RouterModuleClient.initModule | public function initModule(RouterInterface $router, LoopInterface $loop)
{
$this->router = $router;
$this->setLoop($loop);
$this->router->addInternalClient($this);
} | php | public function initModule(RouterInterface $router, LoopInterface $loop)
{
$this->router = $router;
$this->setLoop($loop);
$this->router->addInternalClient($this);
} | [
"public",
"function",
"initModule",
"(",
"RouterInterface",
"$",
"router",
",",
"LoopInterface",
"$",
"loop",
")",
"{",
"$",
"this",
"->",
"router",
"=",
"$",
"router",
";",
"$",
"this",
"->",
"setLoop",
"(",
"$",
"loop",
")",
";",
"$",
"this",
"->",
"router",
"->",
"addInternalClient",
"(",
"$",
"this",
")",
";",
"}"
] | Called by the router when it is added
@param RouterInterface $router
@param LoopInterface $loop | [
"Called",
"by",
"the",
"router",
"when",
"it",
"is",
"added"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Module/RouterModuleClient.php#L24-L30 |
voryx/Thruway | src/Role/Dealer.php | Dealer.processRegister | private function processRegister(Session $session, RegisterMessage $msg)
{
// check for valid URI
if (!Utils::uriIsValid($msg->getProcedureName())) {
$session->sendMessage(ErrorMessage::createErrorMessageFromMessage($msg, 'wamp.error.invalid_uri'));
return;
}
//Check to see if the procedure is already registered
/** @var Procedure $procedure */
if (isset($this->procedures[$msg->getProcedureName()])) {
$procedure = $this->procedures[$msg->getProcedureName()];
} else {
$procedure = new Procedure($msg->getProcedureName());
$this->procedures[$msg->getProcedureName()] = $procedure;
}
if ($procedure->processRegister($session, $msg)) {
// registration succeeded
// make sure we have the registration in the collection
// of registrations for this session
if (!$this->registrationsBySession->contains($session)) {
$this->registrationsBySession->attach($session, []);
}
$registrationsForThisSession = $this->registrationsBySession[$session];
if (!in_array($procedure, $registrationsForThisSession, true)) {
$registrationsForThisSession[] = $procedure;
$this->registrationsBySession[$session] = $registrationsForThisSession;
}
}
} | php | private function processRegister(Session $session, RegisterMessage $msg)
{
// check for valid URI
if (!Utils::uriIsValid($msg->getProcedureName())) {
$session->sendMessage(ErrorMessage::createErrorMessageFromMessage($msg, 'wamp.error.invalid_uri'));
return;
}
//Check to see if the procedure is already registered
/** @var Procedure $procedure */
if (isset($this->procedures[$msg->getProcedureName()])) {
$procedure = $this->procedures[$msg->getProcedureName()];
} else {
$procedure = new Procedure($msg->getProcedureName());
$this->procedures[$msg->getProcedureName()] = $procedure;
}
if ($procedure->processRegister($session, $msg)) {
// registration succeeded
// make sure we have the registration in the collection
// of registrations for this session
if (!$this->registrationsBySession->contains($session)) {
$this->registrationsBySession->attach($session, []);
}
$registrationsForThisSession = $this->registrationsBySession[$session];
if (!in_array($procedure, $registrationsForThisSession, true)) {
$registrationsForThisSession[] = $procedure;
$this->registrationsBySession[$session] = $registrationsForThisSession;
}
}
} | [
"private",
"function",
"processRegister",
"(",
"Session",
"$",
"session",
",",
"RegisterMessage",
"$",
"msg",
")",
"{",
"// check for valid URI",
"if",
"(",
"!",
"Utils",
"::",
"uriIsValid",
"(",
"$",
"msg",
"->",
"getProcedureName",
"(",
")",
")",
")",
"{",
"$",
"session",
"->",
"sendMessage",
"(",
"ErrorMessage",
"::",
"createErrorMessageFromMessage",
"(",
"$",
"msg",
",",
"'wamp.error.invalid_uri'",
")",
")",
";",
"return",
";",
"}",
"//Check to see if the procedure is already registered",
"/** @var Procedure $procedure */",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"procedures",
"[",
"$",
"msg",
"->",
"getProcedureName",
"(",
")",
"]",
")",
")",
"{",
"$",
"procedure",
"=",
"$",
"this",
"->",
"procedures",
"[",
"$",
"msg",
"->",
"getProcedureName",
"(",
")",
"]",
";",
"}",
"else",
"{",
"$",
"procedure",
"=",
"new",
"Procedure",
"(",
"$",
"msg",
"->",
"getProcedureName",
"(",
")",
")",
";",
"$",
"this",
"->",
"procedures",
"[",
"$",
"msg",
"->",
"getProcedureName",
"(",
")",
"]",
"=",
"$",
"procedure",
";",
"}",
"if",
"(",
"$",
"procedure",
"->",
"processRegister",
"(",
"$",
"session",
",",
"$",
"msg",
")",
")",
"{",
"// registration succeeded",
"// make sure we have the registration in the collection",
"// of registrations for this session",
"if",
"(",
"!",
"$",
"this",
"->",
"registrationsBySession",
"->",
"contains",
"(",
"$",
"session",
")",
")",
"{",
"$",
"this",
"->",
"registrationsBySession",
"->",
"attach",
"(",
"$",
"session",
",",
"[",
"]",
")",
";",
"}",
"$",
"registrationsForThisSession",
"=",
"$",
"this",
"->",
"registrationsBySession",
"[",
"$",
"session",
"]",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"procedure",
",",
"$",
"registrationsForThisSession",
",",
"true",
")",
")",
"{",
"$",
"registrationsForThisSession",
"[",
"]",
"=",
"$",
"procedure",
";",
"$",
"this",
"->",
"registrationsBySession",
"[",
"$",
"session",
"]",
"=",
"$",
"registrationsForThisSession",
";",
"}",
"}",
"}"
] | process RegisterMessage
@param \Thruway\Session $session
@param \Thruway\Message\RegisterMessage $msg | [
"process",
"RegisterMessage"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Role/Dealer.php#L174-L207 |
voryx/Thruway | src/Role/Dealer.php | Dealer.processUnregister | private function processUnregister(Session $session, UnregisterMessage $msg)
{
$registration = $this->getRegistrationById($msg->getRegistrationId());
if ($registration && $this->procedures[$registration->getProcedureName()]) {
$procedure = $this->procedures[$registration->getProcedureName()];
if ($procedure) {
if ($procedure->processUnregister($session, $msg)) {
// Unregistration was successful - remove from this sessions
// list of registrations
if ($this->registrationsBySession->contains($session) &&
in_array($procedure, $this->registrationsBySession[$session], true)
) {
$registrationsInSession = $this->registrationsBySession[$session];
array_splice($registrationsInSession, array_search($procedure, $registrationsInSession, true), 1);
}
}
}
return;
}
// apparently we didn't find anything to unregister
$session->sendMessage(ErrorMessage::createErrorMessageFromMessage($msg, 'wamp.error.no_such_procedure'));
} | php | private function processUnregister(Session $session, UnregisterMessage $msg)
{
$registration = $this->getRegistrationById($msg->getRegistrationId());
if ($registration && $this->procedures[$registration->getProcedureName()]) {
$procedure = $this->procedures[$registration->getProcedureName()];
if ($procedure) {
if ($procedure->processUnregister($session, $msg)) {
// Unregistration was successful - remove from this sessions
// list of registrations
if ($this->registrationsBySession->contains($session) &&
in_array($procedure, $this->registrationsBySession[$session], true)
) {
$registrationsInSession = $this->registrationsBySession[$session];
array_splice($registrationsInSession, array_search($procedure, $registrationsInSession, true), 1);
}
}
}
return;
}
// apparently we didn't find anything to unregister
$session->sendMessage(ErrorMessage::createErrorMessageFromMessage($msg, 'wamp.error.no_such_procedure'));
} | [
"private",
"function",
"processUnregister",
"(",
"Session",
"$",
"session",
",",
"UnregisterMessage",
"$",
"msg",
")",
"{",
"$",
"registration",
"=",
"$",
"this",
"->",
"getRegistrationById",
"(",
"$",
"msg",
"->",
"getRegistrationId",
"(",
")",
")",
";",
"if",
"(",
"$",
"registration",
"&&",
"$",
"this",
"->",
"procedures",
"[",
"$",
"registration",
"->",
"getProcedureName",
"(",
")",
"]",
")",
"{",
"$",
"procedure",
"=",
"$",
"this",
"->",
"procedures",
"[",
"$",
"registration",
"->",
"getProcedureName",
"(",
")",
"]",
";",
"if",
"(",
"$",
"procedure",
")",
"{",
"if",
"(",
"$",
"procedure",
"->",
"processUnregister",
"(",
"$",
"session",
",",
"$",
"msg",
")",
")",
"{",
"// Unregistration was successful - remove from this sessions",
"// list of registrations",
"if",
"(",
"$",
"this",
"->",
"registrationsBySession",
"->",
"contains",
"(",
"$",
"session",
")",
"&&",
"in_array",
"(",
"$",
"procedure",
",",
"$",
"this",
"->",
"registrationsBySession",
"[",
"$",
"session",
"]",
",",
"true",
")",
")",
"{",
"$",
"registrationsInSession",
"=",
"$",
"this",
"->",
"registrationsBySession",
"[",
"$",
"session",
"]",
";",
"array_splice",
"(",
"$",
"registrationsInSession",
",",
"array_search",
"(",
"$",
"procedure",
",",
"$",
"registrationsInSession",
",",
"true",
")",
",",
"1",
")",
";",
"}",
"}",
"}",
"return",
";",
"}",
"// apparently we didn't find anything to unregister",
"$",
"session",
"->",
"sendMessage",
"(",
"ErrorMessage",
"::",
"createErrorMessageFromMessage",
"(",
"$",
"msg",
",",
"'wamp.error.no_such_procedure'",
")",
")",
";",
"}"
] | process UnregisterMessage
@param \Thruway\Session $session
@param \Thruway\Message\UnregisterMessage $msg
@throws \Exception | [
"process",
"UnregisterMessage"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Role/Dealer.php#L216-L240 |
voryx/Thruway | src/Role/Dealer.php | Dealer.processCall | private function processCall(Session $session, CallMessage $msg)
{
if (!Utils::uriIsValid($msg->getProcedureName())) {
$session->sendMessage(ErrorMessage::createErrorMessageFromMessage($msg, 'wamp.error.invalid_uri'));
return;
}
if (!isset($this->procedures[$msg->getProcedureName()])) {
$session->sendMessage(ErrorMessage::createErrorMessageFromMessage($msg, 'wamp.error.no_such_procedure'));
return;
}
/* @var $procedure \Thruway\Procedure */
$procedure = $this->procedures[$msg->getProcedureName()];
$call = new Call($session, $msg, $procedure);
$this->callInvocationIndex[$call->getInvocationRequestId()] = $call;
$this->callRequestIndex[$msg->getRequestId()] = $call;
$keepIndex = $procedure->processCall($session, $call);
if (!$keepIndex) {
$this->removeCall($call);
}
} | php | private function processCall(Session $session, CallMessage $msg)
{
if (!Utils::uriIsValid($msg->getProcedureName())) {
$session->sendMessage(ErrorMessage::createErrorMessageFromMessage($msg, 'wamp.error.invalid_uri'));
return;
}
if (!isset($this->procedures[$msg->getProcedureName()])) {
$session->sendMessage(ErrorMessage::createErrorMessageFromMessage($msg, 'wamp.error.no_such_procedure'));
return;
}
/* @var $procedure \Thruway\Procedure */
$procedure = $this->procedures[$msg->getProcedureName()];
$call = new Call($session, $msg, $procedure);
$this->callInvocationIndex[$call->getInvocationRequestId()] = $call;
$this->callRequestIndex[$msg->getRequestId()] = $call;
$keepIndex = $procedure->processCall($session, $call);
if (!$keepIndex) {
$this->removeCall($call);
}
} | [
"private",
"function",
"processCall",
"(",
"Session",
"$",
"session",
",",
"CallMessage",
"$",
"msg",
")",
"{",
"if",
"(",
"!",
"Utils",
"::",
"uriIsValid",
"(",
"$",
"msg",
"->",
"getProcedureName",
"(",
")",
")",
")",
"{",
"$",
"session",
"->",
"sendMessage",
"(",
"ErrorMessage",
"::",
"createErrorMessageFromMessage",
"(",
"$",
"msg",
",",
"'wamp.error.invalid_uri'",
")",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"procedures",
"[",
"$",
"msg",
"->",
"getProcedureName",
"(",
")",
"]",
")",
")",
"{",
"$",
"session",
"->",
"sendMessage",
"(",
"ErrorMessage",
"::",
"createErrorMessageFromMessage",
"(",
"$",
"msg",
",",
"'wamp.error.no_such_procedure'",
")",
")",
";",
"return",
";",
"}",
"/* @var $procedure \\Thruway\\Procedure */",
"$",
"procedure",
"=",
"$",
"this",
"->",
"procedures",
"[",
"$",
"msg",
"->",
"getProcedureName",
"(",
")",
"]",
";",
"$",
"call",
"=",
"new",
"Call",
"(",
"$",
"session",
",",
"$",
"msg",
",",
"$",
"procedure",
")",
";",
"$",
"this",
"->",
"callInvocationIndex",
"[",
"$",
"call",
"->",
"getInvocationRequestId",
"(",
")",
"]",
"=",
"$",
"call",
";",
"$",
"this",
"->",
"callRequestIndex",
"[",
"$",
"msg",
"->",
"getRequestId",
"(",
")",
"]",
"=",
"$",
"call",
";",
"$",
"keepIndex",
"=",
"$",
"procedure",
"->",
"processCall",
"(",
"$",
"session",
",",
"$",
"call",
")",
";",
"if",
"(",
"!",
"$",
"keepIndex",
")",
"{",
"$",
"this",
"->",
"removeCall",
"(",
"$",
"call",
")",
";",
"}",
"}"
] | Process call
@param \Thruway\Session $session
@param \Thruway\Message\CallMessage $msg
@return boolean | [
"Process",
"call"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Role/Dealer.php#L249-L276 |
voryx/Thruway | src/Role/Dealer.php | Dealer.processYield | private function processYield(Session $session, YieldMessage $msg)
{
/* @var $call Call */
$call = isset($this->callInvocationIndex[$msg->getRequestId()]) ? $this->callInvocationIndex[$msg->getRequestId()] : null;
if (!$call) {
$session->sendMessage(ErrorMessage::createErrorMessageFromMessage($msg));
Logger::error($this, "Was expecting a call");
return;
}
$keepIndex = $call->processYield($session, $msg);
if (!$keepIndex) {
$this->removeCall($call);
}
/* @var $procedure \Thruway\Procedure */
$procedure = isset($this->procedures[$call->getCallMessage()->getUri()]) ? $this->procedures[$call->getCallMessage()->getUri()] : null;
if ($procedure && $procedure->getAllowMultipleRegistrations()) {
$procedure->processQueue();
}
//Process queues on other registrations if we can take more requests
if ($session->getPendingCallCount() == 0 && $this->registrationsBySession->contains($session)) {
$this->processQueue($session);
}
} | php | private function processYield(Session $session, YieldMessage $msg)
{
/* @var $call Call */
$call = isset($this->callInvocationIndex[$msg->getRequestId()]) ? $this->callInvocationIndex[$msg->getRequestId()] : null;
if (!$call) {
$session->sendMessage(ErrorMessage::createErrorMessageFromMessage($msg));
Logger::error($this, "Was expecting a call");
return;
}
$keepIndex = $call->processYield($session, $msg);
if (!$keepIndex) {
$this->removeCall($call);
}
/* @var $procedure \Thruway\Procedure */
$procedure = isset($this->procedures[$call->getCallMessage()->getUri()]) ? $this->procedures[$call->getCallMessage()->getUri()] : null;
if ($procedure && $procedure->getAllowMultipleRegistrations()) {
$procedure->processQueue();
}
//Process queues on other registrations if we can take more requests
if ($session->getPendingCallCount() == 0 && $this->registrationsBySession->contains($session)) {
$this->processQueue($session);
}
} | [
"private",
"function",
"processYield",
"(",
"Session",
"$",
"session",
",",
"YieldMessage",
"$",
"msg",
")",
"{",
"/* @var $call Call */",
"$",
"call",
"=",
"isset",
"(",
"$",
"this",
"->",
"callInvocationIndex",
"[",
"$",
"msg",
"->",
"getRequestId",
"(",
")",
"]",
")",
"?",
"$",
"this",
"->",
"callInvocationIndex",
"[",
"$",
"msg",
"->",
"getRequestId",
"(",
")",
"]",
":",
"null",
";",
"if",
"(",
"!",
"$",
"call",
")",
"{",
"$",
"session",
"->",
"sendMessage",
"(",
"ErrorMessage",
"::",
"createErrorMessageFromMessage",
"(",
"$",
"msg",
")",
")",
";",
"Logger",
"::",
"error",
"(",
"$",
"this",
",",
"\"Was expecting a call\"",
")",
";",
"return",
";",
"}",
"$",
"keepIndex",
"=",
"$",
"call",
"->",
"processYield",
"(",
"$",
"session",
",",
"$",
"msg",
")",
";",
"if",
"(",
"!",
"$",
"keepIndex",
")",
"{",
"$",
"this",
"->",
"removeCall",
"(",
"$",
"call",
")",
";",
"}",
"/* @var $procedure \\Thruway\\Procedure */",
"$",
"procedure",
"=",
"isset",
"(",
"$",
"this",
"->",
"procedures",
"[",
"$",
"call",
"->",
"getCallMessage",
"(",
")",
"->",
"getUri",
"(",
")",
"]",
")",
"?",
"$",
"this",
"->",
"procedures",
"[",
"$",
"call",
"->",
"getCallMessage",
"(",
")",
"->",
"getUri",
"(",
")",
"]",
":",
"null",
";",
"if",
"(",
"$",
"procedure",
"&&",
"$",
"procedure",
"->",
"getAllowMultipleRegistrations",
"(",
")",
")",
"{",
"$",
"procedure",
"->",
"processQueue",
"(",
")",
";",
"}",
"//Process queues on other registrations if we can take more requests",
"if",
"(",
"$",
"session",
"->",
"getPendingCallCount",
"(",
")",
"==",
"0",
"&&",
"$",
"this",
"->",
"registrationsBySession",
"->",
"contains",
"(",
"$",
"session",
")",
")",
"{",
"$",
"this",
"->",
"processQueue",
"(",
"$",
"session",
")",
";",
"}",
"}"
] | process YieldMessage
@param \Thruway\Session $session
@param \Thruway\Message\YieldMessage $msg | [
"process",
"YieldMessage"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Role/Dealer.php#L284-L314 |
voryx/Thruway | src/Role/Dealer.php | Dealer.processError | private function processError(Session $session, ErrorMessage $msg)
{
switch ($msg->getErrorMsgCode()) {
case Message::MSG_INVOCATION:
$this->processInvocationError($session, $msg);
break;
case Message::MSG_INTERRUPT:
$this->processInterruptError($session, $msg);
break;
}
} | php | private function processError(Session $session, ErrorMessage $msg)
{
switch ($msg->getErrorMsgCode()) {
case Message::MSG_INVOCATION:
$this->processInvocationError($session, $msg);
break;
case Message::MSG_INTERRUPT:
$this->processInterruptError($session, $msg);
break;
}
} | [
"private",
"function",
"processError",
"(",
"Session",
"$",
"session",
",",
"ErrorMessage",
"$",
"msg",
")",
"{",
"switch",
"(",
"$",
"msg",
"->",
"getErrorMsgCode",
"(",
")",
")",
"{",
"case",
"Message",
"::",
"MSG_INVOCATION",
":",
"$",
"this",
"->",
"processInvocationError",
"(",
"$",
"session",
",",
"$",
"msg",
")",
";",
"break",
";",
"case",
"Message",
"::",
"MSG_INTERRUPT",
":",
"$",
"this",
"->",
"processInterruptError",
"(",
"$",
"session",
",",
"$",
"msg",
")",
";",
"break",
";",
"}",
"}"
] | process ErrorMessage
@param \Thruway\Session $session
@param \Thruway\Message\ErrorMessage $msg | [
"process",
"ErrorMessage"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Role/Dealer.php#L340-L350 |
voryx/Thruway | src/Role/Dealer.php | Dealer.processInvocationError | private function processInvocationError(Session $session, ErrorMessage $msg)
{
//$call = $this->getCallByRequestId($msg->getRequestId());
$call = $this->callInvocationIndex[$msg->getRequestId()];
if (!$call) {
$errorMsg = ErrorMessage::createErrorMessageFromMessage($msg);
Logger::error($this, 'No call for invocation error message: ' . $msg->getRequestId());
// TODO: do we send a message back to the callee?
$errorMsg->setErrorURI('wamp.error.no_such_procedure');
$session->sendMessage($errorMsg);
return;
}
if ($call->getCalleeSession() !== $session) {
Logger::error($this, 'Attempted Invocation Error from session that does not own the call');
return;
}
$call->getRegistration()->removeCall($call);
$this->removeCall($call);
$errorMsg = ErrorMessage::createErrorMessageFromMessage($call->getCallMessage());
$errorMsg->setErrorURI($msg->getErrorURI());
$errorMsg->setArguments($msg->getArguments());
$errorMsg->setArgumentsKw($msg->getArgumentsKw());
// not sure if this detail should pass through
$errorMsg->setDetails($msg->getDetails());
$call->getCallerSession()->sendMessage($errorMsg);
} | php | private function processInvocationError(Session $session, ErrorMessage $msg)
{
//$call = $this->getCallByRequestId($msg->getRequestId());
$call = $this->callInvocationIndex[$msg->getRequestId()];
if (!$call) {
$errorMsg = ErrorMessage::createErrorMessageFromMessage($msg);
Logger::error($this, 'No call for invocation error message: ' . $msg->getRequestId());
// TODO: do we send a message back to the callee?
$errorMsg->setErrorURI('wamp.error.no_such_procedure');
$session->sendMessage($errorMsg);
return;
}
if ($call->getCalleeSession() !== $session) {
Logger::error($this, 'Attempted Invocation Error from session that does not own the call');
return;
}
$call->getRegistration()->removeCall($call);
$this->removeCall($call);
$errorMsg = ErrorMessage::createErrorMessageFromMessage($call->getCallMessage());
$errorMsg->setErrorURI($msg->getErrorURI());
$errorMsg->setArguments($msg->getArguments());
$errorMsg->setArgumentsKw($msg->getArgumentsKw());
// not sure if this detail should pass through
$errorMsg->setDetails($msg->getDetails());
$call->getCallerSession()->sendMessage($errorMsg);
} | [
"private",
"function",
"processInvocationError",
"(",
"Session",
"$",
"session",
",",
"ErrorMessage",
"$",
"msg",
")",
"{",
"//$call = $this->getCallByRequestId($msg->getRequestId());",
"$",
"call",
"=",
"$",
"this",
"->",
"callInvocationIndex",
"[",
"$",
"msg",
"->",
"getRequestId",
"(",
")",
"]",
";",
"if",
"(",
"!",
"$",
"call",
")",
"{",
"$",
"errorMsg",
"=",
"ErrorMessage",
"::",
"createErrorMessageFromMessage",
"(",
"$",
"msg",
")",
";",
"Logger",
"::",
"error",
"(",
"$",
"this",
",",
"'No call for invocation error message: '",
".",
"$",
"msg",
"->",
"getRequestId",
"(",
")",
")",
";",
"// TODO: do we send a message back to the callee?",
"$",
"errorMsg",
"->",
"setErrorURI",
"(",
"'wamp.error.no_such_procedure'",
")",
";",
"$",
"session",
"->",
"sendMessage",
"(",
"$",
"errorMsg",
")",
";",
"return",
";",
"}",
"if",
"(",
"$",
"call",
"->",
"getCalleeSession",
"(",
")",
"!==",
"$",
"session",
")",
"{",
"Logger",
"::",
"error",
"(",
"$",
"this",
",",
"'Attempted Invocation Error from session that does not own the call'",
")",
";",
"return",
";",
"}",
"$",
"call",
"->",
"getRegistration",
"(",
")",
"->",
"removeCall",
"(",
"$",
"call",
")",
";",
"$",
"this",
"->",
"removeCall",
"(",
"$",
"call",
")",
";",
"$",
"errorMsg",
"=",
"ErrorMessage",
"::",
"createErrorMessageFromMessage",
"(",
"$",
"call",
"->",
"getCallMessage",
"(",
")",
")",
";",
"$",
"errorMsg",
"->",
"setErrorURI",
"(",
"$",
"msg",
"->",
"getErrorURI",
"(",
")",
")",
";",
"$",
"errorMsg",
"->",
"setArguments",
"(",
"$",
"msg",
"->",
"getArguments",
"(",
")",
")",
";",
"$",
"errorMsg",
"->",
"setArgumentsKw",
"(",
"$",
"msg",
"->",
"getArgumentsKw",
"(",
")",
")",
";",
"// not sure if this detail should pass through",
"$",
"errorMsg",
"->",
"setDetails",
"(",
"$",
"msg",
"->",
"getDetails",
"(",
")",
")",
";",
"$",
"call",
"->",
"getCallerSession",
"(",
")",
"->",
"sendMessage",
"(",
"$",
"errorMsg",
")",
";",
"}"
] | Process InvocationError
@param \Thruway\Session $session
@param \Thruway\Message\ErrorMessage $msg | [
"Process",
"InvocationError"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Role/Dealer.php#L398-L433 |
voryx/Thruway | src/Role/Dealer.php | Dealer.removeCall | protected function removeCall(Call $call)
{
$call->getProcedure()->removeCall($call);
unset($this->callInvocationIndex[$call->getInvocationRequestId()]);
unset($this->callRequestIndex[$call->getCallMessage()->getRequestId()]);
if ($call->getCancelMessage()) {
unset($this->callCancelIndex[$call->getCancelMessage()->getRequestId()]);
}
if ($call->getInterruptMessage()) {
unset($this->callInterruptIndex[$call->getInterruptMessage()->getRequestId()]);
}
} | php | protected function removeCall(Call $call)
{
$call->getProcedure()->removeCall($call);
unset($this->callInvocationIndex[$call->getInvocationRequestId()]);
unset($this->callRequestIndex[$call->getCallMessage()->getRequestId()]);
if ($call->getCancelMessage()) {
unset($this->callCancelIndex[$call->getCancelMessage()->getRequestId()]);
}
if ($call->getInterruptMessage()) {
unset($this->callInterruptIndex[$call->getInterruptMessage()->getRequestId()]);
}
} | [
"protected",
"function",
"removeCall",
"(",
"Call",
"$",
"call",
")",
"{",
"$",
"call",
"->",
"getProcedure",
"(",
")",
"->",
"removeCall",
"(",
"$",
"call",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"callInvocationIndex",
"[",
"$",
"call",
"->",
"getInvocationRequestId",
"(",
")",
"]",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"callRequestIndex",
"[",
"$",
"call",
"->",
"getCallMessage",
"(",
")",
"->",
"getRequestId",
"(",
")",
"]",
")",
";",
"if",
"(",
"$",
"call",
"->",
"getCancelMessage",
"(",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"callCancelIndex",
"[",
"$",
"call",
"->",
"getCancelMessage",
"(",
")",
"->",
"getRequestId",
"(",
")",
"]",
")",
";",
"}",
"if",
"(",
"$",
"call",
"->",
"getInterruptMessage",
"(",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"callInterruptIndex",
"[",
"$",
"call",
"->",
"getInterruptMessage",
"(",
")",
"->",
"getRequestId",
"(",
")",
"]",
")",
";",
"}",
"}"
] | This removes all references to calls so they can be GCed
@param Call $call | [
"This",
"removes",
"all",
"references",
"to",
"calls",
"so",
"they",
"can",
"be",
"GCed"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Role/Dealer.php#L465-L476 |
voryx/Thruway | src/Role/Dealer.php | Dealer.getCallByRequestId | public function getCallByRequestId($requestId)
{
$call = isset($this->callRequestIndex[$requestId]) ? $this->callRequestIndex[$requestId] : false;
return $call;
} | php | public function getCallByRequestId($requestId)
{
$call = isset($this->callRequestIndex[$requestId]) ? $this->callRequestIndex[$requestId] : false;
return $call;
} | [
"public",
"function",
"getCallByRequestId",
"(",
"$",
"requestId",
")",
"{",
"$",
"call",
"=",
"isset",
"(",
"$",
"this",
"->",
"callRequestIndex",
"[",
"$",
"requestId",
"]",
")",
"?",
"$",
"this",
"->",
"callRequestIndex",
"[",
"$",
"requestId",
"]",
":",
"false",
";",
"return",
"$",
"call",
";",
"}"
] | Get Call by requestID
@param int $requestId
@return \Thruway\Call|boolean | [
"Get",
"Call",
"by",
"requestID"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Role/Dealer.php#L484-L489 |
voryx/Thruway | src/Role/Dealer.php | Dealer.handlesMessage | public function handlesMessage(Message $msg)
{
$handledMsgCodes = [
Message::MSG_CALL,
Message::MSG_CANCEL,
Message::MSG_REGISTER,
Message::MSG_UNREGISTER,
Message::MSG_YIELD,
Message::MSG_INTERRUPT
];
if (in_array($msg->getMsgCode(), $handledMsgCodes)) {
return true;
} elseif ($msg instanceof ErrorMessage && $msg->getErrorMsgCode() === Message::MSG_INVOCATION) {
return true;
} elseif ($msg instanceof ErrorMessage && $msg->getErrorMsgCode() === Message::MSG_INTERRUPT) {
return true;
} else {
return false;
}
} | php | public function handlesMessage(Message $msg)
{
$handledMsgCodes = [
Message::MSG_CALL,
Message::MSG_CANCEL,
Message::MSG_REGISTER,
Message::MSG_UNREGISTER,
Message::MSG_YIELD,
Message::MSG_INTERRUPT
];
if (in_array($msg->getMsgCode(), $handledMsgCodes)) {
return true;
} elseif ($msg instanceof ErrorMessage && $msg->getErrorMsgCode() === Message::MSG_INVOCATION) {
return true;
} elseif ($msg instanceof ErrorMessage && $msg->getErrorMsgCode() === Message::MSG_INTERRUPT) {
return true;
} else {
return false;
}
} | [
"public",
"function",
"handlesMessage",
"(",
"Message",
"$",
"msg",
")",
"{",
"$",
"handledMsgCodes",
"=",
"[",
"Message",
"::",
"MSG_CALL",
",",
"Message",
"::",
"MSG_CANCEL",
",",
"Message",
"::",
"MSG_REGISTER",
",",
"Message",
"::",
"MSG_UNREGISTER",
",",
"Message",
"::",
"MSG_YIELD",
",",
"Message",
"::",
"MSG_INTERRUPT",
"]",
";",
"if",
"(",
"in_array",
"(",
"$",
"msg",
"->",
"getMsgCode",
"(",
")",
",",
"$",
"handledMsgCodes",
")",
")",
"{",
"return",
"true",
";",
"}",
"elseif",
"(",
"$",
"msg",
"instanceof",
"ErrorMessage",
"&&",
"$",
"msg",
"->",
"getErrorMsgCode",
"(",
")",
"===",
"Message",
"::",
"MSG_INVOCATION",
")",
"{",
"return",
"true",
";",
"}",
"elseif",
"(",
"$",
"msg",
"instanceof",
"ErrorMessage",
"&&",
"$",
"msg",
"->",
"getErrorMsgCode",
"(",
")",
"===",
"Message",
"::",
"MSG_INTERRUPT",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Returns true if this role handles this message.
@param \Thruway\Message\Message $msg
@return boolean | [
"Returns",
"true",
"if",
"this",
"role",
"handles",
"this",
"message",
"."
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Role/Dealer.php#L525-L545 |
voryx/Thruway | src/Role/Dealer.php | Dealer.leave | public function leave(Session $session)
{
/* @var $procedure \Thruway\Procedure */
foreach ($this->procedures as $procedure) {
$procedure->leave($session);
}
foreach ($this->callInvocationIndex as $call) {
if ($session->getSessionId() === $call->getCallerSession()->getSessionId()) {
$cancelMsg = new CancelMessage($call->getCallMessage()->getRequestId(), (object)[]);
$this->processCancel($session, $cancelMsg);
}
}
// remove the list of registrations
if ($this->registrationsBySession->contains($session)) {
$this->registrationsBySession->detach($session);
}
} | php | public function leave(Session $session)
{
/* @var $procedure \Thruway\Procedure */
foreach ($this->procedures as $procedure) {
$procedure->leave($session);
}
foreach ($this->callInvocationIndex as $call) {
if ($session->getSessionId() === $call->getCallerSession()->getSessionId()) {
$cancelMsg = new CancelMessage($call->getCallMessage()->getRequestId(), (object)[]);
$this->processCancel($session, $cancelMsg);
}
}
// remove the list of registrations
if ($this->registrationsBySession->contains($session)) {
$this->registrationsBySession->detach($session);
}
} | [
"public",
"function",
"leave",
"(",
"Session",
"$",
"session",
")",
"{",
"/* @var $procedure \\Thruway\\Procedure */",
"foreach",
"(",
"$",
"this",
"->",
"procedures",
"as",
"$",
"procedure",
")",
"{",
"$",
"procedure",
"->",
"leave",
"(",
"$",
"session",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"callInvocationIndex",
"as",
"$",
"call",
")",
"{",
"if",
"(",
"$",
"session",
"->",
"getSessionId",
"(",
")",
"===",
"$",
"call",
"->",
"getCallerSession",
"(",
")",
"->",
"getSessionId",
"(",
")",
")",
"{",
"$",
"cancelMsg",
"=",
"new",
"CancelMessage",
"(",
"$",
"call",
"->",
"getCallMessage",
"(",
")",
"->",
"getRequestId",
"(",
")",
",",
"(",
"object",
")",
"[",
"]",
")",
";",
"$",
"this",
"->",
"processCancel",
"(",
"$",
"session",
",",
"$",
"cancelMsg",
")",
";",
"}",
"}",
"// remove the list of registrations",
"if",
"(",
"$",
"this",
"->",
"registrationsBySession",
"->",
"contains",
"(",
"$",
"session",
")",
")",
"{",
"$",
"this",
"->",
"registrationsBySession",
"->",
"detach",
"(",
"$",
"session",
")",
";",
"}",
"}"
] | process leave session
@param \Thruway\Session $session | [
"process",
"leave",
"session"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Role/Dealer.php#L552-L570 |
voryx/Thruway | src/Role/Dealer.php | Dealer.managerGetRegistrations | public function managerGetRegistrations()
{
$theRegistrations = [];
/* @var $procedure \Thruway\Procedure */
foreach ($this->procedures as $procedure) {
/* @var $registration \Thruway\Registration */
foreach ($procedure->getRegistrations() as $registration) {
$theRegistrations[] = [
'id' => $registration->getId(),
'name' => $registration->getProcedureName(),
'session' => $registration->getSession()->getSessionId(),
'statistics' => $registration->getStatistics()
];
}
}
return [$theRegistrations];
} | php | public function managerGetRegistrations()
{
$theRegistrations = [];
/* @var $procedure \Thruway\Procedure */
foreach ($this->procedures as $procedure) {
/* @var $registration \Thruway\Registration */
foreach ($procedure->getRegistrations() as $registration) {
$theRegistrations[] = [
'id' => $registration->getId(),
'name' => $registration->getProcedureName(),
'session' => $registration->getSession()->getSessionId(),
'statistics' => $registration->getStatistics()
];
}
}
return [$theRegistrations];
} | [
"public",
"function",
"managerGetRegistrations",
"(",
")",
"{",
"$",
"theRegistrations",
"=",
"[",
"]",
";",
"/* @var $procedure \\Thruway\\Procedure */",
"foreach",
"(",
"$",
"this",
"->",
"procedures",
"as",
"$",
"procedure",
")",
"{",
"/* @var $registration \\Thruway\\Registration */",
"foreach",
"(",
"$",
"procedure",
"->",
"getRegistrations",
"(",
")",
"as",
"$",
"registration",
")",
"{",
"$",
"theRegistrations",
"[",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"registration",
"->",
"getId",
"(",
")",
",",
"'name'",
"=>",
"$",
"registration",
"->",
"getProcedureName",
"(",
")",
",",
"'session'",
"=>",
"$",
"registration",
"->",
"getSession",
"(",
")",
"->",
"getSessionId",
"(",
")",
",",
"'statistics'",
"=>",
"$",
"registration",
"->",
"getStatistics",
"(",
")",
"]",
";",
"}",
"}",
"return",
"[",
"$",
"theRegistrations",
"]",
";",
"}"
] | Get list registrations
todo: this may be used by testing
@return array | [
"Get",
"list",
"registrations"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Role/Dealer.php#L579-L597 |
voryx/Thruway | src/Realm.php | Realm.processSendWelcome | private function processSendWelcome(Session $session, WelcomeMessage $msg)
{
$helloDetails = $session->getHelloMessage()->getDetails();
if (is_object($helloDetails) && isset($helloDetails->roles) && is_object($helloDetails->roles)) {
$session->setRoleFeatures($helloDetails->roles);
}
$session->setState(Session::STATE_UP); // this should probably be after authentication
$details = $msg->getDetails();
if (is_object($details) && isset($details->roles) && is_object($details->roles)) {
$roles = array_filter((array) $details->roles, function($key) {
return in_array($key, ['broker', 'dealer']);
}, ARRAY_FILTER_USE_KEY);
$details->roles = (object) $roles;
$msg->setDetails($details);
}
} | php | private function processSendWelcome(Session $session, WelcomeMessage $msg)
{
$helloDetails = $session->getHelloMessage()->getDetails();
if (is_object($helloDetails) && isset($helloDetails->roles) && is_object($helloDetails->roles)) {
$session->setRoleFeatures($helloDetails->roles);
}
$session->setState(Session::STATE_UP); // this should probably be after authentication
$details = $msg->getDetails();
if (is_object($details) && isset($details->roles) && is_object($details->roles)) {
$roles = array_filter((array) $details->roles, function($key) {
return in_array($key, ['broker', 'dealer']);
}, ARRAY_FILTER_USE_KEY);
$details->roles = (object) $roles;
$msg->setDetails($details);
}
} | [
"private",
"function",
"processSendWelcome",
"(",
"Session",
"$",
"session",
",",
"WelcomeMessage",
"$",
"msg",
")",
"{",
"$",
"helloDetails",
"=",
"$",
"session",
"->",
"getHelloMessage",
"(",
")",
"->",
"getDetails",
"(",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"helloDetails",
")",
"&&",
"isset",
"(",
"$",
"helloDetails",
"->",
"roles",
")",
"&&",
"is_object",
"(",
"$",
"helloDetails",
"->",
"roles",
")",
")",
"{",
"$",
"session",
"->",
"setRoleFeatures",
"(",
"$",
"helloDetails",
"->",
"roles",
")",
";",
"}",
"$",
"session",
"->",
"setState",
"(",
"Session",
"::",
"STATE_UP",
")",
";",
"// this should probably be after authentication",
"$",
"details",
"=",
"$",
"msg",
"->",
"getDetails",
"(",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"details",
")",
"&&",
"isset",
"(",
"$",
"details",
"->",
"roles",
")",
"&&",
"is_object",
"(",
"$",
"details",
"->",
"roles",
")",
")",
"{",
"$",
"roles",
"=",
"array_filter",
"(",
"(",
"array",
")",
"$",
"details",
"->",
"roles",
",",
"function",
"(",
"$",
"key",
")",
"{",
"return",
"in_array",
"(",
"$",
"key",
",",
"[",
"'broker'",
",",
"'dealer'",
"]",
")",
";",
"}",
",",
"ARRAY_FILTER_USE_KEY",
")",
";",
"$",
"details",
"->",
"roles",
"=",
"(",
"object",
")",
"$",
"roles",
";",
"$",
"msg",
"->",
"setDetails",
"(",
"$",
"details",
")",
";",
"}",
"}"
] | Process HelloMessage
@param \Thruway\Session $session
@param \Thruway\Message\WelcomeMessage $msg
@throws InvalidRealmNameException | [
"Process",
"HelloMessage"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Realm.php#L157-L177 |
voryx/Thruway | src/Realm.php | Realm.processAuthenticate | private function processAuthenticate(Session $session, AuthenticateMessage $msg)
{
$session->abort(new \stdClass(), 'thruway.error.internal');
Logger::error($this, 'Authenticate sent to realm without auth manager.');
} | php | private function processAuthenticate(Session $session, AuthenticateMessage $msg)
{
$session->abort(new \stdClass(), 'thruway.error.internal');
Logger::error($this, 'Authenticate sent to realm without auth manager.');
} | [
"private",
"function",
"processAuthenticate",
"(",
"Session",
"$",
"session",
",",
"AuthenticateMessage",
"$",
"msg",
")",
"{",
"$",
"session",
"->",
"abort",
"(",
"new",
"\\",
"stdClass",
"(",
")",
",",
"'thruway.error.internal'",
")",
";",
"Logger",
"::",
"error",
"(",
"$",
"this",
",",
"'Authenticate sent to realm without auth manager.'",
")",
";",
"}"
] | Process AuthenticateMessage
@param \Thruway\Session $session
@param \Thruway\Message\AuthenticateMessage $msg | [
"Process",
"AuthenticateMessage"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Realm.php#L186-L190 |
voryx/Thruway | src/Realm.php | Realm.managerGetSessions | public function managerGetSessions()
{
$theSessions = [];
/* @var $session \Thruway\Session */
foreach ($this->sessions as $session) {
$sessionRealm = null;
// just in case the session is not in a realm yet
if ($session->getRealm() !== null) {
$sessionRealm = $session->getRealm()->getRealmName();
}
if ($session->getAuthenticationDetails() !== null) {
$authDetails = $session->getAuthenticationDetails();
$auth = [
'authid' => $authDetails->getAuthId(),
'authmethod' => $authDetails->getAuthMethod()
];
} else {
$auth = new \stdClass();
}
$theSessions[] = [
'id' => $session->getSessionId(),
'transport' => $session->getTransport()->getTransportDetails(),
'messagesSent' => $session->getMessagesSent(),
'sessionStart' => $session->getSessionStart(),
'realm' => $sessionRealm,
'auth' => $auth
];
}
return $theSessions;
} | php | public function managerGetSessions()
{
$theSessions = [];
/* @var $session \Thruway\Session */
foreach ($this->sessions as $session) {
$sessionRealm = null;
// just in case the session is not in a realm yet
if ($session->getRealm() !== null) {
$sessionRealm = $session->getRealm()->getRealmName();
}
if ($session->getAuthenticationDetails() !== null) {
$authDetails = $session->getAuthenticationDetails();
$auth = [
'authid' => $authDetails->getAuthId(),
'authmethod' => $authDetails->getAuthMethod()
];
} else {
$auth = new \stdClass();
}
$theSessions[] = [
'id' => $session->getSessionId(),
'transport' => $session->getTransport()->getTransportDetails(),
'messagesSent' => $session->getMessagesSent(),
'sessionStart' => $session->getSessionStart(),
'realm' => $sessionRealm,
'auth' => $auth
];
}
return $theSessions;
} | [
"public",
"function",
"managerGetSessions",
"(",
")",
"{",
"$",
"theSessions",
"=",
"[",
"]",
";",
"/* @var $session \\Thruway\\Session */",
"foreach",
"(",
"$",
"this",
"->",
"sessions",
"as",
"$",
"session",
")",
"{",
"$",
"sessionRealm",
"=",
"null",
";",
"// just in case the session is not in a realm yet",
"if",
"(",
"$",
"session",
"->",
"getRealm",
"(",
")",
"!==",
"null",
")",
"{",
"$",
"sessionRealm",
"=",
"$",
"session",
"->",
"getRealm",
"(",
")",
"->",
"getRealmName",
"(",
")",
";",
"}",
"if",
"(",
"$",
"session",
"->",
"getAuthenticationDetails",
"(",
")",
"!==",
"null",
")",
"{",
"$",
"authDetails",
"=",
"$",
"session",
"->",
"getAuthenticationDetails",
"(",
")",
";",
"$",
"auth",
"=",
"[",
"'authid'",
"=>",
"$",
"authDetails",
"->",
"getAuthId",
"(",
")",
",",
"'authmethod'",
"=>",
"$",
"authDetails",
"->",
"getAuthMethod",
"(",
")",
"]",
";",
"}",
"else",
"{",
"$",
"auth",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"}",
"$",
"theSessions",
"[",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"session",
"->",
"getSessionId",
"(",
")",
",",
"'transport'",
"=>",
"$",
"session",
"->",
"getTransport",
"(",
")",
"->",
"getTransportDetails",
"(",
")",
",",
"'messagesSent'",
"=>",
"$",
"session",
"->",
"getMessagesSent",
"(",
")",
",",
"'sessionStart'",
"=>",
"$",
"session",
"->",
"getSessionStart",
"(",
")",
",",
"'realm'",
"=>",
"$",
"sessionRealm",
",",
"'auth'",
"=>",
"$",
"auth",
"]",
";",
"}",
"return",
"$",
"theSessions",
";",
"}"
] | Get list sessions
todo: this is used by some tests - is leftover from the old manager stuff
@return array | [
"Get",
"list",
"sessions"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Realm.php#L199-L233 |
voryx/Thruway | src/Realm.php | Realm.leave | public function leave(Session $session)
{
Logger::debug($this, "Leaving realm {$session->getRealm()->getRealmName()}");
$key = array_search($session, $this->sessions, true);
if ($key !== false) {
array_splice($this->sessions, $key, 1);
}
} | php | public function leave(Session $session)
{
Logger::debug($this, "Leaving realm {$session->getRealm()->getRealmName()}");
$key = array_search($session, $this->sessions, true);
if ($key !== false) {
array_splice($this->sessions, $key, 1);
}
} | [
"public",
"function",
"leave",
"(",
"Session",
"$",
"session",
")",
"{",
"Logger",
"::",
"debug",
"(",
"$",
"this",
",",
"\"Leaving realm {$session->getRealm()->getRealmName()}\"",
")",
";",
"$",
"key",
"=",
"array_search",
"(",
"$",
"session",
",",
"$",
"this",
"->",
"sessions",
",",
"true",
")",
";",
"if",
"(",
"$",
"key",
"!==",
"false",
")",
"{",
"array_splice",
"(",
"$",
"this",
"->",
"sessions",
",",
"$",
"key",
",",
"1",
")",
";",
"}",
"}"
] | Process on session leave
@param \Thruway\Session $session | [
"Process",
"on",
"session",
"leave"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Realm.php#L250-L259 |
voryx/Thruway | src/Realm.php | Realm.publishMeta | public function publishMeta($topicName, $arguments, $argumentsKw = null, $options = null)
{
if ($this->metaSession === null) {
// setup a new metaSession
$s = new Session(new DummyTransport());
$this->metaSession = $s;
}
$messageEvent = new MessageEvent($this->metaSession,
new PublishMessage(
Utils::getUniqueId(),
$options,
$topicName,
$arguments,
$argumentsKw
));
$this->getBroker()->handlePublishMessage($messageEvent);
} | php | public function publishMeta($topicName, $arguments, $argumentsKw = null, $options = null)
{
if ($this->metaSession === null) {
// setup a new metaSession
$s = new Session(new DummyTransport());
$this->metaSession = $s;
}
$messageEvent = new MessageEvent($this->metaSession,
new PublishMessage(
Utils::getUniqueId(),
$options,
$topicName,
$arguments,
$argumentsKw
));
$this->getBroker()->handlePublishMessage($messageEvent);
} | [
"public",
"function",
"publishMeta",
"(",
"$",
"topicName",
",",
"$",
"arguments",
",",
"$",
"argumentsKw",
"=",
"null",
",",
"$",
"options",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"metaSession",
"===",
"null",
")",
"{",
"// setup a new metaSession",
"$",
"s",
"=",
"new",
"Session",
"(",
"new",
"DummyTransport",
"(",
")",
")",
";",
"$",
"this",
"->",
"metaSession",
"=",
"$",
"s",
";",
"}",
"$",
"messageEvent",
"=",
"new",
"MessageEvent",
"(",
"$",
"this",
"->",
"metaSession",
",",
"new",
"PublishMessage",
"(",
"Utils",
"::",
"getUniqueId",
"(",
")",
",",
"$",
"options",
",",
"$",
"topicName",
",",
"$",
"arguments",
",",
"$",
"argumentsKw",
")",
")",
";",
"$",
"this",
"->",
"getBroker",
"(",
")",
"->",
"handlePublishMessage",
"(",
"$",
"messageEvent",
")",
";",
"}"
] | Publish meta
@param string $topicName
@param mixed $arguments
@param mixed $argumentsKw
@param mixed $options | [
"Publish",
"meta"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Realm.php#L299-L316 |
voryx/Thruway | src/Subscription/StateHandlerRegistry.php | StateHandlerRegistry.initModule | public function initModule(RouterInterface $router, LoopInterface $loop)
{
parent::initModule($router, $loop);
$this->routerRealm = $router->getRealmManager()->getRealm($this->getRealm());
$this->broker = $this->routerRealm->getBroker();
$this->broker->setStateHandlerRegistry($this);
} | php | public function initModule(RouterInterface $router, LoopInterface $loop)
{
parent::initModule($router, $loop);
$this->routerRealm = $router->getRealmManager()->getRealm($this->getRealm());
$this->broker = $this->routerRealm->getBroker();
$this->broker->setStateHandlerRegistry($this);
} | [
"public",
"function",
"initModule",
"(",
"RouterInterface",
"$",
"router",
",",
"LoopInterface",
"$",
"loop",
")",
"{",
"parent",
"::",
"initModule",
"(",
"$",
"router",
",",
"$",
"loop",
")",
";",
"$",
"this",
"->",
"routerRealm",
"=",
"$",
"router",
"->",
"getRealmManager",
"(",
")",
"->",
"getRealm",
"(",
"$",
"this",
"->",
"getRealm",
"(",
")",
")",
";",
"$",
"this",
"->",
"broker",
"=",
"$",
"this",
"->",
"routerRealm",
"->",
"getBroker",
"(",
")",
";",
"$",
"this",
"->",
"broker",
"->",
"setStateHandlerRegistry",
"(",
"$",
"this",
")",
";",
"}"
] | Gets called when the module is initialized in the router
@inheritdoc | [
"Gets",
"called",
"when",
"the",
"module",
"is",
"initialized",
"in",
"the",
"router"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Subscription/StateHandlerRegistry.php#L62-L69 |
voryx/Thruway | src/Subscription/StateHandlerRegistry.php | StateHandlerRegistry.onSessionStart | public function onSessionStart($session, $transport)
{
$promises = [];
$promises[] = $session->register('add_state_handler', [$this, "addStateHandler"]);
$promises[] = $session->register('remove_state_handler', [$this, "removeStateHandler"]);
$pAll = \React\Promise\all($promises);
$pAll->then(
function () {
$this->setReady(true);
},
function () {
$this->setReady(false);
}
);
} | php | public function onSessionStart($session, $transport)
{
$promises = [];
$promises[] = $session->register('add_state_handler', [$this, "addStateHandler"]);
$promises[] = $session->register('remove_state_handler', [$this, "removeStateHandler"]);
$pAll = \React\Promise\all($promises);
$pAll->then(
function () {
$this->setReady(true);
},
function () {
$this->setReady(false);
}
);
} | [
"public",
"function",
"onSessionStart",
"(",
"$",
"session",
",",
"$",
"transport",
")",
"{",
"$",
"promises",
"=",
"[",
"]",
";",
"$",
"promises",
"[",
"]",
"=",
"$",
"session",
"->",
"register",
"(",
"'add_state_handler'",
",",
"[",
"$",
"this",
",",
"\"addStateHandler\"",
"]",
")",
";",
"$",
"promises",
"[",
"]",
"=",
"$",
"session",
"->",
"register",
"(",
"'remove_state_handler'",
",",
"[",
"$",
"this",
",",
"\"removeStateHandler\"",
"]",
")",
";",
"$",
"pAll",
"=",
"\\",
"React",
"\\",
"Promise",
"\\",
"all",
"(",
"$",
"promises",
")",
";",
"$",
"pAll",
"->",
"then",
"(",
"function",
"(",
")",
"{",
"$",
"this",
"->",
"setReady",
"(",
"true",
")",
";",
"}",
",",
"function",
"(",
")",
"{",
"$",
"this",
"->",
"setReady",
"(",
"false",
")",
";",
"}",
")",
";",
"}"
] | Handles session started
@param \Thruway\ClientSession $session
@param \Thruway\Transport\TransportProviderInterface $transport | [
"Handles",
"session",
"started"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Subscription/StateHandlerRegistry.php#L77-L93 |
voryx/Thruway | src/Subscription/StateHandlerRegistry.php | StateHandlerRegistry.setupStateHandlerRegistration | private function setupStateHandlerRegistration(SubscriptionGroup $subscriptionGroup)
{
/** @var StateHandlerRegistration $stateHandlerRegistration */
foreach ($this->stateHandlerRegistrations as $stateHandlerRegistration) {
if ($stateHandlerRegistration->handlesStateFor($subscriptionGroup)) {
$this->stateHandlerMap->attach($subscriptionGroup, $stateHandlerRegistration);
return;
}
}
$this->stateHandlerMap->attach($subscriptionGroup, null);
} | php | private function setupStateHandlerRegistration(SubscriptionGroup $subscriptionGroup)
{
/** @var StateHandlerRegistration $stateHandlerRegistration */
foreach ($this->stateHandlerRegistrations as $stateHandlerRegistration) {
if ($stateHandlerRegistration->handlesStateFor($subscriptionGroup)) {
$this->stateHandlerMap->attach($subscriptionGroup, $stateHandlerRegistration);
return;
}
}
$this->stateHandlerMap->attach($subscriptionGroup, null);
} | [
"private",
"function",
"setupStateHandlerRegistration",
"(",
"SubscriptionGroup",
"$",
"subscriptionGroup",
")",
"{",
"/** @var StateHandlerRegistration $stateHandlerRegistration */",
"foreach",
"(",
"$",
"this",
"->",
"stateHandlerRegistrations",
"as",
"$",
"stateHandlerRegistration",
")",
"{",
"if",
"(",
"$",
"stateHandlerRegistration",
"->",
"handlesStateFor",
"(",
"$",
"subscriptionGroup",
")",
")",
"{",
"$",
"this",
"->",
"stateHandlerMap",
"->",
"attach",
"(",
"$",
"subscriptionGroup",
",",
"$",
"stateHandlerRegistration",
")",
";",
"return",
";",
"}",
"}",
"$",
"this",
"->",
"stateHandlerMap",
"->",
"attach",
"(",
"$",
"subscriptionGroup",
",",
"null",
")",
";",
"}"
] | Called when we need to setup a registration
If there is a registration that works - then we set the handler
Otherwise, we set it to null
@param SubscriptionGroup $subscriptionGroup | [
"Called",
"when",
"we",
"need",
"to",
"setup",
"a",
"registration",
"If",
"there",
"is",
"a",
"registration",
"that",
"works",
"-",
"then",
"we",
"set",
"the",
"handler",
"Otherwise",
"we",
"set",
"it",
"to",
"null"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Subscription/StateHandlerRegistry.php#L180-L190 |
voryx/Thruway | src/Authentication/AbstractAuthProviderClient.php | AbstractAuthProviderClient.onSessionStart | public function onSessionStart($session, $transport)
{
$session->register(
"thruway.auth.{$this->getMethodName()}.onhello",
[$this, 'processHello'],
['replace_orphaned_session' => 'yes']
)
->then(function () use ($session) {
$session->register(
"thruway.auth.{$this->getMethodName()}.onauthenticate",
[$this, 'preProcessAuthenticate'],
['replace_orphaned_session' => 'yes']
)->then(function () use ($session) {
$registrations = new \stdClass();
$registrations->onhello = "thruway.auth.{$this->getMethodName()}.onhello";
$registrations->onauthenticate = "thruway.auth.{$this->getMethodName()}.onauthenticate";
$session->call('thruway.auth.registermethod',
[
$this->getMethodName(),
$registrations,
$this->getAuthRealms()
]
)->then(function ($args) {
Logger::debug($this, "Authentication Method Registration Successful: {$this->getMethodName()}");
});
});
});
} | php | public function onSessionStart($session, $transport)
{
$session->register(
"thruway.auth.{$this->getMethodName()}.onhello",
[$this, 'processHello'],
['replace_orphaned_session' => 'yes']
)
->then(function () use ($session) {
$session->register(
"thruway.auth.{$this->getMethodName()}.onauthenticate",
[$this, 'preProcessAuthenticate'],
['replace_orphaned_session' => 'yes']
)->then(function () use ($session) {
$registrations = new \stdClass();
$registrations->onhello = "thruway.auth.{$this->getMethodName()}.onhello";
$registrations->onauthenticate = "thruway.auth.{$this->getMethodName()}.onauthenticate";
$session->call('thruway.auth.registermethod',
[
$this->getMethodName(),
$registrations,
$this->getAuthRealms()
]
)->then(function ($args) {
Logger::debug($this, "Authentication Method Registration Successful: {$this->getMethodName()}");
});
});
});
} | [
"public",
"function",
"onSessionStart",
"(",
"$",
"session",
",",
"$",
"transport",
")",
"{",
"$",
"session",
"->",
"register",
"(",
"\"thruway.auth.{$this->getMethodName()}.onhello\"",
",",
"[",
"$",
"this",
",",
"'processHello'",
"]",
",",
"[",
"'replace_orphaned_session'",
"=>",
"'yes'",
"]",
")",
"->",
"then",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"session",
")",
"{",
"$",
"session",
"->",
"register",
"(",
"\"thruway.auth.{$this->getMethodName()}.onauthenticate\"",
",",
"[",
"$",
"this",
",",
"'preProcessAuthenticate'",
"]",
",",
"[",
"'replace_orphaned_session'",
"=>",
"'yes'",
"]",
")",
"->",
"then",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"session",
")",
"{",
"$",
"registrations",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"registrations",
"->",
"onhello",
"=",
"\"thruway.auth.{$this->getMethodName()}.onhello\"",
";",
"$",
"registrations",
"->",
"onauthenticate",
"=",
"\"thruway.auth.{$this->getMethodName()}.onauthenticate\"",
";",
"$",
"session",
"->",
"call",
"(",
"'thruway.auth.registermethod'",
",",
"[",
"$",
"this",
"->",
"getMethodName",
"(",
")",
",",
"$",
"registrations",
",",
"$",
"this",
"->",
"getAuthRealms",
"(",
")",
"]",
")",
"->",
"then",
"(",
"function",
"(",
"$",
"args",
")",
"{",
"Logger",
"::",
"debug",
"(",
"$",
"this",
",",
"\"Authentication Method Registration Successful: {$this->getMethodName()}\"",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Handles session start
@param \Thruway\ClientSession $session
@param \Thruway\Transport\TransportProviderInterface $transport | [
"Handles",
"session",
"start"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Authentication/AbstractAuthProviderClient.php#L60-L89 |
voryx/Thruway | src/Authentication/AbstractAuthProviderClient.php | AbstractAuthProviderClient.preProcessAuthenticate | public function preProcessAuthenticate(array $args)
{
$args = $args[0];
$signature = isset($args->signature) ? $args->signature : null;
$extra = isset($args->extra) ? $args->extra : null;
if (!$signature) {
return ['ERROR'];
}
return $this->processAuthenticate($signature, $extra);
} | php | public function preProcessAuthenticate(array $args)
{
$args = $args[0];
$signature = isset($args->signature) ? $args->signature : null;
$extra = isset($args->extra) ? $args->extra : null;
if (!$signature) {
return ['ERROR'];
}
return $this->processAuthenticate($signature, $extra);
} | [
"public",
"function",
"preProcessAuthenticate",
"(",
"array",
"$",
"args",
")",
"{",
"$",
"args",
"=",
"$",
"args",
"[",
"0",
"]",
";",
"$",
"signature",
"=",
"isset",
"(",
"$",
"args",
"->",
"signature",
")",
"?",
"$",
"args",
"->",
"signature",
":",
"null",
";",
"$",
"extra",
"=",
"isset",
"(",
"$",
"args",
"->",
"extra",
")",
"?",
"$",
"args",
"->",
"extra",
":",
"null",
";",
"if",
"(",
"!",
"$",
"signature",
")",
"{",
"return",
"[",
"'ERROR'",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"processAuthenticate",
"(",
"$",
"signature",
",",
"$",
"extra",
")",
";",
"}"
] | Pre process AuthenticateMessage
Extract and validate arguments
@param array $args
@return array | [
"Pre",
"process",
"AuthenticateMessage",
"Extract",
"and",
"validate",
"arguments"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Authentication/AbstractAuthProviderClient.php#L98-L110 |
voryx/Thruway | Examples/Authentication/WampCra/UserDb.php | UserDb.add | function add($userName, $password, $salt = null)
{
if ($salt !== null) {
$key = \Thruway\Common\Utils::getDerivedKey($password, $salt);
} else {
$key = $password;
}
$this->users[$userName] = ["authid" => $userName, "key" => $key, "salt" => $salt];
} | php | function add($userName, $password, $salt = null)
{
if ($salt !== null) {
$key = \Thruway\Common\Utils::getDerivedKey($password, $salt);
} else {
$key = $password;
}
$this->users[$userName] = ["authid" => $userName, "key" => $key, "salt" => $salt];
} | [
"function",
"add",
"(",
"$",
"userName",
",",
"$",
"password",
",",
"$",
"salt",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"salt",
"!==",
"null",
")",
"{",
"$",
"key",
"=",
"\\",
"Thruway",
"\\",
"Common",
"\\",
"Utils",
"::",
"getDerivedKey",
"(",
"$",
"password",
",",
"$",
"salt",
")",
";",
"}",
"else",
"{",
"$",
"key",
"=",
"$",
"password",
";",
"}",
"$",
"this",
"->",
"users",
"[",
"$",
"userName",
"]",
"=",
"[",
"\"authid\"",
"=>",
"$",
"userName",
",",
"\"key\"",
"=>",
"$",
"key",
",",
"\"salt\"",
"=>",
"$",
"salt",
"]",
";",
"}"
] | Add new user
@param string $userName
@param string $password
@param string $salt | [
"Add",
"new",
"user"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/Examples/Authentication/WampCra/UserDb.php#L30-L39 |
voryx/Thruway | Examples/Authentication/WampCra/UserDb.php | UserDb.get | function get($authId)
{
if (isset($this->users[$authId])) {
return $this->users[$authId];
} else {
return false;
}
} | php | function get($authId)
{
if (isset($this->users[$authId])) {
return $this->users[$authId];
} else {
return false;
}
} | [
"function",
"get",
"(",
"$",
"authId",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"users",
"[",
"$",
"authId",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"users",
"[",
"$",
"authId",
"]",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Get user by username
@param string $authId Username
@return boolean | [
"Get",
"user",
"by",
"username"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/Examples/Authentication/WampCra/UserDb.php#L47-L54 |
voryx/Thruway | src/Subscription/SubscriptionGroup.php | SubscriptionGroup.sendEventMessage | private function sendEventMessage(Session $session, PublishMessage $msg, Subscription $subscription)
{
$sessionId = $subscription->getSession()->getSessionId();
$authroles = [];
$authid = '';
$authenticationDetails = $subscription->getSession()->getAuthenticationDetails();
if ($authenticationDetails) {
$authroles = $authenticationDetails->getAuthRoles();
$authid = $authenticationDetails->getAuthId();
}
if ((!$msg->excludeMe() || $subscription->getSession() != $session)
&& !$msg->isExcluded($sessionId)
&& $msg->isWhiteListed($sessionId)
&& $msg->hasEligibleAuthrole($authroles)
&& $msg->hasEligibleAuthid($authid)
) {
$eventMsg = EventMessage::createFromPublishMessage($msg, $subscription->getId());
if ($subscription->isDisclosePublisher() === true) {
$eventMsg->disclosePublisher($session);
}
if ($this->getMatchType() !== 'exact') {
$eventMsg->getDetails()->topic = $msg->getUri();
}
$subscription->sendEventMessage($eventMsg);
}
} | php | private function sendEventMessage(Session $session, PublishMessage $msg, Subscription $subscription)
{
$sessionId = $subscription->getSession()->getSessionId();
$authroles = [];
$authid = '';
$authenticationDetails = $subscription->getSession()->getAuthenticationDetails();
if ($authenticationDetails) {
$authroles = $authenticationDetails->getAuthRoles();
$authid = $authenticationDetails->getAuthId();
}
if ((!$msg->excludeMe() || $subscription->getSession() != $session)
&& !$msg->isExcluded($sessionId)
&& $msg->isWhiteListed($sessionId)
&& $msg->hasEligibleAuthrole($authroles)
&& $msg->hasEligibleAuthid($authid)
) {
$eventMsg = EventMessage::createFromPublishMessage($msg, $subscription->getId());
if ($subscription->isDisclosePublisher() === true) {
$eventMsg->disclosePublisher($session);
}
if ($this->getMatchType() !== 'exact') {
$eventMsg->getDetails()->topic = $msg->getUri();
}
$subscription->sendEventMessage($eventMsg);
}
} | [
"private",
"function",
"sendEventMessage",
"(",
"Session",
"$",
"session",
",",
"PublishMessage",
"$",
"msg",
",",
"Subscription",
"$",
"subscription",
")",
"{",
"$",
"sessionId",
"=",
"$",
"subscription",
"->",
"getSession",
"(",
")",
"->",
"getSessionId",
"(",
")",
";",
"$",
"authroles",
"=",
"[",
"]",
";",
"$",
"authid",
"=",
"''",
";",
"$",
"authenticationDetails",
"=",
"$",
"subscription",
"->",
"getSession",
"(",
")",
"->",
"getAuthenticationDetails",
"(",
")",
";",
"if",
"(",
"$",
"authenticationDetails",
")",
"{",
"$",
"authroles",
"=",
"$",
"authenticationDetails",
"->",
"getAuthRoles",
"(",
")",
";",
"$",
"authid",
"=",
"$",
"authenticationDetails",
"->",
"getAuthId",
"(",
")",
";",
"}",
"if",
"(",
"(",
"!",
"$",
"msg",
"->",
"excludeMe",
"(",
")",
"||",
"$",
"subscription",
"->",
"getSession",
"(",
")",
"!=",
"$",
"session",
")",
"&&",
"!",
"$",
"msg",
"->",
"isExcluded",
"(",
"$",
"sessionId",
")",
"&&",
"$",
"msg",
"->",
"isWhiteListed",
"(",
"$",
"sessionId",
")",
"&&",
"$",
"msg",
"->",
"hasEligibleAuthrole",
"(",
"$",
"authroles",
")",
"&&",
"$",
"msg",
"->",
"hasEligibleAuthid",
"(",
"$",
"authid",
")",
")",
"{",
"$",
"eventMsg",
"=",
"EventMessage",
"::",
"createFromPublishMessage",
"(",
"$",
"msg",
",",
"$",
"subscription",
"->",
"getId",
"(",
")",
")",
";",
"if",
"(",
"$",
"subscription",
"->",
"isDisclosePublisher",
"(",
")",
"===",
"true",
")",
"{",
"$",
"eventMsg",
"->",
"disclosePublisher",
"(",
"$",
"session",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"getMatchType",
"(",
")",
"!==",
"'exact'",
")",
"{",
"$",
"eventMsg",
"->",
"getDetails",
"(",
")",
"->",
"topic",
"=",
"$",
"msg",
"->",
"getUri",
"(",
")",
";",
"}",
"$",
"subscription",
"->",
"sendEventMessage",
"(",
"$",
"eventMsg",
")",
";",
"}",
"}"
] | Send an Event Message for each subscription
@param Session $session
@param PublishMessage $msg
@param Subscription $subscription | [
"Send",
"an",
"Event",
"Message",
"for",
"each",
"subscription"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Subscription/SubscriptionGroup.php#L112-L138 |
voryx/Thruway | src/Subscription/Subscription.php | Subscription.createSubscriptionFromSubscribeMessage | public static function createSubscriptionFromSubscribeMessage(Session $session, SubscribeMessage $msg)
{
$options = $msg->getOptions();
$subscription = new Subscription($msg->getTopicName(), $session, $options);
if (isset($options->disclose_publisher) && $options->disclose_publisher === true) {
$subscription->setDisclosePublisher(true);
}
return $subscription;
} | php | public static function createSubscriptionFromSubscribeMessage(Session $session, SubscribeMessage $msg)
{
$options = $msg->getOptions();
$subscription = new Subscription($msg->getTopicName(), $session, $options);
if (isset($options->disclose_publisher) && $options->disclose_publisher === true) {
$subscription->setDisclosePublisher(true);
}
return $subscription;
} | [
"public",
"static",
"function",
"createSubscriptionFromSubscribeMessage",
"(",
"Session",
"$",
"session",
",",
"SubscribeMessage",
"$",
"msg",
")",
"{",
"$",
"options",
"=",
"$",
"msg",
"->",
"getOptions",
"(",
")",
";",
"$",
"subscription",
"=",
"new",
"Subscription",
"(",
"$",
"msg",
"->",
"getTopicName",
"(",
")",
",",
"$",
"session",
",",
"$",
"options",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"->",
"disclose_publisher",
")",
"&&",
"$",
"options",
"->",
"disclose_publisher",
"===",
"true",
")",
"{",
"$",
"subscription",
"->",
"setDisclosePublisher",
"(",
"true",
")",
";",
"}",
"return",
"$",
"subscription",
";",
"}"
] | Create Subscription from SubscribeMessage
@param Session $session
@param SubscribeMessage $msg
@return Subscription | [
"Create",
"Subscription",
"from",
"SubscribeMessage"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Subscription/Subscription.php#L81-L91 |
voryx/Thruway | Examples/Authentication/GithubCallbackServer/GithubCallbackAuthProvider.php | GithubCallbackAuthProvider.processAuthenticate | public function processAuthenticate($state, $extra = null)
{
if (!isset($state)) {
return ["FAILURE"];
}
//If we don't already have a promise for this state, create one
if (!isset($this->promises[$state])) {
$deferred = new Deferred();
$this->promises[$state] = $deferred;
}
return $this->promises[$state]->promise();
} | php | public function processAuthenticate($state, $extra = null)
{
if (!isset($state)) {
return ["FAILURE"];
}
//If we don't already have a promise for this state, create one
if (!isset($this->promises[$state])) {
$deferred = new Deferred();
$this->promises[$state] = $deferred;
}
return $this->promises[$state]->promise();
} | [
"public",
"function",
"processAuthenticate",
"(",
"$",
"state",
",",
"$",
"extra",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"state",
")",
")",
"{",
"return",
"[",
"\"FAILURE\"",
"]",
";",
"}",
"//If we don't already have a promise for this state, create one",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"promises",
"[",
"$",
"state",
"]",
")",
")",
"{",
"$",
"deferred",
"=",
"new",
"Deferred",
"(",
")",
";",
"$",
"this",
"->",
"promises",
"[",
"$",
"state",
"]",
"=",
"$",
"deferred",
";",
"}",
"return",
"$",
"this",
"->",
"promises",
"[",
"$",
"state",
"]",
"->",
"promise",
"(",
")",
";",
"}"
] | Process authenticate
@param mixed $state
@param mixed $extra
@return array | [
"Process",
"authenticate"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/Examples/Authentication/GithubCallbackServer/GithubCallbackAuthProvider.php#L71-L86 |
voryx/Thruway | Examples/Authentication/GithubCallbackServer/GithubCallbackAuthProvider.php | GithubCallbackAuthProvider.onHttpRequest | public function onHttpRequest(\React\Http\Request $request, $response)
{
if ($request->getPath() !== "/auth/github/callback") {
$response->writeHead(404, ['Content-Type' => 'text/plain']);
$response->end("Not Found");
return;
}
$query = $request->getQuery();
if (!isset($query['state']) || !isset($query['code'])) {
$response->writeHead(200, ['Content-Type' => 'text/plain']);
$response->end("No Code or State query params found");
return;
}
//If we don't already have a promise for this state, create one
if (!isset($this->promises[$query['state']])) {
$deferred = new Deferred();
$this->promises[$query['state']] = $deferred;
}
$accessToken = $this->getAccessToken($query['code']);
if ($accessToken) {
$email = $this->getEmails($accessToken)[0]->email;
$this->promises[$query['state']]->resolve(["SUCCESS", ["authid" => $email]]);
} else {
$this->promises[$query['state']]->resolve(["FAILURE"]);
}
$response->writeHead(200, ['Content-Type' => 'text/html']);
$response->end("<script>window.close();</script>");
} | php | public function onHttpRequest(\React\Http\Request $request, $response)
{
if ($request->getPath() !== "/auth/github/callback") {
$response->writeHead(404, ['Content-Type' => 'text/plain']);
$response->end("Not Found");
return;
}
$query = $request->getQuery();
if (!isset($query['state']) || !isset($query['code'])) {
$response->writeHead(200, ['Content-Type' => 'text/plain']);
$response->end("No Code or State query params found");
return;
}
//If we don't already have a promise for this state, create one
if (!isset($this->promises[$query['state']])) {
$deferred = new Deferred();
$this->promises[$query['state']] = $deferred;
}
$accessToken = $this->getAccessToken($query['code']);
if ($accessToken) {
$email = $this->getEmails($accessToken)[0]->email;
$this->promises[$query['state']]->resolve(["SUCCESS", ["authid" => $email]]);
} else {
$this->promises[$query['state']]->resolve(["FAILURE"]);
}
$response->writeHead(200, ['Content-Type' => 'text/html']);
$response->end("<script>window.close();</script>");
} | [
"public",
"function",
"onHttpRequest",
"(",
"\\",
"React",
"\\",
"Http",
"\\",
"Request",
"$",
"request",
",",
"$",
"response",
")",
"{",
"if",
"(",
"$",
"request",
"->",
"getPath",
"(",
")",
"!==",
"\"/auth/github/callback\"",
")",
"{",
"$",
"response",
"->",
"writeHead",
"(",
"404",
",",
"[",
"'Content-Type'",
"=>",
"'text/plain'",
"]",
")",
";",
"$",
"response",
"->",
"end",
"(",
"\"Not Found\"",
")",
";",
"return",
";",
"}",
"$",
"query",
"=",
"$",
"request",
"->",
"getQuery",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"query",
"[",
"'state'",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"query",
"[",
"'code'",
"]",
")",
")",
"{",
"$",
"response",
"->",
"writeHead",
"(",
"200",
",",
"[",
"'Content-Type'",
"=>",
"'text/plain'",
"]",
")",
";",
"$",
"response",
"->",
"end",
"(",
"\"No Code or State query params found\"",
")",
";",
"return",
";",
"}",
"//If we don't already have a promise for this state, create one",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"promises",
"[",
"$",
"query",
"[",
"'state'",
"]",
"]",
")",
")",
"{",
"$",
"deferred",
"=",
"new",
"Deferred",
"(",
")",
";",
"$",
"this",
"->",
"promises",
"[",
"$",
"query",
"[",
"'state'",
"]",
"]",
"=",
"$",
"deferred",
";",
"}",
"$",
"accessToken",
"=",
"$",
"this",
"->",
"getAccessToken",
"(",
"$",
"query",
"[",
"'code'",
"]",
")",
";",
"if",
"(",
"$",
"accessToken",
")",
"{",
"$",
"email",
"=",
"$",
"this",
"->",
"getEmails",
"(",
"$",
"accessToken",
")",
"[",
"0",
"]",
"->",
"email",
";",
"$",
"this",
"->",
"promises",
"[",
"$",
"query",
"[",
"'state'",
"]",
"]",
"->",
"resolve",
"(",
"[",
"\"SUCCESS\"",
",",
"[",
"\"authid\"",
"=>",
"$",
"email",
"]",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"promises",
"[",
"$",
"query",
"[",
"'state'",
"]",
"]",
"->",
"resolve",
"(",
"[",
"\"FAILURE\"",
"]",
")",
";",
"}",
"$",
"response",
"->",
"writeHead",
"(",
"200",
",",
"[",
"'Content-Type'",
"=>",
"'text/html'",
"]",
")",
";",
"$",
"response",
"->",
"end",
"(",
"\"<script>window.close();</script>\"",
")",
";",
"}"
] | Handle process on http request
@param \React\Http\Request $request
@param \React\Http\Request $response | [
"Handle",
"process",
"on",
"http",
"request"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/Examples/Authentication/GithubCallbackServer/GithubCallbackAuthProvider.php#L105-L139 |
voryx/Thruway | Examples/Authentication/GithubCallbackServer/GithubCallbackAuthProvider.php | GithubCallbackAuthProvider.getAccessToken | private function getAccessToken($code)
{
$data = [
"client_id" => $this->clientId,
"client_secret" => $this->clientSecret,
"code" => $code
];
$data_string = json_encode($data);
//This needs to be replaced with Guzzle or something async
$ch = curl_init('https://github.com/login/oauth/access_token');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt(
$ch,
CURLOPT_HTTPHEADER,
[
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string)
]
);
$result = curl_exec($ch);
parse_str($result, $resultArray);
if (isset($resultArray['access_token'])) {
return $resultArray['access_token'];
} else {
return false;
}
} | php | private function getAccessToken($code)
{
$data = [
"client_id" => $this->clientId,
"client_secret" => $this->clientSecret,
"code" => $code
];
$data_string = json_encode($data);
//This needs to be replaced with Guzzle or something async
$ch = curl_init('https://github.com/login/oauth/access_token');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt(
$ch,
CURLOPT_HTTPHEADER,
[
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string)
]
);
$result = curl_exec($ch);
parse_str($result, $resultArray);
if (isset($resultArray['access_token'])) {
return $resultArray['access_token'];
} else {
return false;
}
} | [
"private",
"function",
"getAccessToken",
"(",
"$",
"code",
")",
"{",
"$",
"data",
"=",
"[",
"\"client_id\"",
"=>",
"$",
"this",
"->",
"clientId",
",",
"\"client_secret\"",
"=>",
"$",
"this",
"->",
"clientSecret",
",",
"\"code\"",
"=>",
"$",
"code",
"]",
";",
"$",
"data_string",
"=",
"json_encode",
"(",
"$",
"data",
")",
";",
"//This needs to be replaced with Guzzle or something async",
"$",
"ch",
"=",
"curl_init",
"(",
"'https://github.com/login/oauth/access_token'",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_CUSTOMREQUEST",
",",
"\"POST\"",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_POSTFIELDS",
",",
"$",
"data_string",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_RETURNTRANSFER",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_HTTPHEADER",
",",
"[",
"'Content-Type: application/json'",
",",
"'Content-Length: '",
".",
"strlen",
"(",
"$",
"data_string",
")",
"]",
")",
";",
"$",
"result",
"=",
"curl_exec",
"(",
"$",
"ch",
")",
";",
"parse_str",
"(",
"$",
"result",
",",
"$",
"resultArray",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"resultArray",
"[",
"'access_token'",
"]",
")",
")",
"{",
"return",
"$",
"resultArray",
"[",
"'access_token'",
"]",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Get access token from code
@param string $code
@return string|boolean | [
"Get",
"access",
"token",
"from",
"code"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/Examples/Authentication/GithubCallbackServer/GithubCallbackAuthProvider.php#L147-L179 |
voryx/Thruway | Examples/Authentication/GithubCallbackServer/GithubCallbackAuthProvider.php | GithubCallbackAuthProvider.getEmails | private function getEmails($accessToken)
{
$ch = curl_init("https://api.github.com/user/emails?access_token={$accessToken}");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt(
$ch,
CURLOPT_HTTPHEADER,
['Content-Type: application/json', 'User-Agent: Thruway-WAMP-App']
);
$result = curl_exec($ch);
return json_decode($result);
} | php | private function getEmails($accessToken)
{
$ch = curl_init("https://api.github.com/user/emails?access_token={$accessToken}");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt(
$ch,
CURLOPT_HTTPHEADER,
['Content-Type: application/json', 'User-Agent: Thruway-WAMP-App']
);
$result = curl_exec($ch);
return json_decode($result);
} | [
"private",
"function",
"getEmails",
"(",
"$",
"accessToken",
")",
"{",
"$",
"ch",
"=",
"curl_init",
"(",
"\"https://api.github.com/user/emails?access_token={$accessToken}\"",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_CUSTOMREQUEST",
",",
"\"GET\"",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_RETURNTRANSFER",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_HTTPHEADER",
",",
"[",
"'Content-Type: application/json'",
",",
"'User-Agent: Thruway-WAMP-App'",
"]",
")",
";",
"$",
"result",
"=",
"curl_exec",
"(",
"$",
"ch",
")",
";",
"return",
"json_decode",
"(",
"$",
"result",
")",
";",
"}"
] | Get list email from accesstokens
@param string $accessToken
@return mixed | [
"Get",
"list",
"email",
"from",
"accesstokens"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/Examples/Authentication/GithubCallbackServer/GithubCallbackAuthProvider.php#L187-L203 |
voryx/Thruway | Examples/RawSocket/RawSocketClient.php | RawSocketClient.onSessionStart | public function onSessionStart($session, $transport)
{
$session->register('com.example.add2', [$this, 'add2'])
->then(function () use ($session) {
echo "Registered RPC\n";
$session->call('com.example.add2', [2, 3])
->then(function ($res) {
echo "Got result: " . $res[0] . "\n";
$this->setAttemptRetry(false);
$this->session->shutdown();
});
});
} | php | public function onSessionStart($session, $transport)
{
$session->register('com.example.add2', [$this, 'add2'])
->then(function () use ($session) {
echo "Registered RPC\n";
$session->call('com.example.add2', [2, 3])
->then(function ($res) {
echo "Got result: " . $res[0] . "\n";
$this->setAttemptRetry(false);
$this->session->shutdown();
});
});
} | [
"public",
"function",
"onSessionStart",
"(",
"$",
"session",
",",
"$",
"transport",
")",
"{",
"$",
"session",
"->",
"register",
"(",
"'com.example.add2'",
",",
"[",
"$",
"this",
",",
"'add2'",
"]",
")",
"->",
"then",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"session",
")",
"{",
"echo",
"\"Registered RPC\\n\"",
";",
"$",
"session",
"->",
"call",
"(",
"'com.example.add2'",
",",
"[",
"2",
",",
"3",
"]",
")",
"->",
"then",
"(",
"function",
"(",
"$",
"res",
")",
"{",
"echo",
"\"Got result: \"",
".",
"$",
"res",
"[",
"0",
"]",
".",
"\"\\n\"",
";",
"$",
"this",
"->",
"setAttemptRetry",
"(",
"false",
")",
";",
"$",
"this",
"->",
"session",
"->",
"shutdown",
"(",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Handle on session start
@param \Thruway\ClientSession $session
@param \Thruway\Transport\TransportInterface $transport | [
"Handle",
"on",
"session",
"start"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/Examples/RawSocket/RawSocketClient.php#L14-L28 |
voryx/Thruway | Examples/100Clients/CallingClient.php | CallingClient.onSessionStart | public function onSessionStart($session, $transport)
{
$this->thePromise->then(function () use ($session) {
$session->call('com.example.thefunction0', [])
->then(function ($res) {
echo "Done.\n";
exit;
});
});
} | php | public function onSessionStart($session, $transport)
{
$this->thePromise->then(function () use ($session) {
$session->call('com.example.thefunction0', [])
->then(function ($res) {
echo "Done.\n";
exit;
});
});
} | [
"public",
"function",
"onSessionStart",
"(",
"$",
"session",
",",
"$",
"transport",
")",
"{",
"$",
"this",
"->",
"thePromise",
"->",
"then",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"session",
")",
"{",
"$",
"session",
"->",
"call",
"(",
"'com.example.thefunction0'",
",",
"[",
"]",
")",
"->",
"then",
"(",
"function",
"(",
"$",
"res",
")",
"{",
"echo",
"\"Done.\\n\"",
";",
"exit",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] | Handle on session start
@param \Thruway\ClientSession $session
@param \Thruway\Transport\TransportInterface $transport | [
"Handle",
"on",
"session",
"start"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/Examples/100Clients/CallingClient.php#L33-L42 |
voryx/Thruway | src/Authentication/WampCraAuthProvider.php | WampCraAuthProvider.processHello | public function processHello(array $args)
{
$helloMsg = array_shift($args);
$sessionInfo = array_shift($args);
if (!is_array($helloMsg)) {
return ['ERROR'];
}
if (!is_object($sessionInfo)) {
return ['ERROR'];
}
$helloMsg = Message::createMessageFromArray($helloMsg);
if (!$helloMsg instanceof HelloMessage
|| !$sessionInfo
|| !isset($helloMsg->getDetails()->authid)
|| !$this->getUserDb() instanceof WampCraUserDbInterface
) {
return ['ERROR'];
}
$authid = $helloMsg->getDetails()->authid;
$user = $this->getUserDb()->get($authid);
if (!$user) {
return ['FAILURE'];
}
// create a challenge
$nonce = bin2hex(openssl_random_pseudo_bytes(22));
$authRole = 'user';
$authMethod = 'wampcra';
$authProvider = 'userdb';
$now = new \DateTime();
$timeStamp = $now->format($now::ISO8601);
if (!isset($sessionInfo->sessionId)) {
return ['ERROR'];
}
$sessionId = $sessionInfo->sessionId;
$challenge = [
'authid' => $authid,
'authrole' => $authRole,
'authprovider' => $authProvider,
'authmethod' => $authMethod,
'nonce' => $nonce,
'timestamp' => $timeStamp,
'session' => $sessionId
];
$serializedChallenge = json_encode($challenge);
$challengeDetails = [
'challenge' => $serializedChallenge,
'challenge_method' => $this->getMethodName()
];
if ($user['salt'] !== null) {
// we are using salty password
$saltInfo = [
'salt' => $user['salt'],
'keylen' => 32,
'iterations' => 1000
];
$challengeDetails = array_merge($challengeDetails, $saltInfo);
}
return ['CHALLENGE', (object)$challengeDetails];
} | php | public function processHello(array $args)
{
$helloMsg = array_shift($args);
$sessionInfo = array_shift($args);
if (!is_array($helloMsg)) {
return ['ERROR'];
}
if (!is_object($sessionInfo)) {
return ['ERROR'];
}
$helloMsg = Message::createMessageFromArray($helloMsg);
if (!$helloMsg instanceof HelloMessage
|| !$sessionInfo
|| !isset($helloMsg->getDetails()->authid)
|| !$this->getUserDb() instanceof WampCraUserDbInterface
) {
return ['ERROR'];
}
$authid = $helloMsg->getDetails()->authid;
$user = $this->getUserDb()->get($authid);
if (!$user) {
return ['FAILURE'];
}
// create a challenge
$nonce = bin2hex(openssl_random_pseudo_bytes(22));
$authRole = 'user';
$authMethod = 'wampcra';
$authProvider = 'userdb';
$now = new \DateTime();
$timeStamp = $now->format($now::ISO8601);
if (!isset($sessionInfo->sessionId)) {
return ['ERROR'];
}
$sessionId = $sessionInfo->sessionId;
$challenge = [
'authid' => $authid,
'authrole' => $authRole,
'authprovider' => $authProvider,
'authmethod' => $authMethod,
'nonce' => $nonce,
'timestamp' => $timeStamp,
'session' => $sessionId
];
$serializedChallenge = json_encode($challenge);
$challengeDetails = [
'challenge' => $serializedChallenge,
'challenge_method' => $this->getMethodName()
];
if ($user['salt'] !== null) {
// we are using salty password
$saltInfo = [
'salt' => $user['salt'],
'keylen' => 32,
'iterations' => 1000
];
$challengeDetails = array_merge($challengeDetails, $saltInfo);
}
return ['CHALLENGE', (object)$challengeDetails];
} | [
"public",
"function",
"processHello",
"(",
"array",
"$",
"args",
")",
"{",
"$",
"helloMsg",
"=",
"array_shift",
"(",
"$",
"args",
")",
";",
"$",
"sessionInfo",
"=",
"array_shift",
"(",
"$",
"args",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"helloMsg",
")",
")",
"{",
"return",
"[",
"'ERROR'",
"]",
";",
"}",
"if",
"(",
"!",
"is_object",
"(",
"$",
"sessionInfo",
")",
")",
"{",
"return",
"[",
"'ERROR'",
"]",
";",
"}",
"$",
"helloMsg",
"=",
"Message",
"::",
"createMessageFromArray",
"(",
"$",
"helloMsg",
")",
";",
"if",
"(",
"!",
"$",
"helloMsg",
"instanceof",
"HelloMessage",
"||",
"!",
"$",
"sessionInfo",
"||",
"!",
"isset",
"(",
"$",
"helloMsg",
"->",
"getDetails",
"(",
")",
"->",
"authid",
")",
"||",
"!",
"$",
"this",
"->",
"getUserDb",
"(",
")",
"instanceof",
"WampCraUserDbInterface",
")",
"{",
"return",
"[",
"'ERROR'",
"]",
";",
"}",
"$",
"authid",
"=",
"$",
"helloMsg",
"->",
"getDetails",
"(",
")",
"->",
"authid",
";",
"$",
"user",
"=",
"$",
"this",
"->",
"getUserDb",
"(",
")",
"->",
"get",
"(",
"$",
"authid",
")",
";",
"if",
"(",
"!",
"$",
"user",
")",
"{",
"return",
"[",
"'FAILURE'",
"]",
";",
"}",
"// create a challenge",
"$",
"nonce",
"=",
"bin2hex",
"(",
"openssl_random_pseudo_bytes",
"(",
"22",
")",
")",
";",
"$",
"authRole",
"=",
"'user'",
";",
"$",
"authMethod",
"=",
"'wampcra'",
";",
"$",
"authProvider",
"=",
"'userdb'",
";",
"$",
"now",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"$",
"timeStamp",
"=",
"$",
"now",
"->",
"format",
"(",
"$",
"now",
"::",
"ISO8601",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"sessionInfo",
"->",
"sessionId",
")",
")",
"{",
"return",
"[",
"'ERROR'",
"]",
";",
"}",
"$",
"sessionId",
"=",
"$",
"sessionInfo",
"->",
"sessionId",
";",
"$",
"challenge",
"=",
"[",
"'authid'",
"=>",
"$",
"authid",
",",
"'authrole'",
"=>",
"$",
"authRole",
",",
"'authprovider'",
"=>",
"$",
"authProvider",
",",
"'authmethod'",
"=>",
"$",
"authMethod",
",",
"'nonce'",
"=>",
"$",
"nonce",
",",
"'timestamp'",
"=>",
"$",
"timeStamp",
",",
"'session'",
"=>",
"$",
"sessionId",
"]",
";",
"$",
"serializedChallenge",
"=",
"json_encode",
"(",
"$",
"challenge",
")",
";",
"$",
"challengeDetails",
"=",
"[",
"'challenge'",
"=>",
"$",
"serializedChallenge",
",",
"'challenge_method'",
"=>",
"$",
"this",
"->",
"getMethodName",
"(",
")",
"]",
";",
"if",
"(",
"$",
"user",
"[",
"'salt'",
"]",
"!==",
"null",
")",
"{",
"// we are using salty password",
"$",
"saltInfo",
"=",
"[",
"'salt'",
"=>",
"$",
"user",
"[",
"'salt'",
"]",
",",
"'keylen'",
"=>",
"32",
",",
"'iterations'",
"=>",
"1000",
"]",
";",
"$",
"challengeDetails",
"=",
"array_merge",
"(",
"$",
"challengeDetails",
",",
"$",
"saltInfo",
")",
";",
"}",
"return",
"[",
"'CHALLENGE'",
",",
"(",
"object",
")",
"$",
"challengeDetails",
"]",
";",
"}"
] | The arguments given by the server are the actual hello message ($args[0])
and some session information ($args[1])
The session information is an associative array that contains the sessionId and realm
@param array $args
@return array | [
"The",
"arguments",
"given",
"by",
"the",
"server",
"are",
"the",
"actual",
"hello",
"message",
"(",
"$args",
"[",
"0",
"]",
")",
"and",
"some",
"session",
"information",
"(",
"$args",
"[",
"1",
"]",
")"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Authentication/WampCraAuthProvider.php#L38-L110 |
voryx/Thruway | src/Authentication/WampCraAuthProvider.php | WampCraAuthProvider.processAuthenticate | public function processAuthenticate($signature, $extra = null)
{
$challenge = $this->getChallengeFromExtra($extra);
if (!$challenge
|| !isset($challenge->authid)
|| !$this->getUserDb() instanceof WampCraUserDbInterface
) {
return ['FAILURE'];
}
$authid = $challenge->authid;
$user = $this->getUserDb()->get($authid);
if (!$user) {
return ['FAILURE'];
}
$keyToUse = $user['key'];
$token = base64_encode(hash_hmac('sha256', json_encode($challenge), $keyToUse, true));
if ($token != $signature) {
return ['FAILURE'];
}
$authDetails = [
'authmethod' => 'wampcra',
'authrole' => 'user',
'authid' => $challenge->authid,
'authprovider' => $challenge->authprovider
];
return ['SUCCESS', $authDetails];
} | php | public function processAuthenticate($signature, $extra = null)
{
$challenge = $this->getChallengeFromExtra($extra);
if (!$challenge
|| !isset($challenge->authid)
|| !$this->getUserDb() instanceof WampCraUserDbInterface
) {
return ['FAILURE'];
}
$authid = $challenge->authid;
$user = $this->getUserDb()->get($authid);
if (!$user) {
return ['FAILURE'];
}
$keyToUse = $user['key'];
$token = base64_encode(hash_hmac('sha256', json_encode($challenge), $keyToUse, true));
if ($token != $signature) {
return ['FAILURE'];
}
$authDetails = [
'authmethod' => 'wampcra',
'authrole' => 'user',
'authid' => $challenge->authid,
'authprovider' => $challenge->authprovider
];
return ['SUCCESS', $authDetails];
} | [
"public",
"function",
"processAuthenticate",
"(",
"$",
"signature",
",",
"$",
"extra",
"=",
"null",
")",
"{",
"$",
"challenge",
"=",
"$",
"this",
"->",
"getChallengeFromExtra",
"(",
"$",
"extra",
")",
";",
"if",
"(",
"!",
"$",
"challenge",
"||",
"!",
"isset",
"(",
"$",
"challenge",
"->",
"authid",
")",
"||",
"!",
"$",
"this",
"->",
"getUserDb",
"(",
")",
"instanceof",
"WampCraUserDbInterface",
")",
"{",
"return",
"[",
"'FAILURE'",
"]",
";",
"}",
"$",
"authid",
"=",
"$",
"challenge",
"->",
"authid",
";",
"$",
"user",
"=",
"$",
"this",
"->",
"getUserDb",
"(",
")",
"->",
"get",
"(",
"$",
"authid",
")",
";",
"if",
"(",
"!",
"$",
"user",
")",
"{",
"return",
"[",
"'FAILURE'",
"]",
";",
"}",
"$",
"keyToUse",
"=",
"$",
"user",
"[",
"'key'",
"]",
";",
"$",
"token",
"=",
"base64_encode",
"(",
"hash_hmac",
"(",
"'sha256'",
",",
"json_encode",
"(",
"$",
"challenge",
")",
",",
"$",
"keyToUse",
",",
"true",
")",
")",
";",
"if",
"(",
"$",
"token",
"!=",
"$",
"signature",
")",
"{",
"return",
"[",
"'FAILURE'",
"]",
";",
"}",
"$",
"authDetails",
"=",
"[",
"'authmethod'",
"=>",
"'wampcra'",
",",
"'authrole'",
"=>",
"'user'",
",",
"'authid'",
"=>",
"$",
"challenge",
"->",
"authid",
",",
"'authprovider'",
"=>",
"$",
"challenge",
"->",
"authprovider",
"]",
";",
"return",
"[",
"'SUCCESS'",
",",
"$",
"authDetails",
"]",
";",
"}"
] | Process authenticate
@param mixed $signature
@param mixed $extra
@return array | [
"Process",
"authenticate"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Authentication/WampCraAuthProvider.php#L119-L154 |
voryx/Thruway | src/Authentication/WampCraAuthProvider.php | WampCraAuthProvider.getChallengeFromExtra | private function getChallengeFromExtra($extra)
{
return (is_object($extra)
&& isset($extra->challenge_details)
&& is_object($extra->challenge_details)
&& isset($extra->challenge_details->challenge))
? json_decode($extra->challenge_details->challenge)
: false;
} | php | private function getChallengeFromExtra($extra)
{
return (is_object($extra)
&& isset($extra->challenge_details)
&& is_object($extra->challenge_details)
&& isset($extra->challenge_details->challenge))
? json_decode($extra->challenge_details->challenge)
: false;
} | [
"private",
"function",
"getChallengeFromExtra",
"(",
"$",
"extra",
")",
"{",
"return",
"(",
"is_object",
"(",
"$",
"extra",
")",
"&&",
"isset",
"(",
"$",
"extra",
"->",
"challenge_details",
")",
"&&",
"is_object",
"(",
"$",
"extra",
"->",
"challenge_details",
")",
"&&",
"isset",
"(",
"$",
"extra",
"->",
"challenge_details",
"->",
"challenge",
")",
")",
"?",
"json_decode",
"(",
"$",
"extra",
"->",
"challenge_details",
"->",
"challenge",
")",
":",
"false",
";",
"}"
] | Gets the Challenge Message from the extra object
@param $extra
@return bool | \stdClass | [
"Gets",
"the",
"Challenge",
"Message",
"from",
"the",
"extra",
"object"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Authentication/WampCraAuthProvider.php#L181-L189 |
voryx/Thruway | Examples/Authentication/Facebook/FacebookAuthProvider.php | FacebookAuthProvider.processAuthenticate | public function processAuthenticate($signature, $extra = null)
{
\Facebook\FacebookSession::setDefaultApplication($this->appId, $this->appSecret);
$session = new \Facebook\FacebookSession($signature);
$sessionInfo = $session->getSessionInfo();
//Make sure that we received a valid token
if ($sessionInfo->isValid()) {
return ["SUCCESS"];
} else {
return ["FAILURE"];
}
} | php | public function processAuthenticate($signature, $extra = null)
{
\Facebook\FacebookSession::setDefaultApplication($this->appId, $this->appSecret);
$session = new \Facebook\FacebookSession($signature);
$sessionInfo = $session->getSessionInfo();
//Make sure that we received a valid token
if ($sessionInfo->isValid()) {
return ["SUCCESS"];
} else {
return ["FAILURE"];
}
} | [
"public",
"function",
"processAuthenticate",
"(",
"$",
"signature",
",",
"$",
"extra",
"=",
"null",
")",
"{",
"\\",
"Facebook",
"\\",
"FacebookSession",
"::",
"setDefaultApplication",
"(",
"$",
"this",
"->",
"appId",
",",
"$",
"this",
"->",
"appSecret",
")",
";",
"$",
"session",
"=",
"new",
"\\",
"Facebook",
"\\",
"FacebookSession",
"(",
"$",
"signature",
")",
";",
"$",
"sessionInfo",
"=",
"$",
"session",
"->",
"getSessionInfo",
"(",
")",
";",
"//Make sure that we received a valid token",
"if",
"(",
"$",
"sessionInfo",
"->",
"isValid",
"(",
")",
")",
"{",
"return",
"[",
"\"SUCCESS\"",
"]",
";",
"}",
"else",
"{",
"return",
"[",
"\"FAILURE\"",
"]",
";",
"}",
"}"
] | process authenticate
@param mixed $signature
@param mixed $extra
@return array | [
"process",
"authenticate"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/Examples/Authentication/Facebook/FacebookAuthProvider.php#L56-L70 |
voryx/Thruway | src/Peer/Router.php | Router.start | public function start($runLoop = true)
{
Logger::info($this, 'Starting router');
if ($this->loop === null) {
throw new \Exception('Loop is null');
}
$this->started = true;
$this->eventDispatcher->dispatch('router.start', new RouterStartEvent());
if ($runLoop) {
Logger::info($this, 'Starting loop');
$this->loop->run();
}
} | php | public function start($runLoop = true)
{
Logger::info($this, 'Starting router');
if ($this->loop === null) {
throw new \Exception('Loop is null');
}
$this->started = true;
$this->eventDispatcher->dispatch('router.start', new RouterStartEvent());
if ($runLoop) {
Logger::info($this, 'Starting loop');
$this->loop->run();
}
} | [
"public",
"function",
"start",
"(",
"$",
"runLoop",
"=",
"true",
")",
"{",
"Logger",
"::",
"info",
"(",
"$",
"this",
",",
"'Starting router'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"loop",
"===",
"null",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Loop is null'",
")",
";",
"}",
"$",
"this",
"->",
"started",
"=",
"true",
";",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatch",
"(",
"'router.start'",
",",
"new",
"RouterStartEvent",
"(",
")",
")",
";",
"if",
"(",
"$",
"runLoop",
")",
"{",
"Logger",
"::",
"info",
"(",
"$",
"this",
",",
"'Starting loop'",
")",
";",
"$",
"this",
"->",
"loop",
"->",
"run",
"(",
")",
";",
"}",
"}"
] | Start router
@param bool $runLoop
@throws \Exception | [
"Start",
"router"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Peer/Router.php#L118-L133 |
voryx/Thruway | src/Peer/Router.php | Router.onClose | public function onClose(TransportInterface $transport)
{
Logger::debug($this, 'onClose from ' . json_encode($transport->getTransportDetails()));
$this->sessions->detach($transport);
} | php | public function onClose(TransportInterface $transport)
{
Logger::debug($this, 'onClose from ' . json_encode($transport->getTransportDetails()));
$this->sessions->detach($transport);
} | [
"public",
"function",
"onClose",
"(",
"TransportInterface",
"$",
"transport",
")",
"{",
"Logger",
"::",
"debug",
"(",
"$",
"this",
",",
"'onClose from '",
".",
"json_encode",
"(",
"$",
"transport",
"->",
"getTransportDetails",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"sessions",
"->",
"detach",
"(",
"$",
"transport",
")",
";",
"}"
] | Handle close transport
@param \Thruway\Transport\TransportInterface $transport | [
"Handle",
"close",
"transport"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Peer/Router.php#L148-L153 |
voryx/Thruway | src/Peer/Router.php | Router.getSessionBySessionId | public function getSessionBySessionId($sessionId)
{
if (!is_scalar($sessionId)) {
return false;
}
return isset($this->sessions[$sessionId]) ? $this->sessions[$sessionId] : false;
} | php | public function getSessionBySessionId($sessionId)
{
if (!is_scalar($sessionId)) {
return false;
}
return isset($this->sessions[$sessionId]) ? $this->sessions[$sessionId] : false;
} | [
"public",
"function",
"getSessionBySessionId",
"(",
"$",
"sessionId",
")",
"{",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"sessionId",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"isset",
"(",
"$",
"this",
"->",
"sessions",
"[",
"$",
"sessionId",
"]",
")",
"?",
"$",
"this",
"->",
"sessions",
"[",
"$",
"sessionId",
"]",
":",
"false",
";",
"}"
] | Get session by session ID
@param int $sessionId
@return \Thruway\Session|boolean | [
"Get",
"session",
"by",
"session",
"ID"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Peer/Router.php#L216-L223 |
voryx/Thruway | src/Peer/Router.php | Router.managerGetRealms | public function managerGetRealms()
{
$theRealms = [];
foreach ($this->realmManager->getRealms() as $realm) {
/* @var $realm \Thruway\Realm */
$theRealms[] = [
'name' => $realm->getRealmName()
];
}
return [$theRealms];
} | php | public function managerGetRealms()
{
$theRealms = [];
foreach ($this->realmManager->getRealms() as $realm) {
/* @var $realm \Thruway\Realm */
$theRealms[] = [
'name' => $realm->getRealmName()
];
}
return [$theRealms];
} | [
"public",
"function",
"managerGetRealms",
"(",
")",
"{",
"$",
"theRealms",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"realmManager",
"->",
"getRealms",
"(",
")",
"as",
"$",
"realm",
")",
"{",
"/* @var $realm \\Thruway\\Realm */",
"$",
"theRealms",
"[",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"realm",
"->",
"getRealmName",
"(",
")",
"]",
";",
"}",
"return",
"[",
"$",
"theRealms",
"]",
";",
"}"
] | Get list realms
@return array | [
"Get",
"list",
"realms"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Peer/Router.php#L302-L314 |
voryx/Thruway | src/Peer/Router.php | Router.registerModule | public function registerModule(RouterModuleInterface $module)
{
$module->initModule($this, $this->getLoop());
$this->eventDispatcher->addSubscriber($module);
} | php | public function registerModule(RouterModuleInterface $module)
{
$module->initModule($this, $this->getLoop());
$this->eventDispatcher->addSubscriber($module);
} | [
"public",
"function",
"registerModule",
"(",
"RouterModuleInterface",
"$",
"module",
")",
"{",
"$",
"module",
"->",
"initModule",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"getLoop",
"(",
")",
")",
";",
"$",
"this",
"->",
"eventDispatcher",
"->",
"addSubscriber",
"(",
"$",
"module",
")",
";",
"}"
] | Registers a RouterModule
@param RouterModuleInterface $module | [
"Registers",
"a",
"RouterModule"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Peer/Router.php#L321-L325 |
voryx/Thruway | src/Registration.php | Registration.createRegistrationFromRegisterMessage | public static function createRegistrationFromRegisterMessage(Session $session, RegisterMessage $msg)
{
$registration = new self($session, $msg->getProcedureName());
$options = $msg->getOptions();
if (isset($options->disclose_caller) && $options->disclose_caller === true) {
$registration->setDiscloseCaller(true);
}
if (isset($options->invoke)) {
$registration->setInvokeType($options->invoke);
} else {
if (isset($options->thruway_multiregister) && $options->thruway_multiregister === true) {
$registration->setInvokeType(self::THRUWAY_REGISTRATION);
} else {
$registration->setInvokeType(self::SINGLE_REGISTRATION);
}
}
return $registration;
} | php | public static function createRegistrationFromRegisterMessage(Session $session, RegisterMessage $msg)
{
$registration = new self($session, $msg->getProcedureName());
$options = $msg->getOptions();
if (isset($options->disclose_caller) && $options->disclose_caller === true) {
$registration->setDiscloseCaller(true);
}
if (isset($options->invoke)) {
$registration->setInvokeType($options->invoke);
} else {
if (isset($options->thruway_multiregister) && $options->thruway_multiregister === true) {
$registration->setInvokeType(self::THRUWAY_REGISTRATION);
} else {
$registration->setInvokeType(self::SINGLE_REGISTRATION);
}
}
return $registration;
} | [
"public",
"static",
"function",
"createRegistrationFromRegisterMessage",
"(",
"Session",
"$",
"session",
",",
"RegisterMessage",
"$",
"msg",
")",
"{",
"$",
"registration",
"=",
"new",
"self",
"(",
"$",
"session",
",",
"$",
"msg",
"->",
"getProcedureName",
"(",
")",
")",
";",
"$",
"options",
"=",
"$",
"msg",
"->",
"getOptions",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"->",
"disclose_caller",
")",
"&&",
"$",
"options",
"->",
"disclose_caller",
"===",
"true",
")",
"{",
"$",
"registration",
"->",
"setDiscloseCaller",
"(",
"true",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"options",
"->",
"invoke",
")",
")",
"{",
"$",
"registration",
"->",
"setInvokeType",
"(",
"$",
"options",
"->",
"invoke",
")",
";",
"}",
"else",
"{",
"if",
"(",
"isset",
"(",
"$",
"options",
"->",
"thruway_multiregister",
")",
"&&",
"$",
"options",
"->",
"thruway_multiregister",
"===",
"true",
")",
"{",
"$",
"registration",
"->",
"setInvokeType",
"(",
"self",
"::",
"THRUWAY_REGISTRATION",
")",
";",
"}",
"else",
"{",
"$",
"registration",
"->",
"setInvokeType",
"(",
"self",
"::",
"SINGLE_REGISTRATION",
")",
";",
"}",
"}",
"return",
"$",
"registration",
";",
"}"
] | Create Registration from RegisterMessage
@param \Thruway\Session $session
@param \Thruway\Message\RegisterMessage $msg
@return \Thruway\Registration | [
"Create",
"Registration",
"from",
"RegisterMessage"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Registration.php#L138-L158 |
voryx/Thruway | src/Registration.php | Registration.processCall | public function processCall(Call $call)
{
if ($call->getRegistration() !== null) {
throw new \Exception('Registration already set when asked to process call');
}
$call->setRegistration($this);
$this->calls[] = $call;
$this->session->incPendingCallCount();
$callCount = count($this->calls);
if ($callCount === 1) {
// we just became busy
$this->busyStart = microtime(true);
}
if ($callCount > $this->maxSimultaneousCalls) {
$this->maxSimultaneousCalls = $callCount;
}
$this->invocationCount++;
$this->lastCallStartedAt = new \DateTime();
$this->getSession()->sendMessage($call->getInvocationMessage());
} | php | public function processCall(Call $call)
{
if ($call->getRegistration() !== null) {
throw new \Exception('Registration already set when asked to process call');
}
$call->setRegistration($this);
$this->calls[] = $call;
$this->session->incPendingCallCount();
$callCount = count($this->calls);
if ($callCount === 1) {
// we just became busy
$this->busyStart = microtime(true);
}
if ($callCount > $this->maxSimultaneousCalls) {
$this->maxSimultaneousCalls = $callCount;
}
$this->invocationCount++;
$this->lastCallStartedAt = new \DateTime();
$this->getSession()->sendMessage($call->getInvocationMessage());
} | [
"public",
"function",
"processCall",
"(",
"Call",
"$",
"call",
")",
"{",
"if",
"(",
"$",
"call",
"->",
"getRegistration",
"(",
")",
"!==",
"null",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Registration already set when asked to process call'",
")",
";",
"}",
"$",
"call",
"->",
"setRegistration",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"calls",
"[",
"]",
"=",
"$",
"call",
";",
"$",
"this",
"->",
"session",
"->",
"incPendingCallCount",
"(",
")",
";",
"$",
"callCount",
"=",
"count",
"(",
"$",
"this",
"->",
"calls",
")",
";",
"if",
"(",
"$",
"callCount",
"===",
"1",
")",
"{",
"// we just became busy",
"$",
"this",
"->",
"busyStart",
"=",
"microtime",
"(",
"true",
")",
";",
"}",
"if",
"(",
"$",
"callCount",
">",
"$",
"this",
"->",
"maxSimultaneousCalls",
")",
"{",
"$",
"this",
"->",
"maxSimultaneousCalls",
"=",
"$",
"callCount",
";",
"}",
"$",
"this",
"->",
"invocationCount",
"++",
";",
"$",
"this",
"->",
"lastCallStartedAt",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"$",
"this",
"->",
"getSession",
"(",
")",
"->",
"sendMessage",
"(",
"$",
"call",
"->",
"getInvocationMessage",
"(",
")",
")",
";",
"}"
] | Process call
@param Call $call
@throws \Exception | [
"Process",
"call"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Registration.php#L225-L247 |
voryx/Thruway | src/Registration.php | Registration.getCallByRequestId | public function getCallByRequestId($requestId)
{
/** @var Call $call */
foreach ($this->calls as $call) {
if ($call->getInvocationMessage()->getRequestId() === $requestId) {
return $call;
}
}
return false;
} | php | public function getCallByRequestId($requestId)
{
/** @var Call $call */
foreach ($this->calls as $call) {
if ($call->getInvocationMessage()->getRequestId() === $requestId) {
return $call;
}
}
return false;
} | [
"public",
"function",
"getCallByRequestId",
"(",
"$",
"requestId",
")",
"{",
"/** @var Call $call */",
"foreach",
"(",
"$",
"this",
"->",
"calls",
"as",
"$",
"call",
")",
"{",
"if",
"(",
"$",
"call",
"->",
"getInvocationMessage",
"(",
")",
"->",
"getRequestId",
"(",
")",
"===",
"$",
"requestId",
")",
"{",
"return",
"$",
"call",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Get call by request ID
@param int $requestId
@return boolean | [
"Get",
"call",
"by",
"request",
"ID"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Registration.php#L255-L265 |
voryx/Thruway | src/Registration.php | Registration.removeCall | public function removeCall($callToRemove)
{
/* @var $call \Thruway\Call */
foreach ($this->calls as $i => $call) {
if ($callToRemove === $call) {
array_splice($this->calls, $i, 1);
$this->session->decPendingCallCount();
$callEnd = microtime(true);
// average call time
$callsInAverage = $this->invocationCount - count($this->calls) - 1;
// add this call time into the total
$this->completedCallTimeTotal += $callEnd - $call->getCallStart();
$callsInAverage++;
$this->invocationAverageTime = ((float)$this->completedCallTimeTotal) / $callsInAverage;
if (count($this->calls) == 0) {
$this->lastIdledAt = new \DateTime();
if ($this->busyStart !== null) {
$this->busyTime = $this->busyTime + ($callEnd - $this->busyStart);
$this->busyStart = null;
}
}
}
}
} | php | public function removeCall($callToRemove)
{
/* @var $call \Thruway\Call */
foreach ($this->calls as $i => $call) {
if ($callToRemove === $call) {
array_splice($this->calls, $i, 1);
$this->session->decPendingCallCount();
$callEnd = microtime(true);
// average call time
$callsInAverage = $this->invocationCount - count($this->calls) - 1;
// add this call time into the total
$this->completedCallTimeTotal += $callEnd - $call->getCallStart();
$callsInAverage++;
$this->invocationAverageTime = ((float)$this->completedCallTimeTotal) / $callsInAverage;
if (count($this->calls) == 0) {
$this->lastIdledAt = new \DateTime();
if ($this->busyStart !== null) {
$this->busyTime = $this->busyTime + ($callEnd - $this->busyStart);
$this->busyStart = null;
}
}
}
}
} | [
"public",
"function",
"removeCall",
"(",
"$",
"callToRemove",
")",
"{",
"/* @var $call \\Thruway\\Call */",
"foreach",
"(",
"$",
"this",
"->",
"calls",
"as",
"$",
"i",
"=>",
"$",
"call",
")",
"{",
"if",
"(",
"$",
"callToRemove",
"===",
"$",
"call",
")",
"{",
"array_splice",
"(",
"$",
"this",
"->",
"calls",
",",
"$",
"i",
",",
"1",
")",
";",
"$",
"this",
"->",
"session",
"->",
"decPendingCallCount",
"(",
")",
";",
"$",
"callEnd",
"=",
"microtime",
"(",
"true",
")",
";",
"// average call time",
"$",
"callsInAverage",
"=",
"$",
"this",
"->",
"invocationCount",
"-",
"count",
"(",
"$",
"this",
"->",
"calls",
")",
"-",
"1",
";",
"// add this call time into the total",
"$",
"this",
"->",
"completedCallTimeTotal",
"+=",
"$",
"callEnd",
"-",
"$",
"call",
"->",
"getCallStart",
"(",
")",
";",
"$",
"callsInAverage",
"++",
";",
"$",
"this",
"->",
"invocationAverageTime",
"=",
"(",
"(",
"float",
")",
"$",
"this",
"->",
"completedCallTimeTotal",
")",
"/",
"$",
"callsInAverage",
";",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"calls",
")",
"==",
"0",
")",
"{",
"$",
"this",
"->",
"lastIdledAt",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"busyStart",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"busyTime",
"=",
"$",
"this",
"->",
"busyTime",
"+",
"(",
"$",
"callEnd",
"-",
"$",
"this",
"->",
"busyStart",
")",
";",
"$",
"this",
"->",
"busyStart",
"=",
"null",
";",
"}",
"}",
"}",
"}",
"}"
] | Remove call
@param \Thruway\Call $callToRemove | [
"Remove",
"call"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Registration.php#L272-L298 |
voryx/Thruway | src/Registration.php | Registration.errorAllPendingCalls | public function errorAllPendingCalls()
{
foreach ($this->calls as $call) {
$call->getCallerSession()->sendMessage(ErrorMessage::createErrorMessageFromMessage($call->getCallMessage(), 'wamp.error.canceled'));
}
} | php | public function errorAllPendingCalls()
{
foreach ($this->calls as $call) {
$call->getCallerSession()->sendMessage(ErrorMessage::createErrorMessageFromMessage($call->getCallMessage(), 'wamp.error.canceled'));
}
} | [
"public",
"function",
"errorAllPendingCalls",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"calls",
"as",
"$",
"call",
")",
"{",
"$",
"call",
"->",
"getCallerSession",
"(",
")",
"->",
"sendMessage",
"(",
"ErrorMessage",
"::",
"createErrorMessageFromMessage",
"(",
"$",
"call",
"->",
"getCallMessage",
"(",
")",
",",
"'wamp.error.canceled'",
")",
")",
";",
"}",
"}"
] | This will send error messages on all pending calls
This is used when a session disconnects before completing a call | [
"This",
"will",
"send",
"error",
"messages",
"on",
"all",
"pending",
"calls",
"This",
"is",
"used",
"when",
"a",
"session",
"disconnects",
"before",
"completing",
"a",
"call"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Registration.php#L364-L369 |
voryx/Thruway | src/Registration.php | Registration.getStatistics | public function getStatistics()
{
return [
'currentCallCount' => count($this->calls),
'registeredAt' => $this->registeredAt,
'invocationCount' => $this->invocationCount,
'invocationAverageTime' => $this->invocationAverageTime,
'busyTime' => $this->busyTime,
'busyStart' => $this->busyStart,
'lastIdledAt' => $this->lastIdledAt,
'lastCallStartedAt' => $this->lastCallStartedAt,
'completedCallTimeTotal' => $this->completedCallTimeTotal
];
} | php | public function getStatistics()
{
return [
'currentCallCount' => count($this->calls),
'registeredAt' => $this->registeredAt,
'invocationCount' => $this->invocationCount,
'invocationAverageTime' => $this->invocationAverageTime,
'busyTime' => $this->busyTime,
'busyStart' => $this->busyStart,
'lastIdledAt' => $this->lastIdledAt,
'lastCallStartedAt' => $this->lastCallStartedAt,
'completedCallTimeTotal' => $this->completedCallTimeTotal
];
} | [
"public",
"function",
"getStatistics",
"(",
")",
"{",
"return",
"[",
"'currentCallCount'",
"=>",
"count",
"(",
"$",
"this",
"->",
"calls",
")",
",",
"'registeredAt'",
"=>",
"$",
"this",
"->",
"registeredAt",
",",
"'invocationCount'",
"=>",
"$",
"this",
"->",
"invocationCount",
",",
"'invocationAverageTime'",
"=>",
"$",
"this",
"->",
"invocationAverageTime",
",",
"'busyTime'",
"=>",
"$",
"this",
"->",
"busyTime",
",",
"'busyStart'",
"=>",
"$",
"this",
"->",
"busyStart",
",",
"'lastIdledAt'",
"=>",
"$",
"this",
"->",
"lastIdledAt",
",",
"'lastCallStartedAt'",
"=>",
"$",
"this",
"->",
"lastCallStartedAt",
",",
"'completedCallTimeTotal'",
"=>",
"$",
"this",
"->",
"completedCallTimeTotal",
"]",
";",
"}"
] | Get registration statistics
@return array | [
"Get",
"registration",
"statistics"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Registration.php#L376-L389 |
voryx/Thruway | src/Session.php | Session.sendMessage | public function sendMessage(Message $msg)
{
$this->lastOutboundActivity = microtime(true);
$this->dispatchMessage($msg, 'Send');
} | php | public function sendMessage(Message $msg)
{
$this->lastOutboundActivity = microtime(true);
$this->dispatchMessage($msg, 'Send');
} | [
"public",
"function",
"sendMessage",
"(",
"Message",
"$",
"msg",
")",
"{",
"$",
"this",
"->",
"lastOutboundActivity",
"=",
"microtime",
"(",
"true",
")",
";",
"$",
"this",
"->",
"dispatchMessage",
"(",
"$",
"msg",
",",
"'Send'",
")",
";",
"}"
] | Send message
@param \Thruway\Message\Message $msg
@return mixed|void | [
"Send",
"message"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Session.php#L111-L115 |
voryx/Thruway | src/Session.php | Session.onClose | public function onClose()
{
if ($this->realm !== null) {
// only send the leave metaevent if we actually made it into the realm
if ($this->isAuthenticated()) {
// metaevent
$this->getRealm()->publishMeta('wamp.metaevent.session.on_leave', [$this->getMetaInfo()]);
}
$this->dispatcher->dispatch('LeaveRealm', new LeaveRealmEvent($this->realm, $this));
$this->realm = null;
}
} | php | public function onClose()
{
if ($this->realm !== null) {
// only send the leave metaevent if we actually made it into the realm
if ($this->isAuthenticated()) {
// metaevent
$this->getRealm()->publishMeta('wamp.metaevent.session.on_leave', [$this->getMetaInfo()]);
}
$this->dispatcher->dispatch('LeaveRealm', new LeaveRealmEvent($this->realm, $this));
$this->realm = null;
}
} | [
"public",
"function",
"onClose",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"realm",
"!==",
"null",
")",
"{",
"// only send the leave metaevent if we actually made it into the realm",
"if",
"(",
"$",
"this",
"->",
"isAuthenticated",
"(",
")",
")",
"{",
"// metaevent",
"$",
"this",
"->",
"getRealm",
"(",
")",
"->",
"publishMeta",
"(",
"'wamp.metaevent.session.on_leave'",
",",
"[",
"$",
"this",
"->",
"getMetaInfo",
"(",
")",
"]",
")",
";",
"}",
"$",
"this",
"->",
"dispatcher",
"->",
"dispatch",
"(",
"'LeaveRealm'",
",",
"new",
"LeaveRealmEvent",
"(",
"$",
"this",
"->",
"realm",
",",
"$",
"this",
")",
")",
";",
"$",
"this",
"->",
"realm",
"=",
"null",
";",
"}",
"}"
] | Handle close session | [
"Handle",
"close",
"session"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Session.php#L129-L141 |
voryx/Thruway | src/Session.php | Session.setAuthenticated | public function setAuthenticated($authenticated)
{
// make sure the metaevent is only sent when changing from
// not-authenticate to authenticated
if ($authenticated && !$this->authenticated) {
// metaevent
$this->getRealm()->publishMeta('wamp.metaevent.session.on_join', [$this->getMetaInfo()]);
}
parent::setAuthenticated($authenticated);
} | php | public function setAuthenticated($authenticated)
{
// make sure the metaevent is only sent when changing from
// not-authenticate to authenticated
if ($authenticated && !$this->authenticated) {
// metaevent
$this->getRealm()->publishMeta('wamp.metaevent.session.on_join', [$this->getMetaInfo()]);
}
parent::setAuthenticated($authenticated);
} | [
"public",
"function",
"setAuthenticated",
"(",
"$",
"authenticated",
")",
"{",
"// make sure the metaevent is only sent when changing from",
"// not-authenticate to authenticated",
"if",
"(",
"$",
"authenticated",
"&&",
"!",
"$",
"this",
"->",
"authenticated",
")",
"{",
"// metaevent",
"$",
"this",
"->",
"getRealm",
"(",
")",
"->",
"publishMeta",
"(",
"'wamp.metaevent.session.on_join'",
",",
"[",
"$",
"this",
"->",
"getMetaInfo",
"(",
")",
"]",
")",
";",
"}",
"parent",
"::",
"setAuthenticated",
"(",
"$",
"authenticated",
")",
";",
"}"
] | Set authenticated state
@param boolean $authenticated | [
"Set",
"authenticated",
"state"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Session.php#L197-L207 |
voryx/Thruway | src/Session.php | Session.getMetaInfo | public function getMetaInfo()
{
if ($this->getAuthenticationDetails() instanceof AuthenticationDetails) {
$authId = $this->getAuthenticationDetails()->getAuthId();
$authMethod = $this->getAuthenticationDetails()->getAuthMethod();
$authRole = $this->getAuthenticationDetails()->getAuthRole();
$authRoles = $this->getAuthenticationDetails()->getAuthRoles();
} else {
$authId = 'anonymous';
$authMethod = 'anonymous';
$authRole = 'anonymous';
$authRoles = [];
}
return [
'realm' => $this->getRealm()->getRealmName(),
'authprovider' => null,
'authid' => $authId,
'authrole' => $authRole,
'authroles' => $authRoles,
'authmethod' => $authMethod,
'session' => $this->getSessionId(),
'role_features' => $this->getRoleFeatures()
];
} | php | public function getMetaInfo()
{
if ($this->getAuthenticationDetails() instanceof AuthenticationDetails) {
$authId = $this->getAuthenticationDetails()->getAuthId();
$authMethod = $this->getAuthenticationDetails()->getAuthMethod();
$authRole = $this->getAuthenticationDetails()->getAuthRole();
$authRoles = $this->getAuthenticationDetails()->getAuthRoles();
} else {
$authId = 'anonymous';
$authMethod = 'anonymous';
$authRole = 'anonymous';
$authRoles = [];
}
return [
'realm' => $this->getRealm()->getRealmName(),
'authprovider' => null,
'authid' => $authId,
'authrole' => $authRole,
'authroles' => $authRoles,
'authmethod' => $authMethod,
'session' => $this->getSessionId(),
'role_features' => $this->getRoleFeatures()
];
} | [
"public",
"function",
"getMetaInfo",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getAuthenticationDetails",
"(",
")",
"instanceof",
"AuthenticationDetails",
")",
"{",
"$",
"authId",
"=",
"$",
"this",
"->",
"getAuthenticationDetails",
"(",
")",
"->",
"getAuthId",
"(",
")",
";",
"$",
"authMethod",
"=",
"$",
"this",
"->",
"getAuthenticationDetails",
"(",
")",
"->",
"getAuthMethod",
"(",
")",
";",
"$",
"authRole",
"=",
"$",
"this",
"->",
"getAuthenticationDetails",
"(",
")",
"->",
"getAuthRole",
"(",
")",
";",
"$",
"authRoles",
"=",
"$",
"this",
"->",
"getAuthenticationDetails",
"(",
")",
"->",
"getAuthRoles",
"(",
")",
";",
"}",
"else",
"{",
"$",
"authId",
"=",
"'anonymous'",
";",
"$",
"authMethod",
"=",
"'anonymous'",
";",
"$",
"authRole",
"=",
"'anonymous'",
";",
"$",
"authRoles",
"=",
"[",
"]",
";",
"}",
"return",
"[",
"'realm'",
"=>",
"$",
"this",
"->",
"getRealm",
"(",
")",
"->",
"getRealmName",
"(",
")",
",",
"'authprovider'",
"=>",
"null",
",",
"'authid'",
"=>",
"$",
"authId",
",",
"'authrole'",
"=>",
"$",
"authRole",
",",
"'authroles'",
"=>",
"$",
"authRoles",
",",
"'authmethod'",
"=>",
"$",
"authMethod",
",",
"'session'",
"=>",
"$",
"this",
"->",
"getSessionId",
"(",
")",
",",
"'role_features'",
"=>",
"$",
"this",
"->",
"getRoleFeatures",
"(",
")",
"]",
";",
"}"
] | Get meta info
@return array | [
"Get",
"meta",
"info"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Session.php#L214-L238 |
voryx/Thruway | src/Authentication/AuthenticationManager.php | AuthenticationManager.onSessionStart | public function onSessionStart($session, $transport)
{
$session->register('thruway.auth.registermethod', [$this, 'registerAuthMethod'], ['disclose_caller' => true])
->then(
function () {
$this->setReady(true);
},
function () {
$this->setReady(false);
Logger::error($this, 'registration of registerAuthMethod failed.');
}
);
} | php | public function onSessionStart($session, $transport)
{
$session->register('thruway.auth.registermethod', [$this, 'registerAuthMethod'], ['disclose_caller' => true])
->then(
function () {
$this->setReady(true);
},
function () {
$this->setReady(false);
Logger::error($this, 'registration of registerAuthMethod failed.');
}
);
} | [
"public",
"function",
"onSessionStart",
"(",
"$",
"session",
",",
"$",
"transport",
")",
"{",
"$",
"session",
"->",
"register",
"(",
"'thruway.auth.registermethod'",
",",
"[",
"$",
"this",
",",
"'registerAuthMethod'",
"]",
",",
"[",
"'disclose_caller'",
"=>",
"true",
"]",
")",
"->",
"then",
"(",
"function",
"(",
")",
"{",
"$",
"this",
"->",
"setReady",
"(",
"true",
")",
";",
"}",
",",
"function",
"(",
")",
"{",
"$",
"this",
"->",
"setReady",
"(",
"false",
")",
";",
"Logger",
"::",
"error",
"(",
"$",
"this",
",",
"'registration of registerAuthMethod failed.'",
")",
";",
"}",
")",
";",
"}"
] | Handles session started
@param \Thruway\ClientSession $session
@param \Thruway\Transport\TransportProviderInterface $transport | [
"Handles",
"session",
"started"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Authentication/AuthenticationManager.php#L114-L126 |
voryx/Thruway | src/Authentication/AuthenticationManager.php | AuthenticationManager.processMessage | private function processMessage(Realm $realm, Session $session, Message $msg)
{
if ($session->isAuthenticated()) {
throw new \Exception('Message sent to authentication manager for already authenticated session.');
}
// trusted transports do not need any authentication
if ($session->getTransport()->isTrusted()) {
$authDetails = new AuthenticationDetails();
$authDetails->setAuthMethod('internalClient');
$authDetails->setAuthId('internal');
// set the authid if the hello has one
if ($msg instanceof HelloMessage) {
$details = $msg->getDetails();
if (isset($details) && isset($details->authid)) {
$authDetails->setAuthId($details->authid);
}
}
$authDetails->addAuthRole('authenticated_user');
$authDetails->addAuthRole('admin');
$session->setAuthenticationDetails($authDetails);
$session->setAuthenticated(true);
$details = new \stdClass();
$details->authid = $authDetails->getAuthId();
$details->authmethod = $authDetails->getAuthMethod();
$details->authrole = $authDetails->getAuthRole();
$details->authroles = $authDetails->getAuthRoles();
$session->sendMessage(new WelcomeMessage($session->getSessionId(), $details));
return;
}
if (!$this->readyToAuthenticate()) {
$session->abort(new \stdClass(), 'thruway.authenticator.not_ready');
return;
}
if ($msg instanceof HelloMessage) {
if ($session->getAuthenticationDetails() !== null) {
// Todo: probably shouldn't be so dramatic here
throw new \Exception(
'Hello message sent to authentication manager when there is already authentication details attached.'
);
}
$this->handleHelloMessage($realm, $session, $msg);
} else {
if ($msg instanceof AuthenticateMessage) {
$this->handleAuthenticateMessage($realm, $session, $msg);
} else {
throw new \Exception('Invalid message type sent to AuthenticationManager.');
}
}
} | php | private function processMessage(Realm $realm, Session $session, Message $msg)
{
if ($session->isAuthenticated()) {
throw new \Exception('Message sent to authentication manager for already authenticated session.');
}
// trusted transports do not need any authentication
if ($session->getTransport()->isTrusted()) {
$authDetails = new AuthenticationDetails();
$authDetails->setAuthMethod('internalClient');
$authDetails->setAuthId('internal');
// set the authid if the hello has one
if ($msg instanceof HelloMessage) {
$details = $msg->getDetails();
if (isset($details) && isset($details->authid)) {
$authDetails->setAuthId($details->authid);
}
}
$authDetails->addAuthRole('authenticated_user');
$authDetails->addAuthRole('admin');
$session->setAuthenticationDetails($authDetails);
$session->setAuthenticated(true);
$details = new \stdClass();
$details->authid = $authDetails->getAuthId();
$details->authmethod = $authDetails->getAuthMethod();
$details->authrole = $authDetails->getAuthRole();
$details->authroles = $authDetails->getAuthRoles();
$session->sendMessage(new WelcomeMessage($session->getSessionId(), $details));
return;
}
if (!$this->readyToAuthenticate()) {
$session->abort(new \stdClass(), 'thruway.authenticator.not_ready');
return;
}
if ($msg instanceof HelloMessage) {
if ($session->getAuthenticationDetails() !== null) {
// Todo: probably shouldn't be so dramatic here
throw new \Exception(
'Hello message sent to authentication manager when there is already authentication details attached.'
);
}
$this->handleHelloMessage($realm, $session, $msg);
} else {
if ($msg instanceof AuthenticateMessage) {
$this->handleAuthenticateMessage($realm, $session, $msg);
} else {
throw new \Exception('Invalid message type sent to AuthenticationManager.');
}
}
} | [
"private",
"function",
"processMessage",
"(",
"Realm",
"$",
"realm",
",",
"Session",
"$",
"session",
",",
"Message",
"$",
"msg",
")",
"{",
"if",
"(",
"$",
"session",
"->",
"isAuthenticated",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Message sent to authentication manager for already authenticated session.'",
")",
";",
"}",
"// trusted transports do not need any authentication",
"if",
"(",
"$",
"session",
"->",
"getTransport",
"(",
")",
"->",
"isTrusted",
"(",
")",
")",
"{",
"$",
"authDetails",
"=",
"new",
"AuthenticationDetails",
"(",
")",
";",
"$",
"authDetails",
"->",
"setAuthMethod",
"(",
"'internalClient'",
")",
";",
"$",
"authDetails",
"->",
"setAuthId",
"(",
"'internal'",
")",
";",
"// set the authid if the hello has one",
"if",
"(",
"$",
"msg",
"instanceof",
"HelloMessage",
")",
"{",
"$",
"details",
"=",
"$",
"msg",
"->",
"getDetails",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"details",
")",
"&&",
"isset",
"(",
"$",
"details",
"->",
"authid",
")",
")",
"{",
"$",
"authDetails",
"->",
"setAuthId",
"(",
"$",
"details",
"->",
"authid",
")",
";",
"}",
"}",
"$",
"authDetails",
"->",
"addAuthRole",
"(",
"'authenticated_user'",
")",
";",
"$",
"authDetails",
"->",
"addAuthRole",
"(",
"'admin'",
")",
";",
"$",
"session",
"->",
"setAuthenticationDetails",
"(",
"$",
"authDetails",
")",
";",
"$",
"session",
"->",
"setAuthenticated",
"(",
"true",
")",
";",
"$",
"details",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"details",
"->",
"authid",
"=",
"$",
"authDetails",
"->",
"getAuthId",
"(",
")",
";",
"$",
"details",
"->",
"authmethod",
"=",
"$",
"authDetails",
"->",
"getAuthMethod",
"(",
")",
";",
"$",
"details",
"->",
"authrole",
"=",
"$",
"authDetails",
"->",
"getAuthRole",
"(",
")",
";",
"$",
"details",
"->",
"authroles",
"=",
"$",
"authDetails",
"->",
"getAuthRoles",
"(",
")",
";",
"$",
"session",
"->",
"sendMessage",
"(",
"new",
"WelcomeMessage",
"(",
"$",
"session",
"->",
"getSessionId",
"(",
")",
",",
"$",
"details",
")",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"readyToAuthenticate",
"(",
")",
")",
"{",
"$",
"session",
"->",
"abort",
"(",
"new",
"\\",
"stdClass",
"(",
")",
",",
"'thruway.authenticator.not_ready'",
")",
";",
"return",
";",
"}",
"if",
"(",
"$",
"msg",
"instanceof",
"HelloMessage",
")",
"{",
"if",
"(",
"$",
"session",
"->",
"getAuthenticationDetails",
"(",
")",
"!==",
"null",
")",
"{",
"// Todo: probably shouldn't be so dramatic here",
"throw",
"new",
"\\",
"Exception",
"(",
"'Hello message sent to authentication manager when there is already authentication details attached.'",
")",
";",
"}",
"$",
"this",
"->",
"handleHelloMessage",
"(",
"$",
"realm",
",",
"$",
"session",
",",
"$",
"msg",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"msg",
"instanceof",
"AuthenticateMessage",
")",
"{",
"$",
"this",
"->",
"handleAuthenticateMessage",
"(",
"$",
"realm",
",",
"$",
"session",
",",
"$",
"msg",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Invalid message type sent to AuthenticationManager.'",
")",
";",
"}",
"}",
"}"
] | Handles all messages for authentication (Hello and Authenticate)
This is called by the Realm to handle authentication
@param \Thruway\Realm $realm
@param \Thruway\Session $session
@param \Thruway\Message\Message $msg
@throws \Exception | [
"Handles",
"all",
"messages",
"for",
"authentication",
"(",
"Hello",
"and",
"Authenticate",
")",
"This",
"is",
"called",
"by",
"the",
"Realm",
"to",
"handle",
"authentication"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Authentication/AuthenticationManager.php#L137-L196 |
voryx/Thruway | src/Authentication/AuthenticationManager.php | AuthenticationManager.handleHelloMessage | public function handleHelloMessage(Realm $realm, Session $session, HelloMessage $msg)
{
$requestedMethods = $msg->getAuthMethods();
$sentMessage = false;
// Go through the authmethods and try to send a response message
foreach ($this->authMethods as $authMethod => $authMethodInfo) {
if (in_array($authMethod, $requestedMethods)
&& (in_array($realm->getRealmName(), $authMethodInfo['auth_realms'])
|| in_array("*", $authMethodInfo['auth_realms']))
) {
$this->onHelloAuthHandler($authMethod, $authMethodInfo, $realm, $session, $msg);
$sentMessage = true;
}
}
//If we already replied with a message, we don't have to do anything else
if ($sentMessage) {
return;
}
// If no authentication providers are registered for this realm send an abort message
if ($this->realmHasAuthProvider($realm->getRealmName())) {
$session->abort(new \stdClass(), 'wamp.error.not_authorized');
return;
}
//If we've gotten this far, it means that the user needs to be Logged in as anonymous
$session->setAuthenticationDetails(AuthenticationDetails::createAnonymous());
$details = new \stdClass();
$session->sendMessage(new WelcomeMessage($session->getSessionId(), $details));
$session->setAuthenticated(true);
} | php | public function handleHelloMessage(Realm $realm, Session $session, HelloMessage $msg)
{
$requestedMethods = $msg->getAuthMethods();
$sentMessage = false;
// Go through the authmethods and try to send a response message
foreach ($this->authMethods as $authMethod => $authMethodInfo) {
if (in_array($authMethod, $requestedMethods)
&& (in_array($realm->getRealmName(), $authMethodInfo['auth_realms'])
|| in_array("*", $authMethodInfo['auth_realms']))
) {
$this->onHelloAuthHandler($authMethod, $authMethodInfo, $realm, $session, $msg);
$sentMessage = true;
}
}
//If we already replied with a message, we don't have to do anything else
if ($sentMessage) {
return;
}
// If no authentication providers are registered for this realm send an abort message
if ($this->realmHasAuthProvider($realm->getRealmName())) {
$session->abort(new \stdClass(), 'wamp.error.not_authorized');
return;
}
//If we've gotten this far, it means that the user needs to be Logged in as anonymous
$session->setAuthenticationDetails(AuthenticationDetails::createAnonymous());
$details = new \stdClass();
$session->sendMessage(new WelcomeMessage($session->getSessionId(), $details));
$session->setAuthenticated(true);
} | [
"public",
"function",
"handleHelloMessage",
"(",
"Realm",
"$",
"realm",
",",
"Session",
"$",
"session",
",",
"HelloMessage",
"$",
"msg",
")",
"{",
"$",
"requestedMethods",
"=",
"$",
"msg",
"->",
"getAuthMethods",
"(",
")",
";",
"$",
"sentMessage",
"=",
"false",
";",
"// Go through the authmethods and try to send a response message",
"foreach",
"(",
"$",
"this",
"->",
"authMethods",
"as",
"$",
"authMethod",
"=>",
"$",
"authMethodInfo",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"authMethod",
",",
"$",
"requestedMethods",
")",
"&&",
"(",
"in_array",
"(",
"$",
"realm",
"->",
"getRealmName",
"(",
")",
",",
"$",
"authMethodInfo",
"[",
"'auth_realms'",
"]",
")",
"||",
"in_array",
"(",
"\"*\"",
",",
"$",
"authMethodInfo",
"[",
"'auth_realms'",
"]",
")",
")",
")",
"{",
"$",
"this",
"->",
"onHelloAuthHandler",
"(",
"$",
"authMethod",
",",
"$",
"authMethodInfo",
",",
"$",
"realm",
",",
"$",
"session",
",",
"$",
"msg",
")",
";",
"$",
"sentMessage",
"=",
"true",
";",
"}",
"}",
"//If we already replied with a message, we don't have to do anything else",
"if",
"(",
"$",
"sentMessage",
")",
"{",
"return",
";",
"}",
"// If no authentication providers are registered for this realm send an abort message",
"if",
"(",
"$",
"this",
"->",
"realmHasAuthProvider",
"(",
"$",
"realm",
"->",
"getRealmName",
"(",
")",
")",
")",
"{",
"$",
"session",
"->",
"abort",
"(",
"new",
"\\",
"stdClass",
"(",
")",
",",
"'wamp.error.not_authorized'",
")",
";",
"return",
";",
"}",
"//If we've gotten this far, it means that the user needs to be Logged in as anonymous",
"$",
"session",
"->",
"setAuthenticationDetails",
"(",
"AuthenticationDetails",
"::",
"createAnonymous",
"(",
")",
")",
";",
"$",
"details",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"session",
"->",
"sendMessage",
"(",
"new",
"WelcomeMessage",
"(",
"$",
"session",
"->",
"getSessionId",
"(",
")",
",",
"$",
"details",
")",
")",
";",
"$",
"session",
"->",
"setAuthenticated",
"(",
"true",
")",
";",
"}"
] | Handle HelloMessage
@param \Thruway\Realm $realm
@param \Thruway\Session $session
@param \Thruway\Message\HelloMessage $msg | [
"Handle",
"HelloMessage"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Authentication/AuthenticationManager.php#L205-L241 |
voryx/Thruway | src/Authentication/AuthenticationManager.php | AuthenticationManager.onHelloAuthHandler | private function onHelloAuthHandler($authMethod, $authMethodInfo, Realm $realm, Session $session, HelloMessage $msg)
{
$authDetails = new AuthenticationDetails();
$authDetails->setAuthMethod($authMethod);
$helloDetails = $msg->getDetails();
if (isset($helloDetails->authid)) {
$authDetails->setAuthId($helloDetails->authid);
}
$session->setAuthenticationDetails($authDetails);
$sessionInfo = ['sessionId' => $session->getSessionId(), 'realm' => $realm->getRealmName()];
$onHelloSuccess = function ($res) use ($realm, $session, $msg) {
// this is handling the return of the onhello RPC call
if (isset($res[0]) && $res[0] === 'FAILURE') {
$this->abortSessionUsingResponse($session, $res);
return;
}
if (count($res) < 2) {
$session->abort(new \stdClass(), 'thruway.auth.invalid_response_to_hello');
return;
}
switch ($res[0]) {
case 'CHALLENGE':
// TODO: validate challenge message
$authMethod = $res[1]->challenge_method;
$challenge = $res[1]->challenge;
$session->getAuthenticationDetails()->setChallenge($challenge);
$session->getAuthenticationDetails()->setChallengeDetails($res[1]);
$challengeDetails = $session->getAuthenticationDetails()->getChallengeDetails();
$session->sendMessage(new ChallengeMessage($authMethod, $challengeDetails));
break;
case 'NOCHALLENGE':
$details = $res[1];
$details->authmethod = $session->getAuthenticationDetails()->getAuthMethod();
$this->sendWelcomeMessage($session, $details);
break;
default:
$session->abort(new \stdClass(), "thruway.error.authentication_failure");
}
};
$onHelloError = function () use ($session) {
Logger::error($this, 'onhello rejected the promise');
$session->abort(new \stdClass(), 'thruway.error.unknown');
};
$onHelloAuthHandler = $authMethodInfo['handlers']->onhello;
//Make the OnHello Call
$this->session->call($onHelloAuthHandler, [$msg, $sessionInfo])
->then($onHelloSuccess, $onHelloError);
} | php | private function onHelloAuthHandler($authMethod, $authMethodInfo, Realm $realm, Session $session, HelloMessage $msg)
{
$authDetails = new AuthenticationDetails();
$authDetails->setAuthMethod($authMethod);
$helloDetails = $msg->getDetails();
if (isset($helloDetails->authid)) {
$authDetails->setAuthId($helloDetails->authid);
}
$session->setAuthenticationDetails($authDetails);
$sessionInfo = ['sessionId' => $session->getSessionId(), 'realm' => $realm->getRealmName()];
$onHelloSuccess = function ($res) use ($realm, $session, $msg) {
// this is handling the return of the onhello RPC call
if (isset($res[0]) && $res[0] === 'FAILURE') {
$this->abortSessionUsingResponse($session, $res);
return;
}
if (count($res) < 2) {
$session->abort(new \stdClass(), 'thruway.auth.invalid_response_to_hello');
return;
}
switch ($res[0]) {
case 'CHALLENGE':
// TODO: validate challenge message
$authMethod = $res[1]->challenge_method;
$challenge = $res[1]->challenge;
$session->getAuthenticationDetails()->setChallenge($challenge);
$session->getAuthenticationDetails()->setChallengeDetails($res[1]);
$challengeDetails = $session->getAuthenticationDetails()->getChallengeDetails();
$session->sendMessage(new ChallengeMessage($authMethod, $challengeDetails));
break;
case 'NOCHALLENGE':
$details = $res[1];
$details->authmethod = $session->getAuthenticationDetails()->getAuthMethod();
$this->sendWelcomeMessage($session, $details);
break;
default:
$session->abort(new \stdClass(), "thruway.error.authentication_failure");
}
};
$onHelloError = function () use ($session) {
Logger::error($this, 'onhello rejected the promise');
$session->abort(new \stdClass(), 'thruway.error.unknown');
};
$onHelloAuthHandler = $authMethodInfo['handlers']->onhello;
//Make the OnHello Call
$this->session->call($onHelloAuthHandler, [$msg, $sessionInfo])
->then($onHelloSuccess, $onHelloError);
} | [
"private",
"function",
"onHelloAuthHandler",
"(",
"$",
"authMethod",
",",
"$",
"authMethodInfo",
",",
"Realm",
"$",
"realm",
",",
"Session",
"$",
"session",
",",
"HelloMessage",
"$",
"msg",
")",
"{",
"$",
"authDetails",
"=",
"new",
"AuthenticationDetails",
"(",
")",
";",
"$",
"authDetails",
"->",
"setAuthMethod",
"(",
"$",
"authMethod",
")",
";",
"$",
"helloDetails",
"=",
"$",
"msg",
"->",
"getDetails",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"helloDetails",
"->",
"authid",
")",
")",
"{",
"$",
"authDetails",
"->",
"setAuthId",
"(",
"$",
"helloDetails",
"->",
"authid",
")",
";",
"}",
"$",
"session",
"->",
"setAuthenticationDetails",
"(",
"$",
"authDetails",
")",
";",
"$",
"sessionInfo",
"=",
"[",
"'sessionId'",
"=>",
"$",
"session",
"->",
"getSessionId",
"(",
")",
",",
"'realm'",
"=>",
"$",
"realm",
"->",
"getRealmName",
"(",
")",
"]",
";",
"$",
"onHelloSuccess",
"=",
"function",
"(",
"$",
"res",
")",
"use",
"(",
"$",
"realm",
",",
"$",
"session",
",",
"$",
"msg",
")",
"{",
"// this is handling the return of the onhello RPC call",
"if",
"(",
"isset",
"(",
"$",
"res",
"[",
"0",
"]",
")",
"&&",
"$",
"res",
"[",
"0",
"]",
"===",
"'FAILURE'",
")",
"{",
"$",
"this",
"->",
"abortSessionUsingResponse",
"(",
"$",
"session",
",",
"$",
"res",
")",
";",
"return",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"res",
")",
"<",
"2",
")",
"{",
"$",
"session",
"->",
"abort",
"(",
"new",
"\\",
"stdClass",
"(",
")",
",",
"'thruway.auth.invalid_response_to_hello'",
")",
";",
"return",
";",
"}",
"switch",
"(",
"$",
"res",
"[",
"0",
"]",
")",
"{",
"case",
"'CHALLENGE'",
":",
"// TODO: validate challenge message",
"$",
"authMethod",
"=",
"$",
"res",
"[",
"1",
"]",
"->",
"challenge_method",
";",
"$",
"challenge",
"=",
"$",
"res",
"[",
"1",
"]",
"->",
"challenge",
";",
"$",
"session",
"->",
"getAuthenticationDetails",
"(",
")",
"->",
"setChallenge",
"(",
"$",
"challenge",
")",
";",
"$",
"session",
"->",
"getAuthenticationDetails",
"(",
")",
"->",
"setChallengeDetails",
"(",
"$",
"res",
"[",
"1",
"]",
")",
";",
"$",
"challengeDetails",
"=",
"$",
"session",
"->",
"getAuthenticationDetails",
"(",
")",
"->",
"getChallengeDetails",
"(",
")",
";",
"$",
"session",
"->",
"sendMessage",
"(",
"new",
"ChallengeMessage",
"(",
"$",
"authMethod",
",",
"$",
"challengeDetails",
")",
")",
";",
"break",
";",
"case",
"'NOCHALLENGE'",
":",
"$",
"details",
"=",
"$",
"res",
"[",
"1",
"]",
";",
"$",
"details",
"->",
"authmethod",
"=",
"$",
"session",
"->",
"getAuthenticationDetails",
"(",
")",
"->",
"getAuthMethod",
"(",
")",
";",
"$",
"this",
"->",
"sendWelcomeMessage",
"(",
"$",
"session",
",",
"$",
"details",
")",
";",
"break",
";",
"default",
":",
"$",
"session",
"->",
"abort",
"(",
"new",
"\\",
"stdClass",
"(",
")",
",",
"\"thruway.error.authentication_failure\"",
")",
";",
"}",
"}",
";",
"$",
"onHelloError",
"=",
"function",
"(",
")",
"use",
"(",
"$",
"session",
")",
"{",
"Logger",
"::",
"error",
"(",
"$",
"this",
",",
"'onhello rejected the promise'",
")",
";",
"$",
"session",
"->",
"abort",
"(",
"new",
"\\",
"stdClass",
"(",
")",
",",
"'thruway.error.unknown'",
")",
";",
"}",
";",
"$",
"onHelloAuthHandler",
"=",
"$",
"authMethodInfo",
"[",
"'handlers'",
"]",
"->",
"onhello",
";",
"//Make the OnHello Call",
"$",
"this",
"->",
"session",
"->",
"call",
"(",
"$",
"onHelloAuthHandler",
",",
"[",
"$",
"msg",
",",
"$",
"sessionInfo",
"]",
")",
"->",
"then",
"(",
"$",
"onHelloSuccess",
",",
"$",
"onHelloError",
")",
";",
"}"
] | Call the RPC URI that has been registered to handle Authentication Hello Messages
@param $authMethod
@param $authMethodInfo
@param Realm $realm
@param Session $session
@param HelloMessage $msg | [
"Call",
"the",
"RPC",
"URI",
"that",
"has",
"been",
"registered",
"to",
"handle",
"Authentication",
"Hello",
"Messages"
] | train | https://github.com/voryx/Thruway/blob/b86c0cddbec8fb69ff583e093d4cc169011fcbfb/src/Authentication/AuthenticationManager.php#L252-L319 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.