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
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
Tustin/psn-php
src/Api/Session.php
Session.titleType
public function titleType() : int { if (!isset($this->session->npTitleDetail)) return SessionType::Unknown; switch ($this->session->npTitleType) { case 'party': return SessionType::Party; case 'game': return sessionType::Game; default: return SessionType::Unknown; } }
php
public function titleType() : int { if (!isset($this->session->npTitleDetail)) return SessionType::Unknown; switch ($this->session->npTitleType) { case 'party': return SessionType::Party; case 'game': return sessionType::Game; default: return SessionType::Unknown; } }
[ "public", "function", "titleType", "(", ")", ":", "int", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "session", "->", "npTitleDetail", ")", ")", "return", "SessionType", "::", "Unknown", ";", "switch", "(", "$", "this", "->", "session", "->",...
Get SessionType of Session. @return integer SessionType flag.
[ "Get", "SessionType", "of", "Session", "." ]
2f640b8790efa8f8570bc7e6a69dae115148c999
https://github.com/Tustin/psn-php/blob/2f640b8790efa8f8570bc7e6a69dae115148c999/src/Api/Session.php#L142-L154
train
Tustin/psn-php
src/Api/User.php
User.info
public function info() : object { if ($this->profile === null) { $this->profile = $this->get(sprintf(self::USERS_ENDPOINT . 'profile2', $this->onlineIdParameter), [ 'fields' => 'npId,onlineId,accountId,avatarUrls,plus,aboutMe,languagesUsed,trophySummary(@default,progress,earnedTrophies),isOfficiallyVerified,personalDetail(@default,profilePictureUrls),personalDetailSharing,personalDetailSharingRequestMessageFlag,primaryOnlineStatus,presences(@titleInfo,hasBroadcastData),friendRelation,requestMessageFlag,blocking,mutualFriendsCount,following,followerCount,friendsCount,followingUsersCount&avatarSizes=m,xl&profilePictureSizes=m,xl&languagesUsedLanguageSet=set3&psVitaTitleIcon=circled&titleIconSize=s' ])->profile; } return $this->profile; }
php
public function info() : object { if ($this->profile === null) { $this->profile = $this->get(sprintf(self::USERS_ENDPOINT . 'profile2', $this->onlineIdParameter), [ 'fields' => 'npId,onlineId,accountId,avatarUrls,plus,aboutMe,languagesUsed,trophySummary(@default,progress,earnedTrophies),isOfficiallyVerified,personalDetail(@default,profilePictureUrls),personalDetailSharing,personalDetailSharingRequestMessageFlag,primaryOnlineStatus,presences(@titleInfo,hasBroadcastData),friendRelation,requestMessageFlag,blocking,mutualFriendsCount,following,followerCount,friendsCount,followingUsersCount&avatarSizes=m,xl&profilePictureSizes=m,xl&languagesUsedLanguageSet=set3&psVitaTitleIcon=circled&titleIconSize=s' ])->profile; } return $this->profile; }
[ "public", "function", "info", "(", ")", ":", "object", "{", "if", "(", "$", "this", "->", "profile", "===", "null", ")", "{", "$", "this", "->", "profile", "=", "$", "this", "->", "get", "(", "sprintf", "(", "self", "::", "USERS_ENDPOINT", ".", "'p...
Gets profile information. @return object
[ "Gets", "profile", "information", "." ]
2f640b8790efa8f8570bc7e6a69dae115148c999
https://github.com/Tustin/psn-php/blob/2f640b8790efa8f8570bc7e6a69dae115148c999/src/Api/User.php#L75-L83
train
Tustin/psn-php
src/Api/User.php
User.lastOnlineDate
public function lastOnlineDate() : ?\DateTime { $isOnline = $this->info()->presences[0]->onlineStatus == "online"; // They're online now, so just return the current DateTime. if ($isOnline) return new \DateTime(); // If they don't have a DateTime, just return null. // This can happen if the User object was created using the onlineId string and not the profile data. // Sony only provides lastOnlineDate on the 'friends/profiles2' endpoint and not the individual userinfo endpoint. // This can be a TODO if in the future Sony decides to make that property available for that endpoint. // - Tustin 9/29/2018 if (!isset($this->info()->presences[0]->lastOnlineDate)) return null; // I guess it's possible for lastOnlineDate to not exist, but that seems very unlikely. return new \DateTime($this->info()->presences[0]->lastOnlineDate); }
php
public function lastOnlineDate() : ?\DateTime { $isOnline = $this->info()->presences[0]->onlineStatus == "online"; // They're online now, so just return the current DateTime. if ($isOnline) return new \DateTime(); // If they don't have a DateTime, just return null. // This can happen if the User object was created using the onlineId string and not the profile data. // Sony only provides lastOnlineDate on the 'friends/profiles2' endpoint and not the individual userinfo endpoint. // This can be a TODO if in the future Sony decides to make that property available for that endpoint. // - Tustin 9/29/2018 if (!isset($this->info()->presences[0]->lastOnlineDate)) return null; // I guess it's possible for lastOnlineDate to not exist, but that seems very unlikely. return new \DateTime($this->info()->presences[0]->lastOnlineDate); }
[ "public", "function", "lastOnlineDate", "(", ")", ":", "?", "\\", "DateTime", "{", "$", "isOnline", "=", "$", "this", "->", "info", "(", ")", "->", "presences", "[", "0", "]", "->", "onlineStatus", "==", "\"online\"", ";", "// They're online now, so just ret...
Gets the last online date for the User. @return \DateTime|null
[ "Gets", "the", "last", "online", "date", "for", "the", "User", "." ]
2f640b8790efa8f8570bc7e6a69dae115148c999
https://github.com/Tustin/psn-php/blob/2f640b8790efa8f8570bc7e6a69dae115148c999/src/Api/User.php#L160-L176
train
Tustin/psn-php
src/Api/User.php
User.add
public function add(string $requestMessage = null) : void { if ($this->onlineIdParameter() === 'me') return; $data = ($requestMessage === null) ? new \stdClass() : [ "requestMessage" => $requestMessage ]; $this->postJson(sprintf(self::USERS_ENDPOINT . 'friendList/%s', $this->client->onlineId(), $this->onlineId()), $data); }
php
public function add(string $requestMessage = null) : void { if ($this->onlineIdParameter() === 'me') return; $data = ($requestMessage === null) ? new \stdClass() : [ "requestMessage" => $requestMessage ]; $this->postJson(sprintf(self::USERS_ENDPOINT . 'friendList/%s', $this->client->onlineId(), $this->onlineId()), $data); }
[ "public", "function", "add", "(", "string", "$", "requestMessage", "=", "null", ")", ":", "void", "{", "if", "(", "$", "this", "->", "onlineIdParameter", "(", ")", "===", "'me'", ")", "return", ";", "$", "data", "=", "(", "$", "requestMessage", "===", ...
Add the User to friends list. Will not do anything if called on the logged in user. @param string $requestMessage Message to send with the request. @return void
[ "Add", "the", "User", "to", "friends", "list", "." ]
2f640b8790efa8f8570bc7e6a69dae115148c999
https://github.com/Tustin/psn-php/blob/2f640b8790efa8f8570bc7e6a69dae115148c999/src/Api/User.php#L186-L195
train
Tustin/psn-php
src/Api/User.php
User.remove
public function remove() : void { if ($this->onlineIdParameter() === 'me') return; $this->delete(sprintf(self::USERS_ENDPOINT . 'friendList/%s', $this->client->onlineId(), $this->onlineId())); }
php
public function remove() : void { if ($this->onlineIdParameter() === 'me') return; $this->delete(sprintf(self::USERS_ENDPOINT . 'friendList/%s', $this->client->onlineId(), $this->onlineId())); }
[ "public", "function", "remove", "(", ")", ":", "void", "{", "if", "(", "$", "this", "->", "onlineIdParameter", "(", ")", "===", "'me'", ")", "return", ";", "$", "this", "->", "delete", "(", "sprintf", "(", "self", "::", "USERS_ENDPOINT", ".", "'friendL...
Remove the User from friends list. Will not do anything if called on the logged in user. @return void
[ "Remove", "the", "User", "from", "friends", "list", "." ]
2f640b8790efa8f8570bc7e6a69dae115148c999
https://github.com/Tustin/psn-php/blob/2f640b8790efa8f8570bc7e6a69dae115148c999/src/Api/User.php#L204-L209
train
Tustin/psn-php
src/Api/User.php
User.block
public function block() : void { if ($this->onlineIdParameter() === 'me') return; $this->post(sprintf(self::USERS_ENDPOINT . 'blockList/%s', $this->client->onlineId(), $this->onlineId()), null); }
php
public function block() : void { if ($this->onlineIdParameter() === 'me') return; $this->post(sprintf(self::USERS_ENDPOINT . 'blockList/%s', $this->client->onlineId(), $this->onlineId()), null); }
[ "public", "function", "block", "(", ")", ":", "void", "{", "if", "(", "$", "this", "->", "onlineIdParameter", "(", ")", "===", "'me'", ")", "return", ";", "$", "this", "->", "post", "(", "sprintf", "(", "self", "::", "USERS_ENDPOINT", ".", "'blockList/...
Block the User. @return void
[ "Block", "the", "User", "." ]
2f640b8790efa8f8570bc7e6a69dae115148c999
https://github.com/Tustin/psn-php/blob/2f640b8790efa8f8570bc7e6a69dae115148c999/src/Api/User.php#L216-L221
train
Tustin/psn-php
src/Api/User.php
User.friends
public function friends($sort = 'onlineStatus', $offset = 0, $limit = 36) : array { $result = []; $friends = $this->get(sprintf(self::USERS_ENDPOINT . 'friends/profiles2', $this->onlineIdParameter()), [ 'fields' => 'onlineId,accountId,avatarUrls,plus,trophySummary(@default),isOfficiallyVerified,personalDetail(@default,profilePictureUrls),presences(@titleInfo,hasBroadcastData,lastOnlineDate),presences(@titleInfo),friendRelation,consoleAvailability', 'offset' => $offset, 'limit' => $limit, 'profilePictureSizes' => 'm', 'avatarSizes' => 'm', 'titleIconSize' => 's', 'sort' => $sort ]); foreach ($friends->profiles as $friend) { $result[] = new self($this->client, $friend); } return $result; }
php
public function friends($sort = 'onlineStatus', $offset = 0, $limit = 36) : array { $result = []; $friends = $this->get(sprintf(self::USERS_ENDPOINT . 'friends/profiles2', $this->onlineIdParameter()), [ 'fields' => 'onlineId,accountId,avatarUrls,plus,trophySummary(@default),isOfficiallyVerified,personalDetail(@default,profilePictureUrls),presences(@titleInfo,hasBroadcastData,lastOnlineDate),presences(@titleInfo),friendRelation,consoleAvailability', 'offset' => $offset, 'limit' => $limit, 'profilePictureSizes' => 'm', 'avatarSizes' => 'm', 'titleIconSize' => 's', 'sort' => $sort ]); foreach ($friends->profiles as $friend) { $result[] = new self($this->client, $friend); } return $result; }
[ "public", "function", "friends", "(", "$", "sort", "=", "'onlineStatus'", ",", "$", "offset", "=", "0", ",", "$", "limit", "=", "36", ")", ":", "array", "{", "$", "result", "=", "[", "]", ";", "$", "friends", "=", "$", "this", "->", "get", "(", ...
Gets the User's friends. @param string $sort Order to return friends in (onlineStatus | name-onlineId) @param integer $offset Where to start @param integer $limit How many friends to return @return array Array of Api\User.
[ "Gets", "the", "User", "s", "friends", "." ]
2f640b8790efa8f8570bc7e6a69dae115148c999
https://github.com/Tustin/psn-php/blob/2f640b8790efa8f8570bc7e6a69dae115148c999/src/Api/User.php#L245-L264
train
Tustin/psn-php
src/Api/User.php
User.games
public function games($limit = 100) : array { $returnGames = []; $games = $this->get(sprintf(Game::GAME_ENDPOINT . 'users/%s/titles', $this->onlineIdParameter()), [ 'type' => 'played', 'app' => 'richProfile', // ?? 'sort' => '-lastPlayedDate', 'limit' => $limit, 'iw' => 240, // Size of game image width 'ih' => 240 // Size of game image height ]); if ($games->size === 0) return $returnGames; foreach ($games->titles as $game) { $returnGames[] = new Game($this->client, $game->titleId, $this); } return $returnGames; }
php
public function games($limit = 100) : array { $returnGames = []; $games = $this->get(sprintf(Game::GAME_ENDPOINT . 'users/%s/titles', $this->onlineIdParameter()), [ 'type' => 'played', 'app' => 'richProfile', // ?? 'sort' => '-lastPlayedDate', 'limit' => $limit, 'iw' => 240, // Size of game image width 'ih' => 240 // Size of game image height ]); if ($games->size === 0) return $returnGames; foreach ($games->titles as $game) { $returnGames[] = new Game($this->client, $game->titleId, $this); } return $returnGames; }
[ "public", "function", "games", "(", "$", "limit", "=", "100", ")", ":", "array", "{", "$", "returnGames", "=", "[", "]", ";", "$", "games", "=", "$", "this", "->", "get", "(", "sprintf", "(", "Game", "::", "GAME_ENDPOINT", ".", "'users/%s/titles'", "...
Gets the User's Games played. @return array Array of Api\Game.
[ "Gets", "the", "User", "s", "Games", "played", "." ]
2f640b8790efa8f8570bc7e6a69dae115148c999
https://github.com/Tustin/psn-php/blob/2f640b8790efa8f8570bc7e6a69dae115148c999/src/Api/User.php#L271-L291
train
Tustin/psn-php
src/Api/User.php
User.sendMessage
public function sendMessage(string $message) : ?Message { $thread = $this->messageGroup(); if ($thread === null) return null; return $thread->sendMessage($message); }
php
public function sendMessage(string $message) : ?Message { $thread = $this->messageGroup(); if ($thread === null) return null; return $thread->sendMessage($message); }
[ "public", "function", "sendMessage", "(", "string", "$", "message", ")", ":", "?", "Message", "{", "$", "thread", "=", "$", "this", "->", "messageGroup", "(", ")", ";", "if", "(", "$", "thread", "===", "null", ")", "return", "null", ";", "return", "$...
Send a Message to the User. @param string $message Message to send. @return Message|null
[ "Send", "a", "Message", "to", "the", "User", "." ]
2f640b8790efa8f8570bc7e6a69dae115148c999
https://github.com/Tustin/psn-php/blob/2f640b8790efa8f8570bc7e6a69dae115148c999/src/Api/User.php#L299-L306
train
Tustin/psn-php
src/Api/User.php
User.sendImage
public function sendImage(string $imageContents) : ?Message { $thread = $this->messageGroup(); if ($thread === null) return null; return $thread->sendImage($imageContents); }
php
public function sendImage(string $imageContents) : ?Message { $thread = $this->messageGroup(); if ($thread === null) return null; return $thread->sendImage($imageContents); }
[ "public", "function", "sendImage", "(", "string", "$", "imageContents", ")", ":", "?", "Message", "{", "$", "thread", "=", "$", "this", "->", "messageGroup", "(", ")", ";", "if", "(", "$", "thread", "===", "null", ")", "return", "null", ";", "return", ...
Send an image Message to the User. @param string $imageContents Raw bytes of the image. @return Message|null
[ "Send", "an", "image", "Message", "to", "the", "User", "." ]
2f640b8790efa8f8570bc7e6a69dae115148c999
https://github.com/Tustin/psn-php/blob/2f640b8790efa8f8570bc7e6a69dae115148c999/src/Api/User.php#L314-L321
train
Tustin/psn-php
src/Api/User.php
User.sendAudio
public function sendAudio(string $audioContents, int $audioLengthSeconds) : ?Message { $thread = $this->messageGroup(); if ($thread === null) return null; return $thread->sendAudio($audioContents, $audioLengthSeconds); }
php
public function sendAudio(string $audioContents, int $audioLengthSeconds) : ?Message { $thread = $this->messageGroup(); if ($thread === null) return null; return $thread->sendAudio($audioContents, $audioLengthSeconds); }
[ "public", "function", "sendAudio", "(", "string", "$", "audioContents", ",", "int", "$", "audioLengthSeconds", ")", ":", "?", "Message", "{", "$", "thread", "=", "$", "this", "->", "messageGroup", "(", ")", ";", "if", "(", "$", "thread", "===", "null", ...
Send an audio Message to the User. @param string $audioContents Raw bytes of the audio. @param integer $audioLengthSeconds Length of audio file (in seconds). @return Message|null
[ "Send", "an", "audio", "Message", "to", "the", "User", "." ]
2f640b8790efa8f8570bc7e6a69dae115148c999
https://github.com/Tustin/psn-php/blob/2f640b8790efa8f8570bc7e6a69dae115148c999/src/Api/User.php#L330-L337
train
Tustin/psn-php
src/Api/User.php
User.messageThreads
public function messageThreads() : array { $returnThreads = []; $threads = $this->get(MessageThread::MESSAGE_THREAD_ENDPOINT . 'users/me/threadIds', [ 'withOnlineIds' => $this->onlineId() ]); if (empty($threads->threadIds)) return []; foreach ($threads->threadIds as $thread) { $returnThreads[] = new MessageThread($this->client, $thread->threadId); } return $returnThreads; }
php
public function messageThreads() : array { $returnThreads = []; $threads = $this->get(MessageThread::MESSAGE_THREAD_ENDPOINT . 'users/me/threadIds', [ 'withOnlineIds' => $this->onlineId() ]); if (empty($threads->threadIds)) return []; foreach ($threads->threadIds as $thread) { $returnThreads[] = new MessageThread($this->client, $thread->threadId); } return $returnThreads; }
[ "public", "function", "messageThreads", "(", ")", ":", "array", "{", "$", "returnThreads", "=", "[", "]", ";", "$", "threads", "=", "$", "this", "->", "get", "(", "MessageThread", "::", "MESSAGE_THREAD_ENDPOINT", ".", "'users/me/threadIds'", ",", "[", "'with...
Get all MessageThreads with the User. @return array Array of Api\MessageThread.
[ "Get", "all", "MessageThreads", "with", "the", "User", "." ]
2f640b8790efa8f8570bc7e6a69dae115148c999
https://github.com/Tustin/psn-php/blob/2f640b8790efa8f8570bc7e6a69dae115148c999/src/Api/User.php#L344-L359
train
Tustin/psn-php
src/Api/User.php
User.privateMessageThread
public function privateMessageThread() : ?MessageThread { $threads = $this->messageThreads(); if (count($threads) === 0) return null; foreach ($threads as $thread) { if ($thread->memberCount() === 2) { return $thread; } } return null; }
php
public function privateMessageThread() : ?MessageThread { $threads = $this->messageThreads(); if (count($threads) === 0) return null; foreach ($threads as $thread) { if ($thread->memberCount() === 2) { return $thread; } } return null; }
[ "public", "function", "privateMessageThread", "(", ")", ":", "?", "MessageThread", "{", "$", "threads", "=", "$", "this", "->", "messageThreads", "(", ")", ";", "if", "(", "count", "(", "$", "threads", ")", "===", "0", ")", "return", "null", ";", "fore...
Get MessageThread with just the logged in account and the current User. @return MessageThread|null
[ "Get", "MessageThread", "with", "just", "the", "logged", "in", "account", "and", "the", "current", "User", "." ]
2f640b8790efa8f8570bc7e6a69dae115148c999
https://github.com/Tustin/psn-php/blob/2f640b8790efa8f8570bc7e6a69dae115148c999/src/Api/User.php#L366-L379
train
Tustin/psn-php
src/Api/User.php
User.story
public function story(int $page = 0, bool $includeComments = true, int $offset = 0, int $blockSize = 10) : array { $returnActivity = []; $activity = $this->get(sprintf(Story::ACTIVITY_ENDPOINT . 'v2/users/%s/feed/%d', $this->onlineIdParameter, $page), [ 'includeComments' => $includeComments, 'offset' => $offset, 'blockSize' => $blockSize ]); foreach ($activity->feed as $story) { // Some stories might just be a collection of similiar stories (like trophy unlocks) // These stories can't be interacted with like other stories, so we need to grab the condensed stories if (isset($story->condensedStories)) { foreach ($story->condensedStories as $condensed) { $returnActivity[] = new Story($this->client, $condensed, $this); } } else { $returnActivity[] = new Story($this->client, $story, $this); } } return $returnActivity; }
php
public function story(int $page = 0, bool $includeComments = true, int $offset = 0, int $blockSize = 10) : array { $returnActivity = []; $activity = $this->get(sprintf(Story::ACTIVITY_ENDPOINT . 'v2/users/%s/feed/%d', $this->onlineIdParameter, $page), [ 'includeComments' => $includeComments, 'offset' => $offset, 'blockSize' => $blockSize ]); foreach ($activity->feed as $story) { // Some stories might just be a collection of similiar stories (like trophy unlocks) // These stories can't be interacted with like other stories, so we need to grab the condensed stories if (isset($story->condensedStories)) { foreach ($story->condensedStories as $condensed) { $returnActivity[] = new Story($this->client, $condensed, $this); } } else { $returnActivity[] = new Story($this->client, $story, $this); } } return $returnActivity; }
[ "public", "function", "story", "(", "int", "$", "page", "=", "0", ",", "bool", "$", "includeComments", "=", "true", ",", "int", "$", "offset", "=", "0", ",", "int", "$", "blockSize", "=", "10", ")", ":", "array", "{", "$", "returnActivity", "=", "[...
Gets the User's Activity. @return array Array of Api\Story
[ "Gets", "the", "User", "s", "Activity", "." ]
2f640b8790efa8f8570bc7e6a69dae115148c999
https://github.com/Tustin/psn-php/blob/2f640b8790efa8f8570bc7e6a69dae115148c999/src/Api/User.php#L410-L432
train
Tustin/psn-php
src/Api/User.php
User.communities
public function communities() : array { $returnCommunities = []; $communities = $this->get(Community::COMMUNITY_ENDPOINT . 'communities', [ 'fields' => 'backgroundImage,description,id,isCommon,members,name,profileImage,role,unreadMessageCount,sessions,timezoneUtcOffset,language,titleName', 'includeFields' => 'gameSessions,timezoneUtcOffset,parties', 'sort' => 'common', 'onlineId' => $this->onlineId() ]); if ($communities->size === 0) return $returnCommunities; foreach ($communities->communities as $community) { $returnCommunities[] = new Community($this->client, $community->id); } return $returnCommunities; }
php
public function communities() : array { $returnCommunities = []; $communities = $this->get(Community::COMMUNITY_ENDPOINT . 'communities', [ 'fields' => 'backgroundImage,description,id,isCommon,members,name,profileImage,role,unreadMessageCount,sessions,timezoneUtcOffset,language,titleName', 'includeFields' => 'gameSessions,timezoneUtcOffset,parties', 'sort' => 'common', 'onlineId' => $this->onlineId() ]); if ($communities->size === 0) return $returnCommunities; foreach ($communities->communities as $community) { $returnCommunities[] = new Community($this->client, $community->id); } return $returnCommunities; }
[ "public", "function", "communities", "(", ")", ":", "array", "{", "$", "returnCommunities", "=", "[", "]", ";", "$", "communities", "=", "$", "this", "->", "get", "(", "Community", "::", "COMMUNITY_ENDPOINT", ".", "'communities'", ",", "[", "'fields'", "=>...
Get all Communities the User is in. @return array Array of Api\Community.
[ "Get", "all", "Communities", "the", "User", "is", "in", "." ]
2f640b8790efa8f8570bc7e6a69dae115148c999
https://github.com/Tustin/psn-php/blob/2f640b8790efa8f8570bc7e6a69dae115148c999/src/Api/User.php#L439-L458
train
Tustin/psn-php
src/Api/User.php
User.filterSessions
private function filterSessions(int $type) : array { $sessions = $this->sessions(); $filteredSession = array_filter($sessions, function($session) use ($type) { if ($session->getTitleType() & $type) return $session; }); return $filteredSession; }
php
private function filterSessions(int $type) : array { $sessions = $this->sessions(); $filteredSession = array_filter($sessions, function($session) use ($type) { if ($session->getTitleType() & $type) return $session; }); return $filteredSession; }
[ "private", "function", "filterSessions", "(", "int", "$", "type", ")", ":", "array", "{", "$", "sessions", "=", "$", "this", "->", "sessions", "(", ")", ";", "$", "filteredSession", "=", "array_filter", "(", "$", "sessions", ",", "function", "(", "$", ...
Filter User's Sessions by SessionType flag. @param integer $type SessionType flag. @return array Array of Api\Session.
[ "Filter", "User", "s", "Sessions", "by", "SessionType", "flag", "." ]
2f640b8790efa8f8570bc7e6a69dae115148c999
https://github.com/Tustin/psn-php/blob/2f640b8790efa8f8570bc7e6a69dae115148c999/src/Api/User.php#L511-L520
train
Tustin/psn-php
src/Api/User.php
User.sessions
private function sessions() : array { if (!empty($sessions)) return $sessions; $returnSessions = []; $sessions = $this->get(sprintf(Session::SESSION_ENDPOINT, $this->onlineIdParameter), [ 'fields' => '@default,npTitleDetail,npTitleDetail.platform,sessionName,sessionCreateTimestamp,availablePlatforms,members,memberCount,sessionMaxUser', 'titleIconSize' => 's', 'npLanguage' => 'en' ]); if ($sessions->size === 0) return null; // Multiple sessions could be used if the user is in a party while playing a game. foreach ($sessions->sessions as $session) { $returnSessions[] = new Session($this->client, $session); } $sessions = $returnSessions; return $returnSessions; }
php
private function sessions() : array { if (!empty($sessions)) return $sessions; $returnSessions = []; $sessions = $this->get(sprintf(Session::SESSION_ENDPOINT, $this->onlineIdParameter), [ 'fields' => '@default,npTitleDetail,npTitleDetail.platform,sessionName,sessionCreateTimestamp,availablePlatforms,members,memberCount,sessionMaxUser', 'titleIconSize' => 's', 'npLanguage' => 'en' ]); if ($sessions->size === 0) return null; // Multiple sessions could be used if the user is in a party while playing a game. foreach ($sessions->sessions as $session) { $returnSessions[] = new Session($this->client, $session); } $sessions = $returnSessions; return $returnSessions; }
[ "private", "function", "sessions", "(", ")", ":", "array", "{", "if", "(", "!", "empty", "(", "$", "sessions", ")", ")", "return", "$", "sessions", ";", "$", "returnSessions", "=", "[", "]", ";", "$", "sessions", "=", "$", "this", "->", "get", "(",...
Gets all the User's active Sessions. @return array Array of Api\Session.
[ "Gets", "all", "the", "User", "s", "active", "Sessions", "." ]
2f640b8790efa8f8570bc7e6a69dae115148c999
https://github.com/Tustin/psn-php/blob/2f640b8790efa8f8570bc7e6a69dae115148c999/src/Api/User.php#L527-L549
train
ongr-io/ElasticsearchDSL
src/SearchEndpoint/SearchEndpointFactory.php
SearchEndpointFactory.get
public static function get($type) { if (!array_key_exists($type, self::$endpoints)) { throw new \RuntimeException('Endpoint does not exist.'); } return new self::$endpoints[$type](); }
php
public static function get($type) { if (!array_key_exists($type, self::$endpoints)) { throw new \RuntimeException('Endpoint does not exist.'); } return new self::$endpoints[$type](); }
[ "public", "static", "function", "get", "(", "$", "type", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "type", ",", "self", "::", "$", "endpoints", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Endpoint does not exist.'", ")", ...
Returns a search endpoint instance. @param string $type Type of endpoint. @return SearchEndpointInterface @throws \RuntimeException Endpoint does not exist.
[ "Returns", "a", "search", "endpoint", "instance", "." ]
197eeddacccf2195bd7a9e0572ef24bb50a700c8
https://github.com/ongr-io/ElasticsearchDSL/blob/197eeddacccf2195bd7a9e0572ef24bb50a700c8/src/SearchEndpoint/SearchEndpointFactory.php#L41-L48
train
ongr-io/ElasticsearchDSL
src/Query/Compound/BoolQuery.php
BoolQuery.add
public function add(BuilderInterface $query, $type = self::MUST, $key = null) { if (!in_array($type, [self::MUST, self::MUST_NOT, self::SHOULD, self::FILTER])) { throw new \UnexpectedValueException(sprintf('The bool operator %s is not supported', $type)); } if (!$key) { $key = bin2hex(random_bytes(30)); } $this->container[$type][$key] = $query; return $key; }
php
public function add(BuilderInterface $query, $type = self::MUST, $key = null) { if (!in_array($type, [self::MUST, self::MUST_NOT, self::SHOULD, self::FILTER])) { throw new \UnexpectedValueException(sprintf('The bool operator %s is not supported', $type)); } if (!$key) { $key = bin2hex(random_bytes(30)); } $this->container[$type][$key] = $query; return $key; }
[ "public", "function", "add", "(", "BuilderInterface", "$", "query", ",", "$", "type", "=", "self", "::", "MUST", ",", "$", "key", "=", "null", ")", "{", "if", "(", "!", "in_array", "(", "$", "type", ",", "[", "self", "::", "MUST", ",", "self", ":...
Add BuilderInterface object to bool operator. @param BuilderInterface $query Query add to the bool. @param string $type Bool type. Example: must, must_not, should. @param string $key Key that indicates a builder id. @return string Key of added builder. @throws \UnexpectedValueException
[ "Add", "BuilderInterface", "object", "to", "bool", "operator", "." ]
197eeddacccf2195bd7a9e0572ef24bb50a700c8
https://github.com/ongr-io/ElasticsearchDSL/blob/197eeddacccf2195bd7a9e0572ef24bb50a700c8/src/Query/Compound/BoolQuery.php#L81-L94
train
ongr-io/ElasticsearchDSL
src/Aggregation/Bucketing/RangeAggregation.php
RangeAggregation.removeRange
public function removeRange($from, $to) { foreach ($this->ranges as $key => $range) { if (array_diff_assoc(array_filter(['from' => $from, 'to' => $to]), $range) === []) { unset($this->ranges[$key]); return true; } } return false; }
php
public function removeRange($from, $to) { foreach ($this->ranges as $key => $range) { if (array_diff_assoc(array_filter(['from' => $from, 'to' => $to]), $range) === []) { unset($this->ranges[$key]); return true; } } return false; }
[ "public", "function", "removeRange", "(", "$", "from", ",", "$", "to", ")", "{", "foreach", "(", "$", "this", "->", "ranges", "as", "$", "key", "=>", "$", "range", ")", "{", "if", "(", "array_diff_assoc", "(", "array_filter", "(", "[", "'from'", "=>"...
Remove range from aggregation. Returns true on success. @param int|float|null $from @param int|float|null $to @return bool
[ "Remove", "range", "from", "aggregation", ".", "Returns", "true", "on", "success", "." ]
197eeddacccf2195bd7a9e0572ef24bb50a700c8
https://github.com/ongr-io/ElasticsearchDSL/blob/197eeddacccf2195bd7a9e0572ef24bb50a700c8/src/Aggregation/Bucketing/RangeAggregation.php#L110-L121
train
ongr-io/ElasticsearchDSL
src/Aggregation/Bucketing/RangeAggregation.php
RangeAggregation.removeRangeByKey
public function removeRangeByKey($key) { if ($this->keyed) { foreach ($this->ranges as $rangeKey => $range) { if (array_key_exists('key', $range) && $range['key'] === $key) { unset($this->ranges[$rangeKey]); return true; } } } return false; }
php
public function removeRangeByKey($key) { if ($this->keyed) { foreach ($this->ranges as $rangeKey => $range) { if (array_key_exists('key', $range) && $range['key'] === $key) { unset($this->ranges[$rangeKey]); return true; } } } return false; }
[ "public", "function", "removeRangeByKey", "(", "$", "key", ")", "{", "if", "(", "$", "this", "->", "keyed", ")", "{", "foreach", "(", "$", "this", "->", "ranges", "as", "$", "rangeKey", "=>", "$", "range", ")", "{", "if", "(", "array_key_exists", "("...
Removes range by key. @param string $key Range key. @return bool
[ "Removes", "range", "by", "key", "." ]
197eeddacccf2195bd7a9e0572ef24bb50a700c8
https://github.com/ongr-io/ElasticsearchDSL/blob/197eeddacccf2195bd7a9e0572ef24bb50a700c8/src/Aggregation/Bucketing/RangeAggregation.php#L130-L143
train
ongr-io/ElasticsearchDSL
src/BuilderBag.php
BuilderBag.add
public function add(BuilderInterface $builder) { if (method_exists($builder, 'getName')) { $name = $builder->getName(); } else { $name = bin2hex(random_bytes(30)); } $this->bag[$name] = $builder; return $name; }
php
public function add(BuilderInterface $builder) { if (method_exists($builder, 'getName')) { $name = $builder->getName(); } else { $name = bin2hex(random_bytes(30)); } $this->bag[$name] = $builder; return $name; }
[ "public", "function", "add", "(", "BuilderInterface", "$", "builder", ")", "{", "if", "(", "method_exists", "(", "$", "builder", ",", "'getName'", ")", ")", "{", "$", "name", "=", "$", "builder", "->", "getName", "(", ")", ";", "}", "else", "{", "$",...
Adds a builder. @param BuilderInterface $builder @return string
[ "Adds", "a", "builder", "." ]
197eeddacccf2195bd7a9e0572ef24bb50a700c8
https://github.com/ongr-io/ElasticsearchDSL/blob/197eeddacccf2195bd7a9e0572ef24bb50a700c8/src/BuilderBag.php#L41-L52
train
ongr-io/ElasticsearchDSL
src/BuilderBag.php
BuilderBag.all
public function all($type = null) { return array_filter( $this->bag, /** @var BuilderInterface $builder */ function (BuilderInterface $builder) use ($type) { return $type === null || $builder->getType() == $type; } ); }
php
public function all($type = null) { return array_filter( $this->bag, /** @var BuilderInterface $builder */ function (BuilderInterface $builder) use ($type) { return $type === null || $builder->getType() == $type; } ); }
[ "public", "function", "all", "(", "$", "type", "=", "null", ")", "{", "return", "array_filter", "(", "$", "this", "->", "bag", ",", "/** @var BuilderInterface $builder */", "function", "(", "BuilderInterface", "$", "builder", ")", "use", "(", "$", "type", ")...
Returns all builders contained. @param string|null $type Builder type. @return BuilderInterface[]
[ "Returns", "all", "builders", "contained", "." ]
197eeddacccf2195bd7a9e0572ef24bb50a700c8
https://github.com/ongr-io/ElasticsearchDSL/blob/197eeddacccf2195bd7a9e0572ef24bb50a700c8/src/BuilderBag.php#L103-L112
train
ongr-io/ElasticsearchDSL
src/Search.php
Search.addQuery
public function addQuery(BuilderInterface $query, $boolType = BoolQuery::MUST, $key = null) { $endpoint = $this->getEndpoint(QueryEndpoint::NAME); $endpoint->addToBool($query, $boolType, $key); return $this; }
php
public function addQuery(BuilderInterface $query, $boolType = BoolQuery::MUST, $key = null) { $endpoint = $this->getEndpoint(QueryEndpoint::NAME); $endpoint->addToBool($query, $boolType, $key); return $this; }
[ "public", "function", "addQuery", "(", "BuilderInterface", "$", "query", ",", "$", "boolType", "=", "BoolQuery", "::", "MUST", ",", "$", "key", "=", "null", ")", "{", "$", "endpoint", "=", "$", "this", "->", "getEndpoint", "(", "QueryEndpoint", "::", "NA...
Adds query to the search. @param BuilderInterface $query @param string $boolType @param string $key @return $this
[ "Adds", "query", "to", "the", "search", "." ]
197eeddacccf2195bd7a9e0572ef24bb50a700c8
https://github.com/ongr-io/ElasticsearchDSL/blob/197eeddacccf2195bd7a9e0572ef24bb50a700c8/src/Search.php#L207-L213
train
ongr-io/ElasticsearchDSL
src/Search.php
Search.getEndpoint
private function getEndpoint($type) { if (!array_key_exists($type, $this->endpoints)) { $this->endpoints[$type] = SearchEndpointFactory::get($type); } return $this->endpoints[$type]; }
php
private function getEndpoint($type) { if (!array_key_exists($type, $this->endpoints)) { $this->endpoints[$type] = SearchEndpointFactory::get($type); } return $this->endpoints[$type]; }
[ "private", "function", "getEndpoint", "(", "$", "type", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "type", ",", "$", "this", "->", "endpoints", ")", ")", "{", "$", "this", "->", "endpoints", "[", "$", "type", "]", "=", "SearchEndpointFacto...
Returns endpoint instance. @param string $type Endpoint type. @return SearchEndpointInterface
[ "Returns", "endpoint", "instance", "." ]
197eeddacccf2195bd7a9e0572ef24bb50a700c8
https://github.com/ongr-io/ElasticsearchDSL/blob/197eeddacccf2195bd7a9e0572ef24bb50a700c8/src/Search.php#L222-L229
train
ongr-io/ElasticsearchDSL
src/Search.php
Search.setEndpointParameters
public function setEndpointParameters($endpointName, array $parameters) { /** @var AbstractSearchEndpoint $endpoint */ $endpoint = $this->getEndpoint($endpointName); $endpoint->setParameters($parameters); }
php
public function setEndpointParameters($endpointName, array $parameters) { /** @var AbstractSearchEndpoint $endpoint */ $endpoint = $this->getEndpoint($endpointName); $endpoint->setParameters($parameters); }
[ "public", "function", "setEndpointParameters", "(", "$", "endpointName", ",", "array", "$", "parameters", ")", "{", "/** @var AbstractSearchEndpoint $endpoint */", "$", "endpoint", "=", "$", "this", "->", "getEndpoint", "(", "$", "endpointName", ")", ";", "$", "en...
Sets parameters to the endpoint. @param string $endpointName @param array $parameters
[ "Sets", "parameters", "to", "the", "endpoint", "." ]
197eeddacccf2195bd7a9e0572ef24bb50a700c8
https://github.com/ongr-io/ElasticsearchDSL/blob/197eeddacccf2195bd7a9e0572ef24bb50a700c8/src/Search.php#L263-L268
train
ongr-io/ElasticsearchDSL
src/Search.php
Search.addPostFilter
public function addPostFilter(BuilderInterface $filter, $boolType = BoolQuery::MUST, $key = null) { $this ->getEndpoint(PostFilterEndpoint::NAME) ->addToBool($filter, $boolType, $key); return $this; }
php
public function addPostFilter(BuilderInterface $filter, $boolType = BoolQuery::MUST, $key = null) { $this ->getEndpoint(PostFilterEndpoint::NAME) ->addToBool($filter, $boolType, $key); return $this; }
[ "public", "function", "addPostFilter", "(", "BuilderInterface", "$", "filter", ",", "$", "boolType", "=", "BoolQuery", "::", "MUST", ",", "$", "key", "=", "null", ")", "{", "$", "this", "->", "getEndpoint", "(", "PostFilterEndpoint", "::", "NAME", ")", "->...
Adds a post filter to search. @param BuilderInterface $filter Filter. @param string $boolType Example boolType values: - must - must_not - should. @param string $key @return $this.
[ "Adds", "a", "post", "filter", "to", "search", "." ]
197eeddacccf2195bd7a9e0572ef24bb50a700c8
https://github.com/ongr-io/ElasticsearchDSL/blob/197eeddacccf2195bd7a9e0572ef24bb50a700c8/src/Search.php#L282-L289
train
ongr-io/ElasticsearchDSL
src/Search.php
Search.addAggregation
public function addAggregation(AbstractAggregation $aggregation) { $this->getEndpoint(AggregationsEndpoint::NAME)->add($aggregation, $aggregation->getName()); return $this; }
php
public function addAggregation(AbstractAggregation $aggregation) { $this->getEndpoint(AggregationsEndpoint::NAME)->add($aggregation, $aggregation->getName()); return $this; }
[ "public", "function", "addAggregation", "(", "AbstractAggregation", "$", "aggregation", ")", "{", "$", "this", "->", "getEndpoint", "(", "AggregationsEndpoint", "::", "NAME", ")", "->", "add", "(", "$", "aggregation", ",", "$", "aggregation", "->", "getName", ...
Adds aggregation into search. @param AbstractAggregation $aggregation @return $this
[ "Adds", "aggregation", "into", "search", "." ]
197eeddacccf2195bd7a9e0572ef24bb50a700c8
https://github.com/ongr-io/ElasticsearchDSL/blob/197eeddacccf2195bd7a9e0572ef24bb50a700c8/src/Search.php#L324-L329
train
ongr-io/ElasticsearchDSL
src/Search.php
Search.addInnerHit
public function addInnerHit(NestedInnerHit $innerHit) { $this->getEndpoint(InnerHitsEndpoint::NAME)->add($innerHit, $innerHit->getName()); return $this; }
php
public function addInnerHit(NestedInnerHit $innerHit) { $this->getEndpoint(InnerHitsEndpoint::NAME)->add($innerHit, $innerHit->getName()); return $this; }
[ "public", "function", "addInnerHit", "(", "NestedInnerHit", "$", "innerHit", ")", "{", "$", "this", "->", "getEndpoint", "(", "InnerHitsEndpoint", "::", "NAME", ")", "->", "add", "(", "$", "innerHit", ",", "$", "innerHit", "->", "getName", "(", ")", ")", ...
Adds inner hit into search. @param NestedInnerHit $innerHit @return $this
[ "Adds", "inner", "hit", "into", "search", "." ]
197eeddacccf2195bd7a9e0572ef24bb50a700c8
https://github.com/ongr-io/ElasticsearchDSL/blob/197eeddacccf2195bd7a9e0572ef24bb50a700c8/src/Search.php#L348-L353
train
ongr-io/ElasticsearchDSL
src/Search.php
Search.addSort
public function addSort(BuilderInterface $sort) { $this->getEndpoint(SortEndpoint::NAME)->add($sort); return $this; }
php
public function addSort(BuilderInterface $sort) { $this->getEndpoint(SortEndpoint::NAME)->add($sort); return $this; }
[ "public", "function", "addSort", "(", "BuilderInterface", "$", "sort", ")", "{", "$", "this", "->", "getEndpoint", "(", "SortEndpoint", "::", "NAME", ")", "->", "add", "(", "$", "sort", ")", ";", "return", "$", "this", ";", "}" ]
Adds sort to search. @param BuilderInterface $sort @return $this
[ "Adds", "sort", "to", "search", "." ]
197eeddacccf2195bd7a9e0572ef24bb50a700c8
https://github.com/ongr-io/ElasticsearchDSL/blob/197eeddacccf2195bd7a9e0572ef24bb50a700c8/src/Search.php#L372-L377
train
ongr-io/ElasticsearchDSL
src/Search.php
Search.addSuggest
public function addSuggest(NamedBuilderInterface $suggest) { $this->getEndpoint(SuggestEndpoint::NAME)->add($suggest, $suggest->getName()); return $this; }
php
public function addSuggest(NamedBuilderInterface $suggest) { $this->getEndpoint(SuggestEndpoint::NAME)->add($suggest, $suggest->getName()); return $this; }
[ "public", "function", "addSuggest", "(", "NamedBuilderInterface", "$", "suggest", ")", "{", "$", "this", "->", "getEndpoint", "(", "SuggestEndpoint", "::", "NAME", ")", "->", "add", "(", "$", "suggest", ",", "$", "suggest", "->", "getName", "(", ")", ")", ...
Adds suggest into search. @param BuilderInterface $suggest @return $this
[ "Adds", "suggest", "into", "search", "." ]
197eeddacccf2195bd7a9e0572ef24bb50a700c8
https://github.com/ongr-io/ElasticsearchDSL/blob/197eeddacccf2195bd7a9e0572ef24bb50a700c8/src/Search.php#L423-L428
train
ongr-io/ElasticsearchDSL
src/Query/Geo/GeoShapeQuery.php
GeoShapeQuery.addShape
public function addShape($field, $type, array $coordinates, $relation = self::INTERSECTS, array $parameters = []) { // TODO: remove this in the next major version if (is_array($relation)) { $parameters = $relation; $relation = self::INTERSECTS; trigger_error('$parameters as parameter 4 in addShape is deprecated', E_USER_DEPRECATED); } $filter = array_merge( $parameters, [ 'type' => $type, 'coordinates' => $coordinates, ] ); $this->fields[$field] = [ 'shape' => $filter, 'relation' => $relation, ]; }
php
public function addShape($field, $type, array $coordinates, $relation = self::INTERSECTS, array $parameters = []) { // TODO: remove this in the next major version if (is_array($relation)) { $parameters = $relation; $relation = self::INTERSECTS; trigger_error('$parameters as parameter 4 in addShape is deprecated', E_USER_DEPRECATED); } $filter = array_merge( $parameters, [ 'type' => $type, 'coordinates' => $coordinates, ] ); $this->fields[$field] = [ 'shape' => $filter, 'relation' => $relation, ]; }
[ "public", "function", "addShape", "(", "$", "field", ",", "$", "type", ",", "array", "$", "coordinates", ",", "$", "relation", "=", "self", "::", "INTERSECTS", ",", "array", "$", "parameters", "=", "[", "]", ")", "{", "// TODO: remove this in the next major ...
Add geo-shape provided filter. @param string $field Field name. @param string $type Shape type. @param array $coordinates Shape coordinates. @param string $relation Spatial relation. @param array $parameters Additional parameters.
[ "Add", "geo", "-", "shape", "provided", "filter", "." ]
197eeddacccf2195bd7a9e0572ef24bb50a700c8
https://github.com/ongr-io/ElasticsearchDSL/blob/197eeddacccf2195bd7a9e0572ef24bb50a700c8/src/Query/Geo/GeoShapeQuery.php#L61-L82
train
ongr-io/ElasticsearchDSL
src/Query/Geo/GeoShapeQuery.php
GeoShapeQuery.addPreIndexedShape
public function addPreIndexedShape($field, $id, $type, $index, $path, array $parameters = []) { $filter = array_merge( $parameters, [ 'id' => $id, 'type' => $type, 'index' => $index, 'path' => $path, ] ); $this->fields[$field]['indexed_shape'] = $filter; }
php
public function addPreIndexedShape($field, $id, $type, $index, $path, array $parameters = []) { $filter = array_merge( $parameters, [ 'id' => $id, 'type' => $type, 'index' => $index, 'path' => $path, ] ); $this->fields[$field]['indexed_shape'] = $filter; }
[ "public", "function", "addPreIndexedShape", "(", "$", "field", ",", "$", "id", ",", "$", "type", ",", "$", "index", ",", "$", "path", ",", "array", "$", "parameters", "=", "[", "]", ")", "{", "$", "filter", "=", "array_merge", "(", "$", "parameters",...
Add geo-shape pre-indexed filter. @param string $field Field name. @param string $id The ID of the document that containing the pre-indexed shape. @param string $type Name of the index where the pre-indexed shape is. @param string $index Index type where the pre-indexed shape is. @param string $path The field specified as path containing the pre-indexed shape. @param array $parameters Additional parameters.
[ "Add", "geo", "-", "shape", "pre", "-", "indexed", "filter", "." ]
197eeddacccf2195bd7a9e0572ef24bb50a700c8
https://github.com/ongr-io/ElasticsearchDSL/blob/197eeddacccf2195bd7a9e0572ef24bb50a700c8/src/Query/Geo/GeoShapeQuery.php#L94-L107
train
ongr-io/ElasticsearchDSL
src/Aggregation/Bucketing/HistogramAggregation.php
HistogramAggregation.setOrder
public function setOrder($mode, $direction = self::DIRECTION_ASC) { $this->orderMode = $mode; $this->orderDirection = $direction; }
php
public function setOrder($mode, $direction = self::DIRECTION_ASC) { $this->orderMode = $mode; $this->orderDirection = $direction; }
[ "public", "function", "setOrder", "(", "$", "mode", ",", "$", "direction", "=", "self", "::", "DIRECTION_ASC", ")", "{", "$", "this", "->", "orderMode", "=", "$", "mode", ";", "$", "this", "->", "orderDirection", "=", "$", "direction", ";", "}" ]
Sets buckets ordering. @param string $mode @param string $direction
[ "Sets", "buckets", "ordering", "." ]
197eeddacccf2195bd7a9e0572ef24bb50a700c8
https://github.com/ongr-io/ElasticsearchDSL/blob/197eeddacccf2195bd7a9e0572ef24bb50a700c8/src/Aggregation/Bucketing/HistogramAggregation.php#L117-L121
train
ongr-io/ElasticsearchDSL
src/Aggregation/AbstractAggregation.php
AbstractAggregation.addAggregation
public function addAggregation(AbstractAggregation $abstractAggregation) { if (!$this->aggregations) { $this->aggregations = $this->createBuilderBag(); } $this->aggregations->add($abstractAggregation); return $this; }
php
public function addAggregation(AbstractAggregation $abstractAggregation) { if (!$this->aggregations) { $this->aggregations = $this->createBuilderBag(); } $this->aggregations->add($abstractAggregation); return $this; }
[ "public", "function", "addAggregation", "(", "AbstractAggregation", "$", "abstractAggregation", ")", "{", "if", "(", "!", "$", "this", "->", "aggregations", ")", "{", "$", "this", "->", "aggregations", "=", "$", "this", "->", "createBuilderBag", "(", ")", ";...
Adds a sub-aggregation. @param AbstractAggregation $abstractAggregation @return $this
[ "Adds", "a", "sub", "-", "aggregation", "." ]
197eeddacccf2195bd7a9e0572ef24bb50a700c8
https://github.com/ongr-io/ElasticsearchDSL/blob/197eeddacccf2195bd7a9e0572ef24bb50a700c8/src/Aggregation/AbstractAggregation.php#L82-L91
train
ongr-io/ElasticsearchDSL
src/Aggregation/AbstractAggregation.php
AbstractAggregation.collectNestedAggregations
protected function collectNestedAggregations() { $result = []; /** @var AbstractAggregation $aggregation */ foreach ($this->getAggregations() as $aggregation) { $result[$aggregation->getName()] = $aggregation->toArray(); } return $result; }
php
protected function collectNestedAggregations() { $result = []; /** @var AbstractAggregation $aggregation */ foreach ($this->getAggregations() as $aggregation) { $result[$aggregation->getName()] = $aggregation->toArray(); } return $result; }
[ "protected", "function", "collectNestedAggregations", "(", ")", "{", "$", "result", "=", "[", "]", ";", "/** @var AbstractAggregation $aggregation */", "foreach", "(", "$", "this", "->", "getAggregations", "(", ")", "as", "$", "aggregation", ")", "{", "$", "resu...
Process all nested aggregations. @return array
[ "Process", "all", "nested", "aggregations", "." ]
197eeddacccf2195bd7a9e0572ef24bb50a700c8
https://github.com/ongr-io/ElasticsearchDSL/blob/197eeddacccf2195bd7a9e0572ef24bb50a700c8/src/Aggregation/AbstractAggregation.php#L148-L157
train
ongr-io/ElasticsearchDSL
src/Aggregation/Bucketing/Ipv4RangeAggregation.php
Ipv4RangeAggregation.addRange
public function addRange($from = null, $to = null) { $range = array_filter( [ 'from' => $from, 'to' => $to, ], function ($v) { return !is_null($v); } ); $this->ranges[] = $range; return $this; }
php
public function addRange($from = null, $to = null) { $range = array_filter( [ 'from' => $from, 'to' => $to, ], function ($v) { return !is_null($v); } ); $this->ranges[] = $range; return $this; }
[ "public", "function", "addRange", "(", "$", "from", "=", "null", ",", "$", "to", "=", "null", ")", "{", "$", "range", "=", "array_filter", "(", "[", "'from'", "=>", "$", "from", ",", "'to'", "=>", "$", "to", ",", "]", ",", "function", "(", "$", ...
Add range to aggregation. @param string|null $from @param string|null $to @return Ipv4RangeAggregation
[ "Add", "range", "to", "aggregation", "." ]
197eeddacccf2195bd7a9e0572ef24bb50a700c8
https://github.com/ongr-io/ElasticsearchDSL/blob/197eeddacccf2195bd7a9e0572ef24bb50a700c8/src/Aggregation/Bucketing/Ipv4RangeAggregation.php#L62-L77
train
ongr-io/ElasticsearchDSL
src/Query/Compound/FunctionScoreQuery.php
FunctionScoreQuery.addFieldValueFactorFunction
public function addFieldValueFactorFunction($field, $factor, $modifier = 'none', BuilderInterface $query = null) { $function = [ 'field_value_factor' => [ 'field' => $field, 'factor' => $factor, 'modifier' => $modifier, ], ]; $this->applyFilter($function, $query); $this->functions[] = $function; return $this; }
php
public function addFieldValueFactorFunction($field, $factor, $modifier = 'none', BuilderInterface $query = null) { $function = [ 'field_value_factor' => [ 'field' => $field, 'factor' => $factor, 'modifier' => $modifier, ], ]; $this->applyFilter($function, $query); $this->functions[] = $function; return $this; }
[ "public", "function", "addFieldValueFactorFunction", "(", "$", "field", ",", "$", "factor", ",", "$", "modifier", "=", "'none'", ",", "BuilderInterface", "$", "query", "=", "null", ")", "{", "$", "function", "=", "[", "'field_value_factor'", "=>", "[", "'fie...
Creates field_value_factor function. @param string $field @param float $factor @param string $modifier @param BuilderInterface $query @return $this
[ "Creates", "field_value_factor", "function", "." ]
197eeddacccf2195bd7a9e0572ef24bb50a700c8
https://github.com/ongr-io/ElasticsearchDSL/blob/197eeddacccf2195bd7a9e0572ef24bb50a700c8/src/Query/Compound/FunctionScoreQuery.php#L66-L81
train
ongr-io/ElasticsearchDSL
src/Query/Compound/FunctionScoreQuery.php
FunctionScoreQuery.addDecayFunction
public function addDecayFunction( $type, $field, array $function, array $options = [], BuilderInterface $query = null, $weight = null ) { $function = array_filter( [ $type => array_merge( [$field => $function], $options ), 'weight' => $weight, ] ); $this->applyFilter($function, $query); $this->functions[] = $function; return $this; }
php
public function addDecayFunction( $type, $field, array $function, array $options = [], BuilderInterface $query = null, $weight = null ) { $function = array_filter( [ $type => array_merge( [$field => $function], $options ), 'weight' => $weight, ] ); $this->applyFilter($function, $query); $this->functions[] = $function; return $this; }
[ "public", "function", "addDecayFunction", "(", "$", "type", ",", "$", "field", ",", "array", "$", "function", ",", "array", "$", "options", "=", "[", "]", ",", "BuilderInterface", "$", "query", "=", "null", ",", "$", "weight", "=", "null", ")", "{", ...
Add decay function to function score. Weight and query are optional. @param string $type @param string $field @param array $function @param array $options @param BuilderInterface $query @param int $weight @return $this
[ "Add", "decay", "function", "to", "function", "score", ".", "Weight", "and", "query", "are", "optional", "." ]
197eeddacccf2195bd7a9e0572ef24bb50a700c8
https://github.com/ongr-io/ElasticsearchDSL/blob/197eeddacccf2195bd7a9e0572ef24bb50a700c8/src/Query/Compound/FunctionScoreQuery.php#L108-L131
train
ongr-io/ElasticsearchDSL
src/Query/Compound/FunctionScoreQuery.php
FunctionScoreQuery.addWeightFunction
public function addWeightFunction($weight, BuilderInterface $query = null) { $function = [ 'weight' => $weight, ]; $this->applyFilter($function, $query); $this->functions[] = $function; return $this; }
php
public function addWeightFunction($weight, BuilderInterface $query = null) { $function = [ 'weight' => $weight, ]; $this->applyFilter($function, $query); $this->functions[] = $function; return $this; }
[ "public", "function", "addWeightFunction", "(", "$", "weight", ",", "BuilderInterface", "$", "query", "=", "null", ")", "{", "$", "function", "=", "[", "'weight'", "=>", "$", "weight", ",", "]", ";", "$", "this", "->", "applyFilter", "(", "$", "function"...
Adds function to function score without decay function. Influence search score only for specific query. @param float $weight @param BuilderInterface $query @return $this
[ "Adds", "function", "to", "function", "score", "without", "decay", "function", ".", "Influence", "search", "score", "only", "for", "specific", "query", "." ]
197eeddacccf2195bd7a9e0572ef24bb50a700c8
https://github.com/ongr-io/ElasticsearchDSL/blob/197eeddacccf2195bd7a9e0572ef24bb50a700c8/src/Query/Compound/FunctionScoreQuery.php#L141-L152
train
ongr-io/ElasticsearchDSL
src/Query/Compound/FunctionScoreQuery.php
FunctionScoreQuery.addRandomFunction
public function addRandomFunction($seed = null, BuilderInterface $query = null) { $function = [ 'random_score' => $seed ? [ 'seed' => $seed ] : new \stdClass(), ]; $this->applyFilter($function, $query); $this->functions[] = $function; return $this; }
php
public function addRandomFunction($seed = null, BuilderInterface $query = null) { $function = [ 'random_score' => $seed ? [ 'seed' => $seed ] : new \stdClass(), ]; $this->applyFilter($function, $query); $this->functions[] = $function; return $this; }
[ "public", "function", "addRandomFunction", "(", "$", "seed", "=", "null", ",", "BuilderInterface", "$", "query", "=", "null", ")", "{", "$", "function", "=", "[", "'random_score'", "=>", "$", "seed", "?", "[", "'seed'", "=>", "$", "seed", "]", ":", "ne...
Adds random score function. Seed is optional. @param mixed $seed @param BuilderInterface $query @return $this
[ "Adds", "random", "score", "function", ".", "Seed", "is", "optional", "." ]
197eeddacccf2195bd7a9e0572ef24bb50a700c8
https://github.com/ongr-io/ElasticsearchDSL/blob/197eeddacccf2195bd7a9e0572ef24bb50a700c8/src/Query/Compound/FunctionScoreQuery.php#L162-L173
train
ongr-io/ElasticsearchDSL
src/Query/Compound/FunctionScoreQuery.php
FunctionScoreQuery.addScriptScoreFunction
public function addScriptScoreFunction( $inline, array $params = [], array $options = [], BuilderInterface $query = null ) { $function = [ 'script_score' => [ 'script' => array_filter( array_merge( [ 'lang' => 'painless', 'inline' => $inline, 'params' => $params ], $options ) ) ], ]; $this->applyFilter($function, $query); $this->functions[] = $function; return $this; }
php
public function addScriptScoreFunction( $inline, array $params = [], array $options = [], BuilderInterface $query = null ) { $function = [ 'script_score' => [ 'script' => array_filter( array_merge( [ 'lang' => 'painless', 'inline' => $inline, 'params' => $params ], $options ) ) ], ]; $this->applyFilter($function, $query); $this->functions[] = $function; return $this; }
[ "public", "function", "addScriptScoreFunction", "(", "$", "inline", ",", "array", "$", "params", "=", "[", "]", ",", "array", "$", "options", "=", "[", "]", ",", "BuilderInterface", "$", "query", "=", "null", ")", "{", "$", "function", "=", "[", "'scri...
Adds script score function. @param string $inline @param array $params @param array $options @param BuilderInterface $query @return $this
[ "Adds", "script", "score", "function", "." ]
197eeddacccf2195bd7a9e0572ef24bb50a700c8
https://github.com/ongr-io/ElasticsearchDSL/blob/197eeddacccf2195bd7a9e0572ef24bb50a700c8/src/Query/Compound/FunctionScoreQuery.php#L185-L211
train
ongr-io/ElasticsearchDSL
src/Highlight/Highlight.php
Highlight.setTags
public function setTags(array $preTags, array $postTags) { $this->tags['pre_tags'] = $preTags; $this->tags['post_tags'] = $postTags; return $this; }
php
public function setTags(array $preTags, array $postTags) { $this->tags['pre_tags'] = $preTags; $this->tags['post_tags'] = $postTags; return $this; }
[ "public", "function", "setTags", "(", "array", "$", "preTags", ",", "array", "$", "postTags", ")", "{", "$", "this", "->", "tags", "[", "'pre_tags'", "]", "=", "$", "preTags", ";", "$", "this", "->", "tags", "[", "'post_tags'", "]", "=", "$", "postTa...
Sets html tag and its class used in highlighting. @param array $preTags @param array $postTags @return $this
[ "Sets", "html", "tag", "and", "its", "class", "used", "in", "highlighting", "." ]
197eeddacccf2195bd7a9e0572ef24bb50a700c8
https://github.com/ongr-io/ElasticsearchDSL/blob/197eeddacccf2195bd7a9e0572ef24bb50a700c8/src/Highlight/Highlight.php#L55-L61
train
ongr-io/ElasticsearchDSL
src/Serializer/OrderedSerializer.php
OrderedSerializer.order
private function order(array $data) { $filteredData = $this->filterOrderable($data); if (!empty($filteredData)) { uasort( $filteredData, function (OrderedNormalizerInterface $a, OrderedNormalizerInterface $b) { return $a->getOrder() > $b->getOrder(); } ); return array_merge($filteredData, array_diff_key($data, $filteredData)); } return $data; }
php
private function order(array $data) { $filteredData = $this->filterOrderable($data); if (!empty($filteredData)) { uasort( $filteredData, function (OrderedNormalizerInterface $a, OrderedNormalizerInterface $b) { return $a->getOrder() > $b->getOrder(); } ); return array_merge($filteredData, array_diff_key($data, $filteredData)); } return $data; }
[ "private", "function", "order", "(", "array", "$", "data", ")", "{", "$", "filteredData", "=", "$", "this", "->", "filterOrderable", "(", "$", "data", ")", ";", "if", "(", "!", "empty", "(", "$", "filteredData", ")", ")", "{", "uasort", "(", "$", "...
Orders objects if can be done. @param array $data Data to order. @return array
[ "Orders", "objects", "if", "can", "be", "done", "." ]
197eeddacccf2195bd7a9e0572ef24bb50a700c8
https://github.com/ongr-io/ElasticsearchDSL/blob/197eeddacccf2195bd7a9e0572ef24bb50a700c8/src/Serializer/OrderedSerializer.php#L54-L70
train
sonata-project/SonataPageBundle
src/Controller/Api/SiteController.php
SiteController.deleteSiteAction
public function deleteSiteAction($id) { $site = $this->getSite($id); $this->siteManager->delete($site); return ['deleted' => true]; }
php
public function deleteSiteAction($id) { $site = $this->getSite($id); $this->siteManager->delete($site); return ['deleted' => true]; }
[ "public", "function", "deleteSiteAction", "(", "$", "id", ")", "{", "$", "site", "=", "$", "this", "->", "getSite", "(", "$", "id", ")", ";", "$", "this", "->", "siteManager", "->", "delete", "(", "$", "site", ")", ";", "return", "[", "'deleted'", ...
Deletes a site. @ApiDoc( requirements={ {"name"="id", "dataType"="integer", "requirement"="\d+", "description"="site id"} }, statusCodes={ 200="Returned when site is successfully deleted", 400="Returned when an error has occurred while deleting the site", 404="Returned when unable to find the site" } ) @param int $id A Site identifier @throws NotFoundHttpException @return \FOS\RestBundle\View\View
[ "Deletes", "a", "site", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/Controller/Api/SiteController.php#L199-L206
train
sonata-project/SonataPageBundle
src/Controller/Api/SiteController.php
SiteController.handleWriteSite
protected function handleWriteSite($request, $id = null) { $site = $id ? $this->getSite($id) : null; $form = $this->formFactory->createNamed(null, 'sonata_page_api_form_site', $site, [ 'csrf_protection' => false, ]); $form->handleRequest($request); if ($form->isValid()) { $site = $form->getData(); $this->siteManager->save($site); return $this->serializeContext($site, ['sonata_api_read']); } return $form; }
php
protected function handleWriteSite($request, $id = null) { $site = $id ? $this->getSite($id) : null; $form = $this->formFactory->createNamed(null, 'sonata_page_api_form_site', $site, [ 'csrf_protection' => false, ]); $form->handleRequest($request); if ($form->isValid()) { $site = $form->getData(); $this->siteManager->save($site); return $this->serializeContext($site, ['sonata_api_read']); } return $form; }
[ "protected", "function", "handleWriteSite", "(", "$", "request", ",", "$", "id", "=", "null", ")", "{", "$", "site", "=", "$", "id", "?", "$", "this", "->", "getSite", "(", "$", "id", ")", ":", "null", ";", "$", "form", "=", "$", "this", "->", ...
Write a site, this method is used by both POST and PUT action methods. @param Request $request Symfony request @param int|null $id A post identifier @return FormInterface|FOSRestView
[ "Write", "a", "site", "this", "method", "is", "used", "by", "both", "POST", "and", "PUT", "action", "methods", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/Controller/Api/SiteController.php#L236-L255
train
sonata-project/SonataPageBundle
src/Entity/BlockManager.php
BlockManager.updatePosition
public function updatePosition($id, $position, $parentId = null, $pageId = null, $partial = true) { if ($partial) { $meta = $this->getEntityManager()->getClassMetadata($this->getClass()); // retrieve object references $block = $this->getEntityManager()->getReference($this->getClass(), $id); $pageRelation = $meta->getAssociationMapping('page'); $page = $this->getEntityManager()->getPartialReference($pageRelation['targetEntity'], $pageId); $parentRelation = $meta->getAssociationMapping('parent'); $parent = $this->getEntityManager()->getPartialReference($parentRelation['targetEntity'], $parentId); $block->setPage($page); $block->setParent($parent); } else { $block = $this->find($id); } // set new values $block->setPosition($position); $this->getEntityManager()->persist($block); return $block; }
php
public function updatePosition($id, $position, $parentId = null, $pageId = null, $partial = true) { if ($partial) { $meta = $this->getEntityManager()->getClassMetadata($this->getClass()); // retrieve object references $block = $this->getEntityManager()->getReference($this->getClass(), $id); $pageRelation = $meta->getAssociationMapping('page'); $page = $this->getEntityManager()->getPartialReference($pageRelation['targetEntity'], $pageId); $parentRelation = $meta->getAssociationMapping('parent'); $parent = $this->getEntityManager()->getPartialReference($parentRelation['targetEntity'], $parentId); $block->setPage($page); $block->setParent($parent); } else { $block = $this->find($id); } // set new values $block->setPosition($position); $this->getEntityManager()->persist($block); return $block; }
[ "public", "function", "updatePosition", "(", "$", "id", ",", "$", "position", ",", "$", "parentId", "=", "null", ",", "$", "pageId", "=", "null", ",", "$", "partial", "=", "true", ")", "{", "if", "(", "$", "partial", ")", "{", "$", "meta", "=", "...
Updates position for given block. @param int $id Block Id @param int $position New Position @param int $parentId Parent block Id (needed when partial = true) @param int $pageId Page Id (needed when partial = true) @param bool $partial Should we use partial references? (Better for performance, but can lead to query issues.) @return mixed
[ "Updates", "position", "for", "given", "block", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/Entity/BlockManager.php#L49-L73
train
sonata-project/SonataPageBundle
src/Page/PageServiceManager.php
PageServiceManager.createResponse
protected function createResponse(PageInterface $page) { if ($page->getTarget()) { $page->addHeader('Location', $this->router->generate($page->getTarget())); $response = new Response('', 302, $page->getHeaders() ?: []); } else { $response = new Response('', 200, $page->getHeaders() ?: []); } return $response; }
php
protected function createResponse(PageInterface $page) { if ($page->getTarget()) { $page->addHeader('Location', $this->router->generate($page->getTarget())); $response = new Response('', 302, $page->getHeaders() ?: []); } else { $response = new Response('', 200, $page->getHeaders() ?: []); } return $response; }
[ "protected", "function", "createResponse", "(", "PageInterface", "$", "page", ")", "{", "if", "(", "$", "page", "->", "getTarget", "(", ")", ")", "{", "$", "page", "->", "addHeader", "(", "'Location'", ",", "$", "this", "->", "router", "->", "generate", ...
Creates a base response for given page. @param PageInterface $page @return Response
[ "Creates", "a", "base", "response", "for", "given", "page", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/Page/PageServiceManager.php#L127-L137
train
sonata-project/SonataPageBundle
src/Listener/ResponseListener.php
ResponseListener.onCoreResponse
public function onCoreResponse(FilterResponseEvent $event) { $cms = $this->cmsSelector->retrieve(); $response = $event->getResponse(); $request = $event->getRequest(); if ($this->cmsSelector->isEditor()) { $response->setPrivate(); if (!$request->cookies->has('sonata_page_is_editor')) { $response->headers->setCookie(new Cookie('sonata_page_is_editor', '1')); } } $page = $cms->getCurrentPage(); // display a validation page before redirecting, so the editor can edit the current page if ( $page && $response->isRedirection() && $this->cmsSelector->isEditor() && !$request->get('_sonata_page_skip') && !$this->skipRedirection ) { $response = new Response($this->templating->render('@SonataPage/Page/redirect.html.twig', [ 'response' => $response, 'page' => $page, ])); $response->setPrivate(); $event->setResponse($response); return; } if (!$this->decoratorStrategy->isDecorable($event->getRequest(), $event->getRequestType(), $response)) { return; } if (!$this->cmsSelector->isEditor() && $request->cookies->has('sonata_page_is_editor')) { $response->headers->clearCookie('sonata_page_is_editor'); } if (!$page) { throw new InternalErrorException('No page instance available for the url, run the sonata:page:update-core-routes and sonata:page:create-snapshots commands'); } // only decorate hybrid page or page with decorate = true if (!$page->isHybrid() || !$page->getDecorate()) { return; } $parameters = [ 'content' => $response->getContent(), ]; $response = $this->pageServiceManager->execute($page, $request, $parameters, $response); if (!$this->cmsSelector->isEditor() && $page->isCms()) { $response->setTtl($page->getTtl()); } $event->setResponse($response); }
php
public function onCoreResponse(FilterResponseEvent $event) { $cms = $this->cmsSelector->retrieve(); $response = $event->getResponse(); $request = $event->getRequest(); if ($this->cmsSelector->isEditor()) { $response->setPrivate(); if (!$request->cookies->has('sonata_page_is_editor')) { $response->headers->setCookie(new Cookie('sonata_page_is_editor', '1')); } } $page = $cms->getCurrentPage(); // display a validation page before redirecting, so the editor can edit the current page if ( $page && $response->isRedirection() && $this->cmsSelector->isEditor() && !$request->get('_sonata_page_skip') && !$this->skipRedirection ) { $response = new Response($this->templating->render('@SonataPage/Page/redirect.html.twig', [ 'response' => $response, 'page' => $page, ])); $response->setPrivate(); $event->setResponse($response); return; } if (!$this->decoratorStrategy->isDecorable($event->getRequest(), $event->getRequestType(), $response)) { return; } if (!$this->cmsSelector->isEditor() && $request->cookies->has('sonata_page_is_editor')) { $response->headers->clearCookie('sonata_page_is_editor'); } if (!$page) { throw new InternalErrorException('No page instance available for the url, run the sonata:page:update-core-routes and sonata:page:create-snapshots commands'); } // only decorate hybrid page or page with decorate = true if (!$page->isHybrid() || !$page->getDecorate()) { return; } $parameters = [ 'content' => $response->getContent(), ]; $response = $this->pageServiceManager->execute($page, $request, $parameters, $response); if (!$this->cmsSelector->isEditor() && $page->isCms()) { $response->setTtl($page->getTtl()); } $event->setResponse($response); }
[ "public", "function", "onCoreResponse", "(", "FilterResponseEvent", "$", "event", ")", "{", "$", "cms", "=", "$", "this", "->", "cmsSelector", "->", "retrieve", "(", ")", ";", "$", "response", "=", "$", "event", "->", "getResponse", "(", ")", ";", "$", ...
Filter the `core.response` event to decorate the action. @param FilterResponseEvent $event @throws InternalErrorException
[ "Filter", "the", "core", ".", "response", "event", "to", "decorate", "the", "action", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/Listener/ResponseListener.php#L88-L152
train
sonata-project/SonataPageBundle
src/Command/CloneSiteCommand.php
CloneSiteCommand.listAllSites
private function listAllSites(OutputInterface $output) { $output->writeln(sprintf(' % 5s - % -30s - %s', 'ID', 'Name', 'Url')); $sites = $this->getSiteManager()->findAll(); foreach ($sites as $site) { $output->writeln(sprintf(' % 5s - % -30s - %s', $site->getId(), $site->getName(), $site->getUrl())); } }
php
private function listAllSites(OutputInterface $output) { $output->writeln(sprintf(' % 5s - % -30s - %s', 'ID', 'Name', 'Url')); $sites = $this->getSiteManager()->findAll(); foreach ($sites as $site) { $output->writeln(sprintf(' % 5s - % -30s - %s', $site->getId(), $site->getName(), $site->getUrl())); } }
[ "private", "function", "listAllSites", "(", "OutputInterface", "$", "output", ")", "{", "$", "output", "->", "writeln", "(", "sprintf", "(", "' % 5s - % -30s - %s'", ",", "'ID'", ",", "'Name'", ",", "'Url'", ")", ")", ";", "$", "sites", "=", "$", "this", ...
Prints a list of all available sites. @param OutputInterface $output
[ "Prints", "a", "list", "of", "all", "available", "sites", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/Command/CloneSiteCommand.php#L198-L207
train
sonata-project/SonataPageBundle
src/Controller/Api/PageController.php
PageController.postPageBlockAction
public function postPageBlockAction($id, Request $request) { $page = $id ? $this->getPage($id) : null; $form = $this->formFactory->createNamed(null, 'sonata_page_api_form_block', null, [ 'csrf_protection' => false, ]); $form->handleRequest($request); if ($form->isValid()) { $block = $form->getData(); $block->setPage($page); $this->blockManager->save($block); return $block; } return $form; }
php
public function postPageBlockAction($id, Request $request) { $page = $id ? $this->getPage($id) : null; $form = $this->formFactory->createNamed(null, 'sonata_page_api_form_block', null, [ 'csrf_protection' => false, ]); $form->handleRequest($request); if ($form->isValid()) { $block = $form->getData(); $block->setPage($page); $this->blockManager->save($block); return $block; } return $form; }
[ "public", "function", "postPageBlockAction", "(", "$", "id", ",", "Request", "$", "request", ")", "{", "$", "page", "=", "$", "id", "?", "$", "this", "->", "getPage", "(", "$", "id", ")", ":", "null", ";", "$", "form", "=", "$", "this", "->", "fo...
Adds a block. @ApiDoc( requirements={ {"name"="id", "dataType"="integer", "requirement"="\d+", "description"="page identifier"} }, input={"class"="sonata_page_api_form_block", "name"="", "groups"={"sonata_api_write"}}, output={"class"="Sonata\PageBundle\Model\Block", "groups"={"sonata_api_read"}}, statusCodes={ 200="Returned when successful", 400="Returned when an error has occurred while block creation", 404="Returned when unable to find page" } ) @View(serializerGroups={"sonata_api_read"}, serializerEnableMaxDepthChecks=true) @param int $id A Page identifier @param Request $request A Symfony request @throws NotFoundHttpException @return BlockInterface
[ "Adds", "a", "block", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/Controller/Api/PageController.php#L237-L257
train
sonata-project/SonataPageBundle
src/Controller/Api/PageController.php
PageController.deletePageAction
public function deletePageAction($id) { $page = $this->getPage($id); $this->pageManager->delete($page); return ['deleted' => true]; }
php
public function deletePageAction($id) { $page = $this->getPage($id); $this->pageManager->delete($page); return ['deleted' => true]; }
[ "public", "function", "deletePageAction", "(", "$", "id", ")", "{", "$", "page", "=", "$", "this", "->", "getPage", "(", "$", "id", ")", ";", "$", "this", "->", "pageManager", "->", "delete", "(", "$", "page", ")", ";", "return", "[", "'deleted'", ...
Deletes a page. @ApiDoc( requirements={ {"name"="id", "dataType"="integer", "requirement"="\d+", "description"="page identifier"} }, statusCodes={ 200="Returned when page is successfully deleted", 400="Returned when an error has occurred while page deletion", 404="Returned when unable to find page" } ) @param int $id A Page identifier @throws NotFoundHttpException @return \FOS\RestBundle\View\View
[ "Deletes", "a", "page", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/Controller/Api/PageController.php#L331-L338
train
sonata-project/SonataPageBundle
src/Controller/Api/PageController.php
PageController.postPageSnapshotAction
public function postPageSnapshotAction($id) { $page = $this->getPage($id); $this->backend->createAndPublish('sonata.page.create_snapshot', [ 'pageId' => $page->getId(), ]); return ['queued' => true]; }
php
public function postPageSnapshotAction($id) { $page = $this->getPage($id); $this->backend->createAndPublish('sonata.page.create_snapshot', [ 'pageId' => $page->getId(), ]); return ['queued' => true]; }
[ "public", "function", "postPageSnapshotAction", "(", "$", "id", ")", "{", "$", "page", "=", "$", "this", "->", "getPage", "(", "$", "id", ")", ";", "$", "this", "->", "backend", "->", "createAndPublish", "(", "'sonata.page.create_snapshot'", ",", "[", "'pa...
Creates snapshots of a page. @ApiDoc( requirements={ {"name"="id", "dataType"="integer", "requirement"="\d+", "description"="page identifier"} }, statusCodes={ 200="Returned when snapshots are successfully queued for creation", 400="Returned when an error has occurred while snapshots creation", 404="Returned when unable to find page" } ) @param int $id A Page identifier @throws NotFoundHttpException @return \FOS\RestBundle\View\View
[ "Creates", "snapshots", "of", "a", "page", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/Controller/Api/PageController.php#L360-L369
train
sonata-project/SonataPageBundle
src/Controller/Api/PageController.php
PageController.postPagesSnapshotsAction
public function postPagesSnapshotsAction() { $sites = $this->siteManager->findAll(); foreach ($sites as $site) { $this->backend->createAndPublish('sonata.page.create_snapshot', [ 'siteId' => $site->getId(), ]); } return ['queued' => true]; }
php
public function postPagesSnapshotsAction() { $sites = $this->siteManager->findAll(); foreach ($sites as $site) { $this->backend->createAndPublish('sonata.page.create_snapshot', [ 'siteId' => $site->getId(), ]); } return ['queued' => true]; }
[ "public", "function", "postPagesSnapshotsAction", "(", ")", "{", "$", "sites", "=", "$", "this", "->", "siteManager", "->", "findAll", "(", ")", ";", "foreach", "(", "$", "sites", "as", "$", "site", ")", "{", "$", "this", "->", "backend", "->", "create...
Creates snapshots of all pages. @ApiDoc( statusCodes={ 200="Returned when snapshots are successfully queued for creation", 400="Returned when an error has occurred while snapshots creation", } ) @throws NotFoundHttpException @return \FOS\RestBundle\View\View
[ "Creates", "snapshots", "of", "all", "pages", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/Controller/Api/PageController.php#L385-L396
train
sonata-project/SonataPageBundle
src/Controller/Api/PageController.php
PageController.handleWritePage
protected function handleWritePage($request, $id = null) { $page = $id ? $this->getPage($id) : null; $form = $this->formFactory->createNamed(null, 'sonata_page_api_form_page', $page, [ 'csrf_protection' => false, ]); $form->handleRequest($request); if ($form->isValid()) { $page = $form->getData(); $this->pageManager->save($page); return $this->serializeContext($page, ['sonata_api_read']); } return $form; }
php
protected function handleWritePage($request, $id = null) { $page = $id ? $this->getPage($id) : null; $form = $this->formFactory->createNamed(null, 'sonata_page_api_form_page', $page, [ 'csrf_protection' => false, ]); $form->handleRequest($request); if ($form->isValid()) { $page = $form->getData(); $this->pageManager->save($page); return $this->serializeContext($page, ['sonata_api_read']); } return $form; }
[ "protected", "function", "handleWritePage", "(", "$", "request", ",", "$", "id", "=", "null", ")", "{", "$", "page", "=", "$", "id", "?", "$", "this", "->", "getPage", "(", "$", "id", ")", ":", "null", ";", "$", "form", "=", "$", "this", "->", ...
Write a page, this method is used by both POST and PUT action methods. @param Request $request Symfony request @param int|null $id A page identifier @return FormInterface
[ "Write", "a", "page", "this", "method", "is", "used", "by", "both", "POST", "and", "PUT", "action", "methods", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/Controller/Api/PageController.php#L446-L464
train
sonata-project/SonataPageBundle
src/Model/Page.php
Page.getContainerByCode
public function getContainerByCode($code) { $block = null; foreach ($this->getBlocks() as $blockTmp) { if (\in_array($blockTmp->getType(), ['sonata.page.block.container', 'sonata.block.service.container'], true) && $blockTmp->getSetting('code') === $code) { $block = $blockTmp; break; } } return $block; }
php
public function getContainerByCode($code) { $block = null; foreach ($this->getBlocks() as $blockTmp) { if (\in_array($blockTmp->getType(), ['sonata.page.block.container', 'sonata.block.service.container'], true) && $blockTmp->getSetting('code') === $code) { $block = $blockTmp; break; } } return $block; }
[ "public", "function", "getContainerByCode", "(", "$", "code", ")", "{", "$", "block", "=", "null", ";", "foreach", "(", "$", "this", "->", "getBlocks", "(", ")", "as", "$", "blockTmp", ")", "{", "if", "(", "\\", "in_array", "(", "$", "blockTmp", "->"...
Retrieve a block by code. @param string $code @return PageBlockInterface
[ "Retrieve", "a", "block", "by", "code", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/Model/Page.php#L820-L833
train
sonata-project/SonataPageBundle
src/Model/Page.php
Page.getBlocksByType
public function getBlocksByType($type) { $blocks = []; foreach ($this->getBlocks() as $block) { if ($type === $block->getType()) { $blocks[] = $block; } } return $blocks; }
php
public function getBlocksByType($type) { $blocks = []; foreach ($this->getBlocks() as $block) { if ($type === $block->getType()) { $blocks[] = $block; } } return $blocks; }
[ "public", "function", "getBlocksByType", "(", "$", "type", ")", "{", "$", "blocks", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "getBlocks", "(", ")", "as", "$", "block", ")", "{", "if", "(", "$", "type", "===", "$", "block", "->", "ge...
Retrieve blocks by type. @param string $type @return array
[ "Retrieve", "blocks", "by", "type", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/Model/Page.php#L842-L853
train
sonata-project/SonataPageBundle
src/Model/Page.php
Page.getHeadersAsArray
protected function getHeadersAsArray($rawHeaders) { $headers = []; foreach (explode("\r\n", (string) $rawHeaders) as $header) { if (false !== strpos($header, ':')) { list($name, $headerStr) = explode(':', $header, 2); $headers[trim($name)] = trim($headerStr); } } return $headers; }
php
protected function getHeadersAsArray($rawHeaders) { $headers = []; foreach (explode("\r\n", (string) $rawHeaders) as $header) { if (false !== strpos($header, ':')) { list($name, $headerStr) = explode(':', $header, 2); $headers[trim($name)] = trim($headerStr); } } return $headers; }
[ "protected", "function", "getHeadersAsArray", "(", "$", "rawHeaders", ")", "{", "$", "headers", "=", "[", "]", ";", "foreach", "(", "explode", "(", "\"\\r\\n\"", ",", "(", "string", ")", "$", "rawHeaders", ")", "as", "$", "header", ")", "{", "if", "(",...
Converts the headers passed as string to an array. @param string $rawHeaders The headers @return array
[ "Converts", "the", "headers", "passed", "as", "string", "to", "an", "array", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/Model/Page.php#L924-L936
train
sonata-project/SonataPageBundle
src/Model/Page.php
Page.getHeadersAsString
protected function getHeadersAsString(array $headers) { $rawHeaders = []; foreach ($headers as $name => $header) { $rawHeaders[] = sprintf('%s: %s', trim($name), trim($header)); } $rawHeaders = implode("\r\n", $rawHeaders); return $rawHeaders; }
php
protected function getHeadersAsString(array $headers) { $rawHeaders = []; foreach ($headers as $name => $header) { $rawHeaders[] = sprintf('%s: %s', trim($name), trim($header)); } $rawHeaders = implode("\r\n", $rawHeaders); return $rawHeaders; }
[ "protected", "function", "getHeadersAsString", "(", "array", "$", "headers", ")", "{", "$", "rawHeaders", "=", "[", "]", ";", "foreach", "(", "$", "headers", "as", "$", "name", "=>", "$", "header", ")", "{", "$", "rawHeaders", "[", "]", "=", "sprintf",...
Converts the headers passed as an associative array to a string. @param array $headers The headers @return string
[ "Converts", "the", "headers", "passed", "as", "an", "associative", "array", "to", "a", "string", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/Model/Page.php#L945-L956
train
sonata-project/SonataPageBundle
src/Route/CmsPageRouter.php
CmsPageRouter.generateFromPage
protected function generateFromPage(PageInterface $page, array $parameters = [], $referenceType = self::ABSOLUTE_PATH) { // hybrid pages use, by definition, the default routing mechanism if ($page->isHybrid()) { return $this->router->generate($page->getRouteName(), $parameters, $referenceType); } $url = $this->getUrlFromPage($page); if (false === $url) { throw new \RuntimeException(sprintf('Page "%d" has no url or customUrl.', $page->getId())); } // NEXT_MAJOR: remove this if block if (!$this->context instanceof SiteRequestContextInterface) { @trigger_error( sprintf('Since, 3.3 when calling %s, %s::$context should implement SiteRequestContextInterface. This will become mandatory in 4.0.', __METHOD__, __CLASS__), E_USER_DEPRECATED ); return $this->decorateUrl($url, $parameters, $referenceType); } // Get current site $currentSite = $this->context->getSite(); // Change to new site $this->context->setSite($page->getSite()); // Fetch Url $decoratedUrl = $this->decorateUrl($url, $parameters, $referenceType); // Swap back to original site $this->context->setSite($currentSite); return $decoratedUrl; }
php
protected function generateFromPage(PageInterface $page, array $parameters = [], $referenceType = self::ABSOLUTE_PATH) { // hybrid pages use, by definition, the default routing mechanism if ($page->isHybrid()) { return $this->router->generate($page->getRouteName(), $parameters, $referenceType); } $url = $this->getUrlFromPage($page); if (false === $url) { throw new \RuntimeException(sprintf('Page "%d" has no url or customUrl.', $page->getId())); } // NEXT_MAJOR: remove this if block if (!$this->context instanceof SiteRequestContextInterface) { @trigger_error( sprintf('Since, 3.3 when calling %s, %s::$context should implement SiteRequestContextInterface. This will become mandatory in 4.0.', __METHOD__, __CLASS__), E_USER_DEPRECATED ); return $this->decorateUrl($url, $parameters, $referenceType); } // Get current site $currentSite = $this->context->getSite(); // Change to new site $this->context->setSite($page->getSite()); // Fetch Url $decoratedUrl = $this->decorateUrl($url, $parameters, $referenceType); // Swap back to original site $this->context->setSite($currentSite); return $decoratedUrl; }
[ "protected", "function", "generateFromPage", "(", "PageInterface", "$", "page", ",", "array", "$", "parameters", "=", "[", "]", ",", "$", "referenceType", "=", "self", "::", "ABSOLUTE_PATH", ")", "{", "// hybrid pages use, by definition, the default routing mechanism", ...
Generates an URL from a Page object. We swap site context to make sure the right context is used when generating the url. @param PageInterface $page Page object @param array $parameters An array of parameters @param bool|string $referenceType The type of reference to be generated (one of the constants) @throws \RuntimeException @return string
[ "Generates", "an", "URL", "from", "a", "Page", "object", ".", "We", "swap", "site", "context", "to", "make", "sure", "the", "right", "context", "is", "used", "when", "generating", "the", "url", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/Route/CmsPageRouter.php#L201-L234
train
sonata-project/SonataPageBundle
src/Route/CmsPageRouter.php
CmsPageRouter.generateFromPageSlug
protected function generateFromPageSlug(array $parameters = [], $referenceType = self::ABSOLUTE_PATH) { if (!isset($parameters['path'])) { throw new \RuntimeException('Please provide a `path` parameters'); } $url = $parameters['path']; unset($parameters['path']); return $this->decorateUrl($url, $parameters, $referenceType); }
php
protected function generateFromPageSlug(array $parameters = [], $referenceType = self::ABSOLUTE_PATH) { if (!isset($parameters['path'])) { throw new \RuntimeException('Please provide a `path` parameters'); } $url = $parameters['path']; unset($parameters['path']); return $this->decorateUrl($url, $parameters, $referenceType); }
[ "protected", "function", "generateFromPageSlug", "(", "array", "$", "parameters", "=", "[", "]", ",", "$", "referenceType", "=", "self", "::", "ABSOLUTE_PATH", ")", "{", "if", "(", "!", "isset", "(", "$", "parameters", "[", "'path'", "]", ")", ")", "{", ...
Generates an URL for a page slug. @param array $parameters An array of parameters @param bool|string $referenceType The type of reference to be generated (one of the constants) @throws \RuntimeException @return string
[ "Generates", "an", "URL", "for", "a", "page", "slug", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/Route/CmsPageRouter.php#L246-L256
train
sonata-project/SonataPageBundle
src/Route/CmsPageRouter.php
CmsPageRouter.decorateUrl
protected function decorateUrl($url, array $parameters = [], $referenceType = self::ABSOLUTE_PATH) { if (!$this->context) { throw new \RuntimeException('No context associated to the CmsPageRouter'); } $schemeAuthority = ''; if ($this->context->getHost() && (self::ABSOLUTE_URL === $referenceType || self::NETWORK_PATH === $referenceType)) { $port = ''; if ('http' === $this->context->getScheme() && 80 !== $this->context->getHttpPort()) { $port = sprintf(':%s', $this->context->getHttpPort()); } elseif ('https' === $this->context->getScheme() && 443 !== $this->context->getHttpsPort()) { $port = sprintf(':%s', $this->context->getHttpsPort()); } $schemeAuthority = self::NETWORK_PATH === $referenceType ? '//' : sprintf('%s://', $this->context->getScheme()); $schemeAuthority = sprintf('%s%s%s', $schemeAuthority, $this->context->getHost(), $port); } if (self::RELATIVE_PATH === $referenceType) { $url = $this->getRelativePath($this->context->getPathInfo(), $url); } else { $url = sprintf('%s%s%s', $schemeAuthority, $this->context->getBaseUrl(), $url); } if (\count($parameters) > 0) { return sprintf('%s?%s', $url, http_build_query($parameters, '', '&')); } return $url; }
php
protected function decorateUrl($url, array $parameters = [], $referenceType = self::ABSOLUTE_PATH) { if (!$this->context) { throw new \RuntimeException('No context associated to the CmsPageRouter'); } $schemeAuthority = ''; if ($this->context->getHost() && (self::ABSOLUTE_URL === $referenceType || self::NETWORK_PATH === $referenceType)) { $port = ''; if ('http' === $this->context->getScheme() && 80 !== $this->context->getHttpPort()) { $port = sprintf(':%s', $this->context->getHttpPort()); } elseif ('https' === $this->context->getScheme() && 443 !== $this->context->getHttpsPort()) { $port = sprintf(':%s', $this->context->getHttpsPort()); } $schemeAuthority = self::NETWORK_PATH === $referenceType ? '//' : sprintf('%s://', $this->context->getScheme()); $schemeAuthority = sprintf('%s%s%s', $schemeAuthority, $this->context->getHost(), $port); } if (self::RELATIVE_PATH === $referenceType) { $url = $this->getRelativePath($this->context->getPathInfo(), $url); } else { $url = sprintf('%s%s%s', $schemeAuthority, $this->context->getBaseUrl(), $url); } if (\count($parameters) > 0) { return sprintf('%s?%s', $url, http_build_query($parameters, '', '&')); } return $url; }
[ "protected", "function", "decorateUrl", "(", "$", "url", ",", "array", "$", "parameters", "=", "[", "]", ",", "$", "referenceType", "=", "self", "::", "ABSOLUTE_PATH", ")", "{", "if", "(", "!", "$", "this", "->", "context", ")", "{", "throw", "new", ...
Decorates an URL with url context and query. @param string $url Relative URL @param array $parameters An array of parameters @param bool|string $referenceType The type of reference to be generated (one of the constants) @throws \RuntimeException @return string
[ "Decorates", "an", "URL", "with", "url", "context", "and", "query", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/Route/CmsPageRouter.php#L269-L299
train
sonata-project/SonataPageBundle
src/Route/CmsPageRouter.php
CmsPageRouter.getPageByPageAlias
protected function getPageByPageAlias($alias) { $site = $this->siteSelector->retrieve(); $page = $this->cmsSelector->retrieve()->getPageByPageAlias($site, $alias); return $page; }
php
protected function getPageByPageAlias($alias) { $site = $this->siteSelector->retrieve(); $page = $this->cmsSelector->retrieve()->getPageByPageAlias($site, $alias); return $page; }
[ "protected", "function", "getPageByPageAlias", "(", "$", "alias", ")", "{", "$", "site", "=", "$", "this", "->", "siteSelector", "->", "retrieve", "(", ")", ";", "$", "page", "=", "$", "this", "->", "cmsSelector", "->", "retrieve", "(", ")", "->", "get...
Retrieves a page object from a page alias. @param string $alias @throws PageNotFoundException @return \Sonata\PageBundle\Model\PageInterface|null
[ "Retrieves", "a", "page", "object", "from", "a", "page", "alias", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/Route/CmsPageRouter.php#L323-L329
train
sonata-project/SonataPageBundle
src/Model/SnapshotPageProxy.php
SnapshotPageProxy.serialize
public function serialize() { if ($this->manager) { return serialize([ 'pageId' => $this->getPage()->getId(), 'snapshotId' => $this->snapshot->getId(), ]); } return serialize([]); }
php
public function serialize() { if ($this->manager) { return serialize([ 'pageId' => $this->getPage()->getId(), 'snapshotId' => $this->snapshot->getId(), ]); } return serialize([]); }
[ "public", "function", "serialize", "(", ")", "{", "if", "(", "$", "this", "->", "manager", ")", "{", "return", "serialize", "(", "[", "'pageId'", "=>", "$", "this", "->", "getPage", "(", ")", "->", "getId", "(", ")", ",", "'snapshotId'", "=>", "$", ...
Serialize a snapshot page proxy. @return string
[ "Serialize", "a", "snapshot", "page", "proxy", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/Model/SnapshotPageProxy.php#L673-L683
train
sonata-project/SonataPageBundle
src/Twig/Extension/PageExtension.php
PageExtension.ajaxUrl
public function ajaxUrl(PageBlockInterface $block, $parameters = [], $absolute = UrlGeneratorInterface::ABSOLUTE_PATH) { $parameters['blockId'] = $block->getId(); if ($block->getPage() instanceof PageInterface) { $parameters['pageId'] = $block->getPage()->getId(); } return $this->router->generate('sonata_page_ajax_block', $parameters, $absolute); }
php
public function ajaxUrl(PageBlockInterface $block, $parameters = [], $absolute = UrlGeneratorInterface::ABSOLUTE_PATH) { $parameters['blockId'] = $block->getId(); if ($block->getPage() instanceof PageInterface) { $parameters['pageId'] = $block->getPage()->getId(); } return $this->router->generate('sonata_page_ajax_block', $parameters, $absolute); }
[ "public", "function", "ajaxUrl", "(", "PageBlockInterface", "$", "block", ",", "$", "parameters", "=", "[", "]", ",", "$", "absolute", "=", "UrlGeneratorInterface", "::", "ABSOLUTE_PATH", ")", "{", "$", "parameters", "[", "'blockId'", "]", "=", "$", "block",...
Returns the URL for an ajax request for given block. @param PageBlockInterface $block Block service @param array $parameters Provide absolute or relative url ? @param bool $absolute @return string
[ "Returns", "the", "URL", "for", "an", "ajax", "request", "for", "given", "block", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/Twig/Extension/PageExtension.php#L185-L194
train
sonata-project/SonataPageBundle
src/Twig/Extension/PageExtension.php
PageExtension.controller
public function controller($controller, $attributes = [], $query = []) { if (!isset($attributes['pathInfo'])) { $site = $this->siteSelector->retrieve(); if ($site) { $sitePath = $site->getRelativePath(); $globals = $this->environment->getGlobals(); $currentPathInfo = $globals['app']->getRequest()->getPathInfo(); $attributes['pathInfo'] = $sitePath.$currentPathInfo; } } // Simplify this when dropping twig-bridge < 3.2 support if (method_exists(AppVariable::class, 'getToken')) { return HttpKernelExtension::controller($controller, $attributes, $query); } return $this->httpKernelExtension->controller($controller, $attributes, $query); }
php
public function controller($controller, $attributes = [], $query = []) { if (!isset($attributes['pathInfo'])) { $site = $this->siteSelector->retrieve(); if ($site) { $sitePath = $site->getRelativePath(); $globals = $this->environment->getGlobals(); $currentPathInfo = $globals['app']->getRequest()->getPathInfo(); $attributes['pathInfo'] = $sitePath.$currentPathInfo; } } // Simplify this when dropping twig-bridge < 3.2 support if (method_exists(AppVariable::class, 'getToken')) { return HttpKernelExtension::controller($controller, $attributes, $query); } return $this->httpKernelExtension->controller($controller, $attributes, $query); }
[ "public", "function", "controller", "(", "$", "controller", ",", "$", "attributes", "=", "[", "]", ",", "$", "query", "=", "[", "]", ")", "{", "if", "(", "!", "isset", "(", "$", "attributes", "[", "'pathInfo'", "]", ")", ")", "{", "$", "site", "=...
Forwards pathInfo to subrequests. Allows HostPathSiteSelector to work. @param string $controller @param array $attributes @param array $query @return ControllerReference
[ "Forwards", "pathInfo", "to", "subrequests", ".", "Allows", "HostPathSiteSelector", "to", "work", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/Twig/Extension/PageExtension.php#L275-L294
train
sonata-project/SonataPageBundle
src/Page/TemplateManager.php
TemplateManager.getTemplatePath
protected function getTemplatePath($code) { $code = $code ?: $this->getDefaultTemplateCode(); $template = $this->get($code); return $template ? $template->getPath() : $this->defaultTemplatePath; }
php
protected function getTemplatePath($code) { $code = $code ?: $this->getDefaultTemplateCode(); $template = $this->get($code); return $template ? $template->getPath() : $this->defaultTemplatePath; }
[ "protected", "function", "getTemplatePath", "(", "$", "code", ")", "{", "$", "code", "=", "$", "code", "?", ":", "$", "this", "->", "getDefaultTemplateCode", "(", ")", ";", "$", "template", "=", "$", "this", "->", "get", "(", "$", "code", ")", ";", ...
Returns the template path for given code. @param string|null $code @return string
[ "Returns", "the", "template", "path", "for", "given", "code", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/Page/TemplateManager.php#L141-L147
train
sonata-project/SonataPageBundle
src/Controller/Api/BlockController.php
BlockController.deleteBlockAction
public function deleteBlockAction($id) { $block = $this->getBlock($id); $this->blockManager->delete($block); return ['deleted' => true]; }
php
public function deleteBlockAction($id) { $block = $this->getBlock($id); $this->blockManager->delete($block); return ['deleted' => true]; }
[ "public", "function", "deleteBlockAction", "(", "$", "id", ")", "{", "$", "block", "=", "$", "this", "->", "getBlock", "(", "$", "id", ")", ";", "$", "this", "->", "blockManager", "->", "delete", "(", "$", "block", ")", ";", "return", "[", "'deleted'...
Deletes a block. @ApiDoc( requirements={ {"name"="id", "dataType"="integer", "requirement"="\d+", "description"="block identifier"} }, statusCodes={ 200="Returned when block is successfully deleted", 400="Returned when an error has occurred while block deletion", 404="Returned when unable to find block" } ) @param int $id A Block identifier @throws NotFoundHttpException @return \FOS\RestBundle\View\View
[ "Deletes", "a", "block", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/Controller/Api/BlockController.php#L141-L148
train
sonata-project/SonataPageBundle
src/Site/BaseSiteSelector.php
BaseSiteSelector.matchRequest
protected function matchRequest(SiteInterface $site, Request $request) { $results = []; // we read the value from the attribute to handle fragment support $requestPathInfo = $request->get('pathInfo', $request->getPathInfo()); if (!preg_match(sprintf('@^(%s)(/.*|$)@', $site->getRelativePath()), $requestPathInfo, $results)) { return false; } return $results[2]; }
php
protected function matchRequest(SiteInterface $site, Request $request) { $results = []; // we read the value from the attribute to handle fragment support $requestPathInfo = $request->get('pathInfo', $request->getPathInfo()); if (!preg_match(sprintf('@^(%s)(/.*|$)@', $site->getRelativePath()), $requestPathInfo, $results)) { return false; } return $results[2]; }
[ "protected", "function", "matchRequest", "(", "SiteInterface", "$", "site", ",", "Request", "$", "request", ")", "{", "$", "results", "=", "[", "]", ";", "// we read the value from the attribute to handle fragment support", "$", "requestPathInfo", "=", "$", "request",...
Returns TRUE whether the given site matches the given request. @param SiteInterface $site A site instance @param Request $request A request instance @return string|bool FALSE whether the site does not match
[ "Returns", "TRUE", "whether", "the", "given", "site", "matches", "the", "given", "request", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/Site/BaseSiteSelector.php#L137-L149
train
sonata-project/SonataPageBundle
src/Site/BaseSiteSelector.php
BaseSiteSelector.getPreferredSite
protected function getPreferredSite(array $sites, Request $request) { if (0 === \count($sites)) { return; } $sitesLocales = array_map(static function (SiteInterface $site) { return $site->getLocale(); }, $sites); $language = $request->getPreferredLanguage($sitesLocales); $host = $request->getHost(); foreach ($sites as $site) { if (\in_array($site->getHost(), ['localhost', $host], true) && $language === $site->getLocale()) { return $site; } } return reset($sites); }
php
protected function getPreferredSite(array $sites, Request $request) { if (0 === \count($sites)) { return; } $sitesLocales = array_map(static function (SiteInterface $site) { return $site->getLocale(); }, $sites); $language = $request->getPreferredLanguage($sitesLocales); $host = $request->getHost(); foreach ($sites as $site) { if (\in_array($site->getHost(), ['localhost', $host], true) && $language === $site->getLocale()) { return $site; } } return reset($sites); }
[ "protected", "function", "getPreferredSite", "(", "array", "$", "sites", ",", "Request", "$", "request", ")", "{", "if", "(", "0", "===", "\\", "count", "(", "$", "sites", ")", ")", "{", "return", ";", "}", "$", "sitesLocales", "=", "array_map", "(", ...
Gets the preferred site based on the given request. @param array $sites An array of enabled sites @param Request $request A request instance @return SiteInterface|null
[ "Gets", "the", "preferred", "site", "based", "on", "the", "given", "request", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/Site/BaseSiteSelector.php#L159-L179
train
sonata-project/SonataPageBundle
src/DependencyInjection/SonataPageExtension.php
SonataPageExtension.configurePageDefaults
public function configurePageDefaults(ContainerBuilder $container, array $config) { $defaults = [ 'templateCode' => $config['default_template'], 'enabled' => true, 'routeName' => null, 'name' => null, 'slug' => null, 'url' => null, 'requestMethod' => null, 'decorate' => true, ]; $container->getDefinition('sonata.page.manager.page') ->replaceArgument(2, $defaults); foreach ($config['page_defaults'] as $name => $pageDefaults) { $config['page_defaults'][$name] = array_merge($defaults, $pageDefaults); } $container->getDefinition('sonata.page.manager.page') ->replaceArgument(3, $config['page_defaults']); }
php
public function configurePageDefaults(ContainerBuilder $container, array $config) { $defaults = [ 'templateCode' => $config['default_template'], 'enabled' => true, 'routeName' => null, 'name' => null, 'slug' => null, 'url' => null, 'requestMethod' => null, 'decorate' => true, ]; $container->getDefinition('sonata.page.manager.page') ->replaceArgument(2, $defaults); foreach ($config['page_defaults'] as $name => $pageDefaults) { $config['page_defaults'][$name] = array_merge($defaults, $pageDefaults); } $container->getDefinition('sonata.page.manager.page') ->replaceArgument(3, $config['page_defaults']); }
[ "public", "function", "configurePageDefaults", "(", "ContainerBuilder", "$", "container", ",", "array", "$", "config", ")", "{", "$", "defaults", "=", "[", "'templateCode'", "=>", "$", "config", "[", "'default_template'", "]", ",", "'enabled'", "=>", "true", "...
Configure the page default settings. @param ContainerBuilder $container Container builder @param array $config Array of configuration
[ "Configure", "the", "page", "default", "settings", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/DependencyInjection/SonataPageExtension.php#L118-L140
train
sonata-project/SonataPageBundle
src/DependencyInjection/SonataPageExtension.php
SonataPageExtension.configureMultisite
public function configureMultisite(ContainerBuilder $container, array $config) { $multisite = $config['multisite']; if ('host' === $multisite) { $container->setAlias('sonata.page.site.selector', 'sonata.page.site.selector.host'); $container->removeDefinition('sonata.page.site.selector.host_by_locale'); $container->removeDefinition('sonata.page.site.selector.host_with_path'); $container->removeDefinition('sonata.page.site.selector.host_with_path_by_locale'); } elseif ('host_by_locale' === $multisite) { $container->setAlias('sonata.page.site.selector', 'sonata.page.site.selector.host_by_locale'); $container->removeDefinition('sonata.page.site.selector.host'); $container->removeDefinition('sonata.page.site.selector.host_with_path'); $container->removeDefinition('sonata.page.site.selector.host_with_path_by_locale'); } else { /* * The multipath option required a specific router and RequestContext */ $container->setAlias('router.request_context', 'sonata.page.router.request_context'); if ('host_with_path' === $multisite) { $container->setAlias('sonata.page.site.selector', 'sonata.page.site.selector.host_with_path'); $container->removeDefinition('sonata.page.site.selector.host_with_path_by_locale'); $container->removeDefinition('sonata.page.site.selector.host'); $container->removeDefinition('sonata.page.site.selector.host_by_locale'); } elseif ('host_with_path_by_locale' === $multisite) { $container->setAlias('sonata.page.site.selector', 'sonata.page.site.selector.host_with_path_by_locale'); $container->removeDefinition('sonata.page.site.selector.host_with_path'); $container->removeDefinition('sonata.page.site.selector.host'); $container->removeDefinition('sonata.page.site.selector.host_by_locale'); } } if ($container->hasAlias('sonata.page.site.selector')) { $container->getAlias('sonata.page.site.selector')->setPublic(true); } }
php
public function configureMultisite(ContainerBuilder $container, array $config) { $multisite = $config['multisite']; if ('host' === $multisite) { $container->setAlias('sonata.page.site.selector', 'sonata.page.site.selector.host'); $container->removeDefinition('sonata.page.site.selector.host_by_locale'); $container->removeDefinition('sonata.page.site.selector.host_with_path'); $container->removeDefinition('sonata.page.site.selector.host_with_path_by_locale'); } elseif ('host_by_locale' === $multisite) { $container->setAlias('sonata.page.site.selector', 'sonata.page.site.selector.host_by_locale'); $container->removeDefinition('sonata.page.site.selector.host'); $container->removeDefinition('sonata.page.site.selector.host_with_path'); $container->removeDefinition('sonata.page.site.selector.host_with_path_by_locale'); } else { /* * The multipath option required a specific router and RequestContext */ $container->setAlias('router.request_context', 'sonata.page.router.request_context'); if ('host_with_path' === $multisite) { $container->setAlias('sonata.page.site.selector', 'sonata.page.site.selector.host_with_path'); $container->removeDefinition('sonata.page.site.selector.host_with_path_by_locale'); $container->removeDefinition('sonata.page.site.selector.host'); $container->removeDefinition('sonata.page.site.selector.host_by_locale'); } elseif ('host_with_path_by_locale' === $multisite) { $container->setAlias('sonata.page.site.selector', 'sonata.page.site.selector.host_with_path_by_locale'); $container->removeDefinition('sonata.page.site.selector.host_with_path'); $container->removeDefinition('sonata.page.site.selector.host'); $container->removeDefinition('sonata.page.site.selector.host_by_locale'); } } if ($container->hasAlias('sonata.page.site.selector')) { $container->getAlias('sonata.page.site.selector')->setPublic(true); } }
[ "public", "function", "configureMultisite", "(", "ContainerBuilder", "$", "container", ",", "array", "$", "config", ")", "{", "$", "multisite", "=", "$", "config", "[", "'multisite'", "]", ";", "if", "(", "'host'", "===", "$", "multisite", ")", "{", "$", ...
Configure the multi-site feature. @param ContainerBuilder $container Container builder @param array $config Array of configuration
[ "Configure", "the", "multi", "-", "site", "feature", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/DependencyInjection/SonataPageExtension.php#L367-L407
train
sonata-project/SonataPageBundle
src/DependencyInjection/SonataPageExtension.php
SonataPageExtension.configureTemplates
public function configureTemplates(ContainerBuilder $container, array $config) { $templateManager = $container->getDefinition('sonata.page.template_manager'); // add all templates to manager $definitions = []; foreach ($config['templates'] as $code => $info) { $definition = new Definition(Template::class, [ $info['name'], $info['path'], $info['containers'], ]); $definition->setPublic(false); $definitions[$code] = $definition; } $templateManager->addMethodCall('setAll', [$definitions]); // set default template $templateManager->addMethodCall('setDefaultTemplateCode', [$config['default_template']]); }
php
public function configureTemplates(ContainerBuilder $container, array $config) { $templateManager = $container->getDefinition('sonata.page.template_manager'); // add all templates to manager $definitions = []; foreach ($config['templates'] as $code => $info) { $definition = new Definition(Template::class, [ $info['name'], $info['path'], $info['containers'], ]); $definition->setPublic(false); $definitions[$code] = $definition; } $templateManager->addMethodCall('setAll', [$definitions]); // set default template $templateManager->addMethodCall('setDefaultTemplateCode', [$config['default_template']]); }
[ "public", "function", "configureTemplates", "(", "ContainerBuilder", "$", "container", ",", "array", "$", "config", ")", "{", "$", "templateManager", "=", "$", "container", "->", "getDefinition", "(", "'sonata.page.template_manager'", ")", ";", "// add all templates t...
Configure the page templates. @param ContainerBuilder $container Container builder @param array $config Array of configuration
[ "Configure", "the", "page", "templates", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/DependencyInjection/SonataPageExtension.php#L415-L436
train
sonata-project/SonataPageBundle
src/DependencyInjection/SonataPageExtension.php
SonataPageExtension.configureTemplatesAdmin
public function configureTemplatesAdmin(ContainerBuilder $container, array $config) { $templateManager = $container->getDefinition('sonata.page.admin.page'); $definitions = $config['templates_admin']; $templateManager->addMethodCall('setTemplates', [$definitions]); }
php
public function configureTemplatesAdmin(ContainerBuilder $container, array $config) { $templateManager = $container->getDefinition('sonata.page.admin.page'); $definitions = $config['templates_admin']; $templateManager->addMethodCall('setTemplates', [$definitions]); }
[ "public", "function", "configureTemplatesAdmin", "(", "ContainerBuilder", "$", "container", ",", "array", "$", "config", ")", "{", "$", "templateManager", "=", "$", "container", "->", "getDefinition", "(", "'sonata.page.admin.page'", ")", ";", "$", "definitions", ...
Configure the page admin templates. @param ContainerBuilder $container Container builder @param array $config Array of configuration
[ "Configure", "the", "page", "admin", "templates", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/DependencyInjection/SonataPageExtension.php#L444-L451
train
sonata-project/SonataPageBundle
src/DependencyInjection/SonataPageExtension.php
SonataPageExtension.configureCache
public function configureCache(ContainerBuilder $container, array $config) { if (isset($config['caches']['esi'])) { $container ->getDefinition('sonata.page.cache.esi') ->replaceArgument(0, $config['caches']['esi']['token']) ->replaceArgument(1, $config['caches']['esi']['servers']) ->replaceArgument(3, 3 === $config['caches']['esi']['version'] ? 'ban' : 'purge'); } else { $container->removeDefinition('sonata.page.cache.esi'); } if (isset($config['caches']['ssi'])) { $container ->getDefinition('sonata.page.cache.ssi') ->replaceArgument(0, $config['caches']['ssi']['token']); } else { $container->removeDefinition('sonata.page.cache.ssi'); } }
php
public function configureCache(ContainerBuilder $container, array $config) { if (isset($config['caches']['esi'])) { $container ->getDefinition('sonata.page.cache.esi') ->replaceArgument(0, $config['caches']['esi']['token']) ->replaceArgument(1, $config['caches']['esi']['servers']) ->replaceArgument(3, 3 === $config['caches']['esi']['version'] ? 'ban' : 'purge'); } else { $container->removeDefinition('sonata.page.cache.esi'); } if (isset($config['caches']['ssi'])) { $container ->getDefinition('sonata.page.cache.ssi') ->replaceArgument(0, $config['caches']['ssi']['token']); } else { $container->removeDefinition('sonata.page.cache.ssi'); } }
[ "public", "function", "configureCache", "(", "ContainerBuilder", "$", "container", ",", "array", "$", "config", ")", "{", "if", "(", "isset", "(", "$", "config", "[", "'caches'", "]", "[", "'esi'", "]", ")", ")", "{", "$", "container", "->", "getDefiniti...
Configure the cache options. @param ContainerBuilder $container Container builder @param array $config Array of configuration
[ "Configure", "the", "cache", "options", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/DependencyInjection/SonataPageExtension.php#L459-L478
train
sonata-project/SonataPageBundle
src/DependencyInjection/SonataPageExtension.php
SonataPageExtension.configureExceptions
public function configureExceptions(ContainerBuilder $container, array $config) { $exceptions = []; foreach ($config['catch_exceptions'] as $keyWord => $codes) { foreach ($codes as $code) { $exceptions[$code] = sprintf('_page_internal_error_%s', $keyWord); } } // add exception pages in exception_listener $container->getDefinition('sonata.page.kernel.exception_listener') ->replaceArgument(6, $exceptions); // add exception pages as default rendering parameters in page templates $container->getDefinition('sonata.page.template_manager') ->replaceArgument(1, ['error_codes' => $exceptions]); }
php
public function configureExceptions(ContainerBuilder $container, array $config) { $exceptions = []; foreach ($config['catch_exceptions'] as $keyWord => $codes) { foreach ($codes as $code) { $exceptions[$code] = sprintf('_page_internal_error_%s', $keyWord); } } // add exception pages in exception_listener $container->getDefinition('sonata.page.kernel.exception_listener') ->replaceArgument(6, $exceptions); // add exception pages as default rendering parameters in page templates $container->getDefinition('sonata.page.template_manager') ->replaceArgument(1, ['error_codes' => $exceptions]); }
[ "public", "function", "configureExceptions", "(", "ContainerBuilder", "$", "container", ",", "array", "$", "config", ")", "{", "$", "exceptions", "=", "[", "]", ";", "foreach", "(", "$", "config", "[", "'catch_exceptions'", "]", "as", "$", "keyWord", "=>", ...
Configures the page custom exceptions. @param ContainerBuilder $container Container builder @param array $config An array of bundle configuration
[ "Configures", "the", "page", "custom", "exceptions", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/DependencyInjection/SonataPageExtension.php#L486-L502
train
sonata-project/SonataPageBundle
src/DependencyInjection/SonataPageExtension.php
SonataPageExtension.configurePageServices
public function configurePageServices(ContainerBuilder $container, array $config) { // set the default page service to use when no page type has been set. (backward compatibility) $definition = $container->getDefinition('sonata.page.page_service_manager'); $definition->addMethodCall('setDefault', [new Reference($config['default_page_service'])]); }
php
public function configurePageServices(ContainerBuilder $container, array $config) { // set the default page service to use when no page type has been set. (backward compatibility) $definition = $container->getDefinition('sonata.page.page_service_manager'); $definition->addMethodCall('setDefault', [new Reference($config['default_page_service'])]); }
[ "public", "function", "configurePageServices", "(", "ContainerBuilder", "$", "container", ",", "array", "$", "config", ")", "{", "// set the default page service to use when no page type has been set. (backward compatibility)", "$", "definition", "=", "$", "container", "->", ...
Configures the page services. @param ContainerBuilder $container Container builder @param array $config An array of bundle configuration
[ "Configures", "the", "page", "services", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/DependencyInjection/SonataPageExtension.php#L510-L515
train
sonata-project/SonataPageBundle
src/Listener/RequestListener.php
RequestListener.onCoreRequest
public function onCoreRequest(GetResponseEvent $event) { $request = $event->getRequest(); $cms = $this->cmsSelector->retrieve(); if (!$cms) { throw new InternalErrorException('No CMS Manager available'); } // true cms page if (PageInterface::PAGE_ROUTE_CMS_NAME === $request->get('_route')) { return; } if (!$this->decoratorStrategy->isRequestDecorable($request)) { return; } $site = $this->siteSelector->retrieve(); if (!$site) { throw new InternalErrorException('No site available for the current request with uri '.htmlspecialchars($request->getUri(), ENT_QUOTES)); } if ($site->getLocale() && $site->getLocale() !== $request->get('_locale')) { throw new PageNotFoundException(sprintf('Invalid locale - site.locale=%s - request._locale=%s', $site->getLocale(), $request->get('_locale'))); } try { $page = $cms->getPageByRouteName($site, $request->get('_route')); if (!$page->getEnabled() && !$this->cmsSelector->isEditor()) { throw new PageNotFoundException(sprintf('The page is not enabled : id=%s', $page->getId())); } $cms->setCurrentPage($page); } catch (PageNotFoundException $e) { return; } }
php
public function onCoreRequest(GetResponseEvent $event) { $request = $event->getRequest(); $cms = $this->cmsSelector->retrieve(); if (!$cms) { throw new InternalErrorException('No CMS Manager available'); } // true cms page if (PageInterface::PAGE_ROUTE_CMS_NAME === $request->get('_route')) { return; } if (!$this->decoratorStrategy->isRequestDecorable($request)) { return; } $site = $this->siteSelector->retrieve(); if (!$site) { throw new InternalErrorException('No site available for the current request with uri '.htmlspecialchars($request->getUri(), ENT_QUOTES)); } if ($site->getLocale() && $site->getLocale() !== $request->get('_locale')) { throw new PageNotFoundException(sprintf('Invalid locale - site.locale=%s - request._locale=%s', $site->getLocale(), $request->get('_locale'))); } try { $page = $cms->getPageByRouteName($site, $request->get('_route')); if (!$page->getEnabled() && !$this->cmsSelector->isEditor()) { throw new PageNotFoundException(sprintf('The page is not enabled : id=%s', $page->getId())); } $cms->setCurrentPage($page); } catch (PageNotFoundException $e) { return; } }
[ "public", "function", "onCoreRequest", "(", "GetResponseEvent", "$", "event", ")", "{", "$", "request", "=", "$", "event", "->", "getRequest", "(", ")", ";", "$", "cms", "=", "$", "this", "->", "cmsSelector", "->", "retrieve", "(", ")", ";", "if", "(",...
Filter the `core.request` event to decorated the action. @param GetResponseEvent $event @throws InternalErrorException @throws PageNotFoundException
[ "Filter", "the", "core", ".", "request", "event", "to", "decorated", "the", "action", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/Listener/RequestListener.php#L68-L107
train
sonata-project/SonataPageBundle
src/Entity/SnapshotManager.php
SnapshotManager.getPageByName
public function getPageByName($routeName) { @trigger_error( 'The '.__METHOD__.' method is deprecated since version 3.2 and will be removed in 4.0.', E_USER_DEPRECATED ); $snapshots = $this->getEntityManager()->createQueryBuilder() ->select('s') ->from($this->class, 's') ->where('s.routeName = :routeName') ->setParameters([ 'routeName' => $routeName, ]) ->getQuery() ->execute(); $snapshot = \count($snapshots) > 0 ? $snapshots[0] : false; if ($snapshot) { return new SnapshotPageProxy($this, $snapshot); } return false; }
php
public function getPageByName($routeName) { @trigger_error( 'The '.__METHOD__.' method is deprecated since version 3.2 and will be removed in 4.0.', E_USER_DEPRECATED ); $snapshots = $this->getEntityManager()->createQueryBuilder() ->select('s') ->from($this->class, 's') ->where('s.routeName = :routeName') ->setParameters([ 'routeName' => $routeName, ]) ->getQuery() ->execute(); $snapshot = \count($snapshots) > 0 ? $snapshots[0] : false; if ($snapshot) { return new SnapshotPageProxy($this, $snapshot); } return false; }
[ "public", "function", "getPageByName", "(", "$", "routeName", ")", "{", "@", "trigger_error", "(", "'The '", ".", "__METHOD__", ".", "' method is deprecated since version 3.2 and will be removed in 4.0.'", ",", "E_USER_DEPRECATED", ")", ";", "$", "snapshots", "=", "$", ...
return a page with the given routeName. @param string $routeName @return PageInterface|false @deprecated since 3.2, to be removed in 4.0
[ "return", "a", "page", "with", "the", "given", "routeName", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/Entity/SnapshotManager.php#L174-L198
train
sonata-project/SonataPageBundle
src/Entity/SnapshotManager.php
SnapshotManager.createSnapshotPageProxy
final public function createSnapshotPageProxy(TransformerInterface $transformer, SnapshotInterface $snapshot) { return $this->snapshotPageProxyFactory ->create($this, $transformer, $snapshot) ; }
php
final public function createSnapshotPageProxy(TransformerInterface $transformer, SnapshotInterface $snapshot) { return $this->snapshotPageProxyFactory ->create($this, $transformer, $snapshot) ; }
[ "final", "public", "function", "createSnapshotPageProxy", "(", "TransformerInterface", "$", "transformer", ",", "SnapshotInterface", "$", "snapshot", ")", "{", "return", "$", "this", "->", "snapshotPageProxyFactory", "->", "create", "(", "$", "this", ",", "$", "tr...
Create a snapShotPageProxy instance. @param TransformerInterface $transformer @param SnapshotInterface $snapshot @return SnapshotPageProxyInterface
[ "Create", "a", "snapShotPageProxy", "instance", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/Entity/SnapshotManager.php#L359-L364
train
sonata-project/SonataPageBundle
src/Model/SnapshotChildrenCollection.php
SnapshotChildrenCollection.load
private function load() { if (null === $this->collection) { $this->collection = $this->transformer->getChildren($this->page); } }
php
private function load() { if (null === $this->collection) { $this->collection = $this->transformer->getChildren($this->page); } }
[ "private", "function", "load", "(", ")", "{", "if", "(", "null", "===", "$", "this", "->", "collection", ")", "{", "$", "this", "->", "collection", "=", "$", "this", "->", "transformer", "->", "getChildren", "(", "$", "this", "->", "page", ")", ";", ...
load the children collection.
[ "load", "the", "children", "collection", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/Model/SnapshotChildrenCollection.php#L111-L116
train
sonata-project/SonataPageBundle
src/Controller/Api/SnapshotController.php
SnapshotController.deleteSnapshotAction
public function deleteSnapshotAction($id) { $snapshots = $this->getSnapshot($id); $this->snapshotManager->delete($snapshots); return ['deleted' => true]; }
php
public function deleteSnapshotAction($id) { $snapshots = $this->getSnapshot($id); $this->snapshotManager->delete($snapshots); return ['deleted' => true]; }
[ "public", "function", "deleteSnapshotAction", "(", "$", "id", ")", "{", "$", "snapshots", "=", "$", "this", "->", "getSnapshot", "(", "$", "id", ")", ";", "$", "this", "->", "snapshotManager", "->", "delete", "(", "$", "snapshots", ")", ";", "return", ...
Deletes a snapshot. @ApiDoc( requirements={ {"name"="id", "dataType"="integer", "requirement"="\d+", "description"="snapshot id"} }, statusCodes={ 200="Returned when snapshots is successfully deleted", 400="Returned when an error has occurred while deleting the snapshots", 404="Returned when unable to find the snapshots" } ) @param int $id A Snapshot identifier @throws NotFoundHttpException @return \FOS\RestBundle\View\View
[ "Deletes", "a", "snapshot", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/Controller/Api/SnapshotController.php#L144-L151
train
sonata-project/SonataPageBundle
src/Listener/ExceptionListener.php
ExceptionListener.getErrorCodePage
public function getErrorCodePage($statusCode) { if (!$this->hasErrorCode($statusCode)) { throw new InternalErrorException(sprintf('There is not page configured to handle the status code %d', $statusCode)); } $cms = $this->cmsManagerSelector->retrieve(); $site = $this->siteSelector->retrieve(); if (!$site) { throw new \RuntimeException('No site available'); } return $cms->getPageByRouteName($site, $this->httpErrorCodes[$statusCode]); }
php
public function getErrorCodePage($statusCode) { if (!$this->hasErrorCode($statusCode)) { throw new InternalErrorException(sprintf('There is not page configured to handle the status code %d', $statusCode)); } $cms = $this->cmsManagerSelector->retrieve(); $site = $this->siteSelector->retrieve(); if (!$site) { throw new \RuntimeException('No site available'); } return $cms->getPageByRouteName($site, $this->httpErrorCodes[$statusCode]); }
[ "public", "function", "getErrorCodePage", "(", "$", "statusCode", ")", "{", "if", "(", "!", "$", "this", "->", "hasErrorCode", "(", "$", "statusCode", ")", ")", "{", "throw", "new", "InternalErrorException", "(", "sprintf", "(", "'There is not page configured to...
Returns a fully loaded page from a route name by the http error code throw. @param int $statusCode @throws \RuntimeException When site is not found, check your state database @throws InternalErrorException When you do not configure page for http error code @return \Sonata\PageBundle\Model\PageInterface
[ "Returns", "a", "fully", "loaded", "page", "from", "a", "route", "name", "by", "the", "http", "error", "code", "throw", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/Listener/ExceptionListener.php#L134-L148
train
sonata-project/SonataPageBundle
src/Listener/ExceptionListener.php
ExceptionListener.handleNativeError
private function handleNativeError(GetResponseForExceptionEvent $event) { if (true === $this->debug) { return; } if (true === $this->status) { return; } $this->status = true; $exception = $event->getException(); $statusCode = $exception instanceof HttpExceptionInterface ? $exception->getStatusCode() : 500; $cmsManager = $this->cmsManagerSelector->retrieve(); if ($event->getRequest()->get('_route') && !$this->decoratorStrategy->isRouteNameDecorable($event->getRequest()->get('_route'))) { return; } if (!$this->decoratorStrategy->isRouteUriDecorable($event->getRequest()->getPathInfo())) { return; } if (!$this->hasErrorCode($statusCode)) { return; } $message = sprintf('%s: %s (uncaught exception) at %s line %s', \get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine()); $this->logException($exception, $exception, $message); try { $page = $this->getErrorCodePage($statusCode); $cmsManager->setCurrentPage($page); if (null !== $page->getSite()->getLocale() && $page->getSite()->getLocale() !== $event->getRequest()->getLocale()) { // Compare locales because Request returns the default one if null. // If 404, LocaleListener from HttpKernel component of Symfony is not called. // It uses the "_locale" attribute set by SiteSelectorInterface to set the request locale. // So in order to translate messages, force here the locale with the site. $event->getRequest()->setLocale($page->getSite()->getLocale()); } $response = $this->pageServiceManager->execute($page, $event->getRequest(), [], new Response('', $statusCode)); } catch (\Exception $e) { $this->logException($exception, $e); $event->setException($e); $this->handleInternalError($event); return; } $event->setResponse($response); }
php
private function handleNativeError(GetResponseForExceptionEvent $event) { if (true === $this->debug) { return; } if (true === $this->status) { return; } $this->status = true; $exception = $event->getException(); $statusCode = $exception instanceof HttpExceptionInterface ? $exception->getStatusCode() : 500; $cmsManager = $this->cmsManagerSelector->retrieve(); if ($event->getRequest()->get('_route') && !$this->decoratorStrategy->isRouteNameDecorable($event->getRequest()->get('_route'))) { return; } if (!$this->decoratorStrategy->isRouteUriDecorable($event->getRequest()->getPathInfo())) { return; } if (!$this->hasErrorCode($statusCode)) { return; } $message = sprintf('%s: %s (uncaught exception) at %s line %s', \get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine()); $this->logException($exception, $exception, $message); try { $page = $this->getErrorCodePage($statusCode); $cmsManager->setCurrentPage($page); if (null !== $page->getSite()->getLocale() && $page->getSite()->getLocale() !== $event->getRequest()->getLocale()) { // Compare locales because Request returns the default one if null. // If 404, LocaleListener from HttpKernel component of Symfony is not called. // It uses the "_locale" attribute set by SiteSelectorInterface to set the request locale. // So in order to translate messages, force here the locale with the site. $event->getRequest()->setLocale($page->getSite()->getLocale()); } $response = $this->pageServiceManager->execute($page, $event->getRequest(), [], new Response('', $statusCode)); } catch (\Exception $e) { $this->logException($exception, $e); $event->setException($e); $this->handleInternalError($event); return; } $event->setResponse($response); }
[ "private", "function", "handleNativeError", "(", "GetResponseForExceptionEvent", "$", "event", ")", "{", "if", "(", "true", "===", "$", "this", "->", "debug", ")", "{", "return", ";", "}", "if", "(", "true", "===", "$", "this", "->", "status", ")", "{", ...
Handles a native error. @param GetResponseForExceptionEvent $event @throws mixed
[ "Handles", "a", "native", "error", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/Listener/ExceptionListener.php#L215-L273
train
sonata-project/SonataPageBundle
src/Listener/ExceptionListener.php
ExceptionListener.logException
private function logException(\Exception $originalException, \Exception $generatedException, $message = null) { if (!$message) { $message = sprintf('Exception thrown when handling an exception (%s: %s)', \get_class($generatedException), $generatedException->getMessage()); } if (null !== $this->logger) { if (!$originalException instanceof HttpExceptionInterface || $originalException->getStatusCode() >= 500) { $this->logger->critical($message, ['exception' => $originalException]); } else { $this->logger->error($message, ['exception' => $originalException]); } } else { error_log($message); } }
php
private function logException(\Exception $originalException, \Exception $generatedException, $message = null) { if (!$message) { $message = sprintf('Exception thrown when handling an exception (%s: %s)', \get_class($generatedException), $generatedException->getMessage()); } if (null !== $this->logger) { if (!$originalException instanceof HttpExceptionInterface || $originalException->getStatusCode() >= 500) { $this->logger->critical($message, ['exception' => $originalException]); } else { $this->logger->error($message, ['exception' => $originalException]); } } else { error_log($message); } }
[ "private", "function", "logException", "(", "\\", "Exception", "$", "originalException", ",", "\\", "Exception", "$", "generatedException", ",", "$", "message", "=", "null", ")", "{", "if", "(", "!", "$", "message", ")", "{", "$", "message", "=", "sprintf"...
Logs exceptions. @param \Exception $originalException Original exception that called the listener @param \Exception $generatedException Generated exception @param string|null $message Message to log
[ "Logs", "exceptions", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/Listener/ExceptionListener.php#L282-L297
train
sonata-project/SonataPageBundle
src/CmsManager/CmsPageManager.php
CmsPageManager.loadBlocks
private function loadBlocks(PageInterface $page) { $blocks = $this->blockInteractor->loadPageBlocks($page); // save a local cache foreach ($blocks as $block) { $this->blocks[$block->getId()] = $block; } }
php
private function loadBlocks(PageInterface $page) { $blocks = $this->blockInteractor->loadPageBlocks($page); // save a local cache foreach ($blocks as $block) { $this->blocks[$block->getId()] = $block; } }
[ "private", "function", "loadBlocks", "(", "PageInterface", "$", "page", ")", "{", "$", "blocks", "=", "$", "this", "->", "blockInteractor", "->", "loadPageBlocks", "(", "$", "page", ")", ";", "// save a local cache", "foreach", "(", "$", "blocks", "as", "$",...
load all the related nested blocks linked to one page. @param PageInterface $page
[ "load", "all", "the", "related", "nested", "blocks", "linked", "to", "one", "page", "." ]
ae701888155e295af1ac3c560b0c8cb4d1014a7c
https://github.com/sonata-project/SonataPageBundle/blob/ae701888155e295af1ac3c560b0c8cb4d1014a7c/src/CmsManager/CmsPageManager.php#L208-L216
train
albertcht/invisible-recaptcha
src/InvisibleReCaptchaServiceProvider.php
InvisibleReCaptchaServiceProvider.boot
public function boot() { $this->bootConfig(); $this->app['validator']->extend('captcha', function ($attribute, $value) { return $this->app['captcha']->verifyResponse($value, $this->app['request']->getClientIp()); }); }
php
public function boot() { $this->bootConfig(); $this->app['validator']->extend('captcha', function ($attribute, $value) { return $this->app['captcha']->verifyResponse($value, $this->app['request']->getClientIp()); }); }
[ "public", "function", "boot", "(", ")", "{", "$", "this", "->", "bootConfig", "(", ")", ";", "$", "this", "->", "app", "[", "'validator'", "]", "->", "extend", "(", "'captcha'", ",", "function", "(", "$", "attribute", ",", "$", "value", ")", "{", "...
Boot the services for the application. @return void
[ "Boot", "the", "services", "for", "the", "application", "." ]
5e5f06447bbb0068dbfe81dca8c35f77814d7122
https://github.com/albertcht/invisible-recaptcha/blob/5e5f06447bbb0068dbfe81dca8c35f77814d7122/src/InvisibleReCaptchaServiceProvider.php#L15-L21
train
albertcht/invisible-recaptcha
src/InvisibleReCaptcha.php
InvisibleReCaptcha.render
public function render($lang = null) { $html = $this->renderPolyfill(); $html .= $this->renderCaptchaHTML(); $html .= $this->renderFooterJS($lang); return $html; }
php
public function render($lang = null) { $html = $this->renderPolyfill(); $html .= $this->renderCaptchaHTML(); $html .= $this->renderFooterJS($lang); return $html; }
[ "public", "function", "render", "(", "$", "lang", "=", "null", ")", "{", "$", "html", "=", "$", "this", "->", "renderPolyfill", "(", ")", ";", "$", "html", ".=", "$", "this", "->", "renderCaptchaHTML", "(", ")", ";", "$", "html", ".=", "$", "this",...
Render HTML reCaptcha by optional language param. @return string
[ "Render", "HTML", "reCaptcha", "by", "optional", "language", "param", "." ]
5e5f06447bbb0068dbfe81dca8c35f77814d7122
https://github.com/albertcht/invisible-recaptcha/blob/5e5f06447bbb0068dbfe81dca8c35f77814d7122/src/InvisibleReCaptcha.php#L91-L97
train
albertcht/invisible-recaptcha
src/InvisibleReCaptcha.php
InvisibleReCaptcha.renderCaptchaHTML
public function renderCaptchaHTML() { $html = '<div id="_g-recaptcha"></div>' . PHP_EOL; if ($this->getOption('hideBadge', false)) { $html .= '<style>.grecaptcha-badge{display:none;!important}</style>' . PHP_EOL; } $html .= '<div class="g-recaptcha" data-sitekey="' . $this->siteKey .'" '; $html .= 'data-size="invisible" data-callback="_submitForm" data-badge="' . $this->getOption('dataBadge', 'bottomright') . '"></div>'; return $html; }
php
public function renderCaptchaHTML() { $html = '<div id="_g-recaptcha"></div>' . PHP_EOL; if ($this->getOption('hideBadge', false)) { $html .= '<style>.grecaptcha-badge{display:none;!important}</style>' . PHP_EOL; } $html .= '<div class="g-recaptcha" data-sitekey="' . $this->siteKey .'" '; $html .= 'data-size="invisible" data-callback="_submitForm" data-badge="' . $this->getOption('dataBadge', 'bottomright') . '"></div>'; return $html; }
[ "public", "function", "renderCaptchaHTML", "(", ")", "{", "$", "html", "=", "'<div id=\"_g-recaptcha\"></div>'", ".", "PHP_EOL", ";", "if", "(", "$", "this", "->", "getOption", "(", "'hideBadge'", ",", "false", ")", ")", "{", "$", "html", ".=", "'<style>.gre...
Render the captcha HTML. @return string
[ "Render", "the", "captcha", "HTML", "." ]
5e5f06447bbb0068dbfe81dca8c35f77814d7122
https://github.com/albertcht/invisible-recaptcha/blob/5e5f06447bbb0068dbfe81dca8c35f77814d7122/src/InvisibleReCaptcha.php#L114-L124
train
albertcht/invisible-recaptcha
src/InvisibleReCaptcha.php
InvisibleReCaptcha.renderFooterJS
public function renderFooterJS($lang = null) { $html = '<script src="' . $this->getCaptchaJs($lang) . '" async defer></script>' . PHP_EOL; $html .= '<script>var _submitForm,_captchaForm,_captchaSubmit,_execute=true;</script>'; $html .= "<script>window.addEventListener('load', _loadCaptcha);" . PHP_EOL; $html .= "function _loadCaptcha(){"; if ($this->getOption('hideBadge', false)) { $html .= "document.querySelector('.grecaptcha-badge').style = 'display:none;!important'" . PHP_EOL; } $html .= '_captchaForm=document.querySelector("#_g-recaptcha").closest("form");'; $html .= "_captchaSubmit=_captchaForm.querySelector('[type=submit]');"; $html .= '_submitForm=function(){if(typeof _submitEvent==="function"){_submitEvent();'; $html .= 'grecaptcha.reset();}else{_captchaForm.submit();}};'; $html .= "_captchaForm.addEventListener('submit',"; $html .= "function(e){e.preventDefault();if(typeof _beforeSubmit==='function'){"; $html .= "_execute=_beforeSubmit(e);}if(_execute){grecaptcha.execute();}});"; if ($this->getOption('debug', false)) { $html .= $this->renderDebug(); } $html .= "}</script>" . PHP_EOL; return $html; }
php
public function renderFooterJS($lang = null) { $html = '<script src="' . $this->getCaptchaJs($lang) . '" async defer></script>' . PHP_EOL; $html .= '<script>var _submitForm,_captchaForm,_captchaSubmit,_execute=true;</script>'; $html .= "<script>window.addEventListener('load', _loadCaptcha);" . PHP_EOL; $html .= "function _loadCaptcha(){"; if ($this->getOption('hideBadge', false)) { $html .= "document.querySelector('.grecaptcha-badge').style = 'display:none;!important'" . PHP_EOL; } $html .= '_captchaForm=document.querySelector("#_g-recaptcha").closest("form");'; $html .= "_captchaSubmit=_captchaForm.querySelector('[type=submit]');"; $html .= '_submitForm=function(){if(typeof _submitEvent==="function"){_submitEvent();'; $html .= 'grecaptcha.reset();}else{_captchaForm.submit();}};'; $html .= "_captchaForm.addEventListener('submit',"; $html .= "function(e){e.preventDefault();if(typeof _beforeSubmit==='function'){"; $html .= "_execute=_beforeSubmit(e);}if(_execute){grecaptcha.execute();}});"; if ($this->getOption('debug', false)) { $html .= $this->renderDebug(); } $html .= "}</script>" . PHP_EOL; return $html; }
[ "public", "function", "renderFooterJS", "(", "$", "lang", "=", "null", ")", "{", "$", "html", "=", "'<script src=\"'", ".", "$", "this", "->", "getCaptchaJs", "(", "$", "lang", ")", ".", "'\" async defer></script>'", ".", "PHP_EOL", ";", "$", "html", ".=",...
Render the footer JS neccessary for the recaptcha integration. @return string
[ "Render", "the", "footer", "JS", "neccessary", "for", "the", "recaptcha", "integration", "." ]
5e5f06447bbb0068dbfe81dca8c35f77814d7122
https://github.com/albertcht/invisible-recaptcha/blob/5e5f06447bbb0068dbfe81dca8c35f77814d7122/src/InvisibleReCaptcha.php#L131-L152
train
albertcht/invisible-recaptcha
src/InvisibleReCaptcha.php
InvisibleReCaptcha.renderDebug
public function renderDebug() { $html = ''; foreach (static::DEBUG_ELEMENTS as $element) { $html .= $this->consoleLog('"Checking element binding of ' . $element . '..."'); $html .= $this->consoleLog($element . '!==undefined'); } return $html; }
php
public function renderDebug() { $html = ''; foreach (static::DEBUG_ELEMENTS as $element) { $html .= $this->consoleLog('"Checking element binding of ' . $element . '..."'); $html .= $this->consoleLog($element . '!==undefined'); } return $html; }
[ "public", "function", "renderDebug", "(", ")", "{", "$", "html", "=", "''", ";", "foreach", "(", "static", "::", "DEBUG_ELEMENTS", "as", "$", "element", ")", "{", "$", "html", ".=", "$", "this", "->", "consoleLog", "(", "'\"Checking element binding of '", ...
Get debug javascript code. @return string
[ "Get", "debug", "javascript", "code", "." ]
5e5f06447bbb0068dbfe81dca8c35f77814d7122
https://github.com/albertcht/invisible-recaptcha/blob/5e5f06447bbb0068dbfe81dca8c35f77814d7122/src/InvisibleReCaptcha.php#L159-L168
train
albertcht/invisible-recaptcha
src/InvisibleReCaptcha.php
InvisibleReCaptcha.verifyResponse
public function verifyResponse($response, $clientIp) { if (empty($response)) { return false; } $response = $this->sendVerifyRequest([ 'secret' => $this->secretKey, 'remoteip' => $clientIp, 'response' => $response ]); return isset($response['success']) && $response['success'] === true; }
php
public function verifyResponse($response, $clientIp) { if (empty($response)) { return false; } $response = $this->sendVerifyRequest([ 'secret' => $this->secretKey, 'remoteip' => $clientIp, 'response' => $response ]); return isset($response['success']) && $response['success'] === true; }
[ "public", "function", "verifyResponse", "(", "$", "response", ",", "$", "clientIp", ")", "{", "if", "(", "empty", "(", "$", "response", ")", ")", "{", "return", "false", ";", "}", "$", "response", "=", "$", "this", "->", "sendVerifyRequest", "(", "[", ...
Verify invisible reCaptcha response. @param string $response @param string $clientIp @return bool
[ "Verify", "invisible", "reCaptcha", "response", "." ]
5e5f06447bbb0068dbfe81dca8c35f77814d7122
https://github.com/albertcht/invisible-recaptcha/blob/5e5f06447bbb0068dbfe81dca8c35f77814d7122/src/InvisibleReCaptcha.php#L188-L201
train
madcoda/php-youtube-api
src/Youtube.php
Youtube.searchVideos
public function searchVideos($q, $maxResults = 10, $order = null) { $params = array( 'q' => $q, 'type' => 'video', 'part' => 'id, snippet', 'maxResults' => $maxResults ); if (!empty($order)) { $params['order'] = $order; } return $this->searchAdvanced($params); }
php
public function searchVideos($q, $maxResults = 10, $order = null) { $params = array( 'q' => $q, 'type' => 'video', 'part' => 'id, snippet', 'maxResults' => $maxResults ); if (!empty($order)) { $params['order'] = $order; } return $this->searchAdvanced($params); }
[ "public", "function", "searchVideos", "(", "$", "q", ",", "$", "maxResults", "=", "10", ",", "$", "order", "=", "null", ")", "{", "$", "params", "=", "array", "(", "'q'", "=>", "$", "q", ",", "'type'", "=>", "'video'", ",", "'part'", "=>", "'id, sn...
Search only videos @param string $q Query @param integer $maxResults number of results to return @param string $order Order by @return \StdClass API results
[ "Search", "only", "videos" ]
78ceca57c5fbbae51cef81bd216ed0886f4920d2
https://github.com/madcoda/php-youtube-api/blob/78ceca57c5fbbae51cef81bd216ed0886f4920d2/src/Youtube.php#L195-L208
train
madcoda/php-youtube-api
src/Youtube.php
Youtube.getChannelFromURL
public function getChannelFromURL($youtube_url) { if (strpos($youtube_url, 'youtube.com') === false) { throw new \Exception('The supplied URL does not look like a Youtube URL'); } $path = static::_parse_url_path($youtube_url); if (strpos($path, '/channel') === 0) { $segments = explode('/', $path); $channelId = $segments[count($segments) - 1]; $channel = $this->getChannelById($channelId); } elseif (strpos($path, '/user') === 0) { $segments = explode('/', $path); $username = $segments[count($segments) - 1]; $channel = $this->getChannelByName($username); } else { throw new \Exception('The supplied URL does not look like a Youtube Channel URL'); } return $channel; }
php
public function getChannelFromURL($youtube_url) { if (strpos($youtube_url, 'youtube.com') === false) { throw new \Exception('The supplied URL does not look like a Youtube URL'); } $path = static::_parse_url_path($youtube_url); if (strpos($path, '/channel') === 0) { $segments = explode('/', $path); $channelId = $segments[count($segments) - 1]; $channel = $this->getChannelById($channelId); } elseif (strpos($path, '/user') === 0) { $segments = explode('/', $path); $username = $segments[count($segments) - 1]; $channel = $this->getChannelByName($username); } else { throw new \Exception('The supplied URL does not look like a Youtube Channel URL'); } return $channel; }
[ "public", "function", "getChannelFromURL", "(", "$", "youtube_url", ")", "{", "if", "(", "strpos", "(", "$", "youtube_url", ",", "'youtube.com'", ")", "===", "false", ")", "{", "throw", "new", "\\", "Exception", "(", "'The supplied URL does not look like a Youtube...
Get the channel object by supplying the URL of the channel page @param string $youtube_url @throws \Exception @return object Channel object
[ "Get", "the", "channel", "object", "by", "supplying", "the", "URL", "of", "the", "channel", "page" ]
78ceca57c5fbbae51cef81bd216ed0886f4920d2
https://github.com/madcoda/php-youtube-api/blob/78ceca57c5fbbae51cef81bd216ed0886f4920d2/src/Youtube.php#L502-L522
train
madcoda/php-youtube-api
src/Youtube.php
Youtube._parse_url_query
public static function _parse_url_query($url) { $queryString = parse_url($url, PHP_URL_QUERY); $params = array(); parse_str($queryString, $params); if (count($params) === 0) { return $params; } return array_filter($params); }
php
public static function _parse_url_query($url) { $queryString = parse_url($url, PHP_URL_QUERY); $params = array(); parse_str($queryString, $params); if (count($params) === 0) { return $params; } return array_filter($params); }
[ "public", "static", "function", "_parse_url_query", "(", "$", "url", ")", "{", "$", "queryString", "=", "parse_url", "(", "$", "url", ",", "PHP_URL_QUERY", ")", ";", "$", "params", "=", "array", "(", ")", ";", "parse_str", "(", "$", "queryString", ",", ...
Parse the input url string and return an array of query params @param string $url the URL @return array array of query params
[ "Parse", "the", "input", "url", "string", "and", "return", "an", "array", "of", "query", "params" ]
78ceca57c5fbbae51cef81bd216ed0886f4920d2
https://github.com/madcoda/php-youtube-api/blob/78ceca57c5fbbae51cef81bd216ed0886f4920d2/src/Youtube.php#L661-L674
train
marcelog/PAMI
src/PAMI/Client/Impl/ClientImpl.php
ClientImpl.open
public function open() { $cString = $this->scheme . $this->host . ':' . $this->port; $this->context = stream_context_create(); $errno = 0; $errstr = ''; $this->socket = @stream_socket_client( $cString, $errno, $errstr, $this->cTimeout, STREAM_CLIENT_CONNECT, $this->context ); if ($this->socket === false) { throw new ClientException('Error connecting to ami: ' . $errstr); } $msg = new LoginAction($this->user, $this->pass, $this->eventMask); $asteriskId = @stream_get_line($this->socket, 1024, Message::EOL); if (strstr($asteriskId, 'Asterisk') === false) { throw new ClientException( "Unknown peer. Is this an ami?: $asteriskId" ); } $response = $this->send($msg); if (!$response->isSuccess()) { throw new ClientException( 'Could not connect: ' . $response->getMessage() ); } @stream_set_blocking($this->socket, 0); $this->currentProcessingMessage = ''; $this->logger->debug('Logged in successfully to ami.'); }
php
public function open() { $cString = $this->scheme . $this->host . ':' . $this->port; $this->context = stream_context_create(); $errno = 0; $errstr = ''; $this->socket = @stream_socket_client( $cString, $errno, $errstr, $this->cTimeout, STREAM_CLIENT_CONNECT, $this->context ); if ($this->socket === false) { throw new ClientException('Error connecting to ami: ' . $errstr); } $msg = new LoginAction($this->user, $this->pass, $this->eventMask); $asteriskId = @stream_get_line($this->socket, 1024, Message::EOL); if (strstr($asteriskId, 'Asterisk') === false) { throw new ClientException( "Unknown peer. Is this an ami?: $asteriskId" ); } $response = $this->send($msg); if (!$response->isSuccess()) { throw new ClientException( 'Could not connect: ' . $response->getMessage() ); } @stream_set_blocking($this->socket, 0); $this->currentProcessingMessage = ''; $this->logger->debug('Logged in successfully to ami.'); }
[ "public", "function", "open", "(", ")", "{", "$", "cString", "=", "$", "this", "->", "scheme", ".", "$", "this", "->", "host", ".", "':'", ".", "$", "this", "->", "port", ";", "$", "this", "->", "context", "=", "stream_context_create", "(", ")", ";...
Opens a tcp connection to ami. @throws \PAMI\Client\Exception\ClientException @return void
[ "Opens", "a", "tcp", "connection", "to", "ami", "." ]
f586d0fcbf7db7952965ccb91e4ed231bd168fb3
https://github.com/marcelog/PAMI/blob/f586d0fcbf7db7952965ccb91e4ed231bd168fb3/src/PAMI/Client/Impl/ClientImpl.php#L163-L196
train
marcelog/PAMI
src/PAMI/Client/Impl/ClientImpl.php
ClientImpl.registerEventListener
public function registerEventListener($listener, $predicate = null) { $listenerId = uniqid('PamiListener'); $this->eventListeners[$listenerId] = array($listener, $predicate); return $listenerId; }
php
public function registerEventListener($listener, $predicate = null) { $listenerId = uniqid('PamiListener'); $this->eventListeners[$listenerId] = array($listener, $predicate); return $listenerId; }
[ "public", "function", "registerEventListener", "(", "$", "listener", ",", "$", "predicate", "=", "null", ")", "{", "$", "listenerId", "=", "uniqid", "(", "'PamiListener'", ")", ";", "$", "this", "->", "eventListeners", "[", "$", "listenerId", "]", "=", "ar...
Registers the given listener so it can receive events. Returns the generated id for this new listener. You can pass in a an IEventListener, a Closure, and an array containing the object and name of the method to invoke. Can specify an optional predicate to invoke before calling the callback. @param mixed $listener @param \Closure|null $predicate @return string
[ "Registers", "the", "given", "listener", "so", "it", "can", "receive", "events", ".", "Returns", "the", "generated", "id", "for", "this", "new", "listener", ".", "You", "can", "pass", "in", "a", "an", "IEventListener", "a", "Closure", "and", "an", "array",...
f586d0fcbf7db7952965ccb91e4ed231bd168fb3
https://github.com/marcelog/PAMI/blob/f586d0fcbf7db7952965ccb91e4ed231bd168fb3/src/PAMI/Client/Impl/ClientImpl.php#L209-L214
train
marcelog/PAMI
src/PAMI/Client/Impl/ClientImpl.php
ClientImpl.getMessages
protected function getMessages() { $msgs = array(); // Read something. $read = @fread($this->socket, 65535); if ($read === false || @feof($this->socket)) { throw new ClientException('Error reading'); } $this->currentProcessingMessage .= $read; // If we have a complete message, then return it. Save the rest for // later. while (($marker = strpos($this->currentProcessingMessage, Message::EOM))) { $msg = substr($this->currentProcessingMessage, 0, $marker); $this->currentProcessingMessage = substr( $this->currentProcessingMessage, $marker + strlen(Message::EOM) ); $msgs[] = $msg; } return $msgs; }
php
protected function getMessages() { $msgs = array(); // Read something. $read = @fread($this->socket, 65535); if ($read === false || @feof($this->socket)) { throw new ClientException('Error reading'); } $this->currentProcessingMessage .= $read; // If we have a complete message, then return it. Save the rest for // later. while (($marker = strpos($this->currentProcessingMessage, Message::EOM))) { $msg = substr($this->currentProcessingMessage, 0, $marker); $this->currentProcessingMessage = substr( $this->currentProcessingMessage, $marker + strlen(Message::EOM) ); $msgs[] = $msg; } return $msgs; }
[ "protected", "function", "getMessages", "(", ")", "{", "$", "msgs", "=", "array", "(", ")", ";", "// Read something.", "$", "read", "=", "@", "fread", "(", "$", "this", "->", "socket", ",", "65535", ")", ";", "if", "(", "$", "read", "===", "false", ...
Reads a complete message over the stream until EOM. @throws ClientException @return \string[]
[ "Reads", "a", "complete", "message", "over", "the", "stream", "until", "EOM", "." ]
f586d0fcbf7db7952965ccb91e4ed231bd168fb3
https://github.com/marcelog/PAMI/blob/f586d0fcbf7db7952965ccb91e4ed231bd168fb3/src/PAMI/Client/Impl/ClientImpl.php#L236-L256
train
marcelog/PAMI
src/PAMI/Client/Impl/ClientImpl.php
ClientImpl.findResponse
protected function findResponse(IncomingMessage $message) { $actionId = $message->getActionId(); if (isset($this->incomingQueue[$actionId])) { return $this->incomingQueue[$actionId]; } return false; }
php
protected function findResponse(IncomingMessage $message) { $actionId = $message->getActionId(); if (isset($this->incomingQueue[$actionId])) { return $this->incomingQueue[$actionId]; } return false; }
[ "protected", "function", "findResponse", "(", "IncomingMessage", "$", "message", ")", "{", "$", "actionId", "=", "$", "message", "->", "getActionId", "(", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "incomingQueue", "[", "$", "actionId", "]", "...
Tries to find an associated response for the given message. @param IncomingMessage $message Message sent by asterisk. @return \PAMI\Message\Response\ResponseMessage
[ "Tries", "to", "find", "an", "associated", "response", "for", "the", "given", "message", "." ]
f586d0fcbf7db7952965ccb91e4ed231bd168fb3
https://github.com/marcelog/PAMI/blob/f586d0fcbf7db7952965ccb91e4ed231bd168fb3/src/PAMI/Client/Impl/ClientImpl.php#L305-L312
train
marcelog/PAMI
src/PAMI/Client/Impl/ClientImpl.php
ClientImpl.dispatch
protected function dispatch(IncomingMessage $message) { foreach ($this->eventListeners as $data) { $listener = $data[0]; $predicate = $data[1]; if (is_callable($predicate) && !call_user_func($predicate, $message)) { continue; } if ($listener instanceof \Closure) { $listener($message); } elseif (is_array($listener)) { $listener[0]->{$listener[1]}($message); } else { $listener->handle($message); } } }
php
protected function dispatch(IncomingMessage $message) { foreach ($this->eventListeners as $data) { $listener = $data[0]; $predicate = $data[1]; if (is_callable($predicate) && !call_user_func($predicate, $message)) { continue; } if ($listener instanceof \Closure) { $listener($message); } elseif (is_array($listener)) { $listener[0]->{$listener[1]}($message); } else { $listener->handle($message); } } }
[ "protected", "function", "dispatch", "(", "IncomingMessage", "$", "message", ")", "{", "foreach", "(", "$", "this", "->", "eventListeners", "as", "$", "data", ")", "{", "$", "listener", "=", "$", "data", "[", "0", "]", ";", "$", "predicate", "=", "$", ...
Dispatchs the incoming message to a handler. @param \PAMI\Message\IncomingMessage $message Message to dispatch. @return void
[ "Dispatchs", "the", "incoming", "message", "to", "a", "handler", "." ]
f586d0fcbf7db7952965ccb91e4ed231bd168fb3
https://github.com/marcelog/PAMI/blob/f586d0fcbf7db7952965ccb91e4ed231bd168fb3/src/PAMI/Client/Impl/ClientImpl.php#L321-L337
train