repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
MichaelJ2324/PHP-REST-Client | src/Endpoint/Abstracts/AbstractEndpoint.php | AbstractEndpoint.configureRequest | protected function configureRequest(RequestInterface $Request)
{
if ($Request->getStatus() >= Curl::STATUS_SENT){
$Request->reset();
}
if (isset($this->properties[self::PROPERTY_HTTP_METHOD]) &&
$this->properties[self::PROPERTY_HTTP_METHOD] !== ''){
$Request->setMethod($this->properties[self::PROPERTY_HTTP_METHOD]);
}
$url = $this->configureURL($this->getOptions());
if ($this->verifyUrl($url)) {
$url = rtrim($this->getBaseUrl(),"/")."/".$url;
$Request->setURL($url);
}
$data = ($this->getData()?$this->getData():NULL);
$data = $this->configureData($data);
$Request->setBody($data);
if ($this->authRequired()){
if (isset($this->Auth)){
$this->Auth->configureRequest($Request);
}
}
return $Request;
} | php | protected function configureRequest(RequestInterface $Request)
{
if ($Request->getStatus() >= Curl::STATUS_SENT){
$Request->reset();
}
if (isset($this->properties[self::PROPERTY_HTTP_METHOD]) &&
$this->properties[self::PROPERTY_HTTP_METHOD] !== ''){
$Request->setMethod($this->properties[self::PROPERTY_HTTP_METHOD]);
}
$url = $this->configureURL($this->getOptions());
if ($this->verifyUrl($url)) {
$url = rtrim($this->getBaseUrl(),"/")."/".$url;
$Request->setURL($url);
}
$data = ($this->getData()?$this->getData():NULL);
$data = $this->configureData($data);
$Request->setBody($data);
if ($this->authRequired()){
if (isset($this->Auth)){
$this->Auth->configureRequest($Request);
}
}
return $Request;
} | [
"protected",
"function",
"configureRequest",
"(",
"RequestInterface",
"$",
"Request",
")",
"{",
"if",
"(",
"$",
"Request",
"->",
"getStatus",
"(",
")",
">=",
"Curl",
"::",
"STATUS_SENT",
")",
"{",
"$",
"Request",
"->",
"reset",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"properties",
"[",
"self",
"::",
"PROPERTY_HTTP_METHOD",
"]",
")",
"&&",
"$",
"this",
"->",
"properties",
"[",
"self",
"::",
"PROPERTY_HTTP_METHOD",
"]",
"!==",
"''",
")",
"{",
"$",
"Request",
"->",
"setMethod",
"(",
"$",
"this",
"->",
"properties",
"[",
"self",
"::",
"PROPERTY_HTTP_METHOD",
"]",
")",
";",
"}",
"$",
"url",
"=",
"$",
"this",
"->",
"configureURL",
"(",
"$",
"this",
"->",
"getOptions",
"(",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"verifyUrl",
"(",
"$",
"url",
")",
")",
"{",
"$",
"url",
"=",
"rtrim",
"(",
"$",
"this",
"->",
"getBaseUrl",
"(",
")",
",",
"\"/\"",
")",
".",
"\"/\"",
".",
"$",
"url",
";",
"$",
"Request",
"->",
"setURL",
"(",
"$",
"url",
")",
";",
"}",
"$",
"data",
"=",
"(",
"$",
"this",
"->",
"getData",
"(",
")",
"?",
"$",
"this",
"->",
"getData",
"(",
")",
":",
"NULL",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"configureData",
"(",
"$",
"data",
")",
";",
"$",
"Request",
"->",
"setBody",
"(",
"$",
"data",
")",
";",
"if",
"(",
"$",
"this",
"->",
"authRequired",
"(",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"Auth",
")",
")",
"{",
"$",
"this",
"->",
"Auth",
"->",
"configureRequest",
"(",
"$",
"Request",
")",
";",
"}",
"}",
"return",
"$",
"Request",
";",
"}"
] | Verifies URL and Data are setup, then sets them on the Request Object
@param RequestInterface $Request
@return RequestInterface | [
"Verifies",
"URL",
"and",
"Data",
"are",
"setup",
"then",
"sets",
"them",
"on",
"the",
"Request",
"Object"
] | b8a2caaf6456eccaa845ba5c5098608aa9645c92 | https://github.com/MichaelJ2324/PHP-REST-Client/blob/b8a2caaf6456eccaa845ba5c5098608aa9645c92/src/Endpoint/Abstracts/AbstractEndpoint.php#L285-L308 | train |
MichaelJ2324/PHP-REST-Client | src/Endpoint/Abstracts/AbstractEndpoint.php | AbstractEndpoint.configureResponse | protected function configureResponse(ResponseInterface $Response){
$Response->setRequest($this->Request);
$Response->extract();
return $Response;
} | php | protected function configureResponse(ResponseInterface $Response){
$Response->setRequest($this->Request);
$Response->extract();
return $Response;
} | [
"protected",
"function",
"configureResponse",
"(",
"ResponseInterface",
"$",
"Response",
")",
"{",
"$",
"Response",
"->",
"setRequest",
"(",
"$",
"this",
"->",
"Request",
")",
";",
"$",
"Response",
"->",
"extract",
"(",
")",
";",
"return",
"$",
"Response",
";",
"}"
] | Configure the Response Object after sending of the Request
@param ResponseInterface $Response
@return ResponseInterface | [
"Configure",
"the",
"Response",
"Object",
"after",
"sending",
"of",
"the",
"Request"
] | b8a2caaf6456eccaa845ba5c5098608aa9645c92 | https://github.com/MichaelJ2324/PHP-REST-Client/blob/b8a2caaf6456eccaa845ba5c5098608aa9645c92/src/Endpoint/Abstracts/AbstractEndpoint.php#L315-L319 | train |
MichaelJ2324/PHP-REST-Client | src/Endpoint/Abstracts/AbstractEndpoint.php | AbstractEndpoint.verifyUrl | private function verifyUrl($url)
{
if (strpos($url, static::$_URL_VAR_CHARACTER) !== false) {
throw new InvalidUrl(array(get_class($this), $url));
}
return true;
} | php | private function verifyUrl($url)
{
if (strpos($url, static::$_URL_VAR_CHARACTER) !== false) {
throw new InvalidUrl(array(get_class($this), $url));
}
return true;
} | [
"private",
"function",
"verifyUrl",
"(",
"$",
"url",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"url",
",",
"static",
"::",
"$",
"_URL_VAR_CHARACTER",
")",
"!==",
"false",
")",
"{",
"throw",
"new",
"InvalidUrl",
"(",
"array",
"(",
"get_class",
"(",
"$",
"this",
")",
",",
"$",
"url",
")",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Verify if URL is configured properly
@param string $url
@return bool
@throws InvalidUrl | [
"Verify",
"if",
"URL",
"is",
"configured",
"properly"
] | b8a2caaf6456eccaa845ba5c5098608aa9645c92 | https://github.com/MichaelJ2324/PHP-REST-Client/blob/b8a2caaf6456eccaa845ba5c5098608aa9645c92/src/Endpoint/Abstracts/AbstractEndpoint.php#L389-L395 | train |
MichaelJ2324/PHP-REST-Client | src/Endpoint/Abstracts/AbstractEndpoint.php | AbstractEndpoint.requiresOptions | protected function requiresOptions()
{
$url = $this->getEndPointUrl();
$variables = $this->extractUrlVariables($url);
return !empty($variables);
} | php | protected function requiresOptions()
{
$url = $this->getEndPointUrl();
$variables = $this->extractUrlVariables($url);
return !empty($variables);
} | [
"protected",
"function",
"requiresOptions",
"(",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"getEndPointUrl",
"(",
")",
";",
"$",
"variables",
"=",
"$",
"this",
"->",
"extractUrlVariables",
"(",
"$",
"url",
")",
";",
"return",
"!",
"empty",
"(",
"$",
"variables",
")",
";",
"}"
] | Checks if Endpoint URL requires Options
@return bool|array | [
"Checks",
"if",
"Endpoint",
"URL",
"requires",
"Options"
] | b8a2caaf6456eccaa845ba5c5098608aa9645c92 | https://github.com/MichaelJ2324/PHP-REST-Client/blob/b8a2caaf6456eccaa845ba5c5098608aa9645c92/src/Endpoint/Abstracts/AbstractEndpoint.php#L402-L407 | train |
MichaelJ2324/PHP-REST-Client | src/Endpoint/Abstracts/AbstractEndpoint.php | AbstractEndpoint.extractUrlVariables | protected function extractUrlVariables($url){
$variables = array();
$pattern = "/(\\".static::$_URL_VAR_CHARACTER.".*?[^\\/]*)/";
if (preg_match($pattern,$url,$matches)){
array_shift($matches);
foreach($matches as $match){
$variables[] = $match[0];
}
}
return $variables;
} | php | protected function extractUrlVariables($url){
$variables = array();
$pattern = "/(\\".static::$_URL_VAR_CHARACTER.".*?[^\\/]*)/";
if (preg_match($pattern,$url,$matches)){
array_shift($matches);
foreach($matches as $match){
$variables[] = $match[0];
}
}
return $variables;
} | [
"protected",
"function",
"extractUrlVariables",
"(",
"$",
"url",
")",
"{",
"$",
"variables",
"=",
"array",
"(",
")",
";",
"$",
"pattern",
"=",
"\"/(\\\\\"",
".",
"static",
"::",
"$",
"_URL_VAR_CHARACTER",
".",
"\".*?[^\\\\/]*)/\"",
";",
"if",
"(",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"url",
",",
"$",
"matches",
")",
")",
"{",
"array_shift",
"(",
"$",
"matches",
")",
";",
"foreach",
"(",
"$",
"matches",
"as",
"$",
"match",
")",
"{",
"$",
"variables",
"[",
"]",
"=",
"$",
"match",
"[",
"0",
"]",
";",
"}",
"}",
"return",
"$",
"variables",
";",
"}"
] | Helper method for extracting variables via Regex from a passed in URL
@param $url
@return array | [
"Helper",
"method",
"for",
"extracting",
"variables",
"via",
"Regex",
"from",
"a",
"passed",
"in",
"URL"
] | b8a2caaf6456eccaa845ba5c5098608aa9645c92 | https://github.com/MichaelJ2324/PHP-REST-Client/blob/b8a2caaf6456eccaa845ba5c5098608aa9645c92/src/Endpoint/Abstracts/AbstractEndpoint.php#L414-L424 | train |
Innmind/Math | src/Matrix/Vector.php | Vector.lead | public function lead(): Number
{
return $this->reduce(
new Integer(0),
static function(Number $lead, Number $number): Number {
if (!$lead->equals(new Integer(0))) {
return $lead;
}
return $number;
}
);
} | php | public function lead(): Number
{
return $this->reduce(
new Integer(0),
static function(Number $lead, Number $number): Number {
if (!$lead->equals(new Integer(0))) {
return $lead;
}
return $number;
}
);
} | [
"public",
"function",
"lead",
"(",
")",
":",
"Number",
"{",
"return",
"$",
"this",
"->",
"reduce",
"(",
"new",
"Integer",
"(",
"0",
")",
",",
"static",
"function",
"(",
"Number",
"$",
"lead",
",",
"Number",
"$",
"number",
")",
":",
"Number",
"{",
"if",
"(",
"!",
"$",
"lead",
"->",
"equals",
"(",
"new",
"Integer",
"(",
"0",
")",
")",
")",
"{",
"return",
"$",
"lead",
";",
"}",
"return",
"$",
"number",
";",
"}",
")",
";",
"}"
] | First non zero number found | [
"First",
"non",
"zero",
"number",
"found"
] | ac9ad4dd1852c145e90f5edc0f38a873b125a50b | https://github.com/Innmind/Math/blob/ac9ad4dd1852c145e90f5edc0f38a873b125a50b/src/Matrix/Vector.php#L212-L224 | train |
bseddon/XPath20 | XPath2Parser.php | XPath2Parser.log | public function log( $message )
{
if ( ! $this->enableLogging ) return;
if ( ! isset( $this->log ) ) $this->log = \lyquidity\XPath2\lyquidity\Log::getInstance();
$this->log->info( $message );
} | php | public function log( $message )
{
if ( ! $this->enableLogging ) return;
if ( ! isset( $this->log ) ) $this->log = \lyquidity\XPath2\lyquidity\Log::getInstance();
$this->log->info( $message );
} | [
"public",
"function",
"log",
"(",
"$",
"message",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"enableLogging",
")",
"return",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"log",
")",
")",
"$",
"this",
"->",
"log",
"=",
"\\",
"lyquidity",
"\\",
"XPath2",
"\\",
"lyquidity",
"\\",
"Log",
"::",
"getInstance",
"(",
")",
";",
"$",
"this",
"->",
"log",
"->",
"info",
"(",
"$",
"message",
")",
";",
"}"
] | Log a message to the current log target
@param string $message | [
"Log",
"a",
"message",
"to",
"the",
"current",
"log",
"target"
] | 69882b6efffaa5470a819d5fdd2f6473ddeb046d | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/XPath2Parser.php#L188-L193 | train |
bseddon/XPath20 | XPath2Parser.php | XPath2Parser.yyExpecting | protected function yyExpecting ( $state )
{
$token = 0;
$n = 0;
$len = 0;
$ok = array_fill( 0, count( XPath2Parser::$yyName ), false );
if ( ( $n = XPath2Parser::$yySindex[ $state ] ) != 0 )
{
for ( $token = $n < 0 ? -$n : 0; ( $token < count( XPath2Parser::$yyName ) && ( $n + $token < count( XPath2Parser::$yyTable ) ) ); ++ $token )
{
if ( XPath2Parser::$yyCheck[ $n + $token ] == $token && !$ok[ $token ] && ! is_null( XPath2Parser::$yyName[ $token ] ) )
{
++ $len;
$ok[ $token ] = true;
}
}
}
if ( ( $n = XPath2Parser::$yyRindex[ $state ] ) != 0 )
{
for ( $token = $n < 0 ? -$n : 0; ( $token < count( XPath2Parser::$yyName ) ) && ( $n + $token < count( XPath2Parser::$yyTable ) ); ++ $token )
{
if ( XPath2Parser::$yyCheck[ $n + $token ] == $token && ! $ok[ $token ] && ! is_null( XPath2Parser::$yyName[ $token ] ) )
{
++ $len;
$ok[ $token ] = true;
}
}
}
/**
* @var array[ string ] $result
*/
$result = array_fill( 0, $len, null );
for ( $n = $token = 0; $n < $len; ++ $token )
if ( $ok[ $token ] ) $result[ $n++ ] = XPath2Parser::$yyName[ $token ];
return $result;
} | php | protected function yyExpecting ( $state )
{
$token = 0;
$n = 0;
$len = 0;
$ok = array_fill( 0, count( XPath2Parser::$yyName ), false );
if ( ( $n = XPath2Parser::$yySindex[ $state ] ) != 0 )
{
for ( $token = $n < 0 ? -$n : 0; ( $token < count( XPath2Parser::$yyName ) && ( $n + $token < count( XPath2Parser::$yyTable ) ) ); ++ $token )
{
if ( XPath2Parser::$yyCheck[ $n + $token ] == $token && !$ok[ $token ] && ! is_null( XPath2Parser::$yyName[ $token ] ) )
{
++ $len;
$ok[ $token ] = true;
}
}
}
if ( ( $n = XPath2Parser::$yyRindex[ $state ] ) != 0 )
{
for ( $token = $n < 0 ? -$n : 0; ( $token < count( XPath2Parser::$yyName ) ) && ( $n + $token < count( XPath2Parser::$yyTable ) ); ++ $token )
{
if ( XPath2Parser::$yyCheck[ $n + $token ] == $token && ! $ok[ $token ] && ! is_null( XPath2Parser::$yyName[ $token ] ) )
{
++ $len;
$ok[ $token ] = true;
}
}
}
/**
* @var array[ string ] $result
*/
$result = array_fill( 0, $len, null );
for ( $n = $token = 0; $n < $len; ++ $token )
if ( $ok[ $token ] ) $result[ $n++ ] = XPath2Parser::$yyName[ $token ];
return $result;
} | [
"protected",
"function",
"yyExpecting",
"(",
"$",
"state",
")",
"{",
"$",
"token",
"=",
"0",
";",
"$",
"n",
"=",
"0",
";",
"$",
"len",
"=",
"0",
";",
"$",
"ok",
"=",
"array_fill",
"(",
"0",
",",
"count",
"(",
"XPath2Parser",
"::",
"$",
"yyName",
")",
",",
"false",
")",
";",
"if",
"(",
"(",
"$",
"n",
"=",
"XPath2Parser",
"::",
"$",
"yySindex",
"[",
"$",
"state",
"]",
")",
"!=",
"0",
")",
"{",
"for",
"(",
"$",
"token",
"=",
"$",
"n",
"<",
"0",
"?",
"-",
"$",
"n",
":",
"0",
";",
"(",
"$",
"token",
"<",
"count",
"(",
"XPath2Parser",
"::",
"$",
"yyName",
")",
"&&",
"(",
"$",
"n",
"+",
"$",
"token",
"<",
"count",
"(",
"XPath2Parser",
"::",
"$",
"yyTable",
")",
")",
")",
";",
"++",
"$",
"token",
")",
"{",
"if",
"(",
"XPath2Parser",
"::",
"$",
"yyCheck",
"[",
"$",
"n",
"+",
"$",
"token",
"]",
"==",
"$",
"token",
"&&",
"!",
"$",
"ok",
"[",
"$",
"token",
"]",
"&&",
"!",
"is_null",
"(",
"XPath2Parser",
"::",
"$",
"yyName",
"[",
"$",
"token",
"]",
")",
")",
"{",
"++",
"$",
"len",
";",
"$",
"ok",
"[",
"$",
"token",
"]",
"=",
"true",
";",
"}",
"}",
"}",
"if",
"(",
"(",
"$",
"n",
"=",
"XPath2Parser",
"::",
"$",
"yyRindex",
"[",
"$",
"state",
"]",
")",
"!=",
"0",
")",
"{",
"for",
"(",
"$",
"token",
"=",
"$",
"n",
"<",
"0",
"?",
"-",
"$",
"n",
":",
"0",
";",
"(",
"$",
"token",
"<",
"count",
"(",
"XPath2Parser",
"::",
"$",
"yyName",
")",
")",
"&&",
"(",
"$",
"n",
"+",
"$",
"token",
"<",
"count",
"(",
"XPath2Parser",
"::",
"$",
"yyTable",
")",
")",
";",
"++",
"$",
"token",
")",
"{",
"if",
"(",
"XPath2Parser",
"::",
"$",
"yyCheck",
"[",
"$",
"n",
"+",
"$",
"token",
"]",
"==",
"$",
"token",
"&&",
"!",
"$",
"ok",
"[",
"$",
"token",
"]",
"&&",
"!",
"is_null",
"(",
"XPath2Parser",
"::",
"$",
"yyName",
"[",
"$",
"token",
"]",
")",
")",
"{",
"++",
"$",
"len",
";",
"$",
"ok",
"[",
"$",
"token",
"]",
"=",
"true",
";",
"}",
"}",
"}",
"/**\r\n\t * @var array[ string ] $result\r\n\t */",
"$",
"result",
"=",
"array_fill",
"(",
"0",
",",
"$",
"len",
",",
"null",
")",
";",
"for",
"(",
"$",
"n",
"=",
"$",
"token",
"=",
"0",
";",
"$",
"n",
"<",
"$",
"len",
";",
"++",
"$",
"token",
")",
"if",
"(",
"$",
"ok",
"[",
"$",
"token",
"]",
")",
"$",
"result",
"[",
"$",
"n",
"++",
"]",
"=",
"XPath2Parser",
"::",
"$",
"yyName",
"[",
"$",
"token",
"]",
";",
"return",
"$",
"result",
";",
"}"
] | computes list of expected tokens on error by tracing the tables.
@param int $state for which to compute the list.
@return array list of token names. | [
"computes",
"list",
"of",
"expected",
"tokens",
"on",
"error",
"by",
"tracing",
"the",
"tables",
"."
] | 69882b6efffaa5470a819d5fdd2f6473ddeb046d | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/XPath2Parser.php#L491-L529 | train |
itkg/core | src/Itkg/Core/Cache/Adapter/FileSystem.php | FileSystem.get | public function get(CacheableInterface $item)
{
$targetFile = $this->getTargetFile($item->getHashKey());
$return = false;
if (file_exists($targetFile)) {
if ($item->getTtl() > 0 && ((filemtime($targetFile) + $item->getTtl()) < time())) {
$this->remove($item);
} else {
$return = unserialize(file_get_contents($targetFile, false, null, strlen(self::STR_PREFIX)));
}
}
return $return;
} | php | public function get(CacheableInterface $item)
{
$targetFile = $this->getTargetFile($item->getHashKey());
$return = false;
if (file_exists($targetFile)) {
if ($item->getTtl() > 0 && ((filemtime($targetFile) + $item->getTtl()) < time())) {
$this->remove($item);
} else {
$return = unserialize(file_get_contents($targetFile, false, null, strlen(self::STR_PREFIX)));
}
}
return $return;
} | [
"public",
"function",
"get",
"(",
"CacheableInterface",
"$",
"item",
")",
"{",
"$",
"targetFile",
"=",
"$",
"this",
"->",
"getTargetFile",
"(",
"$",
"item",
"->",
"getHashKey",
"(",
")",
")",
";",
"$",
"return",
"=",
"false",
";",
"if",
"(",
"file_exists",
"(",
"$",
"targetFile",
")",
")",
"{",
"if",
"(",
"$",
"item",
"->",
"getTtl",
"(",
")",
">",
"0",
"&&",
"(",
"(",
"filemtime",
"(",
"$",
"targetFile",
")",
"+",
"$",
"item",
"->",
"getTtl",
"(",
")",
")",
"<",
"time",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"remove",
"(",
"$",
"item",
")",
";",
"}",
"else",
"{",
"$",
"return",
"=",
"unserialize",
"(",
"file_get_contents",
"(",
"$",
"targetFile",
",",
"false",
",",
"null",
",",
"strlen",
"(",
"self",
"::",
"STR_PREFIX",
")",
")",
")",
";",
"}",
"}",
"return",
"$",
"return",
";",
"}"
] | Get value from cache
Must return false when cache is expired or invalid
@param \Itkg\Core\CacheableInterface $item
@return mixed | [
"Get",
"value",
"from",
"cache",
"Must",
"return",
"false",
"when",
"cache",
"is",
"expired",
"or",
"invalid"
] | e5e4efb05feb4d23b0df41f2b21fd095103e593b | https://github.com/itkg/core/blob/e5e4efb05feb4d23b0df41f2b21fd095103e593b/src/Itkg/Core/Cache/Adapter/FileSystem.php#L106-L120 | train |
rawphp/RawMigrator | lib/Migrator.php | Migrator.init | public function init( $config = NULL )
{
parent::init( $config );
if ( !isset( $config[ 'migration_path' ] ) )
{
throw new \InvalidArgumentException( 'Missing migration_path parameter' );
}
foreach ( $config as $key => $value )
{
switch( $key )
{
case 'migration_path':
$this->migrationPath = $value;
break;
case 'migration_namespace':
$this->migrationNamespace = $value;
break;
case 'namespaces':
$this->namespaces = $value;
break;
case 'class_prefix':
$this->classPrefix = $value;
break;
case 'migration_table':
$this->migrationTable = $value;
break;
case 'class_name_style':
$this->migrationClassStyle = $value;
break;
case 'overwrite':
$this->overwrite = $value;
break;
case 'levels':
$this->levels = $value;
break;
case 'name':
$this->migrationClass = $value;
break;
case 'verbose':
$this->verbose = $value === 'true' ? TRUE : FALSE;
break;
default:
// Do nothing
break;
}
}
$this->doAction( self::ON_INIT_ACTION );
} | php | public function init( $config = NULL )
{
parent::init( $config );
if ( !isset( $config[ 'migration_path' ] ) )
{
throw new \InvalidArgumentException( 'Missing migration_path parameter' );
}
foreach ( $config as $key => $value )
{
switch( $key )
{
case 'migration_path':
$this->migrationPath = $value;
break;
case 'migration_namespace':
$this->migrationNamespace = $value;
break;
case 'namespaces':
$this->namespaces = $value;
break;
case 'class_prefix':
$this->classPrefix = $value;
break;
case 'migration_table':
$this->migrationTable = $value;
break;
case 'class_name_style':
$this->migrationClassStyle = $value;
break;
case 'overwrite':
$this->overwrite = $value;
break;
case 'levels':
$this->levels = $value;
break;
case 'name':
$this->migrationClass = $value;
break;
case 'verbose':
$this->verbose = $value === 'true' ? TRUE : FALSE;
break;
default:
// Do nothing
break;
}
}
$this->doAction( self::ON_INIT_ACTION );
} | [
"public",
"function",
"init",
"(",
"$",
"config",
"=",
"NULL",
")",
"{",
"parent",
"::",
"init",
"(",
"$",
"config",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"config",
"[",
"'migration_path'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Missing migration_path parameter'",
")",
";",
"}",
"foreach",
"(",
"$",
"config",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"switch",
"(",
"$",
"key",
")",
"{",
"case",
"'migration_path'",
":",
"$",
"this",
"->",
"migrationPath",
"=",
"$",
"value",
";",
"break",
";",
"case",
"'migration_namespace'",
":",
"$",
"this",
"->",
"migrationNamespace",
"=",
"$",
"value",
";",
"break",
";",
"case",
"'namespaces'",
":",
"$",
"this",
"->",
"namespaces",
"=",
"$",
"value",
";",
"break",
";",
"case",
"'class_prefix'",
":",
"$",
"this",
"->",
"classPrefix",
"=",
"$",
"value",
";",
"break",
";",
"case",
"'migration_table'",
":",
"$",
"this",
"->",
"migrationTable",
"=",
"$",
"value",
";",
"break",
";",
"case",
"'class_name_style'",
":",
"$",
"this",
"->",
"migrationClassStyle",
"=",
"$",
"value",
";",
"break",
";",
"case",
"'overwrite'",
":",
"$",
"this",
"->",
"overwrite",
"=",
"$",
"value",
";",
"break",
";",
"case",
"'levels'",
":",
"$",
"this",
"->",
"levels",
"=",
"$",
"value",
";",
"break",
";",
"case",
"'name'",
":",
"$",
"this",
"->",
"migrationClass",
"=",
"$",
"value",
";",
"break",
";",
"case",
"'verbose'",
":",
"$",
"this",
"->",
"verbose",
"=",
"$",
"value",
"===",
"'true'",
"?",
"TRUE",
":",
"FALSE",
";",
"break",
";",
"default",
":",
"// Do nothing",
"break",
";",
"}",
"}",
"$",
"this",
"->",
"doAction",
"(",
"self",
"::",
"ON_INIT_ACTION",
")",
";",
"}"
] | Initialises the migrator.
@param array $config configuration array
@action ON_INIT_ACTION
@throws \InvalidArgumentException if a configuration is missing | [
"Initialises",
"the",
"migrator",
"."
] | bbf5e354d7ff532552fd6865b38e4c1a3b6f3757 | https://github.com/rawphp/RawMigrator/blob/bbf5e354d7ff532552fd6865b38e4c1a3b6f3757/lib/Migrator.php#L95-L155 | train |
rawphp/RawMigrator | lib/Migrator.php | Migrator.createMigration | public function createMigration( )
{
$date = new \DateTime();
$tStamp = substr( $date->format( 'U' ), 2 );
if ( self::STYLE_CAMEL_CASE !== $this->migrationClassStyle )
{
$parts = preg_split('/(?=[A-Z])/', $this->migrationClass, -1, PREG_SPLIT_NO_EMPTY);
$className = $this->classPrefix . '_' . $tStamp . '_' . implode( '_', $parts );
}
else
{
$className = $this->classPrefix . $tStamp . $this->migrationClass;
}
$template = $this->getMigrationTemplate( $className );
$path = $this->migrationPath . $className . '.php';
$template = $this->filter( self::ON_CREATE_MIGRATION_FILTER, $template );
if ( ( file_exists( $path ) && $this->overwrite ) || !file_exists( $path ) )
{
$result = file_put_contents( $path, $template );
}
elseif ( file_exists( $path ) )
{
throw new MigrationException( 'Migration file already exists' );
}
$this->doAction( self::ON_CREATE_MIGRATION_ACTION );
return FALSE !== $result;
} | php | public function createMigration( )
{
$date = new \DateTime();
$tStamp = substr( $date->format( 'U' ), 2 );
if ( self::STYLE_CAMEL_CASE !== $this->migrationClassStyle )
{
$parts = preg_split('/(?=[A-Z])/', $this->migrationClass, -1, PREG_SPLIT_NO_EMPTY);
$className = $this->classPrefix . '_' . $tStamp . '_' . implode( '_', $parts );
}
else
{
$className = $this->classPrefix . $tStamp . $this->migrationClass;
}
$template = $this->getMigrationTemplate( $className );
$path = $this->migrationPath . $className . '.php';
$template = $this->filter( self::ON_CREATE_MIGRATION_FILTER, $template );
if ( ( file_exists( $path ) && $this->overwrite ) || !file_exists( $path ) )
{
$result = file_put_contents( $path, $template );
}
elseif ( file_exists( $path ) )
{
throw new MigrationException( 'Migration file already exists' );
}
$this->doAction( self::ON_CREATE_MIGRATION_ACTION );
return FALSE !== $result;
} | [
"public",
"function",
"createMigration",
"(",
")",
"{",
"$",
"date",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"$",
"tStamp",
"=",
"substr",
"(",
"$",
"date",
"->",
"format",
"(",
"'U'",
")",
",",
"2",
")",
";",
"if",
"(",
"self",
"::",
"STYLE_CAMEL_CASE",
"!==",
"$",
"this",
"->",
"migrationClassStyle",
")",
"{",
"$",
"parts",
"=",
"preg_split",
"(",
"'/(?=[A-Z])/'",
",",
"$",
"this",
"->",
"migrationClass",
",",
"-",
"1",
",",
"PREG_SPLIT_NO_EMPTY",
")",
";",
"$",
"className",
"=",
"$",
"this",
"->",
"classPrefix",
".",
"'_'",
".",
"$",
"tStamp",
".",
"'_'",
".",
"implode",
"(",
"'_'",
",",
"$",
"parts",
")",
";",
"}",
"else",
"{",
"$",
"className",
"=",
"$",
"this",
"->",
"classPrefix",
".",
"$",
"tStamp",
".",
"$",
"this",
"->",
"migrationClass",
";",
"}",
"$",
"template",
"=",
"$",
"this",
"->",
"getMigrationTemplate",
"(",
"$",
"className",
")",
";",
"$",
"path",
"=",
"$",
"this",
"->",
"migrationPath",
".",
"$",
"className",
".",
"'.php'",
";",
"$",
"template",
"=",
"$",
"this",
"->",
"filter",
"(",
"self",
"::",
"ON_CREATE_MIGRATION_FILTER",
",",
"$",
"template",
")",
";",
"if",
"(",
"(",
"file_exists",
"(",
"$",
"path",
")",
"&&",
"$",
"this",
"->",
"overwrite",
")",
"||",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"$",
"result",
"=",
"file_put_contents",
"(",
"$",
"path",
",",
"$",
"template",
")",
";",
"}",
"elseif",
"(",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"MigrationException",
"(",
"'Migration file already exists'",
")",
";",
"}",
"$",
"this",
"->",
"doAction",
"(",
"self",
"::",
"ON_CREATE_MIGRATION_ACTION",
")",
";",
"return",
"FALSE",
"!==",
"$",
"result",
";",
"}"
] | Creates a new migration class file.
@filter ON_CREATE_MIGRATION_FILTER
@action ON_CREATE_MIGRATION_ACTION
@return bool TRUE on success, FALSE on failure
@throws MigrationException if configuration is missing | [
"Creates",
"a",
"new",
"migration",
"class",
"file",
"."
] | bbf5e354d7ff532552fd6865b38e4c1a3b6f3757 | https://github.com/rawphp/RawMigrator/blob/bbf5e354d7ff532552fd6865b38e4c1a3b6f3757/lib/Migrator.php#L168-L203 | train |
rawphp/RawMigrator | lib/Migrator.php | Migrator.getMigrationTemplate | public function getMigrationTemplate( $name )
{
$template = '<?php' . PHP_EOL . PHP_EOL;
if ( '' !== $this->migrationNamespace )
{
$template .= 'namespace ' . $this->migrationNamespace . ';' . PHP_EOL . PHP_EOL;
}
$template .= 'use RawPHP\RawMigrator\Migration;' . PHP_EOL;
$template .= 'use RawPHP\RawDatabase\IDatabase;' . PHP_EOL . PHP_EOL;
$template .= 'class ' . $name . ' extends Migration' . PHP_EOL;
$template .= '{' . PHP_EOL;
$template .= ' /**' . PHP_EOL;
$template .= ' * Implement database changes here.' . PHP_EOL;
$template .= ' * ' . PHP_EOL;
$template .= ' * @param IDatabase $db database instance' . PHP_EOL;
$template .= ' */' . PHP_EOL;
$template .= ' public function migrateUp( IDatabase $db )' . PHP_EOL;
$template .= ' {' . PHP_EOL;
$template .= ' ' . PHP_EOL;
$template .= ' }' . PHP_EOL . PHP_EOL;
$template .= ' /**' . PHP_EOL;
$template .= ' * Implement reverting changes here.' . PHP_EOL;
$template .= ' * ' . PHP_EOL;
$template .= ' * @param IDatabase $db database instance' . PHP_EOL;
$template .= ' */' . PHP_EOL;
$template .= ' public function migrateDown( IDatabase $db )' . PHP_EOL;
$template .= ' {' . PHP_EOL;
$template .= ' ' . PHP_EOL;
$template .= ' }' . PHP_EOL . PHP_EOL;
$template .= ' /**' . PHP_EOL;
$template .= ' * Alternatively to <code>migrateUp()</code>, this method will' . PHP_EOL;
$template .= ' * use transactions (if available) to process the database changes.' .
PHP_EOL;
$template .= ' * ' . PHP_EOL;
$template .= ' * @param IDatabase $db database instance' . PHP_EOL;
$template .= ' */' . PHP_EOL;
$template .= ' public function safeMigrateUp( IDatabase $db )' . PHP_EOL;
$template .= ' {' . PHP_EOL;
$template .= ' ' . PHP_EOL;
$template .= ' }' . PHP_EOL . PHP_EOL;
$template .= ' /**' . PHP_EOL;
$template .= ' * Alternatively to <code>migrateDown()</code>, this method will' .
PHP_EOL;
$template .= ' * use transactions (if available) to revert changes.' . PHP_EOL;
$template .= ' * ' . PHP_EOL;
$template .= ' * @param IDatabase $db database instance' . PHP_EOL;
$template .= ' */' . PHP_EOL;
$template .= ' public function safeMigrateDown( IDatabase $db )' . PHP_EOL;
$template .= ' {' . PHP_EOL;
$template .= ' ' . PHP_EOL;
$template .= ' }' . PHP_EOL;
$template .= '}';
return $this->filter( self::ON_GET_MIGRATION_TEMPLATE_FILTER, $template, $name );
} | php | public function getMigrationTemplate( $name )
{
$template = '<?php' . PHP_EOL . PHP_EOL;
if ( '' !== $this->migrationNamespace )
{
$template .= 'namespace ' . $this->migrationNamespace . ';' . PHP_EOL . PHP_EOL;
}
$template .= 'use RawPHP\RawMigrator\Migration;' . PHP_EOL;
$template .= 'use RawPHP\RawDatabase\IDatabase;' . PHP_EOL . PHP_EOL;
$template .= 'class ' . $name . ' extends Migration' . PHP_EOL;
$template .= '{' . PHP_EOL;
$template .= ' /**' . PHP_EOL;
$template .= ' * Implement database changes here.' . PHP_EOL;
$template .= ' * ' . PHP_EOL;
$template .= ' * @param IDatabase $db database instance' . PHP_EOL;
$template .= ' */' . PHP_EOL;
$template .= ' public function migrateUp( IDatabase $db )' . PHP_EOL;
$template .= ' {' . PHP_EOL;
$template .= ' ' . PHP_EOL;
$template .= ' }' . PHP_EOL . PHP_EOL;
$template .= ' /**' . PHP_EOL;
$template .= ' * Implement reverting changes here.' . PHP_EOL;
$template .= ' * ' . PHP_EOL;
$template .= ' * @param IDatabase $db database instance' . PHP_EOL;
$template .= ' */' . PHP_EOL;
$template .= ' public function migrateDown( IDatabase $db )' . PHP_EOL;
$template .= ' {' . PHP_EOL;
$template .= ' ' . PHP_EOL;
$template .= ' }' . PHP_EOL . PHP_EOL;
$template .= ' /**' . PHP_EOL;
$template .= ' * Alternatively to <code>migrateUp()</code>, this method will' . PHP_EOL;
$template .= ' * use transactions (if available) to process the database changes.' .
PHP_EOL;
$template .= ' * ' . PHP_EOL;
$template .= ' * @param IDatabase $db database instance' . PHP_EOL;
$template .= ' */' . PHP_EOL;
$template .= ' public function safeMigrateUp( IDatabase $db )' . PHP_EOL;
$template .= ' {' . PHP_EOL;
$template .= ' ' . PHP_EOL;
$template .= ' }' . PHP_EOL . PHP_EOL;
$template .= ' /**' . PHP_EOL;
$template .= ' * Alternatively to <code>migrateDown()</code>, this method will' .
PHP_EOL;
$template .= ' * use transactions (if available) to revert changes.' . PHP_EOL;
$template .= ' * ' . PHP_EOL;
$template .= ' * @param IDatabase $db database instance' . PHP_EOL;
$template .= ' */' . PHP_EOL;
$template .= ' public function safeMigrateDown( IDatabase $db )' . PHP_EOL;
$template .= ' {' . PHP_EOL;
$template .= ' ' . PHP_EOL;
$template .= ' }' . PHP_EOL;
$template .= '}';
return $this->filter( self::ON_GET_MIGRATION_TEMPLATE_FILTER, $template, $name );
} | [
"public",
"function",
"getMigrationTemplate",
"(",
"$",
"name",
")",
"{",
"$",
"template",
"=",
"'<?php'",
".",
"PHP_EOL",
".",
"PHP_EOL",
";",
"if",
"(",
"''",
"!==",
"$",
"this",
"->",
"migrationNamespace",
")",
"{",
"$",
"template",
".=",
"'namespace '",
".",
"$",
"this",
"->",
"migrationNamespace",
".",
"';'",
".",
"PHP_EOL",
".",
"PHP_EOL",
";",
"}",
"$",
"template",
".=",
"'use RawPHP\\RawMigrator\\Migration;'",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"'use RawPHP\\RawDatabase\\IDatabase;'",
".",
"PHP_EOL",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"'class '",
".",
"$",
"name",
".",
"' extends Migration'",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"'{'",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' /**'",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' * Implement database changes here.'",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' * '",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' * @param IDatabase $db database instance'",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' */'",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' public function migrateUp( IDatabase $db )'",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' {'",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' '",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' }'",
".",
"PHP_EOL",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' /**'",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' * Implement reverting changes here.'",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' * '",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' * @param IDatabase $db database instance'",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' */'",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' public function migrateDown( IDatabase $db )'",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' {'",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' '",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' }'",
".",
"PHP_EOL",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' /**'",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' * Alternatively to <code>migrateUp()</code>, this method will'",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' * use transactions (if available) to process the database changes.'",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' * '",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' * @param IDatabase $db database instance'",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' */'",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' public function safeMigrateUp( IDatabase $db )'",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' {'",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' '",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' }'",
".",
"PHP_EOL",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' /**'",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' * Alternatively to <code>migrateDown()</code>, this method will'",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' * use transactions (if available) to revert changes.'",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' * '",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' * @param IDatabase $db database instance'",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' */'",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' public function safeMigrateDown( IDatabase $db )'",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' {'",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' '",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"' }'",
".",
"PHP_EOL",
";",
"$",
"template",
".=",
"'}'",
";",
"return",
"$",
"this",
"->",
"filter",
"(",
"self",
"::",
"ON_GET_MIGRATION_TEMPLATE_FILTER",
",",
"$",
"template",
",",
"$",
"name",
")",
";",
"}"
] | Creates the migration template file code.
@param string $name new migration class name
@filter ON_GET_MIGRATION_TEMPLATE_FILTER
@return string class template | [
"Creates",
"the",
"migration",
"template",
"file",
"code",
"."
] | bbf5e354d7ff532552fd6865b38e4c1a3b6f3757 | https://github.com/rawphp/RawMigrator/blob/bbf5e354d7ff532552fd6865b38e4c1a3b6f3757/lib/Migrator.php#L214-L275 | train |
rawphp/RawMigrator | lib/Migrator.php | Migrator.createMigrationTable | public function createMigrationTable( )
{
if ( empty( $this->migrationTable ) )
{
throw new RawException( 'Migration table name must be set' );
}
$result = NULL;
$table = array(
'migration_id' => 'INTEGER(11) PRIMARY KEY AUTO_INCREMENT NOT NULL',
'migration_name' => 'VARCHAR(128) NOT NULL',
'migration_date_applied' => 'BIGINT(20) NOT NULL',
);
if ( TRUE === $this->db->createTable( $this->migrationTable, $table ) )
{
$result = $this->db->addIndex( $this->migrationTable, array( 'migration_name' ) );
}
$this->doAction( self::ON_CREATE_MIGRATION_TABLE_ACTION );
return $result;
} | php | public function createMigrationTable( )
{
if ( empty( $this->migrationTable ) )
{
throw new RawException( 'Migration table name must be set' );
}
$result = NULL;
$table = array(
'migration_id' => 'INTEGER(11) PRIMARY KEY AUTO_INCREMENT NOT NULL',
'migration_name' => 'VARCHAR(128) NOT NULL',
'migration_date_applied' => 'BIGINT(20) NOT NULL',
);
if ( TRUE === $this->db->createTable( $this->migrationTable, $table ) )
{
$result = $this->db->addIndex( $this->migrationTable, array( 'migration_name' ) );
}
$this->doAction( self::ON_CREATE_MIGRATION_TABLE_ACTION );
return $result;
} | [
"public",
"function",
"createMigrationTable",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"migrationTable",
")",
")",
"{",
"throw",
"new",
"RawException",
"(",
"'Migration table name must be set'",
")",
";",
"}",
"$",
"result",
"=",
"NULL",
";",
"$",
"table",
"=",
"array",
"(",
"'migration_id'",
"=>",
"'INTEGER(11) PRIMARY KEY AUTO_INCREMENT NOT NULL'",
",",
"'migration_name'",
"=>",
"'VARCHAR(128) NOT NULL'",
",",
"'migration_date_applied'",
"=>",
"'BIGINT(20) NOT NULL'",
",",
")",
";",
"if",
"(",
"TRUE",
"===",
"$",
"this",
"->",
"db",
"->",
"createTable",
"(",
"$",
"this",
"->",
"migrationTable",
",",
"$",
"table",
")",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"db",
"->",
"addIndex",
"(",
"$",
"this",
"->",
"migrationTable",
",",
"array",
"(",
"'migration_name'",
")",
")",
";",
"}",
"$",
"this",
"->",
"doAction",
"(",
"self",
"::",
"ON_CREATE_MIGRATION_TABLE_ACTION",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Creates the migration database table if it doesn't exist.
@action ON_CREATE_MIGRATION_TABLE_ACTION
@return bool TRUE on success, FALSE on failure
@throws RawException if migration table is not set | [
"Creates",
"the",
"migration",
"database",
"table",
"if",
"it",
"doesn",
"t",
"exist",
"."
] | bbf5e354d7ff532552fd6865b38e4c1a3b6f3757 | https://github.com/rawphp/RawMigrator/blob/bbf5e354d7ff532552fd6865b38e4c1a3b6f3757/lib/Migrator.php#L286-L309 | train |
rawphp/RawMigrator | lib/Migrator.php | Migrator.getMigrations | public function getMigrations( )
{
$migrations = array();
$dir = opendir( $this->migrationPath );
while ( ( $file = readdir( $dir ) ) !== FALSE )
{
if ( '.' !== $file && '..' !== $file )
{
$migrations[] = str_replace( '.php', '', $file );
}
}
closedir( $dir );
usort( $migrations, array( $this, '_sortMigrations' ) );
return $this->filter( self::ON_GET_MIGRATIONS_FILTER, $migrations );
} | php | public function getMigrations( )
{
$migrations = array();
$dir = opendir( $this->migrationPath );
while ( ( $file = readdir( $dir ) ) !== FALSE )
{
if ( '.' !== $file && '..' !== $file )
{
$migrations[] = str_replace( '.php', '', $file );
}
}
closedir( $dir );
usort( $migrations, array( $this, '_sortMigrations' ) );
return $this->filter( self::ON_GET_MIGRATIONS_FILTER, $migrations );
} | [
"public",
"function",
"getMigrations",
"(",
")",
"{",
"$",
"migrations",
"=",
"array",
"(",
")",
";",
"$",
"dir",
"=",
"opendir",
"(",
"$",
"this",
"->",
"migrationPath",
")",
";",
"while",
"(",
"(",
"$",
"file",
"=",
"readdir",
"(",
"$",
"dir",
")",
")",
"!==",
"FALSE",
")",
"{",
"if",
"(",
"'.'",
"!==",
"$",
"file",
"&&",
"'..'",
"!==",
"$",
"file",
")",
"{",
"$",
"migrations",
"[",
"]",
"=",
"str_replace",
"(",
"'.php'",
",",
"''",
",",
"$",
"file",
")",
";",
"}",
"}",
"closedir",
"(",
"$",
"dir",
")",
";",
"usort",
"(",
"$",
"migrations",
",",
"array",
"(",
"$",
"this",
",",
"'_sortMigrations'",
")",
")",
";",
"return",
"$",
"this",
"->",
"filter",
"(",
"self",
"::",
"ON_GET_MIGRATIONS_FILTER",
",",
"$",
"migrations",
")",
";",
"}"
] | Returns a list of migration files.
@filter ON_GET_MIGRATIONS_FILTER
@return array list of available migrations | [
"Returns",
"a",
"list",
"of",
"migration",
"files",
"."
] | bbf5e354d7ff532552fd6865b38e4c1a3b6f3757 | https://github.com/rawphp/RawMigrator/blob/bbf5e354d7ff532552fd6865b38e4c1a3b6f3757/lib/Migrator.php#L318-L337 | train |
rawphp/RawMigrator | lib/Migrator.php | Migrator.getNewMigrations | public function getNewMigrations( )
{
// check if migration table exists
$exists = $this->db->tableExists( $this->migrationTable );
if ( !$exists )
{
$this->createMigrationTable( );
}
$query = "SELECT * FROM $this->migrationTable";
$applied = $this->db->query( $query );
$migrations = $this->getMigrations();
$list = array();
foreach( $migrations as $migration )
{
$done = FALSE;
$migToFind = NULL;
foreach( $this->namespaces as $ns )
{
$cls = $ns . $migration;
if ( class_exists( $cls ) )
{
$migToFind = $cls;
break;
}
}
foreach( $applied as $mig )
{
if ( $mig[ 'migration_name' ] === $migToFind )
{
$done = TRUE;
break;
}
}
if ( !$done )
{
$list[] = $migration;
}
}
return $this->filter( self::ON_GET_NEW_MIGRATIONS_FILTER, $list );
} | php | public function getNewMigrations( )
{
// check if migration table exists
$exists = $this->db->tableExists( $this->migrationTable );
if ( !$exists )
{
$this->createMigrationTable( );
}
$query = "SELECT * FROM $this->migrationTable";
$applied = $this->db->query( $query );
$migrations = $this->getMigrations();
$list = array();
foreach( $migrations as $migration )
{
$done = FALSE;
$migToFind = NULL;
foreach( $this->namespaces as $ns )
{
$cls = $ns . $migration;
if ( class_exists( $cls ) )
{
$migToFind = $cls;
break;
}
}
foreach( $applied as $mig )
{
if ( $mig[ 'migration_name' ] === $migToFind )
{
$done = TRUE;
break;
}
}
if ( !$done )
{
$list[] = $migration;
}
}
return $this->filter( self::ON_GET_NEW_MIGRATIONS_FILTER, $list );
} | [
"public",
"function",
"getNewMigrations",
"(",
")",
"{",
"// check if migration table exists",
"$",
"exists",
"=",
"$",
"this",
"->",
"db",
"->",
"tableExists",
"(",
"$",
"this",
"->",
"migrationTable",
")",
";",
"if",
"(",
"!",
"$",
"exists",
")",
"{",
"$",
"this",
"->",
"createMigrationTable",
"(",
")",
";",
"}",
"$",
"query",
"=",
"\"SELECT * FROM $this->migrationTable\"",
";",
"$",
"applied",
"=",
"$",
"this",
"->",
"db",
"->",
"query",
"(",
"$",
"query",
")",
";",
"$",
"migrations",
"=",
"$",
"this",
"->",
"getMigrations",
"(",
")",
";",
"$",
"list",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"migrations",
"as",
"$",
"migration",
")",
"{",
"$",
"done",
"=",
"FALSE",
";",
"$",
"migToFind",
"=",
"NULL",
";",
"foreach",
"(",
"$",
"this",
"->",
"namespaces",
"as",
"$",
"ns",
")",
"{",
"$",
"cls",
"=",
"$",
"ns",
".",
"$",
"migration",
";",
"if",
"(",
"class_exists",
"(",
"$",
"cls",
")",
")",
"{",
"$",
"migToFind",
"=",
"$",
"cls",
";",
"break",
";",
"}",
"}",
"foreach",
"(",
"$",
"applied",
"as",
"$",
"mig",
")",
"{",
"if",
"(",
"$",
"mig",
"[",
"'migration_name'",
"]",
"===",
"$",
"migToFind",
")",
"{",
"$",
"done",
"=",
"TRUE",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"done",
")",
"{",
"$",
"list",
"[",
"]",
"=",
"$",
"migration",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"filter",
"(",
"self",
"::",
"ON_GET_NEW_MIGRATIONS_FILTER",
",",
"$",
"list",
")",
";",
"}"
] | Returns a list of new migrations.
@filter ON_GET_NEW_MIGRATIONS_FILTER
@return array list of migrations | [
"Returns",
"a",
"list",
"of",
"new",
"migrations",
"."
] | bbf5e354d7ff532552fd6865b38e4c1a3b6f3757 | https://github.com/rawphp/RawMigrator/blob/bbf5e354d7ff532552fd6865b38e4c1a3b6f3757/lib/Migrator.php#L346-L397 | train |
rawphp/RawMigrator | lib/Migrator.php | Migrator.getAppliedMigrations | public function getAppliedMigrations( )
{
$query = "SELECT * FROM $this->migrationTable";
$applied = $this->db->query( $query );
$list = array();
foreach( $applied as $mig )
{
$list[] = $mig[ 'migration_name' ];
}
$list = array_reverse( $list );
return $this->filter( self::ON_GET_APPLIED_MIGRATIONS_FILTER, $list );
} | php | public function getAppliedMigrations( )
{
$query = "SELECT * FROM $this->migrationTable";
$applied = $this->db->query( $query );
$list = array();
foreach( $applied as $mig )
{
$list[] = $mig[ 'migration_name' ];
}
$list = array_reverse( $list );
return $this->filter( self::ON_GET_APPLIED_MIGRATIONS_FILTER, $list );
} | [
"public",
"function",
"getAppliedMigrations",
"(",
")",
"{",
"$",
"query",
"=",
"\"SELECT * FROM $this->migrationTable\"",
";",
"$",
"applied",
"=",
"$",
"this",
"->",
"db",
"->",
"query",
"(",
"$",
"query",
")",
";",
"$",
"list",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"applied",
"as",
"$",
"mig",
")",
"{",
"$",
"list",
"[",
"]",
"=",
"$",
"mig",
"[",
"'migration_name'",
"]",
";",
"}",
"$",
"list",
"=",
"array_reverse",
"(",
"$",
"list",
")",
";",
"return",
"$",
"this",
"->",
"filter",
"(",
"self",
"::",
"ON_GET_APPLIED_MIGRATIONS_FILTER",
",",
"$",
"list",
")",
";",
"}"
] | Returns a list of applied migrations.
@filter ON_GET_APPLIED_MIGRATIONS_FILTER
@return array list of applied migrations | [
"Returns",
"a",
"list",
"of",
"applied",
"migrations",
"."
] | bbf5e354d7ff532552fd6865b38e4c1a3b6f3757 | https://github.com/rawphp/RawMigrator/blob/bbf5e354d7ff532552fd6865b38e4c1a3b6f3757/lib/Migrator.php#L406-L422 | train |
rawphp/RawMigrator | lib/Migrator.php | Migrator.migrateUp | public function migrateUp( $levels = NULL )
{
if ( NULL !== $levels )
{
$this->levels = $levels;
}
$newMigrations = $this->getNewMigrations( );
$i = 0;
if ( self::MIGRATE_ALL === $this->levels || $this->levels > count( $newMigrations ) )
{
$this->levels = count( $newMigrations );
}
while ( $i < $this->levels )
{
$class = $this->migrationNamespace . '\\' . $newMigrations[ $i ];
if ( !class_exists( $class ) )
{
if ( !array_search( 'RawPHP\\RawMigrator\\Migrations\\', $this->namespaces, TRUE ) )
{
$this->namespaces[] = 'RawPHP\\RawMigrator\\Migrations\\';
}
foreach( $this->namespaces as $ns )
{
$cls = $ns . $newMigrations[ $i ];
if ( class_exists( $cls ) )
{
$class = $cls;
break;
}
}
if ( NULL === $class )
{
throw new MigrationException( 'Migration class: ' . $class . ' - not found' );
}
}
$migration = new $class( );
$method = new \ReflectionMethod( $class, 'migrateUp' );
// run migrateUp
if ( $class === $method->getdeclaringClass()->name )
{
$migration->migrateUp( $this->db );
$this->_addMigrationRecord( $class );
}
else
{
$method = new \ReflectionMethod( $class, 'safeMigrateUp' );
if ( $class === $method->getDeclaringClass()->name )
{
try
{
$this->db->startTransaction( );
// turn off auto commit
$this->db->setTransactionAutocommit( FALSE );
// run safeMigrateUp
$migration->safeMigrateUp( $this->db );
// update migrations table with the new applied migration
$this->_addMigrationRecord( $class );
// commit transaction
$this->db->commitTransaction( );
}
catch ( Exception $e )
{
// roleback transaction
$this->db->rollbackTransaction( );
throw $e;
}
}
}
$i++;
if ( $this->levels === $i )
{
$this->doAction( self::ON_MIGRATE_UP_ACTION );
return;
}
}
} | php | public function migrateUp( $levels = NULL )
{
if ( NULL !== $levels )
{
$this->levels = $levels;
}
$newMigrations = $this->getNewMigrations( );
$i = 0;
if ( self::MIGRATE_ALL === $this->levels || $this->levels > count( $newMigrations ) )
{
$this->levels = count( $newMigrations );
}
while ( $i < $this->levels )
{
$class = $this->migrationNamespace . '\\' . $newMigrations[ $i ];
if ( !class_exists( $class ) )
{
if ( !array_search( 'RawPHP\\RawMigrator\\Migrations\\', $this->namespaces, TRUE ) )
{
$this->namespaces[] = 'RawPHP\\RawMigrator\\Migrations\\';
}
foreach( $this->namespaces as $ns )
{
$cls = $ns . $newMigrations[ $i ];
if ( class_exists( $cls ) )
{
$class = $cls;
break;
}
}
if ( NULL === $class )
{
throw new MigrationException( 'Migration class: ' . $class . ' - not found' );
}
}
$migration = new $class( );
$method = new \ReflectionMethod( $class, 'migrateUp' );
// run migrateUp
if ( $class === $method->getdeclaringClass()->name )
{
$migration->migrateUp( $this->db );
$this->_addMigrationRecord( $class );
}
else
{
$method = new \ReflectionMethod( $class, 'safeMigrateUp' );
if ( $class === $method->getDeclaringClass()->name )
{
try
{
$this->db->startTransaction( );
// turn off auto commit
$this->db->setTransactionAutocommit( FALSE );
// run safeMigrateUp
$migration->safeMigrateUp( $this->db );
// update migrations table with the new applied migration
$this->_addMigrationRecord( $class );
// commit transaction
$this->db->commitTransaction( );
}
catch ( Exception $e )
{
// roleback transaction
$this->db->rollbackTransaction( );
throw $e;
}
}
}
$i++;
if ( $this->levels === $i )
{
$this->doAction( self::ON_MIGRATE_UP_ACTION );
return;
}
}
} | [
"public",
"function",
"migrateUp",
"(",
"$",
"levels",
"=",
"NULL",
")",
"{",
"if",
"(",
"NULL",
"!==",
"$",
"levels",
")",
"{",
"$",
"this",
"->",
"levels",
"=",
"$",
"levels",
";",
"}",
"$",
"newMigrations",
"=",
"$",
"this",
"->",
"getNewMigrations",
"(",
")",
";",
"$",
"i",
"=",
"0",
";",
"if",
"(",
"self",
"::",
"MIGRATE_ALL",
"===",
"$",
"this",
"->",
"levels",
"||",
"$",
"this",
"->",
"levels",
">",
"count",
"(",
"$",
"newMigrations",
")",
")",
"{",
"$",
"this",
"->",
"levels",
"=",
"count",
"(",
"$",
"newMigrations",
")",
";",
"}",
"while",
"(",
"$",
"i",
"<",
"$",
"this",
"->",
"levels",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"migrationNamespace",
".",
"'\\\\'",
".",
"$",
"newMigrations",
"[",
"$",
"i",
"]",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"if",
"(",
"!",
"array_search",
"(",
"'RawPHP\\\\RawMigrator\\\\Migrations\\\\'",
",",
"$",
"this",
"->",
"namespaces",
",",
"TRUE",
")",
")",
"{",
"$",
"this",
"->",
"namespaces",
"[",
"]",
"=",
"'RawPHP\\\\RawMigrator\\\\Migrations\\\\'",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"namespaces",
"as",
"$",
"ns",
")",
"{",
"$",
"cls",
"=",
"$",
"ns",
".",
"$",
"newMigrations",
"[",
"$",
"i",
"]",
";",
"if",
"(",
"class_exists",
"(",
"$",
"cls",
")",
")",
"{",
"$",
"class",
"=",
"$",
"cls",
";",
"break",
";",
"}",
"}",
"if",
"(",
"NULL",
"===",
"$",
"class",
")",
"{",
"throw",
"new",
"MigrationException",
"(",
"'Migration class: '",
".",
"$",
"class",
".",
"' - not found'",
")",
";",
"}",
"}",
"$",
"migration",
"=",
"new",
"$",
"class",
"(",
")",
";",
"$",
"method",
"=",
"new",
"\\",
"ReflectionMethod",
"(",
"$",
"class",
",",
"'migrateUp'",
")",
";",
"// run migrateUp",
"if",
"(",
"$",
"class",
"===",
"$",
"method",
"->",
"getdeclaringClass",
"(",
")",
"->",
"name",
")",
"{",
"$",
"migration",
"->",
"migrateUp",
"(",
"$",
"this",
"->",
"db",
")",
";",
"$",
"this",
"->",
"_addMigrationRecord",
"(",
"$",
"class",
")",
";",
"}",
"else",
"{",
"$",
"method",
"=",
"new",
"\\",
"ReflectionMethod",
"(",
"$",
"class",
",",
"'safeMigrateUp'",
")",
";",
"if",
"(",
"$",
"class",
"===",
"$",
"method",
"->",
"getDeclaringClass",
"(",
")",
"->",
"name",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"db",
"->",
"startTransaction",
"(",
")",
";",
"// turn off auto commit",
"$",
"this",
"->",
"db",
"->",
"setTransactionAutocommit",
"(",
"FALSE",
")",
";",
"// run safeMigrateUp",
"$",
"migration",
"->",
"safeMigrateUp",
"(",
"$",
"this",
"->",
"db",
")",
";",
"// update migrations table with the new applied migration",
"$",
"this",
"->",
"_addMigrationRecord",
"(",
"$",
"class",
")",
";",
"// commit transaction",
"$",
"this",
"->",
"db",
"->",
"commitTransaction",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"// roleback transaction",
"$",
"this",
"->",
"db",
"->",
"rollbackTransaction",
"(",
")",
";",
"throw",
"$",
"e",
";",
"}",
"}",
"}",
"$",
"i",
"++",
";",
"if",
"(",
"$",
"this",
"->",
"levels",
"===",
"$",
"i",
")",
"{",
"$",
"this",
"->",
"doAction",
"(",
"self",
"::",
"ON_MIGRATE_UP_ACTION",
")",
";",
"return",
";",
"}",
"}",
"}"
] | Runs the UP migration.
@param mixed $levels optional migration levels size
@action ON_MIGRATE_UP_ACTION
@throws MigrationException on failed transaction | [
"Runs",
"the",
"UP",
"migration",
"."
] | bbf5e354d7ff532552fd6865b38e4c1a3b6f3757 | https://github.com/rawphp/RawMigrator/blob/bbf5e354d7ff532552fd6865b38e4c1a3b6f3757/lib/Migrator.php#L433-L530 | train |
rawphp/RawMigrator | lib/Migrator.php | Migrator.migrateDown | public function migrateDown( $levels = NULL )
{
if ( NULL !== $levels )
{
$this->levels = $levels;
}
$migrations = $this->getAppliedMigrations( );
$i = 0;
if ( self::MIGRATE_ALL === $this->levels || $this->levels > count( $migrations ) )
{
$this->levels = count( $migrations );
}
while ( $i < $this->levels )
{
$class = $migrations[ $i ];
$migration = new $class( );
$method = new \ReflectionMethod( $class, 'migrateDown' );
// run migrateDown
if ( $class === $method->getDeclaringClass( )->name )
{
$migration->migrateDown( $this->db );
// delete migration from table
if ( FALSE === $this->_deleteMigrationRecord( $class ) )
{
throw new MigrationException( 'Failed to delete migration record: ' . $class );
}
}
else // run safeMigrateDown
{
$method = new \ReflectionMethod( $class, 'safeMigrateDown' );
if ( $class === $method->getDeclaringClass( )->name )
{
try
{
// start transaction
$this->db->startTransaction( );
// turn off auto commit
$this->db->setTransactionAutocommit( FALSE );
// run safeMigrateDown
$migration->safeMigrateDown( $this->db );
// delete migration record
if ( FALSE === $this->_deleteMigrationRecord( $class ) )
{
throw new MigrationException(
'Failed to delete migration record: ' . $class );
$this->db->rollbackTransaction();
}
// commit transaction
$this->db->commitTransaction( );
}
catch ( \Exception $e )
{
// rollback transaction
$this->db->rollbackTransaction( );
throw $e;
}
}
}
$i++;
if ( $this->levels === $i )
{
$this->doAction( self::ON_MIGRATE_DOWN_ACTION );
return;
}
}
} | php | public function migrateDown( $levels = NULL )
{
if ( NULL !== $levels )
{
$this->levels = $levels;
}
$migrations = $this->getAppliedMigrations( );
$i = 0;
if ( self::MIGRATE_ALL === $this->levels || $this->levels > count( $migrations ) )
{
$this->levels = count( $migrations );
}
while ( $i < $this->levels )
{
$class = $migrations[ $i ];
$migration = new $class( );
$method = new \ReflectionMethod( $class, 'migrateDown' );
// run migrateDown
if ( $class === $method->getDeclaringClass( )->name )
{
$migration->migrateDown( $this->db );
// delete migration from table
if ( FALSE === $this->_deleteMigrationRecord( $class ) )
{
throw new MigrationException( 'Failed to delete migration record: ' . $class );
}
}
else // run safeMigrateDown
{
$method = new \ReflectionMethod( $class, 'safeMigrateDown' );
if ( $class === $method->getDeclaringClass( )->name )
{
try
{
// start transaction
$this->db->startTransaction( );
// turn off auto commit
$this->db->setTransactionAutocommit( FALSE );
// run safeMigrateDown
$migration->safeMigrateDown( $this->db );
// delete migration record
if ( FALSE === $this->_deleteMigrationRecord( $class ) )
{
throw new MigrationException(
'Failed to delete migration record: ' . $class );
$this->db->rollbackTransaction();
}
// commit transaction
$this->db->commitTransaction( );
}
catch ( \Exception $e )
{
// rollback transaction
$this->db->rollbackTransaction( );
throw $e;
}
}
}
$i++;
if ( $this->levels === $i )
{
$this->doAction( self::ON_MIGRATE_DOWN_ACTION );
return;
}
}
} | [
"public",
"function",
"migrateDown",
"(",
"$",
"levels",
"=",
"NULL",
")",
"{",
"if",
"(",
"NULL",
"!==",
"$",
"levels",
")",
"{",
"$",
"this",
"->",
"levels",
"=",
"$",
"levels",
";",
"}",
"$",
"migrations",
"=",
"$",
"this",
"->",
"getAppliedMigrations",
"(",
")",
";",
"$",
"i",
"=",
"0",
";",
"if",
"(",
"self",
"::",
"MIGRATE_ALL",
"===",
"$",
"this",
"->",
"levels",
"||",
"$",
"this",
"->",
"levels",
">",
"count",
"(",
"$",
"migrations",
")",
")",
"{",
"$",
"this",
"->",
"levels",
"=",
"count",
"(",
"$",
"migrations",
")",
";",
"}",
"while",
"(",
"$",
"i",
"<",
"$",
"this",
"->",
"levels",
")",
"{",
"$",
"class",
"=",
"$",
"migrations",
"[",
"$",
"i",
"]",
";",
"$",
"migration",
"=",
"new",
"$",
"class",
"(",
")",
";",
"$",
"method",
"=",
"new",
"\\",
"ReflectionMethod",
"(",
"$",
"class",
",",
"'migrateDown'",
")",
";",
"// run migrateDown",
"if",
"(",
"$",
"class",
"===",
"$",
"method",
"->",
"getDeclaringClass",
"(",
")",
"->",
"name",
")",
"{",
"$",
"migration",
"->",
"migrateDown",
"(",
"$",
"this",
"->",
"db",
")",
";",
"// delete migration from table",
"if",
"(",
"FALSE",
"===",
"$",
"this",
"->",
"_deleteMigrationRecord",
"(",
"$",
"class",
")",
")",
"{",
"throw",
"new",
"MigrationException",
"(",
"'Failed to delete migration record: '",
".",
"$",
"class",
")",
";",
"}",
"}",
"else",
"// run safeMigrateDown",
"{",
"$",
"method",
"=",
"new",
"\\",
"ReflectionMethod",
"(",
"$",
"class",
",",
"'safeMigrateDown'",
")",
";",
"if",
"(",
"$",
"class",
"===",
"$",
"method",
"->",
"getDeclaringClass",
"(",
")",
"->",
"name",
")",
"{",
"try",
"{",
"// start transaction",
"$",
"this",
"->",
"db",
"->",
"startTransaction",
"(",
")",
";",
"// turn off auto commit",
"$",
"this",
"->",
"db",
"->",
"setTransactionAutocommit",
"(",
"FALSE",
")",
";",
"// run safeMigrateDown",
"$",
"migration",
"->",
"safeMigrateDown",
"(",
"$",
"this",
"->",
"db",
")",
";",
"// delete migration record",
"if",
"(",
"FALSE",
"===",
"$",
"this",
"->",
"_deleteMigrationRecord",
"(",
"$",
"class",
")",
")",
"{",
"throw",
"new",
"MigrationException",
"(",
"'Failed to delete migration record: '",
".",
"$",
"class",
")",
";",
"$",
"this",
"->",
"db",
"->",
"rollbackTransaction",
"(",
")",
";",
"}",
"// commit transaction",
"$",
"this",
"->",
"db",
"->",
"commitTransaction",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"// rollback transaction",
"$",
"this",
"->",
"db",
"->",
"rollbackTransaction",
"(",
")",
";",
"throw",
"$",
"e",
";",
"}",
"}",
"}",
"$",
"i",
"++",
";",
"if",
"(",
"$",
"this",
"->",
"levels",
"===",
"$",
"i",
")",
"{",
"$",
"this",
"->",
"doAction",
"(",
"self",
"::",
"ON_MIGRATE_DOWN_ACTION",
")",
";",
"return",
";",
"}",
"}",
"}"
] | Runs the DOWN migration.
@param mixed $levels optional migration levels size
@action ON_MIGRATE_DOWN_ACTION
@throws MigrationException on failed transaction | [
"Runs",
"the",
"DOWN",
"migration",
"."
] | bbf5e354d7ff532552fd6865b38e4c1a3b6f3757 | https://github.com/rawphp/RawMigrator/blob/bbf5e354d7ff532552fd6865b38e4c1a3b6f3757/lib/Migrator.php#L541-L624 | train |
rawphp/RawMigrator | lib/Migrator.php | Migrator._addMigrationRecord | private function _addMigrationRecord( $class )
{
$name = $this->db->prepareString( $class );
$tm = new \DateTime();
$tm = $tm->getTimestamp();
// update migrations table with the new applied migration
$query = "INSERT INTO $this->migrationTable
( migration_name, migration_date_applied ) VALUES ( ";
$query .= "'$name', ";
$query .= "$tm";
$query .= " )";
$this->db->lockTables( $this->migrationTable );
$id = $this->db->insert( $query );
if ( $this->verbose )
{
echo 'Migrating: ' . $class . PHP_EOL;
}
$this->db->unlockTables();
return FALSE !== $id;
} | php | private function _addMigrationRecord( $class )
{
$name = $this->db->prepareString( $class );
$tm = new \DateTime();
$tm = $tm->getTimestamp();
// update migrations table with the new applied migration
$query = "INSERT INTO $this->migrationTable
( migration_name, migration_date_applied ) VALUES ( ";
$query .= "'$name', ";
$query .= "$tm";
$query .= " )";
$this->db->lockTables( $this->migrationTable );
$id = $this->db->insert( $query );
if ( $this->verbose )
{
echo 'Migrating: ' . $class . PHP_EOL;
}
$this->db->unlockTables();
return FALSE !== $id;
} | [
"private",
"function",
"_addMigrationRecord",
"(",
"$",
"class",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"db",
"->",
"prepareString",
"(",
"$",
"class",
")",
";",
"$",
"tm",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"$",
"tm",
"=",
"$",
"tm",
"->",
"getTimestamp",
"(",
")",
";",
"// update migrations table with the new applied migration",
"$",
"query",
"=",
"\"INSERT INTO $this->migrationTable \n ( migration_name, migration_date_applied ) VALUES ( \"",
";",
"$",
"query",
".=",
"\"'$name', \"",
";",
"$",
"query",
".=",
"\"$tm\"",
";",
"$",
"query",
".=",
"\" )\"",
";",
"$",
"this",
"->",
"db",
"->",
"lockTables",
"(",
"$",
"this",
"->",
"migrationTable",
")",
";",
"$",
"id",
"=",
"$",
"this",
"->",
"db",
"->",
"insert",
"(",
"$",
"query",
")",
";",
"if",
"(",
"$",
"this",
"->",
"verbose",
")",
"{",
"echo",
"'Migrating: '",
".",
"$",
"class",
".",
"PHP_EOL",
";",
"}",
"$",
"this",
"->",
"db",
"->",
"unlockTables",
"(",
")",
";",
"return",
"FALSE",
"!==",
"$",
"id",
";",
"}"
] | Inserts an applied migration into the database.
@param string $class migration name
@return bool TRUE on success, FALSE on failure | [
"Inserts",
"an",
"applied",
"migration",
"into",
"the",
"database",
"."
] | bbf5e354d7ff532552fd6865b38e4c1a3b6f3757 | https://github.com/rawphp/RawMigrator/blob/bbf5e354d7ff532552fd6865b38e4c1a3b6f3757/lib/Migrator.php#L633-L660 | train |
rawphp/RawMigrator | lib/Migrator.php | Migrator._deleteMigrationRecord | private function _deleteMigrationRecord( $class )
{
$name = $this->db->prepareString( $class );
$query = "DELETE FROM $this->migrationTable WHERE migration_name = '$name'";
$this->db->lockTables( $this->migrationTable );
$result = $this->db->execute( $query );
if ( $this->verbose )
{
echo 'Deleting: ' . $class . PHP_EOL;
}
$this->db->unlockTables();
return $result === 1;
} | php | private function _deleteMigrationRecord( $class )
{
$name = $this->db->prepareString( $class );
$query = "DELETE FROM $this->migrationTable WHERE migration_name = '$name'";
$this->db->lockTables( $this->migrationTable );
$result = $this->db->execute( $query );
if ( $this->verbose )
{
echo 'Deleting: ' . $class . PHP_EOL;
}
$this->db->unlockTables();
return $result === 1;
} | [
"private",
"function",
"_deleteMigrationRecord",
"(",
"$",
"class",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"db",
"->",
"prepareString",
"(",
"$",
"class",
")",
";",
"$",
"query",
"=",
"\"DELETE FROM $this->migrationTable WHERE migration_name = '$name'\"",
";",
"$",
"this",
"->",
"db",
"->",
"lockTables",
"(",
"$",
"this",
"->",
"migrationTable",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"db",
"->",
"execute",
"(",
"$",
"query",
")",
";",
"if",
"(",
"$",
"this",
"->",
"verbose",
")",
"{",
"echo",
"'Deleting: '",
".",
"$",
"class",
".",
"PHP_EOL",
";",
"}",
"$",
"this",
"->",
"db",
"->",
"unlockTables",
"(",
")",
";",
"return",
"$",
"result",
"===",
"1",
";",
"}"
] | Deletes a migration entry from the database.
@param string $class migration name
@return bool TRUE on success, FALSE on failure | [
"Deletes",
"a",
"migration",
"entry",
"from",
"the",
"database",
"."
] | bbf5e354d7ff532552fd6865b38e4c1a3b6f3757 | https://github.com/rawphp/RawMigrator/blob/bbf5e354d7ff532552fd6865b38e4c1a3b6f3757/lib/Migrator.php#L669-L687 | train |
CascadeEnergy/distributed-locking | src/DistributedLocking/LockSet/DefaultLockSet.php | DefaultLockSet.lock | public function lock($lockName)
{
$lockHandle = $this->lockProvider->lock($lockName);
if ($lockHandle === false) {
return false;
}
$this->lockList[$lockName] = $lockHandle;
return true;
} | php | public function lock($lockName)
{
$lockHandle = $this->lockProvider->lock($lockName);
if ($lockHandle === false) {
return false;
}
$this->lockList[$lockName] = $lockHandle;
return true;
} | [
"public",
"function",
"lock",
"(",
"$",
"lockName",
")",
"{",
"$",
"lockHandle",
"=",
"$",
"this",
"->",
"lockProvider",
"->",
"lock",
"(",
"$",
"lockName",
")",
";",
"if",
"(",
"$",
"lockHandle",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"lockList",
"[",
"$",
"lockName",
"]",
"=",
"$",
"lockHandle",
";",
"return",
"true",
";",
"}"
] | Attempts to acquire a single lock by name, and adds it to the lock set.
@param string $lockName The name of the lock to acquire
@return bool True if the lock was acquired, false otherwise | [
"Attempts",
"to",
"acquire",
"a",
"single",
"lock",
"by",
"name",
"and",
"adds",
"it",
"to",
"the",
"lock",
"set",
"."
] | 866e5aa41398ec33f7113b42663437005caf498a | https://github.com/CascadeEnergy/distributed-locking/blob/866e5aa41398ec33f7113b42663437005caf498a/src/DistributedLocking/LockSet/DefaultLockSet.php#L42-L52 | train |
Xsaven/laravel-intelect-admin | src/Addons/JWTAuth/Payload.php | Payload.toArray | public function toArray()
{
$results = [];
foreach ($this->claims as $claim) {
$results[$claim->getName()] = $claim->getValue();
}
return $results;
} | php | public function toArray()
{
$results = [];
foreach ($this->claims as $claim) {
$results[$claim->getName()] = $claim->getValue();
}
return $results;
} | [
"public",
"function",
"toArray",
"(",
")",
"{",
"$",
"results",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"claims",
"as",
"$",
"claim",
")",
"{",
"$",
"results",
"[",
"$",
"claim",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"claim",
"->",
"getValue",
"(",
")",
";",
"}",
"return",
"$",
"results",
";",
"}"
] | Get the array of claims.
@return array | [
"Get",
"the",
"array",
"of",
"claims",
"."
] | 592574633d12c74cf25b43dd6694fee496abefcb | https://github.com/Xsaven/laravel-intelect-admin/blob/592574633d12c74cf25b43dd6694fee496abefcb/src/Addons/JWTAuth/Payload.php#L47-L55 | train |
melisplatform/melis-calendar | src/Service/MelisCalendarService.php | MelisCalendarService.addCalendarEvent | public function addCalendarEvent($postValues){
$responseData = array();
$calendarTable = $this->getServiceLocator()->get('MelisCalendarTable');
$melisCoreAuth = $this->getServiceLocator()->get('MelisCoreAuth');
$userAuthDatas = $melisCoreAuth->getStorage()->read();
$userId = (int) $userAuthDatas->usr_id;
if (!isset($postValues['cal_id']))
{
$postValues['cal_date_end'] = $postValues['cal_date_start'];
$postValues['cal_date_last_update'] = $postValues['cal_date_start'];
$postValues['cal_date_added'] = date('Y-m-d H:i:s');
$postValues['cal_last_update_by'] = $userId;
$postValues['cal_created_by'] = $userId;
$eventId = $calendarTable->save($postValues);
$responseData = array(
'id' => $eventId,
'title' => $postValues['cal_event_title'],
'start' => $postValues['cal_date_start'],
'end' => $postValues['cal_date_end'],
);
}
else
{
$resultEvent = $calendarTable->getEntryById($postValues['cal_id']);
if (!empty($resultEvent)){
$event = $resultEvent->current();
if (!empty($event)){
$postValues['cal_last_update_by'] = $userId;
$postValues['cal_date_last_update'] = date('Y-m-d H:i:s');
$calendarTable->save($postValues,$postValues['cal_id']);
$responseData = array(
'id' => $postValues['cal_id'],
'title' => $postValues['cal_event_title'],
);
}
}
}
return $responseData;
} | php | public function addCalendarEvent($postValues){
$responseData = array();
$calendarTable = $this->getServiceLocator()->get('MelisCalendarTable');
$melisCoreAuth = $this->getServiceLocator()->get('MelisCoreAuth');
$userAuthDatas = $melisCoreAuth->getStorage()->read();
$userId = (int) $userAuthDatas->usr_id;
if (!isset($postValues['cal_id']))
{
$postValues['cal_date_end'] = $postValues['cal_date_start'];
$postValues['cal_date_last_update'] = $postValues['cal_date_start'];
$postValues['cal_date_added'] = date('Y-m-d H:i:s');
$postValues['cal_last_update_by'] = $userId;
$postValues['cal_created_by'] = $userId;
$eventId = $calendarTable->save($postValues);
$responseData = array(
'id' => $eventId,
'title' => $postValues['cal_event_title'],
'start' => $postValues['cal_date_start'],
'end' => $postValues['cal_date_end'],
);
}
else
{
$resultEvent = $calendarTable->getEntryById($postValues['cal_id']);
if (!empty($resultEvent)){
$event = $resultEvent->current();
if (!empty($event)){
$postValues['cal_last_update_by'] = $userId;
$postValues['cal_date_last_update'] = date('Y-m-d H:i:s');
$calendarTable->save($postValues,$postValues['cal_id']);
$responseData = array(
'id' => $postValues['cal_id'],
'title' => $postValues['cal_event_title'],
);
}
}
}
return $responseData;
} | [
"public",
"function",
"addCalendarEvent",
"(",
"$",
"postValues",
")",
"{",
"$",
"responseData",
"=",
"array",
"(",
")",
";",
"$",
"calendarTable",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'MelisCalendarTable'",
")",
";",
"$",
"melisCoreAuth",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'MelisCoreAuth'",
")",
";",
"$",
"userAuthDatas",
"=",
"$",
"melisCoreAuth",
"->",
"getStorage",
"(",
")",
"->",
"read",
"(",
")",
";",
"$",
"userId",
"=",
"(",
"int",
")",
"$",
"userAuthDatas",
"->",
"usr_id",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"postValues",
"[",
"'cal_id'",
"]",
")",
")",
"{",
"$",
"postValues",
"[",
"'cal_date_end'",
"]",
"=",
"$",
"postValues",
"[",
"'cal_date_start'",
"]",
";",
"$",
"postValues",
"[",
"'cal_date_last_update'",
"]",
"=",
"$",
"postValues",
"[",
"'cal_date_start'",
"]",
";",
"$",
"postValues",
"[",
"'cal_date_added'",
"]",
"=",
"date",
"(",
"'Y-m-d H:i:s'",
")",
";",
"$",
"postValues",
"[",
"'cal_last_update_by'",
"]",
"=",
"$",
"userId",
";",
"$",
"postValues",
"[",
"'cal_created_by'",
"]",
"=",
"$",
"userId",
";",
"$",
"eventId",
"=",
"$",
"calendarTable",
"->",
"save",
"(",
"$",
"postValues",
")",
";",
"$",
"responseData",
"=",
"array",
"(",
"'id'",
"=>",
"$",
"eventId",
",",
"'title'",
"=>",
"$",
"postValues",
"[",
"'cal_event_title'",
"]",
",",
"'start'",
"=>",
"$",
"postValues",
"[",
"'cal_date_start'",
"]",
",",
"'end'",
"=>",
"$",
"postValues",
"[",
"'cal_date_end'",
"]",
",",
")",
";",
"}",
"else",
"{",
"$",
"resultEvent",
"=",
"$",
"calendarTable",
"->",
"getEntryById",
"(",
"$",
"postValues",
"[",
"'cal_id'",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"resultEvent",
")",
")",
"{",
"$",
"event",
"=",
"$",
"resultEvent",
"->",
"current",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"event",
")",
")",
"{",
"$",
"postValues",
"[",
"'cal_last_update_by'",
"]",
"=",
"$",
"userId",
";",
"$",
"postValues",
"[",
"'cal_date_last_update'",
"]",
"=",
"date",
"(",
"'Y-m-d H:i:s'",
")",
";",
"$",
"calendarTable",
"->",
"save",
"(",
"$",
"postValues",
",",
"$",
"postValues",
"[",
"'cal_id'",
"]",
")",
";",
"$",
"responseData",
"=",
"array",
"(",
"'id'",
"=>",
"$",
"postValues",
"[",
"'cal_id'",
"]",
",",
"'title'",
"=>",
"$",
"postValues",
"[",
"'cal_event_title'",
"]",
",",
")",
";",
"}",
"}",
"}",
"return",
"$",
"responseData",
";",
"}"
] | Adding and Updating Calendar Event
@param array $postValues
if the action is adding new Event, the postValues containing
cal_event_title
cal_date_start
if the action is updating the Event title, the postValues containing
cal_id
cal_event_title
cal_date_start
@return Array | [
"Adding",
"and",
"Updating",
"Calendar",
"Event"
] | 1e6df34adc14f03dfdcc6e4ac05d4fa08cb7d223 | https://github.com/melisplatform/melis-calendar/blob/1e6df34adc14f03dfdcc6e4ac05d4fa08cb7d223/src/Service/MelisCalendarService.php#L48-L101 | train |
melisplatform/melis-calendar | src/Service/MelisCalendarService.php | MelisCalendarService.deleteCalendarEvent | public function deleteCalendarEvent($postValues)
{
$calId = null;
$calendarTable = $this->getServiceLocator()->get('MelisCalendarTable');
$resultEvent = $calendarTable->getEntryById($postValues['cal_id']);
if (!empty($resultEvent)){
$event = $resultEvent->current();
if (!empty($event)){
$calId = $calendarTable->deleteById($postValues['cal_id']);
}
}
return $calId;
} | php | public function deleteCalendarEvent($postValues)
{
$calId = null;
$calendarTable = $this->getServiceLocator()->get('MelisCalendarTable');
$resultEvent = $calendarTable->getEntryById($postValues['cal_id']);
if (!empty($resultEvent)){
$event = $resultEvent->current();
if (!empty($event)){
$calId = $calendarTable->deleteById($postValues['cal_id']);
}
}
return $calId;
} | [
"public",
"function",
"deleteCalendarEvent",
"(",
"$",
"postValues",
")",
"{",
"$",
"calId",
"=",
"null",
";",
"$",
"calendarTable",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'MelisCalendarTable'",
")",
";",
"$",
"resultEvent",
"=",
"$",
"calendarTable",
"->",
"getEntryById",
"(",
"$",
"postValues",
"[",
"'cal_id'",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"resultEvent",
")",
")",
"{",
"$",
"event",
"=",
"$",
"resultEvent",
"->",
"current",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"event",
")",
")",
"{",
"$",
"calId",
"=",
"$",
"calendarTable",
"->",
"deleteById",
"(",
"$",
"postValues",
"[",
"'cal_id'",
"]",
")",
";",
"}",
"}",
"return",
"$",
"calId",
";",
"}"
] | Deleting Calendar Item Event
@param Array $postValues, this containing the calendar id $postValues['cal_id']
@return Int|null if the deletion is failed | [
"Deleting",
"Calendar",
"Item",
"Event"
] | 1e6df34adc14f03dfdcc6e4ac05d4fa08cb7d223 | https://github.com/melisplatform/melis-calendar/blob/1e6df34adc14f03dfdcc6e4ac05d4fa08cb7d223/src/Service/MelisCalendarService.php#L146-L162 | train |
ciims/ciims-modules-api | components/ApiAccessControlFilter.php | ApiAccessControlFilter.accessDenied | protected function accessDenied($user,$message=NULL)
{
http_response_code(403);
Yii::app()->controller->renderOutput(array(), 403, $message);
} | php | protected function accessDenied($user,$message=NULL)
{
http_response_code(403);
Yii::app()->controller->renderOutput(array(), 403, $message);
} | [
"protected",
"function",
"accessDenied",
"(",
"$",
"user",
",",
"$",
"message",
"=",
"NULL",
")",
"{",
"http_response_code",
"(",
"403",
")",
";",
"Yii",
"::",
"app",
"(",
")",
"->",
"controller",
"->",
"renderOutput",
"(",
"array",
"(",
")",
",",
"403",
",",
"$",
"message",
")",
";",
"}"
] | Denies the access of the user.
This method is invoked when access check fails.
@param IWebUser $user the current user
@param string $message the error message to be displayed | [
"Denies",
"the",
"access",
"of",
"the",
"user",
".",
"This",
"method",
"is",
"invoked",
"when",
"access",
"check",
"fails",
"."
] | 4351855328da0b112ac27bde7e7e07e212be8689 | https://github.com/ciims/ciims-modules-api/blob/4351855328da0b112ac27bde7e7e07e212be8689/components/ApiAccessControlFilter.php#L93-L97 | train |
codemojo-dr/startkit-php-sdk | src/CodeMojo/Client/Services/LoyaltyService.php | LoyaltyService.addLoyaltyPoints | public function addLoyaltyPoints($user_id, $transaction_value, $platform = null, $service = null, $expires_in_days = null, $transaction_id = null, $meta = null, $tag = null, $frozen = false){
$url = $this->authenticationService->getServerEndPoint() . Endpoints::VERSION . Endpoints::BASE_LOYALTY . Endpoints::LOYALTY_CALCULATE;
$params = array(
"customer_id" => $user_id, "transaction" => $transaction_value,
'transaction_id'=> $transaction_id ? $transaction_id : sha1('loyalty_' . $user_id . '_' . time()),
'hold' => $frozen ? 1 : 0, 'meta' => $meta, 'tag' => $tag, "expiry" => $expires_in_days,
"platform" => $platform, "service" => $service
);
$result = $this->authenticationService->getTransport()->fetch($url, $params,'PUT', array(), 0);
return $result['code'] == APIResponse::RESPONSE_SUCCESS;
} | php | public function addLoyaltyPoints($user_id, $transaction_value, $platform = null, $service = null, $expires_in_days = null, $transaction_id = null, $meta = null, $tag = null, $frozen = false){
$url = $this->authenticationService->getServerEndPoint() . Endpoints::VERSION . Endpoints::BASE_LOYALTY . Endpoints::LOYALTY_CALCULATE;
$params = array(
"customer_id" => $user_id, "transaction" => $transaction_value,
'transaction_id'=> $transaction_id ? $transaction_id : sha1('loyalty_' . $user_id . '_' . time()),
'hold' => $frozen ? 1 : 0, 'meta' => $meta, 'tag' => $tag, "expiry" => $expires_in_days,
"platform" => $platform, "service" => $service
);
$result = $this->authenticationService->getTransport()->fetch($url, $params,'PUT', array(), 0);
return $result['code'] == APIResponse::RESPONSE_SUCCESS;
} | [
"public",
"function",
"addLoyaltyPoints",
"(",
"$",
"user_id",
",",
"$",
"transaction_value",
",",
"$",
"platform",
"=",
"null",
",",
"$",
"service",
"=",
"null",
",",
"$",
"expires_in_days",
"=",
"null",
",",
"$",
"transaction_id",
"=",
"null",
",",
"$",
"meta",
"=",
"null",
",",
"$",
"tag",
"=",
"null",
",",
"$",
"frozen",
"=",
"false",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"authenticationService",
"->",
"getServerEndPoint",
"(",
")",
".",
"Endpoints",
"::",
"VERSION",
".",
"Endpoints",
"::",
"BASE_LOYALTY",
".",
"Endpoints",
"::",
"LOYALTY_CALCULATE",
";",
"$",
"params",
"=",
"array",
"(",
"\"customer_id\"",
"=>",
"$",
"user_id",
",",
"\"transaction\"",
"=>",
"$",
"transaction_value",
",",
"'transaction_id'",
"=>",
"$",
"transaction_id",
"?",
"$",
"transaction_id",
":",
"sha1",
"(",
"'loyalty_'",
".",
"$",
"user_id",
".",
"'_'",
".",
"time",
"(",
")",
")",
",",
"'hold'",
"=>",
"$",
"frozen",
"?",
"1",
":",
"0",
",",
"'meta'",
"=>",
"$",
"meta",
",",
"'tag'",
"=>",
"$",
"tag",
",",
"\"expiry\"",
"=>",
"$",
"expires_in_days",
",",
"\"platform\"",
"=>",
"$",
"platform",
",",
"\"service\"",
"=>",
"$",
"service",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"authenticationService",
"->",
"getTransport",
"(",
")",
"->",
"fetch",
"(",
"$",
"url",
",",
"$",
"params",
",",
"'PUT'",
",",
"array",
"(",
")",
",",
"0",
")",
";",
"return",
"$",
"result",
"[",
"'code'",
"]",
"==",
"APIResponse",
"::",
"RESPONSE_SUCCESS",
";",
"}"
] | Add loyalty points to users wallet
@param $user_id
@param $transaction_value
@param null $platform
@param null $service
@param null $expires_in_days
@param null $transaction_id
@param null $meta
@param null $tag
@param bool $frozen
@return bool
@throws \CodeMojo\Client\Http\InvalidArgumentException
@throws \CodeMojo\OAuth2\Exception | [
"Add",
"loyalty",
"points",
"to",
"users",
"wallet"
] | cd2227e1a221be2cd75dc96d1c9e0acfda936fb3 | https://github.com/codemojo-dr/startkit-php-sdk/blob/cd2227e1a221be2cd75dc96d1c9e0acfda936fb3/src/CodeMojo/Client/Services/LoyaltyService.php#L59-L72 | train |
Wedeto/DB | src/Query/UnionClause.php | UnionClause.toSQL | public function toSQL(Parameters $params, bool $inner_clause)
{
$q = $this->getQuery();
$t = $this->getType();
$scope = $params->getSubScope($this->sub_scope_number);
$this->sub_scope_number = $scope->getScopeID();
return 'UNION ' . $t . ' (' . $params->getDriver()->toSQL($scope, $q) . ')';
} | php | public function toSQL(Parameters $params, bool $inner_clause)
{
$q = $this->getQuery();
$t = $this->getType();
$scope = $params->getSubScope($this->sub_scope_number);
$this->sub_scope_number = $scope->getScopeID();
return 'UNION ' . $t . ' (' . $params->getDriver()->toSQL($scope, $q) . ')';
} | [
"public",
"function",
"toSQL",
"(",
"Parameters",
"$",
"params",
",",
"bool",
"$",
"inner_clause",
")",
"{",
"$",
"q",
"=",
"$",
"this",
"->",
"getQuery",
"(",
")",
";",
"$",
"t",
"=",
"$",
"this",
"->",
"getType",
"(",
")",
";",
"$",
"scope",
"=",
"$",
"params",
"->",
"getSubScope",
"(",
"$",
"this",
"->",
"sub_scope_number",
")",
";",
"$",
"this",
"->",
"sub_scope_number",
"=",
"$",
"scope",
"->",
"getScopeID",
"(",
")",
";",
"return",
"'UNION '",
".",
"$",
"t",
".",
"' ('",
".",
"$",
"params",
"->",
"getDriver",
"(",
")",
"->",
"toSQL",
"(",
"$",
"scope",
",",
"$",
"q",
")",
".",
"')'",
";",
"}"
] | Write a UNION clause as SQL query synta
@param Parameters $params The query parameters: tables and placeholder values
@param bool $inner_clause Unused
@return string The generated SQL | [
"Write",
"a",
"UNION",
"clause",
"as",
"SQL",
"query",
"synta"
] | 715f8f2e3ae6b53c511c40b620921cb9c87e6f62 | https://github.com/Wedeto/DB/blob/715f8f2e3ae6b53c511c40b620921cb9c87e6f62/src/Query/UnionClause.php#L79-L87 | train |
Revys/revy | src/App/EntityBase.php | EntityBase.getRules | public static function getRules()
{
$rules = static::rules();
if (RevyAdmin::isTranslationMode()) {
$object = new static();
foreach ($rules as $field => $rule) {
if ($object->isTranslatableField($field)) {
unset($rules[$field]);
foreach (Language::getLocales() as $locale) {
$rules[RevyAdmin::getTranslationFieldName($field, $locale)] = $rule;
}
}
}
}
return $rules;
} | php | public static function getRules()
{
$rules = static::rules();
if (RevyAdmin::isTranslationMode()) {
$object = new static();
foreach ($rules as $field => $rule) {
if ($object->isTranslatableField($field)) {
unset($rules[$field]);
foreach (Language::getLocales() as $locale) {
$rules[RevyAdmin::getTranslationFieldName($field, $locale)] = $rule;
}
}
}
}
return $rules;
} | [
"public",
"static",
"function",
"getRules",
"(",
")",
"{",
"$",
"rules",
"=",
"static",
"::",
"rules",
"(",
")",
";",
"if",
"(",
"RevyAdmin",
"::",
"isTranslationMode",
"(",
")",
")",
"{",
"$",
"object",
"=",
"new",
"static",
"(",
")",
";",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"field",
"=>",
"$",
"rule",
")",
"{",
"if",
"(",
"$",
"object",
"->",
"isTranslatableField",
"(",
"$",
"field",
")",
")",
"{",
"unset",
"(",
"$",
"rules",
"[",
"$",
"field",
"]",
")",
";",
"foreach",
"(",
"Language",
"::",
"getLocales",
"(",
")",
"as",
"$",
"locale",
")",
"{",
"$",
"rules",
"[",
"RevyAdmin",
"::",
"getTranslationFieldName",
"(",
"$",
"field",
",",
"$",
"locale",
")",
"]",
"=",
"$",
"rule",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"rules",
";",
"}"
] | Validation default rules
Prepare rules | [
"Validation",
"default",
"rules"
] | b2c13f5f7e88eec2681b4ec8a0385e18c28fbfd1 | https://github.com/Revys/revy/blob/b2c13f5f7e88eec2681b4ec8a0385e18c28fbfd1/src/App/EntityBase.php#L177-L195 | train |
congraphcms/core | Traits/ErrorManagerTrait.php | ErrorManagerTrait.resolveErrorKey | protected function resolveErrorKey($messages = [])
{
// if there is no error key defined leave messages as they were
if(empty($this->errorKey))
{
return $messages;
}
// keys are divided on every .
$keys = explode('.', $this->errorKey);
// we need to reverse this array for sorting
$keys = array_reverse($keys);
foreach ($keys as $errorKey) {
$messages = array($errorKey => $messages);
}
return $messages;
} | php | protected function resolveErrorKey($messages = [])
{
// if there is no error key defined leave messages as they were
if(empty($this->errorKey))
{
return $messages;
}
// keys are divided on every .
$keys = explode('.', $this->errorKey);
// we need to reverse this array for sorting
$keys = array_reverse($keys);
foreach ($keys as $errorKey) {
$messages = array($errorKey => $messages);
}
return $messages;
} | [
"protected",
"function",
"resolveErrorKey",
"(",
"$",
"messages",
"=",
"[",
"]",
")",
"{",
"// if there is no error key defined leave messages as they were",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"errorKey",
")",
")",
"{",
"return",
"$",
"messages",
";",
"}",
"// keys are divided on every .",
"$",
"keys",
"=",
"explode",
"(",
"'.'",
",",
"$",
"this",
"->",
"errorKey",
")",
";",
"// we need to reverse this array for sorting",
"$",
"keys",
"=",
"array_reverse",
"(",
"$",
"keys",
")",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"errorKey",
")",
"{",
"$",
"messages",
"=",
"array",
"(",
"$",
"errorKey",
"=>",
"$",
"messages",
")",
";",
"}",
"return",
"$",
"messages",
";",
"}"
] | Nest messages according to error key
@param array $messages
@return array | [
"Nest",
"messages",
"according",
"to",
"error",
"key"
] | d017d3951b446fb2ac93b8fcee120549bb125b17 | https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Traits/ErrorManagerTrait.php#L68-L87 | train |
congraphcms/core | Traits/ErrorManagerTrait.php | ErrorManagerTrait.addErrors | public function addErrors($messages = [])
{
// check if messages are an array
if(! is_array($messages) && ! $messages instanceof MessageProvider)
{
$messages = (array) $messages;
}
return $this->errors->merge($this->resolveErrorKey($messages));
} | php | public function addErrors($messages = [])
{
// check if messages are an array
if(! is_array($messages) && ! $messages instanceof MessageProvider)
{
$messages = (array) $messages;
}
return $this->errors->merge($this->resolveErrorKey($messages));
} | [
"public",
"function",
"addErrors",
"(",
"$",
"messages",
"=",
"[",
"]",
")",
"{",
"// check if messages are an array",
"if",
"(",
"!",
"is_array",
"(",
"$",
"messages",
")",
"&&",
"!",
"$",
"messages",
"instanceof",
"MessageProvider",
")",
"{",
"$",
"messages",
"=",
"(",
"array",
")",
"$",
"messages",
";",
"}",
"return",
"$",
"this",
"->",
"errors",
"->",
"merge",
"(",
"$",
"this",
"->",
"resolveErrorKey",
"(",
"$",
"messages",
")",
")",
";",
"}"
] | Add messages to error message bag
@param array $messages (optional)
@return boolean | [
"Add",
"messages",
"to",
"error",
"message",
"bag"
] | d017d3951b446fb2ac93b8fcee120549bb125b17 | https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Traits/ErrorManagerTrait.php#L96-L105 | train |
vukbgit/PHPCraft.Subject | src/Traits/Messages.php | Messages.injectMessages | public function injectMessages(Message $messages)
{
$this->messages = $messages;
$this->messages->setCookie($this->cookies);
} | php | public function injectMessages(Message $messages)
{
$this->messages = $messages;
$this->messages->setCookie($this->cookies);
} | [
"public",
"function",
"injectMessages",
"(",
"Message",
"$",
"messages",
")",
"{",
"$",
"this",
"->",
"messages",
"=",
"$",
"messages",
";",
"$",
"this",
"->",
"messages",
"->",
"setCookie",
"(",
"$",
"this",
"->",
"cookies",
")",
";",
"}"
] | Injects messages manager instance
@param PHPCraft\Message\Message $messages messages manager instance | [
"Injects",
"messages",
"manager",
"instance"
] | a43ad7868098ff1e7bda6819547ea64f9a853732 | https://github.com/vukbgit/PHPCraft.Subject/blob/a43ad7868098ff1e7bda6819547ea64f9a853732/src/Traits/Messages.php#L53-L57 | train |
juliendidier/BuzzProfilerBundle | Buzz/Client/DebugClient.php | DebugClient.formatBytes | private function formatBytes($bytes, $precision = 2)
{
$unit = array('B','KB','MB','GB','TB','PB','EB');
if (!$bytes) {
return "0 B";
}
return @round(
$bytes / pow(1024, ($i = floor(log($bytes, 1024)))), $precision
).' '.$unit[$i];
} | php | private function formatBytes($bytes, $precision = 2)
{
$unit = array('B','KB','MB','GB','TB','PB','EB');
if (!$bytes) {
return "0 B";
}
return @round(
$bytes / pow(1024, ($i = floor(log($bytes, 1024)))), $precision
).' '.$unit[$i];
} | [
"private",
"function",
"formatBytes",
"(",
"$",
"bytes",
",",
"$",
"precision",
"=",
"2",
")",
"{",
"$",
"unit",
"=",
"array",
"(",
"'B'",
",",
"'KB'",
",",
"'MB'",
",",
"'GB'",
",",
"'TB'",
",",
"'PB'",
",",
"'EB'",
")",
";",
"if",
"(",
"!",
"$",
"bytes",
")",
"{",
"return",
"\"0 B\"",
";",
"}",
"return",
"@",
"round",
"(",
"$",
"bytes",
"/",
"pow",
"(",
"1024",
",",
"(",
"$",
"i",
"=",
"floor",
"(",
"log",
"(",
"$",
"bytes",
",",
"1024",
")",
")",
")",
")",
",",
"$",
"precision",
")",
".",
"' '",
".",
"$",
"unit",
"[",
"$",
"i",
"]",
";",
"}"
] | formats a bigint into a human readable size
@param int $size
@param int $precision
@return string | [
"formats",
"a",
"bigint",
"into",
"a",
"human",
"readable",
"size"
] | 7d06f1230630bce8d8514e7af3995d852aa34e14 | https://github.com/juliendidier/BuzzProfilerBundle/blob/7d06f1230630bce8d8514e7af3995d852aa34e14/Buzz/Client/DebugClient.php#L79-L90 | train |
horntell/php-sdk | lib/guzzle/GuzzleHttp/Adapter/Curl/BatchContext.php | BatchContext.removeAll | public function removeAll()
{
foreach ($this->handles as $transaction) {
$ch = $this->handles[$transaction];
curl_multi_remove_handle($this->multi, $ch);
curl_close($ch);
unset($this->handles[$transaction]);
}
} | php | public function removeAll()
{
foreach ($this->handles as $transaction) {
$ch = $this->handles[$transaction];
curl_multi_remove_handle($this->multi, $ch);
curl_close($ch);
unset($this->handles[$transaction]);
}
} | [
"public",
"function",
"removeAll",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"handles",
"as",
"$",
"transaction",
")",
"{",
"$",
"ch",
"=",
"$",
"this",
"->",
"handles",
"[",
"$",
"transaction",
"]",
";",
"curl_multi_remove_handle",
"(",
"$",
"this",
"->",
"multi",
",",
"$",
"ch",
")",
";",
"curl_close",
"(",
"$",
"ch",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"handles",
"[",
"$",
"transaction",
"]",
")",
";",
"}",
"}"
] | Closes all of the requests associated with the underlying multi handle. | [
"Closes",
"all",
"of",
"the",
"requests",
"associated",
"with",
"the",
"underlying",
"multi",
"handle",
"."
] | e5205e9396a21b754d5651a8aa5898da5922a1b7 | https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/Adapter/Curl/BatchContext.php#L45-L53 | train |
horntell/php-sdk | lib/guzzle/GuzzleHttp/Adapter/Curl/BatchContext.php | BatchContext.findTransaction | public function findTransaction($handle)
{
foreach ($this->handles as $transaction) {
if ($this->handles[$transaction] === $handle) {
return $transaction;
}
}
throw new AdapterException('No curl handle was found');
} | php | public function findTransaction($handle)
{
foreach ($this->handles as $transaction) {
if ($this->handles[$transaction] === $handle) {
return $transaction;
}
}
throw new AdapterException('No curl handle was found');
} | [
"public",
"function",
"findTransaction",
"(",
"$",
"handle",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"handles",
"as",
"$",
"transaction",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"handles",
"[",
"$",
"transaction",
"]",
"===",
"$",
"handle",
")",
"{",
"return",
"$",
"transaction",
";",
"}",
"}",
"throw",
"new",
"AdapterException",
"(",
"'No curl handle was found'",
")",
";",
"}"
] | Find a transaction for a given curl handle
@param resource $handle Curl handle
@return TransactionInterface
@throws AdapterException if a transaction is not found | [
"Find",
"a",
"transaction",
"for",
"a",
"given",
"curl",
"handle"
] | e5205e9396a21b754d5651a8aa5898da5922a1b7 | https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/Adapter/Curl/BatchContext.php#L63-L72 | train |
horntell/php-sdk | lib/guzzle/GuzzleHttp/Adapter/Curl/BatchContext.php | BatchContext.nextPending | public function nextPending()
{
if (!$this->hasPending()) {
return null;
}
$current = $this->pending->current();
$this->pending->next();
return $current;
} | php | public function nextPending()
{
if (!$this->hasPending()) {
return null;
}
$current = $this->pending->current();
$this->pending->next();
return $current;
} | [
"public",
"function",
"nextPending",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasPending",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"current",
"=",
"$",
"this",
"->",
"pending",
"->",
"current",
"(",
")",
";",
"$",
"this",
"->",
"pending",
"->",
"next",
"(",
")",
";",
"return",
"$",
"current",
";",
"}"
] | Pop the next transaction from the transaction queue
@return TransactionInterface|null | [
"Pop",
"the",
"next",
"transaction",
"from",
"the",
"transaction",
"queue"
] | e5205e9396a21b754d5651a8aa5898da5922a1b7 | https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/Adapter/Curl/BatchContext.php#L99-L109 | train |
horntell/php-sdk | lib/guzzle/GuzzleHttp/Adapter/Curl/BatchContext.php | BatchContext.addTransaction | public function addTransaction(TransactionInterface $transaction, $handle)
{
if (isset($this->handles[$transaction])) {
throw new AdapterException('Transaction already registered');
}
$code = curl_multi_add_handle($this->multi, $handle);
if ($code != CURLM_OK) {
MultiAdapter::throwMultiError($code);
}
$this->handles[$transaction] = $handle;
} | php | public function addTransaction(TransactionInterface $transaction, $handle)
{
if (isset($this->handles[$transaction])) {
throw new AdapterException('Transaction already registered');
}
$code = curl_multi_add_handle($this->multi, $handle);
if ($code != CURLM_OK) {
MultiAdapter::throwMultiError($code);
}
$this->handles[$transaction] = $handle;
} | [
"public",
"function",
"addTransaction",
"(",
"TransactionInterface",
"$",
"transaction",
",",
"$",
"handle",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"handles",
"[",
"$",
"transaction",
"]",
")",
")",
"{",
"throw",
"new",
"AdapterException",
"(",
"'Transaction already registered'",
")",
";",
"}",
"$",
"code",
"=",
"curl_multi_add_handle",
"(",
"$",
"this",
"->",
"multi",
",",
"$",
"handle",
")",
";",
"if",
"(",
"$",
"code",
"!=",
"CURLM_OK",
")",
"{",
"MultiAdapter",
"::",
"throwMultiError",
"(",
"$",
"code",
")",
";",
"}",
"$",
"this",
"->",
"handles",
"[",
"$",
"transaction",
"]",
"=",
"$",
"handle",
";",
"}"
] | Add a transaction to the multi handle
@param TransactionInterface $transaction Transaction to add
@param resource $handle Resource to use with the handle
@throws AdapterException If the handle is already registered | [
"Add",
"a",
"transaction",
"to",
"the",
"multi",
"handle"
] | e5205e9396a21b754d5651a8aa5898da5922a1b7 | https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/Adapter/Curl/BatchContext.php#L139-L151 | train |
horntell/php-sdk | lib/guzzle/GuzzleHttp/Adapter/Curl/BatchContext.php | BatchContext.removeTransaction | public function removeTransaction(TransactionInterface $transaction)
{
if (!isset($this->handles[$transaction])) {
throw new AdapterException('Transaction not registered');
}
$handle = $this->handles[$transaction];
$this->handles->detach($transaction);
$info = curl_getinfo($handle);
$code = curl_multi_remove_handle($this->multi, $handle);
curl_close($handle);
if ($code !== CURLM_OK) {
MultiAdapter::throwMultiError($code);
}
return $info;
} | php | public function removeTransaction(TransactionInterface $transaction)
{
if (!isset($this->handles[$transaction])) {
throw new AdapterException('Transaction not registered');
}
$handle = $this->handles[$transaction];
$this->handles->detach($transaction);
$info = curl_getinfo($handle);
$code = curl_multi_remove_handle($this->multi, $handle);
curl_close($handle);
if ($code !== CURLM_OK) {
MultiAdapter::throwMultiError($code);
}
return $info;
} | [
"public",
"function",
"removeTransaction",
"(",
"TransactionInterface",
"$",
"transaction",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"handles",
"[",
"$",
"transaction",
"]",
")",
")",
"{",
"throw",
"new",
"AdapterException",
"(",
"'Transaction not registered'",
")",
";",
"}",
"$",
"handle",
"=",
"$",
"this",
"->",
"handles",
"[",
"$",
"transaction",
"]",
";",
"$",
"this",
"->",
"handles",
"->",
"detach",
"(",
"$",
"transaction",
")",
";",
"$",
"info",
"=",
"curl_getinfo",
"(",
"$",
"handle",
")",
";",
"$",
"code",
"=",
"curl_multi_remove_handle",
"(",
"$",
"this",
"->",
"multi",
",",
"$",
"handle",
")",
";",
"curl_close",
"(",
"$",
"handle",
")",
";",
"if",
"(",
"$",
"code",
"!==",
"CURLM_OK",
")",
"{",
"MultiAdapter",
"::",
"throwMultiError",
"(",
"$",
"code",
")",
";",
"}",
"return",
"$",
"info",
";",
"}"
] | Remove a transaction and associated handle from the context
@param TransactionInterface $transaction Transaction to remove
@return array Returns the curl_getinfo array
@throws AdapterException if the transaction is not found | [
"Remove",
"a",
"transaction",
"and",
"associated",
"handle",
"from",
"the",
"context"
] | e5205e9396a21b754d5651a8aa5898da5922a1b7 | https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/Adapter/Curl/BatchContext.php#L161-L178 | train |
Wedeto/Log | src/Writer/MemLogWriter.php | MemLogWriter.write | public function write(string $level, string $message, array $context)
{
$levnum = Logger::getLevelNumeric($level);
if ($levnum < $this->min_level)
return;
$lvl = sprintf("%10s", $level);
$message = $this->format($lvl, $message, $context);
$this->log[] = $message; //sprintf("%10s: %s", strtoupper($level), $message);
} | php | public function write(string $level, string $message, array $context)
{
$levnum = Logger::getLevelNumeric($level);
if ($levnum < $this->min_level)
return;
$lvl = sprintf("%10s", $level);
$message = $this->format($lvl, $message, $context);
$this->log[] = $message; //sprintf("%10s: %s", strtoupper($level), $message);
} | [
"public",
"function",
"write",
"(",
"string",
"$",
"level",
",",
"string",
"$",
"message",
",",
"array",
"$",
"context",
")",
"{",
"$",
"levnum",
"=",
"Logger",
"::",
"getLevelNumeric",
"(",
"$",
"level",
")",
";",
"if",
"(",
"$",
"levnum",
"<",
"$",
"this",
"->",
"min_level",
")",
"return",
";",
"$",
"lvl",
"=",
"sprintf",
"(",
"\"%10s\"",
",",
"$",
"level",
")",
";",
"$",
"message",
"=",
"$",
"this",
"->",
"format",
"(",
"$",
"lvl",
",",
"$",
"message",
",",
"$",
"context",
")",
";",
"$",
"this",
"->",
"log",
"[",
"]",
"=",
"$",
"message",
";",
"//sprintf(\"%10s: %s\", strtoupper($level), $message);",
"}"
] | Log a line to the memory log, if its level is high enough
@param string $level The level of the message
@param string $message The message
@param array $context The variables to fill in the message | [
"Log",
"a",
"line",
"to",
"the",
"memory",
"log",
"if",
"its",
"level",
"is",
"high",
"enough"
] | 88252c5052089fdcc5dae466d1ad5889bb2b735f | https://github.com/Wedeto/Log/blob/88252c5052089fdcc5dae466d1ad5889bb2b735f/src/Writer/MemLogWriter.php#L59-L68 | train |
SCLInternet/SclZfGenericMapper | src/SclZfGenericMapper/ZendDbMapper.php | ZendDbMapper.getSelect | protected function getSelect($table = null)
{
$this->initialize();
$select = $this->getSlaveSql()->select();
$select->from($table ?: $this->getTableName());
return $select;
} | php | protected function getSelect($table = null)
{
$this->initialize();
$select = $this->getSlaveSql()->select();
$select->from($table ?: $this->getTableName());
return $select;
} | [
"protected",
"function",
"getSelect",
"(",
"$",
"table",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"initialize",
"(",
")",
";",
"$",
"select",
"=",
"$",
"this",
"->",
"getSlaveSql",
"(",
")",
"->",
"select",
"(",
")",
";",
"$",
"select",
"->",
"from",
"(",
"$",
"table",
"?",
":",
"$",
"this",
"->",
"getTableName",
"(",
")",
")",
";",
"return",
"$",
"select",
";",
"}"
] | The version allows read-write access.
@param string $table
@return \Zend\Db\Sql\Select | [
"The",
"version",
"allows",
"read",
"-",
"write",
"access",
"."
] | c61c61546bfbc07e9c9a4b425e8e02fd7182d80b | https://github.com/SCLInternet/SclZfGenericMapper/blob/c61c61546bfbc07e9c9a4b425e8e02fd7182d80b/src/SclZfGenericMapper/ZendDbMapper.php#L132-L141 | train |
melisplatform/melis-composerdeploy | src/Service/MelisComposerService.php | MelisComposerService.runCommand | private function runCommand($cmd, $package = null, $args, $noAddtlArguments = false)
{
$translator = $this->getServiceLocator()->get('translator');
$docPath = str_replace(['\\', 'public/../'], '', $this->getDocumentRoot());
$docPath = trim(substr($docPath, 0, strlen($docPath) - 1)); // remove last "/" trail
set_time_limit(0);
ini_set('memory_limit', -1);
putenv('COMPOSER_HOME=' . self::COMPOSER);
if (in_array($cmd, $this->availableCommands())) {
$dryRunArgs = null;
if ($this->getDryRun()) {
$dryRunArgs = self::DRY_RUN_ARGS;
}
$noProgress = self::NO_PROGRESS;
$ignoreReqs = self::IGNORE_REQ;
$preferDist = self::PREFER_DIST;
$noScript = self::NO_SCRIPTS;
$commandString = "$cmd $package $dryRunArgs $args $ignoreReqs $noProgress $noScript $preferDist --working-dir=\"$docPath\"";
// override commandstring if noAddtlArguments is set to "true"
if ($noAddtlArguments) {
$commandString = "$cmd --working-dir=\"$docPath\"";
}
$input = new StringInput($commandString);
$output = new StreamOutput(fopen('php://output', 'w'));
$composer = new Application();
$formatter = $output->getFormatter();
$formatter->setDecorated(true);
$formatter->setStyle('error', new ComposerOutputFormatterStyle(ComposerOutputFormatterStyle::ERROR));
$formatter->setStyle('info', new ComposerOutputFormatterStyle(ComposerOutputFormatterStyle::INFO));
$formatter->setStyle('comment', new ComposerOutputFormatterStyle(ComposerOutputFormatterStyle::COMMENT));
$formatter->setStyle('warning', new ComposerOutputFormatterStyle(ComposerOutputFormatterStyle::ERROR));
$output->setFormatter($formatter);
chdir($docPath);
if (PHP_OS !== 'AIX' && DIRECTORY_SEPARATOR == '/') {
/** proc_open(): fork failed - Cannot allocate memory [fix] | linux only */
shell_exec('sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024');
shell_exec('sudo /sbin/mkswap /var/swap.1');
shell_exec('sudo /sbin/swapon /var/swap.1');
}
$composer->run($input, $output);
return $output;
}
return sprintf($translator->translate('tr_market_place_unknown_command'), $cmd);
} | php | private function runCommand($cmd, $package = null, $args, $noAddtlArguments = false)
{
$translator = $this->getServiceLocator()->get('translator');
$docPath = str_replace(['\\', 'public/../'], '', $this->getDocumentRoot());
$docPath = trim(substr($docPath, 0, strlen($docPath) - 1)); // remove last "/" trail
set_time_limit(0);
ini_set('memory_limit', -1);
putenv('COMPOSER_HOME=' . self::COMPOSER);
if (in_array($cmd, $this->availableCommands())) {
$dryRunArgs = null;
if ($this->getDryRun()) {
$dryRunArgs = self::DRY_RUN_ARGS;
}
$noProgress = self::NO_PROGRESS;
$ignoreReqs = self::IGNORE_REQ;
$preferDist = self::PREFER_DIST;
$noScript = self::NO_SCRIPTS;
$commandString = "$cmd $package $dryRunArgs $args $ignoreReqs $noProgress $noScript $preferDist --working-dir=\"$docPath\"";
// override commandstring if noAddtlArguments is set to "true"
if ($noAddtlArguments) {
$commandString = "$cmd --working-dir=\"$docPath\"";
}
$input = new StringInput($commandString);
$output = new StreamOutput(fopen('php://output', 'w'));
$composer = new Application();
$formatter = $output->getFormatter();
$formatter->setDecorated(true);
$formatter->setStyle('error', new ComposerOutputFormatterStyle(ComposerOutputFormatterStyle::ERROR));
$formatter->setStyle('info', new ComposerOutputFormatterStyle(ComposerOutputFormatterStyle::INFO));
$formatter->setStyle('comment', new ComposerOutputFormatterStyle(ComposerOutputFormatterStyle::COMMENT));
$formatter->setStyle('warning', new ComposerOutputFormatterStyle(ComposerOutputFormatterStyle::ERROR));
$output->setFormatter($formatter);
chdir($docPath);
if (PHP_OS !== 'AIX' && DIRECTORY_SEPARATOR == '/') {
/** proc_open(): fork failed - Cannot allocate memory [fix] | linux only */
shell_exec('sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024');
shell_exec('sudo /sbin/mkswap /var/swap.1');
shell_exec('sudo /sbin/swapon /var/swap.1');
}
$composer->run($input, $output);
return $output;
}
return sprintf($translator->translate('tr_market_place_unknown_command'), $cmd);
} | [
"private",
"function",
"runCommand",
"(",
"$",
"cmd",
",",
"$",
"package",
"=",
"null",
",",
"$",
"args",
",",
"$",
"noAddtlArguments",
"=",
"false",
")",
"{",
"$",
"translator",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'translator'",
")",
";",
"$",
"docPath",
"=",
"str_replace",
"(",
"[",
"'\\\\'",
",",
"'public/../'",
"]",
",",
"''",
",",
"$",
"this",
"->",
"getDocumentRoot",
"(",
")",
")",
";",
"$",
"docPath",
"=",
"trim",
"(",
"substr",
"(",
"$",
"docPath",
",",
"0",
",",
"strlen",
"(",
"$",
"docPath",
")",
"-",
"1",
")",
")",
";",
"// remove last \"/\" trail",
"set_time_limit",
"(",
"0",
")",
";",
"ini_set",
"(",
"'memory_limit'",
",",
"-",
"1",
")",
";",
"putenv",
"(",
"'COMPOSER_HOME='",
".",
"self",
"::",
"COMPOSER",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"cmd",
",",
"$",
"this",
"->",
"availableCommands",
"(",
")",
")",
")",
"{",
"$",
"dryRunArgs",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"getDryRun",
"(",
")",
")",
"{",
"$",
"dryRunArgs",
"=",
"self",
"::",
"DRY_RUN_ARGS",
";",
"}",
"$",
"noProgress",
"=",
"self",
"::",
"NO_PROGRESS",
";",
"$",
"ignoreReqs",
"=",
"self",
"::",
"IGNORE_REQ",
";",
"$",
"preferDist",
"=",
"self",
"::",
"PREFER_DIST",
";",
"$",
"noScript",
"=",
"self",
"::",
"NO_SCRIPTS",
";",
"$",
"commandString",
"=",
"\"$cmd $package $dryRunArgs $args $ignoreReqs $noProgress $noScript $preferDist --working-dir=\\\"$docPath\\\"\"",
";",
"// override commandstring if noAddtlArguments is set to \"true\"",
"if",
"(",
"$",
"noAddtlArguments",
")",
"{",
"$",
"commandString",
"=",
"\"$cmd --working-dir=\\\"$docPath\\\"\"",
";",
"}",
"$",
"input",
"=",
"new",
"StringInput",
"(",
"$",
"commandString",
")",
";",
"$",
"output",
"=",
"new",
"StreamOutput",
"(",
"fopen",
"(",
"'php://output'",
",",
"'w'",
")",
")",
";",
"$",
"composer",
"=",
"new",
"Application",
"(",
")",
";",
"$",
"formatter",
"=",
"$",
"output",
"->",
"getFormatter",
"(",
")",
";",
"$",
"formatter",
"->",
"setDecorated",
"(",
"true",
")",
";",
"$",
"formatter",
"->",
"setStyle",
"(",
"'error'",
",",
"new",
"ComposerOutputFormatterStyle",
"(",
"ComposerOutputFormatterStyle",
"::",
"ERROR",
")",
")",
";",
"$",
"formatter",
"->",
"setStyle",
"(",
"'info'",
",",
"new",
"ComposerOutputFormatterStyle",
"(",
"ComposerOutputFormatterStyle",
"::",
"INFO",
")",
")",
";",
"$",
"formatter",
"->",
"setStyle",
"(",
"'comment'",
",",
"new",
"ComposerOutputFormatterStyle",
"(",
"ComposerOutputFormatterStyle",
"::",
"COMMENT",
")",
")",
";",
"$",
"formatter",
"->",
"setStyle",
"(",
"'warning'",
",",
"new",
"ComposerOutputFormatterStyle",
"(",
"ComposerOutputFormatterStyle",
"::",
"ERROR",
")",
")",
";",
"$",
"output",
"->",
"setFormatter",
"(",
"$",
"formatter",
")",
";",
"chdir",
"(",
"$",
"docPath",
")",
";",
"if",
"(",
"PHP_OS",
"!==",
"'AIX'",
"&&",
"DIRECTORY_SEPARATOR",
"==",
"'/'",
")",
"{",
"/** proc_open(): fork failed - Cannot allocate memory [fix] | linux only */",
"shell_exec",
"(",
"'sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024'",
")",
";",
"shell_exec",
"(",
"'sudo /sbin/mkswap /var/swap.1'",
")",
";",
"shell_exec",
"(",
"'sudo /sbin/swapon /var/swap.1'",
")",
";",
"}",
"$",
"composer",
"->",
"run",
"(",
"$",
"input",
",",
"$",
"output",
")",
";",
"return",
"$",
"output",
";",
"}",
"return",
"sprintf",
"(",
"$",
"translator",
"->",
"translate",
"(",
"'tr_market_place_unknown_command'",
")",
",",
"$",
"cmd",
")",
";",
"}"
] | This calls the composer CLI to execute a command
@param $cmd
@param null $package
@param $args
@param bool $noAddtlArguments
@return string|\Symfony\Component\Console\Output\StreamOutput
@throws \Exception | [
"This",
"calls",
"the",
"composer",
"CLI",
"to",
"execute",
"a",
"command"
] | 6712bd74be419003048909821a07bafe4ca7ce52 | https://github.com/melisplatform/melis-composerdeploy/blob/6712bd74be419003048909821a07bafe4ca7ce52/src/Service/MelisComposerService.php#L102-L160 | train |
melisplatform/melis-composerdeploy | src/Service/MelisComposerService.php | MelisComposerService.setDocumentRoot | public function setDocumentRoot($documentRoot)
{
if ($documentRoot) {
$this->documentRoot = $documentRoot;
} else {
$this->documentRoot = $this->getDefaultDocRoot();
}
} | php | public function setDocumentRoot($documentRoot)
{
if ($documentRoot) {
$this->documentRoot = $documentRoot;
} else {
$this->documentRoot = $this->getDefaultDocRoot();
}
} | [
"public",
"function",
"setDocumentRoot",
"(",
"$",
"documentRoot",
")",
"{",
"if",
"(",
"$",
"documentRoot",
")",
"{",
"$",
"this",
"->",
"documentRoot",
"=",
"$",
"documentRoot",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"documentRoot",
"=",
"$",
"this",
"->",
"getDefaultDocRoot",
"(",
")",
";",
"}",
"}"
] | Sets the path of the platform, if nothing is set, then it will use the default path of this platform
@param $documentRoot | [
"Sets",
"the",
"path",
"of",
"the",
"platform",
"if",
"nothing",
"is",
"set",
"then",
"it",
"will",
"use",
"the",
"default",
"path",
"of",
"this",
"platform"
] | 6712bd74be419003048909821a07bafe4ca7ce52 | https://github.com/melisplatform/melis-composerdeploy/blob/6712bd74be419003048909821a07bafe4ca7ce52/src/Service/MelisComposerService.php#L201-L208 | train |
melisplatform/melis-composerdeploy | src/Service/MelisComposerService.php | MelisComposerService.availableCommands | private function availableCommands()
{
return [
self::INSTALL,
self::UPDATE,
self::DUMP_AUTOLOAD,
self::DOWNLOAD,
self::REMOVE,
];
} | php | private function availableCommands()
{
return [
self::INSTALL,
self::UPDATE,
self::DUMP_AUTOLOAD,
self::DOWNLOAD,
self::REMOVE,
];
} | [
"private",
"function",
"availableCommands",
"(",
")",
"{",
"return",
"[",
"self",
"::",
"INSTALL",
",",
"self",
"::",
"UPDATE",
",",
"self",
"::",
"DUMP_AUTOLOAD",
",",
"self",
"::",
"DOWNLOAD",
",",
"self",
"::",
"REMOVE",
",",
"]",
";",
"}"
] | Sets the limitation to what commands that can be executed
@return array | [
"Sets",
"the",
"limitation",
"to",
"what",
"commands",
"that",
"can",
"be",
"executed"
] | 6712bd74be419003048909821a07bafe4ca7ce52 | https://github.com/melisplatform/melis-composerdeploy/blob/6712bd74be419003048909821a07bafe4ca7ce52/src/Service/MelisComposerService.php#L225-L234 | train |
FlexModel/FlexModelBundle | EventListener/ObjectUploadSubscriber.php | ObjectUploadSubscriber.preFlush | public function preFlush(PreFlushEventArgs $args)
{
$objectManager = $args->getEntityManager();
$unitOfWork = $objectManager->getUnitOfWork();
$entityMap = $unitOfWork->getIdentityMap();
foreach ($entityMap as $objectClass => $objects) {
if (in_array(UploadObjectInterface::class, class_implements($objectClass))) {
foreach ($objects as $object) {
$this->prepareUploadFileReferences($object);
}
}
}
} | php | public function preFlush(PreFlushEventArgs $args)
{
$objectManager = $args->getEntityManager();
$unitOfWork = $objectManager->getUnitOfWork();
$entityMap = $unitOfWork->getIdentityMap();
foreach ($entityMap as $objectClass => $objects) {
if (in_array(UploadObjectInterface::class, class_implements($objectClass))) {
foreach ($objects as $object) {
$this->prepareUploadFileReferences($object);
}
}
}
} | [
"public",
"function",
"preFlush",
"(",
"PreFlushEventArgs",
"$",
"args",
")",
"{",
"$",
"objectManager",
"=",
"$",
"args",
"->",
"getEntityManager",
"(",
")",
";",
"$",
"unitOfWork",
"=",
"$",
"objectManager",
"->",
"getUnitOfWork",
"(",
")",
";",
"$",
"entityMap",
"=",
"$",
"unitOfWork",
"->",
"getIdentityMap",
"(",
")",
";",
"foreach",
"(",
"$",
"entityMap",
"as",
"$",
"objectClass",
"=>",
"$",
"objects",
")",
"{",
"if",
"(",
"in_array",
"(",
"UploadObjectInterface",
"::",
"class",
",",
"class_implements",
"(",
"$",
"objectClass",
")",
")",
")",
"{",
"foreach",
"(",
"$",
"objects",
"as",
"$",
"object",
")",
"{",
"$",
"this",
"->",
"prepareUploadFileReferences",
"(",
"$",
"object",
")",
";",
"}",
"}",
"}",
"}"
] | Prepares upload file references for all objects implementing the UploadObjectInterface.
@param PreFlushEventArgs $args | [
"Prepares",
"upload",
"file",
"references",
"for",
"all",
"objects",
"implementing",
"the",
"UploadObjectInterface",
"."
] | 7b4720d25b0dc6baf29b1da8ad7c67dfb2686460 | https://github.com/FlexModel/FlexModelBundle/blob/7b4720d25b0dc6baf29b1da8ad7c67dfb2686460/EventListener/ObjectUploadSubscriber.php#L74-L87 | train |
FlexModel/FlexModelBundle | EventListener/ObjectUploadSubscriber.php | ObjectUploadSubscriber.prePersist | public function prePersist(LifecycleEventArgs $args)
{
$object = $args->getObject();
if ($object instanceof UploadObjectInterface) {
$this->prepareUploadFileReferences($object);
}
} | php | public function prePersist(LifecycleEventArgs $args)
{
$object = $args->getObject();
if ($object instanceof UploadObjectInterface) {
$this->prepareUploadFileReferences($object);
}
} | [
"public",
"function",
"prePersist",
"(",
"LifecycleEventArgs",
"$",
"args",
")",
"{",
"$",
"object",
"=",
"$",
"args",
"->",
"getObject",
"(",
")",
";",
"if",
"(",
"$",
"object",
"instanceof",
"UploadObjectInterface",
")",
"{",
"$",
"this",
"->",
"prepareUploadFileReferences",
"(",
"$",
"object",
")",
";",
"}",
"}"
] | Prepares upload file references for a new object implementing the UploadObjectInterface.
@param LifecycleEventArgs $args | [
"Prepares",
"upload",
"file",
"references",
"for",
"a",
"new",
"object",
"implementing",
"the",
"UploadObjectInterface",
"."
] | 7b4720d25b0dc6baf29b1da8ad7c67dfb2686460 | https://github.com/FlexModel/FlexModelBundle/blob/7b4720d25b0dc6baf29b1da8ad7c67dfb2686460/EventListener/ObjectUploadSubscriber.php#L94-L100 | train |
FlexModel/FlexModelBundle | EventListener/ObjectUploadSubscriber.php | ObjectUploadSubscriber.postPersist | public function postPersist(LifecycleEventArgs $args)
{
$object = $args->getObject();
if ($object instanceof UploadObjectInterface) {
$this->storeFileUploads($object);
}
} | php | public function postPersist(LifecycleEventArgs $args)
{
$object = $args->getObject();
if ($object instanceof UploadObjectInterface) {
$this->storeFileUploads($object);
}
} | [
"public",
"function",
"postPersist",
"(",
"LifecycleEventArgs",
"$",
"args",
")",
"{",
"$",
"object",
"=",
"$",
"args",
"->",
"getObject",
"(",
")",
";",
"if",
"(",
"$",
"object",
"instanceof",
"UploadObjectInterface",
")",
"{",
"$",
"this",
"->",
"storeFileUploads",
"(",
"$",
"object",
")",
";",
"}",
"}"
] | Stores the file uploads.
@param LifecycleEventArgs $args | [
"Stores",
"the",
"file",
"uploads",
"."
] | 7b4720d25b0dc6baf29b1da8ad7c67dfb2686460 | https://github.com/FlexModel/FlexModelBundle/blob/7b4720d25b0dc6baf29b1da8ad7c67dfb2686460/EventListener/ObjectUploadSubscriber.php#L107-L113 | train |
FlexModel/FlexModelBundle | EventListener/ObjectUploadSubscriber.php | ObjectUploadSubscriber.prepareUploadFileReferences | private function prepareUploadFileReferences(UploadObjectInterface $object)
{
$object->setFileUploadPath($this->fileUploadPath);
$reflectionClass = new ReflectionClass($object);
$objectName = $reflectionClass->getShortName();
$fileUploads = $object->getFileUploads();
$fileFieldConfigurations = $this->flexModel->getFieldsByDatatype($objectName, 'FILE');
foreach ($fileFieldConfigurations as $fileFieldConfiguration) {
$camelizedFieldName = Container::camelize($fileFieldConfiguration['name']);
$fileFieldProperty = lcfirst($camelizedFieldName);
if (isset($fileUploads[$fileFieldProperty])) {
$getter = 'get'.$camelizedFieldName;
$setter = 'set'.$camelizedFieldName;
$previousFileReference = $object->$getter();
if (empty($previousFileReference) === false) {
$this->filesScheduledForDeletion[] = sprintf('%s/%s', $this->getFilePath($objectName, $fileFieldConfiguration['name']), $previousFileReference);
}
$fileName = md5(uniqid()).'.'.$fileUploads[$fileFieldProperty]->guessExtension();
$object->$setter($fileName);
}
}
} | php | private function prepareUploadFileReferences(UploadObjectInterface $object)
{
$object->setFileUploadPath($this->fileUploadPath);
$reflectionClass = new ReflectionClass($object);
$objectName = $reflectionClass->getShortName();
$fileUploads = $object->getFileUploads();
$fileFieldConfigurations = $this->flexModel->getFieldsByDatatype($objectName, 'FILE');
foreach ($fileFieldConfigurations as $fileFieldConfiguration) {
$camelizedFieldName = Container::camelize($fileFieldConfiguration['name']);
$fileFieldProperty = lcfirst($camelizedFieldName);
if (isset($fileUploads[$fileFieldProperty])) {
$getter = 'get'.$camelizedFieldName;
$setter = 'set'.$camelizedFieldName;
$previousFileReference = $object->$getter();
if (empty($previousFileReference) === false) {
$this->filesScheduledForDeletion[] = sprintf('%s/%s', $this->getFilePath($objectName, $fileFieldConfiguration['name']), $previousFileReference);
}
$fileName = md5(uniqid()).'.'.$fileUploads[$fileFieldProperty]->guessExtension();
$object->$setter($fileName);
}
}
} | [
"private",
"function",
"prepareUploadFileReferences",
"(",
"UploadObjectInterface",
"$",
"object",
")",
"{",
"$",
"object",
"->",
"setFileUploadPath",
"(",
"$",
"this",
"->",
"fileUploadPath",
")",
";",
"$",
"reflectionClass",
"=",
"new",
"ReflectionClass",
"(",
"$",
"object",
")",
";",
"$",
"objectName",
"=",
"$",
"reflectionClass",
"->",
"getShortName",
"(",
")",
";",
"$",
"fileUploads",
"=",
"$",
"object",
"->",
"getFileUploads",
"(",
")",
";",
"$",
"fileFieldConfigurations",
"=",
"$",
"this",
"->",
"flexModel",
"->",
"getFieldsByDatatype",
"(",
"$",
"objectName",
",",
"'FILE'",
")",
";",
"foreach",
"(",
"$",
"fileFieldConfigurations",
"as",
"$",
"fileFieldConfiguration",
")",
"{",
"$",
"camelizedFieldName",
"=",
"Container",
"::",
"camelize",
"(",
"$",
"fileFieldConfiguration",
"[",
"'name'",
"]",
")",
";",
"$",
"fileFieldProperty",
"=",
"lcfirst",
"(",
"$",
"camelizedFieldName",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"fileUploads",
"[",
"$",
"fileFieldProperty",
"]",
")",
")",
"{",
"$",
"getter",
"=",
"'get'",
".",
"$",
"camelizedFieldName",
";",
"$",
"setter",
"=",
"'set'",
".",
"$",
"camelizedFieldName",
";",
"$",
"previousFileReference",
"=",
"$",
"object",
"->",
"$",
"getter",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"previousFileReference",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"filesScheduledForDeletion",
"[",
"]",
"=",
"sprintf",
"(",
"'%s/%s'",
",",
"$",
"this",
"->",
"getFilePath",
"(",
"$",
"objectName",
",",
"$",
"fileFieldConfiguration",
"[",
"'name'",
"]",
")",
",",
"$",
"previousFileReference",
")",
";",
"}",
"$",
"fileName",
"=",
"md5",
"(",
"uniqid",
"(",
")",
")",
".",
"'.'",
".",
"$",
"fileUploads",
"[",
"$",
"fileFieldProperty",
"]",
"->",
"guessExtension",
"(",
")",
";",
"$",
"object",
"->",
"$",
"setter",
"(",
"$",
"fileName",
")",
";",
"}",
"}",
"}"
] | Sets the new file references to the uploaded files on the object and schedules the previous file reference for deletion.
@param UploadObjectInterface $object | [
"Sets",
"the",
"new",
"file",
"references",
"to",
"the",
"uploaded",
"files",
"on",
"the",
"object",
"and",
"schedules",
"the",
"previous",
"file",
"reference",
"for",
"deletion",
"."
] | 7b4720d25b0dc6baf29b1da8ad7c67dfb2686460 | https://github.com/FlexModel/FlexModelBundle/blob/7b4720d25b0dc6baf29b1da8ad7c67dfb2686460/EventListener/ObjectUploadSubscriber.php#L139-L165 | train |
FlexModel/FlexModelBundle | EventListener/ObjectUploadSubscriber.php | ObjectUploadSubscriber.storeFileUploads | private function storeFileUploads(UploadObjectInterface $object)
{
$reflectionClass = new ReflectionClass($object);
$objectName = $reflectionClass->getShortName();
$fileUploads = $object->getFileUploads();
$fileFieldConfigurations = $this->flexModel->getFieldsByDatatype($objectName, 'FILE');
foreach ($fileFieldConfigurations as $fileFieldConfiguration) {
$camelizedFieldName = Container::camelize($fileFieldConfiguration['name']);
$fileFieldProperty = lcfirst($camelizedFieldName);
if (isset($fileUploads[$fileFieldProperty])) {
$getter = 'get'.$camelizedFieldName;
$setter = 'set'.$camelizedFieldName.'Upload';
$fileUploads[$fileFieldProperty]->move($this->getFilePath($objectName, $fileFieldConfiguration['name']), $object->$getter());
$object->$setter(null);
}
}
} | php | private function storeFileUploads(UploadObjectInterface $object)
{
$reflectionClass = new ReflectionClass($object);
$objectName = $reflectionClass->getShortName();
$fileUploads = $object->getFileUploads();
$fileFieldConfigurations = $this->flexModel->getFieldsByDatatype($objectName, 'FILE');
foreach ($fileFieldConfigurations as $fileFieldConfiguration) {
$camelizedFieldName = Container::camelize($fileFieldConfiguration['name']);
$fileFieldProperty = lcfirst($camelizedFieldName);
if (isset($fileUploads[$fileFieldProperty])) {
$getter = 'get'.$camelizedFieldName;
$setter = 'set'.$camelizedFieldName.'Upload';
$fileUploads[$fileFieldProperty]->move($this->getFilePath($objectName, $fileFieldConfiguration['name']), $object->$getter());
$object->$setter(null);
}
}
} | [
"private",
"function",
"storeFileUploads",
"(",
"UploadObjectInterface",
"$",
"object",
")",
"{",
"$",
"reflectionClass",
"=",
"new",
"ReflectionClass",
"(",
"$",
"object",
")",
";",
"$",
"objectName",
"=",
"$",
"reflectionClass",
"->",
"getShortName",
"(",
")",
";",
"$",
"fileUploads",
"=",
"$",
"object",
"->",
"getFileUploads",
"(",
")",
";",
"$",
"fileFieldConfigurations",
"=",
"$",
"this",
"->",
"flexModel",
"->",
"getFieldsByDatatype",
"(",
"$",
"objectName",
",",
"'FILE'",
")",
";",
"foreach",
"(",
"$",
"fileFieldConfigurations",
"as",
"$",
"fileFieldConfiguration",
")",
"{",
"$",
"camelizedFieldName",
"=",
"Container",
"::",
"camelize",
"(",
"$",
"fileFieldConfiguration",
"[",
"'name'",
"]",
")",
";",
"$",
"fileFieldProperty",
"=",
"lcfirst",
"(",
"$",
"camelizedFieldName",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"fileUploads",
"[",
"$",
"fileFieldProperty",
"]",
")",
")",
"{",
"$",
"getter",
"=",
"'get'",
".",
"$",
"camelizedFieldName",
";",
"$",
"setter",
"=",
"'set'",
".",
"$",
"camelizedFieldName",
".",
"'Upload'",
";",
"$",
"fileUploads",
"[",
"$",
"fileFieldProperty",
"]",
"->",
"move",
"(",
"$",
"this",
"->",
"getFilePath",
"(",
"$",
"objectName",
",",
"$",
"fileFieldConfiguration",
"[",
"'name'",
"]",
")",
",",
"$",
"object",
"->",
"$",
"getter",
"(",
")",
")",
";",
"$",
"object",
"->",
"$",
"setter",
"(",
"null",
")",
";",
"}",
"}",
"}"
] | Stores the uploaded files to the specified file system location.
@param UploadObjectInterface $object | [
"Stores",
"the",
"uploaded",
"files",
"to",
"the",
"specified",
"file",
"system",
"location",
"."
] | 7b4720d25b0dc6baf29b1da8ad7c67dfb2686460 | https://github.com/FlexModel/FlexModelBundle/blob/7b4720d25b0dc6baf29b1da8ad7c67dfb2686460/EventListener/ObjectUploadSubscriber.php#L172-L191 | train |
gplcart/twocheckout | Main.php | Main.setOrderCompletePage | protected function setOrderCompletePage(array $order, $model, $controller)
{
$this->order = $model;
$this->data_order = $order;
$this->controller = $controller;
if ($order['payment'] === 'twocheckout') {
$this->submitPayment();
$this->completePayment();
}
} | php | protected function setOrderCompletePage(array $order, $model, $controller)
{
$this->order = $model;
$this->data_order = $order;
$this->controller = $controller;
if ($order['payment'] === 'twocheckout') {
$this->submitPayment();
$this->completePayment();
}
} | [
"protected",
"function",
"setOrderCompletePage",
"(",
"array",
"$",
"order",
",",
"$",
"model",
",",
"$",
"controller",
")",
"{",
"$",
"this",
"->",
"order",
"=",
"$",
"model",
";",
"$",
"this",
"->",
"data_order",
"=",
"$",
"order",
";",
"$",
"this",
"->",
"controller",
"=",
"$",
"controller",
";",
"if",
"(",
"$",
"order",
"[",
"'payment'",
"]",
"===",
"'twocheckout'",
")",
"{",
"$",
"this",
"->",
"submitPayment",
"(",
")",
";",
"$",
"this",
"->",
"completePayment",
"(",
")",
";",
"}",
"}"
] | Set order complete page
@param array $order
@param \gplcart\core\models\Order $model
@param \gplcart\core\controllers\frontend\Controller $controller | [
"Set",
"order",
"complete",
"page"
] | b1578f866ac29d37720e1d616b8b4783832d5107 | https://github.com/gplcart/twocheckout/blob/b1578f866ac29d37720e1d616b8b4783832d5107/Main.php#L164-L174 | train |
gplcart/twocheckout | Main.php | Main.completePayment | protected function completePayment()
{
if ($this->controller->isQuery('paid')) {
$gateway = $this->getGateway();
$this->response = $gateway->completePurchase($this->getPurchaseParams())->send();
$this->processResponse();
}
} | php | protected function completePayment()
{
if ($this->controller->isQuery('paid')) {
$gateway = $this->getGateway();
$this->response = $gateway->completePurchase($this->getPurchaseParams())->send();
$this->processResponse();
}
} | [
"protected",
"function",
"completePayment",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"controller",
"->",
"isQuery",
"(",
"'paid'",
")",
")",
"{",
"$",
"gateway",
"=",
"$",
"this",
"->",
"getGateway",
"(",
")",
";",
"$",
"this",
"->",
"response",
"=",
"$",
"gateway",
"->",
"completePurchase",
"(",
"$",
"this",
"->",
"getPurchaseParams",
"(",
")",
")",
"->",
"send",
"(",
")",
";",
"$",
"this",
"->",
"processResponse",
"(",
")",
";",
"}",
"}"
] | Performs actions when purchase is completed | [
"Performs",
"actions",
"when",
"purchase",
"is",
"completed"
] | b1578f866ac29d37720e1d616b8b4783832d5107 | https://github.com/gplcart/twocheckout/blob/b1578f866ac29d37720e1d616b8b4783832d5107/Main.php#L218-L225 | train |
zodream/database | src/Query/Components/RecordBuilder.php | RecordBuilder.replace | public function replace(array $data) {
$addFields = implode('`,`', array_keys($data));
return $this->command()
->insertOrReplace("`{$addFields}`", Str::repeat('?', $data),
array_values($data));
} | php | public function replace(array $data) {
$addFields = implode('`,`', array_keys($data));
return $this->command()
->insertOrReplace("`{$addFields}`", Str::repeat('?', $data),
array_values($data));
} | [
"public",
"function",
"replace",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"addFields",
"=",
"implode",
"(",
"'`,`'",
",",
"array_keys",
"(",
"$",
"data",
")",
")",
";",
"return",
"$",
"this",
"->",
"command",
"(",
")",
"->",
"insertOrReplace",
"(",
"\"`{$addFields}`\"",
",",
"Str",
"::",
"repeat",
"(",
"'?'",
",",
"$",
"data",
")",
",",
"array_values",
"(",
"$",
"data",
")",
")",
";",
"}"
] | INSERT OR REPLACE
@param array $data
@return mixed | [
"INSERT",
"OR",
"REPLACE"
] | 03712219c057799d07350a3a2650c55bcc92c28e | https://github.com/zodream/database/blob/03712219c057799d07350a3a2650c55bcc92c28e/src/Query/Components/RecordBuilder.php#L106-L111 | train |
agentmedia/phine-core | src/Core/Logic/Module/AjaxBackendForm.php | AjaxBackendForm.SetJSFieldValue | protected function SetJSFieldValue($field, $value)
{
$jsField = Str::ToJavascript($field, false);
$jsValue = Str::ToJavascript($value, false);
echo "<script>$($jsField).val($jsValue);</script>";
} | php | protected function SetJSFieldValue($field, $value)
{
$jsField = Str::ToJavascript($field, false);
$jsValue = Str::ToJavascript($value, false);
echo "<script>$($jsField).val($jsValue);</script>";
} | [
"protected",
"function",
"SetJSFieldValue",
"(",
"$",
"field",
",",
"$",
"value",
")",
"{",
"$",
"jsField",
"=",
"Str",
"::",
"ToJavascript",
"(",
"$",
"field",
",",
"false",
")",
";",
"$",
"jsValue",
"=",
"Str",
"::",
"ToJavascript",
"(",
"$",
"value",
",",
"false",
")",
";",
"echo",
"\"<script>$($jsField).val($jsValue);</script>\"",
";",
"}"
] | Sets a field value as typical action of a modal form call
@param string $field The field specifier; typically starting with '#'
@param string $value The value | [
"Sets",
"a",
"field",
"value",
"as",
"typical",
"action",
"of",
"a",
"modal",
"form",
"call"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Module/AjaxBackendForm.php#L28-L33 | train |
agentmedia/phine-core | src/Core/Logic/Module/AjaxBackendForm.php | AjaxBackendForm.SetJSHtml | protected function SetJSHtml($element, $html)
{
$jsElement = Str::ToJavascript($element, false);
$jsHtml = Str::ToJavascript($html, false);
echo "<script>$($jsElement).html($jsHtml);</script>";
} | php | protected function SetJSHtml($element, $html)
{
$jsElement = Str::ToJavascript($element, false);
$jsHtml = Str::ToJavascript($html, false);
echo "<script>$($jsElement).html($jsHtml);</script>";
} | [
"protected",
"function",
"SetJSHtml",
"(",
"$",
"element",
",",
"$",
"html",
")",
"{",
"$",
"jsElement",
"=",
"Str",
"::",
"ToJavascript",
"(",
"$",
"element",
",",
"false",
")",
";",
"$",
"jsHtml",
"=",
"Str",
"::",
"ToJavascript",
"(",
"$",
"html",
",",
"false",
")",
";",
"echo",
"\"<script>$($jsElement).html($jsHtml);</script>\"",
";",
"}"
] | Sets element html content as a typical action of a modal form call
@param string $element The element specifier; typically starting with '#'
@param string $html The html string | [
"Sets",
"element",
"html",
"content",
"as",
"a",
"typical",
"action",
"of",
"a",
"modal",
"form",
"call"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Module/AjaxBackendForm.php#L40-L45 | train |
Dev4Media/ngnfeed-ebay | src/D4m/NgnFeed/Ebay/Model/Entity.php | Entity.add | private function add($field, $args)
{
if ($this->hasField($field) && null !== $args[0]) {
$this->virtualFieldsCollection[$field][] = $args[0];
} else if ( null === $args[0]){
throw new \InvalidArgumentException("The argument given is null ");
} else {
throw new \BadMethodCallException("There is no method add".ucfirst($field)."() on ".get_class($this));
}
} | php | private function add($field, $args)
{
if ($this->hasField($field) && null !== $args[0]) {
$this->virtualFieldsCollection[$field][] = $args[0];
} else if ( null === $args[0]){
throw new \InvalidArgumentException("The argument given is null ");
} else {
throw new \BadMethodCallException("There is no method add".ucfirst($field)."() on ".get_class($this));
}
} | [
"private",
"function",
"add",
"(",
"$",
"field",
",",
"$",
"args",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasField",
"(",
"$",
"field",
")",
"&&",
"null",
"!==",
"$",
"args",
"[",
"0",
"]",
")",
"{",
"$",
"this",
"->",
"virtualFieldsCollection",
"[",
"$",
"field",
"]",
"[",
"]",
"=",
"$",
"args",
"[",
"0",
"]",
";",
"}",
"else",
"if",
"(",
"null",
"===",
"$",
"args",
"[",
"0",
"]",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"The argument given is null \"",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"BadMethodCallException",
"(",
"\"There is no method add\"",
".",
"ucfirst",
"(",
"$",
"field",
")",
".",
"\"() on \"",
".",
"get_class",
"(",
"$",
"this",
")",
")",
";",
"}",
"}"
] | Add an object to a collection
@param string $field
@param array $args
@throws \BadMethodCallException
@throws \InvalidArgumentException | [
"Add",
"an",
"object",
"to",
"a",
"collection"
] | fb9652e30c7e4823a4e4dd571f41c8839953e72c | https://github.com/Dev4Media/ngnfeed-ebay/blob/fb9652e30c7e4823a4e4dd571f41c8839953e72c/src/D4m/NgnFeed/Ebay/Model/Entity.php#L34-L43 | train |
goncalomb/asbestos | src/classes/Http/Response.php | Response.setContentType | public function setContentType($type, $statusCode=null)
{
if (isset(static::$_types[$type])) {
$type = static::$_types[$type];
}
$this->setHeader('Content-Type', $type);
if ($statusCode) {
$this->_statusCode = $statusCode;
}
} | php | public function setContentType($type, $statusCode=null)
{
if (isset(static::$_types[$type])) {
$type = static::$_types[$type];
}
$this->setHeader('Content-Type', $type);
if ($statusCode) {
$this->_statusCode = $statusCode;
}
} | [
"public",
"function",
"setContentType",
"(",
"$",
"type",
",",
"$",
"statusCode",
"=",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"_types",
"[",
"$",
"type",
"]",
")",
")",
"{",
"$",
"type",
"=",
"static",
"::",
"$",
"_types",
"[",
"$",
"type",
"]",
";",
"}",
"$",
"this",
"->",
"setHeader",
"(",
"'Content-Type'",
",",
"$",
"type",
")",
";",
"if",
"(",
"$",
"statusCode",
")",
"{",
"$",
"this",
"->",
"_statusCode",
"=",
"$",
"statusCode",
";",
"}",
"}"
] | Set the response content type header and status code.
@param string $type Response content type.
@param int $statusCode Response status code. | [
"Set",
"the",
"response",
"content",
"type",
"header",
"and",
"status",
"code",
"."
] | 14a875b6c125cfeefe4eb1c3c524500eb8a51d04 | https://github.com/goncalomb/asbestos/blob/14a875b6c125cfeefe4eb1c3c524500eb8a51d04/src/classes/Http/Response.php#L79-L88 | train |
goncalomb/asbestos | src/classes/Http/Response.php | Response.send | public function send()
{
if (headers_sent()) {
return false;
}
// set headers
foreach ($this->getHeaders() as $h) {
header($h[0] . ': ' . $h[1], false, $this->_statusCode);
}
// set status code
if (function_exists('http_response_code')) {
http_response_code($this->_statusCode);
}
// send content
echo $this->_content;
return true;
} | php | public function send()
{
if (headers_sent()) {
return false;
}
// set headers
foreach ($this->getHeaders() as $h) {
header($h[0] . ': ' . $h[1], false, $this->_statusCode);
}
// set status code
if (function_exists('http_response_code')) {
http_response_code($this->_statusCode);
}
// send content
echo $this->_content;
return true;
} | [
"public",
"function",
"send",
"(",
")",
"{",
"if",
"(",
"headers_sent",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"// set headers",
"foreach",
"(",
"$",
"this",
"->",
"getHeaders",
"(",
")",
"as",
"$",
"h",
")",
"{",
"header",
"(",
"$",
"h",
"[",
"0",
"]",
".",
"': '",
".",
"$",
"h",
"[",
"1",
"]",
",",
"false",
",",
"$",
"this",
"->",
"_statusCode",
")",
";",
"}",
"// set status code",
"if",
"(",
"function_exists",
"(",
"'http_response_code'",
")",
")",
"{",
"http_response_code",
"(",
"$",
"this",
"->",
"_statusCode",
")",
";",
"}",
"// send content",
"echo",
"$",
"this",
"->",
"_content",
";",
"return",
"true",
";",
"}"
] | Send the response using the normal PHP functions. | [
"Send",
"the",
"response",
"using",
"the",
"normal",
"PHP",
"functions",
"."
] | 14a875b6c125cfeefe4eb1c3c524500eb8a51d04 | https://github.com/goncalomb/asbestos/blob/14a875b6c125cfeefe4eb1c3c524500eb8a51d04/src/classes/Http/Response.php#L93-L109 | train |
nicmart/DomainSpecificQuery | src/Lucene/LuceneQuery.php | LuceneQuery.convertExpressionsToStrings | public function convertExpressionsToStrings()
{
$this->setMainQuery((string) $this->getMainQuery());
$this->setFilterQueries(array_map(
function($expr) { return (string) $expr; },
$this->getFilterQueries()
));
return $this;
} | php | public function convertExpressionsToStrings()
{
$this->setMainQuery((string) $this->getMainQuery());
$this->setFilterQueries(array_map(
function($expr) { return (string) $expr; },
$this->getFilterQueries()
));
return $this;
} | [
"public",
"function",
"convertExpressionsToStrings",
"(",
")",
"{",
"$",
"this",
"->",
"setMainQuery",
"(",
"(",
"string",
")",
"$",
"this",
"->",
"getMainQuery",
"(",
")",
")",
";",
"$",
"this",
"->",
"setFilterQueries",
"(",
"array_map",
"(",
"function",
"(",
"$",
"expr",
")",
"{",
"return",
"(",
"string",
")",
"$",
"expr",
";",
"}",
",",
"$",
"this",
"->",
"getFilterQueries",
"(",
")",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Convert all expressions to strings.
@return $this | [
"Convert",
"all",
"expressions",
"to",
"strings",
"."
] | 7c01fe94337afdfae5884809e8b5487127a63ac3 | https://github.com/nicmart/DomainSpecificQuery/blob/7c01fe94337afdfae5884809e8b5487127a63ac3/src/Lucene/LuceneQuery.php#L124-L134 | train |
ekyna/Resource | Event/EventQueue.php | EventQueue.enqueue | protected function enqueue($eventName, $resourceOrEvent)
{
if (!$this->isOpened()) {
throw new RuntimeException("The event queue is closed.");
}
if (!preg_match('~^[a-z_]+\.[a-z_]+\.[a-z_]+$~', $eventName)) {
throw new InvalidArgumentException("Unexpected event name '{$eventName}'.");
}
if ($resourceOrEvent instanceof ResourceInterface) {
$resource = $resourceOrEvent;
} elseif ($resourceOrEvent instanceof ResourceEventInterface) {
$resource = $resourceOrEvent->getResource();
} else {
throw new InvalidArgumentException("Expected instanceof ResourceInterface or ResourceEventInterface");
}
$oid = spl_object_hash($resource);
// TODO we are enqueueing into en empty queue (cleared by the flush method)
// so duplication and conflict can't be resolved
// TODO see persistAndRecompute (.., $andSchedule = false)
// Don't add twice
if (isset($this->queue[$eventName]) && isset($this->queue[$eventName][$oid])) {
return;
}
$this->preventEventConflict($eventName, $oid);
if (!isset($this->queue[$eventName])) {
$this->queue[$eventName] = [];
}
$this->queue[$eventName][$oid] = $resourceOrEvent;
} | php | protected function enqueue($eventName, $resourceOrEvent)
{
if (!$this->isOpened()) {
throw new RuntimeException("The event queue is closed.");
}
if (!preg_match('~^[a-z_]+\.[a-z_]+\.[a-z_]+$~', $eventName)) {
throw new InvalidArgumentException("Unexpected event name '{$eventName}'.");
}
if ($resourceOrEvent instanceof ResourceInterface) {
$resource = $resourceOrEvent;
} elseif ($resourceOrEvent instanceof ResourceEventInterface) {
$resource = $resourceOrEvent->getResource();
} else {
throw new InvalidArgumentException("Expected instanceof ResourceInterface or ResourceEventInterface");
}
$oid = spl_object_hash($resource);
// TODO we are enqueueing into en empty queue (cleared by the flush method)
// so duplication and conflict can't be resolved
// TODO see persistAndRecompute (.., $andSchedule = false)
// Don't add twice
if (isset($this->queue[$eventName]) && isset($this->queue[$eventName][$oid])) {
return;
}
$this->preventEventConflict($eventName, $oid);
if (!isset($this->queue[$eventName])) {
$this->queue[$eventName] = [];
}
$this->queue[$eventName][$oid] = $resourceOrEvent;
} | [
"protected",
"function",
"enqueue",
"(",
"$",
"eventName",
",",
"$",
"resourceOrEvent",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isOpened",
"(",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"The event queue is closed.\"",
")",
";",
"}",
"if",
"(",
"!",
"preg_match",
"(",
"'~^[a-z_]+\\.[a-z_]+\\.[a-z_]+$~'",
",",
"$",
"eventName",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Unexpected event name '{$eventName}'.\"",
")",
";",
"}",
"if",
"(",
"$",
"resourceOrEvent",
"instanceof",
"ResourceInterface",
")",
"{",
"$",
"resource",
"=",
"$",
"resourceOrEvent",
";",
"}",
"elseif",
"(",
"$",
"resourceOrEvent",
"instanceof",
"ResourceEventInterface",
")",
"{",
"$",
"resource",
"=",
"$",
"resourceOrEvent",
"->",
"getResource",
"(",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Expected instanceof ResourceInterface or ResourceEventInterface\"",
")",
";",
"}",
"$",
"oid",
"=",
"spl_object_hash",
"(",
"$",
"resource",
")",
";",
"// TODO we are enqueueing into en empty queue (cleared by the flush method)",
"// so duplication and conflict can't be resolved",
"// TODO see persistAndRecompute (.., $andSchedule = false)",
"// Don't add twice",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"queue",
"[",
"$",
"eventName",
"]",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"queue",
"[",
"$",
"eventName",
"]",
"[",
"$",
"oid",
"]",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"preventEventConflict",
"(",
"$",
"eventName",
",",
"$",
"oid",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"queue",
"[",
"$",
"eventName",
"]",
")",
")",
"{",
"$",
"this",
"->",
"queue",
"[",
"$",
"eventName",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"queue",
"[",
"$",
"eventName",
"]",
"[",
"$",
"oid",
"]",
"=",
"$",
"resourceOrEvent",
";",
"}"
] | Schedules a resource event of the given type.
@param string $eventName
@param ResourceInterface|ResourceEventInterface $resourceOrEvent
@throws \Ekyna\Component\Resource\Exception\ResourceExceptionInterface | [
"Schedules",
"a",
"resource",
"event",
"of",
"the",
"given",
"type",
"."
] | 96ee3d28e02bd9513705408e3bb7f88a76e52f56 | https://github.com/ekyna/Resource/blob/96ee3d28e02bd9513705408e3bb7f88a76e52f56/Event/EventQueue.php#L111-L147 | train |
ekyna/Resource | Event/EventQueue.php | EventQueue.getQueueSortingCallback | protected function getQueueSortingCallback()
{
// [$resourceId => $parentId]
$parentMap = $this->registry->getParentMap();
// [$resourceId => $priority]
$priorityMap = $this->registry->getEventPriorityMap();
/**
* Returns whether or not $a is a child of $b.
*
* @param string $a
* @param string $b
*
* @return bool
*
* @todo Move in resource registry
*/
$isChildOf = function($a, $b) use ($parentMap) {
while (isset($parentMap[$a])) {
$parentId = $parentMap[$a];
if ($parentId === $b) {
return true;
}
$a = $parentId;
}
return false;
};
return function ($a, $b) use ($isChildOf, $priorityMap) {
$aId = $this->getEventPrefix($a);
$bId = $this->getEventPrefix($b);
// By prefix (resource id) priority
$aPriority = isset($priorityMap[$aId]) ? $priorityMap[$aId] : 0;
$bPriority = isset($priorityMap[$bId]) ? $priorityMap[$bId] : 0;
if ($aPriority > $bPriority) {
return -1;
} elseif ($bPriority > $aPriority) {
return 1;
}
// By resource hierarchy (children first)
if ($isChildOf($aId, $bId)) {
// B is a parent of A
return -1;
} elseif ($isChildOf($bId, $aId)) {
// A is a parent of B
return 1;
}
// By suffix priority
$aPriority = $this->getEventPriority($a);
$bPriority = $this->getEventPriority($b);
if ($aPriority > $bPriority) {
return -1;
} elseif ($bPriority > $aPriority) {
return 1;
}
return 0;
};
} | php | protected function getQueueSortingCallback()
{
// [$resourceId => $parentId]
$parentMap = $this->registry->getParentMap();
// [$resourceId => $priority]
$priorityMap = $this->registry->getEventPriorityMap();
/**
* Returns whether or not $a is a child of $b.
*
* @param string $a
* @param string $b
*
* @return bool
*
* @todo Move in resource registry
*/
$isChildOf = function($a, $b) use ($parentMap) {
while (isset($parentMap[$a])) {
$parentId = $parentMap[$a];
if ($parentId === $b) {
return true;
}
$a = $parentId;
}
return false;
};
return function ($a, $b) use ($isChildOf, $priorityMap) {
$aId = $this->getEventPrefix($a);
$bId = $this->getEventPrefix($b);
// By prefix (resource id) priority
$aPriority = isset($priorityMap[$aId]) ? $priorityMap[$aId] : 0;
$bPriority = isset($priorityMap[$bId]) ? $priorityMap[$bId] : 0;
if ($aPriority > $bPriority) {
return -1;
} elseif ($bPriority > $aPriority) {
return 1;
}
// By resource hierarchy (children first)
if ($isChildOf($aId, $bId)) {
// B is a parent of A
return -1;
} elseif ($isChildOf($bId, $aId)) {
// A is a parent of B
return 1;
}
// By suffix priority
$aPriority = $this->getEventPriority($a);
$bPriority = $this->getEventPriority($b);
if ($aPriority > $bPriority) {
return -1;
} elseif ($bPriority > $aPriority) {
return 1;
}
return 0;
};
} | [
"protected",
"function",
"getQueueSortingCallback",
"(",
")",
"{",
"// [$resourceId => $parentId]",
"$",
"parentMap",
"=",
"$",
"this",
"->",
"registry",
"->",
"getParentMap",
"(",
")",
";",
"// [$resourceId => $priority]",
"$",
"priorityMap",
"=",
"$",
"this",
"->",
"registry",
"->",
"getEventPriorityMap",
"(",
")",
";",
"/**\n * Returns whether or not $a is a child of $b.\n *\n * @param string $a\n * @param string $b\n *\n * @return bool\n *\n * @todo Move in resource registry\n */",
"$",
"isChildOf",
"=",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"use",
"(",
"$",
"parentMap",
")",
"{",
"while",
"(",
"isset",
"(",
"$",
"parentMap",
"[",
"$",
"a",
"]",
")",
")",
"{",
"$",
"parentId",
"=",
"$",
"parentMap",
"[",
"$",
"a",
"]",
";",
"if",
"(",
"$",
"parentId",
"===",
"$",
"b",
")",
"{",
"return",
"true",
";",
"}",
"$",
"a",
"=",
"$",
"parentId",
";",
"}",
"return",
"false",
";",
"}",
";",
"return",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"use",
"(",
"$",
"isChildOf",
",",
"$",
"priorityMap",
")",
"{",
"$",
"aId",
"=",
"$",
"this",
"->",
"getEventPrefix",
"(",
"$",
"a",
")",
";",
"$",
"bId",
"=",
"$",
"this",
"->",
"getEventPrefix",
"(",
"$",
"b",
")",
";",
"// By prefix (resource id) priority",
"$",
"aPriority",
"=",
"isset",
"(",
"$",
"priorityMap",
"[",
"$",
"aId",
"]",
")",
"?",
"$",
"priorityMap",
"[",
"$",
"aId",
"]",
":",
"0",
";",
"$",
"bPriority",
"=",
"isset",
"(",
"$",
"priorityMap",
"[",
"$",
"bId",
"]",
")",
"?",
"$",
"priorityMap",
"[",
"$",
"bId",
"]",
":",
"0",
";",
"if",
"(",
"$",
"aPriority",
">",
"$",
"bPriority",
")",
"{",
"return",
"-",
"1",
";",
"}",
"elseif",
"(",
"$",
"bPriority",
">",
"$",
"aPriority",
")",
"{",
"return",
"1",
";",
"}",
"// By resource hierarchy (children first)",
"if",
"(",
"$",
"isChildOf",
"(",
"$",
"aId",
",",
"$",
"bId",
")",
")",
"{",
"// B is a parent of A",
"return",
"-",
"1",
";",
"}",
"elseif",
"(",
"$",
"isChildOf",
"(",
"$",
"bId",
",",
"$",
"aId",
")",
")",
"{",
"// A is a parent of B",
"return",
"1",
";",
"}",
"// By suffix priority",
"$",
"aPriority",
"=",
"$",
"this",
"->",
"getEventPriority",
"(",
"$",
"a",
")",
";",
"$",
"bPriority",
"=",
"$",
"this",
"->",
"getEventPriority",
"(",
"$",
"b",
")",
";",
"if",
"(",
"$",
"aPriority",
">",
"$",
"bPriority",
")",
"{",
"return",
"-",
"1",
";",
"}",
"elseif",
"(",
"$",
"bPriority",
">",
"$",
"aPriority",
")",
"{",
"return",
"1",
";",
"}",
"return",
"0",
";",
"}",
";",
"}"
] | Returns the queue sorting callback.
@return \Closure | [
"Returns",
"the",
"queue",
"sorting",
"callback",
"."
] | 96ee3d28e02bd9513705408e3bb7f88a76e52f56 | https://github.com/ekyna/Resource/blob/96ee3d28e02bd9513705408e3bb7f88a76e52f56/Event/EventQueue.php#L183-L247 | train |
antbank/ab-reader | src/Adapter/PopplerAdapter.php | PopplerAdapter.read | public function read(string $file): string
{
$destFile = tempnam(sys_get_temp_dir(), 'pdf_to_text_');
$command = sprintf(
'pdftotext -layout %s %s',
escapeshellarg(realpath($file)),
escapeshellarg($destFile)
);
$return = 0;
$output = system($command, $return);
$content = file_get_contents($destFile);
unlink($destFile);
switch ($return) {
case 0:
return $content;
default:
throw new \Exception($command . PHP_EOL . $output, $return);
}
} | php | public function read(string $file): string
{
$destFile = tempnam(sys_get_temp_dir(), 'pdf_to_text_');
$command = sprintf(
'pdftotext -layout %s %s',
escapeshellarg(realpath($file)),
escapeshellarg($destFile)
);
$return = 0;
$output = system($command, $return);
$content = file_get_contents($destFile);
unlink($destFile);
switch ($return) {
case 0:
return $content;
default:
throw new \Exception($command . PHP_EOL . $output, $return);
}
} | [
"public",
"function",
"read",
"(",
"string",
"$",
"file",
")",
":",
"string",
"{",
"$",
"destFile",
"=",
"tempnam",
"(",
"sys_get_temp_dir",
"(",
")",
",",
"'pdf_to_text_'",
")",
";",
"$",
"command",
"=",
"sprintf",
"(",
"'pdftotext -layout %s %s'",
",",
"escapeshellarg",
"(",
"realpath",
"(",
"$",
"file",
")",
")",
",",
"escapeshellarg",
"(",
"$",
"destFile",
")",
")",
";",
"$",
"return",
"=",
"0",
";",
"$",
"output",
"=",
"system",
"(",
"$",
"command",
",",
"$",
"return",
")",
";",
"$",
"content",
"=",
"file_get_contents",
"(",
"$",
"destFile",
")",
";",
"unlink",
"(",
"$",
"destFile",
")",
";",
"switch",
"(",
"$",
"return",
")",
"{",
"case",
"0",
":",
"return",
"$",
"content",
";",
"default",
":",
"throw",
"new",
"\\",
"Exception",
"(",
"$",
"command",
".",
"PHP_EOL",
".",
"$",
"output",
",",
"$",
"return",
")",
";",
"}",
"}"
] | Read a file and returns text content
@param string $file File path to read
@return string File content
@throws \Exception | [
"Read",
"a",
"file",
"and",
"returns",
"text",
"content"
] | e8b8d4cae4caa7f0a9248ba7b052d387d2118463 | https://github.com/antbank/ab-reader/blob/e8b8d4cae4caa7f0a9248ba7b052d387d2118463/src/Adapter/PopplerAdapter.php#L14-L37 | train |
TiMESPLiNTER/tsFramework | src/ch/timesplinter/logger/FileLogger.php | FileLogger.writeMessage | protected function writeMessage($level, $msg, $vars = null) {
// Because of date('u')-PHP-bug (always 00000)
$mtimeParts = explode(' ', microtime());
$repl = array(
Logger::PATTERN_CLASS => $this->classContext,
Logger::PATTERN_CLASSNAME => StringUtils::afterLast($this->classContext, '\\'),
Logger::PATTERN_LEVEL => str_pad($level, 5, ' ', STR_PAD_RIGHT),
Logger::PATTERN_MESSAGE => $msg,
Logger::PATTERN_TIMESTAMP => date($this->dtFormat, $mtimeParts[1]) . ',' . substr($mtimeParts[0], 2) /* date('Y-m-d H:i:s,u') */
);
error_log(str_ireplace(array_keys($repl), $repl, $this->pattern) . "\r\n", 3, $this->logfilePath);
} | php | protected function writeMessage($level, $msg, $vars = null) {
// Because of date('u')-PHP-bug (always 00000)
$mtimeParts = explode(' ', microtime());
$repl = array(
Logger::PATTERN_CLASS => $this->classContext,
Logger::PATTERN_CLASSNAME => StringUtils::afterLast($this->classContext, '\\'),
Logger::PATTERN_LEVEL => str_pad($level, 5, ' ', STR_PAD_RIGHT),
Logger::PATTERN_MESSAGE => $msg,
Logger::PATTERN_TIMESTAMP => date($this->dtFormat, $mtimeParts[1]) . ',' . substr($mtimeParts[0], 2) /* date('Y-m-d H:i:s,u') */
);
error_log(str_ireplace(array_keys($repl), $repl, $this->pattern) . "\r\n", 3, $this->logfilePath);
} | [
"protected",
"function",
"writeMessage",
"(",
"$",
"level",
",",
"$",
"msg",
",",
"$",
"vars",
"=",
"null",
")",
"{",
"// Because of date('u')-PHP-bug (always 00000)",
"$",
"mtimeParts",
"=",
"explode",
"(",
"' '",
",",
"microtime",
"(",
")",
")",
";",
"$",
"repl",
"=",
"array",
"(",
"Logger",
"::",
"PATTERN_CLASS",
"=>",
"$",
"this",
"->",
"classContext",
",",
"Logger",
"::",
"PATTERN_CLASSNAME",
"=>",
"StringUtils",
"::",
"afterLast",
"(",
"$",
"this",
"->",
"classContext",
",",
"'\\\\'",
")",
",",
"Logger",
"::",
"PATTERN_LEVEL",
"=>",
"str_pad",
"(",
"$",
"level",
",",
"5",
",",
"' '",
",",
"STR_PAD_RIGHT",
")",
",",
"Logger",
"::",
"PATTERN_MESSAGE",
"=>",
"$",
"msg",
",",
"Logger",
"::",
"PATTERN_TIMESTAMP",
"=>",
"date",
"(",
"$",
"this",
"->",
"dtFormat",
",",
"$",
"mtimeParts",
"[",
"1",
"]",
")",
".",
"','",
".",
"substr",
"(",
"$",
"mtimeParts",
"[",
"0",
"]",
",",
"2",
")",
"/* date('Y-m-d H:i:s,u') */",
")",
";",
"error_log",
"(",
"str_ireplace",
"(",
"array_keys",
"(",
"$",
"repl",
")",
",",
"$",
"repl",
",",
"$",
"this",
"->",
"pattern",
")",
".",
"\"\\r\\n\"",
",",
"3",
",",
"$",
"this",
"->",
"logfilePath",
")",
";",
"}"
] | Writes the message with the given pattern into the defined log-file
@param type $level
@param type $msg
@param type $vars | [
"Writes",
"the",
"message",
"with",
"the",
"given",
"pattern",
"into",
"the",
"defined",
"log",
"-",
"file"
] | b3b9fd98f6d456a9e571015877ecca203786fd0c | https://github.com/TiMESPLiNTER/tsFramework/blob/b3b9fd98f6d456a9e571015877ecca203786fd0c/src/ch/timesplinter/logger/FileLogger.php#L72-L85 | train |
redkite-labs/ThemeEngineBundle | Core/Rendering/Listener/BasePageRenderingListener.php | BasePageRenderingListener.renderSlot | protected function renderSlot(Response $response, SlotContent $slotContent)
{
if (null === $slotContent->getSlotName()) {
throw new \RuntimeException('No slot has been defined for the event ' . get_class($this));
}
$isReplacing = $slotContent->isReplacing();
if (null === $isReplacing) {
throw new \RuntimeException('No action has been specified for the event ' . get_class($this));
}
if (null === $slotContent->getContent()) {
return null;
}
$content = $response->getContent();
$content = ($isReplacing) ? $this->replaceContent($slotContent, $content) : $this->injectContent($slotContent, $content);
if (null !== $content) {
$response->setContent($content);
}
return $response;
} | php | protected function renderSlot(Response $response, SlotContent $slotContent)
{
if (null === $slotContent->getSlotName()) {
throw new \RuntimeException('No slot has been defined for the event ' . get_class($this));
}
$isReplacing = $slotContent->isReplacing();
if (null === $isReplacing) {
throw new \RuntimeException('No action has been specified for the event ' . get_class($this));
}
if (null === $slotContent->getContent()) {
return null;
}
$content = $response->getContent();
$content = ($isReplacing) ? $this->replaceContent($slotContent, $content) : $this->injectContent($slotContent, $content);
if (null !== $content) {
$response->setContent($content);
}
return $response;
} | [
"protected",
"function",
"renderSlot",
"(",
"Response",
"$",
"response",
",",
"SlotContent",
"$",
"slotContent",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"slotContent",
"->",
"getSlotName",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'No slot has been defined for the event '",
".",
"get_class",
"(",
"$",
"this",
")",
")",
";",
"}",
"$",
"isReplacing",
"=",
"$",
"slotContent",
"->",
"isReplacing",
"(",
")",
";",
"if",
"(",
"null",
"===",
"$",
"isReplacing",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'No action has been specified for the event '",
".",
"get_class",
"(",
"$",
"this",
")",
")",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"slotContent",
"->",
"getContent",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"content",
"=",
"$",
"response",
"->",
"getContent",
"(",
")",
";",
"$",
"content",
"=",
"(",
"$",
"isReplacing",
")",
"?",
"$",
"this",
"->",
"replaceContent",
"(",
"$",
"slotContent",
",",
"$",
"content",
")",
":",
"$",
"this",
"->",
"injectContent",
"(",
"$",
"slotContent",
",",
"$",
"content",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"content",
")",
"{",
"$",
"response",
"->",
"setContent",
"(",
"$",
"content",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | Renders the current slot
@param Response $response
@param SlotContent $slotContent
@return \Symfony\Component\HttpFoundation\Response
@throws \RuntimeException | [
"Renders",
"the",
"current",
"slot"
] | 427409110f2d4f8f39d8802c17d5dd4115cbdf2b | https://github.com/redkite-labs/ThemeEngineBundle/blob/427409110f2d4f8f39d8802c17d5dd4115cbdf2b/Core/Rendering/Listener/BasePageRenderingListener.php#L83-L105 | train |
redkite-labs/ThemeEngineBundle | Core/Rendering/Listener/BasePageRenderingListener.php | BasePageRenderingListener.injectContent | protected function injectContent(SlotContent $slotContent, $content)
{
$regex = $this->getPattern($slotContent->getSlotName());
if (false == preg_match($regex, $content, $match)) {
return;
}
$newContent = $match[1] . PHP_EOL . $slotContent->getContent();
return preg_replace($regex, $newContent, $content);
} | php | protected function injectContent(SlotContent $slotContent, $content)
{
$regex = $this->getPattern($slotContent->getSlotName());
if (false == preg_match($regex, $content, $match)) {
return;
}
$newContent = $match[1] . PHP_EOL . $slotContent->getContent();
return preg_replace($regex, $newContent, $content);
} | [
"protected",
"function",
"injectContent",
"(",
"SlotContent",
"$",
"slotContent",
",",
"$",
"content",
")",
"{",
"$",
"regex",
"=",
"$",
"this",
"->",
"getPattern",
"(",
"$",
"slotContent",
"->",
"getSlotName",
"(",
")",
")",
";",
"if",
"(",
"false",
"==",
"preg_match",
"(",
"$",
"regex",
",",
"$",
"content",
",",
"$",
"match",
")",
")",
"{",
"return",
";",
"}",
"$",
"newContent",
"=",
"$",
"match",
"[",
"1",
"]",
".",
"PHP_EOL",
".",
"$",
"slotContent",
"->",
"getContent",
"(",
")",
";",
"return",
"preg_replace",
"(",
"$",
"regex",
",",
"$",
"newContent",
",",
"$",
"content",
")",
";",
"}"
] | Injects the content at the end of the given content
@param SlotContent $slotContent
@param string $content The content to inject
@return string | [
"Injects",
"the",
"content",
"at",
"the",
"end",
"of",
"the",
"given",
"content"
] | 427409110f2d4f8f39d8802c17d5dd4115cbdf2b | https://github.com/redkite-labs/ThemeEngineBundle/blob/427409110f2d4f8f39d8802c17d5dd4115cbdf2b/Core/Rendering/Listener/BasePageRenderingListener.php#L128-L137 | train |
ekyna/Table | Bridge/Twig/TwigRenderer.php | TwigRenderer.renderCell | public function renderCell(CellView $cell)
{
$name = $cell->vars['block_prefix'] . '_cell';
return trim($this->template->renderBlock($name, $cell->vars));
} | php | public function renderCell(CellView $cell)
{
$name = $cell->vars['block_prefix'] . '_cell';
return trim($this->template->renderBlock($name, $cell->vars));
} | [
"public",
"function",
"renderCell",
"(",
"CellView",
"$",
"cell",
")",
"{",
"$",
"name",
"=",
"$",
"cell",
"->",
"vars",
"[",
"'block_prefix'",
"]",
".",
"'_cell'",
";",
"return",
"trim",
"(",
"$",
"this",
"->",
"template",
"->",
"renderBlock",
"(",
"$",
"name",
",",
"$",
"cell",
"->",
"vars",
")",
")",
";",
"}"
] | Renders a cell.
@param CellView $cell
@return string | [
"Renders",
"a",
"cell",
"."
] | 6f06e8fd8a3248d52f3a91f10508471344db311a | https://github.com/ekyna/Table/blob/6f06e8fd8a3248d52f3a91f10508471344db311a/Bridge/Twig/TwigRenderer.php#L88-L93 | train |
ekyna/Table | Bridge/Twig/TwigRenderer.php | TwigRenderer.renderPager | public function renderPager(TableView $view, $viewName = 'twitter_bootstrap3', array $options = [])
{
if (!$view->pager) {
return '';
}
$pageParam = $view->ui['page_name'];
$options = array_merge([
'pageParameter' => '[' . $pageParam . ']',
'proximity' => 3,
'next_message' => '»',
'prev_message' => '«',
'default_view' => 'default',
], $options);
$routeGenerator = function ($page) use ($pageParam) {
return '?' . $pageParam . '=' . $page;
};
return $this->viewFactory->get($viewName)->render($view->pager, $routeGenerator, $options);
} | php | public function renderPager(TableView $view, $viewName = 'twitter_bootstrap3', array $options = [])
{
if (!$view->pager) {
return '';
}
$pageParam = $view->ui['page_name'];
$options = array_merge([
'pageParameter' => '[' . $pageParam . ']',
'proximity' => 3,
'next_message' => '»',
'prev_message' => '«',
'default_view' => 'default',
], $options);
$routeGenerator = function ($page) use ($pageParam) {
return '?' . $pageParam . '=' . $page;
};
return $this->viewFactory->get($viewName)->render($view->pager, $routeGenerator, $options);
} | [
"public",
"function",
"renderPager",
"(",
"TableView",
"$",
"view",
",",
"$",
"viewName",
"=",
"'twitter_bootstrap3'",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"$",
"view",
"->",
"pager",
")",
"{",
"return",
"''",
";",
"}",
"$",
"pageParam",
"=",
"$",
"view",
"->",
"ui",
"[",
"'page_name'",
"]",
";",
"$",
"options",
"=",
"array_merge",
"(",
"[",
"'pageParameter'",
"=>",
"'['",
".",
"$",
"pageParam",
".",
"']'",
",",
"'proximity'",
"=>",
"3",
",",
"'next_message'",
"=>",
"'»'",
",",
"'prev_message'",
"=>",
"'«'",
",",
"'default_view'",
"=>",
"'default'",
",",
"]",
",",
"$",
"options",
")",
";",
"$",
"routeGenerator",
"=",
"function",
"(",
"$",
"page",
")",
"use",
"(",
"$",
"pageParam",
")",
"{",
"return",
"'?'",
".",
"$",
"pageParam",
".",
"'='",
".",
"$",
"page",
";",
"}",
";",
"return",
"$",
"this",
"->",
"viewFactory",
"->",
"get",
"(",
"$",
"viewName",
")",
"->",
"render",
"(",
"$",
"view",
"->",
"pager",
",",
"$",
"routeGenerator",
",",
"$",
"options",
")",
";",
"}"
] | Renders pager.
@param TableView $view
@param string $viewName
@param array $options
@return string | [
"Renders",
"pager",
"."
] | 6f06e8fd8a3248d52f3a91f10508471344db311a | https://github.com/ekyna/Table/blob/6f06e8fd8a3248d52f3a91f10508471344db311a/Bridge/Twig/TwigRenderer.php#L104-L125 | train |
joegreen88/zf1-component-validate | src/Zend/Validate/EmailAddress.php | Zend_Validate_EmailAddress.setOptions | public function setOptions(array $options = array())
{
if (array_key_exists('messages', $options)) {
$this->setMessages($options['messages']);
}
if (array_key_exists('hostname', $options)) {
if (array_key_exists('allow', $options)) {
$this->setHostnameValidator($options['hostname'], $options['allow']);
} else {
$this->setHostnameValidator($options['hostname']);
}
} elseif ($this->_options['hostname'] == null) {
$this->setHostnameValidator();
}
if (array_key_exists('mx', $options)) {
$this->setValidateMx($options['mx']);
}
if (array_key_exists('deep', $options)) {
$this->setDeepMxCheck($options['deep']);
}
if (array_key_exists('domain', $options)) {
$this->setDomainCheck($options['domain']);
}
return $this;
} | php | public function setOptions(array $options = array())
{
if (array_key_exists('messages', $options)) {
$this->setMessages($options['messages']);
}
if (array_key_exists('hostname', $options)) {
if (array_key_exists('allow', $options)) {
$this->setHostnameValidator($options['hostname'], $options['allow']);
} else {
$this->setHostnameValidator($options['hostname']);
}
} elseif ($this->_options['hostname'] == null) {
$this->setHostnameValidator();
}
if (array_key_exists('mx', $options)) {
$this->setValidateMx($options['mx']);
}
if (array_key_exists('deep', $options)) {
$this->setDeepMxCheck($options['deep']);
}
if (array_key_exists('domain', $options)) {
$this->setDomainCheck($options['domain']);
}
return $this;
} | [
"public",
"function",
"setOptions",
"(",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"'messages'",
",",
"$",
"options",
")",
")",
"{",
"$",
"this",
"->",
"setMessages",
"(",
"$",
"options",
"[",
"'messages'",
"]",
")",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"'hostname'",
",",
"$",
"options",
")",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"'allow'",
",",
"$",
"options",
")",
")",
"{",
"$",
"this",
"->",
"setHostnameValidator",
"(",
"$",
"options",
"[",
"'hostname'",
"]",
",",
"$",
"options",
"[",
"'allow'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"setHostnameValidator",
"(",
"$",
"options",
"[",
"'hostname'",
"]",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"this",
"->",
"_options",
"[",
"'hostname'",
"]",
"==",
"null",
")",
"{",
"$",
"this",
"->",
"setHostnameValidator",
"(",
")",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"'mx'",
",",
"$",
"options",
")",
")",
"{",
"$",
"this",
"->",
"setValidateMx",
"(",
"$",
"options",
"[",
"'mx'",
"]",
")",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"'deep'",
",",
"$",
"options",
")",
")",
"{",
"$",
"this",
"->",
"setDeepMxCheck",
"(",
"$",
"options",
"[",
"'deep'",
"]",
")",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"'domain'",
",",
"$",
"options",
")",
")",
"{",
"$",
"this",
"->",
"setDomainCheck",
"(",
"$",
"options",
"[",
"'domain'",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set options for the email validator
@param array $options
@return Zend_Validate_EmailAddress fluid interface | [
"Set",
"options",
"for",
"the",
"email",
"validator"
] | 88d9ea016f73d48ff0ba7d06ecbbf28951fd279e | https://github.com/joegreen88/zf1-component-validate/blob/88d9ea016f73d48ff0ba7d06ecbbf28951fd279e/src/Zend/Validate/EmailAddress.php#L176-L205 | train |
joegreen88/zf1-component-validate | src/Zend/Validate/EmailAddress.php | Zend_Validate_EmailAddress.setValidateMx | public function setValidateMx($mx)
{
if ((bool) $mx && !$this->validateMxSupported()) {
throw new Zend_Validate_Exception('MX checking not available on this system');
}
$this->_options['mx'] = (bool) $mx;
return $this;
} | php | public function setValidateMx($mx)
{
if ((bool) $mx && !$this->validateMxSupported()) {
throw new Zend_Validate_Exception('MX checking not available on this system');
}
$this->_options['mx'] = (bool) $mx;
return $this;
} | [
"public",
"function",
"setValidateMx",
"(",
"$",
"mx",
")",
"{",
"if",
"(",
"(",
"bool",
")",
"$",
"mx",
"&&",
"!",
"$",
"this",
"->",
"validateMxSupported",
"(",
")",
")",
"{",
"throw",
"new",
"Zend_Validate_Exception",
"(",
"'MX checking not available on this system'",
")",
";",
"}",
"$",
"this",
"->",
"_options",
"[",
"'mx'",
"]",
"=",
"(",
"bool",
")",
"$",
"mx",
";",
"return",
"$",
"this",
";",
"}"
] | Set whether we check for a valid MX record via DNS
This only applies when DNS hostnames are validated
@param boolean $mx Set allowed to true to validate for MX records, and false to not validate them
@return Zend_Validate_EmailAddress Fluid Interface | [
"Set",
"whether",
"we",
"check",
"for",
"a",
"valid",
"MX",
"record",
"via",
"DNS"
] | 88d9ea016f73d48ff0ba7d06ecbbf28951fd279e | https://github.com/joegreen88/zf1-component-validate/blob/88d9ea016f73d48ff0ba7d06ecbbf28951fd279e/src/Zend/Validate/EmailAddress.php#L288-L297 | train |
vdhicts/dicms-pagination | src/Pagination.php | Pagination.setLimit | private function setLimit($limit = self::NO_LIMIT)
{
if (! is_int($limit)) {
throw new Exceptions\InvalidIntegerType(gettype($limit));
}
// A limit of 0 or less is useless, fallback to no limit
if ($limit !== self::NO_LIMIT && $limit <= 0) {
throw new Exceptions\PositiveIntegerRequired($limit);
}
$this->limit = $limit;
} | php | private function setLimit($limit = self::NO_LIMIT)
{
if (! is_int($limit)) {
throw new Exceptions\InvalidIntegerType(gettype($limit));
}
// A limit of 0 or less is useless, fallback to no limit
if ($limit !== self::NO_LIMIT && $limit <= 0) {
throw new Exceptions\PositiveIntegerRequired($limit);
}
$this->limit = $limit;
} | [
"private",
"function",
"setLimit",
"(",
"$",
"limit",
"=",
"self",
"::",
"NO_LIMIT",
")",
"{",
"if",
"(",
"!",
"is_int",
"(",
"$",
"limit",
")",
")",
"{",
"throw",
"new",
"Exceptions",
"\\",
"InvalidIntegerType",
"(",
"gettype",
"(",
"$",
"limit",
")",
")",
";",
"}",
"// A limit of 0 or less is useless, fallback to no limit",
"if",
"(",
"$",
"limit",
"!==",
"self",
"::",
"NO_LIMIT",
"&&",
"$",
"limit",
"<=",
"0",
")",
"{",
"throw",
"new",
"Exceptions",
"\\",
"PositiveIntegerRequired",
"(",
"$",
"limit",
")",
";",
"}",
"$",
"this",
"->",
"limit",
"=",
"$",
"limit",
";",
"}"
] | Stores the limit.
@param int $limit
@throws Exceptions\InvalidIntegerType
@throws Exceptions\PositiveIntegerRequired | [
"Stores",
"the",
"limit",
"."
] | e280cb0015ffbe210bcf94acf68186fa5f31f122 | https://github.com/vdhicts/dicms-pagination/blob/e280cb0015ffbe210bcf94acf68186fa5f31f122/src/Pagination.php#L94-L106 | train |
vdhicts/dicms-pagination | src/Pagination.php | Pagination.setTotalItems | private function setTotalItems($totalItems)
{
if (! is_int($totalItems)) {
throw new Exceptions\InvalidIntegerType(gettype($totalItems));
}
// A result may have zero or more items
if ($totalItems < 0) {
throw new Exceptions\PositiveIntegerRequired($totalItems);
}
$this->totalItems = $totalItems;
$this->changedTotalItems();
} | php | private function setTotalItems($totalItems)
{
if (! is_int($totalItems)) {
throw new Exceptions\InvalidIntegerType(gettype($totalItems));
}
// A result may have zero or more items
if ($totalItems < 0) {
throw new Exceptions\PositiveIntegerRequired($totalItems);
}
$this->totalItems = $totalItems;
$this->changedTotalItems();
} | [
"private",
"function",
"setTotalItems",
"(",
"$",
"totalItems",
")",
"{",
"if",
"(",
"!",
"is_int",
"(",
"$",
"totalItems",
")",
")",
"{",
"throw",
"new",
"Exceptions",
"\\",
"InvalidIntegerType",
"(",
"gettype",
"(",
"$",
"totalItems",
")",
")",
";",
"}",
"// A result may have zero or more items",
"if",
"(",
"$",
"totalItems",
"<",
"0",
")",
"{",
"throw",
"new",
"Exceptions",
"\\",
"PositiveIntegerRequired",
"(",
"$",
"totalItems",
")",
";",
"}",
"$",
"this",
"->",
"totalItems",
"=",
"$",
"totalItems",
";",
"$",
"this",
"->",
"changedTotalItems",
"(",
")",
";",
"}"
] | Stores the total amount of items.
@param int $totalItems
@throws Exceptions\InvalidIntegerType
@throws Exceptions\PositiveIntegerRequired | [
"Stores",
"the",
"total",
"amount",
"of",
"items",
"."
] | e280cb0015ffbe210bcf94acf68186fa5f31f122 | https://github.com/vdhicts/dicms-pagination/blob/e280cb0015ffbe210bcf94acf68186fa5f31f122/src/Pagination.php#L143-L157 | train |
vdhicts/dicms-pagination | src/Pagination.php | Pagination.calculateTotalPages | private function calculateTotalPages()
{
// With zero items, there is still one page
if ($this->getTotalItems() === 0) {
$this->setTotalPages(1);
return;
}
// The total amount of pages is calculated by dividing the total amount of items by the items per page
$totalPages = ceil($this->getTotalItems() / $this->getLimit());
$this->setTotalPages((int)$totalPages);
} | php | private function calculateTotalPages()
{
// With zero items, there is still one page
if ($this->getTotalItems() === 0) {
$this->setTotalPages(1);
return;
}
// The total amount of pages is calculated by dividing the total amount of items by the items per page
$totalPages = ceil($this->getTotalItems() / $this->getLimit());
$this->setTotalPages((int)$totalPages);
} | [
"private",
"function",
"calculateTotalPages",
"(",
")",
"{",
"// With zero items, there is still one page",
"if",
"(",
"$",
"this",
"->",
"getTotalItems",
"(",
")",
"===",
"0",
")",
"{",
"$",
"this",
"->",
"setTotalPages",
"(",
"1",
")",
";",
"return",
";",
"}",
"// The total amount of pages is calculated by dividing the total amount of items by the items per page",
"$",
"totalPages",
"=",
"ceil",
"(",
"$",
"this",
"->",
"getTotalItems",
"(",
")",
"/",
"$",
"this",
"->",
"getLimit",
"(",
")",
")",
";",
"$",
"this",
"->",
"setTotalPages",
"(",
"(",
"int",
")",
"$",
"totalPages",
")",
";",
"}"
] | Calculates the total amount of pages. | [
"Calculates",
"the",
"total",
"amount",
"of",
"pages",
"."
] | e280cb0015ffbe210bcf94acf68186fa5f31f122 | https://github.com/vdhicts/dicms-pagination/blob/e280cb0015ffbe210bcf94acf68186fa5f31f122/src/Pagination.php#L170-L182 | train |
vdhicts/dicms-pagination | src/Pagination.php | Pagination.setPage | private function setPage($page)
{
if (! is_int($page)) {
throw new Exceptions\InvalidIntegerType(gettype($page));
}
// There is at least one page
if ($page <= 0) {
throw new Exceptions\PositiveIntegerRequired($page);
}
$this->page = $page;
$this->changedPage();
} | php | private function setPage($page)
{
if (! is_int($page)) {
throw new Exceptions\InvalidIntegerType(gettype($page));
}
// There is at least one page
if ($page <= 0) {
throw new Exceptions\PositiveIntegerRequired($page);
}
$this->page = $page;
$this->changedPage();
} | [
"private",
"function",
"setPage",
"(",
"$",
"page",
")",
"{",
"if",
"(",
"!",
"is_int",
"(",
"$",
"page",
")",
")",
"{",
"throw",
"new",
"Exceptions",
"\\",
"InvalidIntegerType",
"(",
"gettype",
"(",
"$",
"page",
")",
")",
";",
"}",
"// There is at least one page",
"if",
"(",
"$",
"page",
"<=",
"0",
")",
"{",
"throw",
"new",
"Exceptions",
"\\",
"PositiveIntegerRequired",
"(",
"$",
"page",
")",
";",
"}",
"$",
"this",
"->",
"page",
"=",
"$",
"page",
";",
"$",
"this",
"->",
"changedPage",
"(",
")",
";",
"}"
] | Stores the current page.
@param int $page
@throws Exceptions\InvalidIntegerType
@throws Exceptions\PositiveIntegerRequired | [
"Stores",
"the",
"current",
"page",
"."
] | e280cb0015ffbe210bcf94acf68186fa5f31f122 | https://github.com/vdhicts/dicms-pagination/blob/e280cb0015ffbe210bcf94acf68186fa5f31f122/src/Pagination.php#L199-L213 | train |
vdhicts/dicms-pagination | src/Pagination.php | Pagination.calculateOffset | private function calculateOffset()
{
// When no limit is provided, all items are on one page, so the offset is unreasonable
if (! $this->hasLimit()) {
$this->setOffset(0);
return;
}
$offset = ($this->getPage() * $this->getLimit()) - $this->getLimit();
$this->setOffset((int)$offset);
} | php | private function calculateOffset()
{
// When no limit is provided, all items are on one page, so the offset is unreasonable
if (! $this->hasLimit()) {
$this->setOffset(0);
return;
}
$offset = ($this->getPage() * $this->getLimit()) - $this->getLimit();
$this->setOffset((int)$offset);
} | [
"private",
"function",
"calculateOffset",
"(",
")",
"{",
"// When no limit is provided, all items are on one page, so the offset is unreasonable",
"if",
"(",
"!",
"$",
"this",
"->",
"hasLimit",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setOffset",
"(",
"0",
")",
";",
"return",
";",
"}",
"$",
"offset",
"=",
"(",
"$",
"this",
"->",
"getPage",
"(",
")",
"*",
"$",
"this",
"->",
"getLimit",
"(",
")",
")",
"-",
"$",
"this",
"->",
"getLimit",
"(",
")",
";",
"$",
"this",
"->",
"setOffset",
"(",
"(",
"int",
")",
"$",
"offset",
")",
";",
"}"
] | Calculates the offset for the current page and limit. | [
"Calculates",
"the",
"offset",
"for",
"the",
"current",
"page",
"and",
"limit",
"."
] | e280cb0015ffbe210bcf94acf68186fa5f31f122 | https://github.com/vdhicts/dicms-pagination/blob/e280cb0015ffbe210bcf94acf68186fa5f31f122/src/Pagination.php#L228-L239 | train |
vdhicts/dicms-pagination | src/Pagination.php | Pagination.calculateFirstItemOnPage | private function calculateFirstItemOnPage()
{
// When an offset is used, increase the first item with 1
$offsetItem = $this->getOffset() !== 0 ? 1 : 0;
// When there are a total amount of items and the offset is zero, increase 1
if ($this->getTotalItems() !== 0 && $offsetItem === 0) {
$offsetItem = 1;
}
// Determine the first item on the page
$firstItem = $this->getOffset() + $offsetItem;
$this->setFirstItemOnPage((int)$firstItem);
} | php | private function calculateFirstItemOnPage()
{
// When an offset is used, increase the first item with 1
$offsetItem = $this->getOffset() !== 0 ? 1 : 0;
// When there are a total amount of items and the offset is zero, increase 1
if ($this->getTotalItems() !== 0 && $offsetItem === 0) {
$offsetItem = 1;
}
// Determine the first item on the page
$firstItem = $this->getOffset() + $offsetItem;
$this->setFirstItemOnPage((int)$firstItem);
} | [
"private",
"function",
"calculateFirstItemOnPage",
"(",
")",
"{",
"// When an offset is used, increase the first item with 1",
"$",
"offsetItem",
"=",
"$",
"this",
"->",
"getOffset",
"(",
")",
"!==",
"0",
"?",
"1",
":",
"0",
";",
"// When there are a total amount of items and the offset is zero, increase 1",
"if",
"(",
"$",
"this",
"->",
"getTotalItems",
"(",
")",
"!==",
"0",
"&&",
"$",
"offsetItem",
"===",
"0",
")",
"{",
"$",
"offsetItem",
"=",
"1",
";",
"}",
"// Determine the first item on the page",
"$",
"firstItem",
"=",
"$",
"this",
"->",
"getOffset",
"(",
")",
"+",
"$",
"offsetItem",
";",
"$",
"this",
"->",
"setFirstItemOnPage",
"(",
"(",
"int",
")",
"$",
"firstItem",
")",
";",
"}"
] | Calculates which item number is the first on the current page. | [
"Calculates",
"which",
"item",
"number",
"is",
"the",
"first",
"on",
"the",
"current",
"page",
"."
] | e280cb0015ffbe210bcf94acf68186fa5f31f122 | https://github.com/vdhicts/dicms-pagination/blob/e280cb0015ffbe210bcf94acf68186fa5f31f122/src/Pagination.php#L244-L258 | train |
vdhicts/dicms-pagination | src/Pagination.php | Pagination.calculateLastItemOnPage | private function calculateLastItemOnPage()
{
// When no limit, the last item is the total amount of items
if (! $this->hasLimit()) {
$this->setLastItemOnPage($this->getTotalItems());
return;
}
// Determine the last item on the page
$lastItem = $this->getOffset() + $this->getLimit();
if ($this->getTotalItems() !== 0 && $lastItem > $this->getTotalItems()) {
$lastItem = $this->getTotalItems();
}
$this->setLastItemOnPage((int)$lastItem);
} | php | private function calculateLastItemOnPage()
{
// When no limit, the last item is the total amount of items
if (! $this->hasLimit()) {
$this->setLastItemOnPage($this->getTotalItems());
return;
}
// Determine the last item on the page
$lastItem = $this->getOffset() + $this->getLimit();
if ($this->getTotalItems() !== 0 && $lastItem > $this->getTotalItems()) {
$lastItem = $this->getTotalItems();
}
$this->setLastItemOnPage((int)$lastItem);
} | [
"private",
"function",
"calculateLastItemOnPage",
"(",
")",
"{",
"// When no limit, the last item is the total amount of items",
"if",
"(",
"!",
"$",
"this",
"->",
"hasLimit",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setLastItemOnPage",
"(",
"$",
"this",
"->",
"getTotalItems",
"(",
")",
")",
";",
"return",
";",
"}",
"// Determine the last item on the page",
"$",
"lastItem",
"=",
"$",
"this",
"->",
"getOffset",
"(",
")",
"+",
"$",
"this",
"->",
"getLimit",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getTotalItems",
"(",
")",
"!==",
"0",
"&&",
"$",
"lastItem",
">",
"$",
"this",
"->",
"getTotalItems",
"(",
")",
")",
"{",
"$",
"lastItem",
"=",
"$",
"this",
"->",
"getTotalItems",
"(",
")",
";",
"}",
"$",
"this",
"->",
"setLastItemOnPage",
"(",
"(",
"int",
")",
"$",
"lastItem",
")",
";",
"}"
] | Calculates which item number is the last on the current page. | [
"Calculates",
"which",
"item",
"number",
"is",
"the",
"last",
"on",
"the",
"current",
"page",
"."
] | e280cb0015ffbe210bcf94acf68186fa5f31f122 | https://github.com/vdhicts/dicms-pagination/blob/e280cb0015ffbe210bcf94acf68186fa5f31f122/src/Pagination.php#L263-L278 | train |
Eden-PHP/Block | Component.php | Component.alert | public function alert($message, $type = 'info')
{
Argument::i()
->test(2, 'string')
->test(3, 'string');
return Alert::i($message, $type);
} | php | public function alert($message, $type = 'info')
{
Argument::i()
->test(2, 'string')
->test(3, 'string');
return Alert::i($message, $type);
} | [
"public",
"function",
"alert",
"(",
"$",
"message",
",",
"$",
"type",
"=",
"'info'",
")",
"{",
"Argument",
"::",
"i",
"(",
")",
"->",
"test",
"(",
"2",
",",
"'string'",
")",
"->",
"test",
"(",
"3",
",",
"'string'",
")",
";",
"return",
"Alert",
"::",
"i",
"(",
"$",
"message",
",",
"$",
"type",
")",
";",
"}"
] | Returns an alert
@param string
@param string
@return Eden\Block\Component\Alert | [
"Returns",
"an",
"alert"
] | 681b9f01dd118612d0fced84d2f702167b52109b | https://github.com/Eden-PHP/Block/blob/681b9f01dd118612d0fced84d2f702167b52109b/Component.php#L40-L47 | train |
Eden-PHP/Block | Component.php | Component.hero | public function hero(array $images = array(), $delay = null)
{
Argument::i()->test(2, 'scalar', 'null');
$field = Hero::i()->setImages($images);
if(!is_null($delay) and is_numeric($delay) ) {
$field->setDelay($delay);
}
return $field;
} | php | public function hero(array $images = array(), $delay = null)
{
Argument::i()->test(2, 'scalar', 'null');
$field = Hero::i()->setImages($images);
if(!is_null($delay) and is_numeric($delay) ) {
$field->setDelay($delay);
}
return $field;
} | [
"public",
"function",
"hero",
"(",
"array",
"$",
"images",
"=",
"array",
"(",
")",
",",
"$",
"delay",
"=",
"null",
")",
"{",
"Argument",
"::",
"i",
"(",
")",
"->",
"test",
"(",
"2",
",",
"'scalar'",
",",
"'null'",
")",
";",
"$",
"field",
"=",
"Hero",
"::",
"i",
"(",
")",
"->",
"setImages",
"(",
"$",
"images",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"delay",
")",
"and",
"is_numeric",
"(",
"$",
"delay",
")",
")",
"{",
"$",
"field",
"->",
"setDelay",
"(",
"$",
"delay",
")",
";",
"}",
"return",
"$",
"field",
";",
"}"
] | Returns a hero
@param array
@param scalar|null
@return Eden\Block\Hero | [
"Returns",
"a",
"hero"
] | 681b9f01dd118612d0fced84d2f702167b52109b | https://github.com/Eden-PHP/Block/blob/681b9f01dd118612d0fced84d2f702167b52109b/Component.php#L66-L77 | train |
Eden-PHP/Block | Component.php | Component.sort | public function sort(array $query, $key, $label, $url = null)
{
Argument::i()
->test(2, 'string')
->test(3, 'string')
->test(4, 'string', 'null');
$block = Sort::i($query, $key, $label);
if($url) {
$block->setUrl($url);
}
return $block;
} | php | public function sort(array $query, $key, $label, $url = null)
{
Argument::i()
->test(2, 'string')
->test(3, 'string')
->test(4, 'string', 'null');
$block = Sort::i($query, $key, $label);
if($url) {
$block->setUrl($url);
}
return $block;
} | [
"public",
"function",
"sort",
"(",
"array",
"$",
"query",
",",
"$",
"key",
",",
"$",
"label",
",",
"$",
"url",
"=",
"null",
")",
"{",
"Argument",
"::",
"i",
"(",
")",
"->",
"test",
"(",
"2",
",",
"'string'",
")",
"->",
"test",
"(",
"3",
",",
"'string'",
")",
"->",
"test",
"(",
"4",
",",
"'string'",
",",
"'null'",
")",
";",
"$",
"block",
"=",
"Sort",
"::",
"i",
"(",
"$",
"query",
",",
"$",
"key",
",",
"$",
"label",
")",
";",
"if",
"(",
"$",
"url",
")",
"{",
"$",
"block",
"->",
"setUrl",
"(",
"$",
"url",
")",
";",
"}",
"return",
"$",
"block",
";",
"}"
] | Returns table sort block
@param array
@param string
@param string
@param string|null
@return Eden\Block\Sort | [
"Returns",
"table",
"sort",
"block"
] | 681b9f01dd118612d0fced84d2f702167b52109b | https://github.com/Eden-PHP/Block/blob/681b9f01dd118612d0fced84d2f702167b52109b/Component.php#L88-L102 | train |
fridge-project/dbal | src/Fridge/DBAL/SchemaManager/SQLCollector/AlterSchemaSQLCollector.php | AlterSchemaSQLCollector.setPlatform | public function setPlatform(PlatformInterface $platform)
{
$this->platform = $platform;
$this->createTableSQLCollector->setPlatform($platform);
$this->dropTableSQLCollector->setPlatform($platform);
$this->alterTableSQLCollector->setPlatform($platform);
$this->init();
} | php | public function setPlatform(PlatformInterface $platform)
{
$this->platform = $platform;
$this->createTableSQLCollector->setPlatform($platform);
$this->dropTableSQLCollector->setPlatform($platform);
$this->alterTableSQLCollector->setPlatform($platform);
$this->init();
} | [
"public",
"function",
"setPlatform",
"(",
"PlatformInterface",
"$",
"platform",
")",
"{",
"$",
"this",
"->",
"platform",
"=",
"$",
"platform",
";",
"$",
"this",
"->",
"createTableSQLCollector",
"->",
"setPlatform",
"(",
"$",
"platform",
")",
";",
"$",
"this",
"->",
"dropTableSQLCollector",
"->",
"setPlatform",
"(",
"$",
"platform",
")",
";",
"$",
"this",
"->",
"alterTableSQLCollector",
"->",
"setPlatform",
"(",
"$",
"platform",
")",
";",
"$",
"this",
"->",
"init",
"(",
")",
";",
"}"
] | Sets the platform used to collect queries.
@param \Fridge\DBAL\Platform\PlatformInterface $platform The platform used to collect queries. | [
"Sets",
"the",
"platform",
"used",
"to",
"collect",
"queries",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/SchemaManager/SQLCollector/AlterSchemaSQLCollector.php#L101-L110 | train |
fridge-project/dbal | src/Fridge/DBAL/SchemaManager/SQLCollector/AlterSchemaSQLCollector.php | AlterSchemaSQLCollector.init | public function init()
{
$this->createTableSQLCollector->init();
$this->dropTableSQLCollector->init();
$this->alterTableSQLCollector->init();
$this->dropSequenceQueries = array();
$this->dropViewQueries = array();
$this->createViewQueries = array();
$this->createSequenceQueries = array();
$this->renameSchemaQueries = array();
} | php | public function init()
{
$this->createTableSQLCollector->init();
$this->dropTableSQLCollector->init();
$this->alterTableSQLCollector->init();
$this->dropSequenceQueries = array();
$this->dropViewQueries = array();
$this->createViewQueries = array();
$this->createSequenceQueries = array();
$this->renameSchemaQueries = array();
} | [
"public",
"function",
"init",
"(",
")",
"{",
"$",
"this",
"->",
"createTableSQLCollector",
"->",
"init",
"(",
")",
";",
"$",
"this",
"->",
"dropTableSQLCollector",
"->",
"init",
"(",
")",
";",
"$",
"this",
"->",
"alterTableSQLCollector",
"->",
"init",
"(",
")",
";",
"$",
"this",
"->",
"dropSequenceQueries",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"dropViewQueries",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"createViewQueries",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"createSequenceQueries",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"renameSchemaQueries",
"=",
"array",
"(",
")",
";",
"}"
] | Reinitializes the SQL collector. | [
"Reinitializes",
"the",
"SQL",
"collector",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/SchemaManager/SQLCollector/AlterSchemaSQLCollector.php#L115-L126 | train |
fridge-project/dbal | src/Fridge/DBAL/SchemaManager/SQLCollector/AlterSchemaSQLCollector.php | AlterSchemaSQLCollector.collect | public function collect(SchemaDiff $schemaDiff)
{
if ($schemaDiff->getOldAsset()->getName() !== $schemaDiff->getNewAsset()->getName()) {
$this->renameSchemaQueries = array_merge(
$this->renameSchemaQueries,
$this->platform->getRenameDatabaseSQLQueries($schemaDiff)
);
}
$this->collectTables($schemaDiff);
$this->collectSequences($schemaDiff);
$this->collectViews($schemaDiff);
} | php | public function collect(SchemaDiff $schemaDiff)
{
if ($schemaDiff->getOldAsset()->getName() !== $schemaDiff->getNewAsset()->getName()) {
$this->renameSchemaQueries = array_merge(
$this->renameSchemaQueries,
$this->platform->getRenameDatabaseSQLQueries($schemaDiff)
);
}
$this->collectTables($schemaDiff);
$this->collectSequences($schemaDiff);
$this->collectViews($schemaDiff);
} | [
"public",
"function",
"collect",
"(",
"SchemaDiff",
"$",
"schemaDiff",
")",
"{",
"if",
"(",
"$",
"schemaDiff",
"->",
"getOldAsset",
"(",
")",
"->",
"getName",
"(",
")",
"!==",
"$",
"schemaDiff",
"->",
"getNewAsset",
"(",
")",
"->",
"getName",
"(",
")",
")",
"{",
"$",
"this",
"->",
"renameSchemaQueries",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"renameSchemaQueries",
",",
"$",
"this",
"->",
"platform",
"->",
"getRenameDatabaseSQLQueries",
"(",
"$",
"schemaDiff",
")",
")",
";",
"}",
"$",
"this",
"->",
"collectTables",
"(",
"$",
"schemaDiff",
")",
";",
"$",
"this",
"->",
"collectSequences",
"(",
"$",
"schemaDiff",
")",
";",
"$",
"this",
"->",
"collectViews",
"(",
"$",
"schemaDiff",
")",
";",
"}"
] | Collects queries to alter a schema.
@param \Fridge\DBAL\Schema\Diff\SchemaDiff $schemaDiff The schema difference. | [
"Collects",
"queries",
"to",
"alter",
"a",
"schema",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/SchemaManager/SQLCollector/AlterSchemaSQLCollector.php#L133-L145 | train |
fridge-project/dbal | src/Fridge/DBAL/SchemaManager/SQLCollector/AlterSchemaSQLCollector.php | AlterSchemaSQLCollector.getQueries | public function getQueries()
{
return array_merge(
$this->getDropSequenceQueries(),
$this->getDropViewQueries(),
$this->getRenameTableQueries(),
$this->getDropCheckQueries(),
$this->getDropForeignKeyQueries(),
$this->getDropIndexQueries(),
$this->getDropPrimaryKeyQueries(),
$this->getDropTableQueries(),
$this->getDropColumnQueries(),
$this->getAlterColumnQueries(),
$this->getCreateColumnQueries(),
$this->getCreateTableQueries(),
$this->getCreatePrimaryKeyQueries(),
$this->getCreateIndexQueries(),
$this->getCreateForeignKeyQueries(),
$this->getCreateCheckQueries(),
$this->getCreateViewQueries(),
$this->getCreateSequenceQueries(),
$this->getRenameSchemaQueries()
);
} | php | public function getQueries()
{
return array_merge(
$this->getDropSequenceQueries(),
$this->getDropViewQueries(),
$this->getRenameTableQueries(),
$this->getDropCheckQueries(),
$this->getDropForeignKeyQueries(),
$this->getDropIndexQueries(),
$this->getDropPrimaryKeyQueries(),
$this->getDropTableQueries(),
$this->getDropColumnQueries(),
$this->getAlterColumnQueries(),
$this->getCreateColumnQueries(),
$this->getCreateTableQueries(),
$this->getCreatePrimaryKeyQueries(),
$this->getCreateIndexQueries(),
$this->getCreateForeignKeyQueries(),
$this->getCreateCheckQueries(),
$this->getCreateViewQueries(),
$this->getCreateSequenceQueries(),
$this->getRenameSchemaQueries()
);
} | [
"public",
"function",
"getQueries",
"(",
")",
"{",
"return",
"array_merge",
"(",
"$",
"this",
"->",
"getDropSequenceQueries",
"(",
")",
",",
"$",
"this",
"->",
"getDropViewQueries",
"(",
")",
",",
"$",
"this",
"->",
"getRenameTableQueries",
"(",
")",
",",
"$",
"this",
"->",
"getDropCheckQueries",
"(",
")",
",",
"$",
"this",
"->",
"getDropForeignKeyQueries",
"(",
")",
",",
"$",
"this",
"->",
"getDropIndexQueries",
"(",
")",
",",
"$",
"this",
"->",
"getDropPrimaryKeyQueries",
"(",
")",
",",
"$",
"this",
"->",
"getDropTableQueries",
"(",
")",
",",
"$",
"this",
"->",
"getDropColumnQueries",
"(",
")",
",",
"$",
"this",
"->",
"getAlterColumnQueries",
"(",
")",
",",
"$",
"this",
"->",
"getCreateColumnQueries",
"(",
")",
",",
"$",
"this",
"->",
"getCreateTableQueries",
"(",
")",
",",
"$",
"this",
"->",
"getCreatePrimaryKeyQueries",
"(",
")",
",",
"$",
"this",
"->",
"getCreateIndexQueries",
"(",
")",
",",
"$",
"this",
"->",
"getCreateForeignKeyQueries",
"(",
")",
",",
"$",
"this",
"->",
"getCreateCheckQueries",
"(",
")",
",",
"$",
"this",
"->",
"getCreateViewQueries",
"(",
")",
",",
"$",
"this",
"->",
"getCreateSequenceQueries",
"(",
")",
",",
"$",
"this",
"->",
"getRenameSchemaQueries",
"(",
")",
")",
";",
"}"
] | Gets the queries to alter the schema.
@return array the queries to alter the schema. | [
"Gets",
"the",
"queries",
"to",
"alter",
"the",
"schema",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/SchemaManager/SQLCollector/AlterSchemaSQLCollector.php#L348-L371 | train |
fridge-project/dbal | src/Fridge/DBAL/SchemaManager/SQLCollector/AlterSchemaSQLCollector.php | AlterSchemaSQLCollector.collectTables | private function collectTables(SchemaDiff $schemaDiff)
{
foreach ($schemaDiff->getCreatedTables() as $table) {
$this->createTableSQLCollector->collect($table);
}
foreach ($schemaDiff->getDroppedTables() as $table) {
$this->dropTableSQLCollector->collect($table);
}
foreach ($schemaDiff->getAlteredTables() as $tableDiff) {
$this->alterTableSQLCollector->collect($tableDiff);
}
} | php | private function collectTables(SchemaDiff $schemaDiff)
{
foreach ($schemaDiff->getCreatedTables() as $table) {
$this->createTableSQLCollector->collect($table);
}
foreach ($schemaDiff->getDroppedTables() as $table) {
$this->dropTableSQLCollector->collect($table);
}
foreach ($schemaDiff->getAlteredTables() as $tableDiff) {
$this->alterTableSQLCollector->collect($tableDiff);
}
} | [
"private",
"function",
"collectTables",
"(",
"SchemaDiff",
"$",
"schemaDiff",
")",
"{",
"foreach",
"(",
"$",
"schemaDiff",
"->",
"getCreatedTables",
"(",
")",
"as",
"$",
"table",
")",
"{",
"$",
"this",
"->",
"createTableSQLCollector",
"->",
"collect",
"(",
"$",
"table",
")",
";",
"}",
"foreach",
"(",
"$",
"schemaDiff",
"->",
"getDroppedTables",
"(",
")",
"as",
"$",
"table",
")",
"{",
"$",
"this",
"->",
"dropTableSQLCollector",
"->",
"collect",
"(",
"$",
"table",
")",
";",
"}",
"foreach",
"(",
"$",
"schemaDiff",
"->",
"getAlteredTables",
"(",
")",
"as",
"$",
"tableDiff",
")",
"{",
"$",
"this",
"->",
"alterTableSQLCollector",
"->",
"collect",
"(",
"$",
"tableDiff",
")",
";",
"}",
"}"
] | Collects queries about tables to alter a schema.
@param \Fridge\DBAL\Schema\Diff\SchemaDiff $schemaDiff The schema difference. | [
"Collects",
"queries",
"about",
"tables",
"to",
"alter",
"a",
"schema",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/SchemaManager/SQLCollector/AlterSchemaSQLCollector.php#L378-L391 | train |
fridge-project/dbal | src/Fridge/DBAL/SchemaManager/SQLCollector/AlterSchemaSQLCollector.php | AlterSchemaSQLCollector.collectViews | private function collectViews(SchemaDiff $schemaDiff)
{
foreach ($schemaDiff->getCreatedViews() as $view) {
$this->createViewQueries = array_merge(
$this->createViewQueries,
$this->platform->getCreateViewSQLQueries($view)
);
}
foreach ($schemaDiff->getDroppedViews() as $view) {
$this->dropViewQueries = array_merge(
$this->dropViewQueries,
$this->platform->getDropViewSQLQueries($view)
);
}
} | php | private function collectViews(SchemaDiff $schemaDiff)
{
foreach ($schemaDiff->getCreatedViews() as $view) {
$this->createViewQueries = array_merge(
$this->createViewQueries,
$this->platform->getCreateViewSQLQueries($view)
);
}
foreach ($schemaDiff->getDroppedViews() as $view) {
$this->dropViewQueries = array_merge(
$this->dropViewQueries,
$this->platform->getDropViewSQLQueries($view)
);
}
} | [
"private",
"function",
"collectViews",
"(",
"SchemaDiff",
"$",
"schemaDiff",
")",
"{",
"foreach",
"(",
"$",
"schemaDiff",
"->",
"getCreatedViews",
"(",
")",
"as",
"$",
"view",
")",
"{",
"$",
"this",
"->",
"createViewQueries",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"createViewQueries",
",",
"$",
"this",
"->",
"platform",
"->",
"getCreateViewSQLQueries",
"(",
"$",
"view",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"schemaDiff",
"->",
"getDroppedViews",
"(",
")",
"as",
"$",
"view",
")",
"{",
"$",
"this",
"->",
"dropViewQueries",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"dropViewQueries",
",",
"$",
"this",
"->",
"platform",
"->",
"getDropViewSQLQueries",
"(",
"$",
"view",
")",
")",
";",
"}",
"}"
] | Collects queries about views to alter a schema.
@param \Fridge\DBAL\Schema\Diff\SchemaDiff $schemaDiff The schema difference. | [
"Collects",
"queries",
"about",
"views",
"to",
"alter",
"a",
"schema",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/SchemaManager/SQLCollector/AlterSchemaSQLCollector.php#L398-L413 | train |
fridge-project/dbal | src/Fridge/DBAL/SchemaManager/SQLCollector/AlterSchemaSQLCollector.php | AlterSchemaSQLCollector.collectSequences | private function collectSequences(SchemaDiff $schemaDiff)
{
foreach ($schemaDiff->getCreatedSequences() as $sequence) {
$this->createSequenceQueries = array_merge(
$this->createSequenceQueries,
$this->platform->getCreateSequenceSQLQueries($sequence)
);
}
foreach ($schemaDiff->getDroppedSequences() as $sequence) {
$this->dropSequenceQueries = array_merge(
$this->dropSequenceQueries,
$this->platform->getDropSequenceSQLQueries($sequence)
);
}
} | php | private function collectSequences(SchemaDiff $schemaDiff)
{
foreach ($schemaDiff->getCreatedSequences() as $sequence) {
$this->createSequenceQueries = array_merge(
$this->createSequenceQueries,
$this->platform->getCreateSequenceSQLQueries($sequence)
);
}
foreach ($schemaDiff->getDroppedSequences() as $sequence) {
$this->dropSequenceQueries = array_merge(
$this->dropSequenceQueries,
$this->platform->getDropSequenceSQLQueries($sequence)
);
}
} | [
"private",
"function",
"collectSequences",
"(",
"SchemaDiff",
"$",
"schemaDiff",
")",
"{",
"foreach",
"(",
"$",
"schemaDiff",
"->",
"getCreatedSequences",
"(",
")",
"as",
"$",
"sequence",
")",
"{",
"$",
"this",
"->",
"createSequenceQueries",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"createSequenceQueries",
",",
"$",
"this",
"->",
"platform",
"->",
"getCreateSequenceSQLQueries",
"(",
"$",
"sequence",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"schemaDiff",
"->",
"getDroppedSequences",
"(",
")",
"as",
"$",
"sequence",
")",
"{",
"$",
"this",
"->",
"dropSequenceQueries",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"dropSequenceQueries",
",",
"$",
"this",
"->",
"platform",
"->",
"getDropSequenceSQLQueries",
"(",
"$",
"sequence",
")",
")",
";",
"}",
"}"
] | Collects queries about sequences to a schema.
@param \Fridge\DBAL\Schema\Diff\SchemaDiff $schemaDiff The schema difference. | [
"Collects",
"queries",
"about",
"sequences",
"to",
"a",
"schema",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/SchemaManager/SQLCollector/AlterSchemaSQLCollector.php#L420-L435 | train |
wpdesk/wp-basic-requirements | src/Basic_Requirement_Checker.php | WPDesk_Basic_Requirement_Checker.is_wp_plugin_active | public static function is_wp_plugin_active( $plugin_file ) {
$active_plugins = (array) get_option( 'active_plugins', array() );
if ( is_multisite() ) {
$active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) );
}
return in_array( $plugin_file, $active_plugins ) || array_key_exists( $plugin_file, $active_plugins );
} | php | public static function is_wp_plugin_active( $plugin_file ) {
$active_plugins = (array) get_option( 'active_plugins', array() );
if ( is_multisite() ) {
$active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) );
}
return in_array( $plugin_file, $active_plugins ) || array_key_exists( $plugin_file, $active_plugins );
} | [
"public",
"static",
"function",
"is_wp_plugin_active",
"(",
"$",
"plugin_file",
")",
"{",
"$",
"active_plugins",
"=",
"(",
"array",
")",
"get_option",
"(",
"'active_plugins'",
",",
"array",
"(",
")",
")",
";",
"if",
"(",
"is_multisite",
"(",
")",
")",
"{",
"$",
"active_plugins",
"=",
"array_merge",
"(",
"$",
"active_plugins",
",",
"get_site_option",
"(",
"'active_sitewide_plugins'",
",",
"array",
"(",
")",
")",
")",
";",
"}",
"return",
"in_array",
"(",
"$",
"plugin_file",
",",
"$",
"active_plugins",
")",
"||",
"array_key_exists",
"(",
"$",
"plugin_file",
",",
"$",
"active_plugins",
")",
";",
"}"
] | Checks if plugin is active. Needs to be enabled in deferred way.
@param string $plugin_file
@return bool | [
"Checks",
"if",
"plugin",
"is",
"active",
".",
"Needs",
"to",
"be",
"enabled",
"in",
"deferred",
"way",
"."
] | 57d76f5acf312f632210db71884f282d8fcf1838 | https://github.com/wpdesk/wp-basic-requirements/blob/57d76f5acf312f632210db71884f282d8fcf1838/src/Basic_Requirement_Checker.php#L279-L287 | train |
thomasez/BisonLabSakonninBundle | Controller/SakonninFileController.php | SakonninFileController.indexAction | public function indexAction($access)
{
$em = $this->getDoctrineManager();
$sf = $this->container->get('sakonnin.files');
// Todo: paging or just show the last 20
$files = $sf->getFilesForLoggedIn();
if ($this->isRest($access)) {
return $this->returnRestData($request, $files, array('html' =>'file:_index.html.twig'));
}
return $this->render('BisonLabSakonninBundle:SakonninFile:index.html.twig',
array('files' => $files));
} | php | public function indexAction($access)
{
$em = $this->getDoctrineManager();
$sf = $this->container->get('sakonnin.files');
// Todo: paging or just show the last 20
$files = $sf->getFilesForLoggedIn();
if ($this->isRest($access)) {
return $this->returnRestData($request, $files, array('html' =>'file:_index.html.twig'));
}
return $this->render('BisonLabSakonninBundle:SakonninFile:index.html.twig',
array('files' => $files));
} | [
"public",
"function",
"indexAction",
"(",
"$",
"access",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrineManager",
"(",
")",
";",
"$",
"sf",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'sakonnin.files'",
")",
";",
"// Todo: paging or just show the last 20",
"$",
"files",
"=",
"$",
"sf",
"->",
"getFilesForLoggedIn",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isRest",
"(",
"$",
"access",
")",
")",
"{",
"return",
"$",
"this",
"->",
"returnRestData",
"(",
"$",
"request",
",",
"$",
"files",
",",
"array",
"(",
"'html'",
"=>",
"'file:_index.html.twig'",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"render",
"(",
"'BisonLabSakonninBundle:SakonninFile:index.html.twig'",
",",
"array",
"(",
"'files'",
"=>",
"$",
"files",
")",
")",
";",
"}"
] | Lists all file entities.
@Route("/", name="file_index", methods={"GET"}) | [
"Lists",
"all",
"file",
"entities",
"."
] | 45ca7ce9874c4a2be7b503d7067b3d11d2b518cb | https://github.com/thomasez/BisonLabSakonninBundle/blob/45ca7ce9874c4a2be7b503d7067b3d11d2b518cb/Controller/SakonninFileController.php#L33-L45 | train |
thomasez/BisonLabSakonninBundle | Controller/SakonninFileController.php | SakonninFileController.newAction | public function newAction(Request $request, $access)
{
$file = new SakonninFile();
$form = $this->createCreateForm($file);
$data = $request->request->all();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$sf = $this->container->get('sakonnin.files');
$sf->storeFile($file, isset($data['file_context']) ? $data['file_context'] : array());
if ($this->isRest($access)) {
return $this->returnRestData($request, "OK Done");
}
return $this->redirectToRoute('file_show', array('id' => $file->getId()));
}
if ($this->isRest($access)) {
# We have a problem, and need to tell our user what it is.
# Better make this a Json some day.
return $this->returnErrorResponse("Validation Error", 400,
$this->handleFormErrors($form));
}
return $this->render('BisonLabSakonninBundle:SakonninFile:new.html.twig',
array('file' => $file, 'form' => $form->createView()
));
} | php | public function newAction(Request $request, $access)
{
$file = new SakonninFile();
$form = $this->createCreateForm($file);
$data = $request->request->all();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$sf = $this->container->get('sakonnin.files');
$sf->storeFile($file, isset($data['file_context']) ? $data['file_context'] : array());
if ($this->isRest($access)) {
return $this->returnRestData($request, "OK Done");
}
return $this->redirectToRoute('file_show', array('id' => $file->getId()));
}
if ($this->isRest($access)) {
# We have a problem, and need to tell our user what it is.
# Better make this a Json some day.
return $this->returnErrorResponse("Validation Error", 400,
$this->handleFormErrors($form));
}
return $this->render('BisonLabSakonninBundle:SakonninFile:new.html.twig',
array('file' => $file, 'form' => $form->createView()
));
} | [
"public",
"function",
"newAction",
"(",
"Request",
"$",
"request",
",",
"$",
"access",
")",
"{",
"$",
"file",
"=",
"new",
"SakonninFile",
"(",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"createCreateForm",
"(",
"$",
"file",
")",
";",
"$",
"data",
"=",
"$",
"request",
"->",
"request",
"->",
"all",
"(",
")",
";",
"$",
"form",
"->",
"handleRequest",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"form",
"->",
"isSubmitted",
"(",
")",
"&&",
"$",
"form",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"sf",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'sakonnin.files'",
")",
";",
"$",
"sf",
"->",
"storeFile",
"(",
"$",
"file",
",",
"isset",
"(",
"$",
"data",
"[",
"'file_context'",
"]",
")",
"?",
"$",
"data",
"[",
"'file_context'",
"]",
":",
"array",
"(",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isRest",
"(",
"$",
"access",
")",
")",
"{",
"return",
"$",
"this",
"->",
"returnRestData",
"(",
"$",
"request",
",",
"\"OK Done\"",
")",
";",
"}",
"return",
"$",
"this",
"->",
"redirectToRoute",
"(",
"'file_show'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"file",
"->",
"getId",
"(",
")",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isRest",
"(",
"$",
"access",
")",
")",
"{",
"# We have a problem, and need to tell our user what it is.",
"# Better make this a Json some day.",
"return",
"$",
"this",
"->",
"returnErrorResponse",
"(",
"\"Validation Error\"",
",",
"400",
",",
"$",
"this",
"->",
"handleFormErrors",
"(",
"$",
"form",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"render",
"(",
"'BisonLabSakonninBundle:SakonninFile:new.html.twig'",
",",
"array",
"(",
"'file'",
"=>",
"$",
"file",
",",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
")",
")",
";",
"}"
] | Creates a new file entity.
@Route("/new", name="file_new", methods={"GET", "POST"}) | [
"Creates",
"a",
"new",
"file",
"entity",
"."
] | 45ca7ce9874c4a2be7b503d7067b3d11d2b518cb | https://github.com/thomasez/BisonLabSakonninBundle/blob/45ca7ce9874c4a2be7b503d7067b3d11d2b518cb/Controller/SakonninFileController.php#L69-L97 | train |
thomasez/BisonLabSakonninBundle | Controller/SakonninFileController.php | SakonninFileController.showAction | public function showAction(Request $request, SakonninFile $file, $access)
{
$deleteForm = $this->createDeleteForm($file);
return $this->render('BisonLabSakonninBundle:SakonninFile:show.html.twig',
array(
'file' => $file,
'delete_form' => $deleteForm->createView(),
));
} | php | public function showAction(Request $request, SakonninFile $file, $access)
{
$deleteForm = $this->createDeleteForm($file);
return $this->render('BisonLabSakonninBundle:SakonninFile:show.html.twig',
array(
'file' => $file,
'delete_form' => $deleteForm->createView(),
));
} | [
"public",
"function",
"showAction",
"(",
"Request",
"$",
"request",
",",
"SakonninFile",
"$",
"file",
",",
"$",
"access",
")",
"{",
"$",
"deleteForm",
"=",
"$",
"this",
"->",
"createDeleteForm",
"(",
"$",
"file",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'BisonLabSakonninBundle:SakonninFile:show.html.twig'",
",",
"array",
"(",
"'file'",
"=>",
"$",
"file",
",",
"'delete_form'",
"=>",
"$",
"deleteForm",
"->",
"createView",
"(",
")",
",",
")",
")",
";",
"}"
] | Finds and displays a file entity.
@Route("/{id}", name="file_show", methods={"GET"}) | [
"Finds",
"and",
"displays",
"a",
"file",
"entity",
"."
] | 45ca7ce9874c4a2be7b503d7067b3d11d2b518cb | https://github.com/thomasez/BisonLabSakonninBundle/blob/45ca7ce9874c4a2be7b503d7067b3d11d2b518cb/Controller/SakonninFileController.php#L104-L113 | train |
thomasez/BisonLabSakonninBundle | Controller/SakonninFileController.php | SakonninFileController.viewAction | public function viewAction(Request $request, SakonninFile $file, $access)
{
// TODO: Add access control.
$path = $this->getFilePath();
$response = new BinaryFileResponse($path . "/" . $file->getStoredAs());
return $response;
} | php | public function viewAction(Request $request, SakonninFile $file, $access)
{
// TODO: Add access control.
$path = $this->getFilePath();
$response = new BinaryFileResponse($path . "/" . $file->getStoredAs());
return $response;
} | [
"public",
"function",
"viewAction",
"(",
"Request",
"$",
"request",
",",
"SakonninFile",
"$",
"file",
",",
"$",
"access",
")",
"{",
"// TODO: Add access control.",
"$",
"path",
"=",
"$",
"this",
"->",
"getFilePath",
"(",
")",
";",
"$",
"response",
"=",
"new",
"BinaryFileResponse",
"(",
"$",
"path",
".",
"\"/\"",
".",
"$",
"file",
"->",
"getStoredAs",
"(",
")",
")",
";",
"return",
"$",
"response",
";",
"}"
] | View a file.
@Route("/{id}/view", name="file_view", methods={"GET"}) | [
"View",
"a",
"file",
"."
] | 45ca7ce9874c4a2be7b503d7067b3d11d2b518cb | https://github.com/thomasez/BisonLabSakonninBundle/blob/45ca7ce9874c4a2be7b503d7067b3d11d2b518cb/Controller/SakonninFileController.php#L134-L140 | train |
thomasez/BisonLabSakonninBundle | Controller/SakonninFileController.php | SakonninFileController.editAction | public function editAction(Request $request, SakonninFile $file, $access)
{
$deleteForm = $this->createDeleteForm($file);
$editForm = $this->createForm('BisonLab\SakonninBundle\Form\SakonninFileType', $file);
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) {
$this->getDoctrineManager()->flush();
return $this->redirectToRoute('file_edit', array('id' => $file->getId()));
}
return $this->render('BisonLabSakonninBundle:SakonninFile:edit.html.twig',
array(
'file' => $file,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
} | php | public function editAction(Request $request, SakonninFile $file, $access)
{
$deleteForm = $this->createDeleteForm($file);
$editForm = $this->createForm('BisonLab\SakonninBundle\Form\SakonninFileType', $file);
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) {
$this->getDoctrineManager()->flush();
return $this->redirectToRoute('file_edit', array('id' => $file->getId()));
}
return $this->render('BisonLabSakonninBundle:SakonninFile:edit.html.twig',
array(
'file' => $file,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
} | [
"public",
"function",
"editAction",
"(",
"Request",
"$",
"request",
",",
"SakonninFile",
"$",
"file",
",",
"$",
"access",
")",
"{",
"$",
"deleteForm",
"=",
"$",
"this",
"->",
"createDeleteForm",
"(",
"$",
"file",
")",
";",
"$",
"editForm",
"=",
"$",
"this",
"->",
"createForm",
"(",
"'BisonLab\\SakonninBundle\\Form\\SakonninFileType'",
",",
"$",
"file",
")",
";",
"$",
"editForm",
"->",
"handleRequest",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"editForm",
"->",
"isSubmitted",
"(",
")",
"&&",
"$",
"editForm",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"this",
"->",
"getDoctrineManager",
"(",
")",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"this",
"->",
"redirectToRoute",
"(",
"'file_edit'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"file",
"->",
"getId",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"render",
"(",
"'BisonLabSakonninBundle:SakonninFile:edit.html.twig'",
",",
"array",
"(",
"'file'",
"=>",
"$",
"file",
",",
"'edit_form'",
"=>",
"$",
"editForm",
"->",
"createView",
"(",
")",
",",
"'delete_form'",
"=>",
"$",
"deleteForm",
"->",
"createView",
"(",
")",
",",
")",
")",
";",
"}"
] | Displays a form to edit an existing file entity.
@Route("/{id}/edit", name="file_edit", methods={"GET", "POST"}) | [
"Displays",
"a",
"form",
"to",
"edit",
"an",
"existing",
"file",
"entity",
"."
] | 45ca7ce9874c4a2be7b503d7067b3d11d2b518cb | https://github.com/thomasez/BisonLabSakonninBundle/blob/45ca7ce9874c4a2be7b503d7067b3d11d2b518cb/Controller/SakonninFileController.php#L171-L189 | train |
thomasez/BisonLabSakonninBundle | Controller/SakonninFileController.php | SakonninFileController.deleteAction | public function deleteAction(Request $request, SakonninFile $file, $access)
{
$form = $this->createDeleteForm($file);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrineManager();
$em->remove($file);
$em->flush();
if ($back = $request->request->get('back'))
return $this->redirect($back);
}
return $this->redirectToRoute('file_index');
} | php | public function deleteAction(Request $request, SakonninFile $file, $access)
{
$form = $this->createDeleteForm($file);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrineManager();
$em->remove($file);
$em->flush();
if ($back = $request->request->get('back'))
return $this->redirect($back);
}
return $this->redirectToRoute('file_index');
} | [
"public",
"function",
"deleteAction",
"(",
"Request",
"$",
"request",
",",
"SakonninFile",
"$",
"file",
",",
"$",
"access",
")",
"{",
"$",
"form",
"=",
"$",
"this",
"->",
"createDeleteForm",
"(",
"$",
"file",
")",
";",
"$",
"form",
"->",
"handleRequest",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"form",
"->",
"isSubmitted",
"(",
")",
"&&",
"$",
"form",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrineManager",
"(",
")",
";",
"$",
"em",
"->",
"remove",
"(",
"$",
"file",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"if",
"(",
"$",
"back",
"=",
"$",
"request",
"->",
"request",
"->",
"get",
"(",
"'back'",
")",
")",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"back",
")",
";",
"}",
"return",
"$",
"this",
"->",
"redirectToRoute",
"(",
"'file_index'",
")",
";",
"}"
] | Deletes a file entity.
@Route("/{id}", name="file_delete", methods={"DELETE"}) | [
"Deletes",
"a",
"file",
"entity",
"."
] | 45ca7ce9874c4a2be7b503d7067b3d11d2b518cb | https://github.com/thomasez/BisonLabSakonninBundle/blob/45ca7ce9874c4a2be7b503d7067b3d11d2b518cb/Controller/SakonninFileController.php#L196-L210 | train |
thomasez/BisonLabSakonninBundle | Controller/SakonninFileController.php | SakonninFileController.createDeleteForm | public function createDeleteForm(SakonninFile $file)
{
return $this->createFormBuilder()
->setAction($this->generateUrl('file_delete', array('id' => $file->getId())))
->setMethod('DELETE')
->getForm()
;
} | php | public function createDeleteForm(SakonninFile $file)
{
return $this->createFormBuilder()
->setAction($this->generateUrl('file_delete', array('id' => $file->getId())))
->setMethod('DELETE')
->getForm()
;
} | [
"public",
"function",
"createDeleteForm",
"(",
"SakonninFile",
"$",
"file",
")",
"{",
"return",
"$",
"this",
"->",
"createFormBuilder",
"(",
")",
"->",
"setAction",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'file_delete'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"file",
"->",
"getId",
"(",
")",
")",
")",
")",
"->",
"setMethod",
"(",
"'DELETE'",
")",
"->",
"getForm",
"(",
")",
";",
"}"
] | Creates a form to delete a file entity.
@param SakonninFile $file The file entity
@return \Symfony\Component\Form\Form The form | [
"Creates",
"a",
"form",
"to",
"delete",
"a",
"file",
"entity",
"."
] | 45ca7ce9874c4a2be7b503d7067b3d11d2b518cb | https://github.com/thomasez/BisonLabSakonninBundle/blob/45ca7ce9874c4a2be7b503d7067b3d11d2b518cb/Controller/SakonninFileController.php#L241-L248 | train |
kaiohken1982/NeobazaarMailerModule | src/Mailer/Module.php | Module.onBootstrap | public function onBootstrap(EventInterface $e)
{
/* @var $application \Zend\Mvc\Application */
$application = $e->getTarget();
$serviceManager = $application->getServiceManager();
$eventManager = $application->getEventManager();
$eventManager->attachAggregate($serviceManager->get('Mailer\Mvc\PasswordRecoveryListener'));
$eventManager->attachAggregate($serviceManager->get('Mailer\Mvc\PasswordRecoveredListener'));
$eventManager->attachAggregate($serviceManager->get('Mailer\Mvc\UserRegistrationListener'));
$eventManager->attachAggregate($serviceManager->get('Mailer\Mvc\UserActivationListener'));
$eventManager->attachAggregate($serviceManager->get('Mailer\Mvc\UserContactListener'));
$eventManager->attachAggregate($serviceManager->get('Mailer\Mvc\ClassifiedAnswerListener'));
$eventManager->attachAggregate($serviceManager->get('Mailer\Mvc\ClassifiedCreatedListener'));
$eventManager->attachAggregate($serviceManager->get('Mailer\Mvc\ClassifiedActivatedListener'));
$eventManager->attachAggregate($serviceManager->get('Mailer\Mvc\ClassifiedExpiredListener'));
} | php | public function onBootstrap(EventInterface $e)
{
/* @var $application \Zend\Mvc\Application */
$application = $e->getTarget();
$serviceManager = $application->getServiceManager();
$eventManager = $application->getEventManager();
$eventManager->attachAggregate($serviceManager->get('Mailer\Mvc\PasswordRecoveryListener'));
$eventManager->attachAggregate($serviceManager->get('Mailer\Mvc\PasswordRecoveredListener'));
$eventManager->attachAggregate($serviceManager->get('Mailer\Mvc\UserRegistrationListener'));
$eventManager->attachAggregate($serviceManager->get('Mailer\Mvc\UserActivationListener'));
$eventManager->attachAggregate($serviceManager->get('Mailer\Mvc\UserContactListener'));
$eventManager->attachAggregate($serviceManager->get('Mailer\Mvc\ClassifiedAnswerListener'));
$eventManager->attachAggregate($serviceManager->get('Mailer\Mvc\ClassifiedCreatedListener'));
$eventManager->attachAggregate($serviceManager->get('Mailer\Mvc\ClassifiedActivatedListener'));
$eventManager->attachAggregate($serviceManager->get('Mailer\Mvc\ClassifiedExpiredListener'));
} | [
"public",
"function",
"onBootstrap",
"(",
"EventInterface",
"$",
"e",
")",
"{",
"/* @var $application \\Zend\\Mvc\\Application */",
"$",
"application",
"=",
"$",
"e",
"->",
"getTarget",
"(",
")",
";",
"$",
"serviceManager",
"=",
"$",
"application",
"->",
"getServiceManager",
"(",
")",
";",
"$",
"eventManager",
"=",
"$",
"application",
"->",
"getEventManager",
"(",
")",
";",
"$",
"eventManager",
"->",
"attachAggregate",
"(",
"$",
"serviceManager",
"->",
"get",
"(",
"'Mailer\\Mvc\\PasswordRecoveryListener'",
")",
")",
";",
"$",
"eventManager",
"->",
"attachAggregate",
"(",
"$",
"serviceManager",
"->",
"get",
"(",
"'Mailer\\Mvc\\PasswordRecoveredListener'",
")",
")",
";",
"$",
"eventManager",
"->",
"attachAggregate",
"(",
"$",
"serviceManager",
"->",
"get",
"(",
"'Mailer\\Mvc\\UserRegistrationListener'",
")",
")",
";",
"$",
"eventManager",
"->",
"attachAggregate",
"(",
"$",
"serviceManager",
"->",
"get",
"(",
"'Mailer\\Mvc\\UserActivationListener'",
")",
")",
";",
"$",
"eventManager",
"->",
"attachAggregate",
"(",
"$",
"serviceManager",
"->",
"get",
"(",
"'Mailer\\Mvc\\UserContactListener'",
")",
")",
";",
"$",
"eventManager",
"->",
"attachAggregate",
"(",
"$",
"serviceManager",
"->",
"get",
"(",
"'Mailer\\Mvc\\ClassifiedAnswerListener'",
")",
")",
";",
"$",
"eventManager",
"->",
"attachAggregate",
"(",
"$",
"serviceManager",
"->",
"get",
"(",
"'Mailer\\Mvc\\ClassifiedCreatedListener'",
")",
")",
";",
"$",
"eventManager",
"->",
"attachAggregate",
"(",
"$",
"serviceManager",
"->",
"get",
"(",
"'Mailer\\Mvc\\ClassifiedActivatedListener'",
")",
")",
";",
"$",
"eventManager",
"->",
"attachAggregate",
"(",
"$",
"serviceManager",
"->",
"get",
"(",
"'Mailer\\Mvc\\ClassifiedExpiredListener'",
")",
")",
";",
"}"
] | Registra delle azioni agli eventi che necesitano di invio email
Per quanto riguarda le risposte sarebbe da realizzare una nuova tabella che
salvi i messaggi inviati, la relativa entità, modello e servizio. | [
"Registra",
"delle",
"azioni",
"agli",
"eventi",
"che",
"necesitano",
"di",
"invio",
"email"
] | 0afc66196a0a392ecb4f052f483f2b5ff606bd8f | https://github.com/kaiohken1982/NeobazaarMailerModule/blob/0afc66196a0a392ecb4f052f483f2b5ff606bd8f/src/Mailer/Module.php#L25-L41 | train |
42Telecom/php-sdk-core | src/Factories/ServiceFactory.php | ServiceFactory.get | public static function get($type)
{
$instance = null;
switch ($type) {
case 'IM/Send':
$instance = new SendService();
break;
case 'IM/Status':
$instance = new StatusService();
break;
case 'TFA/Request':
$instance = new RequestService();
break;
case 'TFA/Validate':
$instance = new ValidateService();
break;
default:
throw new \Exception("Error - Unknow service", 1);
}
return $instance;
} | php | public static function get($type)
{
$instance = null;
switch ($type) {
case 'IM/Send':
$instance = new SendService();
break;
case 'IM/Status':
$instance = new StatusService();
break;
case 'TFA/Request':
$instance = new RequestService();
break;
case 'TFA/Validate':
$instance = new ValidateService();
break;
default:
throw new \Exception("Error - Unknow service", 1);
}
return $instance;
} | [
"public",
"static",
"function",
"get",
"(",
"$",
"type",
")",
"{",
"$",
"instance",
"=",
"null",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'IM/Send'",
":",
"$",
"instance",
"=",
"new",
"SendService",
"(",
")",
";",
"break",
";",
"case",
"'IM/Status'",
":",
"$",
"instance",
"=",
"new",
"StatusService",
"(",
")",
";",
"break",
";",
"case",
"'TFA/Request'",
":",
"$",
"instance",
"=",
"new",
"RequestService",
"(",
")",
";",
"break",
";",
"case",
"'TFA/Validate'",
":",
"$",
"instance",
"=",
"new",
"ValidateService",
"(",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Error - Unknow service\"",
",",
"1",
")",
";",
"}",
"return",
"$",
"instance",
";",
"}"
] | Get instance of the specified service.
@param string $type type of service to call.
@return object Instance of the service. | [
"Get",
"instance",
"of",
"the",
"specified",
"service",
"."
] | 41d3cbebe01a93220318a250e08c50a6b69b1594 | https://github.com/42Telecom/php-sdk-core/blob/41d3cbebe01a93220318a250e08c50a6b69b1594/src/Factories/ServiceFactory.php#L22-L49 | train |
linguisticteam/json-ld | src/Generators/json_ld.php | JSON_LD_Maker.make | public function make( $type )
{
$type = __NAMESPACE__ . "\\" . $type;
if (class_exists( $type )) {
/**
* @var \Lti\Seo\Generators\Thing $object
*/
$object = new $type( $this->helper );
$result = $object->format();
if (is_array( $result ) && ! empty( $result )) {
return json_encode( array_merge( array( '@context' => 'http://schema.org' ), $result ) );
}
}
return null;
} | php | public function make( $type )
{
$type = __NAMESPACE__ . "\\" . $type;
if (class_exists( $type )) {
/**
* @var \Lti\Seo\Generators\Thing $object
*/
$object = new $type( $this->helper );
$result = $object->format();
if (is_array( $result ) && ! empty( $result )) {
return json_encode( array_merge( array( '@context' => 'http://schema.org' ), $result ) );
}
}
return null;
} | [
"public",
"function",
"make",
"(",
"$",
"type",
")",
"{",
"$",
"type",
"=",
"__NAMESPACE__",
".",
"\"\\\\\"",
".",
"$",
"type",
";",
"if",
"(",
"class_exists",
"(",
"$",
"type",
")",
")",
"{",
"/**\n * @var \\Lti\\Seo\\Generators\\Thing $object\n */",
"$",
"object",
"=",
"new",
"$",
"type",
"(",
"$",
"this",
"->",
"helper",
")",
";",
"$",
"result",
"=",
"$",
"object",
"->",
"format",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"result",
")",
"&&",
"!",
"empty",
"(",
"$",
"result",
")",
")",
"{",
"return",
"json_encode",
"(",
"array_merge",
"(",
"array",
"(",
"'@context'",
"=>",
"'http://schema.org'",
")",
",",
"$",
"result",
")",
")",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Our schema.org object factory
Makes a new object provided it can find the class
@param string $type The type of object to create
@return null|string json encoded json-ld string, ready for output | [
"Our",
"schema",
".",
"org",
"object",
"factory"
] | 354fd518aff5fa52635f435888056fe0bd926566 | https://github.com/linguisticteam/json-ld/blob/354fd518aff5fa52635f435888056fe0bd926566/src/Generators/json_ld.php#L85-L100 | train |
Xsaven/laravel-intelect-admin | src/Auth/Database/Permission.php | Permission.shouldPassThrough | public function shouldPassThrough(Request $request) : bool
{
if (empty($this->http_method) && empty($this->http_path)) {
return true;
}
$method = $this->http_method;
$matches = array_map(function ($path) use ($method) {
$path = trim(config('lia.route.prefix'), '/').$path;
if (Str::contains($path, ':')) {
list($method, $path) = explode(':', $path);
$method = explode(',', $method);
}
return compact('method', 'path');
}, explode("\r\n", $this->http_path));
foreach ($matches as $match) {
if ($this->matchRequest($match, $request)) {
return true;
}
}
return false;
} | php | public function shouldPassThrough(Request $request) : bool
{
if (empty($this->http_method) && empty($this->http_path)) {
return true;
}
$method = $this->http_method;
$matches = array_map(function ($path) use ($method) {
$path = trim(config('lia.route.prefix'), '/').$path;
if (Str::contains($path, ':')) {
list($method, $path) = explode(':', $path);
$method = explode(',', $method);
}
return compact('method', 'path');
}, explode("\r\n", $this->http_path));
foreach ($matches as $match) {
if ($this->matchRequest($match, $request)) {
return true;
}
}
return false;
} | [
"public",
"function",
"shouldPassThrough",
"(",
"Request",
"$",
"request",
")",
":",
"bool",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"http_method",
")",
"&&",
"empty",
"(",
"$",
"this",
"->",
"http_path",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"method",
"=",
"$",
"this",
"->",
"http_method",
";",
"$",
"matches",
"=",
"array_map",
"(",
"function",
"(",
"$",
"path",
")",
"use",
"(",
"$",
"method",
")",
"{",
"$",
"path",
"=",
"trim",
"(",
"config",
"(",
"'lia.route.prefix'",
")",
",",
"'/'",
")",
".",
"$",
"path",
";",
"if",
"(",
"Str",
"::",
"contains",
"(",
"$",
"path",
",",
"':'",
")",
")",
"{",
"list",
"(",
"$",
"method",
",",
"$",
"path",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"path",
")",
";",
"$",
"method",
"=",
"explode",
"(",
"','",
",",
"$",
"method",
")",
";",
"}",
"return",
"compact",
"(",
"'method'",
",",
"'path'",
")",
";",
"}",
",",
"explode",
"(",
"\"\\r\\n\"",
",",
"$",
"this",
"->",
"http_path",
")",
")",
";",
"foreach",
"(",
"$",
"matches",
"as",
"$",
"match",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"matchRequest",
"(",
"$",
"match",
",",
"$",
"request",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | If request should pass through the current permission.
@param Request $request
@return bool | [
"If",
"request",
"should",
"pass",
"through",
"the",
"current",
"permission",
"."
] | 592574633d12c74cf25b43dd6694fee496abefcb | https://github.com/Xsaven/laravel-intelect-admin/blob/592574633d12c74cf25b43dd6694fee496abefcb/src/Auth/Database/Permission.php#L61-L87 | train |
BenGorFile/DoctrineORMBridge | src/BenGorFile/DoctrineORMBridge/Infrastructure/Persistence/EntityManagerFactory.php | EntityManagerFactory.build | public function build($aConnection, $isDevMode = true)
{
Type::addType('file_id', FileIdType::class);
return EntityManager::create(
$aConnection,
Setup::createYAMLMetadataConfiguration([__DIR__ . '/Mapping'], $isDevMode)
);
} | php | public function build($aConnection, $isDevMode = true)
{
Type::addType('file_id', FileIdType::class);
return EntityManager::create(
$aConnection,
Setup::createYAMLMetadataConfiguration([__DIR__ . '/Mapping'], $isDevMode)
);
} | [
"public",
"function",
"build",
"(",
"$",
"aConnection",
",",
"$",
"isDevMode",
"=",
"true",
")",
"{",
"Type",
"::",
"addType",
"(",
"'file_id'",
",",
"FileIdType",
"::",
"class",
")",
";",
"return",
"EntityManager",
"::",
"create",
"(",
"$",
"aConnection",
",",
"Setup",
"::",
"createYAMLMetadataConfiguration",
"(",
"[",
"__DIR__",
".",
"'/Mapping'",
"]",
",",
"$",
"isDevMode",
")",
")",
";",
"}"
] | Decorates the doctrine entity manager
with library's mappings and custom types.
@param mixed $aConnection Connection parameters as db driver
@param bool $isDevMode Enables the dev mode, by default is enabled
@return EntityManager | [
"Decorates",
"the",
"doctrine",
"entity",
"manager",
"with",
"library",
"s",
"mappings",
"and",
"custom",
"types",
"."
] | c632521914d20c1bb7e837db7a3bcacbdebeeb7e | https://github.com/BenGorFile/DoctrineORMBridge/blob/c632521914d20c1bb7e837db7a3bcacbdebeeb7e/src/BenGorFile/DoctrineORMBridge/Infrastructure/Persistence/EntityManagerFactory.php#L36-L44 | train |
miaoxing/plugin | src/Service/V.php | V.message | public function message($ruleOrMessage, $message = null)
{
if (1 === func_num_args()) {
$rule = $this->lastRule;
$message = $ruleOrMessage;
} else {
$rule = $ruleOrMessage;
}
$this->options['messages'][$this->lastKey][$rule] = $message;
return $this;
} | php | public function message($ruleOrMessage, $message = null)
{
if (1 === func_num_args()) {
$rule = $this->lastRule;
$message = $ruleOrMessage;
} else {
$rule = $ruleOrMessage;
}
$this->options['messages'][$this->lastKey][$rule] = $message;
return $this;
} | [
"public",
"function",
"message",
"(",
"$",
"ruleOrMessage",
",",
"$",
"message",
"=",
"null",
")",
"{",
"if",
"(",
"1",
"===",
"func_num_args",
"(",
")",
")",
"{",
"$",
"rule",
"=",
"$",
"this",
"->",
"lastRule",
";",
"$",
"message",
"=",
"$",
"ruleOrMessage",
";",
"}",
"else",
"{",
"$",
"rule",
"=",
"$",
"ruleOrMessage",
";",
"}",
"$",
"this",
"->",
"options",
"[",
"'messages'",
"]",
"[",
"$",
"this",
"->",
"lastKey",
"]",
"[",
"$",
"rule",
"]",
"=",
"$",
"message",
";",
"return",
"$",
"this",
";",
"}"
] | Set rule message for current field
@param string $ruleOrMessage
@param string|null $message
@return $this | [
"Set",
"rule",
"message",
"for",
"current",
"field"
] | f287a1e6c97abba6f06906255b8c26e8ab0afe61 | https://github.com/miaoxing/plugin/blob/f287a1e6c97abba6f06906255b8c26e8ab0afe61/src/Service/V.php#L247-L259 | train |
miaoxing/plugin | src/Service/V.php | V.check | public function check($data = null)
{
$validator = $this->getValidator($data);
if ($validator->isValid()) {
return $this->suc();
} else {
return $this->err($validator->getFirstMessage());
}
} | php | public function check($data = null)
{
$validator = $this->getValidator($data);
if ($validator->isValid()) {
return $this->suc();
} else {
return $this->err($validator->getFirstMessage());
}
} | [
"public",
"function",
"check",
"(",
"$",
"data",
"=",
"null",
")",
"{",
"$",
"validator",
"=",
"$",
"this",
"->",
"getValidator",
"(",
"$",
"data",
")",
";",
"if",
"(",
"$",
"validator",
"->",
"isValid",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"suc",
"(",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"err",
"(",
"$",
"validator",
"->",
"getFirstMessage",
"(",
")",
")",
";",
"}",
"}"
] | Validate the data and return the ret array
@param mixed $data
@return array | [
"Validate",
"the",
"data",
"and",
"return",
"the",
"ret",
"array"
] | f287a1e6c97abba6f06906255b8c26e8ab0afe61 | https://github.com/miaoxing/plugin/blob/f287a1e6c97abba6f06906255b8c26e8ab0afe61/src/Service/V.php#L289-L298 | train |
miaoxing/plugin | src/Service/V.php | V.data | public function data($data)
{
if (!$data) {
return $this;
}
// Validate without key
if (!$this->lastKey) {
$data = ['' => $data];
}
$this->options['data'] = $data;
return $this;
} | php | public function data($data)
{
if (!$data) {
return $this;
}
// Validate without key
if (!$this->lastKey) {
$data = ['' => $data];
}
$this->options['data'] = $data;
return $this;
} | [
"public",
"function",
"data",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"$",
"data",
")",
"{",
"return",
"$",
"this",
";",
"}",
"// Validate without key",
"if",
"(",
"!",
"$",
"this",
"->",
"lastKey",
")",
"{",
"$",
"data",
"=",
"[",
"''",
"=>",
"$",
"data",
"]",
";",
"}",
"$",
"this",
"->",
"options",
"[",
"'data'",
"]",
"=",
"$",
"data",
";",
"return",
"$",
"this",
";",
"}"
] | Set data for validation
@param mixed $data
@return $this | [
"Set",
"data",
"for",
"validation"
] | f287a1e6c97abba6f06906255b8c26e8ab0afe61 | https://github.com/miaoxing/plugin/blob/f287a1e6c97abba6f06906255b8c26e8ab0afe61/src/Service/V.php#L317-L331 | train |
miaoxing/plugin | src/Service/V.php | V.getValidator | protected function getValidator($data = null)
{
if (!$this->validator) {
if ($data) {
// Validate without key
if ($this->lastKey === '') {
$data = ['' => $data];
}
$this->options['data'] = $data;
}
$this->validator = $this->wei->validate($this->options);
}
return $this->validator;
} | php | protected function getValidator($data = null)
{
if (!$this->validator) {
if ($data) {
// Validate without key
if ($this->lastKey === '') {
$data = ['' => $data];
}
$this->options['data'] = $data;
}
$this->validator = $this->wei->validate($this->options);
}
return $this->validator;
} | [
"protected",
"function",
"getValidator",
"(",
"$",
"data",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"validator",
")",
"{",
"if",
"(",
"$",
"data",
")",
"{",
"// Validate without key",
"if",
"(",
"$",
"this",
"->",
"lastKey",
"===",
"''",
")",
"{",
"$",
"data",
"=",
"[",
"''",
"=>",
"$",
"data",
"]",
";",
"}",
"$",
"this",
"->",
"options",
"[",
"'data'",
"]",
"=",
"$",
"data",
";",
"}",
"$",
"this",
"->",
"validator",
"=",
"$",
"this",
"->",
"wei",
"->",
"validate",
"(",
"$",
"this",
"->",
"options",
")",
";",
"}",
"return",
"$",
"this",
"->",
"validator",
";",
"}"
] | Instance validate object
@param mixed $data
@return Validate | [
"Instance",
"validate",
"object"
] | f287a1e6c97abba6f06906255b8c26e8ab0afe61 | https://github.com/miaoxing/plugin/blob/f287a1e6c97abba6f06906255b8c26e8ab0afe61/src/Service/V.php#L339-L355 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.