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
|
---|---|---|---|---|---|---|---|---|---|---|
php-lug/lug | src/Component/Grid/Column/ColumnRenderer.php | ColumnRenderer.render | public function render(GridViewInterface $grid, ColumnInterface $column, $data)
{
$types = $this->resolveTypes($column->getType());
if (!isset($this->cache[$hash = spl_object_hash($grid).':'.spl_object_hash($column)])) {
$resolver = new OptionsResolver();
foreach ($types as $type) {
$type->configureOptions($resolver);
}
$this->cache[$hash] = $resolver->resolve(array_merge(
['column' => $column, 'grid' => $grid],
$column->getOptions()
));
}
return reset($types)->render($data, $this->cache[$hash]);
} | php | public function render(GridViewInterface $grid, ColumnInterface $column, $data)
{
$types = $this->resolveTypes($column->getType());
if (!isset($this->cache[$hash = spl_object_hash($grid).':'.spl_object_hash($column)])) {
$resolver = new OptionsResolver();
foreach ($types as $type) {
$type->configureOptions($resolver);
}
$this->cache[$hash] = $resolver->resolve(array_merge(
['column' => $column, 'grid' => $grid],
$column->getOptions()
));
}
return reset($types)->render($data, $this->cache[$hash]);
} | [
"public",
"function",
"render",
"(",
"GridViewInterface",
"$",
"grid",
",",
"ColumnInterface",
"$",
"column",
",",
"$",
"data",
")",
"{",
"$",
"types",
"=",
"$",
"this",
"->",
"resolveTypes",
"(",
"$",
"column",
"->",
"getType",
"(",
")",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"cache",
"[",
"$",
"hash",
"=",
"spl_object_hash",
"(",
"$",
"grid",
")",
".",
"':'",
".",
"spl_object_hash",
"(",
"$",
"column",
")",
"]",
")",
")",
"{",
"$",
"resolver",
"=",
"new",
"OptionsResolver",
"(",
")",
";",
"foreach",
"(",
"$",
"types",
"as",
"$",
"type",
")",
"{",
"$",
"type",
"->",
"configureOptions",
"(",
"$",
"resolver",
")",
";",
"}",
"$",
"this",
"->",
"cache",
"[",
"$",
"hash",
"]",
"=",
"$",
"resolver",
"->",
"resolve",
"(",
"array_merge",
"(",
"[",
"'column'",
"=>",
"$",
"column",
",",
"'grid'",
"=>",
"$",
"grid",
"]",
",",
"$",
"column",
"->",
"getOptions",
"(",
")",
")",
")",
";",
"}",
"return",
"reset",
"(",
"$",
"types",
")",
"->",
"render",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"cache",
"[",
"$",
"hash",
"]",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/Column/ColumnRenderer.php#L46-L64 |
php-lug/lug | src/Component/Grid/Column/ColumnRenderer.php | ColumnRenderer.resolveTypes | private function resolveTypes($type)
{
$columnTypes = [];
do {
$columnTypes[] = $columnType = $this->columnRegistry[$type];
} while (($type = $columnType->getParent()) !== null);
return $columnTypes;
} | php | private function resolveTypes($type)
{
$columnTypes = [];
do {
$columnTypes[] = $columnType = $this->columnRegistry[$type];
} while (($type = $columnType->getParent()) !== null);
return $columnTypes;
} | [
"private",
"function",
"resolveTypes",
"(",
"$",
"type",
")",
"{",
"$",
"columnTypes",
"=",
"[",
"]",
";",
"do",
"{",
"$",
"columnTypes",
"[",
"]",
"=",
"$",
"columnType",
"=",
"$",
"this",
"->",
"columnRegistry",
"[",
"$",
"type",
"]",
";",
"}",
"while",
"(",
"(",
"$",
"type",
"=",
"$",
"columnType",
"->",
"getParent",
"(",
")",
")",
"!==",
"null",
")",
";",
"return",
"$",
"columnTypes",
";",
"}"
] | @param string $type
@return TypeInterface[] | [
"@param",
"string",
"$type"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/Column/ColumnRenderer.php#L71-L80 |
expectation-php/expect | src/matcher/ToHaveKey.php | ToHaveKey.match | public function match($actual)
{
if (is_array($actual) === false) {
throw new InvalidArgumentException("The actual value is not a array");
}
$this->actual = $actual;
return array_key_exists($this->expected, $this->actual);
} | php | public function match($actual)
{
if (is_array($actual) === false) {
throw new InvalidArgumentException("The actual value is not a array");
}
$this->actual = $actual;
return array_key_exists($this->expected, $this->actual);
} | [
"public",
"function",
"match",
"(",
"$",
"actual",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"actual",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"The actual value is not a array\"",
")",
";",
"}",
"$",
"this",
"->",
"actual",
"=",
"$",
"actual",
";",
"return",
"array_key_exists",
"(",
"$",
"this",
"->",
"expected",
",",
"$",
"this",
"->",
"actual",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/expectation-php/expect/blob/1a32c5af37f3dc8dabe4e8eedeeb21aea16ce139/src/matcher/ToHaveKey.php#L53-L62 |
raideer/twitch-api | src/Resources/Streams.php | Streams.getStreams | public function getStreams($params = [])
{
$defaults = [
'game' => null,
'channel' => null,
'limit' => 25,
'offset' => 0,
'client_id' => null,
'stream_type' => 'all',
];
$types = [
'stream_type' => ['all', 'playlist', 'live'],
];
return $this->wrapper->request('GET', 'streams', ['query' => $this->resolveOptions($params, $defaults, [], $types)]);
} | php | public function getStreams($params = [])
{
$defaults = [
'game' => null,
'channel' => null,
'limit' => 25,
'offset' => 0,
'client_id' => null,
'stream_type' => 'all',
];
$types = [
'stream_type' => ['all', 'playlist', 'live'],
];
return $this->wrapper->request('GET', 'streams', ['query' => $this->resolveOptions($params, $defaults, [], $types)]);
} | [
"public",
"function",
"getStreams",
"(",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'game'",
"=>",
"null",
",",
"'channel'",
"=>",
"null",
",",
"'limit'",
"=>",
"25",
",",
"'offset'",
"=>",
"0",
",",
"'client_id'",
"=>",
"null",
",",
"'stream_type'",
"=>",
"'all'",
",",
"]",
";",
"$",
"types",
"=",
"[",
"'stream_type'",
"=>",
"[",
"'all'",
",",
"'playlist'",
",",
"'live'",
"]",
",",
"]",
";",
"return",
"$",
"this",
"->",
"wrapper",
"->",
"request",
"(",
"'GET'",
",",
"'streams'",
",",
"[",
"'query'",
"=>",
"$",
"this",
"->",
"resolveOptions",
"(",
"$",
"params",
",",
"$",
"defaults",
",",
"[",
"]",
",",
"$",
"types",
")",
"]",
")",
";",
"}"
] | Returns a list of stream objects that are queried by a number
of parameters sorted by number of viewers descending.
Learn more:
https://github.com/justintv/Twitch-API/blob/master/v3_resources/streams.md#get-streams
@param array $params Optional params
@return array | [
"Returns",
"a",
"list",
"of",
"stream",
"objects",
"that",
"are",
"queried",
"by",
"a",
"number",
"of",
"parameters",
"sorted",
"by",
"number",
"of",
"viewers",
"descending",
"."
] | train | https://github.com/raideer/twitch-api/blob/27ebf1dcb0315206300d507600b6a82ebe33d57e/src/Resources/Streams.php#L47-L63 |
raideer/twitch-api | src/Resources/Streams.php | Streams.getFeatured | public function getFeatured($params = [])
{
$defaults = [
'limit' => 25,
'offset' => 0,
];
return $this->wrapper->request('GET', 'streams/featured', ['query' => $this->resolveOptions($params, $defaults)]);
} | php | public function getFeatured($params = [])
{
$defaults = [
'limit' => 25,
'offset' => 0,
];
return $this->wrapper->request('GET', 'streams/featured', ['query' => $this->resolveOptions($params, $defaults)]);
} | [
"public",
"function",
"getFeatured",
"(",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'limit'",
"=>",
"25",
",",
"'offset'",
"=>",
"0",
",",
"]",
";",
"return",
"$",
"this",
"->",
"wrapper",
"->",
"request",
"(",
"'GET'",
",",
"'streams/featured'",
",",
"[",
"'query'",
"=>",
"$",
"this",
"->",
"resolveOptions",
"(",
"$",
"params",
",",
"$",
"defaults",
")",
"]",
")",
";",
"}"
] | Returns a list of featured (promoted) stream objects.
Learn more:
https://github.com/justintv/Twitch-API/blob/master/v3_resources/streams.md#get-streamsfeatured
@param array $params Optional params
@return array | [
"Returns",
"a",
"list",
"of",
"featured",
"(",
"promoted",
")",
"stream",
"objects",
"."
] | train | https://github.com/raideer/twitch-api/blob/27ebf1dcb0315206300d507600b6a82ebe33d57e/src/Resources/Streams.php#L75-L83 |
raideer/twitch-api | src/Resources/Streams.php | Streams.getFollowed | public function getFollowed($params = [])
{
$this->wrapper->checkScope('user_read');
$defaults = [
'limit' => 25,
'offset' => 0,
'stream_type' => 'all',
];
$values = [
'stream_type' => ['all', 'playlist', 'live'],
];
return $this->wrapper->request('GET', 'streams/followed', ['query' => $this->resolveOptions($params, $defaults, [], $values)], true);
} | php | public function getFollowed($params = [])
{
$this->wrapper->checkScope('user_read');
$defaults = [
'limit' => 25,
'offset' => 0,
'stream_type' => 'all',
];
$values = [
'stream_type' => ['all', 'playlist', 'live'],
];
return $this->wrapper->request('GET', 'streams/followed', ['query' => $this->resolveOptions($params, $defaults, [], $values)], true);
} | [
"public",
"function",
"getFollowed",
"(",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"wrapper",
"->",
"checkScope",
"(",
"'user_read'",
")",
";",
"$",
"defaults",
"=",
"[",
"'limit'",
"=>",
"25",
",",
"'offset'",
"=>",
"0",
",",
"'stream_type'",
"=>",
"'all'",
",",
"]",
";",
"$",
"values",
"=",
"[",
"'stream_type'",
"=>",
"[",
"'all'",
",",
"'playlist'",
",",
"'live'",
"]",
",",
"]",
";",
"return",
"$",
"this",
"->",
"wrapper",
"->",
"request",
"(",
"'GET'",
",",
"'streams/followed'",
",",
"[",
"'query'",
"=>",
"$",
"this",
"->",
"resolveOptions",
"(",
"$",
"params",
",",
"$",
"defaults",
",",
"[",
"]",
",",
"$",
"values",
")",
"]",
",",
"true",
")",
";",
"}"
] | Returns a list of stream objects that the authenticated user is following.
Learn more:
https://github.com/justintv/Twitch-API/blob/master/v3_resources/users.md#get-streamsfollowed
@param array $params Optional params
@return array | [
"Returns",
"a",
"list",
"of",
"stream",
"objects",
"that",
"the",
"authenticated",
"user",
"is",
"following",
"."
] | train | https://github.com/raideer/twitch-api/blob/27ebf1dcb0315206300d507600b6a82ebe33d57e/src/Resources/Streams.php#L110-L125 |
gedex/php-janrain-api | lib/Janrain/Api/Capture/Versions.php | Versions.entity | public function entity($entityType, $id, $timestamp)
{
$params = array(
'type_name' => $entityType,
'id' => $id,
'timestamp' => $timestamp,
);
return $this->post('versions/entity', $params);
} | php | public function entity($entityType, $id, $timestamp)
{
$params = array(
'type_name' => $entityType,
'id' => $id,
'timestamp' => $timestamp,
);
return $this->post('versions/entity', $params);
} | [
"public",
"function",
"entity",
"(",
"$",
"entityType",
",",
"$",
"id",
",",
"$",
"timestamp",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"'type_name'",
"=>",
"$",
"entityType",
",",
"'id'",
"=>",
"$",
"id",
",",
"'timestamp'",
"=>",
"$",
"timestamp",
",",
")",
";",
"return",
"$",
"this",
"->",
"post",
"(",
"'versions/entity'",
",",
"$",
"params",
")",
";",
"}"
] | Retrieve a past value of single entity by primary key and timestamp.
@param string $entityType
@param string $id
@param string $timestamp | [
"Retrieve",
"a",
"past",
"value",
"of",
"single",
"entity",
"by",
"primary",
"key",
"and",
"timestamp",
"."
] | train | https://github.com/gedex/php-janrain-api/blob/6283f68454e0ad5211ac620f1d337df38cd49597/lib/Janrain/Api/Capture/Versions.php#L17-L26 |
WScore/Validation | src/Utils/HelperSameWith.php | HelperSameWith.prepare | public static function prepare($dio, $rules)
{
if (!Helper::arrGet($rules, 'sameWith')) {
return $rules;
}
$value = self::get_sameWith_value($dio, $rules);
// reset sameWith filter, and set same{As|Empty} filter.
$rules['sameWith'] = false;
if ($value) {
$rules['sameAs'] = $value;
} else {
$rules['sameEmpty'] = true;
}
return $rules;
} | php | public static function prepare($dio, $rules)
{
if (!Helper::arrGet($rules, 'sameWith')) {
return $rules;
}
$value = self::get_sameWith_value($dio, $rules);
// reset sameWith filter, and set same{As|Empty} filter.
$rules['sameWith'] = false;
if ($value) {
$rules['sameAs'] = $value;
} else {
$rules['sameEmpty'] = true;
}
return $rules;
} | [
"public",
"static",
"function",
"prepare",
"(",
"$",
"dio",
",",
"$",
"rules",
")",
"{",
"if",
"(",
"!",
"Helper",
"::",
"arrGet",
"(",
"$",
"rules",
",",
"'sameWith'",
")",
")",
"{",
"return",
"$",
"rules",
";",
"}",
"$",
"value",
"=",
"self",
"::",
"get_sameWith_value",
"(",
"$",
"dio",
",",
"$",
"rules",
")",
";",
"// reset sameWith filter, and set same{As|Empty} filter.",
"$",
"rules",
"[",
"'sameWith'",
"]",
"=",
"false",
";",
"if",
"(",
"$",
"value",
")",
"{",
"$",
"rules",
"[",
"'sameAs'",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"rules",
"[",
"'sameEmpty'",
"]",
"=",
"true",
";",
"}",
"return",
"$",
"rules",
";",
"}"
] | prepares filter for sameWith rule.
get another value to compare in sameWith, and compare it with the value using sameAs rule.
@param Dio $dio
@param array|Rules $rules
@return array|Rules | [
"prepares",
"filter",
"for",
"sameWith",
"rule",
".",
"get",
"another",
"value",
"to",
"compare",
"in",
"sameWith",
"and",
"compare",
"it",
"with",
"the",
"value",
"using",
"sameAs",
"rule",
"."
] | train | https://github.com/WScore/Validation/blob/25c0dca37d624bb0bb22f8e79ba54db2f69e0950/src/Utils/HelperSameWith.php#L18-L33 |
WScore/Validation | src/Utils/HelperSameWith.php | HelperSameWith.get_sameWith_value | private static function get_sameWith_value($dio, $rules)
{
$sub_name = $rules['sameWith'];
if ($rules instanceof Rules) {
$sub_filter = clone $rules;
} else {
$sub_filter = $rules;
}
$sub_filter['sameWith'] = false;
$sub_filter['required'] = false;
$value = $dio->find($sub_name, $sub_filter);
$value = $dio->verify->is($value, $sub_filter);
return $value;
} | php | private static function get_sameWith_value($dio, $rules)
{
$sub_name = $rules['sameWith'];
if ($rules instanceof Rules) {
$sub_filter = clone $rules;
} else {
$sub_filter = $rules;
}
$sub_filter['sameWith'] = false;
$sub_filter['required'] = false;
$value = $dio->find($sub_name, $sub_filter);
$value = $dio->verify->is($value, $sub_filter);
return $value;
} | [
"private",
"static",
"function",
"get_sameWith_value",
"(",
"$",
"dio",
",",
"$",
"rules",
")",
"{",
"$",
"sub_name",
"=",
"$",
"rules",
"[",
"'sameWith'",
"]",
";",
"if",
"(",
"$",
"rules",
"instanceof",
"Rules",
")",
"{",
"$",
"sub_filter",
"=",
"clone",
"$",
"rules",
";",
"}",
"else",
"{",
"$",
"sub_filter",
"=",
"$",
"rules",
";",
"}",
"$",
"sub_filter",
"[",
"'sameWith'",
"]",
"=",
"false",
";",
"$",
"sub_filter",
"[",
"'required'",
"]",
"=",
"false",
";",
"$",
"value",
"=",
"$",
"dio",
"->",
"find",
"(",
"$",
"sub_name",
",",
"$",
"sub_filter",
")",
";",
"$",
"value",
"=",
"$",
"dio",
"->",
"verify",
"->",
"is",
"(",
"$",
"value",
",",
"$",
"sub_filter",
")",
";",
"return",
"$",
"value",
";",
"}"
] | find the same with value.
@param Dio $dio
@param array|Rules $rules
@return mixed | [
"find",
"the",
"same",
"with",
"value",
"."
] | train | https://github.com/WScore/Validation/blob/25c0dca37d624bb0bb22f8e79ba54db2f69e0950/src/Utils/HelperSameWith.php#L42-L56 |
vhraban/Overture | src/ProviderFoundation/TraversableValueContainer.php | TraversableValueContainer.get | public function get($key)
{
$ret = $this->traverseTree($key);
if(!is_scalar($ret))
{
throw new UnexpectedValueException("The {$key} configuration value is not scalar");
}
return $ret;
} | php | public function get($key)
{
$ret = $this->traverseTree($key);
if(!is_scalar($ret))
{
throw new UnexpectedValueException("The {$key} configuration value is not scalar");
}
return $ret;
} | [
"public",
"function",
"get",
"(",
"$",
"key",
")",
"{",
"$",
"ret",
"=",
"$",
"this",
"->",
"traverseTree",
"(",
"$",
"key",
")",
";",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"ret",
")",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"\"The {$key} configuration value is not scalar\"",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] | Get a value for a configuration key
@param string $key The configuration key
@throws MissingKeyException if the path is unreachable
@throws UnexpectedValueException if the path is key is missing
@return string | [
"Get",
"a",
"value",
"for",
"a",
"configuration",
"key"
] | train | https://github.com/vhraban/Overture/blob/4749f2631c9517bc0f6449185d5adb62b85ff4f5/src/ProviderFoundation/TraversableValueContainer.php#L37-L45 |
vhraban/Overture | src/ProviderFoundation/TraversableValueContainer.php | TraversableValueContainer.traverseTree | protected function traverseTree($path)
{
// before the travel current node is the root
$currentNode = $this->tree;
$pathElements = explode(static::KEY_NODE_DELIMITER, $path);
foreach($pathElements as $node)
{
// Ensure the next child exists
if(!isset($currentNode[$node]))
{
throw new MissingKeyException("{$path} configuration value is not found");
}
//update the current path if the child existed
$currentNode = $currentNode[$node];
}
return $currentNode;
} | php | protected function traverseTree($path)
{
// before the travel current node is the root
$currentNode = $this->tree;
$pathElements = explode(static::KEY_NODE_DELIMITER, $path);
foreach($pathElements as $node)
{
// Ensure the next child exists
if(!isset($currentNode[$node]))
{
throw new MissingKeyException("{$path} configuration value is not found");
}
//update the current path if the child existed
$currentNode = $currentNode[$node];
}
return $currentNode;
} | [
"protected",
"function",
"traverseTree",
"(",
"$",
"path",
")",
"{",
"// before the travel current node is the root",
"$",
"currentNode",
"=",
"$",
"this",
"->",
"tree",
";",
"$",
"pathElements",
"=",
"explode",
"(",
"static",
"::",
"KEY_NODE_DELIMITER",
",",
"$",
"path",
")",
";",
"foreach",
"(",
"$",
"pathElements",
"as",
"$",
"node",
")",
"{",
"// Ensure the next child exists",
"if",
"(",
"!",
"isset",
"(",
"$",
"currentNode",
"[",
"$",
"node",
"]",
")",
")",
"{",
"throw",
"new",
"MissingKeyException",
"(",
"\"{$path} configuration value is not found\"",
")",
";",
"}",
"//update the current path if the child existed",
"$",
"currentNode",
"=",
"$",
"currentNode",
"[",
"$",
"node",
"]",
";",
"}",
"return",
"$",
"currentNode",
";",
"}"
] | Traverse a tree until the end of path is reached
$path can be separated with a dot .
In an array [ "section" => ["a => "b"], ["b" => "B"]
value B can be accessed by giving section.b key
@param string $path The path
@throws MissingKeyException if the path is unreachable
@return string | [
"Traverse",
"a",
"tree",
"until",
"the",
"end",
"of",
"path",
"is",
"reached"
] | train | https://github.com/vhraban/Overture/blob/4749f2631c9517bc0f6449185d5adb62b85ff4f5/src/ProviderFoundation/TraversableValueContainer.php#L62-L81 |
madkom/regex | src/Matcher.php | Matcher.match | public function match(string $subject, int $flags = 0, int $offset = 0) : array
{
preg_match($this->pattern->getPattern() . $this->modifier, $subject, $matches, $flags, $offset);
if (($errno = preg_last_error()) !== PREG_NO_ERROR) {
$message = array_flip(get_defined_constants(true)['pcre'])[$errno];
switch ($errno) {
case PREG_INTERNAL_ERROR:
throw new InternalException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_BACKTRACK_LIMIT_ERROR:
throw new BacktrackLimitException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_RECURSION_LIMIT_ERROR:
throw new RecursionLimitException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_BAD_UTF8_ERROR:
throw new BadUtf8Exception("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_BAD_UTF8_OFFSET_ERROR:
throw new BadUtf8OffsetException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_JIT_STACKLIMIT_ERROR:
throw new JitStackLimitException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
}
}
return $matches;
} | php | public function match(string $subject, int $flags = 0, int $offset = 0) : array
{
preg_match($this->pattern->getPattern() . $this->modifier, $subject, $matches, $flags, $offset);
if (($errno = preg_last_error()) !== PREG_NO_ERROR) {
$message = array_flip(get_defined_constants(true)['pcre'])[$errno];
switch ($errno) {
case PREG_INTERNAL_ERROR:
throw new InternalException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_BACKTRACK_LIMIT_ERROR:
throw new BacktrackLimitException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_RECURSION_LIMIT_ERROR:
throw new RecursionLimitException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_BAD_UTF8_ERROR:
throw new BadUtf8Exception("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_BAD_UTF8_OFFSET_ERROR:
throw new BadUtf8OffsetException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
case PREG_JIT_STACKLIMIT_ERROR:
throw new JitStackLimitException("{$message} using pattern: {$this->pattern->getPattern()}", $errno);
}
}
return $matches;
} | [
"public",
"function",
"match",
"(",
"string",
"$",
"subject",
",",
"int",
"$",
"flags",
"=",
"0",
",",
"int",
"$",
"offset",
"=",
"0",
")",
":",
"array",
"{",
"preg_match",
"(",
"$",
"this",
"->",
"pattern",
"->",
"getPattern",
"(",
")",
".",
"$",
"this",
"->",
"modifier",
",",
"$",
"subject",
",",
"$",
"matches",
",",
"$",
"flags",
",",
"$",
"offset",
")",
";",
"if",
"(",
"(",
"$",
"errno",
"=",
"preg_last_error",
"(",
")",
")",
"!==",
"PREG_NO_ERROR",
")",
"{",
"$",
"message",
"=",
"array_flip",
"(",
"get_defined_constants",
"(",
"true",
")",
"[",
"'pcre'",
"]",
")",
"[",
"$",
"errno",
"]",
";",
"switch",
"(",
"$",
"errno",
")",
"{",
"case",
"PREG_INTERNAL_ERROR",
":",
"throw",
"new",
"InternalException",
"(",
"\"{$message} using pattern: {$this->pattern->getPattern()}\"",
",",
"$",
"errno",
")",
";",
"case",
"PREG_BACKTRACK_LIMIT_ERROR",
":",
"throw",
"new",
"BacktrackLimitException",
"(",
"\"{$message} using pattern: {$this->pattern->getPattern()}\"",
",",
"$",
"errno",
")",
";",
"case",
"PREG_RECURSION_LIMIT_ERROR",
":",
"throw",
"new",
"RecursionLimitException",
"(",
"\"{$message} using pattern: {$this->pattern->getPattern()}\"",
",",
"$",
"errno",
")",
";",
"case",
"PREG_BAD_UTF8_ERROR",
":",
"throw",
"new",
"BadUtf8Exception",
"(",
"\"{$message} using pattern: {$this->pattern->getPattern()}\"",
",",
"$",
"errno",
")",
";",
"case",
"PREG_BAD_UTF8_OFFSET_ERROR",
":",
"throw",
"new",
"BadUtf8OffsetException",
"(",
"\"{$message} using pattern: {$this->pattern->getPattern()}\"",
",",
"$",
"errno",
")",
";",
"case",
"PREG_JIT_STACKLIMIT_ERROR",
":",
"throw",
"new",
"JitStackLimitException",
"(",
"\"{$message} using pattern: {$this->pattern->getPattern()}\"",
",",
"$",
"errno",
")",
";",
"}",
"}",
"return",
"$",
"matches",
";",
"}"
] | Retrieve match from subject with Pattern
@param string $subject
@param int $flags
@param int $offset
@return array
@throws BacktrackLimitException
@throws BadUtf8Exception
@throws BadUtf8OffsetException
@throws InternalException
@throws JitStackLimitException
@throws RecursionLimitException | [
"Retrieve",
"match",
"from",
"subject",
"with",
"Pattern"
] | train | https://github.com/madkom/regex/blob/798c1124805b130b1110ee6e8dcc9a88d8aaffa8/src/Matcher.php#L57-L80 |
Litecms/Team | src/Providers/RouteServiceProvider.php | RouteServiceProvider.boot | public function boot()
{
parent::boot();
if (Request::is('*/team/team/*')) {
Route::bind('team', function ($team) {
$teamrepo = $this->app->make('Litecms\Team\Interfaces\TeamRepositoryInterface');
return $teamrepo->findorNew($team);
});
}
} | php | public function boot()
{
parent::boot();
if (Request::is('*/team/team/*')) {
Route::bind('team', function ($team) {
$teamrepo = $this->app->make('Litecms\Team\Interfaces\TeamRepositoryInterface');
return $teamrepo->findorNew($team);
});
}
} | [
"public",
"function",
"boot",
"(",
")",
"{",
"parent",
"::",
"boot",
"(",
")",
";",
"if",
"(",
"Request",
"::",
"is",
"(",
"'*/team/team/*'",
")",
")",
"{",
"Route",
"::",
"bind",
"(",
"'team'",
",",
"function",
"(",
"$",
"team",
")",
"{",
"$",
"teamrepo",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'Litecms\\Team\\Interfaces\\TeamRepositoryInterface'",
")",
";",
"return",
"$",
"teamrepo",
"->",
"findorNew",
"(",
"$",
"team",
")",
";",
"}",
")",
";",
"}",
"}"
] | Define your route model bindings, pattern filters, etc.
@param \Illuminate\Routing\Router $router
@return void | [
"Define",
"your",
"route",
"model",
"bindings",
"pattern",
"filters",
"etc",
"."
] | train | https://github.com/Litecms/Team/blob/a444a6a6604c969df138ac0eb57ed5f4696b0f00/src/Providers/RouteServiceProvider.php#L28-L40 |
contao-community-alliance/url-builder | src/Contao/CsrfUrlBuilder.php | CsrfUrlBuilder.getQueryString | public function getQueryString()
{
$query = parent::getQueryString();
if ($query) {
$query .= '&';
}
$query .= 'rt=' . $this->tokenManager->getToken($this->tokenName)->getValue();
return $query;
} | php | public function getQueryString()
{
$query = parent::getQueryString();
if ($query) {
$query .= '&';
}
$query .= 'rt=' . $this->tokenManager->getToken($this->tokenName)->getValue();
return $query;
} | [
"public",
"function",
"getQueryString",
"(",
")",
"{",
"$",
"query",
"=",
"parent",
"::",
"getQueryString",
"(",
")",
";",
"if",
"(",
"$",
"query",
")",
"{",
"$",
"query",
".=",
"'&'",
";",
"}",
"$",
"query",
".=",
"'rt='",
".",
"$",
"this",
"->",
"tokenManager",
"->",
"getToken",
"(",
"$",
"this",
"->",
"tokenName",
")",
"->",
"getValue",
"(",
")",
";",
"return",
"$",
"query",
";",
"}"
] | Retrieve the serialized query string.
@return string | [
"Retrieve",
"the",
"serialized",
"query",
"string",
"."
] | train | https://github.com/contao-community-alliance/url-builder/blob/2d730649058f3d3af41175358ee92f0659de08a1/src/Contao/CsrfUrlBuilder.php#L67-L77 |
heidelpay/PhpDoc | src/phpDocumentor/Command/Command.php | Command.setHelperSet | public function setHelperSet(HelperSet $helperSet)
{
parent::setHelperSet($helperSet);
$this->getHelper('phpdocumentor_logger')->addOptions($this);
} | php | public function setHelperSet(HelperSet $helperSet)
{
parent::setHelperSet($helperSet);
$this->getHelper('phpdocumentor_logger')->addOptions($this);
} | [
"public",
"function",
"setHelperSet",
"(",
"HelperSet",
"$",
"helperSet",
")",
"{",
"parent",
"::",
"setHelperSet",
"(",
"$",
"helperSet",
")",
";",
"$",
"this",
"->",
"getHelper",
"(",
"'phpdocumentor_logger'",
")",
"->",
"addOptions",
"(",
"$",
"this",
")",
";",
"}"
] | Registers the current command.
@param HelperSet $helperSet | [
"Registers",
"the",
"current",
"command",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Command/Command.php#L32-L37 |
creolab/resources | src/Collection.php | Collection.toArray | public function toArray()
{
$response = array();
foreach ($this->items as $key => $item)
{
$response[] = $item->toArray();
}
return $response;
} | php | public function toArray()
{
$response = array();
foreach ($this->items as $key => $item)
{
$response[] = $item->toArray();
}
return $response;
} | [
"public",
"function",
"toArray",
"(",
")",
"{",
"$",
"response",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"items",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"$",
"response",
"[",
"]",
"=",
"$",
"item",
"->",
"toArray",
"(",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | Return collection as array
@return array | [
"Return",
"collection",
"as",
"array"
] | train | https://github.com/creolab/resources/blob/6e1bdd266aa373f6dafd2408b230f7d2fa05a637/src/Collection.php#L29-L39 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/expression.php | ezcQueryExpression.getIdentifier | protected function getIdentifier( $alias )
{
$aliasParts = explode( '.', $alias );
$identifiers = array();
// If the alias consists of one part, then we just look it up in the
// array. If we find it, we use it, otherwise we return the name as-is
// and assume it's just a column name. The alias target can be a fully
// qualified name (table.column).
if ( count( $aliasParts ) == 1 )
{
if ( $this->aliases !== null &&
array_key_exists( $alias, $this->aliases ) )
{
$alias = $this->aliases[$alias];
}
return $alias;
}
// If the passed name consist of two parts, we need to check all parts
// of the passed-in name for aliases, because an alias can be made for
// both a table name and a column name. For each element we try to find
// whether we have an alias mapping. Unlike the above case, the alias
// target can in this case *not* consist of a fully qualified name as
// this would introduce another part of the name (with two dots).
for ( $i = 0; $i < count( $aliasParts ); $i++ )
{
if ( $this->aliases !== null &&
array_key_exists( $aliasParts[$i], $this->aliases ) )
{
// We only use the found alias if the alias target is not a fully
// qualified name (table.column).
$tmpAlias = $this->aliases[$aliasParts[$i]];
if ( count( explode( '.', $tmpAlias ) ) === 1 )
{
$aliasParts[$i] = $this->aliases[$aliasParts[$i]];
}
}
}
$alias = join( '.', $aliasParts );
return $alias;
} | php | protected function getIdentifier( $alias )
{
$aliasParts = explode( '.', $alias );
$identifiers = array();
// If the alias consists of one part, then we just look it up in the
// array. If we find it, we use it, otherwise we return the name as-is
// and assume it's just a column name. The alias target can be a fully
// qualified name (table.column).
if ( count( $aliasParts ) == 1 )
{
if ( $this->aliases !== null &&
array_key_exists( $alias, $this->aliases ) )
{
$alias = $this->aliases[$alias];
}
return $alias;
}
// If the passed name consist of two parts, we need to check all parts
// of the passed-in name for aliases, because an alias can be made for
// both a table name and a column name. For each element we try to find
// whether we have an alias mapping. Unlike the above case, the alias
// target can in this case *not* consist of a fully qualified name as
// this would introduce another part of the name (with two dots).
for ( $i = 0; $i < count( $aliasParts ); $i++ )
{
if ( $this->aliases !== null &&
array_key_exists( $aliasParts[$i], $this->aliases ) )
{
// We only use the found alias if the alias target is not a fully
// qualified name (table.column).
$tmpAlias = $this->aliases[$aliasParts[$i]];
if ( count( explode( '.', $tmpAlias ) ) === 1 )
{
$aliasParts[$i] = $this->aliases[$aliasParts[$i]];
}
}
}
$alias = join( '.', $aliasParts );
return $alias;
} | [
"protected",
"function",
"getIdentifier",
"(",
"$",
"alias",
")",
"{",
"$",
"aliasParts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"alias",
")",
";",
"$",
"identifiers",
"=",
"array",
"(",
")",
";",
"// If the alias consists of one part, then we just look it up in the",
"// array. If we find it, we use it, otherwise we return the name as-is",
"// and assume it's just a column name. The alias target can be a fully",
"// qualified name (table.column).",
"if",
"(",
"count",
"(",
"$",
"aliasParts",
")",
"==",
"1",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"aliases",
"!==",
"null",
"&&",
"array_key_exists",
"(",
"$",
"alias",
",",
"$",
"this",
"->",
"aliases",
")",
")",
"{",
"$",
"alias",
"=",
"$",
"this",
"->",
"aliases",
"[",
"$",
"alias",
"]",
";",
"}",
"return",
"$",
"alias",
";",
"}",
"// If the passed name consist of two parts, we need to check all parts",
"// of the passed-in name for aliases, because an alias can be made for",
"// both a table name and a column name. For each element we try to find",
"// whether we have an alias mapping. Unlike the above case, the alias",
"// target can in this case *not* consist of a fully qualified name as",
"// this would introduce another part of the name (with two dots).",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"aliasParts",
")",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"aliases",
"!==",
"null",
"&&",
"array_key_exists",
"(",
"$",
"aliasParts",
"[",
"$",
"i",
"]",
",",
"$",
"this",
"->",
"aliases",
")",
")",
"{",
"// We only use the found alias if the alias target is not a fully",
"// qualified name (table.column).",
"$",
"tmpAlias",
"=",
"$",
"this",
"->",
"aliases",
"[",
"$",
"aliasParts",
"[",
"$",
"i",
"]",
"]",
";",
"if",
"(",
"count",
"(",
"explode",
"(",
"'.'",
",",
"$",
"tmpAlias",
")",
")",
"===",
"1",
")",
"{",
"$",
"aliasParts",
"[",
"$",
"i",
"]",
"=",
"$",
"this",
"->",
"aliases",
"[",
"$",
"aliasParts",
"[",
"$",
"i",
"]",
"]",
";",
"}",
"}",
"}",
"$",
"alias",
"=",
"join",
"(",
"'.'",
",",
"$",
"aliasParts",
")",
";",
"return",
"$",
"alias",
";",
"}"
] | Returns the correct identifier for the alias $alias.
If the alias does not exists in the list of aliases
it is returned unchanged.
@param string $alias
@return string | [
"Returns",
"the",
"correct",
"identifier",
"for",
"the",
"alias",
"$alias",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/expression.php#L113-L152 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/expression.php | ezcQueryExpression.lOr | public function lOr()
{
$args = func_get_args();
if ( count( $args ) < 1 )
{
throw new ezcQueryVariableParameterException( 'lOr', count( $args ), 1 );
}
$elements = ezcQuerySelect::arrayFlatten( $args );
if ( count( $elements ) == 1 )
{
return $elements[0];
}
else
{
return '( ' . join( ' OR ', $elements ) . ' )';
}
} | php | public function lOr()
{
$args = func_get_args();
if ( count( $args ) < 1 )
{
throw new ezcQueryVariableParameterException( 'lOr', count( $args ), 1 );
}
$elements = ezcQuerySelect::arrayFlatten( $args );
if ( count( $elements ) == 1 )
{
return $elements[0];
}
else
{
return '( ' . join( ' OR ', $elements ) . ' )';
}
} | [
"public",
"function",
"lOr",
"(",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"args",
")",
"<",
"1",
")",
"{",
"throw",
"new",
"ezcQueryVariableParameterException",
"(",
"'lOr'",
",",
"count",
"(",
"$",
"args",
")",
",",
"1",
")",
";",
"}",
"$",
"elements",
"=",
"ezcQuerySelect",
"::",
"arrayFlatten",
"(",
"$",
"args",
")",
";",
"if",
"(",
"count",
"(",
"$",
"elements",
")",
"==",
"1",
")",
"{",
"return",
"$",
"elements",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"return",
"'( '",
".",
"join",
"(",
"' OR '",
",",
"$",
"elements",
")",
".",
"' )'",
";",
"}",
"}"
] | Returns the SQL to bind logical expressions together using a logical or.
lOr() accepts an arbitrary number of parameters. Each parameter
must contain a logical expression or an array with logical expressions.
Example:
<code>
$q = ezcDbInstance::get()->createSelectQuery();
$e = $q->expr;
$q->select( '*' )->from( 'table' )
->where( $e->lOr( $e->eq( 'id', $q->bindValue( 1 ) ),
$e->eq( 'id', $q->bindValue( 2 ) ) ) );
</code>
@throws ezcDbAbstractionException if called with no parameters.
@return string a logical expression | [
"Returns",
"the",
"SQL",
"to",
"bind",
"logical",
"expressions",
"together",
"using",
"a",
"logical",
"or",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/expression.php#L222-L239 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/expression.php | ezcQueryExpression.basicMath | private function basicMath( $type )
{
$args = func_get_args();
$elements = ezcQuerySelect::arrayFlatten( array_slice( $args, 1 ) );
$elements = $this->getIdentifiers( $elements );
if ( count( $elements ) < 1 )
{
throw new ezcQueryVariableParameterException( $type, count( $args ), 1 );
}
if ( count( $elements ) == 1 )
{
return $elements[0];
}
else
{
return '( ' . join( " $type ", $elements ) . ' )';
}
} | php | private function basicMath( $type )
{
$args = func_get_args();
$elements = ezcQuerySelect::arrayFlatten( array_slice( $args, 1 ) );
$elements = $this->getIdentifiers( $elements );
if ( count( $elements ) < 1 )
{
throw new ezcQueryVariableParameterException( $type, count( $args ), 1 );
}
if ( count( $elements ) == 1 )
{
return $elements[0];
}
else
{
return '( ' . join( " $type ", $elements ) . ' )';
}
} | [
"private",
"function",
"basicMath",
"(",
"$",
"type",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"$",
"elements",
"=",
"ezcQuerySelect",
"::",
"arrayFlatten",
"(",
"array_slice",
"(",
"$",
"args",
",",
"1",
")",
")",
";",
"$",
"elements",
"=",
"$",
"this",
"->",
"getIdentifiers",
"(",
"$",
"elements",
")",
";",
"if",
"(",
"count",
"(",
"$",
"elements",
")",
"<",
"1",
")",
"{",
"throw",
"new",
"ezcQueryVariableParameterException",
"(",
"$",
"type",
",",
"count",
"(",
"$",
"args",
")",
",",
"1",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"elements",
")",
"==",
"1",
")",
"{",
"return",
"$",
"elements",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"return",
"'( '",
".",
"join",
"(",
"\" $type \"",
",",
"$",
"elements",
")",
".",
"' )'",
";",
"}",
"}"
] | Returns the SQL to perform the same mathematical operation over an array
of values or expressions.
basicMath() accepts an arbitrary number of parameters. Each parameter
must contain a value or an expression or an array with values or
expressions.
@throws ezcDbAbstractionException if called with no parameters.
@param string $type the type of operation, can be '+', '-', '*' or '/'.
@param string|array(string) $...
@return string an expression | [
"Returns",
"the",
"SQL",
"to",
"perform",
"the",
"same",
"mathematical",
"operation",
"over",
"an",
"array",
"of",
"values",
"or",
"expressions",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/expression.php#L313-L330 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/expression.php | ezcQueryExpression.eq | public function eq( $value1, $value2 )
{
$value1 = $this->getIdentifier( $value1 );
$value2 = $this->getIdentifier( $value2 );
return "{$value1} = {$value2}";
} | php | public function eq( $value1, $value2 )
{
$value1 = $this->getIdentifier( $value1 );
$value2 = $this->getIdentifier( $value2 );
return "{$value1} = {$value2}";
} | [
"public",
"function",
"eq",
"(",
"$",
"value1",
",",
"$",
"value2",
")",
"{",
"$",
"value1",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"value1",
")",
";",
"$",
"value2",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"value2",
")",
";",
"return",
"\"{$value1} = {$value2}\"",
";",
"}"
] | Returns the SQL to check if two values are equal.
Example:
<code>
$q = ezcDbInstance::get()->createSelectQuery();
$q->select( '*' )->from( 'table' )
->where( $q->expr->eq( 'id', $q->bindValue( 1 ) ) );
</code>
@param string $value1 logical expression to compare
@param string $value2 logical expression to compare with
@return string logical expression | [
"Returns",
"the",
"SQL",
"to",
"check",
"if",
"two",
"values",
"are",
"equal",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/expression.php#L442-L447 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/expression.php | ezcQueryExpression.neq | public function neq( $value1, $value2 )
{
$value1 = $this->getIdentifier( $value1 );
$value2 = $this->getIdentifier( $value2 );
return "{$value1} <> {$value2}";
} | php | public function neq( $value1, $value2 )
{
$value1 = $this->getIdentifier( $value1 );
$value2 = $this->getIdentifier( $value2 );
return "{$value1} <> {$value2}";
} | [
"public",
"function",
"neq",
"(",
"$",
"value1",
",",
"$",
"value2",
")",
"{",
"$",
"value1",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"value1",
")",
";",
"$",
"value2",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"value2",
")",
";",
"return",
"\"{$value1} <> {$value2}\"",
";",
"}"
] | Returns the SQL to check if two values are unequal.
Example:
<code>
$q = ezcDbInstance::get()->createSelectQuery();
$q->select( '*' )->from( 'table' )
->where( $q->expr->neq( 'id', $q->bindValue( 1 ) ) );
</code>
@param string $value1 logical expression to compare
@param string $value2 logical expression to compare with
@return string logical expression | [
"Returns",
"the",
"SQL",
"to",
"check",
"if",
"two",
"values",
"are",
"unequal",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/expression.php#L463-L468 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/expression.php | ezcQueryExpression.gt | public function gt( $value1, $value2 )
{
$value1 = $this->getIdentifier( $value1 );
$value2 = $this->getIdentifier( $value2 );
return "{$value1} > {$value2}";
} | php | public function gt( $value1, $value2 )
{
$value1 = $this->getIdentifier( $value1 );
$value2 = $this->getIdentifier( $value2 );
return "{$value1} > {$value2}";
} | [
"public",
"function",
"gt",
"(",
"$",
"value1",
",",
"$",
"value2",
")",
"{",
"$",
"value1",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"value1",
")",
";",
"$",
"value2",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"value2",
")",
";",
"return",
"\"{$value1} > {$value2}\"",
";",
"}"
] | Returns the SQL to check if one value is greater than another value.
Example:
<code>
$q = ezcDbInstance::get()->createSelectQuery();
$q->select( '*' )->from( 'table' )
->where( $q->expr->gt( 'id', $q->bindValue( 1 ) ) );
</code>
@param string $value1 logical expression to compare
@param string $value2 logical expression to compare with
@return string logical expression | [
"Returns",
"the",
"SQL",
"to",
"check",
"if",
"one",
"value",
"is",
"greater",
"than",
"another",
"value",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/expression.php#L484-L489 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/expression.php | ezcQueryExpression.gte | public function gte( $value1, $value2 )
{
$value1 = $this->getIdentifier( $value1 );
$value2 = $this->getIdentifier( $value2 );
return "{$value1} >= {$value2}";
} | php | public function gte( $value1, $value2 )
{
$value1 = $this->getIdentifier( $value1 );
$value2 = $this->getIdentifier( $value2 );
return "{$value1} >= {$value2}";
} | [
"public",
"function",
"gte",
"(",
"$",
"value1",
",",
"$",
"value2",
")",
"{",
"$",
"value1",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"value1",
")",
";",
"$",
"value2",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"value2",
")",
";",
"return",
"\"{$value1} >= {$value2}\"",
";",
"}"
] | Returns the SQL to check if one value is greater than or equal to
another value.
Example:
<code>
$q = ezcDbInstance::get()->createSelectQuery();
$q->select( '*' )->from( 'table' )
->where( $q->expr->gte( 'id', $q->bindValue( 1 ) ) );
</code>
@param string $value1 logical expression to compare
@param string $value2 logical expression to compare with
@return string logical expression | [
"Returns",
"the",
"SQL",
"to",
"check",
"if",
"one",
"value",
"is",
"greater",
"than",
"or",
"equal",
"to",
"another",
"value",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/expression.php#L506-L511 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/expression.php | ezcQueryExpression.lt | public function lt( $value1, $value2 )
{
$value1 = $this->getIdentifier( $value1 );
$value2 = $this->getIdentifier( $value2 );
return "{$value1} < {$value2}";
} | php | public function lt( $value1, $value2 )
{
$value1 = $this->getIdentifier( $value1 );
$value2 = $this->getIdentifier( $value2 );
return "{$value1} < {$value2}";
} | [
"public",
"function",
"lt",
"(",
"$",
"value1",
",",
"$",
"value2",
")",
"{",
"$",
"value1",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"value1",
")",
";",
"$",
"value2",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"value2",
")",
";",
"return",
"\"{$value1} < {$value2}\"",
";",
"}"
] | Returns the SQL to check if one value is less than another value.
Example:
<code>
$q = ezcDbInstance::get()->createSelectQuery();
$q->select( '*' )->from( 'table' )
->where( $q->expr->lt( 'id', $q->bindValue( 1 ) ) );
</code>
@param string $value1 logical expression to compare
@param string $value2 logical expression to compare with
@return string logical expression | [
"Returns",
"the",
"SQL",
"to",
"check",
"if",
"one",
"value",
"is",
"less",
"than",
"another",
"value",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/expression.php#L527-L532 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/expression.php | ezcQueryExpression.lte | public function lte( $value1, $value2 )
{
$value1 = $this->getIdentifier( $value1 );
$value2 = $this->getIdentifier( $value2 );
return "{$value1} <= {$value2}";
} | php | public function lte( $value1, $value2 )
{
$value1 = $this->getIdentifier( $value1 );
$value2 = $this->getIdentifier( $value2 );
return "{$value1} <= {$value2}";
} | [
"public",
"function",
"lte",
"(",
"$",
"value1",
",",
"$",
"value2",
")",
"{",
"$",
"value1",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"value1",
")",
";",
"$",
"value2",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"value2",
")",
";",
"return",
"\"{$value1} <= {$value2}\"",
";",
"}"
] | Returns the SQL to check if one value is less than or equal to
another value.
Example:
<code>
$q = ezcDbInstance::get()->createSelectQuery();
$q->select( '*' )->from( 'table' )
->where( $q->expr->lte( 'id', $q->bindValue( 1 ) ) );
</code>
@param string $value1 logical expression to compare
@param string $value2 logical expression to compare with
@return string logical expression | [
"Returns",
"the",
"SQL",
"to",
"check",
"if",
"one",
"value",
"is",
"less",
"than",
"or",
"equal",
"to",
"another",
"value",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/expression.php#L549-L554 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/expression.php | ezcQueryExpression.between | public function between( $expression, $value1, $value2 )
{
$expression = $this->getIdentifier( $expression );
$value1 = $this->getIdentifier( $value1 );
$value2 = $this->getIdentifier( $value2 );
return "{$expression} BETWEEN {$value1} AND {$value2}";
} | php | public function between( $expression, $value1, $value2 )
{
$expression = $this->getIdentifier( $expression );
$value1 = $this->getIdentifier( $value1 );
$value2 = $this->getIdentifier( $value2 );
return "{$expression} BETWEEN {$value1} AND {$value2}";
} | [
"public",
"function",
"between",
"(",
"$",
"expression",
",",
"$",
"value1",
",",
"$",
"value2",
")",
"{",
"$",
"expression",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"expression",
")",
";",
"$",
"value1",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"value1",
")",
";",
"$",
"value2",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"value2",
")",
";",
"return",
"\"{$expression} BETWEEN {$value1} AND {$value2}\"",
";",
"}"
] | Returns SQL that checks if an expression evaluates to a value between
two values.
The parameter $expression is checked if it is between $value1 and $value2.
Note: There is a slight difference in the way BETWEEN works on some databases.
http://www.w3schools.com/sql/sql_between.asp. If you want complete database
independence you should avoid using between().
Example:
<code>
$q = ezcDbInstance::get()->createSelectQuery();
$q->select( '*' )->from( 'table' )
->where( $q->expr->between( 'id', $q->bindValue( 1 ), $q->bindValue( 5 ) ) );
</code>
@param string $expression the value to compare to
@param string $value1 the lower value to compare with
@param string $value2 the higher value to compare with
@return string logical expression | [
"Returns",
"SQL",
"that",
"checks",
"if",
"an",
"expression",
"evaluates",
"to",
"a",
"value",
"between",
"two",
"values",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/expression.php#L678-L684 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/expression.php | ezcQueryExpression.mod | public function mod( $expression1, $expression2 )
{
$expression1 = $this->getIdentifier( $expression1 );
$expression2 = $this->getIdentifier( $expression2 );
return "MOD( {$expression1}, {$expression2} )";
} | php | public function mod( $expression1, $expression2 )
{
$expression1 = $this->getIdentifier( $expression1 );
$expression2 = $this->getIdentifier( $expression2 );
return "MOD( {$expression1}, {$expression2} )";
} | [
"public",
"function",
"mod",
"(",
"$",
"expression1",
",",
"$",
"expression2",
")",
"{",
"$",
"expression1",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"expression1",
")",
";",
"$",
"expression2",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"expression2",
")",
";",
"return",
"\"MOD( {$expression1}, {$expression2} )\"",
";",
"}"
] | Returns the remainder of the division operation
$expression1 / $expression2.
@param string $expression1
@param string $expression2
@return string | [
"Returns",
"the",
"remainder",
"of",
"the",
"division",
"operation",
"$expression1",
"/",
"$expression2",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/expression.php#L815-L820 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/expression.php | ezcQueryExpression.bitAnd | public function bitAnd( $value1, $value2 )
{
$value1 = $this->getIdentifier( $value1 );
$value2 = $this->getIdentifier( $value2 );
return "( {$value1} & {$value2} )";
} | php | public function bitAnd( $value1, $value2 )
{
$value1 = $this->getIdentifier( $value1 );
$value2 = $this->getIdentifier( $value2 );
return "( {$value1} & {$value2} )";
} | [
"public",
"function",
"bitAnd",
"(",
"$",
"value1",
",",
"$",
"value2",
")",
"{",
"$",
"value1",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"value1",
")",
";",
"$",
"value2",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"value2",
")",
";",
"return",
"\"( {$value1} & {$value2} )\"",
";",
"}"
] | Returns the SQL that performs the bitwise AND on two values.
@param string $value1
@param string $value2
@return string | [
"Returns",
"the",
"SQL",
"that",
"performs",
"the",
"bitwise",
"AND",
"on",
"two",
"values",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/expression.php#L948-L953 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/expression.php | ezcQueryExpression.bitOr | public function bitOr( $value1, $value2 )
{
$value1 = $this->getIdentifier( $value1 );
$value2 = $this->getIdentifier( $value2 );
return "( {$value1} | {$value2} )";
} | php | public function bitOr( $value1, $value2 )
{
$value1 = $this->getIdentifier( $value1 );
$value2 = $this->getIdentifier( $value2 );
return "( {$value1} | {$value2} )";
} | [
"public",
"function",
"bitOr",
"(",
"$",
"value1",
",",
"$",
"value2",
")",
"{",
"$",
"value1",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"value1",
")",
";",
"$",
"value2",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"value2",
")",
";",
"return",
"\"( {$value1} | {$value2} )\"",
";",
"}"
] | Returns the SQL that performs the bitwise OR on two values.
@param string $value1
@param string $value2
@return string | [
"Returns",
"the",
"SQL",
"that",
"performs",
"the",
"bitwise",
"OR",
"on",
"two",
"values",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/expression.php#L962-L967 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/expression.php | ezcQueryExpression.dateExtract | public function dateExtract( $column, $type )
{
$type = $this->intervalMap[$type];
$column = $this->getIdentifier( $column );
return " EXTRACT( {$type} FROM {$column} ) ";
} | php | public function dateExtract( $column, $type )
{
$type = $this->intervalMap[$type];
$column = $this->getIdentifier( $column );
return " EXTRACT( {$type} FROM {$column} ) ";
} | [
"public",
"function",
"dateExtract",
"(",
"$",
"column",
",",
"$",
"type",
")",
"{",
"$",
"type",
"=",
"$",
"this",
"->",
"intervalMap",
"[",
"$",
"type",
"]",
";",
"$",
"column",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"column",
")",
";",
"return",
"\" EXTRACT( {$type} FROM {$column} ) \"",
";",
"}"
] | Returns the SQL that extracts parts from a timestamp value.
@param string $column The column to operate on
@param string $type one of SECOND, MINUTE, HOUR, DAY, MONTH, or YEAR
@return string | [
"Returns",
"the",
"SQL",
"that",
"extracts",
"parts",
"from",
"a",
"timestamp",
"value",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/expression.php#L1034-L1040 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/expression.php | ezcQueryExpression.searchedCase | public function searchedCase()
{
$args = func_get_args();
if ( count( $args ) === 0 )
{
throw new ezcQueryVariableParameterException( 'searchedCase', count( $args ), 1 );
}
$expr = ' CASE';
foreach ( $args as $arg )
{
if ( is_array( $arg ) && count( $arg ) == 2 )
{
$column1 = $this->getIdentifier( $arg[0] );
$column2 = $this->getIdentifier( $arg[1] );
$expr .= " WHEN {$column1} THEN {$column2}";
}
else if ( is_scalar( $arg ) )
{
$column = $this->getIdentifier( $arg );
$expr .= " ELSE {$column}";
}
}
$expr .= ' END ';
return $expr;
} | php | public function searchedCase()
{
$args = func_get_args();
if ( count( $args ) === 0 )
{
throw new ezcQueryVariableParameterException( 'searchedCase', count( $args ), 1 );
}
$expr = ' CASE';
foreach ( $args as $arg )
{
if ( is_array( $arg ) && count( $arg ) == 2 )
{
$column1 = $this->getIdentifier( $arg[0] );
$column2 = $this->getIdentifier( $arg[1] );
$expr .= " WHEN {$column1} THEN {$column2}";
}
else if ( is_scalar( $arg ) )
{
$column = $this->getIdentifier( $arg );
$expr .= " ELSE {$column}";
}
}
$expr .= ' END ';
return $expr;
} | [
"public",
"function",
"searchedCase",
"(",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"args",
")",
"===",
"0",
")",
"{",
"throw",
"new",
"ezcQueryVariableParameterException",
"(",
"'searchedCase'",
",",
"count",
"(",
"$",
"args",
")",
",",
"1",
")",
";",
"}",
"$",
"expr",
"=",
"' CASE'",
";",
"foreach",
"(",
"$",
"args",
"as",
"$",
"arg",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"arg",
")",
"&&",
"count",
"(",
"$",
"arg",
")",
"==",
"2",
")",
"{",
"$",
"column1",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"arg",
"[",
"0",
"]",
")",
";",
"$",
"column2",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"arg",
"[",
"1",
"]",
")",
";",
"$",
"expr",
".=",
"\" WHEN {$column1} THEN {$column2}\"",
";",
"}",
"else",
"if",
"(",
"is_scalar",
"(",
"$",
"arg",
")",
")",
"{",
"$",
"column",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"arg",
")",
";",
"$",
"expr",
".=",
"\" ELSE {$column}\"",
";",
"}",
"}",
"$",
"expr",
".=",
"' END '",
";",
"return",
"$",
"expr",
";",
"}"
] | Returns a searched CASE statement.
Accepts an arbitrary number of parameters.
The first parameter (array) must always be specified, the last
parameter (string) specifies the ELSE result.
Example:
<code>
$q = ezcDbInstance::get()->createSelectQuery();
$q->select(
$q->expr->searchedCase(
array( $q->expr->gte( 'column1', 20 ), 'column1' )
, array( $q->expr->gte( 'column2', 50 ), 'column2' )
, 'column3'
)
)
->from( 'table' );
</code>
@throws ezcQueryVariableParameterException
@return string | [
"Returns",
"a",
"searched",
"CASE",
"statement",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/expression.php#L1065-L1091 |
kiwi-suite/frontend42 | src/Event/PageEventListener.php | PageEventListener.attach | public function attach(EventManagerInterface $events, $priority = 1)
{
$events->attach(PageEvent::EVENT_ADD_PRE, [$this, 'setStandardParams']);
$events->attach(PageEvent::EVENT_EDIT_PRE, [$this, 'setStandardParams']);
$events->attach(PageEvent::EVENT_APPROVED, [$this, 'setStandardParams']);
$events->attach(PageEvent::EVENT_ADD_PRE, [$this, 'setSlug']);
$events->attach(PageEvent::EVENT_EDIT_PRE, [$this, 'setSlug']);
$events->attach(PageEvent::EVENT_APPROVED, [$this, 'setSlug']);
$events->attach(PageEvent::EVENT_APPROVED, [$this, 'saveNavigation']);
$events->attach(PageEvent::EVENT_APPROVED, [$this, 'updateCache']);
} | php | public function attach(EventManagerInterface $events, $priority = 1)
{
$events->attach(PageEvent::EVENT_ADD_PRE, [$this, 'setStandardParams']);
$events->attach(PageEvent::EVENT_EDIT_PRE, [$this, 'setStandardParams']);
$events->attach(PageEvent::EVENT_APPROVED, [$this, 'setStandardParams']);
$events->attach(PageEvent::EVENT_ADD_PRE, [$this, 'setSlug']);
$events->attach(PageEvent::EVENT_EDIT_PRE, [$this, 'setSlug']);
$events->attach(PageEvent::EVENT_APPROVED, [$this, 'setSlug']);
$events->attach(PageEvent::EVENT_APPROVED, [$this, 'saveNavigation']);
$events->attach(PageEvent::EVENT_APPROVED, [$this, 'updateCache']);
} | [
"public",
"function",
"attach",
"(",
"EventManagerInterface",
"$",
"events",
",",
"$",
"priority",
"=",
"1",
")",
"{",
"$",
"events",
"->",
"attach",
"(",
"PageEvent",
"::",
"EVENT_ADD_PRE",
",",
"[",
"$",
"this",
",",
"'setStandardParams'",
"]",
")",
";",
"$",
"events",
"->",
"attach",
"(",
"PageEvent",
"::",
"EVENT_EDIT_PRE",
",",
"[",
"$",
"this",
",",
"'setStandardParams'",
"]",
")",
";",
"$",
"events",
"->",
"attach",
"(",
"PageEvent",
"::",
"EVENT_APPROVED",
",",
"[",
"$",
"this",
",",
"'setStandardParams'",
"]",
")",
";",
"$",
"events",
"->",
"attach",
"(",
"PageEvent",
"::",
"EVENT_ADD_PRE",
",",
"[",
"$",
"this",
",",
"'setSlug'",
"]",
")",
";",
"$",
"events",
"->",
"attach",
"(",
"PageEvent",
"::",
"EVENT_EDIT_PRE",
",",
"[",
"$",
"this",
",",
"'setSlug'",
"]",
")",
";",
"$",
"events",
"->",
"attach",
"(",
"PageEvent",
"::",
"EVENT_APPROVED",
",",
"[",
"$",
"this",
",",
"'setSlug'",
"]",
")",
";",
"$",
"events",
"->",
"attach",
"(",
"PageEvent",
"::",
"EVENT_APPROVED",
",",
"[",
"$",
"this",
",",
"'saveNavigation'",
"]",
")",
";",
"$",
"events",
"->",
"attach",
"(",
"PageEvent",
"::",
"EVENT_APPROVED",
",",
"[",
"$",
"this",
",",
"'updateCache'",
"]",
")",
";",
"}"
] | Attach one or more listeners
Implementors may add an optional $priority argument; the EventManager
implementation will pass this to the aggregate.
@param EventManagerInterface $events
@param int $priority
@return void | [
"Attach",
"one",
"or",
"more",
"listeners"
] | train | https://github.com/kiwi-suite/frontend42/blob/67e5208387957823ac84f7833eba83d4a8dab8cd/src/Event/PageEventListener.php#L41-L54 |
nonzod/yii2-foundation | helpers/Html.php | Html.icon | public static function icon($icon, $options = [], $prefix = 'fi-', $tag = 'i') {
$class = isset($options['class']) ? ' ' . $options['class'] : '';
$options['class'] = $prefix . $icon . $class;
return static::tag($tag, '', $options);
} | php | public static function icon($icon, $options = [], $prefix = 'fi-', $tag = 'i') {
$class = isset($options['class']) ? ' ' . $options['class'] : '';
$options['class'] = $prefix . $icon . $class;
return static::tag($tag, '', $options);
} | [
"public",
"static",
"function",
"icon",
"(",
"$",
"icon",
",",
"$",
"options",
"=",
"[",
"]",
",",
"$",
"prefix",
"=",
"'fi-'",
",",
"$",
"tag",
"=",
"'i'",
")",
"{",
"$",
"class",
"=",
"isset",
"(",
"$",
"options",
"[",
"'class'",
"]",
")",
"?",
"' '",
".",
"$",
"options",
"[",
"'class'",
"]",
":",
"''",
";",
"$",
"options",
"[",
"'class'",
"]",
"=",
"$",
"prefix",
".",
"$",
"icon",
".",
"$",
"class",
";",
"return",
"static",
"::",
"tag",
"(",
"$",
"tag",
",",
"''",
",",
"$",
"options",
")",
";",
"}"
] | Generates an icon.
@param string $icon the foundation icon name without prefix (e.g. 'plus', 'refresh', 'trash')
@param array $options html options for the icon container
@param string $prefix the css class prefix - defaults to 'fi-'
@param string $tag the icon container tag - defaults to 'i'
@see http://zurb.com/playground/foundation-icon-fonts-3 | [
"Generates",
"an",
"icon",
"."
] | train | https://github.com/nonzod/yii2-foundation/blob/5df93b8a39a73a7fade2f3189693fdb6625205d2/helpers/Html.php#L40-L44 |
nonzod/yii2-foundation | helpers/Html.php | Html.fLabel | public static function fLabel($content, $type = '', $border = '', $options = [], $tag = 'span') {
Html::addCssClass($options, 'label');
Html::addCssClass($options, $type);
Html::addCssClass($options, $border);
return static::tag($tag, $content, $options);
} | php | public static function fLabel($content, $type = '', $border = '', $options = [], $tag = 'span') {
Html::addCssClass($options, 'label');
Html::addCssClass($options, $type);
Html::addCssClass($options, $border);
return static::tag($tag, $content, $options);
} | [
"public",
"static",
"function",
"fLabel",
"(",
"$",
"content",
",",
"$",
"type",
"=",
"''",
",",
"$",
"border",
"=",
"''",
",",
"$",
"options",
"=",
"[",
"]",
",",
"$",
"tag",
"=",
"'span'",
")",
"{",
"Html",
"::",
"addCssClass",
"(",
"$",
"options",
",",
"'label'",
")",
";",
"Html",
"::",
"addCssClass",
"(",
"$",
"options",
",",
"$",
"type",
")",
";",
"Html",
"::",
"addCssClass",
"(",
"$",
"options",
",",
"$",
"border",
")",
";",
"return",
"static",
"::",
"tag",
"(",
"$",
"tag",
",",
"$",
"content",
",",
"$",
"options",
")",
";",
"}"
] | Generates a label.
@param string $content the label content
@param string $type the label type - default is empty
- is one of [[self::TYPE_SECONDARY]], [[self::TYPE_SUCCESS]], [[self::TYPE_WARNING]], [[self::TYPE_ALERT]]
@param string $border the border type - defaults is empty
- is one of [[self::BORDER_RADIUS]], [[self::BORDER_ROUND]]
@param array $options html options for the label container
@param string $tag the label container tag - defaults to 'span'
Example(s):
~~~
echo Html::fLabel('Regular');
echo Html::fLabel('Primary', Html::TYPE_PRIMARY);
echo Html::fLabel('Success round', Html::TYPE_SUCCESS, Html::BORDER_ROUND);
~~~
@see http://getbootstrap.com/components/#labels | [
"Generates",
"a",
"label",
"."
] | train | https://github.com/nonzod/yii2-foundation/blob/5df93b8a39a73a7fade2f3189693fdb6625205d2/helpers/Html.php#L66-L72 |
SergioMadness/query-builder | src/adapters/SQL/ConditionBuilder.php | ConditionBuilder.prepareArray | protected function prepareArray(array $conditions)
{
switch (count($conditions)) {
case 1:
$result = $conditions[0];
break;
case 2:
if (is_array($conditions[1])) {
$result = $conditions[0].' IN ('.implode(',', $conditions[1]).')';
} elseif (is_null($conditions[1])) {
$result = $conditions[0].' IS NULL';
} elseif ($conditions[1] instanceof \pwf\components\querybuilder\interfaces\SelectBuilder) {
$result = $conditions[0].' IN ('.$conditions[1]->generate().')';
$this->setParams(array_merge($this->getParams(),
$conditions[1]->getParams()));
} else {
$result = $conditions[0].'=?';//.$conditions[0];
$this->addParam($conditions[0], $conditions[1]);
}
break;
case 3:
$left = is_array($conditions[1]) ? $this->prepareConditions($conditions[1])
: $conditions[1];
$right = is_array($conditions[2]) ? $this->prepareConditions($conditions[2])
: $conditions[2];
$result = '(('.$left.') '.$conditions[0].' ('.$right.'))';
break;
default:
throw new \Exception('Wrong condition configuration');
}
return $result;
} | php | protected function prepareArray(array $conditions)
{
switch (count($conditions)) {
case 1:
$result = $conditions[0];
break;
case 2:
if (is_array($conditions[1])) {
$result = $conditions[0].' IN ('.implode(',', $conditions[1]).')';
} elseif (is_null($conditions[1])) {
$result = $conditions[0].' IS NULL';
} elseif ($conditions[1] instanceof \pwf\components\querybuilder\interfaces\SelectBuilder) {
$result = $conditions[0].' IN ('.$conditions[1]->generate().')';
$this->setParams(array_merge($this->getParams(),
$conditions[1]->getParams()));
} else {
$result = $conditions[0].'=?';//.$conditions[0];
$this->addParam($conditions[0], $conditions[1]);
}
break;
case 3:
$left = is_array($conditions[1]) ? $this->prepareConditions($conditions[1])
: $conditions[1];
$right = is_array($conditions[2]) ? $this->prepareConditions($conditions[2])
: $conditions[2];
$result = '(('.$left.') '.$conditions[0].' ('.$right.'))';
break;
default:
throw new \Exception('Wrong condition configuration');
}
return $result;
} | [
"protected",
"function",
"prepareArray",
"(",
"array",
"$",
"conditions",
")",
"{",
"switch",
"(",
"count",
"(",
"$",
"conditions",
")",
")",
"{",
"case",
"1",
":",
"$",
"result",
"=",
"$",
"conditions",
"[",
"0",
"]",
";",
"break",
";",
"case",
"2",
":",
"if",
"(",
"is_array",
"(",
"$",
"conditions",
"[",
"1",
"]",
")",
")",
"{",
"$",
"result",
"=",
"$",
"conditions",
"[",
"0",
"]",
".",
"' IN ('",
".",
"implode",
"(",
"','",
",",
"$",
"conditions",
"[",
"1",
"]",
")",
".",
"')'",
";",
"}",
"elseif",
"(",
"is_null",
"(",
"$",
"conditions",
"[",
"1",
"]",
")",
")",
"{",
"$",
"result",
"=",
"$",
"conditions",
"[",
"0",
"]",
".",
"' IS NULL'",
";",
"}",
"elseif",
"(",
"$",
"conditions",
"[",
"1",
"]",
"instanceof",
"\\",
"pwf",
"\\",
"components",
"\\",
"querybuilder",
"\\",
"interfaces",
"\\",
"SelectBuilder",
")",
"{",
"$",
"result",
"=",
"$",
"conditions",
"[",
"0",
"]",
".",
"' IN ('",
".",
"$",
"conditions",
"[",
"1",
"]",
"->",
"generate",
"(",
")",
".",
"')'",
";",
"$",
"this",
"->",
"setParams",
"(",
"array_merge",
"(",
"$",
"this",
"->",
"getParams",
"(",
")",
",",
"$",
"conditions",
"[",
"1",
"]",
"->",
"getParams",
"(",
")",
")",
")",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"$",
"conditions",
"[",
"0",
"]",
".",
"'=?'",
";",
"//.$conditions[0];",
"$",
"this",
"->",
"addParam",
"(",
"$",
"conditions",
"[",
"0",
"]",
",",
"$",
"conditions",
"[",
"1",
"]",
")",
";",
"}",
"break",
";",
"case",
"3",
":",
"$",
"left",
"=",
"is_array",
"(",
"$",
"conditions",
"[",
"1",
"]",
")",
"?",
"$",
"this",
"->",
"prepareConditions",
"(",
"$",
"conditions",
"[",
"1",
"]",
")",
":",
"$",
"conditions",
"[",
"1",
"]",
";",
"$",
"right",
"=",
"is_array",
"(",
"$",
"conditions",
"[",
"2",
"]",
")",
"?",
"$",
"this",
"->",
"prepareConditions",
"(",
"$",
"conditions",
"[",
"2",
"]",
")",
":",
"$",
"conditions",
"[",
"2",
"]",
";",
"$",
"result",
"=",
"'(('",
".",
"$",
"left",
".",
"') '",
".",
"$",
"conditions",
"[",
"0",
"]",
".",
"' ('",
".",
"$",
"right",
".",
"'))'",
";",
"break",
";",
"default",
":",
"throw",
"new",
"\\",
"Exception",
"(",
"'Wrong condition configuration'",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Array to string
@param array $conditions
@return string
@throws \Exception | [
"Array",
"to",
"string"
] | train | https://github.com/SergioMadness/query-builder/blob/95b7a46bba4c4d369101c6f0d37f133fecb3956d/src/adapters/SQL/ConditionBuilder.php#L17-L49 |
tequila/mongodb-odm | src/Metadata/Factory/StaticMethodAwareFactory.php | StaticMethodAwareFactory.getClassMetadata | public function getClassMetadata($documentClass): ClassMetadata
{
if (!array_key_exists($documentClass, $this->metadataCache)) {
if (!class_exists($documentClass)) {
throw new LogicException(sprintf('Document class %s does not exist.', $documentClass));
}
$reflection = new \ReflectionClass($documentClass);
if ($reflection->isAbstract()) {
throw new LogicException(
sprintf('Document class %s must be not abstract.', $documentClass)
);
}
if (!$reflection->hasMethod('loadClassMetadata')) {
throw new LogicException(
sprintf(
'%s requires document class %s to have method "loadClassMetadata()".',
__CLASS__,
$documentClass
)
);
}
$reflectionMethod = $reflection->getMethod('loadClassMetadata');
if (!$reflectionMethod->isPublic() || !$reflectionMethod->isStatic()) {
throw new LogicException(
sprintf(
'%s requires document class %s method "loadClassMetadata" to be public and static.',
__CLASS__,
$documentClass
)
);
}
$metadata = new ClassMetadata($documentClass);
call_user_func([$documentClass, 'loadClassMetadata'], $metadata);
if ($metadata->isIdentifiable() && null === $metadata->getPrimaryKeyField()) {
$metadata->addObjectIdField('id', '_id', true);
}
$this->metadataCache[$documentClass] = $metadata;
}
return $this->metadataCache[$documentClass];
} | php | public function getClassMetadata($documentClass): ClassMetadata
{
if (!array_key_exists($documentClass, $this->metadataCache)) {
if (!class_exists($documentClass)) {
throw new LogicException(sprintf('Document class %s does not exist.', $documentClass));
}
$reflection = new \ReflectionClass($documentClass);
if ($reflection->isAbstract()) {
throw new LogicException(
sprintf('Document class %s must be not abstract.', $documentClass)
);
}
if (!$reflection->hasMethod('loadClassMetadata')) {
throw new LogicException(
sprintf(
'%s requires document class %s to have method "loadClassMetadata()".',
__CLASS__,
$documentClass
)
);
}
$reflectionMethod = $reflection->getMethod('loadClassMetadata');
if (!$reflectionMethod->isPublic() || !$reflectionMethod->isStatic()) {
throw new LogicException(
sprintf(
'%s requires document class %s method "loadClassMetadata" to be public and static.',
__CLASS__,
$documentClass
)
);
}
$metadata = new ClassMetadata($documentClass);
call_user_func([$documentClass, 'loadClassMetadata'], $metadata);
if ($metadata->isIdentifiable() && null === $metadata->getPrimaryKeyField()) {
$metadata->addObjectIdField('id', '_id', true);
}
$this->metadataCache[$documentClass] = $metadata;
}
return $this->metadataCache[$documentClass];
} | [
"public",
"function",
"getClassMetadata",
"(",
"$",
"documentClass",
")",
":",
"ClassMetadata",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"documentClass",
",",
"$",
"this",
"->",
"metadataCache",
")",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"documentClass",
")",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"sprintf",
"(",
"'Document class %s does not exist.'",
",",
"$",
"documentClass",
")",
")",
";",
"}",
"$",
"reflection",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"documentClass",
")",
";",
"if",
"(",
"$",
"reflection",
"->",
"isAbstract",
"(",
")",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"sprintf",
"(",
"'Document class %s must be not abstract.'",
",",
"$",
"documentClass",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"reflection",
"->",
"hasMethod",
"(",
"'loadClassMetadata'",
")",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"sprintf",
"(",
"'%s requires document class %s to have method \"loadClassMetadata()\".'",
",",
"__CLASS__",
",",
"$",
"documentClass",
")",
")",
";",
"}",
"$",
"reflectionMethod",
"=",
"$",
"reflection",
"->",
"getMethod",
"(",
"'loadClassMetadata'",
")",
";",
"if",
"(",
"!",
"$",
"reflectionMethod",
"->",
"isPublic",
"(",
")",
"||",
"!",
"$",
"reflectionMethod",
"->",
"isStatic",
"(",
")",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"sprintf",
"(",
"'%s requires document class %s method \"loadClassMetadata\" to be public and static.'",
",",
"__CLASS__",
",",
"$",
"documentClass",
")",
")",
";",
"}",
"$",
"metadata",
"=",
"new",
"ClassMetadata",
"(",
"$",
"documentClass",
")",
";",
"call_user_func",
"(",
"[",
"$",
"documentClass",
",",
"'loadClassMetadata'",
"]",
",",
"$",
"metadata",
")",
";",
"if",
"(",
"$",
"metadata",
"->",
"isIdentifiable",
"(",
")",
"&&",
"null",
"===",
"$",
"metadata",
"->",
"getPrimaryKeyField",
"(",
")",
")",
"{",
"$",
"metadata",
"->",
"addObjectIdField",
"(",
"'id'",
",",
"'_id'",
",",
"true",
")",
";",
"}",
"$",
"this",
"->",
"metadataCache",
"[",
"$",
"documentClass",
"]",
"=",
"$",
"metadata",
";",
"}",
"return",
"$",
"this",
"->",
"metadataCache",
"[",
"$",
"documentClass",
"]",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/tequila/mongodb-odm/blob/501d58529bbcb23ad7839680462f62d5c3466d23/src/Metadata/Factory/StaticMethodAwareFactory.php#L18-L63 |
php-lug/lug | src/Component/Grid/Sort/Type/ResourceType.php | ResourceType.sort | public function sort($data, array $options)
{
$builder = $options['builder'];
if (!in_array($options['field'], $builder->getAliases(), true)) {
$builder->leftJoin($builder->getProperty($options['field']), $options['field']);
}
$resource = $options['resource'];
$repository = $this->repositoryRegistry[$resource->getName()];
$builder->orderBy($repository->getProperty($options['field'], $resource->getLabelPropertyPath()), $data);
} | php | public function sort($data, array $options)
{
$builder = $options['builder'];
if (!in_array($options['field'], $builder->getAliases(), true)) {
$builder->leftJoin($builder->getProperty($options['field']), $options['field']);
}
$resource = $options['resource'];
$repository = $this->repositoryRegistry[$resource->getName()];
$builder->orderBy($repository->getProperty($options['field'], $resource->getLabelPropertyPath()), $data);
} | [
"public",
"function",
"sort",
"(",
"$",
"data",
",",
"array",
"$",
"options",
")",
"{",
"$",
"builder",
"=",
"$",
"options",
"[",
"'builder'",
"]",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"options",
"[",
"'field'",
"]",
",",
"$",
"builder",
"->",
"getAliases",
"(",
")",
",",
"true",
")",
")",
"{",
"$",
"builder",
"->",
"leftJoin",
"(",
"$",
"builder",
"->",
"getProperty",
"(",
"$",
"options",
"[",
"'field'",
"]",
")",
",",
"$",
"options",
"[",
"'field'",
"]",
")",
";",
"}",
"$",
"resource",
"=",
"$",
"options",
"[",
"'resource'",
"]",
";",
"$",
"repository",
"=",
"$",
"this",
"->",
"repositoryRegistry",
"[",
"$",
"resource",
"->",
"getName",
"(",
")",
"]",
";",
"$",
"builder",
"->",
"orderBy",
"(",
"$",
"repository",
"->",
"getProperty",
"(",
"$",
"options",
"[",
"'field'",
"]",
",",
"$",
"resource",
"->",
"getLabelPropertyPath",
"(",
")",
")",
",",
"$",
"data",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/Sort/Type/ResourceType.php#L49-L61 |
SporkCode/Spork | src/Mvc/Listener/EmailVerificationStrategy.php | EmailVerificationStrategy.attach | public function attach(EventManagerInterface $events)
{
$sharedEvents = $events->getSharedManager();
$this->listeners[] = $sharedEvents->attach(
'Zend\Stdlib\DispatchableInterface',
MvcEvent::EVENT_DISPATCH,
array($this, 'checkEmailVerification'),
10000);
} | php | public function attach(EventManagerInterface $events)
{
$sharedEvents = $events->getSharedManager();
$this->listeners[] = $sharedEvents->attach(
'Zend\Stdlib\DispatchableInterface',
MvcEvent::EVENT_DISPATCH,
array($this, 'checkEmailVerification'),
10000);
} | [
"public",
"function",
"attach",
"(",
"EventManagerInterface",
"$",
"events",
")",
"{",
"$",
"sharedEvents",
"=",
"$",
"events",
"->",
"getSharedManager",
"(",
")",
";",
"$",
"this",
"->",
"listeners",
"[",
"]",
"=",
"$",
"sharedEvents",
"->",
"attach",
"(",
"'Zend\\Stdlib\\DispatchableInterface'",
",",
"MvcEvent",
"::",
"EVENT_DISPATCH",
",",
"array",
"(",
"$",
"this",
",",
"'checkEmailVerification'",
")",
",",
"10000",
")",
";",
"}"
] | Attach event listeners
@see \Zend\EventManager\ListenerAggregateInterface::attach()
@param EventManagerInterface $events | [
"Attach",
"event",
"listeners"
] | train | https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Mvc/Listener/EmailVerificationStrategy.php#L44-L52 |
SporkCode/Spork | src/Mvc/Listener/EmailVerificationStrategy.php | EmailVerificationStrategy.checkEmailVerification | public function checkEmailVerification(MvcEvent $event)
{
$services = $event->getApplication()->getServiceManager();
$appConfig = $services->get('config');
$config = $this->defaultConfig;
if (array_key_exists(self::CONFIG_KEY, $appConfig)) {
$config = $appConfig[self::CONFIG_KEY] + $config;
}
// if (empty($config['routeParams'])) {
// throw new \Exception(sprintf(
// "Route parameters missing. Add \"array('%s' => array('routeParams' => array(PARAMETERS)))\" to your configuration",
// self::CONFIG_KEY));
// }
$routeMatch = $event->getRouteMatch();
if (in_array($routeMatch->getMatchedRouteName(), $config['routeBlacklist'])) {
return;
}
$auth = $services->get($config['authServiceName']);
if (!$auth->hasIdentity()) {
return;
}
$identity = $services->get($config['identityServiceName']);
$isVerified = $config['identityCheckType'] == 'property' ?
$identity->$config['identityCheck'] :
call_user_func(array($identity, $config['identityCheck']));
if ($isVerified) {
return;
}
//$routeMatch = new RouteMatch($config['routeParams']);
//$event->setRouteMatch($routeMatch);
return $services->get('controllerPluginManager')->get('redirect')->toRoute($config['route'], $config['routeParams']);
} | php | public function checkEmailVerification(MvcEvent $event)
{
$services = $event->getApplication()->getServiceManager();
$appConfig = $services->get('config');
$config = $this->defaultConfig;
if (array_key_exists(self::CONFIG_KEY, $appConfig)) {
$config = $appConfig[self::CONFIG_KEY] + $config;
}
// if (empty($config['routeParams'])) {
// throw new \Exception(sprintf(
// "Route parameters missing. Add \"array('%s' => array('routeParams' => array(PARAMETERS)))\" to your configuration",
// self::CONFIG_KEY));
// }
$routeMatch = $event->getRouteMatch();
if (in_array($routeMatch->getMatchedRouteName(), $config['routeBlacklist'])) {
return;
}
$auth = $services->get($config['authServiceName']);
if (!$auth->hasIdentity()) {
return;
}
$identity = $services->get($config['identityServiceName']);
$isVerified = $config['identityCheckType'] == 'property' ?
$identity->$config['identityCheck'] :
call_user_func(array($identity, $config['identityCheck']));
if ($isVerified) {
return;
}
//$routeMatch = new RouteMatch($config['routeParams']);
//$event->setRouteMatch($routeMatch);
return $services->get('controllerPluginManager')->get('redirect')->toRoute($config['route'], $config['routeParams']);
} | [
"public",
"function",
"checkEmailVerification",
"(",
"MvcEvent",
"$",
"event",
")",
"{",
"$",
"services",
"=",
"$",
"event",
"->",
"getApplication",
"(",
")",
"->",
"getServiceManager",
"(",
")",
";",
"$",
"appConfig",
"=",
"$",
"services",
"->",
"get",
"(",
"'config'",
")",
";",
"$",
"config",
"=",
"$",
"this",
"->",
"defaultConfig",
";",
"if",
"(",
"array_key_exists",
"(",
"self",
"::",
"CONFIG_KEY",
",",
"$",
"appConfig",
")",
")",
"{",
"$",
"config",
"=",
"$",
"appConfig",
"[",
"self",
"::",
"CONFIG_KEY",
"]",
"+",
"$",
"config",
";",
"}",
"// if (empty($config['routeParams'])) {",
"// throw new \\Exception(sprintf(",
"// \"Route parameters missing. Add \\\"array('%s' => array('routeParams' => array(PARAMETERS)))\\\" to your configuration\", ",
"// self::CONFIG_KEY));",
"// }",
"$",
"routeMatch",
"=",
"$",
"event",
"->",
"getRouteMatch",
"(",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"routeMatch",
"->",
"getMatchedRouteName",
"(",
")",
",",
"$",
"config",
"[",
"'routeBlacklist'",
"]",
")",
")",
"{",
"return",
";",
"}",
"$",
"auth",
"=",
"$",
"services",
"->",
"get",
"(",
"$",
"config",
"[",
"'authServiceName'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"auth",
"->",
"hasIdentity",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"identity",
"=",
"$",
"services",
"->",
"get",
"(",
"$",
"config",
"[",
"'identityServiceName'",
"]",
")",
";",
"$",
"isVerified",
"=",
"$",
"config",
"[",
"'identityCheckType'",
"]",
"==",
"'property'",
"?",
"$",
"identity",
"->",
"$",
"config",
"[",
"'identityCheck'",
"]",
":",
"call_user_func",
"(",
"array",
"(",
"$",
"identity",
",",
"$",
"config",
"[",
"'identityCheck'",
"]",
")",
")",
";",
"if",
"(",
"$",
"isVerified",
")",
"{",
"return",
";",
"}",
"//$routeMatch = new RouteMatch($config['routeParams']);",
"//$event->setRouteMatch($routeMatch);",
"return",
"$",
"services",
"->",
"get",
"(",
"'controllerPluginManager'",
")",
"->",
"get",
"(",
"'redirect'",
")",
"->",
"toRoute",
"(",
"$",
"config",
"[",
"'route'",
"]",
",",
"$",
"config",
"[",
"'routeParams'",
"]",
")",
";",
"}"
] | Check if the email address is verified and if not redirects to a
specified route.
@param MvcEvent $event | [
"Check",
"if",
"the",
"email",
"address",
"is",
"verified",
"and",
"if",
"not",
"redirects",
"to",
"a",
"specified",
"route",
"."
] | train | https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Mvc/Listener/EmailVerificationStrategy.php#L60-L98 |
ekuiter/feature-php | FeaturePhp/Specification/DirectorySpecification.php | DirectorySpecification.fromArrayAndSettings | public static function fromArrayAndSettings($cfg, $settings) {
$directorySpecification = new self($cfg, $settings->getDirectory());
$directorySpecification->set("source", $settings->getPath($directorySpecification->getSource()));
$directorySpecification->set("baseTarget", $settings->getOptional("target", null));
if (!is_dir($directorySpecification->getSource()))
throw new DirectorySpecificationException("directory \"{$directorySpecification->getSource()}\" does not exist");
return $directorySpecification;
} | php | public static function fromArrayAndSettings($cfg, $settings) {
$directorySpecification = new self($cfg, $settings->getDirectory());
$directorySpecification->set("source", $settings->getPath($directorySpecification->getSource()));
$directorySpecification->set("baseTarget", $settings->getOptional("target", null));
if (!is_dir($directorySpecification->getSource()))
throw new DirectorySpecificationException("directory \"{$directorySpecification->getSource()}\" does not exist");
return $directorySpecification;
} | [
"public",
"static",
"function",
"fromArrayAndSettings",
"(",
"$",
"cfg",
",",
"$",
"settings",
")",
"{",
"$",
"directorySpecification",
"=",
"new",
"self",
"(",
"$",
"cfg",
",",
"$",
"settings",
"->",
"getDirectory",
"(",
")",
")",
";",
"$",
"directorySpecification",
"->",
"set",
"(",
"\"source\"",
",",
"$",
"settings",
"->",
"getPath",
"(",
"$",
"directorySpecification",
"->",
"getSource",
"(",
")",
")",
")",
";",
"$",
"directorySpecification",
"->",
"set",
"(",
"\"baseTarget\"",
",",
"$",
"settings",
"->",
"getOptional",
"(",
"\"target\"",
",",
"null",
")",
")",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"directorySpecification",
"->",
"getSource",
"(",
")",
")",
")",
"throw",
"new",
"DirectorySpecificationException",
"(",
"\"directory \\\"{$directorySpecification->getSource()}\\\" does not exist\"",
")",
";",
"return",
"$",
"directorySpecification",
";",
"}"
] | Creates a directory specification from a plain settings array.
The settings context is taken into consideration to generate paths
relative to the settings.
@param array $cfg a plain settings array
@param \FeaturePhp\Settings $settings the settings context
@return DirectorySpecification | [
"Creates",
"a",
"directory",
"specification",
"from",
"a",
"plain",
"settings",
"array",
".",
"The",
"settings",
"context",
"is",
"taken",
"into",
"consideration",
"to",
"generate",
"paths",
"relative",
"to",
"the",
"settings",
"."
] | train | https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/Specification/DirectorySpecification.php#L48-L57 |
ekuiter/feature-php | FeaturePhp/Specification/DirectorySpecification.php | DirectorySpecification.getFileSpecifications | public function getFileSpecifications() {
$fileSpecifications = array();
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->getSource())) as $entry)
if (!fphp\Helper\Path::isDot($entry)) {
$fileSource = $entry->getPathName();
if (is_link($fileSource))
continue;
$relativeFileTarget = fphp\Helper\Path::stripBase(
realpath($fileSource), realpath($this->getSource()));
foreach ($this->getExclude() as $exclude) {
if ($relativeFileTarget === $exclude)
continue 2;
$parts = explode("/", $exclude);
if ($parts[count($parts) - 1] === "*")
try {
fphp\Helper\Path::stripBase($relativeFileTarget, implode("/", array_slice($parts, 0, count($parts) - 1)));
continue 2;
} catch (fphp\Helper\PathException $e) {}
}
$fileTarget = fphp\Helper\Path::join(
$this->get("baseTarget"), fphp\Helper\Path::join($this->getTarget(), $relativeFileTarget));
$fileSpecifications[] = new FileSpecification(
array("source" => $fileSource, "target" => $fileTarget), $this->getDirectory());
}
return $fileSpecifications;
} | php | public function getFileSpecifications() {
$fileSpecifications = array();
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->getSource())) as $entry)
if (!fphp\Helper\Path::isDot($entry)) {
$fileSource = $entry->getPathName();
if (is_link($fileSource))
continue;
$relativeFileTarget = fphp\Helper\Path::stripBase(
realpath($fileSource), realpath($this->getSource()));
foreach ($this->getExclude() as $exclude) {
if ($relativeFileTarget === $exclude)
continue 2;
$parts = explode("/", $exclude);
if ($parts[count($parts) - 1] === "*")
try {
fphp\Helper\Path::stripBase($relativeFileTarget, implode("/", array_slice($parts, 0, count($parts) - 1)));
continue 2;
} catch (fphp\Helper\PathException $e) {}
}
$fileTarget = fphp\Helper\Path::join(
$this->get("baseTarget"), fphp\Helper\Path::join($this->getTarget(), $relativeFileTarget));
$fileSpecifications[] = new FileSpecification(
array("source" => $fileSource, "target" => $fileTarget), $this->getDirectory());
}
return $fileSpecifications;
} | [
"public",
"function",
"getFileSpecifications",
"(",
")",
"{",
"$",
"fileSpecifications",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"new",
"\\",
"RecursiveIteratorIterator",
"(",
"new",
"\\",
"RecursiveDirectoryIterator",
"(",
"$",
"this",
"->",
"getSource",
"(",
")",
")",
")",
"as",
"$",
"entry",
")",
"if",
"(",
"!",
"fphp",
"\\",
"Helper",
"\\",
"Path",
"::",
"isDot",
"(",
"$",
"entry",
")",
")",
"{",
"$",
"fileSource",
"=",
"$",
"entry",
"->",
"getPathName",
"(",
")",
";",
"if",
"(",
"is_link",
"(",
"$",
"fileSource",
")",
")",
"continue",
";",
"$",
"relativeFileTarget",
"=",
"fphp",
"\\",
"Helper",
"\\",
"Path",
"::",
"stripBase",
"(",
"realpath",
"(",
"$",
"fileSource",
")",
",",
"realpath",
"(",
"$",
"this",
"->",
"getSource",
"(",
")",
")",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getExclude",
"(",
")",
"as",
"$",
"exclude",
")",
"{",
"if",
"(",
"$",
"relativeFileTarget",
"===",
"$",
"exclude",
")",
"continue",
"2",
";",
"$",
"parts",
"=",
"explode",
"(",
"\"/\"",
",",
"$",
"exclude",
")",
";",
"if",
"(",
"$",
"parts",
"[",
"count",
"(",
"$",
"parts",
")",
"-",
"1",
"]",
"===",
"\"*\"",
")",
"try",
"{",
"fphp",
"\\",
"Helper",
"\\",
"Path",
"::",
"stripBase",
"(",
"$",
"relativeFileTarget",
",",
"implode",
"(",
"\"/\"",
",",
"array_slice",
"(",
"$",
"parts",
",",
"0",
",",
"count",
"(",
"$",
"parts",
")",
"-",
"1",
")",
")",
")",
";",
"continue",
"2",
";",
"}",
"catch",
"(",
"fphp",
"\\",
"Helper",
"\\",
"PathException",
"$",
"e",
")",
"{",
"}",
"}",
"$",
"fileTarget",
"=",
"fphp",
"\\",
"Helper",
"\\",
"Path",
"::",
"join",
"(",
"$",
"this",
"->",
"get",
"(",
"\"baseTarget\"",
")",
",",
"fphp",
"\\",
"Helper",
"\\",
"Path",
"::",
"join",
"(",
"$",
"this",
"->",
"getTarget",
"(",
")",
",",
"$",
"relativeFileTarget",
")",
")",
";",
"$",
"fileSpecifications",
"[",
"]",
"=",
"new",
"FileSpecification",
"(",
"array",
"(",
"\"source\"",
"=>",
"$",
"fileSource",
",",
"\"target\"",
"=>",
"$",
"fileTarget",
")",
",",
"$",
"this",
"->",
"getDirectory",
"(",
")",
")",
";",
"}",
"return",
"$",
"fileSpecifications",
";",
"}"
] | Returns the file specifications this directory specification applies to.
The entire source directory tree is considered, except for excluded files.
@return FileSpecification[] | [
"Returns",
"the",
"file",
"specifications",
"this",
"directory",
"specification",
"applies",
"to",
".",
"The",
"entire",
"source",
"directory",
"tree",
"is",
"considered",
"except",
"for",
"excluded",
"files",
"."
] | train | https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/Specification/DirectorySpecification.php#L73-L102 |
bit3archive/php-remote-objects | src/RemoteObjects/Client.php | Client.getRemoteObject | public function getRemoteObject($key, $interface = null)
{
if ($interface) {
if (
$this->logger !== null &&
$this->logger->isHandling(\Monolog\Logger::DEBUG)
) {
$this->logger->addDebug(
'Create new virtual remote object proxy',
array(
'interface' => $interface,
'path' => $key
)
);
}
return RemoteObjectProxyGenerator::generate($this, $interface, $key);
}
else {
if (
$this->logger !== null &&
$this->logger->isHandling(\Monolog\Logger::DEBUG)
) {
$this->logger->addDebug(
'Get remote object proxy',
array(
'path' => $key
)
);
}
return new RemoteObjectProxy($this, $key);
}
} | php | public function getRemoteObject($key, $interface = null)
{
if ($interface) {
if (
$this->logger !== null &&
$this->logger->isHandling(\Monolog\Logger::DEBUG)
) {
$this->logger->addDebug(
'Create new virtual remote object proxy',
array(
'interface' => $interface,
'path' => $key
)
);
}
return RemoteObjectProxyGenerator::generate($this, $interface, $key);
}
else {
if (
$this->logger !== null &&
$this->logger->isHandling(\Monolog\Logger::DEBUG)
) {
$this->logger->addDebug(
'Get remote object proxy',
array(
'path' => $key
)
);
}
return new RemoteObjectProxy($this, $key);
}
} | [
"public",
"function",
"getRemoteObject",
"(",
"$",
"key",
",",
"$",
"interface",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"interface",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"logger",
"!==",
"null",
"&&",
"$",
"this",
"->",
"logger",
"->",
"isHandling",
"(",
"\\",
"Monolog",
"\\",
"Logger",
"::",
"DEBUG",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"addDebug",
"(",
"'Create new virtual remote object proxy'",
",",
"array",
"(",
"'interface'",
"=>",
"$",
"interface",
",",
"'path'",
"=>",
"$",
"key",
")",
")",
";",
"}",
"return",
"RemoteObjectProxyGenerator",
"::",
"generate",
"(",
"$",
"this",
",",
"$",
"interface",
",",
"$",
"key",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"this",
"->",
"logger",
"!==",
"null",
"&&",
"$",
"this",
"->",
"logger",
"->",
"isHandling",
"(",
"\\",
"Monolog",
"\\",
"Logger",
"::",
"DEBUG",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"addDebug",
"(",
"'Get remote object proxy'",
",",
"array",
"(",
"'path'",
"=>",
"$",
"key",
")",
")",
";",
"}",
"return",
"new",
"RemoteObjectProxy",
"(",
"$",
"this",
",",
"$",
"key",
")",
";",
"}",
"}"
] | Get a named remote object proxy.
@param string $key
@param string|null $interface
@return RemoteObject | [
"Get",
"a",
"named",
"remote",
"object",
"proxy",
"."
] | train | https://github.com/bit3archive/php-remote-objects/blob/0a917cdb261d83b1e89bdbdce3627584823bff5f/src/RemoteObjects/Client.php#L128-L161 |
bit3archive/php-remote-objects | src/RemoteObjects/Client.php | Client.invoke | public function invoke($method, $_ = null)
{
$params = func_get_args();
array_shift($params);
return $this->invokeArgs($method, $params);
} | php | public function invoke($method, $_ = null)
{
$params = func_get_args();
array_shift($params);
return $this->invokeArgs($method, $params);
} | [
"public",
"function",
"invoke",
"(",
"$",
"method",
",",
"$",
"_",
"=",
"null",
")",
"{",
"$",
"params",
"=",
"func_get_args",
"(",
")",
";",
"array_shift",
"(",
"$",
"params",
")",
";",
"return",
"$",
"this",
"->",
"invokeArgs",
"(",
"$",
"method",
",",
"$",
"params",
")",
";",
"}"
] | Invoke a remote method.
@param string $method The method name.
@param mixed $_ List of method parameters.
@return mixed | [
"Invoke",
"a",
"remote",
"method",
"."
] | train | https://github.com/bit3archive/php-remote-objects/blob/0a917cdb261d83b1e89bdbdce3627584823bff5f/src/RemoteObjects/Client.php#L171-L177 |
bit3archive/php-remote-objects | src/RemoteObjects/Client.php | Client.invokeArgs | public function invokeArgs($method, array $params)
{
if (
$this->logger !== null &&
$this->logger->isHandling(\Monolog\Logger::DEBUG)
) {
$methodSynopsis = $method . '(';
foreach (array_values($params) as $index => $param) {
if ($index > 0) {
$methodSynopsis .= ', ';
}
$methodSynopsis .= var_export($param, true);
}
$methodSynopsis .= ')';
$this->logger->addDebug(
'Invoke remote object method ' . $methodSynopsis,
array(
'transport' => $this->transport,
'method' => $method,
'params' => $params
)
);
}
$request = $this->encoder->encodeMethod($method, $params);
$response = $this->transport->request($request);
$result = $this->encoder->decodeResult($response);
if (
$this->logger !== null &&
$this->logger->isHandling(\Monolog\Logger::DEBUG)
) {
$this->logger->addDebug(
'Receive methods ' . $methodSynopsis . ' result.',
array(
'transport' => $this->transport,
'method' => $method,
'params' => $params
)
);
}
return $result;
} | php | public function invokeArgs($method, array $params)
{
if (
$this->logger !== null &&
$this->logger->isHandling(\Monolog\Logger::DEBUG)
) {
$methodSynopsis = $method . '(';
foreach (array_values($params) as $index => $param) {
if ($index > 0) {
$methodSynopsis .= ', ';
}
$methodSynopsis .= var_export($param, true);
}
$methodSynopsis .= ')';
$this->logger->addDebug(
'Invoke remote object method ' . $methodSynopsis,
array(
'transport' => $this->transport,
'method' => $method,
'params' => $params
)
);
}
$request = $this->encoder->encodeMethod($method, $params);
$response = $this->transport->request($request);
$result = $this->encoder->decodeResult($response);
if (
$this->logger !== null &&
$this->logger->isHandling(\Monolog\Logger::DEBUG)
) {
$this->logger->addDebug(
'Receive methods ' . $methodSynopsis . ' result.',
array(
'transport' => $this->transport,
'method' => $method,
'params' => $params
)
);
}
return $result;
} | [
"public",
"function",
"invokeArgs",
"(",
"$",
"method",
",",
"array",
"$",
"params",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"logger",
"!==",
"null",
"&&",
"$",
"this",
"->",
"logger",
"->",
"isHandling",
"(",
"\\",
"Monolog",
"\\",
"Logger",
"::",
"DEBUG",
")",
")",
"{",
"$",
"methodSynopsis",
"=",
"$",
"method",
".",
"'('",
";",
"foreach",
"(",
"array_values",
"(",
"$",
"params",
")",
"as",
"$",
"index",
"=>",
"$",
"param",
")",
"{",
"if",
"(",
"$",
"index",
">",
"0",
")",
"{",
"$",
"methodSynopsis",
".=",
"', '",
";",
"}",
"$",
"methodSynopsis",
".=",
"var_export",
"(",
"$",
"param",
",",
"true",
")",
";",
"}",
"$",
"methodSynopsis",
".=",
"')'",
";",
"$",
"this",
"->",
"logger",
"->",
"addDebug",
"(",
"'Invoke remote object method '",
".",
"$",
"methodSynopsis",
",",
"array",
"(",
"'transport'",
"=>",
"$",
"this",
"->",
"transport",
",",
"'method'",
"=>",
"$",
"method",
",",
"'params'",
"=>",
"$",
"params",
")",
")",
";",
"}",
"$",
"request",
"=",
"$",
"this",
"->",
"encoder",
"->",
"encodeMethod",
"(",
"$",
"method",
",",
"$",
"params",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"transport",
"->",
"request",
"(",
"$",
"request",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"encoder",
"->",
"decodeResult",
"(",
"$",
"response",
")",
";",
"if",
"(",
"$",
"this",
"->",
"logger",
"!==",
"null",
"&&",
"$",
"this",
"->",
"logger",
"->",
"isHandling",
"(",
"\\",
"Monolog",
"\\",
"Logger",
"::",
"DEBUG",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"addDebug",
"(",
"'Receive methods '",
".",
"$",
"methodSynopsis",
".",
"' result.'",
",",
"array",
"(",
"'transport'",
"=>",
"$",
"this",
"->",
"transport",
",",
"'method'",
"=>",
"$",
"method",
",",
"'params'",
"=>",
"$",
"params",
")",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Invoke a remote method.
@param string $method The method name.
@param array $params List of method parameters.
@return mixed | [
"Invoke",
"a",
"remote",
"method",
"."
] | train | https://github.com/bit3archive/php-remote-objects/blob/0a917cdb261d83b1e89bdbdce3627584823bff5f/src/RemoteObjects/Client.php#L187-L233 |
neat-php/database | classes/Query.php | Query.select | public function select($expression = '*')
{
if (!is_array($expression)) {
$expression = explode(',', $expression);
}
$this->type = self::TYPE_SELECT;
$this->expressions = array_merge($this->expressions, array_map(function ($expression, $alias) {
return is_string($alias) ? "$expression AS $alias" : $expression;
}, $expression, array_keys($expression)));
return $this;
} | php | public function select($expression = '*')
{
if (!is_array($expression)) {
$expression = explode(',', $expression);
}
$this->type = self::TYPE_SELECT;
$this->expressions = array_merge($this->expressions, array_map(function ($expression, $alias) {
return is_string($alias) ? "$expression AS $alias" : $expression;
}, $expression, array_keys($expression)));
return $this;
} | [
"public",
"function",
"select",
"(",
"$",
"expression",
"=",
"'*'",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"expression",
")",
")",
"{",
"$",
"expression",
"=",
"explode",
"(",
"','",
",",
"$",
"expression",
")",
";",
"}",
"$",
"this",
"->",
"type",
"=",
"self",
"::",
"TYPE_SELECT",
";",
"$",
"this",
"->",
"expressions",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"expressions",
",",
"array_map",
"(",
"function",
"(",
"$",
"expression",
",",
"$",
"alias",
")",
"{",
"return",
"is_string",
"(",
"$",
"alias",
")",
"?",
"\"$expression AS $alias\"",
":",
"$",
"expression",
";",
"}",
",",
"$",
"expression",
",",
"array_keys",
"(",
"$",
"expression",
")",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Select query
@param array|string $expression
@return $this | [
"Select",
"query"
] | train | https://github.com/neat-php/database/blob/7b4b66c8f1bc63e50925f12712b9eedcfb2a98ff/classes/Query.php#L108-L120 |
neat-php/database | classes/Query.php | Query.insert | public function insert($table = null)
{
$this->type = self::TYPE_INSERT;
if ($table) {
$this->table($table);
}
return $this;
} | php | public function insert($table = null)
{
$this->type = self::TYPE_INSERT;
if ($table) {
$this->table($table);
}
return $this;
} | [
"public",
"function",
"insert",
"(",
"$",
"table",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"type",
"=",
"self",
"::",
"TYPE_INSERT",
";",
"if",
"(",
"$",
"table",
")",
"{",
"$",
"this",
"->",
"table",
"(",
"$",
"table",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Insert query
@param string $table (optional)
@return $this | [
"Insert",
"query"
] | train | https://github.com/neat-php/database/blob/7b4b66c8f1bc63e50925f12712b9eedcfb2a98ff/classes/Query.php#L128-L136 |
neat-php/database | classes/Query.php | Query.update | public function update($table = null)
{
$this->type = self::TYPE_UPDATE;
if ($table) {
$this->table($table);
}
return $this;
} | php | public function update($table = null)
{
$this->type = self::TYPE_UPDATE;
if ($table) {
$this->table($table);
}
return $this;
} | [
"public",
"function",
"update",
"(",
"$",
"table",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"type",
"=",
"self",
"::",
"TYPE_UPDATE",
";",
"if",
"(",
"$",
"table",
")",
"{",
"$",
"this",
"->",
"table",
"(",
"$",
"table",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Update query
@param string $table (optional)
@return $this | [
"Update",
"query"
] | train | https://github.com/neat-php/database/blob/7b4b66c8f1bc63e50925f12712b9eedcfb2a98ff/classes/Query.php#L144-L152 |
neat-php/database | classes/Query.php | Query.delete | public function delete($table = null)
{
$this->type = self::TYPE_DELETE;
if ($table) {
$this->table($table);
}
return $this;
} | php | public function delete($table = null)
{
$this->type = self::TYPE_DELETE;
if ($table) {
$this->table($table);
}
return $this;
} | [
"public",
"function",
"delete",
"(",
"$",
"table",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"type",
"=",
"self",
"::",
"TYPE_DELETE",
";",
"if",
"(",
"$",
"table",
")",
"{",
"$",
"this",
"->",
"table",
"(",
"$",
"table",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Delete query
@param string $table (optional)
@return $this | [
"Delete",
"query"
] | train | https://github.com/neat-php/database/blob/7b4b66c8f1bc63e50925f12712b9eedcfb2a98ff/classes/Query.php#L160-L168 |
neat-php/database | classes/Query.php | Query.table | public function table($table, $alias = null)
{
if ($alias) {
$table = [$alias => $table];
} elseif (!is_array($table)) {
$table = [$table];
}
$this->joins = [];
foreach ($table as $alias => $name) {
if ($name instanceof QueryInterface) {
$expression = '(' . $name->getQuery() . ')';
} else {
$expression = $this->connection->quoteIdentifier($name);
}
if (is_string($alias)) {
$this->tables[$alias] = $expression . ' ' . $alias;
} else {
$this->tables[$name] = $expression;
}
}
return $this;
} | php | public function table($table, $alias = null)
{
if ($alias) {
$table = [$alias => $table];
} elseif (!is_array($table)) {
$table = [$table];
}
$this->joins = [];
foreach ($table as $alias => $name) {
if ($name instanceof QueryInterface) {
$expression = '(' . $name->getQuery() . ')';
} else {
$expression = $this->connection->quoteIdentifier($name);
}
if (is_string($alias)) {
$this->tables[$alias] = $expression . ' ' . $alias;
} else {
$this->tables[$name] = $expression;
}
}
return $this;
} | [
"public",
"function",
"table",
"(",
"$",
"table",
",",
"$",
"alias",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"alias",
")",
"{",
"$",
"table",
"=",
"[",
"$",
"alias",
"=>",
"$",
"table",
"]",
";",
"}",
"elseif",
"(",
"!",
"is_array",
"(",
"$",
"table",
")",
")",
"{",
"$",
"table",
"=",
"[",
"$",
"table",
"]",
";",
"}",
"$",
"this",
"->",
"joins",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"table",
"as",
"$",
"alias",
"=>",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"name",
"instanceof",
"QueryInterface",
")",
"{",
"$",
"expression",
"=",
"'('",
".",
"$",
"name",
"->",
"getQuery",
"(",
")",
".",
"')'",
";",
"}",
"else",
"{",
"$",
"expression",
"=",
"$",
"this",
"->",
"connection",
"->",
"quoteIdentifier",
"(",
"$",
"name",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"alias",
")",
")",
"{",
"$",
"this",
"->",
"tables",
"[",
"$",
"alias",
"]",
"=",
"$",
"expression",
".",
"' '",
".",
"$",
"alias",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"tables",
"[",
"$",
"name",
"]",
"=",
"$",
"expression",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Table to insert, update or delete from/into
@param array|string $table
@param string $alias (optional)
@return $this | [
"Table",
"to",
"insert",
"update",
"or",
"delete",
"from",
"/",
"into"
] | train | https://github.com/neat-php/database/blob/7b4b66c8f1bc63e50925f12712b9eedcfb2a98ff/classes/Query.php#L177-L200 |
neat-php/database | classes/Query.php | Query.join | public function join($table, $alias = null, $on = null, $type = 'INNER JOIN')
{
$table = $this->connection->quoteIdentifier($table);
$this->joins[$alias] = "$type $table $alias ON $on";
return $this;
} | php | public function join($table, $alias = null, $on = null, $type = 'INNER JOIN')
{
$table = $this->connection->quoteIdentifier($table);
$this->joins[$alias] = "$type $table $alias ON $on";
return $this;
} | [
"public",
"function",
"join",
"(",
"$",
"table",
",",
"$",
"alias",
"=",
"null",
",",
"$",
"on",
"=",
"null",
",",
"$",
"type",
"=",
"'INNER JOIN'",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"connection",
"->",
"quoteIdentifier",
"(",
"$",
"table",
")",
";",
"$",
"this",
"->",
"joins",
"[",
"$",
"alias",
"]",
"=",
"\"$type $table $alias ON $on\"",
";",
"return",
"$",
"this",
";",
"}"
] | Join a table
@param string $table
@param string $alias
@param string $on
@param string $type
@return $this | [
"Join",
"a",
"table"
] | train | https://github.com/neat-php/database/blob/7b4b66c8f1bc63e50925f12712b9eedcfb2a98ff/classes/Query.php#L235-L242 |
neat-php/database | classes/Query.php | Query.leftJoin | public function leftJoin($table, $alias = null, $on = null)
{
return $this->join($table, $alias, $on, 'LEFT JOIN');
} | php | public function leftJoin($table, $alias = null, $on = null)
{
return $this->join($table, $alias, $on, 'LEFT JOIN');
} | [
"public",
"function",
"leftJoin",
"(",
"$",
"table",
",",
"$",
"alias",
"=",
"null",
",",
"$",
"on",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"join",
"(",
"$",
"table",
",",
"$",
"alias",
",",
"$",
"on",
",",
"'LEFT JOIN'",
")",
";",
"}"
] | LEFT OUTER Join a table
@param string $table
@param string $alias
@param string $on
@return $this | [
"LEFT",
"OUTER",
"Join",
"a",
"table"
] | train | https://github.com/neat-php/database/blob/7b4b66c8f1bc63e50925f12712b9eedcfb2a98ff/classes/Query.php#L252-L255 |
neat-php/database | classes/Query.php | Query.rightJoin | public function rightJoin($table, $alias = null, $on = null)
{
return $this->join($table, $alias, $on, 'RIGHT JOIN');
} | php | public function rightJoin($table, $alias = null, $on = null)
{
return $this->join($table, $alias, $on, 'RIGHT JOIN');
} | [
"public",
"function",
"rightJoin",
"(",
"$",
"table",
",",
"$",
"alias",
"=",
"null",
",",
"$",
"on",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"join",
"(",
"$",
"table",
",",
"$",
"alias",
",",
"$",
"on",
",",
"'RIGHT JOIN'",
")",
";",
"}"
] | RIGHT OUTER Join a table
@param string $table
@param string $alias
@param string $on
@return $this | [
"RIGHT",
"OUTER",
"Join",
"a",
"table"
] | train | https://github.com/neat-php/database/blob/7b4b66c8f1bc63e50925f12712b9eedcfb2a98ff/classes/Query.php#L265-L268 |
neat-php/database | classes/Query.php | Query.innerJoin | public function innerJoin($table, $alias = null, $on = null)
{
return $this->join($table, $alias, $on, 'INNER JOIN');
} | php | public function innerJoin($table, $alias = null, $on = null)
{
return $this->join($table, $alias, $on, 'INNER JOIN');
} | [
"public",
"function",
"innerJoin",
"(",
"$",
"table",
",",
"$",
"alias",
"=",
"null",
",",
"$",
"on",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"join",
"(",
"$",
"table",
",",
"$",
"alias",
",",
"$",
"on",
",",
"'INNER JOIN'",
")",
";",
"}"
] | INNER Join a table
@param string $table
@param string $alias
@param string $on
@return $this | [
"INNER",
"Join",
"a",
"table"
] | train | https://github.com/neat-php/database/blob/7b4b66c8f1bc63e50925f12712b9eedcfb2a98ff/classes/Query.php#L278-L281 |
neat-php/database | classes/Query.php | Query.where | public function where($conditions, ...$parameters)
{
if (is_array($conditions)) {
$this->where = array_merge($this->where, array_map(function ($value, $field) {
$field = $this->connection->quoteIdentifier($field);
if ($value === null) {
return $field . ' IS NULL';
}
return $field . '=' . $this->connection->quote($value);
}, $conditions, array_keys($conditions)));
} else {
if ($parameters) {
$conditions = $this->connection->merge($conditions, $parameters);
}
$this->where[] = $conditions;
}
return $this;
} | php | public function where($conditions, ...$parameters)
{
if (is_array($conditions)) {
$this->where = array_merge($this->where, array_map(function ($value, $field) {
$field = $this->connection->quoteIdentifier($field);
if ($value === null) {
return $field . ' IS NULL';
}
return $field . '=' . $this->connection->quote($value);
}, $conditions, array_keys($conditions)));
} else {
if ($parameters) {
$conditions = $this->connection->merge($conditions, $parameters);
}
$this->where[] = $conditions;
}
return $this;
} | [
"public",
"function",
"where",
"(",
"$",
"conditions",
",",
"...",
"$",
"parameters",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"conditions",
")",
")",
"{",
"$",
"this",
"->",
"where",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"where",
",",
"array_map",
"(",
"function",
"(",
"$",
"value",
",",
"$",
"field",
")",
"{",
"$",
"field",
"=",
"$",
"this",
"->",
"connection",
"->",
"quoteIdentifier",
"(",
"$",
"field",
")",
";",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"$",
"field",
".",
"' IS NULL'",
";",
"}",
"return",
"$",
"field",
".",
"'='",
".",
"$",
"this",
"->",
"connection",
"->",
"quote",
"(",
"$",
"value",
")",
";",
"}",
",",
"$",
"conditions",
",",
"array_keys",
"(",
"$",
"conditions",
")",
")",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"parameters",
")",
"{",
"$",
"conditions",
"=",
"$",
"this",
"->",
"connection",
"->",
"merge",
"(",
"$",
"conditions",
",",
"$",
"parameters",
")",
";",
"}",
"$",
"this",
"->",
"where",
"[",
"]",
"=",
"$",
"conditions",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Where condition
@param array|string $conditions
@param array ...$parameters (optional)
@return $this | [
"Where",
"condition"
] | train | https://github.com/neat-php/database/blob/7b4b66c8f1bc63e50925f12712b9eedcfb2a98ff/classes/Query.php#L316-L335 |
neat-php/database | classes/Query.php | Query.having | public function having($conditions, ...$parameters)
{
if (is_array($conditions)) {
$this->having = array_merge($this->where, array_map(function ($value, $field) {
return $field . '=' . $this->connection->quote($value);
}, $conditions, array_keys($conditions)));
} else {
if ($parameters) {
$conditions = $this->connection->merge($conditions, $parameters);
}
$this->having[] = $conditions;
}
return $this;
} | php | public function having($conditions, ...$parameters)
{
if (is_array($conditions)) {
$this->having = array_merge($this->where, array_map(function ($value, $field) {
return $field . '=' . $this->connection->quote($value);
}, $conditions, array_keys($conditions)));
} else {
if ($parameters) {
$conditions = $this->connection->merge($conditions, $parameters);
}
$this->having[] = $conditions;
}
return $this;
} | [
"public",
"function",
"having",
"(",
"$",
"conditions",
",",
"...",
"$",
"parameters",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"conditions",
")",
")",
"{",
"$",
"this",
"->",
"having",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"where",
",",
"array_map",
"(",
"function",
"(",
"$",
"value",
",",
"$",
"field",
")",
"{",
"return",
"$",
"field",
".",
"'='",
".",
"$",
"this",
"->",
"connection",
"->",
"quote",
"(",
"$",
"value",
")",
";",
"}",
",",
"$",
"conditions",
",",
"array_keys",
"(",
"$",
"conditions",
")",
")",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"parameters",
")",
"{",
"$",
"conditions",
"=",
"$",
"this",
"->",
"connection",
"->",
"merge",
"(",
"$",
"conditions",
",",
"$",
"parameters",
")",
";",
"}",
"$",
"this",
"->",
"having",
"[",
"]",
"=",
"$",
"conditions",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Having condition
@param array|string $conditions
@param mixed ...$parameters (optional)
@return $this | [
"Having",
"condition"
] | train | https://github.com/neat-php/database/blob/7b4b66c8f1bc63e50925f12712b9eedcfb2a98ff/classes/Query.php#L357-L371 |
neat-php/database | classes/Query.php | Query.getSet | public function getSet()
{
$format = function ($value, $field) {
return $this->connection->quoteIdentifier($field) . '=' . $this->connection->quote($value);
};
return implode(',', array_map($format, $this->data, array_keys($this->data)));
} | php | public function getSet()
{
$format = function ($value, $field) {
return $this->connection->quoteIdentifier($field) . '=' . $this->connection->quote($value);
};
return implode(',', array_map($format, $this->data, array_keys($this->data)));
} | [
"public",
"function",
"getSet",
"(",
")",
"{",
"$",
"format",
"=",
"function",
"(",
"$",
"value",
",",
"$",
"field",
")",
"{",
"return",
"$",
"this",
"->",
"connection",
"->",
"quoteIdentifier",
"(",
"$",
"field",
")",
".",
"'='",
".",
"$",
"this",
"->",
"connection",
"->",
"quote",
"(",
"$",
"value",
")",
";",
"}",
";",
"return",
"implode",
"(",
"','",
",",
"array_map",
"(",
"$",
"format",
",",
"$",
"this",
"->",
"data",
",",
"array_keys",
"(",
"$",
"this",
"->",
"data",
")",
")",
")",
";",
"}"
] | Get values
@return string | [
"Get",
"values"
] | train | https://github.com/neat-php/database/blob/7b4b66c8f1bc63e50925f12712b9eedcfb2a98ff/classes/Query.php#L457-L464 |
neat-php/database | classes/Query.php | Query.getLimit | public function getLimit()
{
if ($this->offset && $this->limit) {
return $this->offset . ',' . $this->limit;
}
return (string)$this->limit;
} | php | public function getLimit()
{
if ($this->offset && $this->limit) {
return $this->offset . ',' . $this->limit;
}
return (string)$this->limit;
} | [
"public",
"function",
"getLimit",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"offset",
"&&",
"$",
"this",
"->",
"limit",
")",
"{",
"return",
"$",
"this",
"->",
"offset",
".",
"','",
".",
"$",
"this",
"->",
"limit",
";",
"}",
"return",
"(",
"string",
")",
"$",
"this",
"->",
"limit",
";",
"}"
] | Get limit query part
@return string | [
"Get",
"limit",
"query",
"part"
] | train | https://github.com/neat-php/database/blob/7b4b66c8f1bc63e50925f12712b9eedcfb2a98ff/classes/Query.php#L521-L528 |
neat-php/database | classes/Query.php | Query.getSelectQuery | public function getSelectQuery()
{
$sql = 'SELECT ' . $this->getSelect();
$sql .= "\nFROM " . $this->getFrom();
if ($this->where) {
$sql .= "\nWHERE " . $this->getWhere();
}
if ($this->groupBy) {
$sql .= "\nGROUP BY " . $this->getGroupBy();
}
if ($this->having) {
$sql .= "\nHAVING " . $this->getHaving();
}
if ($this->orderBy) {
$sql .= "\nORDER BY " . $this->getOrderBy();
}
if ($this->limit) {
$sql .= "\nLIMIT " . $this->getLimit();
}
return $sql;
} | php | public function getSelectQuery()
{
$sql = 'SELECT ' . $this->getSelect();
$sql .= "\nFROM " . $this->getFrom();
if ($this->where) {
$sql .= "\nWHERE " . $this->getWhere();
}
if ($this->groupBy) {
$sql .= "\nGROUP BY " . $this->getGroupBy();
}
if ($this->having) {
$sql .= "\nHAVING " . $this->getHaving();
}
if ($this->orderBy) {
$sql .= "\nORDER BY " . $this->getOrderBy();
}
if ($this->limit) {
$sql .= "\nLIMIT " . $this->getLimit();
}
return $sql;
} | [
"public",
"function",
"getSelectQuery",
"(",
")",
"{",
"$",
"sql",
"=",
"'SELECT '",
".",
"$",
"this",
"->",
"getSelect",
"(",
")",
";",
"$",
"sql",
".=",
"\"\\nFROM \"",
".",
"$",
"this",
"->",
"getFrom",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"where",
")",
"{",
"$",
"sql",
".=",
"\"\\nWHERE \"",
".",
"$",
"this",
"->",
"getWhere",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"groupBy",
")",
"{",
"$",
"sql",
".=",
"\"\\nGROUP BY \"",
".",
"$",
"this",
"->",
"getGroupBy",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"having",
")",
"{",
"$",
"sql",
".=",
"\"\\nHAVING \"",
".",
"$",
"this",
"->",
"getHaving",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"orderBy",
")",
"{",
"$",
"sql",
".=",
"\"\\nORDER BY \"",
".",
"$",
"this",
"->",
"getOrderBy",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"limit",
")",
"{",
"$",
"sql",
".=",
"\"\\nLIMIT \"",
".",
"$",
"this",
"->",
"getLimit",
"(",
")",
";",
"}",
"return",
"$",
"sql",
";",
"}"
] | Get SQL select query
@return string | [
"Get",
"SQL",
"select",
"query"
] | train | https://github.com/neat-php/database/blob/7b4b66c8f1bc63e50925f12712b9eedcfb2a98ff/classes/Query.php#L535-L556 |
neat-php/database | classes/Query.php | Query.getInsertQuery | public function getInsertQuery()
{
$sql = 'INSERT INTO ' . $this->getTable();
$sql .= "\n" . $this->getColumns();
$sql .= "\nVALUES " . $this->getValues();
return $sql;
} | php | public function getInsertQuery()
{
$sql = 'INSERT INTO ' . $this->getTable();
$sql .= "\n" . $this->getColumns();
$sql .= "\nVALUES " . $this->getValues();
return $sql;
} | [
"public",
"function",
"getInsertQuery",
"(",
")",
"{",
"$",
"sql",
"=",
"'INSERT INTO '",
".",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"$",
"sql",
".=",
"\"\\n\"",
".",
"$",
"this",
"->",
"getColumns",
"(",
")",
";",
"$",
"sql",
".=",
"\"\\nVALUES \"",
".",
"$",
"this",
"->",
"getValues",
"(",
")",
";",
"return",
"$",
"sql",
";",
"}"
] | Get SQL insert query
@return string | [
"Get",
"SQL",
"insert",
"query"
] | train | https://github.com/neat-php/database/blob/7b4b66c8f1bc63e50925f12712b9eedcfb2a98ff/classes/Query.php#L563-L570 |
neat-php/database | classes/Query.php | Query.getUpdateQuery | public function getUpdateQuery()
{
$sql = 'UPDATE ' . $this->getTable();
$sql .= "\nSET " . $this->getSet();
if ($this->where) {
$sql .= "\nWHERE " . $this->getWhere();
}
if ($this->orderBy) {
$sql .= "\nORDER BY " . $this->getOrderBy();
}
if ($this->limit) {
$sql .= "\nLIMIT " . $this->getLimit();
}
return $sql;
} | php | public function getUpdateQuery()
{
$sql = 'UPDATE ' . $this->getTable();
$sql .= "\nSET " . $this->getSet();
if ($this->where) {
$sql .= "\nWHERE " . $this->getWhere();
}
if ($this->orderBy) {
$sql .= "\nORDER BY " . $this->getOrderBy();
}
if ($this->limit) {
$sql .= "\nLIMIT " . $this->getLimit();
}
return $sql;
} | [
"public",
"function",
"getUpdateQuery",
"(",
")",
"{",
"$",
"sql",
"=",
"'UPDATE '",
".",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"$",
"sql",
".=",
"\"\\nSET \"",
".",
"$",
"this",
"->",
"getSet",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"where",
")",
"{",
"$",
"sql",
".=",
"\"\\nWHERE \"",
".",
"$",
"this",
"->",
"getWhere",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"orderBy",
")",
"{",
"$",
"sql",
".=",
"\"\\nORDER BY \"",
".",
"$",
"this",
"->",
"getOrderBy",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"limit",
")",
"{",
"$",
"sql",
".=",
"\"\\nLIMIT \"",
".",
"$",
"this",
"->",
"getLimit",
"(",
")",
";",
"}",
"return",
"$",
"sql",
";",
"}"
] | Get SQL update query
@return string | [
"Get",
"SQL",
"update",
"query"
] | train | https://github.com/neat-php/database/blob/7b4b66c8f1bc63e50925f12712b9eedcfb2a98ff/classes/Query.php#L577-L592 |
neat-php/database | classes/Query.php | Query.getDeleteQuery | public function getDeleteQuery()
{
$sql = 'DELETE FROM ' . $this->getTable();
if ($this->where) {
$sql .= "\nWHERE " . $this->getWhere();
}
if ($this->limit) {
$sql .= "\nLIMIT " . $this->getLimit();
}
return $sql;
} | php | public function getDeleteQuery()
{
$sql = 'DELETE FROM ' . $this->getTable();
if ($this->where) {
$sql .= "\nWHERE " . $this->getWhere();
}
if ($this->limit) {
$sql .= "\nLIMIT " . $this->getLimit();
}
return $sql;
} | [
"public",
"function",
"getDeleteQuery",
"(",
")",
"{",
"$",
"sql",
"=",
"'DELETE FROM '",
".",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"where",
")",
"{",
"$",
"sql",
".=",
"\"\\nWHERE \"",
".",
"$",
"this",
"->",
"getWhere",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"limit",
")",
"{",
"$",
"sql",
".=",
"\"\\nLIMIT \"",
".",
"$",
"this",
"->",
"getLimit",
"(",
")",
";",
"}",
"return",
"$",
"sql",
";",
"}"
] | Get SQL delete query
@return string | [
"Get",
"SQL",
"delete",
"query"
] | train | https://github.com/neat-php/database/blob/7b4b66c8f1bc63e50925f12712b9eedcfb2a98ff/classes/Query.php#L599-L610 |
m4grio/bangkok-insurance-php | src/Client/BeansTrait.php | BeansTrait.mergeParams | public function mergeParams($method, Array $params = [])
{
$newParams = [];
$preparedParams = $this->defaultParams;
$preparedParams['bean'] = $params;
$newParams[$method] = $preparedParams;
return $newParams;
} | php | public function mergeParams($method, Array $params = [])
{
$newParams = [];
$preparedParams = $this->defaultParams;
$preparedParams['bean'] = $params;
$newParams[$method] = $preparedParams;
return $newParams;
} | [
"public",
"function",
"mergeParams",
"(",
"$",
"method",
",",
"Array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"newParams",
"=",
"[",
"]",
";",
"$",
"preparedParams",
"=",
"$",
"this",
"->",
"defaultParams",
";",
"$",
"preparedParams",
"[",
"'bean'",
"]",
"=",
"$",
"params",
";",
"$",
"newParams",
"[",
"$",
"method",
"]",
"=",
"$",
"preparedParams",
";",
"return",
"$",
"newParams",
";",
"}"
] | Group params in a bean
@param $method
@param array $params
@return array | [
"Group",
"params",
"in",
"a",
"bean"
] | train | https://github.com/m4grio/bangkok-insurance-php/blob/400266d043abe6b7cacb9da36064cbb169149c2a/src/Client/BeansTrait.php#L28-L37 |
i-lateral/silverstripe-modeladminplus | src/SearchContext.php | SearchContext.getSearchFields | public function getSearchFields()
{
$fields = parent::getSearchFields();
$class = $this->modelClass;
$use_autocomplete = $this->getConvertToAutocomplete();
$db = Config::inst()->get($class, "db");
$has_one = Config::inst()->get($class, "has_one");
$has_many = Config::inst()->get($class, "has_many");
$many_many = Config::inst()->get($class, "many_many");
$belongs_many_many = Config::inst()->get($class, "belongs_many_many");
$associations = array_merge(
$has_one,
$has_many,
$many_many,
$belongs_many_many
);
// Change currently scaffolded query fields to use conventional
// field names
/*foreach ($fields as $field) {
$field_class = $this->modelClass;
$name = $field->getName();
$title = $field->Title();
$db_field = $name;
$in_db = false;
// Find any text fields an replace with autocomplete fields
if (ClassInfo::class_name($field) == TextField::class && $use_autocomplete) {
// If this is a relation, switch class name
if (strpos($name, "__")) {
$parts = explode("__", $db_field);
$field_class = isset($associations[$parts[0]]) ? $associations[$parts[0]] : null;
$db_field = $parts[1];
$in_db = ($field_class) ? true : false;
}
// If this is in the DB (not casted)
if (in_array($db_field, array_keys($db))) {
$in_db = true;
}
if ($in_db) {
$fields->replaceField(
$name,
$field = AutoCompleteField::create(
$name,
$title,
$field->Value(),
$field_class,
$db_field
)->setDisplayField($db_field)
->setLabelField($db_field)
->setStoredField($db_field)
);
}
}
$field->setName($name);
}*/
return $fields;
} | php | public function getSearchFields()
{
$fields = parent::getSearchFields();
$class = $this->modelClass;
$use_autocomplete = $this->getConvertToAutocomplete();
$db = Config::inst()->get($class, "db");
$has_one = Config::inst()->get($class, "has_one");
$has_many = Config::inst()->get($class, "has_many");
$many_many = Config::inst()->get($class, "many_many");
$belongs_many_many = Config::inst()->get($class, "belongs_many_many");
$associations = array_merge(
$has_one,
$has_many,
$many_many,
$belongs_many_many
);
// Change currently scaffolded query fields to use conventional
// field names
/*foreach ($fields as $field) {
$field_class = $this->modelClass;
$name = $field->getName();
$title = $field->Title();
$db_field = $name;
$in_db = false;
// Find any text fields an replace with autocomplete fields
if (ClassInfo::class_name($field) == TextField::class && $use_autocomplete) {
// If this is a relation, switch class name
if (strpos($name, "__")) {
$parts = explode("__", $db_field);
$field_class = isset($associations[$parts[0]]) ? $associations[$parts[0]] : null;
$db_field = $parts[1];
$in_db = ($field_class) ? true : false;
}
// If this is in the DB (not casted)
if (in_array($db_field, array_keys($db))) {
$in_db = true;
}
if ($in_db) {
$fields->replaceField(
$name,
$field = AutoCompleteField::create(
$name,
$title,
$field->Value(),
$field_class,
$db_field
)->setDisplayField($db_field)
->setLabelField($db_field)
->setStoredField($db_field)
);
}
}
$field->setName($name);
}*/
return $fields;
} | [
"public",
"function",
"getSearchFields",
"(",
")",
"{",
"$",
"fields",
"=",
"parent",
"::",
"getSearchFields",
"(",
")",
";",
"$",
"class",
"=",
"$",
"this",
"->",
"modelClass",
";",
"$",
"use_autocomplete",
"=",
"$",
"this",
"->",
"getConvertToAutocomplete",
"(",
")",
";",
"$",
"db",
"=",
"Config",
"::",
"inst",
"(",
")",
"->",
"get",
"(",
"$",
"class",
",",
"\"db\"",
")",
";",
"$",
"has_one",
"=",
"Config",
"::",
"inst",
"(",
")",
"->",
"get",
"(",
"$",
"class",
",",
"\"has_one\"",
")",
";",
"$",
"has_many",
"=",
"Config",
"::",
"inst",
"(",
")",
"->",
"get",
"(",
"$",
"class",
",",
"\"has_many\"",
")",
";",
"$",
"many_many",
"=",
"Config",
"::",
"inst",
"(",
")",
"->",
"get",
"(",
"$",
"class",
",",
"\"many_many\"",
")",
";",
"$",
"belongs_many_many",
"=",
"Config",
"::",
"inst",
"(",
")",
"->",
"get",
"(",
"$",
"class",
",",
"\"belongs_many_many\"",
")",
";",
"$",
"associations",
"=",
"array_merge",
"(",
"$",
"has_one",
",",
"$",
"has_many",
",",
"$",
"many_many",
",",
"$",
"belongs_many_many",
")",
";",
"// Change currently scaffolded query fields to use conventional",
"// field names",
"/*foreach ($fields as $field) {\n $field_class = $this->modelClass;\n $name = $field->getName();\n $title = $field->Title();\n $db_field = $name;\n $in_db = false;\n\n // Find any text fields an replace with autocomplete fields\n if (ClassInfo::class_name($field) == TextField::class && $use_autocomplete) {\n // If this is a relation, switch class name\n if (strpos($name, \"__\")) {\n $parts = explode(\"__\", $db_field);\n $field_class = isset($associations[$parts[0]]) ? $associations[$parts[0]] : null;\n $db_field = $parts[1];\n $in_db = ($field_class) ? true : false;\n }\n\n // If this is in the DB (not casted)\n if (in_array($db_field, array_keys($db))) {\n $in_db = true;\n }\n\n if ($in_db) {\n $fields->replaceField(\n $name,\n $field = AutoCompleteField::create(\n $name,\n $title,\n $field->Value(),\n $field_class,\n $db_field\n )->setDisplayField($db_field)\n ->setLabelField($db_field)\n ->setStoredField($db_field)\n );\n }\n }\n\n $field->setName($name);\n }*/",
"return",
"$",
"fields",
";",
"}"
] | Extend default search fields and add extra functionality.
@return \SilverStripe\Forms\FieldList | [
"Extend",
"default",
"search",
"fields",
"and",
"add",
"extra",
"functionality",
"."
] | train | https://github.com/i-lateral/silverstripe-modeladminplus/blob/c5209d9610cdb36ddc7b9231fad342df7e75ffc0/src/SearchContext.php#L25-L87 |
nabab/bbn | src/bbn/file/ftp.php | ftp.scan | public function scan(string $dir, string $type = null, &$res = [], int $timeout = 0): array
{
$res = [];
if ( $dirs = $this->listFiles($dir) ){
foreach ( $dirs as $d ){
if ( $type &&
(strpos($type, 'file') === 0) &&
!isset($d['num']) ){
$res[] = $d['name'];
}
else if ( $type &&
((strpos($type, 'dir') === 0) || (strpos($type, 'fold') === 0)) &&
isset($d['num']) ){
$res[] = $d['name'];
}
else{
$res[] = $d['name'];
}
if ( isset($d['num']) ){
$this->scan($d['name'], $type, $res);
}
}
}
return $res;
} | php | public function scan(string $dir, string $type = null, &$res = [], int $timeout = 0): array
{
$res = [];
if ( $dirs = $this->listFiles($dir) ){
foreach ( $dirs as $d ){
if ( $type &&
(strpos($type, 'file') === 0) &&
!isset($d['num']) ){
$res[] = $d['name'];
}
else if ( $type &&
((strpos($type, 'dir') === 0) || (strpos($type, 'fold') === 0)) &&
isset($d['num']) ){
$res[] = $d['name'];
}
else{
$res[] = $d['name'];
}
if ( isset($d['num']) ){
$this->scan($d['name'], $type, $res);
}
}
}
return $res;
} | [
"public",
"function",
"scan",
"(",
"string",
"$",
"dir",
",",
"string",
"$",
"type",
"=",
"null",
",",
"&",
"$",
"res",
"=",
"[",
"]",
",",
"int",
"$",
"timeout",
"=",
"0",
")",
":",
"array",
"{",
"$",
"res",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"dirs",
"=",
"$",
"this",
"->",
"listFiles",
"(",
"$",
"dir",
")",
")",
"{",
"foreach",
"(",
"$",
"dirs",
"as",
"$",
"d",
")",
"{",
"if",
"(",
"$",
"type",
"&&",
"(",
"strpos",
"(",
"$",
"type",
",",
"'file'",
")",
"===",
"0",
")",
"&&",
"!",
"isset",
"(",
"$",
"d",
"[",
"'num'",
"]",
")",
")",
"{",
"$",
"res",
"[",
"]",
"=",
"$",
"d",
"[",
"'name'",
"]",
";",
"}",
"else",
"if",
"(",
"$",
"type",
"&&",
"(",
"(",
"strpos",
"(",
"$",
"type",
",",
"'dir'",
")",
"===",
"0",
")",
"||",
"(",
"strpos",
"(",
"$",
"type",
",",
"'fold'",
")",
"===",
"0",
")",
")",
"&&",
"isset",
"(",
"$",
"d",
"[",
"'num'",
"]",
")",
")",
"{",
"$",
"res",
"[",
"]",
"=",
"$",
"d",
"[",
"'name'",
"]",
";",
"}",
"else",
"{",
"$",
"res",
"[",
"]",
"=",
"$",
"d",
"[",
"'name'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"d",
"[",
"'num'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"scan",
"(",
"$",
"d",
"[",
"'name'",
"]",
",",
"$",
"type",
",",
"$",
"res",
")",
";",
"}",
"}",
"}",
"return",
"$",
"res",
";",
"}"
] | Scans all the content from a directory, including the subdirectories
<code>
bbn\file\dir::scan("/home/me");
bbn\file\dir::delete("C:\Documents\Test");
</code>
@param string $dir The directory path.
@param string $type The type of item to return ('file', 'dir', default is both)
@return array | [
"Scans",
"all",
"the",
"content",
"from",
"a",
"directory",
"including",
"the",
"subdirectories"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/ftp.php#L164-L188 |
nabab/bbn | src/bbn/file/ftp.php | ftp.delete | public function delete($item){
self::log('delete:'.$item);
if ( $this->checkFilePath($item) &&
ftp_delete($this->cn,$item) ){
return true;
}
return false;
} | php | public function delete($item){
self::log('delete:'.$item);
if ( $this->checkFilePath($item) &&
ftp_delete($this->cn,$item) ){
return true;
}
return false;
} | [
"public",
"function",
"delete",
"(",
"$",
"item",
")",
"{",
"self",
"::",
"log",
"(",
"'delete:'",
".",
"$",
"item",
")",
";",
"if",
"(",
"$",
"this",
"->",
"checkFilePath",
"(",
"$",
"item",
")",
"&&",
"ftp_delete",
"(",
"$",
"this",
"->",
"cn",
",",
"$",
"item",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Deletes a file from the server
@return boolean | [
"Deletes",
"a",
"file",
"from",
"the",
"server"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/ftp.php#L323-L330 |
nabab/bbn | src/bbn/file/ftp.php | ftp.put | public function put($src, $dest){
if ( file_exists($src) &&
($dest = $this->checkFilePath($dest)) &&
ftp_put($this->cn,$dest,$src,FTP_BINARY) ){
return true;
}
return false;
} | php | public function put($src, $dest){
if ( file_exists($src) &&
($dest = $this->checkFilePath($dest)) &&
ftp_put($this->cn,$dest,$src,FTP_BINARY) ){
return true;
}
return false;
} | [
"public",
"function",
"put",
"(",
"$",
"src",
",",
"$",
"dest",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"src",
")",
"&&",
"(",
"$",
"dest",
"=",
"$",
"this",
"->",
"checkFilePath",
"(",
"$",
"dest",
")",
")",
"&&",
"ftp_put",
"(",
"$",
"this",
"->",
"cn",
",",
"$",
"dest",
",",
"$",
"src",
",",
"FTP_BINARY",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Puts a file on the server
@return boolean | [
"Puts",
"a",
"file",
"on",
"the",
"server"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/ftp.php#L337-L344 |
nabab/bbn | src/bbn/file/ftp.php | ftp.get | public function get($src, $dest){
if ( $src = $this->checkFilePath($src) &&
ftp_get($this->cn, $dest, $src, FTP_BINARY) ){
return true;
}
return false;
} | php | public function get($src, $dest){
if ( $src = $this->checkFilePath($src) &&
ftp_get($this->cn, $dest, $src, FTP_BINARY) ){
return true;
}
return false;
} | [
"public",
"function",
"get",
"(",
"$",
"src",
",",
"$",
"dest",
")",
"{",
"if",
"(",
"$",
"src",
"=",
"$",
"this",
"->",
"checkFilePath",
"(",
"$",
"src",
")",
"&&",
"ftp_get",
"(",
"$",
"this",
"->",
"cn",
",",
"$",
"dest",
",",
"$",
"src",
",",
"FTP_BINARY",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Gets a file from the server
@return boolean | [
"Gets",
"a",
"file",
"from",
"the",
"server"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/ftp.php#L351-L357 |
nabab/bbn | src/bbn/file/ftp.php | ftp.move | public function move(string $old, string $new){
if (
!empty($old) &&
!empty($new) &&
($old = $this->checkFilePath($old)) &&
ftp_rename($this->cn, $old, $new)
){
return true;
}
return false;
} | php | public function move(string $old, string $new){
if (
!empty($old) &&
!empty($new) &&
($old = $this->checkFilePath($old)) &&
ftp_rename($this->cn, $old, $new)
){
return true;
}
return false;
} | [
"public",
"function",
"move",
"(",
"string",
"$",
"old",
",",
"string",
"$",
"new",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"old",
")",
"&&",
"!",
"empty",
"(",
"$",
"new",
")",
"&&",
"(",
"$",
"old",
"=",
"$",
"this",
"->",
"checkFilePath",
"(",
"$",
"old",
")",
")",
"&&",
"ftp_rename",
"(",
"$",
"this",
"->",
"cn",
",",
"$",
"old",
",",
"$",
"new",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Moves or renames a file on the server
@param string $old The old file full path
@param string $new The new file full path
@return bool | [
"Moves",
"or",
"renames",
"a",
"file",
"on",
"the",
"server"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/ftp.php#L373-L383 |
nabab/bbn | src/bbn/file/ftp.php | ftp.exists | public function exists(string $path){
if ( !empty($path) ){
$dir = dirname($path);
$ext = \bbn\str::file_ext($path);
$file = basename($path);
if ( \is_array($files = $this->listFiles($dir)) ){
foreach ( $files as $f ){
if ( $f['basename'] === $file ){
return true;
}
}
}
}
return false;
} | php | public function exists(string $path){
if ( !empty($path) ){
$dir = dirname($path);
$ext = \bbn\str::file_ext($path);
$file = basename($path);
if ( \is_array($files = $this->listFiles($dir)) ){
foreach ( $files as $f ){
if ( $f['basename'] === $file ){
return true;
}
}
}
}
return false;
} | [
"public",
"function",
"exists",
"(",
"string",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"path",
")",
")",
"{",
"$",
"dir",
"=",
"dirname",
"(",
"$",
"path",
")",
";",
"$",
"ext",
"=",
"\\",
"bbn",
"\\",
"str",
"::",
"file_ext",
"(",
"$",
"path",
")",
";",
"$",
"file",
"=",
"basename",
"(",
"$",
"path",
")",
";",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"files",
"=",
"$",
"this",
"->",
"listFiles",
"(",
"$",
"dir",
")",
")",
")",
"{",
"foreach",
"(",
"$",
"files",
"as",
"$",
"f",
")",
"{",
"if",
"(",
"$",
"f",
"[",
"'basename'",
"]",
"===",
"$",
"file",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] | Checks if a file is present in a folder on the server
@param string $path The file or dir relative or full path
@return bool | [
"Checks",
"if",
"a",
"file",
"is",
"present",
"in",
"a",
"folder",
"on",
"the",
"server"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/ftp.php#L391-L405 |
php-lug/lug | src/Bundle/GridBundle/Form/Validator/GridSortingValidator.php | GridSortingValidator.validate | public function validate($value, Constraint $constraint)
{
foreach ($value as $column => $order) {
if (!$constraint->grid->hasSort($column)) {
$this->context->buildViolation($constraint->message)
->setParameter('%column%', $column)
->addViolation();
}
}
} | php | public function validate($value, Constraint $constraint)
{
foreach ($value as $column => $order) {
if (!$constraint->grid->hasSort($column)) {
$this->context->buildViolation($constraint->message)
->setParameter('%column%', $column)
->addViolation();
}
}
} | [
"public",
"function",
"validate",
"(",
"$",
"value",
",",
"Constraint",
"$",
"constraint",
")",
"{",
"foreach",
"(",
"$",
"value",
"as",
"$",
"column",
"=>",
"$",
"order",
")",
"{",
"if",
"(",
"!",
"$",
"constraint",
"->",
"grid",
"->",
"hasSort",
"(",
"$",
"column",
")",
")",
"{",
"$",
"this",
"->",
"context",
"->",
"buildViolation",
"(",
"$",
"constraint",
"->",
"message",
")",
"->",
"setParameter",
"(",
"'%column%'",
",",
"$",
"column",
")",
"->",
"addViolation",
"(",
")",
";",
"}",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/GridBundle/Form/Validator/GridSortingValidator.php#L25-L34 |
technote-space/wordpress-plugin-base | src/classes/models/lib/setting.php | Setting.initialize | protected function initialize() {
$data = $this->apply_filters( 'initialize_setting', $this->app->config->load( 'setting' ) );
ksort( $data );
foreach ( $data as $group_priority => $groups ) {
foreach ( $groups as $group => $setting_set ) {
ksort( $setting_set );
$this->_groups[ $group_priority ][ $group ] = [];
$this->_group_priority[ $group ] = $group_priority;
foreach ( $setting_set as $setting_priority => $settings ) {
$this->_groups[ $group_priority ][ $group ] = array_merge( $this->_groups[ $group_priority ][ $group ], array_keys( $settings ) );
foreach ( $settings as $setting => $detail ) {
$this->_settings[ $setting_priority ][ $setting ] = $detail;
$this->_setting_priority[ $setting ] = $setting_priority;
}
}
}
}
} | php | protected function initialize() {
$data = $this->apply_filters( 'initialize_setting', $this->app->config->load( 'setting' ) );
ksort( $data );
foreach ( $data as $group_priority => $groups ) {
foreach ( $groups as $group => $setting_set ) {
ksort( $setting_set );
$this->_groups[ $group_priority ][ $group ] = [];
$this->_group_priority[ $group ] = $group_priority;
foreach ( $setting_set as $setting_priority => $settings ) {
$this->_groups[ $group_priority ][ $group ] = array_merge( $this->_groups[ $group_priority ][ $group ], array_keys( $settings ) );
foreach ( $settings as $setting => $detail ) {
$this->_settings[ $setting_priority ][ $setting ] = $detail;
$this->_setting_priority[ $setting ] = $setting_priority;
}
}
}
}
} | [
"protected",
"function",
"initialize",
"(",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"apply_filters",
"(",
"'initialize_setting'",
",",
"$",
"this",
"->",
"app",
"->",
"config",
"->",
"load",
"(",
"'setting'",
")",
")",
";",
"ksort",
"(",
"$",
"data",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"group_priority",
"=>",
"$",
"groups",
")",
"{",
"foreach",
"(",
"$",
"groups",
"as",
"$",
"group",
"=>",
"$",
"setting_set",
")",
"{",
"ksort",
"(",
"$",
"setting_set",
")",
";",
"$",
"this",
"->",
"_groups",
"[",
"$",
"group_priority",
"]",
"[",
"$",
"group",
"]",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"_group_priority",
"[",
"$",
"group",
"]",
"=",
"$",
"group_priority",
";",
"foreach",
"(",
"$",
"setting_set",
"as",
"$",
"setting_priority",
"=>",
"$",
"settings",
")",
"{",
"$",
"this",
"->",
"_groups",
"[",
"$",
"group_priority",
"]",
"[",
"$",
"group",
"]",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"_groups",
"[",
"$",
"group_priority",
"]",
"[",
"$",
"group",
"]",
",",
"array_keys",
"(",
"$",
"settings",
")",
")",
";",
"foreach",
"(",
"$",
"settings",
"as",
"$",
"setting",
"=>",
"$",
"detail",
")",
"{",
"$",
"this",
"->",
"_settings",
"[",
"$",
"setting_priority",
"]",
"[",
"$",
"setting",
"]",
"=",
"$",
"detail",
";",
"$",
"this",
"->",
"_setting_priority",
"[",
"$",
"setting",
"]",
"=",
"$",
"setting_priority",
";",
"}",
"}",
"}",
"}",
"}"
] | initialize | [
"initialize"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/setting.php#L57-L76 |
technote-space/wordpress-plugin-base | src/classes/models/lib/setting.php | Setting.get_settings | public function get_settings( $group ) {
if ( ! isset( $this->_group_priority[ $group ], $this->_groups[ $this->_group_priority[ $group ] ] ) ) {
return $this->apply_filters( 'get_settings', [], $group );
}
return $this->apply_filters( 'get_settings', $this->_groups[ $this->_group_priority[ $group ] ][ $group ], $group );
} | php | public function get_settings( $group ) {
if ( ! isset( $this->_group_priority[ $group ], $this->_groups[ $this->_group_priority[ $group ] ] ) ) {
return $this->apply_filters( 'get_settings', [], $group );
}
return $this->apply_filters( 'get_settings', $this->_groups[ $this->_group_priority[ $group ] ][ $group ], $group );
} | [
"public",
"function",
"get_settings",
"(",
"$",
"group",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_group_priority",
"[",
"$",
"group",
"]",
",",
"$",
"this",
"->",
"_groups",
"[",
"$",
"this",
"->",
"_group_priority",
"[",
"$",
"group",
"]",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"apply_filters",
"(",
"'get_settings'",
",",
"[",
"]",
",",
"$",
"group",
")",
";",
"}",
"return",
"$",
"this",
"->",
"apply_filters",
"(",
"'get_settings'",
",",
"$",
"this",
"->",
"_groups",
"[",
"$",
"this",
"->",
"_group_priority",
"[",
"$",
"group",
"]",
"]",
"[",
"$",
"group",
"]",
",",
"$",
"group",
")",
";",
"}"
] | @param string $group
@return array | [
"@param",
"string",
"$group"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/setting.php#L90-L96 |
technote-space/wordpress-plugin-base | src/classes/models/lib/setting.php | Setting.get_setting | public function get_setting( $setting, $detail = false ) {
if ( ! $this->is_setting( $setting ) ) {
return $this->apply_filters( 'get_setting', false, $setting, $detail );
}
$data = $this->apply_filters( 'get_setting', $this->_settings[ $this->_setting_priority[ $setting ] ][ $setting ], $setting );
if ( $detail ) {
$data = $this->get_detail_setting( $setting, $data );
}
return $data;
} | php | public function get_setting( $setting, $detail = false ) {
if ( ! $this->is_setting( $setting ) ) {
return $this->apply_filters( 'get_setting', false, $setting, $detail );
}
$data = $this->apply_filters( 'get_setting', $this->_settings[ $this->_setting_priority[ $setting ] ][ $setting ], $setting );
if ( $detail ) {
$data = $this->get_detail_setting( $setting, $data );
}
return $data;
} | [
"public",
"function",
"get_setting",
"(",
"$",
"setting",
",",
"$",
"detail",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"is_setting",
"(",
"$",
"setting",
")",
")",
"{",
"return",
"$",
"this",
"->",
"apply_filters",
"(",
"'get_setting'",
",",
"false",
",",
"$",
"setting",
",",
"$",
"detail",
")",
";",
"}",
"$",
"data",
"=",
"$",
"this",
"->",
"apply_filters",
"(",
"'get_setting'",
",",
"$",
"this",
"->",
"_settings",
"[",
"$",
"this",
"->",
"_setting_priority",
"[",
"$",
"setting",
"]",
"]",
"[",
"$",
"setting",
"]",
",",
"$",
"setting",
")",
";",
"if",
"(",
"$",
"detail",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"get_detail_setting",
"(",
"$",
"setting",
",",
"$",
"data",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | @param string $setting
@param bool $detail
@return array|false | [
"@param",
"string",
"$setting",
"@param",
"bool",
"$detail"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/setting.php#L104-L115 |
technote-space/wordpress-plugin-base | src/classes/models/lib/setting.php | Setting.remove_setting | public function remove_setting( $setting ) {
if ( ! $this->is_setting( $setting ) ) {
return true;
}
$priority = $this->_setting_priority[ $setting ];
unset( $this->_settings[ $priority ][ $setting ] );
unset( $this->_setting_priority[ $setting ] );
if ( empty( $this->_settings[ $priority ] ) ) {
unset( $this->_settings[ $priority ] );
}
foreach ( $this->_groups as $group_priority => $groups ) {
foreach ( $groups as $group => $settings ) {
$key = array_search( $setting, $settings );
if ( false !== $key ) {
unset( $this->_groups[ $group_priority ][ $group ][ $key ] );
if ( empty( $this->_groups[ $group_priority ][ $group ] ) ) {
unset( $this->_groups[ $group_priority ][ $group ] );
unset( $this->_group_priority[ $group ] );
if ( empty( $this->_groups[ $group_priority ] ) ) {
unset( $this->_groups[ $group_priority ] );
}
}
break;
}
}
}
return true;
} | php | public function remove_setting( $setting ) {
if ( ! $this->is_setting( $setting ) ) {
return true;
}
$priority = $this->_setting_priority[ $setting ];
unset( $this->_settings[ $priority ][ $setting ] );
unset( $this->_setting_priority[ $setting ] );
if ( empty( $this->_settings[ $priority ] ) ) {
unset( $this->_settings[ $priority ] );
}
foreach ( $this->_groups as $group_priority => $groups ) {
foreach ( $groups as $group => $settings ) {
$key = array_search( $setting, $settings );
if ( false !== $key ) {
unset( $this->_groups[ $group_priority ][ $group ][ $key ] );
if ( empty( $this->_groups[ $group_priority ][ $group ] ) ) {
unset( $this->_groups[ $group_priority ][ $group ] );
unset( $this->_group_priority[ $group ] );
if ( empty( $this->_groups[ $group_priority ] ) ) {
unset( $this->_groups[ $group_priority ] );
}
}
break;
}
}
}
return true;
} | [
"public",
"function",
"remove_setting",
"(",
"$",
"setting",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"is_setting",
"(",
"$",
"setting",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"priority",
"=",
"$",
"this",
"->",
"_setting_priority",
"[",
"$",
"setting",
"]",
";",
"unset",
"(",
"$",
"this",
"->",
"_settings",
"[",
"$",
"priority",
"]",
"[",
"$",
"setting",
"]",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"_setting_priority",
"[",
"$",
"setting",
"]",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_settings",
"[",
"$",
"priority",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"_settings",
"[",
"$",
"priority",
"]",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"_groups",
"as",
"$",
"group_priority",
"=>",
"$",
"groups",
")",
"{",
"foreach",
"(",
"$",
"groups",
"as",
"$",
"group",
"=>",
"$",
"settings",
")",
"{",
"$",
"key",
"=",
"array_search",
"(",
"$",
"setting",
",",
"$",
"settings",
")",
";",
"if",
"(",
"false",
"!==",
"$",
"key",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"_groups",
"[",
"$",
"group_priority",
"]",
"[",
"$",
"group",
"]",
"[",
"$",
"key",
"]",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_groups",
"[",
"$",
"group_priority",
"]",
"[",
"$",
"group",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"_groups",
"[",
"$",
"group_priority",
"]",
"[",
"$",
"group",
"]",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"_group_priority",
"[",
"$",
"group",
"]",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_groups",
"[",
"$",
"group_priority",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"_groups",
"[",
"$",
"group_priority",
"]",
")",
";",
"}",
"}",
"break",
";",
"}",
"}",
"}",
"return",
"true",
";",
"}"
] | @param string $setting
@return bool | [
"@param",
"string",
"$setting"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/setting.php#L122-L151 |
technote-space/wordpress-plugin-base | src/classes/models/lib/setting.php | Setting.edit_setting | public function edit_setting( $setting, $key, $value ) {
if ( ! $this->is_setting( $setting ) ) {
return true;
}
$priority = $this->_setting_priority[ $setting ];
$this->_settings[ $priority ][ $setting ][ $key ] = $value;
return true;
} | php | public function edit_setting( $setting, $key, $value ) {
if ( ! $this->is_setting( $setting ) ) {
return true;
}
$priority = $this->_setting_priority[ $setting ];
$this->_settings[ $priority ][ $setting ][ $key ] = $value;
return true;
} | [
"public",
"function",
"edit_setting",
"(",
"$",
"setting",
",",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"is_setting",
"(",
"$",
"setting",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"priority",
"=",
"$",
"this",
"->",
"_setting_priority",
"[",
"$",
"setting",
"]",
";",
"$",
"this",
"->",
"_settings",
"[",
"$",
"priority",
"]",
"[",
"$",
"setting",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"return",
"true",
";",
"}"
] | @since 2.1.0
@param string $setting
@param string $key
@param mixed $value
@return bool | [
"@since",
"2",
".",
"1",
".",
"0"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/setting.php#L162-L170 |
technote-space/wordpress-plugin-base | src/classes/models/lib/setting.php | Setting.get_detail_setting | private function get_detail_setting( $setting, $data ) {
$data['key'] = $setting;
$type = $this->app->utility->array_get( $data, 'type', '' );
$default = $this->app->utility->array_get( $data, 'default', '' );
if ( is_callable( $default ) ) {
$default = $default( $this->app );
}
$default = $this->get_expression( $default, $type );
if ( ! empty( $data['translate'] ) ) {
$default = $this->app->translate( $default );
}
$data['info'] = [];
if ( '' !== $default ) {
$data['info'][] = $this->app->translate( 'default' ) . ' = ' . $default;
}
if ( isset( $data['min'] ) ) {
$data['info'][] = $this->app->translate( 'min' ) . ' = ' . $this->get_expression( $data['min'], $type );
}
if ( isset( $data['max'] ) ) {
$data['info'][] = $this->app->translate( 'max' ) . ' = ' . $this->get_expression( $data['max'], $type );
}
$data['name'] = $this->get_filter_prefix() . $data['key'];
$data['saved'] = $this->app->get_option( $data['name'] );
$data['placeholder'] = $default;
$value = $this->apply_filters( $data['key'], $default );
$data['value'] = $value;
$data['used'] = $this->get_expression( $value, $type );
return $data;
} | php | private function get_detail_setting( $setting, $data ) {
$data['key'] = $setting;
$type = $this->app->utility->array_get( $data, 'type', '' );
$default = $this->app->utility->array_get( $data, 'default', '' );
if ( is_callable( $default ) ) {
$default = $default( $this->app );
}
$default = $this->get_expression( $default, $type );
if ( ! empty( $data['translate'] ) ) {
$default = $this->app->translate( $default );
}
$data['info'] = [];
if ( '' !== $default ) {
$data['info'][] = $this->app->translate( 'default' ) . ' = ' . $default;
}
if ( isset( $data['min'] ) ) {
$data['info'][] = $this->app->translate( 'min' ) . ' = ' . $this->get_expression( $data['min'], $type );
}
if ( isset( $data['max'] ) ) {
$data['info'][] = $this->app->translate( 'max' ) . ' = ' . $this->get_expression( $data['max'], $type );
}
$data['name'] = $this->get_filter_prefix() . $data['key'];
$data['saved'] = $this->app->get_option( $data['name'] );
$data['placeholder'] = $default;
$value = $this->apply_filters( $data['key'], $default );
$data['value'] = $value;
$data['used'] = $this->get_expression( $value, $type );
return $data;
} | [
"private",
"function",
"get_detail_setting",
"(",
"$",
"setting",
",",
"$",
"data",
")",
"{",
"$",
"data",
"[",
"'key'",
"]",
"=",
"$",
"setting",
";",
"$",
"type",
"=",
"$",
"this",
"->",
"app",
"->",
"utility",
"->",
"array_get",
"(",
"$",
"data",
",",
"'type'",
",",
"''",
")",
";",
"$",
"default",
"=",
"$",
"this",
"->",
"app",
"->",
"utility",
"->",
"array_get",
"(",
"$",
"data",
",",
"'default'",
",",
"''",
")",
";",
"if",
"(",
"is_callable",
"(",
"$",
"default",
")",
")",
"{",
"$",
"default",
"=",
"$",
"default",
"(",
"$",
"this",
"->",
"app",
")",
";",
"}",
"$",
"default",
"=",
"$",
"this",
"->",
"get_expression",
"(",
"$",
"default",
",",
"$",
"type",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
"[",
"'translate'",
"]",
")",
")",
"{",
"$",
"default",
"=",
"$",
"this",
"->",
"app",
"->",
"translate",
"(",
"$",
"default",
")",
";",
"}",
"$",
"data",
"[",
"'info'",
"]",
"=",
"[",
"]",
";",
"if",
"(",
"''",
"!==",
"$",
"default",
")",
"{",
"$",
"data",
"[",
"'info'",
"]",
"[",
"]",
"=",
"$",
"this",
"->",
"app",
"->",
"translate",
"(",
"'default'",
")",
".",
"' = '",
".",
"$",
"default",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'min'",
"]",
")",
")",
"{",
"$",
"data",
"[",
"'info'",
"]",
"[",
"]",
"=",
"$",
"this",
"->",
"app",
"->",
"translate",
"(",
"'min'",
")",
".",
"' = '",
".",
"$",
"this",
"->",
"get_expression",
"(",
"$",
"data",
"[",
"'min'",
"]",
",",
"$",
"type",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'max'",
"]",
")",
")",
"{",
"$",
"data",
"[",
"'info'",
"]",
"[",
"]",
"=",
"$",
"this",
"->",
"app",
"->",
"translate",
"(",
"'max'",
")",
".",
"' = '",
".",
"$",
"this",
"->",
"get_expression",
"(",
"$",
"data",
"[",
"'max'",
"]",
",",
"$",
"type",
")",
";",
"}",
"$",
"data",
"[",
"'name'",
"]",
"=",
"$",
"this",
"->",
"get_filter_prefix",
"(",
")",
".",
"$",
"data",
"[",
"'key'",
"]",
";",
"$",
"data",
"[",
"'saved'",
"]",
"=",
"$",
"this",
"->",
"app",
"->",
"get_option",
"(",
"$",
"data",
"[",
"'name'",
"]",
")",
";",
"$",
"data",
"[",
"'placeholder'",
"]",
"=",
"$",
"default",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"apply_filters",
"(",
"$",
"data",
"[",
"'key'",
"]",
",",
"$",
"default",
")",
";",
"$",
"data",
"[",
"'value'",
"]",
"=",
"$",
"value",
";",
"$",
"data",
"[",
"'used'",
"]",
"=",
"$",
"this",
"->",
"get_expression",
"(",
"$",
"value",
",",
"$",
"type",
")",
";",
"return",
"$",
"data",
";",
"}"
] | @param string $setting
@param array $data
@return array | [
"@param",
"string",
"$setting",
"@param",
"array",
"$data"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/setting.php#L178-L207 |
technote-space/wordpress-plugin-base | src/classes/models/lib/setting.php | Setting.get_expression | private function get_expression( $value, $type ) {
switch ( $type ) {
case 'bool':
return var_export( $value, true );
case 'int':
return $value;
case 'float':
return round( $value, 6 );
default:
return $value;
}
} | php | private function get_expression( $value, $type ) {
switch ( $type ) {
case 'bool':
return var_export( $value, true );
case 'int':
return $value;
case 'float':
return round( $value, 6 );
default:
return $value;
}
} | [
"private",
"function",
"get_expression",
"(",
"$",
"value",
",",
"$",
"type",
")",
"{",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'bool'",
":",
"return",
"var_export",
"(",
"$",
"value",
",",
"true",
")",
";",
"case",
"'int'",
":",
"return",
"$",
"value",
";",
"case",
"'float'",
":",
"return",
"round",
"(",
"$",
"value",
",",
"6",
")",
";",
"default",
":",
"return",
"$",
"value",
";",
"}",
"}"
] | @param $value
@param $type
@return mixed | [
"@param",
"$value",
"@param",
"$type"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/setting.php#L215-L226 |
technote-space/wordpress-plugin-base | src/classes/models/lib/setting.php | Setting.is_setting | public function is_setting( $setting ) {
return isset( $this->_setting_priority[ $setting ], $this->_settings[ $this->_setting_priority[ $setting ] ] );
} | php | public function is_setting( $setting ) {
return isset( $this->_setting_priority[ $setting ], $this->_settings[ $this->_setting_priority[ $setting ] ] );
} | [
"public",
"function",
"is_setting",
"(",
"$",
"setting",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"_setting_priority",
"[",
"$",
"setting",
"]",
",",
"$",
"this",
"->",
"_settings",
"[",
"$",
"this",
"->",
"_setting_priority",
"[",
"$",
"setting",
"]",
"]",
")",
";",
"}"
] | @param string $setting
@return bool | [
"@param",
"string",
"$setting"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/setting.php#L233-L235 |
j-d/draggy | src/Draggy/Utils/Indenter/AbstractLineIndenter.php | AbstractLineIndenter.findEndStandardBlock | protected function findEndStandardBlock($name, $lineNumber, $maxLine, $targetStepsInto = 0)
{
$stepsInto = 0;
for ($i = $lineNumber; $i <= $maxLine; $i++) {
if ($this->lineTypes['end' . $name][$i] && $i > $lineNumber) {
$stepsInto--;
if ($stepsInto === $targetStepsInto) {
return $i;
}
}
if ($this->lineTypes['start' . $name][$i]) {
$stepsInto++;
}
}
throw new \RuntimeException('Cannot find the end of the ' . $name . ' block starting in line ' . $lineNumber . ' (' . $this->indenterMachine->getLine($lineNumber) . ')');
} | php | protected function findEndStandardBlock($name, $lineNumber, $maxLine, $targetStepsInto = 0)
{
$stepsInto = 0;
for ($i = $lineNumber; $i <= $maxLine; $i++) {
if ($this->lineTypes['end' . $name][$i] && $i > $lineNumber) {
$stepsInto--;
if ($stepsInto === $targetStepsInto) {
return $i;
}
}
if ($this->lineTypes['start' . $name][$i]) {
$stepsInto++;
}
}
throw new \RuntimeException('Cannot find the end of the ' . $name . ' block starting in line ' . $lineNumber . ' (' . $this->indenterMachine->getLine($lineNumber) . ')');
} | [
"protected",
"function",
"findEndStandardBlock",
"(",
"$",
"name",
",",
"$",
"lineNumber",
",",
"$",
"maxLine",
",",
"$",
"targetStepsInto",
"=",
"0",
")",
"{",
"$",
"stepsInto",
"=",
"0",
";",
"for",
"(",
"$",
"i",
"=",
"$",
"lineNumber",
";",
"$",
"i",
"<=",
"$",
"maxLine",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"lineTypes",
"[",
"'end'",
".",
"$",
"name",
"]",
"[",
"$",
"i",
"]",
"&&",
"$",
"i",
">",
"$",
"lineNumber",
")",
"{",
"$",
"stepsInto",
"--",
";",
"if",
"(",
"$",
"stepsInto",
"===",
"$",
"targetStepsInto",
")",
"{",
"return",
"$",
"i",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"lineTypes",
"[",
"'start'",
".",
"$",
"name",
"]",
"[",
"$",
"i",
"]",
")",
"{",
"$",
"stepsInto",
"++",
";",
"}",
"}",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Cannot find the end of the '",
".",
"$",
"name",
".",
"' block starting in line '",
".",
"$",
"lineNumber",
".",
"' ('",
".",
"$",
"this",
"->",
"indenterMachine",
"->",
"getLine",
"(",
"$",
"lineNumber",
")",
".",
"')'",
")",
";",
"}"
] | Generic algorithm to find the end of a block
@param string $name Name of the block
@param int $lineNumber Starting line
@param int $maxLine Max line
@param int $targetStepsInto Targets steps into the source code, used as a stop criteria
@return int
@throws \RuntimeException | [
"Generic",
"algorithm",
"to",
"find",
"the",
"end",
"of",
"a",
"block"
] | train | https://github.com/j-d/draggy/blob/97ffc66e1aacb5f685d7aac5251c4abb8888d4bb/src/Draggy/Utils/Indenter/AbstractLineIndenter.php#L72-L91 |
j-d/draggy | src/Draggy/Utils/Indenter/AbstractLineIndenter.php | AbstractLineIndenter.indent | public function indent()
{
$this->identifyLines();
$endLine = count($this->indenterMachine->getLines()) - 1;
if ($endLine < 0) {
return;
}
foreach ($this->rules as $rulePass) {
for ($i = 0; $i <= $endLine; $i++) {
foreach ($rulePass as $rule) {
$rule($i, $endLine);
}
}
}
} | php | public function indent()
{
$this->identifyLines();
$endLine = count($this->indenterMachine->getLines()) - 1;
if ($endLine < 0) {
return;
}
foreach ($this->rules as $rulePass) {
for ($i = 0; $i <= $endLine; $i++) {
foreach ($rulePass as $rule) {
$rule($i, $endLine);
}
}
}
} | [
"public",
"function",
"indent",
"(",
")",
"{",
"$",
"this",
"->",
"identifyLines",
"(",
")",
";",
"$",
"endLine",
"=",
"count",
"(",
"$",
"this",
"->",
"indenterMachine",
"->",
"getLines",
"(",
")",
")",
"-",
"1",
";",
"if",
"(",
"$",
"endLine",
"<",
"0",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"rules",
"as",
"$",
"rulePass",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<=",
"$",
"endLine",
";",
"$",
"i",
"++",
")",
"{",
"foreach",
"(",
"$",
"rulePass",
"as",
"$",
"rule",
")",
"{",
"$",
"rule",
"(",
"$",
"i",
",",
"$",
"endLine",
")",
";",
"}",
"}",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/j-d/draggy/blob/97ffc66e1aacb5f685d7aac5251c4abb8888d4bb/src/Draggy/Utils/Indenter/AbstractLineIndenter.php#L108-L125 |
mothership-ec/composer | src/Composer/DependencyResolver/Rule.php | Rule.equals | public function equals(Rule $rule)
{
if ($this->ruleHash !== $rule->ruleHash) {
return false;
}
if (count($this->literals) != count($rule->literals)) {
return false;
}
for ($i = 0, $n = count($this->literals); $i < $n; $i++) {
if ($this->literals[$i] !== $rule->literals[$i]) {
return false;
}
}
return true;
} | php | public function equals(Rule $rule)
{
if ($this->ruleHash !== $rule->ruleHash) {
return false;
}
if (count($this->literals) != count($rule->literals)) {
return false;
}
for ($i = 0, $n = count($this->literals); $i < $n; $i++) {
if ($this->literals[$i] !== $rule->literals[$i]) {
return false;
}
}
return true;
} | [
"public",
"function",
"equals",
"(",
"Rule",
"$",
"rule",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"ruleHash",
"!==",
"$",
"rule",
"->",
"ruleHash",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"literals",
")",
"!=",
"count",
"(",
"$",
"rule",
"->",
"literals",
")",
")",
"{",
"return",
"false",
";",
"}",
"for",
"(",
"$",
"i",
"=",
"0",
",",
"$",
"n",
"=",
"count",
"(",
"$",
"this",
"->",
"literals",
")",
";",
"$",
"i",
"<",
"$",
"n",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"literals",
"[",
"$",
"i",
"]",
"!==",
"$",
"rule",
"->",
"literals",
"[",
"$",
"i",
"]",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Checks if this rule is equal to another one
Ignores whether either of the rules is disabled.
@param Rule $rule The rule to check against
@return bool Whether the rules are equal | [
"Checks",
"if",
"this",
"rule",
"is",
"equal",
"to",
"another",
"one"
] | train | https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/DependencyResolver/Rule.php#L115-L132 |
oroinc/OroLayoutComponent | Block/Type/BaseType.php | BaseType.buildView | public function buildView(BlockView $view, BlockInterface $block, Options $options)
{
BlockUtils::setViewVarsFromOptions(
$view,
$options,
['visible', 'translation_domain', 'additional_block_prefixes', 'class_prefix']
);
// merge the passed variables with the existing ones
if (!empty($options['vars'])) {
foreach ($options['vars'] as $name => $value) {
$view->vars[$name] = $value;
}
}
// replace attributes if specified ('attr' variable always exists in a view because it is added by FormView)
if (isset($options['attr'])) {
$view->vars['attr'] = $options['attr'];
}
// add label text and attributes if specified
if (isset($options['label'])) {
$view->vars['label'] = $options->get('label', false);
$view->vars['label_attr'] = [];
if (isset($options['label_attr'])) {
$view->vars['label_attr'] = $options->get('label_attr', false);
}
}
// add core variables to the block view, like id, block type and variables required for rendering engine
$view->vars['id'] = $block->getId();
$view->vars['block_type_widget_id'] = $block->getTypeName() . '_widget';
$view->vars['block_type'] = $block->getTypeName();
$view->vars['unique_block_prefix'] = '_' . preg_replace('/[^a-z0-9_]+/i', '_', $block->getId());
$view->vars['cache_key'] = sprintf('_%s_%s', $block->getId(), $block->getTypeName());
} | php | public function buildView(BlockView $view, BlockInterface $block, Options $options)
{
BlockUtils::setViewVarsFromOptions(
$view,
$options,
['visible', 'translation_domain', 'additional_block_prefixes', 'class_prefix']
);
// merge the passed variables with the existing ones
if (!empty($options['vars'])) {
foreach ($options['vars'] as $name => $value) {
$view->vars[$name] = $value;
}
}
// replace attributes if specified ('attr' variable always exists in a view because it is added by FormView)
if (isset($options['attr'])) {
$view->vars['attr'] = $options['attr'];
}
// add label text and attributes if specified
if (isset($options['label'])) {
$view->vars['label'] = $options->get('label', false);
$view->vars['label_attr'] = [];
if (isset($options['label_attr'])) {
$view->vars['label_attr'] = $options->get('label_attr', false);
}
}
// add core variables to the block view, like id, block type and variables required for rendering engine
$view->vars['id'] = $block->getId();
$view->vars['block_type_widget_id'] = $block->getTypeName() . '_widget';
$view->vars['block_type'] = $block->getTypeName();
$view->vars['unique_block_prefix'] = '_' . preg_replace('/[^a-z0-9_]+/i', '_', $block->getId());
$view->vars['cache_key'] = sprintf('_%s_%s', $block->getId(), $block->getTypeName());
} | [
"public",
"function",
"buildView",
"(",
"BlockView",
"$",
"view",
",",
"BlockInterface",
"$",
"block",
",",
"Options",
"$",
"options",
")",
"{",
"BlockUtils",
"::",
"setViewVarsFromOptions",
"(",
"$",
"view",
",",
"$",
"options",
",",
"[",
"'visible'",
",",
"'translation_domain'",
",",
"'additional_block_prefixes'",
",",
"'class_prefix'",
"]",
")",
";",
"// merge the passed variables with the existing ones",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'vars'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"options",
"[",
"'vars'",
"]",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"view",
"->",
"vars",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"// replace attributes if specified ('attr' variable always exists in a view because it is added by FormView)",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'attr'",
"]",
")",
")",
"{",
"$",
"view",
"->",
"vars",
"[",
"'attr'",
"]",
"=",
"$",
"options",
"[",
"'attr'",
"]",
";",
"}",
"// add label text and attributes if specified",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'label'",
"]",
")",
")",
"{",
"$",
"view",
"->",
"vars",
"[",
"'label'",
"]",
"=",
"$",
"options",
"->",
"get",
"(",
"'label'",
",",
"false",
")",
";",
"$",
"view",
"->",
"vars",
"[",
"'label_attr'",
"]",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'label_attr'",
"]",
")",
")",
"{",
"$",
"view",
"->",
"vars",
"[",
"'label_attr'",
"]",
"=",
"$",
"options",
"->",
"get",
"(",
"'label_attr'",
",",
"false",
")",
";",
"}",
"}",
"// add core variables to the block view, like id, block type and variables required for rendering engine",
"$",
"view",
"->",
"vars",
"[",
"'id'",
"]",
"=",
"$",
"block",
"->",
"getId",
"(",
")",
";",
"$",
"view",
"->",
"vars",
"[",
"'block_type_widget_id'",
"]",
"=",
"$",
"block",
"->",
"getTypeName",
"(",
")",
".",
"'_widget'",
";",
"$",
"view",
"->",
"vars",
"[",
"'block_type'",
"]",
"=",
"$",
"block",
"->",
"getTypeName",
"(",
")",
";",
"$",
"view",
"->",
"vars",
"[",
"'unique_block_prefix'",
"]",
"=",
"'_'",
".",
"preg_replace",
"(",
"'/[^a-z0-9_]+/i'",
",",
"'_'",
",",
"$",
"block",
"->",
"getId",
"(",
")",
")",
";",
"$",
"view",
"->",
"vars",
"[",
"'cache_key'",
"]",
"=",
"sprintf",
"(",
"'_%s_%s'",
",",
"$",
"block",
"->",
"getId",
"(",
")",
",",
"$",
"block",
"->",
"getTypeName",
"(",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/Block/Type/BaseType.php#L37-L72 |
oroinc/OroLayoutComponent | Block/Type/BaseType.php | BaseType.finishView | public function finishView(BlockView $view, BlockInterface $block)
{
if (empty($view->vars['class_prefix']) && $view->parent) {
$view->vars['class_prefix'] = $view->parent->vars['class_prefix'];
}
// add the view to itself vars to allow get it using 'block' variable in a rendered, for example TWIG
$view->vars['block'] = $view;
// add the translation domain
$view->vars['translation_domain'] = $this->getTranslationDomain($view);
// the block prefix must contain only letters, numbers and underscores (_)
// due to limitations of block names in TWIG
$blockPrefixes = $block->getTypeHelper()->getTypeNames($block->getTypeName());
if (!empty($view->vars['additional_block_prefixes'])) {
$blockPrefixes = array_merge($blockPrefixes, $view->vars['additional_block_prefixes']);
}
unset($view->vars['additional_block_prefixes']);
$blockPrefixes[] = $view->vars['unique_block_prefix'];
$view->vars['block_prefixes'] = $blockPrefixes;
if (isset($view->vars['attr']['id']) && !isset($view->vars['label_attr']['for'])) {
$view->vars['label_attr']['for'] = $view->vars['attr']['id'];
}
$view->vars['blocks'] = $view->blocks;
} | php | public function finishView(BlockView $view, BlockInterface $block)
{
if (empty($view->vars['class_prefix']) && $view->parent) {
$view->vars['class_prefix'] = $view->parent->vars['class_prefix'];
}
// add the view to itself vars to allow get it using 'block' variable in a rendered, for example TWIG
$view->vars['block'] = $view;
// add the translation domain
$view->vars['translation_domain'] = $this->getTranslationDomain($view);
// the block prefix must contain only letters, numbers and underscores (_)
// due to limitations of block names in TWIG
$blockPrefixes = $block->getTypeHelper()->getTypeNames($block->getTypeName());
if (!empty($view->vars['additional_block_prefixes'])) {
$blockPrefixes = array_merge($blockPrefixes, $view->vars['additional_block_prefixes']);
}
unset($view->vars['additional_block_prefixes']);
$blockPrefixes[] = $view->vars['unique_block_prefix'];
$view->vars['block_prefixes'] = $blockPrefixes;
if (isset($view->vars['attr']['id']) && !isset($view->vars['label_attr']['for'])) {
$view->vars['label_attr']['for'] = $view->vars['attr']['id'];
}
$view->vars['blocks'] = $view->blocks;
} | [
"public",
"function",
"finishView",
"(",
"BlockView",
"$",
"view",
",",
"BlockInterface",
"$",
"block",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"view",
"->",
"vars",
"[",
"'class_prefix'",
"]",
")",
"&&",
"$",
"view",
"->",
"parent",
")",
"{",
"$",
"view",
"->",
"vars",
"[",
"'class_prefix'",
"]",
"=",
"$",
"view",
"->",
"parent",
"->",
"vars",
"[",
"'class_prefix'",
"]",
";",
"}",
"// add the view to itself vars to allow get it using 'block' variable in a rendered, for example TWIG",
"$",
"view",
"->",
"vars",
"[",
"'block'",
"]",
"=",
"$",
"view",
";",
"// add the translation domain",
"$",
"view",
"->",
"vars",
"[",
"'translation_domain'",
"]",
"=",
"$",
"this",
"->",
"getTranslationDomain",
"(",
"$",
"view",
")",
";",
"// the block prefix must contain only letters, numbers and underscores (_)",
"// due to limitations of block names in TWIG",
"$",
"blockPrefixes",
"=",
"$",
"block",
"->",
"getTypeHelper",
"(",
")",
"->",
"getTypeNames",
"(",
"$",
"block",
"->",
"getTypeName",
"(",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"view",
"->",
"vars",
"[",
"'additional_block_prefixes'",
"]",
")",
")",
"{",
"$",
"blockPrefixes",
"=",
"array_merge",
"(",
"$",
"blockPrefixes",
",",
"$",
"view",
"->",
"vars",
"[",
"'additional_block_prefixes'",
"]",
")",
";",
"}",
"unset",
"(",
"$",
"view",
"->",
"vars",
"[",
"'additional_block_prefixes'",
"]",
")",
";",
"$",
"blockPrefixes",
"[",
"]",
"=",
"$",
"view",
"->",
"vars",
"[",
"'unique_block_prefix'",
"]",
";",
"$",
"view",
"->",
"vars",
"[",
"'block_prefixes'",
"]",
"=",
"$",
"blockPrefixes",
";",
"if",
"(",
"isset",
"(",
"$",
"view",
"->",
"vars",
"[",
"'attr'",
"]",
"[",
"'id'",
"]",
")",
"&&",
"!",
"isset",
"(",
"$",
"view",
"->",
"vars",
"[",
"'label_attr'",
"]",
"[",
"'for'",
"]",
")",
")",
"{",
"$",
"view",
"->",
"vars",
"[",
"'label_attr'",
"]",
"[",
"'for'",
"]",
"=",
"$",
"view",
"->",
"vars",
"[",
"'attr'",
"]",
"[",
"'id'",
"]",
";",
"}",
"$",
"view",
"->",
"vars",
"[",
"'blocks'",
"]",
"=",
"$",
"view",
"->",
"blocks",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/Block/Type/BaseType.php#L77-L107 |
oroinc/OroLayoutComponent | Block/Type/BaseType.php | BaseType.getTranslationDomain | protected function getTranslationDomain(BlockView $view)
{
$translationDomain = $view->vars['translation_domain'];
if (!$translationDomain && $view->parent) {
$translationDomain = $view->parent->vars['translation_domain'];
}
if (!$translationDomain) {
$translationDomain = 'messages';
}
return $translationDomain;
} | php | protected function getTranslationDomain(BlockView $view)
{
$translationDomain = $view->vars['translation_domain'];
if (!$translationDomain && $view->parent) {
$translationDomain = $view->parent->vars['translation_domain'];
}
if (!$translationDomain) {
$translationDomain = 'messages';
}
return $translationDomain;
} | [
"protected",
"function",
"getTranslationDomain",
"(",
"BlockView",
"$",
"view",
")",
"{",
"$",
"translationDomain",
"=",
"$",
"view",
"->",
"vars",
"[",
"'translation_domain'",
"]",
";",
"if",
"(",
"!",
"$",
"translationDomain",
"&&",
"$",
"view",
"->",
"parent",
")",
"{",
"$",
"translationDomain",
"=",
"$",
"view",
"->",
"parent",
"->",
"vars",
"[",
"'translation_domain'",
"]",
";",
"}",
"if",
"(",
"!",
"$",
"translationDomain",
")",
"{",
"$",
"translationDomain",
"=",
"'messages'",
";",
"}",
"return",
"$",
"translationDomain",
";",
"}"
] | @param BlockView $view
@return string | [
"@param",
"BlockView",
"$view"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/Block/Type/BaseType.php#L130-L141 |
inhere/php-librarys | src/Helpers/FormatHelper.php | FormatHelper.beforeTime | public static function beforeTime($secs)
{
static $timeFormats = [
[0, '< 1 sec'],
[1, '1 sec'],
[2, 'secs', 1],
[60, '1 min'],
[120, 'mins', 60],
[3600, '1 hr'],
[7200, 'hrs', 3600],
[86400, '1 day'],
[172800, 'days', 86400],
];
foreach ($timeFormats as $index => $format) {
if ($secs >= $format[0]) {
if ((isset($timeFormats[$index + 1]) && $secs < $timeFormats[$index + 1][0])
|| $index === \count($timeFormats) - 1
) {
if (2 === \count($format)) {
return $format[1];
}
return floor($secs / $format[2]) . ' ' . $format[1];
}
}
}
return date('Y-m-d H:i:s', $secs);
} | php | public static function beforeTime($secs)
{
static $timeFormats = [
[0, '< 1 sec'],
[1, '1 sec'],
[2, 'secs', 1],
[60, '1 min'],
[120, 'mins', 60],
[3600, '1 hr'],
[7200, 'hrs', 3600],
[86400, '1 day'],
[172800, 'days', 86400],
];
foreach ($timeFormats as $index => $format) {
if ($secs >= $format[0]) {
if ((isset($timeFormats[$index + 1]) && $secs < $timeFormats[$index + 1][0])
|| $index === \count($timeFormats) - 1
) {
if (2 === \count($format)) {
return $format[1];
}
return floor($secs / $format[2]) . ' ' . $format[1];
}
}
}
return date('Y-m-d H:i:s', $secs);
} | [
"public",
"static",
"function",
"beforeTime",
"(",
"$",
"secs",
")",
"{",
"static",
"$",
"timeFormats",
"=",
"[",
"[",
"0",
",",
"'< 1 sec'",
"]",
",",
"[",
"1",
",",
"'1 sec'",
"]",
",",
"[",
"2",
",",
"'secs'",
",",
"1",
"]",
",",
"[",
"60",
",",
"'1 min'",
"]",
",",
"[",
"120",
",",
"'mins'",
",",
"60",
"]",
",",
"[",
"3600",
",",
"'1 hr'",
"]",
",",
"[",
"7200",
",",
"'hrs'",
",",
"3600",
"]",
",",
"[",
"86400",
",",
"'1 day'",
"]",
",",
"[",
"172800",
",",
"'days'",
",",
"86400",
"]",
",",
"]",
";",
"foreach",
"(",
"$",
"timeFormats",
"as",
"$",
"index",
"=>",
"$",
"format",
")",
"{",
"if",
"(",
"$",
"secs",
">=",
"$",
"format",
"[",
"0",
"]",
")",
"{",
"if",
"(",
"(",
"isset",
"(",
"$",
"timeFormats",
"[",
"$",
"index",
"+",
"1",
"]",
")",
"&&",
"$",
"secs",
"<",
"$",
"timeFormats",
"[",
"$",
"index",
"+",
"1",
"]",
"[",
"0",
"]",
")",
"||",
"$",
"index",
"===",
"\\",
"count",
"(",
"$",
"timeFormats",
")",
"-",
"1",
")",
"{",
"if",
"(",
"2",
"===",
"\\",
"count",
"(",
"$",
"format",
")",
")",
"{",
"return",
"$",
"format",
"[",
"1",
"]",
";",
"}",
"return",
"floor",
"(",
"$",
"secs",
"/",
"$",
"format",
"[",
"2",
"]",
")",
".",
"' '",
".",
"$",
"format",
"[",
"1",
"]",
";",
"}",
"}",
"}",
"return",
"date",
"(",
"'Y-m-d H:i:s'",
",",
"$",
"secs",
")",
";",
"}"
] | formatTime
@param int $secs
@return string | [
"formatTime"
] | train | https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Helpers/FormatHelper.php#L23-L52 |
inhere/php-librarys | src/Helpers/FormatHelper.php | FormatHelper.bytes | public static function bytes($size, $precision = 2)
{
if (!$size) {
return '0';
}
$base = log($size) / log(1024);
$suffixes = array('b', 'k', 'M', 'G', 'T');
$floorBase = floor($base);
return round(1024 ** ($base - $floorBase), $precision) . $suffixes[(int)$floorBase];
} | php | public static function bytes($size, $precision = 2)
{
if (!$size) {
return '0';
}
$base = log($size) / log(1024);
$suffixes = array('b', 'k', 'M', 'G', 'T');
$floorBase = floor($base);
return round(1024 ** ($base - $floorBase), $precision) . $suffixes[(int)$floorBase];
} | [
"public",
"static",
"function",
"bytes",
"(",
"$",
"size",
",",
"$",
"precision",
"=",
"2",
")",
"{",
"if",
"(",
"!",
"$",
"size",
")",
"{",
"return",
"'0'",
";",
"}",
"$",
"base",
"=",
"log",
"(",
"$",
"size",
")",
"/",
"log",
"(",
"1024",
")",
";",
"$",
"suffixes",
"=",
"array",
"(",
"'b'",
",",
"'k'",
",",
"'M'",
",",
"'G'",
",",
"'T'",
")",
";",
"$",
"floorBase",
"=",
"floor",
"(",
"$",
"base",
")",
";",
"return",
"round",
"(",
"1024",
"**",
"(",
"$",
"base",
"-",
"$",
"floorBase",
")",
",",
"$",
"precision",
")",
".",
"$",
"suffixes",
"[",
"(",
"int",
")",
"$",
"floorBase",
"]",
";",
"}"
] | Format a number into a human readable format
e.g. 24962496 => 23.81M
@param $size
@param int $precision
@return string | [
"Format",
"a",
"number",
"into",
"a",
"human",
"readable",
"format",
"e",
".",
"g",
".",
"24962496",
"=",
">",
"23",
".",
"81M"
] | train | https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Helpers/FormatHelper.php#L124-L135 |
inhere/php-librarys | src/Helpers/FormatHelper.php | FormatHelper.convertBytes | public static function convertBytes($value)
{
if (is_numeric($value)) {
return $value;
}
$value_length = \strlen($value);
$qty = (int)substr($value, 0, $value_length - 1);
$unit = Str::strtolower(substr($value, $value_length - 1));
switch ($unit) {
case 'k':
$qty *= 1024;
break;
case 'm':
$qty *= 1048576;
break;
case 'g':
$qty *= 1073741824;
break;
}
return $qty;
} | php | public static function convertBytes($value)
{
if (is_numeric($value)) {
return $value;
}
$value_length = \strlen($value);
$qty = (int)substr($value, 0, $value_length - 1);
$unit = Str::strtolower(substr($value, $value_length - 1));
switch ($unit) {
case 'k':
$qty *= 1024;
break;
case 'm':
$qty *= 1048576;
break;
case 'g':
$qty *= 1073741824;
break;
}
return $qty;
} | [
"public",
"static",
"function",
"convertBytes",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"$",
"value_length",
"=",
"\\",
"strlen",
"(",
"$",
"value",
")",
";",
"$",
"qty",
"=",
"(",
"int",
")",
"substr",
"(",
"$",
"value",
",",
"0",
",",
"$",
"value_length",
"-",
"1",
")",
";",
"$",
"unit",
"=",
"Str",
"::",
"strtolower",
"(",
"substr",
"(",
"$",
"value",
",",
"$",
"value_length",
"-",
"1",
")",
")",
";",
"switch",
"(",
"$",
"unit",
")",
"{",
"case",
"'k'",
":",
"$",
"qty",
"*=",
"1024",
";",
"break",
";",
"case",
"'m'",
":",
"$",
"qty",
"*=",
"1048576",
";",
"break",
";",
"case",
"'g'",
":",
"$",
"qty",
"*=",
"1073741824",
";",
"break",
";",
"}",
"return",
"$",
"qty",
";",
"}"
] | Convert a shorthand byte value from a PHP configuration directive to an integer value
@param string $value value to convert
@return int | [
"Convert",
"a",
"shorthand",
"byte",
"value",
"from",
"a",
"PHP",
"configuration",
"directive",
"to",
"an",
"integer",
"value"
] | train | https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Helpers/FormatHelper.php#L142-L164 |
inhere/php-librarys | src/Helpers/FormatHelper.php | FormatHelper.ampReplace | public static function ampReplace($text)
{
$text = str_replace([
'&&',
'&#',
'&#',
'&',
'*-*',
'*--*',
], [
'*--*',
'*-*',
'*-*',
'&',
'&#',
'&&',
], $text);
$text = (string)preg_replace('/|&(?![\w]+;)|/', '&', $text);
return $text;
} | php | public static function ampReplace($text)
{
$text = str_replace([
'&&',
'&#',
'&#',
'&',
'*-*',
'*--*',
], [
'*--*',
'*-*',
'*-*',
'&',
'&#',
'&&',
], $text);
$text = (string)preg_replace('/|&(?![\w]+;)|/', '&', $text);
return $text;
} | [
"public",
"static",
"function",
"ampReplace",
"(",
"$",
"text",
")",
"{",
"$",
"text",
"=",
"str_replace",
"(",
"[",
"'&&'",
",",
"'&#'",
",",
"'&#'",
",",
"'&'",
",",
"'*-*'",
",",
"'*--*'",
",",
"]",
",",
"[",
"'*--*'",
",",
"'*-*'",
",",
"'*-*'",
",",
"'&'",
",",
"'&#'",
",",
"'&&'",
",",
"]",
",",
"$",
"text",
")",
";",
"$",
"text",
"=",
"(",
"string",
")",
"preg_replace",
"(",
"'/|&(?![\\w]+;)|/'",
",",
"'&'",
",",
"$",
"text",
")",
";",
"return",
"$",
"text",
";",
"}"
] | Replaces & with & for XHTML compliance
@param string $text Text to process
@return string Processed string. | [
"Replaces",
"&",
";",
"with",
"&",
"for",
"XHTML",
"compliance"
] | train | https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Helpers/FormatHelper.php#L171-L192 |
inhere/php-librarys | src/Helpers/FormatHelper.php | FormatHelper.cleanText | public static function cleanText(string $text)
{
$text = preg_replace('/<script[^>]*>.*?</script>/si', '', $text);
$text = preg_replace('/<a\s+.*?href="([^"]+)"[^>]*>([^<]+)<\/a>/is', '\2 (\1)', $text);
$text = preg_replace('/<!--.+?-->/', '', $text);
$text = preg_replace('/{.+?}/', '', $text);
$text = preg_replace('/ /', ' ', $text);
$text = preg_replace('/&/', ' ', $text);
$text = preg_replace('/"/', ' ', $text);
$text = strip_tags($text);
$text = htmlspecialchars($text);
return $text;
} | php | public static function cleanText(string $text)
{
$text = preg_replace('/<script[^>]*>.*?</script>/si', '', $text);
$text = preg_replace('/<a\s+.*?href="([^"]+)"[^>]*>([^<]+)<\/a>/is', '\2 (\1)', $text);
$text = preg_replace('/<!--.+?-->/', '', $text);
$text = preg_replace('/{.+?}/', '', $text);
$text = preg_replace('/ /', ' ', $text);
$text = preg_replace('/&/', ' ', $text);
$text = preg_replace('/"/', ' ', $text);
$text = strip_tags($text);
$text = htmlspecialchars($text);
return $text;
} | [
"public",
"static",
"function",
"cleanText",
"(",
"string",
"$",
"text",
")",
"{",
"$",
"text",
"=",
"preg_replace",
"(",
"'/<script[^>]*>.*?</script>/si'",
",",
"''",
",",
"$",
"text",
")",
";",
"$",
"text",
"=",
"preg_replace",
"(",
"'/<a\\s+.*?href=\"([^\"]+)\"[^>]*>([^<]+)<\\/a>/is'",
",",
"'\\2 (\\1)'",
",",
"$",
"text",
")",
";",
"$",
"text",
"=",
"preg_replace",
"(",
"'/<!--.+?-->/'",
",",
"''",
",",
"$",
"text",
")",
";",
"$",
"text",
"=",
"preg_replace",
"(",
"'/{.+?}/'",
",",
"''",
",",
"$",
"text",
")",
";",
"$",
"text",
"=",
"preg_replace",
"(",
"'/ /'",
",",
"' '",
",",
"$",
"text",
")",
";",
"$",
"text",
"=",
"preg_replace",
"(",
"'/&/'",
",",
"' '",
",",
"$",
"text",
")",
";",
"$",
"text",
"=",
"preg_replace",
"(",
"'/"/'",
",",
"' '",
",",
"$",
"text",
")",
";",
"$",
"text",
"=",
"strip_tags",
"(",
"$",
"text",
")",
";",
"$",
"text",
"=",
"htmlspecialchars",
"(",
"$",
"text",
")",
";",
"return",
"$",
"text",
";",
"}"
] | Cleans text of all formatting and scripting code
@param string|null|array $text Text to clean
@return string Cleaned text. | [
"Cleans",
"text",
"of",
"all",
"formatting",
"and",
"scripting",
"code"
] | train | https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Helpers/FormatHelper.php#L199-L212 |
inhere/php-librarys | src/Helpers/FormatHelper.php | FormatHelper.phpCode | public static function phpCode($src)
{
// Whitespaces left and right from this signs can be ignored
static $IW = array(
T_CONCAT_EQUAL, // .=
T_DOUBLE_ARROW, // =>
T_BOOLEAN_AND, // &&
T_BOOLEAN_OR, // ||
T_IS_EQUAL, // ==
T_IS_NOT_EQUAL, // != or <>
T_IS_SMALLER_OR_EQUAL, // <=
T_IS_GREATER_OR_EQUAL, // >=
T_INC, // ++
T_DEC, // --
T_PLUS_EQUAL, // +=
T_MINUS_EQUAL, // -=
T_MUL_EQUAL, // *=
T_DIV_EQUAL, // /=
T_IS_IDENTICAL, // ===
T_IS_NOT_IDENTICAL, // !==
T_DOUBLE_COLON, // ::
T_PAAMAYIM_NEKUDOTAYIM, // ::
T_OBJECT_OPERATOR, // ->
T_DOLLAR_OPEN_CURLY_BRACES, // ${
T_AND_EQUAL, // &=
T_MOD_EQUAL, // %=
T_XOR_EQUAL, // ^=
T_OR_EQUAL, // |=
T_SL, // <<
T_SR, // >>
T_SL_EQUAL, // <<=
T_SR_EQUAL, // >>=
);
if (!$src) {
return false;
}
if (is_file($src) && (!$src = file_get_contents($src))) {
return false;
}
$tokens = token_get_all($src);
$new = '';
$c = \count($tokens);
$iw = false; // ignore whitespace
$ih = false; // in HEREDOC
$ls = ''; // last sign
$ot = null; // open tag
for ($i = 0; $i < $c; $i++) {
$token = $tokens[$i];
if (\is_array($token)) {
list($tn, $ts) = $token; // tokens: number, string, line
$tname = token_name($tn);
if ($tn === T_INLINE_HTML) {
$new .= $ts;
$iw = false;
} else {
if ($tn === T_OPEN_TAG) {
if (strpos($ts, ' ') || strpos($ts, "\n") || strpos($ts, "\t") || strpos($ts, "\r")) {
$ts = rtrim($ts);
}
$ts .= ' ';
$new .= $ts;
$ot = T_OPEN_TAG;
$iw = true;
} elseif ($tn === T_OPEN_TAG_WITH_ECHO) {
$new .= $ts;
$ot = T_OPEN_TAG_WITH_ECHO;
$iw = true;
} elseif ($tn === T_CLOSE_TAG) {
if ($ot === T_OPEN_TAG_WITH_ECHO) {
$new = rtrim($new, '; ');
} else {
$ts = ' ' . $ts;
}
$new .= $ts;
$ot = null;
$iw = false;
} elseif (\in_array($tn, $IW, true)) {
$new .= $ts;
$iw = true;
} elseif ($tn === T_CONSTANT_ENCAPSED_STRING || $tn === T_ENCAPSED_AND_WHITESPACE) {
if ($ts[0] === '"') {
$ts = addcslashes($ts, "\n\t\r");
}
$new .= $ts;
$iw = true;
} elseif ($tn === T_WHITESPACE) {
$nt = @$tokens[$i + 1];
if (!$iw && (!\is_string($nt) || $nt === '$') && !\in_array($nt[0], $IW)) {
$new .= " ";
}
$iw = false;
} elseif ($tn === T_START_HEREDOC) {
$new .= "<<<S\n";
$iw = false;
$ih = true; // in HEREDOC
} elseif ($tn === T_END_HEREDOC) {
$new .= "S;\n";
$iw = true;
$ih = false; // in HEREDOC
for ($j = $i + 1; $j < $c; $j++) {
if (\is_string($tokens[$j]) && $tokens[$j] === ';') {
$i = $j;
break;
}
if ($tokens[$j][0] === T_CLOSE_TAG) {
break;
}
}
} elseif ($tn === T_COMMENT || $tn === T_DOC_COMMENT) {
$iw = true;
} else {
if (!$ih) {
$ts = strtolower($ts);
}
$new .= $ts;
$iw = false;
}
}
$ls = '';
} else {
if (($token !== ';' && $token !== ':') || $ls !== $token) {
$new .= $token;
$ls = $token;
}
$iw = true;
}
}
return $new;
} | php | public static function phpCode($src)
{
// Whitespaces left and right from this signs can be ignored
static $IW = array(
T_CONCAT_EQUAL, // .=
T_DOUBLE_ARROW, // =>
T_BOOLEAN_AND, // &&
T_BOOLEAN_OR, // ||
T_IS_EQUAL, // ==
T_IS_NOT_EQUAL, // != or <>
T_IS_SMALLER_OR_EQUAL, // <=
T_IS_GREATER_OR_EQUAL, // >=
T_INC, // ++
T_DEC, // --
T_PLUS_EQUAL, // +=
T_MINUS_EQUAL, // -=
T_MUL_EQUAL, // *=
T_DIV_EQUAL, // /=
T_IS_IDENTICAL, // ===
T_IS_NOT_IDENTICAL, // !==
T_DOUBLE_COLON, // ::
T_PAAMAYIM_NEKUDOTAYIM, // ::
T_OBJECT_OPERATOR, // ->
T_DOLLAR_OPEN_CURLY_BRACES, // ${
T_AND_EQUAL, // &=
T_MOD_EQUAL, // %=
T_XOR_EQUAL, // ^=
T_OR_EQUAL, // |=
T_SL, // <<
T_SR, // >>
T_SL_EQUAL, // <<=
T_SR_EQUAL, // >>=
);
if (!$src) {
return false;
}
if (is_file($src) && (!$src = file_get_contents($src))) {
return false;
}
$tokens = token_get_all($src);
$new = '';
$c = \count($tokens);
$iw = false; // ignore whitespace
$ih = false; // in HEREDOC
$ls = ''; // last sign
$ot = null; // open tag
for ($i = 0; $i < $c; $i++) {
$token = $tokens[$i];
if (\is_array($token)) {
list($tn, $ts) = $token; // tokens: number, string, line
$tname = token_name($tn);
if ($tn === T_INLINE_HTML) {
$new .= $ts;
$iw = false;
} else {
if ($tn === T_OPEN_TAG) {
if (strpos($ts, ' ') || strpos($ts, "\n") || strpos($ts, "\t") || strpos($ts, "\r")) {
$ts = rtrim($ts);
}
$ts .= ' ';
$new .= $ts;
$ot = T_OPEN_TAG;
$iw = true;
} elseif ($tn === T_OPEN_TAG_WITH_ECHO) {
$new .= $ts;
$ot = T_OPEN_TAG_WITH_ECHO;
$iw = true;
} elseif ($tn === T_CLOSE_TAG) {
if ($ot === T_OPEN_TAG_WITH_ECHO) {
$new = rtrim($new, '; ');
} else {
$ts = ' ' . $ts;
}
$new .= $ts;
$ot = null;
$iw = false;
} elseif (\in_array($tn, $IW, true)) {
$new .= $ts;
$iw = true;
} elseif ($tn === T_CONSTANT_ENCAPSED_STRING || $tn === T_ENCAPSED_AND_WHITESPACE) {
if ($ts[0] === '"') {
$ts = addcslashes($ts, "\n\t\r");
}
$new .= $ts;
$iw = true;
} elseif ($tn === T_WHITESPACE) {
$nt = @$tokens[$i + 1];
if (!$iw && (!\is_string($nt) || $nt === '$') && !\in_array($nt[0], $IW)) {
$new .= " ";
}
$iw = false;
} elseif ($tn === T_START_HEREDOC) {
$new .= "<<<S\n";
$iw = false;
$ih = true; // in HEREDOC
} elseif ($tn === T_END_HEREDOC) {
$new .= "S;\n";
$iw = true;
$ih = false; // in HEREDOC
for ($j = $i + 1; $j < $c; $j++) {
if (\is_string($tokens[$j]) && $tokens[$j] === ';') {
$i = $j;
break;
}
if ($tokens[$j][0] === T_CLOSE_TAG) {
break;
}
}
} elseif ($tn === T_COMMENT || $tn === T_DOC_COMMENT) {
$iw = true;
} else {
if (!$ih) {
$ts = strtolower($ts);
}
$new .= $ts;
$iw = false;
}
}
$ls = '';
} else {
if (($token !== ';' && $token !== ':') || $ls !== $token) {
$new .= $token;
$ls = $token;
}
$iw = true;
}
}
return $new;
} | [
"public",
"static",
"function",
"phpCode",
"(",
"$",
"src",
")",
"{",
"// Whitespaces left and right from this signs can be ignored",
"static",
"$",
"IW",
"=",
"array",
"(",
"T_CONCAT_EQUAL",
",",
"// .=",
"T_DOUBLE_ARROW",
",",
"// =>",
"T_BOOLEAN_AND",
",",
"// &&",
"T_BOOLEAN_OR",
",",
"// ||",
"T_IS_EQUAL",
",",
"// ==",
"T_IS_NOT_EQUAL",
",",
"// != or <>",
"T_IS_SMALLER_OR_EQUAL",
",",
"// <=",
"T_IS_GREATER_OR_EQUAL",
",",
"// >=",
"T_INC",
",",
"// ++",
"T_DEC",
",",
"// --",
"T_PLUS_EQUAL",
",",
"// +=",
"T_MINUS_EQUAL",
",",
"// -=",
"T_MUL_EQUAL",
",",
"// *=",
"T_DIV_EQUAL",
",",
"// /=",
"T_IS_IDENTICAL",
",",
"// ===",
"T_IS_NOT_IDENTICAL",
",",
"// !==",
"T_DOUBLE_COLON",
",",
"// ::",
"T_PAAMAYIM_NEKUDOTAYIM",
",",
"// ::",
"T_OBJECT_OPERATOR",
",",
"// ->",
"T_DOLLAR_OPEN_CURLY_BRACES",
",",
"// ${",
"T_AND_EQUAL",
",",
"// &=",
"T_MOD_EQUAL",
",",
"// %=",
"T_XOR_EQUAL",
",",
"// ^=",
"T_OR_EQUAL",
",",
"// |=",
"T_SL",
",",
"// <<",
"T_SR",
",",
"// >>",
"T_SL_EQUAL",
",",
"// <<=",
"T_SR_EQUAL",
",",
"// >>=",
")",
";",
"if",
"(",
"!",
"$",
"src",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"is_file",
"(",
"$",
"src",
")",
"&&",
"(",
"!",
"$",
"src",
"=",
"file_get_contents",
"(",
"$",
"src",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"tokens",
"=",
"token_get_all",
"(",
"$",
"src",
")",
";",
"$",
"new",
"=",
"''",
";",
"$",
"c",
"=",
"\\",
"count",
"(",
"$",
"tokens",
")",
";",
"$",
"iw",
"=",
"false",
";",
"// ignore whitespace",
"$",
"ih",
"=",
"false",
";",
"// in HEREDOC",
"$",
"ls",
"=",
"''",
";",
"// last sign",
"$",
"ot",
"=",
"null",
";",
"// open tag",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"c",
";",
"$",
"i",
"++",
")",
"{",
"$",
"token",
"=",
"$",
"tokens",
"[",
"$",
"i",
"]",
";",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"token",
")",
")",
"{",
"list",
"(",
"$",
"tn",
",",
"$",
"ts",
")",
"=",
"$",
"token",
";",
"// tokens: number, string, line",
"$",
"tname",
"=",
"token_name",
"(",
"$",
"tn",
")",
";",
"if",
"(",
"$",
"tn",
"===",
"T_INLINE_HTML",
")",
"{",
"$",
"new",
".=",
"$",
"ts",
";",
"$",
"iw",
"=",
"false",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"tn",
"===",
"T_OPEN_TAG",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"ts",
",",
"' '",
")",
"||",
"strpos",
"(",
"$",
"ts",
",",
"\"\\n\"",
")",
"||",
"strpos",
"(",
"$",
"ts",
",",
"\"\\t\"",
")",
"||",
"strpos",
"(",
"$",
"ts",
",",
"\"\\r\"",
")",
")",
"{",
"$",
"ts",
"=",
"rtrim",
"(",
"$",
"ts",
")",
";",
"}",
"$",
"ts",
".=",
"' '",
";",
"$",
"new",
".=",
"$",
"ts",
";",
"$",
"ot",
"=",
"T_OPEN_TAG",
";",
"$",
"iw",
"=",
"true",
";",
"}",
"elseif",
"(",
"$",
"tn",
"===",
"T_OPEN_TAG_WITH_ECHO",
")",
"{",
"$",
"new",
".=",
"$",
"ts",
";",
"$",
"ot",
"=",
"T_OPEN_TAG_WITH_ECHO",
";",
"$",
"iw",
"=",
"true",
";",
"}",
"elseif",
"(",
"$",
"tn",
"===",
"T_CLOSE_TAG",
")",
"{",
"if",
"(",
"$",
"ot",
"===",
"T_OPEN_TAG_WITH_ECHO",
")",
"{",
"$",
"new",
"=",
"rtrim",
"(",
"$",
"new",
",",
"'; '",
")",
";",
"}",
"else",
"{",
"$",
"ts",
"=",
"' '",
".",
"$",
"ts",
";",
"}",
"$",
"new",
".=",
"$",
"ts",
";",
"$",
"ot",
"=",
"null",
";",
"$",
"iw",
"=",
"false",
";",
"}",
"elseif",
"(",
"\\",
"in_array",
"(",
"$",
"tn",
",",
"$",
"IW",
",",
"true",
")",
")",
"{",
"$",
"new",
".=",
"$",
"ts",
";",
"$",
"iw",
"=",
"true",
";",
"}",
"elseif",
"(",
"$",
"tn",
"===",
"T_CONSTANT_ENCAPSED_STRING",
"||",
"$",
"tn",
"===",
"T_ENCAPSED_AND_WHITESPACE",
")",
"{",
"if",
"(",
"$",
"ts",
"[",
"0",
"]",
"===",
"'\"'",
")",
"{",
"$",
"ts",
"=",
"addcslashes",
"(",
"$",
"ts",
",",
"\"\\n\\t\\r\"",
")",
";",
"}",
"$",
"new",
".=",
"$",
"ts",
";",
"$",
"iw",
"=",
"true",
";",
"}",
"elseif",
"(",
"$",
"tn",
"===",
"T_WHITESPACE",
")",
"{",
"$",
"nt",
"=",
"@",
"$",
"tokens",
"[",
"$",
"i",
"+",
"1",
"]",
";",
"if",
"(",
"!",
"$",
"iw",
"&&",
"(",
"!",
"\\",
"is_string",
"(",
"$",
"nt",
")",
"||",
"$",
"nt",
"===",
"'$'",
")",
"&&",
"!",
"\\",
"in_array",
"(",
"$",
"nt",
"[",
"0",
"]",
",",
"$",
"IW",
")",
")",
"{",
"$",
"new",
".=",
"\" \"",
";",
"}",
"$",
"iw",
"=",
"false",
";",
"}",
"elseif",
"(",
"$",
"tn",
"===",
"T_START_HEREDOC",
")",
"{",
"$",
"new",
".=",
"\"<<<S\\n\"",
";",
"$",
"iw",
"=",
"false",
";",
"$",
"ih",
"=",
"true",
";",
"// in HEREDOC",
"}",
"elseif",
"(",
"$",
"tn",
"===",
"T_END_HEREDOC",
")",
"{",
"$",
"new",
".=",
"\"S;\\n\"",
";",
"$",
"iw",
"=",
"true",
";",
"$",
"ih",
"=",
"false",
";",
"// in HEREDOC",
"for",
"(",
"$",
"j",
"=",
"$",
"i",
"+",
"1",
";",
"$",
"j",
"<",
"$",
"c",
";",
"$",
"j",
"++",
")",
"{",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"tokens",
"[",
"$",
"j",
"]",
")",
"&&",
"$",
"tokens",
"[",
"$",
"j",
"]",
"===",
"';'",
")",
"{",
"$",
"i",
"=",
"$",
"j",
";",
"break",
";",
"}",
"if",
"(",
"$",
"tokens",
"[",
"$",
"j",
"]",
"[",
"0",
"]",
"===",
"T_CLOSE_TAG",
")",
"{",
"break",
";",
"}",
"}",
"}",
"elseif",
"(",
"$",
"tn",
"===",
"T_COMMENT",
"||",
"$",
"tn",
"===",
"T_DOC_COMMENT",
")",
"{",
"$",
"iw",
"=",
"true",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"$",
"ih",
")",
"{",
"$",
"ts",
"=",
"strtolower",
"(",
"$",
"ts",
")",
";",
"}",
"$",
"new",
".=",
"$",
"ts",
";",
"$",
"iw",
"=",
"false",
";",
"}",
"}",
"$",
"ls",
"=",
"''",
";",
"}",
"else",
"{",
"if",
"(",
"(",
"$",
"token",
"!==",
"';'",
"&&",
"$",
"token",
"!==",
"':'",
")",
"||",
"$",
"ls",
"!==",
"$",
"token",
")",
"{",
"$",
"new",
".=",
"$",
"token",
";",
"$",
"ls",
"=",
"$",
"token",
";",
"}",
"$",
"iw",
"=",
"true",
";",
"}",
"}",
"return",
"$",
"new",
";",
"}"
] | 返回删除注释和空格后的PHP源码(php_strip_whitespace)
@link http://cn2.php.net/manual/zh/function.php-strip-whitespace.php
@param string|bool $src
@return string | [
"返回删除注释和空格后的PHP源码",
"(",
"php_strip_whitespace",
")"
] | train | https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Helpers/FormatHelper.php#L220-L353 |
ekuiter/feature-php | FeaturePhp/Model/XmlModel.php | XmlModel._traverse | private static function _traverse($node, $parent, $callback) {
if (in_array($node->getName(), array("feature", "and", "or", "alt")))
call_user_func($callback, $node, $parent);
foreach ($node->children() as $child)
self::_traverse($child, $node, $callback);
} | php | private static function _traverse($node, $parent, $callback) {
if (in_array($node->getName(), array("feature", "and", "or", "alt")))
call_user_func($callback, $node, $parent);
foreach ($node->children() as $child)
self::_traverse($child, $node, $callback);
} | [
"private",
"static",
"function",
"_traverse",
"(",
"$",
"node",
",",
"$",
"parent",
",",
"$",
"callback",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"node",
"->",
"getName",
"(",
")",
",",
"array",
"(",
"\"feature\"",
",",
"\"and\"",
",",
"\"or\"",
",",
"\"alt\"",
")",
")",
")",
"call_user_func",
"(",
"$",
"callback",
",",
"$",
"node",
",",
"$",
"parent",
")",
";",
"foreach",
"(",
"$",
"node",
"->",
"children",
"(",
")",
"as",
"$",
"child",
")",
"self",
"::",
"_traverse",
"(",
"$",
"child",
",",
"$",
"node",
",",
"$",
"callback",
")",
";",
"}"
] | Traverses a part of the XML feature model's tree.
This is a preorder traversal (in particular, the root is visited first).
@param \SimpleXMLElement $node
@param \SimpleXMLElement $parent
@param callable callback called with the current node and its parent | [
"Traverses",
"a",
"part",
"of",
"the",
"XML",
"feature",
"model",
"s",
"tree",
".",
"This",
"is",
"a",
"preorder",
"traversal",
"(",
"in",
"particular",
"the",
"root",
"is",
"visited",
"first",
")",
"."
] | train | https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/Model/XmlModel.php#L101-L107 |
rattfieldnz/url-validation | src/RattfieldNz/UrlValidation/ExternalSources/Jmathai/PhpMultiCurl/EpiCurl.php | EpiCurl.addURL | public function addURL($url,$options=array()) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
foreach($options as $option=>$value) {
curl_setopt($ch, $option, $value);
}
return $this->addCurl($ch);
} | php | public function addURL($url,$options=array()) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
foreach($options as $option=>$value) {
curl_setopt($ch, $option, $value);
}
return $this->addCurl($ch);
} | [
"public",
"function",
"addURL",
"(",
"$",
"url",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"ch",
"=",
"curl_init",
"(",
"$",
"url",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_RETURNTRANSFER",
",",
"1",
")",
";",
"foreach",
"(",
"$",
"options",
"as",
"$",
"option",
"=>",
"$",
"value",
")",
"{",
"curl_setopt",
"(",
"$",
"ch",
",",
"$",
"option",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"this",
"->",
"addCurl",
"(",
"$",
"ch",
")",
";",
"}"
] | simplifies example and allows for additional curl options to be passed in via array | [
"simplifies",
"example",
"and",
"allows",
"for",
"additional",
"curl",
"options",
"to",
"be",
"passed",
"in",
"via",
"array"
] | train | https://github.com/rattfieldnz/url-validation/blob/ff44a463a9119fa3bea9bd7fef3d44b7e6f9a44c/src/RattfieldNz/UrlValidation/ExternalSources/Jmathai/PhpMultiCurl/EpiCurl.php#L38-L45 |
Litecms/Team | src/Policies/TeamPolicy.php | TeamPolicy.update | public function update(UserPolicy $user, Team $team)
{
if ($user->canDo('team.team.edit') && $user->isAdmin()) {
return true;
}
return $team->user_id == user_id() && $team->user_type == user_type();
} | php | public function update(UserPolicy $user, Team $team)
{
if ($user->canDo('team.team.edit') && $user->isAdmin()) {
return true;
}
return $team->user_id == user_id() && $team->user_type == user_type();
} | [
"public",
"function",
"update",
"(",
"UserPolicy",
"$",
"user",
",",
"Team",
"$",
"team",
")",
"{",
"if",
"(",
"$",
"user",
"->",
"canDo",
"(",
"'team.team.edit'",
")",
"&&",
"$",
"user",
"->",
"isAdmin",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"$",
"team",
"->",
"user_id",
"==",
"user_id",
"(",
")",
"&&",
"$",
"team",
"->",
"user_type",
"==",
"user_type",
"(",
")",
";",
"}"
] | Determine if the given user can update the given team.
@param UserPolicy $user
@param Team $team
@return bool | [
"Determine",
"if",
"the",
"given",
"user",
"can",
"update",
"the",
"given",
"team",
"."
] | train | https://github.com/Litecms/Team/blob/a444a6a6604c969df138ac0eb57ed5f4696b0f00/src/Policies/TeamPolicy.php#L49-L56 |
Litecms/Team | src/Policies/TeamPolicy.php | TeamPolicy.destroy | public function destroy(UserPolicy $user, Team $team)
{
return $team->user_id == user_id() && $team->user_type == user_type();
} | php | public function destroy(UserPolicy $user, Team $team)
{
return $team->user_id == user_id() && $team->user_type == user_type();
} | [
"public",
"function",
"destroy",
"(",
"UserPolicy",
"$",
"user",
",",
"Team",
"$",
"team",
")",
"{",
"return",
"$",
"team",
"->",
"user_id",
"==",
"user_id",
"(",
")",
"&&",
"$",
"team",
"->",
"user_type",
"==",
"user_type",
"(",
")",
";",
"}"
] | Determine if the given user can delete the given team.
@param UserPolicy $user
@param Team $team
@return bool | [
"Determine",
"if",
"the",
"given",
"user",
"can",
"delete",
"the",
"given",
"team",
"."
] | train | https://github.com/Litecms/Team/blob/a444a6a6604c969df138ac0eb57ed5f4696b0f00/src/Policies/TeamPolicy.php#L66-L69 |
surebert/surebert-framework | src/sb/Controller/HTML/HTML5.php | HTML5.includeJavascript | public function includeJavascript($scripts)
{
$src = (!is_array($scripts)) ? Array($scripts) : $scripts;
$html = '';
foreach ($scripts as $s) {
if (!strstr($s, '/')) {
$s = '/js/' . $s;
}
$html .= "\n" . '<script type="text/javascript" src="' . $s . '"></script>';
}
return $html;
} | php | public function includeJavascript($scripts)
{
$src = (!is_array($scripts)) ? Array($scripts) : $scripts;
$html = '';
foreach ($scripts as $s) {
if (!strstr($s, '/')) {
$s = '/js/' . $s;
}
$html .= "\n" . '<script type="text/javascript" src="' . $s . '"></script>';
}
return $html;
} | [
"public",
"function",
"includeJavascript",
"(",
"$",
"scripts",
")",
"{",
"$",
"src",
"=",
"(",
"!",
"is_array",
"(",
"$",
"scripts",
")",
")",
"?",
"Array",
"(",
"$",
"scripts",
")",
":",
"$",
"scripts",
";",
"$",
"html",
"=",
"''",
";",
"foreach",
"(",
"$",
"scripts",
"as",
"$",
"s",
")",
"{",
"if",
"(",
"!",
"strstr",
"(",
"$",
"s",
",",
"'/'",
")",
")",
"{",
"$",
"s",
"=",
"'/js/'",
".",
"$",
"s",
";",
"}",
"$",
"html",
".=",
"\"\\n\"",
".",
"'<script type=\"text/javascript\" src=\"'",
".",
"$",
"s",
".",
"'\"></script>'",
";",
"}",
"return",
"$",
"html",
";",
"}"
] | Creates a javascript include tag
@param $scripts array/string The file names or an array of file names to include | [
"Creates",
"a",
"javascript",
"include",
"tag"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Controller/HTML/HTML5.php#L72-L85 |
surebert/surebert-framework | src/sb/Controller/HTML/HTML5.php | HTML5.htmlHead | public function htmlHead($custom_head_markup = '')
{
if (!empty($custom_head_markup)) {
$this->custom_head_markup = $custom_head_markup;
}
$html = $this->doc_type . "\n";
$html .= $this->opening_html_tag . "\n";
$html .= '<head>' . "\n";
$html .= '<meta http-equiv="Content-Type" content="text/html; charset=' . $this->charset . '" />' . "\n";
$html .= '<meta http-equiv="X-UA-Compatible" content="IE=edge" />'."\n";
$html .= '<title>' . $this->title . '</title>' . "\n";
if ($this->meta instanceof HeadMeta) {
foreach (get_object_vars($this->meta) as $key => $val) {
$html .= '<meta name="' . $key . '" content="' . $val . '" />' . "\n";
}
}
$html .= '<style type="text/css">';
foreach ($this->styles as $style) {
if (!preg_match("~^(http|/)~", $style)) {
$style = '/css/' . $style;
}
$html .= "@import '" . $style . "';\n";
}
$html .= "</style>\n";
if (!empty($this->custom_head_markup)) {
$html.= $this->custom_head_markup;
}
$html.= "</head>\n";
return $html;
} | php | public function htmlHead($custom_head_markup = '')
{
if (!empty($custom_head_markup)) {
$this->custom_head_markup = $custom_head_markup;
}
$html = $this->doc_type . "\n";
$html .= $this->opening_html_tag . "\n";
$html .= '<head>' . "\n";
$html .= '<meta http-equiv="Content-Type" content="text/html; charset=' . $this->charset . '" />' . "\n";
$html .= '<meta http-equiv="X-UA-Compatible" content="IE=edge" />'."\n";
$html .= '<title>' . $this->title . '</title>' . "\n";
if ($this->meta instanceof HeadMeta) {
foreach (get_object_vars($this->meta) as $key => $val) {
$html .= '<meta name="' . $key . '" content="' . $val . '" />' . "\n";
}
}
$html .= '<style type="text/css">';
foreach ($this->styles as $style) {
if (!preg_match("~^(http|/)~", $style)) {
$style = '/css/' . $style;
}
$html .= "@import '" . $style . "';\n";
}
$html .= "</style>\n";
if (!empty($this->custom_head_markup)) {
$html.= $this->custom_head_markup;
}
$html.= "</head>\n";
return $html;
} | [
"public",
"function",
"htmlHead",
"(",
"$",
"custom_head_markup",
"=",
"''",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"custom_head_markup",
")",
")",
"{",
"$",
"this",
"->",
"custom_head_markup",
"=",
"$",
"custom_head_markup",
";",
"}",
"$",
"html",
"=",
"$",
"this",
"->",
"doc_type",
".",
"\"\\n\"",
";",
"$",
"html",
".=",
"$",
"this",
"->",
"opening_html_tag",
".",
"\"\\n\"",
";",
"$",
"html",
".=",
"'<head>'",
".",
"\"\\n\"",
";",
"$",
"html",
".=",
"'<meta http-equiv=\"Content-Type\" content=\"text/html; charset='",
".",
"$",
"this",
"->",
"charset",
".",
"'\" />'",
".",
"\"\\n\"",
";",
"$",
"html",
".=",
"'<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />'",
".",
"\"\\n\"",
";",
"$",
"html",
".=",
"'<title>'",
".",
"$",
"this",
"->",
"title",
".",
"'</title>'",
".",
"\"\\n\"",
";",
"if",
"(",
"$",
"this",
"->",
"meta",
"instanceof",
"HeadMeta",
")",
"{",
"foreach",
"(",
"get_object_vars",
"(",
"$",
"this",
"->",
"meta",
")",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"html",
".=",
"'<meta name=\"'",
".",
"$",
"key",
".",
"'\" content=\"'",
".",
"$",
"val",
".",
"'\" />'",
".",
"\"\\n\"",
";",
"}",
"}",
"$",
"html",
".=",
"'<style type=\"text/css\">'",
";",
"foreach",
"(",
"$",
"this",
"->",
"styles",
"as",
"$",
"style",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"\"~^(http|/)~\"",
",",
"$",
"style",
")",
")",
"{",
"$",
"style",
"=",
"'/css/'",
".",
"$",
"style",
";",
"}",
"$",
"html",
".=",
"\"@import '\"",
".",
"$",
"style",
".",
"\"';\\n\"",
";",
"}",
"$",
"html",
".=",
"\"</style>\\n\"",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"custom_head_markup",
")",
")",
"{",
"$",
"html",
".=",
"$",
"this",
"->",
"custom_head_markup",
";",
"}",
"$",
"html",
".=",
"\"</head>\\n\"",
";",
"return",
"$",
"html",
";",
"}"
] | Renders the HTML head
@param $custom_head_markup string A string of data to include in the HTML head, right before </head> | [
"Renders",
"the",
"HTML",
"head"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Controller/HTML/HTML5.php#L91-L128 |
loevgaard/altapay-php-sdk | src/Payload/Payload.php | Payload.simplePayload | public static function simplePayload(array $payload) : array
{
$payload = array_filter($payload, function ($val) {
if ($val instanceof PayloadInterface) {
$val = $val->getPayload();
}
// this will effectively remove empty arrays
if (is_array($val) && empty($val)) {
return false;
}
if (is_null($val)) {
return false;
}
if ($val === '') {
return false;
}
return true;
});
foreach ($payload as $key => $val) {
if (is_array($val)) {
$payload[$key] = static::simplePayload($val);
} elseif ($val instanceof PayloadInterface) {
$payload[$key] = static::simplePayload($val->getPayload());
}
}
return $payload;
} | php | public static function simplePayload(array $payload) : array
{
$payload = array_filter($payload, function ($val) {
if ($val instanceof PayloadInterface) {
$val = $val->getPayload();
}
// this will effectively remove empty arrays
if (is_array($val) && empty($val)) {
return false;
}
if (is_null($val)) {
return false;
}
if ($val === '') {
return false;
}
return true;
});
foreach ($payload as $key => $val) {
if (is_array($val)) {
$payload[$key] = static::simplePayload($val);
} elseif ($val instanceof PayloadInterface) {
$payload[$key] = static::simplePayload($val->getPayload());
}
}
return $payload;
} | [
"public",
"static",
"function",
"simplePayload",
"(",
"array",
"$",
"payload",
")",
":",
"array",
"{",
"$",
"payload",
"=",
"array_filter",
"(",
"$",
"payload",
",",
"function",
"(",
"$",
"val",
")",
"{",
"if",
"(",
"$",
"val",
"instanceof",
"PayloadInterface",
")",
"{",
"$",
"val",
"=",
"$",
"val",
"->",
"getPayload",
"(",
")",
";",
"}",
"// this will effectively remove empty arrays",
"if",
"(",
"is_array",
"(",
"$",
"val",
")",
"&&",
"empty",
"(",
"$",
"val",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"val",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"val",
"===",
"''",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}",
")",
";",
"foreach",
"(",
"$",
"payload",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"val",
")",
")",
"{",
"$",
"payload",
"[",
"$",
"key",
"]",
"=",
"static",
"::",
"simplePayload",
"(",
"$",
"val",
")",
";",
"}",
"elseif",
"(",
"$",
"val",
"instanceof",
"PayloadInterface",
")",
"{",
"$",
"payload",
"[",
"$",
"key",
"]",
"=",
"static",
"::",
"simplePayload",
"(",
"$",
"val",
"->",
"getPayload",
"(",
")",
")",
";",
"}",
"}",
"return",
"$",
"payload",
";",
"}"
] | If the input array contains objects of PayloadInterface it will convert these to simple arrays
Also it will remove values that are null, empty string or empty arrays
@param array $payload
@return array | [
"If",
"the",
"input",
"array",
"contains",
"objects",
"of",
"PayloadInterface",
"it",
"will",
"convert",
"these",
"to",
"simple",
"arrays",
"Also",
"it",
"will",
"remove",
"values",
"that",
"are",
"null",
"empty",
"string",
"or",
"empty",
"arrays"
] | train | https://github.com/loevgaard/altapay-php-sdk/blob/476664e8725407249c04ca7ae76f92882e4f4583/src/Payload/Payload.php#L21-L53 |
InactiveProjects/limoncello-illuminate | app/Database/Migrations/Runner.php | Runner.rollback | public static function rollback()
{
foreach (array_reverse(self::$migrationClasses) as $migrationClass) {
/** @var Migration $instance */
$instance = new $migrationClass;
$instance->rollback();
}
} | php | public static function rollback()
{
foreach (array_reverse(self::$migrationClasses) as $migrationClass) {
/** @var Migration $instance */
$instance = new $migrationClass;
$instance->rollback();
}
} | [
"public",
"static",
"function",
"rollback",
"(",
")",
"{",
"foreach",
"(",
"array_reverse",
"(",
"self",
"::",
"$",
"migrationClasses",
")",
"as",
"$",
"migrationClass",
")",
"{",
"/** @var Migration $instance */",
"$",
"instance",
"=",
"new",
"$",
"migrationClass",
";",
"$",
"instance",
"->",
"rollback",
"(",
")",
";",
"}",
"}"
] | Rollback application migrations.
@return void | [
"Rollback",
"application",
"migrations",
"."
] | train | https://github.com/InactiveProjects/limoncello-illuminate/blob/cae6fc26190efcf090495a5c3582c10fa2430897/app/Database/Migrations/Runner.php#L39-L46 |
zhouyl/mellivora | Mellivora/Database/Connection.php | Connection.statement | public function statement($query, $bindings = [])
{
return $this->run($query, $bindings, function ($query, $bindings) {
if ($this->pretending()) {
return true;
}
$statement = $this->getPdo()->prepare($query);
$this->bindValues($statement, $this->prepareBindings($bindings));
return $statement->execute();
});
} | php | public function statement($query, $bindings = [])
{
return $this->run($query, $bindings, function ($query, $bindings) {
if ($this->pretending()) {
return true;
}
$statement = $this->getPdo()->prepare($query);
$this->bindValues($statement, $this->prepareBindings($bindings));
return $statement->execute();
});
} | [
"public",
"function",
"statement",
"(",
"$",
"query",
",",
"$",
"bindings",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"run",
"(",
"$",
"query",
",",
"$",
"bindings",
",",
"function",
"(",
"$",
"query",
",",
"$",
"bindings",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"pretending",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"statement",
"=",
"$",
"this",
"->",
"getPdo",
"(",
")",
"->",
"prepare",
"(",
"$",
"query",
")",
";",
"$",
"this",
"->",
"bindValues",
"(",
"$",
"statement",
",",
"$",
"this",
"->",
"prepareBindings",
"(",
"$",
"bindings",
")",
")",
";",
"return",
"$",
"statement",
"->",
"execute",
"(",
")",
";",
"}",
")",
";",
"}"
] | Execute an SQL statement and return the boolean result.
@param string $query
@param array $bindings
@return bool | [
"Execute",
"an",
"SQL",
"statement",
"and",
"return",
"the",
"boolean",
"result",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Connection.php#L454-L467 |
zhouyl/mellivora | Mellivora/Database/Connection.php | Connection.affectingStatement | public function affectingStatement($query, $bindings = [])
{
return $this->run($query, $bindings, function ($query, $bindings) {
if ($this->pretending()) {
return 0;
}
// For update or delete statements, we want to get the number of rows affected
// by the statement and return that back to the developer. We'll first need
// to execute the statement and then we'll use PDO to fetch the affected.
$statement = $this->getPdo()->prepare($query);
$this->bindValues($statement, $this->prepareBindings($bindings));
$statement->execute();
return $statement->rowCount();
});
} | php | public function affectingStatement($query, $bindings = [])
{
return $this->run($query, $bindings, function ($query, $bindings) {
if ($this->pretending()) {
return 0;
}
// For update or delete statements, we want to get the number of rows affected
// by the statement and return that back to the developer. We'll first need
// to execute the statement and then we'll use PDO to fetch the affected.
$statement = $this->getPdo()->prepare($query);
$this->bindValues($statement, $this->prepareBindings($bindings));
$statement->execute();
return $statement->rowCount();
});
} | [
"public",
"function",
"affectingStatement",
"(",
"$",
"query",
",",
"$",
"bindings",
"=",
"[",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"run",
"(",
"$",
"query",
",",
"$",
"bindings",
",",
"function",
"(",
"$",
"query",
",",
"$",
"bindings",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"pretending",
"(",
")",
")",
"{",
"return",
"0",
";",
"}",
"// For update or delete statements, we want to get the number of rows affected",
"// by the statement and return that back to the developer. We'll first need",
"// to execute the statement and then we'll use PDO to fetch the affected.",
"$",
"statement",
"=",
"$",
"this",
"->",
"getPdo",
"(",
")",
"->",
"prepare",
"(",
"$",
"query",
")",
";",
"$",
"this",
"->",
"bindValues",
"(",
"$",
"statement",
",",
"$",
"this",
"->",
"prepareBindings",
"(",
"$",
"bindings",
")",
")",
";",
"$",
"statement",
"->",
"execute",
"(",
")",
";",
"return",
"$",
"statement",
"->",
"rowCount",
"(",
")",
";",
"}",
")",
";",
"}"
] | Run an SQL statement and get the number of rows affected.
@param string $query
@param array $bindings
@return int | [
"Run",
"an",
"SQL",
"statement",
"and",
"get",
"the",
"number",
"of",
"rows",
"affected",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Connection.php#L477-L495 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.