id int32 0 241k | 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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
35,400 | Kajna/K-Core | Core/Http/Request.php | Request.isAjax | public function isAjax()
{
if ($this->headers->get('HTTP_X_REQUESTED_WITH') !== null
&& strtolower($this->headers->get('HTTP_X_REQUESTED_WITH')) === 'xmlhttprequest'
) {
return true;
}
return false;
} | php | public function isAjax()
{
if ($this->headers->get('HTTP_X_REQUESTED_WITH') !== null
&& strtolower($this->headers->get('HTTP_X_REQUESTED_WITH')) === 'xmlhttprequest'
) {
return true;
}
return false;
} | [
"public",
"function",
"isAjax",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"headers",
"->",
"get",
"(",
"'HTTP_X_REQUESTED_WITH'",
")",
"!==",
"null",
"&&",
"strtolower",
"(",
"$",
"this",
"->",
"headers",
"->",
"get",
"(",
"'HTTP_X_REQUESTED_WITH'",
")",
")",
"===",
"'xmlhttprequest'",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Check if it is AJAX request.
@return bool | [
"Check",
"if",
"it",
"is",
"AJAX",
"request",
"."
] | 6a354056cf95e471b9b1eb372c5626123fd77df2 | https://github.com/Kajna/K-Core/blob/6a354056cf95e471b9b1eb372c5626123fd77df2/Core/Http/Request.php#L226-L234 |
35,401 | hail-framework/framework | src/Filesystem/Adapter/Zip.php | Zip.reopenArchive | protected function reopenArchive()
{
$path = $this->archive->filename;
$this->archive->close();
$this->openArchive($path);
} | php | protected function reopenArchive()
{
$path = $this->archive->filename;
$this->archive->close();
$this->openArchive($path);
} | [
"protected",
"function",
"reopenArchive",
"(",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"archive",
"->",
"filename",
";",
"$",
"this",
"->",
"archive",
"->",
"close",
"(",
")",
";",
"$",
"this",
"->",
"openArchive",
"(",
"$",
"path",
")",
";",
"}"
] | Re-open an archive to ensure persistence. | [
"Re",
"-",
"open",
"an",
"archive",
"to",
"ensure",
"persistence",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Filesystem/Adapter/Zip.php#L50-L55 |
35,402 | hail-framework/framework | src/Filesystem/Adapter/Zip.php | Zip.normalizeObject | protected function normalizeObject(array $object)
{
if (\substr($object['name'], -1) === '/') {
return [
'path' => $this->removePathPrefix(\trim($object['name'], '/')),
'type' => 'dir',
];
}
$result = ['type' => 'file'];
$normalised = Util::map($object, static::$resultMap);
$normalised['path'] = $this->removePathPrefix($normalised['path']);
return \array_merge($result, $normalised);
} | php | protected function normalizeObject(array $object)
{
if (\substr($object['name'], -1) === '/') {
return [
'path' => $this->removePathPrefix(\trim($object['name'], '/')),
'type' => 'dir',
];
}
$result = ['type' => 'file'];
$normalised = Util::map($object, static::$resultMap);
$normalised['path'] = $this->removePathPrefix($normalised['path']);
return \array_merge($result, $normalised);
} | [
"protected",
"function",
"normalizeObject",
"(",
"array",
"$",
"object",
")",
"{",
"if",
"(",
"\\",
"substr",
"(",
"$",
"object",
"[",
"'name'",
"]",
",",
"-",
"1",
")",
"===",
"'/'",
")",
"{",
"return",
"[",
"'path'",
"=>",
"$",
"this",
"->",
"removePathPrefix",
"(",
"\\",
"trim",
"(",
"$",
"object",
"[",
"'name'",
"]",
",",
"'/'",
")",
")",
",",
"'type'",
"=>",
"'dir'",
",",
"]",
";",
"}",
"$",
"result",
"=",
"[",
"'type'",
"=>",
"'file'",
"]",
";",
"$",
"normalised",
"=",
"Util",
"::",
"map",
"(",
"$",
"object",
",",
"static",
"::",
"$",
"resultMap",
")",
";",
"$",
"normalised",
"[",
"'path'",
"]",
"=",
"$",
"this",
"->",
"removePathPrefix",
"(",
"$",
"normalised",
"[",
"'path'",
"]",
")",
";",
"return",
"\\",
"array_merge",
"(",
"$",
"result",
",",
"$",
"normalised",
")",
";",
"}"
] | Normalize a zip response array.
@param array $object
@return array | [
"Normalize",
"a",
"zip",
"response",
"array",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Filesystem/Adapter/Zip.php#L264-L278 |
35,403 | hail-framework/framework | src/I18n/Gettext/Extractors/Jed.php | Jed.extract | public static function extract(array $content, Translations $translations)
{
$messages = \current($content);
$headers = $messages[''] ?? null;
unset($messages['']);
if (!empty($headers['domain'])) {
$translations->setDomain($headers['domain']);
}
if (!empty($headers['lang'])) {
$translations->setLanguage($headers['lang']);
}
if (!empty($headers['plural-forms'])) {
$translations->setHeader(Translations::HEADER_PLURAL, $headers['plural-forms']);
}
$context_glue = '\u0004';
foreach ($messages as $key => $translation) {
$key = \explode($context_glue, $key);
$context = isset($key[1]) ? \array_shift($key) : '';
$translations->insert($context, \array_shift($key))
->setTranslation(\array_shift($translation))
->setPluralTranslations($translation);
}
} | php | public static function extract(array $content, Translations $translations)
{
$messages = \current($content);
$headers = $messages[''] ?? null;
unset($messages['']);
if (!empty($headers['domain'])) {
$translations->setDomain($headers['domain']);
}
if (!empty($headers['lang'])) {
$translations->setLanguage($headers['lang']);
}
if (!empty($headers['plural-forms'])) {
$translations->setHeader(Translations::HEADER_PLURAL, $headers['plural-forms']);
}
$context_glue = '\u0004';
foreach ($messages as $key => $translation) {
$key = \explode($context_glue, $key);
$context = isset($key[1]) ? \array_shift($key) : '';
$translations->insert($context, \array_shift($key))
->setTranslation(\array_shift($translation))
->setPluralTranslations($translation);
}
} | [
"public",
"static",
"function",
"extract",
"(",
"array",
"$",
"content",
",",
"Translations",
"$",
"translations",
")",
"{",
"$",
"messages",
"=",
"\\",
"current",
"(",
"$",
"content",
")",
";",
"$",
"headers",
"=",
"$",
"messages",
"[",
"''",
"]",
"??",
"null",
";",
"unset",
"(",
"$",
"messages",
"[",
"''",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"headers",
"[",
"'domain'",
"]",
")",
")",
"{",
"$",
"translations",
"->",
"setDomain",
"(",
"$",
"headers",
"[",
"'domain'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"headers",
"[",
"'lang'",
"]",
")",
")",
"{",
"$",
"translations",
"->",
"setLanguage",
"(",
"$",
"headers",
"[",
"'lang'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"headers",
"[",
"'plural-forms'",
"]",
")",
")",
"{",
"$",
"translations",
"->",
"setHeader",
"(",
"Translations",
"::",
"HEADER_PLURAL",
",",
"$",
"headers",
"[",
"'plural-forms'",
"]",
")",
";",
"}",
"$",
"context_glue",
"=",
"'\\u0004'",
";",
"foreach",
"(",
"$",
"messages",
"as",
"$",
"key",
"=>",
"$",
"translation",
")",
"{",
"$",
"key",
"=",
"\\",
"explode",
"(",
"$",
"context_glue",
",",
"$",
"key",
")",
";",
"$",
"context",
"=",
"isset",
"(",
"$",
"key",
"[",
"1",
"]",
")",
"?",
"\\",
"array_shift",
"(",
"$",
"key",
")",
":",
"''",
";",
"$",
"translations",
"->",
"insert",
"(",
"$",
"context",
",",
"\\",
"array_shift",
"(",
"$",
"key",
")",
")",
"->",
"setTranslation",
"(",
"\\",
"array_shift",
"(",
"$",
"translation",
")",
")",
"->",
"setPluralTranslations",
"(",
"$",
"translation",
")",
";",
"}",
"}"
] | Handle an array of translations and append to the Translations instance.
@param array $content
@param Translations $translations | [
"Handle",
"an",
"array",
"of",
"translations",
"and",
"append",
"to",
"the",
"Translations",
"instance",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/I18n/Gettext/Extractors/Jed.php#L26-L54 |
35,404 | hail-framework/framework | src/Event/EventManager.php | EventManager.addSubscriber | public function addSubscriber(EventSubscriberInterface $subscriber)
{
foreach ($subscriber->getSubscribedEvents() as $eventName => $params) {
if (\is_string($params)) {
$this->attach($eventName, [$subscriber, $params]);
} elseif (\is_array($params)) {
if (\is_string($params[0])) {
$this->attach($eventName, [$subscriber, $params[0]], $params[1] ?? 0);
} else {
foreach ($params as $listener) {
$this->attach($eventName, [$subscriber, $listener[0]], $listener[1] ?? 0);
}
}
}
}
return $this;
} | php | public function addSubscriber(EventSubscriberInterface $subscriber)
{
foreach ($subscriber->getSubscribedEvents() as $eventName => $params) {
if (\is_string($params)) {
$this->attach($eventName, [$subscriber, $params]);
} elseif (\is_array($params)) {
if (\is_string($params[0])) {
$this->attach($eventName, [$subscriber, $params[0]], $params[1] ?? 0);
} else {
foreach ($params as $listener) {
$this->attach($eventName, [$subscriber, $listener[0]], $listener[1] ?? 0);
}
}
}
}
return $this;
} | [
"public",
"function",
"addSubscriber",
"(",
"EventSubscriberInterface",
"$",
"subscriber",
")",
"{",
"foreach",
"(",
"$",
"subscriber",
"->",
"getSubscribedEvents",
"(",
")",
"as",
"$",
"eventName",
"=>",
"$",
"params",
")",
"{",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"params",
")",
")",
"{",
"$",
"this",
"->",
"attach",
"(",
"$",
"eventName",
",",
"[",
"$",
"subscriber",
",",
"$",
"params",
"]",
")",
";",
"}",
"elseif",
"(",
"\\",
"is_array",
"(",
"$",
"params",
")",
")",
"{",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"params",
"[",
"0",
"]",
")",
")",
"{",
"$",
"this",
"->",
"attach",
"(",
"$",
"eventName",
",",
"[",
"$",
"subscriber",
",",
"$",
"params",
"[",
"0",
"]",
"]",
",",
"$",
"params",
"[",
"1",
"]",
"??",
"0",
")",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"params",
"as",
"$",
"listener",
")",
"{",
"$",
"this",
"->",
"attach",
"(",
"$",
"eventName",
",",
"[",
"$",
"subscriber",
",",
"$",
"listener",
"[",
"0",
"]",
"]",
",",
"$",
"listener",
"[",
"1",
"]",
"??",
"0",
")",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Adds an event subscriber.
The subscriber is asked for all the events he is
interested in and added as a listener for these events.
@param EventSubscriberInterface $subscriber The subscriber
@return $this | [
"Adds",
"an",
"event",
"subscriber",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Event/EventManager.php#L195-L212 |
35,405 | hail-framework/framework | src/Event/EventManager.php | EventManager.removeSubscriber | public function removeSubscriber(EventSubscriberInterface $subscriber)
{
foreach ($subscriber->getSubscribedEvents() as $eventName => $params) {
if (\is_array($params) && \is_array($params[0])) {
foreach ($params as $listener) {
$this->detach($eventName, [$subscriber, $listener[0]]);
}
} else {
$this->detach($eventName, [$subscriber, \is_string($params) ? $params : $params[0]]);
}
}
return $this;
} | php | public function removeSubscriber(EventSubscriberInterface $subscriber)
{
foreach ($subscriber->getSubscribedEvents() as $eventName => $params) {
if (\is_array($params) && \is_array($params[0])) {
foreach ($params as $listener) {
$this->detach($eventName, [$subscriber, $listener[0]]);
}
} else {
$this->detach($eventName, [$subscriber, \is_string($params) ? $params : $params[0]]);
}
}
return $this;
} | [
"public",
"function",
"removeSubscriber",
"(",
"EventSubscriberInterface",
"$",
"subscriber",
")",
"{",
"foreach",
"(",
"$",
"subscriber",
"->",
"getSubscribedEvents",
"(",
")",
"as",
"$",
"eventName",
"=>",
"$",
"params",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"params",
")",
"&&",
"\\",
"is_array",
"(",
"$",
"params",
"[",
"0",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"params",
"as",
"$",
"listener",
")",
"{",
"$",
"this",
"->",
"detach",
"(",
"$",
"eventName",
",",
"[",
"$",
"subscriber",
",",
"$",
"listener",
"[",
"0",
"]",
"]",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"detach",
"(",
"$",
"eventName",
",",
"[",
"$",
"subscriber",
",",
"\\",
"is_string",
"(",
"$",
"params",
")",
"?",
"$",
"params",
":",
"$",
"params",
"[",
"0",
"]",
"]",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Removes an event subscriber.
@param EventSubscriberInterface $subscriber The subscriber
@return $this | [
"Removes",
"an",
"event",
"subscriber",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Event/EventManager.php#L221-L234 |
35,406 | hiqdev/hipanel-module-server | src/models/Server.php | Server.canFullRefuse | public function canFullRefuse()
{
if (!is_numeric($this->last_expires)) {
return null; // In case server is not sold
}
return (time() - Yii::$app->formatter->asTimestamp($this->last_expires)) / 3600 / 24 < 5;
} | php | public function canFullRefuse()
{
if (!is_numeric($this->last_expires)) {
return null; // In case server is not sold
}
return (time() - Yii::$app->formatter->asTimestamp($this->last_expires)) / 3600 / 24 < 5;
} | [
"public",
"function",
"canFullRefuse",
"(",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"this",
"->",
"last_expires",
")",
")",
"{",
"return",
"null",
";",
"// In case server is not sold",
"}",
"return",
"(",
"time",
"(",
")",
"-",
"Yii",
"::",
"$",
"app",
"->",
"formatter",
"->",
"asTimestamp",
"(",
"$",
"this",
"->",
"last_expires",
")",
")",
"/",
"3600",
"/",
"24",
"<",
"5",
";",
"}"
] | During 5 days after the last expiration client is able to refuse server with full refund.
Method checks, whether 5 days passed.
@return bool | [
"During",
"5",
"days",
"after",
"the",
"last",
"expiration",
"client",
"is",
"able",
"to",
"refuse",
"server",
"with",
"full",
"refund",
".",
"Method",
"checks",
"whether",
"5",
"days",
"passed",
"."
] | e40c3601952cf1fd420ebb97093ee17a33ff3207 | https://github.com/hiqdev/hipanel-module-server/blob/e40c3601952cf1fd420ebb97093ee17a33ff3207/src/models/Server.php#L240-L247 |
35,407 | hail-framework/framework | src/Http/Message/MessageTrait.php | MessageTrait.validateProtocolVersion | private function validateProtocolVersion($version): void
{
if (empty($version)) {
throw new \InvalidArgumentException(
'HTTP protocol version can not be empty'
);
}
if (!\is_string($version)) {
throw new \InvalidArgumentException(sprintf(
'Unsupported HTTP protocol version; must be a string, received %s',
(\is_object($version) ? \get_class($version) : \gettype($version))
));
}
// HTTP/1 uses a "<major>.<minor>" numbering scheme to indicate
// versions of the protocol, while HTTP/2 does not.
if (!\preg_match('#^(1\.[01]|2)$#', $version)) {
throw new \InvalidArgumentException(\sprintf(
'Unsupported HTTP protocol version "%s" provided',
$version
));
}
} | php | private function validateProtocolVersion($version): void
{
if (empty($version)) {
throw new \InvalidArgumentException(
'HTTP protocol version can not be empty'
);
}
if (!\is_string($version)) {
throw new \InvalidArgumentException(sprintf(
'Unsupported HTTP protocol version; must be a string, received %s',
(\is_object($version) ? \get_class($version) : \gettype($version))
));
}
// HTTP/1 uses a "<major>.<minor>" numbering scheme to indicate
// versions of the protocol, while HTTP/2 does not.
if (!\preg_match('#^(1\.[01]|2)$#', $version)) {
throw new \InvalidArgumentException(\sprintf(
'Unsupported HTTP protocol version "%s" provided',
$version
));
}
} | [
"private",
"function",
"validateProtocolVersion",
"(",
"$",
"version",
")",
":",
"void",
"{",
"if",
"(",
"empty",
"(",
"$",
"version",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'HTTP protocol version can not be empty'",
")",
";",
"}",
"if",
"(",
"!",
"\\",
"is_string",
"(",
"$",
"version",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Unsupported HTTP protocol version; must be a string, received %s'",
",",
"(",
"\\",
"is_object",
"(",
"$",
"version",
")",
"?",
"\\",
"get_class",
"(",
"$",
"version",
")",
":",
"\\",
"gettype",
"(",
"$",
"version",
")",
")",
")",
")",
";",
"}",
"// HTTP/1 uses a \"<major>.<minor>\" numbering scheme to indicate",
"// versions of the protocol, while HTTP/2 does not.",
"if",
"(",
"!",
"\\",
"preg_match",
"(",
"'#^(1\\.[01]|2)$#'",
",",
"$",
"version",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\\",
"sprintf",
"(",
"'Unsupported HTTP protocol version \"%s\" provided'",
",",
"$",
"version",
")",
")",
";",
"}",
"}"
] | Validate the HTTP protocol version
@param string $version
@throws \InvalidArgumentException on invalid HTTP protocol version | [
"Validate",
"the",
"HTTP",
"protocol",
"version"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Http/Message/MessageTrait.php#L193-L215 |
35,408 | hail-framework/framework | src/I18n/Gettext/Extractors/Po.php | Po.fixMultiLines | private static function fixMultiLines($line, array $lines, &$i)
{
for ($j = $i, $t = \count($lines); $j < $t; ++$j) {
if (\substr($line, -1, 1) == '"'
&& isset($lines[$j + 1])
&& \substr(\trim($lines[$j + 1]), 0, 1) == '"'
) {
$line = \substr($line, 0, -1) . \substr(\trim($lines[$j + 1]), 1);
} else {
$i = $j;
break;
}
}
return $line;
} | php | private static function fixMultiLines($line, array $lines, &$i)
{
for ($j = $i, $t = \count($lines); $j < $t; ++$j) {
if (\substr($line, -1, 1) == '"'
&& isset($lines[$j + 1])
&& \substr(\trim($lines[$j + 1]), 0, 1) == '"'
) {
$line = \substr($line, 0, -1) . \substr(\trim($lines[$j + 1]), 1);
} else {
$i = $j;
break;
}
}
return $line;
} | [
"private",
"static",
"function",
"fixMultiLines",
"(",
"$",
"line",
",",
"array",
"$",
"lines",
",",
"&",
"$",
"i",
")",
"{",
"for",
"(",
"$",
"j",
"=",
"$",
"i",
",",
"$",
"t",
"=",
"\\",
"count",
"(",
"$",
"lines",
")",
";",
"$",
"j",
"<",
"$",
"t",
";",
"++",
"$",
"j",
")",
"{",
"if",
"(",
"\\",
"substr",
"(",
"$",
"line",
",",
"-",
"1",
",",
"1",
")",
"==",
"'\"'",
"&&",
"isset",
"(",
"$",
"lines",
"[",
"$",
"j",
"+",
"1",
"]",
")",
"&&",
"\\",
"substr",
"(",
"\\",
"trim",
"(",
"$",
"lines",
"[",
"$",
"j",
"+",
"1",
"]",
")",
",",
"0",
",",
"1",
")",
"==",
"'\"'",
")",
"{",
"$",
"line",
"=",
"\\",
"substr",
"(",
"$",
"line",
",",
"0",
",",
"-",
"1",
")",
".",
"\\",
"substr",
"(",
"\\",
"trim",
"(",
"$",
"lines",
"[",
"$",
"j",
"+",
"1",
"]",
")",
",",
"1",
")",
";",
"}",
"else",
"{",
"$",
"i",
"=",
"$",
"j",
";",
"break",
";",
"}",
"}",
"return",
"$",
"line",
";",
"}"
] | Gets one string from multiline strings.
@param string $line
@param array $lines
@param int &$i
@return string | [
"Gets",
"one",
"string",
"from",
"multiline",
"strings",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/I18n/Gettext/Extractors/Po.php#L162-L177 |
35,409 | mirko-pagliai/php-tools | src/Entity.php | Entity.set | public function set($property, $value = null)
{
if (is_string($property) && $value != '') {
$property = [$property => $value];
}
foreach ($property as $name => $value) {
$this->properties[$name] = $value;
}
return $this;
} | php | public function set($property, $value = null)
{
if (is_string($property) && $value != '') {
$property = [$property => $value];
}
foreach ($property as $name => $value) {
$this->properties[$name] = $value;
}
return $this;
} | [
"public",
"function",
"set",
"(",
"$",
"property",
",",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"property",
")",
"&&",
"$",
"value",
"!=",
"''",
")",
"{",
"$",
"property",
"=",
"[",
"$",
"property",
"=>",
"$",
"value",
"]",
";",
"}",
"foreach",
"(",
"$",
"property",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"properties",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Sets a single property inside this entity
@param string|array $property The name of property to set or a list of
properties with their respective values
@param mixed $value The value to set to the property
@return $this
@uses $properties | [
"Sets",
"a",
"single",
"property",
"inside",
"this",
"entity"
] | 46003b05490de4b570b46c6377f1e09139ffe43b | https://github.com/mirko-pagliai/php-tools/blob/46003b05490de4b570b46c6377f1e09139ffe43b/src/Entity.php#L140-L151 |
35,410 | hail-framework/framework | src/Database/Model.php | Model.dirty | public function dirty(array $dirty = [])
{
$this->dirty = $dirty;
$this->data = \array_merge($this->data, $dirty);
return $this;
} | php | public function dirty(array $dirty = [])
{
$this->dirty = $dirty;
$this->data = \array_merge($this->data, $dirty);
return $this;
} | [
"public",
"function",
"dirty",
"(",
"array",
"$",
"dirty",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"dirty",
"=",
"$",
"dirty",
";",
"$",
"this",
"->",
"data",
"=",
"\\",
"array_merge",
"(",
"$",
"this",
"->",
"data",
",",
"$",
"dirty",
")",
";",
"return",
"$",
"this",
";",
"}"
] | function to SET or RESET the dirty data.
@param array $dirty The dirty data will be set, or empty array to reset the dirty data.
@return self return $this, can using chain method calls. | [
"function",
"to",
"SET",
"or",
"RESET",
"the",
"dirty",
"data",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Model.php#L165-L171 |
35,411 | hail-framework/framework | src/Database/Model.php | Model.get | public function get($id = null)
{
if ($id !== null) {
$this->eq($this->primary, $id);
}
$this->defaultTable();
DB::get($this->sql, PDO::FETCH_INTO, $this->reset());
return $this->dirty();
} | php | public function get($id = null)
{
if ($id !== null) {
$this->eq($this->primary, $id);
}
$this->defaultTable();
DB::get($this->sql, PDO::FETCH_INTO, $this->reset());
return $this->dirty();
} | [
"public",
"function",
"get",
"(",
"$",
"id",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"id",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"eq",
"(",
"$",
"this",
"->",
"primary",
",",
"$",
"id",
")",
";",
"}",
"$",
"this",
"->",
"defaultTable",
"(",
")",
";",
"DB",
"::",
"get",
"(",
"$",
"this",
"->",
"sql",
",",
"PDO",
"::",
"FETCH_INTO",
",",
"$",
"this",
"->",
"reset",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"dirty",
"(",
")",
";",
"}"
] | function to find one record and assign in to current object.
@param int $id If call this function using this param, will find record by using this id. If not set, just find
the first record in database.
@return bool|self if find record, assign in to current object and return it, other wise return "false". | [
"function",
"to",
"find",
"one",
"record",
"and",
"assign",
"in",
"to",
"current",
"object",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Model.php#L188-L198 |
35,412 | hail-framework/framework | src/Database/Model.php | Model.all | public function all()
{
$this->defaultTable();
$sql = $this->sql;
$this->reset();
return DB::select($sql, PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, static::class);
} | php | public function all()
{
$this->defaultTable();
$sql = $this->sql;
$this->reset();
return DB::select($sql, PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, static::class);
} | [
"public",
"function",
"all",
"(",
")",
"{",
"$",
"this",
"->",
"defaultTable",
"(",
")",
";",
"$",
"sql",
"=",
"$",
"this",
"->",
"sql",
";",
"$",
"this",
"->",
"reset",
"(",
")",
";",
"return",
"DB",
"::",
"select",
"(",
"$",
"sql",
",",
"PDO",
"::",
"FETCH_CLASS",
"|",
"PDO",
"::",
"FETCH_PROPS_LATE",
",",
"static",
"::",
"class",
")",
";",
"}"
] | function to find all records in database.
@return array return array of ORM | [
"function",
"to",
"find",
"all",
"records",
"in",
"database",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Model.php#L205-L212 |
35,413 | hail-framework/framework | src/Database/Model.php | Model.delete | public function delete()
{
$this->defaultTable();
$this->eq($this->primary, $this->__get($this->primary));
return DB::delete($this->sql);
} | php | public function delete()
{
$this->defaultTable();
$this->eq($this->primary, $this->__get($this->primary));
return DB::delete($this->sql);
} | [
"public",
"function",
"delete",
"(",
")",
"{",
"$",
"this",
"->",
"defaultTable",
"(",
")",
";",
"$",
"this",
"->",
"eq",
"(",
"$",
"this",
"->",
"primary",
",",
"$",
"this",
"->",
"__get",
"(",
"$",
"this",
"->",
"primary",
")",
")",
";",
"return",
"DB",
"::",
"delete",
"(",
"$",
"this",
"->",
"sql",
")",
";",
"}"
] | function to delete current record in database.
@return bool | [
"function",
"to",
"delete",
"current",
"record",
"in",
"database",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Model.php#L219-L225 |
35,414 | hail-framework/framework | src/Database/Model.php | Model.update | public function update()
{
if ($this->dirty === []) {
return true;
}
$this->defaultTable();
$this->sql['SET'] = $this->dirty;
$this->eq($this->primary, $this->__get($this->primary));
if (DB::update($this->sql)) {
return $this->dirty()->reset();
}
return false;
} | php | public function update()
{
if ($this->dirty === []) {
return true;
}
$this->defaultTable();
$this->sql['SET'] = $this->dirty;
$this->eq($this->primary, $this->__get($this->primary));
if (DB::update($this->sql)) {
return $this->dirty()->reset();
}
return false;
} | [
"public",
"function",
"update",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"dirty",
"===",
"[",
"]",
")",
"{",
"return",
"true",
";",
"}",
"$",
"this",
"->",
"defaultTable",
"(",
")",
";",
"$",
"this",
"->",
"sql",
"[",
"'SET'",
"]",
"=",
"$",
"this",
"->",
"dirty",
";",
"$",
"this",
"->",
"eq",
"(",
"$",
"this",
"->",
"primary",
",",
"$",
"this",
"->",
"__get",
"(",
"$",
"this",
"->",
"primary",
")",
")",
";",
"if",
"(",
"DB",
"::",
"update",
"(",
"$",
"this",
"->",
"sql",
")",
")",
"{",
"return",
"$",
"this",
"->",
"dirty",
"(",
")",
"->",
"reset",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] | function to build update SQL, and update current record in database, just write the dirty data into database.
@return bool|self if update success return current object, other wise return false. | [
"function",
"to",
"build",
"update",
"SQL",
"and",
"update",
"current",
"record",
"in",
"database",
"just",
"write",
"the",
"dirty",
"data",
"into",
"database",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Model.php#L232-L247 |
35,415 | hail-framework/framework | src/Database/Model.php | Model.insert | public function insert()
{
if (\count($this->dirty) === 0) {
return true;
}
$this->defaultTable();
$this->sql['VALUES'] = $this->dirty;
if ($return = DB::insert($this->sql)) {
$this->__set($this->primary, $return);
return $this->dirty()->reset();
}
return false;
} | php | public function insert()
{
if (\count($this->dirty) === 0) {
return true;
}
$this->defaultTable();
$this->sql['VALUES'] = $this->dirty;
if ($return = DB::insert($this->sql)) {
$this->__set($this->primary, $return);
return $this->dirty()->reset();
}
return false;
} | [
"public",
"function",
"insert",
"(",
")",
"{",
"if",
"(",
"\\",
"count",
"(",
"$",
"this",
"->",
"dirty",
")",
"===",
"0",
")",
"{",
"return",
"true",
";",
"}",
"$",
"this",
"->",
"defaultTable",
"(",
")",
";",
"$",
"this",
"->",
"sql",
"[",
"'VALUES'",
"]",
"=",
"$",
"this",
"->",
"dirty",
";",
"if",
"(",
"$",
"return",
"=",
"DB",
"::",
"insert",
"(",
"$",
"this",
"->",
"sql",
")",
")",
"{",
"$",
"this",
"->",
"__set",
"(",
"$",
"this",
"->",
"primary",
",",
"$",
"return",
")",
";",
"return",
"$",
"this",
"->",
"dirty",
"(",
")",
"->",
"reset",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] | function to build insert SQL, and insert current record into database.
@return bool|self if insert success return current object, other wise return false. | [
"function",
"to",
"build",
"insert",
"SQL",
"and",
"insert",
"current",
"record",
"into",
"database",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Model.php#L254-L270 |
35,416 | hail-framework/framework | src/Database/Model.php | Model.addWhere | public function addWhere($field, $value, $op = 'AND')
{
if (!isset($this->sql['WHERE'])) {
$this->sql['WHERE'] = [];
}
if (isset($this->sql['WHERE'][$op])) {
$this->sql['WHERE'][$op][$field] = $value;
} else {
$this->sql['WHERE'][$field] = $value;
$this->sql['WHERE'][$op] = $this->sql['WHERE'];
}
} | php | public function addWhere($field, $value, $op = 'AND')
{
if (!isset($this->sql['WHERE'])) {
$this->sql['WHERE'] = [];
}
if (isset($this->sql['WHERE'][$op])) {
$this->sql['WHERE'][$op][$field] = $value;
} else {
$this->sql['WHERE'][$field] = $value;
$this->sql['WHERE'][$op] = $this->sql['WHERE'];
}
} | [
"public",
"function",
"addWhere",
"(",
"$",
"field",
",",
"$",
"value",
",",
"$",
"op",
"=",
"'AND'",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"sql",
"[",
"'WHERE'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"sql",
"[",
"'WHERE'",
"]",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"sql",
"[",
"'WHERE'",
"]",
"[",
"$",
"op",
"]",
")",
")",
"{",
"$",
"this",
"->",
"sql",
"[",
"'WHERE'",
"]",
"[",
"$",
"op",
"]",
"[",
"$",
"field",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"sql",
"[",
"'WHERE'",
"]",
"[",
"$",
"field",
"]",
"=",
"$",
"value",
";",
"$",
"this",
"->",
"sql",
"[",
"'WHERE'",
"]",
"[",
"$",
"op",
"]",
"=",
"$",
"this",
"->",
"sql",
"[",
"'WHERE'",
"]",
";",
"}",
"}"
] | helper function to add condition into WHERE.
create the SQL Expressions.
@param string $field The field name, the source of Expressions
@param mixed $value the target of the Expressions
@param string $op the operator to concat this Expressions into WHERE or SET statment. | [
"helper",
"function",
"to",
"add",
"condition",
"into",
"WHERE",
".",
"create",
"the",
"SQL",
"Expressions",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Model.php#L383-L395 |
35,417 | DoSomething/gateway | src/Northstar.php | Northstar.getUser | public function getUser($type, $id)
{
$response = $this->get('v1/users/'.$type.'/'.$id);
if (is_null($response)) {
return null;
}
return new NorthstarUser($response['data']);
} | php | public function getUser($type, $id)
{
$response = $this->get('v1/users/'.$type.'/'.$id);
if (is_null($response)) {
return null;
}
return new NorthstarUser($response['data']);
} | [
"public",
"function",
"getUser",
"(",
"$",
"type",
",",
"$",
"id",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"get",
"(",
"'v1/users/'",
".",
"$",
"type",
".",
"'/'",
".",
"$",
"id",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"response",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"new",
"NorthstarUser",
"(",
"$",
"response",
"[",
"'data'",
"]",
")",
";",
"}"
] | Send a GET request to return a user with that id.
@param string $type - 'id', 'email', 'mobile'
@param string $id - ID, email, id, phone
@return NorthstarUser | [
"Send",
"a",
"GET",
"request",
"to",
"return",
"a",
"user",
"with",
"that",
"id",
"."
] | 89c1c59c6af038dff790df6d5aaa9fc703246568 | https://github.com/DoSomething/gateway/blob/89c1c59c6af038dff790df6d5aaa9fc703246568/src/Northstar.php#L57-L66 |
35,418 | DoSomething/gateway | src/Northstar.php | Northstar.updateUser | public function updateUser($id, $input)
{
$response = $this->put('v1/users/_id/'.$id, $input);
return new NorthstarUser($response['data']);
} | php | public function updateUser($id, $input)
{
$response = $this->put('v1/users/_id/'.$id, $input);
return new NorthstarUser($response['data']);
} | [
"public",
"function",
"updateUser",
"(",
"$",
"id",
",",
"$",
"input",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"put",
"(",
"'v1/users/_id/'",
".",
"$",
"id",
",",
"$",
"input",
")",
";",
"return",
"new",
"NorthstarUser",
"(",
"$",
"response",
"[",
"'data'",
"]",
")",
";",
"}"
] | Send a PUT request to update a user in Northstar.
@param string $id - Northstar User ID
@param array $input - Fields to update in profile
@return mixed | [
"Send",
"a",
"PUT",
"request",
"to",
"update",
"a",
"user",
"in",
"Northstar",
"."
] | 89c1c59c6af038dff790df6d5aaa9fc703246568 | https://github.com/DoSomething/gateway/blob/89c1c59c6af038dff790df6d5aaa9fc703246568/src/Northstar.php#L89-L94 |
35,419 | DoSomething/gateway | src/Northstar.php | Northstar.mergeUsers | public function mergeUsers($id, $duplicateId, $pretend = false)
{
$pretendParam = $pretend ? '?pretend=true' : null;
$response = $this->post('v1/users/'.$id.'/merge'.$pretendParam, ['id' => $duplicateId]);
return new NorthstarUser($response['data']);
} | php | public function mergeUsers($id, $duplicateId, $pretend = false)
{
$pretendParam = $pretend ? '?pretend=true' : null;
$response = $this->post('v1/users/'.$id.'/merge'.$pretendParam, ['id' => $duplicateId]);
return new NorthstarUser($response['data']);
} | [
"public",
"function",
"mergeUsers",
"(",
"$",
"id",
",",
"$",
"duplicateId",
",",
"$",
"pretend",
"=",
"false",
")",
"{",
"$",
"pretendParam",
"=",
"$",
"pretend",
"?",
"'?pretend=true'",
":",
"null",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"post",
"(",
"'v1/users/'",
".",
"$",
"id",
".",
"'/merge'",
".",
"$",
"pretendParam",
",",
"[",
"'id'",
"=>",
"$",
"duplicateId",
"]",
")",
";",
"return",
"new",
"NorthstarUser",
"(",
"$",
"response",
"[",
"'data'",
"]",
")",
";",
"}"
] | Send a POST request to merge two users in Northstar.
@param string $id - Northstar User ID.
@param string $duplicateId - Northstar User ID of duplicate user.
@param bool $pretend - Whether to persist the merge or not.
@return mixed | [
"Send",
"a",
"POST",
"request",
"to",
"merge",
"two",
"users",
"in",
"Northstar",
"."
] | 89c1c59c6af038dff790df6d5aaa9fc703246568 | https://github.com/DoSomething/gateway/blob/89c1c59c6af038dff790df6d5aaa9fc703246568/src/Northstar.php#L118-L125 |
35,420 | DoSomething/gateway | src/Northstar.php | Northstar.updateClient | public function updateClient($client_id, $input)
{
$response = $this->put('v2/clients/'.$client_id, $input);
return new NorthstarClient($response['data']);
} | php | public function updateClient($client_id, $input)
{
$response = $this->put('v2/clients/'.$client_id, $input);
return new NorthstarClient($response['data']);
} | [
"public",
"function",
"updateClient",
"(",
"$",
"client_id",
",",
"$",
"input",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"put",
"(",
"'v2/clients/'",
".",
"$",
"client_id",
",",
"$",
"input",
")",
";",
"return",
"new",
"NorthstarClient",
"(",
"$",
"response",
"[",
"'data'",
"]",
")",
";",
"}"
] | Send a POST request to generate new keys to northstar
Requires an `admin` scoped API key.
@param string $client_id - API key
@param array $input - key values
@return NorthstarClient | [
"Send",
"a",
"POST",
"request",
"to",
"generate",
"new",
"keys",
"to",
"northstar",
"Requires",
"an",
"admin",
"scoped",
"API",
"key",
"."
] | 89c1c59c6af038dff790df6d5aaa9fc703246568 | https://github.com/DoSomething/gateway/blob/89c1c59c6af038dff790df6d5aaa9fc703246568/src/Northstar.php#L189-L194 |
35,421 | hail-framework/framework | src/Http/Client/AbstractCurl.php | AbstractCurl.createHandle | protected function createHandle()
{
$curl = $this->handles ? \array_pop($this->handles) : \curl_init();
if (false === $curl) {
throw new ClientException('Unable to create a new cURL handle');
}
return $curl;
} | php | protected function createHandle()
{
$curl = $this->handles ? \array_pop($this->handles) : \curl_init();
if (false === $curl) {
throw new ClientException('Unable to create a new cURL handle');
}
return $curl;
} | [
"protected",
"function",
"createHandle",
"(",
")",
"{",
"$",
"curl",
"=",
"$",
"this",
"->",
"handles",
"?",
"\\",
"array_pop",
"(",
"$",
"this",
"->",
"handles",
")",
":",
"\\",
"curl_init",
"(",
")",
";",
"if",
"(",
"false",
"===",
"$",
"curl",
")",
"{",
"throw",
"new",
"ClientException",
"(",
"'Unable to create a new cURL handle'",
")",
";",
"}",
"return",
"$",
"curl",
";",
"}"
] | Creates a new cURL resource.
@return resource A new cURL resource
@throws ClientException If unable to create a cURL resource | [
"Creates",
"a",
"new",
"cURL",
"resource",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Http/Client/AbstractCurl.php#L38-L46 |
35,422 | hail-framework/framework | src/Http/Client/AbstractCurl.php | AbstractCurl.prepare | protected function prepare($curl, RequestInterface $request, array $options): ResponseInterface
{
if (\defined('CURLOPT_PROTOCOLS')) {
\curl_setopt($curl, \CURLOPT_PROTOCOLS, \CURLPROTO_HTTP | \CURLPROTO_HTTPS);
\curl_setopt($curl, \CURLOPT_REDIR_PROTOCOLS, \CURLPROTO_HTTP | \CURLPROTO_HTTPS);
}
\curl_setopt($curl, \CURLOPT_HEADER, false);
\curl_setopt($curl, \CURLOPT_RETURNTRANSFER, false);
\curl_setopt($curl, \CURLOPT_FAILONERROR, false);
$this->setOptionsFromParameter($curl, $options);
$this->setOptionsFromRequest($curl, $request);
$response = Factory::response();
\curl_setopt($curl, \CURLOPT_HEADERFUNCTION, function ($ch, $data) use ($response) {
$str = \trim($data);
if ('' !== $str) {
if (0 === \stripos($str, 'http/')) {
$this->setStatus($response, $str);
} else {
$this->addHeader($response, $str);
}
}
return \strlen($data);
});
\curl_setopt($curl, \CURLOPT_WRITEFUNCTION, function ($ch, $data) use ($response) {
return $response->getBody()->write($data);
});
// apply additional options
if ($options['curl'] !== []) {
\curl_setopt_array($curl, $options['curl']);
}
return $response;
} | php | protected function prepare($curl, RequestInterface $request, array $options): ResponseInterface
{
if (\defined('CURLOPT_PROTOCOLS')) {
\curl_setopt($curl, \CURLOPT_PROTOCOLS, \CURLPROTO_HTTP | \CURLPROTO_HTTPS);
\curl_setopt($curl, \CURLOPT_REDIR_PROTOCOLS, \CURLPROTO_HTTP | \CURLPROTO_HTTPS);
}
\curl_setopt($curl, \CURLOPT_HEADER, false);
\curl_setopt($curl, \CURLOPT_RETURNTRANSFER, false);
\curl_setopt($curl, \CURLOPT_FAILONERROR, false);
$this->setOptionsFromParameter($curl, $options);
$this->setOptionsFromRequest($curl, $request);
$response = Factory::response();
\curl_setopt($curl, \CURLOPT_HEADERFUNCTION, function ($ch, $data) use ($response) {
$str = \trim($data);
if ('' !== $str) {
if (0 === \stripos($str, 'http/')) {
$this->setStatus($response, $str);
} else {
$this->addHeader($response, $str);
}
}
return \strlen($data);
});
\curl_setopt($curl, \CURLOPT_WRITEFUNCTION, function ($ch, $data) use ($response) {
return $response->getBody()->write($data);
});
// apply additional options
if ($options['curl'] !== []) {
\curl_setopt_array($curl, $options['curl']);
}
return $response;
} | [
"protected",
"function",
"prepare",
"(",
"$",
"curl",
",",
"RequestInterface",
"$",
"request",
",",
"array",
"$",
"options",
")",
":",
"ResponseInterface",
"{",
"if",
"(",
"\\",
"defined",
"(",
"'CURLOPT_PROTOCOLS'",
")",
")",
"{",
"\\",
"curl_setopt",
"(",
"$",
"curl",
",",
"\\",
"CURLOPT_PROTOCOLS",
",",
"\\",
"CURLPROTO_HTTP",
"|",
"\\",
"CURLPROTO_HTTPS",
")",
";",
"\\",
"curl_setopt",
"(",
"$",
"curl",
",",
"\\",
"CURLOPT_REDIR_PROTOCOLS",
",",
"\\",
"CURLPROTO_HTTP",
"|",
"\\",
"CURLPROTO_HTTPS",
")",
";",
"}",
"\\",
"curl_setopt",
"(",
"$",
"curl",
",",
"\\",
"CURLOPT_HEADER",
",",
"false",
")",
";",
"\\",
"curl_setopt",
"(",
"$",
"curl",
",",
"\\",
"CURLOPT_RETURNTRANSFER",
",",
"false",
")",
";",
"\\",
"curl_setopt",
"(",
"$",
"curl",
",",
"\\",
"CURLOPT_FAILONERROR",
",",
"false",
")",
";",
"$",
"this",
"->",
"setOptionsFromParameter",
"(",
"$",
"curl",
",",
"$",
"options",
")",
";",
"$",
"this",
"->",
"setOptionsFromRequest",
"(",
"$",
"curl",
",",
"$",
"request",
")",
";",
"$",
"response",
"=",
"Factory",
"::",
"response",
"(",
")",
";",
"\\",
"curl_setopt",
"(",
"$",
"curl",
",",
"\\",
"CURLOPT_HEADERFUNCTION",
",",
"function",
"(",
"$",
"ch",
",",
"$",
"data",
")",
"use",
"(",
"$",
"response",
")",
"{",
"$",
"str",
"=",
"\\",
"trim",
"(",
"$",
"data",
")",
";",
"if",
"(",
"''",
"!==",
"$",
"str",
")",
"{",
"if",
"(",
"0",
"===",
"\\",
"stripos",
"(",
"$",
"str",
",",
"'http/'",
")",
")",
"{",
"$",
"this",
"->",
"setStatus",
"(",
"$",
"response",
",",
"$",
"str",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"addHeader",
"(",
"$",
"response",
",",
"$",
"str",
")",
";",
"}",
"}",
"return",
"\\",
"strlen",
"(",
"$",
"data",
")",
";",
"}",
")",
";",
"\\",
"curl_setopt",
"(",
"$",
"curl",
",",
"\\",
"CURLOPT_WRITEFUNCTION",
",",
"function",
"(",
"$",
"ch",
",",
"$",
"data",
")",
"use",
"(",
"$",
"response",
")",
"{",
"return",
"$",
"response",
"->",
"getBody",
"(",
")",
"->",
"write",
"(",
"$",
"data",
")",
";",
"}",
")",
";",
"// apply additional options\r",
"if",
"(",
"$",
"options",
"[",
"'curl'",
"]",
"!==",
"[",
"]",
")",
"{",
"\\",
"curl_setopt_array",
"(",
"$",
"curl",
",",
"$",
"options",
"[",
"'curl'",
"]",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | Prepares a cURL resource to send a request.
@param resource $curl
@param RequestInterface $request
@param array $options
@return ResponseInterface | [
"Prepares",
"a",
"cURL",
"resource",
"to",
"send",
"a",
"request",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Http/Client/AbstractCurl.php#L83-L121 |
35,423 | hiqdev/hipanel-module-server | src/controllers/ServerController.php | ServerController.getVNCInfo | public function getVNCInfo($model, $enable = false)
{
if ($enable) {
try {
$vnc = Server::perform('enable-VNC', ['id' => $model->id]);
$vnc['endTime'] = time() + 28800;
Yii::$app->cache->set([__METHOD__, $model->id, $model], $vnc, 28800);
$vnc['enabled'] = true;
} catch (ResponseErrorException $e) {
if ($e->getMessage() !== 'vds_has_tasks') {
throw $e;
}
}
} else {
if ($model->statuses['serverEnableVNC'] !== null && strtotime('+8 hours', strtotime($model->statuses['serverEnableVNC'])) > time()) {
$vnc = Yii::$app->cache->getOrSet([__METHOD__, $model->id, $model], function () use ($model) {
return ArrayHelper::merge([
'endTime' => strtotime($model->statuses['serverEnableVNC']) + 28800,
], Server::perform('enable-VNC', ['id' => $model->id]));
}, 28800);
}
$vnc['enabled'] = $model->statuses['serverEnableVNC'] === null ? false : strtotime('+8 hours', strtotime($model->statuses['serverEnableVNC'])) > time();
}
return $vnc;
} | php | public function getVNCInfo($model, $enable = false)
{
if ($enable) {
try {
$vnc = Server::perform('enable-VNC', ['id' => $model->id]);
$vnc['endTime'] = time() + 28800;
Yii::$app->cache->set([__METHOD__, $model->id, $model], $vnc, 28800);
$vnc['enabled'] = true;
} catch (ResponseErrorException $e) {
if ($e->getMessage() !== 'vds_has_tasks') {
throw $e;
}
}
} else {
if ($model->statuses['serverEnableVNC'] !== null && strtotime('+8 hours', strtotime($model->statuses['serverEnableVNC'])) > time()) {
$vnc = Yii::$app->cache->getOrSet([__METHOD__, $model->id, $model], function () use ($model) {
return ArrayHelper::merge([
'endTime' => strtotime($model->statuses['serverEnableVNC']) + 28800,
], Server::perform('enable-VNC', ['id' => $model->id]));
}, 28800);
}
$vnc['enabled'] = $model->statuses['serverEnableVNC'] === null ? false : strtotime('+8 hours', strtotime($model->statuses['serverEnableVNC'])) > time();
}
return $vnc;
} | [
"public",
"function",
"getVNCInfo",
"(",
"$",
"model",
",",
"$",
"enable",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"enable",
")",
"{",
"try",
"{",
"$",
"vnc",
"=",
"Server",
"::",
"perform",
"(",
"'enable-VNC'",
",",
"[",
"'id'",
"=>",
"$",
"model",
"->",
"id",
"]",
")",
";",
"$",
"vnc",
"[",
"'endTime'",
"]",
"=",
"time",
"(",
")",
"+",
"28800",
";",
"Yii",
"::",
"$",
"app",
"->",
"cache",
"->",
"set",
"(",
"[",
"__METHOD__",
",",
"$",
"model",
"->",
"id",
",",
"$",
"model",
"]",
",",
"$",
"vnc",
",",
"28800",
")",
";",
"$",
"vnc",
"[",
"'enabled'",
"]",
"=",
"true",
";",
"}",
"catch",
"(",
"ResponseErrorException",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
"!==",
"'vds_has_tasks'",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"model",
"->",
"statuses",
"[",
"'serverEnableVNC'",
"]",
"!==",
"null",
"&&",
"strtotime",
"(",
"'+8 hours'",
",",
"strtotime",
"(",
"$",
"model",
"->",
"statuses",
"[",
"'serverEnableVNC'",
"]",
")",
")",
">",
"time",
"(",
")",
")",
"{",
"$",
"vnc",
"=",
"Yii",
"::",
"$",
"app",
"->",
"cache",
"->",
"getOrSet",
"(",
"[",
"__METHOD__",
",",
"$",
"model",
"->",
"id",
",",
"$",
"model",
"]",
",",
"function",
"(",
")",
"use",
"(",
"$",
"model",
")",
"{",
"return",
"ArrayHelper",
"::",
"merge",
"(",
"[",
"'endTime'",
"=>",
"strtotime",
"(",
"$",
"model",
"->",
"statuses",
"[",
"'serverEnableVNC'",
"]",
")",
"+",
"28800",
",",
"]",
",",
"Server",
"::",
"perform",
"(",
"'enable-VNC'",
",",
"[",
"'id'",
"=>",
"$",
"model",
"->",
"id",
"]",
")",
")",
";",
"}",
",",
"28800",
")",
";",
"}",
"$",
"vnc",
"[",
"'enabled'",
"]",
"=",
"$",
"model",
"->",
"statuses",
"[",
"'serverEnableVNC'",
"]",
"===",
"null",
"?",
"false",
":",
"strtotime",
"(",
"'+8 hours'",
",",
"strtotime",
"(",
"$",
"model",
"->",
"statuses",
"[",
"'serverEnableVNC'",
"]",
")",
")",
">",
"time",
"(",
")",
";",
"}",
"return",
"$",
"vnc",
";",
"}"
] | Gets info of VNC on the server.
@param Server $model
@param bool $enable
@throws ResponseErrorException
@return array | [
"Gets",
"info",
"of",
"VNC",
"on",
"the",
"server",
"."
] | e40c3601952cf1fd420ebb97093ee17a33ff3207 | https://github.com/hiqdev/hipanel-module-server/blob/e40c3601952cf1fd420ebb97093ee17a33ff3207/src/controllers/ServerController.php#L829-L854 |
35,424 | hiqdev/hipanel-module-server | src/controllers/ServerController.php | ServerController.getOsimages | protected function getOsimages(Server $model = null)
{
if ($model !== null) {
$type = $model->type;
} else {
$type = null;
}
$models = ServerHelper::getOsimages($type);
if ($models === null) {
throw new NotFoundHttpException('The requested page does not exist.');
}
return $models;
} | php | protected function getOsimages(Server $model = null)
{
if ($model !== null) {
$type = $model->type;
} else {
$type = null;
}
$models = ServerHelper::getOsimages($type);
if ($models === null) {
throw new NotFoundHttpException('The requested page does not exist.');
}
return $models;
} | [
"protected",
"function",
"getOsimages",
"(",
"Server",
"$",
"model",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"model",
"!==",
"null",
")",
"{",
"$",
"type",
"=",
"$",
"model",
"->",
"type",
";",
"}",
"else",
"{",
"$",
"type",
"=",
"null",
";",
"}",
"$",
"models",
"=",
"ServerHelper",
"::",
"getOsimages",
"(",
"$",
"type",
")",
";",
"if",
"(",
"$",
"models",
"===",
"null",
")",
"{",
"throw",
"new",
"NotFoundHttpException",
"(",
"'The requested page does not exist.'",
")",
";",
"}",
"return",
"$",
"models",
";",
"}"
] | Gets OS images.
@param Server $model
@throws NotFoundHttpException
@return array | [
"Gets",
"OS",
"images",
"."
] | e40c3601952cf1fd420ebb97093ee17a33ff3207 | https://github.com/hiqdev/hipanel-module-server/blob/e40c3601952cf1fd420ebb97093ee17a33ff3207/src/controllers/ServerController.php#L887-L902 |
35,425 | hail-framework/framework | src/Http/Cookie.php | Cookie.getExpiresTime | private function getExpiresTime($time): int
{
if ($time instanceof \DateTimeInterface) {
return (int) $time->format('U');
}
if (\is_numeric($time)) {
// average year in seconds
if ($time <= 31557600) {
$time += \time();
}
return (int) $time;
}
return (int) (new \DateTime($time))->format('U');
} | php | private function getExpiresTime($time): int
{
if ($time instanceof \DateTimeInterface) {
return (int) $time->format('U');
}
if (\is_numeric($time)) {
// average year in seconds
if ($time <= 31557600) {
$time += \time();
}
return (int) $time;
}
return (int) (new \DateTime($time))->format('U');
} | [
"private",
"function",
"getExpiresTime",
"(",
"$",
"time",
")",
":",
"int",
"{",
"if",
"(",
"$",
"time",
"instanceof",
"\\",
"DateTimeInterface",
")",
"{",
"return",
"(",
"int",
")",
"$",
"time",
"->",
"format",
"(",
"'U'",
")",
";",
"}",
"if",
"(",
"\\",
"is_numeric",
"(",
"$",
"time",
")",
")",
"{",
"// average year in seconds",
"if",
"(",
"$",
"time",
"<=",
"31557600",
")",
"{",
"$",
"time",
"+=",
"\\",
"time",
"(",
")",
";",
"}",
"return",
"(",
"int",
")",
"$",
"time",
";",
"}",
"return",
"(",
"int",
")",
"(",
"new",
"\\",
"DateTime",
"(",
"$",
"time",
")",
")",
"->",
"format",
"(",
"'U'",
")",
";",
"}"
] | Convert to unix timestamp
@param string|int|\DateTimeInterface $time
@return int | [
"Convert",
"to",
"unix",
"timestamp"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Http/Cookie.php#L188-L204 |
35,426 | hail-framework/framework | src/Container/Container.php | Container.get | public function get($name)
{
switch (true) {
case isset($this->active[$name]):
return $this->values[$name];
case isset($this->values[$name]):
break;
case \array_key_exists($name, $this->values):
break;
case isset($this->alias[$name]):
$this->active[$name] = true;
return $this->values[$name] = $this->get($this->alias[$name]);
case isset($this->factory[$name]):
$factory = $this->factory[$name];
if (\is_string($factory) && \class_exists($factory)) {
$this->values[$name] = $this->create($factory, $this->factoryMap[$name]);
} else {
$this->values[$name] = $this->call($factory, $this->factoryMap[$name]);
}
break;
case \class_exists($name):
return $this->build($name);
default:
throw new NotFoundException($name);
}
$this->active[$name] = true;
if (null !== $configures = $this->getConfigure($name)) {
foreach ($configures as $index => $config) {
$value = $this->call($config, $this->configMap[$name][$index]);
if ($value !== null) {
$this->values[$name] = $value;
}
}
}
return $this->values[$name];
} | php | public function get($name)
{
switch (true) {
case isset($this->active[$name]):
return $this->values[$name];
case isset($this->values[$name]):
break;
case \array_key_exists($name, $this->values):
break;
case isset($this->alias[$name]):
$this->active[$name] = true;
return $this->values[$name] = $this->get($this->alias[$name]);
case isset($this->factory[$name]):
$factory = $this->factory[$name];
if (\is_string($factory) && \class_exists($factory)) {
$this->values[$name] = $this->create($factory, $this->factoryMap[$name]);
} else {
$this->values[$name] = $this->call($factory, $this->factoryMap[$name]);
}
break;
case \class_exists($name):
return $this->build($name);
default:
throw new NotFoundException($name);
}
$this->active[$name] = true;
if (null !== $configures = $this->getConfigure($name)) {
foreach ($configures as $index => $config) {
$value = $this->call($config, $this->configMap[$name][$index]);
if ($value !== null) {
$this->values[$name] = $value;
}
}
}
return $this->values[$name];
} | [
"public",
"function",
"get",
"(",
"$",
"name",
")",
"{",
"switch",
"(",
"true",
")",
"{",
"case",
"isset",
"(",
"$",
"this",
"->",
"active",
"[",
"$",
"name",
"]",
")",
":",
"return",
"$",
"this",
"->",
"values",
"[",
"$",
"name",
"]",
";",
"case",
"isset",
"(",
"$",
"this",
"->",
"values",
"[",
"$",
"name",
"]",
")",
":",
"break",
";",
"case",
"\\",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"values",
")",
":",
"break",
";",
"case",
"isset",
"(",
"$",
"this",
"->",
"alias",
"[",
"$",
"name",
"]",
")",
":",
"$",
"this",
"->",
"active",
"[",
"$",
"name",
"]",
"=",
"true",
";",
"return",
"$",
"this",
"->",
"values",
"[",
"$",
"name",
"]",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"this",
"->",
"alias",
"[",
"$",
"name",
"]",
")",
";",
"case",
"isset",
"(",
"$",
"this",
"->",
"factory",
"[",
"$",
"name",
"]",
")",
":",
"$",
"factory",
"=",
"$",
"this",
"->",
"factory",
"[",
"$",
"name",
"]",
";",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"factory",
")",
"&&",
"\\",
"class_exists",
"(",
"$",
"factory",
")",
")",
"{",
"$",
"this",
"->",
"values",
"[",
"$",
"name",
"]",
"=",
"$",
"this",
"->",
"create",
"(",
"$",
"factory",
",",
"$",
"this",
"->",
"factoryMap",
"[",
"$",
"name",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"values",
"[",
"$",
"name",
"]",
"=",
"$",
"this",
"->",
"call",
"(",
"$",
"factory",
",",
"$",
"this",
"->",
"factoryMap",
"[",
"$",
"name",
"]",
")",
";",
"}",
"break",
";",
"case",
"\\",
"class_exists",
"(",
"$",
"name",
")",
":",
"return",
"$",
"this",
"->",
"build",
"(",
"$",
"name",
")",
";",
"default",
":",
"throw",
"new",
"NotFoundException",
"(",
"$",
"name",
")",
";",
"}",
"$",
"this",
"->",
"active",
"[",
"$",
"name",
"]",
"=",
"true",
";",
"if",
"(",
"null",
"!==",
"$",
"configures",
"=",
"$",
"this",
"->",
"getConfigure",
"(",
"$",
"name",
")",
")",
"{",
"foreach",
"(",
"$",
"configures",
"as",
"$",
"index",
"=>",
"$",
"config",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"call",
"(",
"$",
"config",
",",
"$",
"this",
"->",
"configMap",
"[",
"$",
"name",
"]",
"[",
"$",
"index",
"]",
")",
";",
"if",
"(",
"$",
"value",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"values",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}",
"return",
"$",
"this",
"->",
"values",
"[",
"$",
"name",
"]",
";",
"}"
] | Resolve the registered component with the given name.
@param string $name component name
@return mixed
@throws NotFoundException
@throws InvalidArgumentException | [
"Resolve",
"the",
"registered",
"component",
"with",
"the",
"given",
"name",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Container/Container.php#L90-L138 |
35,427 | hail-framework/framework | src/Container/Container.php | Container.has | public function has($name): bool
{
return isset($this->values[$name]) ||
isset($this->factory[$name]) ||
isset($this->alias[$name]) ||
\array_key_exists($name, $this->values);
} | php | public function has($name): bool
{
return isset($this->values[$name]) ||
isset($this->factory[$name]) ||
isset($this->alias[$name]) ||
\array_key_exists($name, $this->values);
} | [
"public",
"function",
"has",
"(",
"$",
"name",
")",
":",
"bool",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"values",
"[",
"$",
"name",
"]",
")",
"||",
"isset",
"(",
"$",
"this",
"->",
"factory",
"[",
"$",
"name",
"]",
")",
"||",
"isset",
"(",
"$",
"this",
"->",
"alias",
"[",
"$",
"name",
"]",
")",
"||",
"\\",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"values",
")",
";",
"}"
] | Check for the existence of a component with a given name.
@param string $name component name
@return bool true, if a component with the given name has been defined | [
"Check",
"for",
"the",
"existence",
"of",
"a",
"component",
"with",
"a",
"given",
"name",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Container/Container.php#L148-L154 |
35,428 | hail-framework/framework | src/Container/Container.php | Container.inject | public function inject(string $name, $value): void
{
if ($this->has($name)) {
throw new InvalidArgumentException("Attempted override of existing component: {$name}");
}
$this->values[$name] = $value;
$this->active[$name] = true;
} | php | public function inject(string $name, $value): void
{
if ($this->has($name)) {
throw new InvalidArgumentException("Attempted override of existing component: {$name}");
}
$this->values[$name] = $value;
$this->active[$name] = true;
} | [
"public",
"function",
"inject",
"(",
"string",
"$",
"name",
",",
"$",
"value",
")",
":",
"void",
"{",
"if",
"(",
"$",
"this",
"->",
"has",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Attempted override of existing component: {$name}\"",
")",
";",
"}",
"$",
"this",
"->",
"values",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"$",
"this",
"->",
"active",
"[",
"$",
"name",
"]",
"=",
"true",
";",
"}"
] | Dynamically inject a component into this Container.
Enables implementation of "auto-wiring" patterns, where missing components are injected
at run-time into a live `Container` instance.
You should always test with {@see has()} prior to injecting a component - attempting to
override an existing component will generate an exception.
@throws InvalidArgumentException if the specified component has already been defined
@param string $name component name
@param mixed $value | [
"Dynamically",
"inject",
"a",
"component",
"into",
"this",
"Container",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Container/Container.php#L211-L219 |
35,429 | hail-framework/framework | src/Container/Container.php | Container.register | public function register(string $name, $define = null, array $map = []): void
{
if (isset($this->active[$name])) {
throw new InvalidArgumentException("Attempted override of existing component: {$name}");
}
if ($define instanceof \Closure) {
$func = $define;
} elseif (\is_callable($define)) {
// second argument is a creation function
$func = \Closure::fromCallable($define);
} elseif (\is_string($define)) {
// second argument is a class-name
$func = $define;
} elseif (\is_array($define)) {
$func = $name;
$map = $define;
} elseif (null === $define) {
// first argument is both the component and class-name
$func = $name;
$map = [];
} else {
throw new InvalidArgumentException('Unexpected argument type for $define: ' . \gettype($define));
}
$this->factory[$name] = $func;
$this->factoryMap[$name] = $map;
unset($this->values[$name]);
} | php | public function register(string $name, $define = null, array $map = []): void
{
if (isset($this->active[$name])) {
throw new InvalidArgumentException("Attempted override of existing component: {$name}");
}
if ($define instanceof \Closure) {
$func = $define;
} elseif (\is_callable($define)) {
// second argument is a creation function
$func = \Closure::fromCallable($define);
} elseif (\is_string($define)) {
// second argument is a class-name
$func = $define;
} elseif (\is_array($define)) {
$func = $name;
$map = $define;
} elseif (null === $define) {
// first argument is both the component and class-name
$func = $name;
$map = [];
} else {
throw new InvalidArgumentException('Unexpected argument type for $define: ' . \gettype($define));
}
$this->factory[$name] = $func;
$this->factoryMap[$name] = $map;
unset($this->values[$name]);
} | [
"public",
"function",
"register",
"(",
"string",
"$",
"name",
",",
"$",
"define",
"=",
"null",
",",
"array",
"$",
"map",
"=",
"[",
"]",
")",
":",
"void",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"active",
"[",
"$",
"name",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Attempted override of existing component: {$name}\"",
")",
";",
"}",
"if",
"(",
"$",
"define",
"instanceof",
"\\",
"Closure",
")",
"{",
"$",
"func",
"=",
"$",
"define",
";",
"}",
"elseif",
"(",
"\\",
"is_callable",
"(",
"$",
"define",
")",
")",
"{",
"// second argument is a creation function",
"$",
"func",
"=",
"\\",
"Closure",
"::",
"fromCallable",
"(",
"$",
"define",
")",
";",
"}",
"elseif",
"(",
"\\",
"is_string",
"(",
"$",
"define",
")",
")",
"{",
"// second argument is a class-name",
"$",
"func",
"=",
"$",
"define",
";",
"}",
"elseif",
"(",
"\\",
"is_array",
"(",
"$",
"define",
")",
")",
"{",
"$",
"func",
"=",
"$",
"name",
";",
"$",
"map",
"=",
"$",
"define",
";",
"}",
"elseif",
"(",
"null",
"===",
"$",
"define",
")",
"{",
"// first argument is both the component and class-name",
"$",
"func",
"=",
"$",
"name",
";",
"$",
"map",
"=",
"[",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Unexpected argument type for $define: '",
".",
"\\",
"gettype",
"(",
"$",
"define",
")",
")",
";",
"}",
"$",
"this",
"->",
"factory",
"[",
"$",
"name",
"]",
"=",
"$",
"func",
";",
"$",
"this",
"->",
"factoryMap",
"[",
"$",
"name",
"]",
"=",
"$",
"map",
";",
"unset",
"(",
"$",
"this",
"->",
"values",
"[",
"$",
"name",
"]",
")",
";",
"}"
] | Register a component for dependency injection.
There are numerous valid ways to register components.
* `register(Foo::class)` registers a component by it's class-name, and will try to
automatically resolve all of it's constructor arguments.
* `register(Foo::class, ['bar'])` registers a component by it's class-name, and will
use `'bar'` as the first constructor argument, and try to resolve the rest.
* `register(Foo::class, [$container->ref(Bar::class)])` creates a boxed reference to
a registered component `Bar` and provides that as the first argument.
* `register(Foo::class, ['bat' => 'zap'])` registers a component by it's class-name
and will use `'zap'` for the constructor argument named `$bat`, and try to resolve
any other arguments.
* `register(Bar::class, Foo::class)` registers a component `Foo` under another name
`Bar`, which might be an interface or an abstract class.
* `register(Bar::class, Foo::class, ['bar'])` same as above, but uses `'bar'` as the
first argument.
* `register(Bar::class, Foo::class, ['bat' => 'zap'])` same as above, but, well, guess.
* `register(Bar::class, function (Foo $foo) { return new Bar(...); })` registers a
component with a custom creation function.
* `register(Bar::class, function ($name) { ... }, [$container->ref('db.name')]);`
registers a component creation function with a reference to a component "db.name"
as the first argument.
In effect, you can think of `$func` as being an optional argument.
The provided parameter values may include any `\Closure`, such as the boxed
component referenced created by {@see Container::ref()} - these will be unboxed as late
as possible.
@param string $name component name
@param callable|mixed|mixed[]|null $define creation function or class-name, or, if the first
argument is a class-name, a map of constructor arguments
@param array $map mixed list/map of parameter values (and/or boxed values)
@return void
@throws InvalidArgumentException | [
"Register",
"a",
"component",
"for",
"dependency",
"injection",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Container/Container.php#L294-L323 |
35,430 | hail-framework/framework | src/Container/Container.php | Container.set | public function set(string $name, $value): void
{
if (isset($this->active[$name])) {
throw new InvalidArgumentException("Attempted override of existing component: {$name}");
}
$this->values[$name] = $value;
unset(
$this->factory[$name],
$this->factoryMap[$name],
$this->alias[$name]
);
$this->removeAbstractAlias($name);
} | php | public function set(string $name, $value): void
{
if (isset($this->active[$name])) {
throw new InvalidArgumentException("Attempted override of existing component: {$name}");
}
$this->values[$name] = $value;
unset(
$this->factory[$name],
$this->factoryMap[$name],
$this->alias[$name]
);
$this->removeAbstractAlias($name);
} | [
"public",
"function",
"set",
"(",
"string",
"$",
"name",
",",
"$",
"value",
")",
":",
"void",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"active",
"[",
"$",
"name",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Attempted override of existing component: {$name}\"",
")",
";",
"}",
"$",
"this",
"->",
"values",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"unset",
"(",
"$",
"this",
"->",
"factory",
"[",
"$",
"name",
"]",
",",
"$",
"this",
"->",
"factoryMap",
"[",
"$",
"name",
"]",
",",
"$",
"this",
"->",
"alias",
"[",
"$",
"name",
"]",
")",
";",
"$",
"this",
"->",
"removeAbstractAlias",
"(",
"$",
"name",
")",
";",
"}"
] | Directly inject a component into the container - use this to register components that
have already been created for some reason; for example, the Composer ClassLoader.
@param string $name component name
@param mixed $value
@return void
@throws InvalidArgumentException | [
"Directly",
"inject",
"a",
"component",
"into",
"the",
"container",
"-",
"use",
"this",
"to",
"register",
"components",
"that",
"have",
"already",
"been",
"created",
"for",
"some",
"reason",
";",
"for",
"example",
"the",
"Composer",
"ClassLoader",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Container/Container.php#L336-L351 |
35,431 | hail-framework/framework | src/Container/Container.php | Container.alias | public function alias(string $alias, string $abstract): void
{
if (\array_key_exists($alias, $this->values) || isset($this->factory[$alias])) {
throw new InvalidArgumentException("Already defined in container: $alias");
}
if ($alias === $abstract) {
throw new InvalidArgumentException('Alias cannot be the same as the original name');
}
$this->alias[$alias] = $abstract;
if (!isset($this->abstractAlias[$abstract])) {
$this->abstractAlias[$abstract] = [];
}
$this->abstractAlias[$abstract][] = $alias;
} | php | public function alias(string $alias, string $abstract): void
{
if (\array_key_exists($alias, $this->values) || isset($this->factory[$alias])) {
throw new InvalidArgumentException("Already defined in container: $alias");
}
if ($alias === $abstract) {
throw new InvalidArgumentException('Alias cannot be the same as the original name');
}
$this->alias[$alias] = $abstract;
if (!isset($this->abstractAlias[$abstract])) {
$this->abstractAlias[$abstract] = [];
}
$this->abstractAlias[$abstract][] = $alias;
} | [
"public",
"function",
"alias",
"(",
"string",
"$",
"alias",
",",
"string",
"$",
"abstract",
")",
":",
"void",
"{",
"if",
"(",
"\\",
"array_key_exists",
"(",
"$",
"alias",
",",
"$",
"this",
"->",
"values",
")",
"||",
"isset",
"(",
"$",
"this",
"->",
"factory",
"[",
"$",
"alias",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Already defined in container: $alias\"",
")",
";",
"}",
"if",
"(",
"$",
"alias",
"===",
"$",
"abstract",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Alias cannot be the same as the original name'",
")",
";",
"}",
"$",
"this",
"->",
"alias",
"[",
"$",
"alias",
"]",
"=",
"$",
"abstract",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"abstractAlias",
"[",
"$",
"abstract",
"]",
")",
")",
"{",
"$",
"this",
"->",
"abstractAlias",
"[",
"$",
"abstract",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"abstractAlias",
"[",
"$",
"abstract",
"]",
"[",
"]",
"=",
"$",
"alias",
";",
"}"
] | Register a component as an alias of another registered component.
@param string $alias new component name
@param string $abstract referenced existing component name
@throws InvalidArgumentException | [
"Register",
"a",
"component",
"as",
"an",
"alias",
"of",
"another",
"registered",
"component",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Container/Container.php#L361-L378 |
35,432 | hail-framework/framework | src/Container/Container.php | Container.ref | public function ref(string $name)
{
if (isset($this->active[$name])) {
return $this->values[$name];
}
return function () use ($name) {
return $this->get($name);
};
} | php | public function ref(string $name)
{
if (isset($this->active[$name])) {
return $this->values[$name];
}
return function () use ($name) {
return $this->get($name);
};
} | [
"public",
"function",
"ref",
"(",
"string",
"$",
"name",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"active",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"values",
"[",
"$",
"name",
"]",
";",
"}",
"return",
"function",
"(",
")",
"use",
"(",
"$",
"name",
")",
"{",
"return",
"$",
"this",
"->",
"get",
"(",
"$",
"name",
")",
";",
"}",
";",
"}"
] | Creates a boxed reference to a component with a given name.
You can use this in conjunction with `register()` to provide a component reference
without expanding that reference until first use - for example:
$container->register(UserRepo::class, [$container->ref('cache')]);
This will reference the "cache" component and provide it as the first argument to the
constructor of `UserRepo` - compared with using `$container->get('cache')`, this has
the advantage of not actually activating the "cache" component until `UserRepo` is
used for the first time.
Another reason (besides performance) to use references, is to defer the reference:
$container->register(FileCache::class, ['root_path' => $container->ref('cache.path')]);
In this example, the component "cache.path" will be fetched from the container on
first use of `FileCache`, giving you a chance to configure "cache.path" later.
@param string $name component name
@return mixed|\Closure component reference | [
"Creates",
"a",
"boxed",
"reference",
"to",
"a",
"component",
"with",
"a",
"given",
"name",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Container/Container.php#L514-L523 |
35,433 | hail-framework/framework | src/Filesystem/Adapter/Polyfill/StreamedReadingTrait.php | StreamedReadingTrait.readStream | public function readStream($path)
{
if ( ! $data = $this->read($path)) {
return false;
}
$stream = \fopen('php://temp', 'w+b');
\fwrite($stream, $data['contents']);
\rewind($stream);
$data['stream'] = $stream;
unset($data['contents']);
return $data;
} | php | public function readStream($path)
{
if ( ! $data = $this->read($path)) {
return false;
}
$stream = \fopen('php://temp', 'w+b');
\fwrite($stream, $data['contents']);
\rewind($stream);
$data['stream'] = $stream;
unset($data['contents']);
return $data;
} | [
"public",
"function",
"readStream",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"$",
"data",
"=",
"$",
"this",
"->",
"read",
"(",
"$",
"path",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"stream",
"=",
"\\",
"fopen",
"(",
"'php://temp'",
",",
"'w+b'",
")",
";",
"\\",
"fwrite",
"(",
"$",
"stream",
",",
"$",
"data",
"[",
"'contents'",
"]",
")",
";",
"\\",
"rewind",
"(",
"$",
"stream",
")",
";",
"$",
"data",
"[",
"'stream'",
"]",
"=",
"$",
"stream",
";",
"unset",
"(",
"$",
"data",
"[",
"'contents'",
"]",
")",
";",
"return",
"$",
"data",
";",
"}"
] | Reads a file as a stream.
@param string $path
@return array|false
@see \Hail\Filesystem\ReadInterface::readStream() | [
"Reads",
"a",
"file",
"as",
"a",
"stream",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Filesystem/Adapter/Polyfill/StreamedReadingTrait.php#L19-L32 |
35,434 | hail-framework/framework | src/Filesystem/Adapter/AbstractFtpAdapter.php | AbstractFtpAdapter.sortListing | protected function sortListing(array $result)
{
$compare = function ($one, $two) {
return \strnatcmp($one['path'], $two['path']);
};
\usort($result, $compare);
return $result;
} | php | protected function sortListing(array $result)
{
$compare = function ($one, $two) {
return \strnatcmp($one['path'], $two['path']);
};
\usort($result, $compare);
return $result;
} | [
"protected",
"function",
"sortListing",
"(",
"array",
"$",
"result",
")",
"{",
"$",
"compare",
"=",
"function",
"(",
"$",
"one",
",",
"$",
"two",
")",
"{",
"return",
"\\",
"strnatcmp",
"(",
"$",
"one",
"[",
"'path'",
"]",
",",
"$",
"two",
"[",
"'path'",
"]",
")",
";",
"}",
";",
"\\",
"usort",
"(",
"$",
"result",
",",
"$",
"compare",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Sort a directory listing.
@param array $result
@return array sorted listing | [
"Sort",
"a",
"directory",
"listing",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Filesystem/Adapter/AbstractFtpAdapter.php#L324-L333 |
35,435 | jormin/aliyun | sdk/aliyun-mns-php-sdk/AliyunMNS/Http/HttpClient.php | HttpClient.parseEndpoint | private function parseEndpoint()
{
$pieces = explode("//", $this->endpoint);
$host = end($pieces);
$host_pieces = explode(".", $host);
$this->accountId = $host_pieces[0];
$region_pieces = explode("-internal", $host_pieces[2]);
$this->region = $region_pieces[0];
} | php | private function parseEndpoint()
{
$pieces = explode("//", $this->endpoint);
$host = end($pieces);
$host_pieces = explode(".", $host);
$this->accountId = $host_pieces[0];
$region_pieces = explode("-internal", $host_pieces[2]);
$this->region = $region_pieces[0];
} | [
"private",
"function",
"parseEndpoint",
"(",
")",
"{",
"$",
"pieces",
"=",
"explode",
"(",
"\"//\"",
",",
"$",
"this",
"->",
"endpoint",
")",
";",
"$",
"host",
"=",
"end",
"(",
"$",
"pieces",
")",
";",
"$",
"host_pieces",
"=",
"explode",
"(",
"\".\"",
",",
"$",
"host",
")",
";",
"$",
"this",
"->",
"accountId",
"=",
"$",
"host_pieces",
"[",
"0",
"]",
";",
"$",
"region_pieces",
"=",
"explode",
"(",
"\"-internal\"",
",",
"$",
"host_pieces",
"[",
"2",
"]",
")",
";",
"$",
"this",
"->",
"region",
"=",
"$",
"region_pieces",
"[",
"0",
"]",
";",
"}"
] | This function is for SDK internal use | [
"This",
"function",
"is",
"for",
"SDK",
"internal",
"use"
] | c0eb19f5c265dba1f463af1db7347acdcfddb240 | https://github.com/jormin/aliyun/blob/c0eb19f5c265dba1f463af1db7347acdcfddb240/sdk/aliyun-mns-php-sdk/AliyunMNS/Http/HttpClient.php#L64-L73 |
35,436 | Kajna/K-Core | Core/Auth/Auth.php | Auth.changePassword | public function changePassword($username, $newPass)
{
$password = $this->hasher->HashPassword($newPass);
return $this
->conn
->prepare(sprintf("UPDATE %s SET user_pass=:newPass WHERE user_name = :username", $this->table))
->execute(['newPass' => $password, 'username' => $username]);
} | php | public function changePassword($username, $newPass)
{
$password = $this->hasher->HashPassword($newPass);
return $this
->conn
->prepare(sprintf("UPDATE %s SET user_pass=:newPass WHERE user_name = :username", $this->table))
->execute(['newPass' => $password, 'username' => $username]);
} | [
"public",
"function",
"changePassword",
"(",
"$",
"username",
",",
"$",
"newPass",
")",
"{",
"$",
"password",
"=",
"$",
"this",
"->",
"hasher",
"->",
"HashPassword",
"(",
"$",
"newPass",
")",
";",
"return",
"$",
"this",
"->",
"conn",
"->",
"prepare",
"(",
"sprintf",
"(",
"\"UPDATE %s SET user_pass=:newPass WHERE user_name = :username\"",
",",
"$",
"this",
"->",
"table",
")",
")",
"->",
"execute",
"(",
"[",
"'newPass'",
"=>",
"$",
"password",
",",
"'username'",
"=>",
"$",
"username",
"]",
")",
";",
"}"
] | Change user password.
@param string $username
@param string $newPass
@return bool | [
"Change",
"user",
"password",
"."
] | 6a354056cf95e471b9b1eb372c5626123fd77df2 | https://github.com/Kajna/K-Core/blob/6a354056cf95e471b9b1eb372c5626123fd77df2/Core/Auth/Auth.php#L112-L119 |
35,437 | Kajna/K-Core | Core/Auth/Auth.php | Auth.login | public function login($username, $password)
{
$stmt = $this->conn->prepare(
sprintf("SELECT user_id, user_name, user_pass
FROM %s WHERE user_name = :name LIMIT 1", $this->table));
$stmt->execute(['name' => $username]);
$result = $stmt->fetch(\PDO::FETCH_ASSOC);
if ($result['user_name'] !== $username) {
return false;
}
if ($this->hasher->CheckPassword($password, $result['user_pass'])) {
// Clear previous session
$this->session->regenerate();
// Write new data to session
$data = [
'id' => $result['user_id'],
'logged_' . $this->table => true
];
$this->session->set('user', $data);
return true;
}
return false;
} | php | public function login($username, $password)
{
$stmt = $this->conn->prepare(
sprintf("SELECT user_id, user_name, user_pass
FROM %s WHERE user_name = :name LIMIT 1", $this->table));
$stmt->execute(['name' => $username]);
$result = $stmt->fetch(\PDO::FETCH_ASSOC);
if ($result['user_name'] !== $username) {
return false;
}
if ($this->hasher->CheckPassword($password, $result['user_pass'])) {
// Clear previous session
$this->session->regenerate();
// Write new data to session
$data = [
'id' => $result['user_id'],
'logged_' . $this->table => true
];
$this->session->set('user', $data);
return true;
}
return false;
} | [
"public",
"function",
"login",
"(",
"$",
"username",
",",
"$",
"password",
")",
"{",
"$",
"stmt",
"=",
"$",
"this",
"->",
"conn",
"->",
"prepare",
"(",
"sprintf",
"(",
"\"SELECT user_id, user_name, user_pass\n\t\t\tFROM %s WHERE user_name = :name LIMIT 1\"",
",",
"$",
"this",
"->",
"table",
")",
")",
";",
"$",
"stmt",
"->",
"execute",
"(",
"[",
"'name'",
"=>",
"$",
"username",
"]",
")",
";",
"$",
"result",
"=",
"$",
"stmt",
"->",
"fetch",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"if",
"(",
"$",
"result",
"[",
"'user_name'",
"]",
"!==",
"$",
"username",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"hasher",
"->",
"CheckPassword",
"(",
"$",
"password",
",",
"$",
"result",
"[",
"'user_pass'",
"]",
")",
")",
"{",
"// Clear previous session",
"$",
"this",
"->",
"session",
"->",
"regenerate",
"(",
")",
";",
"// Write new data to session",
"$",
"data",
"=",
"[",
"'id'",
"=>",
"$",
"result",
"[",
"'user_id'",
"]",
",",
"'logged_'",
".",
"$",
"this",
"->",
"table",
"=>",
"true",
"]",
";",
"$",
"this",
"->",
"session",
"->",
"set",
"(",
"'user'",
",",
"$",
"data",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Try to login user with passed parameters.
@param string $username
@param string $password
@return bool | [
"Try",
"to",
"login",
"user",
"with",
"passed",
"parameters",
"."
] | 6a354056cf95e471b9b1eb372c5626123fd77df2 | https://github.com/Kajna/K-Core/blob/6a354056cf95e471b9b1eb372c5626123fd77df2/Core/Auth/Auth.php#L143-L168 |
35,438 | Kajna/K-Core | Core/Auth/Auth.php | Auth.isLogged | public function isLogged()
{
$user = $this->session->get('user');
if (isset($user['logged_' . $this->table])
&& $user['logged_' . $this->table] === true
) {
return true;
}
return false;
} | php | public function isLogged()
{
$user = $this->session->get('user');
if (isset($user['logged_' . $this->table])
&& $user['logged_' . $this->table] === true
) {
return true;
}
return false;
} | [
"public",
"function",
"isLogged",
"(",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"session",
"->",
"get",
"(",
"'user'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"user",
"[",
"'logged_'",
".",
"$",
"this",
"->",
"table",
"]",
")",
"&&",
"$",
"user",
"[",
"'logged_'",
".",
"$",
"this",
"->",
"table",
"]",
"===",
"true",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Check if there is logged user.
@return bool | [
"Check",
"if",
"there",
"is",
"logged",
"user",
"."
] | 6a354056cf95e471b9b1eb372c5626123fd77df2 | https://github.com/Kajna/K-Core/blob/6a354056cf95e471b9b1eb372c5626123fd77df2/Core/Auth/Auth.php#L213-L222 |
35,439 | hail-framework/framework | src/I18n/Gettext/Translator.php | Translator.addTranslations | protected function addTranslations(array $translations)
{
$domain = $translations['domain'] ?? '';
//Set the first domain loaded as default domain
if ($this->domain === null) {
$this->domain = $domain;
}
if (isset($this->dictionary[$domain])) {
$this->dictionary[$domain] = \array_replace_recursive($this->dictionary[$domain], $translations['messages']);
return;
}
if (!empty($translations['plural-forms'])) {
[$count, $code] = \array_map('trim', \explode(';', $translations['plural-forms'], 2));
// extract just the expression turn 'n' into a php variable '$n'.
// Slap on a return keyword and semicolon at the end.
$this->plurals[$domain] = [
'count' => (int) \str_replace('nplurals=', '', $count),
'code' => \str_replace('plural=', 'return ', \str_replace('n', '$n', $code)).';',
];
}
$this->dictionary[$domain] = $translations['messages'];
} | php | protected function addTranslations(array $translations)
{
$domain = $translations['domain'] ?? '';
//Set the first domain loaded as default domain
if ($this->domain === null) {
$this->domain = $domain;
}
if (isset($this->dictionary[$domain])) {
$this->dictionary[$domain] = \array_replace_recursive($this->dictionary[$domain], $translations['messages']);
return;
}
if (!empty($translations['plural-forms'])) {
[$count, $code] = \array_map('trim', \explode(';', $translations['plural-forms'], 2));
// extract just the expression turn 'n' into a php variable '$n'.
// Slap on a return keyword and semicolon at the end.
$this->plurals[$domain] = [
'count' => (int) \str_replace('nplurals=', '', $count),
'code' => \str_replace('plural=', 'return ', \str_replace('n', '$n', $code)).';',
];
}
$this->dictionary[$domain] = $translations['messages'];
} | [
"protected",
"function",
"addTranslations",
"(",
"array",
"$",
"translations",
")",
"{",
"$",
"domain",
"=",
"$",
"translations",
"[",
"'domain'",
"]",
"??",
"''",
";",
"//Set the first domain loaded as default domain",
"if",
"(",
"$",
"this",
"->",
"domain",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"domain",
"=",
"$",
"domain",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"dictionary",
"[",
"$",
"domain",
"]",
")",
")",
"{",
"$",
"this",
"->",
"dictionary",
"[",
"$",
"domain",
"]",
"=",
"\\",
"array_replace_recursive",
"(",
"$",
"this",
"->",
"dictionary",
"[",
"$",
"domain",
"]",
",",
"$",
"translations",
"[",
"'messages'",
"]",
")",
";",
"return",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"translations",
"[",
"'plural-forms'",
"]",
")",
")",
"{",
"[",
"$",
"count",
",",
"$",
"code",
"]",
"=",
"\\",
"array_map",
"(",
"'trim'",
",",
"\\",
"explode",
"(",
"';'",
",",
"$",
"translations",
"[",
"'plural-forms'",
"]",
",",
"2",
")",
")",
";",
"// extract just the expression turn 'n' into a php variable '$n'.",
"// Slap on a return keyword and semicolon at the end.",
"$",
"this",
"->",
"plurals",
"[",
"$",
"domain",
"]",
"=",
"[",
"'count'",
"=>",
"(",
"int",
")",
"\\",
"str_replace",
"(",
"'nplurals='",
",",
"''",
",",
"$",
"count",
")",
",",
"'code'",
"=>",
"\\",
"str_replace",
"(",
"'plural='",
",",
"'return '",
",",
"\\",
"str_replace",
"(",
"'n'",
",",
"'$n'",
",",
"$",
"code",
")",
")",
".",
"';'",
",",
"]",
";",
"}",
"$",
"this",
"->",
"dictionary",
"[",
"$",
"domain",
"]",
"=",
"$",
"translations",
"[",
"'messages'",
"]",
";",
"}"
] | Set new translations to the dictionary.
@param array $translations | [
"Set",
"new",
"translations",
"to",
"the",
"dictionary",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/I18n/Gettext/Translator.php#L179-L206 |
35,440 | hail-framework/framework | src/I18n/Gettext/Translator.php | Translator.fixTerseIfs | private static function fixTerseIfs($code, $inner = false)
{
/*
* (?P<expression>[^?]+) Capture everything up to ? as 'expression'
* \? ?
* (?P<success>[^:]+) Capture everything up to : as 'success'
* : :
* (?P<failure>[^;]+) Capture everything up to ; as 'failure'
*/
\preg_match('/(?P<expression>[^?]+)\?(?P<success>[^:]+):(?P<failure>[^;]+)/', $code, $matches);
// If no match was found then no terse if was present
if (!isset($matches[0])) {
return $code;
}
$expression = $matches['expression'];
$success = $matches['success'];
$failure = $matches['failure'];
// Go look for another terse if in the failure state.
$failure = self::fixTerseIfs($failure, true);
$code = $expression.' ? '.$success.' : '.$failure;
if ($inner) {
return "($code)";
}
// note the semicolon. We need that for executing the code.
return "$code;";
} | php | private static function fixTerseIfs($code, $inner = false)
{
/*
* (?P<expression>[^?]+) Capture everything up to ? as 'expression'
* \? ?
* (?P<success>[^:]+) Capture everything up to : as 'success'
* : :
* (?P<failure>[^;]+) Capture everything up to ; as 'failure'
*/
\preg_match('/(?P<expression>[^?]+)\?(?P<success>[^:]+):(?P<failure>[^;]+)/', $code, $matches);
// If no match was found then no terse if was present
if (!isset($matches[0])) {
return $code;
}
$expression = $matches['expression'];
$success = $matches['success'];
$failure = $matches['failure'];
// Go look for another terse if in the failure state.
$failure = self::fixTerseIfs($failure, true);
$code = $expression.' ? '.$success.' : '.$failure;
if ($inner) {
return "($code)";
}
// note the semicolon. We need that for executing the code.
return "$code;";
} | [
"private",
"static",
"function",
"fixTerseIfs",
"(",
"$",
"code",
",",
"$",
"inner",
"=",
"false",
")",
"{",
"/*\n * (?P<expression>[^?]+) Capture everything up to ? as 'expression'\n * \\? ?\n * (?P<success>[^:]+) Capture everything up to : as 'success'\n * : :\n * (?P<failure>[^;]+) Capture everything up to ; as 'failure'\n */",
"\\",
"preg_match",
"(",
"'/(?P<expression>[^?]+)\\?(?P<success>[^:]+):(?P<failure>[^;]+)/'",
",",
"$",
"code",
",",
"$",
"matches",
")",
";",
"// If no match was found then no terse if was present",
"if",
"(",
"!",
"isset",
"(",
"$",
"matches",
"[",
"0",
"]",
")",
")",
"{",
"return",
"$",
"code",
";",
"}",
"$",
"expression",
"=",
"$",
"matches",
"[",
"'expression'",
"]",
";",
"$",
"success",
"=",
"$",
"matches",
"[",
"'success'",
"]",
";",
"$",
"failure",
"=",
"$",
"matches",
"[",
"'failure'",
"]",
";",
"// Go look for another terse if in the failure state.",
"$",
"failure",
"=",
"self",
"::",
"fixTerseIfs",
"(",
"$",
"failure",
",",
"true",
")",
";",
"$",
"code",
"=",
"$",
"expression",
".",
"' ? '",
".",
"$",
"success",
".",
"' : '",
".",
"$",
"failure",
";",
"if",
"(",
"$",
"inner",
")",
"{",
"return",
"\"($code)\"",
";",
"}",
"// note the semicolon. We need that for executing the code.",
"return",
"\"$code;\"",
";",
"}"
] | This function will recursively wrap failure states in brackets if they contain a nested terse if.
This because PHP can not handle nested terse if's unless they are wrapped in brackets.
This code probably only works for the gettext plural decision codes.
return ($n==1 ? 0 : $n%10>=2 && $n%10<=4 && ($n%100<10 || $n%100>=20) ? 1 : 2);
becomes
return ($n==1 ? 0 : ($n%10>=2 && $n%10<=4 && ($n%100<10 || $n%100>=20) ? 1 : 2));
@param string $code the terse if string
@param bool $inner If inner is true we wrap it in brackets
@return string A formatted terse If that PHP can work with. | [
"This",
"function",
"will",
"recursively",
"wrap",
"failure",
"states",
"in",
"brackets",
"if",
"they",
"contain",
"a",
"nested",
"terse",
"if",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/I18n/Gettext/Translator.php#L267-L297 |
35,441 | Kajna/K-Core | Core/Core/Controller.php | Controller.render | protected function render($view, array $data = [])
{
// Extract variables.
extract($data);
// Start buffering.
ob_start();
// Load view file (root location is declared in viewPath var).
include $this->container->get('config')['viewsPath'] . '/' . $view . '.php';
// Get buffered content
$body = ob_get_contents();
ob_end_clean();
// Make response and add body to it
$response = new Response();
$response->writeBody($body);
return $response;
} | php | protected function render($view, array $data = [])
{
// Extract variables.
extract($data);
// Start buffering.
ob_start();
// Load view file (root location is declared in viewPath var).
include $this->container->get('config')['viewsPath'] . '/' . $view . '.php';
// Get buffered content
$body = ob_get_contents();
ob_end_clean();
// Make response and add body to it
$response = new Response();
$response->writeBody($body);
return $response;
} | [
"protected",
"function",
"render",
"(",
"$",
"view",
",",
"array",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"// Extract variables.",
"extract",
"(",
"$",
"data",
")",
";",
"// Start buffering.",
"ob_start",
"(",
")",
";",
"// Load view file (root location is declared in viewPath var).",
"include",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'config'",
")",
"[",
"'viewsPath'",
"]",
".",
"'/'",
".",
"$",
"view",
".",
"'.php'",
";",
"// Get buffered content",
"$",
"body",
"=",
"ob_get_contents",
"(",
")",
";",
"ob_end_clean",
"(",
")",
";",
"// Make response and add body to it",
"$",
"response",
"=",
"new",
"Response",
"(",
")",
";",
"$",
"response",
"->",
"writeBody",
"(",
"$",
"body",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Render output for display.
@param string $view
@param array $data
@return ResponseInterface | [
"Render",
"output",
"for",
"display",
"."
] | 6a354056cf95e471b9b1eb372c5626123fd77df2 | https://github.com/Kajna/K-Core/blob/6a354056cf95e471b9b1eb372c5626123fd77df2/Core/Core/Controller.php#L30-L49 |
35,442 | Kajna/K-Core | Core/Core/Controller.php | Controller.buffer | protected function buffer($view, array $data = [])
{
// Extract variables.
extract($data);
// Start buffering.
ob_start();
// Load view file (root location is declared in viewsPath var).
include $this->container->get('config')['viewsPath'] . '/' . $view . '.php';
// Return string.
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
} | php | protected function buffer($view, array $data = [])
{
// Extract variables.
extract($data);
// Start buffering.
ob_start();
// Load view file (root location is declared in viewsPath var).
include $this->container->get('config')['viewsPath'] . '/' . $view . '.php';
// Return string.
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
} | [
"protected",
"function",
"buffer",
"(",
"$",
"view",
",",
"array",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"// Extract variables.",
"extract",
"(",
"$",
"data",
")",
";",
"// Start buffering.",
"ob_start",
"(",
")",
";",
"// Load view file (root location is declared in viewsPath var).",
"include",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'config'",
")",
"[",
"'viewsPath'",
"]",
".",
"'/'",
".",
"$",
"view",
".",
"'.php'",
";",
"// Return string. ",
"$",
"buffer",
"=",
"ob_get_contents",
"(",
")",
";",
"ob_end_clean",
"(",
")",
";",
"return",
"$",
"buffer",
";",
"}"
] | Buffer output and return it as string.
@param string $view
@param array $data
@return string | [
"Buffer",
"output",
"and",
"return",
"it",
"as",
"string",
"."
] | 6a354056cf95e471b9b1eb372c5626123fd77df2 | https://github.com/Kajna/K-Core/blob/6a354056cf95e471b9b1eb372c5626123fd77df2/Core/Core/Controller.php#L58-L73 |
35,443 | hail-framework/framework | src/Debugger/Logger.php | Logger.log | public function log($level, $message, array $context = []): void
{
if (!isset($this->logLevels[$level])) {
$level = LogLevel::DEBUG;
}
$this->exceptionFile = null;
if ($this->logLevels[$level] < $this->level) {
return;
}
$exceptionFile = null;
if (isset($context['exception']) && $context['exception'] instanceof \Throwable) {
$exceptionFile = $this->getExceptionFile($context['exception']);
}
if (SEASLOG_EXTENSION) {
$message .= $exceptionFile ? ' @@ ' . \basename($exceptionFile) : '';
\SeasLog::log($level, $message, $context);
} else {
$message = Dumper::interpolate($message, $context);
$line = static::formatLogLine($message, $exceptionFile);
$file = $this->directory . '/' . $level . '.log';
if (!@\file_put_contents($file, $line . PHP_EOL, FILE_APPEND | LOCK_EX)) { // @ is escalated to exception
throw new \RuntimeException("Unable to write to log file '$file'. Is directory writable?");
}
}
if ($exceptionFile) {
$this->logException($context['exception'], $exceptionFile);
}
if (\in_array($level, [LogLevel::ERROR, LogLevel::EMERGENCY, LogLevel::CRITICAL, LogLevel::ALERT], true)) {
$this->sendEmail($message);
}
$this->exceptionFile = $exceptionFile;
} | php | public function log($level, $message, array $context = []): void
{
if (!isset($this->logLevels[$level])) {
$level = LogLevel::DEBUG;
}
$this->exceptionFile = null;
if ($this->logLevels[$level] < $this->level) {
return;
}
$exceptionFile = null;
if (isset($context['exception']) && $context['exception'] instanceof \Throwable) {
$exceptionFile = $this->getExceptionFile($context['exception']);
}
if (SEASLOG_EXTENSION) {
$message .= $exceptionFile ? ' @@ ' . \basename($exceptionFile) : '';
\SeasLog::log($level, $message, $context);
} else {
$message = Dumper::interpolate($message, $context);
$line = static::formatLogLine($message, $exceptionFile);
$file = $this->directory . '/' . $level . '.log';
if (!@\file_put_contents($file, $line . PHP_EOL, FILE_APPEND | LOCK_EX)) { // @ is escalated to exception
throw new \RuntimeException("Unable to write to log file '$file'. Is directory writable?");
}
}
if ($exceptionFile) {
$this->logException($context['exception'], $exceptionFile);
}
if (\in_array($level, [LogLevel::ERROR, LogLevel::EMERGENCY, LogLevel::CRITICAL, LogLevel::ALERT], true)) {
$this->sendEmail($message);
}
$this->exceptionFile = $exceptionFile;
} | [
"public",
"function",
"log",
"(",
"$",
"level",
",",
"$",
"message",
",",
"array",
"$",
"context",
"=",
"[",
"]",
")",
":",
"void",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"logLevels",
"[",
"$",
"level",
"]",
")",
")",
"{",
"$",
"level",
"=",
"LogLevel",
"::",
"DEBUG",
";",
"}",
"$",
"this",
"->",
"exceptionFile",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"logLevels",
"[",
"$",
"level",
"]",
"<",
"$",
"this",
"->",
"level",
")",
"{",
"return",
";",
"}",
"$",
"exceptionFile",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"context",
"[",
"'exception'",
"]",
")",
"&&",
"$",
"context",
"[",
"'exception'",
"]",
"instanceof",
"\\",
"Throwable",
")",
"{",
"$",
"exceptionFile",
"=",
"$",
"this",
"->",
"getExceptionFile",
"(",
"$",
"context",
"[",
"'exception'",
"]",
")",
";",
"}",
"if",
"(",
"SEASLOG_EXTENSION",
")",
"{",
"$",
"message",
".=",
"$",
"exceptionFile",
"?",
"' @@ '",
".",
"\\",
"basename",
"(",
"$",
"exceptionFile",
")",
":",
"''",
";",
"\\",
"SeasLog",
"::",
"log",
"(",
"$",
"level",
",",
"$",
"message",
",",
"$",
"context",
")",
";",
"}",
"else",
"{",
"$",
"message",
"=",
"Dumper",
"::",
"interpolate",
"(",
"$",
"message",
",",
"$",
"context",
")",
";",
"$",
"line",
"=",
"static",
"::",
"formatLogLine",
"(",
"$",
"message",
",",
"$",
"exceptionFile",
")",
";",
"$",
"file",
"=",
"$",
"this",
"->",
"directory",
".",
"'/'",
".",
"$",
"level",
".",
"'.log'",
";",
"if",
"(",
"!",
"@",
"\\",
"file_put_contents",
"(",
"$",
"file",
",",
"$",
"line",
".",
"PHP_EOL",
",",
"FILE_APPEND",
"|",
"LOCK_EX",
")",
")",
"{",
"// @ is escalated to exception",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Unable to write to log file '$file'. Is directory writable?\"",
")",
";",
"}",
"}",
"if",
"(",
"$",
"exceptionFile",
")",
"{",
"$",
"this",
"->",
"logException",
"(",
"$",
"context",
"[",
"'exception'",
"]",
",",
"$",
"exceptionFile",
")",
";",
"}",
"if",
"(",
"\\",
"in_array",
"(",
"$",
"level",
",",
"[",
"LogLevel",
"::",
"ERROR",
",",
"LogLevel",
"::",
"EMERGENCY",
",",
"LogLevel",
"::",
"CRITICAL",
",",
"LogLevel",
"::",
"ALERT",
"]",
",",
"true",
")",
")",
"{",
"$",
"this",
"->",
"sendEmail",
"(",
"$",
"message",
")",
";",
"}",
"$",
"this",
"->",
"exceptionFile",
"=",
"$",
"exceptionFile",
";",
"}"
] | Logs message or exception to file and sends email notification.
@param mixed $level
@param string $message
@param array $context
@return void | [
"Logs",
"message",
"or",
"exception",
"to",
"file",
"and",
"sends",
"email",
"notification",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Logger.php#L99-L140 |
35,444 | hail-framework/framework | src/Debugger/Logger.php | Logger.logException | protected function logException(\Throwable $exception, string $file = null): string
{
$file = $file ?: $this->getExceptionFile($exception);
$bs = $this->blueScreen ?: new BlueScreen;
$bs->renderToFile($exception, $file);
return $file;
} | php | protected function logException(\Throwable $exception, string $file = null): string
{
$file = $file ?: $this->getExceptionFile($exception);
$bs = $this->blueScreen ?: new BlueScreen;
$bs->renderToFile($exception, $file);
return $file;
} | [
"protected",
"function",
"logException",
"(",
"\\",
"Throwable",
"$",
"exception",
",",
"string",
"$",
"file",
"=",
"null",
")",
":",
"string",
"{",
"$",
"file",
"=",
"$",
"file",
"?",
":",
"$",
"this",
"->",
"getExceptionFile",
"(",
"$",
"exception",
")",
";",
"$",
"bs",
"=",
"$",
"this",
"->",
"blueScreen",
"?",
":",
"new",
"BlueScreen",
";",
"$",
"bs",
"->",
"renderToFile",
"(",
"$",
"exception",
",",
"$",
"file",
")",
";",
"return",
"$",
"file",
";",
"}"
] | Logs exception to the file if file doesn't exist.
@param \Throwable $exception
@param string $file
@return string logged error filename | [
"Logs",
"exception",
"to",
"the",
"file",
"if",
"file",
"doesn",
"t",
"exist",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Logger.php#L208-L215 |
35,445 | hail-framework/framework | src/Debugger/Logger.php | Logger.defaultMailer | public function defaultMailer($message, string $email): void
{
$host = \preg_replace('#[^\w.-]+#', '', $_SERVER['HTTP_HOST'] ?? php_uname('n'));
$parts = \str_replace(
["\r\n", "\n"],
["\n", PHP_EOL],
[
'headers' => \implode("\n", [
'From: ' . ($this->fromEmail ?: "noreply@$host"),
'X-Mailer: Tracy',
'Content-Type: text/plain; charset=UTF-8',
'Content-Transfer-Encoding: 8bit',
]) . "\n",
'subject' => "PHP: An error occurred on the server $host",
'body' => Dumper::formatMessage($message) . "\n\nsource: " . Helpers::getSource(),
]
);
\mail($email, $parts['subject'], $parts['body'], $parts['headers']);
} | php | public function defaultMailer($message, string $email): void
{
$host = \preg_replace('#[^\w.-]+#', '', $_SERVER['HTTP_HOST'] ?? php_uname('n'));
$parts = \str_replace(
["\r\n", "\n"],
["\n", PHP_EOL],
[
'headers' => \implode("\n", [
'From: ' . ($this->fromEmail ?: "noreply@$host"),
'X-Mailer: Tracy',
'Content-Type: text/plain; charset=UTF-8',
'Content-Transfer-Encoding: 8bit',
]) . "\n",
'subject' => "PHP: An error occurred on the server $host",
'body' => Dumper::formatMessage($message) . "\n\nsource: " . Helpers::getSource(),
]
);
\mail($email, $parts['subject'], $parts['body'], $parts['headers']);
} | [
"public",
"function",
"defaultMailer",
"(",
"$",
"message",
",",
"string",
"$",
"email",
")",
":",
"void",
"{",
"$",
"host",
"=",
"\\",
"preg_replace",
"(",
"'#[^\\w.-]+#'",
",",
"''",
",",
"$",
"_SERVER",
"[",
"'HTTP_HOST'",
"]",
"??",
"php_uname",
"(",
"'n'",
")",
")",
";",
"$",
"parts",
"=",
"\\",
"str_replace",
"(",
"[",
"\"\\r\\n\"",
",",
"\"\\n\"",
"]",
",",
"[",
"\"\\n\"",
",",
"PHP_EOL",
"]",
",",
"[",
"'headers'",
"=>",
"\\",
"implode",
"(",
"\"\\n\"",
",",
"[",
"'From: '",
".",
"(",
"$",
"this",
"->",
"fromEmail",
"?",
":",
"\"noreply@$host\"",
")",
",",
"'X-Mailer: Tracy'",
",",
"'Content-Type: text/plain; charset=UTF-8'",
",",
"'Content-Transfer-Encoding: 8bit'",
",",
"]",
")",
".",
"\"\\n\"",
",",
"'subject'",
"=>",
"\"PHP: An error occurred on the server $host\"",
",",
"'body'",
"=>",
"Dumper",
"::",
"formatMessage",
"(",
"$",
"message",
")",
".",
"\"\\n\\nsource: \"",
".",
"Helpers",
"::",
"getSource",
"(",
")",
",",
"]",
")",
";",
"\\",
"mail",
"(",
"$",
"email",
",",
"$",
"parts",
"[",
"'subject'",
"]",
",",
"$",
"parts",
"[",
"'body'",
"]",
",",
"$",
"parts",
"[",
"'headers'",
"]",
")",
";",
"}"
] | Default mailer.
@param mixed
@param string
@return void
@internal | [
"Default",
"mailer",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Logger.php#L247-L266 |
35,446 | Kajna/K-Core | Core/Routing/Router.php | Router.execute | public function execute($uri, $requestMethod)
{
foreach ($this->routes as $route) {
if (true === $route->matches($uri, $requestMethod)) {
return $route;
}
}
return null;
} | php | public function execute($uri, $requestMethod)
{
foreach ($this->routes as $route) {
if (true === $route->matches($uri, $requestMethod)) {
return $route;
}
}
return null;
} | [
"public",
"function",
"execute",
"(",
"$",
"uri",
",",
"$",
"requestMethod",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"routes",
"as",
"$",
"route",
")",
"{",
"if",
"(",
"true",
"===",
"$",
"route",
"->",
"matches",
"(",
"$",
"uri",
",",
"$",
"requestMethod",
")",
")",
"{",
"return",
"$",
"route",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Check routes and returns matching one if found,
otherwise return null.
@var string $uri
@var string $requestMethod
@return null|RouteInterface | [
"Check",
"routes",
"and",
"returns",
"matching",
"one",
"if",
"found",
"otherwise",
"return",
"null",
"."
] | 6a354056cf95e471b9b1eb372c5626123fd77df2 | https://github.com/Kajna/K-Core/blob/6a354056cf95e471b9b1eb372c5626123fd77df2/Core/Routing/Router.php#L48-L56 |
35,447 | Kajna/K-Core | Core/Routing/Router.php | Router.put | public function put($url, $class, $function)
{
$route = new Route($this->urlPrefix . $url, 'PUT', self::$CONTROLLERS_ROOT . $class, $function);
$this->addRoute($route);
return $route;
} | php | public function put($url, $class, $function)
{
$route = new Route($this->urlPrefix . $url, 'PUT', self::$CONTROLLERS_ROOT . $class, $function);
$this->addRoute($route);
return $route;
} | [
"public",
"function",
"put",
"(",
"$",
"url",
",",
"$",
"class",
",",
"$",
"function",
")",
"{",
"$",
"route",
"=",
"new",
"Route",
"(",
"$",
"this",
"->",
"urlPrefix",
".",
"$",
"url",
",",
"'PUT'",
",",
"self",
"::",
"$",
"CONTROLLERS_ROOT",
".",
"$",
"class",
",",
"$",
"function",
")",
";",
"$",
"this",
"->",
"addRoute",
"(",
"$",
"route",
")",
";",
"return",
"$",
"route",
";",
"}"
] | Add a route object to the router accepting PUT request method.
@param string $url
@param string $class
@param string $function
@return RouteInterface | [
"Add",
"a",
"route",
"object",
"to",
"the",
"router",
"accepting",
"PUT",
"request",
"method",
"."
] | 6a354056cf95e471b9b1eb372c5626123fd77df2 | https://github.com/Kajna/K-Core/blob/6a354056cf95e471b9b1eb372c5626123fd77df2/Core/Routing/Router.php#L96-L101 |
35,448 | Kajna/K-Core | Core/Routing/Router.php | Router.addRoute | public function addRoute(RouteInterface $route)
{
foreach ($this->middlewares as $m) {
$route->addMiddleware($m);
}
$this->routes[] = $route;
return $this;
} | php | public function addRoute(RouteInterface $route)
{
foreach ($this->middlewares as $m) {
$route->addMiddleware($m);
}
$this->routes[] = $route;
return $this;
} | [
"public",
"function",
"addRoute",
"(",
"RouteInterface",
"$",
"route",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"middlewares",
"as",
"$",
"m",
")",
"{",
"$",
"route",
"->",
"addMiddleware",
"(",
"$",
"m",
")",
";",
"}",
"$",
"this",
"->",
"routes",
"[",
"]",
"=",
"$",
"route",
";",
"return",
"$",
"this",
";",
"}"
] | Add custom route object to routes array.
@param RouteInterface $route
@return self | [
"Add",
"custom",
"route",
"object",
"to",
"routes",
"array",
"."
] | 6a354056cf95e471b9b1eb372c5626123fd77df2 | https://github.com/Kajna/K-Core/blob/6a354056cf95e471b9b1eb372c5626123fd77df2/Core/Routing/Router.php#L174-L181 |
35,449 | hiqdev/hipanel-module-server | src/widgets/OSFormatter.php | OSFormatter.generateInfoCircle | public function generateInfoCircle()
{
Modal::begin([
'toggleButton' => [
'class' => 'fa fa-info text-info os-info-popover',
'label' => '',
],
'header' => Html::tag('h4', $this->osimage->getFullOsName()),
'size' => Modal::SIZE_LARGE,
]);
echo Html::tag('div', $this->generateOSInfo(), [
'class' => 'table-responsive',
]);
Modal::end();
} | php | public function generateInfoCircle()
{
Modal::begin([
'toggleButton' => [
'class' => 'fa fa-info text-info os-info-popover',
'label' => '',
],
'header' => Html::tag('h4', $this->osimage->getFullOsName()),
'size' => Modal::SIZE_LARGE,
]);
echo Html::tag('div', $this->generateOSInfo(), [
'class' => 'table-responsive',
]);
Modal::end();
} | [
"public",
"function",
"generateInfoCircle",
"(",
")",
"{",
"Modal",
"::",
"begin",
"(",
"[",
"'toggleButton'",
"=>",
"[",
"'class'",
"=>",
"'fa fa-info text-info os-info-popover'",
",",
"'label'",
"=>",
"''",
",",
"]",
",",
"'header'",
"=>",
"Html",
"::",
"tag",
"(",
"'h4'",
",",
"$",
"this",
"->",
"osimage",
"->",
"getFullOsName",
"(",
")",
")",
",",
"'size'",
"=>",
"Modal",
"::",
"SIZE_LARGE",
",",
"]",
")",
";",
"echo",
"Html",
"::",
"tag",
"(",
"'div'",
",",
"$",
"this",
"->",
"generateOSInfo",
"(",
")",
",",
"[",
"'class'",
"=>",
"'table-responsive'",
",",
"]",
")",
";",
"Modal",
"::",
"end",
"(",
")",
";",
"}"
] | Renders info-circle with modal popup. | [
"Renders",
"info",
"-",
"circle",
"with",
"modal",
"popup",
"."
] | e40c3601952cf1fd420ebb97093ee17a33ff3207 | https://github.com/hiqdev/hipanel-module-server/blob/e40c3601952cf1fd420ebb97093ee17a33ff3207/src/widgets/OSFormatter.php#L85-L99 |
35,450 | DoSomething/gateway | src/Laravel/HasNorthstarToken.php | HasNorthstarToken.getOAuthToken | public function getOAuthToken()
{
// If any of the required fields are empty, return null.
$hasAnEmptyField = empty($this->northstar_id) || empty($this->access_token) ||
empty($this->access_token_expiration) || empty($this->refresh_token) || empty($this->role);
if ($hasAnEmptyField) {
return null;
}
return new AccessToken([
'resource_owner_id' => $this->getNorthstarIdentifier(),
'access_token' => $this->access_token,
'refresh_token' => $this->refresh_token,
'expires' => $this->access_token_expiration,
'role' => $this->role,
]);
} | php | public function getOAuthToken()
{
// If any of the required fields are empty, return null.
$hasAnEmptyField = empty($this->northstar_id) || empty($this->access_token) ||
empty($this->access_token_expiration) || empty($this->refresh_token) || empty($this->role);
if ($hasAnEmptyField) {
return null;
}
return new AccessToken([
'resource_owner_id' => $this->getNorthstarIdentifier(),
'access_token' => $this->access_token,
'refresh_token' => $this->refresh_token,
'expires' => $this->access_token_expiration,
'role' => $this->role,
]);
} | [
"public",
"function",
"getOAuthToken",
"(",
")",
"{",
"// If any of the required fields are empty, return null.",
"$",
"hasAnEmptyField",
"=",
"empty",
"(",
"$",
"this",
"->",
"northstar_id",
")",
"||",
"empty",
"(",
"$",
"this",
"->",
"access_token",
")",
"||",
"empty",
"(",
"$",
"this",
"->",
"access_token_expiration",
")",
"||",
"empty",
"(",
"$",
"this",
"->",
"refresh_token",
")",
"||",
"empty",
"(",
"$",
"this",
"->",
"role",
")",
";",
"if",
"(",
"$",
"hasAnEmptyField",
")",
"{",
"return",
"null",
";",
"}",
"return",
"new",
"AccessToken",
"(",
"[",
"'resource_owner_id'",
"=>",
"$",
"this",
"->",
"getNorthstarIdentifier",
"(",
")",
",",
"'access_token'",
"=>",
"$",
"this",
"->",
"access_token",
",",
"'refresh_token'",
"=>",
"$",
"this",
"->",
"refresh_token",
",",
"'expires'",
"=>",
"$",
"this",
"->",
"access_token_expiration",
",",
"'role'",
"=>",
"$",
"this",
"->",
"role",
",",
"]",
")",
";",
"}"
] | Get the access token for the user.
@return AccessToken|null | [
"Get",
"the",
"access",
"token",
"for",
"the",
"user",
"."
] | 89c1c59c6af038dff790df6d5aaa9fc703246568 | https://github.com/DoSomething/gateway/blob/89c1c59c6af038dff790df6d5aaa9fc703246568/src/Laravel/HasNorthstarToken.php#L72-L89 |
35,451 | DoSomething/gateway | src/Laravel/HasNorthstarToken.php | HasNorthstarToken.setOAuthToken | public function setOAuthToken(AccessToken $token)
{
$this->access_token = $token->getToken();
$this->access_token_expiration = $token->getExpires();
$this->refresh_token = $token->getRefreshToken();
$this->role = $token->getValues()['role'];
} | php | public function setOAuthToken(AccessToken $token)
{
$this->access_token = $token->getToken();
$this->access_token_expiration = $token->getExpires();
$this->refresh_token = $token->getRefreshToken();
$this->role = $token->getValues()['role'];
} | [
"public",
"function",
"setOAuthToken",
"(",
"AccessToken",
"$",
"token",
")",
"{",
"$",
"this",
"->",
"access_token",
"=",
"$",
"token",
"->",
"getToken",
"(",
")",
";",
"$",
"this",
"->",
"access_token_expiration",
"=",
"$",
"token",
"->",
"getExpires",
"(",
")",
";",
"$",
"this",
"->",
"refresh_token",
"=",
"$",
"token",
"->",
"getRefreshToken",
"(",
")",
";",
"$",
"this",
"->",
"role",
"=",
"$",
"token",
"->",
"getValues",
"(",
")",
"[",
"'role'",
"]",
";",
"}"
] | Save the access token for the user.
@param AccessToken $token | [
"Save",
"the",
"access",
"token",
"for",
"the",
"user",
"."
] | 89c1c59c6af038dff790df6d5aaa9fc703246568 | https://github.com/DoSomething/gateway/blob/89c1c59c6af038dff790df6d5aaa9fc703246568/src/Laravel/HasNorthstarToken.php#L96-L102 |
35,452 | DoSomething/gateway | src/Laravel/HasNorthstarToken.php | HasNorthstarToken.clearOAuthToken | public function clearOAuthToken()
{
$this->access_token = null;
$this->access_token_expiration = null;
$this->refresh_token = null;
} | php | public function clearOAuthToken()
{
$this->access_token = null;
$this->access_token_expiration = null;
$this->refresh_token = null;
} | [
"public",
"function",
"clearOAuthToken",
"(",
")",
"{",
"$",
"this",
"->",
"access_token",
"=",
"null",
";",
"$",
"this",
"->",
"access_token_expiration",
"=",
"null",
";",
"$",
"this",
"->",
"refresh_token",
"=",
"null",
";",
"}"
] | Clear the access token for the user.
@return void | [
"Clear",
"the",
"access",
"token",
"for",
"the",
"user",
"."
] | 89c1c59c6af038dff790df6d5aaa9fc703246568 | https://github.com/DoSomething/gateway/blob/89c1c59c6af038dff790df6d5aaa9fc703246568/src/Laravel/HasNorthstarToken.php#L109-L114 |
35,453 | jormin/aliyun | sdk/aliyun-opensearch-php-sdk/OpenSearch/Thrift/Protocol/TProtocol.php | TProtocol.skip | public function skip($type)
{
switch ($type) {
case TType::BOOL:
return $this->readBool($bool);
case TType::BYTE:
return $this->readByte($byte);
case TType::I16:
return $this->readI16($i16);
case TType::I32:
return $this->readI32($i32);
case TType::I64:
return $this->readI64($i64);
case TType::DOUBLE:
return $this->readDouble($dub);
case TType::STRING:
return $this->readString($str);
case TType::STRUCT:
{
$result = $this->readStructBegin($name);
while (true) {
$result += $this->readFieldBegin($name, $ftype, $fid);
if ($ftype == TType::STOP) {
break;
}
$result += $this->skip($ftype);
$result += $this->readFieldEnd();
}
$result += $this->readStructEnd();
return $result;
}
case TType::MAP:
{
$result = $this->readMapBegin($keyType, $valType, $size);
for ($i = 0; $i < $size; $i++) {
$result += $this->skip($keyType);
$result += $this->skip($valType);
}
$result += $this->readMapEnd();
return $result;
}
case TType::SET:
{
$result = $this->readSetBegin($elemType, $size);
for ($i = 0; $i < $size; $i++) {
$result += $this->skip($elemType);
}
$result += $this->readSetEnd();
return $result;
}
case TType::LST:
{
$result = $this->readListBegin($elemType, $size);
for ($i = 0; $i < $size; $i++) {
$result += $this->skip($elemType);
}
$result += $this->readListEnd();
return $result;
}
default:
throw new TProtocolException('Unknown field type: '.$type,
TProtocolException::INVALID_DATA);
}
} | php | public function skip($type)
{
switch ($type) {
case TType::BOOL:
return $this->readBool($bool);
case TType::BYTE:
return $this->readByte($byte);
case TType::I16:
return $this->readI16($i16);
case TType::I32:
return $this->readI32($i32);
case TType::I64:
return $this->readI64($i64);
case TType::DOUBLE:
return $this->readDouble($dub);
case TType::STRING:
return $this->readString($str);
case TType::STRUCT:
{
$result = $this->readStructBegin($name);
while (true) {
$result += $this->readFieldBegin($name, $ftype, $fid);
if ($ftype == TType::STOP) {
break;
}
$result += $this->skip($ftype);
$result += $this->readFieldEnd();
}
$result += $this->readStructEnd();
return $result;
}
case TType::MAP:
{
$result = $this->readMapBegin($keyType, $valType, $size);
for ($i = 0; $i < $size; $i++) {
$result += $this->skip($keyType);
$result += $this->skip($valType);
}
$result += $this->readMapEnd();
return $result;
}
case TType::SET:
{
$result = $this->readSetBegin($elemType, $size);
for ($i = 0; $i < $size; $i++) {
$result += $this->skip($elemType);
}
$result += $this->readSetEnd();
return $result;
}
case TType::LST:
{
$result = $this->readListBegin($elemType, $size);
for ($i = 0; $i < $size; $i++) {
$result += $this->skip($elemType);
}
$result += $this->readListEnd();
return $result;
}
default:
throw new TProtocolException('Unknown field type: '.$type,
TProtocolException::INVALID_DATA);
}
} | [
"public",
"function",
"skip",
"(",
"$",
"type",
")",
"{",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"TType",
"::",
"BOOL",
":",
"return",
"$",
"this",
"->",
"readBool",
"(",
"$",
"bool",
")",
";",
"case",
"TType",
"::",
"BYTE",
":",
"return",
"$",
"this",
"->",
"readByte",
"(",
"$",
"byte",
")",
";",
"case",
"TType",
"::",
"I16",
":",
"return",
"$",
"this",
"->",
"readI16",
"(",
"$",
"i16",
")",
";",
"case",
"TType",
"::",
"I32",
":",
"return",
"$",
"this",
"->",
"readI32",
"(",
"$",
"i32",
")",
";",
"case",
"TType",
"::",
"I64",
":",
"return",
"$",
"this",
"->",
"readI64",
"(",
"$",
"i64",
")",
";",
"case",
"TType",
"::",
"DOUBLE",
":",
"return",
"$",
"this",
"->",
"readDouble",
"(",
"$",
"dub",
")",
";",
"case",
"TType",
"::",
"STRING",
":",
"return",
"$",
"this",
"->",
"readString",
"(",
"$",
"str",
")",
";",
"case",
"TType",
"::",
"STRUCT",
":",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"readStructBegin",
"(",
"$",
"name",
")",
";",
"while",
"(",
"true",
")",
"{",
"$",
"result",
"+=",
"$",
"this",
"->",
"readFieldBegin",
"(",
"$",
"name",
",",
"$",
"ftype",
",",
"$",
"fid",
")",
";",
"if",
"(",
"$",
"ftype",
"==",
"TType",
"::",
"STOP",
")",
"{",
"break",
";",
"}",
"$",
"result",
"+=",
"$",
"this",
"->",
"skip",
"(",
"$",
"ftype",
")",
";",
"$",
"result",
"+=",
"$",
"this",
"->",
"readFieldEnd",
"(",
")",
";",
"}",
"$",
"result",
"+=",
"$",
"this",
"->",
"readStructEnd",
"(",
")",
";",
"return",
"$",
"result",
";",
"}",
"case",
"TType",
"::",
"MAP",
":",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"readMapBegin",
"(",
"$",
"keyType",
",",
"$",
"valType",
",",
"$",
"size",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"size",
";",
"$",
"i",
"++",
")",
"{",
"$",
"result",
"+=",
"$",
"this",
"->",
"skip",
"(",
"$",
"keyType",
")",
";",
"$",
"result",
"+=",
"$",
"this",
"->",
"skip",
"(",
"$",
"valType",
")",
";",
"}",
"$",
"result",
"+=",
"$",
"this",
"->",
"readMapEnd",
"(",
")",
";",
"return",
"$",
"result",
";",
"}",
"case",
"TType",
"::",
"SET",
":",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"readSetBegin",
"(",
"$",
"elemType",
",",
"$",
"size",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"size",
";",
"$",
"i",
"++",
")",
"{",
"$",
"result",
"+=",
"$",
"this",
"->",
"skip",
"(",
"$",
"elemType",
")",
";",
"}",
"$",
"result",
"+=",
"$",
"this",
"->",
"readSetEnd",
"(",
")",
";",
"return",
"$",
"result",
";",
"}",
"case",
"TType",
"::",
"LST",
":",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"readListBegin",
"(",
"$",
"elemType",
",",
"$",
"size",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"size",
";",
"$",
"i",
"++",
")",
"{",
"$",
"result",
"+=",
"$",
"this",
"->",
"skip",
"(",
"$",
"elemType",
")",
";",
"}",
"$",
"result",
"+=",
"$",
"this",
"->",
"readListEnd",
"(",
")",
";",
"return",
"$",
"result",
";",
"}",
"default",
":",
"throw",
"new",
"TProtocolException",
"(",
"'Unknown field type: '",
".",
"$",
"type",
",",
"TProtocolException",
"::",
"INVALID_DATA",
")",
";",
"}",
"}"
] | The skip function is a utility to parse over unrecognized date without
causing corruption.
@param TType $type What type is it | [
"The",
"skip",
"function",
"is",
"a",
"utility",
"to",
"parse",
"over",
"unrecognized",
"date",
"without",
"causing",
"corruption",
"."
] | c0eb19f5c265dba1f463af1db7347acdcfddb240 | https://github.com/jormin/aliyun/blob/c0eb19f5c265dba1f463af1db7347acdcfddb240/sdk/aliyun-opensearch-php-sdk/OpenSearch/Thrift/Protocol/TProtocol.php#L184-L251 |
35,454 | hiqdev/hipanel-module-server | src/forms/ServerForm.php | ServerForm.fromServer | public static function fromServer(Server $server): ServerForm
{
return new self(array_merge($server->getAttributes(), ['server' => $server->name, 'scenario' => 'update'], [
'ips' => implode(',', ArrayHelper::getColumn($server->ips, 'ip')),
]));
} | php | public static function fromServer(Server $server): ServerForm
{
return new self(array_merge($server->getAttributes(), ['server' => $server->name, 'scenario' => 'update'], [
'ips' => implode(',', ArrayHelper::getColumn($server->ips, 'ip')),
]));
} | [
"public",
"static",
"function",
"fromServer",
"(",
"Server",
"$",
"server",
")",
":",
"ServerForm",
"{",
"return",
"new",
"self",
"(",
"array_merge",
"(",
"$",
"server",
"->",
"getAttributes",
"(",
")",
",",
"[",
"'server'",
"=>",
"$",
"server",
"->",
"name",
",",
"'scenario'",
"=>",
"'update'",
"]",
",",
"[",
"'ips'",
"=>",
"implode",
"(",
"','",
",",
"ArrayHelper",
"::",
"getColumn",
"(",
"$",
"server",
"->",
"ips",
",",
"'ip'",
")",
")",
",",
"]",
")",
")",
";",
"}"
] | Create ServerForm model from Server model.
@param Server $server
@return ServerForm | [
"Create",
"ServerForm",
"model",
"from",
"Server",
"model",
"."
] | e40c3601952cf1fd420ebb97093ee17a33ff3207 | https://github.com/hiqdev/hipanel-module-server/blob/e40c3601952cf1fd420ebb97093ee17a33ff3207/src/forms/ServerForm.php#L39-L44 |
35,455 | hail-framework/framework | src/Http/Header.php | Header.replace | public function replace(array $headers = []): void
{
$this->headerNames = [];
$this->headers = [];
$headers !== [] && $this->add($headers);
if (!isset($this->headers['Cache-Control'])) {
$this->set('Cache-Control', '');
}
} | php | public function replace(array $headers = []): void
{
$this->headerNames = [];
$this->headers = [];
$headers !== [] && $this->add($headers);
if (!isset($this->headers['Cache-Control'])) {
$this->set('Cache-Control', '');
}
} | [
"public",
"function",
"replace",
"(",
"array",
"$",
"headers",
"=",
"[",
"]",
")",
":",
"void",
"{",
"$",
"this",
"->",
"headerNames",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"headers",
"=",
"[",
"]",
";",
"$",
"headers",
"!==",
"[",
"]",
"&&",
"$",
"this",
"->",
"add",
"(",
"$",
"headers",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"'Cache-Control'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"set",
"(",
"'Cache-Control'",
",",
"''",
")",
";",
"}",
"}"
] | Replaces the current HTTP headers by a new set.
@param array $headers An array of HTTP headers
@throws \LogicException | [
"Replaces",
"the",
"current",
"HTTP",
"headers",
"by",
"a",
"new",
"set",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Http/Header.php#L55-L65 |
35,456 | hail-framework/framework | src/Http/Header.php | Header.has | public function has($key)
{
if (\strpos($key, '_')) {
$key = \str_replace('_', '-', $key);
}
return isset($this->headerNames[\strtolower($key)]);
} | php | public function has($key)
{
if (\strpos($key, '_')) {
$key = \str_replace('_', '-', $key);
}
return isset($this->headerNames[\strtolower($key)]);
} | [
"public",
"function",
"has",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"\\",
"strpos",
"(",
"$",
"key",
",",
"'_'",
")",
")",
"{",
"$",
"key",
"=",
"\\",
"str_replace",
"(",
"'_'",
",",
"'-'",
",",
"$",
"key",
")",
";",
"}",
"return",
"isset",
"(",
"$",
"this",
"->",
"headerNames",
"[",
"\\",
"strtolower",
"(",
"$",
"key",
")",
"]",
")",
";",
"}"
] | Returns true if the HTTP header is defined.
@param string $key The HTTP header
@return bool true if the parameter exists, false otherwise | [
"Returns",
"true",
"if",
"the",
"HTTP",
"header",
"is",
"defined",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Http/Header.php#L162-L169 |
35,457 | hail-framework/framework | src/Http/Header.php | Header.hasCacheControlDirective | public function hasCacheControlDirective($key)
{
return isset($this->computedCacheControl[$key]) || \array_key_exists($key, $this->computedCacheControl);
} | php | public function hasCacheControlDirective($key)
{
return isset($this->computedCacheControl[$key]) || \array_key_exists($key, $this->computedCacheControl);
} | [
"public",
"function",
"hasCacheControlDirective",
"(",
"$",
"key",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"computedCacheControl",
"[",
"$",
"key",
"]",
")",
"||",
"\\",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"computedCacheControl",
")",
";",
"}"
] | Returns true if the Cache-Control directive is defined.
@param string $key The Cache-Control directive
@return bool true if the directive exists, false otherwise | [
"Returns",
"true",
"if",
"the",
"Cache",
"-",
"Control",
"directive",
"is",
"defined",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Http/Header.php#L218-L221 |
35,458 | hail-framework/framework | src/Http/Header.php | Header.parseCacheControl | protected function parseCacheControl($header)
{
$cacheControl = [];
\preg_match_all('#([a-zA-Z][a-zA-Z_-]*)\s*(?:=(?:"([^"]*)"|([^ \t",;]*)))?#', $header, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
$cacheControl[\strtolower($match[1])] = $match[3] ?? ($match[2] ?? true);
}
return $cacheControl;
} | php | protected function parseCacheControl($header)
{
$cacheControl = [];
\preg_match_all('#([a-zA-Z][a-zA-Z_-]*)\s*(?:=(?:"([^"]*)"|([^ \t",;]*)))?#', $header, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
$cacheControl[\strtolower($match[1])] = $match[3] ?? ($match[2] ?? true);
}
return $cacheControl;
} | [
"protected",
"function",
"parseCacheControl",
"(",
"$",
"header",
")",
"{",
"$",
"cacheControl",
"=",
"[",
"]",
";",
"\\",
"preg_match_all",
"(",
"'#([a-zA-Z][a-zA-Z_-]*)\\s*(?:=(?:\"([^\"]*)\"|([^ \\t\",;]*)))?#'",
",",
"$",
"header",
",",
"$",
"matches",
",",
"PREG_SET_ORDER",
")",
";",
"foreach",
"(",
"$",
"matches",
"as",
"$",
"match",
")",
"{",
"$",
"cacheControl",
"[",
"\\",
"strtolower",
"(",
"$",
"match",
"[",
"1",
"]",
")",
"]",
"=",
"$",
"match",
"[",
"3",
"]",
"??",
"(",
"$",
"match",
"[",
"2",
"]",
"??",
"true",
")",
";",
"}",
"return",
"$",
"cacheControl",
";",
"}"
] | Parses a Cache-Control HTTP header.
@param string $header The value of the Cache-Control HTTP header
@return array An array representing the attribute values | [
"Parses",
"a",
"Cache",
"-",
"Control",
"HTTP",
"header",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Http/Header.php#L415-L424 |
35,459 | hail-framework/framework | src/Http/RequestHandler.php | RequestHandler.get | protected function get(ServerRequestInterface $request, bool $next = false): ?MiddlewareInterface
{
$index = $next ? ++$this->index : $this->index;
if (!isset($this->middleware[$index])) {
return null;
}
$middleware = $this->middleware[$index];
if (\is_array($middleware)) {
$conditions = $middleware;
$middleware = \array_pop($conditions);
if (!Matcher\Factory::matches($conditions, $request)) {
return $this->get($request, true);
}
}
if (\is_callable($middleware)) {
return new Middleware\CallableWrapper($middleware);
}
if (\is_string($middleware)) {
if ($this->container === null) {
throw new \RuntimeException("No valid middleware provided: $middleware");
}
$middleware = $this->container->get($middleware);
}
if (!$middleware instanceof MiddlewareInterface) {
throw new \RuntimeException('The middleware must be an instance of MiddlewareInterface');
}
return $middleware;
} | php | protected function get(ServerRequestInterface $request, bool $next = false): ?MiddlewareInterface
{
$index = $next ? ++$this->index : $this->index;
if (!isset($this->middleware[$index])) {
return null;
}
$middleware = $this->middleware[$index];
if (\is_array($middleware)) {
$conditions = $middleware;
$middleware = \array_pop($conditions);
if (!Matcher\Factory::matches($conditions, $request)) {
return $this->get($request, true);
}
}
if (\is_callable($middleware)) {
return new Middleware\CallableWrapper($middleware);
}
if (\is_string($middleware)) {
if ($this->container === null) {
throw new \RuntimeException("No valid middleware provided: $middleware");
}
$middleware = $this->container->get($middleware);
}
if (!$middleware instanceof MiddlewareInterface) {
throw new \RuntimeException('The middleware must be an instance of MiddlewareInterface');
}
return $middleware;
} | [
"protected",
"function",
"get",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"bool",
"$",
"next",
"=",
"false",
")",
":",
"?",
"MiddlewareInterface",
"{",
"$",
"index",
"=",
"$",
"next",
"?",
"++",
"$",
"this",
"->",
"index",
":",
"$",
"this",
"->",
"index",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"middleware",
"[",
"$",
"index",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"middleware",
"=",
"$",
"this",
"->",
"middleware",
"[",
"$",
"index",
"]",
";",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"middleware",
")",
")",
"{",
"$",
"conditions",
"=",
"$",
"middleware",
";",
"$",
"middleware",
"=",
"\\",
"array_pop",
"(",
"$",
"conditions",
")",
";",
"if",
"(",
"!",
"Matcher",
"\\",
"Factory",
"::",
"matches",
"(",
"$",
"conditions",
",",
"$",
"request",
")",
")",
"{",
"return",
"$",
"this",
"->",
"get",
"(",
"$",
"request",
",",
"true",
")",
";",
"}",
"}",
"if",
"(",
"\\",
"is_callable",
"(",
"$",
"middleware",
")",
")",
"{",
"return",
"new",
"Middleware",
"\\",
"CallableWrapper",
"(",
"$",
"middleware",
")",
";",
"}",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"middleware",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"container",
"===",
"null",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"No valid middleware provided: $middleware\"",
")",
";",
"}",
"$",
"middleware",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"$",
"middleware",
")",
";",
"}",
"if",
"(",
"!",
"$",
"middleware",
"instanceof",
"MiddlewareInterface",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'The middleware must be an instance of MiddlewareInterface'",
")",
";",
"}",
"return",
"$",
"middleware",
";",
"}"
] | Return the current or next available middleware frame in the middleware.
@param ServerRequestInterface $request
@param bool $next
@return null|MiddlewareInterface
@throws | [
"Return",
"the",
"current",
"or",
"next",
"available",
"middleware",
"frame",
"in",
"the",
"middleware",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Http/RequestHandler.php#L87-L123 |
35,460 | hail-framework/framework | src/Http/Middleware/BasePath.php | BasePath.addBasePath | private function addBasePath($path)
{
if (\strpos($path, $this->basePath) === 0) {
return $path;
}
return \str_replace('//', '/', $this->basePath . '/' . $path);
} | php | private function addBasePath($path)
{
if (\strpos($path, $this->basePath) === 0) {
return $path;
}
return \str_replace('//', '/', $this->basePath . '/' . $path);
} | [
"private",
"function",
"addBasePath",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"\\",
"strpos",
"(",
"$",
"path",
",",
"$",
"this",
"->",
"basePath",
")",
"===",
"0",
")",
"{",
"return",
"$",
"path",
";",
"}",
"return",
"\\",
"str_replace",
"(",
"'//'",
",",
"'/'",
",",
"$",
"this",
"->",
"basePath",
".",
"'/'",
".",
"$",
"path",
")",
";",
"}"
] | Adds the basepath to a path.
@param string $path
@return string | [
"Adds",
"the",
"basepath",
"to",
"a",
"path",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Http/Middleware/BasePath.php#L111-L118 |
35,461 | hail-framework/framework | src/Image/Commands/Argument.php | Argument.required | public function required()
{
if (!array_key_exists($this->key, $this->command->arguments)) {
throw new \Hail\Image\Exception\InvalidArgumentException(
sprintf('Missing argument %d for %s', $this->key + 1, $this->getCommandName())
);
}
return $this;
} | php | public function required()
{
if (!array_key_exists($this->key, $this->command->arguments)) {
throw new \Hail\Image\Exception\InvalidArgumentException(
sprintf('Missing argument %d for %s', $this->key + 1, $this->getCommandName())
);
}
return $this;
} | [
"public",
"function",
"required",
"(",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"this",
"->",
"key",
",",
"$",
"this",
"->",
"command",
"->",
"arguments",
")",
")",
"{",
"throw",
"new",
"\\",
"Hail",
"\\",
"Image",
"\\",
"Exception",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Missing argument %d for %s'",
",",
"$",
"this",
"->",
"key",
"+",
"1",
",",
"$",
"this",
"->",
"getCommandName",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Defines current argument as required
@return self | [
"Defines",
"current",
"argument",
"as",
"required"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Image/Commands/Argument.php#L68-L77 |
35,462 | hiqdev/hipanel-module-dns | src/models/Record.php | Record.buildRuleWhen | protected function buildRuleWhen($type, $not = false)
{
return function ($model) use ($type, $not) {
/* @var $model Record */
return $not xor in_array($model->type, (array) $type, true);
};
} | php | protected function buildRuleWhen($type, $not = false)
{
return function ($model) use ($type, $not) {
/* @var $model Record */
return $not xor in_array($model->type, (array) $type, true);
};
} | [
"protected",
"function",
"buildRuleWhen",
"(",
"$",
"type",
",",
"$",
"not",
"=",
"false",
")",
"{",
"return",
"function",
"(",
"$",
"model",
")",
"use",
"(",
"$",
"type",
",",
"$",
"not",
")",
"{",
"/* @var $model Record */",
"return",
"$",
"not",
"xor",
"in_array",
"(",
"$",
"model",
"->",
"type",
",",
"(",
"array",
")",
"$",
"type",
",",
"true",
")",
";",
"}",
";",
"}"
] | Builds a closure for Yii server-side validation property `when` in order to apply the rule to only a certain
list of DNS record types.
@param array|string $type types, that are must be validated with the rule
@param bool $not inverts $type
@return \Closure | [
"Builds",
"a",
"closure",
"for",
"Yii",
"server",
"-",
"side",
"validation",
"property",
"when",
"in",
"order",
"to",
"apply",
"the",
"rule",
"to",
"only",
"a",
"certain",
"list",
"of",
"DNS",
"record",
"types",
"."
] | 7e9199c95d91a979b7bd4fd07fe801dbe9e69183 | https://github.com/hiqdev/hipanel-module-dns/blob/7e9199c95d91a979b7bd4fd07fe801dbe9e69183/src/models/Record.php#L156-L162 |
35,463 | hiqdev/hipanel-module-dns | src/models/Record.php | Record.buildRuleWhenClient | protected function buildRuleWhenClient($type, $not = false)
{
$not = Json::encode($not);
$types = Json::encode((array) $type);
return new JsExpression("
function (attribute, value) {
var type = $(attribute.input).closest('.record-item').find('[data-attribute=type]');
if (!type) return true;
var types = $types;
return $not !== (types.indexOf(type.val()) > -1);
}
");
} | php | protected function buildRuleWhenClient($type, $not = false)
{
$not = Json::encode($not);
$types = Json::encode((array) $type);
return new JsExpression("
function (attribute, value) {
var type = $(attribute.input).closest('.record-item').find('[data-attribute=type]');
if (!type) return true;
var types = $types;
return $not !== (types.indexOf(type.val()) > -1);
}
");
} | [
"protected",
"function",
"buildRuleWhenClient",
"(",
"$",
"type",
",",
"$",
"not",
"=",
"false",
")",
"{",
"$",
"not",
"=",
"Json",
"::",
"encode",
"(",
"$",
"not",
")",
";",
"$",
"types",
"=",
"Json",
"::",
"encode",
"(",
"(",
"array",
")",
"$",
"type",
")",
";",
"return",
"new",
"JsExpression",
"(",
"\"\n function (attribute, value) {\n var type = $(attribute.input).closest('.record-item').find('[data-attribute=type]');\n if (!type) return true;\n var types = $types;\n return $not !== (types.indexOf(type.val()) > -1);\n }\n \"",
")",
";",
"}"
] | Builds the JS expression for Yii `whenClient` validation in order to apply validation to only a certain
list of DNS record types.
@param array|string $type types, that are must be validated with the rule
@param bool $not inverts $type
@return JsExpression | [
"Builds",
"the",
"JS",
"expression",
"for",
"Yii",
"whenClient",
"validation",
"in",
"order",
"to",
"apply",
"validation",
"to",
"only",
"a",
"certain",
"list",
"of",
"DNS",
"record",
"types",
"."
] | 7e9199c95d91a979b7bd4fd07fe801dbe9e69183 | https://github.com/hiqdev/hipanel-module-dns/blob/7e9199c95d91a979b7bd4fd07fe801dbe9e69183/src/models/Record.php#L172-L185 |
35,464 | hail-framework/framework | src/Database/Migration/Adapter/PostgresAdapter.php | PostgresAdapter.createSchema | public function createSchema($schemaName = 'public')
{
$sql = \sprintf('CREATE SCHEMA %s;',
$this->quoteSchemaName($schemaName)); // from postgres 9.3 we can use "CREATE SCHEMA IF NOT EXISTS schema_name"
$this->execute($sql);
} | php | public function createSchema($schemaName = 'public')
{
$sql = \sprintf('CREATE SCHEMA %s;',
$this->quoteSchemaName($schemaName)); // from postgres 9.3 we can use "CREATE SCHEMA IF NOT EXISTS schema_name"
$this->execute($sql);
} | [
"public",
"function",
"createSchema",
"(",
"$",
"schemaName",
"=",
"'public'",
")",
"{",
"$",
"sql",
"=",
"\\",
"sprintf",
"(",
"'CREATE SCHEMA %s;'",
",",
"$",
"this",
"->",
"quoteSchemaName",
"(",
"$",
"schemaName",
")",
")",
";",
"// from postgres 9.3 we can use \"CREATE SCHEMA IF NOT EXISTS schema_name\"",
"$",
"this",
"->",
"execute",
"(",
"$",
"sql",
")",
";",
"}"
] | Creates the specified schema.
@param string $schemaName Schema Name
@return void | [
"Creates",
"the",
"specified",
"schema",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Adapter/PostgresAdapter.php#L1053-L1058 |
35,465 | hail-framework/framework | src/Database/Migration/Adapter/PostgresAdapter.php | PostgresAdapter.isArrayType | protected function isArrayType($columnType)
{
if (!\preg_match('/^([a-z]+)(?:\[\]){1,}$/', $columnType, $matches)) {
return false;
}
$baseType = $matches[1];
return \in_array($baseType, $this->getColumnTypes(), true);
} | php | protected function isArrayType($columnType)
{
if (!\preg_match('/^([a-z]+)(?:\[\]){1,}$/', $columnType, $matches)) {
return false;
}
$baseType = $matches[1];
return \in_array($baseType, $this->getColumnTypes(), true);
} | [
"protected",
"function",
"isArrayType",
"(",
"$",
"columnType",
")",
"{",
"if",
"(",
"!",
"\\",
"preg_match",
"(",
"'/^([a-z]+)(?:\\[\\]){1,}$/'",
",",
"$",
"columnType",
",",
"$",
"matches",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"baseType",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"return",
"\\",
"in_array",
"(",
"$",
"baseType",
",",
"$",
"this",
"->",
"getColumnTypes",
"(",
")",
",",
"true",
")",
";",
"}"
] | Check if the given column is an array of a valid type.
@param string $columnType
@return bool | [
"Check",
"if",
"the",
"given",
"column",
"is",
"an",
"array",
"of",
"a",
"valid",
"type",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Adapter/PostgresAdapter.php#L1148-L1157 |
35,466 | hail-framework/framework | src/Util/Env.php | Env.get | public static function get(string $name): ?string
{
if (isset($_ENV[$name])) {
return $_ENV[$name];
}
if (isset($_SERVER[$name])) {
return $_SERVER[$name];
}
$value = \getenv($name);
return $value === false ? null : $value; // switch getenv default to null
} | php | public static function get(string $name): ?string
{
if (isset($_ENV[$name])) {
return $_ENV[$name];
}
if (isset($_SERVER[$name])) {
return $_SERVER[$name];
}
$value = \getenv($name);
return $value === false ? null : $value; // switch getenv default to null
} | [
"public",
"static",
"function",
"get",
"(",
"string",
"$",
"name",
")",
":",
"?",
"string",
"{",
"if",
"(",
"isset",
"(",
"$",
"_ENV",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"_ENV",
"[",
"$",
"name",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"_SERVER",
"[",
"$",
"name",
"]",
";",
"}",
"$",
"value",
"=",
"\\",
"getenv",
"(",
"$",
"name",
")",
";",
"return",
"$",
"value",
"===",
"false",
"?",
"null",
":",
"$",
"value",
";",
"// switch getenv default to null",
"}"
] | Search the different places for environment variables and return first value found.
@param string $name
@return string|null | [
"Search",
"the",
"different",
"places",
"for",
"environment",
"variables",
"and",
"return",
"first",
"value",
"found",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Env.php#L107-L120 |
35,467 | hail-framework/framework | src/Util/Env.php | Env.clear | public static function clear($name): void
{
if (static::$immutable) {
return;
}
if (\function_exists('\\putenv')) {
\putenv($name);
}
unset($_ENV[$name], $_SERVER[$name]);
} | php | public static function clear($name): void
{
if (static::$immutable) {
return;
}
if (\function_exists('\\putenv')) {
\putenv($name);
}
unset($_ENV[$name], $_SERVER[$name]);
} | [
"public",
"static",
"function",
"clear",
"(",
"$",
"name",
")",
":",
"void",
"{",
"if",
"(",
"static",
"::",
"$",
"immutable",
")",
"{",
"return",
";",
"}",
"if",
"(",
"\\",
"function_exists",
"(",
"'\\\\putenv'",
")",
")",
"{",
"\\",
"putenv",
"(",
"$",
"name",
")",
";",
"}",
"unset",
"(",
"$",
"_ENV",
"[",
"$",
"name",
"]",
",",
"$",
"_SERVER",
"[",
"$",
"name",
"]",
")",
";",
"}"
] | Clear an environment variable.
@param string $name
@return void | [
"Clear",
"an",
"environment",
"variable",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Env.php#L169-L180 |
35,468 | hail-framework/framework | src/Template/Tokenizer/Token/Element.php | Element.isClosingElementImplied | public function isClosingElementImplied(string $html): bool
{
$parent = $this->getParent();
if ($parent === null || !($parent instanceof self)) {
return false;
}
$name = $this->parseElementName($html);
$parentName = $parent->getName();
// HEAD: no closing tag.
if ($name === 'body' && $parentName === 'head') {
return true;
}
// P
if ($parentName === 'p' && \in_array($name, self::NO_CHILDREN_OF_P, true)) {
return true;
}
// LI
if ($parentName === 'li' && $name === 'li') {
return true;
}
// DT and DD
if (($parentName === 'dt' || $parentName === 'dd') && ($name === 'dt' || $name === 'dd')) {
return true;
}
// RP and RT
if (($parentName === 'rp' || $parentName === 'rt') && ($name === 'rp' || $name === 'rt')) {
return true;
}
return false;
} | php | public function isClosingElementImplied(string $html): bool
{
$parent = $this->getParent();
if ($parent === null || !($parent instanceof self)) {
return false;
}
$name = $this->parseElementName($html);
$parentName = $parent->getName();
// HEAD: no closing tag.
if ($name === 'body' && $parentName === 'head') {
return true;
}
// P
if ($parentName === 'p' && \in_array($name, self::NO_CHILDREN_OF_P, true)) {
return true;
}
// LI
if ($parentName === 'li' && $name === 'li') {
return true;
}
// DT and DD
if (($parentName === 'dt' || $parentName === 'dd') && ($name === 'dt' || $name === 'dd')) {
return true;
}
// RP and RT
if (($parentName === 'rp' || $parentName === 'rt') && ($name === 'rp' || $name === 'rt')) {
return true;
}
return false;
} | [
"public",
"function",
"isClosingElementImplied",
"(",
"string",
"$",
"html",
")",
":",
"bool",
"{",
"$",
"parent",
"=",
"$",
"this",
"->",
"getParent",
"(",
")",
";",
"if",
"(",
"$",
"parent",
"===",
"null",
"||",
"!",
"(",
"$",
"parent",
"instanceof",
"self",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"name",
"=",
"$",
"this",
"->",
"parseElementName",
"(",
"$",
"html",
")",
";",
"$",
"parentName",
"=",
"$",
"parent",
"->",
"getName",
"(",
")",
";",
"// HEAD: no closing tag.",
"if",
"(",
"$",
"name",
"===",
"'body'",
"&&",
"$",
"parentName",
"===",
"'head'",
")",
"{",
"return",
"true",
";",
"}",
"// P",
"if",
"(",
"$",
"parentName",
"===",
"'p'",
"&&",
"\\",
"in_array",
"(",
"$",
"name",
",",
"self",
"::",
"NO_CHILDREN_OF_P",
",",
"true",
")",
")",
"{",
"return",
"true",
";",
"}",
"// LI",
"if",
"(",
"$",
"parentName",
"===",
"'li'",
"&&",
"$",
"name",
"===",
"'li'",
")",
"{",
"return",
"true",
";",
"}",
"// DT and DD",
"if",
"(",
"(",
"$",
"parentName",
"===",
"'dt'",
"||",
"$",
"parentName",
"===",
"'dd'",
")",
"&&",
"(",
"$",
"name",
"===",
"'dt'",
"||",
"$",
"name",
"===",
"'dd'",
")",
")",
"{",
"return",
"true",
";",
"}",
"// RP and RT",
"if",
"(",
"(",
"$",
"parentName",
"===",
"'rp'",
"||",
"$",
"parentName",
"===",
"'rt'",
")",
"&&",
"(",
"$",
"name",
"===",
"'rp'",
"||",
"$",
"name",
"===",
"'rt'",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Does the parent have an implied closing tag?
@param string $html
@return boolean | [
"Does",
"the",
"parent",
"have",
"an",
"implied",
"closing",
"tag?"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Template/Tokenizer/Token/Element.php#L80-L116 |
35,469 | hail-framework/framework | src/Template/Tokenizer/Token/Element.php | Element.parse | public function parse(string $html): string
{
$html = ltrim($html);
$this->setTokenPosition($html);
try {
$this->name = $this->parseElementName($html);
$remainingHtml = $this->parseAttributes($html);
$posOfClosingBracket = $this->getPositionOfElementEndTag($remainingHtml);
// Is self-closing?
$posOfSelfClosingBracket = \mb_strpos($remainingHtml, '/>');
$remainingHtml = \mb_substr($remainingHtml, $posOfClosingBracket + 1);
if ($posOfSelfClosingBracket !== false && $posOfSelfClosingBracket === $posOfClosingBracket - 1) {
// Self-closing element. (Note: $this->valuue is unchanged.)
return $remainingHtml;
}
// Lets close those closed-only elements that are left open.
if (\in_array($this->name, self::VOID_ELEMENTS, true)) {
return $remainingHtml;
}
// Open element.
return $this->parseContents($remainingHtml);
} catch (ParseException $e) {
if ($this->getThrowOnError()) {
throw $e;
}
}
return '';
} | php | public function parse(string $html): string
{
$html = ltrim($html);
$this->setTokenPosition($html);
try {
$this->name = $this->parseElementName($html);
$remainingHtml = $this->parseAttributes($html);
$posOfClosingBracket = $this->getPositionOfElementEndTag($remainingHtml);
// Is self-closing?
$posOfSelfClosingBracket = \mb_strpos($remainingHtml, '/>');
$remainingHtml = \mb_substr($remainingHtml, $posOfClosingBracket + 1);
if ($posOfSelfClosingBracket !== false && $posOfSelfClosingBracket === $posOfClosingBracket - 1) {
// Self-closing element. (Note: $this->valuue is unchanged.)
return $remainingHtml;
}
// Lets close those closed-only elements that are left open.
if (\in_array($this->name, self::VOID_ELEMENTS, true)) {
return $remainingHtml;
}
// Open element.
return $this->parseContents($remainingHtml);
} catch (ParseException $e) {
if ($this->getThrowOnError()) {
throw $e;
}
}
return '';
} | [
"public",
"function",
"parse",
"(",
"string",
"$",
"html",
")",
":",
"string",
"{",
"$",
"html",
"=",
"ltrim",
"(",
"$",
"html",
")",
";",
"$",
"this",
"->",
"setTokenPosition",
"(",
"$",
"html",
")",
";",
"try",
"{",
"$",
"this",
"->",
"name",
"=",
"$",
"this",
"->",
"parseElementName",
"(",
"$",
"html",
")",
";",
"$",
"remainingHtml",
"=",
"$",
"this",
"->",
"parseAttributes",
"(",
"$",
"html",
")",
";",
"$",
"posOfClosingBracket",
"=",
"$",
"this",
"->",
"getPositionOfElementEndTag",
"(",
"$",
"remainingHtml",
")",
";",
"// Is self-closing?",
"$",
"posOfSelfClosingBracket",
"=",
"\\",
"mb_strpos",
"(",
"$",
"remainingHtml",
",",
"'/>'",
")",
";",
"$",
"remainingHtml",
"=",
"\\",
"mb_substr",
"(",
"$",
"remainingHtml",
",",
"$",
"posOfClosingBracket",
"+",
"1",
")",
";",
"if",
"(",
"$",
"posOfSelfClosingBracket",
"!==",
"false",
"&&",
"$",
"posOfSelfClosingBracket",
"===",
"$",
"posOfClosingBracket",
"-",
"1",
")",
"{",
"// Self-closing element. (Note: $this->valuue is unchanged.)",
"return",
"$",
"remainingHtml",
";",
"}",
"// Lets close those closed-only elements that are left open.",
"if",
"(",
"\\",
"in_array",
"(",
"$",
"this",
"->",
"name",
",",
"self",
"::",
"VOID_ELEMENTS",
",",
"true",
")",
")",
"{",
"return",
"$",
"remainingHtml",
";",
"}",
"// Open element.",
"return",
"$",
"this",
"->",
"parseContents",
"(",
"$",
"remainingHtml",
")",
";",
"}",
"catch",
"(",
"ParseException",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getThrowOnError",
"(",
")",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"}",
"return",
"''",
";",
"}"
] | Will parse this element.
@param string $html
@return string Remaining HTML. | [
"Will",
"parse",
"this",
"element",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Template/Tokenizer/Token/Element.php#L125-L157 |
35,470 | hail-framework/framework | src/Template/Tokenizer/Token/Element.php | Element.parseContents | private function parseContents(string $html): string
{
if (\trim($html) === '') {
return '';
}
// Determine value.
$this->value = $html;
if (\preg_match("/(.*)<\/\s*" . $this->name . "\s*>/iU", $html, $valueMatches) === 1) {
$this->value = $valueMatches[1];
}
// Don't parse contents of "iframe" element.
if ($this->name === 'iframe') {
return $this->parseNoContents('iframe', $html);
}
// Only TEXT inside a "script" element.
if ($this->name === 'script') {
return $this->parseForeignContents('script', $html);
}
// Only TEXT inside a "style" element.
if ($this->name === 'style') {
return $this->parseForeignContents('style', $html);
}
// Parse contents one token at a time.
$remainingHtml = $html;
while ($this->isAnotherTokenPresent($remainingHtml)) {
$token = Tokenizer::buildFromHtml($remainingHtml, $this);
if (!$token instanceof TokenInterface || $token->isClosingElementImplied($remainingHtml)) {
return $remainingHtml;
}
$remainingHtml = $token->parse($remainingHtml);
$this->children[] = $token;
}
$this->removeLastTokenIfContainsOnlyWhitespace();
// Remove remaining closing tag.
$posOfClosingBracket = \mb_strpos($remainingHtml, '>');
return \mb_substr($remainingHtml, $posOfClosingBracket + 1);
} | php | private function parseContents(string $html): string
{
if (\trim($html) === '') {
return '';
}
// Determine value.
$this->value = $html;
if (\preg_match("/(.*)<\/\s*" . $this->name . "\s*>/iU", $html, $valueMatches) === 1) {
$this->value = $valueMatches[1];
}
// Don't parse contents of "iframe" element.
if ($this->name === 'iframe') {
return $this->parseNoContents('iframe', $html);
}
// Only TEXT inside a "script" element.
if ($this->name === 'script') {
return $this->parseForeignContents('script', $html);
}
// Only TEXT inside a "style" element.
if ($this->name === 'style') {
return $this->parseForeignContents('style', $html);
}
// Parse contents one token at a time.
$remainingHtml = $html;
while ($this->isAnotherTokenPresent($remainingHtml)) {
$token = Tokenizer::buildFromHtml($remainingHtml, $this);
if (!$token instanceof TokenInterface || $token->isClosingElementImplied($remainingHtml)) {
return $remainingHtml;
}
$remainingHtml = $token->parse($remainingHtml);
$this->children[] = $token;
}
$this->removeLastTokenIfContainsOnlyWhitespace();
// Remove remaining closing tag.
$posOfClosingBracket = \mb_strpos($remainingHtml, '>');
return \mb_substr($remainingHtml, $posOfClosingBracket + 1);
} | [
"private",
"function",
"parseContents",
"(",
"string",
"$",
"html",
")",
":",
"string",
"{",
"if",
"(",
"\\",
"trim",
"(",
"$",
"html",
")",
"===",
"''",
")",
"{",
"return",
"''",
";",
"}",
"// Determine value.",
"$",
"this",
"->",
"value",
"=",
"$",
"html",
";",
"if",
"(",
"\\",
"preg_match",
"(",
"\"/(.*)<\\/\\s*\"",
".",
"$",
"this",
"->",
"name",
".",
"\"\\s*>/iU\"",
",",
"$",
"html",
",",
"$",
"valueMatches",
")",
"===",
"1",
")",
"{",
"$",
"this",
"->",
"value",
"=",
"$",
"valueMatches",
"[",
"1",
"]",
";",
"}",
"// Don't parse contents of \"iframe\" element.",
"if",
"(",
"$",
"this",
"->",
"name",
"===",
"'iframe'",
")",
"{",
"return",
"$",
"this",
"->",
"parseNoContents",
"(",
"'iframe'",
",",
"$",
"html",
")",
";",
"}",
"// Only TEXT inside a \"script\" element.",
"if",
"(",
"$",
"this",
"->",
"name",
"===",
"'script'",
")",
"{",
"return",
"$",
"this",
"->",
"parseForeignContents",
"(",
"'script'",
",",
"$",
"html",
")",
";",
"}",
"// Only TEXT inside a \"style\" element.",
"if",
"(",
"$",
"this",
"->",
"name",
"===",
"'style'",
")",
"{",
"return",
"$",
"this",
"->",
"parseForeignContents",
"(",
"'style'",
",",
"$",
"html",
")",
";",
"}",
"// Parse contents one token at a time.",
"$",
"remainingHtml",
"=",
"$",
"html",
";",
"while",
"(",
"$",
"this",
"->",
"isAnotherTokenPresent",
"(",
"$",
"remainingHtml",
")",
")",
"{",
"$",
"token",
"=",
"Tokenizer",
"::",
"buildFromHtml",
"(",
"$",
"remainingHtml",
",",
"$",
"this",
")",
";",
"if",
"(",
"!",
"$",
"token",
"instanceof",
"TokenInterface",
"||",
"$",
"token",
"->",
"isClosingElementImplied",
"(",
"$",
"remainingHtml",
")",
")",
"{",
"return",
"$",
"remainingHtml",
";",
"}",
"$",
"remainingHtml",
"=",
"$",
"token",
"->",
"parse",
"(",
"$",
"remainingHtml",
")",
";",
"$",
"this",
"->",
"children",
"[",
"]",
"=",
"$",
"token",
";",
"}",
"$",
"this",
"->",
"removeLastTokenIfContainsOnlyWhitespace",
"(",
")",
";",
"// Remove remaining closing tag.",
"$",
"posOfClosingBracket",
"=",
"\\",
"mb_strpos",
"(",
"$",
"remainingHtml",
",",
"'>'",
")",
";",
"return",
"\\",
"mb_substr",
"(",
"$",
"remainingHtml",
",",
"$",
"posOfClosingBracket",
"+",
"1",
")",
";",
"}"
] | Will parse the contents of this element.
@param string $html
@return string Remaining HTML. | [
"Will",
"parse",
"the",
"contents",
"of",
"this",
"element",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Template/Tokenizer/Token/Element.php#L234-L280 |
35,471 | hail-framework/framework | src/Template/Tokenizer/Token/Element.php | Element.parseElementName | private function parseElementName(string $html): string
{
$html = \trim($html);
$elementMatchSuccessful = \preg_match(
"/^(<(([a-z0-9\-]+:)?[a-z0-9\-]+))/i",
$html,
$elementMatches
);
if ($elementMatchSuccessful !== 1) {
if ($this->getThrowOnError()) {
throw new ParseException('Invalid element name. Truncated html = ' . \mb_substr($html, 0, 20));
}
return '';
}
return \mb_strtolower($elementMatches[2]);
} | php | private function parseElementName(string $html): string
{
$html = \trim($html);
$elementMatchSuccessful = \preg_match(
"/^(<(([a-z0-9\-]+:)?[a-z0-9\-]+))/i",
$html,
$elementMatches
);
if ($elementMatchSuccessful !== 1) {
if ($this->getThrowOnError()) {
throw new ParseException('Invalid element name. Truncated html = ' . \mb_substr($html, 0, 20));
}
return '';
}
return \mb_strtolower($elementMatches[2]);
} | [
"private",
"function",
"parseElementName",
"(",
"string",
"$",
"html",
")",
":",
"string",
"{",
"$",
"html",
"=",
"\\",
"trim",
"(",
"$",
"html",
")",
";",
"$",
"elementMatchSuccessful",
"=",
"\\",
"preg_match",
"(",
"\"/^(<(([a-z0-9\\-]+:)?[a-z0-9\\-]+))/i\"",
",",
"$",
"html",
",",
"$",
"elementMatches",
")",
";",
"if",
"(",
"$",
"elementMatchSuccessful",
"!==",
"1",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getThrowOnError",
"(",
")",
")",
"{",
"throw",
"new",
"ParseException",
"(",
"'Invalid element name. Truncated html = '",
".",
"\\",
"mb_substr",
"(",
"$",
"html",
",",
"0",
",",
"20",
")",
")",
";",
"}",
"return",
"''",
";",
"}",
"return",
"\\",
"mb_strtolower",
"(",
"$",
"elementMatches",
"[",
"2",
"]",
")",
";",
"}"
] | Will get the element name from the html string.
@param $html string
@return string The element name. | [
"Will",
"get",
"the",
"element",
"name",
"from",
"the",
"html",
"string",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Template/Tokenizer/Token/Element.php#L289-L306 |
35,472 | hail-framework/framework | src/Template/Tokenizer/Token/Element.php | Element.parseForeignContents | private function parseForeignContents(string $tag, string $html): string
{
$remainingHtml = \ltrim($html);
// Find all contents.
$remainingHtml = $this->determineRemainingHtmlOfForeignContents(
$tag,
$html,
$remainingHtml
);
// Handle no contents.
if ($this->value === '') {
return $remainingHtml;
}
if ($tag === 'script') {
$text = new TextJs($this, $this->value);
} elseif ($tag === 'style') {
$text = new TextCss($this, $this->value);
} else {
$text = new Text($this, $this->value);
}
$this->children[] = $text;
return $remainingHtml;
} | php | private function parseForeignContents(string $tag, string $html): string
{
$remainingHtml = \ltrim($html);
// Find all contents.
$remainingHtml = $this->determineRemainingHtmlOfForeignContents(
$tag,
$html,
$remainingHtml
);
// Handle no contents.
if ($this->value === '') {
return $remainingHtml;
}
if ($tag === 'script') {
$text = new TextJs($this, $this->value);
} elseif ($tag === 'style') {
$text = new TextCss($this, $this->value);
} else {
$text = new Text($this, $this->value);
}
$this->children[] = $text;
return $remainingHtml;
} | [
"private",
"function",
"parseForeignContents",
"(",
"string",
"$",
"tag",
",",
"string",
"$",
"html",
")",
":",
"string",
"{",
"$",
"remainingHtml",
"=",
"\\",
"ltrim",
"(",
"$",
"html",
")",
";",
"// Find all contents.",
"$",
"remainingHtml",
"=",
"$",
"this",
"->",
"determineRemainingHtmlOfForeignContents",
"(",
"$",
"tag",
",",
"$",
"html",
",",
"$",
"remainingHtml",
")",
";",
"// Handle no contents.",
"if",
"(",
"$",
"this",
"->",
"value",
"===",
"''",
")",
"{",
"return",
"$",
"remainingHtml",
";",
"}",
"if",
"(",
"$",
"tag",
"===",
"'script'",
")",
"{",
"$",
"text",
"=",
"new",
"TextJs",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"value",
")",
";",
"}",
"elseif",
"(",
"$",
"tag",
"===",
"'style'",
")",
"{",
"$",
"text",
"=",
"new",
"TextCss",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"value",
")",
";",
"}",
"else",
"{",
"$",
"text",
"=",
"new",
"Text",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"value",
")",
";",
"}",
"$",
"this",
"->",
"children",
"[",
"]",
"=",
"$",
"text",
";",
"return",
"$",
"remainingHtml",
";",
"}"
] | Will parse the script and style contents correctly.
@param $tag string
@param $html string
@return string The remaining HTML. | [
"Will",
"parse",
"the",
"script",
"and",
"style",
"contents",
"correctly",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Template/Tokenizer/Token/Element.php#L316-L343 |
35,473 | hail-framework/framework | src/Template/Tokenizer/Token/Element.php | Element.parseNoContents | private function parseNoContents(string $tag, string $html): string
{
$remainingHtml = \ltrim($html);
$matchingResult = \preg_match(
"/(<\/\s*" . $tag . "\s*>)/i",
$html,
$endOfScriptMatches
);
if ($matchingResult === 0) {
return '';
}
$closingTag = $endOfScriptMatches[1];
$this->value = \mb_substr($remainingHtml, 0, \mb_strpos($html, $closingTag));
return \mb_substr(
\mb_strstr($remainingHtml, $closingTag),
\mb_strlen($closingTag)
);
} | php | private function parseNoContents(string $tag, string $html): string
{
$remainingHtml = \ltrim($html);
$matchingResult = \preg_match(
"/(<\/\s*" . $tag . "\s*>)/i",
$html,
$endOfScriptMatches
);
if ($matchingResult === 0) {
return '';
}
$closingTag = $endOfScriptMatches[1];
$this->value = \mb_substr($remainingHtml, 0, \mb_strpos($html, $closingTag));
return \mb_substr(
\mb_strstr($remainingHtml, $closingTag),
\mb_strlen($closingTag)
);
} | [
"private",
"function",
"parseNoContents",
"(",
"string",
"$",
"tag",
",",
"string",
"$",
"html",
")",
":",
"string",
"{",
"$",
"remainingHtml",
"=",
"\\",
"ltrim",
"(",
"$",
"html",
")",
";",
"$",
"matchingResult",
"=",
"\\",
"preg_match",
"(",
"\"/(<\\/\\s*\"",
".",
"$",
"tag",
".",
"\"\\s*>)/i\"",
",",
"$",
"html",
",",
"$",
"endOfScriptMatches",
")",
";",
"if",
"(",
"$",
"matchingResult",
"===",
"0",
")",
"{",
"return",
"''",
";",
"}",
"$",
"closingTag",
"=",
"$",
"endOfScriptMatches",
"[",
"1",
"]",
";",
"$",
"this",
"->",
"value",
"=",
"\\",
"mb_substr",
"(",
"$",
"remainingHtml",
",",
"0",
",",
"\\",
"mb_strpos",
"(",
"$",
"html",
",",
"$",
"closingTag",
")",
")",
";",
"return",
"\\",
"mb_substr",
"(",
"\\",
"mb_strstr",
"(",
"$",
"remainingHtml",
",",
"$",
"closingTag",
")",
",",
"\\",
"mb_strlen",
"(",
"$",
"closingTag",
")",
")",
";",
"}"
] | Will not parse the contents of an element.
"iframe" elements.
@param $tag string
@param $html string
@return string The remaining HTML. | [
"Will",
"not",
"parse",
"the",
"contents",
"of",
"an",
"element",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Template/Tokenizer/Token/Element.php#L355-L374 |
35,474 | hail-framework/framework | src/Database/Migration/Adapter/AdapterFactory.php | AdapterFactory.registerAdapter | public function registerAdapter($name, $class)
{
if (!is_subclass_of($class, AdapterInterface::class)) {
throw new \RuntimeException(sprintf(
'Adapter class "%s" must implement ' . AdapterInterface::class,
$class
));
}
$this->adapters[$name] = $class;
return $this;
} | php | public function registerAdapter($name, $class)
{
if (!is_subclass_of($class, AdapterInterface::class)) {
throw new \RuntimeException(sprintf(
'Adapter class "%s" must implement ' . AdapterInterface::class,
$class
));
}
$this->adapters[$name] = $class;
return $this;
} | [
"public",
"function",
"registerAdapter",
"(",
"$",
"name",
",",
"$",
"class",
")",
"{",
"if",
"(",
"!",
"is_subclass_of",
"(",
"$",
"class",
",",
"AdapterInterface",
"::",
"class",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Adapter class \"%s\" must implement '",
".",
"AdapterInterface",
"::",
"class",
",",
"$",
"class",
")",
")",
";",
"}",
"$",
"this",
"->",
"adapters",
"[",
"$",
"name",
"]",
"=",
"$",
"class",
";",
"return",
"$",
"this",
";",
"}"
] | Add or replace an adapter with a fully qualified class name.
@throws \RuntimeException
@param string $name
@param string $class
@return $this | [
"Add",
"or",
"replace",
"an",
"adapter",
"with",
"a",
"fully",
"qualified",
"class",
"name",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Adapter/AdapterFactory.php#L93-L104 |
35,475 | hail-framework/framework | src/Database/Migration/Adapter/AdapterFactory.php | AdapterFactory.registerWrapper | public function registerWrapper($name, $class)
{
if (!is_subclass_of($class, WrapperInterface::class)) {
throw new \RuntimeException(sprintf(
'Wrapper class "%s" must be implement ' . WrapperInterface::class,
$class
));
}
$this->wrappers[$name] = $class;
return $this;
} | php | public function registerWrapper($name, $class)
{
if (!is_subclass_of($class, WrapperInterface::class)) {
throw new \RuntimeException(sprintf(
'Wrapper class "%s" must be implement ' . WrapperInterface::class,
$class
));
}
$this->wrappers[$name] = $class;
return $this;
} | [
"public",
"function",
"registerWrapper",
"(",
"$",
"name",
",",
"$",
"class",
")",
"{",
"if",
"(",
"!",
"is_subclass_of",
"(",
"$",
"class",
",",
"WrapperInterface",
"::",
"class",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Wrapper class \"%s\" must be implement '",
".",
"WrapperInterface",
"::",
"class",
",",
"$",
"class",
")",
")",
";",
"}",
"$",
"this",
"->",
"wrappers",
"[",
"$",
"name",
"]",
"=",
"$",
"class",
";",
"return",
"$",
"this",
";",
"}"
] | Add or replace a wrapper with a fully qualified class name.
@throws \RuntimeException
@param string $name
@param string $class
@return $this | [
"Add",
"or",
"replace",
"a",
"wrapper",
"with",
"a",
"fully",
"qualified",
"class",
"name",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Adapter/AdapterFactory.php#L152-L163 |
35,476 | aimeos/ai-slim | lib/custom/src/MW/View/Helper/Response/Slim.php | Slim.createStream | public function createStream( $resource )
{
if( is_resource( $resource ) === true ) {
return new \Slim\Http\Stream( $resource );
}
if( ( $fh = @fopen( $resource, 'r' ) ) !== false ) {
return new \Slim\Http\Stream( $fh );
}
throw new \Aimeos\MW\Exception( sprintf( 'Unable to open file "%1$s"', $resource ) );
} | php | public function createStream( $resource )
{
if( is_resource( $resource ) === true ) {
return new \Slim\Http\Stream( $resource );
}
if( ( $fh = @fopen( $resource, 'r' ) ) !== false ) {
return new \Slim\Http\Stream( $fh );
}
throw new \Aimeos\MW\Exception( sprintf( 'Unable to open file "%1$s"', $resource ) );
} | [
"public",
"function",
"createStream",
"(",
"$",
"resource",
")",
"{",
"if",
"(",
"is_resource",
"(",
"$",
"resource",
")",
"===",
"true",
")",
"{",
"return",
"new",
"\\",
"Slim",
"\\",
"Http",
"\\",
"Stream",
"(",
"$",
"resource",
")",
";",
"}",
"if",
"(",
"(",
"$",
"fh",
"=",
"@",
"fopen",
"(",
"$",
"resource",
",",
"'r'",
")",
")",
"!==",
"false",
")",
"{",
"return",
"new",
"\\",
"Slim",
"\\",
"Http",
"\\",
"Stream",
"(",
"$",
"fh",
")",
";",
"}",
"throw",
"new",
"\\",
"Aimeos",
"\\",
"MW",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'Unable to open file \"%1$s\"'",
",",
"$",
"resource",
")",
")",
";",
"}"
] | Creates a new PSR-7 stream object
@param string|resource Absolute file path or file descriptor
@return \Psr\Http\Message\StreamInterface Stream object | [
"Creates",
"a",
"new",
"PSR",
"-",
"7",
"stream",
"object"
] | 13f22efe21450df4c822d9a77034f66a471cfa69 | https://github.com/aimeos/ai-slim/blob/13f22efe21450df4c822d9a77034f66a471cfa69/lib/custom/src/MW/View/Helper/Response/Slim.php#L32-L43 |
35,477 | htmlburger/wpemerge-cli | src/NodePackageManagers/Proxy.php | Proxy.getNodePackageManager | protected function getNodePackageManager() {
$is_windows = strtolower( substr( PHP_OS, 0, 3 ) ) === 'win';
$node_package_managers = [
'yarn' => Yarn::class,
'npm' => Npm::class,
];
foreach ( $node_package_managers as $manager => $class ) {
$command = $is_windows ? 'where ' . escapeshellarg( $manager ) : 'which ' . escapeshellarg( $manager );
try {
$output = App::execute( $command );
} catch ( ProcessFailedException $e ) {
continue;
}
if ( ! trim( $output ) ) {
continue;
}
return new $class();
}
throw new RuntimeException( 'Could not find a node package manager. Please check if npm is added to your PATH.' );
} | php | protected function getNodePackageManager() {
$is_windows = strtolower( substr( PHP_OS, 0, 3 ) ) === 'win';
$node_package_managers = [
'yarn' => Yarn::class,
'npm' => Npm::class,
];
foreach ( $node_package_managers as $manager => $class ) {
$command = $is_windows ? 'where ' . escapeshellarg( $manager ) : 'which ' . escapeshellarg( $manager );
try {
$output = App::execute( $command );
} catch ( ProcessFailedException $e ) {
continue;
}
if ( ! trim( $output ) ) {
continue;
}
return new $class();
}
throw new RuntimeException( 'Could not find a node package manager. Please check if npm is added to your PATH.' );
} | [
"protected",
"function",
"getNodePackageManager",
"(",
")",
"{",
"$",
"is_windows",
"=",
"strtolower",
"(",
"substr",
"(",
"PHP_OS",
",",
"0",
",",
"3",
")",
")",
"===",
"'win'",
";",
"$",
"node_package_managers",
"=",
"[",
"'yarn'",
"=>",
"Yarn",
"::",
"class",
",",
"'npm'",
"=>",
"Npm",
"::",
"class",
",",
"]",
";",
"foreach",
"(",
"$",
"node_package_managers",
"as",
"$",
"manager",
"=>",
"$",
"class",
")",
"{",
"$",
"command",
"=",
"$",
"is_windows",
"?",
"'where '",
".",
"escapeshellarg",
"(",
"$",
"manager",
")",
":",
"'which '",
".",
"escapeshellarg",
"(",
"$",
"manager",
")",
";",
"try",
"{",
"$",
"output",
"=",
"App",
"::",
"execute",
"(",
"$",
"command",
")",
";",
"}",
"catch",
"(",
"ProcessFailedException",
"$",
"e",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"!",
"trim",
"(",
"$",
"output",
")",
")",
"{",
"continue",
";",
"}",
"return",
"new",
"$",
"class",
"(",
")",
";",
"}",
"throw",
"new",
"RuntimeException",
"(",
"'Could not find a node package manager. Please check if npm is added to your PATH.'",
")",
";",
"}"
] | Get an instance of the first available package manager
@return NodePackageManagerInterface | [
"Get",
"an",
"instance",
"of",
"the",
"first",
"available",
"package",
"manager"
] | 075f1982b7dd87039a4e7bbc05caf676a10fe862 | https://github.com/htmlburger/wpemerge-cli/blob/075f1982b7dd87039a4e7bbc05caf676a10fe862/src/NodePackageManagers/Proxy.php#L51-L75 |
35,478 | hail-framework/framework | src/Container/Builder.php | Builder.create | public static function create(ContainerInterface $container, string $class, array $map = [], array $params = null)
{
if (!\class_exists($class)) {
throw new \InvalidArgumentException("unable to create component: {$class} (autoloading failed)");
}
if (\method_exists($class, 'getInstance')) {
return $class::getInstance();
}
if ($params === null) {
$reflection = new \ReflectionClass($class);
if (!$reflection->isInstantiable()) {
throw new \InvalidArgumentException("unable to create instance of abstract class: {$class}");
}
$constructor = $reflection->getConstructor();
if ($constructor && ($params = $constructor->getParameters()) !== []) {
$params = static::resolve($container, $params, $map, false);
} else {
$params = [];
}
return $reflection->newInstanceArgs($params);
}
if ($params !== []) {
$params = static::resolve($container, $params, $map, false);
}
return new $class(...$params);
} | php | public static function create(ContainerInterface $container, string $class, array $map = [], array $params = null)
{
if (!\class_exists($class)) {
throw new \InvalidArgumentException("unable to create component: {$class} (autoloading failed)");
}
if (\method_exists($class, 'getInstance')) {
return $class::getInstance();
}
if ($params === null) {
$reflection = new \ReflectionClass($class);
if (!$reflection->isInstantiable()) {
throw new \InvalidArgumentException("unable to create instance of abstract class: {$class}");
}
$constructor = $reflection->getConstructor();
if ($constructor && ($params = $constructor->getParameters()) !== []) {
$params = static::resolve($container, $params, $map, false);
} else {
$params = [];
}
return $reflection->newInstanceArgs($params);
}
if ($params !== []) {
$params = static::resolve($container, $params, $map, false);
}
return new $class(...$params);
} | [
"public",
"static",
"function",
"create",
"(",
"ContainerInterface",
"$",
"container",
",",
"string",
"$",
"class",
",",
"array",
"$",
"map",
"=",
"[",
"]",
",",
"array",
"$",
"params",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"\\",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"unable to create component: {$class} (autoloading failed)\"",
")",
";",
"}",
"if",
"(",
"\\",
"method_exists",
"(",
"$",
"class",
",",
"'getInstance'",
")",
")",
"{",
"return",
"$",
"class",
"::",
"getInstance",
"(",
")",
";",
"}",
"if",
"(",
"$",
"params",
"===",
"null",
")",
"{",
"$",
"reflection",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"class",
")",
";",
"if",
"(",
"!",
"$",
"reflection",
"->",
"isInstantiable",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"unable to create instance of abstract class: {$class}\"",
")",
";",
"}",
"$",
"constructor",
"=",
"$",
"reflection",
"->",
"getConstructor",
"(",
")",
";",
"if",
"(",
"$",
"constructor",
"&&",
"(",
"$",
"params",
"=",
"$",
"constructor",
"->",
"getParameters",
"(",
")",
")",
"!==",
"[",
"]",
")",
"{",
"$",
"params",
"=",
"static",
"::",
"resolve",
"(",
"$",
"container",
",",
"$",
"params",
",",
"$",
"map",
",",
"false",
")",
";",
"}",
"else",
"{",
"$",
"params",
"=",
"[",
"]",
";",
"}",
"return",
"$",
"reflection",
"->",
"newInstanceArgs",
"(",
"$",
"params",
")",
";",
"}",
"if",
"(",
"$",
"params",
"!==",
"[",
"]",
")",
"{",
"$",
"params",
"=",
"static",
"::",
"resolve",
"(",
"$",
"container",
",",
"$",
"params",
",",
"$",
"map",
",",
"false",
")",
";",
"}",
"return",
"new",
"$",
"class",
"(",
"...",
"$",
"params",
")",
";",
"}"
] | Create an instance of a given class.
@noinspection PhpDocMissingThrowsInspection
@param ContainerInterface $container
@param string $class fully-qualified class-name
@param mixed[] $map mixed list/map of parameter values (and/or boxed values)
@param \ReflectionParameter[]|array[]|null $params
@return mixed
@throws \InvalidArgumentException | [
"Create",
"an",
"instance",
"of",
"a",
"given",
"class",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Container/Builder.php#L67-L100 |
35,479 | hail-framework/framework | src/Container/Builder.php | Builder.resolve | protected static function resolve(
ContainerInterface $container,
array $params,
array $map,
bool $safe = true
): array {
$args = [];
foreach ($params as $index => $param) {
$value = static::getParameterValue($container, $param, $index, $map, $safe);
if ($value instanceof \Closure) {
$value = $value($container); // unbox a boxed value
}
$args[] = $value; // argument resolved!
}
return $args;
} | php | protected static function resolve(
ContainerInterface $container,
array $params,
array $map,
bool $safe = true
): array {
$args = [];
foreach ($params as $index => $param) {
$value = static::getParameterValue($container, $param, $index, $map, $safe);
if ($value instanceof \Closure) {
$value = $value($container); // unbox a boxed value
}
$args[] = $value; // argument resolved!
}
return $args;
} | [
"protected",
"static",
"function",
"resolve",
"(",
"ContainerInterface",
"$",
"container",
",",
"array",
"$",
"params",
",",
"array",
"$",
"map",
",",
"bool",
"$",
"safe",
"=",
"true",
")",
":",
"array",
"{",
"$",
"args",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"index",
"=>",
"$",
"param",
")",
"{",
"$",
"value",
"=",
"static",
"::",
"getParameterValue",
"(",
"$",
"container",
",",
"$",
"param",
",",
"$",
"index",
",",
"$",
"map",
",",
"$",
"safe",
")",
";",
"if",
"(",
"$",
"value",
"instanceof",
"\\",
"Closure",
")",
"{",
"$",
"value",
"=",
"$",
"value",
"(",
"$",
"container",
")",
";",
"// unbox a boxed value",
"}",
"$",
"args",
"[",
"]",
"=",
"$",
"value",
";",
"// argument resolved!",
"}",
"return",
"$",
"args",
";",
"}"
] | Internally resolves parameters to functions or constructors.
@param ContainerInterface $container
@param \ReflectionParameter[]|array[] $params parameter reflections
@param array $map mixed list/map of parameter values (and/or boxed values)
@param bool $safe if TRUE, it's considered safe to resolve against parameter names
@return array parameters
@throws \InvalidArgumentException | [
"Internally",
"resolves",
"parameters",
"to",
"functions",
"or",
"constructors",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Container/Builder.php#L137-L155 |
35,480 | hail-framework/framework | src/Debugger/Helpers.php | Helpers.editorLink | public static function editorLink(string $file, int $line = null): string
{
$file = \strtr($origFile = $file, Debugger::$editorMapping);
if ($editor = self::editorUri($origFile, $line)) {
$file = \str_replace('\\', '/', $file);
if (\preg_match('#(^[a-z]:)?/.{1,50}$#i', $file, $m) && \strlen($file) > \strlen($m[0])) {
$file = '...' . $m[0];
}
$file = \str_replace('/', DIRECTORY_SEPARATOR, $file);
return self::formatHtml('<a href="%" title="%">%<b>%</b>%</a>',
$editor,
$file . ($line ? ":$line" : ''),
\rtrim(\dirname($file), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR,
\basename($file),
$line ? ":$line" : ''
);
}
return self::formatHtml('<span>%</span>', $file . ($line ? ":$line" : ''));
} | php | public static function editorLink(string $file, int $line = null): string
{
$file = \strtr($origFile = $file, Debugger::$editorMapping);
if ($editor = self::editorUri($origFile, $line)) {
$file = \str_replace('\\', '/', $file);
if (\preg_match('#(^[a-z]:)?/.{1,50}$#i', $file, $m) && \strlen($file) > \strlen($m[0])) {
$file = '...' . $m[0];
}
$file = \str_replace('/', DIRECTORY_SEPARATOR, $file);
return self::formatHtml('<a href="%" title="%">%<b>%</b>%</a>',
$editor,
$file . ($line ? ":$line" : ''),
\rtrim(\dirname($file), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR,
\basename($file),
$line ? ":$line" : ''
);
}
return self::formatHtml('<span>%</span>', $file . ($line ? ":$line" : ''));
} | [
"public",
"static",
"function",
"editorLink",
"(",
"string",
"$",
"file",
",",
"int",
"$",
"line",
"=",
"null",
")",
":",
"string",
"{",
"$",
"file",
"=",
"\\",
"strtr",
"(",
"$",
"origFile",
"=",
"$",
"file",
",",
"Debugger",
"::",
"$",
"editorMapping",
")",
";",
"if",
"(",
"$",
"editor",
"=",
"self",
"::",
"editorUri",
"(",
"$",
"origFile",
",",
"$",
"line",
")",
")",
"{",
"$",
"file",
"=",
"\\",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"file",
")",
";",
"if",
"(",
"\\",
"preg_match",
"(",
"'#(^[a-z]:)?/.{1,50}$#i'",
",",
"$",
"file",
",",
"$",
"m",
")",
"&&",
"\\",
"strlen",
"(",
"$",
"file",
")",
">",
"\\",
"strlen",
"(",
"$",
"m",
"[",
"0",
"]",
")",
")",
"{",
"$",
"file",
"=",
"'...'",
".",
"$",
"m",
"[",
"0",
"]",
";",
"}",
"$",
"file",
"=",
"\\",
"str_replace",
"(",
"'/'",
",",
"DIRECTORY_SEPARATOR",
",",
"$",
"file",
")",
";",
"return",
"self",
"::",
"formatHtml",
"(",
"'<a href=\"%\" title=\"%\">%<b>%</b>%</a>'",
",",
"$",
"editor",
",",
"$",
"file",
".",
"(",
"$",
"line",
"?",
"\":$line\"",
":",
"''",
")",
",",
"\\",
"rtrim",
"(",
"\\",
"dirname",
"(",
"$",
"file",
")",
",",
"DIRECTORY_SEPARATOR",
")",
".",
"DIRECTORY_SEPARATOR",
",",
"\\",
"basename",
"(",
"$",
"file",
")",
",",
"$",
"line",
"?",
"\":$line\"",
":",
"''",
")",
";",
"}",
"return",
"self",
"::",
"formatHtml",
"(",
"'<span>%</span>'",
",",
"$",
"file",
".",
"(",
"$",
"line",
"?",
"\":$line\"",
":",
"''",
")",
")",
";",
"}"
] | Returns HTML link to editor.
@param string $file
@param int|null $line
@return string | [
"Returns",
"HTML",
"link",
"to",
"editor",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Helpers.php#L29-L49 |
35,481 | hail-framework/framework | src/Debugger/Helpers.php | Helpers.editorUri | public static function editorUri(
string $file,
int $line = null,
string $action = 'open',
string $search = '',
string $replace = ''
): ?string {
if (Debugger::$editor && $file && ($action === 'create' || is_file($file))) {
$file = \str_replace('/', DIRECTORY_SEPARATOR, $file);
$file = \strtr($file, Debugger::$editorMapping);
return strtr(Debugger::$editor, [
'%action' => $action,
'%file' => rawurlencode($file),
'%line' => $line ?: 1,
'%search' => rawurlencode($search),
'%replace' => rawurlencode($replace),
]);
}
return null;
} | php | public static function editorUri(
string $file,
int $line = null,
string $action = 'open',
string $search = '',
string $replace = ''
): ?string {
if (Debugger::$editor && $file && ($action === 'create' || is_file($file))) {
$file = \str_replace('/', DIRECTORY_SEPARATOR, $file);
$file = \strtr($file, Debugger::$editorMapping);
return strtr(Debugger::$editor, [
'%action' => $action,
'%file' => rawurlencode($file),
'%line' => $line ?: 1,
'%search' => rawurlencode($search),
'%replace' => rawurlencode($replace),
]);
}
return null;
} | [
"public",
"static",
"function",
"editorUri",
"(",
"string",
"$",
"file",
",",
"int",
"$",
"line",
"=",
"null",
",",
"string",
"$",
"action",
"=",
"'open'",
",",
"string",
"$",
"search",
"=",
"''",
",",
"string",
"$",
"replace",
"=",
"''",
")",
":",
"?",
"string",
"{",
"if",
"(",
"Debugger",
"::",
"$",
"editor",
"&&",
"$",
"file",
"&&",
"(",
"$",
"action",
"===",
"'create'",
"||",
"is_file",
"(",
"$",
"file",
")",
")",
")",
"{",
"$",
"file",
"=",
"\\",
"str_replace",
"(",
"'/'",
",",
"DIRECTORY_SEPARATOR",
",",
"$",
"file",
")",
";",
"$",
"file",
"=",
"\\",
"strtr",
"(",
"$",
"file",
",",
"Debugger",
"::",
"$",
"editorMapping",
")",
";",
"return",
"strtr",
"(",
"Debugger",
"::",
"$",
"editor",
",",
"[",
"'%action'",
"=>",
"$",
"action",
",",
"'%file'",
"=>",
"rawurlencode",
"(",
"$",
"file",
")",
",",
"'%line'",
"=>",
"$",
"line",
"?",
":",
"1",
",",
"'%search'",
"=>",
"rawurlencode",
"(",
"$",
"search",
")",
",",
"'%replace'",
"=>",
"rawurlencode",
"(",
"$",
"replace",
")",
",",
"]",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Returns link to editor.
@return string|null | [
"Returns",
"link",
"to",
"editor",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Helpers.php#L57-L78 |
35,482 | hail-framework/framework | src/Debugger/Helpers.php | Helpers.getSuggestion | public static function getSuggestion(array $items, string $value): ?string
{
$best = null;
$min = (\strlen($value) / 4 + 1) * 10 + .1;
foreach (\array_unique($items, SORT_REGULAR) as $item) {
$item = \is_object($item) ? $item->getName() : $item;
if (($len = \levenshtein($item, $value, 10, 11, 10)) > 0 && $len < $min) {
$min = $len;
$best = $item;
}
}
return $best;
} | php | public static function getSuggestion(array $items, string $value): ?string
{
$best = null;
$min = (\strlen($value) / 4 + 1) * 10 + .1;
foreach (\array_unique($items, SORT_REGULAR) as $item) {
$item = \is_object($item) ? $item->getName() : $item;
if (($len = \levenshtein($item, $value, 10, 11, 10)) > 0 && $len < $min) {
$min = $len;
$best = $item;
}
}
return $best;
} | [
"public",
"static",
"function",
"getSuggestion",
"(",
"array",
"$",
"items",
",",
"string",
"$",
"value",
")",
":",
"?",
"string",
"{",
"$",
"best",
"=",
"null",
";",
"$",
"min",
"=",
"(",
"\\",
"strlen",
"(",
"$",
"value",
")",
"/",
"4",
"+",
"1",
")",
"*",
"10",
"+",
".1",
";",
"foreach",
"(",
"\\",
"array_unique",
"(",
"$",
"items",
",",
"SORT_REGULAR",
")",
"as",
"$",
"item",
")",
"{",
"$",
"item",
"=",
"\\",
"is_object",
"(",
"$",
"item",
")",
"?",
"$",
"item",
"->",
"getName",
"(",
")",
":",
"$",
"item",
";",
"if",
"(",
"(",
"$",
"len",
"=",
"\\",
"levenshtein",
"(",
"$",
"item",
",",
"$",
"value",
",",
"10",
",",
"11",
",",
"10",
")",
")",
">",
"0",
"&&",
"$",
"len",
"<",
"$",
"min",
")",
"{",
"$",
"min",
"=",
"$",
"len",
";",
"$",
"best",
"=",
"$",
"item",
";",
"}",
"}",
"return",
"$",
"best",
";",
"}"
] | Finds the best suggestion.
@return string|NULL | [
"Finds",
"the",
"best",
"suggestion",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Helpers.php#L292-L305 |
35,483 | hail-framework/framework | src/Session/Session.php | Session.isStarted | public function isStarted()
{
$started = \session_status() === PHP_SESSION_ACTIVE;
// if the session was started externally, move the flash values forward
if ($started && !$this->flashMoved) {
$this->moveFlash();
}
// done
return $started;
} | php | public function isStarted()
{
$started = \session_status() === PHP_SESSION_ACTIVE;
// if the session was started externally, move the flash values forward
if ($started && !$this->flashMoved) {
$this->moveFlash();
}
// done
return $started;
} | [
"public",
"function",
"isStarted",
"(",
")",
"{",
"$",
"started",
"=",
"\\",
"session_status",
"(",
")",
"===",
"PHP_SESSION_ACTIVE",
";",
"// if the session was started externally, move the flash values forward",
"if",
"(",
"$",
"started",
"&&",
"!",
"$",
"this",
"->",
"flashMoved",
")",
"{",
"$",
"this",
"->",
"moveFlash",
"(",
")",
";",
"}",
"// done",
"return",
"$",
"started",
";",
"}"
] | Is the session already started?
@return bool | [
"Is",
"the",
"session",
"already",
"started?"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Session/Session.php#L178-L189 |
35,484 | hail-framework/framework | src/Session/Session.php | Session.start | public function start(array $options = null)
{
$sessionStatus = \session_status();
if ($sessionStatus === PHP_SESSION_DISABLED) {
throw new \RuntimeException('PHP sessions are disabled');
}
if ($sessionStatus === PHP_SESSION_ACTIVE) {
throw new \RuntimeException('session has already been started');
}
if ($this->handler) {
\session_set_save_handler($this->handler, true);
}
\session_set_cookie_params(
$this->cookieParams['lifetime'],
$this->cookieParams['path'],
$this->cookieParams['domain'],
$this->cookieParams['secure'],
$this->cookieParams['httponly']
);
if ($options === null) {
$options = [];
}
if (!isset($options['serialize_handler'])) {
$serializeHandler = \ini_get('serialize_handler');
if ($serializeHandler === 'php' || $serializeHandler === 'php_binary') {
$options['serialize_handler'] = 'php_serialize';
}
}
$result = \session_start($options);
if ($result) {
$this->moveFlash();
}
return $result;
} | php | public function start(array $options = null)
{
$sessionStatus = \session_status();
if ($sessionStatus === PHP_SESSION_DISABLED) {
throw new \RuntimeException('PHP sessions are disabled');
}
if ($sessionStatus === PHP_SESSION_ACTIVE) {
throw new \RuntimeException('session has already been started');
}
if ($this->handler) {
\session_set_save_handler($this->handler, true);
}
\session_set_cookie_params(
$this->cookieParams['lifetime'],
$this->cookieParams['path'],
$this->cookieParams['domain'],
$this->cookieParams['secure'],
$this->cookieParams['httponly']
);
if ($options === null) {
$options = [];
}
if (!isset($options['serialize_handler'])) {
$serializeHandler = \ini_get('serialize_handler');
if ($serializeHandler === 'php' || $serializeHandler === 'php_binary') {
$options['serialize_handler'] = 'php_serialize';
}
}
$result = \session_start($options);
if ($result) {
$this->moveFlash();
}
return $result;
} | [
"public",
"function",
"start",
"(",
"array",
"$",
"options",
"=",
"null",
")",
"{",
"$",
"sessionStatus",
"=",
"\\",
"session_status",
"(",
")",
";",
"if",
"(",
"$",
"sessionStatus",
"===",
"PHP_SESSION_DISABLED",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'PHP sessions are disabled'",
")",
";",
"}",
"if",
"(",
"$",
"sessionStatus",
"===",
"PHP_SESSION_ACTIVE",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'session has already been started'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"handler",
")",
"{",
"\\",
"session_set_save_handler",
"(",
"$",
"this",
"->",
"handler",
",",
"true",
")",
";",
"}",
"\\",
"session_set_cookie_params",
"(",
"$",
"this",
"->",
"cookieParams",
"[",
"'lifetime'",
"]",
",",
"$",
"this",
"->",
"cookieParams",
"[",
"'path'",
"]",
",",
"$",
"this",
"->",
"cookieParams",
"[",
"'domain'",
"]",
",",
"$",
"this",
"->",
"cookieParams",
"[",
"'secure'",
"]",
",",
"$",
"this",
"->",
"cookieParams",
"[",
"'httponly'",
"]",
")",
";",
"if",
"(",
"$",
"options",
"===",
"null",
")",
"{",
"$",
"options",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'serialize_handler'",
"]",
")",
")",
"{",
"$",
"serializeHandler",
"=",
"\\",
"ini_get",
"(",
"'serialize_handler'",
")",
";",
"if",
"(",
"$",
"serializeHandler",
"===",
"'php'",
"||",
"$",
"serializeHandler",
"===",
"'php_binary'",
")",
"{",
"$",
"options",
"[",
"'serialize_handler'",
"]",
"=",
"'php_serialize'",
";",
"}",
"}",
"$",
"result",
"=",
"\\",
"session_start",
"(",
"$",
"options",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
"$",
"this",
"->",
"moveFlash",
"(",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Starts a new or existing session.
@param array $options
@return bool
@throws \RuntimeException | [
"Starts",
"a",
"new",
"or",
"existing",
"session",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Session/Session.php#L200-L242 |
35,485 | hail-framework/framework | src/Session/Session.php | Session.moveFlash | protected function moveFlash()
{
if (!isset($_SESSION[static::FLASH_NEXT])) {
$_SESSION[static::FLASH_NEXT] = [];
}
$_SESSION[static::FLASH_NOW] = $_SESSION[static::FLASH_NEXT];
$_SESSION[static::FLASH_NEXT] = [];
$this->flashMoved = true;
} | php | protected function moveFlash()
{
if (!isset($_SESSION[static::FLASH_NEXT])) {
$_SESSION[static::FLASH_NEXT] = [];
}
$_SESSION[static::FLASH_NOW] = $_SESSION[static::FLASH_NEXT];
$_SESSION[static::FLASH_NEXT] = [];
$this->flashMoved = true;
} | [
"protected",
"function",
"moveFlash",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"_SESSION",
"[",
"static",
"::",
"FLASH_NEXT",
"]",
")",
")",
"{",
"$",
"_SESSION",
"[",
"static",
"::",
"FLASH_NEXT",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"_SESSION",
"[",
"static",
"::",
"FLASH_NOW",
"]",
"=",
"$",
"_SESSION",
"[",
"static",
"::",
"FLASH_NEXT",
"]",
";",
"$",
"_SESSION",
"[",
"static",
"::",
"FLASH_NEXT",
"]",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"flashMoved",
"=",
"true",
";",
"}"
] | Moves the "next" flash values to the "now" values, thereby clearing the
"next" values. | [
"Moves",
"the",
"next",
"flash",
"values",
"to",
"the",
"now",
"values",
"thereby",
"clearing",
"the",
"next",
"values",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Session/Session.php#L248-L256 |
35,486 | hail-framework/framework | src/Session/Session.php | Session.isResumable | public function isResumable(): bool
{
$name = $this->getName();
if ($this->request) {
return $this->request->cookie($name) !== null;
}
return isset($_COOKIE[$name]);
} | php | public function isResumable(): bool
{
$name = $this->getName();
if ($this->request) {
return $this->request->cookie($name) !== null;
}
return isset($_COOKIE[$name]);
} | [
"public",
"function",
"isResumable",
"(",
")",
":",
"bool",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"request",
")",
"{",
"return",
"$",
"this",
"->",
"request",
"->",
"cookie",
"(",
"$",
"name",
")",
"!==",
"null",
";",
"}",
"return",
"isset",
"(",
"$",
"_COOKIE",
"[",
"$",
"name",
"]",
")",
";",
"}"
] | Is a session available to be resumed?
@return bool | [
"Is",
"a",
"session",
"available",
"to",
"be",
"resumed?"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Session/Session.php#L295-L304 |
35,487 | hail-framework/framework | src/Session/Session.php | Session.resume | public function resume(): bool
{
if ($this->isStarted()) {
return true;
}
if ($this->isResumable()) {
return $this->start();
}
return false;
} | php | public function resume(): bool
{
if ($this->isStarted()) {
return true;
}
if ($this->isResumable()) {
return $this->start();
}
return false;
} | [
"public",
"function",
"resume",
"(",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"this",
"->",
"isStarted",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isResumable",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"start",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Resumes a session, but does not start a new one if there is no
existing one.
@return bool | [
"Resumes",
"a",
"session",
"but",
"does",
"not",
"start",
"a",
"new",
"one",
"if",
"there",
"is",
"no",
"existing",
"one",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Session/Session.php#L313-L324 |
35,488 | hail-framework/framework | src/Session/Session.php | Session.regenerateId | public function regenerateId(): bool
{
$result = \session_regenerate_id(true);
if ($result && $this->csrfToken) {
$this->csrfToken->regenerateValue();
}
return $result;
} | php | public function regenerateId(): bool
{
$result = \session_regenerate_id(true);
if ($result && $this->csrfToken) {
$this->csrfToken->regenerateValue();
}
return $result;
} | [
"public",
"function",
"regenerateId",
"(",
")",
":",
"bool",
"{",
"$",
"result",
"=",
"\\",
"session_regenerate_id",
"(",
"true",
")",
";",
"if",
"(",
"$",
"result",
"&&",
"$",
"this",
"->",
"csrfToken",
")",
"{",
"$",
"this",
"->",
"csrfToken",
"->",
"regenerateValue",
"(",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Regenerates and replaces the current session id; also regenerates the
CSRF token value if one exists.
@return bool True if regeneration worked, false if not. | [
"Regenerates",
"and",
"replaces",
"the",
"current",
"session",
"id",
";",
"also",
"regenerates",
"the",
"CSRF",
"token",
"value",
"if",
"one",
"exists",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Session/Session.php#L409-L417 |
35,489 | hail-framework/framework | src/Image/ImageCache.php | ImageCache.make | public function make($data)
{
// include "modified" property for any files
if ($this->isFile($data)) {
$this->setProperty('modified', \filemtime((string) $data));
}
// register make call
$this->__call('make', [$data]);
return $this;
} | php | public function make($data)
{
// include "modified" property for any files
if ($this->isFile($data)) {
$this->setProperty('modified', \filemtime((string) $data));
}
// register make call
$this->__call('make', [$data]);
return $this;
} | [
"public",
"function",
"make",
"(",
"$",
"data",
")",
"{",
"// include \"modified\" property for any files",
"if",
"(",
"$",
"this",
"->",
"isFile",
"(",
"$",
"data",
")",
")",
"{",
"$",
"this",
"->",
"setProperty",
"(",
"'modified'",
",",
"\\",
"filemtime",
"(",
"(",
"string",
")",
"$",
"data",
")",
")",
";",
"}",
"// register make call",
"$",
"this",
"->",
"__call",
"(",
"'make'",
",",
"[",
"$",
"data",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Special make method to add modifed data to checksum
@param mixed $data
@return self | [
"Special",
"make",
"method",
"to",
"add",
"modifed",
"data",
"to",
"checksum"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Image/ImageCache.php#L81-L92 |
35,490 | hail-framework/framework | src/Debugger/BlueScreen.php | BlueScreen.render | public function render(\Throwable $exception): string
{
\ob_start();
if (Helpers::isAjax() && \session_status() === PHP_SESSION_ACTIVE) {
$this->renderTemplate($exception, __DIR__ . '/assets/BlueScreen/content.phtml');
$contentId = $_SERVER['HTTP_X_TRACY_AJAX'];
$_SESSION['_tracy']['bluescreen'][$contentId] = [
'content' => \ob_get_clean(),
'dumps' => Dumper::fetchLiveData(),
'time' => \time(),
];
return '';
}
$this->renderTemplate($exception, __DIR__ . '/assets/BlueScreen/page.phtml');
return \ob_get_clean();
} | php | public function render(\Throwable $exception): string
{
\ob_start();
if (Helpers::isAjax() && \session_status() === PHP_SESSION_ACTIVE) {
$this->renderTemplate($exception, __DIR__ . '/assets/BlueScreen/content.phtml');
$contentId = $_SERVER['HTTP_X_TRACY_AJAX'];
$_SESSION['_tracy']['bluescreen'][$contentId] = [
'content' => \ob_get_clean(),
'dumps' => Dumper::fetchLiveData(),
'time' => \time(),
];
return '';
}
$this->renderTemplate($exception, __DIR__ . '/assets/BlueScreen/page.phtml');
return \ob_get_clean();
} | [
"public",
"function",
"render",
"(",
"\\",
"Throwable",
"$",
"exception",
")",
":",
"string",
"{",
"\\",
"ob_start",
"(",
")",
";",
"if",
"(",
"Helpers",
"::",
"isAjax",
"(",
")",
"&&",
"\\",
"session_status",
"(",
")",
"===",
"PHP_SESSION_ACTIVE",
")",
"{",
"$",
"this",
"->",
"renderTemplate",
"(",
"$",
"exception",
",",
"__DIR__",
".",
"'/assets/BlueScreen/content.phtml'",
")",
";",
"$",
"contentId",
"=",
"$",
"_SERVER",
"[",
"'HTTP_X_TRACY_AJAX'",
"]",
";",
"$",
"_SESSION",
"[",
"'_tracy'",
"]",
"[",
"'bluescreen'",
"]",
"[",
"$",
"contentId",
"]",
"=",
"[",
"'content'",
"=>",
"\\",
"ob_get_clean",
"(",
")",
",",
"'dumps'",
"=>",
"Dumper",
"::",
"fetchLiveData",
"(",
")",
",",
"'time'",
"=>",
"\\",
"time",
"(",
")",
",",
"]",
";",
"return",
"''",
";",
"}",
"$",
"this",
"->",
"renderTemplate",
"(",
"$",
"exception",
",",
"__DIR__",
".",
"'/assets/BlueScreen/page.phtml'",
")",
";",
"return",
"\\",
"ob_get_clean",
"(",
")",
";",
"}"
] | Renders blue screen.
@param \Throwable $exception
@return string | [
"Renders",
"blue",
"screen",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/BlueScreen.php#L84-L102 |
35,491 | hail-framework/framework | src/Debugger/BlueScreen.php | BlueScreen.highlightLine | public static function highlightLine(string $html, int $line, int $lines = 15): string
{
$source = \explode("\n", "\n" . \str_replace("\r\n", "\n", $html));
$out = '';
$spans = 1;
$start = $i = \max(1, \min($line, \count($source) - 1) - (int)\floor($lines * 2 / 3));
while (--$i >= 1) { // find last highlighted block
if (\preg_match('#.*(</?span[^>]*>)#', $source[$i], $m)) {
if ($m[1] !== '</span>') {
$spans++;
$out .= $m[1];
}
break;
}
}
$source = \array_slice($source, $start, $lines, true);
\end($source);
$numWidth = \strlen((string)\key($source));
foreach ($source as $n => $s) {
$spans += \substr_count($s, '<span') - \substr_count($s, '</span');
$s = \str_replace(["\r", "\n"], ['', ''], $s);
\preg_match_all('#<[^>]+>#', $s, $tags);
if ($n == $line) {
$out .= \sprintf(
"<span class=\"highlight\">%{$numWidth}s: %s\n</span>%s",
$n,
\strip_tags($s),
\implode('', $tags[0])
);
} else {
$out .= \sprintf("<span class=\"line\">%{$numWidth}s:</span> %s\n", $n, $s);
}
}
$out .= \str_repeat('</span>', $spans) . '</code>';
return $out;
} | php | public static function highlightLine(string $html, int $line, int $lines = 15): string
{
$source = \explode("\n", "\n" . \str_replace("\r\n", "\n", $html));
$out = '';
$spans = 1;
$start = $i = \max(1, \min($line, \count($source) - 1) - (int)\floor($lines * 2 / 3));
while (--$i >= 1) { // find last highlighted block
if (\preg_match('#.*(</?span[^>]*>)#', $source[$i], $m)) {
if ($m[1] !== '</span>') {
$spans++;
$out .= $m[1];
}
break;
}
}
$source = \array_slice($source, $start, $lines, true);
\end($source);
$numWidth = \strlen((string)\key($source));
foreach ($source as $n => $s) {
$spans += \substr_count($s, '<span') - \substr_count($s, '</span');
$s = \str_replace(["\r", "\n"], ['', ''], $s);
\preg_match_all('#<[^>]+>#', $s, $tags);
if ($n == $line) {
$out .= \sprintf(
"<span class=\"highlight\">%{$numWidth}s: %s\n</span>%s",
$n,
\strip_tags($s),
\implode('', $tags[0])
);
} else {
$out .= \sprintf("<span class=\"line\">%{$numWidth}s:</span> %s\n", $n, $s);
}
}
$out .= \str_repeat('</span>', $spans) . '</code>';
return $out;
} | [
"public",
"static",
"function",
"highlightLine",
"(",
"string",
"$",
"html",
",",
"int",
"$",
"line",
",",
"int",
"$",
"lines",
"=",
"15",
")",
":",
"string",
"{",
"$",
"source",
"=",
"\\",
"explode",
"(",
"\"\\n\"",
",",
"\"\\n\"",
".",
"\\",
"str_replace",
"(",
"\"\\r\\n\"",
",",
"\"\\n\"",
",",
"$",
"html",
")",
")",
";",
"$",
"out",
"=",
"''",
";",
"$",
"spans",
"=",
"1",
";",
"$",
"start",
"=",
"$",
"i",
"=",
"\\",
"max",
"(",
"1",
",",
"\\",
"min",
"(",
"$",
"line",
",",
"\\",
"count",
"(",
"$",
"source",
")",
"-",
"1",
")",
"-",
"(",
"int",
")",
"\\",
"floor",
"(",
"$",
"lines",
"*",
"2",
"/",
"3",
")",
")",
";",
"while",
"(",
"--",
"$",
"i",
">=",
"1",
")",
"{",
"// find last highlighted block",
"if",
"(",
"\\",
"preg_match",
"(",
"'#.*(</?span[^>]*>)#'",
",",
"$",
"source",
"[",
"$",
"i",
"]",
",",
"$",
"m",
")",
")",
"{",
"if",
"(",
"$",
"m",
"[",
"1",
"]",
"!==",
"'</span>'",
")",
"{",
"$",
"spans",
"++",
";",
"$",
"out",
".=",
"$",
"m",
"[",
"1",
"]",
";",
"}",
"break",
";",
"}",
"}",
"$",
"source",
"=",
"\\",
"array_slice",
"(",
"$",
"source",
",",
"$",
"start",
",",
"$",
"lines",
",",
"true",
")",
";",
"\\",
"end",
"(",
"$",
"source",
")",
";",
"$",
"numWidth",
"=",
"\\",
"strlen",
"(",
"(",
"string",
")",
"\\",
"key",
"(",
"$",
"source",
")",
")",
";",
"foreach",
"(",
"$",
"source",
"as",
"$",
"n",
"=>",
"$",
"s",
")",
"{",
"$",
"spans",
"+=",
"\\",
"substr_count",
"(",
"$",
"s",
",",
"'<span'",
")",
"-",
"\\",
"substr_count",
"(",
"$",
"s",
",",
"'</span'",
")",
";",
"$",
"s",
"=",
"\\",
"str_replace",
"(",
"[",
"\"\\r\"",
",",
"\"\\n\"",
"]",
",",
"[",
"''",
",",
"''",
"]",
",",
"$",
"s",
")",
";",
"\\",
"preg_match_all",
"(",
"'#<[^>]+>#'",
",",
"$",
"s",
",",
"$",
"tags",
")",
";",
"if",
"(",
"$",
"n",
"==",
"$",
"line",
")",
"{",
"$",
"out",
".=",
"\\",
"sprintf",
"(",
"\"<span class=\\\"highlight\\\">%{$numWidth}s: %s\\n</span>%s\"",
",",
"$",
"n",
",",
"\\",
"strip_tags",
"(",
"$",
"s",
")",
",",
"\\",
"implode",
"(",
"''",
",",
"$",
"tags",
"[",
"0",
"]",
")",
")",
";",
"}",
"else",
"{",
"$",
"out",
".=",
"\\",
"sprintf",
"(",
"\"<span class=\\\"line\\\">%{$numWidth}s:</span> %s\\n\"",
",",
"$",
"n",
",",
"$",
"s",
")",
";",
"}",
"}",
"$",
"out",
".=",
"\\",
"str_repeat",
"(",
"'</span>'",
",",
"$",
"spans",
")",
".",
"'</code>'",
";",
"return",
"$",
"out",
";",
"}"
] | Returns highlighted line in HTML code.
@param string $html
@param int $line
@param int $lines
@return string | [
"Returns",
"highlighted",
"line",
"in",
"HTML",
"code",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/BlueScreen.php#L344-L382 |
35,492 | hail-framework/framework | src/Debugger/BlueScreen.php | BlueScreen.isCollapsed | public function isCollapsed(string $file): bool
{
$file = \str_replace('\\', '/', $file) . '/';
foreach ($this->collapsePaths as $path) {
$path = \str_replace('\\', '/', $path) . '/';
if (\strpos($file, $path) === 0) {
return true;
}
}
return false;
} | php | public function isCollapsed(string $file): bool
{
$file = \str_replace('\\', '/', $file) . '/';
foreach ($this->collapsePaths as $path) {
$path = \str_replace('\\', '/', $path) . '/';
if (\strpos($file, $path) === 0) {
return true;
}
}
return false;
} | [
"public",
"function",
"isCollapsed",
"(",
"string",
"$",
"file",
")",
":",
"bool",
"{",
"$",
"file",
"=",
"\\",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"file",
")",
".",
"'/'",
";",
"foreach",
"(",
"$",
"this",
"->",
"collapsePaths",
"as",
"$",
"path",
")",
"{",
"$",
"path",
"=",
"\\",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"path",
")",
".",
"'/'",
";",
"if",
"(",
"\\",
"strpos",
"(",
"$",
"file",
",",
"$",
"path",
")",
"===",
"0",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Should a file be collapsed in stack trace?
@param string $file
@return bool | [
"Should",
"a",
"file",
"be",
"collapsed",
"in",
"stack",
"trace?"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/BlueScreen.php#L392-L403 |
35,493 | hail-framework/framework | src/Template/Extension/Asset.php | Asset.cachedAssetUrl | public function cachedAssetUrl($url)
{
$filePath = $this->path . '/' . \ltrim($url, '/');
if (!\file_exists($filePath)) {
throw new \LogicException(
'Unable to locate the asset "' . $url . '" in the "' . $this->path . '" directory.'
);
}
$lastUpdated = \filemtime($filePath);
$pathInfo = \pathinfo($url);
if ($pathInfo['dirname'] === '.') {
$directory = '';
} elseif ($pathInfo['dirname'] === '/') {
$directory = '/';
} else {
$directory = $pathInfo['dirname'] . '/';
}
if ($this->filenameMethod) {
return $directory . $pathInfo['filename'] . '.' . $lastUpdated . '.' . $pathInfo['extension'];
}
return $directory . $pathInfo['filename'] . '.' . $pathInfo['extension'] . '?v=' . $lastUpdated;
} | php | public function cachedAssetUrl($url)
{
$filePath = $this->path . '/' . \ltrim($url, '/');
if (!\file_exists($filePath)) {
throw new \LogicException(
'Unable to locate the asset "' . $url . '" in the "' . $this->path . '" directory.'
);
}
$lastUpdated = \filemtime($filePath);
$pathInfo = \pathinfo($url);
if ($pathInfo['dirname'] === '.') {
$directory = '';
} elseif ($pathInfo['dirname'] === '/') {
$directory = '/';
} else {
$directory = $pathInfo['dirname'] . '/';
}
if ($this->filenameMethod) {
return $directory . $pathInfo['filename'] . '.' . $lastUpdated . '.' . $pathInfo['extension'];
}
return $directory . $pathInfo['filename'] . '.' . $pathInfo['extension'] . '?v=' . $lastUpdated;
} | [
"public",
"function",
"cachedAssetUrl",
"(",
"$",
"url",
")",
"{",
"$",
"filePath",
"=",
"$",
"this",
"->",
"path",
".",
"'/'",
".",
"\\",
"ltrim",
"(",
"$",
"url",
",",
"'/'",
")",
";",
"if",
"(",
"!",
"\\",
"file_exists",
"(",
"$",
"filePath",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Unable to locate the asset \"'",
".",
"$",
"url",
".",
"'\" in the \"'",
".",
"$",
"this",
"->",
"path",
".",
"'\" directory.'",
")",
";",
"}",
"$",
"lastUpdated",
"=",
"\\",
"filemtime",
"(",
"$",
"filePath",
")",
";",
"$",
"pathInfo",
"=",
"\\",
"pathinfo",
"(",
"$",
"url",
")",
";",
"if",
"(",
"$",
"pathInfo",
"[",
"'dirname'",
"]",
"===",
"'.'",
")",
"{",
"$",
"directory",
"=",
"''",
";",
"}",
"elseif",
"(",
"$",
"pathInfo",
"[",
"'dirname'",
"]",
"===",
"'/'",
")",
"{",
"$",
"directory",
"=",
"'/'",
";",
"}",
"else",
"{",
"$",
"directory",
"=",
"$",
"pathInfo",
"[",
"'dirname'",
"]",
".",
"'/'",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"filenameMethod",
")",
"{",
"return",
"$",
"directory",
".",
"$",
"pathInfo",
"[",
"'filename'",
"]",
".",
"'.'",
".",
"$",
"lastUpdated",
".",
"'.'",
".",
"$",
"pathInfo",
"[",
"'extension'",
"]",
";",
"}",
"return",
"$",
"directory",
".",
"$",
"pathInfo",
"[",
"'filename'",
"]",
".",
"'.'",
".",
"$",
"pathInfo",
"[",
"'extension'",
"]",
".",
"'?v='",
".",
"$",
"lastUpdated",
";",
"}"
] | Create "cache busted" asset URL.
@param string $url
@return string | [
"Create",
"cache",
"busted",
"asset",
"URL",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Template/Extension/Asset.php#L63-L89 |
35,494 | hail-framework/framework | src/Database/Migration/Generator/MySqlAdapter.php | MySqlAdapter.getSchema | public function getSchema()
{
$this->output->writeln('Load current database schema.');
$result = [];
$result['database'] = $this->getDatabaseSchemata($this->dbName);
$tables = $this->getTables();
foreach ($tables as $table) {
$tableName = $table['table_name'];
$this->output->writeln(sprintf('Table: <info>%s</info>', $tableName));
$result['tables'][$tableName]['table'] = $table;
$result['tables'][$tableName]['columns'] = $this->getColumns($tableName);
$result['tables'][$tableName]['indexes'] = $this->getIndexes($tableName);
$result['tables'][$tableName]['foreign_keys'] = $this->getForeignKeys($tableName);
}
return $result;
} | php | public function getSchema()
{
$this->output->writeln('Load current database schema.');
$result = [];
$result['database'] = $this->getDatabaseSchemata($this->dbName);
$tables = $this->getTables();
foreach ($tables as $table) {
$tableName = $table['table_name'];
$this->output->writeln(sprintf('Table: <info>%s</info>', $tableName));
$result['tables'][$tableName]['table'] = $table;
$result['tables'][$tableName]['columns'] = $this->getColumns($tableName);
$result['tables'][$tableName]['indexes'] = $this->getIndexes($tableName);
$result['tables'][$tableName]['foreign_keys'] = $this->getForeignKeys($tableName);
}
return $result;
} | [
"public",
"function",
"getSchema",
"(",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"'Load current database schema.'",
")",
";",
"$",
"result",
"=",
"[",
"]",
";",
"$",
"result",
"[",
"'database'",
"]",
"=",
"$",
"this",
"->",
"getDatabaseSchemata",
"(",
"$",
"this",
"->",
"dbName",
")",
";",
"$",
"tables",
"=",
"$",
"this",
"->",
"getTables",
"(",
")",
";",
"foreach",
"(",
"$",
"tables",
"as",
"$",
"table",
")",
"{",
"$",
"tableName",
"=",
"$",
"table",
"[",
"'table_name'",
"]",
";",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"sprintf",
"(",
"'Table: <info>%s</info>'",
",",
"$",
"tableName",
")",
")",
";",
"$",
"result",
"[",
"'tables'",
"]",
"[",
"$",
"tableName",
"]",
"[",
"'table'",
"]",
"=",
"$",
"table",
";",
"$",
"result",
"[",
"'tables'",
"]",
"[",
"$",
"tableName",
"]",
"[",
"'columns'",
"]",
"=",
"$",
"this",
"->",
"getColumns",
"(",
"$",
"tableName",
")",
";",
"$",
"result",
"[",
"'tables'",
"]",
"[",
"$",
"tableName",
"]",
"[",
"'indexes'",
"]",
"=",
"$",
"this",
"->",
"getIndexes",
"(",
"$",
"tableName",
")",
";",
"$",
"result",
"[",
"'tables'",
"]",
"[",
"$",
"tableName",
"]",
"[",
"'foreign_keys'",
"]",
"=",
"$",
"this",
"->",
"getForeignKeys",
"(",
"$",
"tableName",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Load current database schema.
@return array | [
"Load",
"current",
"database",
"schema",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Generator/MySqlAdapter.php#L64-L82 |
35,495 | hail-framework/framework | src/Database/Migration/Generator/MySqlAdapter.php | MySqlAdapter.getTableCreateSql | public function getTableCreateSql($tableName)
{
$sql = sprintf('SHOW CREATE TABLE %s', $this->ident($tableName));
$result = $this->pdo->query($sql)->fetch();
return $result['CREATE TABLE'];
} | php | public function getTableCreateSql($tableName)
{
$sql = sprintf('SHOW CREATE TABLE %s', $this->ident($tableName));
$result = $this->pdo->query($sql)->fetch();
return $result['CREATE TABLE'];
} | [
"public",
"function",
"getTableCreateSql",
"(",
"$",
"tableName",
")",
"{",
"$",
"sql",
"=",
"sprintf",
"(",
"'SHOW CREATE TABLE %s'",
",",
"$",
"this",
"->",
"ident",
"(",
"$",
"tableName",
")",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"pdo",
"->",
"query",
"(",
"$",
"sql",
")",
"->",
"fetch",
"(",
")",
";",
"return",
"$",
"result",
"[",
"'CREATE TABLE'",
"]",
";",
"}"
] | Get SQL to create a table.
@param string $tableName
@return string | [
"Get",
"SQL",
"to",
"create",
"a",
"table",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Generator/MySqlAdapter.php#L276-L282 |
35,496 | DoSomething/gateway | src/Common/ApiCollection.php | ApiCollection.setPaginator | public function setPaginator($class, $options = [])
{
$interfaces = class_implements($class);
if (in_array('Illuminate\Contracts\Pagination\LengthAwarePaginator', $interfaces)) {
$paginator = new $class($this->items, $this->total, $this->perPage, $this->currentPage, $options);
} elseif (in_array('Illuminate\Contracts\Pagination\Paginator', $interfaces)) {
$paginator = new $class($this->items, $this->perPage, $this->currentPage, $options);
$paginator->hasMorePagesWhen($this->hasMore);
} else {
throw new \InvalidArgumentException('Cannot use the given paginator.');
}
$this->paginator = $paginator;
} | php | public function setPaginator($class, $options = [])
{
$interfaces = class_implements($class);
if (in_array('Illuminate\Contracts\Pagination\LengthAwarePaginator', $interfaces)) {
$paginator = new $class($this->items, $this->total, $this->perPage, $this->currentPage, $options);
} elseif (in_array('Illuminate\Contracts\Pagination\Paginator', $interfaces)) {
$paginator = new $class($this->items, $this->perPage, $this->currentPage, $options);
$paginator->hasMorePagesWhen($this->hasMore);
} else {
throw new \InvalidArgumentException('Cannot use the given paginator.');
}
$this->paginator = $paginator;
} | [
"public",
"function",
"setPaginator",
"(",
"$",
"class",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"interfaces",
"=",
"class_implements",
"(",
"$",
"class",
")",
";",
"if",
"(",
"in_array",
"(",
"'Illuminate\\Contracts\\Pagination\\LengthAwarePaginator'",
",",
"$",
"interfaces",
")",
")",
"{",
"$",
"paginator",
"=",
"new",
"$",
"class",
"(",
"$",
"this",
"->",
"items",
",",
"$",
"this",
"->",
"total",
",",
"$",
"this",
"->",
"perPage",
",",
"$",
"this",
"->",
"currentPage",
",",
"$",
"options",
")",
";",
"}",
"elseif",
"(",
"in_array",
"(",
"'Illuminate\\Contracts\\Pagination\\Paginator'",
",",
"$",
"interfaces",
")",
")",
"{",
"$",
"paginator",
"=",
"new",
"$",
"class",
"(",
"$",
"this",
"->",
"items",
",",
"$",
"this",
"->",
"perPage",
",",
"$",
"this",
"->",
"currentPage",
",",
"$",
"options",
")",
";",
"$",
"paginator",
"->",
"hasMorePagesWhen",
"(",
"$",
"this",
"->",
"hasMore",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Cannot use the given paginator.'",
")",
";",
"}",
"$",
"this",
"->",
"paginator",
"=",
"$",
"paginator",
";",
"}"
] | Set a paginator for this collection.
@param string $class
@param array $options | [
"Set",
"a",
"paginator",
"for",
"this",
"collection",
"."
] | 89c1c59c6af038dff790df6d5aaa9fc703246568 | https://github.com/DoSomething/gateway/blob/89c1c59c6af038dff790df6d5aaa9fc703246568/src/Common/ApiCollection.php#L88-L102 |
35,497 | Kajna/K-Core | Core/Util/Message.php | Message.get | public static function get($key = '', $preserve = false)
{
$value = null;
if (isset($_SESSION['flashmessage'][$key])) {
$value = $_SESSION['flashmessage'][$key];
if (!$preserve) {
unset($_SESSION['flashmessage'][$key]);
}
}
return $value;
} | php | public static function get($key = '', $preserve = false)
{
$value = null;
if (isset($_SESSION['flashmessage'][$key])) {
$value = $_SESSION['flashmessage'][$key];
if (!$preserve) {
unset($_SESSION['flashmessage'][$key]);
}
}
return $value;
} | [
"public",
"static",
"function",
"get",
"(",
"$",
"key",
"=",
"''",
",",
"$",
"preserve",
"=",
"false",
")",
"{",
"$",
"value",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"_SESSION",
"[",
"'flashmessage'",
"]",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"value",
"=",
"$",
"_SESSION",
"[",
"'flashmessage'",
"]",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"!",
"$",
"preserve",
")",
"{",
"unset",
"(",
"$",
"_SESSION",
"[",
"'flashmessage'",
"]",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"return",
"$",
"value",
";",
"}"
] | Get message and destroy upon reading unless stated otherwise.
@param string $key
@param bool $preserve
@return mixed | [
"Get",
"message",
"and",
"destroy",
"upon",
"reading",
"unless",
"stated",
"otherwise",
"."
] | 6a354056cf95e471b9b1eb372c5626123fd77df2 | https://github.com/Kajna/K-Core/blob/6a354056cf95e471b9b1eb372c5626123fd77df2/Core/Util/Message.php#L32-L42 |
35,498 | hail-framework/framework | src/Template/Engine.php | Engine.addData | public function addData(array $data, $templates = null): self
{
if (null === $templates) {
$this->sharedVariables = \array_merge($this->sharedVariables, $data);
return $this;
}
if (\is_string($templates)) {
$templates = [$templates];
}
if (\is_array($templates)) {
foreach ($templates as $template) {
if (isset($this->templateVariables[$template])) {
$this->templateVariables[$template] = \array_merge($this->templateVariables[$template], $data);
} else {
$this->templateVariables[$template] = $data;
}
}
return $this;
}
throw new \InvalidArgumentException(
'The templates variable must be null, an array or a string, ' . \gettype($templates) . ' given.'
);
} | php | public function addData(array $data, $templates = null): self
{
if (null === $templates) {
$this->sharedVariables = \array_merge($this->sharedVariables, $data);
return $this;
}
if (\is_string($templates)) {
$templates = [$templates];
}
if (\is_array($templates)) {
foreach ($templates as $template) {
if (isset($this->templateVariables[$template])) {
$this->templateVariables[$template] = \array_merge($this->templateVariables[$template], $data);
} else {
$this->templateVariables[$template] = $data;
}
}
return $this;
}
throw new \InvalidArgumentException(
'The templates variable must be null, an array or a string, ' . \gettype($templates) . ' given.'
);
} | [
"public",
"function",
"addData",
"(",
"array",
"$",
"data",
",",
"$",
"templates",
"=",
"null",
")",
":",
"self",
"{",
"if",
"(",
"null",
"===",
"$",
"templates",
")",
"{",
"$",
"this",
"->",
"sharedVariables",
"=",
"\\",
"array_merge",
"(",
"$",
"this",
"->",
"sharedVariables",
",",
"$",
"data",
")",
";",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"templates",
")",
")",
"{",
"$",
"templates",
"=",
"[",
"$",
"templates",
"]",
";",
"}",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"templates",
")",
")",
"{",
"foreach",
"(",
"$",
"templates",
"as",
"$",
"template",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"templateVariables",
"[",
"$",
"template",
"]",
")",
")",
"{",
"$",
"this",
"->",
"templateVariables",
"[",
"$",
"template",
"]",
"=",
"\\",
"array_merge",
"(",
"$",
"this",
"->",
"templateVariables",
"[",
"$",
"template",
"]",
",",
"$",
"data",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"templateVariables",
"[",
"$",
"template",
"]",
"=",
"$",
"data",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'The templates variable must be null, an array or a string, '",
".",
"\\",
"gettype",
"(",
"$",
"templates",
")",
".",
"' given.'",
")",
";",
"}"
] | Add preassigned template data.
@param array $data ;
@param null|string|array $templates ;
@return self
@throws \InvalidArgumentException | [
"Add",
"preassigned",
"template",
"data",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Template/Engine.php#L91-L118 |
35,499 | hail-framework/framework | src/Template/Engine.php | Engine.callFunction | public function callFunction($name, Template $template = null, $arguments = [])
{
$callable = $this->getFunction($name);
if (\is_array($callable) &&
isset($callable[0]) &&
$callable[0] instanceof ExtensionInterface
) {
$callable[0]->template = $template;
}
return $callable(...$arguments);
} | php | public function callFunction($name, Template $template = null, $arguments = [])
{
$callable = $this->getFunction($name);
if (\is_array($callable) &&
isset($callable[0]) &&
$callable[0] instanceof ExtensionInterface
) {
$callable[0]->template = $template;
}
return $callable(...$arguments);
} | [
"public",
"function",
"callFunction",
"(",
"$",
"name",
",",
"Template",
"$",
"template",
"=",
"null",
",",
"$",
"arguments",
"=",
"[",
"]",
")",
"{",
"$",
"callable",
"=",
"$",
"this",
"->",
"getFunction",
"(",
"$",
"name",
")",
";",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"callable",
")",
"&&",
"isset",
"(",
"$",
"callable",
"[",
"0",
"]",
")",
"&&",
"$",
"callable",
"[",
"0",
"]",
"instanceof",
"ExtensionInterface",
")",
"{",
"$",
"callable",
"[",
"0",
"]",
"->",
"template",
"=",
"$",
"template",
";",
"}",
"return",
"$",
"callable",
"(",
"...",
"$",
"arguments",
")",
";",
"}"
] | Call the function.
@param string $name
@param Template $template
@param array $arguments
@return mixed | [
"Call",
"the",
"function",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Template/Engine.php#L229-L241 |
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.