repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/implementations/query_select_sqlite.php | ezcQuerySelectSqlite.buildRightJoins | private function buildRightJoins()
{
$resultArray = array();
foreach ( $this->rightJoins as $rJoinPart )
{
$oneItemResult = '';
if ( $rJoinPart === null )
{
break; // this is last empty entry so cancel adding.
}
// reverse lists of tables and conditions to make LEFT JOIN
// that will produce result equal to original right join.
$reversedTables = array_reverse( $rJoinPart['tables'] );
$reversedConditions = array_reverse( $rJoinPart['conditions'] );
// adding first table.
list( $key, $val ) = each( $reversedTables );
$oneItemResult .= $val;
while ( list( $key, $nextCondition ) = each( $reversedConditions ) )
{
list( $key2, $nextTable ) = each( $reversedTables );
$oneItemResult .= " LEFT JOIN {$nextTable} ON {$nextCondition}";
}
$resultArray[] = $oneItemResult;
}
return join( ', ', $resultArray );
} | php | private function buildRightJoins()
{
$resultArray = array();
foreach ( $this->rightJoins as $rJoinPart )
{
$oneItemResult = '';
if ( $rJoinPart === null )
{
break; // this is last empty entry so cancel adding.
}
// reverse lists of tables and conditions to make LEFT JOIN
// that will produce result equal to original right join.
$reversedTables = array_reverse( $rJoinPart['tables'] );
$reversedConditions = array_reverse( $rJoinPart['conditions'] );
// adding first table.
list( $key, $val ) = each( $reversedTables );
$oneItemResult .= $val;
while ( list( $key, $nextCondition ) = each( $reversedConditions ) )
{
list( $key2, $nextTable ) = each( $reversedTables );
$oneItemResult .= " LEFT JOIN {$nextTable} ON {$nextCondition}";
}
$resultArray[] = $oneItemResult;
}
return join( ', ', $resultArray );
} | [
"private",
"function",
"buildRightJoins",
"(",
")",
"{",
"$",
"resultArray",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"rightJoins",
"as",
"$",
"rJoinPart",
")",
"{",
"$",
"oneItemResult",
"=",
"''",
";",
"if",
"(",
"$",
"rJoinPart",
"===",
"null",
")",
"{",
"break",
";",
"// this is last empty entry so cancel adding.",
"}",
"// reverse lists of tables and conditions to make LEFT JOIN ",
"// that will produce result equal to original right join.",
"$",
"reversedTables",
"=",
"array_reverse",
"(",
"$",
"rJoinPart",
"[",
"'tables'",
"]",
")",
";",
"$",
"reversedConditions",
"=",
"array_reverse",
"(",
"$",
"rJoinPart",
"[",
"'conditions'",
"]",
")",
";",
"// adding first table.",
"list",
"(",
"$",
"key",
",",
"$",
"val",
")",
"=",
"each",
"(",
"$",
"reversedTables",
")",
";",
"$",
"oneItemResult",
".=",
"$",
"val",
";",
"while",
"(",
"list",
"(",
"$",
"key",
",",
"$",
"nextCondition",
")",
"=",
"each",
"(",
"$",
"reversedConditions",
")",
")",
"{",
"list",
"(",
"$",
"key2",
",",
"$",
"nextTable",
")",
"=",
"each",
"(",
"$",
"reversedTables",
")",
";",
"$",
"oneItemResult",
".=",
"\" LEFT JOIN {$nextTable} ON {$nextCondition}\"",
";",
"}",
"$",
"resultArray",
"[",
"]",
"=",
"$",
"oneItemResult",
";",
"}",
"return",
"join",
"(",
"', '",
",",
"$",
"resultArray",
")",
";",
"}"
] | Returns SQL string with part of FROM clause that performs right join emulation.
SQLite don't support right joins directly but there is workaround.
identical result could be acheived using right joins for tables in reverce order.
String created from entries of $rightJoins.
One entry is a complete table_reference clause of SQL FROM clause.
<code>
rightJoins[0][tables] = array( 'table1', 'table2', 'table3' )
rightJoins[0][conditions] = array( condition1, condition2 )
</code>
forms SQL: 'table3 LEFT JOIN table2 condition2 ON LEFT JOIN table1 ON condition1'.
@return string the SQL call including all right joins set in query. | [
"Returns",
"SQL",
"string",
"with",
"part",
"of",
"FROM",
"clause",
"that",
"performs",
"right",
"join",
"emulation",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/implementations/query_select_sqlite.php#L141-L171 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/implementations/query_select_sqlite.php | ezcQuerySelectSqlite.rightJoin | public function rightJoin()
{
$args = func_get_args();
$passedArgsCount = func_num_args();
if ( $passedArgsCount < 2 || $passedArgsCount > 4 )
{
throw new ezcQueryInvalidException( 'SELECT', "Wrong argument count passed to {$type}Join(): {$passedArgsCount}" );
}
// deprecated syntax
if ( $passedArgsCount == 4 )
{
if ( is_string( $args[0] ) && is_string( $args[1] ) &&
is_string( $args[2] ) && is_string( $args[3] )
)
{
$table1 = $this->getIdentifier( $args[0] );
$table2 = $this->getIdentifier( $args[1] );
$column1 = $this->getIdentifier( $args[2] );
$column2 = $this->getIdentifier( $args[3] );
return "{$table2} LEFT JOIN {$table1} ON {$column1} = {$column2}";
}
else
{
throw new ezcQueryInvalidException( 'SELECT', 'Inconsistent types of arguments passed to rightJoin().' );
}
}
// using from()->rightJoin() syntax assumed, so check if last call was to from()
if ( $this->lastInvokedMethod != 'from' )
{
throw new ezcQueryInvalidException( 'SELECT', 'Invoking rightJoin() not immediately after from().' );
}
$table = '';
if ( !is_string( $args[0] ) )
{
throw new ezcQueryInvalidException( 'SELECT',
'Inconsistent type of first argument passed to rightJoin(). Should be string with name of table.' );
}
$table = $this->getIdentifier( $args[0] );
$condition = '';
if ( $passedArgsCount == 2 && is_string( $args[1] ) )
{
$condition = $args[1];
}
else if ( $passedArgsCount == 3 && is_string( $args[1] ) && is_string( $args[2] ) )
{
$arg1 = $this->getIdentifier( $args[1] );
$arg2 = $this->getIdentifier( $args[2] );
$condition = "{$arg1} = {$arg2}";
}
// If rightJoin info entry is empty than remove last table from
// fromTables list and add it at first place to the list of tables in
// correspondent rightJoin info entry.
// Subsequent calls to rightJoin() without from() will just add one
// table and one condition to the correspondent arrays.
if ( end( $this->rightJoins ) === null ) // fill last rightJoin info entry with table name.
{
$lastTable = array_pop ( $this->fromTables );
array_pop( $this->rightJoins );
$this->rightJoins[count( $this->rightJoins )]['tables'][] = $lastTable;
}
if ( $table != '' && $condition != '' )
{
$this->rightJoins[count( $this->rightJoins ) - 1]['tables'][] = $table;
$this->rightJoins[count( $this->rightJoins ) - 1]['conditions'][] = $condition;
}
// build fromString using fromTables and add right joins stuff to te end.
$this->fromString = 'FROM ' . join( ', ', $this->fromTables );
$this->fromString .= $this->buildRightJoins();
return $this;
} | php | public function rightJoin()
{
$args = func_get_args();
$passedArgsCount = func_num_args();
if ( $passedArgsCount < 2 || $passedArgsCount > 4 )
{
throw new ezcQueryInvalidException( 'SELECT', "Wrong argument count passed to {$type}Join(): {$passedArgsCount}" );
}
// deprecated syntax
if ( $passedArgsCount == 4 )
{
if ( is_string( $args[0] ) && is_string( $args[1] ) &&
is_string( $args[2] ) && is_string( $args[3] )
)
{
$table1 = $this->getIdentifier( $args[0] );
$table2 = $this->getIdentifier( $args[1] );
$column1 = $this->getIdentifier( $args[2] );
$column2 = $this->getIdentifier( $args[3] );
return "{$table2} LEFT JOIN {$table1} ON {$column1} = {$column2}";
}
else
{
throw new ezcQueryInvalidException( 'SELECT', 'Inconsistent types of arguments passed to rightJoin().' );
}
}
// using from()->rightJoin() syntax assumed, so check if last call was to from()
if ( $this->lastInvokedMethod != 'from' )
{
throw new ezcQueryInvalidException( 'SELECT', 'Invoking rightJoin() not immediately after from().' );
}
$table = '';
if ( !is_string( $args[0] ) )
{
throw new ezcQueryInvalidException( 'SELECT',
'Inconsistent type of first argument passed to rightJoin(). Should be string with name of table.' );
}
$table = $this->getIdentifier( $args[0] );
$condition = '';
if ( $passedArgsCount == 2 && is_string( $args[1] ) )
{
$condition = $args[1];
}
else if ( $passedArgsCount == 3 && is_string( $args[1] ) && is_string( $args[2] ) )
{
$arg1 = $this->getIdentifier( $args[1] );
$arg2 = $this->getIdentifier( $args[2] );
$condition = "{$arg1} = {$arg2}";
}
// If rightJoin info entry is empty than remove last table from
// fromTables list and add it at first place to the list of tables in
// correspondent rightJoin info entry.
// Subsequent calls to rightJoin() without from() will just add one
// table and one condition to the correspondent arrays.
if ( end( $this->rightJoins ) === null ) // fill last rightJoin info entry with table name.
{
$lastTable = array_pop ( $this->fromTables );
array_pop( $this->rightJoins );
$this->rightJoins[count( $this->rightJoins )]['tables'][] = $lastTable;
}
if ( $table != '' && $condition != '' )
{
$this->rightJoins[count( $this->rightJoins ) - 1]['tables'][] = $table;
$this->rightJoins[count( $this->rightJoins ) - 1]['conditions'][] = $condition;
}
// build fromString using fromTables and add right joins stuff to te end.
$this->fromString = 'FROM ' . join( ', ', $this->fromTables );
$this->fromString .= $this->buildRightJoins();
return $this;
} | [
"public",
"function",
"rightJoin",
"(",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"$",
"passedArgsCount",
"=",
"func_num_args",
"(",
")",
";",
"if",
"(",
"$",
"passedArgsCount",
"<",
"2",
"||",
"$",
"passedArgsCount",
">",
"4",
")",
"{",
"throw",
"new",
"ezcQueryInvalidException",
"(",
"'SELECT'",
",",
"\"Wrong argument count passed to {$type}Join(): {$passedArgsCount}\"",
")",
";",
"}",
"// deprecated syntax",
"if",
"(",
"$",
"passedArgsCount",
"==",
"4",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"args",
"[",
"0",
"]",
")",
"&&",
"is_string",
"(",
"$",
"args",
"[",
"1",
"]",
")",
"&&",
"is_string",
"(",
"$",
"args",
"[",
"2",
"]",
")",
"&&",
"is_string",
"(",
"$",
"args",
"[",
"3",
"]",
")",
")",
"{",
"$",
"table1",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"args",
"[",
"0",
"]",
")",
";",
"$",
"table2",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"args",
"[",
"1",
"]",
")",
";",
"$",
"column1",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"args",
"[",
"2",
"]",
")",
";",
"$",
"column2",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"args",
"[",
"3",
"]",
")",
";",
"return",
"\"{$table2} LEFT JOIN {$table1} ON {$column1} = {$column2}\"",
";",
"}",
"else",
"{",
"throw",
"new",
"ezcQueryInvalidException",
"(",
"'SELECT'",
",",
"'Inconsistent types of arguments passed to rightJoin().'",
")",
";",
"}",
"}",
"// using from()->rightJoin() syntax assumed, so check if last call was to from()",
"if",
"(",
"$",
"this",
"->",
"lastInvokedMethod",
"!=",
"'from'",
")",
"{",
"throw",
"new",
"ezcQueryInvalidException",
"(",
"'SELECT'",
",",
"'Invoking rightJoin() not immediately after from().'",
")",
";",
"}",
"$",
"table",
"=",
"''",
";",
"if",
"(",
"!",
"is_string",
"(",
"$",
"args",
"[",
"0",
"]",
")",
")",
"{",
"throw",
"new",
"ezcQueryInvalidException",
"(",
"'SELECT'",
",",
"'Inconsistent type of first argument passed to rightJoin(). Should be string with name of table.'",
")",
";",
"}",
"$",
"table",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"args",
"[",
"0",
"]",
")",
";",
"$",
"condition",
"=",
"''",
";",
"if",
"(",
"$",
"passedArgsCount",
"==",
"2",
"&&",
"is_string",
"(",
"$",
"args",
"[",
"1",
"]",
")",
")",
"{",
"$",
"condition",
"=",
"$",
"args",
"[",
"1",
"]",
";",
"}",
"else",
"if",
"(",
"$",
"passedArgsCount",
"==",
"3",
"&&",
"is_string",
"(",
"$",
"args",
"[",
"1",
"]",
")",
"&&",
"is_string",
"(",
"$",
"args",
"[",
"2",
"]",
")",
")",
"{",
"$",
"arg1",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"args",
"[",
"1",
"]",
")",
";",
"$",
"arg2",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"args",
"[",
"2",
"]",
")",
";",
"$",
"condition",
"=",
"\"{$arg1} = {$arg2}\"",
";",
"}",
"// If rightJoin info entry is empty than remove last table from",
"// fromTables list and add it at first place to the list of tables in",
"// correspondent rightJoin info entry.",
"// Subsequent calls to rightJoin() without from() will just add one",
"// table and one condition to the correspondent arrays.",
"if",
"(",
"end",
"(",
"$",
"this",
"->",
"rightJoins",
")",
"===",
"null",
")",
"// fill last rightJoin info entry with table name.",
"{",
"$",
"lastTable",
"=",
"array_pop",
"(",
"$",
"this",
"->",
"fromTables",
")",
";",
"array_pop",
"(",
"$",
"this",
"->",
"rightJoins",
")",
";",
"$",
"this",
"->",
"rightJoins",
"[",
"count",
"(",
"$",
"this",
"->",
"rightJoins",
")",
"]",
"[",
"'tables'",
"]",
"[",
"]",
"=",
"$",
"lastTable",
";",
"}",
"if",
"(",
"$",
"table",
"!=",
"''",
"&&",
"$",
"condition",
"!=",
"''",
")",
"{",
"$",
"this",
"->",
"rightJoins",
"[",
"count",
"(",
"$",
"this",
"->",
"rightJoins",
")",
"-",
"1",
"]",
"[",
"'tables'",
"]",
"[",
"]",
"=",
"$",
"table",
";",
"$",
"this",
"->",
"rightJoins",
"[",
"count",
"(",
"$",
"this",
"->",
"rightJoins",
")",
"-",
"1",
"]",
"[",
"'conditions'",
"]",
"[",
"]",
"=",
"$",
"condition",
";",
"}",
"// build fromString using fromTables and add right joins stuff to te end.",
"$",
"this",
"->",
"fromString",
"=",
"'FROM '",
".",
"join",
"(",
"', '",
",",
"$",
"this",
"->",
"fromTables",
")",
";",
"$",
"this",
"->",
"fromString",
".=",
"$",
"this",
"->",
"buildRightJoins",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Returns the SQL for a right join or prepares $fromString for a right join.
This method could be used in two forms:
<b>rightJoin( 't2', $joinCondition )</b>
Takes 2 string arguments and returns ezcQuery.
The first parameter is the name of the table to join with. The table to
which is joined should have been previously set with the from() method.
The second parameter should be a string containing a join condition that
is returned by an ezcQueryExpression.
Example:
<code>
// the following code will produce the SQL
// SELECT id FROM t1 LEFT JOIN t2 ON t1.id = t2.id
$q->select( 'id' )->from( 't1' )->rightJoin( 't2', $q->expr->eq('t1.id', 't2.id' ) );
</code>
<b>rightJoin( 't2', 't1.id', 't2.id' )</b>
Takes 3 string arguments and returns ezcQuery. This is a simplified form
of the 2 parameter version. rightJoin( 't2', 't1.id', 't2.id' ) is
equal to rightJoin( 't2', $this->expr->eq('t1.id', 't2.id' ) );
The first parameter is the name of the table to join with. The table to
which is joined should have been previously set with the from() method.
The second parameter is the name of the column on the table set
previously with the from() method and the third parameter the name of
the column to join with on the table that was specified in the first
parameter.
Example:
<code>
// the following code will produce the SQL
// SELECT id FROM t1 LEFT JOIN t2 ON t1.id = t2.id
$q->select( 'id' )->from( 't1' )->rightJoin( 't2', 't1.id', 't2.id' );
</code>
@apichange Remove 4 argument version.
@throws ezcQueryInvalidException if called with inconsistent parameters or if
invoked without preceding call to from().
@param string $table2,... The table to join with, followed by either the
two join columns, or a join condition.
@return ezcQuery | [
"Returns",
"the",
"SQL",
"for",
"a",
"right",
"join",
"or",
"prepares",
"$fromString",
"for",
"a",
"right",
"join",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/implementations/query_select_sqlite.php#L225-L305 |
Eresus/EresusCMS | src/core/Kernel.php | Eresus_Kernel.log | public static function log($sender, $priority, $message)
{
if ($priority > self::$logLevel)
{
return;
}
if (is_array($sender))
{
$sender = implode('/', $sender);
}
if (empty($sender))
{
$sender = 'unknown';
}
/* Если есть аргументы для подстановки — вставляем их */
if (@func_num_args() > 3)
{
$args = array();
for ($i = 3; $i < @func_num_args(); $i++)
{
$var = func_get_arg($i);
if (is_object($var))
{
$var = get_class($var);
}
$args []= $var;
}
$message = vsprintf($message, $args);
}
$message = $sender . ': ' . $message;
$priorities = array(
LOG_DEBUG => 'debug',
LOG_INFO => 'info',
LOG_NOTICE => 'notice',
LOG_WARNING => 'warning',
LOG_ERR => 'error',
LOG_CRIT => 'critical',
LOG_ALERT => 'ALERT',
LOG_EMERG => 'PANIC'
);
$message = '[' . (array_key_exists($priority, $priorities)
? $priorities[$priority] : 'unknown') . '] ' . $message;
if (!error_log($message))
{
if (!syslog($priority, $message))
{
fputs(STDERR, $message);
}
}
} | php | public static function log($sender, $priority, $message)
{
if ($priority > self::$logLevel)
{
return;
}
if (is_array($sender))
{
$sender = implode('/', $sender);
}
if (empty($sender))
{
$sender = 'unknown';
}
/* Если есть аргументы для подстановки — вставляем их */
if (@func_num_args() > 3)
{
$args = array();
for ($i = 3; $i < @func_num_args(); $i++)
{
$var = func_get_arg($i);
if (is_object($var))
{
$var = get_class($var);
}
$args []= $var;
}
$message = vsprintf($message, $args);
}
$message = $sender . ': ' . $message;
$priorities = array(
LOG_DEBUG => 'debug',
LOG_INFO => 'info',
LOG_NOTICE => 'notice',
LOG_WARNING => 'warning',
LOG_ERR => 'error',
LOG_CRIT => 'critical',
LOG_ALERT => 'ALERT',
LOG_EMERG => 'PANIC'
);
$message = '[' . (array_key_exists($priority, $priorities)
? $priorities[$priority] : 'unknown') . '] ' . $message;
if (!error_log($message))
{
if (!syslog($priority, $message))
{
fputs(STDERR, $message);
}
}
} | [
"public",
"static",
"function",
"log",
"(",
"$",
"sender",
",",
"$",
"priority",
",",
"$",
"message",
")",
"{",
"if",
"(",
"$",
"priority",
">",
"self",
"::",
"$",
"logLevel",
")",
"{",
"return",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"sender",
")",
")",
"{",
"$",
"sender",
"=",
"implode",
"(",
"'/'",
",",
"$",
"sender",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"sender",
")",
")",
"{",
"$",
"sender",
"=",
"'unknown'",
";",
"}",
"/* Если есть аргументы для подстановки — вставляем их */",
"if",
"(",
"@",
"func_num_args",
"(",
")",
">",
"3",
")",
"{",
"$",
"args",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"3",
";",
"$",
"i",
"<",
"@",
"func_num_args",
"(",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"var",
"=",
"func_get_arg",
"(",
"$",
"i",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"var",
")",
")",
"{",
"$",
"var",
"=",
"get_class",
"(",
"$",
"var",
")",
";",
"}",
"$",
"args",
"[",
"]",
"=",
"$",
"var",
";",
"}",
"$",
"message",
"=",
"vsprintf",
"(",
"$",
"message",
",",
"$",
"args",
")",
";",
"}",
"$",
"message",
"=",
"$",
"sender",
".",
"': '",
".",
"$",
"message",
";",
"$",
"priorities",
"=",
"array",
"(",
"LOG_DEBUG",
"=>",
"'debug'",
",",
"LOG_INFO",
"=>",
"'info'",
",",
"LOG_NOTICE",
"=>",
"'notice'",
",",
"LOG_WARNING",
"=>",
"'warning'",
",",
"LOG_ERR",
"=>",
"'error'",
",",
"LOG_CRIT",
"=>",
"'critical'",
",",
"LOG_ALERT",
"=>",
"'ALERT'",
",",
"LOG_EMERG",
"=>",
"'PANIC'",
")",
";",
"$",
"message",
"=",
"'['",
".",
"(",
"array_key_exists",
"(",
"$",
"priority",
",",
"$",
"priorities",
")",
"?",
"$",
"priorities",
"[",
"$",
"priority",
"]",
":",
"'unknown'",
")",
".",
"'] '",
".",
"$",
"message",
";",
"if",
"(",
"!",
"error_log",
"(",
"$",
"message",
")",
")",
"{",
"if",
"(",
"!",
"syslog",
"(",
"$",
"priority",
",",
"$",
"message",
")",
")",
"{",
"fputs",
"(",
"STDERR",
",",
"$",
"message",
")",
";",
"}",
"}",
"}"
] | Записывает сообщение в журнал
@param string|array $sender отправитель (используйте \__METHOD\__ и \__FUNCTION\__)
@param int $priority уровень важности (используйте константы LOG_xxx)
@param string $message текст сообщение
@param mixed ... аргументы для вставки в $message через {@link sprintf}
@see $logLevel
@since 3.01 | [
"Записывает",
"сообщение",
"в",
"журнал"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/Kernel.php#L84-L139 |
Eresus/EresusCMS | src/core/Kernel.php | Eresus_Kernel.logException | public static function logException($e)
{
$previous = $e->getPrevious();
$trace = $e->getTraceAsString();
$logMessage = sprintf(
"%s in %s at %s\n%s\nBacktrace:\n%s\n",
get_class($e),
$e->getFile(),
$e->getLine(),
$e->getMessage(),
$trace
);
Eresus_Kernel::log(__METHOD__, LOG_ERR, $logMessage);
if ($previous)
{
self::logException($previous, 'Previous exception:');
}
} | php | public static function logException($e)
{
$previous = $e->getPrevious();
$trace = $e->getTraceAsString();
$logMessage = sprintf(
"%s in %s at %s\n%s\nBacktrace:\n%s\n",
get_class($e),
$e->getFile(),
$e->getLine(),
$e->getMessage(),
$trace
);
Eresus_Kernel::log(__METHOD__, LOG_ERR, $logMessage);
if ($previous)
{
self::logException($previous, 'Previous exception:');
}
} | [
"public",
"static",
"function",
"logException",
"(",
"$",
"e",
")",
"{",
"$",
"previous",
"=",
"$",
"e",
"->",
"getPrevious",
"(",
")",
";",
"$",
"trace",
"=",
"$",
"e",
"->",
"getTraceAsString",
"(",
")",
";",
"$",
"logMessage",
"=",
"sprintf",
"(",
"\"%s in %s at %s\\n%s\\nBacktrace:\\n%s\\n\"",
",",
"get_class",
"(",
"$",
"e",
")",
",",
"$",
"e",
"->",
"getFile",
"(",
")",
",",
"$",
"e",
"->",
"getLine",
"(",
")",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"trace",
")",
";",
"Eresus_Kernel",
"::",
"log",
"(",
"__METHOD__",
",",
"LOG_ERR",
",",
"$",
"logMessage",
")",
";",
"if",
"(",
"$",
"previous",
")",
"{",
"self",
"::",
"logException",
"(",
"$",
"previous",
",",
"'Previous exception:'",
")",
";",
"}",
"}"
] | Записывает сообщение об исключении в журнал
@param Exception $e
@since 3.01 | [
"Записывает",
"сообщение",
"об",
"исключении",
"в",
"журнал"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/Kernel.php#L148-L168 |
Eresus/EresusCMS | src/core/Kernel.php | Eresus_Kernel.init | public static function init()
{
/* Разрешаем только однократный вызов этого метода */
if (self::$inited)
{
return;
}
// Устанавливаем кодировку по умолчанию для операций mb_*
mb_internal_encoding('utf-8');
/* Предотвращает появление ошибок, связанных с неустановленной временной зоной */
@$timezone = date_default_timezone_get();
date_default_timezone_set($timezone);
self::initExceptionHandling();
self::$inited = true;
} | php | public static function init()
{
/* Разрешаем только однократный вызов этого метода */
if (self::$inited)
{
return;
}
// Устанавливаем кодировку по умолчанию для операций mb_*
mb_internal_encoding('utf-8');
/* Предотвращает появление ошибок, связанных с неустановленной временной зоной */
@$timezone = date_default_timezone_get();
date_default_timezone_set($timezone);
self::initExceptionHandling();
self::$inited = true;
} | [
"public",
"static",
"function",
"init",
"(",
")",
"{",
"/* Разрешаем только однократный вызов этого метода */",
"if",
"(",
"self",
"::",
"$",
"inited",
")",
"{",
"return",
";",
"}",
"// Устанавливаем кодировку по умолчанию для операций mb_*",
"mb_internal_encoding",
"(",
"'utf-8'",
")",
";",
"/* Предотвращает появление ошибок, связанных с неустановленной временной зоной */",
"@",
"$",
"timezone",
"=",
"date_default_timezone_get",
"(",
")",
";",
"date_default_timezone_set",
"(",
"$",
"timezone",
")",
";",
"self",
"::",
"initExceptionHandling",
"(",
")",
";",
"self",
"::",
"$",
"inited",
"=",
"true",
";",
"}"
] | Инициализация ядра
Этот метод:
1. устанавливает временную зону;
2. регистрирует {@link initExceptionHandling() перехватчики ошибок}.
@return void
@since 3.00 | [
"Инициализация",
"ядра"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/Kernel.php#L181-L199 |
Eresus/EresusCMS | src/core/Kernel.php | Eresus_Kernel.errorHandler | public static function errorHandler($errno, $errstr, $errfile, $errline)
{
/* Нулевое значение 'error_reporting' означает что был использован оператор "@" */
if (error_reporting() == 0)
{
return true;
}
/*
* Примечание: На самом деле этот метод обрабатывает только E_WARNING, E_NOTICE, E_USER_ERROR,
* E_USER_WARNING, E_USER_NOTICE и E_STRICT
*/
/* Определяем серьёзность ошибки */
switch ($errno)
{
case E_STRICT:
case E_NOTICE:
case E_USER_NOTICE:
$level = LOG_NOTICE;
break;
case E_WARNING:
case E_USER_WARNING:
$level = LOG_WARNING;
break;
default:
$level = LOG_ERR;
break;
}
if ($level < LOG_NOTICE)
{
throw new ErrorException($errstr, $errno, $level, $errfile, $errline);
}
/*else
{
$logMessage = sprintf(
"%s in %s:%s",
$errstr,
$errfile,
$errline
);
Eresus_Logger::log(__FUNCTION__, $level, $logMessage);
}*/
return true;
} | php | public static function errorHandler($errno, $errstr, $errfile, $errline)
{
/* Нулевое значение 'error_reporting' означает что был использован оператор "@" */
if (error_reporting() == 0)
{
return true;
}
/*
* Примечание: На самом деле этот метод обрабатывает только E_WARNING, E_NOTICE, E_USER_ERROR,
* E_USER_WARNING, E_USER_NOTICE и E_STRICT
*/
/* Определяем серьёзность ошибки */
switch ($errno)
{
case E_STRICT:
case E_NOTICE:
case E_USER_NOTICE:
$level = LOG_NOTICE;
break;
case E_WARNING:
case E_USER_WARNING:
$level = LOG_WARNING;
break;
default:
$level = LOG_ERR;
break;
}
if ($level < LOG_NOTICE)
{
throw new ErrorException($errstr, $errno, $level, $errfile, $errline);
}
/*else
{
$logMessage = sprintf(
"%s in %s:%s",
$errstr,
$errfile,
$errline
);
Eresus_Logger::log(__FUNCTION__, $level, $logMessage);
}*/
return true;
} | [
"public",
"static",
"function",
"errorHandler",
"(",
"$",
"errno",
",",
"$",
"errstr",
",",
"$",
"errfile",
",",
"$",
"errline",
")",
"{",
"/* Нулевое значение 'error_reporting' означает что был использован оператор \"@\" */",
"if",
"(",
"error_reporting",
"(",
")",
"==",
"0",
")",
"{",
"return",
"true",
";",
"}",
"/*\n * Примечание: На самом деле этот метод обрабатывает только E_WARNING, E_NOTICE, E_USER_ERROR,\n * E_USER_WARNING, E_USER_NOTICE и E_STRICT\n */",
"/* Определяем серьёзность ошибки */",
"switch",
"(",
"$",
"errno",
")",
"{",
"case",
"E_STRICT",
":",
"case",
"E_NOTICE",
":",
"case",
"E_USER_NOTICE",
":",
"$",
"level",
"=",
"LOG_NOTICE",
";",
"break",
";",
"case",
"E_WARNING",
":",
"case",
"E_USER_WARNING",
":",
"$",
"level",
"=",
"LOG_WARNING",
";",
"break",
";",
"default",
":",
"$",
"level",
"=",
"LOG_ERR",
";",
"break",
";",
"}",
"if",
"(",
"$",
"level",
"<",
"LOG_NOTICE",
")",
"{",
"throw",
"new",
"ErrorException",
"(",
"$",
"errstr",
",",
"$",
"errno",
",",
"$",
"level",
",",
"$",
"errfile",
",",
"$",
"errline",
")",
";",
"}",
"/*else\n {\n $logMessage = sprintf(\n \"%s in %s:%s\",\n $errstr,\n $errfile,\n $errline\n );\n Eresus_Logger::log(__FUNCTION__, $level, $logMessage);\n }*/",
"return",
"true",
";",
"}"
] | Обработчик ошибок
Обработчик ошибок, устанавливаемый через {@link set_error_handler() set_error_handler()} в
методе {@link initExceptionHandling()}. Все ошибки важнее E_NOTICE превращаются в исключения
{@link http://php.net/ErrorException ErrorException}.
@param int $errno тип ошибки
@param string $errstr описание ошибки
@param string $errfile имя файла, в котором произошла ошибка
@param int $errline строка, где произошла ошибка
@throws ErrorException
@return bool
@since 3.00 | [
"Обработчик",
"ошибок"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/Kernel.php#L219-L265 |
Eresus/EresusCMS | src/core/Kernel.php | Eresus_Kernel.fatalErrorHandler | public static function fatalErrorHandler($output)
{
// Освобождает резервный буфер
unset($GLOBALS['ERESUS_MEMORY_OVERFLOW_BUFFER']);
if (preg_match('/(parse|fatal) error:.*in .* on line/Ui', $output, $m))
{
$GLOBALS['ERESUS_CORE_FATAL_ERROR_HANDLER'] = true;
switch (strtolower($m[1]))
{
case 'fatal':
$message = 'FATAL ERROR';
break;
case 'parse':
$message = 'PARSE ERROR';
break;
default:
$message = 'ERROR:';
}
self::log(__FUNCTION__, LOG_CRIT, trim($output));
if (!self::isCLI())
{
header('Internal Server Error', true, 500);
header('Content-type: text/plain', true);
}
return $message . "\nSee application log for more info.\n";
}
$GLOBALS['ERESUS_MEMORY_OVERFLOW_BUFFER'] =
str_repeat('x', self::MEMORY_OVERFLOW_BUFFER_SIZE * 1024);
// возвращаем false для вывода буфера
return false;
} | php | public static function fatalErrorHandler($output)
{
// Освобождает резервный буфер
unset($GLOBALS['ERESUS_MEMORY_OVERFLOW_BUFFER']);
if (preg_match('/(parse|fatal) error:.*in .* on line/Ui', $output, $m))
{
$GLOBALS['ERESUS_CORE_FATAL_ERROR_HANDLER'] = true;
switch (strtolower($m[1]))
{
case 'fatal':
$message = 'FATAL ERROR';
break;
case 'parse':
$message = 'PARSE ERROR';
break;
default:
$message = 'ERROR:';
}
self::log(__FUNCTION__, LOG_CRIT, trim($output));
if (!self::isCLI())
{
header('Internal Server Error', true, 500);
header('Content-type: text/plain', true);
}
return $message . "\nSee application log for more info.\n";
}
$GLOBALS['ERESUS_MEMORY_OVERFLOW_BUFFER'] =
str_repeat('x', self::MEMORY_OVERFLOW_BUFFER_SIZE * 1024);
// возвращаем false для вывода буфера
return false;
} | [
"public",
"static",
"function",
"fatalErrorHandler",
"(",
"$",
"output",
")",
"{",
"// Освобождает резервный буфер",
"unset",
"(",
"$",
"GLOBALS",
"[",
"'ERESUS_MEMORY_OVERFLOW_BUFFER'",
"]",
")",
";",
"if",
"(",
"preg_match",
"(",
"'/(parse|fatal) error:.*in .* on line/Ui'",
",",
"$",
"output",
",",
"$",
"m",
")",
")",
"{",
"$",
"GLOBALS",
"[",
"'ERESUS_CORE_FATAL_ERROR_HANDLER'",
"]",
"=",
"true",
";",
"switch",
"(",
"strtolower",
"(",
"$",
"m",
"[",
"1",
"]",
")",
")",
"{",
"case",
"'fatal'",
":",
"$",
"message",
"=",
"'FATAL ERROR'",
";",
"break",
";",
"case",
"'parse'",
":",
"$",
"message",
"=",
"'PARSE ERROR'",
";",
"break",
";",
"default",
":",
"$",
"message",
"=",
"'ERROR:'",
";",
"}",
"self",
"::",
"log",
"(",
"__FUNCTION__",
",",
"LOG_CRIT",
",",
"trim",
"(",
"$",
"output",
")",
")",
";",
"if",
"(",
"!",
"self",
"::",
"isCLI",
"(",
")",
")",
"{",
"header",
"(",
"'Internal Server Error'",
",",
"true",
",",
"500",
")",
";",
"header",
"(",
"'Content-type: text/plain'",
",",
"true",
")",
";",
"}",
"return",
"$",
"message",
".",
"\"\\nSee application log for more info.\\n\"",
";",
"}",
"$",
"GLOBALS",
"[",
"'ERESUS_MEMORY_OVERFLOW_BUFFER'",
"]",
"=",
"str_repeat",
"(",
"'x'",
",",
"self",
"::",
"MEMORY_OVERFLOW_BUFFER_SIZE",
"*",
"1024",
")",
";",
"// возвращаем false для вывода буфера",
"return",
"false",
";",
"}"
] | Обработчик фатальных ошибок
Этот обработчик пытается перехватывать сообщения о фатальных ошибках, недоступных при
использовании {@link set_error_handler() set_error_handler()}. Это делается через обработчик
{@link ob_start() ob_start()}, устанавливаемый в методе {@link initExceptionHandling()}.
<i>Замечание по производительности</i>: этот метод освобождает в начале и выделяет в конце
своей работы буфер в памяти для отлова ошибок переполнения памяти. Эти операции затормаживают
вывод примерно на 1-2%.
@param string $output содержимое буфера вывода
@return string|bool
@since 3.00
@uses Eresus_Logger::log | [
"Обработчик",
"фатальных",
"ошибок"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/Kernel.php#L285-L318 |
Eresus/EresusCMS | src/core/Kernel.php | Eresus_Kernel.autoload | public static function autoload($className)
{
/*
* Классы Eresus
*/
if (stripos($className, 'Eresus_') === 0)
{
$fileName = dirname(__FILE__) . DIRECTORY_SEPARATOR .
str_replace('_', DIRECTORY_SEPARATOR, substr($className, 7)) . '.php';
if (file_exists($fileName))
{
/** @noinspection PhpIncludeInspection */
include $fileName;
return self::classExists($className);
}
/*
* Doctrine при загрузке сущностей ищет необязательный класс с суффиксом «Table».
* Отсутствие такого класса не является ошибкой. Отсутствие любого другого класса расцениваем
* как логическую ошибку.
*/
elseif (substr($className, -5) !== 'Table')
{
throw new LogicException('Class "' . $className . '" not found');
}
}
/*
* Классы Botobor
*/
if (stripos($className, 'Botobor') === 0)
{
$fileName = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'botobor' . DIRECTORY_SEPARATOR .
'botobor.php';
if (file_exists($fileName))
{
/** @noinspection PhpIncludeInspection */
include $fileName;
return self::classExists($className);
}
}
return false;
} | php | public static function autoload($className)
{
/*
* Классы Eresus
*/
if (stripos($className, 'Eresus_') === 0)
{
$fileName = dirname(__FILE__) . DIRECTORY_SEPARATOR .
str_replace('_', DIRECTORY_SEPARATOR, substr($className, 7)) . '.php';
if (file_exists($fileName))
{
/** @noinspection PhpIncludeInspection */
include $fileName;
return self::classExists($className);
}
/*
* Doctrine при загрузке сущностей ищет необязательный класс с суффиксом «Table».
* Отсутствие такого класса не является ошибкой. Отсутствие любого другого класса расцениваем
* как логическую ошибку.
*/
elseif (substr($className, -5) !== 'Table')
{
throw new LogicException('Class "' . $className . '" not found');
}
}
/*
* Классы Botobor
*/
if (stripos($className, 'Botobor') === 0)
{
$fileName = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'botobor' . DIRECTORY_SEPARATOR .
'botobor.php';
if (file_exists($fileName))
{
/** @noinspection PhpIncludeInspection */
include $fileName;
return self::classExists($className);
}
}
return false;
} | [
"public",
"static",
"function",
"autoload",
"(",
"$",
"className",
")",
"{",
"/*\n * Классы Eresus\n */",
"if",
"(",
"stripos",
"(",
"$",
"className",
",",
"'Eresus_'",
")",
"===",
"0",
")",
"{",
"$",
"fileName",
"=",
"dirname",
"(",
"__FILE__",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"str_replace",
"(",
"'_'",
",",
"DIRECTORY_SEPARATOR",
",",
"substr",
"(",
"$",
"className",
",",
"7",
")",
")",
".",
"'.php'",
";",
"if",
"(",
"file_exists",
"(",
"$",
"fileName",
")",
")",
"{",
"/** @noinspection PhpIncludeInspection */",
"include",
"$",
"fileName",
";",
"return",
"self",
"::",
"classExists",
"(",
"$",
"className",
")",
";",
"}",
"/*\n * Doctrine при загрузке сущностей ищет необязательный класс с суффиксом «Table».\n * Отсутствие такого класса не является ошибкой. Отсутствие любого другого класса расцениваем\n * как логическую ошибку.\n */",
"elseif",
"(",
"substr",
"(",
"$",
"className",
",",
"-",
"5",
")",
"!==",
"'Table'",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"'Class \"'",
".",
"$",
"className",
".",
"'\" not found'",
")",
";",
"}",
"}",
"/*\n * Классы Botobor\n */",
"if",
"(",
"stripos",
"(",
"$",
"className",
",",
"'Botobor'",
")",
"===",
"0",
")",
"{",
"$",
"fileName",
"=",
"dirname",
"(",
"__FILE__",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"'botobor'",
".",
"DIRECTORY_SEPARATOR",
".",
"'botobor.php'",
";",
"if",
"(",
"file_exists",
"(",
"$",
"fileName",
")",
")",
"{",
"/** @noinspection PhpIncludeInspection */",
"include",
"$",
"fileName",
";",
"return",
"self",
"::",
"classExists",
"(",
"$",
"className",
")",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Автозагрузчик классов
Работает только для классов «Eresus_*». Из имени класса удаляется префикс «Eresus_», все
символы в имени класса «_» заменяются на разделитель директорий, добавляется суффикс «.php».
Таким образом класс «Eresus_HTTP_Request» будет искаться в файле «core/HTTP/Request.php».
Устанавливается через {@link spl_autoload_register() spl_autoload_register()} в методе
{@link init()}.
@param string $className
@throws LogicException если класс не найден
@return bool
@since 3.00
@uses classExists() | [
"Автозагрузчик",
"классов"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/Kernel.php#L340-L384 |
Eresus/EresusCMS | src/core/Kernel.php | Eresus_Kernel.exec | public static function exec($class)
{
if (!class_exists($class))
{
throw new LogicException('Application class "' . $class . '" does not exists');
}
self::$app = new $class();
if (!method_exists($class, 'main'))
{
self::$app = null;
throw new LogicException('Method "main()" does not exists in "' . $class . '"');
}
try
{
self::log(__METHOD__, LOG_DEBUG, 'executing %s', $class);
$exitCode = self::$app->main();
self::log(__METHOD__, LOG_DEBUG, '%s done with code: %d', $class, $exitCode);
}
catch (Eresus_SuccessException $e)
{
$exitCode = 0;
}
catch (Exception $e)
{
//self::handleException($e);
$exitCode = $e->getCode() ? $e->getCode() : 0xFFFF;
}
self::$app = null;
return $exitCode;
} | php | public static function exec($class)
{
if (!class_exists($class))
{
throw new LogicException('Application class "' . $class . '" does not exists');
}
self::$app = new $class();
if (!method_exists($class, 'main'))
{
self::$app = null;
throw new LogicException('Method "main()" does not exists in "' . $class . '"');
}
try
{
self::log(__METHOD__, LOG_DEBUG, 'executing %s', $class);
$exitCode = self::$app->main();
self::log(__METHOD__, LOG_DEBUG, '%s done with code: %d', $class, $exitCode);
}
catch (Eresus_SuccessException $e)
{
$exitCode = 0;
}
catch (Exception $e)
{
//self::handleException($e);
$exitCode = $e->getCode() ? $e->getCode() : 0xFFFF;
}
self::$app = null;
return $exitCode;
} | [
"public",
"static",
"function",
"exec",
"(",
"$",
"class",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"'Application class \"'",
".",
"$",
"class",
".",
"'\" does not exists'",
")",
";",
"}",
"self",
"::",
"$",
"app",
"=",
"new",
"$",
"class",
"(",
")",
";",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"class",
",",
"'main'",
")",
")",
"{",
"self",
"::",
"$",
"app",
"=",
"null",
";",
"throw",
"new",
"LogicException",
"(",
"'Method \"main()\" does not exists in \"'",
".",
"$",
"class",
".",
"'\"'",
")",
";",
"}",
"try",
"{",
"self",
"::",
"log",
"(",
"__METHOD__",
",",
"LOG_DEBUG",
",",
"'executing %s'",
",",
"$",
"class",
")",
";",
"$",
"exitCode",
"=",
"self",
"::",
"$",
"app",
"->",
"main",
"(",
")",
";",
"self",
"::",
"log",
"(",
"__METHOD__",
",",
"LOG_DEBUG",
",",
"'%s done with code: %d'",
",",
"$",
"class",
",",
"$",
"exitCode",
")",
";",
"}",
"catch",
"(",
"Eresus_SuccessException",
"$",
"e",
")",
"{",
"$",
"exitCode",
"=",
"0",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"//self::handleException($e);",
"$",
"exitCode",
"=",
"$",
"e",
"->",
"getCode",
"(",
")",
"?",
"$",
"e",
"->",
"getCode",
"(",
")",
":",
"0xFFFF",
";",
"}",
"self",
"::",
"$",
"app",
"=",
"null",
";",
"return",
"$",
"exitCode",
";",
"}"
] | Создаёт экземпляр приложения и выполняет его
Класс приложения должен содержать публичный метод main(), который будет вызван после создания
экземпляра класса.
@param string $class имя класса приложения
@throws LogicException если класс $class не найден или не содержит метода «main()»
@return int код завершения (0 — успешное завершение)
@since 3.00
@see $app, app() | [
"Создаёт",
"экземпляр",
"приложения",
"и",
"выполняет",
"его"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/Kernel.php#L492-L524 |
Eresus/EresusCMS | src/core/Kernel.php | Eresus_Kernel.initExceptionHandling | private static function initExceptionHandling()
{
/* Резервируем буфер на случай переполнения памяти */
$GLOBALS['ERESUS_MEMORY_OVERFLOW_BUFFER'] =
str_repeat('x', self::MEMORY_OVERFLOW_BUFFER_SIZE * 1024);
/* Меняем значения php.ini */
ini_set('html_errors', 0); // Немного косметики
set_error_handler(array('Eresus_Kernel', 'errorHandler'));
self::log(__METHOD__, LOG_DEBUG, 'Error handler installed');
/*
* В PHP нет стандартных методов для перехвата некоторых типов ошибок (например E_PARSE или
* E_ERROR), однако способ всё же есть — зарегистрировать функцию через ob_start.
* Но только не в режиме CLI.
*/
if (!self::isCLI())
{
if (ob_start(array('Eresus_Kernel', 'fatalErrorHandler'), 4096))
{
self::log(__METHOD__, LOG_DEBUG, 'Fatal error handler installed');
}
else
{
self::log( __METHOD__, LOG_NOTICE,
'Fatal error handler not installed! Fatal error will be not handled!');
}
}
} | php | private static function initExceptionHandling()
{
/* Резервируем буфер на случай переполнения памяти */
$GLOBALS['ERESUS_MEMORY_OVERFLOW_BUFFER'] =
str_repeat('x', self::MEMORY_OVERFLOW_BUFFER_SIZE * 1024);
/* Меняем значения php.ini */
ini_set('html_errors', 0); // Немного косметики
set_error_handler(array('Eresus_Kernel', 'errorHandler'));
self::log(__METHOD__, LOG_DEBUG, 'Error handler installed');
/*
* В PHP нет стандартных методов для перехвата некоторых типов ошибок (например E_PARSE или
* E_ERROR), однако способ всё же есть — зарегистрировать функцию через ob_start.
* Но только не в режиме CLI.
*/
if (!self::isCLI())
{
if (ob_start(array('Eresus_Kernel', 'fatalErrorHandler'), 4096))
{
self::log(__METHOD__, LOG_DEBUG, 'Fatal error handler installed');
}
else
{
self::log( __METHOD__, LOG_NOTICE,
'Fatal error handler not installed! Fatal error will be not handled!');
}
}
} | [
"private",
"static",
"function",
"initExceptionHandling",
"(",
")",
"{",
"/* Резервируем буфер на случай переполнения памяти */",
"$",
"GLOBALS",
"[",
"'ERESUS_MEMORY_OVERFLOW_BUFFER'",
"]",
"=",
"str_repeat",
"(",
"'x'",
",",
"self",
"::",
"MEMORY_OVERFLOW_BUFFER_SIZE",
"*",
"1024",
")",
";",
"/* Меняем значения php.ini */",
"ini_set",
"(",
"'html_errors'",
",",
"0",
")",
";",
"// Немного косметики",
"set_error_handler",
"(",
"array",
"(",
"'Eresus_Kernel'",
",",
"'errorHandler'",
")",
")",
";",
"self",
"::",
"log",
"(",
"__METHOD__",
",",
"LOG_DEBUG",
",",
"'Error handler installed'",
")",
";",
"/*\n * В PHP нет стандартных методов для перехвата некоторых типов ошибок (например E_PARSE или\n * E_ERROR), однако способ всё же есть — зарегистрировать функцию через ob_start.\n * Но только не в режиме CLI.\n */",
"if",
"(",
"!",
"self",
"::",
"isCLI",
"(",
")",
")",
"{",
"if",
"(",
"ob_start",
"(",
"array",
"(",
"'Eresus_Kernel'",
",",
"'fatalErrorHandler'",
")",
",",
"4096",
")",
")",
"{",
"self",
"::",
"log",
"(",
"__METHOD__",
",",
"LOG_DEBUG",
",",
"'Fatal error handler installed'",
")",
";",
"}",
"else",
"{",
"self",
"::",
"log",
"(",
"__METHOD__",
",",
"LOG_NOTICE",
",",
"'Fatal error handler not installed! Fatal error will be not handled!'",
")",
";",
"}",
"}",
"}"
] | Инициализирует обработчики ошибок
Этот метод:
1. резервирует в памяти буфер, освобождаемый для обработки ошибок нехватки памяти;
2. отключает HTML-оформление стандартных сообщений об ошибках;
3. регистрирует {@link errorHandler()};
4. регистрирует {@link fatalErrorHandler()}.
@return void
@since 3.00
@uses Eresus_Logger::log() | [
"Инициализирует",
"обработчики",
"ошибок"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/Kernel.php#L559-L588 |
php-lug/lug | src/Bundle/GridBundle/Batch/Type/DeleteType.php | DeleteType.batch | public function batch($data, array $options)
{
if (!is_array($data) && !$data instanceof \Traversable) {
return;
}
$grid = $options['grid'];
$domainManager = $this->domainManagerRegistry[$grid->getResource()->getName()];
$api = $this->parameterResolver->resolveApi();
foreach ($data as $object) {
try {
$domainManager->delete($object, !$api);
} catch (DomainException $e) {
if ($api) {
throw $e;
}
}
}
if ($api) {
$domainManager->flush();
}
} | php | public function batch($data, array $options)
{
if (!is_array($data) && !$data instanceof \Traversable) {
return;
}
$grid = $options['grid'];
$domainManager = $this->domainManagerRegistry[$grid->getResource()->getName()];
$api = $this->parameterResolver->resolveApi();
foreach ($data as $object) {
try {
$domainManager->delete($object, !$api);
} catch (DomainException $e) {
if ($api) {
throw $e;
}
}
}
if ($api) {
$domainManager->flush();
}
} | [
"public",
"function",
"batch",
"(",
"$",
"data",
",",
"array",
"$",
"options",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
")",
"&&",
"!",
"$",
"data",
"instanceof",
"\\",
"Traversable",
")",
"{",
"return",
";",
"}",
"$",
"grid",
"=",
"$",
"options",
"[",
"'grid'",
"]",
";",
"$",
"domainManager",
"=",
"$",
"this",
"->",
"domainManagerRegistry",
"[",
"$",
"grid",
"->",
"getResource",
"(",
")",
"->",
"getName",
"(",
")",
"]",
";",
"$",
"api",
"=",
"$",
"this",
"->",
"parameterResolver",
"->",
"resolveApi",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"object",
")",
"{",
"try",
"{",
"$",
"domainManager",
"->",
"delete",
"(",
"$",
"object",
",",
"!",
"$",
"api",
")",
";",
"}",
"catch",
"(",
"DomainException",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"api",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"api",
")",
"{",
"$",
"domainManager",
"->",
"flush",
"(",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/GridBundle/Batch/Type/DeleteType.php#L49-L72 |
geocoder-php/GeocoderServiceProvider | src/Geocoder/Provider/GeocoderServiceProvider.php | GeocoderServiceProvider.register | public function register(Container $app)
{
$this->injectServices($app);
if (isset($app['profiler'])) {
$this->injectDataCollector($app);
}
} | php | public function register(Container $app)
{
$this->injectServices($app);
if (isset($app['profiler'])) {
$this->injectDataCollector($app);
}
} | [
"public",
"function",
"register",
"(",
"Container",
"$",
"app",
")",
"{",
"$",
"this",
"->",
"injectServices",
"(",
"$",
"app",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"app",
"[",
"'profiler'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"injectDataCollector",
"(",
"$",
"app",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/geocoder-php/GeocoderServiceProvider/blob/9bb850f5ac881b4d317d569c87e0573faa69e4bb/src/Geocoder/Provider/GeocoderServiceProvider.php#L19-L26 |
geocoder-php/GeocoderServiceProvider | src/Geocoder/Provider/GeocoderServiceProvider.php | GeocoderServiceProvider.injectServices | protected function injectServices(Container $app)
{
if (isset($app['profiler'])) {
$app['geocoder.logger'] = function($app) {
return new \Geocoder\Logger\GeocoderLogger();
};
$app['geocoder'] = function($app) {
$geocoder = new \Geocoder\LoggableGeocoder();
$geocoder->setLogger($app['geocoder.logger']);
$geocoder->registerProvider($app['geocoder.provider']);
return $geocoder;
};
} else {
$app['geocoder'] = function($app) {
$geocoder = new \Geocoder\Geocoder();
$geocoder->registerProvider($app['geocoder.provider']);
return $geocoder;
};
}
$app['geocoder.provider'] = function($app) {
return new \Geocoder\Provider\FreeGeoIpProvider($app['geocoder.adapter']);
};
$app['geocoder.adapter'] = function($app) {
return new \Geocoder\HttpAdapter\CurlHttpAdapter();
};
} | php | protected function injectServices(Container $app)
{
if (isset($app['profiler'])) {
$app['geocoder.logger'] = function($app) {
return new \Geocoder\Logger\GeocoderLogger();
};
$app['geocoder'] = function($app) {
$geocoder = new \Geocoder\LoggableGeocoder();
$geocoder->setLogger($app['geocoder.logger']);
$geocoder->registerProvider($app['geocoder.provider']);
return $geocoder;
};
} else {
$app['geocoder'] = function($app) {
$geocoder = new \Geocoder\Geocoder();
$geocoder->registerProvider($app['geocoder.provider']);
return $geocoder;
};
}
$app['geocoder.provider'] = function($app) {
return new \Geocoder\Provider\FreeGeoIpProvider($app['geocoder.adapter']);
};
$app['geocoder.adapter'] = function($app) {
return new \Geocoder\HttpAdapter\CurlHttpAdapter();
};
} | [
"protected",
"function",
"injectServices",
"(",
"Container",
"$",
"app",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"app",
"[",
"'profiler'",
"]",
")",
")",
"{",
"$",
"app",
"[",
"'geocoder.logger'",
"]",
"=",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"\\",
"Geocoder",
"\\",
"Logger",
"\\",
"GeocoderLogger",
"(",
")",
";",
"}",
";",
"$",
"app",
"[",
"'geocoder'",
"]",
"=",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"geocoder",
"=",
"new",
"\\",
"Geocoder",
"\\",
"LoggableGeocoder",
"(",
")",
";",
"$",
"geocoder",
"->",
"setLogger",
"(",
"$",
"app",
"[",
"'geocoder.logger'",
"]",
")",
";",
"$",
"geocoder",
"->",
"registerProvider",
"(",
"$",
"app",
"[",
"'geocoder.provider'",
"]",
")",
";",
"return",
"$",
"geocoder",
";",
"}",
";",
"}",
"else",
"{",
"$",
"app",
"[",
"'geocoder'",
"]",
"=",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"geocoder",
"=",
"new",
"\\",
"Geocoder",
"\\",
"Geocoder",
"(",
")",
";",
"$",
"geocoder",
"->",
"registerProvider",
"(",
"$",
"app",
"[",
"'geocoder.provider'",
"]",
")",
";",
"return",
"$",
"geocoder",
";",
"}",
";",
"}",
"$",
"app",
"[",
"'geocoder.provider'",
"]",
"=",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"\\",
"Geocoder",
"\\",
"Provider",
"\\",
"FreeGeoIpProvider",
"(",
"$",
"app",
"[",
"'geocoder.adapter'",
"]",
")",
";",
"}",
";",
"$",
"app",
"[",
"'geocoder.adapter'",
"]",
"=",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"\\",
"Geocoder",
"\\",
"HttpAdapter",
"\\",
"CurlHttpAdapter",
"(",
")",
";",
"}",
";",
"}"
] | Injects Geocoder related services in the application. | [
"Injects",
"Geocoder",
"related",
"services",
"in",
"the",
"application",
"."
] | train | https://github.com/geocoder-php/GeocoderServiceProvider/blob/9bb850f5ac881b4d317d569c87e0573faa69e4bb/src/Geocoder/Provider/GeocoderServiceProvider.php#L31-L61 |
geocoder-php/GeocoderServiceProvider | src/Geocoder/Provider/GeocoderServiceProvider.php | GeocoderServiceProvider.injectDataCollector | protected function injectDataCollector(Container $app)
{
$app['data_collector.templates'] = $app->extend('data_collector.templates', function ($templates) {
$templates[] = ['geocoder', '@Geocoder/Collector/geocoder.html.twig'];
return $templates;
});
$app['data_collectors'] = $app->extend('data_collectors', function ($dataCollectors) {
$dataCollectors['geocoder'] = function ($app) { return new GeocoderDataCollector($app['geocoder.logger']); };
return $dataCollectors;
});
$app['twig.loader.filesystem'] = $app->extend('twig.loader.filesystem', function ($loader, $app) {
$loader->addPath($app['geocoder.templates_path'], 'Geocoder');
return $loader;
});
$app['geocoder.templates_path'] = function () {
$r = new \ReflectionClass('Geocoder\Provider\GeocoderServiceProvider');
return dirname(dirname($r->getFileName())).'/../../views';
};
} | php | protected function injectDataCollector(Container $app)
{
$app['data_collector.templates'] = $app->extend('data_collector.templates', function ($templates) {
$templates[] = ['geocoder', '@Geocoder/Collector/geocoder.html.twig'];
return $templates;
});
$app['data_collectors'] = $app->extend('data_collectors', function ($dataCollectors) {
$dataCollectors['geocoder'] = function ($app) { return new GeocoderDataCollector($app['geocoder.logger']); };
return $dataCollectors;
});
$app['twig.loader.filesystem'] = $app->extend('twig.loader.filesystem', function ($loader, $app) {
$loader->addPath($app['geocoder.templates_path'], 'Geocoder');
return $loader;
});
$app['geocoder.templates_path'] = function () {
$r = new \ReflectionClass('Geocoder\Provider\GeocoderServiceProvider');
return dirname(dirname($r->getFileName())).'/../../views';
};
} | [
"protected",
"function",
"injectDataCollector",
"(",
"Container",
"$",
"app",
")",
"{",
"$",
"app",
"[",
"'data_collector.templates'",
"]",
"=",
"$",
"app",
"->",
"extend",
"(",
"'data_collector.templates'",
",",
"function",
"(",
"$",
"templates",
")",
"{",
"$",
"templates",
"[",
"]",
"=",
"[",
"'geocoder'",
",",
"'@Geocoder/Collector/geocoder.html.twig'",
"]",
";",
"return",
"$",
"templates",
";",
"}",
")",
";",
"$",
"app",
"[",
"'data_collectors'",
"]",
"=",
"$",
"app",
"->",
"extend",
"(",
"'data_collectors'",
",",
"function",
"(",
"$",
"dataCollectors",
")",
"{",
"$",
"dataCollectors",
"[",
"'geocoder'",
"]",
"=",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"GeocoderDataCollector",
"(",
"$",
"app",
"[",
"'geocoder.logger'",
"]",
")",
";",
"}",
";",
"return",
"$",
"dataCollectors",
";",
"}",
")",
";",
"$",
"app",
"[",
"'twig.loader.filesystem'",
"]",
"=",
"$",
"app",
"->",
"extend",
"(",
"'twig.loader.filesystem'",
",",
"function",
"(",
"$",
"loader",
",",
"$",
"app",
")",
"{",
"$",
"loader",
"->",
"addPath",
"(",
"$",
"app",
"[",
"'geocoder.templates_path'",
"]",
",",
"'Geocoder'",
")",
";",
"return",
"$",
"loader",
";",
"}",
")",
";",
"$",
"app",
"[",
"'geocoder.templates_path'",
"]",
"=",
"function",
"(",
")",
"{",
"$",
"r",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"'Geocoder\\Provider\\GeocoderServiceProvider'",
")",
";",
"return",
"dirname",
"(",
"dirname",
"(",
"$",
"r",
"->",
"getFileName",
"(",
")",
")",
")",
".",
"'/../../views'",
";",
"}",
";",
"}"
] | Injects Geocoder's data collector in the profiler | [
"Injects",
"Geocoder",
"s",
"data",
"collector",
"in",
"the",
"profiler"
] | train | https://github.com/geocoder-php/GeocoderServiceProvider/blob/9bb850f5ac881b4d317d569c87e0573faa69e4bb/src/Geocoder/Provider/GeocoderServiceProvider.php#L66-L91 |
ouropencode/dachi | src/Collections.php | Collections.asArray | public static function asArray($collection, $safe = false, $eager = false) {
$elements = array();
foreach($collection as $key => $element)
$elements[] = $element->asArray($safe, $eager);
return $elements;
} | php | public static function asArray($collection, $safe = false, $eager = false) {
$elements = array();
foreach($collection as $key => $element)
$elements[] = $element->asArray($safe, $eager);
return $elements;
} | [
"public",
"static",
"function",
"asArray",
"(",
"$",
"collection",
",",
"$",
"safe",
"=",
"false",
",",
"$",
"eager",
"=",
"false",
")",
"{",
"$",
"elements",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"collection",
"as",
"$",
"key",
"=>",
"$",
"element",
")",
"$",
"elements",
"[",
"]",
"=",
"$",
"element",
"->",
"asArray",
"(",
"$",
"safe",
",",
"$",
"eager",
")",
";",
"return",
"$",
"elements",
";",
"}"
] | Retrieve all the Collections's data in an array
Models should implement this method themselves and provide the required
data. Models can omit this, it just means you can't use it.
@param ArrayCollection $collection The collection to operate upon
@param bool $safe Should we return only data we consider "publicly exposable"?
@param bool $eager Should we eager load child data?
@return array | [
"Retrieve",
"all",
"the",
"Collections",
"s",
"data",
"in",
"an",
"array"
] | train | https://github.com/ouropencode/dachi/blob/a0e1daf269d0345afbb859ce20ef9da6decd7efe/src/Collections.php#L26-L33 |
HedronDev/hedron | src/Command/CommandStack.php | CommandStack.execute | public function execute() {
$this->output->writeln('<info>' . shell_exec(implode('; ', $this->commands)) . '</info>');
$this->commands = [];
} | php | public function execute() {
$this->output->writeln('<info>' . shell_exec(implode('; ', $this->commands)) . '</info>');
$this->commands = [];
} | [
"public",
"function",
"execute",
"(",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"'<info>'",
".",
"shell_exec",
"(",
"implode",
"(",
"'; '",
",",
"$",
"this",
"->",
"commands",
")",
")",
".",
"'</info>'",
")",
";",
"$",
"this",
"->",
"commands",
"=",
"[",
"]",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/HedronDev/hedron/blob/3b4adec4912f2d7c0b7e7262dc36515fbc2e8e00/src/Command/CommandStack.php#L39-L42 |
webdevvie/pheanstalk-task-queue-bundle | Command/TaskCleanupCommand.php | TaskCleanupCommand.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
$this->initialiseWorker($input, $output);
$timePeriod = $input->getOption('period');
$this->taskQueueService->cleanUpTasks($timePeriod);
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
$this->initialiseWorker($input, $output);
$timePeriod = $input->getOption('period');
$this->taskQueueService->cleanUpTasks($timePeriod);
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"this",
"->",
"initialiseWorker",
"(",
"$",
"input",
",",
"$",
"output",
")",
";",
"$",
"timePeriod",
"=",
"$",
"input",
"->",
"getOption",
"(",
"'period'",
")",
";",
"$",
"this",
"->",
"taskQueueService",
"->",
"cleanUpTasks",
"(",
"$",
"timePeriod",
")",
";",
"}"
] | {@inheritDoc}
@param InputInterface $input
@param OutputInterface $output
@return void
@throws \InvalidArgumentException | [
"{",
"@inheritDoc",
"}"
] | train | https://github.com/webdevvie/pheanstalk-task-queue-bundle/blob/db5e63a8f844e345dc2e69ce8e94b32d851020eb/Command/TaskCleanupCommand.php#L46-L51 |
SporkCode/Spork | src/ServiceManager/ClassAbstractFactory.php | ClassAbstractFactory.canCreateServiceWithName | public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
{
$config = $serviceLocator->get('config');
$class = $this->getClass($config, $requestedName);
return $class && class_exists($class);
} | php | public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
{
$config = $serviceLocator->get('config');
$class = $this->getClass($config, $requestedName);
return $class && class_exists($class);
} | [
"public",
"function",
"canCreateServiceWithName",
"(",
"ServiceLocatorInterface",
"$",
"serviceLocator",
",",
"$",
"name",
",",
"$",
"requestedName",
")",
"{",
"$",
"config",
"=",
"$",
"serviceLocator",
"->",
"get",
"(",
"'config'",
")",
";",
"$",
"class",
"=",
"$",
"this",
"->",
"getClass",
"(",
"$",
"config",
",",
"$",
"requestedName",
")",
";",
"return",
"$",
"class",
"&&",
"class_exists",
"(",
"$",
"class",
")",
";",
"}"
] | Test if configuration exists and has class field
@see \Zend\ServiceManager\AbstractFactoryInterface::canCreateServiceWithName()
@param ServiceLocatorInterface $serviceLocator
@param string $name
@param string $requestedName
@return boolean | [
"Test",
"if",
"configuration",
"exists",
"and",
"has",
"class",
"field"
] | train | https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/ServiceManager/ClassAbstractFactory.php#L29-L34 |
SporkCode/Spork | src/ServiceManager/ClassAbstractFactory.php | ClassAbstractFactory.createServiceWithName | public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
{
$config = $serviceLocator->get('config');
$class = $this->getClass($config, $requestedName);
return new $class($config[$requestedName]);
} | php | public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
{
$config = $serviceLocator->get('config');
$class = $this->getClass($config, $requestedName);
return new $class($config[$requestedName]);
} | [
"public",
"function",
"createServiceWithName",
"(",
"ServiceLocatorInterface",
"$",
"serviceLocator",
",",
"$",
"name",
",",
"$",
"requestedName",
")",
"{",
"$",
"config",
"=",
"$",
"serviceLocator",
"->",
"get",
"(",
"'config'",
")",
";",
"$",
"class",
"=",
"$",
"this",
"->",
"getClass",
"(",
"$",
"config",
",",
"$",
"requestedName",
")",
";",
"return",
"new",
"$",
"class",
"(",
"$",
"config",
"[",
"$",
"requestedName",
"]",
")",
";",
"}"
] | Create and configure class by creating new instance of class from
configuration
@see \Zend\ServiceManager\AbstractFactoryInterface::createServiceWithName()
@param ServiceLocatorInterface $serviceLocator
@param string $name
@param string $requestedName
@return mixed | [
"Create",
"and",
"configure",
"class",
"by",
"creating",
"new",
"instance",
"of",
"class",
"from",
"configuration"
] | train | https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/ServiceManager/ClassAbstractFactory.php#L46-L51 |
SporkCode/Spork | src/ServiceManager/ClassAbstractFactory.php | ClassAbstractFactory.getClass | protected function getClass($config, $name)
{
if (array_key_exists($name, $config)
&& is_array($config[$name])
&& array_key_exists('class', $config[$name])
&& is_scalar($config[$name]['class'])) {
return $config[$name]['class'];
}
return false;
} | php | protected function getClass($config, $name)
{
if (array_key_exists($name, $config)
&& is_array($config[$name])
&& array_key_exists('class', $config[$name])
&& is_scalar($config[$name]['class'])) {
return $config[$name]['class'];
}
return false;
} | [
"protected",
"function",
"getClass",
"(",
"$",
"config",
",",
"$",
"name",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"config",
")",
"&&",
"is_array",
"(",
"$",
"config",
"[",
"$",
"name",
"]",
")",
"&&",
"array_key_exists",
"(",
"'class'",
",",
"$",
"config",
"[",
"$",
"name",
"]",
")",
"&&",
"is_scalar",
"(",
"$",
"config",
"[",
"$",
"name",
"]",
"[",
"'class'",
"]",
")",
")",
"{",
"return",
"$",
"config",
"[",
"$",
"name",
"]",
"[",
"'class'",
"]",
";",
"}",
"return",
"false",
";",
"}"
] | Look for class name in configuration
@param array $config
@param string $name
@return boolean | [
"Look",
"for",
"class",
"name",
"in",
"configuration"
] | train | https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/ServiceManager/ClassAbstractFactory.php#L60-L70 |
sciactive/nymph-server | src/Drivers/SQLite3Driver.php | SQLite3Driver.connect | public function connect() {
// Check that the SQLite3 extension is installed.
if (!class_exists('SQLite3')) {
throw new Exceptions\UnableToConnectException(
'SQLite3 PHP extension is not available. It probably has not '.
'been installed. Please install and configure it in order to use '.
'SQLite3.'
);
}
$filename = $this->config['SQLite3']['filename'];
$busyTimeout = $this->config['SQLite3']['busy_timeout'];
$openFlags = $this->config['SQLite3']['open_flags'];
$encryptionKey = $this->config['SQLite3']['encryption_key'];
// Connecting
if (!$this->connected) {
$this->link = new SQLite3($filename, $openFlags, $encryptionKey);
if ($this->link) {
$this->connected = true;
$this->link->busyTimeout($busyTimeout);
// Set database and connection options.
$this->link->exec("PRAGMA encoding = \"UTF-8\";");
$this->link->exec("PRAGMA foreign_keys = 1;");
$this->link->exec("PRAGMA case_sensitive_like = 1;");
// Create the preg_match and regexp functions.
// TODO(hperrin): Add more of these functions to get rid of post-query checks.
$this->link->createFunction('preg_match', 'preg_match', 2, SQLITE3_DETERMINISTIC);
$this->link->createFunction('regexp', function ($pattern, $subject) {
return !!$this->posixRegexMatch($pattern, $subject);
}, 2, SQLITE3_DETERMINISTIC);
} else {
$this->connected = false;
if ($filename === ':memory:') {
throw new Exceptions\NotConfiguredException();
} else {
throw new Exceptions\UnableToConnectException('Could not connect.');
}
}
}
return $this->connected;
} | php | public function connect() {
// Check that the SQLite3 extension is installed.
if (!class_exists('SQLite3')) {
throw new Exceptions\UnableToConnectException(
'SQLite3 PHP extension is not available. It probably has not '.
'been installed. Please install and configure it in order to use '.
'SQLite3.'
);
}
$filename = $this->config['SQLite3']['filename'];
$busyTimeout = $this->config['SQLite3']['busy_timeout'];
$openFlags = $this->config['SQLite3']['open_flags'];
$encryptionKey = $this->config['SQLite3']['encryption_key'];
// Connecting
if (!$this->connected) {
$this->link = new SQLite3($filename, $openFlags, $encryptionKey);
if ($this->link) {
$this->connected = true;
$this->link->busyTimeout($busyTimeout);
// Set database and connection options.
$this->link->exec("PRAGMA encoding = \"UTF-8\";");
$this->link->exec("PRAGMA foreign_keys = 1;");
$this->link->exec("PRAGMA case_sensitive_like = 1;");
// Create the preg_match and regexp functions.
// TODO(hperrin): Add more of these functions to get rid of post-query checks.
$this->link->createFunction('preg_match', 'preg_match', 2, SQLITE3_DETERMINISTIC);
$this->link->createFunction('regexp', function ($pattern, $subject) {
return !!$this->posixRegexMatch($pattern, $subject);
}, 2, SQLITE3_DETERMINISTIC);
} else {
$this->connected = false;
if ($filename === ':memory:') {
throw new Exceptions\NotConfiguredException();
} else {
throw new Exceptions\UnableToConnectException('Could not connect.');
}
}
}
return $this->connected;
} | [
"public",
"function",
"connect",
"(",
")",
"{",
"// Check that the SQLite3 extension is installed.",
"if",
"(",
"!",
"class_exists",
"(",
"'SQLite3'",
")",
")",
"{",
"throw",
"new",
"Exceptions",
"\\",
"UnableToConnectException",
"(",
"'SQLite3 PHP extension is not available. It probably has not '",
".",
"'been installed. Please install and configure it in order to use '",
".",
"'SQLite3.'",
")",
";",
"}",
"$",
"filename",
"=",
"$",
"this",
"->",
"config",
"[",
"'SQLite3'",
"]",
"[",
"'filename'",
"]",
";",
"$",
"busyTimeout",
"=",
"$",
"this",
"->",
"config",
"[",
"'SQLite3'",
"]",
"[",
"'busy_timeout'",
"]",
";",
"$",
"openFlags",
"=",
"$",
"this",
"->",
"config",
"[",
"'SQLite3'",
"]",
"[",
"'open_flags'",
"]",
";",
"$",
"encryptionKey",
"=",
"$",
"this",
"->",
"config",
"[",
"'SQLite3'",
"]",
"[",
"'encryption_key'",
"]",
";",
"// Connecting",
"if",
"(",
"!",
"$",
"this",
"->",
"connected",
")",
"{",
"$",
"this",
"->",
"link",
"=",
"new",
"SQLite3",
"(",
"$",
"filename",
",",
"$",
"openFlags",
",",
"$",
"encryptionKey",
")",
";",
"if",
"(",
"$",
"this",
"->",
"link",
")",
"{",
"$",
"this",
"->",
"connected",
"=",
"true",
";",
"$",
"this",
"->",
"link",
"->",
"busyTimeout",
"(",
"$",
"busyTimeout",
")",
";",
"// Set database and connection options.",
"$",
"this",
"->",
"link",
"->",
"exec",
"(",
"\"PRAGMA encoding = \\\"UTF-8\\\";\"",
")",
";",
"$",
"this",
"->",
"link",
"->",
"exec",
"(",
"\"PRAGMA foreign_keys = 1;\"",
")",
";",
"$",
"this",
"->",
"link",
"->",
"exec",
"(",
"\"PRAGMA case_sensitive_like = 1;\"",
")",
";",
"// Create the preg_match and regexp functions.",
"// TODO(hperrin): Add more of these functions to get rid of post-query checks.",
"$",
"this",
"->",
"link",
"->",
"createFunction",
"(",
"'preg_match'",
",",
"'preg_match'",
",",
"2",
",",
"SQLITE3_DETERMINISTIC",
")",
";",
"$",
"this",
"->",
"link",
"->",
"createFunction",
"(",
"'regexp'",
",",
"function",
"(",
"$",
"pattern",
",",
"$",
"subject",
")",
"{",
"return",
"!",
"!",
"$",
"this",
"->",
"posixRegexMatch",
"(",
"$",
"pattern",
",",
"$",
"subject",
")",
";",
"}",
",",
"2",
",",
"SQLITE3_DETERMINISTIC",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"connected",
"=",
"false",
";",
"if",
"(",
"$",
"filename",
"===",
"':memory:'",
")",
"{",
"throw",
"new",
"Exceptions",
"\\",
"NotConfiguredException",
"(",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"Exceptions",
"\\",
"UnableToConnectException",
"(",
"'Could not connect.'",
")",
";",
"}",
"}",
"}",
"return",
"$",
"this",
"->",
"connected",
";",
"}"
] | Connect to the SQLite3 database.
@return bool Whether this instance is connected to a SQLite3 database
after the method has run. | [
"Connect",
"to",
"the",
"SQLite3",
"database",
"."
] | train | https://github.com/sciactive/nymph-server/blob/3c18dbf45c2750d07c798e14534dba87387beeba/src/Drivers/SQLite3Driver.php#L47-L86 |
sciactive/nymph-server | src/Drivers/SQLite3Driver.php | SQLite3Driver.disconnect | public function disconnect() {
if ($this->connected) {
if (is_a($this->link, 'SQLite3')) {
$this->link->exec("PRAGMA optimize;");
$this->link->close();
}
$this->connected = false;
}
return $this->connected;
} | php | public function disconnect() {
if ($this->connected) {
if (is_a($this->link, 'SQLite3')) {
$this->link->exec("PRAGMA optimize;");
$this->link->close();
}
$this->connected = false;
}
return $this->connected;
} | [
"public",
"function",
"disconnect",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"connected",
")",
"{",
"if",
"(",
"is_a",
"(",
"$",
"this",
"->",
"link",
",",
"'SQLite3'",
")",
")",
"{",
"$",
"this",
"->",
"link",
"->",
"exec",
"(",
"\"PRAGMA optimize;\"",
")",
";",
"$",
"this",
"->",
"link",
"->",
"close",
"(",
")",
";",
"}",
"$",
"this",
"->",
"connected",
"=",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"connected",
";",
"}"
] | Disconnect from the SQLite3 database.
@return bool Whether this instance is connected to a SQLite3 database
after the method has run. | [
"Disconnect",
"from",
"the",
"SQLite3",
"database",
"."
] | train | https://github.com/sciactive/nymph-server/blob/3c18dbf45c2750d07c798e14534dba87387beeba/src/Drivers/SQLite3Driver.php#L94-L103 |
sciactive/nymph-server | src/Drivers/SQLite3Driver.php | SQLite3Driver.createTables | private function createTables($etype = null) {
$this->checkReadOnlyMode();
$this->query("SAVEPOINT 'tablecreation';");
try {
if (isset($etype)) {
$etype = '_'.SQLite3::escapeString($etype);
// Create the entity table.
$this->query("CREATE TABLE IF NOT EXISTS \"{$this->prefix}entities{$etype}\" (\"guid\" INTEGER PRIMARY KEY ASC NOT NULL REFERENCES \"{$this->prefix}guids\"(\"guid\") ON DELETE CASCADE, \"tags\" TEXT, \"cdate\" REAL NOT NULL, \"mdate\" REAL NOT NULL);");
$this->query("CREATE INDEX IF NOT EXISTS \"{$this->prefix}entities{$etype}_id_cdate\" ON \"{$this->prefix}entities{$etype}\" (\"cdate\");");
$this->query("CREATE INDEX IF NOT EXISTS \"{$this->prefix}entities{$etype}_id_mdate\" ON \"{$this->prefix}entities{$etype}\" (\"mdate\");");
$this->query("CREATE INDEX IF NOT EXISTS \"{$this->prefix}entities{$etype}_id_tags\" ON \"{$this->prefix}entities{$etype}\" (\"tags\");");
// Create the data table.
$this->query("CREATE TABLE IF NOT EXISTS \"{$this->prefix}data{$etype}\" (\"guid\" INTEGER NOT NULL REFERENCES \"{$this->prefix}entities{$etype}\"(\"guid\") ON DELETE CASCADE, \"name\" TEXT NOT NULL, \"value\" TEXT NOT NULL, PRIMARY KEY(\"guid\", \"name\"));");
$this->query("CREATE INDEX IF NOT EXISTS \"{$this->prefix}data{$etype}_id_guid\" ON \"{$this->prefix}data{$etype}\" (\"guid\");");
$this->query("CREATE INDEX IF NOT EXISTS \"{$this->prefix}data{$etype}_id_name\" ON \"{$this->prefix}data{$etype}\" (\"name\");");
$this->query("CREATE INDEX IF NOT EXISTS \"{$this->prefix}data{$etype}_id_value\" ON \"{$this->prefix}data{$etype}\" (\"value\");");
$this->query("CREATE INDEX IF NOT EXISTS \"{$this->prefix}data{$etype}_id_guid__name_user\" ON \"{$this->prefix}data{$etype}\" (\"guid\") WHERE \"name\" = 'user';");
$this->query("CREATE INDEX IF NOT EXISTS \"{$this->prefix}data{$etype}_id_guid__name_group\" ON \"{$this->prefix}data{$etype}\" (\"guid\") WHERE \"name\" = 'group';");
// Create the comparisons table.
$this->query("CREATE TABLE IF NOT EXISTS \"{$this->prefix}comparisons{$etype}\" (\"guid\" INTEGER NOT NULL REFERENCES \"{$this->prefix}entities{$etype}\"(\"guid\") ON DELETE CASCADE, \"name\" TEXT NOT NULL, \"eq_true\" INTEGER, \"eq_one\" INTEGER, \"eq_zero\" INTEGER, \"eq_negone\" INTEGER, \"eq_emptyarray\" INTEGER, \"string\" TEXT, \"int\" INTEGER, \"float\" REAL, \"is_int\" INTEGER, PRIMARY KEY(\"guid\", \"name\"));");
$this->query("CREATE INDEX IF NOT EXISTS \"{$this->prefix}comparisons{$etype}_id_guid\" ON \"{$this->prefix}comparisons{$etype}\" (\"guid\");");
$this->query("CREATE INDEX IF NOT EXISTS \"{$this->prefix}comparisons{$etype}_id_name\" ON \"{$this->prefix}comparisons{$etype}\" (\"name\");");
$this->query("CREATE INDEX IF NOT EXISTS \"{$this->prefix}comparisons{$etype}_id_name__eq_true\" ON \"{$this->prefix}comparisons{$etype}\" (\"name\") WHERE \"eq_true\" = 1;");
$this->query("CREATE INDEX IF NOT EXISTS \"{$this->prefix}comparisons{$etype}_id_name__not_eq_true\" ON \"{$this->prefix}comparisons{$etype}\" (\"name\") WHERE \"eq_true\" = 0;");
$this->query("CREATE INDEX IF NOT EXISTS \"{$this->prefix}comparisons{$etype}_id_int\" ON \"{$this->prefix}comparisons{$etype}\" (\"int\");");
$this->query("CREATE INDEX IF NOT EXISTS \"{$this->prefix}comparisons{$etype}_id_float\" ON \"{$this->prefix}comparisons{$etype}\" (\"float\");");
// Create the references table.
$this->query("CREATE TABLE IF NOT EXISTS \"{$this->prefix}references{$etype}\" (\"guid\" INTEGER NOT NULL REFERENCES \"{$this->prefix}entities{$etype}\"(\"guid\") ON DELETE CASCADE, \"name\" TEXT NOT NULL, \"reference\" INTEGER NOT NULL, PRIMARY KEY(\"guid\", \"name\", \"reference\"));");
$this->query("CREATE INDEX IF NOT EXISTS \"{$this->prefix}references{$etype}_id_guid\" ON \"{$this->prefix}references{$etype}\" (\"guid\");");
$this->query("CREATE INDEX IF NOT EXISTS \"{$this->prefix}references{$etype}_id_name\" ON \"{$this->prefix}references{$etype}\" (\"name\");");
$this->query("CREATE INDEX IF NOT EXISTS \"{$this->prefix}references{$etype}_id_reference\" ON \"{$this->prefix}references{$etype}\" (\"reference\");");
} else {
// Create the GUID table.
$this->query("CREATE TABLE IF NOT EXISTS \"{$this->prefix}guids\" (\"guid\" INTEGER NOT NULL PRIMARY KEY ASC);");
// Create the UID table.
$this->query("CREATE TABLE IF NOT EXISTS \"{$this->prefix}uids\" (\"name\" TEXT PRIMARY KEY NOT NULL, \"cur_uid\" INTEGER NOT NULL);");
}
} catch (\Exception $e) {
$this->query("ROLLBACK TO 'tablecreation';");
throw $e;
}
$this->query("RELEASE 'tablecreation';");
return true;
} | php | private function createTables($etype = null) {
$this->checkReadOnlyMode();
$this->query("SAVEPOINT 'tablecreation';");
try {
if (isset($etype)) {
$etype = '_'.SQLite3::escapeString($etype);
// Create the entity table.
$this->query("CREATE TABLE IF NOT EXISTS \"{$this->prefix}entities{$etype}\" (\"guid\" INTEGER PRIMARY KEY ASC NOT NULL REFERENCES \"{$this->prefix}guids\"(\"guid\") ON DELETE CASCADE, \"tags\" TEXT, \"cdate\" REAL NOT NULL, \"mdate\" REAL NOT NULL);");
$this->query("CREATE INDEX IF NOT EXISTS \"{$this->prefix}entities{$etype}_id_cdate\" ON \"{$this->prefix}entities{$etype}\" (\"cdate\");");
$this->query("CREATE INDEX IF NOT EXISTS \"{$this->prefix}entities{$etype}_id_mdate\" ON \"{$this->prefix}entities{$etype}\" (\"mdate\");");
$this->query("CREATE INDEX IF NOT EXISTS \"{$this->prefix}entities{$etype}_id_tags\" ON \"{$this->prefix}entities{$etype}\" (\"tags\");");
// Create the data table.
$this->query("CREATE TABLE IF NOT EXISTS \"{$this->prefix}data{$etype}\" (\"guid\" INTEGER NOT NULL REFERENCES \"{$this->prefix}entities{$etype}\"(\"guid\") ON DELETE CASCADE, \"name\" TEXT NOT NULL, \"value\" TEXT NOT NULL, PRIMARY KEY(\"guid\", \"name\"));");
$this->query("CREATE INDEX IF NOT EXISTS \"{$this->prefix}data{$etype}_id_guid\" ON \"{$this->prefix}data{$etype}\" (\"guid\");");
$this->query("CREATE INDEX IF NOT EXISTS \"{$this->prefix}data{$etype}_id_name\" ON \"{$this->prefix}data{$etype}\" (\"name\");");
$this->query("CREATE INDEX IF NOT EXISTS \"{$this->prefix}data{$etype}_id_value\" ON \"{$this->prefix}data{$etype}\" (\"value\");");
$this->query("CREATE INDEX IF NOT EXISTS \"{$this->prefix}data{$etype}_id_guid__name_user\" ON \"{$this->prefix}data{$etype}\" (\"guid\") WHERE \"name\" = 'user';");
$this->query("CREATE INDEX IF NOT EXISTS \"{$this->prefix}data{$etype}_id_guid__name_group\" ON \"{$this->prefix}data{$etype}\" (\"guid\") WHERE \"name\" = 'group';");
// Create the comparisons table.
$this->query("CREATE TABLE IF NOT EXISTS \"{$this->prefix}comparisons{$etype}\" (\"guid\" INTEGER NOT NULL REFERENCES \"{$this->prefix}entities{$etype}\"(\"guid\") ON DELETE CASCADE, \"name\" TEXT NOT NULL, \"eq_true\" INTEGER, \"eq_one\" INTEGER, \"eq_zero\" INTEGER, \"eq_negone\" INTEGER, \"eq_emptyarray\" INTEGER, \"string\" TEXT, \"int\" INTEGER, \"float\" REAL, \"is_int\" INTEGER, PRIMARY KEY(\"guid\", \"name\"));");
$this->query("CREATE INDEX IF NOT EXISTS \"{$this->prefix}comparisons{$etype}_id_guid\" ON \"{$this->prefix}comparisons{$etype}\" (\"guid\");");
$this->query("CREATE INDEX IF NOT EXISTS \"{$this->prefix}comparisons{$etype}_id_name\" ON \"{$this->prefix}comparisons{$etype}\" (\"name\");");
$this->query("CREATE INDEX IF NOT EXISTS \"{$this->prefix}comparisons{$etype}_id_name__eq_true\" ON \"{$this->prefix}comparisons{$etype}\" (\"name\") WHERE \"eq_true\" = 1;");
$this->query("CREATE INDEX IF NOT EXISTS \"{$this->prefix}comparisons{$etype}_id_name__not_eq_true\" ON \"{$this->prefix}comparisons{$etype}\" (\"name\") WHERE \"eq_true\" = 0;");
$this->query("CREATE INDEX IF NOT EXISTS \"{$this->prefix}comparisons{$etype}_id_int\" ON \"{$this->prefix}comparisons{$etype}\" (\"int\");");
$this->query("CREATE INDEX IF NOT EXISTS \"{$this->prefix}comparisons{$etype}_id_float\" ON \"{$this->prefix}comparisons{$etype}\" (\"float\");");
// Create the references table.
$this->query("CREATE TABLE IF NOT EXISTS \"{$this->prefix}references{$etype}\" (\"guid\" INTEGER NOT NULL REFERENCES \"{$this->prefix}entities{$etype}\"(\"guid\") ON DELETE CASCADE, \"name\" TEXT NOT NULL, \"reference\" INTEGER NOT NULL, PRIMARY KEY(\"guid\", \"name\", \"reference\"));");
$this->query("CREATE INDEX IF NOT EXISTS \"{$this->prefix}references{$etype}_id_guid\" ON \"{$this->prefix}references{$etype}\" (\"guid\");");
$this->query("CREATE INDEX IF NOT EXISTS \"{$this->prefix}references{$etype}_id_name\" ON \"{$this->prefix}references{$etype}\" (\"name\");");
$this->query("CREATE INDEX IF NOT EXISTS \"{$this->prefix}references{$etype}_id_reference\" ON \"{$this->prefix}references{$etype}\" (\"reference\");");
} else {
// Create the GUID table.
$this->query("CREATE TABLE IF NOT EXISTS \"{$this->prefix}guids\" (\"guid\" INTEGER NOT NULL PRIMARY KEY ASC);");
// Create the UID table.
$this->query("CREATE TABLE IF NOT EXISTS \"{$this->prefix}uids\" (\"name\" TEXT PRIMARY KEY NOT NULL, \"cur_uid\" INTEGER NOT NULL);");
}
} catch (\Exception $e) {
$this->query("ROLLBACK TO 'tablecreation';");
throw $e;
}
$this->query("RELEASE 'tablecreation';");
return true;
} | [
"private",
"function",
"createTables",
"(",
"$",
"etype",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"checkReadOnlyMode",
"(",
")",
";",
"$",
"this",
"->",
"query",
"(",
"\"SAVEPOINT 'tablecreation';\"",
")",
";",
"try",
"{",
"if",
"(",
"isset",
"(",
"$",
"etype",
")",
")",
"{",
"$",
"etype",
"=",
"'_'",
".",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"etype",
")",
";",
"// Create the entity table.",
"$",
"this",
"->",
"query",
"(",
"\"CREATE TABLE IF NOT EXISTS \\\"{$this->prefix}entities{$etype}\\\" (\\\"guid\\\" INTEGER PRIMARY KEY ASC NOT NULL REFERENCES \\\"{$this->prefix}guids\\\"(\\\"guid\\\") ON DELETE CASCADE, \\\"tags\\\" TEXT, \\\"cdate\\\" REAL NOT NULL, \\\"mdate\\\" REAL NOT NULL);\"",
")",
";",
"$",
"this",
"->",
"query",
"(",
"\"CREATE INDEX IF NOT EXISTS \\\"{$this->prefix}entities{$etype}_id_cdate\\\" ON \\\"{$this->prefix}entities{$etype}\\\" (\\\"cdate\\\");\"",
")",
";",
"$",
"this",
"->",
"query",
"(",
"\"CREATE INDEX IF NOT EXISTS \\\"{$this->prefix}entities{$etype}_id_mdate\\\" ON \\\"{$this->prefix}entities{$etype}\\\" (\\\"mdate\\\");\"",
")",
";",
"$",
"this",
"->",
"query",
"(",
"\"CREATE INDEX IF NOT EXISTS \\\"{$this->prefix}entities{$etype}_id_tags\\\" ON \\\"{$this->prefix}entities{$etype}\\\" (\\\"tags\\\");\"",
")",
";",
"// Create the data table.",
"$",
"this",
"->",
"query",
"(",
"\"CREATE TABLE IF NOT EXISTS \\\"{$this->prefix}data{$etype}\\\" (\\\"guid\\\" INTEGER NOT NULL REFERENCES \\\"{$this->prefix}entities{$etype}\\\"(\\\"guid\\\") ON DELETE CASCADE, \\\"name\\\" TEXT NOT NULL, \\\"value\\\" TEXT NOT NULL, PRIMARY KEY(\\\"guid\\\", \\\"name\\\"));\"",
")",
";",
"$",
"this",
"->",
"query",
"(",
"\"CREATE INDEX IF NOT EXISTS \\\"{$this->prefix}data{$etype}_id_guid\\\" ON \\\"{$this->prefix}data{$etype}\\\" (\\\"guid\\\");\"",
")",
";",
"$",
"this",
"->",
"query",
"(",
"\"CREATE INDEX IF NOT EXISTS \\\"{$this->prefix}data{$etype}_id_name\\\" ON \\\"{$this->prefix}data{$etype}\\\" (\\\"name\\\");\"",
")",
";",
"$",
"this",
"->",
"query",
"(",
"\"CREATE INDEX IF NOT EXISTS \\\"{$this->prefix}data{$etype}_id_value\\\" ON \\\"{$this->prefix}data{$etype}\\\" (\\\"value\\\");\"",
")",
";",
"$",
"this",
"->",
"query",
"(",
"\"CREATE INDEX IF NOT EXISTS \\\"{$this->prefix}data{$etype}_id_guid__name_user\\\" ON \\\"{$this->prefix}data{$etype}\\\" (\\\"guid\\\") WHERE \\\"name\\\" = 'user';\"",
")",
";",
"$",
"this",
"->",
"query",
"(",
"\"CREATE INDEX IF NOT EXISTS \\\"{$this->prefix}data{$etype}_id_guid__name_group\\\" ON \\\"{$this->prefix}data{$etype}\\\" (\\\"guid\\\") WHERE \\\"name\\\" = 'group';\"",
")",
";",
"// Create the comparisons table.",
"$",
"this",
"->",
"query",
"(",
"\"CREATE TABLE IF NOT EXISTS \\\"{$this->prefix}comparisons{$etype}\\\" (\\\"guid\\\" INTEGER NOT NULL REFERENCES \\\"{$this->prefix}entities{$etype}\\\"(\\\"guid\\\") ON DELETE CASCADE, \\\"name\\\" TEXT NOT NULL, \\\"eq_true\\\" INTEGER, \\\"eq_one\\\" INTEGER, \\\"eq_zero\\\" INTEGER, \\\"eq_negone\\\" INTEGER, \\\"eq_emptyarray\\\" INTEGER, \\\"string\\\" TEXT, \\\"int\\\" INTEGER, \\\"float\\\" REAL, \\\"is_int\\\" INTEGER, PRIMARY KEY(\\\"guid\\\", \\\"name\\\"));\"",
")",
";",
"$",
"this",
"->",
"query",
"(",
"\"CREATE INDEX IF NOT EXISTS \\\"{$this->prefix}comparisons{$etype}_id_guid\\\" ON \\\"{$this->prefix}comparisons{$etype}\\\" (\\\"guid\\\");\"",
")",
";",
"$",
"this",
"->",
"query",
"(",
"\"CREATE INDEX IF NOT EXISTS \\\"{$this->prefix}comparisons{$etype}_id_name\\\" ON \\\"{$this->prefix}comparisons{$etype}\\\" (\\\"name\\\");\"",
")",
";",
"$",
"this",
"->",
"query",
"(",
"\"CREATE INDEX IF NOT EXISTS \\\"{$this->prefix}comparisons{$etype}_id_name__eq_true\\\" ON \\\"{$this->prefix}comparisons{$etype}\\\" (\\\"name\\\") WHERE \\\"eq_true\\\" = 1;\"",
")",
";",
"$",
"this",
"->",
"query",
"(",
"\"CREATE INDEX IF NOT EXISTS \\\"{$this->prefix}comparisons{$etype}_id_name__not_eq_true\\\" ON \\\"{$this->prefix}comparisons{$etype}\\\" (\\\"name\\\") WHERE \\\"eq_true\\\" = 0;\"",
")",
";",
"$",
"this",
"->",
"query",
"(",
"\"CREATE INDEX IF NOT EXISTS \\\"{$this->prefix}comparisons{$etype}_id_int\\\" ON \\\"{$this->prefix}comparisons{$etype}\\\" (\\\"int\\\");\"",
")",
";",
"$",
"this",
"->",
"query",
"(",
"\"CREATE INDEX IF NOT EXISTS \\\"{$this->prefix}comparisons{$etype}_id_float\\\" ON \\\"{$this->prefix}comparisons{$etype}\\\" (\\\"float\\\");\"",
")",
";",
"// Create the references table.",
"$",
"this",
"->",
"query",
"(",
"\"CREATE TABLE IF NOT EXISTS \\\"{$this->prefix}references{$etype}\\\" (\\\"guid\\\" INTEGER NOT NULL REFERENCES \\\"{$this->prefix}entities{$etype}\\\"(\\\"guid\\\") ON DELETE CASCADE, \\\"name\\\" TEXT NOT NULL, \\\"reference\\\" INTEGER NOT NULL, PRIMARY KEY(\\\"guid\\\", \\\"name\\\", \\\"reference\\\"));\"",
")",
";",
"$",
"this",
"->",
"query",
"(",
"\"CREATE INDEX IF NOT EXISTS \\\"{$this->prefix}references{$etype}_id_guid\\\" ON \\\"{$this->prefix}references{$etype}\\\" (\\\"guid\\\");\"",
")",
";",
"$",
"this",
"->",
"query",
"(",
"\"CREATE INDEX IF NOT EXISTS \\\"{$this->prefix}references{$etype}_id_name\\\" ON \\\"{$this->prefix}references{$etype}\\\" (\\\"name\\\");\"",
")",
";",
"$",
"this",
"->",
"query",
"(",
"\"CREATE INDEX IF NOT EXISTS \\\"{$this->prefix}references{$etype}_id_reference\\\" ON \\\"{$this->prefix}references{$etype}\\\" (\\\"reference\\\");\"",
")",
";",
"}",
"else",
"{",
"// Create the GUID table.",
"$",
"this",
"->",
"query",
"(",
"\"CREATE TABLE IF NOT EXISTS \\\"{$this->prefix}guids\\\" (\\\"guid\\\" INTEGER NOT NULL PRIMARY KEY ASC);\"",
")",
";",
"// Create the UID table.",
"$",
"this",
"->",
"query",
"(",
"\"CREATE TABLE IF NOT EXISTS \\\"{$this->prefix}uids\\\" (\\\"name\\\" TEXT PRIMARY KEY NOT NULL, \\\"cur_uid\\\" INTEGER NOT NULL);\"",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"query",
"(",
"\"ROLLBACK TO 'tablecreation';\"",
")",
";",
"throw",
"$",
"e",
";",
"}",
"$",
"this",
"->",
"query",
"(",
"\"RELEASE 'tablecreation';\"",
")",
";",
"return",
"true",
";",
"}"
] | Create entity tables in the database.
@param string $etype The entity type to create a table for. If this is
blank, the default tables are created. | [
"Create",
"entity",
"tables",
"in",
"the",
"database",
"."
] | train | https://github.com/sciactive/nymph-server/blob/3c18dbf45c2750d07c798e14534dba87387beeba/src/Drivers/SQLite3Driver.php#L122-L167 |
sciactive/nymph-server | src/Drivers/SQLite3Driver.php | SQLite3Driver.makeEntityQuery | private function makeEntityQuery(
$options,
$selectors,
$etypeDirty,
$subquery = false
) {
$fullQueryCoverage = true;
$sort = $options['sort'] ?? 'cdate';
$etype = '_'.SQLite3::escapeString($etypeDirty);
$queryParts = $this->iterateSelectorsForQuery($selectors, function ($value) use ($options, $etypeDirty, &$fullQueryCoverage) {
$subquery = $this->makeEntityQuery(
$options,
[$value],
$etypeDirty,
true
);
$fullQueryCoverage = $fullQueryCoverage && $subquery['fullCoverage'];
return $subquery['query'];
}, function (&$curQuery, $key, $value, $typeIsOr, $typeIsNot) use ($etype, &$fullQueryCoverage) {
$clauseNot = $key[0] === '!';
// Any options having to do with data only return if the
// entity has the specified variables.
foreach ($value as $curValue) {
switch ($key) {
case 'guid':
case '!guid':
foreach ($curValue as $curGuid) {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."guid"='.(int) $curGuid;
}
break;
case 'tag':
case '!tag':
foreach ($curValue as $curTag) {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."tags" LIKE \'%,'.
str_replace(
['%', '_', ':'],
[':%', ':_', '::'],
SQLite3::escapeString($curTag)
).',%\' ESCAPE \':\'';
}
break;
case 'isset':
case '!isset':
foreach ($curValue as $curVar) {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= 'ie."guid" '.
(($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'IN (SELECT "guid" FROM "'.
$this->prefix.'data'.$etype.'" WHERE "name"=\''.
SQLite3::escapeString($curVar).
'\' AND "value"!=\'N;\')';
}
break;
case 'ref':
case '!ref':
$guids = [];
if (is_array($curValue[1])) {
if (key_exists('guid', $curValue[1])) {
$guids[] = (int) $curValue[1]['guid'];
} else {
foreach ($curValue[1] as $curEntity) {
if (is_object($curEntity)) {
$guids[] = (int) $curEntity->guid;
} elseif (is_array($curEntity)) {
$guids[] = (int) $curEntity['guid'];
} else {
$guids[] = (int) $curEntity;
}
}
}
} elseif (is_object($curValue[1])) {
$guids[] = (int) $curValue[1]->guid;
} else {
$guids[] = (int) $curValue[1];
}
foreach ($guids as $curQguid) {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."guid" IN (SELECT "guid" FROM "'.
$this->prefix.'references'.$etype.'" WHERE "name"=\''.
SQLite3::escapeString($curValue[0]).'\' AND "reference"='.
SQLite3::escapeString((int) $curQguid).')';
}
break;
case 'strict':
case '!strict':
if ($curValue[0] === 'cdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."cdate"='.((float) $curValue[1]);
break;
} elseif ($curValue[0] === 'mdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."mdate"='.((float) $curValue[1]);
break;
} else {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
if (is_callable([$curValue[1], 'toReference'])) {
$svalue = serialize($curValue[1]->toReference());
} else {
$svalue = serialize($curValue[1]);
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."guid" IN (SELECT "guid" FROM "'.$this->prefix.'data'.
$etype.'" WHERE "name"=\''.
SQLite3::escapeString($curValue[0]).
'\' AND "value"=\''.
SQLite3::escapeString(
(
strpos($svalue, "\0") !== false
? '~'.addcslashes($svalue, chr(0).'\\')
: $svalue
)
).'\')';
}
break;
case 'like':
case '!like':
if ($curValue[0] === 'cdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'(ie."cdate" LIKE \''.
SQLite3::escapeString($curValue[1]).
'\' ESCAPE \'\\\')';
break;
} elseif ($curValue[0] === 'mdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'(ie."mdate" LIKE \''.
SQLite3::escapeString($curValue[1]).
'\' ESCAPE \'\\\')';
break;
} else {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."guid" IN (SELECT "guid" FROM "'.
$this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
SQLite3::escapeString($curValue[0]).
'\' AND "string" LIKE \''.
SQLite3::escapeString($curValue[1]).
'\' ESCAPE \'\\\')';
}
break;
case 'ilike':
case '!ilike':
if ($curValue[0] === 'cdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'(ie."cdate" LIKE \''.
SQLite3::escapeString($curValue[1]).
'\' ESCAPE \'\\\')';
break;
} elseif ($curValue[0] === 'mdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'(ie."mdate" LIKE \''.
SQLite3::escapeString($curValue[1]).
'\' ESCAPE \'\\\')';
break;
} else {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."guid" IN (SELECT "guid" FROM "'.
$this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
SQLite3::escapeString($curValue[0]).
'\' AND lower("string") LIKE lower(\''.
SQLite3::escapeString($curValue[1]).
'\') ESCAPE \'\\\')';
}
break;
case 'pmatch':
case '!pmatch':
if ($curValue[0] === 'cdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'(ie."cdate" REGEXP \''.
SQLite3::escapeString($curValue[1]).'\')';
break;
} elseif ($curValue[0] === 'mdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'(ie."mdate" REGEXP \''.
SQLite3::escapeString($curValue[1]).'\')';
break;
} else {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."guid" IN (SELECT "guid" FROM "'.
$this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
SQLite3::escapeString($curValue[0]).
'\' AND "string" REGEXP \''.
SQLite3::escapeString($curValue[1]).'\')';
}
break;
case 'ipmatch':
case '!ipmatch':
if ($curValue[0] === 'cdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'(ie."cdate" REGEXP \''.
SQLite3::escapeString($curValue[1]).'\')';
break;
} elseif ($curValue[0] === 'mdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'(ie."mdate" REGEXP \''.
SQLite3::escapeString($curValue[1]).'\')';
break;
} else {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."guid" IN (SELECT "guid" FROM "'.
$this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
SQLite3::escapeString($curValue[0]).
'\' AND lower("string") REGEXP lower(\''.
SQLite3::escapeString($curValue[1]).'\'))';
}
break;
case 'match':
case '!match':
if ($curValue[0] === 'cdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .=
(($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'preg_match(\''.SQLite3::escapeString($curValue[1]).
'\', ie."cdate")';
break;
} elseif ($curValue[0] === 'mdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .=
(($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'preg_match(\''.SQLite3::escapeString($curValue[1]).
'\', ie."mdate")';
break;
} else {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .=
(($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."guid" IN (SELECT "guid" FROM "'.
$this->prefix.'comparisons'.$etype.
'" WHERE "name"=\''.
SQLite3::escapeString($curValue[0]).
'\' AND "string" IS NOT NULL AND '.
'preg_match(\''.SQLite3::escapeString($curValue[1]).
'\', "string"))';
}
break;
case 'gt':
case '!gt':
if ($curValue[0] === 'cdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."cdate">'.((float) $curValue[1]);
break;
} elseif ($curValue[0] === 'mdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."mdate">'.((float) $curValue[1]);
break;
} else {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .=
(($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."guid" IN (SELECT "guid" FROM "'.
$this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
SQLite3::escapeString($curValue[0]).'\' AND '.
'(("is_int"=\'1\' AND "int" IS NOT NULL AND "int" > '.
((int) $curValue[1]).') OR ('.
'NOT "is_int"=\'1\' AND "float" IS NOT NULL AND "float" > '.
((float) $curValue[1]).')))';
}
break;
case 'gte':
case '!gte':
if ($curValue[0] === 'cdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."cdate">='.((float) $curValue[1]);
break;
} elseif ($curValue[0] === 'mdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."mdate">='.((float) $curValue[1]);
break;
} else {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .=
(($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."guid" IN (SELECT "guid" FROM "'.
$this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
SQLite3::escapeString($curValue[0]).'\' AND '.
'(("is_int"=\'1\' AND "int" IS NOT NULL AND "int" >= '.
((int) $curValue[1]).') OR ('.
'NOT "is_int"=\'1\' AND "float" IS NOT NULL AND "float" >= '.
((float) $curValue[1]).')))';
}
break;
case 'lt':
case '!lt':
if ($curValue[0] === 'cdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."cdate"<'.((float) $curValue[1]);
break;
} elseif ($curValue[0] === 'mdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."mdate"<'.((float) $curValue[1]);
break;
} else {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .=
(($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."guid" IN (SELECT "guid" FROM "'.
$this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
SQLite3::escapeString($curValue[0]).'\' AND '.
'(("is_int"=\'1\' AND "int" IS NOT NULL AND "int" < '.
((int) $curValue[1]).') OR ('.
'NOT "is_int"=\'1\' AND "float" IS NOT NULL AND "float" < '.
((float) $curValue[1]).')))';
}
break;
case 'lte':
case '!lte':
if ($curValue[0] === 'cdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."cdate"<='.((float) $curValue[1]);
break;
} elseif ($curValue[0] === 'mdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."mdate"<='.((float) $curValue[1]);
break;
} else {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .=
(($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."guid" IN (SELECT "guid" FROM "'.
$this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
SQLite3::escapeString($curValue[0]).'\' AND '.
'(("is_int"=\'1\' AND "int" IS NOT NULL AND "int" <= '.
((int) $curValue[1]).') OR ('.
'NOT "is_int"=\'1\' AND "float" IS NOT NULL AND "float" <= '.
((float) $curValue[1]).')))';
}
break;
// Cases after this point contains special values where
// it can be solved by the query, but if those values
// don't match, just check the variable exists.
case 'equal':
case '!equal':
case 'data':
case '!data':
if ($curValue[0] === 'cdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."cdate"='.((float) $curValue[1]);
break;
} elseif ($curValue[0] === 'mdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."mdate"='.((float) $curValue[1]);
break;
} elseif ($curValue[1] === true || $curValue[1] === false) {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."guid" IN (SELECT "guid" FROM "'.
$this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
SQLite3::escapeString($curValue[0]).
'\' AND "eq_true"='.
($curValue[1] ? '1' : '0').')';
break;
} elseif ($curValue[1] === 1) {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."guid" IN (SELECT "guid" FROM "'.
$this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
SQLite3::escapeString($curValue[0]).
'\' AND "eq_one"=1)';
break;
} elseif ($curValue[1] === 0) {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."guid" IN (SELECT "guid" FROM "'.
$this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
SQLite3::escapeString($curValue[0]).
'\' AND "eq_zero"=1)';
break;
} elseif ($curValue[1] === -1) {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."guid" IN (SELECT "guid" FROM "'.
$this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
SQLite3::escapeString($curValue[0]).
'\' AND "eq_negone"=1)';
break;
} elseif ($curValue[1] === []) {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."guid" IN (SELECT "guid" FROM "'.
$this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
SQLite3::escapeString($curValue[0]).
'\' AND "eq_emptyarray"=1)';
break;
}
// Fall through.
case 'array':
case '!array':
if (!($typeIsNot xor $clauseNot)) {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= 'ie."guid" IN (SELECT "guid" FROM "'.
$this->prefix.'data'.$etype.'" WHERE "name"=\''.
SQLite3::escapeString($curValue[0]).'\')';
}
$fullQueryCoverage = false;
break;
}
}
});
switch ($sort) {
case 'guid':
$sort = '"guid"';
break;
case 'mdate':
$sort = '"mdate"';
break;
case 'cdate':
default:
$sort = '"cdate"';
break;
}
if (isset($options['reverse']) && $options['reverse']) {
$sort .= ' DESC';
}
if ($queryParts) {
if ($subquery) {
$query = "((".implode(') AND (', $queryParts)."))";
} else {
$limit = "";
if ($fullQueryCoverage && key_exists('limit', $options)) {
$limit = " LIMIT ".((int) $options['limit']);
}
$offset = "";
if ($fullQueryCoverage && key_exists('offset', $options)) {
$offset = " OFFSET ".((int) $options['offset']);
}
$query =
"SELECT e.\"guid\", e.\"tags\", e.\"cdate\", e.\"mdate\", ".
"d.\"name\", d.\"value\" ".
"FROM \"{$this->prefix}entities{$etype}\" e ".
"LEFT JOIN \"{$this->prefix}data{$etype}\" d USING (\"guid\") ".
"INNER JOIN (".
"SELECT \"guid\" ".
"FROM \"{$this->prefix}entities{$etype}\" ie ".
"WHERE (".
implode(') AND (', $queryParts).
") ".
"ORDER BY ie.{$sort}{$limit}{$offset}".
") f USING (\"guid\") ".
"ORDER BY {$sort};";
}
} else {
if ($subquery) {
$query = '';
} else {
$limit = "";
if (key_exists('limit', $options)) {
$limit = " LIMIT ".((int) $options['limit']);
}
$offset = "";
if (key_exists('offset', $options)) {
$offset = " OFFSET ".((int) $options['offset']);
}
if ($limit || $offset) {
$query =
"SELECT e.\"guid\", e.\"tags\", e.\"cdate\", e.\"mdate\", ".
"d.\"name\", d.\"value\" ".
"FROM \"{$this->prefix}entities{$etype}\" e ".
"LEFT JOIN \"{$this->prefix}data{$etype}\" d USING (\"guid\") ".
"INNER JOIN (".
"SELECT \"guid\" ".
"FROM \"{$this->prefix}entities{$etype}\" ie ".
"ORDER BY ie.{$sort}{$limit}{$offset}".
") f USING (\"guid\") ".
"ORDER BY {$sort};";
} else {
$query =
"SELECT e.\"guid\", e.\"tags\", e.\"cdate\", e.\"mdate\", ".
"d.\"name\", d.\"value\" ".
"FROM \"{$this->prefix}entities{$etype}\" e ".
"LEFT JOIN \"{$this->prefix}data{$etype}\" d USING (\"guid\") ".
"ORDER BY {$sort};";
}
}
}
return [
'fullCoverage' => $fullQueryCoverage,
'limitOffsetCoverage' => $fullQueryCoverage,
'query' => $query
];
} | php | private function makeEntityQuery(
$options,
$selectors,
$etypeDirty,
$subquery = false
) {
$fullQueryCoverage = true;
$sort = $options['sort'] ?? 'cdate';
$etype = '_'.SQLite3::escapeString($etypeDirty);
$queryParts = $this->iterateSelectorsForQuery($selectors, function ($value) use ($options, $etypeDirty, &$fullQueryCoverage) {
$subquery = $this->makeEntityQuery(
$options,
[$value],
$etypeDirty,
true
);
$fullQueryCoverage = $fullQueryCoverage && $subquery['fullCoverage'];
return $subquery['query'];
}, function (&$curQuery, $key, $value, $typeIsOr, $typeIsNot) use ($etype, &$fullQueryCoverage) {
$clauseNot = $key[0] === '!';
// Any options having to do with data only return if the
// entity has the specified variables.
foreach ($value as $curValue) {
switch ($key) {
case 'guid':
case '!guid':
foreach ($curValue as $curGuid) {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."guid"='.(int) $curGuid;
}
break;
case 'tag':
case '!tag':
foreach ($curValue as $curTag) {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."tags" LIKE \'%,'.
str_replace(
['%', '_', ':'],
[':%', ':_', '::'],
SQLite3::escapeString($curTag)
).',%\' ESCAPE \':\'';
}
break;
case 'isset':
case '!isset':
foreach ($curValue as $curVar) {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= 'ie."guid" '.
(($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'IN (SELECT "guid" FROM "'.
$this->prefix.'data'.$etype.'" WHERE "name"=\''.
SQLite3::escapeString($curVar).
'\' AND "value"!=\'N;\')';
}
break;
case 'ref':
case '!ref':
$guids = [];
if (is_array($curValue[1])) {
if (key_exists('guid', $curValue[1])) {
$guids[] = (int) $curValue[1]['guid'];
} else {
foreach ($curValue[1] as $curEntity) {
if (is_object($curEntity)) {
$guids[] = (int) $curEntity->guid;
} elseif (is_array($curEntity)) {
$guids[] = (int) $curEntity['guid'];
} else {
$guids[] = (int) $curEntity;
}
}
}
} elseif (is_object($curValue[1])) {
$guids[] = (int) $curValue[1]->guid;
} else {
$guids[] = (int) $curValue[1];
}
foreach ($guids as $curQguid) {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."guid" IN (SELECT "guid" FROM "'.
$this->prefix.'references'.$etype.'" WHERE "name"=\''.
SQLite3::escapeString($curValue[0]).'\' AND "reference"='.
SQLite3::escapeString((int) $curQguid).')';
}
break;
case 'strict':
case '!strict':
if ($curValue[0] === 'cdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."cdate"='.((float) $curValue[1]);
break;
} elseif ($curValue[0] === 'mdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."mdate"='.((float) $curValue[1]);
break;
} else {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
if (is_callable([$curValue[1], 'toReference'])) {
$svalue = serialize($curValue[1]->toReference());
} else {
$svalue = serialize($curValue[1]);
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."guid" IN (SELECT "guid" FROM "'.$this->prefix.'data'.
$etype.'" WHERE "name"=\''.
SQLite3::escapeString($curValue[0]).
'\' AND "value"=\''.
SQLite3::escapeString(
(
strpos($svalue, "\0") !== false
? '~'.addcslashes($svalue, chr(0).'\\')
: $svalue
)
).'\')';
}
break;
case 'like':
case '!like':
if ($curValue[0] === 'cdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'(ie."cdate" LIKE \''.
SQLite3::escapeString($curValue[1]).
'\' ESCAPE \'\\\')';
break;
} elseif ($curValue[0] === 'mdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'(ie."mdate" LIKE \''.
SQLite3::escapeString($curValue[1]).
'\' ESCAPE \'\\\')';
break;
} else {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."guid" IN (SELECT "guid" FROM "'.
$this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
SQLite3::escapeString($curValue[0]).
'\' AND "string" LIKE \''.
SQLite3::escapeString($curValue[1]).
'\' ESCAPE \'\\\')';
}
break;
case 'ilike':
case '!ilike':
if ($curValue[0] === 'cdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'(ie."cdate" LIKE \''.
SQLite3::escapeString($curValue[1]).
'\' ESCAPE \'\\\')';
break;
} elseif ($curValue[0] === 'mdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'(ie."mdate" LIKE \''.
SQLite3::escapeString($curValue[1]).
'\' ESCAPE \'\\\')';
break;
} else {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."guid" IN (SELECT "guid" FROM "'.
$this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
SQLite3::escapeString($curValue[0]).
'\' AND lower("string") LIKE lower(\''.
SQLite3::escapeString($curValue[1]).
'\') ESCAPE \'\\\')';
}
break;
case 'pmatch':
case '!pmatch':
if ($curValue[0] === 'cdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'(ie."cdate" REGEXP \''.
SQLite3::escapeString($curValue[1]).'\')';
break;
} elseif ($curValue[0] === 'mdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'(ie."mdate" REGEXP \''.
SQLite3::escapeString($curValue[1]).'\')';
break;
} else {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."guid" IN (SELECT "guid" FROM "'.
$this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
SQLite3::escapeString($curValue[0]).
'\' AND "string" REGEXP \''.
SQLite3::escapeString($curValue[1]).'\')';
}
break;
case 'ipmatch':
case '!ipmatch':
if ($curValue[0] === 'cdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'(ie."cdate" REGEXP \''.
SQLite3::escapeString($curValue[1]).'\')';
break;
} elseif ($curValue[0] === 'mdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'(ie."mdate" REGEXP \''.
SQLite3::escapeString($curValue[1]).'\')';
break;
} else {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."guid" IN (SELECT "guid" FROM "'.
$this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
SQLite3::escapeString($curValue[0]).
'\' AND lower("string") REGEXP lower(\''.
SQLite3::escapeString($curValue[1]).'\'))';
}
break;
case 'match':
case '!match':
if ($curValue[0] === 'cdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .=
(($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'preg_match(\''.SQLite3::escapeString($curValue[1]).
'\', ie."cdate")';
break;
} elseif ($curValue[0] === 'mdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .=
(($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'preg_match(\''.SQLite3::escapeString($curValue[1]).
'\', ie."mdate")';
break;
} else {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .=
(($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."guid" IN (SELECT "guid" FROM "'.
$this->prefix.'comparisons'.$etype.
'" WHERE "name"=\''.
SQLite3::escapeString($curValue[0]).
'\' AND "string" IS NOT NULL AND '.
'preg_match(\''.SQLite3::escapeString($curValue[1]).
'\', "string"))';
}
break;
case 'gt':
case '!gt':
if ($curValue[0] === 'cdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."cdate">'.((float) $curValue[1]);
break;
} elseif ($curValue[0] === 'mdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."mdate">'.((float) $curValue[1]);
break;
} else {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .=
(($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."guid" IN (SELECT "guid" FROM "'.
$this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
SQLite3::escapeString($curValue[0]).'\' AND '.
'(("is_int"=\'1\' AND "int" IS NOT NULL AND "int" > '.
((int) $curValue[1]).') OR ('.
'NOT "is_int"=\'1\' AND "float" IS NOT NULL AND "float" > '.
((float) $curValue[1]).')))';
}
break;
case 'gte':
case '!gte':
if ($curValue[0] === 'cdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."cdate">='.((float) $curValue[1]);
break;
} elseif ($curValue[0] === 'mdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."mdate">='.((float) $curValue[1]);
break;
} else {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .=
(($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."guid" IN (SELECT "guid" FROM "'.
$this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
SQLite3::escapeString($curValue[0]).'\' AND '.
'(("is_int"=\'1\' AND "int" IS NOT NULL AND "int" >= '.
((int) $curValue[1]).') OR ('.
'NOT "is_int"=\'1\' AND "float" IS NOT NULL AND "float" >= '.
((float) $curValue[1]).')))';
}
break;
case 'lt':
case '!lt':
if ($curValue[0] === 'cdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."cdate"<'.((float) $curValue[1]);
break;
} elseif ($curValue[0] === 'mdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."mdate"<'.((float) $curValue[1]);
break;
} else {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .=
(($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."guid" IN (SELECT "guid" FROM "'.
$this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
SQLite3::escapeString($curValue[0]).'\' AND '.
'(("is_int"=\'1\' AND "int" IS NOT NULL AND "int" < '.
((int) $curValue[1]).') OR ('.
'NOT "is_int"=\'1\' AND "float" IS NOT NULL AND "float" < '.
((float) $curValue[1]).')))';
}
break;
case 'lte':
case '!lte':
if ($curValue[0] === 'cdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."cdate"<='.((float) $curValue[1]);
break;
} elseif ($curValue[0] === 'mdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."mdate"<='.((float) $curValue[1]);
break;
} else {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .=
(($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."guid" IN (SELECT "guid" FROM "'.
$this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
SQLite3::escapeString($curValue[0]).'\' AND '.
'(("is_int"=\'1\' AND "int" IS NOT NULL AND "int" <= '.
((int) $curValue[1]).') OR ('.
'NOT "is_int"=\'1\' AND "float" IS NOT NULL AND "float" <= '.
((float) $curValue[1]).')))';
}
break;
// Cases after this point contains special values where
// it can be solved by the query, but if those values
// don't match, just check the variable exists.
case 'equal':
case '!equal':
case 'data':
case '!data':
if ($curValue[0] === 'cdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."cdate"='.((float) $curValue[1]);
break;
} elseif ($curValue[0] === 'mdate') {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."mdate"='.((float) $curValue[1]);
break;
} elseif ($curValue[1] === true || $curValue[1] === false) {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."guid" IN (SELECT "guid" FROM "'.
$this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
SQLite3::escapeString($curValue[0]).
'\' AND "eq_true"='.
($curValue[1] ? '1' : '0').')';
break;
} elseif ($curValue[1] === 1) {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."guid" IN (SELECT "guid" FROM "'.
$this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
SQLite3::escapeString($curValue[0]).
'\' AND "eq_one"=1)';
break;
} elseif ($curValue[1] === 0) {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."guid" IN (SELECT "guid" FROM "'.
$this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
SQLite3::escapeString($curValue[0]).
'\' AND "eq_zero"=1)';
break;
} elseif ($curValue[1] === -1) {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."guid" IN (SELECT "guid" FROM "'.
$this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
SQLite3::escapeString($curValue[0]).
'\' AND "eq_negone"=1)';
break;
} elseif ($curValue[1] === []) {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= (($typeIsNot xor $clauseNot) ? 'NOT ' : '').
'ie."guid" IN (SELECT "guid" FROM "'.
$this->prefix.'comparisons'.$etype.'" WHERE "name"=\''.
SQLite3::escapeString($curValue[0]).
'\' AND "eq_emptyarray"=1)';
break;
}
// Fall through.
case 'array':
case '!array':
if (!($typeIsNot xor $clauseNot)) {
if ($curQuery) {
$curQuery .= $typeIsOr ? ' OR ' : ' AND ';
}
$curQuery .= 'ie."guid" IN (SELECT "guid" FROM "'.
$this->prefix.'data'.$etype.'" WHERE "name"=\''.
SQLite3::escapeString($curValue[0]).'\')';
}
$fullQueryCoverage = false;
break;
}
}
});
switch ($sort) {
case 'guid':
$sort = '"guid"';
break;
case 'mdate':
$sort = '"mdate"';
break;
case 'cdate':
default:
$sort = '"cdate"';
break;
}
if (isset($options['reverse']) && $options['reverse']) {
$sort .= ' DESC';
}
if ($queryParts) {
if ($subquery) {
$query = "((".implode(') AND (', $queryParts)."))";
} else {
$limit = "";
if ($fullQueryCoverage && key_exists('limit', $options)) {
$limit = " LIMIT ".((int) $options['limit']);
}
$offset = "";
if ($fullQueryCoverage && key_exists('offset', $options)) {
$offset = " OFFSET ".((int) $options['offset']);
}
$query =
"SELECT e.\"guid\", e.\"tags\", e.\"cdate\", e.\"mdate\", ".
"d.\"name\", d.\"value\" ".
"FROM \"{$this->prefix}entities{$etype}\" e ".
"LEFT JOIN \"{$this->prefix}data{$etype}\" d USING (\"guid\") ".
"INNER JOIN (".
"SELECT \"guid\" ".
"FROM \"{$this->prefix}entities{$etype}\" ie ".
"WHERE (".
implode(') AND (', $queryParts).
") ".
"ORDER BY ie.{$sort}{$limit}{$offset}".
") f USING (\"guid\") ".
"ORDER BY {$sort};";
}
} else {
if ($subquery) {
$query = '';
} else {
$limit = "";
if (key_exists('limit', $options)) {
$limit = " LIMIT ".((int) $options['limit']);
}
$offset = "";
if (key_exists('offset', $options)) {
$offset = " OFFSET ".((int) $options['offset']);
}
if ($limit || $offset) {
$query =
"SELECT e.\"guid\", e.\"tags\", e.\"cdate\", e.\"mdate\", ".
"d.\"name\", d.\"value\" ".
"FROM \"{$this->prefix}entities{$etype}\" e ".
"LEFT JOIN \"{$this->prefix}data{$etype}\" d USING (\"guid\") ".
"INNER JOIN (".
"SELECT \"guid\" ".
"FROM \"{$this->prefix}entities{$etype}\" ie ".
"ORDER BY ie.{$sort}{$limit}{$offset}".
") f USING (\"guid\") ".
"ORDER BY {$sort};";
} else {
$query =
"SELECT e.\"guid\", e.\"tags\", e.\"cdate\", e.\"mdate\", ".
"d.\"name\", d.\"value\" ".
"FROM \"{$this->prefix}entities{$etype}\" e ".
"LEFT JOIN \"{$this->prefix}data{$etype}\" d USING (\"guid\") ".
"ORDER BY {$sort};";
}
}
}
return [
'fullCoverage' => $fullQueryCoverage,
'limitOffsetCoverage' => $fullQueryCoverage,
'query' => $query
];
} | [
"private",
"function",
"makeEntityQuery",
"(",
"$",
"options",
",",
"$",
"selectors",
",",
"$",
"etypeDirty",
",",
"$",
"subquery",
"=",
"false",
")",
"{",
"$",
"fullQueryCoverage",
"=",
"true",
";",
"$",
"sort",
"=",
"$",
"options",
"[",
"'sort'",
"]",
"??",
"'cdate'",
";",
"$",
"etype",
"=",
"'_'",
".",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"etypeDirty",
")",
";",
"$",
"queryParts",
"=",
"$",
"this",
"->",
"iterateSelectorsForQuery",
"(",
"$",
"selectors",
",",
"function",
"(",
"$",
"value",
")",
"use",
"(",
"$",
"options",
",",
"$",
"etypeDirty",
",",
"&",
"$",
"fullQueryCoverage",
")",
"{",
"$",
"subquery",
"=",
"$",
"this",
"->",
"makeEntityQuery",
"(",
"$",
"options",
",",
"[",
"$",
"value",
"]",
",",
"$",
"etypeDirty",
",",
"true",
")",
";",
"$",
"fullQueryCoverage",
"=",
"$",
"fullQueryCoverage",
"&&",
"$",
"subquery",
"[",
"'fullCoverage'",
"]",
";",
"return",
"$",
"subquery",
"[",
"'query'",
"]",
";",
"}",
",",
"function",
"(",
"&",
"$",
"curQuery",
",",
"$",
"key",
",",
"$",
"value",
",",
"$",
"typeIsOr",
",",
"$",
"typeIsNot",
")",
"use",
"(",
"$",
"etype",
",",
"&",
"$",
"fullQueryCoverage",
")",
"{",
"$",
"clauseNot",
"=",
"$",
"key",
"[",
"0",
"]",
"===",
"'!'",
";",
"// Any options having to do with data only return if the",
"// entity has the specified variables.",
"foreach",
"(",
"$",
"value",
"as",
"$",
"curValue",
")",
"{",
"switch",
"(",
"$",
"key",
")",
"{",
"case",
"'guid'",
":",
"case",
"'!guid'",
":",
"foreach",
"(",
"$",
"curValue",
"as",
"$",
"curGuid",
")",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'ie.\"guid\"='",
".",
"(",
"int",
")",
"$",
"curGuid",
";",
"}",
"break",
";",
"case",
"'tag'",
":",
"case",
"'!tag'",
":",
"foreach",
"(",
"$",
"curValue",
"as",
"$",
"curTag",
")",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'ie.\"tags\" LIKE \\'%,'",
".",
"str_replace",
"(",
"[",
"'%'",
",",
"'_'",
",",
"':'",
"]",
",",
"[",
"':%'",
",",
"':_'",
",",
"'::'",
"]",
",",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"curTag",
")",
")",
".",
"',%\\' ESCAPE \\':\\''",
";",
"}",
"break",
";",
"case",
"'isset'",
":",
"case",
"'!isset'",
":",
"foreach",
"(",
"$",
"curValue",
"as",
"$",
"curVar",
")",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"'ie.\"guid\" '",
".",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'IN (SELECT \"guid\" FROM \"'",
".",
"$",
"this",
"->",
"prefix",
".",
"'data'",
".",
"$",
"etype",
".",
"'\" WHERE \"name\"=\\''",
".",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"curVar",
")",
".",
"'\\' AND \"value\"!=\\'N;\\')'",
";",
"}",
"break",
";",
"case",
"'ref'",
":",
"case",
"'!ref'",
":",
"$",
"guids",
"=",
"[",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"curValue",
"[",
"1",
"]",
")",
")",
"{",
"if",
"(",
"key_exists",
"(",
"'guid'",
",",
"$",
"curValue",
"[",
"1",
"]",
")",
")",
"{",
"$",
"guids",
"[",
"]",
"=",
"(",
"int",
")",
"$",
"curValue",
"[",
"1",
"]",
"[",
"'guid'",
"]",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"curValue",
"[",
"1",
"]",
"as",
"$",
"curEntity",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"curEntity",
")",
")",
"{",
"$",
"guids",
"[",
"]",
"=",
"(",
"int",
")",
"$",
"curEntity",
"->",
"guid",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"curEntity",
")",
")",
"{",
"$",
"guids",
"[",
"]",
"=",
"(",
"int",
")",
"$",
"curEntity",
"[",
"'guid'",
"]",
";",
"}",
"else",
"{",
"$",
"guids",
"[",
"]",
"=",
"(",
"int",
")",
"$",
"curEntity",
";",
"}",
"}",
"}",
"}",
"elseif",
"(",
"is_object",
"(",
"$",
"curValue",
"[",
"1",
"]",
")",
")",
"{",
"$",
"guids",
"[",
"]",
"=",
"(",
"int",
")",
"$",
"curValue",
"[",
"1",
"]",
"->",
"guid",
";",
"}",
"else",
"{",
"$",
"guids",
"[",
"]",
"=",
"(",
"int",
")",
"$",
"curValue",
"[",
"1",
"]",
";",
"}",
"foreach",
"(",
"$",
"guids",
"as",
"$",
"curQguid",
")",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'ie.\"guid\" IN (SELECT \"guid\" FROM \"'",
".",
"$",
"this",
"->",
"prefix",
".",
"'references'",
".",
"$",
"etype",
".",
"'\" WHERE \"name\"=\\''",
".",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"curValue",
"[",
"0",
"]",
")",
".",
"'\\' AND \"reference\"='",
".",
"SQLite3",
"::",
"escapeString",
"(",
"(",
"int",
")",
"$",
"curQguid",
")",
".",
"')'",
";",
"}",
"break",
";",
"case",
"'strict'",
":",
"case",
"'!strict'",
":",
"if",
"(",
"$",
"curValue",
"[",
"0",
"]",
"===",
"'cdate'",
")",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'ie.\"cdate\"='",
".",
"(",
"(",
"float",
")",
"$",
"curValue",
"[",
"1",
"]",
")",
";",
"break",
";",
"}",
"elseif",
"(",
"$",
"curValue",
"[",
"0",
"]",
"===",
"'mdate'",
")",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'ie.\"mdate\"='",
".",
"(",
"(",
"float",
")",
"$",
"curValue",
"[",
"1",
"]",
")",
";",
"break",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"if",
"(",
"is_callable",
"(",
"[",
"$",
"curValue",
"[",
"1",
"]",
",",
"'toReference'",
"]",
")",
")",
"{",
"$",
"svalue",
"=",
"serialize",
"(",
"$",
"curValue",
"[",
"1",
"]",
"->",
"toReference",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"svalue",
"=",
"serialize",
"(",
"$",
"curValue",
"[",
"1",
"]",
")",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'ie.\"guid\" IN (SELECT \"guid\" FROM \"'",
".",
"$",
"this",
"->",
"prefix",
".",
"'data'",
".",
"$",
"etype",
".",
"'\" WHERE \"name\"=\\''",
".",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"curValue",
"[",
"0",
"]",
")",
".",
"'\\' AND \"value\"=\\''",
".",
"SQLite3",
"::",
"escapeString",
"(",
"(",
"strpos",
"(",
"$",
"svalue",
",",
"\"\\0\"",
")",
"!==",
"false",
"?",
"'~'",
".",
"addcslashes",
"(",
"$",
"svalue",
",",
"chr",
"(",
"0",
")",
".",
"'\\\\'",
")",
":",
"$",
"svalue",
")",
")",
".",
"'\\')'",
";",
"}",
"break",
";",
"case",
"'like'",
":",
"case",
"'!like'",
":",
"if",
"(",
"$",
"curValue",
"[",
"0",
"]",
"===",
"'cdate'",
")",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'(ie.\"cdate\" LIKE \\''",
".",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"curValue",
"[",
"1",
"]",
")",
".",
"'\\' ESCAPE \\'\\\\\\')'",
";",
"break",
";",
"}",
"elseif",
"(",
"$",
"curValue",
"[",
"0",
"]",
"===",
"'mdate'",
")",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'(ie.\"mdate\" LIKE \\''",
".",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"curValue",
"[",
"1",
"]",
")",
".",
"'\\' ESCAPE \\'\\\\\\')'",
";",
"break",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'ie.\"guid\" IN (SELECT \"guid\" FROM \"'",
".",
"$",
"this",
"->",
"prefix",
".",
"'comparisons'",
".",
"$",
"etype",
".",
"'\" WHERE \"name\"=\\''",
".",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"curValue",
"[",
"0",
"]",
")",
".",
"'\\' AND \"string\" LIKE \\''",
".",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"curValue",
"[",
"1",
"]",
")",
".",
"'\\' ESCAPE \\'\\\\\\')'",
";",
"}",
"break",
";",
"case",
"'ilike'",
":",
"case",
"'!ilike'",
":",
"if",
"(",
"$",
"curValue",
"[",
"0",
"]",
"===",
"'cdate'",
")",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'(ie.\"cdate\" LIKE \\''",
".",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"curValue",
"[",
"1",
"]",
")",
".",
"'\\' ESCAPE \\'\\\\\\')'",
";",
"break",
";",
"}",
"elseif",
"(",
"$",
"curValue",
"[",
"0",
"]",
"===",
"'mdate'",
")",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'(ie.\"mdate\" LIKE \\''",
".",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"curValue",
"[",
"1",
"]",
")",
".",
"'\\' ESCAPE \\'\\\\\\')'",
";",
"break",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'ie.\"guid\" IN (SELECT \"guid\" FROM \"'",
".",
"$",
"this",
"->",
"prefix",
".",
"'comparisons'",
".",
"$",
"etype",
".",
"'\" WHERE \"name\"=\\''",
".",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"curValue",
"[",
"0",
"]",
")",
".",
"'\\' AND lower(\"string\") LIKE lower(\\''",
".",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"curValue",
"[",
"1",
"]",
")",
".",
"'\\') ESCAPE \\'\\\\\\')'",
";",
"}",
"break",
";",
"case",
"'pmatch'",
":",
"case",
"'!pmatch'",
":",
"if",
"(",
"$",
"curValue",
"[",
"0",
"]",
"===",
"'cdate'",
")",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'(ie.\"cdate\" REGEXP \\''",
".",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"curValue",
"[",
"1",
"]",
")",
".",
"'\\')'",
";",
"break",
";",
"}",
"elseif",
"(",
"$",
"curValue",
"[",
"0",
"]",
"===",
"'mdate'",
")",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'(ie.\"mdate\" REGEXP \\''",
".",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"curValue",
"[",
"1",
"]",
")",
".",
"'\\')'",
";",
"break",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'ie.\"guid\" IN (SELECT \"guid\" FROM \"'",
".",
"$",
"this",
"->",
"prefix",
".",
"'comparisons'",
".",
"$",
"etype",
".",
"'\" WHERE \"name\"=\\''",
".",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"curValue",
"[",
"0",
"]",
")",
".",
"'\\' AND \"string\" REGEXP \\''",
".",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"curValue",
"[",
"1",
"]",
")",
".",
"'\\')'",
";",
"}",
"break",
";",
"case",
"'ipmatch'",
":",
"case",
"'!ipmatch'",
":",
"if",
"(",
"$",
"curValue",
"[",
"0",
"]",
"===",
"'cdate'",
")",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'(ie.\"cdate\" REGEXP \\''",
".",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"curValue",
"[",
"1",
"]",
")",
".",
"'\\')'",
";",
"break",
";",
"}",
"elseif",
"(",
"$",
"curValue",
"[",
"0",
"]",
"===",
"'mdate'",
")",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'(ie.\"mdate\" REGEXP \\''",
".",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"curValue",
"[",
"1",
"]",
")",
".",
"'\\')'",
";",
"break",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'ie.\"guid\" IN (SELECT \"guid\" FROM \"'",
".",
"$",
"this",
"->",
"prefix",
".",
"'comparisons'",
".",
"$",
"etype",
".",
"'\" WHERE \"name\"=\\''",
".",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"curValue",
"[",
"0",
"]",
")",
".",
"'\\' AND lower(\"string\") REGEXP lower(\\''",
".",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"curValue",
"[",
"1",
"]",
")",
".",
"'\\'))'",
";",
"}",
"break",
";",
"case",
"'match'",
":",
"case",
"'!match'",
":",
"if",
"(",
"$",
"curValue",
"[",
"0",
"]",
"===",
"'cdate'",
")",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'preg_match(\\''",
".",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"curValue",
"[",
"1",
"]",
")",
".",
"'\\', ie.\"cdate\")'",
";",
"break",
";",
"}",
"elseif",
"(",
"$",
"curValue",
"[",
"0",
"]",
"===",
"'mdate'",
")",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'preg_match(\\''",
".",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"curValue",
"[",
"1",
"]",
")",
".",
"'\\', ie.\"mdate\")'",
";",
"break",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'ie.\"guid\" IN (SELECT \"guid\" FROM \"'",
".",
"$",
"this",
"->",
"prefix",
".",
"'comparisons'",
".",
"$",
"etype",
".",
"'\" WHERE \"name\"=\\''",
".",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"curValue",
"[",
"0",
"]",
")",
".",
"'\\' AND \"string\" IS NOT NULL AND '",
".",
"'preg_match(\\''",
".",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"curValue",
"[",
"1",
"]",
")",
".",
"'\\', \"string\"))'",
";",
"}",
"break",
";",
"case",
"'gt'",
":",
"case",
"'!gt'",
":",
"if",
"(",
"$",
"curValue",
"[",
"0",
"]",
"===",
"'cdate'",
")",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'ie.\"cdate\">'",
".",
"(",
"(",
"float",
")",
"$",
"curValue",
"[",
"1",
"]",
")",
";",
"break",
";",
"}",
"elseif",
"(",
"$",
"curValue",
"[",
"0",
"]",
"===",
"'mdate'",
")",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'ie.\"mdate\">'",
".",
"(",
"(",
"float",
")",
"$",
"curValue",
"[",
"1",
"]",
")",
";",
"break",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'ie.\"guid\" IN (SELECT \"guid\" FROM \"'",
".",
"$",
"this",
"->",
"prefix",
".",
"'comparisons'",
".",
"$",
"etype",
".",
"'\" WHERE \"name\"=\\''",
".",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"curValue",
"[",
"0",
"]",
")",
".",
"'\\' AND '",
".",
"'((\"is_int\"=\\'1\\' AND \"int\" IS NOT NULL AND \"int\" > '",
".",
"(",
"(",
"int",
")",
"$",
"curValue",
"[",
"1",
"]",
")",
".",
"') OR ('",
".",
"'NOT \"is_int\"=\\'1\\' AND \"float\" IS NOT NULL AND \"float\" > '",
".",
"(",
"(",
"float",
")",
"$",
"curValue",
"[",
"1",
"]",
")",
".",
"')))'",
";",
"}",
"break",
";",
"case",
"'gte'",
":",
"case",
"'!gte'",
":",
"if",
"(",
"$",
"curValue",
"[",
"0",
"]",
"===",
"'cdate'",
")",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'ie.\"cdate\">='",
".",
"(",
"(",
"float",
")",
"$",
"curValue",
"[",
"1",
"]",
")",
";",
"break",
";",
"}",
"elseif",
"(",
"$",
"curValue",
"[",
"0",
"]",
"===",
"'mdate'",
")",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'ie.\"mdate\">='",
".",
"(",
"(",
"float",
")",
"$",
"curValue",
"[",
"1",
"]",
")",
";",
"break",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'ie.\"guid\" IN (SELECT \"guid\" FROM \"'",
".",
"$",
"this",
"->",
"prefix",
".",
"'comparisons'",
".",
"$",
"etype",
".",
"'\" WHERE \"name\"=\\''",
".",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"curValue",
"[",
"0",
"]",
")",
".",
"'\\' AND '",
".",
"'((\"is_int\"=\\'1\\' AND \"int\" IS NOT NULL AND \"int\" >= '",
".",
"(",
"(",
"int",
")",
"$",
"curValue",
"[",
"1",
"]",
")",
".",
"') OR ('",
".",
"'NOT \"is_int\"=\\'1\\' AND \"float\" IS NOT NULL AND \"float\" >= '",
".",
"(",
"(",
"float",
")",
"$",
"curValue",
"[",
"1",
"]",
")",
".",
"')))'",
";",
"}",
"break",
";",
"case",
"'lt'",
":",
"case",
"'!lt'",
":",
"if",
"(",
"$",
"curValue",
"[",
"0",
"]",
"===",
"'cdate'",
")",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'ie.\"cdate\"<'",
".",
"(",
"(",
"float",
")",
"$",
"curValue",
"[",
"1",
"]",
")",
";",
"break",
";",
"}",
"elseif",
"(",
"$",
"curValue",
"[",
"0",
"]",
"===",
"'mdate'",
")",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'ie.\"mdate\"<'",
".",
"(",
"(",
"float",
")",
"$",
"curValue",
"[",
"1",
"]",
")",
";",
"break",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'ie.\"guid\" IN (SELECT \"guid\" FROM \"'",
".",
"$",
"this",
"->",
"prefix",
".",
"'comparisons'",
".",
"$",
"etype",
".",
"'\" WHERE \"name\"=\\''",
".",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"curValue",
"[",
"0",
"]",
")",
".",
"'\\' AND '",
".",
"'((\"is_int\"=\\'1\\' AND \"int\" IS NOT NULL AND \"int\" < '",
".",
"(",
"(",
"int",
")",
"$",
"curValue",
"[",
"1",
"]",
")",
".",
"') OR ('",
".",
"'NOT \"is_int\"=\\'1\\' AND \"float\" IS NOT NULL AND \"float\" < '",
".",
"(",
"(",
"float",
")",
"$",
"curValue",
"[",
"1",
"]",
")",
".",
"')))'",
";",
"}",
"break",
";",
"case",
"'lte'",
":",
"case",
"'!lte'",
":",
"if",
"(",
"$",
"curValue",
"[",
"0",
"]",
"===",
"'cdate'",
")",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'ie.\"cdate\"<='",
".",
"(",
"(",
"float",
")",
"$",
"curValue",
"[",
"1",
"]",
")",
";",
"break",
";",
"}",
"elseif",
"(",
"$",
"curValue",
"[",
"0",
"]",
"===",
"'mdate'",
")",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'ie.\"mdate\"<='",
".",
"(",
"(",
"float",
")",
"$",
"curValue",
"[",
"1",
"]",
")",
";",
"break",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'ie.\"guid\" IN (SELECT \"guid\" FROM \"'",
".",
"$",
"this",
"->",
"prefix",
".",
"'comparisons'",
".",
"$",
"etype",
".",
"'\" WHERE \"name\"=\\''",
".",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"curValue",
"[",
"0",
"]",
")",
".",
"'\\' AND '",
".",
"'((\"is_int\"=\\'1\\' AND \"int\" IS NOT NULL AND \"int\" <= '",
".",
"(",
"(",
"int",
")",
"$",
"curValue",
"[",
"1",
"]",
")",
".",
"') OR ('",
".",
"'NOT \"is_int\"=\\'1\\' AND \"float\" IS NOT NULL AND \"float\" <= '",
".",
"(",
"(",
"float",
")",
"$",
"curValue",
"[",
"1",
"]",
")",
".",
"')))'",
";",
"}",
"break",
";",
"// Cases after this point contains special values where",
"// it can be solved by the query, but if those values",
"// don't match, just check the variable exists.",
"case",
"'equal'",
":",
"case",
"'!equal'",
":",
"case",
"'data'",
":",
"case",
"'!data'",
":",
"if",
"(",
"$",
"curValue",
"[",
"0",
"]",
"===",
"'cdate'",
")",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'ie.\"cdate\"='",
".",
"(",
"(",
"float",
")",
"$",
"curValue",
"[",
"1",
"]",
")",
";",
"break",
";",
"}",
"elseif",
"(",
"$",
"curValue",
"[",
"0",
"]",
"===",
"'mdate'",
")",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'ie.\"mdate\"='",
".",
"(",
"(",
"float",
")",
"$",
"curValue",
"[",
"1",
"]",
")",
";",
"break",
";",
"}",
"elseif",
"(",
"$",
"curValue",
"[",
"1",
"]",
"===",
"true",
"||",
"$",
"curValue",
"[",
"1",
"]",
"===",
"false",
")",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'ie.\"guid\" IN (SELECT \"guid\" FROM \"'",
".",
"$",
"this",
"->",
"prefix",
".",
"'comparisons'",
".",
"$",
"etype",
".",
"'\" WHERE \"name\"=\\''",
".",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"curValue",
"[",
"0",
"]",
")",
".",
"'\\' AND \"eq_true\"='",
".",
"(",
"$",
"curValue",
"[",
"1",
"]",
"?",
"'1'",
":",
"'0'",
")",
".",
"')'",
";",
"break",
";",
"}",
"elseif",
"(",
"$",
"curValue",
"[",
"1",
"]",
"===",
"1",
")",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'ie.\"guid\" IN (SELECT \"guid\" FROM \"'",
".",
"$",
"this",
"->",
"prefix",
".",
"'comparisons'",
".",
"$",
"etype",
".",
"'\" WHERE \"name\"=\\''",
".",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"curValue",
"[",
"0",
"]",
")",
".",
"'\\' AND \"eq_one\"=1)'",
";",
"break",
";",
"}",
"elseif",
"(",
"$",
"curValue",
"[",
"1",
"]",
"===",
"0",
")",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'ie.\"guid\" IN (SELECT \"guid\" FROM \"'",
".",
"$",
"this",
"->",
"prefix",
".",
"'comparisons'",
".",
"$",
"etype",
".",
"'\" WHERE \"name\"=\\''",
".",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"curValue",
"[",
"0",
"]",
")",
".",
"'\\' AND \"eq_zero\"=1)'",
";",
"break",
";",
"}",
"elseif",
"(",
"$",
"curValue",
"[",
"1",
"]",
"===",
"-",
"1",
")",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'ie.\"guid\" IN (SELECT \"guid\" FROM \"'",
".",
"$",
"this",
"->",
"prefix",
".",
"'comparisons'",
".",
"$",
"etype",
".",
"'\" WHERE \"name\"=\\''",
".",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"curValue",
"[",
"0",
"]",
")",
".",
"'\\' AND \"eq_negone\"=1)'",
";",
"break",
";",
"}",
"elseif",
"(",
"$",
"curValue",
"[",
"1",
"]",
"===",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"(",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
"?",
"'NOT '",
":",
"''",
")",
".",
"'ie.\"guid\" IN (SELECT \"guid\" FROM \"'",
".",
"$",
"this",
"->",
"prefix",
".",
"'comparisons'",
".",
"$",
"etype",
".",
"'\" WHERE \"name\"=\\''",
".",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"curValue",
"[",
"0",
"]",
")",
".",
"'\\' AND \"eq_emptyarray\"=1)'",
";",
"break",
";",
"}",
"// Fall through.",
"case",
"'array'",
":",
"case",
"'!array'",
":",
"if",
"(",
"!",
"(",
"$",
"typeIsNot",
"xor",
"$",
"clauseNot",
")",
")",
"{",
"if",
"(",
"$",
"curQuery",
")",
"{",
"$",
"curQuery",
".=",
"$",
"typeIsOr",
"?",
"' OR '",
":",
"' AND '",
";",
"}",
"$",
"curQuery",
".=",
"'ie.\"guid\" IN (SELECT \"guid\" FROM \"'",
".",
"$",
"this",
"->",
"prefix",
".",
"'data'",
".",
"$",
"etype",
".",
"'\" WHERE \"name\"=\\''",
".",
"SQLite3",
"::",
"escapeString",
"(",
"$",
"curValue",
"[",
"0",
"]",
")",
".",
"'\\')'",
";",
"}",
"$",
"fullQueryCoverage",
"=",
"false",
";",
"break",
";",
"}",
"}",
"}",
")",
";",
"switch",
"(",
"$",
"sort",
")",
"{",
"case",
"'guid'",
":",
"$",
"sort",
"=",
"'\"guid\"'",
";",
"break",
";",
"case",
"'mdate'",
":",
"$",
"sort",
"=",
"'\"mdate\"'",
";",
"break",
";",
"case",
"'cdate'",
":",
"default",
":",
"$",
"sort",
"=",
"'\"cdate\"'",
";",
"break",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'reverse'",
"]",
")",
"&&",
"$",
"options",
"[",
"'reverse'",
"]",
")",
"{",
"$",
"sort",
".=",
"' DESC'",
";",
"}",
"if",
"(",
"$",
"queryParts",
")",
"{",
"if",
"(",
"$",
"subquery",
")",
"{",
"$",
"query",
"=",
"\"((\"",
".",
"implode",
"(",
"') AND ('",
",",
"$",
"queryParts",
")",
".",
"\"))\"",
";",
"}",
"else",
"{",
"$",
"limit",
"=",
"\"\"",
";",
"if",
"(",
"$",
"fullQueryCoverage",
"&&",
"key_exists",
"(",
"'limit'",
",",
"$",
"options",
")",
")",
"{",
"$",
"limit",
"=",
"\" LIMIT \"",
".",
"(",
"(",
"int",
")",
"$",
"options",
"[",
"'limit'",
"]",
")",
";",
"}",
"$",
"offset",
"=",
"\"\"",
";",
"if",
"(",
"$",
"fullQueryCoverage",
"&&",
"key_exists",
"(",
"'offset'",
",",
"$",
"options",
")",
")",
"{",
"$",
"offset",
"=",
"\" OFFSET \"",
".",
"(",
"(",
"int",
")",
"$",
"options",
"[",
"'offset'",
"]",
")",
";",
"}",
"$",
"query",
"=",
"\"SELECT e.\\\"guid\\\", e.\\\"tags\\\", e.\\\"cdate\\\", e.\\\"mdate\\\", \"",
".",
"\"d.\\\"name\\\", d.\\\"value\\\" \"",
".",
"\"FROM \\\"{$this->prefix}entities{$etype}\\\" e \"",
".",
"\"LEFT JOIN \\\"{$this->prefix}data{$etype}\\\" d USING (\\\"guid\\\") \"",
".",
"\"INNER JOIN (\"",
".",
"\"SELECT \\\"guid\\\" \"",
".",
"\"FROM \\\"{$this->prefix}entities{$etype}\\\" ie \"",
".",
"\"WHERE (\"",
".",
"implode",
"(",
"') AND ('",
",",
"$",
"queryParts",
")",
".",
"\") \"",
".",
"\"ORDER BY ie.{$sort}{$limit}{$offset}\"",
".",
"\") f USING (\\\"guid\\\") \"",
".",
"\"ORDER BY {$sort};\"",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"subquery",
")",
"{",
"$",
"query",
"=",
"''",
";",
"}",
"else",
"{",
"$",
"limit",
"=",
"\"\"",
";",
"if",
"(",
"key_exists",
"(",
"'limit'",
",",
"$",
"options",
")",
")",
"{",
"$",
"limit",
"=",
"\" LIMIT \"",
".",
"(",
"(",
"int",
")",
"$",
"options",
"[",
"'limit'",
"]",
")",
";",
"}",
"$",
"offset",
"=",
"\"\"",
";",
"if",
"(",
"key_exists",
"(",
"'offset'",
",",
"$",
"options",
")",
")",
"{",
"$",
"offset",
"=",
"\" OFFSET \"",
".",
"(",
"(",
"int",
")",
"$",
"options",
"[",
"'offset'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"limit",
"||",
"$",
"offset",
")",
"{",
"$",
"query",
"=",
"\"SELECT e.\\\"guid\\\", e.\\\"tags\\\", e.\\\"cdate\\\", e.\\\"mdate\\\", \"",
".",
"\"d.\\\"name\\\", d.\\\"value\\\" \"",
".",
"\"FROM \\\"{$this->prefix}entities{$etype}\\\" e \"",
".",
"\"LEFT JOIN \\\"{$this->prefix}data{$etype}\\\" d USING (\\\"guid\\\") \"",
".",
"\"INNER JOIN (\"",
".",
"\"SELECT \\\"guid\\\" \"",
".",
"\"FROM \\\"{$this->prefix}entities{$etype}\\\" ie \"",
".",
"\"ORDER BY ie.{$sort}{$limit}{$offset}\"",
".",
"\") f USING (\\\"guid\\\") \"",
".",
"\"ORDER BY {$sort};\"",
";",
"}",
"else",
"{",
"$",
"query",
"=",
"\"SELECT e.\\\"guid\\\", e.\\\"tags\\\", e.\\\"cdate\\\", e.\\\"mdate\\\", \"",
".",
"\"d.\\\"name\\\", d.\\\"value\\\" \"",
".",
"\"FROM \\\"{$this->prefix}entities{$etype}\\\" e \"",
".",
"\"LEFT JOIN \\\"{$this->prefix}data{$etype}\\\" d USING (\\\"guid\\\") \"",
".",
"\"ORDER BY {$sort};\"",
";",
"}",
"}",
"}",
"return",
"[",
"'fullCoverage'",
"=>",
"$",
"fullQueryCoverage",
",",
"'limitOffsetCoverage'",
"=>",
"$",
"fullQueryCoverage",
",",
"'query'",
"=>",
"$",
"query",
"]",
";",
"}"
] | Generate the SQLite3 query.
@param array $options The options array.
@param array $selectors The formatted selector array.
@param string $etypeDirty
@param bool $subquery Whether only a subquery should be returned.
@return string The SQL query. | [
"Generate",
"the",
"SQLite3",
"query",
"."
] | train | https://github.com/sciactive/nymph-server/blob/3c18dbf45c2750d07c798e14534dba87387beeba/src/Drivers/SQLite3Driver.php#L308-L901 |
spiral-modules/listing | source/Listing/StaticState.php | StaticState.getValue | public function getValue($filter, $default = null)
{
if (array_key_exists($filter, $this->filters)) {
return $this->filters[$filter];
}
return $default;
} | php | public function getValue($filter, $default = null)
{
if (array_key_exists($filter, $this->filters)) {
return $this->filters[$filter];
}
return $default;
} | [
"public",
"function",
"getValue",
"(",
"$",
"filter",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"filter",
",",
"$",
"this",
"->",
"filters",
")",
")",
"{",
"return",
"$",
"this",
"->",
"filters",
"[",
"$",
"filter",
"]",
";",
"}",
"return",
"$",
"default",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/spiral-modules/listing/blob/89abe8939ce91cbf61b51b99e93ce1e57c8af83c/source/Listing/StaticState.php#L107-L114 |
surebert/surebert-framework | src/sb/Email/Reader.php | Reader.log | public function log($message)
{
if (!empty($this->log_file)) {
//echo $message;
\file_put_contents($this->log_file, "\n" . $message, \FILE_APPEND);
}
} | php | public function log($message)
{
if (!empty($this->log_file)) {
//echo $message;
\file_put_contents($this->log_file, "\n" . $message, \FILE_APPEND);
}
} | [
"public",
"function",
"log",
"(",
"$",
"message",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"log_file",
")",
")",
"{",
"//echo $message;",
"\\",
"file_put_contents",
"(",
"$",
"this",
"->",
"log_file",
",",
"\"\\n\"",
".",
"$",
"message",
",",
"\\",
"FILE_APPEND",
")",
";",
"}",
"}"
] | Logs messages to a log file if it is set
@param string $message | [
"Logs",
"messages",
"to",
"a",
"log",
"file",
"if",
"it",
"is",
"set"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Email/Reader.php#L160-L167 |
surebert/surebert-framework | src/sb/Email/Reader.php | Reader.open | public function open()
{
//check for mail
$host = "{" . $this->host . ":" . $this->port . "/" . $this->protocol . "/notls}INBOX";
//open the mail box for reading
$this->inbox = \imap_open($host, $this->address, $this->pass);
if (!$this->inbox) {
$this->connected = 0;
} else {
$this->connected = 1;
}
return $this->connected;
} | php | public function open()
{
//check for mail
$host = "{" . $this->host . ":" . $this->port . "/" . $this->protocol . "/notls}INBOX";
//open the mail box for reading
$this->inbox = \imap_open($host, $this->address, $this->pass);
if (!$this->inbox) {
$this->connected = 0;
} else {
$this->connected = 1;
}
return $this->connected;
} | [
"public",
"function",
"open",
"(",
")",
"{",
"//check for mail",
"$",
"host",
"=",
"\"{\"",
".",
"$",
"this",
"->",
"host",
".",
"\":\"",
".",
"$",
"this",
"->",
"port",
".",
"\"/\"",
".",
"$",
"this",
"->",
"protocol",
".",
"\"/notls}INBOX\"",
";",
"//open the mail box for reading",
"$",
"this",
"->",
"inbox",
"=",
"\\",
"imap_open",
"(",
"$",
"host",
",",
"$",
"this",
"->",
"address",
",",
"$",
"this",
"->",
"pass",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"inbox",
")",
"{",
"$",
"this",
"->",
"connected",
"=",
"0",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"connected",
"=",
"1",
";",
"}",
"return",
"$",
"this",
"->",
"connected",
";",
"}"
] | Opens the inbox and returns the connection status | [
"Opens",
"the",
"inbox",
"and",
"returns",
"the",
"connection",
"status"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Email/Reader.php#L173-L191 |
surebert/surebert-framework | src/sb/Email/Reader.php | Reader.close | public function close($expunge)
{
//expunge emails set to delete if delete_after_read is set
if ($expunge) {
\imap_close($this->inbox, CL_EXPUNGE);
} else {
\imap_close($this->inbox);
}
} | php | public function close($expunge)
{
//expunge emails set to delete if delete_after_read is set
if ($expunge) {
\imap_close($this->inbox, CL_EXPUNGE);
} else {
\imap_close($this->inbox);
}
} | [
"public",
"function",
"close",
"(",
"$",
"expunge",
")",
"{",
"//expunge emails set to delete if delete_after_read is set",
"if",
"(",
"$",
"expunge",
")",
"{",
"\\",
"imap_close",
"(",
"$",
"this",
"->",
"inbox",
",",
"CL_EXPUNGE",
")",
";",
"}",
"else",
"{",
"\\",
"imap_close",
"(",
"$",
"this",
"->",
"inbox",
")",
";",
"}",
"}"
] | Closes the inbox and expunges deleted messages if expunge is true
@param boolean $expunge true expunges | [
"Closes",
"the",
"inbox",
"and",
"expunges",
"deleted",
"messages",
"if",
"expunge",
"is",
"true"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Email/Reader.php#L198-L206 |
surebert/surebert-framework | src/sb/Email/Reader.php | Reader.parseHeaderInfo | public function parseHeaderInfo(Email &$email, $header)
{
//map the most useful header info to the email object itself
$email->all_headers = $header;
$email->subject = $header->subject;
$email->to = $header->to[0]->mailbox . '@' . $header->to[0]->host;
$email->from = $header->from[0]->mailbox . '@' . $header->from[0]->host;
$email->reply_to = $header->reply_to[0]->mailbox . '@' . $header->reply_to[0]->host;
$email->sender = $header->sender[0]->mailbox . '@' . $header->sender[0]->host;
$email->size = $header->Size;
$email->date = $header->date;
$email->timestamp = $header->udate;
$email->message_id = $header->message_id;
if ($header->Deleted == 'D') {
$email->deleted = 1;
}
//add the entire header in case we want access to custom headers later
$this->headers = $header;
} | php | public function parseHeaderInfo(Email &$email, $header)
{
//map the most useful header info to the email object itself
$email->all_headers = $header;
$email->subject = $header->subject;
$email->to = $header->to[0]->mailbox . '@' . $header->to[0]->host;
$email->from = $header->from[0]->mailbox . '@' . $header->from[0]->host;
$email->reply_to = $header->reply_to[0]->mailbox . '@' . $header->reply_to[0]->host;
$email->sender = $header->sender[0]->mailbox . '@' . $header->sender[0]->host;
$email->size = $header->Size;
$email->date = $header->date;
$email->timestamp = $header->udate;
$email->message_id = $header->message_id;
if ($header->Deleted == 'D') {
$email->deleted = 1;
}
//add the entire header in case we want access to custom headers later
$this->headers = $header;
} | [
"public",
"function",
"parseHeaderInfo",
"(",
"Email",
"&",
"$",
"email",
",",
"$",
"header",
")",
"{",
"//map the most useful header info to the email object itself",
"$",
"email",
"->",
"all_headers",
"=",
"$",
"header",
";",
"$",
"email",
"->",
"subject",
"=",
"$",
"header",
"->",
"subject",
";",
"$",
"email",
"->",
"to",
"=",
"$",
"header",
"->",
"to",
"[",
"0",
"]",
"->",
"mailbox",
".",
"'@'",
".",
"$",
"header",
"->",
"to",
"[",
"0",
"]",
"->",
"host",
";",
"$",
"email",
"->",
"from",
"=",
"$",
"header",
"->",
"from",
"[",
"0",
"]",
"->",
"mailbox",
".",
"'@'",
".",
"$",
"header",
"->",
"from",
"[",
"0",
"]",
"->",
"host",
";",
"$",
"email",
"->",
"reply_to",
"=",
"$",
"header",
"->",
"reply_to",
"[",
"0",
"]",
"->",
"mailbox",
".",
"'@'",
".",
"$",
"header",
"->",
"reply_to",
"[",
"0",
"]",
"->",
"host",
";",
"$",
"email",
"->",
"sender",
"=",
"$",
"header",
"->",
"sender",
"[",
"0",
"]",
"->",
"mailbox",
".",
"'@'",
".",
"$",
"header",
"->",
"sender",
"[",
"0",
"]",
"->",
"host",
";",
"$",
"email",
"->",
"size",
"=",
"$",
"header",
"->",
"Size",
";",
"$",
"email",
"->",
"date",
"=",
"$",
"header",
"->",
"date",
";",
"$",
"email",
"->",
"timestamp",
"=",
"$",
"header",
"->",
"udate",
";",
"$",
"email",
"->",
"message_id",
"=",
"$",
"header",
"->",
"message_id",
";",
"if",
"(",
"$",
"header",
"->",
"Deleted",
"==",
"'D'",
")",
"{",
"$",
"email",
"->",
"deleted",
"=",
"1",
";",
"}",
"//add the entire header in case we want access to custom headers later",
"$",
"this",
"->",
"headers",
"=",
"$",
"header",
";",
"}"
] | Parses header information from an email and returns it to as properties of the email object
@param sb_Email $email
@param object $header | [
"Parses",
"header",
"information",
"from",
"an",
"email",
"and",
"returns",
"it",
"to",
"as",
"properties",
"of",
"the",
"email",
"object"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Email/Reader.php#L255-L275 |
surebert/surebert-framework | src/sb/Email/Reader.php | Reader.examinePart | private function examinePart(&$email, $part)
{
//echo '<br />'.$part->part_id.' '.$part->type.' '.$part->dparameters[0]->value;
//get subtype JPEG, WAV, HTML, PLAIN, etc
$subtype = \strtolower($part->subtype);
//get encoding 0 = 7bit, 1= 8bit, 2=binary, 3=base64, 4=quoted prinatble, 5=other
$encoding = $part->encoding;
switch ($subtype) {
case 'plain':
if (empty($email->body)) {
$email->body_encoding = $encoding;
$email->body = imap_fetchbody($this->inbox, $email->index, $part->part_id);
}
break;
case 'html':
$email->body_HTML = imap_fetchbody($this->inbox, $email->index, $part->part_id);
break;
case 'applefile':
case 'gif':
case 'png':
case 'jpg':
case 'jpeg':
case 'wav':
case 'mp3':
case 'mp4':
case 'flv':
if ($part->type == 5) {
$attachment = new Email_Attachment();
$attachment->sizeK = $part->bytes / 1000;
$attachment->subtype = $subtype;
$attachment->type = $part->type;
$attachment->name = $part->dparameters[0]->value;
//change jpeg into jpg
$attachment->name = \str_ireplace('jpeg', 'jpg', $attachment->name);
$attachment->extension = \strtolower(end(explode(".", $attachment->name)));
$attachment->contents = \imap_fetchbody($this->inbox, $email->index, $part->part_id);
//decode base64 contents
if ($part->encoding == 3) {
$attachment->contents = \imap_base64($attachment->contents);
}
$attachment->encoding = $part->encoding;
$email->attachments[] = $attachment;
}
}
} | php | private function examinePart(&$email, $part)
{
//echo '<br />'.$part->part_id.' '.$part->type.' '.$part->dparameters[0]->value;
//get subtype JPEG, WAV, HTML, PLAIN, etc
$subtype = \strtolower($part->subtype);
//get encoding 0 = 7bit, 1= 8bit, 2=binary, 3=base64, 4=quoted prinatble, 5=other
$encoding = $part->encoding;
switch ($subtype) {
case 'plain':
if (empty($email->body)) {
$email->body_encoding = $encoding;
$email->body = imap_fetchbody($this->inbox, $email->index, $part->part_id);
}
break;
case 'html':
$email->body_HTML = imap_fetchbody($this->inbox, $email->index, $part->part_id);
break;
case 'applefile':
case 'gif':
case 'png':
case 'jpg':
case 'jpeg':
case 'wav':
case 'mp3':
case 'mp4':
case 'flv':
if ($part->type == 5) {
$attachment = new Email_Attachment();
$attachment->sizeK = $part->bytes / 1000;
$attachment->subtype = $subtype;
$attachment->type = $part->type;
$attachment->name = $part->dparameters[0]->value;
//change jpeg into jpg
$attachment->name = \str_ireplace('jpeg', 'jpg', $attachment->name);
$attachment->extension = \strtolower(end(explode(".", $attachment->name)));
$attachment->contents = \imap_fetchbody($this->inbox, $email->index, $part->part_id);
//decode base64 contents
if ($part->encoding == 3) {
$attachment->contents = \imap_base64($attachment->contents);
}
$attachment->encoding = $part->encoding;
$email->attachments[] = $attachment;
}
}
} | [
"private",
"function",
"examinePart",
"(",
"&",
"$",
"email",
",",
"$",
"part",
")",
"{",
"//echo '<br />'.$part->part_id.' '.$part->type.' '.$part->dparameters[0]->value;",
"//get subtype JPEG, WAV, HTML, PLAIN, etc",
"$",
"subtype",
"=",
"\\",
"strtolower",
"(",
"$",
"part",
"->",
"subtype",
")",
";",
"//get encoding 0 = 7bit, 1= 8bit, 2=binary, 3=base64, 4=quoted prinatble, 5=other",
"$",
"encoding",
"=",
"$",
"part",
"->",
"encoding",
";",
"switch",
"(",
"$",
"subtype",
")",
"{",
"case",
"'plain'",
":",
"if",
"(",
"empty",
"(",
"$",
"email",
"->",
"body",
")",
")",
"{",
"$",
"email",
"->",
"body_encoding",
"=",
"$",
"encoding",
";",
"$",
"email",
"->",
"body",
"=",
"imap_fetchbody",
"(",
"$",
"this",
"->",
"inbox",
",",
"$",
"email",
"->",
"index",
",",
"$",
"part",
"->",
"part_id",
")",
";",
"}",
"break",
";",
"case",
"'html'",
":",
"$",
"email",
"->",
"body_HTML",
"=",
"imap_fetchbody",
"(",
"$",
"this",
"->",
"inbox",
",",
"$",
"email",
"->",
"index",
",",
"$",
"part",
"->",
"part_id",
")",
";",
"break",
";",
"case",
"'applefile'",
":",
"case",
"'gif'",
":",
"case",
"'png'",
":",
"case",
"'jpg'",
":",
"case",
"'jpeg'",
":",
"case",
"'wav'",
":",
"case",
"'mp3'",
":",
"case",
"'mp4'",
":",
"case",
"'flv'",
":",
"if",
"(",
"$",
"part",
"->",
"type",
"==",
"5",
")",
"{",
"$",
"attachment",
"=",
"new",
"Email_Attachment",
"(",
")",
";",
"$",
"attachment",
"->",
"sizeK",
"=",
"$",
"part",
"->",
"bytes",
"/",
"1000",
";",
"$",
"attachment",
"->",
"subtype",
"=",
"$",
"subtype",
";",
"$",
"attachment",
"->",
"type",
"=",
"$",
"part",
"->",
"type",
";",
"$",
"attachment",
"->",
"name",
"=",
"$",
"part",
"->",
"dparameters",
"[",
"0",
"]",
"->",
"value",
";",
"//change jpeg into jpg",
"$",
"attachment",
"->",
"name",
"=",
"\\",
"str_ireplace",
"(",
"'jpeg'",
",",
"'jpg'",
",",
"$",
"attachment",
"->",
"name",
")",
";",
"$",
"attachment",
"->",
"extension",
"=",
"\\",
"strtolower",
"(",
"end",
"(",
"explode",
"(",
"\".\"",
",",
"$",
"attachment",
"->",
"name",
")",
")",
")",
";",
"$",
"attachment",
"->",
"contents",
"=",
"\\",
"imap_fetchbody",
"(",
"$",
"this",
"->",
"inbox",
",",
"$",
"email",
"->",
"index",
",",
"$",
"part",
"->",
"part_id",
")",
";",
"//decode base64 contents",
"if",
"(",
"$",
"part",
"->",
"encoding",
"==",
"3",
")",
"{",
"$",
"attachment",
"->",
"contents",
"=",
"\\",
"imap_base64",
"(",
"$",
"attachment",
"->",
"contents",
")",
";",
"}",
"$",
"attachment",
"->",
"encoding",
"=",
"$",
"part",
"->",
"encoding",
";",
"$",
"email",
"->",
"attachments",
"[",
"]",
"=",
"$",
"attachment",
";",
"}",
"}",
"}"
] | Check in an email part for attachments and data
@param \sb\Email $email The email being examined
@param object $part The current part
@param string $part_id The id of the part | [
"Check",
"in",
"an",
"email",
"part",
"for",
"attachments",
"and",
"data"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Email/Reader.php#L284-L337 |
surebert/surebert-framework | src/sb/Email/Reader.php | Reader.fetchMessages | public function fetchMessages()
{
//count the messages
$this->countMessages();
//if there are zero emails report this to the user
if ($this->email_count == 0) {
$this->log('There are no emails to process!');
return false;
}
$this->log($this->email_count . ' ' . \Strings::pluralize($this->email_count, 'email') . ' to process.');
for ($i = 1; $i < $this->email_count + 1; $i++) {
$email = new Email;
//set the message index in case we want to delete it later
$email->index = $i;
//get all the header info
$this->parseHeaderInfo($email, imap_headerinfo($this->inbox, $i));
$structure = \imap_fetchstructure($this->inbox, $i);
//the type of email format
$email->subtype = \strtolower($structure->subtype);
$email->structure = $structure;
//if the email is divided into parts, html, plain, attachments, etc
if (isset($structure->parts)) {
$part_id = 1;
foreach ($structure->parts as $part) {
//get type 0 = text, 1 = multipart, 2 = message,
//3 = application, 4 = audio, 5= image, 6= video, 7 = other
$type = $part->type;
//multipart
$sub_id = 1;
if ($type == 1 && isset($part->parts)) {
foreach ($part->parts as $part) {
$part->part_id = $part_id . '.' . $sub_id;
$this->examinePart($email, $part);
$sub_id++;
}
} else {
$part->part_id = $part_id;
$this->examinePart($email, $part, $part_id);
}
$part_id++;
}
} else {
//it is just a plain text email
$email->body = \imap_fetchbody($this->inbox, $i, 1);
$email->body_encoding = $structure->encoding;
}
//if the body is base64 encoded, decode it
if ($email->body_encoding == 3) {
$email->body = \base64_decode($email->body);
}
$this->log(print_r($email, 1));
//store the email
$this->emails[] = $email;
}
} | php | public function fetchMessages()
{
//count the messages
$this->countMessages();
//if there are zero emails report this to the user
if ($this->email_count == 0) {
$this->log('There are no emails to process!');
return false;
}
$this->log($this->email_count . ' ' . \Strings::pluralize($this->email_count, 'email') . ' to process.');
for ($i = 1; $i < $this->email_count + 1; $i++) {
$email = new Email;
//set the message index in case we want to delete it later
$email->index = $i;
//get all the header info
$this->parseHeaderInfo($email, imap_headerinfo($this->inbox, $i));
$structure = \imap_fetchstructure($this->inbox, $i);
//the type of email format
$email->subtype = \strtolower($structure->subtype);
$email->structure = $structure;
//if the email is divided into parts, html, plain, attachments, etc
if (isset($structure->parts)) {
$part_id = 1;
foreach ($structure->parts as $part) {
//get type 0 = text, 1 = multipart, 2 = message,
//3 = application, 4 = audio, 5= image, 6= video, 7 = other
$type = $part->type;
//multipart
$sub_id = 1;
if ($type == 1 && isset($part->parts)) {
foreach ($part->parts as $part) {
$part->part_id = $part_id . '.' . $sub_id;
$this->examinePart($email, $part);
$sub_id++;
}
} else {
$part->part_id = $part_id;
$this->examinePart($email, $part, $part_id);
}
$part_id++;
}
} else {
//it is just a plain text email
$email->body = \imap_fetchbody($this->inbox, $i, 1);
$email->body_encoding = $structure->encoding;
}
//if the body is base64 encoded, decode it
if ($email->body_encoding == 3) {
$email->body = \base64_decode($email->body);
}
$this->log(print_r($email, 1));
//store the email
$this->emails[] = $email;
}
} | [
"public",
"function",
"fetchMessages",
"(",
")",
"{",
"//count the messages",
"$",
"this",
"->",
"countMessages",
"(",
")",
";",
"//if there are zero emails report this to the user",
"if",
"(",
"$",
"this",
"->",
"email_count",
"==",
"0",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"'There are no emails to process!'",
")",
";",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"log",
"(",
"$",
"this",
"->",
"email_count",
".",
"' '",
".",
"\\",
"Strings",
"::",
"pluralize",
"(",
"$",
"this",
"->",
"email_count",
",",
"'email'",
")",
".",
"' to process.'",
")",
";",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"email_count",
"+",
"1",
";",
"$",
"i",
"++",
")",
"{",
"$",
"email",
"=",
"new",
"Email",
";",
"//set the message index in case we want to delete it later",
"$",
"email",
"->",
"index",
"=",
"$",
"i",
";",
"//get all the header info",
"$",
"this",
"->",
"parseHeaderInfo",
"(",
"$",
"email",
",",
"imap_headerinfo",
"(",
"$",
"this",
"->",
"inbox",
",",
"$",
"i",
")",
")",
";",
"$",
"structure",
"=",
"\\",
"imap_fetchstructure",
"(",
"$",
"this",
"->",
"inbox",
",",
"$",
"i",
")",
";",
"//the type of email format",
"$",
"email",
"->",
"subtype",
"=",
"\\",
"strtolower",
"(",
"$",
"structure",
"->",
"subtype",
")",
";",
"$",
"email",
"->",
"structure",
"=",
"$",
"structure",
";",
"//if the email is divided into parts, html, plain, attachments, etc",
"if",
"(",
"isset",
"(",
"$",
"structure",
"->",
"parts",
")",
")",
"{",
"$",
"part_id",
"=",
"1",
";",
"foreach",
"(",
"$",
"structure",
"->",
"parts",
"as",
"$",
"part",
")",
"{",
"//get type 0 = text, 1 = multipart, 2 = message,",
"//3 = application, 4 = audio, 5= image, 6= video, 7 = other",
"$",
"type",
"=",
"$",
"part",
"->",
"type",
";",
"//multipart",
"$",
"sub_id",
"=",
"1",
";",
"if",
"(",
"$",
"type",
"==",
"1",
"&&",
"isset",
"(",
"$",
"part",
"->",
"parts",
")",
")",
"{",
"foreach",
"(",
"$",
"part",
"->",
"parts",
"as",
"$",
"part",
")",
"{",
"$",
"part",
"->",
"part_id",
"=",
"$",
"part_id",
".",
"'.'",
".",
"$",
"sub_id",
";",
"$",
"this",
"->",
"examinePart",
"(",
"$",
"email",
",",
"$",
"part",
")",
";",
"$",
"sub_id",
"++",
";",
"}",
"}",
"else",
"{",
"$",
"part",
"->",
"part_id",
"=",
"$",
"part_id",
";",
"$",
"this",
"->",
"examinePart",
"(",
"$",
"email",
",",
"$",
"part",
",",
"$",
"part_id",
")",
";",
"}",
"$",
"part_id",
"++",
";",
"}",
"}",
"else",
"{",
"//it is just a plain text email",
"$",
"email",
"->",
"body",
"=",
"\\",
"imap_fetchbody",
"(",
"$",
"this",
"->",
"inbox",
",",
"$",
"i",
",",
"1",
")",
";",
"$",
"email",
"->",
"body_encoding",
"=",
"$",
"structure",
"->",
"encoding",
";",
"}",
"//if the body is base64 encoded, decode it",
"if",
"(",
"$",
"email",
"->",
"body_encoding",
"==",
"3",
")",
"{",
"$",
"email",
"->",
"body",
"=",
"\\",
"base64_decode",
"(",
"$",
"email",
"->",
"body",
")",
";",
"}",
"$",
"this",
"->",
"log",
"(",
"print_r",
"(",
"$",
"email",
",",
"1",
")",
")",
";",
"//store the email",
"$",
"this",
"->",
"emails",
"[",
"]",
"=",
"$",
"email",
";",
"}",
"}"
] | Fetches all the messages in an inbox and put them in the emails array
@return returns the array of all email objects found | [
"Fetches",
"all",
"the",
"messages",
"in",
"an",
"inbox",
"and",
"put",
"them",
"in",
"the",
"emails",
"array"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Email/Reader.php#L344-L421 |
Litecms/Team | src/Http/Controllers/TeamResourceController.php | TeamResourceController.index | public function index(TeamRequest $request)
{
$view = $this->response->theme->listView();
if ($this->response->typeIs('json')) {
$function = camel_case('get-' . $view);
return $this->repository
->setPresenter(\Litecms\Team\Repositories\Presenter\TeamPresenter::class)
->$function();
}
$teams = $this->repository->paginate();
return $this->response->title(trans('team::team.names'))
->view('team::team.index', true)
->data(compact('teams'))
->output();
} | php | public function index(TeamRequest $request)
{
$view = $this->response->theme->listView();
if ($this->response->typeIs('json')) {
$function = camel_case('get-' . $view);
return $this->repository
->setPresenter(\Litecms\Team\Repositories\Presenter\TeamPresenter::class)
->$function();
}
$teams = $this->repository->paginate();
return $this->response->title(trans('team::team.names'))
->view('team::team.index', true)
->data(compact('teams'))
->output();
} | [
"public",
"function",
"index",
"(",
"TeamRequest",
"$",
"request",
")",
"{",
"$",
"view",
"=",
"$",
"this",
"->",
"response",
"->",
"theme",
"->",
"listView",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"response",
"->",
"typeIs",
"(",
"'json'",
")",
")",
"{",
"$",
"function",
"=",
"camel_case",
"(",
"'get-'",
".",
"$",
"view",
")",
";",
"return",
"$",
"this",
"->",
"repository",
"->",
"setPresenter",
"(",
"\\",
"Litecms",
"\\",
"Team",
"\\",
"Repositories",
"\\",
"Presenter",
"\\",
"TeamPresenter",
"::",
"class",
")",
"->",
"$",
"function",
"(",
")",
";",
"}",
"$",
"teams",
"=",
"$",
"this",
"->",
"repository",
"->",
"paginate",
"(",
")",
";",
"return",
"$",
"this",
"->",
"response",
"->",
"title",
"(",
"trans",
"(",
"'team::team.names'",
")",
")",
"->",
"view",
"(",
"'team::team.index'",
",",
"true",
")",
"->",
"data",
"(",
"compact",
"(",
"'teams'",
")",
")",
"->",
"output",
"(",
")",
";",
"}"
] | Display a list of team.
@return Response | [
"Display",
"a",
"list",
"of",
"team",
"."
] | train | https://github.com/Litecms/Team/blob/a444a6a6604c969df138ac0eb57ed5f4696b0f00/src/Http/Controllers/TeamResourceController.php#L38-L55 |
Litecms/Team | src/Http/Controllers/TeamResourceController.php | TeamResourceController.show | public function show(TeamRequest $request, Team $team)
{
if ($team->exists) {
$view = 'team::team.show';
} else {
$view = 'team::team.new';
}
return $this->response->title(trans('app.view') . ' ' . trans('team::team.name'))
->data(compact('team'))
->view($view, true)
->output();
} | php | public function show(TeamRequest $request, Team $team)
{
if ($team->exists) {
$view = 'team::team.show';
} else {
$view = 'team::team.new';
}
return $this->response->title(trans('app.view') . ' ' . trans('team::team.name'))
->data(compact('team'))
->view($view, true)
->output();
} | [
"public",
"function",
"show",
"(",
"TeamRequest",
"$",
"request",
",",
"Team",
"$",
"team",
")",
"{",
"if",
"(",
"$",
"team",
"->",
"exists",
")",
"{",
"$",
"view",
"=",
"'team::team.show'",
";",
"}",
"else",
"{",
"$",
"view",
"=",
"'team::team.new'",
";",
"}",
"return",
"$",
"this",
"->",
"response",
"->",
"title",
"(",
"trans",
"(",
"'app.view'",
")",
".",
"' '",
".",
"trans",
"(",
"'team::team.name'",
")",
")",
"->",
"data",
"(",
"compact",
"(",
"'team'",
")",
")",
"->",
"view",
"(",
"$",
"view",
",",
"true",
")",
"->",
"output",
"(",
")",
";",
"}"
] | Display team.
@param Request $request
@param Model $team
@return Response | [
"Display",
"team",
"."
] | train | https://github.com/Litecms/Team/blob/a444a6a6604c969df138ac0eb57ed5f4696b0f00/src/Http/Controllers/TeamResourceController.php#L65-L78 |
Litecms/Team | src/Http/Controllers/TeamResourceController.php | TeamResourceController.edit | public function edit(TeamRequest $request, Team $team)
{
return $this->response->title(trans('app.edit') . ' ' . trans('team::team.name'))
->view('team::team.edit', true)
->data(compact('team'))
->output();
} | php | public function edit(TeamRequest $request, Team $team)
{
return $this->response->title(trans('app.edit') . ' ' . trans('team::team.name'))
->view('team::team.edit', true)
->data(compact('team'))
->output();
} | [
"public",
"function",
"edit",
"(",
"TeamRequest",
"$",
"request",
",",
"Team",
"$",
"team",
")",
"{",
"return",
"$",
"this",
"->",
"response",
"->",
"title",
"(",
"trans",
"(",
"'app.edit'",
")",
".",
"' '",
".",
"trans",
"(",
"'team::team.name'",
")",
")",
"->",
"view",
"(",
"'team::team.edit'",
",",
"true",
")",
"->",
"data",
"(",
"compact",
"(",
"'team'",
")",
")",
"->",
"output",
"(",
")",
";",
"}"
] | Show team for editing.
@param Request $request
@param Model $team
@return Response | [
"Show",
"team",
"for",
"editing",
"."
] | train | https://github.com/Litecms/Team/blob/a444a6a6604c969df138ac0eb57ed5f4696b0f00/src/Http/Controllers/TeamResourceController.php#L135-L141 |
Litecms/Team | src/Http/Controllers/TeamResourceController.php | TeamResourceController.update | public function update(TeamRequest $request, Team $team)
{
try {
$attributes = $request->all();
$team->update($attributes);
return $this->response->message(trans('messages.success.updated', ['Module' => trans('team::team.name')]))
->code(204)
->status('success')
->url(guard_url('team/team/' . $team->getRouteKey()))
->redirect();
} catch (Exception $e) {
return $this->response->message($e->getMessage())
->code(400)
->status('error')
->url(guard_url('team/team/' . $team->getRouteKey()))
->redirect();
}
} | php | public function update(TeamRequest $request, Team $team)
{
try {
$attributes = $request->all();
$team->update($attributes);
return $this->response->message(trans('messages.success.updated', ['Module' => trans('team::team.name')]))
->code(204)
->status('success')
->url(guard_url('team/team/' . $team->getRouteKey()))
->redirect();
} catch (Exception $e) {
return $this->response->message($e->getMessage())
->code(400)
->status('error')
->url(guard_url('team/team/' . $team->getRouteKey()))
->redirect();
}
} | [
"public",
"function",
"update",
"(",
"TeamRequest",
"$",
"request",
",",
"Team",
"$",
"team",
")",
"{",
"try",
"{",
"$",
"attributes",
"=",
"$",
"request",
"->",
"all",
"(",
")",
";",
"$",
"team",
"->",
"update",
"(",
"$",
"attributes",
")",
";",
"return",
"$",
"this",
"->",
"response",
"->",
"message",
"(",
"trans",
"(",
"'messages.success.updated'",
",",
"[",
"'Module'",
"=>",
"trans",
"(",
"'team::team.name'",
")",
"]",
")",
")",
"->",
"code",
"(",
"204",
")",
"->",
"status",
"(",
"'success'",
")",
"->",
"url",
"(",
"guard_url",
"(",
"'team/team/'",
".",
"$",
"team",
"->",
"getRouteKey",
"(",
")",
")",
")",
"->",
"redirect",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"return",
"$",
"this",
"->",
"response",
"->",
"message",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
"->",
"code",
"(",
"400",
")",
"->",
"status",
"(",
"'error'",
")",
"->",
"url",
"(",
"guard_url",
"(",
"'team/team/'",
".",
"$",
"team",
"->",
"getRouteKey",
"(",
")",
")",
")",
"->",
"redirect",
"(",
")",
";",
"}",
"}"
] | Update the team.
@param Request $request
@param Model $team
@return Response | [
"Update",
"the",
"team",
"."
] | train | https://github.com/Litecms/Team/blob/a444a6a6604c969df138ac0eb57ed5f4696b0f00/src/Http/Controllers/TeamResourceController.php#L151-L170 |
Litecms/Team | src/Http/Controllers/TeamResourceController.php | TeamResourceController.destroy | public function destroy(TeamRequest $request, Team $team)
{
try {
$team->delete();
return $this->response->message(trans('messages.success.deleted', ['Module' => trans('team::team.name')]))
->code(202)
->status('success')
->url(guard_url('team/team/0'))
->redirect();
} catch (Exception $e) {
return $this->response->message($e->getMessage())
->code(400)
->status('error')
->url(guard_url('team/team/' . $team->getRouteKey()))
->redirect();
}
} | php | public function destroy(TeamRequest $request, Team $team)
{
try {
$team->delete();
return $this->response->message(trans('messages.success.deleted', ['Module' => trans('team::team.name')]))
->code(202)
->status('success')
->url(guard_url('team/team/0'))
->redirect();
} catch (Exception $e) {
return $this->response->message($e->getMessage())
->code(400)
->status('error')
->url(guard_url('team/team/' . $team->getRouteKey()))
->redirect();
}
} | [
"public",
"function",
"destroy",
"(",
"TeamRequest",
"$",
"request",
",",
"Team",
"$",
"team",
")",
"{",
"try",
"{",
"$",
"team",
"->",
"delete",
"(",
")",
";",
"return",
"$",
"this",
"->",
"response",
"->",
"message",
"(",
"trans",
"(",
"'messages.success.deleted'",
",",
"[",
"'Module'",
"=>",
"trans",
"(",
"'team::team.name'",
")",
"]",
")",
")",
"->",
"code",
"(",
"202",
")",
"->",
"status",
"(",
"'success'",
")",
"->",
"url",
"(",
"guard_url",
"(",
"'team/team/0'",
")",
")",
"->",
"redirect",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"return",
"$",
"this",
"->",
"response",
"->",
"message",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
"->",
"code",
"(",
"400",
")",
"->",
"status",
"(",
"'error'",
")",
"->",
"url",
"(",
"guard_url",
"(",
"'team/team/'",
".",
"$",
"team",
"->",
"getRouteKey",
"(",
")",
")",
")",
"->",
"redirect",
"(",
")",
";",
"}",
"}"
] | Remove the team.
@param Model $team
@return Response | [
"Remove",
"the",
"team",
"."
] | train | https://github.com/Litecms/Team/blob/a444a6a6604c969df138ac0eb57ed5f4696b0f00/src/Http/Controllers/TeamResourceController.php#L179-L199 |
chrometoasters/silverstripe-image-quality | src/Extensions/ImageQualityExtension.php | ImageQualityExtension.Quality | public function Quality($quality)
{
// Generate variant key
$variant = $this->owner->variantName(__FUNCTION__, $quality);
// Instruct the backend to search for an existing variant and use the callback to provide it if it does not exist.
return $this->owner->manipulateImage($variant, function (Image_Backend $backend) use ($quality) {
$backendClone = clone $backend;
$backendClone->setQuality($quality);
return $backendClone;
});
} | php | public function Quality($quality)
{
// Generate variant key
$variant = $this->owner->variantName(__FUNCTION__, $quality);
// Instruct the backend to search for an existing variant and use the callback to provide it if it does not exist.
return $this->owner->manipulateImage($variant, function (Image_Backend $backend) use ($quality) {
$backendClone = clone $backend;
$backendClone->setQuality($quality);
return $backendClone;
});
} | [
"public",
"function",
"Quality",
"(",
"$",
"quality",
")",
"{",
"// Generate variant key",
"$",
"variant",
"=",
"$",
"this",
"->",
"owner",
"->",
"variantName",
"(",
"__FUNCTION__",
",",
"$",
"quality",
")",
";",
"// Instruct the backend to search for an existing variant and use the callback to provide it if it does not exist.",
"return",
"$",
"this",
"->",
"owner",
"->",
"manipulateImage",
"(",
"$",
"variant",
",",
"function",
"(",
"Image_Backend",
"$",
"backend",
")",
"use",
"(",
"$",
"quality",
")",
"{",
"$",
"backendClone",
"=",
"clone",
"$",
"backend",
";",
"$",
"backendClone",
"->",
"setQuality",
"(",
"$",
"quality",
")",
";",
"return",
"$",
"backendClone",
";",
"}",
")",
";",
"}"
] | This function adjusts the quality of of an image using SilverStripe 4 syntax.
@param $quality
@return mixed | [
"This",
"function",
"adjusts",
"the",
"quality",
"of",
"of",
"an",
"image",
"using",
"SilverStripe",
"4",
"syntax",
"."
] | train | https://github.com/chrometoasters/silverstripe-image-quality/blob/73947f9def3a596918059d5f472a212bc80d9fbc/src/Extensions/ImageQualityExtension.php#L19-L31 |
DevGroup-ru/yii2-users-module | src/widgets/ManageSocialNetworksWidget.php | ManageSocialNetworksWidget.renderMainContent | protected function renderMainContent()
{
echo Html::beginTag('div', ['class' => 'social-login']);
echo Html::tag('h2', Yii::t('users', 'Add social service'));
foreach ($this->getClients() as $externalService) {
if (!in_array(get_class($externalService), array_keys($this->services))) {
$socialServiceId = SocialService::classNameToId(get_class($externalService));
$i18n = SocialService::i18nNameById($socialServiceId);
$this->clientLink(
$externalService,
'<i class="demo-icon icon-basic-' . $externalService->getName() . '"></i>',
[
'class' => "social-login__social-network social-login__social-network--"
. $externalService->getName(),
'title' => $i18n,
]
);
}
}
echo Html::endTag('div');
echo Html::tag('div', '', ['class' => 'clearfix']);
} | php | protected function renderMainContent()
{
echo Html::beginTag('div', ['class' => 'social-login']);
echo Html::tag('h2', Yii::t('users', 'Add social service'));
foreach ($this->getClients() as $externalService) {
if (!in_array(get_class($externalService), array_keys($this->services))) {
$socialServiceId = SocialService::classNameToId(get_class($externalService));
$i18n = SocialService::i18nNameById($socialServiceId);
$this->clientLink(
$externalService,
'<i class="demo-icon icon-basic-' . $externalService->getName() . '"></i>',
[
'class' => "social-login__social-network social-login__social-network--"
. $externalService->getName(),
'title' => $i18n,
]
);
}
}
echo Html::endTag('div');
echo Html::tag('div', '', ['class' => 'clearfix']);
} | [
"protected",
"function",
"renderMainContent",
"(",
")",
"{",
"echo",
"Html",
"::",
"beginTag",
"(",
"'div'",
",",
"[",
"'class'",
"=>",
"'social-login'",
"]",
")",
";",
"echo",
"Html",
"::",
"tag",
"(",
"'h2'",
",",
"Yii",
"::",
"t",
"(",
"'users'",
",",
"'Add social service'",
")",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getClients",
"(",
")",
"as",
"$",
"externalService",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"get_class",
"(",
"$",
"externalService",
")",
",",
"array_keys",
"(",
"$",
"this",
"->",
"services",
")",
")",
")",
"{",
"$",
"socialServiceId",
"=",
"SocialService",
"::",
"classNameToId",
"(",
"get_class",
"(",
"$",
"externalService",
")",
")",
";",
"$",
"i18n",
"=",
"SocialService",
"::",
"i18nNameById",
"(",
"$",
"socialServiceId",
")",
";",
"$",
"this",
"->",
"clientLink",
"(",
"$",
"externalService",
",",
"'<i class=\"demo-icon icon-basic-'",
".",
"$",
"externalService",
"->",
"getName",
"(",
")",
".",
"'\"></i>'",
",",
"[",
"'class'",
"=>",
"\"social-login__social-network social-login__social-network--\"",
".",
"$",
"externalService",
"->",
"getName",
"(",
")",
",",
"'title'",
"=>",
"$",
"i18n",
",",
"]",
")",
";",
"}",
"}",
"echo",
"Html",
"::",
"endTag",
"(",
"'div'",
")",
";",
"echo",
"Html",
"::",
"tag",
"(",
"'div'",
",",
"''",
",",
"[",
"'class'",
"=>",
"'clearfix'",
"]",
")",
";",
"}"
] | Renders the main content, which includes all external services links. | [
"Renders",
"the",
"main",
"content",
"which",
"includes",
"all",
"external",
"services",
"links",
"."
] | train | https://github.com/DevGroup-ru/yii2-users-module/blob/ff0103dc55c3462627ccc704c33e70c96053f750/src/widgets/ManageSocialNetworksWidget.php#L18-L42 |
zhouyl/mellivora | Mellivora/Database/DatabaseManager.php | DatabaseManager.configuration | protected function configuration($name)
{
$name = $name ?: $this->getDefaultConnection();
// To get the database connection configuration, we will just pull each of the
// connection configurations and get the configurations for the given name.
// If the configuration doesn't exist, we'll throw an exception and bail.
$connections = $this->container['config']['database.connections']->toArray();
if (is_null($config = Arr::get($connections, $name))) {
throw new InvalidArgumentException("Database [$name] not configured.");
}
return $config;
} | php | protected function configuration($name)
{
$name = $name ?: $this->getDefaultConnection();
// To get the database connection configuration, we will just pull each of the
// connection configurations and get the configurations for the given name.
// If the configuration doesn't exist, we'll throw an exception and bail.
$connections = $this->container['config']['database.connections']->toArray();
if (is_null($config = Arr::get($connections, $name))) {
throw new InvalidArgumentException("Database [$name] not configured.");
}
return $config;
} | [
"protected",
"function",
"configuration",
"(",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"$",
"name",
"?",
":",
"$",
"this",
"->",
"getDefaultConnection",
"(",
")",
";",
"// To get the database connection configuration, we will just pull each of the",
"// connection configurations and get the configurations for the given name.",
"// If the configuration doesn't exist, we'll throw an exception and bail.",
"$",
"connections",
"=",
"$",
"this",
"->",
"container",
"[",
"'config'",
"]",
"[",
"'database.connections'",
"]",
"->",
"toArray",
"(",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"config",
"=",
"Arr",
"::",
"get",
"(",
"$",
"connections",
",",
"$",
"name",
")",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Database [$name] not configured.\"",
")",
";",
"}",
"return",
"$",
"config",
";",
"}"
] | Get the configuration for a connection.
@param string $name
@throws \InvalidArgumentException
@return array | [
"Get",
"the",
"configuration",
"for",
"a",
"connection",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/DatabaseManager.php#L133-L147 |
zhouyl/mellivora | Mellivora/Database/DatabaseManager.php | DatabaseManager.configure | protected function configure(Connection $connection, $type)
{
$connection = $this->setPdoForType($connection, $type);
// First we'll set the fetch mode and a few other dependencies of the database
// connection. This method basically just configures and prepares it to get
// used by the application. Once we're finished we'll return it back out.
if ($this->container->has('events')) {
$connection->setEventDispatcher($this->container['events']);
}
// Here we'll set a reconnector callback. This reconnector can be any callable
// so we will set a Closure to reconnect from this manager with the name of
// the connection, which will allow us to reconnect from the connections.
$connection->setReconnector(function ($connection) {
$this->reconnect($connection->getName());
});
return $connection;
} | php | protected function configure(Connection $connection, $type)
{
$connection = $this->setPdoForType($connection, $type);
// First we'll set the fetch mode and a few other dependencies of the database
// connection. This method basically just configures and prepares it to get
// used by the application. Once we're finished we'll return it back out.
if ($this->container->has('events')) {
$connection->setEventDispatcher($this->container['events']);
}
// Here we'll set a reconnector callback. This reconnector can be any callable
// so we will set a Closure to reconnect from this manager with the name of
// the connection, which will allow us to reconnect from the connections.
$connection->setReconnector(function ($connection) {
$this->reconnect($connection->getName());
});
return $connection;
} | [
"protected",
"function",
"configure",
"(",
"Connection",
"$",
"connection",
",",
"$",
"type",
")",
"{",
"$",
"connection",
"=",
"$",
"this",
"->",
"setPdoForType",
"(",
"$",
"connection",
",",
"$",
"type",
")",
";",
"// First we'll set the fetch mode and a few other dependencies of the database",
"// connection. This method basically just configures and prepares it to get",
"// used by the application. Once we're finished we'll return it back out.",
"if",
"(",
"$",
"this",
"->",
"container",
"->",
"has",
"(",
"'events'",
")",
")",
"{",
"$",
"connection",
"->",
"setEventDispatcher",
"(",
"$",
"this",
"->",
"container",
"[",
"'events'",
"]",
")",
";",
"}",
"// Here we'll set a reconnector callback. This reconnector can be any callable",
"// so we will set a Closure to reconnect from this manager with the name of",
"// the connection, which will allow us to reconnect from the connections.",
"$",
"connection",
"->",
"setReconnector",
"(",
"function",
"(",
"$",
"connection",
")",
"{",
"$",
"this",
"->",
"reconnect",
"(",
"$",
"connection",
"->",
"getName",
"(",
")",
")",
";",
"}",
")",
";",
"return",
"$",
"connection",
";",
"}"
] | Prepare the database connection instance.
@param \Mellivora\Database\Connection $connection
@param string $type
@return \Mellivora\Database\Connection | [
"Prepare",
"the",
"database",
"connection",
"instance",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/DatabaseManager.php#L157-L176 |
FriendsOfApi/phraseapp | src/Api/HttpApi.php | HttpApi.httpPatch | protected function httpPatch(string $path, $body, array $requestHeaders = []): ResponseInterface
{
$requestHeaders['Content-Type'] = 'application/json';
return $response = $this->httpClient->sendRequest(
$this->requestBuilder->create('PATCH', $path, $requestHeaders, json_encode($body))
);
} | php | protected function httpPatch(string $path, $body, array $requestHeaders = []): ResponseInterface
{
$requestHeaders['Content-Type'] = 'application/json';
return $response = $this->httpClient->sendRequest(
$this->requestBuilder->create('PATCH', $path, $requestHeaders, json_encode($body))
);
} | [
"protected",
"function",
"httpPatch",
"(",
"string",
"$",
"path",
",",
"$",
"body",
",",
"array",
"$",
"requestHeaders",
"=",
"[",
"]",
")",
":",
"ResponseInterface",
"{",
"$",
"requestHeaders",
"[",
"'Content-Type'",
"]",
"=",
"'application/json'",
";",
"return",
"$",
"response",
"=",
"$",
"this",
"->",
"httpClient",
"->",
"sendRequest",
"(",
"$",
"this",
"->",
"requestBuilder",
"->",
"create",
"(",
"'PATCH'",
",",
"$",
"path",
",",
"$",
"requestHeaders",
",",
"json_encode",
"(",
"$",
"body",
")",
")",
")",
";",
"}"
] | Send a PATCH request with json encoded data.
@param string $path Request path
@param array|string $body Request body
@param array $requestHeaders Request headers
@return ResponseInterface | [
"Send",
"a",
"PATCH",
"request",
"with",
"json",
"encoded",
"data",
"."
] | train | https://github.com/FriendsOfApi/phraseapp/blob/1553bf857eb0858f9a7eb905b085864d24f80886/src/Api/HttpApi.php#L151-L158 |
FriendsOfApi/phraseapp | src/Api/HttpApi.php | HttpApi.handleErrors | protected function handleErrors(ResponseInterface $response)
{
switch ($response->getStatusCode()) {
case 401:
throw new DomainExceptions\InvalidApiKeyException('Invalid API key');
break;
case 403:
throw new DomainExceptions\InsufficientPrivilegesException('Insufficient Privileges');
break;
case 404:
throw new DomainExceptions\NotFoundException('Not found');
break;
case 422:
throw new DomainExceptions\UnprocessableEntityException('Unprocessable entity');
case 429:
throw new DomainExceptions\RateLimitExceededException('Rate limit exceeded');
default:
throw new DomainExceptions\UnknownErrorException('Unknown error');
break;
}
} | php | protected function handleErrors(ResponseInterface $response)
{
switch ($response->getStatusCode()) {
case 401:
throw new DomainExceptions\InvalidApiKeyException('Invalid API key');
break;
case 403:
throw new DomainExceptions\InsufficientPrivilegesException('Insufficient Privileges');
break;
case 404:
throw new DomainExceptions\NotFoundException('Not found');
break;
case 422:
throw new DomainExceptions\UnprocessableEntityException('Unprocessable entity');
case 429:
throw new DomainExceptions\RateLimitExceededException('Rate limit exceeded');
default:
throw new DomainExceptions\UnknownErrorException('Unknown error');
break;
}
} | [
"protected",
"function",
"handleErrors",
"(",
"ResponseInterface",
"$",
"response",
")",
"{",
"switch",
"(",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
")",
"{",
"case",
"401",
":",
"throw",
"new",
"DomainExceptions",
"\\",
"InvalidApiKeyException",
"(",
"'Invalid API key'",
")",
";",
"break",
";",
"case",
"403",
":",
"throw",
"new",
"DomainExceptions",
"\\",
"InsufficientPrivilegesException",
"(",
"'Insufficient Privileges'",
")",
";",
"break",
";",
"case",
"404",
":",
"throw",
"new",
"DomainExceptions",
"\\",
"NotFoundException",
"(",
"'Not found'",
")",
";",
"break",
";",
"case",
"422",
":",
"throw",
"new",
"DomainExceptions",
"\\",
"UnprocessableEntityException",
"(",
"'Unprocessable entity'",
")",
";",
"case",
"429",
":",
"throw",
"new",
"DomainExceptions",
"\\",
"RateLimitExceededException",
"(",
"'Rate limit exceeded'",
")",
";",
"default",
":",
"throw",
"new",
"DomainExceptions",
"\\",
"UnknownErrorException",
"(",
"'Unknown error'",
")",
";",
"break",
";",
"}",
"}"
] | Handle HTTP errors.
Call is controlled by the specific API methods.
@param ResponseInterface $response
@throws DomainException | [
"Handle",
"HTTP",
"errors",
"."
] | train | https://github.com/FriendsOfApi/phraseapp/blob/1553bf857eb0858f9a7eb905b085864d24f80886/src/Api/HttpApi.php#L169-L189 |
impensavel/essence | src/XML.php | XML.getCurrentNode | protected function getCurrentNode()
{
// Clear the libXML error buffer
libxml_clear_errors();
$node = @$this->reader->expand();
$error = libxml_get_last_error();
if ($error instanceof LibXMLError) {
// Only throw exceptions when the level is ERROR or FATAL
if ($error->level > LIBXML_ERR_WARNING) {
throw new EssenceException(sprintf('%s @ line #%d [%s]', trim($error->message), $error->line, $this->current), $error->code);
}
}
try {
return $this->doc->importNode($node, true);
} catch (DOMException $e) {
throw new EssenceException('Node import failed', 0, $e);
}
} | php | protected function getCurrentNode()
{
// Clear the libXML error buffer
libxml_clear_errors();
$node = @$this->reader->expand();
$error = libxml_get_last_error();
if ($error instanceof LibXMLError) {
// Only throw exceptions when the level is ERROR or FATAL
if ($error->level > LIBXML_ERR_WARNING) {
throw new EssenceException(sprintf('%s @ line #%d [%s]', trim($error->message), $error->line, $this->current), $error->code);
}
}
try {
return $this->doc->importNode($node, true);
} catch (DOMException $e) {
throw new EssenceException('Node import failed', 0, $e);
}
} | [
"protected",
"function",
"getCurrentNode",
"(",
")",
"{",
"// Clear the libXML error buffer",
"libxml_clear_errors",
"(",
")",
";",
"$",
"node",
"=",
"@",
"$",
"this",
"->",
"reader",
"->",
"expand",
"(",
")",
";",
"$",
"error",
"=",
"libxml_get_last_error",
"(",
")",
";",
"if",
"(",
"$",
"error",
"instanceof",
"LibXMLError",
")",
"{",
"// Only throw exceptions when the level is ERROR or FATAL",
"if",
"(",
"$",
"error",
"->",
"level",
">",
"LIBXML_ERR_WARNING",
")",
"{",
"throw",
"new",
"EssenceException",
"(",
"sprintf",
"(",
"'%s @ line #%d [%s]'",
",",
"trim",
"(",
"$",
"error",
"->",
"message",
")",
",",
"$",
"error",
"->",
"line",
",",
"$",
"this",
"->",
"current",
")",
",",
"$",
"error",
"->",
"code",
")",
";",
"}",
"}",
"try",
"{",
"return",
"$",
"this",
"->",
"doc",
"->",
"importNode",
"(",
"$",
"node",
",",
"true",
")",
";",
"}",
"catch",
"(",
"DOMException",
"$",
"e",
")",
"{",
"throw",
"new",
"EssenceException",
"(",
"'Node import failed'",
",",
"0",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Get the current node
@throws EssenceException
@return DOMNode | [
"Get",
"the",
"current",
"node"
] | train | https://github.com/impensavel/essence/blob/e74969e55ac889e8c2cab9a915f82e93a72e629e/src/XML.php#L118-L139 |
impensavel/essence | src/XML.php | XML.nextElement | protected function nextElement()
{
do {
if (! $this->reader->read()) {
return false;
}
// Pop previous levels from the stack
$this->stack = array_slice($this->stack, 0, $this->reader->depth, true);
// Push the current Element to the stack
$this->stack[] = $this->reader->name;
// Update the current Element XPath
$this->current = implode('/', $this->stack);
// Set skip to
$this->skip = ($this->skip == $this->current) ? null : $this->skip;
} while ($this->skip);
return true;
} | php | protected function nextElement()
{
do {
if (! $this->reader->read()) {
return false;
}
// Pop previous levels from the stack
$this->stack = array_slice($this->stack, 0, $this->reader->depth, true);
// Push the current Element to the stack
$this->stack[] = $this->reader->name;
// Update the current Element XPath
$this->current = implode('/', $this->stack);
// Set skip to
$this->skip = ($this->skip == $this->current) ? null : $this->skip;
} while ($this->skip);
return true;
} | [
"protected",
"function",
"nextElement",
"(",
")",
"{",
"do",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"reader",
"->",
"read",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Pop previous levels from the stack",
"$",
"this",
"->",
"stack",
"=",
"array_slice",
"(",
"$",
"this",
"->",
"stack",
",",
"0",
",",
"$",
"this",
"->",
"reader",
"->",
"depth",
",",
"true",
")",
";",
"// Push the current Element to the stack",
"$",
"this",
"->",
"stack",
"[",
"]",
"=",
"$",
"this",
"->",
"reader",
"->",
"name",
";",
"// Update the current Element XPath",
"$",
"this",
"->",
"current",
"=",
"implode",
"(",
"'/'",
",",
"$",
"this",
"->",
"stack",
")",
";",
"// Set skip to",
"$",
"this",
"->",
"skip",
"=",
"(",
"$",
"this",
"->",
"skip",
"==",
"$",
"this",
"->",
"current",
")",
"?",
"null",
":",
"$",
"this",
"->",
"skip",
";",
"}",
"while",
"(",
"$",
"this",
"->",
"skip",
")",
";",
"return",
"true",
";",
"}"
] | Read the next Element and handle skipping
@return bool | [
"Read",
"the",
"next",
"Element",
"and",
"handle",
"skipping"
] | train | https://github.com/impensavel/essence/blob/e74969e55ac889e8c2cab9a915f82e93a72e629e/src/XML.php#L146-L167 |
impensavel/essence | src/XML.php | XML.getData | protected function getData($xpath)
{
$xpath = trim($xpath, '/');
if (isset($this->data[$xpath])) {
return $this->data[$xpath];
}
throw new EssenceException('Unregistered Element XPath: "/'.$xpath.'"');
} | php | protected function getData($xpath)
{
$xpath = trim($xpath, '/');
if (isset($this->data[$xpath])) {
return $this->data[$xpath];
}
throw new EssenceException('Unregistered Element XPath: "/'.$xpath.'"');
} | [
"protected",
"function",
"getData",
"(",
"$",
"xpath",
")",
"{",
"$",
"xpath",
"=",
"trim",
"(",
"$",
"xpath",
",",
"'/'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"xpath",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"data",
"[",
"$",
"xpath",
"]",
";",
"}",
"throw",
"new",
"EssenceException",
"(",
"'Unregistered Element XPath: \"/'",
".",
"$",
"xpath",
".",
"'\"'",
")",
";",
"}"
] | Get registered Element data
@param string $xpath Element XPath
@throws EssenceException
@return mixed | [
"Get",
"registered",
"Element",
"data"
] | train | https://github.com/impensavel/essence/blob/e74969e55ac889e8c2cab9a915f82e93a72e629e/src/XML.php#L189-L198 |
impensavel/essence | src/XML.php | XML.prepare | protected function prepare($input, array $config)
{
if ($input instanceof SplFileInfo) {
if (@$this->reader->open($input->getPathname(), $config['encoding'], $config['options'])) {
return;
}
throw new EssenceException('Could not open "'.$input->getPathname().'" for parsing');
}
if (is_string($input)) {
if (@$this->reader->XML($input, $config['encoding'], $config['options'])) {
return;
}
throw new EssenceException('Could not set the XML input string for parsing');
}
if (is_resource($input)) {
$type = get_resource_type($input);
if ($type != 'stream') {
throw new EssenceException('Invalid resource type: '.$type);
}
$string = stream_get_contents($input);
if ($string === false) {
throw new EssenceException('Failed to read input from stream');
}
$this->prepare($string, $config);
return;
}
throw new EssenceException('Invalid input type: '.gettype($input));
} | php | protected function prepare($input, array $config)
{
if ($input instanceof SplFileInfo) {
if (@$this->reader->open($input->getPathname(), $config['encoding'], $config['options'])) {
return;
}
throw new EssenceException('Could not open "'.$input->getPathname().'" for parsing');
}
if (is_string($input)) {
if (@$this->reader->XML($input, $config['encoding'], $config['options'])) {
return;
}
throw new EssenceException('Could not set the XML input string for parsing');
}
if (is_resource($input)) {
$type = get_resource_type($input);
if ($type != 'stream') {
throw new EssenceException('Invalid resource type: '.$type);
}
$string = stream_get_contents($input);
if ($string === false) {
throw new EssenceException('Failed to read input from stream');
}
$this->prepare($string, $config);
return;
}
throw new EssenceException('Invalid input type: '.gettype($input));
} | [
"protected",
"function",
"prepare",
"(",
"$",
"input",
",",
"array",
"$",
"config",
")",
"{",
"if",
"(",
"$",
"input",
"instanceof",
"SplFileInfo",
")",
"{",
"if",
"(",
"@",
"$",
"this",
"->",
"reader",
"->",
"open",
"(",
"$",
"input",
"->",
"getPathname",
"(",
")",
",",
"$",
"config",
"[",
"'encoding'",
"]",
",",
"$",
"config",
"[",
"'options'",
"]",
")",
")",
"{",
"return",
";",
"}",
"throw",
"new",
"EssenceException",
"(",
"'Could not open \"'",
".",
"$",
"input",
"->",
"getPathname",
"(",
")",
".",
"'\" for parsing'",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"input",
")",
")",
"{",
"if",
"(",
"@",
"$",
"this",
"->",
"reader",
"->",
"XML",
"(",
"$",
"input",
",",
"$",
"config",
"[",
"'encoding'",
"]",
",",
"$",
"config",
"[",
"'options'",
"]",
")",
")",
"{",
"return",
";",
"}",
"throw",
"new",
"EssenceException",
"(",
"'Could not set the XML input string for parsing'",
")",
";",
"}",
"if",
"(",
"is_resource",
"(",
"$",
"input",
")",
")",
"{",
"$",
"type",
"=",
"get_resource_type",
"(",
"$",
"input",
")",
";",
"if",
"(",
"$",
"type",
"!=",
"'stream'",
")",
"{",
"throw",
"new",
"EssenceException",
"(",
"'Invalid resource type: '",
".",
"$",
"type",
")",
";",
"}",
"$",
"string",
"=",
"stream_get_contents",
"(",
"$",
"input",
")",
";",
"if",
"(",
"$",
"string",
"===",
"false",
")",
"{",
"throw",
"new",
"EssenceException",
"(",
"'Failed to read input from stream'",
")",
";",
"}",
"$",
"this",
"->",
"prepare",
"(",
"$",
"string",
",",
"$",
"config",
")",
";",
"return",
";",
"}",
"throw",
"new",
"EssenceException",
"(",
"'Invalid input type: '",
".",
"gettype",
"(",
"$",
"input",
")",
")",
";",
"}"
] | Prepare data for extraction
@param mixed $input Input data
@param array $config Configuration settings
@throws EssenceException
@return void | [
"Prepare",
"data",
"for",
"extraction"
] | train | https://github.com/impensavel/essence/blob/e74969e55ac889e8c2cab9a915f82e93a72e629e/src/XML.php#L208-L245 |
impensavel/essence | src/XML.php | XML.DOMNodeChildCount | protected static function DOMNodeChildCount(DOMNode $node)
{
$count = 0;
if ($node->hasChildNodes()) {
foreach ($node->childNodes as $child) {
if ($child->nodeType == XML_ELEMENT_NODE) {
$count++;
}
}
}
return $count;
} | php | protected static function DOMNodeChildCount(DOMNode $node)
{
$count = 0;
if ($node->hasChildNodes()) {
foreach ($node->childNodes as $child) {
if ($child->nodeType == XML_ELEMENT_NODE) {
$count++;
}
}
}
return $count;
} | [
"protected",
"static",
"function",
"DOMNodeChildCount",
"(",
"DOMNode",
"$",
"node",
")",
"{",
"$",
"count",
"=",
"0",
";",
"if",
"(",
"$",
"node",
"->",
"hasChildNodes",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"node",
"->",
"childNodes",
"as",
"$",
"child",
")",
"{",
"if",
"(",
"$",
"child",
"->",
"nodeType",
"==",
"XML_ELEMENT_NODE",
")",
"{",
"$",
"count",
"++",
";",
"}",
"}",
"}",
"return",
"$",
"count",
";",
"}"
] | Count the children of a DOMNode
@static
@param DOMNode $node
@return int | [
"Count",
"the",
"children",
"of",
"a",
"DOMNode"
] | train | https://github.com/impensavel/essence/blob/e74969e55ac889e8c2cab9a915f82e93a72e629e/src/XML.php#L254-L267 |
impensavel/essence | src/XML.php | XML.DOMNodeAttributes | protected static function DOMNodeAttributes(DOMNode $node)
{
$attributes = array();
foreach ($node->attributes as $attribute) {
$attributes[$attribute->name] = $attribute->value;
}
return $attributes;
} | php | protected static function DOMNodeAttributes(DOMNode $node)
{
$attributes = array();
foreach ($node->attributes as $attribute) {
$attributes[$attribute->name] = $attribute->value;
}
return $attributes;
} | [
"protected",
"static",
"function",
"DOMNodeAttributes",
"(",
"DOMNode",
"$",
"node",
")",
"{",
"$",
"attributes",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"node",
"->",
"attributes",
"as",
"$",
"attribute",
")",
"{",
"$",
"attributes",
"[",
"$",
"attribute",
"->",
"name",
"]",
"=",
"$",
"attribute",
"->",
"value",
";",
"}",
"return",
"$",
"attributes",
";",
"}"
] | Get the DONNode attributes
@static
@param DOMNode $node
@return array | [
"Get",
"the",
"DONNode",
"attributes"
] | train | https://github.com/impensavel/essence/blob/e74969e55ac889e8c2cab9a915f82e93a72e629e/src/XML.php#L276-L285 |
impensavel/essence | src/XML.php | XML.DOMNodeValue | protected static function DOMNodeValue(DOMNode $node, $associative = false, $attributes = false)
{
// Return the value immediately when we're dealing with a leaf
// node without attributes or we simply don't want them included
if (static::DOMNodeChildCount($node) == 0 && ($node->hasAttributes() === false || $attributes === false)) {
return $node->nodeValue;
}
$children = array();
if ($node->hasAttributes() && $attributes) {
$children['@'] = static::DOMNodeAttributes($node);
}
foreach ($node->childNodes as $child) {
// Skip text nodes containing whitespace
if ($child instanceof DOMText && $child->isWhitespaceInElementContent()) {
continue;
}
if (static::DOMNodeChildCount($child) > 0) {
$value = static::DOMNodeValue($child, $associative);
} else {
$value = $child->nodeValue;
}
if ($associative) {
$children[$child->nodeName][] = $value;
} else {
$children[] = $value;
}
}
return $children;
} | php | protected static function DOMNodeValue(DOMNode $node, $associative = false, $attributes = false)
{
// Return the value immediately when we're dealing with a leaf
// node without attributes or we simply don't want them included
if (static::DOMNodeChildCount($node) == 0 && ($node->hasAttributes() === false || $attributes === false)) {
return $node->nodeValue;
}
$children = array();
if ($node->hasAttributes() && $attributes) {
$children['@'] = static::DOMNodeAttributes($node);
}
foreach ($node->childNodes as $child) {
// Skip text nodes containing whitespace
if ($child instanceof DOMText && $child->isWhitespaceInElementContent()) {
continue;
}
if (static::DOMNodeChildCount($child) > 0) {
$value = static::DOMNodeValue($child, $associative);
} else {
$value = $child->nodeValue;
}
if ($associative) {
$children[$child->nodeName][] = $value;
} else {
$children[] = $value;
}
}
return $children;
} | [
"protected",
"static",
"function",
"DOMNodeValue",
"(",
"DOMNode",
"$",
"node",
",",
"$",
"associative",
"=",
"false",
",",
"$",
"attributes",
"=",
"false",
")",
"{",
"// Return the value immediately when we're dealing with a leaf",
"// node without attributes or we simply don't want them included",
"if",
"(",
"static",
"::",
"DOMNodeChildCount",
"(",
"$",
"node",
")",
"==",
"0",
"&&",
"(",
"$",
"node",
"->",
"hasAttributes",
"(",
")",
"===",
"false",
"||",
"$",
"attributes",
"===",
"false",
")",
")",
"{",
"return",
"$",
"node",
"->",
"nodeValue",
";",
"}",
"$",
"children",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"node",
"->",
"hasAttributes",
"(",
")",
"&&",
"$",
"attributes",
")",
"{",
"$",
"children",
"[",
"'@'",
"]",
"=",
"static",
"::",
"DOMNodeAttributes",
"(",
"$",
"node",
")",
";",
"}",
"foreach",
"(",
"$",
"node",
"->",
"childNodes",
"as",
"$",
"child",
")",
"{",
"// Skip text nodes containing whitespace",
"if",
"(",
"$",
"child",
"instanceof",
"DOMText",
"&&",
"$",
"child",
"->",
"isWhitespaceInElementContent",
"(",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"static",
"::",
"DOMNodeChildCount",
"(",
"$",
"child",
")",
">",
"0",
")",
"{",
"$",
"value",
"=",
"static",
"::",
"DOMNodeValue",
"(",
"$",
"child",
",",
"$",
"associative",
")",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"$",
"child",
"->",
"nodeValue",
";",
"}",
"if",
"(",
"$",
"associative",
")",
"{",
"$",
"children",
"[",
"$",
"child",
"->",
"nodeName",
"]",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"children",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"children",
";",
"}"
] | Get the DOMNode value
@static
@param DOMNode $node
@param bool $associative Return associative array?
@param bool $attributes Include node attributes?
@return mixed | [
"Get",
"the",
"DOMNode",
"value"
] | train | https://github.com/impensavel/essence/blob/e74969e55ac889e8c2cab9a915f82e93a72e629e/src/XML.php#L296-L330 |
impensavel/essence | src/XML.php | XML.DOMNodeListToArray | public static function DOMNodeListToArray(DOMNodeList $nodeList, $associative = false, $attributes = false)
{
$nodes = array();
foreach ($nodeList as $node) {
$nodes[] = static::DOMNodeValue($node, $associative, $attributes);
}
return $nodes;
} | php | public static function DOMNodeListToArray(DOMNodeList $nodeList, $associative = false, $attributes = false)
{
$nodes = array();
foreach ($nodeList as $node) {
$nodes[] = static::DOMNodeValue($node, $associative, $attributes);
}
return $nodes;
} | [
"public",
"static",
"function",
"DOMNodeListToArray",
"(",
"DOMNodeList",
"$",
"nodeList",
",",
"$",
"associative",
"=",
"false",
",",
"$",
"attributes",
"=",
"false",
")",
"{",
"$",
"nodes",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"nodeList",
"as",
"$",
"node",
")",
"{",
"$",
"nodes",
"[",
"]",
"=",
"static",
"::",
"DOMNodeValue",
"(",
"$",
"node",
",",
"$",
"associative",
",",
"$",
"attributes",
")",
";",
"}",
"return",
"$",
"nodes",
";",
"}"
] | Convert a DOMNodeList into an Array
@static
@param DOMNodeList $nodeList
@param bool $associative Return associative array?
@param bool $attributes Include node attributes?
@return array | [
"Convert",
"a",
"DOMNodeList",
"into",
"an",
"Array"
] | train | https://github.com/impensavel/essence/blob/e74969e55ac889e8c2cab9a915f82e93a72e629e/src/XML.php#L341-L350 |
impensavel/essence | src/XML.php | XML.extract | public function extract($input, array $config = array(), &$data = null)
{
$config = array_replace_recursive(array(
'encoding' => 'UTF-8',
'options' => LIBXML_PARSEHUGE,
), $config);
$this->prepare($input, $config);
while ($this->nextElement()) {
if (! $this->reader->isEmptyElement && $this->reader->nodeType === XMLReader::ELEMENT && $this->isMapped($this->current)) {
$node = $this->getCurrentNode();
// Current element properties
$properties = array();
foreach ($this->maps[$this->current] as $key => $xpath) {
$xpath = trim($xpath);
// Get registered Element data
if (strpos($xpath, '#') === 0) {
$properties[$key] = $this->getData(substr($xpath, 1));
// Get evaluated XPath data
} else {
$properties[$key] = $this->element->evaluate($xpath, $node);
if ($properties[$key] === false) {
throw new EssenceException('Invalid XPath expression: "'.$xpath.'"');
}
}
}
// Execute element data handler
$arguments = array(
'/'.$this->current,
$properties,
&$data,
);
$result = call_user_func_array($this->handlers[$this->current], $arguments);
if ($result) {
// Skip to Element
if ($this->isMapped($result)) {
$this->skip = $result;
// Store Element data
} else {
$this->data[$this->current] = $result;
}
}
}
}
return true;
} | php | public function extract($input, array $config = array(), &$data = null)
{
$config = array_replace_recursive(array(
'encoding' => 'UTF-8',
'options' => LIBXML_PARSEHUGE,
), $config);
$this->prepare($input, $config);
while ($this->nextElement()) {
if (! $this->reader->isEmptyElement && $this->reader->nodeType === XMLReader::ELEMENT && $this->isMapped($this->current)) {
$node = $this->getCurrentNode();
// Current element properties
$properties = array();
foreach ($this->maps[$this->current] as $key => $xpath) {
$xpath = trim($xpath);
// Get registered Element data
if (strpos($xpath, '#') === 0) {
$properties[$key] = $this->getData(substr($xpath, 1));
// Get evaluated XPath data
} else {
$properties[$key] = $this->element->evaluate($xpath, $node);
if ($properties[$key] === false) {
throw new EssenceException('Invalid XPath expression: "'.$xpath.'"');
}
}
}
// Execute element data handler
$arguments = array(
'/'.$this->current,
$properties,
&$data,
);
$result = call_user_func_array($this->handlers[$this->current], $arguments);
if ($result) {
// Skip to Element
if ($this->isMapped($result)) {
$this->skip = $result;
// Store Element data
} else {
$this->data[$this->current] = $result;
}
}
}
}
return true;
} | [
"public",
"function",
"extract",
"(",
"$",
"input",
",",
"array",
"$",
"config",
"=",
"array",
"(",
")",
",",
"&",
"$",
"data",
"=",
"null",
")",
"{",
"$",
"config",
"=",
"array_replace_recursive",
"(",
"array",
"(",
"'encoding'",
"=>",
"'UTF-8'",
",",
"'options'",
"=>",
"LIBXML_PARSEHUGE",
",",
")",
",",
"$",
"config",
")",
";",
"$",
"this",
"->",
"prepare",
"(",
"$",
"input",
",",
"$",
"config",
")",
";",
"while",
"(",
"$",
"this",
"->",
"nextElement",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"reader",
"->",
"isEmptyElement",
"&&",
"$",
"this",
"->",
"reader",
"->",
"nodeType",
"===",
"XMLReader",
"::",
"ELEMENT",
"&&",
"$",
"this",
"->",
"isMapped",
"(",
"$",
"this",
"->",
"current",
")",
")",
"{",
"$",
"node",
"=",
"$",
"this",
"->",
"getCurrentNode",
"(",
")",
";",
"// Current element properties",
"$",
"properties",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"maps",
"[",
"$",
"this",
"->",
"current",
"]",
"as",
"$",
"key",
"=>",
"$",
"xpath",
")",
"{",
"$",
"xpath",
"=",
"trim",
"(",
"$",
"xpath",
")",
";",
"// Get registered Element data",
"if",
"(",
"strpos",
"(",
"$",
"xpath",
",",
"'#'",
")",
"===",
"0",
")",
"{",
"$",
"properties",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"getData",
"(",
"substr",
"(",
"$",
"xpath",
",",
"1",
")",
")",
";",
"// Get evaluated XPath data",
"}",
"else",
"{",
"$",
"properties",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"element",
"->",
"evaluate",
"(",
"$",
"xpath",
",",
"$",
"node",
")",
";",
"if",
"(",
"$",
"properties",
"[",
"$",
"key",
"]",
"===",
"false",
")",
"{",
"throw",
"new",
"EssenceException",
"(",
"'Invalid XPath expression: \"'",
".",
"$",
"xpath",
".",
"'\"'",
")",
";",
"}",
"}",
"}",
"// Execute element data handler",
"$",
"arguments",
"=",
"array",
"(",
"'/'",
".",
"$",
"this",
"->",
"current",
",",
"$",
"properties",
",",
"&",
"$",
"data",
",",
")",
";",
"$",
"result",
"=",
"call_user_func_array",
"(",
"$",
"this",
"->",
"handlers",
"[",
"$",
"this",
"->",
"current",
"]",
",",
"$",
"arguments",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
"// Skip to Element",
"if",
"(",
"$",
"this",
"->",
"isMapped",
"(",
"$",
"result",
")",
")",
"{",
"$",
"this",
"->",
"skip",
"=",
"$",
"result",
";",
"// Store Element data",
"}",
"else",
"{",
"$",
"this",
"->",
"data",
"[",
"$",
"this",
"->",
"current",
"]",
"=",
"$",
"result",
";",
"}",
"}",
"}",
"}",
"return",
"true",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/impensavel/essence/blob/e74969e55ac889e8c2cab9a915f82e93a72e629e/src/XML.php#L355-L411 |
impensavel/essence | src/XML.php | XML.dump | public function dump($input, array $config = array())
{
$config = array_replace_recursive(array(
'encoding' => 'UTF-8',
'options' => LIBXML_PARSEHUGE,
), $config);
$this->prepare($input, $config);
$paths = array();
while ($this->nextElement()) {
if (! $this->reader->isEmptyElement && $this->reader->nodeType === XMLReader::ELEMENT) {
$paths[] = $this->current;
}
}
return array_count_values($paths);
} | php | public function dump($input, array $config = array())
{
$config = array_replace_recursive(array(
'encoding' => 'UTF-8',
'options' => LIBXML_PARSEHUGE,
), $config);
$this->prepare($input, $config);
$paths = array();
while ($this->nextElement()) {
if (! $this->reader->isEmptyElement && $this->reader->nodeType === XMLReader::ELEMENT) {
$paths[] = $this->current;
}
}
return array_count_values($paths);
} | [
"public",
"function",
"dump",
"(",
"$",
"input",
",",
"array",
"$",
"config",
"=",
"array",
"(",
")",
")",
"{",
"$",
"config",
"=",
"array_replace_recursive",
"(",
"array",
"(",
"'encoding'",
"=>",
"'UTF-8'",
",",
"'options'",
"=>",
"LIBXML_PARSEHUGE",
",",
")",
",",
"$",
"config",
")",
";",
"$",
"this",
"->",
"prepare",
"(",
"$",
"input",
",",
"$",
"config",
")",
";",
"$",
"paths",
"=",
"array",
"(",
")",
";",
"while",
"(",
"$",
"this",
"->",
"nextElement",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"reader",
"->",
"isEmptyElement",
"&&",
"$",
"this",
"->",
"reader",
"->",
"nodeType",
"===",
"XMLReader",
"::",
"ELEMENT",
")",
"{",
"$",
"paths",
"[",
"]",
"=",
"$",
"this",
"->",
"current",
";",
"}",
"}",
"return",
"array_count_values",
"(",
"$",
"paths",
")",
";",
"}"
] | Dump XPaths and all their occurrences
@param mixed $input Input data
@param array $config Configuration settings (optional)
@return array | [
"Dump",
"XPaths",
"and",
"all",
"their",
"occurrences"
] | train | https://github.com/impensavel/essence/blob/e74969e55ac889e8c2cab9a915f82e93a72e629e/src/XML.php#L420-L438 |
mridang/magazine | lib/magento/Validator.php | Mage_Connect_Validator.compareStabilities | public function compareStabilities($s1, $s2)
{
$list = $this->getStabilities();
$tmp = array_combine(array_values($list),array_keys($list));
if(!isset($tmp[$s1], $tmp[$s2])) {
throw new Exception("Invalid stability in compareStabilities argument");
}
// 'stable' turns to 3
// 'devel' turns to 0
$s1 = $tmp[$s1];
$s2 = $tmp[$s2];
if($s1 === $s2) {
return 0;
} elseif($s1 > $s2) {
return 1;
} elseif($s1 < $s2) {
return -1;
}
} | php | public function compareStabilities($s1, $s2)
{
$list = $this->getStabilities();
$tmp = array_combine(array_values($list),array_keys($list));
if(!isset($tmp[$s1], $tmp[$s2])) {
throw new Exception("Invalid stability in compareStabilities argument");
}
// 'stable' turns to 3
// 'devel' turns to 0
$s1 = $tmp[$s1];
$s2 = $tmp[$s2];
if($s1 === $s2) {
return 0;
} elseif($s1 > $s2) {
return 1;
} elseif($s1 < $s2) {
return -1;
}
} | [
"public",
"function",
"compareStabilities",
"(",
"$",
"s1",
",",
"$",
"s2",
")",
"{",
"$",
"list",
"=",
"$",
"this",
"->",
"getStabilities",
"(",
")",
";",
"$",
"tmp",
"=",
"array_combine",
"(",
"array_values",
"(",
"$",
"list",
")",
",",
"array_keys",
"(",
"$",
"list",
")",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"tmp",
"[",
"$",
"s1",
"]",
",",
"$",
"tmp",
"[",
"$",
"s2",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Invalid stability in compareStabilities argument\"",
")",
";",
"}",
"// 'stable' turns to 3",
"// 'devel' turns to 0",
"$",
"s1",
"=",
"$",
"tmp",
"[",
"$",
"s1",
"]",
";",
"$",
"s2",
"=",
"$",
"tmp",
"[",
"$",
"s2",
"]",
";",
"if",
"(",
"$",
"s1",
"===",
"$",
"s2",
")",
"{",
"return",
"0",
";",
"}",
"elseif",
"(",
"$",
"s1",
">",
"$",
"s2",
")",
"{",
"return",
"1",
";",
"}",
"elseif",
"(",
"$",
"s1",
"<",
"$",
"s2",
")",
"{",
"return",
"-",
"1",
";",
"}",
"}"
] | Compare stabilities. Returns:
-1 if the first stability is lower than the second
0 if they are equal
1 if the second is lower.
@param $s1
@param $s2
@return int | [
"Compare",
"stabilities",
".",
"Returns",
":"
] | train | https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Validator.php#L57-L78 |
mridang/magazine | lib/magento/Validator.php | Mage_Connect_Validator.validateLicenseUrl | public function validateLicenseUrl($str)
{
if ($str) {
return ( $this->validateUrl($str) || $this->validatePackageName($str));
}
return true;
} | php | public function validateLicenseUrl($str)
{
if ($str) {
return ( $this->validateUrl($str) || $this->validatePackageName($str));
}
return true;
} | [
"public",
"function",
"validateLicenseUrl",
"(",
"$",
"str",
")",
"{",
"if",
"(",
"$",
"str",
")",
"{",
"return",
"(",
"$",
"this",
"->",
"validateUrl",
"(",
"$",
"str",
")",
"||",
"$",
"this",
"->",
"validatePackageName",
"(",
"$",
"str",
")",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Validate License url
@param mixed $str
@return boolean | [
"Validate",
"License",
"url"
] | train | https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Validator.php#L116-L122 |
mridang/magazine | lib/magento/Validator.php | Mage_Connect_Validator.validateCompatible | public function validateCompatible(array $data)
{
if(!count($data)) {
/**
* Allow empty
*/
return true;
}
$count = 0;
foreach($data as $k=>$v) {
foreach(array('name','channel','min','max') as $fld) {
$$fld = trim($v[$fld]);
}
$count++;
$res = $this->validateUrl($channel) && strlen($channel);
if(!$res) {
$this->addError("Invalid or empty channel in compat. #{$count}");
}
$res = $this->validatePackageName($name) && strlen($name);
if(!$res) {
$this->addError("Invalid or empty name in compat. #{$count}");
}
$res1 = $this->validateVersion($min);
if(!$res1) {
$this->addError("Invalid or empty minVersion in compat. #{$count}");
}
$res2 = $this->validateVersion($max);
if(!$res2) {
$this->addError("Invalid or empty maxVersion in compat. #{$count}");
}
if($res1 && $res2 && $this->versionLower($max, $min)) {
$this->addError("Max version is lower than min in compat #{$count}");
}
}
return ! $this->hasErrors();
} | php | public function validateCompatible(array $data)
{
if(!count($data)) {
/**
* Allow empty
*/
return true;
}
$count = 0;
foreach($data as $k=>$v) {
foreach(array('name','channel','min','max') as $fld) {
$$fld = trim($v[$fld]);
}
$count++;
$res = $this->validateUrl($channel) && strlen($channel);
if(!$res) {
$this->addError("Invalid or empty channel in compat. #{$count}");
}
$res = $this->validatePackageName($name) && strlen($name);
if(!$res) {
$this->addError("Invalid or empty name in compat. #{$count}");
}
$res1 = $this->validateVersion($min);
if(!$res1) {
$this->addError("Invalid or empty minVersion in compat. #{$count}");
}
$res2 = $this->validateVersion($max);
if(!$res2) {
$this->addError("Invalid or empty maxVersion in compat. #{$count}");
}
if($res1 && $res2 && $this->versionLower($max, $min)) {
$this->addError("Max version is lower than min in compat #{$count}");
}
}
return ! $this->hasErrors();
} | [
"public",
"function",
"validateCompatible",
"(",
"array",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"count",
"(",
"$",
"data",
")",
")",
"{",
"/**\n * Allow empty\n */",
"return",
"true",
";",
"}",
"$",
"count",
"=",
"0",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"foreach",
"(",
"array",
"(",
"'name'",
",",
"'channel'",
",",
"'min'",
",",
"'max'",
")",
"as",
"$",
"fld",
")",
"{",
"$",
"$",
"fld",
"=",
"trim",
"(",
"$",
"v",
"[",
"$",
"fld",
"]",
")",
";",
"}",
"$",
"count",
"++",
";",
"$",
"res",
"=",
"$",
"this",
"->",
"validateUrl",
"(",
"$",
"channel",
")",
"&&",
"strlen",
"(",
"$",
"channel",
")",
";",
"if",
"(",
"!",
"$",
"res",
")",
"{",
"$",
"this",
"->",
"addError",
"(",
"\"Invalid or empty channel in compat. #{$count}\"",
")",
";",
"}",
"$",
"res",
"=",
"$",
"this",
"->",
"validatePackageName",
"(",
"$",
"name",
")",
"&&",
"strlen",
"(",
"$",
"name",
")",
";",
"if",
"(",
"!",
"$",
"res",
")",
"{",
"$",
"this",
"->",
"addError",
"(",
"\"Invalid or empty name in compat. #{$count}\"",
")",
";",
"}",
"$",
"res1",
"=",
"$",
"this",
"->",
"validateVersion",
"(",
"$",
"min",
")",
";",
"if",
"(",
"!",
"$",
"res1",
")",
"{",
"$",
"this",
"->",
"addError",
"(",
"\"Invalid or empty minVersion in compat. #{$count}\"",
")",
";",
"}",
"$",
"res2",
"=",
"$",
"this",
"->",
"validateVersion",
"(",
"$",
"max",
")",
";",
"if",
"(",
"!",
"$",
"res2",
")",
"{",
"$",
"this",
"->",
"addError",
"(",
"\"Invalid or empty maxVersion in compat. #{$count}\"",
")",
";",
"}",
"if",
"(",
"$",
"res1",
"&&",
"$",
"res2",
"&&",
"$",
"this",
"->",
"versionLower",
"(",
"$",
"max",
",",
"$",
"min",
")",
")",
"{",
"$",
"this",
"->",
"addError",
"(",
"\"Max version is lower than min in compat #{$count}\"",
")",
";",
"}",
"}",
"return",
"!",
"$",
"this",
"->",
"hasErrors",
"(",
")",
";",
"}"
] | Validate compatible data
@param array $data
@return bool | [
"Validate",
"compatible",
"data"
] | train | https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Validator.php#L129-L167 |
mridang/magazine | lib/magento/Validator.php | Mage_Connect_Validator.validateAuthors | public function validateAuthors(array $authors)
{
if(!count($authors)) {
$this->addError('Empty authors section');
return false;
}
$count = 0;
foreach($authors as $k=>$v) {
$count++;
array_map('trim', $v);
$name = $v['name'];
$login = $v['user'];
$email = $v['email'];
$res = $this->validateMaxLen($name, 256) && strlen($name);
if(!$res) {
$this->addError("Invalid or empty name for author #{$count}");
}
$res = $this->validatePackageName($login) && strlen($login);
if(!$res) {
$this->addError("Invalid or empty login for author #{$count}");
}
$res = $this->validateEmail($email);
if(!$res) {
$this->addError("Invalid or empty email for author #{$count}");
}
}
return ! $this->hasErrors();
} | php | public function validateAuthors(array $authors)
{
if(!count($authors)) {
$this->addError('Empty authors section');
return false;
}
$count = 0;
foreach($authors as $k=>$v) {
$count++;
array_map('trim', $v);
$name = $v['name'];
$login = $v['user'];
$email = $v['email'];
$res = $this->validateMaxLen($name, 256) && strlen($name);
if(!$res) {
$this->addError("Invalid or empty name for author #{$count}");
}
$res = $this->validatePackageName($login) && strlen($login);
if(!$res) {
$this->addError("Invalid or empty login for author #{$count}");
}
$res = $this->validateEmail($email);
if(!$res) {
$this->addError("Invalid or empty email for author #{$count}");
}
}
return ! $this->hasErrors();
} | [
"public",
"function",
"validateAuthors",
"(",
"array",
"$",
"authors",
")",
"{",
"if",
"(",
"!",
"count",
"(",
"$",
"authors",
")",
")",
"{",
"$",
"this",
"->",
"addError",
"(",
"'Empty authors section'",
")",
";",
"return",
"false",
";",
"}",
"$",
"count",
"=",
"0",
";",
"foreach",
"(",
"$",
"authors",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"count",
"++",
";",
"array_map",
"(",
"'trim'",
",",
"$",
"v",
")",
";",
"$",
"name",
"=",
"$",
"v",
"[",
"'name'",
"]",
";",
"$",
"login",
"=",
"$",
"v",
"[",
"'user'",
"]",
";",
"$",
"email",
"=",
"$",
"v",
"[",
"'email'",
"]",
";",
"$",
"res",
"=",
"$",
"this",
"->",
"validateMaxLen",
"(",
"$",
"name",
",",
"256",
")",
"&&",
"strlen",
"(",
"$",
"name",
")",
";",
"if",
"(",
"!",
"$",
"res",
")",
"{",
"$",
"this",
"->",
"addError",
"(",
"\"Invalid or empty name for author #{$count}\"",
")",
";",
"}",
"$",
"res",
"=",
"$",
"this",
"->",
"validatePackageName",
"(",
"$",
"login",
")",
"&&",
"strlen",
"(",
"$",
"login",
")",
";",
"if",
"(",
"!",
"$",
"res",
")",
"{",
"$",
"this",
"->",
"addError",
"(",
"\"Invalid or empty login for author #{$count}\"",
")",
";",
"}",
"$",
"res",
"=",
"$",
"this",
"->",
"validateEmail",
"(",
"$",
"email",
")",
";",
"if",
"(",
"!",
"$",
"res",
")",
"{",
"$",
"this",
"->",
"addError",
"(",
"\"Invalid or empty email for author #{$count}\"",
")",
";",
"}",
"}",
"return",
"!",
"$",
"this",
"->",
"hasErrors",
"(",
")",
";",
"}"
] | Validate authors of package
@param array $authors
@return bool | [
"Validate",
"authors",
"of",
"package"
] | train | https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Validator.php#L174-L201 |
mridang/magazine | lib/magento/Validator.php | Mage_Connect_Validator.getErrors | public function getErrors($clear = true)
{
$out = $this->_errors;
if($clear) {
$this->clearErrors();
}
return $out;
} | php | public function getErrors($clear = true)
{
$out = $this->_errors;
if($clear) {
$this->clearErrors();
}
return $out;
} | [
"public",
"function",
"getErrors",
"(",
"$",
"clear",
"=",
"true",
")",
"{",
"$",
"out",
"=",
"$",
"this",
"->",
"_errors",
";",
"if",
"(",
"$",
"clear",
")",
"{",
"$",
"this",
"->",
"clearErrors",
"(",
")",
";",
"}",
"return",
"$",
"out",
";",
"}"
] | Get errors
@param bool $clear if true after this call erros will be cleared
@return array | [
"Get",
"errors"
] | train | https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Validator.php#L255-L262 |
mridang/magazine | lib/magento/Validator.php | Mage_Connect_Validator.validateDate | public function validateDate($date)
{
$subs = null;
$check1 = preg_match("/^([\d]{4})-([\d]{2})-([\d]{2})$/i", $date, $subs);
if(!$check1) {
return false;
}
return checkdate($subs[2], $subs[3], $subs[1]);
} | php | public function validateDate($date)
{
$subs = null;
$check1 = preg_match("/^([\d]{4})-([\d]{2})-([\d]{2})$/i", $date, $subs);
if(!$check1) {
return false;
}
return checkdate($subs[2], $subs[3], $subs[1]);
} | [
"public",
"function",
"validateDate",
"(",
"$",
"date",
")",
"{",
"$",
"subs",
"=",
"null",
";",
"$",
"check1",
"=",
"preg_match",
"(",
"\"/^([\\d]{4})-([\\d]{2})-([\\d]{2})$/i\"",
",",
"$",
"date",
",",
"$",
"subs",
")",
";",
"if",
"(",
"!",
"$",
"check1",
")",
"{",
"return",
"false",
";",
"}",
"return",
"checkdate",
"(",
"$",
"subs",
"[",
"2",
"]",
",",
"$",
"subs",
"[",
"3",
"]",
",",
"$",
"subs",
"[",
"1",
"]",
")",
";",
"}"
] | Validate date format
@param $date
@return bool | [
"Validate",
"date",
"format"
] | train | https://github.com/mridang/magazine/blob/5b3cfecc472c61fde6af63efe62690a30a267a04/lib/magento/Validator.php#L293-L301 |
juskiewicz/Geolocation | src/Http/AbstractHttp.php | AbstractHttp.getUrlContents | protected function getUrlContents(string $url) : string
{
$response = $this->getHttpClient()->get(
$url,
['future' => true]
);
$statusCode = $response->getStatusCode();
if (401 === $statusCode || 403 === $statusCode) {
throw new InvalidCredentials();
} elseif (429 === $statusCode) {
throw new QuotaExceeded();
} elseif ($statusCode >= 300) {
throw InvalidServerResponse::create((string) $url, $statusCode);
}
$body = (string) $response->getBody();
if (empty($body)) {
throw InvalidServerResponse::emptyResponse((string) $url);
}
return $body;
} | php | protected function getUrlContents(string $url) : string
{
$response = $this->getHttpClient()->get(
$url,
['future' => true]
);
$statusCode = $response->getStatusCode();
if (401 === $statusCode || 403 === $statusCode) {
throw new InvalidCredentials();
} elseif (429 === $statusCode) {
throw new QuotaExceeded();
} elseif ($statusCode >= 300) {
throw InvalidServerResponse::create((string) $url, $statusCode);
}
$body = (string) $response->getBody();
if (empty($body)) {
throw InvalidServerResponse::emptyResponse((string) $url);
}
return $body;
} | [
"protected",
"function",
"getUrlContents",
"(",
"string",
"$",
"url",
")",
":",
"string",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"getHttpClient",
"(",
")",
"->",
"get",
"(",
"$",
"url",
",",
"[",
"'future'",
"=>",
"true",
"]",
")",
";",
"$",
"statusCode",
"=",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
";",
"if",
"(",
"401",
"===",
"$",
"statusCode",
"||",
"403",
"===",
"$",
"statusCode",
")",
"{",
"throw",
"new",
"InvalidCredentials",
"(",
")",
";",
"}",
"elseif",
"(",
"429",
"===",
"$",
"statusCode",
")",
"{",
"throw",
"new",
"QuotaExceeded",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"statusCode",
">=",
"300",
")",
"{",
"throw",
"InvalidServerResponse",
"::",
"create",
"(",
"(",
"string",
")",
"$",
"url",
",",
"$",
"statusCode",
")",
";",
"}",
"$",
"body",
"=",
"(",
"string",
")",
"$",
"response",
"->",
"getBody",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"body",
")",
")",
"{",
"throw",
"InvalidServerResponse",
"::",
"emptyResponse",
"(",
"(",
"string",
")",
"$",
"url",
")",
";",
"}",
"return",
"$",
"body",
";",
"}"
] | Get URL and return contents. If content is empty, an exception will be thrown.
@param string $url
@return string
@throws InvalidCredentials
@throws InvalidServerResponse
@throws QuotaExceeded | [
"Get",
"URL",
"and",
"return",
"contents",
".",
"If",
"content",
"is",
"empty",
"an",
"exception",
"will",
"be",
"thrown",
"."
] | train | https://github.com/juskiewicz/Geolocation/blob/5d3cd393961b92bdfbe2dfe631fbfb62c72dc36d/src/Http/AbstractHttp.php#L32-L54 |
digipolisgent/robo-digipolis-package | src/ThemeCompile.php | ThemeCompile.run | public function run()
{
// Print the output of the compile commands.
$this->printed();
if (file_exists($this->dir . '/Gemfile')) {
$bundle = $this->findExecutable('bundle');
$this->processes[] = new Process(
$this->receiveCommand($bundle . ' install --deployment --no-cache'),
$this->dir,
null,
null,
null
);
}
if (file_exists($this->dir . '/package.json')) {
$executable = $this->findExecutable(file_exists($this->dir . '/yarn.lock') ? 'yarn' : 'npm');
$this->processes[] = new Process(
$this->receiveCommand($executable . ' install'),
$this->dir,
null,
null,
null
);
}
// Grunt/gulp and bower must wait for the previous processes to finish.
$result = parent::run();
if ($result->getExitCode() !== 0) {
return $result;
}
$this->processes = [];
if (file_exists($this->dir . '/bower.json')) {
$bower = $this->findExecutable('bower');
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$bower = $this->findExecutable('node') . ' '
. (strpos($bower, 'call ') === 0 ? substr($bower, 5) : $bower);
}
$this->processes[] = new Process(
$this->receiveCommand($bower . ' install'),
$this->dir,
null,
null,
null
);
}
if (file_exists($this->dir . '/Gruntfile.js')) {
$grunt = $this->findExecutable('grunt');
$this->processes[] = new Process(
$this->receiveCommand($grunt . ' ' . $this->command),
$this->dir,
null,
null,
null
);
}
if (file_exists($this->dir . '/gulpfile.js')) {
$gulp = $this->findExecutable('gulp') ? : $this->findExecutable('gulp.js');
$this->processes[] = new Process(
$this->receiveCommand($gulp . ' ' . $this->command),
$this->dir,
null,
null,
null
);
}
return parent::run();
} | php | public function run()
{
// Print the output of the compile commands.
$this->printed();
if (file_exists($this->dir . '/Gemfile')) {
$bundle = $this->findExecutable('bundle');
$this->processes[] = new Process(
$this->receiveCommand($bundle . ' install --deployment --no-cache'),
$this->dir,
null,
null,
null
);
}
if (file_exists($this->dir . '/package.json')) {
$executable = $this->findExecutable(file_exists($this->dir . '/yarn.lock') ? 'yarn' : 'npm');
$this->processes[] = new Process(
$this->receiveCommand($executable . ' install'),
$this->dir,
null,
null,
null
);
}
// Grunt/gulp and bower must wait for the previous processes to finish.
$result = parent::run();
if ($result->getExitCode() !== 0) {
return $result;
}
$this->processes = [];
if (file_exists($this->dir . '/bower.json')) {
$bower = $this->findExecutable('bower');
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$bower = $this->findExecutable('node') . ' '
. (strpos($bower, 'call ') === 0 ? substr($bower, 5) : $bower);
}
$this->processes[] = new Process(
$this->receiveCommand($bower . ' install'),
$this->dir,
null,
null,
null
);
}
if (file_exists($this->dir . '/Gruntfile.js')) {
$grunt = $this->findExecutable('grunt');
$this->processes[] = new Process(
$this->receiveCommand($grunt . ' ' . $this->command),
$this->dir,
null,
null,
null
);
}
if (file_exists($this->dir . '/gulpfile.js')) {
$gulp = $this->findExecutable('gulp') ? : $this->findExecutable('gulp.js');
$this->processes[] = new Process(
$this->receiveCommand($gulp . ' ' . $this->command),
$this->dir,
null,
null,
null
);
}
return parent::run();
} | [
"public",
"function",
"run",
"(",
")",
"{",
"// Print the output of the compile commands.",
"$",
"this",
"->",
"printed",
"(",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"dir",
".",
"'/Gemfile'",
")",
")",
"{",
"$",
"bundle",
"=",
"$",
"this",
"->",
"findExecutable",
"(",
"'bundle'",
")",
";",
"$",
"this",
"->",
"processes",
"[",
"]",
"=",
"new",
"Process",
"(",
"$",
"this",
"->",
"receiveCommand",
"(",
"$",
"bundle",
".",
"' install --deployment --no-cache'",
")",
",",
"$",
"this",
"->",
"dir",
",",
"null",
",",
"null",
",",
"null",
")",
";",
"}",
"if",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"dir",
".",
"'/package.json'",
")",
")",
"{",
"$",
"executable",
"=",
"$",
"this",
"->",
"findExecutable",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"dir",
".",
"'/yarn.lock'",
")",
"?",
"'yarn'",
":",
"'npm'",
")",
";",
"$",
"this",
"->",
"processes",
"[",
"]",
"=",
"new",
"Process",
"(",
"$",
"this",
"->",
"receiveCommand",
"(",
"$",
"executable",
".",
"' install'",
")",
",",
"$",
"this",
"->",
"dir",
",",
"null",
",",
"null",
",",
"null",
")",
";",
"}",
"// Grunt/gulp and bower must wait for the previous processes to finish.",
"$",
"result",
"=",
"parent",
"::",
"run",
"(",
")",
";",
"if",
"(",
"$",
"result",
"->",
"getExitCode",
"(",
")",
"!==",
"0",
")",
"{",
"return",
"$",
"result",
";",
"}",
"$",
"this",
"->",
"processes",
"=",
"[",
"]",
";",
"if",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"dir",
".",
"'/bower.json'",
")",
")",
"{",
"$",
"bower",
"=",
"$",
"this",
"->",
"findExecutable",
"(",
"'bower'",
")",
";",
"if",
"(",
"defined",
"(",
"'PHP_WINDOWS_VERSION_BUILD'",
")",
")",
"{",
"$",
"bower",
"=",
"$",
"this",
"->",
"findExecutable",
"(",
"'node'",
")",
".",
"' '",
".",
"(",
"strpos",
"(",
"$",
"bower",
",",
"'call '",
")",
"===",
"0",
"?",
"substr",
"(",
"$",
"bower",
",",
"5",
")",
":",
"$",
"bower",
")",
";",
"}",
"$",
"this",
"->",
"processes",
"[",
"]",
"=",
"new",
"Process",
"(",
"$",
"this",
"->",
"receiveCommand",
"(",
"$",
"bower",
".",
"' install'",
")",
",",
"$",
"this",
"->",
"dir",
",",
"null",
",",
"null",
",",
"null",
")",
";",
"}",
"if",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"dir",
".",
"'/Gruntfile.js'",
")",
")",
"{",
"$",
"grunt",
"=",
"$",
"this",
"->",
"findExecutable",
"(",
"'grunt'",
")",
";",
"$",
"this",
"->",
"processes",
"[",
"]",
"=",
"new",
"Process",
"(",
"$",
"this",
"->",
"receiveCommand",
"(",
"$",
"grunt",
".",
"' '",
".",
"$",
"this",
"->",
"command",
")",
",",
"$",
"this",
"->",
"dir",
",",
"null",
",",
"null",
",",
"null",
")",
";",
"}",
"if",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"dir",
".",
"'/gulpfile.js'",
")",
")",
"{",
"$",
"gulp",
"=",
"$",
"this",
"->",
"findExecutable",
"(",
"'gulp'",
")",
"?",
":",
"$",
"this",
"->",
"findExecutable",
"(",
"'gulp.js'",
")",
";",
"$",
"this",
"->",
"processes",
"[",
"]",
"=",
"new",
"Process",
"(",
"$",
"this",
"->",
"receiveCommand",
"(",
"$",
"gulp",
".",
"' '",
".",
"$",
"this",
"->",
"command",
")",
",",
"$",
"this",
"->",
"dir",
",",
"null",
",",
"null",
",",
"null",
")",
";",
"}",
"return",
"parent",
"::",
"run",
"(",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/digipolisgent/robo-digipolis-package/blob/6f206f32d910992d27b2a1b4dda1c5e7d8259b75/src/ThemeCompile.php#L46-L112 |
nonzod/yii2-foundation | ActiveField.php | ActiveField.hint | public function hint($content, $options = []) {
$options = array_merge($this->hintOptions, $options, [
'id' => 'hint-' . Html::getInputId($this->model, $this->attribute)
]);
$tag = ArrayHelper::remove($options, 'tag', 'p');
$this->parts['{hint}'] = Html::tag($tag, $content, $options);
return $this;
} | php | public function hint($content, $options = []) {
$options = array_merge($this->hintOptions, $options, [
'id' => 'hint-' . Html::getInputId($this->model, $this->attribute)
]);
$tag = ArrayHelper::remove($options, 'tag', 'p');
$this->parts['{hint}'] = Html::tag($tag, $content, $options);
return $this;
} | [
"public",
"function",
"hint",
"(",
"$",
"content",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"hintOptions",
",",
"$",
"options",
",",
"[",
"'id'",
"=>",
"'hint-'",
".",
"Html",
"::",
"getInputId",
"(",
"$",
"this",
"->",
"model",
",",
"$",
"this",
"->",
"attribute",
")",
"]",
")",
";",
"$",
"tag",
"=",
"ArrayHelper",
"::",
"remove",
"(",
"$",
"options",
",",
"'tag'",
",",
"'p'",
")",
";",
"$",
"this",
"->",
"parts",
"[",
"'{hint}'",
"]",
"=",
"Html",
"::",
"tag",
"(",
"$",
"tag",
",",
"$",
"content",
",",
"$",
"options",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Renders the hint tag.
@param string $content the hint content. It will NOT be HTML-encoded.
@param array $options the tag options in terms of name-value pairs. These will be rendered as
the attributes of the hint tag. The values will be HTML-encoded using [[Html::encode()]].
The following options are specially handled:
- tag: this specifies the tag name. If not set, "div" will be used.
@return static the field object itself | [
"Renders",
"the",
"hint",
"tag",
".",
"@param",
"string",
"$content",
"the",
"hint",
"content",
".",
"It",
"will",
"NOT",
"be",
"HTML",
"-",
"encoded",
".",
"@param",
"array",
"$options",
"the",
"tag",
"options",
"in",
"terms",
"of",
"name",
"-",
"value",
"pairs",
".",
"These",
"will",
"be",
"rendered",
"as",
"the",
"attributes",
"of",
"the",
"hint",
"tag",
".",
"The",
"values",
"will",
"be",
"HTML",
"-",
"encoded",
"using",
"[[",
"Html",
"::",
"encode",
"()",
"]]",
"."
] | train | https://github.com/nonzod/yii2-foundation/blob/5df93b8a39a73a7fade2f3189693fdb6625205d2/ActiveField.php#L76-L85 |
nonzod/yii2-foundation | ActiveField.php | ActiveField.input | public function input($type, $options = []) {
$options = array_merge($this->inputOptions, [
'class' => 'hint-' . Html::getInputId($this->model, $this->attribute)
]);
$this->adjustLabelFor($options);
$this->parts['{input}'] = Html::activeInput($type, $this->model, $this->attribute, $options);
return $this;
} | php | public function input($type, $options = []) {
$options = array_merge($this->inputOptions, [
'class' => 'hint-' . Html::getInputId($this->model, $this->attribute)
]);
$this->adjustLabelFor($options);
$this->parts['{input}'] = Html::activeInput($type, $this->model, $this->attribute, $options);
return $this;
} | [
"public",
"function",
"input",
"(",
"$",
"type",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"inputOptions",
",",
"[",
"'class'",
"=>",
"'hint-'",
".",
"Html",
"::",
"getInputId",
"(",
"$",
"this",
"->",
"model",
",",
"$",
"this",
"->",
"attribute",
")",
"]",
")",
";",
"$",
"this",
"->",
"adjustLabelFor",
"(",
"$",
"options",
")",
";",
"$",
"this",
"->",
"parts",
"[",
"'{input}'",
"]",
"=",
"Html",
"::",
"activeInput",
"(",
"$",
"type",
",",
"$",
"this",
"->",
"model",
",",
"$",
"this",
"->",
"attribute",
",",
"$",
"options",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Renders an input tag.
@param string $type the input type (e.g. 'text', 'password')
@param array $options the tag options in terms of name-value pairs. These will be rendered as
the attributes of the resulting tag. The values will be HTML-encoded using [[Html::encode()]].
@return static the field object itself | [
"Renders",
"an",
"input",
"tag",
"."
] | train | https://github.com/nonzod/yii2-foundation/blob/5df93b8a39a73a7fade2f3189693fdb6625205d2/ActiveField.php#L94-L102 |
nonzod/yii2-foundation | ActiveField.php | ActiveField.textInput | public function textInput($options = []) {
$options = array_merge($this->inputOptions, $options, [
'aria-describedby' => 'hint-' . Html::getInputId($this->model, $this->attribute)
]);
$this->adjustLabelFor($options);
$this->parts['{input}'] = Html::activeTextInput($this->model, $this->attribute, $options);
return $this;
} | php | public function textInput($options = []) {
$options = array_merge($this->inputOptions, $options, [
'aria-describedby' => 'hint-' . Html::getInputId($this->model, $this->attribute)
]);
$this->adjustLabelFor($options);
$this->parts['{input}'] = Html::activeTextInput($this->model, $this->attribute, $options);
return $this;
} | [
"public",
"function",
"textInput",
"(",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"inputOptions",
",",
"$",
"options",
",",
"[",
"'aria-describedby'",
"=>",
"'hint-'",
".",
"Html",
"::",
"getInputId",
"(",
"$",
"this",
"->",
"model",
",",
"$",
"this",
"->",
"attribute",
")",
"]",
")",
";",
"$",
"this",
"->",
"adjustLabelFor",
"(",
"$",
"options",
")",
";",
"$",
"this",
"->",
"parts",
"[",
"'{input}'",
"]",
"=",
"Html",
"::",
"activeTextInput",
"(",
"$",
"this",
"->",
"model",
",",
"$",
"this",
"->",
"attribute",
",",
"$",
"options",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Renders a text input.
This method will generate the "name" and "value" tag attributes automatically for the model attribute
unless they are explicitly specified in `$options`.
@param array $options the tag options in terms of name-value pairs. These will be rendered as
the attributes of the resulting tag. The values will be HTML-encoded using [[Html::encode()]].
@return static the field object itself | [
"Renders",
"a",
"text",
"input",
".",
"This",
"method",
"will",
"generate",
"the",
"name",
"and",
"value",
"tag",
"attributes",
"automatically",
"for",
"the",
"model",
"attribute",
"unless",
"they",
"are",
"explicitly",
"specified",
"in",
"$options",
"."
] | train | https://github.com/nonzod/yii2-foundation/blob/5df93b8a39a73a7fade2f3189693fdb6625205d2/ActiveField.php#L112-L120 |
ShaoZeMing/laravel-merchant | src/Grid/Filter/Presenter/Text.php | Text.inputmask | public function inputmask($options = [], $icon = 'pencil') : self
{
$options = json_encode($options);
Merchant::script("$('#filter-modal input.{$this->filter->getId()}').inputmask($options);");
$this->icon = $icon;
return $this;
} | php | public function inputmask($options = [], $icon = 'pencil') : self
{
$options = json_encode($options);
Merchant::script("$('#filter-modal input.{$this->filter->getId()}').inputmask($options);");
$this->icon = $icon;
return $this;
} | [
"public",
"function",
"inputmask",
"(",
"$",
"options",
"=",
"[",
"]",
",",
"$",
"icon",
"=",
"'pencil'",
")",
":",
"self",
"{",
"$",
"options",
"=",
"json_encode",
"(",
"$",
"options",
")",
";",
"Merchant",
"::",
"script",
"(",
"\"$('#filter-modal input.{$this->filter->getId()}').inputmask($options);\"",
")",
";",
"$",
"this",
"->",
"icon",
"=",
"$",
"icon",
";",
"return",
"$",
"this",
";",
"}"
] | @param array $options
@param string $icon
@return $this | [
"@param",
"array",
"$options",
"@param",
"string",
"$icon"
] | train | https://github.com/ShaoZeMing/laravel-merchant/blob/20801b1735e7832a6e58b37c2c391328f8d626fa/src/Grid/Filter/Presenter/Text.php#L160-L169 |
heidelpay/PhpDoc | src/phpDocumentor/Command/Helper/ConfigurationHelper.php | ConfigurationHelper.getOption | public function getOption(
InputInterface $input,
$name,
$configPath = null,
$default = null,
$commaSeparated = false
) {
$value = $input->getOption($name);
// find value in config
if ($this->valueIsEmpty($value) && $configPath !== null) {
$value = $this->getConfigValueFromPath($configPath);
}
// use default if value is still null
if ($this->valueIsEmpty($value)) {
return (is_array($value) && $default === null) ? array() : $default;
}
return $commaSeparated
? $this->splitCommaSeparatedValues($value)
: $value;
} | php | public function getOption(
InputInterface $input,
$name,
$configPath = null,
$default = null,
$commaSeparated = false
) {
$value = $input->getOption($name);
// find value in config
if ($this->valueIsEmpty($value) && $configPath !== null) {
$value = $this->getConfigValueFromPath($configPath);
}
// use default if value is still null
if ($this->valueIsEmpty($value)) {
return (is_array($value) && $default === null) ? array() : $default;
}
return $commaSeparated
? $this->splitCommaSeparatedValues($value)
: $value;
} | [
"public",
"function",
"getOption",
"(",
"InputInterface",
"$",
"input",
",",
"$",
"name",
",",
"$",
"configPath",
"=",
"null",
",",
"$",
"default",
"=",
"null",
",",
"$",
"commaSeparated",
"=",
"false",
")",
"{",
"$",
"value",
"=",
"$",
"input",
"->",
"getOption",
"(",
"$",
"name",
")",
";",
"// find value in config",
"if",
"(",
"$",
"this",
"->",
"valueIsEmpty",
"(",
"$",
"value",
")",
"&&",
"$",
"configPath",
"!==",
"null",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"getConfigValueFromPath",
"(",
"$",
"configPath",
")",
";",
"}",
"// use default if value is still null",
"if",
"(",
"$",
"this",
"->",
"valueIsEmpty",
"(",
"$",
"value",
")",
")",
"{",
"return",
"(",
"is_array",
"(",
"$",
"value",
")",
"&&",
"$",
"default",
"===",
"null",
")",
"?",
"array",
"(",
")",
":",
"$",
"default",
";",
"}",
"return",
"$",
"commaSeparated",
"?",
"$",
"this",
"->",
"splitCommaSeparatedValues",
"(",
"$",
"value",
")",
":",
"$",
"value",
";",
"}"
] | Returns the value of an option from the command-line parameters,
configuration or given default.
@param InputInterface $input Input interface to query for information
@param string $name Name of the option to retrieve from argv
@param string|null $configPath Path to the config element(s) containing the value to be used when
no option is provided.
@param mixed|null $default Default value used if there is no configuration option or path set
@param bool $commaSeparated Could the value be a comma separated string requiring splitting
@return string|array | [
"Returns",
"the",
"value",
"of",
"an",
"option",
"from",
"the",
"command",
"-",
"line",
"parameters",
"configuration",
"or",
"given",
"default",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Command/Helper/ConfigurationHelper.php#L62-L84 |
heidelpay/PhpDoc | src/phpDocumentor/Command/Helper/ConfigurationHelper.php | ConfigurationHelper.splitCommaSeparatedValues | protected function splitCommaSeparatedValues($value)
{
if (!is_array($value) || (count($value) == 1) && is_string(current($value))) {
$value = (array) $value;
$value = explode(',', $value[0]);
}
return $value;
} | php | protected function splitCommaSeparatedValues($value)
{
if (!is_array($value) || (count($value) == 1) && is_string(current($value))) {
$value = (array) $value;
$value = explode(',', $value[0]);
}
return $value;
} | [
"protected",
"function",
"splitCommaSeparatedValues",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
"||",
"(",
"count",
"(",
"$",
"value",
")",
"==",
"1",
")",
"&&",
"is_string",
"(",
"current",
"(",
"$",
"value",
")",
")",
")",
"{",
"$",
"value",
"=",
"(",
"array",
")",
"$",
"value",
";",
"$",
"value",
"=",
"explode",
"(",
"','",
",",
"$",
"value",
"[",
"0",
"]",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Split comma separated values.
@param mixed $value
@return mixed | [
"Split",
"comma",
"separated",
"values",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Command/Helper/ConfigurationHelper.php#L93-L101 |
heidelpay/PhpDoc | src/phpDocumentor/Command/Helper/ConfigurationHelper.php | ConfigurationHelper.getConfigValueFromPath | public function getConfigValueFromPath($path)
{
/** @var Configuration $node */
$node = $this->configuration;
foreach (explode('/', $path) as $nodeName) {
if (!is_object($node)) {
return null;
}
$node = $node->{'get' . ucfirst($nodeName)}();
}
return $node;
} | php | public function getConfigValueFromPath($path)
{
/** @var Configuration $node */
$node = $this->configuration;
foreach (explode('/', $path) as $nodeName) {
if (!is_object($node)) {
return null;
}
$node = $node->{'get' . ucfirst($nodeName)}();
}
return $node;
} | [
"public",
"function",
"getConfigValueFromPath",
"(",
"$",
"path",
")",
"{",
"/** @var Configuration $node */",
"$",
"node",
"=",
"$",
"this",
"->",
"configuration",
";",
"foreach",
"(",
"explode",
"(",
"'/'",
",",
"$",
"path",
")",
"as",
"$",
"nodeName",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"node",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"node",
"=",
"$",
"node",
"->",
"{",
"'get'",
".",
"ucfirst",
"(",
"$",
"nodeName",
")",
"}",
"(",
")",
";",
"}",
"return",
"$",
"node",
";",
"}"
] | Returns a value by traversing the configuration tree as if it was a file
path.
@param string $path Path to the config value separated by '/'.
@return string|integer|boolean | [
"Returns",
"a",
"value",
"by",
"traversing",
"the",
"configuration",
"tree",
"as",
"if",
"it",
"was",
"a",
"file",
"path",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Command/Helper/ConfigurationHelper.php#L123-L137 |
xiewulong/yii2-fileupload | oss/libs/guzzle/http/Guzzle/Http/RedirectPlugin.php | RedirectPlugin.onRequestSent | public function onRequestSent(Event $event)
{
$response = $event['response'];
$request = $event['request'];
// Only act on redirect requests with Location headers
if (!$response || $request->getParams()->get(self::DISABLE)) {
return;
}
// Trace the original request based on parameter history
$original = $this->getOriginalRequest($request);
// Terminating condition to set the effective repsonse on the original request
if (!$response->isRedirect() || !$response->hasHeader('Location')) {
if ($request !== $original) {
// This is a terminating redirect response, so set it on the original request
$response->getParams()->set(self::REDIRECT_COUNT, $original->getParams()->get(self::REDIRECT_COUNT));
$original->setResponse($response);
$response->setEffectiveUrl($request->getUrl());
}
return;
}
$this->sendRedirectRequest($original, $request, $response);
} | php | public function onRequestSent(Event $event)
{
$response = $event['response'];
$request = $event['request'];
// Only act on redirect requests with Location headers
if (!$response || $request->getParams()->get(self::DISABLE)) {
return;
}
// Trace the original request based on parameter history
$original = $this->getOriginalRequest($request);
// Terminating condition to set the effective repsonse on the original request
if (!$response->isRedirect() || !$response->hasHeader('Location')) {
if ($request !== $original) {
// This is a terminating redirect response, so set it on the original request
$response->getParams()->set(self::REDIRECT_COUNT, $original->getParams()->get(self::REDIRECT_COUNT));
$original->setResponse($response);
$response->setEffectiveUrl($request->getUrl());
}
return;
}
$this->sendRedirectRequest($original, $request, $response);
} | [
"public",
"function",
"onRequestSent",
"(",
"Event",
"$",
"event",
")",
"{",
"$",
"response",
"=",
"$",
"event",
"[",
"'response'",
"]",
";",
"$",
"request",
"=",
"$",
"event",
"[",
"'request'",
"]",
";",
"// Only act on redirect requests with Location headers",
"if",
"(",
"!",
"$",
"response",
"||",
"$",
"request",
"->",
"getParams",
"(",
")",
"->",
"get",
"(",
"self",
"::",
"DISABLE",
")",
")",
"{",
"return",
";",
"}",
"// Trace the original request based on parameter history",
"$",
"original",
"=",
"$",
"this",
"->",
"getOriginalRequest",
"(",
"$",
"request",
")",
";",
"// Terminating condition to set the effective repsonse on the original request",
"if",
"(",
"!",
"$",
"response",
"->",
"isRedirect",
"(",
")",
"||",
"!",
"$",
"response",
"->",
"hasHeader",
"(",
"'Location'",
")",
")",
"{",
"if",
"(",
"$",
"request",
"!==",
"$",
"original",
")",
"{",
"// This is a terminating redirect response, so set it on the original request",
"$",
"response",
"->",
"getParams",
"(",
")",
"->",
"set",
"(",
"self",
"::",
"REDIRECT_COUNT",
",",
"$",
"original",
"->",
"getParams",
"(",
")",
"->",
"get",
"(",
"self",
"::",
"REDIRECT_COUNT",
")",
")",
";",
"$",
"original",
"->",
"setResponse",
"(",
"$",
"response",
")",
";",
"$",
"response",
"->",
"setEffectiveUrl",
"(",
"$",
"request",
"->",
"getUrl",
"(",
")",
")",
";",
"}",
"return",
";",
"}",
"$",
"this",
"->",
"sendRedirectRequest",
"(",
"$",
"original",
",",
"$",
"request",
",",
"$",
"response",
")",
";",
"}"
] | Called when a request receives a redirect response
@param Event $event Event emitted | [
"Called",
"when",
"a",
"request",
"receives",
"a",
"redirect",
"response"
] | train | https://github.com/xiewulong/yii2-fileupload/blob/3e75b17a4a18dd8466e3f57c63136de03470ca82/oss/libs/guzzle/http/Guzzle/Http/RedirectPlugin.php#L58-L83 |
xiewulong/yii2-fileupload | oss/libs/guzzle/http/Guzzle/Http/RedirectPlugin.php | RedirectPlugin.createRedirectRequest | protected function createRedirectRequest(
RequestInterface $request,
$statusCode,
$location,
RequestInterface $original
) {
$redirectRequest = null;
$strict = $original->getParams()->get(self::STRICT_REDIRECTS);
// Use a GET request if this is an entity enclosing request and we are not forcing RFC compliance, but rather
// emulating what all browsers would do
if ($request instanceof EntityEnclosingRequestInterface && !$strict && $statusCode <= 302) {
$redirectRequest = RequestFactory::getInstance()->cloneRequestWithMethod($request, 'GET');
} else {
$redirectRequest = clone $request;
}
$redirectRequest->setIsRedirect(true);
// Always use the same response body when redirecting
$redirectRequest->setResponseBody($request->getResponseBody());
$location = Url::factory($location);
// If the location is not absolute, then combine it with the original URL
if (!$location->isAbsolute()) {
$originalUrl = $redirectRequest->getUrl(true);
// Remove query string parameters and just take what is present on the redirect Location header
$originalUrl->getQuery()->clear();
$location = $originalUrl->combine((string) $location);
}
$redirectRequest->setUrl($location);
// Add the parent request to the request before it sends (make sure it's before the onRequestClone event too)
$redirectRequest->getEventDispatcher()->addListener(
'request.before_send',
$func = function ($e) use (&$func, $request, $redirectRequest) {
$redirectRequest->getEventDispatcher()->removeListener('request.before_send', $func);
$e['request']->getParams()->set(RedirectPlugin::PARENT_REQUEST, $request);
}
);
// Rewind the entity body of the request if needed
if ($redirectRequest instanceof EntityEnclosingRequestInterface && $redirectRequest->getBody()) {
$body = $redirectRequest->getBody();
// Only rewind the body if some of it has been read already, and throw an exception if the rewind fails
if ($body->ftell() && !$body->rewind()) {
throw new CouldNotRewindStreamException(
'Unable to rewind the non-seekable entity body of the request after redirecting. cURL probably '
. 'sent part of body before the redirect occurred. Try adding acustom rewind function using on the '
. 'entity body of the request using setRewindFunction().'
);
}
}
return $redirectRequest;
} | php | protected function createRedirectRequest(
RequestInterface $request,
$statusCode,
$location,
RequestInterface $original
) {
$redirectRequest = null;
$strict = $original->getParams()->get(self::STRICT_REDIRECTS);
// Use a GET request if this is an entity enclosing request and we are not forcing RFC compliance, but rather
// emulating what all browsers would do
if ($request instanceof EntityEnclosingRequestInterface && !$strict && $statusCode <= 302) {
$redirectRequest = RequestFactory::getInstance()->cloneRequestWithMethod($request, 'GET');
} else {
$redirectRequest = clone $request;
}
$redirectRequest->setIsRedirect(true);
// Always use the same response body when redirecting
$redirectRequest->setResponseBody($request->getResponseBody());
$location = Url::factory($location);
// If the location is not absolute, then combine it with the original URL
if (!$location->isAbsolute()) {
$originalUrl = $redirectRequest->getUrl(true);
// Remove query string parameters and just take what is present on the redirect Location header
$originalUrl->getQuery()->clear();
$location = $originalUrl->combine((string) $location);
}
$redirectRequest->setUrl($location);
// Add the parent request to the request before it sends (make sure it's before the onRequestClone event too)
$redirectRequest->getEventDispatcher()->addListener(
'request.before_send',
$func = function ($e) use (&$func, $request, $redirectRequest) {
$redirectRequest->getEventDispatcher()->removeListener('request.before_send', $func);
$e['request']->getParams()->set(RedirectPlugin::PARENT_REQUEST, $request);
}
);
// Rewind the entity body of the request if needed
if ($redirectRequest instanceof EntityEnclosingRequestInterface && $redirectRequest->getBody()) {
$body = $redirectRequest->getBody();
// Only rewind the body if some of it has been read already, and throw an exception if the rewind fails
if ($body->ftell() && !$body->rewind()) {
throw new CouldNotRewindStreamException(
'Unable to rewind the non-seekable entity body of the request after redirecting. cURL probably '
. 'sent part of body before the redirect occurred. Try adding acustom rewind function using on the '
. 'entity body of the request using setRewindFunction().'
);
}
}
return $redirectRequest;
} | [
"protected",
"function",
"createRedirectRequest",
"(",
"RequestInterface",
"$",
"request",
",",
"$",
"statusCode",
",",
"$",
"location",
",",
"RequestInterface",
"$",
"original",
")",
"{",
"$",
"redirectRequest",
"=",
"null",
";",
"$",
"strict",
"=",
"$",
"original",
"->",
"getParams",
"(",
")",
"->",
"get",
"(",
"self",
"::",
"STRICT_REDIRECTS",
")",
";",
"// Use a GET request if this is an entity enclosing request and we are not forcing RFC compliance, but rather",
"// emulating what all browsers would do",
"if",
"(",
"$",
"request",
"instanceof",
"EntityEnclosingRequestInterface",
"&&",
"!",
"$",
"strict",
"&&",
"$",
"statusCode",
"<=",
"302",
")",
"{",
"$",
"redirectRequest",
"=",
"RequestFactory",
"::",
"getInstance",
"(",
")",
"->",
"cloneRequestWithMethod",
"(",
"$",
"request",
",",
"'GET'",
")",
";",
"}",
"else",
"{",
"$",
"redirectRequest",
"=",
"clone",
"$",
"request",
";",
"}",
"$",
"redirectRequest",
"->",
"setIsRedirect",
"(",
"true",
")",
";",
"// Always use the same response body when redirecting",
"$",
"redirectRequest",
"->",
"setResponseBody",
"(",
"$",
"request",
"->",
"getResponseBody",
"(",
")",
")",
";",
"$",
"location",
"=",
"Url",
"::",
"factory",
"(",
"$",
"location",
")",
";",
"// If the location is not absolute, then combine it with the original URL",
"if",
"(",
"!",
"$",
"location",
"->",
"isAbsolute",
"(",
")",
")",
"{",
"$",
"originalUrl",
"=",
"$",
"redirectRequest",
"->",
"getUrl",
"(",
"true",
")",
";",
"// Remove query string parameters and just take what is present on the redirect Location header",
"$",
"originalUrl",
"->",
"getQuery",
"(",
")",
"->",
"clear",
"(",
")",
";",
"$",
"location",
"=",
"$",
"originalUrl",
"->",
"combine",
"(",
"(",
"string",
")",
"$",
"location",
")",
";",
"}",
"$",
"redirectRequest",
"->",
"setUrl",
"(",
"$",
"location",
")",
";",
"// Add the parent request to the request before it sends (make sure it's before the onRequestClone event too)",
"$",
"redirectRequest",
"->",
"getEventDispatcher",
"(",
")",
"->",
"addListener",
"(",
"'request.before_send'",
",",
"$",
"func",
"=",
"function",
"(",
"$",
"e",
")",
"use",
"(",
"&",
"$",
"func",
",",
"$",
"request",
",",
"$",
"redirectRequest",
")",
"{",
"$",
"redirectRequest",
"->",
"getEventDispatcher",
"(",
")",
"->",
"removeListener",
"(",
"'request.before_send'",
",",
"$",
"func",
")",
";",
"$",
"e",
"[",
"'request'",
"]",
"->",
"getParams",
"(",
")",
"->",
"set",
"(",
"RedirectPlugin",
"::",
"PARENT_REQUEST",
",",
"$",
"request",
")",
";",
"}",
")",
";",
"// Rewind the entity body of the request if needed",
"if",
"(",
"$",
"redirectRequest",
"instanceof",
"EntityEnclosingRequestInterface",
"&&",
"$",
"redirectRequest",
"->",
"getBody",
"(",
")",
")",
"{",
"$",
"body",
"=",
"$",
"redirectRequest",
"->",
"getBody",
"(",
")",
";",
"// Only rewind the body if some of it has been read already, and throw an exception if the rewind fails",
"if",
"(",
"$",
"body",
"->",
"ftell",
"(",
")",
"&&",
"!",
"$",
"body",
"->",
"rewind",
"(",
")",
")",
"{",
"throw",
"new",
"CouldNotRewindStreamException",
"(",
"'Unable to rewind the non-seekable entity body of the request after redirecting. cURL probably '",
".",
"'sent part of body before the redirect occurred. Try adding acustom rewind function using on the '",
".",
"'entity body of the request using setRewindFunction().'",
")",
";",
"}",
"}",
"return",
"$",
"redirectRequest",
";",
"}"
] | Create a redirect request for a specific request object
Takes into account strict RFC compliant redirection (e.g. redirect POST with POST) vs doing what most clients do
(e.g. redirect POST with GET).
@param RequestInterface $request Request being redirected
@param RequestInterface $original Original request
@param int $statusCode Status code of the redirect
@param string $location Location header of the redirect
@return RequestInterface Returns a new redirect request
@throws CouldNotRewindStreamException If the body needs to be rewound but cannot | [
"Create",
"a",
"redirect",
"request",
"for",
"a",
"specific",
"request",
"object"
] | train | https://github.com/xiewulong/yii2-fileupload/blob/3e75b17a4a18dd8466e3f57c63136de03470ca82/oss/libs/guzzle/http/Guzzle/Http/RedirectPlugin.php#L117-L172 |
Danzabar/config-builder | src/Files/Merger.php | Merger.load | public function load(ConfigFile $master, ConfigFile $slave)
{
$this->master = $master;
$this->slave = $slave;
return $this;
} | php | public function load(ConfigFile $master, ConfigFile $slave)
{
$this->master = $master;
$this->slave = $slave;
return $this;
} | [
"public",
"function",
"load",
"(",
"ConfigFile",
"$",
"master",
",",
"ConfigFile",
"$",
"slave",
")",
"{",
"$",
"this",
"->",
"master",
"=",
"$",
"master",
";",
"$",
"this",
"->",
"slave",
"=",
"$",
"slave",
";",
"return",
"$",
"this",
";",
"}"
] | Loads the master and slave files
@param \Danzabar\Config\Files\ConfigFile $master
@param \Danzabar\Config\Files\ConfigFile $slave
@return Merger
@author Dan Cox | [
"Loads",
"the",
"master",
"and",
"slave",
"files"
] | train | https://github.com/Danzabar/config-builder/blob/3b237be578172c32498bbcdfb360e69a6243739d/src/Files/Merger.php#L72-L78 |
Danzabar/config-builder | src/Files/Merger.php | Merger.merge | public function merge()
{
if($this->saveBackupBeforeMerge)
{
$this->saveBackup();
}
// Since the param bag has the merge functionality already, why not use it?
$this->master->params()->merge($this->slave->params()->all());
if($this->autoSaveMaster)
{
$this->master->save();
}
if($this->deleteSlaveOnMerge)
{
$this->slave->delete();
}
} | php | public function merge()
{
if($this->saveBackupBeforeMerge)
{
$this->saveBackup();
}
// Since the param bag has the merge functionality already, why not use it?
$this->master->params()->merge($this->slave->params()->all());
if($this->autoSaveMaster)
{
$this->master->save();
}
if($this->deleteSlaveOnMerge)
{
$this->slave->delete();
}
} | [
"public",
"function",
"merge",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"saveBackupBeforeMerge",
")",
"{",
"$",
"this",
"->",
"saveBackup",
"(",
")",
";",
"}",
"// Since the param bag has the merge functionality already, why not use it?",
"$",
"this",
"->",
"master",
"->",
"params",
"(",
")",
"->",
"merge",
"(",
"$",
"this",
"->",
"slave",
"->",
"params",
"(",
")",
"->",
"all",
"(",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"autoSaveMaster",
")",
"{",
"$",
"this",
"->",
"master",
"->",
"save",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"deleteSlaveOnMerge",
")",
"{",
"$",
"this",
"->",
"slave",
"->",
"delete",
"(",
")",
";",
"}",
"}"
] | Performs the merge action
@return void
@author Dan Cox | [
"Performs",
"the",
"merge",
"action"
] | train | https://github.com/Danzabar/config-builder/blob/3b237be578172c32498bbcdfb360e69a6243739d/src/Files/Merger.php#L86-L105 |
Danzabar/config-builder | src/Files/Merger.php | Merger.restore | public function restore()
{
$this->master->params()->rollback();
$this->slave->params()->rollback();
// We should also save these so we know any changes have been fully reversed
$this->master->save();
$this->slave->save();
} | php | public function restore()
{
$this->master->params()->rollback();
$this->slave->params()->rollback();
// We should also save these so we know any changes have been fully reversed
$this->master->save();
$this->slave->save();
} | [
"public",
"function",
"restore",
"(",
")",
"{",
"$",
"this",
"->",
"master",
"->",
"params",
"(",
")",
"->",
"rollback",
"(",
")",
";",
"$",
"this",
"->",
"slave",
"->",
"params",
"(",
")",
"->",
"rollback",
"(",
")",
";",
"// We should also save these so we know any changes have been fully reversed",
"$",
"this",
"->",
"master",
"->",
"save",
"(",
")",
";",
"$",
"this",
"->",
"slave",
"->",
"save",
"(",
")",
";",
"}"
] | Restores the files
@return void
@author Dan Cox | [
"Restores",
"the",
"files"
] | train | https://github.com/Danzabar/config-builder/blob/3b237be578172c32498bbcdfb360e69a6243739d/src/Files/Merger.php#L125-L133 |
highday/glitter | database/migrations/2016_12_14_000023_create_variants_table.php | CreateVariantsTable.up | public function up()
{
Schema::create('variants', function (Blueprint $table) {
$table->increments('id');
$table->integer('product_id')->unsigned();
$table->foreign('product_id')->references('id')->on('products')->onDelete('cascade');
$table->integer('image_id')->unsigned()->nullable();
$table->foreign('image_id')->references('id')->on('media')->onDelete('set null');
$table->string('option1')->nullable();
$table->string('option2')->nullable();
$table->string('option3')->nullable();
$table->string('sku')->nullable();
$table->string('barcode')->nullable();
$table->decimal('price', 13, 3);
$table->decimal('reference_price', 13, 3)->nullable();
$table->boolean('taxes_included')->default(true);
$table->string('inventory_management')->nullable();
$table->integer('inventory_quantity')->unsigned()->nullable();
$table->boolean('out_of_stock_purchase')->default(false);
$table->boolean('requires_shipping')->default(false);
$table->decimal('weight', 13, 3)->nullable();
$table->string('weight_unit')->nullable();
$table->string('fulfillment_service')->nullable();
});
} | php | public function up()
{
Schema::create('variants', function (Blueprint $table) {
$table->increments('id');
$table->integer('product_id')->unsigned();
$table->foreign('product_id')->references('id')->on('products')->onDelete('cascade');
$table->integer('image_id')->unsigned()->nullable();
$table->foreign('image_id')->references('id')->on('media')->onDelete('set null');
$table->string('option1')->nullable();
$table->string('option2')->nullable();
$table->string('option3')->nullable();
$table->string('sku')->nullable();
$table->string('barcode')->nullable();
$table->decimal('price', 13, 3);
$table->decimal('reference_price', 13, 3)->nullable();
$table->boolean('taxes_included')->default(true);
$table->string('inventory_management')->nullable();
$table->integer('inventory_quantity')->unsigned()->nullable();
$table->boolean('out_of_stock_purchase')->default(false);
$table->boolean('requires_shipping')->default(false);
$table->decimal('weight', 13, 3)->nullable();
$table->string('weight_unit')->nullable();
$table->string('fulfillment_service')->nullable();
});
} | [
"public",
"function",
"up",
"(",
")",
"{",
"Schema",
"::",
"create",
"(",
"'variants'",
",",
"function",
"(",
"Blueprint",
"$",
"table",
")",
"{",
"$",
"table",
"->",
"increments",
"(",
"'id'",
")",
";",
"$",
"table",
"->",
"integer",
"(",
"'product_id'",
")",
"->",
"unsigned",
"(",
")",
";",
"$",
"table",
"->",
"foreign",
"(",
"'product_id'",
")",
"->",
"references",
"(",
"'id'",
")",
"->",
"on",
"(",
"'products'",
")",
"->",
"onDelete",
"(",
"'cascade'",
")",
";",
"$",
"table",
"->",
"integer",
"(",
"'image_id'",
")",
"->",
"unsigned",
"(",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"table",
"->",
"foreign",
"(",
"'image_id'",
")",
"->",
"references",
"(",
"'id'",
")",
"->",
"on",
"(",
"'media'",
")",
"->",
"onDelete",
"(",
"'set null'",
")",
";",
"$",
"table",
"->",
"string",
"(",
"'option1'",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"table",
"->",
"string",
"(",
"'option2'",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"table",
"->",
"string",
"(",
"'option3'",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"table",
"->",
"string",
"(",
"'sku'",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"table",
"->",
"string",
"(",
"'barcode'",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"table",
"->",
"decimal",
"(",
"'price'",
",",
"13",
",",
"3",
")",
";",
"$",
"table",
"->",
"decimal",
"(",
"'reference_price'",
",",
"13",
",",
"3",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"table",
"->",
"boolean",
"(",
"'taxes_included'",
")",
"->",
"default",
"(",
"true",
")",
";",
"$",
"table",
"->",
"string",
"(",
"'inventory_management'",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"table",
"->",
"integer",
"(",
"'inventory_quantity'",
")",
"->",
"unsigned",
"(",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"table",
"->",
"boolean",
"(",
"'out_of_stock_purchase'",
")",
"->",
"default",
"(",
"false",
")",
";",
"$",
"table",
"->",
"boolean",
"(",
"'requires_shipping'",
")",
"->",
"default",
"(",
"false",
")",
";",
"$",
"table",
"->",
"decimal",
"(",
"'weight'",
",",
"13",
",",
"3",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"table",
"->",
"string",
"(",
"'weight_unit'",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"table",
"->",
"string",
"(",
"'fulfillment_service'",
")",
"->",
"nullable",
"(",
")",
";",
"}",
")",
";",
"}"
] | Run the migrations.
@return void | [
"Run",
"the",
"migrations",
"."
] | train | https://github.com/highday/glitter/blob/d1c7a227fd2343806bd3ec0314e621ced57dfe66/database/migrations/2016_12_14_000023_create_variants_table.php#L14-L38 |
Smile-SA/EzUICronBundle | Repository/SmileEzCronRepository.php | SmileEzCronRepository.updateCron | public function updateCron(SmileEzCron $cron, $type, $value)
{
switch ($type) {
case 'expression':
if (!CronExpression::isValidExpression($value)) {
throw new InvalidArgumentException(
'expression', 'cron.invalid.type'
);
}
$cron->setExpression($value);
break;
case 'arguments':
if (preg_match_all('|[a-z0-9_\-]+:[a-z0-9_\-]+|', $value) === 0) {
throw new InvalidArgumentException(
'arguments', 'cron.invalid.type'
);
}
$cron->setArguments($value);
break;
case 'priority':
if (!ctype_digit($value)) {
throw new InvalidArgumentException(
'priority', 'cron.invalid.type'
);
}
$cron->setPriority((int)$value);
break;
case 'enabled':
if (!ctype_digit($value) && ((int)$value != 1 || (int)$value != 0)) {
throw new InvalidArgumentException(
'enabled', 'cron.invalid.type'
);
}
$cron->setEnabled((int)$value);
break;
}
$this->getEntityManager()->persist($cron);
$this->getEntityManager()->flush();
} | php | public function updateCron(SmileEzCron $cron, $type, $value)
{
switch ($type) {
case 'expression':
if (!CronExpression::isValidExpression($value)) {
throw new InvalidArgumentException(
'expression', 'cron.invalid.type'
);
}
$cron->setExpression($value);
break;
case 'arguments':
if (preg_match_all('|[a-z0-9_\-]+:[a-z0-9_\-]+|', $value) === 0) {
throw new InvalidArgumentException(
'arguments', 'cron.invalid.type'
);
}
$cron->setArguments($value);
break;
case 'priority':
if (!ctype_digit($value)) {
throw new InvalidArgumentException(
'priority', 'cron.invalid.type'
);
}
$cron->setPriority((int)$value);
break;
case 'enabled':
if (!ctype_digit($value) && ((int)$value != 1 || (int)$value != 0)) {
throw new InvalidArgumentException(
'enabled', 'cron.invalid.type'
);
}
$cron->setEnabled((int)$value);
break;
}
$this->getEntityManager()->persist($cron);
$this->getEntityManager()->flush();
} | [
"public",
"function",
"updateCron",
"(",
"SmileEzCron",
"$",
"cron",
",",
"$",
"type",
",",
"$",
"value",
")",
"{",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'expression'",
":",
"if",
"(",
"!",
"CronExpression",
"::",
"isValidExpression",
"(",
"$",
"value",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'expression'",
",",
"'cron.invalid.type'",
")",
";",
"}",
"$",
"cron",
"->",
"setExpression",
"(",
"$",
"value",
")",
";",
"break",
";",
"case",
"'arguments'",
":",
"if",
"(",
"preg_match_all",
"(",
"'|[a-z0-9_\\-]+:[a-z0-9_\\-]+|'",
",",
"$",
"value",
")",
"===",
"0",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'arguments'",
",",
"'cron.invalid.type'",
")",
";",
"}",
"$",
"cron",
"->",
"setArguments",
"(",
"$",
"value",
")",
";",
"break",
";",
"case",
"'priority'",
":",
"if",
"(",
"!",
"ctype_digit",
"(",
"$",
"value",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'priority'",
",",
"'cron.invalid.type'",
")",
";",
"}",
"$",
"cron",
"->",
"setPriority",
"(",
"(",
"int",
")",
"$",
"value",
")",
";",
"break",
";",
"case",
"'enabled'",
":",
"if",
"(",
"!",
"ctype_digit",
"(",
"$",
"value",
")",
"&&",
"(",
"(",
"int",
")",
"$",
"value",
"!=",
"1",
"||",
"(",
"int",
")",
"$",
"value",
"!=",
"0",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'enabled'",
",",
"'cron.invalid.type'",
")",
";",
"}",
"$",
"cron",
"->",
"setEnabled",
"(",
"(",
"int",
")",
"$",
"value",
")",
";",
"break",
";",
"}",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"persist",
"(",
"$",
"cron",
")",
";",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"flush",
"(",
")",
";",
"}"
] | Edit cron definition
@param SmileEzCron $cron cron object
@param string $type cron property identifier
@param string $value cron property value
@throws InvalidArgumentException | [
"Edit",
"cron",
"definition"
] | train | https://github.com/Smile-SA/EzUICronBundle/blob/c62fc6a3ab0b39e3f911742d9affe4aade90cf66/Repository/SmileEzCronRepository.php#L39-L78 |
philiplb/Valdi | src/Valdi/Validator/Between.php | Between.isValidComparison | protected function isValidComparison($value, $parameters) {
return $this->isAllNumeric($value, $parameters[0], $parameters[1])
&& $value >= $parameters[0]
&& $value <= $parameters[1];
} | php | protected function isValidComparison($value, $parameters) {
return $this->isAllNumeric($value, $parameters[0], $parameters[1])
&& $value >= $parameters[0]
&& $value <= $parameters[1];
} | [
"protected",
"function",
"isValidComparison",
"(",
"$",
"value",
",",
"$",
"parameters",
")",
"{",
"return",
"$",
"this",
"->",
"isAllNumeric",
"(",
"$",
"value",
",",
"$",
"parameters",
"[",
"0",
"]",
",",
"$",
"parameters",
"[",
"1",
"]",
")",
"&&",
"$",
"value",
">=",
"$",
"parameters",
"[",
"0",
"]",
"&&",
"$",
"value",
"<=",
"$",
"parameters",
"[",
"1",
"]",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/philiplb/Valdi/blob/9927ec34a2cb00cec705e952d3c2374e2dc3c972/src/Valdi/Validator/Between.php#L32-L36 |
mvccore/ext-router-module | src/MvcCore/Ext/Routers/Modules/Route/PropsGettersSetters.php | PropsGettersSetters.& | public function & SetAllowedLocalizations (/* ...$allowedLocalizations */) {
/** @var $this \MvcCore\Ext\Routers\Modules\IRoute */
$allowedLocalizations = func_get_args();
if (count($allowedLocalizations) === 1 && is_array($allowedLocalizations[0]))
$allowedLocalizations = $allowedLocalizations[0];
$this->allowedLocalizations = array_combine($allowedLocalizations, $allowedLocalizations);
return $this;
} | php | public function & SetAllowedLocalizations (/* ...$allowedLocalizations */) {
/** @var $this \MvcCore\Ext\Routers\Modules\IRoute */
$allowedLocalizations = func_get_args();
if (count($allowedLocalizations) === 1 && is_array($allowedLocalizations[0]))
$allowedLocalizations = $allowedLocalizations[0];
$this->allowedLocalizations = array_combine($allowedLocalizations, $allowedLocalizations);
return $this;
} | [
"public",
"function",
"&",
"SetAllowedLocalizations",
"(",
"/* ...$allowedLocalizations */",
")",
"{",
"/** @var $this \\MvcCore\\Ext\\Routers\\Modules\\IRoute */",
"$",
"allowedLocalizations",
"=",
"func_get_args",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"allowedLocalizations",
")",
"===",
"1",
"&&",
"is_array",
"(",
"$",
"allowedLocalizations",
"[",
"0",
"]",
")",
")",
"$",
"allowedLocalizations",
"=",
"$",
"allowedLocalizations",
"[",
"0",
"]",
";",
"$",
"this",
"->",
"allowedLocalizations",
"=",
"array_combine",
"(",
"$",
"allowedLocalizations",
",",
"$",
"allowedLocalizations",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set allowed localizations for the routed module if there is used
any variant of module router with localization.
@var \string[] $allowedLocalizations..., International lower case language
code(s) (+ optionally dash character
+ upper case international locale code(s))
@return \MvcCore\Ext\Routers\Modules\Route|\MvcCore\Ext\Routers\Modules\IRoute | [
"Set",
"allowed",
"localizations",
"for",
"the",
"routed",
"module",
"if",
"there",
"is",
"used",
"any",
"variant",
"of",
"module",
"router",
"with",
"localization",
"."
] | train | https://github.com/mvccore/ext-router-module/blob/7695784a451db86cca6a43c98d076803cd0a50a7/src/MvcCore/Ext/Routers/Modules/Route/PropsGettersSetters.php#L115-L122 |
mvccore/ext-router-module | src/MvcCore/Ext/Routers/Modules/Route/PropsGettersSetters.php | PropsGettersSetters.trriggerUnusedMethodError | protected function trriggerUnusedMethodError ($method) {
/** @var $this \MvcCore\Ext\Routers\Modules\IRoute */
$selfClass = version_compare(PHP_VERSION, '5.5', '>') ? self::class : __CLASS__;
trigger_error("[$selfClass] The method `$method` is not used in this extended class.", E_USER_WARNING);
return $this;
} | php | protected function trriggerUnusedMethodError ($method) {
/** @var $this \MvcCore\Ext\Routers\Modules\IRoute */
$selfClass = version_compare(PHP_VERSION, '5.5', '>') ? self::class : __CLASS__;
trigger_error("[$selfClass] The method `$method` is not used in this extended class.", E_USER_WARNING);
return $this;
} | [
"protected",
"function",
"trriggerUnusedMethodError",
"(",
"$",
"method",
")",
"{",
"/** @var $this \\MvcCore\\Ext\\Routers\\Modules\\IRoute */",
"$",
"selfClass",
"=",
"version_compare",
"(",
"PHP_VERSION",
",",
"'5.5'",
",",
"'>'",
")",
"?",
"self",
"::",
"class",
":",
"__CLASS__",
";",
"trigger_error",
"(",
"\"[$selfClass] The method `$method` is not used in this extended class.\"",
",",
"E_USER_WARNING",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Trigger `E_USER_WARNING` user error about not used method in this
extended module domain route.
@param string $method
@return \MvcCore\Ext\Routers\Modules\IRoute | [
"Trigger",
"E_USER_WARNING",
"user",
"error",
"about",
"not",
"used",
"method",
"in",
"this",
"extended",
"module",
"domain",
"route",
"."
] | train | https://github.com/mvccore/ext-router-module/blob/7695784a451db86cca6a43c98d076803cd0a50a7/src/MvcCore/Ext/Routers/Modules/Route/PropsGettersSetters.php#L308-L313 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Mail/src/parser/interfaces/part_parser.php | ezcMailPartParser.createPartParserForHeaders | static public function createPartParserForHeaders( ezcMailHeadersHolder $headers )
{
// default as specified by RFC2045 - #5.2
$mainType = 'text';
$subType = 'plain';
// parse the Content-Type header
if ( isset( $headers['Content-Type'] ) )
{
$matches = array();
// matches "type/subtype; blahblahblah"
preg_match_all( '/^(\S+)\/([^;]+)/',
$headers['Content-Type'], $matches, PREG_SET_ORDER );
if ( count( $matches ) > 0 )
{
$mainType = strtolower( $matches[0][1] );
$subType = strtolower( $matches[0][2] );
}
}
$bodyParser = null;
// create the correct type parser for this the detected type of part
switch ( $mainType )
{
/* RFC 2045 defined types */
case 'image':
case 'audio':
case 'video':
case 'application':
$bodyParser = new ezcMailFileParser( $mainType, $subType, $headers );
break;
case 'message':
switch ( $subType )
{
case "rfc822":
$bodyParser = new ezcMailRfc822DigestParser( $headers );
break;
case "delivery-status":
$bodyParser = new ezcMailDeliveryStatusParser( $headers );
break;
default:
$bodyParser = new ezcMailFileParser( $mainType, $subType, $headers );
break;
}
break;
case 'text':
if ( ezcMailPartParser::$parseTextAttachmentsAsFiles === true )
{
$bodyParser = new ezcMailFileParser( $mainType, $subType, $headers );
}
else
{
$bodyParser = new ezcMailTextParser( $subType, $headers );
}
break;
case 'multipart':
switch ( $subType )
{
case 'mixed':
$bodyParser = new ezcMailMultipartMixedParser( $headers );
break;
case 'alternative':
$bodyParser = new ezcMailMultipartAlternativeParser( $headers );
break;
case 'related':
$bodyParser = new ezcMailMultipartRelatedParser( $headers );
break;
case 'digest':
$bodyParser = new ezcMailMultipartDigestParser( $headers );
break;
case 'report':
$bodyParser = new ezcMailMultipartReportParser( $headers );
break;
default:
$bodyParser = new ezcMailMultipartMixedParser( $headers );
break;
}
break;
/* extensions */
default:
// we treat the body as binary if no main content type is set
// or if it is unknown
$bodyParser = new ezcMailFileParser( $mainType, $subType, $headers );
break;
}
return $bodyParser;
} | php | static public function createPartParserForHeaders( ezcMailHeadersHolder $headers )
{
// default as specified by RFC2045 - #5.2
$mainType = 'text';
$subType = 'plain';
// parse the Content-Type header
if ( isset( $headers['Content-Type'] ) )
{
$matches = array();
// matches "type/subtype; blahblahblah"
preg_match_all( '/^(\S+)\/([^;]+)/',
$headers['Content-Type'], $matches, PREG_SET_ORDER );
if ( count( $matches ) > 0 )
{
$mainType = strtolower( $matches[0][1] );
$subType = strtolower( $matches[0][2] );
}
}
$bodyParser = null;
// create the correct type parser for this the detected type of part
switch ( $mainType )
{
/* RFC 2045 defined types */
case 'image':
case 'audio':
case 'video':
case 'application':
$bodyParser = new ezcMailFileParser( $mainType, $subType, $headers );
break;
case 'message':
switch ( $subType )
{
case "rfc822":
$bodyParser = new ezcMailRfc822DigestParser( $headers );
break;
case "delivery-status":
$bodyParser = new ezcMailDeliveryStatusParser( $headers );
break;
default:
$bodyParser = new ezcMailFileParser( $mainType, $subType, $headers );
break;
}
break;
case 'text':
if ( ezcMailPartParser::$parseTextAttachmentsAsFiles === true )
{
$bodyParser = new ezcMailFileParser( $mainType, $subType, $headers );
}
else
{
$bodyParser = new ezcMailTextParser( $subType, $headers );
}
break;
case 'multipart':
switch ( $subType )
{
case 'mixed':
$bodyParser = new ezcMailMultipartMixedParser( $headers );
break;
case 'alternative':
$bodyParser = new ezcMailMultipartAlternativeParser( $headers );
break;
case 'related':
$bodyParser = new ezcMailMultipartRelatedParser( $headers );
break;
case 'digest':
$bodyParser = new ezcMailMultipartDigestParser( $headers );
break;
case 'report':
$bodyParser = new ezcMailMultipartReportParser( $headers );
break;
default:
$bodyParser = new ezcMailMultipartMixedParser( $headers );
break;
}
break;
/* extensions */
default:
// we treat the body as binary if no main content type is set
// or if it is unknown
$bodyParser = new ezcMailFileParser( $mainType, $subType, $headers );
break;
}
return $bodyParser;
} | [
"static",
"public",
"function",
"createPartParserForHeaders",
"(",
"ezcMailHeadersHolder",
"$",
"headers",
")",
"{",
"// default as specified by RFC2045 - #5.2",
"$",
"mainType",
"=",
"'text'",
";",
"$",
"subType",
"=",
"'plain'",
";",
"// parse the Content-Type header",
"if",
"(",
"isset",
"(",
"$",
"headers",
"[",
"'Content-Type'",
"]",
")",
")",
"{",
"$",
"matches",
"=",
"array",
"(",
")",
";",
"// matches \"type/subtype; blahblahblah\"",
"preg_match_all",
"(",
"'/^(\\S+)\\/([^;]+)/'",
",",
"$",
"headers",
"[",
"'Content-Type'",
"]",
",",
"$",
"matches",
",",
"PREG_SET_ORDER",
")",
";",
"if",
"(",
"count",
"(",
"$",
"matches",
")",
">",
"0",
")",
"{",
"$",
"mainType",
"=",
"strtolower",
"(",
"$",
"matches",
"[",
"0",
"]",
"[",
"1",
"]",
")",
";",
"$",
"subType",
"=",
"strtolower",
"(",
"$",
"matches",
"[",
"0",
"]",
"[",
"2",
"]",
")",
";",
"}",
"}",
"$",
"bodyParser",
"=",
"null",
";",
"// create the correct type parser for this the detected type of part",
"switch",
"(",
"$",
"mainType",
")",
"{",
"/* RFC 2045 defined types */",
"case",
"'image'",
":",
"case",
"'audio'",
":",
"case",
"'video'",
":",
"case",
"'application'",
":",
"$",
"bodyParser",
"=",
"new",
"ezcMailFileParser",
"(",
"$",
"mainType",
",",
"$",
"subType",
",",
"$",
"headers",
")",
";",
"break",
";",
"case",
"'message'",
":",
"switch",
"(",
"$",
"subType",
")",
"{",
"case",
"\"rfc822\"",
":",
"$",
"bodyParser",
"=",
"new",
"ezcMailRfc822DigestParser",
"(",
"$",
"headers",
")",
";",
"break",
";",
"case",
"\"delivery-status\"",
":",
"$",
"bodyParser",
"=",
"new",
"ezcMailDeliveryStatusParser",
"(",
"$",
"headers",
")",
";",
"break",
";",
"default",
":",
"$",
"bodyParser",
"=",
"new",
"ezcMailFileParser",
"(",
"$",
"mainType",
",",
"$",
"subType",
",",
"$",
"headers",
")",
";",
"break",
";",
"}",
"break",
";",
"case",
"'text'",
":",
"if",
"(",
"ezcMailPartParser",
"::",
"$",
"parseTextAttachmentsAsFiles",
"===",
"true",
")",
"{",
"$",
"bodyParser",
"=",
"new",
"ezcMailFileParser",
"(",
"$",
"mainType",
",",
"$",
"subType",
",",
"$",
"headers",
")",
";",
"}",
"else",
"{",
"$",
"bodyParser",
"=",
"new",
"ezcMailTextParser",
"(",
"$",
"subType",
",",
"$",
"headers",
")",
";",
"}",
"break",
";",
"case",
"'multipart'",
":",
"switch",
"(",
"$",
"subType",
")",
"{",
"case",
"'mixed'",
":",
"$",
"bodyParser",
"=",
"new",
"ezcMailMultipartMixedParser",
"(",
"$",
"headers",
")",
";",
"break",
";",
"case",
"'alternative'",
":",
"$",
"bodyParser",
"=",
"new",
"ezcMailMultipartAlternativeParser",
"(",
"$",
"headers",
")",
";",
"break",
";",
"case",
"'related'",
":",
"$",
"bodyParser",
"=",
"new",
"ezcMailMultipartRelatedParser",
"(",
"$",
"headers",
")",
";",
"break",
";",
"case",
"'digest'",
":",
"$",
"bodyParser",
"=",
"new",
"ezcMailMultipartDigestParser",
"(",
"$",
"headers",
")",
";",
"break",
";",
"case",
"'report'",
":",
"$",
"bodyParser",
"=",
"new",
"ezcMailMultipartReportParser",
"(",
"$",
"headers",
")",
";",
"break",
";",
"default",
":",
"$",
"bodyParser",
"=",
"new",
"ezcMailMultipartMixedParser",
"(",
"$",
"headers",
")",
";",
"break",
";",
"}",
"break",
";",
"/* extensions */",
"default",
":",
"// we treat the body as binary if no main content type is set",
"// or if it is unknown",
"$",
"bodyParser",
"=",
"new",
"ezcMailFileParser",
"(",
"$",
"mainType",
",",
"$",
"subType",
",",
"$",
"headers",
")",
";",
"break",
";",
"}",
"return",
"$",
"bodyParser",
";",
"}"
] | Returns a part parser corresponding to the given $headers.
@throws ezcBaseFileNotFoundException
if a neccessary temporary file could not be openened.
@param ezcMailHeadersHolder $headers
@return ezcMailPartParser | [
"Returns",
"a",
"part",
"parser",
"corresponding",
"to",
"the",
"given",
"$headers",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/parser/interfaces/part_parser.php#L105-L197 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Mail/src/parser/interfaces/part_parser.php | ezcMailPartParser.parseHeader | protected function parseHeader( $line, ezcMailHeadersHolder $headers )
{
$matches = array();
preg_match_all( "/^([\w-_]*):\s?(.*)/", $line, $matches, PREG_SET_ORDER );
if ( count( $matches ) > 0 )
{
if ( !in_array( strtolower( $matches[0][1] ), self::$uniqueHeaders ) )
{
$arr = $headers[$matches[0][1]];
$arr[0][] = str_replace( "\t", " ", trim( $matches[0][2] ) );
$headers[$matches[0][1]] = $arr;
}
else
{
$headers[$matches[0][1]] = str_replace( "\t", " ", trim( $matches[0][2] ) );
}
$this->lastParsedHeader = $matches[0][1];
}
else if ( $this->lastParsedHeader !== null ) // take care of folding
{
if ( !in_array( strtolower( $this->lastParsedHeader ), self::$uniqueHeaders ) )
{
$arr = $headers[$this->lastParsedHeader];
$arr[0][count( $arr[0] ) - 1] .= str_replace( "\t", " ", $line );
$headers[$this->lastParsedHeader] = $arr;
}
else
{
$headers[$this->lastParsedHeader] .= str_replace( "\t", " ", $line );
}
}
// else -invalid syntax, this should never happen.
} | php | protected function parseHeader( $line, ezcMailHeadersHolder $headers )
{
$matches = array();
preg_match_all( "/^([\w-_]*):\s?(.*)/", $line, $matches, PREG_SET_ORDER );
if ( count( $matches ) > 0 )
{
if ( !in_array( strtolower( $matches[0][1] ), self::$uniqueHeaders ) )
{
$arr = $headers[$matches[0][1]];
$arr[0][] = str_replace( "\t", " ", trim( $matches[0][2] ) );
$headers[$matches[0][1]] = $arr;
}
else
{
$headers[$matches[0][1]] = str_replace( "\t", " ", trim( $matches[0][2] ) );
}
$this->lastParsedHeader = $matches[0][1];
}
else if ( $this->lastParsedHeader !== null ) // take care of folding
{
if ( !in_array( strtolower( $this->lastParsedHeader ), self::$uniqueHeaders ) )
{
$arr = $headers[$this->lastParsedHeader];
$arr[0][count( $arr[0] ) - 1] .= str_replace( "\t", " ", $line );
$headers[$this->lastParsedHeader] = $arr;
}
else
{
$headers[$this->lastParsedHeader] .= str_replace( "\t", " ", $line );
}
}
// else -invalid syntax, this should never happen.
} | [
"protected",
"function",
"parseHeader",
"(",
"$",
"line",
",",
"ezcMailHeadersHolder",
"$",
"headers",
")",
"{",
"$",
"matches",
"=",
"array",
"(",
")",
";",
"preg_match_all",
"(",
"\"/^([\\w-_]*):\\s?(.*)/\"",
",",
"$",
"line",
",",
"$",
"matches",
",",
"PREG_SET_ORDER",
")",
";",
"if",
"(",
"count",
"(",
"$",
"matches",
")",
">",
"0",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"strtolower",
"(",
"$",
"matches",
"[",
"0",
"]",
"[",
"1",
"]",
")",
",",
"self",
"::",
"$",
"uniqueHeaders",
")",
")",
"{",
"$",
"arr",
"=",
"$",
"headers",
"[",
"$",
"matches",
"[",
"0",
"]",
"[",
"1",
"]",
"]",
";",
"$",
"arr",
"[",
"0",
"]",
"[",
"]",
"=",
"str_replace",
"(",
"\"\\t\"",
",",
"\" \"",
",",
"trim",
"(",
"$",
"matches",
"[",
"0",
"]",
"[",
"2",
"]",
")",
")",
";",
"$",
"headers",
"[",
"$",
"matches",
"[",
"0",
"]",
"[",
"1",
"]",
"]",
"=",
"$",
"arr",
";",
"}",
"else",
"{",
"$",
"headers",
"[",
"$",
"matches",
"[",
"0",
"]",
"[",
"1",
"]",
"]",
"=",
"str_replace",
"(",
"\"\\t\"",
",",
"\" \"",
",",
"trim",
"(",
"$",
"matches",
"[",
"0",
"]",
"[",
"2",
"]",
")",
")",
";",
"}",
"$",
"this",
"->",
"lastParsedHeader",
"=",
"$",
"matches",
"[",
"0",
"]",
"[",
"1",
"]",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"lastParsedHeader",
"!==",
"null",
")",
"// take care of folding",
"{",
"if",
"(",
"!",
"in_array",
"(",
"strtolower",
"(",
"$",
"this",
"->",
"lastParsedHeader",
")",
",",
"self",
"::",
"$",
"uniqueHeaders",
")",
")",
"{",
"$",
"arr",
"=",
"$",
"headers",
"[",
"$",
"this",
"->",
"lastParsedHeader",
"]",
";",
"$",
"arr",
"[",
"0",
"]",
"[",
"count",
"(",
"$",
"arr",
"[",
"0",
"]",
")",
"-",
"1",
"]",
".=",
"str_replace",
"(",
"\"\\t\"",
",",
"\" \"",
",",
"$",
"line",
")",
";",
"$",
"headers",
"[",
"$",
"this",
"->",
"lastParsedHeader",
"]",
"=",
"$",
"arr",
";",
"}",
"else",
"{",
"$",
"headers",
"[",
"$",
"this",
"->",
"lastParsedHeader",
"]",
".=",
"str_replace",
"(",
"\"\\t\"",
",",
"\" \"",
",",
"$",
"line",
")",
";",
"}",
"}",
"// else -invalid syntax, this should never happen.",
"}"
] | Parses the header given by $line and adds to $headers.
This method is usually used to parse the headers for a subpart. The
only exception is RFC822 parts since you know the type in advance.
@todo deal with headers that are listed several times
@param string $line
@param ezcMailHeadersHolder $headers | [
"Parses",
"the",
"header",
"given",
"by",
"$line",
"and",
"adds",
"to",
"$headers",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/parser/interfaces/part_parser.php#L209-L241 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Mail/src/parser/interfaces/part_parser.php | ezcMailPartParser.parsePartHeaders | static public function parsePartHeaders( ezcMailHeadersHolder $headers, ezcMailPart $part )
{
if ( isset( $headers['Content-Disposition'] ) )
{
$part->contentDisposition = ezcMailRfc2231Implementation::parseContentDisposition( $headers['Content-Disposition'] );
}
} | php | static public function parsePartHeaders( ezcMailHeadersHolder $headers, ezcMailPart $part )
{
if ( isset( $headers['Content-Disposition'] ) )
{
$part->contentDisposition = ezcMailRfc2231Implementation::parseContentDisposition( $headers['Content-Disposition'] );
}
} | [
"static",
"public",
"function",
"parsePartHeaders",
"(",
"ezcMailHeadersHolder",
"$",
"headers",
",",
"ezcMailPart",
"$",
"part",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"headers",
"[",
"'Content-Disposition'",
"]",
")",
")",
"{",
"$",
"part",
"->",
"contentDisposition",
"=",
"ezcMailRfc2231Implementation",
"::",
"parseContentDisposition",
"(",
"$",
"headers",
"[",
"'Content-Disposition'",
"]",
")",
";",
"}",
"}"
] | Scans through $headers and sets any specific header properties on $part.
Currently we only have Content-Disposition on the ezcMailPart level.
All parser parts must call this method once.
@param ezcMailHeadersHolder $headers
@param ezcMailPart $part | [
"Scans",
"through",
"$headers",
"and",
"sets",
"any",
"specific",
"header",
"properties",
"on",
"$part",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/parser/interfaces/part_parser.php#L252-L258 |
oroinc/OroLayoutComponent | LayoutContext.php | LayoutContext.getResolver | public function getResolver()
{
if ($this->resolver === null) {
$this->resolver = $this->createResolver();
}
return $this->resolver;
} | php | public function getResolver()
{
if ($this->resolver === null) {
$this->resolver = $this->createResolver();
}
return $this->resolver;
} | [
"public",
"function",
"getResolver",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"resolver",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"resolver",
"=",
"$",
"this",
"->",
"createResolver",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"resolver",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/LayoutContext.php#L46-L53 |
oroinc/OroLayoutComponent | LayoutContext.php | LayoutContext.resolve | public function resolve()
{
if ($this->resolved) {
throw new Exception\LogicException('The context variables are already resolved.');
}
try {
$this->items = $this->getResolver()->resolve($this->items);
// validate that all added objects implement ContextItemInterface
foreach ($this->items as $name => $value) {
if (is_object($value) && !$value instanceof ContextItemInterface) {
throw new InvalidOptionsException(
sprintf(
'The option "%s" has invalid type. Expected "%s", but "%s" given.',
$name,
'Oro\Component\Layout\ContextItemInterface',
get_class($value)
)
);
}
}
$this->resolved = true;
$this->hash = $this->generateHash();
} catch (OptionsResolverException $e) {
throw new Exception\LogicException(
sprintf('Failed to resolve the context variables. Reason: %s', $e->getMessage()),
0,
$e
);
}
} | php | public function resolve()
{
if ($this->resolved) {
throw new Exception\LogicException('The context variables are already resolved.');
}
try {
$this->items = $this->getResolver()->resolve($this->items);
// validate that all added objects implement ContextItemInterface
foreach ($this->items as $name => $value) {
if (is_object($value) && !$value instanceof ContextItemInterface) {
throw new InvalidOptionsException(
sprintf(
'The option "%s" has invalid type. Expected "%s", but "%s" given.',
$name,
'Oro\Component\Layout\ContextItemInterface',
get_class($value)
)
);
}
}
$this->resolved = true;
$this->hash = $this->generateHash();
} catch (OptionsResolverException $e) {
throw new Exception\LogicException(
sprintf('Failed to resolve the context variables. Reason: %s', $e->getMessage()),
0,
$e
);
}
} | [
"public",
"function",
"resolve",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"resolved",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"LogicException",
"(",
"'The context variables are already resolved.'",
")",
";",
"}",
"try",
"{",
"$",
"this",
"->",
"items",
"=",
"$",
"this",
"->",
"getResolver",
"(",
")",
"->",
"resolve",
"(",
"$",
"this",
"->",
"items",
")",
";",
"// validate that all added objects implement ContextItemInterface",
"foreach",
"(",
"$",
"this",
"->",
"items",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
"&&",
"!",
"$",
"value",
"instanceof",
"ContextItemInterface",
")",
"{",
"throw",
"new",
"InvalidOptionsException",
"(",
"sprintf",
"(",
"'The option \"%s\" has invalid type. Expected \"%s\", but \"%s\" given.'",
",",
"$",
"name",
",",
"'Oro\\Component\\Layout\\ContextItemInterface'",
",",
"get_class",
"(",
"$",
"value",
")",
")",
")",
";",
"}",
"}",
"$",
"this",
"->",
"resolved",
"=",
"true",
";",
"$",
"this",
"->",
"hash",
"=",
"$",
"this",
"->",
"generateHash",
"(",
")",
";",
"}",
"catch",
"(",
"OptionsResolverException",
"$",
"e",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"LogicException",
"(",
"sprintf",
"(",
"'Failed to resolve the context variables. Reason: %s'",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
",",
"0",
",",
"$",
"e",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/LayoutContext.php#L58-L90 |
oroinc/OroLayoutComponent | LayoutContext.php | LayoutContext.has | public function has($name)
{
return isset($this->items[$name]) || array_key_exists($name, $this->items);
} | php | public function has($name)
{
return isset($this->items[$name]) || array_key_exists($name, $this->items);
} | [
"public",
"function",
"has",
"(",
"$",
"name",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"items",
"[",
"$",
"name",
"]",
")",
"||",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"items",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/LayoutContext.php#L103-L106 |
oroinc/OroLayoutComponent | LayoutContext.php | LayoutContext.getOr | public function getOr($name, $default = null)
{
return isset($this->items[$name]) || array_key_exists($name, $this->items)
? $this->items[$name]
: $default;
} | php | public function getOr($name, $default = null)
{
return isset($this->items[$name]) || array_key_exists($name, $this->items)
? $this->items[$name]
: $default;
} | [
"public",
"function",
"getOr",
"(",
"$",
"name",
",",
"$",
"default",
"=",
"null",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"items",
"[",
"$",
"name",
"]",
")",
"||",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"items",
")",
"?",
"$",
"this",
"->",
"items",
"[",
"$",
"name",
"]",
":",
"$",
"default",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/LayoutContext.php#L123-L128 |
oroinc/OroLayoutComponent | LayoutContext.php | LayoutContext.set | public function set($name, $value)
{
if ($this->resolved && !$this->has($name)) {
throw new Exception\LogicException(
sprintf('The item "%s" cannot be added because the context variables are already resolved.', $name)
);
}
$this->items[$name] = $value;
} | php | public function set($name, $value)
{
if ($this->resolved && !$this->has($name)) {
throw new Exception\LogicException(
sprintf('The item "%s" cannot be added because the context variables are already resolved.', $name)
);
}
$this->items[$name] = $value;
} | [
"public",
"function",
"set",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"resolved",
"&&",
"!",
"$",
"this",
"->",
"has",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"LogicException",
"(",
"sprintf",
"(",
"'The item \"%s\" cannot be added because the context variables are already resolved.'",
",",
"$",
"name",
")",
")",
";",
"}",
"$",
"this",
"->",
"items",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/LayoutContext.php#L133-L142 |
oroinc/OroLayoutComponent | LayoutContext.php | LayoutContext.remove | public function remove($name)
{
if ($this->resolved && $this->has($name)) {
throw new Exception\LogicException(
sprintf('The item "%s" cannot be removed because the context variables are already resolved.', $name)
);
}
unset($this->items[$name]);
} | php | public function remove($name)
{
if ($this->resolved && $this->has($name)) {
throw new Exception\LogicException(
sprintf('The item "%s" cannot be removed because the context variables are already resolved.', $name)
);
}
unset($this->items[$name]);
} | [
"public",
"function",
"remove",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"resolved",
"&&",
"$",
"this",
"->",
"has",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"LogicException",
"(",
"sprintf",
"(",
"'The item \"%s\" cannot be removed because the context variables are already resolved.'",
",",
"$",
"name",
")",
")",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"items",
"[",
"$",
"name",
"]",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/LayoutContext.php#L147-L156 |
oroinc/OroLayoutComponent | LayoutContext.php | LayoutContext.offsetExists | public function offsetExists($name)
{
return isset($this->items[$name]) || array_key_exists($name, $this->items);
} | php | public function offsetExists($name)
{
return isset($this->items[$name]) || array_key_exists($name, $this->items);
} | [
"public",
"function",
"offsetExists",
"(",
"$",
"name",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"items",
"[",
"$",
"name",
"]",
")",
"||",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"items",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/LayoutContext.php#L169-L172 |
oroinc/OroLayoutComponent | LayoutContext.php | LayoutContext.offsetGet | public function offsetGet($name)
{
if (!isset($this->items[$name]) && !array_key_exists($name, $this->items)) {
throw new \OutOfBoundsException(sprintf('Undefined index: %s.', $name));
};
return $this->items[$name];
} | php | public function offsetGet($name)
{
if (!isset($this->items[$name]) && !array_key_exists($name, $this->items)) {
throw new \OutOfBoundsException(sprintf('Undefined index: %s.', $name));
};
return $this->items[$name];
} | [
"public",
"function",
"offsetGet",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"items",
"[",
"$",
"name",
"]",
")",
"&&",
"!",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"items",
")",
")",
"{",
"throw",
"new",
"\\",
"OutOfBoundsException",
"(",
"sprintf",
"(",
"'Undefined index: %s.'",
",",
"$",
"name",
")",
")",
";",
"}",
";",
"return",
"$",
"this",
"->",
"items",
"[",
"$",
"name",
"]",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/LayoutContext.php#L177-L184 |
mothership-ec/composer | src/Composer/Repository/ComposerRepository.php | ComposerRepository.findPackage | public function findPackage($name, $version)
{
if (!$this->hasProviders()) {
return parent::findPackage($name, $version);
}
// normalize version & name
$versionParser = new VersionParser();
$version = $versionParser->normalize($version);
$name = strtolower($name);
foreach ($this->getProviderNames() as $providerName) {
if ($name === $providerName) {
$packages = $this->whatProvides(new Pool('dev'), $providerName);
foreach ($packages as $package) {
if ($name == $package->getName() && $version === $package->getVersion()) {
return $package;
}
}
}
}
} | php | public function findPackage($name, $version)
{
if (!$this->hasProviders()) {
return parent::findPackage($name, $version);
}
// normalize version & name
$versionParser = new VersionParser();
$version = $versionParser->normalize($version);
$name = strtolower($name);
foreach ($this->getProviderNames() as $providerName) {
if ($name === $providerName) {
$packages = $this->whatProvides(new Pool('dev'), $providerName);
foreach ($packages as $package) {
if ($name == $package->getName() && $version === $package->getVersion()) {
return $package;
}
}
}
}
} | [
"public",
"function",
"findPackage",
"(",
"$",
"name",
",",
"$",
"version",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasProviders",
"(",
")",
")",
"{",
"return",
"parent",
"::",
"findPackage",
"(",
"$",
"name",
",",
"$",
"version",
")",
";",
"}",
"// normalize version & name",
"$",
"versionParser",
"=",
"new",
"VersionParser",
"(",
")",
";",
"$",
"version",
"=",
"$",
"versionParser",
"->",
"normalize",
"(",
"$",
"version",
")",
";",
"$",
"name",
"=",
"strtolower",
"(",
"$",
"name",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getProviderNames",
"(",
")",
"as",
"$",
"providerName",
")",
"{",
"if",
"(",
"$",
"name",
"===",
"$",
"providerName",
")",
"{",
"$",
"packages",
"=",
"$",
"this",
"->",
"whatProvides",
"(",
"new",
"Pool",
"(",
"'dev'",
")",
",",
"$",
"providerName",
")",
";",
"foreach",
"(",
"$",
"packages",
"as",
"$",
"package",
")",
"{",
"if",
"(",
"$",
"name",
"==",
"$",
"package",
"->",
"getName",
"(",
")",
"&&",
"$",
"version",
"===",
"$",
"package",
"->",
"getVersion",
"(",
")",
")",
"{",
"return",
"$",
"package",
";",
"}",
"}",
"}",
"}",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/Repository/ComposerRepository.php#L102-L122 |
mothership-ec/composer | src/Composer/Repository/ComposerRepository.php | ComposerRepository.search | public function search($query, $mode = 0)
{
$this->loadRootServerFile();
if ($this->searchUrl && $mode === self::SEARCH_FULLTEXT) {
$url = str_replace('%query%', $query, $this->searchUrl);
$hostname = parse_url($url, PHP_URL_HOST) ?: $url;
$json = $this->rfs->getContents($hostname, $url, false);
$results = JsonFile::parseJson($json, $url);
return $results['results'];
}
if ($this->hasProviders()) {
$results = array();
$regex = '{(?:'.implode('|', preg_split('{\s+}', $query)).')}i';
foreach ($this->getProviderNames() as $name) {
if (preg_match($regex, $name)) {
$results[] = array('name' => $name);
}
}
return $results;
}
return parent::search($query, $mode);
} | php | public function search($query, $mode = 0)
{
$this->loadRootServerFile();
if ($this->searchUrl && $mode === self::SEARCH_FULLTEXT) {
$url = str_replace('%query%', $query, $this->searchUrl);
$hostname = parse_url($url, PHP_URL_HOST) ?: $url;
$json = $this->rfs->getContents($hostname, $url, false);
$results = JsonFile::parseJson($json, $url);
return $results['results'];
}
if ($this->hasProviders()) {
$results = array();
$regex = '{(?:'.implode('|', preg_split('{\s+}', $query)).')}i';
foreach ($this->getProviderNames() as $name) {
if (preg_match($regex, $name)) {
$results[] = array('name' => $name);
}
}
return $results;
}
return parent::search($query, $mode);
} | [
"public",
"function",
"search",
"(",
"$",
"query",
",",
"$",
"mode",
"=",
"0",
")",
"{",
"$",
"this",
"->",
"loadRootServerFile",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"searchUrl",
"&&",
"$",
"mode",
"===",
"self",
"::",
"SEARCH_FULLTEXT",
")",
"{",
"$",
"url",
"=",
"str_replace",
"(",
"'%query%'",
",",
"$",
"query",
",",
"$",
"this",
"->",
"searchUrl",
")",
";",
"$",
"hostname",
"=",
"parse_url",
"(",
"$",
"url",
",",
"PHP_URL_HOST",
")",
"?",
":",
"$",
"url",
";",
"$",
"json",
"=",
"$",
"this",
"->",
"rfs",
"->",
"getContents",
"(",
"$",
"hostname",
",",
"$",
"url",
",",
"false",
")",
";",
"$",
"results",
"=",
"JsonFile",
"::",
"parseJson",
"(",
"$",
"json",
",",
"$",
"url",
")",
";",
"return",
"$",
"results",
"[",
"'results'",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"hasProviders",
"(",
")",
")",
"{",
"$",
"results",
"=",
"array",
"(",
")",
";",
"$",
"regex",
"=",
"'{(?:'",
".",
"implode",
"(",
"'|'",
",",
"preg_split",
"(",
"'{\\s+}'",
",",
"$",
"query",
")",
")",
".",
"')}i'",
";",
"foreach",
"(",
"$",
"this",
"->",
"getProviderNames",
"(",
")",
"as",
"$",
"name",
")",
"{",
"if",
"(",
"preg_match",
"(",
"$",
"regex",
",",
"$",
"name",
")",
")",
"{",
"$",
"results",
"[",
"]",
"=",
"array",
"(",
"'name'",
"=>",
"$",
"name",
")",
";",
"}",
"}",
"return",
"$",
"results",
";",
"}",
"return",
"parent",
"::",
"search",
"(",
"$",
"query",
",",
"$",
"mode",
")",
";",
"}"
] | {@inheritDoc} | [
"{"
] | train | https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/Repository/ComposerRepository.php#L169-L197 |
ezsystems/ezcomments-ls-extension | classes/ezcomnotificationemailmanager.php | ezcomNotificationEmailManager.executeSending | public function executeSending( $subject, $body, $subscriber )
{
$email = $subscriber->attribute( 'email' );
$parameters = array();
$parameters['content_type'] = $this->emailContentType;
$parameters['from'] = $this->emailFrom;
$transport = eZNotificationTransport::instance( 'ezmail' );
$result = $transport->send( array( $email ), $subject, $body, null, $parameters );
if ( $result === false )
{
throw new Exception( 'Send email error! Subscriber id:' .$subscriber->attribute( 'id' ) );
}
eZDebugSetting::writeNotice( 'extension-ezcomments', "An email has been sent to '$email' (subject: $subject)", __METHOD__ );
} | php | public function executeSending( $subject, $body, $subscriber )
{
$email = $subscriber->attribute( 'email' );
$parameters = array();
$parameters['content_type'] = $this->emailContentType;
$parameters['from'] = $this->emailFrom;
$transport = eZNotificationTransport::instance( 'ezmail' );
$result = $transport->send( array( $email ), $subject, $body, null, $parameters );
if ( $result === false )
{
throw new Exception( 'Send email error! Subscriber id:' .$subscriber->attribute( 'id' ) );
}
eZDebugSetting::writeNotice( 'extension-ezcomments', "An email has been sent to '$email' (subject: $subject)", __METHOD__ );
} | [
"public",
"function",
"executeSending",
"(",
"$",
"subject",
",",
"$",
"body",
",",
"$",
"subscriber",
")",
"{",
"$",
"email",
"=",
"$",
"subscriber",
"->",
"attribute",
"(",
"'email'",
")",
";",
"$",
"parameters",
"=",
"array",
"(",
")",
";",
"$",
"parameters",
"[",
"'content_type'",
"]",
"=",
"$",
"this",
"->",
"emailContentType",
";",
"$",
"parameters",
"[",
"'from'",
"]",
"=",
"$",
"this",
"->",
"emailFrom",
";",
"$",
"transport",
"=",
"eZNotificationTransport",
"::",
"instance",
"(",
"'ezmail'",
")",
";",
"$",
"result",
"=",
"$",
"transport",
"->",
"send",
"(",
"array",
"(",
"$",
"email",
")",
",",
"$",
"subject",
",",
"$",
"body",
",",
"null",
",",
"$",
"parameters",
")",
";",
"if",
"(",
"$",
"result",
"===",
"false",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Send email error! Subscriber id:'",
".",
"$",
"subscriber",
"->",
"attribute",
"(",
"'id'",
")",
")",
";",
"}",
"eZDebugSetting",
"::",
"writeNotice",
"(",
"'extension-ezcomments'",
",",
"\"An email has been sent to '$email' (subject: $subject)\"",
",",
"__METHOD__",
")",
";",
"}"
] | Execute sending process in Email
@see extension/ezcomments/classes/ezcomNotificationManager#executeSending($subject, $body, $subscriber) | [
"Execute",
"sending",
"process",
"in",
"Email"
] | train | https://github.com/ezsystems/ezcomments-ls-extension/blob/2b4cd8c34d4a77813e4d6a9c5a0d317a274c63c5/classes/ezcomnotificationemailmanager.php#L34-L47 |
PayBreak/foundation | src/Decision/Condition/LessThanOrEqualCondition.php | LessThanOrEqualCondition.checkCondition | public function checkCondition(Value $value)
{
return (parent::checkCondition($value) || $value->getValue() == $this->getValue()->getValue());
} | php | public function checkCondition(Value $value)
{
return (parent::checkCondition($value) || $value->getValue() == $this->getValue()->getValue());
} | [
"public",
"function",
"checkCondition",
"(",
"Value",
"$",
"value",
")",
"{",
"return",
"(",
"parent",
"::",
"checkCondition",
"(",
"$",
"value",
")",
"||",
"$",
"value",
"->",
"getValue",
"(",
")",
"==",
"$",
"this",
"->",
"getValue",
"(",
")",
"->",
"getValue",
"(",
")",
")",
";",
"}"
] | Test Value against Condition
@param Value $value
@return bool
@throws \PayBreak\Foundation\Decision\ProcessingException | [
"Test",
"Value",
"against",
"Condition"
] | train | https://github.com/PayBreak/foundation/blob/3dc5a5791e0c95abefa2a415a7f9fdb5abb62ca4/src/Decision/Condition/LessThanOrEqualCondition.php#L38-L41 |
caffeinated/beverage | src/Dotenv.php | Dotenv.normaliseEnvironmentVariable | private static function normaliseEnvironmentVariable($name, $value)
{
list($name, $value) = self::splitCompoundStringIntoParts($name, $value);
$name = self::sanitiseVariableName($name);
$value = self::sanitiseVariableValue($value);
$value = self::resolveNestedVariables($value);
return array($name, $value);
} | php | private static function normaliseEnvironmentVariable($name, $value)
{
list($name, $value) = self::splitCompoundStringIntoParts($name, $value);
$name = self::sanitiseVariableName($name);
$value = self::sanitiseVariableValue($value);
$value = self::resolveNestedVariables($value);
return array($name, $value);
} | [
"private",
"static",
"function",
"normaliseEnvironmentVariable",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"list",
"(",
"$",
"name",
",",
"$",
"value",
")",
"=",
"self",
"::",
"splitCompoundStringIntoParts",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"$",
"name",
"=",
"self",
"::",
"sanitiseVariableName",
"(",
"$",
"name",
")",
";",
"$",
"value",
"=",
"self",
"::",
"sanitiseVariableValue",
"(",
"$",
"value",
")",
";",
"$",
"value",
"=",
"self",
"::",
"resolveNestedVariables",
"(",
"$",
"value",
")",
";",
"return",
"array",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}"
] | Takes value as passed in by developer and:
- ensures we're dealing with a separate name and value, breaking apart the name string if needed
- cleaning the value of quotes
- cleaning the name of quotes
- resolving nested variables
@param $name
@param $value
@return array | [
"Takes",
"value",
"as",
"passed",
"in",
"by",
"developer",
"and",
":",
"-",
"ensures",
"we",
"re",
"dealing",
"with",
"a",
"separate",
"name",
"and",
"value",
"breaking",
"apart",
"the",
"name",
"string",
"if",
"needed",
"-",
"cleaning",
"the",
"value",
"of",
"quotes",
"-",
"cleaning",
"the",
"name",
"of",
"quotes",
"-",
"resolving",
"nested",
"variables"
] | train | https://github.com/caffeinated/beverage/blob/c7d612a1d3bc1baddc97fec60ab17224550efaf3/src/Dotenv.php#L68-L76 |
gedex/php-janrain-api | lib/Janrain/Api/Engage/Engage.php | Engage.setAuthProviders | public function setAuthProviders(array $params = array())
{
if (!isset($params['providers'])) {
throw new MissingArgumentException('providers');
}
if (!is_array($params['providers'])) {
throw new InvalidArgumentException('Invalid Argument: providers must be passed as array');
}
$params['providers'] = json_encode(array_values($params['providers']));
return $this->post('set_auth_providers', $params);
} | php | public function setAuthProviders(array $params = array())
{
if (!isset($params['providers'])) {
throw new MissingArgumentException('providers');
}
if (!is_array($params['providers'])) {
throw new InvalidArgumentException('Invalid Argument: providers must be passed as array');
}
$params['providers'] = json_encode(array_values($params['providers']));
return $this->post('set_auth_providers', $params);
} | [
"public",
"function",
"setAuthProviders",
"(",
"array",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"params",
"[",
"'providers'",
"]",
")",
")",
"{",
"throw",
"new",
"MissingArgumentException",
"(",
"'providers'",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"params",
"[",
"'providers'",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Invalid Argument: providers must be passed as array'",
")",
";",
"}",
"$",
"params",
"[",
"'providers'",
"]",
"=",
"json_encode",
"(",
"array_values",
"(",
"$",
"params",
"[",
"'providers'",
"]",
")",
")",
";",
"return",
"$",
"this",
"->",
"post",
"(",
"'set_auth_providers'",
",",
"$",
"params",
")",
";",
"}"
] | Defines the list of identity providers provided by the Engage server to
sign-in widgets. This is the same list that is managed by the dashboard.
@param array $params | [
"Defines",
"the",
"list",
"of",
"identity",
"providers",
"provided",
"by",
"the",
"Engage",
"server",
"to",
"sign",
"-",
"in",
"widgets",
".",
"This",
"is",
"the",
"same",
"list",
"that",
"is",
"managed",
"by",
"the",
"dashboard",
"."
] | train | https://github.com/gedex/php-janrain-api/blob/6283f68454e0ad5211ac620f1d337df38cd49597/lib/Janrain/Api/Engage/Engage.php#L112-L125 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_select.php | ezcQuerySelect.reset | public function reset()
{
$this->selectString = null;
$this->fromString = null;
$this->whereString = null;
$this->groupString = null;
$this->havingString = null;
$this->orderString = null;
$this->limitString = null;
$this->lastInvokedClauseMethod = null;
$this->boundCounter = 0;
$this->boundValues = array();
} | php | public function reset()
{
$this->selectString = null;
$this->fromString = null;
$this->whereString = null;
$this->groupString = null;
$this->havingString = null;
$this->orderString = null;
$this->limitString = null;
$this->lastInvokedClauseMethod = null;
$this->boundCounter = 0;
$this->boundValues = array();
} | [
"public",
"function",
"reset",
"(",
")",
"{",
"$",
"this",
"->",
"selectString",
"=",
"null",
";",
"$",
"this",
"->",
"fromString",
"=",
"null",
";",
"$",
"this",
"->",
"whereString",
"=",
"null",
";",
"$",
"this",
"->",
"groupString",
"=",
"null",
";",
"$",
"this",
"->",
"havingString",
"=",
"null",
";",
"$",
"this",
"->",
"orderString",
"=",
"null",
";",
"$",
"this",
"->",
"limitString",
"=",
"null",
";",
"$",
"this",
"->",
"lastInvokedClauseMethod",
"=",
"null",
";",
"$",
"this",
"->",
"boundCounter",
"=",
"0",
";",
"$",
"this",
"->",
"boundValues",
"=",
"array",
"(",
")",
";",
"}"
] | Resets the query object for reuse.
@return void | [
"Resets",
"the",
"query",
"object",
"for",
"reuse",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_select.php#L136-L149 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_select.php | ezcQuerySelect.select | public function select()
{
if ( $this->selectString == null )
{
$this->selectString = 'SELECT ';
}
$args = func_get_args();
$cols = self::arrayFlatten( $args );
if ( count( $cols ) < 1 )
{
throw new ezcQueryVariableParameterException( 'select', count( $args ), 1 );
}
$this->lastInvokedMethod = 'select';
$cols = $this->getIdentifiers( $cols );
// glue string should be inserted each time but not before first entry
if ( ( $this->selectString !== 'SELECT ' ) &&
( $this->selectString !== 'SELECT DISTINCT ' ) )
{
$this->selectString .= ', ';
}
$this->selectString .= join( ', ', $cols );
return $this;
} | php | public function select()
{
if ( $this->selectString == null )
{
$this->selectString = 'SELECT ';
}
$args = func_get_args();
$cols = self::arrayFlatten( $args );
if ( count( $cols ) < 1 )
{
throw new ezcQueryVariableParameterException( 'select', count( $args ), 1 );
}
$this->lastInvokedMethod = 'select';
$cols = $this->getIdentifiers( $cols );
// glue string should be inserted each time but not before first entry
if ( ( $this->selectString !== 'SELECT ' ) &&
( $this->selectString !== 'SELECT DISTINCT ' ) )
{
$this->selectString .= ', ';
}
$this->selectString .= join( ', ', $cols );
return $this;
} | [
"public",
"function",
"select",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"selectString",
"==",
"null",
")",
"{",
"$",
"this",
"->",
"selectString",
"=",
"'SELECT '",
";",
"}",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"$",
"cols",
"=",
"self",
"::",
"arrayFlatten",
"(",
"$",
"args",
")",
";",
"if",
"(",
"count",
"(",
"$",
"cols",
")",
"<",
"1",
")",
"{",
"throw",
"new",
"ezcQueryVariableParameterException",
"(",
"'select'",
",",
"count",
"(",
"$",
"args",
")",
",",
"1",
")",
";",
"}",
"$",
"this",
"->",
"lastInvokedMethod",
"=",
"'select'",
";",
"$",
"cols",
"=",
"$",
"this",
"->",
"getIdentifiers",
"(",
"$",
"cols",
")",
";",
"// glue string should be inserted each time but not before first entry",
"if",
"(",
"(",
"$",
"this",
"->",
"selectString",
"!==",
"'SELECT '",
")",
"&&",
"(",
"$",
"this",
"->",
"selectString",
"!==",
"'SELECT DISTINCT '",
")",
")",
"{",
"$",
"this",
"->",
"selectString",
".=",
"', '",
";",
"}",
"$",
"this",
"->",
"selectString",
".=",
"join",
"(",
"', '",
",",
"$",
"cols",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Opens the query and selects which columns you want to return with
the query.
select() accepts an arbitrary number of parameters. Each parameter
must contain either the name of a column or an array containing
the names of the columns.
Each call to select() appends columns to the list of columns that will be
used in the query.
Example:
<code>
$q->select( 'column1', 'column2' );
</code>
The same could also be written
<code>
$columns[] = 'column1';
$columns[] = 'column2;
$q->select( $columns );
</code>
or using several calls
<code>
$q->select( 'column1' )->select( 'column2' );
</code>
Each of above code produce SQL clause 'SELECT column1, column2' for the query.
@throws ezcQueryVariableParameterException if called with no parameters..
@param string|array(string) $... Either a string with a column name or an array of column names.
@return ezcQuery returns a pointer to $this. | [
"Opens",
"the",
"query",
"and",
"selects",
"which",
"columns",
"you",
"want",
"to",
"return",
"with",
"the",
"query",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_select.php#L182-L208 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_select.php | ezcQuerySelect.selectDistinct | public function selectDistinct()
{
if ( $this->selectString == null )
{
$this->selectString = 'SELECT DISTINCT ';
}
elseif ( strpos ( $this->selectString, 'DISTINCT' ) === false )
{
throw new ezcQueryInvalidException(
'SELECT',
'You can\'t use selectDistinct() after using select() in the same query.'
);
}
// Call ezcQuerySelect::select() to do the parameter processing
$args = func_get_args();
return call_user_func_array(
array( $this, 'select' ),
$args
);
} | php | public function selectDistinct()
{
if ( $this->selectString == null )
{
$this->selectString = 'SELECT DISTINCT ';
}
elseif ( strpos ( $this->selectString, 'DISTINCT' ) === false )
{
throw new ezcQueryInvalidException(
'SELECT',
'You can\'t use selectDistinct() after using select() in the same query.'
);
}
// Call ezcQuerySelect::select() to do the parameter processing
$args = func_get_args();
return call_user_func_array(
array( $this, 'select' ),
$args
);
} | [
"public",
"function",
"selectDistinct",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"selectString",
"==",
"null",
")",
"{",
"$",
"this",
"->",
"selectString",
"=",
"'SELECT DISTINCT '",
";",
"}",
"elseif",
"(",
"strpos",
"(",
"$",
"this",
"->",
"selectString",
",",
"'DISTINCT'",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"ezcQueryInvalidException",
"(",
"'SELECT'",
",",
"'You can\\'t use selectDistinct() after using select() in the same query.'",
")",
";",
"}",
"// Call ezcQuerySelect::select() to do the parameter processing",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"return",
"call_user_func_array",
"(",
"array",
"(",
"$",
"this",
",",
"'select'",
")",
",",
"$",
"args",
")",
";",
"}"
] | Opens the query and uses a distinct select on the columns you want to
return with the query.
selectDistinct() accepts an arbitrary number of parameters. Each
parameter must contain either the name of a column or an array
containing the names of the columns.
Each call to selectDistinct() appends columns to the list of columns
that will be used in the query.
Example:
<code>
$q->selectDistinct( 'column1', 'column2' );
</code>
The same could also be written
<code>
$columns[] = 'column1';
$columns[] = 'column2;
$q->selectDistinct( $columns );
</code>
or using several calls
<code>
$q->selectDistinct( 'column1' )->select( 'column2' );
</code>
Each of above code produce SQL clause 'SELECT DISTINCT column1, column2'
for the query.
You may call select() after calling selectDistinct() which will result
in the additional columns beein added. A call of selectDistinct() after
select() will result in an ezcQueryInvalidException.
@throws ezcQueryVariableParameterException if called with no parameters..
@throws ezcQueryInvalidException if called after select()
@param string|array(string) $... Either a string with a column name or an array of column names.
@return ezcQuery returns a pointer to $this. | [
"Opens",
"the",
"query",
"and",
"uses",
"a",
"distinct",
"select",
"on",
"the",
"columns",
"you",
"want",
"to",
"return",
"with",
"the",
"query",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_select.php#L270-L290 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_select.php | ezcQuerySelect.from | public function from()
{
if ( $this->fromString == '' )
{
$this->fromString = 'FROM ';
}
$args = func_get_args();
$tables = self::arrayFlatten( $args );
if ( count( $tables ) < 1 )
{
throw new ezcQueryVariableParameterException( 'from', count( $args ), 1 );
}
$this->lastInvokedMethod = 'from';
$tables = $this->getIdentifiers( $tables );
$tables = $this->getPrefixedTableNames($tables);
// glue string should be inserted each time but not before first entry
if ( $this->fromString != 'FROM ' )
{
$this->fromString .= ', ';
}
$this->fromString .= join( ', ', $tables );
return $this;
} | php | public function from()
{
if ( $this->fromString == '' )
{
$this->fromString = 'FROM ';
}
$args = func_get_args();
$tables = self::arrayFlatten( $args );
if ( count( $tables ) < 1 )
{
throw new ezcQueryVariableParameterException( 'from', count( $args ), 1 );
}
$this->lastInvokedMethod = 'from';
$tables = $this->getIdentifiers( $tables );
$tables = $this->getPrefixedTableNames($tables);
// glue string should be inserted each time but not before first entry
if ( $this->fromString != 'FROM ' )
{
$this->fromString .= ', ';
}
$this->fromString .= join( ', ', $tables );
return $this;
} | [
"public",
"function",
"from",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"fromString",
"==",
"''",
")",
"{",
"$",
"this",
"->",
"fromString",
"=",
"'FROM '",
";",
"}",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"$",
"tables",
"=",
"self",
"::",
"arrayFlatten",
"(",
"$",
"args",
")",
";",
"if",
"(",
"count",
"(",
"$",
"tables",
")",
"<",
"1",
")",
"{",
"throw",
"new",
"ezcQueryVariableParameterException",
"(",
"'from'",
",",
"count",
"(",
"$",
"args",
")",
",",
"1",
")",
";",
"}",
"$",
"this",
"->",
"lastInvokedMethod",
"=",
"'from'",
";",
"$",
"tables",
"=",
"$",
"this",
"->",
"getIdentifiers",
"(",
"$",
"tables",
")",
";",
"$",
"tables",
"=",
"$",
"this",
"->",
"getPrefixedTableNames",
"(",
"$",
"tables",
")",
";",
"// glue string should be inserted each time but not before first entry",
"if",
"(",
"$",
"this",
"->",
"fromString",
"!=",
"'FROM '",
")",
"{",
"$",
"this",
"->",
"fromString",
".=",
"', '",
";",
"}",
"$",
"this",
"->",
"fromString",
".=",
"join",
"(",
"', '",
",",
"$",
"tables",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Select which tables you want to select from.
from() accepts an arbitrary number of parameters. Each parameter
must contain either the name of a table or an array containing
the names of tables..
Each call to from() appends tables to the list of tables that will be
used in the query.
Example:
<code>
// the following code will produce the SQL
// SELECT id FROM table_name
$q->select( 'id' )->from( 'table_name' );
</code>
@throws ezcQueryVariableParameterException if called with no parameters.
@param string|array(string) $... Either a string with a table name or an array of table names.
@return ezcQuery a pointer to $this | [
"Select",
"which",
"tables",
"you",
"want",
"to",
"select",
"from",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_select.php#L312-L337 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_select.php | ezcQuerySelect.doJoin | protected function doJoin( $type )
{
$args = func_get_args();
// Remove the first one, as that's the $type of join.
array_shift( $args );
$sqlType = strtoupper( $type );
$passedArgsCount = func_num_args() - 1;
if ( $passedArgsCount < 2 || $passedArgsCount > 4 )
{
throw new ezcQueryInvalidException( 'SELECT', "Wrong argument count passed to {$type}Join(): {$passedArgsCount}" );
}
// deprecated syntax
if ( $passedArgsCount == 4 )
{
if ( is_string( $args[0] ) && is_string( $args[1] ) &&
is_string( $args[2] ) && is_string( $args[3] )
)
{
$table1 = $this->getIdentifier( $args[0] );
$table2 = $this->getIdentifier( $args[1] );
$column1 = $this->getIdentifier( $args[2] );
$column2 = $this->getIdentifier( $args[3] );
return "{$table1} {$sqlType} JOIN {$table2} ON {$column1} = {$column2}";
}
else
{
throw new ezcQueryInvalidException( 'SELECT', "Inconsistent types of arguments passed to {$type}Join()." );
}
}
// using from()->*Join() syntax assumed, so check if last call was to from()
if ( $this->lastInvokedMethod != 'from' )
{
throw new ezcQueryInvalidException( 'SELECT', "Invoking {$type}Join() not immediately after from()." );
}
$table = '';
if ( !is_string( $args[0] ) )
{
throw new ezcQueryInvalidException( 'SELECT',
"Inconsistent type of first argument passed to {$type}Join(). Should be string with name of table." );
}
$table = $this->getIdentifier( $args[0] );
$condition = '';
if ( $passedArgsCount == 2 && is_string( $args[1] ) )
{
$condition = $args[1];
}
else if ( $passedArgsCount == 3 && is_string( $args[1] ) && is_string( $args[2] ) )
{
$arg1 = $this->getIdentifier( $args[1] );
$arg2 = $this->getIdentifier( $args[2] );
$condition = "{$arg1} = {$arg2}";
}
$this->fromString .= " {$sqlType} JOIN {$table} ON {$condition}";
return $this;
} | php | protected function doJoin( $type )
{
$args = func_get_args();
// Remove the first one, as that's the $type of join.
array_shift( $args );
$sqlType = strtoupper( $type );
$passedArgsCount = func_num_args() - 1;
if ( $passedArgsCount < 2 || $passedArgsCount > 4 )
{
throw new ezcQueryInvalidException( 'SELECT', "Wrong argument count passed to {$type}Join(): {$passedArgsCount}" );
}
// deprecated syntax
if ( $passedArgsCount == 4 )
{
if ( is_string( $args[0] ) && is_string( $args[1] ) &&
is_string( $args[2] ) && is_string( $args[3] )
)
{
$table1 = $this->getIdentifier( $args[0] );
$table2 = $this->getIdentifier( $args[1] );
$column1 = $this->getIdentifier( $args[2] );
$column2 = $this->getIdentifier( $args[3] );
return "{$table1} {$sqlType} JOIN {$table2} ON {$column1} = {$column2}";
}
else
{
throw new ezcQueryInvalidException( 'SELECT', "Inconsistent types of arguments passed to {$type}Join()." );
}
}
// using from()->*Join() syntax assumed, so check if last call was to from()
if ( $this->lastInvokedMethod != 'from' )
{
throw new ezcQueryInvalidException( 'SELECT', "Invoking {$type}Join() not immediately after from()." );
}
$table = '';
if ( !is_string( $args[0] ) )
{
throw new ezcQueryInvalidException( 'SELECT',
"Inconsistent type of first argument passed to {$type}Join(). Should be string with name of table." );
}
$table = $this->getIdentifier( $args[0] );
$condition = '';
if ( $passedArgsCount == 2 && is_string( $args[1] ) )
{
$condition = $args[1];
}
else if ( $passedArgsCount == 3 && is_string( $args[1] ) && is_string( $args[2] ) )
{
$arg1 = $this->getIdentifier( $args[1] );
$arg2 = $this->getIdentifier( $args[2] );
$condition = "{$arg1} = {$arg2}";
}
$this->fromString .= " {$sqlType} JOIN {$table} ON {$condition}";
return $this;
} | [
"protected",
"function",
"doJoin",
"(",
"$",
"type",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"// Remove the first one, as that's the $type of join.",
"array_shift",
"(",
"$",
"args",
")",
";",
"$",
"sqlType",
"=",
"strtoupper",
"(",
"$",
"type",
")",
";",
"$",
"passedArgsCount",
"=",
"func_num_args",
"(",
")",
"-",
"1",
";",
"if",
"(",
"$",
"passedArgsCount",
"<",
"2",
"||",
"$",
"passedArgsCount",
">",
"4",
")",
"{",
"throw",
"new",
"ezcQueryInvalidException",
"(",
"'SELECT'",
",",
"\"Wrong argument count passed to {$type}Join(): {$passedArgsCount}\"",
")",
";",
"}",
"// deprecated syntax",
"if",
"(",
"$",
"passedArgsCount",
"==",
"4",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"args",
"[",
"0",
"]",
")",
"&&",
"is_string",
"(",
"$",
"args",
"[",
"1",
"]",
")",
"&&",
"is_string",
"(",
"$",
"args",
"[",
"2",
"]",
")",
"&&",
"is_string",
"(",
"$",
"args",
"[",
"3",
"]",
")",
")",
"{",
"$",
"table1",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"args",
"[",
"0",
"]",
")",
";",
"$",
"table2",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"args",
"[",
"1",
"]",
")",
";",
"$",
"column1",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"args",
"[",
"2",
"]",
")",
";",
"$",
"column2",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"args",
"[",
"3",
"]",
")",
";",
"return",
"\"{$table1} {$sqlType} JOIN {$table2} ON {$column1} = {$column2}\"",
";",
"}",
"else",
"{",
"throw",
"new",
"ezcQueryInvalidException",
"(",
"'SELECT'",
",",
"\"Inconsistent types of arguments passed to {$type}Join().\"",
")",
";",
"}",
"}",
"// using from()->*Join() syntax assumed, so check if last call was to from()",
"if",
"(",
"$",
"this",
"->",
"lastInvokedMethod",
"!=",
"'from'",
")",
"{",
"throw",
"new",
"ezcQueryInvalidException",
"(",
"'SELECT'",
",",
"\"Invoking {$type}Join() not immediately after from().\"",
")",
";",
"}",
"$",
"table",
"=",
"''",
";",
"if",
"(",
"!",
"is_string",
"(",
"$",
"args",
"[",
"0",
"]",
")",
")",
"{",
"throw",
"new",
"ezcQueryInvalidException",
"(",
"'SELECT'",
",",
"\"Inconsistent type of first argument passed to {$type}Join(). Should be string with name of table.\"",
")",
";",
"}",
"$",
"table",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"args",
"[",
"0",
"]",
")",
";",
"$",
"condition",
"=",
"''",
";",
"if",
"(",
"$",
"passedArgsCount",
"==",
"2",
"&&",
"is_string",
"(",
"$",
"args",
"[",
"1",
"]",
")",
")",
"{",
"$",
"condition",
"=",
"$",
"args",
"[",
"1",
"]",
";",
"}",
"else",
"if",
"(",
"$",
"passedArgsCount",
"==",
"3",
"&&",
"is_string",
"(",
"$",
"args",
"[",
"1",
"]",
")",
"&&",
"is_string",
"(",
"$",
"args",
"[",
"2",
"]",
")",
")",
"{",
"$",
"arg1",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"args",
"[",
"1",
"]",
")",
";",
"$",
"arg2",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"args",
"[",
"2",
"]",
")",
";",
"$",
"condition",
"=",
"\"{$arg1} = {$arg2}\"",
";",
"}",
"$",
"this",
"->",
"fromString",
".=",
"\" {$sqlType} JOIN {$table} ON {$condition}\"",
";",
"return",
"$",
"this",
";",
"}"
] | Returns the SQL for a join or prepares $fromString for a join.
This method could be used in two forms:
<b>doJoin( $joinType, 't2', $joinCondition )</b>
Takes the join type and two string arguments and returns ezcQuery.
The second parameter is the name of the table to join with. The table to
which is joined should have been previously set with the from() method.
The third parameter should be a string containing a join condition that
is returned by an ezcQueryExpression.
<b>doJoin( $joinType, 't2', 't1.id', 't2.id' )</b>
Takes the join type and three string arguments and returns ezcQuery.
This is a simplified form of the three parameter version. doJoin(
'inner', 't2', 't1.id', 't2.id' ) is equal to doJoin( 'inner', 't2',
$this->expr->eq('t1.id', 't2.id' ) );
The second parameter is the name of the table to join with. The table to
which is joined should have been previously set with the from() method.
The third parameter is the name of the column on the table set
previously with the from() method and the fourth parameter the name of
the column to join with on the table that was specified in the first
parameter.
@apichange Remove "5" argument version.
@throws ezcQueryInvalidException if called with inconsistent parameters or if
invoked without preceding call to from().
@param string $type The join type: inner, right or left.
@param string $table2,... The table to join with, followed by either the
two join columns, or a join condition.
@return ezcQuery | [
"Returns",
"the",
"SQL",
"for",
"a",
"join",
"or",
"prepares",
"$fromString",
"for",
"a",
"join",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_select.php#L379-L442 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_select.php | ezcQuerySelect.limit | public function limit( $limit, $offset = '' )
{
if ( $offset === '' )
{
$this->limitString = "LIMIT {$limit}";
}
else
{
$this->limitString = "LIMIT {$limit} OFFSET {$offset}";
}
$this->lastInvokedMethod = 'limit';
return $this;
} | php | public function limit( $limit, $offset = '' )
{
if ( $offset === '' )
{
$this->limitString = "LIMIT {$limit}";
}
else
{
$this->limitString = "LIMIT {$limit} OFFSET {$offset}";
}
$this->lastInvokedMethod = 'limit';
return $this;
} | [
"public",
"function",
"limit",
"(",
"$",
"limit",
",",
"$",
"offset",
"=",
"''",
")",
"{",
"if",
"(",
"$",
"offset",
"===",
"''",
")",
"{",
"$",
"this",
"->",
"limitString",
"=",
"\"LIMIT {$limit}\"",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"limitString",
"=",
"\"LIMIT {$limit} OFFSET {$offset}\"",
";",
"}",
"$",
"this",
"->",
"lastInvokedMethod",
"=",
"'limit'",
";",
"return",
"$",
"this",
";",
"}"
] | Returns SQL that limits the result set.
$limit controls the maximum number of rows that will be returned.
$offset controls which row that will be the first in the result
set from the total amount of matching rows.
Example:
<code>
$q->select( '*' )->from( 'table' )
->limit( 10, 0 );
</code>
LIMIT is not part of SQL92. It is implemented here anyway since all
databases support it one way or the other and because it is
essential.
@param string $limit integer expression
@param string $offset integer expression
@return ezcQuerySelect | [
"Returns",
"SQL",
"that",
"limits",
"the",
"result",
"set",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_select.php#L691-L704 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.