repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
153
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
sequence | func_documentation_string
stringlengths 1
46.9k
| func_documentation_tokens
sequence | split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
diskerror/Utilities | src/Sprintf.php | Sprintf.init | public function init($formatStr, $removeLeadSpace = true)
{
// Convert new spec types to proper format string with proper added charactera.
$this->_formatStr = preg_replace(
array(
self::SPEC_FIND . '[aA]/u',
self::SPEC_FIND . 'H/u',
self::SPEC_FIND . '[qQ]/u',
self::SPEC_FIND . 'S/u',
self::SPEC_FIND . '[tT]/u'
),
array(
'\'$1s\'',
'$1s',
'"$1s"',
'$1s',
'`$1s`'
),
$formatStr
);
// removes initial tabs or spaces from line
if ( $removeLeadSpace ) {
$this->_formatStr = preg_replace('/^\s+/um', '', $this->_formatStr);
}
// create an array of specification letters
$specs = array();
$specCount = preg_match_all(self::FILTERS, $formatStr, $specs);
// remove escaping pointer to numbered specifiers
// we're assuming they're used from some place earlier
$numSpec = array();
for ( $l = $specCount - 1; $l >= 0; --$l ) {
if ( false !== strpos($specs[0][$l], '$') ) {
$numSpec[] = $specs[0][$l];
unset($specs[0][$l], $specs[1][$l]);
--$specCount;
}
}
$specs[0] = array_values($specs[0]);
$specs[1] = array_values($specs[1]);
// Save the indexes of the specs to escape.
// Members might not be at sequential indexes.
$this->_specsToEsc = array();
$this->_specsToHex = array();
for ($i = 0; $i < $specCount; ++$i) {
switch ( $specs[1][$i] ) {
case 'A':
case 'Q':
case 'S':
case 'T':
$this->_specsToEsc[] = $i;
break;
case 'H':
$this->_specsToHex[] = $i;
break;
}
}
// Add values from referenced specs.
foreach ($numSpec as $ns) {
if ( preg_match('/A|Q|S|T/u', $ns) ) {
$ref = preg_replace('/^\D*(\d+)\D*$/u', '$1', $ns) - 1;
if ( !in_array($ref, $this->_specsToEsc) ) {
$this->_specsToEsc[] = $ref;
}
if ( !in_array($ref, $this->_specsToHex) ) {
$this->_specsToHex[] = $ref;
}
}
}
return $this; // allows for chaining
} | php | public function init($formatStr, $removeLeadSpace = true)
{
// Convert new spec types to proper format string with proper added charactera.
$this->_formatStr = preg_replace(
array(
self::SPEC_FIND . '[aA]/u',
self::SPEC_FIND . 'H/u',
self::SPEC_FIND . '[qQ]/u',
self::SPEC_FIND . 'S/u',
self::SPEC_FIND . '[tT]/u'
),
array(
'\'$1s\'',
'$1s',
'"$1s"',
'$1s',
'`$1s`'
),
$formatStr
);
// removes initial tabs or spaces from line
if ( $removeLeadSpace ) {
$this->_formatStr = preg_replace('/^\s+/um', '', $this->_formatStr);
}
// create an array of specification letters
$specs = array();
$specCount = preg_match_all(self::FILTERS, $formatStr, $specs);
// remove escaping pointer to numbered specifiers
// we're assuming they're used from some place earlier
$numSpec = array();
for ( $l = $specCount - 1; $l >= 0; --$l ) {
if ( false !== strpos($specs[0][$l], '$') ) {
$numSpec[] = $specs[0][$l];
unset($specs[0][$l], $specs[1][$l]);
--$specCount;
}
}
$specs[0] = array_values($specs[0]);
$specs[1] = array_values($specs[1]);
// Save the indexes of the specs to escape.
// Members might not be at sequential indexes.
$this->_specsToEsc = array();
$this->_specsToHex = array();
for ($i = 0; $i < $specCount; ++$i) {
switch ( $specs[1][$i] ) {
case 'A':
case 'Q':
case 'S':
case 'T':
$this->_specsToEsc[] = $i;
break;
case 'H':
$this->_specsToHex[] = $i;
break;
}
}
// Add values from referenced specs.
foreach ($numSpec as $ns) {
if ( preg_match('/A|Q|S|T/u', $ns) ) {
$ref = preg_replace('/^\D*(\d+)\D*$/u', '$1', $ns) - 1;
if ( !in_array($ref, $this->_specsToEsc) ) {
$this->_specsToEsc[] = $ref;
}
if ( !in_array($ref, $this->_specsToHex) ) {
$this->_specsToHex[] = $ref;
}
}
}
return $this; // allows for chaining
} | [
"public",
"function",
"init",
"(",
"$",
"formatStr",
",",
"$",
"removeLeadSpace",
"=",
"true",
")",
"{",
"//\tConvert new spec types to proper format string with proper added charactera.",
"$",
"this",
"->",
"_formatStr",
"=",
"preg_replace",
"(",
"array",
"(",
"self",
"::",
"SPEC_FIND",
".",
"'[aA]/u'",
",",
"self",
"::",
"SPEC_FIND",
".",
"'H/u'",
",",
"self",
"::",
"SPEC_FIND",
".",
"'[qQ]/u'",
",",
"self",
"::",
"SPEC_FIND",
".",
"'S/u'",
",",
"self",
"::",
"SPEC_FIND",
".",
"'[tT]/u'",
")",
",",
"array",
"(",
"'\\'$1s\\''",
",",
"'$1s'",
",",
"'\"$1s\"'",
",",
"'$1s'",
",",
"'`$1s`'",
")",
",",
"$",
"formatStr",
")",
";",
"//\tremoves initial tabs or spaces from line",
"if",
"(",
"$",
"removeLeadSpace",
")",
"{",
"$",
"this",
"->",
"_formatStr",
"=",
"preg_replace",
"(",
"'/^\\s+/um'",
",",
"''",
",",
"$",
"this",
"->",
"_formatStr",
")",
";",
"}",
"//\tcreate an array of specification letters",
"$",
"specs",
"=",
"array",
"(",
")",
";",
"$",
"specCount",
"=",
"preg_match_all",
"(",
"self",
"::",
"FILTERS",
",",
"$",
"formatStr",
",",
"$",
"specs",
")",
";",
"//\tremove escaping pointer to numbered specifiers",
"//\twe're assuming they're used from some place earlier",
"$",
"numSpec",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"l",
"=",
"$",
"specCount",
"-",
"1",
";",
"$",
"l",
">=",
"0",
";",
"--",
"$",
"l",
")",
"{",
"if",
"(",
"false",
"!==",
"strpos",
"(",
"$",
"specs",
"[",
"0",
"]",
"[",
"$",
"l",
"]",
",",
"'$'",
")",
")",
"{",
"$",
"numSpec",
"[",
"]",
"=",
"$",
"specs",
"[",
"0",
"]",
"[",
"$",
"l",
"]",
";",
"unset",
"(",
"$",
"specs",
"[",
"0",
"]",
"[",
"$",
"l",
"]",
",",
"$",
"specs",
"[",
"1",
"]",
"[",
"$",
"l",
"]",
")",
";",
"--",
"$",
"specCount",
";",
"}",
"}",
"$",
"specs",
"[",
"0",
"]",
"=",
"array_values",
"(",
"$",
"specs",
"[",
"0",
"]",
")",
";",
"$",
"specs",
"[",
"1",
"]",
"=",
"array_values",
"(",
"$",
"specs",
"[",
"1",
"]",
")",
";",
"//\tSave the indexes of the specs to escape.",
"//\tMembers might not be at sequential indexes.",
"$",
"this",
"->",
"_specsToEsc",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"_specsToHex",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"specCount",
";",
"++",
"$",
"i",
")",
"{",
"switch",
"(",
"$",
"specs",
"[",
"1",
"]",
"[",
"$",
"i",
"]",
")",
"{",
"case",
"'A'",
":",
"case",
"'Q'",
":",
"case",
"'S'",
":",
"case",
"'T'",
":",
"$",
"this",
"->",
"_specsToEsc",
"[",
"]",
"=",
"$",
"i",
";",
"break",
";",
"case",
"'H'",
":",
"$",
"this",
"->",
"_specsToHex",
"[",
"]",
"=",
"$",
"i",
";",
"break",
";",
"}",
"}",
"//\tAdd values from referenced specs.",
"foreach",
"(",
"$",
"numSpec",
"as",
"$",
"ns",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/A|Q|S|T/u'",
",",
"$",
"ns",
")",
")",
"{",
"$",
"ref",
"=",
"preg_replace",
"(",
"'/^\\D*(\\d+)\\D*$/u'",
",",
"'$1'",
",",
"$",
"ns",
")",
"-",
"1",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"ref",
",",
"$",
"this",
"->",
"_specsToEsc",
")",
")",
"{",
"$",
"this",
"->",
"_specsToEsc",
"[",
"]",
"=",
"$",
"ref",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"$",
"ref",
",",
"$",
"this",
"->",
"_specsToHex",
")",
")",
"{",
"$",
"this",
"->",
"_specsToHex",
"[",
"]",
"=",
"$",
"ref",
";",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"//\tallows for chaining",
"}"
] | Set format specification string. Can be chained.
Reference numbers (the "4$" inside "%4$s") here and in sprintf are 1-based.
Note that this is changed and stored interally as a 0-based indexed array.
**These should NOT be used as they cannot be handled well without replacing
the PHP builtin printf variant used for formatting.**
@param string $formatStr
@param bool $removeLeadSpace -OPTIONAL
@return Diskerror\Utilities\Sprintf | [
"Set",
"format",
"specification",
"string",
".",
"Can",
"be",
"chained",
"."
] | train | https://github.com/diskerror/Utilities/blob/cc5eec2417f7c2c76a84584ebd5237197dc54236/src/Sprintf.php#L62-L138 |
diskerror/Utilities | src/Sprintf.php | Sprintf.bind | public function bind($aIn)
{
$aIn = ( is_array($aIn) ? array_values($aIn) : func_get_args() );
foreach ( $this->_specsToEsc as $s ) {
// $aIn[$s] = addslashes($aIn[$s]);
$aIn[$s] = preg_replace(self::ESCAPE_REG, '\\\\$1', $aIn[$s]);
}
foreach ( $this->_specsToHex as $s ) {
$aIn[$s] = ( $aIn[$s] === '' ? '""' : '0x' . bin2hex($aIn[$s]) );
}
return vsprintf( $this->_formatStr, $aIn );
} | php | public function bind($aIn)
{
$aIn = ( is_array($aIn) ? array_values($aIn) : func_get_args() );
foreach ( $this->_specsToEsc as $s ) {
// $aIn[$s] = addslashes($aIn[$s]);
$aIn[$s] = preg_replace(self::ESCAPE_REG, '\\\\$1', $aIn[$s]);
}
foreach ( $this->_specsToHex as $s ) {
$aIn[$s] = ( $aIn[$s] === '' ? '""' : '0x' . bin2hex($aIn[$s]) );
}
return vsprintf( $this->_formatStr, $aIn );
} | [
"public",
"function",
"bind",
"(",
"$",
"aIn",
")",
"{",
"$",
"aIn",
"=",
"(",
"is_array",
"(",
"$",
"aIn",
")",
"?",
"array_values",
"(",
"$",
"aIn",
")",
":",
"func_get_args",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"_specsToEsc",
"as",
"$",
"s",
")",
"{",
"//\t\t\t$aIn[$s] = addslashes($aIn[$s]);",
"$",
"aIn",
"[",
"$",
"s",
"]",
"=",
"preg_replace",
"(",
"self",
"::",
"ESCAPE_REG",
",",
"'\\\\\\\\$1'",
",",
"$",
"aIn",
"[",
"$",
"s",
"]",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"_specsToHex",
"as",
"$",
"s",
")",
"{",
"$",
"aIn",
"[",
"$",
"s",
"]",
"=",
"(",
"$",
"aIn",
"[",
"$",
"s",
"]",
"===",
"''",
"?",
"'\"\"'",
":",
"'0x'",
".",
"bin2hex",
"(",
"$",
"aIn",
"[",
"$",
"s",
"]",
")",
")",
";",
"}",
"return",
"vsprintf",
"(",
"$",
"this",
"->",
"_formatStr",
",",
"$",
"aIn",
")",
";",
"}"
] | Bind input values to the stored format string by position.
May have an array or any number of scalar arguments.
@param mixed $aIn
@return string | [
"Bind",
"input",
"values",
"to",
"the",
"stored",
"format",
"string",
"by",
"position",
".",
"May",
"have",
"an",
"array",
"or",
"any",
"number",
"of",
"scalar",
"arguments",
"."
] | train | https://github.com/diskerror/Utilities/blob/cc5eec2417f7c2c76a84584ebd5237197dc54236/src/Sprintf.php#L147-L161 |
jaeger-app/email | src/Email/Swift5.php | Swift5.getMailer | public function getMailer()
{
if(is_null($this->mailer))
{
if (isset($this->config['type']) && $this->config['type'] == 'smtp') {
$transport = \Swift_SmtpTransport::newInstance($this->config['smtp_options']['host'], $this->config['smtp_options']['port']);
$transport->setUsername($this->config['smtp_options']['connection_config']['username']);
$transport->setPassword($this->config['smtp_options']['connection_config']['password']);
} else {
$transport = \Swift_MailTransport::newInstance();
}
$this->mailer = \Swift_Mailer::newInstance($transport);
$this->mailer_logger = new \Swift_Plugins_Loggers_ArrayLogger();
$this->mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($this->mailer_logger));
}
return $this->mailer;
} | php | public function getMailer()
{
if(is_null($this->mailer))
{
if (isset($this->config['type']) && $this->config['type'] == 'smtp') {
$transport = \Swift_SmtpTransport::newInstance($this->config['smtp_options']['host'], $this->config['smtp_options']['port']);
$transport->setUsername($this->config['smtp_options']['connection_config']['username']);
$transport->setPassword($this->config['smtp_options']['connection_config']['password']);
} else {
$transport = \Swift_MailTransport::newInstance();
}
$this->mailer = \Swift_Mailer::newInstance($transport);
$this->mailer_logger = new \Swift_Plugins_Loggers_ArrayLogger();
$this->mailer->registerPlugin(new \Swift_Plugins_LoggerPlugin($this->mailer_logger));
}
return $this->mailer;
} | [
"public",
"function",
"getMailer",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"mailer",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"config",
"[",
"'type'",
"]",
")",
"&&",
"$",
"this",
"->",
"config",
"[",
"'type'",
"]",
"==",
"'smtp'",
")",
"{",
"$",
"transport",
"=",
"\\",
"Swift_SmtpTransport",
"::",
"newInstance",
"(",
"$",
"this",
"->",
"config",
"[",
"'smtp_options'",
"]",
"[",
"'host'",
"]",
",",
"$",
"this",
"->",
"config",
"[",
"'smtp_options'",
"]",
"[",
"'port'",
"]",
")",
";",
"$",
"transport",
"->",
"setUsername",
"(",
"$",
"this",
"->",
"config",
"[",
"'smtp_options'",
"]",
"[",
"'connection_config'",
"]",
"[",
"'username'",
"]",
")",
";",
"$",
"transport",
"->",
"setPassword",
"(",
"$",
"this",
"->",
"config",
"[",
"'smtp_options'",
"]",
"[",
"'connection_config'",
"]",
"[",
"'password'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"transport",
"=",
"\\",
"Swift_MailTransport",
"::",
"newInstance",
"(",
")",
";",
"}",
"$",
"this",
"->",
"mailer",
"=",
"\\",
"Swift_Mailer",
"::",
"newInstance",
"(",
"$",
"transport",
")",
";",
"$",
"this",
"->",
"mailer_logger",
"=",
"new",
"\\",
"Swift_Plugins_Loggers_ArrayLogger",
"(",
")",
";",
"$",
"this",
"->",
"mailer",
"->",
"registerPlugin",
"(",
"new",
"\\",
"Swift_Plugins_LoggerPlugin",
"(",
"$",
"this",
"->",
"mailer_logger",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"mailer",
";",
"}"
] | (non-PHPdoc)
@see \JaegerApp\Email\SwiftAbstract::getMailer() | [
"(",
"non",
"-",
"PHPdoc",
")"
] | train | https://github.com/jaeger-app/email/blob/0ab7535e578b2112a929816e39afb6118eaca669/src/Email/Swift5.php#L46-L64 |
jaeger-app/email | src/Email/Swift5.php | Swift5.getMessage | public function getMessage(array $to, $from_email, $from_name, $subject, $message_body, array $attachments, $mail_type='html')
{
$message = \Swift_Message::newInstance();
$message->setTo($to);
if ($attachments) {
foreach ($attachments as $attachment) {
foreach ($attachment as $file => $alt_name) {
if ($alt_name == '') {
$message->attach(\Swift_Attachment::fromPath($file));
} else {
$message->attach(\Swift_Attachment::fromPath($file)->setFilename($alt_name));
}
}
}
}
$message->setFrom($from_email, $from_name);
$message->setSubject($subject);
if ($mail_type == 'html') {
$message->setBody($message_body, 'text/html');
} else {
$message->setBody($message_body);
}
return $message;
} | php | public function getMessage(array $to, $from_email, $from_name, $subject, $message_body, array $attachments, $mail_type='html')
{
$message = \Swift_Message::newInstance();
$message->setTo($to);
if ($attachments) {
foreach ($attachments as $attachment) {
foreach ($attachment as $file => $alt_name) {
if ($alt_name == '') {
$message->attach(\Swift_Attachment::fromPath($file));
} else {
$message->attach(\Swift_Attachment::fromPath($file)->setFilename($alt_name));
}
}
}
}
$message->setFrom($from_email, $from_name);
$message->setSubject($subject);
if ($mail_type == 'html') {
$message->setBody($message_body, 'text/html');
} else {
$message->setBody($message_body);
}
return $message;
} | [
"public",
"function",
"getMessage",
"(",
"array",
"$",
"to",
",",
"$",
"from_email",
",",
"$",
"from_name",
",",
"$",
"subject",
",",
"$",
"message_body",
",",
"array",
"$",
"attachments",
",",
"$",
"mail_type",
"=",
"'html'",
")",
"{",
"$",
"message",
"=",
"\\",
"Swift_Message",
"::",
"newInstance",
"(",
")",
";",
"$",
"message",
"->",
"setTo",
"(",
"$",
"to",
")",
";",
"if",
"(",
"$",
"attachments",
")",
"{",
"foreach",
"(",
"$",
"attachments",
"as",
"$",
"attachment",
")",
"{",
"foreach",
"(",
"$",
"attachment",
"as",
"$",
"file",
"=>",
"$",
"alt_name",
")",
"{",
"if",
"(",
"$",
"alt_name",
"==",
"''",
")",
"{",
"$",
"message",
"->",
"attach",
"(",
"\\",
"Swift_Attachment",
"::",
"fromPath",
"(",
"$",
"file",
")",
")",
";",
"}",
"else",
"{",
"$",
"message",
"->",
"attach",
"(",
"\\",
"Swift_Attachment",
"::",
"fromPath",
"(",
"$",
"file",
")",
"->",
"setFilename",
"(",
"$",
"alt_name",
")",
")",
";",
"}",
"}",
"}",
"}",
"$",
"message",
"->",
"setFrom",
"(",
"$",
"from_email",
",",
"$",
"from_name",
")",
";",
"$",
"message",
"->",
"setSubject",
"(",
"$",
"subject",
")",
";",
"if",
"(",
"$",
"mail_type",
"==",
"'html'",
")",
"{",
"$",
"message",
"->",
"setBody",
"(",
"$",
"message_body",
",",
"'text/html'",
")",
";",
"}",
"else",
"{",
"$",
"message",
"->",
"setBody",
"(",
"$",
"message_body",
")",
";",
"}",
"return",
"$",
"message",
";",
"}"
] | (non-PHPdoc)
@see \JaegerApp\Email\SwiftAbstract::getMessage() | [
"(",
"non",
"-",
"PHPdoc",
")"
] | train | https://github.com/jaeger-app/email/blob/0ab7535e578b2112a929816e39afb6118eaca669/src/Email/Swift5.php#L70-L95 |
weareunite/unisys-contacts | src/Http/Controllers/CountryController.php | CountryController.listForSelect | public function listForSelect()
{
$object = Country::orderBy('name', 'asc')
->get(['id', 'name']);
return $this->response->collection($object, CountryForSelectResource::class);
} | php | public function listForSelect()
{
$object = Country::orderBy('name', 'asc')
->get(['id', 'name']);
return $this->response->collection($object, CountryForSelectResource::class);
} | [
"public",
"function",
"listForSelect",
"(",
")",
"{",
"$",
"object",
"=",
"Country",
"::",
"orderBy",
"(",
"'name'",
",",
"'asc'",
")",
"->",
"get",
"(",
"[",
"'id'",
",",
"'name'",
"]",
")",
";",
"return",
"$",
"this",
"->",
"response",
"->",
"collection",
"(",
"$",
"object",
",",
"CountryForSelectResource",
"::",
"class",
")",
";",
"}"
] | List for select
@return AnonymousResourceCollection|CountryForSelectResource[] | [
"List",
"for",
"select"
] | train | https://github.com/weareunite/unisys-contacts/blob/6515f6516e8822c1b2f79ad36a65e17ac72e3e12/src/Http/Controllers/CountryController.php#L64-L70 |
kettari/tallanto-client-api-bundle | Api/Method/TallantoGetUsersMethod.php | TallantoGetUsersMethod.getUsers | public function getUsers($items)
{
$result = [];
foreach ($items as $item) {
$result[] = new User($item);
}
return $result;
} | php | public function getUsers($items)
{
$result = [];
foreach ($items as $item) {
$result[] = new User($item);
}
return $result;
} | [
"public",
"function",
"getUsers",
"(",
"$",
"items",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"new",
"User",
"(",
"$",
"item",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Returns array of users.
@param array $items
@return array | [
"Returns",
"array",
"of",
"users",
"."
] | train | https://github.com/kettari/tallanto-client-api-bundle/blob/09863d2b0fed306cc1218ed602ba6c6ad461c3da/Api/Method/TallantoGetUsersMethod.php#L101-L109 |
interactivesolutions/honeycomb-regions | src/app/http/controllers/regions/HCCountriesController.php | HCCountriesController.adminIndex | public function adminIndex()
{
$config = [
'title' => trans('HCRegions::regions_countries.page_title'),
'listURL' => route('admin.api.regions.countries'),
'newFormUrl' => route('admin.api.form-manager', ['regions-countries-new']),
'editFormUrl' => route('admin.api.form-manager', ['regions-countries-edit']),
'imagesUrl' => route('resource.get', ['/']),
'headers' => $this->getAdminListHeader(),
];
if (auth()->user()->can('interactivesolutions_honeycomb_regions_regions_countries_update'))
$config['actions'][] = 'update';
$config['actions'][] = 'search';
$config['filters'] = $this->getFilters();
return hcview('HCCoreUI::admin.content.list', ['config' => $config]);
} | php | public function adminIndex()
{
$config = [
'title' => trans('HCRegions::regions_countries.page_title'),
'listURL' => route('admin.api.regions.countries'),
'newFormUrl' => route('admin.api.form-manager', ['regions-countries-new']),
'editFormUrl' => route('admin.api.form-manager', ['regions-countries-edit']),
'imagesUrl' => route('resource.get', ['/']),
'headers' => $this->getAdminListHeader(),
];
if (auth()->user()->can('interactivesolutions_honeycomb_regions_regions_countries_update'))
$config['actions'][] = 'update';
$config['actions'][] = 'search';
$config['filters'] = $this->getFilters();
return hcview('HCCoreUI::admin.content.list', ['config' => $config]);
} | [
"public",
"function",
"adminIndex",
"(",
")",
"{",
"$",
"config",
"=",
"[",
"'title'",
"=>",
"trans",
"(",
"'HCRegions::regions_countries.page_title'",
")",
",",
"'listURL'",
"=>",
"route",
"(",
"'admin.api.regions.countries'",
")",
",",
"'newFormUrl'",
"=>",
"route",
"(",
"'admin.api.form-manager'",
",",
"[",
"'regions-countries-new'",
"]",
")",
",",
"'editFormUrl'",
"=>",
"route",
"(",
"'admin.api.form-manager'",
",",
"[",
"'regions-countries-edit'",
"]",
")",
",",
"'imagesUrl'",
"=>",
"route",
"(",
"'resource.get'",
",",
"[",
"'/'",
"]",
")",
",",
"'headers'",
"=>",
"$",
"this",
"->",
"getAdminListHeader",
"(",
")",
",",
"]",
";",
"if",
"(",
"auth",
"(",
")",
"->",
"user",
"(",
")",
"->",
"can",
"(",
"'interactivesolutions_honeycomb_regions_regions_countries_update'",
")",
")",
"$",
"config",
"[",
"'actions'",
"]",
"[",
"]",
"=",
"'update'",
";",
"$",
"config",
"[",
"'actions'",
"]",
"[",
"]",
"=",
"'search'",
";",
"$",
"config",
"[",
"'filters'",
"]",
"=",
"$",
"this",
"->",
"getFilters",
"(",
")",
";",
"return",
"hcview",
"(",
"'HCCoreUI::admin.content.list'",
",",
"[",
"'config'",
"=>",
"$",
"config",
"]",
")",
";",
"}"
] | Returning configured admin view
@return \Illuminate\Contracts\View\Factory|\Illuminate\View\View | [
"Returning",
"configured",
"admin",
"view"
] | train | https://github.com/interactivesolutions/honeycomb-regions/blob/80ecc48563b04910870515dc84f03b9189070368/src/app/http/controllers/regions/HCCountriesController.php#L18-L36 |
interactivesolutions/honeycomb-regions | src/app/http/controllers/regions/HCCountriesController.php | HCCountriesController.__apiUpdate | protected function __apiUpdate(string $id)
{
$record = HCCountries::findOrFail($id);
$record->languages()->sync(array_get($this->getInputData(), 'languages'));
return $this->apiShow($record->id);
} | php | protected function __apiUpdate(string $id)
{
$record = HCCountries::findOrFail($id);
$record->languages()->sync(array_get($this->getInputData(), 'languages'));
return $this->apiShow($record->id);
} | [
"protected",
"function",
"__apiUpdate",
"(",
"string",
"$",
"id",
")",
"{",
"$",
"record",
"=",
"HCCountries",
"::",
"findOrFail",
"(",
"$",
"id",
")",
";",
"$",
"record",
"->",
"languages",
"(",
")",
"->",
"sync",
"(",
"array_get",
"(",
"$",
"this",
"->",
"getInputData",
"(",
")",
",",
"'languages'",
")",
")",
";",
"return",
"$",
"this",
"->",
"apiShow",
"(",
"$",
"record",
"->",
"id",
")",
";",
"}"
] | Updates existing item based on ID
@param $id
@return mixed | [
"Updates",
"existing",
"item",
"based",
"on",
"ID"
] | train | https://github.com/interactivesolutions/honeycomb-regions/blob/80ecc48563b04910870515dc84f03b9189070368/src/app/http/controllers/regions/HCCountriesController.php#L83-L89 |
interactivesolutions/honeycomb-regions | src/app/http/controllers/regions/HCCountriesController.php | HCCountriesController.getInputData | protected function getInputData()
{
(new HCCountriesValidator())->validateForm();
$_data = request()->all();
array_set($data, 'languages', array_get($_data, 'languages'));
return $data;
} | php | protected function getInputData()
{
(new HCCountriesValidator())->validateForm();
$_data = request()->all();
array_set($data, 'languages', array_get($_data, 'languages'));
return $data;
} | [
"protected",
"function",
"getInputData",
"(",
")",
"{",
"(",
"new",
"HCCountriesValidator",
"(",
")",
")",
"->",
"validateForm",
"(",
")",
";",
"$",
"_data",
"=",
"request",
"(",
")",
"->",
"all",
"(",
")",
";",
"array_set",
"(",
"$",
"data",
",",
"'languages'",
",",
"array_get",
"(",
"$",
"_data",
",",
"'languages'",
")",
")",
";",
"return",
"$",
"data",
";",
"}"
] | Getting user data on POST call
@return mixed | [
"Getting",
"user",
"data",
"on",
"POST",
"call"
] | train | https://github.com/interactivesolutions/honeycomb-regions/blob/80ecc48563b04910870515dc84f03b9189070368/src/app/http/controllers/regions/HCCountriesController.php#L147-L156 |
interactivesolutions/honeycomb-regions | src/app/http/controllers/regions/HCCountriesController.php | HCCountriesController.getFilters | private function getFilters()
{
$filters = [];
$regions = [
'fieldID' => 'region_id',
'type' => 'dropDownList',
'label' => trans('HCRegions::regions_countries.region'),
'options' => HCContinents::all()->toArray(),
'showNodes' => ['name'],
];
$filters[] = addAllOptionToDropDownList($regions);
return $filters;
} | php | private function getFilters()
{
$filters = [];
$regions = [
'fieldID' => 'region_id',
'type' => 'dropDownList',
'label' => trans('HCRegions::regions_countries.region'),
'options' => HCContinents::all()->toArray(),
'showNodes' => ['name'],
];
$filters[] = addAllOptionToDropDownList($regions);
return $filters;
} | [
"private",
"function",
"getFilters",
"(",
")",
"{",
"$",
"filters",
"=",
"[",
"]",
";",
"$",
"regions",
"=",
"[",
"'fieldID'",
"=>",
"'region_id'",
",",
"'type'",
"=>",
"'dropDownList'",
",",
"'label'",
"=>",
"trans",
"(",
"'HCRegions::regions_countries.region'",
")",
",",
"'options'",
"=>",
"HCContinents",
"::",
"all",
"(",
")",
"->",
"toArray",
"(",
")",
",",
"'showNodes'",
"=>",
"[",
"'name'",
"]",
",",
"]",
";",
"$",
"filters",
"[",
"]",
"=",
"addAllOptionToDropDownList",
"(",
"$",
"regions",
")",
";",
"return",
"$",
"filters",
";",
"}"
] | Generating filters required for admin view
@return array | [
"Generating",
"filters",
"required",
"for",
"admin",
"view"
] | train | https://github.com/interactivesolutions/honeycomb-regions/blob/80ecc48563b04910870515dc84f03b9189070368/src/app/http/controllers/regions/HCCountriesController.php#L183-L198 |
WasabiLib/wasabilib | src/WasabiLib/Wizard/ClosureArguments.php | ClosureArguments.get | public function get($key) {
return isset($this->_elements[$key]) ? $this->_elements[$key] : null;
} | php | public function get($key) {
return isset($this->_elements[$key]) ? $this->_elements[$key] : null;
} | [
"public",
"function",
"get",
"(",
"$",
"key",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"_elements",
"[",
"$",
"key",
"]",
")",
"?",
"$",
"this",
"->",
"_elements",
"[",
"$",
"key",
"]",
":",
"null",
";",
"}"
] | Returns a value of an element in the list.
@param string $key
@return mixed | [
"Returns",
"a",
"value",
"of",
"an",
"element",
"in",
"the",
"list",
"."
] | train | https://github.com/WasabiLib/wasabilib/blob/5a55bfbea6b6ee10222c521112d469015db170b7/src/WasabiLib/Wizard/ClosureArguments.php#L62-L64 |
tux-rampage/rampage-php | library/rampage/core/ServiceCallbackDelegator.php | ServiceCallbackDelegator.setServiceLocator | public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
{
$this->serviceLocator = $serviceLocator;
$this->callback = null;
return $this;
} | php | public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
{
$this->serviceLocator = $serviceLocator;
$this->callback = null;
return $this;
} | [
"public",
"function",
"setServiceLocator",
"(",
"ServiceLocatorInterface",
"$",
"serviceLocator",
")",
"{",
"$",
"this",
"->",
"serviceLocator",
"=",
"$",
"serviceLocator",
";",
"$",
"this",
"->",
"callback",
"=",
"null",
";",
"return",
"$",
"this",
";",
"}"
] | {@inheritdoc}
@see \Zend\ServiceManager\ServiceLocatorAwareInterface::setServiceLocator() | [
"{"
] | train | https://github.com/tux-rampage/rampage-php/blob/1c679b04a6d477e2f8fdb86135e1d9f0c128b1cf/library/rampage/core/ServiceCallbackDelegator.php#L74-L80 |
radnan/rdn-factory | src/RdnFactory/Factory/Plugin/PluginManager.php | PluginManager.createService | public function createService(ServiceLocatorInterface $services)
{
$config = $services->get('Config');
$config = new Config($config['rdn_factory_plugins']);
$plugins = new Plugin\PluginManager($config);
$plugins->setServiceLocator($services);
return $plugins;
} | php | public function createService(ServiceLocatorInterface $services)
{
$config = $services->get('Config');
$config = new Config($config['rdn_factory_plugins']);
$plugins = new Plugin\PluginManager($config);
$plugins->setServiceLocator($services);
return $plugins;
} | [
"public",
"function",
"createService",
"(",
"ServiceLocatorInterface",
"$",
"services",
")",
"{",
"$",
"config",
"=",
"$",
"services",
"->",
"get",
"(",
"'Config'",
")",
";",
"$",
"config",
"=",
"new",
"Config",
"(",
"$",
"config",
"[",
"'rdn_factory_plugins'",
"]",
")",
";",
"$",
"plugins",
"=",
"new",
"Plugin",
"\\",
"PluginManager",
"(",
"$",
"config",
")",
";",
"$",
"plugins",
"->",
"setServiceLocator",
"(",
"$",
"services",
")",
";",
"return",
"$",
"plugins",
";",
"}"
] | Create service
@param ServiceLocatorInterface $services
@return mixed | [
"Create",
"service"
] | train | https://github.com/radnan/rdn-factory/blob/7efb4b37ade8f2cb15c675f7b390b6338cdae91a/src/RdnFactory/Factory/Plugin/PluginManager.php#L18-L27 |
cityware/city-components | src/Folder.php | Folder.read | public function read($sort = true, $exceptions = false, $fullPath = false)
{
$dirs = $files = array();
if (!$this->pwd()) {
return array($dirs, $files);
}
if (is_array($exceptions)) {
$exceptions = array_flip($exceptions);
}
$skipHidden = isset($exceptions['.']) || $exceptions === true;
try {
$iterator = new DirectoryIterator($this->path);
} catch (\Exception $e) {
return array($dirs, $files);
}
foreach ($iterator as $item) {
if ($item->isDot()) {
continue;
}
$name = $item->getFileName();
if ($skipHidden && $name[0] === '.' || isset($exceptions[$name])) {
continue;
}
if ($fullPath) {
$name = $item->getPathName();
}
if ($item->isDir()) {
$dirs[] = $name;
} else {
$files[] = $name;
}
}
if ($sort || $this->sort) {
sort($dirs);
sort($files);
}
return array($dirs, $files);
} | php | public function read($sort = true, $exceptions = false, $fullPath = false)
{
$dirs = $files = array();
if (!$this->pwd()) {
return array($dirs, $files);
}
if (is_array($exceptions)) {
$exceptions = array_flip($exceptions);
}
$skipHidden = isset($exceptions['.']) || $exceptions === true;
try {
$iterator = new DirectoryIterator($this->path);
} catch (\Exception $e) {
return array($dirs, $files);
}
foreach ($iterator as $item) {
if ($item->isDot()) {
continue;
}
$name = $item->getFileName();
if ($skipHidden && $name[0] === '.' || isset($exceptions[$name])) {
continue;
}
if ($fullPath) {
$name = $item->getPathName();
}
if ($item->isDir()) {
$dirs[] = $name;
} else {
$files[] = $name;
}
}
if ($sort || $this->sort) {
sort($dirs);
sort($files);
}
return array($dirs, $files);
} | [
"public",
"function",
"read",
"(",
"$",
"sort",
"=",
"true",
",",
"$",
"exceptions",
"=",
"false",
",",
"$",
"fullPath",
"=",
"false",
")",
"{",
"$",
"dirs",
"=",
"$",
"files",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"pwd",
"(",
")",
")",
"{",
"return",
"array",
"(",
"$",
"dirs",
",",
"$",
"files",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"exceptions",
")",
")",
"{",
"$",
"exceptions",
"=",
"array_flip",
"(",
"$",
"exceptions",
")",
";",
"}",
"$",
"skipHidden",
"=",
"isset",
"(",
"$",
"exceptions",
"[",
"'.'",
"]",
")",
"||",
"$",
"exceptions",
"===",
"true",
";",
"try",
"{",
"$",
"iterator",
"=",
"new",
"DirectoryIterator",
"(",
"$",
"this",
"->",
"path",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"return",
"array",
"(",
"$",
"dirs",
",",
"$",
"files",
")",
";",
"}",
"foreach",
"(",
"$",
"iterator",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"->",
"isDot",
"(",
")",
")",
"{",
"continue",
";",
"}",
"$",
"name",
"=",
"$",
"item",
"->",
"getFileName",
"(",
")",
";",
"if",
"(",
"$",
"skipHidden",
"&&",
"$",
"name",
"[",
"0",
"]",
"===",
"'.'",
"||",
"isset",
"(",
"$",
"exceptions",
"[",
"$",
"name",
"]",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"fullPath",
")",
"{",
"$",
"name",
"=",
"$",
"item",
"->",
"getPathName",
"(",
")",
";",
"}",
"if",
"(",
"$",
"item",
"->",
"isDir",
"(",
")",
")",
"{",
"$",
"dirs",
"[",
"]",
"=",
"$",
"name",
";",
"}",
"else",
"{",
"$",
"files",
"[",
"]",
"=",
"$",
"name",
";",
"}",
"}",
"if",
"(",
"$",
"sort",
"||",
"$",
"this",
"->",
"sort",
")",
"{",
"sort",
"(",
"$",
"dirs",
")",
";",
"sort",
"(",
"$",
"files",
")",
";",
"}",
"return",
"array",
"(",
"$",
"dirs",
",",
"$",
"files",
")",
";",
"}"
] | Returns an array of the contents of the current directory.
The returned array holds two arrays: One of directories and one of files.
@param boolean $sort Whether you want the results sorted, set this and the sort property
to false to get unsorted results.
@param array|boolean $exceptions Either an array or boolean true will not grab dot files
@param boolean $fullPath True returns the full path
@return mixed Contents of current directory as an array, an empty array on failure | [
"Returns",
"an",
"array",
"of",
"the",
"contents",
"of",
"the",
"current",
"directory",
".",
"The",
"returned",
"array",
"holds",
"two",
"arrays",
":",
"One",
"of",
"directories",
"and",
"one",
"of",
"files",
"."
] | train | https://github.com/cityware/city-components/blob/103211a4896f7e9ecdccec2ee9bf26239d52faa0/src/Folder.php#L158-L199 |
cityware/city-components | src/Folder.php | Folder._findRecursive | protected function _findRecursive($pattern, $sort = false)
{
list($dirs, $files) = $this->read($sort);
$found = array();
foreach ($files as $file) {
if (preg_match('/^' . $pattern . '$/i', $file)) {
$found[] = Folder::addPathElement($this->path, $file);
}
}
$start = $this->path;
foreach ($dirs as $dir) {
$this->cd(Folder::addPathElement($start, $dir));
$found = array_merge($found, $this->findRecursive($pattern, $sort));
}
return $found;
} | php | protected function _findRecursive($pattern, $sort = false)
{
list($dirs, $files) = $this->read($sort);
$found = array();
foreach ($files as $file) {
if (preg_match('/^' . $pattern . '$/i', $file)) {
$found[] = Folder::addPathElement($this->path, $file);
}
}
$start = $this->path;
foreach ($dirs as $dir) {
$this->cd(Folder::addPathElement($start, $dir));
$found = array_merge($found, $this->findRecursive($pattern, $sort));
}
return $found;
} | [
"protected",
"function",
"_findRecursive",
"(",
"$",
"pattern",
",",
"$",
"sort",
"=",
"false",
")",
"{",
"list",
"(",
"$",
"dirs",
",",
"$",
"files",
")",
"=",
"$",
"this",
"->",
"read",
"(",
"$",
"sort",
")",
";",
"$",
"found",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/^'",
".",
"$",
"pattern",
".",
"'$/i'",
",",
"$",
"file",
")",
")",
"{",
"$",
"found",
"[",
"]",
"=",
"Folder",
"::",
"addPathElement",
"(",
"$",
"this",
"->",
"path",
",",
"$",
"file",
")",
";",
"}",
"}",
"$",
"start",
"=",
"$",
"this",
"->",
"path",
";",
"foreach",
"(",
"$",
"dirs",
"as",
"$",
"dir",
")",
"{",
"$",
"this",
"->",
"cd",
"(",
"Folder",
"::",
"addPathElement",
"(",
"$",
"start",
",",
"$",
"dir",
")",
")",
";",
"$",
"found",
"=",
"array_merge",
"(",
"$",
"found",
",",
"$",
"this",
"->",
"findRecursive",
"(",
"$",
"pattern",
",",
"$",
"sort",
")",
")",
";",
"}",
"return",
"$",
"found",
";",
"}"
] | Private helper function for findRecursive.
@param string $pattern Pattern to match against
@param boolean $sort Whether results should be sorted.
@return array Files matching pattern | [
"Private",
"helper",
"function",
"for",
"findRecursive",
"."
] | train | https://github.com/cityware/city-components/blob/103211a4896f7e9ecdccec2ee9bf26239d52faa0/src/Folder.php#L241-L259 |
cityware/city-components | src/Folder.php | Folder.inPath | public function inPath($path = '', $reverse = false)
{
$dir = Folder::slashTerm($path);
$current = Folder::slashTerm($this->pwd());
if (!$reverse) {
$return = preg_match('/^(.*)' . preg_quote($dir, '/') . '(.*)/', $current);
} else {
$return = preg_match('/^(.*)' . preg_quote($current, '/') . '(.*)/', $dir);
}
return (bool) $return;
} | php | public function inPath($path = '', $reverse = false)
{
$dir = Folder::slashTerm($path);
$current = Folder::slashTerm($this->pwd());
if (!$reverse) {
$return = preg_match('/^(.*)' . preg_quote($dir, '/') . '(.*)/', $current);
} else {
$return = preg_match('/^(.*)' . preg_quote($current, '/') . '(.*)/', $dir);
}
return (bool) $return;
} | [
"public",
"function",
"inPath",
"(",
"$",
"path",
"=",
"''",
",",
"$",
"reverse",
"=",
"false",
")",
"{",
"$",
"dir",
"=",
"Folder",
"::",
"slashTerm",
"(",
"$",
"path",
")",
";",
"$",
"current",
"=",
"Folder",
"::",
"slashTerm",
"(",
"$",
"this",
"->",
"pwd",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"reverse",
")",
"{",
"$",
"return",
"=",
"preg_match",
"(",
"'/^(.*)'",
".",
"preg_quote",
"(",
"$",
"dir",
",",
"'/'",
")",
".",
"'(.*)/'",
",",
"$",
"current",
")",
";",
"}",
"else",
"{",
"$",
"return",
"=",
"preg_match",
"(",
"'/^(.*)'",
".",
"preg_quote",
"(",
"$",
"current",
",",
"'/'",
")",
".",
"'(.*)/'",
",",
"$",
"dir",
")",
";",
"}",
"return",
"(",
"bool",
")",
"$",
"return",
";",
"}"
] | Returns true if the File is in given path.
@param string $path The path to check that the current pwd() resides with in.
@param boolean $reverse Reverse the search, check that pwd() resides within $path.
@return boolean | [
"Returns",
"true",
"if",
"the",
"File",
"is",
"in",
"given",
"path",
"."
] | train | https://github.com/cityware/city-components/blob/103211a4896f7e9ecdccec2ee9bf26239d52faa0/src/Folder.php#L353-L365 |
cityware/city-components | src/Folder.php | Folder.chmod | public function chmod($path, $mode = false, $recursive = true, $exceptions = array())
{
if (!$mode) {
$mode = $this->mode;
}
if ($recursive === false && is_dir($path)) {
//@codingStandardsIgnoreStart
if (@chmod($path, intval($mode, 8))) {
//@codingStandardsIgnoreEnd
$this->_messages[] = __d('cake_dev', '%s changed to %s', $path, $mode);
return true;
}
$this->_errors[] = __d('cake_dev', '%s NOT changed to %s', $path, $mode);
return false;
}
if (is_dir($path)) {
$paths = $this->tree($path);
foreach ($paths as $type) {
foreach ($type as $fullpath) {
$check = explode(DS, $fullpath);
$count = count($check);
if (in_array($check[$count - 1], $exceptions)) {
continue;
}
//@codingStandardsIgnoreStart
if (@chmod($fullpath, intval($mode, 8))) {
//@codingStandardsIgnoreEnd
$this->_messages[] = __d('cake_dev', '%s changed to %s', $fullpath, $mode);
} else {
$this->_errors[] = __d('cake_dev', '%s NOT changed to %s', $fullpath, $mode);
}
}
}
if (empty($this->_errors)) {
return true;
}
}
return false;
} | php | public function chmod($path, $mode = false, $recursive = true, $exceptions = array())
{
if (!$mode) {
$mode = $this->mode;
}
if ($recursive === false && is_dir($path)) {
//@codingStandardsIgnoreStart
if (@chmod($path, intval($mode, 8))) {
//@codingStandardsIgnoreEnd
$this->_messages[] = __d('cake_dev', '%s changed to %s', $path, $mode);
return true;
}
$this->_errors[] = __d('cake_dev', '%s NOT changed to %s', $path, $mode);
return false;
}
if (is_dir($path)) {
$paths = $this->tree($path);
foreach ($paths as $type) {
foreach ($type as $fullpath) {
$check = explode(DS, $fullpath);
$count = count($check);
if (in_array($check[$count - 1], $exceptions)) {
continue;
}
//@codingStandardsIgnoreStart
if (@chmod($fullpath, intval($mode, 8))) {
//@codingStandardsIgnoreEnd
$this->_messages[] = __d('cake_dev', '%s changed to %s', $fullpath, $mode);
} else {
$this->_errors[] = __d('cake_dev', '%s NOT changed to %s', $fullpath, $mode);
}
}
}
if (empty($this->_errors)) {
return true;
}
}
return false;
} | [
"public",
"function",
"chmod",
"(",
"$",
"path",
",",
"$",
"mode",
"=",
"false",
",",
"$",
"recursive",
"=",
"true",
",",
"$",
"exceptions",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"mode",
")",
"{",
"$",
"mode",
"=",
"$",
"this",
"->",
"mode",
";",
"}",
"if",
"(",
"$",
"recursive",
"===",
"false",
"&&",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"//@codingStandardsIgnoreStart",
"if",
"(",
"@",
"chmod",
"(",
"$",
"path",
",",
"intval",
"(",
"$",
"mode",
",",
"8",
")",
")",
")",
"{",
"//@codingStandardsIgnoreEnd",
"$",
"this",
"->",
"_messages",
"[",
"]",
"=",
"__d",
"(",
"'cake_dev'",
",",
"'%s changed to %s'",
",",
"$",
"path",
",",
"$",
"mode",
")",
";",
"return",
"true",
";",
"}",
"$",
"this",
"->",
"_errors",
"[",
"]",
"=",
"__d",
"(",
"'cake_dev'",
",",
"'%s NOT changed to %s'",
",",
"$",
"path",
",",
"$",
"mode",
")",
";",
"return",
"false",
";",
"}",
"if",
"(",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"$",
"paths",
"=",
"$",
"this",
"->",
"tree",
"(",
"$",
"path",
")",
";",
"foreach",
"(",
"$",
"paths",
"as",
"$",
"type",
")",
"{",
"foreach",
"(",
"$",
"type",
"as",
"$",
"fullpath",
")",
"{",
"$",
"check",
"=",
"explode",
"(",
"DS",
",",
"$",
"fullpath",
")",
";",
"$",
"count",
"=",
"count",
"(",
"$",
"check",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"check",
"[",
"$",
"count",
"-",
"1",
"]",
",",
"$",
"exceptions",
")",
")",
"{",
"continue",
";",
"}",
"//@codingStandardsIgnoreStart",
"if",
"(",
"@",
"chmod",
"(",
"$",
"fullpath",
",",
"intval",
"(",
"$",
"mode",
",",
"8",
")",
")",
")",
"{",
"//@codingStandardsIgnoreEnd",
"$",
"this",
"->",
"_messages",
"[",
"]",
"=",
"__d",
"(",
"'cake_dev'",
",",
"'%s changed to %s'",
",",
"$",
"fullpath",
",",
"$",
"mode",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_errors",
"[",
"]",
"=",
"__d",
"(",
"'cake_dev'",
",",
"'%s NOT changed to %s'",
",",
"$",
"fullpath",
",",
"$",
"mode",
")",
";",
"}",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_errors",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Change the mode on a directory structure recursively. This includes changing the mode on files as well.
@param string $path The path to chmod
@param integer $mode octal value 0755
@param boolean $recursive chmod recursively, set to false to only change the current directory.
@param array $exceptions array of files, directories to skip
@return boolean Returns TRUE on success, FALSE on failure | [
"Change",
"the",
"mode",
"on",
"a",
"directory",
"structure",
"recursively",
".",
"This",
"includes",
"changing",
"the",
"mode",
"on",
"files",
"as",
"well",
"."
] | train | https://github.com/cityware/city-components/blob/103211a4896f7e9ecdccec2ee9bf26239d52faa0/src/Folder.php#L376-L424 |
cityware/city-components | src/Folder.php | Folder.tree | public function tree($path = null, $exceptions = false, $type = null)
{
if (!$path) {
$path = $this->path;
}
$files = array();
$directories = array($path);
if (is_array($exceptions)) {
$exceptions = array_flip($exceptions);
}
$skipHidden = false;
if ($exceptions === true) {
$skipHidden = true;
} elseif (isset($exceptions['.'])) {
$skipHidden = true;
unset($exceptions['.']);
}
try {
$directory = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::KEY_AS_PATHNAME | RecursiveDirectoryIterator::CURRENT_AS_SELF);
$iterator = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::SELF_FIRST);
} catch (Exception $e) {
if ($type === null) {
return array(array(), array());
}
return array();
}
foreach ($iterator as $itemPath => $fsIterator) {
if ($skipHidden) {
$subPathName = $fsIterator->getSubPathname();
if ($subPathName{0} === '.' || strpos($subPathName, DS . '.') !== false) {
continue;
}
}
$item = $fsIterator->current();
if (!empty($exceptions) && isset($exceptions[$item->getFilename()])) {
continue;
}
if ($item->isFile()) {
$files[] = $itemPath;
} elseif ($item->isDir() && !$item->isDot()) {
$directories[] = $itemPath;
}
}
if ($type === null) {
return array($directories, $files);
}
if ($type === 'dir') {
return $directories;
}
return $files;
} | php | public function tree($path = null, $exceptions = false, $type = null)
{
if (!$path) {
$path = $this->path;
}
$files = array();
$directories = array($path);
if (is_array($exceptions)) {
$exceptions = array_flip($exceptions);
}
$skipHidden = false;
if ($exceptions === true) {
$skipHidden = true;
} elseif (isset($exceptions['.'])) {
$skipHidden = true;
unset($exceptions['.']);
}
try {
$directory = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::KEY_AS_PATHNAME | RecursiveDirectoryIterator::CURRENT_AS_SELF);
$iterator = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::SELF_FIRST);
} catch (Exception $e) {
if ($type === null) {
return array(array(), array());
}
return array();
}
foreach ($iterator as $itemPath => $fsIterator) {
if ($skipHidden) {
$subPathName = $fsIterator->getSubPathname();
if ($subPathName{0} === '.' || strpos($subPathName, DS . '.') !== false) {
continue;
}
}
$item = $fsIterator->current();
if (!empty($exceptions) && isset($exceptions[$item->getFilename()])) {
continue;
}
if ($item->isFile()) {
$files[] = $itemPath;
} elseif ($item->isDir() && !$item->isDot()) {
$directories[] = $itemPath;
}
}
if ($type === null) {
return array($directories, $files);
}
if ($type === 'dir') {
return $directories;
}
return $files;
} | [
"public",
"function",
"tree",
"(",
"$",
"path",
"=",
"null",
",",
"$",
"exceptions",
"=",
"false",
",",
"$",
"type",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"path",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"path",
";",
"}",
"$",
"files",
"=",
"array",
"(",
")",
";",
"$",
"directories",
"=",
"array",
"(",
"$",
"path",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"exceptions",
")",
")",
"{",
"$",
"exceptions",
"=",
"array_flip",
"(",
"$",
"exceptions",
")",
";",
"}",
"$",
"skipHidden",
"=",
"false",
";",
"if",
"(",
"$",
"exceptions",
"===",
"true",
")",
"{",
"$",
"skipHidden",
"=",
"true",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"exceptions",
"[",
"'.'",
"]",
")",
")",
"{",
"$",
"skipHidden",
"=",
"true",
";",
"unset",
"(",
"$",
"exceptions",
"[",
"'.'",
"]",
")",
";",
"}",
"try",
"{",
"$",
"directory",
"=",
"new",
"RecursiveDirectoryIterator",
"(",
"$",
"path",
",",
"RecursiveDirectoryIterator",
"::",
"KEY_AS_PATHNAME",
"|",
"RecursiveDirectoryIterator",
"::",
"CURRENT_AS_SELF",
")",
";",
"$",
"iterator",
"=",
"new",
"RecursiveIteratorIterator",
"(",
"$",
"directory",
",",
"RecursiveIteratorIterator",
"::",
"SELF_FIRST",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"type",
"===",
"null",
")",
"{",
"return",
"array",
"(",
"array",
"(",
")",
",",
"array",
"(",
")",
")",
";",
"}",
"return",
"array",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"iterator",
"as",
"$",
"itemPath",
"=>",
"$",
"fsIterator",
")",
"{",
"if",
"(",
"$",
"skipHidden",
")",
"{",
"$",
"subPathName",
"=",
"$",
"fsIterator",
"->",
"getSubPathname",
"(",
")",
";",
"if",
"(",
"$",
"subPathName",
"{",
"0",
"}",
"===",
"'.'",
"||",
"strpos",
"(",
"$",
"subPathName",
",",
"DS",
".",
"'.'",
")",
"!==",
"false",
")",
"{",
"continue",
";",
"}",
"}",
"$",
"item",
"=",
"$",
"fsIterator",
"->",
"current",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"exceptions",
")",
"&&",
"isset",
"(",
"$",
"exceptions",
"[",
"$",
"item",
"->",
"getFilename",
"(",
")",
"]",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"item",
"->",
"isFile",
"(",
")",
")",
"{",
"$",
"files",
"[",
"]",
"=",
"$",
"itemPath",
";",
"}",
"elseif",
"(",
"$",
"item",
"->",
"isDir",
"(",
")",
"&&",
"!",
"$",
"item",
"->",
"isDot",
"(",
")",
")",
"{",
"$",
"directories",
"[",
"]",
"=",
"$",
"itemPath",
";",
"}",
"}",
"if",
"(",
"$",
"type",
"===",
"null",
")",
"{",
"return",
"array",
"(",
"$",
"directories",
",",
"$",
"files",
")",
";",
"}",
"if",
"(",
"$",
"type",
"===",
"'dir'",
")",
"{",
"return",
"$",
"directories",
";",
"}",
"return",
"$",
"files",
";",
"}"
] | Returns an array of nested directories and files in each directory
@param string $path the directory path to build the tree from
@param array|boolean $exceptions Either an array of files/folder to exclude
or boolean true to not grab dot files/folders
@param string $type either 'file' or 'dir'. null returns both files and directories
@return mixed array of nested directories and files in each directory | [
"Returns",
"an",
"array",
"of",
"nested",
"directories",
"and",
"files",
"in",
"each",
"directory"
] | train | https://github.com/cityware/city-components/blob/103211a4896f7e9ecdccec2ee9bf26239d52faa0/src/Folder.php#L435-L491 |
cityware/city-components | src/Folder.php | Folder.create | public function create($pathname, $mode = false)
{
if (is_dir($pathname) || empty($pathname)) {
return true;
}
if (!$mode) {
$mode = $this->mode;
}
if (is_file($pathname)) {
$this->_errors[] = __d('cake_dev', '%s is a file', $pathname);
return false;
}
$pathname = rtrim($pathname, DS);
$nextPathname = substr($pathname, 0, strrpos($pathname, DS));
if ($this->create($nextPathname, $mode)) {
if (!file_exists($pathname)) {
$old = umask(0);
if (mkdir($pathname, $mode)) {
umask($old);
$this->_messages[] = __d('cake_dev', '%s created', $pathname);
return true;
}
umask($old);
$this->_errors[] = __d('cake_dev', '%s NOT created', $pathname);
return false;
}
}
return false;
} | php | public function create($pathname, $mode = false)
{
if (is_dir($pathname) || empty($pathname)) {
return true;
}
if (!$mode) {
$mode = $this->mode;
}
if (is_file($pathname)) {
$this->_errors[] = __d('cake_dev', '%s is a file', $pathname);
return false;
}
$pathname = rtrim($pathname, DS);
$nextPathname = substr($pathname, 0, strrpos($pathname, DS));
if ($this->create($nextPathname, $mode)) {
if (!file_exists($pathname)) {
$old = umask(0);
if (mkdir($pathname, $mode)) {
umask($old);
$this->_messages[] = __d('cake_dev', '%s created', $pathname);
return true;
}
umask($old);
$this->_errors[] = __d('cake_dev', '%s NOT created', $pathname);
return false;
}
}
return false;
} | [
"public",
"function",
"create",
"(",
"$",
"pathname",
",",
"$",
"mode",
"=",
"false",
")",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"pathname",
")",
"||",
"empty",
"(",
"$",
"pathname",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"!",
"$",
"mode",
")",
"{",
"$",
"mode",
"=",
"$",
"this",
"->",
"mode",
";",
"}",
"if",
"(",
"is_file",
"(",
"$",
"pathname",
")",
")",
"{",
"$",
"this",
"->",
"_errors",
"[",
"]",
"=",
"__d",
"(",
"'cake_dev'",
",",
"'%s is a file'",
",",
"$",
"pathname",
")",
";",
"return",
"false",
";",
"}",
"$",
"pathname",
"=",
"rtrim",
"(",
"$",
"pathname",
",",
"DS",
")",
";",
"$",
"nextPathname",
"=",
"substr",
"(",
"$",
"pathname",
",",
"0",
",",
"strrpos",
"(",
"$",
"pathname",
",",
"DS",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"create",
"(",
"$",
"nextPathname",
",",
"$",
"mode",
")",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"pathname",
")",
")",
"{",
"$",
"old",
"=",
"umask",
"(",
"0",
")",
";",
"if",
"(",
"mkdir",
"(",
"$",
"pathname",
",",
"$",
"mode",
")",
")",
"{",
"umask",
"(",
"$",
"old",
")",
";",
"$",
"this",
"->",
"_messages",
"[",
"]",
"=",
"__d",
"(",
"'cake_dev'",
",",
"'%s created'",
",",
"$",
"pathname",
")",
";",
"return",
"true",
";",
"}",
"umask",
"(",
"$",
"old",
")",
";",
"$",
"this",
"->",
"_errors",
"[",
"]",
"=",
"__d",
"(",
"'cake_dev'",
",",
"'%s NOT created'",
",",
"$",
"pathname",
")",
";",
"return",
"false",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Create a directory structure recursively. Can be used to create
deep path structures like `/foo/bar/baz/shoe/horn`
@param string $pathname The directory structure to create
@param integer $mode octal value 0755
@return boolean Returns TRUE on success, FALSE on failure | [
"Create",
"a",
"directory",
"structure",
"recursively",
".",
"Can",
"be",
"used",
"to",
"create",
"deep",
"path",
"structures",
"like",
"/",
"foo",
"/",
"bar",
"/",
"baz",
"/",
"shoe",
"/",
"horn"
] | train | https://github.com/cityware/city-components/blob/103211a4896f7e9ecdccec2ee9bf26239d52faa0/src/Folder.php#L501-L536 |
cityware/city-components | src/Folder.php | Folder.messages | public function messages($reset = true)
{
$messages = $this->_messages;
if ($reset) {
$this->_messages = array();
}
return $messages;
} | php | public function messages($reset = true)
{
$messages = $this->_messages;
if ($reset) {
$this->_messages = array();
}
return $messages;
} | [
"public",
"function",
"messages",
"(",
"$",
"reset",
"=",
"true",
")",
"{",
"$",
"messages",
"=",
"$",
"this",
"->",
"_messages",
";",
"if",
"(",
"$",
"reset",
")",
"{",
"$",
"this",
"->",
"_messages",
"=",
"array",
"(",
")",
";",
"}",
"return",
"$",
"messages",
";",
"}"
] | get messages from latest method
@param boolean $reset Reset message stack after reading
@return array | [
"get",
"messages",
"from",
"latest",
"method"
] | train | https://github.com/cityware/city-components/blob/103211a4896f7e9ecdccec2ee9bf26239d52faa0/src/Folder.php#L775-L783 |
cityware/city-components | src/Folder.php | Folder.errors | public function errors($reset = true)
{
$errors = $this->_errors;
if ($reset) {
$this->_errors = array();
}
return $errors;
} | php | public function errors($reset = true)
{
$errors = $this->_errors;
if ($reset) {
$this->_errors = array();
}
return $errors;
} | [
"public",
"function",
"errors",
"(",
"$",
"reset",
"=",
"true",
")",
"{",
"$",
"errors",
"=",
"$",
"this",
"->",
"_errors",
";",
"if",
"(",
"$",
"reset",
")",
"{",
"$",
"this",
"->",
"_errors",
"=",
"array",
"(",
")",
";",
"}",
"return",
"$",
"errors",
";",
"}"
] | get error from latest method
@param boolean $reset Reset error stack after reading
@return array | [
"get",
"error",
"from",
"latest",
"method"
] | train | https://github.com/cityware/city-components/blob/103211a4896f7e9ecdccec2ee9bf26239d52faa0/src/Folder.php#L791-L799 |
cityware/city-components | src/Folder.php | Folder.realpath | public function realpath($path)
{
$path = str_replace('/', DS, trim($path));
if (strpos($path, '..') === false) {
if (!Folder::isAbsolute($path)) {
$path = Folder::addPathElement($this->path, $path);
}
return $path;
}
$parts = explode(DS, $path);
$newparts = array();
$newpath = '';
if ($path[0] === DS) {
$newpath = DS;
}
while (($part = array_shift($parts)) !== null) {
if ($part === '.' || $part === '') {
continue;
}
if ($part === '..') {
if (!empty($newparts)) {
array_pop($newparts);
continue;
}
return false;
}
$newparts[] = $part;
}
$newpath .= implode(DS, $newparts);
return Folder::slashTerm($newpath);
} | php | public function realpath($path)
{
$path = str_replace('/', DS, trim($path));
if (strpos($path, '..') === false) {
if (!Folder::isAbsolute($path)) {
$path = Folder::addPathElement($this->path, $path);
}
return $path;
}
$parts = explode(DS, $path);
$newparts = array();
$newpath = '';
if ($path[0] === DS) {
$newpath = DS;
}
while (($part = array_shift($parts)) !== null) {
if ($part === '.' || $part === '') {
continue;
}
if ($part === '..') {
if (!empty($newparts)) {
array_pop($newparts);
continue;
}
return false;
}
$newparts[] = $part;
}
$newpath .= implode(DS, $newparts);
return Folder::slashTerm($newpath);
} | [
"public",
"function",
"realpath",
"(",
"$",
"path",
")",
"{",
"$",
"path",
"=",
"str_replace",
"(",
"'/'",
",",
"DS",
",",
"trim",
"(",
"$",
"path",
")",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"path",
",",
"'..'",
")",
"===",
"false",
")",
"{",
"if",
"(",
"!",
"Folder",
"::",
"isAbsolute",
"(",
"$",
"path",
")",
")",
"{",
"$",
"path",
"=",
"Folder",
"::",
"addPathElement",
"(",
"$",
"this",
"->",
"path",
",",
"$",
"path",
")",
";",
"}",
"return",
"$",
"path",
";",
"}",
"$",
"parts",
"=",
"explode",
"(",
"DS",
",",
"$",
"path",
")",
";",
"$",
"newparts",
"=",
"array",
"(",
")",
";",
"$",
"newpath",
"=",
"''",
";",
"if",
"(",
"$",
"path",
"[",
"0",
"]",
"===",
"DS",
")",
"{",
"$",
"newpath",
"=",
"DS",
";",
"}",
"while",
"(",
"(",
"$",
"part",
"=",
"array_shift",
"(",
"$",
"parts",
")",
")",
"!==",
"null",
")",
"{",
"if",
"(",
"$",
"part",
"===",
"'.'",
"||",
"$",
"part",
"===",
"''",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"part",
"===",
"'..'",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"newparts",
")",
")",
"{",
"array_pop",
"(",
"$",
"newparts",
")",
";",
"continue",
";",
"}",
"return",
"false",
";",
"}",
"$",
"newparts",
"[",
"]",
"=",
"$",
"part",
";",
"}",
"$",
"newpath",
".=",
"implode",
"(",
"DS",
",",
"$",
"newparts",
")",
";",
"return",
"Folder",
"::",
"slashTerm",
"(",
"$",
"newpath",
")",
";",
"}"
] | Get the real path (taking ".." and such into account)
@param string $path Path to resolve
@return string The resolved path | [
"Get",
"the",
"real",
"path",
"(",
"taking",
"..",
"and",
"such",
"into",
"account",
")"
] | train | https://github.com/cityware/city-components/blob/103211a4896f7e9ecdccec2ee9bf26239d52faa0/src/Folder.php#L807-L841 |
nullivex/lib-xport | LSS/Xport/Log.php | Log.setCallback | public function setCallback($callback){
if(!is_callable($callback))
throw new Exception('Invalid callback passed for logging: '.$callback);
$this->callback = $callback;
return $this;
} | php | public function setCallback($callback){
if(!is_callable($callback))
throw new Exception('Invalid callback passed for logging: '.$callback);
$this->callback = $callback;
return $this;
} | [
"public",
"function",
"setCallback",
"(",
"$",
"callback",
")",
"{",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"callback",
")",
")",
"throw",
"new",
"Exception",
"(",
"'Invalid callback passed for logging: '",
".",
"$",
"callback",
")",
";",
"$",
"this",
"->",
"callback",
"=",
"$",
"callback",
";",
"return",
"$",
"this",
";",
"}"
] | ----------------------------------------------------- | [
"-----------------------------------------------------"
] | train | https://github.com/nullivex/lib-xport/blob/87a2156d9d15a8eecbcab3e5a00326dc24b9e97e/LSS/Xport/Log.php#L53-L58 |
nullivex/lib-xport | LSS/Xport/Log.php | Log.add | public function add($msg,$level=self::INFO){
//dont log if we dont need to
if($level > $this->level || $this->level === false)
return false;
//fail if not initialized
if(!$this->sig || !$this->callback)
throw new Exception('Logging not initiated please call Vidcache->initLog()');
//format the message (gets further formatted by the callback
$msg = '['.$this->label.'] ['.$this->sig.'] - '.$msg;
//call to the logging function
return call_user_func_array($this->callback,array($msg,$level));
} | php | public function add($msg,$level=self::INFO){
//dont log if we dont need to
if($level > $this->level || $this->level === false)
return false;
//fail if not initialized
if(!$this->sig || !$this->callback)
throw new Exception('Logging not initiated please call Vidcache->initLog()');
//format the message (gets further formatted by the callback
$msg = '['.$this->label.'] ['.$this->sig.'] - '.$msg;
//call to the logging function
return call_user_func_array($this->callback,array($msg,$level));
} | [
"public",
"function",
"add",
"(",
"$",
"msg",
",",
"$",
"level",
"=",
"self",
"::",
"INFO",
")",
"{",
"//dont log if we dont need to",
"if",
"(",
"$",
"level",
">",
"$",
"this",
"->",
"level",
"||",
"$",
"this",
"->",
"level",
"===",
"false",
")",
"return",
"false",
";",
"//fail if not initialized",
"if",
"(",
"!",
"$",
"this",
"->",
"sig",
"||",
"!",
"$",
"this",
"->",
"callback",
")",
"throw",
"new",
"Exception",
"(",
"'Logging not initiated please call Vidcache->initLog()'",
")",
";",
"//format the message (gets further formatted by the callback",
"$",
"msg",
"=",
"'['",
".",
"$",
"this",
"->",
"label",
".",
"'] ['",
".",
"$",
"this",
"->",
"sig",
".",
"'] - '",
".",
"$",
"msg",
";",
"//call to the logging function",
"return",
"call_user_func_array",
"(",
"$",
"this",
"->",
"callback",
",",
"array",
"(",
"$",
"msg",
",",
"$",
"level",
")",
")",
";",
"}"
] | ----------------------------------------------------- | [
"-----------------------------------------------------"
] | train | https://github.com/nullivex/lib-xport/blob/87a2156d9d15a8eecbcab3e5a00326dc24b9e97e/LSS/Xport/Log.php#L97-L108 |
Clastic/UserBundle | DependencyInjection/ClasticUserExtension.php | ClasticUserExtension.prepend | public function prepend(ContainerBuilder $container)
{
$bundles = $container->getParameter('kernel.bundles');
if (true === isset($bundles['FOSUserBundle'])) {
$this->configureFOSUserBundle($container);
}
} | php | public function prepend(ContainerBuilder $container)
{
$bundles = $container->getParameter('kernel.bundles');
if (true === isset($bundles['FOSUserBundle'])) {
$this->configureFOSUserBundle($container);
}
} | [
"public",
"function",
"prepend",
"(",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"bundles",
"=",
"$",
"container",
"->",
"getParameter",
"(",
"'kernel.bundles'",
")",
";",
"if",
"(",
"true",
"===",
"isset",
"(",
"$",
"bundles",
"[",
"'FOSUserBundle'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"configureFOSUserBundle",
"(",
"$",
"container",
")",
";",
"}",
"}"
] | Allow an extension to prepend the extension configurations.
@param ContainerBuilder $container | [
"Allow",
"an",
"extension",
"to",
"prepend",
"the",
"extension",
"configurations",
"."
] | train | https://github.com/Clastic/UserBundle/blob/0d9f54a11d8ba9029331e032ce5f8fea09a90b5e/DependencyInjection/ClasticUserExtension.php#L37-L44 |
asbsoft/yii2-common_2_170212 | i18n/UniPhpMessageSource.php | UniPhpMessageSource.existsMessage | public function existsMessage($language, $category, $message)
{
$key = $language . '/' . $category;
if (!isset(static::$_messages[$key])) {
static::$_messages[$key] = $this->loadMessages($category, $language);
}
if (isset(static::$_messages[$key][$message]) && static::$_messages[$key][$message] !== '') return true;
else return false;
} | php | public function existsMessage($language, $category, $message)
{
$key = $language . '/' . $category;
if (!isset(static::$_messages[$key])) {
static::$_messages[$key] = $this->loadMessages($category, $language);
}
if (isset(static::$_messages[$key][$message]) && static::$_messages[$key][$message] !== '') return true;
else return false;
} | [
"public",
"function",
"existsMessage",
"(",
"$",
"language",
",",
"$",
"category",
",",
"$",
"message",
")",
"{",
"$",
"key",
"=",
"$",
"language",
".",
"'/'",
".",
"$",
"category",
";",
"if",
"(",
"!",
"isset",
"(",
"static",
"::",
"$",
"_messages",
"[",
"$",
"key",
"]",
")",
")",
"{",
"static",
"::",
"$",
"_messages",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"loadMessages",
"(",
"$",
"category",
",",
"$",
"language",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"_messages",
"[",
"$",
"key",
"]",
"[",
"$",
"message",
"]",
")",
"&&",
"static",
"::",
"$",
"_messages",
"[",
"$",
"key",
"]",
"[",
"$",
"message",
"]",
"!==",
"''",
")",
"return",
"true",
";",
"else",
"return",
"false",
";",
"}"
] | Check to exists message translation | [
"Check",
"to",
"exists",
"message",
"translation"
] | train | https://github.com/asbsoft/yii2-common_2_170212/blob/6c58012ff89225d7d4e42b200cf39e009e9d9dac/i18n/UniPhpMessageSource.php#L32-L40 |
asbsoft/yii2-common_2_170212 | i18n/UniPhpMessageSource.php | UniPhpMessageSource.getModuleByTransCategory | protected function getModuleByTransCategory($category)
{
foreach(TranslationsBuilder::$transCatToModule as $pattern => $module) {
if (0 === strpos($category, rtrim($pattern, '*'))) {
return $module;
}
}
} | php | protected function getModuleByTransCategory($category)
{
foreach(TranslationsBuilder::$transCatToModule as $pattern => $module) {
if (0 === strpos($category, rtrim($pattern, '*'))) {
return $module;
}
}
} | [
"protected",
"function",
"getModuleByTransCategory",
"(",
"$",
"category",
")",
"{",
"foreach",
"(",
"TranslationsBuilder",
"::",
"$",
"transCatToModule",
"as",
"$",
"pattern",
"=>",
"$",
"module",
")",
"{",
"if",
"(",
"0",
"===",
"strpos",
"(",
"$",
"category",
",",
"rtrim",
"(",
"$",
"pattern",
",",
"'*'",
")",
")",
")",
"{",
"return",
"$",
"module",
";",
"}",
"}",
"}"
] | Get module by translation category | [
"Get",
"module",
"by",
"translation",
"category"
] | train | https://github.com/asbsoft/yii2-common_2_170212/blob/6c58012ff89225d7d4e42b200cf39e009e9d9dac/i18n/UniPhpMessageSource.php#L43-L50 |
Clastic/AliasBundle | EventListener/NodeListener.php | NodeListener.validateUnique | private function validateUnique(Alias $alias, LifecycleEventArgs $args)
{
return (bool) $args->getObjectManager()
->getRepository('ClasticAliasBundle:Alias')
->findBy(array(
'alias' => $alias->getAlias(),
));
} | php | private function validateUnique(Alias $alias, LifecycleEventArgs $args)
{
return (bool) $args->getObjectManager()
->getRepository('ClasticAliasBundle:Alias')
->findBy(array(
'alias' => $alias->getAlias(),
));
} | [
"private",
"function",
"validateUnique",
"(",
"Alias",
"$",
"alias",
",",
"LifecycleEventArgs",
"$",
"args",
")",
"{",
"return",
"(",
"bool",
")",
"$",
"args",
"->",
"getObjectManager",
"(",
")",
"->",
"getRepository",
"(",
"'ClasticAliasBundle:Alias'",
")",
"->",
"findBy",
"(",
"array",
"(",
"'alias'",
"=>",
"$",
"alias",
"->",
"getAlias",
"(",
")",
",",
")",
")",
";",
"}"
] | @param Alias $alias
@param LifecycleEventArgs $args
@return bool | [
"@param",
"Alias",
"$alias",
"@param",
"LifecycleEventArgs",
"$args"
] | train | https://github.com/Clastic/AliasBundle/blob/7f5099589561ed4988abab2dcccf5c58ea5edb66/EventListener/NodeListener.php#L164-L171 |
Celarius/nofuzz-framework | src/SimpleCache/CacheManager.php | CacheManager.createCache | public function createCache(string $driverName, array $options=null): \Nofuzz\SimpleCache\CacheInterface
{
# Build the name
$driverClassName = '\\Nofuzz\\SimpleCache\\Drivers\\'.ucfirst($driverName);
# Create the Class
$driverClass = new $driverClassName($options);
# Add to the list of drivers
if ( !is_null($driverClass) ) {
$this->drivers[strtolower($driverName)] = $driverClass;
}
return $driverClass;
} | php | public function createCache(string $driverName, array $options=null): \Nofuzz\SimpleCache\CacheInterface
{
# Build the name
$driverClassName = '\\Nofuzz\\SimpleCache\\Drivers\\'.ucfirst($driverName);
# Create the Class
$driverClass = new $driverClassName($options);
# Add to the list of drivers
if ( !is_null($driverClass) ) {
$this->drivers[strtolower($driverName)] = $driverClass;
}
return $driverClass;
} | [
"public",
"function",
"createCache",
"(",
"string",
"$",
"driverName",
",",
"array",
"$",
"options",
"=",
"null",
")",
":",
"\\",
"Nofuzz",
"\\",
"SimpleCache",
"\\",
"CacheInterface",
"{",
"# Build the name",
"$",
"driverClassName",
"=",
"'\\\\Nofuzz\\\\SimpleCache\\\\Drivers\\\\'",
".",
"ucfirst",
"(",
"$",
"driverName",
")",
";",
"# Create the Class",
"$",
"driverClass",
"=",
"new",
"$",
"driverClassName",
"(",
"$",
"options",
")",
";",
"# Add to the list of drivers",
"if",
"(",
"!",
"is_null",
"(",
"$",
"driverClass",
")",
")",
"{",
"$",
"this",
"->",
"drivers",
"[",
"strtolower",
"(",
"$",
"driverName",
")",
"]",
"=",
"$",
"driverClass",
";",
"}",
"return",
"$",
"driverClass",
";",
"}"
] | Generate a new Cache of $driver type
@param string $driver
@return object | [
"Generate",
"a",
"new",
"Cache",
"of",
"$driver",
"type"
] | train | https://github.com/Celarius/nofuzz-framework/blob/867c5150baa431e8f800624a26ba80e95eebd4e5/src/SimpleCache/CacheManager.php#L51-L65 |
Celarius/nofuzz-framework | src/SimpleCache/CacheManager.php | CacheManager.getCache | public function getCache(string $driverName=''): \Nofuzz\SimpleCache\CacheInterface
{
if (empty($driverName)) {
# Return the 1st Cache in the list
return (array_values($this->drivers)[0] ?? null);
} else {
# Return the Cache for the $driverName
return $this->drivers[strtolower($driverName)] ?? null;
}
} | php | public function getCache(string $driverName=''): \Nofuzz\SimpleCache\CacheInterface
{
if (empty($driverName)) {
# Return the 1st Cache in the list
return (array_values($this->drivers)[0] ?? null);
} else {
# Return the Cache for the $driverName
return $this->drivers[strtolower($driverName)] ?? null;
}
} | [
"public",
"function",
"getCache",
"(",
"string",
"$",
"driverName",
"=",
"''",
")",
":",
"\\",
"Nofuzz",
"\\",
"SimpleCache",
"\\",
"CacheInterface",
"{",
"if",
"(",
"empty",
"(",
"$",
"driverName",
")",
")",
"{",
"# Return the 1st Cache in the list",
"return",
"(",
"array_values",
"(",
"$",
"this",
"->",
"drivers",
")",
"[",
"0",
"]",
"??",
"null",
")",
";",
"}",
"else",
"{",
"# Return the Cache for the $driverName",
"return",
"$",
"this",
"->",
"drivers",
"[",
"strtolower",
"(",
"$",
"driverName",
")",
"]",
"??",
"null",
";",
"}",
"}"
] | Get a generated Cache Driver
@param string $driverName
@return null | object | [
"Get",
"a",
"generated",
"Cache",
"Driver"
] | train | https://github.com/Celarius/nofuzz-framework/blob/867c5150baa431e8f800624a26ba80e95eebd4e5/src/SimpleCache/CacheManager.php#L73-L82 |
titon/model | src/Titon/Model/Relation/OneToOne.php | OneToOne.deleteDependents | public function deleteDependents(Event $event, $ids, $count) {
$rfk = $this->getRelatedForeignKey();
$this->query(Query::UPDATE)->where($rfk, $ids)->save([$rfk => null]);
} | php | public function deleteDependents(Event $event, $ids, $count) {
$rfk = $this->getRelatedForeignKey();
$this->query(Query::UPDATE)->where($rfk, $ids)->save([$rfk => null]);
} | [
"public",
"function",
"deleteDependents",
"(",
"Event",
"$",
"event",
",",
"$",
"ids",
",",
"$",
"count",
")",
"{",
"$",
"rfk",
"=",
"$",
"this",
"->",
"getRelatedForeignKey",
"(",
")",
";",
"$",
"this",
"->",
"query",
"(",
"Query",
"::",
"UPDATE",
")",
"->",
"where",
"(",
"$",
"rfk",
",",
"$",
"ids",
")",
"->",
"save",
"(",
"[",
"$",
"rfk",
"=>",
"null",
"]",
")",
";",
"}"
] | Child records should not be deleted, but will have the foreign key modified.
Use database level `ON DELETE CASCADE` for cascading deletion.
{@inheritdoc} | [
"Child",
"records",
"should",
"not",
"be",
"deleted",
"but",
"will",
"have",
"the",
"foreign",
"key",
"modified",
".",
"Use",
"database",
"level",
"ON",
"DELETE",
"CASCADE",
"for",
"cascading",
"deletion",
"."
] | train | https://github.com/titon/model/blob/274e3810c2cfbb6818a388daaa462ff05de99cbd/src/Titon/Model/Relation/OneToOne.php#L33-L37 |
titon/model | src/Titon/Model/Relation/OneToOne.php | OneToOne.linkRelations | public function linkRelations(Event $event, $id, $count) {
$links = $this->getLinked();
$rfk = $this->getRelatedForeignKey();
if (!$id || $links->isEmpty()) {
return;
}
// Reset the previous records
$this->query(Query::UPDATE)->where($rfk, $id)->save([$rfk => null]);
// Save the current record
$link = $links[0]->set($rfk, $id);
if (!$link->save(['validate' => false, 'atomic' => false, 'force' => true])) {
throw new RelationQueryFailureException(sprintf('Failed to link %s related record(s)', $this->getAlias()));
}
$links->flush();
} | php | public function linkRelations(Event $event, $id, $count) {
$links = $this->getLinked();
$rfk = $this->getRelatedForeignKey();
if (!$id || $links->isEmpty()) {
return;
}
// Reset the previous records
$this->query(Query::UPDATE)->where($rfk, $id)->save([$rfk => null]);
// Save the current record
$link = $links[0]->set($rfk, $id);
if (!$link->save(['validate' => false, 'atomic' => false, 'force' => true])) {
throw new RelationQueryFailureException(sprintf('Failed to link %s related record(s)', $this->getAlias()));
}
$links->flush();
} | [
"public",
"function",
"linkRelations",
"(",
"Event",
"$",
"event",
",",
"$",
"id",
",",
"$",
"count",
")",
"{",
"$",
"links",
"=",
"$",
"this",
"->",
"getLinked",
"(",
")",
";",
"$",
"rfk",
"=",
"$",
"this",
"->",
"getRelatedForeignKey",
"(",
")",
";",
"if",
"(",
"!",
"$",
"id",
"||",
"$",
"links",
"->",
"isEmpty",
"(",
")",
")",
"{",
"return",
";",
"}",
"// Reset the previous records",
"$",
"this",
"->",
"query",
"(",
"Query",
"::",
"UPDATE",
")",
"->",
"where",
"(",
"$",
"rfk",
",",
"$",
"id",
")",
"->",
"save",
"(",
"[",
"$",
"rfk",
"=>",
"null",
"]",
")",
";",
"// Save the current record",
"$",
"link",
"=",
"$",
"links",
"[",
"0",
"]",
"->",
"set",
"(",
"$",
"rfk",
",",
"$",
"id",
")",
";",
"if",
"(",
"!",
"$",
"link",
"->",
"save",
"(",
"[",
"'validate'",
"=>",
"false",
",",
"'atomic'",
"=>",
"false",
",",
"'force'",
"=>",
"true",
"]",
")",
")",
"{",
"throw",
"new",
"RelationQueryFailureException",
"(",
"sprintf",
"(",
"'Failed to link %s related record(s)'",
",",
"$",
"this",
"->",
"getAlias",
"(",
")",
")",
")",
";",
"}",
"$",
"links",
"->",
"flush",
"(",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/titon/model/blob/274e3810c2cfbb6818a388daaa462ff05de99cbd/src/Titon/Model/Relation/OneToOne.php#L85-L104 |
ice-php/redis | src/RedisServer.php | RedisServer.slowLogGet | public function slowLogGet(?int $count = null)
{
if ($count) {
return $this->handle->slowlog("get $count");
}
return $this->handle->slowlog('get');
} | php | public function slowLogGet(?int $count = null)
{
if ($count) {
return $this->handle->slowlog("get $count");
}
return $this->handle->slowlog('get');
} | [
"public",
"function",
"slowLogGet",
"(",
"?",
"int",
"$",
"count",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"count",
")",
"{",
"return",
"$",
"this",
"->",
"handle",
"->",
"slowlog",
"(",
"\"get $count\"",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handle",
"->",
"slowlog",
"(",
"'get'",
")",
";",
"}"
] | 获取一定数量的慢日志
@param int $count
@return mixed | [
"获取一定数量的慢日志"
] | train | https://github.com/ice-php/redis/blob/fe0c484ad61831d8f7c163188a90ed1bfa508d73/src/RedisServer.php#L108-L114 |
ice-php/redis | src/RedisServer.php | RedisServer.configSet | public function configSet(string $key, string $value): array
{
return $this->handle->config('SET', $key, $value);
} | php | public function configSet(string $key, string $value): array
{
return $this->handle->config('SET', $key, $value);
} | [
"public",
"function",
"configSet",
"(",
"string",
"$",
"key",
",",
"string",
"$",
"value",
")",
":",
"array",
"{",
"return",
"$",
"this",
"->",
"handle",
"->",
"config",
"(",
"'SET'",
",",
"$",
"key",
",",
"$",
"value",
")",
";",
"}"
] | 设置配置信息
@param $key string 配置项名称
@param $value string 配置值
@return array | [
"设置配置信息"
] | train | https://github.com/ice-php/redis/blob/fe0c484ad61831d8f7c163188a90ed1bfa508d73/src/RedisServer.php#L151-L154 |
buybrain/nervus-php | src/Buybrain/Nervus/Adapter/SignalAdapter.php | SignalAdapter.doStep | protected function doStep()
{
// Wait for the next signal request. The request itself doesn't contain any data.
$this->decoder->decode(SignalRequest::class);
try {
// Request a new signal from the implementation
$this->signaler->signal($this);
} catch (Exception $ex) {
$this->encoder->encode(SignalResponse::error($ex));
}
} | php | protected function doStep()
{
// Wait for the next signal request. The request itself doesn't contain any data.
$this->decoder->decode(SignalRequest::class);
try {
// Request a new signal from the implementation
$this->signaler->signal($this);
} catch (Exception $ex) {
$this->encoder->encode(SignalResponse::error($ex));
}
} | [
"protected",
"function",
"doStep",
"(",
")",
"{",
"// Wait for the next signal request. The request itself doesn't contain any data.",
"$",
"this",
"->",
"decoder",
"->",
"decode",
"(",
"SignalRequest",
"::",
"class",
")",
";",
"try",
"{",
"// Request a new signal from the implementation",
"$",
"this",
"->",
"signaler",
"->",
"signal",
"(",
"$",
"this",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"$",
"this",
"->",
"encoder",
"->",
"encode",
"(",
"SignalResponse",
"::",
"error",
"(",
"$",
"ex",
")",
")",
";",
"}",
"}"
] | Perform a single step, process a single request | [
"Perform",
"a",
"single",
"step",
"process",
"a",
"single",
"request"
] | train | https://github.com/buybrain/nervus-php/blob/96e00e30571b3ea4cf3494cd26c930ffa336c3bf/src/Buybrain/Nervus/Adapter/SignalAdapter.php#L44-L55 |
buybrain/nervus-php | src/Buybrain/Nervus/Adapter/SignalAdapter.php | SignalAdapter.onSignal | public function onSignal(array $ids, callable $onAck)
{
// We got a signal, send it to the host application
$this->encoder->encode(SignalResponse::success(new Signal($ids)));
while (true) {
// Wait for the result, which should be a request to ack or nack the signal
/** @var SignalAckRequest $ackRequest */
$ackRequest = $this->decoder->decode(SignalAckRequest::class);
// Let the implementation handle the ack request
try {
call_user_func($onAck, $ackRequest->isAck());
$this->encoder->encode(SignalAckResponse::success());
// The acknowledgement worked, we can stop listening for consecutive acknowledgement requests
break;
} catch (Exception $ex) {
// Something went wrong. Send the error back and wait for the next acknowledgement request
$this->encoder->encode(SignalAckResponse::error($ex));
}
}
} | php | public function onSignal(array $ids, callable $onAck)
{
// We got a signal, send it to the host application
$this->encoder->encode(SignalResponse::success(new Signal($ids)));
while (true) {
// Wait for the result, which should be a request to ack or nack the signal
/** @var SignalAckRequest $ackRequest */
$ackRequest = $this->decoder->decode(SignalAckRequest::class);
// Let the implementation handle the ack request
try {
call_user_func($onAck, $ackRequest->isAck());
$this->encoder->encode(SignalAckResponse::success());
// The acknowledgement worked, we can stop listening for consecutive acknowledgement requests
break;
} catch (Exception $ex) {
// Something went wrong. Send the error back and wait for the next acknowledgement request
$this->encoder->encode(SignalAckResponse::error($ex));
}
}
} | [
"public",
"function",
"onSignal",
"(",
"array",
"$",
"ids",
",",
"callable",
"$",
"onAck",
")",
"{",
"// We got a signal, send it to the host application",
"$",
"this",
"->",
"encoder",
"->",
"encode",
"(",
"SignalResponse",
"::",
"success",
"(",
"new",
"Signal",
"(",
"$",
"ids",
")",
")",
")",
";",
"while",
"(",
"true",
")",
"{",
"// Wait for the result, which should be a request to ack or nack the signal",
"/** @var SignalAckRequest $ackRequest */",
"$",
"ackRequest",
"=",
"$",
"this",
"->",
"decoder",
"->",
"decode",
"(",
"SignalAckRequest",
"::",
"class",
")",
";",
"// Let the implementation handle the ack request",
"try",
"{",
"call_user_func",
"(",
"$",
"onAck",
",",
"$",
"ackRequest",
"->",
"isAck",
"(",
")",
")",
";",
"$",
"this",
"->",
"encoder",
"->",
"encode",
"(",
"SignalAckResponse",
"::",
"success",
"(",
")",
")",
";",
"// The acknowledgement worked, we can stop listening for consecutive acknowledgement requests",
"break",
";",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"// Something went wrong. Send the error back and wait for the next acknowledgement request",
"$",
"this",
"->",
"encoder",
"->",
"encode",
"(",
"SignalAckResponse",
"::",
"error",
"(",
"$",
"ex",
")",
")",
";",
"}",
"}",
"}"
] | Callback method meant to be called by signal handlers when a new signal is available
@param EntityId[] $ids
@param callable $onAck will be passed a single boolean $ack argument | [
"Callback",
"method",
"meant",
"to",
"be",
"called",
"by",
"signal",
"handlers",
"when",
"a",
"new",
"signal",
"is",
"available"
] | train | https://github.com/buybrain/nervus-php/blob/96e00e30571b3ea4cf3494cd26c930ffa336c3bf/src/Buybrain/Nervus/Adapter/SignalAdapter.php#L63-L84 |
yujin1st/yii2-user | models/query/UserQuery.php | UserQuery.byUsernameOrEmail | public function byUsernameOrEmail($usernameOrEmail) {
if (filter_var($usernameOrEmail, FILTER_VALIDATE_EMAIL)) {
return $this->byEmail($usernameOrEmail);
}
return $this->byUsername($usernameOrEmail);
} | php | public function byUsernameOrEmail($usernameOrEmail) {
if (filter_var($usernameOrEmail, FILTER_VALIDATE_EMAIL)) {
return $this->byEmail($usernameOrEmail);
}
return $this->byUsername($usernameOrEmail);
} | [
"public",
"function",
"byUsernameOrEmail",
"(",
"$",
"usernameOrEmail",
")",
"{",
"if",
"(",
"filter_var",
"(",
"$",
"usernameOrEmail",
",",
"FILTER_VALIDATE_EMAIL",
")",
")",
"{",
"return",
"$",
"this",
"->",
"byEmail",
"(",
"$",
"usernameOrEmail",
")",
";",
"}",
"return",
"$",
"this",
"->",
"byUsername",
"(",
"$",
"usernameOrEmail",
")",
";",
"}"
] | Finds a user by the given email.
@param string $usernameOrEmail Email to be used on search.
@return $this | [
"Finds",
"a",
"user",
"by",
"the",
"given",
"email",
"."
] | train | https://github.com/yujin1st/yii2-user/blob/b404c77acf4a96f0cdf9bb0af5c8d62bcae3946f/models/query/UserQuery.php#L79-L85 |
easy-system/es-http | src/Factory/UriFactory.php | UriFactory.make | public static function make(array $server = null)
{
$scheme = UriSchemeFactory::make($server);
$host = UriHostFactory::make($server);
$port = UriPortFactory::make($server);
$path = UriPathFactory::make($server);
$query = UriQueryFactory::make($server);
$url = '';
if ($host) {
$url .= $scheme . '://' . $host . ':' . $port;
$path = '/' . ltrim($path, '/');
}
$url .= $path;
if ($query) {
$url .= '?' . $query;
}
$uri = new Uri($url);
if ($host) {
return $uri;
}
return $uri->withScheme($scheme)->withPort($port);
} | php | public static function make(array $server = null)
{
$scheme = UriSchemeFactory::make($server);
$host = UriHostFactory::make($server);
$port = UriPortFactory::make($server);
$path = UriPathFactory::make($server);
$query = UriQueryFactory::make($server);
$url = '';
if ($host) {
$url .= $scheme . '://' . $host . ':' . $port;
$path = '/' . ltrim($path, '/');
}
$url .= $path;
if ($query) {
$url .= '?' . $query;
}
$uri = new Uri($url);
if ($host) {
return $uri;
}
return $uri->withScheme($scheme)->withPort($port);
} | [
"public",
"static",
"function",
"make",
"(",
"array",
"$",
"server",
"=",
"null",
")",
"{",
"$",
"scheme",
"=",
"UriSchemeFactory",
"::",
"make",
"(",
"$",
"server",
")",
";",
"$",
"host",
"=",
"UriHostFactory",
"::",
"make",
"(",
"$",
"server",
")",
";",
"$",
"port",
"=",
"UriPortFactory",
"::",
"make",
"(",
"$",
"server",
")",
";",
"$",
"path",
"=",
"UriPathFactory",
"::",
"make",
"(",
"$",
"server",
")",
";",
"$",
"query",
"=",
"UriQueryFactory",
"::",
"make",
"(",
"$",
"server",
")",
";",
"$",
"url",
"=",
"''",
";",
"if",
"(",
"$",
"host",
")",
"{",
"$",
"url",
".=",
"$",
"scheme",
".",
"'://'",
".",
"$",
"host",
".",
"':'",
".",
"$",
"port",
";",
"$",
"path",
"=",
"'/'",
".",
"ltrim",
"(",
"$",
"path",
",",
"'/'",
")",
";",
"}",
"$",
"url",
".=",
"$",
"path",
";",
"if",
"(",
"$",
"query",
")",
"{",
"$",
"url",
".=",
"'?'",
".",
"$",
"query",
";",
"}",
"$",
"uri",
"=",
"new",
"Uri",
"(",
"$",
"url",
")",
";",
"if",
"(",
"$",
"host",
")",
"{",
"return",
"$",
"uri",
";",
"}",
"return",
"$",
"uri",
"->",
"withScheme",
"(",
"$",
"scheme",
")",
"->",
"withPort",
"(",
"$",
"port",
")",
";",
"}"
] | Makes the instance of Es\Http\Uri.
@param array $server Optional; null by default or empty array means
global $_SERVER. The source data
@return \Es\Http\Uri The instance of Uri | [
"Makes",
"the",
"instance",
"of",
"Es",
"\\",
"Http",
"\\",
"Uri",
"."
] | train | https://github.com/easy-system/es-http/blob/dd5852e94901e147a7546a8715133408ece767a1/src/Factory/UriFactory.php#L27-L53 |
fratily/kernel | src/Controller/ActionMiddleware.php | ActionMiddleware.process | public function process(
ServerRequestInterface $request,
RequestHandlerInterface $handler
): ResponseInterface{
// アクション実行前にアクションコールバックを使うイベントを実行
// 例) コールバックを包むコールバックを生成してアクションとする等
if(!is_callable($request->getAttribute("action"))){
throw new \LogicException;
}
if(
!is_object($request->getAttribute("routing"))
|| !$request->getAttribute("routing") instanceof Routing
){
throw new \LogicException;
}
$response = $this->container->invokeCallback(
$request->getAttribute("action"),
array_merge(
$request->getAttribute("routing")->params,
[
"request" => $request,
"_route" => $request->getAttribute("routing")->name,
"_handler" => $handler,
]
),
[
ServerRequestInterface::class => $request,
RequestInterface::class => $request,
]
);
// アクション実行後にレスポンスを使うイベントを実行
// 例) Allow: jsonなリクエストの場合は配列のレスポンスをJsonResponseに置き換える等
if(!$response instanceof ResponseInterface){
$class = ResponseInterface::class;
throw new Exception\ActionException(
"Action method must return an instance of the object"
. "that implements {$class}."
);
}
return $response;
} | php | public function process(
ServerRequestInterface $request,
RequestHandlerInterface $handler
): ResponseInterface{
// アクション実行前にアクションコールバックを使うイベントを実行
// 例) コールバックを包むコールバックを生成してアクションとする等
if(!is_callable($request->getAttribute("action"))){
throw new \LogicException;
}
if(
!is_object($request->getAttribute("routing"))
|| !$request->getAttribute("routing") instanceof Routing
){
throw new \LogicException;
}
$response = $this->container->invokeCallback(
$request->getAttribute("action"),
array_merge(
$request->getAttribute("routing")->params,
[
"request" => $request,
"_route" => $request->getAttribute("routing")->name,
"_handler" => $handler,
]
),
[
ServerRequestInterface::class => $request,
RequestInterface::class => $request,
]
);
// アクション実行後にレスポンスを使うイベントを実行
// 例) Allow: jsonなリクエストの場合は配列のレスポンスをJsonResponseに置き換える等
if(!$response instanceof ResponseInterface){
$class = ResponseInterface::class;
throw new Exception\ActionException(
"Action method must return an instance of the object"
. "that implements {$class}."
);
}
return $response;
} | [
"public",
"function",
"process",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"RequestHandlerInterface",
"$",
"handler",
")",
":",
"ResponseInterface",
"{",
"// アクション実行前にアクションコールバックを使うイベントを実行",
"// 例) コールバックを包むコールバックを生成してアクションとする等",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"request",
"->",
"getAttribute",
"(",
"\"action\"",
")",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
";",
"}",
"if",
"(",
"!",
"is_object",
"(",
"$",
"request",
"->",
"getAttribute",
"(",
"\"routing\"",
")",
")",
"||",
"!",
"$",
"request",
"->",
"getAttribute",
"(",
"\"routing\"",
")",
"instanceof",
"Routing",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
";",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"container",
"->",
"invokeCallback",
"(",
"$",
"request",
"->",
"getAttribute",
"(",
"\"action\"",
")",
",",
"array_merge",
"(",
"$",
"request",
"->",
"getAttribute",
"(",
"\"routing\"",
")",
"->",
"params",
",",
"[",
"\"request\"",
"=>",
"$",
"request",
",",
"\"_route\"",
"=>",
"$",
"request",
"->",
"getAttribute",
"(",
"\"routing\"",
")",
"->",
"name",
",",
"\"_handler\"",
"=>",
"$",
"handler",
",",
"]",
")",
",",
"[",
"ServerRequestInterface",
"::",
"class",
"=>",
"$",
"request",
",",
"RequestInterface",
"::",
"class",
"=>",
"$",
"request",
",",
"]",
")",
";",
"// アクション実行後にレスポンスを使うイベントを実行",
"// 例) Allow: jsonなリクエストの場合は配列のレスポンスをJsonResponseに置き換える等",
"if",
"(",
"!",
"$",
"response",
"instanceof",
"ResponseInterface",
")",
"{",
"$",
"class",
"=",
"ResponseInterface",
"::",
"class",
";",
"throw",
"new",
"Exception",
"\\",
"ActionException",
"(",
"\"Action method must return an instance of the object\"",
".",
"\"that implements {$class}.\"",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/fratily/kernel/blob/b37d7626182b3cfef3e4fb317a0e4c6001754965/src/Controller/ActionMiddleware.php#L51-L98 |
brosland/framework | src/Brosland/Forms/Controls/DatePicker.php | DatePicker.getControl | public function getControl()
{
$control = parent::getControl();
$control->data('datepicker-format', $this->translateFormatToJs($this->format));
return $control;
} | php | public function getControl()
{
$control = parent::getControl();
$control->data('datepicker-format', $this->translateFormatToJs($this->format));
return $control;
} | [
"public",
"function",
"getControl",
"(",
")",
"{",
"$",
"control",
"=",
"parent",
"::",
"getControl",
"(",
")",
";",
"$",
"control",
"->",
"data",
"(",
"'datepicker-format'",
",",
"$",
"this",
"->",
"translateFormatToJs",
"(",
"$",
"this",
"->",
"format",
")",
")",
";",
"return",
"$",
"control",
";",
"}"
] | Generates control's HTML element.
@return Nette\Utils\Html | [
"Generates",
"control",
"s",
"HTML",
"element",
"."
] | train | https://github.com/brosland/framework/blob/8e1c66830779dd7c3de3cb2b4beef7df82f15b0b/src/Brosland/Forms/Controls/DatePicker.php#L101-L107 |
brosland/framework | src/Brosland/Forms/Controls/DatePicker.php | DatePicker.register | public static function register($defaultDateFormat = 'd/m/Y')
{
Container::extensionMethod('addDatePicker', function (Container $container, $name, $label = NULL)
use ($defaultDateFormat)
{
$control = $container[$name] = new DatePicker($label);
$control->setDateFormat($defaultDateFormat);
return $control;
});
} | php | public static function register($defaultDateFormat = 'd/m/Y')
{
Container::extensionMethod('addDatePicker', function (Container $container, $name, $label = NULL)
use ($defaultDateFormat)
{
$control = $container[$name] = new DatePicker($label);
$control->setDateFormat($defaultDateFormat);
return $control;
});
} | [
"public",
"static",
"function",
"register",
"(",
"$",
"defaultDateFormat",
"=",
"'d/m/Y'",
")",
"{",
"Container",
"::",
"extensionMethod",
"(",
"'addDatePicker'",
",",
"function",
"(",
"Container",
"$",
"container",
",",
"$",
"name",
",",
"$",
"label",
"=",
"NULL",
")",
"use",
"(",
"$",
"defaultDateFormat",
")",
"{",
"$",
"control",
"=",
"$",
"container",
"[",
"$",
"name",
"]",
"=",
"new",
"DatePicker",
"(",
"$",
"label",
")",
";",
"$",
"control",
"->",
"setDateFormat",
"(",
"$",
"defaultDateFormat",
")",
";",
"return",
"$",
"control",
";",
"}",
")",
";",
"}"
] | Registers method 'addDatePicker' adding DatePicker to form | [
"Registers",
"method",
"addDatePicker",
"adding",
"DatePicker",
"to",
"form"
] | train | https://github.com/brosland/framework/blob/8e1c66830779dd7c3de3cb2b4beef7df82f15b0b/src/Brosland/Forms/Controls/DatePicker.php#L121-L131 |
flowcode/AmulenShopBundle | src/Flowcode/ShopBundle/Controller/InventoryController.php | InventoryController.showAction | public function showAction(Inventory $inventory)
{
$products = $inventory->getItems();
$editForm = $this->createForm(new InventoryType(), $inventory, array(
'action' => $this->generateUrl('stock_inventory_update', array('id' => $inventory->getid())),
'method' => 'PUT',
));
$editItemsForm = $this->createForm(new InventoryItemsType(), $inventory, array(
'action' => $this->generateUrl('stock_inventory_item_update', array('id' => $inventory->getid())),
'method' => 'PUT',
));
$deleteForm = $this->createDeleteForm($inventory->getId(), 'stock_inventory_delete');
return array(
'inventory' => $inventory,
'products' => $products,
'edit_form' => $editForm->createView(),
'edit_items_form' => $editItemsForm->createView(),
'delete_form' => $deleteForm->createView(),
);
} | php | public function showAction(Inventory $inventory)
{
$products = $inventory->getItems();
$editForm = $this->createForm(new InventoryType(), $inventory, array(
'action' => $this->generateUrl('stock_inventory_update', array('id' => $inventory->getid())),
'method' => 'PUT',
));
$editItemsForm = $this->createForm(new InventoryItemsType(), $inventory, array(
'action' => $this->generateUrl('stock_inventory_item_update', array('id' => $inventory->getid())),
'method' => 'PUT',
));
$deleteForm = $this->createDeleteForm($inventory->getId(), 'stock_inventory_delete');
return array(
'inventory' => $inventory,
'products' => $products,
'edit_form' => $editForm->createView(),
'edit_items_form' => $editItemsForm->createView(),
'delete_form' => $deleteForm->createView(),
);
} | [
"public",
"function",
"showAction",
"(",
"Inventory",
"$",
"inventory",
")",
"{",
"$",
"products",
"=",
"$",
"inventory",
"->",
"getItems",
"(",
")",
";",
"$",
"editForm",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"InventoryType",
"(",
")",
",",
"$",
"inventory",
",",
"array",
"(",
"'action'",
"=>",
"$",
"this",
"->",
"generateUrl",
"(",
"'stock_inventory_update'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"inventory",
"->",
"getid",
"(",
")",
")",
")",
",",
"'method'",
"=>",
"'PUT'",
",",
")",
")",
";",
"$",
"editItemsForm",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"InventoryItemsType",
"(",
")",
",",
"$",
"inventory",
",",
"array",
"(",
"'action'",
"=>",
"$",
"this",
"->",
"generateUrl",
"(",
"'stock_inventory_item_update'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"inventory",
"->",
"getid",
"(",
")",
")",
")",
",",
"'method'",
"=>",
"'PUT'",
",",
")",
")",
";",
"$",
"deleteForm",
"=",
"$",
"this",
"->",
"createDeleteForm",
"(",
"$",
"inventory",
"->",
"getId",
"(",
")",
",",
"'stock_inventory_delete'",
")",
";",
"return",
"array",
"(",
"'inventory'",
"=>",
"$",
"inventory",
",",
"'products'",
"=>",
"$",
"products",
",",
"'edit_form'",
"=>",
"$",
"editForm",
"->",
"createView",
"(",
")",
",",
"'edit_items_form'",
"=>",
"$",
"editItemsForm",
"->",
"createView",
"(",
")",
",",
"'delete_form'",
"=>",
"$",
"deleteForm",
"->",
"createView",
"(",
")",
",",
")",
";",
"}"
] | Finds and displays a Inventory entity.
@Route("/{id}/show", name="stock_inventory_show", requirements={"id"="\d+"})
@Method("GET")
@Template() | [
"Finds",
"and",
"displays",
"a",
"Inventory",
"entity",
"."
] | train | https://github.com/flowcode/AmulenShopBundle/blob/500aaf4364be3c42fca69ecd10a449da03993814/src/Flowcode/ShopBundle/Controller/InventoryController.php#L59-L81 |
flowcode/AmulenShopBundle | src/Flowcode/ShopBundle/Controller/InventoryController.php | InventoryController.confirmAction | public function confirmAction(Inventory $inventory)
{
$em = $this->getDoctrine()->getManager();
$warehouseProductRepo = $em->getRepository('FlowerStockBundle:WarehouseProduct');
foreach ($inventory->getItems() as $item) {
$warehouseProduct = $warehouseProductRepo->findOneBy(array(
'product' => $item->getProduct(),
'warehouse' => $inventory->getWarehouse(),
));
if (!$warehouseProduct) {
$warehouseProduct = new WarehouseProduct();
$warehouseProduct->setProduct($item->getProduct());
$warehouseProduct->setWarehouse($item->getWarehouse());
$em->persist($warehouseProduct);
}
$warehouseProduct->setStock($item->getStock());
}
$inventory->setStatus(Inventory::STATUS_CONFIRMED);
$em->flush();
return $this->redirect($this->generateUrl('stock_inventory_show', array('id' => $inventory->getId())));
} | php | public function confirmAction(Inventory $inventory)
{
$em = $this->getDoctrine()->getManager();
$warehouseProductRepo = $em->getRepository('FlowerStockBundle:WarehouseProduct');
foreach ($inventory->getItems() as $item) {
$warehouseProduct = $warehouseProductRepo->findOneBy(array(
'product' => $item->getProduct(),
'warehouse' => $inventory->getWarehouse(),
));
if (!$warehouseProduct) {
$warehouseProduct = new WarehouseProduct();
$warehouseProduct->setProduct($item->getProduct());
$warehouseProduct->setWarehouse($item->getWarehouse());
$em->persist($warehouseProduct);
}
$warehouseProduct->setStock($item->getStock());
}
$inventory->setStatus(Inventory::STATUS_CONFIRMED);
$em->flush();
return $this->redirect($this->generateUrl('stock_inventory_show', array('id' => $inventory->getId())));
} | [
"public",
"function",
"confirmAction",
"(",
"Inventory",
"$",
"inventory",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"warehouseProductRepo",
"=",
"$",
"em",
"->",
"getRepository",
"(",
"'FlowerStockBundle:WarehouseProduct'",
")",
";",
"foreach",
"(",
"$",
"inventory",
"->",
"getItems",
"(",
")",
"as",
"$",
"item",
")",
"{",
"$",
"warehouseProduct",
"=",
"$",
"warehouseProductRepo",
"->",
"findOneBy",
"(",
"array",
"(",
"'product'",
"=>",
"$",
"item",
"->",
"getProduct",
"(",
")",
",",
"'warehouse'",
"=>",
"$",
"inventory",
"->",
"getWarehouse",
"(",
")",
",",
")",
")",
";",
"if",
"(",
"!",
"$",
"warehouseProduct",
")",
"{",
"$",
"warehouseProduct",
"=",
"new",
"WarehouseProduct",
"(",
")",
";",
"$",
"warehouseProduct",
"->",
"setProduct",
"(",
"$",
"item",
"->",
"getProduct",
"(",
")",
")",
";",
"$",
"warehouseProduct",
"->",
"setWarehouse",
"(",
"$",
"item",
"->",
"getWarehouse",
"(",
")",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"warehouseProduct",
")",
";",
"}",
"$",
"warehouseProduct",
"->",
"setStock",
"(",
"$",
"item",
"->",
"getStock",
"(",
")",
")",
";",
"}",
"$",
"inventory",
"->",
"setStatus",
"(",
"Inventory",
"::",
"STATUS_CONFIRMED",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'stock_inventory_show'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"inventory",
"->",
"getId",
"(",
")",
")",
")",
")",
";",
"}"
] | Finds and displays a Inventory entity.
@Route("/{id}/confirm", name="stock_inventory_confirm", requirements={"id"="\d+"})
@Method("GET") | [
"Finds",
"and",
"displays",
"a",
"Inventory",
"entity",
"."
] | train | https://github.com/flowcode/AmulenShopBundle/blob/500aaf4364be3c42fca69ecd10a449da03993814/src/Flowcode/ShopBundle/Controller/InventoryController.php#L89-L114 |
flowcode/AmulenShopBundle | src/Flowcode/ShopBundle/Controller/InventoryController.php | InventoryController.setProductWarehouseStockAction | public function setProductWarehouseStockAction(InventoryItem $item)
{
$em = $this->getDoctrine()->getManager();
/* @var WarehouseProductService $warehouseProductService */
$warehouseProductService = $this->get('flower.stock.service.warehouse_product');
$warehouseProduct = $warehouseProductService->getByWarehouseProduct($item->getInventory()->getWarehouse(), $item->getProduct());
$item->setStock($warehouseProduct->getStock());
$em->flush();
return $this->redirect($this->generateUrl('stock_inventory_show', array('id' => $item->getInventory()->getId())));
} | php | public function setProductWarehouseStockAction(InventoryItem $item)
{
$em = $this->getDoctrine()->getManager();
/* @var WarehouseProductService $warehouseProductService */
$warehouseProductService = $this->get('flower.stock.service.warehouse_product');
$warehouseProduct = $warehouseProductService->getByWarehouseProduct($item->getInventory()->getWarehouse(), $item->getProduct());
$item->setStock($warehouseProduct->getStock());
$em->flush();
return $this->redirect($this->generateUrl('stock_inventory_show', array('id' => $item->getInventory()->getId())));
} | [
"public",
"function",
"setProductWarehouseStockAction",
"(",
"InventoryItem",
"$",
"item",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"/* @var WarehouseProductService $warehouseProductService */",
"$",
"warehouseProductService",
"=",
"$",
"this",
"->",
"get",
"(",
"'flower.stock.service.warehouse_product'",
")",
";",
"$",
"warehouseProduct",
"=",
"$",
"warehouseProductService",
"->",
"getByWarehouseProduct",
"(",
"$",
"item",
"->",
"getInventory",
"(",
")",
"->",
"getWarehouse",
"(",
")",
",",
"$",
"item",
"->",
"getProduct",
"(",
")",
")",
";",
"$",
"item",
"->",
"setStock",
"(",
"$",
"warehouseProduct",
"->",
"getStock",
"(",
")",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'stock_inventory_show'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"item",
"->",
"getInventory",
"(",
")",
"->",
"getId",
"(",
")",
")",
")",
")",
";",
"}"
] | Finds and displays a Inventory entity.
@Route("/item/{id}/set_warehouse_stock", name="stock_inventory_product_set_warehouse_stock", requirements={"id"="\d+"})
@Method("GET") | [
"Finds",
"and",
"displays",
"a",
"Inventory",
"entity",
"."
] | train | https://github.com/flowcode/AmulenShopBundle/blob/500aaf4364be3c42fca69ecd10a449da03993814/src/Flowcode/ShopBundle/Controller/InventoryController.php#L158-L167 |
flowcode/AmulenShopBundle | src/Flowcode/ShopBundle/Controller/InventoryController.php | InventoryController.newAction | public function newAction()
{
$inventory = new Inventory();
$today = new \DateTime();;
$inventory->setDate($today);
$inventory->setUser($this->getUser());
$inventory->setStatus(Inventory::STATUS_DRAFT);
$defaultCode = $this->getInventoryService()->getNextCode();
$inventory->setCode($defaultCode);
$defaultName = $this->get('translator')->trans('default_name', [
"%date%" => $today->format('d/m/y'),
], 'Inventory');
$inventory->setName($defaultName);
$form = $this->createForm(new InventoryType(), $inventory);
return array(
'inventory' => $inventory,
'form' => $form->createView(),
);
} | php | public function newAction()
{
$inventory = new Inventory();
$today = new \DateTime();;
$inventory->setDate($today);
$inventory->setUser($this->getUser());
$inventory->setStatus(Inventory::STATUS_DRAFT);
$defaultCode = $this->getInventoryService()->getNextCode();
$inventory->setCode($defaultCode);
$defaultName = $this->get('translator')->trans('default_name', [
"%date%" => $today->format('d/m/y'),
], 'Inventory');
$inventory->setName($defaultName);
$form = $this->createForm(new InventoryType(), $inventory);
return array(
'inventory' => $inventory,
'form' => $form->createView(),
);
} | [
"public",
"function",
"newAction",
"(",
")",
"{",
"$",
"inventory",
"=",
"new",
"Inventory",
"(",
")",
";",
"$",
"today",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
";",
"$",
"inventory",
"->",
"setDate",
"(",
"$",
"today",
")",
";",
"$",
"inventory",
"->",
"setUser",
"(",
"$",
"this",
"->",
"getUser",
"(",
")",
")",
";",
"$",
"inventory",
"->",
"setStatus",
"(",
"Inventory",
"::",
"STATUS_DRAFT",
")",
";",
"$",
"defaultCode",
"=",
"$",
"this",
"->",
"getInventoryService",
"(",
")",
"->",
"getNextCode",
"(",
")",
";",
"$",
"inventory",
"->",
"setCode",
"(",
"$",
"defaultCode",
")",
";",
"$",
"defaultName",
"=",
"$",
"this",
"->",
"get",
"(",
"'translator'",
")",
"->",
"trans",
"(",
"'default_name'",
",",
"[",
"\"%date%\"",
"=>",
"$",
"today",
"->",
"format",
"(",
"'d/m/y'",
")",
",",
"]",
",",
"'Inventory'",
")",
";",
"$",
"inventory",
"->",
"setName",
"(",
"$",
"defaultName",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"InventoryType",
"(",
")",
",",
"$",
"inventory",
")",
";",
"return",
"array",
"(",
"'inventory'",
"=>",
"$",
"inventory",
",",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
",",
")",
";",
"}"
] | Displays a form to create a new Inventory entity.
@Route("/new", name="stock_inventory_new")
@Method("GET")
@Template() | [
"Displays",
"a",
"form",
"to",
"create",
"a",
"new",
"Inventory",
"entity",
"."
] | train | https://github.com/flowcode/AmulenShopBundle/blob/500aaf4364be3c42fca69ecd10a449da03993814/src/Flowcode/ShopBundle/Controller/InventoryController.php#L176-L199 |
flowcode/AmulenShopBundle | src/Flowcode/ShopBundle/Controller/InventoryController.php | InventoryController.createAction | public function createAction(Request $request)
{
$inventory = new Inventory();
$inventory->setStatus(Inventory::STATUS_DRAFT);
$form = $this->createForm(new InventoryType(), $inventory);
if ($form->handleRequest($request)->isValid()) {
$em = $this->getDoctrine()->getManager();
$this->get('flower.stock.service.inventory')->fillInventory($inventory);
$em->persist($inventory);
$em->flush();
return $this->redirect($this->generateUrl('stock_inventory_show', array('id' => $inventory->getId())));
}
return array(
'inventory' => $inventory,
'form' => $form->createView(),
);
} | php | public function createAction(Request $request)
{
$inventory = new Inventory();
$inventory->setStatus(Inventory::STATUS_DRAFT);
$form = $this->createForm(new InventoryType(), $inventory);
if ($form->handleRequest($request)->isValid()) {
$em = $this->getDoctrine()->getManager();
$this->get('flower.stock.service.inventory')->fillInventory($inventory);
$em->persist($inventory);
$em->flush();
return $this->redirect($this->generateUrl('stock_inventory_show', array('id' => $inventory->getId())));
}
return array(
'inventory' => $inventory,
'form' => $form->createView(),
);
} | [
"public",
"function",
"createAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"inventory",
"=",
"new",
"Inventory",
"(",
")",
";",
"$",
"inventory",
"->",
"setStatus",
"(",
"Inventory",
"::",
"STATUS_DRAFT",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"InventoryType",
"(",
")",
",",
"$",
"inventory",
")",
";",
"if",
"(",
"$",
"form",
"->",
"handleRequest",
"(",
"$",
"request",
")",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"this",
"->",
"get",
"(",
"'flower.stock.service.inventory'",
")",
"->",
"fillInventory",
"(",
"$",
"inventory",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"inventory",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'stock_inventory_show'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"inventory",
"->",
"getId",
"(",
")",
")",
")",
")",
";",
"}",
"return",
"array",
"(",
"'inventory'",
"=>",
"$",
"inventory",
",",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
",",
")",
";",
"}"
] | Creates a new Inventory entity.
@Route("/create", name="stock_inventory_create")
@Method("POST")
@Template("FlowerStockBundle:Inventory:new.html.twig") | [
"Creates",
"a",
"new",
"Inventory",
"entity",
"."
] | train | https://github.com/flowcode/AmulenShopBundle/blob/500aaf4364be3c42fca69ecd10a449da03993814/src/Flowcode/ShopBundle/Controller/InventoryController.php#L208-L227 |
flowcode/AmulenShopBundle | src/Flowcode/ShopBundle/Controller/InventoryController.php | InventoryController.editAction | public function editAction(Inventory $inventory)
{
$editForm = $this->createForm(new InventoryType(), $inventory, array(
'action' => $this->generateUrl('stock_inventory_update', array('id' => $inventory->getid())),
'method' => 'PUT',
));
$deleteForm = $this->createDeleteForm($inventory->getId(), 'stock_inventory_delete');
return array(
'inventory' => $inventory,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
} | php | public function editAction(Inventory $inventory)
{
$editForm = $this->createForm(new InventoryType(), $inventory, array(
'action' => $this->generateUrl('stock_inventory_update', array('id' => $inventory->getid())),
'method' => 'PUT',
));
$deleteForm = $this->createDeleteForm($inventory->getId(), 'stock_inventory_delete');
return array(
'inventory' => $inventory,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
} | [
"public",
"function",
"editAction",
"(",
"Inventory",
"$",
"inventory",
")",
"{",
"$",
"editForm",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"InventoryType",
"(",
")",
",",
"$",
"inventory",
",",
"array",
"(",
"'action'",
"=>",
"$",
"this",
"->",
"generateUrl",
"(",
"'stock_inventory_update'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"inventory",
"->",
"getid",
"(",
")",
")",
")",
",",
"'method'",
"=>",
"'PUT'",
",",
")",
")",
";",
"$",
"deleteForm",
"=",
"$",
"this",
"->",
"createDeleteForm",
"(",
"$",
"inventory",
"->",
"getId",
"(",
")",
",",
"'stock_inventory_delete'",
")",
";",
"return",
"array",
"(",
"'inventory'",
"=>",
"$",
"inventory",
",",
"'edit_form'",
"=>",
"$",
"editForm",
"->",
"createView",
"(",
")",
",",
"'delete_form'",
"=>",
"$",
"deleteForm",
"->",
"createView",
"(",
")",
",",
")",
";",
"}"
] | Displays a form to edit an existing Inventory entity.
@Route("/{id}/edit", name="stock_inventory_edit", requirements={"id"="\d+"})
@Method("GET")
@Template() | [
"Displays",
"a",
"form",
"to",
"edit",
"an",
"existing",
"Inventory",
"entity",
"."
] | train | https://github.com/flowcode/AmulenShopBundle/blob/500aaf4364be3c42fca69ecd10a449da03993814/src/Flowcode/ShopBundle/Controller/InventoryController.php#L236-L249 |
flowcode/AmulenShopBundle | src/Flowcode/ShopBundle/Controller/InventoryController.php | InventoryController.saveItemsAction | public function saveItemsAction(Inventory $inventory, Request $request)
{
$editItemsForm = $this->createForm(new InventoryItemsType(), $inventory, array(
'action' => $this->generateUrl('stock_inventory_item_update', array('id' => $inventory->getid())),
'method' => 'PUT',
));
if ($editItemsForm->handleRequest($request)->isValid()) {
$this->getDoctrine()->getManager()->flush();
return $this->redirect($this->generateUrl('stock_inventory_show', array('id' => $inventory->getId())));
}
$deleteForm = $this->createDeleteForm($inventory->getId(), 'stock_inventory_delete');
$editForm = $this->createForm(new InventoryType(), $inventory, array(
'action' => $this->generateUrl('stock_inventory_update', array('id' => $inventory->getid())),
'method' => 'PUT',
));
return array(
'inventory' => $inventory,
'edit_form' => $editForm->createView(),
'editItemsForm' => $editItemsForm,
'delete_form' => $deleteForm->createView(),
);
} | php | public function saveItemsAction(Inventory $inventory, Request $request)
{
$editItemsForm = $this->createForm(new InventoryItemsType(), $inventory, array(
'action' => $this->generateUrl('stock_inventory_item_update', array('id' => $inventory->getid())),
'method' => 'PUT',
));
if ($editItemsForm->handleRequest($request)->isValid()) {
$this->getDoctrine()->getManager()->flush();
return $this->redirect($this->generateUrl('stock_inventory_show', array('id' => $inventory->getId())));
}
$deleteForm = $this->createDeleteForm($inventory->getId(), 'stock_inventory_delete');
$editForm = $this->createForm(new InventoryType(), $inventory, array(
'action' => $this->generateUrl('stock_inventory_update', array('id' => $inventory->getid())),
'method' => 'PUT',
));
return array(
'inventory' => $inventory,
'edit_form' => $editForm->createView(),
'editItemsForm' => $editItemsForm,
'delete_form' => $deleteForm->createView(),
);
} | [
"public",
"function",
"saveItemsAction",
"(",
"Inventory",
"$",
"inventory",
",",
"Request",
"$",
"request",
")",
"{",
"$",
"editItemsForm",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"InventoryItemsType",
"(",
")",
",",
"$",
"inventory",
",",
"array",
"(",
"'action'",
"=>",
"$",
"this",
"->",
"generateUrl",
"(",
"'stock_inventory_item_update'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"inventory",
"->",
"getid",
"(",
")",
")",
")",
",",
"'method'",
"=>",
"'PUT'",
",",
")",
")",
";",
"if",
"(",
"$",
"editItemsForm",
"->",
"handleRequest",
"(",
"$",
"request",
")",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'stock_inventory_show'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"inventory",
"->",
"getId",
"(",
")",
")",
")",
")",
";",
"}",
"$",
"deleteForm",
"=",
"$",
"this",
"->",
"createDeleteForm",
"(",
"$",
"inventory",
"->",
"getId",
"(",
")",
",",
"'stock_inventory_delete'",
")",
";",
"$",
"editForm",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"InventoryType",
"(",
")",
",",
"$",
"inventory",
",",
"array",
"(",
"'action'",
"=>",
"$",
"this",
"->",
"generateUrl",
"(",
"'stock_inventory_update'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"inventory",
"->",
"getid",
"(",
")",
")",
")",
",",
"'method'",
"=>",
"'PUT'",
",",
")",
")",
";",
"return",
"array",
"(",
"'inventory'",
"=>",
"$",
"inventory",
",",
"'edit_form'",
"=>",
"$",
"editForm",
"->",
"createView",
"(",
")",
",",
"'editItemsForm'",
"=>",
"$",
"editItemsForm",
",",
"'delete_form'",
"=>",
"$",
"deleteForm",
"->",
"createView",
"(",
")",
",",
")",
";",
"}"
] | Displays a form to edit an existing Inventory entity.
@Route("/{id}/saveitems", name="stock_inventory_item_update", requirements={"id"="\d+"})
@Method("PUT")
@Template() | [
"Displays",
"a",
"form",
"to",
"edit",
"an",
"existing",
"Inventory",
"entity",
"."
] | train | https://github.com/flowcode/AmulenShopBundle/blob/500aaf4364be3c42fca69ecd10a449da03993814/src/Flowcode/ShopBundle/Controller/InventoryController.php#L258-L282 |
flowcode/AmulenShopBundle | src/Flowcode/ShopBundle/Controller/InventoryController.php | InventoryController.saveStock | public function saveStock(InventoryItem $inventoryItem, Request $request)
{
$answer = $this->get('flower.stock.service.inventory')->itemIsValid($inventoryItem);
if ($answer == true) {
$inventoryItem->setStock($request->get('stock'));
return true;
}
return false;
} | php | public function saveStock(InventoryItem $inventoryItem, Request $request)
{
$answer = $this->get('flower.stock.service.inventory')->itemIsValid($inventoryItem);
if ($answer == true) {
$inventoryItem->setStock($request->get('stock'));
return true;
}
return false;
} | [
"public",
"function",
"saveStock",
"(",
"InventoryItem",
"$",
"inventoryItem",
",",
"Request",
"$",
"request",
")",
"{",
"$",
"answer",
"=",
"$",
"this",
"->",
"get",
"(",
"'flower.stock.service.inventory'",
")",
"->",
"itemIsValid",
"(",
"$",
"inventoryItem",
")",
";",
"if",
"(",
"$",
"answer",
"==",
"true",
")",
"{",
"$",
"inventoryItem",
"->",
"setStock",
"(",
"$",
"request",
"->",
"get",
"(",
"'stock'",
")",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Edits an existing Inventory entity.
@Route("/stock/inventory/inventoryItem/{id}/save", name="stock_inventory_save")
@Method("POST")
@Template() | [
"Edits",
"an",
"existing",
"Inventory",
"entity",
"."
] | train | https://github.com/flowcode/AmulenShopBundle/blob/500aaf4364be3c42fca69ecd10a449da03993814/src/Flowcode/ShopBundle/Controller/InventoryController.php#L324-L333 |
iRAP-software/package-core-libs | src/StringLib.php | StringLib.generateRandomString | public static function generateRandomString($numChars, $charOptions=0)
{
$userLowerCase = !($charOptions & self::PASSWORD_DISABLE_LOWER_CASE);
$useUppercase = !($charOptions & self::PASSWORD_DISABLE_UPPER_CASE);
$useNumbers = !($charOptions & self::PASSWORD_DISABLE_NUMBERS);
$useSpecialChars = !($charOptions & self::PASSWORD_DISABLE_SPECIAL_CHARS);
$lowerCase = str_split('abcdefghijklmnopqrstuvwxyz', 1);
$numbers = str_split('0123456789', 1);
$capitalLetters = str_split('ABCDEFGHIJKLMNOPQRSTUVWXYZ', 1);
$specialChars = str_split('!@#$%^&*(){}[]+-/_', 1);
$possibleChars = array();
if ($userLowerCase)
{
$possibleChars = array_merge($possibleChars, $lowerCase);
$requirements['lower_case'] = $lowerCase;
}
if ($useUppercase)
{
$possibleChars = array_merge($possibleChars, $capitalLetters);
$requirements['capitals'] = $capitalLetters;
}
if ($useNumbers)
{
$possibleChars = array_merge($possibleChars, $numbers);
$requirements['numbers'] = $numbers;
}
if ($useSpecialChars)
{
$possibleChars = array_merge($possibleChars, $specialChars);
$requirements['special_characters'] = $specialChars;
}
$acceptableToken = false;
while (!$acceptableToken)
{
$outstandingRequirements = $requirements; #copy the array
$token = '';
$acceptableToken = true;
$maxPossibleCharIndex = count($possibleChars) - 1;
for ($s=0; $s<$numChars; $s++)
{
$token .= $possibleChars[rand(0, $maxPossibleCharIndex)];
}
$stringArray = str_split($token);
foreach ($stringArray as $character)
{
if (count($outstandingRequirements) > 0) # must recalc each time
{
foreach ($outstandingRequirements as $name => $arrayOfChars)
{
if (array_search($character, $arrayOfChars) !== FALSE)
{
unset($outstandingRequirements[$name]);
break;
}
}
}
else
{
# Stop parsing the token as soon as all required chars found
break;
}
}
if (count($outstandingRequirements) != 0)
{
$acceptableToken = false;
}
}
return $token;
} | php | public static function generateRandomString($numChars, $charOptions=0)
{
$userLowerCase = !($charOptions & self::PASSWORD_DISABLE_LOWER_CASE);
$useUppercase = !($charOptions & self::PASSWORD_DISABLE_UPPER_CASE);
$useNumbers = !($charOptions & self::PASSWORD_DISABLE_NUMBERS);
$useSpecialChars = !($charOptions & self::PASSWORD_DISABLE_SPECIAL_CHARS);
$lowerCase = str_split('abcdefghijklmnopqrstuvwxyz', 1);
$numbers = str_split('0123456789', 1);
$capitalLetters = str_split('ABCDEFGHIJKLMNOPQRSTUVWXYZ', 1);
$specialChars = str_split('!@#$%^&*(){}[]+-/_', 1);
$possibleChars = array();
if ($userLowerCase)
{
$possibleChars = array_merge($possibleChars, $lowerCase);
$requirements['lower_case'] = $lowerCase;
}
if ($useUppercase)
{
$possibleChars = array_merge($possibleChars, $capitalLetters);
$requirements['capitals'] = $capitalLetters;
}
if ($useNumbers)
{
$possibleChars = array_merge($possibleChars, $numbers);
$requirements['numbers'] = $numbers;
}
if ($useSpecialChars)
{
$possibleChars = array_merge($possibleChars, $specialChars);
$requirements['special_characters'] = $specialChars;
}
$acceptableToken = false;
while (!$acceptableToken)
{
$outstandingRequirements = $requirements; #copy the array
$token = '';
$acceptableToken = true;
$maxPossibleCharIndex = count($possibleChars) - 1;
for ($s=0; $s<$numChars; $s++)
{
$token .= $possibleChars[rand(0, $maxPossibleCharIndex)];
}
$stringArray = str_split($token);
foreach ($stringArray as $character)
{
if (count($outstandingRequirements) > 0) # must recalc each time
{
foreach ($outstandingRequirements as $name => $arrayOfChars)
{
if (array_search($character, $arrayOfChars) !== FALSE)
{
unset($outstandingRequirements[$name]);
break;
}
}
}
else
{
# Stop parsing the token as soon as all required chars found
break;
}
}
if (count($outstandingRequirements) != 0)
{
$acceptableToken = false;
}
}
return $token;
} | [
"public",
"static",
"function",
"generateRandomString",
"(",
"$",
"numChars",
",",
"$",
"charOptions",
"=",
"0",
")",
"{",
"$",
"userLowerCase",
"=",
"!",
"(",
"$",
"charOptions",
"&",
"self",
"::",
"PASSWORD_DISABLE_LOWER_CASE",
")",
";",
"$",
"useUppercase",
"=",
"!",
"(",
"$",
"charOptions",
"&",
"self",
"::",
"PASSWORD_DISABLE_UPPER_CASE",
")",
";",
"$",
"useNumbers",
"=",
"!",
"(",
"$",
"charOptions",
"&",
"self",
"::",
"PASSWORD_DISABLE_NUMBERS",
")",
";",
"$",
"useSpecialChars",
"=",
"!",
"(",
"$",
"charOptions",
"&",
"self",
"::",
"PASSWORD_DISABLE_SPECIAL_CHARS",
")",
";",
"$",
"lowerCase",
"=",
"str_split",
"(",
"'abcdefghijklmnopqrstuvwxyz'",
",",
"1",
")",
";",
"$",
"numbers",
"=",
"str_split",
"(",
"'0123456789'",
",",
"1",
")",
";",
"$",
"capitalLetters",
"=",
"str_split",
"(",
"'ABCDEFGHIJKLMNOPQRSTUVWXYZ'",
",",
"1",
")",
";",
"$",
"specialChars",
"=",
"str_split",
"(",
"'!@#$%^&*(){}[]+-/_'",
",",
"1",
")",
";",
"$",
"possibleChars",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"userLowerCase",
")",
"{",
"$",
"possibleChars",
"=",
"array_merge",
"(",
"$",
"possibleChars",
",",
"$",
"lowerCase",
")",
";",
"$",
"requirements",
"[",
"'lower_case'",
"]",
"=",
"$",
"lowerCase",
";",
"}",
"if",
"(",
"$",
"useUppercase",
")",
"{",
"$",
"possibleChars",
"=",
"array_merge",
"(",
"$",
"possibleChars",
",",
"$",
"capitalLetters",
")",
";",
"$",
"requirements",
"[",
"'capitals'",
"]",
"=",
"$",
"capitalLetters",
";",
"}",
"if",
"(",
"$",
"useNumbers",
")",
"{",
"$",
"possibleChars",
"=",
"array_merge",
"(",
"$",
"possibleChars",
",",
"$",
"numbers",
")",
";",
"$",
"requirements",
"[",
"'numbers'",
"]",
"=",
"$",
"numbers",
";",
"}",
"if",
"(",
"$",
"useSpecialChars",
")",
"{",
"$",
"possibleChars",
"=",
"array_merge",
"(",
"$",
"possibleChars",
",",
"$",
"specialChars",
")",
";",
"$",
"requirements",
"[",
"'special_characters'",
"]",
"=",
"$",
"specialChars",
";",
"}",
"$",
"acceptableToken",
"=",
"false",
";",
"while",
"(",
"!",
"$",
"acceptableToken",
")",
"{",
"$",
"outstandingRequirements",
"=",
"$",
"requirements",
";",
"#copy the array",
"$",
"token",
"=",
"''",
";",
"$",
"acceptableToken",
"=",
"true",
";",
"$",
"maxPossibleCharIndex",
"=",
"count",
"(",
"$",
"possibleChars",
")",
"-",
"1",
";",
"for",
"(",
"$",
"s",
"=",
"0",
";",
"$",
"s",
"<",
"$",
"numChars",
";",
"$",
"s",
"++",
")",
"{",
"$",
"token",
".=",
"$",
"possibleChars",
"[",
"rand",
"(",
"0",
",",
"$",
"maxPossibleCharIndex",
")",
"]",
";",
"}",
"$",
"stringArray",
"=",
"str_split",
"(",
"$",
"token",
")",
";",
"foreach",
"(",
"$",
"stringArray",
"as",
"$",
"character",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"outstandingRequirements",
")",
">",
"0",
")",
"# must recalc each time",
"{",
"foreach",
"(",
"$",
"outstandingRequirements",
"as",
"$",
"name",
"=>",
"$",
"arrayOfChars",
")",
"{",
"if",
"(",
"array_search",
"(",
"$",
"character",
",",
"$",
"arrayOfChars",
")",
"!==",
"FALSE",
")",
"{",
"unset",
"(",
"$",
"outstandingRequirements",
"[",
"$",
"name",
"]",
")",
";",
"break",
";",
"}",
"}",
"}",
"else",
"{",
"# Stop parsing the token as soon as all required chars found",
"break",
";",
"}",
"}",
"if",
"(",
"count",
"(",
"$",
"outstandingRequirements",
")",
"!=",
"0",
")",
"{",
"$",
"acceptableToken",
"=",
"false",
";",
"}",
"}",
"return",
"$",
"token",
";",
"}"
] | Generates a random string. This can be useful for password generation
or to create a single-use token for the user to do something
(e.g. click an email link to register).
@param int $numChars - how many characters long the string should be
@param int $charOptions - bitwise result of following vars
PASSWORD_DISABLE_LOWER_CASE
PASSWORD_DISABLE_UPPER_CASE
PASSWORD_DISABLE_NUMBERS
PASSWORD_DISABLE_SPECIAL_CHARS
@return token - the generated string | [
"Generates",
"a",
"random",
"string",
".",
"This",
"can",
"be",
"useful",
"for",
"password",
"generation",
"or",
"to",
"create",
"a",
"single",
"-",
"use",
"token",
"for",
"the",
"user",
"to",
"do",
"something",
"(",
"e",
".",
"g",
".",
"click",
"an",
"email",
"link",
"to",
"register",
")",
"."
] | train | https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/StringLib.php#L32-L113 |
iRAP-software/package-core-libs | src/StringLib.php | StringLib.endsWith | public static function endsWith($haystack,
$needle,
$caseSensitive = true,
$ignoreWhiteSpace = false)
{
$revHaystack = strrev($haystack);
$revNeedle = strrev($needle);
return self::startsWith(
$revHaystack,
$revNeedle,
$caseSensitive,
$ignoreWhiteSpace
);
} | php | public static function endsWith($haystack,
$needle,
$caseSensitive = true,
$ignoreWhiteSpace = false)
{
$revHaystack = strrev($haystack);
$revNeedle = strrev($needle);
return self::startsWith(
$revHaystack,
$revNeedle,
$caseSensitive,
$ignoreWhiteSpace
);
} | [
"public",
"static",
"function",
"endsWith",
"(",
"$",
"haystack",
",",
"$",
"needle",
",",
"$",
"caseSensitive",
"=",
"true",
",",
"$",
"ignoreWhiteSpace",
"=",
"false",
")",
"{",
"$",
"revHaystack",
"=",
"strrev",
"(",
"$",
"haystack",
")",
";",
"$",
"revNeedle",
"=",
"strrev",
"(",
"$",
"needle",
")",
";",
"return",
"self",
"::",
"startsWith",
"(",
"$",
"revHaystack",
",",
"$",
"revNeedle",
",",
"$",
"caseSensitive",
",",
"$",
"ignoreWhiteSpace",
")",
";",
"}"
] | Checks to see if the string in $haystack ends with $needle.
@param string haystack - the string to search in.
@param string needle - the string to look for
@param bool caseSensitive - whether to enforce case sensitivity or not
(default true)
@param bool ignoreWhiteSpace - whether to ignore white space at the ends
of the inputs
@return true if haystack begins with the provided string. False otherwise. | [
"Checks",
"to",
"see",
"if",
"the",
"string",
"in",
"$haystack",
"ends",
"with",
"$needle",
"."
] | train | https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/StringLib.php#L128-L142 |
iRAP-software/package-core-libs | src/StringLib.php | StringLib.startsWith | public static function startsWith($haystack,
$needle,
$caseSensitive = true,
$ignoreWhiteSpace = false)
{
$result = false;
if ($caseSensitive == false) //Reduce to lower case if required.
{
$haystack = strtolower($haystack);
$needle = strtolower($needle);
}
if ($ignoreWhiteSpace)
{
$haystack = trim($haystack);
$needle = trim($needle);
}
if (strpos($haystack, $needle) === 0)
{
$result = true;
}
return $result;
} | php | public static function startsWith($haystack,
$needle,
$caseSensitive = true,
$ignoreWhiteSpace = false)
{
$result = false;
if ($caseSensitive == false) //Reduce to lower case if required.
{
$haystack = strtolower($haystack);
$needle = strtolower($needle);
}
if ($ignoreWhiteSpace)
{
$haystack = trim($haystack);
$needle = trim($needle);
}
if (strpos($haystack, $needle) === 0)
{
$result = true;
}
return $result;
} | [
"public",
"static",
"function",
"startsWith",
"(",
"$",
"haystack",
",",
"$",
"needle",
",",
"$",
"caseSensitive",
"=",
"true",
",",
"$",
"ignoreWhiteSpace",
"=",
"false",
")",
"{",
"$",
"result",
"=",
"false",
";",
"if",
"(",
"$",
"caseSensitive",
"==",
"false",
")",
"//Reduce to lower case if required.",
"{",
"$",
"haystack",
"=",
"strtolower",
"(",
"$",
"haystack",
")",
";",
"$",
"needle",
"=",
"strtolower",
"(",
"$",
"needle",
")",
";",
"}",
"if",
"(",
"$",
"ignoreWhiteSpace",
")",
"{",
"$",
"haystack",
"=",
"trim",
"(",
"$",
"haystack",
")",
";",
"$",
"needle",
"=",
"trim",
"(",
"$",
"needle",
")",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"haystack",
",",
"$",
"needle",
")",
"===",
"0",
")",
"{",
"$",
"result",
"=",
"true",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Checks to see if the string in $haystack begins with $needle.
@param haystack - the string to search in.
@param needle - the string to look for
@param caseSensitive - whether to enforce case sensitivity or not (default true)
@param ignoreWhiteSpace - whether to ignore white space at the ends of the inputs
functionfunction
@return result - true if the haystack begins with the provided string. False otherwise. | [
"Checks",
"to",
"see",
"if",
"the",
"string",
"in",
"$haystack",
"begins",
"with",
"$needle",
"."
] | train | https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/StringLib.php#L155-L180 |
iRAP-software/package-core-libs | src/StringLib.php | StringLib.nl2br | public static function nl2br($input)
{
$output = str_replace(PHP_EOL, '<br />', $input);
$output = str_replace("\r\n", '<br />', $output);
return $output;
} | php | public static function nl2br($input)
{
$output = str_replace(PHP_EOL, '<br />', $input);
$output = str_replace("\r\n", '<br />', $output);
return $output;
} | [
"public",
"static",
"function",
"nl2br",
"(",
"$",
"input",
")",
"{",
"$",
"output",
"=",
"str_replace",
"(",
"PHP_EOL",
",",
"'<br />'",
",",
"$",
"input",
")",
";",
"$",
"output",
"=",
"str_replace",
"(",
"\"\\r\\n\"",
",",
"'<br />'",
",",
"$",
"output",
")",
";",
"return",
"$",
"output",
";",
"}"
] | My own 'extended' version of nl2br which works in a lot of cases where
the standard nl2br doesnot
@param string $input - the input string to convert
@return string $output - the converted string | [
"My",
"own",
"extended",
"version",
"of",
"nl2br",
"which",
"works",
"in",
"a",
"lot",
"of",
"cases",
"where",
"the",
"standard",
"nl2br",
"doesnot"
] | train | https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/StringLib.php#L202-L207 |
iRAP-software/package-core-libs | src/StringLib.php | StringLib.convertLineEndings | public static function convertLineEndings($input)
{
# This must be first as it is the most specific of the endlines.
$output = str_replace("\r\n", "\n", $input);
# There are some strange cases where it is just \r
$output = str_replace("\r", "\n", $output);
# the system might be windows!
$output = str_replace("\n", PHP_EOL, $output);
return $output;
} | php | public static function convertLineEndings($input)
{
# This must be first as it is the most specific of the endlines.
$output = str_replace("\r\n", "\n", $input);
# There are some strange cases where it is just \r
$output = str_replace("\r", "\n", $output);
# the system might be windows!
$output = str_replace("\n", PHP_EOL, $output);
return $output;
} | [
"public",
"static",
"function",
"convertLineEndings",
"(",
"$",
"input",
")",
"{",
"# This must be first as it is the most specific of the endlines.",
"$",
"output",
"=",
"str_replace",
"(",
"\"\\r\\n\"",
",",
"\"\\n\"",
",",
"$",
"input",
")",
";",
"# There are some strange cases where it is just \\r",
"$",
"output",
"=",
"str_replace",
"(",
"\"\\r\"",
",",
"\"\\n\"",
",",
"$",
"output",
")",
";",
"# the system might be windows!",
"$",
"output",
"=",
"str_replace",
"(",
"\"\\n\"",
",",
"PHP_EOL",
",",
"$",
"output",
")",
";",
"return",
"$",
"output",
";",
"}"
] | Converts any newlines to the systems format.
The use of " instead of ' is very important!
@param $input - any string input
@return $output - the newly reformatted string | [
"Converts",
"any",
"newlines",
"to",
"the",
"systems",
"format",
".",
"The",
"use",
"of",
"instead",
"of",
"is",
"very",
"important!"
] | train | https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/StringLib.php#L216-L228 |
iRAP-software/package-core-libs | src/StringLib.php | StringLib.encrypt | public static function encrypt($message, $key)
{
$md5Key = md5($key);
$encrypted = mcrypt_encrypt(
MCRYPT_RIJNDAEL_256,
$md5Key,
$message,
MCRYPT_MODE_CBC,
md5($md5Key)
);
$encoded_encryption = base64_encode($encrypted);
return $encoded_encryption;
} | php | public static function encrypt($message, $key)
{
$md5Key = md5($key);
$encrypted = mcrypt_encrypt(
MCRYPT_RIJNDAEL_256,
$md5Key,
$message,
MCRYPT_MODE_CBC,
md5($md5Key)
);
$encoded_encryption = base64_encode($encrypted);
return $encoded_encryption;
} | [
"public",
"static",
"function",
"encrypt",
"(",
"$",
"message",
",",
"$",
"key",
")",
"{",
"$",
"md5Key",
"=",
"md5",
"(",
"$",
"key",
")",
";",
"$",
"encrypted",
"=",
"mcrypt_encrypt",
"(",
"MCRYPT_RIJNDAEL_256",
",",
"$",
"md5Key",
",",
"$",
"message",
",",
"MCRYPT_MODE_CBC",
",",
"md5",
"(",
"$",
"md5Key",
")",
")",
";",
"$",
"encoded_encryption",
"=",
"base64_encode",
"(",
"$",
"encrypted",
")",
";",
"return",
"$",
"encoded_encryption",
";",
"}"
] | Encrypt a String
@param String $message - the message to encrypt
@param String $key - the key to encrypt and then decrypt the message.
@return String - the encryptd form of the string | [
"Encrypt",
"a",
"String"
] | train | https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/StringLib.php#L237-L251 |
iRAP-software/package-core-libs | src/StringLib.php | StringLib.decrypt | public static function decrypt($encrypted_text, $key)
{
$md5Key = md5($key);
$decrypted_text = mcrypt_decrypt(
MCRYPT_RIJNDAEL_256,
$md5Key,
base64_decode($encrypted_text),
MCRYPT_MODE_CBC,
md5($md5Key)
);
$trimmed_decryption = rtrim($decrypted_text, "\0");
return $trimmed_decryption;
} | php | public static function decrypt($encrypted_text, $key)
{
$md5Key = md5($key);
$decrypted_text = mcrypt_decrypt(
MCRYPT_RIJNDAEL_256,
$md5Key,
base64_decode($encrypted_text),
MCRYPT_MODE_CBC,
md5($md5Key)
);
$trimmed_decryption = rtrim($decrypted_text, "\0");
return $trimmed_decryption;
} | [
"public",
"static",
"function",
"decrypt",
"(",
"$",
"encrypted_text",
",",
"$",
"key",
")",
"{",
"$",
"md5Key",
"=",
"md5",
"(",
"$",
"key",
")",
";",
"$",
"decrypted_text",
"=",
"mcrypt_decrypt",
"(",
"MCRYPT_RIJNDAEL_256",
",",
"$",
"md5Key",
",",
"base64_decode",
"(",
"$",
"encrypted_text",
")",
",",
"MCRYPT_MODE_CBC",
",",
"md5",
"(",
"$",
"md5Key",
")",
")",
";",
"$",
"trimmed_decryption",
"=",
"rtrim",
"(",
"$",
"decrypted_text",
",",
"\"\\0\"",
")",
";",
"return",
"$",
"trimmed_decryption",
";",
"}"
] | Decrypt a String
@param String $encrypted_text - the message to decrypt
@param String $key - the key to encrypt and decrypt the message.
@return String - the unencrypted form of the text | [
"Decrypt",
"a",
"String"
] | train | https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/StringLib.php#L260-L274 |
iRAP-software/package-core-libs | src/StringLib.php | StringLib.isRegExp | public static function isRegExp($regexp)
{
$isRegExp = true;
if (@preg_match($regexp, "Put any string in here.") === false)
{
$isRegExp = false;
}
return $isRegExp;
} | php | public static function isRegExp($regexp)
{
$isRegExp = true;
if (@preg_match($regexp, "Put any string in here.") === false)
{
$isRegExp = false;
}
return $isRegExp;
} | [
"public",
"static",
"function",
"isRegExp",
"(",
"$",
"regexp",
")",
"{",
"$",
"isRegExp",
"=",
"true",
";",
"if",
"(",
"@",
"preg_match",
"(",
"$",
"regexp",
",",
"\"Put any string in here.\"",
")",
"===",
"false",
")",
"{",
"$",
"isRegExp",
"=",
"false",
";",
"}",
"return",
"$",
"isRegExp",
";",
"}"
] | Check whether the provided string is a regexp.
Reference:
http://stackoverflow.com/questions/8825025/test-if-a-regular-expression-is-a-valid-one-in-php | [
"Check",
"whether",
"the",
"provided",
"string",
"is",
"a",
"regexp",
".",
"Reference",
":",
"http",
":",
"//",
"stackoverflow",
".",
"com",
"/",
"questions",
"/",
"8825025",
"/",
"test",
"-",
"if",
"-",
"a",
"-",
"regular",
"-",
"expression",
"-",
"is",
"-",
"a",
"-",
"valid",
"-",
"one",
"-",
"in",
"-",
"php"
] | train | https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/StringLib.php#L293-L303 |
iRAP-software/package-core-libs | src/StringLib.php | StringLib.sanitizeRegExp | public static function sanitizeRegExp($regExp)
{
$pattern_parts = explode($regExp{0}, trim($regExp));
$pattern_last = sizeof($pattern_parts) - 1;
$pattern_parts[$pattern_last] = str_replace('e', '', $pattern_parts[$pattern_last]);
return implode($regExp{0}, $pattern_parts);
} | php | public static function sanitizeRegExp($regExp)
{
$pattern_parts = explode($regExp{0}, trim($regExp));
$pattern_last = sizeof($pattern_parts) - 1;
$pattern_parts[$pattern_last] = str_replace('e', '', $pattern_parts[$pattern_last]);
return implode($regExp{0}, $pattern_parts);
} | [
"public",
"static",
"function",
"sanitizeRegExp",
"(",
"$",
"regExp",
")",
"{",
"$",
"pattern_parts",
"=",
"explode",
"(",
"$",
"regExp",
"{",
"0",
"}",
",",
"trim",
"(",
"$",
"regExp",
")",
")",
";",
"$",
"pattern_last",
"=",
"sizeof",
"(",
"$",
"pattern_parts",
")",
"-",
"1",
";",
"$",
"pattern_parts",
"[",
"$",
"pattern_last",
"]",
"=",
"str_replace",
"(",
"'e'",
",",
"''",
",",
"$",
"pattern_parts",
"[",
"$",
"pattern_last",
"]",
")",
";",
"return",
"implode",
"(",
"$",
"regExp",
"{",
"0",
"}",
",",
"$",
"pattern_parts",
")",
";",
"}"
] | Function to remove the e modifier from regular expressions.
http://stackoverflow.com/questions/7243073/how-can-i-disable-the-e-preg-replace-eval-modifier-in-php
@param string $regExp
@return string - the sanitized regexp without the modifier. | [
"Function",
"to",
"remove",
"the",
"e",
"modifier",
"from",
"regular",
"expressions",
".",
"http",
":",
"//",
"stackoverflow",
".",
"com",
"/",
"questions",
"/",
"7243073",
"/",
"how",
"-",
"can",
"-",
"i",
"-",
"disable",
"-",
"the",
"-",
"e",
"-",
"preg",
"-",
"replace",
"-",
"eval",
"-",
"modifier",
"-",
"in",
"-",
"php"
] | train | https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/StringLib.php#L312-L319 |
iRAP-software/package-core-libs | src/StringLib.php | StringLib.replace | public static function replace($search, $replace, $subject)
{
if (is_array($search) || is_array($replace))
{
throw new \Exception("The search or replace parameters cannot be arrays.");
}
$pairs = array(
$search => $replace
);
return strtr($subject, $pairs);
} | php | public static function replace($search, $replace, $subject)
{
if (is_array($search) || is_array($replace))
{
throw new \Exception("The search or replace parameters cannot be arrays.");
}
$pairs = array(
$search => $replace
);
return strtr($subject, $pairs);
} | [
"public",
"static",
"function",
"replace",
"(",
"$",
"search",
",",
"$",
"replace",
",",
"$",
"subject",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"search",
")",
"||",
"is_array",
"(",
"$",
"replace",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"The search or replace parameters cannot be arrays.\"",
")",
";",
"}",
"$",
"pairs",
"=",
"array",
"(",
"$",
"search",
"=>",
"$",
"replace",
")",
";",
"return",
"strtr",
"(",
"$",
"subject",
",",
"$",
"pairs",
")",
";",
"}"
] | This is an wrapper around strtr that enforces the use of strings instead of arrays for
the parameters. If you want to substitute multiple items then please use replacePairs()
instead. Both methods wrap around strtr instead of str_replace because I believe that the
behaviour is closer to what the developer would expect if they hadn't ready any documentation
For information about how strtr may be safer than str_replace, please read the comments
in http://php.net/manual/en/function.strtr.php
@param string $search - the string to search for within the subject that needs replacing
@param string $replace - the string to replace with
@param string $subject - the string to perform substitutions in.
@return string - the result of converting the subject string. | [
"This",
"is",
"an",
"wrapper",
"around",
"strtr",
"that",
"enforces",
"the",
"use",
"of",
"strings",
"instead",
"of",
"arrays",
"for",
"the",
"parameters",
".",
"If",
"you",
"want",
"to",
"substitute",
"multiple",
"items",
"then",
"please",
"use",
"replacePairs",
"()",
"instead",
".",
"Both",
"methods",
"wrap",
"around",
"strtr",
"instead",
"of",
"str_replace",
"because",
"I",
"believe",
"that",
"the",
"behaviour",
"is",
"closer",
"to",
"what",
"the",
"developer",
"would",
"expect",
"if",
"they",
"hadn",
"t",
"ready",
"any",
"documentation",
"For",
"information",
"about",
"how",
"strtr",
"may",
"be",
"safer",
"than",
"str_replace",
"please",
"read",
"the",
"comments",
"in",
"http",
":",
"//",
"php",
".",
"net",
"/",
"manual",
"/",
"en",
"/",
"function",
".",
"strtr",
".",
"php"
] | train | https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/StringLib.php#L334-L346 |
iRAP-software/package-core-libs | src/StringLib.php | StringLib.contains | public static function contains($haystack, $needle, $caseSensitive = true)
{
if ($caseSensitive)
{
$pos = strpos($haystack, $needle);
}
else
{
$pos = strpos($haystack, $needle);
}
# Need to be careful to by type sensitive here because could return value 0 which would
# need to return true.
return ($pos !== FALSE);
} | php | public static function contains($haystack, $needle, $caseSensitive = true)
{
if ($caseSensitive)
{
$pos = strpos($haystack, $needle);
}
else
{
$pos = strpos($haystack, $needle);
}
# Need to be careful to by type sensitive here because could return value 0 which would
# need to return true.
return ($pos !== FALSE);
} | [
"public",
"static",
"function",
"contains",
"(",
"$",
"haystack",
",",
"$",
"needle",
",",
"$",
"caseSensitive",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"caseSensitive",
")",
"{",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"haystack",
",",
"$",
"needle",
")",
";",
"}",
"else",
"{",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"haystack",
",",
"$",
"needle",
")",
";",
"}",
"# Need to be careful to by type sensitive here because could return value 0 which would",
"# need to return true.",
"return",
"(",
"$",
"pos",
"!==",
"FALSE",
")",
";",
"}"
] | Find out whether the $needle string contains the $haystack string.
This will use strpos rather than strstr because strpos is faster and less
memory intensive.
https://stackoverflow.com/questions/5820586/which-method-is-preferred-strstr-or-strpos
@return bool - true if does contain, false if not | [
"Find",
"out",
"whether",
"the",
"$needle",
"string",
"contains",
"the",
"$haystack",
"string",
".",
"This",
"will",
"use",
"strpos",
"rather",
"than",
"strstr",
"because",
"strpos",
"is",
"faster",
"and",
"less",
"memory",
"intensive",
".",
"https",
":",
"//",
"stackoverflow",
".",
"com",
"/",
"questions",
"/",
"5820586",
"/",
"which",
"-",
"method",
"-",
"is",
"-",
"preferred",
"-",
"strstr",
"-",
"or",
"-",
"strpos"
] | train | https://github.com/iRAP-software/package-core-libs/blob/244871d2fbc2f3fac26ff4b98715224953d9befb/src/StringLib.php#L372-L386 |
netcore/module-category | Traits/ControllerHelpersTrait.php | ControllerHelpersTrait.clearCache | private function clearCache(): void
{
try {
$cacheTag = config('netcore.module-category.cache_tag');
$isRedis = cache()->getStore() instanceof RedisStore;
if ($cacheTag && $isRedis) {
cache()->tags([$cacheTag])->flush();
} else {
cache()->flush();
}
} catch (Exception $exception) {
logger()->error('[module-category] Unable to clear cache: ' . $exception->getMessage());
}
} | php | private function clearCache(): void
{
try {
$cacheTag = config('netcore.module-category.cache_tag');
$isRedis = cache()->getStore() instanceof RedisStore;
if ($cacheTag && $isRedis) {
cache()->tags([$cacheTag])->flush();
} else {
cache()->flush();
}
} catch (Exception $exception) {
logger()->error('[module-category] Unable to clear cache: ' . $exception->getMessage());
}
} | [
"private",
"function",
"clearCache",
"(",
")",
":",
"void",
"{",
"try",
"{",
"$",
"cacheTag",
"=",
"config",
"(",
"'netcore.module-category.cache_tag'",
")",
";",
"$",
"isRedis",
"=",
"cache",
"(",
")",
"->",
"getStore",
"(",
")",
"instanceof",
"RedisStore",
";",
"if",
"(",
"$",
"cacheTag",
"&&",
"$",
"isRedis",
")",
"{",
"cache",
"(",
")",
"->",
"tags",
"(",
"[",
"$",
"cacheTag",
"]",
")",
"->",
"flush",
"(",
")",
";",
"}",
"else",
"{",
"cache",
"(",
")",
"->",
"flush",
"(",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"exception",
")",
"{",
"logger",
"(",
")",
"->",
"error",
"(",
"'[module-category] Unable to clear cache: '",
".",
"$",
"exception",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] | Clear cache.
@return void | [
"Clear",
"cache",
"."
] | train | https://github.com/netcore/module-category/blob/61a4fc2525774f8ddea730ad9f6f06644552adf7/Traits/ControllerHelpersTrait.php#L18-L32 |
netcore/module-category | Traits/ControllerHelpersTrait.php | ControllerHelpersTrait.modifySlugs | private function modifySlugs(Request &$request): void
{
$translations = $request->input('translations', []);
$existingSlugs = [];
$i = 1;
foreach ($translations as $iso => $translationData) {
// Auto generated
if (!$slug = array_get($translationData, 'slug')) {
continue;
}
$slug = SlugService::createSlug(CategoryTranslation::class, 'slug', $slug, ['unique' => false]);
// Prevent equal slug's on create.
if (in_array($slug, $existingSlugs)) {
$slug .= '-' . $i;
$i++;
}
$translations[$iso]['slug'] = $slug;
$existingSlugs[] = $slug;
}
$request->merge(compact('translations'));
} | php | private function modifySlugs(Request &$request): void
{
$translations = $request->input('translations', []);
$existingSlugs = [];
$i = 1;
foreach ($translations as $iso => $translationData) {
// Auto generated
if (!$slug = array_get($translationData, 'slug')) {
continue;
}
$slug = SlugService::createSlug(CategoryTranslation::class, 'slug', $slug, ['unique' => false]);
// Prevent equal slug's on create.
if (in_array($slug, $existingSlugs)) {
$slug .= '-' . $i;
$i++;
}
$translations[$iso]['slug'] = $slug;
$existingSlugs[] = $slug;
}
$request->merge(compact('translations'));
} | [
"private",
"function",
"modifySlugs",
"(",
"Request",
"&",
"$",
"request",
")",
":",
"void",
"{",
"$",
"translations",
"=",
"$",
"request",
"->",
"input",
"(",
"'translations'",
",",
"[",
"]",
")",
";",
"$",
"existingSlugs",
"=",
"[",
"]",
";",
"$",
"i",
"=",
"1",
";",
"foreach",
"(",
"$",
"translations",
"as",
"$",
"iso",
"=>",
"$",
"translationData",
")",
"{",
"// Auto generated",
"if",
"(",
"!",
"$",
"slug",
"=",
"array_get",
"(",
"$",
"translationData",
",",
"'slug'",
")",
")",
"{",
"continue",
";",
"}",
"$",
"slug",
"=",
"SlugService",
"::",
"createSlug",
"(",
"CategoryTranslation",
"::",
"class",
",",
"'slug'",
",",
"$",
"slug",
",",
"[",
"'unique'",
"=>",
"false",
"]",
")",
";",
"// Prevent equal slug's on create.",
"if",
"(",
"in_array",
"(",
"$",
"slug",
",",
"$",
"existingSlugs",
")",
")",
"{",
"$",
"slug",
".=",
"'-'",
".",
"$",
"i",
";",
"$",
"i",
"++",
";",
"}",
"$",
"translations",
"[",
"$",
"iso",
"]",
"[",
"'slug'",
"]",
"=",
"$",
"slug",
";",
"$",
"existingSlugs",
"[",
"]",
"=",
"$",
"slug",
";",
"}",
"$",
"request",
"->",
"merge",
"(",
"compact",
"(",
"'translations'",
")",
")",
";",
"}"
] | Check and modify custom slug.
@param Request $request
@return void | [
"Check",
"and",
"modify",
"custom",
"slug",
"."
] | train | https://github.com/netcore/module-category/blob/61a4fc2525774f8ddea730ad9f6f06644552adf7/Traits/ControllerHelpersTrait.php#L40-L65 |
dreamfactorysoftware/df-couchdb | database/migrations/2015_02_03_161457_create_couchdb_tables.php | CreateCouchDbTables.up | public function up()
{
// CouchDB Service Configuration
Schema::create(
'couchdb_config',
function (Blueprint $t){
$t->integer('service_id')->unsigned()->primary();
$t->foreign('service_id')->references('id')->on('service')->onDelete('cascade');
$t->string('dsn')->default(0)->nullable();
$t->text('options')->nullable();
}
);
} | php | public function up()
{
// CouchDB Service Configuration
Schema::create(
'couchdb_config',
function (Blueprint $t){
$t->integer('service_id')->unsigned()->primary();
$t->foreign('service_id')->references('id')->on('service')->onDelete('cascade');
$t->string('dsn')->default(0)->nullable();
$t->text('options')->nullable();
}
);
} | [
"public",
"function",
"up",
"(",
")",
"{",
"// CouchDB Service Configuration",
"Schema",
"::",
"create",
"(",
"'couchdb_config'",
",",
"function",
"(",
"Blueprint",
"$",
"t",
")",
"{",
"$",
"t",
"->",
"integer",
"(",
"'service_id'",
")",
"->",
"unsigned",
"(",
")",
"->",
"primary",
"(",
")",
";",
"$",
"t",
"->",
"foreign",
"(",
"'service_id'",
")",
"->",
"references",
"(",
"'id'",
")",
"->",
"on",
"(",
"'service'",
")",
"->",
"onDelete",
"(",
"'cascade'",
")",
";",
"$",
"t",
"->",
"string",
"(",
"'dsn'",
")",
"->",
"default",
"(",
"0",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"t",
"->",
"text",
"(",
"'options'",
")",
"->",
"nullable",
"(",
")",
";",
"}",
")",
";",
"}"
] | Run the migrations.
@return void | [
"Run",
"the",
"migrations",
"."
] | train | https://github.com/dreamfactorysoftware/df-couchdb/blob/aca68357773ec0a12ae747cefbcace6a935feba9/database/migrations/2015_02_03_161457_create_couchdb_tables.php#L13-L25 |
sheychen290/inutils | src/Storage/Normalizable.php | Normalizable.getAll | public function getAll()
{
$all = parent::getAll();
$res = [];
foreach ($all as $key => $raw) {
$res[$key] = $raw['value'];
}
return $res;
} | php | public function getAll()
{
$all = parent::getAll();
$res = [];
foreach ($all as $key => $raw) {
$res[$key] = $raw['value'];
}
return $res;
} | [
"public",
"function",
"getAll",
"(",
")",
"{",
"$",
"all",
"=",
"parent",
"::",
"getAll",
"(",
")",
";",
"$",
"res",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"all",
"as",
"$",
"key",
"=>",
"$",
"raw",
")",
"{",
"$",
"res",
"[",
"$",
"key",
"]",
"=",
"$",
"raw",
"[",
"'value'",
"]",
";",
"}",
"return",
"$",
"res",
";",
"}"
] | Get Normalized Data Array
@return array | [
"Get",
"Normalized",
"Data",
"Array"
] | train | https://github.com/sheychen290/inutils/blob/43cae2967faa1df57ec9bbf9596b45c0762081a6/src/Storage/Normalizable.php#L15-L24 |
sheychen290/inutils | src/Storage/Normalizable.php | Normalizable.set | public function set(string $key, $value)
{
parent::set(Formater::normalize($key), [
'key' => $key,
'value' => $value
]);
} | php | public function set(string $key, $value)
{
parent::set(Formater::normalize($key), [
'key' => $key,
'value' => $value
]);
} | [
"public",
"function",
"set",
"(",
"string",
"$",
"key",
",",
"$",
"value",
")",
"{",
"parent",
"::",
"set",
"(",
"Formater",
"::",
"normalize",
"(",
"$",
"key",
")",
",",
"[",
"'key'",
"=>",
"$",
"key",
",",
"'value'",
"=>",
"$",
"value",
"]",
")",
";",
"}"
] | Set or Override a Value | [
"Set",
"or",
"Override",
"a",
"Value"
] | train | https://github.com/sheychen290/inutils/blob/43cae2967faa1df57ec9bbf9596b45c0762081a6/src/Storage/Normalizable.php#L57-L63 |
sheychen290/inutils | src/Storage/Normalizable.php | Normalizable.getOriginal | public function getOriginal(string $key, $default = null)
{
if ($this->has($key)) {
return parent::get(Formater::normalize($key))['key'];
}
return $default;
} | php | public function getOriginal(string $key, $default = null)
{
if ($this->has($key)) {
return parent::get(Formater::normalize($key))['key'];
}
return $default;
} | [
"public",
"function",
"getOriginal",
"(",
"string",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"has",
"(",
"$",
"key",
")",
")",
"{",
"return",
"parent",
"::",
"get",
"(",
"Formater",
"::",
"normalize",
"(",
"$",
"key",
")",
")",
"[",
"'key'",
"]",
";",
"}",
"return",
"$",
"default",
";",
"}"
] | Get Original Key from any Format
@param string $key
@param $default if key not found
@return Original Key or $default | [
"Get",
"Original",
"Key",
"from",
"any",
"Format"
] | train | https://github.com/sheychen290/inutils/blob/43cae2967faa1df57ec9bbf9596b45c0762081a6/src/Storage/Normalizable.php#L88-L95 |
open-orchestra/open-orchestra-media-admin-bundle | MediaAdminBundle/DataFixtures/MongoDB/LoadMediaData.php | LoadMediaData.generateMedia | protected function generateMedia(
$fileName,
$folderReference,
$name,
array $keywordReferencesArray,
array $languagesArray
) {
$folder = $this->getReference($folderReference);
$filePath = __DIR__ . '/Files/' . $fileName;
$tmpFilePath = $this->container->getParameter('open_orchestra_media_admin.tmp_dir')
. DIRECTORY_SEPARATOR . $fileName;
copy($filePath, $tmpFilePath);
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mimeType = finfo_file($finfo, $tmpFilePath);
finfo_close($finfo);
$uploadedFile = new UploadedFile($tmpFilePath, $fileName, $mimeType);
$saveMediaManager = $this->container->get('open_orchestra_media_admin.manager.save_media');
$media = $saveMediaManager->initializeMediaFromUploadedFile($uploadedFile, $folder->getId(), $folder->getSiteId());
$media->setName($name);
foreach ($keywordReferencesArray as $keywordReference) {
$media->addKeyword($this->getReference($keywordReference));
}
foreach ($languagesArray as $language => $labels) {
$media->addTitle($language, $labels['title']);
}
$saveMediaManager->saveMedia($media);
return $media;
} | php | protected function generateMedia(
$fileName,
$folderReference,
$name,
array $keywordReferencesArray,
array $languagesArray
) {
$folder = $this->getReference($folderReference);
$filePath = __DIR__ . '/Files/' . $fileName;
$tmpFilePath = $this->container->getParameter('open_orchestra_media_admin.tmp_dir')
. DIRECTORY_SEPARATOR . $fileName;
copy($filePath, $tmpFilePath);
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mimeType = finfo_file($finfo, $tmpFilePath);
finfo_close($finfo);
$uploadedFile = new UploadedFile($tmpFilePath, $fileName, $mimeType);
$saveMediaManager = $this->container->get('open_orchestra_media_admin.manager.save_media');
$media = $saveMediaManager->initializeMediaFromUploadedFile($uploadedFile, $folder->getId(), $folder->getSiteId());
$media->setName($name);
foreach ($keywordReferencesArray as $keywordReference) {
$media->addKeyword($this->getReference($keywordReference));
}
foreach ($languagesArray as $language => $labels) {
$media->addTitle($language, $labels['title']);
}
$saveMediaManager->saveMedia($media);
return $media;
} | [
"protected",
"function",
"generateMedia",
"(",
"$",
"fileName",
",",
"$",
"folderReference",
",",
"$",
"name",
",",
"array",
"$",
"keywordReferencesArray",
",",
"array",
"$",
"languagesArray",
")",
"{",
"$",
"folder",
"=",
"$",
"this",
"->",
"getReference",
"(",
"$",
"folderReference",
")",
";",
"$",
"filePath",
"=",
"__DIR__",
".",
"'/Files/'",
".",
"$",
"fileName",
";",
"$",
"tmpFilePath",
"=",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'open_orchestra_media_admin.tmp_dir'",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"fileName",
";",
"copy",
"(",
"$",
"filePath",
",",
"$",
"tmpFilePath",
")",
";",
"$",
"finfo",
"=",
"finfo_open",
"(",
"FILEINFO_MIME_TYPE",
")",
";",
"$",
"mimeType",
"=",
"finfo_file",
"(",
"$",
"finfo",
",",
"$",
"tmpFilePath",
")",
";",
"finfo_close",
"(",
"$",
"finfo",
")",
";",
"$",
"uploadedFile",
"=",
"new",
"UploadedFile",
"(",
"$",
"tmpFilePath",
",",
"$",
"fileName",
",",
"$",
"mimeType",
")",
";",
"$",
"saveMediaManager",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'open_orchestra_media_admin.manager.save_media'",
")",
";",
"$",
"media",
"=",
"$",
"saveMediaManager",
"->",
"initializeMediaFromUploadedFile",
"(",
"$",
"uploadedFile",
",",
"$",
"folder",
"->",
"getId",
"(",
")",
",",
"$",
"folder",
"->",
"getSiteId",
"(",
")",
")",
";",
"$",
"media",
"->",
"setName",
"(",
"$",
"name",
")",
";",
"foreach",
"(",
"$",
"keywordReferencesArray",
"as",
"$",
"keywordReference",
")",
"{",
"$",
"media",
"->",
"addKeyword",
"(",
"$",
"this",
"->",
"getReference",
"(",
"$",
"keywordReference",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"languagesArray",
"as",
"$",
"language",
"=>",
"$",
"labels",
")",
"{",
"$",
"media",
"->",
"addTitle",
"(",
"$",
"language",
",",
"$",
"labels",
"[",
"'title'",
"]",
")",
";",
"}",
"$",
"saveMediaManager",
"->",
"saveMedia",
"(",
"$",
"media",
")",
";",
"return",
"$",
"media",
";",
"}"
] | Generate a media
@param string $fileName
@param string $folderReference
@param string $name
@param array $keywordReferencesArray
@param array $languagesArray | [
"Generate",
"a",
"media"
] | train | https://github.com/open-orchestra/open-orchestra-media-admin-bundle/blob/743fa00a6491b84d67221e215a806d8b210bf773/MediaAdminBundle/DataFixtures/MongoDB/LoadMediaData.php#L91-L124 |
indigophp-archive/fuel-core | classes/Logger.php | Logger.forge | public static function forge($instance = 'default', array $handlers = array())
{
$logger = new Monolog\Logger($instance);
$handlers = \Arr::merge(\Config::get('logger.'.$instance, array()), $handlers);
foreach ($handlers as $handler)
{
$handler = \Fuel::value($handler);
$logger->pushHandler($handler);
}
return static::newInstance($instance, $logger);
} | php | public static function forge($instance = 'default', array $handlers = array())
{
$logger = new Monolog\Logger($instance);
$handlers = \Arr::merge(\Config::get('logger.'.$instance, array()), $handlers);
foreach ($handlers as $handler)
{
$handler = \Fuel::value($handler);
$logger->pushHandler($handler);
}
return static::newInstance($instance, $logger);
} | [
"public",
"static",
"function",
"forge",
"(",
"$",
"instance",
"=",
"'default'",
",",
"array",
"$",
"handlers",
"=",
"array",
"(",
")",
")",
"{",
"$",
"logger",
"=",
"new",
"Monolog",
"\\",
"Logger",
"(",
"$",
"instance",
")",
";",
"$",
"handlers",
"=",
"\\",
"Arr",
"::",
"merge",
"(",
"\\",
"Config",
"::",
"get",
"(",
"'logger.'",
".",
"$",
"instance",
",",
"array",
"(",
")",
")",
",",
"$",
"handlers",
")",
";",
"foreach",
"(",
"$",
"handlers",
"as",
"$",
"handler",
")",
"{",
"$",
"handler",
"=",
"\\",
"Fuel",
"::",
"value",
"(",
"$",
"handler",
")",
";",
"$",
"logger",
"->",
"pushHandler",
"(",
"$",
"handler",
")",
";",
"}",
"return",
"static",
"::",
"newInstance",
"(",
"$",
"instance",
",",
"$",
"logger",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/indigophp-archive/fuel-core/blob/275462154fb7937f8e1c2c541b31d8e7c5760e39/classes/Logger.php#L33-L45 |
rozaverta/cmf | core/Support/CollectionRecorder.php | CollectionRecorder.getPage | public function getPage()
{
return $this->offset > $this->limit ? floor($this->offset / $this->limit) : 1;
} | php | public function getPage()
{
return $this->offset > $this->limit ? floor($this->offset / $this->limit) : 1;
} | [
"public",
"function",
"getPage",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"offset",
">",
"$",
"this",
"->",
"limit",
"?",
"floor",
"(",
"$",
"this",
"->",
"offset",
"/",
"$",
"this",
"->",
"limit",
")",
":",
"1",
";",
"}"
] | Get current page number.
@return int | [
"Get",
"current",
"page",
"number",
"."
] | train | https://github.com/rozaverta/cmf/blob/95ed38362e397d1c700ee255f7200234ef98d356/core/Support/CollectionRecorder.php#L82-L85 |
rozaverta/cmf | core/Support/CollectionRecorder.php | CollectionRecorder.getPages | public function getPages()
{
return $this->total > $this->limit ? ceil($this->total / $this->limit) : 1;
} | php | public function getPages()
{
return $this->total > $this->limit ? ceil($this->total / $this->limit) : 1;
} | [
"public",
"function",
"getPages",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"total",
">",
"$",
"this",
"->",
"limit",
"?",
"ceil",
"(",
"$",
"this",
"->",
"total",
"/",
"$",
"this",
"->",
"limit",
")",
":",
"1",
";",
"}"
] | Count all pages.
@return int | [
"Count",
"all",
"pages",
"."
] | train | https://github.com/rozaverta/cmf/blob/95ed38362e397d1c700ee255f7200234ef98d356/core/Support/CollectionRecorder.php#L92-L95 |
firelit/firelit-framework | src/Response.php | Response.contentType | public function contentType($type = false)
{
if (headers_sent()) {
if (self::$exceptOnHeaders) {
throw new \Exception('Headers already sent. Content-type cannot be changed.');
} else {
return;
}
}
if (!$type) {
$type = "text/html";
}
self::$contentType = $type ."; charset=". strtolower(self::$charset);
header("Content-Type: ". self::$contentType);
} | php | public function contentType($type = false)
{
if (headers_sent()) {
if (self::$exceptOnHeaders) {
throw new \Exception('Headers already sent. Content-type cannot be changed.');
} else {
return;
}
}
if (!$type) {
$type = "text/html";
}
self::$contentType = $type ."; charset=". strtolower(self::$charset);
header("Content-Type: ". self::$contentType);
} | [
"public",
"function",
"contentType",
"(",
"$",
"type",
"=",
"false",
")",
"{",
"if",
"(",
"headers_sent",
"(",
")",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"exceptOnHeaders",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Headers already sent. Content-type cannot be changed.'",
")",
";",
"}",
"else",
"{",
"return",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"type",
")",
"{",
"$",
"type",
"=",
"\"text/html\"",
";",
"}",
"self",
"::",
"$",
"contentType",
"=",
"$",
"type",
".",
"\"; charset=\"",
".",
"strtolower",
"(",
"self",
"::",
"$",
"charset",
")",
";",
"header",
"(",
"\"Content-Type: \"",
".",
"self",
"::",
"$",
"contentType",
")",
";",
"}"
] | Set the HTTP content type
@param Mixed $type The response type (defaults to 'text/html') | [
"Set",
"the",
"HTTP",
"content",
"type"
] | train | https://github.com/firelit/firelit-framework/blob/308639d40391dd82b45038e35d5e3589d2666886/src/Response.php#L110-L127 |
firelit/firelit-framework | src/Response.php | Response.code | public function code($code = false)
{
if (!$code) {
return http_response_code();
}
if (headers_sent()) {
if (self::$exceptOnHeaders && (http_response_code() != $code)) {
throw new \Exception('Headers already sent. HTTP response code cannot be changed.');
} else {
return;
}
}
self::$code = $code;
http_response_code(self::$code);
} | php | public function code($code = false)
{
if (!$code) {
return http_response_code();
}
if (headers_sent()) {
if (self::$exceptOnHeaders && (http_response_code() != $code)) {
throw new \Exception('Headers already sent. HTTP response code cannot be changed.');
} else {
return;
}
}
self::$code = $code;
http_response_code(self::$code);
} | [
"public",
"function",
"code",
"(",
"$",
"code",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"code",
")",
"{",
"return",
"http_response_code",
"(",
")",
";",
"}",
"if",
"(",
"headers_sent",
"(",
")",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"exceptOnHeaders",
"&&",
"(",
"http_response_code",
"(",
")",
"!=",
"$",
"code",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Headers already sent. HTTP response code cannot be changed.'",
")",
";",
"}",
"else",
"{",
"return",
";",
"}",
"}",
"self",
"::",
"$",
"code",
"=",
"$",
"code",
";",
"http_response_code",
"(",
"self",
"::",
"$",
"code",
")",
";",
"}"
] | Set the HTTP response code
@param Mixed $code The response code to use or false to return current value
@return Return the code used if $code is false | [
"Set",
"the",
"HTTP",
"response",
"code"
] | train | https://github.com/firelit/firelit-framework/blob/308639d40391dd82b45038e35d5e3589d2666886/src/Response.php#L134-L151 |
firelit/firelit-framework | src/Response.php | Response.redirect | public function redirect($path, $type = 302, $end = true)
{
// $type should be one of the following:
// 301 = Moved permanently
// 302 = Temporary redirect
// 303 = Perform GET at new location (instead of POST)
if (headers_sent()) {
if (self::$exceptOnHeaders) {
throw new \Exception('Headers already sent. Redirect cannot be initiated.');
} else {
return;
}
}
if (self::$outputBuffering) {
$this->cleanBuffer();
}
$this->code($type);
header('Location: '. $path);
if ($end) {
exit;
}
} | php | public function redirect($path, $type = 302, $end = true)
{
// $type should be one of the following:
// 301 = Moved permanently
// 302 = Temporary redirect
// 303 = Perform GET at new location (instead of POST)
if (headers_sent()) {
if (self::$exceptOnHeaders) {
throw new \Exception('Headers already sent. Redirect cannot be initiated.');
} else {
return;
}
}
if (self::$outputBuffering) {
$this->cleanBuffer();
}
$this->code($type);
header('Location: '. $path);
if ($end) {
exit;
}
} | [
"public",
"function",
"redirect",
"(",
"$",
"path",
",",
"$",
"type",
"=",
"302",
",",
"$",
"end",
"=",
"true",
")",
"{",
"// $type should be one of the following:",
"// 301 = Moved permanently",
"// 302 = Temporary redirect",
"// 303 = Perform GET at new location (instead of POST)",
"if",
"(",
"headers_sent",
"(",
")",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"exceptOnHeaders",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Headers already sent. Redirect cannot be initiated.'",
")",
";",
"}",
"else",
"{",
"return",
";",
"}",
"}",
"if",
"(",
"self",
"::",
"$",
"outputBuffering",
")",
"{",
"$",
"this",
"->",
"cleanBuffer",
"(",
")",
";",
"}",
"$",
"this",
"->",
"code",
"(",
"$",
"type",
")",
";",
"header",
"(",
"'Location: '",
".",
"$",
"path",
")",
";",
"if",
"(",
"$",
"end",
")",
"{",
"exit",
";",
"}",
"}"
] | Redirect the client
@param String $path
@param Int $type 301 or 302 redirect
@param Bool $end End response | [
"Redirect",
"the",
"client"
] | train | https://github.com/firelit/firelit-framework/blob/308639d40391dd82b45038e35d5e3589d2666886/src/Response.php#L159-L184 |
razielsd/webdriverlib | WebDriver/WebDriver/Server/Selendroid.php | WebDriver_Server_Selendroid.getCommandConfiguration | public function getCommandConfiguration($command)
{
$url = "selendroid/configure/command/{$command}";
$result = $this->driver->curl($this->driver->factoryCommand($url, WebDriver_Command::METHOD_GET));
return isset($result['value']) ? $result['value'] : [];
} | php | public function getCommandConfiguration($command)
{
$url = "selendroid/configure/command/{$command}";
$result = $this->driver->curl($this->driver->factoryCommand($url, WebDriver_Command::METHOD_GET));
return isset($result['value']) ? $result['value'] : [];
} | [
"public",
"function",
"getCommandConfiguration",
"(",
"$",
"command",
")",
"{",
"$",
"url",
"=",
"\"selendroid/configure/command/{$command}\"",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"driver",
"->",
"curl",
"(",
"$",
"this",
"->",
"driver",
"->",
"factoryCommand",
"(",
"$",
"url",
",",
"WebDriver_Command",
"::",
"METHOD_GET",
")",
")",
";",
"return",
"isset",
"(",
"$",
"result",
"[",
"'value'",
"]",
")",
"?",
"$",
"result",
"[",
"'value'",
"]",
":",
"[",
"]",
";",
"}"
] | Gets command configuration.
@param string $command
@return array | [
"Gets",
"command",
"configuration",
"."
] | train | https://github.com/razielsd/webdriverlib/blob/e498afc36a8cdeab5b6ca95016420557baf32f36/WebDriver/WebDriver/Server/Selendroid.php#L49-L54 |
razielsd/webdriverlib | WebDriver/WebDriver/Server/Selendroid.php | WebDriver_Server_Selendroid.setCommandConfiguration | public function setCommandConfiguration($command, array $properties)
{
$url = "selendroid/configure/command/{$command}";
$properties['command'] = $command;
$this->driver->curl($this->driver->factoryCommand($url, WebDriver_Command::METHOD_POST, $properties));
return $this;
} | php | public function setCommandConfiguration($command, array $properties)
{
$url = "selendroid/configure/command/{$command}";
$properties['command'] = $command;
$this->driver->curl($this->driver->factoryCommand($url, WebDriver_Command::METHOD_POST, $properties));
return $this;
} | [
"public",
"function",
"setCommandConfiguration",
"(",
"$",
"command",
",",
"array",
"$",
"properties",
")",
"{",
"$",
"url",
"=",
"\"selendroid/configure/command/{$command}\"",
";",
"$",
"properties",
"[",
"'command'",
"]",
"=",
"$",
"command",
";",
"$",
"this",
"->",
"driver",
"->",
"curl",
"(",
"$",
"this",
"->",
"driver",
"->",
"factoryCommand",
"(",
"$",
"url",
",",
"WebDriver_Command",
"::",
"METHOD_POST",
",",
"$",
"properties",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Sets command configuration.
@param string $command
@param array $properties
@return $this | [
"Sets",
"command",
"configuration",
"."
] | train | https://github.com/razielsd/webdriverlib/blob/e498afc36a8cdeab5b6ca95016420557baf32f36/WebDriver/WebDriver/Server/Selendroid.php#L64-L70 |
wigedev/simple-mvc | src/Utility/Router.php | Router.route | public function route(string $uri, Response $response) : void
{
$this->reroutes ++;
if ($this->reroutes > 10) {
FW()->log->critical('The request for ' . $uri . ' has redirected too many times!');
$response->setStatusCode(508);
return;
}
// Process the URI
$url_array = $this->processURL($uri);
// Extract the ISO locale code from the beginning
$this->extractLocale($url_array, $response);
// Remove the extension from the filename
$filename = array_pop($url_array);
$extension = pathinfo($filename, PATHINFO_EXTENSION);
$filename = pathinfo($filename, PATHINFO_FILENAME);
$url_array[] = $filename;
// Save the resolved path and extension
$this->path = implode('/', $url_array);
FW()->log->debug('Resolved Path: ' . $this->path);
$this->extension = $extension;
// Get the module and action if provided. TODO: This needs a try/catch
$variables = $this->matchRoute($url_array);
$response->resetMCAValues();
if (isset($variables['module'])) {
$response->setModule($variables['module']);
unset($variables['module']);
}
if (isset($variables['controller'])) {
$response->setController($variables['controller']);
unset($variables['controller']);
}
if (isset($variables['action'])) {
$response->setAction($variables['action']);
unset($variables['action']);
}
// Store the variables for retrieval
if (count($variables) > 0) {
$response->setVariables($variables);
}
} | php | public function route(string $uri, Response $response) : void
{
$this->reroutes ++;
if ($this->reroutes > 10) {
FW()->log->critical('The request for ' . $uri . ' has redirected too many times!');
$response->setStatusCode(508);
return;
}
// Process the URI
$url_array = $this->processURL($uri);
// Extract the ISO locale code from the beginning
$this->extractLocale($url_array, $response);
// Remove the extension from the filename
$filename = array_pop($url_array);
$extension = pathinfo($filename, PATHINFO_EXTENSION);
$filename = pathinfo($filename, PATHINFO_FILENAME);
$url_array[] = $filename;
// Save the resolved path and extension
$this->path = implode('/', $url_array);
FW()->log->debug('Resolved Path: ' . $this->path);
$this->extension = $extension;
// Get the module and action if provided. TODO: This needs a try/catch
$variables = $this->matchRoute($url_array);
$response->resetMCAValues();
if (isset($variables['module'])) {
$response->setModule($variables['module']);
unset($variables['module']);
}
if (isset($variables['controller'])) {
$response->setController($variables['controller']);
unset($variables['controller']);
}
if (isset($variables['action'])) {
$response->setAction($variables['action']);
unset($variables['action']);
}
// Store the variables for retrieval
if (count($variables) > 0) {
$response->setVariables($variables);
}
} | [
"public",
"function",
"route",
"(",
"string",
"$",
"uri",
",",
"Response",
"$",
"response",
")",
":",
"void",
"{",
"$",
"this",
"->",
"reroutes",
"++",
";",
"if",
"(",
"$",
"this",
"->",
"reroutes",
">",
"10",
")",
"{",
"FW",
"(",
")",
"->",
"log",
"->",
"critical",
"(",
"'The request for '",
".",
"$",
"uri",
".",
"' has redirected too many times!'",
")",
";",
"$",
"response",
"->",
"setStatusCode",
"(",
"508",
")",
";",
"return",
";",
"}",
"// Process the URI",
"$",
"url_array",
"=",
"$",
"this",
"->",
"processURL",
"(",
"$",
"uri",
")",
";",
"// Extract the ISO locale code from the beginning",
"$",
"this",
"->",
"extractLocale",
"(",
"$",
"url_array",
",",
"$",
"response",
")",
";",
"// Remove the extension from the filename",
"$",
"filename",
"=",
"array_pop",
"(",
"$",
"url_array",
")",
";",
"$",
"extension",
"=",
"pathinfo",
"(",
"$",
"filename",
",",
"PATHINFO_EXTENSION",
")",
";",
"$",
"filename",
"=",
"pathinfo",
"(",
"$",
"filename",
",",
"PATHINFO_FILENAME",
")",
";",
"$",
"url_array",
"[",
"]",
"=",
"$",
"filename",
";",
"// Save the resolved path and extension",
"$",
"this",
"->",
"path",
"=",
"implode",
"(",
"'/'",
",",
"$",
"url_array",
")",
";",
"FW",
"(",
")",
"->",
"log",
"->",
"debug",
"(",
"'Resolved Path: '",
".",
"$",
"this",
"->",
"path",
")",
";",
"$",
"this",
"->",
"extension",
"=",
"$",
"extension",
";",
"// Get the module and action if provided. TODO: This needs a try/catch",
"$",
"variables",
"=",
"$",
"this",
"->",
"matchRoute",
"(",
"$",
"url_array",
")",
";",
"$",
"response",
"->",
"resetMCAValues",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"variables",
"[",
"'module'",
"]",
")",
")",
"{",
"$",
"response",
"->",
"setModule",
"(",
"$",
"variables",
"[",
"'module'",
"]",
")",
";",
"unset",
"(",
"$",
"variables",
"[",
"'module'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"variables",
"[",
"'controller'",
"]",
")",
")",
"{",
"$",
"response",
"->",
"setController",
"(",
"$",
"variables",
"[",
"'controller'",
"]",
")",
";",
"unset",
"(",
"$",
"variables",
"[",
"'controller'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"variables",
"[",
"'action'",
"]",
")",
")",
"{",
"$",
"response",
"->",
"setAction",
"(",
"$",
"variables",
"[",
"'action'",
"]",
")",
";",
"unset",
"(",
"$",
"variables",
"[",
"'action'",
"]",
")",
";",
"}",
"// Store the variables for retrieval",
"if",
"(",
"count",
"(",
"$",
"variables",
")",
">",
"0",
")",
"{",
"$",
"response",
"->",
"setVariables",
"(",
"$",
"variables",
")",
";",
"}",
"}"
] | Do the routing
@param string $uri The request URI
@param Response $response The object managing the response to the request
@throws \Exception | [
"Do",
"the",
"routing"
] | train | https://github.com/wigedev/simple-mvc/blob/b722eff02c5dcd8c6f09c8d78f72bc71cb9e1a94/src/Utility/Router.php#L44-L84 |
wigedev/simple-mvc | src/Utility/Router.php | Router.processURL | protected function processURL(string $url) : array
{
$url = trim($url, '/');
$url_array = explode('/', $url);
return $url_array;
} | php | protected function processURL(string $url) : array
{
$url = trim($url, '/');
$url_array = explode('/', $url);
return $url_array;
} | [
"protected",
"function",
"processURL",
"(",
"string",
"$",
"url",
")",
":",
"array",
"{",
"$",
"url",
"=",
"trim",
"(",
"$",
"url",
",",
"'/'",
")",
";",
"$",
"url_array",
"=",
"explode",
"(",
"'/'",
",",
"$",
"url",
")",
";",
"return",
"$",
"url_array",
";",
"}"
] | Splits the URL into an array
@param string $url The URL to be processed
@return array The pieces of the array | [
"Splits",
"the",
"URL",
"into",
"an",
"array"
] | train | https://github.com/wigedev/simple-mvc/blob/b722eff02c5dcd8c6f09c8d78f72bc71cb9e1a94/src/Utility/Router.php#L111-L116 |
wigedev/simple-mvc | src/Utility/Router.php | Router.extractLocale | protected function extractLocale(array &$url_array, Response $response) : void
{
if (count($url_array) > 0 && preg_match('/^([a-z0-9]{2,3})-([a-z0-9]{4}-?)?([a-z0-9]{2,3})?$/i',
$url_array[0])) {
$response->setLocale(array_shift($url_array));
}
reset($url_array);
} | php | protected function extractLocale(array &$url_array, Response $response) : void
{
if (count($url_array) > 0 && preg_match('/^([a-z0-9]{2,3})-([a-z0-9]{4}-?)?([a-z0-9]{2,3})?$/i',
$url_array[0])) {
$response->setLocale(array_shift($url_array));
}
reset($url_array);
} | [
"protected",
"function",
"extractLocale",
"(",
"array",
"&",
"$",
"url_array",
",",
"Response",
"$",
"response",
")",
":",
"void",
"{",
"if",
"(",
"count",
"(",
"$",
"url_array",
")",
">",
"0",
"&&",
"preg_match",
"(",
"'/^([a-z0-9]{2,3})-([a-z0-9]{4}-?)?([a-z0-9]{2,3})?$/i'",
",",
"$",
"url_array",
"[",
"0",
"]",
")",
")",
"{",
"$",
"response",
"->",
"setLocale",
"(",
"array_shift",
"(",
"$",
"url_array",
")",
")",
";",
"}",
"reset",
"(",
"$",
"url_array",
")",
";",
"}"
] | Remove the locale from the first element in the array if one is set.
@param array $url_array
@param Response $response | [
"Remove",
"the",
"locale",
"from",
"the",
"first",
"element",
"in",
"the",
"array",
"if",
"one",
"is",
"set",
"."
] | train | https://github.com/wigedev/simple-mvc/blob/b722eff02c5dcd8c6f09c8d78f72bc71cb9e1a94/src/Utility/Router.php#L123-L130 |
wigedev/simple-mvc | src/Utility/Router.php | Router.matchRoute | protected function matchRoute(array $url_array) : array
{
// If the routes haven't already been set up, process them.
if (!isset($this->route_definitions)) {
$this->loadRoutes();
}
$url = '/' . implode('/', $url_array);
$matches = $this->doRouteMatching($url);
if (false === $matches) {
throw new \Exception('Unable to route url ' . $url);
}
$route_name = array_shift($matches);
FW()->log->debug('URL matched route ' . $route_name);
$route_config = $this->route_definitions[$route_name];
$return = (isset($route_config['defaults'])) ? $route_config['defaults'] : [];
foreach ($matches as $name => $match) {
if (!is_numeric($name)) { // If the key is a number, it is an artifact of the regex process, ignore it
$return[$name] = $match;
}
}
return $return;
} | php | protected function matchRoute(array $url_array) : array
{
// If the routes haven't already been set up, process them.
if (!isset($this->route_definitions)) {
$this->loadRoutes();
}
$url = '/' . implode('/', $url_array);
$matches = $this->doRouteMatching($url);
if (false === $matches) {
throw new \Exception('Unable to route url ' . $url);
}
$route_name = array_shift($matches);
FW()->log->debug('URL matched route ' . $route_name);
$route_config = $this->route_definitions[$route_name];
$return = (isset($route_config['defaults'])) ? $route_config['defaults'] : [];
foreach ($matches as $name => $match) {
if (!is_numeric($name)) { // If the key is a number, it is an artifact of the regex process, ignore it
$return[$name] = $match;
}
}
return $return;
} | [
"protected",
"function",
"matchRoute",
"(",
"array",
"$",
"url_array",
")",
":",
"array",
"{",
"// If the routes haven't already been set up, process them.",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"route_definitions",
")",
")",
"{",
"$",
"this",
"->",
"loadRoutes",
"(",
")",
";",
"}",
"$",
"url",
"=",
"'/'",
".",
"implode",
"(",
"'/'",
",",
"$",
"url_array",
")",
";",
"$",
"matches",
"=",
"$",
"this",
"->",
"doRouteMatching",
"(",
"$",
"url",
")",
";",
"if",
"(",
"false",
"===",
"$",
"matches",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Unable to route url '",
".",
"$",
"url",
")",
";",
"}",
"$",
"route_name",
"=",
"array_shift",
"(",
"$",
"matches",
")",
";",
"FW",
"(",
")",
"->",
"log",
"->",
"debug",
"(",
"'URL matched route '",
".",
"$",
"route_name",
")",
";",
"$",
"route_config",
"=",
"$",
"this",
"->",
"route_definitions",
"[",
"$",
"route_name",
"]",
";",
"$",
"return",
"=",
"(",
"isset",
"(",
"$",
"route_config",
"[",
"'defaults'",
"]",
")",
")",
"?",
"$",
"route_config",
"[",
"'defaults'",
"]",
":",
"[",
"]",
";",
"foreach",
"(",
"$",
"matches",
"as",
"$",
"name",
"=>",
"$",
"match",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"name",
")",
")",
"{",
"// If the key is a number, it is an artifact of the regex process, ignore it",
"$",
"return",
"[",
"$",
"name",
"]",
"=",
"$",
"match",
";",
"}",
"}",
"return",
"$",
"return",
";",
"}"
] | Take the url pieces and compare them to the routes set in the configuration file to extract variables.
@param string[] $url_array An array of url pieces to be parsed to get the variables.
@return array
@throws \Exception | [
"Take",
"the",
"url",
"pieces",
"and",
"compare",
"them",
"to",
"the",
"routes",
"set",
"in",
"the",
"configuration",
"file",
"to",
"extract",
"variables",
"."
] | train | https://github.com/wigedev/simple-mvc/blob/b722eff02c5dcd8c6f09c8d78f72bc71cb9e1a94/src/Utility/Router.php#L140-L161 |
wigedev/simple-mvc | src/Utility/Router.php | Router.doRouteMatching | protected function doRouteMatching($url)
{
$matches = array();
foreach ($this->route_definitions as $name => $route) {
if (preg_match($route['regex'], $url, $matches)) {
$matches[0] = $name;
return $matches;
}
}
return false;
} | php | protected function doRouteMatching($url)
{
$matches = array();
foreach ($this->route_definitions as $name => $route) {
if (preg_match($route['regex'], $url, $matches)) {
$matches[0] = $name;
return $matches;
}
}
return false;
} | [
"protected",
"function",
"doRouteMatching",
"(",
"$",
"url",
")",
"{",
"$",
"matches",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"route_definitions",
"as",
"$",
"name",
"=>",
"$",
"route",
")",
"{",
"if",
"(",
"preg_match",
"(",
"$",
"route",
"[",
"'regex'",
"]",
",",
"$",
"url",
",",
"$",
"matches",
")",
")",
"{",
"$",
"matches",
"[",
"0",
"]",
"=",
"$",
"name",
";",
"return",
"$",
"matches",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Processs the url.
@param string $url The url to match
@return array|bool | [
"Processs",
"the",
"url",
"."
] | train | https://github.com/wigedev/simple-mvc/blob/b722eff02c5dcd8c6f09c8d78f72bc71cb9e1a94/src/Utility/Router.php#L170-L180 |
wigedev/simple-mvc | src/Utility/Router.php | Router.loadRoutes | protected function loadRoutes() : void
{
$routeConfig = Core::i()->config->getConfiguration('routes');
// If there is a default route, make it last in the array
if (isset($routeConfig['default'])) {
$default_route = $routeConfig['default'];
unset($routeConfig['default']);
$routeConfig['default'] = $default_route;
}
// Parse the routes and build the regex strings
foreach ($routeConfig as $route_name => $route) {
$regex = $route['route'];
$regex = str_replace('/', '\/', $regex);
$regex = str_replace('[', '(', $regex);
$regex = str_replace(']', ')?', $regex);
if (isset($route['constraints'])) {
foreach ($route['constraints'] as $key => $constraint) {
$regex = str_replace(':' . $key . ':', "(?P<{$key}>" . $constraint . ')', $regex);
}
}
$routeConfig[$route_name]['regex'] = '/^' . $regex . '$/i';
}
$this->route_definitions = $routeConfig;
} | php | protected function loadRoutes() : void
{
$routeConfig = Core::i()->config->getConfiguration('routes');
// If there is a default route, make it last in the array
if (isset($routeConfig['default'])) {
$default_route = $routeConfig['default'];
unset($routeConfig['default']);
$routeConfig['default'] = $default_route;
}
// Parse the routes and build the regex strings
foreach ($routeConfig as $route_name => $route) {
$regex = $route['route'];
$regex = str_replace('/', '\/', $regex);
$regex = str_replace('[', '(', $regex);
$regex = str_replace(']', ')?', $regex);
if (isset($route['constraints'])) {
foreach ($route['constraints'] as $key => $constraint) {
$regex = str_replace(':' . $key . ':', "(?P<{$key}>" . $constraint . ')', $regex);
}
}
$routeConfig[$route_name]['regex'] = '/^' . $regex . '$/i';
}
$this->route_definitions = $routeConfig;
} | [
"protected",
"function",
"loadRoutes",
"(",
")",
":",
"void",
"{",
"$",
"routeConfig",
"=",
"Core",
"::",
"i",
"(",
")",
"->",
"config",
"->",
"getConfiguration",
"(",
"'routes'",
")",
";",
"// If there is a default route, make it last in the array",
"if",
"(",
"isset",
"(",
"$",
"routeConfig",
"[",
"'default'",
"]",
")",
")",
"{",
"$",
"default_route",
"=",
"$",
"routeConfig",
"[",
"'default'",
"]",
";",
"unset",
"(",
"$",
"routeConfig",
"[",
"'default'",
"]",
")",
";",
"$",
"routeConfig",
"[",
"'default'",
"]",
"=",
"$",
"default_route",
";",
"}",
"// Parse the routes and build the regex strings",
"foreach",
"(",
"$",
"routeConfig",
"as",
"$",
"route_name",
"=>",
"$",
"route",
")",
"{",
"$",
"regex",
"=",
"$",
"route",
"[",
"'route'",
"]",
";",
"$",
"regex",
"=",
"str_replace",
"(",
"'/'",
",",
"'\\/'",
",",
"$",
"regex",
")",
";",
"$",
"regex",
"=",
"str_replace",
"(",
"'['",
",",
"'('",
",",
"$",
"regex",
")",
";",
"$",
"regex",
"=",
"str_replace",
"(",
"']'",
",",
"')?'",
",",
"$",
"regex",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"route",
"[",
"'constraints'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"route",
"[",
"'constraints'",
"]",
"as",
"$",
"key",
"=>",
"$",
"constraint",
")",
"{",
"$",
"regex",
"=",
"str_replace",
"(",
"':'",
".",
"$",
"key",
".",
"':'",
",",
"\"(?P<{$key}>\"",
".",
"$",
"constraint",
".",
"')'",
",",
"$",
"regex",
")",
";",
"}",
"}",
"$",
"routeConfig",
"[",
"$",
"route_name",
"]",
"[",
"'regex'",
"]",
"=",
"'/^'",
".",
"$",
"regex",
".",
"'$/i'",
";",
"}",
"$",
"this",
"->",
"route_definitions",
"=",
"$",
"routeConfig",
";",
"}"
] | Load the routes from the configuration | [
"Load",
"the",
"routes",
"from",
"the",
"configuration"
] | train | https://github.com/wigedev/simple-mvc/blob/b722eff02c5dcd8c6f09c8d78f72bc71cb9e1a94/src/Utility/Router.php#L185-L208 |
lbmzorx/yii2-components | src/action/MutiCreateAction.php | MutiCreateAction.run | public function run()
{
/* @var $model \yii\db\ActiveRecord */
$model = new $this->modelClass;
$depances=$this->newDepance();
$model->setScenario( $this->scenario );
$request=yii::$app->getRequest();
if ($request->getIsPost()) {
$depances['model']=$model;
if($this->transation){
/**
* @var $t \yii\db\Transaction
*/
$t=($this->modelClass)::getDb()->beginTransaction();
}
$status=$this->save($depances);
if ($status == true) {
if($this->transation){
$t->commit();
}
yii::$app->getSession()->setFlash('success', yii::t('app', 'Created Success'));
if($request->isAjax){
return ['status'=>true,'msg'=>yii::t('app','Created Success')];
}else{
return $this->controller->redirect([$this->indexView]);
}
} else {
if($this->transation){
$t->rollBack();
}
if($request->isAjax){
return ['status'=>false,'msg'=>yii::$app->getSession()->getFlash('error')];
}
return $status;
}
}
$model->loadDefaultValues();
$data = [
'model' => $model,
];
if($depances){
foreach ($depances as $name=>$depance){
$data[$name]=$depance;
}
}
if( is_array($this->data) ){
$data = array_merge($data, $this->data);
}elseif ($this->data instanceof \Closure){
$data = call_user_func_array($this->data, [$model, $this]);
}
$this->viewFile === null && $this->viewFile = $this->id;
return $this->controller->render($this->viewFile, $data);
} | php | public function run()
{
/* @var $model \yii\db\ActiveRecord */
$model = new $this->modelClass;
$depances=$this->newDepance();
$model->setScenario( $this->scenario );
$request=yii::$app->getRequest();
if ($request->getIsPost()) {
$depances['model']=$model;
if($this->transation){
/**
* @var $t \yii\db\Transaction
*/
$t=($this->modelClass)::getDb()->beginTransaction();
}
$status=$this->save($depances);
if ($status == true) {
if($this->transation){
$t->commit();
}
yii::$app->getSession()->setFlash('success', yii::t('app', 'Created Success'));
if($request->isAjax){
return ['status'=>true,'msg'=>yii::t('app','Created Success')];
}else{
return $this->controller->redirect([$this->indexView]);
}
} else {
if($this->transation){
$t->rollBack();
}
if($request->isAjax){
return ['status'=>false,'msg'=>yii::$app->getSession()->getFlash('error')];
}
return $status;
}
}
$model->loadDefaultValues();
$data = [
'model' => $model,
];
if($depances){
foreach ($depances as $name=>$depance){
$data[$name]=$depance;
}
}
if( is_array($this->data) ){
$data = array_merge($data, $this->data);
}elseif ($this->data instanceof \Closure){
$data = call_user_func_array($this->data, [$model, $this]);
}
$this->viewFile === null && $this->viewFile = $this->id;
return $this->controller->render($this->viewFile, $data);
} | [
"public",
"function",
"run",
"(",
")",
"{",
"/* @var $model \\yii\\db\\ActiveRecord */",
"$",
"model",
"=",
"new",
"$",
"this",
"->",
"modelClass",
";",
"$",
"depances",
"=",
"$",
"this",
"->",
"newDepance",
"(",
")",
";",
"$",
"model",
"->",
"setScenario",
"(",
"$",
"this",
"->",
"scenario",
")",
";",
"$",
"request",
"=",
"yii",
"::",
"$",
"app",
"->",
"getRequest",
"(",
")",
";",
"if",
"(",
"$",
"request",
"->",
"getIsPost",
"(",
")",
")",
"{",
"$",
"depances",
"[",
"'model'",
"]",
"=",
"$",
"model",
";",
"if",
"(",
"$",
"this",
"->",
"transation",
")",
"{",
"/**\n * @var $t \\yii\\db\\Transaction\n */",
"$",
"t",
"=",
"(",
"$",
"this",
"->",
"modelClass",
")",
"::",
"getDb",
"(",
")",
"->",
"beginTransaction",
"(",
")",
";",
"}",
"$",
"status",
"=",
"$",
"this",
"->",
"save",
"(",
"$",
"depances",
")",
";",
"if",
"(",
"$",
"status",
"==",
"true",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"transation",
")",
"{",
"$",
"t",
"->",
"commit",
"(",
")",
";",
"}",
"yii",
"::",
"$",
"app",
"->",
"getSession",
"(",
")",
"->",
"setFlash",
"(",
"'success'",
",",
"yii",
"::",
"t",
"(",
"'app'",
",",
"'Created Success'",
")",
")",
";",
"if",
"(",
"$",
"request",
"->",
"isAjax",
")",
"{",
"return",
"[",
"'status'",
"=>",
"true",
",",
"'msg'",
"=>",
"yii",
"::",
"t",
"(",
"'app'",
",",
"'Created Success'",
")",
"]",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"controller",
"->",
"redirect",
"(",
"[",
"$",
"this",
"->",
"indexView",
"]",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"this",
"->",
"transation",
")",
"{",
"$",
"t",
"->",
"rollBack",
"(",
")",
";",
"}",
"if",
"(",
"$",
"request",
"->",
"isAjax",
")",
"{",
"return",
"[",
"'status'",
"=>",
"false",
",",
"'msg'",
"=>",
"yii",
"::",
"$",
"app",
"->",
"getSession",
"(",
")",
"->",
"getFlash",
"(",
"'error'",
")",
"]",
";",
"}",
"return",
"$",
"status",
";",
"}",
"}",
"$",
"model",
"->",
"loadDefaultValues",
"(",
")",
";",
"$",
"data",
"=",
"[",
"'model'",
"=>",
"$",
"model",
",",
"]",
";",
"if",
"(",
"$",
"depances",
")",
"{",
"foreach",
"(",
"$",
"depances",
"as",
"$",
"name",
"=>",
"$",
"depance",
")",
"{",
"$",
"data",
"[",
"$",
"name",
"]",
"=",
"$",
"depance",
";",
"}",
"}",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"data",
")",
")",
"{",
"$",
"data",
"=",
"array_merge",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"data",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"data",
"instanceof",
"\\",
"Closure",
")",
"{",
"$",
"data",
"=",
"call_user_func_array",
"(",
"$",
"this",
"->",
"data",
",",
"[",
"$",
"model",
",",
"$",
"this",
"]",
")",
";",
"}",
"$",
"this",
"->",
"viewFile",
"===",
"null",
"&&",
"$",
"this",
"->",
"viewFile",
"=",
"$",
"this",
"->",
"id",
";",
"return",
"$",
"this",
"->",
"controller",
"->",
"render",
"(",
"$",
"this",
"->",
"viewFile",
",",
"$",
"data",
")",
";",
"}"
] | create创建页
@return array|string | [
"create创建页"
] | train | https://github.com/lbmzorx/yii2-components/blob/0d5344fbaf07ee979942414d2874696273ce7bdd/src/action/MutiCreateAction.php#L46-L103 |
lbmzorx/yii2-components | src/action/MutiCreateAction.php | MutiCreateAction.loadCondition | protected function loadCondition($name,$models){
if(isset($this->_condition[$name]) && !empty($this->_condition[$name])){
$data=[];
foreach ($this->_condition[$name] as $attribute=>$v){
if(preg_match('/{(?P<model>\w+):(?P<attribute>\w+)}/',$v,$match)){
if(isset($models[$match['model']])){
if(isset($models[$match['model']]->{$match['attribute']})){
$data[$attribute]=$models[$match['model']]->{$match['attribute']};
}
}
}
}
if(!empty($data)){
return $data;
}
}
return false;
} | php | protected function loadCondition($name,$models){
if(isset($this->_condition[$name]) && !empty($this->_condition[$name])){
$data=[];
foreach ($this->_condition[$name] as $attribute=>$v){
if(preg_match('/{(?P<model>\w+):(?P<attribute>\w+)}/',$v,$match)){
if(isset($models[$match['model']])){
if(isset($models[$match['model']]->{$match['attribute']})){
$data[$attribute]=$models[$match['model']]->{$match['attribute']};
}
}
}
}
if(!empty($data)){
return $data;
}
}
return false;
} | [
"protected",
"function",
"loadCondition",
"(",
"$",
"name",
",",
"$",
"models",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_condition",
"[",
"$",
"name",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"_condition",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"data",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"_condition",
"[",
"$",
"name",
"]",
"as",
"$",
"attribute",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/{(?P<model>\\w+):(?P<attribute>\\w+)}/'",
",",
"$",
"v",
",",
"$",
"match",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"models",
"[",
"$",
"match",
"[",
"'model'",
"]",
"]",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"models",
"[",
"$",
"match",
"[",
"'model'",
"]",
"]",
"->",
"{",
"$",
"match",
"[",
"'attribute'",
"]",
"}",
")",
")",
"{",
"$",
"data",
"[",
"$",
"attribute",
"]",
"=",
"$",
"models",
"[",
"$",
"match",
"[",
"'model'",
"]",
"]",
"->",
"{",
"$",
"match",
"[",
"'attribute'",
"]",
"}",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"return",
"$",
"data",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | 解析条件
@param $name
@param $models
@return array|bool | [
"解析条件"
] | train | https://github.com/lbmzorx/yii2-components/blob/0d5344fbaf07ee979942414d2874696273ce7bdd/src/action/MutiCreateAction.php#L141-L158 |
lbmzorx/yii2-components | src/action/MutiCreateAction.php | MutiCreateAction.analysisLinkStack | protected function analysisLinkStack($condition,$name){
foreach ($condition as $k=>$v){
if(preg_match('/{(?P<model>\w+):(?P<attribute>\w+)}/',$k,$match)){
$this->orderStack($match['model'],$name);
$this->_condition[$name][$v]=$k;
}
if(preg_match('/{(?P<model>\w+):(?P<attribute>\w+)}/',$v,$match)){
$this->orderStack($name,$match['model']);
$this->_condition[$match['model']][$match['attribute']]='{'.$name.':'.$k.'}';
}
}
} | php | protected function analysisLinkStack($condition,$name){
foreach ($condition as $k=>$v){
if(preg_match('/{(?P<model>\w+):(?P<attribute>\w+)}/',$k,$match)){
$this->orderStack($match['model'],$name);
$this->_condition[$name][$v]=$k;
}
if(preg_match('/{(?P<model>\w+):(?P<attribute>\w+)}/',$v,$match)){
$this->orderStack($name,$match['model']);
$this->_condition[$match['model']][$match['attribute']]='{'.$name.':'.$k.'}';
}
}
} | [
"protected",
"function",
"analysisLinkStack",
"(",
"$",
"condition",
",",
"$",
"name",
")",
"{",
"foreach",
"(",
"$",
"condition",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/{(?P<model>\\w+):(?P<attribute>\\w+)}/'",
",",
"$",
"k",
",",
"$",
"match",
")",
")",
"{",
"$",
"this",
"->",
"orderStack",
"(",
"$",
"match",
"[",
"'model'",
"]",
",",
"$",
"name",
")",
";",
"$",
"this",
"->",
"_condition",
"[",
"$",
"name",
"]",
"[",
"$",
"v",
"]",
"=",
"$",
"k",
";",
"}",
"if",
"(",
"preg_match",
"(",
"'/{(?P<model>\\w+):(?P<attribute>\\w+)}/'",
",",
"$",
"v",
",",
"$",
"match",
")",
")",
"{",
"$",
"this",
"->",
"orderStack",
"(",
"$",
"name",
",",
"$",
"match",
"[",
"'model'",
"]",
")",
";",
"$",
"this",
"->",
"_condition",
"[",
"$",
"match",
"[",
"'model'",
"]",
"]",
"[",
"$",
"match",
"[",
"'attribute'",
"]",
"]",
"=",
"'{'",
".",
"$",
"name",
".",
"':'",
".",
"$",
"k",
".",
"'}'",
";",
"}",
"}",
"}"
] | 解析模型依赖关系 | [
"解析模型依赖关系"
] | train | https://github.com/lbmzorx/yii2-components/blob/0d5344fbaf07ee979942414d2874696273ce7bdd/src/action/MutiCreateAction.php#L164-L175 |
lbmzorx/yii2-components | src/action/MutiCreateAction.php | MutiCreateAction.orderStack | protected function orderStack($model,$name){
$inModel=in_array($model,$this->_linkStack);
$inName=in_array($name,$this->_linkStack);
if( $inModel&&$inName){
$flip=array_flip($this->_linkStack);
if($flip[$model]>$flip[$name]){ //
unset($this->_linkStack[$flip[$model]]);
array_splice($this->_linkStack,$flip[$name],0,$model);
}
}elseif( $inModel &&(!$inName) ){
$this->_linkStack[]=$name;
}else if( !$inModel&&$inName ){
$flip=array_flip($this->_linkStack);
array_splice($this->_linkStack,$flip[$name],0,$model);
}else{
$this->_linkStack[]=$model;
$this->_linkStack[]=$name;
}
} | php | protected function orderStack($model,$name){
$inModel=in_array($model,$this->_linkStack);
$inName=in_array($name,$this->_linkStack);
if( $inModel&&$inName){
$flip=array_flip($this->_linkStack);
if($flip[$model]>$flip[$name]){ //
unset($this->_linkStack[$flip[$model]]);
array_splice($this->_linkStack,$flip[$name],0,$model);
}
}elseif( $inModel &&(!$inName) ){
$this->_linkStack[]=$name;
}else if( !$inModel&&$inName ){
$flip=array_flip($this->_linkStack);
array_splice($this->_linkStack,$flip[$name],0,$model);
}else{
$this->_linkStack[]=$model;
$this->_linkStack[]=$name;
}
} | [
"protected",
"function",
"orderStack",
"(",
"$",
"model",
",",
"$",
"name",
")",
"{",
"$",
"inModel",
"=",
"in_array",
"(",
"$",
"model",
",",
"$",
"this",
"->",
"_linkStack",
")",
";",
"$",
"inName",
"=",
"in_array",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"_linkStack",
")",
";",
"if",
"(",
"$",
"inModel",
"&&",
"$",
"inName",
")",
"{",
"$",
"flip",
"=",
"array_flip",
"(",
"$",
"this",
"->",
"_linkStack",
")",
";",
"if",
"(",
"$",
"flip",
"[",
"$",
"model",
"]",
">",
"$",
"flip",
"[",
"$",
"name",
"]",
")",
"{",
"//",
"unset",
"(",
"$",
"this",
"->",
"_linkStack",
"[",
"$",
"flip",
"[",
"$",
"model",
"]",
"]",
")",
";",
"array_splice",
"(",
"$",
"this",
"->",
"_linkStack",
",",
"$",
"flip",
"[",
"$",
"name",
"]",
",",
"0",
",",
"$",
"model",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"inModel",
"&&",
"(",
"!",
"$",
"inName",
")",
")",
"{",
"$",
"this",
"->",
"_linkStack",
"[",
"]",
"=",
"$",
"name",
";",
"}",
"else",
"if",
"(",
"!",
"$",
"inModel",
"&&",
"$",
"inName",
")",
"{",
"$",
"flip",
"=",
"array_flip",
"(",
"$",
"this",
"->",
"_linkStack",
")",
";",
"array_splice",
"(",
"$",
"this",
"->",
"_linkStack",
",",
"$",
"flip",
"[",
"$",
"name",
"]",
",",
"0",
",",
"$",
"model",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_linkStack",
"[",
"]",
"=",
"$",
"model",
";",
"$",
"this",
"->",
"_linkStack",
"[",
"]",
"=",
"$",
"name",
";",
"}",
"}"
] | 插入模型正确的位置
@param $model
@param $name | [
"插入模型正确的位置"
] | train | https://github.com/lbmzorx/yii2-components/blob/0d5344fbaf07ee979942414d2874696273ce7bdd/src/action/MutiCreateAction.php#L182-L200 |
lbmzorx/yii2-components | src/action/MutiCreateAction.php | MutiCreateAction.newDepance | protected function newDepance(){
if(is_array($this->depandeClass) && !empty($this->depandeClass)){
if(!isset($this->depandeClass['class'])){
$depanceModels=[];
foreach ($this->depandeClass as $key=>$depance){
$name=StringHelper::basename($depance['class']);
/**
* @var \yii\db\ActiveRecord $depanceModels
*/
$depanceModels[$name]=Yii::createObject($depance['class']);
if(isset($depance['scenario'])){
$depanceModels[$name]->setScenario($depance['scenario']);
}
if(isset($depance['condition'])){
$this->analysisLinkStack($depance['condition'],$name);
}
}
}else{
$name=StringHelper::basename($this->depandeClass['class']);
/**
* @var \yii\db\ActiveRecord $depanceModels
*/
$depanceModels[$name]=Yii::createObject($this->depandeClass['class']);
if(isset($this->depandeClass['scenario'])){
$depanceModels[$name]->setScenario($this->depandeClass['scenario']);
}
if(isset($this->depandeClass['condition'])){
$this->analysisLinkStack($this->depandeClass['condition'],$name);
}
}
if(!empty($depanceModels)){
return $depanceModels;
}
}
return false;
} | php | protected function newDepance(){
if(is_array($this->depandeClass) && !empty($this->depandeClass)){
if(!isset($this->depandeClass['class'])){
$depanceModels=[];
foreach ($this->depandeClass as $key=>$depance){
$name=StringHelper::basename($depance['class']);
/**
* @var \yii\db\ActiveRecord $depanceModels
*/
$depanceModels[$name]=Yii::createObject($depance['class']);
if(isset($depance['scenario'])){
$depanceModels[$name]->setScenario($depance['scenario']);
}
if(isset($depance['condition'])){
$this->analysisLinkStack($depance['condition'],$name);
}
}
}else{
$name=StringHelper::basename($this->depandeClass['class']);
/**
* @var \yii\db\ActiveRecord $depanceModels
*/
$depanceModels[$name]=Yii::createObject($this->depandeClass['class']);
if(isset($this->depandeClass['scenario'])){
$depanceModels[$name]->setScenario($this->depandeClass['scenario']);
}
if(isset($this->depandeClass['condition'])){
$this->analysisLinkStack($this->depandeClass['condition'],$name);
}
}
if(!empty($depanceModels)){
return $depanceModels;
}
}
return false;
} | [
"protected",
"function",
"newDepance",
"(",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"depandeClass",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"depandeClass",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"depandeClass",
"[",
"'class'",
"]",
")",
")",
"{",
"$",
"depanceModels",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"depandeClass",
"as",
"$",
"key",
"=>",
"$",
"depance",
")",
"{",
"$",
"name",
"=",
"StringHelper",
"::",
"basename",
"(",
"$",
"depance",
"[",
"'class'",
"]",
")",
";",
"/**\n * @var \\yii\\db\\ActiveRecord $depanceModels\n */",
"$",
"depanceModels",
"[",
"$",
"name",
"]",
"=",
"Yii",
"::",
"createObject",
"(",
"$",
"depance",
"[",
"'class'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"depance",
"[",
"'scenario'",
"]",
")",
")",
"{",
"$",
"depanceModels",
"[",
"$",
"name",
"]",
"->",
"setScenario",
"(",
"$",
"depance",
"[",
"'scenario'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"depance",
"[",
"'condition'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"analysisLinkStack",
"(",
"$",
"depance",
"[",
"'condition'",
"]",
",",
"$",
"name",
")",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"name",
"=",
"StringHelper",
"::",
"basename",
"(",
"$",
"this",
"->",
"depandeClass",
"[",
"'class'",
"]",
")",
";",
"/**\n * @var \\yii\\db\\ActiveRecord $depanceModels\n */",
"$",
"depanceModels",
"[",
"$",
"name",
"]",
"=",
"Yii",
"::",
"createObject",
"(",
"$",
"this",
"->",
"depandeClass",
"[",
"'class'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"depandeClass",
"[",
"'scenario'",
"]",
")",
")",
"{",
"$",
"depanceModels",
"[",
"$",
"name",
"]",
"->",
"setScenario",
"(",
"$",
"this",
"->",
"depandeClass",
"[",
"'scenario'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"depandeClass",
"[",
"'condition'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"analysisLinkStack",
"(",
"$",
"this",
"->",
"depandeClass",
"[",
"'condition'",
"]",
",",
"$",
"name",
")",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"depanceModels",
")",
")",
"{",
"return",
"$",
"depanceModels",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | new depance model
@return array|bool|Yii\db\ActiveRecord | [
"new",
"depance",
"model"
] | train | https://github.com/lbmzorx/yii2-components/blob/0d5344fbaf07ee979942414d2874696273ce7bdd/src/action/MutiCreateAction.php#L208-L245 |
Silvestra/Silvestra | src/Silvestra/Component/Banner/Form/Type/BannerType.php | BannerType.buildForm | public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add(
'title',
'text',
array(
'label' => 'form.banner.title',
'required' => false,
'constraints' => array(new Assert\NotBlank(), new Assert\Length(array('min' => 3, 'max' => 255)))
)
);
$builder->add(
'description',
'textarea',
array(
'label' => 'form.banner.description',
'required' => false,
)
);
$builder->add(
'lang',
'choice',
array(
'label' => 'form.banner.language',
'choices' => $this->localeHelper->getDisplayLocales(),
)
);
$builder->add(
'uri',
'text',
array(
'label' => 'form.banner.uri',
'required' => false,
'constraints' => array(new Assert\NotBlank(), new Assert\Length(array('max' => 511)), new Assert\Url())
)
);
$builder->add(
'position',
'integer',
array(
'label' => 'form.banner.position',
'required' => false,
'constraints' => array(new Assert\NotBlank())
)
);
$builder->add(
'blank',
'checkbox',
array(
'label' => 'form.banner.blank',
'required' => false,
)
);
$builder->add(
'publish',
'checkbox',
array(
'label' => 'form.banner.publish',
'required' => false,
)
);
$builder->add(
'publishFrom',
'date',
array(
'label' => 'form.banner.publish_from',
'required' => false,
)
);
$builder->add(
'publishTo',
'date',
array(
'label' => 'form.banner.publish_to',
'required' => false,
)
);
$builder->add(
'image',
'silvestra_media_image',
array(
'required' => false,
)
);
$builder->add(
'script',
'textarea',
array(
'label' => 'form.banner.script',
'required' => false,
)
);
$builder->add('submit', 'submit', array('label' => 'form.button.save'));
} | php | public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add(
'title',
'text',
array(
'label' => 'form.banner.title',
'required' => false,
'constraints' => array(new Assert\NotBlank(), new Assert\Length(array('min' => 3, 'max' => 255)))
)
);
$builder->add(
'description',
'textarea',
array(
'label' => 'form.banner.description',
'required' => false,
)
);
$builder->add(
'lang',
'choice',
array(
'label' => 'form.banner.language',
'choices' => $this->localeHelper->getDisplayLocales(),
)
);
$builder->add(
'uri',
'text',
array(
'label' => 'form.banner.uri',
'required' => false,
'constraints' => array(new Assert\NotBlank(), new Assert\Length(array('max' => 511)), new Assert\Url())
)
);
$builder->add(
'position',
'integer',
array(
'label' => 'form.banner.position',
'required' => false,
'constraints' => array(new Assert\NotBlank())
)
);
$builder->add(
'blank',
'checkbox',
array(
'label' => 'form.banner.blank',
'required' => false,
)
);
$builder->add(
'publish',
'checkbox',
array(
'label' => 'form.banner.publish',
'required' => false,
)
);
$builder->add(
'publishFrom',
'date',
array(
'label' => 'form.banner.publish_from',
'required' => false,
)
);
$builder->add(
'publishTo',
'date',
array(
'label' => 'form.banner.publish_to',
'required' => false,
)
);
$builder->add(
'image',
'silvestra_media_image',
array(
'required' => false,
)
);
$builder->add(
'script',
'textarea',
array(
'label' => 'form.banner.script',
'required' => false,
)
);
$builder->add('submit', 'submit', array('label' => 'form.button.save'));
} | [
"public",
"function",
"buildForm",
"(",
"FormBuilderInterface",
"$",
"builder",
",",
"array",
"$",
"options",
")",
"{",
"$",
"builder",
"->",
"add",
"(",
"'title'",
",",
"'text'",
",",
"array",
"(",
"'label'",
"=>",
"'form.banner.title'",
",",
"'required'",
"=>",
"false",
",",
"'constraints'",
"=>",
"array",
"(",
"new",
"Assert",
"\\",
"NotBlank",
"(",
")",
",",
"new",
"Assert",
"\\",
"Length",
"(",
"array",
"(",
"'min'",
"=>",
"3",
",",
"'max'",
"=>",
"255",
")",
")",
")",
")",
")",
";",
"$",
"builder",
"->",
"add",
"(",
"'description'",
",",
"'textarea'",
",",
"array",
"(",
"'label'",
"=>",
"'form.banner.description'",
",",
"'required'",
"=>",
"false",
",",
")",
")",
";",
"$",
"builder",
"->",
"add",
"(",
"'lang'",
",",
"'choice'",
",",
"array",
"(",
"'label'",
"=>",
"'form.banner.language'",
",",
"'choices'",
"=>",
"$",
"this",
"->",
"localeHelper",
"->",
"getDisplayLocales",
"(",
")",
",",
")",
")",
";",
"$",
"builder",
"->",
"add",
"(",
"'uri'",
",",
"'text'",
",",
"array",
"(",
"'label'",
"=>",
"'form.banner.uri'",
",",
"'required'",
"=>",
"false",
",",
"'constraints'",
"=>",
"array",
"(",
"new",
"Assert",
"\\",
"NotBlank",
"(",
")",
",",
"new",
"Assert",
"\\",
"Length",
"(",
"array",
"(",
"'max'",
"=>",
"511",
")",
")",
",",
"new",
"Assert",
"\\",
"Url",
"(",
")",
")",
")",
")",
";",
"$",
"builder",
"->",
"add",
"(",
"'position'",
",",
"'integer'",
",",
"array",
"(",
"'label'",
"=>",
"'form.banner.position'",
",",
"'required'",
"=>",
"false",
",",
"'constraints'",
"=>",
"array",
"(",
"new",
"Assert",
"\\",
"NotBlank",
"(",
")",
")",
")",
")",
";",
"$",
"builder",
"->",
"add",
"(",
"'blank'",
",",
"'checkbox'",
",",
"array",
"(",
"'label'",
"=>",
"'form.banner.blank'",
",",
"'required'",
"=>",
"false",
",",
")",
")",
";",
"$",
"builder",
"->",
"add",
"(",
"'publish'",
",",
"'checkbox'",
",",
"array",
"(",
"'label'",
"=>",
"'form.banner.publish'",
",",
"'required'",
"=>",
"false",
",",
")",
")",
";",
"$",
"builder",
"->",
"add",
"(",
"'publishFrom'",
",",
"'date'",
",",
"array",
"(",
"'label'",
"=>",
"'form.banner.publish_from'",
",",
"'required'",
"=>",
"false",
",",
")",
")",
";",
"$",
"builder",
"->",
"add",
"(",
"'publishTo'",
",",
"'date'",
",",
"array",
"(",
"'label'",
"=>",
"'form.banner.publish_to'",
",",
"'required'",
"=>",
"false",
",",
")",
")",
";",
"$",
"builder",
"->",
"add",
"(",
"'image'",
",",
"'silvestra_media_image'",
",",
"array",
"(",
"'required'",
"=>",
"false",
",",
")",
")",
";",
"$",
"builder",
"->",
"add",
"(",
"'script'",
",",
"'textarea'",
",",
"array",
"(",
"'label'",
"=>",
"'form.banner.script'",
",",
"'required'",
"=>",
"false",
",",
")",
")",
";",
"$",
"builder",
"->",
"add",
"(",
"'submit'",
",",
"'submit'",
",",
"array",
"(",
"'label'",
"=>",
"'form.button.save'",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/Silvestra/Silvestra/blob/b7367601b01495ae3c492b42042f804dee13ab06/src/Silvestra/Component/Banner/Form/Type/BannerType.php#L52-L156 |
parfumix/laravel-translator | src/Drivers/Database.php | Database.setTranslations | protected function setTranslations() {
if( $this->getAttribute('cache_time') ) {
$translations = Cache::remember('users', $this->getAttribute('cache_time'), function() {
$translations = $this->getRepository()
->allTranslations()
->toArray();
return $this->prepareTranslations(
$translations
);
});
} else {
$translations = $this->getRepository()
->allTranslations()
->toArray();
$translations = $this->prepareTranslations(
$translations
);
}
$this->translations = $translations;
return $this;
} | php | protected function setTranslations() {
if( $this->getAttribute('cache_time') ) {
$translations = Cache::remember('users', $this->getAttribute('cache_time'), function() {
$translations = $this->getRepository()
->allTranslations()
->toArray();
return $this->prepareTranslations(
$translations
);
});
} else {
$translations = $this->getRepository()
->allTranslations()
->toArray();
$translations = $this->prepareTranslations(
$translations
);
}
$this->translations = $translations;
return $this;
} | [
"protected",
"function",
"setTranslations",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getAttribute",
"(",
"'cache_time'",
")",
")",
"{",
"$",
"translations",
"=",
"Cache",
"::",
"remember",
"(",
"'users'",
",",
"$",
"this",
"->",
"getAttribute",
"(",
"'cache_time'",
")",
",",
"function",
"(",
")",
"{",
"$",
"translations",
"=",
"$",
"this",
"->",
"getRepository",
"(",
")",
"->",
"allTranslations",
"(",
")",
"->",
"toArray",
"(",
")",
";",
"return",
"$",
"this",
"->",
"prepareTranslations",
"(",
"$",
"translations",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"$",
"translations",
"=",
"$",
"this",
"->",
"getRepository",
"(",
")",
"->",
"allTranslations",
"(",
")",
"->",
"toArray",
"(",
")",
";",
"$",
"translations",
"=",
"$",
"this",
"->",
"prepareTranslations",
"(",
"$",
"translations",
")",
";",
"}",
"$",
"this",
"->",
"translations",
"=",
"$",
"translations",
";",
"return",
"$",
"this",
";",
"}"
] | Set translations .
@return $this | [
"Set",
"translations",
"."
] | train | https://github.com/parfumix/laravel-translator/blob/b85f17cbfebd4f35d1bfb817fbf13bff2c3f487e/src/Drivers/Database.php#L64-L88 |
parfumix/laravel-translator | src/Drivers/Database.php | Database.prepareTranslations | protected function prepareTranslations($translations) {
$return = [];
foreach($translations as $translation)
$return[$translation['locale']][!is_null($translation['group']) ? $translation['group']. '.' . $translation['key'] : ''. $translation['key']] = $translation['value'];
return $return;
} | php | protected function prepareTranslations($translations) {
$return = [];
foreach($translations as $translation)
$return[$translation['locale']][!is_null($translation['group']) ? $translation['group']. '.' . $translation['key'] : ''. $translation['key']] = $translation['value'];
return $return;
} | [
"protected",
"function",
"prepareTranslations",
"(",
"$",
"translations",
")",
"{",
"$",
"return",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"translations",
"as",
"$",
"translation",
")",
"$",
"return",
"[",
"$",
"translation",
"[",
"'locale'",
"]",
"]",
"[",
"!",
"is_null",
"(",
"$",
"translation",
"[",
"'group'",
"]",
")",
"?",
"$",
"translation",
"[",
"'group'",
"]",
".",
"'.'",
".",
"$",
"translation",
"[",
"'key'",
"]",
":",
"''",
".",
"$",
"translation",
"[",
"'key'",
"]",
"]",
"=",
"$",
"translation",
"[",
"'value'",
"]",
";",
"return",
"$",
"return",
";",
"}"
] | Prepare translations .
@param $translations
@return array | [
"Prepare",
"translations",
"."
] | train | https://github.com/parfumix/laravel-translator/blob/b85f17cbfebd4f35d1bfb817fbf13bff2c3f487e/src/Drivers/Database.php#L96-L103 |
parfumix/laravel-translator | src/Drivers/Database.php | Database.getTranslation | protected function getTranslation($key, $locale) {
if( isset($this->translations[$locale][$key]) )
return $this->translations[$locale][$key];
return $key;
} | php | protected function getTranslation($key, $locale) {
if( isset($this->translations[$locale][$key]) )
return $this->translations[$locale][$key];
return $key;
} | [
"protected",
"function",
"getTranslation",
"(",
"$",
"key",
",",
"$",
"locale",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"translations",
"[",
"$",
"locale",
"]",
"[",
"$",
"key",
"]",
")",
")",
"return",
"$",
"this",
"->",
"translations",
"[",
"$",
"locale",
"]",
"[",
"$",
"key",
"]",
";",
"return",
"$",
"key",
";",
"}"
] | Get translation by key .
@param $key
@param $locale
@return mixed | [
"Get",
"translation",
"by",
"key",
"."
] | train | https://github.com/parfumix/laravel-translator/blob/b85f17cbfebd4f35d1bfb817fbf13bff2c3f487e/src/Drivers/Database.php#L121-L126 |
parfumix/laravel-translator | src/Drivers/Database.php | Database.get | public function get($key, $replacement = array(), $locale = null) {
$locale = $this->locale($locale);
$translation = $this->getTranslation($key, $locale);
return $this->replace(
$translation, $replacement
);
} | php | public function get($key, $replacement = array(), $locale = null) {
$locale = $this->locale($locale);
$translation = $this->getTranslation($key, $locale);
return $this->replace(
$translation, $replacement
);
} | [
"public",
"function",
"get",
"(",
"$",
"key",
",",
"$",
"replacement",
"=",
"array",
"(",
")",
",",
"$",
"locale",
"=",
"null",
")",
"{",
"$",
"locale",
"=",
"$",
"this",
"->",
"locale",
"(",
"$",
"locale",
")",
";",
"$",
"translation",
"=",
"$",
"this",
"->",
"getTranslation",
"(",
"$",
"key",
",",
"$",
"locale",
")",
";",
"return",
"$",
"this",
"->",
"replace",
"(",
"$",
"translation",
",",
"$",
"replacement",
")",
";",
"}"
] | Get translation by key .
@param $key
@param array $replacement
@param null $locale
@return bool | [
"Get",
"translation",
"by",
"key",
"."
] | train | https://github.com/parfumix/laravel-translator/blob/b85f17cbfebd4f35d1bfb817fbf13bff2c3f487e/src/Drivers/Database.php#L137-L145 |
parfumix/laravel-translator | src/Drivers/Database.php | Database.has | public function has($key, $locale = null) {
$locale = $this->locale($locale);
return $this->get($key, [], $locale) !== $key;
} | php | public function has($key, $locale = null) {
$locale = $this->locale($locale);
return $this->get($key, [], $locale) !== $key;
} | [
"public",
"function",
"has",
"(",
"$",
"key",
",",
"$",
"locale",
"=",
"null",
")",
"{",
"$",
"locale",
"=",
"$",
"this",
"->",
"locale",
"(",
"$",
"locale",
")",
";",
"return",
"$",
"this",
"->",
"get",
"(",
"$",
"key",
",",
"[",
"]",
",",
"$",
"locale",
")",
"!==",
"$",
"key",
";",
"}"
] | Check if has translation .
@param $key
@param null $locale
@return bool | [
"Check",
"if",
"has",
"translation",
"."
] | train | https://github.com/parfumix/laravel-translator/blob/b85f17cbfebd4f35d1bfb817fbf13bff2c3f487e/src/Drivers/Database.php#L154-L158 |
parfumix/laravel-translator | src/Drivers/Database.php | Database.delete | public function delete($key, $group = null, $locale = null) {
$locale = $this->locale($locale);
$translation = $this->getRepository()
->getByKey($key, $locale, $group);
if( isset($translation->id) )
$this->getRepository()
->removeById($translation->id);
#@todo need to refresh cache .
return true;
} | php | public function delete($key, $group = null, $locale = null) {
$locale = $this->locale($locale);
$translation = $this->getRepository()
->getByKey($key, $locale, $group);
if( isset($translation->id) )
$this->getRepository()
->removeById($translation->id);
#@todo need to refresh cache .
return true;
} | [
"public",
"function",
"delete",
"(",
"$",
"key",
",",
"$",
"group",
"=",
"null",
",",
"$",
"locale",
"=",
"null",
")",
"{",
"$",
"locale",
"=",
"$",
"this",
"->",
"locale",
"(",
"$",
"locale",
")",
";",
"$",
"translation",
"=",
"$",
"this",
"->",
"getRepository",
"(",
")",
"->",
"getByKey",
"(",
"$",
"key",
",",
"$",
"locale",
",",
"$",
"group",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"translation",
"->",
"id",
")",
")",
"$",
"this",
"->",
"getRepository",
"(",
")",
"->",
"removeById",
"(",
"$",
"translation",
"->",
"id",
")",
";",
"#@todo need to refresh cache .",
"return",
"true",
";",
"}"
] | Delete translation by key .
@param $key
@param null $group
@param null $locale
@return bool | [
"Delete",
"translation",
"by",
"key",
"."
] | train | https://github.com/parfumix/laravel-translator/blob/b85f17cbfebd4f35d1bfb817fbf13bff2c3f487e/src/Drivers/Database.php#L168-L181 |
nexxes/php-tokenmatcher | src/Optional.php | Optional.match | public function match(array $tokens, $offset = 0) {
$this->status = self::STATUS_SUCCESS; // Optional always matches
if (false !== ($matched = $this->matched->match($tokens, $offset))) {
return $matched;
} else {
return 0;
}
} | php | public function match(array $tokens, $offset = 0) {
$this->status = self::STATUS_SUCCESS; // Optional always matches
if (false !== ($matched = $this->matched->match($tokens, $offset))) {
return $matched;
} else {
return 0;
}
} | [
"public",
"function",
"match",
"(",
"array",
"$",
"tokens",
",",
"$",
"offset",
"=",
"0",
")",
"{",
"$",
"this",
"->",
"status",
"=",
"self",
"::",
"STATUS_SUCCESS",
";",
"// Optional always matches",
"if",
"(",
"false",
"!==",
"(",
"$",
"matched",
"=",
"$",
"this",
"->",
"matched",
"->",
"match",
"(",
"$",
"tokens",
",",
"$",
"offset",
")",
")",
")",
"{",
"return",
"$",
"matched",
";",
"}",
"else",
"{",
"return",
"0",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/nexxes/php-tokenmatcher/blob/dbcf29755c9396d45130f0558d6cc07ea647ca50/src/Optional.php#L30-L38 |
manzoli2122/salao-despesas-ajax | src/Despesas/Ajax/Http/Controllers/FuncionarioController.php | FuncionarioController.getDatatable | public function getDatatable(){
$models = $this->model->getDatatable();
return Datatables::of($models)
->addColumn('action', function($linha) {
return '<button data-id="'.$linha->id.'" type="button" class="btn btn-primary btn-xs btn-datatable" btn-show title="Visualizar" style="margin-left: 10px;"> <i class="fa fa-search"></i> </button>' ;
})->make(true);
} | php | public function getDatatable(){
$models = $this->model->getDatatable();
return Datatables::of($models)
->addColumn('action', function($linha) {
return '<button data-id="'.$linha->id.'" type="button" class="btn btn-primary btn-xs btn-datatable" btn-show title="Visualizar" style="margin-left: 10px;"> <i class="fa fa-search"></i> </button>' ;
})->make(true);
} | [
"public",
"function",
"getDatatable",
"(",
")",
"{",
"$",
"models",
"=",
"$",
"this",
"->",
"model",
"->",
"getDatatable",
"(",
")",
";",
"return",
"Datatables",
"::",
"of",
"(",
"$",
"models",
")",
"->",
"addColumn",
"(",
"'action'",
",",
"function",
"(",
"$",
"linha",
")",
"{",
"return",
"'<button data-id=\"'",
".",
"$",
"linha",
"->",
"id",
".",
"'\" type=\"button\" class=\"btn btn-primary btn-xs btn-datatable\" btn-show title=\"Visualizar\" style=\"margin-left: 10px;\"> <i class=\"fa fa-search\"></i> </button>'",
";",
"}",
")",
"->",
"make",
"(",
"true",
")",
";",
"}"
] | Processa a requisição AJAX do DataTable na página de listagem.
Mais informações em: http://datatables.yajrabox.com
@return \Illuminate\Http\JsonResponse | [
"Processa",
"a",
"requisição",
"AJAX",
"do",
"DataTable",
"na",
"página",
"de",
"listagem",
".",
"Mais",
"informações",
"em",
":",
"http",
":",
"//",
"datatables",
".",
"yajrabox",
".",
"com"
] | train | https://github.com/manzoli2122/salao-despesas-ajax/blob/58a217b27f5644bcb8c0c16f06df52050d139a6c/src/Despesas/Ajax/Http/Controllers/FuncionarioController.php#L53-L59 |
jhorlima/wp-mocabonita | src/model/MbWpUser.php | MbWpUser.getCurrentUser | public static function getCurrentUser($dontThrowException = false)
{
if (!self::$currentUser instanceof MbWpUser) {
try {
self::$currentUser = self::findOrFail(get_current_user_id());
} catch (\Exception $e) {
self::$currentUser = new self();
self::$currentUser->forceFill([
'ID' => 0,
'user_login' => 'Anonymous',
'user_nicename' => 'Anonymous',
'display_name' => 'Anonymous',
]);
}
}
if (!self::$currentUser->exists && !$dontThrowException) {
throw new \Exception("No users have been logged in!");
}
return self::$currentUser;
} | php | public static function getCurrentUser($dontThrowException = false)
{
if (!self::$currentUser instanceof MbWpUser) {
try {
self::$currentUser = self::findOrFail(get_current_user_id());
} catch (\Exception $e) {
self::$currentUser = new self();
self::$currentUser->forceFill([
'ID' => 0,
'user_login' => 'Anonymous',
'user_nicename' => 'Anonymous',
'display_name' => 'Anonymous',
]);
}
}
if (!self::$currentUser->exists && !$dontThrowException) {
throw new \Exception("No users have been logged in!");
}
return self::$currentUser;
} | [
"public",
"static",
"function",
"getCurrentUser",
"(",
"$",
"dontThrowException",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"currentUser",
"instanceof",
"MbWpUser",
")",
"{",
"try",
"{",
"self",
"::",
"$",
"currentUser",
"=",
"self",
"::",
"findOrFail",
"(",
"get_current_user_id",
"(",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"self",
"::",
"$",
"currentUser",
"=",
"new",
"self",
"(",
")",
";",
"self",
"::",
"$",
"currentUser",
"->",
"forceFill",
"(",
"[",
"'ID'",
"=>",
"0",
",",
"'user_login'",
"=>",
"'Anonymous'",
",",
"'user_nicename'",
"=>",
"'Anonymous'",
",",
"'display_name'",
"=>",
"'Anonymous'",
",",
"]",
")",
";",
"}",
"}",
"if",
"(",
"!",
"self",
"::",
"$",
"currentUser",
"->",
"exists",
"&&",
"!",
"$",
"dontThrowException",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"No users have been logged in!\"",
")",
";",
"}",
"return",
"self",
"::",
"$",
"currentUser",
";",
"}"
] | Get current user logged
@param bool $dontThrowException
@return MbWpUser
@throws \Exception | [
"Get",
"current",
"user",
"logged"
] | train | https://github.com/jhorlima/wp-mocabonita/blob/a864b40d5452bc9b892f02a6bb28c02639f25fa8/src/model/MbWpUser.php#L128-L150 |
zodream/gzo | src/Domain/Generator/AbstractGenerator.php | AbstractGenerator.write | public function write($file = '') {
if ($file == '') {
$file = $this->outSourceFile;
}
file_put_contents($file, $this->generate());
} | php | public function write($file = '') {
if ($file == '') {
$file = $this->outSourceFile;
}
file_put_contents($file, $this->generate());
} | [
"public",
"function",
"write",
"(",
"$",
"file",
"=",
"''",
")",
"{",
"if",
"(",
"$",
"file",
"==",
"''",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"outSourceFile",
";",
"}",
"file_put_contents",
"(",
"$",
"file",
",",
"$",
"this",
"->",
"generate",
"(",
")",
")",
";",
"}"
] | Generates the code and writes it to a source file.
@param string $file | [
"Generates",
"the",
"code",
"and",
"writes",
"it",
"to",
"a",
"source",
"file",
"."
] | train | https://github.com/zodream/gzo/blob/106ca1f0281c140c280c3709f54ef059b7ffcdf9/src/Domain/Generator/AbstractGenerator.php#L86-L92 |
afonzeca/arun-core | src/ArunCore/Core/Domain/DomainActionExecutor.php | DomainActionExecutor.exec | public function exec(
string $className,
string $domain,
string $action
): bool {
if (
class_exists($className) &&
$this->lHelper->isDomainEnabled($domain)
) {
$numOfMandatoryParams = $this->lHelper->numberOfMandatoryParameters($className, $domain, $action);
$realParameters = $this->cInput->getParams();
$numOfMandatoryParams !== null && ($numOfMandatoryParams <= count($this->cInput->getParams()))
?: $action = "help";
$this->makeObjectAndRunMethod($className, $domain, $action, $realParameters);
return true;
}
$this->makeObjectAndRunMethod("App\Console\Domains\DefaultDomain", $domain, "help", []);
return false;
} | php | public function exec(
string $className,
string $domain,
string $action
): bool {
if (
class_exists($className) &&
$this->lHelper->isDomainEnabled($domain)
) {
$numOfMandatoryParams = $this->lHelper->numberOfMandatoryParameters($className, $domain, $action);
$realParameters = $this->cInput->getParams();
$numOfMandatoryParams !== null && ($numOfMandatoryParams <= count($this->cInput->getParams()))
?: $action = "help";
$this->makeObjectAndRunMethod($className, $domain, $action, $realParameters);
return true;
}
$this->makeObjectAndRunMethod("App\Console\Domains\DefaultDomain", $domain, "help", []);
return false;
} | [
"public",
"function",
"exec",
"(",
"string",
"$",
"className",
",",
"string",
"$",
"domain",
",",
"string",
"$",
"action",
")",
":",
"bool",
"{",
"if",
"(",
"class_exists",
"(",
"$",
"className",
")",
"&&",
"$",
"this",
"->",
"lHelper",
"->",
"isDomainEnabled",
"(",
"$",
"domain",
")",
")",
"{",
"$",
"numOfMandatoryParams",
"=",
"$",
"this",
"->",
"lHelper",
"->",
"numberOfMandatoryParameters",
"(",
"$",
"className",
",",
"$",
"domain",
",",
"$",
"action",
")",
";",
"$",
"realParameters",
"=",
"$",
"this",
"->",
"cInput",
"->",
"getParams",
"(",
")",
";",
"$",
"numOfMandatoryParams",
"!==",
"null",
"&&",
"(",
"$",
"numOfMandatoryParams",
"<=",
"count",
"(",
"$",
"this",
"->",
"cInput",
"->",
"getParams",
"(",
")",
")",
")",
"?",
":",
"$",
"action",
"=",
"\"help\"",
";",
"$",
"this",
"->",
"makeObjectAndRunMethod",
"(",
"$",
"className",
",",
"$",
"domain",
",",
"$",
"action",
",",
"$",
"realParameters",
")",
";",
"return",
"true",
";",
"}",
"$",
"this",
"->",
"makeObjectAndRunMethod",
"(",
"\"App\\Console\\Domains\\DefaultDomain\"",
",",
"$",
"domain",
",",
"\"help\"",
",",
"[",
"]",
")",
";",
"return",
"false",
";",
"}"
] | Get DOMAIN:ACTION and parameters processed from a Class which adhere to CommandLineManagerInterface
check if the number of parameters from cli corresponds to class parameters that manages the DOMAIN:ACTION
This method uses Factory for making the Class (because DOMAINS are not services, we do not store it into the
container)
@param string $className
@param string $domain
@param string $action
@throws \Exception
@throws \DI\DependencyException
@throws \DI\NotFoundException
@throws \ReflectionException
@return bool | [
"Get",
"DOMAIN",
":",
"ACTION",
"and",
"parameters",
"processed",
"from",
"a",
"Class",
"which",
"adhere",
"to",
"CommandLineManagerInterface",
"check",
"if",
"the",
"number",
"of",
"parameters",
"from",
"cli",
"corresponds",
"to",
"class",
"parameters",
"that",
"manages",
"the",
"DOMAIN",
":",
"ACTION",
"This",
"method",
"uses",
"Factory",
"for",
"making",
"the",
"Class",
"(",
"because",
"DOMAINS",
"are",
"not",
"services",
"we",
"do",
"not",
"store",
"it",
"into",
"the",
"container",
")"
] | train | https://github.com/afonzeca/arun-core/blob/7a8af37e326187ff9ed7e2ff7bde6a489a9803a2/src/ArunCore/Core/Domain/DomainActionExecutor.php#L100-L123 |
afonzeca/arun-core | src/ArunCore/Core/Domain/DomainActionExecutor.php | DomainActionExecutor.makeObjectAndRunMethod | private function makeObjectAndRunMethod(
string $className,
string $domain,
string $action,
array $realParameters
): void
{
if (!$this->lHelper->isActionEnabled($className, $action)) {
$action = "help";
}
$this->container->make($className)
->{$action}
(...($this->lHelper->getReCastedParameters($className, $domain, $action, $realParameters)));
} | php | private function makeObjectAndRunMethod(
string $className,
string $domain,
string $action,
array $realParameters
): void
{
if (!$this->lHelper->isActionEnabled($className, $action)) {
$action = "help";
}
$this->container->make($className)
->{$action}
(...($this->lHelper->getReCastedParameters($className, $domain, $action, $realParameters)));
} | [
"private",
"function",
"makeObjectAndRunMethod",
"(",
"string",
"$",
"className",
",",
"string",
"$",
"domain",
",",
"string",
"$",
"action",
",",
"array",
"$",
"realParameters",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"lHelper",
"->",
"isActionEnabled",
"(",
"$",
"className",
",",
"$",
"action",
")",
")",
"{",
"$",
"action",
"=",
"\"help\"",
";",
"}",
"$",
"this",
"->",
"container",
"->",
"make",
"(",
"$",
"className",
")",
"->",
"{",
"$",
"action",
"}",
"(",
"...",
"(",
"$",
"this",
"->",
"lHelper",
"->",
"getReCastedParameters",
"(",
"$",
"className",
",",
"$",
"domain",
",",
"$",
"action",
",",
"$",
"realParameters",
")",
")",
")",
";",
"}"
] | @param string $className
@param string $domain
@param string $action
@param array $realParameters
@throws \DI\DependencyException
@throws \DI\NotFoundException
@throws \ReflectionException | [
"@param",
"string",
"$className",
"@param",
"string",
"$domain",
"@param",
"string",
"$action",
"@param",
"array",
"$realParameters"
] | train | https://github.com/afonzeca/arun-core/blob/7a8af37e326187ff9ed7e2ff7bde6a489a9803a2/src/ArunCore/Core/Domain/DomainActionExecutor.php#L135-L149 |
mszewcz/php-json-schema-validator | src/Validators/ObjectValidators/PatternPropertiesValidator.php | PatternPropertiesValidator.validate | public function validate($subject): bool
{
if (\is_array($this->schema['patternProperties'])) {
foreach ($this->schema['patternProperties'] as $pattern => $patternSchema) {
foreach ($subject as $propertyName => $propertyData) {
if (\preg_match(sprintf('/%s/', $pattern), $propertyName)) {
$nodeValidator = new NodeValidator($patternSchema, $this->rootSchema);
if (!$nodeValidator->validate($propertyData)) {
return false;
}
}
}
}
}
return true;
} | php | public function validate($subject): bool
{
if (\is_array($this->schema['patternProperties'])) {
foreach ($this->schema['patternProperties'] as $pattern => $patternSchema) {
foreach ($subject as $propertyName => $propertyData) {
if (\preg_match(sprintf('/%s/', $pattern), $propertyName)) {
$nodeValidator = new NodeValidator($patternSchema, $this->rootSchema);
if (!$nodeValidator->validate($propertyData)) {
return false;
}
}
}
}
}
return true;
} | [
"public",
"function",
"validate",
"(",
"$",
"subject",
")",
":",
"bool",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"this",
"->",
"schema",
"[",
"'patternProperties'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"schema",
"[",
"'patternProperties'",
"]",
"as",
"$",
"pattern",
"=>",
"$",
"patternSchema",
")",
"{",
"foreach",
"(",
"$",
"subject",
"as",
"$",
"propertyName",
"=>",
"$",
"propertyData",
")",
"{",
"if",
"(",
"\\",
"preg_match",
"(",
"sprintf",
"(",
"'/%s/'",
",",
"$",
"pattern",
")",
",",
"$",
"propertyName",
")",
")",
"{",
"$",
"nodeValidator",
"=",
"new",
"NodeValidator",
"(",
"$",
"patternSchema",
",",
"$",
"this",
"->",
"rootSchema",
")",
";",
"if",
"(",
"!",
"$",
"nodeValidator",
"->",
"validate",
"(",
"$",
"propertyData",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
"}",
"}",
"return",
"true",
";",
"}"
] | Validates subject against patternProperties
@param array $subject
@return bool | [
"Validates",
"subject",
"against",
"patternProperties"
] | train | https://github.com/mszewcz/php-json-schema-validator/blob/f7768bfe07ce6508bb1ff36163560a5e5791de7d/src/Validators/ObjectValidators/PatternPropertiesValidator.php#L48-L63 |