repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
KDF5000/EasyThink | src/ThinkPHP/Library/Behavior/FireShowPageTraceBehavior.php | FirePHP.getRequestHeader | protected function getRequestHeader($Name)
{
$headers = self::getAllRequestHeaders();
if (isset($headers[strtolower($Name)])) {
return $headers[strtolower($Name)];
}
return false;
} | php | protected function getRequestHeader($Name)
{
$headers = self::getAllRequestHeaders();
if (isset($headers[strtolower($Name)])) {
return $headers[strtolower($Name)];
}
return false;
} | [
"protected",
"function",
"getRequestHeader",
"(",
"$",
"Name",
")",
"{",
"$",
"headers",
"=",
"self",
"::",
"getAllRequestHeaders",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"headers",
"[",
"strtolower",
"(",
"$",
"Name",
")",
"]",
")",
")",
"{",
"return",
"$",
"headers",
"[",
"strtolower",
"(",
"$",
"Name",
")",
"]",
";",
"}",
"return",
"false",
";",
"}"
] | Get a request header
@return string|false | [
"Get",
"a",
"request",
"header"
] | 86efc9c8a0d504e01e2fea55868227fdc8928841 | https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Behavior/FireShowPageTraceBehavior.php#L1456-L1463 | train |
KDF5000/EasyThink | src/ThinkPHP/Library/Behavior/FireShowPageTraceBehavior.php | FirePHP.jsonEncode | public function jsonEncode($Object, $skipObjectEncode = false)
{
if (!$skipObjectEncode) {
$Object = $this->encodeObject($Object);
}
if (function_exists('json_encode')
&& $this->options['useNativeJsonEncode']!=false) {
return json_encode($Object);
} else {
return $this->json_encode($Object);
}
} | php | public function jsonEncode($Object, $skipObjectEncode = false)
{
if (!$skipObjectEncode) {
$Object = $this->encodeObject($Object);
}
if (function_exists('json_encode')
&& $this->options['useNativeJsonEncode']!=false) {
return json_encode($Object);
} else {
return $this->json_encode($Object);
}
} | [
"public",
"function",
"jsonEncode",
"(",
"$",
"Object",
",",
"$",
"skipObjectEncode",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"skipObjectEncode",
")",
"{",
"$",
"Object",
"=",
"$",
"this",
"->",
"encodeObject",
"(",
"$",
"Object",
")",
";",
"}",
"if",
"(",
"function_exists",
"(",
"'json_encode'",
")",
"&&",
"$",
"this",
"->",
"options",
"[",
"'useNativeJsonEncode'",
"]",
"!=",
"false",
")",
"{",
"return",
"json_encode",
"(",
"$",
"Object",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"json_encode",
"(",
"$",
"Object",
")",
";",
"}",
"}"
] | Encode an object into a JSON string
Uses PHP's jeson_encode() if available
@param object $Object The object to be encoded
@return string The JSON string | [
"Encode",
"an",
"object",
"into",
"a",
"JSON",
"string"
] | 86efc9c8a0d504e01e2fea55868227fdc8928841 | https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Behavior/FireShowPageTraceBehavior.php#L1484-L1497 | train |
geniv/nette-identity-authorizator | src/Drivers/DibiDriver.php | DibiDriver.saveRole | public function saveRole(array $values): int
{
$result = $this->generalSave($values, $this->tableRole);
$this->cache->clean([Cache::TAGS => ['DibiDriver']]);
return $result;
} | php | public function saveRole(array $values): int
{
$result = $this->generalSave($values, $this->tableRole);
$this->cache->clean([Cache::TAGS => ['DibiDriver']]);
return $result;
} | [
"public",
"function",
"saveRole",
"(",
"array",
"$",
"values",
")",
":",
"int",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"generalSave",
"(",
"$",
"values",
",",
"$",
"this",
"->",
"tableRole",
")",
";",
"$",
"this",
"->",
"cache",
"->",
"clean",
"(",
"[",
"Cache",
"::",
"TAGS",
"=>",
"[",
"'DibiDriver'",
"]",
"]",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Save role.
@param array $values
@return int
@throws UniqueConstraintViolationException
@throws \Dibi\Exception | [
"Save",
"role",
"."
] | f7db1cd589d022b6443f24a59432098a343d4639 | https://github.com/geniv/nette-identity-authorizator/blob/f7db1cd589d022b6443f24a59432098a343d4639/src/Drivers/DibiDriver.php#L186-L191 | train |
geniv/nette-identity-authorizator | src/Drivers/DibiDriver.php | DibiDriver.saveResource | public function saveResource(array $values): int
{
$result = $this->generalSave($values, $this->tableResource);
$this->cache->clean([Cache::TAGS => ['DibiDriver']]);
return $result;
} | php | public function saveResource(array $values): int
{
$result = $this->generalSave($values, $this->tableResource);
$this->cache->clean([Cache::TAGS => ['DibiDriver']]);
return $result;
} | [
"public",
"function",
"saveResource",
"(",
"array",
"$",
"values",
")",
":",
"int",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"generalSave",
"(",
"$",
"values",
",",
"$",
"this",
"->",
"tableResource",
")",
";",
"$",
"this",
"->",
"cache",
"->",
"clean",
"(",
"[",
"Cache",
"::",
"TAGS",
"=>",
"[",
"'DibiDriver'",
"]",
"]",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Save resource.
@param array $values
@return int
@throws UniqueConstraintViolationException
@throws \Dibi\Exception | [
"Save",
"resource",
"."
] | f7db1cd589d022b6443f24a59432098a343d4639 | https://github.com/geniv/nette-identity-authorizator/blob/f7db1cd589d022b6443f24a59432098a343d4639/src/Drivers/DibiDriver.php#L202-L207 | train |
geniv/nette-identity-authorizator | src/Drivers/DibiDriver.php | DibiDriver.savePrivilege | public function savePrivilege(array $values): int
{
$result = $this->generalSave($values, $this->tablePrivilege);
$this->cache->clean([Cache::TAGS => ['DibiDriver']]);
return $result;
} | php | public function savePrivilege(array $values): int
{
$result = $this->generalSave($values, $this->tablePrivilege);
$this->cache->clean([Cache::TAGS => ['DibiDriver']]);
return $result;
} | [
"public",
"function",
"savePrivilege",
"(",
"array",
"$",
"values",
")",
":",
"int",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"generalSave",
"(",
"$",
"values",
",",
"$",
"this",
"->",
"tablePrivilege",
")",
";",
"$",
"this",
"->",
"cache",
"->",
"clean",
"(",
"[",
"Cache",
"::",
"TAGS",
"=>",
"[",
"'DibiDriver'",
"]",
"]",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Save privilege.
@param array $values
@return int
@throws UniqueConstraintViolationException
@throws \Dibi\Exception | [
"Save",
"privilege",
"."
] | f7db1cd589d022b6443f24a59432098a343d4639 | https://github.com/geniv/nette-identity-authorizator/blob/f7db1cd589d022b6443f24a59432098a343d4639/src/Drivers/DibiDriver.php#L218-L223 | train |
porkchopsandwiches/doctrine-utilities | lib/src/PorkChopSandwiches/Doctrine/Utilities/DB.php | DB.buildInQueryBindings | public function buildInQueryBindings ($values, $prefix = "in_", &$bound_parameters = array()) {
$sql = "()";
if (is_array($values) && count($values) > 0) {
$sql = array();
$values = array_values($values);
foreach ($values as $index => $value) {
$label_name = $prefix . "_" . $index;
$sql[] = ":" . $label_name;
$bound_parameters[$label_name] = $value;
}
$sql = "(" . implode(", ", $sql) . ")";
}
return $sql;
} | php | public function buildInQueryBindings ($values, $prefix = "in_", &$bound_parameters = array()) {
$sql = "()";
if (is_array($values) && count($values) > 0) {
$sql = array();
$values = array_values($values);
foreach ($values as $index => $value) {
$label_name = $prefix . "_" . $index;
$sql[] = ":" . $label_name;
$bound_parameters[$label_name] = $value;
}
$sql = "(" . implode(", ", $sql) . ")";
}
return $sql;
} | [
"public",
"function",
"buildInQueryBindings",
"(",
"$",
"values",
",",
"$",
"prefix",
"=",
"\"in_\"",
",",
"&",
"$",
"bound_parameters",
"=",
"array",
"(",
")",
")",
"{",
"$",
"sql",
"=",
"\"()\"",
";",
"if",
"(",
"is_array",
"(",
"$",
"values",
")",
"&&",
"count",
"(",
"$",
"values",
")",
">",
"0",
")",
"{",
"$",
"sql",
"=",
"array",
"(",
")",
";",
"$",
"values",
"=",
"array_values",
"(",
"$",
"values",
")",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"index",
"=>",
"$",
"value",
")",
"{",
"$",
"label_name",
"=",
"$",
"prefix",
".",
"\"_\"",
".",
"$",
"index",
";",
"$",
"sql",
"[",
"]",
"=",
"\":\"",
".",
"$",
"label_name",
";",
"$",
"bound_parameters",
"[",
"$",
"label_name",
"]",
"=",
"$",
"value",
";",
"}",
"$",
"sql",
"=",
"\"(\"",
".",
"implode",
"(",
"\", \"",
",",
"$",
"sql",
")",
".",
"\")\"",
";",
"}",
"return",
"$",
"sql",
";",
"}"
] | Builds a sub-query for an IN statement with bound values.
@example buildInQueryBindings(array("a", "b", "c"), "ex") => "(:ex_0, :ex_1, :ex_2)", and adds keys for 'ex_0', 'ex_1' and 'ex_2' to the bound parameters
@param array $values The values to bind.
@param string [$prefix] A prefix to apply to the bound parameter keys.
@param array [&$bound_parameters] A reference to the array to inject the bindings on to.
@return string Contains the SQL query subsection, ex. "(:in_1, :in_2)" | [
"Builds",
"a",
"sub",
"-",
"query",
"for",
"an",
"IN",
"statement",
"with",
"bound",
"values",
"."
] | cc5e4268bac36c68af62d69d9512a0dd01ee310f | https://github.com/porkchopsandwiches/doctrine-utilities/blob/cc5e4268bac36c68af62d69d9512a0dd01ee310f/lib/src/PorkChopSandwiches/Doctrine/Utilities/DB.php#L42-L60 | train |
porkchopsandwiches/doctrine-utilities | lib/src/PorkChopSandwiches/Doctrine/Utilities/DB.php | DB.query | public function query ($sql, array $bound_parameters = array(), $fetch = true) {
$statement = $this -> entity_manager -> getConnection() -> prepare($sql);
foreach ($bound_parameters as $parameter => $value) {
$statement -> bindValue($parameter, $value);
}
$statement -> execute();
if ($fetch) {
return $statement -> fetchAll();
} else {
return null;
}
} | php | public function query ($sql, array $bound_parameters = array(), $fetch = true) {
$statement = $this -> entity_manager -> getConnection() -> prepare($sql);
foreach ($bound_parameters as $parameter => $value) {
$statement -> bindValue($parameter, $value);
}
$statement -> execute();
if ($fetch) {
return $statement -> fetchAll();
} else {
return null;
}
} | [
"public",
"function",
"query",
"(",
"$",
"sql",
",",
"array",
"$",
"bound_parameters",
"=",
"array",
"(",
")",
",",
"$",
"fetch",
"=",
"true",
")",
"{",
"$",
"statement",
"=",
"$",
"this",
"->",
"entity_manager",
"->",
"getConnection",
"(",
")",
"->",
"prepare",
"(",
"$",
"sql",
")",
";",
"foreach",
"(",
"$",
"bound_parameters",
"as",
"$",
"parameter",
"=>",
"$",
"value",
")",
"{",
"$",
"statement",
"->",
"bindValue",
"(",
"$",
"parameter",
",",
"$",
"value",
")",
";",
"}",
"$",
"statement",
"->",
"execute",
"(",
")",
";",
"if",
"(",
"$",
"fetch",
")",
"{",
"return",
"$",
"statement",
"->",
"fetchAll",
"(",
")",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] | Performs an arbitrary SQL query.
@author Cam Morrow
@param string $sql
@param array [$bound_parameters]
@param bool [$fetch]
@return array|null | [
"Performs",
"an",
"arbitrary",
"SQL",
"query",
"."
] | cc5e4268bac36c68af62d69d9512a0dd01ee310f | https://github.com/porkchopsandwiches/doctrine-utilities/blob/cc5e4268bac36c68af62d69d9512a0dd01ee310f/lib/src/PorkChopSandwiches/Doctrine/Utilities/DB.php#L73-L88 | train |
porkchopsandwiches/doctrine-utilities | lib/src/PorkChopSandwiches/Doctrine/Utilities/DB.php | DB.queryDQL | public function queryDQL ($dql, array $bound_parameters = array()) {
$statement = $this -> entity_manager -> createQuery($dql);
foreach ($bound_parameters as $parameter => $value) {
$statement -> setParameter($parameter, $value);
}
return $statement -> getResult();
} | php | public function queryDQL ($dql, array $bound_parameters = array()) {
$statement = $this -> entity_manager -> createQuery($dql);
foreach ($bound_parameters as $parameter => $value) {
$statement -> setParameter($parameter, $value);
}
return $statement -> getResult();
} | [
"public",
"function",
"queryDQL",
"(",
"$",
"dql",
",",
"array",
"$",
"bound_parameters",
"=",
"array",
"(",
")",
")",
"{",
"$",
"statement",
"=",
"$",
"this",
"->",
"entity_manager",
"->",
"createQuery",
"(",
"$",
"dql",
")",
";",
"foreach",
"(",
"$",
"bound_parameters",
"as",
"$",
"parameter",
"=>",
"$",
"value",
")",
"{",
"$",
"statement",
"->",
"setParameter",
"(",
"$",
"parameter",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"statement",
"->",
"getResult",
"(",
")",
";",
"}"
] | Performs an arbitrary DQL query.
@param string $dql
@param array [$bound_parameters]
@return array | [
"Performs",
"an",
"arbitrary",
"DQL",
"query",
"."
] | cc5e4268bac36c68af62d69d9512a0dd01ee310f | https://github.com/porkchopsandwiches/doctrine-utilities/blob/cc5e4268bac36c68af62d69d9512a0dd01ee310f/lib/src/PorkChopSandwiches/Doctrine/Utilities/DB.php#L98-L106 | train |
linkeddatacenter/BOTK-rdf | library/BOTK/RDF/HttpClient.php | HttpClient.useIdentity | public static function useIdentity($username=null,$password=null,$timeout=null)
{
$httpClient = \EasyRdf_Http::getDefaultHttpClient();
// if current default http client does not provide setAuth use a new instance of HttpClient
if (!($httpClient instanceof \Zend_Http_Client or $httpClient instanceof HttpClient)){
$httpClient = new HttpClient(null,array (
'maxredirects' => 5,
'useragent' => 'BOTK HttpClient',
'timeout' => ini_get('max_execution_time') || 30,
));
}
$httpClient->setAuth($username, $password);
return \EasyRdf_Http::setDefaultHttpClient($httpClient);
} | php | public static function useIdentity($username=null,$password=null,$timeout=null)
{
$httpClient = \EasyRdf_Http::getDefaultHttpClient();
// if current default http client does not provide setAuth use a new instance of HttpClient
if (!($httpClient instanceof \Zend_Http_Client or $httpClient instanceof HttpClient)){
$httpClient = new HttpClient(null,array (
'maxredirects' => 5,
'useragent' => 'BOTK HttpClient',
'timeout' => ini_get('max_execution_time') || 30,
));
}
$httpClient->setAuth($username, $password);
return \EasyRdf_Http::setDefaultHttpClient($httpClient);
} | [
"public",
"static",
"function",
"useIdentity",
"(",
"$",
"username",
"=",
"null",
",",
"$",
"password",
"=",
"null",
",",
"$",
"timeout",
"=",
"null",
")",
"{",
"$",
"httpClient",
"=",
"\\",
"EasyRdf_Http",
"::",
"getDefaultHttpClient",
"(",
")",
";",
"// if current default http client does not provide setAuth use a new instance of HttpClient",
"if",
"(",
"!",
"(",
"$",
"httpClient",
"instanceof",
"\\",
"Zend_Http_Client",
"or",
"$",
"httpClient",
"instanceof",
"HttpClient",
")",
")",
"{",
"$",
"httpClient",
"=",
"new",
"HttpClient",
"(",
"null",
",",
"array",
"(",
"'maxredirects'",
"=>",
"5",
",",
"'useragent'",
"=>",
"'BOTK HttpClient'",
",",
"'timeout'",
"=>",
"ini_get",
"(",
"'max_execution_time'",
")",
"||",
"30",
",",
")",
")",
";",
"}",
"$",
"httpClient",
"->",
"setAuth",
"(",
"$",
"username",
",",
"$",
"password",
")",
";",
"return",
"\\",
"EasyRdf_Http",
"::",
"setDefaultHttpClient",
"(",
"$",
"httpClient",
")",
";",
"}"
] | Just an helper to use HttPClient as default EastRdf_default_client) | [
"Just",
"an",
"helper",
"to",
"use",
"HttPClient",
"as",
"default",
"EastRdf_default_client",
")"
] | f89eb4bd8eddbce75b8ca83a1199bd1e7481fc69 | https://github.com/linkeddatacenter/BOTK-rdf/blob/f89eb4bd8eddbce75b8ca83a1199bd1e7481fc69/library/BOTK/RDF/HttpClient.php#L19-L34 | train |
lassodatasystems/LassoMailParserBundle | ParseHelper.php | ParseHelper.hasHeader | protected function hasHeader(Part $part, $header)
{
if (count($part->getHeaders()) < 1) {
return false;
}
return $part
->getHeaders()
->has($header);
} | php | protected function hasHeader(Part $part, $header)
{
if (count($part->getHeaders()) < 1) {
return false;
}
return $part
->getHeaders()
->has($header);
} | [
"protected",
"function",
"hasHeader",
"(",
"Part",
"$",
"part",
",",
"$",
"header",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"part",
"->",
"getHeaders",
"(",
")",
")",
"<",
"1",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"part",
"->",
"getHeaders",
"(",
")",
"->",
"has",
"(",
"$",
"header",
")",
";",
"}"
] | The confusing zend API makes a custom function for
header checking necessary.
@param Part $part
@param string $header
@return bool | [
"The",
"confusing",
"zend",
"API",
"makes",
"a",
"custom",
"function",
"for",
"header",
"checking",
"necessary",
"."
] | c7d2bde3034462fd305e38481cfb737b50eede0a | https://github.com/lassodatasystems/LassoMailParserBundle/blob/c7d2bde3034462fd305e38481cfb737b50eede0a/ParseHelper.php#L33-L42 | train |
lassodatasystems/LassoMailParserBundle | ParseHelper.php | ParseHelper.getContentType | protected function getContentType(Part $part)
{
if (!$this->hasHeader($part, 'Content-Type')) {
throw new Exception('This email does not have a content type. Check for that with hasContentType()');
}
$zendContentType = $part
->getHeaders()
->get('Content-Type');
switch (true) {
case is_array($zendContentType):
return $zendContentType[0];
case $zendContentType instanceof HeaderInterface:
return $zendContentType;
case $zendContentType instanceof ArrayIterator:
return $zendContentType->current();
default:
throw new Exception('Unexpected return type ' .
gettype($zendContentType) .
', expected one of string, array, HeaderInterface or ArrayIterator' .
' from Part::getHeaders()::get("Content-Type"))'
);
}
} | php | protected function getContentType(Part $part)
{
if (!$this->hasHeader($part, 'Content-Type')) {
throw new Exception('This email does not have a content type. Check for that with hasContentType()');
}
$zendContentType = $part
->getHeaders()
->get('Content-Type');
switch (true) {
case is_array($zendContentType):
return $zendContentType[0];
case $zendContentType instanceof HeaderInterface:
return $zendContentType;
case $zendContentType instanceof ArrayIterator:
return $zendContentType->current();
default:
throw new Exception('Unexpected return type ' .
gettype($zendContentType) .
', expected one of string, array, HeaderInterface or ArrayIterator' .
' from Part::getHeaders()::get("Content-Type"))'
);
}
} | [
"protected",
"function",
"getContentType",
"(",
"Part",
"$",
"part",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasHeader",
"(",
"$",
"part",
",",
"'Content-Type'",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'This email does not have a content type. Check for that with hasContentType()'",
")",
";",
"}",
"$",
"zendContentType",
"=",
"$",
"part",
"->",
"getHeaders",
"(",
")",
"->",
"get",
"(",
"'Content-Type'",
")",
";",
"switch",
"(",
"true",
")",
"{",
"case",
"is_array",
"(",
"$",
"zendContentType",
")",
":",
"return",
"$",
"zendContentType",
"[",
"0",
"]",
";",
"case",
"$",
"zendContentType",
"instanceof",
"HeaderInterface",
":",
"return",
"$",
"zendContentType",
";",
"case",
"$",
"zendContentType",
"instanceof",
"ArrayIterator",
":",
"return",
"$",
"zendContentType",
"->",
"current",
"(",
")",
";",
"default",
":",
"throw",
"new",
"Exception",
"(",
"'Unexpected return type '",
".",
"gettype",
"(",
"$",
"zendContentType",
")",
".",
"', expected one of string, array, HeaderInterface or ArrayIterator'",
".",
"' from Part::getHeaders()::get(\"Content-Type\"))'",
")",
";",
"}",
"}"
] | Returns the content type of the given part. Since zends API
allows for four different return values, we need to handle
every type differently. Multiple content-type headers can't
be accounted for, in those cases we simply take the first
one and hope for the best. If it doesn't work, there's not
much that could be done as content-type guessing is not an
easily solved problem.
The content-type header should always be broken up into
a header interface, it just could happen that the zend
framework returns an array or array iterator when multiple
content-type headers are present. In that case, the first
encountered header will be used.
@param Part $part
@return HeaderInterface
@throws \Exception | [
"Returns",
"the",
"content",
"type",
"of",
"the",
"given",
"part",
".",
"Since",
"zends",
"API",
"allows",
"for",
"four",
"different",
"return",
"values",
"we",
"need",
"to",
"handle",
"every",
"type",
"differently",
".",
"Multiple",
"content",
"-",
"type",
"headers",
"can",
"t",
"be",
"accounted",
"for",
"in",
"those",
"cases",
"we",
"simply",
"take",
"the",
"first",
"one",
"and",
"hope",
"for",
"the",
"best",
".",
"If",
"it",
"doesn",
"t",
"work",
"there",
"s",
"not",
"much",
"that",
"could",
"be",
"done",
"as",
"content",
"-",
"type",
"guessing",
"is",
"not",
"an",
"easily",
"solved",
"problem",
"."
] | c7d2bde3034462fd305e38481cfb737b50eede0a | https://github.com/lassodatasystems/LassoMailParserBundle/blob/c7d2bde3034462fd305e38481cfb737b50eede0a/ParseHelper.php#L64-L88 | train |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Type/Type.php | Type.convertToDatabaseValue | public function convertToDatabaseValue($value, $marshal = true)
{
$converted = $value !== null ? $this->databaseValue($value) : null;
if (!$marshal) {
return $converted;
}
return $converted === null ? self::getNull() : [static::$dynamoKey => $converted];
} | php | public function convertToDatabaseValue($value, $marshal = true)
{
$converted = $value !== null ? $this->databaseValue($value) : null;
if (!$marshal) {
return $converted;
}
return $converted === null ? self::getNull() : [static::$dynamoKey => $converted];
} | [
"public",
"function",
"convertToDatabaseValue",
"(",
"$",
"value",
",",
"$",
"marshal",
"=",
"true",
")",
"{",
"$",
"converted",
"=",
"$",
"value",
"!==",
"null",
"?",
"$",
"this",
"->",
"databaseValue",
"(",
"$",
"value",
")",
":",
"null",
";",
"if",
"(",
"!",
"$",
"marshal",
")",
"{",
"return",
"$",
"converted",
";",
"}",
"return",
"$",
"converted",
"===",
"null",
"?",
"self",
"::",
"getNull",
"(",
")",
":",
"[",
"static",
"::",
"$",
"dynamoKey",
"=>",
"$",
"converted",
"]",
";",
"}"
] | Converts a value from its PHP representation of this type to its serialized
DynamoDB representation, optionally applying marshalling afterwards.
@param mixed $value The PHP value to convert.
@param bool $marshal
@return array|string The serialized DynamoDB representation of the value. | [
"Converts",
"a",
"value",
"from",
"its",
"PHP",
"representation",
"of",
"this",
"type",
"to",
"its",
"serialized",
"DynamoDB",
"representation",
"optionally",
"applying",
"marshalling",
"afterwards",
"."
] | 119d355e2c5cbaef1f867970349b4432f5704fcd | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Type/Type.php#L113-L122 | train |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Type/Type.php | Type.convertToPHPValue | public function convertToPHPValue($value, $unmarshal = true)
{
if ($unmarshal) {
$value = $value === self::getNull() ? null : $value[static::$dynamoKey];
}
return $value === null ? null : $this->phpValue($value);
} | php | public function convertToPHPValue($value, $unmarshal = true)
{
if ($unmarshal) {
$value = $value === self::getNull() ? null : $value[static::$dynamoKey];
}
return $value === null ? null : $this->phpValue($value);
} | [
"public",
"function",
"convertToPHPValue",
"(",
"$",
"value",
",",
"$",
"unmarshal",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"unmarshal",
")",
"{",
"$",
"value",
"=",
"$",
"value",
"===",
"self",
"::",
"getNull",
"(",
")",
"?",
"null",
":",
"$",
"value",
"[",
"static",
"::",
"$",
"dynamoKey",
"]",
";",
"}",
"return",
"$",
"value",
"===",
"null",
"?",
"null",
":",
"$",
"this",
"->",
"phpValue",
"(",
"$",
"value",
")",
";",
"}"
] | Converts a value from its serialized DynamoDB representation to its PHP representation
of this type, optionally unmarshalling it first.
@param array|string $value The serialized DynamoDB value to convert.
@param bool $unmarshal
@return mixed The PHP representation of the value. | [
"Converts",
"a",
"value",
"from",
"its",
"serialized",
"DynamoDB",
"representation",
"to",
"its",
"PHP",
"representation",
"of",
"this",
"type",
"optionally",
"unmarshalling",
"it",
"first",
"."
] | 119d355e2c5cbaef1f867970349b4432f5704fcd | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Type/Type.php#L133-L140 | train |
cloudtek/dynamodm | lib/Cloudtek/DynamoDM/Type/Type.php | Type.convertUnmappedToPHPValue | public static function convertUnmappedToPHPValue($value)
{
$type = key($value);
$value = current($value);
switch ($type) {
case 'S':
case 'B':
case 'BOOL':
return $value;
case 'NULL':
return null;
case 'N':
// Use type coercion to unmarshal numbers to int/float.
return $value + 0;
case 'M':
case 'L':
foreach ($value as $k => $v) {
$value[$k] = self::convertUnmappedToPHPValue($v);
}
return $value;
case 'BS':
case 'NS':
case 'SS':
$childType = substr($type, 0, 1);
return array_map(
function ($childValue) use ($childType) {
return self::convertUnmappedToPHPValue([$childType => $childValue]);
},
$value
);
}
throw new \UnexpectedValueException("Unexpected type: $type.");
} | php | public static function convertUnmappedToPHPValue($value)
{
$type = key($value);
$value = current($value);
switch ($type) {
case 'S':
case 'B':
case 'BOOL':
return $value;
case 'NULL':
return null;
case 'N':
// Use type coercion to unmarshal numbers to int/float.
return $value + 0;
case 'M':
case 'L':
foreach ($value as $k => $v) {
$value[$k] = self::convertUnmappedToPHPValue($v);
}
return $value;
case 'BS':
case 'NS':
case 'SS':
$childType = substr($type, 0, 1);
return array_map(
function ($childValue) use ($childType) {
return self::convertUnmappedToPHPValue([$childType => $childValue]);
},
$value
);
}
throw new \UnexpectedValueException("Unexpected type: $type.");
} | [
"public",
"static",
"function",
"convertUnmappedToPHPValue",
"(",
"$",
"value",
")",
"{",
"$",
"type",
"=",
"key",
"(",
"$",
"value",
")",
";",
"$",
"value",
"=",
"current",
"(",
"$",
"value",
")",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'S'",
":",
"case",
"'B'",
":",
"case",
"'BOOL'",
":",
"return",
"$",
"value",
";",
"case",
"'NULL'",
":",
"return",
"null",
";",
"case",
"'N'",
":",
"// Use type coercion to unmarshal numbers to int/float.",
"return",
"$",
"value",
"+",
"0",
";",
"case",
"'M'",
":",
"case",
"'L'",
":",
"foreach",
"(",
"$",
"value",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"value",
"[",
"$",
"k",
"]",
"=",
"self",
"::",
"convertUnmappedToPHPValue",
"(",
"$",
"v",
")",
";",
"}",
"return",
"$",
"value",
";",
"case",
"'BS'",
":",
"case",
"'NS'",
":",
"case",
"'SS'",
":",
"$",
"childType",
"=",
"substr",
"(",
"$",
"type",
",",
"0",
",",
"1",
")",
";",
"return",
"array_map",
"(",
"function",
"(",
"$",
"childValue",
")",
"use",
"(",
"$",
"childType",
")",
"{",
"return",
"self",
"::",
"convertUnmappedToPHPValue",
"(",
"[",
"$",
"childType",
"=>",
"$",
"childValue",
"]",
")",
";",
"}",
",",
"$",
"value",
")",
";",
"}",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"\"Unexpected type: $type.\"",
")",
";",
"}"
] | Child values of a list or map do not have an ODM type mapped, it must be
inferred from the value and DynamoDB data type.
Adapted from {@see \Aws\DynamoDb\Marshaler}.
@param mixed $value
@return mixed The PHP representation of the value. | [
"Child",
"values",
"of",
"a",
"list",
"or",
"map",
"do",
"not",
"have",
"an",
"ODM",
"type",
"mapped",
"it",
"must",
"be",
"inferred",
"from",
"the",
"value",
"and",
"DynamoDB",
"data",
"type",
"."
] | 119d355e2c5cbaef1f867970349b4432f5704fcd | https://github.com/cloudtek/dynamodm/blob/119d355e2c5cbaef1f867970349b4432f5704fcd/lib/Cloudtek/DynamoDM/Type/Type.php#L152-L188 | train |
dms-org/common.structure | src/Geo/Country.php | Country.fromName | public static function fromName(string $countryName): Country
{
self::getNameMap();
if (!isset(self::$alpha2CodeMap[$countryName])) {
throw InvalidArgumentException::format(
'Invalid country short name supplied to %s: country \'%s\' is not a valid option',
__METHOD__, $countryName
);
}
return new self(self::$alpha2CodeMap[$countryName]);
} | php | public static function fromName(string $countryName): Country
{
self::getNameMap();
if (!isset(self::$alpha2CodeMap[$countryName])) {
throw InvalidArgumentException::format(
'Invalid country short name supplied to %s: country \'%s\' is not a valid option',
__METHOD__, $countryName
);
}
return new self(self::$alpha2CodeMap[$countryName]);
} | [
"public",
"static",
"function",
"fromName",
"(",
"string",
"$",
"countryName",
")",
":",
"Country",
"{",
"self",
"::",
"getNameMap",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"alpha2CodeMap",
"[",
"$",
"countryName",
"]",
")",
")",
"{",
"throw",
"InvalidArgumentException",
"::",
"format",
"(",
"'Invalid country short name supplied to %s: country \\'%s\\' is not a valid option'",
",",
"__METHOD__",
",",
"$",
"countryName",
")",
";",
"}",
"return",
"new",
"self",
"(",
"self",
"::",
"$",
"alpha2CodeMap",
"[",
"$",
"countryName",
"]",
")",
";",
"}"
] | Builds a country enum from the supplied country short name.
@param string $countryName
@return Country
@throws InvalidArgumentException | [
"Builds",
"a",
"country",
"enum",
"from",
"the",
"supplied",
"country",
"short",
"name",
"."
] | 23f122182f60df5ec847047a81a39c8aab019ff1 | https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/Geo/Country.php#L310-L322 | train |
dms-org/common.structure | src/Geo/Country.php | Country.getNameMap | public static function getNameMap(): array
{
if (self::$nameMap === null) {
self::$nameMap = [];
$countries = self::getLoader()->all();
foreach ($countries as $country) {
self::$nameMap[$country['alpha2']] = $country['name'];
}
self::$alpha2CodeMap = array_flip(self::$nameMap);
}
return self::$nameMap;
} | php | public static function getNameMap(): array
{
if (self::$nameMap === null) {
self::$nameMap = [];
$countries = self::getLoader()->all();
foreach ($countries as $country) {
self::$nameMap[$country['alpha2']] = $country['name'];
}
self::$alpha2CodeMap = array_flip(self::$nameMap);
}
return self::$nameMap;
} | [
"public",
"static",
"function",
"getNameMap",
"(",
")",
":",
"array",
"{",
"if",
"(",
"self",
"::",
"$",
"nameMap",
"===",
"null",
")",
"{",
"self",
"::",
"$",
"nameMap",
"=",
"[",
"]",
";",
"$",
"countries",
"=",
"self",
"::",
"getLoader",
"(",
")",
"->",
"all",
"(",
")",
";",
"foreach",
"(",
"$",
"countries",
"as",
"$",
"country",
")",
"{",
"self",
"::",
"$",
"nameMap",
"[",
"$",
"country",
"[",
"'alpha2'",
"]",
"]",
"=",
"$",
"country",
"[",
"'name'",
"]",
";",
"}",
"self",
"::",
"$",
"alpha2CodeMap",
"=",
"array_flip",
"(",
"self",
"::",
"$",
"nameMap",
")",
";",
"}",
"return",
"self",
"::",
"$",
"nameMap",
";",
"}"
] | Returns an array the country short names indexed by
their respective ISO 3166-1 alpha-2 country code.
@return string[] | [
"Returns",
"an",
"array",
"the",
"country",
"short",
"names",
"indexed",
"by",
"their",
"respective",
"ISO",
"3166",
"-",
"1",
"alpha",
"-",
"2",
"country",
"code",
"."
] | 23f122182f60df5ec847047a81a39c8aab019ff1 | https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/Geo/Country.php#L344-L358 | train |
nicmart/DomainSpecificQuery | src/Lucene/Compiler/Map/MapBuilder.php | MapBuilder.combine | public function combine($op, $map1/**, $transf2,... */)
{
$transformations = func_get_args();
array_shift($transformations);
return function(Expression $expr, $compiler) use ($op, $transformations)
{
$tree = new SpanExpression(strtoupper($op));
foreach ($transformations as $transformation) {
$tree->addExpression($transformation($expr, $compiler));
}
return $tree;
};
} | php | public function combine($op, $map1/**, $transf2,... */)
{
$transformations = func_get_args();
array_shift($transformations);
return function(Expression $expr, $compiler) use ($op, $transformations)
{
$tree = new SpanExpression(strtoupper($op));
foreach ($transformations as $transformation) {
$tree->addExpression($transformation($expr, $compiler));
}
return $tree;
};
} | [
"public",
"function",
"combine",
"(",
"$",
"op",
",",
"$",
"map1",
"/**, $transf2,... */",
")",
"{",
"$",
"transformations",
"=",
"func_get_args",
"(",
")",
";",
"array_shift",
"(",
"$",
"transformations",
")",
";",
"return",
"function",
"(",
"Expression",
"$",
"expr",
",",
"$",
"compiler",
")",
"use",
"(",
"$",
"op",
",",
"$",
"transformations",
")",
"{",
"$",
"tree",
"=",
"new",
"SpanExpression",
"(",
"strtoupper",
"(",
"$",
"op",
")",
")",
";",
"foreach",
"(",
"$",
"transformations",
"as",
"$",
"transformation",
")",
"{",
"$",
"tree",
"->",
"addExpression",
"(",
"$",
"transformation",
"(",
"$",
"expr",
",",
"$",
"compiler",
")",
")",
";",
"}",
"return",
"$",
"tree",
";",
"}",
";",
"}"
] | Combine many maps to a single tree one
@param string $op A boolean operator
@param callable $map1, ...
@return callable | [
"Combine",
"many",
"maps",
"to",
"a",
"single",
"tree",
"one"
] | 7c01fe94337afdfae5884809e8b5487127a63ac3 | https://github.com/nicmart/DomainSpecificQuery/blob/7c01fe94337afdfae5884809e8b5487127a63ac3/src/Lucene/Compiler/Map/MapBuilder.php#L142-L157 | train |
nicmart/DomainSpecificQuery | src/Lucene/Compiler/Map/MapBuilder.php | MapBuilder.regexps | public function regexps(array $regexpsMap)
{
return function(FieldExpression $expr, $compiler) use ($regexpsMap)
{
$value = $expr->getValue();
foreach ($regexpsMap as $regexp => $transformation) {
if (preg_match($regexp, $value))
return $transformation($expr, $compiler);
}
throw new UnregisteredTransformationException("There is no transformation matching the value \"$value\"");
};
} | php | public function regexps(array $regexpsMap)
{
return function(FieldExpression $expr, $compiler) use ($regexpsMap)
{
$value = $expr->getValue();
foreach ($regexpsMap as $regexp => $transformation) {
if (preg_match($regexp, $value))
return $transformation($expr, $compiler);
}
throw new UnregisteredTransformationException("There is no transformation matching the value \"$value\"");
};
} | [
"public",
"function",
"regexps",
"(",
"array",
"$",
"regexpsMap",
")",
"{",
"return",
"function",
"(",
"FieldExpression",
"$",
"expr",
",",
"$",
"compiler",
")",
"use",
"(",
"$",
"regexpsMap",
")",
"{",
"$",
"value",
"=",
"$",
"expr",
"->",
"getValue",
"(",
")",
";",
"foreach",
"(",
"$",
"regexpsMap",
"as",
"$",
"regexp",
"=>",
"$",
"transformation",
")",
"{",
"if",
"(",
"preg_match",
"(",
"$",
"regexp",
",",
"$",
"value",
")",
")",
"return",
"$",
"transformation",
"(",
"$",
"expr",
",",
"$",
"compiler",
")",
";",
"}",
"throw",
"new",
"UnregisteredTransformationException",
"(",
"\"There is no transformation matching the value \\\"$value\\\"\"",
")",
";",
"}",
";",
"}"
] | This map select the transformation with regexps on the exoression value
@param callable[] $regexpsMap
@return callable | [
"This",
"map",
"select",
"the",
"transformation",
"with",
"regexps",
"on",
"the",
"exoression",
"value"
] | 7c01fe94337afdfae5884809e8b5487127a63ac3 | https://github.com/nicmart/DomainSpecificQuery/blob/7c01fe94337afdfae5884809e8b5487127a63ac3/src/Lucene/Compiler/Map/MapBuilder.php#L165-L178 | train |
nicmart/DomainSpecificQuery | src/Lucene/Compiler/Map/MapBuilder.php | MapBuilder.conditional | public function conditional($condition1, $map1/*, $condition2, $map2*/)
{
$args = func_get_args();
return function(Expression $expr, $compiler) use ($args)
{
$numargs = count($args);
for ($i = 0; $i + 1 < $numargs; $i += 2) {
$condition = $args[$i];
$map = $args[$i+1];
if ($condition($expr))
return $map($expr, $compiler);
}
throw new UnregisteredTransformationException("No condition matched with the given expression");
};
} | php | public function conditional($condition1, $map1/*, $condition2, $map2*/)
{
$args = func_get_args();
return function(Expression $expr, $compiler) use ($args)
{
$numargs = count($args);
for ($i = 0; $i + 1 < $numargs; $i += 2) {
$condition = $args[$i];
$map = $args[$i+1];
if ($condition($expr))
return $map($expr, $compiler);
}
throw new UnregisteredTransformationException("No condition matched with the given expression");
};
} | [
"public",
"function",
"conditional",
"(",
"$",
"condition1",
",",
"$",
"map1",
"/*, $condition2, $map2*/",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"return",
"function",
"(",
"Expression",
"$",
"expr",
",",
"$",
"compiler",
")",
"use",
"(",
"$",
"args",
")",
"{",
"$",
"numargs",
"=",
"count",
"(",
"$",
"args",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"+",
"1",
"<",
"$",
"numargs",
";",
"$",
"i",
"+=",
"2",
")",
"{",
"$",
"condition",
"=",
"$",
"args",
"[",
"$",
"i",
"]",
";",
"$",
"map",
"=",
"$",
"args",
"[",
"$",
"i",
"+",
"1",
"]",
";",
"if",
"(",
"$",
"condition",
"(",
"$",
"expr",
")",
")",
"return",
"$",
"map",
"(",
"$",
"expr",
",",
"$",
"compiler",
")",
";",
"}",
"throw",
"new",
"UnregisteredTransformationException",
"(",
"\"No condition matched with the given expression\"",
")",
";",
"}",
";",
"}"
] | Build a map from a collection of condition and map couples.
It will be used the map of the first matched condition.
@param callable $condition1
@param callable $map1 , ...
@return callable | [
"Build",
"a",
"map",
"from",
"a",
"collection",
"of",
"condition",
"and",
"map",
"couples",
".",
"It",
"will",
"be",
"used",
"the",
"map",
"of",
"the",
"first",
"matched",
"condition",
"."
] | 7c01fe94337afdfae5884809e8b5487127a63ac3 | https://github.com/nicmart/DomainSpecificQuery/blob/7c01fe94337afdfae5884809e8b5487127a63ac3/src/Lucene/Compiler/Map/MapBuilder.php#L189-L203 | train |
nicmart/DomainSpecificQuery | src/Lucene/Compiler/Map/MapBuilder.php | MapBuilder.attr | public function attr($map, array $attributes)
{
return function(Expression $expr, $compiler) use ($map, $attributes)
{
$luceneExpr = $map($expr, $compiler);
foreach ($attributes as $name => $value) {
$luceneExpr[$name] = $value;
}
return $luceneExpr;
};
} | php | public function attr($map, array $attributes)
{
return function(Expression $expr, $compiler) use ($map, $attributes)
{
$luceneExpr = $map($expr, $compiler);
foreach ($attributes as $name => $value) {
$luceneExpr[$name] = $value;
}
return $luceneExpr;
};
} | [
"public",
"function",
"attr",
"(",
"$",
"map",
",",
"array",
"$",
"attributes",
")",
"{",
"return",
"function",
"(",
"Expression",
"$",
"expr",
",",
"$",
"compiler",
")",
"use",
"(",
"$",
"map",
",",
"$",
"attributes",
")",
"{",
"$",
"luceneExpr",
"=",
"$",
"map",
"(",
"$",
"expr",
",",
"$",
"compiler",
")",
";",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"luceneExpr",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"luceneExpr",
";",
"}",
";",
"}"
] | Set attributes in the resulting expression.
@param $map
@param array $attributes
@return callable | [
"Set",
"attributes",
"in",
"the",
"resulting",
"expression",
"."
] | 7c01fe94337afdfae5884809e8b5487127a63ac3 | https://github.com/nicmart/DomainSpecificQuery/blob/7c01fe94337afdfae5884809e8b5487127a63ac3/src/Lucene/Compiler/Map/MapBuilder.php#L234-L246 | train |
AnonymPHP/Anonym-Route | Middleware.php | Middleware.middleware | public function middleware($name = '', $role = '', Closure $next = null)
{
if (!$this->accessDispatcher) {
$this->accessDispatcher = new AccessDispatcher();
}
$middleware = $this->accessDispatcher->process([
'name' => $name,
'role' => $role,
'next' => $next
]);
if (true !== $middleware) {
app('route.middleware.failed');
}
return true;
} | php | public function middleware($name = '', $role = '', Closure $next = null)
{
if (!$this->accessDispatcher) {
$this->accessDispatcher = new AccessDispatcher();
}
$middleware = $this->accessDispatcher->process([
'name' => $name,
'role' => $role,
'next' => $next
]);
if (true !== $middleware) {
app('route.middleware.failed');
}
return true;
} | [
"public",
"function",
"middleware",
"(",
"$",
"name",
"=",
"''",
",",
"$",
"role",
"=",
"''",
",",
"Closure",
"$",
"next",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"accessDispatcher",
")",
"{",
"$",
"this",
"->",
"accessDispatcher",
"=",
"new",
"AccessDispatcher",
"(",
")",
";",
"}",
"$",
"middleware",
"=",
"$",
"this",
"->",
"accessDispatcher",
"->",
"process",
"(",
"[",
"'name'",
"=>",
"$",
"name",
",",
"'role'",
"=>",
"$",
"role",
",",
"'next'",
"=>",
"$",
"next",
"]",
")",
";",
"if",
"(",
"true",
"!==",
"$",
"middleware",
")",
"{",
"app",
"(",
"'route.middleware.failed'",
")",
";",
"}",
"return",
"true",
";",
"}"
] | determine user authentication
@param string $name the middleware name
@param string|array $role the role of user, can be string or array
@param Closure $next the callback for middleware
@throws MiddlewareException
@return bool | [
"determine",
"user",
"authentication"
] | bb7f8004fbbd2998af8b0061f404f026f11466ab | https://github.com/AnonymPHP/Anonym-Route/blob/bb7f8004fbbd2998af8b0061f404f026f11466ab/Middleware.php#L41-L58 | train |
Blipfoto/php-sdk | src/Blipfoto/Api/File.php | File.path | public function path() {
$args = func_get_args();
if (count($args)) {
$this->path = $this->verify($args[0]);
}
return $this->path;
} | php | public function path() {
$args = func_get_args();
if (count($args)) {
$this->path = $this->verify($args[0]);
}
return $this->path;
} | [
"public",
"function",
"path",
"(",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"args",
")",
")",
"{",
"$",
"this",
"->",
"path",
"=",
"$",
"this",
"->",
"verify",
"(",
"$",
"args",
"[",
"0",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"path",
";",
"}"
] | Get or set the path.
@param string $path (optional)
@return string | [
"Get",
"or",
"set",
"the",
"path",
"."
] | 04f770ac7427e79d15f97b993c787651079cdeb4 | https://github.com/Blipfoto/php-sdk/blob/04f770ac7427e79d15f97b993c787651079cdeb4/src/Blipfoto/Api/File.php#L29-L35 | train |
Blipfoto/php-sdk | src/Blipfoto/Api/File.php | File.verify | public function verify($path) {
$full_path = realpath($path);
$data = @getimagesize($full_path);
if (!$data) {
throw new FileException(sprintf('File "%s" cannot be read.', $path), 1);
}
if ($data[2] != IMG_JPG) {
throw new FileException(sprintf('File "%s" is not a JPG.', $path), 240);
}
if ($data[0] < 600 || $data[1] < 600) {
throw new FileException(sprintf('File "%s" is too small.', $path), 241);
}
return $full_path;
} | php | public function verify($path) {
$full_path = realpath($path);
$data = @getimagesize($full_path);
if (!$data) {
throw new FileException(sprintf('File "%s" cannot be read.', $path), 1);
}
if ($data[2] != IMG_JPG) {
throw new FileException(sprintf('File "%s" is not a JPG.', $path), 240);
}
if ($data[0] < 600 || $data[1] < 600) {
throw new FileException(sprintf('File "%s" is too small.', $path), 241);
}
return $full_path;
} | [
"public",
"function",
"verify",
"(",
"$",
"path",
")",
"{",
"$",
"full_path",
"=",
"realpath",
"(",
"$",
"path",
")",
";",
"$",
"data",
"=",
"@",
"getimagesize",
"(",
"$",
"full_path",
")",
";",
"if",
"(",
"!",
"$",
"data",
")",
"{",
"throw",
"new",
"FileException",
"(",
"sprintf",
"(",
"'File \"%s\" cannot be read.'",
",",
"$",
"path",
")",
",",
"1",
")",
";",
"}",
"if",
"(",
"$",
"data",
"[",
"2",
"]",
"!=",
"IMG_JPG",
")",
"{",
"throw",
"new",
"FileException",
"(",
"sprintf",
"(",
"'File \"%s\" is not a JPG.'",
",",
"$",
"path",
")",
",",
"240",
")",
";",
"}",
"if",
"(",
"$",
"data",
"[",
"0",
"]",
"<",
"600",
"||",
"$",
"data",
"[",
"1",
"]",
"<",
"600",
")",
"{",
"throw",
"new",
"FileException",
"(",
"sprintf",
"(",
"'File \"%s\" is too small.'",
",",
"$",
"path",
")",
",",
"241",
")",
";",
"}",
"return",
"$",
"full_path",
";",
"}"
] | Verify the file at a path.
@param string $path
@return string
@throws FileException | [
"Verify",
"the",
"file",
"at",
"a",
"path",
"."
] | 04f770ac7427e79d15f97b993c787651079cdeb4 | https://github.com/Blipfoto/php-sdk/blob/04f770ac7427e79d15f97b993c787651079cdeb4/src/Blipfoto/Api/File.php#L44-L57 | train |
eureka-framework/component-response | src/Response/Json/Json.php | Json.renderContent | public function renderContent()
{
$string = json_encode($this->getContent(), $this->option, $this->depth);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new \RuntimeException('Json encode error ! (error: ' . json_last_error_msg() . ')');
}
return $string;
} | php | public function renderContent()
{
$string = json_encode($this->getContent(), $this->option, $this->depth);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new \RuntimeException('Json encode error ! (error: ' . json_last_error_msg() . ')');
}
return $string;
} | [
"public",
"function",
"renderContent",
"(",
")",
"{",
"$",
"string",
"=",
"json_encode",
"(",
"$",
"this",
"->",
"getContent",
"(",
")",
",",
"$",
"this",
"->",
"option",
",",
"$",
"this",
"->",
"depth",
")",
";",
"if",
"(",
"json_last_error",
"(",
")",
"!==",
"JSON_ERROR_NONE",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Json encode error ! (error: '",
".",
"json_last_error_msg",
"(",
")",
".",
"')'",
")",
";",
"}",
"return",
"$",
"string",
";",
"}"
] | Encode content into json format & display it.
@return string
@throws \RuntimeException | [
"Encode",
"content",
"into",
"json",
"format",
"&",
"display",
"it",
"."
] | f34aea3a0aa67b88c5e7f8a3b86af29c550fa99a | https://github.com/eureka-framework/component-response/blob/f34aea3a0aa67b88c5e7f8a3b86af29c550fa99a/src/Response/Json/Json.php#L46-L55 | train |
Torann/skosh-generator | src/Content/Content.php | Content.load | protected function load(SplFileInfo $file)
{
// File info
$this->filename = $file->getBasename();
$this->sourcePath = $file->getRelativePath();
// Load the file
$data = $file->getContents();
list($content, $meta) = $this->splitContentMeta($data);
// Parse meta
$meta = Yaml::parse($meta) ?: [];
// Parse content
switch ($file->getExtension()) {
case 'md':
case 'markdown':
$content = Markdown::parse($content);
$this->type = self::TYPE_MARKDOWN;
break;
case 'tx':
case 'textile':
$content = Textile::parse($content);
$this->type = self::TYPE_TEXTILE;
break;
}
// Set content
$this->content = $content;
$this->meta = $meta;
// Ensure local URLs are absolute
foreach($this->meta as $key=>$value) {
if (preg_match('/\burl\b|.*_url\b/', $key)) {
$this->meta[$key] = $this->builder->getUrl($value);
}
}
// Set target
$this->setTarget($file);
// Pagination enabled
$this->paginate = isset($this->meta['paginate']);
// Get parent page
if ($root = dirname(dirname($this->target))) {
if ($root !== DIRECTORY_SEPARATOR) {
$this->parentId = ltrim($root, '/');
}
}
// Set URL
$this->url = '/' . trim(str_replace([DIRECTORY_SEPARATOR, '//'], ['/', '/'], $this->target), '/');
// Remove "index.html" from the end, this provides a cleaner URL
if (substr($this->url, -10) === 'index.html') {
$this->url = substr($this->url, 0, -10);
}
// Set basic values
$this->id = trim($this->url, '/') ?: 'root';
$this->title = $this->get('title');
$this->url = $this->builder->getUrl($this->url);
// Set Description
if ($this->has('description')) {
$this->description = $this->get('description');
}
else {
$this->description = $this->getDescription();
}
} | php | protected function load(SplFileInfo $file)
{
// File info
$this->filename = $file->getBasename();
$this->sourcePath = $file->getRelativePath();
// Load the file
$data = $file->getContents();
list($content, $meta) = $this->splitContentMeta($data);
// Parse meta
$meta = Yaml::parse($meta) ?: [];
// Parse content
switch ($file->getExtension()) {
case 'md':
case 'markdown':
$content = Markdown::parse($content);
$this->type = self::TYPE_MARKDOWN;
break;
case 'tx':
case 'textile':
$content = Textile::parse($content);
$this->type = self::TYPE_TEXTILE;
break;
}
// Set content
$this->content = $content;
$this->meta = $meta;
// Ensure local URLs are absolute
foreach($this->meta as $key=>$value) {
if (preg_match('/\burl\b|.*_url\b/', $key)) {
$this->meta[$key] = $this->builder->getUrl($value);
}
}
// Set target
$this->setTarget($file);
// Pagination enabled
$this->paginate = isset($this->meta['paginate']);
// Get parent page
if ($root = dirname(dirname($this->target))) {
if ($root !== DIRECTORY_SEPARATOR) {
$this->parentId = ltrim($root, '/');
}
}
// Set URL
$this->url = '/' . trim(str_replace([DIRECTORY_SEPARATOR, '//'], ['/', '/'], $this->target), '/');
// Remove "index.html" from the end, this provides a cleaner URL
if (substr($this->url, -10) === 'index.html') {
$this->url = substr($this->url, 0, -10);
}
// Set basic values
$this->id = trim($this->url, '/') ?: 'root';
$this->title = $this->get('title');
$this->url = $this->builder->getUrl($this->url);
// Set Description
if ($this->has('description')) {
$this->description = $this->get('description');
}
else {
$this->description = $this->getDescription();
}
} | [
"protected",
"function",
"load",
"(",
"SplFileInfo",
"$",
"file",
")",
"{",
"// File info",
"$",
"this",
"->",
"filename",
"=",
"$",
"file",
"->",
"getBasename",
"(",
")",
";",
"$",
"this",
"->",
"sourcePath",
"=",
"$",
"file",
"->",
"getRelativePath",
"(",
")",
";",
"// Load the file",
"$",
"data",
"=",
"$",
"file",
"->",
"getContents",
"(",
")",
";",
"list",
"(",
"$",
"content",
",",
"$",
"meta",
")",
"=",
"$",
"this",
"->",
"splitContentMeta",
"(",
"$",
"data",
")",
";",
"// Parse meta",
"$",
"meta",
"=",
"Yaml",
"::",
"parse",
"(",
"$",
"meta",
")",
"?",
":",
"[",
"]",
";",
"// Parse content",
"switch",
"(",
"$",
"file",
"->",
"getExtension",
"(",
")",
")",
"{",
"case",
"'md'",
":",
"case",
"'markdown'",
":",
"$",
"content",
"=",
"Markdown",
"::",
"parse",
"(",
"$",
"content",
")",
";",
"$",
"this",
"->",
"type",
"=",
"self",
"::",
"TYPE_MARKDOWN",
";",
"break",
";",
"case",
"'tx'",
":",
"case",
"'textile'",
":",
"$",
"content",
"=",
"Textile",
"::",
"parse",
"(",
"$",
"content",
")",
";",
"$",
"this",
"->",
"type",
"=",
"self",
"::",
"TYPE_TEXTILE",
";",
"break",
";",
"}",
"// Set content",
"$",
"this",
"->",
"content",
"=",
"$",
"content",
";",
"$",
"this",
"->",
"meta",
"=",
"$",
"meta",
";",
"// Ensure local URLs are absolute",
"foreach",
"(",
"$",
"this",
"->",
"meta",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/\\burl\\b|.*_url\\b/'",
",",
"$",
"key",
")",
")",
"{",
"$",
"this",
"->",
"meta",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"builder",
"->",
"getUrl",
"(",
"$",
"value",
")",
";",
"}",
"}",
"// Set target",
"$",
"this",
"->",
"setTarget",
"(",
"$",
"file",
")",
";",
"// Pagination enabled",
"$",
"this",
"->",
"paginate",
"=",
"isset",
"(",
"$",
"this",
"->",
"meta",
"[",
"'paginate'",
"]",
")",
";",
"// Get parent page",
"if",
"(",
"$",
"root",
"=",
"dirname",
"(",
"dirname",
"(",
"$",
"this",
"->",
"target",
")",
")",
")",
"{",
"if",
"(",
"$",
"root",
"!==",
"DIRECTORY_SEPARATOR",
")",
"{",
"$",
"this",
"->",
"parentId",
"=",
"ltrim",
"(",
"$",
"root",
",",
"'/'",
")",
";",
"}",
"}",
"// Set URL",
"$",
"this",
"->",
"url",
"=",
"'/'",
".",
"trim",
"(",
"str_replace",
"(",
"[",
"DIRECTORY_SEPARATOR",
",",
"'//'",
"]",
",",
"[",
"'/'",
",",
"'/'",
"]",
",",
"$",
"this",
"->",
"target",
")",
",",
"'/'",
")",
";",
"// Remove \"index.html\" from the end, this provides a cleaner URL",
"if",
"(",
"substr",
"(",
"$",
"this",
"->",
"url",
",",
"-",
"10",
")",
"===",
"'index.html'",
")",
"{",
"$",
"this",
"->",
"url",
"=",
"substr",
"(",
"$",
"this",
"->",
"url",
",",
"0",
",",
"-",
"10",
")",
";",
"}",
"// Set basic values",
"$",
"this",
"->",
"id",
"=",
"trim",
"(",
"$",
"this",
"->",
"url",
",",
"'/'",
")",
"?",
":",
"'root'",
";",
"$",
"this",
"->",
"title",
"=",
"$",
"this",
"->",
"get",
"(",
"'title'",
")",
";",
"$",
"this",
"->",
"url",
"=",
"$",
"this",
"->",
"builder",
"->",
"getUrl",
"(",
"$",
"this",
"->",
"url",
")",
";",
"// Set Description",
"if",
"(",
"$",
"this",
"->",
"has",
"(",
"'description'",
")",
")",
"{",
"$",
"this",
"->",
"description",
"=",
"$",
"this",
"->",
"get",
"(",
"'description'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"description",
"=",
"$",
"this",
"->",
"getDescription",
"(",
")",
";",
"}",
"}"
] | Load and parse content from file.
@param SplFileInfo $file
@return void | [
"Load",
"and",
"parse",
"content",
"from",
"file",
"."
] | ea60e037d92398d7c146eb2349735d5692e3c48c | https://github.com/Torann/skosh-generator/blob/ea60e037d92398d7c146eb2349735d5692e3c48c/src/Content/Content.php#L98-L170 | train |
Torann/skosh-generator | src/Content/Content.php | Content.splitContentMeta | protected function splitContentMeta($data)
{
// Remove Byte Order Mark (BOM)
$data = preg_replace('/\x{EF}\x{BB}\x{BF}/', '', $data);
// Pattern for detecting a metadata separator (---)
// Using ^ and $ in this way requires the PCRE_MULTILINE modifier
$pattern = '/' // Pattern start
. '^' // Beginning of line
. '---' // Literal ---
. '\\s*' // Zero or more whitespace characters
. '$' // End of line
. '/m'; // Pattern end, PCRE_MULTILINE modifier
// Separate the meta-data from the content
$data = trim($data);
if (
(substr($data, 0, 3) === '---') &&
(preg_match($pattern, $data, $matches, PREG_OFFSET_CAPTURE, 3))
) {
$pos = $matches[0][1];
$len = strlen($matches[0][0]);
$meta = trim(substr($data, 3, $pos - 3));
$content = trim(substr($data, $pos + $len));
}
else {
$content = $data;
$meta = null;
}
return [$content, $meta];
} | php | protected function splitContentMeta($data)
{
// Remove Byte Order Mark (BOM)
$data = preg_replace('/\x{EF}\x{BB}\x{BF}/', '', $data);
// Pattern for detecting a metadata separator (---)
// Using ^ and $ in this way requires the PCRE_MULTILINE modifier
$pattern = '/' // Pattern start
. '^' // Beginning of line
. '---' // Literal ---
. '\\s*' // Zero or more whitespace characters
. '$' // End of line
. '/m'; // Pattern end, PCRE_MULTILINE modifier
// Separate the meta-data from the content
$data = trim($data);
if (
(substr($data, 0, 3) === '---') &&
(preg_match($pattern, $data, $matches, PREG_OFFSET_CAPTURE, 3))
) {
$pos = $matches[0][1];
$len = strlen($matches[0][0]);
$meta = trim(substr($data, 3, $pos - 3));
$content = trim(substr($data, $pos + $len));
}
else {
$content = $data;
$meta = null;
}
return [$content, $meta];
} | [
"protected",
"function",
"splitContentMeta",
"(",
"$",
"data",
")",
"{",
"// Remove Byte Order Mark (BOM)",
"$",
"data",
"=",
"preg_replace",
"(",
"'/\\x{EF}\\x{BB}\\x{BF}/'",
",",
"''",
",",
"$",
"data",
")",
";",
"// Pattern for detecting a metadata separator (---)",
"// Using ^ and $ in this way requires the PCRE_MULTILINE modifier",
"$",
"pattern",
"=",
"'/'",
"// Pattern start",
".",
"'^'",
"// Beginning of line",
".",
"'---'",
"// Literal ---",
".",
"'\\\\s*'",
"// Zero or more whitespace characters",
".",
"'$'",
"// End of line",
".",
"'/m'",
";",
"// Pattern end, PCRE_MULTILINE modifier",
"// Separate the meta-data from the content",
"$",
"data",
"=",
"trim",
"(",
"$",
"data",
")",
";",
"if",
"(",
"(",
"substr",
"(",
"$",
"data",
",",
"0",
",",
"3",
")",
"===",
"'---'",
")",
"&&",
"(",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"data",
",",
"$",
"matches",
",",
"PREG_OFFSET_CAPTURE",
",",
"3",
")",
")",
")",
"{",
"$",
"pos",
"=",
"$",
"matches",
"[",
"0",
"]",
"[",
"1",
"]",
";",
"$",
"len",
"=",
"strlen",
"(",
"$",
"matches",
"[",
"0",
"]",
"[",
"0",
"]",
")",
";",
"$",
"meta",
"=",
"trim",
"(",
"substr",
"(",
"$",
"data",
",",
"3",
",",
"$",
"pos",
"-",
"3",
")",
")",
";",
"$",
"content",
"=",
"trim",
"(",
"substr",
"(",
"$",
"data",
",",
"$",
"pos",
"+",
"$",
"len",
")",
")",
";",
"}",
"else",
"{",
"$",
"content",
"=",
"$",
"data",
";",
"$",
"meta",
"=",
"null",
";",
"}",
"return",
"[",
"$",
"content",
",",
"$",
"meta",
"]",
";",
"}"
] | Parse metadata and content
@param string $data
@return array | [
"Parse",
"metadata",
"and",
"content"
] | ea60e037d92398d7c146eb2349735d5692e3c48c | https://github.com/Torann/skosh-generator/blob/ea60e037d92398d7c146eb2349735d5692e3c48c/src/Content/Content.php#L178-L211 | train |
Torann/skosh-generator | src/Content/Content.php | Content.setTarget | protected function setTarget(SplFileInfo $file)
{
// Page extension
$ext = $file->getExtension();
// Twig templates are HTML
if (!$this->has('template') || $this->get('template') === 'none') {
$targetExt = $ext;
}
else {
$targetExt = 'html';
}
// Get clean source path
$sourcePath = $this->getCleanPath($file->getRelativePathName());
// Replace source extension with that of the template
$this->target = substr($sourcePath, 0, -strlen($ext));
$this->target .= $targetExt;
} | php | protected function setTarget(SplFileInfo $file)
{
// Page extension
$ext = $file->getExtension();
// Twig templates are HTML
if (!$this->has('template') || $this->get('template') === 'none') {
$targetExt = $ext;
}
else {
$targetExt = 'html';
}
// Get clean source path
$sourcePath = $this->getCleanPath($file->getRelativePathName());
// Replace source extension with that of the template
$this->target = substr($sourcePath, 0, -strlen($ext));
$this->target .= $targetExt;
} | [
"protected",
"function",
"setTarget",
"(",
"SplFileInfo",
"$",
"file",
")",
"{",
"// Page extension",
"$",
"ext",
"=",
"$",
"file",
"->",
"getExtension",
"(",
")",
";",
"// Twig templates are HTML",
"if",
"(",
"!",
"$",
"this",
"->",
"has",
"(",
"'template'",
")",
"||",
"$",
"this",
"->",
"get",
"(",
"'template'",
")",
"===",
"'none'",
")",
"{",
"$",
"targetExt",
"=",
"$",
"ext",
";",
"}",
"else",
"{",
"$",
"targetExt",
"=",
"'html'",
";",
"}",
"// Get clean source path",
"$",
"sourcePath",
"=",
"$",
"this",
"->",
"getCleanPath",
"(",
"$",
"file",
"->",
"getRelativePathName",
"(",
")",
")",
";",
"// Replace source extension with that of the template",
"$",
"this",
"->",
"target",
"=",
"substr",
"(",
"$",
"sourcePath",
",",
"0",
",",
"-",
"strlen",
"(",
"$",
"ext",
")",
")",
";",
"$",
"this",
"->",
"target",
".=",
"$",
"targetExt",
";",
"}"
] | Determine the target path.
@param SplFileInfo $file
@return string | [
"Determine",
"the",
"target",
"path",
"."
] | ea60e037d92398d7c146eb2349735d5692e3c48c | https://github.com/Torann/skosh-generator/blob/ea60e037d92398d7c146eb2349735d5692e3c48c/src/Content/Content.php#L232-L251 | train |
zhaoxianfang/tools | src/Symfony/Component/DependencyInjection/Definition.php | Definition.setMethodCalls | public function setMethodCalls(array $calls = array())
{
$this->calls = array();
foreach ($calls as $call) {
$this->addMethodCall($call[0], $call[1]);
}
return $this;
} | php | public function setMethodCalls(array $calls = array())
{
$this->calls = array();
foreach ($calls as $call) {
$this->addMethodCall($call[0], $call[1]);
}
return $this;
} | [
"public",
"function",
"setMethodCalls",
"(",
"array",
"$",
"calls",
"=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"calls",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"calls",
"as",
"$",
"call",
")",
"{",
"$",
"this",
"->",
"addMethodCall",
"(",
"$",
"call",
"[",
"0",
"]",
",",
"$",
"call",
"[",
"1",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Sets the methods to call after service initialization.
@return $this | [
"Sets",
"the",
"methods",
"to",
"call",
"after",
"service",
"initialization",
"."
] | d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7 | https://github.com/zhaoxianfang/tools/blob/d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7/src/Symfony/Component/DependencyInjection/Definition.php#L323-L331 | train |
zhaoxianfang/tools | src/Symfony/Component/DependencyInjection/Definition.php | Definition.addAutowiringType | public function addAutowiringType($type)
{
@trigger_error(sprintf('Autowiring-types are deprecated since Symfony 3.3 and will be removed in 4.0. Use aliases instead for "%s".', $type), E_USER_DEPRECATED);
$this->autowiringTypes[$type] = true;
return $this;
} | php | public function addAutowiringType($type)
{
@trigger_error(sprintf('Autowiring-types are deprecated since Symfony 3.3 and will be removed in 4.0. Use aliases instead for "%s".', $type), E_USER_DEPRECATED);
$this->autowiringTypes[$type] = true;
return $this;
} | [
"public",
"function",
"addAutowiringType",
"(",
"$",
"type",
")",
"{",
"@",
"trigger_error",
"(",
"sprintf",
"(",
"'Autowiring-types are deprecated since Symfony 3.3 and will be removed in 4.0. Use aliases instead for \"%s\".'",
",",
"$",
"type",
")",
",",
"E_USER_DEPRECATED",
")",
";",
"$",
"this",
"->",
"autowiringTypes",
"[",
"$",
"type",
"]",
"=",
"true",
";",
"return",
"$",
"this",
";",
"}"
] | Adds a type that will default to this definition.
@param string $type
@return $this
@deprecated since version 3.3, to be removed in 4.0. | [
"Adds",
"a",
"type",
"that",
"will",
"default",
"to",
"this",
"definition",
"."
] | d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7 | https://github.com/zhaoxianfang/tools/blob/d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7/src/Symfony/Component/DependencyInjection/Definition.php#L879-L886 | train |
zhaoxianfang/tools | src/Symfony/Component/DependencyInjection/Definition.php | Definition.hasAutowiringType | public function hasAutowiringType($type)
{
@trigger_error(sprintf('Autowiring-types are deprecated since Symfony 3.3 and will be removed in 4.0. Use aliases instead for "%s".', $type), E_USER_DEPRECATED);
return isset($this->autowiringTypes[$type]);
} | php | public function hasAutowiringType($type)
{
@trigger_error(sprintf('Autowiring-types are deprecated since Symfony 3.3 and will be removed in 4.0. Use aliases instead for "%s".', $type), E_USER_DEPRECATED);
return isset($this->autowiringTypes[$type]);
} | [
"public",
"function",
"hasAutowiringType",
"(",
"$",
"type",
")",
"{",
"@",
"trigger_error",
"(",
"sprintf",
"(",
"'Autowiring-types are deprecated since Symfony 3.3 and will be removed in 4.0. Use aliases instead for \"%s\".'",
",",
"$",
"type",
")",
",",
"E_USER_DEPRECATED",
")",
";",
"return",
"isset",
"(",
"$",
"this",
"->",
"autowiringTypes",
"[",
"$",
"type",
"]",
")",
";",
"}"
] | Will this definition default for the given type?
@param string $type
@return bool
@deprecated since version 3.3, to be removed in 4.0. | [
"Will",
"this",
"definition",
"default",
"for",
"the",
"given",
"type?"
] | d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7 | https://github.com/zhaoxianfang/tools/blob/d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7/src/Symfony/Component/DependencyInjection/Definition.php#L915-L920 | train |
stubbles/stubbles-peer | src/main/php/http/HttpResponse.php | HttpResponse.readHeader | private function readHeader(): self
{
if (null !== $this->statusLine) {
return $this;
}
do {
$this->parseStatusLine($this->socket->readLine());
$headers = '';
$line = '';
while (!$this->socket->eof() && Http::END_OF_LINE !== $line) {
$line = $this->socket->readLine() . Http::END_OF_LINE;
$headers .= $line;
}
$this->headers->append($headers);
} while ($this->requireContinue());
return $this;
} | php | private function readHeader(): self
{
if (null !== $this->statusLine) {
return $this;
}
do {
$this->parseStatusLine($this->socket->readLine());
$headers = '';
$line = '';
while (!$this->socket->eof() && Http::END_OF_LINE !== $line) {
$line = $this->socket->readLine() . Http::END_OF_LINE;
$headers .= $line;
}
$this->headers->append($headers);
} while ($this->requireContinue());
return $this;
} | [
"private",
"function",
"readHeader",
"(",
")",
":",
"self",
"{",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"statusLine",
")",
"{",
"return",
"$",
"this",
";",
"}",
"do",
"{",
"$",
"this",
"->",
"parseStatusLine",
"(",
"$",
"this",
"->",
"socket",
"->",
"readLine",
"(",
")",
")",
";",
"$",
"headers",
"=",
"''",
";",
"$",
"line",
"=",
"''",
";",
"while",
"(",
"!",
"$",
"this",
"->",
"socket",
"->",
"eof",
"(",
")",
"&&",
"Http",
"::",
"END_OF_LINE",
"!==",
"$",
"line",
")",
"{",
"$",
"line",
"=",
"$",
"this",
"->",
"socket",
"->",
"readLine",
"(",
")",
".",
"Http",
"::",
"END_OF_LINE",
";",
"$",
"headers",
".=",
"$",
"line",
";",
"}",
"$",
"this",
"->",
"headers",
"->",
"append",
"(",
"$",
"headers",
")",
";",
"}",
"while",
"(",
"$",
"this",
"->",
"requireContinue",
"(",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | reads response headers
@return \stubbles\peer\http\HttpResponse | [
"reads",
"response",
"headers"
] | dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc | https://github.com/stubbles/stubbles-peer/blob/dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc/src/main/php/http/HttpResponse.php#L173-L191 | train |
stubbles/stubbles-peer | src/main/php/http/HttpResponse.php | HttpResponse.parseStatusLine | private function parseStatusLine(string $statusLine)
{
$matches = [];
if (preg_match("=^(HTTP/\d+\.\d+) (\d{3}) ([^\r]*)=", $statusLine, $matches) == false) {
throw new ProtocolViolation(
'Received status line "' . addcslashes($statusLine, "\0..\37!\177..\377")
. '" does not match expected format "=^(HTTP/\d+\.\d+) (\d{3}) ([^\r]*)="'
);
}
$this->statusLine = $matches[0];
$this->version = HttpVersion::fromString($matches[1]);
$this->statusCode = (int) $matches[2];
$this->reasonPhrase = $matches[3];
} | php | private function parseStatusLine(string $statusLine)
{
$matches = [];
if (preg_match("=^(HTTP/\d+\.\d+) (\d{3}) ([^\r]*)=", $statusLine, $matches) == false) {
throw new ProtocolViolation(
'Received status line "' . addcslashes($statusLine, "\0..\37!\177..\377")
. '" does not match expected format "=^(HTTP/\d+\.\d+) (\d{3}) ([^\r]*)="'
);
}
$this->statusLine = $matches[0];
$this->version = HttpVersion::fromString($matches[1]);
$this->statusCode = (int) $matches[2];
$this->reasonPhrase = $matches[3];
} | [
"private",
"function",
"parseStatusLine",
"(",
"string",
"$",
"statusLine",
")",
"{",
"$",
"matches",
"=",
"[",
"]",
";",
"if",
"(",
"preg_match",
"(",
"\"=^(HTTP/\\d+\\.\\d+) (\\d{3}) ([^\\r]*)=\"",
",",
"$",
"statusLine",
",",
"$",
"matches",
")",
"==",
"false",
")",
"{",
"throw",
"new",
"ProtocolViolation",
"(",
"'Received status line \"'",
".",
"addcslashes",
"(",
"$",
"statusLine",
",",
"\"\\0..\\37!\\177..\\377\"",
")",
".",
"'\" does not match expected format \"=^(HTTP/\\d+\\.\\d+) (\\d{3}) ([^\\r]*)=\"'",
")",
";",
"}",
"$",
"this",
"->",
"statusLine",
"=",
"$",
"matches",
"[",
"0",
"]",
";",
"$",
"this",
"->",
"version",
"=",
"HttpVersion",
"::",
"fromString",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
";",
"$",
"this",
"->",
"statusCode",
"=",
"(",
"int",
")",
"$",
"matches",
"[",
"2",
"]",
";",
"$",
"this",
"->",
"reasonPhrase",
"=",
"$",
"matches",
"[",
"3",
"]",
";",
"}"
] | parses first line of response
@param string $statusLine first line of response
@throws ProtocolViolation when status line can not be parsed | [
"parses",
"first",
"line",
"of",
"response"
] | dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc | https://github.com/stubbles/stubbles-peer/blob/dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc/src/main/php/http/HttpResponse.php#L199-L213 | train |
stubbles/stubbles-peer | src/main/php/http/HttpResponse.php | HttpResponse.readBody | private function readBody(): self
{
if (null !== $this->body) {
return $this;
}
if ($this->headers->get('Transfer-Encoding') === 'chunked') {
$this->body = $this->readChunked();
} else {
$this->body = $this->readDefault((int) $this->headers->get('Content-Length', 4096));
}
return $this;
} | php | private function readBody(): self
{
if (null !== $this->body) {
return $this;
}
if ($this->headers->get('Transfer-Encoding') === 'chunked') {
$this->body = $this->readChunked();
} else {
$this->body = $this->readDefault((int) $this->headers->get('Content-Length', 4096));
}
return $this;
} | [
"private",
"function",
"readBody",
"(",
")",
":",
"self",
"{",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"body",
")",
"{",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"headers",
"->",
"get",
"(",
"'Transfer-Encoding'",
")",
"===",
"'chunked'",
")",
"{",
"$",
"this",
"->",
"body",
"=",
"$",
"this",
"->",
"readChunked",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"body",
"=",
"$",
"this",
"->",
"readDefault",
"(",
"(",
"int",
")",
"$",
"this",
"->",
"headers",
"->",
"get",
"(",
"'Content-Length'",
",",
"4096",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | reads the response body
@return \stubbles\peer\http\HttpResponse | [
"reads",
"the",
"response",
"body"
] | dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc | https://github.com/stubbles/stubbles-peer/blob/dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc/src/main/php/http/HttpResponse.php#L230-L243 | train |
stubbles/stubbles-peer | src/main/php/http/HttpResponse.php | HttpResponse.readChunked | private function readChunked(): string
{
$readLength = 0;
$chunksize = null;
$extension = null;
$body = '';
sscanf($this->socket->readLine(), '%x%s', $chunksize, $extension);
while (0 < $chunksize) {
$data = $this->socket->read($chunksize + 4);
$body .= rtrim($data);
$readLength += $chunksize;
sscanf($this->socket->readLine(), '%x', $chunksize);
}
$this->headers->put('Content-Length', $readLength);
$this->headers->remove('Transfer-Encoding');
return $body;
} | php | private function readChunked(): string
{
$readLength = 0;
$chunksize = null;
$extension = null;
$body = '';
sscanf($this->socket->readLine(), '%x%s', $chunksize, $extension);
while (0 < $chunksize) {
$data = $this->socket->read($chunksize + 4);
$body .= rtrim($data);
$readLength += $chunksize;
sscanf($this->socket->readLine(), '%x', $chunksize);
}
$this->headers->put('Content-Length', $readLength);
$this->headers->remove('Transfer-Encoding');
return $body;
} | [
"private",
"function",
"readChunked",
"(",
")",
":",
"string",
"{",
"$",
"readLength",
"=",
"0",
";",
"$",
"chunksize",
"=",
"null",
";",
"$",
"extension",
"=",
"null",
";",
"$",
"body",
"=",
"''",
";",
"sscanf",
"(",
"$",
"this",
"->",
"socket",
"->",
"readLine",
"(",
")",
",",
"'%x%s'",
",",
"$",
"chunksize",
",",
"$",
"extension",
")",
";",
"while",
"(",
"0",
"<",
"$",
"chunksize",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"socket",
"->",
"read",
"(",
"$",
"chunksize",
"+",
"4",
")",
";",
"$",
"body",
".=",
"rtrim",
"(",
"$",
"data",
")",
";",
"$",
"readLength",
"+=",
"$",
"chunksize",
";",
"sscanf",
"(",
"$",
"this",
"->",
"socket",
"->",
"readLine",
"(",
")",
",",
"'%x'",
",",
"$",
"chunksize",
")",
";",
"}",
"$",
"this",
"->",
"headers",
"->",
"put",
"(",
"'Content-Length'",
",",
"$",
"readLength",
")",
";",
"$",
"this",
"->",
"headers",
"->",
"remove",
"(",
"'Transfer-Encoding'",
")",
";",
"return",
"$",
"body",
";",
"}"
] | helper method to read chunked response body
The method implements the pseudo code given in RFC 2616 section 19.4.6:
Introduction of Transfer-Encoding. Chunk extensions are ignored.
@return string | [
"helper",
"method",
"to",
"read",
"chunked",
"response",
"body"
] | dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc | https://github.com/stubbles/stubbles-peer/blob/dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc/src/main/php/http/HttpResponse.php#L253-L270 | train |
stubbles/stubbles-peer | src/main/php/http/HttpResponse.php | HttpResponse.readDefault | private function readDefault(int $readLength): string
{
$body = $buffer = '';
$read = 0;
while ($read < $readLength && !$this->socket->eof()) {
$buffer = $this->socket->read($readLength);
$read += strlen($buffer);
$body .= $buffer;
}
return $body;
} | php | private function readDefault(int $readLength): string
{
$body = $buffer = '';
$read = 0;
while ($read < $readLength && !$this->socket->eof()) {
$buffer = $this->socket->read($readLength);
$read += strlen($buffer);
$body .= $buffer;
}
return $body;
} | [
"private",
"function",
"readDefault",
"(",
"int",
"$",
"readLength",
")",
":",
"string",
"{",
"$",
"body",
"=",
"$",
"buffer",
"=",
"''",
";",
"$",
"read",
"=",
"0",
";",
"while",
"(",
"$",
"read",
"<",
"$",
"readLength",
"&&",
"!",
"$",
"this",
"->",
"socket",
"->",
"eof",
"(",
")",
")",
"{",
"$",
"buffer",
"=",
"$",
"this",
"->",
"socket",
"->",
"read",
"(",
"$",
"readLength",
")",
";",
"$",
"read",
"+=",
"strlen",
"(",
"$",
"buffer",
")",
";",
"$",
"body",
".=",
"$",
"buffer",
";",
"}",
"return",
"$",
"body",
";",
"}"
] | helper method for default reading of response body
@param int $readLength expected length of response body
@return string | [
"helper",
"method",
"for",
"default",
"reading",
"of",
"response",
"body"
] | dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc | https://github.com/stubbles/stubbles-peer/blob/dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc/src/main/php/http/HttpResponse.php#L278-L289 | train |
OpenConext-Attic/OpenConext-engineblock-metadata | src/MetadataRepository/DoctrineMetadataRepository.php | DoctrineMetadataRepository.findReservedSchacHomeOrganizations | public function findReservedSchacHomeOrganizations()
{
$queryBuilder = $this->idpRepository
->createQueryBuilder('role')
->select('role.schacHomeOrganization')
->distinct()
->orderBy('role.schacHomeOrganization');
$this->compositeFilter->toQueryBuilder($queryBuilder, $this->idpRepository->getClassName());
return $queryBuilder
->getQuery()
->execute();
} | php | public function findReservedSchacHomeOrganizations()
{
$queryBuilder = $this->idpRepository
->createQueryBuilder('role')
->select('role.schacHomeOrganization')
->distinct()
->orderBy('role.schacHomeOrganization');
$this->compositeFilter->toQueryBuilder($queryBuilder, $this->idpRepository->getClassName());
return $queryBuilder
->getQuery()
->execute();
} | [
"public",
"function",
"findReservedSchacHomeOrganizations",
"(",
")",
"{",
"$",
"queryBuilder",
"=",
"$",
"this",
"->",
"idpRepository",
"->",
"createQueryBuilder",
"(",
"'role'",
")",
"->",
"select",
"(",
"'role.schacHomeOrganization'",
")",
"->",
"distinct",
"(",
")",
"->",
"orderBy",
"(",
"'role.schacHomeOrganization'",
")",
";",
"$",
"this",
"->",
"compositeFilter",
"->",
"toQueryBuilder",
"(",
"$",
"queryBuilder",
",",
"$",
"this",
"->",
"idpRepository",
"->",
"getClassName",
"(",
")",
")",
";",
"return",
"$",
"queryBuilder",
"->",
"getQuery",
"(",
")",
"->",
"execute",
"(",
")",
";",
"}"
] | Find all SchacHomeOrganizations that are reserved by Identity Providers.
@return string[] | [
"Find",
"all",
"SchacHomeOrganizations",
"that",
"are",
"reserved",
"by",
"Identity",
"Providers",
"."
] | 236e2f52ef9cf28e71404544a1c4388f63ee535d | https://github.com/OpenConext-Attic/OpenConext-engineblock-metadata/blob/236e2f52ef9cf28e71404544a1c4388f63ee535d/src/MetadataRepository/DoctrineMetadataRepository.php#L93-L106 | train |
OpenConext-Attic/OpenConext-engineblock-metadata | src/MetadataRepository/DoctrineMetadataRepository.php | DoctrineMetadataRepository.synchronize | public function synchronize(array $roles)
{
$result = new SynchronizationResult();
$repository = $this;
$this->entityManager->transactional(function (EntityManager $em) use ($roles, $repository, $result) {
$idpsToBeRemoved = $repository->findAllIdentityProviderEntityIds();
$spsToBeRemoved = $repository->findAllServiceProviderEntityIds();
foreach ($roles as $role) {
if ($role instanceof IdentityProvider) {
// Does the IDP already exist in the database?
$index = array_search($role->entityId, $idpsToBeRemoved);
if ($index === false) {
// The IDP is new: create it.
$em->persist($role);
$result->createdIdentityProviders[] = $role->entityId;
} else {
// Remove from the list of entity ids so it won't get deleted later on.
unset($idpsToBeRemoved[$index]);
// The IDP already exists: update it.
$identityProvider = $repository->findIdentityProviderByEntityId($role->entityId);
$role->id = $identityProvider->id;
$em->persist($em->merge($role));
$result->updatedIdentityProviders[] = $role->entityId;
}
continue;
}
if ($role instanceof ServiceProvider) {
// Does the SP already exist in the database?
$index = array_search($role->entityId, $spsToBeRemoved);
if ($index === false) {
// The SP is new: create it.
$em->persist($role);
$result->createdServiceProviders[] = $role->entityId;
} else {
// Remove from the list of entity ids so it won't get deleted later on.
unset($spsToBeRemoved[$index]);
// The SP already exists: update it.
$serviceProvider = $repository->findServiceProviderByEntityId($role->entityId);
$role->id = $serviceProvider->id;
$em->persist($em->merge($role));
$result->updatedServiceProviders[] = $role->entityId;
}
continue;
}
throw new RuntimeException('Unsupported role provided to synchonization: ' . var_export($role, true));
}
if ($idpsToBeRemoved) {
$this->deleteRolesByEntityIds($this->idpRepository, $idpsToBeRemoved);
$result->removedIdentityProviders = $idpsToBeRemoved;
}
if ($spsToBeRemoved) {
$this->deleteRolesByEntityIds($this->spRepository, $spsToBeRemoved);
$result->removedServiceProviders = $spsToBeRemoved;
}
});
return $result;
} | php | public function synchronize(array $roles)
{
$result = new SynchronizationResult();
$repository = $this;
$this->entityManager->transactional(function (EntityManager $em) use ($roles, $repository, $result) {
$idpsToBeRemoved = $repository->findAllIdentityProviderEntityIds();
$spsToBeRemoved = $repository->findAllServiceProviderEntityIds();
foreach ($roles as $role) {
if ($role instanceof IdentityProvider) {
// Does the IDP already exist in the database?
$index = array_search($role->entityId, $idpsToBeRemoved);
if ($index === false) {
// The IDP is new: create it.
$em->persist($role);
$result->createdIdentityProviders[] = $role->entityId;
} else {
// Remove from the list of entity ids so it won't get deleted later on.
unset($idpsToBeRemoved[$index]);
// The IDP already exists: update it.
$identityProvider = $repository->findIdentityProviderByEntityId($role->entityId);
$role->id = $identityProvider->id;
$em->persist($em->merge($role));
$result->updatedIdentityProviders[] = $role->entityId;
}
continue;
}
if ($role instanceof ServiceProvider) {
// Does the SP already exist in the database?
$index = array_search($role->entityId, $spsToBeRemoved);
if ($index === false) {
// The SP is new: create it.
$em->persist($role);
$result->createdServiceProviders[] = $role->entityId;
} else {
// Remove from the list of entity ids so it won't get deleted later on.
unset($spsToBeRemoved[$index]);
// The SP already exists: update it.
$serviceProvider = $repository->findServiceProviderByEntityId($role->entityId);
$role->id = $serviceProvider->id;
$em->persist($em->merge($role));
$result->updatedServiceProviders[] = $role->entityId;
}
continue;
}
throw new RuntimeException('Unsupported role provided to synchonization: ' . var_export($role, true));
}
if ($idpsToBeRemoved) {
$this->deleteRolesByEntityIds($this->idpRepository, $idpsToBeRemoved);
$result->removedIdentityProviders = $idpsToBeRemoved;
}
if ($spsToBeRemoved) {
$this->deleteRolesByEntityIds($this->spRepository, $spsToBeRemoved);
$result->removedServiceProviders = $spsToBeRemoved;
}
});
return $result;
} | [
"public",
"function",
"synchronize",
"(",
"array",
"$",
"roles",
")",
"{",
"$",
"result",
"=",
"new",
"SynchronizationResult",
"(",
")",
";",
"$",
"repository",
"=",
"$",
"this",
";",
"$",
"this",
"->",
"entityManager",
"->",
"transactional",
"(",
"function",
"(",
"EntityManager",
"$",
"em",
")",
"use",
"(",
"$",
"roles",
",",
"$",
"repository",
",",
"$",
"result",
")",
"{",
"$",
"idpsToBeRemoved",
"=",
"$",
"repository",
"->",
"findAllIdentityProviderEntityIds",
"(",
")",
";",
"$",
"spsToBeRemoved",
"=",
"$",
"repository",
"->",
"findAllServiceProviderEntityIds",
"(",
")",
";",
"foreach",
"(",
"$",
"roles",
"as",
"$",
"role",
")",
"{",
"if",
"(",
"$",
"role",
"instanceof",
"IdentityProvider",
")",
"{",
"// Does the IDP already exist in the database?",
"$",
"index",
"=",
"array_search",
"(",
"$",
"role",
"->",
"entityId",
",",
"$",
"idpsToBeRemoved",
")",
";",
"if",
"(",
"$",
"index",
"===",
"false",
")",
"{",
"// The IDP is new: create it.",
"$",
"em",
"->",
"persist",
"(",
"$",
"role",
")",
";",
"$",
"result",
"->",
"createdIdentityProviders",
"[",
"]",
"=",
"$",
"role",
"->",
"entityId",
";",
"}",
"else",
"{",
"// Remove from the list of entity ids so it won't get deleted later on.",
"unset",
"(",
"$",
"idpsToBeRemoved",
"[",
"$",
"index",
"]",
")",
";",
"// The IDP already exists: update it.",
"$",
"identityProvider",
"=",
"$",
"repository",
"->",
"findIdentityProviderByEntityId",
"(",
"$",
"role",
"->",
"entityId",
")",
";",
"$",
"role",
"->",
"id",
"=",
"$",
"identityProvider",
"->",
"id",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"em",
"->",
"merge",
"(",
"$",
"role",
")",
")",
";",
"$",
"result",
"->",
"updatedIdentityProviders",
"[",
"]",
"=",
"$",
"role",
"->",
"entityId",
";",
"}",
"continue",
";",
"}",
"if",
"(",
"$",
"role",
"instanceof",
"ServiceProvider",
")",
"{",
"// Does the SP already exist in the database?",
"$",
"index",
"=",
"array_search",
"(",
"$",
"role",
"->",
"entityId",
",",
"$",
"spsToBeRemoved",
")",
";",
"if",
"(",
"$",
"index",
"===",
"false",
")",
"{",
"// The SP is new: create it.",
"$",
"em",
"->",
"persist",
"(",
"$",
"role",
")",
";",
"$",
"result",
"->",
"createdServiceProviders",
"[",
"]",
"=",
"$",
"role",
"->",
"entityId",
";",
"}",
"else",
"{",
"// Remove from the list of entity ids so it won't get deleted later on.",
"unset",
"(",
"$",
"spsToBeRemoved",
"[",
"$",
"index",
"]",
")",
";",
"// The SP already exists: update it.",
"$",
"serviceProvider",
"=",
"$",
"repository",
"->",
"findServiceProviderByEntityId",
"(",
"$",
"role",
"->",
"entityId",
")",
";",
"$",
"role",
"->",
"id",
"=",
"$",
"serviceProvider",
"->",
"id",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"em",
"->",
"merge",
"(",
"$",
"role",
")",
")",
";",
"$",
"result",
"->",
"updatedServiceProviders",
"[",
"]",
"=",
"$",
"role",
"->",
"entityId",
";",
"}",
"continue",
";",
"}",
"throw",
"new",
"RuntimeException",
"(",
"'Unsupported role provided to synchonization: '",
".",
"var_export",
"(",
"$",
"role",
",",
"true",
")",
")",
";",
"}",
"if",
"(",
"$",
"idpsToBeRemoved",
")",
"{",
"$",
"this",
"->",
"deleteRolesByEntityIds",
"(",
"$",
"this",
"->",
"idpRepository",
",",
"$",
"idpsToBeRemoved",
")",
";",
"$",
"result",
"->",
"removedIdentityProviders",
"=",
"$",
"idpsToBeRemoved",
";",
"}",
"if",
"(",
"$",
"spsToBeRemoved",
")",
"{",
"$",
"this",
"->",
"deleteRolesByEntityIds",
"(",
"$",
"this",
"->",
"spRepository",
",",
"$",
"spsToBeRemoved",
")",
";",
"$",
"result",
"->",
"removedServiceProviders",
"=",
"$",
"spsToBeRemoved",
";",
"}",
"}",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Synchronize the database with the provided roles.
Any roles (idp or sp) already existing the database are updated. New
roles are created. All identity- or service providers in the database
which are NOT in the provided roles are deleted at the end of the
synchronization process.
@param AbstractRole[] $roles
@return SynchronizationResult | [
"Synchronize",
"the",
"database",
"with",
"the",
"provided",
"roles",
"."
] | 236e2f52ef9cf28e71404544a1c4388f63ee535d | https://github.com/OpenConext-Attic/OpenConext-engineblock-metadata/blob/236e2f52ef9cf28e71404544a1c4388f63ee535d/src/MetadataRepository/DoctrineMetadataRepository.php#L244-L312 | train |
rollerworks/search-doctrine-orm | CachedDqlConditionGenerator.php | CachedDqlConditionGenerator.updateQuery | public function updateQuery(string $prependQuery = ' WHERE '): self
{
$whereCase = $this->getWhereClause($prependQuery);
if ($whereCase !== '') {
$this->query->setDQL($this->query->getDQL().$whereCase);
$this->query->setHint(
$this->conditionGenerator->getQueryHintName(),
$this->getQueryHintValue()
);
}
return $this;
} | php | public function updateQuery(string $prependQuery = ' WHERE '): self
{
$whereCase = $this->getWhereClause($prependQuery);
if ($whereCase !== '') {
$this->query->setDQL($this->query->getDQL().$whereCase);
$this->query->setHint(
$this->conditionGenerator->getQueryHintName(),
$this->getQueryHintValue()
);
}
return $this;
} | [
"public",
"function",
"updateQuery",
"(",
"string",
"$",
"prependQuery",
"=",
"' WHERE '",
")",
":",
"self",
"{",
"$",
"whereCase",
"=",
"$",
"this",
"->",
"getWhereClause",
"(",
"$",
"prependQuery",
")",
";",
"if",
"(",
"$",
"whereCase",
"!==",
"''",
")",
"{",
"$",
"this",
"->",
"query",
"->",
"setDQL",
"(",
"$",
"this",
"->",
"query",
"->",
"getDQL",
"(",
")",
".",
"$",
"whereCase",
")",
";",
"$",
"this",
"->",
"query",
"->",
"setHint",
"(",
"$",
"this",
"->",
"conditionGenerator",
"->",
"getQueryHintName",
"(",
")",
",",
"$",
"this",
"->",
"getQueryHintValue",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Updates the configured query object with the where-clause.
@param string $prependQuery Prepends this string to the where-clause
("WHERE" or "AND" for example) | [
"Updates",
"the",
"configured",
"query",
"object",
"with",
"the",
"where",
"-",
"clause",
"."
] | d4d7e9cfc6591d34e9d00f084c35f109f971ac4f | https://github.com/rollerworks/search-doctrine-orm/blob/d4d7e9cfc6591d34e9d00f084c35f109f971ac4f/CachedDqlConditionGenerator.php#L116-L129 | train |
rollerworks/search-doctrine-orm | CachedDqlConditionGenerator.php | CachedDqlConditionGenerator.getQueryHintValue | public function getQueryHintValue(): SqlConversionInfo
{
if (null === $this->whereClause) {
throw new BadMethodCallException(
'Unable to get query-hint value for ConditionGenerator. Call getWhereClause() before calling this method.'
);
}
return new SqlConversionInfo(
$this->nativePlatform,
$this->parameters,
$this->conditionGenerator->getFieldsConfig()->getFields()
);
} | php | public function getQueryHintValue(): SqlConversionInfo
{
if (null === $this->whereClause) {
throw new BadMethodCallException(
'Unable to get query-hint value for ConditionGenerator. Call getWhereClause() before calling this method.'
);
}
return new SqlConversionInfo(
$this->nativePlatform,
$this->parameters,
$this->conditionGenerator->getFieldsConfig()->getFields()
);
} | [
"public",
"function",
"getQueryHintValue",
"(",
")",
":",
"SqlConversionInfo",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"whereClause",
")",
"{",
"throw",
"new",
"BadMethodCallException",
"(",
"'Unable to get query-hint value for ConditionGenerator. Call getWhereClause() before calling this method.'",
")",
";",
"}",
"return",
"new",
"SqlConversionInfo",
"(",
"$",
"this",
"->",
"nativePlatform",
",",
"$",
"this",
"->",
"parameters",
",",
"$",
"this",
"->",
"conditionGenerator",
"->",
"getFieldsConfig",
"(",
")",
"->",
"getFields",
"(",
")",
")",
";",
"}"
] | Returns the Query-hint value for the final query object.
The Query hint is used for value-conversions.
@return SqlConversionInfo | [
"Returns",
"the",
"Query",
"-",
"hint",
"value",
"for",
"the",
"final",
"query",
"object",
"."
] | d4d7e9cfc6591d34e9d00f084c35f109f971ac4f | https://github.com/rollerworks/search-doctrine-orm/blob/d4d7e9cfc6591d34e9d00f084c35f109f971ac4f/CachedDqlConditionGenerator.php#L150-L163 | train |
karwana/php-messageformat | MessageFormat/MessageFormat.php | MessageFormat.get | public function get($message_key) {
$this->ensureLoaded();
// Check for a section key, which uses a period as a separator.
$separator = strpos($message_key, '.');
if (false === $separator) {
if (isset($this->messages[$message_key])) {
return $this->messages[$message_key];
}
if (isset($this->link)) {
return $this->link->get($message_key);
}
throw new \InvalidArgumentException('Unknown key "' . $message_key . '".');
}
$section = substr($message_key, 0, $separator);
$sub_key = substr($message_key, $separator + 1);
if (isset($this->messages[$section][$sub_key])) {
return $this->messages[$section][$sub_key];
}
if (isset($this->link)) {
return $this->link->get($message_key);
}
if (!isset($this->messages[$section])) {
throw new \InvalidArgumentException('Unknown section "' . $section . '".');
}
throw new \InvalidArgumentException('Unknown key "' . $sub_key . '" in section "' . $section . '".');
} | php | public function get($message_key) {
$this->ensureLoaded();
// Check for a section key, which uses a period as a separator.
$separator = strpos($message_key, '.');
if (false === $separator) {
if (isset($this->messages[$message_key])) {
return $this->messages[$message_key];
}
if (isset($this->link)) {
return $this->link->get($message_key);
}
throw new \InvalidArgumentException('Unknown key "' . $message_key . '".');
}
$section = substr($message_key, 0, $separator);
$sub_key = substr($message_key, $separator + 1);
if (isset($this->messages[$section][$sub_key])) {
return $this->messages[$section][$sub_key];
}
if (isset($this->link)) {
return $this->link->get($message_key);
}
if (!isset($this->messages[$section])) {
throw new \InvalidArgumentException('Unknown section "' . $section . '".');
}
throw new \InvalidArgumentException('Unknown key "' . $sub_key . '" in section "' . $section . '".');
} | [
"public",
"function",
"get",
"(",
"$",
"message_key",
")",
"{",
"$",
"this",
"->",
"ensureLoaded",
"(",
")",
";",
"// Check for a section key, which uses a period as a separator.",
"$",
"separator",
"=",
"strpos",
"(",
"$",
"message_key",
",",
"'.'",
")",
";",
"if",
"(",
"false",
"===",
"$",
"separator",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"messages",
"[",
"$",
"message_key",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"messages",
"[",
"$",
"message_key",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"link",
")",
")",
"{",
"return",
"$",
"this",
"->",
"link",
"->",
"get",
"(",
"$",
"message_key",
")",
";",
"}",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Unknown key \"'",
".",
"$",
"message_key",
".",
"'\".'",
")",
";",
"}",
"$",
"section",
"=",
"substr",
"(",
"$",
"message_key",
",",
"0",
",",
"$",
"separator",
")",
";",
"$",
"sub_key",
"=",
"substr",
"(",
"$",
"message_key",
",",
"$",
"separator",
"+",
"1",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"messages",
"[",
"$",
"section",
"]",
"[",
"$",
"sub_key",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"messages",
"[",
"$",
"section",
"]",
"[",
"$",
"sub_key",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"link",
")",
")",
"{",
"return",
"$",
"this",
"->",
"link",
"->",
"get",
"(",
"$",
"message_key",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"messages",
"[",
"$",
"section",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Unknown section \"'",
".",
"$",
"section",
".",
"'\".'",
")",
";",
"}",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Unknown key \"'",
".",
"$",
"sub_key",
".",
"'\" in section \"'",
".",
"$",
"section",
".",
"'\".'",
")",
";",
"}"
] | Gets the raw value of a message.
@param string $message_key
@return string | [
"Gets",
"the",
"raw",
"value",
"of",
"a",
"message",
"."
] | bf6a25ffb6ad99d1a67bdaa6b8ab029e6fa30e8f | https://github.com/karwana/php-messageformat/blob/bf6a25ffb6ad99d1a67bdaa6b8ab029e6fa30e8f/MessageFormat/MessageFormat.php#L142-L175 | train |
karwana/php-messageformat | MessageFormat/MessageFormat.php | MessageFormat.format | public function format($message_key, $args) {
return \MessageFormatter::formatMessage($this->locale, $this->get($message_key), $args);
} | php | public function format($message_key, $args) {
return \MessageFormatter::formatMessage($this->locale, $this->get($message_key), $args);
} | [
"public",
"function",
"format",
"(",
"$",
"message_key",
",",
"$",
"args",
")",
"{",
"return",
"\\",
"MessageFormatter",
"::",
"formatMessage",
"(",
"$",
"this",
"->",
"locale",
",",
"$",
"this",
"->",
"get",
"(",
"$",
"message_key",
")",
",",
"$",
"args",
")",
";",
"}"
] | Gets the formatted value of a message.
@param string $message_key
@param array $args
@return string | [
"Gets",
"the",
"formatted",
"value",
"of",
"a",
"message",
"."
] | bf6a25ffb6ad99d1a67bdaa6b8ab029e6fa30e8f | https://github.com/karwana/php-messageformat/blob/bf6a25ffb6ad99d1a67bdaa6b8ab029e6fa30e8f/MessageFormat/MessageFormat.php#L186-L188 | train |
SlaxWeb/View | src/AbstractLoader.php | AbstractLoader.setTemplate | public function setTemplate(string $template): self
{
$this->template = $template;
$this->logger->debug("Template file set to loader.", ["template" => $this->template]);
return $this;
} | php | public function setTemplate(string $template): self
{
$this->template = $template;
$this->logger->debug("Template file set to loader.", ["template" => $this->template]);
return $this;
} | [
"public",
"function",
"setTemplate",
"(",
"string",
"$",
"template",
")",
":",
"self",
"{",
"$",
"this",
"->",
"template",
"=",
"$",
"template",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"\"Template file set to loader.\"",
",",
"[",
"\"template\"",
"=>",
"$",
"this",
"->",
"template",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set the template
Sets the template filename.
@param string $template Name of the template file
@return self | [
"Set",
"the",
"template"
] | f5dac7c5c7466a0ecd417f22c9da1308b7ce2eac | https://github.com/SlaxWeb/View/blob/f5dac7c5c7466a0ecd417f22c9da1308b7ce2eac/src/AbstractLoader.php#L121-L126 | train |
SlaxWeb/View | src/AbstractLoader.php | AbstractLoader.setTemplateDir | public function setTemplateDir(string $templateDir): self
{
$this->templateDir = rtrim($templateDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
$this->logger->debug("Template directory set to loader." , ["templateDir" => $this->templateDir]);
return $this;
} | php | public function setTemplateDir(string $templateDir): self
{
$this->templateDir = rtrim($templateDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
$this->logger->debug("Template directory set to loader." , ["templateDir" => $this->templateDir]);
return $this;
} | [
"public",
"function",
"setTemplateDir",
"(",
"string",
"$",
"templateDir",
")",
":",
"self",
"{",
"$",
"this",
"->",
"templateDir",
"=",
"rtrim",
"(",
"$",
"templateDir",
",",
"DIRECTORY_SEPARATOR",
")",
".",
"DIRECTORY_SEPARATOR",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"\"Template directory set to loader.\"",
",",
"[",
"\"templateDir\"",
"=>",
"$",
"this",
"->",
"templateDir",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set the template directory
Sets the template directory name.
@param string $templateDir Name of the template directory
@return self | [
"Set",
"the",
"template",
"directory"
] | f5dac7c5c7466a0ecd417f22c9da1308b7ce2eac | https://github.com/SlaxWeb/View/blob/f5dac7c5c7466a0ecd417f22c9da1308b7ce2eac/src/AbstractLoader.php#L136-L141 | train |
OpenConext/Stepup-bundle | src/Request/RequestId.php | RequestId.set | public function set($requestId, $allowOverwrite = false)
{
if ($this->requestId !== null && !$allowOverwrite) {
throw new \LogicException('May not overwrite request ID.');
}
$this->requestId = $requestId;
} | php | public function set($requestId, $allowOverwrite = false)
{
if ($this->requestId !== null && !$allowOverwrite) {
throw new \LogicException('May not overwrite request ID.');
}
$this->requestId = $requestId;
} | [
"public",
"function",
"set",
"(",
"$",
"requestId",
",",
"$",
"allowOverwrite",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"requestId",
"!==",
"null",
"&&",
"!",
"$",
"allowOverwrite",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'May not overwrite request ID.'",
")",
";",
"}",
"$",
"this",
"->",
"requestId",
"=",
"$",
"requestId",
";",
"}"
] | We allow overwriting the RequestId so that we can inject a RequestId from a header when log statements already
have been made - which would cause an exception otherwise. The use-case here is the Stepup-Middleware
application, this application receives API-calls, but by then log messages have already been written.
However, for the sake of correlation we do want to use the log to show the correct request_id when actually
handling the request.
@param string $requestId
@param bool $allowOverwrite | [
"We",
"allow",
"overwriting",
"the",
"RequestId",
"so",
"that",
"we",
"can",
"inject",
"a",
"RequestId",
"from",
"a",
"header",
"when",
"log",
"statements",
"already",
"have",
"been",
"made",
"-",
"which",
"would",
"cause",
"an",
"exception",
"otherwise",
".",
"The",
"use",
"-",
"case",
"here",
"is",
"the",
"Stepup",
"-",
"Middleware",
"application",
"this",
"application",
"receives",
"API",
"-",
"calls",
"but",
"by",
"then",
"log",
"messages",
"have",
"already",
"been",
"written",
".",
"However",
"for",
"the",
"sake",
"of",
"correlation",
"we",
"do",
"want",
"to",
"use",
"the",
"log",
"to",
"show",
"the",
"correct",
"request_id",
"when",
"actually",
"handling",
"the",
"request",
"."
] | 94178ddb421889df9e068109293a8da880793ed2 | https://github.com/OpenConext/Stepup-bundle/blob/94178ddb421889df9e068109293a8da880793ed2/src/Request/RequestId.php#L70-L77 | train |
fridge-project/dbal | src/Fridge/DBAL/Schema/Diff/SchemaDiff.php | SchemaDiff.hasTableDifference | private function hasTableDifference()
{
return !empty($this->createdTables) || !empty($this->alteredTables) || !empty($this->droppedTables);
} | php | private function hasTableDifference()
{
return !empty($this->createdTables) || !empty($this->alteredTables) || !empty($this->droppedTables);
} | [
"private",
"function",
"hasTableDifference",
"(",
")",
"{",
"return",
"!",
"empty",
"(",
"$",
"this",
"->",
"createdTables",
")",
"||",
"!",
"empty",
"(",
"$",
"this",
"->",
"alteredTables",
")",
"||",
"!",
"empty",
"(",
"$",
"this",
"->",
"droppedTables",
")",
";",
"}"
] | Checks if the schema diff has table difference.
@return boolean TRUE if the schema diff has table difference else FALSE. | [
"Checks",
"if",
"the",
"schema",
"diff",
"has",
"table",
"difference",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Schema/Diff/SchemaDiff.php#L178-L181 | train |
freialib/hlin.security | src/Protocol.php | Protocol.matches | function matches($entity, array $context = null, $attribute = null) {
// cycle though acceptable entities
foreach ($this->entities as $name) {
// found an entity
if ($name === $entity) {
if ($this->parameters !== null) {
// we check if every paramter registered for this permission
// definition is set in the current test
foreach ($this->parameters as $key => $values) {
// we assume it doesn't match; ie. deny by default
$match = false;
// we get the value for the paramter definition, or null
$param_value = isset($context[$key]) ? $context[$key] : null;
// if we got NULL, it means the value wasn't set so we
// fail the test. All paramters in the definition must
// match, to at least one allowed value
if ($param_value !== null) {
// if it matched we go over the values in the
// definition
foreach ($values as $value) {
// ... and check with the value we got
if ($value === $param_value) {
// we found a match
$match = true;
// break out of the values loop, but we
// still need to continue check the rest of
// the paramters in the definition
break;
}
}
}
else { # parameter is not set
// we fail the match
return false;
}
// if we fail to match even 1 paramter then we fail the
// match for the definition. All paramters must match
// with at least one value
if ($match == false) {
return false;
}
}
}
else if ( ! empty($context) && ! $this->all_parameters) {
// context requires paramters but rights only give access
// to non-paramters; the resolution is that it's not allowed
// unless the all_parameters flag was passed when creating
// the protocol
return false;
}
// every paramter matched to at least one value. Now we check if
// we need a object check
if ($attribute !== null) {
$match = false;
// if we do we go though all objects and check with the
// test object
// do we actually have anything to test?
if ($this->attributes === null) {
return false;
}
foreach ($this->attributes as $attr) {
if ($attr === $attribute) {
// match found
$match = true;
// no reason to go on
break;
}
}
// we return the results of our search
return $match;
}
else { # no object defintion
return true;
}
}
}
// the permission doesn't apply to the definition in question
return false;
} | php | function matches($entity, array $context = null, $attribute = null) {
// cycle though acceptable entities
foreach ($this->entities as $name) {
// found an entity
if ($name === $entity) {
if ($this->parameters !== null) {
// we check if every paramter registered for this permission
// definition is set in the current test
foreach ($this->parameters as $key => $values) {
// we assume it doesn't match; ie. deny by default
$match = false;
// we get the value for the paramter definition, or null
$param_value = isset($context[$key]) ? $context[$key] : null;
// if we got NULL, it means the value wasn't set so we
// fail the test. All paramters in the definition must
// match, to at least one allowed value
if ($param_value !== null) {
// if it matched we go over the values in the
// definition
foreach ($values as $value) {
// ... and check with the value we got
if ($value === $param_value) {
// we found a match
$match = true;
// break out of the values loop, but we
// still need to continue check the rest of
// the paramters in the definition
break;
}
}
}
else { # parameter is not set
// we fail the match
return false;
}
// if we fail to match even 1 paramter then we fail the
// match for the definition. All paramters must match
// with at least one value
if ($match == false) {
return false;
}
}
}
else if ( ! empty($context) && ! $this->all_parameters) {
// context requires paramters but rights only give access
// to non-paramters; the resolution is that it's not allowed
// unless the all_parameters flag was passed when creating
// the protocol
return false;
}
// every paramter matched to at least one value. Now we check if
// we need a object check
if ($attribute !== null) {
$match = false;
// if we do we go though all objects and check with the
// test object
// do we actually have anything to test?
if ($this->attributes === null) {
return false;
}
foreach ($this->attributes as $attr) {
if ($attr === $attribute) {
// match found
$match = true;
// no reason to go on
break;
}
}
// we return the results of our search
return $match;
}
else { # no object defintion
return true;
}
}
}
// the permission doesn't apply to the definition in question
return false;
} | [
"function",
"matches",
"(",
"$",
"entity",
",",
"array",
"$",
"context",
"=",
"null",
",",
"$",
"attribute",
"=",
"null",
")",
"{",
"// cycle though acceptable entities",
"foreach",
"(",
"$",
"this",
"->",
"entities",
"as",
"$",
"name",
")",
"{",
"// found an entity",
"if",
"(",
"$",
"name",
"===",
"$",
"entity",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"parameters",
"!==",
"null",
")",
"{",
"// we check if every paramter registered for this permission",
"// definition is set in the current test",
"foreach",
"(",
"$",
"this",
"->",
"parameters",
"as",
"$",
"key",
"=>",
"$",
"values",
")",
"{",
"// we assume it doesn't match; ie. deny by default",
"$",
"match",
"=",
"false",
";",
"// we get the value for the paramter definition, or null",
"$",
"param_value",
"=",
"isset",
"(",
"$",
"context",
"[",
"$",
"key",
"]",
")",
"?",
"$",
"context",
"[",
"$",
"key",
"]",
":",
"null",
";",
"// if we got NULL, it means the value wasn't set so we",
"// fail the test. All paramters in the definition must",
"// match, to at least one allowed value",
"if",
"(",
"$",
"param_value",
"!==",
"null",
")",
"{",
"// if it matched we go over the values in the",
"// definition",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"// ... and check with the value we got",
"if",
"(",
"$",
"value",
"===",
"$",
"param_value",
")",
"{",
"// we found a match",
"$",
"match",
"=",
"true",
";",
"// break out of the values loop, but we",
"// still need to continue check the rest of",
"// the paramters in the definition",
"break",
";",
"}",
"}",
"}",
"else",
"{",
"# parameter is not set",
"// we fail the match",
"return",
"false",
";",
"}",
"// if we fail to match even 1 paramter then we fail the",
"// match for the definition. All paramters must match",
"// with at least one value",
"if",
"(",
"$",
"match",
"==",
"false",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
"else",
"if",
"(",
"!",
"empty",
"(",
"$",
"context",
")",
"&&",
"!",
"$",
"this",
"->",
"all_parameters",
")",
"{",
"// context requires paramters but rights only give access",
"// to non-paramters; the resolution is that it's not allowed",
"// unless the all_parameters flag was passed when creating",
"// the protocol",
"return",
"false",
";",
"}",
"// every paramter matched to at least one value. Now we check if",
"// we need a object check",
"if",
"(",
"$",
"attribute",
"!==",
"null",
")",
"{",
"$",
"match",
"=",
"false",
";",
"// if we do we go though all objects and check with the",
"// test object",
"// do we actually have anything to test?",
"if",
"(",
"$",
"this",
"->",
"attributes",
"===",
"null",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"attributes",
"as",
"$",
"attr",
")",
"{",
"if",
"(",
"$",
"attr",
"===",
"$",
"attribute",
")",
"{",
"// match found",
"$",
"match",
"=",
"true",
";",
"// no reason to go on",
"break",
";",
"}",
"}",
"// we return the results of our search",
"return",
"$",
"match",
";",
"}",
"else",
"{",
"# no object defintion",
"return",
"true",
";",
"}",
"}",
"}",
"// the permission doesn't apply to the definition in question",
"return",
"false",
";",
"}"
] | Relays are entities or routes, context is an array of values required for
the match, among these values "owner" is a special idenfication value.
For inpage elements you must provide attribute restrictions. An
attribute is an element on the page.
@return boolean | [
"Relays",
"are",
"entities",
"or",
"routes",
"context",
"is",
"an",
"array",
"of",
"values",
"required",
"for",
"the",
"match",
"among",
"these",
"values",
"owner",
"is",
"a",
"special",
"idenfication",
"value",
"."
] | 7f6aea6a7eb64f1095e176ddfad64008eed68b2e | https://github.com/freialib/hlin.security/blob/7f6aea6a7eb64f1095e176ddfad64008eed68b2e/src/Protocol.php#L28-L114 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/utils/SlugUtils.php | SlugUtils.isSlug | public static function isSlug($string, $with_slash=true)
{
if ($with_slash)
$match = '/'.self::SLUG_WITH_SLASH_MATCH.'/';
else
$match = '/'.self::SLUG_MATCH.'/';
return preg_match($match, $string) > 0;
} | php | public static function isSlug($string, $with_slash=true)
{
if ($with_slash)
$match = '/'.self::SLUG_WITH_SLASH_MATCH.'/';
else
$match = '/'.self::SLUG_MATCH.'/';
return preg_match($match, $string) > 0;
} | [
"public",
"static",
"function",
"isSlug",
"(",
"$",
"string",
",",
"$",
"with_slash",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"with_slash",
")",
"$",
"match",
"=",
"'/'",
".",
"self",
"::",
"SLUG_WITH_SLASH_MATCH",
".",
"'/'",
";",
"else",
"$",
"match",
"=",
"'/'",
".",
"self",
"::",
"SLUG_MATCH",
".",
"'/'",
";",
"return",
"preg_match",
"(",
"$",
"match",
",",
"$",
"string",
")",
">",
"0",
";",
"}"
] | Determines if the string given is a slug or not.
@param string $string The string to test
@param boolean $with_slash If true, then slashes will be allowed in the slug
@return boolean True if string is a slug | [
"Determines",
"if",
"the",
"string",
"given",
"is",
"a",
"slug",
"or",
"not",
"."
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/utils/SlugUtils.php#L215-L223 | train |
wb-crowdfusion/crowdfusion | system/core/classes/libraries/utils/SlugUtils.php | SlugUtils.createSlugFromCamelCase | public static function createSlugFromCamelCase($string, $allowSlashes = false)
{
$string = trim(preg_replace('/(([A-Z]|[0-9])[^A-Z])/',' $1',$string));
return SlugUtils::createSlug($string,$allowSlashes);
} | php | public static function createSlugFromCamelCase($string, $allowSlashes = false)
{
$string = trim(preg_replace('/(([A-Z]|[0-9])[^A-Z])/',' $1',$string));
return SlugUtils::createSlug($string,$allowSlashes);
} | [
"public",
"static",
"function",
"createSlugFromCamelCase",
"(",
"$",
"string",
",",
"$",
"allowSlashes",
"=",
"false",
")",
"{",
"$",
"string",
"=",
"trim",
"(",
"preg_replace",
"(",
"'/(([A-Z]|[0-9])[^A-Z])/'",
",",
"' $1'",
",",
"$",
"string",
")",
")",
";",
"return",
"SlugUtils",
"::",
"createSlug",
"(",
"$",
"string",
",",
"$",
"allowSlashes",
")",
";",
"}"
] | Creates a slug from the camel case text given. Adds space in between words starting with capital letters and acronyms.
@param string $string A bit of camel case text that we will generate our slug from.
@param boolean $allowSlashes If set to false, any slashes will be removed from the slug.
Default: false
@return string Our sluggified version of the {@link $string} param | [
"Creates",
"a",
"slug",
"from",
"the",
"camel",
"case",
"text",
"given",
".",
"Adds",
"space",
"in",
"between",
"words",
"starting",
"with",
"capital",
"letters",
"and",
"acronyms",
"."
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/utils/SlugUtils.php#L235-L240 | train |
lasallecms/lasallecms-l5-lasallecmsemail-pkg | src/Processing/BaseInboundProcessing.php | BaseInboundProcessing.sendEmailNotificationToSender | public function sendEmailNotificationToSender($message, $mappedVars) {
// Prep the email
$data = $this->prepareNotificationEmailData($message, $mappedVars);
// What blade file to use?
$emailBladeFile = 'lasallecmsemail::email.notification_email_to_inbound_sender';
// Send da email
Mail::queue($emailBladeFile, ['data' => $data], function ($message) use ($data) {
$message->from($data['from_email_address'], $data['from_name']);
$message->to($data['to_email_address'] , $data['to_email_address']);
$message->subject($data['subject']);
});
} | php | public function sendEmailNotificationToSender($message, $mappedVars) {
// Prep the email
$data = $this->prepareNotificationEmailData($message, $mappedVars);
// What blade file to use?
$emailBladeFile = 'lasallecmsemail::email.notification_email_to_inbound_sender';
// Send da email
Mail::queue($emailBladeFile, ['data' => $data], function ($message) use ($data) {
$message->from($data['from_email_address'], $data['from_name']);
$message->to($data['to_email_address'] , $data['to_email_address']);
$message->subject($data['subject']);
});
} | [
"public",
"function",
"sendEmailNotificationToSender",
"(",
"$",
"message",
",",
"$",
"mappedVars",
")",
"{",
"// Prep the email",
"$",
"data",
"=",
"$",
"this",
"->",
"prepareNotificationEmailData",
"(",
"$",
"message",
",",
"$",
"mappedVars",
")",
";",
"// What blade file to use?",
"$",
"emailBladeFile",
"=",
"'lasallecmsemail::email.notification_email_to_inbound_sender'",
";",
"// Send da email",
"Mail",
"::",
"queue",
"(",
"$",
"emailBladeFile",
",",
"[",
"'data'",
"=>",
"$",
"data",
"]",
",",
"function",
"(",
"$",
"message",
")",
"use",
"(",
"$",
"data",
")",
"{",
"$",
"message",
"->",
"from",
"(",
"$",
"data",
"[",
"'from_email_address'",
"]",
",",
"$",
"data",
"[",
"'from_name'",
"]",
")",
";",
"$",
"message",
"->",
"to",
"(",
"$",
"data",
"[",
"'to_email_address'",
"]",
",",
"$",
"data",
"[",
"'to_email_address'",
"]",
")",
";",
"$",
"message",
"->",
"subject",
"(",
"$",
"data",
"[",
"'subject'",
"]",
")",
";",
"}",
")",
";",
"}"
] | Send an email notification to sender
@param string $message Message to put in the body of the email
@param array $mappedVars Inbound POST vars mapped to database fields
@return void | [
"Send",
"an",
"email",
"notification",
"to",
"sender"
] | 95db5a59ab322105b9d3681cf9ab1f829c9fdb9f | https://github.com/lasallecms/lasallecms-l5-lasallecmsemail-pkg/blob/95db5a59ab322105b9d3681cf9ab1f829c9fdb9f/src/Processing/BaseInboundProcessing.php#L120-L135 | train |
lasallecms/lasallecms-l5-lasallecmsemail-pkg | src/Processing/BaseInboundProcessing.php | BaseInboundProcessing.prepareNotificationEmailData | public function prepareNotificationEmailData($message, $mappedVars) {
$data = [];
// Build the email data
$data['site_name'] = config('lasallecmsfrontend.site_name');
$data['from_name'] = $data['site_name'];
$data['from_email_address'] = config('lasallecmsusermanagement.administrator_first_among_equals_email');
$data['to_email_address'] = trim($mappedVars['from_email_address']);
$data['to_name'] = $this->genericWashText($data['from_name']);
$data['subject'] = "Notification email from ".$data['site_name'];
$data['message'] = $message;
return $data;
} | php | public function prepareNotificationEmailData($message, $mappedVars) {
$data = [];
// Build the email data
$data['site_name'] = config('lasallecmsfrontend.site_name');
$data['from_name'] = $data['site_name'];
$data['from_email_address'] = config('lasallecmsusermanagement.administrator_first_among_equals_email');
$data['to_email_address'] = trim($mappedVars['from_email_address']);
$data['to_name'] = $this->genericWashText($data['from_name']);
$data['subject'] = "Notification email from ".$data['site_name'];
$data['message'] = $message;
return $data;
} | [
"public",
"function",
"prepareNotificationEmailData",
"(",
"$",
"message",
",",
"$",
"mappedVars",
")",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"// Build the email data",
"$",
"data",
"[",
"'site_name'",
"]",
"=",
"config",
"(",
"'lasallecmsfrontend.site_name'",
")",
";",
"$",
"data",
"[",
"'from_name'",
"]",
"=",
"$",
"data",
"[",
"'site_name'",
"]",
";",
"$",
"data",
"[",
"'from_email_address'",
"]",
"=",
"config",
"(",
"'lasallecmsusermanagement.administrator_first_among_equals_email'",
")",
";",
"$",
"data",
"[",
"'to_email_address'",
"]",
"=",
"trim",
"(",
"$",
"mappedVars",
"[",
"'from_email_address'",
"]",
")",
";",
"$",
"data",
"[",
"'to_name'",
"]",
"=",
"$",
"this",
"->",
"genericWashText",
"(",
"$",
"data",
"[",
"'from_name'",
"]",
")",
";",
"$",
"data",
"[",
"'subject'",
"]",
"=",
"\"Notification email from \"",
".",
"$",
"data",
"[",
"'site_name'",
"]",
";",
"$",
"data",
"[",
"'message'",
"]",
"=",
"$",
"message",
";",
"return",
"$",
"data",
";",
"}"
] | Prepare the data needed to send out a notification email to the inbound email's sender
NOTE! USING MAILGUN SPECIFIC POST VARS FOR THE "TO" EMAIL FIELDS!
@param string $message Message to put in the body of the email
@param array $mappedVars Inbound POST vars mapped to database fields
@return array | [
"Prepare",
"the",
"data",
"needed",
"to",
"send",
"out",
"a",
"notification",
"email",
"to",
"the",
"inbound",
"email",
"s",
"sender"
] | 95db5a59ab322105b9d3681cf9ab1f829c9fdb9f | https://github.com/lasallecms/lasallecms-l5-lasallecmsemail-pkg/blob/95db5a59ab322105b9d3681cf9ab1f829c9fdb9f/src/Processing/BaseInboundProcessing.php#L147-L162 | train |
lasallecms/lasallecms-l5-lasallecmsemail-pkg | src/Processing/BaseInboundProcessing.php | BaseInboundProcessing.buildDataForDatabaseInsert | public function buildDataForDatabaseInsert($mappedVars) {
$data = [];
$data['priority_id'] = null;
$data['slug'] = $this->genericCreateSlug($mappedVars['subject']);
$data['sent'] = 1;
$data['sent_timestamp'] = Carbon::now();
$data['read'] = 0;
$data['archived'] = 0;
$data['created_at'] = Carbon::now();
$data['created_by'] = $mappedVars['user_id'];
$data['updated_at'] = Carbon::now();
$data['updated_by'] = $mappedVars['user_id'];
$data['locked_at'] = null;
$data['locked_by'] = null;
return $data;
} | php | public function buildDataForDatabaseInsert($mappedVars) {
$data = [];
$data['priority_id'] = null;
$data['slug'] = $this->genericCreateSlug($mappedVars['subject']);
$data['sent'] = 1;
$data['sent_timestamp'] = Carbon::now();
$data['read'] = 0;
$data['archived'] = 0;
$data['created_at'] = Carbon::now();
$data['created_by'] = $mappedVars['user_id'];
$data['updated_at'] = Carbon::now();
$data['updated_by'] = $mappedVars['user_id'];
$data['locked_at'] = null;
$data['locked_by'] = null;
return $data;
} | [
"public",
"function",
"buildDataForDatabaseInsert",
"(",
"$",
"mappedVars",
")",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"$",
"data",
"[",
"'priority_id'",
"]",
"=",
"null",
";",
"$",
"data",
"[",
"'slug'",
"]",
"=",
"$",
"this",
"->",
"genericCreateSlug",
"(",
"$",
"mappedVars",
"[",
"'subject'",
"]",
")",
";",
"$",
"data",
"[",
"'sent'",
"]",
"=",
"1",
";",
"$",
"data",
"[",
"'sent_timestamp'",
"]",
"=",
"Carbon",
"::",
"now",
"(",
")",
";",
"$",
"data",
"[",
"'read'",
"]",
"=",
"0",
";",
"$",
"data",
"[",
"'archived'",
"]",
"=",
"0",
";",
"$",
"data",
"[",
"'created_at'",
"]",
"=",
"Carbon",
"::",
"now",
"(",
")",
";",
"$",
"data",
"[",
"'created_by'",
"]",
"=",
"$",
"mappedVars",
"[",
"'user_id'",
"]",
";",
"$",
"data",
"[",
"'updated_at'",
"]",
"=",
"Carbon",
"::",
"now",
"(",
")",
";",
"$",
"data",
"[",
"'updated_by'",
"]",
"=",
"$",
"mappedVars",
"[",
"'user_id'",
"]",
";",
"$",
"data",
"[",
"'locked_at'",
"]",
"=",
"null",
";",
"$",
"data",
"[",
"'locked_by'",
"]",
"=",
"null",
";",
"return",
"$",
"data",
";",
"}"
] | Build the data for the INSERT into email_messages.
Some fields are already in the $data array.
These are the db fields that are missing in the $data array.
@param array $mappedVars Inbound POST vars mapped to database fields
@return array | [
"Build",
"the",
"data",
"for",
"the",
"INSERT",
"into",
"email_messages",
"."
] | 95db5a59ab322105b9d3681cf9ab1f829c9fdb9f | https://github.com/lasallecms/lasallecms-l5-lasallecmsemail-pkg/blob/95db5a59ab322105b9d3681cf9ab1f829c9fdb9f/src/Processing/BaseInboundProcessing.php#L189-L207 | train |
lasallecms/lasallecms-l5-lasallecmsemail-pkg | src/Processing/BaseInboundProcessing.php | BaseInboundProcessing.prepareAttachmentDataForInsert | public function prepareAttachmentDataForInsert($emailMessageID, $attachment, $attachmentPath, $data=null) {
$data1 = [];
$data1['email_messages_id'] = $emailMessageID;
$data1['attachment_path'] = $attachmentPath;
$data1['attachment_filename'] = $data['attachment-'.$attachment]->getClientOriginalName();
if (!empty($data['alternate_sort_string1'])) {
$data1['alternate_sort_string1'] = $data['alternate_sort_string1'];
} else {
$data1['alternate_sort_string1'] = null;
}
if (!empty($data['alternate_sort_string2'])) {
$data1['alternate_sort_string2'] = $data['alternate_sort_string2'];
} else {
$data1['alternate_sort_string2'] = null;
}
if (!empty($data['comments'])) {
$data1['comments'] = $data['comments'];
} else {
$data1['comments'] = null;
}
return $data1;
} | php | public function prepareAttachmentDataForInsert($emailMessageID, $attachment, $attachmentPath, $data=null) {
$data1 = [];
$data1['email_messages_id'] = $emailMessageID;
$data1['attachment_path'] = $attachmentPath;
$data1['attachment_filename'] = $data['attachment-'.$attachment]->getClientOriginalName();
if (!empty($data['alternate_sort_string1'])) {
$data1['alternate_sort_string1'] = $data['alternate_sort_string1'];
} else {
$data1['alternate_sort_string1'] = null;
}
if (!empty($data['alternate_sort_string2'])) {
$data1['alternate_sort_string2'] = $data['alternate_sort_string2'];
} else {
$data1['alternate_sort_string2'] = null;
}
if (!empty($data['comments'])) {
$data1['comments'] = $data['comments'];
} else {
$data1['comments'] = null;
}
return $data1;
} | [
"public",
"function",
"prepareAttachmentDataForInsert",
"(",
"$",
"emailMessageID",
",",
"$",
"attachment",
",",
"$",
"attachmentPath",
",",
"$",
"data",
"=",
"null",
")",
"{",
"$",
"data1",
"=",
"[",
"]",
";",
"$",
"data1",
"[",
"'email_messages_id'",
"]",
"=",
"$",
"emailMessageID",
";",
"$",
"data1",
"[",
"'attachment_path'",
"]",
"=",
"$",
"attachmentPath",
";",
"$",
"data1",
"[",
"'attachment_filename'",
"]",
"=",
"$",
"data",
"[",
"'attachment-'",
".",
"$",
"attachment",
"]",
"->",
"getClientOriginalName",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
"[",
"'alternate_sort_string1'",
"]",
")",
")",
"{",
"$",
"data1",
"[",
"'alternate_sort_string1'",
"]",
"=",
"$",
"data",
"[",
"'alternate_sort_string1'",
"]",
";",
"}",
"else",
"{",
"$",
"data1",
"[",
"'alternate_sort_string1'",
"]",
"=",
"null",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
"[",
"'alternate_sort_string2'",
"]",
")",
")",
"{",
"$",
"data1",
"[",
"'alternate_sort_string2'",
"]",
"=",
"$",
"data",
"[",
"'alternate_sort_string2'",
"]",
";",
"}",
"else",
"{",
"$",
"data1",
"[",
"'alternate_sort_string2'",
"]",
"=",
"null",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
"[",
"'comments'",
"]",
")",
")",
"{",
"$",
"data1",
"[",
"'comments'",
"]",
"=",
"$",
"data",
"[",
"'comments'",
"]",
";",
"}",
"else",
"{",
"$",
"data1",
"[",
"'comments'",
"]",
"=",
"null",
";",
"}",
"return",
"$",
"data1",
";",
"}"
] | Prepare the data for the INSERT into the "email_attachments" db table.
@param int $emailMessageID The ID of the just inserted "email_messages" record
@param int $attachment What attachment number? eg, attachment-1. AKA, Mailgun's "attachment-x" post var
@param string $attachmentPath Where are the attachments saved?
@param array $data Inbound POST vars, and processed vars,
@return array | [
"Prepare",
"the",
"data",
"for",
"the",
"INSERT",
"into",
"the",
"email_attachments",
"db",
"table",
"."
] | 95db5a59ab322105b9d3681cf9ab1f829c9fdb9f | https://github.com/lasallecms/lasallecms-l5-lasallecmsemail-pkg/blob/95db5a59ab322105b9d3681cf9ab1f829c9fdb9f/src/Processing/BaseInboundProcessing.php#L252-L278 | train |
lasallecms/lasallecms-l5-lasallecmsemail-pkg | src/Processing/BaseInboundProcessing.php | BaseInboundProcessing.manageTokenBasedLogin | public function manageTokenBasedLogin($user_id, $email) {
//-------------------------------------------------------------
// Create a Login Token so customer login bypasses login form
//-------------------------------------------------------------
$this->userTokenbasedloginRepository->createLoginToken($user_id);
//-------------------------------------------------------------
// Send Login Token email to the customer
//-------------------------------------------------------------
$this->sendLoginTokenEmail->sendEmail($user_id, $email);
return;
} | php | public function manageTokenBasedLogin($user_id, $email) {
//-------------------------------------------------------------
// Create a Login Token so customer login bypasses login form
//-------------------------------------------------------------
$this->userTokenbasedloginRepository->createLoginToken($user_id);
//-------------------------------------------------------------
// Send Login Token email to the customer
//-------------------------------------------------------------
$this->sendLoginTokenEmail->sendEmail($user_id, $email);
return;
} | [
"public",
"function",
"manageTokenBasedLogin",
"(",
"$",
"user_id",
",",
"$",
"email",
")",
"{",
"//-------------------------------------------------------------",
"// Create a Login Token so customer login bypasses login form",
"//-------------------------------------------------------------",
"$",
"this",
"->",
"userTokenbasedloginRepository",
"->",
"createLoginToken",
"(",
"$",
"user_id",
")",
";",
"//-------------------------------------------------------------",
"// Send Login Token email to the customer",
"//-------------------------------------------------------------",
"$",
"this",
"->",
"sendLoginTokenEmail",
"->",
"sendEmail",
"(",
"$",
"user_id",
",",
"$",
"email",
")",
";",
"return",
";",
"}"
] | Create the token for token based login; and, send out the email with the token based login link, to a user
@param int $user_id ID field of the "users" db table
@param array $email Email fields for the outgoing email with the token login link
@return void | [
"Create",
"the",
"token",
"for",
"token",
"based",
"login",
";",
"and",
"send",
"out",
"the",
"email",
"with",
"the",
"token",
"based",
"login",
"link",
"to",
"a",
"user"
] | 95db5a59ab322105b9d3681cf9ab1f829c9fdb9f | https://github.com/lasallecms/lasallecms-l5-lasallecmsemail-pkg/blob/95db5a59ab322105b9d3681cf9ab1f829c9fdb9f/src/Processing/BaseInboundProcessing.php#L293-L306 | train |
phossa/phossa-route | src/Phossa/Route/Collector/CollectorAbstract.php | CollectorAbstract.setCollectorHandler | protected function setCollectorHandler(ResultInterface $result)
{
$status = $result->getStatus();
if (is_null($result->getHandler()) && $this->getHandler($status)) {
// debug message
$this->debug(Message::get(
Message::DEBUG_SET_C_HANDLER,
get_class($this),
$status
));
$result->setHandler($this->getHandler($status));
}
return $this;
} | php | protected function setCollectorHandler(ResultInterface $result)
{
$status = $result->getStatus();
if (is_null($result->getHandler()) && $this->getHandler($status)) {
// debug message
$this->debug(Message::get(
Message::DEBUG_SET_C_HANDLER,
get_class($this),
$status
));
$result->setHandler($this->getHandler($status));
}
return $this;
} | [
"protected",
"function",
"setCollectorHandler",
"(",
"ResultInterface",
"$",
"result",
")",
"{",
"$",
"status",
"=",
"$",
"result",
"->",
"getStatus",
"(",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"result",
"->",
"getHandler",
"(",
")",
")",
"&&",
"$",
"this",
"->",
"getHandler",
"(",
"$",
"status",
")",
")",
"{",
"// debug message",
"$",
"this",
"->",
"debug",
"(",
"Message",
"::",
"get",
"(",
"Message",
"::",
"DEBUG_SET_C_HANDLER",
",",
"get_class",
"(",
"$",
"this",
")",
",",
"$",
"status",
")",
")",
";",
"$",
"result",
"->",
"setHandler",
"(",
"$",
"this",
"->",
"getHandler",
"(",
"$",
"status",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set collector level handler if result has no handler set yet
@param ResultInterface $result desc
@return self
@access protected | [
"Set",
"collector",
"level",
"handler",
"if",
"result",
"has",
"no",
"handler",
"set",
"yet"
] | fdcc1c814b8b1692a60d433d3c085e6c7a923acc | https://github.com/phossa/phossa-route/blob/fdcc1c814b8b1692a60d433d3c085e6c7a923acc/src/Phossa/Route/Collector/CollectorAbstract.php#L150-L163 | train |
sndsgd/http | src/http/UploadedFile.php | UploadedFile.getContentType | public function getContentType(bool $allowUnverified = false): string
{
# always use the verified content type if it exists
if ($this->contentType === null) {
if ($allowUnverified) {
return $this->unverifiedContentType;
}
$this->contentType = $this->getContentTypeFromFile($this->tempPath);
}
return $this->contentType;
} | php | public function getContentType(bool $allowUnverified = false): string
{
# always use the verified content type if it exists
if ($this->contentType === null) {
if ($allowUnverified) {
return $this->unverifiedContentType;
}
$this->contentType = $this->getContentTypeFromFile($this->tempPath);
}
return $this->contentType;
} | [
"public",
"function",
"getContentType",
"(",
"bool",
"$",
"allowUnverified",
"=",
"false",
")",
":",
"string",
"{",
"# always use the verified content type if it exists",
"if",
"(",
"$",
"this",
"->",
"contentType",
"===",
"null",
")",
"{",
"if",
"(",
"$",
"allowUnverified",
")",
"{",
"return",
"$",
"this",
"->",
"unverifiedContentType",
";",
"}",
"$",
"this",
"->",
"contentType",
"=",
"$",
"this",
"->",
"getContentTypeFromFile",
"(",
"$",
"this",
"->",
"tempPath",
")",
";",
"}",
"return",
"$",
"this",
"->",
"contentType",
";",
"}"
] | Get the content type
@param bool $allowUnverified
@return string | [
"Get",
"the",
"content",
"type"
] | e7f82010a66c6d3241a24ea82baf4593130c723b | https://github.com/sndsgd/http/blob/e7f82010a66c6d3241a24ea82baf4593130c723b/src/http/UploadedFile.php#L94-L104 | train |
sndsgd/http | src/http/UploadedFile.php | UploadedFile.isType | public function isType(
array $mimeTypes,
bool $allowUnverified = false
): bool
{
$contentType = $this->getContentType($allowUnverified);
foreach ($mimeTypes as $type) {
if (strtolower($type) === $contentType) {
return true;
}
}
return false;
} | php | public function isType(
array $mimeTypes,
bool $allowUnverified = false
): bool
{
$contentType = $this->getContentType($allowUnverified);
foreach ($mimeTypes as $type) {
if (strtolower($type) === $contentType) {
return true;
}
}
return false;
} | [
"public",
"function",
"isType",
"(",
"array",
"$",
"mimeTypes",
",",
"bool",
"$",
"allowUnverified",
"=",
"false",
")",
":",
"bool",
"{",
"$",
"contentType",
"=",
"$",
"this",
"->",
"getContentType",
"(",
"$",
"allowUnverified",
")",
";",
"foreach",
"(",
"$",
"mimeTypes",
"as",
"$",
"type",
")",
"{",
"if",
"(",
"strtolower",
"(",
"$",
"type",
")",
"===",
"$",
"contentType",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Determine whether the file type matches any that are provided
@param array<string> $mimeTypes Acceptable mime types
@param bool $allowUnverified Whether to trust the client provided type
@return bool | [
"Determine",
"whether",
"the",
"file",
"type",
"matches",
"any",
"that",
"are",
"provided"
] | e7f82010a66c6d3241a24ea82baf4593130c723b | https://github.com/sndsgd/http/blob/e7f82010a66c6d3241a24ea82baf4593130c723b/src/http/UploadedFile.php#L124-L136 | train |
sndsgd/http | src/http/UploadedFile.php | UploadedFile.getFormattedSize | public function getFormattedSize(
int $precision = 0,
string $point = ".",
string $sep = ","
): string
{
return \sndsgd\Fs::formatSize($this->size, $precision, $point, $sep);
} | php | public function getFormattedSize(
int $precision = 0,
string $point = ".",
string $sep = ","
): string
{
return \sndsgd\Fs::formatSize($this->size, $precision, $point, $sep);
} | [
"public",
"function",
"getFormattedSize",
"(",
"int",
"$",
"precision",
"=",
"0",
",",
"string",
"$",
"point",
"=",
"\".\"",
",",
"string",
"$",
"sep",
"=",
"\",\"",
")",
":",
"string",
"{",
"return",
"\\",
"sndsgd",
"\\",
"Fs",
"::",
"formatSize",
"(",
"$",
"this",
"->",
"size",
",",
"$",
"precision",
",",
"$",
"point",
",",
"$",
"sep",
")",
";",
"}"
] | Retrieve a human readable version of the size
@param int $precision The number of decimal places to show
@param string $point The decimal point
@param string $sep The thousands separator
@return string | [
"Retrieve",
"a",
"human",
"readable",
"version",
"of",
"the",
"size"
] | e7f82010a66c6d3241a24ea82baf4593130c723b | https://github.com/sndsgd/http/blob/e7f82010a66c6d3241a24ea82baf4593130c723b/src/http/UploadedFile.php#L156-L163 | train |
sndsgd/http | src/http/UploadedFile.php | UploadedFile.toArray | public function toArray(): array
{
return [
"clientFilename" => $this->getClientFilename(),
"unverifiedContentType" => $this->error ? "" : $this->getContentType(true),
"verifiedContentType" => $this->error ? "" : $this->getContentType(),
"size" => $this->error ? 0 : $this->getSize(),
"tempPath" => $this->error ? "" : $this->getTempPath(),
"error" => $this->error ? $this->error->getMessage() : "",
];
} | php | public function toArray(): array
{
return [
"clientFilename" => $this->getClientFilename(),
"unverifiedContentType" => $this->error ? "" : $this->getContentType(true),
"verifiedContentType" => $this->error ? "" : $this->getContentType(),
"size" => $this->error ? 0 : $this->getSize(),
"tempPath" => $this->error ? "" : $this->getTempPath(),
"error" => $this->error ? $this->error->getMessage() : "",
];
} | [
"public",
"function",
"toArray",
"(",
")",
":",
"array",
"{",
"return",
"[",
"\"clientFilename\"",
"=>",
"$",
"this",
"->",
"getClientFilename",
"(",
")",
",",
"\"unverifiedContentType\"",
"=>",
"$",
"this",
"->",
"error",
"?",
"\"\"",
":",
"$",
"this",
"->",
"getContentType",
"(",
"true",
")",
",",
"\"verifiedContentType\"",
"=>",
"$",
"this",
"->",
"error",
"?",
"\"\"",
":",
"$",
"this",
"->",
"getContentType",
"(",
")",
",",
"\"size\"",
"=>",
"$",
"this",
"->",
"error",
"?",
"0",
":",
"$",
"this",
"->",
"getSize",
"(",
")",
",",
"\"tempPath\"",
"=>",
"$",
"this",
"->",
"error",
"?",
"\"\"",
":",
"$",
"this",
"->",
"getTempPath",
"(",
")",
",",
"\"error\"",
"=>",
"$",
"this",
"->",
"error",
"?",
"$",
"this",
"->",
"error",
"->",
"getMessage",
"(",
")",
":",
"\"\"",
",",
"]",
";",
"}"
] | Get an array representation of this object
@return array | [
"Get",
"an",
"array",
"representation",
"of",
"this",
"object"
] | e7f82010a66c6d3241a24ea82baf4593130c723b | https://github.com/sndsgd/http/blob/e7f82010a66c6d3241a24ea82baf4593130c723b/src/http/UploadedFile.php#L192-L202 | train |
cubicmushroom/valueobjects | src/Web/EmailAddress.php | EmailAddress.getDomainPart | public function getDomainPart()
{
$parts = \explode('@', $this->toNative());
$domain = \trim($parts[1], '[]');
return Domain::specifyType($domain);
} | php | public function getDomainPart()
{
$parts = \explode('@', $this->toNative());
$domain = \trim($parts[1], '[]');
return Domain::specifyType($domain);
} | [
"public",
"function",
"getDomainPart",
"(",
")",
"{",
"$",
"parts",
"=",
"\\",
"explode",
"(",
"'@'",
",",
"$",
"this",
"->",
"toNative",
"(",
")",
")",
";",
"$",
"domain",
"=",
"\\",
"trim",
"(",
"$",
"parts",
"[",
"1",
"]",
",",
"'[]'",
")",
";",
"return",
"Domain",
"::",
"specifyType",
"(",
"$",
"domain",
")",
";",
"}"
] | Returns the domain part of the email address
@return Domain | [
"Returns",
"the",
"domain",
"part",
"of",
"the",
"email",
"address"
] | 4554239ab75d65eeb9773219aa5b07e9fbfabb92 | https://github.com/cubicmushroom/valueobjects/blob/4554239ab75d65eeb9773219aa5b07e9fbfabb92/src/Web/EmailAddress.php#L44-L50 | train |
randomhost/image | src/php/Text/Decorator/Border.php | Border.insertTextBorder | protected function insertTextBorder($xPosition, $yPosition, $text)
{
if (!$this->getBorderColor() instanceof Image\Color) {
throw new \RuntimeException(
'Attempt to render text border without setting a color'
);
}
/*
* Set the alpha transparency to zero since we are going to render the
* overlay text multiple times using different offsets to achieve a
* border effect which is not natively supported by GD.
*/
$borderAlpha = $this->getBorderColor()->getAlpha();
$this->getBorderColor()->setAlpha(0);
/*
* Overwrite the original text color with the border color so we can use
* the decorated class for rendering.
*/
$textColor = $this->getTextColor();
$this->setTextColor($this->getBorderColor());
// render border
parent::insertText($xPosition - 1, $yPosition - 1, $text);
parent::insertText($xPosition - 1, $yPosition, $text);
parent::insertText($xPosition - 1, $yPosition + 1, $text);
parent::insertText($xPosition, $yPosition - 1, $text);
parent::insertText($xPosition, $yPosition + 1, $text);
parent::insertText($xPosition + 1, $yPosition - 1, $text);
parent::insertText($xPosition + 1, $yPosition, $text);
parent::insertText($xPosition + 1, $yPosition + 1, $text);
// restore original border alpha transparency
$this->getBorderColor()->setAlpha($borderAlpha);
// restore original text color for rendering the text
$this->setTextColor($textColor);
return $this;
} | php | protected function insertTextBorder($xPosition, $yPosition, $text)
{
if (!$this->getBorderColor() instanceof Image\Color) {
throw new \RuntimeException(
'Attempt to render text border without setting a color'
);
}
/*
* Set the alpha transparency to zero since we are going to render the
* overlay text multiple times using different offsets to achieve a
* border effect which is not natively supported by GD.
*/
$borderAlpha = $this->getBorderColor()->getAlpha();
$this->getBorderColor()->setAlpha(0);
/*
* Overwrite the original text color with the border color so we can use
* the decorated class for rendering.
*/
$textColor = $this->getTextColor();
$this->setTextColor($this->getBorderColor());
// render border
parent::insertText($xPosition - 1, $yPosition - 1, $text);
parent::insertText($xPosition - 1, $yPosition, $text);
parent::insertText($xPosition - 1, $yPosition + 1, $text);
parent::insertText($xPosition, $yPosition - 1, $text);
parent::insertText($xPosition, $yPosition + 1, $text);
parent::insertText($xPosition + 1, $yPosition - 1, $text);
parent::insertText($xPosition + 1, $yPosition, $text);
parent::insertText($xPosition + 1, $yPosition + 1, $text);
// restore original border alpha transparency
$this->getBorderColor()->setAlpha($borderAlpha);
// restore original text color for rendering the text
$this->setTextColor($textColor);
return $this;
} | [
"protected",
"function",
"insertTextBorder",
"(",
"$",
"xPosition",
",",
"$",
"yPosition",
",",
"$",
"text",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"getBorderColor",
"(",
")",
"instanceof",
"Image",
"\\",
"Color",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Attempt to render text border without setting a color'",
")",
";",
"}",
"/*\n * Set the alpha transparency to zero since we are going to render the\n * overlay text multiple times using different offsets to achieve a\n * border effect which is not natively supported by GD.\n */",
"$",
"borderAlpha",
"=",
"$",
"this",
"->",
"getBorderColor",
"(",
")",
"->",
"getAlpha",
"(",
")",
";",
"$",
"this",
"->",
"getBorderColor",
"(",
")",
"->",
"setAlpha",
"(",
"0",
")",
";",
"/*\n * Overwrite the original text color with the border color so we can use\n * the decorated class for rendering.\n */",
"$",
"textColor",
"=",
"$",
"this",
"->",
"getTextColor",
"(",
")",
";",
"$",
"this",
"->",
"setTextColor",
"(",
"$",
"this",
"->",
"getBorderColor",
"(",
")",
")",
";",
"// render border",
"parent",
"::",
"insertText",
"(",
"$",
"xPosition",
"-",
"1",
",",
"$",
"yPosition",
"-",
"1",
",",
"$",
"text",
")",
";",
"parent",
"::",
"insertText",
"(",
"$",
"xPosition",
"-",
"1",
",",
"$",
"yPosition",
",",
"$",
"text",
")",
";",
"parent",
"::",
"insertText",
"(",
"$",
"xPosition",
"-",
"1",
",",
"$",
"yPosition",
"+",
"1",
",",
"$",
"text",
")",
";",
"parent",
"::",
"insertText",
"(",
"$",
"xPosition",
",",
"$",
"yPosition",
"-",
"1",
",",
"$",
"text",
")",
";",
"parent",
"::",
"insertText",
"(",
"$",
"xPosition",
",",
"$",
"yPosition",
"+",
"1",
",",
"$",
"text",
")",
";",
"parent",
"::",
"insertText",
"(",
"$",
"xPosition",
"+",
"1",
",",
"$",
"yPosition",
"-",
"1",
",",
"$",
"text",
")",
";",
"parent",
"::",
"insertText",
"(",
"$",
"xPosition",
"+",
"1",
",",
"$",
"yPosition",
",",
"$",
"text",
")",
";",
"parent",
"::",
"insertText",
"(",
"$",
"xPosition",
"+",
"1",
",",
"$",
"yPosition",
"+",
"1",
",",
"$",
"text",
")",
";",
"// restore original border alpha transparency",
"$",
"this",
"->",
"getBorderColor",
"(",
")",
"->",
"setAlpha",
"(",
"$",
"borderAlpha",
")",
";",
"// restore original text color for rendering the text",
"$",
"this",
"->",
"setTextColor",
"(",
"$",
"textColor",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Renders the given text border onto the image resource, using the given
coordinates.
@param int $xPosition The x-ordinate.
@param int $yPosition The y-ordinate position of the fonts baseline.
@param string $text The text string in UTF-8 encoding.
@return $this;
@throws \RuntimeException Thrown if $this->image is not a valid image
resource or the font file isn't set. | [
"Renders",
"the",
"given",
"text",
"border",
"onto",
"the",
"image",
"resource",
"using",
"the",
"given",
"coordinates",
"."
] | bd669ba6b50fd2bbbe50c4ef06235b111a8a30b0 | https://github.com/randomhost/image/blob/bd669ba6b50fd2bbbe50c4ef06235b111a8a30b0/src/php/Text/Decorator/Border.php#L81-L121 | train |
Aviogram/Common | src/PHPClass/Element/ClassTrait.php | ClassTrait.resolveConflictInsteadOf | public function resolveConflictInsteadOf($trait, $method, $insteadOfTrait)
{
$fullClass = $this->classFile->getFullClassName($trait);
if (method_exists($fullClass, $method) === false) {
throw \Aviogram\Common\PHPClass\Exception\ClassTrait::undefinedMethod($trait, $method);
}
if ($trait !== $this->name && $insteadOfTrait !== $this->name) {
throw \Aviogram\Common\PHPClass\Exception\ClassTrait::knownTraitNotUsedByResolveInsteadOf($this->name);
} else if ($trait !== $this->name && in_array($trait, $this->secondNames) === false) {
if ($this->classFile->isClassDefined($trait) === false) {
throw \Aviogram\Common\PHPClass\Exception\ClassTrait::traitNotFound($trait);
}
$this->secondNames[] = $trait;
} else if ($insteadOfTrait !== $this->name && in_array($insteadOfTrait, $this->secondNames) === false) {
if ($this->classFile->isClassDefined($insteadOfTrait) === false) {
throw \Aviogram\Common\PHPClass\Exception\ClassTrait::traitNotFound($insteadOfTrait);
}
$this->secondNames[] = $insteadOfTrait;
}
$this->conflicts[] = "{$trait}::{$method} insteadOf {$insteadOfTrait};";
return $this;
} | php | public function resolveConflictInsteadOf($trait, $method, $insteadOfTrait)
{
$fullClass = $this->classFile->getFullClassName($trait);
if (method_exists($fullClass, $method) === false) {
throw \Aviogram\Common\PHPClass\Exception\ClassTrait::undefinedMethod($trait, $method);
}
if ($trait !== $this->name && $insteadOfTrait !== $this->name) {
throw \Aviogram\Common\PHPClass\Exception\ClassTrait::knownTraitNotUsedByResolveInsteadOf($this->name);
} else if ($trait !== $this->name && in_array($trait, $this->secondNames) === false) {
if ($this->classFile->isClassDefined($trait) === false) {
throw \Aviogram\Common\PHPClass\Exception\ClassTrait::traitNotFound($trait);
}
$this->secondNames[] = $trait;
} else if ($insteadOfTrait !== $this->name && in_array($insteadOfTrait, $this->secondNames) === false) {
if ($this->classFile->isClassDefined($insteadOfTrait) === false) {
throw \Aviogram\Common\PHPClass\Exception\ClassTrait::traitNotFound($insteadOfTrait);
}
$this->secondNames[] = $insteadOfTrait;
}
$this->conflicts[] = "{$trait}::{$method} insteadOf {$insteadOfTrait};";
return $this;
} | [
"public",
"function",
"resolveConflictInsteadOf",
"(",
"$",
"trait",
",",
"$",
"method",
",",
"$",
"insteadOfTrait",
")",
"{",
"$",
"fullClass",
"=",
"$",
"this",
"->",
"classFile",
"->",
"getFullClassName",
"(",
"$",
"trait",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"fullClass",
",",
"$",
"method",
")",
"===",
"false",
")",
"{",
"throw",
"\\",
"Aviogram",
"\\",
"Common",
"\\",
"PHPClass",
"\\",
"Exception",
"\\",
"ClassTrait",
"::",
"undefinedMethod",
"(",
"$",
"trait",
",",
"$",
"method",
")",
";",
"}",
"if",
"(",
"$",
"trait",
"!==",
"$",
"this",
"->",
"name",
"&&",
"$",
"insteadOfTrait",
"!==",
"$",
"this",
"->",
"name",
")",
"{",
"throw",
"\\",
"Aviogram",
"\\",
"Common",
"\\",
"PHPClass",
"\\",
"Exception",
"\\",
"ClassTrait",
"::",
"knownTraitNotUsedByResolveInsteadOf",
"(",
"$",
"this",
"->",
"name",
")",
";",
"}",
"else",
"if",
"(",
"$",
"trait",
"!==",
"$",
"this",
"->",
"name",
"&&",
"in_array",
"(",
"$",
"trait",
",",
"$",
"this",
"->",
"secondNames",
")",
"===",
"false",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"classFile",
"->",
"isClassDefined",
"(",
"$",
"trait",
")",
"===",
"false",
")",
"{",
"throw",
"\\",
"Aviogram",
"\\",
"Common",
"\\",
"PHPClass",
"\\",
"Exception",
"\\",
"ClassTrait",
"::",
"traitNotFound",
"(",
"$",
"trait",
")",
";",
"}",
"$",
"this",
"->",
"secondNames",
"[",
"]",
"=",
"$",
"trait",
";",
"}",
"else",
"if",
"(",
"$",
"insteadOfTrait",
"!==",
"$",
"this",
"->",
"name",
"&&",
"in_array",
"(",
"$",
"insteadOfTrait",
",",
"$",
"this",
"->",
"secondNames",
")",
"===",
"false",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"classFile",
"->",
"isClassDefined",
"(",
"$",
"insteadOfTrait",
")",
"===",
"false",
")",
"{",
"throw",
"\\",
"Aviogram",
"\\",
"Common",
"\\",
"PHPClass",
"\\",
"Exception",
"\\",
"ClassTrait",
"::",
"traitNotFound",
"(",
"$",
"insteadOfTrait",
")",
";",
"}",
"$",
"this",
"->",
"secondNames",
"[",
"]",
"=",
"$",
"insteadOfTrait",
";",
"}",
"$",
"this",
"->",
"conflicts",
"[",
"]",
"=",
"\"{$trait}::{$method} insteadOf {$insteadOfTrait};\"",
";",
"return",
"$",
"this",
";",
"}"
] | Resolve method name conflict with ignoring one trait over the other
@param string $trait The trait that will be used
@param string $method The method of the trait which causes the conflict
@param string $insteadOfTrait The trait which will be ignored
@return $this
@throws \Aviogram\Common\PHPClass\Exception\ClassTrait When the base trait is not used
@throws \Aviogram\Common\PHPClass\Exception\ClassTrait When the method does not exists | [
"Resolve",
"method",
"name",
"conflict",
"with",
"ignoring",
"one",
"trait",
"over",
"the",
"other"
] | bcff2e409cccd4791a3f9bca0b2cdd70c25ddec5 | https://github.com/Aviogram/Common/blob/bcff2e409cccd4791a3f9bca0b2cdd70c25ddec5/src/PHPClass/Element/ClassTrait.php#L58-L84 | train |
Aviogram/Common | src/PHPClass/Element/ClassTrait.php | ClassTrait.resolveConflictAlias | public function resolveConflictAlias($trait, $method, $alias)
{
$fullClass = $this->classFile->getFullClassName($trait);
if (method_exists($fullClass, $method) === false) {
throw \Aviogram\Common\PHPClass\Exception\ClassTrait::undefinedMethod($trait, $method);
}
$this->conflicts[] = "{$trait}::{$method} as {$alias};";
if ($trait !== $this->name && in_array($trait, $this->secondNames) === false) {
if ($this->classFile->isTraitDefined($trait) === false) {
throw \Aviogram\Common\PHPClass\Exception\ClassTrait::traitNotFound($trait);
}
$this->secondNames[] = $trait;
}
return $this;
} | php | public function resolveConflictAlias($trait, $method, $alias)
{
$fullClass = $this->classFile->getFullClassName($trait);
if (method_exists($fullClass, $method) === false) {
throw \Aviogram\Common\PHPClass\Exception\ClassTrait::undefinedMethod($trait, $method);
}
$this->conflicts[] = "{$trait}::{$method} as {$alias};";
if ($trait !== $this->name && in_array($trait, $this->secondNames) === false) {
if ($this->classFile->isTraitDefined($trait) === false) {
throw \Aviogram\Common\PHPClass\Exception\ClassTrait::traitNotFound($trait);
}
$this->secondNames[] = $trait;
}
return $this;
} | [
"public",
"function",
"resolveConflictAlias",
"(",
"$",
"trait",
",",
"$",
"method",
",",
"$",
"alias",
")",
"{",
"$",
"fullClass",
"=",
"$",
"this",
"->",
"classFile",
"->",
"getFullClassName",
"(",
"$",
"trait",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"fullClass",
",",
"$",
"method",
")",
"===",
"false",
")",
"{",
"throw",
"\\",
"Aviogram",
"\\",
"Common",
"\\",
"PHPClass",
"\\",
"Exception",
"\\",
"ClassTrait",
"::",
"undefinedMethod",
"(",
"$",
"trait",
",",
"$",
"method",
")",
";",
"}",
"$",
"this",
"->",
"conflicts",
"[",
"]",
"=",
"\"{$trait}::{$method} as {$alias};\"",
";",
"if",
"(",
"$",
"trait",
"!==",
"$",
"this",
"->",
"name",
"&&",
"in_array",
"(",
"$",
"trait",
",",
"$",
"this",
"->",
"secondNames",
")",
"===",
"false",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"classFile",
"->",
"isTraitDefined",
"(",
"$",
"trait",
")",
"===",
"false",
")",
"{",
"throw",
"\\",
"Aviogram",
"\\",
"Common",
"\\",
"PHPClass",
"\\",
"Exception",
"\\",
"ClassTrait",
"::",
"traitNotFound",
"(",
"$",
"trait",
")",
";",
"}",
"$",
"this",
"->",
"secondNames",
"[",
"]",
"=",
"$",
"trait",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Resolve method name conflict with aliasing the method name
@param string $trait The trait that causing the conflict
@param string $method The method of the trait that causing the conflict
@param string $alias The alias for the method
@return $this
@throws \Aviogram\Common\PHPClass\Exception\ClassTrait When the trait does not exists
@throws \Aviogram\Common\PHPClass\Exception\ClassTrait When the method is not defined on the trait | [
"Resolve",
"method",
"name",
"conflict",
"with",
"aliasing",
"the",
"method",
"name"
] | bcff2e409cccd4791a3f9bca0b2cdd70c25ddec5 | https://github.com/Aviogram/Common/blob/bcff2e409cccd4791a3f9bca0b2cdd70c25ddec5/src/PHPClass/Element/ClassTrait.php#L97-L115 | train |
t3v/t3v_datamapper | Classes/Service/PageService.php | PageService.getPageByUid | public function getPageByUid(int $uid, int $languageUid = null) {
return $this->getPage($uid, $languageUid);
} | php | public function getPageByUid(int $uid, int $languageUid = null) {
return $this->getPage($uid, $languageUid);
} | [
"public",
"function",
"getPageByUid",
"(",
"int",
"$",
"uid",
",",
"int",
"$",
"languageUid",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"getPage",
"(",
"$",
"uid",
",",
"$",
"languageUid",
")",
";",
"}"
] | Gets a page by UID.
Alias for `getPage`.
@param int $uid The UID of the page
@param int $languageUid The optional language UID, defaults to the UID of the current system language
@return array|null The row for the page or null if no page was found | [
"Gets",
"a",
"page",
"by",
"UID",
"."
] | bab2de90f467936fbe4270cd133cb4109d1108eb | https://github.com/t3v/t3v_datamapper/blob/bab2de90f467936fbe4270cd133cb4109d1108eb/Classes/Service/PageService.php#L167-L169 | train |
t3v/t3v_datamapper | Classes/Service/PageService.php | PageService.getPages | public function getPages($uids, int $languageUid = null): array {
$pages = [];
if (is_string($uids)) {
$uids = GeneralUtility::intExplode(',', $uids, true);
}
if ($uids) {
foreach($uids as $uid) {
$record = $this->getPage($uid, $languageUid);
if ($record) {
$pages[] = $record;
}
}
}
return $pages;
} | php | public function getPages($uids, int $languageUid = null): array {
$pages = [];
if (is_string($uids)) {
$uids = GeneralUtility::intExplode(',', $uids, true);
}
if ($uids) {
foreach($uids as $uid) {
$record = $this->getPage($uid, $languageUid);
if ($record) {
$pages[] = $record;
}
}
}
return $pages;
} | [
"public",
"function",
"getPages",
"(",
"$",
"uids",
",",
"int",
"$",
"languageUid",
"=",
"null",
")",
":",
"array",
"{",
"$",
"pages",
"=",
"[",
"]",
";",
"if",
"(",
"is_string",
"(",
"$",
"uids",
")",
")",
"{",
"$",
"uids",
"=",
"GeneralUtility",
"::",
"intExplode",
"(",
"','",
",",
"$",
"uids",
",",
"true",
")",
";",
"}",
"if",
"(",
"$",
"uids",
")",
"{",
"foreach",
"(",
"$",
"uids",
"as",
"$",
"uid",
")",
"{",
"$",
"record",
"=",
"$",
"this",
"->",
"getPage",
"(",
"$",
"uid",
",",
"$",
"languageUid",
")",
";",
"if",
"(",
"$",
"record",
")",
"{",
"$",
"pages",
"[",
"]",
"=",
"$",
"record",
";",
"}",
"}",
"}",
"return",
"$",
"pages",
";",
"}"
] | Gets pages.
@param array|string $uids The UIDs as array or as string, seperated by `,`
@param int $languageUid The optional language UID, defaults to the UID of the current system language
@return array The pages or empty if no pages were found | [
"Gets",
"pages",
"."
] | bab2de90f467936fbe4270cd133cb4109d1108eb | https://github.com/t3v/t3v_datamapper/blob/bab2de90f467936fbe4270cd133cb4109d1108eb/Classes/Service/PageService.php#L178-L196 | train |
t3v/t3v_datamapper | Classes/Service/PageService.php | PageService.getSubpages | public function getSubpages(int $pid, int $recursion = 1, bool $exclude = true, int $languageUid = null): array {
$subpages = [];
$subpagesUids = $this->getSubpagesUids($pid, $recursion, $exclude);
if ($subpagesUids) {
foreach ($subpagesUids as $subpageUid) {
$record = $this->getPage($subpageUid, $languageUid);
if ($record) {
$subpages[] = $record;
}
}
}
return $subpages;
} | php | public function getSubpages(int $pid, int $recursion = 1, bool $exclude = true, int $languageUid = null): array {
$subpages = [];
$subpagesUids = $this->getSubpagesUids($pid, $recursion, $exclude);
if ($subpagesUids) {
foreach ($subpagesUids as $subpageUid) {
$record = $this->getPage($subpageUid, $languageUid);
if ($record) {
$subpages[] = $record;
}
}
}
return $subpages;
} | [
"public",
"function",
"getSubpages",
"(",
"int",
"$",
"pid",
",",
"int",
"$",
"recursion",
"=",
"1",
",",
"bool",
"$",
"exclude",
"=",
"true",
",",
"int",
"$",
"languageUid",
"=",
"null",
")",
":",
"array",
"{",
"$",
"subpages",
"=",
"[",
"]",
";",
"$",
"subpagesUids",
"=",
"$",
"this",
"->",
"getSubpagesUids",
"(",
"$",
"pid",
",",
"$",
"recursion",
",",
"$",
"exclude",
")",
";",
"if",
"(",
"$",
"subpagesUids",
")",
"{",
"foreach",
"(",
"$",
"subpagesUids",
"as",
"$",
"subpageUid",
")",
"{",
"$",
"record",
"=",
"$",
"this",
"->",
"getPage",
"(",
"$",
"subpageUid",
",",
"$",
"languageUid",
")",
";",
"if",
"(",
"$",
"record",
")",
"{",
"$",
"subpages",
"[",
"]",
"=",
"$",
"record",
";",
"}",
"}",
"}",
"return",
"$",
"subpages",
";",
"}"
] | Gets the subpages of a page.
@param int $pid The PID of the entry page to search from
@param int $recursion The recursion, defaults to `1`
@param bool $exclude If set, the entry page should be excluded, defaults to `true`
@param int $languageUid The optional language UID, defaults to the UID of the current system language
@return array The subpages or empty if no subpages were found | [
"Gets",
"the",
"subpages",
"of",
"a",
"page",
"."
] | bab2de90f467936fbe4270cd133cb4109d1108eb | https://github.com/t3v/t3v_datamapper/blob/bab2de90f467936fbe4270cd133cb4109d1108eb/Classes/Service/PageService.php#L220-L235 | train |
t3v/t3v_datamapper | Classes/Service/PageService.php | PageService.getSubpagesUids | public function getSubpagesUids(int $pid, int $recursion = 1, bool $exclude = true): array {
$subpagesUids = [];
$treeList = $this->queryGenerator->getTreeList($pid, $recursion, 0, 1);
$recordUids = GeneralUtility::intExplode(',', $treeList, true);
if ($recordUids) {
foreach ($recordUids as $recordUid) {
if ($this->getPage($recordUid)) {
$subpagesUids[] = $recordUid;
}
}
}
if ($exclude) {
unset($subpagesUids[0]);
}
return $subpagesUids;
} | php | public function getSubpagesUids(int $pid, int $recursion = 1, bool $exclude = true): array {
$subpagesUids = [];
$treeList = $this->queryGenerator->getTreeList($pid, $recursion, 0, 1);
$recordUids = GeneralUtility::intExplode(',', $treeList, true);
if ($recordUids) {
foreach ($recordUids as $recordUid) {
if ($this->getPage($recordUid)) {
$subpagesUids[] = $recordUid;
}
}
}
if ($exclude) {
unset($subpagesUids[0]);
}
return $subpagesUids;
} | [
"public",
"function",
"getSubpagesUids",
"(",
"int",
"$",
"pid",
",",
"int",
"$",
"recursion",
"=",
"1",
",",
"bool",
"$",
"exclude",
"=",
"true",
")",
":",
"array",
"{",
"$",
"subpagesUids",
"=",
"[",
"]",
";",
"$",
"treeList",
"=",
"$",
"this",
"->",
"queryGenerator",
"->",
"getTreeList",
"(",
"$",
"pid",
",",
"$",
"recursion",
",",
"0",
",",
"1",
")",
";",
"$",
"recordUids",
"=",
"GeneralUtility",
"::",
"intExplode",
"(",
"','",
",",
"$",
"treeList",
",",
"true",
")",
";",
"if",
"(",
"$",
"recordUids",
")",
"{",
"foreach",
"(",
"$",
"recordUids",
"as",
"$",
"recordUid",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getPage",
"(",
"$",
"recordUid",
")",
")",
"{",
"$",
"subpagesUids",
"[",
"]",
"=",
"$",
"recordUid",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"exclude",
")",
"{",
"unset",
"(",
"$",
"subpagesUids",
"[",
"0",
"]",
")",
";",
"}",
"return",
"$",
"subpagesUids",
";",
"}"
] | Gets the subpages UIDs of a page.
@param int $pid The PID of the entry page to search from
@param int $recursion The recursion level, defaults to `1`
@param bool $exclude If set, the entry page should be excluded, defaults to `true`
@return array The subpages UIDs or empty if no subpages were found | [
"Gets",
"the",
"subpages",
"UIDs",
"of",
"a",
"page",
"."
] | bab2de90f467936fbe4270cd133cb4109d1108eb | https://github.com/t3v/t3v_datamapper/blob/bab2de90f467936fbe4270cd133cb4109d1108eb/Classes/Service/PageService.php#L245-L263 | train |
squareproton/Bond | src/Bond/Normality.php | Normality.build | public function build()
{
$this->profiler->log('Build started');
$this->callbacks['log']( "normality entity builder start" );
$this->prepare();
$processing = $this->options->getMatchingRelations( $skipping );
$this->callbacks['log']( "skipping {$skipping->count()} ". $skipping->implode(', ', 'name' ) );
$this->callbacks['log']( "processing {$processing->count()}" );
// build relation
$this->profiler->log('generation begin');
$built = [];
foreach( $processing as $relation ) {
$entity = $this->buildRelation( $relation );
$this->profiler->log($entity);
$built[] = $entity;
}
$this->profiler->log('generation end');
$this->buildEntityRegistration( $built );
// remove orphan entities
$options = $this->options->prepareOptions;
if( $options & Options::REMOVE_ORPHANS ) {
if( !( $options & Options::BACKUP ) ) {
throw new IncompatibleOptionException("You cannot have Options::REMOVE_ORPHANS set if Options::BACKUP is not set");
}
$dirs = [
$this->options->getPath('entity'),
$this->options->getPath('entityPlaceholder'),
$this->options->getPath('repository'),
$this->options->getPath('repositoryPlaceholder'),
];
$files = [];
foreach( $dirs as $dir ) {
$i = new \DirectoryIterator($dir);
foreach( $i as $file ) {
if( !$file->isDot() and !$file->isDir() ) {
$files[$file->getPathname()] = substr( $file->getBasename(), 0, -4 );
}
}
}
// identify files we no longer need
$orphans = array_diff( $files, $built );
foreach( $orphans as $orphan => $entityName ) {
unlink( $orphan );
}
}
return $processing;
} | php | public function build()
{
$this->profiler->log('Build started');
$this->callbacks['log']( "normality entity builder start" );
$this->prepare();
$processing = $this->options->getMatchingRelations( $skipping );
$this->callbacks['log']( "skipping {$skipping->count()} ". $skipping->implode(', ', 'name' ) );
$this->callbacks['log']( "processing {$processing->count()}" );
// build relation
$this->profiler->log('generation begin');
$built = [];
foreach( $processing as $relation ) {
$entity = $this->buildRelation( $relation );
$this->profiler->log($entity);
$built[] = $entity;
}
$this->profiler->log('generation end');
$this->buildEntityRegistration( $built );
// remove orphan entities
$options = $this->options->prepareOptions;
if( $options & Options::REMOVE_ORPHANS ) {
if( !( $options & Options::BACKUP ) ) {
throw new IncompatibleOptionException("You cannot have Options::REMOVE_ORPHANS set if Options::BACKUP is not set");
}
$dirs = [
$this->options->getPath('entity'),
$this->options->getPath('entityPlaceholder'),
$this->options->getPath('repository'),
$this->options->getPath('repositoryPlaceholder'),
];
$files = [];
foreach( $dirs as $dir ) {
$i = new \DirectoryIterator($dir);
foreach( $i as $file ) {
if( !$file->isDot() and !$file->isDir() ) {
$files[$file->getPathname()] = substr( $file->getBasename(), 0, -4 );
}
}
}
// identify files we no longer need
$orphans = array_diff( $files, $built );
foreach( $orphans as $orphan => $entityName ) {
unlink( $orphan );
}
}
return $processing;
} | [
"public",
"function",
"build",
"(",
")",
"{",
"$",
"this",
"->",
"profiler",
"->",
"log",
"(",
"'Build started'",
")",
";",
"$",
"this",
"->",
"callbacks",
"[",
"'log'",
"]",
"(",
"\"normality entity builder start\"",
")",
";",
"$",
"this",
"->",
"prepare",
"(",
")",
";",
"$",
"processing",
"=",
"$",
"this",
"->",
"options",
"->",
"getMatchingRelations",
"(",
"$",
"skipping",
")",
";",
"$",
"this",
"->",
"callbacks",
"[",
"'log'",
"]",
"(",
"\"skipping {$skipping->count()} \"",
".",
"$",
"skipping",
"->",
"implode",
"(",
"', '",
",",
"'name'",
")",
")",
";",
"$",
"this",
"->",
"callbacks",
"[",
"'log'",
"]",
"(",
"\"processing {$processing->count()}\"",
")",
";",
"// build relation",
"$",
"this",
"->",
"profiler",
"->",
"log",
"(",
"'generation begin'",
")",
";",
"$",
"built",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"processing",
"as",
"$",
"relation",
")",
"{",
"$",
"entity",
"=",
"$",
"this",
"->",
"buildRelation",
"(",
"$",
"relation",
")",
";",
"$",
"this",
"->",
"profiler",
"->",
"log",
"(",
"$",
"entity",
")",
";",
"$",
"built",
"[",
"]",
"=",
"$",
"entity",
";",
"}",
"$",
"this",
"->",
"profiler",
"->",
"log",
"(",
"'generation end'",
")",
";",
"$",
"this",
"->",
"buildEntityRegistration",
"(",
"$",
"built",
")",
";",
"// remove orphan entities",
"$",
"options",
"=",
"$",
"this",
"->",
"options",
"->",
"prepareOptions",
";",
"if",
"(",
"$",
"options",
"&",
"Options",
"::",
"REMOVE_ORPHANS",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"options",
"&",
"Options",
"::",
"BACKUP",
")",
")",
"{",
"throw",
"new",
"IncompatibleOptionException",
"(",
"\"You cannot have Options::REMOVE_ORPHANS set if Options::BACKUP is not set\"",
")",
";",
"}",
"$",
"dirs",
"=",
"[",
"$",
"this",
"->",
"options",
"->",
"getPath",
"(",
"'entity'",
")",
",",
"$",
"this",
"->",
"options",
"->",
"getPath",
"(",
"'entityPlaceholder'",
")",
",",
"$",
"this",
"->",
"options",
"->",
"getPath",
"(",
"'repository'",
")",
",",
"$",
"this",
"->",
"options",
"->",
"getPath",
"(",
"'repositoryPlaceholder'",
")",
",",
"]",
";",
"$",
"files",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"dirs",
"as",
"$",
"dir",
")",
"{",
"$",
"i",
"=",
"new",
"\\",
"DirectoryIterator",
"(",
"$",
"dir",
")",
";",
"foreach",
"(",
"$",
"i",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"!",
"$",
"file",
"->",
"isDot",
"(",
")",
"and",
"!",
"$",
"file",
"->",
"isDir",
"(",
")",
")",
"{",
"$",
"files",
"[",
"$",
"file",
"->",
"getPathname",
"(",
")",
"]",
"=",
"substr",
"(",
"$",
"file",
"->",
"getBasename",
"(",
")",
",",
"0",
",",
"-",
"4",
")",
";",
"}",
"}",
"}",
"// identify files we no longer need",
"$",
"orphans",
"=",
"array_diff",
"(",
"$",
"files",
",",
"$",
"built",
")",
";",
"foreach",
"(",
"$",
"orphans",
"as",
"$",
"orphan",
"=>",
"$",
"entityName",
")",
"{",
"unlink",
"(",
"$",
"orphan",
")",
";",
"}",
"}",
"return",
"$",
"processing",
";",
"}"
] | Build all entities
@return int Number of jobs completed | [
"Build",
"all",
"entities"
] | a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Normality.php#L95-L160 | train |
squareproton/Bond | src/Bond/Normality.php | Normality.getEntityGenerator | public function getEntityGenerator( PgClass $pgclass, array $options, $entityFileStore )
{
// build entity
$tags = $this->getNormalityTags();
$generators = array(
'Entity' => '\Bond\Normality\Generate\Entity',
'Link' => '\Bond\Normality\Generate\Entity\Link',
'Child' => '\Bond\Normality\Generate\Entity\Child',
);
if( isset( $tags['entity'] ) ) {
$entity = $tags['entity'];
} elseif ( $parent = $this->get('parent') ) {
$entity = 'Child';
} else {
$entity = 'Entity';
}
foreach( $generators as $key => $generator ) {
if( in_array( strtolower( $entity ), array( strtolower( $key ), strtolower( $generator ) ) ) ) {
$ref = new \ReflectionClass( $generator );
return $ref->newInstance( $this, $db, $options, $entityFileStore );
}
}
throw new \RuntimeException( "No generator found for `{entity}` and relation `{$this->get('name')}`" );
} | php | public function getEntityGenerator( PgClass $pgclass, array $options, $entityFileStore )
{
// build entity
$tags = $this->getNormalityTags();
$generators = array(
'Entity' => '\Bond\Normality\Generate\Entity',
'Link' => '\Bond\Normality\Generate\Entity\Link',
'Child' => '\Bond\Normality\Generate\Entity\Child',
);
if( isset( $tags['entity'] ) ) {
$entity = $tags['entity'];
} elseif ( $parent = $this->get('parent') ) {
$entity = 'Child';
} else {
$entity = 'Entity';
}
foreach( $generators as $key => $generator ) {
if( in_array( strtolower( $entity ), array( strtolower( $key ), strtolower( $generator ) ) ) ) {
$ref = new \ReflectionClass( $generator );
return $ref->newInstance( $this, $db, $options, $entityFileStore );
}
}
throw new \RuntimeException( "No generator found for `{entity}` and relation `{$this->get('name')}`" );
} | [
"public",
"function",
"getEntityGenerator",
"(",
"PgClass",
"$",
"pgclass",
",",
"array",
"$",
"options",
",",
"$",
"entityFileStore",
")",
"{",
"// build entity",
"$",
"tags",
"=",
"$",
"this",
"->",
"getNormalityTags",
"(",
")",
";",
"$",
"generators",
"=",
"array",
"(",
"'Entity'",
"=>",
"'\\Bond\\Normality\\Generate\\Entity'",
",",
"'Link'",
"=>",
"'\\Bond\\Normality\\Generate\\Entity\\Link'",
",",
"'Child'",
"=>",
"'\\Bond\\Normality\\Generate\\Entity\\Child'",
",",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"tags",
"[",
"'entity'",
"]",
")",
")",
"{",
"$",
"entity",
"=",
"$",
"tags",
"[",
"'entity'",
"]",
";",
"}",
"elseif",
"(",
"$",
"parent",
"=",
"$",
"this",
"->",
"get",
"(",
"'parent'",
")",
")",
"{",
"$",
"entity",
"=",
"'Child'",
";",
"}",
"else",
"{",
"$",
"entity",
"=",
"'Entity'",
";",
"}",
"foreach",
"(",
"$",
"generators",
"as",
"$",
"key",
"=>",
"$",
"generator",
")",
"{",
"if",
"(",
"in_array",
"(",
"strtolower",
"(",
"$",
"entity",
")",
",",
"array",
"(",
"strtolower",
"(",
"$",
"key",
")",
",",
"strtolower",
"(",
"$",
"generator",
")",
")",
")",
")",
"{",
"$",
"ref",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"generator",
")",
";",
"return",
"$",
"ref",
"->",
"newInstance",
"(",
"$",
"this",
",",
"$",
"db",
",",
"$",
"options",
",",
"$",
"entityFileStore",
")",
";",
"}",
"}",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"No generator found for `{entity}` and relation `{$this->get('name')}`\"",
")",
";",
"}"
] | Get the entity type. Defaults to 'base'. Set by '@normality-entity: ignore';
The code that handles the output of this function can be found in 'Normality::buildRelation';
@return string | [
"Get",
"the",
"entity",
"type",
".",
"Defaults",
"to",
"base",
".",
"Set",
"by"
] | a04ad9dd1a35adeaec98237716c2a41ce02b4f1a | https://github.com/squareproton/Bond/blob/a04ad9dd1a35adeaec98237716c2a41ce02b4f1a/src/Bond/Normality.php#L328-L361 | train |
FusePump/cli.php | lib/FusePump/Cli/Timer.php | Timer.startAvg | public function startAvg($block)
{
if ($this->enabled) {
if (!isset($this->avgs[$block])) {
$this->avgs[$block] = array();
$this->avgs[$block]['count'] = 0;
$this->avgs[$block]['total'] = 0;
}
$this->avgs[$block]['start'] = microtime(true);
if (!isset($this->avgs[$block]['start-line'])) {
$this->avgs[$block]['start-line'] = $this->getLineNumber();
}
// Initialise max and min time
if (!isset($this->avgs[$block]['max-time'])) {
$this->avgs[$block]['max-time'] = 0;
}
if (!isset($this->avgs[$block]['min-time'])) {
$this->avgs[$block]['min-time'] = 9999;
}
}
} | php | public function startAvg($block)
{
if ($this->enabled) {
if (!isset($this->avgs[$block])) {
$this->avgs[$block] = array();
$this->avgs[$block]['count'] = 0;
$this->avgs[$block]['total'] = 0;
}
$this->avgs[$block]['start'] = microtime(true);
if (!isset($this->avgs[$block]['start-line'])) {
$this->avgs[$block]['start-line'] = $this->getLineNumber();
}
// Initialise max and min time
if (!isset($this->avgs[$block]['max-time'])) {
$this->avgs[$block]['max-time'] = 0;
}
if (!isset($this->avgs[$block]['min-time'])) {
$this->avgs[$block]['min-time'] = 9999;
}
}
} | [
"public",
"function",
"startAvg",
"(",
"$",
"block",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"enabled",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"avgs",
"[",
"$",
"block",
"]",
")",
")",
"{",
"$",
"this",
"->",
"avgs",
"[",
"$",
"block",
"]",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"avgs",
"[",
"$",
"block",
"]",
"[",
"'count'",
"]",
"=",
"0",
";",
"$",
"this",
"->",
"avgs",
"[",
"$",
"block",
"]",
"[",
"'total'",
"]",
"=",
"0",
";",
"}",
"$",
"this",
"->",
"avgs",
"[",
"$",
"block",
"]",
"[",
"'start'",
"]",
"=",
"microtime",
"(",
"true",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"avgs",
"[",
"$",
"block",
"]",
"[",
"'start-line'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"avgs",
"[",
"$",
"block",
"]",
"[",
"'start-line'",
"]",
"=",
"$",
"this",
"->",
"getLineNumber",
"(",
")",
";",
"}",
"// Initialise max and min time",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"avgs",
"[",
"$",
"block",
"]",
"[",
"'max-time'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"avgs",
"[",
"$",
"block",
"]",
"[",
"'max-time'",
"]",
"=",
"0",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"avgs",
"[",
"$",
"block",
"]",
"[",
"'min-time'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"avgs",
"[",
"$",
"block",
"]",
"[",
"'min-time'",
"]",
"=",
"9999",
";",
"}",
"}",
"}"
] | Start average block timer
@param string $block - key to identify block | [
"Start",
"average",
"block",
"timer"
] | 2cc92f09ce7b2f73d5cbc09f5ae4f31f3f9ae3b4 | https://github.com/FusePump/cli.php/blob/2cc92f09ce7b2f73d5cbc09f5ae4f31f3f9ae3b4/lib/FusePump/Cli/Timer.php#L116-L138 | train |
FusePump/cli.php | lib/FusePump/Cli/Timer.php | Timer.stopAvg | public function stopAvg($block)
{
if ($this->enabled) {
if (!isset($this->avgs[$block])) {
throw new \Exception('Average block '.$block.' has not been started!');
}
$this->avgs[$block]['stop'] = microtime(true);
if (!isset($this->avgs[$block]['stop-line'])) {
$this->avgs[$block]['stop-line'] = $this->getLineNumber();
}
// Calculate average
$this->avgs[$block]['count']++; // increment count
$time = $this->avgs[$block]['stop'] - $this->avgs[$block]['start'];
// Check max and min time
if ($this->avgs[$block]['max-time'] < $time) {
$this->avgs[$block]['max-time'] = $time;
}
if ($this->avgs[$block]['min-time'] > $time) {
$this->avgs[$block]['min-time'] = $time;
}
$this->avgs[$block]['total'] = $this->avgs[$block]['total'] + $time;
}
} | php | public function stopAvg($block)
{
if ($this->enabled) {
if (!isset($this->avgs[$block])) {
throw new \Exception('Average block '.$block.' has not been started!');
}
$this->avgs[$block]['stop'] = microtime(true);
if (!isset($this->avgs[$block]['stop-line'])) {
$this->avgs[$block]['stop-line'] = $this->getLineNumber();
}
// Calculate average
$this->avgs[$block]['count']++; // increment count
$time = $this->avgs[$block]['stop'] - $this->avgs[$block]['start'];
// Check max and min time
if ($this->avgs[$block]['max-time'] < $time) {
$this->avgs[$block]['max-time'] = $time;
}
if ($this->avgs[$block]['min-time'] > $time) {
$this->avgs[$block]['min-time'] = $time;
}
$this->avgs[$block]['total'] = $this->avgs[$block]['total'] + $time;
}
} | [
"public",
"function",
"stopAvg",
"(",
"$",
"block",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"enabled",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"avgs",
"[",
"$",
"block",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Average block '",
".",
"$",
"block",
".",
"' has not been started!'",
")",
";",
"}",
"$",
"this",
"->",
"avgs",
"[",
"$",
"block",
"]",
"[",
"'stop'",
"]",
"=",
"microtime",
"(",
"true",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"avgs",
"[",
"$",
"block",
"]",
"[",
"'stop-line'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"avgs",
"[",
"$",
"block",
"]",
"[",
"'stop-line'",
"]",
"=",
"$",
"this",
"->",
"getLineNumber",
"(",
")",
";",
"}",
"// Calculate average",
"$",
"this",
"->",
"avgs",
"[",
"$",
"block",
"]",
"[",
"'count'",
"]",
"++",
";",
"// increment count",
"$",
"time",
"=",
"$",
"this",
"->",
"avgs",
"[",
"$",
"block",
"]",
"[",
"'stop'",
"]",
"-",
"$",
"this",
"->",
"avgs",
"[",
"$",
"block",
"]",
"[",
"'start'",
"]",
";",
"// Check max and min time",
"if",
"(",
"$",
"this",
"->",
"avgs",
"[",
"$",
"block",
"]",
"[",
"'max-time'",
"]",
"<",
"$",
"time",
")",
"{",
"$",
"this",
"->",
"avgs",
"[",
"$",
"block",
"]",
"[",
"'max-time'",
"]",
"=",
"$",
"time",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"avgs",
"[",
"$",
"block",
"]",
"[",
"'min-time'",
"]",
">",
"$",
"time",
")",
"{",
"$",
"this",
"->",
"avgs",
"[",
"$",
"block",
"]",
"[",
"'min-time'",
"]",
"=",
"$",
"time",
";",
"}",
"$",
"this",
"->",
"avgs",
"[",
"$",
"block",
"]",
"[",
"'total'",
"]",
"=",
"$",
"this",
"->",
"avgs",
"[",
"$",
"block",
"]",
"[",
"'total'",
"]",
"+",
"$",
"time",
";",
"}",
"}"
] | Stop average block and calculate average
@param string $block - average block identifier
@throws \Exception if block not defined | [
"Stop",
"average",
"block",
"and",
"calculate",
"average"
] | 2cc92f09ce7b2f73d5cbc09f5ae4f31f3f9ae3b4 | https://github.com/FusePump/cli.php/blob/2cc92f09ce7b2f73d5cbc09f5ae4f31f3f9ae3b4/lib/FusePump/Cli/Timer.php#L147-L174 | train |
FusePump/cli.php | lib/FusePump/Cli/Timer.php | Timer.printAvgBlock | private function printAvgBlock($block)
{
if (!array_key_exists($block, $this->avgs)) {
throw new \Exception('Average block '.$block.' not defined');
}
$this->finishAvgBlock($block);
$output = "";
$output .= " $block";
$output .= " [".$this->avgs[$block]['count']."]";
$output .= " (".$this->avgs[$block]['start-line']."-".$this->avgs[$block]['stop-line'].")";
$output .= ": ";
$output .= round($this->avgs[$block]['avg'], 4);
$output .= ' seconds';
$output .= PHP_EOL;
// Output max and min time
$output .= " max time: ".round($this->avgs[$block]['max-time'], 4).PHP_EOL;
$output .= " min time: ".round($this->avgs[$block]['min-time'], 4).PHP_EOL;
return $output;
} | php | private function printAvgBlock($block)
{
if (!array_key_exists($block, $this->avgs)) {
throw new \Exception('Average block '.$block.' not defined');
}
$this->finishAvgBlock($block);
$output = "";
$output .= " $block";
$output .= " [".$this->avgs[$block]['count']."]";
$output .= " (".$this->avgs[$block]['start-line']."-".$this->avgs[$block]['stop-line'].")";
$output .= ": ";
$output .= round($this->avgs[$block]['avg'], 4);
$output .= ' seconds';
$output .= PHP_EOL;
// Output max and min time
$output .= " max time: ".round($this->avgs[$block]['max-time'], 4).PHP_EOL;
$output .= " min time: ".round($this->avgs[$block]['min-time'], 4).PHP_EOL;
return $output;
} | [
"private",
"function",
"printAvgBlock",
"(",
"$",
"block",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"block",
",",
"$",
"this",
"->",
"avgs",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Average block '",
".",
"$",
"block",
".",
"' not defined'",
")",
";",
"}",
"$",
"this",
"->",
"finishAvgBlock",
"(",
"$",
"block",
")",
";",
"$",
"output",
"=",
"\"\"",
";",
"$",
"output",
".=",
"\" $block\"",
";",
"$",
"output",
".=",
"\" [\"",
".",
"$",
"this",
"->",
"avgs",
"[",
"$",
"block",
"]",
"[",
"'count'",
"]",
".",
"\"]\"",
";",
"$",
"output",
".=",
"\" (\"",
".",
"$",
"this",
"->",
"avgs",
"[",
"$",
"block",
"]",
"[",
"'start-line'",
"]",
".",
"\"-\"",
".",
"$",
"this",
"->",
"avgs",
"[",
"$",
"block",
"]",
"[",
"'stop-line'",
"]",
".",
"\")\"",
";",
"$",
"output",
".=",
"\": \"",
";",
"$",
"output",
".=",
"round",
"(",
"$",
"this",
"->",
"avgs",
"[",
"$",
"block",
"]",
"[",
"'avg'",
"]",
",",
"4",
")",
";",
"$",
"output",
".=",
"' seconds'",
";",
"$",
"output",
".=",
"PHP_EOL",
";",
"// Output max and min time",
"$",
"output",
".=",
"\" max time: \"",
".",
"round",
"(",
"$",
"this",
"->",
"avgs",
"[",
"$",
"block",
"]",
"[",
"'max-time'",
"]",
",",
"4",
")",
".",
"PHP_EOL",
";",
"$",
"output",
".=",
"\" min time: \"",
".",
"round",
"(",
"$",
"this",
"->",
"avgs",
"[",
"$",
"block",
"]",
"[",
"'min-time'",
"]",
",",
"4",
")",
".",
"PHP_EOL",
";",
"return",
"$",
"output",
";",
"}"
] | Print average block
@param string $block - key to identify block
@return string output
@throws \Exception if block not defined | [
"Print",
"average",
"block"
] | 2cc92f09ce7b2f73d5cbc09f5ae4f31f3f9ae3b4 | https://github.com/FusePump/cli.php/blob/2cc92f09ce7b2f73d5cbc09f5ae4f31f3f9ae3b4/lib/FusePump/Cli/Timer.php#L249-L270 | train |
FusePump/cli.php | lib/FusePump/Cli/Timer.php | Timer.get | public function get($block)
{
if ($this->enabled) {
if (!array_key_exists($block, $this->blocks)) {
throw new \Exception('Block '.$block.' not defined');
}
$this->finishBlock($block);
return $this->blocks[$block];
}
} | php | public function get($block)
{
if ($this->enabled) {
if (!array_key_exists($block, $this->blocks)) {
throw new \Exception('Block '.$block.' not defined');
}
$this->finishBlock($block);
return $this->blocks[$block];
}
} | [
"public",
"function",
"get",
"(",
"$",
"block",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"enabled",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"block",
",",
"$",
"this",
"->",
"blocks",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Block '",
".",
"$",
"block",
".",
"' not defined'",
")",
";",
"}",
"$",
"this",
"->",
"finishBlock",
"(",
"$",
"block",
")",
";",
"return",
"$",
"this",
"->",
"blocks",
"[",
"$",
"block",
"]",
";",
"}",
"}"
] | Get block info
@param string $block - key to identify block
@return mixed - associative array
@throws \Exception if block not defined | [
"Get",
"block",
"info"
] | 2cc92f09ce7b2f73d5cbc09f5ae4f31f3f9ae3b4 | https://github.com/FusePump/cli.php/blob/2cc92f09ce7b2f73d5cbc09f5ae4f31f3f9ae3b4/lib/FusePump/Cli/Timer.php#L291-L302 | train |
FusePump/cli.php | lib/FusePump/Cli/Timer.php | Timer.getAvg | public function getAvg($block)
{
if ($this->enabled) {
if (!array_key_exists($block, $this->avgs)) {
throw new \Exception('Average block '.$block.' not defined');
}
$this->finishAvgBlock($block);
return $this->avgs[$block];
}
} | php | public function getAvg($block)
{
if ($this->enabled) {
if (!array_key_exists($block, $this->avgs)) {
throw new \Exception('Average block '.$block.' not defined');
}
$this->finishAvgBlock($block);
return $this->avgs[$block];
}
} | [
"public",
"function",
"getAvg",
"(",
"$",
"block",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"enabled",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"block",
",",
"$",
"this",
"->",
"avgs",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Average block '",
".",
"$",
"block",
".",
"' not defined'",
")",
";",
"}",
"$",
"this",
"->",
"finishAvgBlock",
"(",
"$",
"block",
")",
";",
"return",
"$",
"this",
"->",
"avgs",
"[",
"$",
"block",
"]",
";",
"}",
"}"
] | Get average block info
@param string $block - key to identify block
@return mixed - associative array
@throws \Exception | [
"Get",
"average",
"block",
"info"
] | 2cc92f09ce7b2f73d5cbc09f5ae4f31f3f9ae3b4 | https://github.com/FusePump/cli.php/blob/2cc92f09ce7b2f73d5cbc09f5ae4f31f3f9ae3b4/lib/FusePump/Cli/Timer.php#L312-L323 | train |
FusePump/cli.php | lib/FusePump/Cli/Timer.php | Timer.finishAvgBlock | private function finishAvgBlock($block)
{
if (!array_key_exists($block, $this->avgs)) {
throw new \Exception('Average block '.$block.' not defined');
}
$this->avgs[$block]['avg'] = $this->avgs[$block]['total'] / $this->avgs[$block]['count'];
return $this->avgs[$block];
} | php | private function finishAvgBlock($block)
{
if (!array_key_exists($block, $this->avgs)) {
throw new \Exception('Average block '.$block.' not defined');
}
$this->avgs[$block]['avg'] = $this->avgs[$block]['total'] / $this->avgs[$block]['count'];
return $this->avgs[$block];
} | [
"private",
"function",
"finishAvgBlock",
"(",
"$",
"block",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"block",
",",
"$",
"this",
"->",
"avgs",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Average block '",
".",
"$",
"block",
".",
"' not defined'",
")",
";",
"}",
"$",
"this",
"->",
"avgs",
"[",
"$",
"block",
"]",
"[",
"'avg'",
"]",
"=",
"$",
"this",
"->",
"avgs",
"[",
"$",
"block",
"]",
"[",
"'total'",
"]",
"/",
"$",
"this",
"->",
"avgs",
"[",
"$",
"block",
"]",
"[",
"'count'",
"]",
";",
"return",
"$",
"this",
"->",
"avgs",
"[",
"$",
"block",
"]",
";",
"}"
] | Finish average block
@param string $block - key to identify block
@return mixed
@throws \Exception | [
"Finish",
"average",
"block"
] | 2cc92f09ce7b2f73d5cbc09f5ae4f31f3f9ae3b4 | https://github.com/FusePump/cli.php/blob/2cc92f09ce7b2f73d5cbc09f5ae4f31f3f9ae3b4/lib/FusePump/Cli/Timer.php#L351-L359 | train |
marando/Units | src/Marando/Units/Distance.php | Distance.create | public static function create($value, $symbol)
{
// Find the conversion factor to meters
$factor = static::factorToMeters($symbol);
// Ensure proper formatting of value and factor for bc math
$value = number_format($value, static::$s, '.', '');
$factor = number_format($factor, static::$s, '.', '');
// Convert to meters
$meters = bcmul($value, $factor, static::$s);
// Create new distance.
$dist = new static($meters);
$dist->format(static::FORMAT_DEFAULT . $symbol);
return $dist;
} | php | public static function create($value, $symbol)
{
// Find the conversion factor to meters
$factor = static::factorToMeters($symbol);
// Ensure proper formatting of value and factor for bc math
$value = number_format($value, static::$s, '.', '');
$factor = number_format($factor, static::$s, '.', '');
// Convert to meters
$meters = bcmul($value, $factor, static::$s);
// Create new distance.
$dist = new static($meters);
$dist->format(static::FORMAT_DEFAULT . $symbol);
return $dist;
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"value",
",",
"$",
"symbol",
")",
"{",
"// Find the conversion factor to meters",
"$",
"factor",
"=",
"static",
"::",
"factorToMeters",
"(",
"$",
"symbol",
")",
";",
"// Ensure proper formatting of value and factor for bc math",
"$",
"value",
"=",
"number_format",
"(",
"$",
"value",
",",
"static",
"::",
"$",
"s",
",",
"'.'",
",",
"''",
")",
";",
"$",
"factor",
"=",
"number_format",
"(",
"$",
"factor",
",",
"static",
"::",
"$",
"s",
",",
"'.'",
",",
"''",
")",
";",
"// Convert to meters",
"$",
"meters",
"=",
"bcmul",
"(",
"$",
"value",
",",
"$",
"factor",
",",
"static",
"::",
"$",
"s",
")",
";",
"// Create new distance.",
"$",
"dist",
"=",
"new",
"static",
"(",
"$",
"meters",
")",
";",
"$",
"dist",
"->",
"format",
"(",
"static",
"::",
"FORMAT_DEFAULT",
".",
"$",
"symbol",
")",
";",
"return",
"$",
"dist",
";",
"}"
] | Creates a new distance from a value and symbol.
@param double|string $value Value of the distance
@param string $symbol Symbol of the distance, e.g. m or km
@return static | [
"Creates",
"a",
"new",
"distance",
"from",
"a",
"value",
"and",
"symbol",
"."
] | 1721f16a2fdbd3fd8acb9061d393ce9ef1ce6e70 | https://github.com/marando/Units/blob/1721f16a2fdbd3fd8acb9061d393ce9ef1ce6e70/src/Marando/Units/Distance.php#L88-L105 | train |
marando/Units | src/Marando/Units/Distance.php | Distance.unit | public function unit($symbol, $string = false)
{
// Format instance's meter value and factor to the specified unit.
$m = number_format($this->m, static::$s, '.', '');
$fact = number_format(static::factorToMeters($symbol), static::$s, '.',
'');
// Divide the meters by the factor and trim end of zeros
$unit = bcdiv($m, $fact, static::$s);
$unit = static::removeTrailingZeros($unit);
// Return rounded double value, or string value.
return $string ? $unit : round($unit, 20);
} | php | public function unit($symbol, $string = false)
{
// Format instance's meter value and factor to the specified unit.
$m = number_format($this->m, static::$s, '.', '');
$fact = number_format(static::factorToMeters($symbol), static::$s, '.',
'');
// Divide the meters by the factor and trim end of zeros
$unit = bcdiv($m, $fact, static::$s);
$unit = static::removeTrailingZeros($unit);
// Return rounded double value, or string value.
return $string ? $unit : round($unit, 20);
} | [
"public",
"function",
"unit",
"(",
"$",
"symbol",
",",
"$",
"string",
"=",
"false",
")",
"{",
"// Format instance's meter value and factor to the specified unit.",
"$",
"m",
"=",
"number_format",
"(",
"$",
"this",
"->",
"m",
",",
"static",
"::",
"$",
"s",
",",
"'.'",
",",
"''",
")",
";",
"$",
"fact",
"=",
"number_format",
"(",
"static",
"::",
"factorToMeters",
"(",
"$",
"symbol",
")",
",",
"static",
"::",
"$",
"s",
",",
"'.'",
",",
"''",
")",
";",
"// Divide the meters by the factor and trim end of zeros",
"$",
"unit",
"=",
"bcdiv",
"(",
"$",
"m",
",",
"$",
"fact",
",",
"static",
"::",
"$",
"s",
")",
";",
"$",
"unit",
"=",
"static",
"::",
"removeTrailingZeros",
"(",
"$",
"unit",
")",
";",
"// Return rounded double value, or string value.",
"return",
"$",
"string",
"?",
"$",
"unit",
":",
"round",
"(",
"$",
"unit",
",",
"20",
")",
";",
"}"
] | Returns the value of this instance at the specified unit optionally as
a string with higher precision.
@param string $symbol Symbol of the unit to obtain
@param bool $string True to return as string, false for double
@return double|string | [
"Returns",
"the",
"value",
"of",
"this",
"instance",
"at",
"the",
"specified",
"unit",
"optionally",
"as",
"a",
"string",
"with",
"higher",
"precision",
"."
] | 1721f16a2fdbd3fd8acb9061d393ce9ef1ce6e70 | https://github.com/marando/Units/blob/1721f16a2fdbd3fd8acb9061d393ce9ef1ce6e70/src/Marando/Units/Distance.php#L449-L462 | train |
marando/Units | src/Marando/Units/Distance.php | Distance.add | public function add(Distance $b)
{
return Distance::m(bcadd($this->m, $b->m), static::$s);
} | php | public function add(Distance $b)
{
return Distance::m(bcadd($this->m, $b->m), static::$s);
} | [
"public",
"function",
"add",
"(",
"Distance",
"$",
"b",
")",
"{",
"return",
"Distance",
"::",
"m",
"(",
"bcadd",
"(",
"$",
"this",
"->",
"m",
",",
"$",
"b",
"->",
"m",
")",
",",
"static",
"::",
"$",
"s",
")",
";",
"}"
] | Adds another distance to this instance and returns a new instance with
the sum.
@param Distance $b Distance to add
@return static Sum of the two distances | [
"Adds",
"another",
"distance",
"to",
"this",
"instance",
"and",
"returns",
"a",
"new",
"instance",
"with",
"the",
"sum",
"."
] | 1721f16a2fdbd3fd8acb9061d393ce9ef1ce6e70 | https://github.com/marando/Units/blob/1721f16a2fdbd3fd8acb9061d393ce9ef1ce6e70/src/Marando/Units/Distance.php#L502-L505 | train |
marando/Units | src/Marando/Units/Distance.php | Distance.sub | public function sub(Distance $b)
{
return Distance::m(bcsub($this->m, $b->m), static::$s);
} | php | public function sub(Distance $b)
{
return Distance::m(bcsub($this->m, $b->m), static::$s);
} | [
"public",
"function",
"sub",
"(",
"Distance",
"$",
"b",
")",
"{",
"return",
"Distance",
"::",
"m",
"(",
"bcsub",
"(",
"$",
"this",
"->",
"m",
",",
"$",
"b",
"->",
"m",
")",
",",
"static",
"::",
"$",
"s",
")",
";",
"}"
] | Subtracts another distance from this instance and returns a new instance
with the difference.
@param Distance $b Distance to subtract
@return static Difference of the two distances | [
"Subtracts",
"another",
"distance",
"from",
"this",
"instance",
"and",
"returns",
"a",
"new",
"instance",
"with",
"the",
"difference",
"."
] | 1721f16a2fdbd3fd8acb9061d393ce9ef1ce6e70 | https://github.com/marando/Units/blob/1721f16a2fdbd3fd8acb9061d393ce9ef1ce6e70/src/Marando/Units/Distance.php#L515-L518 | train |
marando/Units | src/Marando/Units/Distance.php | Distance.format | public function format($format)
{
// Sprintf and unit regex
$pattern = '/(%(?:\d+\$)?[+-]?(?:[ 0]|\'.{1})?-?\d*(?:\.\d+)?[bcdeEufFgGosxX])(.*)/';
// Check if string has sprintf and unit...
if (preg_match_all($pattern, $format, $m)) {
// Valid format, save to instance.
$this->format = $format;
// Get sprintf and units
$sprintf = $m[1][0];
$unit = $m[2][0];
// Try to find value of instance at specified units.
$value = $this->{trim($unit)};
if ($value == 0) {
$value = $this->{strtolower(trim($unit))};
if ($value == 0) {
$value = $this->{strtoupper(trim($unit))};
}
}
// Should just display as scientific notation?
if (sprintf($sprintf, $value) == 0 || $value > 10e9) {
// Change sprintf to use e for scientific notation
$sprintf = preg_replace('/[bcdeEufFgGosxX]/', 'e', $sprintf);
}
// Return value with format and unit suffix.
return sprintf($sprintf, $value) . $unit;
} else {
// No valid format found, use old format.
if (preg_match_all($pattern, $this->format, $m)) {
return $this->format(
str_replace(trim($m[2][0]), '', $m[0][0]) . $format);
}
}
} | php | public function format($format)
{
// Sprintf and unit regex
$pattern = '/(%(?:\d+\$)?[+-]?(?:[ 0]|\'.{1})?-?\d*(?:\.\d+)?[bcdeEufFgGosxX])(.*)/';
// Check if string has sprintf and unit...
if (preg_match_all($pattern, $format, $m)) {
// Valid format, save to instance.
$this->format = $format;
// Get sprintf and units
$sprintf = $m[1][0];
$unit = $m[2][0];
// Try to find value of instance at specified units.
$value = $this->{trim($unit)};
if ($value == 0) {
$value = $this->{strtolower(trim($unit))};
if ($value == 0) {
$value = $this->{strtoupper(trim($unit))};
}
}
// Should just display as scientific notation?
if (sprintf($sprintf, $value) == 0 || $value > 10e9) {
// Change sprintf to use e for scientific notation
$sprintf = preg_replace('/[bcdeEufFgGosxX]/', 'e', $sprintf);
}
// Return value with format and unit suffix.
return sprintf($sprintf, $value) . $unit;
} else {
// No valid format found, use old format.
if (preg_match_all($pattern, $this->format, $m)) {
return $this->format(
str_replace(trim($m[2][0]), '', $m[0][0]) . $format);
}
}
} | [
"public",
"function",
"format",
"(",
"$",
"format",
")",
"{",
"// Sprintf and unit regex",
"$",
"pattern",
"=",
"'/(%(?:\\d+\\$)?[+-]?(?:[ 0]|\\'.{1})?-?\\d*(?:\\.\\d+)?[bcdeEufFgGosxX])(.*)/'",
";",
"// Check if string has sprintf and unit...",
"if",
"(",
"preg_match_all",
"(",
"$",
"pattern",
",",
"$",
"format",
",",
"$",
"m",
")",
")",
"{",
"// Valid format, save to instance.",
"$",
"this",
"->",
"format",
"=",
"$",
"format",
";",
"// Get sprintf and units",
"$",
"sprintf",
"=",
"$",
"m",
"[",
"1",
"]",
"[",
"0",
"]",
";",
"$",
"unit",
"=",
"$",
"m",
"[",
"2",
"]",
"[",
"0",
"]",
";",
"// Try to find value of instance at specified units.",
"$",
"value",
"=",
"$",
"this",
"->",
"{",
"trim",
"(",
"$",
"unit",
")",
"}",
";",
"if",
"(",
"$",
"value",
"==",
"0",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"{",
"strtolower",
"(",
"trim",
"(",
"$",
"unit",
")",
")",
"}",
";",
"if",
"(",
"$",
"value",
"==",
"0",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"{",
"strtoupper",
"(",
"trim",
"(",
"$",
"unit",
")",
")",
"}",
";",
"}",
"}",
"// Should just display as scientific notation?",
"if",
"(",
"sprintf",
"(",
"$",
"sprintf",
",",
"$",
"value",
")",
"==",
"0",
"||",
"$",
"value",
">",
"10e9",
")",
"{",
"// Change sprintf to use e for scientific notation",
"$",
"sprintf",
"=",
"preg_replace",
"(",
"'/[bcdeEufFgGosxX]/'",
",",
"'e'",
",",
"$",
"sprintf",
")",
";",
"}",
"// Return value with format and unit suffix.",
"return",
"sprintf",
"(",
"$",
"sprintf",
",",
"$",
"value",
")",
".",
"$",
"unit",
";",
"}",
"else",
"{",
"// No valid format found, use old format.",
"if",
"(",
"preg_match_all",
"(",
"$",
"pattern",
",",
"$",
"this",
"->",
"format",
",",
"$",
"m",
")",
")",
"{",
"return",
"$",
"this",
"->",
"format",
"(",
"str_replace",
"(",
"trim",
"(",
"$",
"m",
"[",
"2",
"]",
"[",
"0",
"]",
")",
",",
"''",
",",
"$",
"m",
"[",
"0",
"]",
"[",
"0",
"]",
")",
".",
"$",
"format",
")",
";",
"}",
"}",
"}"
] | Formats this instance in the specified strign format.
@param string $format Formatter string, e.g. %01.3f au
@return string | [
"Formats",
"this",
"instance",
"in",
"the",
"specified",
"strign",
"format",
"."
] | 1721f16a2fdbd3fd8acb9061d393ce9ef1ce6e70 | https://github.com/marando/Units/blob/1721f16a2fdbd3fd8acb9061d393ce9ef1ce6e70/src/Marando/Units/Distance.php#L563-L601 | train |
ekyna/MediaBundle | Listener/MediaListener.php | MediaListener.cleanTranslations | private function cleanTranslations(MediaInterface $media)
{
foreach ($media->getTranslations() as $trans) {
if (0 == strlen($trans->getTitle()) && 0 == strlen($trans->getDescription())) {
$media->removeTranslation($trans);
}
}
} | php | private function cleanTranslations(MediaInterface $media)
{
foreach ($media->getTranslations() as $trans) {
if (0 == strlen($trans->getTitle()) && 0 == strlen($trans->getDescription())) {
$media->removeTranslation($trans);
}
}
} | [
"private",
"function",
"cleanTranslations",
"(",
"MediaInterface",
"$",
"media",
")",
"{",
"foreach",
"(",
"$",
"media",
"->",
"getTranslations",
"(",
")",
"as",
"$",
"trans",
")",
"{",
"if",
"(",
"0",
"==",
"strlen",
"(",
"$",
"trans",
"->",
"getTitle",
"(",
")",
")",
"&&",
"0",
"==",
"strlen",
"(",
"$",
"trans",
"->",
"getDescription",
"(",
")",
")",
")",
"{",
"$",
"media",
"->",
"removeTranslation",
"(",
"$",
"trans",
")",
";",
"}",
"}",
"}"
] | Removes empty translations
@param MediaInterface $media | [
"Removes",
"empty",
"translations"
] | 512cf86c801a130a9f17eba8b48d646d23acdbab | https://github.com/ekyna/MediaBundle/blob/512cf86c801a130a9f17eba8b48d646d23acdbab/Listener/MediaListener.php#L96-L103 | train |
agentmedia/phine-core | src/Core/Modules/Backend/AjaxPageParams.php | AjaxPageParams.AddOptionalParamsField | private function AddOptionalParamsField()
{
$name = 'OptionalParameters';
$field = new Textarea($name, $this->OptionalParamsText());
$this->AddField($field);
$this->SetTransAttribute($name, 'placeholder');
} | php | private function AddOptionalParamsField()
{
$name = 'OptionalParameters';
$field = new Textarea($name, $this->OptionalParamsText());
$this->AddField($field);
$this->SetTransAttribute($name, 'placeholder');
} | [
"private",
"function",
"AddOptionalParamsField",
"(",
")",
"{",
"$",
"name",
"=",
"'OptionalParameters'",
";",
"$",
"field",
"=",
"new",
"Textarea",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"OptionalParamsText",
"(",
")",
")",
";",
"$",
"this",
"->",
"AddField",
"(",
"$",
"field",
")",
";",
"$",
"this",
"->",
"SetTransAttribute",
"(",
"$",
"name",
",",
"'placeholder'",
")",
";",
"}"
] | Adds the optional parameters textarea | [
"Adds",
"the",
"optional",
"parameters",
"textarea"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/AjaxPageParams.php#L76-L82 | train |
agentmedia/phine-core | src/Core/Modules/Backend/AjaxPageParams.php | AjaxPageParams.AddFragmentField | private function AddFragmentField()
{
$name = 'Fragment';
$field = Input::Text($name, Request::GetData($this->prefix . 'Fragment'));
$this->AddField($field);
$this->SetTransAttribute($name, 'placeholder');
} | php | private function AddFragmentField()
{
$name = 'Fragment';
$field = Input::Text($name, Request::GetData($this->prefix . 'Fragment'));
$this->AddField($field);
$this->SetTransAttribute($name, 'placeholder');
} | [
"private",
"function",
"AddFragmentField",
"(",
")",
"{",
"$",
"name",
"=",
"'Fragment'",
";",
"$",
"field",
"=",
"Input",
"::",
"Text",
"(",
"$",
"name",
",",
"Request",
"::",
"GetData",
"(",
"$",
"this",
"->",
"prefix",
".",
"'Fragment'",
")",
")",
";",
"$",
"this",
"->",
"AddField",
"(",
"$",
"field",
")",
";",
"$",
"this",
"->",
"SetTransAttribute",
"(",
"$",
"name",
",",
"'placeholder'",
")",
";",
"}"
] | Adds the fragment field | [
"Adds",
"the",
"fragment",
"field"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/AjaxPageParams.php#L86-L92 | train |
agentmedia/phine-core | src/Core/Modules/Backend/AjaxPageParams.php | AjaxPageParams.OptionalParamsText | private function OptionalParamsText()
{
$params = $this->params;
foreach ($this->oblParams as $name)
{
unset($params[$name]);
}
return $this->serializer->ArrayToLines($params);
} | php | private function OptionalParamsText()
{
$params = $this->params;
foreach ($this->oblParams as $name)
{
unset($params[$name]);
}
return $this->serializer->ArrayToLines($params);
} | [
"private",
"function",
"OptionalParamsText",
"(",
")",
"{",
"$",
"params",
"=",
"$",
"this",
"->",
"params",
";",
"foreach",
"(",
"$",
"this",
"->",
"oblParams",
"as",
"$",
"name",
")",
"{",
"unset",
"(",
"$",
"params",
"[",
"$",
"name",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"serializer",
"->",
"ArrayToLines",
"(",
"$",
"params",
")",
";",
"}"
] | The field value of the optional paramaters
@return string Returns the optional parameters as multiline text | [
"The",
"field",
"value",
"of",
"the",
"optional",
"paramaters"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/AjaxPageParams.php#L97-L105 | train |
agentmedia/phine-core | src/Core/Modules/Backend/AjaxPageParams.php | AjaxPageParams.OnSuccess | protected function OnSuccess()
{
$allParams = array();
foreach ($this->oblParams as $param)
{
if ($this->Value($param)) {
$allParams[$param] = $this->Value($param);
}
}
$optParams = $this->serializer->LinesToArray($this->Value('OptionalParameters'));
foreach ($optParams as $name=>$value)
{
if (!isset($allParams[$name]))
{
$allParams[$name] = $value;
}
}
$this->SetJSFieldValue('#' . $this->prefix . 'Params', $this->serializer->ArrayToLines($allParams));
$this->SetJSFieldValue('#' . $this->prefix . 'Page', $this->page->GetID());
$this->SetJSFieldValue('#' . $this->prefix . 'Fragment', $this->Value('Fragment'));
$this->SetJSHtml('#' . $this->prefix . 'Url', FrontendRouter::PageUrl($this->page, $allParams, $this->Value('Fragment')));
$this->CloseModal();
} | php | protected function OnSuccess()
{
$allParams = array();
foreach ($this->oblParams as $param)
{
if ($this->Value($param)) {
$allParams[$param] = $this->Value($param);
}
}
$optParams = $this->serializer->LinesToArray($this->Value('OptionalParameters'));
foreach ($optParams as $name=>$value)
{
if (!isset($allParams[$name]))
{
$allParams[$name] = $value;
}
}
$this->SetJSFieldValue('#' . $this->prefix . 'Params', $this->serializer->ArrayToLines($allParams));
$this->SetJSFieldValue('#' . $this->prefix . 'Page', $this->page->GetID());
$this->SetJSFieldValue('#' . $this->prefix . 'Fragment', $this->Value('Fragment'));
$this->SetJSHtml('#' . $this->prefix . 'Url', FrontendRouter::PageUrl($this->page, $allParams, $this->Value('Fragment')));
$this->CloseModal();
} | [
"protected",
"function",
"OnSuccess",
"(",
")",
"{",
"$",
"allParams",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"oblParams",
"as",
"$",
"param",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"Value",
"(",
"$",
"param",
")",
")",
"{",
"$",
"allParams",
"[",
"$",
"param",
"]",
"=",
"$",
"this",
"->",
"Value",
"(",
"$",
"param",
")",
";",
"}",
"}",
"$",
"optParams",
"=",
"$",
"this",
"->",
"serializer",
"->",
"LinesToArray",
"(",
"$",
"this",
"->",
"Value",
"(",
"'OptionalParameters'",
")",
")",
";",
"foreach",
"(",
"$",
"optParams",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"allParams",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"allParams",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"$",
"this",
"->",
"SetJSFieldValue",
"(",
"'#'",
".",
"$",
"this",
"->",
"prefix",
".",
"'Params'",
",",
"$",
"this",
"->",
"serializer",
"->",
"ArrayToLines",
"(",
"$",
"allParams",
")",
")",
";",
"$",
"this",
"->",
"SetJSFieldValue",
"(",
"'#'",
".",
"$",
"this",
"->",
"prefix",
".",
"'Page'",
",",
"$",
"this",
"->",
"page",
"->",
"GetID",
"(",
")",
")",
";",
"$",
"this",
"->",
"SetJSFieldValue",
"(",
"'#'",
".",
"$",
"this",
"->",
"prefix",
".",
"'Fragment'",
",",
"$",
"this",
"->",
"Value",
"(",
"'Fragment'",
")",
")",
";",
"$",
"this",
"->",
"SetJSHtml",
"(",
"'#'",
".",
"$",
"this",
"->",
"prefix",
".",
"'Url'",
",",
"FrontendRouter",
"::",
"PageUrl",
"(",
"$",
"this",
"->",
"page",
",",
"$",
"allParams",
",",
"$",
"this",
"->",
"Value",
"(",
"'Fragment'",
")",
")",
")",
";",
"$",
"this",
"->",
"CloseModal",
"(",
")",
";",
"}"
] | Saves the page selection | [
"Saves",
"the",
"page",
"selection"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/AjaxPageParams.php#L110-L132 | train |
pickles2/px2-publish-ex | php/publish.php | publish.cli_header | private function cli_header(){
ob_start();
print $this->px->pxcmd()->get_cli_header();
print 'publish directory(tmp): '.$this->path_tmp_publish."\n";
print 'lockfile: '.$this->path_lockfile."\n";
print 'publish directory: '.$this->path_publish_dir."\n";
print 'domain: '.$this->domain."\n";
print 'docroot directory: '.$this->path_docroot."\n";
print 'ignore: '.join(', ', $this->plugin_conf->paths_ignore)."\n";
print 'region: '.join(', ', $this->paths_region)."\n";
print 'ignore (tmp): '.join(', ', $this->paths_ignore)."\n";
print 'keep cache: '.($this->flg_keep_cache ? 'true' : 'false')."\n";
print 'devices:'."\n";
foreach($this->plugin_conf->devices as $key=>$device){
print ' - device['.$key.']:'."\n";
print ' - user_agent: '.$device->user_agent."\n";
print ' - path_publish_dir: '.$device->path_publish_dir."\n";
print ' - path_rewrite_rule: '.$device->path_rewrite_rule."\n";
print ' - paths_target: '.(is_array($device->paths_target) ? join(', ', $device->paths_target) : '')."\n";
print ' - paths_ignore: '.(is_array($device->paths_ignore) ? join(', ', $device->paths_ignore) : '')."\n";
print ' - rewrite_direction: '.$device->rewrite_direction."\n";
}
print 'skip default device: '.($this->plugin_conf->skip_default_device ? 'true' : 'false')."\n";
print '------------'."\n";
flush();
return ob_get_clean();
} | php | private function cli_header(){
ob_start();
print $this->px->pxcmd()->get_cli_header();
print 'publish directory(tmp): '.$this->path_tmp_publish."\n";
print 'lockfile: '.$this->path_lockfile."\n";
print 'publish directory: '.$this->path_publish_dir."\n";
print 'domain: '.$this->domain."\n";
print 'docroot directory: '.$this->path_docroot."\n";
print 'ignore: '.join(', ', $this->plugin_conf->paths_ignore)."\n";
print 'region: '.join(', ', $this->paths_region)."\n";
print 'ignore (tmp): '.join(', ', $this->paths_ignore)."\n";
print 'keep cache: '.($this->flg_keep_cache ? 'true' : 'false')."\n";
print 'devices:'."\n";
foreach($this->plugin_conf->devices as $key=>$device){
print ' - device['.$key.']:'."\n";
print ' - user_agent: '.$device->user_agent."\n";
print ' - path_publish_dir: '.$device->path_publish_dir."\n";
print ' - path_rewrite_rule: '.$device->path_rewrite_rule."\n";
print ' - paths_target: '.(is_array($device->paths_target) ? join(', ', $device->paths_target) : '')."\n";
print ' - paths_ignore: '.(is_array($device->paths_ignore) ? join(', ', $device->paths_ignore) : '')."\n";
print ' - rewrite_direction: '.$device->rewrite_direction."\n";
}
print 'skip default device: '.($this->plugin_conf->skip_default_device ? 'true' : 'false')."\n";
print '------------'."\n";
flush();
return ob_get_clean();
} | [
"private",
"function",
"cli_header",
"(",
")",
"{",
"ob_start",
"(",
")",
";",
"print",
"$",
"this",
"->",
"px",
"->",
"pxcmd",
"(",
")",
"->",
"get_cli_header",
"(",
")",
";",
"print",
"'publish directory(tmp): '",
".",
"$",
"this",
"->",
"path_tmp_publish",
".",
"\"\\n\"",
";",
"print",
"'lockfile: '",
".",
"$",
"this",
"->",
"path_lockfile",
".",
"\"\\n\"",
";",
"print",
"'publish directory: '",
".",
"$",
"this",
"->",
"path_publish_dir",
".",
"\"\\n\"",
";",
"print",
"'domain: '",
".",
"$",
"this",
"->",
"domain",
".",
"\"\\n\"",
";",
"print",
"'docroot directory: '",
".",
"$",
"this",
"->",
"path_docroot",
".",
"\"\\n\"",
";",
"print",
"'ignore: '",
".",
"join",
"(",
"', '",
",",
"$",
"this",
"->",
"plugin_conf",
"->",
"paths_ignore",
")",
".",
"\"\\n\"",
";",
"print",
"'region: '",
".",
"join",
"(",
"', '",
",",
"$",
"this",
"->",
"paths_region",
")",
".",
"\"\\n\"",
";",
"print",
"'ignore (tmp): '",
".",
"join",
"(",
"', '",
",",
"$",
"this",
"->",
"paths_ignore",
")",
".",
"\"\\n\"",
";",
"print",
"'keep cache: '",
".",
"(",
"$",
"this",
"->",
"flg_keep_cache",
"?",
"'true'",
":",
"'false'",
")",
".",
"\"\\n\"",
";",
"print",
"'devices:'",
".",
"\"\\n\"",
";",
"foreach",
"(",
"$",
"this",
"->",
"plugin_conf",
"->",
"devices",
"as",
"$",
"key",
"=>",
"$",
"device",
")",
"{",
"print",
"' - device['",
".",
"$",
"key",
".",
"']:'",
".",
"\"\\n\"",
";",
"print",
"' - user_agent: '",
".",
"$",
"device",
"->",
"user_agent",
".",
"\"\\n\"",
";",
"print",
"' - path_publish_dir: '",
".",
"$",
"device",
"->",
"path_publish_dir",
".",
"\"\\n\"",
";",
"print",
"' - path_rewrite_rule: '",
".",
"$",
"device",
"->",
"path_rewrite_rule",
".",
"\"\\n\"",
";",
"print",
"' - paths_target: '",
".",
"(",
"is_array",
"(",
"$",
"device",
"->",
"paths_target",
")",
"?",
"join",
"(",
"', '",
",",
"$",
"device",
"->",
"paths_target",
")",
":",
"''",
")",
".",
"\"\\n\"",
";",
"print",
"' - paths_ignore: '",
".",
"(",
"is_array",
"(",
"$",
"device",
"->",
"paths_ignore",
")",
"?",
"join",
"(",
"', '",
",",
"$",
"device",
"->",
"paths_ignore",
")",
":",
"''",
")",
".",
"\"\\n\"",
";",
"print",
"' - rewrite_direction: '",
".",
"$",
"device",
"->",
"rewrite_direction",
".",
"\"\\n\"",
";",
"}",
"print",
"'skip default device: '",
".",
"(",
"$",
"this",
"->",
"plugin_conf",
"->",
"skip_default_device",
"?",
"'true'",
":",
"'false'",
")",
".",
"\"\\n\"",
";",
"print",
"'------------'",
".",
"\"\\n\"",
";",
"flush",
"(",
")",
";",
"return",
"ob_get_clean",
"(",
")",
";",
"}"
] | print CLI header | [
"print",
"CLI",
"header"
] | 5b6c375cacb01183f3102bfc111e3bf132f774f5 | https://github.com/pickles2/px2-publish-ex/blob/5b6c375cacb01183f3102bfc111e3bf132f774f5/php/publish.php#L268-L294 | train |
pickles2/px2-publish-ex | php/publish.php | publish.make_list_by_sitemap | private function make_list_by_sitemap(){
$sitemap = $this->px->site()->get_sitemap();
foreach( $sitemap as $page_info ){
set_time_limit(30);
$href = $this->px->href( $page_info['path'] );
if( preg_match('/^(?:[a-zA-Z0-9]+\:)?\/\//', $href) ){
// プロトコル名、またはドメイン名から始まるリンク先はスキップ
continue;
}
$href = preg_replace( '/\/$/s', '/'.$this->px->get_directory_index_primary(), $href );
$href = preg_replace( '/^'.preg_quote($this->px->get_path_controot(), '/').'/s', '/', $href );
$this->add_queue( $href );
}
return true;
} | php | private function make_list_by_sitemap(){
$sitemap = $this->px->site()->get_sitemap();
foreach( $sitemap as $page_info ){
set_time_limit(30);
$href = $this->px->href( $page_info['path'] );
if( preg_match('/^(?:[a-zA-Z0-9]+\:)?\/\//', $href) ){
// プロトコル名、またはドメイン名から始まるリンク先はスキップ
continue;
}
$href = preg_replace( '/\/$/s', '/'.$this->px->get_directory_index_primary(), $href );
$href = preg_replace( '/^'.preg_quote($this->px->get_path_controot(), '/').'/s', '/', $href );
$this->add_queue( $href );
}
return true;
} | [
"private",
"function",
"make_list_by_sitemap",
"(",
")",
"{",
"$",
"sitemap",
"=",
"$",
"this",
"->",
"px",
"->",
"site",
"(",
")",
"->",
"get_sitemap",
"(",
")",
";",
"foreach",
"(",
"$",
"sitemap",
"as",
"$",
"page_info",
")",
"{",
"set_time_limit",
"(",
"30",
")",
";",
"$",
"href",
"=",
"$",
"this",
"->",
"px",
"->",
"href",
"(",
"$",
"page_info",
"[",
"'path'",
"]",
")",
";",
"if",
"(",
"preg_match",
"(",
"'/^(?:[a-zA-Z0-9]+\\:)?\\/\\//'",
",",
"$",
"href",
")",
")",
"{",
"// プロトコル名、またはドメイン名から始まるリンク先はスキップ\r",
"continue",
";",
"}",
"$",
"href",
"=",
"preg_replace",
"(",
"'/\\/$/s'",
",",
"'/'",
".",
"$",
"this",
"->",
"px",
"->",
"get_directory_index_primary",
"(",
")",
",",
"$",
"href",
")",
";",
"$",
"href",
"=",
"preg_replace",
"(",
"'/^'",
".",
"preg_quote",
"(",
"$",
"this",
"->",
"px",
"->",
"get_path_controot",
"(",
")",
",",
"'/'",
")",
".",
"'/s'",
",",
"'/'",
",",
"$",
"href",
")",
";",
"$",
"this",
"->",
"add_queue",
"(",
"$",
"href",
")",
";",
"}",
"return",
"true",
";",
"}"
] | make list by sitemap
@return bool 常に `true` を返します。 | [
"make",
"list",
"by",
"sitemap"
] | 5b6c375cacb01183f3102bfc111e3bf132f774f5 | https://github.com/pickles2/px2-publish-ex/blob/5b6c375cacb01183f3102bfc111e3bf132f774f5/php/publish.php#L1068-L1082 | train |
skimia/AngularBundle | Components/BundleManager/BundleManager.php | BundleManager.hasBundle | public function hasBundle($name) {
if (isset($this->_globalConfig['bundles'][$name])) {
return true;
} else {
foreach ($this->_bundleConfig as $value) {
if ($value['short_name'] == $name) {
return true;
}
}
return false;
}
} | php | public function hasBundle($name) {
if (isset($this->_globalConfig['bundles'][$name])) {
return true;
} else {
foreach ($this->_bundleConfig as $value) {
if ($value['short_name'] == $name) {
return true;
}
}
return false;
}
} | [
"public",
"function",
"hasBundle",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_globalConfig",
"[",
"'bundles'",
"]",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_bundleConfig",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"[",
"'short_name'",
"]",
"==",
"$",
"name",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}",
"}"
] | Can use shortName or Symfony Bundle Name | [
"Can",
"use",
"shortName",
"or",
"Symfony",
"Bundle",
"Name"
] | ce12fbc03f8554a7879467e73a739ede8991ec48 | https://github.com/skimia/AngularBundle/blob/ce12fbc03f8554a7879467e73a739ede8991ec48/Components/BundleManager/BundleManager.php#L22-L33 | train |
shrink0r/php-schema | src/Property/StringProperty.php | StringProperty.validate | public function validate($value)
{
return is_string($value) ? Ok::unit() : Error::unit([ Error::NON_STRING ]);
} | php | public function validate($value)
{
return is_string($value) ? Ok::unit() : Error::unit([ Error::NON_STRING ]);
} | [
"public",
"function",
"validate",
"(",
"$",
"value",
")",
"{",
"return",
"is_string",
"(",
"$",
"value",
")",
"?",
"Ok",
"::",
"unit",
"(",
")",
":",
"Error",
"::",
"unit",
"(",
"[",
"Error",
"::",
"NON_STRING",
"]",
")",
";",
"}"
] | Tells if a given value is a valid string.
@param mixed $value
@return ResultInterface Returns Ok if the value is valid, otherwise an Error is returned. | [
"Tells",
"if",
"a",
"given",
"value",
"is",
"a",
"valid",
"string",
"."
] | 94293fe897af376dd9d05962e2c516079409dd29 | https://github.com/shrink0r/php-schema/blob/94293fe897af376dd9d05962e2c516079409dd29/src/Property/StringProperty.php#L18-L21 | train |
nochso/ORM2 | src/DBA/LogEntry.php | LogEntry.finish | public function finish()
{
$this->end = microtime(true);
$this->duration = $this->end - $this->start;
DBA::addLog($this);
} | php | public function finish()
{
$this->end = microtime(true);
$this->duration = $this->end - $this->start;
DBA::addLog($this);
} | [
"public",
"function",
"finish",
"(",
")",
"{",
"$",
"this",
"->",
"end",
"=",
"microtime",
"(",
"true",
")",
";",
"$",
"this",
"->",
"duration",
"=",
"$",
"this",
"->",
"end",
"-",
"$",
"this",
"->",
"start",
";",
"DBA",
"::",
"addLog",
"(",
"$",
"this",
")",
";",
"}"
] | Add the finished entry to the log | [
"Add",
"the",
"finished",
"entry",
"to",
"the",
"log"
] | 89f9a5c61ad5f575fbdd52990171b52d54f8bfbc | https://github.com/nochso/ORM2/blob/89f9a5c61ad5f575fbdd52990171b52d54f8bfbc/src/DBA/LogEntry.php#L38-L43 | train |
nochso/ORM2 | src/DBA/LogEntry.php | LogEntry.getPrettyStatement | public function getPrettyStatement()
{
$assoc = [];
$statement = $this->statement;
foreach ($this->data as $key => $value) {
if (is_numeric($key)) {
$statement = $this->strReplaceOnce('?', "'" . $value . "'", $statement);
} else {
$assoc[] = $key;
}
}
// Sort non-numeric keys descending by their string length.
usort($assoc, function ($a, $b) {
$alen = strlen($a);
$blen = strlen($b);
if ($alen === $blen) {
return 0;
}
return $alen > $blen ? -1 : 1;
});
// Replace the longest keys first. This avoids conflicts/overlaps of shorter keys.
foreach ($assoc as $key) {
$statement = str_replace($key, "'" . $this->data[$key] . "'", $statement);
}
return $statement;
} | php | public function getPrettyStatement()
{
$assoc = [];
$statement = $this->statement;
foreach ($this->data as $key => $value) {
if (is_numeric($key)) {
$statement = $this->strReplaceOnce('?', "'" . $value . "'", $statement);
} else {
$assoc[] = $key;
}
}
// Sort non-numeric keys descending by their string length.
usort($assoc, function ($a, $b) {
$alen = strlen($a);
$blen = strlen($b);
if ($alen === $blen) {
return 0;
}
return $alen > $blen ? -1 : 1;
});
// Replace the longest keys first. This avoids conflicts/overlaps of shorter keys.
foreach ($assoc as $key) {
$statement = str_replace($key, "'" . $this->data[$key] . "'", $statement);
}
return $statement;
} | [
"public",
"function",
"getPrettyStatement",
"(",
")",
"{",
"$",
"assoc",
"=",
"[",
"]",
";",
"$",
"statement",
"=",
"$",
"this",
"->",
"statement",
";",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"key",
")",
")",
"{",
"$",
"statement",
"=",
"$",
"this",
"->",
"strReplaceOnce",
"(",
"'?'",
",",
"\"'\"",
".",
"$",
"value",
".",
"\"'\"",
",",
"$",
"statement",
")",
";",
"}",
"else",
"{",
"$",
"assoc",
"[",
"]",
"=",
"$",
"key",
";",
"}",
"}",
"// Sort non-numeric keys descending by their string length.",
"usort",
"(",
"$",
"assoc",
",",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"$",
"alen",
"=",
"strlen",
"(",
"$",
"a",
")",
";",
"$",
"blen",
"=",
"strlen",
"(",
"$",
"b",
")",
";",
"if",
"(",
"$",
"alen",
"===",
"$",
"blen",
")",
"{",
"return",
"0",
";",
"}",
"return",
"$",
"alen",
">",
"$",
"blen",
"?",
"-",
"1",
":",
"1",
";",
"}",
")",
";",
"// Replace the longest keys first. This avoids conflicts/overlaps of shorter keys.",
"foreach",
"(",
"$",
"assoc",
"as",
"$",
"key",
")",
"{",
"$",
"statement",
"=",
"str_replace",
"(",
"$",
"key",
",",
"\"'\"",
".",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
".",
"\"'\"",
",",
"$",
"statement",
")",
";",
"}",
"return",
"$",
"statement",
";",
"}"
] | Returns a readable SQL statement with the parameters merged inline.
Both numeric and hashed arrays work, but they can't be mixed.
@return string | [
"Returns",
"a",
"readable",
"SQL",
"statement",
"with",
"the",
"parameters",
"merged",
"inline",
".",
"Both",
"numeric",
"and",
"hashed",
"arrays",
"work",
"but",
"they",
"can",
"t",
"be",
"mixed",
"."
] | 89f9a5c61ad5f575fbdd52990171b52d54f8bfbc | https://github.com/nochso/ORM2/blob/89f9a5c61ad5f575fbdd52990171b52d54f8bfbc/src/DBA/LogEntry.php#L61-L86 | train |
mtils/file-db | src/FileDB/Controller/FileController.php | FileController.index | public function index($dirId=null)
{
if ($dirId == 'index') {
$dirId = NULL;
}
$parentDir = NULL;
$params = $this->getPassThruParams();
$dir = $this->getDirectory($dirId);
if ( isset($params['type']) && $params['type'] == 'image') {
$this->filterToImages($dir);
}
$this->sortChildren($dir);
$viewParams = [
'dir' => $dir,
'parents' => $this->fileDB->getParents($dir),
'params' => $params,
'toRoute' => function ($action, $params=[]) {
return $this->toRoute($action, $params);
},
'attributeSetter' => $this->getAttributeProvider($this->getContext())
];
return View::make($this->getTemplate(), $viewParams);
} | php | public function index($dirId=null)
{
if ($dirId == 'index') {
$dirId = NULL;
}
$parentDir = NULL;
$params = $this->getPassThruParams();
$dir = $this->getDirectory($dirId);
if ( isset($params['type']) && $params['type'] == 'image') {
$this->filterToImages($dir);
}
$this->sortChildren($dir);
$viewParams = [
'dir' => $dir,
'parents' => $this->fileDB->getParents($dir),
'params' => $params,
'toRoute' => function ($action, $params=[]) {
return $this->toRoute($action, $params);
},
'attributeSetter' => $this->getAttributeProvider($this->getContext())
];
return View::make($this->getTemplate(), $viewParams);
} | [
"public",
"function",
"index",
"(",
"$",
"dirId",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"dirId",
"==",
"'index'",
")",
"{",
"$",
"dirId",
"=",
"NULL",
";",
"}",
"$",
"parentDir",
"=",
"NULL",
";",
"$",
"params",
"=",
"$",
"this",
"->",
"getPassThruParams",
"(",
")",
";",
"$",
"dir",
"=",
"$",
"this",
"->",
"getDirectory",
"(",
"$",
"dirId",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'type'",
"]",
")",
"&&",
"$",
"params",
"[",
"'type'",
"]",
"==",
"'image'",
")",
"{",
"$",
"this",
"->",
"filterToImages",
"(",
"$",
"dir",
")",
";",
"}",
"$",
"this",
"->",
"sortChildren",
"(",
"$",
"dir",
")",
";",
"$",
"viewParams",
"=",
"[",
"'dir'",
"=>",
"$",
"dir",
",",
"'parents'",
"=>",
"$",
"this",
"->",
"fileDB",
"->",
"getParents",
"(",
"$",
"dir",
")",
",",
"'params'",
"=>",
"$",
"params",
",",
"'toRoute'",
"=>",
"function",
"(",
"$",
"action",
",",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"toRoute",
"(",
"$",
"action",
",",
"$",
"params",
")",
";",
"}",
",",
"'attributeSetter'",
"=>",
"$",
"this",
"->",
"getAttributeProvider",
"(",
"$",
"this",
"->",
"getContext",
"(",
")",
")",
"]",
";",
"return",
"View",
"::",
"make",
"(",
"$",
"this",
"->",
"getTemplate",
"(",
")",
",",
"$",
"viewParams",
")",
";",
"}"
] | List a directory or the root directory.
@param int $dirId (optional)
@return mixed | [
"List",
"a",
"directory",
"or",
"the",
"root",
"directory",
"."
] | 270ebc26b0fa3d2c996ca8861507fa63d2db6814 | https://github.com/mtils/file-db/blob/270ebc26b0fa3d2c996ca8861507fa63d2db6814/src/FileDB/Controller/FileController.php#L112-L142 | train |
mtils/file-db | src/FileDB/Controller/FileController.php | FileController.upload | public function upload(Request $request, $dirId)
{
try {
$folder = $this->getDirOrFail($dirId);
if (!$request->hasFile('uploadedFile')) {
throw new RuntimeException('Uploaded File not found');
}
$uploadedFile = $request->file('uploadedFile');
/** @var UploadedFile $uploadedFile */
$uploadedFile = is_array($uploadedFile) ? $uploadedFile[0] : $uploadedFile;
$fileName = $uploadedFile->getClientOriginalName();
$newPath = $this->getTempDir() . '/' . $fileName;
$uploadedFile->move($this->getTempDir(), $fileName);
$this->fileDB->importFile($newPath, $folder);
return $this->redirectTo('index', $folder->getId());
} catch(FileException $e) {
$this->flashMessage('upload-failed','danger');
} catch(RuntimeException $e) {
$this->flashMessage('uploaded-file-missing','danger');
}
return $this->redirectTo('index');
} | php | public function upload(Request $request, $dirId)
{
try {
$folder = $this->getDirOrFail($dirId);
if (!$request->hasFile('uploadedFile')) {
throw new RuntimeException('Uploaded File not found');
}
$uploadedFile = $request->file('uploadedFile');
/** @var UploadedFile $uploadedFile */
$uploadedFile = is_array($uploadedFile) ? $uploadedFile[0] : $uploadedFile;
$fileName = $uploadedFile->getClientOriginalName();
$newPath = $this->getTempDir() . '/' . $fileName;
$uploadedFile->move($this->getTempDir(), $fileName);
$this->fileDB->importFile($newPath, $folder);
return $this->redirectTo('index', $folder->getId());
} catch(FileException $e) {
$this->flashMessage('upload-failed','danger');
} catch(RuntimeException $e) {
$this->flashMessage('uploaded-file-missing','danger');
}
return $this->redirectTo('index');
} | [
"public",
"function",
"upload",
"(",
"Request",
"$",
"request",
",",
"$",
"dirId",
")",
"{",
"try",
"{",
"$",
"folder",
"=",
"$",
"this",
"->",
"getDirOrFail",
"(",
"$",
"dirId",
")",
";",
"if",
"(",
"!",
"$",
"request",
"->",
"hasFile",
"(",
"'uploadedFile'",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'Uploaded File not found'",
")",
";",
"}",
"$",
"uploadedFile",
"=",
"$",
"request",
"->",
"file",
"(",
"'uploadedFile'",
")",
";",
"/** @var UploadedFile $uploadedFile */",
"$",
"uploadedFile",
"=",
"is_array",
"(",
"$",
"uploadedFile",
")",
"?",
"$",
"uploadedFile",
"[",
"0",
"]",
":",
"$",
"uploadedFile",
";",
"$",
"fileName",
"=",
"$",
"uploadedFile",
"->",
"getClientOriginalName",
"(",
")",
";",
"$",
"newPath",
"=",
"$",
"this",
"->",
"getTempDir",
"(",
")",
".",
"'/'",
".",
"$",
"fileName",
";",
"$",
"uploadedFile",
"->",
"move",
"(",
"$",
"this",
"->",
"getTempDir",
"(",
")",
",",
"$",
"fileName",
")",
";",
"$",
"this",
"->",
"fileDB",
"->",
"importFile",
"(",
"$",
"newPath",
",",
"$",
"folder",
")",
";",
"return",
"$",
"this",
"->",
"redirectTo",
"(",
"'index'",
",",
"$",
"folder",
"->",
"getId",
"(",
")",
")",
";",
"}",
"catch",
"(",
"FileException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"flashMessage",
"(",
"'upload-failed'",
",",
"'danger'",
")",
";",
"}",
"catch",
"(",
"RuntimeException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"flashMessage",
"(",
"'uploaded-file-missing'",
",",
"'danger'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"redirectTo",
"(",
"'index'",
")",
";",
"}"
] | Upload a file into the file db.
@param Request $request
@param int $dirId
@return RedirectResponse | [
"Upload",
"a",
"file",
"into",
"the",
"file",
"db",
"."
] | 270ebc26b0fa3d2c996ca8861507fa63d2db6814 | https://github.com/mtils/file-db/blob/270ebc26b0fa3d2c996ca8861507fa63d2db6814/src/FileDB/Controller/FileController.php#L180-L214 | train |
mtils/file-db | src/FileDB/Controller/FileController.php | FileController.sync | public function sync($dirId)
{
$dir = $this->getDirOrFail($dirId);
$this->fileDB->syncWithFs($dir, 1);
return $this->redirectTo('index', [$dir->getId()]);
} | php | public function sync($dirId)
{
$dir = $this->getDirOrFail($dirId);
$this->fileDB->syncWithFs($dir, 1);
return $this->redirectTo('index', [$dir->getId()]);
} | [
"public",
"function",
"sync",
"(",
"$",
"dirId",
")",
"{",
"$",
"dir",
"=",
"$",
"this",
"->",
"getDirOrFail",
"(",
"$",
"dirId",
")",
";",
"$",
"this",
"->",
"fileDB",
"->",
"syncWithFs",
"(",
"$",
"dir",
",",
"1",
")",
";",
"return",
"$",
"this",
"->",
"redirectTo",
"(",
"'index'",
",",
"[",
"$",
"dir",
"->",
"getId",
"(",
")",
"]",
")",
";",
"}"
] | Synchronize the filesystem into the db in this folder.
@param int $dirId
@return RedirectResponse | [
"Synchronize",
"the",
"filesystem",
"into",
"the",
"db",
"in",
"this",
"folder",
"."
] | 270ebc26b0fa3d2c996ca8861507fa63d2db6814 | https://github.com/mtils/file-db/blob/270ebc26b0fa3d2c996ca8861507fa63d2db6814/src/FileDB/Controller/FileController.php#L223-L228 | train |
mtils/file-db | src/FileDB/Controller/FileController.php | FileController.provideOpenLinkAttributes | public function provideOpenLinkAttributes($context, Closure $closure)
{
$closure->bindTo($this);
$this->extend($this->getContextExtendName($context), $closure);
return $this;
} | php | public function provideOpenLinkAttributes($context, Closure $closure)
{
$closure->bindTo($this);
$this->extend($this->getContextExtendName($context), $closure);
return $this;
} | [
"public",
"function",
"provideOpenLinkAttributes",
"(",
"$",
"context",
",",
"Closure",
"$",
"closure",
")",
"{",
"$",
"closure",
"->",
"bindTo",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"extend",
"(",
"$",
"this",
"->",
"getContextExtendName",
"(",
"$",
"context",
")",
",",
"$",
"closure",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Assign a callable to manipulate the attributes for the "open" links to
open files.
@param string $context
@param Closure $closure
@return $this | [
"Assign",
"a",
"callable",
"to",
"manipulate",
"the",
"attributes",
"for",
"the",
"open",
"links",
"to",
"open",
"files",
"."
] | 270ebc26b0fa3d2c996ca8861507fa63d2db6814 | https://github.com/mtils/file-db/blob/270ebc26b0fa3d2c996ca8861507fa63d2db6814/src/FileDB/Controller/FileController.php#L400-L405 | train |
mtils/file-db | src/FileDB/Controller/FileController.php | FileController.getPassThruParams | protected function getPassThruParams()
{
if ($this->passThruParams !== null) {
return $this->passThruParams;
}
$this->passThruParams = [];
$all = Input::all();
$filtered = array_except($all, ['sync','uploadedFile','folderName']);
// Security check
if (count($filtered) > 30) {
throw new RuntimeException('Too many query params');
}
foreach ($filtered as $key=>$value) {
$this->passThruParams[$key] = strip_tags($value);
}
return $this->passThruParams;
} | php | protected function getPassThruParams()
{
if ($this->passThruParams !== null) {
return $this->passThruParams;
}
$this->passThruParams = [];
$all = Input::all();
$filtered = array_except($all, ['sync','uploadedFile','folderName']);
// Security check
if (count($filtered) > 30) {
throw new RuntimeException('Too many query params');
}
foreach ($filtered as $key=>$value) {
$this->passThruParams[$key] = strip_tags($value);
}
return $this->passThruParams;
} | [
"protected",
"function",
"getPassThruParams",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"passThruParams",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"passThruParams",
";",
"}",
"$",
"this",
"->",
"passThruParams",
"=",
"[",
"]",
";",
"$",
"all",
"=",
"Input",
"::",
"all",
"(",
")",
";",
"$",
"filtered",
"=",
"array_except",
"(",
"$",
"all",
",",
"[",
"'sync'",
",",
"'uploadedFile'",
",",
"'folderName'",
"]",
")",
";",
"// Security check",
"if",
"(",
"count",
"(",
"$",
"filtered",
")",
">",
"30",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'Too many query params'",
")",
";",
"}",
"foreach",
"(",
"$",
"filtered",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"passThruParams",
"[",
"$",
"key",
"]",
"=",
"strip_tags",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"this",
"->",
"passThruParams",
";",
"}"
] | Get some parameters that should be added to every link.
@return array | [
"Get",
"some",
"parameters",
"that",
"should",
"be",
"added",
"to",
"every",
"link",
"."
] | 270ebc26b0fa3d2c996ca8861507fa63d2db6814 | https://github.com/mtils/file-db/blob/270ebc26b0fa3d2c996ca8861507fa63d2db6814/src/FileDB/Controller/FileController.php#L412-L436 | train |
mtils/file-db | src/FileDB/Controller/FileController.php | FileController.getAttributeProvider | protected function getAttributeProvider($context)
{
$extendName = $this->getContextExtendName($context);
if ($this->hasExtension($extendName)) {
return $this->getExtension($extendName);
}
return function($file) {
return [
'href' =>$file->url,
'class'=>'inline',
'onclick'=>"window.open($(this).attr('href'), 'imgViewer','width=600,height=400'); return false;"];
};
} | php | protected function getAttributeProvider($context)
{
$extendName = $this->getContextExtendName($context);
if ($this->hasExtension($extendName)) {
return $this->getExtension($extendName);
}
return function($file) {
return [
'href' =>$file->url,
'class'=>'inline',
'onclick'=>"window.open($(this).attr('href'), 'imgViewer','width=600,height=400'); return false;"];
};
} | [
"protected",
"function",
"getAttributeProvider",
"(",
"$",
"context",
")",
"{",
"$",
"extendName",
"=",
"$",
"this",
"->",
"getContextExtendName",
"(",
"$",
"context",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasExtension",
"(",
"$",
"extendName",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getExtension",
"(",
"$",
"extendName",
")",
";",
"}",
"return",
"function",
"(",
"$",
"file",
")",
"{",
"return",
"[",
"'href'",
"=>",
"$",
"file",
"->",
"url",
",",
"'class'",
"=>",
"'inline'",
",",
"'onclick'",
"=>",
"\"window.open($(this).attr('href'), 'imgViewer','width=600,height=400'); return false;\"",
"]",
";",
"}",
";",
"}"
] | Return the attribute provider to provide attributes for the open links.
@see self::provideOpenLinkAttributes()
@param string $context
@return callable | [
"Return",
"the",
"attribute",
"provider",
"to",
"provide",
"attributes",
"for",
"the",
"open",
"links",
"."
] | 270ebc26b0fa3d2c996ca8861507fa63d2db6814 | https://github.com/mtils/file-db/blob/270ebc26b0fa3d2c996ca8861507fa63d2db6814/src/FileDB/Controller/FileController.php#L478-L494 | train |
loevgaard/dandomain-foundation-entities | src/Entity/Order.php | Order.createMoney | private function createMoney(int $amount = 0): ?Money
{
if (!$this->currency) {
return null;
}
return DandomainFoundation\createMoney($this->currency->getIsoCodeAlpha(), $amount);
} | php | private function createMoney(int $amount = 0): ?Money
{
if (!$this->currency) {
return null;
}
return DandomainFoundation\createMoney($this->currency->getIsoCodeAlpha(), $amount);
} | [
"private",
"function",
"createMoney",
"(",
"int",
"$",
"amount",
"=",
"0",
")",
":",
"?",
"Money",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"currency",
")",
"{",
"return",
"null",
";",
"}",
"return",
"DandomainFoundation",
"\\",
"createMoney",
"(",
"$",
"this",
"->",
"currency",
"->",
"getIsoCodeAlpha",
"(",
")",
",",
"$",
"amount",
")",
";",
"}"
] | A helper method for creating a Money object from a float based on the shared currency.
@param int $amount
@return Money|null | [
"A",
"helper",
"method",
"for",
"creating",
"a",
"Money",
"object",
"from",
"a",
"float",
"based",
"on",
"the",
"shared",
"currency",
"."
] | 256f7aa8b40d2bd9488046c3c2b1e04e982d78ad | https://github.com/loevgaard/dandomain-foundation-entities/blob/256f7aa8b40d2bd9488046c3c2b1e04e982d78ad/src/Entity/Order.php#L1265-L1272 | train |
koolkode/meta | src/DocComment.php | DocComment.getDescription | public function getDescription($short = false)
{
if($short)
{
if($pos = strpos($this->description, "\r"))
{
return substr($this->description, 0, $pos);
}
if($pos = strpos($this->description, "\n"))
{
return substr($this->description, 0, $pos);
}
}
return $this->description;
} | php | public function getDescription($short = false)
{
if($short)
{
if($pos = strpos($this->description, "\r"))
{
return substr($this->description, 0, $pos);
}
if($pos = strpos($this->description, "\n"))
{
return substr($this->description, 0, $pos);
}
}
return $this->description;
} | [
"public",
"function",
"getDescription",
"(",
"$",
"short",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"short",
")",
"{",
"if",
"(",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"this",
"->",
"description",
",",
"\"\\r\"",
")",
")",
"{",
"return",
"substr",
"(",
"$",
"this",
"->",
"description",
",",
"0",
",",
"$",
"pos",
")",
";",
"}",
"if",
"(",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"this",
"->",
"description",
",",
"\"\\n\"",
")",
")",
"{",
"return",
"substr",
"(",
"$",
"this",
"->",
"description",
",",
"0",
",",
"$",
"pos",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"description",
";",
"}"
] | Get the description from this doc comment.
@param boolean $short Return the short description (first paragraph)?
@return string | [
"Get",
"the",
"description",
"from",
"this",
"doc",
"comment",
"."
] | 339db24d3ce461190f552c96e243bca21010f360 | https://github.com/koolkode/meta/blob/339db24d3ce461190f552c96e243bca21010f360/src/DocComment.php#L48-L64 | train |
koolkode/meta | src/DocComment.php | DocComment.getTagValue | public function getTagValue($tag)
{
if(!$this->hasTag($tag))
{
throw new \OutOfBoundsException('Tag ' . $tag . ' is not set');
}
if(empty($this->tags[$tag]))
{
throw new \OutOfBoundsException('Tag ' . $tag . ' does not have a value');
}
return $this->tags[$tag][0];
} | php | public function getTagValue($tag)
{
if(!$this->hasTag($tag))
{
throw new \OutOfBoundsException('Tag ' . $tag . ' is not set');
}
if(empty($this->tags[$tag]))
{
throw new \OutOfBoundsException('Tag ' . $tag . ' does not have a value');
}
return $this->tags[$tag][0];
} | [
"public",
"function",
"getTagValue",
"(",
"$",
"tag",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasTag",
"(",
"$",
"tag",
")",
")",
"{",
"throw",
"new",
"\\",
"OutOfBoundsException",
"(",
"'Tag '",
".",
"$",
"tag",
".",
"' is not set'",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"tags",
"[",
"$",
"tag",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"OutOfBoundsException",
"(",
"'Tag '",
".",
"$",
"tag",
".",
"' does not have a value'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"tags",
"[",
"$",
"tag",
"]",
"[",
"0",
"]",
";",
"}"
] | Get the value of a tag.
@param string $tag
@return string
@throws \OutOfBoundsException | [
"Get",
"the",
"value",
"of",
"a",
"tag",
"."
] | 339db24d3ce461190f552c96e243bca21010f360 | https://github.com/koolkode/meta/blob/339db24d3ce461190f552c96e243bca21010f360/src/DocComment.php#L95-L108 | train |
koolkode/meta | src/DocComment.php | DocComment.getFieldType | public function getFieldType(NamespaceContext $context = NULL)
{
try
{
$var = $this->getTagValue('var');
}
catch(\Exception $e)
{
return new MetaType(MetaType::TYPE_MIXED);
}
return $this->parseTypeInfo($var, ($context === NULL) ? new NamespaceContext() : $context);
} | php | public function getFieldType(NamespaceContext $context = NULL)
{
try
{
$var = $this->getTagValue('var');
}
catch(\Exception $e)
{
return new MetaType(MetaType::TYPE_MIXED);
}
return $this->parseTypeInfo($var, ($context === NULL) ? new NamespaceContext() : $context);
} | [
"public",
"function",
"getFieldType",
"(",
"NamespaceContext",
"$",
"context",
"=",
"NULL",
")",
"{",
"try",
"{",
"$",
"var",
"=",
"$",
"this",
"->",
"getTagValue",
"(",
"'var'",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"return",
"new",
"MetaType",
"(",
"MetaType",
"::",
"TYPE_MIXED",
")",
";",
"}",
"return",
"$",
"this",
"->",
"parseTypeInfo",
"(",
"$",
"var",
",",
"(",
"$",
"context",
"===",
"NULL",
")",
"?",
"new",
"NamespaceContext",
"(",
")",
":",
"$",
"context",
")",
";",
"}"
] | Get the type of the field this doc comment belongs to.
@param NamespaceContext $context
@return MetaType | [
"Get",
"the",
"type",
"of",
"the",
"field",
"this",
"doc",
"comment",
"belongs",
"to",
"."
] | 339db24d3ce461190f552c96e243bca21010f360 | https://github.com/koolkode/meta/blob/339db24d3ce461190f552c96e243bca21010f360/src/DocComment.php#L132-L144 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.