repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
flarum/core | src/Group/Group.php | Group.hasPermission | public function hasPermission($permission)
{
if ($this->id == self::ADMINISTRATOR_ID) {
return true;
}
return $this->permissions->contains('permission', $permission);
} | php | public function hasPermission($permission)
{
if ($this->id == self::ADMINISTRATOR_ID) {
return true;
}
return $this->permissions->contains('permission', $permission);
} | [
"public",
"function",
"hasPermission",
"(",
"$",
"permission",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"id",
"==",
"self",
"::",
"ADMINISTRATOR_ID",
")",
"{",
"return",
"true",
";",
"}",
"return",
"$",
"this",
"->",
"permissions",
"->",
"contains",
"(",
"'permission'",
",",
"$",
"permission",
")",
";",
"}"
] | Check whether the group has a certain permission.
@param string $permission
@return bool | [
"Check",
"whether",
"the",
"group",
"has",
"a",
"certain",
"permission",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Group/Group.php#L136-L143 | train |
flarum/core | src/User/RegistrationToken.php | RegistrationToken.generate | public static function generate(string $provider, string $identifier, array $attributes, array $payload)
{
$token = new static;
$token->token = str_random(40);
$token->provider = $provider;
$token->identifier = $identifier;
$token->user_attributes = $attributes;
$token->payload = $payload;
$token->created_at = Carbon::now();
return $token;
} | php | public static function generate(string $provider, string $identifier, array $attributes, array $payload)
{
$token = new static;
$token->token = str_random(40);
$token->provider = $provider;
$token->identifier = $identifier;
$token->user_attributes = $attributes;
$token->payload = $payload;
$token->created_at = Carbon::now();
return $token;
} | [
"public",
"static",
"function",
"generate",
"(",
"string",
"$",
"provider",
",",
"string",
"$",
"identifier",
",",
"array",
"$",
"attributes",
",",
"array",
"$",
"payload",
")",
"{",
"$",
"token",
"=",
"new",
"static",
";",
"$",
"token",
"->",
"token",
"=",
"str_random",
"(",
"40",
")",
";",
"$",
"token",
"->",
"provider",
"=",
"$",
"provider",
";",
"$",
"token",
"->",
"identifier",
"=",
"$",
"identifier",
";",
"$",
"token",
"->",
"user_attributes",
"=",
"$",
"attributes",
";",
"$",
"token",
"->",
"payload",
"=",
"$",
"payload",
";",
"$",
"token",
"->",
"created_at",
"=",
"Carbon",
"::",
"now",
"(",
")",
";",
"return",
"$",
"token",
";",
"}"
] | Generate an auth token for the specified user.
@param string $provider
@param string $identifier
@param array $attributes
@param array $payload
@return static | [
"Generate",
"an",
"auth",
"token",
"for",
"the",
"specified",
"user",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/User/RegistrationToken.php#L61-L73 | train |
flarum/core | src/Http/Middleware/DispatchRoute.php | DispatchRoute.process | public function process(Request $request, Handler $handler): Response
{
$method = $request->getMethod();
$uri = $request->getUri()->getPath() ?: '/';
$routeInfo = $this->getDispatcher()->dispatch($method, $uri);
switch ($routeInfo[0]) {
case Dispatcher::NOT_FOUND:
throw new RouteNotFoundException($uri);
case Dispatcher::METHOD_NOT_ALLOWED:
throw new MethodNotAllowedException($method);
case Dispatcher::FOUND:
$handler = $routeInfo[1];
$parameters = $routeInfo[2];
return $handler($request, $parameters);
}
} | php | public function process(Request $request, Handler $handler): Response
{
$method = $request->getMethod();
$uri = $request->getUri()->getPath() ?: '/';
$routeInfo = $this->getDispatcher()->dispatch($method, $uri);
switch ($routeInfo[0]) {
case Dispatcher::NOT_FOUND:
throw new RouteNotFoundException($uri);
case Dispatcher::METHOD_NOT_ALLOWED:
throw new MethodNotAllowedException($method);
case Dispatcher::FOUND:
$handler = $routeInfo[1];
$parameters = $routeInfo[2];
return $handler($request, $parameters);
}
} | [
"public",
"function",
"process",
"(",
"Request",
"$",
"request",
",",
"Handler",
"$",
"handler",
")",
":",
"Response",
"{",
"$",
"method",
"=",
"$",
"request",
"->",
"getMethod",
"(",
")",
";",
"$",
"uri",
"=",
"$",
"request",
"->",
"getUri",
"(",
")",
"->",
"getPath",
"(",
")",
"?",
":",
"'/'",
";",
"$",
"routeInfo",
"=",
"$",
"this",
"->",
"getDispatcher",
"(",
")",
"->",
"dispatch",
"(",
"$",
"method",
",",
"$",
"uri",
")",
";",
"switch",
"(",
"$",
"routeInfo",
"[",
"0",
"]",
")",
"{",
"case",
"Dispatcher",
"::",
"NOT_FOUND",
":",
"throw",
"new",
"RouteNotFoundException",
"(",
"$",
"uri",
")",
";",
"case",
"Dispatcher",
"::",
"METHOD_NOT_ALLOWED",
":",
"throw",
"new",
"MethodNotAllowedException",
"(",
"$",
"method",
")",
";",
"case",
"Dispatcher",
"::",
"FOUND",
":",
"$",
"handler",
"=",
"$",
"routeInfo",
"[",
"1",
"]",
";",
"$",
"parameters",
"=",
"$",
"routeInfo",
"[",
"2",
"]",
";",
"return",
"$",
"handler",
"(",
"$",
"request",
",",
"$",
"parameters",
")",
";",
"}",
"}"
] | Dispatch the given request to our route collection.
@throws MethodNotAllowedException
@throws RouteNotFoundException | [
"Dispatch",
"the",
"given",
"request",
"to",
"our",
"route",
"collection",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Http/Middleware/DispatchRoute.php#L51-L69 | train |
flarum/core | src/Post/PostRepository.php | PostRepository.findOrFail | public function findOrFail($id, User $actor = null)
{
return $this->queryVisibleTo($actor)->findOrFail($id);
} | php | public function findOrFail($id, User $actor = null)
{
return $this->queryVisibleTo($actor)->findOrFail($id);
} | [
"public",
"function",
"findOrFail",
"(",
"$",
"id",
",",
"User",
"$",
"actor",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"queryVisibleTo",
"(",
"$",
"actor",
")",
"->",
"findOrFail",
"(",
"$",
"id",
")",
";",
"}"
] | Find a post by ID, optionally making sure it is visible to a certain
user, or throw an exception.
@param int $id
@param \Flarum\User\User $actor
@return \Flarum\Post\Post
@throws \Illuminate\Database\Eloquent\ModelNotFoundException | [
"Find",
"a",
"post",
"by",
"ID",
"optionally",
"making",
"sure",
"it",
"is",
"visible",
"to",
"a",
"certain",
"user",
"or",
"throw",
"an",
"exception",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Post/PostRepository.php#L55-L58 | train |
flarum/core | src/Post/PostRepository.php | PostRepository.findByIds | public function findByIds(array $ids, User $actor = null)
{
$posts = $this->queryIds($ids, $actor)->get();
$posts = $posts->sort(function ($a, $b) use ($ids) {
$aPos = array_search($a->id, $ids);
$bPos = array_search($b->id, $ids);
if ($aPos === $bPos) {
return 0;
}
return $aPos < $bPos ? -1 : 1;
});
return $posts;
} | php | public function findByIds(array $ids, User $actor = null)
{
$posts = $this->queryIds($ids, $actor)->get();
$posts = $posts->sort(function ($a, $b) use ($ids) {
$aPos = array_search($a->id, $ids);
$bPos = array_search($b->id, $ids);
if ($aPos === $bPos) {
return 0;
}
return $aPos < $bPos ? -1 : 1;
});
return $posts;
} | [
"public",
"function",
"findByIds",
"(",
"array",
"$",
"ids",
",",
"User",
"$",
"actor",
"=",
"null",
")",
"{",
"$",
"posts",
"=",
"$",
"this",
"->",
"queryIds",
"(",
"$",
"ids",
",",
"$",
"actor",
")",
"->",
"get",
"(",
")",
";",
"$",
"posts",
"=",
"$",
"posts",
"->",
"sort",
"(",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"use",
"(",
"$",
"ids",
")",
"{",
"$",
"aPos",
"=",
"array_search",
"(",
"$",
"a",
"->",
"id",
",",
"$",
"ids",
")",
";",
"$",
"bPos",
"=",
"array_search",
"(",
"$",
"b",
"->",
"id",
",",
"$",
"ids",
")",
";",
"if",
"(",
"$",
"aPos",
"===",
"$",
"bPos",
")",
"{",
"return",
"0",
";",
"}",
"return",
"$",
"aPos",
"<",
"$",
"bPos",
"?",
"-",
"1",
":",
"1",
";",
"}",
")",
";",
"return",
"$",
"posts",
";",
"}"
] | Find posts by their IDs, optionally making sure they are visible to a
certain user.
@param array $ids
@param \Flarum\User\User|null $actor
@return \Illuminate\Database\Eloquent\Collection | [
"Find",
"posts",
"by",
"their",
"IDs",
"optionally",
"making",
"sure",
"they",
"are",
"visible",
"to",
"a",
"certain",
"user",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Post/PostRepository.php#L93-L109 | train |
flarum/core | src/Post/PostRepository.php | PostRepository.filterVisibleIds | public function filterVisibleIds(array $ids, User $actor)
{
return $this->queryIds($ids, $actor)->pluck('posts.id')->all();
} | php | public function filterVisibleIds(array $ids, User $actor)
{
return $this->queryIds($ids, $actor)->pluck('posts.id')->all();
} | [
"public",
"function",
"filterVisibleIds",
"(",
"array",
"$",
"ids",
",",
"User",
"$",
"actor",
")",
"{",
"return",
"$",
"this",
"->",
"queryIds",
"(",
"$",
"ids",
",",
"$",
"actor",
")",
"->",
"pluck",
"(",
"'posts.id'",
")",
"->",
"all",
"(",
")",
";",
"}"
] | Filter a list of post IDs to only include posts that are visible to a
certain user.
@param array $ids
@param User $actor
@return array | [
"Filter",
"a",
"list",
"of",
"post",
"IDs",
"to",
"only",
"include",
"posts",
"that",
"are",
"visible",
"to",
"a",
"certain",
"user",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Post/PostRepository.php#L119-L122 | train |
flarum/core | src/Post/PostRepository.php | PostRepository.getIndexForNumber | public function getIndexForNumber($discussionId, $number, User $actor = null)
{
$query = Discussion::find($discussionId)
->posts()
->whereVisibleTo($actor)
->where('created_at', '<', function ($query) use ($discussionId, $number) {
$query->select('created_at')
->from('posts')
->where('discussion_id', $discussionId)
->whereNotNull('number')
->take(1)
// We don't add $number as a binding because for some
// reason doing so makes the bindings go out of order.
->orderByRaw('ABS(CAST(number AS SIGNED) - '.(int) $number.')');
});
return $query->count();
} | php | public function getIndexForNumber($discussionId, $number, User $actor = null)
{
$query = Discussion::find($discussionId)
->posts()
->whereVisibleTo($actor)
->where('created_at', '<', function ($query) use ($discussionId, $number) {
$query->select('created_at')
->from('posts')
->where('discussion_id', $discussionId)
->whereNotNull('number')
->take(1)
// We don't add $number as a binding because for some
// reason doing so makes the bindings go out of order.
->orderByRaw('ABS(CAST(number AS SIGNED) - '.(int) $number.')');
});
return $query->count();
} | [
"public",
"function",
"getIndexForNumber",
"(",
"$",
"discussionId",
",",
"$",
"number",
",",
"User",
"$",
"actor",
"=",
"null",
")",
"{",
"$",
"query",
"=",
"Discussion",
"::",
"find",
"(",
"$",
"discussionId",
")",
"->",
"posts",
"(",
")",
"->",
"whereVisibleTo",
"(",
"$",
"actor",
")",
"->",
"where",
"(",
"'created_at'",
",",
"'<'",
",",
"function",
"(",
"$",
"query",
")",
"use",
"(",
"$",
"discussionId",
",",
"$",
"number",
")",
"{",
"$",
"query",
"->",
"select",
"(",
"'created_at'",
")",
"->",
"from",
"(",
"'posts'",
")",
"->",
"where",
"(",
"'discussion_id'",
",",
"$",
"discussionId",
")",
"->",
"whereNotNull",
"(",
"'number'",
")",
"->",
"take",
"(",
"1",
")",
"// We don't add $number as a binding because for some",
"// reason doing so makes the bindings go out of order.",
"->",
"orderByRaw",
"(",
"'ABS(CAST(number AS SIGNED) - '",
".",
"(",
"int",
")",
"$",
"number",
".",
"')'",
")",
";",
"}",
")",
";",
"return",
"$",
"query",
"->",
"count",
"(",
")",
";",
"}"
] | Get the position within a discussion where a post with a certain number
is. If the post with that number does not exist, the index of the
closest post to it will be returned.
@param int $discussionId
@param int $number
@param \Flarum\User\User|null $actor
@return int | [
"Get",
"the",
"position",
"within",
"a",
"discussion",
"where",
"a",
"post",
"with",
"a",
"certain",
"number",
"is",
".",
"If",
"the",
"post",
"with",
"that",
"number",
"does",
"not",
"exist",
"the",
"index",
"of",
"the",
"closest",
"post",
"to",
"it",
"will",
"be",
"returned",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Post/PostRepository.php#L134-L152 | train |
flarum/core | src/User/SelfDemotionGuard.php | SelfDemotionGuard.handle | public function handle(Saving $event)
{
// Non-admin users pose no problem
if (! $event->actor->isAdmin()) {
return;
}
// Only admins can demote users, which means demoting other users is
// fine, because we still have at least one admin (the actor) left
if ($event->actor->id !== $event->user->id) {
return;
}
$groups = array_get($event->data, 'relationships.groups.data');
// If there is no group data (not even an empty array), this means
// groups were not changed (and thus not removed) - we're fine!
if (! isset($groups)) {
return;
}
$adminGroups = array_filter($groups, function ($group) {
return $group['id'] == Group::ADMINISTRATOR_ID;
});
// As long as the user is still part of the admin group, all is good
if ($adminGroups) {
return;
}
// If we get to this point, we have to prohibit the edit
throw new PermissionDeniedException;
} | php | public function handle(Saving $event)
{
// Non-admin users pose no problem
if (! $event->actor->isAdmin()) {
return;
}
// Only admins can demote users, which means demoting other users is
// fine, because we still have at least one admin (the actor) left
if ($event->actor->id !== $event->user->id) {
return;
}
$groups = array_get($event->data, 'relationships.groups.data');
// If there is no group data (not even an empty array), this means
// groups were not changed (and thus not removed) - we're fine!
if (! isset($groups)) {
return;
}
$adminGroups = array_filter($groups, function ($group) {
return $group['id'] == Group::ADMINISTRATOR_ID;
});
// As long as the user is still part of the admin group, all is good
if ($adminGroups) {
return;
}
// If we get to this point, we have to prohibit the edit
throw new PermissionDeniedException;
} | [
"public",
"function",
"handle",
"(",
"Saving",
"$",
"event",
")",
"{",
"// Non-admin users pose no problem",
"if",
"(",
"!",
"$",
"event",
"->",
"actor",
"->",
"isAdmin",
"(",
")",
")",
"{",
"return",
";",
"}",
"// Only admins can demote users, which means demoting other users is",
"// fine, because we still have at least one admin (the actor) left",
"if",
"(",
"$",
"event",
"->",
"actor",
"->",
"id",
"!==",
"$",
"event",
"->",
"user",
"->",
"id",
")",
"{",
"return",
";",
"}",
"$",
"groups",
"=",
"array_get",
"(",
"$",
"event",
"->",
"data",
",",
"'relationships.groups.data'",
")",
";",
"// If there is no group data (not even an empty array), this means",
"// groups were not changed (and thus not removed) - we're fine!",
"if",
"(",
"!",
"isset",
"(",
"$",
"groups",
")",
")",
"{",
"return",
";",
"}",
"$",
"adminGroups",
"=",
"array_filter",
"(",
"$",
"groups",
",",
"function",
"(",
"$",
"group",
")",
"{",
"return",
"$",
"group",
"[",
"'id'",
"]",
"==",
"Group",
"::",
"ADMINISTRATOR_ID",
";",
"}",
")",
";",
"// As long as the user is still part of the admin group, all is good",
"if",
"(",
"$",
"adminGroups",
")",
"{",
"return",
";",
"}",
"// If we get to this point, we have to prohibit the edit",
"throw",
"new",
"PermissionDeniedException",
";",
"}"
] | Prevent an admin from removing their admin permission via the API.
@param Saving $event
@throws PermissionDeniedException | [
"Prevent",
"an",
"admin",
"from",
"removing",
"their",
"admin",
"permission",
"via",
"the",
"API",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/User/SelfDemotionGuard.php#L25-L57 | train |
flarum/core | src/Search/GambitManager.php | GambitManager.apply | public function apply(AbstractSearch $search, $query)
{
$query = $this->applyGambits($search, $query);
if ($query) {
$this->applyFulltext($search, $query);
}
} | php | public function apply(AbstractSearch $search, $query)
{
$query = $this->applyGambits($search, $query);
if ($query) {
$this->applyFulltext($search, $query);
}
} | [
"public",
"function",
"apply",
"(",
"AbstractSearch",
"$",
"search",
",",
"$",
"query",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"applyGambits",
"(",
"$",
"search",
",",
"$",
"query",
")",
";",
"if",
"(",
"$",
"query",
")",
"{",
"$",
"this",
"->",
"applyFulltext",
"(",
"$",
"search",
",",
"$",
"query",
")",
";",
"}",
"}"
] | Apply gambits to a search, given a search query.
@param AbstractSearch $search
@param string $query | [
"Apply",
"gambits",
"to",
"a",
"search",
"given",
"a",
"search",
"query",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Search/GambitManager.php#L61-L68 | train |
flarum/core | src/User/Guest.php | Guest.getGroupsAttribute | public function getGroupsAttribute()
{
if (! isset($this->attributes['groups'])) {
$this->attributes['groups'] = $this->relations['groups'] = Group::where('id', Group::GUEST_ID)->get();
}
return $this->attributes['groups'];
} | php | public function getGroupsAttribute()
{
if (! isset($this->attributes['groups'])) {
$this->attributes['groups'] = $this->relations['groups'] = Group::where('id', Group::GUEST_ID)->get();
}
return $this->attributes['groups'];
} | [
"public",
"function",
"getGroupsAttribute",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"attributes",
"[",
"'groups'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"attributes",
"[",
"'groups'",
"]",
"=",
"$",
"this",
"->",
"relations",
"[",
"'groups'",
"]",
"=",
"Group",
"::",
"where",
"(",
"'id'",
",",
"Group",
"::",
"GUEST_ID",
")",
"->",
"get",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"attributes",
"[",
"'groups'",
"]",
";",
"}"
] | Get the guest's group, containing only the 'guests' group model.
@return \Flarum\Group\Group | [
"Get",
"the",
"guest",
"s",
"group",
"containing",
"only",
"the",
"guests",
"group",
"model",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/User/Guest.php#L30-L37 | train |
flarum/core | src/Foundation/Console/InfoCommand.php | InfoCommand.findPackageVersion | private function findPackageVersion($path, $fallback = null)
{
if (file_exists("$path/.git")) {
$cwd = getcwd();
chdir($path);
$output = [];
$status = null;
exec('git rev-parse HEAD 2>&1', $output, $status);
chdir($cwd);
if ($status == 0) {
return isset($fallback) ? "$fallback ($output[0])" : $output[0];
}
}
return $fallback;
} | php | private function findPackageVersion($path, $fallback = null)
{
if (file_exists("$path/.git")) {
$cwd = getcwd();
chdir($path);
$output = [];
$status = null;
exec('git rev-parse HEAD 2>&1', $output, $status);
chdir($cwd);
if ($status == 0) {
return isset($fallback) ? "$fallback ($output[0])" : $output[0];
}
}
return $fallback;
} | [
"private",
"function",
"findPackageVersion",
"(",
"$",
"path",
",",
"$",
"fallback",
"=",
"null",
")",
"{",
"if",
"(",
"file_exists",
"(",
"\"$path/.git\"",
")",
")",
"{",
"$",
"cwd",
"=",
"getcwd",
"(",
")",
";",
"chdir",
"(",
"$",
"path",
")",
";",
"$",
"output",
"=",
"[",
"]",
";",
"$",
"status",
"=",
"null",
";",
"exec",
"(",
"'git rev-parse HEAD 2>&1'",
",",
"$",
"output",
",",
"$",
"status",
")",
";",
"chdir",
"(",
"$",
"cwd",
")",
";",
"if",
"(",
"$",
"status",
"==",
"0",
")",
"{",
"return",
"isset",
"(",
"$",
"fallback",
")",
"?",
"\"$fallback ($output[0])\"",
":",
"$",
"output",
"[",
"0",
"]",
";",
"}",
"}",
"return",
"$",
"fallback",
";",
"}"
] | Try to detect a package's exact version.
If the package seems to be a Git version, we extract the currently
checked out commit using the command line.
@param string $path
@param string $fallback
@return string | [
"Try",
"to",
"detect",
"a",
"package",
"s",
"exact",
"version",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Foundation/Console/InfoCommand.php#L111-L129 | train |
flarum/core | src/Discussion/UserState.php | UserState.read | public function read($number)
{
if ($number > $this->last_read_post_number) {
$this->last_read_post_number = $number;
$this->last_read_at = Carbon::now();
$this->raise(new UserRead($this));
}
return $this;
} | php | public function read($number)
{
if ($number > $this->last_read_post_number) {
$this->last_read_post_number = $number;
$this->last_read_at = Carbon::now();
$this->raise(new UserRead($this));
}
return $this;
} | [
"public",
"function",
"read",
"(",
"$",
"number",
")",
"{",
"if",
"(",
"$",
"number",
">",
"$",
"this",
"->",
"last_read_post_number",
")",
"{",
"$",
"this",
"->",
"last_read_post_number",
"=",
"$",
"number",
";",
"$",
"this",
"->",
"last_read_at",
"=",
"Carbon",
"::",
"now",
"(",
")",
";",
"$",
"this",
"->",
"raise",
"(",
"new",
"UserRead",
"(",
"$",
"this",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Mark the discussion as being read up to a certain point. Raises the
DiscussionWasRead event.
@param int $number
@return $this | [
"Mark",
"the",
"discussion",
"as",
"being",
"read",
"up",
"to",
"a",
"certain",
"point",
".",
"Raises",
"the",
"DiscussionWasRead",
"event",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Discussion/UserState.php#L58-L68 | train |
flarum/core | src/Discussion/DiscussionRepository.php | DiscussionRepository.findOrFail | public function findOrFail($id, User $user = null)
{
$query = Discussion::where('id', $id);
return $this->scopeVisibleTo($query, $user)->firstOrFail();
} | php | public function findOrFail($id, User $user = null)
{
$query = Discussion::where('id', $id);
return $this->scopeVisibleTo($query, $user)->firstOrFail();
} | [
"public",
"function",
"findOrFail",
"(",
"$",
"id",
",",
"User",
"$",
"user",
"=",
"null",
")",
"{",
"$",
"query",
"=",
"Discussion",
"::",
"where",
"(",
"'id'",
",",
"$",
"id",
")",
";",
"return",
"$",
"this",
"->",
"scopeVisibleTo",
"(",
"$",
"query",
",",
"$",
"user",
")",
"->",
"firstOrFail",
"(",
")",
";",
"}"
] | Find a discussion by ID, optionally making sure it is visible to a
certain user, or throw an exception.
@param int $id
@param User $user
@return \Flarum\Discussion\Discussion | [
"Find",
"a",
"discussion",
"by",
"ID",
"optionally",
"making",
"sure",
"it",
"is",
"visible",
"to",
"a",
"certain",
"user",
"or",
"throw",
"an",
"exception",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Discussion/DiscussionRepository.php#L37-L42 | train |
flarum/core | src/Discussion/DiscussionRepository.php | DiscussionRepository.getReadIds | public function getReadIds(User $user)
{
return Discussion::leftJoin('discussion_user', 'discussion_user.discussion_id', '=', 'discussions.id')
->where('discussion_user.user_id', $user->id)
->whereColumn('last_read_post_number', '>=', 'last_post_number')
->pluck('id')
->all();
} | php | public function getReadIds(User $user)
{
return Discussion::leftJoin('discussion_user', 'discussion_user.discussion_id', '=', 'discussions.id')
->where('discussion_user.user_id', $user->id)
->whereColumn('last_read_post_number', '>=', 'last_post_number')
->pluck('id')
->all();
} | [
"public",
"function",
"getReadIds",
"(",
"User",
"$",
"user",
")",
"{",
"return",
"Discussion",
"::",
"leftJoin",
"(",
"'discussion_user'",
",",
"'discussion_user.discussion_id'",
",",
"'='",
",",
"'discussions.id'",
")",
"->",
"where",
"(",
"'discussion_user.user_id'",
",",
"$",
"user",
"->",
"id",
")",
"->",
"whereColumn",
"(",
"'last_read_post_number'",
",",
"'>='",
",",
"'last_post_number'",
")",
"->",
"pluck",
"(",
"'id'",
")",
"->",
"all",
"(",
")",
";",
"}"
] | Get the IDs of discussions which a user has read completely.
@param User $user
@return array | [
"Get",
"the",
"IDs",
"of",
"discussions",
"which",
"a",
"user",
"has",
"read",
"completely",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Discussion/DiscussionRepository.php#L50-L57 | train |
flarum/core | src/Http/UrlGenerator.php | UrlGenerator.addCollection | public function addCollection($key, RouteCollection $routes, $prefix = null)
{
$this->routes[$key] = new RouteCollectionUrlGenerator(
$this->app->url($prefix),
$routes
);
return $this;
} | php | public function addCollection($key, RouteCollection $routes, $prefix = null)
{
$this->routes[$key] = new RouteCollectionUrlGenerator(
$this->app->url($prefix),
$routes
);
return $this;
} | [
"public",
"function",
"addCollection",
"(",
"$",
"key",
",",
"RouteCollection",
"$",
"routes",
",",
"$",
"prefix",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"routes",
"[",
"$",
"key",
"]",
"=",
"new",
"RouteCollectionUrlGenerator",
"(",
"$",
"this",
"->",
"app",
"->",
"url",
"(",
"$",
"prefix",
")",
",",
"$",
"routes",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Register a named route collection for URL generation.
@param string $key
@param RouteCollection $routes
@param string $prefix
@return static | [
"Register",
"a",
"named",
"route",
"collection",
"for",
"URL",
"generation",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Http/UrlGenerator.php#L39-L47 | train |
flarum/core | src/Foundation/DispatchEventsTrait.php | DispatchEventsTrait.dispatchEventsFor | public function dispatchEventsFor($entity, User $actor = null)
{
foreach ($entity->releaseEvents() as $event) {
$event->actor = $actor;
$this->events->dispatch($event);
}
} | php | public function dispatchEventsFor($entity, User $actor = null)
{
foreach ($entity->releaseEvents() as $event) {
$event->actor = $actor;
$this->events->dispatch($event);
}
} | [
"public",
"function",
"dispatchEventsFor",
"(",
"$",
"entity",
",",
"User",
"$",
"actor",
"=",
"null",
")",
"{",
"foreach",
"(",
"$",
"entity",
"->",
"releaseEvents",
"(",
")",
"as",
"$",
"event",
")",
"{",
"$",
"event",
"->",
"actor",
"=",
"$",
"actor",
";",
"$",
"this",
"->",
"events",
"->",
"dispatch",
"(",
"$",
"event",
")",
";",
"}",
"}"
] | Dispatch all events for an entity.
@param object $entity
@param User $actor | [
"Dispatch",
"all",
"events",
"for",
"an",
"entity",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Foundation/DispatchEventsTrait.php#L30-L37 | train |
flarum/core | src/Notification/NotificationSyncer.php | NotificationSyncer.sync | public function sync(Blueprint\BlueprintInterface $blueprint, array $users)
{
$attributes = $this->getAttributes($blueprint);
// Find all existing notification records in the database matching this
// blueprint. We will begin by assuming that they all need to be
// deleted in order to match the provided list of users.
$toDelete = Notification::where($attributes)->get();
$toUndelete = [];
$newRecipients = [];
// For each of the provided users, check to see if they already have
// a notification record in the database. If they do, we will make sure
// it isn't marked as deleted. If they don't, we will want to create a
// new record for them.
foreach ($users as $user) {
if (! ($user instanceof User)) {
continue;
}
$existing = $toDelete->first(function ($notification, $i) use ($user) {
return $notification->user_id === $user->id;
});
if ($existing) {
$toUndelete[] = $existing->id;
$toDelete->forget($toDelete->search($existing));
} elseif (! static::$onePerUser || ! in_array($user->id, static::$sentTo)) {
$newRecipients[] = $user;
static::$sentTo[] = $user->id;
}
}
// Delete all of the remaining notification records which weren't
// removed from this collection by the above loop. Un-delete the
// existing records that we want to keep.
if (count($toDelete)) {
$this->setDeleted($toDelete->pluck('id')->all(), true);
}
if (count($toUndelete)) {
$this->setDeleted($toUndelete, false);
}
// Create a notification record, and send an email, for all users
// receiving this notification for the first time (we know because they
// didn't have a record in the database).
if (count($newRecipients)) {
$this->sendNotifications($blueprint, $newRecipients);
}
} | php | public function sync(Blueprint\BlueprintInterface $blueprint, array $users)
{
$attributes = $this->getAttributes($blueprint);
// Find all existing notification records in the database matching this
// blueprint. We will begin by assuming that they all need to be
// deleted in order to match the provided list of users.
$toDelete = Notification::where($attributes)->get();
$toUndelete = [];
$newRecipients = [];
// For each of the provided users, check to see if they already have
// a notification record in the database. If they do, we will make sure
// it isn't marked as deleted. If they don't, we will want to create a
// new record for them.
foreach ($users as $user) {
if (! ($user instanceof User)) {
continue;
}
$existing = $toDelete->first(function ($notification, $i) use ($user) {
return $notification->user_id === $user->id;
});
if ($existing) {
$toUndelete[] = $existing->id;
$toDelete->forget($toDelete->search($existing));
} elseif (! static::$onePerUser || ! in_array($user->id, static::$sentTo)) {
$newRecipients[] = $user;
static::$sentTo[] = $user->id;
}
}
// Delete all of the remaining notification records which weren't
// removed from this collection by the above loop. Un-delete the
// existing records that we want to keep.
if (count($toDelete)) {
$this->setDeleted($toDelete->pluck('id')->all(), true);
}
if (count($toUndelete)) {
$this->setDeleted($toUndelete, false);
}
// Create a notification record, and send an email, for all users
// receiving this notification for the first time (we know because they
// didn't have a record in the database).
if (count($newRecipients)) {
$this->sendNotifications($blueprint, $newRecipients);
}
} | [
"public",
"function",
"sync",
"(",
"Blueprint",
"\\",
"BlueprintInterface",
"$",
"blueprint",
",",
"array",
"$",
"users",
")",
"{",
"$",
"attributes",
"=",
"$",
"this",
"->",
"getAttributes",
"(",
"$",
"blueprint",
")",
";",
"// Find all existing notification records in the database matching this",
"// blueprint. We will begin by assuming that they all need to be",
"// deleted in order to match the provided list of users.",
"$",
"toDelete",
"=",
"Notification",
"::",
"where",
"(",
"$",
"attributes",
")",
"->",
"get",
"(",
")",
";",
"$",
"toUndelete",
"=",
"[",
"]",
";",
"$",
"newRecipients",
"=",
"[",
"]",
";",
"// For each of the provided users, check to see if they already have",
"// a notification record in the database. If they do, we will make sure",
"// it isn't marked as deleted. If they don't, we will want to create a",
"// new record for them.",
"foreach",
"(",
"$",
"users",
"as",
"$",
"user",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"user",
"instanceof",
"User",
")",
")",
"{",
"continue",
";",
"}",
"$",
"existing",
"=",
"$",
"toDelete",
"->",
"first",
"(",
"function",
"(",
"$",
"notification",
",",
"$",
"i",
")",
"use",
"(",
"$",
"user",
")",
"{",
"return",
"$",
"notification",
"->",
"user_id",
"===",
"$",
"user",
"->",
"id",
";",
"}",
")",
";",
"if",
"(",
"$",
"existing",
")",
"{",
"$",
"toUndelete",
"[",
"]",
"=",
"$",
"existing",
"->",
"id",
";",
"$",
"toDelete",
"->",
"forget",
"(",
"$",
"toDelete",
"->",
"search",
"(",
"$",
"existing",
")",
")",
";",
"}",
"elseif",
"(",
"!",
"static",
"::",
"$",
"onePerUser",
"||",
"!",
"in_array",
"(",
"$",
"user",
"->",
"id",
",",
"static",
"::",
"$",
"sentTo",
")",
")",
"{",
"$",
"newRecipients",
"[",
"]",
"=",
"$",
"user",
";",
"static",
"::",
"$",
"sentTo",
"[",
"]",
"=",
"$",
"user",
"->",
"id",
";",
"}",
"}",
"// Delete all of the remaining notification records which weren't",
"// removed from this collection by the above loop. Un-delete the",
"// existing records that we want to keep.",
"if",
"(",
"count",
"(",
"$",
"toDelete",
")",
")",
"{",
"$",
"this",
"->",
"setDeleted",
"(",
"$",
"toDelete",
"->",
"pluck",
"(",
"'id'",
")",
"->",
"all",
"(",
")",
",",
"true",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"toUndelete",
")",
")",
"{",
"$",
"this",
"->",
"setDeleted",
"(",
"$",
"toUndelete",
",",
"false",
")",
";",
"}",
"// Create a notification record, and send an email, for all users",
"// receiving this notification for the first time (we know because they",
"// didn't have a record in the database).",
"if",
"(",
"count",
"(",
"$",
"newRecipients",
")",
")",
"{",
"$",
"this",
"->",
"sendNotifications",
"(",
"$",
"blueprint",
",",
"$",
"newRecipients",
")",
";",
"}",
"}"
] | Sync a notification so that it is visible to the specified users, and not
visible to anyone else. If it is being made visible for the first time,
attempt to send the user an email.
@param \Flarum\Notification\Blueprint\BlueprintInterface $blueprint
@param User[] $users
@return void | [
"Sync",
"a",
"notification",
"so",
"that",
"it",
"is",
"visible",
"to",
"the",
"specified",
"users",
"and",
"not",
"visible",
"to",
"anyone",
"else",
".",
"If",
"it",
"is",
"being",
"made",
"visible",
"for",
"the",
"first",
"time",
"attempt",
"to",
"send",
"the",
"user",
"an",
"email",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Notification/NotificationSyncer.php#L72-L122 | train |
flarum/core | src/Notification/NotificationSyncer.php | NotificationSyncer.delete | public function delete(BlueprintInterface $blueprint)
{
Notification::where($this->getAttributes($blueprint))->update(['is_deleted' => true]);
} | php | public function delete(BlueprintInterface $blueprint)
{
Notification::where($this->getAttributes($blueprint))->update(['is_deleted' => true]);
} | [
"public",
"function",
"delete",
"(",
"BlueprintInterface",
"$",
"blueprint",
")",
"{",
"Notification",
"::",
"where",
"(",
"$",
"this",
"->",
"getAttributes",
"(",
"$",
"blueprint",
")",
")",
"->",
"update",
"(",
"[",
"'is_deleted'",
"=>",
"true",
"]",
")",
";",
"}"
] | Delete a notification for all users.
@param \Flarum\Notification\Blueprint\BlueprintInterface $blueprint
@return void | [
"Delete",
"a",
"notification",
"for",
"all",
"users",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Notification/NotificationSyncer.php#L130-L133 | train |
flarum/core | src/Notification/NotificationSyncer.php | NotificationSyncer.restore | public function restore(BlueprintInterface $blueprint)
{
Notification::where($this->getAttributes($blueprint))->update(['is_deleted' => false]);
} | php | public function restore(BlueprintInterface $blueprint)
{
Notification::where($this->getAttributes($blueprint))->update(['is_deleted' => false]);
} | [
"public",
"function",
"restore",
"(",
"BlueprintInterface",
"$",
"blueprint",
")",
"{",
"Notification",
"::",
"where",
"(",
"$",
"this",
"->",
"getAttributes",
"(",
"$",
"blueprint",
")",
")",
"->",
"update",
"(",
"[",
"'is_deleted'",
"=>",
"false",
"]",
")",
";",
"}"
] | Restore a notification for all users.
@param BlueprintInterface $blueprint
@return void | [
"Restore",
"a",
"notification",
"for",
"all",
"users",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Notification/NotificationSyncer.php#L141-L144 | train |
flarum/core | src/Notification/NotificationSyncer.php | NotificationSyncer.mailNotifications | protected function mailNotifications(MailableInterface $blueprint, array $recipients)
{
foreach ($recipients as $user) {
if ($user->shouldEmail($blueprint::getType())) {
$this->mailer->send($blueprint, $user);
}
}
} | php | protected function mailNotifications(MailableInterface $blueprint, array $recipients)
{
foreach ($recipients as $user) {
if ($user->shouldEmail($blueprint::getType())) {
$this->mailer->send($blueprint, $user);
}
}
} | [
"protected",
"function",
"mailNotifications",
"(",
"MailableInterface",
"$",
"blueprint",
",",
"array",
"$",
"recipients",
")",
"{",
"foreach",
"(",
"$",
"recipients",
"as",
"$",
"user",
")",
"{",
"if",
"(",
"$",
"user",
"->",
"shouldEmail",
"(",
"$",
"blueprint",
"::",
"getType",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"mailer",
"->",
"send",
"(",
"$",
"blueprint",
",",
"$",
"user",
")",
";",
"}",
"}",
"}"
] | Mail a notification to a list of users.
@param MailableInterface $blueprint
@param User[] $recipients | [
"Mail",
"a",
"notification",
"to",
"a",
"list",
"of",
"users",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Notification/NotificationSyncer.php#L198-L205 | train |
flarum/core | src/Notification/NotificationSyncer.php | NotificationSyncer.getAttributes | protected function getAttributes(Blueprint\BlueprintInterface $blueprint)
{
return [
'type' => $blueprint::getType(),
'from_user_id' => ($fromUser = $blueprint->getFromUser()) ? $fromUser->id : null,
'subject_id' => ($subject = $blueprint->getSubject()) ? $subject->id : null,
'data' => ($data = $blueprint->getData()) ? json_encode($data) : null
];
} | php | protected function getAttributes(Blueprint\BlueprintInterface $blueprint)
{
return [
'type' => $blueprint::getType(),
'from_user_id' => ($fromUser = $blueprint->getFromUser()) ? $fromUser->id : null,
'subject_id' => ($subject = $blueprint->getSubject()) ? $subject->id : null,
'data' => ($data = $blueprint->getData()) ? json_encode($data) : null
];
} | [
"protected",
"function",
"getAttributes",
"(",
"Blueprint",
"\\",
"BlueprintInterface",
"$",
"blueprint",
")",
"{",
"return",
"[",
"'type'",
"=>",
"$",
"blueprint",
"::",
"getType",
"(",
")",
",",
"'from_user_id'",
"=>",
"(",
"$",
"fromUser",
"=",
"$",
"blueprint",
"->",
"getFromUser",
"(",
")",
")",
"?",
"$",
"fromUser",
"->",
"id",
":",
"null",
",",
"'subject_id'",
"=>",
"(",
"$",
"subject",
"=",
"$",
"blueprint",
"->",
"getSubject",
"(",
")",
")",
"?",
"$",
"subject",
"->",
"id",
":",
"null",
",",
"'data'",
"=>",
"(",
"$",
"data",
"=",
"$",
"blueprint",
"->",
"getData",
"(",
")",
")",
"?",
"json_encode",
"(",
"$",
"data",
")",
":",
"null",
"]",
";",
"}"
] | Construct an array of attributes to be stored in a notification record in
the database, given a notification blueprint.
@param \Flarum\Notification\Blueprint\BlueprintInterface $blueprint
@return array | [
"Construct",
"an",
"array",
"of",
"attributes",
"to",
"be",
"stored",
"in",
"a",
"notification",
"record",
"in",
"the",
"database",
"given",
"a",
"notification",
"blueprint",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Notification/NotificationSyncer.php#L225-L233 | train |
flarum/core | src/Extension/ExtensionManager.php | ExtensionManager.enable | public function enable($name)
{
if ($this->isEnabled($name)) {
return;
}
$extension = $this->getExtension($name);
$this->dispatcher->dispatch(new Enabling($extension));
$enabled = $this->getEnabled();
$enabled[] = $name;
$this->migrate($extension);
$this->publishAssets($extension);
$this->setEnabled($enabled);
$extension->enable($this->app);
$this->dispatcher->dispatch(new Enabled($extension));
} | php | public function enable($name)
{
if ($this->isEnabled($name)) {
return;
}
$extension = $this->getExtension($name);
$this->dispatcher->dispatch(new Enabling($extension));
$enabled = $this->getEnabled();
$enabled[] = $name;
$this->migrate($extension);
$this->publishAssets($extension);
$this->setEnabled($enabled);
$extension->enable($this->app);
$this->dispatcher->dispatch(new Enabled($extension));
} | [
"public",
"function",
"enable",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isEnabled",
"(",
"$",
"name",
")",
")",
"{",
"return",
";",
"}",
"$",
"extension",
"=",
"$",
"this",
"->",
"getExtension",
"(",
"$",
"name",
")",
";",
"$",
"this",
"->",
"dispatcher",
"->",
"dispatch",
"(",
"new",
"Enabling",
"(",
"$",
"extension",
")",
")",
";",
"$",
"enabled",
"=",
"$",
"this",
"->",
"getEnabled",
"(",
")",
";",
"$",
"enabled",
"[",
"]",
"=",
"$",
"name",
";",
"$",
"this",
"->",
"migrate",
"(",
"$",
"extension",
")",
";",
"$",
"this",
"->",
"publishAssets",
"(",
"$",
"extension",
")",
";",
"$",
"this",
"->",
"setEnabled",
"(",
"$",
"enabled",
")",
";",
"$",
"extension",
"->",
"enable",
"(",
"$",
"this",
"->",
"app",
")",
";",
"$",
"this",
"->",
"dispatcher",
"->",
"dispatch",
"(",
"new",
"Enabled",
"(",
"$",
"extension",
")",
")",
";",
"}"
] | Enables the extension.
@param string $name | [
"Enables",
"the",
"extension",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Extension/ExtensionManager.php#L113-L136 | train |
flarum/core | src/Extension/ExtensionManager.php | ExtensionManager.disable | public function disable($name)
{
$enabled = $this->getEnabled();
if (($k = array_search($name, $enabled)) === false) {
return;
}
$extension = $this->getExtension($name);
$this->dispatcher->dispatch(new Disabling($extension));
unset($enabled[$k]);
$this->setEnabled($enabled);
$extension->disable($this->app);
$this->dispatcher->dispatch(new Disabled($extension));
} | php | public function disable($name)
{
$enabled = $this->getEnabled();
if (($k = array_search($name, $enabled)) === false) {
return;
}
$extension = $this->getExtension($name);
$this->dispatcher->dispatch(new Disabling($extension));
unset($enabled[$k]);
$this->setEnabled($enabled);
$extension->disable($this->app);
$this->dispatcher->dispatch(new Disabled($extension));
} | [
"public",
"function",
"disable",
"(",
"$",
"name",
")",
"{",
"$",
"enabled",
"=",
"$",
"this",
"->",
"getEnabled",
"(",
")",
";",
"if",
"(",
"(",
"$",
"k",
"=",
"array_search",
"(",
"$",
"name",
",",
"$",
"enabled",
")",
")",
"===",
"false",
")",
"{",
"return",
";",
"}",
"$",
"extension",
"=",
"$",
"this",
"->",
"getExtension",
"(",
"$",
"name",
")",
";",
"$",
"this",
"->",
"dispatcher",
"->",
"dispatch",
"(",
"new",
"Disabling",
"(",
"$",
"extension",
")",
")",
";",
"unset",
"(",
"$",
"enabled",
"[",
"$",
"k",
"]",
")",
";",
"$",
"this",
"->",
"setEnabled",
"(",
"$",
"enabled",
")",
";",
"$",
"extension",
"->",
"disable",
"(",
"$",
"this",
"->",
"app",
")",
";",
"$",
"this",
"->",
"dispatcher",
"->",
"dispatch",
"(",
"new",
"Disabled",
"(",
"$",
"extension",
")",
")",
";",
"}"
] | Disables an extension.
@param string $name | [
"Disables",
"an",
"extension",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Extension/ExtensionManager.php#L143-L162 | train |
flarum/core | src/Extension/ExtensionManager.php | ExtensionManager.uninstall | public function uninstall($name)
{
$extension = $this->getExtension($name);
$this->disable($name);
$this->migrateDown($extension);
$this->unpublishAssets($extension);
$extension->setInstalled(false);
$this->dispatcher->dispatch(new Uninstalled($extension));
} | php | public function uninstall($name)
{
$extension = $this->getExtension($name);
$this->disable($name);
$this->migrateDown($extension);
$this->unpublishAssets($extension);
$extension->setInstalled(false);
$this->dispatcher->dispatch(new Uninstalled($extension));
} | [
"public",
"function",
"uninstall",
"(",
"$",
"name",
")",
"{",
"$",
"extension",
"=",
"$",
"this",
"->",
"getExtension",
"(",
"$",
"name",
")",
";",
"$",
"this",
"->",
"disable",
"(",
"$",
"name",
")",
";",
"$",
"this",
"->",
"migrateDown",
"(",
"$",
"extension",
")",
";",
"$",
"this",
"->",
"unpublishAssets",
"(",
"$",
"extension",
")",
";",
"$",
"extension",
"->",
"setInstalled",
"(",
"false",
")",
";",
"$",
"this",
"->",
"dispatcher",
"->",
"dispatch",
"(",
"new",
"Uninstalled",
"(",
"$",
"extension",
")",
")",
";",
"}"
] | Uninstalls an extension.
@param string $name | [
"Uninstalls",
"an",
"extension",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Extension/ExtensionManager.php#L169-L182 | train |
flarum/core | src/Extension/ExtensionManager.php | ExtensionManager.publishAssets | protected function publishAssets(Extension $extension)
{
if ($extension->hasAssets()) {
$this->filesystem->copyDirectory(
$extension->getPath().'/assets',
$this->app->publicPath().'/assets/extensions/'.$extension->getId()
);
}
} | php | protected function publishAssets(Extension $extension)
{
if ($extension->hasAssets()) {
$this->filesystem->copyDirectory(
$extension->getPath().'/assets',
$this->app->publicPath().'/assets/extensions/'.$extension->getId()
);
}
} | [
"protected",
"function",
"publishAssets",
"(",
"Extension",
"$",
"extension",
")",
"{",
"if",
"(",
"$",
"extension",
"->",
"hasAssets",
"(",
")",
")",
"{",
"$",
"this",
"->",
"filesystem",
"->",
"copyDirectory",
"(",
"$",
"extension",
"->",
"getPath",
"(",
")",
".",
"'/assets'",
",",
"$",
"this",
"->",
"app",
"->",
"publicPath",
"(",
")",
".",
"'/assets/extensions/'",
".",
"$",
"extension",
"->",
"getId",
"(",
")",
")",
";",
"}",
"}"
] | Copy the assets from an extension's assets directory into public view.
@param Extension $extension | [
"Copy",
"the",
"assets",
"from",
"an",
"extension",
"s",
"assets",
"directory",
"into",
"public",
"view",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Extension/ExtensionManager.php#L189-L197 | train |
flarum/core | src/Extension/ExtensionManager.php | ExtensionManager.unpublishAssets | protected function unpublishAssets(Extension $extension)
{
$this->filesystem->deleteDirectory($this->app->publicPath().'/assets/extensions/'.$extension->getId());
} | php | protected function unpublishAssets(Extension $extension)
{
$this->filesystem->deleteDirectory($this->app->publicPath().'/assets/extensions/'.$extension->getId());
} | [
"protected",
"function",
"unpublishAssets",
"(",
"Extension",
"$",
"extension",
")",
"{",
"$",
"this",
"->",
"filesystem",
"->",
"deleteDirectory",
"(",
"$",
"this",
"->",
"app",
"->",
"publicPath",
"(",
")",
".",
"'/assets/extensions/'",
".",
"$",
"extension",
"->",
"getId",
"(",
")",
")",
";",
"}"
] | Delete an extension's assets from public view.
@param Extension $extension | [
"Delete",
"an",
"extension",
"s",
"assets",
"from",
"public",
"view",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Extension/ExtensionManager.php#L204-L207 | train |
flarum/core | src/Extension/ExtensionManager.php | ExtensionManager.getAsset | public function getAsset(Extension $extension, $path)
{
return $this->app->publicPath().'/assets/extensions/'.$extension->getId().$path;
} | php | public function getAsset(Extension $extension, $path)
{
return $this->app->publicPath().'/assets/extensions/'.$extension->getId().$path;
} | [
"public",
"function",
"getAsset",
"(",
"Extension",
"$",
"extension",
",",
"$",
"path",
")",
"{",
"return",
"$",
"this",
"->",
"app",
"->",
"publicPath",
"(",
")",
".",
"'/assets/extensions/'",
".",
"$",
"extension",
"->",
"getId",
"(",
")",
".",
"$",
"path",
";",
"}"
] | Get the path to an extension's published asset.
@param Extension $extension
@param string $path
@return string | [
"Get",
"the",
"path",
"to",
"an",
"extension",
"s",
"published",
"asset",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Extension/ExtensionManager.php#L216-L219 | train |
flarum/core | src/Extension/ExtensionManager.php | ExtensionManager.migrate | public function migrate(Extension $extension, $direction = 'up')
{
$this->app->bind('Illuminate\Database\Schema\Builder', function ($container) {
return $container->make('Illuminate\Database\ConnectionInterface')->getSchemaBuilder();
});
$extension->migrate($this->migrator, $direction);
} | php | public function migrate(Extension $extension, $direction = 'up')
{
$this->app->bind('Illuminate\Database\Schema\Builder', function ($container) {
return $container->make('Illuminate\Database\ConnectionInterface')->getSchemaBuilder();
});
$extension->migrate($this->migrator, $direction);
} | [
"public",
"function",
"migrate",
"(",
"Extension",
"$",
"extension",
",",
"$",
"direction",
"=",
"'up'",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"bind",
"(",
"'Illuminate\\Database\\Schema\\Builder'",
",",
"function",
"(",
"$",
"container",
")",
"{",
"return",
"$",
"container",
"->",
"make",
"(",
"'Illuminate\\Database\\ConnectionInterface'",
")",
"->",
"getSchemaBuilder",
"(",
")",
";",
"}",
")",
";",
"$",
"extension",
"->",
"migrate",
"(",
"$",
"this",
"->",
"migrator",
",",
"$",
"direction",
")",
";",
"}"
] | Runs the database migrations for the extension.
@param Extension $extension
@param string $direction
@return void | [
"Runs",
"the",
"database",
"migrations",
"for",
"the",
"extension",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Extension/ExtensionManager.php#L228-L235 | train |
flarum/core | src/Extension/ExtensionManager.php | ExtensionManager.getEnabledExtensions | public function getEnabledExtensions()
{
$enabled = [];
$extensions = $this->getExtensions();
foreach ($this->getEnabled() as $id) {
if (isset($extensions[$id])) {
$enabled[$id] = $extensions[$id];
}
}
return $enabled;
} | php | public function getEnabledExtensions()
{
$enabled = [];
$extensions = $this->getExtensions();
foreach ($this->getEnabled() as $id) {
if (isset($extensions[$id])) {
$enabled[$id] = $extensions[$id];
}
}
return $enabled;
} | [
"public",
"function",
"getEnabledExtensions",
"(",
")",
"{",
"$",
"enabled",
"=",
"[",
"]",
";",
"$",
"extensions",
"=",
"$",
"this",
"->",
"getExtensions",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getEnabled",
"(",
")",
"as",
"$",
"id",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"extensions",
"[",
"$",
"id",
"]",
")",
")",
"{",
"$",
"enabled",
"[",
"$",
"id",
"]",
"=",
"$",
"extensions",
"[",
"$",
"id",
"]",
";",
"}",
"}",
"return",
"$",
"enabled",
";",
"}"
] | Get only enabled extensions.
@return array | [
"Get",
"only",
"enabled",
"extensions",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Extension/ExtensionManager.php#L263-L275 | train |
flarum/core | src/Extension/ExtensionManager.php | ExtensionManager.extend | public function extend(Container $app)
{
foreach ($this->getEnabledExtensions() as $extension) {
$extension->extend($app);
}
} | php | public function extend(Container $app)
{
foreach ($this->getEnabledExtensions() as $extension) {
$extension->extend($app);
}
} | [
"public",
"function",
"extend",
"(",
"Container",
"$",
"app",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getEnabledExtensions",
"(",
")",
"as",
"$",
"extension",
")",
"{",
"$",
"extension",
"->",
"extend",
"(",
"$",
"app",
")",
";",
"}",
"}"
] | Call on all enabled extensions to extend the Flarum application.
@param Container $app | [
"Call",
"on",
"all",
"enabled",
"extensions",
"to",
"extend",
"the",
"Flarum",
"application",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Extension/ExtensionManager.php#L282-L287 | train |
flarum/core | src/Extension/ExtensionManager.php | ExtensionManager.setEnabled | protected function setEnabled(array $enabled)
{
$enabled = array_values(array_unique($enabled));
$this->config->set('extensions_enabled', json_encode($enabled));
} | php | protected function setEnabled(array $enabled)
{
$enabled = array_values(array_unique($enabled));
$this->config->set('extensions_enabled', json_encode($enabled));
} | [
"protected",
"function",
"setEnabled",
"(",
"array",
"$",
"enabled",
")",
"{",
"$",
"enabled",
"=",
"array_values",
"(",
"array_unique",
"(",
"$",
"enabled",
")",
")",
";",
"$",
"this",
"->",
"config",
"->",
"set",
"(",
"'extensions_enabled'",
",",
"json_encode",
"(",
"$",
"enabled",
")",
")",
";",
"}"
] | Persist the currently enabled extensions.
@param array $enabled | [
"Persist",
"the",
"currently",
"enabled",
"extensions",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Extension/ExtensionManager.php#L304-L309 | train |
flarum/core | src/Event/ConfigureLocales.php | ConfigureLocales.loadLanguagePackFrom | public function loadLanguagePackFrom($directory)
{
$name = $title = basename($directory);
if (file_exists($manifest = $directory.'/composer.json')) {
$json = json_decode(file_get_contents($manifest), true);
if (empty($json)) {
throw new RuntimeException("Error parsing composer.json in $name: ".json_last_error_msg());
}
$locale = array_get($json, 'extra.flarum-locale.code');
$title = array_get($json, 'extra.flarum-locale.title', $title);
}
if (! isset($locale)) {
throw new RuntimeException("Language pack $name must define \"extra.flarum-locale.code\" in composer.json.");
}
$this->locales->addLocale($locale, $title);
if (! is_dir($localeDir = $directory.'/locale')) {
throw new RuntimeException("Language pack $name must have a \"locale\" subdirectory.");
}
if (file_exists($file = $localeDir.'/config.js')) {
$this->locales->addJsFile($locale, $file);
}
if (file_exists($file = $localeDir.'/config.css')) {
$this->locales->addCssFile($locale, $file);
}
foreach (new DirectoryIterator($localeDir) as $file) {
if ($file->isFile() && in_array($file->getExtension(), ['yml', 'yaml'])) {
$this->locales->addTranslations($locale, $file->getPathname());
}
}
} | php | public function loadLanguagePackFrom($directory)
{
$name = $title = basename($directory);
if (file_exists($manifest = $directory.'/composer.json')) {
$json = json_decode(file_get_contents($manifest), true);
if (empty($json)) {
throw new RuntimeException("Error parsing composer.json in $name: ".json_last_error_msg());
}
$locale = array_get($json, 'extra.flarum-locale.code');
$title = array_get($json, 'extra.flarum-locale.title', $title);
}
if (! isset($locale)) {
throw new RuntimeException("Language pack $name must define \"extra.flarum-locale.code\" in composer.json.");
}
$this->locales->addLocale($locale, $title);
if (! is_dir($localeDir = $directory.'/locale')) {
throw new RuntimeException("Language pack $name must have a \"locale\" subdirectory.");
}
if (file_exists($file = $localeDir.'/config.js')) {
$this->locales->addJsFile($locale, $file);
}
if (file_exists($file = $localeDir.'/config.css')) {
$this->locales->addCssFile($locale, $file);
}
foreach (new DirectoryIterator($localeDir) as $file) {
if ($file->isFile() && in_array($file->getExtension(), ['yml', 'yaml'])) {
$this->locales->addTranslations($locale, $file->getPathname());
}
}
} | [
"public",
"function",
"loadLanguagePackFrom",
"(",
"$",
"directory",
")",
"{",
"$",
"name",
"=",
"$",
"title",
"=",
"basename",
"(",
"$",
"directory",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"manifest",
"=",
"$",
"directory",
".",
"'/composer.json'",
")",
")",
"{",
"$",
"json",
"=",
"json_decode",
"(",
"file_get_contents",
"(",
"$",
"manifest",
")",
",",
"true",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"json",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Error parsing composer.json in $name: \"",
".",
"json_last_error_msg",
"(",
")",
")",
";",
"}",
"$",
"locale",
"=",
"array_get",
"(",
"$",
"json",
",",
"'extra.flarum-locale.code'",
")",
";",
"$",
"title",
"=",
"array_get",
"(",
"$",
"json",
",",
"'extra.flarum-locale.title'",
",",
"$",
"title",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"locale",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Language pack $name must define \\\"extra.flarum-locale.code\\\" in composer.json.\"",
")",
";",
"}",
"$",
"this",
"->",
"locales",
"->",
"addLocale",
"(",
"$",
"locale",
",",
"$",
"title",
")",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"localeDir",
"=",
"$",
"directory",
".",
"'/locale'",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Language pack $name must have a \\\"locale\\\" subdirectory.\"",
")",
";",
"}",
"if",
"(",
"file_exists",
"(",
"$",
"file",
"=",
"$",
"localeDir",
".",
"'/config.js'",
")",
")",
"{",
"$",
"this",
"->",
"locales",
"->",
"addJsFile",
"(",
"$",
"locale",
",",
"$",
"file",
")",
";",
"}",
"if",
"(",
"file_exists",
"(",
"$",
"file",
"=",
"$",
"localeDir",
".",
"'/config.css'",
")",
")",
"{",
"$",
"this",
"->",
"locales",
"->",
"addCssFile",
"(",
"$",
"locale",
",",
"$",
"file",
")",
";",
"}",
"foreach",
"(",
"new",
"DirectoryIterator",
"(",
"$",
"localeDir",
")",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"file",
"->",
"isFile",
"(",
")",
"&&",
"in_array",
"(",
"$",
"file",
"->",
"getExtension",
"(",
")",
",",
"[",
"'yml'",
",",
"'yaml'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"locales",
"->",
"addTranslations",
"(",
"$",
"locale",
",",
"$",
"file",
"->",
"getPathname",
"(",
")",
")",
";",
"}",
"}",
"}"
] | Load language pack resources from the given directory.
@param string $directory | [
"Load",
"language",
"pack",
"resources",
"from",
"the",
"given",
"directory",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Event/ConfigureLocales.php#L41-L79 | train |
flarum/core | src/Console/Event/Configuring.php | Configuring.addCommand | public function addCommand($command)
{
if (is_string($command)) {
$command = $this->app->make($command);
}
if ($command instanceof Command) {
$command->setLaravel($this->app);
}
$this->console->add($command);
} | php | public function addCommand($command)
{
if (is_string($command)) {
$command = $this->app->make($command);
}
if ($command instanceof Command) {
$command->setLaravel($this->app);
}
$this->console->add($command);
} | [
"public",
"function",
"addCommand",
"(",
"$",
"command",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"command",
")",
")",
"{",
"$",
"command",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"$",
"command",
")",
";",
"}",
"if",
"(",
"$",
"command",
"instanceof",
"Command",
")",
"{",
"$",
"command",
"->",
"setLaravel",
"(",
"$",
"this",
"->",
"app",
")",
";",
"}",
"$",
"this",
"->",
"console",
"->",
"add",
"(",
"$",
"command",
")",
";",
"}"
] | Add a console command to the flarum binary.
@param Command|string $command | [
"Add",
"a",
"console",
"command",
"to",
"the",
"flarum",
"binary",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Console/Event/Configuring.php#L50-L61 | train |
flarum/core | src/Discussion/Discussion.php | Discussion.start | public static function start($title, User $user)
{
$discussion = new static;
$discussion->title = $title;
$discussion->created_at = Carbon::now();
$discussion->user_id = $user->id;
$discussion->setRelation('user', $user);
$discussion->raise(new Started($discussion));
return $discussion;
} | php | public static function start($title, User $user)
{
$discussion = new static;
$discussion->title = $title;
$discussion->created_at = Carbon::now();
$discussion->user_id = $user->id;
$discussion->setRelation('user', $user);
$discussion->raise(new Started($discussion));
return $discussion;
} | [
"public",
"static",
"function",
"start",
"(",
"$",
"title",
",",
"User",
"$",
"user",
")",
"{",
"$",
"discussion",
"=",
"new",
"static",
";",
"$",
"discussion",
"->",
"title",
"=",
"$",
"title",
";",
"$",
"discussion",
"->",
"created_at",
"=",
"Carbon",
"::",
"now",
"(",
")",
";",
"$",
"discussion",
"->",
"user_id",
"=",
"$",
"user",
"->",
"id",
";",
"$",
"discussion",
"->",
"setRelation",
"(",
"'user'",
",",
"$",
"user",
")",
";",
"$",
"discussion",
"->",
"raise",
"(",
"new",
"Started",
"(",
"$",
"discussion",
")",
")",
";",
"return",
"$",
"discussion",
";",
"}"
] | Start a new discussion. Raises the DiscussionWasStarted event.
@param string $title
@param User $user
@return static | [
"Start",
"a",
"new",
"discussion",
".",
"Raises",
"the",
"DiscussionWasStarted",
"event",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Discussion/Discussion.php#L129-L142 | train |
flarum/core | src/Discussion/Discussion.php | Discussion.rename | public function rename($title)
{
if ($this->title !== $title) {
$oldTitle = $this->title;
$this->title = $title;
$this->raise(new Renamed($this, $oldTitle));
}
return $this;
} | php | public function rename($title)
{
if ($this->title !== $title) {
$oldTitle = $this->title;
$this->title = $title;
$this->raise(new Renamed($this, $oldTitle));
}
return $this;
} | [
"public",
"function",
"rename",
"(",
"$",
"title",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"title",
"!==",
"$",
"title",
")",
"{",
"$",
"oldTitle",
"=",
"$",
"this",
"->",
"title",
";",
"$",
"this",
"->",
"title",
"=",
"$",
"title",
";",
"$",
"this",
"->",
"raise",
"(",
"new",
"Renamed",
"(",
"$",
"this",
",",
"$",
"oldTitle",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Rename the discussion. Raises the DiscussionWasRenamed event.
@param string $title
@return $this | [
"Rename",
"the",
"discussion",
".",
"Raises",
"the",
"DiscussionWasRenamed",
"event",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Discussion/Discussion.php#L150-L160 | train |
flarum/core | src/Discussion/Discussion.php | Discussion.hide | public function hide(User $actor = null)
{
if (! $this->hidden_at) {
$this->hidden_at = Carbon::now();
$this->hidden_user_id = $actor ? $actor->id : null;
$this->raise(new Hidden($this));
}
return $this;
} | php | public function hide(User $actor = null)
{
if (! $this->hidden_at) {
$this->hidden_at = Carbon::now();
$this->hidden_user_id = $actor ? $actor->id : null;
$this->raise(new Hidden($this));
}
return $this;
} | [
"public",
"function",
"hide",
"(",
"User",
"$",
"actor",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hidden_at",
")",
"{",
"$",
"this",
"->",
"hidden_at",
"=",
"Carbon",
"::",
"now",
"(",
")",
";",
"$",
"this",
"->",
"hidden_user_id",
"=",
"$",
"actor",
"?",
"$",
"actor",
"->",
"id",
":",
"null",
";",
"$",
"this",
"->",
"raise",
"(",
"new",
"Hidden",
"(",
"$",
"this",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Hide the discussion.
@param User $actor
@return $this | [
"Hide",
"the",
"discussion",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Discussion/Discussion.php#L168-L178 | train |
flarum/core | src/Discussion/Discussion.php | Discussion.restore | public function restore()
{
if ($this->hidden_at !== null) {
$this->hidden_at = null;
$this->hidden_user_id = null;
$this->raise(new Restored($this));
}
return $this;
} | php | public function restore()
{
if ($this->hidden_at !== null) {
$this->hidden_at = null;
$this->hidden_user_id = null;
$this->raise(new Restored($this));
}
return $this;
} | [
"public",
"function",
"restore",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hidden_at",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"hidden_at",
"=",
"null",
";",
"$",
"this",
"->",
"hidden_user_id",
"=",
"null",
";",
"$",
"this",
"->",
"raise",
"(",
"new",
"Restored",
"(",
"$",
"this",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Restore the discussion.
@return $this | [
"Restore",
"the",
"discussion",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Discussion/Discussion.php#L185-L195 | train |
flarum/core | src/Discussion/Discussion.php | Discussion.setFirstPost | public function setFirstPost(Post $post)
{
$this->created_at = $post->created_at;
$this->user_id = $post->user_id;
$this->first_post_id = $post->id;
return $this;
} | php | public function setFirstPost(Post $post)
{
$this->created_at = $post->created_at;
$this->user_id = $post->user_id;
$this->first_post_id = $post->id;
return $this;
} | [
"public",
"function",
"setFirstPost",
"(",
"Post",
"$",
"post",
")",
"{",
"$",
"this",
"->",
"created_at",
"=",
"$",
"post",
"->",
"created_at",
";",
"$",
"this",
"->",
"user_id",
"=",
"$",
"post",
"->",
"user_id",
";",
"$",
"this",
"->",
"first_post_id",
"=",
"$",
"post",
"->",
"id",
";",
"return",
"$",
"this",
";",
"}"
] | Set the discussion's first post details.
@param Post $post
@return $this | [
"Set",
"the",
"discussion",
"s",
"first",
"post",
"details",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Discussion/Discussion.php#L203-L210 | train |
flarum/core | src/Discussion/Discussion.php | Discussion.setLastPost | public function setLastPost(Post $post)
{
$this->last_posted_at = $post->created_at;
$this->last_posted_user_id = $post->user_id;
$this->last_post_id = $post->id;
$this->last_post_number = $post->number;
return $this;
} | php | public function setLastPost(Post $post)
{
$this->last_posted_at = $post->created_at;
$this->last_posted_user_id = $post->user_id;
$this->last_post_id = $post->id;
$this->last_post_number = $post->number;
return $this;
} | [
"public",
"function",
"setLastPost",
"(",
"Post",
"$",
"post",
")",
"{",
"$",
"this",
"->",
"last_posted_at",
"=",
"$",
"post",
"->",
"created_at",
";",
"$",
"this",
"->",
"last_posted_user_id",
"=",
"$",
"post",
"->",
"user_id",
";",
"$",
"this",
"->",
"last_post_id",
"=",
"$",
"post",
"->",
"id",
";",
"$",
"this",
"->",
"last_post_number",
"=",
"$",
"post",
"->",
"number",
";",
"return",
"$",
"this",
";",
"}"
] | Set the discussion's last post details.
@param Post $post
@return $this | [
"Set",
"the",
"discussion",
"s",
"last",
"post",
"details",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Discussion/Discussion.php#L218-L226 | train |
flarum/core | src/Discussion/Discussion.php | Discussion.refreshLastPost | public function refreshLastPost()
{
/** @var Post $lastPost */
if ($lastPost = $this->comments()->latest()->first()) {
$this->setLastPost($lastPost);
}
return $this;
} | php | public function refreshLastPost()
{
/** @var Post $lastPost */
if ($lastPost = $this->comments()->latest()->first()) {
$this->setLastPost($lastPost);
}
return $this;
} | [
"public",
"function",
"refreshLastPost",
"(",
")",
"{",
"/** @var Post $lastPost */",
"if",
"(",
"$",
"lastPost",
"=",
"$",
"this",
"->",
"comments",
"(",
")",
"->",
"latest",
"(",
")",
"->",
"first",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setLastPost",
"(",
"$",
"lastPost",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Refresh a discussion's last post details.
@return $this | [
"Refresh",
"a",
"discussion",
"s",
"last",
"post",
"details",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Discussion/Discussion.php#L233-L241 | train |
flarum/core | src/Discussion/Discussion.php | Discussion.mergePost | public function mergePost(MergeableInterface $post)
{
$lastPost = $this->posts()->latest()->first();
$post = $post->saveAfter($lastPost);
return $this->modifiedPosts[] = $post;
} | php | public function mergePost(MergeableInterface $post)
{
$lastPost = $this->posts()->latest()->first();
$post = $post->saveAfter($lastPost);
return $this->modifiedPosts[] = $post;
} | [
"public",
"function",
"mergePost",
"(",
"MergeableInterface",
"$",
"post",
")",
"{",
"$",
"lastPost",
"=",
"$",
"this",
"->",
"posts",
"(",
")",
"->",
"latest",
"(",
")",
"->",
"first",
"(",
")",
";",
"$",
"post",
"=",
"$",
"post",
"->",
"saveAfter",
"(",
"$",
"lastPost",
")",
";",
"return",
"$",
"this",
"->",
"modifiedPosts",
"[",
"]",
"=",
"$",
"post",
";",
"}"
] | Save a post, attempting to merge it with the discussion's last post.
The merge logic is delegated to the new post. (As an example, a
DiscussionRenamedPost will merge if adjacent to another
DiscussionRenamedPost, and delete if the title has been reverted
completely.)
@param \Flarum\Post\MergeableInterface $post The post to save.
@return Post The resulting post. It may or may not be the same post as
was originally intended to be saved. It also may not exist, if the
merge logic resulted in deletion. | [
"Save",
"a",
"post",
"attempting",
"to",
"merge",
"it",
"with",
"the",
"discussion",
"s",
"last",
"post",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Discussion/Discussion.php#L280-L287 | train |
flarum/core | src/Discussion/Discussion.php | Discussion.state | public function state(User $user = null)
{
$user = $user ?: static::$stateUser;
return $this->hasOne(UserState::class)->where('user_id', $user ? $user->id : null);
} | php | public function state(User $user = null)
{
$user = $user ?: static::$stateUser;
return $this->hasOne(UserState::class)->where('user_id', $user ? $user->id : null);
} | [
"public",
"function",
"state",
"(",
"User",
"$",
"user",
"=",
"null",
")",
"{",
"$",
"user",
"=",
"$",
"user",
"?",
":",
"static",
"::",
"$",
"stateUser",
";",
"return",
"$",
"this",
"->",
"hasOne",
"(",
"UserState",
"::",
"class",
")",
"->",
"where",
"(",
"'user_id'",
",",
"$",
"user",
"?",
"$",
"user",
"->",
"id",
":",
"null",
")",
";",
"}"
] | Define the relationship with the discussion's state for a particular
user.
If no user is passed (i.e. in the case of eager loading the 'state'
relation), then the static `$stateUser` property is used.
@see Discussion::setStateUser()
@param User|null $user
@return \Illuminate\Database\Eloquent\Relations\HasOne | [
"Define",
"the",
"relationship",
"with",
"the",
"discussion",
"s",
"state",
"for",
"a",
"particular",
"user",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Discussion/Discussion.php#L410-L415 | train |
flarum/core | src/Discussion/Discussion.php | Discussion.setTitleAttribute | protected function setTitleAttribute($title)
{
$this->attributes['title'] = $title;
$this->slug = Str::slug($title);
} | php | protected function setTitleAttribute($title)
{
$this->attributes['title'] = $title;
$this->slug = Str::slug($title);
} | [
"protected",
"function",
"setTitleAttribute",
"(",
"$",
"title",
")",
"{",
"$",
"this",
"->",
"attributes",
"[",
"'title'",
"]",
"=",
"$",
"title",
";",
"$",
"this",
"->",
"slug",
"=",
"Str",
"::",
"slug",
"(",
"$",
"title",
")",
";",
"}"
] | Set the discussion title.
This automatically creates a matching slug for the discussion.
@param string $title | [
"Set",
"the",
"discussion",
"title",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Discussion/Discussion.php#L454-L458 | train |
flarum/core | src/Database/AbstractModel.php | AbstractModel.getAttribute | public function getAttribute($key)
{
if (! is_null($value = parent::getAttribute($key))) {
return $value;
}
// If a custom relation with this key has been set up, then we will load
// and return results from the query and hydrate the relationship's
// value on the "relationships" array.
if (! $this->relationLoaded($key) && ($relation = $this->getCustomRelation($key))) {
if (! $relation instanceof Relation) {
throw new LogicException(
'Relationship method must return an object of type '.Relation::class
);
}
return $this->relations[$key] = $relation->getResults();
}
} | php | public function getAttribute($key)
{
if (! is_null($value = parent::getAttribute($key))) {
return $value;
}
// If a custom relation with this key has been set up, then we will load
// and return results from the query and hydrate the relationship's
// value on the "relationships" array.
if (! $this->relationLoaded($key) && ($relation = $this->getCustomRelation($key))) {
if (! $relation instanceof Relation) {
throw new LogicException(
'Relationship method must return an object of type '.Relation::class
);
}
return $this->relations[$key] = $relation->getResults();
}
} | [
"public",
"function",
"getAttribute",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"value",
"=",
"parent",
"::",
"getAttribute",
"(",
"$",
"key",
")",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"// If a custom relation with this key has been set up, then we will load",
"// and return results from the query and hydrate the relationship's",
"// value on the \"relationships\" array.",
"if",
"(",
"!",
"$",
"this",
"->",
"relationLoaded",
"(",
"$",
"key",
")",
"&&",
"(",
"$",
"relation",
"=",
"$",
"this",
"->",
"getCustomRelation",
"(",
"$",
"key",
")",
")",
")",
"{",
"if",
"(",
"!",
"$",
"relation",
"instanceof",
"Relation",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"'Relationship method must return an object of type '",
".",
"Relation",
"::",
"class",
")",
";",
"}",
"return",
"$",
"this",
"->",
"relations",
"[",
"$",
"key",
"]",
"=",
"$",
"relation",
"->",
"getResults",
"(",
")",
";",
"}",
"}"
] | Get an attribute from the model. If nothing is found, attempt to load
a custom relation method with this key.
@param string $key
@return mixed | [
"Get",
"an",
"attribute",
"from",
"the",
"model",
".",
"If",
"nothing",
"is",
"found",
"attempt",
"to",
"load",
"a",
"custom",
"relation",
"method",
"with",
"this",
"key",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Database/AbstractModel.php#L116-L134 | train |
flarum/core | src/Database/MigrationCreator.php | MigrationCreator.create | public function create($name, $extension = null, $table = null, $create = false)
{
$migrationPath = $this->getMigrationPath($extension);
$path = $this->getPath($name, $migrationPath);
$stub = $this->getStub($table, $create);
$this->files->put($path, $this->populateStub($stub, $table));
return $path;
} | php | public function create($name, $extension = null, $table = null, $create = false)
{
$migrationPath = $this->getMigrationPath($extension);
$path = $this->getPath($name, $migrationPath);
$stub = $this->getStub($table, $create);
$this->files->put($path, $this->populateStub($stub, $table));
return $path;
} | [
"public",
"function",
"create",
"(",
"$",
"name",
",",
"$",
"extension",
"=",
"null",
",",
"$",
"table",
"=",
"null",
",",
"$",
"create",
"=",
"false",
")",
"{",
"$",
"migrationPath",
"=",
"$",
"this",
"->",
"getMigrationPath",
"(",
"$",
"extension",
")",
";",
"$",
"path",
"=",
"$",
"this",
"->",
"getPath",
"(",
"$",
"name",
",",
"$",
"migrationPath",
")",
";",
"$",
"stub",
"=",
"$",
"this",
"->",
"getStub",
"(",
"$",
"table",
",",
"$",
"create",
")",
";",
"$",
"this",
"->",
"files",
"->",
"put",
"(",
"$",
"path",
",",
"$",
"this",
"->",
"populateStub",
"(",
"$",
"stub",
",",
"$",
"table",
")",
")",
";",
"return",
"$",
"path",
";",
"}"
] | Create a new migration for the given extension.
@param string $name
@param Extension $extension
@param string $table
@param bool $create
@return string | [
"Create",
"a",
"new",
"migration",
"for",
"the",
"given",
"extension",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Database/MigrationCreator.php#L52-L63 | train |
flarum/core | src/Console/AbstractCommand.php | AbstractCommand.error | protected function error($message)
{
if ($this->output instanceof ConsoleOutputInterface) {
$this->output->getErrorOutput()->writeln("<error>$message</error>");
} else {
$this->output->writeln("<error>$message</error>");
}
} | php | protected function error($message)
{
if ($this->output instanceof ConsoleOutputInterface) {
$this->output->getErrorOutput()->writeln("<error>$message</error>");
} else {
$this->output->writeln("<error>$message</error>");
}
} | [
"protected",
"function",
"error",
"(",
"$",
"message",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"output",
"instanceof",
"ConsoleOutputInterface",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"getErrorOutput",
"(",
")",
"->",
"writeln",
"(",
"\"<error>$message</error>\"",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"\"<error>$message</error>\"",
")",
";",
"}",
"}"
] | Send an error or warning message to the user.
If possible, this will send the message via STDERR.
@param string $message | [
"Send",
"an",
"error",
"or",
"warning",
"message",
"to",
"the",
"user",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Console/AbstractCommand.php#L75-L82 | train |
flarum/core | src/Post/Post.php | Post.isVisibleTo | public function isVisibleTo(User $user)
{
return (bool) $this->newQuery()->whereVisibleTo($user)->find($this->id);
} | php | public function isVisibleTo(User $user)
{
return (bool) $this->newQuery()->whereVisibleTo($user)->find($this->id);
} | [
"public",
"function",
"isVisibleTo",
"(",
"User",
"$",
"user",
")",
"{",
"return",
"(",
"bool",
")",
"$",
"this",
"->",
"newQuery",
"(",
")",
"->",
"whereVisibleTo",
"(",
"$",
"user",
")",
"->",
"find",
"(",
"$",
"this",
"->",
"id",
")",
";",
"}"
] | Determine whether or not this post is visible to the given user.
@param User $user
@return bool | [
"Determine",
"whether",
"or",
"not",
"this",
"post",
"is",
"visible",
"to",
"the",
"given",
"user",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Post/Post.php#L122-L125 | train |
flarum/core | src/Post/Post.php | Post.newFromBuilder | public function newFromBuilder($attributes = [], $connection = null)
{
$attributes = (array) $attributes;
if (! empty($attributes['type'])
&& isset(static::$models[$attributes['type']])
&& class_exists($class = static::$models[$attributes['type']])
) {
/** @var Post $instance */
$instance = new $class;
$instance->exists = true;
$instance->setRawAttributes($attributes, true);
$instance->setConnection($connection ?: $this->connection);
return $instance;
}
return parent::newFromBuilder($attributes, $connection);
} | php | public function newFromBuilder($attributes = [], $connection = null)
{
$attributes = (array) $attributes;
if (! empty($attributes['type'])
&& isset(static::$models[$attributes['type']])
&& class_exists($class = static::$models[$attributes['type']])
) {
/** @var Post $instance */
$instance = new $class;
$instance->exists = true;
$instance->setRawAttributes($attributes, true);
$instance->setConnection($connection ?: $this->connection);
return $instance;
}
return parent::newFromBuilder($attributes, $connection);
} | [
"public",
"function",
"newFromBuilder",
"(",
"$",
"attributes",
"=",
"[",
"]",
",",
"$",
"connection",
"=",
"null",
")",
"{",
"$",
"attributes",
"=",
"(",
"array",
")",
"$",
"attributes",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"attributes",
"[",
"'type'",
"]",
")",
"&&",
"isset",
"(",
"static",
"::",
"$",
"models",
"[",
"$",
"attributes",
"[",
"'type'",
"]",
"]",
")",
"&&",
"class_exists",
"(",
"$",
"class",
"=",
"static",
"::",
"$",
"models",
"[",
"$",
"attributes",
"[",
"'type'",
"]",
"]",
")",
")",
"{",
"/** @var Post $instance */",
"$",
"instance",
"=",
"new",
"$",
"class",
";",
"$",
"instance",
"->",
"exists",
"=",
"true",
";",
"$",
"instance",
"->",
"setRawAttributes",
"(",
"$",
"attributes",
",",
"true",
")",
";",
"$",
"instance",
"->",
"setConnection",
"(",
"$",
"connection",
"?",
":",
"$",
"this",
"->",
"connection",
")",
";",
"return",
"$",
"instance",
";",
"}",
"return",
"parent",
"::",
"newFromBuilder",
"(",
"$",
"attributes",
",",
"$",
"connection",
")",
";",
"}"
] | Create a new model instance according to the post's type.
@param array $attributes
@param string|null $connection
@return static|object | [
"Create",
"a",
"new",
"model",
"instance",
"according",
"to",
"the",
"post",
"s",
"type",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Post/Post.php#L186-L204 | train |
flarum/core | src/Extension/Extension.php | Extension.assignId | protected function assignId()
{
list($vendor, $package) = explode('/', $this->name);
$package = str_replace(['flarum-ext-', 'flarum-'], '', $package);
$this->id = "$vendor-$package";
} | php | protected function assignId()
{
list($vendor, $package) = explode('/', $this->name);
$package = str_replace(['flarum-ext-', 'flarum-'], '', $package);
$this->id = "$vendor-$package";
} | [
"protected",
"function",
"assignId",
"(",
")",
"{",
"list",
"(",
"$",
"vendor",
",",
"$",
"package",
")",
"=",
"explode",
"(",
"'/'",
",",
"$",
"this",
"->",
"name",
")",
";",
"$",
"package",
"=",
"str_replace",
"(",
"[",
"'flarum-ext-'",
",",
"'flarum-'",
"]",
",",
"''",
",",
"$",
"package",
")",
";",
"$",
"this",
"->",
"id",
"=",
"\"$vendor-$package\"",
";",
"}"
] | Assigns the id for the extension used globally. | [
"Assigns",
"the",
"id",
"for",
"the",
"extension",
"used",
"globally",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Extension/Extension.php#L107-L112 | train |
flarum/core | src/Extension/Extension.php | Extension.getIcon | public function getIcon()
{
$icon = $this->composerJsonAttribute('extra.flarum-extension.icon');
$file = Arr::get($icon, 'image');
if (is_null($icon) || is_null($file)) {
return $icon;
}
$file = $this->path.'/'.$file;
if (file_exists($file)) {
$extension = pathinfo($file, PATHINFO_EXTENSION);
if (! array_key_exists($extension, self::LOGO_MIMETYPES)) {
throw new \RuntimeException('Invalid image type');
}
$mimetype = self::LOGO_MIMETYPES[$extension];
$data = base64_encode(file_get_contents($file));
$icon['backgroundImage'] = "url('data:$mimetype;base64,$data')";
}
return $icon;
} | php | public function getIcon()
{
$icon = $this->composerJsonAttribute('extra.flarum-extension.icon');
$file = Arr::get($icon, 'image');
if (is_null($icon) || is_null($file)) {
return $icon;
}
$file = $this->path.'/'.$file;
if (file_exists($file)) {
$extension = pathinfo($file, PATHINFO_EXTENSION);
if (! array_key_exists($extension, self::LOGO_MIMETYPES)) {
throw new \RuntimeException('Invalid image type');
}
$mimetype = self::LOGO_MIMETYPES[$extension];
$data = base64_encode(file_get_contents($file));
$icon['backgroundImage'] = "url('data:$mimetype;base64,$data')";
}
return $icon;
} | [
"public",
"function",
"getIcon",
"(",
")",
"{",
"$",
"icon",
"=",
"$",
"this",
"->",
"composerJsonAttribute",
"(",
"'extra.flarum-extension.icon'",
")",
";",
"$",
"file",
"=",
"Arr",
"::",
"get",
"(",
"$",
"icon",
",",
"'image'",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"icon",
")",
"||",
"is_null",
"(",
"$",
"file",
")",
")",
"{",
"return",
"$",
"icon",
";",
"}",
"$",
"file",
"=",
"$",
"this",
"->",
"path",
".",
"'/'",
".",
"$",
"file",
";",
"if",
"(",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"$",
"extension",
"=",
"pathinfo",
"(",
"$",
"file",
",",
"PATHINFO_EXTENSION",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"extension",
",",
"self",
"::",
"LOGO_MIMETYPES",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Invalid image type'",
")",
";",
"}",
"$",
"mimetype",
"=",
"self",
"::",
"LOGO_MIMETYPES",
"[",
"$",
"extension",
"]",
";",
"$",
"data",
"=",
"base64_encode",
"(",
"file_get_contents",
"(",
"$",
"file",
")",
")",
";",
"$",
"icon",
"[",
"'backgroundImage'",
"]",
"=",
"\"url('data:$mimetype;base64,$data')\"",
";",
"}",
"return",
"$",
"icon",
";",
"}"
] | Loads the icon information from the composer.json.
@return array|null | [
"Loads",
"the",
"icon",
"information",
"from",
"the",
"composer",
".",
"json",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Extension/Extension.php#L200-L224 | train |
flarum/core | src/Extension/Extension.php | Extension.toArray | public function toArray()
{
return (array) array_merge([
'id' => $this->getId(),
'version' => $this->getVersion(),
'path' => $this->path,
'icon' => $this->getIcon(),
'hasAssets' => $this->hasAssets(),
'hasMigrations' => $this->hasMigrations(),
], $this->composerJson);
} | php | public function toArray()
{
return (array) array_merge([
'id' => $this->getId(),
'version' => $this->getVersion(),
'path' => $this->path,
'icon' => $this->getIcon(),
'hasAssets' => $this->hasAssets(),
'hasMigrations' => $this->hasMigrations(),
], $this->composerJson);
} | [
"public",
"function",
"toArray",
"(",
")",
"{",
"return",
"(",
"array",
")",
"array_merge",
"(",
"[",
"'id'",
"=>",
"$",
"this",
"->",
"getId",
"(",
")",
",",
"'version'",
"=>",
"$",
"this",
"->",
"getVersion",
"(",
")",
",",
"'path'",
"=>",
"$",
"this",
"->",
"path",
",",
"'icon'",
"=>",
"$",
"this",
"->",
"getIcon",
"(",
")",
",",
"'hasAssets'",
"=>",
"$",
"this",
"->",
"hasAssets",
"(",
")",
",",
"'hasMigrations'",
"=>",
"$",
"this",
"->",
"hasMigrations",
"(",
")",
",",
"]",
",",
"$",
"this",
"->",
"composerJson",
")",
";",
"}"
] | Generates an array result for the object.
@return array | [
"Generates",
"an",
"array",
"result",
"for",
"the",
"object",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Extension/Extension.php#L363-L373 | train |
flarum/core | src/User/EmailConfirmationMailer.php | EmailConfirmationMailer.getEmailData | protected function getEmailData(User $user, $email)
{
$token = $this->generateToken($user, $email);
return [
'{username}' => $user->display_name,
'{url}' => $this->url->to('forum')->route('confirmEmail', ['token' => $token->token]),
'{forum}' => $this->settings->get('forum_title')
];
} | php | protected function getEmailData(User $user, $email)
{
$token = $this->generateToken($user, $email);
return [
'{username}' => $user->display_name,
'{url}' => $this->url->to('forum')->route('confirmEmail', ['token' => $token->token]),
'{forum}' => $this->settings->get('forum_title')
];
} | [
"protected",
"function",
"getEmailData",
"(",
"User",
"$",
"user",
",",
"$",
"email",
")",
"{",
"$",
"token",
"=",
"$",
"this",
"->",
"generateToken",
"(",
"$",
"user",
",",
"$",
"email",
")",
";",
"return",
"[",
"'{username}'",
"=>",
"$",
"user",
"->",
"display_name",
",",
"'{url}'",
"=>",
"$",
"this",
"->",
"url",
"->",
"to",
"(",
"'forum'",
")",
"->",
"route",
"(",
"'confirmEmail'",
",",
"[",
"'token'",
"=>",
"$",
"token",
"->",
"token",
"]",
")",
",",
"'{forum}'",
"=>",
"$",
"this",
"->",
"settings",
"->",
"get",
"(",
"'forum_title'",
")",
"]",
";",
"}"
] | Get the data that should be made available to email templates.
@param User $user
@param string $email
@return array | [
"Get",
"the",
"data",
"that",
"should",
"be",
"made",
"available",
"to",
"email",
"templates",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/User/EmailConfirmationMailer.php#L84-L93 | train |
flarum/core | src/Group/Permission.php | Permission.map | public static function map()
{
$permissions = [];
foreach (static::get() as $permission) {
$permissions[$permission->permission][] = (string) $permission->group_id;
}
return $permissions;
} | php | public static function map()
{
$permissions = [];
foreach (static::get() as $permission) {
$permissions[$permission->permission][] = (string) $permission->group_id;
}
return $permissions;
} | [
"public",
"static",
"function",
"map",
"(",
")",
"{",
"$",
"permissions",
"=",
"[",
"]",
";",
"foreach",
"(",
"static",
"::",
"get",
"(",
")",
"as",
"$",
"permission",
")",
"{",
"$",
"permissions",
"[",
"$",
"permission",
"->",
"permission",
"]",
"[",
"]",
"=",
"(",
"string",
")",
"$",
"permission",
"->",
"group_id",
";",
"}",
"return",
"$",
"permissions",
";",
"}"
] | Get a map of permissions to the group IDs that have them.
@return array[] | [
"Get",
"a",
"map",
"of",
"permissions",
"to",
"the",
"group",
"IDs",
"that",
"have",
"them",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Group/Permission.php#L57-L66 | train |
flarum/core | src/Forum/ForumServiceProvider.php | ForumServiceProvider.populateRoutes | protected function populateRoutes(RouteCollection $routes)
{
$factory = $this->app->make(RouteHandlerFactory::class);
$callback = include __DIR__.'/routes.php';
$callback($routes, $factory);
$this->app->make('events')->fire(
new ConfigureForumRoutes($routes, $factory)
);
$defaultRoute = $this->app->make('flarum.settings')->get('default_route');
if (isset($routes->getRouteData()[0]['GET'][$defaultRoute])) {
$toDefaultController = $routes->getRouteData()[0]['GET'][$defaultRoute];
} else {
$toDefaultController = $factory->toForum(Content\Index::class);
}
$routes->get(
'/',
'default',
$toDefaultController
);
} | php | protected function populateRoutes(RouteCollection $routes)
{
$factory = $this->app->make(RouteHandlerFactory::class);
$callback = include __DIR__.'/routes.php';
$callback($routes, $factory);
$this->app->make('events')->fire(
new ConfigureForumRoutes($routes, $factory)
);
$defaultRoute = $this->app->make('flarum.settings')->get('default_route');
if (isset($routes->getRouteData()[0]['GET'][$defaultRoute])) {
$toDefaultController = $routes->getRouteData()[0]['GET'][$defaultRoute];
} else {
$toDefaultController = $factory->toForum(Content\Index::class);
}
$routes->get(
'/',
'default',
$toDefaultController
);
} | [
"protected",
"function",
"populateRoutes",
"(",
"RouteCollection",
"$",
"routes",
")",
"{",
"$",
"factory",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"RouteHandlerFactory",
"::",
"class",
")",
";",
"$",
"callback",
"=",
"include",
"__DIR__",
".",
"'/routes.php'",
";",
"$",
"callback",
"(",
"$",
"routes",
",",
"$",
"factory",
")",
";",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'events'",
")",
"->",
"fire",
"(",
"new",
"ConfigureForumRoutes",
"(",
"$",
"routes",
",",
"$",
"factory",
")",
")",
";",
"$",
"defaultRoute",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'flarum.settings'",
")",
"->",
"get",
"(",
"'default_route'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"routes",
"->",
"getRouteData",
"(",
")",
"[",
"0",
"]",
"[",
"'GET'",
"]",
"[",
"$",
"defaultRoute",
"]",
")",
")",
"{",
"$",
"toDefaultController",
"=",
"$",
"routes",
"->",
"getRouteData",
"(",
")",
"[",
"0",
"]",
"[",
"'GET'",
"]",
"[",
"$",
"defaultRoute",
"]",
";",
"}",
"else",
"{",
"$",
"toDefaultController",
"=",
"$",
"factory",
"->",
"toForum",
"(",
"Content",
"\\",
"Index",
"::",
"class",
")",
";",
"}",
"$",
"routes",
"->",
"get",
"(",
"'/'",
",",
"'default'",
",",
"$",
"toDefaultController",
")",
";",
"}"
] | Populate the forum client routes.
@param RouteCollection $routes | [
"Populate",
"the",
"forum",
"client",
"routes",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Forum/ForumServiceProvider.php#L173-L197 | train |
flarum/core | src/Notification/Notification.php | Notification.scopeWhereSubjectVisibleTo | public function scopeWhereSubjectVisibleTo(Builder $query, User $actor)
{
$query->where(function ($query) use ($actor) {
$classes = [];
foreach (static::$subjectModels as $type => $class) {
$classes[$class][] = $type;
}
foreach ($classes as $class => $types) {
$query->orWhere(function ($query) use ($types, $class, $actor) {
$query->whereIn('type', $types)
->whereExists(function ($query) use ($class, $actor) {
$query->selectRaw(1)
->from((new $class)->getTable())
->whereColumn('id', 'subject_id');
static::$dispatcher->dispatch(
new ScopeModelVisibility($class::query()->setQuery($query), $actor, 'view')
);
});
});
}
});
} | php | public function scopeWhereSubjectVisibleTo(Builder $query, User $actor)
{
$query->where(function ($query) use ($actor) {
$classes = [];
foreach (static::$subjectModels as $type => $class) {
$classes[$class][] = $type;
}
foreach ($classes as $class => $types) {
$query->orWhere(function ($query) use ($types, $class, $actor) {
$query->whereIn('type', $types)
->whereExists(function ($query) use ($class, $actor) {
$query->selectRaw(1)
->from((new $class)->getTable())
->whereColumn('id', 'subject_id');
static::$dispatcher->dispatch(
new ScopeModelVisibility($class::query()->setQuery($query), $actor, 'view')
);
});
});
}
});
} | [
"public",
"function",
"scopeWhereSubjectVisibleTo",
"(",
"Builder",
"$",
"query",
",",
"User",
"$",
"actor",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"function",
"(",
"$",
"query",
")",
"use",
"(",
"$",
"actor",
")",
"{",
"$",
"classes",
"=",
"[",
"]",
";",
"foreach",
"(",
"static",
"::",
"$",
"subjectModels",
"as",
"$",
"type",
"=>",
"$",
"class",
")",
"{",
"$",
"classes",
"[",
"$",
"class",
"]",
"[",
"]",
"=",
"$",
"type",
";",
"}",
"foreach",
"(",
"$",
"classes",
"as",
"$",
"class",
"=>",
"$",
"types",
")",
"{",
"$",
"query",
"->",
"orWhere",
"(",
"function",
"(",
"$",
"query",
")",
"use",
"(",
"$",
"types",
",",
"$",
"class",
",",
"$",
"actor",
")",
"{",
"$",
"query",
"->",
"whereIn",
"(",
"'type'",
",",
"$",
"types",
")",
"->",
"whereExists",
"(",
"function",
"(",
"$",
"query",
")",
"use",
"(",
"$",
"class",
",",
"$",
"actor",
")",
"{",
"$",
"query",
"->",
"selectRaw",
"(",
"1",
")",
"->",
"from",
"(",
"(",
"new",
"$",
"class",
")",
"->",
"getTable",
"(",
")",
")",
"->",
"whereColumn",
"(",
"'id'",
",",
"'subject_id'",
")",
";",
"static",
"::",
"$",
"dispatcher",
"->",
"dispatch",
"(",
"new",
"ScopeModelVisibility",
"(",
"$",
"class",
"::",
"query",
"(",
")",
"->",
"setQuery",
"(",
"$",
"query",
")",
",",
"$",
"actor",
",",
"'view'",
")",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
"}",
")",
";",
"}"
] | Scope the query to include only notifications whose subjects are visible
to the given user.
@param Builder $query | [
"Scope",
"the",
"query",
"to",
"include",
"only",
"notifications",
"whose",
"subjects",
"are",
"visible",
"to",
"the",
"given",
"user",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Notification/Notification.php#L146-L170 | train |
flarum/core | src/Notification/Notification.php | Notification.scopeWhereSubject | public function scopeWhereSubject(Builder $query, $model)
{
$query->whereSubjectModel(get_class($model))
->where('subject_id', $model->id);
} | php | public function scopeWhereSubject(Builder $query, $model)
{
$query->whereSubjectModel(get_class($model))
->where('subject_id', $model->id);
} | [
"public",
"function",
"scopeWhereSubject",
"(",
"Builder",
"$",
"query",
",",
"$",
"model",
")",
"{",
"$",
"query",
"->",
"whereSubjectModel",
"(",
"get_class",
"(",
"$",
"model",
")",
")",
"->",
"where",
"(",
"'subject_id'",
",",
"$",
"model",
"->",
"id",
")",
";",
"}"
] | Scope the query to include only notifications that have the given
subject.
@param Builder $query
@param object $model | [
"Scope",
"the",
"query",
"to",
"include",
"only",
"notifications",
"that",
"have",
"the",
"given",
"subject",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Notification/Notification.php#L179-L183 | train |
flarum/core | src/Notification/Notification.php | Notification.scopeWhereSubjectModel | public function scopeWhereSubjectModel(Builder $query, string $class)
{
$notificationTypes = array_filter(self::getSubjectModels(), function ($modelClass) use ($class) {
return $modelClass === $class or is_subclass_of($class, $modelClass);
});
$query->whereIn('type', array_keys($notificationTypes));
} | php | public function scopeWhereSubjectModel(Builder $query, string $class)
{
$notificationTypes = array_filter(self::getSubjectModels(), function ($modelClass) use ($class) {
return $modelClass === $class or is_subclass_of($class, $modelClass);
});
$query->whereIn('type', array_keys($notificationTypes));
} | [
"public",
"function",
"scopeWhereSubjectModel",
"(",
"Builder",
"$",
"query",
",",
"string",
"$",
"class",
")",
"{",
"$",
"notificationTypes",
"=",
"array_filter",
"(",
"self",
"::",
"getSubjectModels",
"(",
")",
",",
"function",
"(",
"$",
"modelClass",
")",
"use",
"(",
"$",
"class",
")",
"{",
"return",
"$",
"modelClass",
"===",
"$",
"class",
"or",
"is_subclass_of",
"(",
"$",
"class",
",",
"$",
"modelClass",
")",
";",
"}",
")",
";",
"$",
"query",
"->",
"whereIn",
"(",
"'type'",
",",
"array_keys",
"(",
"$",
"notificationTypes",
")",
")",
";",
"}"
] | Scope the query to include only notification types that use the given
subject model.
@param Builder $query
@param string $class | [
"Scope",
"the",
"query",
"to",
"include",
"only",
"notification",
"types",
"that",
"use",
"the",
"given",
"subject",
"model",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Notification/Notification.php#L192-L199 | train |
flarum/core | src/User/EmailToken.php | EmailToken.generate | public static function generate($email, $userId)
{
$token = new static;
$token->token = str_random(40);
$token->user_id = $userId;
$token->email = $email;
$token->created_at = Carbon::now();
return $token;
} | php | public static function generate($email, $userId)
{
$token = new static;
$token->token = str_random(40);
$token->user_id = $userId;
$token->email = $email;
$token->created_at = Carbon::now();
return $token;
} | [
"public",
"static",
"function",
"generate",
"(",
"$",
"email",
",",
"$",
"userId",
")",
"{",
"$",
"token",
"=",
"new",
"static",
";",
"$",
"token",
"->",
"token",
"=",
"str_random",
"(",
"40",
")",
";",
"$",
"token",
"->",
"user_id",
"=",
"$",
"userId",
";",
"$",
"token",
"->",
"email",
"=",
"$",
"email",
";",
"$",
"token",
"->",
"created_at",
"=",
"Carbon",
"::",
"now",
"(",
")",
";",
"return",
"$",
"token",
";",
"}"
] | Generate an email token for the specified user.
@param string $email
@param int $userId
@return static | [
"Generate",
"an",
"email",
"token",
"for",
"the",
"specified",
"user",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/User/EmailToken.php#L53-L63 | train |
flarum/core | src/Database/Migration.php | Migration.addColumns | public static function addColumns($tableName, array $columnDefinitions)
{
return [
'up' => function (Builder $schema) use ($tableName, $columnDefinitions) {
$schema->table($tableName, function (Blueprint $table) use ($schema, $columnDefinitions) {
foreach ($columnDefinitions as $columnName => $options) {
$type = array_shift($options);
$table->addColumn($type, $columnName, $options);
}
});
},
'down' => function (Builder $schema) use ($tableName, $columnDefinitions) {
$schema->table($tableName, function (Blueprint $table) use ($columnDefinitions) {
$table->dropColumn(array_keys($columnDefinitions));
});
}
];
} | php | public static function addColumns($tableName, array $columnDefinitions)
{
return [
'up' => function (Builder $schema) use ($tableName, $columnDefinitions) {
$schema->table($tableName, function (Blueprint $table) use ($schema, $columnDefinitions) {
foreach ($columnDefinitions as $columnName => $options) {
$type = array_shift($options);
$table->addColumn($type, $columnName, $options);
}
});
},
'down' => function (Builder $schema) use ($tableName, $columnDefinitions) {
$schema->table($tableName, function (Blueprint $table) use ($columnDefinitions) {
$table->dropColumn(array_keys($columnDefinitions));
});
}
];
} | [
"public",
"static",
"function",
"addColumns",
"(",
"$",
"tableName",
",",
"array",
"$",
"columnDefinitions",
")",
"{",
"return",
"[",
"'up'",
"=>",
"function",
"(",
"Builder",
"$",
"schema",
")",
"use",
"(",
"$",
"tableName",
",",
"$",
"columnDefinitions",
")",
"{",
"$",
"schema",
"->",
"table",
"(",
"$",
"tableName",
",",
"function",
"(",
"Blueprint",
"$",
"table",
")",
"use",
"(",
"$",
"schema",
",",
"$",
"columnDefinitions",
")",
"{",
"foreach",
"(",
"$",
"columnDefinitions",
"as",
"$",
"columnName",
"=>",
"$",
"options",
")",
"{",
"$",
"type",
"=",
"array_shift",
"(",
"$",
"options",
")",
";",
"$",
"table",
"->",
"addColumn",
"(",
"$",
"type",
",",
"$",
"columnName",
",",
"$",
"options",
")",
";",
"}",
"}",
")",
";",
"}",
",",
"'down'",
"=>",
"function",
"(",
"Builder",
"$",
"schema",
")",
"use",
"(",
"$",
"tableName",
",",
"$",
"columnDefinitions",
")",
"{",
"$",
"schema",
"->",
"table",
"(",
"$",
"tableName",
",",
"function",
"(",
"Blueprint",
"$",
"table",
")",
"use",
"(",
"$",
"columnDefinitions",
")",
"{",
"$",
"table",
"->",
"dropColumn",
"(",
"array_keys",
"(",
"$",
"columnDefinitions",
")",
")",
";",
"}",
")",
";",
"}",
"]",
";",
"}"
] | Add columns to a table. | [
"Add",
"columns",
"to",
"a",
"table",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Database/Migration.php#L60-L77 | train |
flarum/core | src/Database/Migration.php | Migration.renameColumns | public static function renameColumns($tableName, array $columnNames)
{
return [
'up' => function (Builder $schema) use ($tableName, $columnNames) {
$schema->table($tableName, function (Blueprint $table) use ($columnNames) {
foreach ($columnNames as $from => $to) {
$table->renameColumn($from, $to);
}
});
},
'down' => function (Builder $schema) use ($tableName, $columnNames) {
$schema->table($tableName, function (Blueprint $table) use ($columnNames) {
foreach ($columnNames as $to => $from) {
$table->renameColumn($from, $to);
}
});
}
];
} | php | public static function renameColumns($tableName, array $columnNames)
{
return [
'up' => function (Builder $schema) use ($tableName, $columnNames) {
$schema->table($tableName, function (Blueprint $table) use ($columnNames) {
foreach ($columnNames as $from => $to) {
$table->renameColumn($from, $to);
}
});
},
'down' => function (Builder $schema) use ($tableName, $columnNames) {
$schema->table($tableName, function (Blueprint $table) use ($columnNames) {
foreach ($columnNames as $to => $from) {
$table->renameColumn($from, $to);
}
});
}
];
} | [
"public",
"static",
"function",
"renameColumns",
"(",
"$",
"tableName",
",",
"array",
"$",
"columnNames",
")",
"{",
"return",
"[",
"'up'",
"=>",
"function",
"(",
"Builder",
"$",
"schema",
")",
"use",
"(",
"$",
"tableName",
",",
"$",
"columnNames",
")",
"{",
"$",
"schema",
"->",
"table",
"(",
"$",
"tableName",
",",
"function",
"(",
"Blueprint",
"$",
"table",
")",
"use",
"(",
"$",
"columnNames",
")",
"{",
"foreach",
"(",
"$",
"columnNames",
"as",
"$",
"from",
"=>",
"$",
"to",
")",
"{",
"$",
"table",
"->",
"renameColumn",
"(",
"$",
"from",
",",
"$",
"to",
")",
";",
"}",
"}",
")",
";",
"}",
",",
"'down'",
"=>",
"function",
"(",
"Builder",
"$",
"schema",
")",
"use",
"(",
"$",
"tableName",
",",
"$",
"columnNames",
")",
"{",
"$",
"schema",
"->",
"table",
"(",
"$",
"tableName",
",",
"function",
"(",
"Blueprint",
"$",
"table",
")",
"use",
"(",
"$",
"columnNames",
")",
"{",
"foreach",
"(",
"$",
"columnNames",
"as",
"$",
"to",
"=>",
"$",
"from",
")",
"{",
"$",
"table",
"->",
"renameColumn",
"(",
"$",
"from",
",",
"$",
"to",
")",
";",
"}",
"}",
")",
";",
"}",
"]",
";",
"}"
] | Rename multiple columns. | [
"Rename",
"multiple",
"columns",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Database/Migration.php#L103-L121 | train |
flarum/core | src/Database/Migration.php | Migration.addSettings | public static function addSettings(array $defaults)
{
return [
'up' => function (Builder $schema) use ($defaults) {
$settings = new DatabaseSettingsRepository(
$schema->getConnection()
);
foreach ($defaults as $key => $value) {
$settings->set($key, $value);
}
},
'down' => function (Builder $schema) use ($defaults) {
$settings = new DatabaseSettingsRepository(
$schema->getConnection()
);
foreach (array_keys($defaults) as $key) {
$settings->delete($key);
}
}
];
} | php | public static function addSettings(array $defaults)
{
return [
'up' => function (Builder $schema) use ($defaults) {
$settings = new DatabaseSettingsRepository(
$schema->getConnection()
);
foreach ($defaults as $key => $value) {
$settings->set($key, $value);
}
},
'down' => function (Builder $schema) use ($defaults) {
$settings = new DatabaseSettingsRepository(
$schema->getConnection()
);
foreach (array_keys($defaults) as $key) {
$settings->delete($key);
}
}
];
} | [
"public",
"static",
"function",
"addSettings",
"(",
"array",
"$",
"defaults",
")",
"{",
"return",
"[",
"'up'",
"=>",
"function",
"(",
"Builder",
"$",
"schema",
")",
"use",
"(",
"$",
"defaults",
")",
"{",
"$",
"settings",
"=",
"new",
"DatabaseSettingsRepository",
"(",
"$",
"schema",
"->",
"getConnection",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"defaults",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"settings",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"}",
",",
"'down'",
"=>",
"function",
"(",
"Builder",
"$",
"schema",
")",
"use",
"(",
"$",
"defaults",
")",
"{",
"$",
"settings",
"=",
"new",
"DatabaseSettingsRepository",
"(",
"$",
"schema",
"->",
"getConnection",
"(",
")",
")",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"defaults",
")",
"as",
"$",
"key",
")",
"{",
"$",
"settings",
"->",
"delete",
"(",
"$",
"key",
")",
";",
"}",
"}",
"]",
";",
"}"
] | Add default values for config values. | [
"Add",
"default",
"values",
"for",
"config",
"values",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Database/Migration.php#L126-L148 | train |
flarum/core | src/Database/Migration.php | Migration.addPermissions | public static function addPermissions(array $permissions)
{
$rows = [];
foreach ($permissions as $permission => $groups) {
foreach ((array) $groups as $group) {
$rows[] = [
'group_id' => $group,
'permission' => $permission,
];
}
}
return [
'up' => function (Builder $schema) use ($rows) {
$db = $schema->getConnection();
foreach ($rows as $row) {
if ($db->table('group_permission')->where($row)->exists()) {
continue;
}
if ($db->table('groups')->where('id', $row['group_id'])->doesntExist()) {
continue;
}
$db->table('group_permission')->insert($row);
}
},
'down' => function (Builder $schema) use ($rows) {
$db = $schema->getConnection();
foreach ($rows as $row) {
$db->table('group_permission')->where($row)->delete();
}
}
];
} | php | public static function addPermissions(array $permissions)
{
$rows = [];
foreach ($permissions as $permission => $groups) {
foreach ((array) $groups as $group) {
$rows[] = [
'group_id' => $group,
'permission' => $permission,
];
}
}
return [
'up' => function (Builder $schema) use ($rows) {
$db = $schema->getConnection();
foreach ($rows as $row) {
if ($db->table('group_permission')->where($row)->exists()) {
continue;
}
if ($db->table('groups')->where('id', $row['group_id'])->doesntExist()) {
continue;
}
$db->table('group_permission')->insert($row);
}
},
'down' => function (Builder $schema) use ($rows) {
$db = $schema->getConnection();
foreach ($rows as $row) {
$db->table('group_permission')->where($row)->delete();
}
}
];
} | [
"public",
"static",
"function",
"addPermissions",
"(",
"array",
"$",
"permissions",
")",
"{",
"$",
"rows",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"permissions",
"as",
"$",
"permission",
"=>",
"$",
"groups",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"groups",
"as",
"$",
"group",
")",
"{",
"$",
"rows",
"[",
"]",
"=",
"[",
"'group_id'",
"=>",
"$",
"group",
",",
"'permission'",
"=>",
"$",
"permission",
",",
"]",
";",
"}",
"}",
"return",
"[",
"'up'",
"=>",
"function",
"(",
"Builder",
"$",
"schema",
")",
"use",
"(",
"$",
"rows",
")",
"{",
"$",
"db",
"=",
"$",
"schema",
"->",
"getConnection",
"(",
")",
";",
"foreach",
"(",
"$",
"rows",
"as",
"$",
"row",
")",
"{",
"if",
"(",
"$",
"db",
"->",
"table",
"(",
"'group_permission'",
")",
"->",
"where",
"(",
"$",
"row",
")",
"->",
"exists",
"(",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"db",
"->",
"table",
"(",
"'groups'",
")",
"->",
"where",
"(",
"'id'",
",",
"$",
"row",
"[",
"'group_id'",
"]",
")",
"->",
"doesntExist",
"(",
")",
")",
"{",
"continue",
";",
"}",
"$",
"db",
"->",
"table",
"(",
"'group_permission'",
")",
"->",
"insert",
"(",
"$",
"row",
")",
";",
"}",
"}",
",",
"'down'",
"=>",
"function",
"(",
"Builder",
"$",
"schema",
")",
"use",
"(",
"$",
"rows",
")",
"{",
"$",
"db",
"=",
"$",
"schema",
"->",
"getConnection",
"(",
")",
";",
"foreach",
"(",
"$",
"rows",
"as",
"$",
"row",
")",
"{",
"$",
"db",
"->",
"table",
"(",
"'group_permission'",
")",
"->",
"where",
"(",
"$",
"row",
")",
"->",
"delete",
"(",
")",
";",
"}",
"}",
"]",
";",
"}"
] | Add default permissions. | [
"Add",
"default",
"permissions",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Database/Migration.php#L153-L191 | train |
flarum/core | src/Formatter/Formatter.php | Formatter.parse | public function parse($text, $context = null)
{
$parser = $this->getParser($context);
$this->events->dispatch(new Parsing($parser, $context, $text));
return $parser->parse($text);
} | php | public function parse($text, $context = null)
{
$parser = $this->getParser($context);
$this->events->dispatch(new Parsing($parser, $context, $text));
return $parser->parse($text);
} | [
"public",
"function",
"parse",
"(",
"$",
"text",
",",
"$",
"context",
"=",
"null",
")",
"{",
"$",
"parser",
"=",
"$",
"this",
"->",
"getParser",
"(",
"$",
"context",
")",
";",
"$",
"this",
"->",
"events",
"->",
"dispatch",
"(",
"new",
"Parsing",
"(",
"$",
"parser",
",",
"$",
"context",
",",
"$",
"text",
")",
")",
";",
"return",
"$",
"parser",
"->",
"parse",
"(",
"$",
"text",
")",
";",
"}"
] | Parse text.
@param string $text
@param mixed $context
@return string | [
"Parse",
"text",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Formatter/Formatter.php#L59-L66 | train |
flarum/core | src/Formatter/Formatter.php | Formatter.render | public function render($xml, $context = null, ServerRequestInterface $request = null)
{
$renderer = $this->getRenderer();
$this->events->dispatch(new Rendering($renderer, $context, $xml, $request));
return $renderer->render($xml);
} | php | public function render($xml, $context = null, ServerRequestInterface $request = null)
{
$renderer = $this->getRenderer();
$this->events->dispatch(new Rendering($renderer, $context, $xml, $request));
return $renderer->render($xml);
} | [
"public",
"function",
"render",
"(",
"$",
"xml",
",",
"$",
"context",
"=",
"null",
",",
"ServerRequestInterface",
"$",
"request",
"=",
"null",
")",
"{",
"$",
"renderer",
"=",
"$",
"this",
"->",
"getRenderer",
"(",
")",
";",
"$",
"this",
"->",
"events",
"->",
"dispatch",
"(",
"new",
"Rendering",
"(",
"$",
"renderer",
",",
"$",
"context",
",",
"$",
"xml",
",",
"$",
"request",
")",
")",
";",
"return",
"$",
"renderer",
"->",
"render",
"(",
"$",
"xml",
")",
";",
"}"
] | Render parsed XML.
@param string $xml
@param mixed $context
@param ServerRequestInterface|null $request
@return string | [
"Render",
"parsed",
"XML",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Formatter/Formatter.php#L76-L83 | train |
flarum/core | src/Formatter/Formatter.php | Formatter.getComponent | protected function getComponent($name)
{
$formatter = $this->cache->rememberForever('flarum.formatter', function () {
return $this->getConfigurator()->finalize();
});
return $formatter[$name];
} | php | protected function getComponent($name)
{
$formatter = $this->cache->rememberForever('flarum.formatter', function () {
return $this->getConfigurator()->finalize();
});
return $formatter[$name];
} | [
"protected",
"function",
"getComponent",
"(",
"$",
"name",
")",
"{",
"$",
"formatter",
"=",
"$",
"this",
"->",
"cache",
"->",
"rememberForever",
"(",
"'flarum.formatter'",
",",
"function",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"getConfigurator",
"(",
")",
"->",
"finalize",
"(",
")",
";",
"}",
")",
";",
"return",
"$",
"formatter",
"[",
"$",
"name",
"]",
";",
"}"
] | Get a TextFormatter component.
@param string $name "renderer" or "parser" or "js"
@return mixed | [
"Get",
"a",
"TextFormatter",
"component",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Formatter/Formatter.php#L155-L162 | train |
flarum/core | src/Api/Serializer/AbstractSerializer.php | AbstractSerializer.getCustomRelationship | protected function getCustomRelationship($model, $name)
{
$relationship = static::$dispatcher->until(
new GetApiRelationship($this, $name, $model)
);
if ($relationship && ! ($relationship instanceof Relationship)) {
throw new LogicException(
'GetApiRelationship handler must return an instance of '.Relationship::class
);
}
return $relationship;
} | php | protected function getCustomRelationship($model, $name)
{
$relationship = static::$dispatcher->until(
new GetApiRelationship($this, $name, $model)
);
if ($relationship && ! ($relationship instanceof Relationship)) {
throw new LogicException(
'GetApiRelationship handler must return an instance of '.Relationship::class
);
}
return $relationship;
} | [
"protected",
"function",
"getCustomRelationship",
"(",
"$",
"model",
",",
"$",
"name",
")",
"{",
"$",
"relationship",
"=",
"static",
"::",
"$",
"dispatcher",
"->",
"until",
"(",
"new",
"GetApiRelationship",
"(",
"$",
"this",
",",
"$",
"name",
",",
"$",
"model",
")",
")",
";",
"if",
"(",
"$",
"relationship",
"&&",
"!",
"(",
"$",
"relationship",
"instanceof",
"Relationship",
")",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"'GetApiRelationship handler must return an instance of '",
".",
"Relationship",
"::",
"class",
")",
";",
"}",
"return",
"$",
"relationship",
";",
"}"
] | Get a custom relationship.
@param mixed $model
@param string $name
@return Relationship|null | [
"Get",
"a",
"custom",
"relationship",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Api/Serializer/AbstractSerializer.php#L133-L146 | train |
flarum/core | src/Api/Serializer/AbstractSerializer.php | AbstractSerializer.hasOne | public function hasOne($model, $serializer, $relation = null)
{
return $this->buildRelationship($model, $serializer, $relation);
} | php | public function hasOne($model, $serializer, $relation = null)
{
return $this->buildRelationship($model, $serializer, $relation);
} | [
"public",
"function",
"hasOne",
"(",
"$",
"model",
",",
"$",
"serializer",
",",
"$",
"relation",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"buildRelationship",
"(",
"$",
"model",
",",
"$",
"serializer",
",",
"$",
"relation",
")",
";",
"}"
] | Get a relationship builder for a has-one relationship.
@param mixed $model
@param string|Closure|\Tobscure\JsonApi\SerializerInterface $serializer
@param string|Closure|null $relation
@return Relationship | [
"Get",
"a",
"relationship",
"builder",
"for",
"a",
"has",
"-",
"one",
"relationship",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Api/Serializer/AbstractSerializer.php#L156-L159 | train |
flarum/core | src/Api/Serializer/AbstractSerializer.php | AbstractSerializer.hasMany | public function hasMany($model, $serializer, $relation = null)
{
return $this->buildRelationship($model, $serializer, $relation, true);
} | php | public function hasMany($model, $serializer, $relation = null)
{
return $this->buildRelationship($model, $serializer, $relation, true);
} | [
"public",
"function",
"hasMany",
"(",
"$",
"model",
",",
"$",
"serializer",
",",
"$",
"relation",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"buildRelationship",
"(",
"$",
"model",
",",
"$",
"serializer",
",",
"$",
"relation",
",",
"true",
")",
";",
"}"
] | Get a relationship builder for a has-many relationship.
@param mixed $model
@param string|Closure|\Tobscure\JsonApi\SerializerInterface $serializer
@param string|null $relation
@return Relationship | [
"Get",
"a",
"relationship",
"builder",
"for",
"a",
"has",
"-",
"many",
"relationship",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Api/Serializer/AbstractSerializer.php#L169-L172 | train |
flarum/core | src/Search/ApplySearchParametersTrait.php | ApplySearchParametersTrait.applySort | protected function applySort(AbstractSearch $search, array $sort = null)
{
$sort = $sort ?: $search->getDefaultSort();
if (is_callable($sort)) {
$sort($search->getQuery());
} else {
foreach ($sort as $field => $order) {
if (is_array($order)) {
foreach ($order as $value) {
$search->getQuery()->orderByRaw(snake_case($field).' != ?', [$value]);
}
} else {
$search->getQuery()->orderBy(snake_case($field), $order);
}
}
}
} | php | protected function applySort(AbstractSearch $search, array $sort = null)
{
$sort = $sort ?: $search->getDefaultSort();
if (is_callable($sort)) {
$sort($search->getQuery());
} else {
foreach ($sort as $field => $order) {
if (is_array($order)) {
foreach ($order as $value) {
$search->getQuery()->orderByRaw(snake_case($field).' != ?', [$value]);
}
} else {
$search->getQuery()->orderBy(snake_case($field), $order);
}
}
}
} | [
"protected",
"function",
"applySort",
"(",
"AbstractSearch",
"$",
"search",
",",
"array",
"$",
"sort",
"=",
"null",
")",
"{",
"$",
"sort",
"=",
"$",
"sort",
"?",
":",
"$",
"search",
"->",
"getDefaultSort",
"(",
")",
";",
"if",
"(",
"is_callable",
"(",
"$",
"sort",
")",
")",
"{",
"$",
"sort",
"(",
"$",
"search",
"->",
"getQuery",
"(",
")",
")",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"sort",
"as",
"$",
"field",
"=>",
"$",
"order",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"order",
")",
")",
"{",
"foreach",
"(",
"$",
"order",
"as",
"$",
"value",
")",
"{",
"$",
"search",
"->",
"getQuery",
"(",
")",
"->",
"orderByRaw",
"(",
"snake_case",
"(",
"$",
"field",
")",
".",
"' != ?'",
",",
"[",
"$",
"value",
"]",
")",
";",
"}",
"}",
"else",
"{",
"$",
"search",
"->",
"getQuery",
"(",
")",
"->",
"orderBy",
"(",
"snake_case",
"(",
"$",
"field",
")",
",",
"$",
"order",
")",
";",
"}",
"}",
"}",
"}"
] | Apply sort criteria to a discussion search.
@param AbstractSearch $search
@param array $sort | [
"Apply",
"sort",
"criteria",
"to",
"a",
"discussion",
"search",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Search/ApplySearchParametersTrait.php#L22-L39 | train |
flarum/core | src/Post/CommentPost.php | CommentPost.revise | public function revise($content, User $actor)
{
if ($this->content !== $content) {
$this->content = $content;
$this->edited_at = Carbon::now();
$this->edited_user_id = $actor->id;
$this->raise(new Revised($this));
}
return $this;
} | php | public function revise($content, User $actor)
{
if ($this->content !== $content) {
$this->content = $content;
$this->edited_at = Carbon::now();
$this->edited_user_id = $actor->id;
$this->raise(new Revised($this));
}
return $this;
} | [
"public",
"function",
"revise",
"(",
"$",
"content",
",",
"User",
"$",
"actor",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"content",
"!==",
"$",
"content",
")",
"{",
"$",
"this",
"->",
"content",
"=",
"$",
"content",
";",
"$",
"this",
"->",
"edited_at",
"=",
"Carbon",
"::",
"now",
"(",
")",
";",
"$",
"this",
"->",
"edited_user_id",
"=",
"$",
"actor",
"->",
"id",
";",
"$",
"this",
"->",
"raise",
"(",
"new",
"Revised",
"(",
"$",
"this",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Revise the post's content.
@param string $content
@param User $actor
@return $this | [
"Revise",
"the",
"post",
"s",
"content",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Post/CommentPost.php#L76-L88 | train |
flarum/core | src/Post/CommentPost.php | CommentPost.setContentAttribute | public function setContentAttribute($value)
{
$this->attributes['content'] = $value ? static::$formatter->parse($value, $this) : null;
} | php | public function setContentAttribute($value)
{
$this->attributes['content'] = $value ? static::$formatter->parse($value, $this) : null;
} | [
"public",
"function",
"setContentAttribute",
"(",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"attributes",
"[",
"'content'",
"]",
"=",
"$",
"value",
"?",
"static",
"::",
"$",
"formatter",
"->",
"parse",
"(",
"$",
"value",
",",
"$",
"this",
")",
":",
"null",
";",
"}"
] | Parse the content before it is saved to the database.
@param string $value | [
"Parse",
"the",
"content",
"before",
"it",
"is",
"saved",
"to",
"the",
"database",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Post/CommentPost.php#L151-L154 | train |
flarum/core | src/Database/Migrator.php | Migrator.runClosureMigration | protected function runClosureMigration($migration, $direction = 'up')
{
if (is_array($migration) && array_key_exists($direction, $migration)) {
call_user_func($migration[$direction], $this->schemaBuilder);
} else {
throw new Exception('Migration file should contain an array with up/down.');
}
} | php | protected function runClosureMigration($migration, $direction = 'up')
{
if (is_array($migration) && array_key_exists($direction, $migration)) {
call_user_func($migration[$direction], $this->schemaBuilder);
} else {
throw new Exception('Migration file should contain an array with up/down.');
}
} | [
"protected",
"function",
"runClosureMigration",
"(",
"$",
"migration",
",",
"$",
"direction",
"=",
"'up'",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"migration",
")",
"&&",
"array_key_exists",
"(",
"$",
"direction",
",",
"$",
"migration",
")",
")",
"{",
"call_user_func",
"(",
"$",
"migration",
"[",
"$",
"direction",
"]",
",",
"$",
"this",
"->",
"schemaBuilder",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"(",
"'Migration file should contain an array with up/down.'",
")",
";",
"}",
"}"
] | Runs a closure migration based on the migrate direction.
@param $migration
@param string $direction
@throws Exception | [
"Runs",
"a",
"closure",
"migration",
"based",
"on",
"the",
"migrate",
"direction",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Database/Migrator.php#L196-L203 | train |
flarum/core | src/User/LoginProvider.php | LoginProvider.logIn | public static function logIn(string $provider, string $identifier): ?User
{
if ($provider = static::where(compact('provider', 'identifier'))->first()) {
$provider->touch();
return $provider->user;
}
return null;
} | php | public static function logIn(string $provider, string $identifier): ?User
{
if ($provider = static::where(compact('provider', 'identifier'))->first()) {
$provider->touch();
return $provider->user;
}
return null;
} | [
"public",
"static",
"function",
"logIn",
"(",
"string",
"$",
"provider",
",",
"string",
"$",
"identifier",
")",
":",
"?",
"User",
"{",
"if",
"(",
"$",
"provider",
"=",
"static",
"::",
"where",
"(",
"compact",
"(",
"'provider'",
",",
"'identifier'",
")",
")",
"->",
"first",
"(",
")",
")",
"{",
"$",
"provider",
"->",
"touch",
"(",
")",
";",
"return",
"$",
"provider",
"->",
"user",
";",
"}",
"return",
"null",
";",
"}"
] | Get the user associated with the provider so that they can be logged in.
@param string $provider
@param string $identifier
@return User|null | [
"Get",
"the",
"user",
"associated",
"with",
"the",
"provider",
"so",
"that",
"they",
"can",
"be",
"logged",
"in",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/User/LoginProvider.php#L50-L59 | train |
flarum/core | src/Api/Client.php | Client.send | public function send($controller, User $actor = null, array $queryParams = [], array $body = []): ResponseInterface
{
$request = ServerRequestFactory::fromGlobals(null, $queryParams, $body);
$request = $request->withAttribute('actor', $actor);
if (is_string($controller)) {
$controller = $this->container->make($controller);
}
if (! ($controller instanceof RequestHandlerInterface)) {
throw new InvalidArgumentException(
'Endpoint must be an instance of '.RequestHandlerInterface::class
);
}
try {
return $controller->handle($request);
} catch (Exception $e) {
if (! $this->errorHandler) {
throw $e;
}
return $this->errorHandler->handle($e);
}
} | php | public function send($controller, User $actor = null, array $queryParams = [], array $body = []): ResponseInterface
{
$request = ServerRequestFactory::fromGlobals(null, $queryParams, $body);
$request = $request->withAttribute('actor', $actor);
if (is_string($controller)) {
$controller = $this->container->make($controller);
}
if (! ($controller instanceof RequestHandlerInterface)) {
throw new InvalidArgumentException(
'Endpoint must be an instance of '.RequestHandlerInterface::class
);
}
try {
return $controller->handle($request);
} catch (Exception $e) {
if (! $this->errorHandler) {
throw $e;
}
return $this->errorHandler->handle($e);
}
} | [
"public",
"function",
"send",
"(",
"$",
"controller",
",",
"User",
"$",
"actor",
"=",
"null",
",",
"array",
"$",
"queryParams",
"=",
"[",
"]",
",",
"array",
"$",
"body",
"=",
"[",
"]",
")",
":",
"ResponseInterface",
"{",
"$",
"request",
"=",
"ServerRequestFactory",
"::",
"fromGlobals",
"(",
"null",
",",
"$",
"queryParams",
",",
"$",
"body",
")",
";",
"$",
"request",
"=",
"$",
"request",
"->",
"withAttribute",
"(",
"'actor'",
",",
"$",
"actor",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"controller",
")",
")",
"{",
"$",
"controller",
"=",
"$",
"this",
"->",
"container",
"->",
"make",
"(",
"$",
"controller",
")",
";",
"}",
"if",
"(",
"!",
"(",
"$",
"controller",
"instanceof",
"RequestHandlerInterface",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Endpoint must be an instance of '",
".",
"RequestHandlerInterface",
"::",
"class",
")",
";",
"}",
"try",
"{",
"return",
"$",
"controller",
"->",
"handle",
"(",
"$",
"request",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"errorHandler",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"return",
"$",
"this",
"->",
"errorHandler",
"->",
"handle",
"(",
"$",
"e",
")",
";",
"}",
"}"
] | Execute the given API action class, pass the input and return its response.
@param string|RequestHandlerInterface $controller
@param User|null $actor
@param array $queryParams
@param array $body
@return ResponseInterface
@throws Exception | [
"Execute",
"the",
"given",
"API",
"action",
"class",
"pass",
"the",
"input",
"and",
"return",
"its",
"response",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Api/Client.php#L54-L79 | train |
flarum/core | src/Group/GroupRepository.php | GroupRepository.findOrFail | public function findOrFail($id, User $actor = null)
{
$query = Group::where('id', $id);
return $this->scopeVisibleTo($query, $actor)->firstOrFail();
} | php | public function findOrFail($id, User $actor = null)
{
$query = Group::where('id', $id);
return $this->scopeVisibleTo($query, $actor)->firstOrFail();
} | [
"public",
"function",
"findOrFail",
"(",
"$",
"id",
",",
"User",
"$",
"actor",
"=",
"null",
")",
"{",
"$",
"query",
"=",
"Group",
"::",
"where",
"(",
"'id'",
",",
"$",
"id",
")",
";",
"return",
"$",
"this",
"->",
"scopeVisibleTo",
"(",
"$",
"query",
",",
"$",
"actor",
")",
"->",
"firstOrFail",
"(",
")",
";",
"}"
] | Find a user by ID, optionally making sure it is visible to a certain
user, or throw an exception.
@param int $id
@param User $actor
@return \Flarum\Group\Group
@throws \Illuminate\Database\Eloquent\ModelNotFoundException | [
"Find",
"a",
"user",
"by",
"ID",
"optionally",
"making",
"sure",
"it",
"is",
"visible",
"to",
"a",
"certain",
"user",
"or",
"throw",
"an",
"exception",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Group/GroupRepository.php#L39-L44 | train |
flarum/core | src/Group/GroupRepository.php | GroupRepository.findByName | public function findByName($name, User $actor = null)
{
$query = Group::where('name_singular', $name)->orWhere('name_plural', $name);
return $this->scopeVisibleTo($query, $actor)->first();
} | php | public function findByName($name, User $actor = null)
{
$query = Group::where('name_singular', $name)->orWhere('name_plural', $name);
return $this->scopeVisibleTo($query, $actor)->first();
} | [
"public",
"function",
"findByName",
"(",
"$",
"name",
",",
"User",
"$",
"actor",
"=",
"null",
")",
"{",
"$",
"query",
"=",
"Group",
"::",
"where",
"(",
"'name_singular'",
",",
"$",
"name",
")",
"->",
"orWhere",
"(",
"'name_plural'",
",",
"$",
"name",
")",
";",
"return",
"$",
"this",
"->",
"scopeVisibleTo",
"(",
"$",
"query",
",",
"$",
"actor",
")",
"->",
"first",
"(",
")",
";",
"}"
] | Find a group by name.
@param string $name
@return User|null | [
"Find",
"a",
"group",
"by",
"name",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Group/GroupRepository.php#L52-L57 | train |
flarum/core | src/Util/Str.php | Str.slug | public static function slug($str)
{
$str = strtolower($str);
$str = preg_replace('/[^a-z0-9]/i', '-', $str);
$str = preg_replace('/-+/', '-', $str);
$str = preg_replace('/-$|^-/', '', $str);
return $str;
} | php | public static function slug($str)
{
$str = strtolower($str);
$str = preg_replace('/[^a-z0-9]/i', '-', $str);
$str = preg_replace('/-+/', '-', $str);
$str = preg_replace('/-$|^-/', '', $str);
return $str;
} | [
"public",
"static",
"function",
"slug",
"(",
"$",
"str",
")",
"{",
"$",
"str",
"=",
"strtolower",
"(",
"$",
"str",
")",
";",
"$",
"str",
"=",
"preg_replace",
"(",
"'/[^a-z0-9]/i'",
",",
"'-'",
",",
"$",
"str",
")",
";",
"$",
"str",
"=",
"preg_replace",
"(",
"'/-+/'",
",",
"'-'",
",",
"$",
"str",
")",
";",
"$",
"str",
"=",
"preg_replace",
"(",
"'/-$|^-/'",
",",
"''",
",",
"$",
"str",
")",
";",
"return",
"$",
"str",
";",
"}"
] | Create a slug out of the given string.
Non-alphanumeric characters are converted to hyphens.
@param string $str
@return string | [
"Create",
"a",
"slug",
"out",
"of",
"the",
"given",
"string",
"."
] | 99a6066f96899c15145eff80bb3ad3e97ff24c29 | https://github.com/flarum/core/blob/99a6066f96899c15145eff80bb3ad3e97ff24c29/src/Util/Str.php#L24-L32 | train |
briannesbitt/Carbon | src/Carbon/Traits/Date.php | Date.autoDetectTimeZone | protected function autoDetectTimeZone($object, $originalObject = null)
{
/** @var CarbonTimeZone $timezone */
$timezone = CarbonTimeZone::instance($object);
if ($timezone && is_int($originalObject ?: $object)) {
$timezone = $timezone->toRegionTimeZone($this);
}
return $timezone;
} | php | protected function autoDetectTimeZone($object, $originalObject = null)
{
/** @var CarbonTimeZone $timezone */
$timezone = CarbonTimeZone::instance($object);
if ($timezone && is_int($originalObject ?: $object)) {
$timezone = $timezone->toRegionTimeZone($this);
}
return $timezone;
} | [
"protected",
"function",
"autoDetectTimeZone",
"(",
"$",
"object",
",",
"$",
"originalObject",
"=",
"null",
")",
"{",
"/** @var CarbonTimeZone $timezone */",
"$",
"timezone",
"=",
"CarbonTimeZone",
"::",
"instance",
"(",
"$",
"object",
")",
";",
"if",
"(",
"$",
"timezone",
"&&",
"is_int",
"(",
"$",
"originalObject",
"?",
":",
"$",
"object",
")",
")",
"{",
"$",
"timezone",
"=",
"$",
"timezone",
"->",
"toRegionTimeZone",
"(",
"$",
"this",
")",
";",
"}",
"return",
"$",
"timezone",
";",
"}"
] | Creates a DateTimeZone from a string, DateTimeZone or integer offset then convert it as region timezone
if integer.
@param \DateTimeZone|string|int|null $object
@param \DateTimeZone|string|int|null $originalObject if different
@throws \InvalidArgumentException
@return CarbonTimeZone|false | [
"Creates",
"a",
"DateTimeZone",
"from",
"a",
"string",
"DateTimeZone",
"or",
"integer",
"offset",
"then",
"convert",
"it",
"as",
"region",
"timezone",
"if",
"integer",
"."
] | 3f227330a10b48e5a27b74b12d972d787d5a78b3 | https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Date.php#L608-L617 | train |
briannesbitt/Carbon | src/Carbon/Traits/Date.php | Date.resolveCarbon | protected function resolveCarbon($date = null)
{
if (!$date) {
return $this->nowWithSameTz();
}
if (is_string($date)) {
return static::parse($date, $this->getTimezone());
}
static::expectDateTime($date, ['null', 'string']);
return $date instanceof self ? $date : static::instance($date);
} | php | protected function resolveCarbon($date = null)
{
if (!$date) {
return $this->nowWithSameTz();
}
if (is_string($date)) {
return static::parse($date, $this->getTimezone());
}
static::expectDateTime($date, ['null', 'string']);
return $date instanceof self ? $date : static::instance($date);
} | [
"protected",
"function",
"resolveCarbon",
"(",
"$",
"date",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"date",
")",
"{",
"return",
"$",
"this",
"->",
"nowWithSameTz",
"(",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"date",
")",
")",
"{",
"return",
"static",
"::",
"parse",
"(",
"$",
"date",
",",
"$",
"this",
"->",
"getTimezone",
"(",
")",
")",
";",
"}",
"static",
"::",
"expectDateTime",
"(",
"$",
"date",
",",
"[",
"'null'",
",",
"'string'",
"]",
")",
";",
"return",
"$",
"date",
"instanceof",
"self",
"?",
"$",
"date",
":",
"static",
"::",
"instance",
"(",
"$",
"date",
")",
";",
"}"
] | Return the Carbon instance passed through, a now instance in the same timezone
if null given or parse the input if string given.
@param \Carbon\Carbon|\DateTimeInterface|string|null $date
@return static|CarbonInterface | [
"Return",
"the",
"Carbon",
"instance",
"passed",
"through",
"a",
"now",
"instance",
"in",
"the",
"same",
"timezone",
"if",
"null",
"given",
"or",
"parse",
"the",
"input",
"if",
"string",
"given",
"."
] | 3f227330a10b48e5a27b74b12d972d787d5a78b3 | https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Date.php#L717-L730 | train |
briannesbitt/Carbon | src/Carbon/Traits/Date.php | Date.addUnitNoOverflow | public function addUnitNoOverflow($valueUnit, $value, $overflowUnit)
{
return $this->setUnitNoOverflow($valueUnit, $this->$valueUnit + $value, $overflowUnit);
} | php | public function addUnitNoOverflow($valueUnit, $value, $overflowUnit)
{
return $this->setUnitNoOverflow($valueUnit, $this->$valueUnit + $value, $overflowUnit);
} | [
"public",
"function",
"addUnitNoOverflow",
"(",
"$",
"valueUnit",
",",
"$",
"value",
",",
"$",
"overflowUnit",
")",
"{",
"return",
"$",
"this",
"->",
"setUnitNoOverflow",
"(",
"$",
"valueUnit",
",",
"$",
"this",
"->",
"$",
"valueUnit",
"+",
"$",
"value",
",",
"$",
"overflowUnit",
")",
";",
"}"
] | Add any unit to a new value without overflowing current other unit given.
@param string $valueUnit unit name to modify
@param int $value amount to add to the input unit
@param string $overflowUnit unit name to not overflow
@return static|CarbonInterface | [
"Add",
"any",
"unit",
"to",
"a",
"new",
"value",
"without",
"overflowing",
"current",
"other",
"unit",
"given",
"."
] | 3f227330a10b48e5a27b74b12d972d787d5a78b3 | https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Date.php#L1299-L1302 | train |
briannesbitt/Carbon | src/Carbon/Traits/Date.php | Date.subUnitNoOverflow | public function subUnitNoOverflow($valueUnit, $value, $overflowUnit)
{
return $this->setUnitNoOverflow($valueUnit, $this->$valueUnit - $value, $overflowUnit);
} | php | public function subUnitNoOverflow($valueUnit, $value, $overflowUnit)
{
return $this->setUnitNoOverflow($valueUnit, $this->$valueUnit - $value, $overflowUnit);
} | [
"public",
"function",
"subUnitNoOverflow",
"(",
"$",
"valueUnit",
",",
"$",
"value",
",",
"$",
"overflowUnit",
")",
"{",
"return",
"$",
"this",
"->",
"setUnitNoOverflow",
"(",
"$",
"valueUnit",
",",
"$",
"this",
"->",
"$",
"valueUnit",
"-",
"$",
"value",
",",
"$",
"overflowUnit",
")",
";",
"}"
] | Subtract any unit to a new value without overflowing current other unit given.
@param string $valueUnit unit name to modify
@param int $value amount to subtract to the input unit
@param string $overflowUnit unit name to not overflow
@return static|CarbonInterface | [
"Subtract",
"any",
"unit",
"to",
"a",
"new",
"value",
"without",
"overflowing",
"current",
"other",
"unit",
"given",
"."
] | 3f227330a10b48e5a27b74b12d972d787d5a78b3 | https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Date.php#L1313-L1316 | train |
briannesbitt/Carbon | src/Carbon/Traits/Date.php | Date.utcOffset | public function utcOffset(int $offset = null)
{
if (func_num_args() < 1) {
return $this->offsetMinutes;
}
return $this->setTimezone(static::safeCreateDateTimeZone($offset / static::MINUTES_PER_HOUR));
} | php | public function utcOffset(int $offset = null)
{
if (func_num_args() < 1) {
return $this->offsetMinutes;
}
return $this->setTimezone(static::safeCreateDateTimeZone($offset / static::MINUTES_PER_HOUR));
} | [
"public",
"function",
"utcOffset",
"(",
"int",
"$",
"offset",
"=",
"null",
")",
"{",
"if",
"(",
"func_num_args",
"(",
")",
"<",
"1",
")",
"{",
"return",
"$",
"this",
"->",
"offsetMinutes",
";",
"}",
"return",
"$",
"this",
"->",
"setTimezone",
"(",
"static",
"::",
"safeCreateDateTimeZone",
"(",
"$",
"offset",
"/",
"static",
"::",
"MINUTES_PER_HOUR",
")",
")",
";",
"}"
] | Returns the minutes offset to UTC if no arguments passed, else set the timezone with given minutes shift passed.
@param int|null $offset
@return int|static|CarbonInterface | [
"Returns",
"the",
"minutes",
"offset",
"to",
"UTC",
"if",
"no",
"arguments",
"passed",
"else",
"set",
"the",
"timezone",
"with",
"given",
"minutes",
"shift",
"passed",
"."
] | 3f227330a10b48e5a27b74b12d972d787d5a78b3 | https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Date.php#L1325-L1332 | train |
briannesbitt/Carbon | src/Carbon/Traits/Date.php | Date.setTimezone | public function setTimezone($value)
{
/** @var static $date */
$date = parent::setTimezone(static::safeCreateDateTimeZone($value));
// https://bugs.php.net/bug.php?id=72338
// just workaround on this bug
$date->getTimestamp();
return $date;
} | php | public function setTimezone($value)
{
/** @var static $date */
$date = parent::setTimezone(static::safeCreateDateTimeZone($value));
// https://bugs.php.net/bug.php?id=72338
// just workaround on this bug
$date->getTimestamp();
return $date;
} | [
"public",
"function",
"setTimezone",
"(",
"$",
"value",
")",
"{",
"/** @var static $date */",
"$",
"date",
"=",
"parent",
"::",
"setTimezone",
"(",
"static",
"::",
"safeCreateDateTimeZone",
"(",
"$",
"value",
")",
")",
";",
"// https://bugs.php.net/bug.php?id=72338",
"// just workaround on this bug",
"$",
"date",
"->",
"getTimestamp",
"(",
")",
";",
"return",
"$",
"date",
";",
"}"
] | Set the instance's timezone from a string or object.
@param \DateTimeZone|string $value
@return static|CarbonInterface | [
"Set",
"the",
"instance",
"s",
"timezone",
"from",
"a",
"string",
"or",
"object",
"."
] | 3f227330a10b48e5a27b74b12d972d787d5a78b3 | https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Date.php#L1403-L1412 | train |
briannesbitt/Carbon | src/Carbon/Traits/Date.php | Date.setTimeFrom | public function setTimeFrom($date = null)
{
$date = $this->resolveCarbon($date);
return $this->setTime($date->hour, $date->minute, $date->second, $date->microsecond);
} | php | public function setTimeFrom($date = null)
{
$date = $this->resolveCarbon($date);
return $this->setTime($date->hour, $date->minute, $date->second, $date->microsecond);
} | [
"public",
"function",
"setTimeFrom",
"(",
"$",
"date",
"=",
"null",
")",
"{",
"$",
"date",
"=",
"$",
"this",
"->",
"resolveCarbon",
"(",
"$",
"date",
")",
";",
"return",
"$",
"this",
"->",
"setTime",
"(",
"$",
"date",
"->",
"hour",
",",
"$",
"date",
"->",
"minute",
",",
"$",
"date",
"->",
"second",
",",
"$",
"date",
"->",
"microsecond",
")",
";",
"}"
] | Set the hour, minute, second and microseconds for this instance to that of the passed instance.
@param \Carbon\Carbon|\DateTimeInterface $date now if null
@return static | [
"Set",
"the",
"hour",
"minute",
"second",
"and",
"microseconds",
"for",
"this",
"instance",
"to",
"that",
"of",
"the",
"passed",
"instance",
"."
] | 3f227330a10b48e5a27b74b12d972d787d5a78b3 | https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Date.php#L1460-L1465 | train |
briannesbitt/Carbon | src/Carbon/Traits/Date.php | Date.setDateTimeFrom | public function setDateTimeFrom($date = null)
{
$date = $this->resolveCarbon($date);
return $this->modify($date->rawFormat('Y-m-d H:i:s.u'));
} | php | public function setDateTimeFrom($date = null)
{
$date = $this->resolveCarbon($date);
return $this->modify($date->rawFormat('Y-m-d H:i:s.u'));
} | [
"public",
"function",
"setDateTimeFrom",
"(",
"$",
"date",
"=",
"null",
")",
"{",
"$",
"date",
"=",
"$",
"this",
"->",
"resolveCarbon",
"(",
"$",
"date",
")",
";",
"return",
"$",
"this",
"->",
"modify",
"(",
"$",
"date",
"->",
"rawFormat",
"(",
"'Y-m-d H:i:s.u'",
")",
")",
";",
"}"
] | Set the date and time for this instance to that of the passed instance.
@param \Carbon\Carbon|\DateTimeInterface $date
@return static | [
"Set",
"the",
"date",
"and",
"time",
"for",
"this",
"instance",
"to",
"that",
"of",
"the",
"passed",
"instance",
"."
] | 3f227330a10b48e5a27b74b12d972d787d5a78b3 | https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Date.php#L1474-L1479 | train |
briannesbitt/Carbon | src/Carbon/Traits/Date.php | Date.hasRelativeKeywords | public static function hasRelativeKeywords($time)
{
if (strtotime($time) === false) {
return false;
}
$date1 = new DateTime('2000-01-01T00:00:00Z');
$date1->modify($time);
$date2 = new DateTime('2001-12-25T00:00:00Z');
$date2->modify($time);
return $date1 != $date2;
} | php | public static function hasRelativeKeywords($time)
{
if (strtotime($time) === false) {
return false;
}
$date1 = new DateTime('2000-01-01T00:00:00Z');
$date1->modify($time);
$date2 = new DateTime('2001-12-25T00:00:00Z');
$date2->modify($time);
return $date1 != $date2;
} | [
"public",
"static",
"function",
"hasRelativeKeywords",
"(",
"$",
"time",
")",
"{",
"if",
"(",
"strtotime",
"(",
"$",
"time",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"$",
"date1",
"=",
"new",
"DateTime",
"(",
"'2000-01-01T00:00:00Z'",
")",
";",
"$",
"date1",
"->",
"modify",
"(",
"$",
"time",
")",
";",
"$",
"date2",
"=",
"new",
"DateTime",
"(",
"'2001-12-25T00:00:00Z'",
")",
";",
"$",
"date2",
"->",
"modify",
"(",
"$",
"time",
")",
";",
"return",
"$",
"date1",
"!=",
"$",
"date2",
";",
"}"
] | Determine if a time string will produce a relative date.
@param string $time
@return bool true if time match a relative date, false if absolute or invalid time string | [
"Determine",
"if",
"a",
"time",
"string",
"will",
"produce",
"a",
"relative",
"date",
"."
] | 3f227330a10b48e5a27b74b12d972d787d5a78b3 | https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Date.php#L1598-L1610 | train |
briannesbitt/Carbon | src/Carbon/Traits/Date.php | Date.getIsoFormats | public function getIsoFormats($locale = null)
{
return [
'LT' => $this->getTranslationMessage('formats.LT', $locale, 'h:mm A'),
'LTS' => $this->getTranslationMessage('formats.LTS', $locale, 'h:mm:ss A'),
'L' => $this->getTranslationMessage('formats.L', $locale, 'MM/DD/YYYY'),
'LL' => $this->getTranslationMessage('formats.LL', $locale, 'MMMM D, YYYY'),
'LLL' => $this->getTranslationMessage('formats.LLL', $locale, 'MMMM D, YYYY h:mm A'),
'LLLL' => $this->getTranslationMessage('formats.LLLL', $locale, 'dddd, MMMM D, YYYY h:mm A'),
];
} | php | public function getIsoFormats($locale = null)
{
return [
'LT' => $this->getTranslationMessage('formats.LT', $locale, 'h:mm A'),
'LTS' => $this->getTranslationMessage('formats.LTS', $locale, 'h:mm:ss A'),
'L' => $this->getTranslationMessage('formats.L', $locale, 'MM/DD/YYYY'),
'LL' => $this->getTranslationMessage('formats.LL', $locale, 'MMMM D, YYYY'),
'LLL' => $this->getTranslationMessage('formats.LLL', $locale, 'MMMM D, YYYY h:mm A'),
'LLLL' => $this->getTranslationMessage('formats.LLLL', $locale, 'dddd, MMMM D, YYYY h:mm A'),
];
} | [
"public",
"function",
"getIsoFormats",
"(",
"$",
"locale",
"=",
"null",
")",
"{",
"return",
"[",
"'LT'",
"=>",
"$",
"this",
"->",
"getTranslationMessage",
"(",
"'formats.LT'",
",",
"$",
"locale",
",",
"'h:mm A'",
")",
",",
"'LTS'",
"=>",
"$",
"this",
"->",
"getTranslationMessage",
"(",
"'formats.LTS'",
",",
"$",
"locale",
",",
"'h:mm:ss A'",
")",
",",
"'L'",
"=>",
"$",
"this",
"->",
"getTranslationMessage",
"(",
"'formats.L'",
",",
"$",
"locale",
",",
"'MM/DD/YYYY'",
")",
",",
"'LL'",
"=>",
"$",
"this",
"->",
"getTranslationMessage",
"(",
"'formats.LL'",
",",
"$",
"locale",
",",
"'MMMM D, YYYY'",
")",
",",
"'LLL'",
"=>",
"$",
"this",
"->",
"getTranslationMessage",
"(",
"'formats.LLL'",
",",
"$",
"locale",
",",
"'MMMM D, YYYY h:mm A'",
")",
",",
"'LLLL'",
"=>",
"$",
"this",
"->",
"getTranslationMessage",
"(",
"'formats.LLLL'",
",",
"$",
"locale",
",",
"'dddd, MMMM D, YYYY h:mm A'",
")",
",",
"]",
";",
"}"
] | Returns list of locale formats for ISO formatting.
@param string|null $locale current locale used if null
@return array | [
"Returns",
"list",
"of",
"locale",
"formats",
"for",
"ISO",
"formatting",
"."
] | 3f227330a10b48e5a27b74b12d972d787d5a78b3 | https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Date.php#L1656-L1666 | train |
briannesbitt/Carbon | src/Carbon/Traits/Date.php | Date.getCalendarFormats | public function getCalendarFormats($locale = null)
{
return [
'sameDay' => $this->getTranslationMessage('calendar.sameDay', $locale, '[Today at] LT'),
'nextDay' => $this->getTranslationMessage('calendar.nextDay', $locale, '[Tomorrow at] LT'),
'nextWeek' => $this->getTranslationMessage('calendar.nextWeek', $locale, 'dddd [at] LT'),
'lastDay' => $this->getTranslationMessage('calendar.lastDay', $locale, '[Yesterday at] LT'),
'lastWeek' => $this->getTranslationMessage('calendar.lastWeek', $locale, '[Last] dddd [at] LT'),
'sameElse' => $this->getTranslationMessage('calendar.sameElse', $locale, 'L'),
];
} | php | public function getCalendarFormats($locale = null)
{
return [
'sameDay' => $this->getTranslationMessage('calendar.sameDay', $locale, '[Today at] LT'),
'nextDay' => $this->getTranslationMessage('calendar.nextDay', $locale, '[Tomorrow at] LT'),
'nextWeek' => $this->getTranslationMessage('calendar.nextWeek', $locale, 'dddd [at] LT'),
'lastDay' => $this->getTranslationMessage('calendar.lastDay', $locale, '[Yesterday at] LT'),
'lastWeek' => $this->getTranslationMessage('calendar.lastWeek', $locale, '[Last] dddd [at] LT'),
'sameElse' => $this->getTranslationMessage('calendar.sameElse', $locale, 'L'),
];
} | [
"public",
"function",
"getCalendarFormats",
"(",
"$",
"locale",
"=",
"null",
")",
"{",
"return",
"[",
"'sameDay'",
"=>",
"$",
"this",
"->",
"getTranslationMessage",
"(",
"'calendar.sameDay'",
",",
"$",
"locale",
",",
"'[Today at] LT'",
")",
",",
"'nextDay'",
"=>",
"$",
"this",
"->",
"getTranslationMessage",
"(",
"'calendar.nextDay'",
",",
"$",
"locale",
",",
"'[Tomorrow at] LT'",
")",
",",
"'nextWeek'",
"=>",
"$",
"this",
"->",
"getTranslationMessage",
"(",
"'calendar.nextWeek'",
",",
"$",
"locale",
",",
"'dddd [at] LT'",
")",
",",
"'lastDay'",
"=>",
"$",
"this",
"->",
"getTranslationMessage",
"(",
"'calendar.lastDay'",
",",
"$",
"locale",
",",
"'[Yesterday at] LT'",
")",
",",
"'lastWeek'",
"=>",
"$",
"this",
"->",
"getTranslationMessage",
"(",
"'calendar.lastWeek'",
",",
"$",
"locale",
",",
"'[Last] dddd [at] LT'",
")",
",",
"'sameElse'",
"=>",
"$",
"this",
"->",
"getTranslationMessage",
"(",
"'calendar.sameElse'",
",",
"$",
"locale",
",",
"'L'",
")",
",",
"]",
";",
"}"
] | Returns list of calendar formats for ISO formatting.
@param string|null $locale current locale used if null
@return array | [
"Returns",
"list",
"of",
"calendar",
"formats",
"for",
"ISO",
"formatting",
"."
] | 3f227330a10b48e5a27b74b12d972d787d5a78b3 | https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Date.php#L1675-L1685 | train |
briannesbitt/Carbon | src/Carbon/Traits/Date.php | Date.getPaddedUnit | public function getPaddedUnit($unit, $length = 2, $padString = '0', $padType = STR_PAD_LEFT)
{
return ($this->$unit < 0 ? '-' : '').str_pad(abs($this->$unit), $length, $padString, $padType);
} | php | public function getPaddedUnit($unit, $length = 2, $padString = '0', $padType = STR_PAD_LEFT)
{
return ($this->$unit < 0 ? '-' : '').str_pad(abs($this->$unit), $length, $padString, $padType);
} | [
"public",
"function",
"getPaddedUnit",
"(",
"$",
"unit",
",",
"$",
"length",
"=",
"2",
",",
"$",
"padString",
"=",
"'0'",
",",
"$",
"padType",
"=",
"STR_PAD_LEFT",
")",
"{",
"return",
"(",
"$",
"this",
"->",
"$",
"unit",
"<",
"0",
"?",
"'-'",
":",
"''",
")",
".",
"str_pad",
"(",
"abs",
"(",
"$",
"this",
"->",
"$",
"unit",
")",
",",
"$",
"length",
",",
"$",
"padString",
",",
"$",
"padType",
")",
";",
"}"
] | Returns a unit of the instance padded with 0 by default or any other string if specified.
@param string $unit Carbon unit name
@param int $length Length of the output (2 by default)
@param string $padString String to use for padding ("0" by default)
@param int $padType Side(s) to pad (STR_PAD_LEFT by default)
@return string | [
"Returns",
"a",
"unit",
"of",
"the",
"instance",
"padded",
"with",
"0",
"by",
"default",
"or",
"any",
"other",
"string",
"if",
"specified",
"."
] | 3f227330a10b48e5a27b74b12d972d787d5a78b3 | https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Date.php#L1826-L1829 | train |
briannesbitt/Carbon | src/Carbon/Traits/Date.php | Date.ordinal | public function ordinal(string $key, string $period = null): string
{
$number = $this->$key;
$result = $this->translate('ordinal', [
':number' => $number,
':period' => $period,
]);
return strval($result === 'ordinal' ? $number : $result);
} | php | public function ordinal(string $key, string $period = null): string
{
$number = $this->$key;
$result = $this->translate('ordinal', [
':number' => $number,
':period' => $period,
]);
return strval($result === 'ordinal' ? $number : $result);
} | [
"public",
"function",
"ordinal",
"(",
"string",
"$",
"key",
",",
"string",
"$",
"period",
"=",
"null",
")",
":",
"string",
"{",
"$",
"number",
"=",
"$",
"this",
"->",
"$",
"key",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"translate",
"(",
"'ordinal'",
",",
"[",
"':number'",
"=>",
"$",
"number",
",",
"':period'",
"=>",
"$",
"period",
",",
"]",
")",
";",
"return",
"strval",
"(",
"$",
"result",
"===",
"'ordinal'",
"?",
"$",
"number",
":",
"$",
"result",
")",
";",
"}"
] | Return a property with its ordinal.
@param string $key
@param string|null $period
@return string | [
"Return",
"a",
"property",
"with",
"its",
"ordinal",
"."
] | 3f227330a10b48e5a27b74b12d972d787d5a78b3 | https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Date.php#L1839-L1848 | train |
briannesbitt/Carbon | src/Carbon/Traits/Date.php | Date.meridiem | public function meridiem(bool $isLower = false): string
{
$hour = $this->hour;
$index = $hour < 12 ? 0 : 1;
if ($isLower) {
$key = 'meridiem.'.($index + 2);
$result = $this->translate($key);
if ($result !== $key) {
return $result;
}
}
$key = "meridiem.$index";
$result = $this->translate($key);
if ($result === $key) {
$result = $this->translate('meridiem', [
':hour' => $this->hour,
':minute' => $this->minute,
':isLower' => $isLower,
]);
if ($result === 'meridiem') {
return $isLower ? $this->latinMeridiem : $this->latinUpperMeridiem;
}
} elseif ($isLower) {
$result = mb_strtolower($result);
}
return $result;
} | php | public function meridiem(bool $isLower = false): string
{
$hour = $this->hour;
$index = $hour < 12 ? 0 : 1;
if ($isLower) {
$key = 'meridiem.'.($index + 2);
$result = $this->translate($key);
if ($result !== $key) {
return $result;
}
}
$key = "meridiem.$index";
$result = $this->translate($key);
if ($result === $key) {
$result = $this->translate('meridiem', [
':hour' => $this->hour,
':minute' => $this->minute,
':isLower' => $isLower,
]);
if ($result === 'meridiem') {
return $isLower ? $this->latinMeridiem : $this->latinUpperMeridiem;
}
} elseif ($isLower) {
$result = mb_strtolower($result);
}
return $result;
} | [
"public",
"function",
"meridiem",
"(",
"bool",
"$",
"isLower",
"=",
"false",
")",
":",
"string",
"{",
"$",
"hour",
"=",
"$",
"this",
"->",
"hour",
";",
"$",
"index",
"=",
"$",
"hour",
"<",
"12",
"?",
"0",
":",
"1",
";",
"if",
"(",
"$",
"isLower",
")",
"{",
"$",
"key",
"=",
"'meridiem.'",
".",
"(",
"$",
"index",
"+",
"2",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"translate",
"(",
"$",
"key",
")",
";",
"if",
"(",
"$",
"result",
"!==",
"$",
"key",
")",
"{",
"return",
"$",
"result",
";",
"}",
"}",
"$",
"key",
"=",
"\"meridiem.$index\"",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"translate",
"(",
"$",
"key",
")",
";",
"if",
"(",
"$",
"result",
"===",
"$",
"key",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"translate",
"(",
"'meridiem'",
",",
"[",
"':hour'",
"=>",
"$",
"this",
"->",
"hour",
",",
"':minute'",
"=>",
"$",
"this",
"->",
"minute",
",",
"':isLower'",
"=>",
"$",
"isLower",
",",
"]",
")",
";",
"if",
"(",
"$",
"result",
"===",
"'meridiem'",
")",
"{",
"return",
"$",
"isLower",
"?",
"$",
"this",
"->",
"latinMeridiem",
":",
"$",
"this",
"->",
"latinUpperMeridiem",
";",
"}",
"}",
"elseif",
"(",
"$",
"isLower",
")",
"{",
"$",
"result",
"=",
"mb_strtolower",
"(",
"$",
"result",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Return the meridiem of the current time in the current locale.
@param bool $isLower if true, returns lowercase variant if available in the current locale.
@return string | [
"Return",
"the",
"meridiem",
"of",
"the",
"current",
"time",
"in",
"the",
"current",
"locale",
"."
] | 3f227330a10b48e5a27b74b12d972d787d5a78b3 | https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Date.php#L1857-L1888 | train |
briannesbitt/Carbon | src/Carbon/Traits/Date.php | Date.getAltNumber | public function getAltNumber(string $key): string
{
$number = strlen($key) > 1 ? $this->$key : $this->rawFormat('h');
$translateKey = "alt_numbers.$number";
$symbol = $this->translate($translateKey);
if ($symbol !== $translateKey) {
return $symbol;
}
if ($number > 99 && $this->translate('alt_numbers.99') !== 'alt_numbers.99') {
$start = '';
foreach ([10000, 1000, 100] as $exp) {
$key = "alt_numbers_pow.$exp";
if ($number >= $exp && $number < $exp * 10 && ($pow = $this->translate($key)) !== $key) {
$unit = floor($number / $exp);
$number -= $unit * $exp;
$start .= ($unit > 1 ? $this->translate("alt_numbers.$unit") : '').$pow;
}
}
$result = '';
while ($number) {
$chunk = $number % 100;
$result = $this->translate("alt_numbers.$chunk").$result;
$number = floor($number / 100);
}
return "$start$result";
}
if ($number > 9 && $this->translate('alt_numbers.9') !== 'alt_numbers.9') {
$result = '';
while ($number) {
$chunk = $number % 10;
$result = $this->translate("alt_numbers.$chunk").$result;
$number = floor($number / 10);
}
return $result;
}
return $number;
} | php | public function getAltNumber(string $key): string
{
$number = strlen($key) > 1 ? $this->$key : $this->rawFormat('h');
$translateKey = "alt_numbers.$number";
$symbol = $this->translate($translateKey);
if ($symbol !== $translateKey) {
return $symbol;
}
if ($number > 99 && $this->translate('alt_numbers.99') !== 'alt_numbers.99') {
$start = '';
foreach ([10000, 1000, 100] as $exp) {
$key = "alt_numbers_pow.$exp";
if ($number >= $exp && $number < $exp * 10 && ($pow = $this->translate($key)) !== $key) {
$unit = floor($number / $exp);
$number -= $unit * $exp;
$start .= ($unit > 1 ? $this->translate("alt_numbers.$unit") : '').$pow;
}
}
$result = '';
while ($number) {
$chunk = $number % 100;
$result = $this->translate("alt_numbers.$chunk").$result;
$number = floor($number / 100);
}
return "$start$result";
}
if ($number > 9 && $this->translate('alt_numbers.9') !== 'alt_numbers.9') {
$result = '';
while ($number) {
$chunk = $number % 10;
$result = $this->translate("alt_numbers.$chunk").$result;
$number = floor($number / 10);
}
return $result;
}
return $number;
} | [
"public",
"function",
"getAltNumber",
"(",
"string",
"$",
"key",
")",
":",
"string",
"{",
"$",
"number",
"=",
"strlen",
"(",
"$",
"key",
")",
">",
"1",
"?",
"$",
"this",
"->",
"$",
"key",
":",
"$",
"this",
"->",
"rawFormat",
"(",
"'h'",
")",
";",
"$",
"translateKey",
"=",
"\"alt_numbers.$number\"",
";",
"$",
"symbol",
"=",
"$",
"this",
"->",
"translate",
"(",
"$",
"translateKey",
")",
";",
"if",
"(",
"$",
"symbol",
"!==",
"$",
"translateKey",
")",
"{",
"return",
"$",
"symbol",
";",
"}",
"if",
"(",
"$",
"number",
">",
"99",
"&&",
"$",
"this",
"->",
"translate",
"(",
"'alt_numbers.99'",
")",
"!==",
"'alt_numbers.99'",
")",
"{",
"$",
"start",
"=",
"''",
";",
"foreach",
"(",
"[",
"10000",
",",
"1000",
",",
"100",
"]",
"as",
"$",
"exp",
")",
"{",
"$",
"key",
"=",
"\"alt_numbers_pow.$exp\"",
";",
"if",
"(",
"$",
"number",
">=",
"$",
"exp",
"&&",
"$",
"number",
"<",
"$",
"exp",
"*",
"10",
"&&",
"(",
"$",
"pow",
"=",
"$",
"this",
"->",
"translate",
"(",
"$",
"key",
")",
")",
"!==",
"$",
"key",
")",
"{",
"$",
"unit",
"=",
"floor",
"(",
"$",
"number",
"/",
"$",
"exp",
")",
";",
"$",
"number",
"-=",
"$",
"unit",
"*",
"$",
"exp",
";",
"$",
"start",
".=",
"(",
"$",
"unit",
">",
"1",
"?",
"$",
"this",
"->",
"translate",
"(",
"\"alt_numbers.$unit\"",
")",
":",
"''",
")",
".",
"$",
"pow",
";",
"}",
"}",
"$",
"result",
"=",
"''",
";",
"while",
"(",
"$",
"number",
")",
"{",
"$",
"chunk",
"=",
"$",
"number",
"%",
"100",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"translate",
"(",
"\"alt_numbers.$chunk\"",
")",
".",
"$",
"result",
";",
"$",
"number",
"=",
"floor",
"(",
"$",
"number",
"/",
"100",
")",
";",
"}",
"return",
"\"$start$result\"",
";",
"}",
"if",
"(",
"$",
"number",
">",
"9",
"&&",
"$",
"this",
"->",
"translate",
"(",
"'alt_numbers.9'",
")",
"!==",
"'alt_numbers.9'",
")",
"{",
"$",
"result",
"=",
"''",
";",
"while",
"(",
"$",
"number",
")",
"{",
"$",
"chunk",
"=",
"$",
"number",
"%",
"10",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"translate",
"(",
"\"alt_numbers.$chunk\"",
")",
".",
"$",
"result",
";",
"$",
"number",
"=",
"floor",
"(",
"$",
"number",
"/",
"10",
")",
";",
"}",
"return",
"$",
"result",
";",
"}",
"return",
"$",
"number",
";",
"}"
] | Returns the alternative number if available in the current locale.
@param string $key date property
@return string | [
"Returns",
"the",
"alternative",
"number",
"if",
"available",
"in",
"the",
"current",
"locale",
"."
] | 3f227330a10b48e5a27b74b12d972d787d5a78b3 | https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Date.php#L1897-L1939 | train |
briannesbitt/Carbon | src/Carbon/Traits/Date.php | Date.setUnit | public function setUnit($unit, $value = null)
{
$unit = static::singularUnit($unit);
$dateUnits = ['year', 'month', 'day'];
if (in_array($unit, $dateUnits)) {
return $this->setDate(...array_map(function ($name) use ($unit, $value) {
return $name === $unit ? $value : $this->$name;
}, $dateUnits));
}
$units = ['hour', 'minute', 'second', 'micro'];
if ($unit === 'millisecond' || $unit === 'milli') {
$value *= 1000;
$unit = 'micro';
} elseif ($unit === 'microsecond') {
$unit = 'micro';
}
return $this->setTime(...array_map(function ($name) use ($unit, $value) {
return $name === $unit ? $value : $this->$name;
}, $units));
} | php | public function setUnit($unit, $value = null)
{
$unit = static::singularUnit($unit);
$dateUnits = ['year', 'month', 'day'];
if (in_array($unit, $dateUnits)) {
return $this->setDate(...array_map(function ($name) use ($unit, $value) {
return $name === $unit ? $value : $this->$name;
}, $dateUnits));
}
$units = ['hour', 'minute', 'second', 'micro'];
if ($unit === 'millisecond' || $unit === 'milli') {
$value *= 1000;
$unit = 'micro';
} elseif ($unit === 'microsecond') {
$unit = 'micro';
}
return $this->setTime(...array_map(function ($name) use ($unit, $value) {
return $name === $unit ? $value : $this->$name;
}, $units));
} | [
"public",
"function",
"setUnit",
"(",
"$",
"unit",
",",
"$",
"value",
"=",
"null",
")",
"{",
"$",
"unit",
"=",
"static",
"::",
"singularUnit",
"(",
"$",
"unit",
")",
";",
"$",
"dateUnits",
"=",
"[",
"'year'",
",",
"'month'",
",",
"'day'",
"]",
";",
"if",
"(",
"in_array",
"(",
"$",
"unit",
",",
"$",
"dateUnits",
")",
")",
"{",
"return",
"$",
"this",
"->",
"setDate",
"(",
"...",
"array_map",
"(",
"function",
"(",
"$",
"name",
")",
"use",
"(",
"$",
"unit",
",",
"$",
"value",
")",
"{",
"return",
"$",
"name",
"===",
"$",
"unit",
"?",
"$",
"value",
":",
"$",
"this",
"->",
"$",
"name",
";",
"}",
",",
"$",
"dateUnits",
")",
")",
";",
"}",
"$",
"units",
"=",
"[",
"'hour'",
",",
"'minute'",
",",
"'second'",
",",
"'micro'",
"]",
";",
"if",
"(",
"$",
"unit",
"===",
"'millisecond'",
"||",
"$",
"unit",
"===",
"'milli'",
")",
"{",
"$",
"value",
"*=",
"1000",
";",
"$",
"unit",
"=",
"'micro'",
";",
"}",
"elseif",
"(",
"$",
"unit",
"===",
"'microsecond'",
")",
"{",
"$",
"unit",
"=",
"'micro'",
";",
"}",
"return",
"$",
"this",
"->",
"setTime",
"(",
"...",
"array_map",
"(",
"function",
"(",
"$",
"name",
")",
"use",
"(",
"$",
"unit",
",",
"$",
"value",
")",
"{",
"return",
"$",
"name",
"===",
"$",
"unit",
"?",
"$",
"value",
":",
"$",
"this",
"->",
"$",
"name",
";",
"}",
",",
"$",
"units",
")",
")",
";",
"}"
] | Set specified unit to new given value.
@param string $unit year, month, day, hour, minute, second or microsecond
@param int $value new value for given unit
@return static | [
"Set",
"specified",
"unit",
"to",
"new",
"given",
"value",
"."
] | 3f227330a10b48e5a27b74b12d972d787d5a78b3 | https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Date.php#L2248-L2269 | train |
briannesbitt/Carbon | src/Carbon/Traits/Localization.php | Localization.setFallbackLocale | public static function setFallbackLocale($locale)
{
$translator = static::getTranslator();
if (method_exists($translator, 'setFallbackLocales')) {
$translator->setFallbackLocales([$locale]);
if ($translator instanceof Translator) {
$preferredLocale = $translator->getLocale();
$translator->setMessages($preferredLocale, array_replace_recursive(
$translator->getMessages()[$locale] ?? [],
Translator::get($locale)->getMessages()[$locale] ?? [],
$translator->getMessages($preferredLocale)
));
}
}
} | php | public static function setFallbackLocale($locale)
{
$translator = static::getTranslator();
if (method_exists($translator, 'setFallbackLocales')) {
$translator->setFallbackLocales([$locale]);
if ($translator instanceof Translator) {
$preferredLocale = $translator->getLocale();
$translator->setMessages($preferredLocale, array_replace_recursive(
$translator->getMessages()[$locale] ?? [],
Translator::get($locale)->getMessages()[$locale] ?? [],
$translator->getMessages($preferredLocale)
));
}
}
} | [
"public",
"static",
"function",
"setFallbackLocale",
"(",
"$",
"locale",
")",
"{",
"$",
"translator",
"=",
"static",
"::",
"getTranslator",
"(",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"translator",
",",
"'setFallbackLocales'",
")",
")",
"{",
"$",
"translator",
"->",
"setFallbackLocales",
"(",
"[",
"$",
"locale",
"]",
")",
";",
"if",
"(",
"$",
"translator",
"instanceof",
"Translator",
")",
"{",
"$",
"preferredLocale",
"=",
"$",
"translator",
"->",
"getLocale",
"(",
")",
";",
"$",
"translator",
"->",
"setMessages",
"(",
"$",
"preferredLocale",
",",
"array_replace_recursive",
"(",
"$",
"translator",
"->",
"getMessages",
"(",
")",
"[",
"$",
"locale",
"]",
"??",
"[",
"]",
",",
"Translator",
"::",
"get",
"(",
"$",
"locale",
")",
"->",
"getMessages",
"(",
")",
"[",
"$",
"locale",
"]",
"??",
"[",
"]",
",",
"$",
"translator",
"->",
"getMessages",
"(",
"$",
"preferredLocale",
")",
")",
")",
";",
"}",
"}",
"}"
] | Set the fallback locale.
@see https://symfony.com/doc/current/components/translation.html#fallback-locales
@param string $locale | [
"Set",
"the",
"fallback",
"locale",
"."
] | 3f227330a10b48e5a27b74b12d972d787d5a78b3 | https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Localization.php#L418-L434 | train |
briannesbitt/Carbon | src/Carbon/Traits/Localization.php | Localization.localeHasShortUnits | public static function localeHasShortUnits($locale)
{
return static::executeWithLocale($locale, function ($newLocale, TranslatorInterface $translator) {
return $newLocale &&
(
($y = static::translateWith($translator, 'y')) !== 'y' &&
$y !== static::translateWith($translator, 'year')
) || (
($y = static::translateWith($translator, 'd')) !== 'd' &&
$y !== static::translateWith($translator, 'day')
) || (
($y = static::translateWith($translator, 'h')) !== 'h' &&
$y !== static::translateWith($translator, 'hour')
);
});
} | php | public static function localeHasShortUnits($locale)
{
return static::executeWithLocale($locale, function ($newLocale, TranslatorInterface $translator) {
return $newLocale &&
(
($y = static::translateWith($translator, 'y')) !== 'y' &&
$y !== static::translateWith($translator, 'year')
) || (
($y = static::translateWith($translator, 'd')) !== 'd' &&
$y !== static::translateWith($translator, 'day')
) || (
($y = static::translateWith($translator, 'h')) !== 'h' &&
$y !== static::translateWith($translator, 'hour')
);
});
} | [
"public",
"static",
"function",
"localeHasShortUnits",
"(",
"$",
"locale",
")",
"{",
"return",
"static",
"::",
"executeWithLocale",
"(",
"$",
"locale",
",",
"function",
"(",
"$",
"newLocale",
",",
"TranslatorInterface",
"$",
"translator",
")",
"{",
"return",
"$",
"newLocale",
"&&",
"(",
"(",
"$",
"y",
"=",
"static",
"::",
"translateWith",
"(",
"$",
"translator",
",",
"'y'",
")",
")",
"!==",
"'y'",
"&&",
"$",
"y",
"!==",
"static",
"::",
"translateWith",
"(",
"$",
"translator",
",",
"'year'",
")",
")",
"||",
"(",
"(",
"$",
"y",
"=",
"static",
"::",
"translateWith",
"(",
"$",
"translator",
",",
"'d'",
")",
")",
"!==",
"'d'",
"&&",
"$",
"y",
"!==",
"static",
"::",
"translateWith",
"(",
"$",
"translator",
",",
"'day'",
")",
")",
"||",
"(",
"(",
"$",
"y",
"=",
"static",
"::",
"translateWith",
"(",
"$",
"translator",
",",
"'h'",
")",
")",
"!==",
"'h'",
"&&",
"$",
"y",
"!==",
"static",
"::",
"translateWith",
"(",
"$",
"translator",
",",
"'hour'",
")",
")",
";",
"}",
")",
";",
"}"
] | Returns true if the given locale is internally supported and has short-units support.
Support is considered enabled if either year, day or hour has a short variant translated.
@param string $locale locale ex. en
@return bool | [
"Returns",
"true",
"if",
"the",
"given",
"locale",
"is",
"internally",
"supported",
"and",
"has",
"short",
"-",
"units",
"support",
".",
"Support",
"is",
"considered",
"enabled",
"if",
"either",
"year",
"day",
"or",
"hour",
"has",
"a",
"short",
"variant",
"translated",
"."
] | 3f227330a10b48e5a27b74b12d972d787d5a78b3 | https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Localization.php#L480-L495 | train |
briannesbitt/Carbon | src/Carbon/Traits/Localization.php | Localization.getAvailableLocalesInfo | public static function getAvailableLocalesInfo()
{
$languages = [];
foreach (static::getAvailableLocales() as $id) {
$languages[$id] = new Language($id);
}
return $languages;
} | php | public static function getAvailableLocalesInfo()
{
$languages = [];
foreach (static::getAvailableLocales() as $id) {
$languages[$id] = new Language($id);
}
return $languages;
} | [
"public",
"static",
"function",
"getAvailableLocalesInfo",
"(",
")",
"{",
"$",
"languages",
"=",
"[",
"]",
";",
"foreach",
"(",
"static",
"::",
"getAvailableLocales",
"(",
")",
"as",
"$",
"id",
")",
"{",
"$",
"languages",
"[",
"$",
"id",
"]",
"=",
"new",
"Language",
"(",
"$",
"id",
")",
";",
"}",
"return",
"$",
"languages",
";",
"}"
] | Returns list of Language object for each available locale. This object allow you to get the ISO name, native
name, region and variant of the locale.
@return Language[] | [
"Returns",
"list",
"of",
"Language",
"object",
"for",
"each",
"available",
"locale",
".",
"This",
"object",
"allow",
"you",
"to",
"get",
"the",
"ISO",
"name",
"native",
"name",
"region",
"and",
"variant",
"of",
"the",
"locale",
"."
] | 3f227330a10b48e5a27b74b12d972d787d5a78b3 | https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Localization.php#L601-L609 | train |
briannesbitt/Carbon | src/Carbon/Traits/Creator.php | Creator.createFromDate | public static function createFromDate($year = null, $month = null, $day = null, $tz = null)
{
return static::create($year, $month, $day, null, null, null, $tz);
} | php | public static function createFromDate($year = null, $month = null, $day = null, $tz = null)
{
return static::create($year, $month, $day, null, null, null, $tz);
} | [
"public",
"static",
"function",
"createFromDate",
"(",
"$",
"year",
"=",
"null",
",",
"$",
"month",
"=",
"null",
",",
"$",
"day",
"=",
"null",
",",
"$",
"tz",
"=",
"null",
")",
"{",
"return",
"static",
"::",
"create",
"(",
"$",
"year",
",",
"$",
"month",
",",
"$",
"day",
",",
"null",
",",
"null",
",",
"null",
",",
"$",
"tz",
")",
";",
"}"
] | Create a Carbon instance from just a date. The time portion is set to now.
@param int|null $year
@param int|null $month
@param int|null $day
@param \DateTimeZone|string|null $tz
@throws \InvalidArgumentException
@return static|CarbonInterface | [
"Create",
"a",
"Carbon",
"instance",
"from",
"just",
"a",
"date",
".",
"The",
"time",
"portion",
"is",
"set",
"to",
"now",
"."
] | 3f227330a10b48e5a27b74b12d972d787d5a78b3 | https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Creator.php#L393-L396 | train |
briannesbitt/Carbon | src/Carbon/Traits/Creator.php | Creator.createMidnightDate | public static function createMidnightDate($year = null, $month = null, $day = null, $tz = null)
{
return static::create($year, $month, $day, 0, 0, 0, $tz);
} | php | public static function createMidnightDate($year = null, $month = null, $day = null, $tz = null)
{
return static::create($year, $month, $day, 0, 0, 0, $tz);
} | [
"public",
"static",
"function",
"createMidnightDate",
"(",
"$",
"year",
"=",
"null",
",",
"$",
"month",
"=",
"null",
",",
"$",
"day",
"=",
"null",
",",
"$",
"tz",
"=",
"null",
")",
"{",
"return",
"static",
"::",
"create",
"(",
"$",
"year",
",",
"$",
"month",
",",
"$",
"day",
",",
"0",
",",
"0",
",",
"0",
",",
"$",
"tz",
")",
";",
"}"
] | Create a Carbon instance from just a date. The time portion is set to midnight.
@param int|null $year
@param int|null $month
@param int|null $day
@param \DateTimeZone|string|null $tz
@return static|CarbonInterface | [
"Create",
"a",
"Carbon",
"instance",
"from",
"just",
"a",
"date",
".",
"The",
"time",
"portion",
"is",
"set",
"to",
"midnight",
"."
] | 3f227330a10b48e5a27b74b12d972d787d5a78b3 | https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Creator.php#L408-L411 | train |
briannesbitt/Carbon | src/Carbon/Traits/Creator.php | Creator.createFromLocaleFormat | public static function createFromLocaleFormat($format, $locale, $time, $tz = null)
{
return static::rawCreateFromFormat($format, static::translateTimeString($time, $locale, 'en'), $tz);
} | php | public static function createFromLocaleFormat($format, $locale, $time, $tz = null)
{
return static::rawCreateFromFormat($format, static::translateTimeString($time, $locale, 'en'), $tz);
} | [
"public",
"static",
"function",
"createFromLocaleFormat",
"(",
"$",
"format",
",",
"$",
"locale",
",",
"$",
"time",
",",
"$",
"tz",
"=",
"null",
")",
"{",
"return",
"static",
"::",
"rawCreateFromFormat",
"(",
"$",
"format",
",",
"static",
"::",
"translateTimeString",
"(",
"$",
"time",
",",
"$",
"locale",
",",
"'en'",
")",
",",
"$",
"tz",
")",
";",
"}"
] | Create a Carbon instance from a specific format and a string in a given language.
@param string $format Datetime format
@param string $locale
@param string $time
@param \DateTimeZone|string|false|null $tz
@throws InvalidArgumentException
@return static|CarbonInterface|false | [
"Create",
"a",
"Carbon",
"instance",
"from",
"a",
"specific",
"format",
"and",
"a",
"string",
"in",
"a",
"given",
"language",
"."
] | 3f227330a10b48e5a27b74b12d972d787d5a78b3 | https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Creator.php#L723-L726 | train |
briannesbitt/Carbon | src/Carbon/Traits/Creator.php | Creator.createFromLocaleIsoFormat | public static function createFromLocaleIsoFormat($format, $locale, $time, $tz = null)
{
$time = static::translateTimeString($time, $locale, 'en', CarbonInterface::TRANSLATE_MONTHS | CarbonInterface::TRANSLATE_DAYS | CarbonInterface::TRANSLATE_MERIDIEM);
return static::createFromIsoFormat($format, $time, $tz, $locale);
} | php | public static function createFromLocaleIsoFormat($format, $locale, $time, $tz = null)
{
$time = static::translateTimeString($time, $locale, 'en', CarbonInterface::TRANSLATE_MONTHS | CarbonInterface::TRANSLATE_DAYS | CarbonInterface::TRANSLATE_MERIDIEM);
return static::createFromIsoFormat($format, $time, $tz, $locale);
} | [
"public",
"static",
"function",
"createFromLocaleIsoFormat",
"(",
"$",
"format",
",",
"$",
"locale",
",",
"$",
"time",
",",
"$",
"tz",
"=",
"null",
")",
"{",
"$",
"time",
"=",
"static",
"::",
"translateTimeString",
"(",
"$",
"time",
",",
"$",
"locale",
",",
"'en'",
",",
"CarbonInterface",
"::",
"TRANSLATE_MONTHS",
"|",
"CarbonInterface",
"::",
"TRANSLATE_DAYS",
"|",
"CarbonInterface",
"::",
"TRANSLATE_MERIDIEM",
")",
";",
"return",
"static",
"::",
"createFromIsoFormat",
"(",
"$",
"format",
",",
"$",
"time",
",",
"$",
"tz",
",",
"$",
"locale",
")",
";",
"}"
] | Create a Carbon instance from a specific ISO format and a string in a given language.
@param string $format Datetime ISO format
@param string $locale
@param string $time
@param \DateTimeZone|string|false|null $tz
@throws InvalidArgumentException
@return static|CarbonInterface|false | [
"Create",
"a",
"Carbon",
"instance",
"from",
"a",
"specific",
"ISO",
"format",
"and",
"a",
"string",
"in",
"a",
"given",
"language",
"."
] | 3f227330a10b48e5a27b74b12d972d787d5a78b3 | https://github.com/briannesbitt/Carbon/blob/3f227330a10b48e5a27b74b12d972d787d5a78b3/src/Carbon/Traits/Creator.php#L740-L745 | train |