id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
|
---|---|---|---|---|---|---|---|---|---|---|---|
20,100 |
haldayne/boost
|
src/Map.php
|
Map.walk
|
protected function walk(callable $code)
{
foreach ($this->array as $hash => &$value) {
$key = $this->hash_to_key($hash);
if (! $this->passes($this->call($code, $value, $key))) {
break;
}
}
return $this;
}
|
php
|
protected function walk(callable $code)
{
foreach ($this->array as $hash => &$value) {
$key = $this->hash_to_key($hash);
if (! $this->passes($this->call($code, $value, $key))) {
break;
}
}
return $this;
}
|
[
"protected",
"function",
"walk",
"(",
"callable",
"$",
"code",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"array",
"as",
"$",
"hash",
"=>",
"&",
"$",
"value",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"hash_to_key",
"(",
"$",
"hash",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"passes",
"(",
"$",
"this",
"->",
"call",
"(",
"$",
"code",
",",
"$",
"value",
",",
"$",
"key",
")",
")",
")",
"{",
"break",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Execute the given code over each element of the map. The code receives
the value by reference and then the key as formal parameters.
The items are walked in the order they exist in the map. If the code
returns boolean false, then the iteration halts. Values can be modified
from within the callback, but not keys.
Example:
```
$map->each(function (&$value, $key) { $value++; return true; })->sum();
```
@param callable $code
@return $this
|
[
"Execute",
"the",
"given",
"code",
"over",
"each",
"element",
"of",
"the",
"map",
".",
"The",
"code",
"receives",
"the",
"value",
"by",
"reference",
"and",
"then",
"the",
"key",
"as",
"formal",
"parameters",
"."
] |
d18cc398557e23f9c316ea7fb40b90f84cc53650
|
https://github.com/haldayne/boost/blob/d18cc398557e23f9c316ea7fb40b90f84cc53650/src/Map.php#L956-L965
|
20,101 |
haldayne/boost
|
src/Map.php
|
Map.walk_backward
|
protected function walk_backward(callable $code)
{
for (end($this->array); null !== ($hash = key($this->array)); prev($this->array)) {
$key = $this->hash_to_key($hash);
$current = current($this->array);
$value =& $current;
if (! $this->passes($this->call($code, $value, $key))) {
break;
}
}
return $this;
}
|
php
|
protected function walk_backward(callable $code)
{
for (end($this->array); null !== ($hash = key($this->array)); prev($this->array)) {
$key = $this->hash_to_key($hash);
$current = current($this->array);
$value =& $current;
if (! $this->passes($this->call($code, $value, $key))) {
break;
}
}
return $this;
}
|
[
"protected",
"function",
"walk_backward",
"(",
"callable",
"$",
"code",
")",
"{",
"for",
"(",
"end",
"(",
"$",
"this",
"->",
"array",
")",
";",
"null",
"!==",
"(",
"$",
"hash",
"=",
"key",
"(",
"$",
"this",
"->",
"array",
")",
")",
";",
"prev",
"(",
"$",
"this",
"->",
"array",
")",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"hash_to_key",
"(",
"$",
"hash",
")",
";",
"$",
"current",
"=",
"current",
"(",
"$",
"this",
"->",
"array",
")",
";",
"$",
"value",
"=",
"&",
"$",
"current",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"passes",
"(",
"$",
"this",
"->",
"call",
"(",
"$",
"code",
",",
"$",
"value",
",",
"$",
"key",
")",
")",
")",
"{",
"break",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Like `walk`, except walk from the end toward the front.
@param callable $code
@return $this
|
[
"Like",
"walk",
"except",
"walk",
"from",
"the",
"end",
"toward",
"the",
"front",
"."
] |
d18cc398557e23f9c316ea7fb40b90f84cc53650
|
https://github.com/haldayne/boost/blob/d18cc398557e23f9c316ea7fb40b90f84cc53650/src/Map.php#L973-L984
|
20,102 |
haldayne/boost
|
src/Map.php
|
Map.key_to_hash
|
private function key_to_hash($key)
{
if (null === $key) {
$hash = 'null';
} else if (is_int($key)) {
$hash = $key;
} else if (is_float($key)) {
$hash = "f_$key";
} else if (is_bool($key)) {
$hash = "b_$key";
} else if (is_string($key)) {
$hash = "s_$key";
} else if (is_object($key) || is_callable($key)) {
$hash = spl_object_hash($key);
} else if (is_array($key)) {
$hash = 'a_' . md5(json_encode($key));
} else if (is_resource($key)) {
$hash = "r_$key";
} else {
throw new \InvalidArgumentException(sprintf(
'Unsupported key type "%s"',
gettype($key)
));
}
$this->map_hash_to_key[$hash] = $key;
return $hash;
}
|
php
|
private function key_to_hash($key)
{
if (null === $key) {
$hash = 'null';
} else if (is_int($key)) {
$hash = $key;
} else if (is_float($key)) {
$hash = "f_$key";
} else if (is_bool($key)) {
$hash = "b_$key";
} else if (is_string($key)) {
$hash = "s_$key";
} else if (is_object($key) || is_callable($key)) {
$hash = spl_object_hash($key);
} else if (is_array($key)) {
$hash = 'a_' . md5(json_encode($key));
} else if (is_resource($key)) {
$hash = "r_$key";
} else {
throw new \InvalidArgumentException(sprintf(
'Unsupported key type "%s"',
gettype($key)
));
}
$this->map_hash_to_key[$hash] = $key;
return $hash;
}
|
[
"private",
"function",
"key_to_hash",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"key",
")",
"{",
"$",
"hash",
"=",
"'null'",
";",
"}",
"else",
"if",
"(",
"is_int",
"(",
"$",
"key",
")",
")",
"{",
"$",
"hash",
"=",
"$",
"key",
";",
"}",
"else",
"if",
"(",
"is_float",
"(",
"$",
"key",
")",
")",
"{",
"$",
"hash",
"=",
"\"f_$key\"",
";",
"}",
"else",
"if",
"(",
"is_bool",
"(",
"$",
"key",
")",
")",
"{",
"$",
"hash",
"=",
"\"b_$key\"",
";",
"}",
"else",
"if",
"(",
"is_string",
"(",
"$",
"key",
")",
")",
"{",
"$",
"hash",
"=",
"\"s_$key\"",
";",
"}",
"else",
"if",
"(",
"is_object",
"(",
"$",
"key",
")",
"||",
"is_callable",
"(",
"$",
"key",
")",
")",
"{",
"$",
"hash",
"=",
"spl_object_hash",
"(",
"$",
"key",
")",
";",
"}",
"else",
"if",
"(",
"is_array",
"(",
"$",
"key",
")",
")",
"{",
"$",
"hash",
"=",
"'a_'",
".",
"md5",
"(",
"json_encode",
"(",
"$",
"key",
")",
")",
";",
"}",
"else",
"if",
"(",
"is_resource",
"(",
"$",
"key",
")",
")",
"{",
"$",
"hash",
"=",
"\"r_$key\"",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Unsupported key type \"%s\"'",
",",
"gettype",
"(",
"$",
"key",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"map_hash_to_key",
"[",
"$",
"hash",
"]",
"=",
"$",
"key",
";",
"return",
"$",
"hash",
";",
"}"
] |
Lookup the hash for the given key. If a hash does not yet exist, one is
created.
@param mixed $key
@return string
@throws \InvalidArgumentException
|
[
"Lookup",
"the",
"hash",
"for",
"the",
"given",
"key",
".",
"If",
"a",
"hash",
"does",
"not",
"yet",
"exist",
"one",
"is",
"created",
"."
] |
d18cc398557e23f9c316ea7fb40b90f84cc53650
|
https://github.com/haldayne/boost/blob/d18cc398557e23f9c316ea7fb40b90f84cc53650/src/Map.php#L1009-L1044
|
20,103 |
haldayne/boost
|
src/Map.php
|
Map.hash_to_key
|
private function hash_to_key($hash)
{
if (array_key_exists($hash, $this->map_hash_to_key)) {
return $this->map_hash_to_key[$hash];
} else {
throw new \OutOfBoundsException(sprintf(
'Hash "%s" has not been created',
$hash
));
}
}
|
php
|
private function hash_to_key($hash)
{
if (array_key_exists($hash, $this->map_hash_to_key)) {
return $this->map_hash_to_key[$hash];
} else {
throw new \OutOfBoundsException(sprintf(
'Hash "%s" has not been created',
$hash
));
}
}
|
[
"private",
"function",
"hash_to_key",
"(",
"$",
"hash",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"hash",
",",
"$",
"this",
"->",
"map_hash_to_key",
")",
")",
"{",
"return",
"$",
"this",
"->",
"map_hash_to_key",
"[",
"$",
"hash",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"OutOfBoundsException",
"(",
"sprintf",
"(",
"'Hash \"%s\" has not been created'",
",",
"$",
"hash",
")",
")",
";",
"}",
"}"
] |
Lookup the key for the given hash.
@param string $hash
@return mixed
|
[
"Lookup",
"the",
"key",
"for",
"the",
"given",
"hash",
"."
] |
d18cc398557e23f9c316ea7fb40b90f84cc53650
|
https://github.com/haldayne/boost/blob/d18cc398557e23f9c316ea7fb40b90f84cc53650/src/Map.php#L1052-L1062
|
20,104 |
atkrad/data-tables
|
src/DataSource/ServerSide/CakePHP.php
|
CakePHP.setQuery
|
public function setQuery(Query $query)
{
$this->query = $query;
$this->clonedQuery = clone $query;
return $this;
}
|
php
|
public function setQuery(Query $query)
{
$this->query = $query;
$this->clonedQuery = clone $query;
return $this;
}
|
[
"public",
"function",
"setQuery",
"(",
"Query",
"$",
"query",
")",
"{",
"$",
"this",
"->",
"query",
"=",
"$",
"query",
";",
"$",
"this",
"->",
"clonedQuery",
"=",
"clone",
"$",
"query",
";",
"return",
"$",
"this",
";",
"}"
] |
Set CakePHP query
@param Query $query CakePHP query
@return CakePHP
|
[
"Set",
"CakePHP",
"query"
] |
5afcc337ab624ca626e29d9674459c5105982b16
|
https://github.com/atkrad/data-tables/blob/5afcc337ab624ca626e29d9674459c5105982b16/src/DataSource/ServerSide/CakePHP.php#L166-L172
|
20,105 |
atkrad/data-tables
|
src/DataSource/ServerSide/CakePHP.php
|
CakePHP.preparePaging
|
protected function preparePaging(Request $request)
{
self::$countBeforePaging = $this->query->count();
$this->query->limit($request->getLength());
$this->query->offset($request->getStart());
}
|
php
|
protected function preparePaging(Request $request)
{
self::$countBeforePaging = $this->query->count();
$this->query->limit($request->getLength());
$this->query->offset($request->getStart());
}
|
[
"protected",
"function",
"preparePaging",
"(",
"Request",
"$",
"request",
")",
"{",
"self",
"::",
"$",
"countBeforePaging",
"=",
"$",
"this",
"->",
"query",
"->",
"count",
"(",
")",
";",
"$",
"this",
"->",
"query",
"->",
"limit",
"(",
"$",
"request",
"->",
"getLength",
"(",
")",
")",
";",
"$",
"this",
"->",
"query",
"->",
"offset",
"(",
"$",
"request",
"->",
"getStart",
"(",
")",
")",
";",
"}"
] |
Prepare CakePHP paging
@param Request $request DataTable request
|
[
"Prepare",
"CakePHP",
"paging"
] |
5afcc337ab624ca626e29d9674459c5105982b16
|
https://github.com/atkrad/data-tables/blob/5afcc337ab624ca626e29d9674459c5105982b16/src/DataSource/ServerSide/CakePHP.php#L179-L184
|
20,106 |
atkrad/data-tables
|
src/DataSource/ServerSide/CakePHP.php
|
CakePHP.prepareSearch
|
protected function prepareSearch(Request $request)
{
$value = $request->getSearch()->getValue();
if (!empty($value)) {
$where = [];
foreach ($request->getColumns() as $column) {
if ($column->getSearchable() === true) {
$where[$column->getData() . ' LIKE'] = '%' . $value . '%';
}
}
$this->query->andWhere(
function (QueryExpression $exp) use ($where) {
return $exp->or_($where);
}
);
}
}
|
php
|
protected function prepareSearch(Request $request)
{
$value = $request->getSearch()->getValue();
if (!empty($value)) {
$where = [];
foreach ($request->getColumns() as $column) {
if ($column->getSearchable() === true) {
$where[$column->getData() . ' LIKE'] = '%' . $value . '%';
}
}
$this->query->andWhere(
function (QueryExpression $exp) use ($where) {
return $exp->or_($where);
}
);
}
}
|
[
"protected",
"function",
"prepareSearch",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"value",
"=",
"$",
"request",
"->",
"getSearch",
"(",
")",
"->",
"getValue",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"$",
"where",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"request",
"->",
"getColumns",
"(",
")",
"as",
"$",
"column",
")",
"{",
"if",
"(",
"$",
"column",
"->",
"getSearchable",
"(",
")",
"===",
"true",
")",
"{",
"$",
"where",
"[",
"$",
"column",
"->",
"getData",
"(",
")",
".",
"' LIKE'",
"]",
"=",
"'%'",
".",
"$",
"value",
".",
"'%'",
";",
"}",
"}",
"$",
"this",
"->",
"query",
"->",
"andWhere",
"(",
"function",
"(",
"QueryExpression",
"$",
"exp",
")",
"use",
"(",
"$",
"where",
")",
"{",
"return",
"$",
"exp",
"->",
"or_",
"(",
"$",
"where",
")",
";",
"}",
")",
";",
"}",
"}"
] |
Prepare CakePHP search
@param Request $request DataTable request
|
[
"Prepare",
"CakePHP",
"search"
] |
5afcc337ab624ca626e29d9674459c5105982b16
|
https://github.com/atkrad/data-tables/blob/5afcc337ab624ca626e29d9674459c5105982b16/src/DataSource/ServerSide/CakePHP.php#L191-L209
|
20,107 |
atkrad/data-tables
|
src/DataSource/ServerSide/CakePHP.php
|
CakePHP.prepareOrder
|
protected function prepareOrder(Request $request)
{
foreach ($request->getOrder() as $order) {
$this->query->order(
[$this->table->getColumns()[$order->getColumn()]->getData() => strtoupper($order->getDir())]
);
}
}
|
php
|
protected function prepareOrder(Request $request)
{
foreach ($request->getOrder() as $order) {
$this->query->order(
[$this->table->getColumns()[$order->getColumn()]->getData() => strtoupper($order->getDir())]
);
}
}
|
[
"protected",
"function",
"prepareOrder",
"(",
"Request",
"$",
"request",
")",
"{",
"foreach",
"(",
"$",
"request",
"->",
"getOrder",
"(",
")",
"as",
"$",
"order",
")",
"{",
"$",
"this",
"->",
"query",
"->",
"order",
"(",
"[",
"$",
"this",
"->",
"table",
"->",
"getColumns",
"(",
")",
"[",
"$",
"order",
"->",
"getColumn",
"(",
")",
"]",
"->",
"getData",
"(",
")",
"=>",
"strtoupper",
"(",
"$",
"order",
"->",
"getDir",
"(",
")",
")",
"]",
")",
";",
"}",
"}"
] |
Prepare CakePHP order
@param Request $request DataTable request
|
[
"Prepare",
"CakePHP",
"order"
] |
5afcc337ab624ca626e29d9674459c5105982b16
|
https://github.com/atkrad/data-tables/blob/5afcc337ab624ca626e29d9674459c5105982b16/src/DataSource/ServerSide/CakePHP.php#L216-L223
|
20,108 |
atkrad/data-tables
|
src/DataSource/ServerSide/CakePHP.php
|
CakePHP.getProperty
|
protected function getProperty($dataName)
{
$dataName = explode('.', trim($dataName));
if (count($dataName) != 2) {
throw new Exception('You are set invalid date.');
}
$tableAlias = $dataName[0];
$colName = $dataName[1];
if ($this->query->repository()->alias() == $tableAlias) {
return $colName;
} elseif (array_key_exists($tableAlias, $this->query->contain())) {
return [
'propertyPath' => $this->query
->eagerLoader()->normalized($this->query->repository())[$tableAlias]['propertyPath'],
'field' => $colName
];
}
}
|
php
|
protected function getProperty($dataName)
{
$dataName = explode('.', trim($dataName));
if (count($dataName) != 2) {
throw new Exception('You are set invalid date.');
}
$tableAlias = $dataName[0];
$colName = $dataName[1];
if ($this->query->repository()->alias() == $tableAlias) {
return $colName;
} elseif (array_key_exists($tableAlias, $this->query->contain())) {
return [
'propertyPath' => $this->query
->eagerLoader()->normalized($this->query->repository())[$tableAlias]['propertyPath'],
'field' => $colName
];
}
}
|
[
"protected",
"function",
"getProperty",
"(",
"$",
"dataName",
")",
"{",
"$",
"dataName",
"=",
"explode",
"(",
"'.'",
",",
"trim",
"(",
"$",
"dataName",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"dataName",
")",
"!=",
"2",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'You are set invalid date.'",
")",
";",
"}",
"$",
"tableAlias",
"=",
"$",
"dataName",
"[",
"0",
"]",
";",
"$",
"colName",
"=",
"$",
"dataName",
"[",
"1",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"query",
"->",
"repository",
"(",
")",
"->",
"alias",
"(",
")",
"==",
"$",
"tableAlias",
")",
"{",
"return",
"$",
"colName",
";",
"}",
"elseif",
"(",
"array_key_exists",
"(",
"$",
"tableAlias",
",",
"$",
"this",
"->",
"query",
"->",
"contain",
"(",
")",
")",
")",
"{",
"return",
"[",
"'propertyPath'",
"=>",
"$",
"this",
"->",
"query",
"->",
"eagerLoader",
"(",
")",
"->",
"normalized",
"(",
"$",
"this",
"->",
"query",
"->",
"repository",
"(",
")",
")",
"[",
"$",
"tableAlias",
"]",
"[",
"'propertyPath'",
"]",
",",
"'field'",
"=>",
"$",
"colName",
"]",
";",
"}",
"}"
] |
Get CakePHP property
@param string $dataName Column data name
@throws Exception
@return array|string
|
[
"Get",
"CakePHP",
"property"
] |
5afcc337ab624ca626e29d9674459c5105982b16
|
https://github.com/atkrad/data-tables/blob/5afcc337ab624ca626e29d9674459c5105982b16/src/DataSource/ServerSide/CakePHP.php#L233-L253
|
20,109 |
qcubed/orm
|
src/Query/Clause/OrderBy.php
|
OrderBy._UpdateQueryBuilder
|
public function _UpdateQueryBuilder(Builder $objBuilder)
{
$intLength = count($this->objNodeArray);
for ($intIndex = 0; $intIndex < $intLength; $intIndex++) {
$objNode = $this->objNodeArray[$intIndex];
if ($objNode instanceof Node\Virtual) {
if ($objNode->hasSubquery()) {
throw new Caller('You cannot define a virtual node in an order by clause. You must use an Expand clause to define it.');
}
$strOrderByCommand = '__' . $objNode->getAttributeName();
} elseif ($objNode instanceof Node\Column) {
/** @var Node\Column $objNode */
$strOrderByCommand = $objNode->getColumnAlias($objBuilder);
} elseif ($objNode instanceof iCondition) {
/** @var iCondition $objNode */
$strOrderByCommand = $objNode->getWhereClause($objBuilder);
} else {
$strOrderByCommand = '';
}
// Check to see if they want a ASC/DESC declarator
if ((($intIndex + 1) < $intLength) &&
!($this->objNodeArray[$intIndex + 1] instanceof Node\NodeBase)
) {
if ((!$this->objNodeArray[$intIndex + 1]) ||
(trim(strtolower($this->objNodeArray[$intIndex + 1])) == 'desc')
) {
$strOrderByCommand .= ' DESC';
} else {
$strOrderByCommand .= ' ASC';
}
$intIndex++;
}
$objBuilder->addOrderByItem($strOrderByCommand);
}
}
|
php
|
public function _UpdateQueryBuilder(Builder $objBuilder)
{
$intLength = count($this->objNodeArray);
for ($intIndex = 0; $intIndex < $intLength; $intIndex++) {
$objNode = $this->objNodeArray[$intIndex];
if ($objNode instanceof Node\Virtual) {
if ($objNode->hasSubquery()) {
throw new Caller('You cannot define a virtual node in an order by clause. You must use an Expand clause to define it.');
}
$strOrderByCommand = '__' . $objNode->getAttributeName();
} elseif ($objNode instanceof Node\Column) {
/** @var Node\Column $objNode */
$strOrderByCommand = $objNode->getColumnAlias($objBuilder);
} elseif ($objNode instanceof iCondition) {
/** @var iCondition $objNode */
$strOrderByCommand = $objNode->getWhereClause($objBuilder);
} else {
$strOrderByCommand = '';
}
// Check to see if they want a ASC/DESC declarator
if ((($intIndex + 1) < $intLength) &&
!($this->objNodeArray[$intIndex + 1] instanceof Node\NodeBase)
) {
if ((!$this->objNodeArray[$intIndex + 1]) ||
(trim(strtolower($this->objNodeArray[$intIndex + 1])) == 'desc')
) {
$strOrderByCommand .= ' DESC';
} else {
$strOrderByCommand .= ' ASC';
}
$intIndex++;
}
$objBuilder->addOrderByItem($strOrderByCommand);
}
}
|
[
"public",
"function",
"_UpdateQueryBuilder",
"(",
"Builder",
"$",
"objBuilder",
")",
"{",
"$",
"intLength",
"=",
"count",
"(",
"$",
"this",
"->",
"objNodeArray",
")",
";",
"for",
"(",
"$",
"intIndex",
"=",
"0",
";",
"$",
"intIndex",
"<",
"$",
"intLength",
";",
"$",
"intIndex",
"++",
")",
"{",
"$",
"objNode",
"=",
"$",
"this",
"->",
"objNodeArray",
"[",
"$",
"intIndex",
"]",
";",
"if",
"(",
"$",
"objNode",
"instanceof",
"Node",
"\\",
"Virtual",
")",
"{",
"if",
"(",
"$",
"objNode",
"->",
"hasSubquery",
"(",
")",
")",
"{",
"throw",
"new",
"Caller",
"(",
"'You cannot define a virtual node in an order by clause. You must use an Expand clause to define it.'",
")",
";",
"}",
"$",
"strOrderByCommand",
"=",
"'__'",
".",
"$",
"objNode",
"->",
"getAttributeName",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"objNode",
"instanceof",
"Node",
"\\",
"Column",
")",
"{",
"/** @var Node\\Column $objNode */",
"$",
"strOrderByCommand",
"=",
"$",
"objNode",
"->",
"getColumnAlias",
"(",
"$",
"objBuilder",
")",
";",
"}",
"elseif",
"(",
"$",
"objNode",
"instanceof",
"iCondition",
")",
"{",
"/** @var iCondition $objNode */",
"$",
"strOrderByCommand",
"=",
"$",
"objNode",
"->",
"getWhereClause",
"(",
"$",
"objBuilder",
")",
";",
"}",
"else",
"{",
"$",
"strOrderByCommand",
"=",
"''",
";",
"}",
"// Check to see if they want a ASC/DESC declarator",
"if",
"(",
"(",
"(",
"$",
"intIndex",
"+",
"1",
")",
"<",
"$",
"intLength",
")",
"&&",
"!",
"(",
"$",
"this",
"->",
"objNodeArray",
"[",
"$",
"intIndex",
"+",
"1",
"]",
"instanceof",
"Node",
"\\",
"NodeBase",
")",
")",
"{",
"if",
"(",
"(",
"!",
"$",
"this",
"->",
"objNodeArray",
"[",
"$",
"intIndex",
"+",
"1",
"]",
")",
"||",
"(",
"trim",
"(",
"strtolower",
"(",
"$",
"this",
"->",
"objNodeArray",
"[",
"$",
"intIndex",
"+",
"1",
"]",
")",
")",
"==",
"'desc'",
")",
")",
"{",
"$",
"strOrderByCommand",
".=",
"' DESC'",
";",
"}",
"else",
"{",
"$",
"strOrderByCommand",
".=",
"' ASC'",
";",
"}",
"$",
"intIndex",
"++",
";",
"}",
"$",
"objBuilder",
"->",
"addOrderByItem",
"(",
"$",
"strOrderByCommand",
")",
";",
"}",
"}"
] |
Updates the query builder according to this clause. This is called by the query builder only.
@param Builder $objBuilder
@throws Caller
|
[
"Updates",
"the",
"query",
"builder",
"according",
"to",
"this",
"clause",
".",
"This",
"is",
"called",
"by",
"the",
"query",
"builder",
"only",
"."
] |
f320eba671f20874b1f3809c5293f8c02d5b1204
|
https://github.com/qcubed/orm/blob/f320eba671f20874b1f3809c5293f8c02d5b1204/src/Query/Clause/OrderBy.php#L114-L150
|
20,110 |
2amigos/yiifoundation
|
widgets/Orbit.php
|
Orbit.renderOrbit
|
public function renderOrbit()
{
$contents = $list = array();
foreach ($this->items as $item) {
$list[] = $this->renderItem($item);
}
if ($this->showPreloader) {
$contents[] = \CHtml::tag('div', array('class' => Enum::ORBIT_LOADER), ' ');
}
$contents[] = \CHtml::tag(
'ul',
array(
'id' => $this->getId(),
'data-orbit' => 'data-orbit'
),
implode("\n", $list)
);
return \CHtml::tag('div', $this->htmlOptions, implode("\n", $contents));
}
|
php
|
public function renderOrbit()
{
$contents = $list = array();
foreach ($this->items as $item) {
$list[] = $this->renderItem($item);
}
if ($this->showPreloader) {
$contents[] = \CHtml::tag('div', array('class' => Enum::ORBIT_LOADER), ' ');
}
$contents[] = \CHtml::tag(
'ul',
array(
'id' => $this->getId(),
'data-orbit' => 'data-orbit'
),
implode("\n", $list)
);
return \CHtml::tag('div', $this->htmlOptions, implode("\n", $contents));
}
|
[
"public",
"function",
"renderOrbit",
"(",
")",
"{",
"$",
"contents",
"=",
"$",
"list",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"items",
"as",
"$",
"item",
")",
"{",
"$",
"list",
"[",
"]",
"=",
"$",
"this",
"->",
"renderItem",
"(",
"$",
"item",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"showPreloader",
")",
"{",
"$",
"contents",
"[",
"]",
"=",
"\\",
"CHtml",
"::",
"tag",
"(",
"'div'",
",",
"array",
"(",
"'class'",
"=>",
"Enum",
"::",
"ORBIT_LOADER",
")",
",",
"' '",
")",
";",
"}",
"$",
"contents",
"[",
"]",
"=",
"\\",
"CHtml",
"::",
"tag",
"(",
"'ul'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"getId",
"(",
")",
",",
"'data-orbit'",
"=>",
"'data-orbit'",
")",
",",
"implode",
"(",
"\"\\n\"",
",",
"$",
"list",
")",
")",
";",
"return",
"\\",
"CHtml",
"::",
"tag",
"(",
"'div'",
",",
"$",
"this",
"->",
"htmlOptions",
",",
"implode",
"(",
"\"\\n\"",
",",
"$",
"contents",
")",
")",
";",
"}"
] |
Renders the orbit plugin
@return string the generated HTML string
|
[
"Renders",
"the",
"orbit",
"plugin"
] |
49bed0d3ca1a9bac9299000e48a2661bdc8f9a29
|
https://github.com/2amigos/yiifoundation/blob/49bed0d3ca1a9bac9299000e48a2661bdc8f9a29/widgets/Orbit.php#L112-L132
|
20,111 |
2amigos/yiifoundation
|
widgets/Orbit.php
|
Orbit.renderItem
|
public function renderItem($item)
{
$content = ArrayHelper::getValue($item, 'content', '');
$caption = ArrayHelper::getValue($item, 'caption');
if ($caption !== null) {
$caption = \CHtml::tag('div', array('class' => Enum::ORBIT_CAPTION), $caption);
}
return \CHtml::tag('li', array(), $content . $caption);
}
|
php
|
public function renderItem($item)
{
$content = ArrayHelper::getValue($item, 'content', '');
$caption = ArrayHelper::getValue($item, 'caption');
if ($caption !== null) {
$caption = \CHtml::tag('div', array('class' => Enum::ORBIT_CAPTION), $caption);
}
return \CHtml::tag('li', array(), $content . $caption);
}
|
[
"public",
"function",
"renderItem",
"(",
"$",
"item",
")",
"{",
"$",
"content",
"=",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"item",
",",
"'content'",
",",
"''",
")",
";",
"$",
"caption",
"=",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"item",
",",
"'caption'",
")",
";",
"if",
"(",
"$",
"caption",
"!==",
"null",
")",
"{",
"$",
"caption",
"=",
"\\",
"CHtml",
"::",
"tag",
"(",
"'div'",
",",
"array",
"(",
"'class'",
"=>",
"Enum",
"::",
"ORBIT_CAPTION",
")",
",",
"$",
"caption",
")",
";",
"}",
"return",
"\\",
"CHtml",
"::",
"tag",
"(",
"'li'",
",",
"array",
"(",
")",
",",
"$",
"content",
".",
"$",
"caption",
")",
";",
"}"
] |
Returns a generated LI tag item
@param array $item the item configuration
@return string the resulting li tag
|
[
"Returns",
"a",
"generated",
"LI",
"tag",
"item"
] |
49bed0d3ca1a9bac9299000e48a2661bdc8f9a29
|
https://github.com/2amigos/yiifoundation/blob/49bed0d3ca1a9bac9299000e48a2661bdc8f9a29/widgets/Orbit.php#L139-L148
|
20,112 |
2amigos/yiifoundation
|
widgets/Orbit.php
|
Orbit.registerClientScript
|
public function registerClientScript()
{
if (!empty($this->pluginOptions)) {
$options = \CJavaScript::encode($this->pluginOptions);
\Yii::app()->clientScript
->registerScript('Orbit#' . $this->getId(), "$(document).foundation('orbit', {$options});");
}
if (!empty($this->events)) {
$this->registerEvents("#{$this->getId()}", $this->events);
}
}
|
php
|
public function registerClientScript()
{
if (!empty($this->pluginOptions)) {
$options = \CJavaScript::encode($this->pluginOptions);
\Yii::app()->clientScript
->registerScript('Orbit#' . $this->getId(), "$(document).foundation('orbit', {$options});");
}
if (!empty($this->events)) {
$this->registerEvents("#{$this->getId()}", $this->events);
}
}
|
[
"public",
"function",
"registerClientScript",
"(",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"pluginOptions",
")",
")",
"{",
"$",
"options",
"=",
"\\",
"CJavaScript",
"::",
"encode",
"(",
"$",
"this",
"->",
"pluginOptions",
")",
";",
"\\",
"Yii",
"::",
"app",
"(",
")",
"->",
"clientScript",
"->",
"registerScript",
"(",
"'Orbit#'",
".",
"$",
"this",
"->",
"getId",
"(",
")",
",",
"\"$(document).foundation('orbit', {$options});\"",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"events",
")",
")",
"{",
"$",
"this",
"->",
"registerEvents",
"(",
"\"#{$this->getId()}\"",
",",
"$",
"this",
"->",
"events",
")",
";",
"}",
"}"
] |
Registers the plugin script
|
[
"Registers",
"the",
"plugin",
"script"
] |
49bed0d3ca1a9bac9299000e48a2661bdc8f9a29
|
https://github.com/2amigos/yiifoundation/blob/49bed0d3ca1a9bac9299000e48a2661bdc8f9a29/widgets/Orbit.php#L153-L164
|
20,113 |
parsnick/steak
|
src/Console/BuildCommand.php
|
BuildCommand.runCleanTask
|
protected function runCleanTask($outputDir)
{
$cleanTime = $this->runTimedTask(function () use ($outputDir) {
$this->builder->clean($outputDir);
});
$this->output->writeln(
"<comment>Cleaned <path>{$outputDir}</path> in <time>{$cleanTime}ms</time></comment>",
OutputInterface::VERBOSITY_VERBOSE
);
}
|
php
|
protected function runCleanTask($outputDir)
{
$cleanTime = $this->runTimedTask(function () use ($outputDir) {
$this->builder->clean($outputDir);
});
$this->output->writeln(
"<comment>Cleaned <path>{$outputDir}</path> in <time>{$cleanTime}ms</time></comment>",
OutputInterface::VERBOSITY_VERBOSE
);
}
|
[
"protected",
"function",
"runCleanTask",
"(",
"$",
"outputDir",
")",
"{",
"$",
"cleanTime",
"=",
"$",
"this",
"->",
"runTimedTask",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"outputDir",
")",
"{",
"$",
"this",
"->",
"builder",
"->",
"clean",
"(",
"$",
"outputDir",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"\"<comment>Cleaned <path>{$outputDir}</path> in <time>{$cleanTime}ms</time></comment>\"",
",",
"OutputInterface",
"::",
"VERBOSITY_VERBOSE",
")",
";",
"}"
] |
Clean the output build directory.
@param string $outputDir
|
[
"Clean",
"the",
"output",
"build",
"directory",
"."
] |
461869189a640938438187330f6c50aca97c5ccc
|
https://github.com/parsnick/steak/blob/461869189a640938438187330f6c50aca97c5ccc/src/Console/BuildCommand.php#L92-L102
|
20,114 |
parsnick/steak
|
src/Console/BuildCommand.php
|
BuildCommand.runBuildTask
|
protected function runBuildTask($sourceDir, $outputDir)
{
$buildTime = $this->runTimedTask(function () use ($sourceDir, $outputDir) {
$this->builder->build($sourceDir, $outputDir);
});
$this->output->writeln(
"<comment>PHP built in <time>{$buildTime}ms</time></comment>",
OutputInterface::VERBOSITY_VERBOSE
);
}
|
php
|
protected function runBuildTask($sourceDir, $outputDir)
{
$buildTime = $this->runTimedTask(function () use ($sourceDir, $outputDir) {
$this->builder->build($sourceDir, $outputDir);
});
$this->output->writeln(
"<comment>PHP built in <time>{$buildTime}ms</time></comment>",
OutputInterface::VERBOSITY_VERBOSE
);
}
|
[
"protected",
"function",
"runBuildTask",
"(",
"$",
"sourceDir",
",",
"$",
"outputDir",
")",
"{",
"$",
"buildTime",
"=",
"$",
"this",
"->",
"runTimedTask",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"sourceDir",
",",
"$",
"outputDir",
")",
"{",
"$",
"this",
"->",
"builder",
"->",
"build",
"(",
"$",
"sourceDir",
",",
"$",
"outputDir",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"\"<comment>PHP built in <time>{$buildTime}ms</time></comment>\"",
",",
"OutputInterface",
"::",
"VERBOSITY_VERBOSE",
")",
";",
"}"
] |
Build the new site pages.
@param string $sourceDir
@param string $outputDir
|
[
"Build",
"the",
"new",
"site",
"pages",
"."
] |
461869189a640938438187330f6c50aca97c5ccc
|
https://github.com/parsnick/steak/blob/461869189a640938438187330f6c50aca97c5ccc/src/Console/BuildCommand.php#L110-L120
|
20,115 |
parsnick/steak
|
src/Console/BuildCommand.php
|
BuildCommand.runGulpTask
|
protected function runGulpTask()
{
$this->output->writeln("<comment>Starting gulp...</comment>", OutputInterface::VERBOSITY_VERY_VERBOSE);
$process = $this->createGulpProcess('steak:build');
$callback = $this->getProcessLogger($this->output);
$timer = new Stopwatch();
$timer->start('gulp');
try {
$process->mustRun($callback);
$this->output->writeln(
"<comment>gulp published in <time>{$timer->stop('gulp')->getDuration()}ms</time></comment>",
OutputInterface::VERBOSITY_VERBOSE
);
} catch (ProcessFailedException $exception) {
$this->output->writeln(
"<error>gulp process failed after <time>{$timer->stop('gulp')->getDuration()}ms</time></error>",
OutputInterface::VERBOSITY_VERBOSE
);
if (str_contains($process->getOutput(), 'Local gulp not found') || str_contains($process->getErrorOutput(), 'Cannot find module')) {
$this->output->writeln("<comment>Missing npm dependencies, attempting install. This might take a minute...</comment>");
$this->output->writeln(' <comment>$</comment> npm install', OutputInterface::VERBOSITY_VERBOSE);
try {
$npmInstallTime = $this->runTimedTask(function () {
(new Process('npm install', $this->container['config']['source.directory']))->setTimeout(180)->mustRun();
});
$this->output->writeln(" <comment>npm installed in in <time>{$npmInstallTime}ms</time></comment>", OutputInterface::VERBOSITY_VERBOSE);
$this->output->writeln('<comment>Retrying <b>steak:publish</b> task...</comment>');
$process->mustRun($callback);
} catch (RuntimeException $exception) {
$this->output->writeln("We tried but <error>npm install</error> failed");
}
}
}
}
|
php
|
protected function runGulpTask()
{
$this->output->writeln("<comment>Starting gulp...</comment>", OutputInterface::VERBOSITY_VERY_VERBOSE);
$process = $this->createGulpProcess('steak:build');
$callback = $this->getProcessLogger($this->output);
$timer = new Stopwatch();
$timer->start('gulp');
try {
$process->mustRun($callback);
$this->output->writeln(
"<comment>gulp published in <time>{$timer->stop('gulp')->getDuration()}ms</time></comment>",
OutputInterface::VERBOSITY_VERBOSE
);
} catch (ProcessFailedException $exception) {
$this->output->writeln(
"<error>gulp process failed after <time>{$timer->stop('gulp')->getDuration()}ms</time></error>",
OutputInterface::VERBOSITY_VERBOSE
);
if (str_contains($process->getOutput(), 'Local gulp not found') || str_contains($process->getErrorOutput(), 'Cannot find module')) {
$this->output->writeln("<comment>Missing npm dependencies, attempting install. This might take a minute...</comment>");
$this->output->writeln(' <comment>$</comment> npm install', OutputInterface::VERBOSITY_VERBOSE);
try {
$npmInstallTime = $this->runTimedTask(function () {
(new Process('npm install', $this->container['config']['source.directory']))->setTimeout(180)->mustRun();
});
$this->output->writeln(" <comment>npm installed in in <time>{$npmInstallTime}ms</time></comment>", OutputInterface::VERBOSITY_VERBOSE);
$this->output->writeln('<comment>Retrying <b>steak:publish</b> task...</comment>');
$process->mustRun($callback);
} catch (RuntimeException $exception) {
$this->output->writeln("We tried but <error>npm install</error> failed");
}
}
}
}
|
[
"protected",
"function",
"runGulpTask",
"(",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"\"<comment>Starting gulp...</comment>\"",
",",
"OutputInterface",
"::",
"VERBOSITY_VERY_VERBOSE",
")",
";",
"$",
"process",
"=",
"$",
"this",
"->",
"createGulpProcess",
"(",
"'steak:build'",
")",
";",
"$",
"callback",
"=",
"$",
"this",
"->",
"getProcessLogger",
"(",
"$",
"this",
"->",
"output",
")",
";",
"$",
"timer",
"=",
"new",
"Stopwatch",
"(",
")",
";",
"$",
"timer",
"->",
"start",
"(",
"'gulp'",
")",
";",
"try",
"{",
"$",
"process",
"->",
"mustRun",
"(",
"$",
"callback",
")",
";",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"\"<comment>gulp published in <time>{$timer->stop('gulp')->getDuration()}ms</time></comment>\"",
",",
"OutputInterface",
"::",
"VERBOSITY_VERBOSE",
")",
";",
"}",
"catch",
"(",
"ProcessFailedException",
"$",
"exception",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"\"<error>gulp process failed after <time>{$timer->stop('gulp')->getDuration()}ms</time></error>\"",
",",
"OutputInterface",
"::",
"VERBOSITY_VERBOSE",
")",
";",
"if",
"(",
"str_contains",
"(",
"$",
"process",
"->",
"getOutput",
"(",
")",
",",
"'Local gulp not found'",
")",
"||",
"str_contains",
"(",
"$",
"process",
"->",
"getErrorOutput",
"(",
")",
",",
"'Cannot find module'",
")",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"\"<comment>Missing npm dependencies, attempting install. This might take a minute...</comment>\"",
")",
";",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"' <comment>$</comment> npm install'",
",",
"OutputInterface",
"::",
"VERBOSITY_VERBOSE",
")",
";",
"try",
"{",
"$",
"npmInstallTime",
"=",
"$",
"this",
"->",
"runTimedTask",
"(",
"function",
"(",
")",
"{",
"(",
"new",
"Process",
"(",
"'npm install'",
",",
"$",
"this",
"->",
"container",
"[",
"'config'",
"]",
"[",
"'source.directory'",
"]",
")",
")",
"->",
"setTimeout",
"(",
"180",
")",
"->",
"mustRun",
"(",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"\" <comment>npm installed in in <time>{$npmInstallTime}ms</time></comment>\"",
",",
"OutputInterface",
"::",
"VERBOSITY_VERBOSE",
")",
";",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"'<comment>Retrying <b>steak:publish</b> task...</comment>'",
")",
";",
"$",
"process",
"->",
"mustRun",
"(",
"$",
"callback",
")",
";",
"}",
"catch",
"(",
"RuntimeException",
"$",
"exception",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"\"We tried but <error>npm install</error> failed\"",
")",
";",
"}",
"}",
"}",
"}"
] |
Trigger gulp to copy other assets to the build dir.
|
[
"Trigger",
"gulp",
"to",
"copy",
"other",
"assets",
"to",
"the",
"build",
"dir",
"."
] |
461869189a640938438187330f6c50aca97c5ccc
|
https://github.com/parsnick/steak/blob/461869189a640938438187330f6c50aca97c5ccc/src/Console/BuildCommand.php#L125-L173
|
20,116 |
comodojo/cookies
|
src/Comodojo/Cookies/Cookie.php
|
Cookie.create
|
public static function create($name, array $properties = [], $serialize = true) {
try {
$class = get_called_class();
$cookie = new $class($name);
CookieTools::setCookieProperties($cookie, $properties, $serialize);
} catch (CookieException $ce) {
throw $ce;
}
return $cookie;
}
|
php
|
public static function create($name, array $properties = [], $serialize = true) {
try {
$class = get_called_class();
$cookie = new $class($name);
CookieTools::setCookieProperties($cookie, $properties, $serialize);
} catch (CookieException $ce) {
throw $ce;
}
return $cookie;
}
|
[
"public",
"static",
"function",
"create",
"(",
"$",
"name",
",",
"array",
"$",
"properties",
"=",
"[",
"]",
",",
"$",
"serialize",
"=",
"true",
")",
"{",
"try",
"{",
"$",
"class",
"=",
"get_called_class",
"(",
")",
";",
"$",
"cookie",
"=",
"new",
"$",
"class",
"(",
"$",
"name",
")",
";",
"CookieTools",
"::",
"setCookieProperties",
"(",
"$",
"cookie",
",",
"$",
"properties",
",",
"$",
"serialize",
")",
";",
"}",
"catch",
"(",
"CookieException",
"$",
"ce",
")",
"{",
"throw",
"$",
"ce",
";",
"}",
"return",
"$",
"cookie",
";",
"}"
] |
Static method to quickly create a cookie
@param string $name
The cookie name
@param array $properties
Array of properties cookie should have
@return self
@throws CookieException
|
[
"Static",
"method",
"to",
"quickly",
"create",
"a",
"cookie"
] |
a81c7dff37d52c1a75462c0ad30db75d0c3b0081
|
https://github.com/comodojo/cookies/blob/a81c7dff37d52c1a75462c0ad30db75d0c3b0081/src/Comodojo/Cookies/Cookie.php#L63-L81
|
20,117 |
comodojo/cookies
|
src/Comodojo/Cookies/Cookie.php
|
Cookie.retrieve
|
public static function retrieve($name) {
try {
$class = get_called_class();
$cookie = new $class($name);
return $cookie->load();
} catch (CookieException $ce) {
throw $ce;
}
}
|
php
|
public static function retrieve($name) {
try {
$class = get_called_class();
$cookie = new $class($name);
return $cookie->load();
} catch (CookieException $ce) {
throw $ce;
}
}
|
[
"public",
"static",
"function",
"retrieve",
"(",
"$",
"name",
")",
"{",
"try",
"{",
"$",
"class",
"=",
"get_called_class",
"(",
")",
";",
"$",
"cookie",
"=",
"new",
"$",
"class",
"(",
"$",
"name",
")",
";",
"return",
"$",
"cookie",
"->",
"load",
"(",
")",
";",
"}",
"catch",
"(",
"CookieException",
"$",
"ce",
")",
"{",
"throw",
"$",
"ce",
";",
"}",
"}"
] |
Static method to quickly get a cookie
@param string $name
The cookie name
@return self
@throws CookieException
|
[
"Static",
"method",
"to",
"quickly",
"get",
"a",
"cookie"
] |
a81c7dff37d52c1a75462c0ad30db75d0c3b0081
|
https://github.com/comodojo/cookies/blob/a81c7dff37d52c1a75462c0ad30db75d0c3b0081/src/Comodojo/Cookies/Cookie.php#L92-L108
|
20,118 |
ronanguilloux/SilexMarkdownServiceProvider
|
src/Rg/Markdown/Finder.php
|
Finder.getContent
|
public function getContent($path)
{
// only a page index was given ?
if (('0' == $path) || (int) ($path) > 0) {
$path = $this->findByIndex($path);
} else {
$path = $this->basePath . '/' . $path;
$infos = pathinfo($path);
// was the extension given ?
if (empty($infos['extension'])) {
$path .= '.md';
}
}
if (file_exists($path)) {
return file_get_contents($path);
}
return false;
}
|
php
|
public function getContent($path)
{
// only a page index was given ?
if (('0' == $path) || (int) ($path) > 0) {
$path = $this->findByIndex($path);
} else {
$path = $this->basePath . '/' . $path;
$infos = pathinfo($path);
// was the extension given ?
if (empty($infos['extension'])) {
$path .= '.md';
}
}
if (file_exists($path)) {
return file_get_contents($path);
}
return false;
}
|
[
"public",
"function",
"getContent",
"(",
"$",
"path",
")",
"{",
"// only a page index was given ?",
"if",
"(",
"(",
"'0'",
"==",
"$",
"path",
")",
"||",
"(",
"int",
")",
"(",
"$",
"path",
")",
">",
"0",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"findByIndex",
"(",
"$",
"path",
")",
";",
"}",
"else",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"basePath",
".",
"'/'",
".",
"$",
"path",
";",
"$",
"infos",
"=",
"pathinfo",
"(",
"$",
"path",
")",
";",
"// was the extension given ?",
"if",
"(",
"empty",
"(",
"$",
"infos",
"[",
"'extension'",
"]",
")",
")",
"{",
"$",
"path",
".=",
"'.md'",
";",
"}",
"}",
"if",
"(",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"return",
"file_get_contents",
"(",
"$",
"path",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
getContent
Retrieve a file content using the given path
@param string $path the markdown file path
@return mixed: false or the markdown file raw content (string)
|
[
"getContent",
"Retrieve",
"a",
"file",
"content",
"using",
"the",
"given",
"path"
] |
8266baf0b8a74a98ea32ba1417d767dca6b374b3
|
https://github.com/ronanguilloux/SilexMarkdownServiceProvider/blob/8266baf0b8a74a98ea32ba1417d767dca6b374b3/src/Rg/Markdown/Finder.php#L51-L69
|
20,119 |
ronanguilloux/SilexMarkdownServiceProvider
|
src/Rg/Markdown/Finder.php
|
Finder.getList
|
public function getList()
{
$list = glob($this->basePath . "/*.md");
foreach ($list as $key=>$item) {
$item = pathinfo($item);
$item = $item['filename'];
$item = preg_split("/^[\d-]+/", $item, 2, PREG_SPLIT_NO_EMPTY);
$list[$key] = ucfirst(str_replace('-',' ',$item[0]));
}
return $list;
}
|
php
|
public function getList()
{
$list = glob($this->basePath . "/*.md");
foreach ($list as $key=>$item) {
$item = pathinfo($item);
$item = $item['filename'];
$item = preg_split("/^[\d-]+/", $item, 2, PREG_SPLIT_NO_EMPTY);
$list[$key] = ucfirst(str_replace('-',' ',$item[0]));
}
return $list;
}
|
[
"public",
"function",
"getList",
"(",
")",
"{",
"$",
"list",
"=",
"glob",
"(",
"$",
"this",
"->",
"basePath",
".",
"\"/*.md\"",
")",
";",
"foreach",
"(",
"$",
"list",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"$",
"item",
"=",
"pathinfo",
"(",
"$",
"item",
")",
";",
"$",
"item",
"=",
"$",
"item",
"[",
"'filename'",
"]",
";",
"$",
"item",
"=",
"preg_split",
"(",
"\"/^[\\d-]+/\"",
",",
"$",
"item",
",",
"2",
",",
"PREG_SPLIT_NO_EMPTY",
")",
";",
"$",
"list",
"[",
"$",
"key",
"]",
"=",
"ucfirst",
"(",
"str_replace",
"(",
"'-'",
",",
"' '",
",",
"$",
"item",
"[",
"0",
"]",
")",
")",
";",
"}",
"return",
"$",
"list",
";",
"}"
] |
getList
In the file list returned, in array values, '-' become spaces.
@return array mardown file list
|
[
"getList",
"In",
"the",
"file",
"list",
"returned",
"in",
"array",
"values",
"-",
"become",
"spaces",
"."
] |
8266baf0b8a74a98ea32ba1417d767dca6b374b3
|
https://github.com/ronanguilloux/SilexMarkdownServiceProvider/blob/8266baf0b8a74a98ea32ba1417d767dca6b374b3/src/Rg/Markdown/Finder.php#L96-L107
|
20,120 |
jpcercal/resource-query-language
|
src/Parser/AbstractParser.php
|
AbstractParser.process
|
public function process(ExprBuilder $builder, $field, $expression, $value)
{
if (!Expr::isValidExpression($expression)) {
throw new ParserException(sprintf(
'The expression "%s" is not allowed or not exists.',
$expression
));
}
switch ($expression) {
case 'between':
set_error_handler(function () use ($value) {
throw new ParserException(sprintf(
'The value of "between" expression "%s" is not valid.',
$value
));
});
list($from, $to) = explode('-', $value);
restore_error_handler();
return $builder->between($field, $from, $to);
case 'paginate':
set_error_handler(function () use ($value) {
throw new ParserException(sprintf(
'The value of "paginate" expression "%s" is not valid.',
$value
));
});
list($currentPageNumber, $maxResultsPerPage) = explode('-', $value);
restore_error_handler();
return $builder->paginate($currentPageNumber, $maxResultsPerPage);
case 'or':
return $builder->orx($value);
default:
return $builder->{$expression}($field, $value);
}
}
|
php
|
public function process(ExprBuilder $builder, $field, $expression, $value)
{
if (!Expr::isValidExpression($expression)) {
throw new ParserException(sprintf(
'The expression "%s" is not allowed or not exists.',
$expression
));
}
switch ($expression) {
case 'between':
set_error_handler(function () use ($value) {
throw new ParserException(sprintf(
'The value of "between" expression "%s" is not valid.',
$value
));
});
list($from, $to) = explode('-', $value);
restore_error_handler();
return $builder->between($field, $from, $to);
case 'paginate':
set_error_handler(function () use ($value) {
throw new ParserException(sprintf(
'The value of "paginate" expression "%s" is not valid.',
$value
));
});
list($currentPageNumber, $maxResultsPerPage) = explode('-', $value);
restore_error_handler();
return $builder->paginate($currentPageNumber, $maxResultsPerPage);
case 'or':
return $builder->orx($value);
default:
return $builder->{$expression}($field, $value);
}
}
|
[
"public",
"function",
"process",
"(",
"ExprBuilder",
"$",
"builder",
",",
"$",
"field",
",",
"$",
"expression",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"Expr",
"::",
"isValidExpression",
"(",
"$",
"expression",
")",
")",
"{",
"throw",
"new",
"ParserException",
"(",
"sprintf",
"(",
"'The expression \"%s\" is not allowed or not exists.'",
",",
"$",
"expression",
")",
")",
";",
"}",
"switch",
"(",
"$",
"expression",
")",
"{",
"case",
"'between'",
":",
"set_error_handler",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"value",
")",
"{",
"throw",
"new",
"ParserException",
"(",
"sprintf",
"(",
"'The value of \"between\" expression \"%s\" is not valid.'",
",",
"$",
"value",
")",
")",
";",
"}",
")",
";",
"list",
"(",
"$",
"from",
",",
"$",
"to",
")",
"=",
"explode",
"(",
"'-'",
",",
"$",
"value",
")",
";",
"restore_error_handler",
"(",
")",
";",
"return",
"$",
"builder",
"->",
"between",
"(",
"$",
"field",
",",
"$",
"from",
",",
"$",
"to",
")",
";",
"case",
"'paginate'",
":",
"set_error_handler",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"value",
")",
"{",
"throw",
"new",
"ParserException",
"(",
"sprintf",
"(",
"'The value of \"paginate\" expression \"%s\" is not valid.'",
",",
"$",
"value",
")",
")",
";",
"}",
")",
";",
"list",
"(",
"$",
"currentPageNumber",
",",
"$",
"maxResultsPerPage",
")",
"=",
"explode",
"(",
"'-'",
",",
"$",
"value",
")",
";",
"restore_error_handler",
"(",
")",
";",
"return",
"$",
"builder",
"->",
"paginate",
"(",
"$",
"currentPageNumber",
",",
"$",
"maxResultsPerPage",
")",
";",
"case",
"'or'",
":",
"return",
"$",
"builder",
"->",
"orx",
"(",
"$",
"value",
")",
";",
"default",
":",
"return",
"$",
"builder",
"->",
"{",
"$",
"expression",
"}",
"(",
"$",
"field",
",",
"$",
"value",
")",
";",
"}",
"}"
] |
Process one expression an enqueue it using the ExprBuilder instance.
@param ExprBuilder $builder
@param string $field
@param string $expression
@param string $value
@return ExprBuilder
@throws ParserException
|
[
"Process",
"one",
"expression",
"an",
"enqueue",
"it",
"using",
"the",
"ExprBuilder",
"instance",
"."
] |
2a1520198c717a8199cd8d3d85ca2557e24cb7f5
|
https://github.com/jpcercal/resource-query-language/blob/2a1520198c717a8199cd8d3d85ca2557e24cb7f5/src/Parser/AbstractParser.php#L53-L94
|
20,121 |
yuncms/framework
|
src/filters/OAuth2Authorize.php
|
OAuth2Authorize.afterAction
|
public function afterAction($action, $result)
{
if (Yii::$app->user->isGuest) {
return $result;
} else {
return $this->finishAuthorization();
}
}
|
php
|
public function afterAction($action, $result)
{
if (Yii::$app->user->isGuest) {
return $result;
} else {
return $this->finishAuthorization();
}
}
|
[
"public",
"function",
"afterAction",
"(",
"$",
"action",
",",
"$",
"result",
")",
"{",
"if",
"(",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"isGuest",
")",
"{",
"return",
"$",
"result",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"finishAuthorization",
"(",
")",
";",
"}",
"}"
] |
If user is logged on, do oauth login immediatly,
continue authorization in the another case
@param \yii\base\Action $action
@param mixed $result
@return mixed
@throws Exception
|
[
"If",
"user",
"is",
"logged",
"on",
"do",
"oauth",
"login",
"immediatly",
"continue",
"authorization",
"in",
"the",
"another",
"case"
] |
af42e28ea4ae15ab8eead3f6d119f93863b94154
|
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/filters/OAuth2Authorize.php#L95-L102
|
20,122 |
silverbusters/silverstripe-simplelistfield
|
forms/SimpleListField/SimpleListField.php
|
SimpleListField.addScenarioFromYml
|
public static function addScenarioFromYml($key){
$cfg = Config::inst()->get('SimpleListField', 'Scenarios');
if( isset($cfg[$key]) ){
if( (isset($cfg[$key]['preload']) && !$cfg[$key]['preload']) || !isset($cfg[$key]['preload']) ){
self::$scenarios[$key] = $cfg[$key];
}
}
}
|
php
|
public static function addScenarioFromYml($key){
$cfg = Config::inst()->get('SimpleListField', 'Scenarios');
if( isset($cfg[$key]) ){
if( (isset($cfg[$key]['preload']) && !$cfg[$key]['preload']) || !isset($cfg[$key]['preload']) ){
self::$scenarios[$key] = $cfg[$key];
}
}
}
|
[
"public",
"static",
"function",
"addScenarioFromYml",
"(",
"$",
"key",
")",
"{",
"$",
"cfg",
"=",
"Config",
"::",
"inst",
"(",
")",
"->",
"get",
"(",
"'SimpleListField'",
",",
"'Scenarios'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"cfg",
"[",
"$",
"key",
"]",
")",
")",
"{",
"if",
"(",
"(",
"isset",
"(",
"$",
"cfg",
"[",
"$",
"key",
"]",
"[",
"'preload'",
"]",
")",
"&&",
"!",
"$",
"cfg",
"[",
"$",
"key",
"]",
"[",
"'preload'",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"cfg",
"[",
"$",
"key",
"]",
"[",
"'preload'",
"]",
")",
")",
"{",
"self",
"::",
"$",
"scenarios",
"[",
"$",
"key",
"]",
"=",
"$",
"cfg",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"}"
] |
Add single scenario by using yml configuration
|
[
"Add",
"single",
"scenario",
"by",
"using",
"yml",
"configuration"
] |
c883e13b1b877d74e266edf2a646661039803440
|
https://github.com/silverbusters/silverstripe-simplelistfield/blob/c883e13b1b877d74e266edf2a646661039803440/forms/SimpleListField/SimpleListField.php#L115-L123
|
20,123 |
askupasoftware/amarkal
|
Extensions/WordPress/MetaBox/MetaBox.php
|
MetaBox.add_meta_boxes
|
public function add_meta_boxes( $post_type )
{
if ( in_array( $post_type, $this->settings['post_types'] )) {
add_meta_box(
$this->settings['id'],
$this->settings['title'],
array( $this, 'render' ),
$post_type,
$this->settings['context'],
$this->settings['priority']
);
}
}
|
php
|
public function add_meta_boxes( $post_type )
{
if ( in_array( $post_type, $this->settings['post_types'] )) {
add_meta_box(
$this->settings['id'],
$this->settings['title'],
array( $this, 'render' ),
$post_type,
$this->settings['context'],
$this->settings['priority']
);
}
}
|
[
"public",
"function",
"add_meta_boxes",
"(",
"$",
"post_type",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"post_type",
",",
"$",
"this",
"->",
"settings",
"[",
"'post_types'",
"]",
")",
")",
"{",
"add_meta_box",
"(",
"$",
"this",
"->",
"settings",
"[",
"'id'",
"]",
",",
"$",
"this",
"->",
"settings",
"[",
"'title'",
"]",
",",
"array",
"(",
"$",
"this",
",",
"'render'",
")",
",",
"$",
"post_type",
",",
"$",
"this",
"->",
"settings",
"[",
"'context'",
"]",
",",
"$",
"this",
"->",
"settings",
"[",
"'priority'",
"]",
")",
";",
"}",
"}"
] |
Adds the meta box container.
|
[
"Adds",
"the",
"meta",
"box",
"container",
"."
] |
fe8283e2d6847ef697abec832da7ee741a85058c
|
https://github.com/askupasoftware/amarkal/blob/fe8283e2d6847ef697abec832da7ee741a85058c/Extensions/WordPress/MetaBox/MetaBox.php#L114-L126
|
20,124 |
askupasoftware/amarkal
|
Extensions/WordPress/MetaBox/MetaBox.php
|
MetaBox.save
|
public function save( $post_id )
{
/**
* A note on security:
*
* We need to verify this came from the our screen and with proper authorization,
* because save_post can be triggered at other times. since metaboxes can
* be removed - by having a nonce field in only one metabox there is no
* guarantee the nonce will be there. By placing a nonce field in each
* metabox you can check if data from that metabox has been sent
* (and is actually from where you think it is) prior to processing any data.
* @see http://wordpress.stackexchange.com/a/49460/25959
*/
// Check if our nonce is set.
if ( ! isset( $_POST[$this->nonce_name()] ) )
{
return $post_id;
}
// Verify that the nonce is valid.
$nonce = filter_input( INPUT_POST, $this->nonce_name() );
if ( ! wp_verify_nonce( $nonce, $this->action_name() ) )
{
return $post_id;
}
// Bail if this is an autosave (nothing has been submitted)
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
{
return $post_id;
}
// Check the user's permissions.
$post_type = filter_input( INPUT_POST, 'post_type' );
if( in_array( $post_type, $this->settings['post_types'] ) )
{
// NOTE: this might not work for custom post types, unless Amarkal
// is used to register them (custom post types might have labels different
// than 'edit_{post_type}'
$capability = 'edit_'.$post_type;
if ( !current_user_can( $capability, $post_id ) )
{
return $post_id;
}
}
else
{
return $post_id;
}
// OK, it is safe to process data.
$old_instance = \get_post_meta( $post_id, $this->settings['id'], true );
$new_instance = $this->form->updater->update( $old_instance === "" ? array() : $old_instance );
\update_post_meta( $post_id, $this->settings['id'], $new_instance );
// Callback
$callable = $this->settings['callback'];
if(is_callable( $callable ) )
{
$callable( $post_id, $new_instance );
}
}
|
php
|
public function save( $post_id )
{
/**
* A note on security:
*
* We need to verify this came from the our screen and with proper authorization,
* because save_post can be triggered at other times. since metaboxes can
* be removed - by having a nonce field in only one metabox there is no
* guarantee the nonce will be there. By placing a nonce field in each
* metabox you can check if data from that metabox has been sent
* (and is actually from where you think it is) prior to processing any data.
* @see http://wordpress.stackexchange.com/a/49460/25959
*/
// Check if our nonce is set.
if ( ! isset( $_POST[$this->nonce_name()] ) )
{
return $post_id;
}
// Verify that the nonce is valid.
$nonce = filter_input( INPUT_POST, $this->nonce_name() );
if ( ! wp_verify_nonce( $nonce, $this->action_name() ) )
{
return $post_id;
}
// Bail if this is an autosave (nothing has been submitted)
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
{
return $post_id;
}
// Check the user's permissions.
$post_type = filter_input( INPUT_POST, 'post_type' );
if( in_array( $post_type, $this->settings['post_types'] ) )
{
// NOTE: this might not work for custom post types, unless Amarkal
// is used to register them (custom post types might have labels different
// than 'edit_{post_type}'
$capability = 'edit_'.$post_type;
if ( !current_user_can( $capability, $post_id ) )
{
return $post_id;
}
}
else
{
return $post_id;
}
// OK, it is safe to process data.
$old_instance = \get_post_meta( $post_id, $this->settings['id'], true );
$new_instance = $this->form->updater->update( $old_instance === "" ? array() : $old_instance );
\update_post_meta( $post_id, $this->settings['id'], $new_instance );
// Callback
$callable = $this->settings['callback'];
if(is_callable( $callable ) )
{
$callable( $post_id, $new_instance );
}
}
|
[
"public",
"function",
"save",
"(",
"$",
"post_id",
")",
"{",
"/**\n * A note on security:\n * \n * We need to verify this came from the our screen and with proper authorization,\n * because save_post can be triggered at other times. since metaboxes can \n * be removed - by having a nonce field in only one metabox there is no \n * guarantee the nonce will be there. By placing a nonce field in each \n * metabox you can check if data from that metabox has been sent \n * (and is actually from where you think it is) prior to processing any data.\n * @see http://wordpress.stackexchange.com/a/49460/25959\n */",
"// Check if our nonce is set.",
"if",
"(",
"!",
"isset",
"(",
"$",
"_POST",
"[",
"$",
"this",
"->",
"nonce_name",
"(",
")",
"]",
")",
")",
"{",
"return",
"$",
"post_id",
";",
"}",
"// Verify that the nonce is valid.",
"$",
"nonce",
"=",
"filter_input",
"(",
"INPUT_POST",
",",
"$",
"this",
"->",
"nonce_name",
"(",
")",
")",
";",
"if",
"(",
"!",
"wp_verify_nonce",
"(",
"$",
"nonce",
",",
"$",
"this",
"->",
"action_name",
"(",
")",
")",
")",
"{",
"return",
"$",
"post_id",
";",
"}",
"// Bail if this is an autosave (nothing has been submitted)",
"if",
"(",
"defined",
"(",
"'DOING_AUTOSAVE'",
")",
"&&",
"DOING_AUTOSAVE",
")",
"{",
"return",
"$",
"post_id",
";",
"}",
"// Check the user's permissions.",
"$",
"post_type",
"=",
"filter_input",
"(",
"INPUT_POST",
",",
"'post_type'",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"post_type",
",",
"$",
"this",
"->",
"settings",
"[",
"'post_types'",
"]",
")",
")",
"{",
"// NOTE: this might not work for custom post types, unless Amarkal",
"// is used to register them (custom post types might have labels different ",
"// than 'edit_{post_type}'",
"$",
"capability",
"=",
"'edit_'",
".",
"$",
"post_type",
";",
"if",
"(",
"!",
"current_user_can",
"(",
"$",
"capability",
",",
"$",
"post_id",
")",
")",
"{",
"return",
"$",
"post_id",
";",
"}",
"}",
"else",
"{",
"return",
"$",
"post_id",
";",
"}",
"// OK, it is safe to process data.",
"$",
"old_instance",
"=",
"\\",
"get_post_meta",
"(",
"$",
"post_id",
",",
"$",
"this",
"->",
"settings",
"[",
"'id'",
"]",
",",
"true",
")",
";",
"$",
"new_instance",
"=",
"$",
"this",
"->",
"form",
"->",
"updater",
"->",
"update",
"(",
"$",
"old_instance",
"===",
"\"\"",
"?",
"array",
"(",
")",
":",
"$",
"old_instance",
")",
";",
"\\",
"update_post_meta",
"(",
"$",
"post_id",
",",
"$",
"this",
"->",
"settings",
"[",
"'id'",
"]",
",",
"$",
"new_instance",
")",
";",
"// Callback",
"$",
"callable",
"=",
"$",
"this",
"->",
"settings",
"[",
"'callback'",
"]",
";",
"if",
"(",
"is_callable",
"(",
"$",
"callable",
")",
")",
"{",
"$",
"callable",
"(",
"$",
"post_id",
",",
"$",
"new_instance",
")",
";",
"}",
"}"
] |
Save the meta when the post is saved.
@param int $post_id The ID of the post being saved.
|
[
"Save",
"the",
"meta",
"when",
"the",
"post",
"is",
"saved",
"."
] |
fe8283e2d6847ef697abec832da7ee741a85058c
|
https://github.com/askupasoftware/amarkal/blob/fe8283e2d6847ef697abec832da7ee741a85058c/Extensions/WordPress/MetaBox/MetaBox.php#L133-L195
|
20,125 |
askupasoftware/amarkal
|
Extensions/WordPress/MetaBox/MetaBox.php
|
MetaBox.render
|
public function render( $post )
{
$old_instance = \get_post_meta( $post->ID, $this->settings['id'], true );
$this->form->updater->update( $old_instance === "" ? array() : $old_instance );
// Add an nonce field so we can check for it later.
wp_nonce_field( $this->action_name(), $this->nonce_name() );
$this->form->render(true);
}
|
php
|
public function render( $post )
{
$old_instance = \get_post_meta( $post->ID, $this->settings['id'], true );
$this->form->updater->update( $old_instance === "" ? array() : $old_instance );
// Add an nonce field so we can check for it later.
wp_nonce_field( $this->action_name(), $this->nonce_name() );
$this->form->render(true);
}
|
[
"public",
"function",
"render",
"(",
"$",
"post",
")",
"{",
"$",
"old_instance",
"=",
"\\",
"get_post_meta",
"(",
"$",
"post",
"->",
"ID",
",",
"$",
"this",
"->",
"settings",
"[",
"'id'",
"]",
",",
"true",
")",
";",
"$",
"this",
"->",
"form",
"->",
"updater",
"->",
"update",
"(",
"$",
"old_instance",
"===",
"\"\"",
"?",
"array",
"(",
")",
":",
"$",
"old_instance",
")",
";",
"// Add an nonce field so we can check for it later.",
"wp_nonce_field",
"(",
"$",
"this",
"->",
"action_name",
"(",
")",
",",
"$",
"this",
"->",
"nonce_name",
"(",
")",
")",
";",
"$",
"this",
"->",
"form",
"->",
"render",
"(",
"true",
")",
";",
"}"
] |
Render Meta Box content.
@param WP_Post $post The post object.
|
[
"Render",
"Meta",
"Box",
"content",
"."
] |
fe8283e2d6847ef697abec832da7ee741a85058c
|
https://github.com/askupasoftware/amarkal/blob/fe8283e2d6847ef697abec832da7ee741a85058c/Extensions/WordPress/MetaBox/MetaBox.php#L202-L209
|
20,126 |
askupasoftware/amarkal
|
Extensions/WordPress/MetaBox/MetaBox.php
|
MetaBox.get_meta_value
|
static function get_meta_value( $post_id, $metabox_id, $field_name = null )
{
$meta = \get_post_meta( $post_id, $metabox_id, true );
if( null == $field_name )
{
return $meta;
}
if( isset($meta[$field_name]) )
{
return $meta[$field_name];
}
}
|
php
|
static function get_meta_value( $post_id, $metabox_id, $field_name = null )
{
$meta = \get_post_meta( $post_id, $metabox_id, true );
if( null == $field_name )
{
return $meta;
}
if( isset($meta[$field_name]) )
{
return $meta[$field_name];
}
}
|
[
"static",
"function",
"get_meta_value",
"(",
"$",
"post_id",
",",
"$",
"metabox_id",
",",
"$",
"field_name",
"=",
"null",
")",
"{",
"$",
"meta",
"=",
"\\",
"get_post_meta",
"(",
"$",
"post_id",
",",
"$",
"metabox_id",
",",
"true",
")",
";",
"if",
"(",
"null",
"==",
"$",
"field_name",
")",
"{",
"return",
"$",
"meta",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"meta",
"[",
"$",
"field_name",
"]",
")",
")",
"{",
"return",
"$",
"meta",
"[",
"$",
"field_name",
"]",
";",
"}",
"}"
] |
Get a meta box value for a given post id, by specifying the metabox
id and field name. If no field name is given, an associative array with
all the meta box values will be returned.
@param int $post_id The post's id
@param string $metabox_id The metabox id
@param string $field_name (optional) The metabox field name
@return mixed
|
[
"Get",
"a",
"meta",
"box",
"value",
"for",
"a",
"given",
"post",
"id",
"by",
"specifying",
"the",
"metabox",
"id",
"and",
"field",
"name",
".",
"If",
"no",
"field",
"name",
"is",
"given",
"an",
"associative",
"array",
"with",
"all",
"the",
"meta",
"box",
"values",
"will",
"be",
"returned",
"."
] |
fe8283e2d6847ef697abec832da7ee741a85058c
|
https://github.com/askupasoftware/amarkal/blob/fe8283e2d6847ef697abec832da7ee741a85058c/Extensions/WordPress/MetaBox/MetaBox.php#L221-L233
|
20,127 |
webforge-labs/psc-cms
|
lib/Psc/PHPExcel/SimpleImporter.php
|
SimpleImporter.findAll
|
public function findAll() {
$sheets = array();
foreach ($this->readSelectedSheets() as $selectName => $excelSheet) {
$sheets[$selectName] = new Sheet($selectName, $this->readRows($excelSheet));
}
return $sheets;
}
|
php
|
public function findAll() {
$sheets = array();
foreach ($this->readSelectedSheets() as $selectName => $excelSheet) {
$sheets[$selectName] = new Sheet($selectName, $this->readRows($excelSheet));
}
return $sheets;
}
|
[
"public",
"function",
"findAll",
"(",
")",
"{",
"$",
"sheets",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"readSelectedSheets",
"(",
")",
"as",
"$",
"selectName",
"=>",
"$",
"excelSheet",
")",
"{",
"$",
"sheets",
"[",
"$",
"selectName",
"]",
"=",
"new",
"Sheet",
"(",
"$",
"selectName",
",",
"$",
"this",
"->",
"readRows",
"(",
"$",
"excelSheet",
")",
")",
";",
"}",
"return",
"$",
"sheets",
";",
"}"
] |
Returns all selected Sheets with all rows
@return Sheet[]
|
[
"Returns",
"all",
"selected",
"Sheets",
"with",
"all",
"rows"
] |
467bfa2547e6b4fa487d2d7f35fa6cc618dbc763
|
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/PHPExcel/SimpleImporter.php#L65-L73
|
20,128 |
Nozemi/SlickBoard-Library
|
lib/SBLib/Utilities/MISC.php
|
MISC.findFile
|
public static function findFile($file, $loops = 3) {
// Checks whether or not $file exists.
if (!file_exists($file)) {
// How many parent folders it'll check. (3 by default)
for ($i = 0; $i < $loops; $i++) {
if (!file_exists($file)) {
$file = '../' . $file;
}
}
}
return $file;
}
|
php
|
public static function findFile($file, $loops = 3) {
// Checks whether or not $file exists.
if (!file_exists($file)) {
// How many parent folders it'll check. (3 by default)
for ($i = 0; $i < $loops; $i++) {
if (!file_exists($file)) {
$file = '../' . $file;
}
}
}
return $file;
}
|
[
"public",
"static",
"function",
"findFile",
"(",
"$",
"file",
",",
"$",
"loops",
"=",
"3",
")",
"{",
"// Checks whether or not $file exists.",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"// How many parent folders it'll check. (3 by default)",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"loops",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"$",
"file",
"=",
"'../'",
".",
"$",
"file",
";",
"}",
"}",
"}",
"return",
"$",
"file",
";",
"}"
] |
Finds a file, by default it will try up to 3 parent folders.
|
[
"Finds",
"a",
"file",
"by",
"default",
"it",
"will",
"try",
"up",
"to",
"3",
"parent",
"folders",
"."
] |
c9f0a26a30f8127c997f75d7232eac170972418d
|
https://github.com/Nozemi/SlickBoard-Library/blob/c9f0a26a30f8127c997f75d7232eac170972418d/lib/SBLib/Utilities/MISC.php#L31-L43
|
20,129 |
Nozemi/SlickBoard-Library
|
lib/SBLib/Utilities/MISC.php
|
MISC.findKey
|
public static function findKey($aKey, $array) {
// Check if an array is provided.
if (is_array($array)) {
// Loops through the array.
foreach ($array as $key => $item) {
// Checks if it did find the matching key. If it doesn't, it continues looping until it does,
// or until the end of the array.
if ($key == $aKey) {
return $item;
} else {
$result = self::findKey($aKey, $item);
if ($result != false) {
return $result;
}
}
}
}
return false;
}
|
php
|
public static function findKey($aKey, $array) {
// Check if an array is provided.
if (is_array($array)) {
// Loops through the array.
foreach ($array as $key => $item) {
// Checks if it did find the matching key. If it doesn't, it continues looping until it does,
// or until the end of the array.
if ($key == $aKey) {
return $item;
} else {
$result = self::findKey($aKey, $item);
if ($result != false) {
return $result;
}
}
}
}
return false;
}
|
[
"public",
"static",
"function",
"findKey",
"(",
"$",
"aKey",
",",
"$",
"array",
")",
"{",
"// Check if an array is provided.",
"if",
"(",
"is_array",
"(",
"$",
"array",
")",
")",
"{",
"// Loops through the array.",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"// Checks if it did find the matching key. If it doesn't, it continues looping until it does,",
"// or until the end of the array.",
"if",
"(",
"$",
"key",
"==",
"$",
"aKey",
")",
"{",
"return",
"$",
"item",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"self",
"::",
"findKey",
"(",
"$",
"aKey",
",",
"$",
"item",
")",
";",
"if",
"(",
"$",
"result",
"!=",
"false",
")",
"{",
"return",
"$",
"result",
";",
"}",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] |
in the array the key is, just that it exists in there somewhere.
|
[
"in",
"the",
"array",
"the",
"key",
"is",
"just",
"that",
"it",
"exists",
"in",
"there",
"somewhere",
"."
] |
c9f0a26a30f8127c997f75d7232eac170972418d
|
https://github.com/Nozemi/SlickBoard-Library/blob/c9f0a26a30f8127c997f75d7232eac170972418d/lib/SBLib/Utilities/MISC.php#L55-L73
|
20,130 |
daithi-coombes/bluemix-personality-insights-php
|
lib/Config.php
|
Config.getInstance
|
public static function getInstance($configFile='config.yml')
{
static $instance = null;
if (null === $instance) {
$instance = new static();
}
$configuration = Yaml::parse(file_get_contents($configFile));
$instance->setParams($configuration);
return $instance;
}
|
php
|
public static function getInstance($configFile='config.yml')
{
static $instance = null;
if (null === $instance) {
$instance = new static();
}
$configuration = Yaml::parse(file_get_contents($configFile));
$instance->setParams($configuration);
return $instance;
}
|
[
"public",
"static",
"function",
"getInstance",
"(",
"$",
"configFile",
"=",
"'config.yml'",
")",
"{",
"static",
"$",
"instance",
"=",
"null",
";",
"if",
"(",
"null",
"===",
"$",
"instance",
")",
"{",
"$",
"instance",
"=",
"new",
"static",
"(",
")",
";",
"}",
"$",
"configuration",
"=",
"Yaml",
"::",
"parse",
"(",
"file_get_contents",
"(",
"$",
"configFile",
")",
")",
";",
"$",
"instance",
"->",
"setParams",
"(",
"$",
"configuration",
")",
";",
"return",
"$",
"instance",
";",
"}"
] |
Config singleton.
@param string $configFile The yaml config file relative to project root.
@return Config The *Singleton* instance.
|
[
"Config",
"singleton",
"."
] |
171bd0a6deb3e1e9a7b38fc61c2a7ae601d76a9a
|
https://github.com/daithi-coombes/bluemix-personality-insights-php/blob/171bd0a6deb3e1e9a7b38fc61c2a7ae601d76a9a/lib/Config.php#L26-L37
|
20,131 |
PortaText/php-sdk
|
src/PortaText/Client/Base.php
|
Base.assertResult
|
protected function assertResult($descriptor, $result)
{
$errors = array(
401 => "InvalidCredentials",
402 => "PaymentRequired",
403 => "Forbidden",
404 => "NotFound",
405 => "InvalidMethod",
406 => "NotAcceptable",
415 => "InvalidMedia",
429 => "RateLimited",
500 => "ServerError",
400 => "ClientError"
);
if (isset($errors[$result->code])) {
$class = $errors[$result->code];
$class = "PortaText\\Exception\\$class";
throw new $class($descriptor, $result);
}
}
|
php
|
protected function assertResult($descriptor, $result)
{
$errors = array(
401 => "InvalidCredentials",
402 => "PaymentRequired",
403 => "Forbidden",
404 => "NotFound",
405 => "InvalidMethod",
406 => "NotAcceptable",
415 => "InvalidMedia",
429 => "RateLimited",
500 => "ServerError",
400 => "ClientError"
);
if (isset($errors[$result->code])) {
$class = $errors[$result->code];
$class = "PortaText\\Exception\\$class";
throw new $class($descriptor, $result);
}
}
|
[
"protected",
"function",
"assertResult",
"(",
"$",
"descriptor",
",",
"$",
"result",
")",
"{",
"$",
"errors",
"=",
"array",
"(",
"401",
"=>",
"\"InvalidCredentials\"",
",",
"402",
"=>",
"\"PaymentRequired\"",
",",
"403",
"=>",
"\"Forbidden\"",
",",
"404",
"=>",
"\"NotFound\"",
",",
"405",
"=>",
"\"InvalidMethod\"",
",",
"406",
"=>",
"\"NotAcceptable\"",
",",
"415",
"=>",
"\"InvalidMedia\"",
",",
"429",
"=>",
"\"RateLimited\"",
",",
"500",
"=>",
"\"ServerError\"",
",",
"400",
"=>",
"\"ClientError\"",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"errors",
"[",
"$",
"result",
"->",
"code",
"]",
")",
")",
"{",
"$",
"class",
"=",
"$",
"errors",
"[",
"$",
"result",
"->",
"code",
"]",
";",
"$",
"class",
"=",
"\"PortaText\\\\Exception\\\\$class\"",
";",
"throw",
"new",
"$",
"class",
"(",
"$",
"descriptor",
",",
"$",
"result",
")",
";",
"}",
"}"
] |
Will assert that the request finished successfuly.
@param PortaText\Command\Descriptor $descriptor The Command execution
descriptor.
@param PortaText\Command\Result $result Request execution result.
@return void
@throws PortaText\Exception\ServerError
@throws PortaText\Exception\ClientError
@throws PortaText\Exception\InvalidCredentials
@throws PortaText\Exception\PaymentRequired
@throws PortaText\Exception\Forbidden
@throws PortaText\Exception\NotFound
@throws PortaText\Exception\InvalidMedia
@throws PortaText\Exception\NotAcceptable
@throws PortaText\Exception\InvalidMethod
@throws PortaText\Exception\RateLimited
|
[
"Will",
"assert",
"that",
"the",
"request",
"finished",
"successfuly",
"."
] |
dbe04ef043db5b251953f9de57aa4d0f1785dfcc
|
https://github.com/PortaText/php-sdk/blob/dbe04ef043db5b251953f9de57aa4d0f1785dfcc/src/PortaText/Client/Base.php#L275-L294
|
20,132 |
webforge-labs/psc-cms
|
lib/Psc/Form/ValidationPackage.php
|
ValidationPackage.createValidator
|
public function createValidator(Array $simpleRules = array()) {
$validator = new Validator();
if (count($simpleRules) > 0) {
$validator->addSimpleRules($simpleRules);
}
return $validator;
}
|
php
|
public function createValidator(Array $simpleRules = array()) {
$validator = new Validator();
if (count($simpleRules) > 0) {
$validator->addSimpleRules($simpleRules);
}
return $validator;
}
|
[
"public",
"function",
"createValidator",
"(",
"Array",
"$",
"simpleRules",
"=",
"array",
"(",
")",
")",
"{",
"$",
"validator",
"=",
"new",
"Validator",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"simpleRules",
")",
">",
"0",
")",
"{",
"$",
"validator",
"->",
"addSimpleRules",
"(",
"$",
"simpleRules",
")",
";",
"}",
"return",
"$",
"validator",
";",
"}"
] |
Erstellt einen Validator mit den SimpleRules
'field'=>'nes'
$validator->validate('field', $formValue);
|
[
"Erstellt",
"einen",
"Validator",
"mit",
"den",
"SimpleRules"
] |
467bfa2547e6b4fa487d2d7f35fa6cc618dbc763
|
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Form/ValidationPackage.php#L74-L81
|
20,133 |
webforge-labs/psc-cms
|
lib/Psc/Form/ValidationPackage.php
|
ValidationPackage.createComponentsValidator
|
public function createComponentsValidator(FormData $requestData, EntityFormPanel $panel, DCPackage $dc, Array $components = NULL) {
$this->validationEntity = $entity = $panel->getEntityForm()->getEntity();
$components = isset($components) ? Code::castCollection($components) : $panel->getEntityForm()->getComponents();
return $this->componentsValidator =
new ComponentsValidator($this->createFormDataSet($requestData, $panel, $entity),
$components,
$this->componentRuleMapper
);
}
|
php
|
public function createComponentsValidator(FormData $requestData, EntityFormPanel $panel, DCPackage $dc, Array $components = NULL) {
$this->validationEntity = $entity = $panel->getEntityForm()->getEntity();
$components = isset($components) ? Code::castCollection($components) : $panel->getEntityForm()->getComponents();
return $this->componentsValidator =
new ComponentsValidator($this->createFormDataSet($requestData, $panel, $entity),
$components,
$this->componentRuleMapper
);
}
|
[
"public",
"function",
"createComponentsValidator",
"(",
"FormData",
"$",
"requestData",
",",
"EntityFormPanel",
"$",
"panel",
",",
"DCPackage",
"$",
"dc",
",",
"Array",
"$",
"components",
"=",
"NULL",
")",
"{",
"$",
"this",
"->",
"validationEntity",
"=",
"$",
"entity",
"=",
"$",
"panel",
"->",
"getEntityForm",
"(",
")",
"->",
"getEntity",
"(",
")",
";",
"$",
"components",
"=",
"isset",
"(",
"$",
"components",
")",
"?",
"Code",
"::",
"castCollection",
"(",
"$",
"components",
")",
":",
"$",
"panel",
"->",
"getEntityForm",
"(",
")",
"->",
"getComponents",
"(",
")",
";",
"return",
"$",
"this",
"->",
"componentsValidator",
"=",
"new",
"ComponentsValidator",
"(",
"$",
"this",
"->",
"createFormDataSet",
"(",
"$",
"requestData",
",",
"$",
"panel",
",",
"$",
"entity",
")",
",",
"$",
"components",
",",
"$",
"this",
"->",
"componentRuleMapper",
")",
";",
"}"
] |
Erstellt einen ComponentsValidator anhand des EntityFormPanels
Der FormPanel muss die Componenten schon erstellt haben sie werden mit getComponents() aus dem Formular genommen
|
[
"Erstellt",
"einen",
"ComponentsValidator",
"anhand",
"des",
"EntityFormPanels"
] |
467bfa2547e6b4fa487d2d7f35fa6cc618dbc763
|
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Form/ValidationPackage.php#L108-L118
|
20,134 |
webforge-labs/psc-cms
|
lib/Psc/Form/ValidationPackage.php
|
ValidationPackage.createFormDataSet
|
public function createFormDataSet(FormData $requestData, EntityFormPanel $panel, Entity $entity) {
$meta = $entity->getSetMeta();
// wir müssen die Spezial-Felder vom EntityFormPanel hier tracken
foreach ($panel->getControlFields() as $field) {
$meta->setFieldType($field, Type::create('String'));
}
// sonderfeld disabled wird ignored
$meta->setFieldType('disabled', Type::create('Array'));
try {
$set = new Set((array) $requestData, $meta);
} catch (\Psc\Data\FieldNotDefinedException $e) {
throw \Psc\Exception::create("In den FormularDaten befindet sich ein Feld '%s', welches kein Feld aus Entity getSetMeta ist (%s).", implode('.',$e->field), implode(', ',$e->avaibleFields));
}
return $set;
}
|
php
|
public function createFormDataSet(FormData $requestData, EntityFormPanel $panel, Entity $entity) {
$meta = $entity->getSetMeta();
// wir müssen die Spezial-Felder vom EntityFormPanel hier tracken
foreach ($panel->getControlFields() as $field) {
$meta->setFieldType($field, Type::create('String'));
}
// sonderfeld disabled wird ignored
$meta->setFieldType('disabled', Type::create('Array'));
try {
$set = new Set((array) $requestData, $meta);
} catch (\Psc\Data\FieldNotDefinedException $e) {
throw \Psc\Exception::create("In den FormularDaten befindet sich ein Feld '%s', welches kein Feld aus Entity getSetMeta ist (%s).", implode('.',$e->field), implode(', ',$e->avaibleFields));
}
return $set;
}
|
[
"public",
"function",
"createFormDataSet",
"(",
"FormData",
"$",
"requestData",
",",
"EntityFormPanel",
"$",
"panel",
",",
"Entity",
"$",
"entity",
")",
"{",
"$",
"meta",
"=",
"$",
"entity",
"->",
"getSetMeta",
"(",
")",
";",
"// wir müssen die Spezial-Felder vom EntityFormPanel hier tracken",
"foreach",
"(",
"$",
"panel",
"->",
"getControlFields",
"(",
")",
"as",
"$",
"field",
")",
"{",
"$",
"meta",
"->",
"setFieldType",
"(",
"$",
"field",
",",
"Type",
"::",
"create",
"(",
"'String'",
")",
")",
";",
"}",
"// sonderfeld disabled wird ignored",
"$",
"meta",
"->",
"setFieldType",
"(",
"'disabled'",
",",
"Type",
"::",
"create",
"(",
"'Array'",
")",
")",
";",
"try",
"{",
"$",
"set",
"=",
"new",
"Set",
"(",
"(",
"array",
")",
"$",
"requestData",
",",
"$",
"meta",
")",
";",
"}",
"catch",
"(",
"\\",
"Psc",
"\\",
"Data",
"\\",
"FieldNotDefinedException",
"$",
"e",
")",
"{",
"throw",
"\\",
"Psc",
"\\",
"Exception",
"::",
"create",
"(",
"\"In den FormularDaten befindet sich ein Feld '%s', welches kein Feld aus Entity getSetMeta ist (%s).\"",
",",
"implode",
"(",
"'.'",
",",
"$",
"e",
"->",
"field",
")",
",",
"implode",
"(",
"', '",
",",
"$",
"e",
"->",
"avaibleFields",
")",
")",
";",
"}",
"return",
"$",
"set",
";",
"}"
] |
Erstellt aus dem Request und dem FormPanel ein Set mit allen FormularDaten
man könnte sich hier auch mal vorstellen die formulardaten im set aufzusplitten
Sicherheit: alle Felder die nicht registriert sind durch Componenten oder den Formpanel (getControlFields) schmeissen hier eine Exception
|
[
"Erstellt",
"aus",
"dem",
"Request",
"und",
"dem",
"FormPanel",
"ein",
"Set",
"mit",
"allen",
"FormularDaten"
] |
467bfa2547e6b4fa487d2d7f35fa6cc618dbc763
|
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Form/ValidationPackage.php#L137-L156
|
20,135 |
aedart/laravel-helpers
|
src/Traits/Cache/CacheTrait.php
|
CacheTrait.getDefaultCache
|
public function getDefaultCache(): ?Repository
{
// By default, the Cache Facade does not return the
// any actual cache repository, but rather an
// instance of \Illuminate\Cache\CacheManager.
// Therefore, we make sure only to obtain its
// "store", to make sure that its only the cache repository
// instance that we obtain.
$manager = Cache::getFacadeRoot();
if (isset($manager)) {
return $cache = $manager->store();
}
return $manager;
}
|
php
|
public function getDefaultCache(): ?Repository
{
// By default, the Cache Facade does not return the
// any actual cache repository, but rather an
// instance of \Illuminate\Cache\CacheManager.
// Therefore, we make sure only to obtain its
// "store", to make sure that its only the cache repository
// instance that we obtain.
$manager = Cache::getFacadeRoot();
if (isset($manager)) {
return $cache = $manager->store();
}
return $manager;
}
|
[
"public",
"function",
"getDefaultCache",
"(",
")",
":",
"?",
"Repository",
"{",
"// By default, the Cache Facade does not return the",
"// any actual cache repository, but rather an",
"// instance of \\Illuminate\\Cache\\CacheManager.",
"// Therefore, we make sure only to obtain its",
"// \"store\", to make sure that its only the cache repository",
"// instance that we obtain.",
"$",
"manager",
"=",
"Cache",
"::",
"getFacadeRoot",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"manager",
")",
")",
"{",
"return",
"$",
"cache",
"=",
"$",
"manager",
"->",
"store",
"(",
")",
";",
"}",
"return",
"$",
"manager",
";",
"}"
] |
Get a default cache value, if any is available
@return Repository|null A default cache value or Null if no default value is available
|
[
"Get",
"a",
"default",
"cache",
"value",
"if",
"any",
"is",
"available"
] |
8b81a2d6658f3f8cb62b6be2c34773aaa2df219a
|
https://github.com/aedart/laravel-helpers/blob/8b81a2d6658f3f8cb62b6be2c34773aaa2df219a/src/Traits/Cache/CacheTrait.php#L76-L89
|
20,136 |
aryelgois/yasql-php
|
src/Composer.php
|
Composer.generate
|
public static function generate(Event $event)
{
$args = $event->getArguments();
if (empty($args)) {
echo "Usage:\n\n"
. " composer yasql-generate -- YASQL_FILE [INDENTATION]\n\n"
. "By default, INDENTATION is 2\n";
die(1);
}
echo Controller::generate(
file_get_contents($args[0]),
null,
$args[1] ?? 2
);
}
|
php
|
public static function generate(Event $event)
{
$args = $event->getArguments();
if (empty($args)) {
echo "Usage:\n\n"
. " composer yasql-generate -- YASQL_FILE [INDENTATION]\n\n"
. "By default, INDENTATION is 2\n";
die(1);
}
echo Controller::generate(
file_get_contents($args[0]),
null,
$args[1] ?? 2
);
}
|
[
"public",
"static",
"function",
"generate",
"(",
"Event",
"$",
"event",
")",
"{",
"$",
"args",
"=",
"$",
"event",
"->",
"getArguments",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"args",
")",
")",
"{",
"echo",
"\"Usage:\\n\\n\"",
".",
"\" composer yasql-generate -- YASQL_FILE [INDENTATION]\\n\\n\"",
".",
"\"By default, INDENTATION is 2\\n\"",
";",
"die",
"(",
"1",
")",
";",
"}",
"echo",
"Controller",
"::",
"generate",
"(",
"file_get_contents",
"(",
"$",
"args",
"[",
"0",
"]",
")",
",",
"null",
",",
"$",
"args",
"[",
"1",
"]",
"??",
"2",
")",
";",
"}"
] |
Generates the SQL from a YASQL file
Arguments:
string $1 Path to YASQL file
int $2 How many spaces per indentation level
@param Event $event Composer run-script event
|
[
"Generates",
"the",
"SQL",
"from",
"a",
"YASQL",
"file"
] |
f428b180d35bfc1ddf1f9b3323f9b085fbc09ac7
|
https://github.com/aryelgois/yasql-php/blob/f428b180d35bfc1ddf1f9b3323f9b085fbc09ac7/src/Composer.php#L101-L116
|
20,137 |
webforge-labs/psc-cms
|
lib/Psc/Doctrine/PhpParser.php
|
PhpParser.parseUseStatement
|
private function parseUseStatement()
{
$class = '';
$alias = '';
$statements = array();
$explicitAlias = false;
while (($token = $this->next())) {
$isNameToken = $token[0] === T_STRING || $token[0] === T_NS_SEPARATOR;
if (!$explicitAlias && $isNameToken) {
$class .= $token[1];
$alias = $token[1];
} else if ($explicitAlias && $isNameToken) {
$alias .= $token[1];
} else if ($token[0] === T_AS) {
$explicitAlias = true;
$alias = '';
} else if ($token === ',') {
$statements[$alias] = $class;
$class = '';
$alias = '';
$explicitAlias = false;
} else if ($token === ';') {
$statements[$alias] = $class;
break;
} else {
break;
}
}
return $statements;
}
|
php
|
private function parseUseStatement()
{
$class = '';
$alias = '';
$statements = array();
$explicitAlias = false;
while (($token = $this->next())) {
$isNameToken = $token[0] === T_STRING || $token[0] === T_NS_SEPARATOR;
if (!$explicitAlias && $isNameToken) {
$class .= $token[1];
$alias = $token[1];
} else if ($explicitAlias && $isNameToken) {
$alias .= $token[1];
} else if ($token[0] === T_AS) {
$explicitAlias = true;
$alias = '';
} else if ($token === ',') {
$statements[$alias] = $class;
$class = '';
$alias = '';
$explicitAlias = false;
} else if ($token === ';') {
$statements[$alias] = $class;
break;
} else {
break;
}
}
return $statements;
}
|
[
"private",
"function",
"parseUseStatement",
"(",
")",
"{",
"$",
"class",
"=",
"''",
";",
"$",
"alias",
"=",
"''",
";",
"$",
"statements",
"=",
"array",
"(",
")",
";",
"$",
"explicitAlias",
"=",
"false",
";",
"while",
"(",
"(",
"$",
"token",
"=",
"$",
"this",
"->",
"next",
"(",
")",
")",
")",
"{",
"$",
"isNameToken",
"=",
"$",
"token",
"[",
"0",
"]",
"===",
"T_STRING",
"||",
"$",
"token",
"[",
"0",
"]",
"===",
"T_NS_SEPARATOR",
";",
"if",
"(",
"!",
"$",
"explicitAlias",
"&&",
"$",
"isNameToken",
")",
"{",
"$",
"class",
".=",
"$",
"token",
"[",
"1",
"]",
";",
"$",
"alias",
"=",
"$",
"token",
"[",
"1",
"]",
";",
"}",
"else",
"if",
"(",
"$",
"explicitAlias",
"&&",
"$",
"isNameToken",
")",
"{",
"$",
"alias",
".=",
"$",
"token",
"[",
"1",
"]",
";",
"}",
"else",
"if",
"(",
"$",
"token",
"[",
"0",
"]",
"===",
"T_AS",
")",
"{",
"$",
"explicitAlias",
"=",
"true",
";",
"$",
"alias",
"=",
"''",
";",
"}",
"else",
"if",
"(",
"$",
"token",
"===",
"','",
")",
"{",
"$",
"statements",
"[",
"$",
"alias",
"]",
"=",
"$",
"class",
";",
"$",
"class",
"=",
"''",
";",
"$",
"alias",
"=",
"''",
";",
"$",
"explicitAlias",
"=",
"false",
";",
"}",
"else",
"if",
"(",
"$",
"token",
"===",
"';'",
")",
"{",
"$",
"statements",
"[",
"$",
"alias",
"]",
"=",
"$",
"class",
";",
"break",
";",
"}",
"else",
"{",
"break",
";",
"}",
"}",
"return",
"$",
"statements",
";",
"}"
] |
Parse a single use statement.
@return array A list with all found class names for a use statement.
|
[
"Parse",
"a",
"single",
"use",
"statement",
"."
] |
467bfa2547e6b4fa487d2d7f35fa6cc618dbc763
|
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/PhpParser.php#L195-L225
|
20,138 |
antonmedv/silicone
|
src/Silicone/Routing/Loader/AnnotatedRouteControllerLoader.php
|
AnnotatedRouteControllerLoader.getDefaultRouteName
|
protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMethod $method)
{
$routeName = parent::getDefaultRouteName($class, $method);
return preg_replace(array(
'/(module_|controller_?)/',
'/__/'
), array(
'_',
'_'
), $routeName);
}
|
php
|
protected function getDefaultRouteName(\ReflectionClass $class, \ReflectionMethod $method)
{
$routeName = parent::getDefaultRouteName($class, $method);
return preg_replace(array(
'/(module_|controller_?)/',
'/__/'
), array(
'_',
'_'
), $routeName);
}
|
[
"protected",
"function",
"getDefaultRouteName",
"(",
"\\",
"ReflectionClass",
"$",
"class",
",",
"\\",
"ReflectionMethod",
"$",
"method",
")",
"{",
"$",
"routeName",
"=",
"parent",
"::",
"getDefaultRouteName",
"(",
"$",
"class",
",",
"$",
"method",
")",
";",
"return",
"preg_replace",
"(",
"array",
"(",
"'/(module_|controller_?)/'",
",",
"'/__/'",
")",
",",
"array",
"(",
"'_'",
",",
"'_'",
")",
",",
"$",
"routeName",
")",
";",
"}"
] |
Makes the default route name more sane by removing common keywords.
@param \ReflectionClass $class A ReflectionClass instance
@param \ReflectionMethod $method A ReflectionMethod instance
@return string
|
[
"Makes",
"the",
"default",
"route",
"name",
"more",
"sane",
"by",
"removing",
"common",
"keywords",
"."
] |
e4a67ed41f0f419984df642b303f2a491c9a3933
|
https://github.com/antonmedv/silicone/blob/e4a67ed41f0f419984df642b303f2a491c9a3933/src/Silicone/Routing/Loader/AnnotatedRouteControllerLoader.php#L36-L47
|
20,139 |
Double-Opt-in/php-client-api
|
src/Client/Api.php
|
Api.resolveClient
|
private function resolveClient($client)
{
$client = ! empty($client)
? $client
: new Client();
$client->setBaseUrl(Properties::baseUrl())
->setUserAgent('Double Opt-in php-api/' . self::VERSION);
$httpClientConfig = $this->config->getHttpClientConfig();
if (array_key_exists('verify', $httpClientConfig)
&& $httpClientConfig['verify'] === false)
{
$client->setSslVerification(false, false);
}
return $client;
}
|
php
|
private function resolveClient($client)
{
$client = ! empty($client)
? $client
: new Client();
$client->setBaseUrl(Properties::baseUrl())
->setUserAgent('Double Opt-in php-api/' . self::VERSION);
$httpClientConfig = $this->config->getHttpClientConfig();
if (array_key_exists('verify', $httpClientConfig)
&& $httpClientConfig['verify'] === false)
{
$client->setSslVerification(false, false);
}
return $client;
}
|
[
"private",
"function",
"resolveClient",
"(",
"$",
"client",
")",
"{",
"$",
"client",
"=",
"!",
"empty",
"(",
"$",
"client",
")",
"?",
"$",
"client",
":",
"new",
"Client",
"(",
")",
";",
"$",
"client",
"->",
"setBaseUrl",
"(",
"Properties",
"::",
"baseUrl",
"(",
")",
")",
"->",
"setUserAgent",
"(",
"'Double Opt-in php-api/'",
".",
"self",
"::",
"VERSION",
")",
";",
"$",
"httpClientConfig",
"=",
"$",
"this",
"->",
"config",
"->",
"getHttpClientConfig",
"(",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"'verify'",
",",
"$",
"httpClientConfig",
")",
"&&",
"$",
"httpClientConfig",
"[",
"'verify'",
"]",
"===",
"false",
")",
"{",
"$",
"client",
"->",
"setSslVerification",
"(",
"false",
",",
"false",
")",
";",
"}",
"return",
"$",
"client",
";",
"}"
] |
resolves a http client
@param ClientInterface|null $client
@return ClientInterface|Client
|
[
"resolves",
"a",
"http",
"client"
] |
2f17da58ec20a408bbd55b2cdd053bc689f995f4
|
https://github.com/Double-Opt-in/php-client-api/blob/2f17da58ec20a408bbd55b2cdd053bc689f995f4/src/Client/Api.php#L84-L101
|
20,140 |
Double-Opt-in/php-client-api
|
src/Client/Api.php
|
Api.setupOAuth2Plugin
|
private function setupOAuth2Plugin()
{
$oauth2AuthorizationClient = $this->resolveClient(null);
$oauth2AuthorizationClient->setBaseUrl(Properties::authorizationUrl());
$clientCredentials = new ClientCredentials($oauth2AuthorizationClient, $this->config->toArray());
$oauth2Plugin = new OAuth2Plugin($clientCredentials);
$oauth2Plugin->setCache($this->config->getAccessTokenCacheFile());
$this->client->addSubscriber($oauth2Plugin);
}
|
php
|
private function setupOAuth2Plugin()
{
$oauth2AuthorizationClient = $this->resolveClient(null);
$oauth2AuthorizationClient->setBaseUrl(Properties::authorizationUrl());
$clientCredentials = new ClientCredentials($oauth2AuthorizationClient, $this->config->toArray());
$oauth2Plugin = new OAuth2Plugin($clientCredentials);
$oauth2Plugin->setCache($this->config->getAccessTokenCacheFile());
$this->client->addSubscriber($oauth2Plugin);
}
|
[
"private",
"function",
"setupOAuth2Plugin",
"(",
")",
"{",
"$",
"oauth2AuthorizationClient",
"=",
"$",
"this",
"->",
"resolveClient",
"(",
"null",
")",
";",
"$",
"oauth2AuthorizationClient",
"->",
"setBaseUrl",
"(",
"Properties",
"::",
"authorizationUrl",
"(",
")",
")",
";",
"$",
"clientCredentials",
"=",
"new",
"ClientCredentials",
"(",
"$",
"oauth2AuthorizationClient",
",",
"$",
"this",
"->",
"config",
"->",
"toArray",
"(",
")",
")",
";",
"$",
"oauth2Plugin",
"=",
"new",
"OAuth2Plugin",
"(",
"$",
"clientCredentials",
")",
";",
"$",
"oauth2Plugin",
"->",
"setCache",
"(",
"$",
"this",
"->",
"config",
"->",
"getAccessTokenCacheFile",
"(",
")",
")",
";",
"$",
"this",
"->",
"client",
"->",
"addSubscriber",
"(",
"$",
"oauth2Plugin",
")",
";",
"}"
] |
setting up the oauth2 plugin for authorizing the requests
|
[
"setting",
"up",
"the",
"oauth2",
"plugin",
"for",
"authorizing",
"the",
"requests"
] |
2f17da58ec20a408bbd55b2cdd053bc689f995f4
|
https://github.com/Double-Opt-in/php-client-api/blob/2f17da58ec20a408bbd55b2cdd053bc689f995f4/src/Client/Api.php#L106-L116
|
20,141 |
Double-Opt-in/php-client-api
|
src/Client/Api.php
|
Api.send
|
public function send(ClientCommand $command)
{
$request = $this->client->createRequest(
$command->method(),
$this->client->getBaseUrl() . $command->uri($this->cryptographyEngine),
$this->headers($command->apiVersion(), $command->format(), $command->headers()),
$command->body($this->cryptographyEngine),
$this->config->getHttpClientConfig()
);
try {
$response = $request->send();
} catch (ClientErrorResponseException $exception) {
$response = $exception->getResponse();
} catch (ServerErrorResponseException $exception) {
$response = $exception->getResponse();
}
return $command->response($response, $this->cryptographyEngine);
}
|
php
|
public function send(ClientCommand $command)
{
$request = $this->client->createRequest(
$command->method(),
$this->client->getBaseUrl() . $command->uri($this->cryptographyEngine),
$this->headers($command->apiVersion(), $command->format(), $command->headers()),
$command->body($this->cryptographyEngine),
$this->config->getHttpClientConfig()
);
try {
$response = $request->send();
} catch (ClientErrorResponseException $exception) {
$response = $exception->getResponse();
} catch (ServerErrorResponseException $exception) {
$response = $exception->getResponse();
}
return $command->response($response, $this->cryptographyEngine);
}
|
[
"public",
"function",
"send",
"(",
"ClientCommand",
"$",
"command",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"client",
"->",
"createRequest",
"(",
"$",
"command",
"->",
"method",
"(",
")",
",",
"$",
"this",
"->",
"client",
"->",
"getBaseUrl",
"(",
")",
".",
"$",
"command",
"->",
"uri",
"(",
"$",
"this",
"->",
"cryptographyEngine",
")",
",",
"$",
"this",
"->",
"headers",
"(",
"$",
"command",
"->",
"apiVersion",
"(",
")",
",",
"$",
"command",
"->",
"format",
"(",
")",
",",
"$",
"command",
"->",
"headers",
"(",
")",
")",
",",
"$",
"command",
"->",
"body",
"(",
"$",
"this",
"->",
"cryptographyEngine",
")",
",",
"$",
"this",
"->",
"config",
"->",
"getHttpClientConfig",
"(",
")",
")",
";",
"try",
"{",
"$",
"response",
"=",
"$",
"request",
"->",
"send",
"(",
")",
";",
"}",
"catch",
"(",
"ClientErrorResponseException",
"$",
"exception",
")",
"{",
"$",
"response",
"=",
"$",
"exception",
"->",
"getResponse",
"(",
")",
";",
"}",
"catch",
"(",
"ServerErrorResponseException",
"$",
"exception",
")",
"{",
"$",
"response",
"=",
"$",
"exception",
"->",
"getResponse",
"(",
")",
";",
"}",
"return",
"$",
"command",
"->",
"response",
"(",
"$",
"response",
",",
"$",
"this",
"->",
"cryptographyEngine",
")",
";",
"}"
] |
get all actions
@param ClientCommand $command
@return Response|CommandResponse|DecryptedCommandResponse|StatusResponse
|
[
"get",
"all",
"actions"
] |
2f17da58ec20a408bbd55b2cdd053bc689f995f4
|
https://github.com/Double-Opt-in/php-client-api/blob/2f17da58ec20a408bbd55b2cdd053bc689f995f4/src/Client/Api.php#L125-L144
|
20,142 |
lode/fem
|
src/login_token.php
|
login_token.get_by_token
|
public static function get_by_token($token) {
$mysql = bootstrap::get_library('mysql');
$sql = "SELECT * FROM `login_tokens` WHERE `code` = '%s';";
$login = $mysql::select('row', $sql, $token);
if (empty($login)) {
return false;
}
return new static($login['id']);
}
|
php
|
public static function get_by_token($token) {
$mysql = bootstrap::get_library('mysql');
$sql = "SELECT * FROM `login_tokens` WHERE `code` = '%s';";
$login = $mysql::select('row', $sql, $token);
if (empty($login)) {
return false;
}
return new static($login['id']);
}
|
[
"public",
"static",
"function",
"get_by_token",
"(",
"$",
"token",
")",
"{",
"$",
"mysql",
"=",
"bootstrap",
"::",
"get_library",
"(",
"'mysql'",
")",
";",
"$",
"sql",
"=",
"\"SELECT * FROM `login_tokens` WHERE `code` = '%s';\"",
";",
"$",
"login",
"=",
"$",
"mysql",
"::",
"select",
"(",
"'row'",
",",
"$",
"sql",
",",
"$",
"token",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"login",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"new",
"static",
"(",
"$",
"login",
"[",
"'id'",
"]",
")",
";",
"}"
] |
checks whether the given token match one on file
@param string $token
@return $this|boolean false when the token is not found
|
[
"checks",
"whether",
"the",
"given",
"token",
"match",
"one",
"on",
"file"
] |
c1c466c1a904d99452b341c5ae7cbc3e22b106e1
|
https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/login_token.php#L80-L90
|
20,143 |
lode/fem
|
src/login_token.php
|
login_token.is_valid
|
public function is_valid($mark_as_used=true) {
if (!empty($this->data['used'])) {
return false;
}
if (time() > $this->data['expire_at']) {
return false;
}
if ($mark_as_used) {
$this->mark_as_used();
}
return true;
}
|
php
|
public function is_valid($mark_as_used=true) {
if (!empty($this->data['used'])) {
return false;
}
if (time() > $this->data['expire_at']) {
return false;
}
if ($mark_as_used) {
$this->mark_as_used();
}
return true;
}
|
[
"public",
"function",
"is_valid",
"(",
"$",
"mark_as_used",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"data",
"[",
"'used'",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"time",
"(",
")",
">",
"$",
"this",
"->",
"data",
"[",
"'expire_at'",
"]",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"mark_as_used",
")",
"{",
"$",
"this",
"->",
"mark_as_used",
"(",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
check if the token is still valid
also marks the token as used to prevent more people getting in
@param boolean $mark_as_used set to false to validate w/o user action
@return boolean
|
[
"check",
"if",
"the",
"token",
"is",
"still",
"valid",
"also",
"marks",
"the",
"token",
"as",
"used",
"to",
"prevent",
"more",
"people",
"getting",
"in"
] |
c1c466c1a904d99452b341c5ae7cbc3e22b106e1
|
https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/login_token.php#L99-L112
|
20,144 |
lode/fem
|
src/login_token.php
|
login_token.create
|
public static function create($user_id) {
$text = bootstrap::get_library('text');
$mysql = bootstrap::get_library('mysql');
$new_token = $text::generate_token(self::TOKEN_LENGTH);
$expiration = (time() + self::EXPIRATION);
$sql = "INSERT INTO `login_tokens` SET `code` = '%s', `user_id` = %d, `expire_at` = %d;";
$binds = [$new_token, $user_id, $expiration];
$mysql::query($sql, $binds);
return new static($mysql::$insert_id);
}
|
php
|
public static function create($user_id) {
$text = bootstrap::get_library('text');
$mysql = bootstrap::get_library('mysql');
$new_token = $text::generate_token(self::TOKEN_LENGTH);
$expiration = (time() + self::EXPIRATION);
$sql = "INSERT INTO `login_tokens` SET `code` = '%s', `user_id` = %d, `expire_at` = %d;";
$binds = [$new_token, $user_id, $expiration];
$mysql::query($sql, $binds);
return new static($mysql::$insert_id);
}
|
[
"public",
"static",
"function",
"create",
"(",
"$",
"user_id",
")",
"{",
"$",
"text",
"=",
"bootstrap",
"::",
"get_library",
"(",
"'text'",
")",
";",
"$",
"mysql",
"=",
"bootstrap",
"::",
"get_library",
"(",
"'mysql'",
")",
";",
"$",
"new_token",
"=",
"$",
"text",
"::",
"generate_token",
"(",
"self",
"::",
"TOKEN_LENGTH",
")",
";",
"$",
"expiration",
"=",
"(",
"time",
"(",
")",
"+",
"self",
"::",
"EXPIRATION",
")",
";",
"$",
"sql",
"=",
"\"INSERT INTO `login_tokens` SET `code` = '%s', `user_id` = %d, `expire_at` = %d;\"",
";",
"$",
"binds",
"=",
"[",
"$",
"new_token",
",",
"$",
"user_id",
",",
"$",
"expiration",
"]",
";",
"$",
"mysql",
"::",
"query",
"(",
"$",
"sql",
",",
"$",
"binds",
")",
";",
"return",
"new",
"static",
"(",
"$",
"mysql",
"::",
"$",
"insert_id",
")",
";",
"}"
] |
create a new temporary login token
@param int $user_id
@return $this
|
[
"create",
"a",
"new",
"temporary",
"login",
"token"
] |
c1c466c1a904d99452b341c5ae7cbc3e22b106e1
|
https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/login_token.php#L143-L155
|
20,145 |
2amigos/yiifoundation
|
helpers/Icon.php
|
Icon.registerIconFontSet
|
public static function registerIconFontSet($fontName, $forceCopyAssets = false)
{
if (!in_array($fontName, static::getAvailableIconFontSets())) {
return false;
}
$fontPath = \Yii::getPathOfAlias('foundation.fonts.foundation_icons_' . $fontName);
$fontUrl = \Yii::app()->assetManager->publish($fontPath, true, -1, $forceCopyAssets);
\Yii::app()->clientScript->registerCssFile($fontUrl . "/stylesheets/{$fontName}_foundicons.css");
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7.0')) {
\Yii::app()->clientScript->registerCssFile($fontUrl . "/stylesheets/{$fontName}_foundicons_ie7.css");
}
}
|
php
|
public static function registerIconFontSet($fontName, $forceCopyAssets = false)
{
if (!in_array($fontName, static::getAvailableIconFontSets())) {
return false;
}
$fontPath = \Yii::getPathOfAlias('foundation.fonts.foundation_icons_' . $fontName);
$fontUrl = \Yii::app()->assetManager->publish($fontPath, true, -1, $forceCopyAssets);
\Yii::app()->clientScript->registerCssFile($fontUrl . "/stylesheets/{$fontName}_foundicons.css");
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7.0')) {
\Yii::app()->clientScript->registerCssFile($fontUrl . "/stylesheets/{$fontName}_foundicons_ie7.css");
}
}
|
[
"public",
"static",
"function",
"registerIconFontSet",
"(",
"$",
"fontName",
",",
"$",
"forceCopyAssets",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"fontName",
",",
"static",
"::",
"getAvailableIconFontSets",
"(",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"fontPath",
"=",
"\\",
"Yii",
"::",
"getPathOfAlias",
"(",
"'foundation.fonts.foundation_icons_'",
".",
"$",
"fontName",
")",
";",
"$",
"fontUrl",
"=",
"\\",
"Yii",
"::",
"app",
"(",
")",
"->",
"assetManager",
"->",
"publish",
"(",
"$",
"fontPath",
",",
"true",
",",
"-",
"1",
",",
"$",
"forceCopyAssets",
")",
";",
"\\",
"Yii",
"::",
"app",
"(",
")",
"->",
"clientScript",
"->",
"registerCssFile",
"(",
"$",
"fontUrl",
".",
"\"/stylesheets/{$fontName}_foundicons.css\"",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"_SERVER",
"[",
"'HTTP_USER_AGENT'",
"]",
",",
"'MSIE 7.0'",
")",
")",
"{",
"\\",
"Yii",
"::",
"app",
"(",
")",
"->",
"clientScript",
"->",
"registerCssFile",
"(",
"$",
"fontUrl",
".",
"\"/stylesheets/{$fontName}_foundicons_ie7.css\"",
")",
";",
"}",
"}"
] |
Registers a specific Icon Set. They are registered individually
@param $fontName
@param $forceCopyAssets
@return bool
|
[
"Registers",
"a",
"specific",
"Icon",
"Set",
".",
"They",
"are",
"registered",
"individually"
] |
49bed0d3ca1a9bac9299000e48a2661bdc8f9a29
|
https://github.com/2amigos/yiifoundation/blob/49bed0d3ca1a9bac9299000e48a2661bdc8f9a29/helpers/Icon.php#L46-L60
|
20,146 |
phossa2/config
|
src/Config/Loader/ConfigFileLoader.php
|
ConfigFileLoader.setRootDir
|
public function setRootDir(/*# string */ $rootDir)
{
$dir = realpath($rootDir);
if (false === $dir) {
throw new InvalidArgumentException(
Message::get(Message::CONFIG_ROOT_INVALID, $rootDir),
Message::CONFIG_ROOT_INVALID
);
}
$this->root_dir = $dir . \DIRECTORY_SEPARATOR;
return $this;
}
|
php
|
public function setRootDir(/*# string */ $rootDir)
{
$dir = realpath($rootDir);
if (false === $dir) {
throw new InvalidArgumentException(
Message::get(Message::CONFIG_ROOT_INVALID, $rootDir),
Message::CONFIG_ROOT_INVALID
);
}
$this->root_dir = $dir . \DIRECTORY_SEPARATOR;
return $this;
}
|
[
"public",
"function",
"setRootDir",
"(",
"/*# string */",
"$",
"rootDir",
")",
"{",
"$",
"dir",
"=",
"realpath",
"(",
"$",
"rootDir",
")",
";",
"if",
"(",
"false",
"===",
"$",
"dir",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"Message",
"::",
"get",
"(",
"Message",
"::",
"CONFIG_ROOT_INVALID",
",",
"$",
"rootDir",
")",
",",
"Message",
"::",
"CONFIG_ROOT_INVALID",
")",
";",
"}",
"$",
"this",
"->",
"root_dir",
"=",
"$",
"dir",
".",
"\\",
"DIRECTORY_SEPARATOR",
";",
"return",
"$",
"this",
";",
"}"
] |
Set config file root directory
@param string $rootDir
@return $this
@throws InvalidArgumentException if root dir is unknown
@access public
@api
|
[
"Set",
"config",
"file",
"root",
"directory"
] |
7c046fd2c97633b69545b4745d8bffe28e19b1df
|
https://github.com/phossa2/config/blob/7c046fd2c97633b69545b4745d8bffe28e19b1df/src/Config/Loader/ConfigFileLoader.php#L120-L134
|
20,147 |
phossa2/config
|
src/Config/Loader/ConfigFileLoader.php
|
ConfigFileLoader.globFiles
|
protected function globFiles(
/*# string */ $group,
/*# string */ $environment
)/*# : array */ {
$files = [];
$group = '' === $group ? '*' : $group;
foreach ($this->getSearchDirs($environment) as $dir) {
$file = $dir . $group . '.' . $this->file_type;
$files = array_merge($files, glob($file));
}
return $files;
}
|
php
|
protected function globFiles(
/*# string */ $group,
/*# string */ $environment
)/*# : array */ {
$files = [];
$group = '' === $group ? '*' : $group;
foreach ($this->getSearchDirs($environment) as $dir) {
$file = $dir . $group . '.' . $this->file_type;
$files = array_merge($files, glob($file));
}
return $files;
}
|
[
"protected",
"function",
"globFiles",
"(",
"/*# string */",
"$",
"group",
",",
"/*# string */",
"$",
"environment",
")",
"/*# : array */",
"{",
"$",
"files",
"=",
"[",
"]",
";",
"$",
"group",
"=",
"''",
"===",
"$",
"group",
"?",
"'*'",
":",
"$",
"group",
";",
"foreach",
"(",
"$",
"this",
"->",
"getSearchDirs",
"(",
"$",
"environment",
")",
"as",
"$",
"dir",
")",
"{",
"$",
"file",
"=",
"$",
"dir",
".",
"$",
"group",
".",
"'.'",
".",
"$",
"this",
"->",
"file_type",
";",
"$",
"files",
"=",
"array_merge",
"(",
"$",
"files",
",",
"glob",
"(",
"$",
"file",
")",
")",
";",
"}",
"return",
"$",
"files",
";",
"}"
] |
Returns an array of files to read from
@param string $group
@param string $environment
@return array
@access protected
|
[
"Returns",
"an",
"array",
"of",
"files",
"to",
"read",
"from"
] |
7c046fd2c97633b69545b4745d8bffe28e19b1df
|
https://github.com/phossa2/config/blob/7c046fd2c97633b69545b4745d8bffe28e19b1df/src/Config/Loader/ConfigFileLoader.php#L181-L192
|
20,148 |
phossa2/config
|
src/Config/Loader/ConfigFileLoader.php
|
ConfigFileLoader.getSearchDirs
|
protected function getSearchDirs(/*# string */ $env)/*# : array */
{
if (!isset($this->sub_dirs[$env])) {
$this->sub_dirs[$env] = $this->buildSearchDirs($env);
}
return $this->sub_dirs[$env];
}
|
php
|
protected function getSearchDirs(/*# string */ $env)/*# : array */
{
if (!isset($this->sub_dirs[$env])) {
$this->sub_dirs[$env] = $this->buildSearchDirs($env);
}
return $this->sub_dirs[$env];
}
|
[
"protected",
"function",
"getSearchDirs",
"(",
"/*# string */",
"$",
"env",
")",
"/*# : array */",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"sub_dirs",
"[",
"$",
"env",
"]",
")",
")",
"{",
"$",
"this",
"->",
"sub_dirs",
"[",
"$",
"env",
"]",
"=",
"$",
"this",
"->",
"buildSearchDirs",
"(",
"$",
"env",
")",
";",
"}",
"return",
"$",
"this",
"->",
"sub_dirs",
"[",
"$",
"env",
"]",
";",
"}"
] |
Get the search directories
@param string $env
@return array
@access protected
|
[
"Get",
"the",
"search",
"directories"
] |
7c046fd2c97633b69545b4745d8bffe28e19b1df
|
https://github.com/phossa2/config/blob/7c046fd2c97633b69545b4745d8bffe28e19b1df/src/Config/Loader/ConfigFileLoader.php#L201-L207
|
20,149 |
phossa2/config
|
src/Config/Loader/ConfigFileLoader.php
|
ConfigFileLoader.buildSearchDirs
|
protected function buildSearchDirs(/*# string */ $env)/*# : array */
{
$path = $this->root_dir;
$part = preg_split(
'/[\/\\\]/',
trim($env, '/\\'),
0,
\PREG_SPLIT_NO_EMPTY
);
$subdirs = [$path];
foreach ($part as $dir) {
$path .= $dir . \DIRECTORY_SEPARATOR;
if (false === file_exists($path)) {
trigger_error(
Message::get(Message::CONFIG_ENV_UNKNOWN, $env),
\E_USER_WARNING
);
break;
}
$subdirs[] = $path;
}
return $subdirs;
}
|
php
|
protected function buildSearchDirs(/*# string */ $env)/*# : array */
{
$path = $this->root_dir;
$part = preg_split(
'/[\/\\\]/',
trim($env, '/\\'),
0,
\PREG_SPLIT_NO_EMPTY
);
$subdirs = [$path];
foreach ($part as $dir) {
$path .= $dir . \DIRECTORY_SEPARATOR;
if (false === file_exists($path)) {
trigger_error(
Message::get(Message::CONFIG_ENV_UNKNOWN, $env),
\E_USER_WARNING
);
break;
}
$subdirs[] = $path;
}
return $subdirs;
}
|
[
"protected",
"function",
"buildSearchDirs",
"(",
"/*# string */",
"$",
"env",
")",
"/*# : array */",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"root_dir",
";",
"$",
"part",
"=",
"preg_split",
"(",
"'/[\\/\\\\\\]/'",
",",
"trim",
"(",
"$",
"env",
",",
"'/\\\\'",
")",
",",
"0",
",",
"\\",
"PREG_SPLIT_NO_EMPTY",
")",
";",
"$",
"subdirs",
"=",
"[",
"$",
"path",
"]",
";",
"foreach",
"(",
"$",
"part",
"as",
"$",
"dir",
")",
"{",
"$",
"path",
".=",
"$",
"dir",
".",
"\\",
"DIRECTORY_SEPARATOR",
";",
"if",
"(",
"false",
"===",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"trigger_error",
"(",
"Message",
"::",
"get",
"(",
"Message",
"::",
"CONFIG_ENV_UNKNOWN",
",",
"$",
"env",
")",
",",
"\\",
"E_USER_WARNING",
")",
";",
"break",
";",
"}",
"$",
"subdirs",
"[",
"]",
"=",
"$",
"path",
";",
"}",
"return",
"$",
"subdirs",
";",
"}"
] |
Build search directories
@param string $env
@return array
@access protected
|
[
"Build",
"search",
"directories"
] |
7c046fd2c97633b69545b4745d8bffe28e19b1df
|
https://github.com/phossa2/config/blob/7c046fd2c97633b69545b4745d8bffe28e19b1df/src/Config/Loader/ConfigFileLoader.php#L216-L238
|
20,150 |
ConnectHolland/tulip-api-client
|
src/Client.php
|
Client.getServiceUrl
|
public function getServiceUrl($serviceName, $action)
{
return sprintf('%s/api/%s/%s/%s', $this->tulipUrl, $this->apiVersion, $serviceName, $action);
}
|
php
|
public function getServiceUrl($serviceName, $action)
{
return sprintf('%s/api/%s/%s/%s', $this->tulipUrl, $this->apiVersion, $serviceName, $action);
}
|
[
"public",
"function",
"getServiceUrl",
"(",
"$",
"serviceName",
",",
"$",
"action",
")",
"{",
"return",
"sprintf",
"(",
"'%s/api/%s/%s/%s'",
",",
"$",
"this",
"->",
"tulipUrl",
",",
"$",
"this",
"->",
"apiVersion",
",",
"$",
"serviceName",
",",
"$",
"action",
")",
";",
"}"
] |
Returns the full Tulip API URL for the specified service and action.
@param string $serviceName
@param string $action
@return string
|
[
"Returns",
"the",
"full",
"Tulip",
"API",
"URL",
"for",
"the",
"specified",
"service",
"and",
"action",
"."
] |
641325e2d57c1c272ede7fd8b47d4f2b67b73507
|
https://github.com/ConnectHolland/tulip-api-client/blob/641325e2d57c1c272ede7fd8b47d4f2b67b73507/src/Client.php#L85-L88
|
20,151 |
ConnectHolland/tulip-api-client
|
src/Client.php
|
Client.callService
|
public function callService($serviceName, $action, array $parameters = array(), array $files = array())
{
$httpClient = $this->getHTTPClient();
$url = $this->getServiceUrl($serviceName, $action);
$request = new Request('POST', $url, $this->getRequestHeaders($url, $parameters), $this->getRequestBody($parameters, $files));
try {
$response = $httpClient->send($request);
} catch (GuzzleRequestException $exception) {
$response = $exception->getResponse();
}
$this->validateAPIResponseCode($request, $response);
return $response;
}
|
php
|
public function callService($serviceName, $action, array $parameters = array(), array $files = array())
{
$httpClient = $this->getHTTPClient();
$url = $this->getServiceUrl($serviceName, $action);
$request = new Request('POST', $url, $this->getRequestHeaders($url, $parameters), $this->getRequestBody($parameters, $files));
try {
$response = $httpClient->send($request);
} catch (GuzzleRequestException $exception) {
$response = $exception->getResponse();
}
$this->validateAPIResponseCode($request, $response);
return $response;
}
|
[
"public",
"function",
"callService",
"(",
"$",
"serviceName",
",",
"$",
"action",
",",
"array",
"$",
"parameters",
"=",
"array",
"(",
")",
",",
"array",
"$",
"files",
"=",
"array",
"(",
")",
")",
"{",
"$",
"httpClient",
"=",
"$",
"this",
"->",
"getHTTPClient",
"(",
")",
";",
"$",
"url",
"=",
"$",
"this",
"->",
"getServiceUrl",
"(",
"$",
"serviceName",
",",
"$",
"action",
")",
";",
"$",
"request",
"=",
"new",
"Request",
"(",
"'POST'",
",",
"$",
"url",
",",
"$",
"this",
"->",
"getRequestHeaders",
"(",
"$",
"url",
",",
"$",
"parameters",
")",
",",
"$",
"this",
"->",
"getRequestBody",
"(",
"$",
"parameters",
",",
"$",
"files",
")",
")",
";",
"try",
"{",
"$",
"response",
"=",
"$",
"httpClient",
"->",
"send",
"(",
"$",
"request",
")",
";",
"}",
"catch",
"(",
"GuzzleRequestException",
"$",
"exception",
")",
"{",
"$",
"response",
"=",
"$",
"exception",
"->",
"getResponse",
"(",
")",
";",
"}",
"$",
"this",
"->",
"validateAPIResponseCode",
"(",
"$",
"request",
",",
"$",
"response",
")",
";",
"return",
"$",
"response",
";",
"}"
] |
Call a Tulip API service.
@param string $serviceName
@param string $action
@param array $parameters
@param array $files
@return ResponseInterface
@throws RequestException
|
[
"Call",
"a",
"Tulip",
"API",
"service",
"."
] |
641325e2d57c1c272ede7fd8b47d4f2b67b73507
|
https://github.com/ConnectHolland/tulip-api-client/blob/641325e2d57c1c272ede7fd8b47d4f2b67b73507/src/Client.php#L112-L128
|
20,152 |
ConnectHolland/tulip-api-client
|
src/Client.php
|
Client.getHTTPClient
|
private function getHTTPClient()
{
if ($this->httpClient instanceof ClientInterface === false) {
$this->httpClient = new HTTPClient();
}
return $this->httpClient;
}
|
php
|
private function getHTTPClient()
{
if ($this->httpClient instanceof ClientInterface === false) {
$this->httpClient = new HTTPClient();
}
return $this->httpClient;
}
|
[
"private",
"function",
"getHTTPClient",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"httpClient",
"instanceof",
"ClientInterface",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"httpClient",
"=",
"new",
"HTTPClient",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"httpClient",
";",
"}"
] |
Returns a ClientInterface instance.
@return ClientInterface
|
[
"Returns",
"a",
"ClientInterface",
"instance",
"."
] |
641325e2d57c1c272ede7fd8b47d4f2b67b73507
|
https://github.com/ConnectHolland/tulip-api-client/blob/641325e2d57c1c272ede7fd8b47d4f2b67b73507/src/Client.php#L135-L142
|
20,153 |
ConnectHolland/tulip-api-client
|
src/Client.php
|
Client.getRequestHeaders
|
private function getRequestHeaders($url, array $parameters)
{
$headers = array();
if (isset($this->clientId) && isset($this->sharedSecret)) {
$objectIdentifier = null;
if ($this->apiVersion === '1.1' && isset($parameters['id'])) {
$objectIdentifier = $parameters['id'];
} elseif ($this->apiVersion === '1.0' && isset($parameters['api_id'])) {
$objectIdentifier = $parameters['api_id'];
}
$headers['X-Tulip-Client-ID'] = $this->clientId;
$headers['X-Tulip-Client-Authentication'] = hash_hmac('sha256', $this->clientId.$url.$objectIdentifier, $this->sharedSecret);
}
return $headers;
}
|
php
|
private function getRequestHeaders($url, array $parameters)
{
$headers = array();
if (isset($this->clientId) && isset($this->sharedSecret)) {
$objectIdentifier = null;
if ($this->apiVersion === '1.1' && isset($parameters['id'])) {
$objectIdentifier = $parameters['id'];
} elseif ($this->apiVersion === '1.0' && isset($parameters['api_id'])) {
$objectIdentifier = $parameters['api_id'];
}
$headers['X-Tulip-Client-ID'] = $this->clientId;
$headers['X-Tulip-Client-Authentication'] = hash_hmac('sha256', $this->clientId.$url.$objectIdentifier, $this->sharedSecret);
}
return $headers;
}
|
[
"private",
"function",
"getRequestHeaders",
"(",
"$",
"url",
",",
"array",
"$",
"parameters",
")",
"{",
"$",
"headers",
"=",
"array",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"clientId",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"sharedSecret",
")",
")",
"{",
"$",
"objectIdentifier",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"apiVersion",
"===",
"'1.1'",
"&&",
"isset",
"(",
"$",
"parameters",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"objectIdentifier",
"=",
"$",
"parameters",
"[",
"'id'",
"]",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"apiVersion",
"===",
"'1.0'",
"&&",
"isset",
"(",
"$",
"parameters",
"[",
"'api_id'",
"]",
")",
")",
"{",
"$",
"objectIdentifier",
"=",
"$",
"parameters",
"[",
"'api_id'",
"]",
";",
"}",
"$",
"headers",
"[",
"'X-Tulip-Client-ID'",
"]",
"=",
"$",
"this",
"->",
"clientId",
";",
"$",
"headers",
"[",
"'X-Tulip-Client-Authentication'",
"]",
"=",
"hash_hmac",
"(",
"'sha256'",
",",
"$",
"this",
"->",
"clientId",
".",
"$",
"url",
".",
"$",
"objectIdentifier",
",",
"$",
"this",
"->",
"sharedSecret",
")",
";",
"}",
"return",
"$",
"headers",
";",
"}"
] |
Returns the request authentication headers when a client ID and shared secret are provided.
@param string $url
@param array $parameters
@return array
|
[
"Returns",
"the",
"request",
"authentication",
"headers",
"when",
"a",
"client",
"ID",
"and",
"shared",
"secret",
"are",
"provided",
"."
] |
641325e2d57c1c272ede7fd8b47d4f2b67b73507
|
https://github.com/ConnectHolland/tulip-api-client/blob/641325e2d57c1c272ede7fd8b47d4f2b67b73507/src/Client.php#L152-L169
|
20,154 |
ConnectHolland/tulip-api-client
|
src/Client.php
|
Client.getRequestBody
|
private function getRequestBody(array $parameters, array $files)
{
$body = array();
foreach ($parameters as $parameterName => $parameterValue) {
if (is_scalar($parameterValue) || (is_null($parameterValue) && $parameterName !== 'id')) {
$body[] = array(
'name' => $parameterName,
'contents' => strval($parameterValue),
);
}
}
foreach ($files as $parameterName => $fileResource) {
if (is_resource($fileResource)) {
$metaData = stream_get_meta_data($fileResource);
$body[] = array(
'name' => $parameterName,
'contents' => $fileResource,
'filename' => basename($metaData['uri']),
);
}
}
return new MultipartStream($body);
}
|
php
|
private function getRequestBody(array $parameters, array $files)
{
$body = array();
foreach ($parameters as $parameterName => $parameterValue) {
if (is_scalar($parameterValue) || (is_null($parameterValue) && $parameterName !== 'id')) {
$body[] = array(
'name' => $parameterName,
'contents' => strval($parameterValue),
);
}
}
foreach ($files as $parameterName => $fileResource) {
if (is_resource($fileResource)) {
$metaData = stream_get_meta_data($fileResource);
$body[] = array(
'name' => $parameterName,
'contents' => $fileResource,
'filename' => basename($metaData['uri']),
);
}
}
return new MultipartStream($body);
}
|
[
"private",
"function",
"getRequestBody",
"(",
"array",
"$",
"parameters",
",",
"array",
"$",
"files",
")",
"{",
"$",
"body",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"parameterName",
"=>",
"$",
"parameterValue",
")",
"{",
"if",
"(",
"is_scalar",
"(",
"$",
"parameterValue",
")",
"||",
"(",
"is_null",
"(",
"$",
"parameterValue",
")",
"&&",
"$",
"parameterName",
"!==",
"'id'",
")",
")",
"{",
"$",
"body",
"[",
"]",
"=",
"array",
"(",
"'name'",
"=>",
"$",
"parameterName",
",",
"'contents'",
"=>",
"strval",
"(",
"$",
"parameterValue",
")",
",",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"files",
"as",
"$",
"parameterName",
"=>",
"$",
"fileResource",
")",
"{",
"if",
"(",
"is_resource",
"(",
"$",
"fileResource",
")",
")",
"{",
"$",
"metaData",
"=",
"stream_get_meta_data",
"(",
"$",
"fileResource",
")",
";",
"$",
"body",
"[",
"]",
"=",
"array",
"(",
"'name'",
"=>",
"$",
"parameterName",
",",
"'contents'",
"=>",
"$",
"fileResource",
",",
"'filename'",
"=>",
"basename",
"(",
"$",
"metaData",
"[",
"'uri'",
"]",
")",
",",
")",
";",
"}",
"}",
"return",
"new",
"MultipartStream",
"(",
"$",
"body",
")",
";",
"}"
] |
Returns the multipart request body with the parameters and files.
@param array $parameters
@param array $files
@return MultipartStream
|
[
"Returns",
"the",
"multipart",
"request",
"body",
"with",
"the",
"parameters",
"and",
"files",
"."
] |
641325e2d57c1c272ede7fd8b47d4f2b67b73507
|
https://github.com/ConnectHolland/tulip-api-client/blob/641325e2d57c1c272ede7fd8b47d4f2b67b73507/src/Client.php#L179-L204
|
20,155 |
ConnectHolland/tulip-api-client
|
src/Client.php
|
Client.validateAPIResponseCode
|
private function validateAPIResponseCode(RequestInterface $request, ResponseInterface $response)
{
$responseParser = new ResponseParser($response);
switch ($responseParser->getResponseCode()) {
case ResponseCodes::SUCCESS:
break;
case ResponseCodes::NOT_AUTHORIZED:
throw new NotAuthorizedException($responseParser->getErrorMessage(), $request, $response);
case ResponseCodes::UNKNOWN_SERVICE:
throw new UnknownServiceException($responseParser->getErrorMessage(), $request, $response);
case ResponseCodes::PARAMETERS_REQUIRED:
throw new ParametersRequiredException($responseParser->getErrorMessage(), $request, $response);
case ResponseCodes::NON_EXISTING_OBJECT:
throw new NonExistingObjectException($responseParser->getErrorMessage(), $request, $response);
case ResponseCodes::UNKNOWN_ERROR:
default:
throw new UnknownErrorException($responseParser->getErrorMessage(), $request, $response);
}
}
|
php
|
private function validateAPIResponseCode(RequestInterface $request, ResponseInterface $response)
{
$responseParser = new ResponseParser($response);
switch ($responseParser->getResponseCode()) {
case ResponseCodes::SUCCESS:
break;
case ResponseCodes::NOT_AUTHORIZED:
throw new NotAuthorizedException($responseParser->getErrorMessage(), $request, $response);
case ResponseCodes::UNKNOWN_SERVICE:
throw new UnknownServiceException($responseParser->getErrorMessage(), $request, $response);
case ResponseCodes::PARAMETERS_REQUIRED:
throw new ParametersRequiredException($responseParser->getErrorMessage(), $request, $response);
case ResponseCodes::NON_EXISTING_OBJECT:
throw new NonExistingObjectException($responseParser->getErrorMessage(), $request, $response);
case ResponseCodes::UNKNOWN_ERROR:
default:
throw new UnknownErrorException($responseParser->getErrorMessage(), $request, $response);
}
}
|
[
"private",
"function",
"validateAPIResponseCode",
"(",
"RequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
")",
"{",
"$",
"responseParser",
"=",
"new",
"ResponseParser",
"(",
"$",
"response",
")",
";",
"switch",
"(",
"$",
"responseParser",
"->",
"getResponseCode",
"(",
")",
")",
"{",
"case",
"ResponseCodes",
"::",
"SUCCESS",
":",
"break",
";",
"case",
"ResponseCodes",
"::",
"NOT_AUTHORIZED",
":",
"throw",
"new",
"NotAuthorizedException",
"(",
"$",
"responseParser",
"->",
"getErrorMessage",
"(",
")",
",",
"$",
"request",
",",
"$",
"response",
")",
";",
"case",
"ResponseCodes",
"::",
"UNKNOWN_SERVICE",
":",
"throw",
"new",
"UnknownServiceException",
"(",
"$",
"responseParser",
"->",
"getErrorMessage",
"(",
")",
",",
"$",
"request",
",",
"$",
"response",
")",
";",
"case",
"ResponseCodes",
"::",
"PARAMETERS_REQUIRED",
":",
"throw",
"new",
"ParametersRequiredException",
"(",
"$",
"responseParser",
"->",
"getErrorMessage",
"(",
")",
",",
"$",
"request",
",",
"$",
"response",
")",
";",
"case",
"ResponseCodes",
"::",
"NON_EXISTING_OBJECT",
":",
"throw",
"new",
"NonExistingObjectException",
"(",
"$",
"responseParser",
"->",
"getErrorMessage",
"(",
")",
",",
"$",
"request",
",",
"$",
"response",
")",
";",
"case",
"ResponseCodes",
"::",
"UNKNOWN_ERROR",
":",
"default",
":",
"throw",
"new",
"UnknownErrorException",
"(",
"$",
"responseParser",
"->",
"getErrorMessage",
"(",
")",
",",
"$",
"request",
",",
"$",
"response",
")",
";",
"}",
"}"
] |
Validates the Tulip API response code.
@param RequestInterface $request
@param ResponseInterface $response
@throws NotAuthorizedException when not authenticated / authorized correctly.
@throws UnknownServiceException when the called API service is not found within the Tulip API.
@throws ParametersRequiredException when the required parameters for the service / action were not provided or incorrect.
@throws NonExistingObjectException when a requested object was not found.
@throws UnknownErrorException when an error occurs within the Tulip API.
|
[
"Validates",
"the",
"Tulip",
"API",
"response",
"code",
"."
] |
641325e2d57c1c272ede7fd8b47d4f2b67b73507
|
https://github.com/ConnectHolland/tulip-api-client/blob/641325e2d57c1c272ede7fd8b47d4f2b67b73507/src/Client.php#L218-L236
|
20,156 |
webforge-labs/psc-cms
|
lib/Psc/Data/Set.php
|
Set.setFieldsFromArray
|
public function setFieldsFromArray(Array $fields) {
foreach ($fields as $field => $value) {
$this->set($field, $value);
}
return $this;
}
|
php
|
public function setFieldsFromArray(Array $fields) {
foreach ($fields as $field => $value) {
$this->set($field, $value);
}
return $this;
}
|
[
"public",
"function",
"setFieldsFromArray",
"(",
"Array",
"$",
"fields",
")",
"{",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"set",
"(",
"$",
"field",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Setzt mehrere Felder aus einem Array
die Felder die als Schlüssel angegeben werden, müssen alle als Meta existieren
@param array $fields Schlüssel sind mit . getrennte strings Werte sind die Werte der Felder
|
[
"Setzt",
"mehrere",
"Felder",
"aus",
"einem",
"Array"
] |
467bfa2547e6b4fa487d2d7f35fa6cc618dbc763
|
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Data/Set.php#L112-L117
|
20,157 |
webforge-labs/psc-cms
|
lib/Psc/Data/Set.php
|
Set.createFromStruct
|
public static function createFromStruct(Array $struct, SetMeta $meta = NULL) {
if (!isset($meta)) $meta = new SetMeta();
$set = new static(array(), $meta);
foreach ($struct as $field => $list) {
list($value, $type) = $list;
$set->set($field, $value, $type);
}
return $set;
}
|
php
|
public static function createFromStruct(Array $struct, SetMeta $meta = NULL) {
if (!isset($meta)) $meta = new SetMeta();
$set = new static(array(), $meta);
foreach ($struct as $field => $list) {
list($value, $type) = $list;
$set->set($field, $value, $type);
}
return $set;
}
|
[
"public",
"static",
"function",
"createFromStruct",
"(",
"Array",
"$",
"struct",
",",
"SetMeta",
"$",
"meta",
"=",
"NULL",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"meta",
")",
")",
"$",
"meta",
"=",
"new",
"SetMeta",
"(",
")",
";",
"$",
"set",
"=",
"new",
"static",
"(",
"array",
"(",
")",
",",
"$",
"meta",
")",
";",
"foreach",
"(",
"$",
"struct",
"as",
"$",
"field",
"=>",
"$",
"list",
")",
"{",
"list",
"(",
"$",
"value",
",",
"$",
"type",
")",
"=",
"$",
"list",
";",
"$",
"set",
"->",
"set",
"(",
"$",
"field",
",",
"$",
"value",
",",
"$",
"type",
")",
";",
"}",
"return",
"$",
"set",
";",
"}"
] |
Erstellt ein Set mit angegebenen Metadaten
Shortcoming um die Felder des Sets nicht doppelt bezeichnen zu müssen
struct ist ein Array von Listen mit jeweils genau 2 elementen (key 0 und key 1)
@param list[] $struct die Listen sind von der Form: list(mixed $fieldValue, Webforge\Types\Type $fieldType). Die Schlüssel sind die Feldnamen
@return Set
|
[
"Erstellt",
"ein",
"Set",
"mit",
"angegebenen",
"Metadaten"
] |
467bfa2547e6b4fa487d2d7f35fa6cc618dbc763
|
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Data/Set.php#L166-L176
|
20,158 |
webforge-labs/psc-cms
|
lib/Psc/PHP/Lexer.php
|
Lexer.init
|
public function init($source) {
$this->source = $source; // für debug
$this->scan($source);
$this->reset();
}
|
php
|
public function init($source) {
$this->source = $source; // für debug
$this->scan($source);
$this->reset();
}
|
[
"public",
"function",
"init",
"(",
"$",
"source",
")",
"{",
"$",
"this",
"->",
"source",
"=",
"$",
"source",
";",
"// für debug",
"$",
"this",
"->",
"scan",
"(",
"$",
"source",
")",
";",
"$",
"this",
"->",
"reset",
"(",
")",
";",
"}"
] |
Initialisiert den Lexer
der Sourcecode wird gelesen und in tokens übersetzt
nach diesem Befehl ist der erste token in $this->token gesetzt
|
[
"Initialisiert",
"den",
"Lexer"
] |
467bfa2547e6b4fa487d2d7f35fa6cc618dbc763
|
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/PHP/Lexer.php#L114-L118
|
20,159 |
webforge-labs/psc-cms
|
lib/Psc/Doctrine/EntityRepository.php
|
EntityRepository.save
|
public function save(Entity $entity) {
$this->_em->persist($entity);
$this->_em->flush();
return $this;
}
|
php
|
public function save(Entity $entity) {
$this->_em->persist($entity);
$this->_em->flush();
return $this;
}
|
[
"public",
"function",
"save",
"(",
"Entity",
"$",
"entity",
")",
"{",
"$",
"this",
"->",
"_em",
"->",
"persist",
"(",
"$",
"entity",
")",
";",
"$",
"this",
"->",
"_em",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Persisted das Entity und flushed den EntityManager
|
[
"Persisted",
"das",
"Entity",
"und",
"flushed",
"den",
"EntityManager"
] |
467bfa2547e6b4fa487d2d7f35fa6cc618dbc763
|
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/EntityRepository.php#L40-L44
|
20,160 |
webforge-labs/psc-cms
|
lib/Psc/Doctrine/EntityRepository.php
|
EntityRepository.hydrateRole
|
public function hydrateRole($role, $identifier) {
return $this->_em->getRepository($this->_class->namespace.'\\'.ucfirst($role))->hydrate($identifier);
}
|
php
|
public function hydrateRole($role, $identifier) {
return $this->_em->getRepository($this->_class->namespace.'\\'.ucfirst($role))->hydrate($identifier);
}
|
[
"public",
"function",
"hydrateRole",
"(",
"$",
"role",
",",
"$",
"identifier",
")",
"{",
"return",
"$",
"this",
"->",
"_em",
"->",
"getRepository",
"(",
"$",
"this",
"->",
"_class",
"->",
"namespace",
".",
"'\\\\'",
".",
"ucfirst",
"(",
"$",
"role",
")",
")",
"->",
"hydrate",
"(",
"$",
"identifier",
")",
";",
"}"
] |
Returns an entity of the project, which implements a specific Psc\CMS\Role
@return Psc\CMS\Role\$role.toCamelCase()
|
[
"Returns",
"an",
"entity",
"of",
"the",
"project",
"which",
"implements",
"a",
"specific",
"Psc",
"\\",
"CMS",
"\\",
"Role"
] |
467bfa2547e6b4fa487d2d7f35fa6cc618dbc763
|
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/EntityRepository.php#L104-L106
|
20,161 |
webforge-labs/psc-cms
|
lib/Psc/Doctrine/EntityRepository.php
|
EntityRepository.hydrateBy
|
public function hydrateBy(array $criterias) {
$entity = $this->findOneBy($criterias);
if (!($entity instanceof $this->_entityName)) {
throw new EntityNotFoundException(sprintf('Entity %s nicht gefunden: criterias: %s', $this->_entityName, Code::varInfo($criterias)));
}
return $entity;
}
|
php
|
public function hydrateBy(array $criterias) {
$entity = $this->findOneBy($criterias);
if (!($entity instanceof $this->_entityName)) {
throw new EntityNotFoundException(sprintf('Entity %s nicht gefunden: criterias: %s', $this->_entityName, Code::varInfo($criterias)));
}
return $entity;
}
|
[
"public",
"function",
"hydrateBy",
"(",
"array",
"$",
"criterias",
")",
"{",
"$",
"entity",
"=",
"$",
"this",
"->",
"findOneBy",
"(",
"$",
"criterias",
")",
";",
"if",
"(",
"!",
"(",
"$",
"entity",
"instanceof",
"$",
"this",
"->",
"_entityName",
")",
")",
"{",
"throw",
"new",
"EntityNotFoundException",
"(",
"sprintf",
"(",
"'Entity %s nicht gefunden: criterias: %s'",
",",
"$",
"this",
"->",
"_entityName",
",",
"Code",
"::",
"varInfo",
"(",
"$",
"criterias",
")",
")",
")",
";",
"}",
"return",
"$",
"entity",
";",
"}"
] |
Sowie findOneBy aber mit exception
@throws \Psc\Exception
|
[
"Sowie",
"findOneBy",
"aber",
"mit",
"exception"
] |
467bfa2547e6b4fa487d2d7f35fa6cc618dbc763
|
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/EntityRepository.php#L135-L143
|
20,162 |
webforge-labs/psc-cms
|
lib/Psc/Doctrine/EntityRepository.php
|
EntityRepository.configureUniqueConstraintValidator
|
public function configureUniqueConstraintValidator(UniqueConstraintValidator $validator = NULL) {
$uniqueConstraints = $this->getUniqueConstraints();
if (!isset($validator)) {
// erstelle einen neuen
$constraint = array_shift($uniqueConstraints);
$validator = new UniqueConstraintValidator($constraint);
}
// benutze den bestehenden / füge die restlichen UniqueConstraints hinzu
foreach ($uniqueConstraints as $constraint) {
$validator->addUniqueConstraint($constraint);
}
/* verarbeiten die Daten für alle Constraints */
foreach ($validator->getUniqueConstraints() as $constraint) {
$validator->updateIndex($constraint, $this->getUniqueIndex($constraint));
}
return $validator;
}
|
php
|
public function configureUniqueConstraintValidator(UniqueConstraintValidator $validator = NULL) {
$uniqueConstraints = $this->getUniqueConstraints();
if (!isset($validator)) {
// erstelle einen neuen
$constraint = array_shift($uniqueConstraints);
$validator = new UniqueConstraintValidator($constraint);
}
// benutze den bestehenden / füge die restlichen UniqueConstraints hinzu
foreach ($uniqueConstraints as $constraint) {
$validator->addUniqueConstraint($constraint);
}
/* verarbeiten die Daten für alle Constraints */
foreach ($validator->getUniqueConstraints() as $constraint) {
$validator->updateIndex($constraint, $this->getUniqueIndex($constraint));
}
return $validator;
}
|
[
"public",
"function",
"configureUniqueConstraintValidator",
"(",
"UniqueConstraintValidator",
"$",
"validator",
"=",
"NULL",
")",
"{",
"$",
"uniqueConstraints",
"=",
"$",
"this",
"->",
"getUniqueConstraints",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"validator",
")",
")",
"{",
"// erstelle einen neuen\r",
"$",
"constraint",
"=",
"array_shift",
"(",
"$",
"uniqueConstraints",
")",
";",
"$",
"validator",
"=",
"new",
"UniqueConstraintValidator",
"(",
"$",
"constraint",
")",
";",
"}",
"// benutze den bestehenden / füge die restlichen UniqueConstraints hinzu\r",
"foreach",
"(",
"$",
"uniqueConstraints",
"as",
"$",
"constraint",
")",
"{",
"$",
"validator",
"->",
"addUniqueConstraint",
"(",
"$",
"constraint",
")",
";",
"}",
"/* verarbeiten die Daten für alle Constraints */\r",
"foreach",
"(",
"$",
"validator",
"->",
"getUniqueConstraints",
"(",
")",
"as",
"$",
"constraint",
")",
"{",
"$",
"validator",
"->",
"updateIndex",
"(",
"$",
"constraint",
",",
"$",
"this",
"->",
"getUniqueIndex",
"(",
"$",
"constraint",
")",
")",
";",
"}",
"return",
"$",
"validator",
";",
"}"
] |
Setzt einen UniqueConstraintValidator mit den passenden UniqueConstraints des Entities
sind keine Unique-Constraints für diese Klasse gesetzt, wird eine \Psc\Doctrine\NoUniqueConstraintException geworfen
@throws Psc\Doctrine\UniqueConstraintException, wenn $this->getUniqueIndex() einen inkonsistenten Index zurückgibt (index mit duplikaten)
|
[
"Setzt",
"einen",
"UniqueConstraintValidator",
"mit",
"den",
"passenden",
"UniqueConstraints",
"des",
"Entities"
] |
467bfa2547e6b4fa487d2d7f35fa6cc618dbc763
|
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/Doctrine/EntityRepository.php#L222-L242
|
20,163 |
davidgorges/color-contrast-php
|
src/ColorContrast.php
|
ColorContrast.calculateYIQValue
|
private function calculateYIQValue(RGB $color)
{
$yiq = (($color->getRed() * 299) + ($color->getGreen() * 587) + ($color->getBlue() * 114)) / 1000;
return $yiq;
}
|
php
|
private function calculateYIQValue(RGB $color)
{
$yiq = (($color->getRed() * 299) + ($color->getGreen() * 587) + ($color->getBlue() * 114)) / 1000;
return $yiq;
}
|
[
"private",
"function",
"calculateYIQValue",
"(",
"RGB",
"$",
"color",
")",
"{",
"$",
"yiq",
"=",
"(",
"(",
"$",
"color",
"->",
"getRed",
"(",
")",
"*",
"299",
")",
"+",
"(",
"$",
"color",
"->",
"getGreen",
"(",
")",
"*",
"587",
")",
"+",
"(",
"$",
"color",
"->",
"getBlue",
"(",
")",
"*",
"114",
")",
")",
"/",
"1000",
";",
"return",
"$",
"yiq",
";",
"}"
] |
calculates the YIQ value for a given color.
@param RGB $color
@return float 0-255
|
[
"calculates",
"the",
"YIQ",
"value",
"for",
"a",
"given",
"color",
"."
] |
11edc6e04ce73d8d9b0bffeda1586f2c2fa22e71
|
https://github.com/davidgorges/color-contrast-php/blob/11edc6e04ce73d8d9b0bffeda1586f2c2fa22e71/src/ColorContrast.php#L169-L173
|
20,164 |
aryelgois/yasql-php
|
src/Parser.php
|
Parser.extractKeyword
|
protected static function extractKeyword(
string $haystack,
string $needle,
&$matches = null
) {
$pattern = '/' . (strpos($needle, '^') === 0 ? '' : ' ?') . $needle
. (strrpos($needle, '$') === strlen($needle)-1 ? '' : ' ?') . '/i';
if (preg_match($pattern, $haystack, $matches, PREG_OFFSET_CAPTURE)) {
$m = $matches[0];
$haystack = substr_replace($haystack, ' ', $m[1], strlen($m[0]));
return trim($haystack);
}
return false;
}
|
php
|
protected static function extractKeyword(
string $haystack,
string $needle,
&$matches = null
) {
$pattern = '/' . (strpos($needle, '^') === 0 ? '' : ' ?') . $needle
. (strrpos($needle, '$') === strlen($needle)-1 ? '' : ' ?') . '/i';
if (preg_match($pattern, $haystack, $matches, PREG_OFFSET_CAPTURE)) {
$m = $matches[0];
$haystack = substr_replace($haystack, ' ', $m[1], strlen($m[0]));
return trim($haystack);
}
return false;
}
|
[
"protected",
"static",
"function",
"extractKeyword",
"(",
"string",
"$",
"haystack",
",",
"string",
"$",
"needle",
",",
"&",
"$",
"matches",
"=",
"null",
")",
"{",
"$",
"pattern",
"=",
"'/'",
".",
"(",
"strpos",
"(",
"$",
"needle",
",",
"'^'",
")",
"===",
"0",
"?",
"''",
":",
"' ?'",
")",
".",
"$",
"needle",
".",
"(",
"strrpos",
"(",
"$",
"needle",
",",
"'$'",
")",
"===",
"strlen",
"(",
"$",
"needle",
")",
"-",
"1",
"?",
"''",
":",
"' ?'",
")",
".",
"'/i'",
";",
"if",
"(",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"haystack",
",",
"$",
"matches",
",",
"PREG_OFFSET_CAPTURE",
")",
")",
"{",
"$",
"m",
"=",
"$",
"matches",
"[",
"0",
"]",
";",
"$",
"haystack",
"=",
"substr_replace",
"(",
"$",
"haystack",
",",
"' '",
",",
"$",
"m",
"[",
"1",
"]",
",",
"strlen",
"(",
"$",
"m",
"[",
"0",
"]",
")",
")",
";",
"return",
"trim",
"(",
"$",
"haystack",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Extracts a keyword from a string
@param string $haystack String to look for the keyword
@param string $needle PCRE subpattern with the keyword (insensitive)
@param string $matches @see \preg_match() $matches (PREG_OFFSET_CAPTURE)
@return false If the keyword was not found
@return string The string without the keyword
|
[
"Extracts",
"a",
"keyword",
"from",
"a",
"string"
] |
f428b180d35bfc1ddf1f9b3323f9b085fbc09ac7
|
https://github.com/aryelgois/yasql-php/blob/f428b180d35bfc1ddf1f9b3323f9b085fbc09ac7/src/Parser.php#L404-L418
|
20,165 |
titon/db
|
src/Titon/Db/Database.php
|
Database.getDriver
|
public function getDriver($key) {
if (isset($this->_drivers[$key])) {
return $this->_drivers[$key];
}
throw new MissingDriverException(sprintf('Driver %s does not exist', $key));
}
|
php
|
public function getDriver($key) {
if (isset($this->_drivers[$key])) {
return $this->_drivers[$key];
}
throw new MissingDriverException(sprintf('Driver %s does not exist', $key));
}
|
[
"public",
"function",
"getDriver",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_drivers",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_drivers",
"[",
"$",
"key",
"]",
";",
"}",
"throw",
"new",
"MissingDriverException",
"(",
"sprintf",
"(",
"'Driver %s does not exist'",
",",
"$",
"key",
")",
")",
";",
"}"
] |
Return a driver by key.
@param string $key
@return \Titon\Db\Driver
@throws \Titon\Db\Exception\MissingDriverException
|
[
"Return",
"a",
"driver",
"by",
"key",
"."
] |
fbc5159d1ce9d2139759c9367565986981485604
|
https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Database.php#L49-L55
|
20,166 |
claroline/ForumBundle
|
Controller/ForumController.php
|
ForumController.createSubjectAction
|
public function createSubjectAction(Category $category)
{
$forum = $category->getForum();
$collection = new ResourceCollection(array($forum->getResourceNode()));
if (!$this->authorization->isGranted('post', $collection)) {
throw new AccessDeniedException($collection->getErrorsForDisplay());
}
$form = $this->get('form.factory')->create(new SubjectType(), new Subject);
$form->handleRequest($this->get('request'));
if ($form->isValid()) {
$user = $this->tokenStorage->getToken()->getUser();
$subject = $form->getData();
$subject->setCreator($user);
$subject->setAuthor($user->getFirstName() . ' ' . $user->getLastName());
//instantiation of the new resources
$subject->setCategory($category);
$this->manager->createSubject($subject);
$dataMessage = $form->get('message')->getData();
if ($dataMessage['content'] !== null) {
$message = new Message();
$message->setContent($dataMessage['content']);
$message->setCreator($user);
$message->setAuthor($user->getFirstName() . ' ' . $user->getLastName());
$message->setSubject($subject);
$this->manager->createMessage($message, $subject);
return new RedirectResponse(
$this->generateUrl('claro_forum_subjects', array('category' => $category->getId()))
);
}
}
$form->get('message')->addError(
new FormError($this->get('translator')->trans('field_content_required', array(), 'forum'))
);
return array(
'form' => $form->createView(),
'_resource' => $forum,
'workspace' => $forum->getResourceNode()->getWorkspace()
);
}
|
php
|
public function createSubjectAction(Category $category)
{
$forum = $category->getForum();
$collection = new ResourceCollection(array($forum->getResourceNode()));
if (!$this->authorization->isGranted('post', $collection)) {
throw new AccessDeniedException($collection->getErrorsForDisplay());
}
$form = $this->get('form.factory')->create(new SubjectType(), new Subject);
$form->handleRequest($this->get('request'));
if ($form->isValid()) {
$user = $this->tokenStorage->getToken()->getUser();
$subject = $form->getData();
$subject->setCreator($user);
$subject->setAuthor($user->getFirstName() . ' ' . $user->getLastName());
//instantiation of the new resources
$subject->setCategory($category);
$this->manager->createSubject($subject);
$dataMessage = $form->get('message')->getData();
if ($dataMessage['content'] !== null) {
$message = new Message();
$message->setContent($dataMessage['content']);
$message->setCreator($user);
$message->setAuthor($user->getFirstName() . ' ' . $user->getLastName());
$message->setSubject($subject);
$this->manager->createMessage($message, $subject);
return new RedirectResponse(
$this->generateUrl('claro_forum_subjects', array('category' => $category->getId()))
);
}
}
$form->get('message')->addError(
new FormError($this->get('translator')->trans('field_content_required', array(), 'forum'))
);
return array(
'form' => $form->createView(),
'_resource' => $forum,
'workspace' => $forum->getResourceNode()->getWorkspace()
);
}
|
[
"public",
"function",
"createSubjectAction",
"(",
"Category",
"$",
"category",
")",
"{",
"$",
"forum",
"=",
"$",
"category",
"->",
"getForum",
"(",
")",
";",
"$",
"collection",
"=",
"new",
"ResourceCollection",
"(",
"array",
"(",
"$",
"forum",
"->",
"getResourceNode",
"(",
")",
")",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"authorization",
"->",
"isGranted",
"(",
"'post'",
",",
"$",
"collection",
")",
")",
"{",
"throw",
"new",
"AccessDeniedException",
"(",
"$",
"collection",
"->",
"getErrorsForDisplay",
"(",
")",
")",
";",
"}",
"$",
"form",
"=",
"$",
"this",
"->",
"get",
"(",
"'form.factory'",
")",
"->",
"create",
"(",
"new",
"SubjectType",
"(",
")",
",",
"new",
"Subject",
")",
";",
"$",
"form",
"->",
"handleRequest",
"(",
"$",
"this",
"->",
"get",
"(",
"'request'",
")",
")",
";",
"if",
"(",
"$",
"form",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"tokenStorage",
"->",
"getToken",
"(",
")",
"->",
"getUser",
"(",
")",
";",
"$",
"subject",
"=",
"$",
"form",
"->",
"getData",
"(",
")",
";",
"$",
"subject",
"->",
"setCreator",
"(",
"$",
"user",
")",
";",
"$",
"subject",
"->",
"setAuthor",
"(",
"$",
"user",
"->",
"getFirstName",
"(",
")",
".",
"' '",
".",
"$",
"user",
"->",
"getLastName",
"(",
")",
")",
";",
"//instantiation of the new resources",
"$",
"subject",
"->",
"setCategory",
"(",
"$",
"category",
")",
";",
"$",
"this",
"->",
"manager",
"->",
"createSubject",
"(",
"$",
"subject",
")",
";",
"$",
"dataMessage",
"=",
"$",
"form",
"->",
"get",
"(",
"'message'",
")",
"->",
"getData",
"(",
")",
";",
"if",
"(",
"$",
"dataMessage",
"[",
"'content'",
"]",
"!==",
"null",
")",
"{",
"$",
"message",
"=",
"new",
"Message",
"(",
")",
";",
"$",
"message",
"->",
"setContent",
"(",
"$",
"dataMessage",
"[",
"'content'",
"]",
")",
";",
"$",
"message",
"->",
"setCreator",
"(",
"$",
"user",
")",
";",
"$",
"message",
"->",
"setAuthor",
"(",
"$",
"user",
"->",
"getFirstName",
"(",
")",
".",
"' '",
".",
"$",
"user",
"->",
"getLastName",
"(",
")",
")",
";",
"$",
"message",
"->",
"setSubject",
"(",
"$",
"subject",
")",
";",
"$",
"this",
"->",
"manager",
"->",
"createMessage",
"(",
"$",
"message",
",",
"$",
"subject",
")",
";",
"return",
"new",
"RedirectResponse",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'claro_forum_subjects'",
",",
"array",
"(",
"'category'",
"=>",
"$",
"category",
"->",
"getId",
"(",
")",
")",
")",
")",
";",
"}",
"}",
"$",
"form",
"->",
"get",
"(",
"'message'",
")",
"->",
"addError",
"(",
"new",
"FormError",
"(",
"$",
"this",
"->",
"get",
"(",
"'translator'",
")",
"->",
"trans",
"(",
"'field_content_required'",
",",
"array",
"(",
")",
",",
"'forum'",
")",
")",
")",
";",
"return",
"array",
"(",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
",",
"'_resource'",
"=>",
"$",
"forum",
",",
"'workspace'",
"=>",
"$",
"forum",
"->",
"getResourceNode",
"(",
")",
"->",
"getWorkspace",
"(",
")",
")",
";",
"}"
] |
The form submission is working but I had to do some weird things to make it works.
@Route(
"/subject/create/{category}",
name="claro_forum_create_subject"
)
@ParamConverter("authenticatedUser", options={"authenticatedUser" = true})
@Template("ClarolineForumBundle:Forum:subjectForm.html.twig")
@param Category $category
@throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
@throws \Exception
@return array|\Symfony\Component\HttpFoundation\RedirectResponse
|
[
"The",
"form",
"submission",
"is",
"working",
"but",
"I",
"had",
"to",
"do",
"some",
"weird",
"things",
"to",
"make",
"it",
"works",
"."
] |
bd85dfd870cacee541ea94fec8e59744bf90eaf4
|
https://github.com/claroline/ForumBundle/blob/bd85dfd870cacee541ea94fec8e59744bf90eaf4/Controller/ForumController.php#L272-L317
|
20,167 |
anexia-it/anexia-laravel-encryption
|
src/DatabaseEncryptionScope.php
|
DatabaseEncryptionScope.addWithDecryptKey
|
protected function addWithDecryptKey(Builder $builder)
{
$builder->macro('withDecryptKey', function (Builder $builder, $decryptKey) {
$model = $builder->getModel();
$encryptedFields = $model::getEncryptedFields();
if (!empty($encryptedFields)) {
$builder->setEncryptionModel($model);
/** @var DatabaseEncryptionServiceInterface $encryptionService */
$encryptionService = $model::getEncryptionService();
foreach ($encryptedFields as $encryptedField) {
$decryptStmt = $encryptionService->getDecryptExpression($encryptedField, $decryptKey);
$builder->addEncryptionSelect([
'column' => $encryptedField,
'select' => DB::raw("$decryptStmt as $encryptedField")
]);
}
}
return $builder;
});
}
|
php
|
protected function addWithDecryptKey(Builder $builder)
{
$builder->macro('withDecryptKey', function (Builder $builder, $decryptKey) {
$model = $builder->getModel();
$encryptedFields = $model::getEncryptedFields();
if (!empty($encryptedFields)) {
$builder->setEncryptionModel($model);
/** @var DatabaseEncryptionServiceInterface $encryptionService */
$encryptionService = $model::getEncryptionService();
foreach ($encryptedFields as $encryptedField) {
$decryptStmt = $encryptionService->getDecryptExpression($encryptedField, $decryptKey);
$builder->addEncryptionSelect([
'column' => $encryptedField,
'select' => DB::raw("$decryptStmt as $encryptedField")
]);
}
}
return $builder;
});
}
|
[
"protected",
"function",
"addWithDecryptKey",
"(",
"Builder",
"$",
"builder",
")",
"{",
"$",
"builder",
"->",
"macro",
"(",
"'withDecryptKey'",
",",
"function",
"(",
"Builder",
"$",
"builder",
",",
"$",
"decryptKey",
")",
"{",
"$",
"model",
"=",
"$",
"builder",
"->",
"getModel",
"(",
")",
";",
"$",
"encryptedFields",
"=",
"$",
"model",
"::",
"getEncryptedFields",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"encryptedFields",
")",
")",
"{",
"$",
"builder",
"->",
"setEncryptionModel",
"(",
"$",
"model",
")",
";",
"/** @var DatabaseEncryptionServiceInterface $encryptionService */",
"$",
"encryptionService",
"=",
"$",
"model",
"::",
"getEncryptionService",
"(",
")",
";",
"foreach",
"(",
"$",
"encryptedFields",
"as",
"$",
"encryptedField",
")",
"{",
"$",
"decryptStmt",
"=",
"$",
"encryptionService",
"->",
"getDecryptExpression",
"(",
"$",
"encryptedField",
",",
"$",
"decryptKey",
")",
";",
"$",
"builder",
"->",
"addEncryptionSelect",
"(",
"[",
"'column'",
"=>",
"$",
"encryptedField",
",",
"'select'",
"=>",
"DB",
"::",
"raw",
"(",
"\"$decryptStmt as $encryptedField\"",
")",
"]",
")",
";",
"}",
"}",
"return",
"$",
"builder",
";",
"}",
")",
";",
"}"
] |
Add the with-decrypt-key extension to the builder.
@param \Illuminate\Database\Eloquent\Builder $builder
@return void
|
[
"Add",
"the",
"with",
"-",
"decrypt",
"-",
"key",
"extension",
"to",
"the",
"builder",
"."
] |
b7c72d99916ebca2d2cf2dbab1d4c0f84e383081
|
https://github.com/anexia-it/anexia-laravel-encryption/blob/b7c72d99916ebca2d2cf2dbab1d4c0f84e383081/src/DatabaseEncryptionScope.php#L61-L81
|
20,168 |
neilime/zf2-browscap
|
src/Browscap/BrowscapService.php
|
BrowscapService.factory
|
public static function factory($aOptions){
if($aOptions instanceof \Traversable)$aOptions = \Zend\Stdlib\ArrayUtils::iteratorToArray($aOptions);
elseif(!is_array($aOptions))throw new \InvalidArgumentException(__METHOD__.' expects an array or Traversable object; received "'.(is_object($aOptions)?get_class($aOptions):gettype($aOptions)).'"');
$oBrowscapService = new static();
//Browscap.ini file path
if(isset($aOptions['browscap_ini_path']))$oBrowscapService->setBrowscapIniPath($aOptions['browscap_ini_path']);
//Cache
if(isset($aOptions['cache']))$oBrowscapService->setCache($aOptions['cache']);
if(isset($aOptions['allows_native_get_browser']))$oBrowscapService->setAllowsNativeGetBrowser(!!$aOptions['allows_native_get_browser']);
return $oBrowscapService;
}
|
php
|
public static function factory($aOptions){
if($aOptions instanceof \Traversable)$aOptions = \Zend\Stdlib\ArrayUtils::iteratorToArray($aOptions);
elseif(!is_array($aOptions))throw new \InvalidArgumentException(__METHOD__.' expects an array or Traversable object; received "'.(is_object($aOptions)?get_class($aOptions):gettype($aOptions)).'"');
$oBrowscapService = new static();
//Browscap.ini file path
if(isset($aOptions['browscap_ini_path']))$oBrowscapService->setBrowscapIniPath($aOptions['browscap_ini_path']);
//Cache
if(isset($aOptions['cache']))$oBrowscapService->setCache($aOptions['cache']);
if(isset($aOptions['allows_native_get_browser']))$oBrowscapService->setAllowsNativeGetBrowser(!!$aOptions['allows_native_get_browser']);
return $oBrowscapService;
}
|
[
"public",
"static",
"function",
"factory",
"(",
"$",
"aOptions",
")",
"{",
"if",
"(",
"$",
"aOptions",
"instanceof",
"\\",
"Traversable",
")",
"$",
"aOptions",
"=",
"\\",
"Zend",
"\\",
"Stdlib",
"\\",
"ArrayUtils",
"::",
"iteratorToArray",
"(",
"$",
"aOptions",
")",
";",
"elseif",
"(",
"!",
"is_array",
"(",
"$",
"aOptions",
")",
")",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"__METHOD__",
".",
"' expects an array or Traversable object; received \"'",
".",
"(",
"is_object",
"(",
"$",
"aOptions",
")",
"?",
"get_class",
"(",
"$",
"aOptions",
")",
":",
"gettype",
"(",
"$",
"aOptions",
")",
")",
".",
"'\"'",
")",
";",
"$",
"oBrowscapService",
"=",
"new",
"static",
"(",
")",
";",
"//Browscap.ini file path",
"if",
"(",
"isset",
"(",
"$",
"aOptions",
"[",
"'browscap_ini_path'",
"]",
")",
")",
"$",
"oBrowscapService",
"->",
"setBrowscapIniPath",
"(",
"$",
"aOptions",
"[",
"'browscap_ini_path'",
"]",
")",
";",
"//Cache",
"if",
"(",
"isset",
"(",
"$",
"aOptions",
"[",
"'cache'",
"]",
")",
")",
"$",
"oBrowscapService",
"->",
"setCache",
"(",
"$",
"aOptions",
"[",
"'cache'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"aOptions",
"[",
"'allows_native_get_browser'",
"]",
")",
")",
"$",
"oBrowscapService",
"->",
"setAllowsNativeGetBrowser",
"(",
"!",
"!",
"$",
"aOptions",
"[",
"'allows_native_get_browser'",
"]",
")",
";",
"return",
"$",
"oBrowscapService",
";",
"}"
] |
Instantiate AccessControl Authentication Service
@param array|Traversable $aConfiguration
@param \Zend\ServiceManager\ServiceLocatorInterface $oServiceLocator
@throws \InvalidArgumentException
@return \BoilerAppAccessControl\Authentication\AccessControlAuthenticationService
|
[
"Instantiate",
"AccessControl",
"Authentication",
"Service"
] |
490a4d573a2f6340c67a4254d5a46d3276583e1b
|
https://github.com/neilime/zf2-browscap/blob/490a4d573a2f6340c67a4254d5a46d3276583e1b/src/Browscap/BrowscapService.php#L41-L56
|
20,169 |
neilime/zf2-browscap
|
src/Browscap/BrowscapService.php
|
BrowscapService.loadBrowscapIni
|
public function loadBrowscapIni(){
$sBrowscapIniPath = $this->getBrowscapIniPath();
//Local file
if(is_readable($sBrowscapIniPath)){
$aBrowscap = parse_ini_file($this->getBrowscapIniPath(), true, INI_SCANNER_RAW);
if($aBrowscap === false)throw new \RuntimeException('Error appends while parsing browscap.ini file "'.$sBrowscapIniPath.'"');
}
//Remote file
else{
if(($oFileHandle = @fopen($sBrowscapIniPath, 'r')) === false)throw new \InvalidArgumentException('Unable to load browscap.ini file "'.$sBrowscapIniPath.'"');
$sBrowscapIniContents = '';
while(($sContent = fgets($oFileHandle)) !== false) {
$sBrowscapIniContents .= $sContent.PHP_EOL;
}
if(!feof($oFileHandle))throw new \RuntimeException('Unable to retrieve contents from browscap.ini file "'.$sBrowscapIniPath.'"');
fclose($oFileHandle);
$aBrowscap = parse_ini_string($sBrowscapIniContents, true, INI_SCANNER_RAW);
if($aBrowscap === false)throw new \RuntimeException('Error appends while parsing browscap.ini file "'.$sBrowscapIniPath.'"');
}
$aBrowscapKeys = array_keys($aBrowscap);
$aBrowscap = array_combine($aBrowscapKeys, array_map(function($aUserAgentInfos, $sUserAgent){
$aUserAgentInfos = array_map(function($sValue){
if($sValue === 'true')return 1;
elseif($sValue === 'false')return '';
else return $sValue;
}, $aUserAgentInfos);
//Define browser name regex
$aUserAgentInfos['browser_name_regex'] = '^'.str_replace(
array('\\','.','?','*','^','$','[',']','|','(',')','+','{','}','%'),
array('\\\\','\\.','.','.*','\\^','\\$','\\[','\\]','\\|','\\(','\\)','\\+','\\{','\\}','\\%'),
$sUserAgent
).'$';
return array_change_key_case($aUserAgentInfos,CASE_LOWER);
},$aBrowscap,$aBrowscapKeys));
uksort($aBrowscap,function($sUserAgentA,$sUserAgentB){
if(($sUserAgentALength = strlen($sUserAgentA)) > ($sUserAgentBLength = strlen($sUserAgentB)))return -1;
elseif($sUserAgentALength < $sUserAgentBLength)return 1;
else return strcasecmp($sUserAgentA,$sUserAgentB);
});
return $this->setBrowscap($aBrowscap);
}
|
php
|
public function loadBrowscapIni(){
$sBrowscapIniPath = $this->getBrowscapIniPath();
//Local file
if(is_readable($sBrowscapIniPath)){
$aBrowscap = parse_ini_file($this->getBrowscapIniPath(), true, INI_SCANNER_RAW);
if($aBrowscap === false)throw new \RuntimeException('Error appends while parsing browscap.ini file "'.$sBrowscapIniPath.'"');
}
//Remote file
else{
if(($oFileHandle = @fopen($sBrowscapIniPath, 'r')) === false)throw new \InvalidArgumentException('Unable to load browscap.ini file "'.$sBrowscapIniPath.'"');
$sBrowscapIniContents = '';
while(($sContent = fgets($oFileHandle)) !== false) {
$sBrowscapIniContents .= $sContent.PHP_EOL;
}
if(!feof($oFileHandle))throw new \RuntimeException('Unable to retrieve contents from browscap.ini file "'.$sBrowscapIniPath.'"');
fclose($oFileHandle);
$aBrowscap = parse_ini_string($sBrowscapIniContents, true, INI_SCANNER_RAW);
if($aBrowscap === false)throw new \RuntimeException('Error appends while parsing browscap.ini file "'.$sBrowscapIniPath.'"');
}
$aBrowscapKeys = array_keys($aBrowscap);
$aBrowscap = array_combine($aBrowscapKeys, array_map(function($aUserAgentInfos, $sUserAgent){
$aUserAgentInfos = array_map(function($sValue){
if($sValue === 'true')return 1;
elseif($sValue === 'false')return '';
else return $sValue;
}, $aUserAgentInfos);
//Define browser name regex
$aUserAgentInfos['browser_name_regex'] = '^'.str_replace(
array('\\','.','?','*','^','$','[',']','|','(',')','+','{','}','%'),
array('\\\\','\\.','.','.*','\\^','\\$','\\[','\\]','\\|','\\(','\\)','\\+','\\{','\\}','\\%'),
$sUserAgent
).'$';
return array_change_key_case($aUserAgentInfos,CASE_LOWER);
},$aBrowscap,$aBrowscapKeys));
uksort($aBrowscap,function($sUserAgentA,$sUserAgentB){
if(($sUserAgentALength = strlen($sUserAgentA)) > ($sUserAgentBLength = strlen($sUserAgentB)))return -1;
elseif($sUserAgentALength < $sUserAgentBLength)return 1;
else return strcasecmp($sUserAgentA,$sUserAgentB);
});
return $this->setBrowscap($aBrowscap);
}
|
[
"public",
"function",
"loadBrowscapIni",
"(",
")",
"{",
"$",
"sBrowscapIniPath",
"=",
"$",
"this",
"->",
"getBrowscapIniPath",
"(",
")",
";",
"//Local file",
"if",
"(",
"is_readable",
"(",
"$",
"sBrowscapIniPath",
")",
")",
"{",
"$",
"aBrowscap",
"=",
"parse_ini_file",
"(",
"$",
"this",
"->",
"getBrowscapIniPath",
"(",
")",
",",
"true",
",",
"INI_SCANNER_RAW",
")",
";",
"if",
"(",
"$",
"aBrowscap",
"===",
"false",
")",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Error appends while parsing browscap.ini file \"'",
".",
"$",
"sBrowscapIniPath",
".",
"'\"'",
")",
";",
"}",
"//Remote file",
"else",
"{",
"if",
"(",
"(",
"$",
"oFileHandle",
"=",
"@",
"fopen",
"(",
"$",
"sBrowscapIniPath",
",",
"'r'",
")",
")",
"===",
"false",
")",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Unable to load browscap.ini file \"'",
".",
"$",
"sBrowscapIniPath",
".",
"'\"'",
")",
";",
"$",
"sBrowscapIniContents",
"=",
"''",
";",
"while",
"(",
"(",
"$",
"sContent",
"=",
"fgets",
"(",
"$",
"oFileHandle",
")",
")",
"!==",
"false",
")",
"{",
"$",
"sBrowscapIniContents",
".=",
"$",
"sContent",
".",
"PHP_EOL",
";",
"}",
"if",
"(",
"!",
"feof",
"(",
"$",
"oFileHandle",
")",
")",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Unable to retrieve contents from browscap.ini file \"'",
".",
"$",
"sBrowscapIniPath",
".",
"'\"'",
")",
";",
"fclose",
"(",
"$",
"oFileHandle",
")",
";",
"$",
"aBrowscap",
"=",
"parse_ini_string",
"(",
"$",
"sBrowscapIniContents",
",",
"true",
",",
"INI_SCANNER_RAW",
")",
";",
"if",
"(",
"$",
"aBrowscap",
"===",
"false",
")",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Error appends while parsing browscap.ini file \"'",
".",
"$",
"sBrowscapIniPath",
".",
"'\"'",
")",
";",
"}",
"$",
"aBrowscapKeys",
"=",
"array_keys",
"(",
"$",
"aBrowscap",
")",
";",
"$",
"aBrowscap",
"=",
"array_combine",
"(",
"$",
"aBrowscapKeys",
",",
"array_map",
"(",
"function",
"(",
"$",
"aUserAgentInfos",
",",
"$",
"sUserAgent",
")",
"{",
"$",
"aUserAgentInfos",
"=",
"array_map",
"(",
"function",
"(",
"$",
"sValue",
")",
"{",
"if",
"(",
"$",
"sValue",
"===",
"'true'",
")",
"return",
"1",
";",
"elseif",
"(",
"$",
"sValue",
"===",
"'false'",
")",
"return",
"''",
";",
"else",
"return",
"$",
"sValue",
";",
"}",
",",
"$",
"aUserAgentInfos",
")",
";",
"//Define browser name regex",
"$",
"aUserAgentInfos",
"[",
"'browser_name_regex'",
"]",
"=",
"'^'",
".",
"str_replace",
"(",
"array",
"(",
"'\\\\'",
",",
"'.'",
",",
"'?'",
",",
"'*'",
",",
"'^'",
",",
"'$'",
",",
"'['",
",",
"']'",
",",
"'|'",
",",
"'('",
",",
"')'",
",",
"'+'",
",",
"'{'",
",",
"'}'",
",",
"'%'",
")",
",",
"array",
"(",
"'\\\\\\\\'",
",",
"'\\\\.'",
",",
"'.'",
",",
"'.*'",
",",
"'\\\\^'",
",",
"'\\\\$'",
",",
"'\\\\['",
",",
"'\\\\]'",
",",
"'\\\\|'",
",",
"'\\\\('",
",",
"'\\\\)'",
",",
"'\\\\+'",
",",
"'\\\\{'",
",",
"'\\\\}'",
",",
"'\\\\%'",
")",
",",
"$",
"sUserAgent",
")",
".",
"'$'",
";",
"return",
"array_change_key_case",
"(",
"$",
"aUserAgentInfos",
",",
"CASE_LOWER",
")",
";",
"}",
",",
"$",
"aBrowscap",
",",
"$",
"aBrowscapKeys",
")",
")",
";",
"uksort",
"(",
"$",
"aBrowscap",
",",
"function",
"(",
"$",
"sUserAgentA",
",",
"$",
"sUserAgentB",
")",
"{",
"if",
"(",
"(",
"$",
"sUserAgentALength",
"=",
"strlen",
"(",
"$",
"sUserAgentA",
")",
")",
">",
"(",
"$",
"sUserAgentBLength",
"=",
"strlen",
"(",
"$",
"sUserAgentB",
")",
")",
")",
"return",
"-",
"1",
";",
"elseif",
"(",
"$",
"sUserAgentALength",
"<",
"$",
"sUserAgentBLength",
")",
"return",
"1",
";",
"else",
"return",
"strcasecmp",
"(",
"$",
"sUserAgentA",
",",
"$",
"sUserAgentB",
")",
";",
"}",
")",
";",
"return",
"$",
"this",
"->",
"setBrowscap",
"(",
"$",
"aBrowscap",
")",
";",
"}"
] |
Load and parse browscap.ini file
@throws \RuntimeException
@return \Neilime\Browscap\BrowscapService
|
[
"Load",
"and",
"parse",
"browscap",
".",
"ini",
"file"
] |
490a4d573a2f6340c67a4254d5a46d3276583e1b
|
https://github.com/neilime/zf2-browscap/blob/490a4d573a2f6340c67a4254d5a46d3276583e1b/src/Browscap/BrowscapService.php#L182-L228
|
20,170 |
left-right/center
|
src/controllers/FileController.php
|
FileController.image
|
public function image() {
if (Request::hasFile('image') && Request::has('table_name') && Request::has('field_name')) {
return json_encode(self::saveImage(
Request::input('table_name'),
Request::input('field_name'),
Request::file('image'),
null,
Request::file('image')->getClientOriginalExtension()
));
} elseif (!Request::hasFile('image')) {
return 'no image';
} elseif (!Request::hasFile('table_name')) {
return 'no table_name';
} elseif (!Request::hasFile('field_name')) {
return 'no field_name';
}
}
|
php
|
public function image() {
if (Request::hasFile('image') && Request::has('table_name') && Request::has('field_name')) {
return json_encode(self::saveImage(
Request::input('table_name'),
Request::input('field_name'),
Request::file('image'),
null,
Request::file('image')->getClientOriginalExtension()
));
} elseif (!Request::hasFile('image')) {
return 'no image';
} elseif (!Request::hasFile('table_name')) {
return 'no table_name';
} elseif (!Request::hasFile('field_name')) {
return 'no field_name';
}
}
|
[
"public",
"function",
"image",
"(",
")",
"{",
"if",
"(",
"Request",
"::",
"hasFile",
"(",
"'image'",
")",
"&&",
"Request",
"::",
"has",
"(",
"'table_name'",
")",
"&&",
"Request",
"::",
"has",
"(",
"'field_name'",
")",
")",
"{",
"return",
"json_encode",
"(",
"self",
"::",
"saveImage",
"(",
"Request",
"::",
"input",
"(",
"'table_name'",
")",
",",
"Request",
"::",
"input",
"(",
"'field_name'",
")",
",",
"Request",
"::",
"file",
"(",
"'image'",
")",
",",
"null",
",",
"Request",
"::",
"file",
"(",
"'image'",
")",
"->",
"getClientOriginalExtension",
"(",
")",
")",
")",
";",
"}",
"elseif",
"(",
"!",
"Request",
"::",
"hasFile",
"(",
"'image'",
")",
")",
"{",
"return",
"'no image'",
";",
"}",
"elseif",
"(",
"!",
"Request",
"::",
"hasFile",
"(",
"'table_name'",
")",
")",
"{",
"return",
"'no table_name'",
";",
"}",
"elseif",
"(",
"!",
"Request",
"::",
"hasFile",
"(",
"'field_name'",
")",
")",
"{",
"return",
"'no field_name'",
";",
"}",
"}"
] |
handle image upload route
|
[
"handle",
"image",
"upload",
"route"
] |
47c225538475ca3e87fa49f31a323b6e6bd4eff2
|
https://github.com/left-right/center/blob/47c225538475ca3e87fa49f31a323b6e6bd4eff2/src/controllers/FileController.php#L28-L44
|
20,171 |
ppetermann/king23
|
src/Http/Router.php
|
Router.addRoute
|
public function addRoute($route, $class, $action, $parameters = [], $hostparameters = [])
{
$this->log->debug('adding route : ' . $route . ' to class ' . $class . ' and action ' . $action);
$this->routes[$route] = [
"class" => $class,
"action" => $action,
"parameters" => $parameters,
"hostparameters" => $hostparameters
];
return $this;
}
|
php
|
public function addRoute($route, $class, $action, $parameters = [], $hostparameters = [])
{
$this->log->debug('adding route : ' . $route . ' to class ' . $class . ' and action ' . $action);
$this->routes[$route] = [
"class" => $class,
"action" => $action,
"parameters" => $parameters,
"hostparameters" => $hostparameters
];
return $this;
}
|
[
"public",
"function",
"addRoute",
"(",
"$",
"route",
",",
"$",
"class",
",",
"$",
"action",
",",
"$",
"parameters",
"=",
"[",
"]",
",",
"$",
"hostparameters",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"log",
"->",
"debug",
"(",
"'adding route : '",
".",
"$",
"route",
".",
"' to class '",
".",
"$",
"class",
".",
"' and action '",
".",
"$",
"action",
")",
";",
"$",
"this",
"->",
"routes",
"[",
"$",
"route",
"]",
"=",
"[",
"\"class\"",
"=>",
"$",
"class",
",",
"\"action\"",
"=>",
"$",
"action",
",",
"\"parameters\"",
"=>",
"$",
"parameters",
",",
"\"hostparameters\"",
"=>",
"$",
"hostparameters",
"]",
";",
"return",
"$",
"this",
";",
"}"
] |
add route to list of known routes
@param String $route beginning string of the route
@param String $class to be used for this route
@param String $action method to be called
@param string[] $parameters list of parameters that should be retrieved from url
@param array $hostparameters - allows to use subdomains as parameters
@return self
|
[
"add",
"route",
"to",
"list",
"of",
"known",
"routes"
] |
603896083ec89f5ac4d744abd3b1b4db3e914c95
|
https://github.com/ppetermann/king23/blob/603896083ec89f5ac4d744abd3b1b4db3e914c95/src/Http/Router.php#L87-L98
|
20,172 |
ppetermann/king23
|
src/Http/Router.php
|
Router.setBaseHost
|
public function setBaseHost($baseHost = null)
{
$this->log->debug('Setting Router baseHost to ' . $baseHost);
$this->baseHost = $baseHost;
return $this;
}
|
php
|
public function setBaseHost($baseHost = null)
{
$this->log->debug('Setting Router baseHost to ' . $baseHost);
$this->baseHost = $baseHost;
return $this;
}
|
[
"public",
"function",
"setBaseHost",
"(",
"$",
"baseHost",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"log",
"->",
"debug",
"(",
"'Setting Router baseHost to '",
".",
"$",
"baseHost",
")",
";",
"$",
"this",
"->",
"baseHost",
"=",
"$",
"baseHost",
";",
"return",
"$",
"this",
";",
"}"
] |
method to set the basicHost for hostparameters in routing
@see King23_Router::$basicHost
@param String $baseHost
@return self
|
[
"method",
"to",
"set",
"the",
"basicHost",
"for",
"hostparameters",
"in",
"routing"
] |
603896083ec89f5ac4d744abd3b1b4db3e914c95
|
https://github.com/ppetermann/king23/blob/603896083ec89f5ac4d744abd3b1b4db3e914c95/src/Http/Router.php#L107-L112
|
20,173 |
ppetermann/king23
|
src/Http/Router.php
|
Router.handleRoute
|
private function handleRoute($info, ServerRequestInterface $request, $route) : ResponseInterface
{
// initialize router attributes for the request
$attributes = [
'params' => [
'url' => [],
'host' => []
]
];
// prepare parameters
if ($paramstr = substr($request->getUri()->getPath(), strlen($route))) {
$attributes['params']['url'] = $this->filterParameters($info['parameters'], explode("/", $paramstr));
}
// check host parameters
if (count($info["hostparameters"]) > 0) {
$attributes['params']['host'] = $this->extractHostParameters($request, $info);
}
// put route parameters into king23.router.parameters attribute
$request = $request->withAttribute('king23.router', $attributes);
/** @var \King23\Controller\Controller $controller */
$controller = $this->container->get($info["class"]);
return $controller->dispatch($info["action"], $request);
}
|
php
|
private function handleRoute($info, ServerRequestInterface $request, $route) : ResponseInterface
{
// initialize router attributes for the request
$attributes = [
'params' => [
'url' => [],
'host' => []
]
];
// prepare parameters
if ($paramstr = substr($request->getUri()->getPath(), strlen($route))) {
$attributes['params']['url'] = $this->filterParameters($info['parameters'], explode("/", $paramstr));
}
// check host parameters
if (count($info["hostparameters"]) > 0) {
$attributes['params']['host'] = $this->extractHostParameters($request, $info);
}
// put route parameters into king23.router.parameters attribute
$request = $request->withAttribute('king23.router', $attributes);
/** @var \King23\Controller\Controller $controller */
$controller = $this->container->get($info["class"]);
return $controller->dispatch($info["action"], $request);
}
|
[
"private",
"function",
"handleRoute",
"(",
"$",
"info",
",",
"ServerRequestInterface",
"$",
"request",
",",
"$",
"route",
")",
":",
"ResponseInterface",
"{",
"// initialize router attributes for the request",
"$",
"attributes",
"=",
"[",
"'params'",
"=>",
"[",
"'url'",
"=>",
"[",
"]",
",",
"'host'",
"=>",
"[",
"]",
"]",
"]",
";",
"// prepare parameters",
"if",
"(",
"$",
"paramstr",
"=",
"substr",
"(",
"$",
"request",
"->",
"getUri",
"(",
")",
"->",
"getPath",
"(",
")",
",",
"strlen",
"(",
"$",
"route",
")",
")",
")",
"{",
"$",
"attributes",
"[",
"'params'",
"]",
"[",
"'url'",
"]",
"=",
"$",
"this",
"->",
"filterParameters",
"(",
"$",
"info",
"[",
"'parameters'",
"]",
",",
"explode",
"(",
"\"/\"",
",",
"$",
"paramstr",
")",
")",
";",
"}",
"// check host parameters",
"if",
"(",
"count",
"(",
"$",
"info",
"[",
"\"hostparameters\"",
"]",
")",
">",
"0",
")",
"{",
"$",
"attributes",
"[",
"'params'",
"]",
"[",
"'host'",
"]",
"=",
"$",
"this",
"->",
"extractHostParameters",
"(",
"$",
"request",
",",
"$",
"info",
")",
";",
"}",
"// put route parameters into king23.router.parameters attribute",
"$",
"request",
"=",
"$",
"request",
"->",
"withAttribute",
"(",
"'king23.router'",
",",
"$",
"attributes",
")",
";",
"/** @var \\King23\\Controller\\Controller $controller */",
"$",
"controller",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"$",
"info",
"[",
"\"class\"",
"]",
")",
";",
"return",
"$",
"controller",
"->",
"dispatch",
"(",
"$",
"info",
"[",
"\"action\"",
"]",
",",
"$",
"request",
")",
";",
"}"
] |
Handle a regular route
@param array $info
@param ServerRequestInterface $request
@param string $route
@return ResponseInterface
@throws \King23\Controller\Exceptions\ActionDoesNotExistException
|
[
"Handle",
"a",
"regular",
"route"
] |
603896083ec89f5ac4d744abd3b1b4db3e914c95
|
https://github.com/ppetermann/king23/blob/603896083ec89f5ac4d744abd3b1b4db3e914c95/src/Http/Router.php#L149-L176
|
20,174 |
ppetermann/king23
|
src/Http/Router.php
|
Router.extractHostParameters
|
private function extractHostParameters($request, $info)
{
$hostname = $this->cleanHostName($request);
if (empty($hostname)) {
$params = [];
} else {
$params = array_reverse(explode(".", $hostname));
}
$parameters = $this->filterParameters($info['hostparameters'], $params);
return $parameters;
}
|
php
|
private function extractHostParameters($request, $info)
{
$hostname = $this->cleanHostName($request);
if (empty($hostname)) {
$params = [];
} else {
$params = array_reverse(explode(".", $hostname));
}
$parameters = $this->filterParameters($info['hostparameters'], $params);
return $parameters;
}
|
[
"private",
"function",
"extractHostParameters",
"(",
"$",
"request",
",",
"$",
"info",
")",
"{",
"$",
"hostname",
"=",
"$",
"this",
"->",
"cleanHostName",
"(",
"$",
"request",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"hostname",
")",
")",
"{",
"$",
"params",
"=",
"[",
"]",
";",
"}",
"else",
"{",
"$",
"params",
"=",
"array_reverse",
"(",
"explode",
"(",
"\".\"",
",",
"$",
"hostname",
")",
")",
";",
"}",
"$",
"parameters",
"=",
"$",
"this",
"->",
"filterParameters",
"(",
"$",
"info",
"[",
"'hostparameters'",
"]",
",",
"$",
"params",
")",
";",
"return",
"$",
"parameters",
";",
"}"
] |
extract parameters from hostname
@param ServerRequestInterface $request
@param array $info
@return array
|
[
"extract",
"parameters",
"from",
"hostname"
] |
603896083ec89f5ac4d744abd3b1b4db3e914c95
|
https://github.com/ppetermann/king23/blob/603896083ec89f5ac4d744abd3b1b4db3e914c95/src/Http/Router.php#L203-L215
|
20,175 |
ppetermann/king23
|
src/Http/Router.php
|
Router.cleanHostName
|
private function cleanHostName(ServerRequestInterface $request)
{
if (is_null($this->baseHost)) {
$hostname = $request->getUri()->getHost();
} else {
$hostname = str_replace($this->baseHost, "", $request->getUri()->getHost());
}
if (substr($hostname, -1) == ".") {
$hostname = substr($hostname, 0, -1);
}
return $hostname;
}
|
php
|
private function cleanHostName(ServerRequestInterface $request)
{
if (is_null($this->baseHost)) {
$hostname = $request->getUri()->getHost();
} else {
$hostname = str_replace($this->baseHost, "", $request->getUri()->getHost());
}
if (substr($hostname, -1) == ".") {
$hostname = substr($hostname, 0, -1);
}
return $hostname;
}
|
[
"private",
"function",
"cleanHostName",
"(",
"ServerRequestInterface",
"$",
"request",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"baseHost",
")",
")",
"{",
"$",
"hostname",
"=",
"$",
"request",
"->",
"getUri",
"(",
")",
"->",
"getHost",
"(",
")",
";",
"}",
"else",
"{",
"$",
"hostname",
"=",
"str_replace",
"(",
"$",
"this",
"->",
"baseHost",
",",
"\"\"",
",",
"$",
"request",
"->",
"getUri",
"(",
")",
"->",
"getHost",
"(",
")",
")",
";",
"}",
"if",
"(",
"substr",
"(",
"$",
"hostname",
",",
"-",
"1",
")",
"==",
"\".\"",
")",
"{",
"$",
"hostname",
"=",
"substr",
"(",
"$",
"hostname",
",",
"0",
",",
"-",
"1",
")",
";",
"}",
"return",
"$",
"hostname",
";",
"}"
] |
will get hostname, and clean basehost off it
@param ServerRequestInterface $request
@return string
|
[
"will",
"get",
"hostname",
"and",
"clean",
"basehost",
"off",
"it"
] |
603896083ec89f5ac4d744abd3b1b4db3e914c95
|
https://github.com/ppetermann/king23/blob/603896083ec89f5ac4d744abd3b1b4db3e914c95/src/Http/Router.php#L223-L237
|
20,176 |
kharanenka/laravel-cache-helper
|
src/Kharanenka/Helper/CCache.php
|
CCache.put
|
public static function put($arTags, $sKeys, &$arValue, $iMinute)
{
$obDate = Carbon::now()->addMinute($iMinute);
$sCacheDriver = config('cache.default');
if(!empty($arTags)) {
if($sCacheDriver == 'redis') {
Cache::tags($arTags)->put($sKeys, $arValue, $obDate);
return;
} else {
$sKeys = implode('_', $arTags).'_'.$sKeys;
}
}
Cache::put($sKeys, $arValue, $obDate);
}
|
php
|
public static function put($arTags, $sKeys, &$arValue, $iMinute)
{
$obDate = Carbon::now()->addMinute($iMinute);
$sCacheDriver = config('cache.default');
if(!empty($arTags)) {
if($sCacheDriver == 'redis') {
Cache::tags($arTags)->put($sKeys, $arValue, $obDate);
return;
} else {
$sKeys = implode('_', $arTags).'_'.$sKeys;
}
}
Cache::put($sKeys, $arValue, $obDate);
}
|
[
"public",
"static",
"function",
"put",
"(",
"$",
"arTags",
",",
"$",
"sKeys",
",",
"&",
"$",
"arValue",
",",
"$",
"iMinute",
")",
"{",
"$",
"obDate",
"=",
"Carbon",
"::",
"now",
"(",
")",
"->",
"addMinute",
"(",
"$",
"iMinute",
")",
";",
"$",
"sCacheDriver",
"=",
"config",
"(",
"'cache.default'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"arTags",
")",
")",
"{",
"if",
"(",
"$",
"sCacheDriver",
"==",
"'redis'",
")",
"{",
"Cache",
"::",
"tags",
"(",
"$",
"arTags",
")",
"->",
"put",
"(",
"$",
"sKeys",
",",
"$",
"arValue",
",",
"$",
"obDate",
")",
";",
"return",
";",
"}",
"else",
"{",
"$",
"sKeys",
"=",
"implode",
"(",
"'_'",
",",
"$",
"arTags",
")",
".",
"'_'",
".",
"$",
"sKeys",
";",
"}",
"}",
"Cache",
"::",
"put",
"(",
"$",
"sKeys",
",",
"$",
"arValue",
",",
"$",
"obDate",
")",
";",
"}"
] |
Put cache data
@param array $arTags
@param string $sKeys
@param mixed $arValue
@param int $iMinute
|
[
"Put",
"cache",
"data"
] |
5423eed6830ade6f7af8b02eb6ad33a97db7b848
|
https://github.com/kharanenka/laravel-cache-helper/blob/5423eed6830ade6f7af8b02eb6ad33a97db7b848/src/Kharanenka/Helper/CCache.php#L62-L77
|
20,177 |
kharanenka/laravel-cache-helper
|
src/Kharanenka/Helper/CCache.php
|
CCache.forever
|
public static function forever($arTags, $sKeys, &$arValue)
{
$sCacheDriver = config('cache.default');
if(!empty($arTags)) {
if($sCacheDriver == 'redis') {
Cache::tags($arTags)->forever($sKeys, $arValue);
return;
} else {
$sKeys = implode('_', $arTags).'_'.$sKeys;
}
}
Cache::forever($sKeys, $arValue);
}
|
php
|
public static function forever($arTags, $sKeys, &$arValue)
{
$sCacheDriver = config('cache.default');
if(!empty($arTags)) {
if($sCacheDriver == 'redis') {
Cache::tags($arTags)->forever($sKeys, $arValue);
return;
} else {
$sKeys = implode('_', $arTags).'_'.$sKeys;
}
}
Cache::forever($sKeys, $arValue);
}
|
[
"public",
"static",
"function",
"forever",
"(",
"$",
"arTags",
",",
"$",
"sKeys",
",",
"&",
"$",
"arValue",
")",
"{",
"$",
"sCacheDriver",
"=",
"config",
"(",
"'cache.default'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"arTags",
")",
")",
"{",
"if",
"(",
"$",
"sCacheDriver",
"==",
"'redis'",
")",
"{",
"Cache",
"::",
"tags",
"(",
"$",
"arTags",
")",
"->",
"forever",
"(",
"$",
"sKeys",
",",
"$",
"arValue",
")",
";",
"return",
";",
"}",
"else",
"{",
"$",
"sKeys",
"=",
"implode",
"(",
"'_'",
",",
"$",
"arTags",
")",
".",
"'_'",
".",
"$",
"sKeys",
";",
"}",
"}",
"Cache",
"::",
"forever",
"(",
"$",
"sKeys",
",",
"$",
"arValue",
")",
";",
"}"
] |
Forever cache data
@param array $arTags
@param string $sKeys
@param mixed $arValue
|
[
"Forever",
"cache",
"data"
] |
5423eed6830ade6f7af8b02eb6ad33a97db7b848
|
https://github.com/kharanenka/laravel-cache-helper/blob/5423eed6830ade6f7af8b02eb6ad33a97db7b848/src/Kharanenka/Helper/CCache.php#L85-L98
|
20,178 |
kharanenka/laravel-cache-helper
|
src/Kharanenka/Helper/CCache.php
|
CCache.clear
|
public static function clear($arTags, $sKeys = null)
{
$sCacheDriver = config('cache.default');
if(!empty($arTags)) {
if($sCacheDriver == 'redis') {
if(!empty($sKeys)) {
Cache::tags($arTags)->forget($sKeys);
} else {
Cache::tags($arTags)->flush();
}
} else {
$sKeys = implode('_', $arTags).'_'.$sKeys;
Cache::forget($sKeys);
}
}
}
|
php
|
public static function clear($arTags, $sKeys = null)
{
$sCacheDriver = config('cache.default');
if(!empty($arTags)) {
if($sCacheDriver == 'redis') {
if(!empty($sKeys)) {
Cache::tags($arTags)->forget($sKeys);
} else {
Cache::tags($arTags)->flush();
}
} else {
$sKeys = implode('_', $arTags).'_'.$sKeys;
Cache::forget($sKeys);
}
}
}
|
[
"public",
"static",
"function",
"clear",
"(",
"$",
"arTags",
",",
"$",
"sKeys",
"=",
"null",
")",
"{",
"$",
"sCacheDriver",
"=",
"config",
"(",
"'cache.default'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"arTags",
")",
")",
"{",
"if",
"(",
"$",
"sCacheDriver",
"==",
"'redis'",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"sKeys",
")",
")",
"{",
"Cache",
"::",
"tags",
"(",
"$",
"arTags",
")",
"->",
"forget",
"(",
"$",
"sKeys",
")",
";",
"}",
"else",
"{",
"Cache",
"::",
"tags",
"(",
"$",
"arTags",
")",
"->",
"flush",
"(",
")",
";",
"}",
"}",
"else",
"{",
"$",
"sKeys",
"=",
"implode",
"(",
"'_'",
",",
"$",
"arTags",
")",
".",
"'_'",
".",
"$",
"sKeys",
";",
"Cache",
"::",
"forget",
"(",
"$",
"sKeys",
")",
";",
"}",
"}",
"}"
] |
Clear cache data
@param array $arTags
@param string $sKeys
|
[
"Clear",
"cache",
"data"
] |
5423eed6830ade6f7af8b02eb6ad33a97db7b848
|
https://github.com/kharanenka/laravel-cache-helper/blob/5423eed6830ade6f7af8b02eb6ad33a97db7b848/src/Kharanenka/Helper/CCache.php#L105-L120
|
20,179 |
infinity-next/braintree
|
src/Billable.php
|
Billable.onTrial
|
public function onTrial()
{
if (! is_null($this->getTrialEndDate())) {
return Carbon::today()->lt($this->getTrialEndDate());
} else {
return false;
}
}
|
php
|
public function onTrial()
{
if (! is_null($this->getTrialEndDate())) {
return Carbon::today()->lt($this->getTrialEndDate());
} else {
return false;
}
}
|
[
"public",
"function",
"onTrial",
"(",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"getTrialEndDate",
"(",
")",
")",
")",
"{",
"return",
"Carbon",
"::",
"today",
"(",
")",
"->",
"lt",
"(",
"$",
"this",
"->",
"getTrialEndDate",
"(",
")",
")",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] |
Determine if the entity is within their trial period.
@return bool
|
[
"Determine",
"if",
"the",
"entity",
"is",
"within",
"their",
"trial",
"period",
"."
] |
4bf6f49d4d8a05734a295003137f360e331cc10f
|
https://github.com/infinity-next/braintree/blob/4bf6f49d4d8a05734a295003137f360e331cc10f/src/Billable.php#L196-L203
|
20,180 |
infinity-next/braintree
|
src/Billable.php
|
Billable.onGracePeriod
|
public function onGracePeriod()
{
if (! is_null($endsAt = $this->getSubscriptionEndDate())) {
return Carbon::now()->lt(Carbon::instance($endsAt));
} else {
return false;
}
}
|
php
|
public function onGracePeriod()
{
if (! is_null($endsAt = $this->getSubscriptionEndDate())) {
return Carbon::now()->lt(Carbon::instance($endsAt));
} else {
return false;
}
}
|
[
"public",
"function",
"onGracePeriod",
"(",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"endsAt",
"=",
"$",
"this",
"->",
"getSubscriptionEndDate",
"(",
")",
")",
")",
"{",
"return",
"Carbon",
"::",
"now",
"(",
")",
"->",
"lt",
"(",
"Carbon",
"::",
"instance",
"(",
"$",
"endsAt",
")",
")",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] |
Determine if the entity is on grace period after cancellation.
@return bool
|
[
"Determine",
"if",
"the",
"entity",
"is",
"on",
"grace",
"period",
"after",
"cancellation",
"."
] |
4bf6f49d4d8a05734a295003137f360e331cc10f
|
https://github.com/infinity-next/braintree/blob/4bf6f49d4d8a05734a295003137f360e331cc10f/src/Billable.php#L210-L217
|
20,181 |
infinity-next/braintree
|
src/Billable.php
|
Billable.subscribed
|
public function subscribed()
{
if ($this->requiresCardUpFront()) {
return $this->braintreeIsActive() || $this->onGracePeriod();
}
else {
return $this->braintreeIsActive() || $this->onTrial() || $this->onGracePeriod();
}
}
|
php
|
public function subscribed()
{
if ($this->requiresCardUpFront()) {
return $this->braintreeIsActive() || $this->onGracePeriod();
}
else {
return $this->braintreeIsActive() || $this->onTrial() || $this->onGracePeriod();
}
}
|
[
"public",
"function",
"subscribed",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"requiresCardUpFront",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"braintreeIsActive",
"(",
")",
"||",
"$",
"this",
"->",
"onGracePeriod",
"(",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"braintreeIsActive",
"(",
")",
"||",
"$",
"this",
"->",
"onTrial",
"(",
")",
"||",
"$",
"this",
"->",
"onGracePeriod",
"(",
")",
";",
"}",
"}"
] |
Determine if the entity has an active subscription.
@return bool
|
[
"Determine",
"if",
"the",
"entity",
"has",
"an",
"active",
"subscription",
"."
] |
4bf6f49d4d8a05734a295003137f360e331cc10f
|
https://github.com/infinity-next/braintree/blob/4bf6f49d4d8a05734a295003137f360e331cc10f/src/Billable.php#L224-L232
|
20,182 |
tbreuss/pvc
|
src/Middleware/MiddlewareStack.php
|
MiddlewareStack.push
|
public function push(MiddlewareInterface $middleware): self
{
$stack = clone $this;
array_unshift($stack->middlewares, $middleware);
return $stack;
}
|
php
|
public function push(MiddlewareInterface $middleware): self
{
$stack = clone $this;
array_unshift($stack->middlewares, $middleware);
return $stack;
}
|
[
"public",
"function",
"push",
"(",
"MiddlewareInterface",
"$",
"middleware",
")",
":",
"self",
"{",
"$",
"stack",
"=",
"clone",
"$",
"this",
";",
"array_unshift",
"(",
"$",
"stack",
"->",
"middlewares",
",",
"$",
"middleware",
")",
";",
"return",
"$",
"stack",
";",
"}"
] |
Creates a new stack with the given middleware pushed.
@param MiddlewareInterface $middleware
@return self
|
[
"Creates",
"a",
"new",
"stack",
"with",
"the",
"given",
"middleware",
"pushed",
"."
] |
ae100351010a8c9f645ccb918f70a26e167de7a7
|
https://github.com/tbreuss/pvc/blob/ae100351010a8c9f645ccb918f70a26e167de7a7/src/Middleware/MiddlewareStack.php#L65-L70
|
20,183 |
HedronDev/hedron
|
src/Parser/BaseParser.php
|
BaseParser.getDataDirectoryPath
|
protected function getDataDirectoryPath() {
$data_dir = $this->getEnvironment()->getDataDirectory();
$config = $this->getConfiguration();
return str_replace('{branch}', $config->getBranch(), $data_dir);
}
|
php
|
protected function getDataDirectoryPath() {
$data_dir = $this->getEnvironment()->getDataDirectory();
$config = $this->getConfiguration();
return str_replace('{branch}', $config->getBranch(), $data_dir);
}
|
[
"protected",
"function",
"getDataDirectoryPath",
"(",
")",
"{",
"$",
"data_dir",
"=",
"$",
"this",
"->",
"getEnvironment",
"(",
")",
"->",
"getDataDirectory",
"(",
")",
";",
"$",
"config",
"=",
"$",
"this",
"->",
"getConfiguration",
"(",
")",
";",
"return",
"str_replace",
"(",
"'{branch}'",
",",
"$",
"config",
"->",
"getBranch",
"(",
")",
",",
"$",
"data_dir",
")",
";",
"}"
] |
The absolute path of the client site data directory.
@return string
The absolute path of the client site data directory.
|
[
"The",
"absolute",
"path",
"of",
"the",
"client",
"site",
"data",
"directory",
"."
] |
3b4adec4912f2d7c0b7e7262dc36515fbc2e8e00
|
https://github.com/HedronDev/hedron/blob/3b4adec4912f2d7c0b7e7262dc36515fbc2e8e00/src/Parser/BaseParser.php#L119-L123
|
20,184 |
giftcards/Encryption
|
Cipher/MysqlAes.php
|
MysqlAes.mysqlAesKey
|
protected function mysqlAesKey($key)
{
$newKey = str_repeat(chr(0), 16);
for ($i = 0, $len = strlen($key); $i < $len; $i++) {
$newKey[$i % 16] = $newKey[$i % 16] ^ $key[$i];
}
return $newKey;
}
|
php
|
protected function mysqlAesKey($key)
{
$newKey = str_repeat(chr(0), 16);
for ($i = 0, $len = strlen($key); $i < $len; $i++) {
$newKey[$i % 16] = $newKey[$i % 16] ^ $key[$i];
}
return $newKey;
}
|
[
"protected",
"function",
"mysqlAesKey",
"(",
"$",
"key",
")",
"{",
"$",
"newKey",
"=",
"str_repeat",
"(",
"chr",
"(",
"0",
")",
",",
"16",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
",",
"$",
"len",
"=",
"strlen",
"(",
"$",
"key",
")",
";",
"$",
"i",
"<",
"$",
"len",
";",
"$",
"i",
"++",
")",
"{",
"$",
"newKey",
"[",
"$",
"i",
"%",
"16",
"]",
"=",
"$",
"newKey",
"[",
"$",
"i",
"%",
"16",
"]",
"^",
"$",
"key",
"[",
"$",
"i",
"]",
";",
"}",
"return",
"$",
"newKey",
";",
"}"
] |
Converts the key into the MySQL equivalent version
@param $key
@return string
|
[
"Converts",
"the",
"key",
"into",
"the",
"MySQL",
"equivalent",
"version"
] |
a48f92408538e2ffe1c8603f168d57803aad7100
|
https://github.com/giftcards/Encryption/blob/a48f92408538e2ffe1c8603f168d57803aad7100/Cipher/MysqlAes.php#L61-L70
|
20,185 |
Smile-SA/EzUICronBundle
|
DependencyInjection/SmileEzUICronExtension.php
|
SmileEzUICronExtension.prependYui
|
private function prependYui(ContainerBuilder $container)
{
$container->setParameter(
'smile_ez_uicron.public_dir',
'bundles/smileezuicron'
);
$yuiConfigFile = __DIR__ . '/../Resources/config/yui.yml';
$config = Yaml::parse(file_get_contents($yuiConfigFile));
$container->prependExtensionConfig('ez_platformui', $config);
$container->addResource(new FileResource($yuiConfigFile));
}
|
php
|
private function prependYui(ContainerBuilder $container)
{
$container->setParameter(
'smile_ez_uicron.public_dir',
'bundles/smileezuicron'
);
$yuiConfigFile = __DIR__ . '/../Resources/config/yui.yml';
$config = Yaml::parse(file_get_contents($yuiConfigFile));
$container->prependExtensionConfig('ez_platformui', $config);
$container->addResource(new FileResource($yuiConfigFile));
}
|
[
"private",
"function",
"prependYui",
"(",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"container",
"->",
"setParameter",
"(",
"'smile_ez_uicron.public_dir'",
",",
"'bundles/smileezuicron'",
")",
";",
"$",
"yuiConfigFile",
"=",
"__DIR__",
".",
"'/../Resources/config/yui.yml'",
";",
"$",
"config",
"=",
"Yaml",
"::",
"parse",
"(",
"file_get_contents",
"(",
"$",
"yuiConfigFile",
")",
")",
";",
"$",
"container",
"->",
"prependExtensionConfig",
"(",
"'ez_platformui'",
",",
"$",
"config",
")",
";",
"$",
"container",
"->",
"addResource",
"(",
"new",
"FileResource",
"(",
"$",
"yuiConfigFile",
")",
")",
";",
"}"
] |
Prepend ezplatform yui interface plugin
@param ContainerBuilder $container
|
[
"Prepend",
"ezplatform",
"yui",
"interface",
"plugin"
] |
c62fc6a3ab0b39e3f911742d9affe4aade90cf66
|
https://github.com/Smile-SA/EzUICronBundle/blob/c62fc6a3ab0b39e3f911742d9affe4aade90cf66/DependencyInjection/SmileEzUICronExtension.php#L48-L58
|
20,186 |
Smile-SA/EzUICronBundle
|
DependencyInjection/SmileEzUICronExtension.php
|
SmileEzUICronExtension.prependCss
|
private function prependCss(ContainerBuilder $container)
{
$container->setParameter(
'smile_ez_uicron.css_dir',
'bundles/smileezuicron/css'
);
$cssConfigFile = __DIR__ . '/../Resources/config/css.yml';
$config = Yaml::parse(file_get_contents($cssConfigFile));
$container->prependExtensionConfig('ez_platformui', $config);
$container->addResource(new FileResource($cssConfigFile));
}
|
php
|
private function prependCss(ContainerBuilder $container)
{
$container->setParameter(
'smile_ez_uicron.css_dir',
'bundles/smileezuicron/css'
);
$cssConfigFile = __DIR__ . '/../Resources/config/css.yml';
$config = Yaml::parse(file_get_contents($cssConfigFile));
$container->prependExtensionConfig('ez_platformui', $config);
$container->addResource(new FileResource($cssConfigFile));
}
|
[
"private",
"function",
"prependCss",
"(",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"container",
"->",
"setParameter",
"(",
"'smile_ez_uicron.css_dir'",
",",
"'bundles/smileezuicron/css'",
")",
";",
"$",
"cssConfigFile",
"=",
"__DIR__",
".",
"'/../Resources/config/css.yml'",
";",
"$",
"config",
"=",
"Yaml",
"::",
"parse",
"(",
"file_get_contents",
"(",
"$",
"cssConfigFile",
")",
")",
";",
"$",
"container",
"->",
"prependExtensionConfig",
"(",
"'ez_platformui'",
",",
"$",
"config",
")",
";",
"$",
"container",
"->",
"addResource",
"(",
"new",
"FileResource",
"(",
"$",
"cssConfigFile",
")",
")",
";",
"}"
] |
Prepend ezplatform css interface plugin
@param ContainerBuilder $container
|
[
"Prepend",
"ezplatform",
"css",
"interface",
"plugin"
] |
c62fc6a3ab0b39e3f911742d9affe4aade90cf66
|
https://github.com/Smile-SA/EzUICronBundle/blob/c62fc6a3ab0b39e3f911742d9affe4aade90cf66/DependencyInjection/SmileEzUICronExtension.php#L65-L75
|
20,187 |
Eresus/EresusCMS
|
src/core/framework/core/3rdparty/ezcomponents/Mail/src/parts/text.php
|
ezcMailText.generateHeaders
|
public function generateHeaders()
{
$this->setHeader( "Content-Type", "text/" . $this->subType . "; charset=" . $this->charset );
$this->setHeader( "Content-Transfer-Encoding", $this->encoding );
return parent::generateHeaders();
}
|
php
|
public function generateHeaders()
{
$this->setHeader( "Content-Type", "text/" . $this->subType . "; charset=" . $this->charset );
$this->setHeader( "Content-Transfer-Encoding", $this->encoding );
return parent::generateHeaders();
}
|
[
"public",
"function",
"generateHeaders",
"(",
")",
"{",
"$",
"this",
"->",
"setHeader",
"(",
"\"Content-Type\"",
",",
"\"text/\"",
".",
"$",
"this",
"->",
"subType",
".",
"\"; charset=\"",
".",
"$",
"this",
"->",
"charset",
")",
";",
"$",
"this",
"->",
"setHeader",
"(",
"\"Content-Transfer-Encoding\"",
",",
"$",
"this",
"->",
"encoding",
")",
";",
"return",
"parent",
"::",
"generateHeaders",
"(",
")",
";",
"}"
] |
Returns the headers set for this part as a RFC822 compliant string.
This method does not add the required two lines of space
to separate the headers from the body of the part.
@see setHeader()
@return string
|
[
"Returns",
"the",
"headers",
"set",
"for",
"this",
"part",
"as",
"a",
"RFC822",
"compliant",
"string",
"."
] |
b0afc661105f0a2f65d49abac13956cc93c5188d
|
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/parts/text.php#L155-L160
|
20,188 |
heidelpay/PhpDoc
|
src/phpDocumentor/Plugin/Scrybe/Command/Manual/BaseConvertCommand.php
|
BaseConvertCommand.buildCollection
|
protected function buildCollection(array $sources, array $extensions)
{
$collection = new Collection();
$collection->setAllowedExtensions($extensions);
foreach ($sources as $path) {
if (is_dir($path)) {
$collection->addDirectory($path);
continue;
}
$collection->addFile($path);
}
return $collection;
}
|
php
|
protected function buildCollection(array $sources, array $extensions)
{
$collection = new Collection();
$collection->setAllowedExtensions($extensions);
foreach ($sources as $path) {
if (is_dir($path)) {
$collection->addDirectory($path);
continue;
}
$collection->addFile($path);
}
return $collection;
}
|
[
"protected",
"function",
"buildCollection",
"(",
"array",
"$",
"sources",
",",
"array",
"$",
"extensions",
")",
"{",
"$",
"collection",
"=",
"new",
"Collection",
"(",
")",
";",
"$",
"collection",
"->",
"setAllowedExtensions",
"(",
"$",
"extensions",
")",
";",
"foreach",
"(",
"$",
"sources",
"as",
"$",
"path",
")",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"$",
"collection",
"->",
"addDirectory",
"(",
"$",
"path",
")",
";",
"continue",
";",
"}",
"$",
"collection",
"->",
"addFile",
"(",
"$",
"path",
")",
";",
"}",
"return",
"$",
"collection",
";",
"}"
] |
Constructs a Fileset collection and returns that.
@param array $sources List of source paths.
@param array $extensions List of extensions to scan for in directories.
@return Collection
|
[
"Constructs",
"a",
"Fileset",
"collection",
"and",
"returns",
"that",
"."
] |
5ac9e842cbd4cbb70900533b240c131f3515ee02
|
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Plugin/Scrybe/Command/Manual/BaseConvertCommand.php#L195-L209
|
20,189 |
gregoryv/php-logger
|
src/CachedWriter.php
|
CachedWriter.swrite
|
public function swrite($severity, $value='')
{
if(sizeof($this->cache) == $this->messageLimit) {
array_shift($this->cache);
}
$this->cache[] = $value;
}
|
php
|
public function swrite($severity, $value='')
{
if(sizeof($this->cache) == $this->messageLimit) {
array_shift($this->cache);
}
$this->cache[] = $value;
}
|
[
"public",
"function",
"swrite",
"(",
"$",
"severity",
",",
"$",
"value",
"=",
"''",
")",
"{",
"if",
"(",
"sizeof",
"(",
"$",
"this",
"->",
"cache",
")",
"==",
"$",
"this",
"->",
"messageLimit",
")",
"{",
"array_shift",
"(",
"$",
"this",
"->",
"cache",
")",
";",
"}",
"$",
"this",
"->",
"cache",
"[",
"]",
"=",
"$",
"value",
";",
"}"
] |
Stores messages in the public cache by priority
|
[
"Stores",
"messages",
"in",
"the",
"public",
"cache",
"by",
"priority"
] |
0f8ffc360a0233531a9775359929af8876997862
|
https://github.com/gregoryv/php-logger/blob/0f8ffc360a0233531a9775359929af8876997862/src/CachedWriter.php#L29-L35
|
20,190 |
DevGroup-ru/yii2-users-module
|
src/controllers/RbacManageController.php
|
RbacManageController.actionRemoveItems
|
public function actionRemoveItems()
{
if (false === Yii::$app->request->isAjax) {
throw new NotFoundHttpException(Yii::t('users', 'Page not found'));
}
$type = Yii::$app->request->post('item-type', 0);
self::checkPermissions($type);
$items = Yii::$app->request->post('items', []);
$authManager = Yii::$app->getAuthManager();
$removed = 0;
foreach ($items as $item) {
try {
$authManager->remove(new Item(['name' => $item]));
$removed++;
} catch (\Exception $e) {
Yii::$app->session->setFlash(
'warning',
Yii::t('users', "Unknown RBAC item name '{name}'", ['name' => $item])
);
}
}
if (0 !== $removed) {
Yii::$app->session->setFlash(
'info',
Yii::t('users', "Items removed: {count}", ['count' => $removed])
);
}
}
|
php
|
public function actionRemoveItems()
{
if (false === Yii::$app->request->isAjax) {
throw new NotFoundHttpException(Yii::t('users', 'Page not found'));
}
$type = Yii::$app->request->post('item-type', 0);
self::checkPermissions($type);
$items = Yii::$app->request->post('items', []);
$authManager = Yii::$app->getAuthManager();
$removed = 0;
foreach ($items as $item) {
try {
$authManager->remove(new Item(['name' => $item]));
$removed++;
} catch (\Exception $e) {
Yii::$app->session->setFlash(
'warning',
Yii::t('users', "Unknown RBAC item name '{name}'", ['name' => $item])
);
}
}
if (0 !== $removed) {
Yii::$app->session->setFlash(
'info',
Yii::t('users', "Items removed: {count}", ['count' => $removed])
);
}
}
|
[
"public",
"function",
"actionRemoveItems",
"(",
")",
"{",
"if",
"(",
"false",
"===",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"isAjax",
")",
"{",
"throw",
"new",
"NotFoundHttpException",
"(",
"Yii",
"::",
"t",
"(",
"'users'",
",",
"'Page not found'",
")",
")",
";",
"}",
"$",
"type",
"=",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"post",
"(",
"'item-type'",
",",
"0",
")",
";",
"self",
"::",
"checkPermissions",
"(",
"$",
"type",
")",
";",
"$",
"items",
"=",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"post",
"(",
"'items'",
",",
"[",
"]",
")",
";",
"$",
"authManager",
"=",
"Yii",
"::",
"$",
"app",
"->",
"getAuthManager",
"(",
")",
";",
"$",
"removed",
"=",
"0",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"try",
"{",
"$",
"authManager",
"->",
"remove",
"(",
"new",
"Item",
"(",
"[",
"'name'",
"=>",
"$",
"item",
"]",
")",
")",
";",
"$",
"removed",
"++",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"session",
"->",
"setFlash",
"(",
"'warning'",
",",
"Yii",
"::",
"t",
"(",
"'users'",
",",
"\"Unknown RBAC item name '{name}'\"",
",",
"[",
"'name'",
"=>",
"$",
"item",
"]",
")",
")",
";",
"}",
"}",
"if",
"(",
"0",
"!==",
"$",
"removed",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"session",
"->",
"setFlash",
"(",
"'info'",
",",
"Yii",
"::",
"t",
"(",
"'users'",
",",
"\"Items removed: {count}\"",
",",
"[",
"'count'",
"=>",
"$",
"removed",
"]",
")",
")",
";",
"}",
"}"
] |
Respond only on Ajax
@throws NotFoundHttpException
|
[
"Respond",
"only",
"on",
"Ajax"
] |
ff0103dc55c3462627ccc704c33e70c96053f750
|
https://github.com/DevGroup-ru/yii2-users-module/blob/ff0103dc55c3462627ccc704c33e70c96053f750/src/controllers/RbacManageController.php#L90-L117
|
20,191 |
DevGroup-ru/yii2-users-module
|
src/controllers/RbacManageController.php
|
RbacManageController.actionDelete
|
public function actionDelete($id, $type, $returnUrl = '')
{
self::checkPermissions($type);
if (true === Yii::$app->getAuthManager()->remove(new Item(['name' => $id]))) {
Yii::$app->session->setFlash(
'info',
Yii::t('users', "Item successfully removed")
);
} else {
Yii::$app->session->setFlash(
'warning',
Yii::t('users', "Unknown RBAC item name '{name}'", ['name' => $id])
);
}
$returnUrl = empty($returnUrl) ? ['/users/rbac-manage/index', 'type' => $type] : $returnUrl;
return $this->redirect($returnUrl);
}
|
php
|
public function actionDelete($id, $type, $returnUrl = '')
{
self::checkPermissions($type);
if (true === Yii::$app->getAuthManager()->remove(new Item(['name' => $id]))) {
Yii::$app->session->setFlash(
'info',
Yii::t('users', "Item successfully removed")
);
} else {
Yii::$app->session->setFlash(
'warning',
Yii::t('users', "Unknown RBAC item name '{name}'", ['name' => $id])
);
}
$returnUrl = empty($returnUrl) ? ['/users/rbac-manage/index', 'type' => $type] : $returnUrl;
return $this->redirect($returnUrl);
}
|
[
"public",
"function",
"actionDelete",
"(",
"$",
"id",
",",
"$",
"type",
",",
"$",
"returnUrl",
"=",
"''",
")",
"{",
"self",
"::",
"checkPermissions",
"(",
"$",
"type",
")",
";",
"if",
"(",
"true",
"===",
"Yii",
"::",
"$",
"app",
"->",
"getAuthManager",
"(",
")",
"->",
"remove",
"(",
"new",
"Item",
"(",
"[",
"'name'",
"=>",
"$",
"id",
"]",
")",
")",
")",
"{",
"Yii",
"::",
"$",
"app",
"->",
"session",
"->",
"setFlash",
"(",
"'info'",
",",
"Yii",
"::",
"t",
"(",
"'users'",
",",
"\"Item successfully removed\"",
")",
")",
";",
"}",
"else",
"{",
"Yii",
"::",
"$",
"app",
"->",
"session",
"->",
"setFlash",
"(",
"'warning'",
",",
"Yii",
"::",
"t",
"(",
"'users'",
",",
"\"Unknown RBAC item name '{name}'\"",
",",
"[",
"'name'",
"=>",
"$",
"id",
"]",
")",
")",
";",
"}",
"$",
"returnUrl",
"=",
"empty",
"(",
"$",
"returnUrl",
")",
"?",
"[",
"'/users/rbac-manage/index'",
",",
"'type'",
"=>",
"$",
"type",
"]",
":",
"$",
"returnUrl",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"returnUrl",
")",
";",
"}"
] |
Deletes an existing RBAC Item model.
@param integer $id
@param $type
@param string $returnUrl
@return mixed
@throws ForbiddenHttpException
|
[
"Deletes",
"an",
"existing",
"RBAC",
"Item",
"model",
"."
] |
ff0103dc55c3462627ccc704c33e70c96053f750
|
https://github.com/DevGroup-ru/yii2-users-module/blob/ff0103dc55c3462627ccc704c33e70c96053f750/src/controllers/RbacManageController.php#L128-L144
|
20,192 |
creolab/resources
|
src/Transformer.php
|
Transformer.transform
|
public function transform($data = null, $rules = null)
{
// The data
if ( ! $data) $data = $this->data;
// The rules
if ( ! $rules) $rules = $this->rules;
// Merge the default ones in
$rules = array_merge($this->defaultRules, $rules);
foreach ($rules as $key => $rule)
{
if (isset($data[$key]))
{
if ($rule == 'datetime') $data[$key] = Carbon::parse($data[$key]);
elseif ($rule == 'time') $data[$key] = Carbon::parse($data[$key]);
elseif ($rule == 'date') $data[$key] = Carbon::parse($data[$key]);
elseif ($rule == 'image') $data[$key] = $this->transformImage($data[$key]);
elseif ($rule == 'strip_tags') $data[$key] = strip_tags($data[$key]);
elseif (is_string($rule) and class_exists($rule)) $data[$key] = new $rule($data[$key]);
elseif (is_array($rule)) $data[$key] = $data[$key];
}
}
return $data;
}
|
php
|
public function transform($data = null, $rules = null)
{
// The data
if ( ! $data) $data = $this->data;
// The rules
if ( ! $rules) $rules = $this->rules;
// Merge the default ones in
$rules = array_merge($this->defaultRules, $rules);
foreach ($rules as $key => $rule)
{
if (isset($data[$key]))
{
if ($rule == 'datetime') $data[$key] = Carbon::parse($data[$key]);
elseif ($rule == 'time') $data[$key] = Carbon::parse($data[$key]);
elseif ($rule == 'date') $data[$key] = Carbon::parse($data[$key]);
elseif ($rule == 'image') $data[$key] = $this->transformImage($data[$key]);
elseif ($rule == 'strip_tags') $data[$key] = strip_tags($data[$key]);
elseif (is_string($rule) and class_exists($rule)) $data[$key] = new $rule($data[$key]);
elseif (is_array($rule)) $data[$key] = $data[$key];
}
}
return $data;
}
|
[
"public",
"function",
"transform",
"(",
"$",
"data",
"=",
"null",
",",
"$",
"rules",
"=",
"null",
")",
"{",
"// The data",
"if",
"(",
"!",
"$",
"data",
")",
"$",
"data",
"=",
"$",
"this",
"->",
"data",
";",
"// The rules",
"if",
"(",
"!",
"$",
"rules",
")",
"$",
"rules",
"=",
"$",
"this",
"->",
"rules",
";",
"// Merge the default ones in",
"$",
"rules",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"defaultRules",
",",
"$",
"rules",
")",
";",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"key",
"=>",
"$",
"rule",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
")",
"{",
"if",
"(",
"$",
"rule",
"==",
"'datetime'",
")",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"Carbon",
"::",
"parse",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
";",
"elseif",
"(",
"$",
"rule",
"==",
"'time'",
")",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"Carbon",
"::",
"parse",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
";",
"elseif",
"(",
"$",
"rule",
"==",
"'date'",
")",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"Carbon",
"::",
"parse",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
";",
"elseif",
"(",
"$",
"rule",
"==",
"'image'",
")",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"transformImage",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
";",
"elseif",
"(",
"$",
"rule",
"==",
"'strip_tags'",
")",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"strip_tags",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
";",
"elseif",
"(",
"is_string",
"(",
"$",
"rule",
")",
"and",
"class_exists",
"(",
"$",
"rule",
")",
")",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"new",
"$",
"rule",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
";",
"elseif",
"(",
"is_array",
"(",
"$",
"rule",
")",
")",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"data",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] |
Transform data types for item
@param array $data
@param array $rules
@return array
|
[
"Transform",
"data",
"types",
"for",
"item"
] |
6e1bdd266aa373f6dafd2408b230f7d2fa05a637
|
https://github.com/creolab/resources/blob/6e1bdd266aa373f6dafd2408b230f7d2fa05a637/src/Transformer.php#L39-L65
|
20,193 |
legalthings/permission-matcher
|
src/PermissionMatcher.php
|
PermissionMatcher.match
|
public function match($permissions, array $authzGroups)
{
$privileges = [];
foreach ($permissions as $permissionAuthzGroup => $permissionPrivileges) {
$matchingAuthzGroup = $this->getMatchingAuthzGroup($permissionAuthzGroup, $authzGroups);
if (!$matchingAuthzGroup) {
continue;
}
$privileges[] = $permissionPrivileges;
}
return $this->flatten($privileges);
}
|
php
|
public function match($permissions, array $authzGroups)
{
$privileges = [];
foreach ($permissions as $permissionAuthzGroup => $permissionPrivileges) {
$matchingAuthzGroup = $this->getMatchingAuthzGroup($permissionAuthzGroup, $authzGroups);
if (!$matchingAuthzGroup) {
continue;
}
$privileges[] = $permissionPrivileges;
}
return $this->flatten($privileges);
}
|
[
"public",
"function",
"match",
"(",
"$",
"permissions",
",",
"array",
"$",
"authzGroups",
")",
"{",
"$",
"privileges",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"permissions",
"as",
"$",
"permissionAuthzGroup",
"=>",
"$",
"permissionPrivileges",
")",
"{",
"$",
"matchingAuthzGroup",
"=",
"$",
"this",
"->",
"getMatchingAuthzGroup",
"(",
"$",
"permissionAuthzGroup",
",",
"$",
"authzGroups",
")",
";",
"if",
"(",
"!",
"$",
"matchingAuthzGroup",
")",
"{",
"continue",
";",
"}",
"$",
"privileges",
"[",
"]",
"=",
"$",
"permissionPrivileges",
";",
"}",
"return",
"$",
"this",
"->",
"flatten",
"(",
"$",
"privileges",
")",
";",
"}"
] |
Get a flat list of privileges for matching authz groups
@param array|object $permissions
@param array $authzGroups
@return array
|
[
"Get",
"a",
"flat",
"list",
"of",
"privileges",
"for",
"matching",
"authz",
"groups"
] |
fbfa925e92406fe9dac83b387be47931e6de0f81
|
https://github.com/legalthings/permission-matcher/blob/fbfa925e92406fe9dac83b387be47931e6de0f81/src/PermissionMatcher.php#L17-L32
|
20,194 |
legalthings/permission-matcher
|
src/PermissionMatcher.php
|
PermissionMatcher.matchFull
|
public function matchFull($permissions, array $authzGroups)
{
$privileges = [];
foreach ($permissions as $permissionAuthzGroup => $permissionPrivileges) {
$matchingAuthzGroup = $this->getMatchingAuthzGroup($permissionAuthzGroup, $authzGroups);
if (!$matchingAuthzGroup) {
continue;
}
$privileges = $this->addAuthzGroupsToPrivileges($privileges, $permissionPrivileges, [
$permissionAuthzGroup, $matchingAuthzGroup
]);
}
return $privileges;
}
|
php
|
public function matchFull($permissions, array $authzGroups)
{
$privileges = [];
foreach ($permissions as $permissionAuthzGroup => $permissionPrivileges) {
$matchingAuthzGroup = $this->getMatchingAuthzGroup($permissionAuthzGroup, $authzGroups);
if (!$matchingAuthzGroup) {
continue;
}
$privileges = $this->addAuthzGroupsToPrivileges($privileges, $permissionPrivileges, [
$permissionAuthzGroup, $matchingAuthzGroup
]);
}
return $privileges;
}
|
[
"public",
"function",
"matchFull",
"(",
"$",
"permissions",
",",
"array",
"$",
"authzGroups",
")",
"{",
"$",
"privileges",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"permissions",
"as",
"$",
"permissionAuthzGroup",
"=>",
"$",
"permissionPrivileges",
")",
"{",
"$",
"matchingAuthzGroup",
"=",
"$",
"this",
"->",
"getMatchingAuthzGroup",
"(",
"$",
"permissionAuthzGroup",
",",
"$",
"authzGroups",
")",
";",
"if",
"(",
"!",
"$",
"matchingAuthzGroup",
")",
"{",
"continue",
";",
"}",
"$",
"privileges",
"=",
"$",
"this",
"->",
"addAuthzGroupsToPrivileges",
"(",
"$",
"privileges",
",",
"$",
"permissionPrivileges",
",",
"[",
"$",
"permissionAuthzGroup",
",",
"$",
"matchingAuthzGroup",
"]",
")",
";",
"}",
"return",
"$",
"privileges",
";",
"}"
] |
Get a list of privileges for matching authz groups containing more information
Returns an array of objects where the privilege is the key and authzgroups the value
@param array|object $permissions
@param array $authzGroups
@return array
|
[
"Get",
"a",
"list",
"of",
"privileges",
"for",
"matching",
"authz",
"groups",
"containing",
"more",
"information",
"Returns",
"an",
"array",
"of",
"objects",
"where",
"the",
"privilege",
"is",
"the",
"key",
"and",
"authzgroups",
"the",
"value"
] |
fbfa925e92406fe9dac83b387be47931e6de0f81
|
https://github.com/legalthings/permission-matcher/blob/fbfa925e92406fe9dac83b387be47931e6de0f81/src/PermissionMatcher.php#L42-L59
|
20,195 |
legalthings/permission-matcher
|
src/PermissionMatcher.php
|
PermissionMatcher.getMatchingAuthzGroup
|
protected function getMatchingAuthzGroup($permissionAuthzGroup, array $authzGroups)
{
$invert = $this->stringStartsWith($permissionAuthzGroup, '!');
if ($invert) {
$permissionAuthzGroup = substr($permissionAuthzGroup, 1);
}
$matches = [];
foreach ($authzGroups as $authzGroup) {
$match = $this->authzGroupsAreEqual($permissionAuthzGroup, $authzGroup);
if ($match && $invert) {
return null;
}
if ($match && !$invert || !$match && $invert) {
$matches[] = $authzGroup;
}
}
return !empty($matches) ? $matches[0] : null;
}
|
php
|
protected function getMatchingAuthzGroup($permissionAuthzGroup, array $authzGroups)
{
$invert = $this->stringStartsWith($permissionAuthzGroup, '!');
if ($invert) {
$permissionAuthzGroup = substr($permissionAuthzGroup, 1);
}
$matches = [];
foreach ($authzGroups as $authzGroup) {
$match = $this->authzGroupsAreEqual($permissionAuthzGroup, $authzGroup);
if ($match && $invert) {
return null;
}
if ($match && !$invert || !$match && $invert) {
$matches[] = $authzGroup;
}
}
return !empty($matches) ? $matches[0] : null;
}
|
[
"protected",
"function",
"getMatchingAuthzGroup",
"(",
"$",
"permissionAuthzGroup",
",",
"array",
"$",
"authzGroups",
")",
"{",
"$",
"invert",
"=",
"$",
"this",
"->",
"stringStartsWith",
"(",
"$",
"permissionAuthzGroup",
",",
"'!'",
")",
";",
"if",
"(",
"$",
"invert",
")",
"{",
"$",
"permissionAuthzGroup",
"=",
"substr",
"(",
"$",
"permissionAuthzGroup",
",",
"1",
")",
";",
"}",
"$",
"matches",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"authzGroups",
"as",
"$",
"authzGroup",
")",
"{",
"$",
"match",
"=",
"$",
"this",
"->",
"authzGroupsAreEqual",
"(",
"$",
"permissionAuthzGroup",
",",
"$",
"authzGroup",
")",
";",
"if",
"(",
"$",
"match",
"&&",
"$",
"invert",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"match",
"&&",
"!",
"$",
"invert",
"||",
"!",
"$",
"match",
"&&",
"$",
"invert",
")",
"{",
"$",
"matches",
"[",
"]",
"=",
"$",
"authzGroup",
";",
"}",
"}",
"return",
"!",
"empty",
"(",
"$",
"matches",
")",
"?",
"$",
"matches",
"[",
"0",
"]",
":",
"null",
";",
"}"
] |
Check if one of the authz groups match
@param string $permissionAuthzGroup
@param array $authzGroups
@return string|null
|
[
"Check",
"if",
"one",
"of",
"the",
"authz",
"groups",
"match"
] |
fbfa925e92406fe9dac83b387be47931e6de0f81
|
https://github.com/legalthings/permission-matcher/blob/fbfa925e92406fe9dac83b387be47931e6de0f81/src/PermissionMatcher.php#L68-L91
|
20,196 |
legalthings/permission-matcher
|
src/PermissionMatcher.php
|
PermissionMatcher.authzGroupsAreEqual
|
protected function authzGroupsAreEqual($permissionAuthzGroup, $authzGroup)
{
return $this->pathsAreEqual($permissionAuthzGroup, $authzGroup) &&
$this->queryParamsAreEqual($permissionAuthzGroup, $authzGroup);
}
|
php
|
protected function authzGroupsAreEqual($permissionAuthzGroup, $authzGroup)
{
return $this->pathsAreEqual($permissionAuthzGroup, $authzGroup) &&
$this->queryParamsAreEqual($permissionAuthzGroup, $authzGroup);
}
|
[
"protected",
"function",
"authzGroupsAreEqual",
"(",
"$",
"permissionAuthzGroup",
",",
"$",
"authzGroup",
")",
"{",
"return",
"$",
"this",
"->",
"pathsAreEqual",
"(",
"$",
"permissionAuthzGroup",
",",
"$",
"authzGroup",
")",
"&&",
"$",
"this",
"->",
"queryParamsAreEqual",
"(",
"$",
"permissionAuthzGroup",
",",
"$",
"authzGroup",
")",
";",
"}"
] |
Check if authz groups match
@param string $permissionAuthzGroup
@param string $authzGroup
@return boolean
|
[
"Check",
"if",
"authz",
"groups",
"match"
] |
fbfa925e92406fe9dac83b387be47931e6de0f81
|
https://github.com/legalthings/permission-matcher/blob/fbfa925e92406fe9dac83b387be47931e6de0f81/src/PermissionMatcher.php#L101-L105
|
20,197 |
legalthings/permission-matcher
|
src/PermissionMatcher.php
|
PermissionMatcher.pathsAreEqual
|
protected function pathsAreEqual($permissionAuthzGroup, $authzGroup)
{
$permissionAuthzGroupPath = rtrim(strtok($permissionAuthzGroup, '?'), '/');
$authzGroupPath = rtrim(strtok($authzGroup, '?'), '/');
return $this->matchAuthzGroupPaths($permissionAuthzGroupPath, $authzGroupPath) ||
$this->matchAuthzGroupPaths($authzGroupPath, $permissionAuthzGroupPath);
}
|
php
|
protected function pathsAreEqual($permissionAuthzGroup, $authzGroup)
{
$permissionAuthzGroupPath = rtrim(strtok($permissionAuthzGroup, '?'), '/');
$authzGroupPath = rtrim(strtok($authzGroup, '?'), '/');
return $this->matchAuthzGroupPaths($permissionAuthzGroupPath, $authzGroupPath) ||
$this->matchAuthzGroupPaths($authzGroupPath, $permissionAuthzGroupPath);
}
|
[
"protected",
"function",
"pathsAreEqual",
"(",
"$",
"permissionAuthzGroup",
",",
"$",
"authzGroup",
")",
"{",
"$",
"permissionAuthzGroupPath",
"=",
"rtrim",
"(",
"strtok",
"(",
"$",
"permissionAuthzGroup",
",",
"'?'",
")",
",",
"'/'",
")",
";",
"$",
"authzGroupPath",
"=",
"rtrim",
"(",
"strtok",
"(",
"$",
"authzGroup",
",",
"'?'",
")",
",",
"'/'",
")",
";",
"return",
"$",
"this",
"->",
"matchAuthzGroupPaths",
"(",
"$",
"permissionAuthzGroupPath",
",",
"$",
"authzGroupPath",
")",
"||",
"$",
"this",
"->",
"matchAuthzGroupPaths",
"(",
"$",
"authzGroupPath",
",",
"$",
"permissionAuthzGroupPath",
")",
";",
"}"
] |
Compare the paths of two authz groups
@param string $permissionAuthzGroup
@param string $authzGroup
@return boolean
|
[
"Compare",
"the",
"paths",
"of",
"two",
"authz",
"groups"
] |
fbfa925e92406fe9dac83b387be47931e6de0f81
|
https://github.com/legalthings/permission-matcher/blob/fbfa925e92406fe9dac83b387be47931e6de0f81/src/PermissionMatcher.php#L114-L121
|
20,198 |
legalthings/permission-matcher
|
src/PermissionMatcher.php
|
PermissionMatcher.matchAuthzGroupPaths
|
protected function matchAuthzGroupPaths($pattern, $subject)
{
$regex = '^' . str_replace('[^/]+', '\\*', preg_quote($pattern, '~')) . '$';
$regex = str_replace('\\*', '(.*)', $regex);
$match = preg_match('~' . $regex . '~i', $subject);
return $match;
}
|
php
|
protected function matchAuthzGroupPaths($pattern, $subject)
{
$regex = '^' . str_replace('[^/]+', '\\*', preg_quote($pattern, '~')) . '$';
$regex = str_replace('\\*', '(.*)', $regex);
$match = preg_match('~' . $regex . '~i', $subject);
return $match;
}
|
[
"protected",
"function",
"matchAuthzGroupPaths",
"(",
"$",
"pattern",
",",
"$",
"subject",
")",
"{",
"$",
"regex",
"=",
"'^'",
".",
"str_replace",
"(",
"'[^/]+'",
",",
"'\\\\*'",
",",
"preg_quote",
"(",
"$",
"pattern",
",",
"'~'",
")",
")",
".",
"'$'",
";",
"$",
"regex",
"=",
"str_replace",
"(",
"'\\\\*'",
",",
"'(.*)'",
",",
"$",
"regex",
")",
";",
"$",
"match",
"=",
"preg_match",
"(",
"'~'",
".",
"$",
"regex",
".",
"'~i'",
",",
"$",
"subject",
")",
";",
"return",
"$",
"match",
";",
"}"
] |
Check if one paths mathes the other
@param string $pattern
@param string $subject
@return boolean
|
[
"Check",
"if",
"one",
"paths",
"mathes",
"the",
"other"
] |
fbfa925e92406fe9dac83b387be47931e6de0f81
|
https://github.com/legalthings/permission-matcher/blob/fbfa925e92406fe9dac83b387be47931e6de0f81/src/PermissionMatcher.php#L130-L138
|
20,199 |
legalthings/permission-matcher
|
src/PermissionMatcher.php
|
PermissionMatcher.queryParamsAreEqual
|
protected function queryParamsAreEqual($permissionAuthzGroup, $authzGroup)
{
$authzGroupQueryParams = array_change_key_case($this->getStringQueryParameters($authzGroup), CASE_LOWER);
$permissionAuthzGroupQueryParams = array_change_key_case($this->getStringQueryParameters($permissionAuthzGroup), CASE_LOWER);
ksort($authzGroupQueryParams);
ksort($permissionAuthzGroupQueryParams);
return $permissionAuthzGroupQueryParams === $authzGroupQueryParams;
}
|
php
|
protected function queryParamsAreEqual($permissionAuthzGroup, $authzGroup)
{
$authzGroupQueryParams = array_change_key_case($this->getStringQueryParameters($authzGroup), CASE_LOWER);
$permissionAuthzGroupQueryParams = array_change_key_case($this->getStringQueryParameters($permissionAuthzGroup), CASE_LOWER);
ksort($authzGroupQueryParams);
ksort($permissionAuthzGroupQueryParams);
return $permissionAuthzGroupQueryParams === $authzGroupQueryParams;
}
|
[
"protected",
"function",
"queryParamsAreEqual",
"(",
"$",
"permissionAuthzGroup",
",",
"$",
"authzGroup",
")",
"{",
"$",
"authzGroupQueryParams",
"=",
"array_change_key_case",
"(",
"$",
"this",
"->",
"getStringQueryParameters",
"(",
"$",
"authzGroup",
")",
",",
"CASE_LOWER",
")",
";",
"$",
"permissionAuthzGroupQueryParams",
"=",
"array_change_key_case",
"(",
"$",
"this",
"->",
"getStringQueryParameters",
"(",
"$",
"permissionAuthzGroup",
")",
",",
"CASE_LOWER",
")",
";",
"ksort",
"(",
"$",
"authzGroupQueryParams",
")",
";",
"ksort",
"(",
"$",
"permissionAuthzGroupQueryParams",
")",
";",
"return",
"$",
"permissionAuthzGroupQueryParams",
"===",
"$",
"authzGroupQueryParams",
";",
"}"
] |
Compare the query parameters of two authz groups
@param string $permissionAuthzGroup
@param string $authzGroup
@return boolean
|
[
"Compare",
"the",
"query",
"parameters",
"of",
"two",
"authz",
"groups"
] |
fbfa925e92406fe9dac83b387be47931e6de0f81
|
https://github.com/legalthings/permission-matcher/blob/fbfa925e92406fe9dac83b387be47931e6de0f81/src/PermissionMatcher.php#L148-L157
|
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.