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,200 | hail-framework/framework | src/Database/Migration/Table.php | Table.update | public function update()
{
if (!$this->exists()) {
throw new \RuntimeException('Cannot update a table that doesn\'t exist!');
}
// update table
foreach ($this->getPendingColumns() as $column) {
$this->getAdapter()->addColumn($this, $column);
}
foreach ($this->getIndexes() as $index) {
$this->getAdapter()->addIndex($this, $index);
}
foreach ($this->getForeignKeys() as $foreignKey) {
$this->getAdapter()->addForeignKey($this, $foreignKey);
}
$this->saveData();
$this->reset(); // reset pending changes
} | php | public function update()
{
if (!$this->exists()) {
throw new \RuntimeException('Cannot update a table that doesn\'t exist!');
}
// update table
foreach ($this->getPendingColumns() as $column) {
$this->getAdapter()->addColumn($this, $column);
}
foreach ($this->getIndexes() as $index) {
$this->getAdapter()->addIndex($this, $index);
}
foreach ($this->getForeignKeys() as $foreignKey) {
$this->getAdapter()->addForeignKey($this, $foreignKey);
}
$this->saveData();
$this->reset(); // reset pending changes
} | [
"public",
"function",
"update",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"exists",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Cannot update a table that doesn\\'t exist!'",
")",
";",
"}",
"// update table",
"foreach",
"(",
"$",
"this",
"->",
"getPendingColumns",
"(",
")",
"as",
"$",
"column",
")",
"{",
"$",
"this",
"->",
"getAdapter",
"(",
")",
"->",
"addColumn",
"(",
"$",
"this",
",",
"$",
"column",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"getIndexes",
"(",
")",
"as",
"$",
"index",
")",
"{",
"$",
"this",
"->",
"getAdapter",
"(",
")",
"->",
"addIndex",
"(",
"$",
"this",
",",
"$",
"index",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"getForeignKeys",
"(",
")",
"as",
"$",
"foreignKey",
")",
"{",
"$",
"this",
"->",
"getAdapter",
"(",
")",
"->",
"addForeignKey",
"(",
"$",
"this",
",",
"$",
"foreignKey",
")",
";",
"}",
"$",
"this",
"->",
"saveData",
"(",
")",
";",
"$",
"this",
"->",
"reset",
"(",
")",
";",
"// reset pending changes",
"}"
] | Updates a table from the object instance.
@throws \RuntimeException
@return void | [
"Updates",
"a",
"table",
"from",
"the",
"object",
"instance",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Table.php#L662-L683 |
35,201 | hail-framework/framework | src/Database/Migration/Table.php | Table.saveData | public function saveData()
{
$rows = $this->getData();
if (empty($rows)) {
return;
}
$bulk = true;
$row = current($rows);
$c = array_keys($row);
foreach ($this->getData() as $row) {
$k = array_keys($row);
if ($k != $c) {
$bulk = false;
break;
}
}
if ($bulk) {
$this->getAdapter()->bulkinsert($this, $this->getData());
} else {
foreach ($this->getData() as $row) {
$this->getAdapter()->insert($this, $row);
}
}
} | php | public function saveData()
{
$rows = $this->getData();
if (empty($rows)) {
return;
}
$bulk = true;
$row = current($rows);
$c = array_keys($row);
foreach ($this->getData() as $row) {
$k = array_keys($row);
if ($k != $c) {
$bulk = false;
break;
}
}
if ($bulk) {
$this->getAdapter()->bulkinsert($this, $this->getData());
} else {
foreach ($this->getData() as $row) {
$this->getAdapter()->insert($this, $row);
}
}
} | [
"public",
"function",
"saveData",
"(",
")",
"{",
"$",
"rows",
"=",
"$",
"this",
"->",
"getData",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"rows",
")",
")",
"{",
"return",
";",
"}",
"$",
"bulk",
"=",
"true",
";",
"$",
"row",
"=",
"current",
"(",
"$",
"rows",
")",
";",
"$",
"c",
"=",
"array_keys",
"(",
"$",
"row",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getData",
"(",
")",
"as",
"$",
"row",
")",
"{",
"$",
"k",
"=",
"array_keys",
"(",
"$",
"row",
")",
";",
"if",
"(",
"$",
"k",
"!=",
"$",
"c",
")",
"{",
"$",
"bulk",
"=",
"false",
";",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"bulk",
")",
"{",
"$",
"this",
"->",
"getAdapter",
"(",
")",
"->",
"bulkinsert",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"getData",
"(",
")",
")",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getData",
"(",
")",
"as",
"$",
"row",
")",
"{",
"$",
"this",
"->",
"getAdapter",
"(",
")",
"->",
"insert",
"(",
"$",
"this",
",",
"$",
"row",
")",
";",
"}",
"}",
"}"
] | Commit the pending data waiting for insertion.
@return void | [
"Commit",
"the",
"pending",
"data",
"waiting",
"for",
"insertion",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Table.php#L690-L715 |
35,202 | hail-framework/framework | src/Http/Message/Response.php | Response.setStatusCode | private function setStatusCode($code, $reasonPhrase = ''): void
{
if (
!\is_numeric($code) || \is_float($code) ||
$code < static::MIN_STATUS_CODE_VALUE ||
$code > static::MAX_STATUS_CODE_VALUE
) {
throw new \InvalidArgumentException(sprintf(
'Invalid status code "%s"; must be an integer between %d and %d, inclusive',
\is_scalar($code) ? $code : \gettype($code),
static::MIN_STATUS_CODE_VALUE,
static::MAX_STATUS_CODE_VALUE
));
}
if (!\is_string($reasonPhrase)) {
throw new \InvalidArgumentException(\sprintf(
'Unsupported response reason phrase; must be a string, received %s',
\is_object($reasonPhrase) ? \get_class($reasonPhrase) : \gettype($reasonPhrase)
));
}
if ($reasonPhrase === '' && isset($this->phrases[$code])) {
$reasonPhrase = self::$phrases[$code];
}
$this->reasonPhrase = $reasonPhrase;
$this->statusCode = (int) $code;
} | php | private function setStatusCode($code, $reasonPhrase = ''): void
{
if (
!\is_numeric($code) || \is_float($code) ||
$code < static::MIN_STATUS_CODE_VALUE ||
$code > static::MAX_STATUS_CODE_VALUE
) {
throw new \InvalidArgumentException(sprintf(
'Invalid status code "%s"; must be an integer between %d and %d, inclusive',
\is_scalar($code) ? $code : \gettype($code),
static::MIN_STATUS_CODE_VALUE,
static::MAX_STATUS_CODE_VALUE
));
}
if (!\is_string($reasonPhrase)) {
throw new \InvalidArgumentException(\sprintf(
'Unsupported response reason phrase; must be a string, received %s',
\is_object($reasonPhrase) ? \get_class($reasonPhrase) : \gettype($reasonPhrase)
));
}
if ($reasonPhrase === '' && isset($this->phrases[$code])) {
$reasonPhrase = self::$phrases[$code];
}
$this->reasonPhrase = $reasonPhrase;
$this->statusCode = (int) $code;
} | [
"private",
"function",
"setStatusCode",
"(",
"$",
"code",
",",
"$",
"reasonPhrase",
"=",
"''",
")",
":",
"void",
"{",
"if",
"(",
"!",
"\\",
"is_numeric",
"(",
"$",
"code",
")",
"||",
"\\",
"is_float",
"(",
"$",
"code",
")",
"||",
"$",
"code",
"<",
"static",
"::",
"MIN_STATUS_CODE_VALUE",
"||",
"$",
"code",
">",
"static",
"::",
"MAX_STATUS_CODE_VALUE",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Invalid status code \"%s\"; must be an integer between %d and %d, inclusive'",
",",
"\\",
"is_scalar",
"(",
"$",
"code",
")",
"?",
"$",
"code",
":",
"\\",
"gettype",
"(",
"$",
"code",
")",
",",
"static",
"::",
"MIN_STATUS_CODE_VALUE",
",",
"static",
"::",
"MAX_STATUS_CODE_VALUE",
")",
")",
";",
"}",
"if",
"(",
"!",
"\\",
"is_string",
"(",
"$",
"reasonPhrase",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\\",
"sprintf",
"(",
"'Unsupported response reason phrase; must be a string, received %s'",
",",
"\\",
"is_object",
"(",
"$",
"reasonPhrase",
")",
"?",
"\\",
"get_class",
"(",
"$",
"reasonPhrase",
")",
":",
"\\",
"gettype",
"(",
"$",
"reasonPhrase",
")",
")",
")",
";",
"}",
"if",
"(",
"$",
"reasonPhrase",
"===",
"''",
"&&",
"isset",
"(",
"$",
"this",
"->",
"phrases",
"[",
"$",
"code",
"]",
")",
")",
"{",
"$",
"reasonPhrase",
"=",
"self",
"::",
"$",
"phrases",
"[",
"$",
"code",
"]",
";",
"}",
"$",
"this",
"->",
"reasonPhrase",
"=",
"$",
"reasonPhrase",
";",
"$",
"this",
"->",
"statusCode",
"=",
"(",
"int",
")",
"$",
"code",
";",
"}"
] | Set a valid status code.
@param int $code
@param string $reasonPhrase
@throws \InvalidArgumentException on an invalid status code. | [
"Set",
"a",
"valid",
"status",
"code",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Http/Message/Response.php#L159-L187 |
35,203 | DoSomething/gateway | src/AuthorizesWithBasicAuth.php | AuthorizesWithBasicAuth.getCredentials | protected function getCredentials()
{
if (empty($this->username) || empty($this->password)) {
throw new \Exception('Basic authentication requires a $username & $password property.');
}
return [$this->username, $this->password];
} | php | protected function getCredentials()
{
if (empty($this->username) || empty($this->password)) {
throw new \Exception('Basic authentication requires a $username & $password property.');
}
return [$this->username, $this->password];
} | [
"protected",
"function",
"getCredentials",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"username",
")",
"||",
"empty",
"(",
"$",
"this",
"->",
"password",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Basic authentication requires a $username & $password property.'",
")",
";",
"}",
"return",
"[",
"$",
"this",
"->",
"username",
",",
"$",
"this",
"->",
"password",
"]",
";",
"}"
] | Get the authorization credentials for a request
@return null|array
@throws \Exception | [
"Get",
"the",
"authorization",
"credentials",
"for",
"a",
"request"
] | 89c1c59c6af038dff790df6d5aaa9fc703246568 | https://github.com/DoSomething/gateway/blob/89c1c59c6af038dff790df6d5aaa9fc703246568/src/AuthorizesWithBasicAuth.php#L40-L47 |
35,204 | hail-framework/framework | src/Console/Application.php | Application.runWithTry | public function runWithTry(array $argv)
{
try {
return $this->run($argv);
} catch (CommandArgumentNotEnoughException $e) {
$this->logger->error($e->getMessage());
$this->logger->writeln('Expected argument prototypes:');
foreach ($e->getCommand()->getAllCommandPrototype() as $p) {
$this->logger->writeln("\t" . $p);
}
$this->logger->newline();
} catch (CommandNotFoundException $e) {
$this->logger->error($e->getMessage() . ' available commands are: ' .
implode(', ', $e->getCommand()->getVisibleCommandList())
);
$this->logger->newline();
$this->logger->writeln('Please try the command below to see the details:');
$this->logger->newline();
$this->logger->writeln("\t" . $this->getProgramName() . ' help ');
$this->logger->newline();
} catch (BadMethodCallException $e) {
$this->logger->error($e->getMessage());
$this->logger->error('Seems like an application logic error, please contact the developer.');
} catch (Exception $e) {
ExceptionPrinter::dump($e, $this->getOption('debug'));
}
return false;
} | php | public function runWithTry(array $argv)
{
try {
return $this->run($argv);
} catch (CommandArgumentNotEnoughException $e) {
$this->logger->error($e->getMessage());
$this->logger->writeln('Expected argument prototypes:');
foreach ($e->getCommand()->getAllCommandPrototype() as $p) {
$this->logger->writeln("\t" . $p);
}
$this->logger->newline();
} catch (CommandNotFoundException $e) {
$this->logger->error($e->getMessage() . ' available commands are: ' .
implode(', ', $e->getCommand()->getVisibleCommandList())
);
$this->logger->newline();
$this->logger->writeln('Please try the command below to see the details:');
$this->logger->newline();
$this->logger->writeln("\t" . $this->getProgramName() . ' help ');
$this->logger->newline();
} catch (BadMethodCallException $e) {
$this->logger->error($e->getMessage());
$this->logger->error('Seems like an application logic error, please contact the developer.');
} catch (Exception $e) {
ExceptionPrinter::dump($e, $this->getOption('debug'));
}
return false;
} | [
"public",
"function",
"runWithTry",
"(",
"array",
"$",
"argv",
")",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"run",
"(",
"$",
"argv",
")",
";",
"}",
"catch",
"(",
"CommandArgumentNotEnoughException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"error",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"writeln",
"(",
"'Expected argument prototypes:'",
")",
";",
"foreach",
"(",
"$",
"e",
"->",
"getCommand",
"(",
")",
"->",
"getAllCommandPrototype",
"(",
")",
"as",
"$",
"p",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"writeln",
"(",
"\"\\t\"",
".",
"$",
"p",
")",
";",
"}",
"$",
"this",
"->",
"logger",
"->",
"newline",
"(",
")",
";",
"}",
"catch",
"(",
"CommandNotFoundException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"error",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
".",
"' available commands are: '",
".",
"implode",
"(",
"', '",
",",
"$",
"e",
"->",
"getCommand",
"(",
")",
"->",
"getVisibleCommandList",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"newline",
"(",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"writeln",
"(",
"'Please try the command below to see the details:'",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"newline",
"(",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"writeln",
"(",
"\"\\t\"",
".",
"$",
"this",
"->",
"getProgramName",
"(",
")",
".",
"' help '",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"newline",
"(",
")",
";",
"}",
"catch",
"(",
"BadMethodCallException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"error",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"error",
"(",
"'Seems like an application logic error, please contact the developer.'",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"ExceptionPrinter",
"::",
"dump",
"(",
"$",
"e",
",",
"$",
"this",
"->",
"getOption",
"(",
"'debug'",
")",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Execute `run` method with a default try & catch block to catch the exception.
@param array $argv
@return bool return true for success, false for failure. the returned
state will be reflected to the exit code of the process. | [
"Execute",
"run",
"method",
"with",
"a",
"default",
"try",
"&",
"catch",
"block",
"to",
"catch",
"the",
"exception",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/Application.php#L117-L146 |
35,205 | hail-framework/framework | src/Console/Application.php | Application.run | public function run(array $argv)
{
$this->setProgramName($argv[0]);
$currentCommand = $this;
// init application,
// before parsing options, we have to known the registered commands.
$currentCommand->init();
// use getoption kit to parse application options
$parser = new ContinuousOptionParser($currentCommand->getOptionCollection());
// parse the first part options (options after script name)
// option parser should stop before next command name.
//
// $ app.php -v -d next
// |
// |->> parser
//
//
$currentCommand->setOptions(
$parser->parse($argv)
);
if (false === $currentCommand->prepare()) {
return false;
}
$commandStack = [];
$arguments = [];
// build the command list from command line arguments
while (!$parser->isEnd()) {
$a = $parser->getCurrentArgument();
// if current command is in subcommand list.
if ($currentCommand->hasCommands()) {
if (!$currentCommand->hasCommand($a)) {
if (!$this->getOption('no-interact') && ($guess = $currentCommand->guessCommand($a)) !== null) {
$a = $guess;
} else {
throw new CommandNotFoundException($currentCommand, $a);
}
}
$parser->advance(); // advance position
// get command object of "$a"
/** @var Command $nextCommand */
$nextCommand = $currentCommand->getCommand($a);
$parser->setSpecs($nextCommand->getOptionCollection());
// parse the option result for command.
$nextCommand->setOptions(
$parser->continueParse()
);
$commandStack[] = $currentCommand = $nextCommand; // save command object into the stack
} else {
$r = $parser->continueParse();
if (count($r)) {
// get the option result and merge the new result
$currentCommand->getOptions()->merge($r);
} else {
$a = $parser->advance();
$arguments[] = $a;
}
}
}
foreach ($commandStack as $cmd) {
if (false === $cmd->prepare()) {
return false;
}
}
// get last command and run
if ($lastCommand = array_pop($commandStack)) {
$lastCommand->executeWrapper($arguments);
$lastCommand->finish();
while ($cmd = array_pop($commandStack)) {
// call finish stage.. of every command.
$cmd->finish();
}
} else {
// no command specified.
$this->executeWrapper($arguments);
return true;
}
$currentCommand->finish();
$this->finish();
return true;
} | php | public function run(array $argv)
{
$this->setProgramName($argv[0]);
$currentCommand = $this;
// init application,
// before parsing options, we have to known the registered commands.
$currentCommand->init();
// use getoption kit to parse application options
$parser = new ContinuousOptionParser($currentCommand->getOptionCollection());
// parse the first part options (options after script name)
// option parser should stop before next command name.
//
// $ app.php -v -d next
// |
// |->> parser
//
//
$currentCommand->setOptions(
$parser->parse($argv)
);
if (false === $currentCommand->prepare()) {
return false;
}
$commandStack = [];
$arguments = [];
// build the command list from command line arguments
while (!$parser->isEnd()) {
$a = $parser->getCurrentArgument();
// if current command is in subcommand list.
if ($currentCommand->hasCommands()) {
if (!$currentCommand->hasCommand($a)) {
if (!$this->getOption('no-interact') && ($guess = $currentCommand->guessCommand($a)) !== null) {
$a = $guess;
} else {
throw new CommandNotFoundException($currentCommand, $a);
}
}
$parser->advance(); // advance position
// get command object of "$a"
/** @var Command $nextCommand */
$nextCommand = $currentCommand->getCommand($a);
$parser->setSpecs($nextCommand->getOptionCollection());
// parse the option result for command.
$nextCommand->setOptions(
$parser->continueParse()
);
$commandStack[] = $currentCommand = $nextCommand; // save command object into the stack
} else {
$r = $parser->continueParse();
if (count($r)) {
// get the option result and merge the new result
$currentCommand->getOptions()->merge($r);
} else {
$a = $parser->advance();
$arguments[] = $a;
}
}
}
foreach ($commandStack as $cmd) {
if (false === $cmd->prepare()) {
return false;
}
}
// get last command and run
if ($lastCommand = array_pop($commandStack)) {
$lastCommand->executeWrapper($arguments);
$lastCommand->finish();
while ($cmd = array_pop($commandStack)) {
// call finish stage.. of every command.
$cmd->finish();
}
} else {
// no command specified.
$this->executeWrapper($arguments);
return true;
}
$currentCommand->finish();
$this->finish();
return true;
} | [
"public",
"function",
"run",
"(",
"array",
"$",
"argv",
")",
"{",
"$",
"this",
"->",
"setProgramName",
"(",
"$",
"argv",
"[",
"0",
"]",
")",
";",
"$",
"currentCommand",
"=",
"$",
"this",
";",
"// init application,",
"// before parsing options, we have to known the registered commands.",
"$",
"currentCommand",
"->",
"init",
"(",
")",
";",
"// use getoption kit to parse application options",
"$",
"parser",
"=",
"new",
"ContinuousOptionParser",
"(",
"$",
"currentCommand",
"->",
"getOptionCollection",
"(",
")",
")",
";",
"// parse the first part options (options after script name)",
"// option parser should stop before next command name.",
"//",
"// $ app.php -v -d next",
"// |",
"// |->> parser",
"//",
"//",
"$",
"currentCommand",
"->",
"setOptions",
"(",
"$",
"parser",
"->",
"parse",
"(",
"$",
"argv",
")",
")",
";",
"if",
"(",
"false",
"===",
"$",
"currentCommand",
"->",
"prepare",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"commandStack",
"=",
"[",
"]",
";",
"$",
"arguments",
"=",
"[",
"]",
";",
"// build the command list from command line arguments",
"while",
"(",
"!",
"$",
"parser",
"->",
"isEnd",
"(",
")",
")",
"{",
"$",
"a",
"=",
"$",
"parser",
"->",
"getCurrentArgument",
"(",
")",
";",
"// if current command is in subcommand list.",
"if",
"(",
"$",
"currentCommand",
"->",
"hasCommands",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"currentCommand",
"->",
"hasCommand",
"(",
"$",
"a",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"getOption",
"(",
"'no-interact'",
")",
"&&",
"(",
"$",
"guess",
"=",
"$",
"currentCommand",
"->",
"guessCommand",
"(",
"$",
"a",
")",
")",
"!==",
"null",
")",
"{",
"$",
"a",
"=",
"$",
"guess",
";",
"}",
"else",
"{",
"throw",
"new",
"CommandNotFoundException",
"(",
"$",
"currentCommand",
",",
"$",
"a",
")",
";",
"}",
"}",
"$",
"parser",
"->",
"advance",
"(",
")",
";",
"// advance position",
"// get command object of \"$a\"",
"/** @var Command $nextCommand */",
"$",
"nextCommand",
"=",
"$",
"currentCommand",
"->",
"getCommand",
"(",
"$",
"a",
")",
";",
"$",
"parser",
"->",
"setSpecs",
"(",
"$",
"nextCommand",
"->",
"getOptionCollection",
"(",
")",
")",
";",
"// parse the option result for command.",
"$",
"nextCommand",
"->",
"setOptions",
"(",
"$",
"parser",
"->",
"continueParse",
"(",
")",
")",
";",
"$",
"commandStack",
"[",
"]",
"=",
"$",
"currentCommand",
"=",
"$",
"nextCommand",
";",
"// save command object into the stack",
"}",
"else",
"{",
"$",
"r",
"=",
"$",
"parser",
"->",
"continueParse",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"r",
")",
")",
"{",
"// get the option result and merge the new result",
"$",
"currentCommand",
"->",
"getOptions",
"(",
")",
"->",
"merge",
"(",
"$",
"r",
")",
";",
"}",
"else",
"{",
"$",
"a",
"=",
"$",
"parser",
"->",
"advance",
"(",
")",
";",
"$",
"arguments",
"[",
"]",
"=",
"$",
"a",
";",
"}",
"}",
"}",
"foreach",
"(",
"$",
"commandStack",
"as",
"$",
"cmd",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"cmd",
"->",
"prepare",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"// get last command and run",
"if",
"(",
"$",
"lastCommand",
"=",
"array_pop",
"(",
"$",
"commandStack",
")",
")",
"{",
"$",
"lastCommand",
"->",
"executeWrapper",
"(",
"$",
"arguments",
")",
";",
"$",
"lastCommand",
"->",
"finish",
"(",
")",
";",
"while",
"(",
"$",
"cmd",
"=",
"array_pop",
"(",
"$",
"commandStack",
")",
")",
"{",
"// call finish stage.. of every command.",
"$",
"cmd",
"->",
"finish",
"(",
")",
";",
"}",
"}",
"else",
"{",
"// no command specified.",
"$",
"this",
"->",
"executeWrapper",
"(",
"$",
"arguments",
")",
";",
"return",
"true",
";",
"}",
"$",
"currentCommand",
"->",
"finish",
"(",
")",
";",
"$",
"this",
"->",
"finish",
"(",
")",
";",
"return",
"true",
";",
"}"
] | Run application with
list argv
@param array $argv
@return bool return true for success, false for failure. the returned
state will be reflected to the exit code of the process.
@throws CommandNotFoundException | [
"Run",
"application",
"with",
"list",
"argv"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/Application.php#L159-L261 |
35,206 | hail-framework/framework | src/Console/Application.php | Application.prepare | public function prepare()
{
$this->startedAt = microtime(true);
if ($this->getOption('debug')) {
$this->logger->setLevel(LogLevel::DEBUG);
} elseif ($this->getOption('verbose')) {
$this->logger->setLevel(LogLevel::INFO);
} elseif ($this->getOption('quiet')) {
$this->logger->setLevel(LogLevel::ERROR);
} elseif ($this->config('debug', false)) {
$this->logger->setLevel(LogLevel::DEBUG);
} elseif ($this->config('verbose', false)) {
$this->logger->setLevel(LogLevel::INFO);
}
return true;
} | php | public function prepare()
{
$this->startedAt = microtime(true);
if ($this->getOption('debug')) {
$this->logger->setLevel(LogLevel::DEBUG);
} elseif ($this->getOption('verbose')) {
$this->logger->setLevel(LogLevel::INFO);
} elseif ($this->getOption('quiet')) {
$this->logger->setLevel(LogLevel::ERROR);
} elseif ($this->config('debug', false)) {
$this->logger->setLevel(LogLevel::DEBUG);
} elseif ($this->config('verbose', false)) {
$this->logger->setLevel(LogLevel::INFO);
}
return true;
} | [
"public",
"function",
"prepare",
"(",
")",
"{",
"$",
"this",
"->",
"startedAt",
"=",
"microtime",
"(",
"true",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getOption",
"(",
"'debug'",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"setLevel",
"(",
"LogLevel",
"::",
"DEBUG",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"getOption",
"(",
"'verbose'",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"setLevel",
"(",
"LogLevel",
"::",
"INFO",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"getOption",
"(",
"'quiet'",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"setLevel",
"(",
"LogLevel",
"::",
"ERROR",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"config",
"(",
"'debug'",
",",
"false",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"setLevel",
"(",
"LogLevel",
"::",
"DEBUG",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"config",
"(",
"'verbose'",
",",
"false",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"setLevel",
"(",
"LogLevel",
"::",
"INFO",
")",
";",
"}",
"return",
"true",
";",
"}"
] | This is a `before` trigger of an app. when the application is getting
started, we run `prepare` method to prepare the settings. | [
"This",
"is",
"a",
"before",
"trigger",
"of",
"an",
"app",
".",
"when",
"the",
"application",
"is",
"getting",
"started",
"we",
"run",
"prepare",
"method",
"to",
"prepare",
"the",
"settings",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/Application.php#L267-L284 |
35,207 | hail-framework/framework | src/Console/Application.php | Application.execute | public function execute(...$arguments)
{
$options = $this->getOptions();
if ($options->version) {
$this->logger->writeln($this->name() . ' - ' . static::VERSION);
$this->logger->writeln('console core: ' . static::CORE_VERSION);
return;
}
// show list and help by default
$help = $this->getCommand('help');
$help->setOptions($options);
if ($help || $options->help) {
$help->executeWrapper($arguments);
return;
}
throw new CommandNotFoundException($this, 'help');
} | php | public function execute(...$arguments)
{
$options = $this->getOptions();
if ($options->version) {
$this->logger->writeln($this->name() . ' - ' . static::VERSION);
$this->logger->writeln('console core: ' . static::CORE_VERSION);
return;
}
// show list and help by default
$help = $this->getCommand('help');
$help->setOptions($options);
if ($help || $options->help) {
$help->executeWrapper($arguments);
return;
}
throw new CommandNotFoundException($this, 'help');
} | [
"public",
"function",
"execute",
"(",
"...",
"$",
"arguments",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"getOptions",
"(",
")",
";",
"if",
"(",
"$",
"options",
"->",
"version",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"writeln",
"(",
"$",
"this",
"->",
"name",
"(",
")",
".",
"' - '",
".",
"static",
"::",
"VERSION",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"writeln",
"(",
"'console core: '",
".",
"static",
"::",
"CORE_VERSION",
")",
";",
"return",
";",
"}",
"// show list and help by default",
"$",
"help",
"=",
"$",
"this",
"->",
"getCommand",
"(",
"'help'",
")",
";",
"$",
"help",
"->",
"setOptions",
"(",
"$",
"options",
")",
";",
"if",
"(",
"$",
"help",
"||",
"$",
"options",
"->",
"help",
")",
"{",
"$",
"help",
"->",
"executeWrapper",
"(",
"$",
"arguments",
")",
";",
"return",
";",
"}",
"throw",
"new",
"CommandNotFoundException",
"(",
"$",
"this",
",",
"'help'",
")",
";",
"}"
] | This method is the top logic of an application. when there is no
argument provided, we show help content by default.
@param array ...$arguments
@throws CommandNotFoundException | [
"This",
"method",
"is",
"the",
"top",
"logic",
"of",
"an",
"application",
".",
"when",
"there",
"is",
"no",
"argument",
"provided",
"we",
"show",
"help",
"content",
"by",
"default",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/Application.php#L322-L342 |
35,208 | hail-framework/framework | src/Image/Size.php | Size.getConstraint | private function getConstraint(Closure $callback = null)
{
$constraint = new Constraint(clone $this);
if ($callback !== null) {
$callback($constraint);
}
return $constraint;
} | php | private function getConstraint(Closure $callback = null)
{
$constraint = new Constraint(clone $this);
if ($callback !== null) {
$callback($constraint);
}
return $constraint;
} | [
"private",
"function",
"getConstraint",
"(",
"Closure",
"$",
"callback",
"=",
"null",
")",
"{",
"$",
"constraint",
"=",
"new",
"Constraint",
"(",
"clone",
"$",
"this",
")",
";",
"if",
"(",
"$",
"callback",
"!==",
"null",
")",
"{",
"$",
"callback",
"(",
"$",
"constraint",
")",
";",
"}",
"return",
"$",
"constraint",
";",
"}"
] | Runs constraints on current size
@param Closure|null $callback
@return \Hail\Image\Constraint | [
"Runs",
"constraints",
"on",
"current",
"size"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Image/Size.php#L370-L379 |
35,209 | hail-framework/framework | src/Http/Helpers.php | Helpers.getMethod | public static function getMethod(array $server): string
{
$method = $server['REQUEST_METHOD'] ?? 'GET';
if ($method === 'POST' &&
isset(
$server['HTTP_X_HTTP_METHOD_OVERRIDE'],
self::$methods[$server['HTTP_X_HTTP_METHOD_OVERRIDE']]
)
) {
$method = $server['HTTP_X_HTTP_METHOD_OVERRIDE'];
}
return $method;
} | php | public static function getMethod(array $server): string
{
$method = $server['REQUEST_METHOD'] ?? 'GET';
if ($method === 'POST' &&
isset(
$server['HTTP_X_HTTP_METHOD_OVERRIDE'],
self::$methods[$server['HTTP_X_HTTP_METHOD_OVERRIDE']]
)
) {
$method = $server['HTTP_X_HTTP_METHOD_OVERRIDE'];
}
return $method;
} | [
"public",
"static",
"function",
"getMethod",
"(",
"array",
"$",
"server",
")",
":",
"string",
"{",
"$",
"method",
"=",
"$",
"server",
"[",
"'REQUEST_METHOD'",
"]",
"??",
"'GET'",
";",
"if",
"(",
"$",
"method",
"===",
"'POST'",
"&&",
"isset",
"(",
"$",
"server",
"[",
"'HTTP_X_HTTP_METHOD_OVERRIDE'",
"]",
",",
"self",
"::",
"$",
"methods",
"[",
"$",
"server",
"[",
"'HTTP_X_HTTP_METHOD_OVERRIDE'",
"]",
"]",
")",
")",
"{",
"$",
"method",
"=",
"$",
"server",
"[",
"'HTTP_X_HTTP_METHOD_OVERRIDE'",
"]",
";",
"}",
"return",
"$",
"method",
";",
"}"
] | Get method from server variables.
@param array $server Typically $_SERVER or similar structure.
@return string | [
"Get",
"method",
"from",
"server",
"variables",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Http/Helpers.php#L244-L257 |
35,210 | hail-framework/framework | src/Http/Helpers.php | Helpers.getProtocol | public static function getProtocol(array $server): string
{
if (!isset($server['SERVER_PROTOCOL'])) {
return '1.1';
}
if (!\preg_match('#^(HTTP/)?(?P<version>[1-9]\d*(?:\.\d)?)$#', $server['SERVER_PROTOCOL'], $matches)) {
throw new \UnexpectedValueException("Unrecognized protocol version ({$server['SERVER_PROTOCOL']})");
}
return $matches['version'];
} | php | public static function getProtocol(array $server): string
{
if (!isset($server['SERVER_PROTOCOL'])) {
return '1.1';
}
if (!\preg_match('#^(HTTP/)?(?P<version>[1-9]\d*(?:\.\d)?)$#', $server['SERVER_PROTOCOL'], $matches)) {
throw new \UnexpectedValueException("Unrecognized protocol version ({$server['SERVER_PROTOCOL']})");
}
return $matches['version'];
} | [
"public",
"static",
"function",
"getProtocol",
"(",
"array",
"$",
"server",
")",
":",
"string",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"server",
"[",
"'SERVER_PROTOCOL'",
"]",
")",
")",
"{",
"return",
"'1.1'",
";",
"}",
"if",
"(",
"!",
"\\",
"preg_match",
"(",
"'#^(HTTP/)?(?P<version>[1-9]\\d*(?:\\.\\d)?)$#'",
",",
"$",
"server",
"[",
"'SERVER_PROTOCOL'",
"]",
",",
"$",
"matches",
")",
")",
"{",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"\"Unrecognized protocol version ({$server['SERVER_PROTOCOL']})\"",
")",
";",
"}",
"return",
"$",
"matches",
"[",
"'version'",
"]",
";",
"}"
] | Get protocol from server variables.
@param array $server Typically $_SERVER or similar structure.
@return string
@throws \UnexpectedValueException | [
"Get",
"protocol",
"from",
"server",
"variables",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Http/Helpers.php#L267-L278 |
35,211 | hail-framework/framework | src/Http/Helpers.php | Helpers.fixContentLength | public static function fixContentLength(MessageInterface $response): MessageInterface
{
$size = $response->getBody()->getSize();
if ($size !== null) {
return $response->withHeader('Content-Length', (string) $size);
}
return $response->withoutHeader('Content-Length');
} | php | public static function fixContentLength(MessageInterface $response): MessageInterface
{
$size = $response->getBody()->getSize();
if ($size !== null) {
return $response->withHeader('Content-Length', (string) $size);
}
return $response->withoutHeader('Content-Length');
} | [
"public",
"static",
"function",
"fixContentLength",
"(",
"MessageInterface",
"$",
"response",
")",
":",
"MessageInterface",
"{",
"$",
"size",
"=",
"$",
"response",
"->",
"getBody",
"(",
")",
"->",
"getSize",
"(",
")",
";",
"if",
"(",
"$",
"size",
"!==",
"null",
")",
"{",
"return",
"$",
"response",
"->",
"withHeader",
"(",
"'Content-Length'",
",",
"(",
"string",
")",
"$",
"size",
")",
";",
"}",
"return",
"$",
"response",
"->",
"withoutHeader",
"(",
"'Content-Length'",
")",
";",
"}"
] | Add or remove the Content-Length header
Used by middlewares that modify the body content
@param MessageInterface $response
@return MessageInterface | [
"Add",
"or",
"remove",
"the",
"Content",
"-",
"Length",
"header",
"Used",
"by",
"middlewares",
"that",
"modify",
"the",
"body",
"content"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Http/Helpers.php#L327-L335 |
35,212 | hail-framework/framework | src/Database/Migration/Config.php | Config.getEnvironments | public function getEnvironments()
{
if (isset($this->values['environments'])) {
$environments = [];
foreach ($this->values['environments'] as $key => $value) {
if (is_array($value)) {
$environments[$key] = $value;
}
}
return $environments;
}
return null;
} | php | public function getEnvironments()
{
if (isset($this->values['environments'])) {
$environments = [];
foreach ($this->values['environments'] as $key => $value) {
if (is_array($value)) {
$environments[$key] = $value;
}
}
return $environments;
}
return null;
} | [
"public",
"function",
"getEnvironments",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"values",
"[",
"'environments'",
"]",
")",
")",
"{",
"$",
"environments",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"values",
"[",
"'environments'",
"]",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"environments",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"environments",
";",
"}",
"return",
"null",
";",
"}"
] | Returns the configuration for each environment.
This method returns <code>null</code> if no environments exist.
@return array|null | [
"Returns",
"the",
"configuration",
"for",
"each",
"environment",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Config.php#L71-L85 |
35,213 | hail-framework/framework | src/Database/Migration/Config.php | Config.getDefaultEnvironment | public function getDefaultEnvironment()
{
// if the user has configured a default database then use it,
// providing it actually exists!
if (isset($this->values['environments']['default_database'])) {
if ($this->getEnvironment($this->values['environments']['default_database'])) {
return $this->values['environments']['default_database'];
}
throw new \RuntimeException(sprintf(
'The environment configuration for \'%s\' is missing',
$this->values['environments']['default_database']
));
}
// else default to the first available one
if (is_array($this->getEnvironments()) && count($this->getEnvironments()) > 0) {
$names = array_keys($this->getEnvironments());
return $names[0];
}
throw new \RuntimeException('Could not find a default environment');
} | php | public function getDefaultEnvironment()
{
// if the user has configured a default database then use it,
// providing it actually exists!
if (isset($this->values['environments']['default_database'])) {
if ($this->getEnvironment($this->values['environments']['default_database'])) {
return $this->values['environments']['default_database'];
}
throw new \RuntimeException(sprintf(
'The environment configuration for \'%s\' is missing',
$this->values['environments']['default_database']
));
}
// else default to the first available one
if (is_array($this->getEnvironments()) && count($this->getEnvironments()) > 0) {
$names = array_keys($this->getEnvironments());
return $names[0];
}
throw new \RuntimeException('Could not find a default environment');
} | [
"public",
"function",
"getDefaultEnvironment",
"(",
")",
"{",
"// if the user has configured a default database then use it,",
"// providing it actually exists!",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"values",
"[",
"'environments'",
"]",
"[",
"'default_database'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getEnvironment",
"(",
"$",
"this",
"->",
"values",
"[",
"'environments'",
"]",
"[",
"'default_database'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"values",
"[",
"'environments'",
"]",
"[",
"'default_database'",
"]",
";",
"}",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'The environment configuration for \\'%s\\' is missing'",
",",
"$",
"this",
"->",
"values",
"[",
"'environments'",
"]",
"[",
"'default_database'",
"]",
")",
")",
";",
"}",
"// else default to the first available one",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"getEnvironments",
"(",
")",
")",
"&&",
"count",
"(",
"$",
"this",
"->",
"getEnvironments",
"(",
")",
")",
">",
"0",
")",
"{",
"$",
"names",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"getEnvironments",
"(",
")",
")",
";",
"return",
"$",
"names",
"[",
"0",
"]",
";",
"}",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Could not find a default environment'",
")",
";",
"}"
] | Gets the default environment name.
@throws \RuntimeException
@return string | [
"Gets",
"the",
"default",
"environment",
"name",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Config.php#L129-L152 |
35,214 | hail-framework/framework | src/Database/Migration/Config.php | Config.getMigrationBaseClassName | public function getMigrationBaseClassName($dropNamespace = true)
{
$className = $this->values['migration_base_class'] ?? AbstractMigration::class;
if ($dropNamespace) {
return substr(strrchr($className, '\\'), 1) ?: $className;
}
return $className;
} | php | public function getMigrationBaseClassName($dropNamespace = true)
{
$className = $this->values['migration_base_class'] ?? AbstractMigration::class;
if ($dropNamespace) {
return substr(strrchr($className, '\\'), 1) ?: $className;
}
return $className;
} | [
"public",
"function",
"getMigrationBaseClassName",
"(",
"$",
"dropNamespace",
"=",
"true",
")",
"{",
"$",
"className",
"=",
"$",
"this",
"->",
"values",
"[",
"'migration_base_class'",
"]",
"??",
"AbstractMigration",
"::",
"class",
";",
"if",
"(",
"$",
"dropNamespace",
")",
"{",
"return",
"substr",
"(",
"strrchr",
"(",
"$",
"className",
",",
"'\\\\'",
")",
",",
"1",
")",
"?",
":",
"$",
"className",
";",
"}",
"return",
"$",
"className",
";",
"}"
] | Gets the base class name for migrations.
@param bool $dropNamespace Return the base migration class name without the namespace.
@return string | [
"Gets",
"the",
"base",
"class",
"name",
"for",
"migrations",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Config.php#L191-L200 |
35,215 | hail-framework/framework | src/Console/Command/Help.php | Help.execute | public function execute(...$commandNames)
{
$logger = $this->logger;
$app = $this->getApplication();
$progname = basename($app->getProgramName());
// if there is no subcommand to render help, show all available commands.
$count = count($commandNames);
if ($count) {
$cmd = $app;
for ($i = 0; $cmd && $i < $count; ++$i) {
$cmd = $cmd->getCommand($commandNames[$i]);
}
if (!$cmd) {
throw new \Exception('Command entry ' . implode(' ', $commandNames) . ' not found');
}
if ($brief = $cmd->brief()) {
$logger->writeln('NAME', 'yellow');
$logger->writeln("\t<strong_white>" . $cmd->name() . '</strong_white> - ' . $brief);
$logger->newline();
}
if ($aliases = $cmd->aliases()) {
$logger->writeln('ALIASES', 'yellow');
$logger->writeln("\t<strong_white>" . implode(', ', $aliases) . '</strong_white>');
$logger->newline();
}
$this->printUsage($cmd);
$logger->writeln('SYNOPSIS', 'yellow');
$prototypes = $cmd->getAllCommandPrototype();
foreach ($prototypes as $prototype) {
$logger->writeln("\t" . ' ' . $prototype);
}
$logger->newline();
$this->printOptions($cmd);
$this->printCommand($cmd);
$this->printHelp($cmd);
} else {
// print application
$cmd = $this->parent;
$logger->writeln(ucfirst($cmd->brief()), 'strong_white');
$logger->newline();
$this->printUsage($cmd);
$logger->writeln('SYNOPSIS', 'yellow');
$logger->write("\t" . $progname);
if (!empty($cmd->getOptionCollection()->options)) {
$logger->write(' [options]');
}
if ($cmd->hasCommands()) {
$logger->write(' <command>');
} else {
foreach ($cmd->getArguments() as $argument) {
$logger->write(' <' . $argument->name() . '>');
}
}
$logger->newline();
$logger->newline();
$this->printOptions($cmd);
$this->printCommand($cmd);
$this->printHelp($cmd);
}
} | php | public function execute(...$commandNames)
{
$logger = $this->logger;
$app = $this->getApplication();
$progname = basename($app->getProgramName());
// if there is no subcommand to render help, show all available commands.
$count = count($commandNames);
if ($count) {
$cmd = $app;
for ($i = 0; $cmd && $i < $count; ++$i) {
$cmd = $cmd->getCommand($commandNames[$i]);
}
if (!$cmd) {
throw new \Exception('Command entry ' . implode(' ', $commandNames) . ' not found');
}
if ($brief = $cmd->brief()) {
$logger->writeln('NAME', 'yellow');
$logger->writeln("\t<strong_white>" . $cmd->name() . '</strong_white> - ' . $brief);
$logger->newline();
}
if ($aliases = $cmd->aliases()) {
$logger->writeln('ALIASES', 'yellow');
$logger->writeln("\t<strong_white>" . implode(', ', $aliases) . '</strong_white>');
$logger->newline();
}
$this->printUsage($cmd);
$logger->writeln('SYNOPSIS', 'yellow');
$prototypes = $cmd->getAllCommandPrototype();
foreach ($prototypes as $prototype) {
$logger->writeln("\t" . ' ' . $prototype);
}
$logger->newline();
$this->printOptions($cmd);
$this->printCommand($cmd);
$this->printHelp($cmd);
} else {
// print application
$cmd = $this->parent;
$logger->writeln(ucfirst($cmd->brief()), 'strong_white');
$logger->newline();
$this->printUsage($cmd);
$logger->writeln('SYNOPSIS', 'yellow');
$logger->write("\t" . $progname);
if (!empty($cmd->getOptionCollection()->options)) {
$logger->write(' [options]');
}
if ($cmd->hasCommands()) {
$logger->write(' <command>');
} else {
foreach ($cmd->getArguments() as $argument) {
$logger->write(' <' . $argument->name() . '>');
}
}
$logger->newline();
$logger->newline();
$this->printOptions($cmd);
$this->printCommand($cmd);
$this->printHelp($cmd);
}
} | [
"public",
"function",
"execute",
"(",
"...",
"$",
"commandNames",
")",
"{",
"$",
"logger",
"=",
"$",
"this",
"->",
"logger",
";",
"$",
"app",
"=",
"$",
"this",
"->",
"getApplication",
"(",
")",
";",
"$",
"progname",
"=",
"basename",
"(",
"$",
"app",
"->",
"getProgramName",
"(",
")",
")",
";",
"// if there is no subcommand to render help, show all available commands.",
"$",
"count",
"=",
"count",
"(",
"$",
"commandNames",
")",
";",
"if",
"(",
"$",
"count",
")",
"{",
"$",
"cmd",
"=",
"$",
"app",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"cmd",
"&&",
"$",
"i",
"<",
"$",
"count",
";",
"++",
"$",
"i",
")",
"{",
"$",
"cmd",
"=",
"$",
"cmd",
"->",
"getCommand",
"(",
"$",
"commandNames",
"[",
"$",
"i",
"]",
")",
";",
"}",
"if",
"(",
"!",
"$",
"cmd",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Command entry '",
".",
"implode",
"(",
"' '",
",",
"$",
"commandNames",
")",
".",
"' not found'",
")",
";",
"}",
"if",
"(",
"$",
"brief",
"=",
"$",
"cmd",
"->",
"brief",
"(",
")",
")",
"{",
"$",
"logger",
"->",
"writeln",
"(",
"'NAME'",
",",
"'yellow'",
")",
";",
"$",
"logger",
"->",
"writeln",
"(",
"\"\\t<strong_white>\"",
".",
"$",
"cmd",
"->",
"name",
"(",
")",
".",
"'</strong_white> - '",
".",
"$",
"brief",
")",
";",
"$",
"logger",
"->",
"newline",
"(",
")",
";",
"}",
"if",
"(",
"$",
"aliases",
"=",
"$",
"cmd",
"->",
"aliases",
"(",
")",
")",
"{",
"$",
"logger",
"->",
"writeln",
"(",
"'ALIASES'",
",",
"'yellow'",
")",
";",
"$",
"logger",
"->",
"writeln",
"(",
"\"\\t<strong_white>\"",
".",
"implode",
"(",
"', '",
",",
"$",
"aliases",
")",
".",
"'</strong_white>'",
")",
";",
"$",
"logger",
"->",
"newline",
"(",
")",
";",
"}",
"$",
"this",
"->",
"printUsage",
"(",
"$",
"cmd",
")",
";",
"$",
"logger",
"->",
"writeln",
"(",
"'SYNOPSIS'",
",",
"'yellow'",
")",
";",
"$",
"prototypes",
"=",
"$",
"cmd",
"->",
"getAllCommandPrototype",
"(",
")",
";",
"foreach",
"(",
"$",
"prototypes",
"as",
"$",
"prototype",
")",
"{",
"$",
"logger",
"->",
"writeln",
"(",
"\"\\t\"",
".",
"' '",
".",
"$",
"prototype",
")",
";",
"}",
"$",
"logger",
"->",
"newline",
"(",
")",
";",
"$",
"this",
"->",
"printOptions",
"(",
"$",
"cmd",
")",
";",
"$",
"this",
"->",
"printCommand",
"(",
"$",
"cmd",
")",
";",
"$",
"this",
"->",
"printHelp",
"(",
"$",
"cmd",
")",
";",
"}",
"else",
"{",
"// print application",
"$",
"cmd",
"=",
"$",
"this",
"->",
"parent",
";",
"$",
"logger",
"->",
"writeln",
"(",
"ucfirst",
"(",
"$",
"cmd",
"->",
"brief",
"(",
")",
")",
",",
"'strong_white'",
")",
";",
"$",
"logger",
"->",
"newline",
"(",
")",
";",
"$",
"this",
"->",
"printUsage",
"(",
"$",
"cmd",
")",
";",
"$",
"logger",
"->",
"writeln",
"(",
"'SYNOPSIS'",
",",
"'yellow'",
")",
";",
"$",
"logger",
"->",
"write",
"(",
"\"\\t\"",
".",
"$",
"progname",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"cmd",
"->",
"getOptionCollection",
"(",
")",
"->",
"options",
")",
")",
"{",
"$",
"logger",
"->",
"write",
"(",
"' [options]'",
")",
";",
"}",
"if",
"(",
"$",
"cmd",
"->",
"hasCommands",
"(",
")",
")",
"{",
"$",
"logger",
"->",
"write",
"(",
"' <command>'",
")",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"cmd",
"->",
"getArguments",
"(",
")",
"as",
"$",
"argument",
")",
"{",
"$",
"logger",
"->",
"write",
"(",
"' <'",
".",
"$",
"argument",
"->",
"name",
"(",
")",
".",
"'>'",
")",
";",
"}",
"}",
"$",
"logger",
"->",
"newline",
"(",
")",
";",
"$",
"logger",
"->",
"newline",
"(",
")",
";",
"$",
"this",
"->",
"printOptions",
"(",
"$",
"cmd",
")",
";",
"$",
"this",
"->",
"printCommand",
"(",
"$",
"cmd",
")",
";",
"$",
"this",
"->",
"printHelp",
"(",
"$",
"cmd",
")",
";",
"}",
"}"
] | Show command help message.
@param array ...$commandNames command name
@throws \Exception | [
"Show",
"command",
"help",
"message",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/Command/Help.php#L74-L146 |
35,216 | cfxmarkets/php-public-models | src/Exchange/Order.php | Order.validateStatusActive | protected function validateStatusActive($field) {
if (!$this->initializing) {
$passedStates = [
'active' => ["Order Active", "This order is currently active and cannot be altered"],
'cancelled' => ["Item Cancelled", "This order has been cancelled and cannot be altered"],
'matched' => ["Item Sold", "This order has already been successfully executed and sold and cannot be altered"],
'expired' => ["Item Expired", "This intent has expired and cannot be altered"],
];
if (in_array($this->getStatus(), array_keys($passedStates), true)) {
$e = $passedStates[$this->getStatus()];
$this->setError($field, 'immutableStatus', [
"title" => "Order Not Alterable",
"detail" => $e[1],
]);
return false;
} else {
$this->clearError($field, 'immutableStatus');
return true;
}
}
} | php | protected function validateStatusActive($field) {
if (!$this->initializing) {
$passedStates = [
'active' => ["Order Active", "This order is currently active and cannot be altered"],
'cancelled' => ["Item Cancelled", "This order has been cancelled and cannot be altered"],
'matched' => ["Item Sold", "This order has already been successfully executed and sold and cannot be altered"],
'expired' => ["Item Expired", "This intent has expired and cannot be altered"],
];
if (in_array($this->getStatus(), array_keys($passedStates), true)) {
$e = $passedStates[$this->getStatus()];
$this->setError($field, 'immutableStatus', [
"title" => "Order Not Alterable",
"detail" => $e[1],
]);
return false;
} else {
$this->clearError($field, 'immutableStatus');
return true;
}
}
} | [
"protected",
"function",
"validateStatusActive",
"(",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"initializing",
")",
"{",
"$",
"passedStates",
"=",
"[",
"'active'",
"=>",
"[",
"\"Order Active\"",
",",
"\"This order is currently active and cannot be altered\"",
"]",
",",
"'cancelled'",
"=>",
"[",
"\"Item Cancelled\"",
",",
"\"This order has been cancelled and cannot be altered\"",
"]",
",",
"'matched'",
"=>",
"[",
"\"Item Sold\"",
",",
"\"This order has already been successfully executed and sold and cannot be altered\"",
"]",
",",
"'expired'",
"=>",
"[",
"\"Item Expired\"",
",",
"\"This intent has expired and cannot be altered\"",
"]",
",",
"]",
";",
"if",
"(",
"in_array",
"(",
"$",
"this",
"->",
"getStatus",
"(",
")",
",",
"array_keys",
"(",
"$",
"passedStates",
")",
",",
"true",
")",
")",
"{",
"$",
"e",
"=",
"$",
"passedStates",
"[",
"$",
"this",
"->",
"getStatus",
"(",
")",
"]",
";",
"$",
"this",
"->",
"setError",
"(",
"$",
"field",
",",
"'immutableStatus'",
",",
"[",
"\"title\"",
"=>",
"\"Order Not Alterable\"",
",",
"\"detail\"",
"=>",
"$",
"e",
"[",
"1",
"]",
",",
"]",
")",
";",
"return",
"false",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"clearError",
"(",
"$",
"field",
",",
"'immutableStatus'",
")",
";",
"return",
"true",
";",
"}",
"}",
"}"
] | Validates that the current status permits edits
If the order is actively listed, certain fields should not be editable. This checks the status and
sets an error if the user is trying to edit fields that are not editable for the given status.
@param string $field The name of the field being validated
@return bool Whether or not the validation has passed | [
"Validates",
"that",
"the",
"current",
"status",
"permits",
"edits"
] | b91a58f7d9519b98b29c58f0911e976e361a5f65 | https://github.com/cfxmarkets/php-public-models/blob/b91a58f7d9519b98b29c58f0911e976e361a5f65/src/Exchange/Order.php#L294-L315 |
35,217 | hail-framework/framework | src/Console/CommandLoader.php | CommandLoader.autoload | public static function autoload(Command $parent)
{
$reflector = new \ReflectionObject($parent);
$dir = \dirname($reflector->getFileName()) . '/';
/*
* Commands to be autoloaded must located at specific directory.
* If parent is Application, commands must be whthin App/Command/ directory.
* If parent is another command named Foo or FooCommand, sub-commands must
* within App/Command/Foo/ directory, if App/Command/Foo/ directory
* not exists found in App/Command/Command/ directory.
*/
if ($parent->isApplication()) {
$subNamespace = 'Command';
} else {
$subNamespace = static::clearSuffix(
$reflector->getShortName()
);
if (!\is_dir($dir . $subNamespace)) {
$subNamespace = 'Command';
}
}
$dir .= $subNamespace;
if (!\is_dir($dir)) {
return;
}
$classes = static::scanPhp($dir);
$namespace = '\\' . $reflector->getNamespaceName() . '\\' . $subNamespace;
foreach ($classes as $class) {
$class = $namespace . '\\' . $class;
$reflection = new \ReflectionClass($class);
if ($reflection->isInstantiable()) {
$parent->addCommand($class);
}
}
} | php | public static function autoload(Command $parent)
{
$reflector = new \ReflectionObject($parent);
$dir = \dirname($reflector->getFileName()) . '/';
/*
* Commands to be autoloaded must located at specific directory.
* If parent is Application, commands must be whthin App/Command/ directory.
* If parent is another command named Foo or FooCommand, sub-commands must
* within App/Command/Foo/ directory, if App/Command/Foo/ directory
* not exists found in App/Command/Command/ directory.
*/
if ($parent->isApplication()) {
$subNamespace = 'Command';
} else {
$subNamespace = static::clearSuffix(
$reflector->getShortName()
);
if (!\is_dir($dir . $subNamespace)) {
$subNamespace = 'Command';
}
}
$dir .= $subNamespace;
if (!\is_dir($dir)) {
return;
}
$classes = static::scanPhp($dir);
$namespace = '\\' . $reflector->getNamespaceName() . '\\' . $subNamespace;
foreach ($classes as $class) {
$class = $namespace . '\\' . $class;
$reflection = new \ReflectionClass($class);
if ($reflection->isInstantiable()) {
$parent->addCommand($class);
}
}
} | [
"public",
"static",
"function",
"autoload",
"(",
"Command",
"$",
"parent",
")",
"{",
"$",
"reflector",
"=",
"new",
"\\",
"ReflectionObject",
"(",
"$",
"parent",
")",
";",
"$",
"dir",
"=",
"\\",
"dirname",
"(",
"$",
"reflector",
"->",
"getFileName",
"(",
")",
")",
".",
"'/'",
";",
"/*\n * Commands to be autoloaded must located at specific directory.\n * If parent is Application, commands must be whthin App/Command/ directory.\n * If parent is another command named Foo or FooCommand, sub-commands must\n * within App/Command/Foo/ directory, if App/Command/Foo/ directory\n * not exists found in App/Command/Command/ directory.\n */",
"if",
"(",
"$",
"parent",
"->",
"isApplication",
"(",
")",
")",
"{",
"$",
"subNamespace",
"=",
"'Command'",
";",
"}",
"else",
"{",
"$",
"subNamespace",
"=",
"static",
"::",
"clearSuffix",
"(",
"$",
"reflector",
"->",
"getShortName",
"(",
")",
")",
";",
"if",
"(",
"!",
"\\",
"is_dir",
"(",
"$",
"dir",
".",
"$",
"subNamespace",
")",
")",
"{",
"$",
"subNamespace",
"=",
"'Command'",
";",
"}",
"}",
"$",
"dir",
".=",
"$",
"subNamespace",
";",
"if",
"(",
"!",
"\\",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"return",
";",
"}",
"$",
"classes",
"=",
"static",
"::",
"scanPhp",
"(",
"$",
"dir",
")",
";",
"$",
"namespace",
"=",
"'\\\\'",
".",
"$",
"reflector",
"->",
"getNamespaceName",
"(",
")",
".",
"'\\\\'",
".",
"$",
"subNamespace",
";",
"foreach",
"(",
"$",
"classes",
"as",
"$",
"class",
")",
"{",
"$",
"class",
"=",
"$",
"namespace",
".",
"'\\\\'",
".",
"$",
"class",
";",
"$",
"reflection",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"class",
")",
";",
"if",
"(",
"$",
"reflection",
"->",
"isInstantiable",
"(",
")",
")",
"{",
"$",
"parent",
"->",
"addCommand",
"(",
"$",
"class",
")",
";",
"}",
"}",
"}"
] | Add all commands in a directory to parent command
@param Command $parent object we want to load its commands/subcommands
@return void
@throws CommandClassNotFoundException
@throws \ReflectionException | [
"Add",
"all",
"commands",
"in",
"a",
"directory",
"to",
"parent",
"command"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/CommandLoader.php#L62-L102 |
35,218 | hail-framework/framework | src/Console/CommandLoader.php | CommandLoader.inverseTranslate | public static function inverseTranslate(string $className): string
{
// remove the suffix 'Command', then lower case the first letter
$className = \lcfirst(static::clearSuffix($className));
return \strtolower(
\preg_replace('/([A-Z])/', ':\1', $className)
);
} | php | public static function inverseTranslate(string $className): string
{
// remove the suffix 'Command', then lower case the first letter
$className = \lcfirst(static::clearSuffix($className));
return \strtolower(
\preg_replace('/([A-Z])/', ':\1', $className)
);
} | [
"public",
"static",
"function",
"inverseTranslate",
"(",
"string",
"$",
"className",
")",
":",
"string",
"{",
"// remove the suffix 'Command', then lower case the first letter",
"$",
"className",
"=",
"\\",
"lcfirst",
"(",
"static",
"::",
"clearSuffix",
"(",
"$",
"className",
")",
")",
";",
"return",
"\\",
"strtolower",
"(",
"\\",
"preg_replace",
"(",
"'/([A-Z])/'",
",",
"':\\1'",
",",
"$",
"className",
")",
")",
";",
"}"
] | Translate class name to command name
This method is inverse of self::translate()
HelpCommand => help
SuchALongCommand => such:a:long
@param string $className class name.
@return string translated command name. | [
"Translate",
"class",
"name",
"to",
"command",
"name"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/CommandLoader.php#L136-L144 |
35,219 | hail-framework/framework | src/Redis/Cluster/Native.php | Native.getConnectionBySlot | public function getConnectionBySlot($slot)
{
if ($slot < 0x0000 || $slot > 0x3FFF) {
throw new \OutOfBoundsException("Invalid slot [$slot].");
}
if (isset($this->slots[$slot])) {
return $this->slots[$slot];
}
$connectionID = $this->guessNode($slot);
if (!$connection = $this->getConnectionById($connectionID)) {
$connection = $this->createConnection($connectionID);
}
return $this->slots[$slot] = $connection;
} | php | public function getConnectionBySlot($slot)
{
if ($slot < 0x0000 || $slot > 0x3FFF) {
throw new \OutOfBoundsException("Invalid slot [$slot].");
}
if (isset($this->slots[$slot])) {
return $this->slots[$slot];
}
$connectionID = $this->guessNode($slot);
if (!$connection = $this->getConnectionById($connectionID)) {
$connection = $this->createConnection($connectionID);
}
return $this->slots[$slot] = $connection;
} | [
"public",
"function",
"getConnectionBySlot",
"(",
"$",
"slot",
")",
"{",
"if",
"(",
"$",
"slot",
"<",
"0x0000",
"||",
"$",
"slot",
">",
"0x3FFF",
")",
"{",
"throw",
"new",
"\\",
"OutOfBoundsException",
"(",
"\"Invalid slot [$slot].\"",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"slots",
"[",
"$",
"slot",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"slots",
"[",
"$",
"slot",
"]",
";",
"}",
"$",
"connectionID",
"=",
"$",
"this",
"->",
"guessNode",
"(",
"$",
"slot",
")",
";",
"if",
"(",
"!",
"$",
"connection",
"=",
"$",
"this",
"->",
"getConnectionById",
"(",
"$",
"connectionID",
")",
")",
"{",
"$",
"connection",
"=",
"$",
"this",
"->",
"createConnection",
"(",
"$",
"connectionID",
")",
";",
"}",
"return",
"$",
"this",
"->",
"slots",
"[",
"$",
"slot",
"]",
"=",
"$",
"connection",
";",
"}"
] | Returns the connection currently associated to a given slot.
@param int $slot Slot index.
@return Client|mixed|null
@throws RedisException | [
"Returns",
"the",
"connection",
"currently",
"associated",
"to",
"a",
"given",
"slot",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Redis/Cluster/Native.php#L325-L341 |
35,220 | hail-framework/framework | src/Redis/Cluster/Native.php | Native.getRandomConnection | protected function getRandomConnection(): ?Client
{
if ($this->pool) {
return $this->pool[\array_rand($this->pool)];
}
if ($this->hosts) {
$key = \array_rand($this->hosts);
$connectionID = $this->hosts[$key];
unset($key);
return $this->createConnection($connectionID);
}
return null;
} | php | protected function getRandomConnection(): ?Client
{
if ($this->pool) {
return $this->pool[\array_rand($this->pool)];
}
if ($this->hosts) {
$key = \array_rand($this->hosts);
$connectionID = $this->hosts[$key];
unset($key);
return $this->createConnection($connectionID);
}
return null;
} | [
"protected",
"function",
"getRandomConnection",
"(",
")",
":",
"?",
"Client",
"{",
"if",
"(",
"$",
"this",
"->",
"pool",
")",
"{",
"return",
"$",
"this",
"->",
"pool",
"[",
"\\",
"array_rand",
"(",
"$",
"this",
"->",
"pool",
")",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"hosts",
")",
"{",
"$",
"key",
"=",
"\\",
"array_rand",
"(",
"$",
"this",
"->",
"hosts",
")",
";",
"$",
"connectionID",
"=",
"$",
"this",
"->",
"hosts",
"[",
"$",
"key",
"]",
";",
"unset",
"(",
"$",
"key",
")",
";",
"return",
"$",
"this",
"->",
"createConnection",
"(",
"$",
"connectionID",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Returns a random connection from the pool.
@return Client|null | [
"Returns",
"a",
"random",
"connection",
"from",
"the",
"pool",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Redis/Cluster/Native.php#L357-L372 |
35,221 | hail-framework/framework | src/Redis/Cluster/Native.php | Native.onMovedResponse | protected function onMovedResponse(string $command, array $args, string $details)
{
[$slot, $connectionID] = \explode(' ', $details, 2);
if (!$connection = $this->getConnectionById($connectionID)) {
$connection = $this->createConnection($connectionID);
}
$this->askSlotsMap($connection);
$this->move($connection, $slot);
return $this->execute($command, $args);
} | php | protected function onMovedResponse(string $command, array $args, string $details)
{
[$slot, $connectionID] = \explode(' ', $details, 2);
if (!$connection = $this->getConnectionById($connectionID)) {
$connection = $this->createConnection($connectionID);
}
$this->askSlotsMap($connection);
$this->move($connection, $slot);
return $this->execute($command, $args);
} | [
"protected",
"function",
"onMovedResponse",
"(",
"string",
"$",
"command",
",",
"array",
"$",
"args",
",",
"string",
"$",
"details",
")",
"{",
"[",
"$",
"slot",
",",
"$",
"connectionID",
"]",
"=",
"\\",
"explode",
"(",
"' '",
",",
"$",
"details",
",",
"2",
")",
";",
"if",
"(",
"!",
"$",
"connection",
"=",
"$",
"this",
"->",
"getConnectionById",
"(",
"$",
"connectionID",
")",
")",
"{",
"$",
"connection",
"=",
"$",
"this",
"->",
"createConnection",
"(",
"$",
"connectionID",
")",
";",
"}",
"$",
"this",
"->",
"askSlotsMap",
"(",
"$",
"connection",
")",
";",
"$",
"this",
"->",
"move",
"(",
"$",
"connection",
",",
"$",
"slot",
")",
";",
"return",
"$",
"this",
"->",
"execute",
"(",
"$",
"command",
",",
"$",
"args",
")",
";",
"}"
] | Handles -MOVED responses by executing again the command against the node
indicated by the Redis response.
@param string $command Command that generated the -MOVED response.
@param array $args
@param string $details Parameters of the -MOVED response.
@return mixed
@throws RedisException | [
"Handles",
"-",
"MOVED",
"responses",
"by",
"executing",
"again",
"the",
"command",
"against",
"the",
"node",
"indicated",
"by",
"the",
"Redis",
"response",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Redis/Cluster/Native.php#L421-L432 |
35,222 | hail-framework/framework | src/Redis/Cluster/Native.php | Native.getSlot | public function getSlot($command, $args): ?int
{
$id = \strtoupper($command);
$slot = null;
if (isset($this->commands[$id])) {
$key = $this->commands[$id]($id, $args);
if (null !== $key) {
$slot = $this->getSlotByKey($key);
}
}
return $slot;
} | php | public function getSlot($command, $args): ?int
{
$id = \strtoupper($command);
$slot = null;
if (isset($this->commands[$id])) {
$key = $this->commands[$id]($id, $args);
if (null !== $key) {
$slot = $this->getSlotByKey($key);
}
}
return $slot;
} | [
"public",
"function",
"getSlot",
"(",
"$",
"command",
",",
"$",
"args",
")",
":",
"?",
"int",
"{",
"$",
"id",
"=",
"\\",
"strtoupper",
"(",
"$",
"command",
")",
";",
"$",
"slot",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"commands",
"[",
"$",
"id",
"]",
")",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"commands",
"[",
"$",
"id",
"]",
"(",
"$",
"id",
",",
"$",
"args",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"key",
")",
"{",
"$",
"slot",
"=",
"$",
"this",
"->",
"getSlotByKey",
"(",
"$",
"key",
")",
";",
"}",
"}",
"return",
"$",
"slot",
";",
"}"
] | Returns a slot for the given command used for clustering distribution or
NULL when this is not possible.
@param string $command Command name.
@param array $args
@return int|null | [
"Returns",
"a",
"slot",
"for",
"the",
"given",
"command",
"used",
"for",
"clustering",
"distribution",
"or",
"NULL",
"when",
"this",
"is",
"not",
"possible",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Redis/Cluster/Native.php#L899-L914 |
35,223 | Kajna/K-Core | Core/Routing/Route.php | Route.matches | public function matches($uri, $method)
{
// Check if request method matches.
if (in_array($method, $this->methods)) {
$paramValues = [];
// Replace parameters with proper regex patterns.
$urlRegex = preg_replace_callback(self::MATCHES_REGEX, [$this, 'regexUrl'], $this->url);
// Check if URI matches and if it matches put results in values array.
$pattern = '@^' . $urlRegex . '/?$@' . ($this->matchUnicode?'u':'');
if (preg_match($pattern, $uri, $paramValues) === 1) {// There is a match.
// Extract parameter names.
$paramNames = [];
preg_match_all(self::MATCHES_REGEX, $this->url, $paramNames, PREG_PATTERN_ORDER);
// Put parameters to array to be passed to controller/function later.
foreach ($paramNames[0] as $index => $value) {
$this->params[substr($value, 1)] = urldecode($paramValues[$index + 1]);
}
// Append passed params to executable
$this->executable->addParams($this->params);
// Everything is done return true.
return true;
}
}
// No match found return false.
return false;
} | php | public function matches($uri, $method)
{
// Check if request method matches.
if (in_array($method, $this->methods)) {
$paramValues = [];
// Replace parameters with proper regex patterns.
$urlRegex = preg_replace_callback(self::MATCHES_REGEX, [$this, 'regexUrl'], $this->url);
// Check if URI matches and if it matches put results in values array.
$pattern = '@^' . $urlRegex . '/?$@' . ($this->matchUnicode?'u':'');
if (preg_match($pattern, $uri, $paramValues) === 1) {// There is a match.
// Extract parameter names.
$paramNames = [];
preg_match_all(self::MATCHES_REGEX, $this->url, $paramNames, PREG_PATTERN_ORDER);
// Put parameters to array to be passed to controller/function later.
foreach ($paramNames[0] as $index => $value) {
$this->params[substr($value, 1)] = urldecode($paramValues[$index + 1]);
}
// Append passed params to executable
$this->executable->addParams($this->params);
// Everything is done return true.
return true;
}
}
// No match found return false.
return false;
} | [
"public",
"function",
"matches",
"(",
"$",
"uri",
",",
"$",
"method",
")",
"{",
"// Check if request method matches.",
"if",
"(",
"in_array",
"(",
"$",
"method",
",",
"$",
"this",
"->",
"methods",
")",
")",
"{",
"$",
"paramValues",
"=",
"[",
"]",
";",
"// Replace parameters with proper regex patterns.",
"$",
"urlRegex",
"=",
"preg_replace_callback",
"(",
"self",
"::",
"MATCHES_REGEX",
",",
"[",
"$",
"this",
",",
"'regexUrl'",
"]",
",",
"$",
"this",
"->",
"url",
")",
";",
"// Check if URI matches and if it matches put results in values array.",
"$",
"pattern",
"=",
"'@^'",
".",
"$",
"urlRegex",
".",
"'/?$@'",
".",
"(",
"$",
"this",
"->",
"matchUnicode",
"?",
"'u'",
":",
"''",
")",
";",
"if",
"(",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"uri",
",",
"$",
"paramValues",
")",
"===",
"1",
")",
"{",
"// There is a match.",
"// Extract parameter names.",
"$",
"paramNames",
"=",
"[",
"]",
";",
"preg_match_all",
"(",
"self",
"::",
"MATCHES_REGEX",
",",
"$",
"this",
"->",
"url",
",",
"$",
"paramNames",
",",
"PREG_PATTERN_ORDER",
")",
";",
"// Put parameters to array to be passed to controller/function later.",
"foreach",
"(",
"$",
"paramNames",
"[",
"0",
"]",
"as",
"$",
"index",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"params",
"[",
"substr",
"(",
"$",
"value",
",",
"1",
")",
"]",
"=",
"urldecode",
"(",
"$",
"paramValues",
"[",
"$",
"index",
"+",
"1",
"]",
")",
";",
"}",
"// Append passed params to executable",
"$",
"this",
"->",
"executable",
"->",
"addParams",
"(",
"$",
"this",
"->",
"params",
")",
";",
"// Everything is done return true.",
"return",
"true",
";",
"}",
"}",
"// No match found return false.",
"return",
"false",
";",
"}"
] | Check if requested URI and method matches this route.
@param string $uri
@param string $method
@return bool | [
"Check",
"if",
"requested",
"URI",
"and",
"method",
"matches",
"this",
"route",
"."
] | 6a354056cf95e471b9b1eb372c5626123fd77df2 | https://github.com/Kajna/K-Core/blob/6a354056cf95e471b9b1eb372c5626123fd77df2/Core/Routing/Route.php#L128-L158 |
35,224 | Kajna/K-Core | Core/Routing/Route.php | Route.regexUrl | protected function regexUrl($matches)
{
$key = substr($matches[0], 1);
if (isset($this->conditions[$key])) {
return '(' . $this->conditions[$key] . ')';
} else {
return '(' . self::$conditionRegex['default'] . ')';
}
} | php | protected function regexUrl($matches)
{
$key = substr($matches[0], 1);
if (isset($this->conditions[$key])) {
return '(' . $this->conditions[$key] . ')';
} else {
return '(' . self::$conditionRegex['default'] . ')';
}
} | [
"protected",
"function",
"regexUrl",
"(",
"$",
"matches",
")",
"{",
"$",
"key",
"=",
"substr",
"(",
"$",
"matches",
"[",
"0",
"]",
",",
"1",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"conditions",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"'('",
".",
"$",
"this",
"->",
"conditions",
"[",
"$",
"key",
"]",
".",
"')'",
";",
"}",
"else",
"{",
"return",
"'('",
".",
"self",
"::",
"$",
"conditionRegex",
"[",
"'default'",
"]",
".",
"')'",
";",
"}",
"}"
] | Helper regex for matches function.
@param string $matches
@return string | [
"Helper",
"regex",
"for",
"matches",
"function",
"."
] | 6a354056cf95e471b9b1eb372c5626123fd77df2 | https://github.com/Kajna/K-Core/blob/6a354056cf95e471b9b1eb372c5626123fd77df2/Core/Routing/Route.php#L166-L174 |
35,225 | Kajna/K-Core | Core/Routing/Route.php | Route.where | public function where($key, $condition)
{
$this->conditions[$key] = self::$conditionRegex[$condition];
return $this;
} | php | public function where($key, $condition)
{
$this->conditions[$key] = self::$conditionRegex[$condition];
return $this;
} | [
"public",
"function",
"where",
"(",
"$",
"key",
",",
"$",
"condition",
")",
"{",
"$",
"this",
"->",
"conditions",
"[",
"$",
"key",
"]",
"=",
"self",
"::",
"$",
"conditionRegex",
"[",
"$",
"condition",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Set route parameter condition.
@param string $key
@param string $condition
@return self | [
"Set",
"route",
"parameter",
"condition",
"."
] | 6a354056cf95e471b9b1eb372c5626123fd77df2 | https://github.com/Kajna/K-Core/blob/6a354056cf95e471b9b1eb372c5626123fd77df2/Core/Routing/Route.php#L193-L197 |
35,226 | hail-framework/framework | src/Console/Corrector.php | Corrector.correct | public static function correct(string $input, array $possibleTokens = []): string
{
$guess = static::match($input, $possibleTokens);
if ($guess === $input) {
return $guess;
}
return static::askForGuess($guess) ? $guess : $input;
} | php | public static function correct(string $input, array $possibleTokens = []): string
{
$guess = static::match($input, $possibleTokens);
if ($guess === $input) {
return $guess;
}
return static::askForGuess($guess) ? $guess : $input;
} | [
"public",
"static",
"function",
"correct",
"(",
"string",
"$",
"input",
",",
"array",
"$",
"possibleTokens",
"=",
"[",
"]",
")",
":",
"string",
"{",
"$",
"guess",
"=",
"static",
"::",
"match",
"(",
"$",
"input",
",",
"$",
"possibleTokens",
")",
";",
"if",
"(",
"$",
"guess",
"===",
"$",
"input",
")",
"{",
"return",
"$",
"guess",
";",
"}",
"return",
"static",
"::",
"askForGuess",
"(",
"$",
"guess",
")",
"?",
"$",
"guess",
":",
"$",
"input",
";",
"}"
] | Given user's input, ask user to correct it.
@param string $input user's input
@param string[] $possibleTokens candidates of the suggestion
@return string corrected input | [
"Given",
"user",
"s",
"input",
"ask",
"user",
"to",
"correct",
"it",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/Corrector.php#L18-L26 |
35,227 | hail-framework/framework | src/Console/Corrector.php | Corrector.match | public static function match(string $input, array $possibleTokens = []): string
{
if (empty($possibleTokens)) {
return $input;
}
$bestSimilarity = -1;
$bestGuess = $input;
foreach ($possibleTokens as $possibleToken) {
similar_text($input, $possibleToken, $similarity);
if ($similarity > $bestSimilarity) {
$bestSimilarity = $similarity;
$bestGuess = $possibleToken;
}
}
return $bestGuess;
} | php | public static function match(string $input, array $possibleTokens = []): string
{
if (empty($possibleTokens)) {
return $input;
}
$bestSimilarity = -1;
$bestGuess = $input;
foreach ($possibleTokens as $possibleToken) {
similar_text($input, $possibleToken, $similarity);
if ($similarity > $bestSimilarity) {
$bestSimilarity = $similarity;
$bestGuess = $possibleToken;
}
}
return $bestGuess;
} | [
"public",
"static",
"function",
"match",
"(",
"string",
"$",
"input",
",",
"array",
"$",
"possibleTokens",
"=",
"[",
"]",
")",
":",
"string",
"{",
"if",
"(",
"empty",
"(",
"$",
"possibleTokens",
")",
")",
"{",
"return",
"$",
"input",
";",
"}",
"$",
"bestSimilarity",
"=",
"-",
"1",
";",
"$",
"bestGuess",
"=",
"$",
"input",
";",
"foreach",
"(",
"$",
"possibleTokens",
"as",
"$",
"possibleToken",
")",
"{",
"similar_text",
"(",
"$",
"input",
",",
"$",
"possibleToken",
",",
"$",
"similarity",
")",
";",
"if",
"(",
"$",
"similarity",
">",
"$",
"bestSimilarity",
")",
"{",
"$",
"bestSimilarity",
"=",
"$",
"similarity",
";",
"$",
"bestGuess",
"=",
"$",
"possibleToken",
";",
"}",
"}",
"return",
"$",
"bestGuess",
";",
"}"
] | Given user's input, return the best match among candidates.
@param string $input @see self::correct()
@param string[] $possibleTokens @see self::correct()
@return string best matched string or raw input if no candidates provided | [
"Given",
"user",
"s",
"input",
"return",
"the",
"best",
"match",
"among",
"candidates",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/Corrector.php#L36-L53 |
35,228 | hail-framework/framework | src/Util/Strings.php | Strings.fixEncoding | public static function fixEncoding(string $s): string
{
// removes xD800-xDFFF, x110000 and higher
return \htmlspecialchars_decode(\htmlspecialchars($s, ENT_NOQUOTES | ENT_IGNORE, 'UTF-8'), ENT_NOQUOTES);
} | php | public static function fixEncoding(string $s): string
{
// removes xD800-xDFFF, x110000 and higher
return \htmlspecialchars_decode(\htmlspecialchars($s, ENT_NOQUOTES | ENT_IGNORE, 'UTF-8'), ENT_NOQUOTES);
} | [
"public",
"static",
"function",
"fixEncoding",
"(",
"string",
"$",
"s",
")",
":",
"string",
"{",
"// removes xD800-xDFFF, x110000 and higher",
"return",
"\\",
"htmlspecialchars_decode",
"(",
"\\",
"htmlspecialchars",
"(",
"$",
"s",
",",
"ENT_NOQUOTES",
"|",
"ENT_IGNORE",
",",
"'UTF-8'",
")",
",",
"ENT_NOQUOTES",
")",
";",
"}"
] | Removes invalid code unit sequences from UTF-8 string.
@param string $s byte stream to fix
@return string | [
"Removes",
"invalid",
"code",
"unit",
"sequences",
"from",
"UTF",
"-",
"8",
"string",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Strings.php#L38-L42 |
35,229 | hail-framework/framework | src/Util/Strings.php | Strings.ord | public static function ord(string $char): int
{
if (\function_exists('\mb_ord')) {
return \mb_ord($char);
}
$code = ($c = \unpack('C*', \substr($char, 0, 4))) ? $c[1] : 0;
if (0xF0 <= $code) {
return (($code - 0xF0) << 18) + (($c[2] - 0x80) << 12) + (($c[3] - 0x80) << 6) + $c[4] - 0x80;
}
if (0xE0 <= $code) {
return (($code - 0xE0) << 12) + (($c[2] - 0x80) << 6) + $c[3] - 0x80;
}
if (0xC0 <= $code) {
return (($code - 0xC0) << 6) + $c[2] - 0x80;
}
return $code;
} | php | public static function ord(string $char): int
{
if (\function_exists('\mb_ord')) {
return \mb_ord($char);
}
$code = ($c = \unpack('C*', \substr($char, 0, 4))) ? $c[1] : 0;
if (0xF0 <= $code) {
return (($code - 0xF0) << 18) + (($c[2] - 0x80) << 12) + (($c[3] - 0x80) << 6) + $c[4] - 0x80;
}
if (0xE0 <= $code) {
return (($code - 0xE0) << 12) + (($c[2] - 0x80) << 6) + $c[3] - 0x80;
}
if (0xC0 <= $code) {
return (($code - 0xC0) << 6) + $c[2] - 0x80;
}
return $code;
} | [
"public",
"static",
"function",
"ord",
"(",
"string",
"$",
"char",
")",
":",
"int",
"{",
"if",
"(",
"\\",
"function_exists",
"(",
"'\\mb_ord'",
")",
")",
"{",
"return",
"\\",
"mb_ord",
"(",
"$",
"char",
")",
";",
"}",
"$",
"code",
"=",
"(",
"$",
"c",
"=",
"\\",
"unpack",
"(",
"'C*'",
",",
"\\",
"substr",
"(",
"$",
"char",
",",
"0",
",",
"4",
")",
")",
")",
"?",
"$",
"c",
"[",
"1",
"]",
":",
"0",
";",
"if",
"(",
"0xF0",
"<=",
"$",
"code",
")",
"{",
"return",
"(",
"(",
"$",
"code",
"-",
"0xF0",
")",
"<<",
"18",
")",
"+",
"(",
"(",
"$",
"c",
"[",
"2",
"]",
"-",
"0x80",
")",
"<<",
"12",
")",
"+",
"(",
"(",
"$",
"c",
"[",
"3",
"]",
"-",
"0x80",
")",
"<<",
"6",
")",
"+",
"$",
"c",
"[",
"4",
"]",
"-",
"0x80",
";",
"}",
"if",
"(",
"0xE0",
"<=",
"$",
"code",
")",
"{",
"return",
"(",
"(",
"$",
"code",
"-",
"0xE0",
")",
"<<",
"12",
")",
"+",
"(",
"(",
"$",
"c",
"[",
"2",
"]",
"-",
"0x80",
")",
"<<",
"6",
")",
"+",
"$",
"c",
"[",
"3",
"]",
"-",
"0x80",
";",
"}",
"if",
"(",
"0xC0",
"<=",
"$",
"code",
")",
"{",
"return",
"(",
"(",
"$",
"code",
"-",
"0xC0",
")",
"<<",
"6",
")",
"+",
"$",
"c",
"[",
"2",
"]",
"-",
"0x80",
";",
"}",
"return",
"$",
"code",
";",
"}"
] | Get a decimal code representation of a specific character.
@param string $char Character.
@return int | [
"Get",
"a",
"decimal",
"code",
"representation",
"of",
"a",
"specific",
"character",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Strings.php#L51-L69 |
35,230 | hail-framework/framework | src/Util/Strings.php | Strings.chr | public static function chr(int $code): string
{
if ($code < 0 || ($code >= 0xD800 && $code <= 0xDFFF) || $code > 0x10FFFF) {
throw new \InvalidArgumentException('Code point must be in range 0x0 to 0xD7FF or 0xE000 to 0x10FFFF.');
}
if (\function_exists('\mb_chr')) {
return \mb_chr($code);
}
if (\function_exists('\iconv')) {
return \iconv('UTF-32BE', 'UTF-8//IGNORE', \pack('N', $code));
}
if (0x80 > $code %= 0x200000) {
return \chr($code);
}
if (0x800 > $code) {
return \chr(0xC0 | $code >> 6) . \chr(0x80 | $code & 0x3F);
}
if (0x10000 > $code) {
return \chr(0xE0 | $code >> 12) . \chr(0x80 | $code >> 6 & 0x3F) . \chr(0x80 | $code & 0x3F);
}
return \chr(0xF0 | $code >> 18) . \chr(0x80 | $code >> 12 & 0x3F) . \chr(0x80 | $code >> 6 & 0x3F) . \chr(0x80 | $code & 0x3F);
} | php | public static function chr(int $code): string
{
if ($code < 0 || ($code >= 0xD800 && $code <= 0xDFFF) || $code > 0x10FFFF) {
throw new \InvalidArgumentException('Code point must be in range 0x0 to 0xD7FF or 0xE000 to 0x10FFFF.');
}
if (\function_exists('\mb_chr')) {
return \mb_chr($code);
}
if (\function_exists('\iconv')) {
return \iconv('UTF-32BE', 'UTF-8//IGNORE', \pack('N', $code));
}
if (0x80 > $code %= 0x200000) {
return \chr($code);
}
if (0x800 > $code) {
return \chr(0xC0 | $code >> 6) . \chr(0x80 | $code & 0x3F);
}
if (0x10000 > $code) {
return \chr(0xE0 | $code >> 12) . \chr(0x80 | $code >> 6 & 0x3F) . \chr(0x80 | $code & 0x3F);
}
return \chr(0xF0 | $code >> 18) . \chr(0x80 | $code >> 12 & 0x3F) . \chr(0x80 | $code >> 6 & 0x3F) . \chr(0x80 | $code & 0x3F);
} | [
"public",
"static",
"function",
"chr",
"(",
"int",
"$",
"code",
")",
":",
"string",
"{",
"if",
"(",
"$",
"code",
"<",
"0",
"||",
"(",
"$",
"code",
">=",
"0xD800",
"&&",
"$",
"code",
"<=",
"0xDFFF",
")",
"||",
"$",
"code",
">",
"0x10FFFF",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Code point must be in range 0x0 to 0xD7FF or 0xE000 to 0x10FFFF.'",
")",
";",
"}",
"if",
"(",
"\\",
"function_exists",
"(",
"'\\mb_chr'",
")",
")",
"{",
"return",
"\\",
"mb_chr",
"(",
"$",
"code",
")",
";",
"}",
"if",
"(",
"\\",
"function_exists",
"(",
"'\\iconv'",
")",
")",
"{",
"return",
"\\",
"iconv",
"(",
"'UTF-32BE'",
",",
"'UTF-8//IGNORE'",
",",
"\\",
"pack",
"(",
"'N'",
",",
"$",
"code",
")",
")",
";",
"}",
"if",
"(",
"0x80",
">",
"$",
"code",
"%=",
"0x200000",
")",
"{",
"return",
"\\",
"chr",
"(",
"$",
"code",
")",
";",
"}",
"if",
"(",
"0x800",
">",
"$",
"code",
")",
"{",
"return",
"\\",
"chr",
"(",
"0xC0",
"|",
"$",
"code",
">>",
"6",
")",
".",
"\\",
"chr",
"(",
"0x80",
"|",
"$",
"code",
"&",
"0x3F",
")",
";",
"}",
"if",
"(",
"0x10000",
">",
"$",
"code",
")",
"{",
"return",
"\\",
"chr",
"(",
"0xE0",
"|",
"$",
"code",
">>",
"12",
")",
".",
"\\",
"chr",
"(",
"0x80",
"|",
"$",
"code",
">>",
"6",
"&",
"0x3F",
")",
".",
"\\",
"chr",
"(",
"0x80",
"|",
"$",
"code",
"&",
"0x3F",
")",
";",
"}",
"return",
"\\",
"chr",
"(",
"0xF0",
"|",
"$",
"code",
">>",
"18",
")",
".",
"\\",
"chr",
"(",
"0x80",
"|",
"$",
"code",
">>",
"12",
"&",
"0x3F",
")",
".",
"\\",
"chr",
"(",
"0x80",
"|",
"$",
"code",
">>",
"6",
"&",
"0x3F",
")",
".",
"\\",
"chr",
"(",
"0x80",
"|",
"$",
"code",
"&",
"0x3F",
")",
";",
"}"
] | Returns a specific character in UTF-8.
@param int $code code point (0x0 to 0xD7FF or 0xE000 to 0x10FFFF)
@return string
@throws \InvalidArgumentException if code point is not in valid range | [
"Returns",
"a",
"specific",
"character",
"in",
"UTF",
"-",
"8",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Strings.php#L79-L104 |
35,231 | hail-framework/framework | src/Util/Strings.php | Strings.normalizeNewLines | public static function normalizeNewLines(string $s): string
{
if (\strpos($s, "\r") === false) {
return $s;
}
return \str_replace(["\r\n", "\r"], "\n", $s);
} | php | public static function normalizeNewLines(string $s): string
{
if (\strpos($s, "\r") === false) {
return $s;
}
return \str_replace(["\r\n", "\r"], "\n", $s);
} | [
"public",
"static",
"function",
"normalizeNewLines",
"(",
"string",
"$",
"s",
")",
":",
"string",
"{",
"if",
"(",
"\\",
"strpos",
"(",
"$",
"s",
",",
"\"\\r\"",
")",
"===",
"false",
")",
"{",
"return",
"$",
"s",
";",
"}",
"return",
"\\",
"str_replace",
"(",
"[",
"\"\\r\\n\"",
",",
"\"\\r\"",
"]",
",",
"\"\\n\"",
",",
"$",
"s",
")",
";",
"}"
] | Standardize line endings to unix-like.
@param string $s UTF-8 encoding or 8-bit
@return string | [
"Standardize",
"line",
"endings",
"to",
"unix",
"-",
"like",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Strings.php#L190-L197 |
35,232 | hail-framework/framework | src/Util/Strings.php | Strings.truncate | public static function truncate(string $s, int $maxLen, string $append = "\xE2\x80\xA6"): string
{
if (\mb_strlen($s) > $maxLen) {
$maxLen -= \mb_strlen($append);
if ($maxLen < 1) {
return $append;
}
if ($matches = static::match($s, '#^.{1,' . $maxLen . '}(?=[\s\x00-/:-@\[-`{-~])#us')) {
return $matches[0] . $append;
}
return \mb_substr($s, 0, $maxLen) . $append;
}
return $s;
} | php | public static function truncate(string $s, int $maxLen, string $append = "\xE2\x80\xA6"): string
{
if (\mb_strlen($s) > $maxLen) {
$maxLen -= \mb_strlen($append);
if ($maxLen < 1) {
return $append;
}
if ($matches = static::match($s, '#^.{1,' . $maxLen . '}(?=[\s\x00-/:-@\[-`{-~])#us')) {
return $matches[0] . $append;
}
return \mb_substr($s, 0, $maxLen) . $append;
}
return $s;
} | [
"public",
"static",
"function",
"truncate",
"(",
"string",
"$",
"s",
",",
"int",
"$",
"maxLen",
",",
"string",
"$",
"append",
"=",
"\"\\xE2\\x80\\xA6\"",
")",
":",
"string",
"{",
"if",
"(",
"\\",
"mb_strlen",
"(",
"$",
"s",
")",
">",
"$",
"maxLen",
")",
"{",
"$",
"maxLen",
"-=",
"\\",
"mb_strlen",
"(",
"$",
"append",
")",
";",
"if",
"(",
"$",
"maxLen",
"<",
"1",
")",
"{",
"return",
"$",
"append",
";",
"}",
"if",
"(",
"$",
"matches",
"=",
"static",
"::",
"match",
"(",
"$",
"s",
",",
"'#^.{1,'",
".",
"$",
"maxLen",
".",
"'}(?=[\\s\\x00-/:-@\\[-`{-~])#us'",
")",
")",
"{",
"return",
"$",
"matches",
"[",
"0",
"]",
".",
"$",
"append",
";",
"}",
"return",
"\\",
"mb_substr",
"(",
"$",
"s",
",",
"0",
",",
"$",
"maxLen",
")",
".",
"$",
"append",
";",
"}",
"return",
"$",
"s",
";",
"}"
] | Truncates string to maximal length.
@param string $s UTF-8 encoding
@param int $maxLen
@param string $append UTF-8 encoding
@return string | [
"Truncates",
"string",
"to",
"maximal",
"length",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Strings.php#L277-L293 |
35,233 | hail-framework/framework | src/Util/Strings.php | Strings.indent | public static function indent(string $s, int $level = 1, string $chars = "\t"): string
{
if ($level > 0) {
$s = static::replace($s, '#(?:^|[\r\n]+)(?=[^\r\n])#', '$0' . \str_repeat($chars, $level));
}
return $s;
} | php | public static function indent(string $s, int $level = 1, string $chars = "\t"): string
{
if ($level > 0) {
$s = static::replace($s, '#(?:^|[\r\n]+)(?=[^\r\n])#', '$0' . \str_repeat($chars, $level));
}
return $s;
} | [
"public",
"static",
"function",
"indent",
"(",
"string",
"$",
"s",
",",
"int",
"$",
"level",
"=",
"1",
",",
"string",
"$",
"chars",
"=",
"\"\\t\"",
")",
":",
"string",
"{",
"if",
"(",
"$",
"level",
">",
"0",
")",
"{",
"$",
"s",
"=",
"static",
"::",
"replace",
"(",
"$",
"s",
",",
"'#(?:^|[\\r\\n]+)(?=[^\\r\\n])#'",
",",
"'$0'",
".",
"\\",
"str_repeat",
"(",
"$",
"chars",
",",
"$",
"level",
")",
")",
";",
"}",
"return",
"$",
"s",
";",
"}"
] | Indents the content from the left.
@param string $s UTF-8 encoding or 8-bit
@param int $level
@param string $chars
@return string | [
"Indents",
"the",
"content",
"from",
"the",
"left",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Strings.php#L305-L312 |
35,234 | hail-framework/framework | src/Util/Strings.php | Strings.compare | public static function compare(string $left, string $right, int $len = null): bool
{
if (\class_exists('\Normalizer', false)) {
$left = \Normalizer::normalize($left, \Normalizer::FORM_D); // form NFD is faster
$right = \Normalizer::normalize($right, \Normalizer::FORM_D); // form NFD is faster
}
if ($len < 0) {
$left = \mb_substr($left, $len, -$len);
$right = \mb_substr($right, $len, -$len);
} elseif ($len !== null) {
$left = \mb_substr($left, 0, $len);
$right = \mb_substr($right, 0, $len);
}
return \mb_strtolower($left) === \mb_strtolower($right);
} | php | public static function compare(string $left, string $right, int $len = null): bool
{
if (\class_exists('\Normalizer', false)) {
$left = \Normalizer::normalize($left, \Normalizer::FORM_D); // form NFD is faster
$right = \Normalizer::normalize($right, \Normalizer::FORM_D); // form NFD is faster
}
if ($len < 0) {
$left = \mb_substr($left, $len, -$len);
$right = \mb_substr($right, $len, -$len);
} elseif ($len !== null) {
$left = \mb_substr($left, 0, $len);
$right = \mb_substr($right, 0, $len);
}
return \mb_strtolower($left) === \mb_strtolower($right);
} | [
"public",
"static",
"function",
"compare",
"(",
"string",
"$",
"left",
",",
"string",
"$",
"right",
",",
"int",
"$",
"len",
"=",
"null",
")",
":",
"bool",
"{",
"if",
"(",
"\\",
"class_exists",
"(",
"'\\Normalizer'",
",",
"false",
")",
")",
"{",
"$",
"left",
"=",
"\\",
"Normalizer",
"::",
"normalize",
"(",
"$",
"left",
",",
"\\",
"Normalizer",
"::",
"FORM_D",
")",
";",
"// form NFD is faster",
"$",
"right",
"=",
"\\",
"Normalizer",
"::",
"normalize",
"(",
"$",
"right",
",",
"\\",
"Normalizer",
"::",
"FORM_D",
")",
";",
"// form NFD is faster",
"}",
"if",
"(",
"$",
"len",
"<",
"0",
")",
"{",
"$",
"left",
"=",
"\\",
"mb_substr",
"(",
"$",
"left",
",",
"$",
"len",
",",
"-",
"$",
"len",
")",
";",
"$",
"right",
"=",
"\\",
"mb_substr",
"(",
"$",
"right",
",",
"$",
"len",
",",
"-",
"$",
"len",
")",
";",
"}",
"elseif",
"(",
"$",
"len",
"!==",
"null",
")",
"{",
"$",
"left",
"=",
"\\",
"mb_substr",
"(",
"$",
"left",
",",
"0",
",",
"$",
"len",
")",
";",
"$",
"right",
"=",
"\\",
"mb_substr",
"(",
"$",
"right",
",",
"0",
",",
"$",
"len",
")",
";",
"}",
"return",
"\\",
"mb_strtolower",
"(",
"$",
"left",
")",
"===",
"\\",
"mb_strtolower",
"(",
"$",
"right",
")",
";",
"}"
] | Case-insensitive compares UTF-8 strings.
@param string
@param string
@param int
@return bool | [
"Case",
"-",
"insensitive",
"compares",
"UTF",
"-",
"8",
"strings",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Strings.php#L349-L365 |
35,235 | hail-framework/framework | src/Util/Strings.php | Strings.findPrefix | public static function findPrefix($first, ...$strings): string
{
if (\is_array($first)) {
$strings = $first;
$first = $strings[0];
unset($strings[0]);
}
for ($i = 0, $n = \strlen($first); $i < $n; $i++) {
foreach ($strings as $s) {
if (!isset($s[$i]) || $first[$i] !== $s[$i]) {
while ($i && $first[$i - 1] >= "\x80" && $first[$i] >= "\x80" && $first[$i] < "\xC0") {
$i--;
}
return \substr($first, 0, $i);
}
}
}
return $first;
} | php | public static function findPrefix($first, ...$strings): string
{
if (\is_array($first)) {
$strings = $first;
$first = $strings[0];
unset($strings[0]);
}
for ($i = 0, $n = \strlen($first); $i < $n; $i++) {
foreach ($strings as $s) {
if (!isset($s[$i]) || $first[$i] !== $s[$i]) {
while ($i && $first[$i - 1] >= "\x80" && $first[$i] >= "\x80" && $first[$i] < "\xC0") {
$i--;
}
return \substr($first, 0, $i);
}
}
}
return $first;
} | [
"public",
"static",
"function",
"findPrefix",
"(",
"$",
"first",
",",
"...",
"$",
"strings",
")",
":",
"string",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"first",
")",
")",
"{",
"$",
"strings",
"=",
"$",
"first",
";",
"$",
"first",
"=",
"$",
"strings",
"[",
"0",
"]",
";",
"unset",
"(",
"$",
"strings",
"[",
"0",
"]",
")",
";",
"}",
"for",
"(",
"$",
"i",
"=",
"0",
",",
"$",
"n",
"=",
"\\",
"strlen",
"(",
"$",
"first",
")",
";",
"$",
"i",
"<",
"$",
"n",
";",
"$",
"i",
"++",
")",
"{",
"foreach",
"(",
"$",
"strings",
"as",
"$",
"s",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"s",
"[",
"$",
"i",
"]",
")",
"||",
"$",
"first",
"[",
"$",
"i",
"]",
"!==",
"$",
"s",
"[",
"$",
"i",
"]",
")",
"{",
"while",
"(",
"$",
"i",
"&&",
"$",
"first",
"[",
"$",
"i",
"-",
"1",
"]",
">=",
"\"\\x80\"",
"&&",
"$",
"first",
"[",
"$",
"i",
"]",
">=",
"\"\\x80\"",
"&&",
"$",
"first",
"[",
"$",
"i",
"]",
"<",
"\"\\xC0\"",
")",
"{",
"$",
"i",
"--",
";",
"}",
"return",
"\\",
"substr",
"(",
"$",
"first",
",",
"0",
",",
"$",
"i",
")",
";",
"}",
"}",
"}",
"return",
"$",
"first",
";",
"}"
] | Finds the length of common prefix of strings.
@param string|array $first
@param array ...$strings
@return string | [
"Finds",
"the",
"length",
"of",
"common",
"prefix",
"of",
"strings",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Strings.php#L376-L397 |
35,236 | hail-framework/framework | src/Util/Strings.php | Strings.trim | public static function trim(string $s, string $charList = self::TRIM_CHARACTERS): string
{
$charList = \preg_quote($charList, '#');
return static::replace($s, '#^[' . $charList . ']+|[' . $charList . ']+\z#u', '');
} | php | public static function trim(string $s, string $charList = self::TRIM_CHARACTERS): string
{
$charList = \preg_quote($charList, '#');
return static::replace($s, '#^[' . $charList . ']+|[' . $charList . ']+\z#u', '');
} | [
"public",
"static",
"function",
"trim",
"(",
"string",
"$",
"s",
",",
"string",
"$",
"charList",
"=",
"self",
"::",
"TRIM_CHARACTERS",
")",
":",
"string",
"{",
"$",
"charList",
"=",
"\\",
"preg_quote",
"(",
"$",
"charList",
",",
"'#'",
")",
";",
"return",
"static",
"::",
"replace",
"(",
"$",
"s",
",",
"'#^['",
".",
"$",
"charList",
".",
"']+|['",
".",
"$",
"charList",
".",
"']+\\z#u'",
",",
"''",
")",
";",
"}"
] | Strips whitespace.
@param string $s UTF-8 encoding
@param string $charList
@return string
@throws RegexpException | [
"Strips",
"whitespace",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Strings.php#L408-L413 |
35,237 | hail-framework/framework | src/Util/Strings.php | Strings.ltrim | public static function ltrim(string $s, string $charList = self::TRIM_CHARACTERS): string
{
$charList = \preg_quote($charList, '#');
return static::replace($s, '#^[' . $charList . ']+#u', '');
} | php | public static function ltrim(string $s, string $charList = self::TRIM_CHARACTERS): string
{
$charList = \preg_quote($charList, '#');
return static::replace($s, '#^[' . $charList . ']+#u', '');
} | [
"public",
"static",
"function",
"ltrim",
"(",
"string",
"$",
"s",
",",
"string",
"$",
"charList",
"=",
"self",
"::",
"TRIM_CHARACTERS",
")",
":",
"string",
"{",
"$",
"charList",
"=",
"\\",
"preg_quote",
"(",
"$",
"charList",
",",
"'#'",
")",
";",
"return",
"static",
"::",
"replace",
"(",
"$",
"s",
",",
"'#^['",
".",
"$",
"charList",
".",
"']+#u'",
",",
"''",
")",
";",
"}"
] | Strips whitespace from the beginning of a string.
@param string $s UTF-8 encoding
@param string $charList
@return string
@throws RegexpException | [
"Strips",
"whitespace",
"from",
"the",
"beginning",
"of",
"a",
"string",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Strings.php#L424-L429 |
35,238 | hail-framework/framework | src/Util/Strings.php | Strings.rtrim | public static function rtrim(string $s, string $charList = self::TRIM_CHARACTERS): string
{
$charList = \preg_quote($charList, '#');
return static::replace($s, '#[' . $charList . ']+\z#u', '');
} | php | public static function rtrim(string $s, string $charList = self::TRIM_CHARACTERS): string
{
$charList = \preg_quote($charList, '#');
return static::replace($s, '#[' . $charList . ']+\z#u', '');
} | [
"public",
"static",
"function",
"rtrim",
"(",
"string",
"$",
"s",
",",
"string",
"$",
"charList",
"=",
"self",
"::",
"TRIM_CHARACTERS",
")",
":",
"string",
"{",
"$",
"charList",
"=",
"\\",
"preg_quote",
"(",
"$",
"charList",
",",
"'#'",
")",
";",
"return",
"static",
"::",
"replace",
"(",
"$",
"s",
",",
"'#['",
".",
"$",
"charList",
".",
"']+\\z#u'",
",",
"''",
")",
";",
"}"
] | Strips whitespace from the end of a string.
@param string $s UTF-8 encoding
@param string $charList
@return string
@throws RegexpException | [
"Strips",
"whitespace",
"from",
"the",
"end",
"of",
"a",
"string",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Strings.php#L440-L445 |
35,239 | hail-framework/framework | src/Util/Strings.php | Strings.padLeft | public static function padLeft(string $s, int $length, string $pad = ' '): string
{
$length -= \mb_strlen($s);
if ($length <= 0) {
return $s;
}
$padLen = \mb_strlen($pad);
return \str_repeat($pad, (int) ($length / $padLen)) . \mb_substr($pad, 0, $length % $padLen) . $s;
} | php | public static function padLeft(string $s, int $length, string $pad = ' '): string
{
$length -= \mb_strlen($s);
if ($length <= 0) {
return $s;
}
$padLen = \mb_strlen($pad);
return \str_repeat($pad, (int) ($length / $padLen)) . \mb_substr($pad, 0, $length % $padLen) . $s;
} | [
"public",
"static",
"function",
"padLeft",
"(",
"string",
"$",
"s",
",",
"int",
"$",
"length",
",",
"string",
"$",
"pad",
"=",
"' '",
")",
":",
"string",
"{",
"$",
"length",
"-=",
"\\",
"mb_strlen",
"(",
"$",
"s",
")",
";",
"if",
"(",
"$",
"length",
"<=",
"0",
")",
"{",
"return",
"$",
"s",
";",
"}",
"$",
"padLen",
"=",
"\\",
"mb_strlen",
"(",
"$",
"pad",
")",
";",
"return",
"\\",
"str_repeat",
"(",
"$",
"pad",
",",
"(",
"int",
")",
"(",
"$",
"length",
"/",
"$",
"padLen",
")",
")",
".",
"\\",
"mb_substr",
"(",
"$",
"pad",
",",
"0",
",",
"$",
"length",
"%",
"$",
"padLen",
")",
".",
"$",
"s",
";",
"}"
] | Pad a UTF-8 string to a certain length with another string.
@param string $s UTF-8 encoding
@param int $length
@param string $pad
@return string | [
"Pad",
"a",
"UTF",
"-",
"8",
"string",
"to",
"a",
"certain",
"length",
"with",
"another",
"string",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Strings.php#L457-L467 |
35,240 | hail-framework/framework | src/Util/Strings.php | Strings.split | public static function split(string $subject, string $pattern, int $flags = 0): array
{
return static::pcre('\preg_split', [$pattern, $subject, -1, $flags | PREG_SPLIT_DELIM_CAPTURE]);
} | php | public static function split(string $subject, string $pattern, int $flags = 0): array
{
return static::pcre('\preg_split', [$pattern, $subject, -1, $flags | PREG_SPLIT_DELIM_CAPTURE]);
} | [
"public",
"static",
"function",
"split",
"(",
"string",
"$",
"subject",
",",
"string",
"$",
"pattern",
",",
"int",
"$",
"flags",
"=",
"0",
")",
":",
"array",
"{",
"return",
"static",
"::",
"pcre",
"(",
"'\\preg_split'",
",",
"[",
"$",
"pattern",
",",
"$",
"subject",
",",
"-",
"1",
",",
"$",
"flags",
"|",
"PREG_SPLIT_DELIM_CAPTURE",
"]",
")",
";",
"}"
] | Splits string by a regular expression.
@param string $subject
@param string $pattern
@param int $flags
@return array
@throws RegexpException | [
"Splits",
"string",
"by",
"a",
"regular",
"expression",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Strings.php#L615-L618 |
35,241 | hail-framework/framework | src/Util/Strings.php | Strings.match | public static function match(string $subject, string $pattern, int $flags = 0, int $offset = 0)
{
if ($offset > \strlen($subject)) {
return null;
}
$m = null;
return static::pcre('\preg_match', [$pattern, $subject, &$m, $flags, $offset])
? $m
: null;
} | php | public static function match(string $subject, string $pattern, int $flags = 0, int $offset = 0)
{
if ($offset > \strlen($subject)) {
return null;
}
$m = null;
return static::pcre('\preg_match', [$pattern, $subject, &$m, $flags, $offset])
? $m
: null;
} | [
"public",
"static",
"function",
"match",
"(",
"string",
"$",
"subject",
",",
"string",
"$",
"pattern",
",",
"int",
"$",
"flags",
"=",
"0",
",",
"int",
"$",
"offset",
"=",
"0",
")",
"{",
"if",
"(",
"$",
"offset",
">",
"\\",
"strlen",
"(",
"$",
"subject",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"m",
"=",
"null",
";",
"return",
"static",
"::",
"pcre",
"(",
"'\\preg_match'",
",",
"[",
"$",
"pattern",
",",
"$",
"subject",
",",
"&",
"$",
"m",
",",
"$",
"flags",
",",
"$",
"offset",
"]",
")",
"?",
"$",
"m",
":",
"null",
";",
"}"
] | Performs a regular expression match.
@param string $subject
@param string $pattern
@param int $flags can be PREG_OFFSET_CAPTURE (returned in bytes)
@param int $offset offset in bytes
@return array|null
@throws RegexpException | [
"Performs",
"a",
"regular",
"expression",
"match",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Strings.php#L632-L643 |
35,242 | hail-framework/framework | src/Util/Strings.php | Strings.matchAll | public static function matchAll(string $subject, string $pattern, int $flags = 0, int $offset = 0): array
{
if ($offset > \strlen($subject)) {
return [];
}
$m = null;
static::pcre('\preg_match_all', [
$pattern,
$subject,
&$m,
($flags & PREG_PATTERN_ORDER) ? $flags : ($flags | PREG_SET_ORDER),
$offset,
]);
return $m;
} | php | public static function matchAll(string $subject, string $pattern, int $flags = 0, int $offset = 0): array
{
if ($offset > \strlen($subject)) {
return [];
}
$m = null;
static::pcre('\preg_match_all', [
$pattern,
$subject,
&$m,
($flags & PREG_PATTERN_ORDER) ? $flags : ($flags | PREG_SET_ORDER),
$offset,
]);
return $m;
} | [
"public",
"static",
"function",
"matchAll",
"(",
"string",
"$",
"subject",
",",
"string",
"$",
"pattern",
",",
"int",
"$",
"flags",
"=",
"0",
",",
"int",
"$",
"offset",
"=",
"0",
")",
":",
"array",
"{",
"if",
"(",
"$",
"offset",
">",
"\\",
"strlen",
"(",
"$",
"subject",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"m",
"=",
"null",
";",
"static",
"::",
"pcre",
"(",
"'\\preg_match_all'",
",",
"[",
"$",
"pattern",
",",
"$",
"subject",
",",
"&",
"$",
"m",
",",
"(",
"$",
"flags",
"&",
"PREG_PATTERN_ORDER",
")",
"?",
"$",
"flags",
":",
"(",
"$",
"flags",
"|",
"PREG_SET_ORDER",
")",
",",
"$",
"offset",
",",
"]",
")",
";",
"return",
"$",
"m",
";",
"}"
] | Performs a global regular expression match.
@param string $subject
@param string $pattern
@param int $flags can be PREG_OFFSET_CAPTURE (returned in bytes); PREG_SET_ORDER is default
@param int $offset offset in bytes
@return array
@throws RegexpException | [
"Performs",
"a",
"global",
"regular",
"expression",
"match",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Strings.php#L657-L673 |
35,243 | hail-framework/framework | src/Debugger/Profiler.php | Profiler.finish | public static function finish(...$args)
{
if (Debugger::isProductionMode()) {
return false;
}
if ([] === static::$stack) {
throw new \RuntimeException('The stack is empty. Call Hail\Debugger\Profiler::start() first.');
}
$now = \microtime(true);
$memoryUsage = \memory_get_usage(true);
if (!isset($args[1])) {
$label = $args[0] ?? static::getCurrentFileHashLine(1);
} else {
$label = \sprintf(...$args);
}
/** @var array $profile */
$profile = \array_pop(static::$stack);
$profile['meta'][self::FINISH_LABEL] = $label;
$profile['meta'][self::FINISH_TIME] = $now;
$profile['meta'][self::FINISH_MEMORY_USAGE] = $memoryUsage;
$profile[self::ABSOLUTE_DURATION] = $profile['meta'][self::FINISH_TIME] - $profile['meta'][self::START_TIME];
$profile[self::DURATION] = $profile[self::ABSOLUTE_DURATION] - $profile['meta'][self::TIME_OFFSET];
$profile[self::ABSOLUTE_MEMORY_USAGE_CHANGE] = $profile['meta'][self::FINISH_MEMORY_USAGE] - $profile['meta'][self::START_MEMORY_USAGE];
$profile[self::MEMORY_USAGE_CHANGE] = $profile[self::ABSOLUTE_MEMORY_USAGE_CHANGE] - $profile['meta'][self::MEMORY_USAGE_OFFSET];
if ([] !== static::$stack) {
$prefix = &static::$stack[\count(static::$stack) - 1]['meta'];
$prefix[self::TIME_OFFSET] += $profile[self::ABSOLUTE_DURATION];
$prefix[self::MEMORY_USAGE_OFFSET] += $profile[self::ABSOLUTE_MEMORY_USAGE_CHANGE];
}
self::$profiles[] = $profile;
return $profile;
} | php | public static function finish(...$args)
{
if (Debugger::isProductionMode()) {
return false;
}
if ([] === static::$stack) {
throw new \RuntimeException('The stack is empty. Call Hail\Debugger\Profiler::start() first.');
}
$now = \microtime(true);
$memoryUsage = \memory_get_usage(true);
if (!isset($args[1])) {
$label = $args[0] ?? static::getCurrentFileHashLine(1);
} else {
$label = \sprintf(...$args);
}
/** @var array $profile */
$profile = \array_pop(static::$stack);
$profile['meta'][self::FINISH_LABEL] = $label;
$profile['meta'][self::FINISH_TIME] = $now;
$profile['meta'][self::FINISH_MEMORY_USAGE] = $memoryUsage;
$profile[self::ABSOLUTE_DURATION] = $profile['meta'][self::FINISH_TIME] - $profile['meta'][self::START_TIME];
$profile[self::DURATION] = $profile[self::ABSOLUTE_DURATION] - $profile['meta'][self::TIME_OFFSET];
$profile[self::ABSOLUTE_MEMORY_USAGE_CHANGE] = $profile['meta'][self::FINISH_MEMORY_USAGE] - $profile['meta'][self::START_MEMORY_USAGE];
$profile[self::MEMORY_USAGE_CHANGE] = $profile[self::ABSOLUTE_MEMORY_USAGE_CHANGE] - $profile['meta'][self::MEMORY_USAGE_OFFSET];
if ([] !== static::$stack) {
$prefix = &static::$stack[\count(static::$stack) - 1]['meta'];
$prefix[self::TIME_OFFSET] += $profile[self::ABSOLUTE_DURATION];
$prefix[self::MEMORY_USAGE_OFFSET] += $profile[self::ABSOLUTE_MEMORY_USAGE_CHANGE];
}
self::$profiles[] = $profile;
return $profile;
} | [
"public",
"static",
"function",
"finish",
"(",
"...",
"$",
"args",
")",
"{",
"if",
"(",
"Debugger",
"::",
"isProductionMode",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"[",
"]",
"===",
"static",
"::",
"$",
"stack",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'The stack is empty. Call Hail\\Debugger\\Profiler::start() first.'",
")",
";",
"}",
"$",
"now",
"=",
"\\",
"microtime",
"(",
"true",
")",
";",
"$",
"memoryUsage",
"=",
"\\",
"memory_get_usage",
"(",
"true",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"args",
"[",
"1",
"]",
")",
")",
"{",
"$",
"label",
"=",
"$",
"args",
"[",
"0",
"]",
"??",
"static",
"::",
"getCurrentFileHashLine",
"(",
"1",
")",
";",
"}",
"else",
"{",
"$",
"label",
"=",
"\\",
"sprintf",
"(",
"...",
"$",
"args",
")",
";",
"}",
"/** @var array $profile */",
"$",
"profile",
"=",
"\\",
"array_pop",
"(",
"static",
"::",
"$",
"stack",
")",
";",
"$",
"profile",
"[",
"'meta'",
"]",
"[",
"self",
"::",
"FINISH_LABEL",
"]",
"=",
"$",
"label",
";",
"$",
"profile",
"[",
"'meta'",
"]",
"[",
"self",
"::",
"FINISH_TIME",
"]",
"=",
"$",
"now",
";",
"$",
"profile",
"[",
"'meta'",
"]",
"[",
"self",
"::",
"FINISH_MEMORY_USAGE",
"]",
"=",
"$",
"memoryUsage",
";",
"$",
"profile",
"[",
"self",
"::",
"ABSOLUTE_DURATION",
"]",
"=",
"$",
"profile",
"[",
"'meta'",
"]",
"[",
"self",
"::",
"FINISH_TIME",
"]",
"-",
"$",
"profile",
"[",
"'meta'",
"]",
"[",
"self",
"::",
"START_TIME",
"]",
";",
"$",
"profile",
"[",
"self",
"::",
"DURATION",
"]",
"=",
"$",
"profile",
"[",
"self",
"::",
"ABSOLUTE_DURATION",
"]",
"-",
"$",
"profile",
"[",
"'meta'",
"]",
"[",
"self",
"::",
"TIME_OFFSET",
"]",
";",
"$",
"profile",
"[",
"self",
"::",
"ABSOLUTE_MEMORY_USAGE_CHANGE",
"]",
"=",
"$",
"profile",
"[",
"'meta'",
"]",
"[",
"self",
"::",
"FINISH_MEMORY_USAGE",
"]",
"-",
"$",
"profile",
"[",
"'meta'",
"]",
"[",
"self",
"::",
"START_MEMORY_USAGE",
"]",
";",
"$",
"profile",
"[",
"self",
"::",
"MEMORY_USAGE_CHANGE",
"]",
"=",
"$",
"profile",
"[",
"self",
"::",
"ABSOLUTE_MEMORY_USAGE_CHANGE",
"]",
"-",
"$",
"profile",
"[",
"'meta'",
"]",
"[",
"self",
"::",
"MEMORY_USAGE_OFFSET",
"]",
";",
"if",
"(",
"[",
"]",
"!==",
"static",
"::",
"$",
"stack",
")",
"{",
"$",
"prefix",
"=",
"&",
"static",
"::",
"$",
"stack",
"[",
"\\",
"count",
"(",
"static",
"::",
"$",
"stack",
")",
"-",
"1",
"]",
"[",
"'meta'",
"]",
";",
"$",
"prefix",
"[",
"self",
"::",
"TIME_OFFSET",
"]",
"+=",
"$",
"profile",
"[",
"self",
"::",
"ABSOLUTE_DURATION",
"]",
";",
"$",
"prefix",
"[",
"self",
"::",
"MEMORY_USAGE_OFFSET",
"]",
"+=",
"$",
"profile",
"[",
"self",
"::",
"ABSOLUTE_MEMORY_USAGE_CHANGE",
"]",
";",
"}",
"self",
"::",
"$",
"profiles",
"[",
"]",
"=",
"$",
"profile",
";",
"return",
"$",
"profile",
";",
"}"
] | Finish profiling and get result
@param array ...$args
@return bool|array profile on success or false on failure
@throws \RuntimeException | [
"Finish",
"profiling",
"and",
"get",
"result"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Profiler.php#L96-L133 |
35,244 | hail-framework/framework | src/Config.php | Config.loadYaml | protected static function loadYaml($file, $ext)
{
$filename = \basename($file);
$dir = \runtime_path('yaml');
$cache = $dir . DIRECTORY_SEPARATOR . substr($filename, 0, -\strlen($ext)) . '.php';
if (@\filemtime($cache) < \filemtime($file)) {
$content = Yaml::parseFile($file);
if (!\is_dir($dir) && !@\mkdir($dir, 0755) && !\is_dir($dir)) {
throw new \RuntimeException('Temp directory permission denied');
}
\file_put_contents($cache, '<?php return ' . static::parseArrayToCode($content) . ';');
if (\function_exists('\opcache_invalidate')) {
\opcache_invalidate($cache, true);
}
}
return include $cache;
} | php | protected static function loadYaml($file, $ext)
{
$filename = \basename($file);
$dir = \runtime_path('yaml');
$cache = $dir . DIRECTORY_SEPARATOR . substr($filename, 0, -\strlen($ext)) . '.php';
if (@\filemtime($cache) < \filemtime($file)) {
$content = Yaml::parseFile($file);
if (!\is_dir($dir) && !@\mkdir($dir, 0755) && !\is_dir($dir)) {
throw new \RuntimeException('Temp directory permission denied');
}
\file_put_contents($cache, '<?php return ' . static::parseArrayToCode($content) . ';');
if (\function_exists('\opcache_invalidate')) {
\opcache_invalidate($cache, true);
}
}
return include $cache;
} | [
"protected",
"static",
"function",
"loadYaml",
"(",
"$",
"file",
",",
"$",
"ext",
")",
"{",
"$",
"filename",
"=",
"\\",
"basename",
"(",
"$",
"file",
")",
";",
"$",
"dir",
"=",
"\\",
"runtime_path",
"(",
"'yaml'",
")",
";",
"$",
"cache",
"=",
"$",
"dir",
".",
"DIRECTORY_SEPARATOR",
".",
"substr",
"(",
"$",
"filename",
",",
"0",
",",
"-",
"\\",
"strlen",
"(",
"$",
"ext",
")",
")",
".",
"'.php'",
";",
"if",
"(",
"@",
"\\",
"filemtime",
"(",
"$",
"cache",
")",
"<",
"\\",
"filemtime",
"(",
"$",
"file",
")",
")",
"{",
"$",
"content",
"=",
"Yaml",
"::",
"parseFile",
"(",
"$",
"file",
")",
";",
"if",
"(",
"!",
"\\",
"is_dir",
"(",
"$",
"dir",
")",
"&&",
"!",
"@",
"\\",
"mkdir",
"(",
"$",
"dir",
",",
"0755",
")",
"&&",
"!",
"\\",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Temp directory permission denied'",
")",
";",
"}",
"\\",
"file_put_contents",
"(",
"$",
"cache",
",",
"'<?php return '",
".",
"static",
"::",
"parseArrayToCode",
"(",
"$",
"content",
")",
".",
"';'",
")",
";",
"if",
"(",
"\\",
"function_exists",
"(",
"'\\opcache_invalidate'",
")",
")",
"{",
"\\",
"opcache_invalidate",
"(",
"$",
"cache",
",",
"true",
")",
";",
"}",
"}",
"return",
"include",
"$",
"cache",
";",
"}"
] | Parse a YAML file or load it from the cache
@param $file
@return array|mixed | [
"Parse",
"a",
"YAML",
"file",
"or",
"load",
"it",
"from",
"the",
"cache"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Config.php#L149-L171 |
35,245 | Kajna/K-Core | Core/Container/Container.php | Container.get | public function get($key)
{
if (!$this->offsetExists($key)) {
throw new InvalidArgumentException(sprintf('Identifier "%s" is not defined.', $key));
}
return $this->offsetGet($key);
} | php | public function get($key)
{
if (!$this->offsetExists($key)) {
throw new InvalidArgumentException(sprintf('Identifier "%s" is not defined.', $key));
}
return $this->offsetGet($key);
} | [
"public",
"function",
"get",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"offsetExists",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Identifier \"%s\" is not defined.'",
",",
"$",
"key",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"offsetGet",
"(",
"$",
"key",
")",
";",
"}"
] | Get entry from container
@param string $key
@return mixed
@throws InvalidArgumentException | [
"Get",
"entry",
"from",
"container"
] | 6a354056cf95e471b9b1eb372c5626123fd77df2 | https://github.com/Kajna/K-Core/blob/6a354056cf95e471b9b1eb372c5626123fd77df2/Core/Container/Container.php#L76-L82 |
35,246 | mirko-pagliai/php-tools | src/FileArray.php | FileArray.delete | public function delete($key)
{
key_exists_or_fail($key, $this->data);
unset($this->data[$key]);
$this->data = array_values($this->data);
return $this;
} | php | public function delete($key)
{
key_exists_or_fail($key, $this->data);
unset($this->data[$key]);
$this->data = array_values($this->data);
return $this;
} | [
"public",
"function",
"delete",
"(",
"$",
"key",
")",
"{",
"key_exists_or_fail",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"data",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
")",
";",
"$",
"this",
"->",
"data",
"=",
"array_values",
"(",
"$",
"this",
"->",
"data",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Deletes a value from its key number.
Note that the keys will be re-ordered.
@param int $key Key number
@return $this
@throws KeyNotExistsException
@uses $data | [
"Deletes",
"a",
"value",
"from",
"its",
"key",
"number",
"."
] | 46003b05490de4b570b46c6377f1e09139ffe43b | https://github.com/mirko-pagliai/php-tools/blob/46003b05490de4b570b46c6377f1e09139ffe43b/src/FileArray.php#L74-L81 |
35,247 | hail-framework/framework | src/Debugger/Debugger.php | Debugger.enable | public static function enable($mode = null, string $logDirectory = null, string $email = null): void
{
if ($mode !== null || self::$productionMode === null) {
self::$mode = $mode;
if (\is_bool($mode)) {
self::$productionMode = $mode;
}
}
// logging configuration
if ($email !== null) {
self::$email = $email;
}
if ($logDirectory) {
if (!preg_match('#([a-z]+:)?[/\\\\]#Ai', $logDirectory)) {
self::exceptionHandler(new \RuntimeException('Logging directory must be absolute path.'));
} elseif (!is_dir(self::$logDirectory)) {
self::exceptionHandler(new \RuntimeException("Logging directory '" . $logDirectory . "' is not found."));
}
self::$logDirectory = $logDirectory;
}
if (self::$enabled) {
return;
}
self::$reserved = \str_repeat('t', 30000);
self::$obLevel = \ob_get_level();
// php configuration
if (self::$iniSet = \function_exists('\ini_set')) {
\ini_set('html_errors', '0');
\ini_set('log_errors', '0');
}
\error_reporting(E_ALL);
\register_shutdown_function([__CLASS__, 'shutdownHandler']);
\set_exception_handler([__CLASS__, 'exceptionHandler']);
\set_error_handler([__CLASS__, 'errorHandler']);
self::$enabled = true;
self::$enabledTime = \microtime(true);
} | php | public static function enable($mode = null, string $logDirectory = null, string $email = null): void
{
if ($mode !== null || self::$productionMode === null) {
self::$mode = $mode;
if (\is_bool($mode)) {
self::$productionMode = $mode;
}
}
// logging configuration
if ($email !== null) {
self::$email = $email;
}
if ($logDirectory) {
if (!preg_match('#([a-z]+:)?[/\\\\]#Ai', $logDirectory)) {
self::exceptionHandler(new \RuntimeException('Logging directory must be absolute path.'));
} elseif (!is_dir(self::$logDirectory)) {
self::exceptionHandler(new \RuntimeException("Logging directory '" . $logDirectory . "' is not found."));
}
self::$logDirectory = $logDirectory;
}
if (self::$enabled) {
return;
}
self::$reserved = \str_repeat('t', 30000);
self::$obLevel = \ob_get_level();
// php configuration
if (self::$iniSet = \function_exists('\ini_set')) {
\ini_set('html_errors', '0');
\ini_set('log_errors', '0');
}
\error_reporting(E_ALL);
\register_shutdown_function([__CLASS__, 'shutdownHandler']);
\set_exception_handler([__CLASS__, 'exceptionHandler']);
\set_error_handler([__CLASS__, 'errorHandler']);
self::$enabled = true;
self::$enabledTime = \microtime(true);
} | [
"public",
"static",
"function",
"enable",
"(",
"$",
"mode",
"=",
"null",
",",
"string",
"$",
"logDirectory",
"=",
"null",
",",
"string",
"$",
"email",
"=",
"null",
")",
":",
"void",
"{",
"if",
"(",
"$",
"mode",
"!==",
"null",
"||",
"self",
"::",
"$",
"productionMode",
"===",
"null",
")",
"{",
"self",
"::",
"$",
"mode",
"=",
"$",
"mode",
";",
"if",
"(",
"\\",
"is_bool",
"(",
"$",
"mode",
")",
")",
"{",
"self",
"::",
"$",
"productionMode",
"=",
"$",
"mode",
";",
"}",
"}",
"// logging configuration",
"if",
"(",
"$",
"email",
"!==",
"null",
")",
"{",
"self",
"::",
"$",
"email",
"=",
"$",
"email",
";",
"}",
"if",
"(",
"$",
"logDirectory",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"'#([a-z]+:)?[/\\\\\\\\]#Ai'",
",",
"$",
"logDirectory",
")",
")",
"{",
"self",
"::",
"exceptionHandler",
"(",
"new",
"\\",
"RuntimeException",
"(",
"'Logging directory must be absolute path.'",
")",
")",
";",
"}",
"elseif",
"(",
"!",
"is_dir",
"(",
"self",
"::",
"$",
"logDirectory",
")",
")",
"{",
"self",
"::",
"exceptionHandler",
"(",
"new",
"\\",
"RuntimeException",
"(",
"\"Logging directory '\"",
".",
"$",
"logDirectory",
".",
"\"' is not found.\"",
")",
")",
";",
"}",
"self",
"::",
"$",
"logDirectory",
"=",
"$",
"logDirectory",
";",
"}",
"if",
"(",
"self",
"::",
"$",
"enabled",
")",
"{",
"return",
";",
"}",
"self",
"::",
"$",
"reserved",
"=",
"\\",
"str_repeat",
"(",
"'t'",
",",
"30000",
")",
";",
"self",
"::",
"$",
"obLevel",
"=",
"\\",
"ob_get_level",
"(",
")",
";",
"// php configuration",
"if",
"(",
"self",
"::",
"$",
"iniSet",
"=",
"\\",
"function_exists",
"(",
"'\\ini_set'",
")",
")",
"{",
"\\",
"ini_set",
"(",
"'html_errors'",
",",
"'0'",
")",
";",
"\\",
"ini_set",
"(",
"'log_errors'",
",",
"'0'",
")",
";",
"}",
"\\",
"error_reporting",
"(",
"E_ALL",
")",
";",
"\\",
"register_shutdown_function",
"(",
"[",
"__CLASS__",
",",
"'shutdownHandler'",
"]",
")",
";",
"\\",
"set_exception_handler",
"(",
"[",
"__CLASS__",
",",
"'exceptionHandler'",
"]",
")",
";",
"\\",
"set_error_handler",
"(",
"[",
"__CLASS__",
",",
"'errorHandler'",
"]",
")",
";",
"self",
"::",
"$",
"enabled",
"=",
"true",
";",
"self",
"::",
"$",
"enabledTime",
"=",
"\\",
"microtime",
"(",
"true",
")",
";",
"}"
] | Enables displaying or logging errors and exceptions.
@param mixed $mode production, development mode, autodetection or IP address(es) whitelist.
@param string $logDirectory error log directory
@param string $email administrator email; enables email sending in production mode
@return void | [
"Enables",
"displaying",
"or",
"logging",
"errors",
"and",
"exceptions",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Debugger.php#L210-L256 |
35,248 | hail-framework/framework | src/Debugger/Debugger.php | Debugger.shutdownHandler | public static function shutdownHandler(): void
{
if (!self::$reserved) {
return;
}
$error = \error_get_last();
if (\in_array($error['type'],
[E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE, E_RECOVERABLE_ERROR, E_USER_ERROR], true
)) {
self::exceptionHandler(
Helpers::fixStack(
new \ErrorException($error['message'], 0, $error['type'], $error['file'], $error['line'])
), false
);
}
} | php | public static function shutdownHandler(): void
{
if (!self::$reserved) {
return;
}
$error = \error_get_last();
if (\in_array($error['type'],
[E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE, E_RECOVERABLE_ERROR, E_USER_ERROR], true
)) {
self::exceptionHandler(
Helpers::fixStack(
new \ErrorException($error['message'], 0, $error['type'], $error['file'], $error['line'])
), false
);
}
} | [
"public",
"static",
"function",
"shutdownHandler",
"(",
")",
":",
"void",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"reserved",
")",
"{",
"return",
";",
"}",
"$",
"error",
"=",
"\\",
"error_get_last",
"(",
")",
";",
"if",
"(",
"\\",
"in_array",
"(",
"$",
"error",
"[",
"'type'",
"]",
",",
"[",
"E_ERROR",
",",
"E_CORE_ERROR",
",",
"E_COMPILE_ERROR",
",",
"E_PARSE",
",",
"E_RECOVERABLE_ERROR",
",",
"E_USER_ERROR",
"]",
",",
"true",
")",
")",
"{",
"self",
"::",
"exceptionHandler",
"(",
"Helpers",
"::",
"fixStack",
"(",
"new",
"\\",
"ErrorException",
"(",
"$",
"error",
"[",
"'message'",
"]",
",",
"0",
",",
"$",
"error",
"[",
"'type'",
"]",
",",
"$",
"error",
"[",
"'file'",
"]",
",",
"$",
"error",
"[",
"'line'",
"]",
")",
")",
",",
"false",
")",
";",
"}",
"}"
] | Shutdown handler to catch fatal errors and execute of the planned activities.
@return void
@internal | [
"Shutdown",
"handler",
"to",
"catch",
"fatal",
"errors",
"and",
"execute",
"of",
"the",
"planned",
"activities",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Debugger.php#L372-L388 |
35,249 | hail-framework/framework | src/Debugger/Debugger.php | Debugger.dump | public static function dump($var, bool $return = false)
{
if ($return) {
\ob_start();
Dumper::dump($var, [
Dumper::DEPTH => self::$maxDepth,
Dumper::TRUNCATE => self::$maxLength,
]);
return \ob_get_clean();
}
if (!self::isProductionMode()) {
Dumper::dump($var, [
Dumper::DEPTH => self::$maxDepth,
Dumper::TRUNCATE => self::$maxLength,
Dumper::LOCATION => self::$showLocation,
]);
}
return $var;
} | php | public static function dump($var, bool $return = false)
{
if ($return) {
\ob_start();
Dumper::dump($var, [
Dumper::DEPTH => self::$maxDepth,
Dumper::TRUNCATE => self::$maxLength,
]);
return \ob_get_clean();
}
if (!self::isProductionMode()) {
Dumper::dump($var, [
Dumper::DEPTH => self::$maxDepth,
Dumper::TRUNCATE => self::$maxLength,
Dumper::LOCATION => self::$showLocation,
]);
}
return $var;
} | [
"public",
"static",
"function",
"dump",
"(",
"$",
"var",
",",
"bool",
"$",
"return",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"return",
")",
"{",
"\\",
"ob_start",
"(",
")",
";",
"Dumper",
"::",
"dump",
"(",
"$",
"var",
",",
"[",
"Dumper",
"::",
"DEPTH",
"=>",
"self",
"::",
"$",
"maxDepth",
",",
"Dumper",
"::",
"TRUNCATE",
"=>",
"self",
"::",
"$",
"maxLength",
",",
"]",
")",
";",
"return",
"\\",
"ob_get_clean",
"(",
")",
";",
"}",
"if",
"(",
"!",
"self",
"::",
"isProductionMode",
"(",
")",
")",
"{",
"Dumper",
"::",
"dump",
"(",
"$",
"var",
",",
"[",
"Dumper",
"::",
"DEPTH",
"=>",
"self",
"::",
"$",
"maxDepth",
",",
"Dumper",
"::",
"TRUNCATE",
"=>",
"self",
"::",
"$",
"maxLength",
",",
"Dumper",
"::",
"LOCATION",
"=>",
"self",
"::",
"$",
"showLocation",
",",
"]",
")",
";",
"}",
"return",
"$",
"var",
";",
"}"
] | Dumps information about a variable in readable format.
@tracySkipLocation
@param mixed $var variable to dump
@param bool $return return output instead of printing it? (bypasses $productionMode)
@return mixed variable itself or dump | [
"Dumps",
"information",
"about",
"a",
"variable",
"in",
"readable",
"format",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Debugger.php#L746-L767 |
35,250 | hail-framework/framework | src/Debugger/Debugger.php | Debugger.barDump | public static function barDump($var, string $title = null, array $options = null)
{
if (!self::isProductionMode()) {
static $panel;
if (!$panel) {
self::getBar()->addPanel($panel = new Bar\DefaultPanel('dumps'), 'Tracy:dumps');
}
$panel->data[] = [
'title' => $title,
'dump' => Dumper::toHtml($var, $options + [
Dumper::DEPTH => self::$maxDepth,
Dumper::TRUNCATE => self::$maxLength,
Dumper::LOCATION => self::$showLocation ?: Dumper::LOCATION_CLASS | Dumper::LOCATION_SOURCE,
]),
];
}
return $var;
} | php | public static function barDump($var, string $title = null, array $options = null)
{
if (!self::isProductionMode()) {
static $panel;
if (!$panel) {
self::getBar()->addPanel($panel = new Bar\DefaultPanel('dumps'), 'Tracy:dumps');
}
$panel->data[] = [
'title' => $title,
'dump' => Dumper::toHtml($var, $options + [
Dumper::DEPTH => self::$maxDepth,
Dumper::TRUNCATE => self::$maxLength,
Dumper::LOCATION => self::$showLocation ?: Dumper::LOCATION_CLASS | Dumper::LOCATION_SOURCE,
]),
];
}
return $var;
} | [
"public",
"static",
"function",
"barDump",
"(",
"$",
"var",
",",
"string",
"$",
"title",
"=",
"null",
",",
"array",
"$",
"options",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"isProductionMode",
"(",
")",
")",
"{",
"static",
"$",
"panel",
";",
"if",
"(",
"!",
"$",
"panel",
")",
"{",
"self",
"::",
"getBar",
"(",
")",
"->",
"addPanel",
"(",
"$",
"panel",
"=",
"new",
"Bar",
"\\",
"DefaultPanel",
"(",
"'dumps'",
")",
",",
"'Tracy:dumps'",
")",
";",
"}",
"$",
"panel",
"->",
"data",
"[",
"]",
"=",
"[",
"'title'",
"=>",
"$",
"title",
",",
"'dump'",
"=>",
"Dumper",
"::",
"toHtml",
"(",
"$",
"var",
",",
"$",
"options",
"+",
"[",
"Dumper",
"::",
"DEPTH",
"=>",
"self",
"::",
"$",
"maxDepth",
",",
"Dumper",
"::",
"TRUNCATE",
"=>",
"self",
"::",
"$",
"maxLength",
",",
"Dumper",
"::",
"LOCATION",
"=>",
"self",
"::",
"$",
"showLocation",
"?",
":",
"Dumper",
"::",
"LOCATION_CLASS",
"|",
"Dumper",
"::",
"LOCATION_SOURCE",
",",
"]",
")",
",",
"]",
";",
"}",
"return",
"$",
"var",
";",
"}"
] | Dumps information about a variable in Tracy Debug Bar.
@tracySkipLocation
@param mixed $var variable to dump
@param string $title optional title
@param array $options dumper options
@return mixed variable itself | [
"Dumps",
"information",
"about",
"a",
"variable",
"in",
"Tracy",
"Debug",
"Bar",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Debugger.php#L797-L815 |
35,251 | hail-framework/framework | src/Debugger/Debugger.php | Debugger.log | public static function log($message, string $priority = self::INFO): ?string
{
$logger = self::sendToLogger(self::getLogger(), $priority, $message);
if ($logger instanceof Logger) {
return $logger->getLastExceptionFile();
}
return null;
} | php | public static function log($message, string $priority = self::INFO): ?string
{
$logger = self::sendToLogger(self::getLogger(), $priority, $message);
if ($logger instanceof Logger) {
return $logger->getLastExceptionFile();
}
return null;
} | [
"public",
"static",
"function",
"log",
"(",
"$",
"message",
",",
"string",
"$",
"priority",
"=",
"self",
"::",
"INFO",
")",
":",
"?",
"string",
"{",
"$",
"logger",
"=",
"self",
"::",
"sendToLogger",
"(",
"self",
"::",
"getLogger",
"(",
")",
",",
"$",
"priority",
",",
"$",
"message",
")",
";",
"if",
"(",
"$",
"logger",
"instanceof",
"Logger",
")",
"{",
"return",
"$",
"logger",
"->",
"getLastExceptionFile",
"(",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Logs message or exception.
@param mixed $message
@param string $priority
@return string|null | [
"Logs",
"message",
"or",
"exception",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Debugger.php#L826-L835 |
35,252 | hail-framework/framework | src/Debugger/Debugger.php | Debugger.chromeLog | public static function chromeLog($message, string $priority = self::DEBUG): bool
{
if (self::$showChromeLogger && !self::isProductionMode()) {
self::sendToLogger(self::getChromeLogger(), $priority, $message);
return true;
}
return false;
} | php | public static function chromeLog($message, string $priority = self::DEBUG): bool
{
if (self::$showChromeLogger && !self::isProductionMode()) {
self::sendToLogger(self::getChromeLogger(), $priority, $message);
return true;
}
return false;
} | [
"public",
"static",
"function",
"chromeLog",
"(",
"$",
"message",
",",
"string",
"$",
"priority",
"=",
"self",
"::",
"DEBUG",
")",
":",
"bool",
"{",
"if",
"(",
"self",
"::",
"$",
"showChromeLogger",
"&&",
"!",
"self",
"::",
"isProductionMode",
"(",
")",
")",
"{",
"self",
"::",
"sendToLogger",
"(",
"self",
"::",
"getChromeLogger",
"(",
")",
",",
"$",
"priority",
",",
"$",
"message",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Sends message to ChromeLogger console.
@param mixed $message message to log
@param string $priority
@return bool was successful? | [
"Sends",
"message",
"to",
"ChromeLogger",
"console",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Debugger.php#L858-L867 |
35,253 | mcrumm/pecan | src/Drupe.php | Drupe.checkRunning | public function checkRunning(Timer $timer)
{
if (!$this->running) {
$timer->cancel();
// @codeCoverageIgnoreStart
exit($this->exitCode);
// @codeCoverageIgnoreEnd
}
} | php | public function checkRunning(Timer $timer)
{
if (!$this->running) {
$timer->cancel();
// @codeCoverageIgnoreStart
exit($this->exitCode);
// @codeCoverageIgnoreEnd
}
} | [
"public",
"function",
"checkRunning",
"(",
"Timer",
"$",
"timer",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"running",
")",
"{",
"$",
"timer",
"->",
"cancel",
"(",
")",
";",
"// @codeCoverageIgnoreStart",
"exit",
"(",
"$",
"this",
"->",
"exitCode",
")",
";",
"// @codeCoverageIgnoreEnd",
"}",
"}"
] | Checks whether or not the shell is still running.
@param Timer $timer | [
"Checks",
"whether",
"or",
"not",
"the",
"shell",
"is",
"still",
"running",
"."
] | f35f01249587a4df45c7d3ab78f3e51919471177 | https://github.com/mcrumm/pecan/blob/f35f01249587a4df45c7d3ab78f3e51919471177/src/Drupe.php#L151-L159 |
35,254 | htmlburger/wpemerge-cli | src/Presets/FilesystemTrait.php | FilesystemTrait.copy | protected function copy( $files ) {
$failures = [];
foreach ( $files as $source => $destination ) {
if ( file_exists( $destination ) ) {
$failures[ $source ] = $destination;
continue;
}
$directory = dirname( $destination );
if ( ! file_exists( $directory ) ) {
mkdir( $directory );
}
copy( $source, $destination );
}
return $failures;
} | php | protected function copy( $files ) {
$failures = [];
foreach ( $files as $source => $destination ) {
if ( file_exists( $destination ) ) {
$failures[ $source ] = $destination;
continue;
}
$directory = dirname( $destination );
if ( ! file_exists( $directory ) ) {
mkdir( $directory );
}
copy( $source, $destination );
}
return $failures;
} | [
"protected",
"function",
"copy",
"(",
"$",
"files",
")",
"{",
"$",
"failures",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"source",
"=>",
"$",
"destination",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"destination",
")",
")",
"{",
"$",
"failures",
"[",
"$",
"source",
"]",
"=",
"$",
"destination",
";",
"continue",
";",
"}",
"$",
"directory",
"=",
"dirname",
"(",
"$",
"destination",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"directory",
")",
")",
"{",
"mkdir",
"(",
"$",
"directory",
")",
";",
"}",
"copy",
"(",
"$",
"source",
",",
"$",
"destination",
")",
";",
"}",
"return",
"$",
"failures",
";",
"}"
] | Copy a list of files, returning an array of failures.
@param array $files
@return array | [
"Copy",
"a",
"list",
"of",
"files",
"returning",
"an",
"array",
"of",
"failures",
"."
] | 075f1982b7dd87039a4e7bbc05caf676a10fe862 | https://github.com/htmlburger/wpemerge-cli/blob/075f1982b7dd87039a4e7bbc05caf676a10fe862/src/Presets/FilesystemTrait.php#L22-L40 |
35,255 | htmlburger/wpemerge-cli | src/Presets/FilesystemTrait.php | FilesystemTrait.stringHasStatement | protected function stringHasStatement( $haystack, $needle ) {
$pattern = '~^\s*(' . preg_quote( $needle, '~' ) . ')\s*$~m';
return (bool) preg_match( $pattern, $haystack );
} | php | protected function stringHasStatement( $haystack, $needle ) {
$pattern = '~^\s*(' . preg_quote( $needle, '~' ) . ')\s*$~m';
return (bool) preg_match( $pattern, $haystack );
} | [
"protected",
"function",
"stringHasStatement",
"(",
"$",
"haystack",
",",
"$",
"needle",
")",
"{",
"$",
"pattern",
"=",
"'~^\\s*('",
".",
"preg_quote",
"(",
"$",
"needle",
",",
"'~'",
")",
".",
"')\\s*$~m'",
";",
"return",
"(",
"bool",
")",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"haystack",
")",
";",
"}"
] | Get whether a string has a given statement present.
@param string $haystack
@param string $needle
@return boolean | [
"Get",
"whether",
"a",
"string",
"has",
"a",
"given",
"statement",
"present",
"."
] | 075f1982b7dd87039a4e7bbc05caf676a10fe862 | https://github.com/htmlburger/wpemerge-cli/blob/075f1982b7dd87039a4e7bbc05caf676a10fe862/src/Presets/FilesystemTrait.php#L62-L65 |
35,256 | htmlburger/wpemerge-cli | src/Presets/FilesystemTrait.php | FilesystemTrait.appendUniqueStatement | protected function appendUniqueStatement( $filepath, $statement ) {
$contents = file_get_contents( $filepath );
if ( $this->stringHasStatement( $contents, $statement ) ) {
return;
}
$eol = $this->getEol( $contents );
$content_lines = explode( "\n", $contents );
$last_line = trim( $content_lines[ count( $content_lines ) - 1 ] );
if ( empty( $last_line ) ) {
$contents .= $statement . $eol;
} else {
$contents .= $eol . $statement;
}
file_put_contents( $filepath, $contents );
} | php | protected function appendUniqueStatement( $filepath, $statement ) {
$contents = file_get_contents( $filepath );
if ( $this->stringHasStatement( $contents, $statement ) ) {
return;
}
$eol = $this->getEol( $contents );
$content_lines = explode( "\n", $contents );
$last_line = trim( $content_lines[ count( $content_lines ) - 1 ] );
if ( empty( $last_line ) ) {
$contents .= $statement . $eol;
} else {
$contents .= $eol . $statement;
}
file_put_contents( $filepath, $contents );
} | [
"protected",
"function",
"appendUniqueStatement",
"(",
"$",
"filepath",
",",
"$",
"statement",
")",
"{",
"$",
"contents",
"=",
"file_get_contents",
"(",
"$",
"filepath",
")",
";",
"if",
"(",
"$",
"this",
"->",
"stringHasStatement",
"(",
"$",
"contents",
",",
"$",
"statement",
")",
")",
"{",
"return",
";",
"}",
"$",
"eol",
"=",
"$",
"this",
"->",
"getEol",
"(",
"$",
"contents",
")",
";",
"$",
"content_lines",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"contents",
")",
";",
"$",
"last_line",
"=",
"trim",
"(",
"$",
"content_lines",
"[",
"count",
"(",
"$",
"content_lines",
")",
"-",
"1",
"]",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"last_line",
")",
")",
"{",
"$",
"contents",
".=",
"$",
"statement",
".",
"$",
"eol",
";",
"}",
"else",
"{",
"$",
"contents",
".=",
"$",
"eol",
".",
"$",
"statement",
";",
"}",
"file_put_contents",
"(",
"$",
"filepath",
",",
"$",
"contents",
")",
";",
"}"
] | Append a statement to file.
@param string $filepath
@param string $statement
@return void | [
"Append",
"a",
"statement",
"to",
"file",
"."
] | 075f1982b7dd87039a4e7bbc05caf676a10fe862 | https://github.com/htmlburger/wpemerge-cli/blob/075f1982b7dd87039a4e7bbc05caf676a10fe862/src/Presets/FilesystemTrait.php#L74-L92 |
35,257 | Kajna/K-Core | Core/Session/Handlers/DatabaseSessionHandler.php | DatabaseSessionHandler.read | public function read($id)
{
$stmt = $this->db->prepare("SELECT session_data FROM " . $this->tableName . " WHERE session_id = :id");
$stmt->execute(['id' => $id]);
return base64_decode($stmt->fetchColumn());
} | php | public function read($id)
{
$stmt = $this->db->prepare("SELECT session_data FROM " . $this->tableName . " WHERE session_id = :id");
$stmt->execute(['id' => $id]);
return base64_decode($stmt->fetchColumn());
} | [
"public",
"function",
"read",
"(",
"$",
"id",
")",
"{",
"$",
"stmt",
"=",
"$",
"this",
"->",
"db",
"->",
"prepare",
"(",
"\"SELECT session_data FROM \"",
".",
"$",
"this",
"->",
"tableName",
".",
"\" WHERE session_id = :id\"",
")",
";",
"$",
"stmt",
"->",
"execute",
"(",
"[",
"'id'",
"=>",
"$",
"id",
"]",
")",
";",
"return",
"base64_decode",
"(",
"$",
"stmt",
"->",
"fetchColumn",
"(",
")",
")",
";",
"}"
] | Read the session
@param int $id
@return string string of the session | [
"Read",
"the",
"session"
] | 6a354056cf95e471b9b1eb372c5626123fd77df2 | https://github.com/Kajna/K-Core/blob/6a354056cf95e471b9b1eb372c5626123fd77df2/Core/Session/Handlers/DatabaseSessionHandler.php#L88-L93 |
35,258 | hail-framework/framework | src/Mail/Message.php | Message.formatEmail | private function formatEmail(string $email, string $name = null): array
{
if (!$name && \preg_match('#^(.+) +<(.*)>\z#', $email, $matches)) {
return [$matches[2] => $matches[1]];
}
return [$email => $name];
} | php | private function formatEmail(string $email, string $name = null): array
{
if (!$name && \preg_match('#^(.+) +<(.*)>\z#', $email, $matches)) {
return [$matches[2] => $matches[1]];
}
return [$email => $name];
} | [
"private",
"function",
"formatEmail",
"(",
"string",
"$",
"email",
",",
"string",
"$",
"name",
"=",
"null",
")",
":",
"array",
"{",
"if",
"(",
"!",
"$",
"name",
"&&",
"\\",
"preg_match",
"(",
"'#^(.+) +<(.*)>\\z#'",
",",
"$",
"email",
",",
"$",
"matches",
")",
")",
"{",
"return",
"[",
"$",
"matches",
"[",
"2",
"]",
"=>",
"$",
"matches",
"[",
"1",
"]",
"]",
";",
"}",
"return",
"[",
"$",
"email",
"=>",
"$",
"name",
"]",
";",
"}"
] | Formats recipient email.
@param string $email
@param string|null $name
@return array | [
"Formats",
"recipient",
"email",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Mail/Message.php#L175-L182 |
35,259 | hail-framework/framework | src/Mail/Message.php | Message.setHtmlBody | public function setHtmlBody(string $html, string $basePath = null)
{
if ($basePath) {
$cids = [];
$matches = Strings::matchAll(
$html,
'#
(<img[^<>]*\s src\s*=\s*
|<body[^<>]*\s background\s*=\s*
|<[^<>]+\s style\s*=\s* ["\'][^"\'>]+[:\s] url\(
|<style[^>]*>[^<]+ [:\s] url\()
(["\']?)(?![a-z]+:|[/\\#])([^"\'>)\s]+)
|\[\[ ([\w()+./@~-]+) \]\]
#ix',
PREG_OFFSET_CAPTURE
);
foreach (\array_reverse($matches) as $m) {
$file = \rtrim($basePath, '/\\') . '/' . (isset($m[4]) ? $m[4][0] : \urldecode($m[3][0]));
if (!isset($cids[$file])) {
$cids[$file] = \substr($this->addEmbeddedFile($file)->getHeader('Content-ID'), 1, -1);
}
$html = \substr_replace($html,
"{$m[1][0]}{$m[2][0]}cid:{$cids[$file]}",
$m[0][1], \strlen($m[0][0])
);
}
}
if ($this->getSubject() == null) { // intentionally ==
$html = Strings::replace($html, '#<title>(.+?)</title>#is', function (array $m): void {
$this->setSubject(\html_entity_decode($m[1], ENT_QUOTES, 'UTF-8'));
});
}
$this->htmlBody = \ltrim(\str_replace("\r", '', $html), "\n");
if ($html !== '' && $this->getBody() === '') {
$this->setBody($this->buildText($html));
}
return $this;
} | php | public function setHtmlBody(string $html, string $basePath = null)
{
if ($basePath) {
$cids = [];
$matches = Strings::matchAll(
$html,
'#
(<img[^<>]*\s src\s*=\s*
|<body[^<>]*\s background\s*=\s*
|<[^<>]+\s style\s*=\s* ["\'][^"\'>]+[:\s] url\(
|<style[^>]*>[^<]+ [:\s] url\()
(["\']?)(?![a-z]+:|[/\\#])([^"\'>)\s]+)
|\[\[ ([\w()+./@~-]+) \]\]
#ix',
PREG_OFFSET_CAPTURE
);
foreach (\array_reverse($matches) as $m) {
$file = \rtrim($basePath, '/\\') . '/' . (isset($m[4]) ? $m[4][0] : \urldecode($m[3][0]));
if (!isset($cids[$file])) {
$cids[$file] = \substr($this->addEmbeddedFile($file)->getHeader('Content-ID'), 1, -1);
}
$html = \substr_replace($html,
"{$m[1][0]}{$m[2][0]}cid:{$cids[$file]}",
$m[0][1], \strlen($m[0][0])
);
}
}
if ($this->getSubject() == null) { // intentionally ==
$html = Strings::replace($html, '#<title>(.+?)</title>#is', function (array $m): void {
$this->setSubject(\html_entity_decode($m[1], ENT_QUOTES, 'UTF-8'));
});
}
$this->htmlBody = \ltrim(\str_replace("\r", '', $html), "\n");
if ($html !== '' && $this->getBody() === '') {
$this->setBody($this->buildText($html));
}
return $this;
} | [
"public",
"function",
"setHtmlBody",
"(",
"string",
"$",
"html",
",",
"string",
"$",
"basePath",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"basePath",
")",
"{",
"$",
"cids",
"=",
"[",
"]",
";",
"$",
"matches",
"=",
"Strings",
"::",
"matchAll",
"(",
"$",
"html",
",",
"'#\n\t\t\t\t\t(<img[^<>]*\\s src\\s*=\\s*\n\t\t\t\t\t|<body[^<>]*\\s background\\s*=\\s*\n\t\t\t\t\t|<[^<>]+\\s style\\s*=\\s* [\"\\'][^\"\\'>]+[:\\s] url\\(\n\t\t\t\t\t|<style[^>]*>[^<]+ [:\\s] url\\()\n\t\t\t\t\t([\"\\']?)(?![a-z]+:|[/\\\\#])([^\"\\'>)\\s]+)\n\t\t\t\t\t|\\[\\[ ([\\w()+./@~-]+) \\]\\]\n\t\t\t\t#ix'",
",",
"PREG_OFFSET_CAPTURE",
")",
";",
"foreach",
"(",
"\\",
"array_reverse",
"(",
"$",
"matches",
")",
"as",
"$",
"m",
")",
"{",
"$",
"file",
"=",
"\\",
"rtrim",
"(",
"$",
"basePath",
",",
"'/\\\\'",
")",
".",
"'/'",
".",
"(",
"isset",
"(",
"$",
"m",
"[",
"4",
"]",
")",
"?",
"$",
"m",
"[",
"4",
"]",
"[",
"0",
"]",
":",
"\\",
"urldecode",
"(",
"$",
"m",
"[",
"3",
"]",
"[",
"0",
"]",
")",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"cids",
"[",
"$",
"file",
"]",
")",
")",
"{",
"$",
"cids",
"[",
"$",
"file",
"]",
"=",
"\\",
"substr",
"(",
"$",
"this",
"->",
"addEmbeddedFile",
"(",
"$",
"file",
")",
"->",
"getHeader",
"(",
"'Content-ID'",
")",
",",
"1",
",",
"-",
"1",
")",
";",
"}",
"$",
"html",
"=",
"\\",
"substr_replace",
"(",
"$",
"html",
",",
"\"{$m[1][0]}{$m[2][0]}cid:{$cids[$file]}\"",
",",
"$",
"m",
"[",
"0",
"]",
"[",
"1",
"]",
",",
"\\",
"strlen",
"(",
"$",
"m",
"[",
"0",
"]",
"[",
"0",
"]",
")",
")",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"getSubject",
"(",
")",
"==",
"null",
")",
"{",
"// intentionally ==",
"$",
"html",
"=",
"Strings",
"::",
"replace",
"(",
"$",
"html",
",",
"'#<title>(.+?)</title>#is'",
",",
"function",
"(",
"array",
"$",
"m",
")",
":",
"void",
"{",
"$",
"this",
"->",
"setSubject",
"(",
"\\",
"html_entity_decode",
"(",
"$",
"m",
"[",
"1",
"]",
",",
"ENT_QUOTES",
",",
"'UTF-8'",
")",
")",
";",
"}",
")",
";",
"}",
"$",
"this",
"->",
"htmlBody",
"=",
"\\",
"ltrim",
"(",
"\\",
"str_replace",
"(",
"\"\\r\"",
",",
"''",
",",
"$",
"html",
")",
",",
"\"\\n\"",
")",
";",
"if",
"(",
"$",
"html",
"!==",
"''",
"&&",
"$",
"this",
"->",
"getBody",
"(",
")",
"===",
"''",
")",
"{",
"$",
"this",
"->",
"setBody",
"(",
"$",
"this",
"->",
"buildText",
"(",
"$",
"html",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Sets HTML body.
@param string $html
@param string|null $basePath
@return $this
@throws RegexpException | [
"Sets",
"HTML",
"body",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Mail/Message.php#L243-L284 |
35,260 | hail-framework/framework | src/Mail/Message.php | Message.addEmbeddedFile | public function addEmbeddedFile(string $file, string $content = null, string $contentType = null): MimePart
{
return $this->inlines[$file] = $this->createAttachment($file, $content, $contentType, 'inline')
->setHeader('Content-ID', $this->getRandomId());
} | php | public function addEmbeddedFile(string $file, string $content = null, string $contentType = null): MimePart
{
return $this->inlines[$file] = $this->createAttachment($file, $content, $contentType, 'inline')
->setHeader('Content-ID', $this->getRandomId());
} | [
"public",
"function",
"addEmbeddedFile",
"(",
"string",
"$",
"file",
",",
"string",
"$",
"content",
"=",
"null",
",",
"string",
"$",
"contentType",
"=",
"null",
")",
":",
"MimePart",
"{",
"return",
"$",
"this",
"->",
"inlines",
"[",
"$",
"file",
"]",
"=",
"$",
"this",
"->",
"createAttachment",
"(",
"$",
"file",
",",
"$",
"content",
",",
"$",
"contentType",
",",
"'inline'",
")",
"->",
"setHeader",
"(",
"'Content-ID'",
",",
"$",
"this",
"->",
"getRandomId",
"(",
")",
")",
";",
"}"
] | Adds embedded file.
@param string $file
@param string|null $content
@param string|null $contentType
@return MimePart | [
"Adds",
"embedded",
"file",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Mail/Message.php#L305-L309 |
35,261 | hail-framework/framework | src/Mail/Message.php | Message.addAttachment | public function addAttachment(string $file, string $content = null, string $contentType = null): MimePart
{
return $this->attachments[] = $this->createAttachment($file, $content, $contentType, 'attachment');
} | php | public function addAttachment(string $file, string $content = null, string $contentType = null): MimePart
{
return $this->attachments[] = $this->createAttachment($file, $content, $contentType, 'attachment');
} | [
"public",
"function",
"addAttachment",
"(",
"string",
"$",
"file",
",",
"string",
"$",
"content",
"=",
"null",
",",
"string",
"$",
"contentType",
"=",
"null",
")",
":",
"MimePart",
"{",
"return",
"$",
"this",
"->",
"attachments",
"[",
"]",
"=",
"$",
"this",
"->",
"createAttachment",
"(",
"$",
"file",
",",
"$",
"content",
",",
"$",
"contentType",
",",
"'attachment'",
")",
";",
"}"
] | Adds attachment.
@param string $file
@param string|null $content
@param string|null $contentType
@return MimePart | [
"Adds",
"attachment",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Mail/Message.php#L336-L339 |
35,262 | hail-framework/framework | src/Mail/Message.php | Message.createAttachment | private function createAttachment(
string $file,
string $content = null,
string $contentType = null,
string $disposition
): MimePart {
$part = new MimePart;
if ($content === null) {
$content = @\file_get_contents($file); // @ is escalated to exception
if ($content === false) {
throw new FileNotFoundException("Unable to read file '$file'.");
}
}
if (!$contentType) {
$contentType = MimeType::getMimeTypeByContent($content);
}
if (!\strcasecmp($contentType, 'message/rfc822')) { // not allowed for attached files
$contentType = 'application/octet-stream';
} elseif (!\strcasecmp($contentType, 'image/svg')) { // Troublesome for some mailers...
$contentType = 'image/svg+xml';
}
$part->setBody($content);
$part->setContentType($contentType);
$part->setEncoding(\preg_match('#(multipart|message)/#A', $contentType) ?
self::ENCODING_8BIT : self::ENCODING_BASE64);
$part->setHeader('Content-Disposition',
$disposition . '; filename="' . Strings::fixEncoding(\basename($file)) . '"');
return $part;
} | php | private function createAttachment(
string $file,
string $content = null,
string $contentType = null,
string $disposition
): MimePart {
$part = new MimePart;
if ($content === null) {
$content = @\file_get_contents($file); // @ is escalated to exception
if ($content === false) {
throw new FileNotFoundException("Unable to read file '$file'.");
}
}
if (!$contentType) {
$contentType = MimeType::getMimeTypeByContent($content);
}
if (!\strcasecmp($contentType, 'message/rfc822')) { // not allowed for attached files
$contentType = 'application/octet-stream';
} elseif (!\strcasecmp($contentType, 'image/svg')) { // Troublesome for some mailers...
$contentType = 'image/svg+xml';
}
$part->setBody($content);
$part->setContentType($contentType);
$part->setEncoding(\preg_match('#(multipart|message)/#A', $contentType) ?
self::ENCODING_8BIT : self::ENCODING_BASE64);
$part->setHeader('Content-Disposition',
$disposition . '; filename="' . Strings::fixEncoding(\basename($file)) . '"');
return $part;
} | [
"private",
"function",
"createAttachment",
"(",
"string",
"$",
"file",
",",
"string",
"$",
"content",
"=",
"null",
",",
"string",
"$",
"contentType",
"=",
"null",
",",
"string",
"$",
"disposition",
")",
":",
"MimePart",
"{",
"$",
"part",
"=",
"new",
"MimePart",
";",
"if",
"(",
"$",
"content",
"===",
"null",
")",
"{",
"$",
"content",
"=",
"@",
"\\",
"file_get_contents",
"(",
"$",
"file",
")",
";",
"// @ is escalated to exception",
"if",
"(",
"$",
"content",
"===",
"false",
")",
"{",
"throw",
"new",
"FileNotFoundException",
"(",
"\"Unable to read file '$file'.\"",
")",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"contentType",
")",
"{",
"$",
"contentType",
"=",
"MimeType",
"::",
"getMimeTypeByContent",
"(",
"$",
"content",
")",
";",
"}",
"if",
"(",
"!",
"\\",
"strcasecmp",
"(",
"$",
"contentType",
",",
"'message/rfc822'",
")",
")",
"{",
"// not allowed for attached files",
"$",
"contentType",
"=",
"'application/octet-stream'",
";",
"}",
"elseif",
"(",
"!",
"\\",
"strcasecmp",
"(",
"$",
"contentType",
",",
"'image/svg'",
")",
")",
"{",
"// Troublesome for some mailers...",
"$",
"contentType",
"=",
"'image/svg+xml'",
";",
"}",
"$",
"part",
"->",
"setBody",
"(",
"$",
"content",
")",
";",
"$",
"part",
"->",
"setContentType",
"(",
"$",
"contentType",
")",
";",
"$",
"part",
"->",
"setEncoding",
"(",
"\\",
"preg_match",
"(",
"'#(multipart|message)/#A'",
",",
"$",
"contentType",
")",
"?",
"self",
"::",
"ENCODING_8BIT",
":",
"self",
"::",
"ENCODING_BASE64",
")",
";",
"$",
"part",
"->",
"setHeader",
"(",
"'Content-Disposition'",
",",
"$",
"disposition",
".",
"'; filename=\"'",
".",
"Strings",
"::",
"fixEncoding",
"(",
"\\",
"basename",
"(",
"$",
"file",
")",
")",
".",
"'\"'",
")",
";",
"return",
"$",
"part",
";",
"}"
] | Creates file MIME part.
@param string $file
@param string|null $content
@param string|null $contentType
@param string $disposition
@return MimePart | [
"Creates",
"file",
"MIME",
"part",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Mail/Message.php#L363-L395 |
35,263 | hail-framework/framework | src/Mail/Message.php | Message.build | protected function build()
{
$mail = clone $this;
$mail->setHeader('Message-ID', $this->getRandomId());
$cursor = $mail;
if ($mail->attachments) {
$tmp = $cursor->setContentType('multipart/mixed');
$cursor = $cursor->addPart();
foreach ($mail->attachments as $value) {
$tmp->addPart($value);
}
}
if ($mail->htmlBody !== '') {
$tmp = $cursor->setContentType('multipart/alternative');
$cursor = $cursor->addPart();
$alt = $tmp->addPart();
if ($mail->inlines) {
$tmp = $alt->setContentType('multipart/related');
$alt = $alt->addPart();
foreach ($mail->inlines as $value) {
$tmp->addPart($value);
}
}
$alt->setContentType('text/html', 'UTF-8')
->setEncoding(\preg_match('#[^\n]{990}#', $mail->htmlBody)
? self::ENCODING_QUOTED_PRINTABLE
: (\preg_match('#[\x80-\xFF]#', $mail->htmlBody) ? self::ENCODING_8BIT : self::ENCODING_7BIT))
->setBody($mail->htmlBody);
}
$text = $mail->getBody();
$mail->setBody('');
$cursor->setContentType('text/plain', 'UTF-8')
->setEncoding(\preg_match('#[^\n]{990}#', $text)
? self::ENCODING_QUOTED_PRINTABLE
: (\preg_match('#[\x80-\xFF]#', $text) ? self::ENCODING_8BIT : self::ENCODING_7BIT))
->setBody($text);
return $mail;
} | php | protected function build()
{
$mail = clone $this;
$mail->setHeader('Message-ID', $this->getRandomId());
$cursor = $mail;
if ($mail->attachments) {
$tmp = $cursor->setContentType('multipart/mixed');
$cursor = $cursor->addPart();
foreach ($mail->attachments as $value) {
$tmp->addPart($value);
}
}
if ($mail->htmlBody !== '') {
$tmp = $cursor->setContentType('multipart/alternative');
$cursor = $cursor->addPart();
$alt = $tmp->addPart();
if ($mail->inlines) {
$tmp = $alt->setContentType('multipart/related');
$alt = $alt->addPart();
foreach ($mail->inlines as $value) {
$tmp->addPart($value);
}
}
$alt->setContentType('text/html', 'UTF-8')
->setEncoding(\preg_match('#[^\n]{990}#', $mail->htmlBody)
? self::ENCODING_QUOTED_PRINTABLE
: (\preg_match('#[\x80-\xFF]#', $mail->htmlBody) ? self::ENCODING_8BIT : self::ENCODING_7BIT))
->setBody($mail->htmlBody);
}
$text = $mail->getBody();
$mail->setBody('');
$cursor->setContentType('text/plain', 'UTF-8')
->setEncoding(\preg_match('#[^\n]{990}#', $text)
? self::ENCODING_QUOTED_PRINTABLE
: (\preg_match('#[\x80-\xFF]#', $text) ? self::ENCODING_8BIT : self::ENCODING_7BIT))
->setBody($text);
return $mail;
} | [
"protected",
"function",
"build",
"(",
")",
"{",
"$",
"mail",
"=",
"clone",
"$",
"this",
";",
"$",
"mail",
"->",
"setHeader",
"(",
"'Message-ID'",
",",
"$",
"this",
"->",
"getRandomId",
"(",
")",
")",
";",
"$",
"cursor",
"=",
"$",
"mail",
";",
"if",
"(",
"$",
"mail",
"->",
"attachments",
")",
"{",
"$",
"tmp",
"=",
"$",
"cursor",
"->",
"setContentType",
"(",
"'multipart/mixed'",
")",
";",
"$",
"cursor",
"=",
"$",
"cursor",
"->",
"addPart",
"(",
")",
";",
"foreach",
"(",
"$",
"mail",
"->",
"attachments",
"as",
"$",
"value",
")",
"{",
"$",
"tmp",
"->",
"addPart",
"(",
"$",
"value",
")",
";",
"}",
"}",
"if",
"(",
"$",
"mail",
"->",
"htmlBody",
"!==",
"''",
")",
"{",
"$",
"tmp",
"=",
"$",
"cursor",
"->",
"setContentType",
"(",
"'multipart/alternative'",
")",
";",
"$",
"cursor",
"=",
"$",
"cursor",
"->",
"addPart",
"(",
")",
";",
"$",
"alt",
"=",
"$",
"tmp",
"->",
"addPart",
"(",
")",
";",
"if",
"(",
"$",
"mail",
"->",
"inlines",
")",
"{",
"$",
"tmp",
"=",
"$",
"alt",
"->",
"setContentType",
"(",
"'multipart/related'",
")",
";",
"$",
"alt",
"=",
"$",
"alt",
"->",
"addPart",
"(",
")",
";",
"foreach",
"(",
"$",
"mail",
"->",
"inlines",
"as",
"$",
"value",
")",
"{",
"$",
"tmp",
"->",
"addPart",
"(",
"$",
"value",
")",
";",
"}",
"}",
"$",
"alt",
"->",
"setContentType",
"(",
"'text/html'",
",",
"'UTF-8'",
")",
"->",
"setEncoding",
"(",
"\\",
"preg_match",
"(",
"'#[^\\n]{990}#'",
",",
"$",
"mail",
"->",
"htmlBody",
")",
"?",
"self",
"::",
"ENCODING_QUOTED_PRINTABLE",
":",
"(",
"\\",
"preg_match",
"(",
"'#[\\x80-\\xFF]#'",
",",
"$",
"mail",
"->",
"htmlBody",
")",
"?",
"self",
"::",
"ENCODING_8BIT",
":",
"self",
"::",
"ENCODING_7BIT",
")",
")",
"->",
"setBody",
"(",
"$",
"mail",
"->",
"htmlBody",
")",
";",
"}",
"$",
"text",
"=",
"$",
"mail",
"->",
"getBody",
"(",
")",
";",
"$",
"mail",
"->",
"setBody",
"(",
"''",
")",
";",
"$",
"cursor",
"->",
"setContentType",
"(",
"'text/plain'",
",",
"'UTF-8'",
")",
"->",
"setEncoding",
"(",
"\\",
"preg_match",
"(",
"'#[^\\n]{990}#'",
",",
"$",
"text",
")",
"?",
"self",
"::",
"ENCODING_QUOTED_PRINTABLE",
":",
"(",
"\\",
"preg_match",
"(",
"'#[\\x80-\\xFF]#'",
",",
"$",
"text",
")",
"?",
"self",
"::",
"ENCODING_8BIT",
":",
"self",
"::",
"ENCODING_7BIT",
")",
")",
"->",
"setBody",
"(",
"$",
"text",
")",
";",
"return",
"$",
"mail",
";",
"}"
] | Builds email. Does not modify itself, but returns a new object.
@return static | [
"Builds",
"email",
".",
"Does",
"not",
"modify",
"itself",
"but",
"returns",
"a",
"new",
"object",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Mail/Message.php#L415-L456 |
35,264 | hail-framework/framework | src/Mail/Message.php | Message.buildText | protected function buildText(string $html): string
{
$text = Strings::replace($html, [
'#<(style|script|head).*</\\1>#Uis' => '',
'#<t[dh][ >]#i' => ' $0',
'#<a\s[^>]*href=(?|"([^"]+)"|\'([^\']+)\')[^>]*>(.*?)</a>#is' => '$2 <$1>',
'#[\r\n]+#' => ' ',
'#<(/?p|/?h\d|li|br|/tr)[ >/]#i' => "\n$0",
]);
$text = \html_entity_decode(\strip_tags($text), ENT_QUOTES, 'UTF-8');
$text = Strings::replace($text, '#[ \t]+#', ' ');
return \trim($text);
} | php | protected function buildText(string $html): string
{
$text = Strings::replace($html, [
'#<(style|script|head).*</\\1>#Uis' => '',
'#<t[dh][ >]#i' => ' $0',
'#<a\s[^>]*href=(?|"([^"]+)"|\'([^\']+)\')[^>]*>(.*?)</a>#is' => '$2 <$1>',
'#[\r\n]+#' => ' ',
'#<(/?p|/?h\d|li|br|/tr)[ >/]#i' => "\n$0",
]);
$text = \html_entity_decode(\strip_tags($text), ENT_QUOTES, 'UTF-8');
$text = Strings::replace($text, '#[ \t]+#', ' ');
return \trim($text);
} | [
"protected",
"function",
"buildText",
"(",
"string",
"$",
"html",
")",
":",
"string",
"{",
"$",
"text",
"=",
"Strings",
"::",
"replace",
"(",
"$",
"html",
",",
"[",
"'#<(style|script|head).*</\\\\1>#Uis'",
"=>",
"''",
",",
"'#<t[dh][ >]#i'",
"=>",
"' $0'",
",",
"'#<a\\s[^>]*href=(?|\"([^\"]+)\"|\\'([^\\']+)\\')[^>]*>(.*?)</a>#is'",
"=>",
"'$2 <$1>'",
",",
"'#[\\r\\n]+#'",
"=>",
"' '",
",",
"'#<(/?p|/?h\\d|li|br|/tr)[ >/]#i'",
"=>",
"\"\\n$0\"",
",",
"]",
")",
";",
"$",
"text",
"=",
"\\",
"html_entity_decode",
"(",
"\\",
"strip_tags",
"(",
"$",
"text",
")",
",",
"ENT_QUOTES",
",",
"'UTF-8'",
")",
";",
"$",
"text",
"=",
"Strings",
"::",
"replace",
"(",
"$",
"text",
",",
"'#[ \\t]+#'",
",",
"' '",
")",
";",
"return",
"\\",
"trim",
"(",
"$",
"text",
")",
";",
"}"
] | Builds text content.
@param string $html
@return string
@throws RegexpException | [
"Builds",
"text",
"content",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Mail/Message.php#L467-L480 |
35,265 | hail-framework/framework | src/Mail/MimePart.php | MimePart.getEncodedHeader | public function getEncodedHeader(string $name): ?string
{
$offset = \strlen($name) + 2; // colon + space
if (!isset($this->headers[$name])) {
return null;
}
if (\is_array($this->headers[$name])) {
$s = '';
foreach ($this->headers[$name] as $email => $mailer) {
if ($mailer != null) { // intentionally ==
$s .= self::encodeHeader($mailer, $offset, true);
$email = " <$email>";
}
$s .= self::append($email . ',', $offset);
}
return \ltrim(\substr($s, 0, -1)); // last comma
}
if (\preg_match('#^(\S+; (?:file)?name=)"(.*)"\z#', $this->headers[$name], $m)) { // Content-Disposition
$offset += \strlen($m[1]);
return $m[1] . '"' . self::encodeHeader($m[2], $offset) . '"';
}
return \ltrim(self::encodeHeader($this->headers[$name], $offset));
} | php | public function getEncodedHeader(string $name): ?string
{
$offset = \strlen($name) + 2; // colon + space
if (!isset($this->headers[$name])) {
return null;
}
if (\is_array($this->headers[$name])) {
$s = '';
foreach ($this->headers[$name] as $email => $mailer) {
if ($mailer != null) { // intentionally ==
$s .= self::encodeHeader($mailer, $offset, true);
$email = " <$email>";
}
$s .= self::append($email . ',', $offset);
}
return \ltrim(\substr($s, 0, -1)); // last comma
}
if (\preg_match('#^(\S+; (?:file)?name=)"(.*)"\z#', $this->headers[$name], $m)) { // Content-Disposition
$offset += \strlen($m[1]);
return $m[1] . '"' . self::encodeHeader($m[2], $offset) . '"';
}
return \ltrim(self::encodeHeader($this->headers[$name], $offset));
} | [
"public",
"function",
"getEncodedHeader",
"(",
"string",
"$",
"name",
")",
":",
"?",
"string",
"{",
"$",
"offset",
"=",
"\\",
"strlen",
"(",
"$",
"name",
")",
"+",
"2",
";",
"// colon + space",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"this",
"->",
"headers",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"s",
"=",
"''",
";",
"foreach",
"(",
"$",
"this",
"->",
"headers",
"[",
"$",
"name",
"]",
"as",
"$",
"email",
"=>",
"$",
"mailer",
")",
"{",
"if",
"(",
"$",
"mailer",
"!=",
"null",
")",
"{",
"// intentionally ==",
"$",
"s",
".=",
"self",
"::",
"encodeHeader",
"(",
"$",
"mailer",
",",
"$",
"offset",
",",
"true",
")",
";",
"$",
"email",
"=",
"\" <$email>\"",
";",
"}",
"$",
"s",
".=",
"self",
"::",
"append",
"(",
"$",
"email",
".",
"','",
",",
"$",
"offset",
")",
";",
"}",
"return",
"\\",
"ltrim",
"(",
"\\",
"substr",
"(",
"$",
"s",
",",
"0",
",",
"-",
"1",
")",
")",
";",
"// last comma",
"}",
"if",
"(",
"\\",
"preg_match",
"(",
"'#^(\\S+; (?:file)?name=)\"(.*)\"\\z#'",
",",
"$",
"this",
"->",
"headers",
"[",
"$",
"name",
"]",
",",
"$",
"m",
")",
")",
"{",
"// Content-Disposition",
"$",
"offset",
"+=",
"\\",
"strlen",
"(",
"$",
"m",
"[",
"1",
"]",
")",
";",
"return",
"$",
"m",
"[",
"1",
"]",
".",
"'\"'",
".",
"self",
"::",
"encodeHeader",
"(",
"$",
"m",
"[",
"2",
"]",
",",
"$",
"offset",
")",
".",
"'\"'",
";",
"}",
"return",
"\\",
"ltrim",
"(",
"self",
"::",
"encodeHeader",
"(",
"$",
"this",
"->",
"headers",
"[",
"$",
"name",
"]",
",",
"$",
"offset",
")",
")",
";",
"}"
] | Returns an encoded header. | [
"Returns",
"an",
"encoded",
"header",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Mail/MimePart.php#L126-L155 |
35,266 | hail-framework/framework | src/Mail/MimePart.php | MimePart.setContentType | public function setContentType(string $contentType, string $charset = null)
{
$this->setHeader('Content-Type', $contentType . ($charset ? "; charset=$charset" : ''));
return $this;
} | php | public function setContentType(string $contentType, string $charset = null)
{
$this->setHeader('Content-Type', $contentType . ($charset ? "; charset=$charset" : ''));
return $this;
} | [
"public",
"function",
"setContentType",
"(",
"string",
"$",
"contentType",
",",
"string",
"$",
"charset",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"setHeader",
"(",
"'Content-Type'",
",",
"$",
"contentType",
".",
"(",
"$",
"charset",
"?",
"\"; charset=$charset\"",
":",
"''",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Sets Content-Type header.
@return static | [
"Sets",
"Content",
"-",
"Type",
"header",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Mail/MimePart.php#L172-L177 |
35,267 | hail-framework/framework | src/Mail/MimePart.php | MimePart.addPart | public function addPart(self $part = null): self
{
return $this->parts[] = $part === null ? new self : $part;
} | php | public function addPart(self $part = null): self
{
return $this->parts[] = $part === null ? new self : $part;
} | [
"public",
"function",
"addPart",
"(",
"self",
"$",
"part",
"=",
"null",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"parts",
"[",
"]",
"=",
"$",
"part",
"===",
"null",
"?",
"new",
"self",
":",
"$",
"part",
";",
"}"
] | Adds or creates new multipart. | [
"Adds",
"or",
"creates",
"new",
"multipart",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Mail/MimePart.php#L205-L208 |
35,268 | hail-framework/framework | src/Mail/MimePart.php | MimePart.getEncodedMessage | public function getEncodedMessage(): string
{
$output = '';
$boundary = '--------' . Generators::random();
foreach ($this->headers as $name => $value) {
$output .= $name . ': ' . $this->getEncodedHeader($name);
if ($this->parts && $name === 'Content-Type') {
$output .= ';' . self::EOL . "\tboundary=\"$boundary\"";
}
$output .= self::EOL;
}
$output .= self::EOL;
$body = $this->body;
if ($body !== '') {
switch ($this->getEncoding()) {
case self::ENCODING_QUOTED_PRINTABLE:
$output .= \quoted_printable_encode($body);
break;
case self::ENCODING_BASE64:
$output .= \rtrim(\chunk_split(\base64_encode($body), self::LINE_LENGTH, self::EOL));
break;
case self::ENCODING_7BIT:
$body = \preg_replace('#[\x80-\xFF]+#', '', $body);
// break intentionally omitted
case self::ENCODING_8BIT:
$output .= \str_replace(["\x00", "\r", "\n"], ['', '', self::EOL], $body);
break;
default:
throw new RuntimeException('Unknown encoding.');
}
}
if ($this->parts) {
if (\substr($output, -\strlen(self::EOL)) !== self::EOL) {
$output .= self::EOL;
}
foreach ($this->parts as $part) {
$output .= '--' . $boundary . self::EOL . $part->getEncodedMessage() . self::EOL;
}
$output .= '--' . $boundary . '--';
}
return $output;
} | php | public function getEncodedMessage(): string
{
$output = '';
$boundary = '--------' . Generators::random();
foreach ($this->headers as $name => $value) {
$output .= $name . ': ' . $this->getEncodedHeader($name);
if ($this->parts && $name === 'Content-Type') {
$output .= ';' . self::EOL . "\tboundary=\"$boundary\"";
}
$output .= self::EOL;
}
$output .= self::EOL;
$body = $this->body;
if ($body !== '') {
switch ($this->getEncoding()) {
case self::ENCODING_QUOTED_PRINTABLE:
$output .= \quoted_printable_encode($body);
break;
case self::ENCODING_BASE64:
$output .= \rtrim(\chunk_split(\base64_encode($body), self::LINE_LENGTH, self::EOL));
break;
case self::ENCODING_7BIT:
$body = \preg_replace('#[\x80-\xFF]+#', '', $body);
// break intentionally omitted
case self::ENCODING_8BIT:
$output .= \str_replace(["\x00", "\r", "\n"], ['', '', self::EOL], $body);
break;
default:
throw new RuntimeException('Unknown encoding.');
}
}
if ($this->parts) {
if (\substr($output, -\strlen(self::EOL)) !== self::EOL) {
$output .= self::EOL;
}
foreach ($this->parts as $part) {
$output .= '--' . $boundary . self::EOL . $part->getEncodedMessage() . self::EOL;
}
$output .= '--' . $boundary . '--';
}
return $output;
} | [
"public",
"function",
"getEncodedMessage",
"(",
")",
":",
"string",
"{",
"$",
"output",
"=",
"''",
";",
"$",
"boundary",
"=",
"'--------'",
".",
"Generators",
"::",
"random",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"headers",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"output",
".=",
"$",
"name",
".",
"': '",
".",
"$",
"this",
"->",
"getEncodedHeader",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"this",
"->",
"parts",
"&&",
"$",
"name",
"===",
"'Content-Type'",
")",
"{",
"$",
"output",
".=",
"';'",
".",
"self",
"::",
"EOL",
".",
"\"\\tboundary=\\\"$boundary\\\"\"",
";",
"}",
"$",
"output",
".=",
"self",
"::",
"EOL",
";",
"}",
"$",
"output",
".=",
"self",
"::",
"EOL",
";",
"$",
"body",
"=",
"$",
"this",
"->",
"body",
";",
"if",
"(",
"$",
"body",
"!==",
"''",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"getEncoding",
"(",
")",
")",
"{",
"case",
"self",
"::",
"ENCODING_QUOTED_PRINTABLE",
":",
"$",
"output",
".=",
"\\",
"quoted_printable_encode",
"(",
"$",
"body",
")",
";",
"break",
";",
"case",
"self",
"::",
"ENCODING_BASE64",
":",
"$",
"output",
".=",
"\\",
"rtrim",
"(",
"\\",
"chunk_split",
"(",
"\\",
"base64_encode",
"(",
"$",
"body",
")",
",",
"self",
"::",
"LINE_LENGTH",
",",
"self",
"::",
"EOL",
")",
")",
";",
"break",
";",
"case",
"self",
"::",
"ENCODING_7BIT",
":",
"$",
"body",
"=",
"\\",
"preg_replace",
"(",
"'#[\\x80-\\xFF]+#'",
",",
"''",
",",
"$",
"body",
")",
";",
"// break intentionally omitted",
"case",
"self",
"::",
"ENCODING_8BIT",
":",
"$",
"output",
".=",
"\\",
"str_replace",
"(",
"[",
"\"\\x00\"",
",",
"\"\\r\"",
",",
"\"\\n\"",
"]",
",",
"[",
"''",
",",
"''",
",",
"self",
"::",
"EOL",
"]",
",",
"$",
"body",
")",
";",
"break",
";",
"default",
":",
"throw",
"new",
"RuntimeException",
"(",
"'Unknown encoding.'",
")",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"parts",
")",
"{",
"if",
"(",
"\\",
"substr",
"(",
"$",
"output",
",",
"-",
"\\",
"strlen",
"(",
"self",
"::",
"EOL",
")",
")",
"!==",
"self",
"::",
"EOL",
")",
"{",
"$",
"output",
".=",
"self",
"::",
"EOL",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"parts",
"as",
"$",
"part",
")",
"{",
"$",
"output",
".=",
"'--'",
".",
"$",
"boundary",
".",
"self",
"::",
"EOL",
".",
"$",
"part",
"->",
"getEncodedMessage",
"(",
")",
".",
"self",
"::",
"EOL",
";",
"}",
"$",
"output",
".=",
"'--'",
".",
"$",
"boundary",
".",
"'--'",
";",
"}",
"return",
"$",
"output",
";",
"}"
] | Returns encoded message. | [
"Returns",
"encoded",
"message",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Mail/MimePart.php#L239-L288 |
35,269 | hail-framework/framework | src/Mail/MimePart.php | MimePart.encodeHeader | private static function encodeHeader(string $s, int &$offset = 0, bool $quotes = false): string
{
if (\strspn($s,
"!\"#$%&\'()*+,-./0123456789:;<>@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^`abcdefghijklmnopqrstuvwxyz{|}~=? _\r\n\t") === \strlen($s)) {
if ($quotes && \preg_match('#[^ a-zA-Z0-9!\#$%&\'*+/?^_`{|}~-]#', $s)) { // RFC 2822 atext except =
return self::append('"' . \addcslashes($s, '"\\') . '"', $offset);
}
return self::append($s, $offset);
}
$o = '';
if ($offset >= 55) { // maximum for iconv_mime_encode
$o = self::EOL . "\t";
$offset = 1;
}
$filed = \str_repeat(' ', $old = $offset);
if (\function_exists('\iconv_mime_encode')) {
$s = \iconv_mime_encode($filed, $s, [
'scheme' => 'B', // Q is broken
'input-charset' => 'UTF-8',
'output-charset' => 'UTF-8',
]);
} else {
$s = $filed . ': ' . \mb_encode_mimeheader($s, 'UTF-8', 'B');
}
$offset = \strlen($s) - \strrpos($s, "\n");
$s = \str_replace("\n ", "\n\t", \substr($s, $old + 2)); // adds ': '
return $o . $s;
} | php | private static function encodeHeader(string $s, int &$offset = 0, bool $quotes = false): string
{
if (\strspn($s,
"!\"#$%&\'()*+,-./0123456789:;<>@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^`abcdefghijklmnopqrstuvwxyz{|}~=? _\r\n\t") === \strlen($s)) {
if ($quotes && \preg_match('#[^ a-zA-Z0-9!\#$%&\'*+/?^_`{|}~-]#', $s)) { // RFC 2822 atext except =
return self::append('"' . \addcslashes($s, '"\\') . '"', $offset);
}
return self::append($s, $offset);
}
$o = '';
if ($offset >= 55) { // maximum for iconv_mime_encode
$o = self::EOL . "\t";
$offset = 1;
}
$filed = \str_repeat(' ', $old = $offset);
if (\function_exists('\iconv_mime_encode')) {
$s = \iconv_mime_encode($filed, $s, [
'scheme' => 'B', // Q is broken
'input-charset' => 'UTF-8',
'output-charset' => 'UTF-8',
]);
} else {
$s = $filed . ': ' . \mb_encode_mimeheader($s, 'UTF-8', 'B');
}
$offset = \strlen($s) - \strrpos($s, "\n");
$s = \str_replace("\n ", "\n\t", \substr($s, $old + 2)); // adds ': '
return $o . $s;
} | [
"private",
"static",
"function",
"encodeHeader",
"(",
"string",
"$",
"s",
",",
"int",
"&",
"$",
"offset",
"=",
"0",
",",
"bool",
"$",
"quotes",
"=",
"false",
")",
":",
"string",
"{",
"if",
"(",
"\\",
"strspn",
"(",
"$",
"s",
",",
"\"!\\\"#$%&\\'()*+,-./0123456789:;<>@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^`abcdefghijklmnopqrstuvwxyz{|}~=? _\\r\\n\\t\"",
")",
"===",
"\\",
"strlen",
"(",
"$",
"s",
")",
")",
"{",
"if",
"(",
"$",
"quotes",
"&&",
"\\",
"preg_match",
"(",
"'#[^ a-zA-Z0-9!\\#$%&\\'*+/?^_`{|}~-]#'",
",",
"$",
"s",
")",
")",
"{",
"// RFC 2822 atext except =",
"return",
"self",
"::",
"append",
"(",
"'\"'",
".",
"\\",
"addcslashes",
"(",
"$",
"s",
",",
"'\"\\\\'",
")",
".",
"'\"'",
",",
"$",
"offset",
")",
";",
"}",
"return",
"self",
"::",
"append",
"(",
"$",
"s",
",",
"$",
"offset",
")",
";",
"}",
"$",
"o",
"=",
"''",
";",
"if",
"(",
"$",
"offset",
">=",
"55",
")",
"{",
"// maximum for iconv_mime_encode",
"$",
"o",
"=",
"self",
"::",
"EOL",
".",
"\"\\t\"",
";",
"$",
"offset",
"=",
"1",
";",
"}",
"$",
"filed",
"=",
"\\",
"str_repeat",
"(",
"' '",
",",
"$",
"old",
"=",
"$",
"offset",
")",
";",
"if",
"(",
"\\",
"function_exists",
"(",
"'\\iconv_mime_encode'",
")",
")",
"{",
"$",
"s",
"=",
"\\",
"iconv_mime_encode",
"(",
"$",
"filed",
",",
"$",
"s",
",",
"[",
"'scheme'",
"=>",
"'B'",
",",
"// Q is broken",
"'input-charset'",
"=>",
"'UTF-8'",
",",
"'output-charset'",
"=>",
"'UTF-8'",
",",
"]",
")",
";",
"}",
"else",
"{",
"$",
"s",
"=",
"$",
"filed",
".",
"': '",
".",
"\\",
"mb_encode_mimeheader",
"(",
"$",
"s",
",",
"'UTF-8'",
",",
"'B'",
")",
";",
"}",
"$",
"offset",
"=",
"\\",
"strlen",
"(",
"$",
"s",
")",
"-",
"\\",
"strrpos",
"(",
"$",
"s",
",",
"\"\\n\"",
")",
";",
"$",
"s",
"=",
"\\",
"str_replace",
"(",
"\"\\n \"",
",",
"\"\\n\\t\"",
",",
"\\",
"substr",
"(",
"$",
"s",
",",
"$",
"old",
"+",
"2",
")",
")",
";",
"// adds ': '",
"return",
"$",
"o",
".",
"$",
"s",
";",
"}"
] | Converts a 8 bit header to a string. | [
"Converts",
"a",
"8",
"bit",
"header",
"to",
"a",
"string",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Mail/MimePart.php#L297-L329 |
35,270 | hail-framework/framework | src/Debugger/Dumper.php | Dumper.dump | public static function dump($var, array $options = null)
{
if (Helpers::isHtmlMode()) {
echo self::toHtml($var, $options);
} elseif (self::detectColors()) {
echo self::toTerminal($var, $options);
} else {
echo self::toText($var, $options);
}
return $var;
} | php | public static function dump($var, array $options = null)
{
if (Helpers::isHtmlMode()) {
echo self::toHtml($var, $options);
} elseif (self::detectColors()) {
echo self::toTerminal($var, $options);
} else {
echo self::toText($var, $options);
}
return $var;
} | [
"public",
"static",
"function",
"dump",
"(",
"$",
"var",
",",
"array",
"$",
"options",
"=",
"null",
")",
"{",
"if",
"(",
"Helpers",
"::",
"isHtmlMode",
"(",
")",
")",
"{",
"echo",
"self",
"::",
"toHtml",
"(",
"$",
"var",
",",
"$",
"options",
")",
";",
"}",
"elseif",
"(",
"self",
"::",
"detectColors",
"(",
")",
")",
"{",
"echo",
"self",
"::",
"toTerminal",
"(",
"$",
"var",
",",
"$",
"options",
")",
";",
"}",
"else",
"{",
"echo",
"self",
"::",
"toText",
"(",
"$",
"var",
",",
"$",
"options",
")",
";",
"}",
"return",
"$",
"var",
";",
"}"
] | Dumps variable to the output.
@param mixed $var
@param array|null $options
@return mixed variable | [
"Dumps",
"variable",
"to",
"the",
"output",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Dumper.php#L79-L90 |
35,271 | hail-framework/framework | src/Debugger/Dumper.php | Dumper.toHtml | public static function toHtml($var, array $options = null): string
{
$options += [
self::DEPTH => 4,
self::TRUNCATE => 150,
self::COLLAPSE => 14,
self::COLLAPSE_COUNT => 7,
self::OBJECT_EXPORTERS => null,
self::DEBUGINFO => false,
self::KEYS_TO_HIDE => [],
];
$loc = &$options[self::LOCATION];
$loc = $loc === true ? ~0 : (int) $loc;
$options[self::KEYS_TO_HIDE] = \array_flip(\array_map('\\strtolower', $options[self::KEYS_TO_HIDE]));
$options[self::OBJECT_EXPORTERS] = (array) $options[self::OBJECT_EXPORTERS] + self::$objectExporters;
\uksort($options[self::OBJECT_EXPORTERS], function ($a, $b): int {
return $b === '' || (\class_exists($a, false) && \is_subclass_of($a, $b)) ? -1 : 1;
});
$live = !empty($options[self::LIVE]) && $var && (\is_array($var) || \is_object($var) || \is_resource($var));
[$file, $line, $code] = $loc ? self::findLocation() : null;
$locAttrs = $file && $loc & self::LOCATION_SOURCE ? Helpers::formatHtml(
' title="%in file % on line %" data-tracy-href="%"', "$code\n", $file, $line,
Helpers::editorUri($file, $line)
) : null;
return '<pre class="tracy-dump' . ($live && $options[self::COLLAPSE] === true ? ' tracy-collapsed' : '') . '"'
. $locAttrs
. ($live ? " data-tracy-dump='" . \json_encode(self::toJson($var, $options),
JSON_HEX_APOS | JSON_HEX_AMP) . "'>" : '>')
. ($live ? '' : self::dumpVar($var, $options))
. ($file && $loc & self::LOCATION_LINK ? '<small>in ' . Helpers::editorLink($file, $line) . '</small>' : '')
. "</pre>\n";
} | php | public static function toHtml($var, array $options = null): string
{
$options += [
self::DEPTH => 4,
self::TRUNCATE => 150,
self::COLLAPSE => 14,
self::COLLAPSE_COUNT => 7,
self::OBJECT_EXPORTERS => null,
self::DEBUGINFO => false,
self::KEYS_TO_HIDE => [],
];
$loc = &$options[self::LOCATION];
$loc = $loc === true ? ~0 : (int) $loc;
$options[self::KEYS_TO_HIDE] = \array_flip(\array_map('\\strtolower', $options[self::KEYS_TO_HIDE]));
$options[self::OBJECT_EXPORTERS] = (array) $options[self::OBJECT_EXPORTERS] + self::$objectExporters;
\uksort($options[self::OBJECT_EXPORTERS], function ($a, $b): int {
return $b === '' || (\class_exists($a, false) && \is_subclass_of($a, $b)) ? -1 : 1;
});
$live = !empty($options[self::LIVE]) && $var && (\is_array($var) || \is_object($var) || \is_resource($var));
[$file, $line, $code] = $loc ? self::findLocation() : null;
$locAttrs = $file && $loc & self::LOCATION_SOURCE ? Helpers::formatHtml(
' title="%in file % on line %" data-tracy-href="%"', "$code\n", $file, $line,
Helpers::editorUri($file, $line)
) : null;
return '<pre class="tracy-dump' . ($live && $options[self::COLLAPSE] === true ? ' tracy-collapsed' : '') . '"'
. $locAttrs
. ($live ? " data-tracy-dump='" . \json_encode(self::toJson($var, $options),
JSON_HEX_APOS | JSON_HEX_AMP) . "'>" : '>')
. ($live ? '' : self::dumpVar($var, $options))
. ($file && $loc & self::LOCATION_LINK ? '<small>in ' . Helpers::editorLink($file, $line) . '</small>' : '')
. "</pre>\n";
} | [
"public",
"static",
"function",
"toHtml",
"(",
"$",
"var",
",",
"array",
"$",
"options",
"=",
"null",
")",
":",
"string",
"{",
"$",
"options",
"+=",
"[",
"self",
"::",
"DEPTH",
"=>",
"4",
",",
"self",
"::",
"TRUNCATE",
"=>",
"150",
",",
"self",
"::",
"COLLAPSE",
"=>",
"14",
",",
"self",
"::",
"COLLAPSE_COUNT",
"=>",
"7",
",",
"self",
"::",
"OBJECT_EXPORTERS",
"=>",
"null",
",",
"self",
"::",
"DEBUGINFO",
"=>",
"false",
",",
"self",
"::",
"KEYS_TO_HIDE",
"=>",
"[",
"]",
",",
"]",
";",
"$",
"loc",
"=",
"&",
"$",
"options",
"[",
"self",
"::",
"LOCATION",
"]",
";",
"$",
"loc",
"=",
"$",
"loc",
"===",
"true",
"?",
"~",
"0",
":",
"(",
"int",
")",
"$",
"loc",
";",
"$",
"options",
"[",
"self",
"::",
"KEYS_TO_HIDE",
"]",
"=",
"\\",
"array_flip",
"(",
"\\",
"array_map",
"(",
"'\\\\strtolower'",
",",
"$",
"options",
"[",
"self",
"::",
"KEYS_TO_HIDE",
"]",
")",
")",
";",
"$",
"options",
"[",
"self",
"::",
"OBJECT_EXPORTERS",
"]",
"=",
"(",
"array",
")",
"$",
"options",
"[",
"self",
"::",
"OBJECT_EXPORTERS",
"]",
"+",
"self",
"::",
"$",
"objectExporters",
";",
"\\",
"uksort",
"(",
"$",
"options",
"[",
"self",
"::",
"OBJECT_EXPORTERS",
"]",
",",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
":",
"int",
"{",
"return",
"$",
"b",
"===",
"''",
"||",
"(",
"\\",
"class_exists",
"(",
"$",
"a",
",",
"false",
")",
"&&",
"\\",
"is_subclass_of",
"(",
"$",
"a",
",",
"$",
"b",
")",
")",
"?",
"-",
"1",
":",
"1",
";",
"}",
")",
";",
"$",
"live",
"=",
"!",
"empty",
"(",
"$",
"options",
"[",
"self",
"::",
"LIVE",
"]",
")",
"&&",
"$",
"var",
"&&",
"(",
"\\",
"is_array",
"(",
"$",
"var",
")",
"||",
"\\",
"is_object",
"(",
"$",
"var",
")",
"||",
"\\",
"is_resource",
"(",
"$",
"var",
")",
")",
";",
"[",
"$",
"file",
",",
"$",
"line",
",",
"$",
"code",
"]",
"=",
"$",
"loc",
"?",
"self",
"::",
"findLocation",
"(",
")",
":",
"null",
";",
"$",
"locAttrs",
"=",
"$",
"file",
"&&",
"$",
"loc",
"&",
"self",
"::",
"LOCATION_SOURCE",
"?",
"Helpers",
"::",
"formatHtml",
"(",
"' title=\"%in file % on line %\" data-tracy-href=\"%\"'",
",",
"\"$code\\n\"",
",",
"$",
"file",
",",
"$",
"line",
",",
"Helpers",
"::",
"editorUri",
"(",
"$",
"file",
",",
"$",
"line",
")",
")",
":",
"null",
";",
"return",
"'<pre class=\"tracy-dump'",
".",
"(",
"$",
"live",
"&&",
"$",
"options",
"[",
"self",
"::",
"COLLAPSE",
"]",
"===",
"true",
"?",
"' tracy-collapsed'",
":",
"''",
")",
".",
"'\"'",
".",
"$",
"locAttrs",
".",
"(",
"$",
"live",
"?",
"\" data-tracy-dump='\"",
".",
"\\",
"json_encode",
"(",
"self",
"::",
"toJson",
"(",
"$",
"var",
",",
"$",
"options",
")",
",",
"JSON_HEX_APOS",
"|",
"JSON_HEX_AMP",
")",
".",
"\"'>\"",
":",
"'>'",
")",
".",
"(",
"$",
"live",
"?",
"''",
":",
"self",
"::",
"dumpVar",
"(",
"$",
"var",
",",
"$",
"options",
")",
")",
".",
"(",
"$",
"file",
"&&",
"$",
"loc",
"&",
"self",
"::",
"LOCATION_LINK",
"?",
"'<small>in '",
".",
"Helpers",
"::",
"editorLink",
"(",
"$",
"file",
",",
"$",
"line",
")",
".",
"'</small>'",
":",
"''",
")",
".",
"\"</pre>\\n\"",
";",
"}"
] | Dumps variable to HTML.
@return string | [
"Dumps",
"variable",
"to",
"HTML",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Dumper.php#L98-L132 |
35,272 | hail-framework/framework | src/Debugger/Dumper.php | Dumper.toText | public static function toText($var, array $options = null): string
{
return \htmlspecialchars_decode(\strip_tags(self::toHtml($var, $options)), ENT_QUOTES);
} | php | public static function toText($var, array $options = null): string
{
return \htmlspecialchars_decode(\strip_tags(self::toHtml($var, $options)), ENT_QUOTES);
} | [
"public",
"static",
"function",
"toText",
"(",
"$",
"var",
",",
"array",
"$",
"options",
"=",
"null",
")",
":",
"string",
"{",
"return",
"\\",
"htmlspecialchars_decode",
"(",
"\\",
"strip_tags",
"(",
"self",
"::",
"toHtml",
"(",
"$",
"var",
",",
"$",
"options",
")",
")",
",",
"ENT_QUOTES",
")",
";",
"}"
] | Dumps variable to plain text.
@return string | [
"Dumps",
"variable",
"to",
"plain",
"text",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Dumper.php#L140-L143 |
35,273 | hail-framework/framework | src/Debugger/Dumper.php | Dumper.toTerminal | public static function toTerminal($var, array $options = null): string
{
return \htmlspecialchars_decode(\strip_tags(\preg_replace_callback('#<span class="tracy-dump-(\w+)">|</span>#',
function ($m) {
return "\033[" . (isset($m[1], self::$terminalColors[$m[1]]) ? self::$terminalColors[$m[1]] : '0') . 'm';
}, self::toHtml($var, $options))), ENT_QUOTES);
} | php | public static function toTerminal($var, array $options = null): string
{
return \htmlspecialchars_decode(\strip_tags(\preg_replace_callback('#<span class="tracy-dump-(\w+)">|</span>#',
function ($m) {
return "\033[" . (isset($m[1], self::$terminalColors[$m[1]]) ? self::$terminalColors[$m[1]] : '0') . 'm';
}, self::toHtml($var, $options))), ENT_QUOTES);
} | [
"public",
"static",
"function",
"toTerminal",
"(",
"$",
"var",
",",
"array",
"$",
"options",
"=",
"null",
")",
":",
"string",
"{",
"return",
"\\",
"htmlspecialchars_decode",
"(",
"\\",
"strip_tags",
"(",
"\\",
"preg_replace_callback",
"(",
"'#<span class=\"tracy-dump-(\\w+)\">|</span>#'",
",",
"function",
"(",
"$",
"m",
")",
"{",
"return",
"\"\\033[\"",
".",
"(",
"isset",
"(",
"$",
"m",
"[",
"1",
"]",
",",
"self",
"::",
"$",
"terminalColors",
"[",
"$",
"m",
"[",
"1",
"]",
"]",
")",
"?",
"self",
"::",
"$",
"terminalColors",
"[",
"$",
"m",
"[",
"1",
"]",
"]",
":",
"'0'",
")",
".",
"'m'",
";",
"}",
",",
"self",
"::",
"toHtml",
"(",
"$",
"var",
",",
"$",
"options",
")",
")",
")",
",",
"ENT_QUOTES",
")",
";",
"}"
] | Dumps variable to x-terminal.
@return string | [
"Dumps",
"variable",
"to",
"x",
"-",
"terminal",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Dumper.php#L151-L157 |
35,274 | hail-framework/framework | src/Debugger/Dumper.php | Dumper.findLocation | private static function findLocation(): ?array
{
foreach (\debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) as $item) {
if (isset($item['class']) && $item['class'] === __CLASS__) {
$location = $item;
continue;
}
if (isset($item['function'])) {
try {
$reflection = isset($item['class'])
? new \ReflectionMethod($item['class'], $item['function'])
: new \ReflectionFunction($item['function']);
if ($reflection->isInternal() || \preg_match('#\s@tracySkipLocation\s#',
(string) $reflection->getDocComment())) {
$location = $item;
continue;
}
} catch (\ReflectionException $e) {
}
}
break;
}
if (isset($location['file'], $location['line']) && \is_file($location['file'])) {
$lines = \file($location['file']);
$line = $lines[$location['line'] - 1];
return [
$location['file'],
$location['line'],
\trim(\preg_match('#\w*dump(er::\w+)?\(.*\)#i', $line, $m) ? $m[0] : $line),
];
}
return null;
} | php | private static function findLocation(): ?array
{
foreach (\debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) as $item) {
if (isset($item['class']) && $item['class'] === __CLASS__) {
$location = $item;
continue;
}
if (isset($item['function'])) {
try {
$reflection = isset($item['class'])
? new \ReflectionMethod($item['class'], $item['function'])
: new \ReflectionFunction($item['function']);
if ($reflection->isInternal() || \preg_match('#\s@tracySkipLocation\s#',
(string) $reflection->getDocComment())) {
$location = $item;
continue;
}
} catch (\ReflectionException $e) {
}
}
break;
}
if (isset($location['file'], $location['line']) && \is_file($location['file'])) {
$lines = \file($location['file']);
$line = $lines[$location['line'] - 1];
return [
$location['file'],
$location['line'],
\trim(\preg_match('#\w*dump(er::\w+)?\(.*\)#i', $line, $m) ? $m[0] : $line),
];
}
return null;
} | [
"private",
"static",
"function",
"findLocation",
"(",
")",
":",
"?",
"array",
"{",
"foreach",
"(",
"\\",
"debug_backtrace",
"(",
"DEBUG_BACKTRACE_IGNORE_ARGS",
")",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"item",
"[",
"'class'",
"]",
")",
"&&",
"$",
"item",
"[",
"'class'",
"]",
"===",
"__CLASS__",
")",
"{",
"$",
"location",
"=",
"$",
"item",
";",
"continue",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"item",
"[",
"'function'",
"]",
")",
")",
"{",
"try",
"{",
"$",
"reflection",
"=",
"isset",
"(",
"$",
"item",
"[",
"'class'",
"]",
")",
"?",
"new",
"\\",
"ReflectionMethod",
"(",
"$",
"item",
"[",
"'class'",
"]",
",",
"$",
"item",
"[",
"'function'",
"]",
")",
":",
"new",
"\\",
"ReflectionFunction",
"(",
"$",
"item",
"[",
"'function'",
"]",
")",
";",
"if",
"(",
"$",
"reflection",
"->",
"isInternal",
"(",
")",
"||",
"\\",
"preg_match",
"(",
"'#\\s@tracySkipLocation\\s#'",
",",
"(",
"string",
")",
"$",
"reflection",
"->",
"getDocComment",
"(",
")",
")",
")",
"{",
"$",
"location",
"=",
"$",
"item",
";",
"continue",
";",
"}",
"}",
"catch",
"(",
"\\",
"ReflectionException",
"$",
"e",
")",
"{",
"}",
"}",
"break",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"location",
"[",
"'file'",
"]",
",",
"$",
"location",
"[",
"'line'",
"]",
")",
"&&",
"\\",
"is_file",
"(",
"$",
"location",
"[",
"'file'",
"]",
")",
")",
"{",
"$",
"lines",
"=",
"\\",
"file",
"(",
"$",
"location",
"[",
"'file'",
"]",
")",
";",
"$",
"line",
"=",
"$",
"lines",
"[",
"$",
"location",
"[",
"'line'",
"]",
"-",
"1",
"]",
";",
"return",
"[",
"$",
"location",
"[",
"'file'",
"]",
",",
"$",
"location",
"[",
"'line'",
"]",
",",
"\\",
"trim",
"(",
"\\",
"preg_match",
"(",
"'#\\w*dump(er::\\w+)?\\(.*\\)#i'",
",",
"$",
"line",
",",
"$",
"m",
")",
"?",
"$",
"m",
"[",
"0",
"]",
":",
"$",
"line",
")",
",",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Finds the location where dump was called.
@return array|null [file, line, code] | [
"Finds",
"the",
"location",
"where",
"dump",
"was",
"called",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Dumper.php#L573-L609 |
35,275 | hail-framework/framework | src/Console/Option/Option.php | Option.renderReadableSpec | public function renderReadableSpec($renderHint = true)
{
$c1 = '';
if ($this->short) {
$c1 = '-' . $this->short;
}
if ($this->long) {
if ($c1 !== '') {
$c1 .= ', ';
}
$c1 .= '--' . $this->long;
}
if ($renderHint) {
return $c1 . $this->renderValueHint();
}
return $c1;
} | php | public function renderReadableSpec($renderHint = true)
{
$c1 = '';
if ($this->short) {
$c1 = '-' . $this->short;
}
if ($this->long) {
if ($c1 !== '') {
$c1 .= ', ';
}
$c1 .= '--' . $this->long;
}
if ($renderHint) {
return $c1 . $this->renderValueHint();
}
return $c1;
} | [
"public",
"function",
"renderReadableSpec",
"(",
"$",
"renderHint",
"=",
"true",
")",
"{",
"$",
"c1",
"=",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"short",
")",
"{",
"$",
"c1",
"=",
"'-'",
".",
"$",
"this",
"->",
"short",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"long",
")",
"{",
"if",
"(",
"$",
"c1",
"!==",
"''",
")",
"{",
"$",
"c1",
".=",
"', '",
";",
"}",
"$",
"c1",
".=",
"'--'",
".",
"$",
"this",
"->",
"long",
";",
"}",
"if",
"(",
"$",
"renderHint",
")",
"{",
"return",
"$",
"c1",
".",
"$",
"this",
"->",
"renderValueHint",
"(",
")",
";",
"}",
"return",
"$",
"c1",
";",
"}"
] | get readable spec for printing.
@param bool $renderHint render also value hint
@return string | [
"get",
"readable",
"spec",
"for",
"printing",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/Option/Option.php#L409-L429 |
35,276 | hail-framework/framework | src/Filesystem/Adapter/Fallback.php | Fallback.portFromFallback | private function portFromFallback($path, $newpath)
{
$buffer = $this->fallback->readStream($path);
if (false === $buffer) {
return false;
}
$result = $this->mainAdapter->writeStream($newpath, $buffer['stream'], []);
if (\is_resource($buffer['stream'])) {
\fclose($buffer['stream']);
}
return (false !== $result);
} | php | private function portFromFallback($path, $newpath)
{
$buffer = $this->fallback->readStream($path);
if (false === $buffer) {
return false;
}
$result = $this->mainAdapter->writeStream($newpath, $buffer['stream'], []);
if (\is_resource($buffer['stream'])) {
\fclose($buffer['stream']);
}
return (false !== $result);
} | [
"private",
"function",
"portFromFallback",
"(",
"$",
"path",
",",
"$",
"newpath",
")",
"{",
"$",
"buffer",
"=",
"$",
"this",
"->",
"fallback",
"->",
"readStream",
"(",
"$",
"path",
")",
";",
"if",
"(",
"false",
"===",
"$",
"buffer",
")",
"{",
"return",
"false",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"mainAdapter",
"->",
"writeStream",
"(",
"$",
"newpath",
",",
"$",
"buffer",
"[",
"'stream'",
"]",
",",
"[",
"]",
")",
";",
"if",
"(",
"\\",
"is_resource",
"(",
"$",
"buffer",
"[",
"'stream'",
"]",
")",
")",
"{",
"\\",
"fclose",
"(",
"$",
"buffer",
"[",
"'stream'",
"]",
")",
";",
"}",
"return",
"(",
"false",
"!==",
"$",
"result",
")",
";",
"}"
] | Copies a resource accessible through the fallback adapter to the filesystem abstracted with the main adapter.
@param $path
@return bool | [
"Copies",
"a",
"resource",
"accessible",
"through",
"the",
"fallback",
"adapter",
"to",
"the",
"filesystem",
"abstracted",
"with",
"the",
"main",
"adapter",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Filesystem/Adapter/Fallback.php#L351-L366 |
35,277 | hail-framework/framework | src/Http/Response.php | Response.template | public function template($name, array $params = []): ResponseInterface
{
if (\is_array($name)) {
$params = $name;
$name = null;
}
if ($name === null) {
$handler = $this->app->handler();
if ($handler instanceof \Closure) {
throw new \LogicException('Con not build the template from closure handler!');
}
$name = \ltrim($handler['app'] . '/' . $handler['controller'] . '/' . $handler['action'], '/');
} elseif (!\is_string($name)) {
throw new \InvalidArgumentException('Template name not found!');
}
$response = $this->response();
return $this->app->render($response, $name, $params);
} | php | public function template($name, array $params = []): ResponseInterface
{
if (\is_array($name)) {
$params = $name;
$name = null;
}
if ($name === null) {
$handler = $this->app->handler();
if ($handler instanceof \Closure) {
throw new \LogicException('Con not build the template from closure handler!');
}
$name = \ltrim($handler['app'] . '/' . $handler['controller'] . '/' . $handler['action'], '/');
} elseif (!\is_string($name)) {
throw new \InvalidArgumentException('Template name not found!');
}
$response = $this->response();
return $this->app->render($response, $name, $params);
} | [
"public",
"function",
"template",
"(",
"$",
"name",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
":",
"ResponseInterface",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"name",
")",
")",
"{",
"$",
"params",
"=",
"$",
"name",
";",
"$",
"name",
"=",
"null",
";",
"}",
"if",
"(",
"$",
"name",
"===",
"null",
")",
"{",
"$",
"handler",
"=",
"$",
"this",
"->",
"app",
"->",
"handler",
"(",
")",
";",
"if",
"(",
"$",
"handler",
"instanceof",
"\\",
"Closure",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Con not build the template from closure handler!'",
")",
";",
"}",
"$",
"name",
"=",
"\\",
"ltrim",
"(",
"$",
"handler",
"[",
"'app'",
"]",
".",
"'/'",
".",
"$",
"handler",
"[",
"'controller'",
"]",
".",
"'/'",
".",
"$",
"handler",
"[",
"'action'",
"]",
",",
"'/'",
")",
";",
"}",
"elseif",
"(",
"!",
"\\",
"is_string",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Template name not found!'",
")",
";",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"response",
"(",
")",
";",
"return",
"$",
"this",
"->",
"app",
"->",
"render",
"(",
"$",
"response",
",",
"$",
"name",
",",
"$",
"params",
")",
";",
"}"
] | Get or set template name
@param string|array|null $name
@param array $params
@return ResponseInterface
@throws \InvalidArgumentException
@throws \LogicException | [
"Get",
"or",
"set",
"template",
"name"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Http/Response.php#L264-L285 |
35,278 | hail-framework/framework | src/Http/Response.php | Response.setDate | public function setDate(\DateTime $date): self
{
$date->setTimezone(new \DateTimeZone('UTC'));
$this->header->set('Date', $date->format('D, d M Y H:i:s') . ' GMT');
return $this;
} | php | public function setDate(\DateTime $date): self
{
$date->setTimezone(new \DateTimeZone('UTC'));
$this->header->set('Date', $date->format('D, d M Y H:i:s') . ' GMT');
return $this;
} | [
"public",
"function",
"setDate",
"(",
"\\",
"DateTime",
"$",
"date",
")",
":",
"self",
"{",
"$",
"date",
"->",
"setTimezone",
"(",
"new",
"\\",
"DateTimeZone",
"(",
"'UTC'",
")",
")",
";",
"$",
"this",
"->",
"header",
"->",
"set",
"(",
"'Date'",
",",
"$",
"date",
"->",
"format",
"(",
"'D, d M Y H:i:s'",
")",
".",
"' GMT'",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the Date header.
@param \DateTime $date A \DateTime instance
@return $this | [
"Sets",
"the",
"Date",
"header",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Http/Response.php#L686-L692 |
35,279 | hail-framework/framework | src/Http/Response.php | Response.setTtl | public function setTtl(int $seconds): self
{
$this->setSharedMaxAge($this->getAge() + $seconds);
return $this;
} | php | public function setTtl(int $seconds): self
{
$this->setSharedMaxAge($this->getAge() + $seconds);
return $this;
} | [
"public",
"function",
"setTtl",
"(",
"int",
"$",
"seconds",
")",
":",
"self",
"{",
"$",
"this",
"->",
"setSharedMaxAge",
"(",
"$",
"this",
"->",
"getAge",
"(",
")",
"+",
"$",
"seconds",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the response's time-to-live for shared caches.
This method adjusts the Cache-Control/s-maxage directive.
@param int $seconds Number of seconds
@return $this | [
"Sets",
"the",
"response",
"s",
"time",
"-",
"to",
"-",
"live",
"for",
"shared",
"caches",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Http/Response.php#L911-L916 |
35,280 | hail-framework/framework | src/Console/Option/OptionCollection.php | OptionCollection.addOption | public function addOption(Option $spec)
{
$this->data[$spec->getId()] = $spec;
if ($spec->long) {
if (isset($this->longOptions[$spec->long])) {
throw new OptionConflictException('Option conflict: --' . $spec->long . ' is already defined.');
}
$this->longOptions[$spec->long] = $spec;
}
if ($spec->short) {
if (isset($this->shortOptions[$spec->short])) {
throw new OptionConflictException('Option conflict: -' . $spec->short . ' is already defined.');
}
$this->shortOptions[$spec->short] = $spec;
}
$this->options[] = $spec;
if (!$spec->long && !$spec->short) {
throw new InvalidArgumentException('Neither long option name nor short name is not given.');
}
} | php | public function addOption(Option $spec)
{
$this->data[$spec->getId()] = $spec;
if ($spec->long) {
if (isset($this->longOptions[$spec->long])) {
throw new OptionConflictException('Option conflict: --' . $spec->long . ' is already defined.');
}
$this->longOptions[$spec->long] = $spec;
}
if ($spec->short) {
if (isset($this->shortOptions[$spec->short])) {
throw new OptionConflictException('Option conflict: -' . $spec->short . ' is already defined.');
}
$this->shortOptions[$spec->short] = $spec;
}
$this->options[] = $spec;
if (!$spec->long && !$spec->short) {
throw new InvalidArgumentException('Neither long option name nor short name is not given.');
}
} | [
"public",
"function",
"addOption",
"(",
"Option",
"$",
"spec",
")",
"{",
"$",
"this",
"->",
"data",
"[",
"$",
"spec",
"->",
"getId",
"(",
")",
"]",
"=",
"$",
"spec",
";",
"if",
"(",
"$",
"spec",
"->",
"long",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"longOptions",
"[",
"$",
"spec",
"->",
"long",
"]",
")",
")",
"{",
"throw",
"new",
"OptionConflictException",
"(",
"'Option conflict: --'",
".",
"$",
"spec",
"->",
"long",
".",
"' is already defined.'",
")",
";",
"}",
"$",
"this",
"->",
"longOptions",
"[",
"$",
"spec",
"->",
"long",
"]",
"=",
"$",
"spec",
";",
"}",
"if",
"(",
"$",
"spec",
"->",
"short",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"shortOptions",
"[",
"$",
"spec",
"->",
"short",
"]",
")",
")",
"{",
"throw",
"new",
"OptionConflictException",
"(",
"'Option conflict: -'",
".",
"$",
"spec",
"->",
"short",
".",
"' is already defined.'",
")",
";",
"}",
"$",
"this",
"->",
"shortOptions",
"[",
"$",
"spec",
"->",
"short",
"]",
"=",
"$",
"spec",
";",
"}",
"$",
"this",
"->",
"options",
"[",
"]",
"=",
"$",
"spec",
";",
"if",
"(",
"!",
"$",
"spec",
"->",
"long",
"&&",
"!",
"$",
"spec",
"->",
"short",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Neither long option name nor short name is not given.'",
")",
";",
"}",
"}"
] | Add option object.
@param Option $spec the option object.
@throws InvalidArgumentException
@throws OptionConflictException | [
"Add",
"option",
"object",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/Option/OptionCollection.php#L118-L137 |
35,281 | mcrumm/pecan | src/Console.php | Console.format | public function format($message)
{
if (!$this->output) {
throw new \LogicException('A ConsoleOutputInterface must be set before calling format().');
}
return $this->output->getFormatter()->format($message);
} | php | public function format($message)
{
if (!$this->output) {
throw new \LogicException('A ConsoleOutputInterface must be set before calling format().');
}
return $this->output->getFormatter()->format($message);
} | [
"public",
"function",
"format",
"(",
"$",
"message",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"output",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'A ConsoleOutputInterface must be set before calling format().'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"output",
"->",
"getFormatter",
"(",
")",
"->",
"format",
"(",
"$",
"message",
")",
";",
"}"
] | Formats a message.
@param $message
@return string
@throws \LogicException When called before Output is set. | [
"Formats",
"a",
"message",
"."
] | f35f01249587a4df45c7d3ab78f3e51919471177 | https://github.com/mcrumm/pecan/blob/f35f01249587a4df45c7d3ab78f3e51919471177/src/Console.php#L53-L60 |
35,282 | DoSomething/gateway | src/Laravel/LaravelNorthstar.php | LaravelNorthstar.send | public function send($method, $path, $options = [], $withAuthorization = true)
{
try {
return parent::send($method, $path, $options, $withAuthorization);
} catch (ValidationException $e) {
throw LaravelValidationException::withMessages($e->getErrors());
} catch (UnauthorizedException $e) {
throw new \Illuminate\Auth\AuthenticationException;
} catch (ForbiddenException $e) {
throw new \Illuminate\Auth\AuthenticationException;
} catch (InternalException $e) {
$message = 'Northstar returned an unexpected error for that request.';
if (config('app.debug')) {
$message = $e->getMessage();
}
throw new HttpException(500, $message);
}
} | php | public function send($method, $path, $options = [], $withAuthorization = true)
{
try {
return parent::send($method, $path, $options, $withAuthorization);
} catch (ValidationException $e) {
throw LaravelValidationException::withMessages($e->getErrors());
} catch (UnauthorizedException $e) {
throw new \Illuminate\Auth\AuthenticationException;
} catch (ForbiddenException $e) {
throw new \Illuminate\Auth\AuthenticationException;
} catch (InternalException $e) {
$message = 'Northstar returned an unexpected error for that request.';
if (config('app.debug')) {
$message = $e->getMessage();
}
throw new HttpException(500, $message);
}
} | [
"public",
"function",
"send",
"(",
"$",
"method",
",",
"$",
"path",
",",
"$",
"options",
"=",
"[",
"]",
",",
"$",
"withAuthorization",
"=",
"true",
")",
"{",
"try",
"{",
"return",
"parent",
"::",
"send",
"(",
"$",
"method",
",",
"$",
"path",
",",
"$",
"options",
",",
"$",
"withAuthorization",
")",
";",
"}",
"catch",
"(",
"ValidationException",
"$",
"e",
")",
"{",
"throw",
"LaravelValidationException",
"::",
"withMessages",
"(",
"$",
"e",
"->",
"getErrors",
"(",
")",
")",
";",
"}",
"catch",
"(",
"UnauthorizedException",
"$",
"e",
")",
"{",
"throw",
"new",
"\\",
"Illuminate",
"\\",
"Auth",
"\\",
"AuthenticationException",
";",
"}",
"catch",
"(",
"ForbiddenException",
"$",
"e",
")",
"{",
"throw",
"new",
"\\",
"Illuminate",
"\\",
"Auth",
"\\",
"AuthenticationException",
";",
"}",
"catch",
"(",
"InternalException",
"$",
"e",
")",
"{",
"$",
"message",
"=",
"'Northstar returned an unexpected error for that request.'",
";",
"if",
"(",
"config",
"(",
"'app.debug'",
")",
")",
"{",
"$",
"message",
"=",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"}",
"throw",
"new",
"HttpException",
"(",
"500",
",",
"$",
"message",
")",
";",
"}",
"}"
] | Send a Northstar API request, and translates any Northstar exceptions
into their built-in Laravel equivalents.
@param string $method
@param string $path
@param array $options
@param bool $withAuthorization
@return \GuzzleHttp\Psr7\Response|void | [
"Send",
"a",
"Northstar",
"API",
"request",
"and",
"translates",
"any",
"Northstar",
"exceptions",
"into",
"their",
"built",
"-",
"in",
"Laravel",
"equivalents",
"."
] | 89c1c59c6af038dff790df6d5aaa9fc703246568 | https://github.com/DoSomething/gateway/blob/89c1c59c6af038dff790df6d5aaa9fc703246568/src/Laravel/LaravelNorthstar.php#L41-L60 |
35,283 | htmlburger/wpemerge-cli | src/Composer/Composer.php | Composer.getComposerJson | public static function getComposerJson( $directory ) {
$composer_json = $directory . DIRECTORY_SEPARATOR . 'composer.json';
if ( ! file_exists( $composer_json ) ) {
return null;
}
$composer = @json_decode( file_get_contents( $composer_json ), true );
if ( ! $composer ) {
return null;
}
return $composer;
} | php | public static function getComposerJson( $directory ) {
$composer_json = $directory . DIRECTORY_SEPARATOR . 'composer.json';
if ( ! file_exists( $composer_json ) ) {
return null;
}
$composer = @json_decode( file_get_contents( $composer_json ), true );
if ( ! $composer ) {
return null;
}
return $composer;
} | [
"public",
"static",
"function",
"getComposerJson",
"(",
"$",
"directory",
")",
"{",
"$",
"composer_json",
"=",
"$",
"directory",
".",
"DIRECTORY_SEPARATOR",
".",
"'composer.json'",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"composer_json",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"composer",
"=",
"@",
"json_decode",
"(",
"file_get_contents",
"(",
"$",
"composer_json",
")",
",",
"true",
")",
";",
"if",
"(",
"!",
"$",
"composer",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"composer",
";",
"}"
] | Load and parse a composer.json file from a directory
@param string $directory
@return array|null | [
"Load",
"and",
"parse",
"a",
"composer",
".",
"json",
"file",
"from",
"a",
"directory"
] | 075f1982b7dd87039a4e7bbc05caf676a10fe862 | https://github.com/htmlburger/wpemerge-cli/blob/075f1982b7dd87039a4e7bbc05caf676a10fe862/src/Composer/Composer.php#L15-L29 |
35,284 | htmlburger/wpemerge-cli | src/Composer/Composer.php | Composer.storeComposerJson | public static function storeComposerJson( $composer, $directory ) {
$composer_json = $directory . DIRECTORY_SEPARATOR . 'composer.json';
file_put_contents( $composer_json, json_encode( $composer, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) );
} | php | public static function storeComposerJson( $composer, $directory ) {
$composer_json = $directory . DIRECTORY_SEPARATOR . 'composer.json';
file_put_contents( $composer_json, json_encode( $composer, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) );
} | [
"public",
"static",
"function",
"storeComposerJson",
"(",
"$",
"composer",
",",
"$",
"directory",
")",
"{",
"$",
"composer_json",
"=",
"$",
"directory",
".",
"DIRECTORY_SEPARATOR",
".",
"'composer.json'",
";",
"file_put_contents",
"(",
"$",
"composer_json",
",",
"json_encode",
"(",
"$",
"composer",
",",
"JSON_PRETTY_PRINT",
"|",
"JSON_UNESCAPED_SLASHES",
")",
")",
";",
"}"
] | Store a parsed composer.json file in a directory
@param array $composer
@param string $directory
@return void | [
"Store",
"a",
"parsed",
"composer",
".",
"json",
"file",
"in",
"a",
"directory"
] | 075f1982b7dd87039a4e7bbc05caf676a10fe862 | https://github.com/htmlburger/wpemerge-cli/blob/075f1982b7dd87039a4e7bbc05caf676a10fe862/src/Composer/Composer.php#L38-L42 |
35,285 | htmlburger/wpemerge-cli | src/Composer/Composer.php | Composer.installed | public static function installed( $directory, $package ) {
$command = 'composer show ' . $package . ' -D';
try {
App::execute( $command, $directory );
} catch ( ProcessFailedException $e ) {
return false;
}
return true;
} | php | public static function installed( $directory, $package ) {
$command = 'composer show ' . $package . ' -D';
try {
App::execute( $command, $directory );
} catch ( ProcessFailedException $e ) {
return false;
}
return true;
} | [
"public",
"static",
"function",
"installed",
"(",
"$",
"directory",
",",
"$",
"package",
")",
"{",
"$",
"command",
"=",
"'composer show '",
".",
"$",
"package",
".",
"' -D'",
";",
"try",
"{",
"App",
"::",
"execute",
"(",
"$",
"command",
",",
"$",
"directory",
")",
";",
"}",
"catch",
"(",
"ProcessFailedException",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Check if a package is already installed
@param string $directory
@param string $package
@return boolean | [
"Check",
"if",
"a",
"package",
"is",
"already",
"installed"
] | 075f1982b7dd87039a4e7bbc05caf676a10fe862 | https://github.com/htmlburger/wpemerge-cli/blob/075f1982b7dd87039a4e7bbc05caf676a10fe862/src/Composer/Composer.php#L51-L61 |
35,286 | hail-framework/framework | src/AliasLoader.php | AliasLoader.ensureFacadeExists | protected function ensureFacadeExists(string $alias): string
{
if (\file_exists($path = \runtime_path('facade', $alias . '.php'))) {
return $path;
}
if (!\is_dir($dir = \dirname($path)) && !@\mkdir($dir) && !\is_dir($dir)) {
throw new \RuntimeException('Temp directory permission denied');
}
\file_put_contents($path, $this->formatFacadeCode($alias));
if (\function_exists('\opcache_invalidate')) {
\opcache_invalidate($path, true);
}
return $path;
} | php | protected function ensureFacadeExists(string $alias): string
{
if (\file_exists($path = \runtime_path('facade', $alias . '.php'))) {
return $path;
}
if (!\is_dir($dir = \dirname($path)) && !@\mkdir($dir) && !\is_dir($dir)) {
throw new \RuntimeException('Temp directory permission denied');
}
\file_put_contents($path, $this->formatFacadeCode($alias));
if (\function_exists('\opcache_invalidate')) {
\opcache_invalidate($path, true);
}
return $path;
} | [
"protected",
"function",
"ensureFacadeExists",
"(",
"string",
"$",
"alias",
")",
":",
"string",
"{",
"if",
"(",
"\\",
"file_exists",
"(",
"$",
"path",
"=",
"\\",
"runtime_path",
"(",
"'facade'",
",",
"$",
"alias",
".",
"'.php'",
")",
")",
")",
"{",
"return",
"$",
"path",
";",
"}",
"if",
"(",
"!",
"\\",
"is_dir",
"(",
"$",
"dir",
"=",
"\\",
"dirname",
"(",
"$",
"path",
")",
")",
"&&",
"!",
"@",
"\\",
"mkdir",
"(",
"$",
"dir",
")",
"&&",
"!",
"\\",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Temp directory permission denied'",
")",
";",
"}",
"\\",
"file_put_contents",
"(",
"$",
"path",
",",
"$",
"this",
"->",
"formatFacadeCode",
"(",
"$",
"alias",
")",
")",
";",
"if",
"(",
"\\",
"function_exists",
"(",
"'\\opcache_invalidate'",
")",
")",
"{",
"\\",
"opcache_invalidate",
"(",
"$",
"path",
",",
"true",
")",
";",
"}",
"return",
"$",
"path",
";",
"}"
] | Ensure that the given alias has an existing real-time facade class.
@param string $alias
@return string
@throws \RuntimeException | [
"Ensure",
"that",
"the",
"given",
"alias",
"has",
"an",
"existing",
"real",
"-",
"time",
"facade",
"class",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/AliasLoader.php#L89-L106 |
35,287 | hail-framework/framework | src/AliasLoader.php | AliasLoader.register | public function register(): void
{
if (!$this->registered) {
\spl_autoload_register([$this, 'load'], true, true);
$this->registered = true;
}
} | php | public function register(): void
{
if (!$this->registered) {
\spl_autoload_register([$this, 'load'], true, true);
$this->registered = true;
}
} | [
"public",
"function",
"register",
"(",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"registered",
")",
"{",
"\\",
"spl_autoload_register",
"(",
"[",
"$",
"this",
",",
"'load'",
"]",
",",
"true",
",",
"true",
")",
";",
"$",
"this",
"->",
"registered",
"=",
"true",
";",
"}",
"}"
] | Prepend the loader to the auto-loader stack.
@return void | [
"Prepend",
"the",
"loader",
"to",
"the",
"auto",
"-",
"loader",
"stack",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/AliasLoader.php#L198-L204 |
35,288 | Kajna/K-Core | Core/Session/Session.php | Session.validate | protected function validate()
{
// Are needed session variables set ?
if (!isset($_SESSION['s3ss10nCr3at3d']) || !isset($_SESSION['n3k0t'])) {
return false;
}
// Check if session token match ?
if ($this->matchUserAgent) {
if ($_SESSION['n3k0t'] !== hash_hmac($this->hashAlgo, $_SERVER['HTTP_USER_AGENT'] . $_SESSION['s3ss10nCr3at3d'], $this->hashKey)) {
return false;
}
} elseif ($_SESSION['n3k0t'] !== hash_hmac($this->hashAlgo, $_SESSION['s3ss10nCr3at3d'], $this->hashKey)) {
return false;
}
// Is session expired ?
if ((time() > ($_SESSION['s3ss10nCr3at3d']) + $this->expiration)) {
return false;
}
// Everything is fine return true
return true;
} | php | protected function validate()
{
// Are needed session variables set ?
if (!isset($_SESSION['s3ss10nCr3at3d']) || !isset($_SESSION['n3k0t'])) {
return false;
}
// Check if session token match ?
if ($this->matchUserAgent) {
if ($_SESSION['n3k0t'] !== hash_hmac($this->hashAlgo, $_SERVER['HTTP_USER_AGENT'] . $_SESSION['s3ss10nCr3at3d'], $this->hashKey)) {
return false;
}
} elseif ($_SESSION['n3k0t'] !== hash_hmac($this->hashAlgo, $_SESSION['s3ss10nCr3at3d'], $this->hashKey)) {
return false;
}
// Is session expired ?
if ((time() > ($_SESSION['s3ss10nCr3at3d']) + $this->expiration)) {
return false;
}
// Everything is fine return true
return true;
} | [
"protected",
"function",
"validate",
"(",
")",
"{",
"// Are needed session variables set ?",
"if",
"(",
"!",
"isset",
"(",
"$",
"_SESSION",
"[",
"'s3ss10nCr3at3d'",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"_SESSION",
"[",
"'n3k0t'",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Check if session token match ?",
"if",
"(",
"$",
"this",
"->",
"matchUserAgent",
")",
"{",
"if",
"(",
"$",
"_SESSION",
"[",
"'n3k0t'",
"]",
"!==",
"hash_hmac",
"(",
"$",
"this",
"->",
"hashAlgo",
",",
"$",
"_SERVER",
"[",
"'HTTP_USER_AGENT'",
"]",
".",
"$",
"_SESSION",
"[",
"'s3ss10nCr3at3d'",
"]",
",",
"$",
"this",
"->",
"hashKey",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"elseif",
"(",
"$",
"_SESSION",
"[",
"'n3k0t'",
"]",
"!==",
"hash_hmac",
"(",
"$",
"this",
"->",
"hashAlgo",
",",
"$",
"_SESSION",
"[",
"'s3ss10nCr3at3d'",
"]",
",",
"$",
"this",
"->",
"hashKey",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Is session expired ?",
"if",
"(",
"(",
"time",
"(",
")",
">",
"(",
"$",
"_SESSION",
"[",
"'s3ss10nCr3at3d'",
"]",
")",
"+",
"$",
"this",
"->",
"expiration",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Everything is fine return true",
"return",
"true",
";",
"}"
] | Validate session.
@return bool | [
"Validate",
"session",
"."
] | 6a354056cf95e471b9b1eb372c5626123fd77df2 | https://github.com/Kajna/K-Core/blob/6a354056cf95e471b9b1eb372c5626123fd77df2/Core/Session/Session.php#L136-L159 |
35,289 | Kajna/K-Core | Core/Session/Session.php | Session.regenerate | public function regenerate()
{
// If headers already sent can't do much
if (headers_sent()) {
return;
}
// Clear old session data
$_SESSION = [];
// Set session start time
$_SESSION['s3ss10nCr3at3d'] = time();
// Set new session token
if ($this->matchUserAgent) {
$_SESSION['n3k0t'] = hash_hmac($this->hashAlgo, $_SERVER['HTTP_USER_AGENT'] . $_SESSION['s3ss10nCr3at3d'], $this->hashKey);
} else {
$_SESSION['n3k0t'] = hash_hmac($this->hashAlgo, $_SESSION['s3ss10nCr3at3d'], $this->hashKey);
}
// Regenerate session
session_regenerate_id();
} | php | public function regenerate()
{
// If headers already sent can't do much
if (headers_sent()) {
return;
}
// Clear old session data
$_SESSION = [];
// Set session start time
$_SESSION['s3ss10nCr3at3d'] = time();
// Set new session token
if ($this->matchUserAgent) {
$_SESSION['n3k0t'] = hash_hmac($this->hashAlgo, $_SERVER['HTTP_USER_AGENT'] . $_SESSION['s3ss10nCr3at3d'], $this->hashKey);
} else {
$_SESSION['n3k0t'] = hash_hmac($this->hashAlgo, $_SESSION['s3ss10nCr3at3d'], $this->hashKey);
}
// Regenerate session
session_regenerate_id();
} | [
"public",
"function",
"regenerate",
"(",
")",
"{",
"// If headers already sent can't do much",
"if",
"(",
"headers_sent",
"(",
")",
")",
"{",
"return",
";",
"}",
"// Clear old session data",
"$",
"_SESSION",
"=",
"[",
"]",
";",
"// Set session start time",
"$",
"_SESSION",
"[",
"'s3ss10nCr3at3d'",
"]",
"=",
"time",
"(",
")",
";",
"// Set new session token",
"if",
"(",
"$",
"this",
"->",
"matchUserAgent",
")",
"{",
"$",
"_SESSION",
"[",
"'n3k0t'",
"]",
"=",
"hash_hmac",
"(",
"$",
"this",
"->",
"hashAlgo",
",",
"$",
"_SERVER",
"[",
"'HTTP_USER_AGENT'",
"]",
".",
"$",
"_SESSION",
"[",
"'s3ss10nCr3at3d'",
"]",
",",
"$",
"this",
"->",
"hashKey",
")",
";",
"}",
"else",
"{",
"$",
"_SESSION",
"[",
"'n3k0t'",
"]",
"=",
"hash_hmac",
"(",
"$",
"this",
"->",
"hashAlgo",
",",
"$",
"_SESSION",
"[",
"'s3ss10nCr3at3d'",
"]",
",",
"$",
"this",
"->",
"hashKey",
")",
";",
"}",
"// Regenerate session",
"session_regenerate_id",
"(",
")",
";",
"}"
] | Completely regenerate session. | [
"Completely",
"regenerate",
"session",
"."
] | 6a354056cf95e471b9b1eb372c5626123fd77df2 | https://github.com/Kajna/K-Core/blob/6a354056cf95e471b9b1eb372c5626123fd77df2/Core/Session/Session.php#L164-L183 |
35,290 | spiral/debug | src/Traits/BenchmarkTrait.php | BenchmarkTrait.benchmark | private function benchmark(string $event, $context = null): Benchmark
{
$container = ContainerScope::getContainer();
if (empty($container) || !$container->has(BenchmarkerInterface::class)) {
return new Benchmark(
get_class($this),
$event,
$context
);
}
return $container->get(BenchmarkerInterface::class)->record(
get_class($this),
$event,
$context
);
} | php | private function benchmark(string $event, $context = null): Benchmark
{
$container = ContainerScope::getContainer();
if (empty($container) || !$container->has(BenchmarkerInterface::class)) {
return new Benchmark(
get_class($this),
$event,
$context
);
}
return $container->get(BenchmarkerInterface::class)->record(
get_class($this),
$event,
$context
);
} | [
"private",
"function",
"benchmark",
"(",
"string",
"$",
"event",
",",
"$",
"context",
"=",
"null",
")",
":",
"Benchmark",
"{",
"$",
"container",
"=",
"ContainerScope",
"::",
"getContainer",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"container",
")",
"||",
"!",
"$",
"container",
"->",
"has",
"(",
"BenchmarkerInterface",
"::",
"class",
")",
")",
"{",
"return",
"new",
"Benchmark",
"(",
"get_class",
"(",
"$",
"this",
")",
",",
"$",
"event",
",",
"$",
"context",
")",
";",
"}",
"return",
"$",
"container",
"->",
"get",
"(",
"BenchmarkerInterface",
"::",
"class",
")",
"->",
"record",
"(",
"get_class",
"(",
"$",
"this",
")",
",",
"$",
"event",
",",
"$",
"context",
")",
";",
"}"
] | Creates new benchmark record associated with current object.
@param string $event Event name or set of names.
@param string $context Record context (if any).
@return Benchmark
@throws \Psr\Container\ContainerExceptionInterface | [
"Creates",
"new",
"benchmark",
"record",
"associated",
"with",
"current",
"object",
"."
] | d477c7f2e50be8cb934cf3a5f327d6dc3eee2f9f | https://github.com/spiral/debug/blob/d477c7f2e50be8cb934cf3a5f327d6dc3eee2f9f/src/Traits/BenchmarkTrait.php#L31-L47 |
35,291 | hail-framework/framework | src/Database/Migration/Adapter/PdoAdapter.php | PdoAdapter.setConnection | public function setConnection(\PDO $connection)
{
$this->connection = $connection;
// Create the schema table if it doesn't already exist
if (!$this->hasSchemaTable()) {
$this->createSchemaTable();
} else {
$table = new Table($this->getSchemaTableName(), [], $this);
if (!$table->hasColumn('migration_name')) {
$table
->addColumn('migration_name', 'string',
['limit' => 100, 'after' => 'version', 'default' => null, 'null' => true]
)
->save();
}
if (!$table->hasColumn('breakpoint')) {
$table
->addColumn('breakpoint', 'boolean', ['default' => false])
->save();
}
}
return $this;
} | php | public function setConnection(\PDO $connection)
{
$this->connection = $connection;
// Create the schema table if it doesn't already exist
if (!$this->hasSchemaTable()) {
$this->createSchemaTable();
} else {
$table = new Table($this->getSchemaTableName(), [], $this);
if (!$table->hasColumn('migration_name')) {
$table
->addColumn('migration_name', 'string',
['limit' => 100, 'after' => 'version', 'default' => null, 'null' => true]
)
->save();
}
if (!$table->hasColumn('breakpoint')) {
$table
->addColumn('breakpoint', 'boolean', ['default' => false])
->save();
}
}
return $this;
} | [
"public",
"function",
"setConnection",
"(",
"\\",
"PDO",
"$",
"connection",
")",
"{",
"$",
"this",
"->",
"connection",
"=",
"$",
"connection",
";",
"// Create the schema table if it doesn't already exist",
"if",
"(",
"!",
"$",
"this",
"->",
"hasSchemaTable",
"(",
")",
")",
"{",
"$",
"this",
"->",
"createSchemaTable",
"(",
")",
";",
"}",
"else",
"{",
"$",
"table",
"=",
"new",
"Table",
"(",
"$",
"this",
"->",
"getSchemaTableName",
"(",
")",
",",
"[",
"]",
",",
"$",
"this",
")",
";",
"if",
"(",
"!",
"$",
"table",
"->",
"hasColumn",
"(",
"'migration_name'",
")",
")",
"{",
"$",
"table",
"->",
"addColumn",
"(",
"'migration_name'",
",",
"'string'",
",",
"[",
"'limit'",
"=>",
"100",
",",
"'after'",
"=>",
"'version'",
",",
"'default'",
"=>",
"null",
",",
"'null'",
"=>",
"true",
"]",
")",
"->",
"save",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"table",
"->",
"hasColumn",
"(",
"'breakpoint'",
")",
")",
"{",
"$",
"table",
"->",
"addColumn",
"(",
"'breakpoint'",
",",
"'boolean'",
",",
"[",
"'default'",
"=>",
"false",
"]",
")",
"->",
"save",
"(",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Sets the database connection.
@param \PDO $connection Connection
@return AdapterInterface | [
"Sets",
"the",
"database",
"connection",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Adapter/PdoAdapter.php#L70-L94 |
35,292 | hail-framework/framework | src/Database/Migration/Adapter/ProxyAdapter.php | ProxyAdapter.executeCommands | public function executeCommands()
{
$commands = $this->getCommands();
foreach ($commands as $command) {
call_user_func_array([$this->getAdapter(), $command['name']], $command['arguments']);
}
} | php | public function executeCommands()
{
$commands = $this->getCommands();
foreach ($commands as $command) {
call_user_func_array([$this->getAdapter(), $command['name']], $command['arguments']);
}
} | [
"public",
"function",
"executeCommands",
"(",
")",
"{",
"$",
"commands",
"=",
"$",
"this",
"->",
"getCommands",
"(",
")",
";",
"foreach",
"(",
"$",
"commands",
"as",
"$",
"command",
")",
"{",
"call_user_func_array",
"(",
"[",
"$",
"this",
"->",
"getAdapter",
"(",
")",
",",
"$",
"command",
"[",
"'name'",
"]",
"]",
",",
"$",
"command",
"[",
"'arguments'",
"]",
")",
";",
"}",
"}"
] | Execute the recorded commands.
@return void | [
"Execute",
"the",
"recorded",
"commands",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Adapter/ProxyAdapter.php#L253-L259 |
35,293 | hail-framework/framework | src/Database/Migration/Adapter/ProxyAdapter.php | ProxyAdapter.executeInvertedCommands | public function executeInvertedCommands()
{
$commands = $this->getInvertedCommands();
foreach ($commands as $command) {
call_user_func_array([$this->getAdapter(), $command['name']], $command['arguments']);
}
} | php | public function executeInvertedCommands()
{
$commands = $this->getInvertedCommands();
foreach ($commands as $command) {
call_user_func_array([$this->getAdapter(), $command['name']], $command['arguments']);
}
} | [
"public",
"function",
"executeInvertedCommands",
"(",
")",
"{",
"$",
"commands",
"=",
"$",
"this",
"->",
"getInvertedCommands",
"(",
")",
";",
"foreach",
"(",
"$",
"commands",
"as",
"$",
"command",
")",
"{",
"call_user_func_array",
"(",
"[",
"$",
"this",
"->",
"getAdapter",
"(",
")",
",",
"$",
"command",
"[",
"'name'",
"]",
"]",
",",
"$",
"command",
"[",
"'arguments'",
"]",
")",
";",
"}",
"}"
] | Execute the recorded commands in reverse.
@return void | [
"Execute",
"the",
"recorded",
"commands",
"in",
"reverse",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Adapter/ProxyAdapter.php#L266-L272 |
35,294 | hail-framework/framework | src/Http/Middleware/Cors.php | Cors.withCorsHeaders | private static function withCorsHeaders(ResponseInterface $response, array $headers): ResponseInterface
{
foreach ($headers as $name => $value) {
$response = $response->withHeader($name, $value);
}
return $response;
} | php | private static function withCorsHeaders(ResponseInterface $response, array $headers): ResponseInterface
{
foreach ($headers as $name => $value) {
$response = $response->withHeader($name, $value);
}
return $response;
} | [
"private",
"static",
"function",
"withCorsHeaders",
"(",
"ResponseInterface",
"$",
"response",
",",
"array",
"$",
"headers",
")",
":",
"ResponseInterface",
"{",
"foreach",
"(",
"$",
"headers",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"response",
"=",
"$",
"response",
"->",
"withHeader",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | Adds cors headers to the response.
@param ResponseInterface $response
@param array $headers
@return ResponseInterface | [
"Adds",
"cors",
"headers",
"to",
"the",
"response",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Http/Middleware/Cors.php#L172-L179 |
35,295 | hail-framework/framework | src/Http/Middleware/Cors.php | Cors.analyze | public function analyze(RequestInterface $request): array
{
$serverOrigin = Factory::uri($this->settings[self::KEY_SERVER_ORIGIN]);
// check 'Host' request
if ($this->settings[self::KEY_IS_CHECK_HOST] && !$this->isSameHost($request, $serverOrigin)) {
return $this->result(self::ERROR_NO_HOST_HEADER);
}
// Request handlers have common part (#6.1.1 - #6.1.2 and #6.2.1 - #6.2.2)
// #6.1.1 and #6.2.1
$requestOrigin = $this->getRequestOrigin($request);
if ($requestOrigin === null || $requestOrigin === $this->getOriginFromUri($serverOrigin)) {
return $this->result(self::TYPE_REQUEST_OUT_OF_CORS_SCOPE);
}
// #6.1.2 and #6.2.2
if (
!isset($this->settings[self::KEY_ALLOWED_ORIGINS][self::VALUE_ALLOW_ORIGIN_ALL]) &&
!isset($this->settings[self::KEY_ALLOWED_ORIGINS][$requestOrigin])
) {
return $this->result(self::ERROR_ORIGIN_NOT_ALLOWED);
}
// Since this point handlers have their own path for
// - simple CORS and actual CORS request (#6.1.3 - #6.1.4)
// - pre-flight request (#6.2.3 - #6.2.10)
if ($request->getMethod() === 'OPTIONS') {
return $this->analyzeAsPreFlight($request, $requestOrigin);
}
return $this->analyzeAsRequest($requestOrigin);
} | php | public function analyze(RequestInterface $request): array
{
$serverOrigin = Factory::uri($this->settings[self::KEY_SERVER_ORIGIN]);
// check 'Host' request
if ($this->settings[self::KEY_IS_CHECK_HOST] && !$this->isSameHost($request, $serverOrigin)) {
return $this->result(self::ERROR_NO_HOST_HEADER);
}
// Request handlers have common part (#6.1.1 - #6.1.2 and #6.2.1 - #6.2.2)
// #6.1.1 and #6.2.1
$requestOrigin = $this->getRequestOrigin($request);
if ($requestOrigin === null || $requestOrigin === $this->getOriginFromUri($serverOrigin)) {
return $this->result(self::TYPE_REQUEST_OUT_OF_CORS_SCOPE);
}
// #6.1.2 and #6.2.2
if (
!isset($this->settings[self::KEY_ALLOWED_ORIGINS][self::VALUE_ALLOW_ORIGIN_ALL]) &&
!isset($this->settings[self::KEY_ALLOWED_ORIGINS][$requestOrigin])
) {
return $this->result(self::ERROR_ORIGIN_NOT_ALLOWED);
}
// Since this point handlers have their own path for
// - simple CORS and actual CORS request (#6.1.3 - #6.1.4)
// - pre-flight request (#6.2.3 - #6.2.10)
if ($request->getMethod() === 'OPTIONS') {
return $this->analyzeAsPreFlight($request, $requestOrigin);
}
return $this->analyzeAsRequest($requestOrigin);
} | [
"public",
"function",
"analyze",
"(",
"RequestInterface",
"$",
"request",
")",
":",
"array",
"{",
"$",
"serverOrigin",
"=",
"Factory",
"::",
"uri",
"(",
"$",
"this",
"->",
"settings",
"[",
"self",
"::",
"KEY_SERVER_ORIGIN",
"]",
")",
";",
"// check 'Host' request\r",
"if",
"(",
"$",
"this",
"->",
"settings",
"[",
"self",
"::",
"KEY_IS_CHECK_HOST",
"]",
"&&",
"!",
"$",
"this",
"->",
"isSameHost",
"(",
"$",
"request",
",",
"$",
"serverOrigin",
")",
")",
"{",
"return",
"$",
"this",
"->",
"result",
"(",
"self",
"::",
"ERROR_NO_HOST_HEADER",
")",
";",
"}",
"// Request handlers have common part (#6.1.1 - #6.1.2 and #6.2.1 - #6.2.2)\r",
"// #6.1.1 and #6.2.1\r",
"$",
"requestOrigin",
"=",
"$",
"this",
"->",
"getRequestOrigin",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"requestOrigin",
"===",
"null",
"||",
"$",
"requestOrigin",
"===",
"$",
"this",
"->",
"getOriginFromUri",
"(",
"$",
"serverOrigin",
")",
")",
"{",
"return",
"$",
"this",
"->",
"result",
"(",
"self",
"::",
"TYPE_REQUEST_OUT_OF_CORS_SCOPE",
")",
";",
"}",
"// #6.1.2 and #6.2.2\r",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"settings",
"[",
"self",
"::",
"KEY_ALLOWED_ORIGINS",
"]",
"[",
"self",
"::",
"VALUE_ALLOW_ORIGIN_ALL",
"]",
")",
"&&",
"!",
"isset",
"(",
"$",
"this",
"->",
"settings",
"[",
"self",
"::",
"KEY_ALLOWED_ORIGINS",
"]",
"[",
"$",
"requestOrigin",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"result",
"(",
"self",
"::",
"ERROR_ORIGIN_NOT_ALLOWED",
")",
";",
"}",
"// Since this point handlers have their own path for\r",
"// - simple CORS and actual CORS request (#6.1.3 - #6.1.4)\r",
"// - pre-flight request (#6.2.3 - #6.2.10)\r",
"if",
"(",
"$",
"request",
"->",
"getMethod",
"(",
")",
"===",
"'OPTIONS'",
")",
"{",
"return",
"$",
"this",
"->",
"analyzeAsPreFlight",
"(",
"$",
"request",
",",
"$",
"requestOrigin",
")",
";",
"}",
"return",
"$",
"this",
"->",
"analyzeAsRequest",
"(",
"$",
"requestOrigin",
")",
";",
"}"
] | Set request for analysis.
@param RequestInterface $request
@return array
@see http://www.w3.org/TR/cors/#resource-processing-model | [
"Set",
"request",
"for",
"analysis",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Http/Middleware/Cors.php#L189-L223 |
35,296 | hail-framework/framework | src/Image/Image.php | Image.setBackup | public function setBackup($resource, $name = null)
{
$name = $name ?? 'default';
$this->backups[$name] = $resource;
return $this;
} | php | public function setBackup($resource, $name = null)
{
$name = $name ?? 'default';
$this->backups[$name] = $resource;
return $this;
} | [
"public",
"function",
"setBackup",
"(",
"$",
"resource",
",",
"$",
"name",
"=",
"null",
")",
"{",
"$",
"name",
"=",
"$",
"name",
"??",
"'default'",
";",
"$",
"this",
"->",
"backups",
"[",
"$",
"name",
"]",
"=",
"$",
"resource",
";",
"return",
"$",
"this",
";",
"}"
] | Sets current image backup
@param mixed $resource
@param string $name
@return self | [
"Sets",
"current",
"image",
"backup"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Image/Image.php#L244-L251 |
35,297 | netgen-layouts/content-browser-sylius | lib/Backend/ProductBackend.php | ProductBackend.buildLocations | private function buildLocations(array $taxons): array
{
return array_map(
function (TaxonInterface $taxon): Location {
return $this->buildLocation($taxon);
},
$taxons
);
} | php | private function buildLocations(array $taxons): array
{
return array_map(
function (TaxonInterface $taxon): Location {
return $this->buildLocation($taxon);
},
$taxons
);
} | [
"private",
"function",
"buildLocations",
"(",
"array",
"$",
"taxons",
")",
":",
"array",
"{",
"return",
"array_map",
"(",
"function",
"(",
"TaxonInterface",
"$",
"taxon",
")",
":",
"Location",
"{",
"return",
"$",
"this",
"->",
"buildLocation",
"(",
"$",
"taxon",
")",
";",
"}",
",",
"$",
"taxons",
")",
";",
"}"
] | Builds the locations from provided taxons.
@param \Sylius\Component\Taxonomy\Model\TaxonInterface[] $taxons
@return \Netgen\ContentBrowser\Sylius\Item\Product\Location[] | [
"Builds",
"the",
"locations",
"from",
"provided",
"taxons",
"."
] | feb3ab56b584f6fbf4b8b6557ba6398513b116e5 | https://github.com/netgen-layouts/content-browser-sylius/blob/feb3ab56b584f6fbf4b8b6557ba6398513b116e5/lib/Backend/ProductBackend.php#L182-L190 |
35,298 | hail-framework/framework | src/Filesystem/Util/ContentListingFormatter.php | ContentListingFormatter.formatListing | public static function formatListing(string $directory, bool $recursive, array $listing)
{
self::$directory = $directory;
self::$recursive = $recursive;
$listing = \array_values(
\array_map(
['self', 'addPathInfo'],
\array_filter($listing, ['self', 'isEntryOutOfScope'])
)
);
return self::sortListing($listing);
} | php | public static function formatListing(string $directory, bool $recursive, array $listing)
{
self::$directory = $directory;
self::$recursive = $recursive;
$listing = \array_values(
\array_map(
['self', 'addPathInfo'],
\array_filter($listing, ['self', 'isEntryOutOfScope'])
)
);
return self::sortListing($listing);
} | [
"public",
"static",
"function",
"formatListing",
"(",
"string",
"$",
"directory",
",",
"bool",
"$",
"recursive",
",",
"array",
"$",
"listing",
")",
"{",
"self",
"::",
"$",
"directory",
"=",
"$",
"directory",
";",
"self",
"::",
"$",
"recursive",
"=",
"$",
"recursive",
";",
"$",
"listing",
"=",
"\\",
"array_values",
"(",
"\\",
"array_map",
"(",
"[",
"'self'",
",",
"'addPathInfo'",
"]",
",",
"\\",
"array_filter",
"(",
"$",
"listing",
",",
"[",
"'self'",
",",
"'isEntryOutOfScope'",
"]",
")",
")",
")",
";",
"return",
"self",
"::",
"sortListing",
"(",
"$",
"listing",
")",
";",
"}"
] | Format contents listing.
@param string $directory
@param bool $recursive
@param array $listing
@return array | [
"Format",
"contents",
"listing",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Filesystem/Util/ContentListingFormatter.php#L32-L45 |
35,299 | hail-framework/framework | src/Http/Request.php | Request.delete | public function delete(string $name): void
{
!$this->all && $this->inputs();
Arrays::delete($this->input, $name);
$this->cache = [];
} | php | public function delete(string $name): void
{
!$this->all && $this->inputs();
Arrays::delete($this->input, $name);
$this->cache = [];
} | [
"public",
"function",
"delete",
"(",
"string",
"$",
"name",
")",
":",
"void",
"{",
"!",
"$",
"this",
"->",
"all",
"&&",
"$",
"this",
"->",
"inputs",
"(",
")",
";",
"Arrays",
"::",
"delete",
"(",
"$",
"this",
"->",
"input",
",",
"$",
"name",
")",
";",
"$",
"this",
"->",
"cache",
"=",
"[",
"]",
";",
"}"
] | Delete from input
@param string $name | [
"Delete",
"from",
"input"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Http/Request.php#L177-L183 |
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.