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 |
|---|---|---|---|---|---|---|---|---|---|---|
artkonekt/appshell | src/Http/Controllers/CustomerController.php | CustomerController.store | public function store(CreateCustomer $request)
{
try {
$customer = CustomerProxy::create($request->all());
flash()->success(__(':name has been created', ['name' => $customer->getName()]));
} catch (\Exception $e) {
flash()->error(__('Error: :msg', ['msg' => $e->getMessage()]));
return redirect()->back()->withInput();
}
return redirect(route('appshell.customer.index'));
} | php | public function store(CreateCustomer $request)
{
try {
$customer = CustomerProxy::create($request->all());
flash()->success(__(':name has been created', ['name' => $customer->getName()]));
} catch (\Exception $e) {
flash()->error(__('Error: :msg', ['msg' => $e->getMessage()]));
return redirect()->back()->withInput();
}
return redirect(route('appshell.customer.index'));
} | [
"public",
"function",
"store",
"(",
"CreateCustomer",
"$",
"request",
")",
"{",
"try",
"{",
"$",
"customer",
"=",
"CustomerProxy",
"::",
"create",
"(",
"$",
"request",
"->",
"all",
"(",
")",
")",
";",
"flash",
"(",
")",
"->",
"success",
"(",
"__",
"(",
"':name has been created'",
",",
"[",
"'name'",
"=>",
"$",
"customer",
"->",
"getName",
"(",
")",
"]",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"flash",
"(",
")",
"->",
"error",
"(",
"__",
"(",
"'Error: :msg'",
",",
"[",
"'msg'",
"=>",
"$",
"e",
"->",
"getMessage",
"(",
")",
"]",
")",
")",
";",
"return",
"redirect",
"(",
")",
"->",
"back",
"(",
")",
"->",
"withInput",
"(",
")",
";",
"}",
"return",
"redirect",
"(",
"route",
"(",
"'appshell.customer.index'",
")",
")",
";",
"}"
] | @param CreateCustomer $request
@return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector | [
"@param",
"CreateCustomer",
"$request"
] | train | https://github.com/artkonekt/appshell/blob/2ec5d9b36cf65eec619d7daa37ab66d0fd4d9d3b/src/Http/Controllers/CustomerController.php#L52-L65 |
artkonekt/appshell | src/Http/Controllers/CustomerController.php | CustomerController.update | public function update(Customer $customer, UpdateCustomer $request)
{
try {
$customer->update($request->all());
flash()->success(__(':name has been updated', ['name' => $customer->getName()]));
} catch (\Exception $e) {
flash()->error(__('Error: :msg', ['msg' => $e->getMessage()]));
return redirect()->back()->withInput();
}
return redirect(route('appshell.customer.show', $customer));
} | php | public function update(Customer $customer, UpdateCustomer $request)
{
try {
$customer->update($request->all());
flash()->success(__(':name has been updated', ['name' => $customer->getName()]));
} catch (\Exception $e) {
flash()->error(__('Error: :msg', ['msg' => $e->getMessage()]));
return redirect()->back()->withInput();
}
return redirect(route('appshell.customer.show', $customer));
} | [
"public",
"function",
"update",
"(",
"Customer",
"$",
"customer",
",",
"UpdateCustomer",
"$",
"request",
")",
"{",
"try",
"{",
"$",
"customer",
"->",
"update",
"(",
"$",
"request",
"->",
"all",
"(",
")",
")",
";",
"flash",
"(",
")",
"->",
"success",
"(",
"__",
"(",
"':name has been updated'",
",",
"[",
"'name'",
"=>",
"$",
"customer",
"->",
"getName",
"(",
")",
"]",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"flash",
"(",
")",
"->",
"error",
"(",
"__",
"(",
"'Error: :msg'",
",",
"[",
"'msg'",
"=>",
"$",
"e",
"->",
"getMessage",
"(",
")",
"]",
")",
")",
";",
"return",
"redirect",
"(",
")",
"->",
"back",
"(",
")",
"->",
"withInput",
"(",
")",
";",
"}",
"return",
"redirect",
"(",
"route",
"(",
"'appshell.customer.show'",
",",
"$",
"customer",
")",
")",
";",
"}"
] | @param Customer $customer
@param UpdateCustomer $request
@return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector | [
"@param",
"Customer",
"$customer",
"@param",
"UpdateCustomer",
"$request"
] | train | https://github.com/artkonekt/appshell/blob/2ec5d9b36cf65eec619d7daa37ab66d0fd4d9d3b/src/Http/Controllers/CustomerController.php#L102-L115 |
artkonekt/appshell | src/Http/Controllers/CustomerController.php | CustomerController.destroy | public function destroy(Customer $customer)
{
try {
$name = $customer->getName();
$customer->delete();
flash()->info(__('Customer :name has been deleted', ['name' => $name]));
} catch (\Exception $e) {
flash()->error(__('Error: :msg', ['msg' => $e->getMessage()]));
}
return redirect(route('appshell.customer.index'));
} | php | public function destroy(Customer $customer)
{
try {
$name = $customer->getName();
$customer->delete();
flash()->info(__('Customer :name has been deleted', ['name' => $name]));
} catch (\Exception $e) {
flash()->error(__('Error: :msg', ['msg' => $e->getMessage()]));
}
return redirect(route('appshell.customer.index'));
} | [
"public",
"function",
"destroy",
"(",
"Customer",
"$",
"customer",
")",
"{",
"try",
"{",
"$",
"name",
"=",
"$",
"customer",
"->",
"getName",
"(",
")",
";",
"$",
"customer",
"->",
"delete",
"(",
")",
";",
"flash",
"(",
")",
"->",
"info",
"(",
"__",
"(",
"'Customer :name has been deleted'",
",",
"[",
"'name'",
"=>",
"$",
"name",
"]",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"flash",
"(",
")",
"->",
"error",
"(",
"__",
"(",
"'Error: :msg'",
",",
"[",
"'msg'",
"=>",
"$",
"e",
"->",
"getMessage",
"(",
")",
"]",
")",
")",
";",
"}",
"return",
"redirect",
"(",
"route",
"(",
"'appshell.customer.index'",
")",
")",
";",
"}"
] | Delete a customer
@param Customer $customer
@return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector | [
"Delete",
"a",
"customer"
] | train | https://github.com/artkonekt/appshell/blob/2ec5d9b36cf65eec619d7daa37ab66d0fd4d9d3b/src/Http/Controllers/CustomerController.php#L124-L136 |
artkonekt/appshell | src/Acl/ResourcePermissions.php | ResourcePermissions.createPermissionsForResource | public static function createPermissionsForResource($resources)
{
$resources = is_array($resources) ? $resources : [$resources];
$result = collect();
foreach ($resources as $resource) {
foreach (static::allPermissionsFor($resource) as $name) {
$result->put($name, PermissionProxy::create(['name' => $name]));
}
}
return $result;
} | php | public static function createPermissionsForResource($resources)
{
$resources = is_array($resources) ? $resources : [$resources];
$result = collect();
foreach ($resources as $resource) {
foreach (static::allPermissionsFor($resource) as $name) {
$result->put($name, PermissionProxy::create(['name' => $name]));
}
}
return $result;
} | [
"public",
"static",
"function",
"createPermissionsForResource",
"(",
"$",
"resources",
")",
"{",
"$",
"resources",
"=",
"is_array",
"(",
"$",
"resources",
")",
"?",
"$",
"resources",
":",
"[",
"$",
"resources",
"]",
";",
"$",
"result",
"=",
"collect",
"(",
")",
";",
"foreach",
"(",
"$",
"resources",
"as",
"$",
"resource",
")",
"{",
"foreach",
"(",
"static",
"::",
"allPermissionsFor",
"(",
"$",
"resource",
")",
"as",
"$",
"name",
")",
"{",
"$",
"result",
"->",
"put",
"(",
"$",
"name",
",",
"PermissionProxy",
"::",
"create",
"(",
"[",
"'name'",
"=>",
"$",
"name",
"]",
")",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Creates the resource permissions for the given resource(s)
Eg: resource: 'user' creates 'list users', 'create users', ... etc
@param string|array $resources One or more resources to create resource permissions for
Eg. ('product' or ['product', 'category'])
@return \Illuminate\Support\Collection | [
"Creates",
"the",
"resource",
"permissions",
"for",
"the",
"given",
"resource",
"(",
"s",
")",
"Eg",
":",
"resource",
":",
"user",
"creates",
"list",
"users",
"create",
"users",
"...",
"etc"
] | train | https://github.com/artkonekt/appshell/blob/2ec5d9b36cf65eec619d7daa37ab66d0fd4d9d3b/src/Acl/ResourcePermissions.php#L33-L45 |
artkonekt/appshell | src/Acl/ResourcePermissions.php | ResourcePermissions.deletePermissionsForResource | public static function deletePermissionsForResource($resources)
{
$resources = is_array($resources) ? $resources : [$resources];
$result = 0;
foreach ($resources as $resource) {
foreach (static::allPermissionsFor($resource) as $name) {
PermissionProxy::where(['name' => $name])->delete();
$result++;
}
}
app(PermissionRegistrar::class)->forgetCachedPermissions();
return $result;
} | php | public static function deletePermissionsForResource($resources)
{
$resources = is_array($resources) ? $resources : [$resources];
$result = 0;
foreach ($resources as $resource) {
foreach (static::allPermissionsFor($resource) as $name) {
PermissionProxy::where(['name' => $name])->delete();
$result++;
}
}
app(PermissionRegistrar::class)->forgetCachedPermissions();
return $result;
} | [
"public",
"static",
"function",
"deletePermissionsForResource",
"(",
"$",
"resources",
")",
"{",
"$",
"resources",
"=",
"is_array",
"(",
"$",
"resources",
")",
"?",
"$",
"resources",
":",
"[",
"$",
"resources",
"]",
";",
"$",
"result",
"=",
"0",
";",
"foreach",
"(",
"$",
"resources",
"as",
"$",
"resource",
")",
"{",
"foreach",
"(",
"static",
"::",
"allPermissionsFor",
"(",
"$",
"resource",
")",
"as",
"$",
"name",
")",
"{",
"PermissionProxy",
"::",
"where",
"(",
"[",
"'name'",
"=>",
"$",
"name",
"]",
")",
"->",
"delete",
"(",
")",
";",
"$",
"result",
"++",
";",
"}",
"}",
"app",
"(",
"PermissionRegistrar",
"::",
"class",
")",
"->",
"forgetCachedPermissions",
"(",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Deletes permissions for a resource (opposite of createPermissionsForResource)
@see self::createPermissionsForResource
@param $resources
@return int Returns the count of removed permissions | [
"Deletes",
"permissions",
"for",
"a",
"resource",
"(",
"opposite",
"of",
"createPermissionsForResource",
")"
] | train | https://github.com/artkonekt/appshell/blob/2ec5d9b36cf65eec619d7daa37ab66d0fd4d9d3b/src/Acl/ResourcePermissions.php#L56-L71 |
artkonekt/appshell | src/Acl/ResourcePermissions.php | ResourcePermissions.permissionFor | public static function permissionFor($resource, $action)
{
if (! $verb = ResourcePermissions::permissionVerbForAction($action)) {
return false;
}
return sprintf('%s %s', $verb, str_plural($resource));
} | php | public static function permissionFor($resource, $action)
{
if (! $verb = ResourcePermissions::permissionVerbForAction($action)) {
return false;
}
return sprintf('%s %s', $verb, str_plural($resource));
} | [
"public",
"static",
"function",
"permissionFor",
"(",
"$",
"resource",
",",
"$",
"action",
")",
"{",
"if",
"(",
"!",
"$",
"verb",
"=",
"ResourcePermissions",
"::",
"permissionVerbForAction",
"(",
"$",
"action",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"sprintf",
"(",
"'%s %s'",
",",
"$",
"verb",
",",
"str_plural",
"(",
"$",
"resource",
")",
")",
";",
"}"
] | Returns the permission name for a specific resource and action (Laravel std)
@param string $resource Resource name eg. 'user', 'category', 'subscription'
@param string $action Action name eg. 'index', 'show', 'store'
@see https://laravel.com/docs/5.4/controllers#resource-controllers
@see Route::resource()
@return bool|string | [
"Returns",
"the",
"permission",
"name",
"for",
"a",
"specific",
"resource",
"and",
"action",
"(",
"Laravel",
"std",
")"
] | train | https://github.com/artkonekt/appshell/blob/2ec5d9b36cf65eec619d7daa37ab66d0fd4d9d3b/src/Acl/ResourcePermissions.php#L116-L123 |
artkonekt/appshell | src/Acl/ResourcePermissions.php | ResourcePermissions.allPermissionsFor | public static function allPermissionsFor($resource)
{
$result = [];
foreach (static::$permissions as $permission) {
$result[] = sprintf('%s %s', $permission, str_plural($resource));
}
return $result;
} | php | public static function allPermissionsFor($resource)
{
$result = [];
foreach (static::$permissions as $permission) {
$result[] = sprintf('%s %s', $permission, str_plural($resource));
}
return $result;
} | [
"public",
"static",
"function",
"allPermissionsFor",
"(",
"$",
"resource",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"static",
"::",
"$",
"permissions",
"as",
"$",
"permission",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"sprintf",
"(",
"'%s %s'",
",",
"$",
"permission",
",",
"str_plural",
"(",
"$",
"resource",
")",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Returns all the standard permissions for a resource
@param $resource
@return array | [
"Returns",
"all",
"the",
"standard",
"permissions",
"for",
"a",
"resource"
] | train | https://github.com/artkonekt/appshell/blob/2ec5d9b36cf65eec619d7daa37ab66d0fd4d9d3b/src/Acl/ResourcePermissions.php#L132-L140 |
artkonekt/appshell | src/resources/database/migrations/2018_05_27_210939_create_settings_permissions.php | CreateSettingsPermissions.down | public function down()
{
$adminRole = RoleProxy::where(['name' => 'admin'])->first();
if ($adminRole) {
$adminRole->revokePermissionTo(
ResourcePermissions::allPermissionsFor('setting')
);
}
ResourcePermissions::deletePermissionsForResource('setting');
} | php | public function down()
{
$adminRole = RoleProxy::where(['name' => 'admin'])->first();
if ($adminRole) {
$adminRole->revokePermissionTo(
ResourcePermissions::allPermissionsFor('setting')
);
}
ResourcePermissions::deletePermissionsForResource('setting');
} | [
"public",
"function",
"down",
"(",
")",
"{",
"$",
"adminRole",
"=",
"RoleProxy",
"::",
"where",
"(",
"[",
"'name'",
"=>",
"'admin'",
"]",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"$",
"adminRole",
")",
"{",
"$",
"adminRole",
"->",
"revokePermissionTo",
"(",
"ResourcePermissions",
"::",
"allPermissionsFor",
"(",
"'setting'",
")",
")",
";",
"}",
"ResourcePermissions",
"::",
"deletePermissionsForResource",
"(",
"'setting'",
")",
";",
"}"
] | Reverse the migrations.
@return void | [
"Reverse",
"the",
"migrations",
"."
] | train | https://github.com/artkonekt/appshell/blob/2ec5d9b36cf65eec619d7daa37ab66d0fd4d9d3b/src/resources/database/migrations/2018_05_27_210939_create_settings_permissions.php#L24-L34 |
artkonekt/appshell | src/Http/Controllers/RoleController.php | RoleController.store | public function store(CreateRole $request)
{
try {
$role = RoleProxy::create($request->except('permissions'));
$role->syncPermissions($request->permissions());
flash()->success(__('The :name role has been created', ['name' => $role->name]));
} catch (\Exception $e) {
flash()->error(__('Error: :msg', ['msg' => $e->getMessage()]));
return redirect()->back();
}
return redirect(route('appshell.role.index'));
} | php | public function store(CreateRole $request)
{
try {
$role = RoleProxy::create($request->except('permissions'));
$role->syncPermissions($request->permissions());
flash()->success(__('The :name role has been created', ['name' => $role->name]));
} catch (\Exception $e) {
flash()->error(__('Error: :msg', ['msg' => $e->getMessage()]));
return redirect()->back();
}
return redirect(route('appshell.role.index'));
} | [
"public",
"function",
"store",
"(",
"CreateRole",
"$",
"request",
")",
"{",
"try",
"{",
"$",
"role",
"=",
"RoleProxy",
"::",
"create",
"(",
"$",
"request",
"->",
"except",
"(",
"'permissions'",
")",
")",
";",
"$",
"role",
"->",
"syncPermissions",
"(",
"$",
"request",
"->",
"permissions",
"(",
")",
")",
";",
"flash",
"(",
")",
"->",
"success",
"(",
"__",
"(",
"'The :name role has been created'",
",",
"[",
"'name'",
"=>",
"$",
"role",
"->",
"name",
"]",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"flash",
"(",
")",
"->",
"error",
"(",
"__",
"(",
"'Error: :msg'",
",",
"[",
"'msg'",
"=>",
"$",
"e",
"->",
"getMessage",
"(",
")",
"]",
")",
")",
";",
"return",
"redirect",
"(",
")",
"->",
"back",
"(",
")",
";",
"}",
"return",
"redirect",
"(",
"route",
"(",
"'appshell.role.index'",
")",
")",
";",
"}"
] | @param CreateRole $request
@return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector | [
"@param",
"CreateRole",
"$request"
] | train | https://github.com/artkonekt/appshell/blob/2ec5d9b36cf65eec619d7daa37ab66d0fd4d9d3b/src/Http/Controllers/RoleController.php#L64-L77 |
artkonekt/appshell | src/Http/Controllers/RoleController.php | RoleController.update | public function update(Role $role, UpdateRole $request)
{
try {
$role->update($request->except('permissions'));
$role->syncPermissions($request->permissions());
flash()->success(__('The :name role has been updated', ['name' => $role->name]));
} catch (\Exception $e) {
flash()->error(__('Error: :msg', ['msg' => $e->getMessage()]));
return redirect()->back();
}
return redirect(route('appshell.role.show', $role));
} | php | public function update(Role $role, UpdateRole $request)
{
try {
$role->update($request->except('permissions'));
$role->syncPermissions($request->permissions());
flash()->success(__('The :name role has been updated', ['name' => $role->name]));
} catch (\Exception $e) {
flash()->error(__('Error: :msg', ['msg' => $e->getMessage()]));
return redirect()->back();
}
return redirect(route('appshell.role.show', $role));
} | [
"public",
"function",
"update",
"(",
"Role",
"$",
"role",
",",
"UpdateRole",
"$",
"request",
")",
"{",
"try",
"{",
"$",
"role",
"->",
"update",
"(",
"$",
"request",
"->",
"except",
"(",
"'permissions'",
")",
")",
";",
"$",
"role",
"->",
"syncPermissions",
"(",
"$",
"request",
"->",
"permissions",
"(",
")",
")",
";",
"flash",
"(",
")",
"->",
"success",
"(",
"__",
"(",
"'The :name role has been updated'",
",",
"[",
"'name'",
"=>",
"$",
"role",
"->",
"name",
"]",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"flash",
"(",
")",
"->",
"error",
"(",
"__",
"(",
"'Error: :msg'",
",",
"[",
"'msg'",
"=>",
"$",
"e",
"->",
"getMessage",
"(",
")",
"]",
")",
")",
";",
"return",
"redirect",
"(",
")",
"->",
"back",
"(",
")",
";",
"}",
"return",
"redirect",
"(",
"route",
"(",
"'appshell.role.show'",
",",
"$",
"role",
")",
")",
";",
"}"
] | @param Role $role
@param UpdateRole $request
@return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector | [
"@param",
"Role",
"$role",
"@param",
"UpdateRole",
"$request"
] | train | https://github.com/artkonekt/appshell/blob/2ec5d9b36cf65eec619d7daa37ab66d0fd4d9d3b/src/Http/Controllers/RoleController.php#L97-L110 |
artkonekt/appshell | src/Http/Controllers/RoleController.php | RoleController.destroy | public function destroy(Role $role)
{
try {
$name = $role->name;
$role->delete();
flash()->info(__('The :name role has been deleted', ['name' => $name]));
} catch (\Exception $e) {
flash()->error(__('Error: :msg', ['msg' => $e->getMessage()]));
}
return redirect(route('appshell.role.index'));
} | php | public function destroy(Role $role)
{
try {
$name = $role->name;
$role->delete();
flash()->info(__('The :name role has been deleted', ['name' => $name]));
} catch (\Exception $e) {
flash()->error(__('Error: :msg', ['msg' => $e->getMessage()]));
}
return redirect(route('appshell.role.index'));
} | [
"public",
"function",
"destroy",
"(",
"Role",
"$",
"role",
")",
"{",
"try",
"{",
"$",
"name",
"=",
"$",
"role",
"->",
"name",
";",
"$",
"role",
"->",
"delete",
"(",
")",
";",
"flash",
"(",
")",
"->",
"info",
"(",
"__",
"(",
"'The :name role has been deleted'",
",",
"[",
"'name'",
"=>",
"$",
"name",
"]",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"flash",
"(",
")",
"->",
"error",
"(",
"__",
"(",
"'Error: :msg'",
",",
"[",
"'msg'",
"=>",
"$",
"e",
"->",
"getMessage",
"(",
")",
"]",
")",
")",
";",
"}",
"return",
"redirect",
"(",
"route",
"(",
"'appshell.role.index'",
")",
")",
";",
"}"
] | Delete a role
@param Role $role
@return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector | [
"Delete",
"a",
"role"
] | train | https://github.com/artkonekt/appshell/blob/2ec5d9b36cf65eec619d7daa37ab66d0fd4d9d3b/src/Http/Controllers/RoleController.php#L119-L131 |
yiisoft/yii2-twig | src/Template.php | Template.attribute | public static function attribute(\Twig_Environment $env, \Twig_Source $source, $object, $item, array $arguments = [], string $type = \Twig_Template::ANY_CALL, bool $isDefinedTest = false, bool $ignoreStrictCheck = false)
{
if (
$type !== \Twig_Template::METHOD_CALL &&
($object instanceof Object || $object instanceof \yii\base\Model) &&
$object->canGetProperty($item)
) {
return $isDefinedTest ? true : $object->$item;
}
// Convert any Twig_Markup arguments back to strings (unless the class *extends* Twig_Markup)
foreach ($arguments as $key => $value) {
if (is_object($value) && get_class($value) === \Twig_Markup::class) {
$arguments[$key] = (string)$value;
}
}
return \twig_get_attribute($env, $source, $object, $item, $arguments, $type, $isDefinedTest, $ignoreStrictCheck);
} | php | public static function attribute(\Twig_Environment $env, \Twig_Source $source, $object, $item, array $arguments = [], string $type = \Twig_Template::ANY_CALL, bool $isDefinedTest = false, bool $ignoreStrictCheck = false)
{
if (
$type !== \Twig_Template::METHOD_CALL &&
($object instanceof Object || $object instanceof \yii\base\Model) &&
$object->canGetProperty($item)
) {
return $isDefinedTest ? true : $object->$item;
}
// Convert any Twig_Markup arguments back to strings (unless the class *extends* Twig_Markup)
foreach ($arguments as $key => $value) {
if (is_object($value) && get_class($value) === \Twig_Markup::class) {
$arguments[$key] = (string)$value;
}
}
return \twig_get_attribute($env, $source, $object, $item, $arguments, $type, $isDefinedTest, $ignoreStrictCheck);
} | [
"public",
"static",
"function",
"attribute",
"(",
"\\",
"Twig_Environment",
"$",
"env",
",",
"\\",
"Twig_Source",
"$",
"source",
",",
"$",
"object",
",",
"$",
"item",
",",
"array",
"$",
"arguments",
"=",
"[",
"]",
",",
"string",
"$",
"type",
"=",
"\\",
"Twig_Template",
"::",
"ANY_CALL",
",",
"bool",
"$",
"isDefinedTest",
"=",
"false",
",",
"bool",
"$",
"ignoreStrictCheck",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"type",
"!==",
"\\",
"Twig_Template",
"::",
"METHOD_CALL",
"&&",
"(",
"$",
"object",
"instanceof",
"Object",
"||",
"$",
"object",
"instanceof",
"\\",
"yii",
"\\",
"base",
"\\",
"Model",
")",
"&&",
"$",
"object",
"->",
"canGetProperty",
"(",
"$",
"item",
")",
")",
"{",
"return",
"$",
"isDefinedTest",
"?",
"true",
":",
"$",
"object",
"->",
"$",
"item",
";",
"}",
"// Convert any Twig_Markup arguments back to strings (unless the class *extends* Twig_Markup)",
"foreach",
"(",
"$",
"arguments",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
"&&",
"get_class",
"(",
"$",
"value",
")",
"===",
"\\",
"Twig_Markup",
"::",
"class",
")",
"{",
"$",
"arguments",
"[",
"$",
"key",
"]",
"=",
"(",
"string",
")",
"$",
"value",
";",
"}",
"}",
"return",
"\\",
"twig_get_attribute",
"(",
"$",
"env",
",",
"$",
"source",
",",
"$",
"object",
",",
"$",
"item",
",",
"$",
"arguments",
",",
"$",
"type",
",",
"$",
"isDefinedTest",
",",
"$",
"ignoreStrictCheck",
")",
";",
"}"
] | Returns the attribute value for a given array/object.
@param \Twig_Environment $env
@param \Twig_Source $source
@param mixed $object The object or array from where to get the item
@param mixed $item The item to get from the array or object
@param array $arguments An array of arguments to pass if the item is an object method
@param string $type The type of attribute (@see Twig_Template constants)
@param bool $isDefinedTest Whether this is only a defined check
@param bool $ignoreStrictCheck Whether to ignore the strict attribute check or not
@return mixed The attribute value, or a Boolean when $isDefinedTest is true, or null when the attribute is not set and $ignoreStrictCheck is true
@throws \Twig_Error_Runtime if the attribute does not exist and Twig is running in strict mode and $isDefinedTest is false
@internal | [
"Returns",
"the",
"attribute",
"value",
"for",
"a",
"given",
"array",
"/",
"object",
"."
] | train | https://github.com/yiisoft/yii2-twig/blob/1329eb105341c8c31ac8ceb0d37c9b49207789f4/src/Template.php#L33-L49 |
yiisoft/yii2-twig | src/ViewRenderer.php | ViewRenderer.render | public function render($view, $file, $params)
{
$this->twig->addGlobal('this', $view);
$loader = new \Twig_Loader_Filesystem(dirname($file));
if ($view instanceof View) {
$this->addFallbackPaths($loader, $view->theme);
}
$this->addAliases($loader, Yii::$aliases);
$this->twig->setLoader($loader);
// Change lexer syntax (must be set after other settings)
if (!empty($this->lexerOptions)) {
$this->setLexerOptions($this->lexerOptions);
}
return $this->twig->render(pathinfo($file, PATHINFO_BASENAME), $params);
} | php | public function render($view, $file, $params)
{
$this->twig->addGlobal('this', $view);
$loader = new \Twig_Loader_Filesystem(dirname($file));
if ($view instanceof View) {
$this->addFallbackPaths($loader, $view->theme);
}
$this->addAliases($loader, Yii::$aliases);
$this->twig->setLoader($loader);
// Change lexer syntax (must be set after other settings)
if (!empty($this->lexerOptions)) {
$this->setLexerOptions($this->lexerOptions);
}
return $this->twig->render(pathinfo($file, PATHINFO_BASENAME), $params);
} | [
"public",
"function",
"render",
"(",
"$",
"view",
",",
"$",
"file",
",",
"$",
"params",
")",
"{",
"$",
"this",
"->",
"twig",
"->",
"addGlobal",
"(",
"'this'",
",",
"$",
"view",
")",
";",
"$",
"loader",
"=",
"new",
"\\",
"Twig_Loader_Filesystem",
"(",
"dirname",
"(",
"$",
"file",
")",
")",
";",
"if",
"(",
"$",
"view",
"instanceof",
"View",
")",
"{",
"$",
"this",
"->",
"addFallbackPaths",
"(",
"$",
"loader",
",",
"$",
"view",
"->",
"theme",
")",
";",
"}",
"$",
"this",
"->",
"addAliases",
"(",
"$",
"loader",
",",
"Yii",
"::",
"$",
"aliases",
")",
";",
"$",
"this",
"->",
"twig",
"->",
"setLoader",
"(",
"$",
"loader",
")",
";",
"// Change lexer syntax (must be set after other settings)",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"lexerOptions",
")",
")",
"{",
"$",
"this",
"->",
"setLexerOptions",
"(",
"$",
"this",
"->",
"lexerOptions",
")",
";",
"}",
"return",
"$",
"this",
"->",
"twig",
"->",
"render",
"(",
"pathinfo",
"(",
"$",
"file",
",",
"PATHINFO_BASENAME",
")",
",",
"$",
"params",
")",
";",
"}"
] | Renders a view file.
This method is invoked by [[View]] whenever it tries to render a view.
Child classes must implement this method to render the given view file.
@param View $view the view object used for rendering the file.
@param string $file the view file.
@param array $params the parameters to be passed to the view file.
@return string the rendering result | [
"Renders",
"a",
"view",
"file",
"."
] | train | https://github.com/yiisoft/yii2-twig/blob/1329eb105341c8c31ac8ceb0d37c9b49207789f4/src/ViewRenderer.php#L160-L177 |
yiisoft/yii2-twig | src/ViewRenderer.php | ViewRenderer.addAliases | protected function addAliases($loader, $aliases)
{
foreach ($aliases as $alias => $path) {
if (is_array($path)) {
$this->addAliases($loader, $path);
} elseif (is_string($path) && is_dir($path)) {
$loader->addPath($path, substr($alias, 1));
}
}
} | php | protected function addAliases($loader, $aliases)
{
foreach ($aliases as $alias => $path) {
if (is_array($path)) {
$this->addAliases($loader, $path);
} elseif (is_string($path) && is_dir($path)) {
$loader->addPath($path, substr($alias, 1));
}
}
} | [
"protected",
"function",
"addAliases",
"(",
"$",
"loader",
",",
"$",
"aliases",
")",
"{",
"foreach",
"(",
"$",
"aliases",
"as",
"$",
"alias",
"=>",
"$",
"path",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"path",
")",
")",
"{",
"$",
"this",
"->",
"addAliases",
"(",
"$",
"loader",
",",
"$",
"path",
")",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"path",
")",
"&&",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"$",
"loader",
"->",
"addPath",
"(",
"$",
"path",
",",
"substr",
"(",
"$",
"alias",
",",
"1",
")",
")",
";",
"}",
"}",
"}"
] | Adds aliases
@param \Twig_Loader_Filesystem $loader
@param array $aliases | [
"Adds",
"aliases"
] | train | https://github.com/yiisoft/yii2-twig/blob/1329eb105341c8c31ac8ceb0d37c9b49207789f4/src/ViewRenderer.php#L185-L194 |
yiisoft/yii2-twig | src/ViewRenderer.php | ViewRenderer.addFallbackPaths | protected function addFallbackPaths($loader, $theme)
{
foreach ($this->twigFallbackPaths as $namespace => $path) {
$path = Yii::getAlias($path);
if (!is_dir($path)) {
continue;
}
if (is_string($namespace)) {
$loader->addPath($path, $namespace);
} else {
$loader->addPath($path);
}
}
if ($theme instanceOf \yii\base\Theme && is_array($theme->pathMap)) {
$pathMap = $theme->pathMap;
if (isset($pathMap['@app/views'])) {
foreach ((array)$pathMap['@app/views'] as $path) {
$path = Yii::getAlias($path);
if (is_dir($path)) {
$loader->addPath($path, $this->twigViewsNamespace);
}
}
}
if (isset($pathMap['@app/modules'])) {
foreach ((array)$pathMap['@app/modules'] as $path) {
$path = Yii::getAlias($path);
if (is_dir($path)) {
$loader->addPath($path, $this->twigModulesNamespace);
}
}
}
if (isset($pathMap['@app/widgets'])) {
foreach ((array)$pathMap['@app/widgets'] as $path) {
$path = Yii::getAlias($path);
if (is_dir($path)) {
$loader->addPath($path, $this->twigWidgetsNamespace);
}
}
}
}
$defaultViewsPath = Yii::getAlias('@app/views');
if (is_dir($defaultViewsPath)) {
$loader->addPath($defaultViewsPath, $this->twigViewsNamespace);
}
$defaultModulesPath = Yii::getAlias('@app/modules');
if (is_dir($defaultModulesPath)) {
$loader->addPath($defaultModulesPath, $this->twigModulesNamespace);
}
$defaultWidgetsPath = Yii::getAlias('@app/widgets');
if (is_dir($defaultWidgetsPath)) {
$loader->addPath($defaultWidgetsPath, $this->twigWidgetsNamespace);
}
} | php | protected function addFallbackPaths($loader, $theme)
{
foreach ($this->twigFallbackPaths as $namespace => $path) {
$path = Yii::getAlias($path);
if (!is_dir($path)) {
continue;
}
if (is_string($namespace)) {
$loader->addPath($path, $namespace);
} else {
$loader->addPath($path);
}
}
if ($theme instanceOf \yii\base\Theme && is_array($theme->pathMap)) {
$pathMap = $theme->pathMap;
if (isset($pathMap['@app/views'])) {
foreach ((array)$pathMap['@app/views'] as $path) {
$path = Yii::getAlias($path);
if (is_dir($path)) {
$loader->addPath($path, $this->twigViewsNamespace);
}
}
}
if (isset($pathMap['@app/modules'])) {
foreach ((array)$pathMap['@app/modules'] as $path) {
$path = Yii::getAlias($path);
if (is_dir($path)) {
$loader->addPath($path, $this->twigModulesNamespace);
}
}
}
if (isset($pathMap['@app/widgets'])) {
foreach ((array)$pathMap['@app/widgets'] as $path) {
$path = Yii::getAlias($path);
if (is_dir($path)) {
$loader->addPath($path, $this->twigWidgetsNamespace);
}
}
}
}
$defaultViewsPath = Yii::getAlias('@app/views');
if (is_dir($defaultViewsPath)) {
$loader->addPath($defaultViewsPath, $this->twigViewsNamespace);
}
$defaultModulesPath = Yii::getAlias('@app/modules');
if (is_dir($defaultModulesPath)) {
$loader->addPath($defaultModulesPath, $this->twigModulesNamespace);
}
$defaultWidgetsPath = Yii::getAlias('@app/widgets');
if (is_dir($defaultWidgetsPath)) {
$loader->addPath($defaultWidgetsPath, $this->twigWidgetsNamespace);
}
} | [
"protected",
"function",
"addFallbackPaths",
"(",
"$",
"loader",
",",
"$",
"theme",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"twigFallbackPaths",
"as",
"$",
"namespace",
"=>",
"$",
"path",
")",
"{",
"$",
"path",
"=",
"Yii",
"::",
"getAlias",
"(",
"$",
"path",
")",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"namespace",
")",
")",
"{",
"$",
"loader",
"->",
"addPath",
"(",
"$",
"path",
",",
"$",
"namespace",
")",
";",
"}",
"else",
"{",
"$",
"loader",
"->",
"addPath",
"(",
"$",
"path",
")",
";",
"}",
"}",
"if",
"(",
"$",
"theme",
"instanceOf",
"\\",
"yii",
"\\",
"base",
"\\",
"Theme",
"&&",
"is_array",
"(",
"$",
"theme",
"->",
"pathMap",
")",
")",
"{",
"$",
"pathMap",
"=",
"$",
"theme",
"->",
"pathMap",
";",
"if",
"(",
"isset",
"(",
"$",
"pathMap",
"[",
"'@app/views'",
"]",
")",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"pathMap",
"[",
"'@app/views'",
"]",
"as",
"$",
"path",
")",
"{",
"$",
"path",
"=",
"Yii",
"::",
"getAlias",
"(",
"$",
"path",
")",
";",
"if",
"(",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"$",
"loader",
"->",
"addPath",
"(",
"$",
"path",
",",
"$",
"this",
"->",
"twigViewsNamespace",
")",
";",
"}",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"pathMap",
"[",
"'@app/modules'",
"]",
")",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"pathMap",
"[",
"'@app/modules'",
"]",
"as",
"$",
"path",
")",
"{",
"$",
"path",
"=",
"Yii",
"::",
"getAlias",
"(",
"$",
"path",
")",
";",
"if",
"(",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"$",
"loader",
"->",
"addPath",
"(",
"$",
"path",
",",
"$",
"this",
"->",
"twigModulesNamespace",
")",
";",
"}",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"pathMap",
"[",
"'@app/widgets'",
"]",
")",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"pathMap",
"[",
"'@app/widgets'",
"]",
"as",
"$",
"path",
")",
"{",
"$",
"path",
"=",
"Yii",
"::",
"getAlias",
"(",
"$",
"path",
")",
";",
"if",
"(",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"$",
"loader",
"->",
"addPath",
"(",
"$",
"path",
",",
"$",
"this",
"->",
"twigWidgetsNamespace",
")",
";",
"}",
"}",
"}",
"}",
"$",
"defaultViewsPath",
"=",
"Yii",
"::",
"getAlias",
"(",
"'@app/views'",
")",
";",
"if",
"(",
"is_dir",
"(",
"$",
"defaultViewsPath",
")",
")",
"{",
"$",
"loader",
"->",
"addPath",
"(",
"$",
"defaultViewsPath",
",",
"$",
"this",
"->",
"twigViewsNamespace",
")",
";",
"}",
"$",
"defaultModulesPath",
"=",
"Yii",
"::",
"getAlias",
"(",
"'@app/modules'",
")",
";",
"if",
"(",
"is_dir",
"(",
"$",
"defaultModulesPath",
")",
")",
"{",
"$",
"loader",
"->",
"addPath",
"(",
"$",
"defaultModulesPath",
",",
"$",
"this",
"->",
"twigModulesNamespace",
")",
";",
"}",
"$",
"defaultWidgetsPath",
"=",
"Yii",
"::",
"getAlias",
"(",
"'@app/widgets'",
")",
";",
"if",
"(",
"is_dir",
"(",
"$",
"defaultWidgetsPath",
")",
")",
"{",
"$",
"loader",
"->",
"addPath",
"(",
"$",
"defaultWidgetsPath",
",",
"$",
"this",
"->",
"twigWidgetsNamespace",
")",
";",
"}",
"}"
] | Adds fallback paths to twig loader
@param \Twig_Loader_Filesystem $loader
@param \yii\base\Theme|null $theme
@since 2.0.5 | [
"Adds",
"fallback",
"paths",
"to",
"twig",
"loader"
] | train | https://github.com/yiisoft/yii2-twig/blob/1329eb105341c8c31ac8ceb0d37c9b49207789f4/src/ViewRenderer.php#L203-L263 |
yiisoft/yii2-twig | src/ViewRenderer.php | ViewRenderer.addGlobals | public function addGlobals($globals)
{
foreach ($globals as $name => $value) {
if (is_array($value) && isset($value['class'])) {
$value = new ViewRendererStaticClassProxy($value['class']);
}
$this->twig->addGlobal($name, $value);
}
} | php | public function addGlobals($globals)
{
foreach ($globals as $name => $value) {
if (is_array($value) && isset($value['class'])) {
$value = new ViewRendererStaticClassProxy($value['class']);
}
$this->twig->addGlobal($name, $value);
}
} | [
"public",
"function",
"addGlobals",
"(",
"$",
"globals",
")",
"{",
"foreach",
"(",
"$",
"globals",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
"&&",
"isset",
"(",
"$",
"value",
"[",
"'class'",
"]",
")",
")",
"{",
"$",
"value",
"=",
"new",
"ViewRendererStaticClassProxy",
"(",
"$",
"value",
"[",
"'class'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"twig",
"->",
"addGlobal",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"}"
] | Adds global objects or static classes
@param array $globals @see self::$globals | [
"Adds",
"global",
"objects",
"or",
"static",
"classes"
] | train | https://github.com/yiisoft/yii2-twig/blob/1329eb105341c8c31ac8ceb0d37c9b49207789f4/src/ViewRenderer.php#L269-L277 |
yiisoft/yii2-twig | src/ViewRenderer.php | ViewRenderer.addExtensions | public function addExtensions($extensions)
{
foreach ($extensions as $extName) {
$this->twig->addExtension(is_object($extName) ? $extName : Yii::createObject($extName));
}
} | php | public function addExtensions($extensions)
{
foreach ($extensions as $extName) {
$this->twig->addExtension(is_object($extName) ? $extName : Yii::createObject($extName));
}
} | [
"public",
"function",
"addExtensions",
"(",
"$",
"extensions",
")",
"{",
"foreach",
"(",
"$",
"extensions",
"as",
"$",
"extName",
")",
"{",
"$",
"this",
"->",
"twig",
"->",
"addExtension",
"(",
"is_object",
"(",
"$",
"extName",
")",
"?",
"$",
"extName",
":",
"Yii",
"::",
"createObject",
"(",
"$",
"extName",
")",
")",
";",
"}",
"}"
] | Adds custom extensions
@param array $extensions @see self::$extensions | [
"Adds",
"custom",
"extensions"
] | train | https://github.com/yiisoft/yii2-twig/blob/1329eb105341c8c31ac8ceb0d37c9b49207789f4/src/ViewRenderer.php#L301-L306 |
yiisoft/yii2-twig | src/ViewRenderer.php | ViewRenderer.setLexerOptions | public function setLexerOptions($options)
{
$lexer = new \Twig_Lexer($this->twig, $options);
$this->twig->setLexer($lexer);
} | php | public function setLexerOptions($options)
{
$lexer = new \Twig_Lexer($this->twig, $options);
$this->twig->setLexer($lexer);
} | [
"public",
"function",
"setLexerOptions",
"(",
"$",
"options",
")",
"{",
"$",
"lexer",
"=",
"new",
"\\",
"Twig_Lexer",
"(",
"$",
"this",
"->",
"twig",
",",
"$",
"options",
")",
";",
"$",
"this",
"->",
"twig",
"->",
"setLexer",
"(",
"$",
"lexer",
")",
";",
"}"
] | Sets Twig lexer options to change templates syntax
@param array $options @see self::$lexerOptions | [
"Sets",
"Twig",
"lexer",
"options",
"to",
"change",
"templates",
"syntax"
] | train | https://github.com/yiisoft/yii2-twig/blob/1329eb105341c8c31ac8ceb0d37c9b49207789f4/src/ViewRenderer.php#L312-L316 |
yiisoft/yii2-twig | src/ViewRenderer.php | ViewRenderer._addCustom | private function _addCustom($classType, $elements)
{
$classFunction = 'Twig_Simple' . $classType;
foreach ($elements as $name => $func) {
$twigElement = null;
switch ($func) {
// Callable (including just a name of function).
case is_callable($func):
$twigElement = new $classFunction($name, $func);
break;
// Callable (including just a name of function) + options array.
case is_array($func) && is_callable($func[0]):
$twigElement = new $classFunction($name, $func[0], (!empty($func[1]) && is_array($func[1])) ? $func[1] : []);
break;
case $func instanceof \Twig_SimpleFunction || $func instanceof \Twig_SimpleFilter:
$twigElement = $func;
}
if ($twigElement !== null) {
$this->twig->{'add'.$classType}($twigElement);
} else {
throw new \Exception("Incorrect options for \"$classType\" $name.");
}
}
} | php | private function _addCustom($classType, $elements)
{
$classFunction = 'Twig_Simple' . $classType;
foreach ($elements as $name => $func) {
$twigElement = null;
switch ($func) {
// Callable (including just a name of function).
case is_callable($func):
$twigElement = new $classFunction($name, $func);
break;
// Callable (including just a name of function) + options array.
case is_array($func) && is_callable($func[0]):
$twigElement = new $classFunction($name, $func[0], (!empty($func[1]) && is_array($func[1])) ? $func[1] : []);
break;
case $func instanceof \Twig_SimpleFunction || $func instanceof \Twig_SimpleFilter:
$twigElement = $func;
}
if ($twigElement !== null) {
$this->twig->{'add'.$classType}($twigElement);
} else {
throw new \Exception("Incorrect options for \"$classType\" $name.");
}
}
} | [
"private",
"function",
"_addCustom",
"(",
"$",
"classType",
",",
"$",
"elements",
")",
"{",
"$",
"classFunction",
"=",
"'Twig_Simple'",
".",
"$",
"classType",
";",
"foreach",
"(",
"$",
"elements",
"as",
"$",
"name",
"=>",
"$",
"func",
")",
"{",
"$",
"twigElement",
"=",
"null",
";",
"switch",
"(",
"$",
"func",
")",
"{",
"// Callable (including just a name of function).",
"case",
"is_callable",
"(",
"$",
"func",
")",
":",
"$",
"twigElement",
"=",
"new",
"$",
"classFunction",
"(",
"$",
"name",
",",
"$",
"func",
")",
";",
"break",
";",
"// Callable (including just a name of function) + options array.",
"case",
"is_array",
"(",
"$",
"func",
")",
"&&",
"is_callable",
"(",
"$",
"func",
"[",
"0",
"]",
")",
":",
"$",
"twigElement",
"=",
"new",
"$",
"classFunction",
"(",
"$",
"name",
",",
"$",
"func",
"[",
"0",
"]",
",",
"(",
"!",
"empty",
"(",
"$",
"func",
"[",
"1",
"]",
")",
"&&",
"is_array",
"(",
"$",
"func",
"[",
"1",
"]",
")",
")",
"?",
"$",
"func",
"[",
"1",
"]",
":",
"[",
"]",
")",
";",
"break",
";",
"case",
"$",
"func",
"instanceof",
"\\",
"Twig_SimpleFunction",
"||",
"$",
"func",
"instanceof",
"\\",
"Twig_SimpleFilter",
":",
"$",
"twigElement",
"=",
"$",
"func",
";",
"}",
"if",
"(",
"$",
"twigElement",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"twig",
"->",
"{",
"'add'",
".",
"$",
"classType",
"}",
"(",
"$",
"twigElement",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Incorrect options for \\\"$classType\\\" $name.\"",
")",
";",
"}",
"}",
"}"
] | Adds custom function or filter
@param string $classType 'Function' or 'Filter'
@param array $elements Parameters of elements to add
@throws \Exception | [
"Adds",
"custom",
"function",
"or",
"filter"
] | train | https://github.com/yiisoft/yii2-twig/blob/1329eb105341c8c31ac8ceb0d37c9b49207789f4/src/ViewRenderer.php#L324-L350 |
yiisoft/yii2-twig | src/Extension.php | Extension.registerAsset | public function registerAsset($context, $asset)
{
return $this->resolveAndCall($asset, 'register', [
isset($context['this']) ? $context['this'] : null,
]);
} | php | public function registerAsset($context, $asset)
{
return $this->resolveAndCall($asset, 'register', [
isset($context['this']) ? $context['this'] : null,
]);
} | [
"public",
"function",
"registerAsset",
"(",
"$",
"context",
",",
"$",
"asset",
")",
"{",
"return",
"$",
"this",
"->",
"resolveAndCall",
"(",
"$",
"asset",
",",
"'register'",
",",
"[",
"isset",
"(",
"$",
"context",
"[",
"'this'",
"]",
")",
"?",
"$",
"context",
"[",
"'this'",
"]",
":",
"null",
",",
"]",
")",
";",
"}"
] | Function for registering an asset
```
{{ use('yii/web/JqueryAsset') }}
{{ register_jquery_asset() }}
```
@param array $context context information
@param string $asset asset name
@return mixed | [
"Function",
"for",
"registering",
"an",
"asset"
] | train | https://github.com/yiisoft/yii2-twig/blob/1329eb105341c8c31ac8ceb0d37c9b49207789f4/src/Extension.php#L102-L107 |
yiisoft/yii2-twig | src/Extension.php | Extension.registerAssetBundle | public function registerAssetBundle($context, $bundle, $return = false)
{
$bundle = str_replace('/', '\\', $bundle);
$bundle = $this->call($bundle, 'register', [
isset($context['this']) ? $context['this'] : null,
]);
if ($return) {
return $bundle;
}
} | php | public function registerAssetBundle($context, $bundle, $return = false)
{
$bundle = str_replace('/', '\\', $bundle);
$bundle = $this->call($bundle, 'register', [
isset($context['this']) ? $context['this'] : null,
]);
if ($return) {
return $bundle;
}
} | [
"public",
"function",
"registerAssetBundle",
"(",
"$",
"context",
",",
"$",
"bundle",
",",
"$",
"return",
"=",
"false",
")",
"{",
"$",
"bundle",
"=",
"str_replace",
"(",
"'/'",
",",
"'\\\\'",
",",
"$",
"bundle",
")",
";",
"$",
"bundle",
"=",
"$",
"this",
"->",
"call",
"(",
"$",
"bundle",
",",
"'register'",
",",
"[",
"isset",
"(",
"$",
"context",
"[",
"'this'",
"]",
")",
"?",
"$",
"context",
"[",
"'this'",
"]",
":",
"null",
",",
"]",
")",
";",
"if",
"(",
"$",
"return",
")",
"{",
"return",
"$",
"bundle",
";",
"}",
"}"
] | Function for additional syntax of registering asset bundles
```
{{ register_asset_bundle('yii/web/JqueryAsset') }}
```
@param array $context context information
@param string $bundle asset bundle class fully qualified name
@param bool $return indicates if AssetBundle should be returned
@return void|AssetBundle
@since 2.0.4 | [
"Function",
"for",
"additional",
"syntax",
"of",
"registering",
"asset",
"bundles"
] | train | https://github.com/yiisoft/yii2-twig/blob/1329eb105341c8c31ac8ceb0d37c9b49207789f4/src/Extension.php#L123-L134 |
yiisoft/yii2-twig | src/Extension.php | Extension.beginWidget | public function beginWidget($widget, $config = [])
{
$widget = $this->resolveClassName($widget);
$this->widgets[] = $widget;
return $this->call($widget, 'begin', [
$config,
]);
} | php | public function beginWidget($widget, $config = [])
{
$widget = $this->resolveClassName($widget);
$this->widgets[] = $widget;
return $this->call($widget, 'begin', [
$config,
]);
} | [
"public",
"function",
"beginWidget",
"(",
"$",
"widget",
",",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"$",
"widget",
"=",
"$",
"this",
"->",
"resolveClassName",
"(",
"$",
"widget",
")",
";",
"$",
"this",
"->",
"widgets",
"[",
"]",
"=",
"$",
"widget",
";",
"return",
"$",
"this",
"->",
"call",
"(",
"$",
"widget",
",",
"'begin'",
",",
"[",
"$",
"config",
",",
"]",
")",
";",
"}"
] | Function for *_begin syntax support
@param string $widget widget name
@param array $config widget config
@return mixed | [
"Function",
"for",
"*",
"_begin",
"syntax",
"support"
] | train | https://github.com/yiisoft/yii2-twig/blob/1329eb105341c8c31ac8ceb0d37c9b49207789f4/src/Extension.php#L143-L150 |
yiisoft/yii2-twig | src/Extension.php | Extension.viewHelper | public function viewHelper($context, $name = null)
{
if ($name !== null && isset($context['this'])) {
$this->call($context['this'], Inflector::variablize($name));
}
} | php | public function viewHelper($context, $name = null)
{
if ($name !== null && isset($context['this'])) {
$this->call($context['this'], Inflector::variablize($name));
}
} | [
"public",
"function",
"viewHelper",
"(",
"$",
"context",
",",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"name",
"!==",
"null",
"&&",
"isset",
"(",
"$",
"context",
"[",
"'this'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"call",
"(",
"$",
"context",
"[",
"'this'",
"]",
",",
"Inflector",
"::",
"variablize",
"(",
"$",
"name",
")",
")",
";",
"}",
"}"
] | Used for 'begin_page', 'end_page', 'begin_body', 'end_body', 'head'
@param array $context context information
@param string $name | [
"Used",
"for",
"begin_page",
"end_page",
"begin_body",
"end_body",
"head"
] | train | https://github.com/yiisoft/yii2-twig/blob/1329eb105341c8c31ac8ceb0d37c9b49207789f4/src/Extension.php#L190-L195 |
yiisoft/yii2-twig | src/Extension.php | Extension.resolveAndCall | public function resolveAndCall($className, $method, $arguments = null)
{
return $this->call($this->resolveClassName($className), $method, $arguments);
} | php | public function resolveAndCall($className, $method, $arguments = null)
{
return $this->call($this->resolveClassName($className), $method, $arguments);
} | [
"public",
"function",
"resolveAndCall",
"(",
"$",
"className",
",",
"$",
"method",
",",
"$",
"arguments",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"call",
"(",
"$",
"this",
"->",
"resolveClassName",
"(",
"$",
"className",
")",
",",
"$",
"method",
",",
"$",
"arguments",
")",
";",
"}"
] | Resolves a method from widget and asset syntax and calls it
@param string $className class name
@param string $method method name
@param array $arguments
@return mixed | [
"Resolves",
"a",
"method",
"from",
"widget",
"and",
"asset",
"syntax",
"and",
"calls",
"it"
] | train | https://github.com/yiisoft/yii2-twig/blob/1329eb105341c8c31ac8ceb0d37c9b49207789f4/src/Extension.php#L205-L208 |
yiisoft/yii2-twig | src/Extension.php | Extension.call | public function call($className, $method, $arguments = null)
{
$callable = [$className, $method];
if ($arguments === null) {
return call_user_func($callable);
} else {
return call_user_func_array($callable, $arguments);
}
} | php | public function call($className, $method, $arguments = null)
{
$callable = [$className, $method];
if ($arguments === null) {
return call_user_func($callable);
} else {
return call_user_func_array($callable, $arguments);
}
} | [
"public",
"function",
"call",
"(",
"$",
"className",
",",
"$",
"method",
",",
"$",
"arguments",
"=",
"null",
")",
"{",
"$",
"callable",
"=",
"[",
"$",
"className",
",",
"$",
"method",
"]",
";",
"if",
"(",
"$",
"arguments",
"===",
"null",
")",
"{",
"return",
"call_user_func",
"(",
"$",
"callable",
")",
";",
"}",
"else",
"{",
"return",
"call_user_func_array",
"(",
"$",
"callable",
",",
"$",
"arguments",
")",
";",
"}",
"}"
] | Calls a method
@param string $className class name
@param string $method method name
@param array $arguments
@return mixed | [
"Calls",
"a",
"method"
] | train | https://github.com/yiisoft/yii2-twig/blob/1329eb105341c8c31ac8ceb0d37c9b49207789f4/src/Extension.php#L218-L226 |
yiisoft/yii2-twig | src/Extension.php | Extension.resolveClassName | public function resolveClassName($className)
{
$className = Inflector::id2camel($className, '_');
if (isset($this->aliases[$className])) {
return $this->aliases[$className];
}
foreach ($this->namespaces as $namespace) {
$resolvedClassName = $namespace . '\\' . $className;
if (class_exists($resolvedClassName)) {
return $this->aliases[$className] = $resolvedClassName;
}
}
return $className;
} | php | public function resolveClassName($className)
{
$className = Inflector::id2camel($className, '_');
if (isset($this->aliases[$className])) {
return $this->aliases[$className];
}
foreach ($this->namespaces as $namespace) {
$resolvedClassName = $namespace . '\\' . $className;
if (class_exists($resolvedClassName)) {
return $this->aliases[$className] = $resolvedClassName;
}
}
return $className;
} | [
"public",
"function",
"resolveClassName",
"(",
"$",
"className",
")",
"{",
"$",
"className",
"=",
"Inflector",
"::",
"id2camel",
"(",
"$",
"className",
",",
"'_'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"aliases",
"[",
"$",
"className",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"aliases",
"[",
"$",
"className",
"]",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"namespaces",
"as",
"$",
"namespace",
")",
"{",
"$",
"resolvedClassName",
"=",
"$",
"namespace",
".",
"'\\\\'",
".",
"$",
"className",
";",
"if",
"(",
"class_exists",
"(",
"$",
"resolvedClassName",
")",
")",
"{",
"return",
"$",
"this",
"->",
"aliases",
"[",
"$",
"className",
"]",
"=",
"$",
"resolvedClassName",
";",
"}",
"}",
"return",
"$",
"className",
";",
"}"
] | Resolves class name from widget and asset syntax
@param string $className class name
@return string | [
"Resolves",
"class",
"name",
"from",
"widget",
"and",
"asset",
"syntax"
] | train | https://github.com/yiisoft/yii2-twig/blob/1329eb105341c8c31ac8ceb0d37c9b49207789f4/src/Extension.php#L234-L247 |
yiisoft/yii2-twig | src/Extension.php | Extension.addUses | public function addUses($args)
{
foreach ((array)$args as $key => $value) {
$value = str_replace('/', '\\', $value);
if (is_int($key)) {
// namespace or class import
if (class_exists($value)) {
// class import
$this->aliases[StringHelper::basename($value)] = $value;
} else {
// namespace
$this->namespaces[] = $value;
}
} else {
// aliased class import
$this->aliases[$key] = $value;
}
}
} | php | public function addUses($args)
{
foreach ((array)$args as $key => $value) {
$value = str_replace('/', '\\', $value);
if (is_int($key)) {
// namespace or class import
if (class_exists($value)) {
// class import
$this->aliases[StringHelper::basename($value)] = $value;
} else {
// namespace
$this->namespaces[] = $value;
}
} else {
// aliased class import
$this->aliases[$key] = $value;
}
}
} | [
"public",
"function",
"addUses",
"(",
"$",
"args",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"args",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"str_replace",
"(",
"'/'",
",",
"'\\\\'",
",",
"$",
"value",
")",
";",
"if",
"(",
"is_int",
"(",
"$",
"key",
")",
")",
"{",
"// namespace or class import",
"if",
"(",
"class_exists",
"(",
"$",
"value",
")",
")",
"{",
"// class import",
"$",
"this",
"->",
"aliases",
"[",
"StringHelper",
"::",
"basename",
"(",
"$",
"value",
")",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"// namespace",
"$",
"this",
"->",
"namespaces",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"else",
"{",
"// aliased class import",
"$",
"this",
"->",
"aliases",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}"
] | Adds namespaces and aliases from constructor
@param array $args namespaces and classes to use in the template | [
"Adds",
"namespaces",
"and",
"aliases",
"from",
"constructor"
] | train | https://github.com/yiisoft/yii2-twig/blob/1329eb105341c8c31ac8ceb0d37c9b49207789f4/src/Extension.php#L254-L272 |
yiisoft/yii2-twig | src/Extension.php | Extension.path | public function path($path, $args = [])
{
if (is_array($path)) {
$path = array_merge($path, $args);
} elseif ($args !== []) {
$path = array_merge([$path], $args);
}
return Url::to($path);
} | php | public function path($path, $args = [])
{
if (is_array($path)) {
$path = array_merge($path, $args);
} elseif ($args !== []) {
$path = array_merge([$path], $args);
}
return Url::to($path);
} | [
"public",
"function",
"path",
"(",
"$",
"path",
",",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"path",
")",
")",
"{",
"$",
"path",
"=",
"array_merge",
"(",
"$",
"path",
",",
"$",
"args",
")",
";",
"}",
"elseif",
"(",
"$",
"args",
"!==",
"[",
"]",
")",
"{",
"$",
"path",
"=",
"array_merge",
"(",
"[",
"$",
"path",
"]",
",",
"$",
"args",
")",
";",
"}",
"return",
"Url",
"::",
"to",
"(",
"$",
"path",
")",
";",
"}"
] | Generates relative URL
@param string $path the parameter to be used to generate a valid URL
@param array $args arguments
@return string the generated relative URL | [
"Generates",
"relative",
"URL"
] | train | https://github.com/yiisoft/yii2-twig/blob/1329eb105341c8c31ac8ceb0d37c9b49207789f4/src/Extension.php#L281-L290 |
yiisoft/yii2-twig | src/Extension.php | Extension.url | public function url($path, $args = [])
{
if (is_array($path)) {
$path = array_merge($path, $args);
} elseif ($args !== []) {
$path = array_merge([$path], $args);
}
return Url::to($path, true);
} | php | public function url($path, $args = [])
{
if (is_array($path)) {
$path = array_merge($path, $args);
} elseif ($args !== []) {
$path = array_merge([$path], $args);
}
return Url::to($path, true);
} | [
"public",
"function",
"url",
"(",
"$",
"path",
",",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"path",
")",
")",
"{",
"$",
"path",
"=",
"array_merge",
"(",
"$",
"path",
",",
"$",
"args",
")",
";",
"}",
"elseif",
"(",
"$",
"args",
"!==",
"[",
"]",
")",
"{",
"$",
"path",
"=",
"array_merge",
"(",
"[",
"$",
"path",
"]",
",",
"$",
"args",
")",
";",
"}",
"return",
"Url",
"::",
"to",
"(",
"$",
"path",
",",
"true",
")",
";",
"}"
] | Generates absolute URL
@param string $path the parameter to be used to generate a valid URL
@param array $args arguments
@return string the generated absolute URL | [
"Generates",
"absolute",
"URL"
] | train | https://github.com/yiisoft/yii2-twig/blob/1329eb105341c8c31ac8ceb0d37c9b49207789f4/src/Extension.php#L299-L308 |
MrRio/shellwrap | src/MrRio/ShellInspector.php | ShellInspector._dump | public function _dump($value) {
if (is_object($value) && get_class($value) == 'MrRio\ShellWrap') {
echo strval($value);
// Return zero, as this is the exit code
// Otherwise an exception was thrown
return 0;
}
return parent::_dump($value);
} | php | public function _dump($value) {
if (is_object($value) && get_class($value) == 'MrRio\ShellWrap') {
echo strval($value);
// Return zero, as this is the exit code
// Otherwise an exception was thrown
return 0;
}
return parent::_dump($value);
} | [
"public",
"function",
"_dump",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
"&&",
"get_class",
"(",
"$",
"value",
")",
"==",
"'MrRio\\ShellWrap'",
")",
"{",
"echo",
"strval",
"(",
"$",
"value",
")",
";",
"// Return zero, as this is the exit code",
"// Otherwise an exception was thrown",
"return",
"0",
";",
"}",
"return",
"parent",
"::",
"_dump",
"(",
"$",
"value",
")",
";",
"}"
] | Override the public dump function, so we can display plain
text from ShellWrap instead of an object dump. | [
"Override",
"the",
"public",
"dump",
"function",
"so",
"we",
"can",
"display",
"plain",
"text",
"from",
"ShellWrap",
"instead",
"of",
"an",
"object",
"dump",
"."
] | train | https://github.com/MrRio/shellwrap/blob/0a46166ee5d4eb55945d7dfd295c69342b98ba40/src/MrRio/ShellInspector.php#L10-L20 |
lode/jsonapi | src/error.php | error.get_array | public function get_array() {
$response_part = array();
// the basics
$response_part['status'] = $this->http_status;
if (base::$debug) {
$response_part['code'] = $this->error_message;
}
// user guidance
if ($this->friendly_message) {
$response_part['title'] = $this->friendly_message;
}
if ($this->friendly_detail) {
$response_part['detail'] = $this->friendly_detail;
}
// the source of the problem
if ($this->post_body_pointer || $this->get_parameter_name) {
$response_part['source'] = array();
if ($this->post_body_pointer) {
$response_part['source']['pointer'] = $this->post_body_pointer;
}
if ($this->get_parameter_name) {
$response_part['source']['parameter'] = $this->get_parameter_name;
}
}
// technical guidance
if ($this->about_link) {
$response_part['links'] = array(
'about' => $this->about_link,
);
}
if ($this->identifier) {
$response_part['id'] = $this->identifier;
}
// meta data
if ($this->meta_data) {
$response_part['meta'] = $this->meta_data;
}
return $response_part;
} | php | public function get_array() {
$response_part = array();
// the basics
$response_part['status'] = $this->http_status;
if (base::$debug) {
$response_part['code'] = $this->error_message;
}
// user guidance
if ($this->friendly_message) {
$response_part['title'] = $this->friendly_message;
}
if ($this->friendly_detail) {
$response_part['detail'] = $this->friendly_detail;
}
// the source of the problem
if ($this->post_body_pointer || $this->get_parameter_name) {
$response_part['source'] = array();
if ($this->post_body_pointer) {
$response_part['source']['pointer'] = $this->post_body_pointer;
}
if ($this->get_parameter_name) {
$response_part['source']['parameter'] = $this->get_parameter_name;
}
}
// technical guidance
if ($this->about_link) {
$response_part['links'] = array(
'about' => $this->about_link,
);
}
if ($this->identifier) {
$response_part['id'] = $this->identifier;
}
// meta data
if ($this->meta_data) {
$response_part['meta'] = $this->meta_data;
}
return $response_part;
} | [
"public",
"function",
"get_array",
"(",
")",
"{",
"$",
"response_part",
"=",
"array",
"(",
")",
";",
"// the basics",
"$",
"response_part",
"[",
"'status'",
"]",
"=",
"$",
"this",
"->",
"http_status",
";",
"if",
"(",
"base",
"::",
"$",
"debug",
")",
"{",
"$",
"response_part",
"[",
"'code'",
"]",
"=",
"$",
"this",
"->",
"error_message",
";",
"}",
"// user guidance",
"if",
"(",
"$",
"this",
"->",
"friendly_message",
")",
"{",
"$",
"response_part",
"[",
"'title'",
"]",
"=",
"$",
"this",
"->",
"friendly_message",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"friendly_detail",
")",
"{",
"$",
"response_part",
"[",
"'detail'",
"]",
"=",
"$",
"this",
"->",
"friendly_detail",
";",
"}",
"// the source of the problem",
"if",
"(",
"$",
"this",
"->",
"post_body_pointer",
"||",
"$",
"this",
"->",
"get_parameter_name",
")",
"{",
"$",
"response_part",
"[",
"'source'",
"]",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"post_body_pointer",
")",
"{",
"$",
"response_part",
"[",
"'source'",
"]",
"[",
"'pointer'",
"]",
"=",
"$",
"this",
"->",
"post_body_pointer",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"get_parameter_name",
")",
"{",
"$",
"response_part",
"[",
"'source'",
"]",
"[",
"'parameter'",
"]",
"=",
"$",
"this",
"->",
"get_parameter_name",
";",
"}",
"}",
"// technical guidance",
"if",
"(",
"$",
"this",
"->",
"about_link",
")",
"{",
"$",
"response_part",
"[",
"'links'",
"]",
"=",
"array",
"(",
"'about'",
"=>",
"$",
"this",
"->",
"about_link",
",",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"identifier",
")",
"{",
"$",
"response_part",
"[",
"'id'",
"]",
"=",
"$",
"this",
"->",
"identifier",
";",
"}",
"// meta data",
"if",
"(",
"$",
"this",
"->",
"meta_data",
")",
"{",
"$",
"response_part",
"[",
"'meta'",
"]",
"=",
"$",
"this",
"->",
"meta_data",
";",
"}",
"return",
"$",
"response_part",
";",
"}"
] | generates an array for inclusion in the whole response body of an errors collection
@note error message (`code`) is only shown when debug mode is on (@see base::$debug)
@see jsonapi.org/format
@return array, containing:
- status
- code
- title
- detail
- source
- pointer
- parameter
- links
- about
- id
- meta | [
"generates",
"an",
"array",
"for",
"inclusion",
"in",
"the",
"whole",
"response",
"body",
"of",
"an",
"errors",
"collection"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/error.php#L91-L136 |
lode/jsonapi | src/error.php | error.set_http_status | public function set_http_status($http_status) {
if (is_int($http_status)) {
$http_status = (string)$http_status;
// add status message for a few known ones
if (isset(self::$http_status_messages[$http_status])) {
$http_status .= ' '.self::$http_status_messages[$http_status];
}
}
$this->http_status = $http_status;
} | php | public function set_http_status($http_status) {
if (is_int($http_status)) {
$http_status = (string)$http_status;
// add status message for a few known ones
if (isset(self::$http_status_messages[$http_status])) {
$http_status .= ' '.self::$http_status_messages[$http_status];
}
}
$this->http_status = $http_status;
} | [
"public",
"function",
"set_http_status",
"(",
"$",
"http_status",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"http_status",
")",
")",
"{",
"$",
"http_status",
"=",
"(",
"string",
")",
"$",
"http_status",
";",
"// add status message for a few known ones",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"http_status_messages",
"[",
"$",
"http_status",
"]",
")",
")",
"{",
"$",
"http_status",
".=",
"' '",
".",
"self",
"::",
"$",
"http_status_messages",
"[",
"$",
"http_status",
"]",
";",
"}",
"}",
"$",
"this",
"->",
"http_status",
"=",
"$",
"http_status",
";",
"}"
] | sets a status code for the single error
this will end up in response.errors[].status
@note this does only hint but not strictly set the actual status code send out to the browser
use jsonapi\errors->set_http_status() to be sure
@param mixed $http_status string: an http status, should start with the numeric status code
integer: one of the predefined ones in response::STATUS_* ..
.. will be converted to string | [
"sets",
"a",
"status",
"code",
"for",
"the",
"single",
"error",
"this",
"will",
"end",
"up",
"in",
"response",
".",
"errors",
"[]",
".",
"status"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/error.php#L159-L170 |
lode/jsonapi | src/error.php | error.set_about_link | public function set_about_link($about_link, $meta_data=null) {
if ($meta_data) {
if (is_object($meta_data)) {
$meta_data = parent::convert_object_to_array($meta_data);
}
$about_link = array(
'href' => $about_link,
'meta' => $meta_data,
);
}
$this->about_link = $about_link;
} | php | public function set_about_link($about_link, $meta_data=null) {
if ($meta_data) {
if (is_object($meta_data)) {
$meta_data = parent::convert_object_to_array($meta_data);
}
$about_link = array(
'href' => $about_link,
'meta' => $meta_data,
);
}
$this->about_link = $about_link;
} | [
"public",
"function",
"set_about_link",
"(",
"$",
"about_link",
",",
"$",
"meta_data",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"meta_data",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"meta_data",
")",
")",
"{",
"$",
"meta_data",
"=",
"parent",
"::",
"convert_object_to_array",
"(",
"$",
"meta_data",
")",
";",
"}",
"$",
"about_link",
"=",
"array",
"(",
"'href'",
"=>",
"$",
"about_link",
",",
"'meta'",
"=>",
"$",
"meta_data",
",",
")",
";",
"}",
"$",
"this",
"->",
"about_link",
"=",
"$",
"about_link",
";",
"}"
] | sets a link which can help in solving the problem
this will end up in response.errors[].links.about
@param string $about_link string with link
@param mixed $meta_data optional, meta data as key-value pairs
objects are converted in arrays, @see base::convert_object_to_array() | [
"sets",
"a",
"link",
"which",
"can",
"help",
"in",
"solving",
"the",
"problem",
"this",
"will",
"end",
"up",
"in",
"response",
".",
"errors",
"[]",
".",
"links",
".",
"about"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/error.php#L236-L249 |
lode/jsonapi | src/error.php | error.add_meta | public function add_meta($key, $meta_data) {
if (is_object($meta_data)) {
$meta_data = parent::convert_object_to_array($meta_data);
}
$this->meta_data[$key] = $meta_data;
} | php | public function add_meta($key, $meta_data) {
if (is_object($meta_data)) {
$meta_data = parent::convert_object_to_array($meta_data);
}
$this->meta_data[$key] = $meta_data;
} | [
"public",
"function",
"add_meta",
"(",
"$",
"key",
",",
"$",
"meta_data",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"meta_data",
")",
")",
"{",
"$",
"meta_data",
"=",
"parent",
"::",
"convert_object_to_array",
"(",
"$",
"meta_data",
")",
";",
"}",
"$",
"this",
"->",
"meta_data",
"[",
"$",
"key",
"]",
"=",
"$",
"meta_data",
";",
"}"
] | adds some meta data
this will end up in response.errors[].meta.{$key}
@param string $key
@param mixed $meta_data objects are converted in arrays, @see base::convert_object_to_array()
@return void | [
"adds",
"some",
"meta",
"data",
"this",
"will",
"end",
"up",
"in",
"response",
".",
"errors",
"[]",
".",
"meta",
".",
"{",
"$key",
"}"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/error.php#L270-L276 |
lode/jsonapi | src/error.php | error.fill_meta | public function fill_meta($meta_data) {
foreach ($meta_data as $key => $single_meta_data) {
$this->add_meta($key, $single_meta_data);
}
} | php | public function fill_meta($meta_data) {
foreach ($meta_data as $key => $single_meta_data) {
$this->add_meta($key, $single_meta_data);
}
} | [
"public",
"function",
"fill_meta",
"(",
"$",
"meta_data",
")",
"{",
"foreach",
"(",
"$",
"meta_data",
"as",
"$",
"key",
"=>",
"$",
"single_meta_data",
")",
"{",
"$",
"this",
"->",
"add_meta",
"(",
"$",
"key",
",",
"$",
"single_meta_data",
")",
";",
"}",
"}"
] | fills the meta data
this will end up in response.meta
@param array $meta_data
@return void | [
"fills",
"the",
"meta",
"data",
"this",
"will",
"end",
"up",
"in",
"response",
".",
"meta"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/error.php#L285-L289 |
lode/jsonapi | src/collection.php | collection.get_array | public function get_array() {
$response = array();
// links
if ($this->links) {
$response['links'] = $this->links;
}
// primary data
$response['data'] = $this->primary_collection;
// included resources
if ($this->included_data) {
$response['included'] = array_values($this->included_data);
}
// meta data
if ($this->meta_data) {
$response['meta'] = $this->meta_data;
}
return $response;
} | php | public function get_array() {
$response = array();
// links
if ($this->links) {
$response['links'] = $this->links;
}
// primary data
$response['data'] = $this->primary_collection;
// included resources
if ($this->included_data) {
$response['included'] = array_values($this->included_data);
}
// meta data
if ($this->meta_data) {
$response['meta'] = $this->meta_data;
}
return $response;
} | [
"public",
"function",
"get_array",
"(",
")",
"{",
"$",
"response",
"=",
"array",
"(",
")",
";",
"// links",
"if",
"(",
"$",
"this",
"->",
"links",
")",
"{",
"$",
"response",
"[",
"'links'",
"]",
"=",
"$",
"this",
"->",
"links",
";",
"}",
"// primary data",
"$",
"response",
"[",
"'data'",
"]",
"=",
"$",
"this",
"->",
"primary_collection",
";",
"// included resources",
"if",
"(",
"$",
"this",
"->",
"included_data",
")",
"{",
"$",
"response",
"[",
"'included'",
"]",
"=",
"array_values",
"(",
"$",
"this",
"->",
"included_data",
")",
";",
"}",
"// meta data",
"if",
"(",
"$",
"this",
"->",
"meta_data",
")",
"{",
"$",
"response",
"[",
"'meta'",
"]",
"=",
"$",
"this",
"->",
"meta_data",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | generates an array for the whole response body
@see jsonapi.org/format
@return array, containing:
- links
- data []
- {everything from the resource's data-key}
- included {from the resource's included-key}
- meta | [
"generates",
"an",
"array",
"for",
"the",
"whole",
"response",
"body"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/collection.php#L60-L82 |
lode/jsonapi | src/collection.php | collection.add_resource | public function add_resource(\alsvanzelf\jsonapi\resource $resource) {
$resource_array = $resource->get_array();
$included_resources = $resource->get_included_resources();
if (!empty($included_resources)) {
$this->fill_included_resources($included_resources);
}
// root-level meta-data
if (!empty($resource_array['meta'])) {
$this->fill_meta($resource_array['meta']);
}
$this->primary_collection[] = $resource_array['data'];
// make a backup of the actual resource, to pass on as a collection for a relation
$this->primary_resource_objects[] = $resource;
} | php | public function add_resource(\alsvanzelf\jsonapi\resource $resource) {
$resource_array = $resource->get_array();
$included_resources = $resource->get_included_resources();
if (!empty($included_resources)) {
$this->fill_included_resources($included_resources);
}
// root-level meta-data
if (!empty($resource_array['meta'])) {
$this->fill_meta($resource_array['meta']);
}
$this->primary_collection[] = $resource_array['data'];
// make a backup of the actual resource, to pass on as a collection for a relation
$this->primary_resource_objects[] = $resource;
} | [
"public",
"function",
"add_resource",
"(",
"\\",
"alsvanzelf",
"\\",
"jsonapi",
"\\",
"resource",
"$",
"resource",
")",
"{",
"$",
"resource_array",
"=",
"$",
"resource",
"->",
"get_array",
"(",
")",
";",
"$",
"included_resources",
"=",
"$",
"resource",
"->",
"get_included_resources",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"included_resources",
")",
")",
"{",
"$",
"this",
"->",
"fill_included_resources",
"(",
"$",
"included_resources",
")",
";",
"}",
"// root-level meta-data",
"if",
"(",
"!",
"empty",
"(",
"$",
"resource_array",
"[",
"'meta'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"fill_meta",
"(",
"$",
"resource_array",
"[",
"'meta'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"primary_collection",
"[",
"]",
"=",
"$",
"resource_array",
"[",
"'data'",
"]",
";",
"// make a backup of the actual resource, to pass on as a collection for a relation",
"$",
"this",
"->",
"primary_resource_objects",
"[",
"]",
"=",
"$",
"resource",
";",
"}"
] | adds a resource to the primary collection
this will end up in response.data[]
@note only data and meta(root-level) of a resource are used
that is its type, id, attributes, relations, links, meta(data-level)
and meta(root-level) is added to response.meta[]
further, its included resources are separately added to response.included[]
@see jsonapi\resource
@see ->fill_collection() for adding a whole array of resources directly
@param \alsvanzelf\jsonapi\resource $resource
@return void | [
"adds",
"a",
"resource",
"to",
"the",
"primary",
"collection",
"this",
"will",
"end",
"up",
"in",
"response",
".",
"data",
"[]"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/collection.php#L109-L126 |
lode/jsonapi | src/base.php | base.convert_object_to_array | protected static function convert_object_to_array($object) {
if (is_object($object) == false) {
throw new \Exception('can only convert objects');
}
if ($object instanceof \alsvanzelf\jsonapi\resource) {
return $object->get_array();
}
return get_object_vars($object);
} | php | protected static function convert_object_to_array($object) {
if (is_object($object) == false) {
throw new \Exception('can only convert objects');
}
if ($object instanceof \alsvanzelf\jsonapi\resource) {
return $object->get_array();
}
return get_object_vars($object);
} | [
"protected",
"static",
"function",
"convert_object_to_array",
"(",
"$",
"object",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"object",
")",
"==",
"false",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'can only convert objects'",
")",
";",
"}",
"if",
"(",
"$",
"object",
"instanceof",
"\\",
"alsvanzelf",
"\\",
"jsonapi",
"\\",
"resource",
")",
"{",
"return",
"$",
"object",
"->",
"get_array",
"(",
")",
";",
"}",
"return",
"get_object_vars",
"(",
"$",
"object",
")",
";",
"}"
] | converting an object to an array
@param object $object by default, its public properties are used
if it is a \alsvanzelf\jsonapi\resource, its ->get_array() is used
@return array | [
"converting",
"an",
"object",
"to",
"an",
"array"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/base.php#L85-L95 |
lode/jsonapi | src/objects/RelationshipObject.php | RelationshipObject.fromAnything | public static function fromAnything($relation, array $links=[], array $meta=[]) {
if (is_array($relation)) {
$relation = CollectionDocument::fromResources(...$relation);
}
if ($relation instanceof ResourceInterface) {
$relationshipObject = self::fromResource($relation, $links, $meta);
}
elseif ($relation instanceof CollectionDocument) {
$relationshipObject = self::fromCollectionDocument($relation, $links, $meta);
}
elseif ($relation === null) {
$relationshipObject = new RelationshipObject(RelationshipObject::TO_ONE);
}
else {
throw new InputException('unknown format of relation "'.gettype($relation).'"');
}
return $relationshipObject;
} | php | public static function fromAnything($relation, array $links=[], array $meta=[]) {
if (is_array($relation)) {
$relation = CollectionDocument::fromResources(...$relation);
}
if ($relation instanceof ResourceInterface) {
$relationshipObject = self::fromResource($relation, $links, $meta);
}
elseif ($relation instanceof CollectionDocument) {
$relationshipObject = self::fromCollectionDocument($relation, $links, $meta);
}
elseif ($relation === null) {
$relationshipObject = new RelationshipObject(RelationshipObject::TO_ONE);
}
else {
throw new InputException('unknown format of relation "'.gettype($relation).'"');
}
return $relationshipObject;
} | [
"public",
"static",
"function",
"fromAnything",
"(",
"$",
"relation",
",",
"array",
"$",
"links",
"=",
"[",
"]",
",",
"array",
"$",
"meta",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"relation",
")",
")",
"{",
"$",
"relation",
"=",
"CollectionDocument",
"::",
"fromResources",
"(",
"...",
"$",
"relation",
")",
";",
"}",
"if",
"(",
"$",
"relation",
"instanceof",
"ResourceInterface",
")",
"{",
"$",
"relationshipObject",
"=",
"self",
"::",
"fromResource",
"(",
"$",
"relation",
",",
"$",
"links",
",",
"$",
"meta",
")",
";",
"}",
"elseif",
"(",
"$",
"relation",
"instanceof",
"CollectionDocument",
")",
"{",
"$",
"relationshipObject",
"=",
"self",
"::",
"fromCollectionDocument",
"(",
"$",
"relation",
",",
"$",
"links",
",",
"$",
"meta",
")",
";",
"}",
"elseif",
"(",
"$",
"relation",
"===",
"null",
")",
"{",
"$",
"relationshipObject",
"=",
"new",
"RelationshipObject",
"(",
"RelationshipObject",
"::",
"TO_ONE",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"InputException",
"(",
"'unknown format of relation \"'",
".",
"gettype",
"(",
"$",
"relation",
")",
".",
"'\"'",
")",
";",
"}",
"return",
"$",
"relationshipObject",
";",
"}"
] | create a RelationshipObject from mixed input
@param mixed $relation ResourceInterface | ResourceInterface[] | CollectionDocument
@param array $links optional
@param array $meta optional
@return RelationshipObject
@throws InputException if $relation is not one of the supported formats | [
"create",
"a",
"RelationshipObject",
"from",
"mixed",
"input"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/objects/RelationshipObject.php#L59-L78 |
lode/jsonapi | src/objects/RelationshipObject.php | RelationshipObject.setPaginationLinks | public function setPaginationLinks($previousHref=null, $nextHref=null, $firstHref=null, $lastHref=null) {
if ($this->type === RelationshipObject::TO_ONE) {
throw new InputException('can not add pagination links to a to-one relationship');
}
if ($previousHref !== null) {
$this->addLink('prev', $previousHref);
}
if ($nextHref !== null) {
$this->addLink('next', $nextHref);
}
if ($firstHref !== null) {
$this->addLink('first', $firstHref);
}
if ($lastHref !== null) {
$this->addLink('last', $lastHref);
}
} | php | public function setPaginationLinks($previousHref=null, $nextHref=null, $firstHref=null, $lastHref=null) {
if ($this->type === RelationshipObject::TO_ONE) {
throw new InputException('can not add pagination links to a to-one relationship');
}
if ($previousHref !== null) {
$this->addLink('prev', $previousHref);
}
if ($nextHref !== null) {
$this->addLink('next', $nextHref);
}
if ($firstHref !== null) {
$this->addLink('first', $firstHref);
}
if ($lastHref !== null) {
$this->addLink('last', $lastHref);
}
} | [
"public",
"function",
"setPaginationLinks",
"(",
"$",
"previousHref",
"=",
"null",
",",
"$",
"nextHref",
"=",
"null",
",",
"$",
"firstHref",
"=",
"null",
",",
"$",
"lastHref",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"type",
"===",
"RelationshipObject",
"::",
"TO_ONE",
")",
"{",
"throw",
"new",
"InputException",
"(",
"'can not add pagination links to a to-one relationship'",
")",
";",
"}",
"if",
"(",
"$",
"previousHref",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"addLink",
"(",
"'prev'",
",",
"$",
"previousHref",
")",
";",
"}",
"if",
"(",
"$",
"nextHref",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"addLink",
"(",
"'next'",
",",
"$",
"nextHref",
")",
";",
"}",
"if",
"(",
"$",
"firstHref",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"addLink",
"(",
"'first'",
",",
"$",
"firstHref",
")",
";",
"}",
"if",
"(",
"$",
"lastHref",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"addLink",
"(",
"'last'",
",",
"$",
"lastHref",
")",
";",
"}",
"}"
] | @inheritDoc
@throws InputException if used on a to-one relationship | [
"@inheritDoc"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/objects/RelationshipObject.php#L151-L168 |
lode/jsonapi | src/objects/RelationshipObject.php | RelationshipObject.setResource | public function setResource(ResourceInterface $resource) {
if ($this->type === RelationshipObject::TO_MANY) {
throw new InputException('can not set a resource on a to-many relationship, use ->addResource()');
}
$this->resource = $resource;
} | php | public function setResource(ResourceInterface $resource) {
if ($this->type === RelationshipObject::TO_MANY) {
throw new InputException('can not set a resource on a to-many relationship, use ->addResource()');
}
$this->resource = $resource;
} | [
"public",
"function",
"setResource",
"(",
"ResourceInterface",
"$",
"resource",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"type",
"===",
"RelationshipObject",
"::",
"TO_MANY",
")",
"{",
"throw",
"new",
"InputException",
"(",
"'can not set a resource on a to-many relationship, use ->addResource()'",
")",
";",
"}",
"$",
"this",
"->",
"resource",
"=",
"$",
"resource",
";",
"}"
] | set the resource on a to-one relationship
@param ResourceInterface $resource
@throws InputException if used on a to-many relationship, use {@see ->addResource()} instead | [
"set",
"the",
"resource",
"on",
"a",
"to",
"-",
"one",
"relationship"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/objects/RelationshipObject.php#L193-L199 |
lode/jsonapi | src/objects/RelationshipObject.php | RelationshipObject.addResource | public function addResource(ResourceInterface $resource) {
if ($this->type === RelationshipObject::TO_ONE) {
throw new InputException('can not add a resource to a to-one relationship, use ->setResource()');
}
$this->resources[] = $resource;
} | php | public function addResource(ResourceInterface $resource) {
if ($this->type === RelationshipObject::TO_ONE) {
throw new InputException('can not add a resource to a to-one relationship, use ->setResource()');
}
$this->resources[] = $resource;
} | [
"public",
"function",
"addResource",
"(",
"ResourceInterface",
"$",
"resource",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"type",
"===",
"RelationshipObject",
"::",
"TO_ONE",
")",
"{",
"throw",
"new",
"InputException",
"(",
"'can not add a resource to a to-one relationship, use ->setResource()'",
")",
";",
"}",
"$",
"this",
"->",
"resources",
"[",
"]",
"=",
"$",
"resource",
";",
"}"
] | add a resource to a to-many relationship
@param ResourceInterface $resource
@throws InputException if used on a to-one relationship, use {@see ->setResource()} instead | [
"add",
"a",
"resource",
"to",
"a",
"to",
"-",
"many",
"relationship"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/objects/RelationshipObject.php#L208-L214 |
lode/jsonapi | src/objects/RelationshipObject.php | RelationshipObject.hasResource | public function hasResource(ResourceInterface $otherResource) {
if ($this->isEmpty()) {
return false;
}
if ($this->type === RelationshipObject::TO_ONE) {
return $this->resource->getResource()->equals($otherResource->getResource());
}
if ($this->type === RelationshipObject::TO_MANY) {
foreach ($this->resources as $ownResource) {
if ($ownResource->getResource()->equals($otherResource->getResource())) {
return true;
}
}
}
return false;
} | php | public function hasResource(ResourceInterface $otherResource) {
if ($this->isEmpty()) {
return false;
}
if ($this->type === RelationshipObject::TO_ONE) {
return $this->resource->getResource()->equals($otherResource->getResource());
}
if ($this->type === RelationshipObject::TO_MANY) {
foreach ($this->resources as $ownResource) {
if ($ownResource->getResource()->equals($otherResource->getResource())) {
return true;
}
}
}
return false;
} | [
"public",
"function",
"hasResource",
"(",
"ResourceInterface",
"$",
"otherResource",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isEmpty",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"type",
"===",
"RelationshipObject",
"::",
"TO_ONE",
")",
"{",
"return",
"$",
"this",
"->",
"resource",
"->",
"getResource",
"(",
")",
"->",
"equals",
"(",
"$",
"otherResource",
"->",
"getResource",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"type",
"===",
"RelationshipObject",
"::",
"TO_MANY",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"resources",
"as",
"$",
"ownResource",
")",
"{",
"if",
"(",
"$",
"ownResource",
"->",
"getResource",
"(",
")",
"->",
"equals",
"(",
"$",
"otherResource",
"->",
"getResource",
"(",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] | whether or not the $otherResource is (one of) the resource(s) inside the relationship
@internal
@param ResourceInterface $otherResource
@return boolean | [
"whether",
"or",
"not",
"the",
"$otherResource",
"is",
"(",
"one",
"of",
")",
"the",
"resource",
"(",
"s",
")",
"inside",
"the",
"relationship"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/objects/RelationshipObject.php#L235-L251 |
nicmart/StringTemplate | src/StringTemplate/SprintfEngine.php | SprintfEngine.render | public function render($template, $value)
{
//Performance: if there are no '%' fallback to Engine
if (strstr($template, '%') == false) {
return parent::render($template, $value);
}
$result = $template;
if (!is_array($value))
$value = array('' => $value);
foreach (new NestedKeyIterator(new RecursiveArrayOnlyIterator($value)) as $key => $value) {
$pattern = "/" . $this->left . $key . "(%[^" . $this->right . "]+)?" . $this->right . "/";
preg_match_all($pattern, $template, $matches);
$substs = array_map(function ($match) use ($value) {
return $match !== '' ? sprintf($match, $value) : $value;
}, $matches[1]);
$result = str_replace($matches[0], $substs, $result);
}
return $result;
} | php | public function render($template, $value)
{
//Performance: if there are no '%' fallback to Engine
if (strstr($template, '%') == false) {
return parent::render($template, $value);
}
$result = $template;
if (!is_array($value))
$value = array('' => $value);
foreach (new NestedKeyIterator(new RecursiveArrayOnlyIterator($value)) as $key => $value) {
$pattern = "/" . $this->left . $key . "(%[^" . $this->right . "]+)?" . $this->right . "/";
preg_match_all($pattern, $template, $matches);
$substs = array_map(function ($match) use ($value) {
return $match !== '' ? sprintf($match, $value) : $value;
}, $matches[1]);
$result = str_replace($matches[0], $substs, $result);
}
return $result;
} | [
"public",
"function",
"render",
"(",
"$",
"template",
",",
"$",
"value",
")",
"{",
"//Performance: if there are no '%' fallback to Engine",
"if",
"(",
"strstr",
"(",
"$",
"template",
",",
"'%'",
")",
"==",
"false",
")",
"{",
"return",
"parent",
"::",
"render",
"(",
"$",
"template",
",",
"$",
"value",
")",
";",
"}",
"$",
"result",
"=",
"$",
"template",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
")",
"$",
"value",
"=",
"array",
"(",
"''",
"=>",
"$",
"value",
")",
";",
"foreach",
"(",
"new",
"NestedKeyIterator",
"(",
"new",
"RecursiveArrayOnlyIterator",
"(",
"$",
"value",
")",
")",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"pattern",
"=",
"\"/\"",
".",
"$",
"this",
"->",
"left",
".",
"$",
"key",
".",
"\"(%[^\"",
".",
"$",
"this",
"->",
"right",
".",
"\"]+)?\"",
".",
"$",
"this",
"->",
"right",
".",
"\"/\"",
";",
"preg_match_all",
"(",
"$",
"pattern",
",",
"$",
"template",
",",
"$",
"matches",
")",
";",
"$",
"substs",
"=",
"array_map",
"(",
"function",
"(",
"$",
"match",
")",
"use",
"(",
"$",
"value",
")",
"{",
"return",
"$",
"match",
"!==",
"''",
"?",
"sprintf",
"(",
"$",
"match",
",",
"$",
"value",
")",
":",
"$",
"value",
";",
"}",
",",
"$",
"matches",
"[",
"1",
"]",
")",
";",
"$",
"result",
"=",
"str_replace",
"(",
"$",
"matches",
"[",
"0",
"]",
",",
"$",
"substs",
",",
"$",
"result",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/nicmart/StringTemplate/blob/612eeb821b33c0b67d3755a5b24471e30d4d737b/src/StringTemplate/SprintfEngine.php#L30-L50 |
lode/jsonapi | src/helpers/Converter.php | Converter.mergeProfilesInContentType | public static function mergeProfilesInContentType($contentType, array $profiles) {
if ($profiles === []) {
return $contentType;
}
$profileLinks = [];
foreach ($profiles as $profile) {
$link = $profile->getAliasedLink();
$profileLinks[] = ($link instanceof LinkObject) ? $link->toArray()['href'] : $link;
}
$profileLinks = implode(' ', $profileLinks);
return $contentType.';profile="'.$profileLinks.'", '.$contentType;
} | php | public static function mergeProfilesInContentType($contentType, array $profiles) {
if ($profiles === []) {
return $contentType;
}
$profileLinks = [];
foreach ($profiles as $profile) {
$link = $profile->getAliasedLink();
$profileLinks[] = ($link instanceof LinkObject) ? $link->toArray()['href'] : $link;
}
$profileLinks = implode(' ', $profileLinks);
return $contentType.';profile="'.$profileLinks.'", '.$contentType;
} | [
"public",
"static",
"function",
"mergeProfilesInContentType",
"(",
"$",
"contentType",
",",
"array",
"$",
"profiles",
")",
"{",
"if",
"(",
"$",
"profiles",
"===",
"[",
"]",
")",
"{",
"return",
"$",
"contentType",
";",
"}",
"$",
"profileLinks",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"profiles",
"as",
"$",
"profile",
")",
"{",
"$",
"link",
"=",
"$",
"profile",
"->",
"getAliasedLink",
"(",
")",
";",
"$",
"profileLinks",
"[",
"]",
"=",
"(",
"$",
"link",
"instanceof",
"LinkObject",
")",
"?",
"$",
"link",
"->",
"toArray",
"(",
")",
"[",
"'href'",
"]",
":",
"$",
"link",
";",
"}",
"$",
"profileLinks",
"=",
"implode",
"(",
"' '",
",",
"$",
"profileLinks",
")",
";",
"return",
"$",
"contentType",
".",
"';profile=\"'",
".",
"$",
"profileLinks",
".",
"'\", '",
".",
"$",
"contentType",
";",
"}"
] | generates the value for a content type header, with profiles merged in if available
@param string $contentType
@param ProfileInterface[] $profiles
@return string | [
"generates",
"the",
"value",
"for",
"a",
"content",
"type",
"header",
"with",
"profiles",
"merged",
"in",
"if",
"available"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/helpers/Converter.php#L44-L57 |
nicmart/StringTemplate | src/StringTemplate/NestedKeyIterator.php | NestedKeyIterator.key | public function key()
{
$keys = $this->stack;
$keys[] = parent::key();
return implode($this->keySeparator, $keys);
} | php | public function key()
{
$keys = $this->stack;
$keys[] = parent::key();
return implode($this->keySeparator, $keys);
} | [
"public",
"function",
"key",
"(",
")",
"{",
"$",
"keys",
"=",
"$",
"this",
"->",
"stack",
";",
"$",
"keys",
"[",
"]",
"=",
"parent",
"::",
"key",
"(",
")",
";",
"return",
"implode",
"(",
"$",
"this",
"->",
"keySeparator",
",",
"$",
"keys",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/nicmart/StringTemplate/blob/612eeb821b33c0b67d3755a5b24471e30d4d737b/src/StringTemplate/NestedKeyIterator.php#L78-L84 |
lode/jsonapi | src/resource.php | resource.get_array | public function get_array() {
$response = array();
// links
if ($this->links) {
$response['links'] = $this->links;
}
// primary data
$response['data'] = array(
'type' => $this->primary_type,
);
if ($this->primary_id) {
$response['data']['id'] = $this->primary_id;
}
if ($this->primary_attributes) {
$response['data']['attributes'] = $this->primary_attributes;
}
if ($this->primary_relationships) {
$response['data']['relationships'] = $this->primary_relationships;
}
if ($this->primary_links) {
$response['data']['links'] = $this->primary_links;
}
if ($this->primary_meta_data) {
$response['data']['meta'] = $this->primary_meta_data;
}
// included resources
if ($this->included_data) {
$response['included'] = array_values($this->included_data);
}
// meta data
if ($this->meta_data) {
$response['meta'] = $this->meta_data;
}
return $response;
} | php | public function get_array() {
$response = array();
// links
if ($this->links) {
$response['links'] = $this->links;
}
// primary data
$response['data'] = array(
'type' => $this->primary_type,
);
if ($this->primary_id) {
$response['data']['id'] = $this->primary_id;
}
if ($this->primary_attributes) {
$response['data']['attributes'] = $this->primary_attributes;
}
if ($this->primary_relationships) {
$response['data']['relationships'] = $this->primary_relationships;
}
if ($this->primary_links) {
$response['data']['links'] = $this->primary_links;
}
if ($this->primary_meta_data) {
$response['data']['meta'] = $this->primary_meta_data;
}
// included resources
if ($this->included_data) {
$response['included'] = array_values($this->included_data);
}
// meta data
if ($this->meta_data) {
$response['meta'] = $this->meta_data;
}
return $response;
} | [
"public",
"function",
"get_array",
"(",
")",
"{",
"$",
"response",
"=",
"array",
"(",
")",
";",
"// links",
"if",
"(",
"$",
"this",
"->",
"links",
")",
"{",
"$",
"response",
"[",
"'links'",
"]",
"=",
"$",
"this",
"->",
"links",
";",
"}",
"// primary data",
"$",
"response",
"[",
"'data'",
"]",
"=",
"array",
"(",
"'type'",
"=>",
"$",
"this",
"->",
"primary_type",
",",
")",
";",
"if",
"(",
"$",
"this",
"->",
"primary_id",
")",
"{",
"$",
"response",
"[",
"'data'",
"]",
"[",
"'id'",
"]",
"=",
"$",
"this",
"->",
"primary_id",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"primary_attributes",
")",
"{",
"$",
"response",
"[",
"'data'",
"]",
"[",
"'attributes'",
"]",
"=",
"$",
"this",
"->",
"primary_attributes",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"primary_relationships",
")",
"{",
"$",
"response",
"[",
"'data'",
"]",
"[",
"'relationships'",
"]",
"=",
"$",
"this",
"->",
"primary_relationships",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"primary_links",
")",
"{",
"$",
"response",
"[",
"'data'",
"]",
"[",
"'links'",
"]",
"=",
"$",
"this",
"->",
"primary_links",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"primary_meta_data",
")",
"{",
"$",
"response",
"[",
"'data'",
"]",
"[",
"'meta'",
"]",
"=",
"$",
"this",
"->",
"primary_meta_data",
";",
"}",
"// included resources",
"if",
"(",
"$",
"this",
"->",
"included_data",
")",
"{",
"$",
"response",
"[",
"'included'",
"]",
"=",
"array_values",
"(",
"$",
"this",
"->",
"included_data",
")",
";",
"}",
"// meta data",
"if",
"(",
"$",
"this",
"->",
"meta_data",
")",
"{",
"$",
"response",
"[",
"'meta'",
"]",
"=",
"$",
"this",
"->",
"meta_data",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | generates an array for the whole response body
@see jsonapi.org/format
@return array, containing:
- links
- data
- type
- id
- attributes
- relationships
- links
- meta
- included
- meta | [
"generates",
"an",
"array",
"for",
"the",
"whole",
"response",
"body"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/resource.php#L136-L175 |
lode/jsonapi | src/resource.php | resource.add_data | public function add_data($key, $value) {
if (is_object($value)) {
$value = parent::convert_object_to_array($value);
}
$this->primary_attributes[$key] = $value;
} | php | public function add_data($key, $value) {
if (is_object($value)) {
$value = parent::convert_object_to_array($value);
}
$this->primary_attributes[$key] = $value;
} | [
"public",
"function",
"add_data",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"parent",
"::",
"convert_object_to_array",
"(",
"$",
"value",
")",
";",
"}",
"$",
"this",
"->",
"primary_attributes",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}"
] | adds a data-point to the primary data
this will end up in response.data.attributes.{$key}
values don't have to be scalar, it can be lists or objects as well
@see ->fill_data() for adding a whole array directly
@param string $key
@param mixed $value objects are converted in arrays, @see base::convert_object_to_array()
@return void | [
"adds",
"a",
"data",
"-",
"point",
"to",
"the",
"primary",
"data",
"this",
"will",
"end",
"up",
"in",
"response",
".",
"data",
".",
"attributes",
".",
"{",
"$key",
"}"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/resource.php#L189-L195 |
lode/jsonapi | src/resource.php | resource.fill_data | public function fill_data($values) {
if (is_object($values)) {
$values = parent::convert_object_to_array($values);
}
if (is_array($values) == false) {
throw new \Exception('use add_data() for adding scalar values');
}
if (isset($values['id']) && $values['id'] == $this->primary_id) {
unset($values['id']);
}
foreach ($values as $key => $single_value) {
$this->add_data($key, $single_value);
}
} | php | public function fill_data($values) {
if (is_object($values)) {
$values = parent::convert_object_to_array($values);
}
if (is_array($values) == false) {
throw new \Exception('use add_data() for adding scalar values');
}
if (isset($values['id']) && $values['id'] == $this->primary_id) {
unset($values['id']);
}
foreach ($values as $key => $single_value) {
$this->add_data($key, $single_value);
}
} | [
"public",
"function",
"fill_data",
"(",
"$",
"values",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"values",
")",
")",
"{",
"$",
"values",
"=",
"parent",
"::",
"convert_object_to_array",
"(",
"$",
"values",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"values",
")",
"==",
"false",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'use add_data() for adding scalar values'",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"values",
"[",
"'id'",
"]",
")",
"&&",
"$",
"values",
"[",
"'id'",
"]",
"==",
"$",
"this",
"->",
"primary_id",
")",
"{",
"unset",
"(",
"$",
"values",
"[",
"'id'",
"]",
")",
";",
"}",
"foreach",
"(",
"$",
"values",
"as",
"$",
"key",
"=>",
"$",
"single_value",
")",
"{",
"$",
"this",
"->",
"add_data",
"(",
"$",
"key",
",",
"$",
"single_value",
")",
";",
"}",
"}"
] | fills the primary data
this will end up in response.data.attributes
this is meant for adding an array as the primary data
objects will be converted using their public keys
@note skips an 'id'-key inside $values if identical to the $id given during construction
@see ->add_data()
@param mixed $values objects are converted in arrays, @see base::convert_object_to_array()
@return void | [
"fills",
"the",
"primary",
"data",
"this",
"will",
"end",
"up",
"in",
"response",
".",
"data",
".",
"attributes"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/resource.php#L211-L226 |
lode/jsonapi | src/resource.php | resource.add_relation | public function add_relation($key, $relation, $skip_include=false, $type=null) {
if ($type && in_array($type, array(self::RELATION_TO_ONE, self::RELATION_TO_MANY)) == false) {
throw new \Exception('unknown relation type');
}
if (isset($this->primary_relationships[$key]) && $relation instanceof \alsvanzelf\jsonapi\resource == false) {
throw new \Exception('can not add a relation twice, unless using a resource object');
}
if (isset($this->primary_relationships[$key]) && $relation instanceof \alsvanzelf\jsonapi\resource) {
if ($type != self::RELATION_TO_MANY || isset($this->primary_relationships[$key]['data']['type'])) {
throw new \Exception('$type should be set to RELATION_TO_MANY for resources using the same key');
}
}
if ($relation instanceof \alsvanzelf\jsonapi\collection && $type == self::RELATION_TO_ONE) {
throw new \Exception('collections can only be added as RELATION_TO_MANY');
}
if ($relation instanceof \alsvanzelf\jsonapi\resource == false && $relation instanceof \alsvanzelf\jsonapi\collection == false && is_array($relation) == false) {
throw new \Exception('unknown relation format');
}
if (is_array($relation)) {
$this->primary_relationships[$key] = $relation;
return;
}
if ($relation instanceof \alsvanzelf\jsonapi\resource) {
// add whole resources as included resource, while keeping the relationship
if ($relation->has_data() && $skip_include == false) {
$this->add_included_resource($relation);
}
$base_url = (isset($this->primary_links['self']['href'])) ? $this->primary_links['self']['href'] : $this->primary_links['self'];
$relation_id = $relation->get_id() ?: null;
$relation_data = [
'type' => $relation->get_type(),
'id' => $relation_id,
];
if (isset($this->primary_relationships[$key])) {
$this->primary_relationships[$key]['data'][] = $relation_data;
return;
}
if ($type == self::RELATION_TO_MANY) {
$relation_data = array($relation_data);
}
}
elseif ($relation instanceof \alsvanzelf\jsonapi\collection) {
$relation_resources = $relation->get_resources();
// add whole resources as included resource, while keeping the relationship
if ($relation_resources && $skip_include == false) {
$this->fill_included_resources($relation);
}
$base_url = (isset($this->primary_links['self']['href'])) ? $this->primary_links['self']['href'] : $this->primary_links['self'];
$relation_data = array();
foreach ($relation_resources as $relation_resource) {
$relation_data[] = [
'type' => $relation_resource->get_type(),
'id' => $relation_resource->get_id(),
];
}
}
$this->primary_relationships[$key] = array(
'data' => $relation_data,
);
$relation_links = [];
if (self::$relation_links == self::RELATION_LINKS_RELATIONSHIP || self::$relation_links == self::RELATION_LINKS_BOTH) {
$relation_links['self'] = $base_url.'/relationships/'.$key;
}
if (self::$relation_links == self::RELATION_LINKS_RESOURCE || self::$relation_links == self::RELATION_LINKS_BOTH) {
$relation_links['related'] = $base_url.'/'.$key;
}
if ($relation_links) {
$this->primary_relationships[$key]['links'] = $relation_links;
}
} | php | public function add_relation($key, $relation, $skip_include=false, $type=null) {
if ($type && in_array($type, array(self::RELATION_TO_ONE, self::RELATION_TO_MANY)) == false) {
throw new \Exception('unknown relation type');
}
if (isset($this->primary_relationships[$key]) && $relation instanceof \alsvanzelf\jsonapi\resource == false) {
throw new \Exception('can not add a relation twice, unless using a resource object');
}
if (isset($this->primary_relationships[$key]) && $relation instanceof \alsvanzelf\jsonapi\resource) {
if ($type != self::RELATION_TO_MANY || isset($this->primary_relationships[$key]['data']['type'])) {
throw new \Exception('$type should be set to RELATION_TO_MANY for resources using the same key');
}
}
if ($relation instanceof \alsvanzelf\jsonapi\collection && $type == self::RELATION_TO_ONE) {
throw new \Exception('collections can only be added as RELATION_TO_MANY');
}
if ($relation instanceof \alsvanzelf\jsonapi\resource == false && $relation instanceof \alsvanzelf\jsonapi\collection == false && is_array($relation) == false) {
throw new \Exception('unknown relation format');
}
if (is_array($relation)) {
$this->primary_relationships[$key] = $relation;
return;
}
if ($relation instanceof \alsvanzelf\jsonapi\resource) {
// add whole resources as included resource, while keeping the relationship
if ($relation->has_data() && $skip_include == false) {
$this->add_included_resource($relation);
}
$base_url = (isset($this->primary_links['self']['href'])) ? $this->primary_links['self']['href'] : $this->primary_links['self'];
$relation_id = $relation->get_id() ?: null;
$relation_data = [
'type' => $relation->get_type(),
'id' => $relation_id,
];
if (isset($this->primary_relationships[$key])) {
$this->primary_relationships[$key]['data'][] = $relation_data;
return;
}
if ($type == self::RELATION_TO_MANY) {
$relation_data = array($relation_data);
}
}
elseif ($relation instanceof \alsvanzelf\jsonapi\collection) {
$relation_resources = $relation->get_resources();
// add whole resources as included resource, while keeping the relationship
if ($relation_resources && $skip_include == false) {
$this->fill_included_resources($relation);
}
$base_url = (isset($this->primary_links['self']['href'])) ? $this->primary_links['self']['href'] : $this->primary_links['self'];
$relation_data = array();
foreach ($relation_resources as $relation_resource) {
$relation_data[] = [
'type' => $relation_resource->get_type(),
'id' => $relation_resource->get_id(),
];
}
}
$this->primary_relationships[$key] = array(
'data' => $relation_data,
);
$relation_links = [];
if (self::$relation_links == self::RELATION_LINKS_RELATIONSHIP || self::$relation_links == self::RELATION_LINKS_BOTH) {
$relation_links['self'] = $base_url.'/relationships/'.$key;
}
if (self::$relation_links == self::RELATION_LINKS_RESOURCE || self::$relation_links == self::RELATION_LINKS_BOTH) {
$relation_links['related'] = $base_url.'/'.$key;
}
if ($relation_links) {
$this->primary_relationships[$key]['links'] = $relation_links;
}
} | [
"public",
"function",
"add_relation",
"(",
"$",
"key",
",",
"$",
"relation",
",",
"$",
"skip_include",
"=",
"false",
",",
"$",
"type",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"type",
"&&",
"in_array",
"(",
"$",
"type",
",",
"array",
"(",
"self",
"::",
"RELATION_TO_ONE",
",",
"self",
"::",
"RELATION_TO_MANY",
")",
")",
"==",
"false",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'unknown relation type'",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"primary_relationships",
"[",
"$",
"key",
"]",
")",
"&&",
"$",
"relation",
"instanceof",
"\\",
"alsvanzelf",
"\\",
"jsonapi",
"\\",
"resource",
"==",
"false",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'can not add a relation twice, unless using a resource object'",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"primary_relationships",
"[",
"$",
"key",
"]",
")",
"&&",
"$",
"relation",
"instanceof",
"\\",
"alsvanzelf",
"\\",
"jsonapi",
"\\",
"resource",
")",
"{",
"if",
"(",
"$",
"type",
"!=",
"self",
"::",
"RELATION_TO_MANY",
"||",
"isset",
"(",
"$",
"this",
"->",
"primary_relationships",
"[",
"$",
"key",
"]",
"[",
"'data'",
"]",
"[",
"'type'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'$type should be set to RELATION_TO_MANY for resources using the same key'",
")",
";",
"}",
"}",
"if",
"(",
"$",
"relation",
"instanceof",
"\\",
"alsvanzelf",
"\\",
"jsonapi",
"\\",
"collection",
"&&",
"$",
"type",
"==",
"self",
"::",
"RELATION_TO_ONE",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'collections can only be added as RELATION_TO_MANY'",
")",
";",
"}",
"if",
"(",
"$",
"relation",
"instanceof",
"\\",
"alsvanzelf",
"\\",
"jsonapi",
"\\",
"resource",
"==",
"false",
"&&",
"$",
"relation",
"instanceof",
"\\",
"alsvanzelf",
"\\",
"jsonapi",
"\\",
"collection",
"==",
"false",
"&&",
"is_array",
"(",
"$",
"relation",
")",
"==",
"false",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'unknown relation format'",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"relation",
")",
")",
"{",
"$",
"this",
"->",
"primary_relationships",
"[",
"$",
"key",
"]",
"=",
"$",
"relation",
";",
"return",
";",
"}",
"if",
"(",
"$",
"relation",
"instanceof",
"\\",
"alsvanzelf",
"\\",
"jsonapi",
"\\",
"resource",
")",
"{",
"// add whole resources as included resource, while keeping the relationship",
"if",
"(",
"$",
"relation",
"->",
"has_data",
"(",
")",
"&&",
"$",
"skip_include",
"==",
"false",
")",
"{",
"$",
"this",
"->",
"add_included_resource",
"(",
"$",
"relation",
")",
";",
"}",
"$",
"base_url",
"=",
"(",
"isset",
"(",
"$",
"this",
"->",
"primary_links",
"[",
"'self'",
"]",
"[",
"'href'",
"]",
")",
")",
"?",
"$",
"this",
"->",
"primary_links",
"[",
"'self'",
"]",
"[",
"'href'",
"]",
":",
"$",
"this",
"->",
"primary_links",
"[",
"'self'",
"]",
";",
"$",
"relation_id",
"=",
"$",
"relation",
"->",
"get_id",
"(",
")",
"?",
":",
"null",
";",
"$",
"relation_data",
"=",
"[",
"'type'",
"=>",
"$",
"relation",
"->",
"get_type",
"(",
")",
",",
"'id'",
"=>",
"$",
"relation_id",
",",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"primary_relationships",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"this",
"->",
"primary_relationships",
"[",
"$",
"key",
"]",
"[",
"'data'",
"]",
"[",
"]",
"=",
"$",
"relation_data",
";",
"return",
";",
"}",
"if",
"(",
"$",
"type",
"==",
"self",
"::",
"RELATION_TO_MANY",
")",
"{",
"$",
"relation_data",
"=",
"array",
"(",
"$",
"relation_data",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"relation",
"instanceof",
"\\",
"alsvanzelf",
"\\",
"jsonapi",
"\\",
"collection",
")",
"{",
"$",
"relation_resources",
"=",
"$",
"relation",
"->",
"get_resources",
"(",
")",
";",
"// add whole resources as included resource, while keeping the relationship",
"if",
"(",
"$",
"relation_resources",
"&&",
"$",
"skip_include",
"==",
"false",
")",
"{",
"$",
"this",
"->",
"fill_included_resources",
"(",
"$",
"relation",
")",
";",
"}",
"$",
"base_url",
"=",
"(",
"isset",
"(",
"$",
"this",
"->",
"primary_links",
"[",
"'self'",
"]",
"[",
"'href'",
"]",
")",
")",
"?",
"$",
"this",
"->",
"primary_links",
"[",
"'self'",
"]",
"[",
"'href'",
"]",
":",
"$",
"this",
"->",
"primary_links",
"[",
"'self'",
"]",
";",
"$",
"relation_data",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"relation_resources",
"as",
"$",
"relation_resource",
")",
"{",
"$",
"relation_data",
"[",
"]",
"=",
"[",
"'type'",
"=>",
"$",
"relation_resource",
"->",
"get_type",
"(",
")",
",",
"'id'",
"=>",
"$",
"relation_resource",
"->",
"get_id",
"(",
")",
",",
"]",
";",
"}",
"}",
"$",
"this",
"->",
"primary_relationships",
"[",
"$",
"key",
"]",
"=",
"array",
"(",
"'data'",
"=>",
"$",
"relation_data",
",",
")",
";",
"$",
"relation_links",
"=",
"[",
"]",
";",
"if",
"(",
"self",
"::",
"$",
"relation_links",
"==",
"self",
"::",
"RELATION_LINKS_RELATIONSHIP",
"||",
"self",
"::",
"$",
"relation_links",
"==",
"self",
"::",
"RELATION_LINKS_BOTH",
")",
"{",
"$",
"relation_links",
"[",
"'self'",
"]",
"=",
"$",
"base_url",
".",
"'/relationships/'",
".",
"$",
"key",
";",
"}",
"if",
"(",
"self",
"::",
"$",
"relation_links",
"==",
"self",
"::",
"RELATION_LINKS_RESOURCE",
"||",
"self",
"::",
"$",
"relation_links",
"==",
"self",
"::",
"RELATION_LINKS_BOTH",
")",
"{",
"$",
"relation_links",
"[",
"'related'",
"]",
"=",
"$",
"base_url",
".",
"'/'",
".",
"$",
"key",
";",
"}",
"if",
"(",
"$",
"relation_links",
")",
"{",
"$",
"this",
"->",
"primary_relationships",
"[",
"$",
"key",
"]",
"[",
"'links'",
"]",
"=",
"$",
"relation_links",
";",
"}",
"}"
] | adds a relation to another resource
this will end up in response.data.relationships.{$key}
$relation should be in the following format (any point can be omitted):
- links
- self
- related
- data
- type
- id
if $relation is a jsonapi\resource or jsonapi\collection, it will also add an included resource
@see ->add_included_resource()
@param string $key
@param mixed $relation can be array or jsonapi\resource or jsonapi\collection
@param boolean $skip_include optional, defaults to false
@param string $type optional, defaults to null
@return void
@todo allow to add collections as well | [
"adds",
"a",
"relation",
"to",
"another",
"resource",
"this",
"will",
"end",
"up",
"in",
"response",
".",
"data",
".",
"relationships",
".",
"{",
"$key",
"}"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/resource.php#L251-L330 |
lode/jsonapi | src/resource.php | resource.fill_relations | public function fill_relations($relations, $skip_include=false) {
foreach ($relations as $key => $relation) {
$this->add_relation($key, $relation, $skip_include);
}
} | php | public function fill_relations($relations, $skip_include=false) {
foreach ($relations as $key => $relation) {
$this->add_relation($key, $relation, $skip_include);
}
} | [
"public",
"function",
"fill_relations",
"(",
"$",
"relations",
",",
"$",
"skip_include",
"=",
"false",
")",
"{",
"foreach",
"(",
"$",
"relations",
"as",
"$",
"key",
"=>",
"$",
"relation",
")",
"{",
"$",
"this",
"->",
"add_relation",
"(",
"$",
"key",
",",
"$",
"relation",
",",
"$",
"skip_include",
")",
";",
"}",
"}"
] | fills the relationships to other resources
this will end up in response.data.relationships
@see ->add_relation()
@param array $relations
@return void | [
"fills",
"the",
"relationships",
"to",
"other",
"resources",
"this",
"will",
"end",
"up",
"in",
"response",
".",
"data",
".",
"relationships"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/resource.php#L341-L345 |
lode/jsonapi | src/resource.php | resource.add_link | public function add_link($key, $link, $meta_data=null, $level=self::LINK_LEVEL_DATA) {
if (is_object($link)) {
$link = parent::convert_object_to_array($link);
}
// can not combine both raw link object and extra meta data
if ($meta_data && is_string($link) == false) {
throw new \Exception('link "'.$key.'" should be a string if meta data is provided separate');
}
if ($level === self::LINK_LEVEL_DATA) {
$revert_root_level = (isset($this->links[$key])) ? $this->links[$key] : null;
}
parent::add_link($key, $link, $meta_data);
if ($level === self::LINK_LEVEL_DATA || $level === self::LINK_LEVEL_BOTH) {
$this->primary_links[$key] = $this->links[$key];
}
if ($level === self::LINK_LEVEL_DATA) {
if ($revert_root_level) {
$this->links[$key] = $revert_root_level;
}
else {
unset($this->links[$key]);
}
}
} | php | public function add_link($key, $link, $meta_data=null, $level=self::LINK_LEVEL_DATA) {
if (is_object($link)) {
$link = parent::convert_object_to_array($link);
}
// can not combine both raw link object and extra meta data
if ($meta_data && is_string($link) == false) {
throw new \Exception('link "'.$key.'" should be a string if meta data is provided separate');
}
if ($level === self::LINK_LEVEL_DATA) {
$revert_root_level = (isset($this->links[$key])) ? $this->links[$key] : null;
}
parent::add_link($key, $link, $meta_data);
if ($level === self::LINK_LEVEL_DATA || $level === self::LINK_LEVEL_BOTH) {
$this->primary_links[$key] = $this->links[$key];
}
if ($level === self::LINK_LEVEL_DATA) {
if ($revert_root_level) {
$this->links[$key] = $revert_root_level;
}
else {
unset($this->links[$key]);
}
}
} | [
"public",
"function",
"add_link",
"(",
"$",
"key",
",",
"$",
"link",
",",
"$",
"meta_data",
"=",
"null",
",",
"$",
"level",
"=",
"self",
"::",
"LINK_LEVEL_DATA",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"link",
")",
")",
"{",
"$",
"link",
"=",
"parent",
"::",
"convert_object_to_array",
"(",
"$",
"link",
")",
";",
"}",
"// can not combine both raw link object and extra meta data",
"if",
"(",
"$",
"meta_data",
"&&",
"is_string",
"(",
"$",
"link",
")",
"==",
"false",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'link \"'",
".",
"$",
"key",
".",
"'\" should be a string if meta data is provided separate'",
")",
";",
"}",
"if",
"(",
"$",
"level",
"===",
"self",
"::",
"LINK_LEVEL_DATA",
")",
"{",
"$",
"revert_root_level",
"=",
"(",
"isset",
"(",
"$",
"this",
"->",
"links",
"[",
"$",
"key",
"]",
")",
")",
"?",
"$",
"this",
"->",
"links",
"[",
"$",
"key",
"]",
":",
"null",
";",
"}",
"parent",
"::",
"add_link",
"(",
"$",
"key",
",",
"$",
"link",
",",
"$",
"meta_data",
")",
";",
"if",
"(",
"$",
"level",
"===",
"self",
"::",
"LINK_LEVEL_DATA",
"||",
"$",
"level",
"===",
"self",
"::",
"LINK_LEVEL_BOTH",
")",
"{",
"$",
"this",
"->",
"primary_links",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"links",
"[",
"$",
"key",
"]",
";",
"}",
"if",
"(",
"$",
"level",
"===",
"self",
"::",
"LINK_LEVEL_DATA",
")",
"{",
"if",
"(",
"$",
"revert_root_level",
")",
"{",
"$",
"this",
"->",
"links",
"[",
"$",
"key",
"]",
"=",
"$",
"revert_root_level",
";",
"}",
"else",
"{",
"unset",
"(",
"$",
"this",
"->",
"links",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"}"
] | this will end up in response.data.links.{$key}
if $also_root is set to true, it will also end up in response.links.{$key}
@see jsonapi\response->add_link()
@param string $key
@param mixed $link objects are converted in arrays, @see base::convert_object_to_array()
@param mixed $meta_data should not be used if $link is non-string
@param string $level one of the predefined ones in ::LINK_LEVEL_*
@return void | [
"this",
"will",
"end",
"up",
"in",
"response",
".",
"data",
".",
"links",
".",
"{",
"$key",
"}",
"if",
"$also_root",
"is",
"set",
"to",
"true",
"it",
"will",
"also",
"end",
"up",
"in",
"response",
".",
"links",
".",
"{",
"$key",
"}"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/resource.php#L359-L386 |
lode/jsonapi | src/resource.php | resource.set_self_link | public function set_self_link($link, $meta_data=null) {
parent::set_self_link($link, $meta_data);
if (self::$self_link_data_level == self::SELF_LINK_SERVER) {
$this->add_link($key='self', $link, $meta_data);
}
if (self::$self_link_data_level == self::SELF_LINK_TYPE) {
$link = '/'.$this->primary_type.'/'.$this->primary_id;
$this->add_link($key='self', $link, $meta_data);
}
} | php | public function set_self_link($link, $meta_data=null) {
parent::set_self_link($link, $meta_data);
if (self::$self_link_data_level == self::SELF_LINK_SERVER) {
$this->add_link($key='self', $link, $meta_data);
}
if (self::$self_link_data_level == self::SELF_LINK_TYPE) {
$link = '/'.$this->primary_type.'/'.$this->primary_id;
$this->add_link($key='self', $link, $meta_data);
}
} | [
"public",
"function",
"set_self_link",
"(",
"$",
"link",
",",
"$",
"meta_data",
"=",
"null",
")",
"{",
"parent",
"::",
"set_self_link",
"(",
"$",
"link",
",",
"$",
"meta_data",
")",
";",
"if",
"(",
"self",
"::",
"$",
"self_link_data_level",
"==",
"self",
"::",
"SELF_LINK_SERVER",
")",
"{",
"$",
"this",
"->",
"add_link",
"(",
"$",
"key",
"=",
"'self'",
",",
"$",
"link",
",",
"$",
"meta_data",
")",
";",
"}",
"if",
"(",
"self",
"::",
"$",
"self_link_data_level",
"==",
"self",
"::",
"SELF_LINK_TYPE",
")",
"{",
"$",
"link",
"=",
"'/'",
".",
"$",
"this",
"->",
"primary_type",
".",
"'/'",
".",
"$",
"this",
"->",
"primary_id",
";",
"$",
"this",
"->",
"add_link",
"(",
"$",
"key",
"=",
"'self'",
",",
"$",
"link",
",",
"$",
"meta_data",
")",
";",
"}",
"}"
] | sets the link to the request used to give this response
this will end up in response.links.self and response.data.links.self
this overrides the jsonapi\response->set_self_link() which only adds it to response.links.self
@see jsonapi\response->set_self_link()
by default this is already set using $_SERVER variables
use this method to override this default behavior
@see jsonapi\response::__construct()
@param string $link
@param mixed $meta_data optional, meta data as key-value pairs
objects are converted in arrays, @see base::convert_object_to_array()
@return void | [
"sets",
"the",
"link",
"to",
"the",
"request",
"used",
"to",
"give",
"this",
"response",
"this",
"will",
"end",
"up",
"in",
"response",
".",
"links",
".",
"self",
"and",
"response",
".",
"data",
".",
"links",
".",
"self",
"this",
"overrides",
"the",
"jsonapi",
"\\",
"response",
"-",
">",
"set_self_link",
"()",
"which",
"only",
"adds",
"it",
"to",
"response",
".",
"links",
".",
"self"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/resource.php#L404-L414 |
lode/jsonapi | src/resource.php | resource.add_self_link_meta | public function add_self_link_meta($key, $meta_data) {
parent::add_self_link_meta($key, $meta_data);
$this->primary_links['self'] = $this->links['self'];
} | php | public function add_self_link_meta($key, $meta_data) {
parent::add_self_link_meta($key, $meta_data);
$this->primary_links['self'] = $this->links['self'];
} | [
"public",
"function",
"add_self_link_meta",
"(",
"$",
"key",
",",
"$",
"meta_data",
")",
"{",
"parent",
"::",
"add_self_link_meta",
"(",
"$",
"key",
",",
"$",
"meta_data",
")",
";",
"$",
"this",
"->",
"primary_links",
"[",
"'self'",
"]",
"=",
"$",
"this",
"->",
"links",
"[",
"'self'",
"]",
";",
"}"
] | adds meta data to the default self link
this will end up in response.links.self.meta.{$key} and response.data.links.self.meta.{$key}
this overrides the jsonapi\response->add_self_link_meta() which only adds it to response.links.self.meta.{$key}
@see jsonapi\response->add_self_link_meta()
@note you can also use ->set_self_link() with the whole meta object at once
@param string $key
@param mixed $meta_data objects are converted in arrays, @see base::convert_object_to_array()
@return void | [
"adds",
"meta",
"data",
"to",
"the",
"default",
"self",
"link",
"this",
"will",
"end",
"up",
"in",
"response",
".",
"links",
".",
"self",
".",
"meta",
".",
"{",
"$key",
"}",
"and",
"response",
".",
"data",
".",
"links",
".",
"self",
".",
"meta",
".",
"{",
"$key",
"}",
"this",
"overrides",
"the",
"jsonapi",
"\\",
"response",
"-",
">",
"add_self_link_meta",
"()",
"which",
"only",
"adds",
"it",
"to",
"response",
".",
"links",
".",
"self",
".",
"meta",
".",
"{",
"$key",
"}"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/resource.php#L429-L433 |
lode/jsonapi | src/resource.php | resource.add_meta | public function add_meta($key, $meta_data, $data_level=false) {
if ($data_level == false) {
return parent::add_meta($key, $meta_data);
}
if (is_object($meta_data)) {
$meta_data = parent::convert_object_to_array($meta_data);
}
$this->primary_meta_data[$key] = $meta_data;
} | php | public function add_meta($key, $meta_data, $data_level=false) {
if ($data_level == false) {
return parent::add_meta($key, $meta_data);
}
if (is_object($meta_data)) {
$meta_data = parent::convert_object_to_array($meta_data);
}
$this->primary_meta_data[$key] = $meta_data;
} | [
"public",
"function",
"add_meta",
"(",
"$",
"key",
",",
"$",
"meta_data",
",",
"$",
"data_level",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"data_level",
"==",
"false",
")",
"{",
"return",
"parent",
"::",
"add_meta",
"(",
"$",
"key",
",",
"$",
"meta_data",
")",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"meta_data",
")",
")",
"{",
"$",
"meta_data",
"=",
"parent",
"::",
"convert_object_to_array",
"(",
"$",
"meta_data",
")",
";",
"}",
"$",
"this",
"->",
"primary_meta_data",
"[",
"$",
"key",
"]",
"=",
"$",
"meta_data",
";",
"}"
] | adds some meta data
this will end up in response.meta.{$key} or response.data.meta.{$key} ..
.. depending on $data_level
@param string $key
@param mixed $meta_data objects are converted in arrays, @see base::convert_object_to_array()
@param boolean $data_level optional, defaults to false
@return void | [
"adds",
"some",
"meta",
"data",
"this",
"will",
"end",
"up",
"in",
"response",
".",
"meta",
".",
"{",
"$key",
"}",
"or",
"response",
".",
"data",
".",
"meta",
".",
"{",
"$key",
"}",
"..",
"..",
"depending",
"on",
"$data_level"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/resource.php#L445-L455 |
lode/jsonapi | src/resource.php | resource.fill_meta | public function fill_meta($meta_data, $data_level=false) {
foreach ($meta_data as $key => $single_meta_data) {
$this->add_meta($key, $single_meta_data, $data_level);
}
} | php | public function fill_meta($meta_data, $data_level=false) {
foreach ($meta_data as $key => $single_meta_data) {
$this->add_meta($key, $single_meta_data, $data_level);
}
} | [
"public",
"function",
"fill_meta",
"(",
"$",
"meta_data",
",",
"$",
"data_level",
"=",
"false",
")",
"{",
"foreach",
"(",
"$",
"meta_data",
"as",
"$",
"key",
"=>",
"$",
"single_meta_data",
")",
"{",
"$",
"this",
"->",
"add_meta",
"(",
"$",
"key",
",",
"$",
"single_meta_data",
",",
"$",
"data_level",
")",
";",
"}",
"}"
] | fills the meta data
this will end up in response.meta or response.data.meta ..
.. depending on $data_level
@param array $meta_data
@param boolean $data_level optional, defaults to false
@return void | [
"fills",
"the",
"meta",
"data",
"this",
"will",
"end",
"up",
"in",
"response",
".",
"meta",
"or",
"response",
".",
"data",
".",
"meta",
"..",
"..",
"depending",
"on",
"$data_level"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/resource.php#L466-L470 |
nicmart/StringTemplate | src/StringTemplate/NestedKeyArray.php | NestedKeyArray.offsetExists | public function offsetExists($offset)
{
$keys = explode($this->keySeparator, $offset);
$ary = &$this->array;
foreach ($keys as $key) {
if (!isset($ary[$key]))
return false;
$ary = &$ary[$key];
}
return true;
} | php | public function offsetExists($offset)
{
$keys = explode($this->keySeparator, $offset);
$ary = &$this->array;
foreach ($keys as $key) {
if (!isset($ary[$key]))
return false;
$ary = &$ary[$key];
}
return true;
} | [
"public",
"function",
"offsetExists",
"(",
"$",
"offset",
")",
"{",
"$",
"keys",
"=",
"explode",
"(",
"$",
"this",
"->",
"keySeparator",
",",
"$",
"offset",
")",
";",
"$",
"ary",
"=",
"&",
"$",
"this",
"->",
"array",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"ary",
"[",
"$",
"key",
"]",
")",
")",
"return",
"false",
";",
"$",
"ary",
"=",
"&",
"$",
"ary",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"true",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/nicmart/StringTemplate/blob/612eeb821b33c0b67d3755a5b24471e30d4d737b/src/StringTemplate/NestedKeyArray.php#L39-L51 |
nicmart/StringTemplate | src/StringTemplate/NestedKeyArray.php | NestedKeyArray.offsetGet | public function offsetGet($offset)
{
$keys = explode($this->keySeparator, $offset);
$result = &$this->array;
foreach ($keys as $key) {
$result = &$result[$key];
}
return $result;
} | php | public function offsetGet($offset)
{
$keys = explode($this->keySeparator, $offset);
$result = &$this->array;
foreach ($keys as $key) {
$result = &$result[$key];
}
return $result;
} | [
"public",
"function",
"offsetGet",
"(",
"$",
"offset",
")",
"{",
"$",
"keys",
"=",
"explode",
"(",
"$",
"this",
"->",
"keySeparator",
",",
"$",
"offset",
")",
";",
"$",
"result",
"=",
"&",
"$",
"this",
"->",
"array",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"$",
"result",
"=",
"&",
"$",
"result",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/nicmart/StringTemplate/blob/612eeb821b33c0b67d3755a5b24471e30d4d737b/src/StringTemplate/NestedKeyArray.php#L56-L66 |
nicmart/StringTemplate | src/StringTemplate/NestedKeyArray.php | NestedKeyArray.offsetSet | public function offsetSet($offset, $value)
{
$this->setNestedOffset($this->array, explode($this->keySeparator, $offset), $value);
} | php | public function offsetSet($offset, $value)
{
$this->setNestedOffset($this->array, explode($this->keySeparator, $offset), $value);
} | [
"public",
"function",
"offsetSet",
"(",
"$",
"offset",
",",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"setNestedOffset",
"(",
"$",
"this",
"->",
"array",
",",
"explode",
"(",
"$",
"this",
"->",
"keySeparator",
",",
"$",
"offset",
")",
",",
"$",
"value",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/nicmart/StringTemplate/blob/612eeb821b33c0b67d3755a5b24471e30d4d737b/src/StringTemplate/NestedKeyArray.php#L71-L74 |
lode/jsonapi | src/objects/RelationshipsObject.php | RelationshipsObject.addRelationshipObject | public function addRelationshipObject($key, RelationshipObject $relationshipObject) {
Validator::checkMemberName($key);
if (isset($this->relationships[$key])) {
throw new DuplicateException('relationship with key "'.$key.'" already set');
}
$this->relationships[$key] = $relationshipObject;
} | php | public function addRelationshipObject($key, RelationshipObject $relationshipObject) {
Validator::checkMemberName($key);
if (isset($this->relationships[$key])) {
throw new DuplicateException('relationship with key "'.$key.'" already set');
}
$this->relationships[$key] = $relationshipObject;
} | [
"public",
"function",
"addRelationshipObject",
"(",
"$",
"key",
",",
"RelationshipObject",
"$",
"relationshipObject",
")",
"{",
"Validator",
"::",
"checkMemberName",
"(",
"$",
"key",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"relationships",
"[",
"$",
"key",
"]",
")",
")",
"{",
"throw",
"new",
"DuplicateException",
"(",
"'relationship with key \"'",
".",
"$",
"key",
".",
"'\" already set'",
")",
";",
"}",
"$",
"this",
"->",
"relationships",
"[",
"$",
"key",
"]",
"=",
"$",
"relationshipObject",
";",
"}"
] | @param string $key
@param RelationshipObject $relationshipObject
@throws DuplicateException if another relationship is already using that $key | [
"@param",
"string",
"$key",
"@param",
"RelationshipObject",
"$relationshipObject"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/objects/RelationshipsObject.php#L49-L57 |
lode/jsonapi | src/ErrorsDocument.php | ErrorsDocument.fromException | public static function fromException($exception, array $options=[]) {
if ($exception instanceof \Exception === false && $exception instanceof \Throwable === false) {
throw new InputException('input is not a real exception in php5 or php7');
}
$options = array_merge(self::$defaults, $options);
$errorsDocument = new self();
$errorsDocument->addException($exception, $options);
return $errorsDocument;
} | php | public static function fromException($exception, array $options=[]) {
if ($exception instanceof \Exception === false && $exception instanceof \Throwable === false) {
throw new InputException('input is not a real exception in php5 or php7');
}
$options = array_merge(self::$defaults, $options);
$errorsDocument = new self();
$errorsDocument->addException($exception, $options);
return $errorsDocument;
} | [
"public",
"static",
"function",
"fromException",
"(",
"$",
"exception",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"exception",
"instanceof",
"\\",
"Exception",
"===",
"false",
"&&",
"$",
"exception",
"instanceof",
"\\",
"Throwable",
"===",
"false",
")",
"{",
"throw",
"new",
"InputException",
"(",
"'input is not a real exception in php5 or php7'",
")",
";",
"}",
"$",
"options",
"=",
"array_merge",
"(",
"self",
"::",
"$",
"defaults",
",",
"$",
"options",
")",
";",
"$",
"errorsDocument",
"=",
"new",
"self",
"(",
")",
";",
"$",
"errorsDocument",
"->",
"addException",
"(",
"$",
"exception",
",",
"$",
"options",
")",
";",
"return",
"$",
"errorsDocument",
";",
"}"
] | @param \Exception|\Throwable $exception
@param array $options optional {@see ErrorsDocument::$defaults}
@return ErrorsDocument
@throws InputException if $exception is not \Exception or \Throwable | [
"@param",
"\\",
"Exception|",
"\\",
"Throwable",
"$exception",
"@param",
"array",
"$options",
"optional",
"{",
"@see",
"ErrorsDocument",
"::",
"$defaults",
"}",
"@return",
"ErrorsDocument"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/ErrorsDocument.php#L53-L64 |
lode/jsonapi | src/ErrorsDocument.php | ErrorsDocument.addException | public function addException($exception, array $options=[]) {
if ($exception instanceof \Exception === false && $exception instanceof \Throwable === false) {
throw new InputException('input is not a real exception in php5 or php7');
}
$options = array_merge(self::$defaults, $options);
$this->addErrorObject(ErrorObject::fromException($exception, $options));
if ($options['includeExceptionPrevious']) {
$exception = $exception->getPrevious();
while ($exception !== null) {
$this->addException($exception, $options);
$exception = $exception->getPrevious();
}
}
} | php | public function addException($exception, array $options=[]) {
if ($exception instanceof \Exception === false && $exception instanceof \Throwable === false) {
throw new InputException('input is not a real exception in php5 or php7');
}
$options = array_merge(self::$defaults, $options);
$this->addErrorObject(ErrorObject::fromException($exception, $options));
if ($options['includeExceptionPrevious']) {
$exception = $exception->getPrevious();
while ($exception !== null) {
$this->addException($exception, $options);
$exception = $exception->getPrevious();
}
}
} | [
"public",
"function",
"addException",
"(",
"$",
"exception",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"exception",
"instanceof",
"\\",
"Exception",
"===",
"false",
"&&",
"$",
"exception",
"instanceof",
"\\",
"Throwable",
"===",
"false",
")",
"{",
"throw",
"new",
"InputException",
"(",
"'input is not a real exception in php5 or php7'",
")",
";",
"}",
"$",
"options",
"=",
"array_merge",
"(",
"self",
"::",
"$",
"defaults",
",",
"$",
"options",
")",
";",
"$",
"this",
"->",
"addErrorObject",
"(",
"ErrorObject",
"::",
"fromException",
"(",
"$",
"exception",
",",
"$",
"options",
")",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'includeExceptionPrevious'",
"]",
")",
"{",
"$",
"exception",
"=",
"$",
"exception",
"->",
"getPrevious",
"(",
")",
";",
"while",
"(",
"$",
"exception",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"addException",
"(",
"$",
"exception",
",",
"$",
"options",
")",
";",
"$",
"exception",
"=",
"$",
"exception",
"->",
"getPrevious",
"(",
")",
";",
"}",
"}",
"}"
] | add an ErrorObject for the given $exception
recursively adds multiple ErrorObjects if $exception carries a ->getPrevious()
@param \Exception|\Throwable $exception
@param array $options optional {@see ErrorsDocument::$defaults}
@throws InputException if $exception is not \Exception or \Throwable | [
"add",
"an",
"ErrorObject",
"for",
"the",
"given",
"$exception"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/ErrorsDocument.php#L76-L92 |
lode/jsonapi | src/ErrorsDocument.php | ErrorsDocument.addErrorObject | public function addErrorObject(ErrorObject $errorObject) {
$this->errors[] = $errorObject;
if ($errorObject->hasHttpStatusCode()) {
$this->setHttpStatusCode($this->determineHttpStatusCode($errorObject->getHttpStatusCode()));
}
} | php | public function addErrorObject(ErrorObject $errorObject) {
$this->errors[] = $errorObject;
if ($errorObject->hasHttpStatusCode()) {
$this->setHttpStatusCode($this->determineHttpStatusCode($errorObject->getHttpStatusCode()));
}
} | [
"public",
"function",
"addErrorObject",
"(",
"ErrorObject",
"$",
"errorObject",
")",
"{",
"$",
"this",
"->",
"errors",
"[",
"]",
"=",
"$",
"errorObject",
";",
"if",
"(",
"$",
"errorObject",
"->",
"hasHttpStatusCode",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setHttpStatusCode",
"(",
"$",
"this",
"->",
"determineHttpStatusCode",
"(",
"$",
"errorObject",
"->",
"getHttpStatusCode",
"(",
")",
")",
")",
";",
"}",
"}"
] | @note also defines the http status code of the document if the ErrorObject has it defined
@param ErrorObject $errorObject | [
"@note",
"also",
"defines",
"the",
"http",
"status",
"code",
"of",
"the",
"document",
"if",
"the",
"ErrorObject",
"has",
"it",
"defined"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/ErrorsDocument.php#L116-L122 |
lode/jsonapi | src/ErrorsDocument.php | ErrorsDocument.determineHttpStatusCode | protected function determineHttpStatusCode($httpStatusCode) {
// add the new code
$category = substr($httpStatusCode, 0, 1);
$this->httpStatusCodes[$category][$httpStatusCode] = true;
$advisedStatusCode = $httpStatusCode;
// when there's multiple, give preference to 5xx errors
if (isset($this->httpStatusCodes['5']) && isset($this->httpStatusCodes['4'])) {
// use a generic one
$advisedStatusCode = 500;
}
elseif (isset($this->httpStatusCodes['5'])) {
if (count($this->httpStatusCodes['5']) === 1) {
$advisedStatusCode = key($this->httpStatusCodes['5']);
}
else {
// use a generic one
$advisedStatusCode = 500;
}
}
elseif (isset($this->httpStatusCodes['4'])) {
if (count($this->httpStatusCodes['4']) === 1) {
$advisedStatusCode = key($this->httpStatusCodes['4']);
}
else {
// use a generic one
$advisedStatusCode = 400;
}
}
return (int) $advisedStatusCode;
} | php | protected function determineHttpStatusCode($httpStatusCode) {
// add the new code
$category = substr($httpStatusCode, 0, 1);
$this->httpStatusCodes[$category][$httpStatusCode] = true;
$advisedStatusCode = $httpStatusCode;
// when there's multiple, give preference to 5xx errors
if (isset($this->httpStatusCodes['5']) && isset($this->httpStatusCodes['4'])) {
// use a generic one
$advisedStatusCode = 500;
}
elseif (isset($this->httpStatusCodes['5'])) {
if (count($this->httpStatusCodes['5']) === 1) {
$advisedStatusCode = key($this->httpStatusCodes['5']);
}
else {
// use a generic one
$advisedStatusCode = 500;
}
}
elseif (isset($this->httpStatusCodes['4'])) {
if (count($this->httpStatusCodes['4']) === 1) {
$advisedStatusCode = key($this->httpStatusCodes['4']);
}
else {
// use a generic one
$advisedStatusCode = 400;
}
}
return (int) $advisedStatusCode;
} | [
"protected",
"function",
"determineHttpStatusCode",
"(",
"$",
"httpStatusCode",
")",
"{",
"// add the new code",
"$",
"category",
"=",
"substr",
"(",
"$",
"httpStatusCode",
",",
"0",
",",
"1",
")",
";",
"$",
"this",
"->",
"httpStatusCodes",
"[",
"$",
"category",
"]",
"[",
"$",
"httpStatusCode",
"]",
"=",
"true",
";",
"$",
"advisedStatusCode",
"=",
"$",
"httpStatusCode",
";",
"// when there's multiple, give preference to 5xx errors",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"httpStatusCodes",
"[",
"'5'",
"]",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"httpStatusCodes",
"[",
"'4'",
"]",
")",
")",
"{",
"// use a generic one",
"$",
"advisedStatusCode",
"=",
"500",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"this",
"->",
"httpStatusCodes",
"[",
"'5'",
"]",
")",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"httpStatusCodes",
"[",
"'5'",
"]",
")",
"===",
"1",
")",
"{",
"$",
"advisedStatusCode",
"=",
"key",
"(",
"$",
"this",
"->",
"httpStatusCodes",
"[",
"'5'",
"]",
")",
";",
"}",
"else",
"{",
"// use a generic one",
"$",
"advisedStatusCode",
"=",
"500",
";",
"}",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"this",
"->",
"httpStatusCodes",
"[",
"'4'",
"]",
")",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"httpStatusCodes",
"[",
"'4'",
"]",
")",
"===",
"1",
")",
"{",
"$",
"advisedStatusCode",
"=",
"key",
"(",
"$",
"this",
"->",
"httpStatusCodes",
"[",
"'4'",
"]",
")",
";",
"}",
"else",
"{",
"// use a generic one",
"$",
"advisedStatusCode",
"=",
"400",
";",
"}",
"}",
"return",
"(",
"int",
")",
"$",
"advisedStatusCode",
";",
"}"
] | @internal
@param string|int $httpStatusCode
@return int | [
"@internal"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/ErrorsDocument.php#L156-L188 |
lode/jsonapi | src/errors.php | errors.get_array | public function get_array() {
$response = array();
// links
if ($this->links) {
$response['links'] = $this->links;
}
// errors
$response['errors'] = $this->errors_collection;
// meta data
if ($this->meta_data) {
$response['meta'] = $this->meta_data;
}
return $response;
} | php | public function get_array() {
$response = array();
// links
if ($this->links) {
$response['links'] = $this->links;
}
// errors
$response['errors'] = $this->errors_collection;
// meta data
if ($this->meta_data) {
$response['meta'] = $this->meta_data;
}
return $response;
} | [
"public",
"function",
"get_array",
"(",
")",
"{",
"$",
"response",
"=",
"array",
"(",
")",
";",
"// links",
"if",
"(",
"$",
"this",
"->",
"links",
")",
"{",
"$",
"response",
"[",
"'links'",
"]",
"=",
"$",
"this",
"->",
"links",
";",
"}",
"// errors",
"$",
"response",
"[",
"'errors'",
"]",
"=",
"$",
"this",
"->",
"errors_collection",
";",
"// meta data",
"if",
"(",
"$",
"this",
"->",
"meta_data",
")",
"{",
"$",
"response",
"[",
"'meta'",
"]",
"=",
"$",
"this",
"->",
"meta_data",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | generates an array for the whole response body
@note error message (`code`) is only shown when debug mode is on (@see base::$debug)
@see jsonapi.org/format
@return array, containing:
- links
- errors []
- status
- code
- title
- detail
- source
- pointer
- parameter
- links
- about
- id
- meta
- meta | [
"generates",
"an",
"array",
"for",
"the",
"whole",
"response",
"body"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/errors.php#L81-L98 |
lode/jsonapi | src/errors.php | errors.send_response | public function send_response($content_type=null, $encode_options=null, $response=null, $jsonp_callback=null) {
parent::send_response($content_type, $encode_options, $response, $jsonp_callback);
exit;
} | php | public function send_response($content_type=null, $encode_options=null, $response=null, $jsonp_callback=null) {
parent::send_response($content_type, $encode_options, $response, $jsonp_callback);
exit;
} | [
"public",
"function",
"send_response",
"(",
"$",
"content_type",
"=",
"null",
",",
"$",
"encode_options",
"=",
"null",
",",
"$",
"response",
"=",
"null",
",",
"$",
"jsonp_callback",
"=",
"null",
")",
"{",
"parent",
"::",
"send_response",
"(",
"$",
"content_type",
",",
"$",
"encode_options",
",",
"$",
"response",
",",
"$",
"jsonp_callback",
")",
";",
"exit",
";",
"}"
] | sends out the json response to the browser
this will fetch the response from ->get_json() if not given via $response
@note this is the same as jsonapi\response->send_response() ..
.. but it will also terminate script execution afterwards
@param string $content_type optional, defaults to ::CONTENT_TYPE_OFFICIAL (the official IANA registered one) ..
.. or to ::CONTENT_TYPE_DEBUG, @see ::$debug
@param int $encode_options optional, $options for json_encode()
defaults to ::ENCODE_DEFAULT or ::ENCODE_DEBUG, @see ::$debug
@param json $response optional, defaults to ::get_json()
@param string $jsonp_callback optional, response as jsonp
@return void more so, a string will be echo'd to the browser ..
.. and script execution will terminate | [
"sends",
"out",
"the",
"json",
"response",
"to",
"the",
"browser",
"this",
"will",
"fetch",
"the",
"response",
"from",
"-",
">",
"get_json",
"()",
"if",
"not",
"given",
"via",
"$response"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/errors.php#L116-L119 |
lode/jsonapi | src/errors.php | errors.add_error | public function add_error($error_message=null, $friendly_message=null, $about_link=null) {
if ($error_message instanceof error == false) {
$error_message = new error($error_message, $friendly_message, $about_link);
}
$this->add_error_object($error_message);
} | php | public function add_error($error_message=null, $friendly_message=null, $about_link=null) {
if ($error_message instanceof error == false) {
$error_message = new error($error_message, $friendly_message, $about_link);
}
$this->add_error_object($error_message);
} | [
"public",
"function",
"add_error",
"(",
"$",
"error_message",
"=",
"null",
",",
"$",
"friendly_message",
"=",
"null",
",",
"$",
"about_link",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"error_message",
"instanceof",
"error",
"==",
"false",
")",
"{",
"$",
"error_message",
"=",
"new",
"error",
"(",
"$",
"error_message",
",",
"$",
"friendly_message",
",",
"$",
"about_link",
")",
";",
"}",
"$",
"this",
"->",
"add_error_object",
"(",
"$",
"error_message",
")",
";",
"}"
] | adds an error to the errors collection
this will end up in response.errors[]
@note error message (if string) is only shown when debug mode is on (@see base::$debug)
@param mixed $error_message optional, can be jsonapi\error object or string
@param string $friendly_message optional, @see jsonapi\error->set_friendly_message()
@param string $about_link optional, @see jsonapi\error->set_about_link() | [
"adds",
"an",
"error",
"to",
"the",
"errors",
"collection",
"this",
"will",
"end",
"up",
"in",
"response",
".",
"errors",
"[]"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/errors.php#L147-L153 |
lode/jsonapi | src/errors.php | errors.add_exception | public function add_exception($exception, $friendly_message=null, $about_link=null) {
$error_message = $exception->getMessage();
$error_status = $exception->getCode();
$new_error = new error($error_message, $friendly_message, $about_link);
if ($error_status) {
$new_error->set_http_status($error_status);
}
// meta data
if (base::$debug) {
$file = $exception->getFile();
if ($file) {
$file = str_replace(base::$appRoot, '', $file);
$new_error->add_meta('file', $file);
}
$line = $exception->getLine();
if ($line) {
$new_error->add_meta('line', $line);
}
$trace = $exception->getTrace();
if ($trace) {
foreach ($trace as &$place) {
if (!empty($place['file'])) {
$place['file'] = str_replace(base::$appRoot, '', $place['file']);
}
}
$new_error->add_meta('trace', $trace);
}
}
$this->add_error_object($new_error);
$previous_exception = $exception->getPrevious();
if ($previous_exception) {
$this->add_exception($previous_exception);
}
} | php | public function add_exception($exception, $friendly_message=null, $about_link=null) {
$error_message = $exception->getMessage();
$error_status = $exception->getCode();
$new_error = new error($error_message, $friendly_message, $about_link);
if ($error_status) {
$new_error->set_http_status($error_status);
}
// meta data
if (base::$debug) {
$file = $exception->getFile();
if ($file) {
$file = str_replace(base::$appRoot, '', $file);
$new_error->add_meta('file', $file);
}
$line = $exception->getLine();
if ($line) {
$new_error->add_meta('line', $line);
}
$trace = $exception->getTrace();
if ($trace) {
foreach ($trace as &$place) {
if (!empty($place['file'])) {
$place['file'] = str_replace(base::$appRoot, '', $place['file']);
}
}
$new_error->add_meta('trace', $trace);
}
}
$this->add_error_object($new_error);
$previous_exception = $exception->getPrevious();
if ($previous_exception) {
$this->add_exception($previous_exception);
}
} | [
"public",
"function",
"add_exception",
"(",
"$",
"exception",
",",
"$",
"friendly_message",
"=",
"null",
",",
"$",
"about_link",
"=",
"null",
")",
"{",
"$",
"error_message",
"=",
"$",
"exception",
"->",
"getMessage",
"(",
")",
";",
"$",
"error_status",
"=",
"$",
"exception",
"->",
"getCode",
"(",
")",
";",
"$",
"new_error",
"=",
"new",
"error",
"(",
"$",
"error_message",
",",
"$",
"friendly_message",
",",
"$",
"about_link",
")",
";",
"if",
"(",
"$",
"error_status",
")",
"{",
"$",
"new_error",
"->",
"set_http_status",
"(",
"$",
"error_status",
")",
";",
"}",
"// meta data",
"if",
"(",
"base",
"::",
"$",
"debug",
")",
"{",
"$",
"file",
"=",
"$",
"exception",
"->",
"getFile",
"(",
")",
";",
"if",
"(",
"$",
"file",
")",
"{",
"$",
"file",
"=",
"str_replace",
"(",
"base",
"::",
"$",
"appRoot",
",",
"''",
",",
"$",
"file",
")",
";",
"$",
"new_error",
"->",
"add_meta",
"(",
"'file'",
",",
"$",
"file",
")",
";",
"}",
"$",
"line",
"=",
"$",
"exception",
"->",
"getLine",
"(",
")",
";",
"if",
"(",
"$",
"line",
")",
"{",
"$",
"new_error",
"->",
"add_meta",
"(",
"'line'",
",",
"$",
"line",
")",
";",
"}",
"$",
"trace",
"=",
"$",
"exception",
"->",
"getTrace",
"(",
")",
";",
"if",
"(",
"$",
"trace",
")",
"{",
"foreach",
"(",
"$",
"trace",
"as",
"&",
"$",
"place",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"place",
"[",
"'file'",
"]",
")",
")",
"{",
"$",
"place",
"[",
"'file'",
"]",
"=",
"str_replace",
"(",
"base",
"::",
"$",
"appRoot",
",",
"''",
",",
"$",
"place",
"[",
"'file'",
"]",
")",
";",
"}",
"}",
"$",
"new_error",
"->",
"add_meta",
"(",
"'trace'",
",",
"$",
"trace",
")",
";",
"}",
"}",
"$",
"this",
"->",
"add_error_object",
"(",
"$",
"new_error",
")",
";",
"$",
"previous_exception",
"=",
"$",
"exception",
"->",
"getPrevious",
"(",
")",
";",
"if",
"(",
"$",
"previous_exception",
")",
"{",
"$",
"this",
"->",
"add_exception",
"(",
"$",
"previous_exception",
")",
";",
"}",
"}"
] | adds an exception as error to the errors collection
this will end up in response.errors[]
@note exception meta data (file, line, trace) is only shown when debug mode is on (@see base::$debug)
@param object $exception extending \Exception
@param string $friendly_message optional, @see jsonapi\error->set_friendly_message()
@param string $about_link optional, @see jsonapi\error->set_about_link() | [
"adds",
"an",
"exception",
"as",
"error",
"to",
"the",
"errors",
"collection",
"this",
"will",
"end",
"up",
"in",
"response",
".",
"errors",
"[]"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/errors.php#L178-L217 |
lode/jsonapi | src/errors.php | errors.add_error_object | private function add_error_object(\alsvanzelf\jsonapi\error $error) {
$error_response_part = $error->get_array();
$error_http_status = $error->get_http_status();
$this->errors_collection[] = $error_response_part;
if ($error_http_status) {
$this->set_http_status($error_http_status);
}
} | php | private function add_error_object(\alsvanzelf\jsonapi\error $error) {
$error_response_part = $error->get_array();
$error_http_status = $error->get_http_status();
$this->errors_collection[] = $error_response_part;
if ($error_http_status) {
$this->set_http_status($error_http_status);
}
} | [
"private",
"function",
"add_error_object",
"(",
"\\",
"alsvanzelf",
"\\",
"jsonapi",
"\\",
"error",
"$",
"error",
")",
"{",
"$",
"error_response_part",
"=",
"$",
"error",
"->",
"get_array",
"(",
")",
";",
"$",
"error_http_status",
"=",
"$",
"error",
"->",
"get_http_status",
"(",
")",
";",
"$",
"this",
"->",
"errors_collection",
"[",
"]",
"=",
"$",
"error_response_part",
";",
"if",
"(",
"$",
"error_http_status",
")",
"{",
"$",
"this",
"->",
"set_http_status",
"(",
"$",
"error_http_status",
")",
";",
"}",
"}"
] | adds a jsonapi\error object to the errors collection
used internally by ->add_error(), ->fill_errors() and ->add_exception()
further, a generic http status is gathered from added objects
@param jsonapi\error $error | [
"adds",
"a",
"jsonapi",
"\\",
"error",
"object",
"to",
"the",
"errors",
"collection",
"used",
"internally",
"by",
"-",
">",
"add_error",
"()",
"-",
">",
"fill_errors",
"()",
"and",
"-",
">",
"add_exception",
"()"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/errors.php#L227-L235 |
lode/jsonapi | src/exception.php | exception.send_response | public function send_response($content_type=null, $encode_options=null, $response=null, $jsonp_callback=null) {
$jsonapi = new errors($this, $this->friendly_message, $this->about_link);
$jsonapi->send_response($content_type, $encode_options, $response, $jsonp_callback);
exit; // sanity check
} | php | public function send_response($content_type=null, $encode_options=null, $response=null, $jsonp_callback=null) {
$jsonapi = new errors($this, $this->friendly_message, $this->about_link);
$jsonapi->send_response($content_type, $encode_options, $response, $jsonp_callback);
exit; // sanity check
} | [
"public",
"function",
"send_response",
"(",
"$",
"content_type",
"=",
"null",
",",
"$",
"encode_options",
"=",
"null",
",",
"$",
"response",
"=",
"null",
",",
"$",
"jsonp_callback",
"=",
"null",
")",
"{",
"$",
"jsonapi",
"=",
"new",
"errors",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"friendly_message",
",",
"$",
"this",
"->",
"about_link",
")",
";",
"$",
"jsonapi",
"->",
"send_response",
"(",
"$",
"content_type",
",",
"$",
"encode_options",
",",
"$",
"response",
",",
"$",
"jsonp_callback",
")",
";",
"exit",
";",
"// sanity check",
"}"
] | sends out the json response of an jsonapi\errors object to the browser
@see errors->send_response() | [
"sends",
"out",
"the",
"json",
"response",
"of",
"an",
"jsonapi",
"\\",
"errors",
"object",
"to",
"the",
"browser"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/exception.php#L74-L78 |
lode/jsonapi | src/profiles/CursorPaginationProfile.php | CursorPaginationProfile.setLinks | public function setLinks(PaginableInterface $paginable, $baseOrCurrentUrl, $firstCursor, $lastCursor) {
$previousLinkObject = new LinkObject($this->generatePreviousLink($baseOrCurrentUrl, $firstCursor));
$nextLinkObject = new LinkObject($this->generateNextLink($baseOrCurrentUrl, $lastCursor));
$this->setPaginationLinkObjects($paginable, $previousLinkObject, $nextLinkObject);
} | php | public function setLinks(PaginableInterface $paginable, $baseOrCurrentUrl, $firstCursor, $lastCursor) {
$previousLinkObject = new LinkObject($this->generatePreviousLink($baseOrCurrentUrl, $firstCursor));
$nextLinkObject = new LinkObject($this->generateNextLink($baseOrCurrentUrl, $lastCursor));
$this->setPaginationLinkObjects($paginable, $previousLinkObject, $nextLinkObject);
} | [
"public",
"function",
"setLinks",
"(",
"PaginableInterface",
"$",
"paginable",
",",
"$",
"baseOrCurrentUrl",
",",
"$",
"firstCursor",
",",
"$",
"lastCursor",
")",
"{",
"$",
"previousLinkObject",
"=",
"new",
"LinkObject",
"(",
"$",
"this",
"->",
"generatePreviousLink",
"(",
"$",
"baseOrCurrentUrl",
",",
"$",
"firstCursor",
")",
")",
";",
"$",
"nextLinkObject",
"=",
"new",
"LinkObject",
"(",
"$",
"this",
"->",
"generateNextLink",
"(",
"$",
"baseOrCurrentUrl",
",",
"$",
"lastCursor",
")",
")",
";",
"$",
"this",
"->",
"setPaginationLinkObjects",
"(",
"$",
"paginable",
",",
"$",
"previousLinkObject",
",",
"$",
"nextLinkObject",
")",
";",
"}"
] | set links to paginate the data using cursors of the paginated data
@param PaginableInterface $paginable a CollectionDocument or RelationshipObject
@param string $baseOrCurrentUrl
@param string $firstCursor
@param string $lastCursor | [
"set",
"links",
"to",
"paginate",
"the",
"data",
"using",
"cursors",
"of",
"the",
"paginated",
"data"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/profiles/CursorPaginationProfile.php#L60-L65 |
lode/jsonapi | src/profiles/CursorPaginationProfile.php | CursorPaginationProfile.setCount | public function setCount(PaginableInterface $paginable, $exactTotal=null, $bestGuessTotal=null) {
$this->setPaginationMeta($paginable, $exactTotal, $bestGuessTotal);
} | php | public function setCount(PaginableInterface $paginable, $exactTotal=null, $bestGuessTotal=null) {
$this->setPaginationMeta($paginable, $exactTotal, $bestGuessTotal);
} | [
"public",
"function",
"setCount",
"(",
"PaginableInterface",
"$",
"paginable",
",",
"$",
"exactTotal",
"=",
"null",
",",
"$",
"bestGuessTotal",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"setPaginationMeta",
"(",
"$",
"paginable",
",",
"$",
"exactTotal",
",",
"$",
"bestGuessTotal",
")",
";",
"}"
] | set count(s) to tell about the (estimated) total size
@param PaginableInterface $paginable a CollectionDocument or RelationshipObject
@param int $exactTotal optional
@param int $bestGuessTotal optional | [
"set",
"count",
"(",
"s",
")",
"to",
"tell",
"about",
"the",
"(",
"estimated",
")",
"total",
"size"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/profiles/CursorPaginationProfile.php#L102-L104 |
lode/jsonapi | src/profiles/CursorPaginationProfile.php | CursorPaginationProfile.setPaginationLinkObjects | public function setPaginationLinkObjects(PaginableInterface $paginable, LinkObject $previousLinkObject, LinkObject $nextLinkObject) {
$paginable->addLinkObject('prev', $previousLinkObject);
$paginable->addLinkObject('next', $nextLinkObject);
} | php | public function setPaginationLinkObjects(PaginableInterface $paginable, LinkObject $previousLinkObject, LinkObject $nextLinkObject) {
$paginable->addLinkObject('prev', $previousLinkObject);
$paginable->addLinkObject('next', $nextLinkObject);
} | [
"public",
"function",
"setPaginationLinkObjects",
"(",
"PaginableInterface",
"$",
"paginable",
",",
"LinkObject",
"$",
"previousLinkObject",
",",
"LinkObject",
"$",
"nextLinkObject",
")",
"{",
"$",
"paginable",
"->",
"addLinkObject",
"(",
"'prev'",
",",
"$",
"previousLinkObject",
")",
";",
"$",
"paginable",
"->",
"addLinkObject",
"(",
"'next'",
",",
"$",
"nextLinkObject",
")",
";",
"}"
] | pagination links are inside the links object that is a sibling of the paginated data
ends up at one of:
- /links/prev & /links/next
- /data/relationships/foo/links/prev & /data/relationships/foo/links/next
- /data/0/relationships/foo/links/prev & /data/0/relationships/foo/links/next
@see https://jsonapi.org/profiles/ethanresnick/cursor-pagination/#terms-pagination-links
@param PaginableInterface $paginable
@param LinkObject $previousLinkObject
@param LinkObject $nextLinkObject | [
"pagination",
"links",
"are",
"inside",
"the",
"links",
"object",
"that",
"is",
"a",
"sibling",
"of",
"the",
"paginated",
"data"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/profiles/CursorPaginationProfile.php#L146-L149 |
lode/jsonapi | src/profiles/CursorPaginationProfile.php | CursorPaginationProfile.setItemMeta | public function setItemMeta(ResourceInterface $resource, $cursor) {
$metadata = [
'cursor' => $cursor,
];
if ($resource instanceof ResourceDocument) {
$resource->addMeta($this->getKeyword('page'), $metadata, $level=Document::LEVEL_RESOURCE);
}
else {
$resource->addMeta($this->getKeyword('page'), $metadata);
}
} | php | public function setItemMeta(ResourceInterface $resource, $cursor) {
$metadata = [
'cursor' => $cursor,
];
if ($resource instanceof ResourceDocument) {
$resource->addMeta($this->getKeyword('page'), $metadata, $level=Document::LEVEL_RESOURCE);
}
else {
$resource->addMeta($this->getKeyword('page'), $metadata);
}
} | [
"public",
"function",
"setItemMeta",
"(",
"ResourceInterface",
"$",
"resource",
",",
"$",
"cursor",
")",
"{",
"$",
"metadata",
"=",
"[",
"'cursor'",
"=>",
"$",
"cursor",
",",
"]",
";",
"if",
"(",
"$",
"resource",
"instanceof",
"ResourceDocument",
")",
"{",
"$",
"resource",
"->",
"addMeta",
"(",
"$",
"this",
"->",
"getKeyword",
"(",
"'page'",
")",
",",
"$",
"metadata",
",",
"$",
"level",
"=",
"Document",
"::",
"LEVEL_RESOURCE",
")",
";",
"}",
"else",
"{",
"$",
"resource",
"->",
"addMeta",
"(",
"$",
"this",
"->",
"getKeyword",
"(",
"'page'",
")",
",",
"$",
"metadata",
")",
";",
"}",
"}"
] | pagination item metadata is the page meta at the top-level of a paginated item
ends up at one of:
- /data/meta/page
- /data/relationships/foo/meta/page
- /data/0/relationships/foo/meta/page
@see https://jsonapi.org/profiles/ethanresnick/cursor-pagination/#terms-pagination-item-metadata
@param ResourceInterface $resource
@param string $cursor | [
"pagination",
"item",
"metadata",
"is",
"the",
"page",
"meta",
"at",
"the",
"top",
"-",
"level",
"of",
"a",
"paginated",
"item"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/profiles/CursorPaginationProfile.php#L189-L200 |
lode/jsonapi | src/profiles/CursorPaginationProfile.php | CursorPaginationProfile.setPaginationMeta | public function setPaginationMeta(PaginableInterface $paginable, $exactTotal=null, $bestGuessTotal=null, $rangeIsTruncated=null) {
$metadata = [];
if ($exactTotal !== null) {
$metadata['total'] = $exactTotal;
}
if ($bestGuessTotal !== null) {
$metadata['estimatedTotal'] = [
'bestGuess' => $bestGuessTotal,
];
}
if ($rangeIsTruncated !== null) {
$metadata['rangeTruncated'] = $rangeIsTruncated;
}
$paginable->addMeta($this->getKeyword('page'), $metadata);
} | php | public function setPaginationMeta(PaginableInterface $paginable, $exactTotal=null, $bestGuessTotal=null, $rangeIsTruncated=null) {
$metadata = [];
if ($exactTotal !== null) {
$metadata['total'] = $exactTotal;
}
if ($bestGuessTotal !== null) {
$metadata['estimatedTotal'] = [
'bestGuess' => $bestGuessTotal,
];
}
if ($rangeIsTruncated !== null) {
$metadata['rangeTruncated'] = $rangeIsTruncated;
}
$paginable->addMeta($this->getKeyword('page'), $metadata);
} | [
"public",
"function",
"setPaginationMeta",
"(",
"PaginableInterface",
"$",
"paginable",
",",
"$",
"exactTotal",
"=",
"null",
",",
"$",
"bestGuessTotal",
"=",
"null",
",",
"$",
"rangeIsTruncated",
"=",
"null",
")",
"{",
"$",
"metadata",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"exactTotal",
"!==",
"null",
")",
"{",
"$",
"metadata",
"[",
"'total'",
"]",
"=",
"$",
"exactTotal",
";",
"}",
"if",
"(",
"$",
"bestGuessTotal",
"!==",
"null",
")",
"{",
"$",
"metadata",
"[",
"'estimatedTotal'",
"]",
"=",
"[",
"'bestGuess'",
"=>",
"$",
"bestGuessTotal",
",",
"]",
";",
"}",
"if",
"(",
"$",
"rangeIsTruncated",
"!==",
"null",
")",
"{",
"$",
"metadata",
"[",
"'rangeTruncated'",
"]",
"=",
"$",
"rangeIsTruncated",
";",
"}",
"$",
"paginable",
"->",
"addMeta",
"(",
"$",
"this",
"->",
"getKeyword",
"(",
"'page'",
")",
",",
"$",
"metadata",
")",
";",
"}"
] | pagination metadata is the page meta that is a sibling of the paginated data (and pagination links)
ends up at one of:
- /meta/page/total & /meta/page/estimatedTotal/bestGuess & /meta/page/rangeTruncated
- /data/relationships/foo/meta/page/total & /data/relationships/foo/meta/page/estimatedTotal/bestGuess & /data/relationships/foo/meta/page/rangeTruncated
- /data/0/relationships/foo/meta/page/total & /data/0/relationships/foo/meta/page/estimatedTotal/bestGuess & /data/0/relationships/foo/meta/page/rangeTruncated
@see https://jsonapi.org/profiles/ethanresnick/cursor-pagination/#terms-pagination-metadata
@param PaginableInterface $paginable
@param int $exactTotal optional
@param int $bestGuessTotal optional
@param boolean $rangeIsTruncated optional, if both after and before are supplied but the items exceed requested or max size | [
"pagination",
"metadata",
"is",
"the",
"page",
"meta",
"that",
"is",
"a",
"sibling",
"of",
"the",
"paginated",
"data",
"(",
"and",
"pagination",
"links",
")"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/profiles/CursorPaginationProfile.php#L217-L233 |
lode/jsonapi | src/profiles/CursorPaginationProfile.php | CursorPaginationProfile.getUnsupportedSortErrorObject | public function getUnsupportedSortErrorObject($genericTitle=null, $specificDetails=null) {
$errorObject = new ErrorObject('Unsupported sort');
$errorObject->appendTypeLink('https://jsonapi.org/profiles/ethanresnick/cursor-pagination/unsupported-sort');
$errorObject->blameQueryParameter('sort');
$errorObject->setHttpStatusCode(400);
if ($genericTitle !== null) {
$errorObject->setHumanExplanation($genericTitle, $specificDetails);
}
return $errorObject;
} | php | public function getUnsupportedSortErrorObject($genericTitle=null, $specificDetails=null) {
$errorObject = new ErrorObject('Unsupported sort');
$errorObject->appendTypeLink('https://jsonapi.org/profiles/ethanresnick/cursor-pagination/unsupported-sort');
$errorObject->blameQueryParameter('sort');
$errorObject->setHttpStatusCode(400);
if ($genericTitle !== null) {
$errorObject->setHumanExplanation($genericTitle, $specificDetails);
}
return $errorObject;
} | [
"public",
"function",
"getUnsupportedSortErrorObject",
"(",
"$",
"genericTitle",
"=",
"null",
",",
"$",
"specificDetails",
"=",
"null",
")",
"{",
"$",
"errorObject",
"=",
"new",
"ErrorObject",
"(",
"'Unsupported sort'",
")",
";",
"$",
"errorObject",
"->",
"appendTypeLink",
"(",
"'https://jsonapi.org/profiles/ethanresnick/cursor-pagination/unsupported-sort'",
")",
";",
"$",
"errorObject",
"->",
"blameQueryParameter",
"(",
"'sort'",
")",
";",
"$",
"errorObject",
"->",
"setHttpStatusCode",
"(",
"400",
")",
";",
"if",
"(",
"$",
"genericTitle",
"!==",
"null",
")",
"{",
"$",
"errorObject",
"->",
"setHumanExplanation",
"(",
"$",
"genericTitle",
",",
"$",
"specificDetails",
")",
";",
"}",
"return",
"$",
"errorObject",
";",
"}"
] | get an ErrorObject for when the requested sorting cannot efficiently be paginated
ends up at:
- /errors/0/code
- /errors/0/status
- /errors/0/source/parameter
- /errors/0/links/type/0
- /errors/0/title optional
- /errors/0/detail optional
@param string $genericTitle optional
@param string $specificDetails optional
@return ErrorObject | [
"get",
"an",
"ErrorObject",
"for",
"when",
"the",
"requested",
"sorting",
"cannot",
"efficiently",
"be",
"paginated"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/profiles/CursorPaginationProfile.php#L250-L261 |
lode/jsonapi | src/profiles/CursorPaginationProfile.php | CursorPaginationProfile.getMaxPageSizeExceededErrorObject | public function getMaxPageSizeExceededErrorObject($maxSize, $genericTitle=null, $specificDetails=null) {
$errorObject = new ErrorObject('Max page size exceeded');
$errorObject->appendTypeLink('https://jsonapi.org/profiles/ethanresnick/cursor-pagination/max-size-exceeded');
$errorObject->blameQueryParameter($this->getKeyword('page').'[size]');
$errorObject->setHttpStatusCode(400);
$errorObject->addMeta($this->getKeyword('page'), $value=['maxSize' => $maxSize]);
if ($genericTitle !== null) {
$errorObject->setHumanExplanation($genericTitle, $specificDetails);
}
return $errorObject;
} | php | public function getMaxPageSizeExceededErrorObject($maxSize, $genericTitle=null, $specificDetails=null) {
$errorObject = new ErrorObject('Max page size exceeded');
$errorObject->appendTypeLink('https://jsonapi.org/profiles/ethanresnick/cursor-pagination/max-size-exceeded');
$errorObject->blameQueryParameter($this->getKeyword('page').'[size]');
$errorObject->setHttpStatusCode(400);
$errorObject->addMeta($this->getKeyword('page'), $value=['maxSize' => $maxSize]);
if ($genericTitle !== null) {
$errorObject->setHumanExplanation($genericTitle, $specificDetails);
}
return $errorObject;
} | [
"public",
"function",
"getMaxPageSizeExceededErrorObject",
"(",
"$",
"maxSize",
",",
"$",
"genericTitle",
"=",
"null",
",",
"$",
"specificDetails",
"=",
"null",
")",
"{",
"$",
"errorObject",
"=",
"new",
"ErrorObject",
"(",
"'Max page size exceeded'",
")",
";",
"$",
"errorObject",
"->",
"appendTypeLink",
"(",
"'https://jsonapi.org/profiles/ethanresnick/cursor-pagination/max-size-exceeded'",
")",
";",
"$",
"errorObject",
"->",
"blameQueryParameter",
"(",
"$",
"this",
"->",
"getKeyword",
"(",
"'page'",
")",
".",
"'[size]'",
")",
";",
"$",
"errorObject",
"->",
"setHttpStatusCode",
"(",
"400",
")",
";",
"$",
"errorObject",
"->",
"addMeta",
"(",
"$",
"this",
"->",
"getKeyword",
"(",
"'page'",
")",
",",
"$",
"value",
"=",
"[",
"'maxSize'",
"=>",
"$",
"maxSize",
"]",
")",
";",
"if",
"(",
"$",
"genericTitle",
"!==",
"null",
")",
"{",
"$",
"errorObject",
"->",
"setHumanExplanation",
"(",
"$",
"genericTitle",
",",
"$",
"specificDetails",
")",
";",
"}",
"return",
"$",
"errorObject",
";",
"}"
] | get an ErrorObject for when the requested page size exceeds the server-defined max page size
ends up at:
- /errors/0/code
- /errors/0/status
- /errors/0/source/parameter
- /errors/0/links/type/0
- /errors/0/meta/page/maxSize
- /errors/0/title optional
- /errors/0/detail optional
@param int $maxSize
@param string $genericTitle optional, e.g. 'Page size requested is too large.'
@param string $specificDetails optional, e.g. 'You requested a size of 200, but 100 is the maximum.'
@return ErrorObject | [
"get",
"an",
"ErrorObject",
"for",
"when",
"the",
"requested",
"page",
"size",
"exceeds",
"the",
"server",
"-",
"defined",
"max",
"page",
"size"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/profiles/CursorPaginationProfile.php#L280-L292 |
lode/jsonapi | src/profiles/CursorPaginationProfile.php | CursorPaginationProfile.getInvalidParameterValueErrorObject | public function getInvalidParameterValueErrorObject($queryParameter, $typeLink=null, $genericTitle=null, $specificDetails=null) {
$errorObject = new ErrorObject('Invalid parameter value');
$errorObject->blameQueryParameter($queryParameter);
$errorObject->setHttpStatusCode(400);
if ($typeLink !== null) {
$errorObject->appendTypeLink($typeLink);
}
if ($genericTitle !== null) {
$errorObject->setHumanExplanation($genericTitle, $specificDetails);
}
return $errorObject;
} | php | public function getInvalidParameterValueErrorObject($queryParameter, $typeLink=null, $genericTitle=null, $specificDetails=null) {
$errorObject = new ErrorObject('Invalid parameter value');
$errorObject->blameQueryParameter($queryParameter);
$errorObject->setHttpStatusCode(400);
if ($typeLink !== null) {
$errorObject->appendTypeLink($typeLink);
}
if ($genericTitle !== null) {
$errorObject->setHumanExplanation($genericTitle, $specificDetails);
}
return $errorObject;
} | [
"public",
"function",
"getInvalidParameterValueErrorObject",
"(",
"$",
"queryParameter",
",",
"$",
"typeLink",
"=",
"null",
",",
"$",
"genericTitle",
"=",
"null",
",",
"$",
"specificDetails",
"=",
"null",
")",
"{",
"$",
"errorObject",
"=",
"new",
"ErrorObject",
"(",
"'Invalid parameter value'",
")",
";",
"$",
"errorObject",
"->",
"blameQueryParameter",
"(",
"$",
"queryParameter",
")",
";",
"$",
"errorObject",
"->",
"setHttpStatusCode",
"(",
"400",
")",
";",
"if",
"(",
"$",
"typeLink",
"!==",
"null",
")",
"{",
"$",
"errorObject",
"->",
"appendTypeLink",
"(",
"$",
"typeLink",
")",
";",
"}",
"if",
"(",
"$",
"genericTitle",
"!==",
"null",
")",
"{",
"$",
"errorObject",
"->",
"setHumanExplanation",
"(",
"$",
"genericTitle",
",",
"$",
"specificDetails",
")",
";",
"}",
"return",
"$",
"errorObject",
";",
"}"
] | get an ErrorObject for when the requested page size is not a positive integer, or when the requested page after/before is not a valid cursor
ends up at:
- /errors/0/code
- /errors/0/status
- /errors/0/source/parameter
- /errors/0/links/type/0 optional
- /errors/0/title optional
- /errors/0/detail optional
@param int $queryParameter e.g. 'sort' or 'page[size]', aliasing should already be done using {@see getKeyword}
@param string $typeLink optional
@param string $genericTitle optional, e.g. 'Invalid Parameter.'
@param string $specificDetails optional, e.g. 'page[size] must be a positive integer; got 0'
@return ErrorObject | [
"get",
"an",
"ErrorObject",
"for",
"when",
"the",
"requested",
"page",
"size",
"is",
"not",
"a",
"positive",
"integer",
"or",
"when",
"the",
"requested",
"page",
"after",
"/",
"before",
"is",
"not",
"a",
"valid",
"cursor"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/profiles/CursorPaginationProfile.php#L311-L325 |
lode/jsonapi | src/profiles/CursorPaginationProfile.php | CursorPaginationProfile.getRangePaginationNotSupportedErrorObject | public function getRangePaginationNotSupportedErrorObject($genericTitle=null, $specificDetails=null) {
$errorObject = new ErrorObject('Range pagination not supported');
$errorObject->appendTypeLink('https://jsonapi.org/profiles/ethanresnick/cursor-pagination/range-pagination-not-supported');
$errorObject->setHttpStatusCode(400);
if ($genericTitle !== null) {
$errorObject->setHumanExplanation($genericTitle, $specificDetails);
}
return $errorObject;
} | php | public function getRangePaginationNotSupportedErrorObject($genericTitle=null, $specificDetails=null) {
$errorObject = new ErrorObject('Range pagination not supported');
$errorObject->appendTypeLink('https://jsonapi.org/profiles/ethanresnick/cursor-pagination/range-pagination-not-supported');
$errorObject->setHttpStatusCode(400);
if ($genericTitle !== null) {
$errorObject->setHumanExplanation($genericTitle, $specificDetails);
}
return $errorObject;
} | [
"public",
"function",
"getRangePaginationNotSupportedErrorObject",
"(",
"$",
"genericTitle",
"=",
"null",
",",
"$",
"specificDetails",
"=",
"null",
")",
"{",
"$",
"errorObject",
"=",
"new",
"ErrorObject",
"(",
"'Range pagination not supported'",
")",
";",
"$",
"errorObject",
"->",
"appendTypeLink",
"(",
"'https://jsonapi.org/profiles/ethanresnick/cursor-pagination/range-pagination-not-supported'",
")",
";",
"$",
"errorObject",
"->",
"setHttpStatusCode",
"(",
"400",
")",
";",
"if",
"(",
"$",
"genericTitle",
"!==",
"null",
")",
"{",
"$",
"errorObject",
"->",
"setHumanExplanation",
"(",
"$",
"genericTitle",
",",
"$",
"specificDetails",
")",
";",
"}",
"return",
"$",
"errorObject",
";",
"}"
] | get an ErrorObject for when range pagination requests (when both 'page[after]' and 'page[before]' are requested) are not supported
ends up at:
- /errors/0/code
- /errors/0/status
- /errors/0/links/type/0
@param string $genericTitle optional
@param string $specificDetails optional
@return ErrorObject | [
"get",
"an",
"ErrorObject",
"for",
"when",
"range",
"pagination",
"requests",
"(",
"when",
"both",
"page",
"[",
"after",
"]",
"and",
"page",
"[",
"before",
"]",
"are",
"requested",
")",
"are",
"not",
"supported"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/profiles/CursorPaginationProfile.php#L339-L349 |
lode/jsonapi | src/profiles/CursorPaginationProfile.php | CursorPaginationProfile.setQueryParameter | private function setQueryParameter($url, $key, $value) {
$originalQuery = parse_url($url, PHP_URL_QUERY);
$decodedQuery = urldecode($originalQuery);
$originalIsEncoded = ($decodedQuery !== $originalQuery);
$originalParameters = [];
parse_str($decodedQuery, $originalParameters);
$newParameters = [];
parse_str($key.'='.$value, $newParameters);
$fullParameters = array_replace_recursive($originalParameters, $newParameters);
$newQuery = http_build_query($fullParameters);
if ($originalIsEncoded === false) {
$newQuery = urldecode($newQuery);
}
$newUrl = str_replace($originalQuery, $newQuery, $url);
return $newUrl;
} | php | private function setQueryParameter($url, $key, $value) {
$originalQuery = parse_url($url, PHP_URL_QUERY);
$decodedQuery = urldecode($originalQuery);
$originalIsEncoded = ($decodedQuery !== $originalQuery);
$originalParameters = [];
parse_str($decodedQuery, $originalParameters);
$newParameters = [];
parse_str($key.'='.$value, $newParameters);
$fullParameters = array_replace_recursive($originalParameters, $newParameters);
$newQuery = http_build_query($fullParameters);
if ($originalIsEncoded === false) {
$newQuery = urldecode($newQuery);
}
$newUrl = str_replace($originalQuery, $newQuery, $url);
return $newUrl;
} | [
"private",
"function",
"setQueryParameter",
"(",
"$",
"url",
",",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"originalQuery",
"=",
"parse_url",
"(",
"$",
"url",
",",
"PHP_URL_QUERY",
")",
";",
"$",
"decodedQuery",
"=",
"urldecode",
"(",
"$",
"originalQuery",
")",
";",
"$",
"originalIsEncoded",
"=",
"(",
"$",
"decodedQuery",
"!==",
"$",
"originalQuery",
")",
";",
"$",
"originalParameters",
"=",
"[",
"]",
";",
"parse_str",
"(",
"$",
"decodedQuery",
",",
"$",
"originalParameters",
")",
";",
"$",
"newParameters",
"=",
"[",
"]",
";",
"parse_str",
"(",
"$",
"key",
".",
"'='",
".",
"$",
"value",
",",
"$",
"newParameters",
")",
";",
"$",
"fullParameters",
"=",
"array_replace_recursive",
"(",
"$",
"originalParameters",
",",
"$",
"newParameters",
")",
";",
"$",
"newQuery",
"=",
"http_build_query",
"(",
"$",
"fullParameters",
")",
";",
"if",
"(",
"$",
"originalIsEncoded",
"===",
"false",
")",
"{",
"$",
"newQuery",
"=",
"urldecode",
"(",
"$",
"newQuery",
")",
";",
"}",
"$",
"newUrl",
"=",
"str_replace",
"(",
"$",
"originalQuery",
",",
"$",
"newQuery",
",",
"$",
"url",
")",
";",
"return",
"$",
"newUrl",
";",
"}"
] | add or adjust a key in the query string of a url
@param string $url
@param string $key
@param string $value | [
"add",
"or",
"adjust",
"a",
"key",
"in",
"the",
"query",
"string",
"of",
"a",
"url"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/profiles/CursorPaginationProfile.php#L362-L383 |
lode/jsonapi | src/helpers/LinksManager.php | LinksManager.addLink | public function addLink($key, $href, array $meta=[]) {
$this->ensureLinksObject();
$this->links->add($key, $href, $meta);
} | php | public function addLink($key, $href, array $meta=[]) {
$this->ensureLinksObject();
$this->links->add($key, $href, $meta);
} | [
"public",
"function",
"addLink",
"(",
"$",
"key",
",",
"$",
"href",
",",
"array",
"$",
"meta",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"ensureLinksObject",
"(",
")",
";",
"$",
"this",
"->",
"links",
"->",
"add",
"(",
"$",
"key",
",",
"$",
"href",
",",
"$",
"meta",
")",
";",
"}"
] | set a key containing a link
@param string $key
@param string $href
@param array $meta optional, if given a LinkObject is added, otherwise a link string is added | [
"set",
"a",
"key",
"containing",
"a",
"link"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/helpers/LinksManager.php#L24-L27 |
lode/jsonapi | src/helpers/LinksManager.php | LinksManager.appendLink | public function appendLink($key, $href, array $meta=[]) {
$this->ensureLinksObject();
$this->links->append($key, $href, $meta);
} | php | public function appendLink($key, $href, array $meta=[]) {
$this->ensureLinksObject();
$this->links->append($key, $href, $meta);
} | [
"public",
"function",
"appendLink",
"(",
"$",
"key",
",",
"$",
"href",
",",
"array",
"$",
"meta",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"ensureLinksObject",
"(",
")",
";",
"$",
"this",
"->",
"links",
"->",
"append",
"(",
"$",
"key",
",",
"$",
"href",
",",
"$",
"meta",
")",
";",
"}"
] | append a link to a key with an array of links
@param string $key
@param string $href
@param array $meta optional, if given a LinkObject is added, otherwise a link string is added | [
"append",
"a",
"link",
"to",
"a",
"key",
"with",
"an",
"array",
"of",
"links"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/helpers/LinksManager.php#L36-L39 |
lode/jsonapi | src/helpers/LinksManager.php | LinksManager.addLinkObject | public function addLinkObject($key, LinkObject $linkObject) {
$this->ensureLinksObject();
$this->links->addLinkObject($key, $linkObject);
} | php | public function addLinkObject($key, LinkObject $linkObject) {
$this->ensureLinksObject();
$this->links->addLinkObject($key, $linkObject);
} | [
"public",
"function",
"addLinkObject",
"(",
"$",
"key",
",",
"LinkObject",
"$",
"linkObject",
")",
"{",
"$",
"this",
"->",
"ensureLinksObject",
"(",
")",
";",
"$",
"this",
"->",
"links",
"->",
"addLinkObject",
"(",
"$",
"key",
",",
"$",
"linkObject",
")",
";",
"}"
] | set a key containing a LinkObject
@param string $key
@param LinkObject $linkObject | [
"set",
"a",
"key",
"containing",
"a",
"LinkObject"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/helpers/LinksManager.php#L51-L54 |
lode/jsonapi | src/helpers/LinksManager.php | LinksManager.addLinksArray | public function addLinksArray($key, LinksArray $linksArray) {
$this->ensureLinksObject();
$this->links->addLinksArray($key, $linksArray);
} | php | public function addLinksArray($key, LinksArray $linksArray) {
$this->ensureLinksObject();
$this->links->addLinksArray($key, $linksArray);
} | [
"public",
"function",
"addLinksArray",
"(",
"$",
"key",
",",
"LinksArray",
"$",
"linksArray",
")",
"{",
"$",
"this",
"->",
"ensureLinksObject",
"(",
")",
";",
"$",
"this",
"->",
"links",
"->",
"addLinksArray",
"(",
"$",
"key",
",",
"$",
"linksArray",
")",
";",
"}"
] | set a key containing a LinksArray
@param string $key
@param LinksArray $linksArray | [
"set",
"a",
"key",
"containing",
"a",
"LinksArray"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/helpers/LinksManager.php#L62-L65 |
lode/jsonapi | src/helpers/LinksManager.php | LinksManager.appendLinkObject | public function appendLinkObject($key, LinkObject $linkObject) {
$this->ensureLinksObject();
$this->links->appendLinkObject($key, $linkObject);
} | php | public function appendLinkObject($key, LinkObject $linkObject) {
$this->ensureLinksObject();
$this->links->appendLinkObject($key, $linkObject);
} | [
"public",
"function",
"appendLinkObject",
"(",
"$",
"key",
",",
"LinkObject",
"$",
"linkObject",
")",
"{",
"$",
"this",
"->",
"ensureLinksObject",
"(",
")",
";",
"$",
"this",
"->",
"links",
"->",
"appendLinkObject",
"(",
"$",
"key",
",",
"$",
"linkObject",
")",
";",
"}"
] | append a LinkObject to a key with a LinksArray
@param string $key
@param LinkObject $linkObject | [
"append",
"a",
"LinkObject",
"to",
"a",
"key",
"with",
"a",
"LinksArray"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/helpers/LinksManager.php#L73-L76 |
lode/jsonapi | src/MetaDocument.php | MetaDocument.add | public function add($key, $value, $level=Document::LEVEL_ROOT) {
parent::addMeta($key, $value, $level);
} | php | public function add($key, $value, $level=Document::LEVEL_ROOT) {
parent::addMeta($key, $value, $level);
} | [
"public",
"function",
"add",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"level",
"=",
"Document",
"::",
"LEVEL_ROOT",
")",
"{",
"parent",
"::",
"addMeta",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"level",
")",
";",
"}"
] | wrapper for Document::addMeta() to the primary data of this document available via `add()`
@param string $key
@param mixed $value
@param string $level one of the Document::LEVEL_* constants, optional, defaults to Document::LEVEL_ROOT | [
"wrapper",
"for",
"Document",
"::",
"addMeta",
"()",
"to",
"the",
"primary",
"data",
"of",
"this",
"document",
"available",
"via",
"add",
"()"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/MetaDocument.php#L46-L48 |
lode/jsonapi | src/CollectionDocument.php | CollectionDocument.fromResources | public static function fromResources(ResourceInterface ...$resources) {
$collectionDocument = new self();
foreach ($resources as $resource) {
$collectionDocument->addResource($resource);
}
return $collectionDocument;
} | php | public static function fromResources(ResourceInterface ...$resources) {
$collectionDocument = new self();
foreach ($resources as $resource) {
$collectionDocument->addResource($resource);
}
return $collectionDocument;
} | [
"public",
"static",
"function",
"fromResources",
"(",
"ResourceInterface",
"...",
"$",
"resources",
")",
"{",
"$",
"collectionDocument",
"=",
"new",
"self",
"(",
")",
";",
"foreach",
"(",
"$",
"resources",
"as",
"$",
"resource",
")",
"{",
"$",
"collectionDocument",
"->",
"addResource",
"(",
"$",
"resource",
")",
";",
"}",
"return",
"$",
"collectionDocument",
";",
"}"
] | generate a CollectionDocument from one or multiple resources
adds included resources if found inside the resource's relationships, use {@see ->addResource()} to change that behavior
@param ResourceInterface ...$resources
@return CollectionDocument | [
"generate",
"a",
"CollectionDocument",
"from",
"one",
"or",
"multiple",
"resources"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/CollectionDocument.php#L42-L50 |
lode/jsonapi | src/CollectionDocument.php | CollectionDocument.addResource | public function addResource(ResourceInterface $resource, array $options=[]) {
if ($resource->getResource()->isEmpty()) {
throw new InputException('does not make sense to add empty resources to a collection');
}
$options = array_merge(self::$defaults, $options);
$this->validator->claimUsedResourceIdentifier($resource);
$this->resources[] = $resource;
if ($options['includeContainedResources'] && $resource instanceof RecursiveResourceContainerInterface) {
$this->addIncludedResourceObject(...$resource->getNestedContainedResourceObjects());
}
} | php | public function addResource(ResourceInterface $resource, array $options=[]) {
if ($resource->getResource()->isEmpty()) {
throw new InputException('does not make sense to add empty resources to a collection');
}
$options = array_merge(self::$defaults, $options);
$this->validator->claimUsedResourceIdentifier($resource);
$this->resources[] = $resource;
if ($options['includeContainedResources'] && $resource instanceof RecursiveResourceContainerInterface) {
$this->addIncludedResourceObject(...$resource->getNestedContainedResourceObjects());
}
} | [
"public",
"function",
"addResource",
"(",
"ResourceInterface",
"$",
"resource",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"resource",
"->",
"getResource",
"(",
")",
"->",
"isEmpty",
"(",
")",
")",
"{",
"throw",
"new",
"InputException",
"(",
"'does not make sense to add empty resources to a collection'",
")",
";",
"}",
"$",
"options",
"=",
"array_merge",
"(",
"self",
"::",
"$",
"defaults",
",",
"$",
"options",
")",
";",
"$",
"this",
"->",
"validator",
"->",
"claimUsedResourceIdentifier",
"(",
"$",
"resource",
")",
";",
"$",
"this",
"->",
"resources",
"[",
"]",
"=",
"$",
"resource",
";",
"if",
"(",
"$",
"options",
"[",
"'includeContainedResources'",
"]",
"&&",
"$",
"resource",
"instanceof",
"RecursiveResourceContainerInterface",
")",
"{",
"$",
"this",
"->",
"addIncludedResourceObject",
"(",
"...",
"$",
"resource",
"->",
"getNestedContainedResourceObjects",
"(",
")",
")",
";",
"}",
"}"
] | add a resource to the collection
adds included resources if found inside the resource's relationships, unless $options['includeContainedResources'] is set to false
@param ResourceInterface $resource
@param array $options optional {@see CollectionDocument::$defaults}
@throws InputException if the resource is empty | [
"add",
"a",
"resource",
"to",
"the",
"collection"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/CollectionDocument.php#L98-L112 |
lode/jsonapi | src/objects/ResourceObject.php | ResourceObject.fromArray | public static function fromArray(array $attributes, $type=null, $id=null, array $options=[]) {
if (isset($attributes['id'])) {
if ($id === null) {
$id = $attributes['id'];
}
unset($attributes['id']);
}
$resourceObject = new self($type, $id);
$resourceObject->setAttributesObject(AttributesObject::fromArray($attributes), $options);
return $resourceObject;
} | php | public static function fromArray(array $attributes, $type=null, $id=null, array $options=[]) {
if (isset($attributes['id'])) {
if ($id === null) {
$id = $attributes['id'];
}
unset($attributes['id']);
}
$resourceObject = new self($type, $id);
$resourceObject->setAttributesObject(AttributesObject::fromArray($attributes), $options);
return $resourceObject;
} | [
"public",
"static",
"function",
"fromArray",
"(",
"array",
"$",
"attributes",
",",
"$",
"type",
"=",
"null",
",",
"$",
"id",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"attributes",
"[",
"'id'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"id",
"===",
"null",
")",
"{",
"$",
"id",
"=",
"$",
"attributes",
"[",
"'id'",
"]",
";",
"}",
"unset",
"(",
"$",
"attributes",
"[",
"'id'",
"]",
")",
";",
"}",
"$",
"resourceObject",
"=",
"new",
"self",
"(",
"$",
"type",
",",
"$",
"id",
")",
";",
"$",
"resourceObject",
"->",
"setAttributesObject",
"(",
"AttributesObject",
"::",
"fromArray",
"(",
"$",
"attributes",
")",
",",
"$",
"options",
")",
";",
"return",
"$",
"resourceObject",
";",
"}"
] | @note if an `id` is set inside $attributes, it is removed from there
and if $id is null, it is filled with that value
it is common to find it inside, and not doing so will cause an exception
@param array $attributes
@param string $type optional
@param string|int $id optional
@param array $options optional {@see ResourceObject::$defaults}
@return ResourceObject | [
"@note",
"if",
"an",
"id",
"is",
"set",
"inside",
"$attributes",
"it",
"is",
"removed",
"from",
"there",
"and",
"if",
"$id",
"is",
"null",
"it",
"is",
"filled",
"with",
"that",
"value",
"it",
"is",
"common",
"to",
"find",
"it",
"inside",
"and",
"not",
"doing",
"so",
"will",
"cause",
"an",
"exception"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/objects/ResourceObject.php#L49-L62 |
lode/jsonapi | src/objects/ResourceObject.php | ResourceObject.add | public function add($key, $value, array $options=[]) {
$options = array_merge(self::$defaults, $options);
if ($this->attributes === null) {
$this->attributes = new AttributesObject();
}
$this->validator->claimUsedFields([$key], Validator::OBJECT_CONTAINER_ATTRIBUTES, $options);
$this->attributes->add($key, $value);
} | php | public function add($key, $value, array $options=[]) {
$options = array_merge(self::$defaults, $options);
if ($this->attributes === null) {
$this->attributes = new AttributesObject();
}
$this->validator->claimUsedFields([$key], Validator::OBJECT_CONTAINER_ATTRIBUTES, $options);
$this->attributes->add($key, $value);
} | [
"public",
"function",
"add",
"(",
"$",
"key",
",",
"$",
"value",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"=",
"array_merge",
"(",
"self",
"::",
"$",
"defaults",
",",
"$",
"options",
")",
";",
"if",
"(",
"$",
"this",
"->",
"attributes",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"attributes",
"=",
"new",
"AttributesObject",
"(",
")",
";",
"}",
"$",
"this",
"->",
"validator",
"->",
"claimUsedFields",
"(",
"[",
"$",
"key",
"]",
",",
"Validator",
"::",
"OBJECT_CONTAINER_ATTRIBUTES",
",",
"$",
"options",
")",
";",
"$",
"this",
"->",
"attributes",
"->",
"add",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}"
] | add key-value pairs to attributes
@param string $key
@param mixed $value
@param array $options optional {@see ResourceObject::$defaults} | [
"add",
"key",
"-",
"value",
"pairs",
"to",
"attributes"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/objects/ResourceObject.php#L84-L94 |
lode/jsonapi | src/objects/ResourceObject.php | ResourceObject.addRelationshipObject | public function addRelationshipObject($key, RelationshipObject $relationshipObject, array $options=[]) {
if ($relationshipObject->hasResource($this)) {
throw new DuplicateException('can not add relation to self');
}
if ($this->relationships === null) {
$this->setRelationshipsObject(new RelationshipsObject());
}
$this->validator->claimUsedFields([$key], Validator::OBJECT_CONTAINER_RELATIONSHIPS, $options);
$this->relationships->addRelationshipObject($key, $relationshipObject);
} | php | public function addRelationshipObject($key, RelationshipObject $relationshipObject, array $options=[]) {
if ($relationshipObject->hasResource($this)) {
throw new DuplicateException('can not add relation to self');
}
if ($this->relationships === null) {
$this->setRelationshipsObject(new RelationshipsObject());
}
$this->validator->claimUsedFields([$key], Validator::OBJECT_CONTAINER_RELATIONSHIPS, $options);
$this->relationships->addRelationshipObject($key, $relationshipObject);
} | [
"public",
"function",
"addRelationshipObject",
"(",
"$",
"key",
",",
"RelationshipObject",
"$",
"relationshipObject",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"relationshipObject",
"->",
"hasResource",
"(",
"$",
"this",
")",
")",
"{",
"throw",
"new",
"DuplicateException",
"(",
"'can not add relation to self'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"relationships",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"setRelationshipsObject",
"(",
"new",
"RelationshipsObject",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"validator",
"->",
"claimUsedFields",
"(",
"[",
"$",
"key",
"]",
",",
"Validator",
"::",
"OBJECT_CONTAINER_RELATIONSHIPS",
",",
"$",
"options",
")",
";",
"$",
"this",
"->",
"relationships",
"->",
"addRelationshipObject",
"(",
"$",
"key",
",",
"$",
"relationshipObject",
")",
";",
"}"
] | @param string $key
@param RelationshipObject $relationshipObject
@param array $options optional {@see ResourceObject::$defaults}
@throws DuplicateException if the resource is contained as a resource in the relationship | [
"@param",
"string",
"$key",
"@param",
"RelationshipObject",
"$relationshipObject",
"@param",
"array",
"$options",
"optional",
"{",
"@see",
"ResourceObject",
"::",
"$defaults",
"}"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/objects/ResourceObject.php#L143-L155 |
lode/jsonapi | src/objects/ResourceObject.php | ResourceObject.hasIdentifierPropertiesOnly | public function hasIdentifierPropertiesOnly() {
if ($this->attributes !== null && $this->attributes->isEmpty() === false) {
return false;
}
if ($this->relationships !== null && $this->relationships->isEmpty() === false) {
return false;
}
if ($this->links !== null && $this->links->isEmpty() === false) {
return false;
}
return true;
} | php | public function hasIdentifierPropertiesOnly() {
if ($this->attributes !== null && $this->attributes->isEmpty() === false) {
return false;
}
if ($this->relationships !== null && $this->relationships->isEmpty() === false) {
return false;
}
if ($this->links !== null && $this->links->isEmpty() === false) {
return false;
}
return true;
} | [
"public",
"function",
"hasIdentifierPropertiesOnly",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"attributes",
"!==",
"null",
"&&",
"$",
"this",
"->",
"attributes",
"->",
"isEmpty",
"(",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"relationships",
"!==",
"null",
"&&",
"$",
"this",
"->",
"relationships",
"->",
"isEmpty",
"(",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"links",
"!==",
"null",
"&&",
"$",
"this",
"->",
"links",
"->",
"isEmpty",
"(",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | whether the ResourceObject is empty except for the ResourceIdentifierObject
this can be used to determine if a Relationship's resource could be added as included resource
@internal
@return boolean | [
"whether",
"the",
"ResourceObject",
"is",
"empty",
"except",
"for",
"the",
"ResourceIdentifierObject"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/objects/ResourceObject.php#L181-L193 |
lode/jsonapi | src/response.php | response.get_json | public function get_json($encode_options=null) {
if (is_int($encode_options) == false) {
$encode_options = self::ENCODE_DEFAULT;
}
if (base::$debug || strpos($_SERVER['HTTP_ACCEPT'], '/json') == false) {
$encode_options = self::ENCODE_DEBUG;
}
$response = $this->get_array();
$json = json_encode($response, $encode_options);
return $json;
} | php | public function get_json($encode_options=null) {
if (is_int($encode_options) == false) {
$encode_options = self::ENCODE_DEFAULT;
}
if (base::$debug || strpos($_SERVER['HTTP_ACCEPT'], '/json') == false) {
$encode_options = self::ENCODE_DEBUG;
}
$response = $this->get_array();
$json = json_encode($response, $encode_options);
return $json;
} | [
"public",
"function",
"get_json",
"(",
"$",
"encode_options",
"=",
"null",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"encode_options",
")",
"==",
"false",
")",
"{",
"$",
"encode_options",
"=",
"self",
"::",
"ENCODE_DEFAULT",
";",
"}",
"if",
"(",
"base",
"::",
"$",
"debug",
"||",
"strpos",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT'",
"]",
",",
"'/json'",
")",
"==",
"false",
")",
"{",
"$",
"encode_options",
"=",
"self",
"::",
"ENCODE_DEBUG",
";",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"get_array",
"(",
")",
";",
"$",
"json",
"=",
"json_encode",
"(",
"$",
"response",
",",
"$",
"encode_options",
")",
";",
"return",
"$",
"json",
";",
"}"
] | returns the whole response body as json
it generates the response via ->get_array()
@see ->get_array() for the structure
@see json_encode() options
@param int $encode_options optional, $options for json_encode()
defaults to ::ENCODE_DEFAULT or ::ENCODE_DEBUG, @see ::$debug
@return json | [
"returns",
"the",
"whole",
"response",
"body",
"as",
"json",
"it",
"generates",
"the",
"response",
"via",
"-",
">",
"get_array",
"()"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/response.php#L131-L144 |
lode/jsonapi | src/response.php | response.send_response | public function send_response($content_type=null, $encode_options=null, $response=null, $jsonp_callback=null) {
if (is_null($response) && $this->http_status != self::STATUS_NO_CONTENT) {
$response = $this->get_json($encode_options);
}
if (empty($content_type)) {
$content_type = self::CONTENT_TYPE_OFFICIAL;
}
if (base::$debug || strpos($_SERVER['HTTP_ACCEPT'], '/json') == false) {
$content_type = self::CONTENT_TYPE_DEBUG;
}
if (self::$send_status_headers) {
$this->send_status_headers();
}
header('Content-Type: '.$content_type.'; charset=utf-8');
if ($this->http_status == self::STATUS_NO_CONTENT) {
return;
}
// jsonp response
if ($content_type == self::CONTENT_TYPE_JSONP) {
if (empty($jsonp_callback)) {
$jsonp_callback = self::JSONP_CALLBACK_DEFAULT;
}
echo $jsonp_callback.'('.$response.')';
return;
}
echo $response;
} | php | public function send_response($content_type=null, $encode_options=null, $response=null, $jsonp_callback=null) {
if (is_null($response) && $this->http_status != self::STATUS_NO_CONTENT) {
$response = $this->get_json($encode_options);
}
if (empty($content_type)) {
$content_type = self::CONTENT_TYPE_OFFICIAL;
}
if (base::$debug || strpos($_SERVER['HTTP_ACCEPT'], '/json') == false) {
$content_type = self::CONTENT_TYPE_DEBUG;
}
if (self::$send_status_headers) {
$this->send_status_headers();
}
header('Content-Type: '.$content_type.'; charset=utf-8');
if ($this->http_status == self::STATUS_NO_CONTENT) {
return;
}
// jsonp response
if ($content_type == self::CONTENT_TYPE_JSONP) {
if (empty($jsonp_callback)) {
$jsonp_callback = self::JSONP_CALLBACK_DEFAULT;
}
echo $jsonp_callback.'('.$response.')';
return;
}
echo $response;
} | [
"public",
"function",
"send_response",
"(",
"$",
"content_type",
"=",
"null",
",",
"$",
"encode_options",
"=",
"null",
",",
"$",
"response",
"=",
"null",
",",
"$",
"jsonp_callback",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"response",
")",
"&&",
"$",
"this",
"->",
"http_status",
"!=",
"self",
"::",
"STATUS_NO_CONTENT",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"get_json",
"(",
"$",
"encode_options",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"content_type",
")",
")",
"{",
"$",
"content_type",
"=",
"self",
"::",
"CONTENT_TYPE_OFFICIAL",
";",
"}",
"if",
"(",
"base",
"::",
"$",
"debug",
"||",
"strpos",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT'",
"]",
",",
"'/json'",
")",
"==",
"false",
")",
"{",
"$",
"content_type",
"=",
"self",
"::",
"CONTENT_TYPE_DEBUG",
";",
"}",
"if",
"(",
"self",
"::",
"$",
"send_status_headers",
")",
"{",
"$",
"this",
"->",
"send_status_headers",
"(",
")",
";",
"}",
"header",
"(",
"'Content-Type: '",
".",
"$",
"content_type",
".",
"'; charset=utf-8'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"http_status",
"==",
"self",
"::",
"STATUS_NO_CONTENT",
")",
"{",
"return",
";",
"}",
"// jsonp response",
"if",
"(",
"$",
"content_type",
"==",
"self",
"::",
"CONTENT_TYPE_JSONP",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"jsonp_callback",
")",
")",
"{",
"$",
"jsonp_callback",
"=",
"self",
"::",
"JSONP_CALLBACK_DEFAULT",
";",
"}",
"echo",
"$",
"jsonp_callback",
".",
"'('",
".",
"$",
"response",
".",
"')'",
";",
"return",
";",
"}",
"echo",
"$",
"response",
";",
"}"
] | sends out the json response to the browser
this will fetch the response from ->get_json() if not given via $response
@note this also sets the needed http headers (status, location and content-type)
@param string $content_type optional, defaults to ::CONTENT_TYPE_OFFICIAL (the official IANA registered one) ..
.. or to ::CONTENT_TYPE_DEBUG, @see ::$debug
@param int $encode_options optional, $options for json_encode()
defaults to ::ENCODE_DEFAULT or ::ENCODE_DEBUG, @see ::$debug
@param json $response optional, defaults to ::get_json()
@param string $jsonp_callback optional, response as jsonp
@return void however, a string will be echo'd to the browser | [
"sends",
"out",
"the",
"json",
"response",
"to",
"the",
"browser",
"this",
"will",
"fetch",
"the",
"response",
"from",
"-",
">",
"get_json",
"()",
"if",
"not",
"given",
"via",
"$response"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/response.php#L160-L192 |
lode/jsonapi | src/response.php | response.send_status_headers | private function send_status_headers() {
if ($this->redirect_location) {
if ($this->http_status == self::STATUS_OK) {
$this->set_http_status(self::STATUS_TEMPORARY_REDIRECT);
}
header('Location: '.$this->redirect_location, $replace=true, $this->http_status);
return;
}
http_response_code($this->http_status);
} | php | private function send_status_headers() {
if ($this->redirect_location) {
if ($this->http_status == self::STATUS_OK) {
$this->set_http_status(self::STATUS_TEMPORARY_REDIRECT);
}
header('Location: '.$this->redirect_location, $replace=true, $this->http_status);
return;
}
http_response_code($this->http_status);
} | [
"private",
"function",
"send_status_headers",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"redirect_location",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"http_status",
"==",
"self",
"::",
"STATUS_OK",
")",
"{",
"$",
"this",
"->",
"set_http_status",
"(",
"self",
"::",
"STATUS_TEMPORARY_REDIRECT",
")",
";",
"}",
"header",
"(",
"'Location: '",
".",
"$",
"this",
"->",
"redirect_location",
",",
"$",
"replace",
"=",
"true",
",",
"$",
"this",
"->",
"http_status",
")",
";",
"return",
";",
"}",
"http_response_code",
"(",
"$",
"this",
"->",
"http_status",
")",
";",
"}"
] | sends out the http status code and optional redirect location
defaults to ::STATUS_OK, or ::STATUS_INTERNAL_SERVER_ERROR for an errors response
@return void | [
"sends",
"out",
"the",
"http",
"status",
"code",
"and",
"optional",
"redirect",
"location",
"defaults",
"to",
"::",
"STATUS_OK",
"or",
"::",
"STATUS_INTERNAL_SERVER_ERROR",
"for",
"an",
"errors",
"response"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/response.php#L200-L211 |
lode/jsonapi | src/response.php | response.set_redirect_location | public function set_redirect_location($location) {
if (self::$send_status_headers == false && base::$debug) {
trigger_error('location will not be send out unless response::$send_status_headers is true', E_USER_NOTICE);
}
$this->redirect_location = $location;
} | php | public function set_redirect_location($location) {
if (self::$send_status_headers == false && base::$debug) {
trigger_error('location will not be send out unless response::$send_status_headers is true', E_USER_NOTICE);
}
$this->redirect_location = $location;
} | [
"public",
"function",
"set_redirect_location",
"(",
"$",
"location",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"send_status_headers",
"==",
"false",
"&&",
"base",
"::",
"$",
"debug",
")",
"{",
"trigger_error",
"(",
"'location will not be send out unless response::$send_status_headers is true'",
",",
"E_USER_NOTICE",
")",
";",
"}",
"$",
"this",
"->",
"redirect_location",
"=",
"$",
"location",
";",
"}"
] | sets a new location the client should follow
@param string $location absolute url | [
"sets",
"a",
"new",
"location",
"the",
"client",
"should",
"follow"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/response.php#L227-L233 |
lode/jsonapi | src/response.php | response.add_link | public function add_link($key, $link, $meta_data=null) {
if ($meta_data) {
if (is_object($meta_data)) {
$meta_data = parent::convert_object_to_array($meta_data);
}
$link = array(
'href' => $link,
'meta' => $meta_data,
);
}
$this->links[$key] = $link;
} | php | public function add_link($key, $link, $meta_data=null) {
if ($meta_data) {
if (is_object($meta_data)) {
$meta_data = parent::convert_object_to_array($meta_data);
}
$link = array(
'href' => $link,
'meta' => $meta_data,
);
}
$this->links[$key] = $link;
} | [
"public",
"function",
"add_link",
"(",
"$",
"key",
",",
"$",
"link",
",",
"$",
"meta_data",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"meta_data",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"meta_data",
")",
")",
"{",
"$",
"meta_data",
"=",
"parent",
"::",
"convert_object_to_array",
"(",
"$",
"meta_data",
")",
";",
"}",
"$",
"link",
"=",
"array",
"(",
"'href'",
"=>",
"$",
"link",
",",
"'meta'",
"=>",
"$",
"meta_data",
",",
")",
";",
"}",
"$",
"this",
"->",
"links",
"[",
"$",
"key",
"]",
"=",
"$",
"link",
";",
"}"
] | adds a link
this will end up in response.links.{$key}
useful for links which can not be added as relation, @see ->add_relation()
@param string $key
@param mixed $link string with link, or raw link object array/object
@param mixed $meta_data optional, meta data as key-value pairs
objects are converted in arrays, @see base::convert_object_to_array()
@return void | [
"adds",
"a",
"link",
"this",
"will",
"end",
"up",
"in",
"response",
".",
"links",
".",
"{",
"$key",
"}"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/response.php#L257-L270 |
lode/jsonapi | src/response.php | response.fill_links | public function fill_links($links) {
foreach ($links as $key => $link) {
$this->add_link($key, $link);
}
} | php | public function fill_links($links) {
foreach ($links as $key => $link) {
$this->add_link($key, $link);
}
} | [
"public",
"function",
"fill_links",
"(",
"$",
"links",
")",
"{",
"foreach",
"(",
"$",
"links",
"as",
"$",
"key",
"=>",
"$",
"link",
")",
"{",
"$",
"this",
"->",
"add_link",
"(",
"$",
"key",
",",
"$",
"link",
")",
";",
"}",
"}"
] | fills the set of links
this will end up in response.links
@see ->add_link()
@param array $links
@return void | [
"fills",
"the",
"set",
"of",
"links",
"this",
"will",
"end",
"up",
"in",
"response",
".",
"links"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/response.php#L281-L285 |
lode/jsonapi | src/response.php | response.set_self_link | public function set_self_link($link, $meta_data=null) {
if ($meta_data) {
// can not combine both raw link object and extra meta data
if (is_string($link) == false) {
throw new \Exception('link "self" should be a string if meta data is provided separate');
}
if (is_object($meta_data)) {
$meta_data = parent::convert_object_to_array($meta_data);
}
$link = array(
'href' => $link,
'meta' => $meta_data,
);
}
$this->links['self'] = $link;
} | php | public function set_self_link($link, $meta_data=null) {
if ($meta_data) {
// can not combine both raw link object and extra meta data
if (is_string($link) == false) {
throw new \Exception('link "self" should be a string if meta data is provided separate');
}
if (is_object($meta_data)) {
$meta_data = parent::convert_object_to_array($meta_data);
}
$link = array(
'href' => $link,
'meta' => $meta_data,
);
}
$this->links['self'] = $link;
} | [
"public",
"function",
"set_self_link",
"(",
"$",
"link",
",",
"$",
"meta_data",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"meta_data",
")",
"{",
"// can not combine both raw link object and extra meta data",
"if",
"(",
"is_string",
"(",
"$",
"link",
")",
"==",
"false",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'link \"self\" should be a string if meta data is provided separate'",
")",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"meta_data",
")",
")",
"{",
"$",
"meta_data",
"=",
"parent",
"::",
"convert_object_to_array",
"(",
"$",
"meta_data",
")",
";",
"}",
"$",
"link",
"=",
"array",
"(",
"'href'",
"=>",
"$",
"link",
",",
"'meta'",
"=>",
"$",
"meta_data",
",",
")",
";",
"}",
"$",
"this",
"->",
"links",
"[",
"'self'",
"]",
"=",
"$",
"link",
";",
"}"
] | sets the link to the request used to give this response
this will end up in response.links.self ..
and in response.data.links.self for single resource objects
by default this is already set using $_SERVER variables
use this method to override this default behavior
@see ::__construct()
@param string $link
@param mixed $meta_data optional, meta data as key-value pairs
objects are converted in arrays, @see base::convert_object_to_array()
@return void | [
"sets",
"the",
"link",
"to",
"the",
"request",
"used",
"to",
"give",
"this",
"response",
"this",
"will",
"end",
"up",
"in",
"response",
".",
"links",
".",
"self",
"..",
"and",
"in",
"response",
".",
"data",
".",
"links",
".",
"self",
"for",
"single",
"resource",
"objects"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/response.php#L301-L319 |
lode/jsonapi | src/response.php | response.add_self_link_meta | public function add_self_link_meta($key, $meta_data) {
if (is_object($meta_data)) {
$meta_data = self::convert_to_array($meta_data);
}
// converts string-type link
if (is_string($this->links['self'])) {
$this->links['self'] = array(
'href' => $this->links['self'],
'meta' => array(),
);
}
$this->links['self']['meta'][$key] = $meta_data;
} | php | public function add_self_link_meta($key, $meta_data) {
if (is_object($meta_data)) {
$meta_data = self::convert_to_array($meta_data);
}
// converts string-type link
if (is_string($this->links['self'])) {
$this->links['self'] = array(
'href' => $this->links['self'],
'meta' => array(),
);
}
$this->links['self']['meta'][$key] = $meta_data;
} | [
"public",
"function",
"add_self_link_meta",
"(",
"$",
"key",
",",
"$",
"meta_data",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"meta_data",
")",
")",
"{",
"$",
"meta_data",
"=",
"self",
"::",
"convert_to_array",
"(",
"$",
"meta_data",
")",
";",
"}",
"// converts string-type link",
"if",
"(",
"is_string",
"(",
"$",
"this",
"->",
"links",
"[",
"'self'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"links",
"[",
"'self'",
"]",
"=",
"array",
"(",
"'href'",
"=>",
"$",
"this",
"->",
"links",
"[",
"'self'",
"]",
",",
"'meta'",
"=>",
"array",
"(",
")",
",",
")",
";",
"}",
"$",
"this",
"->",
"links",
"[",
"'self'",
"]",
"[",
"'meta'",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"meta_data",
";",
"}"
] | adds meta data to the default self link
this will end up in response.links.self.meta.{$key}
@note you can also use ->set_self_link() with the whole meta object at once
@param string $key
@param mixed $meta_data objects are converted in arrays, @see base::convert_object_to_array()
@return void | [
"adds",
"meta",
"data",
"to",
"the",
"default",
"self",
"link",
"this",
"will",
"end",
"up",
"in",
"response",
".",
"links",
".",
"self",
".",
"meta",
".",
"{",
"$key",
"}"
] | train | https://github.com/lode/jsonapi/blob/6a96d5e4164338e3bd025058a56b40d53af5b3d1/src/response.php#L331-L345 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.