repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
maniaplanet/maniaplanet-ws-sdk | libraries/Maniaplanet/WebServices/ManiaHome.php | ManiaHome.postPersonalNotification | function postPersonalNotification(Notification $n)
{
return $this->manialinkPublisher->postPersonalNotification($n->message, $n->receiverName, $n->link, $n->iconStyle,
$n->iconSubStyle);
} | php | function postPersonalNotification(Notification $n)
{
return $this->manialinkPublisher->postPersonalNotification($n->message, $n->receiverName, $n->link, $n->iconStyle,
$n->iconSubStyle);
} | [
"function",
"postPersonalNotification",
"(",
"Notification",
"$",
"n",
")",
"{",
"return",
"$",
"this",
"->",
"manialinkPublisher",
"->",
"postPersonalNotification",
"(",
"$",
"n",
"->",
"message",
",",
"$",
"n",
"->",
"receiverName",
",",
"$",
"n",
"->",
"link",
",",
"$",
"n",
"->",
"iconStyle",
",",
"$",
"n",
"->",
"iconSubStyle",
")",
";",
"}"
] | Send a public notification to a player (specified in
Notification::$receiverName). The message will be prepended with its
nickname and will be visible by all its buddies.
@param Notification $n
@deprecated since version 3.1.0 | [
"Send",
"a",
"public",
"notification",
"to",
"a",
"player",
"(",
"specified",
"in",
"Notification",
"::",
"$receiverName",
")",
".",
"The",
"message",
"will",
"be",
"prepended",
"with",
"its",
"nickname",
"and",
"will",
"be",
"visible",
"by",
"all",
"its",
"buddies",
"."
] | train | https://github.com/maniaplanet/maniaplanet-ws-sdk/blob/027a458388035fe66f2f56ff3ea1f85eff2a5a4e/libraries/Maniaplanet/WebServices/ManiaHome.php#L77-L81 |
maniaplanet/maniaplanet-ws-sdk | libraries/Maniaplanet/WebServices/ManiaHome.php | ManiaHome.postPrivateNotification | function postPrivateNotification(Notification $n)
{
return $this->manialinkPublisher->postPrivateNotification($n->message, $n->receiverName, $n->link);
} | php | function postPrivateNotification(Notification $n)
{
return $this->manialinkPublisher->postPrivateNotification($n->message, $n->receiverName, $n->link);
} | [
"function",
"postPrivateNotification",
"(",
"Notification",
"$",
"n",
")",
"{",
"return",
"$",
"this",
"->",
"manialinkPublisher",
"->",
"postPrivateNotification",
"(",
"$",
"n",
"->",
"message",
",",
"$",
"n",
"->",
"receiverName",
",",
"$",
"n",
"->",
"link",
")",
";",
"}"
] | Send a private message to a player (specified in
Notification::$receiverName).
@param Notification $n
@deprecated since version 3.1.0 | [
"Send",
"a",
"private",
"message",
"to",
"a",
"player",
"(",
"specified",
"in",
"Notification",
"::",
"$receiverName",
")",
"."
] | train | https://github.com/maniaplanet/maniaplanet-ws-sdk/blob/027a458388035fe66f2f56ff3ea1f85eff2a5a4e/libraries/Maniaplanet/WebServices/ManiaHome.php#L89-L92 |
maniaplanet/matchmaking-lobby | MatchMakingLobby/Services/MatchMakingService.php | MatchMakingService.getLobby | function getLobby($lobbyLogin)
{
return $this->db->execute(
'SELECT * FROM LobbyServers '.
'WHERE login = %s', $this->db->quote($lobbyLogin)
)->fetchObject(__NAMESPACE__.'\Lobby');
} | php | function getLobby($lobbyLogin)
{
return $this->db->execute(
'SELECT * FROM LobbyServers '.
'WHERE login = %s', $this->db->quote($lobbyLogin)
)->fetchObject(__NAMESPACE__.'\Lobby');
} | [
"function",
"getLobby",
"(",
"$",
"lobbyLogin",
")",
"{",
"return",
"$",
"this",
"->",
"db",
"->",
"execute",
"(",
"'SELECT * FROM LobbyServers '",
".",
"'WHERE login = %s'",
",",
"$",
"this",
"->",
"db",
"->",
"quote",
"(",
"$",
"lobbyLogin",
")",
")",
"->",
"fetchObject",
"(",
"__NAMESPACE__",
".",
"'\\Lobby'",
")",
";",
"}"
] | Get lobby information
@param string $lobbyLogin
@return Lobby | [
"Get",
"lobby",
"information"
] | train | https://github.com/maniaplanet/matchmaking-lobby/blob/384f22cdd2cfb0204a071810549eaf1eb01d8b7f/MatchMakingLobby/Services/MatchMakingService.php#L40-L46 |
maniaplanet/matchmaking-lobby | MatchMakingLobby/Services/MatchMakingService.php | MatchMakingService.getMatch | function getMatch($matchId)
{
$match = $this->db->execute(
'SELECT id, matchServerLogin, scriptName, titleIdString, state, matchPointsTeam1, matchPointsTeam2, mapPointsTeam1, mapPointsTeam2 '.
'FROM Matches '.
'WHERE id = %d ',
$matchId
)->fetchObject(__NAMESPACE__.'\\Match');
if(!$match)
return false;
$results = $this->db->execute(
'SELECT P.login, P.teamId, P.rank, P.state '.
'FROM Players P '.
'WHERE P.matchId = %d ', $match->id
)->fetchArrayOfAssoc();
foreach($results as $row)
{
$match->players[] = $row['login'];
$match->playersState[$row['login']] = $row['state'];
if($row['rank'] !== null)
{
$match->ranking[$row['rank']][] = $row['login'];
}
if($row['teamId'] === null)
{
continue;
}
elseif((int)$row['teamId'] === 0)
{
$match->team1[] = $row['login'];
}
elseif((int)$row['teamId'] === 1)
{
$match->team2[] = $row['login'];
}
}
uksort($match->ranking, function ($k1, $k2)
{
if($k1 == 0)
{
return 1;
}
if($k1 > $k2)
{
return 1;
}
else
{
return $k1 == $k2 ? 0: -1;
}
});
return $match;
} | php | function getMatch($matchId)
{
$match = $this->db->execute(
'SELECT id, matchServerLogin, scriptName, titleIdString, state, matchPointsTeam1, matchPointsTeam2, mapPointsTeam1, mapPointsTeam2 '.
'FROM Matches '.
'WHERE id = %d ',
$matchId
)->fetchObject(__NAMESPACE__.'\\Match');
if(!$match)
return false;
$results = $this->db->execute(
'SELECT P.login, P.teamId, P.rank, P.state '.
'FROM Players P '.
'WHERE P.matchId = %d ', $match->id
)->fetchArrayOfAssoc();
foreach($results as $row)
{
$match->players[] = $row['login'];
$match->playersState[$row['login']] = $row['state'];
if($row['rank'] !== null)
{
$match->ranking[$row['rank']][] = $row['login'];
}
if($row['teamId'] === null)
{
continue;
}
elseif((int)$row['teamId'] === 0)
{
$match->team1[] = $row['login'];
}
elseif((int)$row['teamId'] === 1)
{
$match->team2[] = $row['login'];
}
}
uksort($match->ranking, function ($k1, $k2)
{
if($k1 == 0)
{
return 1;
}
if($k1 > $k2)
{
return 1;
}
else
{
return $k1 == $k2 ? 0: -1;
}
});
return $match;
} | [
"function",
"getMatch",
"(",
"$",
"matchId",
")",
"{",
"$",
"match",
"=",
"$",
"this",
"->",
"db",
"->",
"execute",
"(",
"'SELECT id, matchServerLogin, scriptName, titleIdString, state, matchPointsTeam1, matchPointsTeam2, mapPointsTeam1, mapPointsTeam2 '",
".",
"'FROM Matches '",
".",
"'WHERE id = %d '",
",",
"$",
"matchId",
")",
"->",
"fetchObject",
"(",
"__NAMESPACE__",
".",
"'\\\\Match'",
")",
";",
"if",
"(",
"!",
"$",
"match",
")",
"return",
"false",
";",
"$",
"results",
"=",
"$",
"this",
"->",
"db",
"->",
"execute",
"(",
"'SELECT P.login, P.teamId, P.rank, P.state '",
".",
"'FROM Players P '",
".",
"'WHERE P.matchId = %d '",
",",
"$",
"match",
"->",
"id",
")",
"->",
"fetchArrayOfAssoc",
"(",
")",
";",
"foreach",
"(",
"$",
"results",
"as",
"$",
"row",
")",
"{",
"$",
"match",
"->",
"players",
"[",
"]",
"=",
"$",
"row",
"[",
"'login'",
"]",
";",
"$",
"match",
"->",
"playersState",
"[",
"$",
"row",
"[",
"'login'",
"]",
"]",
"=",
"$",
"row",
"[",
"'state'",
"]",
";",
"if",
"(",
"$",
"row",
"[",
"'rank'",
"]",
"!==",
"null",
")",
"{",
"$",
"match",
"->",
"ranking",
"[",
"$",
"row",
"[",
"'rank'",
"]",
"]",
"[",
"]",
"=",
"$",
"row",
"[",
"'login'",
"]",
";",
"}",
"if",
"(",
"$",
"row",
"[",
"'teamId'",
"]",
"===",
"null",
")",
"{",
"continue",
";",
"}",
"elseif",
"(",
"(",
"int",
")",
"$",
"row",
"[",
"'teamId'",
"]",
"===",
"0",
")",
"{",
"$",
"match",
"->",
"team1",
"[",
"]",
"=",
"$",
"row",
"[",
"'login'",
"]",
";",
"}",
"elseif",
"(",
"(",
"int",
")",
"$",
"row",
"[",
"'teamId'",
"]",
"===",
"1",
")",
"{",
"$",
"match",
"->",
"team2",
"[",
"]",
"=",
"$",
"row",
"[",
"'login'",
"]",
";",
"}",
"}",
"uksort",
"(",
"$",
"match",
"->",
"ranking",
",",
"function",
"(",
"$",
"k1",
",",
"$",
"k2",
")",
"{",
"if",
"(",
"$",
"k1",
"==",
"0",
")",
"{",
"return",
"1",
";",
"}",
"if",
"(",
"$",
"k1",
">",
"$",
"k2",
")",
"{",
"return",
"1",
";",
"}",
"else",
"{",
"return",
"$",
"k1",
"==",
"$",
"k2",
"?",
"0",
":",
"-",
"1",
";",
"}",
"}",
")",
";",
"return",
"$",
"match",
";",
"}"
] | Get matchServer information
@param string $serverLogin
@param string $scriptName
@param string $titleIdString
@return Match | [
"Get",
"matchServer",
"information"
] | train | https://github.com/maniaplanet/matchmaking-lobby/blob/384f22cdd2cfb0204a071810549eaf1eb01d8b7f/MatchMakingLobby/Services/MatchMakingService.php#L55-L111 |
maniaplanet/matchmaking-lobby | MatchMakingLobby/Services/MatchMakingService.php | MatchMakingService.getMatchQuitters | function getMatchQuitters($matchId)
{
return $this->db->execute('SELECT login FROM Players WHERE matchId = %d AND (`state` = %d OR `state` = %d)',
$matchId,
PlayerInfo::PLAYER_STATE_QUITTER,
PlayerInfo::PLAYER_STATE_GIVE_UP)->fetchArrayOfSingleValues();
} | php | function getMatchQuitters($matchId)
{
return $this->db->execute('SELECT login FROM Players WHERE matchId = %d AND (`state` = %d OR `state` = %d)',
$matchId,
PlayerInfo::PLAYER_STATE_QUITTER,
PlayerInfo::PLAYER_STATE_GIVE_UP)->fetchArrayOfSingleValues();
} | [
"function",
"getMatchQuitters",
"(",
"$",
"matchId",
")",
"{",
"return",
"$",
"this",
"->",
"db",
"->",
"execute",
"(",
"'SELECT login FROM Players WHERE matchId = %d AND (`state` = %d OR `state` = %d)'",
",",
"$",
"matchId",
",",
"PlayerInfo",
"::",
"PLAYER_STATE_QUITTER",
",",
"PlayerInfo",
"::",
"PLAYER_STATE_GIVE_UP",
")",
"->",
"fetchArrayOfSingleValues",
"(",
")",
";",
"}"
] | Get login of players who have quit the match
(quitters or gave up)
@param int $matchId
@return string[] | [
"Get",
"login",
"of",
"players",
"who",
"have",
"quit",
"the",
"match",
"(",
"quitters",
"or",
"gave",
"up",
")"
] | train | https://github.com/maniaplanet/matchmaking-lobby/blob/384f22cdd2cfb0204a071810549eaf1eb01d8b7f/MatchMakingLobby/Services/MatchMakingService.php#L228-L234 |
maniaplanet/matchmaking-lobby | MatchMakingLobby/Services/MatchMakingService.php | MatchMakingService.getPlayersPlayingCount | function getPlayersPlayingCount($lobbyLogin)
{
return $this->db->execute(
'SELECT COUNT(*) '.
'FROM Players P '.
'INNER JOIN Matches M ON P.matchId = M.id '.
'INNER JOIN MatchServers MS ON MS.matchId = M.id '.
'WHERE M.`state` >= %d AND P.state >= %d '.
'AND MS.lobbyLogin = %s',
Match::PREPARED, PlayerInfo::PLAYER_STATE_CONNECTED,
$this->db->quote($lobbyLogin)
)->fetchSingleValue(0);
} | php | function getPlayersPlayingCount($lobbyLogin)
{
return $this->db->execute(
'SELECT COUNT(*) '.
'FROM Players P '.
'INNER JOIN Matches M ON P.matchId = M.id '.
'INNER JOIN MatchServers MS ON MS.matchId = M.id '.
'WHERE M.`state` >= %d AND P.state >= %d '.
'AND MS.lobbyLogin = %s',
Match::PREPARED, PlayerInfo::PLAYER_STATE_CONNECTED,
$this->db->quote($lobbyLogin)
)->fetchSingleValue(0);
} | [
"function",
"getPlayersPlayingCount",
"(",
"$",
"lobbyLogin",
")",
"{",
"return",
"$",
"this",
"->",
"db",
"->",
"execute",
"(",
"'SELECT COUNT(*) '",
".",
"'FROM Players P '",
".",
"'INNER JOIN Matches M ON P.matchId = M.id '",
".",
"'INNER JOIN MatchServers MS ON MS.matchId = M.id '",
".",
"'WHERE M.`state` >= %d AND P.state >= %d '",
".",
"'AND MS.lobbyLogin = %s'",
",",
"Match",
"::",
"PREPARED",
",",
"PlayerInfo",
"::",
"PLAYER_STATE_CONNECTED",
",",
"$",
"this",
"->",
"db",
"->",
"quote",
"(",
"$",
"lobbyLogin",
")",
")",
"->",
"fetchSingleValue",
"(",
"0",
")",
";",
"}"
] | Return the number of match currently played for the lobby
@param string $lobbyLogin
@return int | [
"Return",
"the",
"number",
"of",
"match",
"currently",
"played",
"for",
"the",
"lobby"
] | train | https://github.com/maniaplanet/matchmaking-lobby/blob/384f22cdd2cfb0204a071810549eaf1eb01d8b7f/MatchMakingLobby/Services/MatchMakingService.php#L254-L266 |
maniaplanet/matchmaking-lobby | MatchMakingLobby/Services/MatchMakingService.php | MatchMakingService.getLiveMatchServersCount | function getLiveMatchServersCount($lobbyLogin, $scriptName, $titleIdString)
{
return $this->db->execute(
'SELECT COUNT(*) FROM MatchServers '.
'WHERE DATE_ADD(lastLive, INTERVAL 15 MINUTE) > NOW() '.
'AND lobbyLogin = %s AND scriptName = %s AND titleIdString = %s',
$this->db->quote($lobbyLogin), $this->db->quote($scriptName), $this->db->quote($titleIdString)
)->fetchSingleValue(0);
} | php | function getLiveMatchServersCount($lobbyLogin, $scriptName, $titleIdString)
{
return $this->db->execute(
'SELECT COUNT(*) FROM MatchServers '.
'WHERE DATE_ADD(lastLive, INTERVAL 15 MINUTE) > NOW() '.
'AND lobbyLogin = %s AND scriptName = %s AND titleIdString = %s',
$this->db->quote($lobbyLogin), $this->db->quote($scriptName), $this->db->quote($titleIdString)
)->fetchSingleValue(0);
} | [
"function",
"getLiveMatchServersCount",
"(",
"$",
"lobbyLogin",
",",
"$",
"scriptName",
",",
"$",
"titleIdString",
")",
"{",
"return",
"$",
"this",
"->",
"db",
"->",
"execute",
"(",
"'SELECT COUNT(*) FROM MatchServers '",
".",
"'WHERE DATE_ADD(lastLive, INTERVAL 15 MINUTE) > NOW() '",
".",
"'AND lobbyLogin = %s AND scriptName = %s AND titleIdString = %s'",
",",
"$",
"this",
"->",
"db",
"->",
"quote",
"(",
"$",
"lobbyLogin",
")",
",",
"$",
"this",
"->",
"db",
"->",
"quote",
"(",
"$",
"scriptName",
")",
",",
"$",
"this",
"->",
"db",
"->",
"quote",
"(",
"$",
"titleIdString",
")",
")",
"->",
"fetchSingleValue",
"(",
"0",
")",
";",
"}"
] | Get the number of server the lobby can use
@param string $lobbyLogin
@param string $scriptName
@param string $titleIdString
@return int | [
"Get",
"the",
"number",
"of",
"server",
"the",
"lobby",
"can",
"use"
] | train | https://github.com/maniaplanet/matchmaking-lobby/blob/384f22cdd2cfb0204a071810549eaf1eb01d8b7f/MatchMakingLobby/Services/MatchMakingService.php#L289-L297 |
maniaplanet/matchmaking-lobby | MatchMakingLobby/Services/MatchMakingService.php | MatchMakingService.getLeaveCount | function getLeaveCount($playerLogin, $lobbyLogin)
{
return $this->db->query(
'SELECT count(*) FROM Players P '.
'INNER JOIN Matches M ON P.matchId = M.id '.
'WHERE P.login = %s AND P.`state` IN (%s) AND M.lobbyLogin = %s '.
'AND M.state NOT IN (%s) '.
'AND DATE_ADD(M.creationDate, INTERVAL 1 HOUR) > NOW()',
$this->db->quote($playerLogin),
implode(',', array(PlayerInfo::PLAYER_STATE_NOT_CONNECTED, PlayerInfo::PLAYER_STATE_QUITTER, PlayerInfo::PLAYER_STATE_GIVE_UP, PlayerInfo::PLAYER_STATE_REPLACED)),
$this->db->quote($lobbyLogin),
implode(',', array(Match::PLAYER_CANCEL))
)->fetchSingleValue(0);
} | php | function getLeaveCount($playerLogin, $lobbyLogin)
{
return $this->db->query(
'SELECT count(*) FROM Players P '.
'INNER JOIN Matches M ON P.matchId = M.id '.
'WHERE P.login = %s AND P.`state` IN (%s) AND M.lobbyLogin = %s '.
'AND M.state NOT IN (%s) '.
'AND DATE_ADD(M.creationDate, INTERVAL 1 HOUR) > NOW()',
$this->db->quote($playerLogin),
implode(',', array(PlayerInfo::PLAYER_STATE_NOT_CONNECTED, PlayerInfo::PLAYER_STATE_QUITTER, PlayerInfo::PLAYER_STATE_GIVE_UP, PlayerInfo::PLAYER_STATE_REPLACED)),
$this->db->quote($lobbyLogin),
implode(',', array(Match::PLAYER_CANCEL))
)->fetchSingleValue(0);
} | [
"function",
"getLeaveCount",
"(",
"$",
"playerLogin",
",",
"$",
"lobbyLogin",
")",
"{",
"return",
"$",
"this",
"->",
"db",
"->",
"query",
"(",
"'SELECT count(*) FROM Players P '",
".",
"'INNER JOIN Matches M ON P.matchId = M.id '",
".",
"'WHERE P.login = %s AND P.`state` IN (%s) AND M.lobbyLogin = %s '",
".",
"'AND M.state NOT IN (%s) '",
".",
"'AND DATE_ADD(M.creationDate, INTERVAL 1 HOUR) > NOW()'",
",",
"$",
"this",
"->",
"db",
"->",
"quote",
"(",
"$",
"playerLogin",
")",
",",
"implode",
"(",
"','",
",",
"array",
"(",
"PlayerInfo",
"::",
"PLAYER_STATE_NOT_CONNECTED",
",",
"PlayerInfo",
"::",
"PLAYER_STATE_QUITTER",
",",
"PlayerInfo",
"::",
"PLAYER_STATE_GIVE_UP",
",",
"PlayerInfo",
"::",
"PLAYER_STATE_REPLACED",
")",
")",
",",
"$",
"this",
"->",
"db",
"->",
"quote",
"(",
"$",
"lobbyLogin",
")",
",",
"implode",
"(",
"','",
",",
"array",
"(",
"Match",
"::",
"PLAYER_CANCEL",
")",
")",
")",
"->",
"fetchSingleValue",
"(",
"0",
")",
";",
"}"
] | Get the number of time the player quit a match for this lobby
@param string $playerLogin
@return int | [
"Get",
"the",
"number",
"of",
"time",
"the",
"player",
"quit",
"a",
"match",
"for",
"this",
"lobby"
] | train | https://github.com/maniaplanet/matchmaking-lobby/blob/384f22cdd2cfb0204a071810549eaf1eb01d8b7f/MatchMakingLobby/Services/MatchMakingService.php#L304-L317 |
maniaplanet/matchmaking-lobby | MatchMakingLobby/Services/MatchMakingService.php | MatchMakingService.countAvailableServer | function countAvailableServer($lobbyLogin, $scriptName, $titleIdString)
{
return $this->db->execute(
'SELECT count(MS.login) FROM MatchServers MS '.
'WHERE MS.lobbyLogin = %s AND MS.scriptName = %s AND MS.titleIdString = %s '.
'AND MS.`state` = %d AND matchId IS NULL '.
'AND DATE_ADD(MS.lastLive, INTERVAL 20 SECOND) > NOW() ',
$this->db->quote($lobbyLogin), $this->db->quote($scriptName), $this->db->quote($titleIdString),
\ManiaLivePlugins\MatchMakingLobby\Match\Plugin::SLEEPING
)->fetchSingleValue(null);
} | php | function countAvailableServer($lobbyLogin, $scriptName, $titleIdString)
{
return $this->db->execute(
'SELECT count(MS.login) FROM MatchServers MS '.
'WHERE MS.lobbyLogin = %s AND MS.scriptName = %s AND MS.titleIdString = %s '.
'AND MS.`state` = %d AND matchId IS NULL '.
'AND DATE_ADD(MS.lastLive, INTERVAL 20 SECOND) > NOW() ',
$this->db->quote($lobbyLogin), $this->db->quote($scriptName), $this->db->quote($titleIdString),
\ManiaLivePlugins\MatchMakingLobby\Match\Plugin::SLEEPING
)->fetchSingleValue(null);
} | [
"function",
"countAvailableServer",
"(",
"$",
"lobbyLogin",
",",
"$",
"scriptName",
",",
"$",
"titleIdString",
")",
"{",
"return",
"$",
"this",
"->",
"db",
"->",
"execute",
"(",
"'SELECT count(MS.login) FROM MatchServers MS '",
".",
"'WHERE MS.lobbyLogin = %s AND MS.scriptName = %s AND MS.titleIdString = %s '",
".",
"'AND MS.`state` = %d AND matchId IS NULL '",
".",
"'AND DATE_ADD(MS.lastLive, INTERVAL 20 SECOND) > NOW() '",
",",
"$",
"this",
"->",
"db",
"->",
"quote",
"(",
"$",
"lobbyLogin",
")",
",",
"$",
"this",
"->",
"db",
"->",
"quote",
"(",
"$",
"scriptName",
")",
",",
"$",
"this",
"->",
"db",
"->",
"quote",
"(",
"$",
"titleIdString",
")",
",",
"\\",
"ManiaLivePlugins",
"\\",
"MatchMakingLobby",
"\\",
"Match",
"\\",
"Plugin",
"::",
"SLEEPING",
")",
"->",
"fetchSingleValue",
"(",
"null",
")",
";",
"}"
] | Get number of server available to host a match
for the lobby
@param string $lobbyLogin
@param string $scriptName
@param string $titleIdString
@return string the match server login | [
"Get",
"number",
"of",
"server",
"available",
"to",
"host",
"a",
"match",
"for",
"the",
"lobby"
] | train | https://github.com/maniaplanet/matchmaking-lobby/blob/384f22cdd2cfb0204a071810549eaf1eb01d8b7f/MatchMakingLobby/Services/MatchMakingService.php#L335-L345 |
maniaplanet/matchmaking-lobby | MatchMakingLobby/Services/MatchMakingService.php | MatchMakingService.getAverageTimeBetweenMatches | function getAverageTimeBetweenMatches($lobbyLogin, $scriptName, $titleIdString)
{
$creationTimestamps = $this->db->execute(
'SELECT UNIX_TIMESTAMP(creationDate) '.
'FROM Matches m '.
'WHERE m.lobbyLogin = %s '.
'AND m.scriptName = %s '.
'AND m.titleIdString = %s '.
'AND m.state NOT IN (%s) AND m.creationDate > DATE_SUB(NOW(), INTERVAL 1 HOUR) '.
'ORDER BY creationDate ASC LIMIT 10', $this->db->quote($lobbyLogin),
$this->db->quote($scriptName), $this->db->quote($titleIdString), implode(',',array(Match::PLAYER_CANCEL))
)->fetchArrayOfSingleValues();
if(count($creationTimestamps) < 2)
{
return -1;
}
$sum = 0;
for($i = 1; $i < count($creationTimestamps); $i++)
{
$sum += $creationTimestamps[$i] - $creationTimestamps[$i - 1];
}
return $sum / (count($creationTimestamps) - 1);
} | php | function getAverageTimeBetweenMatches($lobbyLogin, $scriptName, $titleIdString)
{
$creationTimestamps = $this->db->execute(
'SELECT UNIX_TIMESTAMP(creationDate) '.
'FROM Matches m '.
'WHERE m.lobbyLogin = %s '.
'AND m.scriptName = %s '.
'AND m.titleIdString = %s '.
'AND m.state NOT IN (%s) AND m.creationDate > DATE_SUB(NOW(), INTERVAL 1 HOUR) '.
'ORDER BY creationDate ASC LIMIT 10', $this->db->quote($lobbyLogin),
$this->db->quote($scriptName), $this->db->quote($titleIdString), implode(',',array(Match::PLAYER_CANCEL))
)->fetchArrayOfSingleValues();
if(count($creationTimestamps) < 2)
{
return -1;
}
$sum = 0;
for($i = 1; $i < count($creationTimestamps); $i++)
{
$sum += $creationTimestamps[$i] - $creationTimestamps[$i - 1];
}
return $sum / (count($creationTimestamps) - 1);
} | [
"function",
"getAverageTimeBetweenMatches",
"(",
"$",
"lobbyLogin",
",",
"$",
"scriptName",
",",
"$",
"titleIdString",
")",
"{",
"$",
"creationTimestamps",
"=",
"$",
"this",
"->",
"db",
"->",
"execute",
"(",
"'SELECT UNIX_TIMESTAMP(creationDate) '",
".",
"'FROM Matches m '",
".",
"'WHERE m.lobbyLogin = %s '",
".",
"'AND m.scriptName = %s '",
".",
"'AND m.titleIdString = %s '",
".",
"'AND m.state NOT IN (%s) AND m.creationDate > DATE_SUB(NOW(), INTERVAL 1 HOUR) '",
".",
"'ORDER BY creationDate ASC LIMIT 10'",
",",
"$",
"this",
"->",
"db",
"->",
"quote",
"(",
"$",
"lobbyLogin",
")",
",",
"$",
"this",
"->",
"db",
"->",
"quote",
"(",
"$",
"scriptName",
")",
",",
"$",
"this",
"->",
"db",
"->",
"quote",
"(",
"$",
"titleIdString",
")",
",",
"implode",
"(",
"','",
",",
"array",
"(",
"Match",
"::",
"PLAYER_CANCEL",
")",
")",
")",
"->",
"fetchArrayOfSingleValues",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"creationTimestamps",
")",
"<",
"2",
")",
"{",
"return",
"-",
"1",
";",
"}",
"$",
"sum",
"=",
"0",
";",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"creationTimestamps",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"sum",
"+=",
"$",
"creationTimestamps",
"[",
"$",
"i",
"]",
"-",
"$",
"creationTimestamps",
"[",
"$",
"i",
"-",
"1",
"]",
";",
"}",
"return",
"$",
"sum",
"/",
"(",
"count",
"(",
"$",
"creationTimestamps",
")",
"-",
"1",
")",
";",
"}"
] | Get average time between two match. This time is compute with matches over the last hour
If there is not anough matches in database, it returns -1
@param string $lobbyLogin
@param string $scriptName
@param string $titleIdString
@return float Number of seconds | [
"Get",
"average",
"time",
"between",
"two",
"match",
".",
"This",
"time",
"is",
"compute",
"with",
"matches",
"over",
"the",
"last",
"hour",
"If",
"there",
"is",
"not",
"anough",
"matches",
"in",
"database",
"it",
"returns",
"-",
"1"
] | train | https://github.com/maniaplanet/matchmaking-lobby/blob/384f22cdd2cfb0204a071810549eaf1eb01d8b7f/MatchMakingLobby/Services/MatchMakingService.php#L477-L501 |
maniaplanet/matchmaking-lobby | MatchMakingLobby/Services/MatchMakingService.php | MatchMakingService.registerMatch | function registerMatch($serverLogin, Match $match, $scriptName, $titleIdString, $lobbyLogin)
{
$this->db->execute('BEGIN');
try
{
$this->db->execute(
'INSERT INTO Matches (creationDate, state, matchServerLogin, scriptName, titleIdString, lobbyLogin) '.
'VALUES (NOW(), -1, %s, %s, %s, %s)',
$this->db->quote($serverLogin),
$this->db->quote($scriptName),
$this->db->quote($titleIdString),
$this->db->quote($lobbyLogin)
);
$matchId = $this->db->insertID();
$this->updateServerCurrentMatchId($matchId, $serverLogin, $scriptName, $titleIdString);
foreach($match->players as $player)
{
$this->addMatchPlayer($matchId, $player, $match->getTeam($player));
}
$this->db->execute('COMMIT');
}
catch(\Exception $e)
{
$this->db->execute('ROLLBACK');
throw $e;
}
return $matchId;
} | php | function registerMatch($serverLogin, Match $match, $scriptName, $titleIdString, $lobbyLogin)
{
$this->db->execute('BEGIN');
try
{
$this->db->execute(
'INSERT INTO Matches (creationDate, state, matchServerLogin, scriptName, titleIdString, lobbyLogin) '.
'VALUES (NOW(), -1, %s, %s, %s, %s)',
$this->db->quote($serverLogin),
$this->db->quote($scriptName),
$this->db->quote($titleIdString),
$this->db->quote($lobbyLogin)
);
$matchId = $this->db->insertID();
$this->updateServerCurrentMatchId($matchId, $serverLogin, $scriptName, $titleIdString);
foreach($match->players as $player)
{
$this->addMatchPlayer($matchId, $player, $match->getTeam($player));
}
$this->db->execute('COMMIT');
}
catch(\Exception $e)
{
$this->db->execute('ROLLBACK');
throw $e;
}
return $matchId;
} | [
"function",
"registerMatch",
"(",
"$",
"serverLogin",
",",
"Match",
"$",
"match",
",",
"$",
"scriptName",
",",
"$",
"titleIdString",
",",
"$",
"lobbyLogin",
")",
"{",
"$",
"this",
"->",
"db",
"->",
"execute",
"(",
"'BEGIN'",
")",
";",
"try",
"{",
"$",
"this",
"->",
"db",
"->",
"execute",
"(",
"'INSERT INTO Matches (creationDate, state, matchServerLogin, scriptName, titleIdString, lobbyLogin) '",
".",
"'VALUES (NOW(), -1, %s, %s, %s, %s)'",
",",
"$",
"this",
"->",
"db",
"->",
"quote",
"(",
"$",
"serverLogin",
")",
",",
"$",
"this",
"->",
"db",
"->",
"quote",
"(",
"$",
"scriptName",
")",
",",
"$",
"this",
"->",
"db",
"->",
"quote",
"(",
"$",
"titleIdString",
")",
",",
"$",
"this",
"->",
"db",
"->",
"quote",
"(",
"$",
"lobbyLogin",
")",
")",
";",
"$",
"matchId",
"=",
"$",
"this",
"->",
"db",
"->",
"insertID",
"(",
")",
";",
"$",
"this",
"->",
"updateServerCurrentMatchId",
"(",
"$",
"matchId",
",",
"$",
"serverLogin",
",",
"$",
"scriptName",
",",
"$",
"titleIdString",
")",
";",
"foreach",
"(",
"$",
"match",
"->",
"players",
"as",
"$",
"player",
")",
"{",
"$",
"this",
"->",
"addMatchPlayer",
"(",
"$",
"matchId",
",",
"$",
"player",
",",
"$",
"match",
"->",
"getTeam",
"(",
"$",
"player",
")",
")",
";",
"}",
"$",
"this",
"->",
"db",
"->",
"execute",
"(",
"'COMMIT'",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"db",
"->",
"execute",
"(",
"'ROLLBACK'",
")",
";",
"throw",
"$",
"e",
";",
"}",
"return",
"$",
"matchId",
";",
"}"
] | Register a match in database, the match Server will use this to ready up
@param string $serverLogin
@param \ManiaLivePlugins\MatchMakingLobby\Services\Match $match
@param string $scriptName
@param string $titleIdString
@return int $matchId | [
"Register",
"a",
"match",
"in",
"database",
"the",
"match",
"Server",
"will",
"use",
"this",
"to",
"ready",
"up"
] | train | https://github.com/maniaplanet/matchmaking-lobby/blob/384f22cdd2cfb0204a071810549eaf1eb01d8b7f/MatchMakingLobby/Services/MatchMakingService.php#L523-L553 |
maniaplanet/matchmaking-lobby | MatchMakingLobby/Services/MatchMakingService.php | MatchMakingService.updatePlayerState | function updatePlayerState($playerLogin, $matchId, $state)
{
$this->db->execute(
'UPDATE Players SET state = %d WHERE login = %s AND matchId = %d',
$state,
$this->db->quote($playerLogin),
$matchId
);
} | php | function updatePlayerState($playerLogin, $matchId, $state)
{
$this->db->execute(
'UPDATE Players SET state = %d WHERE login = %s AND matchId = %d',
$state,
$this->db->quote($playerLogin),
$matchId
);
} | [
"function",
"updatePlayerState",
"(",
"$",
"playerLogin",
",",
"$",
"matchId",
",",
"$",
"state",
")",
"{",
"$",
"this",
"->",
"db",
"->",
"execute",
"(",
"'UPDATE Players SET state = %d WHERE login = %s AND matchId = %d'",
",",
"$",
"state",
",",
"$",
"this",
"->",
"db",
"->",
"quote",
"(",
"$",
"playerLogin",
")",
",",
"$",
"matchId",
")",
";",
"}"
] | Set the new player state
@param string $playerLogin
@param int $matchId
@param int $state | [
"Set",
"the",
"new",
"player",
"state"
] | train | https://github.com/maniaplanet/matchmaking-lobby/blob/384f22cdd2cfb0204a071810549eaf1eb01d8b7f/MatchMakingLobby/Services/MatchMakingService.php#L594-L602 |
maniaplanet/matchmaking-lobby | MatchMakingLobby/Services/MatchMakingService.php | MatchMakingService.updatePlayerRank | function updatePlayerRank($playerLogin, $matchId, $rank)
{
$this->db->execute(
'UPDATE Players SET rank = %d WHERE login = %s AND matchId = %d',
$rank,
$this->db->quote($playerLogin),
$matchId
);
} | php | function updatePlayerRank($playerLogin, $matchId, $rank)
{
$this->db->execute(
'UPDATE Players SET rank = %d WHERE login = %s AND matchId = %d',
$rank,
$this->db->quote($playerLogin),
$matchId
);
} | [
"function",
"updatePlayerRank",
"(",
"$",
"playerLogin",
",",
"$",
"matchId",
",",
"$",
"rank",
")",
"{",
"$",
"this",
"->",
"db",
"->",
"execute",
"(",
"'UPDATE Players SET rank = %d WHERE login = %s AND matchId = %d'",
",",
"$",
"rank",
",",
"$",
"this",
"->",
"db",
"->",
"quote",
"(",
"$",
"playerLogin",
")",
",",
"$",
"matchId",
")",
";",
"}"
] | Register the player rank on his match
@param string $playerLogin
@param int $matchId
@param int $rank | [
"Register",
"the",
"player",
"rank",
"on",
"his",
"match"
] | train | https://github.com/maniaplanet/matchmaking-lobby/blob/384f22cdd2cfb0204a071810549eaf1eb01d8b7f/MatchMakingLobby/Services/MatchMakingService.php#L610-L618 |
maniaplanet/matchmaking-lobby | MatchMakingLobby/Services/MatchMakingService.php | MatchMakingService.registerMatchServer | function registerMatchServer($serverLogin, $lobbyLogin, $state, $scriptName, $titleIdString, $currentMap)
{
$this->db->execute(
'INSERT INTO MatchServers (login, lobbyLogin, state, lastLive, scriptName, titleIdString, currentMap) '.
'VALUES(%s, %s, %d, NOW(), %s, %s, %s) '.
'ON DUPLICATE KEY UPDATE state=VALUES(state), lobbyLogin=VALUES(lobbyLogin), lastLive=VALUES(lastLive), currentMap=VALUES(currentMap)',
$this->db->quote($serverLogin),
$this->db->quote($lobbyLogin),
$state,
$this->db->quote($scriptName),
$this->db->quote($titleIdString),
$this->db->quote($currentMap)
);
} | php | function registerMatchServer($serverLogin, $lobbyLogin, $state, $scriptName, $titleIdString, $currentMap)
{
$this->db->execute(
'INSERT INTO MatchServers (login, lobbyLogin, state, lastLive, scriptName, titleIdString, currentMap) '.
'VALUES(%s, %s, %d, NOW(), %s, %s, %s) '.
'ON DUPLICATE KEY UPDATE state=VALUES(state), lobbyLogin=VALUES(lobbyLogin), lastLive=VALUES(lastLive), currentMap=VALUES(currentMap)',
$this->db->quote($serverLogin),
$this->db->quote($lobbyLogin),
$state,
$this->db->quote($scriptName),
$this->db->quote($titleIdString),
$this->db->quote($currentMap)
);
} | [
"function",
"registerMatchServer",
"(",
"$",
"serverLogin",
",",
"$",
"lobbyLogin",
",",
"$",
"state",
",",
"$",
"scriptName",
",",
"$",
"titleIdString",
",",
"$",
"currentMap",
")",
"{",
"$",
"this",
"->",
"db",
"->",
"execute",
"(",
"'INSERT INTO MatchServers (login, lobbyLogin, state, lastLive, scriptName, titleIdString, currentMap) '",
".",
"'VALUES(%s, %s, %d, NOW(), %s, %s, %s) '",
".",
"'ON DUPLICATE KEY UPDATE state=VALUES(state), lobbyLogin=VALUES(lobbyLogin), lastLive=VALUES(lastLive), currentMap=VALUES(currentMap)'",
",",
"$",
"this",
"->",
"db",
"->",
"quote",
"(",
"$",
"serverLogin",
")",
",",
"$",
"this",
"->",
"db",
"->",
"quote",
"(",
"$",
"lobbyLogin",
")",
",",
"$",
"state",
",",
"$",
"this",
"->",
"db",
"->",
"quote",
"(",
"$",
"scriptName",
")",
",",
"$",
"this",
"->",
"db",
"->",
"quote",
"(",
"$",
"titleIdString",
")",
",",
"$",
"this",
"->",
"db",
"->",
"quote",
"(",
"$",
"currentMap",
")",
")",
";",
"}"
] | Register a server as match server
@param string $serverLogin
@param string $lobbyLogin
@param string $state | [
"Register",
"a",
"server",
"as",
"match",
"server"
] | train | https://github.com/maniaplanet/matchmaking-lobby/blob/384f22cdd2cfb0204a071810549eaf1eb01d8b7f/MatchMakingLobby/Services/MatchMakingService.php#L626-L639 |
maniaplanet/matchmaking-lobby | MatchMakingLobby/Services/MatchMakingService.php | MatchMakingService.registerLobby | function registerLobby($lobbyLogin, $readyPlayersCount, $connectedPlayersCount, $serverName, $backLink)
{
$this->db->execute(
'INSERT INTO LobbyServers VALUES (%s, %s, %s, %d, %d) '.
'ON DUPLICATE KEY UPDATE '.
'name = VALUES(name), '.
'backLink = VALUES(backLink), '.
'readyPlayers = VALUES(readyPlayers), '.
'connectedPlayers = VALUES(connectedPlayers) ',
$this->db->quote($lobbyLogin), $this->db->quote($serverName), $this->db->quote($backLink),
$readyPlayersCount, $connectedPlayersCount
);
} | php | function registerLobby($lobbyLogin, $readyPlayersCount, $connectedPlayersCount, $serverName, $backLink)
{
$this->db->execute(
'INSERT INTO LobbyServers VALUES (%s, %s, %s, %d, %d) '.
'ON DUPLICATE KEY UPDATE '.
'name = VALUES(name), '.
'backLink = VALUES(backLink), '.
'readyPlayers = VALUES(readyPlayers), '.
'connectedPlayers = VALUES(connectedPlayers) ',
$this->db->quote($lobbyLogin), $this->db->quote($serverName), $this->db->quote($backLink),
$readyPlayersCount, $connectedPlayersCount
);
} | [
"function",
"registerLobby",
"(",
"$",
"lobbyLogin",
",",
"$",
"readyPlayersCount",
",",
"$",
"connectedPlayersCount",
",",
"$",
"serverName",
",",
"$",
"backLink",
")",
"{",
"$",
"this",
"->",
"db",
"->",
"execute",
"(",
"'INSERT INTO LobbyServers VALUES (%s, %s, %s, %d, %d) '",
".",
"'ON DUPLICATE KEY UPDATE '",
".",
"'name = VALUES(name), '",
".",
"'backLink = VALUES(backLink), '",
".",
"'readyPlayers = VALUES(readyPlayers), '",
".",
"'connectedPlayers = VALUES(connectedPlayers) '",
",",
"$",
"this",
"->",
"db",
"->",
"quote",
"(",
"$",
"lobbyLogin",
")",
",",
"$",
"this",
"->",
"db",
"->",
"quote",
"(",
"$",
"serverName",
")",
",",
"$",
"this",
"->",
"db",
"->",
"quote",
"(",
"$",
"backLink",
")",
",",
"$",
"readyPlayersCount",
",",
"$",
"connectedPlayersCount",
")",
";",
"}"
] | Register a lobby server in the system
@param string $lobbyLogin
@param int $readyPlayersCount
@param int $connectedPlayersCount
@param string $serverName
@param string $backLink | [
"Register",
"a",
"lobby",
"server",
"in",
"the",
"system"
] | train | https://github.com/maniaplanet/matchmaking-lobby/blob/384f22cdd2cfb0204a071810549eaf1eb01d8b7f/MatchMakingLobby/Services/MatchMakingService.php#L663-L675 |
yuncms/framework | src/web/UploadedFile.php | UploadedFile.hashName | public function hashName($path = null)
{
if ($path) {
$path = rtrim($path, '/') . '/';
}
$hash = $this->hashName ?: $this->hashName = StringHelper::randomString(40);
return $path . $hash . '.' . $this->getExtension();
} | php | public function hashName($path = null)
{
if ($path) {
$path = rtrim($path, '/') . '/';
}
$hash = $this->hashName ?: $this->hashName = StringHelper::randomString(40);
return $path . $hash . '.' . $this->getExtension();
} | [
"public",
"function",
"hashName",
"(",
"$",
"path",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"path",
")",
"{",
"$",
"path",
"=",
"rtrim",
"(",
"$",
"path",
",",
"'/'",
")",
".",
"'/'",
";",
"}",
"$",
"hash",
"=",
"$",
"this",
"->",
"hashName",
"?",
":",
"$",
"this",
"->",
"hashName",
"=",
"StringHelper",
"::",
"randomString",
"(",
"40",
")",
";",
"return",
"$",
"path",
".",
"$",
"hash",
".",
"'.'",
".",
"$",
"this",
"->",
"getExtension",
"(",
")",
";",
"}"
] | Get a filename for the file.
@param string $path
@return string
@throws \Exception | [
"Get",
"a",
"filename",
"for",
"the",
"file",
"."
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/web/UploadedFile.php#L47-L54 |
yuncms/framework | src/web/UploadedFile.php | UploadedFile.getInstanceByBase64 | public static function getInstanceByBase64($fileName, $base64Data)
{
$fileData = base64_decode($base64Data);
$baseName = basename($fileName);
$tempPath = FileHelper::getTempFilePath($baseName);
file_put_contents($tempPath, $fileData);
return new static([
'isUploadedFile' => false,
'name' => $baseName,
'tempName' => $tempPath,
'type' => FileHelper::getMimeType($tempPath),
'size' => strlen($fileData),
'error' => UPLOAD_ERR_OK,
]);
} | php | public static function getInstanceByBase64($fileName, $base64Data)
{
$fileData = base64_decode($base64Data);
$baseName = basename($fileName);
$tempPath = FileHelper::getTempFilePath($baseName);
file_put_contents($tempPath, $fileData);
return new static([
'isUploadedFile' => false,
'name' => $baseName,
'tempName' => $tempPath,
'type' => FileHelper::getMimeType($tempPath),
'size' => strlen($fileData),
'error' => UPLOAD_ERR_OK,
]);
} | [
"public",
"static",
"function",
"getInstanceByBase64",
"(",
"$",
"fileName",
",",
"$",
"base64Data",
")",
"{",
"$",
"fileData",
"=",
"base64_decode",
"(",
"$",
"base64Data",
")",
";",
"$",
"baseName",
"=",
"basename",
"(",
"$",
"fileName",
")",
";",
"$",
"tempPath",
"=",
"FileHelper",
"::",
"getTempFilePath",
"(",
"$",
"baseName",
")",
";",
"file_put_contents",
"(",
"$",
"tempPath",
",",
"$",
"fileData",
")",
";",
"return",
"new",
"static",
"(",
"[",
"'isUploadedFile'",
"=>",
"false",
",",
"'name'",
"=>",
"$",
"baseName",
",",
"'tempName'",
"=>",
"$",
"tempPath",
",",
"'type'",
"=>",
"FileHelper",
"::",
"getMimeType",
"(",
"$",
"tempPath",
")",
",",
"'size'",
"=>",
"strlen",
"(",
"$",
"fileData",
")",
",",
"'error'",
"=>",
"UPLOAD_ERR_OK",
",",
"]",
")",
";",
"}"
] | 返回一个Base64加载的文件实例
@param string $fileName the file name.
@param string $base64Data the base64Data of the file base64 data.
@return null|UploadedFile the instance of the uploaded file.
@throws \yii\base\Exception
@throws \yii\base\InvalidConfigException | [
"返回一个Base64加载的文件实例"
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/web/UploadedFile.php#L64-L78 |
yuncms/framework | src/web/UploadedFile.php | UploadedFile.getInstanceByRemote | public static function getInstanceByRemote($url)
{
$validator = new UrlValidator();
if ($validator->validate($url, $error)) {
$url = str_replace("&", "&", $url);
$http = new Client();
$response = $http->get($url)->send();
if (!$response->isOk) {
return null;
} else {
$baseName = basename($url);
$tempPath = FileHelper::getTempFilePath($baseName);
file_put_contents($tempPath, $response->content);
return new static([
'isUploadedFile' => false,
'name' => $baseName,
'tempName' => $tempPath,
'type' => FileHelper::getMimeType($tempPath),
'size' => strlen($response->content),
'error' => UPLOAD_ERR_OK,
]);
}
} else {
return null;
}
} | php | public static function getInstanceByRemote($url)
{
$validator = new UrlValidator();
if ($validator->validate($url, $error)) {
$url = str_replace("&", "&", $url);
$http = new Client();
$response = $http->get($url)->send();
if (!$response->isOk) {
return null;
} else {
$baseName = basename($url);
$tempPath = FileHelper::getTempFilePath($baseName);
file_put_contents($tempPath, $response->content);
return new static([
'isUploadedFile' => false,
'name' => $baseName,
'tempName' => $tempPath,
'type' => FileHelper::getMimeType($tempPath),
'size' => strlen($response->content),
'error' => UPLOAD_ERR_OK,
]);
}
} else {
return null;
}
} | [
"public",
"static",
"function",
"getInstanceByRemote",
"(",
"$",
"url",
")",
"{",
"$",
"validator",
"=",
"new",
"UrlValidator",
"(",
")",
";",
"if",
"(",
"$",
"validator",
"->",
"validate",
"(",
"$",
"url",
",",
"$",
"error",
")",
")",
"{",
"$",
"url",
"=",
"str_replace",
"(",
"\"&\"",
",",
"\"&\"",
",",
"$",
"url",
")",
";",
"$",
"http",
"=",
"new",
"Client",
"(",
")",
";",
"$",
"response",
"=",
"$",
"http",
"->",
"get",
"(",
"$",
"url",
")",
"->",
"send",
"(",
")",
";",
"if",
"(",
"!",
"$",
"response",
"->",
"isOk",
")",
"{",
"return",
"null",
";",
"}",
"else",
"{",
"$",
"baseName",
"=",
"basename",
"(",
"$",
"url",
")",
";",
"$",
"tempPath",
"=",
"FileHelper",
"::",
"getTempFilePath",
"(",
"$",
"baseName",
")",
";",
"file_put_contents",
"(",
"$",
"tempPath",
",",
"$",
"response",
"->",
"content",
")",
";",
"return",
"new",
"static",
"(",
"[",
"'isUploadedFile'",
"=>",
"false",
",",
"'name'",
"=>",
"$",
"baseName",
",",
"'tempName'",
"=>",
"$",
"tempPath",
",",
"'type'",
"=>",
"FileHelper",
"::",
"getMimeType",
"(",
"$",
"tempPath",
")",
",",
"'size'",
"=>",
"strlen",
"(",
"$",
"response",
"->",
"content",
")",
",",
"'error'",
"=>",
"UPLOAD_ERR_OK",
",",
"]",
")",
";",
"}",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] | 返回一个从远程加载的文件实例
@param string $url the url of the file url path.
@return null|UploadedFile the instance of the uploaded file.
@throws \yii\base\InvalidConfigException
@throws \yii\base\Exception | [
"返回一个从远程加载的文件实例"
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/web/UploadedFile.php#L87-L112 |
yuncms/framework | src/web/UploadedFile.php | UploadedFile.getInstanceByLocal | public static function getInstanceByLocal($path)
{
$fileContent = file_get_contents($path);
return new static([
'isUploadedFile' => false,
'name' => basename($path),
'tempName' => $path,
'type' => FileHelper::getMimeType($path),
'size' => strlen($fileContent),
'error' => UPLOAD_ERR_OK,
]);
} | php | public static function getInstanceByLocal($path)
{
$fileContent = file_get_contents($path);
return new static([
'isUploadedFile' => false,
'name' => basename($path),
'tempName' => $path,
'type' => FileHelper::getMimeType($path),
'size' => strlen($fileContent),
'error' => UPLOAD_ERR_OK,
]);
} | [
"public",
"static",
"function",
"getInstanceByLocal",
"(",
"$",
"path",
")",
"{",
"$",
"fileContent",
"=",
"file_get_contents",
"(",
"$",
"path",
")",
";",
"return",
"new",
"static",
"(",
"[",
"'isUploadedFile'",
"=>",
"false",
",",
"'name'",
"=>",
"basename",
"(",
"$",
"path",
")",
",",
"'tempName'",
"=>",
"$",
"path",
",",
"'type'",
"=>",
"FileHelper",
"::",
"getMimeType",
"(",
"$",
"path",
")",
",",
"'size'",
"=>",
"strlen",
"(",
"$",
"fileContent",
")",
",",
"'error'",
"=>",
"UPLOAD_ERR_OK",
",",
"]",
")",
";",
"}"
] | 返回一个从本地加载的文件实例
@param string $path the path of the file local path.
@return null|UploadedFile the instance of the uploaded file.
@throws \yii\base\InvalidConfigException | [
"返回一个从本地加载的文件实例"
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/web/UploadedFile.php#L120-L131 |
yuncms/framework | src/web/UploadedFile.php | UploadedFile.save | public function save()
{
$filePath = $this->getRename();
if (!UploadHelper::getDisk()->exists($filePath)) {
$type = $this->getMimeType();
$fileContent = FileHelper::readAndDelete($this->tempName);
UploadHelper::getDisk()->put($filePath, $fileContent, [
'visibility' => AdapterInterface::VISIBILITY_PUBLIC
]);
$model = new Attachment([
'filename' => basename($filePath),
'original_name' => $this->name,
'path' => $filePath,
'size' => $this->size,
'type' => $type,
]);
if ($model->save()) {
return $model;
}
}
return false;
} | php | public function save()
{
$filePath = $this->getRename();
if (!UploadHelper::getDisk()->exists($filePath)) {
$type = $this->getMimeType();
$fileContent = FileHelper::readAndDelete($this->tempName);
UploadHelper::getDisk()->put($filePath, $fileContent, [
'visibility' => AdapterInterface::VISIBILITY_PUBLIC
]);
$model = new Attachment([
'filename' => basename($filePath),
'original_name' => $this->name,
'path' => $filePath,
'size' => $this->size,
'type' => $type,
]);
if ($model->save()) {
return $model;
}
}
return false;
} | [
"public",
"function",
"save",
"(",
")",
"{",
"$",
"filePath",
"=",
"$",
"this",
"->",
"getRename",
"(",
")",
";",
"if",
"(",
"!",
"UploadHelper",
"::",
"getDisk",
"(",
")",
"->",
"exists",
"(",
"$",
"filePath",
")",
")",
"{",
"$",
"type",
"=",
"$",
"this",
"->",
"getMimeType",
"(",
")",
";",
"$",
"fileContent",
"=",
"FileHelper",
"::",
"readAndDelete",
"(",
"$",
"this",
"->",
"tempName",
")",
";",
"UploadHelper",
"::",
"getDisk",
"(",
")",
"->",
"put",
"(",
"$",
"filePath",
",",
"$",
"fileContent",
",",
"[",
"'visibility'",
"=>",
"AdapterInterface",
"::",
"VISIBILITY_PUBLIC",
"]",
")",
";",
"$",
"model",
"=",
"new",
"Attachment",
"(",
"[",
"'filename'",
"=>",
"basename",
"(",
"$",
"filePath",
")",
",",
"'original_name'",
"=>",
"$",
"this",
"->",
"name",
",",
"'path'",
"=>",
"$",
"filePath",
",",
"'size'",
"=>",
"$",
"this",
"->",
"size",
",",
"'type'",
"=>",
"$",
"type",
",",
"]",
")",
";",
"if",
"(",
"$",
"model",
"->",
"save",
"(",
")",
")",
"{",
"return",
"$",
"model",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | 保存上传文件到模型
@return bool|Attachment
@throws \yii\base\ErrorException
@throws \yii\base\InvalidConfigException
@throws \Exception | [
"保存上传文件到模型"
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/web/UploadedFile.php#L159-L180 |
yuncms/framework | src/web/UploadedFile.php | UploadedFile.saveAsTempFile | public function saveAsTempFile(bool $deleteTempFile = true)
{
if ($this->error != UPLOAD_ERR_OK) {
return false;
}
$tempPath = FileHelper::getTempFilePath($this->name);
if (!$this->saveAs($tempPath, $deleteTempFile)) {
return false;
}
return $tempPath;
} | php | public function saveAsTempFile(bool $deleteTempFile = true)
{
if ($this->error != UPLOAD_ERR_OK) {
return false;
}
$tempPath = FileHelper::getTempFilePath($this->name);
if (!$this->saveAs($tempPath, $deleteTempFile)) {
return false;
}
return $tempPath;
} | [
"public",
"function",
"saveAsTempFile",
"(",
"bool",
"$",
"deleteTempFile",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"error",
"!=",
"UPLOAD_ERR_OK",
")",
"{",
"return",
"false",
";",
"}",
"$",
"tempPath",
"=",
"FileHelper",
"::",
"getTempFilePath",
"(",
"$",
"this",
"->",
"name",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"saveAs",
"(",
"$",
"tempPath",
",",
"$",
"deleteTempFile",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"tempPath",
";",
"}"
] | Saves the uploaded file to a temp location.
@param bool $deleteTempFile whether to delete the temporary file after saving.
If true, you will not be able to save the uploaded file again in the current request.
@return string|false the path to the temp file, or false if the file wasn't saved successfully
@see error
@throws \yii\base\Exception | [
"Saves",
"the",
"uploaded",
"file",
"to",
"a",
"temp",
"location",
"."
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/web/UploadedFile.php#L193-L203 |
TypistTech/wp-kses-view | src/ViewAwareTrait.php | ViewAwareTrait.getView | public function getView(): ViewInterface
{
if (null === $this->view) {
$this->setView(
$this->getDefaultView()
);
}
return $this->view;
} | php | public function getView(): ViewInterface
{
if (null === $this->view) {
$this->setView(
$this->getDefaultView()
);
}
return $this->view;
} | [
"public",
"function",
"getView",
"(",
")",
":",
"ViewInterface",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"view",
")",
"{",
"$",
"this",
"->",
"setView",
"(",
"$",
"this",
"->",
"getDefaultView",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"view",
";",
"}"
] | View getter.
@throws UnexpectedValueException If view is null.
@throws UnexpectedValueException If view is not an instance of ViewInterface.
@return ViewInterface | [
"View",
"getter",
"."
] | train | https://github.com/TypistTech/wp-kses-view/blob/6a5e5a34b81c6387d1c5356c9e42166daec9225f/src/ViewAwareTrait.php#L51-L60 |
ronanguilloux/SilexMarkdownServiceProvider | src/Rg/Silex/Provider/Markdown/MarkdownServiceProvider.php | MarkdownServiceProvider.register | public function register(Application $app)
{
$app['md.parser'] = $app->share(function () use ($app) {
return new MarkdownExtended();
});
$app['md.finder'] = $app->share(function () use ($app) {
$args = array('path' => ($app['md.path']) ? $app['md.path'] : null);
return new Finder($args);
});
} | php | public function register(Application $app)
{
$app['md.parser'] = $app->share(function () use ($app) {
return new MarkdownExtended();
});
$app['md.finder'] = $app->share(function () use ($app) {
$args = array('path' => ($app['md.path']) ? $app['md.path'] : null);
return new Finder($args);
});
} | [
"public",
"function",
"register",
"(",
"Application",
"$",
"app",
")",
"{",
"$",
"app",
"[",
"'md.parser'",
"]",
"=",
"$",
"app",
"->",
"share",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"MarkdownExtended",
"(",
")",
";",
"}",
")",
";",
"$",
"app",
"[",
"'md.finder'",
"]",
"=",
"$",
"app",
"->",
"share",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"app",
")",
"{",
"$",
"args",
"=",
"array",
"(",
"'path'",
"=>",
"(",
"$",
"app",
"[",
"'md.path'",
"]",
")",
"?",
"$",
"app",
"[",
"'md.path'",
"]",
":",
"null",
")",
";",
"return",
"new",
"Finder",
"(",
"$",
"args",
")",
";",
"}",
")",
";",
"}"
] | register
@param Application $app
@return mixed registered services | [
"register"
] | train | https://github.com/ronanguilloux/SilexMarkdownServiceProvider/blob/8266baf0b8a74a98ea32ba1417d767dca6b374b3/src/Rg/Silex/Provider/Markdown/MarkdownServiceProvider.php#L36-L47 |
Craftsware/scissor | src/Module.php | Module.get | public function get($value = null) {
$data = $this->collection();
if(is_array($value)) {
$args = [];
foreach($value as $name) {
if(isset($data[$name])) {
$args[$name] = $data[$name];
}
}
return $args;
} else {
if(isset($data[$value])) {
return $data[$value];
} else {
// Get Variables
if(isset($data['var'][$value])) {
return $data['var'][$value];
}
// Get library
if(isset($data['lib'][$value])) {
return $data['lib'][$value];
}
}
}
} | php | public function get($value = null) {
$data = $this->collection();
if(is_array($value)) {
$args = [];
foreach($value as $name) {
if(isset($data[$name])) {
$args[$name] = $data[$name];
}
}
return $args;
} else {
if(isset($data[$value])) {
return $data[$value];
} else {
// Get Variables
if(isset($data['var'][$value])) {
return $data['var'][$value];
}
// Get library
if(isset($data['lib'][$value])) {
return $data['lib'][$value];
}
}
}
} | [
"public",
"function",
"get",
"(",
"$",
"value",
"=",
"null",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"collection",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"args",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"value",
"as",
"$",
"name",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"args",
"[",
"$",
"name",
"]",
"=",
"$",
"data",
"[",
"$",
"name",
"]",
";",
"}",
"}",
"return",
"$",
"args",
";",
"}",
"else",
"{",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"$",
"value",
"]",
")",
")",
"{",
"return",
"$",
"data",
"[",
"$",
"value",
"]",
";",
"}",
"else",
"{",
"// Get Variables",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'var'",
"]",
"[",
"$",
"value",
"]",
")",
")",
"{",
"return",
"$",
"data",
"[",
"'var'",
"]",
"[",
"$",
"value",
"]",
";",
"}",
"// Get library",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'lib'",
"]",
"[",
"$",
"value",
"]",
")",
")",
"{",
"return",
"$",
"data",
"[",
"'lib'",
"]",
"[",
"$",
"value",
"]",
";",
"}",
"}",
"}",
"}"
] | Get data
@param mixed $value
@return array | [
"Get",
"data"
] | train | https://github.com/Craftsware/scissor/blob/644e4a8ea9859fc30fee36705e54784acd8d43e2/src/Module.php#L103-L142 |
Craftsware/scissor | src/Module.php | Module.model | public function model($name, $inject = null) {
// Model instance
$instance = function($path) use ($inject) {
if(class_exists($namespace = 'App\\Modules\\' . str_replace('/', '\\', $path))) {
return new $namespace($inject);
}
};
// Split module and model name
if(strstr($name, '/')) {
$name = explode('/', $name);
return $instance($name[0] . '/Models/' . $name[1]);
}
if(isset($this->module['name'])) {
if($model = $instance($this->module['name'] . '/Models/'. $name)) {
return $model;
}
}
// Use module name if model name is not defined
return $instance($name . '/Models/' . $name);
} | php | public function model($name, $inject = null) {
// Model instance
$instance = function($path) use ($inject) {
if(class_exists($namespace = 'App\\Modules\\' . str_replace('/', '\\', $path))) {
return new $namespace($inject);
}
};
// Split module and model name
if(strstr($name, '/')) {
$name = explode('/', $name);
return $instance($name[0] . '/Models/' . $name[1]);
}
if(isset($this->module['name'])) {
if($model = $instance($this->module['name'] . '/Models/'. $name)) {
return $model;
}
}
// Use module name if model name is not defined
return $instance($name . '/Models/' . $name);
} | [
"public",
"function",
"model",
"(",
"$",
"name",
",",
"$",
"inject",
"=",
"null",
")",
"{",
"// Model instance",
"$",
"instance",
"=",
"function",
"(",
"$",
"path",
")",
"use",
"(",
"$",
"inject",
")",
"{",
"if",
"(",
"class_exists",
"(",
"$",
"namespace",
"=",
"'App\\\\Modules\\\\'",
".",
"str_replace",
"(",
"'/'",
",",
"'\\\\'",
",",
"$",
"path",
")",
")",
")",
"{",
"return",
"new",
"$",
"namespace",
"(",
"$",
"inject",
")",
";",
"}",
"}",
";",
"// Split module and model name",
"if",
"(",
"strstr",
"(",
"$",
"name",
",",
"'/'",
")",
")",
"{",
"$",
"name",
"=",
"explode",
"(",
"'/'",
",",
"$",
"name",
")",
";",
"return",
"$",
"instance",
"(",
"$",
"name",
"[",
"0",
"]",
".",
"'/Models/'",
".",
"$",
"name",
"[",
"1",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"module",
"[",
"'name'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"model",
"=",
"$",
"instance",
"(",
"$",
"this",
"->",
"module",
"[",
"'name'",
"]",
".",
"'/Models/'",
".",
"$",
"name",
")",
")",
"{",
"return",
"$",
"model",
";",
"}",
"}",
"// Use module name if model name is not defined",
"return",
"$",
"instance",
"(",
"$",
"name",
".",
"'/Models/'",
".",
"$",
"name",
")",
";",
"}"
] | Get model from it's module and other modules
@param string $name | [
"Get",
"model",
"from",
"it",
"s",
"module",
"and",
"other",
"modules"
] | train | https://github.com/Craftsware/scissor/blob/644e4a8ea9859fc30fee36705e54784acd8d43e2/src/Module.php#L181-L212 |
Craftsware/scissor | src/Module.php | Module.collection | private function collection($args = null) {
static $data = [];
if(isset($args[1])) {
if(preg_match('/(.*)\[(.*)\]/', $args[0], $matches)) {
$data[$matches[1]][$matches[2]] = $args[1];
} else {
$data[$args[0]] = $args[1];
return $args[1];
}
}
return $data;
} | php | private function collection($args = null) {
static $data = [];
if(isset($args[1])) {
if(preg_match('/(.*)\[(.*)\]/', $args[0], $matches)) {
$data[$matches[1]][$matches[2]] = $args[1];
} else {
$data[$args[0]] = $args[1];
return $args[1];
}
}
return $data;
} | [
"private",
"function",
"collection",
"(",
"$",
"args",
"=",
"null",
")",
"{",
"static",
"$",
"data",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"args",
"[",
"1",
"]",
")",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/(.*)\\[(.*)\\]/'",
",",
"$",
"args",
"[",
"0",
"]",
",",
"$",
"matches",
")",
")",
"{",
"$",
"data",
"[",
"$",
"matches",
"[",
"1",
"]",
"]",
"[",
"$",
"matches",
"[",
"2",
"]",
"]",
"=",
"$",
"args",
"[",
"1",
"]",
";",
"}",
"else",
"{",
"$",
"data",
"[",
"$",
"args",
"[",
"0",
"]",
"]",
"=",
"$",
"args",
"[",
"1",
"]",
";",
"return",
"$",
"args",
"[",
"1",
"]",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] | Collection
@param array $args
@return object $collection | [
"Collection"
] | train | https://github.com/Craftsware/scissor/blob/644e4a8ea9859fc30fee36705e54784acd8d43e2/src/Module.php#L224-L244 |
dandisy/laravel-generator | src/Commands/RollbackGeneratorCommand.php | RollbackGeneratorCommand.handle | public function handle()
{
if (!in_array($this->argument('type'), [
CommandData::$COMMAND_TYPE_API,
CommandData::$COMMAND_TYPE_SCAFFOLD,
CommandData::$COMMAND_TYPE_API_SCAFFOLD,
CommandData::$COMMAND_TYPE_VUEJS,
])) {
$this->error('invalid rollback type');
}
$this->commandData = new CommandData($this, $this->argument('type'));
$this->commandData->config->mName = $this->commandData->modelName = $this->argument('model');
$this->commandData->config->init($this->commandData, ['tableName', 'prefix']);
$migrationGenerator = new MigrationGenerator($this->commandData);
$migrationGenerator->rollback();
$modelGenerator = new ModelGenerator($this->commandData);
$modelGenerator->rollback();
$repositoryGenerator = new RepositoryGenerator($this->commandData);
$repositoryGenerator->rollback();
$requestGenerator = new APIRequestGenerator($this->commandData);
$requestGenerator->rollback();
$controllerGenerator = new APIControllerGenerator($this->commandData);
$controllerGenerator->rollback();
$routesGenerator = new APIRoutesGenerator($this->commandData);
$routesGenerator->rollback();
$requestGenerator = new RequestGenerator($this->commandData);
$requestGenerator->rollback();
$controllerGenerator = new ControllerGenerator($this->commandData);
$controllerGenerator->rollback();
$viewGenerator = new ViewGenerator($this->commandData);
$viewGenerator->rollback();
$routeGenerator = new RoutesGenerator($this->commandData);
$routeGenerator->rollback();
$controllerGenerator = new VueJsControllerGenerator($this->commandData);
$controllerGenerator->rollback();
$routesGenerator = new VueJsRoutesGenerator($this->commandData);
$routesGenerator->rollback();
$viewGenerator = new VueJsViewGenerator($this->commandData);
$viewGenerator->rollback();
$modelJsConfigGenerator = new ModelJsConfigGenerator($this->commandData);
$modelJsConfigGenerator->rollback();
if ($this->commandData->getAddOn('tests')) {
$repositoryTestGenerator = new RepositoryTestGenerator($this->commandData);
$repositoryTestGenerator->rollback();
$testTraitGenerator = new TestTraitGenerator($this->commandData);
$testTraitGenerator->rollback();
$apiTestGenerator = new APITestGenerator($this->commandData);
$apiTestGenerator->rollback();
}
if ($this->commandData->config->getAddOn('menu.enabled')) {
$menuGenerator = new MenuGenerator($this->commandData);
$menuGenerator->rollback();
}
$this->info('Generating autoload files');
$this->composer->dumpOptimized();
} | php | public function handle()
{
if (!in_array($this->argument('type'), [
CommandData::$COMMAND_TYPE_API,
CommandData::$COMMAND_TYPE_SCAFFOLD,
CommandData::$COMMAND_TYPE_API_SCAFFOLD,
CommandData::$COMMAND_TYPE_VUEJS,
])) {
$this->error('invalid rollback type');
}
$this->commandData = new CommandData($this, $this->argument('type'));
$this->commandData->config->mName = $this->commandData->modelName = $this->argument('model');
$this->commandData->config->init($this->commandData, ['tableName', 'prefix']);
$migrationGenerator = new MigrationGenerator($this->commandData);
$migrationGenerator->rollback();
$modelGenerator = new ModelGenerator($this->commandData);
$modelGenerator->rollback();
$repositoryGenerator = new RepositoryGenerator($this->commandData);
$repositoryGenerator->rollback();
$requestGenerator = new APIRequestGenerator($this->commandData);
$requestGenerator->rollback();
$controllerGenerator = new APIControllerGenerator($this->commandData);
$controllerGenerator->rollback();
$routesGenerator = new APIRoutesGenerator($this->commandData);
$routesGenerator->rollback();
$requestGenerator = new RequestGenerator($this->commandData);
$requestGenerator->rollback();
$controllerGenerator = new ControllerGenerator($this->commandData);
$controllerGenerator->rollback();
$viewGenerator = new ViewGenerator($this->commandData);
$viewGenerator->rollback();
$routeGenerator = new RoutesGenerator($this->commandData);
$routeGenerator->rollback();
$controllerGenerator = new VueJsControllerGenerator($this->commandData);
$controllerGenerator->rollback();
$routesGenerator = new VueJsRoutesGenerator($this->commandData);
$routesGenerator->rollback();
$viewGenerator = new VueJsViewGenerator($this->commandData);
$viewGenerator->rollback();
$modelJsConfigGenerator = new ModelJsConfigGenerator($this->commandData);
$modelJsConfigGenerator->rollback();
if ($this->commandData->getAddOn('tests')) {
$repositoryTestGenerator = new RepositoryTestGenerator($this->commandData);
$repositoryTestGenerator->rollback();
$testTraitGenerator = new TestTraitGenerator($this->commandData);
$testTraitGenerator->rollback();
$apiTestGenerator = new APITestGenerator($this->commandData);
$apiTestGenerator->rollback();
}
if ($this->commandData->config->getAddOn('menu.enabled')) {
$menuGenerator = new MenuGenerator($this->commandData);
$menuGenerator->rollback();
}
$this->info('Generating autoload files');
$this->composer->dumpOptimized();
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"this",
"->",
"argument",
"(",
"'type'",
")",
",",
"[",
"CommandData",
"::",
"$",
"COMMAND_TYPE_API",
",",
"CommandData",
"::",
"$",
"COMMAND_TYPE_SCAFFOLD",
",",
"CommandData",
"::",
"$",
"COMMAND_TYPE_API_SCAFFOLD",
",",
"CommandData",
"::",
"$",
"COMMAND_TYPE_VUEJS",
",",
"]",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"'invalid rollback type'",
")",
";",
"}",
"$",
"this",
"->",
"commandData",
"=",
"new",
"CommandData",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"argument",
"(",
"'type'",
")",
")",
";",
"$",
"this",
"->",
"commandData",
"->",
"config",
"->",
"mName",
"=",
"$",
"this",
"->",
"commandData",
"->",
"modelName",
"=",
"$",
"this",
"->",
"argument",
"(",
"'model'",
")",
";",
"$",
"this",
"->",
"commandData",
"->",
"config",
"->",
"init",
"(",
"$",
"this",
"->",
"commandData",
",",
"[",
"'tableName'",
",",
"'prefix'",
"]",
")",
";",
"$",
"migrationGenerator",
"=",
"new",
"MigrationGenerator",
"(",
"$",
"this",
"->",
"commandData",
")",
";",
"$",
"migrationGenerator",
"->",
"rollback",
"(",
")",
";",
"$",
"modelGenerator",
"=",
"new",
"ModelGenerator",
"(",
"$",
"this",
"->",
"commandData",
")",
";",
"$",
"modelGenerator",
"->",
"rollback",
"(",
")",
";",
"$",
"repositoryGenerator",
"=",
"new",
"RepositoryGenerator",
"(",
"$",
"this",
"->",
"commandData",
")",
";",
"$",
"repositoryGenerator",
"->",
"rollback",
"(",
")",
";",
"$",
"requestGenerator",
"=",
"new",
"APIRequestGenerator",
"(",
"$",
"this",
"->",
"commandData",
")",
";",
"$",
"requestGenerator",
"->",
"rollback",
"(",
")",
";",
"$",
"controllerGenerator",
"=",
"new",
"APIControllerGenerator",
"(",
"$",
"this",
"->",
"commandData",
")",
";",
"$",
"controllerGenerator",
"->",
"rollback",
"(",
")",
";",
"$",
"routesGenerator",
"=",
"new",
"APIRoutesGenerator",
"(",
"$",
"this",
"->",
"commandData",
")",
";",
"$",
"routesGenerator",
"->",
"rollback",
"(",
")",
";",
"$",
"requestGenerator",
"=",
"new",
"RequestGenerator",
"(",
"$",
"this",
"->",
"commandData",
")",
";",
"$",
"requestGenerator",
"->",
"rollback",
"(",
")",
";",
"$",
"controllerGenerator",
"=",
"new",
"ControllerGenerator",
"(",
"$",
"this",
"->",
"commandData",
")",
";",
"$",
"controllerGenerator",
"->",
"rollback",
"(",
")",
";",
"$",
"viewGenerator",
"=",
"new",
"ViewGenerator",
"(",
"$",
"this",
"->",
"commandData",
")",
";",
"$",
"viewGenerator",
"->",
"rollback",
"(",
")",
";",
"$",
"routeGenerator",
"=",
"new",
"RoutesGenerator",
"(",
"$",
"this",
"->",
"commandData",
")",
";",
"$",
"routeGenerator",
"->",
"rollback",
"(",
")",
";",
"$",
"controllerGenerator",
"=",
"new",
"VueJsControllerGenerator",
"(",
"$",
"this",
"->",
"commandData",
")",
";",
"$",
"controllerGenerator",
"->",
"rollback",
"(",
")",
";",
"$",
"routesGenerator",
"=",
"new",
"VueJsRoutesGenerator",
"(",
"$",
"this",
"->",
"commandData",
")",
";",
"$",
"routesGenerator",
"->",
"rollback",
"(",
")",
";",
"$",
"viewGenerator",
"=",
"new",
"VueJsViewGenerator",
"(",
"$",
"this",
"->",
"commandData",
")",
";",
"$",
"viewGenerator",
"->",
"rollback",
"(",
")",
";",
"$",
"modelJsConfigGenerator",
"=",
"new",
"ModelJsConfigGenerator",
"(",
"$",
"this",
"->",
"commandData",
")",
";",
"$",
"modelJsConfigGenerator",
"->",
"rollback",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"commandData",
"->",
"getAddOn",
"(",
"'tests'",
")",
")",
"{",
"$",
"repositoryTestGenerator",
"=",
"new",
"RepositoryTestGenerator",
"(",
"$",
"this",
"->",
"commandData",
")",
";",
"$",
"repositoryTestGenerator",
"->",
"rollback",
"(",
")",
";",
"$",
"testTraitGenerator",
"=",
"new",
"TestTraitGenerator",
"(",
"$",
"this",
"->",
"commandData",
")",
";",
"$",
"testTraitGenerator",
"->",
"rollback",
"(",
")",
";",
"$",
"apiTestGenerator",
"=",
"new",
"APITestGenerator",
"(",
"$",
"this",
"->",
"commandData",
")",
";",
"$",
"apiTestGenerator",
"->",
"rollback",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"commandData",
"->",
"config",
"->",
"getAddOn",
"(",
"'menu.enabled'",
")",
")",
"{",
"$",
"menuGenerator",
"=",
"new",
"MenuGenerator",
"(",
"$",
"this",
"->",
"commandData",
")",
";",
"$",
"menuGenerator",
"->",
"rollback",
"(",
")",
";",
"}",
"$",
"this",
"->",
"info",
"(",
"'Generating autoload files'",
")",
";",
"$",
"this",
"->",
"composer",
"->",
"dumpOptimized",
"(",
")",
";",
"}"
] | Execute the command.
@return void | [
"Execute",
"the",
"command",
"."
] | train | https://github.com/dandisy/laravel-generator/blob/742797c8483bc88b54b6302a516a9a85eeb8579b/src/Commands/RollbackGeneratorCommand.php#L69-L145 |
LUSHDigital/microservice-model-utils | src/Traits/MicroServiceCacheTrait.php | MicroServiceCacheTrait.getModelCacheKeys | public function getModelCacheKeys(Cacheable $model)
{
// Build list of cache keys we need to clear.
$cacheKeys = [
implode(':', [$model->getTable(), 'index']),
];
// If the model has an primary key add the cache key.
if (!empty($model->getPrimaryKeyValue())) {
$cacheKeys[] = implode(':', [$model->getTable(), $model->getPrimaryKeyValue()]);
}
// Add the cache keys for the model attributes.
$this->addAttributeCacheKeys($cacheKeys, $model);
return $cacheKeys;
} | php | public function getModelCacheKeys(Cacheable $model)
{
// Build list of cache keys we need to clear.
$cacheKeys = [
implode(':', [$model->getTable(), 'index']),
];
// If the model has an primary key add the cache key.
if (!empty($model->getPrimaryKeyValue())) {
$cacheKeys[] = implode(':', [$model->getTable(), $model->getPrimaryKeyValue()]);
}
// Add the cache keys for the model attributes.
$this->addAttributeCacheKeys($cacheKeys, $model);
return $cacheKeys;
} | [
"public",
"function",
"getModelCacheKeys",
"(",
"Cacheable",
"$",
"model",
")",
"{",
"// Build list of cache keys we need to clear.",
"$",
"cacheKeys",
"=",
"[",
"implode",
"(",
"':'",
",",
"[",
"$",
"model",
"->",
"getTable",
"(",
")",
",",
"'index'",
"]",
")",
",",
"]",
";",
"// If the model has an primary key add the cache key.",
"if",
"(",
"!",
"empty",
"(",
"$",
"model",
"->",
"getPrimaryKeyValue",
"(",
")",
")",
")",
"{",
"$",
"cacheKeys",
"[",
"]",
"=",
"implode",
"(",
"':'",
",",
"[",
"$",
"model",
"->",
"getTable",
"(",
")",
",",
"$",
"model",
"->",
"getPrimaryKeyValue",
"(",
")",
"]",
")",
";",
"}",
"// Add the cache keys for the model attributes.",
"$",
"this",
"->",
"addAttributeCacheKeys",
"(",
"$",
"cacheKeys",
",",
"$",
"model",
")",
";",
"return",
"$",
"cacheKeys",
";",
"}"
] | Get an array of possible cache keys for the given model.
@param Cacheable $model
@return array|bool | [
"Get",
"an",
"array",
"of",
"possible",
"cache",
"keys",
"for",
"the",
"given",
"model",
"."
] | train | https://github.com/LUSHDigital/microservice-model-utils/blob/37a6e3b5f326ab120bb31262fa596e6e3cc20832/src/Traits/MicroServiceCacheTrait.php#L27-L43 |
LUSHDigital/microservice-model-utils | src/Traits/MicroServiceCacheTrait.php | MicroServiceCacheTrait.cacheForget | public function cacheForget(Cacheable $model)
{
// Clear the cache for each key.
foreach ($this->getModelCacheKeys($model) as $cacheKey) {
Cache::forget($cacheKey);
}
return true;
} | php | public function cacheForget(Cacheable $model)
{
// Clear the cache for each key.
foreach ($this->getModelCacheKeys($model) as $cacheKey) {
Cache::forget($cacheKey);
}
return true;
} | [
"public",
"function",
"cacheForget",
"(",
"Cacheable",
"$",
"model",
")",
"{",
"// Clear the cache for each key.",
"foreach",
"(",
"$",
"this",
"->",
"getModelCacheKeys",
"(",
"$",
"model",
")",
"as",
"$",
"cacheKey",
")",
"{",
"Cache",
"::",
"forget",
"(",
"$",
"cacheKey",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Attempt to forget items from the cache for a given model.
@param Cacheable $model
@return bool | [
"Attempt",
"to",
"forget",
"items",
"from",
"the",
"cache",
"for",
"a",
"given",
"model",
"."
] | train | https://github.com/LUSHDigital/microservice-model-utils/blob/37a6e3b5f326ab120bb31262fa596e6e3cc20832/src/Traits/MicroServiceCacheTrait.php#L51-L59 |
LUSHDigital/microservice-model-utils | src/Traits/MicroServiceCacheTrait.php | MicroServiceCacheTrait.addAttributeCacheKeys | protected function addAttributeCacheKeys(array &$cacheKeys, Cacheable $model)
{
// Add a cache key for each attribute marked as a cache key.
foreach ($model->getAttributeCacheKeys() as $attributeCacheKey) {
$origAttributeValue = $this->getOriginalCacheKeyValue($model, $attributeCacheKey);
$attributesValues = [];
if ($origAttributeValue != null) {
array_push($attributesValues, $origAttributeValue);
}
array_push($attributesValues, $model->{$attributeCacheKey});
foreach ($attributesValues as $attributeValue) {
// If the attribute is a collection check each item value.
if ($attributeValue instanceof Collection) {
$this->getCollectionAttributeCacheKeys($cacheKeys, $model, $attributeCacheKey, $attributeValue);
} elseif (is_scalar($attributeValue)) {
// Otherwise just get the value.
$cacheKeys[] = implode(':', [$model->getTable(), $attributeCacheKey, $attributeValue]);
}
}
}
} | php | protected function addAttributeCacheKeys(array &$cacheKeys, Cacheable $model)
{
// Add a cache key for each attribute marked as a cache key.
foreach ($model->getAttributeCacheKeys() as $attributeCacheKey) {
$origAttributeValue = $this->getOriginalCacheKeyValue($model, $attributeCacheKey);
$attributesValues = [];
if ($origAttributeValue != null) {
array_push($attributesValues, $origAttributeValue);
}
array_push($attributesValues, $model->{$attributeCacheKey});
foreach ($attributesValues as $attributeValue) {
// If the attribute is a collection check each item value.
if ($attributeValue instanceof Collection) {
$this->getCollectionAttributeCacheKeys($cacheKeys, $model, $attributeCacheKey, $attributeValue);
} elseif (is_scalar($attributeValue)) {
// Otherwise just get the value.
$cacheKeys[] = implode(':', [$model->getTable(), $attributeCacheKey, $attributeValue]);
}
}
}
} | [
"protected",
"function",
"addAttributeCacheKeys",
"(",
"array",
"&",
"$",
"cacheKeys",
",",
"Cacheable",
"$",
"model",
")",
"{",
"// Add a cache key for each attribute marked as a cache key.",
"foreach",
"(",
"$",
"model",
"->",
"getAttributeCacheKeys",
"(",
")",
"as",
"$",
"attributeCacheKey",
")",
"{",
"$",
"origAttributeValue",
"=",
"$",
"this",
"->",
"getOriginalCacheKeyValue",
"(",
"$",
"model",
",",
"$",
"attributeCacheKey",
")",
";",
"$",
"attributesValues",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"origAttributeValue",
"!=",
"null",
")",
"{",
"array_push",
"(",
"$",
"attributesValues",
",",
"$",
"origAttributeValue",
")",
";",
"}",
"array_push",
"(",
"$",
"attributesValues",
",",
"$",
"model",
"->",
"{",
"$",
"attributeCacheKey",
"}",
")",
";",
"foreach",
"(",
"$",
"attributesValues",
"as",
"$",
"attributeValue",
")",
"{",
"// If the attribute is a collection check each item value.",
"if",
"(",
"$",
"attributeValue",
"instanceof",
"Collection",
")",
"{",
"$",
"this",
"->",
"getCollectionAttributeCacheKeys",
"(",
"$",
"cacheKeys",
",",
"$",
"model",
",",
"$",
"attributeCacheKey",
",",
"$",
"attributeValue",
")",
";",
"}",
"elseif",
"(",
"is_scalar",
"(",
"$",
"attributeValue",
")",
")",
"{",
"// Otherwise just get the value.",
"$",
"cacheKeys",
"[",
"]",
"=",
"implode",
"(",
"':'",
",",
"[",
"$",
"model",
"->",
"getTable",
"(",
")",
",",
"$",
"attributeCacheKey",
",",
"$",
"attributeValue",
"]",
")",
";",
"}",
"}",
"}",
"}"
] | Add cache keys for each attribute of a given model.
@param array $cacheKeys
@param Cacheable $model | [
"Add",
"cache",
"keys",
"for",
"each",
"attribute",
"of",
"a",
"given",
"model",
"."
] | train | https://github.com/LUSHDigital/microservice-model-utils/blob/37a6e3b5f326ab120bb31262fa596e6e3cc20832/src/Traits/MicroServiceCacheTrait.php#L67-L90 |
LUSHDigital/microservice-model-utils | src/Traits/MicroServiceCacheTrait.php | MicroServiceCacheTrait.getCollectionAttributeCacheKeys | protected function getCollectionAttributeCacheKeys(array &$cacheKeys, Cacheable $model, $attribute, $collection)
{
foreach ($collection as $item) {
if (isset($item->id)) {
$cacheKeys[] = implode(':', [$model->getTable(), $attribute, $item->id]);
}
}
} | php | protected function getCollectionAttributeCacheKeys(array &$cacheKeys, Cacheable $model, $attribute, $collection)
{
foreach ($collection as $item) {
if (isset($item->id)) {
$cacheKeys[] = implode(':', [$model->getTable(), $attribute, $item->id]);
}
}
} | [
"protected",
"function",
"getCollectionAttributeCacheKeys",
"(",
"array",
"&",
"$",
"cacheKeys",
",",
"Cacheable",
"$",
"model",
",",
"$",
"attribute",
",",
"$",
"collection",
")",
"{",
"foreach",
"(",
"$",
"collection",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"item",
"->",
"id",
")",
")",
"{",
"$",
"cacheKeys",
"[",
"]",
"=",
"implode",
"(",
"':'",
",",
"[",
"$",
"model",
"->",
"getTable",
"(",
")",
",",
"$",
"attribute",
",",
"$",
"item",
"->",
"id",
"]",
")",
";",
"}",
"}",
"}"
] | Get the attribute cache keys from a collection attribute.
@param array $cacheKeys
@param Cacheable $model
@param $attribute
@param $collection | [
"Get",
"the",
"attribute",
"cache",
"keys",
"from",
"a",
"collection",
"attribute",
"."
] | train | https://github.com/LUSHDigital/microservice-model-utils/blob/37a6e3b5f326ab120bb31262fa596e6e3cc20832/src/Traits/MicroServiceCacheTrait.php#L100-L107 |
LUSHDigital/microservice-model-utils | src/Traits/MicroServiceCacheTrait.php | MicroServiceCacheTrait.getOriginalCacheKeyValue | protected function getOriginalCacheKeyValue(Cacheable $model, $attributeCacheKey)
{
// Bail out if the model is not an eloquent model.
if (!$model instanceof Model) {
return null;
}
return empty($model->getOriginal($attributeCacheKey)) ? null : $model->getOriginal($attributeCacheKey);
} | php | protected function getOriginalCacheKeyValue(Cacheable $model, $attributeCacheKey)
{
// Bail out if the model is not an eloquent model.
if (!$model instanceof Model) {
return null;
}
return empty($model->getOriginal($attributeCacheKey)) ? null : $model->getOriginal($attributeCacheKey);
} | [
"protected",
"function",
"getOriginalCacheKeyValue",
"(",
"Cacheable",
"$",
"model",
",",
"$",
"attributeCacheKey",
")",
"{",
"// Bail out if the model is not an eloquent model.",
"if",
"(",
"!",
"$",
"model",
"instanceof",
"Model",
")",
"{",
"return",
"null",
";",
"}",
"return",
"empty",
"(",
"$",
"model",
"->",
"getOriginal",
"(",
"$",
"attributeCacheKey",
")",
")",
"?",
"null",
":",
"$",
"model",
"->",
"getOriginal",
"(",
"$",
"attributeCacheKey",
")",
";",
"}"
] | Get original cache key value.
@param Cacheable $model
@param $attributeCacheKey
@return mixed|null | [
"Get",
"original",
"cache",
"key",
"value",
"."
] | train | https://github.com/LUSHDigital/microservice-model-utils/blob/37a6e3b5f326ab120bb31262fa596e6e3cc20832/src/Traits/MicroServiceCacheTrait.php#L116-L124 |
AydinHassan/cli-md-renderer | src/InlineRenderer/LinkRenderer.php | LinkRenderer.render | public function render(AbstractInline $inline, CliRenderer $renderer)
{
if (!($inline instanceof Link)) {
throw new \InvalidArgumentException(sprintf('Incompatible inline type: "%s"', get_class($inline)));
}
return $renderer->style($renderer->renderInlines($inline->children()), ['underline', 'bold', 'light_blue']);
} | php | public function render(AbstractInline $inline, CliRenderer $renderer)
{
if (!($inline instanceof Link)) {
throw new \InvalidArgumentException(sprintf('Incompatible inline type: "%s"', get_class($inline)));
}
return $renderer->style($renderer->renderInlines($inline->children()), ['underline', 'bold', 'light_blue']);
} | [
"public",
"function",
"render",
"(",
"AbstractInline",
"$",
"inline",
",",
"CliRenderer",
"$",
"renderer",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"inline",
"instanceof",
"Link",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Incompatible inline type: \"%s\"'",
",",
"get_class",
"(",
"$",
"inline",
")",
")",
")",
";",
"}",
"return",
"$",
"renderer",
"->",
"style",
"(",
"$",
"renderer",
"->",
"renderInlines",
"(",
"$",
"inline",
"->",
"children",
"(",
")",
")",
",",
"[",
"'underline'",
",",
"'bold'",
",",
"'light_blue'",
"]",
")",
";",
"}"
] | @param AbstractInline $inline
@param CliRenderer $renderer
@return string | [
"@param",
"AbstractInline",
"$inline",
"@param",
"CliRenderer",
"$renderer"
] | train | https://github.com/AydinHassan/cli-md-renderer/blob/521f9ace2aeadd58bf8a3910704be8360f5bd7b2/src/InlineRenderer/LinkRenderer.php#L23-L30 |
dms-org/package.blog | src/Infrastructure/Persistence/BlogCategoryMapper.php | BlogCategoryMapper.define | protected function define(MapperDefinition $map)
{
$map->type(BlogCategory::class);
$map->toTable('categories');
$map->idToPrimaryKey('id');
$map->property(BlogCategory::NAME)->to('name')->asVarchar(255);
$map->property(BlogCategory::SLUG)->to('slug')->unique()->asVarchar(255);
$map->property(BlogCategory::PUBLISHED)->to('published')->asBool();
$map->embedded(BlogCategory::CREATED_AT)->using(new DateTimeMapper('created_at'));
$map->embedded(BlogCategory::UPDATED_AT)->using(new DateTimeMapper('updated_at'));
$map->relation(BlogCategory::ARTICLES)
->to(BlogArticle::class)
->toMany()
->withBidirectionalRelation(BlogArticle::AUTHOR)
->withParentIdAs($map->getOrm()->getNamespace() . 'category_id');
MetadataMapper::mapMetadataToJsonColumn($map, 'metadata');
} | php | protected function define(MapperDefinition $map)
{
$map->type(BlogCategory::class);
$map->toTable('categories');
$map->idToPrimaryKey('id');
$map->property(BlogCategory::NAME)->to('name')->asVarchar(255);
$map->property(BlogCategory::SLUG)->to('slug')->unique()->asVarchar(255);
$map->property(BlogCategory::PUBLISHED)->to('published')->asBool();
$map->embedded(BlogCategory::CREATED_AT)->using(new DateTimeMapper('created_at'));
$map->embedded(BlogCategory::UPDATED_AT)->using(new DateTimeMapper('updated_at'));
$map->relation(BlogCategory::ARTICLES)
->to(BlogArticle::class)
->toMany()
->withBidirectionalRelation(BlogArticle::AUTHOR)
->withParentIdAs($map->getOrm()->getNamespace() . 'category_id');
MetadataMapper::mapMetadataToJsonColumn($map, 'metadata');
} | [
"protected",
"function",
"define",
"(",
"MapperDefinition",
"$",
"map",
")",
"{",
"$",
"map",
"->",
"type",
"(",
"BlogCategory",
"::",
"class",
")",
";",
"$",
"map",
"->",
"toTable",
"(",
"'categories'",
")",
";",
"$",
"map",
"->",
"idToPrimaryKey",
"(",
"'id'",
")",
";",
"$",
"map",
"->",
"property",
"(",
"BlogCategory",
"::",
"NAME",
")",
"->",
"to",
"(",
"'name'",
")",
"->",
"asVarchar",
"(",
"255",
")",
";",
"$",
"map",
"->",
"property",
"(",
"BlogCategory",
"::",
"SLUG",
")",
"->",
"to",
"(",
"'slug'",
")",
"->",
"unique",
"(",
")",
"->",
"asVarchar",
"(",
"255",
")",
";",
"$",
"map",
"->",
"property",
"(",
"BlogCategory",
"::",
"PUBLISHED",
")",
"->",
"to",
"(",
"'published'",
")",
"->",
"asBool",
"(",
")",
";",
"$",
"map",
"->",
"embedded",
"(",
"BlogCategory",
"::",
"CREATED_AT",
")",
"->",
"using",
"(",
"new",
"DateTimeMapper",
"(",
"'created_at'",
")",
")",
";",
"$",
"map",
"->",
"embedded",
"(",
"BlogCategory",
"::",
"UPDATED_AT",
")",
"->",
"using",
"(",
"new",
"DateTimeMapper",
"(",
"'updated_at'",
")",
")",
";",
"$",
"map",
"->",
"relation",
"(",
"BlogCategory",
"::",
"ARTICLES",
")",
"->",
"to",
"(",
"BlogArticle",
"::",
"class",
")",
"->",
"toMany",
"(",
")",
"->",
"withBidirectionalRelation",
"(",
"BlogArticle",
"::",
"AUTHOR",
")",
"->",
"withParentIdAs",
"(",
"$",
"map",
"->",
"getOrm",
"(",
")",
"->",
"getNamespace",
"(",
")",
".",
"'category_id'",
")",
";",
"MetadataMapper",
"::",
"mapMetadataToJsonColumn",
"(",
"$",
"map",
",",
"'metadata'",
")",
";",
"}"
] | Defines the entity mapper
@param MapperDefinition $map
@return void | [
"Defines",
"the",
"entity",
"mapper"
] | train | https://github.com/dms-org/package.blog/blob/1500f6fad20d81289a0dfa617fc1c54699f01e16/src/Infrastructure/Persistence/BlogCategoryMapper.php#L24-L49 |
gibilogic/crud-bundle | Entity/EntityService.php | EntityService.getName | public function getName()
{
$fqdnClassName = get_class($this);
$className = substr($fqdnClassName, strrpos($fqdnClassName, '\\') + 1);
return str_replace("Service", "", $className);
} | php | public function getName()
{
$fqdnClassName = get_class($this);
$className = substr($fqdnClassName, strrpos($fqdnClassName, '\\') + 1);
return str_replace("Service", "", $className);
} | [
"public",
"function",
"getName",
"(",
")",
"{",
"$",
"fqdnClassName",
"=",
"get_class",
"(",
"$",
"this",
")",
";",
"$",
"className",
"=",
"substr",
"(",
"$",
"fqdnClassName",
",",
"strrpos",
"(",
"$",
"fqdnClassName",
",",
"'\\\\'",
")",
"+",
"1",
")",
";",
"return",
"str_replace",
"(",
"\"Service\"",
",",
"\"\"",
",",
"$",
"className",
")",
";",
"}"
] | Returns base entity name
@return string | [
"Returns",
"base",
"entity",
"name"
] | train | https://github.com/gibilogic/crud-bundle/blob/847e7c7bee4016026411eb230154f24986335633/Entity/EntityService.php#L58-L63 |
gibilogic/crud-bundle | Entity/EntityService.php | EntityService.findEntities | public function findEntities(Request $request, $filters = array(), $addPagination = false)
{
$options = $this->getOptions($request, $filters, $addPagination);
if (!$addPagination) {
return array(
'entities' => $this->getRepository()->getEntities($options),
'options' => $options
);
}
$entities = $this->getRepository()->getPaginatedEntities($options);
$options['elements'] = $entities->count();
$options['pages'] = (int)ceil($options['elements'] / $options['elementsPerPage']);
return array(
'entities' => $entities,
'options' => $options
);
} | php | public function findEntities(Request $request, $filters = array(), $addPagination = false)
{
$options = $this->getOptions($request, $filters, $addPagination);
if (!$addPagination) {
return array(
'entities' => $this->getRepository()->getEntities($options),
'options' => $options
);
}
$entities = $this->getRepository()->getPaginatedEntities($options);
$options['elements'] = $entities->count();
$options['pages'] = (int)ceil($options['elements'] / $options['elementsPerPage']);
return array(
'entities' => $entities,
'options' => $options
);
} | [
"public",
"function",
"findEntities",
"(",
"Request",
"$",
"request",
",",
"$",
"filters",
"=",
"array",
"(",
")",
",",
"$",
"addPagination",
"=",
"false",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"getOptions",
"(",
"$",
"request",
",",
"$",
"filters",
",",
"$",
"addPagination",
")",
";",
"if",
"(",
"!",
"$",
"addPagination",
")",
"{",
"return",
"array",
"(",
"'entities'",
"=>",
"$",
"this",
"->",
"getRepository",
"(",
")",
"->",
"getEntities",
"(",
"$",
"options",
")",
",",
"'options'",
"=>",
"$",
"options",
")",
";",
"}",
"$",
"entities",
"=",
"$",
"this",
"->",
"getRepository",
"(",
")",
"->",
"getPaginatedEntities",
"(",
"$",
"options",
")",
";",
"$",
"options",
"[",
"'elements'",
"]",
"=",
"$",
"entities",
"->",
"count",
"(",
")",
";",
"$",
"options",
"[",
"'pages'",
"]",
"=",
"(",
"int",
")",
"ceil",
"(",
"$",
"options",
"[",
"'elements'",
"]",
"/",
"$",
"options",
"[",
"'elementsPerPage'",
"]",
")",
";",
"return",
"array",
"(",
"'entities'",
"=>",
"$",
"entities",
",",
"'options'",
"=>",
"$",
"options",
")",
";",
"}"
] | Returns a list of entities.
@param \Symfony\Component\HttpFoundation\Request $request
@param array $filters
@param bool $addPagination
@return array | [
"Returns",
"a",
"list",
"of",
"entities",
"."
] | train | https://github.com/gibilogic/crud-bundle/blob/847e7c7bee4016026411eb230154f24986335633/Entity/EntityService.php#L115-L133 |
gibilogic/crud-bundle | Entity/EntityService.php | EntityService.findUnhydratedEntities | public function findUnhydratedEntities(Request $request, $filters = array(), $addPagination = false)
{
$options = $this->getOptions($request, $filters, $addPagination, true);
if (!$addPagination) {
return array(
'entities' => $this->getRepository()->getEntities($options, AbstractQuery::HYDRATE_ARRAY),
'options' => $options
);
}
$entities = $this->getRepository()->getPaginatedEntities($options, AbstractQuery::HYDRATE_ARRAY);
$options['elements'] = $entities->count();
$options['pages'] = (int)ceil($options['elements'] / $options['elementsPerPage']);
return array(
'entities' => (array)$entities->getIterator(),
'options' => $options
);
} | php | public function findUnhydratedEntities(Request $request, $filters = array(), $addPagination = false)
{
$options = $this->getOptions($request, $filters, $addPagination, true);
if (!$addPagination) {
return array(
'entities' => $this->getRepository()->getEntities($options, AbstractQuery::HYDRATE_ARRAY),
'options' => $options
);
}
$entities = $this->getRepository()->getPaginatedEntities($options, AbstractQuery::HYDRATE_ARRAY);
$options['elements'] = $entities->count();
$options['pages'] = (int)ceil($options['elements'] / $options['elementsPerPage']);
return array(
'entities' => (array)$entities->getIterator(),
'options' => $options
);
} | [
"public",
"function",
"findUnhydratedEntities",
"(",
"Request",
"$",
"request",
",",
"$",
"filters",
"=",
"array",
"(",
")",
",",
"$",
"addPagination",
"=",
"false",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"getOptions",
"(",
"$",
"request",
",",
"$",
"filters",
",",
"$",
"addPagination",
",",
"true",
")",
";",
"if",
"(",
"!",
"$",
"addPagination",
")",
"{",
"return",
"array",
"(",
"'entities'",
"=>",
"$",
"this",
"->",
"getRepository",
"(",
")",
"->",
"getEntities",
"(",
"$",
"options",
",",
"AbstractQuery",
"::",
"HYDRATE_ARRAY",
")",
",",
"'options'",
"=>",
"$",
"options",
")",
";",
"}",
"$",
"entities",
"=",
"$",
"this",
"->",
"getRepository",
"(",
")",
"->",
"getPaginatedEntities",
"(",
"$",
"options",
",",
"AbstractQuery",
"::",
"HYDRATE_ARRAY",
")",
";",
"$",
"options",
"[",
"'elements'",
"]",
"=",
"$",
"entities",
"->",
"count",
"(",
")",
";",
"$",
"options",
"[",
"'pages'",
"]",
"=",
"(",
"int",
")",
"ceil",
"(",
"$",
"options",
"[",
"'elements'",
"]",
"/",
"$",
"options",
"[",
"'elementsPerPage'",
"]",
")",
";",
"return",
"array",
"(",
"'entities'",
"=>",
"(",
"array",
")",
"$",
"entities",
"->",
"getIterator",
"(",
")",
",",
"'options'",
"=>",
"$",
"options",
")",
";",
"}"
] | Returns an unhydrated (ie. as associative array) list of entities.
@param \Symfony\Component\HttpFoundation\Request $request
@param array $filters
@param bool $addPagination
@return array | [
"Returns",
"an",
"unhydrated",
"(",
"ie",
".",
"as",
"associative",
"array",
")",
"list",
"of",
"entities",
"."
] | train | https://github.com/gibilogic/crud-bundle/blob/847e7c7bee4016026411eb230154f24986335633/Entity/EntityService.php#L143-L161 |
gibilogic/crud-bundle | Entity/EntityService.php | EntityService.saveEntity | public function saveEntity($entity)
{
if (!$this->entityManager->contains($entity)) {
$this->entityManager->persist($entity);
}
$this->entityManager->flush();
return true;
} | php | public function saveEntity($entity)
{
if (!$this->entityManager->contains($entity)) {
$this->entityManager->persist($entity);
}
$this->entityManager->flush();
return true;
} | [
"public",
"function",
"saveEntity",
"(",
"$",
"entity",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"entityManager",
"->",
"contains",
"(",
"$",
"entity",
")",
")",
"{",
"$",
"this",
"->",
"entityManager",
"->",
"persist",
"(",
"$",
"entity",
")",
";",
"}",
"$",
"this",
"->",
"entityManager",
"->",
"flush",
"(",
")",
";",
"return",
"true",
";",
"}"
] | Saves the entity.
@param object $entity
@return bool | [
"Saves",
"the",
"entity",
"."
] | train | https://github.com/gibilogic/crud-bundle/blob/847e7c7bee4016026411eb230154f24986335633/Entity/EntityService.php#L169-L177 |
gibilogic/crud-bundle | Entity/EntityService.php | EntityService.removeEntity | public function removeEntity($entity)
{
$this->entityManager->remove($entity);
$this->entityManager->flush();
return true;
} | php | public function removeEntity($entity)
{
$this->entityManager->remove($entity);
$this->entityManager->flush();
return true;
} | [
"public",
"function",
"removeEntity",
"(",
"$",
"entity",
")",
"{",
"$",
"this",
"->",
"entityManager",
"->",
"remove",
"(",
"$",
"entity",
")",
";",
"$",
"this",
"->",
"entityManager",
"->",
"flush",
"(",
")",
";",
"return",
"true",
";",
"}"
] | Removes the entity.
@param object $entity
@return bool | [
"Removes",
"the",
"entity",
"."
] | train | https://github.com/gibilogic/crud-bundle/blob/847e7c7bee4016026411eb230154f24986335633/Entity/EntityService.php#L185-L190 |
gibilogic/crud-bundle | Entity/EntityService.php | EntityService.removeEntities | public function removeEntities(array $ids)
{
foreach ($this->getRepository()->getEntitiesById($ids) as $entity) {
$this->entityManager->remove($entity);
}
$this->entityManager->flush();
return true;
} | php | public function removeEntities(array $ids)
{
foreach ($this->getRepository()->getEntitiesById($ids) as $entity) {
$this->entityManager->remove($entity);
}
$this->entityManager->flush();
return true;
} | [
"public",
"function",
"removeEntities",
"(",
"array",
"$",
"ids",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getRepository",
"(",
")",
"->",
"getEntitiesById",
"(",
"$",
"ids",
")",
"as",
"$",
"entity",
")",
"{",
"$",
"this",
"->",
"entityManager",
"->",
"remove",
"(",
"$",
"entity",
")",
";",
"}",
"$",
"this",
"->",
"entityManager",
"->",
"flush",
"(",
")",
";",
"return",
"true",
";",
"}"
] | Removes a list of entities.
@param array $ids
@return bool | [
"Removes",
"a",
"list",
"of",
"entities",
"."
] | train | https://github.com/gibilogic/crud-bundle/blob/847e7c7bee4016026411eb230154f24986335633/Entity/EntityService.php#L198-L207 |
gibilogic/crud-bundle | Entity/EntityService.php | EntityService.getFilters | public function getFilters(Request $request, $overrideFilters = array(), $ignoreSession = false)
{
if ($ignoreSession) {
return array_replace(
$this->getFiltersFromRequest($request),
$overrideFilters
);
}
$filters = array_replace(
$this->getFiltersFromSession($request->getSession()),
$this->getFiltersFromRequest($request),
$overrideFilters
);
$this->saveFilters($request->getSession(), $filters);
return $filters;
} | php | public function getFilters(Request $request, $overrideFilters = array(), $ignoreSession = false)
{
if ($ignoreSession) {
return array_replace(
$this->getFiltersFromRequest($request),
$overrideFilters
);
}
$filters = array_replace(
$this->getFiltersFromSession($request->getSession()),
$this->getFiltersFromRequest($request),
$overrideFilters
);
$this->saveFilters($request->getSession(), $filters);
return $filters;
} | [
"public",
"function",
"getFilters",
"(",
"Request",
"$",
"request",
",",
"$",
"overrideFilters",
"=",
"array",
"(",
")",
",",
"$",
"ignoreSession",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"ignoreSession",
")",
"{",
"return",
"array_replace",
"(",
"$",
"this",
"->",
"getFiltersFromRequest",
"(",
"$",
"request",
")",
",",
"$",
"overrideFilters",
")",
";",
"}",
"$",
"filters",
"=",
"array_replace",
"(",
"$",
"this",
"->",
"getFiltersFromSession",
"(",
"$",
"request",
"->",
"getSession",
"(",
")",
")",
",",
"$",
"this",
"->",
"getFiltersFromRequest",
"(",
"$",
"request",
")",
",",
"$",
"overrideFilters",
")",
";",
"$",
"this",
"->",
"saveFilters",
"(",
"$",
"request",
"->",
"getSession",
"(",
")",
",",
"$",
"filters",
")",
";",
"return",
"$",
"filters",
";",
"}"
] | Returns the current filters for the entity, if any.
@param \Symfony\Component\HttpFoundation\Request $request
@param array $overrideFilters
@param bool $ignoreSession
@return array | [
"Returns",
"the",
"current",
"filters",
"for",
"the",
"entity",
"if",
"any",
"."
] | train | https://github.com/gibilogic/crud-bundle/blob/847e7c7bee4016026411eb230154f24986335633/Entity/EntityService.php#L217-L234 |
gibilogic/crud-bundle | Entity/EntityService.php | EntityService.getSorting | public function getSorting(Request $request, $ignoreSession = false)
{
if ($ignoreSession) {
return $this->getSortingFromRequest($request);
}
$sorting = array_replace(
$this->getSortingFromSession($request->getSession()),
$this->getSortingFromRequest($request)
);
$this->saveSorting($request->getSession(), $sorting);
return $sorting;
} | php | public function getSorting(Request $request, $ignoreSession = false)
{
if ($ignoreSession) {
return $this->getSortingFromRequest($request);
}
$sorting = array_replace(
$this->getSortingFromSession($request->getSession()),
$this->getSortingFromRequest($request)
);
$this->saveSorting($request->getSession(), $sorting);
return $sorting;
} | [
"public",
"function",
"getSorting",
"(",
"Request",
"$",
"request",
",",
"$",
"ignoreSession",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"ignoreSession",
")",
"{",
"return",
"$",
"this",
"->",
"getSortingFromRequest",
"(",
"$",
"request",
")",
";",
"}",
"$",
"sorting",
"=",
"array_replace",
"(",
"$",
"this",
"->",
"getSortingFromSession",
"(",
"$",
"request",
"->",
"getSession",
"(",
")",
")",
",",
"$",
"this",
"->",
"getSortingFromRequest",
"(",
"$",
"request",
")",
")",
";",
"$",
"this",
"->",
"saveSorting",
"(",
"$",
"request",
"->",
"getSession",
"(",
")",
",",
"$",
"sorting",
")",
";",
"return",
"$",
"sorting",
";",
"}"
] | Returns the current sorting options for the entity.
@param \Symfony\Component\HttpFoundation\Request $request
@param bool $ignoreSession
@return array | [
"Returns",
"the",
"current",
"sorting",
"options",
"for",
"the",
"entity",
"."
] | train | https://github.com/gibilogic/crud-bundle/blob/847e7c7bee4016026411eb230154f24986335633/Entity/EntityService.php#L243-L256 |
gibilogic/crud-bundle | Entity/EntityService.php | EntityService.addFilter | public function addFilter(SessionInterface $session, $filterName, $filterValue, $overwrite = true)
{
if (!$overwrite && $this->hasFilter($session, $filterName)) {
return;
}
$session->set($this->getFilterPrefix() . $filterName, $filterValue);
} | php | public function addFilter(SessionInterface $session, $filterName, $filterValue, $overwrite = true)
{
if (!$overwrite && $this->hasFilter($session, $filterName)) {
return;
}
$session->set($this->getFilterPrefix() . $filterName, $filterValue);
} | [
"public",
"function",
"addFilter",
"(",
"SessionInterface",
"$",
"session",
",",
"$",
"filterName",
",",
"$",
"filterValue",
",",
"$",
"overwrite",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"$",
"overwrite",
"&&",
"$",
"this",
"->",
"hasFilter",
"(",
"$",
"session",
",",
"$",
"filterName",
")",
")",
"{",
"return",
";",
"}",
"$",
"session",
"->",
"set",
"(",
"$",
"this",
"->",
"getFilterPrefix",
"(",
")",
".",
"$",
"filterName",
",",
"$",
"filterValue",
")",
";",
"}"
] | Adds a single filter to the session; set the `overwrite` flag to `false`
if you want to preserve an already existing value.
@param \Symfony\Component\HttpFoundation\Session\SessionInterface $session
@param string $filterName
@param mixed $filterValue
@param boolean $overwrite | [
"Adds",
"a",
"single",
"filter",
"to",
"the",
"session",
";",
"set",
"the",
"overwrite",
"flag",
"to",
"false",
"if",
"you",
"want",
"to",
"preserve",
"an",
"already",
"existing",
"value",
"."
] | train | https://github.com/gibilogic/crud-bundle/blob/847e7c7bee4016026411eb230154f24986335633/Entity/EntityService.php#L279-L286 |
gibilogic/crud-bundle | Entity/EntityService.php | EntityService.saveFilters | protected function saveFilters(SessionInterface $session, array $filters)
{
$this->saveValues($filters, $this->getFilterPrefix(), $session);
} | php | protected function saveFilters(SessionInterface $session, array $filters)
{
$this->saveValues($filters, $this->getFilterPrefix(), $session);
} | [
"protected",
"function",
"saveFilters",
"(",
"SessionInterface",
"$",
"session",
",",
"array",
"$",
"filters",
")",
"{",
"$",
"this",
"->",
"saveValues",
"(",
"$",
"filters",
",",
"$",
"this",
"->",
"getFilterPrefix",
"(",
")",
",",
"$",
"session",
")",
";",
"}"
] | Saves the filters inside the session.
@param \Symfony\Component\HttpFoundation\Session\SessionInterface $session
@param array $filters | [
"Saves",
"the",
"filters",
"inside",
"the",
"session",
"."
] | train | https://github.com/gibilogic/crud-bundle/blob/847e7c7bee4016026411eb230154f24986335633/Entity/EntityService.php#L305-L308 |
gibilogic/crud-bundle | Entity/EntityService.php | EntityService.saveSorting | protected function saveSorting(SessionInterface $session, array $sorting)
{
$this->saveValues($sorting, $this->getSortingPrefix(), $session);
} | php | protected function saveSorting(SessionInterface $session, array $sorting)
{
$this->saveValues($sorting, $this->getSortingPrefix(), $session);
} | [
"protected",
"function",
"saveSorting",
"(",
"SessionInterface",
"$",
"session",
",",
"array",
"$",
"sorting",
")",
"{",
"$",
"this",
"->",
"saveValues",
"(",
"$",
"sorting",
",",
"$",
"this",
"->",
"getSortingPrefix",
"(",
")",
",",
"$",
"session",
")",
";",
"}"
] | Saves the sorting options (sort field and sort order) inside the session.
@param \Symfony\Component\HttpFoundation\Session\SessionInterface $session
@param array $sorting | [
"Saves",
"the",
"sorting",
"options",
"(",
"sort",
"field",
"and",
"sort",
"order",
")",
"inside",
"the",
"session",
"."
] | train | https://github.com/gibilogic/crud-bundle/blob/847e7c7bee4016026411eb230154f24986335633/Entity/EntityService.php#L316-L319 |
gibilogic/crud-bundle | Entity/EntityService.php | EntityService.getFiltersFromRequest | protected function getFiltersFromRequest(Request $request)
{
return $this->extractValues($this->getValuesFromRequest($request), $this->getFilterPrefix());
} | php | protected function getFiltersFromRequest(Request $request)
{
return $this->extractValues($this->getValuesFromRequest($request), $this->getFilterPrefix());
} | [
"protected",
"function",
"getFiltersFromRequest",
"(",
"Request",
"$",
"request",
")",
"{",
"return",
"$",
"this",
"->",
"extractValues",
"(",
"$",
"this",
"->",
"getValuesFromRequest",
"(",
"$",
"request",
")",
",",
"$",
"this",
"->",
"getFilterPrefix",
"(",
")",
")",
";",
"}"
] | Returns the filters from the request.
@param \Symfony\Component\HttpFoundation\Request $request
@return array | [
"Returns",
"the",
"filters",
"from",
"the",
"request",
"."
] | train | https://github.com/gibilogic/crud-bundle/blob/847e7c7bee4016026411eb230154f24986335633/Entity/EntityService.php#L347-L350 |
gibilogic/crud-bundle | Entity/EntityService.php | EntityService.getSortingFromRequest | protected function getSortingFromRequest(Request $request)
{
return $this->extractValues($this->getValuesFromRequest($request), $this->getSortingPrefix());
} | php | protected function getSortingFromRequest(Request $request)
{
return $this->extractValues($this->getValuesFromRequest($request), $this->getSortingPrefix());
} | [
"protected",
"function",
"getSortingFromRequest",
"(",
"Request",
"$",
"request",
")",
"{",
"return",
"$",
"this",
"->",
"extractValues",
"(",
"$",
"this",
"->",
"getValuesFromRequest",
"(",
"$",
"request",
")",
",",
"$",
"this",
"->",
"getSortingPrefix",
"(",
")",
")",
";",
"}"
] | Returns the sorting options from the request.
@param \Symfony\Component\HttpFoundation\Request $request
@return array | [
"Returns",
"the",
"sorting",
"options",
"from",
"the",
"request",
"."
] | train | https://github.com/gibilogic/crud-bundle/blob/847e7c7bee4016026411eb230154f24986335633/Entity/EntityService.php#L369-L372 |
gibilogic/crud-bundle | Entity/EntityService.php | EntityService.getValuesFromRequest | private function getValuesFromRequest(Request $request)
{
$values = array_merge($request->query->all(), $request->request->all());
$contentValues = json_decode($request->getContent(), true);
if (is_array($contentValues)) {
$values = array_merge($values, $contentValues);
}
return $values;
} | php | private function getValuesFromRequest(Request $request)
{
$values = array_merge($request->query->all(), $request->request->all());
$contentValues = json_decode($request->getContent(), true);
if (is_array($contentValues)) {
$values = array_merge($values, $contentValues);
}
return $values;
} | [
"private",
"function",
"getValuesFromRequest",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"values",
"=",
"array_merge",
"(",
"$",
"request",
"->",
"query",
"->",
"all",
"(",
")",
",",
"$",
"request",
"->",
"request",
"->",
"all",
"(",
")",
")",
";",
"$",
"contentValues",
"=",
"json_decode",
"(",
"$",
"request",
"->",
"getContent",
"(",
")",
",",
"true",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"contentValues",
")",
")",
"{",
"$",
"values",
"=",
"array_merge",
"(",
"$",
"values",
",",
"$",
"contentValues",
")",
";",
"}",
"return",
"$",
"values",
";",
"}"
] | Returns the values of the options from the request.
@param \Symfony\Component\HttpFoundation\Request $request
@return array | [
"Returns",
"the",
"values",
"of",
"the",
"options",
"from",
"the",
"request",
"."
] | train | https://github.com/gibilogic/crud-bundle/blob/847e7c7bee4016026411eb230154f24986335633/Entity/EntityService.php#L423-L432 |
gibilogic/crud-bundle | Entity/EntityService.php | EntityService.extractValues | private function extractValues(array $values, $prefix, $removePrefixFromKeys = true)
{
if (empty($values)) {
return array();
}
$validKeys = array_filter(array_keys($values), function($name) use ($prefix) {
return (0 === strpos($name, $prefix));
});
$results = array_intersect_key($values, array_flip($validKeys));
if (!$removePrefixFromKeys) {
return $results;
}
return array_combine(
array_map(function($key) use ($prefix) {
return str_replace($prefix, '', $key);
}, array_keys($results)), $results
);
} | php | private function extractValues(array $values, $prefix, $removePrefixFromKeys = true)
{
if (empty($values)) {
return array();
}
$validKeys = array_filter(array_keys($values), function($name) use ($prefix) {
return (0 === strpos($name, $prefix));
});
$results = array_intersect_key($values, array_flip($validKeys));
if (!$removePrefixFromKeys) {
return $results;
}
return array_combine(
array_map(function($key) use ($prefix) {
return str_replace($prefix, '', $key);
}, array_keys($results)), $results
);
} | [
"private",
"function",
"extractValues",
"(",
"array",
"$",
"values",
",",
"$",
"prefix",
",",
"$",
"removePrefixFromKeys",
"=",
"true",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"values",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"validKeys",
"=",
"array_filter",
"(",
"array_keys",
"(",
"$",
"values",
")",
",",
"function",
"(",
"$",
"name",
")",
"use",
"(",
"$",
"prefix",
")",
"{",
"return",
"(",
"0",
"===",
"strpos",
"(",
"$",
"name",
",",
"$",
"prefix",
")",
")",
";",
"}",
")",
";",
"$",
"results",
"=",
"array_intersect_key",
"(",
"$",
"values",
",",
"array_flip",
"(",
"$",
"validKeys",
")",
")",
";",
"if",
"(",
"!",
"$",
"removePrefixFromKeys",
")",
"{",
"return",
"$",
"results",
";",
"}",
"return",
"array_combine",
"(",
"array_map",
"(",
"function",
"(",
"$",
"key",
")",
"use",
"(",
"$",
"prefix",
")",
"{",
"return",
"str_replace",
"(",
"$",
"prefix",
",",
"''",
",",
"$",
"key",
")",
";",
"}",
",",
"array_keys",
"(",
"$",
"results",
")",
")",
",",
"$",
"results",
")",
";",
"}"
] | Returns all the key-value pairs from the array whose key has the specified prefix.
@param array $values
@param string $prefix
@param bool $removePrefixFromKeys
@return array | [
"Returns",
"all",
"the",
"key",
"-",
"value",
"pairs",
"from",
"the",
"array",
"whose",
"key",
"has",
"the",
"specified",
"prefix",
"."
] | train | https://github.com/gibilogic/crud-bundle/blob/847e7c7bee4016026411eb230154f24986335633/Entity/EntityService.php#L442-L462 |
gibilogic/crud-bundle | Entity/EntityService.php | EntityService.saveValues | private function saveValues(array $values, $prefix, SessionInterface $session)
{
foreach ($values as $name => $value) {
$session->set($prefix . $name, $value);
}
} | php | private function saveValues(array $values, $prefix, SessionInterface $session)
{
foreach ($values as $name => $value) {
$session->set($prefix . $name, $value);
}
} | [
"private",
"function",
"saveValues",
"(",
"array",
"$",
"values",
",",
"$",
"prefix",
",",
"SessionInterface",
"$",
"session",
")",
"{",
"foreach",
"(",
"$",
"values",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"session",
"->",
"set",
"(",
"$",
"prefix",
".",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"}"
] | Saves into the session all the key-value pairs from the array, adding to their keys the specified prefix.
@param array $values
@param string $prefix
@param \Symfony\Component\HttpFoundation\Session\SessionInterface $session | [
"Saves",
"into",
"the",
"session",
"all",
"the",
"key",
"-",
"value",
"pairs",
"from",
"the",
"array",
"adding",
"to",
"their",
"keys",
"the",
"specified",
"prefix",
"."
] | train | https://github.com/gibilogic/crud-bundle/blob/847e7c7bee4016026411eb230154f24986335633/Entity/EntityService.php#L471-L476 |
gibilogic/crud-bundle | Entity/EntityService.php | EntityService.removeValues | private function removeValues($prefix, SessionInterface $session)
{
foreach ($session->all() as $key => $value) {
if (0 === strpos($key, $prefix)) {
$session->remove($key);
}
}
} | php | private function removeValues($prefix, SessionInterface $session)
{
foreach ($session->all() as $key => $value) {
if (0 === strpos($key, $prefix)) {
$session->remove($key);
}
}
} | [
"private",
"function",
"removeValues",
"(",
"$",
"prefix",
",",
"SessionInterface",
"$",
"session",
")",
"{",
"foreach",
"(",
"$",
"session",
"->",
"all",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"0",
"===",
"strpos",
"(",
"$",
"key",
",",
"$",
"prefix",
")",
")",
"{",
"$",
"session",
"->",
"remove",
"(",
"$",
"key",
")",
";",
"}",
"}",
"}"
] | Removes from the session all the key-value pairs whose key has the specified prefix.
@param string $prefix
@param \Symfony\Component\HttpFoundation\Session\SessionInterface $session | [
"Removes",
"from",
"the",
"session",
"all",
"the",
"key",
"-",
"value",
"pairs",
"whose",
"key",
"has",
"the",
"specified",
"prefix",
"."
] | train | https://github.com/gibilogic/crud-bundle/blob/847e7c7bee4016026411eb230154f24986335633/Entity/EntityService.php#L484-L491 |
gibilogic/crud-bundle | Entity/EntityService.php | EntityService.getPage | private function getPage(Request $request)
{
$page = $request->query->get('page', 1);
if (!is_numeric($page) || $page < 1) {
$page = 1;
}
return (int)$page;
} | php | private function getPage(Request $request)
{
$page = $request->query->get('page', 1);
if (!is_numeric($page) || $page < 1) {
$page = 1;
}
return (int)$page;
} | [
"private",
"function",
"getPage",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"page",
"=",
"$",
"request",
"->",
"query",
"->",
"get",
"(",
"'page'",
",",
"1",
")",
";",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"page",
")",
"||",
"$",
"page",
"<",
"1",
")",
"{",
"$",
"page",
"=",
"1",
";",
"}",
"return",
"(",
"int",
")",
"$",
"page",
";",
"}"
] | Returns the current page number.
@param \Symfony\Component\HttpFoundation\Request $request
@return integer | [
"Returns",
"the",
"current",
"page",
"number",
"."
] | train | https://github.com/gibilogic/crud-bundle/blob/847e7c7bee4016026411eb230154f24986335633/Entity/EntityService.php#L499-L507 |
factorio-item-browser/export-data | src/Entity/Mod/Combination.php | Combination.writeData | public function writeData(): array
{
$dataBuilder = new DataBuilder();
$dataBuilder->setString('n', $this->name, '')
->setString('m', $this->mainModName, '')
->setArray('l', array_values(array_unique($this->loadedModNames)), 'strval', [])
->setArray('o', array_values(array_unique($this->loadedOptionalModNames)), 'strval', [])
->setArray('i', array_values(array_unique($this->itemHashes)), 'strval', [])
->setArray('r', array_values(array_unique($this->recipeHashes)), 'strval', [])
->setArray('a', array_values(array_unique($this->machineHashes)), 'strval', [])
->setArray('c', array_values(array_unique($this->iconHashes)), 'strval', []);
return $dataBuilder->getData();
} | php | public function writeData(): array
{
$dataBuilder = new DataBuilder();
$dataBuilder->setString('n', $this->name, '')
->setString('m', $this->mainModName, '')
->setArray('l', array_values(array_unique($this->loadedModNames)), 'strval', [])
->setArray('o', array_values(array_unique($this->loadedOptionalModNames)), 'strval', [])
->setArray('i', array_values(array_unique($this->itemHashes)), 'strval', [])
->setArray('r', array_values(array_unique($this->recipeHashes)), 'strval', [])
->setArray('a', array_values(array_unique($this->machineHashes)), 'strval', [])
->setArray('c', array_values(array_unique($this->iconHashes)), 'strval', []);
return $dataBuilder->getData();
} | [
"public",
"function",
"writeData",
"(",
")",
":",
"array",
"{",
"$",
"dataBuilder",
"=",
"new",
"DataBuilder",
"(",
")",
";",
"$",
"dataBuilder",
"->",
"setString",
"(",
"'n'",
",",
"$",
"this",
"->",
"name",
",",
"''",
")",
"->",
"setString",
"(",
"'m'",
",",
"$",
"this",
"->",
"mainModName",
",",
"''",
")",
"->",
"setArray",
"(",
"'l'",
",",
"array_values",
"(",
"array_unique",
"(",
"$",
"this",
"->",
"loadedModNames",
")",
")",
",",
"'strval'",
",",
"[",
"]",
")",
"->",
"setArray",
"(",
"'o'",
",",
"array_values",
"(",
"array_unique",
"(",
"$",
"this",
"->",
"loadedOptionalModNames",
")",
")",
",",
"'strval'",
",",
"[",
"]",
")",
"->",
"setArray",
"(",
"'i'",
",",
"array_values",
"(",
"array_unique",
"(",
"$",
"this",
"->",
"itemHashes",
")",
")",
",",
"'strval'",
",",
"[",
"]",
")",
"->",
"setArray",
"(",
"'r'",
",",
"array_values",
"(",
"array_unique",
"(",
"$",
"this",
"->",
"recipeHashes",
")",
")",
",",
"'strval'",
",",
"[",
"]",
")",
"->",
"setArray",
"(",
"'a'",
",",
"array_values",
"(",
"array_unique",
"(",
"$",
"this",
"->",
"machineHashes",
")",
")",
",",
"'strval'",
",",
"[",
"]",
")",
"->",
"setArray",
"(",
"'c'",
",",
"array_values",
"(",
"array_unique",
"(",
"$",
"this",
"->",
"iconHashes",
")",
")",
",",
"'strval'",
",",
"[",
"]",
")",
";",
"return",
"$",
"dataBuilder",
"->",
"getData",
"(",
")",
";",
"}"
] | Writes the entity data to an array.
@return array | [
"Writes",
"the",
"entity",
"data",
"to",
"an",
"array",
"."
] | train | https://github.com/factorio-item-browser/export-data/blob/1413b2eed0fbfed0521457ac7ef0d668ac30c212/src/Entity/Mod/Combination.php#L299-L311 |
factorio-item-browser/export-data | src/Entity/Mod/Combination.php | Combination.readData | public function readData(DataContainer $data)
{
$this->name = $data->getString('n', '');
$this->mainModName = $data->getString('m', '');
$this->loadedModNames = array_map('strval', $data->getArray('l'));
$this->loadedOptionalModNames = array_map('strval', $data->getArray('o'));
$this->itemHashes = array_map('strval', $data->getArray('i'));
$this->recipeHashes = array_map('strval', $data->getArray('r'));
$this->machineHashes = array_map('strval', $data->getArray('a'));
$this->iconHashes = array_map('strval', $data->getArray('c'));
return $this;
} | php | public function readData(DataContainer $data)
{
$this->name = $data->getString('n', '');
$this->mainModName = $data->getString('m', '');
$this->loadedModNames = array_map('strval', $data->getArray('l'));
$this->loadedOptionalModNames = array_map('strval', $data->getArray('o'));
$this->itemHashes = array_map('strval', $data->getArray('i'));
$this->recipeHashes = array_map('strval', $data->getArray('r'));
$this->machineHashes = array_map('strval', $data->getArray('a'));
$this->iconHashes = array_map('strval', $data->getArray('c'));
return $this;
} | [
"public",
"function",
"readData",
"(",
"DataContainer",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"name",
"=",
"$",
"data",
"->",
"getString",
"(",
"'n'",
",",
"''",
")",
";",
"$",
"this",
"->",
"mainModName",
"=",
"$",
"data",
"->",
"getString",
"(",
"'m'",
",",
"''",
")",
";",
"$",
"this",
"->",
"loadedModNames",
"=",
"array_map",
"(",
"'strval'",
",",
"$",
"data",
"->",
"getArray",
"(",
"'l'",
")",
")",
";",
"$",
"this",
"->",
"loadedOptionalModNames",
"=",
"array_map",
"(",
"'strval'",
",",
"$",
"data",
"->",
"getArray",
"(",
"'o'",
")",
")",
";",
"$",
"this",
"->",
"itemHashes",
"=",
"array_map",
"(",
"'strval'",
",",
"$",
"data",
"->",
"getArray",
"(",
"'i'",
")",
")",
";",
"$",
"this",
"->",
"recipeHashes",
"=",
"array_map",
"(",
"'strval'",
",",
"$",
"data",
"->",
"getArray",
"(",
"'r'",
")",
")",
";",
"$",
"this",
"->",
"machineHashes",
"=",
"array_map",
"(",
"'strval'",
",",
"$",
"data",
"->",
"getArray",
"(",
"'a'",
")",
")",
";",
"$",
"this",
"->",
"iconHashes",
"=",
"array_map",
"(",
"'strval'",
",",
"$",
"data",
"->",
"getArray",
"(",
"'c'",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Reads the entity data.
@param DataContainer $data
@return $this | [
"Reads",
"the",
"entity",
"data",
"."
] | train | https://github.com/factorio-item-browser/export-data/blob/1413b2eed0fbfed0521457ac7ef0d668ac30c212/src/Entity/Mod/Combination.php#L318-L329 |
factorio-item-browser/export-data | src/Entity/Mod/Combination.php | Combination.calculateHash | public function calculateHash(): string
{
return EntityUtils::calculateHashOfArray([
$this->name,
$this->mainModName,
$this->loadedModNames,
$this->loadedOptionalModNames,
]);
} | php | public function calculateHash(): string
{
return EntityUtils::calculateHashOfArray([
$this->name,
$this->mainModName,
$this->loadedModNames,
$this->loadedOptionalModNames,
]);
} | [
"public",
"function",
"calculateHash",
"(",
")",
":",
"string",
"{",
"return",
"EntityUtils",
"::",
"calculateHashOfArray",
"(",
"[",
"$",
"this",
"->",
"name",
",",
"$",
"this",
"->",
"mainModName",
",",
"$",
"this",
"->",
"loadedModNames",
",",
"$",
"this",
"->",
"loadedOptionalModNames",
",",
"]",
")",
";",
"}"
] | Calculates a hash value representing the entity.
@return string | [
"Calculates",
"a",
"hash",
"value",
"representing",
"the",
"entity",
"."
] | train | https://github.com/factorio-item-browser/export-data/blob/1413b2eed0fbfed0521457ac7ef0d668ac30c212/src/Entity/Mod/Combination.php#L335-L343 |
yuncms/framework | src/user/controllers/RegistrationController.php | RegistrationController.actionConnect | public function actionConnect($code)
{
if (!Yii::$app->user->isGuest) {
return $this->redirect(['/user/settings/networks']);
}
$account = UserSocialAccount::find()->byCode($code)->one();
if ($account === null || $account->getIsConnected()) {
throw new NotFoundHttpException();
}
/** @var User $user */
$user = Yii::createObject([
'class' => User::class,
'scenario' => User::SCENARIO_CONNECT,
'nickname' => $account->username,
'email' => $account->email,
]);
if ($user->load(Yii::$app->request->post()) && $user->createUser()) {
$account->connect($user);
Yii::$app->user->login($user, Yii::$app->settings->get('rememberFor','user'));
return $this->goBack();
}
return $this->render('connect', [
'model' => $user,
]);
} | php | public function actionConnect($code)
{
if (!Yii::$app->user->isGuest) {
return $this->redirect(['/user/settings/networks']);
}
$account = UserSocialAccount::find()->byCode($code)->one();
if ($account === null || $account->getIsConnected()) {
throw new NotFoundHttpException();
}
/** @var User $user */
$user = Yii::createObject([
'class' => User::class,
'scenario' => User::SCENARIO_CONNECT,
'nickname' => $account->username,
'email' => $account->email,
]);
if ($user->load(Yii::$app->request->post()) && $user->createUser()) {
$account->connect($user);
Yii::$app->user->login($user, Yii::$app->settings->get('rememberFor','user'));
return $this->goBack();
}
return $this->render('connect', [
'model' => $user,
]);
} | [
"public",
"function",
"actionConnect",
"(",
"$",
"code",
")",
"{",
"if",
"(",
"!",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"isGuest",
")",
"{",
"return",
"$",
"this",
"->",
"redirect",
"(",
"[",
"'/user/settings/networks'",
"]",
")",
";",
"}",
"$",
"account",
"=",
"UserSocialAccount",
"::",
"find",
"(",
")",
"->",
"byCode",
"(",
"$",
"code",
")",
"->",
"one",
"(",
")",
";",
"if",
"(",
"$",
"account",
"===",
"null",
"||",
"$",
"account",
"->",
"getIsConnected",
"(",
")",
")",
"{",
"throw",
"new",
"NotFoundHttpException",
"(",
")",
";",
"}",
"/** @var User $user */",
"$",
"user",
"=",
"Yii",
"::",
"createObject",
"(",
"[",
"'class'",
"=>",
"User",
"::",
"class",
",",
"'scenario'",
"=>",
"User",
"::",
"SCENARIO_CONNECT",
",",
"'nickname'",
"=>",
"$",
"account",
"->",
"username",
",",
"'email'",
"=>",
"$",
"account",
"->",
"email",
",",
"]",
")",
";",
"if",
"(",
"$",
"user",
"->",
"load",
"(",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"post",
"(",
")",
")",
"&&",
"$",
"user",
"->",
"createUser",
"(",
")",
")",
"{",
"$",
"account",
"->",
"connect",
"(",
"$",
"user",
")",
";",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"login",
"(",
"$",
"user",
",",
"Yii",
"::",
"$",
"app",
"->",
"settings",
"->",
"get",
"(",
"'rememberFor'",
",",
"'user'",
")",
")",
";",
"return",
"$",
"this",
"->",
"goBack",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"render",
"(",
"'connect'",
",",
"[",
"'model'",
"=>",
"$",
"user",
",",
"]",
")",
";",
"}"
] | Displays page where user can create new account that will be connected to social account.
@param string $code
@return string
@throws NotFoundHttpException
@throws \yii\base\InvalidConfigException | [
"Displays",
"page",
"where",
"user",
"can",
"create",
"new",
"account",
"that",
"will",
"be",
"connected",
"to",
"social",
"account",
"."
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/user/controllers/RegistrationController.php#L109-L138 |
yuncms/framework | src/user/controllers/RegistrationController.php | RegistrationController.actionConfirm | public function actionConfirm($id, $code)
{
$user = User::findOne($id);
if ($user === null || Yii::$app->settings->get('enableConfirmation','user') == false) {
return $this->goBack();
}
$user->attemptEmailConfirmation($code);
return $this->redirect(['/user/settings/profile']);
} | php | public function actionConfirm($id, $code)
{
$user = User::findOne($id);
if ($user === null || Yii::$app->settings->get('enableConfirmation','user') == false) {
return $this->goBack();
}
$user->attemptEmailConfirmation($code);
return $this->redirect(['/user/settings/profile']);
} | [
"public",
"function",
"actionConfirm",
"(",
"$",
"id",
",",
"$",
"code",
")",
"{",
"$",
"user",
"=",
"User",
"::",
"findOne",
"(",
"$",
"id",
")",
";",
"if",
"(",
"$",
"user",
"===",
"null",
"||",
"Yii",
"::",
"$",
"app",
"->",
"settings",
"->",
"get",
"(",
"'enableConfirmation'",
",",
"'user'",
")",
"==",
"false",
")",
"{",
"return",
"$",
"this",
"->",
"goBack",
"(",
")",
";",
"}",
"$",
"user",
"->",
"attemptEmailConfirmation",
"(",
"$",
"code",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"[",
"'/user/settings/profile'",
"]",
")",
";",
"}"
] | Confirms user's account. If confirmation was successful logs the user and shows success message. Otherwise
shows error message.
@param integer $id
@param string $code
@return string | [
"Confirms",
"user",
"s",
"account",
".",
"If",
"confirmation",
"was",
"successful",
"logs",
"the",
"user",
"and",
"shows",
"success",
"message",
".",
"Otherwise",
"shows",
"error",
"message",
"."
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/user/controllers/RegistrationController.php#L149-L157 |
nexusnetsoftgmbh/nexuscli | src/Nexus/Dumper/Communication/Command/DumpLocalCommand.php | DumpLocalCommand.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
$configDataProvider = new DumperConfigDataProvider();
$configDataProvider->setVolume($input->getArgument('volume'));
$configDataProvider->setPath($input->getArgument('path'));
$configDataProvider->setVersion($input->getArgument('version'));
$configDataProvider->setEngine();
$this->getFacade()->dump($configDataProvider);
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
$configDataProvider = new DumperConfigDataProvider();
$configDataProvider->setVolume($input->getArgument('volume'));
$configDataProvider->setPath($input->getArgument('path'));
$configDataProvider->setVersion($input->getArgument('version'));
$configDataProvider->setEngine();
$this->getFacade()->dump($configDataProvider);
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"configDataProvider",
"=",
"new",
"DumperConfigDataProvider",
"(",
")",
";",
"$",
"configDataProvider",
"->",
"setVolume",
"(",
"$",
"input",
"->",
"getArgument",
"(",
"'volume'",
")",
")",
";",
"$",
"configDataProvider",
"->",
"setPath",
"(",
"$",
"input",
"->",
"getArgument",
"(",
"'path'",
")",
")",
";",
"$",
"configDataProvider",
"->",
"setVersion",
"(",
"$",
"input",
"->",
"getArgument",
"(",
"'version'",
")",
")",
";",
"$",
"configDataProvider",
"->",
"setEngine",
"(",
")",
";",
"$",
"this",
"->",
"getFacade",
"(",
")",
"->",
"dump",
"(",
"$",
"configDataProvider",
")",
";",
"}"
] | @param \Symfony\Component\Console\Input\InputInterface $input
@param \Symfony\Component\Console\Output\OutputInterface $output
@return int|null|void | [
"@param",
"\\",
"Symfony",
"\\",
"Component",
"\\",
"Console",
"\\",
"Input",
"\\",
"InputInterface",
"$input",
"@param",
"\\",
"Symfony",
"\\",
"Component",
"\\",
"Console",
"\\",
"Output",
"\\",
"OutputInterface",
"$output"
] | train | https://github.com/nexusnetsoftgmbh/nexuscli/blob/8416b43d31ad56ea379ae2b0bf85d456e78ba67a/src/Nexus/Dumper/Communication/Command/DumpLocalCommand.php#L33-L42 |
trafficgate/shell-command | src/ShellCommand.php | ShellCommand.setCommandTimeout | public function setCommandTimeout($commandTimeout)
{
if ($commandTimeout !== null && ! is_numeric($commandTimeout)) {
throw new InvalidArgumentException('Timeout must be an integer.');
}
if (is_string($commandTimeout)) {
$commandTimeout = (int) $commandTimeout;
}
$this->commandTimeout = $commandTimeout;
return $this;
} | php | public function setCommandTimeout($commandTimeout)
{
if ($commandTimeout !== null && ! is_numeric($commandTimeout)) {
throw new InvalidArgumentException('Timeout must be an integer.');
}
if (is_string($commandTimeout)) {
$commandTimeout = (int) $commandTimeout;
}
$this->commandTimeout = $commandTimeout;
return $this;
} | [
"public",
"function",
"setCommandTimeout",
"(",
"$",
"commandTimeout",
")",
"{",
"if",
"(",
"$",
"commandTimeout",
"!==",
"null",
"&&",
"!",
"is_numeric",
"(",
"$",
"commandTimeout",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Timeout must be an integer.'",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"commandTimeout",
")",
")",
"{",
"$",
"commandTimeout",
"=",
"(",
"int",
")",
"$",
"commandTimeout",
";",
"}",
"$",
"this",
"->",
"commandTimeout",
"=",
"$",
"commandTimeout",
";",
"return",
"$",
"this",
";",
"}"
] | Set the command timeout.
@param int $commandTimeout
@return $this | [
"Set",
"the",
"command",
"timeout",
"."
] | train | https://github.com/trafficgate/shell-command/blob/1a5f3fcf689f33098b192c34839effe309202c0e/src/ShellCommand.php#L165-L178 |
trafficgate/shell-command | src/ShellCommand.php | ShellCommand.setRetryLimit | public function setRetryLimit($retryLimit = null)
{
if (! is_numeric($retryLimit) && ! is_null($retryLimit)) {
throw new InvalidArgumentException('Retry limit must be a number or null.');
}
if (is_string($retryLimit)) {
$retryLimit = (int) $retryLimit;
}
$this->retryLimit = $retryLimit;
return $this;
} | php | public function setRetryLimit($retryLimit = null)
{
if (! is_numeric($retryLimit) && ! is_null($retryLimit)) {
throw new InvalidArgumentException('Retry limit must be a number or null.');
}
if (is_string($retryLimit)) {
$retryLimit = (int) $retryLimit;
}
$this->retryLimit = $retryLimit;
return $this;
} | [
"public",
"function",
"setRetryLimit",
"(",
"$",
"retryLimit",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"retryLimit",
")",
"&&",
"!",
"is_null",
"(",
"$",
"retryLimit",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Retry limit must be a number or null.'",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"retryLimit",
")",
")",
"{",
"$",
"retryLimit",
"=",
"(",
"int",
")",
"$",
"retryLimit",
";",
"}",
"$",
"this",
"->",
"retryLimit",
"=",
"$",
"retryLimit",
";",
"return",
"$",
"this",
";",
"}"
] | Set the number of times to retry a command if it fails.
Set the limit to null to retry forever.
@param int|null $retryLimit
@return $this | [
"Set",
"the",
"number",
"of",
"times",
"to",
"retry",
"a",
"command",
"if",
"it",
"fails",
"."
] | train | https://github.com/trafficgate/shell-command/blob/1a5f3fcf689f33098b192c34839effe309202c0e/src/ShellCommand.php#L199-L212 |
trafficgate/shell-command | src/ShellCommand.php | ShellCommand.argument | final public function argument($key)
{
$result = null;
foreach ($this->shellArguments as $shellArgument) {
if ($shellArgument['key'] === $key) {
$result = $shellArgument;
break;
}
}
return $result;
} | php | final public function argument($key)
{
$result = null;
foreach ($this->shellArguments as $shellArgument) {
if ($shellArgument['key'] === $key) {
$result = $shellArgument;
break;
}
}
return $result;
} | [
"final",
"public",
"function",
"argument",
"(",
"$",
"key",
")",
"{",
"$",
"result",
"=",
"null",
";",
"foreach",
"(",
"$",
"this",
"->",
"shellArguments",
"as",
"$",
"shellArgument",
")",
"{",
"if",
"(",
"$",
"shellArgument",
"[",
"'key'",
"]",
"===",
"$",
"key",
")",
"{",
"$",
"result",
"=",
"$",
"shellArgument",
";",
"break",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Get a specific argument.
Return null if the argument isn't found.
@param $key
@return mixed | [
"Get",
"a",
"specific",
"argument",
"."
] | train | https://github.com/trafficgate/shell-command/blob/1a5f3fcf689f33098b192c34839effe309202c0e/src/ShellCommand.php#L264-L277 |
trafficgate/shell-command | src/ShellCommand.php | ShellCommand.option | final public function option($flag)
{
$result = null;
if (array_key_exists($flag, $this->shellOptions)) {
$result = $this->shellOptions[$flag];
}
return $result;
} | php | final public function option($flag)
{
$result = null;
if (array_key_exists($flag, $this->shellOptions)) {
$result = $this->shellOptions[$flag];
}
return $result;
} | [
"final",
"public",
"function",
"option",
"(",
"$",
"flag",
")",
"{",
"$",
"result",
"=",
"null",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"flag",
",",
"$",
"this",
"->",
"shellOptions",
")",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"shellOptions",
"[",
"$",
"flag",
"]",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Get a specific option.
@param $flag
@return mixed | [
"Get",
"a",
"specific",
"option",
"."
] | train | https://github.com/trafficgate/shell-command/blob/1a5f3fcf689f33098b192c34839effe309202c0e/src/ShellCommand.php#L296-L305 |
trafficgate/shell-command | src/ShellCommand.php | ShellCommand.runOnce | final public function runOnce($idleTimeout = null, callable $callback = null)
{
if (! isset($this->shellCommand)) {
throw new LogicException('No command has been specified! Cannot execute.');
}
$process = $this->compile()->setIdleTimeout($idleTimeout);
$error = null;
try {
$process->mustRun($callback);
} catch (ProcessTimedOutException $e) {
$error = $e;
} catch (ProcessFailedException $e) {
$error = $e;
} catch (Exception $e) {
$error = $e;
$this->logger->error($e->getMessage().$e->getTraceAsString());
}
if (isset($error)) {
$this->setLastError($error);
}
return $process->isSuccessful();
} | php | final public function runOnce($idleTimeout = null, callable $callback = null)
{
if (! isset($this->shellCommand)) {
throw new LogicException('No command has been specified! Cannot execute.');
}
$process = $this->compile()->setIdleTimeout($idleTimeout);
$error = null;
try {
$process->mustRun($callback);
} catch (ProcessTimedOutException $e) {
$error = $e;
} catch (ProcessFailedException $e) {
$error = $e;
} catch (Exception $e) {
$error = $e;
$this->logger->error($e->getMessage().$e->getTraceAsString());
}
if (isset($error)) {
$this->setLastError($error);
}
return $process->isSuccessful();
} | [
"final",
"public",
"function",
"runOnce",
"(",
"$",
"idleTimeout",
"=",
"null",
",",
"callable",
"$",
"callback",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"shellCommand",
")",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"'No command has been specified! Cannot execute.'",
")",
";",
"}",
"$",
"process",
"=",
"$",
"this",
"->",
"compile",
"(",
")",
"->",
"setIdleTimeout",
"(",
"$",
"idleTimeout",
")",
";",
"$",
"error",
"=",
"null",
";",
"try",
"{",
"$",
"process",
"->",
"mustRun",
"(",
"$",
"callback",
")",
";",
"}",
"catch",
"(",
"ProcessTimedOutException",
"$",
"e",
")",
"{",
"$",
"error",
"=",
"$",
"e",
";",
"}",
"catch",
"(",
"ProcessFailedException",
"$",
"e",
")",
"{",
"$",
"error",
"=",
"$",
"e",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"error",
"=",
"$",
"e",
";",
"$",
"this",
"->",
"logger",
"->",
"error",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
".",
"$",
"e",
"->",
"getTraceAsString",
"(",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"error",
")",
")",
"{",
"$",
"this",
"->",
"setLastError",
"(",
"$",
"error",
")",
";",
"}",
"return",
"$",
"process",
"->",
"isSuccessful",
"(",
")",
";",
"}"
] | Execute the command.
@param int|null $idleTimeout time from last output before timing out. Null for no timeout
@param callable|null $callback A callback to run whenever there is some output available on STDOUT or STDERR
@throws LogicException
@return bool | [
"Execute",
"the",
"command",
"."
] | train | https://github.com/trafficgate/shell-command/blob/1a5f3fcf689f33098b192c34839effe309202c0e/src/ShellCommand.php#L327-L353 |
trafficgate/shell-command | src/ShellCommand.php | ShellCommand.runMulti | final public function runMulti($idleTimeout = null, callable $callback = null)
{
$this->resetRetryCount();
$successful = false;
while (! $successful && $this->getRetryCount() < $this->getRetryLimit()) {
$successful = $this->runOnce($idleTimeout, $callback);
$this->increaseRetryCount();
yield $successful;
}
} | php | final public function runMulti($idleTimeout = null, callable $callback = null)
{
$this->resetRetryCount();
$successful = false;
while (! $successful && $this->getRetryCount() < $this->getRetryLimit()) {
$successful = $this->runOnce($idleTimeout, $callback);
$this->increaseRetryCount();
yield $successful;
}
} | [
"final",
"public",
"function",
"runMulti",
"(",
"$",
"idleTimeout",
"=",
"null",
",",
"callable",
"$",
"callback",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"resetRetryCount",
"(",
")",
";",
"$",
"successful",
"=",
"false",
";",
"while",
"(",
"!",
"$",
"successful",
"&&",
"$",
"this",
"->",
"getRetryCount",
"(",
")",
"<",
"$",
"this",
"->",
"getRetryLimit",
"(",
")",
")",
"{",
"$",
"successful",
"=",
"$",
"this",
"->",
"runOnce",
"(",
"$",
"idleTimeout",
",",
"$",
"callback",
")",
";",
"$",
"this",
"->",
"increaseRetryCount",
"(",
")",
";",
"yield",
"$",
"successful",
";",
"}",
"}"
] | Execute the command.
@param int|null $idleTimeout time from last output before timing out. Null for no timeout
@param callable|null $callback A callback to run whenever there is some output available on STDOUT or STDERR
@return bool[] | [
"Execute",
"the",
"command",
"."
] | train | https://github.com/trafficgate/shell-command/blob/1a5f3fcf689f33098b192c34839effe309202c0e/src/ShellCommand.php#L379-L390 |
trafficgate/shell-command | src/ShellCommand.php | ShellCommand.updateArgument | final protected function updateArgument($key, $value)
{
foreach ($this->shellArguments as &$shellArgument) {
if ($shellArgument['key'] === $key) {
$shellArgument['value'] = $value;
break;
}
}
unset($shellArgument);
return $this;
} | php | final protected function updateArgument($key, $value)
{
foreach ($this->shellArguments as &$shellArgument) {
if ($shellArgument['key'] === $key) {
$shellArgument['value'] = $value;
break;
}
}
unset($shellArgument);
return $this;
} | [
"final",
"protected",
"function",
"updateArgument",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"shellArguments",
"as",
"&",
"$",
"shellArgument",
")",
"{",
"if",
"(",
"$",
"shellArgument",
"[",
"'key'",
"]",
"===",
"$",
"key",
")",
"{",
"$",
"shellArgument",
"[",
"'value'",
"]",
"=",
"$",
"value",
";",
"break",
";",
"}",
"}",
"unset",
"(",
"$",
"shellArgument",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Update the specific argument.
@param string $key
@param bool $value
@return $this | [
"Update",
"the",
"specific",
"argument",
"."
] | train | https://github.com/trafficgate/shell-command/blob/1a5f3fcf689f33098b192c34839effe309202c0e/src/ShellCommand.php#L426-L438 |
trafficgate/shell-command | src/ShellCommand.php | ShellCommand.updateOption | final protected function updateOption($flag, $enabled, $value = null, $remove = false)
{
$shellOption = $this->option($flag);
$shellOption->enable($enabled);
if ($shellOption->canHaveValue()) {
$this->updateOptionValue($shellOption, $value, $remove);
}
return $this;
} | php | final protected function updateOption($flag, $enabled, $value = null, $remove = false)
{
$shellOption = $this->option($flag);
$shellOption->enable($enabled);
if ($shellOption->canHaveValue()) {
$this->updateOptionValue($shellOption, $value, $remove);
}
return $this;
} | [
"final",
"protected",
"function",
"updateOption",
"(",
"$",
"flag",
",",
"$",
"enabled",
",",
"$",
"value",
"=",
"null",
",",
"$",
"remove",
"=",
"false",
")",
"{",
"$",
"shellOption",
"=",
"$",
"this",
"->",
"option",
"(",
"$",
"flag",
")",
";",
"$",
"shellOption",
"->",
"enable",
"(",
"$",
"enabled",
")",
";",
"if",
"(",
"$",
"shellOption",
"->",
"canHaveValue",
"(",
")",
")",
"{",
"$",
"this",
"->",
"updateOptionValue",
"(",
"$",
"shellOption",
",",
"$",
"value",
",",
"$",
"remove",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Update an option.
@param string $flag
@param bool $enabled
@param bool $value
@param bool $remove
@return $this | [
"Update",
"an",
"option",
"."
] | train | https://github.com/trafficgate/shell-command/blob/1a5f3fcf689f33098b192c34839effe309202c0e/src/ShellCommand.php#L450-L460 |
trafficgate/shell-command | src/ShellCommand.php | ShellCommand.setShellCommand | private function setShellCommand($command)
{
if (! isset($command)) {
throw new InvalidArgumentException('Must define a command.');
}
if (isset($this->shellCommand) && $this->shellCommand !== $command) {
throw new LogicException('Cannot redefine command once set!');
}
$this->shellCommand = $command;
return $this;
} | php | private function setShellCommand($command)
{
if (! isset($command)) {
throw new InvalidArgumentException('Must define a command.');
}
if (isset($this->shellCommand) && $this->shellCommand !== $command) {
throw new LogicException('Cannot redefine command once set!');
}
$this->shellCommand = $command;
return $this;
} | [
"private",
"function",
"setShellCommand",
"(",
"$",
"command",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"command",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Must define a command.'",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"shellCommand",
")",
"&&",
"$",
"this",
"->",
"shellCommand",
"!==",
"$",
"command",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"'Cannot redefine command once set!'",
")",
";",
"}",
"$",
"this",
"->",
"shellCommand",
"=",
"$",
"command",
";",
"return",
"$",
"this",
";",
"}"
] | Set the command to execute.
The command can only be set once.
@param $command
@return $this | [
"Set",
"the",
"command",
"to",
"execute",
"."
] | train | https://github.com/trafficgate/shell-command/blob/1a5f3fcf689f33098b192c34839effe309202c0e/src/ShellCommand.php#L481-L494 |
trafficgate/shell-command | src/ShellCommand.php | ShellCommand.defineArgument | private function defineArgument($key)
{
$shellArgumentFound = false;
foreach ($this->shellArguments as $shellArgument) {
if ($shellArgument['key'] === $key) {
$shellArgumentFound = true;
}
}
if (! $shellArgumentFound) {
array_push($this->shellArguments, ['key' => $key, 'value' => '']);
}
return $this;
} | php | private function defineArgument($key)
{
$shellArgumentFound = false;
foreach ($this->shellArguments as $shellArgument) {
if ($shellArgument['key'] === $key) {
$shellArgumentFound = true;
}
}
if (! $shellArgumentFound) {
array_push($this->shellArguments, ['key' => $key, 'value' => '']);
}
return $this;
} | [
"private",
"function",
"defineArgument",
"(",
"$",
"key",
")",
"{",
"$",
"shellArgumentFound",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"shellArguments",
"as",
"$",
"shellArgument",
")",
"{",
"if",
"(",
"$",
"shellArgument",
"[",
"'key'",
"]",
"===",
"$",
"key",
")",
"{",
"$",
"shellArgumentFound",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"shellArgumentFound",
")",
"{",
"array_push",
"(",
"$",
"this",
"->",
"shellArguments",
",",
"[",
"'key'",
"=>",
"$",
"key",
",",
"'value'",
"=>",
"''",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set an argument for the command.
@param string $key
@return $this | [
"Set",
"an",
"argument",
"for",
"the",
"command",
"."
] | train | https://github.com/trafficgate/shell-command/blob/1a5f3fcf689f33098b192c34839effe309202c0e/src/ShellCommand.php#L527-L541 |
trafficgate/shell-command | src/ShellCommand.php | ShellCommand.updateOptionValue | private function updateOptionValue(ShellOption $shellOption, $value = null, $remove = false)
{
if ($remove) {
$shellOption->removeValue($value);
} else {
$shellOption->addValue($value);
}
} | php | private function updateOptionValue(ShellOption $shellOption, $value = null, $remove = false)
{
if ($remove) {
$shellOption->removeValue($value);
} else {
$shellOption->addValue($value);
}
} | [
"private",
"function",
"updateOptionValue",
"(",
"ShellOption",
"$",
"shellOption",
",",
"$",
"value",
"=",
"null",
",",
"$",
"remove",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"remove",
")",
"{",
"$",
"shellOption",
"->",
"removeValue",
"(",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"shellOption",
"->",
"addValue",
"(",
"$",
"value",
")",
";",
"}",
"}"
] | Update the value for an option.
@param ShellOption $shellOption
@param mixed|null $value
@param bool|false $remove | [
"Update",
"the",
"value",
"for",
"an",
"option",
"."
] | train | https://github.com/trafficgate/shell-command/blob/1a5f3fcf689f33098b192c34839effe309202c0e/src/ShellCommand.php#L564-L571 |
trafficgate/shell-command | src/ShellCommand.php | ShellCommand.compile | private function compile()
{
$shellOptions = [];
/** @var ShellOption $shellOption */
foreach ($this->shellOptions as $shellOption) {
$shellOptions = array_merge($shellOptions, $shellOption->getArray());
}
$shellArguments = [];
foreach ($this->shellArguments as $shellArgument) {
$shellArguments[] = $shellArgument['value'];
}
$command = array_merge([$this->shellCommand], $shellOptions, $shellArguments);
$builder = new Process($command);
$builder->setTimeout($this->getCommandTimeout());
$this->builder = $builder;
return $this->builder;
} | php | private function compile()
{
$shellOptions = [];
/** @var ShellOption $shellOption */
foreach ($this->shellOptions as $shellOption) {
$shellOptions = array_merge($shellOptions, $shellOption->getArray());
}
$shellArguments = [];
foreach ($this->shellArguments as $shellArgument) {
$shellArguments[] = $shellArgument['value'];
}
$command = array_merge([$this->shellCommand], $shellOptions, $shellArguments);
$builder = new Process($command);
$builder->setTimeout($this->getCommandTimeout());
$this->builder = $builder;
return $this->builder;
} | [
"private",
"function",
"compile",
"(",
")",
"{",
"$",
"shellOptions",
"=",
"[",
"]",
";",
"/** @var ShellOption $shellOption */",
"foreach",
"(",
"$",
"this",
"->",
"shellOptions",
"as",
"$",
"shellOption",
")",
"{",
"$",
"shellOptions",
"=",
"array_merge",
"(",
"$",
"shellOptions",
",",
"$",
"shellOption",
"->",
"getArray",
"(",
")",
")",
";",
"}",
"$",
"shellArguments",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"shellArguments",
"as",
"$",
"shellArgument",
")",
"{",
"$",
"shellArguments",
"[",
"]",
"=",
"$",
"shellArgument",
"[",
"'value'",
"]",
";",
"}",
"$",
"command",
"=",
"array_merge",
"(",
"[",
"$",
"this",
"->",
"shellCommand",
"]",
",",
"$",
"shellOptions",
",",
"$",
"shellArguments",
")",
";",
"$",
"builder",
"=",
"new",
"Process",
"(",
"$",
"command",
")",
";",
"$",
"builder",
"->",
"setTimeout",
"(",
"$",
"this",
"->",
"getCommandTimeout",
"(",
")",
")",
";",
"$",
"this",
"->",
"builder",
"=",
"$",
"builder",
";",
"return",
"$",
"this",
"->",
"builder",
";",
"}"
] | Compile the parts of the command.
@return Process | [
"Compile",
"the",
"parts",
"of",
"the",
"command",
"."
] | train | https://github.com/trafficgate/shell-command/blob/1a5f3fcf689f33098b192c34839effe309202c0e/src/ShellCommand.php#L578-L600 |
forxer/tao | src/Tao/Templating/Helpers/Modifier.php | Modifier.nlToP | public function nlToP($string)
{
$string = trim($string);
$string = Modifiers::linebreaks($string);
$string = str_replace("\n", "</p>\n<p>", $string);
$string = str_replace('<p></p>', '', $string);
return '<p>' . $string . '</p>' . PHP_EOL;
} | php | public function nlToP($string)
{
$string = trim($string);
$string = Modifiers::linebreaks($string);
$string = str_replace("\n", "</p>\n<p>", $string);
$string = str_replace('<p></p>', '', $string);
return '<p>' . $string . '</p>' . PHP_EOL;
} | [
"public",
"function",
"nlToP",
"(",
"$",
"string",
")",
"{",
"$",
"string",
"=",
"trim",
"(",
"$",
"string",
")",
";",
"$",
"string",
"=",
"Modifiers",
"::",
"linebreaks",
"(",
"$",
"string",
")",
";",
"$",
"string",
"=",
"str_replace",
"(",
"\"\\n\"",
",",
"\"</p>\\n<p>\"",
",",
"$",
"string",
")",
";",
"$",
"string",
"=",
"str_replace",
"(",
"'<p></p>'",
",",
"''",
",",
"$",
"string",
")",
";",
"return",
"'<p>'",
".",
"$",
"string",
".",
"'</p>'",
".",
"PHP_EOL",
";",
"}"
] | Converts text line breaks into HTML paragraphs.
@param string $string String to transform
@return string | [
"Converts",
"text",
"line",
"breaks",
"into",
"HTML",
"paragraphs",
"."
] | train | https://github.com/forxer/tao/blob/b5e9109c244a29a72403ae6a58633ab96a67c660/src/Tao/Templating/Helpers/Modifier.php#L29-L36 |
forxer/tao | src/Tao/Templating/Helpers/Modifier.php | Modifier.nlToPbr | public function nlToPbr($string)
{
$string = trim($string);
$string = Modifiers::linebreaks($string);
$string = str_replace("\n", '<br />', $string);
$string = str_replace('<br /><br />', "</p>\n<p>", $string);
$string = str_replace('<p></p>', '', $string);
return '<p>' . $string . '</p>' . PHP_EOL;
} | php | public function nlToPbr($string)
{
$string = trim($string);
$string = Modifiers::linebreaks($string);
$string = str_replace("\n", '<br />', $string);
$string = str_replace('<br /><br />', "</p>\n<p>", $string);
$string = str_replace('<p></p>', '', $string);
return '<p>' . $string . '</p>' . PHP_EOL;
} | [
"public",
"function",
"nlToPbr",
"(",
"$",
"string",
")",
"{",
"$",
"string",
"=",
"trim",
"(",
"$",
"string",
")",
";",
"$",
"string",
"=",
"Modifiers",
"::",
"linebreaks",
"(",
"$",
"string",
")",
";",
"$",
"string",
"=",
"str_replace",
"(",
"\"\\n\"",
",",
"'<br />'",
",",
"$",
"string",
")",
";",
"$",
"string",
"=",
"str_replace",
"(",
"'<br /><br />'",
",",
"\"</p>\\n<p>\"",
",",
"$",
"string",
")",
";",
"$",
"string",
"=",
"str_replace",
"(",
"'<p></p>'",
",",
"''",
",",
"$",
"string",
")",
";",
"return",
"'<p>'",
".",
"$",
"string",
".",
"'</p>'",
".",
"PHP_EOL",
";",
"}"
] | Converts text line breaks into HTML paragraphs and HTML line breaks.
@param string $string String to transform
@return string | [
"Converts",
"text",
"line",
"breaks",
"into",
"HTML",
"paragraphs",
"and",
"HTML",
"line",
"breaks",
"."
] | train | https://github.com/forxer/tao/blob/b5e9109c244a29a72403ae6a58633ab96a67c660/src/Tao/Templating/Helpers/Modifier.php#L44-L52 |
forxer/tao | src/Tao/Templating/Helpers/Modifier.php | Modifier.emailEncode | public static function emailEncode($sEmail)
{
$sEmail = bin2hex($sEmail);
$sEmail = chunk_split($sEmail, 2, '%');
$sEmail = '%' . substr($sEmail, 0, strlen($sEmail) - 1);
return $sEmail;
} | php | public static function emailEncode($sEmail)
{
$sEmail = bin2hex($sEmail);
$sEmail = chunk_split($sEmail, 2, '%');
$sEmail = '%' . substr($sEmail, 0, strlen($sEmail) - 1);
return $sEmail;
} | [
"public",
"static",
"function",
"emailEncode",
"(",
"$",
"sEmail",
")",
"{",
"$",
"sEmail",
"=",
"bin2hex",
"(",
"$",
"sEmail",
")",
";",
"$",
"sEmail",
"=",
"chunk_split",
"(",
"$",
"sEmail",
",",
"2",
",",
"'%'",
")",
";",
"$",
"sEmail",
"=",
"'%'",
".",
"substr",
"(",
"$",
"sEmail",
",",
"0",
",",
"strlen",
"(",
"$",
"sEmail",
")",
"-",
"1",
")",
";",
"return",
"$",
"sEmail",
";",
"}"
] | Encode an email address for HTML.
@param string $sEmail
@return string encoded email | [
"Encode",
"an",
"email",
"address",
"for",
"HTML",
"."
] | train | https://github.com/forxer/tao/blob/b5e9109c244a29a72403ae6a58633ab96a67c660/src/Tao/Templating/Helpers/Modifier.php#L60-L66 |
forxer/tao | src/Tao/Templating/Helpers/Modifier.php | Modifier.truncate | public function truncate($string, $length = 80, $etc = '...', $bBreakWords = false, $bMiddle = false)
{
if (mb_strlen($string) > $length)
{
$length -= min($length, mb_strlen($etc));
if (!$bBreakWords && !$bMiddle) {
$string = preg_replace('/\s+?(\S+)?$/u', '', mb_substr($string, 0, $length + 1));
}
if (!$bMiddle) {
return mb_substr($string, 0, $length) . $etc;
}
return mb_substr($string, 0, $length / 2) . $etc . mb_substr($string, - $length / 2, $length);
}
return $string;
} | php | public function truncate($string, $length = 80, $etc = '...', $bBreakWords = false, $bMiddle = false)
{
if (mb_strlen($string) > $length)
{
$length -= min($length, mb_strlen($etc));
if (!$bBreakWords && !$bMiddle) {
$string = preg_replace('/\s+?(\S+)?$/u', '', mb_substr($string, 0, $length + 1));
}
if (!$bMiddle) {
return mb_substr($string, 0, $length) . $etc;
}
return mb_substr($string, 0, $length / 2) . $etc . mb_substr($string, - $length / 2, $length);
}
return $string;
} | [
"public",
"function",
"truncate",
"(",
"$",
"string",
",",
"$",
"length",
"=",
"80",
",",
"$",
"etc",
"=",
"'...'",
",",
"$",
"bBreakWords",
"=",
"false",
",",
"$",
"bMiddle",
"=",
"false",
")",
"{",
"if",
"(",
"mb_strlen",
"(",
"$",
"string",
")",
">",
"$",
"length",
")",
"{",
"$",
"length",
"-=",
"min",
"(",
"$",
"length",
",",
"mb_strlen",
"(",
"$",
"etc",
")",
")",
";",
"if",
"(",
"!",
"$",
"bBreakWords",
"&&",
"!",
"$",
"bMiddle",
")",
"{",
"$",
"string",
"=",
"preg_replace",
"(",
"'/\\s+?(\\S+)?$/u'",
",",
"''",
",",
"mb_substr",
"(",
"$",
"string",
",",
"0",
",",
"$",
"length",
"+",
"1",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"bMiddle",
")",
"{",
"return",
"mb_substr",
"(",
"$",
"string",
",",
"0",
",",
"$",
"length",
")",
".",
"$",
"etc",
";",
"}",
"return",
"mb_substr",
"(",
"$",
"string",
",",
"0",
",",
"$",
"length",
"/",
"2",
")",
".",
"$",
"etc",
".",
"mb_substr",
"(",
"$",
"string",
",",
"-",
"$",
"length",
"/",
"2",
",",
"$",
"length",
")",
";",
"}",
"return",
"$",
"string",
";",
"}"
] | Truncate a string to a certain length if necessary,
optionally splitting in the middle of a word, and
appending the $etc string or inserting $etc into the middle.
@param string $string
@param integer $length
@param string $etc
@param boolean $bBreakWords
@param boolean $bMiddle
@return string truncated string | [
"Truncate",
"a",
"string",
"to",
"a",
"certain",
"length",
"if",
"necessary",
"optionally",
"splitting",
"in",
"the",
"middle",
"of",
"a",
"word",
"and",
"appending",
"the",
"$etc",
"string",
"or",
"inserting",
"$etc",
"into",
"the",
"middle",
"."
] | train | https://github.com/forxer/tao/blob/b5e9109c244a29a72403ae6a58633ab96a67c660/src/Tao/Templating/Helpers/Modifier.php#L80-L98 |
periaptio/empress-generator | src/Commands/ScaffoldMakeCommand.php | ScaffoldMakeCommand.handle | public function handle()
{
parent::handle();
if ($this->option('models')) {
$this->models = explode(',', $this->option('models'));
}
if ($this->option('models')) {
$this->models = explode(',', $this->option('models'));
}
// TODO: compare the length option
$configData = $this->getConfigData();
// get message config by locale
$locale = config('app.locale');
$configMessages = config('generator.message');
if (isset($configMessages[$locale])) {
$messages = $configMessages[$locale];
} else {
$messages = $configMessages['en'];
}
$configData = array_merge([
'MESSAGE_STORE' => "'".str_replace(':model', '$MODEL_NAME$', $messages['store'])."'",
'MESSAGE_UPDATE' => "'".str_replace(':model', '$MODEL_NAME$', $messages['update'])."'",
'MESSAGE_DELETE' => "'".str_replace(':model', '$MODEL_NAME$', $messages['delete'])."'",
'MESSAGE_NOT_FOUND' => "'".str_replace(':model', '$MODEL_NAME$', $messages['not_found'])."'",
], $configData);
// init generators
$routeGenerator = new RoutesGenerator($this);
$modelGenerator = new ModelGenerator($this);
$useRepositoryLayer = config('generator.use_repository_layer', true);
if ($useRepositoryLayer) {
$repositoryGenerator = new RepositoryGenerator($this);
$repositoryGenerator->askMakeBaseRepository();
}
$useServiceLayer = config('generator.use_service_layer', true);
if ($useServiceLayer) {
$serviceGenerator = new ServiceGenerator($this);
}
$requestGenerator = new RequestGenerator($this);
$controllerGenerator = new ControllerGenerator($this);
$viewGenerator = new ViewGenerator($this);
// generate files for every table
foreach ($this->tables as $idx => $tableName) {
if (isset($this->models[$idx])) {
$modelName = $this->models[$idx];
} else {
$modelName = str_singular(studly_case($tableName));
}
$this->comment('Generating scaffold for: '. $tableName);
$data = array_merge($configData, [
'TABLE_NAME' => $tableName,
'MODEL_NAME' => $modelName,
'MODEL_NAME_CAMEL' => camel_case($modelName),
'MODEL_NAME_PLURAL' => str_plural($modelName),
'MODEL_NAME_PLURAL_LOWER' => strtolower(str_plural($modelName)),
'MODEL_NAME_PLURAL_CAMEL' => camel_case(str_plural($modelName)),
'RESOURCE_URL' => str_slug($tableName),
'RESOURCE_SLUG' => str_singular($tableName),
'VIEW_FOLDER_NAME' => snake_case($tableName)
]);
// update route
$routeGenerator->generate($data);
// create a model
$modelGenerator->generate($data);
if (isset($repositoryGenerator)) {
// create a repository
$repositoryGenerator->generate($data);
}
if (isset($serviceGenerator)) {
// create a service
$serviceGenerator->generate($data);
}
// create request files
$requestGenerator->generate($data);
// create a controller
$controllerGenerator->generate($data);
// create a view folder
$viewGenerator->fillableColumns = $modelGenerator->fillableColumns;
$viewGenerator->generate($data);
}
} | php | public function handle()
{
parent::handle();
if ($this->option('models')) {
$this->models = explode(',', $this->option('models'));
}
if ($this->option('models')) {
$this->models = explode(',', $this->option('models'));
}
// TODO: compare the length option
$configData = $this->getConfigData();
// get message config by locale
$locale = config('app.locale');
$configMessages = config('generator.message');
if (isset($configMessages[$locale])) {
$messages = $configMessages[$locale];
} else {
$messages = $configMessages['en'];
}
$configData = array_merge([
'MESSAGE_STORE' => "'".str_replace(':model', '$MODEL_NAME$', $messages['store'])."'",
'MESSAGE_UPDATE' => "'".str_replace(':model', '$MODEL_NAME$', $messages['update'])."'",
'MESSAGE_DELETE' => "'".str_replace(':model', '$MODEL_NAME$', $messages['delete'])."'",
'MESSAGE_NOT_FOUND' => "'".str_replace(':model', '$MODEL_NAME$', $messages['not_found'])."'",
], $configData);
// init generators
$routeGenerator = new RoutesGenerator($this);
$modelGenerator = new ModelGenerator($this);
$useRepositoryLayer = config('generator.use_repository_layer', true);
if ($useRepositoryLayer) {
$repositoryGenerator = new RepositoryGenerator($this);
$repositoryGenerator->askMakeBaseRepository();
}
$useServiceLayer = config('generator.use_service_layer', true);
if ($useServiceLayer) {
$serviceGenerator = new ServiceGenerator($this);
}
$requestGenerator = new RequestGenerator($this);
$controllerGenerator = new ControllerGenerator($this);
$viewGenerator = new ViewGenerator($this);
// generate files for every table
foreach ($this->tables as $idx => $tableName) {
if (isset($this->models[$idx])) {
$modelName = $this->models[$idx];
} else {
$modelName = str_singular(studly_case($tableName));
}
$this->comment('Generating scaffold for: '. $tableName);
$data = array_merge($configData, [
'TABLE_NAME' => $tableName,
'MODEL_NAME' => $modelName,
'MODEL_NAME_CAMEL' => camel_case($modelName),
'MODEL_NAME_PLURAL' => str_plural($modelName),
'MODEL_NAME_PLURAL_LOWER' => strtolower(str_plural($modelName)),
'MODEL_NAME_PLURAL_CAMEL' => camel_case(str_plural($modelName)),
'RESOURCE_URL' => str_slug($tableName),
'RESOURCE_SLUG' => str_singular($tableName),
'VIEW_FOLDER_NAME' => snake_case($tableName)
]);
// update route
$routeGenerator->generate($data);
// create a model
$modelGenerator->generate($data);
if (isset($repositoryGenerator)) {
// create a repository
$repositoryGenerator->generate($data);
}
if (isset($serviceGenerator)) {
// create a service
$serviceGenerator->generate($data);
}
// create request files
$requestGenerator->generate($data);
// create a controller
$controllerGenerator->generate($data);
// create a view folder
$viewGenerator->fillableColumns = $modelGenerator->fillableColumns;
$viewGenerator->generate($data);
}
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"parent",
"::",
"handle",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"option",
"(",
"'models'",
")",
")",
"{",
"$",
"this",
"->",
"models",
"=",
"explode",
"(",
"','",
",",
"$",
"this",
"->",
"option",
"(",
"'models'",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"option",
"(",
"'models'",
")",
")",
"{",
"$",
"this",
"->",
"models",
"=",
"explode",
"(",
"','",
",",
"$",
"this",
"->",
"option",
"(",
"'models'",
")",
")",
";",
"}",
"// TODO: compare the length option",
"$",
"configData",
"=",
"$",
"this",
"->",
"getConfigData",
"(",
")",
";",
"// get message config by locale",
"$",
"locale",
"=",
"config",
"(",
"'app.locale'",
")",
";",
"$",
"configMessages",
"=",
"config",
"(",
"'generator.message'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"configMessages",
"[",
"$",
"locale",
"]",
")",
")",
"{",
"$",
"messages",
"=",
"$",
"configMessages",
"[",
"$",
"locale",
"]",
";",
"}",
"else",
"{",
"$",
"messages",
"=",
"$",
"configMessages",
"[",
"'en'",
"]",
";",
"}",
"$",
"configData",
"=",
"array_merge",
"(",
"[",
"'MESSAGE_STORE'",
"=>",
"\"'\"",
".",
"str_replace",
"(",
"':model'",
",",
"'$MODEL_NAME$'",
",",
"$",
"messages",
"[",
"'store'",
"]",
")",
".",
"\"'\"",
",",
"'MESSAGE_UPDATE'",
"=>",
"\"'\"",
".",
"str_replace",
"(",
"':model'",
",",
"'$MODEL_NAME$'",
",",
"$",
"messages",
"[",
"'update'",
"]",
")",
".",
"\"'\"",
",",
"'MESSAGE_DELETE'",
"=>",
"\"'\"",
".",
"str_replace",
"(",
"':model'",
",",
"'$MODEL_NAME$'",
",",
"$",
"messages",
"[",
"'delete'",
"]",
")",
".",
"\"'\"",
",",
"'MESSAGE_NOT_FOUND'",
"=>",
"\"'\"",
".",
"str_replace",
"(",
"':model'",
",",
"'$MODEL_NAME$'",
",",
"$",
"messages",
"[",
"'not_found'",
"]",
")",
".",
"\"'\"",
",",
"]",
",",
"$",
"configData",
")",
";",
"// init generators",
"$",
"routeGenerator",
"=",
"new",
"RoutesGenerator",
"(",
"$",
"this",
")",
";",
"$",
"modelGenerator",
"=",
"new",
"ModelGenerator",
"(",
"$",
"this",
")",
";",
"$",
"useRepositoryLayer",
"=",
"config",
"(",
"'generator.use_repository_layer'",
",",
"true",
")",
";",
"if",
"(",
"$",
"useRepositoryLayer",
")",
"{",
"$",
"repositoryGenerator",
"=",
"new",
"RepositoryGenerator",
"(",
"$",
"this",
")",
";",
"$",
"repositoryGenerator",
"->",
"askMakeBaseRepository",
"(",
")",
";",
"}",
"$",
"useServiceLayer",
"=",
"config",
"(",
"'generator.use_service_layer'",
",",
"true",
")",
";",
"if",
"(",
"$",
"useServiceLayer",
")",
"{",
"$",
"serviceGenerator",
"=",
"new",
"ServiceGenerator",
"(",
"$",
"this",
")",
";",
"}",
"$",
"requestGenerator",
"=",
"new",
"RequestGenerator",
"(",
"$",
"this",
")",
";",
"$",
"controllerGenerator",
"=",
"new",
"ControllerGenerator",
"(",
"$",
"this",
")",
";",
"$",
"viewGenerator",
"=",
"new",
"ViewGenerator",
"(",
"$",
"this",
")",
";",
"// generate files for every table",
"foreach",
"(",
"$",
"this",
"->",
"tables",
"as",
"$",
"idx",
"=>",
"$",
"tableName",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"models",
"[",
"$",
"idx",
"]",
")",
")",
"{",
"$",
"modelName",
"=",
"$",
"this",
"->",
"models",
"[",
"$",
"idx",
"]",
";",
"}",
"else",
"{",
"$",
"modelName",
"=",
"str_singular",
"(",
"studly_case",
"(",
"$",
"tableName",
")",
")",
";",
"}",
"$",
"this",
"->",
"comment",
"(",
"'Generating scaffold for: '",
".",
"$",
"tableName",
")",
";",
"$",
"data",
"=",
"array_merge",
"(",
"$",
"configData",
",",
"[",
"'TABLE_NAME'",
"=>",
"$",
"tableName",
",",
"'MODEL_NAME'",
"=>",
"$",
"modelName",
",",
"'MODEL_NAME_CAMEL'",
"=>",
"camel_case",
"(",
"$",
"modelName",
")",
",",
"'MODEL_NAME_PLURAL'",
"=>",
"str_plural",
"(",
"$",
"modelName",
")",
",",
"'MODEL_NAME_PLURAL_LOWER'",
"=>",
"strtolower",
"(",
"str_plural",
"(",
"$",
"modelName",
")",
")",
",",
"'MODEL_NAME_PLURAL_CAMEL'",
"=>",
"camel_case",
"(",
"str_plural",
"(",
"$",
"modelName",
")",
")",
",",
"'RESOURCE_URL'",
"=>",
"str_slug",
"(",
"$",
"tableName",
")",
",",
"'RESOURCE_SLUG'",
"=>",
"str_singular",
"(",
"$",
"tableName",
")",
",",
"'VIEW_FOLDER_NAME'",
"=>",
"snake_case",
"(",
"$",
"tableName",
")",
"]",
")",
";",
"// update route",
"$",
"routeGenerator",
"->",
"generate",
"(",
"$",
"data",
")",
";",
"// create a model",
"$",
"modelGenerator",
"->",
"generate",
"(",
"$",
"data",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"repositoryGenerator",
")",
")",
"{",
"// create a repository",
"$",
"repositoryGenerator",
"->",
"generate",
"(",
"$",
"data",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"serviceGenerator",
")",
")",
"{",
"// create a service",
"$",
"serviceGenerator",
"->",
"generate",
"(",
"$",
"data",
")",
";",
"}",
"// create request files",
"$",
"requestGenerator",
"->",
"generate",
"(",
"$",
"data",
")",
";",
"// create a controller",
"$",
"controllerGenerator",
"->",
"generate",
"(",
"$",
"data",
")",
";",
"// create a view folder",
"$",
"viewGenerator",
"->",
"fillableColumns",
"=",
"$",
"modelGenerator",
"->",
"fillableColumns",
";",
"$",
"viewGenerator",
"->",
"generate",
"(",
"$",
"data",
")",
";",
"}",
"}"
] | Execute the command.
@return void | [
"Execute",
"the",
"command",
"."
] | train | https://github.com/periaptio/empress-generator/blob/749fb4b12755819e9c97377ebfb446ee0822168a/src/Commands/ScaffoldMakeCommand.php#L57-L155 |
jenwachter/html-form | src/Abstracts/Addable.php | Addable.findClass | protected function findClass($method)
{
if (!preg_match("/^add([a-zA-Z]+)/", $method, $matches)) {
return false;
}
$className = "\\HtmlForm\\Elements\\{$matches[1]}";
if (!class_exists($className)) {
return false;
}
return $className;
} | php | protected function findClass($method)
{
if (!preg_match("/^add([a-zA-Z]+)/", $method, $matches)) {
return false;
}
$className = "\\HtmlForm\\Elements\\{$matches[1]}";
if (!class_exists($className)) {
return false;
}
return $className;
} | [
"protected",
"function",
"findClass",
"(",
"$",
"method",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"\"/^add([a-zA-Z]+)/\"",
",",
"$",
"method",
",",
"$",
"matches",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"className",
"=",
"\"\\\\HtmlForm\\\\Elements\\\\{$matches[1]}\"",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"className",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"className",
";",
"}"
] | Based on a passed method name, figure out
if there is a cooresponding HtmlForm element.
@param string $method Called method
@return string Class name (if there is one) | [
"Based",
"on",
"a",
"passed",
"method",
"name",
"figure",
"out",
"if",
"there",
"is",
"a",
"cooresponding",
"HtmlForm",
"element",
"."
] | train | https://github.com/jenwachter/html-form/blob/eaece87d474f7da5c25679548fb8f1608a94303c/src/Abstracts/Addable.php#L40-L53 |
atkrad/data-tables | src/Table.php | Table.setDataSource | public function setDataSource(DataSourceInterface $dataSource)
{
$this->dataSource = $dataSource;
$this->dataSource->initialize($this);
} | php | public function setDataSource(DataSourceInterface $dataSource)
{
$this->dataSource = $dataSource;
$this->dataSource->initialize($this);
} | [
"public",
"function",
"setDataSource",
"(",
"DataSourceInterface",
"$",
"dataSource",
")",
"{",
"$",
"this",
"->",
"dataSource",
"=",
"$",
"dataSource",
";",
"$",
"this",
"->",
"dataSource",
"->",
"initialize",
"(",
"$",
"this",
")",
";",
"}"
] | Set Table data source
@param DataSourceInterface $dataSource DataSource object | [
"Set",
"Table",
"data",
"source"
] | train | https://github.com/atkrad/data-tables/blob/5afcc337ab624ca626e29d9674459c5105982b16/src/Table.php#L101-L105 |
atkrad/data-tables | src/Table.php | Table.addColumn | public function addColumn(Column $column)
{
$this->columns[] = $column;
if ($column instanceof ColumnInterface) {
$column->initialize($this);
}
return $this;
} | php | public function addColumn(Column $column)
{
$this->columns[] = $column;
if ($column instanceof ColumnInterface) {
$column->initialize($this);
}
return $this;
} | [
"public",
"function",
"addColumn",
"(",
"Column",
"$",
"column",
")",
"{",
"$",
"this",
"->",
"columns",
"[",
"]",
"=",
"$",
"column",
";",
"if",
"(",
"$",
"column",
"instanceof",
"ColumnInterface",
")",
"{",
"$",
"column",
"->",
"initialize",
"(",
"$",
"this",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Add column to table
@param \DataTable\Column $column Column object
@return Table | [
"Add",
"column",
"to",
"table"
] | train | https://github.com/atkrad/data-tables/blob/5afcc337ab624ca626e29d9674459c5105982b16/src/Table.php#L161-L170 |
atkrad/data-tables | src/Table.php | Table.getExtension | public function getExtension($propertyName)
{
if (array_key_exists($propertyName, $this->extensions)) {
return $this->extensions[$propertyName];
} else {
return false;
}
} | php | public function getExtension($propertyName)
{
if (array_key_exists($propertyName, $this->extensions)) {
return $this->extensions[$propertyName];
} else {
return false;
}
} | [
"public",
"function",
"getExtension",
"(",
"$",
"propertyName",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"propertyName",
",",
"$",
"this",
"->",
"extensions",
")",
")",
"{",
"return",
"$",
"this",
"->",
"extensions",
"[",
"$",
"propertyName",
"]",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Get extension
@param string $propertyName Extension property name
@return bool|ExtensionInterface | [
"Get",
"extension"
] | train | https://github.com/atkrad/data-tables/blob/5afcc337ab624ca626e29d9674459c5105982b16/src/Table.php#L193-L200 |
atkrad/data-tables | src/Table.php | Table.getResponse | public function getResponse()
{
if (!$this->dataSource instanceof ServerSideInterface) {
throw new Exception('You must call this method when use server side data source.');
}
$response = new Response();
$request = new Request();
$this->dataSource->getResponse($response, $request);
return $response;
} | php | public function getResponse()
{
if (!$this->dataSource instanceof ServerSideInterface) {
throw new Exception('You must call this method when use server side data source.');
}
$response = new Response();
$request = new Request();
$this->dataSource->getResponse($response, $request);
return $response;
} | [
"public",
"function",
"getResponse",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"dataSource",
"instanceof",
"ServerSideInterface",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'You must call this method when use server side data source.'",
")",
";",
"}",
"$",
"response",
"=",
"new",
"Response",
"(",
")",
";",
"$",
"request",
"=",
"new",
"Request",
"(",
")",
";",
"$",
"this",
"->",
"dataSource",
"->",
"getResponse",
"(",
"$",
"response",
",",
"$",
"request",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Get DataTable response
@return Response
@throws Exception | [
"Get",
"DataTable",
"response"
] | train | https://github.com/atkrad/data-tables/blob/5afcc337ab624ca626e29d9674459c5105982b16/src/Table.php#L208-L220 |
atkrad/data-tables | src/Table.php | Table.setAjax | public function setAjax($ajax)
{
if (is_string($ajax)) {
$pattern = '/^(\s+)*(function)(\s+)*\(/i';
if (preg_match($pattern, $ajax, $matches) && strtolower($matches[2]) == 'function') {
$hash = sha1($ajax);
$this->properties['ajax'] = $hash;
$this->callbacks[$hash] = $ajax;
return $this;
}
$this->properties['ajax'] = $ajax;
return $this;
} else {
$this->properties['ajax'] = $ajax;
return $this;
}
} | php | public function setAjax($ajax)
{
if (is_string($ajax)) {
$pattern = '/^(\s+)*(function)(\s+)*\(/i';
if (preg_match($pattern, $ajax, $matches) && strtolower($matches[2]) == 'function') {
$hash = sha1($ajax);
$this->properties['ajax'] = $hash;
$this->callbacks[$hash] = $ajax;
return $this;
}
$this->properties['ajax'] = $ajax;
return $this;
} else {
$this->properties['ajax'] = $ajax;
return $this;
}
} | [
"public",
"function",
"setAjax",
"(",
"$",
"ajax",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"ajax",
")",
")",
"{",
"$",
"pattern",
"=",
"'/^(\\s+)*(function)(\\s+)*\\(/i'",
";",
"if",
"(",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"ajax",
",",
"$",
"matches",
")",
"&&",
"strtolower",
"(",
"$",
"matches",
"[",
"2",
"]",
")",
"==",
"'function'",
")",
"{",
"$",
"hash",
"=",
"sha1",
"(",
"$",
"ajax",
")",
";",
"$",
"this",
"->",
"properties",
"[",
"'ajax'",
"]",
"=",
"$",
"hash",
";",
"$",
"this",
"->",
"callbacks",
"[",
"$",
"hash",
"]",
"=",
"$",
"ajax",
";",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"properties",
"[",
"'ajax'",
"]",
"=",
"$",
"ajax",
";",
"return",
"$",
"this",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"properties",
"[",
"'ajax'",
"]",
"=",
"$",
"ajax",
";",
"return",
"$",
"this",
";",
"}",
"}"
] | DataTables can obtain the data it is to display in the table table's body from a number of sources,
including from an Ajax data source, using this initialisation parameter. As with other dynamic data
sources, arrays or objects can be used for the data source for each row, with columns.dataDT
employed to read from specific object properties.
@param string|object|callback $ajax Load data for the table's content from an Ajax source.
@return Table
@see http://datatables.net/reference/option/ajax | [
"DataTables",
"can",
"obtain",
"the",
"data",
"it",
"is",
"to",
"display",
"in",
"the",
"table",
"table",
"s",
"body",
"from",
"a",
"number",
"of",
"sources",
"including",
"from",
"an",
"Ajax",
"data",
"source",
"using",
"this",
"initialisation",
"parameter",
".",
"As",
"with",
"other",
"dynamic",
"data",
"sources",
"arrays",
"or",
"objects",
"can",
"be",
"used",
"for",
"the",
"data",
"source",
"for",
"each",
"row",
"with",
"columns",
".",
"dataDT",
"employed",
"to",
"read",
"from",
"specific",
"object",
"properties",
"."
] | train | https://github.com/atkrad/data-tables/blob/5afcc337ab624ca626e29d9674459c5105982b16/src/Table.php#L513-L530 |
phpmob/changmin | src/PhpMob/MediaBundle/Form/DataTransformer/ImageTypeTransformer.php | ImageTypeTransformer.reverseTransform | public function reverseTransform($value)
{
if (!$value) {
return null;
}
/** @var ImageType $value */
list($section, $code) = ImageType::reverse($value);
return $this->imageTypeRegistry->getSectionType($section, $code);
} | php | public function reverseTransform($value)
{
if (!$value) {
return null;
}
/** @var ImageType $value */
list($section, $code) = ImageType::reverse($value);
return $this->imageTypeRegistry->getSectionType($section, $code);
} | [
"public",
"function",
"reverseTransform",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"$",
"value",
")",
"{",
"return",
"null",
";",
"}",
"/** @var ImageType $value */",
"list",
"(",
"$",
"section",
",",
"$",
"code",
")",
"=",
"ImageType",
"::",
"reverse",
"(",
"$",
"value",
")",
";",
"return",
"$",
"this",
"->",
"imageTypeRegistry",
"->",
"getSectionType",
"(",
"$",
"section",
",",
"$",
"code",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/phpmob/changmin/blob/bfebb1561229094d1c138574abab75f2f1d17d66/src/PhpMob/MediaBundle/Form/DataTransformer/ImageTypeTransformer.php#L53-L62 |
yuncms/framework | src/user/models/UserSocialAccount.php | UserSocialAccount.findProviderDataByUserId | public static function findProviderDataByUserId($userId, $provider)
{
$weChat = static::findOne(['user_id' => $userId, 'provider' => $provider]);
if ($weChat) {
return $weChat->getDecodedData();
}
return null;
} | php | public static function findProviderDataByUserId($userId, $provider)
{
$weChat = static::findOne(['user_id' => $userId, 'provider' => $provider]);
if ($weChat) {
return $weChat->getDecodedData();
}
return null;
} | [
"public",
"static",
"function",
"findProviderDataByUserId",
"(",
"$",
"userId",
",",
"$",
"provider",
")",
"{",
"$",
"weChat",
"=",
"static",
"::",
"findOne",
"(",
"[",
"'user_id'",
"=>",
"$",
"userId",
",",
"'provider'",
"=>",
"$",
"provider",
"]",
")",
";",
"if",
"(",
"$",
"weChat",
")",
"{",
"return",
"$",
"weChat",
"->",
"getDecodedData",
"(",
")",
";",
"}",
"return",
"null",
";",
"}"
] | 通过用户ID查询用户微信绑定信息
@param int $userId
@param string $provider
@return null|array | [
"通过用户ID查询用户微信绑定信息"
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/user/models/UserSocialAccount.php#L138-L145 |
yuncms/framework | src/user/models/UserSocialAccount.php | UserSocialAccount.fetchAccount | protected static function fetchAccount(BaseClientInterface $client)
{
$account = UserSocialAccount::find()->byClient($client)->one();
if (null === $account) {
$account = Yii::createObject(['class' => static::class, 'provider' => $client->getId(), 'client_id' => $client->getUserAttributes()['id'], 'data' => json_encode($client->getUserAttributes())]);
$account->save(false);
}
return $account;
} | php | protected static function fetchAccount(BaseClientInterface $client)
{
$account = UserSocialAccount::find()->byClient($client)->one();
if (null === $account) {
$account = Yii::createObject(['class' => static::class, 'provider' => $client->getId(), 'client_id' => $client->getUserAttributes()['id'], 'data' => json_encode($client->getUserAttributes())]);
$account->save(false);
}
return $account;
} | [
"protected",
"static",
"function",
"fetchAccount",
"(",
"BaseClientInterface",
"$",
"client",
")",
"{",
"$",
"account",
"=",
"UserSocialAccount",
"::",
"find",
"(",
")",
"->",
"byClient",
"(",
"$",
"client",
")",
"->",
"one",
"(",
")",
";",
"if",
"(",
"null",
"===",
"$",
"account",
")",
"{",
"$",
"account",
"=",
"Yii",
"::",
"createObject",
"(",
"[",
"'class'",
"=>",
"static",
"::",
"class",
",",
"'provider'",
"=>",
"$",
"client",
"->",
"getId",
"(",
")",
",",
"'client_id'",
"=>",
"$",
"client",
"->",
"getUserAttributes",
"(",
")",
"[",
"'id'",
"]",
",",
"'data'",
"=>",
"json_encode",
"(",
"$",
"client",
"->",
"getUserAttributes",
"(",
")",
")",
"]",
")",
";",
"$",
"account",
"->",
"save",
"(",
"false",
")",
";",
"}",
"return",
"$",
"account",
";",
"}"
] | Tries to find account, otherwise creates new account.
@param BaseClientInterface $client
@return UserSocialAccount
@throws \yii\base\InvalidConfigException | [
"Tries",
"to",
"find",
"account",
"otherwise",
"creates",
"new",
"account",
"."
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/user/models/UserSocialAccount.php#L208-L217 |
yuncms/framework | src/user/models/UserSocialAccount.php | UserSocialAccount.fetchUser | protected static function fetchUser(UserSocialAccount $account)
{
$user = User::findByEmail($account->email);
if (null !== $user) {
return $user;
}
/** @var \yuncms\user\models\User $user */
$user = Yii::createObject([
'class' => User::class,
'scenario' => User::SCENARIO_CONNECT,
'nickname' => $account->username,
'email' => $account->email
]);
if (!$user->validate(['email'])) {
$account->email = null;
}
if (!$user->validate(['nickname'])) {
$account->username = null;
}
return $user->createUser() ? $user : false;
} | php | protected static function fetchUser(UserSocialAccount $account)
{
$user = User::findByEmail($account->email);
if (null !== $user) {
return $user;
}
/** @var \yuncms\user\models\User $user */
$user = Yii::createObject([
'class' => User::class,
'scenario' => User::SCENARIO_CONNECT,
'nickname' => $account->username,
'email' => $account->email
]);
if (!$user->validate(['email'])) {
$account->email = null;
}
if (!$user->validate(['nickname'])) {
$account->username = null;
}
return $user->createUser() ? $user : false;
} | [
"protected",
"static",
"function",
"fetchUser",
"(",
"UserSocialAccount",
"$",
"account",
")",
"{",
"$",
"user",
"=",
"User",
"::",
"findByEmail",
"(",
"$",
"account",
"->",
"email",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"user",
")",
"{",
"return",
"$",
"user",
";",
"}",
"/** @var \\yuncms\\user\\models\\User $user */",
"$",
"user",
"=",
"Yii",
"::",
"createObject",
"(",
"[",
"'class'",
"=>",
"User",
"::",
"class",
",",
"'scenario'",
"=>",
"User",
"::",
"SCENARIO_CONNECT",
",",
"'nickname'",
"=>",
"$",
"account",
"->",
"username",
",",
"'email'",
"=>",
"$",
"account",
"->",
"email",
"]",
")",
";",
"if",
"(",
"!",
"$",
"user",
"->",
"validate",
"(",
"[",
"'email'",
"]",
")",
")",
"{",
"$",
"account",
"->",
"email",
"=",
"null",
";",
"}",
"if",
"(",
"!",
"$",
"user",
"->",
"validate",
"(",
"[",
"'nickname'",
"]",
")",
")",
"{",
"$",
"account",
"->",
"username",
"=",
"null",
";",
"}",
"return",
"$",
"user",
"->",
"createUser",
"(",
")",
"?",
"$",
"user",
":",
"false",
";",
"}"
] | Tries to find user or create a new one.
@param UserSocialAccount $account
@return User|boolean False when can't create user.
@throws \yii\base\InvalidConfigException | [
"Tries",
"to",
"find",
"user",
"or",
"create",
"a",
"new",
"one",
"."
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/user/models/UserSocialAccount.php#L227-L249 |
silvercommerce/catalogue-frontend | src/extensions/ProductTagExtension.php | ProductTagExtension.isCurrent | public function isCurrent()
{
$request = Injector::inst()->get(HTTPRequest::class);
$tag = $request->getVar("t");
return ($tag == $this->owner->URLSegment);
} | php | public function isCurrent()
{
$request = Injector::inst()->get(HTTPRequest::class);
$tag = $request->getVar("t");
return ($tag == $this->owner->URLSegment);
} | [
"public",
"function",
"isCurrent",
"(",
")",
"{",
"$",
"request",
"=",
"Injector",
"::",
"inst",
"(",
")",
"->",
"get",
"(",
"HTTPRequest",
"::",
"class",
")",
";",
"$",
"tag",
"=",
"$",
"request",
"->",
"getVar",
"(",
"\"t\"",
")",
";",
"return",
"(",
"$",
"tag",
"==",
"$",
"this",
"->",
"owner",
"->",
"URLSegment",
")",
";",
"}"
] | Returns true if this is the currently active page being used to handle this request.
@return bool | [
"Returns",
"true",
"if",
"this",
"is",
"the",
"currently",
"active",
"page",
"being",
"used",
"to",
"handle",
"this",
"request",
"."
] | train | https://github.com/silvercommerce/catalogue-frontend/blob/671f1e32bf6bc6eb193c6608ae904cd055540cc4/src/extensions/ProductTagExtension.php#L20-L26 |
fsi-open/doctrine-extensions-bundle | DependencyInjection/Configuration.php | Configuration.getConfigTreeBuilder | public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('fsi_doctrine_extensions');
$rootNode
->children()
->append($this->getVendorNode('orm'))
->append($this->getFilesystemsNode())
->scalarNode('default_locale')->defaultValue('%locale%')->end()
->scalarNode('default_key_maker_service')->defaultValue('fsi_doctrine_extensions.default.key_maker')->end()
->scalarNode('default_filesystem_prefix')->defaultValue('uploaded')->end()
->scalarNode('default_filesystem_base_url')->defaultValue('/uploaded')->end()
->scalarNode('default_filesystem_path')->defaultValue('%kernel.root_dir%/../web/uploaded')->end()
->scalarNode('default_filesystem_service')->defaultValue('fsi_doctrine_extensions.default.filesystem')->end()
->arrayNode('uploadable_configuration')
->useAttributeAsKey('class')
->prototype('array')
->children()
->scalarNode('class')->end()
->arrayNode('configuration')
->useAttributeAsKey('property')
->prototype('array')
->children()
->scalarNode('property')->end()
->scalarNode('filesystem')->end()
->scalarNode('keymaker')->end()
->end()
->end()
->end()
->end()
->end();
return $treeBuilder;
} | php | public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('fsi_doctrine_extensions');
$rootNode
->children()
->append($this->getVendorNode('orm'))
->append($this->getFilesystemsNode())
->scalarNode('default_locale')->defaultValue('%locale%')->end()
->scalarNode('default_key_maker_service')->defaultValue('fsi_doctrine_extensions.default.key_maker')->end()
->scalarNode('default_filesystem_prefix')->defaultValue('uploaded')->end()
->scalarNode('default_filesystem_base_url')->defaultValue('/uploaded')->end()
->scalarNode('default_filesystem_path')->defaultValue('%kernel.root_dir%/../web/uploaded')->end()
->scalarNode('default_filesystem_service')->defaultValue('fsi_doctrine_extensions.default.filesystem')->end()
->arrayNode('uploadable_configuration')
->useAttributeAsKey('class')
->prototype('array')
->children()
->scalarNode('class')->end()
->arrayNode('configuration')
->useAttributeAsKey('property')
->prototype('array')
->children()
->scalarNode('property')->end()
->scalarNode('filesystem')->end()
->scalarNode('keymaker')->end()
->end()
->end()
->end()
->end()
->end();
return $treeBuilder;
} | [
"public",
"function",
"getConfigTreeBuilder",
"(",
")",
"{",
"$",
"treeBuilder",
"=",
"new",
"TreeBuilder",
"(",
")",
";",
"$",
"rootNode",
"=",
"$",
"treeBuilder",
"->",
"root",
"(",
"'fsi_doctrine_extensions'",
")",
";",
"$",
"rootNode",
"->",
"children",
"(",
")",
"->",
"append",
"(",
"$",
"this",
"->",
"getVendorNode",
"(",
"'orm'",
")",
")",
"->",
"append",
"(",
"$",
"this",
"->",
"getFilesystemsNode",
"(",
")",
")",
"->",
"scalarNode",
"(",
"'default_locale'",
")",
"->",
"defaultValue",
"(",
"'%locale%'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'default_key_maker_service'",
")",
"->",
"defaultValue",
"(",
"'fsi_doctrine_extensions.default.key_maker'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'default_filesystem_prefix'",
")",
"->",
"defaultValue",
"(",
"'uploaded'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'default_filesystem_base_url'",
")",
"->",
"defaultValue",
"(",
"'/uploaded'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'default_filesystem_path'",
")",
"->",
"defaultValue",
"(",
"'%kernel.root_dir%/../web/uploaded'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'default_filesystem_service'",
")",
"->",
"defaultValue",
"(",
"'fsi_doctrine_extensions.default.filesystem'",
")",
"->",
"end",
"(",
")",
"->",
"arrayNode",
"(",
"'uploadable_configuration'",
")",
"->",
"useAttributeAsKey",
"(",
"'class'",
")",
"->",
"prototype",
"(",
"'array'",
")",
"->",
"children",
"(",
")",
"->",
"scalarNode",
"(",
"'class'",
")",
"->",
"end",
"(",
")",
"->",
"arrayNode",
"(",
"'configuration'",
")",
"->",
"useAttributeAsKey",
"(",
"'property'",
")",
"->",
"prototype",
"(",
"'array'",
")",
"->",
"children",
"(",
")",
"->",
"scalarNode",
"(",
"'property'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'filesystem'",
")",
"->",
"end",
"(",
")",
"->",
"scalarNode",
"(",
"'keymaker'",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
"->",
"end",
"(",
")",
";",
"return",
"$",
"treeBuilder",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/fsi-open/doctrine-extensions-bundle/blob/1b9c01e0b216b2c1b2af087de233abbf3c84b9fe/DependencyInjection/Configuration.php#L22-L56 |
freyo/flysystem-qcloud-cos-v3 | src/Client/Http.php | Http.send | public static function send($rq)
{
if (self::$_curlHandler) {
if (function_exists('curl_reset')) {
curl_reset(self::$_curlHandler);
} else {
my_curl_reset(self::$_curlHandler);
}
} else {
self::$_curlHandler = curl_init();
}
curl_setopt(self::$_curlHandler, CURLOPT_URL, $rq['url']);
switch (true) {
case isset($rq['method']) && in_array(strtolower($rq['method']), ['get', 'post', 'put', 'delete', 'head']):
$method = strtoupper($rq['method']);
break;
case isset($rq['data']):
$method = 'POST';
break;
default:
$method = 'GET';
}
$header = isset($rq['header']) ? $rq['header'] : [];
$header[] = 'Method:'.$method;
$header[] = 'User-Agent:'.Conf::getUA();
$header[] = 'Connection: keep-alive';
if ('POST' == $method) {
$header[] = 'Expect: ';
}
isset($rq['host']) && $header[] = 'Host:'.$rq['host'];
curl_setopt(self::$_curlHandler, CURLOPT_HTTPHEADER, $header);
curl_setopt(self::$_curlHandler, CURLOPT_RETURNTRANSFER, 1);
curl_setopt(self::$_curlHandler, CURLOPT_CUSTOMREQUEST, $method);
isset($rq['timeout']) && curl_setopt(self::$_curlHandler, CURLOPT_TIMEOUT, $rq['timeout']);
isset($rq['data']) && in_array($method, ['POST', 'PUT']) && curl_setopt(self::$_curlHandler, CURLOPT_POSTFIELDS, $rq['data']);
$ssl = substr($rq['url'], 0, 8) == 'https://' ? true : false;
if (isset($rq['cert'])) {
curl_setopt(self::$_curlHandler, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt(self::$_curlHandler, CURLOPT_CAINFO, $rq['cert']);
curl_setopt(self::$_curlHandler, CURLOPT_SSL_VERIFYHOST, 2);
self::setCurlSSLVersion($rq);
} elseif ($ssl) {
curl_setopt(self::$_curlHandler, CURLOPT_SSL_VERIFYPEER, false); //true any ca
curl_setopt(self::$_curlHandler, CURLOPT_SSL_VERIFYHOST, 0); //not check the names
self::setCurlSSLVersion($rq);
}
$ret = curl_exec(self::$_curlHandler);
self::$_httpInfo = curl_getinfo(self::$_curlHandler);
return $ret;
} | php | public static function send($rq)
{
if (self::$_curlHandler) {
if (function_exists('curl_reset')) {
curl_reset(self::$_curlHandler);
} else {
my_curl_reset(self::$_curlHandler);
}
} else {
self::$_curlHandler = curl_init();
}
curl_setopt(self::$_curlHandler, CURLOPT_URL, $rq['url']);
switch (true) {
case isset($rq['method']) && in_array(strtolower($rq['method']), ['get', 'post', 'put', 'delete', 'head']):
$method = strtoupper($rq['method']);
break;
case isset($rq['data']):
$method = 'POST';
break;
default:
$method = 'GET';
}
$header = isset($rq['header']) ? $rq['header'] : [];
$header[] = 'Method:'.$method;
$header[] = 'User-Agent:'.Conf::getUA();
$header[] = 'Connection: keep-alive';
if ('POST' == $method) {
$header[] = 'Expect: ';
}
isset($rq['host']) && $header[] = 'Host:'.$rq['host'];
curl_setopt(self::$_curlHandler, CURLOPT_HTTPHEADER, $header);
curl_setopt(self::$_curlHandler, CURLOPT_RETURNTRANSFER, 1);
curl_setopt(self::$_curlHandler, CURLOPT_CUSTOMREQUEST, $method);
isset($rq['timeout']) && curl_setopt(self::$_curlHandler, CURLOPT_TIMEOUT, $rq['timeout']);
isset($rq['data']) && in_array($method, ['POST', 'PUT']) && curl_setopt(self::$_curlHandler, CURLOPT_POSTFIELDS, $rq['data']);
$ssl = substr($rq['url'], 0, 8) == 'https://' ? true : false;
if (isset($rq['cert'])) {
curl_setopt(self::$_curlHandler, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt(self::$_curlHandler, CURLOPT_CAINFO, $rq['cert']);
curl_setopt(self::$_curlHandler, CURLOPT_SSL_VERIFYHOST, 2);
self::setCurlSSLVersion($rq);
} elseif ($ssl) {
curl_setopt(self::$_curlHandler, CURLOPT_SSL_VERIFYPEER, false); //true any ca
curl_setopt(self::$_curlHandler, CURLOPT_SSL_VERIFYHOST, 0); //not check the names
self::setCurlSSLVersion($rq);
}
$ret = curl_exec(self::$_curlHandler);
self::$_httpInfo = curl_getinfo(self::$_curlHandler);
return $ret;
} | [
"public",
"static",
"function",
"send",
"(",
"$",
"rq",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"_curlHandler",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'curl_reset'",
")",
")",
"{",
"curl_reset",
"(",
"self",
"::",
"$",
"_curlHandler",
")",
";",
"}",
"else",
"{",
"my_curl_reset",
"(",
"self",
"::",
"$",
"_curlHandler",
")",
";",
"}",
"}",
"else",
"{",
"self",
"::",
"$",
"_curlHandler",
"=",
"curl_init",
"(",
")",
";",
"}",
"curl_setopt",
"(",
"self",
"::",
"$",
"_curlHandler",
",",
"CURLOPT_URL",
",",
"$",
"rq",
"[",
"'url'",
"]",
")",
";",
"switch",
"(",
"true",
")",
"{",
"case",
"isset",
"(",
"$",
"rq",
"[",
"'method'",
"]",
")",
"&&",
"in_array",
"(",
"strtolower",
"(",
"$",
"rq",
"[",
"'method'",
"]",
")",
",",
"[",
"'get'",
",",
"'post'",
",",
"'put'",
",",
"'delete'",
",",
"'head'",
"]",
")",
":",
"$",
"method",
"=",
"strtoupper",
"(",
"$",
"rq",
"[",
"'method'",
"]",
")",
";",
"break",
";",
"case",
"isset",
"(",
"$",
"rq",
"[",
"'data'",
"]",
")",
":",
"$",
"method",
"=",
"'POST'",
";",
"break",
";",
"default",
":",
"$",
"method",
"=",
"'GET'",
";",
"}",
"$",
"header",
"=",
"isset",
"(",
"$",
"rq",
"[",
"'header'",
"]",
")",
"?",
"$",
"rq",
"[",
"'header'",
"]",
":",
"[",
"]",
";",
"$",
"header",
"[",
"]",
"=",
"'Method:'",
".",
"$",
"method",
";",
"$",
"header",
"[",
"]",
"=",
"'User-Agent:'",
".",
"Conf",
"::",
"getUA",
"(",
")",
";",
"$",
"header",
"[",
"]",
"=",
"'Connection: keep-alive'",
";",
"if",
"(",
"'POST'",
"==",
"$",
"method",
")",
"{",
"$",
"header",
"[",
"]",
"=",
"'Expect: '",
";",
"}",
"isset",
"(",
"$",
"rq",
"[",
"'host'",
"]",
")",
"&&",
"$",
"header",
"[",
"]",
"=",
"'Host:'",
".",
"$",
"rq",
"[",
"'host'",
"]",
";",
"curl_setopt",
"(",
"self",
"::",
"$",
"_curlHandler",
",",
"CURLOPT_HTTPHEADER",
",",
"$",
"header",
")",
";",
"curl_setopt",
"(",
"self",
"::",
"$",
"_curlHandler",
",",
"CURLOPT_RETURNTRANSFER",
",",
"1",
")",
";",
"curl_setopt",
"(",
"self",
"::",
"$",
"_curlHandler",
",",
"CURLOPT_CUSTOMREQUEST",
",",
"$",
"method",
")",
";",
"isset",
"(",
"$",
"rq",
"[",
"'timeout'",
"]",
")",
"&&",
"curl_setopt",
"(",
"self",
"::",
"$",
"_curlHandler",
",",
"CURLOPT_TIMEOUT",
",",
"$",
"rq",
"[",
"'timeout'",
"]",
")",
";",
"isset",
"(",
"$",
"rq",
"[",
"'data'",
"]",
")",
"&&",
"in_array",
"(",
"$",
"method",
",",
"[",
"'POST'",
",",
"'PUT'",
"]",
")",
"&&",
"curl_setopt",
"(",
"self",
"::",
"$",
"_curlHandler",
",",
"CURLOPT_POSTFIELDS",
",",
"$",
"rq",
"[",
"'data'",
"]",
")",
";",
"$",
"ssl",
"=",
"substr",
"(",
"$",
"rq",
"[",
"'url'",
"]",
",",
"0",
",",
"8",
")",
"==",
"'https://'",
"?",
"true",
":",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"rq",
"[",
"'cert'",
"]",
")",
")",
"{",
"curl_setopt",
"(",
"self",
"::",
"$",
"_curlHandler",
",",
"CURLOPT_SSL_VERIFYPEER",
",",
"true",
")",
";",
"curl_setopt",
"(",
"self",
"::",
"$",
"_curlHandler",
",",
"CURLOPT_CAINFO",
",",
"$",
"rq",
"[",
"'cert'",
"]",
")",
";",
"curl_setopt",
"(",
"self",
"::",
"$",
"_curlHandler",
",",
"CURLOPT_SSL_VERIFYHOST",
",",
"2",
")",
";",
"self",
"::",
"setCurlSSLVersion",
"(",
"$",
"rq",
")",
";",
"}",
"elseif",
"(",
"$",
"ssl",
")",
"{",
"curl_setopt",
"(",
"self",
"::",
"$",
"_curlHandler",
",",
"CURLOPT_SSL_VERIFYPEER",
",",
"false",
")",
";",
"//true any ca",
"curl_setopt",
"(",
"self",
"::",
"$",
"_curlHandler",
",",
"CURLOPT_SSL_VERIFYHOST",
",",
"0",
")",
";",
"//not check the names",
"self",
"::",
"setCurlSSLVersion",
"(",
"$",
"rq",
")",
";",
"}",
"$",
"ret",
"=",
"curl_exec",
"(",
"self",
"::",
"$",
"_curlHandler",
")",
";",
"self",
"::",
"$",
"_httpInfo",
"=",
"curl_getinfo",
"(",
"self",
"::",
"$",
"_curlHandler",
")",
";",
"return",
"$",
"ret",
";",
"}"
] | send http request.
@param array $rq http请求信息
url : 请求的url地址
method : 请求方法,'get', 'post', 'put', 'delete', 'head'
data : 请求数据,如有设置,则method为post
header : 需要设置的http头部
host : 请求头部host
timeout : 请求超时时间
cert : ca文件路径
ssl_version: SSL版本号
@return string http请求响应 | [
"send",
"http",
"request",
"."
] | train | https://github.com/freyo/flysystem-qcloud-cos-v3/blob/6bddbc22396aa1228942ec4c0ce46935d415f3b4/src/Client/Http.php#L34-L85 |
praxisnetau/silverware-spam-guard | src/Extensions/UserFormExtension.php | UserFormExtension.updateForm | public function updateForm()
{
if ($userDefinedForm = $this->owner->getController()->data()) {
if ($userDefinedForm->EnableSpamGuard) {
$this->owner->enableSpamProtection();
}
}
} | php | public function updateForm()
{
if ($userDefinedForm = $this->owner->getController()->data()) {
if ($userDefinedForm->EnableSpamGuard) {
$this->owner->enableSpamProtection();
}
}
} | [
"public",
"function",
"updateForm",
"(",
")",
"{",
"if",
"(",
"$",
"userDefinedForm",
"=",
"$",
"this",
"->",
"owner",
"->",
"getController",
"(",
")",
"->",
"data",
"(",
")",
")",
"{",
"if",
"(",
"$",
"userDefinedForm",
"->",
"EnableSpamGuard",
")",
"{",
"$",
"this",
"->",
"owner",
"->",
"enableSpamProtection",
"(",
")",
";",
"}",
"}",
"}"
] | Updates the extended user form instance.
@return void | [
"Updates",
"the",
"extended",
"user",
"form",
"instance",
"."
] | train | https://github.com/praxisnetau/silverware-spam-guard/blob/c5f8836a09141bd675173892a1e3d8c8cc8c1886/src/Extensions/UserFormExtension.php#L38-L47 |
picamator/CacheManager | src/Data/SearchResultFactory.php | SearchResultFactory.create | public function create(array $data, array $missedData) : SearchResultInterface
{
return $this->objectManager->create($this->className, [$data, $missedData]);
} | php | public function create(array $data, array $missedData) : SearchResultInterface
{
return $this->objectManager->create($this->className, [$data, $missedData]);
} | [
"public",
"function",
"create",
"(",
"array",
"$",
"data",
",",
"array",
"$",
"missedData",
")",
":",
"SearchResultInterface",
"{",
"return",
"$",
"this",
"->",
"objectManager",
"->",
"create",
"(",
"$",
"this",
"->",
"className",
",",
"[",
"$",
"data",
",",
"$",
"missedData",
"]",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/picamator/CacheManager/blob/5e5493910610b65ae31a362786d7963ba3e33806/src/Data/SearchResultFactory.php#L43-L46 |
transfer-framework/ezplatform | src/Transfer/EzPlatform/Repository/Values/Mapper/ContentMapper.php | ContentMapper.mapObjectToCreateStruct | public function mapObjectToCreateStruct(ContentCreateStruct $createStruct)
{
// Name collection (ez => transfer)
$keys = array(
'mainLanguageCode' => 'main_language_code',
'remoteId' => 'remote_id',
);
$this->arrayToStruct($createStruct, $keys);
$this->assignStructFieldValues($createStruct);
$this->callStruct($createStruct);
} | php | public function mapObjectToCreateStruct(ContentCreateStruct $createStruct)
{
// Name collection (ez => transfer)
$keys = array(
'mainLanguageCode' => 'main_language_code',
'remoteId' => 'remote_id',
);
$this->arrayToStruct($createStruct, $keys);
$this->assignStructFieldValues($createStruct);
$this->callStruct($createStruct);
} | [
"public",
"function",
"mapObjectToCreateStruct",
"(",
"ContentCreateStruct",
"$",
"createStruct",
")",
"{",
"// Name collection (ez => transfer)",
"$",
"keys",
"=",
"array",
"(",
"'mainLanguageCode'",
"=>",
"'main_language_code'",
",",
"'remoteId'",
"=>",
"'remote_id'",
",",
")",
";",
"$",
"this",
"->",
"arrayToStruct",
"(",
"$",
"createStruct",
",",
"$",
"keys",
")",
";",
"$",
"this",
"->",
"assignStructFieldValues",
"(",
"$",
"createStruct",
")",
";",
"$",
"this",
"->",
"callStruct",
"(",
"$",
"createStruct",
")",
";",
"}"
] | @param ContentCreateStruct $createStruct
@throws \InvalidArgumentException | [
"@param",
"ContentCreateStruct",
"$createStruct"
] | train | https://github.com/transfer-framework/ezplatform/blob/1b2d87caa1a6b79fd8fc78109c26a2d1d6359c2f/src/Transfer/EzPlatform/Repository/Values/Mapper/ContentMapper.php#L56-L69 |
sparwelt/imgix-lib | src/Components/ImageTransformer.php | ImageTransformer.transformImage | public function transformImage($originalImageHtml, array $attributesFilters = [])
{
$dom = new \DOMDocument();
// mute "htmlParseEntityRef: no name in Entity" warning generated by & and &
@$dom->loadHTML('<?xml encoding="utf-8"?>'.$originalImageHtml);
if (0 === $dom->getElementsByTagName('img')->length) {
throw new TransformationException(sprintf('Unable to parse img element: %s', $originalImageHtml));
}
$image = $dom->getElementsByTagName('img')->item(0);
// apply the specified filters
$originalImageUrl = $image->hasAttribute('src') ? trim($image->getAttribute('src')) : null;
$processedAttributes = [];
if (!empty($originalImageUrl) && false === strpos($originalImageUrl, 'data:image/')) {
try {
$elementFilters = $attributesFilters;
// consider html 'width' and 'height' attributes for filter generation
if (isset($elementFilters['src']) && is_array($elementFilters['src'])) {
if ($image->hasAttribute('width') && '' !== $image->getAttribute('width')) {
$elementFilters['src']['w'] = $image->getAttribute('width');
}
if ($image->hasAttribute('height') && '' !== $image->getAttribute('height')) {
$elementFilters['src']['h'] = $image->getAttribute('height');
}
}
foreach ($elementFilters as $attributeName => $filters) {
$attributeValue = $this->attributeGenerator->generateAttributeValue($originalImageUrl, $filters);
if ('' !== $attributeValue) {
$image->setAttribute($attributeName, $attributeValue);
$processedAttributes[] = $attributeName;
}
}
} catch (ResolutionException $e) {
}
}
// apply the cdn domain on the remaining attributes
foreach ($image->attributes as $attribute) {
if (!in_array($attribute->name, $processedAttributes)) {
$this->applyCdnDomain($attribute);
}
}
return $this->renderer->render($image);
} | php | public function transformImage($originalImageHtml, array $attributesFilters = [])
{
$dom = new \DOMDocument();
// mute "htmlParseEntityRef: no name in Entity" warning generated by & and &
@$dom->loadHTML('<?xml encoding="utf-8"?>'.$originalImageHtml);
if (0 === $dom->getElementsByTagName('img')->length) {
throw new TransformationException(sprintf('Unable to parse img element: %s', $originalImageHtml));
}
$image = $dom->getElementsByTagName('img')->item(0);
// apply the specified filters
$originalImageUrl = $image->hasAttribute('src') ? trim($image->getAttribute('src')) : null;
$processedAttributes = [];
if (!empty($originalImageUrl) && false === strpos($originalImageUrl, 'data:image/')) {
try {
$elementFilters = $attributesFilters;
// consider html 'width' and 'height' attributes for filter generation
if (isset($elementFilters['src']) && is_array($elementFilters['src'])) {
if ($image->hasAttribute('width') && '' !== $image->getAttribute('width')) {
$elementFilters['src']['w'] = $image->getAttribute('width');
}
if ($image->hasAttribute('height') && '' !== $image->getAttribute('height')) {
$elementFilters['src']['h'] = $image->getAttribute('height');
}
}
foreach ($elementFilters as $attributeName => $filters) {
$attributeValue = $this->attributeGenerator->generateAttributeValue($originalImageUrl, $filters);
if ('' !== $attributeValue) {
$image->setAttribute($attributeName, $attributeValue);
$processedAttributes[] = $attributeName;
}
}
} catch (ResolutionException $e) {
}
}
// apply the cdn domain on the remaining attributes
foreach ($image->attributes as $attribute) {
if (!in_array($attribute->name, $processedAttributes)) {
$this->applyCdnDomain($attribute);
}
}
return $this->renderer->render($image);
} | [
"public",
"function",
"transformImage",
"(",
"$",
"originalImageHtml",
",",
"array",
"$",
"attributesFilters",
"=",
"[",
"]",
")",
"{",
"$",
"dom",
"=",
"new",
"\\",
"DOMDocument",
"(",
")",
";",
"// mute \"htmlParseEntityRef: no name in Entity\" warning generated by & and &",
"@",
"$",
"dom",
"->",
"loadHTML",
"(",
"'<?xml encoding=\"utf-8\"?>'",
".",
"$",
"originalImageHtml",
")",
";",
"if",
"(",
"0",
"===",
"$",
"dom",
"->",
"getElementsByTagName",
"(",
"'img'",
")",
"->",
"length",
")",
"{",
"throw",
"new",
"TransformationException",
"(",
"sprintf",
"(",
"'Unable to parse img element: %s'",
",",
"$",
"originalImageHtml",
")",
")",
";",
"}",
"$",
"image",
"=",
"$",
"dom",
"->",
"getElementsByTagName",
"(",
"'img'",
")",
"->",
"item",
"(",
"0",
")",
";",
"// apply the specified filters",
"$",
"originalImageUrl",
"=",
"$",
"image",
"->",
"hasAttribute",
"(",
"'src'",
")",
"?",
"trim",
"(",
"$",
"image",
"->",
"getAttribute",
"(",
"'src'",
")",
")",
":",
"null",
";",
"$",
"processedAttributes",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"originalImageUrl",
")",
"&&",
"false",
"===",
"strpos",
"(",
"$",
"originalImageUrl",
",",
"'data:image/'",
")",
")",
"{",
"try",
"{",
"$",
"elementFilters",
"=",
"$",
"attributesFilters",
";",
"// consider html 'width' and 'height' attributes for filter generation",
"if",
"(",
"isset",
"(",
"$",
"elementFilters",
"[",
"'src'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"elementFilters",
"[",
"'src'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"image",
"->",
"hasAttribute",
"(",
"'width'",
")",
"&&",
"''",
"!==",
"$",
"image",
"->",
"getAttribute",
"(",
"'width'",
")",
")",
"{",
"$",
"elementFilters",
"[",
"'src'",
"]",
"[",
"'w'",
"]",
"=",
"$",
"image",
"->",
"getAttribute",
"(",
"'width'",
")",
";",
"}",
"if",
"(",
"$",
"image",
"->",
"hasAttribute",
"(",
"'height'",
")",
"&&",
"''",
"!==",
"$",
"image",
"->",
"getAttribute",
"(",
"'height'",
")",
")",
"{",
"$",
"elementFilters",
"[",
"'src'",
"]",
"[",
"'h'",
"]",
"=",
"$",
"image",
"->",
"getAttribute",
"(",
"'height'",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"elementFilters",
"as",
"$",
"attributeName",
"=>",
"$",
"filters",
")",
"{",
"$",
"attributeValue",
"=",
"$",
"this",
"->",
"attributeGenerator",
"->",
"generateAttributeValue",
"(",
"$",
"originalImageUrl",
",",
"$",
"filters",
")",
";",
"if",
"(",
"''",
"!==",
"$",
"attributeValue",
")",
"{",
"$",
"image",
"->",
"setAttribute",
"(",
"$",
"attributeName",
",",
"$",
"attributeValue",
")",
";",
"$",
"processedAttributes",
"[",
"]",
"=",
"$",
"attributeName",
";",
"}",
"}",
"}",
"catch",
"(",
"ResolutionException",
"$",
"e",
")",
"{",
"}",
"}",
"// apply the cdn domain on the remaining attributes",
"foreach",
"(",
"$",
"image",
"->",
"attributes",
"as",
"$",
"attribute",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"attribute",
"->",
"name",
",",
"$",
"processedAttributes",
")",
")",
"{",
"$",
"this",
"->",
"applyCdnDomain",
"(",
"$",
"attribute",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"renderer",
"->",
"render",
"(",
"$",
"image",
")",
";",
"}"
] | @param string $originalImageHtml
@param array $attributesFilters
@return \DOMElement|string
@throws \Sparwelt\ImgixLib\Exception\TransformationException | [
"@param",
"string",
"$originalImageHtml",
"@param",
"array",
"$attributesFilters"
] | train | https://github.com/sparwelt/imgix-lib/blob/330e1db2bed71bc283e5a2da6246528f240939ec/src/Components/ImageTransformer.php#L42-L90 |
yuncms/framework | src/sms/captcha/Captcha.php | Captcha.run | public function run()
{
if ($this->hasModel()) {
$input = Html::activeTextInput($this->model, $this->attribute, $this->options);
$this->mobileField = Html::getInputId($this->model,$this->mobileField);
} else {
$input = Html::textInput($this->name, $this->value, $this->options);
$this->mobileField = $this->name;
}
$button = Html::button(Yii::t('yuncms', 'Get Verify Code'), $this->buttonOptions);
$this->registerClientScript();
echo strtr($this->template, [
'{input}' => $input,
'{button}' => $button,
]);
} | php | public function run()
{
if ($this->hasModel()) {
$input = Html::activeTextInput($this->model, $this->attribute, $this->options);
$this->mobileField = Html::getInputId($this->model,$this->mobileField);
} else {
$input = Html::textInput($this->name, $this->value, $this->options);
$this->mobileField = $this->name;
}
$button = Html::button(Yii::t('yuncms', 'Get Verify Code'), $this->buttonOptions);
$this->registerClientScript();
echo strtr($this->template, [
'{input}' => $input,
'{button}' => $button,
]);
} | [
"public",
"function",
"run",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasModel",
"(",
")",
")",
"{",
"$",
"input",
"=",
"Html",
"::",
"activeTextInput",
"(",
"$",
"this",
"->",
"model",
",",
"$",
"this",
"->",
"attribute",
",",
"$",
"this",
"->",
"options",
")",
";",
"$",
"this",
"->",
"mobileField",
"=",
"Html",
"::",
"getInputId",
"(",
"$",
"this",
"->",
"model",
",",
"$",
"this",
"->",
"mobileField",
")",
";",
"}",
"else",
"{",
"$",
"input",
"=",
"Html",
"::",
"textInput",
"(",
"$",
"this",
"->",
"name",
",",
"$",
"this",
"->",
"value",
",",
"$",
"this",
"->",
"options",
")",
";",
"$",
"this",
"->",
"mobileField",
"=",
"$",
"this",
"->",
"name",
";",
"}",
"$",
"button",
"=",
"Html",
"::",
"button",
"(",
"Yii",
"::",
"t",
"(",
"'yuncms'",
",",
"'Get Verify Code'",
")",
",",
"$",
"this",
"->",
"buttonOptions",
")",
";",
"$",
"this",
"->",
"registerClientScript",
"(",
")",
";",
"echo",
"strtr",
"(",
"$",
"this",
"->",
"template",
",",
"[",
"'{input}'",
"=>",
"$",
"input",
",",
"'{button}'",
"=>",
"$",
"button",
",",
"]",
")",
";",
"}"
] | Renders the widget. | [
"Renders",
"the",
"widget",
"."
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/sms/captcha/Captcha.php#L115-L131 |
yuncms/framework | src/sms/captcha/Captcha.php | Captcha.registerClientScript | public function registerClientScript()
{
$this->clientOptions = array_merge([
'refreshUrl' => Url::toRoute($this->captchaAction),
'hashKey'=> 'yiiSmsCaptcha/' . trim($this->captchaAction, '/'),
'mobileField' => $this->mobileField,
'buttonTime' => Yii::t('yuncms', 'Resend after @second@ seconds'),
'buttonGet'=>Yii::t('yuncms', 'Get Verify Code'),
], $this->clientOptions);
$options = empty ($this->clientOptions) ? '' : Json::htmlEncode($this->clientOptions);
$id = $this->buttonOptions['id'];
$view = $this->getView();
CaptchaAsset::register($view);
$view->registerJs("\r\njQuery('#$id').yiiSmsCaptcha($options);\r\n");
} | php | public function registerClientScript()
{
$this->clientOptions = array_merge([
'refreshUrl' => Url::toRoute($this->captchaAction),
'hashKey'=> 'yiiSmsCaptcha/' . trim($this->captchaAction, '/'),
'mobileField' => $this->mobileField,
'buttonTime' => Yii::t('yuncms', 'Resend after @second@ seconds'),
'buttonGet'=>Yii::t('yuncms', 'Get Verify Code'),
], $this->clientOptions);
$options = empty ($this->clientOptions) ? '' : Json::htmlEncode($this->clientOptions);
$id = $this->buttonOptions['id'];
$view = $this->getView();
CaptchaAsset::register($view);
$view->registerJs("\r\njQuery('#$id').yiiSmsCaptcha($options);\r\n");
} | [
"public",
"function",
"registerClientScript",
"(",
")",
"{",
"$",
"this",
"->",
"clientOptions",
"=",
"array_merge",
"(",
"[",
"'refreshUrl'",
"=>",
"Url",
"::",
"toRoute",
"(",
"$",
"this",
"->",
"captchaAction",
")",
",",
"'hashKey'",
"=>",
"'yiiSmsCaptcha/'",
".",
"trim",
"(",
"$",
"this",
"->",
"captchaAction",
",",
"'/'",
")",
",",
"'mobileField'",
"=>",
"$",
"this",
"->",
"mobileField",
",",
"'buttonTime'",
"=>",
"Yii",
"::",
"t",
"(",
"'yuncms'",
",",
"'Resend after @second@ seconds'",
")",
",",
"'buttonGet'",
"=>",
"Yii",
"::",
"t",
"(",
"'yuncms'",
",",
"'Get Verify Code'",
")",
",",
"]",
",",
"$",
"this",
"->",
"clientOptions",
")",
";",
"$",
"options",
"=",
"empty",
"(",
"$",
"this",
"->",
"clientOptions",
")",
"?",
"''",
":",
"Json",
"::",
"htmlEncode",
"(",
"$",
"this",
"->",
"clientOptions",
")",
";",
"$",
"id",
"=",
"$",
"this",
"->",
"buttonOptions",
"[",
"'id'",
"]",
";",
"$",
"view",
"=",
"$",
"this",
"->",
"getView",
"(",
")",
";",
"CaptchaAsset",
"::",
"register",
"(",
"$",
"view",
")",
";",
"$",
"view",
"->",
"registerJs",
"(",
"\"\\r\\njQuery('#$id').yiiSmsCaptcha($options);\\r\\n\"",
")",
";",
"}"
] | Registers the needed JavaScript. | [
"Registers",
"the",
"needed",
"JavaScript",
"."
] | train | https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/sms/captcha/Captcha.php#L136-L150 |
narrowspark/http-status | src/HttpStatus.php | HttpStatus.getReasonMessage | public static function getReasonMessage(int $code): string
{
$code = static::filterStatusCode($code);
if (! isset(self::$errorPhrases[$code])) {
throw new OutOfBoundsException(\sprintf('Unknown http status code: `%s`.', $code));
}
return self::$errorPhrases[$code];
} | php | public static function getReasonMessage(int $code): string
{
$code = static::filterStatusCode($code);
if (! isset(self::$errorPhrases[$code])) {
throw new OutOfBoundsException(\sprintf('Unknown http status code: `%s`.', $code));
}
return self::$errorPhrases[$code];
} | [
"public",
"static",
"function",
"getReasonMessage",
"(",
"int",
"$",
"code",
")",
":",
"string",
"{",
"$",
"code",
"=",
"static",
"::",
"filterStatusCode",
"(",
"$",
"code",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"errorPhrases",
"[",
"$",
"code",
"]",
")",
")",
"{",
"throw",
"new",
"OutOfBoundsException",
"(",
"\\",
"sprintf",
"(",
"'Unknown http status code: `%s`.'",
",",
"$",
"code",
")",
")",
";",
"}",
"return",
"self",
"::",
"$",
"errorPhrases",
"[",
"$",
"code",
"]",
";",
"}"
] | Get the message for a given status code.
@param int $code http status code
@throws \Narrowspark\HttpStatus\Exception\InvalidArgumentException If the requested $code is not valid
@throws \Narrowspark\HttpStatus\Exception\OutOfBoundsException If the requested $code is not found
@return string Returns message for the given status code | [
"Get",
"the",
"message",
"for",
"a",
"given",
"status",
"code",
"."
] | train | https://github.com/narrowspark/http-status/blob/127dcbf1fd02ca9c2a7451da7e3c4dd98c508cde/src/HttpStatus.php#L271-L280 |
narrowspark/http-status | src/HttpStatus.php | HttpStatus.getReasonPhrase | public static function getReasonPhrase(int $code): string
{
$code = static::filterStatusCode($code);
if (! isset(self::$statusNames[$code])) {
throw new OutOfBoundsException(\sprintf('Unknown http status code: `%s`.', $code));
}
return self::$statusNames[$code];
} | php | public static function getReasonPhrase(int $code): string
{
$code = static::filterStatusCode($code);
if (! isset(self::$statusNames[$code])) {
throw new OutOfBoundsException(\sprintf('Unknown http status code: `%s`.', $code));
}
return self::$statusNames[$code];
} | [
"public",
"static",
"function",
"getReasonPhrase",
"(",
"int",
"$",
"code",
")",
":",
"string",
"{",
"$",
"code",
"=",
"static",
"::",
"filterStatusCode",
"(",
"$",
"code",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"statusNames",
"[",
"$",
"code",
"]",
")",
")",
"{",
"throw",
"new",
"OutOfBoundsException",
"(",
"\\",
"sprintf",
"(",
"'Unknown http status code: `%s`.'",
",",
"$",
"code",
")",
")",
";",
"}",
"return",
"self",
"::",
"$",
"statusNames",
"[",
"$",
"code",
"]",
";",
"}"
] | Get the name for a given status code.
@param int $code http status code
@throws \Narrowspark\HttpStatus\Exception\InvalidArgumentException If the requested $code is not valid
@throws \Narrowspark\HttpStatus\Exception\OutOfBoundsException If the requested $code is not found
@return string Returns name for the given status code | [
"Get",
"the",
"name",
"for",
"a",
"given",
"status",
"code",
"."
] | train | https://github.com/narrowspark/http-status/blob/127dcbf1fd02ca9c2a7451da7e3c4dd98c508cde/src/HttpStatus.php#L292-L301 |
narrowspark/http-status | src/HttpStatus.php | HttpStatus.getReasonException | public static function getReasonException(int $code): void
{
$code = static::filterStatusCode($code);
if (! isset(self::$statusNames[$code])) {
throw new OutOfBoundsException(\sprintf('Unknown http status code: `%s`.', $code));
}
if (isset(self::$phrasesExceptions[$code])) {
throw new self::$phrasesExceptions[$code]();
}
} | php | public static function getReasonException(int $code): void
{
$code = static::filterStatusCode($code);
if (! isset(self::$statusNames[$code])) {
throw new OutOfBoundsException(\sprintf('Unknown http status code: `%s`.', $code));
}
if (isset(self::$phrasesExceptions[$code])) {
throw new self::$phrasesExceptions[$code]();
}
} | [
"public",
"static",
"function",
"getReasonException",
"(",
"int",
"$",
"code",
")",
":",
"void",
"{",
"$",
"code",
"=",
"static",
"::",
"filterStatusCode",
"(",
"$",
"code",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"statusNames",
"[",
"$",
"code",
"]",
")",
")",
"{",
"throw",
"new",
"OutOfBoundsException",
"(",
"\\",
"sprintf",
"(",
"'Unknown http status code: `%s`.'",
",",
"$",
"code",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"phrasesExceptions",
"[",
"$",
"code",
"]",
")",
")",
"{",
"throw",
"new",
"self",
"::",
"$",
"phrasesExceptions",
"[",
"$",
"code",
"]",
"(",
")",
";",
"}",
"}"
] | Get the text for a given status code.
@param int $code http status code
@throws \Narrowspark\HttpStatus\Exception\InvalidArgumentException
@throws \Narrowspark\HttpStatus\Exception\BadGatewayException
@throws \Narrowspark\HttpStatus\Exception\BadRequestException
@throws \Narrowspark\HttpStatus\Exception\ConflictException
@throws \Narrowspark\HttpStatus\Exception\ExpectationFailedException
@throws \Narrowspark\HttpStatus\Exception\FailedDependencyException
@throws \Narrowspark\HttpStatus\Exception\ForbiddenException
@throws \Narrowspark\HttpStatus\Exception\GatewayTimeoutException
@throws \Narrowspark\HttpStatus\Exception\GoneException
@throws \Narrowspark\HttpStatus\Exception\HttpVersionNotSupportedException
@throws \Narrowspark\HttpStatus\Exception\ImATeapotException
@throws \Narrowspark\HttpStatus\Exception\InsufficientStorageException
@throws \Narrowspark\HttpStatus\Exception\InternalServerErrorException
@throws \Narrowspark\HttpStatus\Exception\LengthRequiredException
@throws \Narrowspark\HttpStatus\Exception\LockedException
@throws \Narrowspark\HttpStatus\Exception\LoopDetectedException
@throws \Narrowspark\HttpStatus\Exception\MethodNotAllowedException
@throws \Narrowspark\HttpStatus\Exception\NetworkAuthenticationRequiredException
@throws \Narrowspark\HttpStatus\Exception\NotAcceptableException
@throws \Narrowspark\HttpStatus\Exception\NotExtendedException
@throws \Narrowspark\HttpStatus\Exception\NotFoundException
@throws \Narrowspark\HttpStatus\Exception\NotImplementedException
@throws \Narrowspark\HttpStatus\Exception\PaymentRequiredException
@throws \Narrowspark\HttpStatus\Exception\PreconditionFailedException
@throws \Narrowspark\HttpStatus\Exception\PreconditionRequiredException
@throws \Narrowspark\HttpStatus\Exception\ProxyAuthenticationRequiredException
@throws \Narrowspark\HttpStatus\Exception\RequestedRangeNotSatisfiableException
@throws \Narrowspark\HttpStatus\Exception\RequestHeaderFieldsTooLargeException
@throws \Narrowspark\HttpStatus\Exception\RequestTimeoutException
@throws \Narrowspark\HttpStatus\Exception\RequestUriTooLongException
@throws \Narrowspark\HttpStatus\Exception\ServiceUnavailableException
@throws \Narrowspark\HttpStatus\Exception\TooEarlyException
@throws \Narrowspark\HttpStatus\Exception\TooManyRequestsException
@throws \Narrowspark\HttpStatus\Exception\UnauthorizedException
@throws \Narrowspark\HttpStatus\Exception\UnavailableForLegalReasonsException
@throws \Narrowspark\HttpStatus\Exception\UnprocessableEntityException
@throws \Narrowspark\HttpStatus\Exception\UnsupportedMediaTypeException
@throws \Narrowspark\HttpStatus\Exception\UpgradeRequiredException
@throws \Narrowspark\HttpStatus\Exception\VariantAlsoNegotiatesException
@throws \Narrowspark\HttpStatus\Exception\OutOfBoundsException | [
"Get",
"the",
"text",
"for",
"a",
"given",
"status",
"code",
"."
] | train | https://github.com/narrowspark/http-status/blob/127dcbf1fd02ca9c2a7451da7e3c4dd98c508cde/src/HttpStatus.php#L349-L360 |
narrowspark/http-status | src/HttpStatus.php | HttpStatus.filterStatusCode | public static function filterStatusCode(int $code): int
{
$filteredCode = \filter_var($code, \FILTER_VALIDATE_INT, ['options' => [
'min_range' => self::MINIMUM,
'max_range' => self::MAXIMUM,
]]);
if ($filteredCode === false) {
throw new InvalidArgumentException(\sprintf(
'The submitted code "%s" must be a positive integer between %s and %s.',
$code,
self::MINIMUM,
self::MAXIMUM
));
}
return $code;
} | php | public static function filterStatusCode(int $code): int
{
$filteredCode = \filter_var($code, \FILTER_VALIDATE_INT, ['options' => [
'min_range' => self::MINIMUM,
'max_range' => self::MAXIMUM,
]]);
if ($filteredCode === false) {
throw new InvalidArgumentException(\sprintf(
'The submitted code "%s" must be a positive integer between %s and %s.',
$code,
self::MINIMUM,
self::MAXIMUM
));
}
return $code;
} | [
"public",
"static",
"function",
"filterStatusCode",
"(",
"int",
"$",
"code",
")",
":",
"int",
"{",
"$",
"filteredCode",
"=",
"\\",
"filter_var",
"(",
"$",
"code",
",",
"\\",
"FILTER_VALIDATE_INT",
",",
"[",
"'options'",
"=>",
"[",
"'min_range'",
"=>",
"self",
"::",
"MINIMUM",
",",
"'max_range'",
"=>",
"self",
"::",
"MAXIMUM",
",",
"]",
"]",
")",
";",
"if",
"(",
"$",
"filteredCode",
"===",
"false",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\\",
"sprintf",
"(",
"'The submitted code \"%s\" must be a positive integer between %s and %s.'",
",",
"$",
"code",
",",
"self",
"::",
"MINIMUM",
",",
"self",
"::",
"MAXIMUM",
")",
")",
";",
"}",
"return",
"$",
"code",
";",
"}"
] | Filter a HTTP Status code.
@param int $code
@throws \Narrowspark\HttpStatus\Exception\InvalidArgumentException if the HTTP status code is invalid
@return int | [
"Filter",
"a",
"HTTP",
"Status",
"code",
"."
] | train | https://github.com/narrowspark/http-status/blob/127dcbf1fd02ca9c2a7451da7e3c4dd98c508cde/src/HttpStatus.php#L371-L388 |
aedart/laravel-helpers | src/Traits/Bus/BusTrait.php | BusTrait.getBus | public function getBus(): ?Dispatcher
{
if (!$this->hasBus()) {
$this->setBus($this->getDefaultBus());
}
return $this->bus;
} | php | public function getBus(): ?Dispatcher
{
if (!$this->hasBus()) {
$this->setBus($this->getDefaultBus());
}
return $this->bus;
} | [
"public",
"function",
"getBus",
"(",
")",
":",
"?",
"Dispatcher",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasBus",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setBus",
"(",
"$",
"this",
"->",
"getDefaultBus",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"bus",
";",
"}"
] | Get bus
If no bus has been set, this method will
set and return a default bus, if any such
value is available
@see getDefaultBus()
@return Dispatcher|null bus or null if none bus has been set | [
"Get",
"bus"
] | train | https://github.com/aedart/laravel-helpers/blob/8b81a2d6658f3f8cb62b6be2c34773aaa2df219a/src/Traits/Bus/BusTrait.php#L53-L59 |
PortaText/php-sdk | src/PortaText/Command/Api/Calls.php | Calls.getEndpoint | protected function getEndpoint($method)
{
$endpoint = "calls";
$searchParams = $this->getArgument("search_params");
if (!is_null($searchParams)) {
$queryString = http_build_query($searchParams);
$this->delArgument("search_params");
return "$endpoint?$queryString";
}
return $endpoint;
} | php | protected function getEndpoint($method)
{
$endpoint = "calls";
$searchParams = $this->getArgument("search_params");
if (!is_null($searchParams)) {
$queryString = http_build_query($searchParams);
$this->delArgument("search_params");
return "$endpoint?$queryString";
}
return $endpoint;
} | [
"protected",
"function",
"getEndpoint",
"(",
"$",
"method",
")",
"{",
"$",
"endpoint",
"=",
"\"calls\"",
";",
"$",
"searchParams",
"=",
"$",
"this",
"->",
"getArgument",
"(",
"\"search_params\"",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"searchParams",
")",
")",
"{",
"$",
"queryString",
"=",
"http_build_query",
"(",
"$",
"searchParams",
")",
";",
"$",
"this",
"->",
"delArgument",
"(",
"\"search_params\"",
")",
";",
"return",
"\"$endpoint?$queryString\"",
";",
"}",
"return",
"$",
"endpoint",
";",
"}"
] | Returns a string with the endpoint for the given command.
@param string $method Method for this command.
@return string | [
"Returns",
"a",
"string",
"with",
"the",
"endpoint",
"for",
"the",
"given",
"command",
"."
] | train | https://github.com/PortaText/php-sdk/blob/dbe04ef043db5b251953f9de57aa4d0f1785dfcc/src/PortaText/Command/Api/Calls.php#L99-L109 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.