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 |
---|---|---|---|---|---|---|---|---|---|---|---|
donquixote/cellbrush | src/Axis/DynamicAxis.php | DynamicAxis.internalAddName | private function internalAddName($name) {
$this->children[$name] = array();
if (false !== $pos = strrpos($name, '.')) {
$parentName = substr($name, 0, $pos);
if (!isset($this->children[$parentName])) {
$this->internalAddName($parentName);
}
$this->parents[$name] = $parentName;
$this->children[$parentName][$name] = true;
}
else {
$this->parents[$name] = null;
$this->toplevelNames[$name] = true;
}
} | php | private function internalAddName($name) {
$this->children[$name] = array();
if (false !== $pos = strrpos($name, '.')) {
$parentName = substr($name, 0, $pos);
if (!isset($this->children[$parentName])) {
$this->internalAddName($parentName);
}
$this->parents[$name] = $parentName;
$this->children[$parentName][$name] = true;
}
else {
$this->parents[$name] = null;
$this->toplevelNames[$name] = true;
}
} | [
"private",
"function",
"internalAddName",
"(",
"$",
"name",
")",
"{",
"$",
"this",
"->",
"children",
"[",
"$",
"name",
"]",
"=",
"array",
"(",
")",
";",
"if",
"(",
"false",
"!==",
"$",
"pos",
"=",
"strrpos",
"(",
"$",
"name",
",",
"'.'",
")",
")",
"{",
"$",
"parentName",
"=",
"substr",
"(",
"$",
"name",
",",
"0",
",",
"$",
"pos",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"children",
"[",
"$",
"parentName",
"]",
")",
")",
"{",
"$",
"this",
"->",
"internalAddName",
"(",
"$",
"parentName",
")",
";",
"}",
"$",
"this",
"->",
"parents",
"[",
"$",
"name",
"]",
"=",
"$",
"parentName",
";",
"$",
"this",
"->",
"children",
"[",
"$",
"parentName",
"]",
"[",
"$",
"name",
"]",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"parents",
"[",
"$",
"name",
"]",
"=",
"null",
";",
"$",
"this",
"->",
"toplevelNames",
"[",
"$",
"name",
"]",
"=",
"true",
";",
"}",
"}"
]
| Adds a name from which we know already it does not exist.
This allows to avoid redundant checks when called internally.
@param string $name | [
"Adds",
"a",
"name",
"from",
"which",
"we",
"know",
"already",
"it",
"does",
"not",
"exist",
".",
"This",
"allows",
"to",
"avoid",
"redundant",
"checks",
"when",
"called",
"internally",
"."
]
| 09c70b421828624756e56591de41d5e86030f50e | https://github.com/donquixote/cellbrush/blob/09c70b421828624756e56591de41d5e86030f50e/src/Axis/DynamicAxis.php#L59-L73 | train |
donquixote/cellbrush | src/Axis/DynamicAxis.php | DynamicAxis.setOrder | function setOrder(array $orderedNames, $parentName = null) {
if (isset($parentName)) {
if (!isset($this->children[$parentName])) {
throw new \Exception("Unknown name '$parentName'.");
}
$this->children[$parentName] = $this->internalSetOrder(
$this->children[$parentName],
$orderedNames);
}
else {
$this->toplevelNames = $this->internalSetOrder(
$this->toplevelNames,
$orderedNames);
}
return $this;
} | php | function setOrder(array $orderedNames, $parentName = null) {
if (isset($parentName)) {
if (!isset($this->children[$parentName])) {
throw new \Exception("Unknown name '$parentName'.");
}
$this->children[$parentName] = $this->internalSetOrder(
$this->children[$parentName],
$orderedNames);
}
else {
$this->toplevelNames = $this->internalSetOrder(
$this->toplevelNames,
$orderedNames);
}
return $this;
} | [
"function",
"setOrder",
"(",
"array",
"$",
"orderedNames",
",",
"$",
"parentName",
"=",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"parentName",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"children",
"[",
"$",
"parentName",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Unknown name '$parentName'.\"",
")",
";",
"}",
"$",
"this",
"->",
"children",
"[",
"$",
"parentName",
"]",
"=",
"$",
"this",
"->",
"internalSetOrder",
"(",
"$",
"this",
"->",
"children",
"[",
"$",
"parentName",
"]",
",",
"$",
"orderedNames",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"toplevelNames",
"=",
"$",
"this",
"->",
"internalSetOrder",
"(",
"$",
"this",
"->",
"toplevelNames",
",",
"$",
"orderedNames",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Sets the order for all children of a parent, or all toplevel names.
This operation cannot add or remove names, only reorder them. If names
would be added or removed, an exception is thrown instead.
@param string[] $orderedNames
@param string|null $parentName
@return $this
@throws \Exception | [
"Sets",
"the",
"order",
"for",
"all",
"children",
"of",
"a",
"parent",
"or",
"all",
"toplevel",
"names",
".",
"This",
"operation",
"cannot",
"add",
"or",
"remove",
"names",
"only",
"reorder",
"them",
".",
"If",
"names",
"would",
"be",
"added",
"or",
"removed",
"an",
"exception",
"is",
"thrown",
"instead",
"."
]
| 09c70b421828624756e56591de41d5e86030f50e | https://github.com/donquixote/cellbrush/blob/09c70b421828624756e56591de41d5e86030f50e/src/Axis/DynamicAxis.php#L120-L135 | train |
neos/swiftmailer | Classes/Transport/LoggingTransport.php | LoggingTransport.send | public function send(\Swift_Mime_SimpleMessage $message, &$failedRecipients = null): int
{
self::$deliveredMessages[] = $message;
$this->systemLogger->log('Sent email to ' . $this->buildStringFromEmailAndNameArray($message->getTo()), LOG_DEBUG, [
'message' => $message->toString()
]);
return count((array)$message->getTo()) + count((array)$message->getCc()) + count((array)$message->getBcc());
} | php | public function send(\Swift_Mime_SimpleMessage $message, &$failedRecipients = null): int
{
self::$deliveredMessages[] = $message;
$this->systemLogger->log('Sent email to ' . $this->buildStringFromEmailAndNameArray($message->getTo()), LOG_DEBUG, [
'message' => $message->toString()
]);
return count((array)$message->getTo()) + count((array)$message->getCc()) + count((array)$message->getBcc());
} | [
"public",
"function",
"send",
"(",
"\\",
"Swift_Mime_SimpleMessage",
"$",
"message",
",",
"&",
"$",
"failedRecipients",
"=",
"null",
")",
":",
"int",
"{",
"self",
"::",
"$",
"deliveredMessages",
"[",
"]",
"=",
"$",
"message",
";",
"$",
"this",
"->",
"systemLogger",
"->",
"log",
"(",
"'Sent email to '",
".",
"$",
"this",
"->",
"buildStringFromEmailAndNameArray",
"(",
"$",
"message",
"->",
"getTo",
"(",
")",
")",
",",
"LOG_DEBUG",
",",
"[",
"'message'",
"=>",
"$",
"message",
"->",
"toString",
"(",
")",
"]",
")",
";",
"return",
"count",
"(",
"(",
"array",
")",
"$",
"message",
"->",
"getTo",
"(",
")",
")",
"+",
"count",
"(",
"(",
"array",
")",
"$",
"message",
"->",
"getCc",
"(",
")",
")",
"+",
"count",
"(",
"(",
"array",
")",
"$",
"message",
"->",
"getBcc",
"(",
")",
")",
";",
"}"
]
| "Send" the given Message. This transport will add it to a stored collection of sent messages
for testing purposes and log the message to the system logger.
@param \Swift_Mime_SimpleMessage $message The message to send
@param array &$failedRecipients Failed recipients
@return int | [
"Send",
"the",
"given",
"Message",
".",
"This",
"transport",
"will",
"add",
"it",
"to",
"a",
"stored",
"collection",
"of",
"sent",
"messages",
"for",
"testing",
"purposes",
"and",
"log",
"the",
"message",
"to",
"the",
"system",
"logger",
"."
]
| 02aac015001563f6a30c48ab3c9449b6d400eede | https://github.com/neos/swiftmailer/blob/02aac015001563f6a30c48ab3c9449b6d400eede/Classes/Transport/LoggingTransport.php#L74-L83 | train |
neos/swiftmailer | Classes/Transport/LoggingTransport.php | LoggingTransport.buildStringFromEmailAndNameArray | protected function buildStringFromEmailAndNameArray(array $addresses): string
{
$results = [];
foreach ($addresses as $emailAddress => $name) {
if ($name !== '') {
$results[] = sprintf('%s <%s>', $name, $emailAddress);
} else {
$results[] = $emailAddress;
}
}
return implode(', ', $results);
} | php | protected function buildStringFromEmailAndNameArray(array $addresses): string
{
$results = [];
foreach ($addresses as $emailAddress => $name) {
if ($name !== '') {
$results[] = sprintf('%s <%s>', $name, $emailAddress);
} else {
$results[] = $emailAddress;
}
}
return implode(', ', $results);
} | [
"protected",
"function",
"buildStringFromEmailAndNameArray",
"(",
"array",
"$",
"addresses",
")",
":",
"string",
"{",
"$",
"results",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"addresses",
"as",
"$",
"emailAddress",
"=>",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"name",
"!==",
"''",
")",
"{",
"$",
"results",
"[",
"]",
"=",
"sprintf",
"(",
"'%s <%s>'",
",",
"$",
"name",
",",
"$",
"emailAddress",
")",
";",
"}",
"else",
"{",
"$",
"results",
"[",
"]",
"=",
"$",
"emailAddress",
";",
"}",
"}",
"return",
"implode",
"(",
"', '",
",",
"$",
"results",
")",
";",
"}"
]
| Builds a plaintext-compatible string representing an array of given E-Mail addresses.
@param array $addresses The addresses where the key is the email address and the value is a name
@return string Looking like "John Doe <[email protected]>, Jeanne Dough <[email protected]>, [email protected]" | [
"Builds",
"a",
"plaintext",
"-",
"compatible",
"string",
"representing",
"an",
"array",
"of",
"given",
"E",
"-",
"Mail",
"addresses",
"."
]
| 02aac015001563f6a30c48ab3c9449b6d400eede | https://github.com/neos/swiftmailer/blob/02aac015001563f6a30c48ab3c9449b6d400eede/Classes/Transport/LoggingTransport.php#L91-L102 | train |
neos/swiftmailer | Classes/TransportFactory.php | TransportFactory.create | public function create(string $transportType, array $transportOptions = [], array $transportArguments = null): \Swift_Transport
{
if (!class_exists($transportType)) {
throw new Exception(sprintf('The specified transport backend "%s" does not exist.', $transportType), 1269351207);
}
if (is_array($transportArguments)) {
$class = new \ReflectionClass($transportType);
$transport = $class->newInstanceArgs($transportArguments);
} else {
$transport = new $transportType();
}
if ($transport instanceof \Swift_Transport) {
foreach ($transportOptions as $optionName => $optionValue) {
if (ObjectAccess::isPropertySettable($transport, $optionName)) {
ObjectAccess::setProperty($transport, $optionName, $optionValue);
}
}
return $transport;
}
throw new Exception(sprintf('The specified transport backend "%s" does not implement %s.', $transportType, \Swift_Transport::class), 1544727431);
} | php | public function create(string $transportType, array $transportOptions = [], array $transportArguments = null): \Swift_Transport
{
if (!class_exists($transportType)) {
throw new Exception(sprintf('The specified transport backend "%s" does not exist.', $transportType), 1269351207);
}
if (is_array($transportArguments)) {
$class = new \ReflectionClass($transportType);
$transport = $class->newInstanceArgs($transportArguments);
} else {
$transport = new $transportType();
}
if ($transport instanceof \Swift_Transport) {
foreach ($transportOptions as $optionName => $optionValue) {
if (ObjectAccess::isPropertySettable($transport, $optionName)) {
ObjectAccess::setProperty($transport, $optionName, $optionValue);
}
}
return $transport;
}
throw new Exception(sprintf('The specified transport backend "%s" does not implement %s.', $transportType, \Swift_Transport::class), 1544727431);
} | [
"public",
"function",
"create",
"(",
"string",
"$",
"transportType",
",",
"array",
"$",
"transportOptions",
"=",
"[",
"]",
",",
"array",
"$",
"transportArguments",
"=",
"null",
")",
":",
"\\",
"Swift_Transport",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"transportType",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"'The specified transport backend \"%s\" does not exist.'",
",",
"$",
"transportType",
")",
",",
"1269351207",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"transportArguments",
")",
")",
"{",
"$",
"class",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"transportType",
")",
";",
"$",
"transport",
"=",
"$",
"class",
"->",
"newInstanceArgs",
"(",
"$",
"transportArguments",
")",
";",
"}",
"else",
"{",
"$",
"transport",
"=",
"new",
"$",
"transportType",
"(",
")",
";",
"}",
"if",
"(",
"$",
"transport",
"instanceof",
"\\",
"Swift_Transport",
")",
"{",
"foreach",
"(",
"$",
"transportOptions",
"as",
"$",
"optionName",
"=>",
"$",
"optionValue",
")",
"{",
"if",
"(",
"ObjectAccess",
"::",
"isPropertySettable",
"(",
"$",
"transport",
",",
"$",
"optionName",
")",
")",
"{",
"ObjectAccess",
"::",
"setProperty",
"(",
"$",
"transport",
",",
"$",
"optionName",
",",
"$",
"optionValue",
")",
";",
"}",
"}",
"return",
"$",
"transport",
";",
"}",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"'The specified transport backend \"%s\" does not implement %s.'",
",",
"$",
"transportType",
",",
"\\",
"Swift_Transport",
"::",
"class",
")",
",",
"1544727431",
")",
";",
"}"
]
| Factory method which creates the specified transport with the given options.
@param string $transportType Object name of the transport to create
@param array $transportOptions Options for the transport
@param array $transportArguments Constructor arguments for the transport
@return \Swift_Transport The created transport instance
@throws Exception
@throws \ReflectionException | [
"Factory",
"method",
"which",
"creates",
"the",
"specified",
"transport",
"with",
"the",
"given",
"options",
"."
]
| 02aac015001563f6a30c48ab3c9449b6d400eede | https://github.com/neos/swiftmailer/blob/02aac015001563f6a30c48ab3c9449b6d400eede/Classes/TransportFactory.php#L34-L58 | train |
neos/swiftmailer | Classes/Transport/MboxTransport.php | MboxTransport.send | public function send(\Swift_Mime_SimpleMessage $message, &$failedRecipients = null)
{
$message->generateId();
// Create a mbox-like header
$mboxFrom = $this->getReversePath($message);
$mboxDate = strftime('%c', $message->getDate()->getTimestamp());
$messageString = sprintf('From %s %s', $mboxFrom, $mboxDate) . chr(10);
// Add the complete mail inclusive headers
$messageString .= $message->toString();
$messageString .= chr(10) . chr(10);
// Write the mbox file
file_put_contents($this->mboxPathAndFilename, $messageString, FILE_APPEND | LOCK_EX);
// Return every recipient as "delivered"
return count((array)$message->getTo()) + count((array)$message->getCc()) + count((array)$message->getBcc());
} | php | public function send(\Swift_Mime_SimpleMessage $message, &$failedRecipients = null)
{
$message->generateId();
// Create a mbox-like header
$mboxFrom = $this->getReversePath($message);
$mboxDate = strftime('%c', $message->getDate()->getTimestamp());
$messageString = sprintf('From %s %s', $mboxFrom, $mboxDate) . chr(10);
// Add the complete mail inclusive headers
$messageString .= $message->toString();
$messageString .= chr(10) . chr(10);
// Write the mbox file
file_put_contents($this->mboxPathAndFilename, $messageString, FILE_APPEND | LOCK_EX);
// Return every recipient as "delivered"
return count((array)$message->getTo()) + count((array)$message->getCc()) + count((array)$message->getBcc());
} | [
"public",
"function",
"send",
"(",
"\\",
"Swift_Mime_SimpleMessage",
"$",
"message",
",",
"&",
"$",
"failedRecipients",
"=",
"null",
")",
"{",
"$",
"message",
"->",
"generateId",
"(",
")",
";",
"// Create a mbox-like header",
"$",
"mboxFrom",
"=",
"$",
"this",
"->",
"getReversePath",
"(",
"$",
"message",
")",
";",
"$",
"mboxDate",
"=",
"strftime",
"(",
"'%c'",
",",
"$",
"message",
"->",
"getDate",
"(",
")",
"->",
"getTimestamp",
"(",
")",
")",
";",
"$",
"messageString",
"=",
"sprintf",
"(",
"'From %s %s'",
",",
"$",
"mboxFrom",
",",
"$",
"mboxDate",
")",
".",
"chr",
"(",
"10",
")",
";",
"// Add the complete mail inclusive headers",
"$",
"messageString",
".=",
"$",
"message",
"->",
"toString",
"(",
")",
";",
"$",
"messageString",
".=",
"chr",
"(",
"10",
")",
".",
"chr",
"(",
"10",
")",
";",
"// Write the mbox file",
"file_put_contents",
"(",
"$",
"this",
"->",
"mboxPathAndFilename",
",",
"$",
"messageString",
",",
"FILE_APPEND",
"|",
"LOCK_EX",
")",
";",
"// Return every recipient as \"delivered\"",
"return",
"count",
"(",
"(",
"array",
")",
"$",
"message",
"->",
"getTo",
"(",
")",
")",
"+",
"count",
"(",
"(",
"array",
")",
"$",
"message",
"->",
"getCc",
"(",
")",
")",
"+",
"count",
"(",
"(",
"array",
")",
"$",
"message",
"->",
"getBcc",
"(",
")",
")",
";",
"}"
]
| Outputs the mail to a text file according to RFC 4155.
@param \Swift_Mime_SimpleMessage $message The message to send
@param array &$failedRecipients Failed recipients (no failures in this transport)
@return int | [
"Outputs",
"the",
"mail",
"to",
"a",
"text",
"file",
"according",
"to",
"RFC",
"4155",
"."
]
| 02aac015001563f6a30c48ab3c9449b6d400eede | https://github.com/neos/swiftmailer/blob/02aac015001563f6a30c48ab3c9449b6d400eede/Classes/Transport/MboxTransport.php#L77-L95 | train |
easy-swoole/utility | src/Mime/MimeDetector.php | MimeDetector.setFile | public function setFile(string $filePath): self
{
if (!file_exists($filePath)) {
throw new MimeDetectorException("File '" . $filePath . "' does not exist.");
}
$this->stream = $this->readFile($filePath);
$this->createByteCache();
return $this;
} | php | public function setFile(string $filePath): self
{
if (!file_exists($filePath)) {
throw new MimeDetectorException("File '" . $filePath . "' does not exist.");
}
$this->stream = $this->readFile($filePath);
$this->createByteCache();
return $this;
} | [
"public",
"function",
"setFile",
"(",
"string",
"$",
"filePath",
")",
":",
"self",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"filePath",
")",
")",
"{",
"throw",
"new",
"MimeDetectorException",
"(",
"\"File '\"",
".",
"$",
"filePath",
".",
"\"' does not exist.\"",
")",
";",
"}",
"$",
"this",
"->",
"stream",
"=",
"$",
"this",
"->",
"readFile",
"(",
"$",
"filePath",
")",
";",
"$",
"this",
"->",
"createByteCache",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Setter for the file to be checked.
@param string $filePath
@return MimeDetector
@throws MimeDetectorException | [
"Setter",
"for",
"the",
"file",
"to",
"be",
"checked",
"."
]
| 11bf7d3604fc2bf1753354e5f6cf30417fcdf39b | https://github.com/easy-swoole/utility/blob/11bf7d3604fc2bf1753354e5f6cf30417fcdf39b/src/Mime/MimeDetector.php#L59-L68 | train |
easy-swoole/utility | src/Mime/MimeDetector.php | MimeDetector.checkString | protected function checkString(string $str, int $offset = 0): bool
{
return $this->checkForBytes($this->toBytes($str), $offset);
} | php | protected function checkString(string $str, int $offset = 0): bool
{
return $this->checkForBytes($this->toBytes($str), $offset);
} | [
"protected",
"function",
"checkString",
"(",
"string",
"$",
"str",
",",
"int",
"$",
"offset",
"=",
"0",
")",
":",
"bool",
"{",
"return",
"$",
"this",
"->",
"checkForBytes",
"(",
"$",
"this",
"->",
"toBytes",
"(",
"$",
"str",
")",
",",
"$",
"offset",
")",
";",
"}"
]
| Checks the byte sequence of a given string.
@param string $str
@param int $offset
@return bool | [
"Checks",
"the",
"byte",
"sequence",
"of",
"a",
"given",
"string",
"."
]
| 11bf7d3604fc2bf1753354e5f6cf30417fcdf39b | https://github.com/easy-swoole/utility/blob/11bf7d3604fc2bf1753354e5f6cf30417fcdf39b/src/Mime/MimeDetector.php#L1062-L1065 | train |
easy-swoole/utility | src/Mime/MimeDetector.php | MimeDetector.searchForBytes | protected function searchForBytes(array $bytes, int $offset = 0, array $mask = []): int
{
$limit = $this->byteCacheLen - count($bytes);
for ($i = $offset; $i < $limit; $i++) {
if ($this->checkForBytes($bytes, $i, $mask)) {
return $i;
}
}
return -1;
} | php | protected function searchForBytes(array $bytes, int $offset = 0, array $mask = []): int
{
$limit = $this->byteCacheLen - count($bytes);
for ($i = $offset; $i < $limit; $i++) {
if ($this->checkForBytes($bytes, $i, $mask)) {
return $i;
}
}
return -1;
} | [
"protected",
"function",
"searchForBytes",
"(",
"array",
"$",
"bytes",
",",
"int",
"$",
"offset",
"=",
"0",
",",
"array",
"$",
"mask",
"=",
"[",
"]",
")",
":",
"int",
"{",
"$",
"limit",
"=",
"$",
"this",
"->",
"byteCacheLen",
"-",
"count",
"(",
"$",
"bytes",
")",
";",
"for",
"(",
"$",
"i",
"=",
"$",
"offset",
";",
"$",
"i",
"<",
"$",
"limit",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"checkForBytes",
"(",
"$",
"bytes",
",",
"$",
"i",
",",
"$",
"mask",
")",
")",
"{",
"return",
"$",
"i",
";",
"}",
"}",
"return",
"-",
"1",
";",
"}"
]
| Returns the offset to the next position of the given byte sequence.
Returns -1 if the sequence was not found.
@param array $bytes
@param int $offset
@param array $mask
@return int | [
"Returns",
"the",
"offset",
"to",
"the",
"next",
"position",
"of",
"the",
"given",
"byte",
"sequence",
".",
"Returns",
"-",
"1",
"if",
"the",
"sequence",
"was",
"not",
"found",
"."
]
| 11bf7d3604fc2bf1753354e5f6cf30417fcdf39b | https://github.com/easy-swoole/utility/blob/11bf7d3604fc2bf1753354e5f6cf30417fcdf39b/src/Mime/MimeDetector.php#L1076-L1087 | train |
easy-swoole/utility | src/Mime/MimeDetector.php | MimeDetector.checkForBytes | protected function checkForBytes(array $bytes, int $offset = 0, array $mask = []): bool
{
if (empty($bytes) || empty($this->byteCache)) {
return false;
}
// make sure we have nummeric indices
$bytes = array_values($bytes);
foreach ($bytes as $i => $byte) {
if (!empty($mask)) {
if (!isset($this->byteCache[$offset + $i]) ||
!isset($mask[$i]) ||
$byte !== ($mask[$i] & $this->byteCache[$offset + $i])
) {
return false;
}
} elseif (!isset($this->byteCache[$offset + $i]) || $this->byteCache[$offset + $i] != $byte) {
return false;
}
}
return true;
} | php | protected function checkForBytes(array $bytes, int $offset = 0, array $mask = []): bool
{
if (empty($bytes) || empty($this->byteCache)) {
return false;
}
// make sure we have nummeric indices
$bytes = array_values($bytes);
foreach ($bytes as $i => $byte) {
if (!empty($mask)) {
if (!isset($this->byteCache[$offset + $i]) ||
!isset($mask[$i]) ||
$byte !== ($mask[$i] & $this->byteCache[$offset + $i])
) {
return false;
}
} elseif (!isset($this->byteCache[$offset + $i]) || $this->byteCache[$offset + $i] != $byte) {
return false;
}
}
return true;
} | [
"protected",
"function",
"checkForBytes",
"(",
"array",
"$",
"bytes",
",",
"int",
"$",
"offset",
"=",
"0",
",",
"array",
"$",
"mask",
"=",
"[",
"]",
")",
":",
"bool",
"{",
"if",
"(",
"empty",
"(",
"$",
"bytes",
")",
"||",
"empty",
"(",
"$",
"this",
"->",
"byteCache",
")",
")",
"{",
"return",
"false",
";",
"}",
"// make sure we have nummeric indices",
"$",
"bytes",
"=",
"array_values",
"(",
"$",
"bytes",
")",
";",
"foreach",
"(",
"$",
"bytes",
"as",
"$",
"i",
"=>",
"$",
"byte",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"mask",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"byteCache",
"[",
"$",
"offset",
"+",
"$",
"i",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"mask",
"[",
"$",
"i",
"]",
")",
"||",
"$",
"byte",
"!==",
"(",
"$",
"mask",
"[",
"$",
"i",
"]",
"&",
"$",
"this",
"->",
"byteCache",
"[",
"$",
"offset",
"+",
"$",
"i",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"elseif",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"byteCache",
"[",
"$",
"offset",
"+",
"$",
"i",
"]",
")",
"||",
"$",
"this",
"->",
"byteCache",
"[",
"$",
"offset",
"+",
"$",
"i",
"]",
"!=",
"$",
"byte",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
]
| Returns true, if a given byte sequence is found at the given offset within the given file.
@param array $bytes
@param int $offset
@param array $mask
@return bool | [
"Returns",
"true",
"if",
"a",
"given",
"byte",
"sequence",
"is",
"found",
"at",
"the",
"given",
"offset",
"within",
"the",
"given",
"file",
"."
]
| 11bf7d3604fc2bf1753354e5f6cf30417fcdf39b | https://github.com/easy-swoole/utility/blob/11bf7d3604fc2bf1753354e5f6cf30417fcdf39b/src/Mime/MimeDetector.php#L1097-L1120 | train |
grasmash/yaml-cli | src/Command/CommandBase.php | CommandBase.loadYamlFile | public function loadYamlFile($filename)
{
if (!file_exists($filename)) {
$this->output->writeln("<error>The file $filename does not exist.</error>");
return false;
}
try {
$contents = Yaml::parse(file_get_contents($filename));
} catch (\Exception $e) {
$this->output->writeln("<error>There was an error parsing $filename. The contents are not valid YAML.</error>");
$this->output->writeln($e->getMessage());
return false;
}
return $contents;
} | php | public function loadYamlFile($filename)
{
if (!file_exists($filename)) {
$this->output->writeln("<error>The file $filename does not exist.</error>");
return false;
}
try {
$contents = Yaml::parse(file_get_contents($filename));
} catch (\Exception $e) {
$this->output->writeln("<error>There was an error parsing $filename. The contents are not valid YAML.</error>");
$this->output->writeln($e->getMessage());
return false;
}
return $contents;
} | [
"public",
"function",
"loadYamlFile",
"(",
"$",
"filename",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"filename",
")",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"\"<error>The file $filename does not exist.</error>\"",
")",
";",
"return",
"false",
";",
"}",
"try",
"{",
"$",
"contents",
"=",
"Yaml",
"::",
"parse",
"(",
"file_get_contents",
"(",
"$",
"filename",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"\"<error>There was an error parsing $filename. The contents are not valid YAML.</error>\"",
")",
";",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"return",
"false",
";",
"}",
"return",
"$",
"contents",
";",
"}"
]
| Loads a yaml file.
@param $filename
The file name.
@return array|bool
The parsed content of the yaml file. FALSE if an error occured. | [
"Loads",
"a",
"yaml",
"file",
"."
]
| e069b51c05aa8a23aa5e5eac250b5a4d9f7f45dc | https://github.com/grasmash/yaml-cli/blob/e069b51c05aa8a23aa5e5eac250b5a4d9f7f45dc/src/Command/CommandBase.php#L58-L76 | train |
grasmash/yaml-cli | src/Command/CommandBase.php | CommandBase.writeYamlFile | public function writeYamlFile($filename, $data)
{
try {
// @todo Allow the inline and indent variables to be set via command line option.
$yaml = Yaml::dump($data->export(), 3, 2);
} catch (\Exception $e) {
$this->output->writeln("<error>There was an error dumping the YAML contents for $filename.</error>");
$this->output->writeln($e->getMessage());
return false;
}
try {
// @todo Use Symfony file system instead so that exceptions can be caught.
file_put_contents($filename, $yaml);
} catch (\Exception $e) {
$this->output->writeln("<error>There was an writing to $filename.</error>");
$this->output->writeln($e->getMessage());
return false;
}
return true;
} | php | public function writeYamlFile($filename, $data)
{
try {
// @todo Allow the inline and indent variables to be set via command line option.
$yaml = Yaml::dump($data->export(), 3, 2);
} catch (\Exception $e) {
$this->output->writeln("<error>There was an error dumping the YAML contents for $filename.</error>");
$this->output->writeln($e->getMessage());
return false;
}
try {
// @todo Use Symfony file system instead so that exceptions can be caught.
file_put_contents($filename, $yaml);
} catch (\Exception $e) {
$this->output->writeln("<error>There was an writing to $filename.</error>");
$this->output->writeln($e->getMessage());
return false;
}
return true;
} | [
"public",
"function",
"writeYamlFile",
"(",
"$",
"filename",
",",
"$",
"data",
")",
"{",
"try",
"{",
"// @todo Allow the inline and indent variables to be set via command line option.",
"$",
"yaml",
"=",
"Yaml",
"::",
"dump",
"(",
"$",
"data",
"->",
"export",
"(",
")",
",",
"3",
",",
"2",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"\"<error>There was an error dumping the YAML contents for $filename.</error>\"",
")",
";",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"return",
"false",
";",
"}",
"try",
"{",
"// @todo Use Symfony file system instead so that exceptions can be caught.",
"file_put_contents",
"(",
"$",
"filename",
",",
"$",
"yaml",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"\"<error>There was an writing to $filename.</error>\"",
")",
";",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
]
| Writes YAML data to a file.
@param string $filename
The filename.
@param Data $data
The YAML file contents.
@return bool
TRUE if file was written successfully. Otherwise, FALSE. | [
"Writes",
"YAML",
"data",
"to",
"a",
"file",
"."
]
| e069b51c05aa8a23aa5e5eac250b5a4d9f7f45dc | https://github.com/grasmash/yaml-cli/blob/e069b51c05aa8a23aa5e5eac250b5a4d9f7f45dc/src/Command/CommandBase.php#L89-L112 | train |
grasmash/yaml-cli | src/Command/CommandBase.php | CommandBase.checkKeyExists | protected function checkKeyExists($data, $key)
{
if (!$data->has($key)) {
$this->output->writeln("<error>The key $key does not exist.");
return false;
}
return true;
} | php | protected function checkKeyExists($data, $key)
{
if (!$data->has($key)) {
$this->output->writeln("<error>The key $key does not exist.");
return false;
}
return true;
} | [
"protected",
"function",
"checkKeyExists",
"(",
"$",
"data",
",",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"$",
"data",
"->",
"has",
"(",
"$",
"key",
")",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"\"<error>The key $key does not exist.\"",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
]
| Checks if a key exists in an array.
Supports dot notation for keys. E.g., first.second.parts.
@param array $data
The array of data that may contain key.
@param string $key
The array key, optionally in dot notation format.
@return bool | [
"Checks",
"if",
"a",
"key",
"exists",
"in",
"an",
"array",
"."
]
| e069b51c05aa8a23aa5e5eac250b5a4d9f7f45dc | https://github.com/grasmash/yaml-cli/blob/e069b51c05aa8a23aa5e5eac250b5a4d9f7f45dc/src/Command/CommandBase.php#L127-L136 | train |
wikimedia/oojs-ui | php/widgets/CheckboxMultiselectInputWidget.php | CheckboxMultiselectInputWidget.cleanUpValue | protected function cleanUpValue( $value ) {
$cleanValue = [];
if ( !is_array( $value ) ) {
return $cleanValue;
}
foreach ( $value as $singleValue ) {
$singleValue = parent::cleanUpValue( $singleValue );
// Remove options that we don't have here
if ( !isset( $this->fields[ $singleValue ] ) ) {
continue;
}
$cleanValue[] = $singleValue;
}
return $cleanValue;
} | php | protected function cleanUpValue( $value ) {
$cleanValue = [];
if ( !is_array( $value ) ) {
return $cleanValue;
}
foreach ( $value as $singleValue ) {
$singleValue = parent::cleanUpValue( $singleValue );
// Remove options that we don't have here
if ( !isset( $this->fields[ $singleValue ] ) ) {
continue;
}
$cleanValue[] = $singleValue;
}
return $cleanValue;
} | [
"protected",
"function",
"cleanUpValue",
"(",
"$",
"value",
")",
"{",
"$",
"cleanValue",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"cleanValue",
";",
"}",
"foreach",
"(",
"$",
"value",
"as",
"$",
"singleValue",
")",
"{",
"$",
"singleValue",
"=",
"parent",
"::",
"cleanUpValue",
"(",
"$",
"singleValue",
")",
";",
"// Remove options that we don't have here",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"fields",
"[",
"$",
"singleValue",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"cleanValue",
"[",
"]",
"=",
"$",
"singleValue",
";",
"}",
"return",
"$",
"cleanValue",
";",
"}"
]
| Clean up incoming value.
@param string[] $value Original value
@return string[] Cleaned up value | [
"Clean",
"up",
"incoming",
"value",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/widgets/CheckboxMultiselectInputWidget.php#L82-L96 | train |
wikimedia/oojs-ui | php/mixins/TitledElement.php | TitledElement.updateTitle | protected function updateTitle() {
$title = $this->getTitle();
if ( $title !== null ) {
// Only if this is an AccessKeyedElement
if ( method_exists( $this, 'formatTitleWithAccessKey' ) ) {
$title = $this->formatTitleWithAccessKey( $title );
}
$this->titled->setAttributes( [ 'title' => $title ] );
} else {
$this->titled->removeAttributes( [ 'title' ] );
}
return $this;
} | php | protected function updateTitle() {
$title = $this->getTitle();
if ( $title !== null ) {
// Only if this is an AccessKeyedElement
if ( method_exists( $this, 'formatTitleWithAccessKey' ) ) {
$title = $this->formatTitleWithAccessKey( $title );
}
$this->titled->setAttributes( [ 'title' => $title ] );
} else {
$this->titled->removeAttributes( [ 'title' ] );
}
return $this;
} | [
"protected",
"function",
"updateTitle",
"(",
")",
"{",
"$",
"title",
"=",
"$",
"this",
"->",
"getTitle",
"(",
")",
";",
"if",
"(",
"$",
"title",
"!==",
"null",
")",
"{",
"// Only if this is an AccessKeyedElement",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"'formatTitleWithAccessKey'",
")",
")",
"{",
"$",
"title",
"=",
"$",
"this",
"->",
"formatTitleWithAccessKey",
"(",
"$",
"title",
")",
";",
"}",
"$",
"this",
"->",
"titled",
"->",
"setAttributes",
"(",
"[",
"'title'",
"=>",
"$",
"title",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"titled",
"->",
"removeAttributes",
"(",
"[",
"'title'",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Update the title attribute, in case of changes to title or accessKey.
@return $this | [
"Update",
"the",
"title",
"attribute",
"in",
"case",
"of",
"changes",
"to",
"title",
"or",
"accessKey",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/mixins/TitledElement.php#L65-L77 | train |
wikimedia/oojs-ui | php/widgets/CheckboxInputWidget.php | CheckboxInputWidget.setSelected | public function setSelected( $state ) {
$this->selected = (bool)$state;
if ( $this->selected ) {
$this->input->setAttributes( [ 'checked' => 'checked' ] );
} else {
$this->input->removeAttributes( [ 'checked' ] );
}
return $this;
} | php | public function setSelected( $state ) {
$this->selected = (bool)$state;
if ( $this->selected ) {
$this->input->setAttributes( [ 'checked' => 'checked' ] );
} else {
$this->input->removeAttributes( [ 'checked' ] );
}
return $this;
} | [
"public",
"function",
"setSelected",
"(",
"$",
"state",
")",
"{",
"$",
"this",
"->",
"selected",
"=",
"(",
"bool",
")",
"$",
"state",
";",
"if",
"(",
"$",
"this",
"->",
"selected",
")",
"{",
"$",
"this",
"->",
"input",
"->",
"setAttributes",
"(",
"[",
"'checked'",
"=>",
"'checked'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"input",
"->",
"removeAttributes",
"(",
"[",
"'checked'",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Set selection state of this checkbox.
@param bool $state Whether the checkbox is selected
@return $this | [
"Set",
"selection",
"state",
"of",
"this",
"checkbox",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/widgets/CheckboxInputWidget.php#L59-L67 | train |
wikimedia/oojs-ui | php/Theme.php | Theme.updateElementClasses | public function updateElementClasses( Element $element ) {
$classes = $this->getElementClasses( $element );
if ( method_exists( $element, 'getIconElement' ) ) {
$element->getIconElement()
->removeClasses( $classes['off'] )
->addClasses( $classes['on'] );
}
if ( method_exists( $element, 'getIndicatorElement' ) ) {
$element->getIndicatorElement()
->removeClasses( $classes['off'] )
->addClasses( $classes['on'] );
}
} | php | public function updateElementClasses( Element $element ) {
$classes = $this->getElementClasses( $element );
if ( method_exists( $element, 'getIconElement' ) ) {
$element->getIconElement()
->removeClasses( $classes['off'] )
->addClasses( $classes['on'] );
}
if ( method_exists( $element, 'getIndicatorElement' ) ) {
$element->getIndicatorElement()
->removeClasses( $classes['off'] )
->addClasses( $classes['on'] );
}
} | [
"public",
"function",
"updateElementClasses",
"(",
"Element",
"$",
"element",
")",
"{",
"$",
"classes",
"=",
"$",
"this",
"->",
"getElementClasses",
"(",
"$",
"element",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"element",
",",
"'getIconElement'",
")",
")",
"{",
"$",
"element",
"->",
"getIconElement",
"(",
")",
"->",
"removeClasses",
"(",
"$",
"classes",
"[",
"'off'",
"]",
")",
"->",
"addClasses",
"(",
"$",
"classes",
"[",
"'on'",
"]",
")",
";",
"}",
"if",
"(",
"method_exists",
"(",
"$",
"element",
",",
"'getIndicatorElement'",
")",
")",
"{",
"$",
"element",
"->",
"getIndicatorElement",
"(",
")",
"->",
"removeClasses",
"(",
"$",
"classes",
"[",
"'off'",
"]",
")",
"->",
"addClasses",
"(",
"$",
"classes",
"[",
"'on'",
"]",
")",
";",
"}",
"}"
]
| Update CSS classes provided by the theme.
For elements with theme logic hooks, this should be called any time there's a state change.
@param Element $element Element for which to update classes
@return array Categorized class names with `on` and `off` lists | [
"Update",
"CSS",
"classes",
"provided",
"by",
"the",
"theme",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/Theme.php#L58-L71 | train |
wikimedia/oojs-ui | php/mixins/TabIndexedElement.php | TabIndexedElement.setTabIndex | public function setTabIndex( $tabIndex ) {
$tabIndex = preg_match( '/^-?\d+$/', $tabIndex ) ? (int)$tabIndex : null;
if ( $this->tabIndex !== $tabIndex ) {
$this->tabIndex = $tabIndex;
$this->updateTabIndex();
}
return $this;
} | php | public function setTabIndex( $tabIndex ) {
$tabIndex = preg_match( '/^-?\d+$/', $tabIndex ) ? (int)$tabIndex : null;
if ( $this->tabIndex !== $tabIndex ) {
$this->tabIndex = $tabIndex;
$this->updateTabIndex();
}
return $this;
} | [
"public",
"function",
"setTabIndex",
"(",
"$",
"tabIndex",
")",
"{",
"$",
"tabIndex",
"=",
"preg_match",
"(",
"'/^-?\\d+$/'",
",",
"$",
"tabIndex",
")",
"?",
"(",
"int",
")",
"$",
"tabIndex",
":",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"tabIndex",
"!==",
"$",
"tabIndex",
")",
"{",
"$",
"this",
"->",
"tabIndex",
"=",
"$",
"tabIndex",
";",
"$",
"this",
"->",
"updateTabIndex",
"(",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Set tab index value.
@param string|int|null $tabIndex Tab index value or null for no tab index
@return $this | [
"Set",
"tab",
"index",
"value",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/mixins/TabIndexedElement.php#L49-L58 | train |
wikimedia/oojs-ui | php/mixins/TabIndexedElement.php | TabIndexedElement.updateTabIndex | public function updateTabIndex() {
$disabled = $this->isDisabled();
if ( $this->tabIndex !== null ) {
$this->tabIndexed->setAttributes( [
// Do not index over disabled elements
'tabindex' => $disabled ? -1 : $this->tabIndex,
// ChromeVox and NVDA do not seem to inherit this from parent elements
'aria-disabled' => ( $disabled ? 'true' : 'false' )
] );
} else {
$this->tabIndexed->removeAttributes( [ 'tabindex', 'aria-disabled' ] );
}
return $this;
} | php | public function updateTabIndex() {
$disabled = $this->isDisabled();
if ( $this->tabIndex !== null ) {
$this->tabIndexed->setAttributes( [
// Do not index over disabled elements
'tabindex' => $disabled ? -1 : $this->tabIndex,
// ChromeVox and NVDA do not seem to inherit this from parent elements
'aria-disabled' => ( $disabled ? 'true' : 'false' )
] );
} else {
$this->tabIndexed->removeAttributes( [ 'tabindex', 'aria-disabled' ] );
}
return $this;
} | [
"public",
"function",
"updateTabIndex",
"(",
")",
"{",
"$",
"disabled",
"=",
"$",
"this",
"->",
"isDisabled",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"tabIndex",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"tabIndexed",
"->",
"setAttributes",
"(",
"[",
"// Do not index over disabled elements",
"'tabindex'",
"=>",
"$",
"disabled",
"?",
"-",
"1",
":",
"$",
"this",
"->",
"tabIndex",
",",
"// ChromeVox and NVDA do not seem to inherit this from parent elements",
"'aria-disabled'",
"=>",
"(",
"$",
"disabled",
"?",
"'true'",
":",
"'false'",
")",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"tabIndexed",
"->",
"removeAttributes",
"(",
"[",
"'tabindex'",
",",
"'aria-disabled'",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Update the tabIndex attribute, in case of changes to tabIndex or disabled
state.
@return $this | [
"Update",
"the",
"tabIndex",
"attribute",
"in",
"case",
"of",
"changes",
"to",
"tabIndex",
"or",
"disabled",
"state",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/mixins/TabIndexedElement.php#L66-L79 | train |
wikimedia/oojs-ui | php/mixins/IconElement.php | IconElement.setIcon | public function setIcon( $icon = null ) {
if ( $this->iconName !== null ) {
$this->icon->removeClasses( [ 'oo-ui-icon-' . $this->iconName ] );
}
if ( $icon !== null ) {
$this->icon->addClasses( [ 'oo-ui-icon-' . $icon ] );
}
$this->iconName = $icon;
$this->toggleClasses( [ 'oo-ui-iconElement' ], (bool)$this->iconName );
$this->icon->toggleClasses( [ 'oo-ui-iconElement-noIcon' ], !$this->iconName );
return $this;
} | php | public function setIcon( $icon = null ) {
if ( $this->iconName !== null ) {
$this->icon->removeClasses( [ 'oo-ui-icon-' . $this->iconName ] );
}
if ( $icon !== null ) {
$this->icon->addClasses( [ 'oo-ui-icon-' . $icon ] );
}
$this->iconName = $icon;
$this->toggleClasses( [ 'oo-ui-iconElement' ], (bool)$this->iconName );
$this->icon->toggleClasses( [ 'oo-ui-iconElement-noIcon' ], !$this->iconName );
return $this;
} | [
"public",
"function",
"setIcon",
"(",
"$",
"icon",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"iconName",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"icon",
"->",
"removeClasses",
"(",
"[",
"'oo-ui-icon-'",
".",
"$",
"this",
"->",
"iconName",
"]",
")",
";",
"}",
"if",
"(",
"$",
"icon",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"icon",
"->",
"addClasses",
"(",
"[",
"'oo-ui-icon-'",
".",
"$",
"icon",
"]",
")",
";",
"}",
"$",
"this",
"->",
"iconName",
"=",
"$",
"icon",
";",
"$",
"this",
"->",
"toggleClasses",
"(",
"[",
"'oo-ui-iconElement'",
"]",
",",
"(",
"bool",
")",
"$",
"this",
"->",
"iconName",
")",
";",
"$",
"this",
"->",
"icon",
"->",
"toggleClasses",
"(",
"[",
"'oo-ui-iconElement-noIcon'",
"]",
",",
"!",
"$",
"this",
"->",
"iconName",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Set icon name.
@param string|null $icon Symbolic icon name
@return $this | [
"Set",
"icon",
"name",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/mixins/IconElement.php#L54-L67 | train |
wikimedia/oojs-ui | php/widgets/TextInputWidget.php | TextInputWidget.setReadOnly | public function setReadOnly( $state ) {
$this->readOnly = (bool)$state;
if ( $this->readOnly ) {
$this->input->setAttributes( [ 'readonly' => 'readonly' ] );
} else {
$this->input->removeAttributes( [ 'readonly' ] );
}
return $this;
} | php | public function setReadOnly( $state ) {
$this->readOnly = (bool)$state;
if ( $this->readOnly ) {
$this->input->setAttributes( [ 'readonly' => 'readonly' ] );
} else {
$this->input->removeAttributes( [ 'readonly' ] );
}
return $this;
} | [
"public",
"function",
"setReadOnly",
"(",
"$",
"state",
")",
"{",
"$",
"this",
"->",
"readOnly",
"=",
"(",
"bool",
")",
"$",
"state",
";",
"if",
"(",
"$",
"this",
"->",
"readOnly",
")",
"{",
"$",
"this",
"->",
"input",
"->",
"setAttributes",
"(",
"[",
"'readonly'",
"=>",
"'readonly'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"input",
"->",
"removeAttributes",
"(",
"[",
"'readonly'",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Set the read-only state of the widget. This should probably change the widget's appearance and
prevent it from being used.
@param bool $state Make input read-only
@return $this | [
"Set",
"the",
"read",
"-",
"only",
"state",
"of",
"the",
"widget",
".",
"This",
"should",
"probably",
"change",
"the",
"widget",
"s",
"appearance",
"and",
"prevent",
"it",
"from",
"being",
"used",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/widgets/TextInputWidget.php#L123-L131 | train |
wikimedia/oojs-ui | php/widgets/TextInputWidget.php | TextInputWidget.setRequired | public function setRequired( $state ) {
$this->required = (bool)$state;
if ( $this->required ) {
$this->input->setAttributes( [ 'required' => 'required', 'aria-required' => 'true' ] );
if ( $this->getIndicator() === null ) {
$this->setIndicator( 'required' );
}
} else {
$this->input->removeAttributes( [ 'required', 'aria-required' ] );
if ( $this->getIndicator() === 'required' ) {
$this->setIndicator( null );
}
}
return $this;
} | php | public function setRequired( $state ) {
$this->required = (bool)$state;
if ( $this->required ) {
$this->input->setAttributes( [ 'required' => 'required', 'aria-required' => 'true' ] );
if ( $this->getIndicator() === null ) {
$this->setIndicator( 'required' );
}
} else {
$this->input->removeAttributes( [ 'required', 'aria-required' ] );
if ( $this->getIndicator() === 'required' ) {
$this->setIndicator( null );
}
}
return $this;
} | [
"public",
"function",
"setRequired",
"(",
"$",
"state",
")",
"{",
"$",
"this",
"->",
"required",
"=",
"(",
"bool",
")",
"$",
"state",
";",
"if",
"(",
"$",
"this",
"->",
"required",
")",
"{",
"$",
"this",
"->",
"input",
"->",
"setAttributes",
"(",
"[",
"'required'",
"=>",
"'required'",
",",
"'aria-required'",
"=>",
"'true'",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getIndicator",
"(",
")",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"setIndicator",
"(",
"'required'",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"input",
"->",
"removeAttributes",
"(",
"[",
"'required'",
",",
"'aria-required'",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getIndicator",
"(",
")",
"===",
"'required'",
")",
"{",
"$",
"this",
"->",
"setIndicator",
"(",
"null",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
]
| Set the required state of the widget.
@param bool $state Make input required
@return $this | [
"Set",
"the",
"required",
"state",
"of",
"the",
"widget",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/widgets/TextInputWidget.php#L148-L162 | train |
wikimedia/oojs-ui | php/Widget.php | Widget.setDisabled | public function setDisabled( $disabled ) {
$this->disabled = (bool)$disabled;
$this->toggleClasses( [ 'oo-ui-widget-disabled' ], $this->disabled );
$this->toggleClasses( [ 'oo-ui-widget-enabled' ], !$this->disabled );
$this->setAttributes( [ 'aria-disabled' => $this->disabled ? 'true' : 'false' ] );
return $this;
} | php | public function setDisabled( $disabled ) {
$this->disabled = (bool)$disabled;
$this->toggleClasses( [ 'oo-ui-widget-disabled' ], $this->disabled );
$this->toggleClasses( [ 'oo-ui-widget-enabled' ], !$this->disabled );
$this->setAttributes( [ 'aria-disabled' => $this->disabled ? 'true' : 'false' ] );
return $this;
} | [
"public",
"function",
"setDisabled",
"(",
"$",
"disabled",
")",
"{",
"$",
"this",
"->",
"disabled",
"=",
"(",
"bool",
")",
"$",
"disabled",
";",
"$",
"this",
"->",
"toggleClasses",
"(",
"[",
"'oo-ui-widget-disabled'",
"]",
",",
"$",
"this",
"->",
"disabled",
")",
";",
"$",
"this",
"->",
"toggleClasses",
"(",
"[",
"'oo-ui-widget-enabled'",
"]",
",",
"!",
"$",
"this",
"->",
"disabled",
")",
";",
"$",
"this",
"->",
"setAttributes",
"(",
"[",
"'aria-disabled'",
"=>",
"$",
"this",
"->",
"disabled",
"?",
"'true'",
":",
"'false'",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Set the disabled state of the widget.
This should probably change the widgets' appearance and prevent it from being used.
@param bool $disabled Disable widget
@return $this | [
"Set",
"the",
"disabled",
"state",
"of",
"the",
"widget",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/Widget.php#L57-L64 | train |
wikimedia/oojs-ui | php/widgets/ButtonWidget.php | ButtonWidget.setHref | public function setHref( $href ) {
$this->href = is_string( $href ) ? $href : null;
$this->updateHref();
return $this;
} | php | public function setHref( $href ) {
$this->href = is_string( $href ) ? $href : null;
$this->updateHref();
return $this;
} | [
"public",
"function",
"setHref",
"(",
"$",
"href",
")",
"{",
"$",
"this",
"->",
"href",
"=",
"is_string",
"(",
"$",
"href",
")",
"?",
"$",
"href",
":",
"null",
";",
"$",
"this",
"->",
"updateHref",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Set hyperlink location.
@param string|null $href Hyperlink location, null to remove
@return $this | [
"Set",
"hyperlink",
"location",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/widgets/ButtonWidget.php#L127-L133 | train |
wikimedia/oojs-ui | php/widgets/ButtonWidget.php | ButtonWidget.updateHref | public function updateHref() {
if ( $this->href !== null && !$this->isDisabled() ) {
$this->button->setAttributes( [ 'href' => $this->href ] );
} else {
$this->button->removeAttributes( [ 'href' ] );
}
return $this;
} | php | public function updateHref() {
if ( $this->href !== null && !$this->isDisabled() ) {
$this->button->setAttributes( [ 'href' => $this->href ] );
} else {
$this->button->removeAttributes( [ 'href' ] );
}
return $this;
} | [
"public",
"function",
"updateHref",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"href",
"!==",
"null",
"&&",
"!",
"$",
"this",
"->",
"isDisabled",
"(",
")",
")",
"{",
"$",
"this",
"->",
"button",
"->",
"setAttributes",
"(",
"[",
"'href'",
"=>",
"$",
"this",
"->",
"href",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"button",
"->",
"removeAttributes",
"(",
"[",
"'href'",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Update the href attribute, in case of changes to href or disabled
state.
@return $this | [
"Update",
"the",
"href",
"attribute",
"in",
"case",
"of",
"changes",
"to",
"href",
"or",
"disabled",
"state",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/widgets/ButtonWidget.php#L141-L148 | train |
wikimedia/oojs-ui | php/widgets/ButtonWidget.php | ButtonWidget.setTarget | public function setTarget( $target ) {
$this->target = is_string( $target ) ? $target : null;
if ( $this->target !== null ) {
$this->button->setAttributes( [ 'target' => $target ] );
} else {
$this->button->removeAttributes( [ 'target' ] );
}
return $this;
} | php | public function setTarget( $target ) {
$this->target = is_string( $target ) ? $target : null;
if ( $this->target !== null ) {
$this->button->setAttributes( [ 'target' => $target ] );
} else {
$this->button->removeAttributes( [ 'target' ] );
}
return $this;
} | [
"public",
"function",
"setTarget",
"(",
"$",
"target",
")",
"{",
"$",
"this",
"->",
"target",
"=",
"is_string",
"(",
"$",
"target",
")",
"?",
"$",
"target",
":",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"target",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"button",
"->",
"setAttributes",
"(",
"[",
"'target'",
"=>",
"$",
"target",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"button",
"->",
"removeAttributes",
"(",
"[",
"'target'",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Set hyperlink target.
@param string|null $target Hyperlink target, null to remove
@return $this | [
"Set",
"hyperlink",
"target",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/widgets/ButtonWidget.php#L156-L166 | train |
wikimedia/oojs-ui | php/widgets/ButtonWidget.php | ButtonWidget.setNoFollow | public function setNoFollow( $noFollow ) {
$this->noFollow = is_bool( $noFollow ) ? $noFollow : true;
if ( $this->noFollow ) {
$this->button->setAttributes( [ 'rel' => 'nofollow' ] );
} else {
$this->button->removeAttributes( [ 'rel' ] );
}
return $this;
} | php | public function setNoFollow( $noFollow ) {
$this->noFollow = is_bool( $noFollow ) ? $noFollow : true;
if ( $this->noFollow ) {
$this->button->setAttributes( [ 'rel' => 'nofollow' ] );
} else {
$this->button->removeAttributes( [ 'rel' ] );
}
return $this;
} | [
"public",
"function",
"setNoFollow",
"(",
"$",
"noFollow",
")",
"{",
"$",
"this",
"->",
"noFollow",
"=",
"is_bool",
"(",
"$",
"noFollow",
")",
"?",
"$",
"noFollow",
":",
"true",
";",
"if",
"(",
"$",
"this",
"->",
"noFollow",
")",
"{",
"$",
"this",
"->",
"button",
"->",
"setAttributes",
"(",
"[",
"'rel'",
"=>",
"'nofollow'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"button",
"->",
"removeAttributes",
"(",
"[",
"'rel'",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Set search engine traversal hint.
@param bool $noFollow True if search engines should avoid traversing this hyperlink
@return $this | [
"Set",
"search",
"engine",
"traversal",
"hint",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/widgets/ButtonWidget.php#L174-L184 | train |
wikimedia/oojs-ui | php/widgets/ButtonWidget.php | ButtonWidget.setActive | public function setActive( $active = null ) {
$this->active = (bool)$active;
$this->toggleClasses( [ 'oo-ui-buttonElement-active' ], $this->active );
return $this;
} | php | public function setActive( $active = null ) {
$this->active = (bool)$active;
$this->toggleClasses( [ 'oo-ui-buttonElement-active' ], $this->active );
return $this;
} | [
"public",
"function",
"setActive",
"(",
"$",
"active",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"active",
"=",
"(",
"bool",
")",
"$",
"active",
";",
"$",
"this",
"->",
"toggleClasses",
"(",
"[",
"'oo-ui-buttonElement-active'",
"]",
",",
"$",
"this",
"->",
"active",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Toggle active state.
A button should be marked as active when clicking it would only refresh the page.
@param bool|null $active Make button active
@return $this | [
"Toggle",
"active",
"state",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/widgets/ButtonWidget.php#L194-L198 | train |
wikimedia/oojs-ui | php/widgets/ButtonInputWidget.php | ButtonInputWidget.setLabel | public function setLabel( $label ) {
if ( $this->useInputTag ) {
// Discard non-plaintext labels
if ( !is_string( $label ) ) {
$label = '';
}
$this->input->setValue( $label );
}
return $this->setLabelElementLabel( $label );
} | php | public function setLabel( $label ) {
if ( $this->useInputTag ) {
// Discard non-plaintext labels
if ( !is_string( $label ) ) {
$label = '';
}
$this->input->setValue( $label );
}
return $this->setLabelElementLabel( $label );
} | [
"public",
"function",
"setLabel",
"(",
"$",
"label",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"useInputTag",
")",
"{",
"// Discard non-plaintext labels",
"if",
"(",
"!",
"is_string",
"(",
"$",
"label",
")",
")",
"{",
"$",
"label",
"=",
"''",
";",
"}",
"$",
"this",
"->",
"input",
"->",
"setValue",
"(",
"$",
"label",
")",
";",
"}",
"return",
"$",
"this",
"->",
"setLabelElementLabel",
"(",
"$",
"label",
")",
";",
"}"
]
| Set label value.
Overridden to support setting the 'value' of `<input>` elements.
@param string|null $label Label text
@return $this | [
"Set",
"label",
"value",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/widgets/ButtonInputWidget.php#L86-L97 | train |
wikimedia/oojs-ui | php/layouts/IndexLayout.php | IndexLayout.addTabPanels | public function addTabPanels( array $tabPanels ) {
$tabItems = [];
foreach ( $tabPanels as $i => $tabPanel ) {
$this->tabPanels[ $tabPanel->getName() ] = $tabPanel;
$labelElement = new Tag( 'span' );
$tabItem = new TabOptionWidget( [
'labelElement' => $labelElement,
'label' => $tabPanel->getLabel(),
'data' => $tabPanel->getName(),
// Select the first item
// TODO: Support selecting an arbitrary item
'selected' => $this->tabSelectWidget->isEmpty() && $i === 0
] );
$tabItems[] = $tabItem;
}
$this->tabSelectWidget->addItems( $tabItems );
$this->stackLayout->addItems( $tabPanels );
} | php | public function addTabPanels( array $tabPanels ) {
$tabItems = [];
foreach ( $tabPanels as $i => $tabPanel ) {
$this->tabPanels[ $tabPanel->getName() ] = $tabPanel;
$labelElement = new Tag( 'span' );
$tabItem = new TabOptionWidget( [
'labelElement' => $labelElement,
'label' => $tabPanel->getLabel(),
'data' => $tabPanel->getName(),
// Select the first item
// TODO: Support selecting an arbitrary item
'selected' => $this->tabSelectWidget->isEmpty() && $i === 0
] );
$tabItems[] = $tabItem;
}
$this->tabSelectWidget->addItems( $tabItems );
$this->stackLayout->addItems( $tabPanels );
} | [
"public",
"function",
"addTabPanels",
"(",
"array",
"$",
"tabPanels",
")",
"{",
"$",
"tabItems",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"tabPanels",
"as",
"$",
"i",
"=>",
"$",
"tabPanel",
")",
"{",
"$",
"this",
"->",
"tabPanels",
"[",
"$",
"tabPanel",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"tabPanel",
";",
"$",
"labelElement",
"=",
"new",
"Tag",
"(",
"'span'",
")",
";",
"$",
"tabItem",
"=",
"new",
"TabOptionWidget",
"(",
"[",
"'labelElement'",
"=>",
"$",
"labelElement",
",",
"'label'",
"=>",
"$",
"tabPanel",
"->",
"getLabel",
"(",
")",
",",
"'data'",
"=>",
"$",
"tabPanel",
"->",
"getName",
"(",
")",
",",
"// Select the first item",
"// TODO: Support selecting an arbitrary item",
"'selected'",
"=>",
"$",
"this",
"->",
"tabSelectWidget",
"->",
"isEmpty",
"(",
")",
"&&",
"$",
"i",
"===",
"0",
"]",
")",
";",
"$",
"tabItems",
"[",
"]",
"=",
"$",
"tabItem",
";",
"}",
"$",
"this",
"->",
"tabSelectWidget",
"->",
"addItems",
"(",
"$",
"tabItems",
")",
";",
"$",
"this",
"->",
"stackLayout",
"->",
"addItems",
"(",
"$",
"tabPanels",
")",
";",
"}"
]
| Add tab panels to the index layout
When tab panels are added with the same names as existing tab panels, the existing tab panels
will be automatically removed before the new tab panels are added.
@param TabPanelLayout[] $tabPanels Tab panels to add | [
"Add",
"tab",
"panels",
"to",
"the",
"index",
"layout"
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/layouts/IndexLayout.php#L106-L123 | train |
wikimedia/oojs-ui | php/mixins/GroupElement.php | GroupElement.addItems | public function addItems( array $items, $index = null ) {
foreach ( $items as $item ) {
// Check if item exists then remove it first, effectively "moving" it
$currentIndex = array_search( $item, $this->items, true );
if ( $currentIndex !== false ) {
$this->removeItems( [ $item ] );
// Adjust index to compensate for removal
if ( $currentIndex < $index ) {
$index--;
}
}
// Add the item
$item->setElementGroup( $this );
}
if ( $index === null || $index < 0 || $index >= count( $this->items ) ) {
$this->items = array_merge( $this->items, $items );
} else {
array_splice( $this->items, $index, 0, $items );
}
// Update actual target element contents to reflect our list
$this->group->clearContent();
$this->group->appendContent( $this->items );
return $this;
} | php | public function addItems( array $items, $index = null ) {
foreach ( $items as $item ) {
// Check if item exists then remove it first, effectively "moving" it
$currentIndex = array_search( $item, $this->items, true );
if ( $currentIndex !== false ) {
$this->removeItems( [ $item ] );
// Adjust index to compensate for removal
if ( $currentIndex < $index ) {
$index--;
}
}
// Add the item
$item->setElementGroup( $this );
}
if ( $index === null || $index < 0 || $index >= count( $this->items ) ) {
$this->items = array_merge( $this->items, $items );
} else {
array_splice( $this->items, $index, 0, $items );
}
// Update actual target element contents to reflect our list
$this->group->clearContent();
$this->group->appendContent( $this->items );
return $this;
} | [
"public",
"function",
"addItems",
"(",
"array",
"$",
"items",
",",
"$",
"index",
"=",
"null",
")",
"{",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"// Check if item exists then remove it first, effectively \"moving\" it",
"$",
"currentIndex",
"=",
"array_search",
"(",
"$",
"item",
",",
"$",
"this",
"->",
"items",
",",
"true",
")",
";",
"if",
"(",
"$",
"currentIndex",
"!==",
"false",
")",
"{",
"$",
"this",
"->",
"removeItems",
"(",
"[",
"$",
"item",
"]",
")",
";",
"// Adjust index to compensate for removal",
"if",
"(",
"$",
"currentIndex",
"<",
"$",
"index",
")",
"{",
"$",
"index",
"--",
";",
"}",
"}",
"// Add the item",
"$",
"item",
"->",
"setElementGroup",
"(",
"$",
"this",
")",
";",
"}",
"if",
"(",
"$",
"index",
"===",
"null",
"||",
"$",
"index",
"<",
"0",
"||",
"$",
"index",
">=",
"count",
"(",
"$",
"this",
"->",
"items",
")",
")",
"{",
"$",
"this",
"->",
"items",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"items",
",",
"$",
"items",
")",
";",
"}",
"else",
"{",
"array_splice",
"(",
"$",
"this",
"->",
"items",
",",
"$",
"index",
",",
"0",
",",
"$",
"items",
")",
";",
"}",
"// Update actual target element contents to reflect our list",
"$",
"this",
"->",
"group",
"->",
"clearContent",
"(",
")",
";",
"$",
"this",
"->",
"group",
"->",
"appendContent",
"(",
"$",
"this",
"->",
"items",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Add items.
Adding an existing item will move it.
@param Element[] $items Items
@param int|null $index Index to insert items at
@return $this | [
"Add",
"items",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/mixins/GroupElement.php#L62-L88 | train |
wikimedia/oojs-ui | php/mixins/GroupElement.php | GroupElement.removeItems | public function removeItems( $items ) {
foreach ( $items as $item ) {
$index = array_search( $item, $this->items, true );
if ( $index !== false ) {
$item->setElementGroup( null );
array_splice( $this->items, $index, 1 );
}
}
// Update actual target element contents to reflect our list
$this->group->clearContent();
$this->group->appendContent( $this->items );
return $this;
} | php | public function removeItems( $items ) {
foreach ( $items as $item ) {
$index = array_search( $item, $this->items, true );
if ( $index !== false ) {
$item->setElementGroup( null );
array_splice( $this->items, $index, 1 );
}
}
// Update actual target element contents to reflect our list
$this->group->clearContent();
$this->group->appendContent( $this->items );
return $this;
} | [
"public",
"function",
"removeItems",
"(",
"$",
"items",
")",
"{",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"$",
"index",
"=",
"array_search",
"(",
"$",
"item",
",",
"$",
"this",
"->",
"items",
",",
"true",
")",
";",
"if",
"(",
"$",
"index",
"!==",
"false",
")",
"{",
"$",
"item",
"->",
"setElementGroup",
"(",
"null",
")",
";",
"array_splice",
"(",
"$",
"this",
"->",
"items",
",",
"$",
"index",
",",
"1",
")",
";",
"}",
"}",
"// Update actual target element contents to reflect our list",
"$",
"this",
"->",
"group",
"->",
"clearContent",
"(",
")",
";",
"$",
"this",
"->",
"group",
"->",
"appendContent",
"(",
"$",
"this",
"->",
"items",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Remove items.
@param Element[] $items Items to remove
@return $this | [
"Remove",
"items",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/mixins/GroupElement.php#L96-L110 | train |
wikimedia/oojs-ui | php/mixins/GroupElement.php | GroupElement.clearItems | public function clearItems() {
foreach ( $this->items as $item ) {
$item->setElementGroup( null );
}
$this->items = [];
$this->group->clearContent();
return $this;
} | php | public function clearItems() {
foreach ( $this->items as $item ) {
$item->setElementGroup( null );
}
$this->items = [];
$this->group->clearContent();
return $this;
} | [
"public",
"function",
"clearItems",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"items",
"as",
"$",
"item",
")",
"{",
"$",
"item",
"->",
"setElementGroup",
"(",
"null",
")",
";",
"}",
"$",
"this",
"->",
"items",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"group",
"->",
"clearContent",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Clear all items.
Items will be detached, not removed, so they can be used later.
@return $this | [
"Clear",
"all",
"items",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/mixins/GroupElement.php#L119-L128 | train |
wikimedia/oojs-ui | php/mixins/IndicatorElement.php | IndicatorElement.setIndicator | public function setIndicator( $indicator = null ) {
if ( $this->indicatorName !== null ) {
$this->indicator->removeClasses( [ 'oo-ui-indicator-' . $this->indicatorName ] );
}
if ( $indicator !== null ) {
$this->indicator->addClasses( [ 'oo-ui-indicator-' . $indicator ] );
}
$this->indicatorName = $indicator;
$this->toggleClasses( [ 'oo-ui-indicatorElement' ], (bool)$this->indicatorName );
$this->indicator->toggleClasses( [ 'oo-ui-indicatorElement-noIndicator' ],
!$this->indicatorName );
return $this;
} | php | public function setIndicator( $indicator = null ) {
if ( $this->indicatorName !== null ) {
$this->indicator->removeClasses( [ 'oo-ui-indicator-' . $this->indicatorName ] );
}
if ( $indicator !== null ) {
$this->indicator->addClasses( [ 'oo-ui-indicator-' . $indicator ] );
}
$this->indicatorName = $indicator;
$this->toggleClasses( [ 'oo-ui-indicatorElement' ], (bool)$this->indicatorName );
$this->indicator->toggleClasses( [ 'oo-ui-indicatorElement-noIndicator' ],
!$this->indicatorName );
return $this;
} | [
"public",
"function",
"setIndicator",
"(",
"$",
"indicator",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"indicatorName",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"indicator",
"->",
"removeClasses",
"(",
"[",
"'oo-ui-indicator-'",
".",
"$",
"this",
"->",
"indicatorName",
"]",
")",
";",
"}",
"if",
"(",
"$",
"indicator",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"indicator",
"->",
"addClasses",
"(",
"[",
"'oo-ui-indicator-'",
".",
"$",
"indicator",
"]",
")",
";",
"}",
"$",
"this",
"->",
"indicatorName",
"=",
"$",
"indicator",
";",
"$",
"this",
"->",
"toggleClasses",
"(",
"[",
"'oo-ui-indicatorElement'",
"]",
",",
"(",
"bool",
")",
"$",
"this",
"->",
"indicatorName",
")",
";",
"$",
"this",
"->",
"indicator",
"->",
"toggleClasses",
"(",
"[",
"'oo-ui-indicatorElement-noIndicator'",
"]",
",",
"!",
"$",
"this",
"->",
"indicatorName",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Set indicator name.
@param string|null $indicator Symbolic name of indicator to use or null for no indicator
@return $this | [
"Set",
"indicator",
"name",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/mixins/IndicatorElement.php#L54-L68 | train |
wikimedia/oojs-ui | php/mixins/LabelElement.php | LabelElement.setLabel | public function setLabel( $label ) {
$this->labelValue = (string)$label !== '' ? $label : null;
$this->label->clearContent();
if ( $this->labelValue !== null ) {
if ( is_string( $this->labelValue ) && trim( $this->labelValue ) === '' ) {
$this->label->appendContent( new HtmlSnippet( ' ' ) );
} else {
$this->label->appendContent( $label );
}
}
$visibleLabel = $this->labelValue !== null && !$this->invisibleLabel;
$this->toggleClasses( [ 'oo-ui-labelElement' ], $visibleLabel );
return $this;
} | php | public function setLabel( $label ) {
$this->labelValue = (string)$label !== '' ? $label : null;
$this->label->clearContent();
if ( $this->labelValue !== null ) {
if ( is_string( $this->labelValue ) && trim( $this->labelValue ) === '' ) {
$this->label->appendContent( new HtmlSnippet( ' ' ) );
} else {
$this->label->appendContent( $label );
}
}
$visibleLabel = $this->labelValue !== null && !$this->invisibleLabel;
$this->toggleClasses( [ 'oo-ui-labelElement' ], $visibleLabel );
return $this;
} | [
"public",
"function",
"setLabel",
"(",
"$",
"label",
")",
"{",
"$",
"this",
"->",
"labelValue",
"=",
"(",
"string",
")",
"$",
"label",
"!==",
"''",
"?",
"$",
"label",
":",
"null",
";",
"$",
"this",
"->",
"label",
"->",
"clearContent",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"labelValue",
"!==",
"null",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"this",
"->",
"labelValue",
")",
"&&",
"trim",
"(",
"$",
"this",
"->",
"labelValue",
")",
"===",
"''",
")",
"{",
"$",
"this",
"->",
"label",
"->",
"appendContent",
"(",
"new",
"HtmlSnippet",
"(",
"' '",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"label",
"->",
"appendContent",
"(",
"$",
"label",
")",
";",
"}",
"}",
"$",
"visibleLabel",
"=",
"$",
"this",
"->",
"labelValue",
"!==",
"null",
"&&",
"!",
"$",
"this",
"->",
"invisibleLabel",
";",
"$",
"this",
"->",
"toggleClasses",
"(",
"[",
"'oo-ui-labelElement'",
"]",
",",
"$",
"visibleLabel",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Set the label.
An empty string will result in the label being hidden. A string containing only whitespace will
be converted to a single ` `.
@param string|HtmlSnippet|null $label Label text
@return $this | [
"Set",
"the",
"label",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/mixins/LabelElement.php#L65-L81 | train |
wikimedia/oojs-ui | php/Element.php | Element.supports | public function supports( $methods ) {
$support = 0;
$methods = (array)$methods;
foreach ( $methods as $method ) {
if ( method_exists( $this, $method ) ) {
$support++;
continue;
}
}
return count( $methods ) === $support;
} | php | public function supports( $methods ) {
$support = 0;
$methods = (array)$methods;
foreach ( $methods as $method ) {
if ( method_exists( $this, $method ) ) {
$support++;
continue;
}
}
return count( $methods ) === $support;
} | [
"public",
"function",
"supports",
"(",
"$",
"methods",
")",
"{",
"$",
"support",
"=",
"0",
";",
"$",
"methods",
"=",
"(",
"array",
")",
"$",
"methods",
";",
"foreach",
"(",
"$",
"methods",
"as",
"$",
"method",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"method",
")",
")",
"{",
"$",
"support",
"++",
";",
"continue",
";",
"}",
"}",
"return",
"count",
"(",
"$",
"methods",
")",
"===",
"$",
"support",
";",
"}"
]
| Check if element supports one or more methods.
@param string|string[] $methods Method or list of methods to check
@return bool All methods are supported | [
"Check",
"if",
"element",
"supports",
"one",
"or",
"more",
"methods",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/Element.php#L141-L153 | train |
wikimedia/oojs-ui | php/Element.php | Element.getSerializedConfig | private function getSerializedConfig() {
// Ensure that '_' comes first in the output.
$config = [ '_' => true ];
$config = $this->getConfig( $config );
// Post-process config array to turn Tag references into ID references
// and HtmlSnippet references into a { html: 'string' } JSON form.
$replaceElements = function ( &$item ) {
if ( $item instanceof Tag ) {
$item->ensureInfusableId();
$item = [ 'tag' => $item->getAttribute( 'id' ) ];
} elseif ( $item instanceof HtmlSnippet ) {
$item = [ 'html' => (string)$item ];
}
};
array_walk_recursive( $config, $replaceElements );
// Set '_' last to ensure that subclasses can't accidentally step on it.
$config['_'] = $this->getJavaScriptClassName();
return $config;
} | php | private function getSerializedConfig() {
// Ensure that '_' comes first in the output.
$config = [ '_' => true ];
$config = $this->getConfig( $config );
// Post-process config array to turn Tag references into ID references
// and HtmlSnippet references into a { html: 'string' } JSON form.
$replaceElements = function ( &$item ) {
if ( $item instanceof Tag ) {
$item->ensureInfusableId();
$item = [ 'tag' => $item->getAttribute( 'id' ) ];
} elseif ( $item instanceof HtmlSnippet ) {
$item = [ 'html' => (string)$item ];
}
};
array_walk_recursive( $config, $replaceElements );
// Set '_' last to ensure that subclasses can't accidentally step on it.
$config['_'] = $this->getJavaScriptClassName();
return $config;
} | [
"private",
"function",
"getSerializedConfig",
"(",
")",
"{",
"// Ensure that '_' comes first in the output.",
"$",
"config",
"=",
"[",
"'_'",
"=>",
"true",
"]",
";",
"$",
"config",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"$",
"config",
")",
";",
"// Post-process config array to turn Tag references into ID references",
"// and HtmlSnippet references into a { html: 'string' } JSON form.",
"$",
"replaceElements",
"=",
"function",
"(",
"&",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"instanceof",
"Tag",
")",
"{",
"$",
"item",
"->",
"ensureInfusableId",
"(",
")",
";",
"$",
"item",
"=",
"[",
"'tag'",
"=>",
"$",
"item",
"->",
"getAttribute",
"(",
"'id'",
")",
"]",
";",
"}",
"elseif",
"(",
"$",
"item",
"instanceof",
"HtmlSnippet",
")",
"{",
"$",
"item",
"=",
"[",
"'html'",
"=>",
"(",
"string",
")",
"$",
"item",
"]",
";",
"}",
"}",
";",
"array_walk_recursive",
"(",
"$",
"config",
",",
"$",
"replaceElements",
")",
";",
"// Set '_' last to ensure that subclasses can't accidentally step on it.",
"$",
"config",
"[",
"'_'",
"]",
"=",
"$",
"this",
"->",
"getJavaScriptClassName",
"(",
")",
";",
"return",
"$",
"config",
";",
"}"
]
| Create a modified version of the configuration array suitable for
JSON serialization by replacing `Tag` references and
`HtmlSnippet`s.
@return array A serialized configuration array. | [
"Create",
"a",
"modified",
"version",
"of",
"the",
"configuration",
"array",
"suitable",
"for",
"JSON",
"serialization",
"by",
"replacing",
"Tag",
"references",
"and",
"HtmlSnippet",
"s",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/Element.php#L197-L215 | train |
wikimedia/oojs-ui | php/Element.php | Element.configFromHtmlAttributes | public static function configFromHtmlAttributes( array $attrs ) {
$booleanAttrs = [
'disabled' => true,
'required' => true,
'autofocus' => true,
'multiple' => true,
'readonly' => true,
];
$attributeToConfig = [
'maxlength' => 'maxLength',
'readonly' => 'readOnly',
'tabindex' => 'tabIndex',
'accesskey' => 'accessKey',
];
$config = [];
foreach ( $attrs as $key => $value ) {
if ( isset( $booleanAttrs[$key] ) && $value !== false && $value !== null ) {
$value = true;
}
if ( isset( $attributeToConfig[$key] ) ) {
$key = $attributeToConfig[$key];
}
$config[$key] = $value;
}
return $config;
} | php | public static function configFromHtmlAttributes( array $attrs ) {
$booleanAttrs = [
'disabled' => true,
'required' => true,
'autofocus' => true,
'multiple' => true,
'readonly' => true,
];
$attributeToConfig = [
'maxlength' => 'maxLength',
'readonly' => 'readOnly',
'tabindex' => 'tabIndex',
'accesskey' => 'accessKey',
];
$config = [];
foreach ( $attrs as $key => $value ) {
if ( isset( $booleanAttrs[$key] ) && $value !== false && $value !== null ) {
$value = true;
}
if ( isset( $attributeToConfig[$key] ) ) {
$key = $attributeToConfig[$key];
}
$config[$key] = $value;
}
return $config;
} | [
"public",
"static",
"function",
"configFromHtmlAttributes",
"(",
"array",
"$",
"attrs",
")",
"{",
"$",
"booleanAttrs",
"=",
"[",
"'disabled'",
"=>",
"true",
",",
"'required'",
"=>",
"true",
",",
"'autofocus'",
"=>",
"true",
",",
"'multiple'",
"=>",
"true",
",",
"'readonly'",
"=>",
"true",
",",
"]",
";",
"$",
"attributeToConfig",
"=",
"[",
"'maxlength'",
"=>",
"'maxLength'",
",",
"'readonly'",
"=>",
"'readOnly'",
",",
"'tabindex'",
"=>",
"'tabIndex'",
",",
"'accesskey'",
"=>",
"'accessKey'",
",",
"]",
";",
"$",
"config",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"attrs",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"booleanAttrs",
"[",
"$",
"key",
"]",
")",
"&&",
"$",
"value",
"!==",
"false",
"&&",
"$",
"value",
"!==",
"null",
")",
"{",
"$",
"value",
"=",
"true",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"attributeToConfig",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"key",
"=",
"$",
"attributeToConfig",
"[",
"$",
"key",
"]",
";",
"}",
"$",
"config",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"config",
";",
"}"
]
| A helper method to massage an array of HTML attributes into a format that is more likely to
work with an OOUI PHP element, camel-casing attribute names and setting values of boolean
ones to true. Intended as a convenience to be used when refactoring legacy systems using HTML
to use OOUI.
@param array $attrs HTML attributes, e.g. `[ 'disabled' => '', 'accesskey' => 'k' ]`
@return array OOUI PHP element config, e.g. `[ 'disabled' => true, 'accessKey' => 'k' ]` | [
"A",
"helper",
"method",
"to",
"massage",
"an",
"array",
"of",
"HTML",
"attributes",
"into",
"a",
"format",
"that",
"is",
"more",
"likely",
"to",
"work",
"with",
"an",
"OOUI",
"PHP",
"element",
"camel",
"-",
"casing",
"attribute",
"names",
"and",
"setting",
"values",
"of",
"boolean",
"ones",
"to",
"true",
".",
"Intended",
"as",
"a",
"convenience",
"to",
"be",
"used",
"when",
"refactoring",
"legacy",
"systems",
"using",
"HTML",
"to",
"use",
"OOUI",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/Element.php#L278-L303 | train |
wikimedia/oojs-ui | php/layouts/FieldLayout.php | FieldLayout.setAlignment | protected function setAlignment( $value ) {
if ( $value !== $this->align ) {
// Default to 'left'
if ( !in_array( $value, [ 'left', 'right', 'top', 'inline' ] ) ) {
$value = 'left';
}
// Validate
if ( $value === 'inline' && !$this->isFieldInline() ) {
$value = 'top';
}
// Reorder elements
$this->body->clearContent();
if ( $this->helpInline ) {
if ( $value === 'top' ) {
$this->header->appendContent( $this->label );
$this->body->appendContent( $this->header, $this->field, $this->help );
} elseif ( $value === 'inline' ) {
$this->header->appendContent( $this->label, $this->help );
$this->body->appendContent( $this->field, $this->header );
} else {
$this->header->appendContent( $this->label, $this->help );
$this->body->appendContent( $this->header, $this->field );
}
} else {
if ( $value === 'top' ) {
$this->header->appendContent( $this->help, $this->label );
$this->body->appendContent( $this->header, $this->field );
} elseif ( $value === 'inline' ) {
$this->header->appendContent( $this->help, $this->label );
$this->body->appendContent( $this->field, $this->header );
} else {
$this->header->appendContent( $this->label );
$this->body->appendContent( $this->header, $this->help, $this->field );
}
}
// Set classes. The following classes can be used here:
// * oo-ui-fieldLayout-align-left
// * oo-ui-fieldLayout-align-right
// * oo-ui-fieldLayout-align-top
// * oo-ui-fieldLayout-align-inline
if ( $this->align ) {
$this->removeClasses( [ 'oo-ui-fieldLayout-align-' . $this->align ] );
}
$this->addClasses( [ 'oo-ui-fieldLayout-align-' . $value ] );
$this->align = $value;
}
return $this;
} | php | protected function setAlignment( $value ) {
if ( $value !== $this->align ) {
// Default to 'left'
if ( !in_array( $value, [ 'left', 'right', 'top', 'inline' ] ) ) {
$value = 'left';
}
// Validate
if ( $value === 'inline' && !$this->isFieldInline() ) {
$value = 'top';
}
// Reorder elements
$this->body->clearContent();
if ( $this->helpInline ) {
if ( $value === 'top' ) {
$this->header->appendContent( $this->label );
$this->body->appendContent( $this->header, $this->field, $this->help );
} elseif ( $value === 'inline' ) {
$this->header->appendContent( $this->label, $this->help );
$this->body->appendContent( $this->field, $this->header );
} else {
$this->header->appendContent( $this->label, $this->help );
$this->body->appendContent( $this->header, $this->field );
}
} else {
if ( $value === 'top' ) {
$this->header->appendContent( $this->help, $this->label );
$this->body->appendContent( $this->header, $this->field );
} elseif ( $value === 'inline' ) {
$this->header->appendContent( $this->help, $this->label );
$this->body->appendContent( $this->field, $this->header );
} else {
$this->header->appendContent( $this->label );
$this->body->appendContent( $this->header, $this->help, $this->field );
}
}
// Set classes. The following classes can be used here:
// * oo-ui-fieldLayout-align-left
// * oo-ui-fieldLayout-align-right
// * oo-ui-fieldLayout-align-top
// * oo-ui-fieldLayout-align-inline
if ( $this->align ) {
$this->removeClasses( [ 'oo-ui-fieldLayout-align-' . $this->align ] );
}
$this->addClasses( [ 'oo-ui-fieldLayout-align-' . $value ] );
$this->align = $value;
}
return $this;
} | [
"protected",
"function",
"setAlignment",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"!==",
"$",
"this",
"->",
"align",
")",
"{",
"// Default to 'left'",
"if",
"(",
"!",
"in_array",
"(",
"$",
"value",
",",
"[",
"'left'",
",",
"'right'",
",",
"'top'",
",",
"'inline'",
"]",
")",
")",
"{",
"$",
"value",
"=",
"'left'",
";",
"}",
"// Validate",
"if",
"(",
"$",
"value",
"===",
"'inline'",
"&&",
"!",
"$",
"this",
"->",
"isFieldInline",
"(",
")",
")",
"{",
"$",
"value",
"=",
"'top'",
";",
"}",
"// Reorder elements",
"$",
"this",
"->",
"body",
"->",
"clearContent",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"helpInline",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"'top'",
")",
"{",
"$",
"this",
"->",
"header",
"->",
"appendContent",
"(",
"$",
"this",
"->",
"label",
")",
";",
"$",
"this",
"->",
"body",
"->",
"appendContent",
"(",
"$",
"this",
"->",
"header",
",",
"$",
"this",
"->",
"field",
",",
"$",
"this",
"->",
"help",
")",
";",
"}",
"elseif",
"(",
"$",
"value",
"===",
"'inline'",
")",
"{",
"$",
"this",
"->",
"header",
"->",
"appendContent",
"(",
"$",
"this",
"->",
"label",
",",
"$",
"this",
"->",
"help",
")",
";",
"$",
"this",
"->",
"body",
"->",
"appendContent",
"(",
"$",
"this",
"->",
"field",
",",
"$",
"this",
"->",
"header",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"header",
"->",
"appendContent",
"(",
"$",
"this",
"->",
"label",
",",
"$",
"this",
"->",
"help",
")",
";",
"$",
"this",
"->",
"body",
"->",
"appendContent",
"(",
"$",
"this",
"->",
"header",
",",
"$",
"this",
"->",
"field",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"value",
"===",
"'top'",
")",
"{",
"$",
"this",
"->",
"header",
"->",
"appendContent",
"(",
"$",
"this",
"->",
"help",
",",
"$",
"this",
"->",
"label",
")",
";",
"$",
"this",
"->",
"body",
"->",
"appendContent",
"(",
"$",
"this",
"->",
"header",
",",
"$",
"this",
"->",
"field",
")",
";",
"}",
"elseif",
"(",
"$",
"value",
"===",
"'inline'",
")",
"{",
"$",
"this",
"->",
"header",
"->",
"appendContent",
"(",
"$",
"this",
"->",
"help",
",",
"$",
"this",
"->",
"label",
")",
";",
"$",
"this",
"->",
"body",
"->",
"appendContent",
"(",
"$",
"this",
"->",
"field",
",",
"$",
"this",
"->",
"header",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"header",
"->",
"appendContent",
"(",
"$",
"this",
"->",
"label",
")",
";",
"$",
"this",
"->",
"body",
"->",
"appendContent",
"(",
"$",
"this",
"->",
"header",
",",
"$",
"this",
"->",
"help",
",",
"$",
"this",
"->",
"field",
")",
";",
"}",
"}",
"// Set classes. The following classes can be used here:",
"// * oo-ui-fieldLayout-align-left",
"// * oo-ui-fieldLayout-align-right",
"// * oo-ui-fieldLayout-align-top",
"// * oo-ui-fieldLayout-align-inline",
"if",
"(",
"$",
"this",
"->",
"align",
")",
"{",
"$",
"this",
"->",
"removeClasses",
"(",
"[",
"'oo-ui-fieldLayout-align-'",
".",
"$",
"this",
"->",
"align",
"]",
")",
";",
"}",
"$",
"this",
"->",
"addClasses",
"(",
"[",
"'oo-ui-fieldLayout-align-'",
".",
"$",
"value",
"]",
")",
";",
"$",
"this",
"->",
"align",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Set the field alignment mode.
@param string $value Alignment mode, either 'left', 'right', 'top' or 'inline'
@return $this | [
"Set",
"the",
"field",
"alignment",
"mode",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/layouts/FieldLayout.php#L223-L272 | train |
wikimedia/oojs-ui | php/layouts/FieldLayout.php | FieldLayout.createHelpElement | private function createHelpElement() {
if ( $this->helpInline ) {
return new LabelWidget( [
'classes' => [ 'oo-ui-inline-help' ],
'label' => $this->helpText,
] );
} else {
return new ButtonWidget( [
'classes' => [ 'oo-ui-fieldLayout-help' ],
'framed' => false,
'icon' => 'info',
'title' => $this->helpText,
// TODO We have no way to use localisation messages in PHP
// (and to use different languages when used from MediaWiki)
// 'label' => msg( 'ooui-field-help' ),
// 'invisibleLabel' => true,
] );
}
} | php | private function createHelpElement() {
if ( $this->helpInline ) {
return new LabelWidget( [
'classes' => [ 'oo-ui-inline-help' ],
'label' => $this->helpText,
] );
} else {
return new ButtonWidget( [
'classes' => [ 'oo-ui-fieldLayout-help' ],
'framed' => false,
'icon' => 'info',
'title' => $this->helpText,
// TODO We have no way to use localisation messages in PHP
// (and to use different languages when used from MediaWiki)
// 'label' => msg( 'ooui-field-help' ),
// 'invisibleLabel' => true,
] );
}
} | [
"private",
"function",
"createHelpElement",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"helpInline",
")",
"{",
"return",
"new",
"LabelWidget",
"(",
"[",
"'classes'",
"=>",
"[",
"'oo-ui-inline-help'",
"]",
",",
"'label'",
"=>",
"$",
"this",
"->",
"helpText",
",",
"]",
")",
";",
"}",
"else",
"{",
"return",
"new",
"ButtonWidget",
"(",
"[",
"'classes'",
"=>",
"[",
"'oo-ui-fieldLayout-help'",
"]",
",",
"'framed'",
"=>",
"false",
",",
"'icon'",
"=>",
"'info'",
",",
"'title'",
"=>",
"$",
"this",
"->",
"helpText",
",",
"// TODO We have no way to use localisation messages in PHP",
"// (and to use different languages when used from MediaWiki)",
"// 'label' => msg( 'ooui-field-help' ),",
"// 'invisibleLabel' => true,",
"]",
")",
";",
"}",
"}"
]
| Creates and returns the help element.
@return Widget The element that should become `$this->help`. | [
"Creates",
"and",
"returns",
"the",
"help",
"element",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/layouts/FieldLayout.php#L306-L324 | train |
wikimedia/oojs-ui | php/widgets/RadioInputWidget.php | RadioInputWidget.setSelected | public function setSelected( $state ) {
// RadioInputWidget doesn't track its state.
if ( $state ) {
$this->input->setAttributes( [ 'checked' => 'checked' ] );
} else {
$this->input->removeAttributes( [ 'checked' ] );
}
return $this;
} | php | public function setSelected( $state ) {
// RadioInputWidget doesn't track its state.
if ( $state ) {
$this->input->setAttributes( [ 'checked' => 'checked' ] );
} else {
$this->input->removeAttributes( [ 'checked' ] );
}
return $this;
} | [
"public",
"function",
"setSelected",
"(",
"$",
"state",
")",
"{",
"// RadioInputWidget doesn't track its state.",
"if",
"(",
"$",
"state",
")",
"{",
"$",
"this",
"->",
"input",
"->",
"setAttributes",
"(",
"[",
"'checked'",
"=>",
"'checked'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"input",
"->",
"removeAttributes",
"(",
"[",
"'checked'",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Set selection state of this radio button.
@param bool $state Whether the button is selected
@return $this | [
"Set",
"selection",
"state",
"of",
"this",
"radio",
"button",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/widgets/RadioInputWidget.php#L41-L49 | train |
wikimedia/oojs-ui | php/mixins/ButtonElement.php | ButtonElement.toggleFramed | public function toggleFramed( $framed = null ) {
$this->framed = $framed !== null ? (bool)$framed : !$this->framed;
$this->toggleClasses( [ 'oo-ui-buttonElement-framed' ], $this->framed );
$this->toggleClasses( [ 'oo-ui-buttonElement-frameless' ], !$this->framed );
return $this;
} | php | public function toggleFramed( $framed = null ) {
$this->framed = $framed !== null ? (bool)$framed : !$this->framed;
$this->toggleClasses( [ 'oo-ui-buttonElement-framed' ], $this->framed );
$this->toggleClasses( [ 'oo-ui-buttonElement-frameless' ], !$this->framed );
return $this;
} | [
"public",
"function",
"toggleFramed",
"(",
"$",
"framed",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"framed",
"=",
"$",
"framed",
"!==",
"null",
"?",
"(",
"bool",
")",
"$",
"framed",
":",
"!",
"$",
"this",
"->",
"framed",
";",
"$",
"this",
"->",
"toggleClasses",
"(",
"[",
"'oo-ui-buttonElement-framed'",
"]",
",",
"$",
"this",
"->",
"framed",
")",
";",
"$",
"this",
"->",
"toggleClasses",
"(",
"[",
"'oo-ui-buttonElement-frameless'",
"]",
",",
"!",
"$",
"this",
"->",
"framed",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Toggle frame.
@param bool|null $framed Make button framed, omit to toggle
@return $this | [
"Toggle",
"frame",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/mixins/ButtonElement.php#L64-L69 | train |
wikimedia/oojs-ui | php/mixins/AccessKeyedElement.php | AccessKeyedElement.setAccessKey | public function setAccessKey( $accessKey ) {
$accessKey = is_string( $accessKey ) && strlen( $accessKey ) ? $accessKey : null;
if ( $this->accessKey !== $accessKey ) {
if ( $accessKey !== null ) {
$this->accessKeyed->setAttributes( [ 'accesskey' => $accessKey ] );
} else {
$this->accessKeyed->removeAttributes( [ 'accesskey' ] );
}
$this->accessKey = $accessKey;
// Only if this is a TitledElement
if ( method_exists( $this, 'updateTitle' ) ) {
$this->updateTitle();
}
}
return $this;
} | php | public function setAccessKey( $accessKey ) {
$accessKey = is_string( $accessKey ) && strlen( $accessKey ) ? $accessKey : null;
if ( $this->accessKey !== $accessKey ) {
if ( $accessKey !== null ) {
$this->accessKeyed->setAttributes( [ 'accesskey' => $accessKey ] );
} else {
$this->accessKeyed->removeAttributes( [ 'accesskey' ] );
}
$this->accessKey = $accessKey;
// Only if this is a TitledElement
if ( method_exists( $this, 'updateTitle' ) ) {
$this->updateTitle();
}
}
return $this;
} | [
"public",
"function",
"setAccessKey",
"(",
"$",
"accessKey",
")",
"{",
"$",
"accessKey",
"=",
"is_string",
"(",
"$",
"accessKey",
")",
"&&",
"strlen",
"(",
"$",
"accessKey",
")",
"?",
"$",
"accessKey",
":",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"accessKey",
"!==",
"$",
"accessKey",
")",
"{",
"if",
"(",
"$",
"accessKey",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"accessKeyed",
"->",
"setAttributes",
"(",
"[",
"'accesskey'",
"=>",
"$",
"accessKey",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"accessKeyed",
"->",
"removeAttributes",
"(",
"[",
"'accesskey'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"accessKey",
"=",
"$",
"accessKey",
";",
"// Only if this is a TitledElement",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"'updateTitle'",
")",
")",
"{",
"$",
"this",
"->",
"updateTitle",
"(",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
]
| Set access key.
@param string $accessKey Tag's access key, use empty string to remove
@return $this | [
"Set",
"access",
"key",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/mixins/AccessKeyedElement.php#L51-L69 | train |
wikimedia/oojs-ui | php/Tag.php | Tag.addClasses | public function addClasses( array $classes ) {
$this->classes = array_unique( array_merge( $this->classes, $classes ) );
return $this;
} | php | public function addClasses( array $classes ) {
$this->classes = array_unique( array_merge( $this->classes, $classes ) );
return $this;
} | [
"public",
"function",
"addClasses",
"(",
"array",
"$",
"classes",
")",
"{",
"$",
"this",
"->",
"classes",
"=",
"array_unique",
"(",
"array_merge",
"(",
"$",
"this",
"->",
"classes",
",",
"$",
"classes",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Add CSS classes.
@param array $classes List of classes to add
@return $this | [
"Add",
"CSS",
"classes",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/Tag.php#L78-L81 | train |
wikimedia/oojs-ui | php/Tag.php | Tag.toggleClasses | public function toggleClasses( array $classes, $toggle = null ) {
if ( $toggle === null ) {
$this->classes = array_diff(
array_merge( $this->classes, $classes ),
array_intersect( $this->classes, $classes )
);
} elseif ( $toggle ) {
$this->classes = array_merge( $this->classes, $classes );
} else {
$this->classes = array_diff( $this->classes, $classes );
}
return $this;
} | php | public function toggleClasses( array $classes, $toggle = null ) {
if ( $toggle === null ) {
$this->classes = array_diff(
array_merge( $this->classes, $classes ),
array_intersect( $this->classes, $classes )
);
} elseif ( $toggle ) {
$this->classes = array_merge( $this->classes, $classes );
} else {
$this->classes = array_diff( $this->classes, $classes );
}
return $this;
} | [
"public",
"function",
"toggleClasses",
"(",
"array",
"$",
"classes",
",",
"$",
"toggle",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"toggle",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"classes",
"=",
"array_diff",
"(",
"array_merge",
"(",
"$",
"this",
"->",
"classes",
",",
"$",
"classes",
")",
",",
"array_intersect",
"(",
"$",
"this",
"->",
"classes",
",",
"$",
"classes",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"toggle",
")",
"{",
"$",
"this",
"->",
"classes",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"classes",
",",
"$",
"classes",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"classes",
"=",
"array_diff",
"(",
"$",
"this",
"->",
"classes",
",",
"$",
"classes",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Toggle CSS classes.
@param array $classes List of classes to add
@param bool|null $toggle Add classes
@return $this | [
"Toggle",
"CSS",
"classes",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/Tag.php#L101-L113 | train |
wikimedia/oojs-ui | php/Tag.php | Tag.removeContent | public function removeContent( ...$content ) {
if ( is_array( $content[ 0 ] ) ) {
$content = $content[ 0 ];
}
foreach ( $content as $item ) {
if ( !is_string( $item ) ) {
// Use strict type comparions so we don't
// compare objects with existing strings
$index = array_search( $item, $this->content, true );
if ( $index !== false ) {
array_splice( $this->content, $index, 1 );
}
}
}
return $this;
} | php | public function removeContent( ...$content ) {
if ( is_array( $content[ 0 ] ) ) {
$content = $content[ 0 ];
}
foreach ( $content as $item ) {
if ( !is_string( $item ) ) {
// Use strict type comparions so we don't
// compare objects with existing strings
$index = array_search( $item, $this->content, true );
if ( $index !== false ) {
array_splice( $this->content, $index, 1 );
}
}
}
return $this;
} | [
"public",
"function",
"removeContent",
"(",
"...",
"$",
"content",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"content",
"[",
"0",
"]",
")",
")",
"{",
"$",
"content",
"=",
"$",
"content",
"[",
"0",
"]",
";",
"}",
"foreach",
"(",
"$",
"content",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"item",
")",
")",
"{",
"// Use strict type comparions so we don't",
"// compare objects with existing strings",
"$",
"index",
"=",
"array_search",
"(",
"$",
"item",
",",
"$",
"this",
"->",
"content",
",",
"true",
")",
";",
"if",
"(",
"$",
"index",
"!==",
"false",
")",
"{",
"array_splice",
"(",
"$",
"this",
"->",
"content",
",",
"$",
"index",
",",
"1",
")",
";",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
]
| Remove any items that match by reference
String items should never match by reference
so will not be removed.
@param string|Tag|HtmlSnippet ...$content Content to reomve.
@return $this | [
"Remove",
"any",
"items",
"that",
"match",
"by",
"reference"
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/Tag.php#L180-L195 | train |
wikimedia/oojs-ui | php/Tag.php | Tag.appendContent | public function appendContent( ...$content ) {
if ( is_array( $content[ 0 ] ) ) {
$content = $content[ 0 ];
}
$this->removeContent( $content );
$this->content = array_merge( $this->content, $content );
return $this;
} | php | public function appendContent( ...$content ) {
if ( is_array( $content[ 0 ] ) ) {
$content = $content[ 0 ];
}
$this->removeContent( $content );
$this->content = array_merge( $this->content, $content );
return $this;
} | [
"public",
"function",
"appendContent",
"(",
"...",
"$",
"content",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"content",
"[",
"0",
"]",
")",
")",
"{",
"$",
"content",
"=",
"$",
"content",
"[",
"0",
"]",
";",
"}",
"$",
"this",
"->",
"removeContent",
"(",
"$",
"content",
")",
";",
"$",
"this",
"->",
"content",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"content",
",",
"$",
"content",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Add content to the end.
Accepts either variadic arguments (the $content argument can be repeated any number of times)
or an array of arguments.
For example, these uses are valid:
* $tag->appendContent( [ $element1, $element2 ] );
* $tag->appendContent( $element1, $element2 );
This, however, is not acceptable
* $tag->appendContent( [ $element1, $element2 ], $element3 );
Objects that are already in $this->content will be moved
to the end of the list, not duplicated.
@param string|Tag|HtmlSnippet ...$content Content to append. Strings will be HTML-escaped
for output, use a HtmlSnippet instance to prevent that.
@return $this | [
"Add",
"content",
"to",
"the",
"end",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/Tag.php#L216-L223 | train |
wikimedia/oojs-ui | php/Tag.php | Tag.prependContent | public function prependContent( ...$content ) {
if ( is_array( $content[ 0 ] ) ) {
$content = $content[ 0 ];
}
$this->removeContent( $content );
array_splice( $this->content, 0, 0, $content );
return $this;
} | php | public function prependContent( ...$content ) {
if ( is_array( $content[ 0 ] ) ) {
$content = $content[ 0 ];
}
$this->removeContent( $content );
array_splice( $this->content, 0, 0, $content );
return $this;
} | [
"public",
"function",
"prependContent",
"(",
"...",
"$",
"content",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"content",
"[",
"0",
"]",
")",
")",
"{",
"$",
"content",
"=",
"$",
"content",
"[",
"0",
"]",
";",
"}",
"$",
"this",
"->",
"removeContent",
"(",
"$",
"content",
")",
";",
"array_splice",
"(",
"$",
"this",
"->",
"content",
",",
"0",
",",
"0",
",",
"$",
"content",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Add content to the beginning.
Accepts either variadic arguments (the $content argument can be repeated any number of times)
or an array of arguments.
Objects that are already in $this->content will be moved
to the end of the list, not duplicated.
For example, these uses are valid:
* $tag->prependContent( [ $element1, $element2 ] );
* $tag->prependContent( $element1, $element2 );
This, however, is not acceptable
* $tag->prependContent( [ $element1, $element2 ], $element3 );
@param string|Tag|HtmlSnippet ...$content Content to prepend. Strings will be HTML-escaped
for output, use a HtmlSnippet instance to prevent that.
@return $this | [
"Add",
"content",
"to",
"the",
"beginning",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/Tag.php#L244-L251 | train |
wikimedia/oojs-ui | php/Tag.php | Tag.ensureInfusableId | public function ensureInfusableId() {
$this->setInfusable( true );
if ( $this->getAttribute( 'id' ) === null ) {
$this->setAttributes( [ 'id' => self::generateElementId() ] );
}
return $this;
} | php | public function ensureInfusableId() {
$this->setInfusable( true );
if ( $this->getAttribute( 'id' ) === null ) {
$this->setAttributes( [ 'id' => self::generateElementId() ] );
}
return $this;
} | [
"public",
"function",
"ensureInfusableId",
"(",
")",
"{",
"$",
"this",
"->",
"setInfusable",
"(",
"true",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getAttribute",
"(",
"'id'",
")",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"setAttributes",
"(",
"[",
"'id'",
"=>",
"self",
"::",
"generateElementId",
"(",
")",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Ensure that this given Tag is infusable and has a unique `id`
attribute.
@return $this | [
"Ensure",
"that",
"this",
"given",
"Tag",
"is",
"infusable",
"and",
"has",
"a",
"unique",
"id",
"attribute",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/Tag.php#L320-L326 | train |
wikimedia/oojs-ui | php/mixins/FlaggedElement.php | FlaggedElement.clearFlags | public function clearFlags() {
$remove = [];
$classPrefix = 'oo-ui-flaggedElement-';
foreach ( $this->flags as $flag ) {
$remove[] = $classPrefix . $flag;
}
$this->flagged->removeClasses( $remove );
$this->flags = [];
return $this;
} | php | public function clearFlags() {
$remove = [];
$classPrefix = 'oo-ui-flaggedElement-';
foreach ( $this->flags as $flag ) {
$remove[] = $classPrefix . $flag;
}
$this->flagged->removeClasses( $remove );
$this->flags = [];
return $this;
} | [
"public",
"function",
"clearFlags",
"(",
")",
"{",
"$",
"remove",
"=",
"[",
"]",
";",
"$",
"classPrefix",
"=",
"'oo-ui-flaggedElement-'",
";",
"foreach",
"(",
"$",
"this",
"->",
"flags",
"as",
"$",
"flag",
")",
"{",
"$",
"remove",
"[",
"]",
"=",
"$",
"classPrefix",
".",
"$",
"flag",
";",
"}",
"$",
"this",
"->",
"flagged",
"->",
"removeClasses",
"(",
"$",
"remove",
")",
";",
"$",
"this",
"->",
"flags",
"=",
"[",
"]",
";",
"return",
"$",
"this",
";",
"}"
]
| Clear all flags.
@return $this | [
"Clear",
"all",
"flags",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/mixins/FlaggedElement.php#L69-L81 | train |
wikimedia/oojs-ui | php/mixins/FlaggedElement.php | FlaggedElement.setFlags | public function setFlags( $flags ) {
$add = [];
$remove = [];
$classPrefix = 'oo-ui-flaggedElement-';
if ( is_string( $flags ) ) {
// Set
if ( !isset( $this->flags[$flags] ) ) {
$this->flags[$flags] = true;
$add[] = $classPrefix . $flags;
}
} elseif ( is_array( $flags ) ) {
foreach ( $flags as $key => $value ) {
if ( is_numeric( $key ) ) {
// Set
if ( !isset( $this->flags[$value] ) ) {
$this->flags[$value] = true;
$add[] = $classPrefix . $value;
}
} else {
if ( $value ) {
// Set
if ( !isset( $this->flags[$key] ) ) {
$this->flags[$key] = true;
$add[] = $classPrefix . $key;
}
} else {
// Remove
if ( isset( $this->flags[$key] ) ) {
unset( $this->flags[$key] );
$remove[] = $classPrefix . $key;
}
}
}
}
}
$this->flagged
->addClasses( $add )
->removeClasses( $remove );
return $this;
} | php | public function setFlags( $flags ) {
$add = [];
$remove = [];
$classPrefix = 'oo-ui-flaggedElement-';
if ( is_string( $flags ) ) {
// Set
if ( !isset( $this->flags[$flags] ) ) {
$this->flags[$flags] = true;
$add[] = $classPrefix . $flags;
}
} elseif ( is_array( $flags ) ) {
foreach ( $flags as $key => $value ) {
if ( is_numeric( $key ) ) {
// Set
if ( !isset( $this->flags[$value] ) ) {
$this->flags[$value] = true;
$add[] = $classPrefix . $value;
}
} else {
if ( $value ) {
// Set
if ( !isset( $this->flags[$key] ) ) {
$this->flags[$key] = true;
$add[] = $classPrefix . $key;
}
} else {
// Remove
if ( isset( $this->flags[$key] ) ) {
unset( $this->flags[$key] );
$remove[] = $classPrefix . $key;
}
}
}
}
}
$this->flagged
->addClasses( $add )
->removeClasses( $remove );
return $this;
} | [
"public",
"function",
"setFlags",
"(",
"$",
"flags",
")",
"{",
"$",
"add",
"=",
"[",
"]",
";",
"$",
"remove",
"=",
"[",
"]",
";",
"$",
"classPrefix",
"=",
"'oo-ui-flaggedElement-'",
";",
"if",
"(",
"is_string",
"(",
"$",
"flags",
")",
")",
"{",
"// Set",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"flags",
"[",
"$",
"flags",
"]",
")",
")",
"{",
"$",
"this",
"->",
"flags",
"[",
"$",
"flags",
"]",
"=",
"true",
";",
"$",
"add",
"[",
"]",
"=",
"$",
"classPrefix",
".",
"$",
"flags",
";",
"}",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"flags",
")",
")",
"{",
"foreach",
"(",
"$",
"flags",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"key",
")",
")",
"{",
"// Set",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"flags",
"[",
"$",
"value",
"]",
")",
")",
"{",
"$",
"this",
"->",
"flags",
"[",
"$",
"value",
"]",
"=",
"true",
";",
"$",
"add",
"[",
"]",
"=",
"$",
"classPrefix",
".",
"$",
"value",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"value",
")",
"{",
"// Set",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"flags",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"this",
"->",
"flags",
"[",
"$",
"key",
"]",
"=",
"true",
";",
"$",
"add",
"[",
"]",
"=",
"$",
"classPrefix",
".",
"$",
"key",
";",
"}",
"}",
"else",
"{",
"// Remove",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"flags",
"[",
"$",
"key",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"flags",
"[",
"$",
"key",
"]",
")",
";",
"$",
"remove",
"[",
"]",
"=",
"$",
"classPrefix",
".",
"$",
"key",
";",
"}",
"}",
"}",
"}",
"}",
"$",
"this",
"->",
"flagged",
"->",
"addClasses",
"(",
"$",
"add",
")",
"->",
"removeClasses",
"(",
"$",
"remove",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Add one or more flags.
@param string|array $flags One or more flags to add, or an array keyed by flag name
containing boolean set/remove instructions.
@return $this | [
"Add",
"one",
"or",
"more",
"flags",
"."
]
| 5218121946d9be8dbcc6b10116711517666ec7f3 | https://github.com/wikimedia/oojs-ui/blob/5218121946d9be8dbcc6b10116711517666ec7f3/php/mixins/FlaggedElement.php#L90-L132 | train |
armetiz/LeezyPheanstalkBundle | src/DataCollector/PheanstalkDataCollector.php | PheanstalkDataCollector.fetchJobs | private function fetchJobs(PheanstalkInterface $pheanstalk, $tubeName)
{
try {
$nextJobReady = $pheanstalk->peekReady($tubeName);
$this->data['jobs'][$tubeName]['ready'] = [
'id' => $nextJobReady->getId(),
'data' => $nextJobReady->getData(),
];
} catch (ServerException $e) {
}
try {
$nextJobBuried = $pheanstalk->peekBuried($tubeName);
$this->data['jobs'][$tubeName]['buried'] = [
'id' => $nextJobBuried->getId(),
'data' => $nextJobBuried->getData(),
];
} catch (ServerException $e) {
}
} | php | private function fetchJobs(PheanstalkInterface $pheanstalk, $tubeName)
{
try {
$nextJobReady = $pheanstalk->peekReady($tubeName);
$this->data['jobs'][$tubeName]['ready'] = [
'id' => $nextJobReady->getId(),
'data' => $nextJobReady->getData(),
];
} catch (ServerException $e) {
}
try {
$nextJobBuried = $pheanstalk->peekBuried($tubeName);
$this->data['jobs'][$tubeName]['buried'] = [
'id' => $nextJobBuried->getId(),
'data' => $nextJobBuried->getData(),
];
} catch (ServerException $e) {
}
} | [
"private",
"function",
"fetchJobs",
"(",
"PheanstalkInterface",
"$",
"pheanstalk",
",",
"$",
"tubeName",
")",
"{",
"try",
"{",
"$",
"nextJobReady",
"=",
"$",
"pheanstalk",
"->",
"peekReady",
"(",
"$",
"tubeName",
")",
";",
"$",
"this",
"->",
"data",
"[",
"'jobs'",
"]",
"[",
"$",
"tubeName",
"]",
"[",
"'ready'",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"nextJobReady",
"->",
"getId",
"(",
")",
",",
"'data'",
"=>",
"$",
"nextJobReady",
"->",
"getData",
"(",
")",
",",
"]",
";",
"}",
"catch",
"(",
"ServerException",
"$",
"e",
")",
"{",
"}",
"try",
"{",
"$",
"nextJobBuried",
"=",
"$",
"pheanstalk",
"->",
"peekBuried",
"(",
"$",
"tubeName",
")",
";",
"$",
"this",
"->",
"data",
"[",
"'jobs'",
"]",
"[",
"$",
"tubeName",
"]",
"[",
"'buried'",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"nextJobBuried",
"->",
"getId",
"(",
")",
",",
"'data'",
"=>",
"$",
"nextJobBuried",
"->",
"getData",
"(",
")",
",",
"]",
";",
"}",
"catch",
"(",
"ServerException",
"$",
"e",
")",
"{",
"}",
"}"
]
| Get the next job ready and buried in the specified tube and connection.
@param PheanstalkInterface $pheanstalk
@param string $tubeName | [
"Get",
"the",
"next",
"job",
"ready",
"and",
"buried",
"in",
"the",
"specified",
"tube",
"and",
"connection",
"."
]
| e27e1507e7224faba0b439a09808839a366a8569 | https://github.com/armetiz/LeezyPheanstalkBundle/blob/e27e1507e7224faba0b439a09808839a366a8569/src/DataCollector/PheanstalkDataCollector.php#L145-L166 | train |
armetiz/LeezyPheanstalkBundle | src/DependencyInjection/LeezyPheanstalkExtension.php | LeezyPheanstalkExtension.configureConnections | public function configureConnections(ContainerBuilder $container, array $config)
{
// Create a connection locator that will reference all existing connection
$connectionLocatorDef = new Definition(PheanstalkLocator::class);
$container->setDefinition('leezy.pheanstalk.pheanstalk_locator', $connectionLocatorDef);
$container->setParameter('leezy.pheanstalk.pheanstalks', $config['pheanstalks']);
} | php | public function configureConnections(ContainerBuilder $container, array $config)
{
// Create a connection locator that will reference all existing connection
$connectionLocatorDef = new Definition(PheanstalkLocator::class);
$container->setDefinition('leezy.pheanstalk.pheanstalk_locator', $connectionLocatorDef);
$container->setParameter('leezy.pheanstalk.pheanstalks', $config['pheanstalks']);
} | [
"public",
"function",
"configureConnections",
"(",
"ContainerBuilder",
"$",
"container",
",",
"array",
"$",
"config",
")",
"{",
"// Create a connection locator that will reference all existing connection",
"$",
"connectionLocatorDef",
"=",
"new",
"Definition",
"(",
"PheanstalkLocator",
"::",
"class",
")",
";",
"$",
"container",
"->",
"setDefinition",
"(",
"'leezy.pheanstalk.pheanstalk_locator'",
",",
"$",
"connectionLocatorDef",
")",
";",
"$",
"container",
"->",
"setParameter",
"(",
"'leezy.pheanstalk.pheanstalks'",
",",
"$",
"config",
"[",
"'pheanstalks'",
"]",
")",
";",
"}"
]
| Configures the Connections and Connection Locator.
@param ContainerBuilder $container
@param array $config
@throws PheanstalkException | [
"Configures",
"the",
"Connections",
"and",
"Connection",
"Locator",
"."
]
| e27e1507e7224faba0b439a09808839a366a8569 | https://github.com/armetiz/LeezyPheanstalkBundle/blob/e27e1507e7224faba0b439a09808839a366a8569/src/DependencyInjection/LeezyPheanstalkExtension.php#L49-L55 | train |
armetiz/LeezyPheanstalkBundle | src/DependencyInjection/LeezyPheanstalkExtension.php | LeezyPheanstalkExtension.configureProfiler | public function configureProfiler(ContainerBuilder $container, array $config)
{
// Setup the data collector service for Symfony profiler
$dataCollectorDef = new Definition(PheanstalkDataCollector::class);
$dataCollectorDef->setPublic(false);
$dataCollectorDef->addTag('data_collector', ['id' => 'pheanstalk', 'template' => $config['profiler']['template']]);
$dataCollectorDef->addArgument(new Reference('leezy.pheanstalk.pheanstalk_locator'));
$container->setDefinition('leezy.pheanstalk.data_collector', $dataCollectorDef);
} | php | public function configureProfiler(ContainerBuilder $container, array $config)
{
// Setup the data collector service for Symfony profiler
$dataCollectorDef = new Definition(PheanstalkDataCollector::class);
$dataCollectorDef->setPublic(false);
$dataCollectorDef->addTag('data_collector', ['id' => 'pheanstalk', 'template' => $config['profiler']['template']]);
$dataCollectorDef->addArgument(new Reference('leezy.pheanstalk.pheanstalk_locator'));
$container->setDefinition('leezy.pheanstalk.data_collector', $dataCollectorDef);
} | [
"public",
"function",
"configureProfiler",
"(",
"ContainerBuilder",
"$",
"container",
",",
"array",
"$",
"config",
")",
"{",
"// Setup the data collector service for Symfony profiler",
"$",
"dataCollectorDef",
"=",
"new",
"Definition",
"(",
"PheanstalkDataCollector",
"::",
"class",
")",
";",
"$",
"dataCollectorDef",
"->",
"setPublic",
"(",
"false",
")",
";",
"$",
"dataCollectorDef",
"->",
"addTag",
"(",
"'data_collector'",
",",
"[",
"'id'",
"=>",
"'pheanstalk'",
",",
"'template'",
"=>",
"$",
"config",
"[",
"'profiler'",
"]",
"[",
"'template'",
"]",
"]",
")",
";",
"$",
"dataCollectorDef",
"->",
"addArgument",
"(",
"new",
"Reference",
"(",
"'leezy.pheanstalk.pheanstalk_locator'",
")",
")",
";",
"$",
"container",
"->",
"setDefinition",
"(",
"'leezy.pheanstalk.data_collector'",
",",
"$",
"dataCollectorDef",
")",
";",
"}"
]
| Configures the profiler data collector.
@param ContainerBuilder $container Container
@param array $config Configuration | [
"Configures",
"the",
"profiler",
"data",
"collector",
"."
]
| e27e1507e7224faba0b439a09808839a366a8569 | https://github.com/armetiz/LeezyPheanstalkBundle/blob/e27e1507e7224faba0b439a09808839a366a8569/src/DependencyInjection/LeezyPheanstalkExtension.php#L63-L72 | train |
eveseat/eveapi | src/Jobs/Character/Blueprints.php | Blueprints.cleanup | private function cleanup(): void
{
CharacterBlueprint::where('character_id', $this->getCharacterId())
->whereNotIn('item_id', $this->cleanup_ids->flatten()->unique()->all())
->delete();
} | php | private function cleanup(): void
{
CharacterBlueprint::where('character_id', $this->getCharacterId())
->whereNotIn('item_id', $this->cleanup_ids->flatten()->unique()->all())
->delete();
} | [
"private",
"function",
"cleanup",
"(",
")",
":",
"void",
"{",
"CharacterBlueprint",
"::",
"where",
"(",
"'character_id'",
",",
"$",
"this",
"->",
"getCharacterId",
"(",
")",
")",
"->",
"whereNotIn",
"(",
"'item_id'",
",",
"$",
"this",
"->",
"cleanup_ids",
"->",
"flatten",
"(",
")",
"->",
"unique",
"(",
")",
"->",
"all",
"(",
")",
")",
"->",
"delete",
"(",
")",
";",
"}"
]
| Removes older entries from blueprints table.
@throws \Exception | [
"Removes",
"older",
"entries",
"from",
"blueprints",
"table",
"."
]
| ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81 | https://github.com/eveseat/eveapi/blob/ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81/src/Jobs/Character/Blueprints.php#L155-L161 | train |
eveseat/eveapi | src/Jobs/Universe/Structures.php | Structures.getCharacterAssetLocations | private function getCharacterAssetLocations(): array
{
$assets = CharacterAsset::where('character_id', $this->getCharacterId())
->where('location_flag', 'Hangar')
->where('location_type', 'other')
// Asset Safety
->where('location_id', '<>', self::ASSET_SAFETY)
// Solar Systems
->whereNotBetween('location_id', self::SOLAR_SYSTEMS_RANGE)
// Bugged Assets
->whereNotBetween('location_id', self::BUGGED_ASSETS_RANGE)
// Station / Outpost
->whereNotBetween('location_id', self::UPWELL_STRUCTURES_RANGE)
// stuffs
->whereNotIn('location_id', function ($query) {
$query->select('item_id')
->from((new CharacterAsset)->getTable())
->where('character_id', $this->getCharacterId())
->distinct();
})
// Remove structures that already have a name resolved
// within the last week.
->whereNotIn('location_id', function ($query) {
$query->select('structure_id')
->from((new UniverseStructure)->getTable())
->where('name', '<>', 'Unknown Structure')
->where('updated_at', '<', carbon('now')->subWeek());
})
->select('location_id')->distinct()
// Until CCP can sort out this endpoint, pick 30 random locations
// and try to get those names. We hard cap it at 30 otherwise we
// will quickly kill the error limit, resulting in a ban.
->inRandomOrder()
->limit(15)
->get();
return $assets->map(function ($asset) {
return $asset->location_id;
})->all();
} | php | private function getCharacterAssetLocations(): array
{
$assets = CharacterAsset::where('character_id', $this->getCharacterId())
->where('location_flag', 'Hangar')
->where('location_type', 'other')
// Asset Safety
->where('location_id', '<>', self::ASSET_SAFETY)
// Solar Systems
->whereNotBetween('location_id', self::SOLAR_SYSTEMS_RANGE)
// Bugged Assets
->whereNotBetween('location_id', self::BUGGED_ASSETS_RANGE)
// Station / Outpost
->whereNotBetween('location_id', self::UPWELL_STRUCTURES_RANGE)
// stuffs
->whereNotIn('location_id', function ($query) {
$query->select('item_id')
->from((new CharacterAsset)->getTable())
->where('character_id', $this->getCharacterId())
->distinct();
})
// Remove structures that already have a name resolved
// within the last week.
->whereNotIn('location_id', function ($query) {
$query->select('structure_id')
->from((new UniverseStructure)->getTable())
->where('name', '<>', 'Unknown Structure')
->where('updated_at', '<', carbon('now')->subWeek());
})
->select('location_id')->distinct()
// Until CCP can sort out this endpoint, pick 30 random locations
// and try to get those names. We hard cap it at 30 otherwise we
// will quickly kill the error limit, resulting in a ban.
->inRandomOrder()
->limit(15)
->get();
return $assets->map(function ($asset) {
return $asset->location_id;
})->all();
} | [
"private",
"function",
"getCharacterAssetLocations",
"(",
")",
":",
"array",
"{",
"$",
"assets",
"=",
"CharacterAsset",
"::",
"where",
"(",
"'character_id'",
",",
"$",
"this",
"->",
"getCharacterId",
"(",
")",
")",
"->",
"where",
"(",
"'location_flag'",
",",
"'Hangar'",
")",
"->",
"where",
"(",
"'location_type'",
",",
"'other'",
")",
"// Asset Safety",
"->",
"where",
"(",
"'location_id'",
",",
"'<>'",
",",
"self",
"::",
"ASSET_SAFETY",
")",
"// Solar Systems",
"->",
"whereNotBetween",
"(",
"'location_id'",
",",
"self",
"::",
"SOLAR_SYSTEMS_RANGE",
")",
"// Bugged Assets",
"->",
"whereNotBetween",
"(",
"'location_id'",
",",
"self",
"::",
"BUGGED_ASSETS_RANGE",
")",
"// Station / Outpost",
"->",
"whereNotBetween",
"(",
"'location_id'",
",",
"self",
"::",
"UPWELL_STRUCTURES_RANGE",
")",
"// stuffs",
"->",
"whereNotIn",
"(",
"'location_id'",
",",
"function",
"(",
"$",
"query",
")",
"{",
"$",
"query",
"->",
"select",
"(",
"'item_id'",
")",
"->",
"from",
"(",
"(",
"new",
"CharacterAsset",
")",
"->",
"getTable",
"(",
")",
")",
"->",
"where",
"(",
"'character_id'",
",",
"$",
"this",
"->",
"getCharacterId",
"(",
")",
")",
"->",
"distinct",
"(",
")",
";",
"}",
")",
"// Remove structures that already have a name resolved",
"// within the last week.",
"->",
"whereNotIn",
"(",
"'location_id'",
",",
"function",
"(",
"$",
"query",
")",
"{",
"$",
"query",
"->",
"select",
"(",
"'structure_id'",
")",
"->",
"from",
"(",
"(",
"new",
"UniverseStructure",
")",
"->",
"getTable",
"(",
")",
")",
"->",
"where",
"(",
"'name'",
",",
"'<>'",
",",
"'Unknown Structure'",
")",
"->",
"where",
"(",
"'updated_at'",
",",
"'<'",
",",
"carbon",
"(",
"'now'",
")",
"->",
"subWeek",
"(",
")",
")",
";",
"}",
")",
"->",
"select",
"(",
"'location_id'",
")",
"->",
"distinct",
"(",
")",
"// Until CCP can sort out this endpoint, pick 30 random locations",
"// and try to get those names. We hard cap it at 30 otherwise we",
"// will quickly kill the error limit, resulting in a ban.",
"->",
"inRandomOrder",
"(",
")",
"->",
"limit",
"(",
"15",
")",
"->",
"get",
"(",
")",
";",
"return",
"$",
"assets",
"->",
"map",
"(",
"function",
"(",
"$",
"asset",
")",
"{",
"return",
"$",
"asset",
"->",
"location_id",
";",
"}",
")",
"->",
"all",
"(",
")",
";",
"}"
]
| Gets the current characters asset locations.
@return array
@throws \Exception | [
"Gets",
"the",
"current",
"characters",
"asset",
"locations",
"."
]
| ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81 | https://github.com/eveseat/eveapi/blob/ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81/src/Jobs/Universe/Structures.php#L175-L218 | train |
eveseat/eveapi | src/Jobs/EsiBase.php | EsiBase.validateCall | public function validateCall(): void
{
if (! in_array($this->method, ['get', 'post', 'put', 'patch', 'delete']))
throw new Exception('Invalid HTTP method used');
if (trim($this->endpoint) === '')
throw new Exception('Empty endpoint used');
// Enfore a version specification unless this is a 'meta' call.
if (trim($this->version) === '' && ! (in_array('meta', $this->tags())))
throw new Exception('Version is empty');
} | php | public function validateCall(): void
{
if (! in_array($this->method, ['get', 'post', 'put', 'patch', 'delete']))
throw new Exception('Invalid HTTP method used');
if (trim($this->endpoint) === '')
throw new Exception('Empty endpoint used');
// Enfore a version specification unless this is a 'meta' call.
if (trim($this->version) === '' && ! (in_array('meta', $this->tags())))
throw new Exception('Version is empty');
} | [
"public",
"function",
"validateCall",
"(",
")",
":",
"void",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"this",
"->",
"method",
",",
"[",
"'get'",
",",
"'post'",
",",
"'put'",
",",
"'patch'",
",",
"'delete'",
"]",
")",
")",
"throw",
"new",
"Exception",
"(",
"'Invalid HTTP method used'",
")",
";",
"if",
"(",
"trim",
"(",
"$",
"this",
"->",
"endpoint",
")",
"===",
"''",
")",
"throw",
"new",
"Exception",
"(",
"'Empty endpoint used'",
")",
";",
"// Enfore a version specification unless this is a 'meta' call.",
"if",
"(",
"trim",
"(",
"$",
"this",
"->",
"version",
")",
"===",
"''",
"&&",
"!",
"(",
"in_array",
"(",
"'meta'",
",",
"$",
"this",
"->",
"tags",
"(",
")",
")",
")",
")",
"throw",
"new",
"Exception",
"(",
"'Version is empty'",
")",
";",
"}"
]
| Validates a call to ensure that a method and endpoint is set
in the job that is using this base class.
@return void
@throws \Exception | [
"Validates",
"a",
"call",
"to",
"ensure",
"that",
"a",
"method",
"and",
"endpoint",
"is",
"set",
"in",
"the",
"job",
"that",
"is",
"using",
"this",
"base",
"class",
"."
]
| ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81 | https://github.com/eveseat/eveapi/blob/ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81/src/Jobs/EsiBase.php#L259-L271 | train |
eveseat/eveapi | src/Jobs/EsiBase.php | EsiBase.tags | public function tags(): array
{
if (property_exists($this, 'tags')) {
if (is_null($this->token))
return array_merge($this->tags, ['public']);
return array_merge($this->tags, ['character_id:' . $this->getCharacterId()]);
}
if (is_null($this->token))
return ['unknown_tag', 'public'];
return ['unknown_tag', 'character_id:' . $this->getCharacterId()];
} | php | public function tags(): array
{
if (property_exists($this, 'tags')) {
if (is_null($this->token))
return array_merge($this->tags, ['public']);
return array_merge($this->tags, ['character_id:' . $this->getCharacterId()]);
}
if (is_null($this->token))
return ['unknown_tag', 'public'];
return ['unknown_tag', 'character_id:' . $this->getCharacterId()];
} | [
"public",
"function",
"tags",
"(",
")",
":",
"array",
"{",
"if",
"(",
"property_exists",
"(",
"$",
"this",
",",
"'tags'",
")",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"token",
")",
")",
"return",
"array_merge",
"(",
"$",
"this",
"->",
"tags",
",",
"[",
"'public'",
"]",
")",
";",
"return",
"array_merge",
"(",
"$",
"this",
"->",
"tags",
",",
"[",
"'character_id:'",
".",
"$",
"this",
"->",
"getCharacterId",
"(",
")",
"]",
")",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"token",
")",
")",
"return",
"[",
"'unknown_tag'",
",",
"'public'",
"]",
";",
"return",
"[",
"'unknown_tag'",
",",
"'character_id:'",
".",
"$",
"this",
"->",
"getCharacterId",
"(",
")",
"]",
";",
"}"
]
| Assign this job a tag so that Horizon can categorize and allow
for specific tags to be monitored.
If a job specifies the tags property, that is added to the
character_id tag that automatically gets appended.
@return array
@throws \Exception | [
"Assign",
"this",
"job",
"a",
"tag",
"so",
"that",
"Horizon",
"can",
"categorize",
"and",
"allow",
"for",
"specific",
"tags",
"to",
"be",
"monitored",
"."
]
| ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81 | https://github.com/eveseat/eveapi/blob/ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81/src/Jobs/EsiBase.php#L283-L297 | train |
eveseat/eveapi | src/Jobs/EsiBase.php | EsiBase.eseye | public function eseye()
{
if ($this->client)
return $this->client;
$this->client = app('esi-client');
if (is_null($this->token))
return $this->client = $this->client->get();
return $this->client = $this->client->get(new EsiAuthentication([
'refresh_token' => $this->token->refresh_token,
'access_token' => $this->token->token,
'token_expires' => $this->token->expires_on,
'scopes' => $this->token->scopes,
]));
} | php | public function eseye()
{
if ($this->client)
return $this->client;
$this->client = app('esi-client');
if (is_null($this->token))
return $this->client = $this->client->get();
return $this->client = $this->client->get(new EsiAuthentication([
'refresh_token' => $this->token->refresh_token,
'access_token' => $this->token->token,
'token_expires' => $this->token->expires_on,
'scopes' => $this->token->scopes,
]));
} | [
"public",
"function",
"eseye",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"client",
")",
"return",
"$",
"this",
"->",
"client",
";",
"$",
"this",
"->",
"client",
"=",
"app",
"(",
"'esi-client'",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"token",
")",
")",
"return",
"$",
"this",
"->",
"client",
"=",
"$",
"this",
"->",
"client",
"->",
"get",
"(",
")",
";",
"return",
"$",
"this",
"->",
"client",
"=",
"$",
"this",
"->",
"client",
"->",
"get",
"(",
"new",
"EsiAuthentication",
"(",
"[",
"'refresh_token'",
"=>",
"$",
"this",
"->",
"token",
"->",
"refresh_token",
",",
"'access_token'",
"=>",
"$",
"this",
"->",
"token",
"->",
"token",
",",
"'token_expires'",
"=>",
"$",
"this",
"->",
"token",
"->",
"expires_on",
",",
"'scopes'",
"=>",
"$",
"this",
"->",
"token",
"->",
"scopes",
",",
"]",
")",
")",
";",
"}"
]
| Get an instance of Eseye to use for this job.
@return \Seat\Eseye\Eseye
@throws \Seat\Eseye\Exceptions\InvalidContainerDataException | [
"Get",
"an",
"instance",
"of",
"Eseye",
"to",
"use",
"for",
"this",
"job",
"."
]
| ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81 | https://github.com/eveseat/eveapi/blob/ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81/src/Jobs/EsiBase.php#L305-L322 | train |
eveseat/eveapi | src/Jobs/EsiBase.php | EsiBase.logWarnings | public function logWarnings(EsiResponse $response): void
{
if (! is_null($response->pages) && $this->page === null) {
$this->eseye()->getLogger()->warning('Response contained pages but none was expected');
dispatch((new Analytics((new AnalyticsContainer)
->set('type', 'endpoint_warning')
->set('ec', 'unexpected_page')
->set('el', $this->version)
->set('ev', $this->endpoint))));
}
if (! is_null($this->page) && $response->pages === null) {
$this->eseye()->getLogger()->warning('Expected a paged response but had none');
dispatch((new Analytics((new AnalyticsContainer)
->set('type', 'endpoint_warning')
->set('ec', 'missing_pages')
->set('el', $this->version)
->set('ev', $this->endpoint))));
}
if (array_key_exists('Warning', $response->headers)) {
$this->eseye()->getLogger()->warning('A response contained a warning: ' .
$response->headers['Warning']);
dispatch((new Analytics((new AnalyticsContainer)
->set('type', 'generic_warning')
->set('ec', 'missing_pages')
->set('el', $this->endpoint)
->set('ev', $response->headers['Warning']))));
}
} | php | public function logWarnings(EsiResponse $response): void
{
if (! is_null($response->pages) && $this->page === null) {
$this->eseye()->getLogger()->warning('Response contained pages but none was expected');
dispatch((new Analytics((new AnalyticsContainer)
->set('type', 'endpoint_warning')
->set('ec', 'unexpected_page')
->set('el', $this->version)
->set('ev', $this->endpoint))));
}
if (! is_null($this->page) && $response->pages === null) {
$this->eseye()->getLogger()->warning('Expected a paged response but had none');
dispatch((new Analytics((new AnalyticsContainer)
->set('type', 'endpoint_warning')
->set('ec', 'missing_pages')
->set('el', $this->version)
->set('ev', $this->endpoint))));
}
if (array_key_exists('Warning', $response->headers)) {
$this->eseye()->getLogger()->warning('A response contained a warning: ' .
$response->headers['Warning']);
dispatch((new Analytics((new AnalyticsContainer)
->set('type', 'generic_warning')
->set('ec', 'missing_pages')
->set('el', $this->endpoint)
->set('ev', $response->headers['Warning']))));
}
} | [
"public",
"function",
"logWarnings",
"(",
"EsiResponse",
"$",
"response",
")",
":",
"void",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"response",
"->",
"pages",
")",
"&&",
"$",
"this",
"->",
"page",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"eseye",
"(",
")",
"->",
"getLogger",
"(",
")",
"->",
"warning",
"(",
"'Response contained pages but none was expected'",
")",
";",
"dispatch",
"(",
"(",
"new",
"Analytics",
"(",
"(",
"new",
"AnalyticsContainer",
")",
"->",
"set",
"(",
"'type'",
",",
"'endpoint_warning'",
")",
"->",
"set",
"(",
"'ec'",
",",
"'unexpected_page'",
")",
"->",
"set",
"(",
"'el'",
",",
"$",
"this",
"->",
"version",
")",
"->",
"set",
"(",
"'ev'",
",",
"$",
"this",
"->",
"endpoint",
")",
")",
")",
")",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"page",
")",
"&&",
"$",
"response",
"->",
"pages",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"eseye",
"(",
")",
"->",
"getLogger",
"(",
")",
"->",
"warning",
"(",
"'Expected a paged response but had none'",
")",
";",
"dispatch",
"(",
"(",
"new",
"Analytics",
"(",
"(",
"new",
"AnalyticsContainer",
")",
"->",
"set",
"(",
"'type'",
",",
"'endpoint_warning'",
")",
"->",
"set",
"(",
"'ec'",
",",
"'missing_pages'",
")",
"->",
"set",
"(",
"'el'",
",",
"$",
"this",
"->",
"version",
")",
"->",
"set",
"(",
"'ev'",
",",
"$",
"this",
"->",
"endpoint",
")",
")",
")",
")",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"'Warning'",
",",
"$",
"response",
"->",
"headers",
")",
")",
"{",
"$",
"this",
"->",
"eseye",
"(",
")",
"->",
"getLogger",
"(",
")",
"->",
"warning",
"(",
"'A response contained a warning: '",
".",
"$",
"response",
"->",
"headers",
"[",
"'Warning'",
"]",
")",
";",
"dispatch",
"(",
"(",
"new",
"Analytics",
"(",
"(",
"new",
"AnalyticsContainer",
")",
"->",
"set",
"(",
"'type'",
",",
"'generic_warning'",
")",
"->",
"set",
"(",
"'ec'",
",",
"'missing_pages'",
")",
"->",
"set",
"(",
"'el'",
",",
"$",
"this",
"->",
"endpoint",
")",
"->",
"set",
"(",
"'ev'",
",",
"$",
"response",
"->",
"headers",
"[",
"'Warning'",
"]",
")",
")",
")",
")",
";",
"}",
"}"
]
| Logs warnings to the Eseye logger.
These warnings will also cause analytics jobs to be
sent to allow for monitoring of endpoint changes.
@param \Seat\Eseye\Containers\EsiResponse $response
@throws \Throwable | [
"Logs",
"warnings",
"to",
"the",
"Eseye",
"logger",
"."
]
| ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81 | https://github.com/eveseat/eveapi/blob/ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81/src/Jobs/EsiBase.php#L334-L370 | train |
eveseat/eveapi | src/Jobs/EsiBase.php | EsiBase.updateRefreshToken | public function updateRefreshToken(): void
{
tap($this->token, function ($token) {
// If no API call was made, the client would never have
// been instantiated and auth information never updated.
if (is_null($this->client) || $this->public_call)
return;
$last_auth = $this->client->getAuthentication();
$token->token = $last_auth->access_token ?? '-';
$token->expires_on = $last_auth->token_expires;
$token->save();
});
} | php | public function updateRefreshToken(): void
{
tap($this->token, function ($token) {
// If no API call was made, the client would never have
// been instantiated and auth information never updated.
if (is_null($this->client) || $this->public_call)
return;
$last_auth = $this->client->getAuthentication();
$token->token = $last_auth->access_token ?? '-';
$token->expires_on = $last_auth->token_expires;
$token->save();
});
} | [
"public",
"function",
"updateRefreshToken",
"(",
")",
":",
"void",
"{",
"tap",
"(",
"$",
"this",
"->",
"token",
",",
"function",
"(",
"$",
"token",
")",
"{",
"// If no API call was made, the client would never have",
"// been instantiated and auth information never updated.",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"client",
")",
"||",
"$",
"this",
"->",
"public_call",
")",
"return",
";",
"$",
"last_auth",
"=",
"$",
"this",
"->",
"client",
"->",
"getAuthentication",
"(",
")",
";",
"$",
"token",
"->",
"token",
"=",
"$",
"last_auth",
"->",
"access_token",
"??",
"'-'",
";",
"$",
"token",
"->",
"expires_on",
"=",
"$",
"last_auth",
"->",
"token_expires",
";",
"$",
"token",
"->",
"save",
"(",
")",
";",
"}",
")",
";",
"}"
]
| Update the access_token last used in the job,
along with the expiry time. | [
"Update",
"the",
"access_token",
"last",
"used",
"in",
"the",
"job",
"along",
"with",
"the",
"expiry",
"time",
"."
]
| ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81 | https://github.com/eveseat/eveapi/blob/ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81/src/Jobs/EsiBase.php#L376-L393 | train |
eveseat/eveapi | src/Jobs/EsiBase.php | EsiBase.nextPage | public function nextPage(int $pages): bool
{
if ($this->page >= $pages)
return false;
$this->page++;
return true;
} | php | public function nextPage(int $pages): bool
{
if ($this->page >= $pages)
return false;
$this->page++;
return true;
} | [
"public",
"function",
"nextPage",
"(",
"int",
"$",
"pages",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"this",
"->",
"page",
">=",
"$",
"pages",
")",
"return",
"false",
";",
"$",
"this",
"->",
"page",
"++",
";",
"return",
"true",
";",
"}"
]
| Check if there are any pages left in a response
based on the number of pages available and the
current page.
@param int $pages
@return bool | [
"Check",
"if",
"there",
"are",
"any",
"pages",
"left",
"in",
"a",
"response",
"based",
"on",
"the",
"number",
"of",
"pages",
"available",
"and",
"the",
"current",
"page",
"."
]
| ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81 | https://github.com/eveseat/eveapi/blob/ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81/src/Jobs/EsiBase.php#L404-L413 | train |
eveseat/eveapi | src/Jobs/EsiBase.php | EsiBase.failed | public function failed(Exception $exception)
{
$this->incrementEsiRateLimit();
// Analytics. Report only the Exception class and message.
dispatch((new Analytics((new AnalyticsContainer)
->set('type', 'exception')
->set('exd', get_class($exception) . ':' . $exception->getMessage())
->set('exf', 1))));
// Rethrow the original exception for Horizon
throw $exception;
} | php | public function failed(Exception $exception)
{
$this->incrementEsiRateLimit();
// Analytics. Report only the Exception class and message.
dispatch((new Analytics((new AnalyticsContainer)
->set('type', 'exception')
->set('exd', get_class($exception) . ':' . $exception->getMessage())
->set('exf', 1))));
// Rethrow the original exception for Horizon
throw $exception;
} | [
"public",
"function",
"failed",
"(",
"Exception",
"$",
"exception",
")",
"{",
"$",
"this",
"->",
"incrementEsiRateLimit",
"(",
")",
";",
"// Analytics. Report only the Exception class and message.",
"dispatch",
"(",
"(",
"new",
"Analytics",
"(",
"(",
"new",
"AnalyticsContainer",
")",
"->",
"set",
"(",
"'type'",
",",
"'exception'",
")",
"->",
"set",
"(",
"'exd'",
",",
"get_class",
"(",
"$",
"exception",
")",
".",
"':'",
".",
"$",
"exception",
"->",
"getMessage",
"(",
")",
")",
"->",
"set",
"(",
"'exf'",
",",
"1",
")",
")",
")",
")",
";",
"// Rethrow the original exception for Horizon",
"throw",
"$",
"exception",
";",
"}"
]
| When a job fails, grab some information and send a
GA event about the exception. The Analytics job
does the work of checking if analytics is disabled
or not, so we don't have to care about that here.
On top of that, we also increment the error rate
limiter. This is checked as part of the preflight
checks when API calls are made.
@param \Exception $exception
@throws \Exception
@throws \Psr\SimpleCache\InvalidArgumentException | [
"When",
"a",
"job",
"fails",
"grab",
"some",
"information",
"and",
"send",
"a",
"GA",
"event",
"about",
"the",
"exception",
".",
"The",
"Analytics",
"job",
"does",
"the",
"work",
"of",
"checking",
"if",
"analytics",
"is",
"disabled",
"or",
"not",
"so",
"we",
"don",
"t",
"have",
"to",
"care",
"about",
"that",
"here",
"."
]
| ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81 | https://github.com/eveseat/eveapi/blob/ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81/src/Jobs/EsiBase.php#L430-L443 | train |
eveseat/eveapi | src/Helpers/EseyeSetup.php | EseyeSetup.get | public function get(EsiAuthentication $authentication = null): Eseye
{
if ($authentication) {
tap($authentication, function ($auth) {
$auth->client_id = env('EVE_CLIENT_ID');
$auth->secret = env('EVE_CLIENT_SECRET');
});
return new Eseye($authentication);
}
// Return an unauthenticated Eseye instance
return new Eseye;
} | php | public function get(EsiAuthentication $authentication = null): Eseye
{
if ($authentication) {
tap($authentication, function ($auth) {
$auth->client_id = env('EVE_CLIENT_ID');
$auth->secret = env('EVE_CLIENT_SECRET');
});
return new Eseye($authentication);
}
// Return an unauthenticated Eseye instance
return new Eseye;
} | [
"public",
"function",
"get",
"(",
"EsiAuthentication",
"$",
"authentication",
"=",
"null",
")",
":",
"Eseye",
"{",
"if",
"(",
"$",
"authentication",
")",
"{",
"tap",
"(",
"$",
"authentication",
",",
"function",
"(",
"$",
"auth",
")",
"{",
"$",
"auth",
"->",
"client_id",
"=",
"env",
"(",
"'EVE_CLIENT_ID'",
")",
";",
"$",
"auth",
"->",
"secret",
"=",
"env",
"(",
"'EVE_CLIENT_SECRET'",
")",
";",
"}",
")",
";",
"return",
"new",
"Eseye",
"(",
"$",
"authentication",
")",
";",
"}",
"// Return an unauthenticated Eseye instance",
"return",
"new",
"Eseye",
";",
"}"
]
| Gets an instance of Eseye.
We automatically add the CLIENT_ID and SHARED_SECRET configured
for this SeAT instance to the EsiAuthentication container.
@param \Seat\Eseye\Containers\EsiAuthentication|null $authentication
@return \Seat\Eseye\Eseye
@throws \Seat\Eseye\Exceptions\InvalidContainerDataException | [
"Gets",
"an",
"instance",
"of",
"Eseye",
"."
]
| ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81 | https://github.com/eveseat/eveapi/blob/ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81/src/Helpers/EseyeSetup.php#L67-L83 | train |
eveseat/eveapi | src/Traits/RateLimitsCalls.php | RateLimitsCalls.isRateLimited | public function isRateLimited(): bool
{
if (cache()->get($this->getRateLimitKey()) < $this->getRateLimit())
return false;
return true;
} | php | public function isRateLimited(): bool
{
if (cache()->get($this->getRateLimitKey()) < $this->getRateLimit())
return false;
return true;
} | [
"public",
"function",
"isRateLimited",
"(",
")",
":",
"bool",
"{",
"if",
"(",
"cache",
"(",
")",
"->",
"get",
"(",
"$",
"this",
"->",
"getRateLimitKey",
"(",
")",
")",
"<",
"$",
"this",
"->",
"getRateLimit",
"(",
")",
")",
"return",
"false",
";",
"return",
"true",
";",
"}"
]
| Checks if the current cache key is to be considered rate limited.
@return bool
@throws \Exception | [
"Checks",
"if",
"the",
"current",
"cache",
"key",
"is",
"to",
"be",
"considered",
"rate",
"limited",
"."
]
| ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81 | https://github.com/eveseat/eveapi/blob/ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81/src/Traits/RateLimitsCalls.php#L37-L44 | train |
eveseat/eveapi | src/Traits/RateLimitsCalls.php | RateLimitsCalls.incrementRateLimitCallCount | public function incrementRateLimitCallCount(int $amount = 1)
{
cache()->set($this->getRateLimitKey(), $amount, carbon('now')->addMinute(1));
} | php | public function incrementRateLimitCallCount(int $amount = 1)
{
cache()->set($this->getRateLimitKey(), $amount, carbon('now')->addMinute(1));
} | [
"public",
"function",
"incrementRateLimitCallCount",
"(",
"int",
"$",
"amount",
"=",
"1",
")",
"{",
"cache",
"(",
")",
"->",
"set",
"(",
"$",
"this",
"->",
"getRateLimitKey",
"(",
")",
",",
"$",
"amount",
",",
"carbon",
"(",
"'now'",
")",
"->",
"addMinute",
"(",
"1",
")",
")",
";",
"}"
]
| Increments the number of calls that have been made.
A rate limit should only live for one minute. This is
because CCP reset the error count every minute.
@param int $amount
@throws \Psr\SimpleCache\InvalidArgumentException | [
"Increments",
"the",
"number",
"of",
"calls",
"that",
"have",
"been",
"made",
"."
]
| ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81 | https://github.com/eveseat/eveapi/blob/ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81/src/Traits/RateLimitsCalls.php#L84-L88 | train |
eveseat/eveapi | src/Jobs/PlanetaryInteraction/Character/PlanetDetail.php | PlanetDetail.resetCollections | private function resetCollections()
{
$this->planet_pins = collect();
$this->planet_factories = collect();
$this->planet_extractors = collect();
$this->planet_heads = collect();
$this->planet_links = collect();
$this->planet_waypoints = collect();
$this->planet_routes = collect();
$this->planet_contents = collect();
} | php | private function resetCollections()
{
$this->planet_pins = collect();
$this->planet_factories = collect();
$this->planet_extractors = collect();
$this->planet_heads = collect();
$this->planet_links = collect();
$this->planet_waypoints = collect();
$this->planet_routes = collect();
$this->planet_contents = collect();
} | [
"private",
"function",
"resetCollections",
"(",
")",
"{",
"$",
"this",
"->",
"planet_pins",
"=",
"collect",
"(",
")",
";",
"$",
"this",
"->",
"planet_factories",
"=",
"collect",
"(",
")",
";",
"$",
"this",
"->",
"planet_extractors",
"=",
"collect",
"(",
")",
";",
"$",
"this",
"->",
"planet_heads",
"=",
"collect",
"(",
")",
";",
"$",
"this",
"->",
"planet_links",
"=",
"collect",
"(",
")",
";",
"$",
"this",
"->",
"planet_waypoints",
"=",
"collect",
"(",
")",
";",
"$",
"this",
"->",
"planet_routes",
"=",
"collect",
"(",
")",
";",
"$",
"this",
"->",
"planet_contents",
"=",
"collect",
"(",
")",
";",
"}"
]
| Resets the collections used for cleanup routines. | [
"Resets",
"the",
"collections",
"used",
"for",
"cleanup",
"routines",
"."
]
| ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81 | https://github.com/eveseat/eveapi/blob/ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81/src/Jobs/PlanetaryInteraction/Character/PlanetDetail.php#L131-L142 | train |
eveseat/eveapi | src/Jobs/PlanetaryInteraction/Character/PlanetDetail.php | PlanetDetail.planetCleanup | private function planetCleanup($planet)
{
// cleaning all waypoints
$this->cleanRouteWaypoints($planet);
// cleaning all routes
$this->cleanRoutes($planet);
// cleaning links
$this->cleanLinks($planet);
// cleaning contents
$this->cleanContents($planet);
// cleaning heads
$this->cleanHeads($planet);
// cleaning extractors
$this->cleanExtractors($planet);
// cleaning factories
$this->cleanFactories($planet);
// cleaning pins
$this->cleanPins($planet);
$this->resetCollections();
} | php | private function planetCleanup($planet)
{
// cleaning all waypoints
$this->cleanRouteWaypoints($planet);
// cleaning all routes
$this->cleanRoutes($planet);
// cleaning links
$this->cleanLinks($planet);
// cleaning contents
$this->cleanContents($planet);
// cleaning heads
$this->cleanHeads($planet);
// cleaning extractors
$this->cleanExtractors($planet);
// cleaning factories
$this->cleanFactories($planet);
// cleaning pins
$this->cleanPins($planet);
$this->resetCollections();
} | [
"private",
"function",
"planetCleanup",
"(",
"$",
"planet",
")",
"{",
"// cleaning all waypoints",
"$",
"this",
"->",
"cleanRouteWaypoints",
"(",
"$",
"planet",
")",
";",
"// cleaning all routes",
"$",
"this",
"->",
"cleanRoutes",
"(",
"$",
"planet",
")",
";",
"// cleaning links",
"$",
"this",
"->",
"cleanLinks",
"(",
"$",
"planet",
")",
";",
"// cleaning contents",
"$",
"this",
"->",
"cleanContents",
"(",
"$",
"planet",
")",
";",
"// cleaning heads",
"$",
"this",
"->",
"cleanHeads",
"(",
"$",
"planet",
")",
";",
"// cleaning extractors",
"$",
"this",
"->",
"cleanExtractors",
"(",
"$",
"planet",
")",
";",
"// cleaning factories",
"$",
"this",
"->",
"cleanFactories",
"(",
"$",
"planet",
")",
";",
"// cleaning pins",
"$",
"this",
"->",
"cleanPins",
"(",
"$",
"planet",
")",
";",
"$",
"this",
"->",
"resetCollections",
"(",
")",
";",
"}"
]
| Performs a cleanup of any routes, links or contents
of a planet.
@param $planet
@throws \Exception | [
"Performs",
"a",
"cleanup",
"of",
"any",
"routes",
"links",
"or",
"contents",
"of",
"a",
"planet",
"."
]
| ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81 | https://github.com/eveseat/eveapi/blob/ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81/src/Jobs/PlanetaryInteraction/Character/PlanetDetail.php#L324-L352 | train |
eveseat/eveapi | src/Traits/PerformsPreFlightChecking.php | PerformsPreFlightChecking.preflighted | public function preflighted(): bool
{
// Just stop if ESI is considered down.
if ($this->isEsiDown()) return false;
// Ignore NPC corporations by marking the job as unauthenticated.
// This is admittedly a little hacky, so a better way is needed
// more long term.
if (in_array('corporation', $this->tags()) && $this->isNPCCorporation())
return false;
// Public endpoints need no checking
if ($this->isPublicEndpoint()) return true;
// Check if the current scope also needs a corp role. If it does,
// ensure that the current character also has the required role
// and the corporation is not an NPC corporation.
if (count($this->roles) > 0) {
// Don't process NPC corporations.
if ($this->isNPCCorporation()) return false;
// Ensure that the character has the needed roles to make
// a call to this endpoint.
if ($this->isCorpCharacterWithRoles())
return true;
else
return false;
}
// If a corporation role is *not* required, check that we have the required
// scope at least.
if (in_array($this->scope, $this->token->scopes))
return true;
// Log the deny
Log::debug('Denied call to ' . $this->endpoint . ' as scope ' . $this->scope . ' was missing.');
return false;
} | php | public function preflighted(): bool
{
// Just stop if ESI is considered down.
if ($this->isEsiDown()) return false;
// Ignore NPC corporations by marking the job as unauthenticated.
// This is admittedly a little hacky, so a better way is needed
// more long term.
if (in_array('corporation', $this->tags()) && $this->isNPCCorporation())
return false;
// Public endpoints need no checking
if ($this->isPublicEndpoint()) return true;
// Check if the current scope also needs a corp role. If it does,
// ensure that the current character also has the required role
// and the corporation is not an NPC corporation.
if (count($this->roles) > 0) {
// Don't process NPC corporations.
if ($this->isNPCCorporation()) return false;
// Ensure that the character has the needed roles to make
// a call to this endpoint.
if ($this->isCorpCharacterWithRoles())
return true;
else
return false;
}
// If a corporation role is *not* required, check that we have the required
// scope at least.
if (in_array($this->scope, $this->token->scopes))
return true;
// Log the deny
Log::debug('Denied call to ' . $this->endpoint . ' as scope ' . $this->scope . ' was missing.');
return false;
} | [
"public",
"function",
"preflighted",
"(",
")",
":",
"bool",
"{",
"// Just stop if ESI is considered down.",
"if",
"(",
"$",
"this",
"->",
"isEsiDown",
"(",
")",
")",
"return",
"false",
";",
"// Ignore NPC corporations by marking the job as unauthenticated.",
"// This is admittedly a little hacky, so a better way is needed",
"// more long term.",
"if",
"(",
"in_array",
"(",
"'corporation'",
",",
"$",
"this",
"->",
"tags",
"(",
")",
")",
"&&",
"$",
"this",
"->",
"isNPCCorporation",
"(",
")",
")",
"return",
"false",
";",
"// Public endpoints need no checking",
"if",
"(",
"$",
"this",
"->",
"isPublicEndpoint",
"(",
")",
")",
"return",
"true",
";",
"// Check if the current scope also needs a corp role. If it does,",
"// ensure that the current character also has the required role",
"// and the corporation is not an NPC corporation.",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"roles",
")",
">",
"0",
")",
"{",
"// Don't process NPC corporations.",
"if",
"(",
"$",
"this",
"->",
"isNPCCorporation",
"(",
")",
")",
"return",
"false",
";",
"// Ensure that the character has the needed roles to make",
"// a call to this endpoint.",
"if",
"(",
"$",
"this",
"->",
"isCorpCharacterWithRoles",
"(",
")",
")",
"return",
"true",
";",
"else",
"return",
"false",
";",
"}",
"// If a corporation role is *not* required, check that we have the required",
"// scope at least.",
"if",
"(",
"in_array",
"(",
"$",
"this",
"->",
"scope",
",",
"$",
"this",
"->",
"token",
"->",
"scopes",
")",
")",
"return",
"true",
";",
"// Log the deny",
"Log",
"::",
"debug",
"(",
"'Denied call to '",
".",
"$",
"this",
"->",
"endpoint",
".",
"' as scope '",
".",
"$",
"this",
"->",
"scope",
".",
"' was missing.'",
")",
";",
"return",
"false",
";",
"}"
]
| Perform a number of preflight checks for an API call.
These checks attempt to pre-empt failure conditions and
other cases where the API call might fail. Checks include
those where a token might be invalid, or insufficient
roles exists on a token to make a corporation call.
Finally, if ESI is determined to be down, this will also
fail preflight checks.
@return bool
@throws \Exception | [
"Perform",
"a",
"number",
"of",
"preflight",
"checks",
"for",
"an",
"API",
"call",
"."
]
| ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81 | https://github.com/eveseat/eveapi/blob/ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81/src/Traits/PerformsPreFlightChecking.php#L49-L89 | train |
eveseat/eveapi | src/Traits/PerformsPreFlightChecking.php | PerformsPreFlightChecking.isEsiDown | public function isEsiDown(): bool
{
// Check if we may have hit an error threshold
if ($this->isEsiRateLimited()) return true;
// Get the latest ESI status.
$status = Cache::remember('esi_db_status', 1, function () {
return EsiStatus::latest()->first();
});
// If we don't have a status yet, assume everything is ok.
if (! $status) return false;
// If the data is too old, return false by default.
// Not being able to ping ESI could be indicative
// of many other problems.
if ($status->created_at->lte(carbon('now')->subHours(2)))
return true;
// If the status is OK, yay.
if ($status->status == 'ok')
return false;
return true;
} | php | public function isEsiDown(): bool
{
// Check if we may have hit an error threshold
if ($this->isEsiRateLimited()) return true;
// Get the latest ESI status.
$status = Cache::remember('esi_db_status', 1, function () {
return EsiStatus::latest()->first();
});
// If we don't have a status yet, assume everything is ok.
if (! $status) return false;
// If the data is too old, return false by default.
// Not being able to ping ESI could be indicative
// of many other problems.
if ($status->created_at->lte(carbon('now')->subHours(2)))
return true;
// If the status is OK, yay.
if ($status->status == 'ok')
return false;
return true;
} | [
"public",
"function",
"isEsiDown",
"(",
")",
":",
"bool",
"{",
"// Check if we may have hit an error threshold",
"if",
"(",
"$",
"this",
"->",
"isEsiRateLimited",
"(",
")",
")",
"return",
"true",
";",
"// Get the latest ESI status.",
"$",
"status",
"=",
"Cache",
"::",
"remember",
"(",
"'esi_db_status'",
",",
"1",
",",
"function",
"(",
")",
"{",
"return",
"EsiStatus",
"::",
"latest",
"(",
")",
"->",
"first",
"(",
")",
";",
"}",
")",
";",
"// If we don't have a status yet, assume everything is ok.",
"if",
"(",
"!",
"$",
"status",
")",
"return",
"false",
";",
"// If the data is too old, return false by default.",
"// Not being able to ping ESI could be indicative",
"// of many other problems.",
"if",
"(",
"$",
"status",
"->",
"created_at",
"->",
"lte",
"(",
"carbon",
"(",
"'now'",
")",
"->",
"subHours",
"(",
"2",
")",
")",
")",
"return",
"true",
";",
"// If the status is OK, yay.",
"if",
"(",
"$",
"status",
"->",
"status",
"==",
"'ok'",
")",
"return",
"false",
";",
"return",
"true",
";",
"}"
]
| Determine if ESI could be down.
The results of this call depends *heavily* on the
fact that the EsiPing job runs and gets output.
@return bool | [
"Determine",
"if",
"ESI",
"could",
"be",
"down",
"."
]
| ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81 | https://github.com/eveseat/eveapi/blob/ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81/src/Traits/PerformsPreFlightChecking.php#L99-L125 | train |
eveseat/eveapi | src/Traits/PerformsPreFlightChecking.php | PerformsPreFlightChecking.isPublicEndpoint | public function isPublicEndpoint(): bool
{
// Public calls need no checking.
if ($this->public_call || is_null($this->token) || $this->scope === 'public')
return true;
return false;
} | php | public function isPublicEndpoint(): bool
{
// Public calls need no checking.
if ($this->public_call || is_null($this->token) || $this->scope === 'public')
return true;
return false;
} | [
"public",
"function",
"isPublicEndpoint",
"(",
")",
":",
"bool",
"{",
"// Public calls need no checking.",
"if",
"(",
"$",
"this",
"->",
"public_call",
"||",
"is_null",
"(",
"$",
"this",
"->",
"token",
")",
"||",
"$",
"this",
"->",
"scope",
"===",
"'public'",
")",
"return",
"true",
";",
"return",
"false",
";",
"}"
]
| Check for a public enpoint call.
@return bool | [
"Check",
"for",
"a",
"public",
"enpoint",
"call",
"."
]
| ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81 | https://github.com/eveseat/eveapi/blob/ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81/src/Traits/PerformsPreFlightChecking.php#L132-L140 | train |
eveseat/eveapi | src/Traits/PerformsPreFlightChecking.php | PerformsPreFlightChecking.isCorpCharacterWithRoles | public function isCorpCharacterWithRoles(): bool
{
// Check the role needed for this call. The minimum role would
// be configured in the roles attribute, but we will add the
// 'Director' role as directors automatically have all roles.
array_push($this->roles, 'Director');
// Perform the check.
if (in_array($this->scope, $this->token->scopes) && ! empty(
array_intersect($this->roles, $this->getCharacterRoles()))) {
return true;
}
// Considering a corporation role was required with the scope,
// fail the authentication check. If we don't fail here, simply
// granting the SSO scope would pass the next truth test.
return false;
} | php | public function isCorpCharacterWithRoles(): bool
{
// Check the role needed for this call. The minimum role would
// be configured in the roles attribute, but we will add the
// 'Director' role as directors automatically have all roles.
array_push($this->roles, 'Director');
// Perform the check.
if (in_array($this->scope, $this->token->scopes) && ! empty(
array_intersect($this->roles, $this->getCharacterRoles()))) {
return true;
}
// Considering a corporation role was required with the scope,
// fail the authentication check. If we don't fail here, simply
// granting the SSO scope would pass the next truth test.
return false;
} | [
"public",
"function",
"isCorpCharacterWithRoles",
"(",
")",
":",
"bool",
"{",
"// Check the role needed for this call. The minimum role would",
"// be configured in the roles attribute, but we will add the",
"// 'Director' role as directors automatically have all roles.",
"array_push",
"(",
"$",
"this",
"->",
"roles",
",",
"'Director'",
")",
";",
"// Perform the check.",
"if",
"(",
"in_array",
"(",
"$",
"this",
"->",
"scope",
",",
"$",
"this",
"->",
"token",
"->",
"scopes",
")",
"&&",
"!",
"empty",
"(",
"array_intersect",
"(",
"$",
"this",
"->",
"roles",
",",
"$",
"this",
"->",
"getCharacterRoles",
"(",
")",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"// Considering a corporation role was required with the scope,",
"// fail the authentication check. If we don't fail here, simply",
"// granting the SSO scope would pass the next truth test.",
"return",
"false",
";",
"}"
]
| Determine if the current character refresh token has
the roles needed to make the corporation API call.
@return bool | [
"Determine",
"if",
"the",
"current",
"character",
"refresh",
"token",
"has",
"the",
"roles",
"needed",
"to",
"make",
"the",
"corporation",
"API",
"call",
"."
]
| ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81 | https://github.com/eveseat/eveapi/blob/ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81/src/Traits/PerformsPreFlightChecking.php#L162-L181 | train |
eveseat/eveapi | src/Models/Assets/CharacterAsset.php | CharacterAsset.getNameAttribute | public function getNameAttribute($value)
{
if (! $this->type)
return null;
if (is_null($value) || $value == '')
return $this->type->typeName;
return $value;
} | php | public function getNameAttribute($value)
{
if (! $this->type)
return null;
if (is_null($value) || $value == '')
return $this->type->typeName;
return $value;
} | [
"public",
"function",
"getNameAttribute",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"type",
")",
"return",
"null",
";",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
"||",
"$",
"value",
"==",
"''",
")",
"return",
"$",
"this",
"->",
"type",
"->",
"typeName",
";",
"return",
"$",
"value",
";",
"}"
]
| Allow us to call CharacterAsset->name.
@param $value
@return string | [
"Allow",
"us",
"to",
"call",
"CharacterAsset",
"-",
">",
"name",
"."
]
| ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81 | https://github.com/eveseat/eveapi/blob/ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81/src/Models/Assets/CharacterAsset.php#L149-L159 | train |
eveseat/eveapi | src/Models/Assets/CharacterAsset.php | CharacterAsset.getUsedVolumeAttribute | public function getUsedVolumeAttribute()
{
$content = $this->content;
if (! is_null($content))
return $content->sum(function ($item) {
return $item->type->volume;
});
return 0.0;
} | php | public function getUsedVolumeAttribute()
{
$content = $this->content;
if (! is_null($content))
return $content->sum(function ($item) {
return $item->type->volume;
});
return 0.0;
} | [
"public",
"function",
"getUsedVolumeAttribute",
"(",
")",
"{",
"$",
"content",
"=",
"$",
"this",
"->",
"content",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"content",
")",
")",
"return",
"$",
"content",
"->",
"sum",
"(",
"function",
"(",
"$",
"item",
")",
"{",
"return",
"$",
"item",
"->",
"type",
"->",
"volume",
";",
"}",
")",
";",
"return",
"0.0",
";",
"}"
]
| Provide the used space based on stored item volume.
@return float | [
"Provide",
"the",
"used",
"space",
"based",
"on",
"stored",
"item",
"volume",
"."
]
| ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81 | https://github.com/eveseat/eveapi/blob/ebbbdb78fef768a7a83cc1eab1f7b4846ea8fa81/src/Models/Assets/CharacterAsset.php#L181-L193 | train |
matomo-org/component-ini | src/IniReader.php | IniReader.readString | public function readString($ini)
{
// On PHP 5.3.3 an empty line return is needed at the end
// See http://3v4l.org/jD1Lh
$ini .= "\n";
if ($this->useNativeFunction) {
$array = $this->readWithNativeFunction($ini);
} else {
$array = $this->readWithAlternativeImplementation($ini);
}
return $array;
} | php | public function readString($ini)
{
// On PHP 5.3.3 an empty line return is needed at the end
// See http://3v4l.org/jD1Lh
$ini .= "\n";
if ($this->useNativeFunction) {
$array = $this->readWithNativeFunction($ini);
} else {
$array = $this->readWithAlternativeImplementation($ini);
}
return $array;
} | [
"public",
"function",
"readString",
"(",
"$",
"ini",
")",
"{",
"// On PHP 5.3.3 an empty line return is needed at the end",
"// See http://3v4l.org/jD1Lh",
"$",
"ini",
".=",
"\"\\n\"",
";",
"if",
"(",
"$",
"this",
"->",
"useNativeFunction",
")",
"{",
"$",
"array",
"=",
"$",
"this",
"->",
"readWithNativeFunction",
"(",
"$",
"ini",
")",
";",
"}",
"else",
"{",
"$",
"array",
"=",
"$",
"this",
"->",
"readWithAlternativeImplementation",
"(",
"$",
"ini",
")",
";",
"}",
"return",
"$",
"array",
";",
"}"
]
| Reads a INI configuration string and returns it as an array.
The array returned is multidimensional, indexed by section names:
```
array(
'Section 1' => array(
'value1' => 'hello',
'value2' => 'world',
),
'Section 2' => array(
'value3' => 'foo',
)
);
```
@param string $ini String containing INI configuration.
@throws IniReadingException
@return array | [
"Reads",
"a",
"INI",
"configuration",
"string",
"and",
"returns",
"it",
"as",
"an",
"array",
"."
]
| fbb28f9155a908147d02a5871a6469beb2981f6c | https://github.com/matomo-org/component-ini/blob/fbb28f9155a908147d02a5871a6469beb2981f6c/src/IniReader.php#L75-L88 | train |
matomo-org/component-ini | src/IniReader.php | IniReader.readComments | public function readComments($filename)
{
$ini = $this->getContentOfIniFile($filename);
$ini = $this->splitIniContentIntoLines($ini);
$descriptions = array();
$section = '';
$lastComment = '';
foreach ($ini as $line) {
$line = trim($line);
if (strpos($line, '[') === 0) {
$tmp = explode(']', $line);
$section = trim(substr($tmp[0], 1));
$descriptions[$section] = array();
$lastComment = '';
continue;
}
if (!preg_match('/^[a-zA-Z0-9[]/', $line)) {
if (strpos($line, ';') === 0) {
$line = trim(substr($line, 1));
}
// comment
$lastComment .= $line . "\n";
continue;
}
list($key, $value) = explode('=', $line, 2);
$key = trim($key);
if (strpos($key, '[]') === strlen($key) - 2) {
$key = substr($key, 0, -2);
}
if (empty($descriptions[$section][$key])) {
$descriptions[$section][$key] = $lastComment;
}
$lastComment = '';
}
return $descriptions;
} | php | public function readComments($filename)
{
$ini = $this->getContentOfIniFile($filename);
$ini = $this->splitIniContentIntoLines($ini);
$descriptions = array();
$section = '';
$lastComment = '';
foreach ($ini as $line) {
$line = trim($line);
if (strpos($line, '[') === 0) {
$tmp = explode(']', $line);
$section = trim(substr($tmp[0], 1));
$descriptions[$section] = array();
$lastComment = '';
continue;
}
if (!preg_match('/^[a-zA-Z0-9[]/', $line)) {
if (strpos($line, ';') === 0) {
$line = trim(substr($line, 1));
}
// comment
$lastComment .= $line . "\n";
continue;
}
list($key, $value) = explode('=', $line, 2);
$key = trim($key);
if (strpos($key, '[]') === strlen($key) - 2) {
$key = substr($key, 0, -2);
}
if (empty($descriptions[$section][$key])) {
$descriptions[$section][$key] = $lastComment;
}
$lastComment = '';
}
return $descriptions;
} | [
"public",
"function",
"readComments",
"(",
"$",
"filename",
")",
"{",
"$",
"ini",
"=",
"$",
"this",
"->",
"getContentOfIniFile",
"(",
"$",
"filename",
")",
";",
"$",
"ini",
"=",
"$",
"this",
"->",
"splitIniContentIntoLines",
"(",
"$",
"ini",
")",
";",
"$",
"descriptions",
"=",
"array",
"(",
")",
";",
"$",
"section",
"=",
"''",
";",
"$",
"lastComment",
"=",
"''",
";",
"foreach",
"(",
"$",
"ini",
"as",
"$",
"line",
")",
"{",
"$",
"line",
"=",
"trim",
"(",
"$",
"line",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"line",
",",
"'['",
")",
"===",
"0",
")",
"{",
"$",
"tmp",
"=",
"explode",
"(",
"']'",
",",
"$",
"line",
")",
";",
"$",
"section",
"=",
"trim",
"(",
"substr",
"(",
"$",
"tmp",
"[",
"0",
"]",
",",
"1",
")",
")",
";",
"$",
"descriptions",
"[",
"$",
"section",
"]",
"=",
"array",
"(",
")",
";",
"$",
"lastComment",
"=",
"''",
";",
"continue",
";",
"}",
"if",
"(",
"!",
"preg_match",
"(",
"'/^[a-zA-Z0-9[]/'",
",",
"$",
"line",
")",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"line",
",",
"';'",
")",
"===",
"0",
")",
"{",
"$",
"line",
"=",
"trim",
"(",
"substr",
"(",
"$",
"line",
",",
"1",
")",
")",
";",
"}",
"// comment",
"$",
"lastComment",
".=",
"$",
"line",
".",
"\"\\n\"",
";",
"continue",
";",
"}",
"list",
"(",
"$",
"key",
",",
"$",
"value",
")",
"=",
"explode",
"(",
"'='",
",",
"$",
"line",
",",
"2",
")",
";",
"$",
"key",
"=",
"trim",
"(",
"$",
"key",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"key",
",",
"'[]'",
")",
"===",
"strlen",
"(",
"$",
"key",
")",
"-",
"2",
")",
"{",
"$",
"key",
"=",
"substr",
"(",
"$",
"key",
",",
"0",
",",
"-",
"2",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"descriptions",
"[",
"$",
"section",
"]",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"descriptions",
"[",
"$",
"section",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"lastComment",
";",
"}",
"$",
"lastComment",
"=",
"''",
";",
"}",
"return",
"$",
"descriptions",
";",
"}"
]
| Reads ini comments for each key.
The array returned is multidimensional, indexed by section names:
```
array(
'Section 1' => array(
'key1' => 'comment 1',
'key2' => 'comment 2',
),
'Section 2' => array(
'key3' => 'comment 3',
)
);
```
@param string $filename The path to a file.
@throws IniReadingException
@return array | [
"Reads",
"ini",
"comments",
"for",
"each",
"key",
"."
]
| fbb28f9155a908147d02a5871a6469beb2981f6c | https://github.com/matomo-org/component-ini/blob/fbb28f9155a908147d02a5871a6469beb2981f6c/src/IniReader.php#L148-L193 | train |
matomo-org/component-ini | src/IniWriter.php | IniWriter.writeToString | public function writeToString(array $config, $header = '')
{
$ini = $header;
$sectionNames = array_keys($config);
foreach ($sectionNames as $sectionName) {
$section = $config[$sectionName];
// no point in writing empty sections
if (empty($section)) {
continue;
}
if (! is_array($section)) {
throw new IniWritingException(sprintf("Section \"%s\" doesn't contain an array of values", $sectionName));
}
$ini .= "[$sectionName]\n";
foreach ($section as $option => $value) {
if (is_numeric($option)) {
$option = $sectionName;
$value = array($value);
}
if (is_array($value)) {
foreach ($value as $currentValue) {
$ini .= $option . '[] = ' . $this->encodeValue($currentValue) . "\n";
}
} else {
$ini .= $option . ' = ' . $this->encodeValue($value) . "\n";
}
}
$ini .= "\n";
}
return $ini;
} | php | public function writeToString(array $config, $header = '')
{
$ini = $header;
$sectionNames = array_keys($config);
foreach ($sectionNames as $sectionName) {
$section = $config[$sectionName];
// no point in writing empty sections
if (empty($section)) {
continue;
}
if (! is_array($section)) {
throw new IniWritingException(sprintf("Section \"%s\" doesn't contain an array of values", $sectionName));
}
$ini .= "[$sectionName]\n";
foreach ($section as $option => $value) {
if (is_numeric($option)) {
$option = $sectionName;
$value = array($value);
}
if (is_array($value)) {
foreach ($value as $currentValue) {
$ini .= $option . '[] = ' . $this->encodeValue($currentValue) . "\n";
}
} else {
$ini .= $option . ' = ' . $this->encodeValue($value) . "\n";
}
}
$ini .= "\n";
}
return $ini;
} | [
"public",
"function",
"writeToString",
"(",
"array",
"$",
"config",
",",
"$",
"header",
"=",
"''",
")",
"{",
"$",
"ini",
"=",
"$",
"header",
";",
"$",
"sectionNames",
"=",
"array_keys",
"(",
"$",
"config",
")",
";",
"foreach",
"(",
"$",
"sectionNames",
"as",
"$",
"sectionName",
")",
"{",
"$",
"section",
"=",
"$",
"config",
"[",
"$",
"sectionName",
"]",
";",
"// no point in writing empty sections",
"if",
"(",
"empty",
"(",
"$",
"section",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"section",
")",
")",
"{",
"throw",
"new",
"IniWritingException",
"(",
"sprintf",
"(",
"\"Section \\\"%s\\\" doesn't contain an array of values\"",
",",
"$",
"sectionName",
")",
")",
";",
"}",
"$",
"ini",
".=",
"\"[$sectionName]\\n\"",
";",
"foreach",
"(",
"$",
"section",
"as",
"$",
"option",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"option",
")",
")",
"{",
"$",
"option",
"=",
"$",
"sectionName",
";",
"$",
"value",
"=",
"array",
"(",
"$",
"value",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"foreach",
"(",
"$",
"value",
"as",
"$",
"currentValue",
")",
"{",
"$",
"ini",
".=",
"$",
"option",
".",
"'[] = '",
".",
"$",
"this",
"->",
"encodeValue",
"(",
"$",
"currentValue",
")",
".",
"\"\\n\"",
";",
"}",
"}",
"else",
"{",
"$",
"ini",
".=",
"$",
"option",
".",
"' = '",
".",
"$",
"this",
"->",
"encodeValue",
"(",
"$",
"value",
")",
".",
"\"\\n\"",
";",
"}",
"}",
"$",
"ini",
".=",
"\"\\n\"",
";",
"}",
"return",
"$",
"ini",
";",
"}"
]
| Writes an array configuration to a INI string and returns it.
The array provided must be multidimensional, indexed by section names:
```
array(
'Section 1' => array(
'value1' => 'hello',
'value2' => 'world',
),
'Section 2' => array(
'value3' => 'foo',
)
);
```
@param array $config
@param string $header Optional header to insert at the top of the file.
@return string
@throws IniWritingException | [
"Writes",
"an",
"array",
"configuration",
"to",
"a",
"INI",
"string",
"and",
"returns",
"it",
"."
]
| fbb28f9155a908147d02a5871a6469beb2981f6c | https://github.com/matomo-org/component-ini/blob/fbb28f9155a908147d02a5871a6469beb2981f6c/src/IniWriter.php#L69-L108 | train |
tomaj/hermes | src/Dispatcher.php | Dispatcher.handle | public function handle(): void
{
try {
$this->driver->wait(function (MessageInterface $message) {
$this->log(
LogLevel::INFO,
"Start handle message #{$message->getId()} ({$message->getType()})",
$this->messageLoggerContext($message)
);
$result = $this->dispatch($message);
if ($this->restart && $this->restart->shouldRestart($this->startTime)) {
throw new RestartException('Restart');
}
return $result;
});
} catch (RestartException $e) {
$this->log(LogLevel::NOTICE, 'Existing hermes dispatcher - restart');
} catch (Exception $exception) {
Debugger::log($exception, Debugger::EXCEPTION);
}
} | php | public function handle(): void
{
try {
$this->driver->wait(function (MessageInterface $message) {
$this->log(
LogLevel::INFO,
"Start handle message #{$message->getId()} ({$message->getType()})",
$this->messageLoggerContext($message)
);
$result = $this->dispatch($message);
if ($this->restart && $this->restart->shouldRestart($this->startTime)) {
throw new RestartException('Restart');
}
return $result;
});
} catch (RestartException $e) {
$this->log(LogLevel::NOTICE, 'Existing hermes dispatcher - restart');
} catch (Exception $exception) {
Debugger::log($exception, Debugger::EXCEPTION);
}
} | [
"public",
"function",
"handle",
"(",
")",
":",
"void",
"{",
"try",
"{",
"$",
"this",
"->",
"driver",
"->",
"wait",
"(",
"function",
"(",
"MessageInterface",
"$",
"message",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"LogLevel",
"::",
"INFO",
",",
"\"Start handle message #{$message->getId()} ({$message->getType()})\"",
",",
"$",
"this",
"->",
"messageLoggerContext",
"(",
"$",
"message",
")",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"dispatch",
"(",
"$",
"message",
")",
";",
"if",
"(",
"$",
"this",
"->",
"restart",
"&&",
"$",
"this",
"->",
"restart",
"->",
"shouldRestart",
"(",
"$",
"this",
"->",
"startTime",
")",
")",
"{",
"throw",
"new",
"RestartException",
"(",
"'Restart'",
")",
";",
"}",
"return",
"$",
"result",
";",
"}",
")",
";",
"}",
"catch",
"(",
"RestartException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"LogLevel",
"::",
"NOTICE",
",",
"'Existing hermes dispatcher - restart'",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"exception",
")",
"{",
"Debugger",
"::",
"log",
"(",
"$",
"exception",
",",
"Debugger",
"::",
"EXCEPTION",
")",
";",
"}",
"}"
]
| Basic method for background job to star listening.
This method hook to driver wait() method and start listening events.
Method is blocking, so when you call it all processing will stop.
WARNING! Don't use it on web server calls. Run it only with cli.
@return void | [
"Basic",
"method",
"for",
"background",
"job",
"to",
"star",
"listening",
"."
]
| e04e5a2544493337fa8e5356128380bd520a2d2c | https://github.com/tomaj/hermes/blob/e04e5a2544493337fa8e5356128380bd520a2d2c/src/Dispatcher.php#L90-L113 | train |
tomaj/hermes | src/Dispatcher.php | Dispatcher.handleMessage | private function handleMessage(HandlerInterface $handler, MessageInterface $message): bool
{
// check if handler implements Psr\Log\LoggerAwareInterface (you can use \Psr\Log\LoggerAwareTrait)
if ($this->logger && method_exists($handler, 'setLogger')) {
$handler->setLogger($this->logger);
}
try {
$result = $handler->handle($message);
$this->log(
LogLevel::INFO,
"End handle message #{$message->getId()} ({$message->getType()})",
$this->messageLoggerContext($message)
);
} catch (Exception $e) {
$this->log(
LogLevel::ERROR,
"Handler " . get_class($handler) . " throws exception - {$e->getMessage()}",
['error' => $e, 'message' => $this->messageLoggerContext($message), 'exception' => $e]
);
Debugger::log($e, Debugger::EXCEPTION);
$result = false;
}
return $result;
} | php | private function handleMessage(HandlerInterface $handler, MessageInterface $message): bool
{
// check if handler implements Psr\Log\LoggerAwareInterface (you can use \Psr\Log\LoggerAwareTrait)
if ($this->logger && method_exists($handler, 'setLogger')) {
$handler->setLogger($this->logger);
}
try {
$result = $handler->handle($message);
$this->log(
LogLevel::INFO,
"End handle message #{$message->getId()} ({$message->getType()})",
$this->messageLoggerContext($message)
);
} catch (Exception $e) {
$this->log(
LogLevel::ERROR,
"Handler " . get_class($handler) . " throws exception - {$e->getMessage()}",
['error' => $e, 'message' => $this->messageLoggerContext($message), 'exception' => $e]
);
Debugger::log($e, Debugger::EXCEPTION);
$result = false;
}
return $result;
} | [
"private",
"function",
"handleMessage",
"(",
"HandlerInterface",
"$",
"handler",
",",
"MessageInterface",
"$",
"message",
")",
":",
"bool",
"{",
"// check if handler implements Psr\\Log\\LoggerAwareInterface (you can use \\Psr\\Log\\LoggerAwareTrait)",
"if",
"(",
"$",
"this",
"->",
"logger",
"&&",
"method_exists",
"(",
"$",
"handler",
",",
"'setLogger'",
")",
")",
"{",
"$",
"handler",
"->",
"setLogger",
"(",
"$",
"this",
"->",
"logger",
")",
";",
"}",
"try",
"{",
"$",
"result",
"=",
"$",
"handler",
"->",
"handle",
"(",
"$",
"message",
")",
";",
"$",
"this",
"->",
"log",
"(",
"LogLevel",
"::",
"INFO",
",",
"\"End handle message #{$message->getId()} ({$message->getType()})\"",
",",
"$",
"this",
"->",
"messageLoggerContext",
"(",
"$",
"message",
")",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"LogLevel",
"::",
"ERROR",
",",
"\"Handler \"",
".",
"get_class",
"(",
"$",
"handler",
")",
".",
"\" throws exception - {$e->getMessage()}\"",
",",
"[",
"'error'",
"=>",
"$",
"e",
",",
"'message'",
"=>",
"$",
"this",
"->",
"messageLoggerContext",
"(",
"$",
"message",
")",
",",
"'exception'",
"=>",
"$",
"e",
"]",
")",
";",
"Debugger",
"::",
"log",
"(",
"$",
"e",
",",
"Debugger",
"::",
"EXCEPTION",
")",
";",
"$",
"result",
"=",
"false",
";",
"}",
"return",
"$",
"result",
";",
"}"
]
| Handle given message with given handler
@param HandlerInterface $handler
@param MessageInterface $message
@return bool | [
"Handle",
"given",
"message",
"with",
"given",
"handler"
]
| e04e5a2544493337fa8e5356128380bd520a2d2c | https://github.com/tomaj/hermes/blob/e04e5a2544493337fa8e5356128380bd520a2d2c/src/Dispatcher.php#L151-L176 | train |
tomaj/hermes | src/Dispatcher.php | Dispatcher.hasHandlers | private function hasHandlers(string $type): bool
{
return isset($this->handlers[$type]) && count($this->handlers[$type]) > 0;
} | php | private function hasHandlers(string $type): bool
{
return isset($this->handlers[$type]) && count($this->handlers[$type]) > 0;
} | [
"private",
"function",
"hasHandlers",
"(",
"string",
"$",
"type",
")",
":",
"bool",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"handlers",
"[",
"$",
"type",
"]",
")",
"&&",
"count",
"(",
"$",
"this",
"->",
"handlers",
"[",
"$",
"type",
"]",
")",
">",
"0",
";",
"}"
]
| Check if actual dispatcher has handler for given type
@param string $type
@return bool | [
"Check",
"if",
"actual",
"dispatcher",
"has",
"handler",
"for",
"given",
"type"
]
| e04e5a2544493337fa8e5356128380bd520a2d2c | https://github.com/tomaj/hermes/blob/e04e5a2544493337fa8e5356128380bd520a2d2c/src/Dispatcher.php#L185-L188 | train |
tomaj/hermes | src/Dispatcher.php | Dispatcher.messageLoggerContext | private function messageLoggerContext(MessageInterface $message): array
{
return [
'id' => $message->getId(),
'created' => $message->getCreated(),
'type' => $message->getType(),
'payload' => $message->getPayload(),
];
} | php | private function messageLoggerContext(MessageInterface $message): array
{
return [
'id' => $message->getId(),
'created' => $message->getCreated(),
'type' => $message->getType(),
'payload' => $message->getPayload(),
];
} | [
"private",
"function",
"messageLoggerContext",
"(",
"MessageInterface",
"$",
"message",
")",
":",
"array",
"{",
"return",
"[",
"'id'",
"=>",
"$",
"message",
"->",
"getId",
"(",
")",
",",
"'created'",
"=>",
"$",
"message",
"->",
"getCreated",
"(",
")",
",",
"'type'",
"=>",
"$",
"message",
"->",
"getType",
"(",
")",
",",
"'payload'",
"=>",
"$",
"message",
"->",
"getPayload",
"(",
")",
",",
"]",
";",
"}"
]
| Serialize message to logger context
@param MessageInterface $message
@return array | [
"Serialize",
"message",
"to",
"logger",
"context"
]
| e04e5a2544493337fa8e5356128380bd520a2d2c | https://github.com/tomaj/hermes/blob/e04e5a2544493337fa8e5356128380bd520a2d2c/src/Dispatcher.php#L210-L218 | train |
what3words/w3w-php-wrapper | src/Geocoder.php | Geocoder.performRequest | private function performRequest($command, $parameters)
{
// add the apikey to the parameters
$parameters["key"] = $this->api_key;
// make an array out of the dictionary so that each element is a key value pair glued together with an '=', and urlencode the parameters
$param_array = array();
foreach ($parameters as $key=>$value)
$param_array[] = "$key=" . urlencode($value);
// glue the array together unto a string with elements connected with '&'
$params = implode("&", $param_array);
// put the whole URL together now
$url = $this->base_url . $command . "?" . $params;
// cal the server
$json = $this->call($url);
$data = json_decode($json, true);
if (isset($data["error"]))
{
$this->error["code"] = $data["error"]["code"];
$this->error["message"] = $data["error"]["message"];
$data = false;
}
return $data;
} | php | private function performRequest($command, $parameters)
{
// add the apikey to the parameters
$parameters["key"] = $this->api_key;
// make an array out of the dictionary so that each element is a key value pair glued together with an '=', and urlencode the parameters
$param_array = array();
foreach ($parameters as $key=>$value)
$param_array[] = "$key=" . urlencode($value);
// glue the array together unto a string with elements connected with '&'
$params = implode("&", $param_array);
// put the whole URL together now
$url = $this->base_url . $command . "?" . $params;
// cal the server
$json = $this->call($url);
$data = json_decode($json, true);
if (isset($data["error"]))
{
$this->error["code"] = $data["error"]["code"];
$this->error["message"] = $data["error"]["message"];
$data = false;
}
return $data;
} | [
"private",
"function",
"performRequest",
"(",
"$",
"command",
",",
"$",
"parameters",
")",
"{",
"// add the apikey to the parameters",
"$",
"parameters",
"[",
"\"key\"",
"]",
"=",
"$",
"this",
"->",
"api_key",
";",
"// make an array out of the dictionary so that each element is a key value pair glued together with an '=', and urlencode the parameters",
"$",
"param_array",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"$",
"param_array",
"[",
"]",
"=",
"\"$key=\"",
".",
"urlencode",
"(",
"$",
"value",
")",
";",
"// glue the array together unto a string with elements connected with '&'",
"$",
"params",
"=",
"implode",
"(",
"\"&\"",
",",
"$",
"param_array",
")",
";",
"// put the whole URL together now",
"$",
"url",
"=",
"$",
"this",
"->",
"base_url",
".",
"$",
"command",
".",
"\"?\"",
".",
"$",
"params",
";",
"// cal the server",
"$",
"json",
"=",
"$",
"this",
"->",
"call",
"(",
"$",
"url",
")",
";",
"$",
"data",
"=",
"json_decode",
"(",
"$",
"json",
",",
"true",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"\"error\"",
"]",
")",
")",
"{",
"$",
"this",
"->",
"error",
"[",
"\"code\"",
"]",
"=",
"$",
"data",
"[",
"\"error\"",
"]",
"[",
"\"code\"",
"]",
";",
"$",
"this",
"->",
"error",
"[",
"\"message\"",
"]",
"=",
"$",
"data",
"[",
"\"error\"",
"]",
"[",
"\"message\"",
"]",
";",
"$",
"data",
"=",
"false",
";",
"}",
"return",
"$",
"data",
";",
"}"
]
| Prepare the call to the API server | [
"Prepare",
"the",
"call",
"to",
"the",
"API",
"server"
]
| 216f620a511ccbb1101dc9236e914c8d174a5082 | https://github.com/what3words/w3w-php-wrapper/blob/216f620a511ccbb1101dc9236e914c8d174a5082/src/Geocoder.php#L97-L126 | train |
what3words/w3w-php-wrapper | src/Geocoder.php | Geocoder.call | private function call($url)
{
$handle = curl_init();
// set the options
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_ENCODING, "");
curl_setopt($handle, CURLOPT_MAXREDIRS, 10);
curl_setopt($handle, CURLOPT_TIMEOUT, 30);
curl_setopt($handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($handle, CURLOPT_CUSTOMREQUEST, "GET");
// make the call
$output = curl_exec($handle);
if ($output == false)
{
$this->error["code"] = "BadConnection";
$this->error["message"] = curl_error($handle);
}
curl_close($handle);
// return the json
return $output;
} | php | private function call($url)
{
$handle = curl_init();
// set the options
curl_setopt($handle, CURLOPT_URL, $url);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_ENCODING, "");
curl_setopt($handle, CURLOPT_MAXREDIRS, 10);
curl_setopt($handle, CURLOPT_TIMEOUT, 30);
curl_setopt($handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($handle, CURLOPT_CUSTOMREQUEST, "GET");
// make the call
$output = curl_exec($handle);
if ($output == false)
{
$this->error["code"] = "BadConnection";
$this->error["message"] = curl_error($handle);
}
curl_close($handle);
// return the json
return $output;
} | [
"private",
"function",
"call",
"(",
"$",
"url",
")",
"{",
"$",
"handle",
"=",
"curl_init",
"(",
")",
";",
"// set the options",
"curl_setopt",
"(",
"$",
"handle",
",",
"CURLOPT_URL",
",",
"$",
"url",
")",
";",
"curl_setopt",
"(",
"$",
"handle",
",",
"CURLOPT_RETURNTRANSFER",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"handle",
",",
"CURLOPT_ENCODING",
",",
"\"\"",
")",
";",
"curl_setopt",
"(",
"$",
"handle",
",",
"CURLOPT_MAXREDIRS",
",",
"10",
")",
";",
"curl_setopt",
"(",
"$",
"handle",
",",
"CURLOPT_TIMEOUT",
",",
"30",
")",
";",
"curl_setopt",
"(",
"$",
"handle",
",",
"CURLOPT_HTTP_VERSION",
",",
"CURL_HTTP_VERSION_1_1",
")",
";",
"curl_setopt",
"(",
"$",
"handle",
",",
"CURLOPT_CUSTOMREQUEST",
",",
"\"GET\"",
")",
";",
"// make the call",
"$",
"output",
"=",
"curl_exec",
"(",
"$",
"handle",
")",
";",
"if",
"(",
"$",
"output",
"==",
"false",
")",
"{",
"$",
"this",
"->",
"error",
"[",
"\"code\"",
"]",
"=",
"\"BadConnection\"",
";",
"$",
"this",
"->",
"error",
"[",
"\"message\"",
"]",
"=",
"curl_error",
"(",
"$",
"handle",
")",
";",
"}",
"curl_close",
"(",
"$",
"handle",
")",
";",
"// return the json",
"return",
"$",
"output",
";",
"}"
]
| Make the call to the API server | [
"Make",
"the",
"call",
"to",
"the",
"API",
"server"
]
| 216f620a511ccbb1101dc9236e914c8d174a5082 | https://github.com/what3words/w3w-php-wrapper/blob/216f620a511ccbb1101dc9236e914c8d174a5082/src/Geocoder.php#L130-L155 | train |
koldy/framework | src/Koldy/Mail/Adapter/PHPMailer.php | PHPMailer.cc | public function cc(string $email, string $name = null)
{
$this->mailer->addCC($email, $name ?? '');
return $this;
} | php | public function cc(string $email, string $name = null)
{
$this->mailer->addCC($email, $name ?? '');
return $this;
} | [
"public",
"function",
"cc",
"(",
"string",
"$",
"email",
",",
"string",
"$",
"name",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"mailer",
"->",
"addCC",
"(",
"$",
"email",
",",
"$",
"name",
"??",
"''",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Send mail carbon copy
@param string $email
@param string|null $name
@return $this
@link http://koldy.net/docs/mail#example | [
"Send",
"mail",
"carbon",
"copy"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Mail/Adapter/PHPMailer.php#L131-L135 | train |
koldy/framework | src/Koldy/Mail/Adapter/PHPMailer.php | PHPMailer.bcc | public function bcc(string $email, string $name = null)
{
$this->mailer->addBCC($email, $name ?? '');
return $this;
} | php | public function bcc(string $email, string $name = null)
{
$this->mailer->addBCC($email, $name ?? '');
return $this;
} | [
"public",
"function",
"bcc",
"(",
"string",
"$",
"email",
",",
"string",
"$",
"name",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"mailer",
"->",
"addBCC",
"(",
"$",
"email",
",",
"$",
"name",
"??",
"''",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Send mail blind carbon copy
@param string $email
@param string|null $name
@return $this
@link http://koldy.net/docs/mail#example | [
"Send",
"mail",
"blind",
"carbon",
"copy"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Mail/Adapter/PHPMailer.php#L146-L150 | train |
dewsign/maxfactor-laravel-support | src/Webpage/Traits/HasParent.php | HasParent.getFullPath | protected function getFullPath($item = null)
{
if (!$item) {
$item = $this;
}
if (!$parent = $item->parent) {
return str_start($item->slug, '/');
}
return str_start(sprintf('%s%s', $this->getFullPath($parent), str_start($item->slug, '/')), '/');
} | php | protected function getFullPath($item = null)
{
if (!$item) {
$item = $this;
}
if (!$parent = $item->parent) {
return str_start($item->slug, '/');
}
return str_start(sprintf('%s%s', $this->getFullPath($parent), str_start($item->slug, '/')), '/');
} | [
"protected",
"function",
"getFullPath",
"(",
"$",
"item",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"item",
")",
"{",
"$",
"item",
"=",
"$",
"this",
";",
"}",
"if",
"(",
"!",
"$",
"parent",
"=",
"$",
"item",
"->",
"parent",
")",
"{",
"return",
"str_start",
"(",
"$",
"item",
"->",
"slug",
",",
"'/'",
")",
";",
"}",
"return",
"str_start",
"(",
"sprintf",
"(",
"'%s%s'",
",",
"$",
"this",
"->",
"getFullPath",
"(",
"$",
"parent",
")",
",",
"str_start",
"(",
"$",
"item",
"->",
"slug",
",",
"'/'",
")",
")",
",",
"'/'",
")",
";",
"}"
]
| Get full path.
@return string Full path | [
"Get",
"full",
"path",
"."
]
| 49ad96edfdd7480a5f50ddea96800d1fe379a2b8 | https://github.com/dewsign/maxfactor-laravel-support/blob/49ad96edfdd7480a5f50ddea96800d1fe379a2b8/src/Webpage/Traits/HasParent.php#L46-L57 | train |
dewsign/maxfactor-laravel-support | src/Webpage/Traits/HasParent.php | HasParent.getFullPathAttribute | public function getFullPathAttribute()
{
$pathSections = explode('/', $this->getFullPath());
$slugsToExclude = array_wrap($this->domainMappedFolders);
$finalSlug = collect($pathSections)
->filter()
->reject(function ($slug) use ($slugsToExclude) {
return in_array($slug, $slugsToExclude);
})
->implode('/');
return str_start($finalSlug, '/');
} | php | public function getFullPathAttribute()
{
$pathSections = explode('/', $this->getFullPath());
$slugsToExclude = array_wrap($this->domainMappedFolders);
$finalSlug = collect($pathSections)
->filter()
->reject(function ($slug) use ($slugsToExclude) {
return in_array($slug, $slugsToExclude);
})
->implode('/');
return str_start($finalSlug, '/');
} | [
"public",
"function",
"getFullPathAttribute",
"(",
")",
"{",
"$",
"pathSections",
"=",
"explode",
"(",
"'/'",
",",
"$",
"this",
"->",
"getFullPath",
"(",
")",
")",
";",
"$",
"slugsToExclude",
"=",
"array_wrap",
"(",
"$",
"this",
"->",
"domainMappedFolders",
")",
";",
"$",
"finalSlug",
"=",
"collect",
"(",
"$",
"pathSections",
")",
"->",
"filter",
"(",
")",
"->",
"reject",
"(",
"function",
"(",
"$",
"slug",
")",
"use",
"(",
"$",
"slugsToExclude",
")",
"{",
"return",
"in_array",
"(",
"$",
"slug",
",",
"$",
"slugsToExclude",
")",
";",
"}",
")",
"->",
"implode",
"(",
"'/'",
")",
";",
"return",
"str_start",
"(",
"$",
"finalSlug",
",",
"'/'",
")",
";",
"}"
]
| Add full path attribute.
@return string Full path | [
"Add",
"full",
"path",
"attribute",
"."
]
| 49ad96edfdd7480a5f50ddea96800d1fe379a2b8 | https://github.com/dewsign/maxfactor-laravel-support/blob/49ad96edfdd7480a5f50ddea96800d1fe379a2b8/src/Webpage/Traits/HasParent.php#L90-L104 | train |
dewsign/maxfactor-laravel-support | src/Webpage/Traits/HasParent.php | HasParent.scopeWhereFullPath | public function scopeWhereFullPath(Builder $query, string $path)
{
$itemSlugs = explode('/', $path);
return $query->where('slug', '=', end($itemSlugs))
->get()
->filter(function ($item) use ($path) {
return $item->full_path === str_start($path, '/');
});
} | php | public function scopeWhereFullPath(Builder $query, string $path)
{
$itemSlugs = explode('/', $path);
return $query->where('slug', '=', end($itemSlugs))
->get()
->filter(function ($item) use ($path) {
return $item->full_path === str_start($path, '/');
});
} | [
"public",
"function",
"scopeWhereFullPath",
"(",
"Builder",
"$",
"query",
",",
"string",
"$",
"path",
")",
"{",
"$",
"itemSlugs",
"=",
"explode",
"(",
"'/'",
",",
"$",
"path",
")",
";",
"return",
"$",
"query",
"->",
"where",
"(",
"'slug'",
",",
"'='",
",",
"end",
"(",
"$",
"itemSlugs",
")",
")",
"->",
"get",
"(",
")",
"->",
"filter",
"(",
"function",
"(",
"$",
"item",
")",
"use",
"(",
"$",
"path",
")",
"{",
"return",
"$",
"item",
"->",
"full_path",
"===",
"str_start",
"(",
"$",
"path",
",",
"'/'",
")",
";",
"}",
")",
";",
"}"
]
| Scope the query to only items that match the full path.
@param \Illuminate\Database\Eloquent\Builder $query
@param string $path Full path
@return \Illuminate\Database\Eloquent\Builder | [
"Scope",
"the",
"query",
"to",
"only",
"items",
"that",
"match",
"the",
"full",
"path",
"."
]
| 49ad96edfdd7480a5f50ddea96800d1fe379a2b8 | https://github.com/dewsign/maxfactor-laravel-support/blob/49ad96edfdd7480a5f50ddea96800d1fe379a2b8/src/Webpage/Traits/HasParent.php#L137-L146 | train |
koldy/framework | src/Koldy/Pagination.php | Pagination.getLinkHtml | protected function getLinkHtml($text, $page, $css)
{
$html = $this->buttonHtmlPattern;
$html = str_replace('{href}', $this->getLinkHref($page), $html);
$html = str_replace('{text}', $text, $html);
$html = str_replace('{page}', $page, $html);
$html = str_replace('{class}', $css, $html);
if ($css == '') {
$html = str_replace(' class=""', '', $html);
}
return $html;
} | php | protected function getLinkHtml($text, $page, $css)
{
$html = $this->buttonHtmlPattern;
$html = str_replace('{href}', $this->getLinkHref($page), $html);
$html = str_replace('{text}', $text, $html);
$html = str_replace('{page}', $page, $html);
$html = str_replace('{class}', $css, $html);
if ($css == '') {
$html = str_replace(' class=""', '', $html);
}
return $html;
} | [
"protected",
"function",
"getLinkHtml",
"(",
"$",
"text",
",",
"$",
"page",
",",
"$",
"css",
")",
"{",
"$",
"html",
"=",
"$",
"this",
"->",
"buttonHtmlPattern",
";",
"$",
"html",
"=",
"str_replace",
"(",
"'{href}'",
",",
"$",
"this",
"->",
"getLinkHref",
"(",
"$",
"page",
")",
",",
"$",
"html",
")",
";",
"$",
"html",
"=",
"str_replace",
"(",
"'{text}'",
",",
"$",
"text",
",",
"$",
"html",
")",
";",
"$",
"html",
"=",
"str_replace",
"(",
"'{page}'",
",",
"$",
"page",
",",
"$",
"html",
")",
";",
"$",
"html",
"=",
"str_replace",
"(",
"'{class}'",
",",
"$",
"css",
",",
"$",
"html",
")",
";",
"if",
"(",
"$",
"css",
"==",
"''",
")",
"{",
"$",
"html",
"=",
"str_replace",
"(",
"' class=\"\"'",
",",
"''",
",",
"$",
"html",
")",
";",
"}",
"return",
"$",
"html",
";",
"}"
]
| Get the HTML for complete link
@param string $text
@param string|int $page
@param string $css
@return mixed | [
"Get",
"the",
"HTML",
"for",
"complete",
"link"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Pagination.php#L261-L275 | train |
koldy/framework | src/Koldy/Pagination.php | Pagination.detectOtherValues | protected function detectOtherValues()
{
$this->totalPages = ceil($this->maxItems / $this->itemsPerPage);
$this->half = floor($this->numberOfPageLinks / 2);
$this->startPage = $this->currentPage - $this->half;
if ($this->startPage < 1) {
$this->startPage = 1;
}
$this->endPage = $this->startPage + $this->numberOfPageLinks - 1;
if ($this->endPage > $this->totalPages) {
$this->endPage = $this->totalPages;
}
} | php | protected function detectOtherValues()
{
$this->totalPages = ceil($this->maxItems / $this->itemsPerPage);
$this->half = floor($this->numberOfPageLinks / 2);
$this->startPage = $this->currentPage - $this->half;
if ($this->startPage < 1) {
$this->startPage = 1;
}
$this->endPage = $this->startPage + $this->numberOfPageLinks - 1;
if ($this->endPage > $this->totalPages) {
$this->endPage = $this->totalPages;
}
} | [
"protected",
"function",
"detectOtherValues",
"(",
")",
"{",
"$",
"this",
"->",
"totalPages",
"=",
"ceil",
"(",
"$",
"this",
"->",
"maxItems",
"/",
"$",
"this",
"->",
"itemsPerPage",
")",
";",
"$",
"this",
"->",
"half",
"=",
"floor",
"(",
"$",
"this",
"->",
"numberOfPageLinks",
"/",
"2",
")",
";",
"$",
"this",
"->",
"startPage",
"=",
"$",
"this",
"->",
"currentPage",
"-",
"$",
"this",
"->",
"half",
";",
"if",
"(",
"$",
"this",
"->",
"startPage",
"<",
"1",
")",
"{",
"$",
"this",
"->",
"startPage",
"=",
"1",
";",
"}",
"$",
"this",
"->",
"endPage",
"=",
"$",
"this",
"->",
"startPage",
"+",
"$",
"this",
"->",
"numberOfPageLinks",
"-",
"1",
";",
"if",
"(",
"$",
"this",
"->",
"endPage",
">",
"$",
"this",
"->",
"totalPages",
")",
"{",
"$",
"this",
"->",
"endPage",
"=",
"$",
"this",
"->",
"totalPages",
";",
"}",
"}"
]
| Detect other values needed for generate methods | [
"Detect",
"other",
"values",
"needed",
"for",
"generate",
"methods"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Pagination.php#L417-L433 | train |
koldy/framework | src/Koldy/Pagination.php | Pagination.toHtml | public function toHtml()
{
$this->detectOtherValues();
$html = '';
$html .= "<{$this->mainPaginationTag} class=\"{$this->mainCssClass}\">";
$html .= $this->getHtml4FirstPage();
$html .= $this->getHtml4PreviousPage();
$html .= $this->getHtml4Pages();
$html .= $this->getHtml4NextPage();
$html .= $this->getHtml4LastPage();
$html .= "</{$this->mainPaginationTag}>";
return $html;
} | php | public function toHtml()
{
$this->detectOtherValues();
$html = '';
$html .= "<{$this->mainPaginationTag} class=\"{$this->mainCssClass}\">";
$html .= $this->getHtml4FirstPage();
$html .= $this->getHtml4PreviousPage();
$html .= $this->getHtml4Pages();
$html .= $this->getHtml4NextPage();
$html .= $this->getHtml4LastPage();
$html .= "</{$this->mainPaginationTag}>";
return $html;
} | [
"public",
"function",
"toHtml",
"(",
")",
"{",
"$",
"this",
"->",
"detectOtherValues",
"(",
")",
";",
"$",
"html",
"=",
"''",
";",
"$",
"html",
".=",
"\"<{$this->mainPaginationTag} class=\\\"{$this->mainCssClass}\\\">\"",
";",
"$",
"html",
".=",
"$",
"this",
"->",
"getHtml4FirstPage",
"(",
")",
";",
"$",
"html",
".=",
"$",
"this",
"->",
"getHtml4PreviousPage",
"(",
")",
";",
"$",
"html",
".=",
"$",
"this",
"->",
"getHtml4Pages",
"(",
")",
";",
"$",
"html",
".=",
"$",
"this",
"->",
"getHtml4NextPage",
"(",
")",
";",
"$",
"html",
".=",
"$",
"this",
"->",
"getHtml4LastPage",
"(",
")",
";",
"$",
"html",
".=",
"\"</{$this->mainPaginationTag}>\"",
";",
"return",
"$",
"html",
";",
"}"
]
| The generate method
@return string | [
"The",
"generate",
"method"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Pagination.php#L496-L510 | train |
koldy/framework | src/Koldy/Validator.php | Validator.getData | public function getData(bool $trimStrings = null): array
{
$trimStrings = ($trimStrings === null) ? true : $trimStrings;
$data = $this->data;
foreach ($data as $key => $value) {
if (array_key_exists($key, $this->rules)) {
if ($value === '') {
// convert empty strings into nulls
$data[$key] = null;
}
}
if ($trimStrings && is_string($data[$key])) {
$data[$key] = trim($data[$key]);
}
}
$csrfParameterName = Csrf::getParameterName();
foreach ($this->rules as $field => $rules) {
if ($field != $csrfParameterName && !array_key_exists($field, $data)) {
$data[$field] = null;
}
if (isset($data[$field]) && is_string($data[$field]) && $rules !== null) {
$rules = explode('|', is_object($rules) && method_exists($rules, '__toString') ? $rules->__toString() : $rules);
// case booleans
if (in_array('bool', $rules) || in_array('boolean', $rules)) {
if ($data[$field] === 'true') {
$data[$field] = true;
} else if ($data[$field] === 'false') {
$data[$field] = false;
} else {
$data[$field] = (bool)$data[$field];
}
} else if (in_array('integer', $rules)) {
$data[$field] = (int)$data[$field];
}
}
}
if ($this->isCsrfEnabled() && isset($data[$csrfParameterName])) {
unset($data[$csrfParameterName]);
}
return $data;
} | php | public function getData(bool $trimStrings = null): array
{
$trimStrings = ($trimStrings === null) ? true : $trimStrings;
$data = $this->data;
foreach ($data as $key => $value) {
if (array_key_exists($key, $this->rules)) {
if ($value === '') {
// convert empty strings into nulls
$data[$key] = null;
}
}
if ($trimStrings && is_string($data[$key])) {
$data[$key] = trim($data[$key]);
}
}
$csrfParameterName = Csrf::getParameterName();
foreach ($this->rules as $field => $rules) {
if ($field != $csrfParameterName && !array_key_exists($field, $data)) {
$data[$field] = null;
}
if (isset($data[$field]) && is_string($data[$field]) && $rules !== null) {
$rules = explode('|', is_object($rules) && method_exists($rules, '__toString') ? $rules->__toString() : $rules);
// case booleans
if (in_array('bool', $rules) || in_array('boolean', $rules)) {
if ($data[$field] === 'true') {
$data[$field] = true;
} else if ($data[$field] === 'false') {
$data[$field] = false;
} else {
$data[$field] = (bool)$data[$field];
}
} else if (in_array('integer', $rules)) {
$data[$field] = (int)$data[$field];
}
}
}
if ($this->isCsrfEnabled() && isset($data[$csrfParameterName])) {
unset($data[$csrfParameterName]);
}
return $data;
} | [
"public",
"function",
"getData",
"(",
"bool",
"$",
"trimStrings",
"=",
"null",
")",
":",
"array",
"{",
"$",
"trimStrings",
"=",
"(",
"$",
"trimStrings",
"===",
"null",
")",
"?",
"true",
":",
"$",
"trimStrings",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"data",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"rules",
")",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"''",
")",
"{",
"// convert empty strings into nulls",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"null",
";",
"}",
"}",
"if",
"(",
"$",
"trimStrings",
"&&",
"is_string",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"trim",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"$",
"csrfParameterName",
"=",
"Csrf",
"::",
"getParameterName",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"rules",
"as",
"$",
"field",
"=>",
"$",
"rules",
")",
"{",
"if",
"(",
"$",
"field",
"!=",
"$",
"csrfParameterName",
"&&",
"!",
"array_key_exists",
"(",
"$",
"field",
",",
"$",
"data",
")",
")",
"{",
"$",
"data",
"[",
"$",
"field",
"]",
"=",
"null",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"$",
"field",
"]",
")",
"&&",
"is_string",
"(",
"$",
"data",
"[",
"$",
"field",
"]",
")",
"&&",
"$",
"rules",
"!==",
"null",
")",
"{",
"$",
"rules",
"=",
"explode",
"(",
"'|'",
",",
"is_object",
"(",
"$",
"rules",
")",
"&&",
"method_exists",
"(",
"$",
"rules",
",",
"'__toString'",
")",
"?",
"$",
"rules",
"->",
"__toString",
"(",
")",
":",
"$",
"rules",
")",
";",
"// case booleans",
"if",
"(",
"in_array",
"(",
"'bool'",
",",
"$",
"rules",
")",
"||",
"in_array",
"(",
"'boolean'",
",",
"$",
"rules",
")",
")",
"{",
"if",
"(",
"$",
"data",
"[",
"$",
"field",
"]",
"===",
"'true'",
")",
"{",
"$",
"data",
"[",
"$",
"field",
"]",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"$",
"data",
"[",
"$",
"field",
"]",
"===",
"'false'",
")",
"{",
"$",
"data",
"[",
"$",
"field",
"]",
"=",
"false",
";",
"}",
"else",
"{",
"$",
"data",
"[",
"$",
"field",
"]",
"=",
"(",
"bool",
")",
"$",
"data",
"[",
"$",
"field",
"]",
";",
"}",
"}",
"else",
"if",
"(",
"in_array",
"(",
"'integer'",
",",
"$",
"rules",
")",
")",
"{",
"$",
"data",
"[",
"$",
"field",
"]",
"=",
"(",
"int",
")",
"$",
"data",
"[",
"$",
"field",
"]",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"isCsrfEnabled",
"(",
")",
"&&",
"isset",
"(",
"$",
"data",
"[",
"$",
"csrfParameterName",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"data",
"[",
"$",
"csrfParameterName",
"]",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
]
| Get the data we're going to validate
@param bool $trimStrings
@return array
@throws Config\Exception
@throws Exception | [
"Get",
"the",
"data",
"we",
"re",
"going",
"to",
"validate"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Validator.php#L192-L240 | train |
koldy/framework | src/Koldy/Validator.php | Validator.validatePresent | protected function validatePresent($value, string $parameter, array $args = [], ?array $rules, array $context): ?string
{
if (!array_key_exists($parameter, $context)) {
return Message::getMessage(Message::PRESENT, [
'param' => $parameter
]);
}
return null;
} | php | protected function validatePresent($value, string $parameter, array $args = [], ?array $rules, array $context): ?string
{
if (!array_key_exists($parameter, $context)) {
return Message::getMessage(Message::PRESENT, [
'param' => $parameter
]);
}
return null;
} | [
"protected",
"function",
"validatePresent",
"(",
"$",
"value",
",",
"string",
"$",
"parameter",
",",
"array",
"$",
"args",
"=",
"[",
"]",
",",
"?",
"array",
"$",
"rules",
",",
"array",
"$",
"context",
")",
":",
"?",
"string",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"parameter",
",",
"$",
"context",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"PRESENT",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
"]",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Validate if parameter is present in array data. It will fail if parameter name does not exists
within data being validated.
@param mixed $value
@param string $parameter
@param array $args
@param array $rules other rule
@param array $context
@return string|null
@throws ValidatorConfigException
@example 'param' => 'present' - will fail if 'param' is not within validation data | [
"Validate",
"if",
"parameter",
"is",
"present",
"in",
"array",
"data",
".",
"It",
"will",
"fail",
"if",
"parameter",
"name",
"does",
"not",
"exists",
"within",
"data",
"being",
"validated",
"."
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Validator.php#L560-L569 | train |
koldy/framework | src/Koldy/Validator.php | Validator.validateMin | protected function validateMin($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
if (count($args) == 0) {
throw new ValidatorConfigException('Validator \'min\' has to have defined minimum value');
}
$minSize = $args[0] ?? null;
if (!is_numeric($minSize)) {
throw new ValidatorConfigException('Validator \'min\' has non-numeric value');
}
$minSize = (int)$minSize;
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (is_array($value) && in_array('array', $rules)) {
// we got an array, so let's check the array size
if (count($value) >= $minSize) {
return null;
}
return Message::getMessage(Message::MIN_VALUE, [
'param' => $parameter,
'min' => $minSize,
'value' => $value
]);
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$value = (string)$value;
if ($value === '') {
return null;
}
if (!is_numeric($value)) {
return Message::getMessage(Message::NUMERIC, [
'param' => $parameter,
'value' => $value
]);
}
$value += 0;
if ($value < $minSize) {
return Message::getMessage(Message::MIN_VALUE, [
'param' => $parameter,
'min' => $minSize,
'value' => $value
]);
}
return null;
} | php | protected function validateMin($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
if (count($args) == 0) {
throw new ValidatorConfigException('Validator \'min\' has to have defined minimum value');
}
$minSize = $args[0] ?? null;
if (!is_numeric($minSize)) {
throw new ValidatorConfigException('Validator \'min\' has non-numeric value');
}
$minSize = (int)$minSize;
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (is_array($value) && in_array('array', $rules)) {
// we got an array, so let's check the array size
if (count($value) >= $minSize) {
return null;
}
return Message::getMessage(Message::MIN_VALUE, [
'param' => $parameter,
'min' => $minSize,
'value' => $value
]);
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$value = (string)$value;
if ($value === '') {
return null;
}
if (!is_numeric($value)) {
return Message::getMessage(Message::NUMERIC, [
'param' => $parameter,
'value' => $value
]);
}
$value += 0;
if ($value < $minSize) {
return Message::getMessage(Message::MIN_VALUE, [
'param' => $parameter,
'min' => $minSize,
'value' => $value
]);
}
return null;
} | [
"protected",
"function",
"validateMin",
"(",
"$",
"value",
",",
"string",
"$",
"parameter",
",",
"array",
"$",
"args",
"=",
"[",
"]",
",",
"array",
"$",
"rules",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"null",
")",
":",
"?",
"string",
"{",
"if",
"(",
"count",
"(",
"$",
"args",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"ValidatorConfigException",
"(",
"'Validator \\'min\\' has to have defined minimum value'",
")",
";",
"}",
"$",
"minSize",
"=",
"$",
"args",
"[",
"0",
"]",
"??",
"null",
";",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"minSize",
")",
")",
"{",
"throw",
"new",
"ValidatorConfigException",
"(",
"'Validator \\'min\\' has non-numeric value'",
")",
";",
"}",
"$",
"minSize",
"=",
"(",
"int",
")",
"$",
"minSize",
";",
"//$value = $this->getValue($parameter);",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
"&&",
"in_array",
"(",
"'array'",
",",
"$",
"rules",
")",
")",
"{",
"// we got an array, so let's check the array size",
"if",
"(",
"count",
"(",
"$",
"value",
")",
">=",
"$",
"minSize",
")",
"{",
"return",
"null",
";",
"}",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"MIN_VALUE",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
",",
"'min'",
"=>",
"$",
"minSize",
",",
"'value'",
"=>",
"$",
"value",
"]",
")",
";",
"}",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"value",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"PRIMITIVE",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
"]",
")",
";",
"}",
"$",
"value",
"=",
"(",
"string",
")",
"$",
"value",
";",
"if",
"(",
"$",
"value",
"===",
"''",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"value",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"NUMERIC",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
",",
"'value'",
"=>",
"$",
"value",
"]",
")",
";",
"}",
"$",
"value",
"+=",
"0",
";",
"if",
"(",
"$",
"value",
"<",
"$",
"minSize",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"MIN_VALUE",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
",",
"'min'",
"=>",
"$",
"minSize",
",",
"'value'",
"=>",
"$",
"value",
"]",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Validate if value has the minimum value of
@param mixed $value
@param string $parameter
@param array $args
@param array $rules other rules
@param array|null $context
@return null|string
@throws ValidatorConfigException
@example 'param' => 'min:5' - will fail if value is not at least 5 | [
"Validate",
"if",
"value",
"has",
"the",
"minimum",
"value",
"of"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Validator.php#L643-L707 | train |
koldy/framework | src/Koldy/Validator.php | Validator.validateMax | protected function validateMax($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
if (count($args) == 0) {
throw new ValidatorConfigException('Validator \'max\' has to have defined maximum value');
}
$maxSize = $args[0] ?? null;
if (!is_numeric($maxSize)) {
throw new ValidatorConfigException('Validator \'max\' has non-numeric value');
}
$maxSize = (int)$maxSize;
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (is_array($value) && in_array('array', $rules)) {
if (count($value) > $maxSize) {
return Message::getMessage(Message::MAX_VALUE, [
'param' => $parameter,
'max' => $maxSize,
'value' => ''
]);
}
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$value = (string)$value;
if ($value === '') {
return null;
}
if (!is_numeric($value)) {
return Message::getMessage(Message::NUMERIC, [
'param' => $parameter,
'value' => $value
]);
}
$value += 0;
if ($value > $maxSize) {
return Message::getMessage(Message::MAX_VALUE, [
'param' => $parameter,
'max' => $maxSize,
'value' => $value
]);
}
return null;
} | php | protected function validateMax($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
if (count($args) == 0) {
throw new ValidatorConfigException('Validator \'max\' has to have defined maximum value');
}
$maxSize = $args[0] ?? null;
if (!is_numeric($maxSize)) {
throw new ValidatorConfigException('Validator \'max\' has non-numeric value');
}
$maxSize = (int)$maxSize;
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (is_array($value) && in_array('array', $rules)) {
if (count($value) > $maxSize) {
return Message::getMessage(Message::MAX_VALUE, [
'param' => $parameter,
'max' => $maxSize,
'value' => ''
]);
}
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$value = (string)$value;
if ($value === '') {
return null;
}
if (!is_numeric($value)) {
return Message::getMessage(Message::NUMERIC, [
'param' => $parameter,
'value' => $value
]);
}
$value += 0;
if ($value > $maxSize) {
return Message::getMessage(Message::MAX_VALUE, [
'param' => $parameter,
'max' => $maxSize,
'value' => $value
]);
}
return null;
} | [
"protected",
"function",
"validateMax",
"(",
"$",
"value",
",",
"string",
"$",
"parameter",
",",
"array",
"$",
"args",
"=",
"[",
"]",
",",
"array",
"$",
"rules",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"null",
")",
":",
"?",
"string",
"{",
"if",
"(",
"count",
"(",
"$",
"args",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"ValidatorConfigException",
"(",
"'Validator \\'max\\' has to have defined maximum value'",
")",
";",
"}",
"$",
"maxSize",
"=",
"$",
"args",
"[",
"0",
"]",
"??",
"null",
";",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"maxSize",
")",
")",
"{",
"throw",
"new",
"ValidatorConfigException",
"(",
"'Validator \\'max\\' has non-numeric value'",
")",
";",
"}",
"$",
"maxSize",
"=",
"(",
"int",
")",
"$",
"maxSize",
";",
"//$value = $this->getValue($parameter);",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
"&&",
"in_array",
"(",
"'array'",
",",
"$",
"rules",
")",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"value",
")",
">",
"$",
"maxSize",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"MAX_VALUE",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
",",
"'max'",
"=>",
"$",
"maxSize",
",",
"'value'",
"=>",
"''",
"]",
")",
";",
"}",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"value",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"PRIMITIVE",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
"]",
")",
";",
"}",
"$",
"value",
"=",
"(",
"string",
")",
"$",
"value",
";",
"if",
"(",
"$",
"value",
"===",
"''",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"value",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"NUMERIC",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
",",
"'value'",
"=>",
"$",
"value",
"]",
")",
";",
"}",
"$",
"value",
"+=",
"0",
";",
"if",
"(",
"$",
"value",
">",
"$",
"maxSize",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"MAX_VALUE",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
",",
"'max'",
"=>",
"$",
"maxSize",
",",
"'value'",
"=>",
"$",
"value",
"]",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Validate if value has the maximum value of
@param mixed $value
@param string $parameter
@param array $args
@param array $rules other rules
@param array|null $context
@return null|string
@throws ValidatorConfigException
@example 'param' => 'max:5' - will fail if value is not at least 5 | [
"Validate",
"if",
"value",
"has",
"the",
"maximum",
"value",
"of"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Validator.php#L722-L784 | train |
koldy/framework | src/Koldy/Validator.php | Validator.validateMinLength | protected function validateMinLength($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
if (count($args) == 0) {
throw new ValidatorConfigException('Validator \'minLength\' has to have defined minimum value');
}
if (!is_numeric($args[0])) {
throw new ValidatorConfigException('Validator \'minLength\' has non-numeric value');
}
//$value = $this->getValue($parameter);
$minLength = (int)$args[0];
if ($minLength < 0) {
throw new ValidatorConfigException('Validator \'minLength\' can not have negative minimum length');
}
if ($value === null) {
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$value = trim((string)$value);
if ($value === '') {
return null;
}
if (mb_strlen($value, Application::getEncoding()) < $minLength) {
return Message::getMessage(Message::MIN_LENGTH, [
'param' => $parameter,
'min' => $minLength,
'value' => $value
]);
}
return null;
} | php | protected function validateMinLength($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
if (count($args) == 0) {
throw new ValidatorConfigException('Validator \'minLength\' has to have defined minimum value');
}
if (!is_numeric($args[0])) {
throw new ValidatorConfigException('Validator \'minLength\' has non-numeric value');
}
//$value = $this->getValue($parameter);
$minLength = (int)$args[0];
if ($minLength < 0) {
throw new ValidatorConfigException('Validator \'minLength\' can not have negative minimum length');
}
if ($value === null) {
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$value = trim((string)$value);
if ($value === '') {
return null;
}
if (mb_strlen($value, Application::getEncoding()) < $minLength) {
return Message::getMessage(Message::MIN_LENGTH, [
'param' => $parameter,
'min' => $minLength,
'value' => $value
]);
}
return null;
} | [
"protected",
"function",
"validateMinLength",
"(",
"$",
"value",
",",
"string",
"$",
"parameter",
",",
"array",
"$",
"args",
"=",
"[",
"]",
",",
"array",
"$",
"rules",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"null",
")",
":",
"?",
"string",
"{",
"if",
"(",
"count",
"(",
"$",
"args",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"ValidatorConfigException",
"(",
"'Validator \\'minLength\\' has to have defined minimum value'",
")",
";",
"}",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"args",
"[",
"0",
"]",
")",
")",
"{",
"throw",
"new",
"ValidatorConfigException",
"(",
"'Validator \\'minLength\\' has non-numeric value'",
")",
";",
"}",
"//$value = $this->getValue($parameter);",
"$",
"minLength",
"=",
"(",
"int",
")",
"$",
"args",
"[",
"0",
"]",
";",
"if",
"(",
"$",
"minLength",
"<",
"0",
")",
"{",
"throw",
"new",
"ValidatorConfigException",
"(",
"'Validator \\'minLength\\' can not have negative minimum length'",
")",
";",
"}",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"value",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"PRIMITIVE",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
"]",
")",
";",
"}",
"$",
"value",
"=",
"trim",
"(",
"(",
"string",
")",
"$",
"value",
")",
";",
"if",
"(",
"$",
"value",
"===",
"''",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"mb_strlen",
"(",
"$",
"value",
",",
"Application",
"::",
"getEncoding",
"(",
")",
")",
"<",
"$",
"minLength",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"MIN_LENGTH",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
",",
"'min'",
"=>",
"$",
"minLength",
",",
"'value'",
"=>",
"$",
"value",
"]",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Validate minimum length of value. If value is numeric, it'll be converted to string
@param mixed $value
@param string $parameter
@param array $args
@param array $rules other rules
@param array|null $context
@return null|string
@throws ValidatorConfigException
@example 'param' => 'minLength:5'
@throws Exception
@deprecated due to ability to use $rules | [
"Validate",
"minimum",
"length",
"of",
"value",
".",
"If",
"value",
"is",
"numeric",
"it",
"ll",
"be",
"converted",
"to",
"string"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Validator.php#L802-L845 | train |
koldy/framework | src/Koldy/Validator.php | Validator.validateMaxLength | protected function validateMaxLength($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
if (count($args) == 0) {
throw new ValidatorConfigException('Validator \'maxLength\' has to have defined maximum value');
}
if (!is_numeric($args[0])) {
throw new ValidatorConfigException('Validator \'maxLength\' has non-numeric value');
}
//$value = $this->getValue($parameter);
$maxLength = (int)$args[0];
if ($maxLength <= 0) {
throw new ValidatorConfigException('Validator \'maxLength\' can\'t have value less or equal to zero in its definition');
}
if ($value === null) {
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$value = trim((string)$value);
if ($value === '') {
return null;
}
if (mb_strlen($value, Application::getEncoding()) > $maxLength) {
return Message::getMessage(Message::MAX_LENGTH, [
'param' => $parameter,
'max' => $maxLength,
'value' => $value
]);
}
return null;
} | php | protected function validateMaxLength($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
if (count($args) == 0) {
throw new ValidatorConfigException('Validator \'maxLength\' has to have defined maximum value');
}
if (!is_numeric($args[0])) {
throw new ValidatorConfigException('Validator \'maxLength\' has non-numeric value');
}
//$value = $this->getValue($parameter);
$maxLength = (int)$args[0];
if ($maxLength <= 0) {
throw new ValidatorConfigException('Validator \'maxLength\' can\'t have value less or equal to zero in its definition');
}
if ($value === null) {
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$value = trim((string)$value);
if ($value === '') {
return null;
}
if (mb_strlen($value, Application::getEncoding()) > $maxLength) {
return Message::getMessage(Message::MAX_LENGTH, [
'param' => $parameter,
'max' => $maxLength,
'value' => $value
]);
}
return null;
} | [
"protected",
"function",
"validateMaxLength",
"(",
"$",
"value",
",",
"string",
"$",
"parameter",
",",
"array",
"$",
"args",
"=",
"[",
"]",
",",
"array",
"$",
"rules",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"null",
")",
":",
"?",
"string",
"{",
"if",
"(",
"count",
"(",
"$",
"args",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"ValidatorConfigException",
"(",
"'Validator \\'maxLength\\' has to have defined maximum value'",
")",
";",
"}",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"args",
"[",
"0",
"]",
")",
")",
"{",
"throw",
"new",
"ValidatorConfigException",
"(",
"'Validator \\'maxLength\\' has non-numeric value'",
")",
";",
"}",
"//$value = $this->getValue($parameter);",
"$",
"maxLength",
"=",
"(",
"int",
")",
"$",
"args",
"[",
"0",
"]",
";",
"if",
"(",
"$",
"maxLength",
"<=",
"0",
")",
"{",
"throw",
"new",
"ValidatorConfigException",
"(",
"'Validator \\'maxLength\\' can\\'t have value less or equal to zero in its definition'",
")",
";",
"}",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"value",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"PRIMITIVE",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
"]",
")",
";",
"}",
"$",
"value",
"=",
"trim",
"(",
"(",
"string",
")",
"$",
"value",
")",
";",
"if",
"(",
"$",
"value",
"===",
"''",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"mb_strlen",
"(",
"$",
"value",
",",
"Application",
"::",
"getEncoding",
"(",
")",
")",
">",
"$",
"maxLength",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"MAX_LENGTH",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
",",
"'max'",
"=>",
"$",
"maxLength",
",",
"'value'",
"=>",
"$",
"value",
"]",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Validate maximum length of value. If value is numeric, it'll be converted to string
@param mixed $value
@param string $parameter
@param array $args
@param array $rules other rules
@param array|null $context
@return null|string
@throws ValidatorConfigException
@example 'param' => 'maxLength:5'
@throws Exception
@deprecated due to ability to use $rules | [
"Validate",
"maximum",
"length",
"of",
"value",
".",
"If",
"value",
"is",
"numeric",
"it",
"ll",
"be",
"converted",
"to",
"string"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Validator.php#L863-L905 | train |
koldy/framework | src/Koldy/Validator.php | Validator.validateLength | protected function validateLength($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
if (count($args) == 0) {
throw new ValidatorConfigException('Validator \'length\' has to have defined maximum value');
}
if (!is_numeric($args[0])) {
throw new ValidatorConfigException('Validator \'length\' has non-numeric value');
}
$requiredLength = (int)$args[0];
if ($requiredLength < 0) {
throw new ValidatorConfigException('Validator \'length\' has negative value in its definition which is not allowed');
}
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$value = trim((string)$value);
if ($value === '') {
return null;
}
if (mb_strlen($value, Application::getEncoding()) != $requiredLength) {
return Message::getMessage(Message::LENGTH, [
'param' => $parameter,
'length' => $args[0],
'value' => $value
]);
}
return null;
} | php | protected function validateLength($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
if (count($args) == 0) {
throw new ValidatorConfigException('Validator \'length\' has to have defined maximum value');
}
if (!is_numeric($args[0])) {
throw new ValidatorConfigException('Validator \'length\' has non-numeric value');
}
$requiredLength = (int)$args[0];
if ($requiredLength < 0) {
throw new ValidatorConfigException('Validator \'length\' has negative value in its definition which is not allowed');
}
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$value = trim((string)$value);
if ($value === '') {
return null;
}
if (mb_strlen($value, Application::getEncoding()) != $requiredLength) {
return Message::getMessage(Message::LENGTH, [
'param' => $parameter,
'length' => $args[0],
'value' => $value
]);
}
return null;
} | [
"protected",
"function",
"validateLength",
"(",
"$",
"value",
",",
"string",
"$",
"parameter",
",",
"array",
"$",
"args",
"=",
"[",
"]",
",",
"array",
"$",
"rules",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"null",
")",
":",
"?",
"string",
"{",
"if",
"(",
"count",
"(",
"$",
"args",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"ValidatorConfigException",
"(",
"'Validator \\'length\\' has to have defined maximum value'",
")",
";",
"}",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"args",
"[",
"0",
"]",
")",
")",
"{",
"throw",
"new",
"ValidatorConfigException",
"(",
"'Validator \\'length\\' has non-numeric value'",
")",
";",
"}",
"$",
"requiredLength",
"=",
"(",
"int",
")",
"$",
"args",
"[",
"0",
"]",
";",
"if",
"(",
"$",
"requiredLength",
"<",
"0",
")",
"{",
"throw",
"new",
"ValidatorConfigException",
"(",
"'Validator \\'length\\' has negative value in its definition which is not allowed'",
")",
";",
"}",
"//$value = $this->getValue($parameter);",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"value",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"PRIMITIVE",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
"]",
")",
";",
"}",
"$",
"value",
"=",
"trim",
"(",
"(",
"string",
")",
"$",
"value",
")",
";",
"if",
"(",
"$",
"value",
"===",
"''",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"mb_strlen",
"(",
"$",
"value",
",",
"Application",
"::",
"getEncoding",
"(",
")",
")",
"!=",
"$",
"requiredLength",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"LENGTH",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
",",
"'length'",
"=>",
"$",
"args",
"[",
"0",
"]",
",",
"'value'",
"=>",
"$",
"value",
"]",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Validate the exact length of string
@param mixed $value
@param string $parameter
@param array $args
@param array $rules other rules
@param array|null $context
@return null|string
@throws ValidatorConfigException
@example 'param' => 'length:5'
@throws Exception | [
"Validate",
"the",
"exact",
"length",
"of",
"string"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Validator.php#L922-L965 | train |
koldy/framework | src/Koldy/Validator.php | Validator.validateInteger | protected function validateInteger($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$value = (string)$value;
if ($value === '') {
return null;
}
if (!is_numeric($value)) {
return Message::getMessage(Message::NUMERIC, [
'param' => $parameter,
'value' => $value
]);
}
if ($value[0] == '-') {
$value = substr($value, 1);
}
if (!ctype_digit($value)) {
return Message::getMessage(Message::INTEGER, [
'param' => $parameter,
'value' => $value
]);
}
return null;
} | php | protected function validateInteger($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$value = (string)$value;
if ($value === '') {
return null;
}
if (!is_numeric($value)) {
return Message::getMessage(Message::NUMERIC, [
'param' => $parameter,
'value' => $value
]);
}
if ($value[0] == '-') {
$value = substr($value, 1);
}
if (!ctype_digit($value)) {
return Message::getMessage(Message::INTEGER, [
'param' => $parameter,
'value' => $value
]);
}
return null;
} | [
"protected",
"function",
"validateInteger",
"(",
"$",
"value",
",",
"string",
"$",
"parameter",
",",
"array",
"$",
"args",
"=",
"[",
"]",
",",
"array",
"$",
"rules",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"null",
")",
":",
"?",
"string",
"{",
"//$value = $this->getValue($parameter);",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"value",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"PRIMITIVE",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
"]",
")",
";",
"}",
"$",
"value",
"=",
"(",
"string",
")",
"$",
"value",
";",
"if",
"(",
"$",
"value",
"===",
"''",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"value",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"NUMERIC",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
",",
"'value'",
"=>",
"$",
"value",
"]",
")",
";",
"}",
"if",
"(",
"$",
"value",
"[",
"0",
"]",
"==",
"'-'",
")",
"{",
"$",
"value",
"=",
"substr",
"(",
"$",
"value",
",",
"1",
")",
";",
"}",
"if",
"(",
"!",
"ctype_digit",
"(",
"$",
"value",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"INTEGER",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
",",
"'value'",
"=>",
"$",
"value",
"]",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Validate if given value is integer. If you need to validate min and max, then chain those validators
@param mixed $value
@param string $parameter
@param array $args
@param array $rules other rules
@param array|null $context
@return null|string
@throws ValidatorConfigException
@example 'param' => 'integer' - passed value must contain 0-9 digits only | [
"Validate",
"if",
"given",
"value",
"is",
"integer",
".",
"If",
"you",
"need",
"to",
"validate",
"min",
"and",
"max",
"then",
"chain",
"those",
"validators"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Validator.php#L980-L1019 | train |
koldy/framework | src/Koldy/Validator.php | Validator.validateAlphaNum | protected function validateAlphaNum($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$value = (string)$value;
if ($value === '') {
return null;
}
if (!ctype_alnum($value)) {
return Message::getMessage(Message::ALPHA_NUM, [
'param' => $parameter,
'value' => $value
]);
}
return null;
} | php | protected function validateAlphaNum($value, string $parameter, array $args = [], array $rules = null, array $context = null): ?string
{
//$value = $this->getValue($parameter);
if ($value === null) {
return null;
}
if (!is_scalar($value)) {
return Message::getMessage(Message::PRIMITIVE, [
'param' => $parameter
]);
}
$value = (string)$value;
if ($value === '') {
return null;
}
if (!ctype_alnum($value)) {
return Message::getMessage(Message::ALPHA_NUM, [
'param' => $parameter,
'value' => $value
]);
}
return null;
} | [
"protected",
"function",
"validateAlphaNum",
"(",
"$",
"value",
",",
"string",
"$",
"parameter",
",",
"array",
"$",
"args",
"=",
"[",
"]",
",",
"array",
"$",
"rules",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"null",
")",
":",
"?",
"string",
"{",
"//$value = $this->getValue($parameter);",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"value",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"PRIMITIVE",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
"]",
")",
";",
"}",
"$",
"value",
"=",
"(",
"string",
")",
"$",
"value",
";",
"if",
"(",
"$",
"value",
"===",
"''",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"ctype_alnum",
"(",
"$",
"value",
")",
")",
"{",
"return",
"Message",
"::",
"getMessage",
"(",
"Message",
"::",
"ALPHA_NUM",
",",
"[",
"'param'",
"=>",
"$",
"parameter",
",",
"'value'",
"=>",
"$",
"value",
"]",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Validate if given value is alpha numeric or not, allowing lower and uppercase English letters with numbers
@param mixed $value
@param string $parameter
@param array $args
@param array $rules other rules
@return null|string
@throws ValidatorConfigException
@example 'param' => 'alphaNum' | [
"Validate",
"if",
"given",
"value",
"is",
"alpha",
"numeric",
"or",
"not",
"allowing",
"lower",
"and",
"uppercase",
"English",
"letters",
"with",
"numbers"
]
| 73559e7040e13ca583d831c7dde6ae02d2bae8e0 | https://github.com/koldy/framework/blob/73559e7040e13ca583d831c7dde6ae02d2bae8e0/src/Koldy/Validator.php#L1132-L1160 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.